@metamask-previews/seedless-onboarding-controller 3.0.0-preview-e821953d → 3.0.0-preview-e43ca14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { base64ToBytes } from "@metamask/utils";
1
+ import { base64ToBytes, bigIntToHex, bytesToBase64, hexToBigInt } from "@metamask/utils";
2
2
  import { bytesToUtf8 } from "@noble/ciphers/utils";
3
3
  /**
4
4
  * Decode the node auth token from base64 to json object.
@@ -28,4 +28,65 @@ export function decodeJWTToken(token) {
28
28
  const decoded = JSON.parse(bytesToUtf8(base64ToBytes(paddedPayload)));
29
29
  return decoded;
30
30
  }
31
+ /**
32
+ * Serialize the vault data.
33
+ *
34
+ * @param data - The vault data to serialize.
35
+ * @returns The serialized vault data.
36
+ */
37
+ export function serializeVaultData(data) {
38
+ const toprfEncryptionKey = bytesToBase64(data.toprfEncryptionKey);
39
+ const toprfPwEncryptionKey = bytesToBase64(data.toprfPwEncryptionKey);
40
+ const toprfAuthKeyPair = serializeToprfAuthKeyPair(data.toprfAuthKeyPair);
41
+ return JSON.stringify({
42
+ toprfEncryptionKey,
43
+ toprfPwEncryptionKey,
44
+ toprfAuthKeyPair,
45
+ revokeToken: data.revokeToken,
46
+ accessToken: data.accessToken,
47
+ });
48
+ }
49
+ /**
50
+ * Deserialize the vault data.
51
+ *
52
+ * @param value - The stringified vault data.
53
+ * @returns The deserialized vault data.
54
+ */
55
+ export function deserializeVaultData(value) {
56
+ const toprfEncryptionKey = base64ToBytes(value.toprfEncryptionKey);
57
+ const toprfPwEncryptionKey = base64ToBytes(value.toprfPwEncryptionKey);
58
+ const toprfAuthKeyPair = deserializeAuthKeyPair(value.toprfAuthKeyPair);
59
+ return {
60
+ ...value,
61
+ toprfEncryptionKey,
62
+ toprfPwEncryptionKey,
63
+ toprfAuthKeyPair,
64
+ };
65
+ }
66
+ /**
67
+ * Serialize TOPRF authentication key pair.
68
+ *
69
+ * @param keyPair - The authentication key pair to serialize.
70
+ * @returns The serialized authentication key pair.
71
+ */
72
+ export function serializeToprfAuthKeyPair(keyPair) {
73
+ const b64EncodedAuthKeyPair = JSON.stringify({
74
+ sk: bigIntToHex(keyPair.sk),
75
+ pk: bytesToBase64(keyPair.pk),
76
+ });
77
+ return b64EncodedAuthKeyPair;
78
+ }
79
+ /**
80
+ * Deserialize the authentication key pair.
81
+ *
82
+ * @param value - The stringified authentication key pair.
83
+ * @returns The deserialized authentication key pair.
84
+ */
85
+ export function deserializeAuthKeyPair(value) {
86
+ const parsedKeyPair = JSON.parse(value);
87
+ return {
88
+ sk: hexToBigInt(parsedKeyPair.sk),
89
+ pk: base64ToBytes(parsedKeyPair.pk),
90
+ };
91
+ }
31
92
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAChD,OAAO,EAAE,WAAW,EAAE,6BAA6B;AAInD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,sEAAsE;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;KAC7C;IAED,mCAAmC;IACnC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,4CAA4C;IAC5C,MAAM,aAAa,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACtE,OAAO,OAA8B,CAAC;AACxC,CAAC","sourcesContent":["import { base64ToBytes } from '@metamask/utils';\nimport { bytesToUtf8 } from '@noble/ciphers/utils';\n\nimport type { DecodedBaseJWTToken, DecodedNodeAuthToken } from './types';\n\n/**\n * Decode the node auth token from base64 to json object.\n *\n * @param token - The node auth token to decode.\n * @returns The decoded node auth token.\n */\nexport function decodeNodeAuthToken(token: string): DecodedNodeAuthToken {\n return JSON.parse(bytesToUtf8(base64ToBytes(token)));\n}\n\n/**\n * Decode JWT token\n *\n * @param token - The JWT token to decode.\n * @returns The decoded JWT token.\n */\nexport function decodeJWTToken(token: string): DecodedBaseJWTToken {\n // JWT tokens have 3 parts separated by dots: header.payload.signature\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw new Error('Invalid JWT token format');\n }\n\n // Decode the payload (second part)\n const payload = parts[1];\n // Add padding if needed for base64 decoding\n const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);\n const decoded = JSON.parse(bytesToUtf8(base64ToBytes(paddedPayload)));\n return decoded as DecodedBaseJWTToken;\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACZ,wBAAwB;AACzB,OAAO,EAAE,WAAW,EAAE,6BAA6B;AASnD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;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B,GAAG,sBAAsB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAExE,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB;QAClB,oBAAoB;QACpB,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,qBAAqB,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3C,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,EAAE,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;QACjC,EAAE,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { KeyPair } from '@metamask/toprf-secure-backup';\nimport {\n base64ToBytes,\n bigIntToHex,\n bytesToBase64,\n hexToBigInt,\n} from '@metamask/utils';\nimport { bytesToUtf8 } from '@noble/ciphers/utils';\n\nimport type {\n DecodedBaseJWTToken,\n DecodedNodeAuthToken,\n DeserializedVaultData,\n VaultData,\n} from './types';\n\n/**\n * Decode the node auth token from base64 to json object.\n *\n * @param token - The node auth token to decode.\n * @returns The decoded node auth token.\n */\nexport function decodeNodeAuthToken(token: string): DecodedNodeAuthToken {\n return JSON.parse(bytesToUtf8(base64ToBytes(token)));\n}\n\n/**\n * Decode JWT token\n *\n * @param token - The JWT token to decode.\n * @returns The decoded JWT token.\n */\nexport function decodeJWTToken(token: string): DecodedBaseJWTToken {\n // JWT tokens have 3 parts separated by dots: header.payload.signature\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw new Error('Invalid JWT token format');\n }\n\n // Decode the payload (second part)\n const payload = parts[1];\n // Add padding if needed for base64 decoding\n const paddedPayload = payload + '='.repeat((4 - (payload.length % 4)) % 4);\n const decoded = JSON.parse(bytesToUtf8(base64ToBytes(paddedPayload)));\n return decoded as DecodedBaseJWTToken;\n}\n\n/**\n * Serialize the vault data.\n *\n * @param data - The vault data to serialize.\n * @returns The serialized vault data.\n */\nexport function serializeVaultData(data: DeserializedVaultData): string {\n const toprfEncryptionKey = bytesToBase64(data.toprfEncryptionKey);\n const toprfPwEncryptionKey = bytesToBase64(data.toprfPwEncryptionKey);\n const toprfAuthKeyPair = serializeToprfAuthKeyPair(data.toprfAuthKeyPair);\n\n return JSON.stringify({\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n revokeToken: data.revokeToken,\n accessToken: data.accessToken,\n });\n}\n\n/**\n * Deserialize the vault data.\n *\n * @param value - The stringified vault data.\n * @returns The deserialized vault data.\n */\nexport function deserializeVaultData(value: VaultData): DeserializedVaultData {\n const toprfEncryptionKey = base64ToBytes(value.toprfEncryptionKey);\n const toprfPwEncryptionKey = base64ToBytes(value.toprfPwEncryptionKey);\n const toprfAuthKeyPair = deserializeAuthKeyPair(value.toprfAuthKeyPair);\n\n return {\n ...value,\n toprfEncryptionKey,\n toprfPwEncryptionKey,\n toprfAuthKeyPair,\n };\n}\n\n/**\n * Serialize TOPRF authentication key pair.\n *\n * @param keyPair - The authentication key pair to serialize.\n * @returns The serialized authentication key pair.\n */\nexport function serializeToprfAuthKeyPair(keyPair: KeyPair): string {\n const b64EncodedAuthKeyPair = JSON.stringify({\n sk: bigIntToHex(keyPair.sk), // Convert BigInt to hex string\n pk: bytesToBase64(keyPair.pk),\n });\n\n return b64EncodedAuthKeyPair;\n}\n\n/**\n * Deserialize the authentication key pair.\n *\n * @param value - The stringified authentication key pair.\n * @returns The deserialized authentication key pair.\n */\nexport function deserializeAuthKeyPair(value: string): KeyPair {\n const parsedKeyPair = JSON.parse(value);\n return {\n sk: hexToBigInt(parsedKeyPair.sk),\n pk: base64ToBytes(parsedKeyPair.pk),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/seedless-onboarding-controller",
3
- "version": "3.0.0-preview-e821953d",
3
+ "version": "3.0.0-preview-e43ca14",
4
4
  "description": "Backup and rehydrate SRP(s) using social login and password",
5
5
  "keywords": [
6
6
  "MetaMask",