@keetanetwork/anchor 0.0.82 → 0.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/anchor-metadata-server.js +1 -1
- package/lib/anchor-metadata-server.js.map +1 -1
- package/lib/anchor-status.d.ts +32 -1
- package/lib/anchor-status.d.ts.map +1 -1
- package/lib/anchor-status.js +62 -1
- package/lib/anchor-status.js.map +1 -1
- package/lib/asset.d.ts +3 -0
- package/lib/asset.d.ts.map +1 -1
- package/lib/asset.js +25 -1
- package/lib/asset.js.map +1 -1
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +48 -44
- package/lib/chaining.js.map +1 -1
- package/lib/encrypted-container.d.ts.map +1 -1
- package/lib/encrypted-container.js +22 -7
- package/lib/encrypted-container.js.map +1 -1
- package/lib/history.d.ts +77 -21
- package/lib/history.d.ts.map +1 -1
- package/lib/history.js +951 -70
- package/lib/history.js.map +1 -1
- package/lib/http-server/index.d.ts.map +1 -1
- package/lib/http-server/index.js +20 -1
- package/lib/http-server/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +18 -2
- package/lib/resolver.js.map +1 -1
- package/lib/sensitive-attribute.d.ts.map +1 -1
- package/lib/sensitive-attribute.js +24 -2
- package/lib/sensitive-attribute.js.map +1 -1
- package/npm-shrinkwrap.json +18 -6
- package/package.json +2 -1
- package/services/fx/client.d.ts +18 -4
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +52 -6
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +35 -0
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +5 -5
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts +17 -1
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +236 -18
- package/services/fx/server.js.map +1 -1
- package/services/fx/status-source.d.ts +34 -0
- package/services/fx/status-source.d.ts.map +1 -0
- package/services/fx/status-source.js +99 -0
- package/services/fx/status-source.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-container.d.ts","sourceRoot":"","sources":["../../src/lib/encrypted-container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,EAAE,MAAM,EAAqE,MAAM,mBAAmB,CAAC;AAE9G,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9C;;GAEG;AACH,eAAO,MAAM,4BAA4B,qmBAsC/B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,4BAA4B,CAAC,MAAM,CAAC,CAAC;AAEtF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,gBAAgB;IAC5D,gBAAyB,IAAI,EAAE,MAAM,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,mCAAmC,CAAU;IAC9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mCAAmC,CAA0C;IAErG,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAE3C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,2BAA2B;gBAKzD,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM;IAY9D,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB;IAI1D,MAAM,IAAI,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,2BAA2B,CAAA;KAAE;WAOpF,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAkBvE;AAQD,QAAA,MAAM,OAAO,EAAE,OAAO,WAAW,CAAC,OAA6B,CAA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|
@@ -606,6 +606,7 @@ async function parseASN1Decrypt(inputInfo, keys) {
|
|
|
606
606
|
return ({
|
|
607
607
|
version: inputInfo.version,
|
|
608
608
|
plaintext: plaintext,
|
|
609
|
+
compressed: containedCompressed,
|
|
609
610
|
...cipherInfo
|
|
610
611
|
});
|
|
611
612
|
}
|
|
@@ -827,6 +828,25 @@ export class EncryptedContainer {
|
|
|
827
828
|
this.#data = { ...this.#data, plaintext };
|
|
828
829
|
return (plaintext);
|
|
829
830
|
}
|
|
831
|
+
/**
|
|
832
|
+
* Return the compressed bytes exactly as they are stored in the encoded
|
|
833
|
+
* container (decrypted where applicable, but before inflation).
|
|
834
|
+
*/
|
|
835
|
+
async #computeSignedCompressed() {
|
|
836
|
+
const info = this.#computeAndSetKeyInfo(this.encrypted);
|
|
837
|
+
let principals = this._internalState.principals;
|
|
838
|
+
if (info.isEncrypted) {
|
|
839
|
+
if (principals === null) {
|
|
840
|
+
throw (new EncryptedContainerError('INVALID_PRINCIPALS', 'May not decrypt data with a null set of principals'));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
principals = [];
|
|
845
|
+
}
|
|
846
|
+
const wrapper = await parseASN1Decrypt(info, principals);
|
|
847
|
+
const compressed = Buffer.from(wrapper.compressed);
|
|
848
|
+
return (compressed);
|
|
849
|
+
}
|
|
830
850
|
/**
|
|
831
851
|
* Compute the encoded version of the plaintext data
|
|
832
852
|
*/
|
|
@@ -1035,13 +1055,8 @@ export class EncryptedContainer {
|
|
|
1035
1055
|
if (!supportedSignatureOIDs.has(signerInfo.signatureAlgorithmOID)) {
|
|
1036
1056
|
throw (new EncryptedContainerError('UNSUPPORTED_SIGNATURE_ALGORITHM', `Unsupported signature algorithm OID: ${signerInfo.signatureAlgorithmOID}`));
|
|
1037
1057
|
}
|
|
1038
|
-
//
|
|
1039
|
-
const
|
|
1040
|
-
if (!plaintext) {
|
|
1041
|
-
throw (new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to compute plaintext for signature verification'));
|
|
1042
|
-
}
|
|
1043
|
-
// Recompute the digest of the compressed plaintext
|
|
1044
|
-
const compressedPlaintext = Buffer.from(await zlibDeflateAsync(bufferToArrayBuffer(plaintext)));
|
|
1058
|
+
// Digest the exact compressed bytes that were signed.
|
|
1059
|
+
const compressedPlaintext = await this.#computeSignedCompressed();
|
|
1045
1060
|
const digestHash = crypto.createHash('sha3-256');
|
|
1046
1061
|
digestHash.update(compressedPlaintext);
|
|
1047
1062
|
const digest = digestHash.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypted-container.js","sourceRoot":"","sources":["../../src/lib/encrypted-container.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,yBAAyB;AAEzB;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,yBAAyB;IACzB,uBAAuB;IACvB,mBAAmB;IACnB,0BAA0B;IAC1B,oBAAoB;IACpB,uBAAuB;IAEvB,mBAAmB;IACnB,qBAAqB;IACrB,8BAA8B;IAC9B,8BAA8B;IAC9B,iCAAiC;IACjC,sBAAsB;IAEtB,wBAAwB;IACxB,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IAEtB,iBAAiB;IACjB,6BAA6B;IAC7B,YAAY;IACZ,+BAA+B;IAE/B,eAAe;IACf,wBAAwB;IACxB,2BAA2B;IAC3B,oBAAoB;IAEpB,oBAAoB;IACpB,qBAAqB;IACrB,oBAAoB;IACpB,+BAA+B;I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,CAAC,MAAM,CAAC,EAC3B,mBAAmB,CAAC,SAAS,CAAC,EAC9B,EAAE,GAAG,EAAE,IAAI,EAAE,CACb,CAAC;QAEF,OAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;;AAGF,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;CACpB,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import crypto from './utils/crypto.js';\nimport { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport type {\n\tASN1OID\n} from '@keetanetwork/keetanet-client/lib/utils/asn1.js';\nimport { Buffer, arrayBufferToBuffer, arrayBufferLikeToBuffer, bufferToArrayBuffer } from './utils/buffer.js';\nimport { isArray } from './utils/array.js';\nimport { KeetaAnchorError } from './error.js';\n\n// #region Error Handling\n\n/**\n * Error codes for EncryptedContainer operations\n */\nexport const EncryptedContainerErrorCodes = [\n\t// Parsing/Malformed data\n\t'MALFORMED_BASE_FORMAT',\n\t'MALFORMED_VERSION',\n\t'MALFORMED_DATA_STRUCTURE',\n\t'MALFORMED_KEY_INFO',\n\t'MALFORMED_SIGNER_INFO',\n\n\t// Algorithm issues\n\t'UNSUPPORTED_VERSION',\n\t'UNSUPPORTED_CIPHER_ALGORITHM',\n\t'UNSUPPORTED_DIGEST_ALGORITHM',\n\t'UNSUPPORTED_SIGNATURE_ALGORITHM',\n\t'UNSUPPORTED_KEY_TYPE',\n\n\t// Key/Decryption issues\n\t'NO_KEYS_PROVIDED',\n\t'NO_MATCHING_KEY',\n\t'DECRYPTION_FAILED',\n\t'DECOMPRESSION_FAILED',\n\n\t// Signing issues\n\t'SIGNER_REQUIRES_PRIVATE_KEY',\n\t'NOT_SIGNED',\n\t'SIGNATURE_VERIFICATION_FAILED',\n\n\t// State issues\n\t'NO_PLAINTEXT_AVAILABLE',\n\t'NO_ENCODED_DATA_AVAILABLE',\n\t'PLAINTEXT_DISABLED',\n\n\t// Access management\n\t'ENCRYPTION_REQUIRED',\n\t'INVALID_PRINCIPALS',\n\t'ACCESS_MANAGEMENT_NOT_ALLOWED',\n\n\t// Internal errors\n\t'INTERNAL_ERROR'\n] as const;\n\n/**\n * Error code type\n */\nexport type EncryptedContainerErrorCode = typeof EncryptedContainerErrorCodes[number];\n\n/**\n * Error class for EncryptedContainer operations\n */\nexport class EncryptedContainerError extends KeetaAnchorError {\n\tstatic override readonly name: string = 'EncryptedContainerError';\n\n\tprivate readonly encryptedContainerErrorObjectTypeID!: string;\n\tprivate static readonly encryptedContainerErrorObjectTypeID = 'f4a8c2e1-7b3d-4f9a-8c5e-2d1f0a9b8c7e';\n\n\treadonly code: EncryptedContainerErrorCode;\n\n\t/**\n\t * Check if a string is a valid EncryptedContainerErrorCode\n\t */\n\tstatic isValidCode(code: string): code is EncryptedContainerErrorCode {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(EncryptedContainerErrorCodes.includes(code as EncryptedContainerErrorCode));\n\t}\n\n\tconstructor(code: EncryptedContainerErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\t// EncryptedContainerError is not a user error\n\t\tthis.userError = false;\n\n\t\tObject.defineProperty(this, 'encryptedContainerErrorObjectTypeID', {\n\t\t\tvalue: EncryptedContainerError.encryptedContainerErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is EncryptedContainerError {\n\t\treturn(this.hasPropWithValue(input, 'encryptedContainerErrorObjectTypeID', EncryptedContainerError.encryptedContainerErrorObjectTypeID));\n\t}\n\n\toverride toJSON(): ReturnType<KeetaAnchorError['toJSON']> & { code: EncryptedContainerErrorCode } {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tcode: this.code\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<EncryptedContainerError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract and validate code\n\t\tif (!('code' in other) || typeof other.code !== 'string') {\n\t\t\tthrow(new Error('Invalid EncryptedContainerError JSON: missing code property'));\n\t\t}\n\n\t\t// Validate code is a valid EncryptedContainerErrorCode\n\t\tconst code = other.code;\n\t\tif (!this.isValidCode(code)) {\n\t\t\tthrow(new Error(`Invalid EncryptedContainerError JSON: unknown code ${code}`));\n\t\t}\n\n\t\tconst error = new this(code, message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\n// #endregion\n\nconst zlibDeflateAsync = KeetaNetLib.Utils.Buffer.ZlibDeflateAsync;\nconst zlibInflateAsync = KeetaNetLib.Utils.Buffer.ZlibInflateAsync;\nconst ASN1toJS = KeetaNetLib.Utils.ASN1.ASN1toJS;\nconst JStoASN1 = KeetaNetLib.Utils.ASN1.JStoASN1;\nconst Account: typeof KeetaNetLib.Account = KeetaNetLib.Account;\ntype Account = InstanceType<typeof KeetaNetLib.Account>;\n\n/**\n * Options for creating an EncryptedContainer from plaintext\n */\nexport type FromPlaintextOptions = {\n\tlocked?: boolean;\n\tsigner?: Account;\n};\n\n/*\n * ASN.1 Schema\n *\n * EncryptedContainer DEFINITIONS ::=\n * BEGIN\n * Version ::= INTEGER { v2(1) }\n *\n * KeyStore ::= SEQUENCE {\n * publicKey OCTET STRING,\n * encryptedSymmetricKey OCTET STRING,\n * ...\n * }\n *\n * EncryptedContainerBox ::= SEQUENCE {\n * keys SEQUENCE OF KeyStore,\n * encryptionAlgorithm OBJECT IDENTIFIER,\n * initializationVector OCTET STRING,\n * encryptedValue OCTET STRING,\n * ...\n * }\n *\n * PlaintextContainerBox ::= SEQUENCE {\n * plainValue OCTET STRING,\n * ...\n * }\n *\n * -- RFC 5652 Section 5.3 SignerInfo (adapted for KeetaNet)\n * SignerInfo ::= SEQUENCE {\n * version CMSVersion, -- INTEGER (3 for subjectKeyIdentifier)\n * sid [0] SubjectKeyIdentifier, -- OCTET STRING (publicKeyAndType)\n * digestAlgorithm OBJECT IDENTIFIER, -- SHA3-256: 2.16.840.1.101.3.4.2.8\n * signatureAlgorithm OBJECT IDENTIFIER, -- Derived from account type\n * signature OCTET STRING,\n * ...\n * }\n *\n * ContainerPackage ::= SEQUENCE {\n * version Version,\n * encryptedContainer [0] EXPLICIT EncryptedContainerBox OPTIONAL,\n * plaintextContainer [1] EXPLICIT PlaintextContainerBox OPTIONAL,\n * signerInfo [2] EXPLICIT SignerInfo OPTIONAL,\n * ...\n * } (WITH COMPONENTS {\n * encryptedContainer PRESENT,\n * plaintextContainer ABSENT\n * } |\n * WITH COMPONENTS {\n * encryptedContainer ABSENT,\n * plaintextContainer PRESENT\n * })\n * END\n *\n */\n\n/**\n * OID constants for cryptographic algorithms\n * // XXX:TODO: We should standardize this somewhere centralized\n */\nconst oidDB = {\n\t// Digest algorithms\n\t'sha3-256': '2.16.840.1.101.3.4.2.8',\n\n\t// Signature algorithms\n\t'ed25519': '1.3.101.112',\n\t'secp256k1': '1.3.132.0.10',\n\t'secp256r1': '1.2.840.10045.3.1.7',\n\n\t// Encryption algorithms\n\t'aes-256-cbc': '2.16.840.1.101.3.4.1.42'\n} as const;\n\n/**\n * Supported algorithms\n * These are the canonical names as defined in oidDB\n */\nconst SUPPORTED_DIGEST_ALGORITHMS = ['sha3-256'] as const;\nconst SUPPORTED_SIGNATURE_ALGORITHMS = ['ed25519', 'secp256k1', 'secp256r1'] as const;\n\n/**\n * Known OID aliases that ASN1 parsers may return instead of our canonical names\n */\nconst OID_ALIASES: { [alias: string]: keyof typeof oidDB } = {\n\t'prime256v1': 'secp256r1'\n};\n\n/**\n * Build reverse lookup: name/alias -> numeric OID\n */\nconst nameToNumericOID: { [name: string]: string } = {};\nfor (const [name, numericOID] of Object.entries(oidDB)) {\n\tnameToNumericOID[name] = numericOID;\n}\nfor (const [alias, canonicalName] of Object.entries(OID_ALIASES)) {\n\tnameToNumericOID[alias] = oidDB[canonicalName];\n}\n\n/**\n * Normalize an OID (name, alias, or already numeric) to its numeric form.\n * Returns undefined if the OID is not recognized.\n */\nfunction normalizeToNumericOID(oid: string): string | undefined {\n\tif (/^\\d+(\\.\\d+)*$/.test(oid)) {\n\t\treturn(oid);\n\t}\n\n\t// Otherwise look up the name/alias\n\treturn(nameToNumericOID[oid]);\n}\n\n// Pre-compute supported numeric OIDs for validation\nconst supportedDigestOIDs = new Set<string>(SUPPORTED_DIGEST_ALGORITHMS.map(name => oidDB[name]));\nconst supportedSignatureOIDs = new Set<string>(SUPPORTED_SIGNATURE_ALGORITHMS.map(name => oidDB[name]));\n\n/**\n * Map account key algorithm to signature algorithm OID\n */\nfunction getSignatureAlgorithmOID(account: Account): string {\n\tconst keyType = account.keyType;\n\tconst KeyAlgo = Account.AccountKeyAlgorithm;\n\n\tif (keyType === KeyAlgo.ECDSA_SECP256K1) {\n\t\treturn(oidDB['secp256k1']);\n\t} else if (keyType === KeyAlgo.ED25519) {\n\t\treturn(oidDB['ed25519']);\n\t} else if (keyType === KeyAlgo.ECDSA_SECP256R1) {\n\t\treturn(oidDB['secp256r1']);\n\t}\n\n\tthrow(new EncryptedContainerError('UNSUPPORTED_KEY_TYPE', `Unsupported key type for signing: ${keyType}`));\n}\n\n/**\n * SignerInfo structure for RFC 5652 CMS compatibility\n */\ntype SignerInfoASN1 = [\n\t/* version - CMSVersion (3 for subjectKeyIdentifier) */\n\tnumber,\n\n\t/* sid - SubjectKeyIdentifier wrapped in context tag [0] */\n\t{\n\t\ttype: 'context',\n\t\tvalue: 0,\n\t\tkind: 'implicit',\n\t\tcontains: Buffer\n\t},\n\n\t/* digestAlgorithm */\n\tASN1OID,\n\n\t/* signatureAlgorithm */\n\tASN1OID,\n\n\t/* signature */\n\tBuffer\n];\n\n/**\n * Parsed SignerInfo data\n */\ntype ParsedSignerInfo = {\n\tversion: number;\n\tsignerPublicKeyAndType: Buffer;\n\tdigestAlgorithmOID: string;\n\tsignatureAlgorithmOID: string;\n\tsignature: Buffer;\n};\n\ntype EncryptedContainerKeyStore = [\n\t/* publicKey */\n\tBuffer,\n\n\t/* encryptedSymmetricKey */\n\tBuffer\n];\n\ntype EncryptedContainerBoxEncrypted = [\n\t/* keys */\n\tEncryptedContainerKeyStore[],\n\n\t/* encryptionAlgorithm */\n\tASN1OID,\n\n\t/* initializationVector */\n\tBuffer,\n\n\t/* value */\n\tBuffer\n];\n\ntype EncryptedContainerBoxPlaintext = [\n\t/* value */\n\tBuffer\n];\n\ntype SignerInfoBoxContext = {\n\ttype: 'context',\n\tvalue: 2,\n\tkind: 'explicit',\n\tcontains: SignerInfoASN1\n};\n\ntype ContainerPackage = [\n\t/* version */\n\tnumber,\n\n\t/* container */\n\tContainerBox,\n\n\t/* signerInfo (optional) */\n\tSignerInfoBoxContext?\n];\n\ntype EncryptedBoxContext = {\n\ttype: 'context',\n\tvalue: 0,\n\tkind: 'explicit',\n\tcontains: EncryptedContainerBoxEncrypted\n};\n\ntype PlaintextBoxContext = {\n\ttype: 'context',\n\tvalue: 1,\n\tkind: 'explicit',\n\tcontains: EncryptedContainerBoxPlaintext\n};\n\ntype ContainerBox = EncryptedBoxContext | PlaintextBoxContext;\n\n/**\n * Build a typed encrypted container box with context tag [0].\n */\nfunction buildEncryptedBox(\n\tkeys: EncryptedContainerKeyStore[],\n\talgorithmOID: string,\n\tiv: Buffer,\n\tencryptedData: Buffer\n): EncryptedBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 0,\n\t\tkind: 'explicit',\n\t\tcontains: [keys, { type: 'oid', oid: algorithmOID }, iv, encryptedData]\n\t});\n}\n\n/**\n * Build a typed plaintext container box with context tag [1].\n */\nfunction buildPlaintextBox(\n\tdata: Buffer\n): PlaintextBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 1,\n\t\tkind: 'explicit',\n\t\tcontains: [data]\n\t});\n}\n\n/**\n * Build a typed signer info box with context tag [2].\n */\nfunction buildSignerInfoBox(\n\tsignerInfo: SignerInfoASN1\n): SignerInfoBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 2,\n\t\tkind: 'explicit',\n\t\tcontains: signerInfo\n\t});\n}\n\ntype CipherOptions = {\n\t/**\n\t * The symmetric cipher key (if any)\n\t */\n\tcipherKey: Buffer | undefined;\n\t/**\n\t * The symmetric cipher IV (if any)\n\t */\n\tcipherIV: Buffer | undefined;\n\t/**\n\t * The symmetric cipher algorithm\n\t */\n\tcipherAlgo: string;\n}\n\ntype ASN1Options = Required<CipherOptions> & {\n\t/**\n\t * The set of accounts to encrypt the formatted data\n\t */\n\tkeys: Account[];\n}\n\ntype SigningOptions = {\n\t/**\n\t * The account to sign the container with\n\t */\n\tsigner: Account;\n}\n\n/**\n* Compiles the ASN.1 for the container\n*\n* @param plaintext The plaintext data to encode\n* @param encryptionOptions Optional encryption options\n* @param signingOptions Optional signing options (will include SignerInfo)\n* @returns The ASN.1 DER data\n*/\nasync function buildASN1(plaintext: Buffer, encryptionOptions?: ASN1Options, signingOptions?: SigningOptions): Promise<Buffer> {\n\tconst compressedPlaintext = Buffer.from(await zlibDeflateAsync(bufferToArrayBuffer(plaintext)));\n\n\t/*\n\t * Build the container box (encrypted or plaintext)\n\t */\n\tlet containerBox: ContainerBox;\n\tif (encryptionOptions) {\n\t\tconst { keys, cipherKey, cipherIV, cipherAlgo } = encryptionOptions;\n\t\tif (keys === undefined || keys.length === 0 || cipherKey === undefined || cipherIV === undefined || cipherAlgo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Unsupported method invocation'));\n\t\t}\n\t\tif (!(cipherAlgo in oidDB)) {\n\t\t\tthrow(new EncryptedContainerError('UNSUPPORTED_CIPHER_ALGORITHM', `Unsupported algorithm: ${cipherAlgo}`));\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst algorithmOID = oidDB[cipherAlgo as keyof typeof oidDB];\n\t\tconst cipher = crypto.createCipheriv(\n\t\t\tcipherAlgo,\n\t\t\tcipherKey,\n\t\t\tcipherIV\n\t\t);\n\n\t\tconst encryptedData = Buffer.concat([\n\t\t\tcipher.update(compressedPlaintext),\n\t\t\tcipher.final()\n\t\t]);\n\n\t\tconst cipherKeyArrayBuffer = bufferToArrayBuffer(cipherKey);\n\t\tconst encryptionKeysSequence = await Promise.all(keys.map(async function(key) {\n\t\t\tconst encryptedSymmetricKey = Buffer.from(await key.encrypt(cipherKeyArrayBuffer));\n\t\t\tconst retval: EncryptedContainerKeyStore = [\n\t\t\t\tBuffer.from(key.publicKeyAndType),\n\t\t\t\tBuffer.from(encryptedSymmetricKey)\n\t\t\t];\n\n\t\t\treturn(retval);\n\t\t}));\n\n\t\tcontainerBox = buildEncryptedBox(encryptionKeysSequence, algorithmOID, cipherIV, encryptedData);\n\t} else {\n\t\t/*\n\t\t * Otherwise we simply pass in the compressed data\n\t\t */\n\t\tcontainerBox = buildPlaintextBox(Buffer.from(compressedPlaintext));\n\t}\n\n\t/*\n\t * Build the typed container package\n\t */\n\tconst container: ContainerPackage = [1, containerBox];\n\n\tif (signingOptions) {\n\t\t/*\n\t\t * Sign the compressed plaintext (before encryption) so signature is verifiable after decryption\n\t\t */\n\t\tconst { signer } = signingOptions;\n\n\t\tif (!signer.hasPrivateKey) {\n\t\t\tthrow(new EncryptedContainerError('SIGNER_REQUIRES_PRIVATE_KEY', 'Signer account must have a private key'));\n\t\t}\n\n\t\t// Hash the compressed plaintext with SHA3-256\n\t\tconst digestHash = crypto.createHash('sha3-256');\n\t\tdigestHash.update(compressedPlaintext);\n\t\tconst digest = digestHash.digest();\n\n\t\t// Sign the digest\n\t\tconst signatureBuffer = await signer.sign(bufferToArrayBuffer(digest), { raw: true });\n\n\t\t// Get signature as Buffer\n\t\tlet signature: Buffer;\n\t\tif (Buffer.isBuffer(signatureBuffer)) {\n\t\t\tsignature = Buffer.from(signatureBuffer);\n\t\t} else if ('get' in signatureBuffer && typeof signatureBuffer.get === 'function') {\n\t\t\tsignature = arrayBufferToBuffer(signatureBuffer.get());\n\t\t} else {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tsignature = arrayBufferToBuffer(signatureBuffer as unknown as ArrayBuffer);\n\t\t}\n\n\t\tconst signerInfoASN1: SignerInfoASN1 = [\n\t\t\t3, // CMSVersion 3 for subjectKeyIdentifier\n\t\t\t{\n\t\t\t\ttype: 'context',\n\t\t\t\tvalue: 0,\n\t\t\t\tkind: 'implicit',\n\t\t\t\tcontains: Buffer.from(signer.publicKeyAndType)\n\t\t\t},\n\t\t\t{ type: 'oid', oid: oidDB['sha3-256'] },\n\t\t\t{ type: 'oid', oid: getSignatureAlgorithmOID(signer) },\n\t\t\tsignature\n\t\t];\n\n\t\tcontainer.push(buildSignerInfoBox(signerInfoASN1));\n\t}\n\n\tconst outputASN1 = JStoASN1(container);\n\tconst outputDER = arrayBufferToBuffer(outputASN1.toBER(false));\n\treturn(outputDER);\n}\n\nfunction parseASN1Bare(input: Buffer, acceptableEncryptionAlgorithms = ['aes-256-cbc', 'null']) {\n\tconst inputSequence = ASN1toJS(bufferToArrayBuffer(input));\n\tif (!isArray(inputSequence) || inputSequence.length < 2) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_BASE_FORMAT', 'Malformed data detected (incorrect base format)'));\n\t}\n\n\tconst version = inputSequence[0];\n\tif (typeof version !== 'bigint') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_VERSION', 'Malformed data detected (version expected at position 0)'));\n\t}\n\n\tif (version !== 1n) {\n\t\tthrow(new EncryptedContainerError('UNSUPPORTED_VERSION', 'Malformed data detected (unsupported version)'));\n\t}\n\n\tconst valueBox = inputSequence[1];\n\tif (typeof valueBox !== 'object' || valueBox === null) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (data expected at position 1)'));\n\t}\n\n\tif (!('type' in valueBox) || typeof valueBox.type !== 'string') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected type at position 1)'));\n\t}\n\n\tif (valueBox.type !== 'context') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context at position 1)'));\n\t}\n\n\tif (!('value' in valueBox) || typeof valueBox.value !== 'number') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context value at position 1)'));\n\t}\n\n\tif (valueBox.value !== 0 && valueBox.value !== 1) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context value of 0 or 1)'));\n\t}\n\n\tif (!('contains' in valueBox) || typeof valueBox.contains !== 'object' || valueBox.contains === null) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected contents at position 1)'));\n\t}\n\n\tlet isEncrypted;\n\tif (valueBox.value === 0) {\n\t\tisEncrypted = true;\n\t} else {\n\t\tisEncrypted = false;\n\t}\n\n\tconst value = valueBox.contains;\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (isEncrypted) {\n\t\tif (!isArray(value, 4)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (incorrect number of elements within position 1 -- expected 4)'));\n\t\t}\n\n\t\tconst keyInfoUnchecked = value[0];\n\t\tif (!isArray(keyInfoUnchecked)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (expected sequence at position 2.0)'));\n\t\t}\n\n\t\tconst keyInfo = keyInfoUnchecked.map(function(checkKeyInfo) {\n\t\t\tif (!isArray(checkKeyInfo, 2)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected sequence of 2 at position 1.0.x)'));\n\t\t\t}\n\n\t\t\tconst publicKeyBuffer = checkKeyInfo[0];\n\t\t\tif (!Buffer.isBuffer(publicKeyBuffer)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected octet string for public key at position 1.0.x)'));\n\t\t\t}\n\t\t\tconst publicKey = Account.fromPublicKeyAndType(publicKeyBuffer);\n\n\t\t\tconst encryptedSymmetricKey = checkKeyInfo[1];\n\t\t\tif (!Buffer.isBuffer(encryptedSymmetricKey)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected octet string for cipher key at position 1.0.x)'));\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\tpublicKey,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t});\n\t\t});\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tconst encryptionAlgorithmOID = value[1];\n\t\t/* XXX:TODO: Lookup the encryption algorithm from the OID */\n\t\tconst encryptionAlgorithm = 'aes-256-cbc';\n\n\t\tconst cipherIV = value[2];\n\t\tif (!Buffer.isBuffer(cipherIV)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (cipher IV expected at position 1.2)'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = value[3];\n\t\tif (!Buffer.isBuffer(encryptedCompressedValue)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (encrypted compressed buffer expected at position 1.3)'));\n\t\t}\n\n\t\tcipherInfo = {\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tencryptedData: encryptedCompressedValue,\n\t\t\tencryptionAlgorithm: encryptionAlgorithm\n\t\t};\n\n\t\tcontainedCompressed = Buffer.from(encryptedCompressedValue);\n\t} else {\n\t\tif (!isArray(value, 1)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (incorrect number of elements within position 1 -- expected 1)'));\n\t\t}\n\n\t\tconst containedCompressedUnchecked = value[0];\n\t\tif (!Buffer.isBuffer(containedCompressedUnchecked)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (compressed buffer expected at position 1.0)'));\n\t\t}\n\n\t\tif (!acceptableEncryptionAlgorithms.includes('null')) {\n\t\t\tthrow(new EncryptedContainerError('ENCRYPTION_REQUIRED', 'Malformed data (plaintext found but the null encryption algorithm is not acceptable)'));\n\t\t}\n\n\t\tcontainedCompressed = Buffer.from(containedCompressedUnchecked);\n\t}\n\n\t// Parse SignerInfo if present\n\tlet signerInfo: ParsedSignerInfo | undefined;\n\tif (inputSequence.length >= 3) {\n\t\tconst signerInfoBox = inputSequence[2];\n\t\tif (typeof signerInfoBox === 'object' && signerInfoBox !== null &&\n\t\t\t'type' in signerInfoBox && signerInfoBox.type === 'context' &&\n\t\t\t'value' in signerInfoBox && signerInfoBox.value === 2 &&\n\t\t\t'contains' in signerInfoBox && isArray(signerInfoBox.contains, 5)) {\n\n\t\t\tconst signerInfoData = signerInfoBox.contains;\n\n\t\t\t// Parse version\n\t\t\tconst signerVersion = signerInfoData[0];\n\t\t\tif (typeof signerVersion !== 'bigint') {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (version expected at position 0)'));\n\t\t\t}\n\n\t\t\t// Parse sid (subjectKeyIdentifier in context tag [0])\n\t\t\tconst sidBox = signerInfoData[1];\n\t\t\tlet signerPublicKeyAndType: Buffer;\n\t\t\tif (typeof sidBox === 'object' && sidBox !== null &&\n\t\t\t\t'type' in sidBox && sidBox.type === 'context' &&\n\t\t\t\t'value' in sidBox && sidBox.value === 0 &&\n\t\t\t\t'contains' in sidBox && (Buffer.isBuffer(sidBox.contains) || sidBox.contains instanceof ArrayBuffer)) {\n\t\t\t\tsignerPublicKeyAndType = arrayBufferLikeToBuffer(sidBox.contains);\n\t\t\t} else if (Buffer.isBuffer(sidBox)) {\n\t\t\t\t// Handle case where ASN.1 parser unwraps the context tag\n\t\t\t\tsignerPublicKeyAndType = Buffer.from(sidBox);\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (sid expected at position 1)'));\n\t\t\t}\n\n\t\t\t// Parse digestAlgorithm\n\t\t\tconst digestAlgoRaw = signerInfoData[2];\n\t\t\tlet digestAlgorithmOID: string;\n\t\t\tif (typeof digestAlgoRaw === 'object' && digestAlgoRaw !== null &&\n\t\t\t\t'type' in digestAlgoRaw && digestAlgoRaw.type === 'oid' &&\n\t\t\t\t'oid' in digestAlgoRaw && typeof digestAlgoRaw.oid === 'string') {\n\t\t\t\tconst normalized = normalizeToNumericOID(digestAlgoRaw.oid);\n\t\t\t\tif (!normalized) {\n\t\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', `Unknown digest algorithm: ${digestAlgoRaw.oid}`));\n\t\t\t\t}\n\t\t\t\tdigestAlgorithmOID = normalized;\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (digestAlgorithm expected at position 2)'));\n\t\t\t}\n\n\t\t\t// Parse signatureAlgorithm\n\t\t\tconst sigAlgoRaw = signerInfoData[3];\n\t\t\tlet signatureAlgorithmOID: string;\n\t\t\tif (typeof sigAlgoRaw === 'object' && sigAlgoRaw !== null &&\n\t\t\t\t'type' in sigAlgoRaw && sigAlgoRaw.type === 'oid' &&\n\t\t\t\t'oid' in sigAlgoRaw && typeof sigAlgoRaw.oid === 'string') {\n\t\t\t\tconst normalized = normalizeToNumericOID(sigAlgoRaw.oid);\n\t\t\t\tif (!normalized) {\n\t\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', `Unknown signature algorithm: ${sigAlgoRaw.oid}`));\n\t\t\t\t}\n\t\t\t\tsignatureAlgorithmOID = normalized;\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (signatureAlgorithm expected at position 3)'));\n\t\t\t}\n\n\t\t\t// Parse signature\n\t\t\tconst signatureRaw = signerInfoData[4];\n\t\t\tif (!Buffer.isBuffer(signatureRaw)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (signature expected at position 4)'));\n\t\t\t}\n\n\t\t\tsignerInfo = {\n\t\t\t\tversion: Number(signerVersion),\n\t\t\t\tsignerPublicKeyAndType,\n\t\t\t\tdigestAlgorithmOID,\n\t\t\t\tsignatureAlgorithmOID,\n\t\t\t\tsignature: Buffer.from(signatureRaw)\n\t\t\t};\n\t\t}\n\t}\n\n\treturn({\n\t\tversion: version,\n\t\tisEncrypted: isEncrypted,\n\t\tinnerValue: containedCompressed,\n\t\tsignerInfo,\n\t\t...cipherInfo\n\t});\n}\n\nasync function parseASN1Decrypt(inputInfo: ReturnType<typeof parseASN1Bare>, keys?: Account[]) {\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (inputInfo.isEncrypted) {\n\t\tif (keys === undefined || keys.length === 0) {\n\t\t\tthrow(new EncryptedContainerError('NO_KEYS_PROVIDED', 'Encrypted Container found with encryption but no keys for decryption supplied'));\n\t\t}\n\n\t\tconst algorithm = inputInfo.encryptionAlgorithm;\n\t\tif (algorithm === undefined) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Encrypted Container found with encryption but no algorithm supplied'));\n\t\t}\n\n\t\tconst keyInfo = inputInfo.keys;\n\t\tif (keyInfo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Encrypted container found with missing keys'));\n\t\t}\n\n\t\tlet decryptionKeyInfo;\n\t\tfor (const checkKeyInfo of keyInfo) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!key.hasPrivateKey) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (key.comparePublicKey(checkKeyInfo.publicKey)) {\n\t\t\t\t\tdecryptionKeyInfo = {\n\t\t\t\t\t\t...checkKeyInfo,\n\t\t\t\t\t\tprivateKey: key\n\t\t\t\t\t};\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (decryptionKeyInfo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_MATCHING_KEY', 'No keys found which can perform decryption on the supplied encryption box'));\n\t\t}\n\n\t\tlet cipherKey: Buffer;\n\t\ttry {\n\t\t\tconst dataToDecrypt = bufferToArrayBuffer(decryptionKeyInfo.encryptedSymmetricKey);\n\t\t\tcipherKey = arrayBufferLikeToBuffer(await decryptionKeyInfo.privateKey.decrypt(dataToDecrypt));\n\t\t} catch (err) {\n\t\t\tthrow(new EncryptedContainerError('DECRYPTION_FAILED', `Key decryption failed: ${err instanceof Error ? err.message : String(err)}`));\n\t\t}\n\n\t\tconst cipherIV = inputInfo.cipherIV;\n\t\tif (cipherIV === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'No Cipher IV found'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = inputInfo.innerValue;\n\t\tconst decipher = crypto.createDecipheriv(algorithm, cipherKey, cipherIV);\n\t\ttry {\n\t\t\tcontainedCompressed = Buffer.concat([\n\t\t\t\tdecipher.update(encryptedCompressedValue),\n\t\t\t\tdecipher.final()\n\t\t\t]);\n\t\t} catch (err) {\n\t\t\tthrow(new EncryptedContainerError('DECRYPTION_FAILED', `Cipher decryption failed: ${err instanceof Error ? err.message : String(err)}`));\n\t\t}\n\n\t\tcipherInfo = {\n\t\t\tisEncrypted: true,\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tcipherKey: cipherKey,\n\t\t\tencryptedData: encryptedCompressedValue\n\t\t};\n\t} else {\n\t\tcontainedCompressed = inputInfo.innerValue;\n\t\tcipherInfo = {\n\t\t\tisEncrypted: false\n\t\t};\n\t}\n\n\tlet plaintext: Buffer;\n\ttry {\n\t\tconst inflated = await zlibInflateAsync(bufferToArrayBuffer(containedCompressed));\n\t\tplaintext = arrayBufferLikeToBuffer(inflated);\n\t} catch (err) {\n\t\tthrow(new EncryptedContainerError('DECOMPRESSION_FAILED', `Inflate failed: ${err instanceof Error ? err.message : String(err)}`));\n\t}\n\n\treturn({\n\t\tversion: inputInfo.version,\n\t\tplaintext: plaintext,\n\t\t...cipherInfo\n\t});\n\n}\n\nasync function parseASN1(input: Buffer, keys?: Account[]) {\n\tconst inputInfo = parseASN1Bare(input);\n\tconst retval = await parseASN1Decrypt(inputInfo, keys);\n\n\treturn(retval);\n}\n\nfunction inputToBuffer(data: string | ArrayBuffer | Buffer): Buffer {\n\tif (typeof data === 'string') {\n\t\treturn(Buffer.from(data, 'utf-8'));\n\t} else if (Buffer.isBuffer(data)) {\n\t\treturn(data);\n\t} else {\n\t\treturn(arrayBufferToBuffer(data));\n\t}\n}\n\ntype EncryptedContainerInfo = Pick<CipherOptions, 'cipherAlgo'> & {\n\t/**\n\t * Set of accounts which can access the data\n\t */\n\tprincipals: Account[];\n}\n\ntype UnencryptedContainerInfo = {\n\t/**\n\t * Unencrypted container should not have any principals\n\t */\n\tprincipals: null;\n}\n\ntype ContainerSigningInfo = {\n\t/**\n\t * The account to sign the container with (for new containers)\n\t */\n\tsigner?: Account;\n\n\t/**\n\t * Parsed signer info from an existing container\n\t */\n\tparsedSignerInfo?: ParsedSignerInfo;\n}\n\nexport class EncryptedContainer {\n\tprivate static readonly algorithm = 'aes-256-cbc';\n\n\t/**\n\t * Flag indicating whether we support exporting the plaintext\n\t */\n\t#mayAccessPlaintext = true;\n\n\t/**\n\t * Encryption details\n\t */\n\tprotected _internalState: EncryptedContainerInfo | UnencryptedContainerInfo;\n\n\t/**\n\t * Signing information\n\t */\n\t#signingInfo: ContainerSigningInfo = {};\n\n\t/**\n\t * The plaintext or encoded (and possibly encrypted) data\n\t */\n\t#data:\n\t\t{ plaintext: Buffer } |\n\t\t{ encoded: Buffer } |\n\t\t{ plaintext: Buffer, encoded: Buffer };\n\n\tconstructor(principals: Account[] | null, signer?: Account) {\n\t\tif (principals === null) {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: null\n\t\t\t};\n\t\t} else {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: principals,\n\t\t\t\tcipherAlgo: EncryptedContainer.algorithm\n\t\t\t}\n\t\t};\n\t\tthis.#data = { plaintext: Buffer.alloc(0) };\n\n\t\tif (signer) {\n\t\t\tthis.#signingInfo.signer = signer;\n\t\t}\n\t}\n\n\tget encrypted(): boolean {\n\t\treturn(this._internalState.principals !== null);\n\t}\n\n\t#isEncrypted(): this is { _internalState: EncryptedContainerInfo } {\n\t\treturn(this.encrypted);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from an encrypted blob,\n\t * it will need to be decryptable with one of the specified principals\n\t *\n\t * After decryption happens, the list of principals with access to the\n\t * resource will be reset to what is contained within the encrypted\n\t * container\n\t */\n\tstatic fromEncryptedBuffer(data: ArrayBuffer | Buffer, principals: Account[]): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(true);\n\n\t\treturn(retval);\n\t}\n\n\tstatic fromEncodedBuffer(data: ArrayBuffer | Buffer, principals: Account[] | null): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(false);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from a plaintext.\n\t *\n\t * It will be decryptable by any one of the specified principals\n\t *\n\t * @param data The plaintext data to encrypt or encode\n\t * @param principals The list of principals who can access the data if it is null then the data is not encrypted\n\t * @param options Options including locked (plaintext accessibility) and signer (for RFC 5652 signing). For backward compatibility, can also be a boolean for locked.\n\t * @returns The EncryptedContainer instance with the plaintext data and principals set\n\t */\n\tstatic fromPlaintext(data: string | ArrayBuffer | Buffer, principals: Account[] | null, options?: boolean | FromPlaintextOptions): EncryptedContainer {\n\t\t// Handle backward compatibility - if options is a boolean, treat it as the locked flag\n\t\tlet lockedOpt: boolean | undefined;\n\t\tlet signer: Account | undefined;\n\n\t\tif (typeof options === 'boolean') {\n\t\t\tlockedOpt = options;\n\t\t} else if (options !== undefined) {\n\t\t\tlockedOpt = options.locked;\n\t\t\tsigner = options.signer;\n\t\t}\n\n\t\tconst retval = new EncryptedContainer(principals, signer);\n\n\t\tlet locked = lockedOpt;\n\t\tif (locked === undefined) {\n\t\t\tlocked = true;\n\t\t\tif (principals === null) {\n\t\t\t\tlocked = false;\n\t\t\t}\n\t\t}\n\n\t\tif (locked) {\n\t\t\tretval.disablePlaintext();\n\t\t}\n\n\t\tretval.setPlaintext(data);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Set the plaintext buffer to the specified value\n\t */\n\tsetPlaintext(data: string | ArrayBuffer | Buffer): void {\n\t\tthis.#data = { plaintext: inputToBuffer(data) };\n\t}\n\n\t/**\n\t * Set the encoded blob to the specified value\n\t */\n\t#setEncodedBuffer(data: ArrayBuffer | Buffer): void {\n\t\tthis.#data = { encoded: inputToBuffer(data) };\n\t}\n\n\tprivate get _encoded(): Buffer | undefined {\n\t\tif ('encoded' in this.#data && this.#data.encoded !== undefined) {\n\t\t\treturn(this.#data.encoded);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\tprivate get _plaintext(): Buffer | undefined {\n\t\tif ('plaintext' in this.#data && this.#data.plaintext !== undefined) {\n\t\t\treturn(this.#data.plaintext);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\t/*\n\t * Return the decoded data from the encoded blob\n\t * and populate the symmetric key parameters from the encoded blob if it is encrypted\n\t */\n\t#computeAndSetKeyInfo(mustBeEncrypted: boolean) {\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_ENCODED_DATA_AVAILABLE', 'No encoded data available'));\n\t\t}\n\n\t\tconst plaintextWrapper = parseASN1Bare(this._encoded);\n\n\t\tif (mustBeEncrypted && !plaintextWrapper.isEncrypted) {\n\t\t\tthrow(new EncryptedContainerError('ENCRYPTION_REQUIRED', 'Unable to set key information from plaintext -- it is not encrypted but that was required'));\n\t\t}\n\n\t\tif (plaintextWrapper.isEncrypted) {\n\t\t\tconst principals = this._internalState.principals;\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new EncryptedContainerError('INVALID_PRINCIPALS', 'May not encrypt data with a null set of principals'));\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Compute the new accounts by merging the input from the\n\t\t\t * data and the existing list of principals\n\t\t\t */\n\t\t\t/**\n\t\t\t * The existing principals from the blob, with existing\n\t\t\t * principals substituted in where appropriate\n\t\t\t */\n\t\t\tconst blobPrincipals = (plaintextWrapper.keys ?? []).map((keyInfo) => {\n\t\t\t\tconst currentPublicKey = keyInfo.publicKey;\n\t\t\t\tif (!currentPublicKey.isAccount()) {\n\t\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Non-account found within the encryption key list'));\n\t\t\t\t}\n\n\t\t\t\tfor (const checkExistingKey of principals) {\n\t\t\t\t\tif (checkExistingKey.comparePublicKey(currentPublicKey)) {\n\t\t\t\t\t\treturn(checkExistingKey);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn(currentPublicKey);\n\t\t\t});\n\n\t\t\tthis._internalState.principals = blobPrincipals;\n\n\t\t\t// Confirm updated principals are populated correctly which sets container to encrypted\n\t\t\tif (!this.encrypted) {\n\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Encrypted data found but not marked as encrypted'));\n\t\t\t}\n\t\t} else {\n\t\t\tthis._internalState.principals = null;\n\n\t\t\tif (this.encrypted) {\n\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Plaintext data found but marked as encrypted'));\n\t\t\t}\n\t\t}\n\n\t\t// Store parsed signer info if present\n\t\tif (plaintextWrapper.signerInfo) {\n\t\t\tthis.#signingInfo.parsedSignerInfo = plaintextWrapper.signerInfo;\n\t\t}\n\n\t\treturn(plaintextWrapper);\n\t}\n\n\t/**\n\t * Populate the plaintext (as well as symmetric key parameters) from\n\t * the encoded blob\n\t */\n\tasync #computePlaintext() {\n\t\tif (this._plaintext) {\n\t\t\treturn(this._plaintext);\n\t\t}\n\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_ENCODED_DATA_AVAILABLE', 'No plaintext or encoded data available'));\n\t\t}\n\n\n\t\tconst info = this.#computeAndSetKeyInfo(this.encrypted);\n\n\t\tlet principals = this._internalState.principals;\n\t\tif (info.isEncrypted) {\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new EncryptedContainerError('INVALID_PRINCIPALS', 'May not decrypt data with a null set of principals'));\n\t\t\t}\n\t\t} else {\n\t\t\tprincipals = [];\n\t\t}\n\n\t\tconst plaintextWrapper = await parseASN1Decrypt(info, principals);\n\t\tconst plaintext = Buffer.from(plaintextWrapper.plaintext);\n\n\t\tthis.#data = { ...this.#data, plaintext };\n\n\t\treturn(plaintext);\n\t}\n\n\t/**\n\t * Compute the encoded version of the plaintext data\n\t */\n\tasync #computePlaintextEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'No plaintext data available'));\n\t\t}\n\n\t\tconst signingOptions = this.#signingInfo.signer\n\t\t\t? { signer: this.#signingInfo.signer }\n\t\t\t: undefined;\n\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext,\n\t\t\tundefined,\n\t\t\tsigningOptions\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\t/**\n\t * Populate the encrypted blob from the plaintext and symmetric key\n\t * parameters. If the symmetric key parameters have not been\n\t * initialized they will be initialized at this time.\n\t */\n\tasync #computeEncryptedEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'No encrypted nor plaintext data available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Asked to encrypt a plaintext buffer'));\n\t\t}\n\n\t\tconst signingOptions = this.#signingInfo.signer\n\t\t\t? { signer: this.#signingInfo.signer }\n\t\t\t: undefined;\n\n\t\t/**\n\t\t * structured data is the ASN.1 encoded structure\n\t\t */\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext,\n\t\t\t{\n\t\t\t\tkeys: this._internalState.principals,\n\t\t\t\tcipherKey: Buffer.from(crypto.randomBytes(32)),\n\t\t\t\tcipherIV: Buffer.from(crypto.randomBytes(16)),\n\t\t\t\tcipherAlgo: this._internalState.cipherAlgo\n\t\t\t},\n\t\t\tsigningOptions\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\tasync #computeEncoded() {\n\t\tif (this._encoded !== undefined) {\n\t\t\treturn(this._encoded);\n\t\t}\n\n\t\tlet computed: Buffer;\n\t\tif (!this.encrypted) {\n\t\t\tcomputed = await this.#computePlaintextEncoded();\n\t\t} else {\n\t\t\tcomputed = await this.#computeEncryptedEncoded();\n\t\t}\n\n\t\tthis.#data = { ...this.#data, encoded: computed };\n\n\t\treturn(computed);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s) synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\tgrantAccessSync(accounts: Account[] | Account): this {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to grant access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\tif (!Array.isArray(accounts)) {\n\t\t\taccounts = [accounts];\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals.push(...accounts);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s).\n\t */\n\tasync grantAccess(accounts: Account[] | Account): Promise<this> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.grantAccessSync(accounts);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\trevokeAccessSync(account: Account): this {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to revoke access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals = this._internalState.principals.filter(function(checkAccount) {\n\t\t\treturn(!checkAccount.comparePublicKey(account));\n\t\t});\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account\n\t */\n\tasync revokeAccess(account: Account): Promise<this> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.revokeAccessSync(account);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Disable access to the plaintext from this instance\n\t */\n\tdisablePlaintext(): this {\n\t\tthis.#mayAccessPlaintext = false;\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Get the plaintext for this instance\n\t */\n\tasync getPlaintext(): Promise<ArrayBuffer> {\n\t\tif (!this.#mayAccessPlaintext) {\n\t\t\tthrow(new EncryptedContainerError('PLAINTEXT_DISABLED', 'May not access plaintext'));\n\t\t}\n\n\t\tconst plaintext = await this.#computePlaintext();\n\n\t\tif (plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Plaintext could not be decoded'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(bufferToArrayBuffer(plaintext));\n\t}\n\n\t/**\n\t * Get the serializable buffer which can be stored and reconstructed\n\t */\n\tasync getEncodedBuffer(): Promise<ArrayBuffer> {\n\t\tconst serialized = await this.#computeEncoded();\n\n\t\tif (serialized === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Could not encode data'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(bufferToArrayBuffer(serialized));\n\t}\n\n\t/**\n\t * Get the list of accounts which have access to read the plaintext of\n\t * this container\n\t */\n\tget principals(): Account[] {\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\treturn(this._internalState.principals);\n\t}\n\n\t/**\n\t * Check if this container is signed\n\t */\n\tget isSigned(): boolean {\n\t\treturn(this.#signingInfo.signer !== undefined || this.#signingInfo.parsedSignerInfo !== undefined);\n\t}\n\n\t/**\n\t * Get the signing account of this container.\n\t */\n\tgetSigningAccount(): Account | undefined {\n\t\t// If we have a signer account set (for new containers), return it\n\t\tif (this.#signingInfo.signer) {\n\t\t\treturn(this.#signingInfo.signer);\n\t\t}\n\n\t\t// If we have parsed signer info (from encoded container), construct account from it\n\t\tif (this.#signingInfo.parsedSignerInfo) {\n\t\t\tconst { signerPublicKeyAndType } = this.#signingInfo.parsedSignerInfo;\n\t\t\treturn(Account.fromPublicKeyAndType(signerPublicKeyAndType));\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\t/**\n\t * Verify the signature on this container.\n\t * This requires decrypting the container first to access the compressed plaintext.\n\t *\n\t * @returns true if signature is valid, false if invalid, or throws if not signed or plaintext unavailable\n\t */\n\tasync verifySignature(): Promise<boolean> {\n\t\t// If we have a signer but no parsed info yet, encode first to produce the signed DER\n\t\tif (!this.#signingInfo.parsedSignerInfo && this.#signingInfo.signer) {\n\t\t\tconst encoded = await this.#computeEncoded();\n\t\t\tif (encoded) {\n\t\t\t\tconst parsed = parseASN1Bare(encoded);\n\t\t\t\tif (parsed.signerInfo) {\n\t\t\t\t\tthis.#signingInfo.parsedSignerInfo = parsed.signerInfo;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!this.#signingInfo.parsedSignerInfo) {\n\t\t\tthrow(new EncryptedContainerError('NOT_SIGNED', 'Container is not signed'));\n\t\t}\n\n\t\tconst signerInfo = this.#signingInfo.parsedSignerInfo;\n\n\t\t// Validate digest algorithm OID\n\t\tif (!supportedDigestOIDs.has(signerInfo.digestAlgorithmOID)) {\n\t\t\tthrow(new EncryptedContainerError(\n\t\t\t\t'UNSUPPORTED_DIGEST_ALGORITHM',\n\t\t\t\t`Unsupported digest algorithm OID: ${signerInfo.digestAlgorithmOID}`\n\t\t\t));\n\t\t}\n\n\t\t// Validate signature algorithm OID\n\t\tif (!supportedSignatureOIDs.has(signerInfo.signatureAlgorithmOID)) {\n\t\t\tthrow(new EncryptedContainerError(\n\t\t\t\t'UNSUPPORTED_SIGNATURE_ALGORITHM',\n\t\t\t\t`Unsupported signature algorithm OID: ${signerInfo.signatureAlgorithmOID}`\n\t\t\t));\n\t\t}\n\n\t\t// We need the plaintext to verify the signature\n\t\tconst plaintext = await this.#computePlaintext();\n\t\tif (!plaintext) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to compute plaintext for signature verification'));\n\t\t}\n\n\t\t// Recompute the digest of the compressed plaintext\n\t\tconst compressedPlaintext = Buffer.from(await zlibDeflateAsync(bufferToArrayBuffer(plaintext)));\n\t\tconst digestHash = crypto.createHash('sha3-256');\n\t\tdigestHash.update(compressedPlaintext);\n\t\tconst digest = digestHash.digest();\n\n\t\t// Get the signer's account (public key only)\n\t\tconst signerAccount = Account.fromPublicKeyAndType(signerInfo.signerPublicKeyAndType);\n\n\t\t// Verify the signature\n\t\tconst signature = signerInfo.signature;\n\t\tconst isValid = signerAccount.verify(\n\t\t\tbufferToArrayBuffer(digest),\n\t\t\tbufferToArrayBuffer(signature),\n\t\t\t{ raw: true }\n\t\t);\n\n\t\treturn(isValid);\n\t}\n}\n\n/** @internal */\nexport const _Testing = {\n\tbuildASN1: buildASN1,\n\tparseASN1: parseASN1\n};\n\nexport default EncryptedContainer;\n"]}
|
|
1
|
+
{"version":3,"file":"encrypted-container.js","sourceRoot":"","sources":["../../src/lib/encrypted-container.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,yBAAyB;AAEzB;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,yBAAyB;IACzB,uBAAuB;IACvB,mBAAmB;IACnB,0BAA0B;IAC1B,oBAAoB;IACpB,uBAAuB;IAEvB,mBAAmB;IACnB,qBAAqB;IACrB,8BAA8B;IAC9B,8BAA8B;IAC9B,iCAAiC;IACjC,sBAAsB;IAEtB,wBAAwB;IACxB,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IAEtB,iBAAiB;IACjB,6BAA6B;IAC7B,YAAY;IACZ,+BAA+B;IAE/B,eAAe;IACf,wBAAwB;IACxB,2BAA2B;IAC3B,oBAAoB;IAEpB,oBAAoB;IACpB,qBAAqB;IACrB,oBAAoB;IACpB,+BAA+B;IAE/B,kBAAkB;IAClB,gBAAgB;CACP,CAAC;AAOX;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAC5D,MAA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AmB,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;QAEnC,6CAA6C;QAC7C,MAAM,aAAa,GAAG,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;QAEtF,uBAAuB;QACvB,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QACvC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CACnC,mBAAmB,CAAC,MAAM,CAAC,EAC3B,mBAAmB,CAAC,SAAS,CAAC,EAC9B,EAAE,GAAG,EAAE,IAAI,EAAE,CACb,CAAC;QAEF,OAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;;AAGF,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;CACpB,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import crypto from './utils/crypto.js';\nimport { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport type {\n\tASN1OID\n} from '@keetanetwork/keetanet-client/lib/utils/asn1.js';\nimport { Buffer, arrayBufferToBuffer, arrayBufferLikeToBuffer, bufferToArrayBuffer } from './utils/buffer.js';\nimport { isArray } from './utils/array.js';\nimport { KeetaAnchorError } from './error.js';\n\n// #region Error Handling\n\n/**\n * Error codes for EncryptedContainer operations\n */\nexport const EncryptedContainerErrorCodes = [\n\t// Parsing/Malformed data\n\t'MALFORMED_BASE_FORMAT',\n\t'MALFORMED_VERSION',\n\t'MALFORMED_DATA_STRUCTURE',\n\t'MALFORMED_KEY_INFO',\n\t'MALFORMED_SIGNER_INFO',\n\n\t// Algorithm issues\n\t'UNSUPPORTED_VERSION',\n\t'UNSUPPORTED_CIPHER_ALGORITHM',\n\t'UNSUPPORTED_DIGEST_ALGORITHM',\n\t'UNSUPPORTED_SIGNATURE_ALGORITHM',\n\t'UNSUPPORTED_KEY_TYPE',\n\n\t// Key/Decryption issues\n\t'NO_KEYS_PROVIDED',\n\t'NO_MATCHING_KEY',\n\t'DECRYPTION_FAILED',\n\t'DECOMPRESSION_FAILED',\n\n\t// Signing issues\n\t'SIGNER_REQUIRES_PRIVATE_KEY',\n\t'NOT_SIGNED',\n\t'SIGNATURE_VERIFICATION_FAILED',\n\n\t// State issues\n\t'NO_PLAINTEXT_AVAILABLE',\n\t'NO_ENCODED_DATA_AVAILABLE',\n\t'PLAINTEXT_DISABLED',\n\n\t// Access management\n\t'ENCRYPTION_REQUIRED',\n\t'INVALID_PRINCIPALS',\n\t'ACCESS_MANAGEMENT_NOT_ALLOWED',\n\n\t// Internal errors\n\t'INTERNAL_ERROR'\n] as const;\n\n/**\n * Error code type\n */\nexport type EncryptedContainerErrorCode = typeof EncryptedContainerErrorCodes[number];\n\n/**\n * Error class for EncryptedContainer operations\n */\nexport class EncryptedContainerError extends KeetaAnchorError {\n\tstatic override readonly name: string = 'EncryptedContainerError';\n\n\tprivate readonly encryptedContainerErrorObjectTypeID!: string;\n\tprivate static readonly encryptedContainerErrorObjectTypeID = 'f4a8c2e1-7b3d-4f9a-8c5e-2d1f0a9b8c7e';\n\n\treadonly code: EncryptedContainerErrorCode;\n\n\t/**\n\t * Check if a string is a valid EncryptedContainerErrorCode\n\t */\n\tstatic isValidCode(code: string): code is EncryptedContainerErrorCode {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(EncryptedContainerErrorCodes.includes(code as EncryptedContainerErrorCode));\n\t}\n\n\tconstructor(code: EncryptedContainerErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\t// EncryptedContainerError is not a user error\n\t\tthis.userError = false;\n\n\t\tObject.defineProperty(this, 'encryptedContainerErrorObjectTypeID', {\n\t\t\tvalue: EncryptedContainerError.encryptedContainerErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is EncryptedContainerError {\n\t\treturn(this.hasPropWithValue(input, 'encryptedContainerErrorObjectTypeID', EncryptedContainerError.encryptedContainerErrorObjectTypeID));\n\t}\n\n\toverride toJSON(): ReturnType<KeetaAnchorError['toJSON']> & { code: EncryptedContainerErrorCode } {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tcode: this.code\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<EncryptedContainerError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract and validate code\n\t\tif (!('code' in other) || typeof other.code !== 'string') {\n\t\t\tthrow(new Error('Invalid EncryptedContainerError JSON: missing code property'));\n\t\t}\n\n\t\t// Validate code is a valid EncryptedContainerErrorCode\n\t\tconst code = other.code;\n\t\tif (!this.isValidCode(code)) {\n\t\t\tthrow(new Error(`Invalid EncryptedContainerError JSON: unknown code ${code}`));\n\t\t}\n\n\t\tconst error = new this(code, message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\n// #endregion\n\nconst zlibDeflateAsync = KeetaNetLib.Utils.Buffer.ZlibDeflateAsync;\nconst zlibInflateAsync = KeetaNetLib.Utils.Buffer.ZlibInflateAsync;\nconst ASN1toJS = KeetaNetLib.Utils.ASN1.ASN1toJS;\nconst JStoASN1 = KeetaNetLib.Utils.ASN1.JStoASN1;\nconst Account: typeof KeetaNetLib.Account = KeetaNetLib.Account;\ntype Account = InstanceType<typeof KeetaNetLib.Account>;\n\n/**\n * Options for creating an EncryptedContainer from plaintext\n */\nexport type FromPlaintextOptions = {\n\tlocked?: boolean;\n\tsigner?: Account;\n};\n\n/*\n * ASN.1 Schema\n *\n * EncryptedContainer DEFINITIONS ::=\n * BEGIN\n * Version ::= INTEGER { v2(1) }\n *\n * KeyStore ::= SEQUENCE {\n * publicKey OCTET STRING,\n * encryptedSymmetricKey OCTET STRING,\n * ...\n * }\n *\n * EncryptedContainerBox ::= SEQUENCE {\n * keys SEQUENCE OF KeyStore,\n * encryptionAlgorithm OBJECT IDENTIFIER,\n * initializationVector OCTET STRING,\n * encryptedValue OCTET STRING,\n * ...\n * }\n *\n * PlaintextContainerBox ::= SEQUENCE {\n * plainValue OCTET STRING,\n * ...\n * }\n *\n * -- RFC 5652 Section 5.3 SignerInfo (adapted for KeetaNet)\n * SignerInfo ::= SEQUENCE {\n * version CMSVersion, -- INTEGER (3 for subjectKeyIdentifier)\n * sid [0] SubjectKeyIdentifier, -- OCTET STRING (publicKeyAndType)\n * digestAlgorithm OBJECT IDENTIFIER, -- SHA3-256: 2.16.840.1.101.3.4.2.8\n * signatureAlgorithm OBJECT IDENTIFIER, -- Derived from account type\n * signature OCTET STRING,\n * ...\n * }\n *\n * ContainerPackage ::= SEQUENCE {\n * version Version,\n * encryptedContainer [0] EXPLICIT EncryptedContainerBox OPTIONAL,\n * plaintextContainer [1] EXPLICIT PlaintextContainerBox OPTIONAL,\n * signerInfo [2] EXPLICIT SignerInfo OPTIONAL,\n * ...\n * } (WITH COMPONENTS {\n * encryptedContainer PRESENT,\n * plaintextContainer ABSENT\n * } |\n * WITH COMPONENTS {\n * encryptedContainer ABSENT,\n * plaintextContainer PRESENT\n * })\n * END\n *\n */\n\n/**\n * OID constants for cryptographic algorithms\n * // XXX:TODO: We should standardize this somewhere centralized\n */\nconst oidDB = {\n\t// Digest algorithms\n\t'sha3-256': '2.16.840.1.101.3.4.2.8',\n\n\t// Signature algorithms\n\t'ed25519': '1.3.101.112',\n\t'secp256k1': '1.3.132.0.10',\n\t'secp256r1': '1.2.840.10045.3.1.7',\n\n\t// Encryption algorithms\n\t'aes-256-cbc': '2.16.840.1.101.3.4.1.42'\n} as const;\n\n/**\n * Supported algorithms\n * These are the canonical names as defined in oidDB\n */\nconst SUPPORTED_DIGEST_ALGORITHMS = ['sha3-256'] as const;\nconst SUPPORTED_SIGNATURE_ALGORITHMS = ['ed25519', 'secp256k1', 'secp256r1'] as const;\n\n/**\n * Known OID aliases that ASN1 parsers may return instead of our canonical names\n */\nconst OID_ALIASES: { [alias: string]: keyof typeof oidDB } = {\n\t'prime256v1': 'secp256r1'\n};\n\n/**\n * Build reverse lookup: name/alias -> numeric OID\n */\nconst nameToNumericOID: { [name: string]: string } = {};\nfor (const [name, numericOID] of Object.entries(oidDB)) {\n\tnameToNumericOID[name] = numericOID;\n}\nfor (const [alias, canonicalName] of Object.entries(OID_ALIASES)) {\n\tnameToNumericOID[alias] = oidDB[canonicalName];\n}\n\n/**\n * Normalize an OID (name, alias, or already numeric) to its numeric form.\n * Returns undefined if the OID is not recognized.\n */\nfunction normalizeToNumericOID(oid: string): string | undefined {\n\tif (/^\\d+(\\.\\d+)*$/.test(oid)) {\n\t\treturn(oid);\n\t}\n\n\t// Otherwise look up the name/alias\n\treturn(nameToNumericOID[oid]);\n}\n\n// Pre-compute supported numeric OIDs for validation\nconst supportedDigestOIDs = new Set<string>(SUPPORTED_DIGEST_ALGORITHMS.map(name => oidDB[name]));\nconst supportedSignatureOIDs = new Set<string>(SUPPORTED_SIGNATURE_ALGORITHMS.map(name => oidDB[name]));\n\n/**\n * Map account key algorithm to signature algorithm OID\n */\nfunction getSignatureAlgorithmOID(account: Account): string {\n\tconst keyType = account.keyType;\n\tconst KeyAlgo = Account.AccountKeyAlgorithm;\n\n\tif (keyType === KeyAlgo.ECDSA_SECP256K1) {\n\t\treturn(oidDB['secp256k1']);\n\t} else if (keyType === KeyAlgo.ED25519) {\n\t\treturn(oidDB['ed25519']);\n\t} else if (keyType === KeyAlgo.ECDSA_SECP256R1) {\n\t\treturn(oidDB['secp256r1']);\n\t}\n\n\tthrow(new EncryptedContainerError('UNSUPPORTED_KEY_TYPE', `Unsupported key type for signing: ${keyType}`));\n}\n\n/**\n * SignerInfo structure for RFC 5652 CMS compatibility\n */\ntype SignerInfoASN1 = [\n\t/* version - CMSVersion (3 for subjectKeyIdentifier) */\n\tnumber,\n\n\t/* sid - SubjectKeyIdentifier wrapped in context tag [0] */\n\t{\n\t\ttype: 'context',\n\t\tvalue: 0,\n\t\tkind: 'implicit',\n\t\tcontains: Buffer\n\t},\n\n\t/* digestAlgorithm */\n\tASN1OID,\n\n\t/* signatureAlgorithm */\n\tASN1OID,\n\n\t/* signature */\n\tBuffer\n];\n\n/**\n * Parsed SignerInfo data\n */\ntype ParsedSignerInfo = {\n\tversion: number;\n\tsignerPublicKeyAndType: Buffer;\n\tdigestAlgorithmOID: string;\n\tsignatureAlgorithmOID: string;\n\tsignature: Buffer;\n};\n\ntype EncryptedContainerKeyStore = [\n\t/* publicKey */\n\tBuffer,\n\n\t/* encryptedSymmetricKey */\n\tBuffer\n];\n\ntype EncryptedContainerBoxEncrypted = [\n\t/* keys */\n\tEncryptedContainerKeyStore[],\n\n\t/* encryptionAlgorithm */\n\tASN1OID,\n\n\t/* initializationVector */\n\tBuffer,\n\n\t/* value */\n\tBuffer\n];\n\ntype EncryptedContainerBoxPlaintext = [\n\t/* value */\n\tBuffer\n];\n\ntype SignerInfoBoxContext = {\n\ttype: 'context',\n\tvalue: 2,\n\tkind: 'explicit',\n\tcontains: SignerInfoASN1\n};\n\ntype ContainerPackage = [\n\t/* version */\n\tnumber,\n\n\t/* container */\n\tContainerBox,\n\n\t/* signerInfo (optional) */\n\tSignerInfoBoxContext?\n];\n\ntype EncryptedBoxContext = {\n\ttype: 'context',\n\tvalue: 0,\n\tkind: 'explicit',\n\tcontains: EncryptedContainerBoxEncrypted\n};\n\ntype PlaintextBoxContext = {\n\ttype: 'context',\n\tvalue: 1,\n\tkind: 'explicit',\n\tcontains: EncryptedContainerBoxPlaintext\n};\n\ntype ContainerBox = EncryptedBoxContext | PlaintextBoxContext;\n\n/**\n * Build a typed encrypted container box with context tag [0].\n */\nfunction buildEncryptedBox(\n\tkeys: EncryptedContainerKeyStore[],\n\talgorithmOID: string,\n\tiv: Buffer,\n\tencryptedData: Buffer\n): EncryptedBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 0,\n\t\tkind: 'explicit',\n\t\tcontains: [keys, { type: 'oid', oid: algorithmOID }, iv, encryptedData]\n\t});\n}\n\n/**\n * Build a typed plaintext container box with context tag [1].\n */\nfunction buildPlaintextBox(\n\tdata: Buffer\n): PlaintextBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 1,\n\t\tkind: 'explicit',\n\t\tcontains: [data]\n\t});\n}\n\n/**\n * Build a typed signer info box with context tag [2].\n */\nfunction buildSignerInfoBox(\n\tsignerInfo: SignerInfoASN1\n): SignerInfoBoxContext {\n\treturn({\n\t\ttype: 'context',\n\t\tvalue: 2,\n\t\tkind: 'explicit',\n\t\tcontains: signerInfo\n\t});\n}\n\ntype CipherOptions = {\n\t/**\n\t * The symmetric cipher key (if any)\n\t */\n\tcipherKey: Buffer | undefined;\n\t/**\n\t * The symmetric cipher IV (if any)\n\t */\n\tcipherIV: Buffer | undefined;\n\t/**\n\t * The symmetric cipher algorithm\n\t */\n\tcipherAlgo: string;\n}\n\ntype ASN1Options = Required<CipherOptions> & {\n\t/**\n\t * The set of accounts to encrypt the formatted data\n\t */\n\tkeys: Account[];\n}\n\ntype SigningOptions = {\n\t/**\n\t * The account to sign the container with\n\t */\n\tsigner: Account;\n}\n\n/**\n* Compiles the ASN.1 for the container\n*\n* @param plaintext The plaintext data to encode\n* @param encryptionOptions Optional encryption options\n* @param signingOptions Optional signing options (will include SignerInfo)\n* @returns The ASN.1 DER data\n*/\nasync function buildASN1(plaintext: Buffer, encryptionOptions?: ASN1Options, signingOptions?: SigningOptions): Promise<Buffer> {\n\tconst compressedPlaintext = Buffer.from(await zlibDeflateAsync(bufferToArrayBuffer(plaintext)));\n\n\t/*\n\t * Build the container box (encrypted or plaintext)\n\t */\n\tlet containerBox: ContainerBox;\n\tif (encryptionOptions) {\n\t\tconst { keys, cipherKey, cipherIV, cipherAlgo } = encryptionOptions;\n\t\tif (keys === undefined || keys.length === 0 || cipherKey === undefined || cipherIV === undefined || cipherAlgo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Unsupported method invocation'));\n\t\t}\n\t\tif (!(cipherAlgo in oidDB)) {\n\t\t\tthrow(new EncryptedContainerError('UNSUPPORTED_CIPHER_ALGORITHM', `Unsupported algorithm: ${cipherAlgo}`));\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst algorithmOID = oidDB[cipherAlgo as keyof typeof oidDB];\n\t\tconst cipher = crypto.createCipheriv(\n\t\t\tcipherAlgo,\n\t\t\tcipherKey,\n\t\t\tcipherIV\n\t\t);\n\n\t\tconst encryptedData = Buffer.concat([\n\t\t\tcipher.update(compressedPlaintext),\n\t\t\tcipher.final()\n\t\t]);\n\n\t\tconst cipherKeyArrayBuffer = bufferToArrayBuffer(cipherKey);\n\t\tconst encryptionKeysSequence = await Promise.all(keys.map(async function(key) {\n\t\t\tconst encryptedSymmetricKey = Buffer.from(await key.encrypt(cipherKeyArrayBuffer));\n\t\t\tconst retval: EncryptedContainerKeyStore = [\n\t\t\t\tBuffer.from(key.publicKeyAndType),\n\t\t\t\tBuffer.from(encryptedSymmetricKey)\n\t\t\t];\n\n\t\t\treturn(retval);\n\t\t}));\n\n\t\tcontainerBox = buildEncryptedBox(encryptionKeysSequence, algorithmOID, cipherIV, encryptedData);\n\t} else {\n\t\t/*\n\t\t * Otherwise we simply pass in the compressed data\n\t\t */\n\t\tcontainerBox = buildPlaintextBox(Buffer.from(compressedPlaintext));\n\t}\n\n\t/*\n\t * Build the typed container package\n\t */\n\tconst container: ContainerPackage = [1, containerBox];\n\n\tif (signingOptions) {\n\t\t/*\n\t\t * Sign the compressed plaintext (before encryption) so signature is verifiable after decryption\n\t\t */\n\t\tconst { signer } = signingOptions;\n\n\t\tif (!signer.hasPrivateKey) {\n\t\t\tthrow(new EncryptedContainerError('SIGNER_REQUIRES_PRIVATE_KEY', 'Signer account must have a private key'));\n\t\t}\n\n\t\t// Hash the compressed plaintext with SHA3-256\n\t\tconst digestHash = crypto.createHash('sha3-256');\n\t\tdigestHash.update(compressedPlaintext);\n\t\tconst digest = digestHash.digest();\n\n\t\t// Sign the digest\n\t\tconst signatureBuffer = await signer.sign(bufferToArrayBuffer(digest), { raw: true });\n\n\t\t// Get signature as Buffer\n\t\tlet signature: Buffer;\n\t\tif (Buffer.isBuffer(signatureBuffer)) {\n\t\t\tsignature = Buffer.from(signatureBuffer);\n\t\t} else if ('get' in signatureBuffer && typeof signatureBuffer.get === 'function') {\n\t\t\tsignature = arrayBufferToBuffer(signatureBuffer.get());\n\t\t} else {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tsignature = arrayBufferToBuffer(signatureBuffer as unknown as ArrayBuffer);\n\t\t}\n\n\t\tconst signerInfoASN1: SignerInfoASN1 = [\n\t\t\t3, // CMSVersion 3 for subjectKeyIdentifier\n\t\t\t{\n\t\t\t\ttype: 'context',\n\t\t\t\tvalue: 0,\n\t\t\t\tkind: 'implicit',\n\t\t\t\tcontains: Buffer.from(signer.publicKeyAndType)\n\t\t\t},\n\t\t\t{ type: 'oid', oid: oidDB['sha3-256'] },\n\t\t\t{ type: 'oid', oid: getSignatureAlgorithmOID(signer) },\n\t\t\tsignature\n\t\t];\n\n\t\tcontainer.push(buildSignerInfoBox(signerInfoASN1));\n\t}\n\n\tconst outputASN1 = JStoASN1(container);\n\tconst outputDER = arrayBufferToBuffer(outputASN1.toBER(false));\n\treturn(outputDER);\n}\n\nfunction parseASN1Bare(input: Buffer, acceptableEncryptionAlgorithms = ['aes-256-cbc', 'null']) {\n\tconst inputSequence = ASN1toJS(bufferToArrayBuffer(input));\n\tif (!isArray(inputSequence) || inputSequence.length < 2) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_BASE_FORMAT', 'Malformed data detected (incorrect base format)'));\n\t}\n\n\tconst version = inputSequence[0];\n\tif (typeof version !== 'bigint') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_VERSION', 'Malformed data detected (version expected at position 0)'));\n\t}\n\n\tif (version !== 1n) {\n\t\tthrow(new EncryptedContainerError('UNSUPPORTED_VERSION', 'Malformed data detected (unsupported version)'));\n\t}\n\n\tconst valueBox = inputSequence[1];\n\tif (typeof valueBox !== 'object' || valueBox === null) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (data expected at position 1)'));\n\t}\n\n\tif (!('type' in valueBox) || typeof valueBox.type !== 'string') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected type at position 1)'));\n\t}\n\n\tif (valueBox.type !== 'context') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context at position 1)'));\n\t}\n\n\tif (!('value' in valueBox) || typeof valueBox.value !== 'number') {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context value at position 1)'));\n\t}\n\n\tif (valueBox.value !== 0 && valueBox.value !== 1) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected context value of 0 or 1)'));\n\t}\n\n\tif (!('contains' in valueBox) || typeof valueBox.contains !== 'object' || valueBox.contains === null) {\n\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data detected (expected contents at position 1)'));\n\t}\n\n\tlet isEncrypted;\n\tif (valueBox.value === 0) {\n\t\tisEncrypted = true;\n\t} else {\n\t\tisEncrypted = false;\n\t}\n\n\tconst value = valueBox.contains;\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (isEncrypted) {\n\t\tif (!isArray(value, 4)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (incorrect number of elements within position 1 -- expected 4)'));\n\t\t}\n\n\t\tconst keyInfoUnchecked = value[0];\n\t\tif (!isArray(keyInfoUnchecked)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (expected sequence at position 2.0)'));\n\t\t}\n\n\t\tconst keyInfo = keyInfoUnchecked.map(function(checkKeyInfo) {\n\t\t\tif (!isArray(checkKeyInfo, 2)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected sequence of 2 at position 1.0.x)'));\n\t\t\t}\n\n\t\t\tconst publicKeyBuffer = checkKeyInfo[0];\n\t\t\tif (!Buffer.isBuffer(publicKeyBuffer)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected octet string for public key at position 1.0.x)'));\n\t\t\t}\n\t\t\tconst publicKey = Account.fromPublicKeyAndType(publicKeyBuffer);\n\n\t\t\tconst encryptedSymmetricKey = checkKeyInfo[1];\n\t\t\tif (!Buffer.isBuffer(encryptedSymmetricKey)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_KEY_INFO', 'Malformed key information (expected octet string for cipher key at position 1.0.x)'));\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\tpublicKey,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t});\n\t\t});\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tconst encryptionAlgorithmOID = value[1];\n\t\t/* XXX:TODO: Lookup the encryption algorithm from the OID */\n\t\tconst encryptionAlgorithm = 'aes-256-cbc';\n\n\t\tconst cipherIV = value[2];\n\t\tif (!Buffer.isBuffer(cipherIV)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (cipher IV expected at position 1.2)'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = value[3];\n\t\tif (!Buffer.isBuffer(encryptedCompressedValue)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (encrypted compressed buffer expected at position 1.3)'));\n\t\t}\n\n\t\tcipherInfo = {\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tencryptedData: encryptedCompressedValue,\n\t\t\tencryptionAlgorithm: encryptionAlgorithm\n\t\t};\n\n\t\tcontainedCompressed = Buffer.from(encryptedCompressedValue);\n\t} else {\n\t\tif (!isArray(value, 1)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (incorrect number of elements within position 1 -- expected 1)'));\n\t\t}\n\n\t\tconst containedCompressedUnchecked = value[0];\n\t\tif (!Buffer.isBuffer(containedCompressedUnchecked)) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Malformed data (compressed buffer expected at position 1.0)'));\n\t\t}\n\n\t\tif (!acceptableEncryptionAlgorithms.includes('null')) {\n\t\t\tthrow(new EncryptedContainerError('ENCRYPTION_REQUIRED', 'Malformed data (plaintext found but the null encryption algorithm is not acceptable)'));\n\t\t}\n\n\t\tcontainedCompressed = Buffer.from(containedCompressedUnchecked);\n\t}\n\n\t// Parse SignerInfo if present\n\tlet signerInfo: ParsedSignerInfo | undefined;\n\tif (inputSequence.length >= 3) {\n\t\tconst signerInfoBox = inputSequence[2];\n\t\tif (typeof signerInfoBox === 'object' && signerInfoBox !== null &&\n\t\t\t'type' in signerInfoBox && signerInfoBox.type === 'context' &&\n\t\t\t'value' in signerInfoBox && signerInfoBox.value === 2 &&\n\t\t\t'contains' in signerInfoBox && isArray(signerInfoBox.contains, 5)) {\n\n\t\t\tconst signerInfoData = signerInfoBox.contains;\n\n\t\t\t// Parse version\n\t\t\tconst signerVersion = signerInfoData[0];\n\t\t\tif (typeof signerVersion !== 'bigint') {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (version expected at position 0)'));\n\t\t\t}\n\n\t\t\t// Parse sid (subjectKeyIdentifier in context tag [0])\n\t\t\tconst sidBox = signerInfoData[1];\n\t\t\tlet signerPublicKeyAndType: Buffer;\n\t\t\tif (typeof sidBox === 'object' && sidBox !== null &&\n\t\t\t\t'type' in sidBox && sidBox.type === 'context' &&\n\t\t\t\t'value' in sidBox && sidBox.value === 0 &&\n\t\t\t\t'contains' in sidBox && (Buffer.isBuffer(sidBox.contains) || sidBox.contains instanceof ArrayBuffer)) {\n\t\t\t\tsignerPublicKeyAndType = arrayBufferLikeToBuffer(sidBox.contains);\n\t\t\t} else if (Buffer.isBuffer(sidBox)) {\n\t\t\t\t// Handle case where ASN.1 parser unwraps the context tag\n\t\t\t\tsignerPublicKeyAndType = Buffer.from(sidBox);\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (sid expected at position 1)'));\n\t\t\t}\n\n\t\t\t// Parse digestAlgorithm\n\t\t\tconst digestAlgoRaw = signerInfoData[2];\n\t\t\tlet digestAlgorithmOID: string;\n\t\t\tif (typeof digestAlgoRaw === 'object' && digestAlgoRaw !== null &&\n\t\t\t\t'type' in digestAlgoRaw && digestAlgoRaw.type === 'oid' &&\n\t\t\t\t'oid' in digestAlgoRaw && typeof digestAlgoRaw.oid === 'string') {\n\t\t\t\tconst normalized = normalizeToNumericOID(digestAlgoRaw.oid);\n\t\t\t\tif (!normalized) {\n\t\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', `Unknown digest algorithm: ${digestAlgoRaw.oid}`));\n\t\t\t\t}\n\t\t\t\tdigestAlgorithmOID = normalized;\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (digestAlgorithm expected at position 2)'));\n\t\t\t}\n\n\t\t\t// Parse signatureAlgorithm\n\t\t\tconst sigAlgoRaw = signerInfoData[3];\n\t\t\tlet signatureAlgorithmOID: string;\n\t\t\tif (typeof sigAlgoRaw === 'object' && sigAlgoRaw !== null &&\n\t\t\t\t'type' in sigAlgoRaw && sigAlgoRaw.type === 'oid' &&\n\t\t\t\t'oid' in sigAlgoRaw && typeof sigAlgoRaw.oid === 'string') {\n\t\t\t\tconst normalized = normalizeToNumericOID(sigAlgoRaw.oid);\n\t\t\t\tif (!normalized) {\n\t\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', `Unknown signature algorithm: ${sigAlgoRaw.oid}`));\n\t\t\t\t}\n\t\t\t\tsignatureAlgorithmOID = normalized;\n\t\t\t} else {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (signatureAlgorithm expected at position 3)'));\n\t\t\t}\n\n\t\t\t// Parse signature\n\t\t\tconst signatureRaw = signerInfoData[4];\n\t\t\tif (!Buffer.isBuffer(signatureRaw)) {\n\t\t\t\tthrow(new EncryptedContainerError('MALFORMED_SIGNER_INFO', 'Malformed SignerInfo (signature expected at position 4)'));\n\t\t\t}\n\n\t\t\tsignerInfo = {\n\t\t\t\tversion: Number(signerVersion),\n\t\t\t\tsignerPublicKeyAndType,\n\t\t\t\tdigestAlgorithmOID,\n\t\t\t\tsignatureAlgorithmOID,\n\t\t\t\tsignature: Buffer.from(signatureRaw)\n\t\t\t};\n\t\t}\n\t}\n\n\treturn({\n\t\tversion: version,\n\t\tisEncrypted: isEncrypted,\n\t\tinnerValue: containedCompressed,\n\t\tsignerInfo,\n\t\t...cipherInfo\n\t});\n}\n\nasync function parseASN1Decrypt(inputInfo: ReturnType<typeof parseASN1Bare>, keys?: Account[]) {\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (inputInfo.isEncrypted) {\n\t\tif (keys === undefined || keys.length === 0) {\n\t\t\tthrow(new EncryptedContainerError('NO_KEYS_PROVIDED', 'Encrypted Container found with encryption but no keys for decryption supplied'));\n\t\t}\n\n\t\tconst algorithm = inputInfo.encryptionAlgorithm;\n\t\tif (algorithm === undefined) {\n\t\t\tthrow(new EncryptedContainerError('MALFORMED_DATA_STRUCTURE', 'Encrypted Container found with encryption but no algorithm supplied'));\n\t\t}\n\n\t\tconst keyInfo = inputInfo.keys;\n\t\tif (keyInfo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Encrypted container found with missing keys'));\n\t\t}\n\n\t\tlet decryptionKeyInfo;\n\t\tfor (const checkKeyInfo of keyInfo) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!key.hasPrivateKey) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (key.comparePublicKey(checkKeyInfo.publicKey)) {\n\t\t\t\t\tdecryptionKeyInfo = {\n\t\t\t\t\t\t...checkKeyInfo,\n\t\t\t\t\t\tprivateKey: key\n\t\t\t\t\t};\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (decryptionKeyInfo === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_MATCHING_KEY', 'No keys found which can perform decryption on the supplied encryption box'));\n\t\t}\n\n\t\tlet cipherKey: Buffer;\n\t\ttry {\n\t\t\tconst dataToDecrypt = bufferToArrayBuffer(decryptionKeyInfo.encryptedSymmetricKey);\n\t\t\tcipherKey = arrayBufferLikeToBuffer(await decryptionKeyInfo.privateKey.decrypt(dataToDecrypt));\n\t\t} catch (err) {\n\t\t\tthrow(new EncryptedContainerError('DECRYPTION_FAILED', `Key decryption failed: ${err instanceof Error ? err.message : String(err)}`));\n\t\t}\n\n\t\tconst cipherIV = inputInfo.cipherIV;\n\t\tif (cipherIV === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'No Cipher IV found'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = inputInfo.innerValue;\n\t\tconst decipher = crypto.createDecipheriv(algorithm, cipherKey, cipherIV);\n\t\ttry {\n\t\t\tcontainedCompressed = Buffer.concat([\n\t\t\t\tdecipher.update(encryptedCompressedValue),\n\t\t\t\tdecipher.final()\n\t\t\t]);\n\t\t} catch (err) {\n\t\t\tthrow(new EncryptedContainerError('DECRYPTION_FAILED', `Cipher decryption failed: ${err instanceof Error ? err.message : String(err)}`));\n\t\t}\n\n\t\tcipherInfo = {\n\t\t\tisEncrypted: true,\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tcipherKey: cipherKey,\n\t\t\tencryptedData: encryptedCompressedValue\n\t\t};\n\t} else {\n\t\tcontainedCompressed = inputInfo.innerValue;\n\t\tcipherInfo = {\n\t\t\tisEncrypted: false\n\t\t};\n\t}\n\n\tlet plaintext: Buffer;\n\ttry {\n\t\tconst inflated = await zlibInflateAsync(bufferToArrayBuffer(containedCompressed));\n\t\tplaintext = arrayBufferLikeToBuffer(inflated);\n\t} catch (err) {\n\t\tthrow(new EncryptedContainerError('DECOMPRESSION_FAILED', `Inflate failed: ${err instanceof Error ? err.message : String(err)}`));\n\t}\n\n\treturn({\n\t\tversion: inputInfo.version,\n\t\tplaintext: plaintext,\n\t\tcompressed: containedCompressed,\n\t\t...cipherInfo\n\t});\n\n}\n\nasync function parseASN1(input: Buffer, keys?: Account[]) {\n\tconst inputInfo = parseASN1Bare(input);\n\tconst retval = await parseASN1Decrypt(inputInfo, keys);\n\n\treturn(retval);\n}\n\nfunction inputToBuffer(data: string | ArrayBuffer | Buffer): Buffer {\n\tif (typeof data === 'string') {\n\t\treturn(Buffer.from(data, 'utf-8'));\n\t} else if (Buffer.isBuffer(data)) {\n\t\treturn(data);\n\t} else {\n\t\treturn(arrayBufferToBuffer(data));\n\t}\n}\n\ntype EncryptedContainerInfo = Pick<CipherOptions, 'cipherAlgo'> & {\n\t/**\n\t * Set of accounts which can access the data\n\t */\n\tprincipals: Account[];\n}\n\ntype UnencryptedContainerInfo = {\n\t/**\n\t * Unencrypted container should not have any principals\n\t */\n\tprincipals: null;\n}\n\ntype ContainerSigningInfo = {\n\t/**\n\t * The account to sign the container with (for new containers)\n\t */\n\tsigner?: Account;\n\n\t/**\n\t * Parsed signer info from an existing container\n\t */\n\tparsedSignerInfo?: ParsedSignerInfo;\n}\n\nexport class EncryptedContainer {\n\tprivate static readonly algorithm = 'aes-256-cbc';\n\n\t/**\n\t * Flag indicating whether we support exporting the plaintext\n\t */\n\t#mayAccessPlaintext = true;\n\n\t/**\n\t * Encryption details\n\t */\n\tprotected _internalState: EncryptedContainerInfo | UnencryptedContainerInfo;\n\n\t/**\n\t * Signing information\n\t */\n\t#signingInfo: ContainerSigningInfo = {};\n\n\t/**\n\t * The plaintext or encoded (and possibly encrypted) data\n\t */\n\t#data:\n\t\t{ plaintext: Buffer } |\n\t\t{ encoded: Buffer } |\n\t\t{ plaintext: Buffer, encoded: Buffer };\n\n\tconstructor(principals: Account[] | null, signer?: Account) {\n\t\tif (principals === null) {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: null\n\t\t\t};\n\t\t} else {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: principals,\n\t\t\t\tcipherAlgo: EncryptedContainer.algorithm\n\t\t\t}\n\t\t};\n\t\tthis.#data = { plaintext: Buffer.alloc(0) };\n\n\t\tif (signer) {\n\t\t\tthis.#signingInfo.signer = signer;\n\t\t}\n\t}\n\n\tget encrypted(): boolean {\n\t\treturn(this._internalState.principals !== null);\n\t}\n\n\t#isEncrypted(): this is { _internalState: EncryptedContainerInfo } {\n\t\treturn(this.encrypted);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from an encrypted blob,\n\t * it will need to be decryptable with one of the specified principals\n\t *\n\t * After decryption happens, the list of principals with access to the\n\t * resource will be reset to what is contained within the encrypted\n\t * container\n\t */\n\tstatic fromEncryptedBuffer(data: ArrayBuffer | Buffer, principals: Account[]): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(true);\n\n\t\treturn(retval);\n\t}\n\n\tstatic fromEncodedBuffer(data: ArrayBuffer | Buffer, principals: Account[] | null): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(false);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from a plaintext.\n\t *\n\t * It will be decryptable by any one of the specified principals\n\t *\n\t * @param data The plaintext data to encrypt or encode\n\t * @param principals The list of principals who can access the data if it is null then the data is not encrypted\n\t * @param options Options including locked (plaintext accessibility) and signer (for RFC 5652 signing). For backward compatibility, can also be a boolean for locked.\n\t * @returns The EncryptedContainer instance with the plaintext data and principals set\n\t */\n\tstatic fromPlaintext(data: string | ArrayBuffer | Buffer, principals: Account[] | null, options?: boolean | FromPlaintextOptions): EncryptedContainer {\n\t\t// Handle backward compatibility - if options is a boolean, treat it as the locked flag\n\t\tlet lockedOpt: boolean | undefined;\n\t\tlet signer: Account | undefined;\n\n\t\tif (typeof options === 'boolean') {\n\t\t\tlockedOpt = options;\n\t\t} else if (options !== undefined) {\n\t\t\tlockedOpt = options.locked;\n\t\t\tsigner = options.signer;\n\t\t}\n\n\t\tconst retval = new EncryptedContainer(principals, signer);\n\n\t\tlet locked = lockedOpt;\n\t\tif (locked === undefined) {\n\t\t\tlocked = true;\n\t\t\tif (principals === null) {\n\t\t\t\tlocked = false;\n\t\t\t}\n\t\t}\n\n\t\tif (locked) {\n\t\t\tretval.disablePlaintext();\n\t\t}\n\n\t\tretval.setPlaintext(data);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Set the plaintext buffer to the specified value\n\t */\n\tsetPlaintext(data: string | ArrayBuffer | Buffer): void {\n\t\tthis.#data = { plaintext: inputToBuffer(data) };\n\t}\n\n\t/**\n\t * Set the encoded blob to the specified value\n\t */\n\t#setEncodedBuffer(data: ArrayBuffer | Buffer): void {\n\t\tthis.#data = { encoded: inputToBuffer(data) };\n\t}\n\n\tprivate get _encoded(): Buffer | undefined {\n\t\tif ('encoded' in this.#data && this.#data.encoded !== undefined) {\n\t\t\treturn(this.#data.encoded);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\tprivate get _plaintext(): Buffer | undefined {\n\t\tif ('plaintext' in this.#data && this.#data.plaintext !== undefined) {\n\t\t\treturn(this.#data.plaintext);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\t/*\n\t * Return the decoded data from the encoded blob\n\t * and populate the symmetric key parameters from the encoded blob if it is encrypted\n\t */\n\t#computeAndSetKeyInfo(mustBeEncrypted: boolean) {\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_ENCODED_DATA_AVAILABLE', 'No encoded data available'));\n\t\t}\n\n\t\tconst plaintextWrapper = parseASN1Bare(this._encoded);\n\n\t\tif (mustBeEncrypted && !plaintextWrapper.isEncrypted) {\n\t\t\tthrow(new EncryptedContainerError('ENCRYPTION_REQUIRED', 'Unable to set key information from plaintext -- it is not encrypted but that was required'));\n\t\t}\n\n\t\tif (plaintextWrapper.isEncrypted) {\n\t\t\tconst principals = this._internalState.principals;\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new EncryptedContainerError('INVALID_PRINCIPALS', 'May not encrypt data with a null set of principals'));\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Compute the new accounts by merging the input from the\n\t\t\t * data and the existing list of principals\n\t\t\t */\n\t\t\t/**\n\t\t\t * The existing principals from the blob, with existing\n\t\t\t * principals substituted in where appropriate\n\t\t\t */\n\t\t\tconst blobPrincipals = (plaintextWrapper.keys ?? []).map((keyInfo) => {\n\t\t\t\tconst currentPublicKey = keyInfo.publicKey;\n\t\t\t\tif (!currentPublicKey.isAccount()) {\n\t\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Non-account found within the encryption key list'));\n\t\t\t\t}\n\n\t\t\t\tfor (const checkExistingKey of principals) {\n\t\t\t\t\tif (checkExistingKey.comparePublicKey(currentPublicKey)) {\n\t\t\t\t\t\treturn(checkExistingKey);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn(currentPublicKey);\n\t\t\t});\n\n\t\t\tthis._internalState.principals = blobPrincipals;\n\n\t\t\t// Confirm updated principals are populated correctly which sets container to encrypted\n\t\t\tif (!this.encrypted) {\n\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Encrypted data found but not marked as encrypted'));\n\t\t\t}\n\t\t} else {\n\t\t\tthis._internalState.principals = null;\n\n\t\t\tif (this.encrypted) {\n\t\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Plaintext data found but marked as encrypted'));\n\t\t\t}\n\t\t}\n\n\t\t// Store parsed signer info if present\n\t\tif (plaintextWrapper.signerInfo) {\n\t\t\tthis.#signingInfo.parsedSignerInfo = plaintextWrapper.signerInfo;\n\t\t}\n\n\t\treturn(plaintextWrapper);\n\t}\n\n\t/**\n\t * Populate the plaintext (as well as symmetric key parameters) from\n\t * the encoded blob\n\t */\n\tasync #computePlaintext() {\n\t\tif (this._plaintext) {\n\t\t\treturn(this._plaintext);\n\t\t}\n\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_ENCODED_DATA_AVAILABLE', 'No plaintext or encoded data available'));\n\t\t}\n\n\n\t\tconst info = this.#computeAndSetKeyInfo(this.encrypted);\n\n\t\tlet principals = this._internalState.principals;\n\t\tif (info.isEncrypted) {\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new EncryptedContainerError('INVALID_PRINCIPALS', 'May not decrypt data with a null set of principals'));\n\t\t\t}\n\t\t} else {\n\t\t\tprincipals = [];\n\t\t}\n\n\t\tconst plaintextWrapper = await parseASN1Decrypt(info, principals);\n\t\tconst plaintext = Buffer.from(plaintextWrapper.plaintext);\n\n\t\tthis.#data = { ...this.#data, plaintext };\n\n\t\treturn(plaintext);\n\t}\n\n\t/**\n\t * Return the compressed bytes exactly as they are stored in the encoded\n\t * container (decrypted where applicable, but before inflation).\n\t */\n\tasync #computeSignedCompressed(): Promise<Buffer> {\n\t\tconst info = this.#computeAndSetKeyInfo(this.encrypted);\n\t\tlet principals = this._internalState.principals;\n\t\tif (info.isEncrypted) {\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new EncryptedContainerError('INVALID_PRINCIPALS', 'May not decrypt data with a null set of principals'));\n\t\t\t}\n\t\t} else {\n\t\t\tprincipals = [];\n\t\t}\n\n\t\tconst wrapper = await parseASN1Decrypt(info, principals);\n\t\tconst compressed = Buffer.from(wrapper.compressed);\n\t\treturn(compressed);\n\t}\n\n\t/**\n\t * Compute the encoded version of the plaintext data\n\t */\n\tasync #computePlaintextEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'No plaintext data available'));\n\t\t}\n\n\t\tconst signingOptions = this.#signingInfo.signer\n\t\t\t? { signer: this.#signingInfo.signer }\n\t\t\t: undefined;\n\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext,\n\t\t\tundefined,\n\t\t\tsigningOptions\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\t/**\n\t * Populate the encrypted blob from the plaintext and symmetric key\n\t * parameters. If the symmetric key parameters have not been\n\t * initialized they will be initialized at this time.\n\t */\n\tasync #computeEncryptedEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'No encrypted nor plaintext data available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Asked to encrypt a plaintext buffer'));\n\t\t}\n\n\t\tconst signingOptions = this.#signingInfo.signer\n\t\t\t? { signer: this.#signingInfo.signer }\n\t\t\t: undefined;\n\n\t\t/**\n\t\t * structured data is the ASN.1 encoded structure\n\t\t */\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext,\n\t\t\t{\n\t\t\t\tkeys: this._internalState.principals,\n\t\t\t\tcipherKey: Buffer.from(crypto.randomBytes(32)),\n\t\t\t\tcipherIV: Buffer.from(crypto.randomBytes(16)),\n\t\t\t\tcipherAlgo: this._internalState.cipherAlgo\n\t\t\t},\n\t\t\tsigningOptions\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\tasync #computeEncoded() {\n\t\tif (this._encoded !== undefined) {\n\t\t\treturn(this._encoded);\n\t\t}\n\n\t\tlet computed: Buffer;\n\t\tif (!this.encrypted) {\n\t\t\tcomputed = await this.#computePlaintextEncoded();\n\t\t} else {\n\t\t\tcomputed = await this.#computeEncryptedEncoded();\n\t\t}\n\n\t\tthis.#data = { ...this.#data, encoded: computed };\n\n\t\treturn(computed);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s) synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\tgrantAccessSync(accounts: Account[] | Account): this {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to grant access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\tif (!Array.isArray(accounts)) {\n\t\t\taccounts = [accounts];\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals.push(...accounts);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s).\n\t */\n\tasync grantAccess(accounts: Account[] | Account): Promise<this> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.grantAccessSync(accounts);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\trevokeAccessSync(account: Account): this {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('NO_PLAINTEXT_AVAILABLE', 'Unable to revoke access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals = this._internalState.principals.filter(function(checkAccount) {\n\t\t\treturn(!checkAccount.comparePublicKey(account));\n\t\t});\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account\n\t */\n\tasync revokeAccess(account: Account): Promise<this> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.revokeAccessSync(account);\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Disable access to the plaintext from this instance\n\t */\n\tdisablePlaintext(): this {\n\t\tthis.#mayAccessPlaintext = false;\n\n\t\treturn(this);\n\t}\n\n\t/**\n\t * Get the plaintext for this instance\n\t */\n\tasync getPlaintext(): Promise<ArrayBuffer> {\n\t\tif (!this.#mayAccessPlaintext) {\n\t\t\tthrow(new EncryptedContainerError('PLAINTEXT_DISABLED', 'May not access plaintext'));\n\t\t}\n\n\t\tconst plaintext = await this.#computePlaintext();\n\n\t\tif (plaintext === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Plaintext could not be decoded'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(bufferToArrayBuffer(plaintext));\n\t}\n\n\t/**\n\t * Get the serializable buffer which can be stored and reconstructed\n\t */\n\tasync getEncodedBuffer(): Promise<ArrayBuffer> {\n\t\tconst serialized = await this.#computeEncoded();\n\n\t\tif (serialized === undefined) {\n\t\t\tthrow(new EncryptedContainerError('INTERNAL_ERROR', 'Could not encode data'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(bufferToArrayBuffer(serialized));\n\t}\n\n\t/**\n\t * Get the list of accounts which have access to read the plaintext of\n\t * this container\n\t */\n\tget principals(): Account[] {\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new EncryptedContainerError('ACCESS_MANAGEMENT_NOT_ALLOWED', 'May not manage access to a plaintext container'));\n\t\t}\n\n\t\treturn(this._internalState.principals);\n\t}\n\n\t/**\n\t * Check if this container is signed\n\t */\n\tget isSigned(): boolean {\n\t\treturn(this.#signingInfo.signer !== undefined || this.#signingInfo.parsedSignerInfo !== undefined);\n\t}\n\n\t/**\n\t * Get the signing account of this container.\n\t */\n\tgetSigningAccount(): Account | undefined {\n\t\t// If we have a signer account set (for new containers), return it\n\t\tif (this.#signingInfo.signer) {\n\t\t\treturn(this.#signingInfo.signer);\n\t\t}\n\n\t\t// If we have parsed signer info (from encoded container), construct account from it\n\t\tif (this.#signingInfo.parsedSignerInfo) {\n\t\t\tconst { signerPublicKeyAndType } = this.#signingInfo.parsedSignerInfo;\n\t\t\treturn(Account.fromPublicKeyAndType(signerPublicKeyAndType));\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\t/**\n\t * Verify the signature on this container.\n\t * This requires decrypting the container first to access the compressed plaintext.\n\t *\n\t * @returns true if signature is valid, false if invalid, or throws if not signed or plaintext unavailable\n\t */\n\tasync verifySignature(): Promise<boolean> {\n\t\t// If we have a signer but no parsed info yet, encode first to produce the signed DER\n\t\tif (!this.#signingInfo.parsedSignerInfo && this.#signingInfo.signer) {\n\t\t\tconst encoded = await this.#computeEncoded();\n\t\t\tif (encoded) {\n\t\t\t\tconst parsed = parseASN1Bare(encoded);\n\t\t\t\tif (parsed.signerInfo) {\n\t\t\t\t\tthis.#signingInfo.parsedSignerInfo = parsed.signerInfo;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!this.#signingInfo.parsedSignerInfo) {\n\t\t\tthrow(new EncryptedContainerError('NOT_SIGNED', 'Container is not signed'));\n\t\t}\n\n\t\tconst signerInfo = this.#signingInfo.parsedSignerInfo;\n\n\t\t// Validate digest algorithm OID\n\t\tif (!supportedDigestOIDs.has(signerInfo.digestAlgorithmOID)) {\n\t\t\tthrow(new EncryptedContainerError(\n\t\t\t\t'UNSUPPORTED_DIGEST_ALGORITHM',\n\t\t\t\t`Unsupported digest algorithm OID: ${signerInfo.digestAlgorithmOID}`\n\t\t\t));\n\t\t}\n\n\t\t// Validate signature algorithm OID\n\t\tif (!supportedSignatureOIDs.has(signerInfo.signatureAlgorithmOID)) {\n\t\t\tthrow(new EncryptedContainerError(\n\t\t\t\t'UNSUPPORTED_SIGNATURE_ALGORITHM',\n\t\t\t\t`Unsupported signature algorithm OID: ${signerInfo.signatureAlgorithmOID}`\n\t\t\t));\n\t\t}\n\n\t\t// Digest the exact compressed bytes that were signed.\n\t\tconst compressedPlaintext = await this.#computeSignedCompressed();\n\t\tconst digestHash = crypto.createHash('sha3-256');\n\t\tdigestHash.update(compressedPlaintext);\n\t\tconst digest = digestHash.digest();\n\n\t\t// Get the signer's account (public key only)\n\t\tconst signerAccount = Account.fromPublicKeyAndType(signerInfo.signerPublicKeyAndType);\n\n\t\t// Verify the signature\n\t\tconst signature = signerInfo.signature;\n\t\tconst isValid = signerAccount.verify(\n\t\t\tbufferToArrayBuffer(digest),\n\t\t\tbufferToArrayBuffer(signature),\n\t\t\t{ raw: true }\n\t\t);\n\n\t\treturn(isValid);\n\t}\n}\n\n/** @internal */\nexport const _Testing = {\n\tbuildASN1: buildASN1,\n\tparseASN1: parseASN1\n};\n\nexport default EncryptedContainer;\n"]}
|
package/lib/history.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { KeetaNetAccount } from './asset.js';
|
|
|
6
6
|
import type { Logger } from './log/index.js';
|
|
7
7
|
import type { KeetaAssetMovementTransaction } from '../services/asset-movement/common.js';
|
|
8
8
|
import type { AnchorTransactionStatus } from './anchor-status.js';
|
|
9
|
+
import type { AnchorExternalInput } from './anchor-external.js';
|
|
9
10
|
type Account = InstanceType<typeof KeetaNetLib.Account>;
|
|
10
11
|
/**
|
|
11
12
|
* Wallet-facing logical category of a transaction.
|
|
@@ -121,6 +122,12 @@ export type LogicalTransaction = {
|
|
|
121
122
|
* transaction. The wallet interprets non-standardized states.
|
|
122
123
|
*/
|
|
123
124
|
providerStatus?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Set when `type` and `counterparty` were inferred locally from the block's
|
|
127
|
+
* anchor `external` without enrichment, so the wallet can render a tentative
|
|
128
|
+
* label and enrich on demand. Cleared once the transfer resolves.
|
|
129
|
+
*/
|
|
130
|
+
provisional?: boolean;
|
|
124
131
|
/**
|
|
125
132
|
* Flow of value relative to the queried account.
|
|
126
133
|
*/
|
|
@@ -165,6 +172,17 @@ export type LogicalTransaction = {
|
|
|
165
172
|
* Raw `external` strings observed, when present.
|
|
166
173
|
*/
|
|
167
174
|
external?: string[];
|
|
175
|
+
/**
|
|
176
|
+
* On-chain operations this transaction declared as its inputs, decoded
|
|
177
|
+
* from the `external` envelope.
|
|
178
|
+
*/
|
|
179
|
+
inputs?: AnchorExternalInput[];
|
|
180
|
+
/**
|
|
181
|
+
* Anchor transfer ids declared locally by the block's SEND `external`
|
|
182
|
+
* envelopes, available without enrichment. Superseded by `anchorTxIDs`
|
|
183
|
+
* once the transfer is resolved.
|
|
184
|
+
*/
|
|
185
|
+
declaredAnchorTxIDs?: string[];
|
|
168
186
|
};
|
|
169
187
|
/**
|
|
170
188
|
* Raw source the transaction was folded from. Present only when
|
|
@@ -237,6 +255,38 @@ export type EnrichedBlock = {
|
|
|
237
255
|
* The block's enriched operations.
|
|
238
256
|
*/
|
|
239
257
|
operations: EnrichedOperation[];
|
|
258
|
+
/**
|
|
259
|
+
* On-chain inputs decoded from the block's SEND `external` envelopes, in
|
|
260
|
+
* the order observed. Captured locally during enrichment, independent of
|
|
261
|
+
* anchor status resolution. Present only when non-empty.
|
|
262
|
+
*/
|
|
263
|
+
inputs?: AnchorExternalInput[];
|
|
264
|
+
/**
|
|
265
|
+
* Anchor transfer references decoded locally from the block's SEND
|
|
266
|
+
* `external` envelopes and trusted (block-owned by the perspective or
|
|
267
|
+
* anchor-signed). Present only when non-empty.
|
|
268
|
+
*/
|
|
269
|
+
declaredAnchors?: DeclaredAnchorRef[];
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* An anchor transfer reference decoded locally from a block's SEND `external`
|
|
273
|
+
* envelope. `signed` is true when the envelope was signed by `anchorID`, which
|
|
274
|
+
* makes the reference trustworthy even for a block the perspective does not own.
|
|
275
|
+
*/
|
|
276
|
+
export type DeclaredAnchorRef = {
|
|
277
|
+
/**
|
|
278
|
+
* Anchor public key string the entry is filed under.
|
|
279
|
+
*/
|
|
280
|
+
anchorID: string;
|
|
281
|
+
/**
|
|
282
|
+
* Anchor-scoped transaction id declared for this transfer. Matches the
|
|
283
|
+
* resolved transfer's id later carried in `refs.anchorTxIDs`.
|
|
284
|
+
*/
|
|
285
|
+
transactionID: string;
|
|
286
|
+
/**
|
|
287
|
+
* Whether the declaring `external` was signed by `anchorID`.
|
|
288
|
+
*/
|
|
289
|
+
signed: boolean;
|
|
240
290
|
};
|
|
241
291
|
/**
|
|
242
292
|
* A classifier that maps an enriched block to zero or more logical
|
|
@@ -300,6 +350,13 @@ export type HistoryAccount = GenericAccount | string | null;
|
|
|
300
350
|
*/
|
|
301
351
|
export interface HistorySource {
|
|
302
352
|
getHistory(account: HistoryAccount, query?: HistoryQuery): Promise<HistoryEntry[]>;
|
|
353
|
+
/**
|
|
354
|
+
* Fetch the vote staple settling `blockHash`, or `null`/`undefined` when it
|
|
355
|
+
* cannot be resolved. Optional: when present, {@link UserHistory.iterate}
|
|
356
|
+
* folds linked multi-hop swap chains incrementally (resolving each
|
|
357
|
+
* referenced predecessor by hash) instead of buffering the whole account.
|
|
358
|
+
*/
|
|
359
|
+
getVoteStaple?(blockHash: string): Promise<HistoryStaple | null | undefined>;
|
|
303
360
|
}
|
|
304
361
|
/**
|
|
305
362
|
* Construction inputs for {@link UserHistory}.
|
|
@@ -337,7 +394,8 @@ export type UserHistoryListOptions = {
|
|
|
337
394
|
*/
|
|
338
395
|
pageSize?: number;
|
|
339
396
|
/**
|
|
340
|
-
* Maximum number of logical transactions to return.
|
|
397
|
+
* Maximum number of logical transactions to return. When unset, every page
|
|
398
|
+
* of history is walked until exhausted.
|
|
341
399
|
*/
|
|
342
400
|
limit?: number;
|
|
343
401
|
/**
|
|
@@ -345,8 +403,9 @@ export type UserHistoryListOptions = {
|
|
|
345
403
|
*/
|
|
346
404
|
cursor?: string;
|
|
347
405
|
/**
|
|
348
|
-
* Enable anchor enrichment
|
|
349
|
-
*
|
|
406
|
+
* Enable anchor enrichment, which resolves each operation to its anchor
|
|
407
|
+
* transfer over HTTP.
|
|
408
|
+
* Defaults to `false`.
|
|
350
409
|
*/
|
|
351
410
|
enrich?: boolean;
|
|
352
411
|
/**
|
|
@@ -363,27 +422,16 @@ export type UserHistoryListOptions = {
|
|
|
363
422
|
*/
|
|
364
423
|
includeSource?: boolean;
|
|
365
424
|
};
|
|
366
|
-
/**
|
|
367
|
-
* Derive the logical type of an anchor transfer from its endpoints.
|
|
368
|
-
*/
|
|
369
|
-
export declare function logicalTypeFromTransfer(transfer: KeetaAssetMovementTransaction): LogicalTransactionType;
|
|
370
|
-
/**
|
|
371
|
-
* Map an anchor transfer's raw status onto the standardized status, carrying
|
|
372
|
-
* the raw provider string for the wallet to interpret.
|
|
373
|
-
*/
|
|
374
|
-
export declare function statusFromTransfer(transfer: KeetaAssetMovementTransaction): {
|
|
375
|
-
status: LogicalTransactionStatus;
|
|
376
|
-
providerStatus: string;
|
|
377
|
-
};
|
|
378
425
|
/**
|
|
379
426
|
* Default ordered classifier list, specific-first.
|
|
380
427
|
*/
|
|
381
428
|
export declare const defaultClassifiers: readonly LogicalClassifier[];
|
|
382
429
|
/**
|
|
383
|
-
* Fold
|
|
384
|
-
*
|
|
430
|
+
* Fold linked chains into single conversions for display: multi-hop swaps, a
|
|
431
|
+
* swap that funds an outbound bridge, and a pay-in send capped by its delivery
|
|
432
|
+
* receive (a non-atomic anchor swap seen leanly).
|
|
385
433
|
*/
|
|
386
|
-
export declare function
|
|
434
|
+
export declare function foldChains(transactions: readonly LogicalTransaction[]): LogicalTransaction[];
|
|
387
435
|
/**
|
|
388
436
|
* Folds a user's on-chain history and anchor transfer data into a condensed
|
|
389
437
|
* list of {@link LogicalTransaction}.
|
|
@@ -392,12 +440,20 @@ export declare class UserHistory {
|
|
|
392
440
|
#private;
|
|
393
441
|
constructor(config: UserHistoryConfig);
|
|
394
442
|
/**
|
|
395
|
-
* Fetch, enrich and fold a user's history into logical transactions
|
|
443
|
+
* Fetch, enrich and fold a user's history into logical transactions,
|
|
444
|
+
* grouping linked multi-hop chains into single conversions.
|
|
396
445
|
*/
|
|
397
446
|
list(account: HistoryAccount, options?: UserHistoryListOptions): Promise<LogicalTransaction[]>;
|
|
398
447
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
448
|
+
* Enrich a single transaction on demand by resolving the anchor transfers
|
|
449
|
+
* for only its contributing blocks.
|
|
450
|
+
*/
|
|
451
|
+
enrichTransaction(transaction: LogicalTransaction, account: HistoryAccount, options?: UserHistoryListOptions): Promise<LogicalTransaction>;
|
|
452
|
+
/**
|
|
453
|
+
* Stream logical transactions newest-first, paging through history one page
|
|
454
|
+
* at a time instead of buffering the full result set. Walks every page until
|
|
455
|
+
* history is exhausted, or until {@link UserHistoryListOptions.limit} logical
|
|
456
|
+
* transactions have been yielded.
|
|
401
457
|
*/
|
|
402
458
|
iterate(account: HistoryAccount, options?: UserHistoryListOptions): AsyncGenerator<LogicalTransaction>;
|
|
403
459
|
}
|