@ckb-ccc/joy-id 0.0.8-alpha.3 → 0.0.9-alpha.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.
Files changed (53) hide show
  1. package/dist/btc/index.d.ts +16 -12
  2. package/dist/btc/index.d.ts.map +1 -1
  3. package/dist/btc/index.js +38 -13
  4. package/dist/ckb/index.d.ts +3 -1
  5. package/dist/ckb/index.d.ts.map +1 -1
  6. package/dist/ckb/index.js +14 -2
  7. package/dist/connectionsStorage/index.d.ts +1 -1
  8. package/dist/connectionsStorage/index.d.ts.map +1 -1
  9. package/dist/connectionsStorage/index.js +5 -5
  10. package/dist/evm/index.d.ts +9 -7
  11. package/dist/evm/index.d.ts.map +1 -1
  12. package/dist/evm/index.js +22 -8
  13. package/dist/nostr/index.d.ts +20 -8
  14. package/dist/nostr/index.d.ts.map +1 -1
  15. package/dist/nostr/index.js +42 -18
  16. package/dist/signerFactory/index.d.ts +1 -1
  17. package/dist/signerFactory/index.d.ts.map +1 -1
  18. package/dist/signerFactory/index.js +4 -4
  19. package/dist.commonjs/advanced.d.ts +1 -1
  20. package/dist.commonjs/advanced.js +19 -40
  21. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  22. package/dist.commonjs/advancedBarrel.js +14 -30
  23. package/dist.commonjs/barrel.d.ts +1 -1
  24. package/dist.commonjs/barrel.js +14 -30
  25. package/dist.commonjs/btc/index.d.ts +60 -63
  26. package/dist.commonjs/btc/index.d.ts.map +1 -1
  27. package/dist.commonjs/btc/index.js +139 -140
  28. package/dist.commonjs/ckb/index.d.ts +116 -121
  29. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  30. package/dist.commonjs/ckb/index.js +262 -307
  31. package/dist.commonjs/common/index.d.ts +21 -34
  32. package/dist.commonjs/common/index.js +45 -50
  33. package/dist.commonjs/connectionsStorage/index.d.ts +44 -53
  34. package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
  35. package/dist.commonjs/connectionsStorage/index.js +47 -50
  36. package/dist.commonjs/evm/index.d.ts +63 -67
  37. package/dist.commonjs/evm/index.d.ts.map +1 -1
  38. package/dist.commonjs/evm/index.js +127 -135
  39. package/dist.commonjs/index.d.ts +1 -1
  40. package/dist.commonjs/index.js +19 -40
  41. package/dist.commonjs/nostr/index.d.ts +54 -48
  42. package/dist.commonjs/nostr/index.d.ts.map +1 -1
  43. package/dist.commonjs/nostr/index.js +113 -108
  44. package/dist.commonjs/signerFactory/index.d.ts +2 -6
  45. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  46. package/dist.commonjs/signerFactory/index.js +32 -43
  47. package/package.json +3 -3
  48. package/src/btc/index.ts +53 -15
  49. package/src/ckb/index.ts +17 -2
  50. package/src/connectionsStorage/index.ts +10 -5
  51. package/src/evm/index.ts +25 -7
  52. package/src/nostr/index.ts +49 -21
  53. package/src/signerFactory/index.ts +10 -3
