jazz-tools 0.10.8 → 0.10.13
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 +12 -0
- package/dist/{chunk-6OJCOJJ6.js → chunk-GSIV52ZH.js} +78 -23
- package/dist/chunk-GSIV52ZH.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/src/auth/PassphraseAuth.ts +33 -2
- package/src/coValues/deepLoading.ts +0 -1
- package/src/coValues/interfaces.ts +6 -6
- package/src/implementation/ContextManager.ts +49 -3
- package/src/tests/ContextManager.test.ts +49 -1
- package/src/tests/PassphraseAuth.test.ts +201 -6
- package/src/tests/deepLoading.test.ts +44 -0
- package/src/types.ts +3 -0
- package/dist/chunk-6OJCOJJ6.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.10.
|
2
|
+
> jazz-tools@0.10.13 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -11,8 +11,8 @@
|
|
11
11
|
[34mESM[39m Build start
|
12
12
|
[32mESM[39m [1mdist/index.js [22m[32m1.50 KB[39m
|
13
13
|
[32mESM[39m [1mdist/testing.js [22m[32m6.28 KB[39m
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
14
|
+
[32mESM[39m [1mdist/chunk-GSIV52ZH.js [22m[32m115.71 KB[39m
|
15
15
|
[32mESM[39m [1mdist/index.js.map [22m[32m259.00 B[39m
|
16
16
|
[32mESM[39m [1mdist/testing.js.map [22m[32m12.41 KB[39m
|
17
|
-
[32mESM[39m [1mdist/chunk-
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
17
|
+
[32mESM[39m [1mdist/chunk-GSIV52ZH.js.map [22m[32m276.19 KB[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 92ms
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.10.13
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 07feedd: Add registerNewUser and generateRandomPassphrase methods to PasskeyAuth and accept the username param on the signUp function
|
8
|
+
|
9
|
+
## 0.10.12
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 4612e05: Fix type inference on `useCoState`
|
14
|
+
|
3
15
|
## 0.10.8
|
4
16
|
|
5
17
|
### Patch Changes
|
@@ -3623,28 +3623,33 @@ var JazzContextManager = class {
|
|
3623
3623
|
await this.createContext(this.props, { credentials }).finally(() => {
|
3624
3624
|
this.authenticating = false;
|
3625
3625
|
});
|
3626
|
-
|
3627
|
-
|
3628
|
-
|
3629
|
-
|
3630
|
-
|
3631
|
-
|
3632
|
-
|
3633
|
-
|
3634
|
-
|
3635
|
-
|
3636
|
-
|
3637
|
-
|
3638
|
-
|
3639
|
-
|
3640
|
-
|
3641
|
-
|
3642
|
-
console.error("Error onAnonymousAccountDiscarded", error);
|
3626
|
+
if (wasAnonymous) {
|
3627
|
+
await this.handleAnonymousAccountMigration(prevContext);
|
3628
|
+
}
|
3629
|
+
};
|
3630
|
+
this.register = async (accountSecret, creationProps) => {
|
3631
|
+
if (!this.props) {
|
3632
|
+
throw new Error("Props required");
|
3633
|
+
}
|
3634
|
+
const prevContext = this.context;
|
3635
|
+
const prevCredentials = await this.authSecretStorage.get();
|
3636
|
+
const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
|
3637
|
+
this.authenticating = true;
|
3638
|
+
await this.createContext(this.props, {
|
3639
|
+
newAccountProps: {
|
3640
|
+
secret: accountSecret,
|
3641
|
+
creationProps
|
3643
3642
|
}
|
3644
|
-
|
3645
|
-
|
3643
|
+
}).finally(() => {
|
3644
|
+
this.authenticating = false;
|
3645
|
+
});
|
3646
|
+
if (wasAnonymous) {
|
3647
|
+
await this.handleAnonymousAccountMigration(prevContext);
|
3648
|
+
}
|
3649
|
+
if (this.context && "me" in this.context) {
|
3650
|
+
return this.context.me.id;
|
3646
3651
|
}
|
3647
|
-
|
3652
|
+
throw new Error("The registration hasn't created a new account");
|
3648
3653
|
};
|
3649
3654
|
this.listeners = /* @__PURE__ */ new Set();
|
3650
3655
|
this.subscribe = (callback) => {
|
@@ -3673,6 +3678,7 @@ var JazzContextManager = class {
|
|
3673
3678
|
...context,
|
3674
3679
|
node: context.node,
|
3675
3680
|
authenticate: this.authenticate,
|
3681
|
+
register: this.register,
|
3676
3682
|
logOut: this.logOut
|
3677
3683
|
};
|
3678
3684
|
if (authProps?.credentials) {
|
@@ -3692,6 +3698,33 @@ var JazzContextManager = class {
|
|
3692
3698
|
getAuthSecretStorage() {
|
3693
3699
|
return this.authSecretStorageWithNotify;
|
3694
3700
|
}
|
3701
|
+
async handleAnonymousAccountMigration(prevContext) {
|
3702
|
+
if (!this.props) {
|
3703
|
+
throw new Error("Props required");
|
3704
|
+
}
|
3705
|
+
const currentContext = this.context;
|
3706
|
+
if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
|
3707
|
+
const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals4.connectedPeers(
|
3708
|
+
prevContext.me.id,
|
3709
|
+
currentContext.me.id,
|
3710
|
+
{
|
3711
|
+
peer1role: "client",
|
3712
|
+
peer2role: "server"
|
3713
|
+
}
|
3714
|
+
);
|
3715
|
+
prevContext.node.syncManager.addPeer(currentAccountAsPeer);
|
3716
|
+
currentContext.node.syncManager.addPeer(prevAccountAsPeer);
|
3717
|
+
try {
|
3718
|
+
await this.props.onAnonymousAccountDiscarded?.(prevContext.me);
|
3719
|
+
await prevContext.me.waitForAllCoValuesSync();
|
3720
|
+
} catch (error) {
|
3721
|
+
console.error("Error onAnonymousAccountDiscarded", error);
|
3722
|
+
}
|
3723
|
+
prevAccountAsPeer.outgoing.close();
|
3724
|
+
currentAccountAsPeer.outgoing.close();
|
3725
|
+
}
|
3726
|
+
prevContext?.done();
|
3727
|
+
}
|
3695
3728
|
notify() {
|
3696
3729
|
for (const listener of this.listeners) {
|
3697
3730
|
listener();
|
@@ -3825,9 +3858,10 @@ import * as bip39 from "@scure/bip39";
|
|
3825
3858
|
import { entropyToMnemonic } from "@scure/bip39";
|
3826
3859
|
import { cojsonInternals as cojsonInternals5 } from "cojson";
|
3827
3860
|
var PassphraseAuth = class {
|
3828
|
-
constructor(crypto, authenticate, authSecretStorage, wordlist) {
|
3861
|
+
constructor(crypto, authenticate, register, authSecretStorage, wordlist) {
|
3829
3862
|
this.crypto = crypto;
|
3830
3863
|
this.authenticate = authenticate;
|
3864
|
+
this.register = register;
|
3831
3865
|
this.authSecretStorage = authSecretStorage;
|
3832
3866
|
this.wordlist = wordlist;
|
3833
3867
|
this.passphrase = "";
|
@@ -3857,7 +3891,7 @@ var PassphraseAuth = class {
|
|
3857
3891
|
this.passphrase = passphrase;
|
3858
3892
|
this.notify();
|
3859
3893
|
};
|
3860
|
-
this.signUp = async () => {
|
3894
|
+
this.signUp = async (name) => {
|
3861
3895
|
const credentials = await this.authSecretStorage.get();
|
3862
3896
|
if (!credentials || !credentials.secretSeed) {
|
3863
3897
|
throw new Error("No credentials found");
|
@@ -3869,8 +3903,26 @@ var PassphraseAuth = class {
|
|
3869
3903
|
accountSecret: credentials.accountSecret,
|
3870
3904
|
provider: "passphrase"
|
3871
3905
|
});
|
3906
|
+
if (name?.trim()) {
|
3907
|
+
const currentAccount = await Account.getMe().ensureLoaded({
|
3908
|
+
profile: {}
|
3909
|
+
});
|
3910
|
+
currentAccount.profile.name = name;
|
3911
|
+
}
|
3872
3912
|
return passphrase;
|
3873
3913
|
};
|
3914
|
+
this.registerNewAccount = async (passphrase, name) => {
|
3915
|
+
const secretSeed = bip39.mnemonicToEntropy(passphrase, this.wordlist);
|
3916
|
+
const accountSecret = this.crypto.agentSecretFromSecretSeed(secretSeed);
|
3917
|
+
const accountID = await this.register(accountSecret, { name });
|
3918
|
+
await this.authSecretStorage.set({
|
3919
|
+
accountID,
|
3920
|
+
secretSeed,
|
3921
|
+
accountSecret,
|
3922
|
+
provider: "passphrase"
|
3923
|
+
});
|
3924
|
+
return accountID;
|
3925
|
+
};
|
3874
3926
|
this.getCurrentAccountPassphrase = async () => {
|
3875
3927
|
const credentials = await this.authSecretStorage.get();
|
3876
3928
|
if (!credentials || !credentials.secretSeed) {
|
@@ -3878,6 +3930,9 @@ var PassphraseAuth = class {
|
|
3878
3930
|
}
|
3879
3931
|
return entropyToMnemonic(credentials.secretSeed, this.wordlist);
|
3880
3932
|
};
|
3933
|
+
this.generateRandomPassphrase = () => {
|
3934
|
+
return entropyToMnemonic(this.crypto.newRandomSecretSeed(), this.wordlist);
|
3935
|
+
};
|
3881
3936
|
this.loadCurrentAccountPassphrase = async () => {
|
3882
3937
|
const passphrase = await this.getCurrentAccountPassphrase();
|
3883
3938
|
this.passphrase = passphrase;
|
@@ -3993,4 +4048,4 @@ export {
|
|
3993
4048
|
consumeInviteLink
|
3994
4049
|
};
|
3995
4050
|
/* istanbul ignore file -- @preserve */
|
3996
|
-
//# sourceMappingURL=chunk-
|
4051
|
+
//# sourceMappingURL=chunk-GSIV52ZH.js.map
|