@keetanetwork/anchor 0.0.16 → 0.0.18

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.
@@ -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,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,8DAA8D;AACxH,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,8DAA8D;AACxH,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AACjD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AACjD,MAAM,OAAO,GAA+B,WAAW,CAAC,OAAO,CAAC;AAEhE,MAAM,mBAAmB,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,mBAAmB,CAAC;AA+GzE,MAAM,KAAK,GAAG;IACb,aAAa,EAAE,yBAAyB;CAC/B,CAAC;AAEX;;;;EAIE;AACF,KAAK,UAAU,SAAS,CAAC,SAAiB,EAAE,iBAA+B;IAC1E,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAE/C;;OAEG;IACH,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEhB;;OAEG;IACH,IAAI,iBAAiB,EAAE,CAAC;QACv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QAED;;;;WAIG;QACH,OAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACrB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAEhD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAK,CAAC,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAAC;QAC3D,CAAC;QAED;;;;WAIG;QACH,OAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YAC1B,MAAK,CAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,OAAM,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACxC,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 } from './utils/buffer.js';\nimport { isArray } from './utils/array.js';\n\nconst zlibDeflate = KeetaNetLib.Utils.Buffer.ZlibDeflate; /* XXX:TODO: Change this to ZlibDeflateAsync when merged in */\nconst zlibInflate = KeetaNetLib.Utils.Buffer.ZlibInflate; /* XXX:TODO: Change this to ZlibInflateAsync when merged in */\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>;\nconst bufferToArrayBuffer = KeetaNetLib.Utils.Helper.bufferToArrayBuffer;\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 * ContainerPackage ::= SEQUENCE {\n * version Version (v2),\n * encryptedContainer [0] EXPLICIT EncryptedContainerBox OPTIONAL,\n * plaintextContainer [1] EXPLICIT PlaintextContainerBox 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\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 ContainerPackage = [\n\t/* version */\n\tnumber,\n\n\t{\n\t\ttype: 'context'\n\t\tvalue: 0,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxEncrypted\n\t} | {\n\t\ttype: 'context',\n\t\tvalue: 1,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxPlaintext\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\nconst oidDB = {\n\t'aes-256-cbc': '2.16.840.1.101.3.4.1.42'\n} as const;\n\n/**\n* Compiles the ASN.1 for the container\n*\n* @returns The ASN.1 DER data\n*/\nasync function buildASN1(plaintext: Buffer, encryptionOptions?: ASN1Options): Promise<Buffer> {\n\tconst compressedPlaintext = Buffer.from(zlibDeflate(plaintext));\n\n\tconst sequence: Partial<ContainerPackage> = [];\n\n\t/*\n\t * Version v2 (1)\n\t */\n\tsequence[0] = 1;\n\n\t/*\n\t * Encrypted container box\n\t */\n\tif (encryptionOptions) {\n\t\tconst { keys, cipherKey, cipherIV, cipherAlgo } = encryptionOptions;\n\n\t\tif (keys === undefined || keys.length === 0 || cipherKey === undefined || cipherIV === undefined || cipherAlgo === undefined) {\n\t\t\tthrow(new Error('internal error: Unsupported method invocation'));\n\t\t}\n\n\t\tif (!(cipherAlgo in oidDB)) {\n\t\t\tthrow(new Error(`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\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\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\tkey.publicKeyAndType,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t];\n\n\t\t\treturn(retval);\n\t\t}));\n\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 0,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [\n\t\t\t\tencryptionKeysSequence,\n\t\t\t\t{ type: 'oid', oid: algorithmOID },\n\t\t\t\tcipherIV,\n\t\t\t\tencryptedData\n\t\t\t]\n\t\t};\n\t} else {\n\t\t/*\n\t\t * Otherwise we simply pass in the compressed data\n\t\t */\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 1,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [compressedPlaintext]\n\t\t};\n\t}\n\n\tconst outputASN1 = JStoASN1(sequence);\n\tconst outputDER = Buffer.from(outputASN1.toBER(false));\n\n\treturn(outputDER);\n}\n\nfunction parseASN1Bare(input: Buffer, acceptableEncryptionAlgorithms = ['aes-256-cbc', 'null']) {\n\tconst inputSequence = ASN1toJS(bufferToArrayBuffer(input));\n\tif (!isArray(inputSequence, 2)) {\n\t\tthrow(new Error('Malformed data detected (incorrect base format)'));\n\t}\n\n\tconst version = inputSequence[0];\n\tif (typeof version !== 'bigint') {\n\t\tthrow(new Error('Malformed data detected (version expected at position 0)'));\n\t}\n\n\tif (version !== 1n) {\n\t\tthrow(new Error('Malformed data detected (unsupported version)'));\n\t}\n\n\tconst valueBox = inputSequence[1];\n\tif (typeof valueBox !== 'object' || valueBox === null) {\n\t\tthrow(new Error('Malformed data detected (data expected at position 1)'));\n\t}\n\n\tif (!('type' in valueBox) || typeof valueBox.type !== 'string') {\n\t\tthrow(new Error('Malformed data detected (expected type at position 1)'));\n\t}\n\n\tif (valueBox.type !== 'context') {\n\t\tthrow(new Error('Malformed data detected (expected context at position 1)'));\n\t}\n\n\tif (!('value' in valueBox) || typeof valueBox.value !== 'number') {\n\t\tthrow(new Error('Malformed data detected (expected context value at position 1)'));\n\t}\n\n\tif (valueBox.value !== 0 && valueBox.value !== 1) {\n\t\tthrow(new Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 = encryptedCompressedValue;\n\t} else {\n\t\tif (!isArray(value, 1)) {\n\t\t\tthrow(new Error('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 Error('Malformed data (compressed buffer expected at position 1.0)'));\n\t\t}\n\n\t\tif (!acceptableEncryptionAlgorithms.includes('null')) {\n\t\t\tthrow(new Error('Malformed data (plaintext found but the null encryption algorithm is not acceptable)'));\n\t\t}\n\n\t\tcontainedCompressed = containedCompressedUnchecked;\n\t}\n\n\treturn({\n\t\tversion: version,\n\t\tisEncrypted: isEncrypted,\n\t\tinnerValue: containedCompressed,\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 Error('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 Error('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 Error('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 Error('No keys found which can perform decryption on the supplied encryption box'));\n\t\t}\n\n\t\tconst cipherKey = Buffer.from(await decryptionKeyInfo.privateKey.decrypt(bufferToArrayBuffer(decryptionKeyInfo.encryptedSymmetricKey)));\n\n\t\tconst cipherIV = inputInfo.cipherIV;\n\t\tif (cipherIV === undefined) {\n\t\t\tthrow(new Error('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\tcontainedCompressed = Buffer.concat([\n\t\t\tdecipher.update(encryptedCompressedValue),\n\t\t\tdecipher.final()\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\tconst plaintext = Buffer.from(zlibInflate(containedCompressed));\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\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\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 * 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) {\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\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: 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: 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 locked If true, the plaintext data will not be accessible from this instance; otherwise it will be -- default depends on principals\n\t * @returns The EncryptedContainer instance with the plaintext data and principals set\n\t */\n\tstatic fromPlaintext(data: string | Buffer, principals: Account[] | null, locked?: boolean): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\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 | Buffer): void {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = Buffer.from(data, 'utf-8');\n\t\t}\n\n\t\tthis.#data = { plaintext: data };\n\t}\n\n\t/**\n\t * Set the encoded blob to the specified value\n\t */\n\t#setEncodedBuffer(data: Buffer): void {\n\t\tthis.#data = { encoded: 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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('internal error: Plaintext data found but marked as encrypted'));\n\t\t\t}\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 Error('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 Error('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 = 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 Error('No plaintext data available'));\n\t\t}\n\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext\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 Error('No encrypted nor plaintext data available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('internal error: Asked to encrypt a plaintext buffer'));\n\t\t}\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: crypto.randomBytes(32),\n\t\t\t\tcipherIV: crypto.randomBytes(16),\n\t\t\t\tcipherAlgo: this._internalState.cipherAlgo\n\t\t\t}\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): void {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('Unable to grant access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('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\t}\n\n\t/**\n\t * Grant access to the secret for account(s).\n\t */\n\tasync grantAccess(accounts: Account[] | Account): Promise<void> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.grantAccessSync(accounts);\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): void {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('Unable to revoke access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('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\t}\n\n\t/**\n\t * Revoke access to the secret for an account\n\t */\n\tasync revokeAccess(account: Account): Promise<void> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.revokeAccessSync(account);\n\t}\n\n\t/**\n\t * Disable access to the plaintext from this instance\n\t */\n\tdisablePlaintext(): void {\n\t\tthis.#mayAccessPlaintext = false;\n\t}\n\n\t/**\n\t * Get the plaintext for this instance\n\t */\n\tasync getPlaintext(): Promise<Buffer> {\n\t\tif (!this.#mayAccessPlaintext) {\n\t\t\tthrow(new Error('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 Error('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(Buffer.from(plaintext));\n\t}\n\n\t/**\n\t * Get the serializable buffer which can be stored and reconstructed\n\t */\n\tasync getEncodedBuffer(): Promise<Buffer> {\n\t\tconst serialized = await this.#computeEncoded();\n\n\t\tif (serialized === undefined) {\n\t\t\tthrow(new Error('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(Buffer.from(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 Error('May not manage access to a plaintext container'));\n\t\t}\n\n\t\treturn(this._internalState.principals);\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,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,8DAA8D;AACxH,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,8DAA8D;AACxH,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AACjD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AACjD,MAAM,OAAO,GAA+B,WAAW,CAAC,OAAO,CAAC;AAgHhE,MAAM,KAAK,GAAG;IACb,aAAa,EAAE,yBAAyB;CAC/B,CAAC;AAEX;;;;EAIE;AACF,KAAK,UAAU,SAAS,CAAC,SAAiB,EAAE,iBAA+B;IAC1E,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAE/C;;OAEG;IACH,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEhB;;OAEG;IACH,IAAI,iBAAiB,EAAE,CAAC;QACvB,MAA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import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport type {\n\tASN1OID\n} from '@keetanetwork/keetanet-client/lib/utils/asn1.js';\nimport { Buffer, arrayBufferToBuffer, bufferToArrayBuffer } from './utils/buffer.js';\nimport { isArray } from './utils/array.js';\n\nconst zlibDeflate = KeetaNetLib.Utils.Buffer.ZlibDeflate; /* XXX:TODO: Change this to ZlibDeflateAsync when merged in */\nconst zlibInflate = KeetaNetLib.Utils.Buffer.ZlibInflate; /* XXX:TODO: Change this to ZlibInflateAsync when merged in */\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 * 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 * ContainerPackage ::= SEQUENCE {\n * version Version (v2),\n * encryptedContainer [0] EXPLICIT EncryptedContainerBox OPTIONAL,\n * plaintextContainer [1] EXPLICIT PlaintextContainerBox 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\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 ContainerPackage = [\n\t/* version */\n\tnumber,\n\n\t{\n\t\ttype: 'context'\n\t\tvalue: 0,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxEncrypted\n\t} | {\n\t\ttype: 'context',\n\t\tvalue: 1,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxPlaintext\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\nconst oidDB = {\n\t'aes-256-cbc': '2.16.840.1.101.3.4.1.42'\n} as const;\n\n/**\n* Compiles the ASN.1 for the container\n*\n* @returns The ASN.1 DER data\n*/\nasync function buildASN1(plaintext: Buffer, encryptionOptions?: ASN1Options): Promise<Buffer> {\n\tconst compressedPlaintext = Buffer.from(zlibDeflate(plaintext));\n\n\tconst sequence: Partial<ContainerPackage> = [];\n\n\t/*\n\t * Version v2 (1)\n\t */\n\tsequence[0] = 1;\n\n\t/*\n\t * Encrypted container box\n\t */\n\tif (encryptionOptions) {\n\t\tconst { keys, cipherKey, cipherIV, cipherAlgo } = encryptionOptions;\n\n\t\tif (keys === undefined || keys.length === 0 || cipherKey === undefined || cipherIV === undefined || cipherAlgo === undefined) {\n\t\t\tthrow(new Error('internal error: Unsupported method invocation'));\n\t\t}\n\n\t\tif (!(cipherAlgo in oidDB)) {\n\t\t\tthrow(new Error(`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\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\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\tkey.publicKeyAndType,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t];\n\n\t\t\treturn(retval);\n\t\t}));\n\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 0,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [\n\t\t\t\tencryptionKeysSequence,\n\t\t\t\t{ type: 'oid', oid: algorithmOID },\n\t\t\t\tcipherIV,\n\t\t\t\tencryptedData\n\t\t\t]\n\t\t};\n\t} else {\n\t\t/*\n\t\t * Otherwise we simply pass in the compressed data\n\t\t */\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 1,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [compressedPlaintext]\n\t\t};\n\t}\n\n\tconst outputASN1 = JStoASN1(sequence);\n\tconst outputDER = Buffer.from(outputASN1.toBER(false));\n\n\treturn(outputDER);\n}\n\nfunction parseASN1Bare(input: Buffer, acceptableEncryptionAlgorithms = ['aes-256-cbc', 'null']) {\n\tconst inputSequence = ASN1toJS(bufferToArrayBuffer(input));\n\tif (!isArray(inputSequence, 2)) {\n\t\tthrow(new Error('Malformed data detected (incorrect base format)'));\n\t}\n\n\tconst version = inputSequence[0];\n\tif (typeof version !== 'bigint') {\n\t\tthrow(new Error('Malformed data detected (version expected at position 0)'));\n\t}\n\n\tif (version !== 1n) {\n\t\tthrow(new Error('Malformed data detected (unsupported version)'));\n\t}\n\n\tconst valueBox = inputSequence[1];\n\tif (typeof valueBox !== 'object' || valueBox === null) {\n\t\tthrow(new Error('Malformed data detected (data expected at position 1)'));\n\t}\n\n\tif (!('type' in valueBox) || typeof valueBox.type !== 'string') {\n\t\tthrow(new Error('Malformed data detected (expected type at position 1)'));\n\t}\n\n\tif (valueBox.type !== 'context') {\n\t\tthrow(new Error('Malformed data detected (expected context at position 1)'));\n\t}\n\n\tif (!('value' in valueBox) || typeof valueBox.value !== 'number') {\n\t\tthrow(new Error('Malformed data detected (expected context value at position 1)'));\n\t}\n\n\tif (valueBox.value !== 0 && valueBox.value !== 1) {\n\t\tthrow(new Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('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 = encryptedCompressedValue;\n\t} else {\n\t\tif (!isArray(value, 1)) {\n\t\t\tthrow(new Error('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 Error('Malformed data (compressed buffer expected at position 1.0)'));\n\t\t}\n\n\t\tif (!acceptableEncryptionAlgorithms.includes('null')) {\n\t\t\tthrow(new Error('Malformed data (plaintext found but the null encryption algorithm is not acceptable)'));\n\t\t}\n\n\t\tcontainedCompressed = containedCompressedUnchecked;\n\t}\n\n\treturn({\n\t\tversion: version,\n\t\tisEncrypted: isEncrypted,\n\t\tinnerValue: containedCompressed,\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 Error('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 Error('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 Error('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 Error('No keys found which can perform decryption on the supplied encryption box'));\n\t\t}\n\n\t\tconst cipherKey = Buffer.from(await decryptionKeyInfo.privateKey.decrypt(bufferToArrayBuffer(decryptionKeyInfo.encryptedSymmetricKey)));\n\n\t\tconst cipherIV = inputInfo.cipherIV;\n\t\tif (cipherIV === undefined) {\n\t\t\tthrow(new Error('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\tcontainedCompressed = Buffer.concat([\n\t\t\tdecipher.update(encryptedCompressedValue),\n\t\t\tdecipher.final()\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\tconst plaintext = Buffer.from(zlibInflate(containedCompressed));\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\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 * 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) {\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\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 locked If true, the plaintext data will not be accessible from this instance; otherwise it will be -- default depends on principals\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, locked?: boolean): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\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 Error('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 Error('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 Error('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 Error('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 Error('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 Error('internal error: Plaintext data found but marked as encrypted'));\n\t\t\t}\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 Error('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 Error('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 = 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 Error('No plaintext data available'));\n\t\t}\n\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext\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 Error('No encrypted nor plaintext data available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('internal error: Asked to encrypt a plaintext buffer'));\n\t\t}\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: crypto.randomBytes(32),\n\t\t\t\tcipherIV: crypto.randomBytes(16),\n\t\t\t\tcipherAlgo: this._internalState.cipherAlgo\n\t\t\t}\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 Error('Unable to grant access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('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 Error('Unable to revoke access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('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 Error('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 Error('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 Error('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 Error('May not manage access to a plaintext container'));\n\t\t}\n\n\t\treturn(this._internalState.principals);\n\t}\n}\n\n/** @internal */\nexport const _Testing = {\n\tbuildASN1: buildASN1,\n\tparseASN1: parseASN1\n};\n\nexport default EncryptedContainer;\n"]}
@@ -1,5 +1,11 @@
1
1
  import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
2
  import type * as ASN1Types from '@keetanetwork/keetanet-client/lib/utils/asn1.ts';
3
+ type AccountKeyAlgorithm = InstanceType<typeof KeetaNetLib.Account>['keyType'];
4
+ /**
5
+ * An alias for the KeetaNetAccount type
6
+ */
7
+ type KeetaNetAccount = ReturnType<typeof KeetaNetLib.Account.fromSeed<AccountKeyAlgorithm>>;
8
+ declare const KeetaNetAccount: typeof KeetaNetLib.Account;
3
9
  declare const ASN1: typeof KeetaNetLib.Utils.ASN1;
4
10
  declare const ASN1toJS: typeof ASN1.ASN1toJS;
5
11
  declare const JStoASN1: typeof ASN1.JStoASN1;
@@ -16,7 +22,7 @@ type EncodeOptions = {
16
22
  };
17
23
  export declare function contextualizeStructSchema(schema: Schema): Schema;
18
24
  export declare function encodeValueBySchema(schema: Schema, value: unknown, options?: EncodeOptions): ASN1AnyJS;
19
- export declare function normalizeDecodedASN1(input: unknown): unknown;
25
+ export declare function normalizeDecodedASN1(input: unknown, principals: KeetaNetAccount[]): unknown;
20
26
  export type { ASN1AnyJS, ASN1OID, ASN1ContextTag, Schema, SchemaMap };
21
27
  export { ASN1toJS, JStoASN1, BufferStorageASN1, ValidateASN1 };
22
28
  //# sourceMappingURL=asn1.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asn1.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/asn1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,KAAK,SAAS,MAAM,iDAAiD,CAAC;AAWlF,QAAA,MAAM,IAAI,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC,IAA6B,CAAC;AAEnE,QAAA,MAAM,QAAQ,EAAE,OAAO,IAAI,CAAC,QAAwB,CAAC;AACrD,QAAA,MAAM,QAAQ,EAAE,OAAO,IAAI,CAAC,QAAwB,CAAC;AACrD,QAAA,MAAM,iBAAiB,EAAE,OAAO,IAAI,CAAC,iBAA0C,CAAC;AAChF,QAAA,MAAM,YAAY,EAAE,OAAO,IAAI,CAAC,YAAgC,CAAC;AAKjE,KAAK,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;AACrC,KAAK,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;AACjC,KAAK,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;AAC/C,KAAK,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC;AAC5C,KAAK,SAAS,CAAC,CAAC,SAAS,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MAAM,QAAQ,EAAE,OAAO,IAAI,CAAC,QAAwB,CAAC;AACrD,QAAA,MAAM,iBAAiB,EAAE,OAAO,IAAI,CAAC,iBAA0C,CAAC;AAChF,QAAA,MAAM,YAAY,EAAE,OAAO,IAAI,CAAC,YAAgC,CAAC;AAKjE,KAAK,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;AACrC,KAAK,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;AACjC,KAAK,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC;AAC/C,KAAK,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC;AAC5C,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAMvE,KAAK,aAAa,GAAG;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;CAC1C,CAAC;AAwCF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAgDhE;AA+ID,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAetG;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,OAAO,CAqH3F;AAED,YAAY,EACX,SAAS,EACT,OAAO,EACP,cAAc,EACd,MAAM,EACN,SAAS,EACT,CAAC;AAEF,OAAO,EACN,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACZ,CAAC"}
@@ -0,0 +1,41 @@
1
+ type ReferenceSchemaNormalized = {
2
+ type: 'struct';
3
+ fieldNames: string[];
4
+ contains: {
5
+ external: {
6
+ type: 'struct';
7
+ fieldNames: string[];
8
+ contains: {
9
+ url: {
10
+ type: 'string';
11
+ kind: 'utf8';
12
+ value: string;
13
+ };
14
+ contentType: {
15
+ type: 'string';
16
+ kind: 'utf8';
17
+ value: string;
18
+ };
19
+ };
20
+ };
21
+ digest: {
22
+ type: 'struct';
23
+ fieldNames: string[];
24
+ contains: {
25
+ digestAlgorithm: {
26
+ type: 'oid';
27
+ oid: string;
28
+ };
29
+ digest: unknown;
30
+ };
31
+ };
32
+ encryptionAlgorithm: {
33
+ type: 'oid';
34
+ oid: string;
35
+ } | undefined;
36
+ };
37
+ };
38
+ export declare const isReferenceSchema: (input: unknown) => input is ReferenceSchemaNormalized;
39
+ export declare const assertReference: (input: unknown) => ReferenceSchemaNormalized;
40
+ export {};
41
+ //# sourceMappingURL=asn1.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asn1.generated.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/asn1.generated.ts"],"names":[],"mappings":"AAMA,KAAK,yBAAyB,GAAG;IAChC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE;QACT,QAAQ,EAAE;YACT,IAAI,EAAE,QAAQ,CAAC;YACf,UAAU,EAAE,MAAM,EAAE,CAAC;YACrB,QAAQ,EAAE;gBACT,GAAG,EAAE;oBACJ,IAAI,EAAE,QAAQ,CAAC;oBACf,IAAI,EAAE,MAAM,CAAC;oBACb,KAAK,EAAE,MAAM,CAAC;iBACd,CAAC;gBACF,WAAW,EAAE;oBAAE,IAAI,EAAE,QAAQ,CAAC;oBAAC,IAAI,EAAE,MAAM,CAAC;oBAAC,KAAK,EAAE,MAAM,CAAC;iBAAE,CAAC;aAC9D,CAAC;SACF,CAAC;QACF,MAAM,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC;YACf,UAAU,EAAE,MAAM,EAAE,CAAC;YACrB,QAAQ,EAAE;gBACT,eAAe,EAAE;oBAAE,IAAI,EAAE,KAAK,CAAC;oBAAC,GAAG,EAAE,MAAM,CAAC;iBAAE,CAAC;gBAC/C,MAAM,EAAE,OAAO,CAAC;aAChB,CAAC;SACF,CAAC;QACF,mBAAmB,EAAE;YAAE,IAAI,EAAE,KAAK,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;SAAE,GAAG,SAAS,CAAC;KAC/D,CAAC;CACF,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,yBAAuE,CAAC;AACrI,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,yBAA2E,CAAC"}
@@ -0,0 +1,221 @@
1
+ import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
+ import * as typia from 'typia';
3
+ export const isReferenceSchema = (() => { const _io0 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io1(input.contains)); const _io1 = input => "object" === typeof input.external && null !== input.external && _io2(input.external) && ("object" === typeof input.digest && null !== input.digest && _io6(input.digest)) && (undefined === input.encryptionAlgorithm || "object" === typeof input.encryptionAlgorithm && null !== input.encryptionAlgorithm && _io9(input.encryptionAlgorithm)); const _io2 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io3(input.contains)); const _io3 = input => "object" === typeof input.url && null !== input.url && _io4(input.url) && ("object" === typeof input.contentType && null !== input.contentType && _io5(input.contentType)); const _io4 = input => "string" === input.type && "utf8" === input.kind && "string" === typeof input.value; const _io5 = input => "string" === input.type && "utf8" === input.kind && "string" === typeof input.value; const _io6 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io7(input.contains)); const _io7 = input => "object" === typeof input.digestAlgorithm && null !== input.digestAlgorithm && _io8(input.digestAlgorithm) && true; const _io8 = input => "oid" === input.type && "string" === typeof input.oid; const _io9 = input => "oid" === input.type && "string" === typeof input.oid; return input => "object" === typeof input && null !== input && _io0(input); })();
4
+ export const assertReference = (() => { const _io0 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io1(input.contains)); const _io1 = input => "object" === typeof input.external && null !== input.external && _io2(input.external) && ("object" === typeof input.digest && null !== input.digest && _io6(input.digest)) && (undefined === input.encryptionAlgorithm || "object" === typeof input.encryptionAlgorithm && null !== input.encryptionAlgorithm && _io9(input.encryptionAlgorithm)); const _io2 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io3(input.contains)); const _io3 = input => "object" === typeof input.url && null !== input.url && _io4(input.url) && ("object" === typeof input.contentType && null !== input.contentType && _io5(input.contentType)); const _io4 = input => "string" === input.type && "utf8" === input.kind && "string" === typeof input.value; const _io5 = input => "string" === input.type && "utf8" === input.kind && "string" === typeof input.value; const _io6 = input => "struct" === input.type && (Array.isArray(input.fieldNames) && input.fieldNames.every(elem => "string" === typeof elem)) && ("object" === typeof input.contains && null !== input.contains && _io7(input.contains)); const _io7 = input => "object" === typeof input.digestAlgorithm && null !== input.digestAlgorithm && _io8(input.digestAlgorithm) && true; const _io8 = input => "oid" === input.type && "string" === typeof input.oid; const _io9 = input => "oid" === input.type && "string" === typeof input.oid; const _ao0 = (input, _path, _exceptionable = true) => ("struct" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
5
+ method: "typia.createAssert",
6
+ path: _path + ".type",
7
+ expected: "\"struct\"",
8
+ value: input.type
9
+ }, _errorFactory)) && ((Array.isArray(input.fieldNames) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
10
+ method: "typia.createAssert",
11
+ path: _path + ".fieldNames",
12
+ expected: "Array<string>",
13
+ value: input.fieldNames
14
+ }, _errorFactory)) && input.fieldNames.every((elem, _index4) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
15
+ method: "typia.createAssert",
16
+ path: _path + ".fieldNames[" + _index4 + "]",
17
+ expected: "string",
18
+ value: elem
19
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
20
+ method: "typia.createAssert",
21
+ path: _path + ".fieldNames",
22
+ expected: "Array<string>",
23
+ value: input.fieldNames
24
+ }, _errorFactory)) && (("object" === typeof input.contains && null !== input.contains || __typia_transform__assertGuard._assertGuard(_exceptionable, {
25
+ method: "typia.createAssert",
26
+ path: _path + ".contains",
27
+ expected: "__type",
28
+ value: input.contains
29
+ }, _errorFactory)) && _ao1(input.contains, _path + ".contains", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
30
+ method: "typia.createAssert",
31
+ path: _path + ".contains",
32
+ expected: "__type",
33
+ value: input.contains
34
+ }, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.external && null !== input.external || __typia_transform__assertGuard._assertGuard(_exceptionable, {
35
+ method: "typia.createAssert",
36
+ path: _path + ".external",
37
+ expected: "__type.o1",
38
+ value: input.external
39
+ }, _errorFactory)) && _ao2(input.external, _path + ".external", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
40
+ method: "typia.createAssert",
41
+ path: _path + ".external",
42
+ expected: "__type.o1",
43
+ value: input.external
44
+ }, _errorFactory)) && (("object" === typeof input.digest && null !== input.digest || __typia_transform__assertGuard._assertGuard(_exceptionable, {
45
+ method: "typia.createAssert",
46
+ path: _path + ".digest",
47
+ expected: "__type.o5",
48
+ value: input.digest
49
+ }, _errorFactory)) && _ao6(input.digest, _path + ".digest", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
50
+ method: "typia.createAssert",
51
+ path: _path + ".digest",
52
+ expected: "__type.o5",
53
+ value: input.digest
54
+ }, _errorFactory)) && (undefined === input.encryptionAlgorithm || ("object" === typeof input.encryptionAlgorithm && null !== input.encryptionAlgorithm || __typia_transform__assertGuard._assertGuard(_exceptionable, {
55
+ method: "typia.createAssert",
56
+ path: _path + ".encryptionAlgorithm",
57
+ expected: "(__type.o8 | undefined)",
58
+ value: input.encryptionAlgorithm
59
+ }, _errorFactory)) && _ao9(input.encryptionAlgorithm, _path + ".encryptionAlgorithm", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
60
+ method: "typia.createAssert",
61
+ path: _path + ".encryptionAlgorithm",
62
+ expected: "(__type.o8 | undefined)",
63
+ value: input.encryptionAlgorithm
64
+ }, _errorFactory)); const _ao2 = (input, _path, _exceptionable = true) => ("struct" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
65
+ method: "typia.createAssert",
66
+ path: _path + ".type",
67
+ expected: "\"struct\"",
68
+ value: input.type
69
+ }, _errorFactory)) && ((Array.isArray(input.fieldNames) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
70
+ method: "typia.createAssert",
71
+ path: _path + ".fieldNames",
72
+ expected: "Array<string>",
73
+ value: input.fieldNames
74
+ }, _errorFactory)) && input.fieldNames.every((elem, _index5) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
75
+ method: "typia.createAssert",
76
+ path: _path + ".fieldNames[" + _index5 + "]",
77
+ expected: "string",
78
+ value: elem
79
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
80
+ method: "typia.createAssert",
81
+ path: _path + ".fieldNames",
82
+ expected: "Array<string>",
83
+ value: input.fieldNames
84
+ }, _errorFactory)) && (("object" === typeof input.contains && null !== input.contains || __typia_transform__assertGuard._assertGuard(_exceptionable, {
85
+ method: "typia.createAssert",
86
+ path: _path + ".contains",
87
+ expected: "__type.o2",
88
+ value: input.contains
89
+ }, _errorFactory)) && _ao3(input.contains, _path + ".contains", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
90
+ method: "typia.createAssert",
91
+ path: _path + ".contains",
92
+ expected: "__type.o2",
93
+ value: input.contains
94
+ }, _errorFactory)); const _ao3 = (input, _path, _exceptionable = true) => (("object" === typeof input.url && null !== input.url || __typia_transform__assertGuard._assertGuard(_exceptionable, {
95
+ method: "typia.createAssert",
96
+ path: _path + ".url",
97
+ expected: "__type.o3",
98
+ value: input.url
99
+ }, _errorFactory)) && _ao4(input.url, _path + ".url", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
100
+ method: "typia.createAssert",
101
+ path: _path + ".url",
102
+ expected: "__type.o3",
103
+ value: input.url
104
+ }, _errorFactory)) && (("object" === typeof input.contentType && null !== input.contentType || __typia_transform__assertGuard._assertGuard(_exceptionable, {
105
+ method: "typia.createAssert",
106
+ path: _path + ".contentType",
107
+ expected: "__type.o4",
108
+ value: input.contentType
109
+ }, _errorFactory)) && _ao5(input.contentType, _path + ".contentType", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
110
+ method: "typia.createAssert",
111
+ path: _path + ".contentType",
112
+ expected: "__type.o4",
113
+ value: input.contentType
114
+ }, _errorFactory)); const _ao4 = (input, _path, _exceptionable = true) => ("string" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
115
+ method: "typia.createAssert",
116
+ path: _path + ".type",
117
+ expected: "\"string\"",
118
+ value: input.type
119
+ }, _errorFactory)) && ("utf8" === input.kind || __typia_transform__assertGuard._assertGuard(_exceptionable, {
120
+ method: "typia.createAssert",
121
+ path: _path + ".kind",
122
+ expected: "\"utf8\"",
123
+ value: input.kind
124
+ }, _errorFactory)) && ("string" === typeof input.value || __typia_transform__assertGuard._assertGuard(_exceptionable, {
125
+ method: "typia.createAssert",
126
+ path: _path + ".value",
127
+ expected: "string",
128
+ value: input.value
129
+ }, _errorFactory)); const _ao5 = (input, _path, _exceptionable = true) => ("string" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
130
+ method: "typia.createAssert",
131
+ path: _path + ".type",
132
+ expected: "\"string\"",
133
+ value: input.type
134
+ }, _errorFactory)) && ("utf8" === input.kind || __typia_transform__assertGuard._assertGuard(_exceptionable, {
135
+ method: "typia.createAssert",
136
+ path: _path + ".kind",
137
+ expected: "\"utf8\"",
138
+ value: input.kind
139
+ }, _errorFactory)) && ("string" === typeof input.value || __typia_transform__assertGuard._assertGuard(_exceptionable, {
140
+ method: "typia.createAssert",
141
+ path: _path + ".value",
142
+ expected: "string",
143
+ value: input.value
144
+ }, _errorFactory)); const _ao6 = (input, _path, _exceptionable = true) => ("struct" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
145
+ method: "typia.createAssert",
146
+ path: _path + ".type",
147
+ expected: "\"struct\"",
148
+ value: input.type
149
+ }, _errorFactory)) && ((Array.isArray(input.fieldNames) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
150
+ method: "typia.createAssert",
151
+ path: _path + ".fieldNames",
152
+ expected: "Array<string>",
153
+ value: input.fieldNames
154
+ }, _errorFactory)) && input.fieldNames.every((elem, _index6) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
155
+ method: "typia.createAssert",
156
+ path: _path + ".fieldNames[" + _index6 + "]",
157
+ expected: "string",
158
+ value: elem
159
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
160
+ method: "typia.createAssert",
161
+ path: _path + ".fieldNames",
162
+ expected: "Array<string>",
163
+ value: input.fieldNames
164
+ }, _errorFactory)) && (("object" === typeof input.contains && null !== input.contains || __typia_transform__assertGuard._assertGuard(_exceptionable, {
165
+ method: "typia.createAssert",
166
+ path: _path + ".contains",
167
+ expected: "__type.o6",
168
+ value: input.contains
169
+ }, _errorFactory)) && _ao7(input.contains, _path + ".contains", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
170
+ method: "typia.createAssert",
171
+ path: _path + ".contains",
172
+ expected: "__type.o6",
173
+ value: input.contains
174
+ }, _errorFactory)); const _ao7 = (input, _path, _exceptionable = true) => (("object" === typeof input.digestAlgorithm && null !== input.digestAlgorithm || __typia_transform__assertGuard._assertGuard(_exceptionable, {
175
+ method: "typia.createAssert",
176
+ path: _path + ".digestAlgorithm",
177
+ expected: "__type.o7",
178
+ value: input.digestAlgorithm
179
+ }, _errorFactory)) && _ao8(input.digestAlgorithm, _path + ".digestAlgorithm", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
180
+ method: "typia.createAssert",
181
+ path: _path + ".digestAlgorithm",
182
+ expected: "__type.o7",
183
+ value: input.digestAlgorithm
184
+ }, _errorFactory)) && true; const _ao8 = (input, _path, _exceptionable = true) => ("oid" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
185
+ method: "typia.createAssert",
186
+ path: _path + ".type",
187
+ expected: "\"oid\"",
188
+ value: input.type
189
+ }, _errorFactory)) && ("string" === typeof input.oid || __typia_transform__assertGuard._assertGuard(_exceptionable, {
190
+ method: "typia.createAssert",
191
+ path: _path + ".oid",
192
+ expected: "string",
193
+ value: input.oid
194
+ }, _errorFactory)); const _ao9 = (input, _path, _exceptionable = true) => ("oid" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
195
+ method: "typia.createAssert",
196
+ path: _path + ".type",
197
+ expected: "\"oid\"",
198
+ value: input.type
199
+ }, _errorFactory)) && ("string" === typeof input.oid || __typia_transform__assertGuard._assertGuard(_exceptionable, {
200
+ method: "typia.createAssert",
201
+ path: _path + ".oid",
202
+ expected: "string",
203
+ value: input.oid
204
+ }, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; return (input, errorFactory) => {
205
+ if (false === __is(input)) {
206
+ _errorFactory = errorFactory;
207
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
208
+ method: "typia.createAssert",
209
+ path: _path + "",
210
+ expected: "ReferenceSchemaNormalized",
211
+ value: input
212
+ }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
213
+ method: "typia.createAssert",
214
+ path: _path + "",
215
+ expected: "ReferenceSchemaNormalized",
216
+ value: input
217
+ }, _errorFactory))(input, "$input", true);
218
+ }
219
+ return input;
220
+ }; })();
221
+ //# sourceMappingURL=asn1.generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asn1.generated.js","sourceRoot":"","sources":["../../../src/lib/utils/asn1.generated.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkC/B,MAAM,CAAC,MAAM,iBAAiB,k0DAAsG,CAAC;AACrI,MAAM,CAAC,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAiG,CAAC","sourcesContent":["import * as typia from 'typia';\n\n/*\n * We can't statically check that ReferenceSchemaNormalized is a subset of ReferenceSchema\n * because it is generated as ASN1.Schema instead of a more specific type\n */\ntype ReferenceSchemaNormalized = {\n\ttype: 'struct';\n\tfieldNames: string[];\n\tcontains: {\n\t\texternal: {\n\t\t\ttype: 'struct';\n\t\t\tfieldNames: string[];\n\t\t\tcontains: {\n\t\t\t\turl: {\n\t\t\t\t\ttype: 'string';\n\t\t\t\t\tkind: 'utf8';\n\t\t\t\t\tvalue: string;\n\t\t\t\t};\n\t\t\t\tcontentType: { type: 'string'; kind: 'utf8'; value: string; };\n\t\t\t};\n\t\t};\n\t\tdigest: {\n\t\t\ttype: 'struct';\n\t\t\tfieldNames: string[];\n\t\t\tcontains: {\n\t\t\t\tdigestAlgorithm: { type: 'oid'; oid: string; };\n\t\t\t\tdigest: unknown;\n\t\t\t};\n\t\t};\n\t\tencryptionAlgorithm: { type: 'oid'; oid: string; } | undefined;\n\t};\n};\n\nexport const isReferenceSchema: (input: unknown) => input is ReferenceSchemaNormalized = typia.createIs<ReferenceSchemaNormalized>();\nexport const assertReference: (input: unknown) => ReferenceSchemaNormalized = typia.createAssert<ReferenceSchemaNormalized>();\n"]}