import {EncodedPayload} from './types' /** * Wrapper class for managing values encoded in a string format. */ export class Payload { /** Instantiate the payload from a given string. */ public static from(v: EncodedPayload): Payload { const encoded = v.slice('multicrypt:'.length) return new Payload(JSON.parse(encoded)) } /** Instantiate the payload from a given value. */ constructor( public readonly value: T, ) {} /** Serialize the value. */ encode(): EncodedPayload { return `multicrypt:${JSON.stringify(this.value)}` } }