@twin.org/crypto 0.0.4-next.8 → 0.9.0
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/dist/es/curves/ed25519.js +1 -1
- package/dist/es/curves/ed25519.js.map +1 -1
- package/dist/es/curves/secp256k1.js +1 -1
- package/dist/es/curves/secp256k1.js.map +1 -1
- package/dist/es/hashes/argon2id.js +1 -1
- package/dist/es/hashes/argon2id.js.map +1 -1
- package/dist/es/hashes/blake2b.js +1 -1
- package/dist/es/hashes/blake2b.js.map +1 -1
- package/dist/es/hashes/blake3.js +1 -1
- package/dist/es/hashes/blake3.js.map +1 -1
- package/dist/es/hashes/hmacSha1.js +1 -1
- package/dist/es/hashes/hmacSha1.js.map +1 -1
- package/dist/es/hashes/hmacSha256.js +2 -1
- package/dist/es/hashes/hmacSha256.js.map +1 -1
- package/dist/es/hashes/hmacSha512.js +2 -1
- package/dist/es/hashes/hmacSha512.js.map +1 -1
- package/dist/es/hashes/sha1.js +1 -1
- package/dist/es/hashes/sha1.js.map +1 -1
- package/dist/es/hashes/sha256.js +2 -1
- package/dist/es/hashes/sha256.js.map +1 -1
- package/dist/es/hashes/sha3.js +2 -1
- package/dist/es/hashes/sha3.js.map +1 -1
- package/dist/es/hashes/sha512.js +2 -1
- package/dist/es/hashes/sha512.js.map +1 -1
- package/dist/es/helpers/integrityHelper.js +1 -1
- package/dist/es/helpers/integrityHelper.js.map +1 -1
- package/dist/es/keys/slip0010.js +1 -1
- package/dist/es/keys/slip0010.js.map +1 -1
- package/dist/es/otp/totp.js +1 -1
- package/dist/es/otp/totp.js.map +1 -1
- package/dist/types/curves/ed25519.d.ts +1 -1
- package/dist/types/curves/secp256k1.d.ts +1 -1
- package/dist/types/hashes/argon2id.d.ts +1 -1
- package/dist/types/hashes/blake2b.d.ts +1 -1
- package/dist/types/hashes/blake3.d.ts +1 -1
- package/dist/types/hashes/hmacSha1.d.ts +1 -1
- package/dist/types/hashes/hmacSha256.d.ts +2 -1
- package/dist/types/hashes/hmacSha512.d.ts +2 -1
- package/dist/types/hashes/sha1.d.ts +1 -1
- package/dist/types/hashes/sha256.d.ts +2 -1
- package/dist/types/hashes/sha3.d.ts +2 -1
- package/dist/types/hashes/sha512.d.ts +2 -1
- package/dist/types/keys/slip0010.d.ts +1 -1
- package/dist/types/otp/totp.d.ts +1 -1
- package/docs/changelog.md +219 -0
- package/docs/reference/classes/Argon2id.md +1 -1
- package/docs/reference/classes/Blake2b.md +1 -1
- package/docs/reference/classes/Blake3.md +1 -1
- package/docs/reference/classes/Ed25519.md +1 -1
- package/docs/reference/classes/HmacSha1.md +1 -1
- package/docs/reference/classes/HmacSha256.md +5 -1
- package/docs/reference/classes/HmacSha512.md +5 -1
- package/docs/reference/classes/Secp256k1.md +1 -1
- package/docs/reference/classes/Sha1.md +1 -1
- package/docs/reference/classes/Sha256.md +5 -1
- package/docs/reference/classes/Sha3.md +5 -1
- package/docs/reference/classes/Sha512.md +5 -1
- package/docs/reference/classes/Slip0010.md +1 -1
- package/docs/reference/classes/Totp.md +1 -1
- package/package.json +4 -4
|
@@ -35,7 +35,7 @@ export class Ed25519 {
|
|
|
35
35
|
return ed25519.getPublicKey(privateKey);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Signs the block with the private key and returns a signature.
|
|
39
39
|
* @param privateKey The private key.
|
|
40
40
|
* @param block The block to sign.
|
|
41
41
|
* @returns The signature.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../../src/curves/ed25519.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGxE;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACI,MAAM,CA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,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAoB;QACzD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,eAAqB,SAAS,CAAC,CAAC;QAEjE,uEAAuE;QACvE,8DAA8D;QAC9D,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAErE,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { GeneralError, Guards, Uint8ArrayHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of Ed25519.\n */\nexport class Ed25519 {\n\t/**\n\t * Private Key Size is the size, in bytes, of private keys as used in this package.\n\t */\n\tpublic static PRIVATE_KEY_SIZE: number = 32;\n\n\t/**\n\t * Public Key Size is the size, in bytes, of public keys as used in this package.\n\t */\n\tpublic static PUBLIC_KEY_SIZE: number = 32;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Ed25519>();\n\n\t/**\n\t * Public returns the PublicKey corresponding to private.\n\t * @param privateKey The private key to get the corresponding public key.\n\t * @returns The public key.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static publicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(privateKey), privateKey);\n\n\t\tif (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Ed25519.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Ed25519.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\treturn ed25519.getPublicKey(privateKey);\n\t}\n\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../../src/curves/ed25519.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGxE;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACI,MAAM,CAAC,gBAAgB,GAAW,EAAE,CAAC;IAE5C;;OAEG;IACI,MAAM,CAAC,eAAe,GAAW,EAAE,CAAC;IAE3C;;OAEG;IACI,MAAM,CAAU,UAAU,aAA6B;IAE9D;;;;;OAKG;IACI,MAAM,CAAC,uBAAuB,CAAC,UAAsB;QAC3D,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QAEtE,IAAI,UAAU,CAAC,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACpD,MAAM,IAAI,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,kBAAkB,EAAE;gBAC9D,YAAY,EAAE,OAAO,CAAC,gBAAgB;gBACtC,UAAU,EAAE,UAAU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BAAiB,CAAC,SAAoB;QACzD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,eAAqB,SAAS,CAAC,CAAC;QAEjE,uEAAuE;QACvE,8DAA8D;QAC9D,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAErE,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { GeneralError, Guards, Uint8ArrayHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of Ed25519.\n */\nexport class Ed25519 {\n\t/**\n\t * Private Key Size is the size, in bytes, of private keys as used in this package.\n\t */\n\tpublic static PRIVATE_KEY_SIZE: number = 32;\n\n\t/**\n\t * Public Key Size is the size, in bytes, of public keys as used in this package.\n\t */\n\tpublic static PUBLIC_KEY_SIZE: number = 32;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Ed25519>();\n\n\t/**\n\t * Public returns the PublicKey corresponding to private.\n\t * @param privateKey The private key to get the corresponding public key.\n\t * @returns The public key.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static publicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(privateKey), privateKey);\n\n\t\tif (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Ed25519.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Ed25519.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\treturn ed25519.getPublicKey(privateKey);\n\t}\n\n\t/**\n\t * Signs the block with the private key and returns a signature.\n\t * @param privateKey The private key.\n\t * @param block The block to sign.\n\t * @returns The signature.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static sign(privateKey: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(privateKey), privateKey);\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(block), block);\n\n\t\tif (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Ed25519.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Ed25519.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey ? privateKey.length : 0\n\t\t\t});\n\t\t}\n\n\t\treturn ed25519.sign(block, privateKey);\n\t}\n\n\t/**\n\t * Verify reports whether sig is a valid signature of block by publicKey.\n\t * @param publicKey The public key to verify the signature.\n\t * @param block The block for the signature.\n\t * @param signature The signature.\n\t * @returns True if the signature matches.\n\t * @throws Error if the public key is not the correct length.\n\t */\n\tpublic static verify(publicKey: Uint8Array, block: Uint8Array, signature: Uint8Array): boolean {\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(publicKey), publicKey);\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(block), block);\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(signature), signature);\n\n\t\tif (publicKey.length !== Ed25519.PUBLIC_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Ed25519.CLASS_NAME, \"publicKeyLength\", {\n\t\t\t\trequiredSize: Ed25519.PUBLIC_KEY_SIZE,\n\t\t\t\tactualSize: publicKey ? publicKey.length : 0\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\treturn ed25519.verify(signature, block, publicKey);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Convert a private key in PKCS8 format.\n\t * @param privateKey The private key to convert.\n\t * @returns The private key in PKCS8 format.\n\t */\n\tpublic static async privateKeyToPkcs8(privateKey: Uint8Array): Promise<CryptoKey> {\n\t\tGuards.uint8Array(Ed25519.CLASS_NAME, nameof(privateKey), privateKey);\n\n\t\tif (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Ed25519.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Ed25519.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\t// crypto.subtle.importKey does not support Ed25519 keys in raw format.\n\t\t// We need to convert the key to PKCS8 format before importing.\n\t\t// The PKCS8 format is the raw key prefixed with the ASN.1 sequence for an Ed25519 private key.\n\t\t// The ASN.1 sequence is 48 46 02 01 00 30 05 06 03 2b 65 70 04 20 04 20 (0x302e020100300506032b657004220420)\n\t\tconst pkcs8Prefix = new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);\n\t\tconst fullKey = Uint8ArrayHelper.concat([pkcs8Prefix, privateKey]);\n\t\treturn crypto.subtle.importKey(\"pkcs8\", new Uint8Array(fullKey), \"Ed25519\", true, [\"sign\"]);\n\t}\n\n\t/**\n\t * Convert a crypto key to raw private key.\n\t * @param cryptoKey The crypto key to convert.\n\t * @returns The raw private key.\n\t */\n\tpublic static async pkcs8ToPrivateKey(cryptoKey: CryptoKey): Promise<Uint8Array> {\n\t\tGuards.defined(Ed25519.CLASS_NAME, nameof(cryptoKey), cryptoKey);\n\n\t\t// crypto.subtle.exportKey does not support Ed25519 keys in raw format.\n\t\t// so we export as PKCS8 and remove the ASN.1 sequence prefix.\n\t\tconst pkcs8Bytes = await crypto.subtle.exportKey(\"pkcs8\", cryptoKey);\n\n\t\treturn new Uint8Array(pkcs8Bytes.slice(16));\n\t}\n}\n"]}
|
|
@@ -35,7 +35,7 @@ export class Secp256k1 {
|
|
|
35
35
|
return secp256k1.getPublicKey(privateKey);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Signs the block with the private key and returns a signature.
|
|
39
39
|
* @param privateKey The private key.
|
|
40
40
|
* @param block The block to sign.
|
|
41
41
|
* @returns The signature.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/curves/secp256k1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,SAAS;IACrB;;OAEG;IACI,MAAM,CAAC,gBAAgB,GAAW,EAAE,CAAC;IAE5C;;OAEG;IACI,MAAM,CAAC,eAAe,GAAW,EAAE,CAAC;IAE3C;;OAEG;IACI,MAAM,CAAU,UAAU,eAA+B;IAEhE;;;;;OAKG;IACI,MAAM,CAAC,uBAAuB,CAAC,UAAsB;QAC3D,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QAExE,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,CAAC,gBAAgB,EAAE,CAAC;YACtD,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,UAAU,EAAE,kBAAkB,EAAE;gBAChE,YAAY,EAAE,SAAS,CAAC,gBAAgB;gBACxC,UAAU,EAAE,UAAU,CAAC,MAAM;aAC7B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,IAAI,CAAC,UAAsB,EAAE,KAAiB;QAC3D,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QACxE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAE9D,IAAI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ier: Apache-2.0.\nimport { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of secp256k1.\n */\nexport class Secp256k1 {\n\t/**\n\t * Private Key Size is the size, in bytes, of private keys as used in this package.\n\t */\n\tpublic static PRIVATE_KEY_SIZE: number = 32;\n\n\t/**\n\t * Public Key Size is the size, in bytes, of public keys as used in this package.\n\t */\n\tpublic static PUBLIC_KEY_SIZE: number = 33;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Secp256k1>();\n\n\t/**\n\t * Public returns the PublicKey corresponding to private.\n\t * @param privateKey The private key to get the corresponding public key.\n\t * @returns The public key.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static publicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(privateKey), privateKey);\n\n\t\tif (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Secp256k1.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Secp256k1.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\treturn secp256k1.getPublicKey(privateKey);\n\t}\n\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/curves/secp256k1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,SAAS;IACrB;;OAEG;IACI,MAAM,CAAC,gBAAgB,GAAW,EAAE,CAAC;IAE5C;;OAEG;IACI,MAAM,CAAC,eAAe,GAAW,EA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UAAU,eAAqB,SAAS,CAAC,CAAC;QACtE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC9D,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,eAAqB,SAAS,CAAC,CAAC;QAEtE,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,CAAC,eAAe,EAAE,CAAC;YACpD,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,UAAU,EAAE,iBAAiB,EAAE;gBAC/D,YAAY,EAAE,SAAS,CAAC,eAAe;gBACvC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aAC5C,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of secp256k1.\n */\nexport class Secp256k1 {\n\t/**\n\t * Private Key Size is the size, in bytes, of private keys as used in this package.\n\t */\n\tpublic static PRIVATE_KEY_SIZE: number = 32;\n\n\t/**\n\t * Public Key Size is the size, in bytes, of public keys as used in this package.\n\t */\n\tpublic static PUBLIC_KEY_SIZE: number = 33;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Secp256k1>();\n\n\t/**\n\t * Public returns the PublicKey corresponding to private.\n\t * @param privateKey The private key to get the corresponding public key.\n\t * @returns The public key.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static publicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(privateKey), privateKey);\n\n\t\tif (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Secp256k1.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Secp256k1.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\treturn secp256k1.getPublicKey(privateKey);\n\t}\n\n\t/**\n\t * Signs the block with the private key and returns a signature.\n\t * @param privateKey The private key.\n\t * @param block The block to sign.\n\t * @returns The signature.\n\t * @throws Error if the private key is not the correct length.\n\t */\n\tpublic static sign(privateKey: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(privateKey), privateKey);\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(block), block);\n\n\t\tif (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Secp256k1.CLASS_NAME, \"privateKeyLength\", {\n\t\t\t\trequiredSize: Secp256k1.PRIVATE_KEY_SIZE,\n\t\t\t\tactualSize: privateKey.length\n\t\t\t});\n\t\t}\n\n\t\tconst res = secp256k1.sign(block, privateKey, { prehash: false });\n\t\treturn res;\n\t}\n\n\t/**\n\t * Verify reports whether sig is a valid signature of block by publicKey.\n\t * @param publicKey The public key to verify the signature.\n\t * @param block The block for the signature.\n\t * @param signature The signature.\n\t * @returns True if the signature matches.\n\t * @throws Error if the public key is not the correct length.\n\t */\n\tpublic static verify(publicKey: Uint8Array, block: Uint8Array, signature: Uint8Array): boolean {\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(publicKey), publicKey);\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(block), block);\n\t\tGuards.uint8Array(Secp256k1.CLASS_NAME, nameof(signature), signature);\n\n\t\tif (publicKey.length !== Secp256k1.PUBLIC_KEY_SIZE) {\n\t\t\tthrow new GeneralError(Secp256k1.CLASS_NAME, \"publicKeyLength\", {\n\t\t\t\trequiredSize: Secp256k1.PUBLIC_KEY_SIZE,\n\t\t\t\tactualSize: publicKey ? publicKey.length : 0\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\treturn secp256k1.verify(signature, block, publicKey, { prehash: false });\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export class Argon2id {
|
|
|
20
20
|
* @param options.p Number of parallel threads to use, default 1.
|
|
21
21
|
* @param options.dkLen The length of the derived key in bytes, default 32.
|
|
22
22
|
* @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.
|
|
23
|
-
* @returns
|
|
23
|
+
* @returns A promise that resolves with the derived key bytes.
|
|
24
24
|
*/
|
|
25
25
|
static async hash(password, salt, options) {
|
|
26
26
|
Guards.uint8Array(Argon2id.CLASS_NAME, "password", password);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argon2id.js","sourceRoot":"","sources":["../../../src/hashes/argon2id.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,QAAoB,EACpB,IAAgB,EAChB,OAMC;QAED,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QACnE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG;YACpB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE;YAC3B,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE;SAClC,CAAC;QACF,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { argon2idAsync } from \"@noble/hashes/argon2.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of the Argon2id password based key derivation function.\n */\nexport class Argon2id {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Argon2id>();\n\n\t/**\n\t * Derive a key from the parameters using Argon2id.\n\t * @param password The password to derive the key from.\n\t * @param salt The salt for the derivation.\n\t * @param options The options for the derivation.\n\t * @param options.t Number of iterations to perform, default 1.\n\t * @param options.m Amount of memory to use in kibibytes, default 8.\n\t * @param options.p Number of parallel threads to use, default 1.\n\t * @param options.dkLen The length of the derived key in bytes, default 32.\n\t * @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.\n\t * @returns
|
|
1
|
+
{"version":3,"file":"argon2id.js","sourceRoot":"","sources":["../../../src/hashes/argon2id.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,QAAoB,EACpB,IAAgB,EAChB,OAMC;QAED,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QACnE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG;YACpB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE;YAC3B,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE;SAClC,CAAC;QACF,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { argon2idAsync } from \"@noble/hashes/argon2.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of the Argon2id password based key derivation function.\n */\nexport class Argon2id {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Argon2id>();\n\n\t/**\n\t * Derive a key from the parameters using Argon2id.\n\t * @param password The password to derive the key from.\n\t * @param salt The salt for the derivation.\n\t * @param options The options for the derivation.\n\t * @param options.t Number of iterations to perform, default 1.\n\t * @param options.m Amount of memory to use in kibibytes, default 8.\n\t * @param options.p Number of parallel threads to use, default 1.\n\t * @param options.dkLen The length of the derived key in bytes, default 32.\n\t * @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.\n\t * @returns A promise that resolves with the derived key bytes.\n\t */\n\tpublic static async hash(\n\t\tpassword: Uint8Array,\n\t\tsalt: Uint8Array,\n\t\toptions?: {\n\t\t\tt?: number;\n\t\t\tm?: number;\n\t\t\tp?: number;\n\t\t\tdkLen?: number;\n\t\t\tmaxmem?: number;\n\t\t}\n\t): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Argon2id.CLASS_NAME, nameof(password), password);\n\t\tGuards.uint8Array(Argon2id.CLASS_NAME, nameof(salt), salt);\n\t\tconst localOptions = {\n\t\t\tt: options?.t ?? 1,\n\t\t\tm: options?.m ?? 8,\n\t\t\tp: options?.p ?? 1,\n\t\t\tdkLen: options?.dkLen ?? 32,\n\t\t\tmaxmem: options?.maxmem ?? 2 ** 30\n\t\t};\n\t\treturn argon2idAsync(password, salt, localOptions);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blake2b.js","sourceRoot":"","sources":["../../../src/hashes/blake2b.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAU,UAAU,aAA6B;IAE9D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;;OAIG;IACH,YAAY,YAAoB,EAAE,GAAgB;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;YAC/B,KAAK,EAAE,YAAY;YACnB,GAAG;SACH,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { blake2b } from \"@noble/hashes/blake2.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with Blake2B Signature scheme.\n */\nexport class Blake2b {\n\t/**\n\t * Blake2b 160.\n\t */\n\tpublic static SIZE_160: number = 20;\n\n\t/**\n\t * Blake2b 256.\n\t */\n\tpublic static SIZE_256: number = 32;\n\n\t/**\n\t * Blake2b 512.\n\t */\n\tpublic static SIZE_512: number = 64;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Blake2b>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Blake2b.\n\t * @param outputLength The output length.\n\t * @param key Optional key for the hash.\n\t */\n\tconstructor(outputLength: number, key?: Uint8Array) {\n\t\tthis._instance = blake2b.create({\n\t\t\tdkLen: outputLength,\n\t\t\tkey\n\t\t});\n\t}\n\n\t/**\n\t * Perform Sum 160 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 160 of the block.\n\t */\n\tpublic static sum160(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_160, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_256, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_512, key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Blake2b {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The
|
|
1
|
+
{"version":3,"file":"blake2b.js","sourceRoot":"","sources":["../../../src/hashes/blake2b.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAU,UAAU,aAA6B;IAE9D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;;OAIG;IACH,YAAY,YAAoB,EAAE,GAAgB;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;YAC/B,KAAK,EAAE,YAAY;YACnB,GAAG;SACH,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC5D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { blake2b } from \"@noble/hashes/blake2.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with Blake2B Signature scheme.\n */\nexport class Blake2b {\n\t/**\n\t * Blake2b 160.\n\t */\n\tpublic static SIZE_160: number = 20;\n\n\t/**\n\t * Blake2b 256.\n\t */\n\tpublic static SIZE_256: number = 32;\n\n\t/**\n\t * Blake2b 512.\n\t */\n\tpublic static SIZE_512: number = 64;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Blake2b>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Blake2b.\n\t * @param outputLength The output length.\n\t * @param key Optional key for the hash.\n\t */\n\tconstructor(outputLength: number, key?: Uint8Array) {\n\t\tthis._instance = blake2b.create({\n\t\t\tdkLen: outputLength,\n\t\t\tkey\n\t\t});\n\t}\n\n\t/**\n\t * Perform Sum 160 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 160 of the block.\n\t */\n\tpublic static sum160(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_160, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_256, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake2b(Blake2b.SIZE_512, key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Blake2b {\n\t\tGuards.uint8Array(Blake2b.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
package/dist/es/hashes/blake3.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blake3.js","sourceRoot":"","sources":["../../../src/hashes/blake3.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;;OAIG;IACH,YAAY,YAAoB,EAAE,GAAgB;QACjD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;YAC9B,KAAK,EAAE,YAAY;YACnB,GAAG;SACH,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { blake3 } from \"@noble/hashes/blake3.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with Blake3 Signature scheme.\n */\nexport class Blake3 {\n\t/**\n\t * Blake3 256.\n\t */\n\tpublic static SIZE_256: number = 32;\n\n\t/**\n\t * Blake3 512.\n\t */\n\tpublic static SIZE_512: number = 64;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Blake3>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Blake3.\n\t * @param outputLength The output length.\n\t * @param key Optional key for the hash.\n\t */\n\tconstructor(outputLength: number, key?: Uint8Array) {\n\t\tthis._instance = blake3.create({\n\t\t\tdkLen: outputLength,\n\t\t\tkey\n\t\t});\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake3(Blake3.SIZE_256, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake3(Blake3.SIZE_512, key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Blake3 {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The
|
|
1
|
+
{"version":3,"file":"blake3.js","sourceRoot":"","sources":["../../../src/hashes/blake3.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,EAAE,CAAC;IAEpC;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;;OAIG;IACH,YAAY,YAAoB,EAAE,GAAgB;QACjD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;YAC9B,KAAK,EAAE,YAAY;YACnB,GAAG;SACH,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAiB,EAAE,GAAgB;QACvD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { blake3 } from \"@noble/hashes/blake3.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with Blake3 Signature scheme.\n */\nexport class Blake3 {\n\t/**\n\t * Blake3 256.\n\t */\n\tpublic static SIZE_256: number = 32;\n\n\t/**\n\t * Blake3 512.\n\t */\n\tpublic static SIZE_512: number = 64;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Blake3>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Blake3.\n\t * @param outputLength The output length.\n\t * @param key Optional key for the hash.\n\t */\n\tconstructor(outputLength: number, key?: Uint8Array) {\n\t\tthis._instance = blake3.create({\n\t\t\tdkLen: outputLength,\n\t\t\tkey\n\t\t});\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake3(Blake3.SIZE_256, key).update(block).digest();\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @param key Optional key for the hash.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array, key?: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\treturn new Blake3(Blake3.SIZE_512, key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Blake3 {\n\t\tGuards.uint8Array(Blake3.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmacSha1.js","sourceRoot":"","sources":["../../../src/hashes/hmacSha1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;OAGG;IACH,YAAY,GAAe;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,GAAG,CAAC,GAAe,EAAE,KAAiB;QACnD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QACzD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC7D,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC7D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with HmacSha1 scheme.\n */\nexport class HmacSha1 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HmacSha1>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of HmacSha1.\n\t * @param key The key for the hmac.\n\t */\n\tconstructor(key: Uint8Array) {\n\t\tthis._instance = hmac.create(sha1, key);\n\t}\n\n\t/**\n\t * Perform Sum on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum of the block.\n\t */\n\tpublic static sum(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(block), block);\n\t\treturn new HmacSha1(key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): HmacSha1 {\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The
|
|
1
|
+
{"version":3,"file":"hmacSha1.js","sourceRoot":"","sources":["../../../src/hashes/hmacSha1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;OAGG;IACH,YAAY,GAAe;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,GAAG,CAAC,GAAe,EAAE,KAAiB;QACnD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QACzD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC7D,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC7D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with HmacSha1 scheme.\n */\nexport class HmacSha1 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HmacSha1>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of HmacSha1.\n\t * @param key The key for the hmac.\n\t */\n\tconstructor(key: Uint8Array) {\n\t\tthis._instance = hmac.create(sha1, key);\n\t}\n\n\t/**\n\t * Perform Sum on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum of the block.\n\t */\n\tpublic static sum(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(block), block);\n\t\treturn new HmacSha1(key).update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): HmacSha1 {\n\t\tGuards.uint8Array(HmacSha1.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
|
@@ -29,6 +29,7 @@ export class HmacSha256 {
|
|
|
29
29
|
* Create a new instance of HmacSha256.
|
|
30
30
|
* @param key The key for the hmac.
|
|
31
31
|
* @param bits The number of bits.
|
|
32
|
+
* @throws GeneralError If the bits are not a valid size.
|
|
32
33
|
*/
|
|
33
34
|
constructor(key, bits = HmacSha256.SIZE_256) {
|
|
34
35
|
if (bits !== HmacSha256.SIZE_224 && bits !== HmacSha256.SIZE_256) {
|
|
@@ -74,7 +75,7 @@ export class HmacSha256 {
|
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Get the digest for the hash.
|
|
77
|
-
* @returns The
|
|
78
|
+
* @returns The computed hash as bytes.
|
|
78
79
|
*/
|
|
79
80
|
digest() {
|
|
80
81
|
return this._instance.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmacSha256.js","sourceRoot":"","sources":["../../../src/hashes/hmacSha256.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,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CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha224, sha256 } from \"@noble/hashes/sha2.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with HmacSha256 scheme.\n */\nexport class HmacSha256 {\n\t/**\n\t * Sha256 256.\n\t */\n\tpublic static readonly SIZE_256: number = 256;\n\n\t/**\n\t * Sha256 224.\n\t */\n\tpublic static readonly SIZE_224: number = 224;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HmacSha256>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of HmacSha256.\n\t * @param key The key for the hmac.\n\t * @param bits The number of bits.\n\t * @throws GeneralError If the bits are not a valid size.\n\t */\n\tconstructor(key: Uint8Array, bits: number = HmacSha256.SIZE_256) {\n\t\tif (bits !== HmacSha256.SIZE_224 && bits !== HmacSha256.SIZE_256) {\n\t\t\tthrow new GeneralError(HmacSha256.CLASS_NAME, \"bitSize\", { bitSize: bits });\n\t\t}\n\n\t\tthis._instance = hmac.create(bits === HmacSha256.SIZE_256 ? sha256 : sha224, key);\n\t}\n\n\t/**\n\t * Perform Sum 224 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 224 of the block.\n\t */\n\tpublic static sum224(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha256.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha256.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha256(key, HmacSha256.SIZE_224);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha256.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha256.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha256(key, HmacSha256.SIZE_256);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): HmacSha256 {\n\t\tGuards.uint8Array(HmacSha256.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
|
@@ -38,6 +38,7 @@ export class HmacSha512 {
|
|
|
38
38
|
* Create a new instance of HmacSha512.
|
|
39
39
|
* @param key The key for the hmac.
|
|
40
40
|
* @param bits The number of bits.
|
|
41
|
+
* @throws GeneralError If the bits are not a valid size.
|
|
41
42
|
*/
|
|
42
43
|
constructor(key, bits = HmacSha512.SIZE_512) {
|
|
43
44
|
if (bits !== HmacSha512.SIZE_224 &&
|
|
@@ -123,7 +124,7 @@ export class HmacSha512 {
|
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
126
|
* Get the digest for the hash.
|
|
126
|
-
* @returns The
|
|
127
|
+
* @returns The computed hash as bytes.
|
|
127
128
|
*/
|
|
128
129
|
digest() {
|
|
129
130
|
return this._instance.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmacSha512.js","sourceRoot":"","sources":["../../../src/hashes/hmacSha512.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,8BAA8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AC;QAC1D,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable camelcase */\n\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha384, sha512, sha512_224, sha512_256 } from \"@noble/hashes/sha2.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to help with HmacSha512 scheme.\n */\nexport class HmacSha512 {\n\t/**\n\t * Sha512 224.\n\t */\n\tpublic static SIZE_224: number = 224;\n\n\t/**\n\t * Sha512 256.\n\t */\n\tpublic static SIZE_256: number = 256;\n\n\t/**\n\t * Sha512 384.\n\t */\n\tpublic static SIZE_384: number = 384;\n\n\t/**\n\t * Sha512 512.\n\t */\n\tpublic static SIZE_512: number = 512;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HmacSha512>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of HmacSha512.\n\t * @param key The key for the hmac.\n\t * @param bits The number of bits.\n\t * @throws GeneralError If the bits are not a valid size.\n\t */\n\tconstructor(key: Uint8Array, bits: number = HmacSha512.SIZE_512) {\n\t\tif (\n\t\t\tbits !== HmacSha512.SIZE_224 &&\n\t\t\tbits !== HmacSha512.SIZE_256 &&\n\t\t\tbits !== HmacSha512.SIZE_384 &&\n\t\t\tbits !== HmacSha512.SIZE_512\n\t\t) {\n\t\t\tthrow new GeneralError(HmacSha512.CLASS_NAME, \"bitSize\", { bitSize: bits });\n\t\t}\n\n\t\tif (bits === HmacSha512.SIZE_224) {\n\t\t\tthis._instance = hmac.create(sha512_224, key);\n\t\t} else if (bits === HmacSha512.SIZE_256) {\n\t\t\tthis._instance = hmac.create(sha512_256, key);\n\t\t} else if (bits === HmacSha512.SIZE_384) {\n\t\t\tthis._instance = hmac.create(sha384, key);\n\t\t} else {\n\t\t\tthis._instance = hmac.create(sha512, key);\n\t\t}\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha512(key, HmacSha512.SIZE_512);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Perform Sum 384 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 384 of the block.\n\t */\n\tpublic static sum384(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha512(key, HmacSha512.SIZE_384);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha512(key, HmacSha512.SIZE_256);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Perform Sum 224 on the block.\n\t * @param key The key for the hmac.\n\t * @param block The block to operate on.\n\t * @returns The sum 224 of the block.\n\t */\n\tpublic static sum224(key: Uint8Array, block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(key), key);\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(block), block);\n\t\tconst instance = new HmacSha512(key, HmacSha512.SIZE_224);\n\t\tinstance.update(block);\n\t\treturn instance.digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): HmacSha512 {\n\t\tGuards.uint8Array(HmacSha512.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
package/dist/es/hashes/sha1.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../src/hashes/sha1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,IAAI;IAChB;;OAEG;IACI,MAAM,CAAU,UAAU,UAA0B;IAE3D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;OAEG;IACH;QACC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,GAAG,CAAC,KAAiB;QAClC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Perform a SHA-1 hash on the block.\n */\nexport class Sha1 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Sha1>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Sha1.\n\t */\n\tconstructor() {\n\t\tthis._instance = sha1.create();\n\t}\n\n\t/**\n\t * Perform Sum on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum of the block.\n\t */\n\tpublic static sum(block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Sha1.CLASS_NAME, nameof(block), block);\n\t\treturn new Sha1().update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Sha1 {\n\t\tGuards.uint8Array(Sha1.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The
|
|
1
|
+
{"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../src/hashes/sha1.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,IAAI;IAChB;;OAEG;IACI,MAAM,CAAU,UAAU,UAA0B;IAE3D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;OAEG;IACH;QACC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,GAAG,CAAC,KAAiB;QAClC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Perform a SHA-1 hash on the block.\n */\nexport class Sha1 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Sha1>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Sha1.\n\t */\n\tconstructor() {\n\t\tthis._instance = sha1.create();\n\t}\n\n\t/**\n\t * Perform Sum on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum of the block.\n\t */\n\tpublic static sum(block: Uint8Array): Uint8Array {\n\t\tGuards.uint8Array(Sha1.CLASS_NAME, nameof(block), block);\n\t\treturn new Sha1().update(block).digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Sha1 {\n\t\tGuards.uint8Array(Sha1.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
package/dist/es/hashes/sha256.js
CHANGED
|
@@ -27,6 +27,7 @@ export class Sha256 {
|
|
|
27
27
|
/**
|
|
28
28
|
* Create a new instance of Sha256.
|
|
29
29
|
* @param bits The number of bits.
|
|
30
|
+
* @throws GeneralError If the bits are not a valid size.
|
|
30
31
|
*/
|
|
31
32
|
constructor(bits = Sha256.SIZE_256) {
|
|
32
33
|
if (bits !== Sha256.SIZE_224 && bits !== Sha256.SIZE_256) {
|
|
@@ -66,7 +67,7 @@ export class Sha256 {
|
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Get the digest for the hash.
|
|
69
|
-
* @returns The
|
|
70
|
+
* @returns The computed hash as bytes.
|
|
70
71
|
*/
|
|
71
72
|
digest() {
|
|
72
73
|
return this._instance.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha256.js","sourceRoot":"","sources":["../../../src/hashes/sha256.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC
|
|
1
|
+
{"version":3,"file":"sha256.js","sourceRoot":"","sources":["../../../src/hashes/sha256.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,UAAU,YAA4B;IAE7D;;;OAGG;IACH,8DAA8D;IAC7C,SAAS,CAAY;IAEtC;;;;OAIG;IACH,YAAY,OAAe,MAAM,CAAC,QAAQ;QACzC,IA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} from \"@noble/hashes/utils.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Perform a SHA-256 hash on the block.\n */\nexport class Sha256 {\n\t/**\n\t * Sha256 256.\n\t */\n\tpublic static readonly SIZE_256: number = 256;\n\n\t/**\n\t * Sha256 224.\n\t */\n\tpublic static readonly SIZE_224: number = 224;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Sha256>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Sha256.\n\t * @param bits The number of bits.\n\t * @throws GeneralError If the bits are not a valid size.\n\t */\n\tconstructor(bits: number = Sha256.SIZE_256) {\n\t\tif (bits !== Sha256.SIZE_224 && bits !== Sha256.SIZE_256) {\n\t\t\tthrow new GeneralError(Sha256.CLASS_NAME, \"bitSize\", { bitSize: bits });\n\t\t}\n\n\t\tthis._instance = bits === Sha256.SIZE_256 ? sha256.create() : sha224.create();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha256(Sha256.SIZE_256);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 224 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 224 of the block.\n\t */\n\tpublic static sum224(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha256(Sha256.SIZE_224);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Sha256 {\n\t\tGuards.uint8Array(Sha256.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
package/dist/es/hashes/sha3.js
CHANGED
|
@@ -36,6 +36,7 @@ export class Sha3 {
|
|
|
36
36
|
/**
|
|
37
37
|
* Create a new instance of Sha3.
|
|
38
38
|
* @param bits The number of bits.
|
|
39
|
+
* @throws GeneralError If the bits are not a valid size.
|
|
39
40
|
*/
|
|
40
41
|
constructor(bits = Sha3.SIZE_256) {
|
|
41
42
|
if (bits !== Sha3.SIZE_224 &&
|
|
@@ -113,7 +114,7 @@ export class Sha3 {
|
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Get the digest for the hash.
|
|
116
|
-
* @returns The
|
|
117
|
+
* @returns The computed hash as bytes.
|
|
117
118
|
*/
|
|
118
119
|
digest() {
|
|
119
120
|
return this._instance.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha3.js","sourceRoot":"","sources":["../../../src/hashes/sha3.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,qCAAqC;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,IAAI;IAChB;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,QAAQ,GAAW,GAAG,CAAC;IAE9C;;OAEG;IACI,MAAM,CAAU,UAAU,UAA0B;IAE3D;;;O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;;;;OAIG;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n// eslint-disable-next-line camelcase\nimport { sha3_224, sha3_256, sha3_384, sha3_512 } from \"@noble/hashes/sha3.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Perform a SHA-3 hash on the block.\n */\nexport class Sha3 {\n\t/**\n\t * Sha3 224.\n\t */\n\tpublic static readonly SIZE_224: number = 224;\n\n\t/**\n\t * Sha3 256.\n\t */\n\tpublic static readonly SIZE_256: number = 256;\n\n\t/**\n\t * Sha3 384.\n\t */\n\tpublic static readonly SIZE_384: number = 384;\n\n\t/**\n\t * Sha3 512.\n\t */\n\tpublic static readonly SIZE_512: number = 512;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Sha3>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Sha3.\n\t * @param bits The number of bits.\n\t * @throws GeneralError If the bits are not a valid size.\n\t */\n\tconstructor(bits: number = Sha3.SIZE_256) {\n\t\tif (\n\t\t\tbits !== Sha3.SIZE_224 &&\n\t\t\tbits !== Sha3.SIZE_256 &&\n\t\t\tbits !== Sha3.SIZE_384 &&\n\t\t\tbits !== Sha3.SIZE_512\n\t\t) {\n\t\t\tthrow new GeneralError(Sha3.CLASS_NAME, \"bitSize\", { bitSize: bits });\n\t\t}\n\n\t\tif (bits === Sha3.SIZE_224) {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tthis._instance = sha3_224.create();\n\t\t} else if (bits === Sha3.SIZE_256) {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tthis._instance = sha3_256.create();\n\t\t} else if (bits === Sha3.SIZE_384) {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tthis._instance = sha3_384.create();\n\t\t} else {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tthis._instance = sha3_512.create();\n\t\t}\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha3(Sha3.SIZE_256);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 224 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 224 of the block.\n\t */\n\tpublic static sum224(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha3(Sha3.SIZE_224);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 384 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 384 of the block.\n\t */\n\tpublic static sum384(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha3(Sha3.SIZE_384);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha3(Sha3.SIZE_512);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Sha3 {\n\t\tGuards.uint8Array(Sha3.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
package/dist/es/hashes/sha512.js
CHANGED
|
@@ -36,6 +36,7 @@ export class Sha512 {
|
|
|
36
36
|
/**
|
|
37
37
|
* Create a new instance of Sha512.
|
|
38
38
|
* @param bits The number of bits.
|
|
39
|
+
* @throws GeneralError If the bits are not a valid size.
|
|
39
40
|
*/
|
|
40
41
|
constructor(bits = Sha512.SIZE_512) {
|
|
41
42
|
if (bits !== Sha512.SIZE_224 &&
|
|
@@ -109,7 +110,7 @@ export class Sha512 {
|
|
|
109
110
|
}
|
|
110
111
|
/**
|
|
111
112
|
* Get the digest for the hash.
|
|
112
|
-
* @returns The
|
|
113
|
+
* @returns The computed hash as bytes.
|
|
113
114
|
*/
|
|
114
115
|
digest() {
|
|
115
116
|
return this._instance.digest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha512.js","sourceRoot":"","sources":["../../../src/hashes/sha512.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,8BAA8B;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;GAEG;AACH,MAAM,OAAO,MAAM;IAClB;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,GAAG,CAAC;IAErC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,GAAG,CAAC;IAErC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,GAAG,CAAC;IAErC;;OAEG;IACI,MAAM,CAAC,QAAQ,GAAW,GAA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G;IACI,MAAM,CAAC,KAAiB;QAC9B,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/* eslint-disable camelcase */\nimport { sha384, sha512, sha512_224, sha512_256 } from \"@noble/hashes/sha2.js\";\nimport type { Hash } from \"@noble/hashes/utils.js\";\nimport { GeneralError, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Perform a SHA-512 hash on the block.\n */\nexport class Sha512 {\n\t/**\n\t * Sha512 224.\n\t */\n\tpublic static SIZE_224: number = 224;\n\n\t/**\n\t * Sha512 256.\n\t */\n\tpublic static SIZE_256: number = 256;\n\n\t/**\n\t * Sha512 384.\n\t */\n\tpublic static SIZE_384: number = 384;\n\n\t/**\n\t * Sha512 512.\n\t */\n\tpublic static SIZE_512: number = 512;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Sha512>();\n\n\t/**\n\t * The instance of the hash.\n\t * @internal\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate readonly _instance: Hash<any>;\n\n\t/**\n\t * Create a new instance of Sha512.\n\t * @param bits The number of bits.\n\t * @throws GeneralError If the bits are not a valid size.\n\t */\n\tconstructor(bits: number = Sha512.SIZE_512) {\n\t\tif (\n\t\t\tbits !== Sha512.SIZE_224 &&\n\t\t\tbits !== Sha512.SIZE_256 &&\n\t\t\tbits !== Sha512.SIZE_384 &&\n\t\t\tbits !== Sha512.SIZE_512\n\t\t) {\n\t\t\tthrow new GeneralError(Sha512.CLASS_NAME, \"bitSize\", { bitSize: bits });\n\t\t}\n\n\t\tif (bits === Sha512.SIZE_224) {\n\t\t\tthis._instance = sha512_224.create();\n\t\t} else if (bits === Sha512.SIZE_256) {\n\t\t\tthis._instance = sha512_256.create();\n\t\t} else if (bits === Sha512.SIZE_384) {\n\t\t\tthis._instance = sha384.create();\n\t\t} else {\n\t\t\tthis._instance = sha512.create();\n\t\t}\n\t}\n\n\t/**\n\t * Perform Sum 512 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 512 of the block.\n\t */\n\tpublic static sum512(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha512(Sha512.SIZE_512);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 384 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 384 of the block.\n\t */\n\tpublic static sum384(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha512(Sha512.SIZE_384);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 256 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 256 of the block.\n\t */\n\tpublic static sum256(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha512(Sha512.SIZE_256);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Perform Sum 224 on the block.\n\t * @param block The block to operate on.\n\t * @returns The sum 224 of the block.\n\t */\n\tpublic static sum224(block: Uint8Array): Uint8Array {\n\t\tconst b2b = new Sha512(Sha512.SIZE_224);\n\t\tb2b.update(block);\n\t\treturn b2b.digest();\n\t}\n\n\t/**\n\t * Update the hash with the block.\n\t * @param block The block to update the hash with.\n\t * @returns The instance for chaining.\n\t */\n\tpublic update(block: Uint8Array): Sha512 {\n\t\tGuards.uint8Array(Sha512.CLASS_NAME, nameof(block), block);\n\t\tthis._instance.update(block);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the digest for the hash.\n\t * @returns The computed hash as bytes.\n\t */\n\tpublic digest(): Uint8Array {\n\t\treturn this._instance.digest();\n\t}\n}\n"]}
|
|
@@ -47,7 +47,7 @@ export class IntegrityHelper {
|
|
|
47
47
|
* Generate a hash for the given content using the specified type.
|
|
48
48
|
* @param type The hash algorithm to use, either "sha256", "sha384" or "sha512".
|
|
49
49
|
* @param content The content to hash as a Uint8Array.
|
|
50
|
-
* @returns The
|
|
50
|
+
* @returns The base64-encoded hash of the content.
|
|
51
51
|
* @internal
|
|
52
52
|
*/
|
|
53
53
|
static generateHash(type, content) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrityHelper.js","sourceRoot":"","sources":["../../../src/helpers/integrityHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,CAAC,IAAwB,EAAE,OAAmB;QACnE,MAAM,CAAC,UAAU,CAChB,eAAe,CAAC,UAAU,UAE1B,IAAI,EACJ,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CACjC,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAExE,OAAO,GAAG,IAAI,IAAI,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IACjE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,SAAiB,EAAE,OAAmB;QAC1D,MAAM,C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} from \"@twin.org/nameof\";\nimport { Sha256 } from \"../hashes/sha256.js\";\nimport { Sha512 } from \"../hashes/sha512.js\";\nimport { IntegrityAlgorithm } from \"../models/integrityAlgorithm.js\";\n\n/**\n * Helper class for creating integrity signatures.\n * @see https://www.w3.org/TR/SRI/\n */\nexport class IntegrityHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IntegrityHelper>();\n\n\t/**\n\t * Generate an integrity signature for the given content using the specified hash algorithm.\n\t * @param type The hash algorithm to use, either \"sha256\", \"sha384\" or \"sha512\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns The integrity signature in the format \"type-base64hash\".\n\t */\n\tpublic static generate(type: IntegrityAlgorithm, content: Uint8Array): string {\n\t\tGuards.arrayOneOf(\n\t\t\tIntegrityHelper.CLASS_NAME,\n\t\t\tnameof(type),\n\t\t\ttype,\n\t\t\tObject.values(IntegrityAlgorithm)\n\t\t);\n\t\tGuards.uint8Array(IntegrityHelper.CLASS_NAME, nameof(content), content);\n\n\t\treturn `${type}-${IntegrityHelper.generateHash(type, content)}`;\n\t}\n\n\t/**\n\t * Verify an integrity signature for the given content.\n\t * @param integrity The integrity signature in the format \"type-base64hash\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns True if the integrity signature matches the content.\n\t * @throws If the integrity signature is invalid.\n\t */\n\tpublic static verify(integrity: string, content: Uint8Array): boolean {\n\t\tGuards.stringValue(IntegrityHelper.CLASS_NAME, nameof(integrity), integrity);\n\t\tGuards.uint8Array(IntegrityHelper.CLASS_NAME, nameof(content), content);\n\n\t\tconst parts = integrity.split(\"-\");\n\t\tif (parts.length !== 2) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [type, hash] = parts;\n\n\t\tGuards.arrayOneOf(\n\t\t\tIntegrityHelper.CLASS_NAME,\n\t\t\tnameof(type),\n\t\t\ttype,\n\t\t\tObject.values(IntegrityAlgorithm)\n\t\t);\n\t\tGuards.stringValue(IntegrityHelper.CLASS_NAME, nameof(hash), hash);\n\n\t\treturn IntegrityHelper.generateHash(type as IntegrityAlgorithm, content) === hash;\n\t}\n\n\t/**\n\t * Generate a hash for the given content using the specified type.\n\t * @param type The hash algorithm to use, either \"sha256\", \"sha384\" or \"sha512\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns The
|
|
1
|
+
{"version":3,"file":"integrityHelper.js","sourceRoot":"","sources":["../../../src/helpers/integrityHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,CAAC,IAAwB,EAAE,OAAmB;QACnE,MAAM,CAAC,UAAU,CAChB,eAAe,CAAC,UAAU,UAE1B,IAAI,EACJ,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CACjC,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAExE,OAAO,GAAG,IAAI,IAAI,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IACjE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,SAAiB,EAAE,OAAmB;QAC1D,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,eAAqB,SAAS,CAAC,CAAC;QAC7E,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAExE,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACd,CAAC;QAED,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;QAE3B,MAAM,CAAC,UAAU,CAChB,eAAe,CAAC,UAAU,UAE1B,IAAI,EACJ,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CACjC,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAEnE,OAAO,eAAe,CAAC,YAAY,CAAC,IAA0B,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACnF,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,YAAY,CAAC,IAAwB,EAAE,OAAmB;QACxE,IAAI,IAAI,CAAC;QACT,IAAI,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACxC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;aAAM,IAAI,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAC/C,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { Sha256 } from \"../hashes/sha256.js\";\nimport { Sha512 } from \"../hashes/sha512.js\";\nimport { IntegrityAlgorithm } from \"../models/integrityAlgorithm.js\";\n\n/**\n * Helper class for creating integrity signatures.\n * @see https://www.w3.org/TR/SRI/\n */\nexport class IntegrityHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IntegrityHelper>();\n\n\t/**\n\t * Generate an integrity signature for the given content using the specified hash algorithm.\n\t * @param type The hash algorithm to use, either \"sha256\", \"sha384\" or \"sha512\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns The integrity signature in the format \"type-base64hash\".\n\t */\n\tpublic static generate(type: IntegrityAlgorithm, content: Uint8Array): string {\n\t\tGuards.arrayOneOf(\n\t\t\tIntegrityHelper.CLASS_NAME,\n\t\t\tnameof(type),\n\t\t\ttype,\n\t\t\tObject.values(IntegrityAlgorithm)\n\t\t);\n\t\tGuards.uint8Array(IntegrityHelper.CLASS_NAME, nameof(content), content);\n\n\t\treturn `${type}-${IntegrityHelper.generateHash(type, content)}`;\n\t}\n\n\t/**\n\t * Verify an integrity signature for the given content.\n\t * @param integrity The integrity signature in the format \"type-base64hash\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns True if the integrity signature matches the content.\n\t * @throws If the integrity signature is invalid.\n\t */\n\tpublic static verify(integrity: string, content: Uint8Array): boolean {\n\t\tGuards.stringValue(IntegrityHelper.CLASS_NAME, nameof(integrity), integrity);\n\t\tGuards.uint8Array(IntegrityHelper.CLASS_NAME, nameof(content), content);\n\n\t\tconst parts = integrity.split(\"-\");\n\t\tif (parts.length !== 2) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [type, hash] = parts;\n\n\t\tGuards.arrayOneOf(\n\t\t\tIntegrityHelper.CLASS_NAME,\n\t\t\tnameof(type),\n\t\t\ttype,\n\t\t\tObject.values(IntegrityAlgorithm)\n\t\t);\n\t\tGuards.stringValue(IntegrityHelper.CLASS_NAME, nameof(hash), hash);\n\n\t\treturn IntegrityHelper.generateHash(type as IntegrityAlgorithm, content) === hash;\n\t}\n\n\t/**\n\t * Generate a hash for the given content using the specified type.\n\t * @param type The hash algorithm to use, either \"sha256\", \"sha384\" or \"sha512\".\n\t * @param content The content to hash as a Uint8Array.\n\t * @returns The base64-encoded hash of the content.\n\t * @internal\n\t */\n\tprivate static generateHash(type: IntegrityAlgorithm, content: Uint8Array): string {\n\t\tlet hash;\n\t\tif (type === IntegrityAlgorithm.Sha384) {\n\t\t\thash = Sha512.sum384(content);\n\t\t} else if (type === IntegrityAlgorithm.Sha512) {\n\t\t\thash = Sha512.sum512(content);\n\t\t} else {\n\t\t\thash = Sha256.sum256(content);\n\t\t}\n\t\treturn Converter.bytesToBase64(hash);\n\t}\n}\n"]}
|
package/dist/es/keys/slip0010.js
CHANGED
|
@@ -64,7 +64,7 @@ export class Slip0010 {
|
|
|
64
64
|
* Get the public key from the private key.
|
|
65
65
|
* @param privateKey The private key.
|
|
66
66
|
* @param keyType The key type.
|
|
67
|
-
* @param withZeroByte Include a zero
|
|
67
|
+
* @param withZeroByte Include a zero byte prefix.
|
|
68
68
|
* @returns The public key.
|
|
69
69
|
*/
|
|
70
70
|
static getPublicKey(privateKey, keyType = KeyType.Ed25519, withZeroByte = true) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slip0010.js","sourceRoot":"","sources":["../../../src/keys/slip0010.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;;;;OAMG;IACI,M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,CAAC,CAAC;QACjD,OAAO;YACN,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,IAAI,UAAU,EAAE;YACrD,SAAS,EAAE,UAAU,CAAC,SAAS,IAAI,IAAI,UAAU,EAAE;SACnD,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,YAAY,CACzB,UAAsB,EACtB,UAAmB,OAAO,CAAC,OAAO,EAClC,eAAwB,IAAI;QAE5B,MAAM,MAAM,GACX,OAAO,KAAK,OAAO,CAAC,OAAO;YAC1B,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC;YAC7C,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9C,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACX,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACnB,OAAO,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HDKey as HDKeySecp256k1 } from \"@scure/bip32\";\nimport { Converter, GeneralError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HDKey as HDKeyEd25519 } from \"micro-key-producer/slip10.js\";\nimport type { Bip32Path } from \"./bip32Path.js\";\nimport { Ed25519 } from \"../curves/ed25519.js\";\nimport { Secp256k1 } from \"../curves/secp256k1.js\";\nimport { KeyType } from \"../models/keyType.js\";\n\n/**\n * Class to help with slip0010 key derivation\n * https://github.com/satoshilabs/slips/blob/master/slip-0010.md.\n */\nexport class Slip0010 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Slip0010>();\n\n\t/**\n\t * Get the master key from the seed.\n\t * @param seed The seed to generate the master key from.\n\t * @param keyType The key type.\n\t * @returns The key and chain code.\n\t * @throws If the seed is invalid.\n\t */\n\tpublic static getMasterKeyFromSeed(\n\t\tseed: Uint8Array,\n\t\tkeyType: KeyType = KeyType.Ed25519\n\t): {\n\t\tprivateKey: Uint8Array;\n\t\tchainCode: Uint8Array;\n\t} {\n\t\ttry {\n\t\t\tconst masterKey =\n\t\t\t\tkeyType === KeyType.Ed25519\n\t\t\t\t\t? HDKeyEd25519.fromMasterSeed(seed)\n\t\t\t\t\t: HDKeySecp256k1.fromMasterSeed(seed);\n\n\t\t\treturn {\n\t\t\t\tprivateKey: masterKey.privateKey ?? new Uint8Array(),\n\t\t\t\tchainCode: masterKey.chainCode ?? new Uint8Array()\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tSlip0010.CLASS_NAME,\n\t\t\t\t\"invalidSeed\",\n\t\t\t\t{ seed: Converter.bytesToUtf8(seed) },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Derive a key from the path.\n\t * @param seed The seed.\n\t * @param path The path.\n\t * @param keyType The key type.\n\t * @returns The key and chain code.\n\t */\n\tpublic static derivePath(\n\t\tseed: Uint8Array,\n\t\tpath: Bip32Path,\n\t\tkeyType: KeyType = KeyType.Ed25519\n\t): {\n\t\tprivateKey: Uint8Array;\n\t\tchainCode: Uint8Array;\n\t} {\n\t\tconst keyOpts = Slip0010.getMasterKeyFromSeed(seed, keyType);\n\n\t\tif (keyType === KeyType.Ed25519) {\n\t\t\tconst hdKey = new HDKeyEd25519(keyOpts);\n\t\t\tconst derivedKey = hdKey.derive(path.toString());\n\t\t\treturn {\n\t\t\t\tprivateKey: derivedKey.privateKey,\n\t\t\t\tchainCode: derivedKey.chainCode\n\t\t\t};\n\t\t}\n\t\tconst hdKey = new HDKeySecp256k1(keyOpts);\n\t\tconst derivedKey = hdKey.derive(path.toString());\n\t\treturn {\n\t\t\tprivateKey: derivedKey.privateKey ?? new Uint8Array(),\n\t\t\tchainCode: derivedKey.chainCode ?? new Uint8Array()\n\t\t};\n\t}\n\n\t/**\n\t * Get the public key from the private key.\n\t * @param privateKey The private key.\n\t * @param keyType The key type.\n\t * @param withZeroByte Include a zero
|
|
1
|
+
{"version":3,"file":"slip0010.js","sourceRoot":"","sources":["../../../src/keys/slip0010.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;;;;OAMG;IACI,MAAM,CAAC,oBAAoB,CACjC,IAAgB,EAChB,UAAmB,OAAO,CAAC,OAAO;QAKlC,IAAI,CAAC;YACJ,MAAM,SAAS,GACd,OAAO,KAAK,OAAO,CAAC,OAAO;gBAC1B,CAAC,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;gBACnC,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAExC,OAAO;gBACN,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,IAAI,UAAU,EAAE;gBACpD,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,IAAI,UAAU,EAAE;aAClD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CACrB,QAAQ,CAAC,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AAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9C,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACX,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACnB,OAAO,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { HDKey as HDKeySecp256k1 } from \"@scure/bip32\";\nimport { Converter, GeneralError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HDKey as HDKeyEd25519 } from \"micro-key-producer/slip10.js\";\nimport type { Bip32Path } from \"./bip32Path.js\";\nimport { Ed25519 } from \"../curves/ed25519.js\";\nimport { Secp256k1 } from \"../curves/secp256k1.js\";\nimport { KeyType } from \"../models/keyType.js\";\n\n/**\n * Class to help with slip0010 key derivation\n * https://github.com/satoshilabs/slips/blob/master/slip-0010.md.\n */\nexport class Slip0010 {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Slip0010>();\n\n\t/**\n\t * Get the master key from the seed.\n\t * @param seed The seed to generate the master key from.\n\t * @param keyType The key type.\n\t * @returns The key and chain code.\n\t * @throws If the seed is invalid.\n\t */\n\tpublic static getMasterKeyFromSeed(\n\t\tseed: Uint8Array,\n\t\tkeyType: KeyType = KeyType.Ed25519\n\t): {\n\t\tprivateKey: Uint8Array;\n\t\tchainCode: Uint8Array;\n\t} {\n\t\ttry {\n\t\t\tconst masterKey =\n\t\t\t\tkeyType === KeyType.Ed25519\n\t\t\t\t\t? HDKeyEd25519.fromMasterSeed(seed)\n\t\t\t\t\t: HDKeySecp256k1.fromMasterSeed(seed);\n\n\t\t\treturn {\n\t\t\t\tprivateKey: masterKey.privateKey ?? new Uint8Array(),\n\t\t\t\tchainCode: masterKey.chainCode ?? new Uint8Array()\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tSlip0010.CLASS_NAME,\n\t\t\t\t\"invalidSeed\",\n\t\t\t\t{ seed: Converter.bytesToUtf8(seed) },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Derive a key from the path.\n\t * @param seed The seed.\n\t * @param path The path.\n\t * @param keyType The key type.\n\t * @returns The key and chain code.\n\t */\n\tpublic static derivePath(\n\t\tseed: Uint8Array,\n\t\tpath: Bip32Path,\n\t\tkeyType: KeyType = KeyType.Ed25519\n\t): {\n\t\tprivateKey: Uint8Array;\n\t\tchainCode: Uint8Array;\n\t} {\n\t\tconst keyOpts = Slip0010.getMasterKeyFromSeed(seed, keyType);\n\n\t\tif (keyType === KeyType.Ed25519) {\n\t\t\tconst hdKey = new HDKeyEd25519(keyOpts);\n\t\t\tconst derivedKey = hdKey.derive(path.toString());\n\t\t\treturn {\n\t\t\t\tprivateKey: derivedKey.privateKey,\n\t\t\t\tchainCode: derivedKey.chainCode\n\t\t\t};\n\t\t}\n\t\tconst hdKey = new HDKeySecp256k1(keyOpts);\n\t\tconst derivedKey = hdKey.derive(path.toString());\n\t\treturn {\n\t\t\tprivateKey: derivedKey.privateKey ?? new Uint8Array(),\n\t\t\tchainCode: derivedKey.chainCode ?? new Uint8Array()\n\t\t};\n\t}\n\n\t/**\n\t * Get the public key from the private key.\n\t * @param privateKey The private key.\n\t * @param keyType The key type.\n\t * @param withZeroByte Include a zero byte prefix.\n\t * @returns The public key.\n\t */\n\tpublic static getPublicKey(\n\t\tprivateKey: Uint8Array,\n\t\tkeyType: KeyType = KeyType.Ed25519,\n\t\twithZeroByte: boolean = true\n\t): Uint8Array {\n\t\tconst signPk =\n\t\t\tkeyType === KeyType.Ed25519\n\t\t\t\t? Ed25519.publicKeyFromPrivateKey(privateKey)\n\t\t\t\t: Secp256k1.publicKeyFromPrivateKey(privateKey);\n\t\tif (withZeroByte) {\n\t\t\tconst arr = new Uint8Array(1 + signPk.length);\n\t\t\tarr[0] = 0;\n\t\t\tarr.set(signPk, 1);\n\t\t\treturn arr;\n\t\t}\n\t\treturn signPk;\n\t}\n}\n"]}
|
package/dist/es/otp/totp.js
CHANGED
|
@@ -25,7 +25,7 @@ export class Totp {
|
|
|
25
25
|
* @param window The allowable margin for the counter.
|
|
26
26
|
* @param interval The time step of the counter.
|
|
27
27
|
* @param timestamp The timestamp now.
|
|
28
|
-
* @returns
|
|
28
|
+
* @returns The counter delta on success, or undefined if no matching code is found within the window.
|
|
29
29
|
*/
|
|
30
30
|
static verify(token, key, window = 2, interval = 30, timestamp = Date.now()) {
|
|
31
31
|
for (let i = -window; i < window; i++) {
|