@metamask/profile-sync-controller 15.0.0 → 17.0.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 +24 -1
- package/dist/controllers/authentication/AuthenticationController.cjs +60 -24
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +6 -4
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +6 -4
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +61 -25
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/auth-snap-requests.cjs +25 -4
- package/dist/controllers/authentication/auth-snap-requests.cjs.map +1 -1
- package/dist/controllers/authentication/auth-snap-requests.d.cts +12 -2
- package/dist/controllers/authentication/auth-snap-requests.d.cts.map +1 -1
- package/dist/controllers/authentication/auth-snap-requests.d.mts +12 -2
- package/dist/controllers/authentication/auth-snap-requests.d.mts.map +1 -1
- package/dist/controllers/authentication/auth-snap-requests.mjs +23 -3
- package/dist/controllers/authentication/auth-snap-requests.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.cjs +36 -3
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +7 -5
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +7 -5
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.mjs +36 -3
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +77 -27
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +24 -10
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +24 -10
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +77 -27
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +22 -26
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +5 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +5 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +23 -27
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +3 -13
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +3 -13
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +16 -7
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +6 -2
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +6 -2
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +16 -7
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.cjs +1 -42
- package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.d.cts +1 -18
- package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.d.mts +1 -18
- package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs +0 -39
- package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +22 -22
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +4 -4
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +4 -4
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +22 -22
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.cts +8 -8
- package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.mts +8 -8
- package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs +8 -11
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +4 -4
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +4 -4
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs +8 -11
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/user-storage.cjs +38 -32
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +4 -3
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +4 -3
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +38 -32
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +16 -4
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +2 -2
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +2 -2
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +16 -4
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/dist/shared/storage-schema.cjs +1 -6
- package/dist/shared/storage-schema.cjs.map +1 -1
- package/dist/shared/storage-schema.d.cts +0 -1
- package/dist/shared/storage-schema.d.cts.map +1 -1
- package/dist/shared/storage-schema.d.mts +0 -1
- package/dist/shared/storage-schema.d.mts.map +1 -1
- package/dist/shared/storage-schema.mjs +0 -4
- package/dist/shared/storage-schema.mjs.map +1 -1
- package/package.json +13 -13
|
@@ -21,6 +21,7 @@ export type GetUserStorageAllFeatureEntriesResponse = {
|
|
|
21
21
|
export type UserStorageMethodOptions = {
|
|
22
22
|
validateAgainstSchema?: boolean;
|
|
23
23
|
nativeScryptCrypto?: NativeScrypt;
|
|
24
|
+
entropySourceId?: string;
|
|
24
25
|
};
|
|
25
26
|
export declare class UserStorage {
|
|
26
27
|
#private;
|
|
@@ -33,8 +34,8 @@ export declare class UserStorage {
|
|
|
33
34
|
getItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<string | null>;
|
|
34
35
|
getAllFeatureItems(path: UserStorageGenericFeatureName, options?: UserStorageMethodOptions): Promise<string[] | null>;
|
|
35
36
|
deleteItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<void>;
|
|
36
|
-
deleteAllFeatureItems(path: UserStorageGenericFeatureName): Promise<void>;
|
|
37
|
-
batchDeleteItems(path: UserStorageGenericFeatureName, values: UserStorageGenericFeatureKey[]): Promise<void>;
|
|
38
|
-
getStorageKey(): Promise<string>;
|
|
37
|
+
deleteAllFeatureItems(path: UserStorageGenericFeatureName, options?: UserStorageMethodOptions): Promise<void>;
|
|
38
|
+
batchDeleteItems(path: UserStorageGenericFeatureName, values: UserStorageGenericFeatureKey[], options?: UserStorageMethodOptions): Promise<void>;
|
|
39
|
+
getStorageKey(entropySourceId?: string): Promise<string>;
|
|
39
40
|
}
|
|
40
41
|
//# sourceMappingURL=user-storage.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.d.mts","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,8CAA0C;AAInE,OAAO,KAAK,EAAE,GAAG,EAAE,0BAAsB;AAEzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,uCAAuC,EAExC,qCAAiC;AAElC,OAAO,KAAK,EAAE,YAAY,EAAE,uCAAmC;AAE/D,eAAO,MAAM,WAAW,QAAS,GAAG,iBAAiB,MAAM,WACiB,CAAC;AAE7E,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A6B,EACnC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAIrB,UAAU,CACd,IAAI,EAAE,uCAAuC,EAC7C,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,qBAAqB,CACzB,IAAI,EAAE,6BAA6B,EACnC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,gBAAgB,CACpB,IAAI,EAAE,6BAA6B,EACnC,MAAM,EAAE,4BAA4B,EAAE,EACtC,OAAO,CAAC,EAAE,wBAAwB;IAK9B,aAAa,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAsd/D"}
|
|
@@ -32,29 +32,30 @@ export class UserStorage {
|
|
|
32
32
|
async deleteItem(path, options) {
|
|
33
33
|
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorage).call(this, path, options);
|
|
34
34
|
}
|
|
35
|
-
async deleteAllFeatureItems(path) {
|
|
36
|
-
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorageAllFeatureEntries).call(this, path);
|
|
35
|
+
async deleteAllFeatureItems(path, options) {
|
|
36
|
+
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorageAllFeatureEntries).call(this, path, options);
|
|
37
37
|
}
|
|
38
|
-
async batchDeleteItems(path, values) {
|
|
39
|
-
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchDeleteUserStorage).call(this, path, values);
|
|
38
|
+
async batchDeleteItems(path, values, options) {
|
|
39
|
+
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchDeleteUserStorage).call(this, path, values, options);
|
|
40
40
|
}
|
|
41
|
-
async getStorageKey() {
|
|
42
|
-
const userProfile = await this.config.auth.getUserProfile();
|
|
41
|
+
async getStorageKey(entropySourceId) {
|
|
42
|
+
const userProfile = await this.config.auth.getUserProfile(entropySourceId);
|
|
43
43
|
const message = `metamask:${userProfile.profileId}`;
|
|
44
44
|
const storageKey = await this.options.storage?.getStorageKey(message);
|
|
45
45
|
if (storageKey) {
|
|
46
46
|
return storageKey;
|
|
47
47
|
}
|
|
48
|
-
const storageKeySignature = await this.config.auth.signMessage(message);
|
|
48
|
+
const storageKeySignature = await this.config.auth.signMessage(message, entropySourceId);
|
|
49
49
|
const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);
|
|
50
50
|
await this.options.storage?.setStorageKey(message, hashedStorageKeySignature);
|
|
51
51
|
return hashedStorageKeySignature;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
_UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async function _UserStorage_upsertUserStorage(path, data, options) {
|
|
55
|
+
const entropySourceId = options?.entropySourceId;
|
|
55
56
|
try {
|
|
56
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
57
|
-
const storageKey = await this.getStorageKey();
|
|
57
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
58
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
58
59
|
const encryptedData = await encryption.encryptString(data, storageKey, options?.nativeScryptCrypto);
|
|
59
60
|
const encryptedPath = createEntryPath(path, storageKey, {
|
|
60
61
|
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
@@ -82,12 +83,13 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
82
83
|
throw new UserStorageError(`failed to upsert user storage for path '${path}'. ${errorMessage}`);
|
|
83
84
|
}
|
|
84
85
|
}, _UserStorage_batchUpsertUserStorage = async function _UserStorage_batchUpsertUserStorage(path, data, options) {
|
|
86
|
+
const entropySourceId = options?.entropySourceId;
|
|
85
87
|
try {
|
|
86
88
|
if (!data.length) {
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
90
|
-
const storageKey = await this.getStorageKey();
|
|
91
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
92
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
91
93
|
const encryptedData = await Promise.all(data.map(async (d) => {
|
|
92
94
|
return [
|
|
93
95
|
__classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_createEntryKey).call(this, d[0], storageKey),
|
|
@@ -116,9 +118,9 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
116
118
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
117
119
|
throw new UserStorageError(`failed to batch upsert user storage for path '${path}'. ${errorMessage}`);
|
|
118
120
|
}
|
|
119
|
-
}, _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = async function _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(path, encryptedData) {
|
|
121
|
+
}, _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = async function _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(path, encryptedData, entropySourceId) {
|
|
120
122
|
try {
|
|
121
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
123
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
122
124
|
const url = new URL(STORAGE_URL(this.env, path));
|
|
123
125
|
const response = await fetch(url.toString(), {
|
|
124
126
|
method: 'PUT',
|
|
@@ -144,9 +146,10 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
144
146
|
throw new UserStorageError(`failed to batch upsert user storage for path '${path}'. ${errorMessage}`);
|
|
145
147
|
}
|
|
146
148
|
}, _UserStorage_getUserStorage = async function _UserStorage_getUserStorage(path, options) {
|
|
149
|
+
const entropySourceId = options?.entropySourceId;
|
|
147
150
|
try {
|
|
148
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
149
|
-
const storageKey = await this.getStorageKey();
|
|
151
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
152
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
150
153
|
const encryptedPath = createEntryPath(path, storageKey, {
|
|
151
154
|
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
152
155
|
});
|
|
@@ -183,9 +186,10 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
183
186
|
throw new UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
|
|
184
187
|
}
|
|
185
188
|
}, _UserStorage_getUserStorageAllFeatureEntries = async function _UserStorage_getUserStorageAllFeatureEntries(path, options) {
|
|
189
|
+
const entropySourceId = options?.entropySourceId;
|
|
186
190
|
try {
|
|
187
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
188
|
-
const storageKey = await this.getStorageKey();
|
|
191
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
192
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
189
193
|
const url = new URL(STORAGE_URL(this.env, path));
|
|
190
194
|
const response = await fetch(url.toString(), {
|
|
191
195
|
headers: {
|
|
@@ -228,7 +232,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
228
232
|
}
|
|
229
233
|
// Re-upload the re-encrypted entries
|
|
230
234
|
if (reEncryptedEntries.length) {
|
|
231
|
-
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries).call(this, path, reEncryptedEntries);
|
|
235
|
+
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries).call(this, path, reEncryptedEntries, entropySourceId);
|
|
232
236
|
}
|
|
233
237
|
return decryptedData;
|
|
234
238
|
}
|
|
@@ -238,9 +242,10 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
238
242
|
throw new UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
|
|
239
243
|
}
|
|
240
244
|
}, _UserStorage_deleteUserStorage = async function _UserStorage_deleteUserStorage(path, options) {
|
|
245
|
+
const entropySourceId = options?.entropySourceId;
|
|
241
246
|
try {
|
|
242
|
-
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
243
|
-
const storageKey = await this.getStorageKey();
|
|
247
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
248
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
244
249
|
const encryptedPath = createEntryPath(path, storageKey, {
|
|
245
250
|
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
246
251
|
});
|
|
@@ -268,9 +273,10 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
268
273
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
269
274
|
throw new UserStorageError(`failed to delete user storage for path '${path}'. ${errorMessage}`);
|
|
270
275
|
}
|
|
271
|
-
}, _UserStorage_deleteUserStorageAllFeatureEntries = async function _UserStorage_deleteUserStorageAllFeatureEntries(path) {
|
|
276
|
+
}, _UserStorage_deleteUserStorageAllFeatureEntries = async function _UserStorage_deleteUserStorageAllFeatureEntries(path, options) {
|
|
272
277
|
try {
|
|
273
|
-
const
|
|
278
|
+
const entropySourceId = options?.entropySourceId;
|
|
279
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
274
280
|
const url = new URL(STORAGE_URL(this.env, path));
|
|
275
281
|
const response = await fetch(url.toString(), {
|
|
276
282
|
method: 'DELETE',
|
|
@@ -295,14 +301,15 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
295
301
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
296
302
|
throw new UserStorageError(`failed to delete user storage for path '${path}'. ${errorMessage}`);
|
|
297
303
|
}
|
|
298
|
-
}, _UserStorage_batchDeleteUserStorage = async function _UserStorage_batchDeleteUserStorage(path,
|
|
304
|
+
}, _UserStorage_batchDeleteUserStorage = async function _UserStorage_batchDeleteUserStorage(path, keysToDelete, options) {
|
|
299
305
|
try {
|
|
300
|
-
if (!
|
|
306
|
+
if (!keysToDelete.length) {
|
|
301
307
|
return;
|
|
302
308
|
}
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
const
|
|
309
|
+
const entropySourceId = options?.entropySourceId;
|
|
310
|
+
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this, entropySourceId);
|
|
311
|
+
const storageKey = await this.getStorageKey(entropySourceId);
|
|
312
|
+
const rawEntryKeys = keysToDelete.map((d) => __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_createEntryKey).call(this, d, storageKey));
|
|
306
313
|
const url = new URL(STORAGE_URL(this.env, path));
|
|
307
314
|
const response = await fetch(url.toString(), {
|
|
308
315
|
method: 'PUT',
|
|
@@ -310,7 +317,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
310
317
|
'Content-Type': 'application/json',
|
|
311
318
|
...headers,
|
|
312
319
|
},
|
|
313
|
-
body: JSON.stringify({ batch_delete:
|
|
320
|
+
body: JSON.stringify({ batch_delete: rawEntryKeys }),
|
|
314
321
|
});
|
|
315
322
|
if (!response.ok) {
|
|
316
323
|
const responseBody = await response.json().catch(() => ({
|
|
@@ -326,10 +333,9 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
326
333
|
throw new UserStorageError(`failed to batch delete user storage for path '${path}'. ${errorMessage}`);
|
|
327
334
|
}
|
|
328
335
|
}, _UserStorage_createEntryKey = function _UserStorage_createEntryKey(key, storageKey) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const accessToken = await this.config.auth.getAccessToken();
|
|
336
|
+
return createSHA256Hash(key + storageKey);
|
|
337
|
+
}, _UserStorage_getAuthorizationHeader = async function _UserStorage_getAuthorizationHeader(entropySourceId) {
|
|
338
|
+
const accessToken = await this.config.auth.getAccessToken(entropySourceId);
|
|
333
339
|
return { Authorization: `Bearer ${accessToken}` };
|
|
334
340
|
};
|
|
335
341
|
//# sourceMappingURL=user-storage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAiB;AAC3D,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,uCAA6B;AACpE,OAAO,EAAE,WAAW,EAAE,2CAAuC;AAE7D,OAAO,EAAE,UAAU,EAAE,0BAAsB;AAO3C,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAG3D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,aAAa,EAAE,CAAC;AAgC7E,MAAM,OAAO,WAAW;IAOtB,YAAY,MAAyB,EAAE,OAA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CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,IAAI,gBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;KACH;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC;AACnB,CAAC,wCAED,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;IAC5D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport { NotFoundError, UserStorageError } from './errors';\nimport encryption, { createSHA256Hash } from '../shared/encryption';\nimport { SHARED_SALT } from '../shared/encryption/constants';\nimport type { Env } from '../shared/env';\nimport { getEnvUrls } from '../shared/env';\nimport type {\n UserStorageGenericFeatureKey,\n UserStorageGenericFeatureName,\n UserStorageGenericPathWithFeatureAndKey,\n UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema';\nimport { createEntryPath } from '../shared/storage-schema';\nimport type { NativeScrypt } from '../shared/types/encryption';\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: (message: `metamask:${string}`) => Promise<string | null>;\n setStorageKey: (message: `metamask:${string}`, val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n\n Data: string;\n}[];\n\nexport type UserStorageMethodOptions = {\n validateAgainstSchema?: boolean;\n nativeScryptCrypto?: NativeScrypt;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n public 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: UserStorageGenericPathWithFeatureAndKey,\n value: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value, options);\n }\n\n async batchSetItems(\n path: UserStorageGenericFeatureName,\n values: [UserStorageGenericFeatureKey, string][],\n options?: UserStorageMethodOptions,\n ) {\n await this.#batchUpsertUserStorage(path, values, options);\n }\n\n async getItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n return this.#getUserStorage(path, options);\n }\n\n async getAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path, options);\n }\n\n async deleteItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorage(path, options);\n }\n\n async deleteAllFeatureItems(\n path: UserStorageGenericFeatureName,\n ): Promise<void> {\n return this.#deleteUserStorageAllFeatureEntries(path);\n }\n\n async batchDeleteItems(\n path: UserStorageGenericFeatureName,\n values: UserStorageGenericFeatureKey[],\n ) {\n return this.#batchDeleteUserStorage(path, values);\n }\n\n async getStorageKey(): Promise<string> {\n const userProfile = await this.config.auth.getUserProfile();\n const message = `metamask:${userProfile.profileId}` as const;\n\n const storageKey = await this.options.storage?.getStorageKey(message);\n if (storageKey) {\n return storageKey;\n }\n\n const storageKeySignature = await this.config.auth.signMessage(message);\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(\n message,\n hashedStorageKeySignature,\n );\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n data: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 #batchUpsertUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: [string, string][],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => {\n return [\n this.#createEntryKey(d[0], storageKey),\n await encryption.encryptString(\n d[1],\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ];\n }),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(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 batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n encryptedData: [string, string][],\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(encryptedData) }),\n });\n\n // istanbul ignore next\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 // istanbul ignore next\n throw new UserStorageError(\n `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 return null;\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 = await response.json();\n const encryptedData = userStorage?.Data ?? null;\n\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n storageKey,\n options?.nativeScryptCrypto,\n );\n\n // Re-encrypt the entry if it was encrypted with a random salt\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await this.#upsertUserStorage(path, decryptedData, options);\n }\n\n return decryptedData;\n } catch (e) {\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: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\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 return null;\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: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry was encrypted with a random salt\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path,\n reEncryptedEntries,\n );\n }\n\n return decryptedData;\n } catch (e) {\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 #deleteUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchDeleteUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: string[],\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => this.#createEntryKey(d, storageKey)),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n\n body: JSON.stringify({ batch_delete: 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 batch delete 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 async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAiB;AAC3D,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,uCAA6B;AACpE,OAAO,EAAE,WAAW,EAAE,2CAAuC;AAE7D,OAAO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I,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAC3E,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport { NotFoundError, UserStorageError } from './errors';\nimport encryption, { createSHA256Hash } from '../shared/encryption';\nimport { SHARED_SALT } from '../shared/encryption/constants';\nimport type { Env } from '../shared/env';\nimport { getEnvUrls } from '../shared/env';\nimport type {\n UserStorageGenericFeatureKey,\n UserStorageGenericFeatureName,\n UserStorageGenericPathWithFeatureAndKey,\n UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema';\nimport { createEntryPath } from '../shared/storage-schema';\nimport type { NativeScrypt } from '../shared/types/encryption';\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: (message: `metamask:${string}`) => Promise<string | null>;\n setStorageKey: (message: `metamask:${string}`, val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n\n Data: string;\n}[];\n\nexport type UserStorageMethodOptions = {\n validateAgainstSchema?: boolean;\n nativeScryptCrypto?: NativeScrypt;\n entropySourceId?: string;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n public 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: UserStorageGenericPathWithFeatureAndKey,\n value: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value, options);\n }\n\n async batchSetItems(\n path: UserStorageGenericFeatureName,\n values: [UserStorageGenericFeatureKey, string][],\n options?: UserStorageMethodOptions,\n ) {\n await this.#batchUpsertUserStorage(path, values, options);\n }\n\n async getItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n return this.#getUserStorage(path, options);\n }\n\n async getAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path, options);\n }\n\n async deleteItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorage(path, options);\n }\n\n async deleteAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorageAllFeatureEntries(path, options);\n }\n\n async batchDeleteItems(\n path: UserStorageGenericFeatureName,\n values: UserStorageGenericFeatureKey[],\n options?: UserStorageMethodOptions,\n ) {\n return this.#batchDeleteUserStorage(path, values, options);\n }\n\n async getStorageKey(entropySourceId?: string): Promise<string> {\n const userProfile = await this.config.auth.getUserProfile(entropySourceId);\n const message = `metamask:${userProfile.profileId}` as const;\n\n const storageKey = await this.options.storage?.getStorageKey(message);\n if (storageKey) {\n return storageKey;\n }\n\n const storageKeySignature = await this.config.auth.signMessage(\n message,\n entropySourceId,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(\n message,\n hashedStorageKeySignature,\n );\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n data: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedData = await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 #batchUpsertUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: [string, string][],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n\n const encryptedData = await Promise.all(\n data.map(async (d) => {\n return [\n this.#createEntryKey(d[0], storageKey),\n await encryption.encryptString(\n d[1],\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ];\n }),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(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 batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n encryptedData: [string, string][],\n entropySourceId?: string,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(encryptedData) }),\n });\n\n // istanbul ignore next\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 // istanbul ignore next\n throw new UserStorageError(\n `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 return null;\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 = await response.json();\n const encryptedData = userStorage?.Data ?? null;\n\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n storageKey,\n options?.nativeScryptCrypto,\n );\n\n // Re-encrypt the entry if it was encrypted with a random salt\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await this.#upsertUserStorage(path, decryptedData, options);\n }\n\n return decryptedData;\n } catch (e) {\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: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\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 return null;\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: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry was encrypted with a random salt\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path,\n reEncryptedEntries,\n entropySourceId,\n );\n }\n\n return decryptedData;\n } catch (e) {\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 #deleteUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const entropySourceId = options?.entropySourceId;\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchDeleteUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n keysToDelete: string[],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n if (!keysToDelete.length) {\n return;\n }\n\n const entropySourceId = options?.entropySourceId;\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n\n const rawEntryKeys = keysToDelete.map((d) =>\n this.#createEntryKey(d, storageKey),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n\n body: JSON.stringify({ batch_delete: rawEntryKeys }),\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 batch delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n return createSHA256Hash(key + storageKey);\n }\n\n async #getAuthorizationHeader(\n entropySourceId?: string,\n ): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken(entropySourceId);\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"]}
|
|
@@ -52,19 +52,31 @@ async function isSnapConnected(provider) {
|
|
|
52
52
|
}
|
|
53
53
|
exports.isSnapConnected = isSnapConnected;
|
|
54
54
|
exports.MESSAGE_SIGNING_SNAP = {
|
|
55
|
-
async getPublicKey(provider) {
|
|
55
|
+
async getPublicKey(provider, entropySourceId) {
|
|
56
56
|
const publicKey = await provider.request({
|
|
57
57
|
method: 'wallet_invokeSnap',
|
|
58
|
-
params: {
|
|
58
|
+
params: {
|
|
59
|
+
snapId: exports.SNAP_ORIGIN,
|
|
60
|
+
request: {
|
|
61
|
+
method: 'getPublicKey',
|
|
62
|
+
...(entropySourceId ? { params: { entropySourceId } } : {}),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
59
65
|
});
|
|
60
66
|
return publicKey;
|
|
61
67
|
},
|
|
62
|
-
async signMessage(provider, message) {
|
|
68
|
+
async signMessage(provider, message, entropySourceId) {
|
|
63
69
|
const signedMessage = await provider?.request({
|
|
64
70
|
method: 'wallet_invokeSnap',
|
|
65
71
|
params: {
|
|
66
72
|
snapId: exports.SNAP_ORIGIN,
|
|
67
|
-
request: {
|
|
73
|
+
request: {
|
|
74
|
+
method: 'signMessage',
|
|
75
|
+
params: {
|
|
76
|
+
message,
|
|
77
|
+
...(entropySourceId ? { entropySourceId } : {}),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
68
80
|
},
|
|
69
81
|
});
|
|
70
82
|
return signedMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-signing-snap-requests.cjs","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":";;;AAUa,QAAA,WAAW,GAAG,oCAAoC,CAAC;AAEhE;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAAC,QAAyB;IACzD,MAAM,MAAM,GAAW,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,mBAAW,CAAC,EAAE,EAAE;SAClB;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,kCASC;AAED;;;;;GAKG;AACI,KAAK,UAAU,QAAQ,CAC5B,QAAyB;IAEzB,MAAM,MAAM,GAAqB,MAAM,QAAQ,CAAC,OAAO,CAAC;QACtD,MAAM,EAAE,iBAAiB;KAC1B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,4BAQC;AAED;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,QAAyB;IAEzB,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,KAAK,CAAC;SACd;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,mBAAW,CAAC,CAAC;KACjD;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAbD,0CAaC;AAEY,QAAA,oBAAoB,GAAG;IAClC,KAAK,CAAC,YAAY,CAAC,QAAyB;
|
|
1
|
+
{"version":3,"file":"messaging-signing-snap-requests.cjs","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":";;;AAUa,QAAA,WAAW,GAAG,oCAAoC,CAAC;AAEhE;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAAC,QAAyB;IACzD,MAAM,MAAM,GAAW,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,mBAAW,CAAC,EAAE,EAAE;SAClB;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,kCASC;AAED;;;;;GAKG;AACI,KAAK,UAAU,QAAQ,CAC5B,QAAyB;IAEzB,MAAM,MAAM,GAAqB,MAAM,QAAQ,CAAC,OAAO,CAAC;QACtD,MAAM,EAAE,iBAAiB;KAC1B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AA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;aACF;SACF,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,OAAe;IAEf,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;AACH,CAAC;AAND,0EAMC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nexport type Snap = {\n permissionName: string;\n id: string;\n version: string;\n initialPermissions: Record<string, unknown>;\n};\nexport type GetSnapsResponse = Record<string, Snap>;\n\nexport const SNAP_ORIGIN = 'npm:@metamask/message-signing-snap';\n\n/**\n * Requests Connection to the Message Signing Snap\n *\n * @param provider - MetaMask Wallet Provider\n * @returns snap connect result\n */\nexport async function connectSnap(provider: Eip1193Provider): Promise<string> {\n const result: string = await provider.request({\n method: 'wallet_requestSnaps',\n params: {\n [SNAP_ORIGIN]: {},\n },\n });\n\n return result;\n}\n\n/**\n * Gets Snaps from a MetaMask Wallet\n *\n * @param provider - MetaMask Wallet Provider\n * @returns All currently installed snaps.\n */\nexport async function getSnaps(\n provider: Eip1193Provider,\n): Promise<GetSnapsResponse> {\n const result: GetSnapsResponse = await provider.request({\n method: 'wallet_getSnaps',\n });\n\n return result;\n}\n\n/**\n * Check if snap is connected\n *\n * @param provider - MetaMask Wallet Provider\n * @returns if snap is connected\n */\nexport async function isSnapConnected(\n provider: Eip1193Provider,\n): Promise<boolean> {\n try {\n const snaps = await getSnaps(provider);\n if (!snaps) {\n return false;\n }\n return Object.keys(snaps).includes(SNAP_ORIGIN);\n } catch (e) {\n console.error('Failed to determine if snap is connected', e);\n return false;\n }\n}\n\nexport const MESSAGE_SIGNING_SNAP = {\n async getPublicKey(provider: Eip1193Provider, entropySourceId?: string) {\n const publicKey: string = await provider.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'getPublicKey',\n ...(entropySourceId ? { params: { entropySourceId } } : {}),\n },\n },\n });\n\n return publicKey;\n },\n\n async signMessage(\n provider: Eip1193Provider,\n message: `metamask:${string}`,\n entropySourceId?: string,\n ) {\n const signedMessage: string = await provider?.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'signMessage',\n params: {\n message,\n ...(entropySourceId ? { entropySourceId } : {}),\n },\n },\n },\n });\n\n return signedMessage;\n },\n};\n\n/**\n * Asserts that a message starts with \"metamask:\"\n *\n * @param message - The message to check.\n */\nexport function assertMessageStartsWithMetamask(\n message: string,\n): asserts message is `metamask:${string}` {\n if (!message.startsWith('metamask:')) {\n throw new Error('Message must start with \"metamask:\"');\n }\n}\n"]}
|
|
@@ -29,8 +29,8 @@ export declare function getSnaps(provider: Eip1193Provider): Promise<GetSnapsRes
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function isSnapConnected(provider: Eip1193Provider): Promise<boolean>;
|
|
31
31
|
export declare const MESSAGE_SIGNING_SNAP: {
|
|
32
|
-
getPublicKey(provider: Eip1193Provider): Promise<string>;
|
|
33
|
-
signMessage(provider: Eip1193Provider, message: `metamask:${string}
|
|
32
|
+
getPublicKey(provider: Eip1193Provider, entropySourceId?: string): Promise<string>;
|
|
33
|
+
signMessage(provider: Eip1193Provider, message: `metamask:${string}`, entropySourceId?: string): Promise<string>;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Asserts that a message starts with "metamask:"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-signing-snap-requests.d.cts","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,eAAO,MAAM,oBAAoB;2BACF,eAAe;
|
|
1
|
+
{"version":3,"file":"messaging-signing-snap-requests.d.cts","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,eAAO,MAAM,oBAAoB;2BACF,eAAe,oBAAoB,MAAM;0BAgB1D,eAAe,WAChB,YAAY,MAAM,EAAE,oBACX,MAAM;CAkB3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,IAAI,YAAY,MAAM,EAAE,CAIzC"}
|
|
@@ -29,8 +29,8 @@ export declare function getSnaps(provider: Eip1193Provider): Promise<GetSnapsRes
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function isSnapConnected(provider: Eip1193Provider): Promise<boolean>;
|
|
31
31
|
export declare const MESSAGE_SIGNING_SNAP: {
|
|
32
|
-
getPublicKey(provider: Eip1193Provider): Promise<string>;
|
|
33
|
-
signMessage(provider: Eip1193Provider, message: `metamask:${string}
|
|
32
|
+
getPublicKey(provider: Eip1193Provider, entropySourceId?: string): Promise<string>;
|
|
33
|
+
signMessage(provider: Eip1193Provider, message: `metamask:${string}`, entropySourceId?: string): Promise<string>;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Asserts that a message starts with "metamask:"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-signing-snap-requests.d.mts","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,eAAO,MAAM,oBAAoB;2BACF,eAAe;
|
|
1
|
+
{"version":3,"file":"messaging-signing-snap-requests.d.mts","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,eAAO,MAAM,oBAAoB;2BACF,eAAe,oBAAoB,MAAM;0BAgB1D,eAAe,WAChB,YAAY,MAAM,EAAE,oBACX,MAAM;CAkB3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,IAAI,YAAY,MAAM,EAAE,CAIzC"}
|
|
@@ -46,19 +46,31 @@ export async function isSnapConnected(provider) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export const MESSAGE_SIGNING_SNAP = {
|
|
49
|
-
async getPublicKey(provider) {
|
|
49
|
+
async getPublicKey(provider, entropySourceId) {
|
|
50
50
|
const publicKey = await provider.request({
|
|
51
51
|
method: 'wallet_invokeSnap',
|
|
52
|
-
params: {
|
|
52
|
+
params: {
|
|
53
|
+
snapId: SNAP_ORIGIN,
|
|
54
|
+
request: {
|
|
55
|
+
method: 'getPublicKey',
|
|
56
|
+
...(entropySourceId ? { params: { entropySourceId } } : {}),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
53
59
|
});
|
|
54
60
|
return publicKey;
|
|
55
61
|
},
|
|
56
|
-
async signMessage(provider, message) {
|
|
62
|
+
async signMessage(provider, message, entropySourceId) {
|
|
57
63
|
const signedMessage = await provider?.request({
|
|
58
64
|
method: 'wallet_invokeSnap',
|
|
59
65
|
params: {
|
|
60
66
|
snapId: SNAP_ORIGIN,
|
|
61
|
-
request: {
|
|
67
|
+
request: {
|
|
68
|
+
method: 'signMessage',
|
|
69
|
+
params: {
|
|
70
|
+
message,
|
|
71
|
+
...(entropySourceId ? { entropySourceId } : {}),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
62
74
|
},
|
|
63
75
|
});
|
|
64
76
|
return signedMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-signing-snap-requests.mjs","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAyB;IACzD,MAAM,MAAM,GAAW,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,WAAW,CAAC,EAAE,EAAE;SAClB;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,QAAyB;IAEzB,MAAM,MAAM,GAAqB,MAAM,QAAQ,CAAC,OAAO,CAAC;QACtD,MAAM,EAAE,iBAAiB;KAC1B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAAyB;IAEzB,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,KAAK,CAAC;SACd;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KACjD;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,KAAK,CAAC,YAAY,CAAC,QAAyB;
|
|
1
|
+
{"version":3,"file":"messaging-signing-snap-requests.mjs","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAyB;IACzD,MAAM,MAAM,GAAW,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,WAAW,CAAC,EAAE,EAAE;SAClB;KACF,CAAC,CAAC;IAEH,OAAO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B,MAAM,EAAE;gBACN,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE;oBACP,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE;wBACN,OAAO;wBACP,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAChD;iBACF;aACF;SACF,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAe;IAEf,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;AACH,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nexport type Snap = {\n permissionName: string;\n id: string;\n version: string;\n initialPermissions: Record<string, unknown>;\n};\nexport type GetSnapsResponse = Record<string, Snap>;\n\nexport const SNAP_ORIGIN = 'npm:@metamask/message-signing-snap';\n\n/**\n * Requests Connection to the Message Signing Snap\n *\n * @param provider - MetaMask Wallet Provider\n * @returns snap connect result\n */\nexport async function connectSnap(provider: Eip1193Provider): Promise<string> {\n const result: string = await provider.request({\n method: 'wallet_requestSnaps',\n params: {\n [SNAP_ORIGIN]: {},\n },\n });\n\n return result;\n}\n\n/**\n * Gets Snaps from a MetaMask Wallet\n *\n * @param provider - MetaMask Wallet Provider\n * @returns All currently installed snaps.\n */\nexport async function getSnaps(\n provider: Eip1193Provider,\n): Promise<GetSnapsResponse> {\n const result: GetSnapsResponse = await provider.request({\n method: 'wallet_getSnaps',\n });\n\n return result;\n}\n\n/**\n * Check if snap is connected\n *\n * @param provider - MetaMask Wallet Provider\n * @returns if snap is connected\n */\nexport async function isSnapConnected(\n provider: Eip1193Provider,\n): Promise<boolean> {\n try {\n const snaps = await getSnaps(provider);\n if (!snaps) {\n return false;\n }\n return Object.keys(snaps).includes(SNAP_ORIGIN);\n } catch (e) {\n console.error('Failed to determine if snap is connected', e);\n return false;\n }\n}\n\nexport const MESSAGE_SIGNING_SNAP = {\n async getPublicKey(provider: Eip1193Provider, entropySourceId?: string) {\n const publicKey: string = await provider.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'getPublicKey',\n ...(entropySourceId ? { params: { entropySourceId } } : {}),\n },\n },\n });\n\n return publicKey;\n },\n\n async signMessage(\n provider: Eip1193Provider,\n message: `metamask:${string}`,\n entropySourceId?: string,\n ) {\n const signedMessage: string = await provider?.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'signMessage',\n params: {\n message,\n ...(entropySourceId ? { entropySourceId } : {}),\n },\n },\n },\n });\n\n return signedMessage;\n },\n};\n\n/**\n * Asserts that a message starts with \"metamask:\"\n *\n * @param message - The message to check.\n */\nexport function assertMessageStartsWithMetamask(\n message: string,\n): asserts message is `metamask:${string}` {\n if (!message.startsWith('metamask:')) {\n throw new Error('Message must start with \"metamask:\"');\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEntryPath = exports.
|
|
3
|
+
exports.createEntryPath = exports.getFeatureAndKeyFromPath = exports.USER_STORAGE_SCHEMA = exports.USER_STORAGE_FEATURE_NAMES = void 0;
|
|
4
4
|
const encryption_1 = require("./encryption/index.cjs");
|
|
5
5
|
/**
|
|
6
6
|
* The User Storage Endpoint requires a feature name and a namespace key.
|
|
@@ -42,11 +42,6 @@ const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema: true
|
|
|
42
42
|
return { feature, key };
|
|
43
43
|
};
|
|
44
44
|
exports.getFeatureAndKeyFromPath = getFeatureAndKeyFromPath;
|
|
45
|
-
const isPathWithFeatureAndKey = (path) => {
|
|
46
|
-
const pathRegex = /^\w+\.\w+$/u;
|
|
47
|
-
return pathRegex.test(path);
|
|
48
|
-
};
|
|
49
|
-
exports.isPathWithFeatureAndKey = isPathWithFeatureAndKey;
|
|
50
45
|
/**
|
|
51
46
|
* Constructs a unique entry path for a user.
|
|
52
47
|
* This can be done due to the uniqueness of the storage key (no users will share the same storage key).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-schema.cjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,sBAA+B,CAAC;AAEhD,QAAA,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAKE,QAAA,mBAAmB,GAAG;IACjC,CAAC,kCAA0B,CAAC,aAAa,CAAC,EAAE,CAAC,uBAAuB,CAAC;IACrE,CAAC,kCAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC;IAC7D,CAAC,kCAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,2BAA2B;CAClF,CAAC;AAuCJ,MAAM,wBAAwB,GAAG,CACtC,IAE2C,EAC3C,UAEI,EAAE,qBAAqB,EAAE,IAAS,EAAE,EAGN,EAAE;IACpC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvC,IAAI,OAAO,CAAC,qBAAqB,EAAE;QACjC,MAAM,iBAAiB,GAAG,OAAkC,CAAC;QAC7D,MAAM,aAAa,GAAG,GAErB,CAAC;QAEF,IAAI,CAAC,CAAC,iBAAiB,IAAI,2BAAmB,CAAC,EAAE;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6BAAgB,EAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC;AAbD,0CAaC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n} as const;\n\nexport type UserStorageFeatureNames =\n (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];\n\nexport const USER_STORAGE_SCHEMA = {\n [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],\n [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatureNames;\n key: UserStorageFeatureKeys<UserStorageFeatureNames>;\n};\n\nexport type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\n/**\n * The below types are mainly used for the SDK.\n * These exist so that the SDK can be used with arbitrary feature names and keys.\n *\n * We only type enforce feature names and keys when using UserStorageController.\n * This is done so we don't end up with magic strings within the applications.\n */\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = <T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n if (options.validateAgainstSchema) {\n const featureToValidate = feature as UserStorageFeatureNames;\n const keyToValidate = key as UserStorageFeatureKeys<\n typeof featureToValidate\n >;\n\n if (!(featureToValidate in USER_STORAGE_SCHEMA)) {\n throw new Error(\n `user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(\n USER_STORAGE_SCHEMA,\n ).join(', ')}`,\n );\n }\n\n const validFeature = USER_STORAGE_SCHEMA[\n featureToValidate\n ] as readonly string[];\n\n if (\n !validFeature.includes(keyToValidate) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`,\n );\n }\n }\n\n return { feature, key } as T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @param options - options object\n * @param options.validateAgainstSchema - whether to validate the path against the schema.\n * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.\n * @returns path to store entry\n */\nexport function createEntryPath<T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path, options);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
|
|
@@ -45,7 +45,6 @@ type UserStorageGenericFeatureAndKey = {
|
|
|
45
45
|
export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : `${string}.${string}`, options?: {
|
|
46
46
|
validateAgainstSchema: T;
|
|
47
47
|
}) => T extends true ? UserStorageFeatureAndKey : UserStorageGenericFeatureAndKey;
|
|
48
|
-
export declare const isPathWithFeatureAndKey: (path: string) => path is UserStoragePathWithFeatureAndKey;
|
|
49
48
|
/**
|
|
50
49
|
* Constructs a unique entry path for a user.
|
|
51
50
|
* This can be done due to the uniqueness of the storage key (no users will share the same storage key).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-schema.d.cts","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,wBAAkC,CAAC;AAE7D,eAAO,MAAM,0BAA0B;;;;CAI7B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,OAAO,0BAA0B,CAAC,CAAC;AAE/E,eAAO,MAAM,mBAAmB;;;;CAItB,CAAC;AAEX,KAAK,iBAAiB,GAAG,OAA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{
|
|
|
45
45
|
export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : `${string}.${string}`, options?: {
|
|
46
46
|
validateAgainstSchema: T;
|
|
47
47
|
}) => T extends true ? UserStorageFeatureAndKey : UserStorageGenericFeatureAndKey;
|
|
48
|
-
export declare const isPathWithFeatureAndKey: (path: string) => path is UserStoragePathWithFeatureAndKey;
|
|
49
48
|
/**
|
|
50
49
|
* Constructs a unique entry path for a user.
|
|
51
50
|
* This can be done due to the uniqueness of the storage key (no users will share the same storage key).
|