@@ -31,31 +31,28 @@ export class NostrSigner extends ccc.SignerNostr {
31
31
 
32
32
  /**
33
33
  * Creates an instance of NostrSigner.
34
- * @param {ccc.Client} client - The client instance.
35
- * @param {string} name - The name of the signer.
36
- * @param {string} icon - The icon URL of the signer.
37
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
38
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
34
+ * @param client - The client instance.
35
+ * @param name - The name of the signer.
36
+ * @param icon - The icon URL of the signer.
37
+ * @param appUri - The application URI.
38
+ * @param connectionsRepo - The connections repository.
39
39
  */
40
40
  constructor(
41
41
  client: ccc.Client,
42
42
  private readonly name: string,
43
43
  private readonly icon: string,
44
- private readonly appUri = "https://app.joy.id",
44
+ private readonly _appUri?: string,
45
45
  private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
46
46
  ) {
47
47
  super(client);
48
48
  }
49
49
 
50
- static isValidClient(client: ccc.Client): boolean {
51
- return client.addressPrefix === "ckt";
52
- }
53
-
54
50
  async replaceClient(client: ccc.Client): Promise<boolean> {
55
- if (!NostrSigner.isValidClient(client)) {
51
+ if (!(await super.replaceClient(client))) {
56
52
  return false;
57
53
  }
58
- return super.replaceClient(client);
54
+ this.connection = undefined;
55
+ return true;
59
56
  }
60
57
 
61
58
  /**
@@ -66,7 +63,10 @@ export class NostrSigner extends ccc.SignerNostr {
66
63
  private getConfig() {
67
64
  return {
68
65
  redirectURL: location.href,
69
- joyidAppURL: this.appUri,
66
+ joyidAppURL:
67
+ this._appUri ?? this.client.addressPrefix === "ckb"
68
+ ? "https://app.joy.id"
69
+ : "https://testnet.joyid.dev",
70
70
  requestNetwork: "nostr",
71
71
  name: this.name,
72
72
  logo: this.icon,
@@ -89,10 +89,14 @@ export class NostrSigner extends ccc.SignerNostr {
89
89
  publicKey: ccc.hexFrom(res.nostrPubkey),
90
90
  keyType: res.keyType,
91
91
  };
92
- await this.connectionsRepo.set(
93
- { uri: this.appUri, addressType: "nostr" },
94
- this.connection,
95
- );
92
+ await this.saveConnection();
93
+ }
94
+
95
+ async disconnect(): Promise<void> {
96
+ await super.disconnect();
97
+
98
+ this.connection = undefined;
99
+ await this.saveConnection();
96
100
  }
97
101
 
98
102
  /**
@@ -104,10 +108,7 @@ export class NostrSigner extends ccc.SignerNostr {
104
108
  return true;
105
109
  }
106
110
 
107
- this.connection = await this.connectionsRepo.get({
108
- uri: this.appUri,
109
- addressType: "nostr",
110
- });
111
+ await this.restoreConnection();
111
112
  return this.connection !== undefined;
112
113
  }
113
114
 
@@ -128,4 +129,31 @@ export class NostrSigner extends ccc.SignerNostr {
128
129
  );
129
130
  return res.event;
130
131
  }
132
+
133
+ /**
134
+ * Saves the current connection.
135
+ * @private
136
+ * @returns {Promise<void>}
137
+ */
138
+ private async saveConnection(): Promise<void> {
139
+ return this.connectionsRepo.set(
140
+ {
141
+ uri: this.getConfig().joyidAppURL,
142
+ addressType: "nostr",
143
+ },
144
+ this.connection,
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Restores the previous connection.
150
+ * @private
151
+ * @returns {Promise<void>}
152
+ */
153
+ private async restoreConnection(): Promise<void> {
154
+ this.connection = await this.connectionsRepo.get({
155
+ uri: this.getConfig().joyidAppURL,
156
+ addressType: "nostr",
157
+ });
158
+ }
131
159
  }
@@ -18,6 +18,7 @@ export function getJoyIdSigners(
18
18
  client: ccc.Client,
19
19
  name: string,
20
20
  icon: string,
21
+ preferredNetworks: ccc.NetworkPreference[],
21
22
  ): ccc.SignerInfo[] {
22
23
  if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {
23
24
  return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map(
@@ -39,7 +40,7 @@ export function getJoyIdSigners(
39
40
  },
40
41
  {
41
42
  name: "BTC",
42
- signer: new BitcoinSigner(client, name, icon),
43
+ signer: new BitcoinSigner(client, name, icon, preferredNetworks),
43
44
  },
44
45
  {
45
46
  name: "Nostr",
@@ -51,11 +52,17 @@ export function getJoyIdSigners(
51
52
  },
52
53
  {
53
54
  name: "BTC (P2WPKH)",
54
- signer: new BitcoinSigner(client, name, icon, "p2wpkh"),
55
+ signer: new BitcoinSigner(
56
+ client,
57
+ name,
58
+ icon,
59
+ preferredNetworks,
60
+ "p2wpkh",
61
+ ),
55
62
  },
56
63
  {
57
64
  name: "BTC (P2TR)",
58
- signer: new BitcoinSigner(client, name, icon, "p2tr"),
65
+ signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
59
66
  },
60
67
  ];
61
68
  }