@metamask-previews/cryptography 0.0.0-preview-0a1dd02ad → 0.0.0-preview-c4789fdf4

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 CHANGED
@@ -7,4 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
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))
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
+
10
18
  [Unreleased]: https://github.com/MetaMask/core/
package/dist/hkdf.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ export type HkdfOptions = {
2
+ /**
3
+ * Skip the minimum IKM length check. Using IKM shorter than 32 bytes
4
+ * reduces the entropy of the derived key material.
5
+ */
6
+ unsafeInputKeyingMaterial?: boolean;
7
+ };
8
+ /**
9
+ * Derive key material using HKDF-SHA-256.
10
+ *
11
+ * @param ikm - The input keying material.
12
+ * @param salt - The salt to use.
13
+ * @param info - Context and application-specific information.
14
+ * @param keyLength - The desired key length in bytes.
15
+ * @param options - Additional configuration options.
16
+ * @returns The derived key material.
17
+ */
18
+ export declare function hkdfSha256(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array>;
19
+ /**
20
+ * Derive key material using HKDF-SHA-384.
21
+ *
22
+ * @param ikm - The input keying material.
23
+ * @param salt - The salt to use.
24
+ * @param info - Context and application-specific information.
25
+ * @param keyLength - The desired key length in bytes.
26
+ * @param options - Additional configuration options.
27
+ * @returns The derived key material.
28
+ */
29
+ export declare function hkdfSha384(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array>;
30
+ /**
31
+ * Derive key material using HKDF-SHA-512.
32
+ *
33
+ * @param ikm - The input keying material.
34
+ * @param salt - The salt to use.
35
+ * @param info - Context and application-specific information.
36
+ * @param keyLength - The desired key length in bytes.
37
+ * @param options - Additional configuration options.
38
+ * @returns The derived key material.
39
+ */
40
+ export declare function hkdfSha512(ikm: BufferSource, salt: BufferSource, info: BufferSource, keyLength: number, options?: HkdfOptions): Promise<Uint8Array>;
41
+ //# sourceMappingURL=hkdf.d.ts.map
@@ -0,0 +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,CAErB;AAED;;;;;;;;;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,CAErB;AAED;;;;;;;;;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,CAErB"}
package/dist/hkdf.js ADDED
@@ -0,0 +1,68 @@
1
+ const MIN_IKM_LENGTH = 32;
2
+ /**
3
+ * Derive key material using HKDF-SHA-256.
4
+ *
5
+ * @param ikm - The input keying material.
6
+ * @param salt - The salt to use.
7
+ * @param info - Context and application-specific information.
8
+ * @param keyLength - The desired key length in bytes.
9
+ * @param options - Additional configuration options.
10
+ * @returns The derived key material.
11
+ */
12
+ export async function hkdfSha256(ikm, salt, info, keyLength, options) {
13
+ return hkdf(ikm, 'SHA-256', salt, info, keyLength, options);
14
+ }
15
+ /**
16
+ * Derive key material using HKDF-SHA-384.
17
+ *
18
+ * @param ikm - The input keying material.
19
+ * @param salt - The salt to use.
20
+ * @param info - Context and application-specific information.
21
+ * @param keyLength - The desired key length in bytes.
22
+ * @param options - Additional configuration options.
23
+ * @returns The derived key material.
24
+ */
25
+ export async function hkdfSha384(ikm, salt, info, keyLength, options) {
26
+ return hkdf(ikm, 'SHA-384', salt, info, keyLength, options);
27
+ }
28
+ /**
29
+ * Derive key material using HKDF-SHA-512.
30
+ *
31
+ * @param ikm - The input keying material.
32
+ * @param salt - The salt to use.
33
+ * @param info - Context and application-specific information.
34
+ * @param keyLength - The desired key length in bytes.
35
+ * @param options - Additional configuration options.
36
+ * @returns The derived key material.
37
+ */
38
+ export async function hkdfSha512(ikm, salt, info, keyLength, options) {
39
+ return hkdf(ikm, 'SHA-512', salt, info, keyLength, options);
40
+ }
41
+ /**
42
+ * Derive key material using HKDF.
43
+ *
44
+ * @param ikm - The input keying material.
45
+ * @param hash - The hash function to use.
46
+ * @param salt - The salt to use.
47
+ * @param info - Context and application-specific information.
48
+ * @param keyLength - The desired key length in bytes.
49
+ * @param options - Additional configuration options.
50
+ * @returns The derived key material.
51
+ */
52
+ async function hkdf(ikm, hash, salt, info, keyLength, options = {}) {
53
+ if (ikm.byteLength === 0) {
54
+ throw new Error(`Unsafe input keying material length: IKM must not be zero bytes for HKDF-${hash}.`);
55
+ }
56
+ if (!options.unsafeInputKeyingMaterial && ikm.byteLength < MIN_IKM_LENGTH) {
57
+ throw new Error(`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\`.`);
58
+ }
59
+ const subtleKey = await globalThis.crypto.subtle.importKey('raw', ikm, { name: 'HKDF' }, false, ['deriveBits']);
60
+ const derivedBits = await globalThis.crypto.subtle.deriveBits({
61
+ name: 'HKDF',
62
+ hash,
63
+ salt,
64
+ info,
65
+ }, subtleKey, keyLength * 8);
66
+ return new Uint8Array(derivedBits);
67
+ }
68
+ //# sourceMappingURL=hkdf.js.map
@@ -0,0 +1 @@
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> {\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> {\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> {\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> {\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 ADDED
@@ -0,0 +1,35 @@
1
+ export type HmacOptions = {
2
+ /**
3
+ * Skip the minimum key length check. Using a key shorter than the hash
4
+ * output length reduces the effective security strength of HMAC (RFC 2104).
5
+ */
6
+ unsafeKeyLength?: boolean;
7
+ };
8
+ /**
9
+ * Compute the HMAC-SHA-256 of the given data using the given key.
10
+ *
11
+ * @param key - The key to use.
12
+ * @param data - The data to hash.
13
+ * @param options - Additional configuration options.
14
+ * @returns The HMAC-SHA-256 of the data.
15
+ */
16
+ export declare function hmacSha256(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array>;
17
+ /**
18
+ * Compute the HMAC-SHA-384 of the given data using the given key.
19
+ *
20
+ * @param key - The key to use.
21
+ * @param data - The data to hash.
22
+ * @param options - Additional configuration options.
23
+ * @returns The HMAC-SHA-384 of the data.
24
+ */
25
+ export declare function hmacSha384(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array>;
26
+ /**
27
+ * Compute the HMAC-SHA-512 of the given data using the given key.
28
+ *
29
+ * @param key - The key to use.
30
+ * @param data - The data to hash.
31
+ * @param options - Additional configuration options.
32
+ * @returns The HMAC-SHA-512 of the data.
33
+ */
34
+ export declare function hmacSha512(key: BufferSource, data: BufferSource, options?: HmacOptions): Promise<Uint8Array>;
35
+ //# sourceMappingURL=hmac.d.ts.map
@@ -0,0 +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,CAErB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,CAErB"}
package/dist/hmac.js ADDED
@@ -0,0 +1,60 @@
1
+ // https://datatracker.ietf.org/doc/html/rfc2104#section-3
2
+ const MIN_KEY_LENGTH = {
3
+ 'SHA-256': 32,
4
+ 'SHA-384': 48,
5
+ 'SHA-512': 64,
6
+ };
7
+ /**
8
+ * Compute the HMAC-SHA-256 of the given data using the given key.
9
+ *
10
+ * @param key - The key to use.
11
+ * @param data - The data to hash.
12
+ * @param options - Additional configuration options.
13
+ * @returns The HMAC-SHA-256 of the data.
14
+ */
15
+ export async function hmacSha256(key, data, options) {
16
+ return hmac(key, 'SHA-256', data, options);
17
+ }
18
+ /**
19
+ * Compute the HMAC-SHA-384 of the given data using the given key.
20
+ *
21
+ * @param key - The key to use.
22
+ * @param data - The data to hash.
23
+ * @param options - Additional configuration options.
24
+ * @returns The HMAC-SHA-384 of the data.
25
+ */
26
+ export async function hmacSha384(key, data, options) {
27
+ return hmac(key, 'SHA-384', data, options);
28
+ }
29
+ /**
30
+ * Compute the HMAC-SHA-512 of the given data using the given key.
31
+ *
32
+ * @param key - The key to use.
33
+ * @param data - The data to hash.
34
+ * @param options - Additional configuration options.
35
+ * @returns The HMAC-SHA-512 of the data.
36
+ */
37
+ export async function hmacSha512(key, data, options) {
38
+ return hmac(key, 'SHA-512', data, options);
39
+ }
40
+ /**
41
+ * Compute the HMAC-SHA of the given data using the given key.
42
+ *
43
+ * @param key - The key to use.
44
+ * @param hash - The hash to use.
45
+ * @param data - The data to hash.
46
+ * @param options - Additional configuration options..
47
+ * @returns The HMAC-SHA of the data.
48
+ */
49
+ async function hmac(key, hash, data, options = {}) {
50
+ if (key.byteLength === 0) {
51
+ throw new Error(`Unsafe key length: Key must not be zero bytes for HMAC-${hash}.`);
52
+ }
53
+ if (!options.unsafeKeyLength && key.byteLength < MIN_KEY_LENGTH[hash]) {
54
+ throw new Error(`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\`.`);
55
+ }
56
+ const subtleKey = await globalThis.crypto.subtle.importKey('raw', key, { name: 'HMAC', hash }, false, ['sign']);
57
+ const result = await globalThis.crypto.subtle.sign('HMAC', subtleKey, data);
58
+ return new Uint8Array(result);
59
+ }
60
+ //# sourceMappingURL=hmac.js.map
@@ -0,0 +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,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> {\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> {\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> {\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> {\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
@@ -1,8 +1,6 @@
1
- /**
2
- * Example function that returns a greeting for the given name.
3
- *
4
- * @param name - The name to greet.
5
- * @returns The greeting.
6
- */
7
- export default function greeter(name: string): string;
1
+ export * from './hkdf.js';
2
+ export * from './hmac.js';
3
+ export * from './pbkdf2.js';
4
+ export * from './sha.js';
5
+ export type * from './types.js';
8
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,mBAAmB,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,5 @@
1
- /**
2
- * Example function that returns a greeting for the given name.
3
- *
4
- * @param name - The name to greet.
5
- * @returns The greeting.
6
- */
7
- export default function greeter(name) {
8
- return `Hello, ${name}!`;
9
- }
1
+ export * from './hkdf.js';
2
+ export * from './hmac.js';
3
+ export * from './pbkdf2.js';
4
+ export * from './sha.js';
10
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC","sourcesContent":["export * from './hkdf.js';\nexport * from './hmac.js';\nexport * from './pbkdf2.js';\nexport * from './sha.js';\nexport type * from './types.js';\n"]}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Options for the PBKDF2 functions.
3
+ */
4
+ export type Pbkdf2Options = {
5
+ /**
6
+ * If `true`, the iteration count check is skipped. Disabling this check
7
+ * reduces the computational cost of brute-force attacks against the derived
8
+ * key.
9
+ */
10
+ unsafeIterations?: boolean;
11
+ };
12
+ /**
13
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
14
+ * The hash function used is SHA-256.
15
+ *
16
+ * @param password - The password to hash.
17
+ * @param salt - The salt to use.
18
+ * @param iterations - The number of iterations.
19
+ * @param keyLength - The desired key length in bytes.
20
+ * @param options - Additional configuration options.
21
+ * @returns The PBKDF2 of the password.
22
+ */
23
+ export declare function pbkdf2Sha256(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array>;
24
+ /**
25
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
26
+ * The hash function used is SHA-384.
27
+ *
28
+ * @param password - The password to hash.
29
+ * @param salt - The salt to use.
30
+ * @param iterations - The number of iterations.
31
+ * @param keyLength - The desired key length in bytes.
32
+ * @param options - Additional configuration options.
33
+ * @returns The PBKDF2 of the password.
34
+ */
35
+ export declare function pbkdf2Sha384(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array>;
36
+ /**
37
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
38
+ * The hash function used is SHA-512.
39
+ *
40
+ * @param password - The password to hash.
41
+ * @param salt - The salt to use.
42
+ * @param iterations - The number of iterations.
43
+ * @param keyLength - The desired key length in bytes.
44
+ * @param options - Additional configuration options.
45
+ * @returns The PBKDF2 of the password.
46
+ */
47
+ export declare function pbkdf2Sha512(password: BufferSource, salt: BufferSource, iterations: number, keyLength: number, options?: Pbkdf2Options): Promise<Uint8Array>;
48
+ //# sourceMappingURL=pbkdf2.d.ts.map
@@ -0,0 +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,CAErB;AAED;;;;;;;;;;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,CAErB;AAED;;;;;;;;;;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,CAErB"}
package/dist/pbkdf2.js ADDED
@@ -0,0 +1,78 @@
1
+ // https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
2
+ const MIN_ITERATIONS = {
3
+ 'SHA-256': 600_000,
4
+ // SHA-384 is not explicitly listed by OWASP; using the SHA-512 value since
5
+ // both variants use 64-bit words internally.
6
+ 'SHA-384': 220_000,
7
+ 'SHA-512': 220_000,
8
+ };
9
+ /**
10
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
11
+ * The hash function used is SHA-256.
12
+ *
13
+ * @param password - The password to hash.
14
+ * @param salt - The salt to use.
15
+ * @param iterations - The number of iterations.
16
+ * @param keyLength - The desired key length in bytes.
17
+ * @param options - Additional configuration options.
18
+ * @returns The PBKDF2 of the password.
19
+ */
20
+ export async function pbkdf2Sha256(password, salt, iterations, keyLength, options) {
21
+ return pbkdf2(password, salt, 'SHA-256', iterations, keyLength, options);
22
+ }
23
+ /**
24
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
25
+ * The hash function used is SHA-384.
26
+ *
27
+ * @param password - The password to hash.
28
+ * @param salt - The salt to use.
29
+ * @param iterations - The number of iterations.
30
+ * @param keyLength - The desired key length in bytes.
31
+ * @param options - Additional configuration options.
32
+ * @returns The PBKDF2 of the password.
33
+ */
34
+ export async function pbkdf2Sha384(password, salt, iterations, keyLength, options) {
35
+ return pbkdf2(password, salt, 'SHA-384', iterations, keyLength, options);
36
+ }
37
+ /**
38
+ * Compute the PBKDF2 of the given password, salt, iterations, and key length.
39
+ * The hash function used is SHA-512.
40
+ *
41
+ * @param password - The password to hash.
42
+ * @param salt - The salt to use.
43
+ * @param iterations - The number of iterations.
44
+ * @param keyLength - The desired key length in bytes.
45
+ * @param options - Additional configuration options.
46
+ * @returns The PBKDF2 of the password.
47
+ */
48
+ export async function pbkdf2Sha512(password, salt, iterations, keyLength, options) {
49
+ return pbkdf2(password, salt, 'SHA-512', iterations, keyLength, options);
50
+ }
51
+ /**
52
+ * Compute the PBKDF2 of the given password, salt, hash, iterations, and key length.
53
+ *
54
+ * @param password - The password to hash.
55
+ * @param salt - The salt to use.
56
+ * @param hash - The hashing function to use.
57
+ * @param iterations - The number of iterations.
58
+ * @param keyLength - The desired key length in bytes.
59
+ * @param options - Additional options.
60
+ * @returns The PBKDF2 of the password.
61
+ */
62
+ async function pbkdf2(password, salt, hash, iterations, keyLength, options) {
63
+ if (!options?.unsafeIterations && iterations < MIN_ITERATIONS[hash]) {
64
+ throw new Error(`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\`.`);
65
+ }
66
+ const key = await globalThis.crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveBits']);
67
+ const derivedBits = await globalThis.crypto.subtle.deriveBits({
68
+ name: 'PBKDF2',
69
+ salt,
70
+ iterations,
71
+ hash,
72
+ }, key,
73
+ // `keyLength` is the number of bytes, but `deriveBits` expects the
74
+ // number of bits, so we multiply by 8.
75
+ keyLength * 8);
76
+ return new Uint8Array(derivedBits);
77
+ }
78
+ //# sourceMappingURL=pbkdf2.js.map
@@ -0,0 +1 @@
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;;;;;;;;;;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;;;;;;;;;;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;;;;;;;;;;GAUG;AACH,KAAK,UAAU,MAAM,CACnB,QAAsB,EACtB,IAAkB,EAClB,IAAkB,EAClB,UAAkB,EAClB,SAAiB,EACjB,OAAuB;IAEvB,IAAI,CAAC,OAAO,EAAE,gBAAgB,IAAI,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,4DAA4D,cAAc,CAAC,IAAI,CAAC,eAAe,IAAI,0EAA0E,CAC9K,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAClD,KAAK,EACL,QAAQ,EACR,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAC3D;QACE,IAAI,EAAE,QAAQ;QACd,IAAI;QACJ,UAAU;QACV,IAAI;KACL,EACD,GAAG;IACH,mEAAmE;IACnE,uCAAuC;IACvC,SAAS,GAAG,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> {\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> {\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> {\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> {\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/sha.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Compute a SHA-256 digest for a given byte array.
3
+ *
4
+ * @param bytes - A byte array.
5
+ * @returns The SHA-256 hash as a byte array.
6
+ */
7
+ export declare function sha256(bytes: BufferSource): Promise<Uint8Array>;
8
+ /**
9
+ * Compute a SHA-384 digest for a given byte array.
10
+ *
11
+ * @param bytes - A byte array.
12
+ * @returns The SHA-384 hash as a byte array.
13
+ */
14
+ export declare function sha384(bytes: BufferSource): Promise<Uint8Array>;
15
+ /**
16
+ * Compute a SHA-512 digest for a given byte array.
17
+ *
18
+ * @param bytes - A byte array.
19
+ * @returns The SHA-512 hash as a byte array.
20
+ */
21
+ export declare function sha512(bytes: BufferSource): Promise<Uint8Array>;
22
+ //# sourceMappingURL=sha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha.d.ts","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAIrE;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAIrE;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAIrE"}
package/dist/sha.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Compute a SHA-256 digest for a given byte array.
3
+ *
4
+ * @param bytes - A byte array.
5
+ * @returns The SHA-256 hash as a byte array.
6
+ */
7
+ export async function sha256(bytes) {
8
+ return new Uint8Array(await globalThis.crypto.subtle.digest('SHA-256', bytes));
9
+ }
10
+ /**
11
+ * Compute a SHA-384 digest for a given byte array.
12
+ *
13
+ * @param bytes - A byte array.
14
+ * @returns The SHA-384 hash as a byte array.
15
+ */
16
+ export async function sha384(bytes) {
17
+ return new Uint8Array(await globalThis.crypto.subtle.digest('SHA-384', bytes));
18
+ }
19
+ /**
20
+ * Compute a SHA-512 digest for a given byte array.
21
+ *
22
+ * @param bytes - A byte array.
23
+ * @returns The SHA-512 hash as a byte array.
24
+ */
25
+ export async function sha512(bytes) {
26
+ return new Uint8Array(await globalThis.crypto.subtle.digest('SHA-512', bytes));
27
+ }
28
+ //# sourceMappingURL=sha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAmB;IAC9C,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,CAAC,KAAmB;IAC9C,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,CAAC,KAAmB;IAC9C,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(bytes: BufferSource): Promise<Uint8Array> {\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(bytes: BufferSource): Promise<Uint8Array> {\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(bytes: BufferSource): Promise<Uint8Array> {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-512', bytes),\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export type HashFunction = 'SHA-256' | 'SHA-384' | 'SHA-512';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/cryptography",
3
- "version": "0.0.0-preview-0a1dd02ad",
3
+ "version": "0.0.0-preview-c4789fdf4",
4
4
  "description": "Provides optimized versions of commonly used cryptography functions for MetaMask clients",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -50,14 +50,15 @@
50
50
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
51
51
  },
52
52
  "devDependencies": {
53
- "@metamask/auto-changelog": "^6.1.0",
53
+ "@metamask/auto-changelog": "^6.2.1",
54
+ "@metamask/utils": "^12.0.0",
54
55
  "@types/jest": "^30.0.0",
55
56
  "@typescript/native": "npm:typescript@^7.0.2",
56
- "deepmerge": "^4.2.2",
57
+ "deepmerge": "^4.3.1",
57
58
  "jest": "^30.4.2",
58
- "rimraf": "^5.0.5",
59
- "ts-jest": "^29.4.11",
60
- "tsx": "^4.20.5",
59
+ "rimraf": "^6.1.3",
60
+ "ts-jest": "^29.4.12",
61
+ "tsx": "^4.23.15",
61
62
  "typedoc": "^0.25.13",
62
63
  "typedoc-plugin-missing-exports": "^2.0.0",
63
64
  "typescript": "npm:@typescript/typescript6@^6.0.2"