jazz-tools 0.10.13 → 0.10.14
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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-GSIV52ZH.js → chunk-5YDDEUNX.js} +15 -18
- package/dist/chunk-5YDDEUNX.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/src/auth/AuthSecretStorage.ts +10 -9
- package/src/implementation/ContextManager.ts +1 -7
- package/src/implementation/createContext.ts +3 -3
- package/src/tests/AuthSecretStorage.test.ts +8 -9
- package/src/tests/PassphraseAuth.test.ts +1 -2
- package/tsconfig.json +1 -1
- package/dist/chunk-GSIV52ZH.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/testing.js
CHANGED
package/package.json
CHANGED
@@ -16,7 +16,6 @@ export type AuthSetPayload = {
|
|
16
16
|
export class AuthSecretStorage {
|
17
17
|
private listeners: Set<(isAuthenticated: boolean) => void>;
|
18
18
|
public isAuthenticated: boolean;
|
19
|
-
notify = false;
|
20
19
|
|
21
20
|
constructor() {
|
22
21
|
this.listeners = new Set();
|
@@ -97,7 +96,7 @@ export class AuthSecretStorage {
|
|
97
96
|
};
|
98
97
|
}
|
99
98
|
|
100
|
-
async
|
99
|
+
async setWithoutNotify(payload: AuthSetPayload) {
|
101
100
|
const kvStore = KvStoreContext.getInstance().getStorage();
|
102
101
|
await kvStore.set(
|
103
102
|
STORAGE_KEY,
|
@@ -110,10 +109,11 @@ export class AuthSecretStorage {
|
|
110
109
|
provider: payload.provider,
|
111
110
|
}),
|
112
111
|
);
|
112
|
+
}
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
async set(payload: AuthSetPayload) {
|
115
|
+
this.setWithoutNotify(payload);
|
116
|
+
this.emitUpdate(payload);
|
117
117
|
}
|
118
118
|
|
119
119
|
getIsAuthenticated(data: AuthCredentials | null): boolean {
|
@@ -139,12 +139,13 @@ export class AuthSecretStorage {
|
|
139
139
|
}
|
140
140
|
}
|
141
141
|
|
142
|
-
async
|
142
|
+
async clearWithoutNotify() {
|
143
143
|
const kvStore = KvStoreContext.getInstance().getStorage();
|
144
144
|
await kvStore.delete(STORAGE_KEY);
|
145
|
+
}
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
async clear() {
|
148
|
+
await this.clearWithoutNotify();
|
149
|
+
this.emitUpdate(null);
|
149
150
|
}
|
150
151
|
}
|
@@ -43,10 +43,6 @@ export class JazzContextManager<
|
|
43
43
|
protected context: PlatformSpecificContext<Acc> | undefined;
|
44
44
|
protected props: P | undefined;
|
45
45
|
protected authSecretStorage = new AuthSecretStorage();
|
46
|
-
protected authSecretStorageWithNotify = Object.assign(
|
47
|
-
Object.create(this.authSecretStorage),
|
48
|
-
{ notify: true },
|
49
|
-
);
|
50
46
|
protected authenticating = false;
|
51
47
|
|
52
48
|
constructor() {
|
@@ -103,9 +99,7 @@ export class JazzContextManager<
|
|
103
99
|
}
|
104
100
|
|
105
101
|
getAuthSecretStorage() {
|
106
|
-
|
107
|
-
// We skip internal notify to ensure that the isAuthenticated changes are notified along with the context updates
|
108
|
-
return this.authSecretStorageWithNotify;
|
102
|
+
return this.authSecretStorage;
|
109
103
|
}
|
110
104
|
|
111
105
|
logOut = async () => {
|
@@ -219,7 +219,7 @@ export async function createJazzContext<Acc extends Account>(options: {
|
|
219
219
|
AccountSchema: options.AccountSchema,
|
220
220
|
sessionProvider: options.sessionProvider,
|
221
221
|
onLogOut: () => {
|
222
|
-
authSecretStorage.
|
222
|
+
authSecretStorage.clearWithoutNotify();
|
223
223
|
},
|
224
224
|
});
|
225
225
|
} else {
|
@@ -240,12 +240,12 @@ export async function createJazzContext<Acc extends Account>(options: {
|
|
240
240
|
crypto,
|
241
241
|
AccountSchema: options.AccountSchema,
|
242
242
|
onLogOut: async () => {
|
243
|
-
await authSecretStorage.
|
243
|
+
await authSecretStorage.clearWithoutNotify();
|
244
244
|
},
|
245
245
|
});
|
246
246
|
|
247
247
|
if (!options.newAccountProps) {
|
248
|
-
await authSecretStorage.
|
248
|
+
await authSecretStorage.setWithoutNotify({
|
249
249
|
accountID: context.account.id,
|
250
250
|
secretSeed,
|
251
251
|
accountSecret: context.node.account.agentSecret,
|
@@ -257,11 +257,10 @@ describe("AuthSecretStorage", () => {
|
|
257
257
|
});
|
258
258
|
});
|
259
259
|
|
260
|
-
describe("notify
|
260
|
+
describe("notify", () => {
|
261
261
|
beforeEach(() => {
|
262
262
|
kvStore.clearAll();
|
263
263
|
authSecretStorage = new AuthSecretStorage();
|
264
|
-
authSecretStorage.notify = true;
|
265
264
|
});
|
266
265
|
|
267
266
|
describe("set", () => {
|
@@ -337,7 +336,7 @@ describe("AuthSecretStorage", () => {
|
|
337
336
|
});
|
338
337
|
});
|
339
338
|
|
340
|
-
describe("notify
|
339
|
+
describe("without notify", () => {
|
341
340
|
beforeEach(() => {
|
342
341
|
kvStore.clearAll();
|
343
342
|
authSecretStorage = new AuthSecretStorage();
|
@@ -348,7 +347,7 @@ describe("AuthSecretStorage", () => {
|
|
348
347
|
const handler = vi.fn();
|
349
348
|
authSecretStorage.onUpdate(handler);
|
350
349
|
|
351
|
-
await authSecretStorage.
|
350
|
+
await authSecretStorage.setWithoutNotify({
|
352
351
|
accountID: "test123" as ID<Account>,
|
353
352
|
accountSecret:
|
354
353
|
"secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
|
@@ -365,7 +364,7 @@ describe("AuthSecretStorage", () => {
|
|
365
364
|
});
|
366
365
|
|
367
366
|
it("should return false for anonymous credentials", async () => {
|
368
|
-
await authSecretStorage.
|
367
|
+
await authSecretStorage.setWithoutNotify({
|
369
368
|
accountID: "test123" as ID<Account>,
|
370
369
|
accountSecret:
|
371
370
|
"secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
|
@@ -376,7 +375,7 @@ describe("AuthSecretStorage", () => {
|
|
376
375
|
});
|
377
376
|
|
378
377
|
it("should return true for non-anonymous credentials", async () => {
|
379
|
-
await authSecretStorage.
|
378
|
+
await authSecretStorage.setWithoutNotify({
|
380
379
|
accountID: "test123" as ID<Account>,
|
381
380
|
accountSecret:
|
382
381
|
"secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
|
@@ -395,7 +394,7 @@ describe("AuthSecretStorage", () => {
|
|
395
394
|
});
|
396
395
|
|
397
396
|
it("should return true when the provider is missing", async () => {
|
398
|
-
await authSecretStorage.
|
397
|
+
await authSecretStorage.setWithoutNotify({
|
399
398
|
accountID: "test123" as ID<Account>,
|
400
399
|
accountSecret:
|
401
400
|
"secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
|
@@ -414,7 +413,7 @@ describe("AuthSecretStorage", () => {
|
|
414
413
|
|
415
414
|
describe("clear", () => {
|
416
415
|
it("should not emit update event when clearing", async () => {
|
417
|
-
await authSecretStorage.
|
416
|
+
await authSecretStorage.setWithoutNotify({
|
418
417
|
accountID: "test123" as ID<Account>,
|
419
418
|
accountSecret:
|
420
419
|
"secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
|
@@ -424,7 +423,7 @@ describe("AuthSecretStorage", () => {
|
|
424
423
|
const handler = vi.fn();
|
425
424
|
authSecretStorage.onUpdate(handler);
|
426
425
|
|
427
|
-
await authSecretStorage.
|
426
|
+
await authSecretStorage.clearWithoutNotify();
|
428
427
|
|
429
428
|
expect(handler).not.toHaveBeenCalled();
|
430
429
|
});
|
@@ -1,8 +1,7 @@
|
|
1
1
|
// @vitest-environment happy-dom
|
2
2
|
|
3
|
-
import { mnemonicToEntropy } from "@scure/bip39";
|
4
3
|
import { AgentSecret } from "cojson";
|
5
|
-
import { PureJSCrypto } from "cojson/
|
4
|
+
import { PureJSCrypto } from "cojson/crypto/PureJSCrypto";
|
6
5
|
import {
|
7
6
|
Account,
|
8
7
|
AuthSecretStorage,
|
package/tsconfig.json
CHANGED