@metamask-previews/cryptography 1.1.0-preview-1a7a6d6d6 → 1.1.2-preview-1d9e239b6

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,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.2]
11
+
12
+ ### Fixed
13
+
14
+ - Only pass `additionalData` to AES-GCM `encrypt` and `decrypt` when it is provided, as browsers such as Chrome reject `additionalData: undefined` ([#10757](https://github.com/MetaMask/core/pull/10757))
15
+
16
+ ## [1.1.1]
17
+
10
18
  ### Fixed
11
19
 
12
20
  - Export AES-GCM IV length ([#10654](https://github.com/MetaMask/core/pull/10654))
@@ -36,6 +44,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
36
44
  - Add `encrypt` and `decrypt` functions for AES-GCM symmetric encryption exported via `@metamask/cryptography/aes-gcm`
37
45
  - Add `getRandomBytes` function for generating cryptographically secure random bytes
38
46
 
39
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.1.0...HEAD
47
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.1.2...HEAD
48
+ [1.1.2]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.1.1...@metamask/cryptography@1.1.2
49
+ [1.1.1]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.1.0...@metamask/cryptography@1.1.1
40
50
  [1.1.0]: https://github.com/MetaMask/core/compare/@metamask/cryptography@1.0.0...@metamask/cryptography@1.1.0
41
51
  [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/cryptography@1.0.0
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,MAAM,MAAM,oB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,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,CA6C9B;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,CA2ClC"}
package/dist/aes-gcm.js CHANGED
@@ -27,7 +27,11 @@ export async function encrypt(key, plaintext, options) {
27
27
  {
28
28
  name: 'AES-GCM',
29
29
  iv,
30
- additionalData: options?.additionalData && toUint8Array(options.additionalData),
30
+ // Browsers such as Chrome reject `additionalData: undefined`, so only set
31
+ // the key when there is associated data.
32
+ ...(options?.additionalData && {
33
+ additionalData: toUint8Array(options.additionalData),
34
+ }),
31
35
  }, subtleKey, toUint8Array(plaintext));
32
36
  return { ciphertext: new Uint8Array(ciphertext), iv };
33
37
  }
@@ -56,7 +60,11 @@ export async function decrypt(key, iv, ciphertext, options) {
56
60
  {
57
61
  name: 'AES-GCM',
58
62
  iv: toUint8Array(iv),
59
- additionalData: options?.additionalData && toUint8Array(options.additionalData),
63
+ // Browsers such as Chrome reject `additionalData: undefined`, so only set
64
+ // the key when there is associated data.
65
+ ...(options?.additionalData && {
66
+ additionalData: toUint8Array(options.additionalData),
67
+ }),
60
68
  }, subtleKey, toUint8Array(ciphertext));
61
69
  return new Uint8Array(plaintext);
62
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C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O,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,SAAS,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CACb,wCAAwC,SAAS,0FAA0F,CAC5I,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;QACE,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC;QACpB,cAAc,EACZ,OAAO,EAAE,cAAc,IAAI,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC;KAClE,EACD,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\nexport const 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 * Associated data authenticated with the ciphertext but not encrypted.\n * Encryption and decryption must use the same value.\n */\n additionalData?: BufferSource;\n\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(options?.unsafeIv ?? getRandomBytes(IV_LENGTH));\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 !== IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${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 {\n name: 'AES-GCM',\n iv,\n additionalData:\n options?.additionalData && toUint8Array(options.additionalData),\n },\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 !== IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${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 {\n name: 'AES-GCM',\n iv: toUint8Array(iv),\n additionalData:\n options?.additionalData && toUint8Array(options.additionalData),\n },\n subtleKey,\n toUint8Array(ciphertext),\n );\n\n return new Uint8Array(plaintext);\n}\n"]}
1
+ {"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,qDAAqD;AACrD,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AA8B5B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAiB,EACjB,SAAuB,EACvB,OAA8B;IAE9B,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IAED,MAA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CAAC;QACxB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,cAAc,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CACb,wCAAwC,SAAS,0FAA0F,CAC5I,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;QACE,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC;QACpB,0EAA0E;QAC1E,yCAAyC;QACzC,GAAG,CAAC,OAAO,EAAE,cAAc,IAAI;YAC7B,cAAc,EAAE,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC;SACrD,CAAC;KACH,EACD,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\nexport const 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 * Associated data authenticated with the ciphertext but not encrypted.\n * Encryption and decryption must use the same value.\n */\n additionalData?: BufferSource;\n\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(options?.unsafeIv ?? getRandomBytes(IV_LENGTH));\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 !== IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${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 {\n name: 'AES-GCM',\n iv,\n // Browsers such as Chrome reject `additionalData: undefined`, so only set\n // the key when there is associated data.\n ...(options?.additionalData && {\n additionalData: toUint8Array(options.additionalData),\n }),\n },\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 !== IV_LENGTH) {\n throw new Error(\n `Unsafe IV length: IV must be exactly ${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 {\n name: 'AES-GCM',\n iv: toUint8Array(iv),\n // Browsers such as Chrome reject `additionalData: undefined`, so only set\n // the key when there is associated data.\n ...(options?.additionalData && {\n additionalData: toUint8Array(options.additionalData),\n }),\n },\n subtleKey,\n toUint8Array(ciphertext),\n );\n\n return new Uint8Array(plaintext);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/cryptography",
3
- "version": "1.1.0-preview-1a7a6d6d6",
3
+ "version": "1.1.2-preview-1d9e239b6",
4
4
  "description": "Provides optimized versions of commonly used cryptography functions for MetaMask clients",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -87,7 +87,7 @@
87
87
  "rimraf": "^6.1.3",
88
88
  "ts-jest": "^29.4.14",
89
89
  "typedoc": "^0.28.20",
90
- "typedoc-plugin-missing-exports": "^2.0.0",
90
+ "typedoc-plugin-missing-exports": "^4.1.4",
91
91
  "typescript": "npm:@typescript/typescript6@^6.0.2"
92
92
  },
93
93
  "engines": {