@metamask-previews/kyc-controller 0.0.0-preview-e68ab1498 → 0.0.0-preview-4b37525

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/KycController-method-action-types.cjs.map +1 -1
  3. package/dist/KycController-method-action-types.d.cts +12 -6
  4. package/dist/KycController-method-action-types.d.cts.map +1 -1
  5. package/dist/KycController-method-action-types.d.mts +12 -6
  6. package/dist/KycController-method-action-types.d.mts.map +1 -1
  7. package/dist/KycController-method-action-types.mjs.map +1 -1
  8. package/dist/KycController.cjs +313 -72
  9. package/dist/KycController.cjs.map +1 -1
  10. package/dist/KycController.d.cts +27 -7
  11. package/dist/KycController.d.cts.map +1 -1
  12. package/dist/KycController.d.mts +27 -7
  13. package/dist/KycController.d.mts.map +1 -1
  14. package/dist/KycController.mjs +314 -73
  15. package/dist/KycController.mjs.map +1 -1
  16. package/dist/KycService-method-action-types.cjs.map +1 -1
  17. package/dist/KycService-method-action-types.d.cts +60 -31
  18. package/dist/KycService-method-action-types.d.cts.map +1 -1
  19. package/dist/KycService-method-action-types.d.mts +60 -31
  20. package/dist/KycService-method-action-types.d.mts.map +1 -1
  21. package/dist/KycService-method-action-types.mjs.map +1 -1
  22. package/dist/KycService.cjs +140 -75
  23. package/dist/KycService.cjs.map +1 -1
  24. package/dist/KycService.d.cts +181 -74
  25. package/dist/KycService.d.cts.map +1 -1
  26. package/dist/KycService.d.mts +181 -74
  27. package/dist/KycService.d.mts.map +1 -1
  28. package/dist/KycService.mjs +140 -75
  29. package/dist/KycService.mjs.map +1 -1
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +3 -3
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.mts +3 -3
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/types.cjs.map +1 -1
  37. package/dist/types.d.cts +49 -4
  38. package/dist/types.d.cts.map +1 -1
  39. package/dist/types.d.mts +49 -4
  40. package/dist/types.d.mts.map +1 -1
  41. package/dist/types.mjs.map +1 -1
  42. package/dist/ukyc/jwtChain.cjs +1 -1
  43. package/dist/ukyc/jwtChain.cjs.map +1 -1
  44. package/dist/ukyc/jwtChain.d.cts +2 -2
  45. package/dist/ukyc/jwtChain.d.mts +2 -2
  46. package/dist/ukyc/jwtChain.mjs +1 -1
  47. package/dist/ukyc/jwtChain.mjs.map +1 -1
  48. package/dist/ukyc/wrapEncryptionKey.cjs +16 -7
  49. package/dist/ukyc/wrapEncryptionKey.cjs.map +1 -1
  50. package/dist/ukyc/wrapEncryptionKey.d.cts +23 -16
  51. package/dist/ukyc/wrapEncryptionKey.d.cts.map +1 -1
  52. package/dist/ukyc/wrapEncryptionKey.d.mts +23 -16
  53. package/dist/ukyc/wrapEncryptionKey.d.mts.map +1 -1
  54. package/dist/ukyc/wrapEncryptionKey.mjs +16 -7
  55. package/dist/ukyc/wrapEncryptionKey.mjs.map +1 -1
  56. package/package.json +1 -1
@@ -1,34 +1,41 @@
1
1
  /**
2
- * Wraps the `data_encryption_key` for the UKYC session server using NaCl's
3
- * `crypto_box` (X25519 + XSalsa20-Poly1305) established with the server's
4
- * per-session wrapping key.
2
+ * Wraps a secret for the UKYC session server using NaCl's `crypto_box`
3
+ * (X25519 + XSalsa20-Poly1305) established with a per-secret wrapping key
4
+ * returned inside an encryption schema from `createUkycSession`.
5
5
  *
6
6
  * Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per
7
- * call), this uses the session client keypair whose public half was already
8
- * handed to the server via `POST /wrapping-key`. The server therefore already
9
- * knows our public key and can derive the same shared secret from its session
10
- * private key, so only `{ encryptedKey, nonce }` need be transmitted.
7
+ * call), this reuses a session client keypair. There is no prior wrapping-key
8
+ * exchange to register that public key, so `data` is
9
+ * `clientPublicKey (32) || ciphertext+tag` and only `{ data, nonce }` need be
10
+ * transmitted. Used for both the `data_encryption_key` and the
11
+ * `ukyc_capability_token`.
11
12
  */
