@metamask/profile-sync-controller 0.3.0 → 0.5.0
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 +25 -1
- package/dist/{chunk-NSSHFDIS.mjs → chunk-2VEMA6OE.mjs} +2 -2
- package/dist/{chunk-HMRRB4EX.js → chunk-4LMFZDL4.js} +22 -13
- package/dist/chunk-4LMFZDL4.js.map +1 -0
- package/dist/{chunk-JJ5BDCKD.js → chunk-4TMLEABQ.js} +18 -16
- package/dist/chunk-4TMLEABQ.js.map +1 -0
- package/dist/{chunk-EYZFHZR2.js → chunk-5MQUI24U.js} +3 -3
- package/dist/{chunk-QU4EXKJO.mjs → chunk-6DAK2U35.mjs} +2 -2
- package/dist/{chunk-LYDHYB6I.mjs → chunk-76NMME23.mjs} +20 -11
- package/dist/chunk-76NMME23.mjs.map +1 -0
- package/dist/{chunk-T3FNDVE3.js → chunk-BKQE7DB5.js} +30 -18
- package/dist/chunk-BKQE7DB5.js.map +1 -0
- package/dist/{chunk-K5UKU454.mjs → chunk-COBJUBZE.mjs} +31 -19
- package/dist/chunk-COBJUBZE.mjs.map +1 -0
- package/dist/{chunk-5TOWF6UW.mjs → chunk-KHASG4H3.mjs} +2 -2
- package/dist/{chunk-4WXZXVLI.mjs → chunk-M7AUA5W7.mjs} +10 -8
- package/dist/{chunk-4WXZXVLI.mjs.map → chunk-M7AUA5W7.mjs.map} +1 -1
- package/dist/{chunk-E7Z5TCQT.mjs → chunk-MK7ABX2V.mjs} +5 -5
- package/dist/{chunk-E7Z5TCQT.mjs.map → chunk-MK7ABX2V.mjs.map} +1 -1
- package/dist/{chunk-ZYYAQJ56.mjs → chunk-NEBLEB3X.mjs} +19 -15
- package/dist/chunk-NEBLEB3X.mjs.map +1 -0
- package/dist/{chunk-AK7OTIWA.js → chunk-NIUQ34PY.js} +3 -3
- package/dist/{chunk-M23ZCTKE.mjs → chunk-OLFO6R7Z.mjs} +55 -20
- package/dist/chunk-OLFO6R7Z.mjs.map +1 -0
- package/dist/{chunk-LNECIW4K.js → chunk-PQMPSEVJ.js} +59 -24
- package/dist/chunk-PQMPSEVJ.js.map +1 -0
- package/dist/{chunk-YKOMKXG4.mjs → chunk-PU7MAIST.mjs} +13 -4
- package/dist/chunk-PU7MAIST.mjs.map +1 -0
- package/dist/{chunk-PQ5T4GHY.js → chunk-QCQU4BQL.js} +15 -2
- package/dist/chunk-QCQU4BQL.js.map +1 -0
- package/dist/{chunk-J7NSK6BO.mjs → chunk-TP7SP3AG.mjs} +2 -2
- package/dist/{chunk-4ZGRRVMI.js → chunk-UEHMUVQQ.js} +4 -4
- package/dist/{chunk-5EBUFNAN.mjs → chunk-UEWCUBMX.mjs} +14 -1
- package/dist/chunk-UEWCUBMX.mjs.map +1 -0
- package/dist/chunk-UHX7HJAI.js +11 -0
- package/dist/{chunk-ZMQRPWJN.js → chunk-UIRAMHNM.js} +12 -12
- package/dist/chunk-UIRAMHNM.js.map +1 -0
- package/dist/{chunk-WAFY3R2F.js → chunk-VWDRFRJU.js} +27 -23
- package/dist/chunk-VWDRFRJU.js.map +1 -0
- package/dist/{chunk-Q5KTSMRE.js → chunk-Y45XUW33.js} +14 -5
- package/dist/chunk-Y45XUW33.js.map +1 -0
- package/dist/controllers/index.js +7 -7
- package/dist/controllers/index.mjs +6 -6
- package/dist/controllers/user-storage/UserStorageController.js +6 -6
- package/dist/controllers/user-storage/UserStorageController.mjs +5 -5
- package/dist/controllers/user-storage/encryption/encryption.js +2 -2
- package/dist/controllers/user-storage/encryption/encryption.mjs +1 -1
- package/dist/controllers/user-storage/encryption/index.js +3 -3
- package/dist/controllers/user-storage/encryption/index.mjs +2 -2
- package/dist/controllers/user-storage/index.js +7 -7
- package/dist/controllers/user-storage/index.mjs +6 -6
- package/dist/controllers/user-storage/schema.js +4 -4
- package/dist/controllers/user-storage/schema.mjs +3 -3
- package/dist/controllers/user-storage/services.js +5 -5
- package/dist/controllers/user-storage/services.mjs +4 -4
- package/dist/index.js +13 -13
- package/dist/index.mjs +12 -12
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +3 -3
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +2 -2
- package/dist/sdk/authentication.js +4 -4
- package/dist/sdk/authentication.mjs +3 -3
- package/dist/sdk/encryption.js +3 -3
- package/dist/sdk/encryption.mjs +2 -2
- package/dist/sdk/index.js +12 -10
- package/dist/sdk/index.mjs +13 -11
- package/dist/sdk/user-storage.js +6 -6
- package/dist/sdk/user-storage.mjs +5 -5
- package/dist/sdk/utils/messaging-signing-snap-requests.js +4 -2
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +5 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/controllers/user-storage/UserStorageController.d.ts +5 -3
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts +4 -4
- package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts +2 -2
- package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts +1 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/encryption/encryption.d.ts +3 -2
- package/dist/types/controllers/user-storage/encryption/encryption.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/services.d.ts +3 -0
- package/dist/types/controllers/user-storage/services.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts +5 -5
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +1 -1
- package/dist/types/sdk/authentication.d.ts +1 -0
- package/dist/types/sdk/authentication.d.ts.map +1 -1
- package/dist/types/sdk/user-storage.d.ts.map +1 -1
- package/dist/types/sdk/utils/messaging-signing-snap-requests.d.ts +7 -0
- package/dist/types/sdk/utils/messaging-signing-snap-requests.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5EBUFNAN.mjs.map +0 -1
- package/dist/chunk-HMRRB4EX.js.map +0 -1
- package/dist/chunk-JJ5BDCKD.js.map +0 -1
- package/dist/chunk-K5UKU454.mjs.map +0 -1
- package/dist/chunk-LDYHGAP4.js +0 -11
- package/dist/chunk-LNECIW4K.js.map +0 -1
- package/dist/chunk-LYDHYB6I.mjs.map +0 -1
- package/dist/chunk-M23ZCTKE.mjs.map +0 -1
- package/dist/chunk-PQ5T4GHY.js.map +0 -1
- package/dist/chunk-Q5KTSMRE.js.map +0 -1
- package/dist/chunk-T3FNDVE3.js.map +0 -1
- package/dist/chunk-WAFY3R2F.js.map +0 -1
- package/dist/chunk-YKOMKXG4.mjs.map +0 -1
- package/dist/chunk-ZMQRPWJN.js.map +0 -1
- package/dist/chunk-ZYYAQJ56.mjs.map +0 -1
- /package/dist/{chunk-NSSHFDIS.mjs.map → chunk-2VEMA6OE.mjs.map} +0 -0
- /package/dist/{chunk-EYZFHZR2.js.map → chunk-5MQUI24U.js.map} +0 -0
- /package/dist/{chunk-QU4EXKJO.mjs.map → chunk-6DAK2U35.mjs.map} +0 -0
- /package/dist/{chunk-5TOWF6UW.mjs.map → chunk-KHASG4H3.mjs.map} +0 -0
- /package/dist/{chunk-AK7OTIWA.js.map → chunk-NIUQ34PY.js.map} +0 -0
- /package/dist/{chunk-J7NSK6BO.mjs.map → chunk-TP7SP3AG.mjs.map} +0 -0
- /package/dist/{chunk-4ZGRRVMI.js.map → chunk-UEHMUVQQ.js.map} +0 -0
- /package/dist/{chunk-LDYHGAP4.js.map → chunk-UHX7HJAI.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/encryption/encryption.ts"],"sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scryptAsync } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport type { NativeScrypt } from '../UserStorageController';\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n async encryptString(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n return await this.#encryptStringV1(\n plaintext,\n password,\n nativeScryptCrypto,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n async decryptString(\n encryptedDataStr: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return await this.#decryptStringV1(\n encryptedData,\n password,\n nativeScryptCrypto,\n );\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n async #encryptStringV1(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { key, salt } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n randomBytes(SCRYPT_SALT_SIZE),\n nativeScryptCrypto,\n );\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n async #decryptStringV1(\n data: EncryptedPayload,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n nativeScryptCrypto,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n async #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n password,\n newSalt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"],"mappings":";;;;;;;;;;;;;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;AAAA,EACrB;AAGA,SAAO,IAAI,KAAK,KAAK,EAAE,QAAQ,UAAU;AAC3C;AAEM;AAAA,4BAAuB,eAC3B,UACA,GACA,MACA,oBACA;AACA,QAAM,iBAAiB,iBAAiB,QAAQ;AAChD,QAAM,YAAY,OACd,mBAAmB,gBAAgB,IAAI,IACvC,gBAAgB,cAAc;AAElC,MAAI,WAAW;AACb,WAAO;AAAA,MACL,KAAK,UAAU;AAAA,MACf,MAAM,UAAU;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,UAAU,QAAQ,YAAY,gBAAgB;AAEpD,MAAI;AAEJ,MAAI,oBAAoB;AACtB,aAAS,MAAM;AAAA,MACb;AAAA,MACA;AAAA,MACA,EAAE;AAAA,MACF,EAAE;AAAA,MACF,EAAE;AAAA,MACF,EAAE;AAAA,IACJ;AAAA,EACF,OAAO;AACL,aAAS,MAAM,YAAY,UAAU,SAAS;AAAA,MAC5C,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,MACL,OAAO,EAAE;AAAA,IACX,CAAC;AAAA,EACH;AACA,eAAa,gBAAgB,SAAS,MAAM;AAE5C,SAAO;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AACF;AAGF,IAAM,aAAa,IAAI,mBAAmB;AAC1C,IAAO,qBAAQ;AAOR,SAAS,iBAAiB,MAAsB;AACrD,QAAM,aAAa,OAAO,IAAI;AAC9B,SAAO,WAAW,UAAU;AAC9B;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
encryption_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-COBJUBZE.mjs";
|
|
4
4
|
|
|
5
5
|
// src/controllers/user-storage/encryption/index.ts
|
|
6
6
|
var encryption_default2 = encryption_default;
|
|
@@ -8,4 +8,4 @@ var encryption_default2 = encryption_default;
|
|
|
8
8
|
export {
|
|
9
9
|
encryption_default2 as encryption_default
|
|
10
10
|
};
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
11
|
+
//# sourceMappingURL=chunk-KHASG4H3.mjs.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JwtBearerAuth
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PU7MAIST.mjs";
|
|
4
4
|
import {
|
|
5
5
|
SIWEJwtBearerAuth
|
|
6
6
|
} from "./chunk-2CWF7ZTL.mjs";
|
|
7
7
|
import {
|
|
8
8
|
SRPJwtBearerAuth
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TP7SP3AG.mjs";
|
|
10
10
|
import {
|
|
11
11
|
AuthType
|
|
12
12
|
} from "./chunk-CAIIVJAO.mjs";
|
|
@@ -15,15 +15,16 @@ import {
|
|
|
15
15
|
SNAP_ORIGIN,
|
|
16
16
|
connectSnap,
|
|
17
17
|
getSnap,
|
|
18
|
-
getSnaps
|
|
19
|
-
|
|
18
|
+
getSnaps,
|
|
19
|
+
isSnapConnected
|
|
20
|
+
} from "./chunk-UEWCUBMX.mjs";
|
|
20
21
|
import {
|
|
21
22
|
STORAGE_URL,
|
|
22
23
|
UserStorage
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-MK7ABX2V.mjs";
|
|
24
25
|
import {
|
|
25
26
|
createSHA256Hash
|
|
26
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-COBJUBZE.mjs";
|
|
27
28
|
import {
|
|
28
29
|
Env,
|
|
29
30
|
Platform,
|
|
@@ -68,10 +69,11 @@ __export(sdk_exports, {
|
|
|
68
69
|
getEnvUrls: () => getEnvUrls,
|
|
69
70
|
getOidcClientId: () => getOidcClientId,
|
|
70
71
|
getSnap: () => getSnap,
|
|
71
|
-
getSnaps: () => getSnaps
|
|
72
|
+
getSnaps: () => getSnaps,
|
|
73
|
+
isSnapConnected: () => isSnapConnected
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
export {
|
|
75
77
|
sdk_exports
|
|
76
78
|
};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-M7AUA5W7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk/index.ts"],"sourcesContent":["export * from './authentication';\nexport * from './user-storage';\nexport * from './env';\nexport * from './errors';\nexport * from './encryption';\nexport * from './utils/messaging-signing-snap-requests';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/sdk/index.ts"],"sourcesContent":["export * from './authentication';\nexport * from './user-storage';\nexport * from './env';\nexport * from './errors';\nexport * from './encryption';\nexport * from './utils/messaging-signing-snap-requests';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createEntryPath
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2VEMA6OE.mjs";
|
|
4
4
|
import {
|
|
5
5
|
encryption_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6DAK2U35.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createSHA256Hash
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-COBJUBZE.mjs";
|
|
10
10
|
import {
|
|
11
11
|
getEnvUrls
|
|
12
12
|
} from "./chunk-KTCSRECK.mjs";
|
|
@@ -157,7 +157,7 @@ getUserStorageAllFeatureEntries_fn = async function(path) {
|
|
|
157
157
|
}
|
|
158
158
|
return encryption_default.decryptString(entry.Data, storageKey);
|
|
159
159
|
});
|
|
160
|
-
return decryptedData;
|
|
160
|
+
return (await Promise.allSettled(decryptedData)).map((d) => d.status === "fulfilled" ? d.value : void 0).filter((d) => d !== void 0);
|
|
161
161
|
} catch (e) {
|
|
162
162
|
if (e instanceof NotFoundError) {
|
|
163
163
|
throw e;
|
|
@@ -183,4 +183,4 @@ export {
|
|
|
183
183
|
STORAGE_URL,
|
|
184
184
|
UserStorage
|
|
185
185
|
};
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
186
|
+
//# sourceMappingURL=chunk-MK7ABX2V.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk/user-storage.ts"],"sourcesContent":["import type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../controllers/user-storage/schema';\nimport { createEntryPath } from '../controllers/user-storage/schema';\nimport type { GetUserStorageAllFeatureEntriesResponse } from '../controllers/user-storage/services';\nimport type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport encryption, { createSHA256Hash } from './encryption';\nimport type { Env } from './env';\nimport { getEnvUrls } from './env';\nimport { NotFoundError, UserStorageError } from './errors';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n env: Env;\n auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n getStorageKey: () => Promise<string | null>;\n setStorageKey: (val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n protected options: UserStorageOptions;\n\n protected env: Env;\n\n constructor(config: UserStorageConfig, options: UserStorageOptions) {\n this.env = config.env;\n this.config = config;\n this.options = options;\n }\n\n async setItem(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value);\n }\n\n async getItem(path: UserStoragePathWithFeatureAndKey): Promise<string> {\n return this.#getUserStorage(path);\n }\n\n async getAllFeatureItems(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path);\n }\n\n async getStorageKey(): Promise<string> {\n const storageKey = await this.options.storage?.getStorageKey();\n if (storageKey) {\n return storageKey;\n }\n\n const userProfile = await this.config.auth.getUserProfile();\n const storageKeySignature = await this.config.auth.signMessage(\n `metamask:${userProfile.profileId}`,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(hashedStorageKeySignature);\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(\n path: UserStoragePathWithFeatureAndKey,\n data: string,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = encryption.encryptString(data, storageKey);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(\n `feature/key set not found for path '${path}'.`,\n );\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const { Data: encryptedData } = await response.json();\n return encryption.decryptString(encryptedData, storageKey);\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(`feature not found for path '${path}'.`);\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await response.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData = userStorage.flatMap((entry) => {\n if (!entry.Data) {\n return [];\n }\n\n return encryption.decryptString(entry.Data, storageKey);\n });\n\n return decryptedData;\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n const hashedKey = createSHA256Hash(key + storageKey);\n return hashedKey;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYO,IAAM,cAAc,CAAC,KAAU,kBACpC,GAAG,WAAW,GAAG,EAAE,iBAAiB,uBAAuB,aAAa;AAb1E;AAkCO,IAAM,cAAN,MAAkB;AAAA,EAOvB,YAAY,QAA2B,SAA6B;AAsCpE,uBAAM;AAwCN,uBAAM;AA+CN,uBAAM;AA0DN;AAOA;AAAA;AAAA,uBAAM;AA7LJ,SAAK,MAAM,OAAO;AAClB,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QACJ,MACA,OACe;AACf,UAAM,sBAAK,0CAAL,WAAwB,MAAM;AAAA,EACtC;AAAA,EAEA,MAAM,QAAQ,MAAyD;AACrE,WAAO,sBAAK,oCAAL,WAAqB;AAAA,EAC9B;AAAA,EAEA,MAAM,mBACJ,MAC0B;AAC1B,WAAO,sBAAK,sEAAL,WAAsC;AAAA,EAC/C;AAAA,EAEA,MAAM,gBAAiC;AACrC,UAAM,aAAa,MAAM,KAAK,QAAQ,SAAS,cAAc;AAC7D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,UAAM,sBAAsB,MAAM,KAAK,OAAO,KAAK;AAAA,MACjD,YAAY,YAAY,SAAS;AAAA,IACnC;AACA,UAAM,4BAA4B,iBAAiB,mBAAmB;AACtE,UAAM,KAAK,QAAQ,SAAS,cAAc,yBAAyB;AACnE,WAAO;AAAA,EACT;AA8JF;AA5JQ;AAAA,uBAAkB,eACtB,MACA,MACe;AACf,MAAI;AACF,UAAM,UAAU,MAAM,sBAAK,oDAAL;AACtB,UAAM,aAAa,MAAM,KAAK,cAAc;AAC5C,UAAM,gBAAgB,mBAAW,cAAc,MAAM,UAAU;AAC/D,UAAM,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AAA,EACT,SAAS,GAAG;AACV,QAAI,aAAa,eAAe;AAC9B,YAAM;AAAA,IACR;AAGA,UAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AAEzD,UAAM,IAAI;AAAA,MACR,wCAAwC,IAAI,MAAM,YAAY;AAAA,IAChE;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SAAC,KAAa,YAA4B;AACvD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AACnD,SAAO;AACT;AAIM;AAAA,4BAAuB,iBAAuC;AAClE,QAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,SAAO,EAAE,eAAe,UAAU,WAAW,GAAG;AAClD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/sdk/user-storage.ts"],"sourcesContent":["import type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../controllers/user-storage/schema';\nimport { createEntryPath } from '../controllers/user-storage/schema';\nimport type { GetUserStorageAllFeatureEntriesResponse } from '../controllers/user-storage/services';\nimport type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport encryption, { createSHA256Hash } from './encryption';\nimport type { Env } from './env';\nimport { getEnvUrls } from './env';\nimport { NotFoundError, UserStorageError } from './errors';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n env: Env;\n auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n getStorageKey: () => Promise<string | null>;\n setStorageKey: (val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n protected options: UserStorageOptions;\n\n protected env: Env;\n\n constructor(config: UserStorageConfig, options: UserStorageOptions) {\n this.env = config.env;\n this.config = config;\n this.options = options;\n }\n\n async setItem(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value);\n }\n\n async getItem(path: UserStoragePathWithFeatureAndKey): Promise<string> {\n return this.#getUserStorage(path);\n }\n\n async getAllFeatureItems(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path);\n }\n\n async getStorageKey(): Promise<string> {\n const storageKey = await this.options.storage?.getStorageKey();\n if (storageKey) {\n return storageKey;\n }\n\n const userProfile = await this.config.auth.getUserProfile();\n const storageKeySignature = await this.config.auth.signMessage(\n `metamask:${userProfile.profileId}`,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(hashedStorageKeySignature);\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(\n path: UserStoragePathWithFeatureAndKey,\n data: string,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = encryption.encryptString(data, storageKey);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(\n `feature/key set not found for path '${path}'.`,\n );\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const { Data: encryptedData } = await response.json();\n return encryption.decryptString(encryptedData, storageKey);\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(`feature not found for path '${path}'.`);\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await response.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData = userStorage.flatMap((entry) => {\n if (!entry.Data) {\n return [];\n }\n\n return encryption.decryptString(entry.Data, storageKey);\n });\n\n return (await Promise.allSettled(decryptedData))\n .map((d) => (d.status === 'fulfilled' ? d.value : undefined))\n .filter((d): d is string => d !== undefined);\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n const hashedKey = createSHA256Hash(key + storageKey);\n return hashedKey;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYO,IAAM,cAAc,CAAC,KAAU,kBACpC,GAAG,WAAW,GAAG,EAAE,iBAAiB,uBAAuB,aAAa;AAb1E;AAkCO,IAAM,cAAN,MAAkB;AAAA,EAOvB,YAAY,QAA2B,SAA6B;AAsCpE,uBAAM;AAwCN,uBAAM;AA+CN,uBAAM;AA4DN;AAOA;AAAA;AAAA,uBAAM;AA/LJ,SAAK,MAAM,OAAO;AAClB,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QACJ,MACA,OACe;AACf,UAAM,sBAAK,0CAAL,WAAwB,MAAM;AAAA,EACtC;AAAA,EAEA,MAAM,QAAQ,MAAyD;AACrE,WAAO,sBAAK,oCAAL,WAAqB;AAAA,EAC9B;AAAA,EAEA,MAAM,mBACJ,MAC0B;AAC1B,WAAO,sBAAK,sEAAL,WAAsC;AAAA,EAC/C;AAAA,EAEA,MAAM,gBAAiC;AACrC,UAAM,aAAa,MAAM,KAAK,QAAQ,SAAS,cAAc;AAC7D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,UAAM,sBAAsB,MAAM,KAAK,OAAO,KAAK;AAAA,MACjD,YAAY,YAAY,SAAS;AAAA,IACnC;AACA,UAAM,4BAA4B,iBAAiB,mBAAmB;AACtE,UAAM,KAAK,QAAQ,SAAS,cAAc,yBAAyB;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WAAW,GAAG;AAC/B,aAAO;AAAA,IACT;AAEA,UAAM,gBAAgB,YAAY,QAAQ,CAAC,UAAU;AACnD,UAAI,CAAC,MAAM,MAAM;AACf,eAAO,CAAC;AAAA,MACV;AAEA,aAAO,mBAAW,cAAc,MAAM,MAAM,UAAU;AAAA,IACxD,CAAC;AAED,YAAQ,MAAM,QAAQ,WAAW,aAAa,GAC3C,IAAI,CAAC,MAAO,EAAE,WAAW,cAAc,EAAE,QAAQ,MAAU,EAC3D,OAAO,CAAC,MAAmB,MAAM,MAAS;AAAA,EAC/C,SAAS,GAAG;AACV,QAAI,aAAa,eAAe;AAC9B,YAAM;AAAA,IACR;AAGA,UAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AAEzD,UAAM,IAAI;AAAA,MACR,wCAAwC,IAAI,MAAM,YAAY;AAAA,IAChE;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SAAC,KAAa,YAA4B;AACvD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AACnD,SAAO;AACT;AAIM;AAAA,4BAAuB,iBAAuC;AAClE,QAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,SAAO,EAAE,eAAe,UAAU,WAAW,GAAG;AAClD;","names":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UserStorageController,
|
|
3
3
|
defaultState
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OLFO6R7Z.mjs";
|
|
5
5
|
import {
|
|
6
6
|
USER_STORAGE_ENDPOINT
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-76NMME23.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createEntryPath
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2VEMA6OE.mjs";
|
|
11
11
|
import {
|
|
12
12
|
encryption_default as encryption_default2
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-KHASG4H3.mjs";
|
|
14
14
|
import {
|
|
15
15
|
createSHA256Hash,
|
|
16
16
|
encryption_default
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-COBJUBZE.mjs";
|
|
18
18
|
import {
|
|
19
19
|
__export
|
|
20
20
|
} from "./chunk-U5UIDVOO.mjs";
|
|
@@ -47,7 +47,11 @@ __export(fixtures_exports, {
|
|
|
47
47
|
var MOCK_STORAGE_KEY_SIGNATURE = "mockStorageKey";
|
|
48
48
|
var MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);
|
|
49
49
|
var MOCK_STORAGE_DATA = JSON.stringify({ hello: "world" });
|
|
50
|
-
var
|
|
50
|
+
var cachedMockEncryptedData;
|
|
51
|
+
var MOCK_ENCRYPTED_STORAGE_DATA = async () => cachedMockEncryptedData ?? (cachedMockEncryptedData = await encryption_default2.encryptString(
|
|
52
|
+
MOCK_STORAGE_DATA,
|
|
53
|
+
MOCK_STORAGE_KEY
|
|
54
|
+
));
|
|
51
55
|
|
|
52
56
|
// src/controllers/user-storage/__fixtures__/mockResponses.ts
|
|
53
57
|
var getMockUserStorageEndpoint = (path) => {
|
|
@@ -59,28 +63,28 @@ var getMockUserStorageEndpoint = (path) => {
|
|
|
59
63
|
MOCK_STORAGE_KEY
|
|
60
64
|
)}`;
|
|
61
65
|
};
|
|
62
|
-
var MOCK_GET_USER_STORAGE_RESPONSE = () => ({
|
|
66
|
+
var MOCK_GET_USER_STORAGE_RESPONSE = async () => ({
|
|
63
67
|
HashedKey: "HASHED_KEY",
|
|
64
|
-
Data: MOCK_ENCRYPTED_STORAGE_DATA()
|
|
68
|
+
Data: await MOCK_ENCRYPTED_STORAGE_DATA()
|
|
65
69
|
});
|
|
66
|
-
var MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE = () => [
|
|
70
|
+
var MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE = async () => [
|
|
67
71
|
{
|
|
68
72
|
HashedKey: "HASHED_KEY",
|
|
69
|
-
Data: MOCK_ENCRYPTED_STORAGE_DATA()
|
|
73
|
+
Data: await MOCK_ENCRYPTED_STORAGE_DATA()
|
|
70
74
|
}
|
|
71
75
|
];
|
|
72
|
-
var getMockUserStorageGetResponse = (path = "notifications.notificationSettings") => {
|
|
76
|
+
var getMockUserStorageGetResponse = async (path = "notifications.notificationSettings") => {
|
|
73
77
|
return {
|
|
74
78
|
url: getMockUserStorageEndpoint(path),
|
|
75
79
|
requestMethod: "GET",
|
|
76
|
-
response: MOCK_GET_USER_STORAGE_RESPONSE()
|
|
80
|
+
response: await MOCK_GET_USER_STORAGE_RESPONSE()
|
|
77
81
|
};
|
|
78
82
|
};
|
|
79
|
-
var getMockUserStorageAllFeatureEntriesResponse = (path = "notifications") => {
|
|
83
|
+
var getMockUserStorageAllFeatureEntriesResponse = async (path = "notifications") => {
|
|
80
84
|
return {
|
|
81
85
|
url: getMockUserStorageEndpoint(path),
|
|
82
86
|
requestMethod: "GET",
|
|
83
|
-
response: MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE()
|
|
87
|
+
response: await MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE()
|
|
84
88
|
};
|
|
85
89
|
};
|
|
86
90
|
var getMockUserStoragePutResponse = (path = "notifications.notificationSettings") => {
|
|
@@ -100,4 +104,4 @@ export {
|
|
|
100
104
|
user_storage_default,
|
|
101
105
|
user_storage_exports
|
|
102
106
|
};
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-NEBLEB3X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\n\n// NOTE - using encryption.encryptString directly in fixtures causes issues on mobile.\n// This is because this fixture is getting added in at run time. Will be improved once we support multiple exports\nlet cachedMockEncryptedData: string;\nexport const MOCK_ENCRYPTED_STORAGE_DATA = async () =>\n (cachedMockEncryptedData ??= await encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n ));\n","import type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../schema';\nimport { createEntryPath } from '../schema';\nimport type {\n GetUserStorageAllFeatureEntriesResponse,\n GetUserStorageResponse,\n} from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const getMockUserStorageEndpoint = (\n path: UserStoragePathWithFeatureAndKey | UserStoragePathWithFeatureOnly,\n) => {\n if (path.split('.').length === 1) {\n return `${USER_STORAGE_ENDPOINT}/${path}`;\n }\n\n return `${USER_STORAGE_ENDPOINT}${createEntryPath(\n path as UserStoragePathWithFeatureAndKey,\n MOCK_STORAGE_KEY,\n )}`;\n};\n\nconst MOCK_GET_USER_STORAGE_RESPONSE =\n async (): Promise<GetUserStorageResponse> => ({\n HashedKey: 'HASHED_KEY',\n Data: await MOCK_ENCRYPTED_STORAGE_DATA(),\n });\n\nconst MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE =\n async (): Promise<GetUserStorageAllFeatureEntriesResponse> => [\n {\n HashedKey: 'HASHED_KEY',\n Data: await MOCK_ENCRYPTED_STORAGE_DATA(),\n },\n ];\n\nexport const getMockUserStorageGetResponse = async (\n path: UserStoragePathWithFeatureAndKey = 'notifications.notificationSettings',\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'GET',\n response: await MOCK_GET_USER_STORAGE_RESPONSE(),\n } satisfies MockResponse;\n};\n\nexport const getMockUserStorageAllFeatureEntriesResponse = async (\n path: UserStoragePathWithFeatureOnly = 'notifications',\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'GET',\n response: await MOCK_GET_USER_STORAGE_ALL_FEATURE_ENTRIES_RESPONSE(),\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = (\n path: UserStoragePathWithFeatureAndKey = 'notifications.notificationSettings',\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAIlE,IAAI;AACG,IAAM,8BAA8B,YACxC,sDAA4B,MAAMA,oBAAW;AAAA,EAC5C;AAAA,EACA;AACF;;;ACKK,IAAM,6BAA6B,CACxC,SACG;AACH,MAAI,KAAK,MAAM,GAAG,EAAE,WAAW,GAAG;AAChC,WAAO,GAAG,qBAAqB,IAAI,IAAI;AAAA,EACzC;AAEA,SAAO,GAAG,qBAAqB,GAAG;AAAA,IAChC;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,IAAM,iCACJ,aAA8C;AAAA,EAC5C,WAAW;AAAA,EACX,MAAM,MAAM,4BAA4B;AAC1C;AAEF,IAAM,qDACJ,YAA8D;AAAA,EAC5D;AAAA,IACE,WAAW;AAAA,IACX,MAAM,MAAM,4BAA4B;AAAA,EAC1C;AACF;AAEK,IAAM,gCAAgC,OAC3C,OAAyC,yCACtC;AACH,SAAO;AAAA,IACL,KAAK,2BAA2B,IAAI;AAAA,IACpC,eAAe;AAAA,IACf,UAAU,MAAM,+BAA+B;AAAA,EACjD;AACF;AAEO,IAAM,8CAA8C,OACzD,OAAuC,oBACpC;AACH,SAAO;AAAA,IACL,KAAK,2BAA2B,IAAI;AAAA,IACpC,eAAe;AAAA,IACf,UAAU,MAAM,mDAAmD;AAAA,EACrE;AACF;AAEO,IAAM,gCAAgC,CAC3C,OAAyC,yCACtC;AACH,SAAO;AAAA,IACL,KAAK,2BAA2B,IAAI;AAAA,IACpC,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;;;AHvEA,IAAMC,yBAAwB;AAE9B,IAAO,uBAAQC;","names":["encryption_default","UserStorageController","UserStorageController"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkBKQE7DB5js = require('./chunk-BKQE7DB5.js');
|
|
4
4
|
|
|
5
5
|
// src/controllers/user-storage/encryption/index.ts
|
|
6
|
-
var encryption_default2 =
|
|
6
|
+
var encryption_default2 = _chunkBKQE7DB5js.encryption_default;
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
exports.encryption_default = encryption_default2;
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
11
|
+
//# sourceMappingURL=chunk-NIUQ34PY.js.map
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
getUserStorage,
|
|
10
10
|
getUserStorageAllFeatureEntries,
|
|
11
11
|
upsertUserStorage
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-76NMME23.mjs";
|
|
13
13
|
import {
|
|
14
14
|
createSHA256Hash
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-COBJUBZE.mjs";
|
|
16
16
|
import {
|
|
17
17
|
__privateAdd,
|
|
18
18
|
__privateGet,
|
|
@@ -37,14 +37,20 @@ var metadata = {
|
|
|
37
37
|
anonymous: false
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
var _auth, _accounts, _notificationServices, _isUnlocked, _keyringController, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, __snapSignMessageCache, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
40
|
+
var _auth, _accounts, _notificationServices, _isUnlocked, _keyringController, _nativeScryptCrypto, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, __snapSignMessageCache, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
41
41
|
var UserStorageController = class extends BaseController {
|
|
42
|
-
constructor(
|
|
42
|
+
constructor({
|
|
43
|
+
messenger,
|
|
44
|
+
state,
|
|
45
|
+
env,
|
|
46
|
+
getMetaMetricsState,
|
|
47
|
+
nativeScryptCrypto
|
|
48
|
+
}) {
|
|
43
49
|
super({
|
|
44
|
-
messenger
|
|
50
|
+
messenger,
|
|
45
51
|
metadata,
|
|
46
52
|
name: controllerName,
|
|
47
|
-
state: { ...defaultState, ...
|
|
53
|
+
state: { ...defaultState, ...state }
|
|
48
54
|
});
|
|
49
55
|
/**
|
|
50
56
|
* Constructor helper for registering this controller's messaging system
|
|
@@ -100,6 +106,29 @@ var UserStorageController = class extends BaseController {
|
|
|
100
106
|
// This is replaced with the actual value in the constructor
|
|
101
107
|
// We will remove this once the feature will be released
|
|
102
108
|
isAccountSyncingEnabled: false,
|
|
109
|
+
isAccountSyncingInProgress: false,
|
|
110
|
+
setupAccountSyncingSubscriptions: () => {
|
|
111
|
+
this.messagingSystem.subscribe(
|
|
112
|
+
"AccountsController:accountAdded",
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
114
|
+
async (account) => {
|
|
115
|
+
if (__privateGet(this, _accounts).isAccountSyncingInProgress) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await this.saveInternalAccountToUserStorage(account.address);
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
this.messagingSystem.subscribe(
|
|
122
|
+
"AccountsController:accountRenamed",
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
124
|
+
async (account) => {
|
|
125
|
+
if (__privateGet(this, _accounts).isAccountSyncingInProgress) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
await this.saveInternalAccountToUserStorage(account.address);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
},
|
|
103
132
|
getInternalAccountByAddress: async (address) => {
|
|
104
133
|
return this.messagingSystem.call(
|
|
105
134
|
"AccountsController:getAccountByAddress",
|
|
@@ -163,26 +192,24 @@ var UserStorageController = class extends BaseController {
|
|
|
163
192
|
"KeyringController:getState"
|
|
164
193
|
);
|
|
165
194
|
__privateSet(this, _isUnlocked, isUnlocked);
|
|
166
|
-
this.messagingSystem.subscribe(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
async () => {
|
|
170
|
-
__privateSet(this, _isUnlocked, true);
|
|
171
|
-
await this.syncInternalAccountsWithUserStorage();
|
|
172
|
-
}
|
|
173
|
-
);
|
|
195
|
+
this.messagingSystem.subscribe("KeyringController:unlock", () => {
|
|
196
|
+
__privateSet(this, _isUnlocked, true);
|
|
197
|
+
});
|
|
174
198
|
this.messagingSystem.subscribe("KeyringController:lock", () => {
|
|
175
199
|
__privateSet(this, _isUnlocked, false);
|
|
176
200
|
});
|
|
177
201
|
}
|
|
178
202
|
});
|
|
203
|
+
__privateAdd(this, _nativeScryptCrypto, void 0);
|
|
179
204
|
__privateAdd(this, __snapSignMessageCache, {});
|
|
180
205
|
__privateGet(this, _accounts).isAccountSyncingEnabled = Boolean(
|
|
181
|
-
|
|
206
|
+
env?.isAccountSyncingEnabled
|
|
182
207
|
);
|
|
183
|
-
this.getMetaMetricsState =
|
|
208
|
+
this.getMetaMetricsState = getMetaMetricsState;
|
|
184
209
|
__privateGet(this, _keyringController).setupLockedStateSubscriptions();
|
|
185
210
|
__privateMethod(this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
211
|
+
__privateSet(this, _nativeScryptCrypto, nativeScryptCrypto);
|
|
212
|
+
__privateGet(this, _accounts).setupAccountSyncingSubscriptions();
|
|
186
213
|
}
|
|
187
214
|
async enableProfileSyncing() {
|
|
188
215
|
try {
|
|
@@ -248,7 +275,8 @@ var UserStorageController = class extends BaseController {
|
|
|
248
275
|
const result = await getUserStorage({
|
|
249
276
|
path,
|
|
250
277
|
bearerToken,
|
|
251
|
-
storageKey
|
|
278
|
+
storageKey,
|
|
279
|
+
nativeScryptCrypto: __privateGet(this, _nativeScryptCrypto)
|
|
252
280
|
});
|
|
253
281
|
return result;
|
|
254
282
|
}
|
|
@@ -265,7 +293,8 @@ var UserStorageController = class extends BaseController {
|
|
|
265
293
|
const result = await getUserStorageAllFeatureEntries({
|
|
266
294
|
path,
|
|
267
295
|
bearerToken,
|
|
268
|
-
storageKey
|
|
296
|
+
storageKey,
|
|
297
|
+
nativeScryptCrypto: __privateGet(this, _nativeScryptCrypto)
|
|
269
298
|
});
|
|
270
299
|
return result;
|
|
271
300
|
}
|
|
@@ -283,7 +312,8 @@ var UserStorageController = class extends BaseController {
|
|
|
283
312
|
await upsertUserStorage(value, {
|
|
284
313
|
path,
|
|
285
314
|
bearerToken,
|
|
286
|
-
storageKey
|
|
315
|
+
storageKey,
|
|
316
|
+
nativeScryptCrypto: __privateGet(this, _nativeScryptCrypto)
|
|
287
317
|
});
|
|
288
318
|
}
|
|
289
319
|
/**
|
|
@@ -307,6 +337,7 @@ var UserStorageController = class extends BaseController {
|
|
|
307
337
|
}
|
|
308
338
|
try {
|
|
309
339
|
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
340
|
+
__privateGet(this, _accounts).isAccountSyncingInProgress = true;
|
|
310
341
|
const userStorageAccountsList = await __privateGet(this, _accounts).getUserStorageAccountsList();
|
|
311
342
|
if (!userStorageAccountsList || !userStorageAccountsList.length) {
|
|
312
343
|
await __privateGet(this, _accounts).saveInternalAccountsListToUserStorage();
|
|
@@ -392,6 +423,8 @@ var UserStorageController = class extends BaseController {
|
|
|
392
423
|
throw new Error(
|
|
393
424
|
`${controllerName} - failed to sync user storage accounts list - ${errorMessage}`
|
|
394
425
|
);
|
|
426
|
+
} finally {
|
|
427
|
+
__privateGet(this, _accounts).isAccountSyncingInProgress = false;
|
|
395
428
|
}
|
|
396
429
|
}
|
|
397
430
|
/**
|
|
@@ -403,6 +436,7 @@ var UserStorageController = class extends BaseController {
|
|
|
403
436
|
return;
|
|
404
437
|
}
|
|
405
438
|
try {
|
|
439
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
406
440
|
await __privateGet(this, _accounts).saveInternalAccountToUserStorage(address);
|
|
407
441
|
} catch (e) {
|
|
408
442
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
@@ -417,6 +451,7 @@ _accounts = new WeakMap();
|
|
|
417
451
|
_notificationServices = new WeakMap();
|
|
418
452
|
_isUnlocked = new WeakMap();
|
|
419
453
|
_keyringController = new WeakMap();
|
|
454
|
+
_nativeScryptCrypto = new WeakMap();
|
|
420
455
|
_registerMessageHandlers = new WeakSet();
|
|
421
456
|
registerMessageHandlers_fn = function() {
|
|
422
457
|
this.messagingSystem.registerActionHandler(
|
|
@@ -508,4 +543,4 @@ export {
|
|
|
508
543
|
defaultState,
|
|
509
544
|
UserStorageController
|
|
510
545
|
};
|
|
511
|
-
//# sourceMappingURL=chunk-
|
|
546
|
+
//# sourceMappingURL=chunk-OLFO6R7Z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"sourcesContent":["import type {\n AccountsControllerListAccountsAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountAddedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { InternalAccount } from '@metamask/keyring-api';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n KeyringControllerAddNewAccountAction,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport type { UserStorageAccount } from './accounts/user-storage';\nimport {\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './accounts/user-storage';\nimport { createSHA256Hash } from './encryption';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from './schema';\nimport {\n getUserStorage,\n getUserStorageAllFeatureEntries,\n upsertUserStorage,\n} from './services';\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nexport declare type NativeScrypt = (\n passwd: string,\n salt: Uint8Array,\n N: number,\n r: number,\n p: number,\n size: number,\n) => Promise<Uint8Array>;\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performGetStorageAllFeatureEntries'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n | 'syncInternalAccountsWithUserStorage'\n | 'saveInternalAccountToUserStorage'\n>;\nexport type UserStorageControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | UserStorageControllerGetStateAction;\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformGetStorageAllFeatureEntries =\n ActionsObj['performGetStorageAllFeatureEntries'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\nexport type UserStorageControllerSyncInternalAccountsWithUserStorage =\n ActionsObj['syncInternalAccountsWithUserStorage'];\nexport type UserStorageControllerSaveInternalAccountToUserStorage =\n ActionsObj['saveInternalAccountToUserStorage'];\n\nexport type UserStorageControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Events = UserStorageControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n // Keyring Requests\n | KeyringControllerGetStateAction\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled\n // Account syncing\n | AccountsControllerListAccountsAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerUpdateAccountMetadataAction\n | KeyringControllerAddNewAccountAction;\n\n// Messenger events\nexport type UserStorageControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type UserStorageControllerAccountSyncingInProgress = {\n type: `${typeof controllerName}:accountSyncingInProgress`;\n payload: [boolean];\n};\nexport type UserStorageControllerAccountSyncingComplete = {\n type: `${typeof controllerName}:accountSyncingComplete`;\n payload: [boolean];\n};\n\nexport type AllowedEvents =\n | UserStorageControllerChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRenamedEvent;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #accounts = {\n // This is replaced with the actual value in the constructor\n // We will remove this once the feature will be released\n isAccountSyncingEnabled: false,\n isAccountSyncingInProgress: false,\n setupAccountSyncingSubscriptions: () => {\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n return;\n }\n await this.saveInternalAccountToUserStorage(account.address);\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountRenamed',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n return;\n }\n await this.saveInternalAccountToUserStorage(account.address);\n },\n );\n },\n getInternalAccountByAddress: async (address: string) => {\n return this.messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n address,\n );\n },\n getInternalAccountsList: async (): Promise<InternalAccount[]> => {\n return this.messagingSystem.call('AccountsController:listAccounts');\n },\n getUserStorageAccountsList: async (): Promise<\n UserStorageAccount[] | null\n > => {\n const rawAccountsListResponse =\n await this.performGetStorageAllFeatureEntries('accounts');\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ??\n null\n );\n },\n saveInternalAccountToUserStorage: async (address: string) => {\n const internalAccount = await this.#accounts.getInternalAccountByAddress(\n address,\n );\n\n if (!internalAccount) {\n return;\n }\n\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await this.performSetStorage(\n `accounts.${address}`,\n JSON.stringify(mappedAccount),\n );\n },\n saveInternalAccountsListToUserStorage: async () => {\n const internalAccountsList =\n await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList) {\n return;\n }\n\n const userStorageAccountsList = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await Promise.all(\n userStorageAccountsList.map(async (userStorageAccount) => {\n await this.performSetStorage(\n `accounts.${userStorageAccount.a}`,\n JSON.stringify(userStorageAccount),\n );\n }),\n );\n },\n };\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n #nativeScryptCrypto: NativeScrypt | undefined = undefined;\n\n getMetaMetricsState: () => boolean;\n\n constructor({\n messenger,\n state,\n env,\n getMetaMetricsState,\n nativeScryptCrypto,\n }: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n env?: {\n isAccountSyncingEnabled?: boolean;\n };\n getMetaMetricsState: () => boolean;\n nativeScryptCrypto?: NativeScrypt;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#accounts.isAccountSyncingEnabled = Boolean(\n env?.isAccountSyncingEnabled,\n );\n\n this.getMetaMetricsState = getMetaMetricsState;\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n this.#nativeScryptCrypto = nativeScryptCrypto;\n this.#accounts.setupAccountSyncingSubscriptions();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n this.performGetStorageAllFeatureEntries.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:syncInternalAccountsWithUserStorage',\n this.syncInternalAccountsWithUserStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:saveInternalAccountToUserStorage',\n this.saveInternalAccountToUserStorage.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n await this.#auth.signOut();\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows retrieval of all stored data for a specific feature. Data stored is formatted as an array of strings.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns the array of decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n\n /**\n * Syncs the internal accounts list with the user storage accounts list.\n * This method is used to make sure that the internal accounts list is up-to-date with the user storage accounts list and vice-versa.\n * It will add new accounts to the internal accounts list, update/merge conflicting names and re-upload the results in some cases to the user storage.\n */\n async syncInternalAccountsWithUserStorage(): Promise<void> {\n if (!this.#accounts.isAccountSyncingEnabled) {\n return;\n }\n\n try {\n this.#assertProfileSyncingEnabled();\n\n this.#accounts.isAccountSyncingInProgress = true;\n\n const userStorageAccountsList =\n await this.#accounts.getUserStorageAccountsList();\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await this.#accounts.saveInternalAccountsListToUserStorage();\n return;\n }\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n let internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreInternalAccountsThanUserStorageAccounts =\n internalAccountsList.length > userStorageAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts than the internal accounts list\n if (!hasMoreInternalAccountsThanUserStorageAccounts) {\n const numberOfAccountsToAdd =\n userStorageAccountsList.length - internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n const addNewAccountsPromises = Array.from({\n length: numberOfAccountsToAdd,\n }).map(async () => {\n await this.messagingSystem.call('KeyringController:addNewAccount');\n });\n\n await Promise.all(addNewAccountsPromises);\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n for await (const internalAccount of internalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n if (!userStorageAccount) {\n await this.#accounts.saveInternalAccountToUserStorage(\n internalAccount.address,\n );\n continue;\n }\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n this.messagingSystem.call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n await this.#accounts.saveInternalAccountToUserStorage(\n internalAccount.address,\n );\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt >\n userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n await this.#accounts.saveInternalAccountToUserStorage(\n internalAccount.address,\n );\n continue;\n }\n }\n\n this.messagingSystem.call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n await this.#accounts.saveInternalAccountToUserStorage(\n internalAccount.address,\n );\n continue;\n }\n }\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n this.#accounts.isAccountSyncingInProgress = false;\n }\n }\n\n /**\n * Saves an individual internal account to the user storage.\n * @param address - The address of the internal account to save\n */\n async saveInternalAccountToUserStorage(address: string): Promise<void> {\n if (!this.#accounts.isAccountSyncingEnabled) {\n return;\n }\n\n try {\n this.#assertProfileSyncingEnabled();\n\n await this.#accounts.saveInternalAccountToUserStorage(address);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to save account to user storage - ${errorMessage}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAaA,SAAS,sBAAsB;AAwD/B,IAAM,iBAAiB;AAchB,IAAM,eAA2C;AAAA,EACtD,yBAAyB;AAAA,EACzB,+BAA+B;AACjC;AAEA,IAAM,WAAsD;AAAA,EAC1D,yBAAyB;AAAA,IACvB,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,+BAA+B;AAAA,IAC7B,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AAjGA;AA8MA,IAAqB,wBAArB,cAAmD,eAIjD;AAAA,EAyJA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAQG;AACD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,GAAG,cAAc,GAAG,MAAM;AAAA,IACr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