@metamask-previews/cryptography 0.0.0-preview-c92646a67 → 1.0.0-preview-cdde826
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/CHANGELOG.md +16 -8
- package/dist/aes-gcm.d.ts +39 -0
- package/dist/aes-gcm.d.ts.map +1 -0
- package/dist/aes-gcm.js +55 -0
- package/dist/aes-gcm.js.map +1 -0
- package/dist/ed25519.d.ts +9 -2
- package/dist/ed25519.d.ts.map +1 -1
- package/dist/ed25519.js +13 -0
- package/dist/ed25519.js.map +1 -1
- package/dist/hkdf.d.ts +3 -3
- package/dist/hkdf.d.ts.map +1 -1
- package/dist/hkdf.js.map +1 -1
- package/dist/hmac.d.ts +3 -3
- package/dist/hmac.d.ts.map +1 -1
- package/dist/hmac.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/pbkdf2.d.ts +3 -3
- package/dist/pbkdf2.d.ts.map +1 -1
- package/dist/pbkdf2.js.map +1 -1
- package/dist/random.d.ts +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js.map +1 -1
- package/dist/sha.d.ts +3 -3
- package/dist/sha.d.ts.map +1 -1
- package/dist/sha.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/x25519.d.ts +9 -2
- package/dist/x25519.d.ts.map +1 -1
- package/dist/x25519.js +13 -0
- package/dist/x25519.js.map +1 -1
- package/package.json +25 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,15 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Narrow return type for AES `encrypt` function to `Uint8Array<ArrayBuffer>` ([#10623](https://github.com/MetaMask/core/pull/10623))
|
|
13
|
+
|
|
14
|
+
## [1.0.0]
|
|
15
|
+
|
|
10
16
|
### Added
|
|
11
17
|
|
|
12
|
-
- Initial release ([#10282](https://github.com/MetaMask/core/pull/10282), [#10431](https://github.com/MetaMask/core/pull/10431), [#10403](https://github.com/MetaMask/core/pull/10403), [#10468](https://github.com/MetaMask/core/pull/10468), [#10503](https://github.com/MetaMask/core/pull/10503), [#10563](https://github.com/MetaMask/core/pull/10563), [#10506](https://github.com/MetaMask/core/pull/10506))
|
|
13
|
-
- Add `sha256`, `sha384`, and `sha512` functions for computing SHA digests
|
|
14
|
-
- Add `hmacSha256`, `hmacSha384`, and `hmacSha512` functions for computing HMAC digests
|
|
15
|
-
- Add `pbkdf2Sha256`, `pbkdf2Sha384`, and `pbkdf2Sha512` functions for key derivation
|
|
16
|
-
- Add `hkdfSha256`, `hkdfSha384`, and `hkdfSha512` functions for key derivation
|
|
17
|
-
- Add `getPublicKey` and `getSharedSecret` functions for X25519 key derivation exported via `@metamask/cryptography/x25519`
|
|
18
|
+
- Initial release ([#10282](https://github.com/MetaMask/core/pull/10282), [#10431](https://github.com/MetaMask/core/pull/10431), [#10403](https://github.com/MetaMask/core/pull/10403), [#10468](https://github.com/MetaMask/core/pull/10468), [#10503](https://github.com/MetaMask/core/pull/10503), [#10563](https://github.com/MetaMask/core/pull/10563), [#10506](https://github.com/MetaMask/core/pull/10506), [#10608](https://github.com/MetaMask/core/pull/10608), [#10571](https://github.com/MetaMask/core/pull/10571), [#10572](https://github.com/MetaMask/core/pull/10572), [#10573](https://github.com/MetaMask/core/pull/10573), [#10613](https://github.com/MetaMask/core/pull/10613))
|
|
19
|
+
- Add `sha256`, `sha384`, and `sha512` functions for computing SHA digests exported via `@metamask/cryptography/sha`
|
|
20
|
+
- Add `hmacSha256`, `hmacSha384`, and `hmacSha512` functions for computing HMAC digests exported via `@metamask/cryptography/hmac`
|
|
21
|
+
- Add `pbkdf2Sha256`, `pbkdf2Sha384`, and `pbkdf2Sha512` functions for key derivation exported via `@metamask/cryptography/pbkdf2`
|
|
22
|
+
- Add `hkdfSha256`, `hkdfSha384`, and `hkdfSha512` functions for key derivation exported via `@metamask/cryptography/hkdf`
|
|
23
|
+
- Add `generateKeyPair`, `getPublicKey` and `getSharedSecret` functions for X25519 key derivation exported via `@metamask/cryptography/x25519`
|
|
24
|
+
- Add `generateKeyPair`, `getPublicKey`, `sign`, and `verify` functions for Ed25519 exported via `@metamask/cryptography/ed25519`
|
|
25
|
+
- Add `encrypt` and `decrypt` functions for AES-GCM symmetric encryption exported via `@metamask/cryptography/aes-gcm`
|
|
18
26
|
- Add `getRandomBytes` function for generating cryptographically secure random bytes
|
|
19
|
-
- Add `getPublicKey`, `sign`, and `verify` functions for Ed25519 exported via `@metamask/cryptography/ed25519`
|
|
20
27
|
|
|
21
|
-
[Unreleased]: https://github.com/MetaMask/core/
|
|
28
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.0.0...HEAD
|
|
29
|
+
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/cryptography@1.0.0
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type AesGcmEncryptOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* The initialization vector. If not provided, a random 12-byte IV
|
|
4
|
+
* is generated automatically. It is recommended to use the generated one rather
|
|
5
|
+
* than providing one, to avoid IV reuse.
|
|
6
|
+
*/
|
|
7
|
+
unsafeIv?: BufferSource;
|
|
8
|
+
} & AesGcmDecryptOptions;
|
|
9
|
+
export type AesGcmDecryptOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Skip the IV length check. Using an IV other than 12 bytes deviates from
|
|
12
|
+
* the standard and is considered less safe.
|
|
13
|
+
*/
|
|
14
|
+
unsafeIvLength?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type AesGcmEncryptResult = {
|
|
17
|
+
ciphertext: Uint8Array<ArrayBuffer>;
|
|
18
|
+
iv: Uint8Array<ArrayBuffer>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Encrypt data using AES-GCM.
|
|
22
|
+
*
|
|
23
|
+
* @param key - The 16, 24, or 32-byte AES key.
|
|
24
|
+
* @param plaintext - The plaintext.
|
|
25
|
+
* @param options - Additional configuration options.
|
|
26
|
+
* @returns The ciphertext and the IV used for encryption.
|
|
27
|
+
*/
|
|
28
|
+
export declare function encrypt(key: BufferSource, plaintext: BufferSource, options?: AesGcmEncryptOptions): Promise<AesGcmEncryptResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Decrypt data using AES-GCM.
|
|
31
|
+
*
|
|
32
|
+
* @param key - The 16, 24, or 32-byte AES key.
|
|
33
|
+
* @param iv - The initialization vector.
|
|
34
|
+
* @param ciphertext - The ciphertext.
|
|
35
|
+
* @param options - Additional configuration options.
|
|
36
|
+
* @returns The decrypted plaintext.
|
|
37
|
+
*/
|
|
38
|
+
export declare function decrypt(key: BufferSource, iv: BufferSource, ciphertext: BufferSource, options?: AesGcmDecryptOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
39
|
+
//# sourceMappingURL=aes-gcm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,oBAAoB,CAAC;AAEzB,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,EAAE,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CAC7B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAuC9B;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAC3B,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,YAAY,EAChB,UAAU,EAAE,YAAY,EACxB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAmClC"}
|
package/dist/aes-gcm.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getRandomBytes } from './random.js';
|
|
2
|
+
import { toUint8Array } from './utils.js';
|
|
3
|
+
// https://www.rfc-editor.org/rfc/rfc5116#section-5.1
|
|
4
|
+
const AES_GCM_IV_LENGTH = 12;
|
|
5
|
+
/**
|
|
6
|
+
* Encrypt data using AES-GCM.
|
|
7
|
+
*
|
|
8
|
+
* @param key - The 16, 24, or 32-byte AES key.
|
|
9
|
+
* @param plaintext - The plaintext.
|
|
10
|
+
* @param options - Additional configuration options.
|
|
11
|
+
* @returns The ciphertext and the IV used for encryption.
|
|
12
|
+
*/
|
|
13
|
+
export async function encrypt(key, plaintext, options) {
|
|
14
|
+
if (key.byteLength === 0) {
|
|
15
|
+
throw new Error('Invalid key length: Key must not be zero bytes for AES-GCM.');
|
|
16
|
+
}
|
|
17
|
+
const iv = toUint8Array(options?.unsafeIv ?? getRandomBytes(AES_GCM_IV_LENGTH));
|
|
18
|
+
if (iv.byteLength === 0) {
|
|
19
|
+
throw new Error('Invalid IV length: IV must not be zero bytes for AES-GCM.');
|
|
20
|
+
}
|
|
21
|
+
if (!options?.unsafeIvLength && iv.byteLength !== AES_GCM_IV_LENGTH) {
|
|
22
|
+
throw new Error(`Unsafe IV length: IV must be exactly ${AES_GCM_IV_LENGTH} bytes for AES-GCM. To bypass this check, set the \`unsafeIvLength\` option to \`true\`.`);
|
|
23
|
+
}
|
|
24
|
+
const subtleKey = await globalThis.crypto.subtle.importKey('raw', key, { name: 'AES-GCM' }, false, ['encrypt']);
|
|
25
|
+
const ciphertext = await globalThis.crypto.subtle.encrypt(
|
|
26
|
+
// Converting to Uint8Array to work around a Node 22 bug, we may be able to remove in the future.
|
|
27
|
+
{ name: 'AES-GCM', iv }, subtleKey, toUint8Array(plaintext));
|
|
28
|
+
return { ciphertext: new Uint8Array(ciphertext), iv };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decrypt data using AES-GCM.
|
|
32
|
+
*
|
|
33
|
+
* @param key - The 16, 24, or 32-byte AES key.
|
|
34
|
+
* @param iv - The initialization vector.
|
|
35
|
+
* @param ciphertext - The ciphertext.
|
|
36
|
+
* @param options - Additional configuration options.
|
|
37
|
+
* @returns The decrypted plaintext.
|
|
38
|
+
*/
|
|
39
|
+
export async function decrypt(key, iv, ciphertext, options) {
|
|
40
|
+
if (key.byteLength === 0) {
|
|
41
|
+
throw new Error('Invalid key length: Key must not be zero bytes for AES-GCM.');
|
|
42
|
+
}
|
|
43
|
+
if (iv.byteLength === 0) {
|
|
44
|
+
throw new Error('Invalid IV length: IV must not be zero bytes for AES-GCM.');
|
|
45
|
+
}
|
|
46
|
+
if (!options?.unsafeIvLength && iv.byteLength !== AES_GCM_IV_LENGTH) {
|
|
47
|
+
throw new Error(`Unsafe IV length: IV must be exactly ${AES_GCM_IV_LENGTH} bytes for AES-GCM. To bypass this check, set the \`unsafeIvLength\` option to \`true\`.`);
|
|
48
|
+
}
|
|
49
|
+
const subtleKey = await globalThis.crypto.subtle.importKey('raw', key, { name: 'AES-GCM' }, false, ['decrypt']);
|
|
50
|
+
const plaintext = await globalThis.crypto.subtle.decrypt(
|
|
51
|
+
// Converting to Uint8Array to work around a Node 22 bug, we may be able to remove in the future.
|
|
52
|
+
{ name: 'AES-GCM', iv: toUint8Array(iv) }, subtleKey, toUint8Array(ciphertext));
|
|
53
|
+
return new Uint8Array(plaintext);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=aes-gcm.js.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AE,UAAU,EAAE,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC;AACxD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAiB,EACjB,EAAgB,EAChB,UAAwB,EACxB,OAA8B;IAE9B,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IAED,IAAI,EAAE,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,cAAc,IAAI,EAAE,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,wCAAwC,iBAAiB,0FAA0F,CACpJ,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,KAAK,EACL,CAAC,SAAS,CAAC,CACZ,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;IACtD,iGAAiG;IACjG,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,EACzC,SAAS,EACT,YAAY,CAAC,UAAU,CAAC,CACzB,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import { getRandomBytes } from './random.js';\nimport { toUint8Array } from './utils.js';\n\n// https://www.rfc-editor.org/rfc/rfc5116#section-5.1\nconst AES_GCM_IV_LENGTH = 12;\n\nexport type AesGcmEncryptOptions = {\n /**\n * The initialization vector. If not provided, a random 12-byte IV\n * is generated automatically. It is recommended to use the generated one rather\n * than providing one, to avoid IV reuse.\n */\n unsafeIv?: BufferSource;\n} & AesGcmDecryptOptions;\n\nexport type AesGcmDecryptOptions = {\n /**\n * Skip the IV length check. Using an IV other than 12 bytes deviates from\n * the standard and is considered less safe.\n */\n unsafeIvLength?: boolean;\n};\n\nexport type AesGcmEncryptResult = {\n ciphertext: Uint8Array<ArrayBuffer>;\n iv: Uint8Array<ArrayBuffer>;\n};\n\n/**\n * Encrypt data using AES-GCM.\n *\n * @param key - The 16, 24, or 32-byte AES key.\n * @param plaintext - The plaintext.\n * @param options - Additional configuration options.\n * @returns The ciphertext and the IV used for encryption.\n */\nexport async function encrypt(\n key: BufferSource,\n plaintext: BufferSource,\n options?: AesGcmEncryptOptions,\n): Promise<AesGcmEncryptResult> {\n if (key.byteLength === 0) {\n throw new Error(\n 'Invalid key length: Key must not be zero bytes for AES-GCM.',\n );\n }\n\n const iv = toUint8Array(\n options?.unsafeIv ?? getRandomBytes(AES_GCM_IV_LENGTH),\n );\n\n if (iv.byteLength === 0) {\n throw new Error(\n 'Invalid IV length: IV must not be zero bytes for AES-GCM.',\n );\n }\n\n if (!options?.unsafeIvLength && iv.byteLength !== AES_GCM_IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${AES_GCM_IV_LENGTH} bytes for AES-GCM. To bypass this check, set the \\`unsafeIvLength\\` option to \\`true\\`.`,\n );\n }\n\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n key,\n { name: 'AES-GCM' },\n false,\n ['encrypt'],\n );\n\n const ciphertext = await globalThis.crypto.subtle.encrypt(\n // Converting to Uint8Array to work around a Node 22 bug, we may be able to remove in the future.\n { name: 'AES-GCM', iv },\n subtleKey,\n toUint8Array(plaintext),\n );\n\n return { ciphertext: new Uint8Array(ciphertext), iv };\n}\n\n/**\n * Decrypt data using AES-GCM.\n *\n * @param key - The 16, 24, or 32-byte AES key.\n * @param iv - The initialization vector.\n * @param ciphertext - The ciphertext.\n * @param options - Additional configuration options.\n * @returns The decrypted plaintext.\n */\nexport async function decrypt(\n key: BufferSource,\n iv: BufferSource,\n ciphertext: BufferSource,\n options?: AesGcmDecryptOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (key.byteLength === 0) {\n throw new Error(\n 'Invalid key length: Key must not be zero bytes for AES-GCM.',\n );\n }\n\n if (iv.byteLength === 0) {\n throw new Error(\n 'Invalid IV length: IV must not be zero bytes for AES-GCM.',\n );\n }\n\n if (!options?.unsafeIvLength && iv.byteLength !== AES_GCM_IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${AES_GCM_IV_LENGTH} bytes for AES-GCM. To bypass this check, set the \\`unsafeIvLength\\` option to \\`true\\`.`,\n );\n }\n\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n key,\n { name: 'AES-GCM' },\n false,\n ['decrypt'],\n );\n\n const plaintext = await globalThis.crypto.subtle.decrypt(\n // Converting to Uint8Array to work around a Node 22 bug, we may be able to remove in the future.\n { name: 'AES-GCM', iv: toUint8Array(iv) },\n subtleKey,\n toUint8Array(ciphertext),\n );\n\n return new Uint8Array(plaintext);\n}\n"]}
|
package/dist/ed25519.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { KeyPair } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a new random Ed25519 key pair.
|
|
4
|
+
*
|
|
5
|
+
* @returns The raw 32-byte Ed25519 private key and 32-byte Ed25519 public key.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateKeyPair(): Promise<KeyPair>;
|
|
1
8
|
/**
|
|
2
9
|
* Derive the Ed25519 public key corresponding to the given private key.
|
|
3
10
|
*
|
|
4
11
|
* @param privateKey - The 32-byte Ed25519 private key.
|
|
5
12
|
* @returns The 32-byte Ed25519 public key.
|
|
6
13
|
*/
|
|
7
|
-
export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Array
|
|
14
|
+
export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
8
15
|
/**
|
|
9
16
|
* Sign the given data using the given Ed25519 private key.
|
|
10
17
|
*
|
|
@@ -12,7 +19,7 @@ export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Arr
|
|
|
12
19
|
* @param data - The data to sign.
|
|
13
20
|
* @returns The 64-byte Ed25519 signature.
|
|
14
21
|
*/
|
|
15
|
-
export declare function sign(privateKey: BufferSource, data: BufferSource): Promise<Uint8Array
|
|
22
|
+
export declare function sign(privateKey: BufferSource, data: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
16
23
|
/**
|
|
17
24
|
* Verify an Ed25519 signature.
|
|
18
25
|
*
|
package/dist/ed25519.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAWrC;;;;GAIG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAOxD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,YAAY,GACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAiClC;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CACxB,UAAU,EAAE,YAAY,EACxB,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAuBlC;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC1B,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,OAAO,CAAC,CA2BlB"}
|
package/dist/ed25519.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRandomBytes } from './random.js';
|
|
1
2
|
import { buildPKCS8Header, toPKCS8 } from './utils.js';
|
|
2
3
|
// https://www.rfc-editor.org/rfc/rfc8032
|
|
3
4
|
const ED25519_KEY_LENGTH = 32;
|
|
@@ -5,6 +6,18 @@ const ED25519_SIGNATURE_LENGTH = 64;
|
|
|
5
6
|
// https://www.rfc-editor.org/rfc/rfc8410#section-7
|
|
6
7
|
// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js
|
|
7
8
|
const ED25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x70]);
|
|
9
|
+
/**
|
|
10
|
+
* Generate a new random Ed25519 key pair.
|
|
11
|
+
*
|
|
12
|
+
* @returns The raw 32-byte Ed25519 private key and 32-byte Ed25519 public key.
|
|
13
|
+
*/
|
|
14
|
+
export async function generateKeyPair() {
|
|
15
|
+
const privateKey = getRandomBytes(ED25519_KEY_LENGTH);
|
|
16
|
+
return {
|
|
17
|
+
privateKey,
|
|
18
|
+
publicKey: await getPublicKey(privateKey),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
8
21
|
/**
|
|
9
22
|
* Derive the Ed25519 public key corresponding to the given private key.
|
|
10
23
|
*
|
package/dist/ed25519.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvD,yCAAyC;AACzC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,mDAAmD;AACnD,8FAA8F;AAC9F,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAwB;IAExB,IAAI,U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xD,OAAO,EACP,OAAO,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACzC,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACnD,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,SAAS,EACT,IAAI,CACL,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,SAAuB,EACvB,SAAuB,EACvB,IAAkB;IAElB,IAAI,SAAS,CAAC,UAAU,KAAK,kBAAkB,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,yDAAyD,kBAAkB,qBAAqB,CACjG,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,wBAAwB,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,uDAAuD,wBAAwB,qBAAqB,CACrG,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,KAAK,EACL,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CACpC,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,SAAS,EACT,SAAS,EACT,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import { buildPKCS8Header, toPKCS8 } from './utils.js';\n\n// https://www.rfc-editor.org/rfc/rfc8032\nconst ED25519_KEY_LENGTH = 32;\nconst ED25519_SIGNATURE_LENGTH = 64;\n\n// https://www.rfc-editor.org/rfc/rfc8410#section-7\n// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js\nconst ED25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x70]);\n\n/**\n * Derive the Ed25519 public key corresponding to the given private key.\n *\n * @param privateKey - The 32-byte Ed25519 private key.\n * @returns The 32-byte Ed25519 public key.\n */\nexport async function getPublicKey(\n privateKey: BufferSource,\n): Promise<Uint8Array
|
|
1
|
+
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvD,yCAAyC;AACzC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,mDAAmD;AACnD,8FAA8F;AAC9F,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,UAAU,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAEtD,OAAO;QACL,UAAU;QACV,SAAS,EAAE,MAAM,YAAY,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAwB;IAExB,IAAI,UAAU,CAAC,UAAU,KAAK,kBAAkB,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CACb,2DAA2D,kBAAkB,qBAAqB,CACnG,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/D,OAAO,EACP,OAAO,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACzC,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,IAAI,EACJ,CAAC,M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nC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,SAAuB,EACvB,SAAuB,EACvB,IAAkB;IAElB,IAAI,SAAS,CAAC,UAAU,KAAK,kBAAkB,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,yDAAyD,kBAAkB,qBAAqB,CACjG,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,wBAAwB,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,uDAAuD,wBAAwB,qBAAqB,CACrG,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,KAAK,EACL,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CACpC,EAAE,IAAI,EAAE,SAAS,EAAE,EACnB,SAAS,EACT,SAAS,EACT,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import { getRandomBytes } from './random.js';\nimport { KeyPair } from './types.js';\nimport { buildPKCS8Header, toPKCS8 } from './utils.js';\n\n// https://www.rfc-editor.org/rfc/rfc8032\nconst ED25519_KEY_LENGTH = 32;\nconst ED25519_SIGNATURE_LENGTH = 64;\n\n// https://www.rfc-editor.org/rfc/rfc8410#section-7\n// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js\nconst ED25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x70]);\n\n/**\n * Generate a new random Ed25519 key pair.\n *\n * @returns The raw 32-byte Ed25519 private key and 32-byte Ed25519 public key.\n */\nexport async function generateKeyPair(): Promise<KeyPair> {\n const privateKey = getRandomBytes(ED25519_KEY_LENGTH);\n\n return {\n privateKey,\n publicKey: await getPublicKey(privateKey),\n };\n}\n\n/**\n * Derive the Ed25519 public key corresponding to the given private key.\n *\n * @param privateKey - The 32-byte Ed25519 private key.\n * @returns The 32-byte Ed25519 public key.\n */\nexport async function getPublicKey(\n privateKey: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (privateKey.byteLength !== ED25519_KEY_LENGTH) {\n throw new Error(\n `Invalid private key length: Private key must be exactly ${ED25519_KEY_LENGTH} bytes for Ed25519.`,\n );\n }\n\n // The WebCrypto API expects private keys to be in PKCS8 format.\n const subtlePrivateKey = await globalThis.crypto.subtle.importKey(\n 'pkcs8',\n toPKCS8(ED25519_PKCS8_HEADER, privateKey),\n { name: 'Ed25519' },\n true,\n ['sign'],\n );\n\n const jwk = await globalThis.crypto.subtle.exportKey('jwk', subtlePrivateKey);\n\n // Intentionally discarding private key from JWK (`d`).\n const subtlePublicKey = await globalThis.crypto.subtle.importKey(\n 'jwk',\n { kty: jwk.kty, crv: jwk.crv, x: jwk.x },\n { name: 'Ed25519' },\n true,\n ['verify'],\n );\n\n const publicKey = await globalThis.crypto.subtle.exportKey(\n 'raw',\n subtlePublicKey,\n );\n\n return new Uint8Array(publicKey);\n}\n\n/**\n * Sign the given data using the given Ed25519 private key.\n *\n * @param privateKey - The 32-byte Ed25519 private key seed.\n * @param data - The data to sign.\n * @returns The 64-byte Ed25519 signature.\n */\nexport async function sign(\n privateKey: BufferSource,\n data: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (privateKey.byteLength !== ED25519_KEY_LENGTH) {\n throw new Error(\n `Invalid private key length: Private key must be exactly ${ED25519_KEY_LENGTH} bytes for Ed25519.`,\n );\n }\n\n // The WebCrypto API expects private keys to be in PKCS8 format.\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'pkcs8',\n toPKCS8(ED25519_PKCS8_HEADER, privateKey),\n { name: 'Ed25519' },\n false,\n ['sign'],\n );\n\n const signature = await globalThis.crypto.subtle.sign(\n { name: 'Ed25519' },\n subtleKey,\n data,\n );\n\n return new Uint8Array(signature);\n}\n\n/**\n * Verify an Ed25519 signature.\n *\n * @param publicKey - The 32-byte Ed25519 public key.\n * @param signature - The 64-byte signature to verify.\n * @param data - The signed data.\n * @returns `true` if the signature is valid, `false` otherwise.\n */\nexport async function verify(\n publicKey: BufferSource,\n signature: BufferSource,\n data: BufferSource,\n): Promise<boolean> {\n if (publicKey.byteLength !== ED25519_KEY_LENGTH) {\n throw new Error(\n `Invalid public key length: Public key must be exactly ${ED25519_KEY_LENGTH} bytes for Ed25519.`,\n );\n }\n\n if (signature.byteLength !== ED25519_SIGNATURE_LENGTH) {\n throw new Error(\n `Invalid signature length: Signature must be exactly ${ED25519_SIGNATURE_LENGTH} bytes for Ed25519.`,\n );\n }\n\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n publicKey,\n { name: 'Ed25519' },\n false,\n ['verify'],\n );\n\n return globalThis.crypto.subtle.verify(\n { name: 'Ed25519' },\n subtleKey,\n signature,\n data,\n );\n}\n"]}
|
package/dist/hkdf.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type HkdfOptions = {
|
|
|
15
15
|
* @param options - Additional configuration options.
|
|
16
16
|
* @returns The derived key material.
|
|
17
17
|
*/
|
|
18
|
-
export declare function hkdfSha256(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array
|
|
18
|
+
export declare function hkdfSha256(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
19
19
|
/**
|
|
20
20
|
* Derive key material using HKDF-SHA-384.
|
|
21
21
|
*
|
|
@@ -26,7 +26,7 @@ export declare function hkdfSha256(ikm: BufferSource, salt: BufferSource, info:
|
|
|
26
26
|
* @param options - Additional configuration options.
|
|
27
27
|
* @returns The derived key material.
|
|
28
28
|
*/
|
|
29
|
-
export declare function hkdfSha384(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array
|
|
29
|
+
export declare function hkdfSha384(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
30
30
|
/**
|
|
31
31
|
* Derive key material using HKDF-SHA-512.
|
|
32
32
|
*
|
|
@@ -37,5 +37,5 @@ export declare function hkdfSha384(ikm: BufferSource, salt: BufferSource, info:
|
|
|
37
37
|
* @param options - Additional configuration options.
|
|
38
38
|
* @returns The derived key material.
|
|
39
39
|
*/
|
|
40
|
-
export declare function hkdfSha512(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array
|
|
40
|
+
export declare function hkdfSha512(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
41
41
|
//# sourceMappingURL=hkdf.d.ts.map
|
package/dist/hkdf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../src/hkdf.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../src/hkdf.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,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,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,IAAI,CACjB,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAO,GAAgB,EAAE;IAEzB,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,yBAAyB,IAAI,GAAG,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CACb,6DAA6D,cAAc,mBAAmB,IAAI,mFAAmF,CACtL,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,MAAM,EAAE,EAChB,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAC3D;QACE,IAAI,EAAE,MAAM;QACZ,IAAI;QACJ,IAAI;QACJ,IAAI;KACL,EACD,SAAS,EACT,SAAS,GAAG,CAAC,CACd,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\nconst MIN_IKM_LENGTH = 32;\n\nexport type HkdfOptions = {\n /**\n * Skip the minimum IKM length check. Using IKM shorter than 32 bytes\n * reduces the entropy of the derived key material.\n */\n unsafeInputKeyingMaterial?: boolean;\n};\n\n/**\n * Derive key material using HKDF-SHA-256.\n *\n * @param ikm - The input keying material.\n * @param salt - The salt to use.\n * @param info - Context and application-specific information.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The derived key material.\n */\nexport async function hkdfSha256(\n ikm: BufferSource,\n salt: BufferSource,\n info: BufferSource,\n keyLength: number,\n options?: HkdfOptions,\n): Promise<Uint8Array
|
|
1
|
+
{"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../src/hkdf.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,EAAE,CAAC;AAU1B;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,IAAI,CACjB,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,IAAkB,EAClB,SAAiB,EACjB,OAAO,GAAgB,EAAE;IAEzB,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,yBAAyB,IAAI,GAAG,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CACb,6DAA6D,cAAc,mBAAmB,IAAI,mFAAmF,CACtL,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,MAAM,EAAE,EAChB,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAC3D;QACE,IAAI,EAAE,MAAM;QACZ,IAAI;QACJ,IAAI;QACJ,IAAI;KACL,EACD,SAAS,EACT,SAAS,GAAG,CAAC,CACd,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\nconst MIN_IKM_LENGTH = 32;\n\nexport type HkdfOptions = {\n /**\n * Skip the minimum IKM length check. Using IKM shorter than 32 bytes\n * reduces the entropy of the derived key material.\n */\n unsafeInputKeyingMaterial?: boolean;\n};\n\n/**\n * Derive key material using HKDF-SHA-256.\n *\n * @param ikm - The input keying material.\n * @param salt - The salt to use.\n * @param info - Context and application-specific information.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The derived key material.\n */\nexport async function hkdfSha256(\n ikm: BufferSource,\n salt: BufferSource,\n info: BufferSource,\n keyLength: number,\n options?: HkdfOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hkdf(ikm, 'SHA-256', salt, info, keyLength, options);\n}\n\n/**\n * Derive key material using HKDF-SHA-384.\n *\n * @param ikm - The input keying material.\n * @param salt - The salt to use.\n * @param info - Context and application-specific information.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The derived key material.\n */\nexport async function hkdfSha384(\n ikm: BufferSource,\n salt: BufferSource,\n info: BufferSource,\n keyLength: number,\n options?: HkdfOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hkdf(ikm, 'SHA-384', salt, info, keyLength, options);\n}\n\n/**\n * Derive key material using HKDF-SHA-512.\n *\n * @param ikm - The input keying material.\n * @param salt - The salt to use.\n * @param info - Context and application-specific information.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The derived key material.\n */\nexport async function hkdfSha512(\n ikm: BufferSource,\n salt: BufferSource,\n info: BufferSource,\n keyLength: number,\n options?: HkdfOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hkdf(ikm, 'SHA-512', salt, info, keyLength, options);\n}\n\n/**\n * Derive key material using HKDF.\n *\n * @param ikm - The input keying material.\n * @param hash - The hash function to use.\n * @param salt - The salt to use.\n * @param info - Context and application-specific information.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The derived key material.\n */\nasync function hkdf(\n ikm: BufferSource,\n hash: HashFunction,\n salt: BufferSource,\n info: BufferSource,\n keyLength: number,\n options: HkdfOptions = {},\n): Promise<Uint8Array<ArrayBuffer>> {\n if (ikm.byteLength === 0) {\n throw new Error(\n `Unsafe input keying material length: IKM must not be zero bytes for HKDF-${hash}.`,\n );\n }\n\n if (!options.unsafeInputKeyingMaterial && ikm.byteLength < MIN_IKM_LENGTH) {\n throw new Error(\n `Unsafe input keying material length: IKM must be at least ${MIN_IKM_LENGTH} bytes for HKDF-${hash}. To bypass this check, set the \\`unsafeInputKeyingMaterial\\` option to \\`true\\`.`,\n );\n }\n\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n ikm,\n { name: 'HKDF' },\n false,\n ['deriveBits'],\n );\n\n const derivedBits = await globalThis.crypto.subtle.deriveBits(\n {\n name: 'HKDF',\n hash,\n salt,\n info,\n },\n subtleKey,\n keyLength * 8,\n );\n\n return new Uint8Array(derivedBits);\n}\n"]}
|
package/dist/hmac.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type HmacOptions = {
|
|
|
13
13
|
* @param options - Additional configuration options.
|
|
14
14
|
* @returns The HMAC-SHA-256 of the data.
|
|
15
15
|
*/
|
|
16
|
-
export declare function hmacSha256(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array
|
|
16
|
+
export declare function hmacSha256(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
17
17
|
/**
|
|
18
18
|
* Compute the HMAC-SHA-384 of the given data using the given key.
|
|
19
19
|
*
|
|
@@ -22,7 +22,7 @@ export declare function hmacSha256(key: BufferSource, data: BufferSource, option
|
|
|
22
22
|
* @param options - Additional configuration options.
|
|
23
23
|
* @returns The HMAC-SHA-384 of the data.
|
|
24
24
|
*/
|
|
25
|
-
export declare function hmacSha384(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array
|
|
25
|
+
export declare function hmacSha384(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
26
26
|
/**
|
|
27
27
|
* Compute the HMAC-SHA-512 of the given data using the given key.
|
|
28
28
|
*
|
|
@@ -31,5 +31,5 @@ export declare function hmacSha384(key: BufferSource, data: BufferSource, option
|
|
|
31
31
|
* @param options - Additional configuration options.
|
|
32
32
|
* @returns The HMAC-SHA-512 of the data.
|
|
33
33
|
*/
|
|
34
|
-
export declare function hmacSha512(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array
|
|
34
|
+
export declare function hmacSha512(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
35
35
|
//# sourceMappingURL=hmac.d.ts.map
|
package/dist/hmac.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC"}
|
package/dist/hmac.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAEA,0DAA0D;AAC1D,MAAM,cAAc,GAAiC;IACnD,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EA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,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC5E,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\n// https://datatracker.ietf.org/doc/html/rfc2104#section-3\nconst MIN_KEY_LENGTH: Record<HashFunction, number> = {\n 'SHA-256': 32,\n 'SHA-384': 48,\n 'SHA-512': 64,\n};\n\nexport type HmacOptions = {\n /**\n * Skip the minimum key length check. Using a key shorter than the hash\n * output length reduces the effective security strength of HMAC (RFC 2104).\n */\n unsafeKeyLength?: boolean;\n};\n\n/**\n * Compute the HMAC-SHA-256 of the given data using the given key.\n *\n * @param key - The key to use.\n * @param data - The data to hash.\n * @param options - Additional configuration options.\n * @returns The HMAC-SHA-256 of the data.\n */\nexport async function hmacSha256(\n key: BufferSource,\n data: BufferSource,\n options?: HmacOptions,\n): Promise<Uint8Array
|
|
1
|
+
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAEA,0DAA0D;AAC1D,MAAM,cAAc,GAAiC;IACnD,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;CACd,CAAC;AAUF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAiB,EACjB,IAAkB,EAClB,OAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,IAAI,CACjB,GAAiB,EACjB,IAAkB,EAClB,IAAkB,EAClB,OAAO,GAAgB,EAAE;IAEzB,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,0DAA0D,IAAI,GAAG,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,GAAG,CAAC,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,2CAA2C,cAAc,CAAC,IAAI,CAAC,mBAAmB,IAAI,yEAAyE,CAChK,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACxD,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EACtB,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC5E,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\n// https://datatracker.ietf.org/doc/html/rfc2104#section-3\nconst MIN_KEY_LENGTH: Record<HashFunction, number> = {\n 'SHA-256': 32,\n 'SHA-384': 48,\n 'SHA-512': 64,\n};\n\nexport type HmacOptions = {\n /**\n * Skip the minimum key length check. Using a key shorter than the hash\n * output length reduces the effective security strength of HMAC (RFC 2104).\n */\n unsafeKeyLength?: boolean;\n};\n\n/**\n * Compute the HMAC-SHA-256 of the given data using the given key.\n *\n * @param key - The key to use.\n * @param data - The data to hash.\n * @param options - Additional configuration options.\n * @returns The HMAC-SHA-256 of the data.\n */\nexport async function hmacSha256(\n key: BufferSource,\n data: BufferSource,\n options?: HmacOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hmac(key, 'SHA-256', data, options);\n}\n\n/**\n * Compute the HMAC-SHA-384 of the given data using the given key.\n *\n * @param key - The key to use.\n * @param data - The data to hash.\n * @param options - Additional configuration options.\n * @returns The HMAC-SHA-384 of the data.\n */\nexport async function hmacSha384(\n key: BufferSource,\n data: BufferSource,\n options?: HmacOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hmac(key, 'SHA-384', data, options);\n}\n\n/**\n * Compute the HMAC-SHA-512 of the given data using the given key.\n *\n * @param key - The key to use.\n * @param data - The data to hash.\n * @param options - Additional configuration options.\n * @returns The HMAC-SHA-512 of the data.\n */\nexport async function hmacSha512(\n key: BufferSource,\n data: BufferSource,\n options?: HmacOptions,\n): Promise<Uint8Array<ArrayBuffer>> {\n return hmac(key, 'SHA-512', data, options);\n}\n\n/**\n * Compute the HMAC-SHA of the given data using the given key.\n *\n * @param key - The key to use.\n * @param hash - The hash to use.\n * @param data - The data to hash.\n * @param options - Additional configuration options..\n * @returns The HMAC-SHA of the data.\n */\nasync function hmac(\n key: BufferSource,\n hash: HashFunction,\n data: BufferSource,\n options: HmacOptions = {},\n): Promise<Uint8Array<ArrayBuffer>> {\n if (key.byteLength === 0) {\n throw new Error(\n `Unsafe key length: Key must not be zero bytes for HMAC-${hash}.`,\n );\n }\n\n if (!options.unsafeKeyLength && key.byteLength < MIN_KEY_LENGTH[hash]) {\n throw new Error(\n `Unsafe key length: Key must be at least ${MIN_KEY_LENGTH[hash]} bytes for HMAC-${hash}. To bypass this check, set the \\`unsafeKeyLength\\` option to \\`true\\`.`,\n );\n }\n\n const subtleKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n key,\n { name: 'HMAC', hash },\n false,\n ['sign'],\n );\n\n const result = await globalThis.crypto.subtle.sign('HMAC', subtleKey, data);\n return new Uint8Array(result);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,mBAAmB,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC","sourcesContent":["export * from './random.js';\nexport type * from './types.js';\n"]}
|
package/dist/pbkdf2.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type Pbkdf2Options = {
|
|
|
20
20
|
* @param options - Additional configuration options.
|
|
21
21
|
* @returns The PBKDF2 of the password.
|
|
22
22
|
*/
|
|
23
|
-
export declare function pbkdf2Sha256(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array
|
|
23
|
+
export declare function pbkdf2Sha256(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array<ArrayBuffer>>;
|
|
24
24
|
/**
|
|
25
25
|
* Compute the PBKDF2 of the given password, salt, iterations, and key length.
|
|
26
26
|
* The hash function used is SHA-384.
|
|
@@ -32,7 +32,7 @@ export declare function pbkdf2Sha256(password: BufferSource, salt: BufferSource,
|
|
|
32
32
|
* @param options - Additional configuration options.
|
|
33
33
|
* @returns The PBKDF2 of the password.
|
|
34
34
|
*/
|
|
35
|
-
export declare function pbkdf2Sha384(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array
|
|
35
|
+
export declare function pbkdf2Sha384(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array<ArrayBuffer>>;
|
|
36
36
|
/**
|
|
37
37
|
* Compute the PBKDF2 of the given password, salt, iterations, and key length.
|
|
38
38
|
* The hash function used is SHA-512.
|
|
@@ -44,5 +44,5 @@ export declare function pbkdf2Sha384(password: BufferSource, salt: BufferSource,
|
|
|
44
44
|
* @param options - Additional configuration options.
|
|
45
45
|
* @returns The PBKDF2 of the password.
|
|
46
46
|
*/
|
|
47
|
-
export declare function pbkdf2Sha512(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array
|
|
47
|
+
export declare function pbkdf2Sha512(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array<ArrayBuffer>>;
|
|
48
48
|
//# sourceMappingURL=pbkdf2.d.ts.map
|
package/dist/pbkdf2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../src/pbkdf2.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,YAAY,EAClB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../src/pbkdf2.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAA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G,CAAC,CACd,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\n// https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html\nconst MIN_ITERATIONS: Record<HashFunction, number> = {\n 'SHA-256': 600_000,\n // SHA-384 is not explicitly listed by OWASP; using the SHA-512 value since\n // both variants use 64-bit words internally.\n 'SHA-384': 220_000,\n 'SHA-512': 220_000,\n};\n\n/**\n * Options for the PBKDF2 functions.\n */\nexport type Pbkdf2Options = {\n /**\n * If `true`, the iteration count check is skipped. Disabling this check\n * reduces the computational cost of brute-force attacks against the derived\n * key.\n */\n unsafeIterations?: boolean;\n};\n\n/**\n * Compute the PBKDF2 of the given password, salt, iterations, and key length.\n * The hash function used is SHA-256.\n *\n * @param password - The password to hash.\n * @param salt - The salt to use.\n * @param iterations - The number of iterations.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The PBKDF2 of the password.\n */\nexport async function pbkdf2Sha256(\n password: BufferSource,\n salt: BufferSource,\n iterations: number,\n keyLength: number,\n options?: Pbkdf2Options,\n): Promise<Uint8Array
|
|
1
|
+
{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../src/pbkdf2.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,cAAc,GAAiC;IACnD,SAAS,EAAE,OAAO;IAClB,2EAA2E;IAC3E,6CAA6C;IAC7C,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,OAAO;CACnB,CAAC;AAcF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAsB,EACtB,IAAkB,EAClB,UAAkB,EAClB,SAAiB,EACjB,OAAuB;IAEvB,OAAO,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;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AAC;AACrC,CAAC","sourcesContent":["import type { HashFunction } from './types.js';\n\n// https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html\nconst MIN_ITERATIONS: Record<HashFunction, number> = {\n 'SHA-256': 600_000,\n // SHA-384 is not explicitly listed by OWASP; using the SHA-512 value since\n // both variants use 64-bit words internally.\n 'SHA-384': 220_000,\n 'SHA-512': 220_000,\n};\n\n/**\n * Options for the PBKDF2 functions.\n */\nexport type Pbkdf2Options = {\n /**\n * If `true`, the iteration count check is skipped. Disabling this check\n * reduces the computational cost of brute-force attacks against the derived\n * key.\n */\n unsafeIterations?: boolean;\n};\n\n/**\n * Compute the PBKDF2 of the given password, salt, iterations, and key length.\n * The hash function used is SHA-256.\n *\n * @param password - The password to hash.\n * @param salt - The salt to use.\n * @param iterations - The number of iterations.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The PBKDF2 of the password.\n */\nexport async function pbkdf2Sha256(\n password: BufferSource,\n salt: BufferSource,\n iterations: number,\n keyLength: number,\n options?: Pbkdf2Options,\n): Promise<Uint8Array<ArrayBuffer>> {\n return pbkdf2(password, salt, 'SHA-256', iterations, keyLength, options);\n}\n\n/**\n * Compute the PBKDF2 of the given password, salt, iterations, and key length.\n * The hash function used is SHA-384.\n *\n * @param password - The password to hash.\n * @param salt - The salt to use.\n * @param iterations - The number of iterations.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The PBKDF2 of the password.\n */\nexport async function pbkdf2Sha384(\n password: BufferSource,\n salt: BufferSource,\n iterations: number,\n keyLength: number,\n options?: Pbkdf2Options,\n): Promise<Uint8Array<ArrayBuffer>> {\n return pbkdf2(password, salt, 'SHA-384', iterations, keyLength, options);\n}\n\n/**\n * Compute the PBKDF2 of the given password, salt, iterations, and key length.\n * The hash function used is SHA-512.\n *\n * @param password - The password to hash.\n * @param salt - The salt to use.\n * @param iterations - The number of iterations.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional configuration options.\n * @returns The PBKDF2 of the password.\n */\nexport async function pbkdf2Sha512(\n password: BufferSource,\n salt: BufferSource,\n iterations: number,\n keyLength: number,\n options?: Pbkdf2Options,\n): Promise<Uint8Array<ArrayBuffer>> {\n return pbkdf2(password, salt, 'SHA-512', iterations, keyLength, options);\n}\n\n/**\n * Compute the PBKDF2 of the given password, salt, hash, iterations, and key length.\n *\n * @param password - The password to hash.\n * @param salt - The salt to use.\n * @param hash - The hashing function to use.\n * @param iterations - The number of iterations.\n * @param keyLength - The desired key length in bytes.\n * @param options - Additional options.\n * @returns The PBKDF2 of the password.\n */\nasync function pbkdf2(\n password: BufferSource,\n salt: BufferSource,\n hash: HashFunction,\n iterations: number,\n keyLength: number,\n options?: Pbkdf2Options,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (!options?.unsafeIterations && iterations < MIN_ITERATIONS[hash]) {\n throw new Error(\n `Unsafe number of iterations: Iterations must be at least ${MIN_ITERATIONS[hash]} for PBKDF2-${hash}. To bypass this check, set the \\`unsafeIterations\\` option to \\`true\\`.`,\n );\n }\n\n const key = await globalThis.crypto.subtle.importKey(\n 'raw',\n password,\n { name: 'PBKDF2' },\n false,\n ['deriveBits'],\n );\n\n const derivedBits = await globalThis.crypto.subtle.deriveBits(\n {\n name: 'PBKDF2',\n salt,\n iterations,\n hash,\n },\n key,\n // `keyLength` is the number of bytes, but `deriveBits` expects the\n // number of bits, so we multiply by 8.\n keyLength * 8,\n );\n\n return new Uint8Array(derivedBits);\n}\n"]}
|
package/dist/random.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @returns An `Uint8Array` of the provided length with random bytes.
|
|
6
6
|
* @throws If `length` is not greater than 0.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getRandomBytes(length: number): Uint8Array
|
|
8
|
+
export declare function getRandomBytes(length: number): Uint8Array<ArrayBuffer>;
|
|
9
9
|
//# sourceMappingURL=random.d.ts.map
|
package/dist/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAKtE"}
|
package/dist/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["/**\n * Generate random bytes using the platform's cryptographically secure pseudo-random number generator (CSPRNG).\n *\n * @param length - The number of random bytes to generate.\n * @returns An `Uint8Array` of the provided length with random bytes.\n * @throws If `length` is not greater than 0.\n */\nexport function getRandomBytes(length: number): Uint8Array {\n if (length <= 0) {\n throw new Error('Invalid length: Length must be greater than 0.');\n }\n return globalThis.crypto.getRandomValues(new Uint8Array(length));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["/**\n * Generate random bytes using the platform's cryptographically secure pseudo-random number generator (CSPRNG).\n *\n * @param length - The number of random bytes to generate.\n * @returns An `Uint8Array` of the provided length with random bytes.\n * @throws If `length` is not greater than 0.\n */\nexport function getRandomBytes(length: number): Uint8Array<ArrayBuffer> {\n if (length <= 0) {\n throw new Error('Invalid length: Length must be greater than 0.');\n }\n return globalThis.crypto.getRandomValues(new Uint8Array(length));\n}\n"]}
|
package/dist/sha.d.ts
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* @param bytes - A byte array.
|
|
5
5
|
* @returns The SHA-256 hash as a byte array.
|
|
6
6
|
*/
|
|
7
|
-
export declare function sha256(bytes: BufferSource): Promise<Uint8Array
|
|
7
|
+
export declare function sha256(bytes: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
8
8
|
/**
|
|
9
9
|
* Compute a SHA-384 digest for a given byte array.
|
|
10
10
|
*
|
|
11
11
|
* @param bytes - A byte array.
|
|
12
12
|
* @returns The SHA-384 hash as a byte array.
|
|
13
13
|
*/
|
|
14
|
-
export declare function sha384(bytes: BufferSource): Promise<Uint8Array
|
|
14
|
+
export declare function sha384(bytes: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
15
15
|
/**
|
|
16
16
|
* Compute a SHA-512 digest for a given byte array.
|
|
17
17
|
*
|
|
18
18
|
* @param bytes - A byte array.
|
|
19
19
|
* @returns The SHA-512 hash as a byte array.
|
|
20
20
|
*/
|
|
21
|
-
export declare function sha512(bytes: BufferSource): Promise<Uint8Array
|
|
21
|
+
export declare function sha512(bytes: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
22
22
|
//# sourceMappingURL=sha.d.ts.map
|
package/dist/sha.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha.d.ts","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,MAAM,
|
|
1
|
+
{"version":3,"file":"sha.d.ts","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAIlC;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAIlC;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAIlC"}
|
package/dist/sha.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,KAAmB;IAEnB,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,KAAmB;IAEnB,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,KAAmB;IAEnB,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Compute a SHA-256 digest for a given byte array.\n *\n * @param bytes - A byte array.\n * @returns The SHA-256 hash as a byte array.\n */\nexport async function sha256(\n bytes: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-256', bytes),\n );\n}\n\n/**\n * Compute a SHA-384 digest for a given byte array.\n *\n * @param bytes - A byte array.\n * @returns The SHA-384 hash as a byte array.\n */\nexport async function sha384(\n bytes: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-384', bytes),\n );\n}\n\n/**\n * Compute a SHA-512 digest for a given byte array.\n *\n * @param bytes - A byte array.\n * @returns The SHA-512 hash as a byte array.\n */\nexport async function sha512(\n bytes: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-512', bytes),\n );\n}\n"]}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7D,MAAM,MAAM,OAAO,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CACpC,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type HashFunction = 'SHA-256' | 'SHA-384' | 'SHA-512';\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type HashFunction = 'SHA-256' | 'SHA-384' | 'SHA-512';\n\nexport type KeyPair = {\n privateKey: Uint8Array<ArrayBuffer>;\n publicKey: Uint8Array<ArrayBuffer>;\n};\n"]}
|
package/dist/x25519.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import type { KeyPair } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a new random X25519 key pair.
|
|
4
|
+
*
|
|
5
|
+
* @returns The raw 32-byte X25519 private key and 32-byte X25519 public key.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateKeyPair(): Promise<KeyPair>;
|
|
1
8
|
/**
|
|
2
9
|
* Derive the X25519 public key corresponding to a private key.
|
|
3
10
|
*
|
|
4
11
|
* @param privateKey - The 32-byte X25519 private key.
|
|
5
12
|
* @returns The 32-byte X25519 public key.
|
|
6
13
|
*/
|
|
7
|
-
export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Array
|
|
14
|
+
export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
8
15
|
/**
|
|
9
16
|
* Compute the X25519 shared secret given a private key and a peer's public key.
|
|
10
17
|
*
|
|
@@ -12,5 +19,5 @@ export declare function getPublicKey(privateKey: BufferSource): Promise<Uint8Arr
|
|
|
12
19
|
* @param publicKey - The 32-byte X25519 public key of the peer.
|
|
13
20
|
* @returns The 32-byte shared secret.
|
|
14
21
|
*/
|
|
15
|
-
export declare function getSharedSecret(privateKey: BufferSource, publicKey: BufferSource): Promise<Uint8Array
|
|
22
|
+
export declare function getSharedSecret(privateKey: BufferSource, publicKey: BufferSource): Promise<Uint8Array<ArrayBuffer>>;
|
|
16
23
|
//# sourceMappingURL=x25519.d.ts.map
|
package/dist/x25519.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x25519.d.ts","sourceRoot":"","sources":["../src/x25519.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"x25519.d.ts","sourceRoot":"","sources":["../src/x25519.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAa1C;;;;GAIG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAOxD;AAoDD;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,YAAY,GACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAGlC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,YAAY,EACxB,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAGlC"}
|
package/dist/x25519.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRandomBytes } from './random.js';
|
|
1
2
|
import { buildPKCS8Header, toPKCS8 } from './utils.js';
|
|
2
3
|
const X25519_KEY_LENGTH = 32;
|
|
3
4
|
// https://www.rfc-editor.org/rfc/rfc7748#section-4.1
|
|
@@ -6,6 +7,18 @@ X25519_BASE_POINT[0] = 9;
|
|
|
6
7
|
// https://www.rfc-editor.org/rfc/rfc8410#section-7
|
|
7
8
|
// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js
|
|
8
9
|
const X25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x6e]);
|
|
10
|
+
/**
|
|
11
|
+
* Generate a new random X25519 key pair.
|
|
12
|
+
*
|
|
13
|
+
* @returns The raw 32-byte X25519 private key and 32-byte X25519 public key.
|
|
14
|
+
*/
|
|
15
|
+
export async function generateKeyPair() {
|
|
16
|
+
const privateKey = getRandomBytes(X25519_KEY_LENGTH);
|
|
17
|
+
return {
|
|
18
|
+
privateKey,
|
|
19
|
+
publicKey: await getPublicKey(privateKey),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
23
|
* Perform scalar multiplication of a point by a private key,
|
|
11
24
|
* specified as the X25519 function in RFC 7748, Section 5.
|
package/dist/x25519.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x25519.js","sourceRoot":"","sources":["../src/x25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,qDAAqD;AACrD,MAAM,iBAAiB,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AAC7C,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEzB,mDAAmD;AACnD,8FAA8F;AAC9F,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,KAAK,UAAU,cAAc,CAC3B,UAAwB,EACxB,SAAuB;IAEvB,IAAI,UAAU,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,2DAA2D,iBAAiB,oBAAoB,CACjG,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,yDAAyD,iBAAiB,oBAAoB,CAC/F,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/D,OAAO,EACP,OAAO,CAAC,mBAAmB,EAAE,UAAU,CAAC,EACxC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9D,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,EAAE,CACH,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CACtD,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,EAC3C,gBAAgB,EAChB,iBAAiB,GAAG,CAAC,CACtB,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAwB;IAExB,iDAAiD;IACjD,OAAO,cAAc,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAwB,EACxB,SAAuB;IAEvB,sDAAsD;IACtD,OAAO,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { buildPKCS8Header, toPKCS8 } from './utils.js';\n\nconst X25519_KEY_LENGTH = 32;\n\n// https://www.rfc-editor.org/rfc/rfc7748#section-4.1\nconst X25519_BASE_POINT = new Uint8Array(32);\nX25519_BASE_POINT[0] = 9;\n\n// https://www.rfc-editor.org/rfc/rfc8410#section-7\n// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js\nconst X25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x6e]);\n\n/**\n * Perform scalar multiplication of a point by a private key,\n * specified as the X25519 function in RFC 7748, Section 5.\n *\n * @param privateKey - The 32-byte X25519 private key (scalar).\n * @param publicKey - The 32-byte X25519 public key (u-coordinate).\n * @returns The 32-byte result of the scalar multiplication.\n */\nasync function scalarMultiply(\n privateKey: BufferSource,\n publicKey: BufferSource,\n): Promise<Uint8Array
|
|
1
|
+
{"version":3,"file":"x25519.js","sourceRoot":"","sources":["../src/x25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,qDAAqD;AACrD,MAAM,iBAAiB,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AAC7C,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEzB,mDAAmD;AACnD,8FAA8F;AAC9F,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,UAAU,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAErD,OAAO;QACL,UAAU;QACV,SAAS,EAAE,MAAM,YAAY,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,cAAc,CAC3B,UAAwB,EACxB,SAAuB;IAEvB,IAAI,UAAU,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,2DAA2D,iBAAiB,oBAAoB,CACjG,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,yDAAyD,iBAAiB,oBAAoB,CAC/F,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/D,OAAO,EACP,OAAO,CAAC,mBAAmB,EAAE,UAAU,CAAC,EACxC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9D,KAAK,EACL,SAAS,EACT,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,EAAE,CACH,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CACtD,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,EAC3C,gBAAgB,EAChB,iBAAiB,GAAG,CAAC,CACtB,CAAC;IAEF,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAwB;IAExB,iDAAiD;IACjD,OAAO,cAAc,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAwB,EACxB,SAAuB;IAEvB,sDAAsD;IACtD,OAAO,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { getRandomBytes } from './random.js';\nimport type { KeyPair } from './types.js';\nimport { buildPKCS8Header, toPKCS8 } from './utils.js';\n\nconst X25519_KEY_LENGTH = 32;\n\n// https://www.rfc-editor.org/rfc/rfc7748#section-4.1\nconst X25519_BASE_POINT = new Uint8Array(32);\nX25519_BASE_POINT[0] = 9;\n\n// https://www.rfc-editor.org/rfc/rfc8410#section-7\n// https://github.com/nodejs/node/blob/main/test/parallel/test-webcrypto-export-import-cfrg.js\nconst X25519_PKCS8_HEADER = buildPKCS8Header([0x2b, 0x65, 0x6e]);\n\n/**\n * Generate a new random X25519 key pair.\n *\n * @returns The raw 32-byte X25519 private key and 32-byte X25519 public key.\n */\nexport async function generateKeyPair(): Promise<KeyPair> {\n const privateKey = getRandomBytes(X25519_KEY_LENGTH);\n\n return {\n privateKey,\n publicKey: await getPublicKey(privateKey),\n };\n}\n\n/**\n * Perform scalar multiplication of a point by a private key,\n * specified as the X25519 function in RFC 7748, Section 5.\n *\n * @param privateKey - The 32-byte X25519 private key (scalar).\n * @param publicKey - The 32-byte X25519 public key (u-coordinate).\n * @returns The 32-byte result of the scalar multiplication.\n */\nasync function scalarMultiply(\n privateKey: BufferSource,\n publicKey: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (privateKey.byteLength !== X25519_KEY_LENGTH) {\n throw new Error(\n `Invalid private key length: Private key must be exactly ${X25519_KEY_LENGTH} bytes for X25519.`,\n );\n }\n\n if (publicKey.byteLength !== X25519_KEY_LENGTH) {\n throw new Error(\n `Invalid public key length: Public key must be exactly ${X25519_KEY_LENGTH} bytes for X25519.`,\n );\n }\n\n // The WebCrypto API expects private keys to be in PKCS8 format.\n const subtlePrivateKey = await globalThis.crypto.subtle.importKey(\n 'pkcs8',\n toPKCS8(X25519_PKCS8_HEADER, privateKey),\n { name: 'X25519' },\n false,\n ['deriveBits'],\n );\n\n const subtlePublicKey = await globalThis.crypto.subtle.importKey(\n 'raw',\n publicKey,\n { name: 'X25519' },\n false,\n [],\n );\n\n const result = await globalThis.crypto.subtle.deriveBits(\n { name: 'X25519', public: subtlePublicKey },\n subtlePrivateKey,\n X25519_KEY_LENGTH * 8,\n );\n\n return new Uint8Array(result);\n}\n\n/**\n * Derive the X25519 public key corresponding to a private key.\n *\n * @param privateKey - The 32-byte X25519 private key.\n * @returns The 32-byte X25519 public key.\n */\nexport async function getPublicKey(\n privateKey: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n // X25519 public keys are derived as X25519(k, 9)\n return scalarMultiply(privateKey, X25519_BASE_POINT);\n}\n\n/**\n * Compute the X25519 shared secret given a private key and a peer's public key.\n *\n * @param privateKey - The 32-byte X25519 private key.\n * @param publicKey - The 32-byte X25519 public key of the peer.\n * @returns The 32-byte shared secret.\n */\nexport async function getSharedSecret(\n privateKey: BufferSource,\n publicKey: BufferSource,\n): Promise<Uint8Array<ArrayBuffer>> {\n // X25519 shared secrets are derived as X25519(a, K_b)\n return scalarMultiply(privateKey, publicKey);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/cryptography",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0-preview-cdde826",
|
|
4
4
|
"description": "Provides optimized versions of commonly used cryptography functions for MetaMask clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -25,10 +25,30 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./aes-gcm": {
|
|
29
|
+
"types": "./dist/aes-gcm.d.ts",
|
|
30
|
+
"default": "./dist/aes-gcm.js"
|
|
31
|
+
},
|
|
28
32
|
"./ed25519": {
|
|
29
33
|
"types": "./dist/ed25519.d.ts",
|
|
30
34
|
"default": "./dist/ed25519.js"
|
|
31
35
|
},
|
|
36
|
+
"./hkdf": {
|
|
37
|
+
"types": "./dist/hkdf.d.ts",
|
|
38
|
+
"default": "./dist/hkdf.js"
|
|
39
|
+
},
|
|
40
|
+
"./hmac": {
|
|
41
|
+
"types": "./dist/hmac.d.ts",
|
|
42
|
+
"default": "./dist/hmac.js"
|
|
43
|
+
},
|
|
44
|
+
"./pbkdf2": {
|
|
45
|
+
"types": "./dist/pbkdf2.d.ts",
|
|
46
|
+
"default": "./dist/pbkdf2.js"
|
|
47
|
+
},
|
|
48
|
+
"./sha": {
|
|
49
|
+
"types": "./dist/sha.d.ts",
|
|
50
|
+
"default": "./dist/sha.js"
|
|
51
|
+
},
|
|
32
52
|
"./x25519": {
|
|
33
53
|
"types": "./dist/x25519.d.ts",
|
|
34
54
|
"default": "./dist/x25519.js"
|
|
@@ -47,10 +67,10 @@
|
|
|
47
67
|
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
48
68
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/cryptography",
|
|
49
69
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/cryptography",
|
|
50
|
-
"lint:tsconfigs": "
|
|
51
|
-
"lint:tsconfigs:fix": "
|
|
52
|
-
"messenger-action-types:check": "
|
|
53
|
-
"messenger-action-types:generate": "
|
|
70
|
+
"lint:tsconfigs": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
|
|
71
|
+
"lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
|
|
72
|
+
"messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
|
|
73
|
+
"messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
|
|
54
74
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
55
75
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
56
76
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -66,7 +86,6 @@
|
|
|
66
86
|
"jest": "^30.5.2",
|
|
67
87
|
"rimraf": "^6.1.3",
|
|
68
88
|
"ts-jest": "^29.4.14",
|
|
69
|
-
"tsx": "^4.23.15",
|
|
70
89
|
"typedoc": "^0.25.13",
|
|
71
90
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
72
91
|
"typescript": "npm:@typescript/typescript6@^6.0.2"
|