12
13
  /**
13
- * The transmitted portion of a wrapped encryption key: the `crypto_box`
14
- * ciphertext (which includes the 16-byte Poly1305 auth tag) and the nonce,
15
- * both unpadded base64url-encoded.
14
+ * The transmitted portion of a wrapped secret: the sender public key prefixed
15
+ * to the `crypto_box` ciphertext (which includes the 16-byte Poly1305 auth
16
+ * tag), and the nonce, both unpadded base64url-encoded. Matches the KYC API
17
+ * `CapabilityAuthorization` wire shape.
16
18
  */
17
19
  export type WrappedEncryptionKeyParts = {
18
- encryptedKey: string;
20
+ data: string;
19
21
  nonce: string;
20
22
  };
21
23
  /**
22
- * Wraps `keyToWrap` for the UKYC session server.
24
+ * Wraps `plaintext` for the UKYC session server.
23
25
  *
24
26
  * The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret
25
27
  * between our session client private key and the session server public key
26
- * returned by `getWrappingKey`.
28
+ * from an encryption schema (`encryptionDataKey` or `ukycCapabilityToken`)
29
+ * returned by `createUkycSession`. The 32-byte client public key is prefixed
30
+ * onto `data` so the server can open the box without a prior key-registration
31
+ * step.
27
32
  *
28
33
  * @param sessionClientPrivateKey - Our session's X25519 private key.
29
34
  * @param sessionServerPublicKey - The server's X25519 public key (base64url).
30
- * @param keyToWrap - The raw symmetric key bytes to encrypt.
31
- * @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.
35
+ * @param plaintext - The raw bytes to encrypt (e.g. the `data_encryption_key`
36
+ * or the encoded `ukyc_capability_token`).
37
+ * @returns The base64url `data` (`clientPublicKey || ciphertext+tag`) and
38
+ * `nonce`.
32
39
  */
33
- export declare function wrapEncryptionKey(sessionClientPrivateKey: Uint8Array, sessionServerPublicKey: string, keyToWrap: Uint8Array): WrappedEncryptionKeyParts;
40
+ export declare function wrapEncryptionKey(sessionClientPrivateKey: Uint8Array, sessionServerPublicKey: string, plaintext: Uint8Array): WrappedEncryptionKeyParts;
34
41
  //# sourceMappingURL=wrapEncryptionKey.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrapEncryptionKey.d.mts","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,uBAAuB,EAAE,UAAU,EACnC,sBAAsB,EAAE,MAAM,EAC9B,SAAS,EAAE,UAAU,GACpB,yBAAyB,CAa3B"}
1
+ {"version":3,"file":"wrapEncryptionKey.d.mts","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,uBAAuB,EAAE,UAAU,EACnC,sBAAsB,EAAE,MAAM,EAC9B,SAAS,EAAE,UAAU,GACpB,yBAAyB,CAmB3B"}
@@ -2,23 +2,32 @@ import $tweetnacl from "tweetnacl";
2
2
  const { randomBytes, box } = $tweetnacl;
3
3
  import { base64UrlToBytes, toBase64Url } from "../encoding.mjs";
