@idos-network/enclave 1.5.0 → 2.2.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/dist/{base-D5Ywnfua.d.mts → base-CjIdohef.d.mts} +4 -4
- package/dist/{base-D5Ywnfua.d.mts.map → base-CjIdohef.d.mts.map} +1 -1
- package/dist/client-Dqb0xbdb.mjs +2 -0
- package/dist/{client-4H2-Ewlq.mjs.map → client-Dqb0xbdb.mjs.map} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/keys-P2XLU3qP.mjs +2 -0
- package/dist/keys-P2XLU3qP.mjs.map +1 -0
- package/dist/local.d.mts +3 -4
- package/dist/local.d.mts.map +1 -1
- package/dist/local.mjs +1 -252
- package/dist/local.mjs.map +1 -1
- package/dist/mpc/index.mjs +1 -2
- package/package.json +8 -8
- package/src/base.test.ts +1 -1
- package/src/base.ts +5 -1
- package/src/local.test.ts +160 -1
- package/src/local.ts +39 -15
- package/dist/client-4H2-Ewlq.mjs +0 -1197
- package/dist/keys-DLzoEkkD.mjs +0 -187
- package/dist/keys-DLzoEkkD.mjs.map +0 -1
package/src/local.ts
CHANGED
|
@@ -96,7 +96,7 @@ export class LocalEnclave<
|
|
|
96
96
|
async reset(): Promise<void> {
|
|
97
97
|
await super.reset();
|
|
98
98
|
this.storedEncryptionProfile = undefined;
|
|
99
|
-
this.store.reset();
|
|
99
|
+
await this.store.reset();
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/** @override parent method to reconfigure the enclave */
|
|
@@ -266,26 +266,32 @@ export class LocalEnclave<
|
|
|
266
266
|
* @see BaseProvider#getPrivateEncryptionProfile
|
|
267
267
|
*/
|
|
268
268
|
async getPrivateEncryptionProfile(skipGuard = false): Promise<PrivateEncryptionProfile> {
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
// Remember duration is a key-use check. A long-lived iframe keeps this profile
|
|
270
|
+
// in memory, so construction-time store expiry is not enough.
|
|
271
|
+
if (this.storedEncryptionProfile && (await this.store.hasRememberDurationElapsed())) {
|
|
272
|
+
await this.reset();
|
|
273
|
+
}
|
|
272
274
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
if (this.storedEncryptionProfile?.userId === this.userId) {
|
|
276
|
+
// A matching cached profile still needs origin authorization before key use.
|
|
277
|
+
// Denying it must keep the profile and the allowlist; only a different user resets.
|
|
278
|
+
if (!skipGuard && !(await this.guardKeys())) {
|
|
279
|
+
throw new Error("Origin is not authorized to use the keys");
|
|
277
280
|
}
|
|
278
281
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
+
return this.storedEncryptionProfile;
|
|
283
|
+
}
|
|
282
284
|
|
|
283
|
-
|
|
284
|
-
// and reset the enclave.
|
|
285
|
+
if (this.storedEncryptionProfile) {
|
|
285
286
|
await this.reset();
|
|
286
287
|
}
|
|
287
288
|
|
|
288
|
-
|
|
289
|
+
if (this.options.encryptionPasswordStore === "mm") {
|
|
290
|
+
throw new Error(
|
|
291
|
+
"MM encryption profiles require an externally supplied encryption private key",
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
289
295
|
let password: string | undefined;
|
|
290
296
|
let encryptionPasswordStore: EncryptionPasswordStore | undefined;
|
|
291
297
|
|
|
@@ -310,7 +316,18 @@ export class LocalEnclave<
|
|
|
310
316
|
throw new Error("Password or encryption password store is not found");
|
|
311
317
|
}
|
|
312
318
|
|
|
313
|
-
|
|
319
|
+
const profile = await this.createEncryptionProfileFromPassword(
|
|
320
|
+
password,
|
|
321
|
+
this.userId,
|
|
322
|
+
encryptionPasswordStore,
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
// Same origin check as the cached path. Password or MPC success is not authorization.
|
|
326
|
+
if (!skipGuard && !(await this.guardKeys())) {
|
|
327
|
+
throw new Error("Origin is not authorized to use the keys");
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return profile;
|
|
314
331
|
}
|
|
315
332
|
|
|
316
333
|
/** @see BaseProvider#ensureUserEncryptionProfile */
|
|
@@ -351,6 +368,13 @@ export class LocalEnclave<
|
|
|
351
368
|
|
|
352
369
|
const keyPair = nacl.box.keyPair.fromSecretKey(secretKey);
|
|
353
370
|
|
|
371
|
+
const expectedPublicKey = this.options.expectedUserEncryptionPublicKey;
|
|
372
|
+
if (expectedPublicKey && base64Encode(keyPair.publicKey) !== expectedPublicKey) {
|
|
373
|
+
throw new Error(
|
|
374
|
+
"Derived encryption public key does not match expectedUserEncryptionPublicKey",
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
354
378
|
await this.store.set(STORAGE_KEYS.USER_ID, userId);
|
|
355
379
|
await this.storeObfuscated.set(STORAGE_KEYS.OBFUSCATED_PASSWORD, password);
|
|
356
380
|
await this.store.delete(STORAGE_KEYS.DEPRECATED___PASSWORD);
|