4
4
  /**
5
- * Wraps `keyToWrap` for the UKYC session server.
5
+ * Wraps `plaintext` for the UKYC session server.
6
6
  *
7
7
  * The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret
8
8
  * between our session client private key and the session server public key
9
- * returned by `getWrappingKey`.
9
+ * from an encryption schema (`encryptionDataKey` or `ukycCapabilityToken`)
10
+ * returned by `createUkycSession`. The 32-byte client public key is prefixed
11
+ * onto `data` so the server can open the box without a prior key-registration
12
+ * step.
10
13
  *
11
14
  * @param sessionClientPrivateKey - Our session's X25519 private key.
12
15
  * @param sessionServerPublicKey - The server's X25519 public key (base64url).
13
- * @param keyToWrap - The raw symmetric key bytes to encrypt.
14
- * @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.
16
+ * @param plaintext - The raw bytes to encrypt (e.g. the `data_encryption_key`
17
+ * or the encoded `ukyc_capability_token`).
18
+ * @returns The base64url `data` (`clientPublicKey || ciphertext+tag`) and
19
+ * `nonce`.
15
20
  */
16
- export function wrapEncryptionKey(sessionClientPrivateKey, sessionServerPublicKey, keyToWrap) {
21
+ export function wrapEncryptionKey(sessionClientPrivateKey, sessionServerPublicKey, plaintext) {
17
22
  const serverPublicKey = base64UrlToBytes(sessionServerPublicKey);
23
+ const { publicKey: clientPublicKey } = box.keyPair.fromSecretKey(sessionClientPrivateKey);
18
24
  const nonce = randomBytes(box.nonceLength);
19
- const encryptedKey = box(keyToWrap, nonce, serverPublicKey, sessionClientPrivateKey);
25
+ const ciphertext = box(plaintext, nonce, serverPublicKey, sessionClientPrivateKey);
26
+ const data = new Uint8Array(clientPublicKey.length + ciphertext.length);
27
+ data.set(clientPublicKey, 0);
28
+ data.set(ciphertext, clientPublicKey.length);
20
29
  return {
21
- encryptedKey: toBase64Url(encryptedKey),
30
+ data: toBase64Url(data),
22
31
  nonce: toBase64Url(nonce),
23
32
  };
24
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wrapEncryptionKey.mjs","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,wBAAuB;AAwB/D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAC/B,uBAAmC,EACnC,sBAA8B,EAC9B,SAAqB;IAErB,MAAM,eAAe,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,GAAG,CACtB,SAAS,EACT,KAAK,EACL,eAAe,EACf,uBAAuB,CACxB,CAAC;IACF,OAAO;QACL,YAAY,EAAE,WAAW,CAAC,YAAY,CAAC;QACvC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import { randomBytes, box } from 'tweetnacl';\n\nimport { base64UrlToBytes, toBase64Url } from '../encoding.js';\n\n/**\n * Wraps the `data_encryption_key` for the UKYC session server using NaCl's\n * `crypto_box` (X25519 + XSalsa20-Poly1305) established with the server's\n * per-session wrapping key.\n *\n * Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per\n * call), this uses the session client keypair whose public half was already\n * handed to the server via `POST /wrapping-key`. The server therefore already\n * knows our public key and can derive the same shared secret from its session\n * private key, so only `{ encryptedKey, nonce }` need be transmitted.\n */\n\n/**\n * The transmitted portion of a wrapped encryption key: the `crypto_box`\n * ciphertext (which includes the 16-byte Poly1305 auth tag) and the nonce,\n * both unpadded base64url-encoded.\n */\nexport type WrappedEncryptionKeyParts = {\n encryptedKey: string;\n nonce: string;\n};\n\n/**\n * Wraps `keyToWrap` for the UKYC session server.\n *\n * The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret\n * between our session client private key and the session server public key\n * returned by `getWrappingKey`.\n *\n * @param sessionClientPrivateKey - Our session's X25519 private key.\n * @param sessionServerPublicKey - The server's X25519 public key (base64url).\n * @param keyToWrap - The raw symmetric key bytes to encrypt.\n * @returns The base64url `encryptedKey` (ciphertext + tag) and `nonce`.\n */\nexport function wrapEncryptionKey(\n sessionClientPrivateKey: Uint8Array,\n sessionServerPublicKey: string,\n keyToWrap: Uint8Array,\n): WrappedEncryptionKeyParts {\n const serverPublicKey = base64UrlToBytes(sessionServerPublicKey);\n const nonce = randomBytes(box.nonceLength);\n const encryptedKey = box(\n keyToWrap,\n nonce,\n serverPublicKey,\n sessionClientPrivateKey,\n );\n return {\n encryptedKey: toBase64Url(encryptedKey),\n nonce: toBase64Url(nonce),\n };\n}\n"]}
1
+ {"version":3,"file":"wrapEncryptionKey.mjs","sourceRoot":"","sources":["../../src/ukyc/wrapEncryptionKey.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,wBAAuB;AA0B/D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,uBAAmC,EACnC,sBAA8B,EAC9B,SAAqB;IAErB,MAAM,eAAe,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACjE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAC9D,uBAAuB,CACxB,CAAC;IACF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,GAAG,CACpB,SAAS,EACT,KAAK,EACL,eAAe,EACf,uBAAuB,CACxB,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,eAAe,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACxE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC;QACvB,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import { randomBytes, box } from 'tweetnacl';\n\nimport { base64UrlToBytes, toBase64Url } from '../encoding.js';\n\n/**\n * Wraps a secret for the UKYC session server using NaCl's `crypto_box`\n * (X25519 + XSalsa20-Poly1305) established with a per-secret wrapping key\n * returned inside an encryption schema from `createUkycSession`.\n *\n * Unlike {@link wrapUserKey} (which generates a fresh ephemeral keypair per\n * call), this reuses a session client keypair. There is no prior wrapping-key\n * exchange to register that public key, so `data` is\n * `clientPublicKey (32) || ciphertext+tag` and only `{ data, nonce }` need be\n * transmitted. Used for both the `data_encryption_key` and the\n * `ukyc_capability_token`.\n */\n\n/**\n * The transmitted portion of a wrapped secret: the sender public key prefixed\n * to the `crypto_box` ciphertext (which includes the 16-byte Poly1305 auth\n * tag), and the nonce, both unpadded base64url-encoded. Matches the KYC API\n * `CapabilityAuthorization` wire shape.\n */\nexport type WrappedEncryptionKeyParts = {\n data: string;\n nonce: string;\n};\n\n/**\n * Wraps `plaintext` for the UKYC session server.\n *\n * The box is sealed with NaCl's `crypto_box`, keyed by the X25519 shared secret\n * between our session client private key and the session server public key\n * from an encryption schema (`encryptionDataKey` or `ukycCapabilityToken`)\n * returned by `createUkycSession`. The 32-byte client public key is prefixed\n * onto `data` so the server can open the box without a prior key-registration\n * step.\n *\n * @param sessionClientPrivateKey - Our session's X25519 private key.\n * @param sessionServerPublicKey - The server's X25519 public key (base64url).\n * @param plaintext - The raw bytes to encrypt (e.g. the `data_encryption_key`\n * or the encoded `ukyc_capability_token`).\n * @returns The base64url `data` (`clientPublicKey || ciphertext+tag`) and\n * `nonce`.\n */\nexport function wrapEncryptionKey(\n sessionClientPrivateKey: Uint8Array,\n sessionServerPublicKey: string,\n plaintext: Uint8Array,\n): WrappedEncryptionKeyParts {\n const serverPublicKey = base64UrlToBytes(sessionServerPublicKey);\n const { publicKey: clientPublicKey } = box.keyPair.fromSecretKey(\n sessionClientPrivateKey,\n );\n const nonce = randomBytes(box.nonceLength);\n const ciphertext = box(\n plaintext,\n nonce,\n serverPublicKey,\n sessionClientPrivateKey,\n );\n const data = new Uint8Array(clientPublicKey.length + ciphertext.length);\n data.set(clientPublicKey, 0);\n data.set(ciphertext, clientPublicKey.length);\n return {\n data: toBase64Url(data),\n nonce: toBase64Url(nonce),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/kyc-controller",
3
- "version": "0.0.0-preview-e68ab1498",
3
+ "version": "0.0.0-preview-4b37525",
4
4
  "description": "Shared KYC / identity verification controller used across MetaMask clients",
5
5
  "keywords": [
6
6
  "Ethereum",