@ckb-ccc/joy-id 0.0.8-alpha.4 → 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 (43) 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 +13 -1
  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 -7
  14. package/dist/nostr/index.d.ts.map +1 -1
  15. package/dist/nostr/index.js +44 -14
  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/btc/index.d.ts +16 -12
  20. package/dist.commonjs/btc/index.d.ts.map +1 -1
  21. package/dist.commonjs/btc/index.js +38 -13
  22. package/dist.commonjs/ckb/index.d.ts +3 -1
  23. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  24. package/dist.commonjs/ckb/index.js +13 -1
  25. package/dist.commonjs/connectionsStorage/index.d.ts +1 -1
  26. package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
  27. package/dist.commonjs/connectionsStorage/index.js +7 -7
  28. package/dist.commonjs/evm/index.d.ts +9 -7
  29. package/dist.commonjs/evm/index.d.ts.map +1 -1
  30. package/dist.commonjs/evm/index.js +22 -8
  31. package/dist.commonjs/nostr/index.d.ts +20 -7
  32. package/dist.commonjs/nostr/index.d.ts.map +1 -1
  33. package/dist.commonjs/nostr/index.js +44 -14
  34. package/dist.commonjs/signerFactory/index.d.ts +1 -1
  35. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  36. package/dist.commonjs/signerFactory/index.js +4 -4
  37. package/package.json +3 -3
  38. package/src/btc/index.ts +53 -15
  39. package/src/ckb/index.ts +16 -1
  40. package/src/connectionsStorage/index.ts +10 -5
  41. package/src/evm/index.ts +25 -7
  42. package/src/nostr/index.ts +51 -16
  43. package/src/signerFactory/index.ts +10 -3
@@ -6,12 +6,14 @@ import { ConnectionsRepo } from "../connectionsStorage";
6
6
  * @extends {ccc.SignerBtc}
7
7
  */
8
8
  export declare class BitcoinSigner extends ccc.SignerBtc {
9
- private readonly name;
10
- private readonly icon;
11
- private readonly addressType;
12
- private readonly appUri;
9
+ readonly name: string;
10
+ readonly icon: string;
11
+ private readonly preferredNetworks;
12
+ readonly addressType: "auto" | "p2wpkh" | "p2tr";
13
+ private readonly _appUri?;
13
14
  private readonly connectionsRepo;
14
15
  private connection?;
16
+ private network;
15
17
  /**
16
18
  * Ensures that the signer is connected and returns the connection.
17
19
  * @private
@@ -21,20 +23,22 @@ export declare class BitcoinSigner extends ccc.SignerBtc {
21
23
  private assertConnection;
22
24
  /**
23
25
  * Creates an instance of BitcoinSigner.
24
- * @param {ccc.Client} client - The client instance.
25
- * @param {string} name - The name of the signer.
26
- * @param {string} icon - The icon URL of the signer.
27
- * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
28
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
26
+ * @param client - The client instance.
27
+ * @param name - The name of the signer.
28
+ * @param icon - The icon URL of the signer.
29
+ * @param addressType - The address type.
30
+ * @param _appUri - The application URI.
31
+ * @param connectionsRepo - The connections repository.
30
32
  */
31
- constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
33
+ constructor(client: ccc.Client, name: string, icon: string, preferredNetworks: ccc.NetworkPreference[], addressType?: "auto" | "p2wpkh" | "p2tr", _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
34
+ replaceClient(client: ccc.Client): Promise<boolean>;
32
35
  /**
33
36
  * Gets the configuration for JoyID.
34
37
  * @private
35
- * @returns {object} The configuration object.
38
+ * @returns The configuration object.
36
39
  */
37
40
  private getConfig;
41
+ disconnect(): Promise<void>;
38
42
  /**
39
43
  * Gets the Bitcoin account address.
40
44
  * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IA4B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA/BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;OAQG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAe,EAChD,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAUjB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAKzC;;;OAGG;IACG,OAAO,IAA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AAC;IAKtC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAKzC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAYrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAsBvE"}
package/dist/btc/index.js CHANGED
@@ -22,35 +22,60 @@ export class BitcoinSigner extends ccc.SignerBtc {
22
22
  }
23
23
  /**
24
24
  * Creates an instance of BitcoinSigner.
25
- * @param {ccc.Client} client - The client instance.
26
- * @param {string} name - The name of the signer.
27
- * @param {string} icon - The icon URL of the signer.
28
- * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
29
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
30
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
25
+ * @param client - The client instance.
26
+ * @param name - The name of the signer.
27
+ * @param icon - The icon URL of the signer.
28
+ * @param addressType - The address type.
29
+ * @param _appUri - The application URI.
30
+ * @param connectionsRepo - The connections repository.
31
31
  */
32
- constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
32
+ constructor(client, name, icon, preferredNetworks, addressType = "auto", _appUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
33
33
  super(client);
34
34
  this.name = name;
35
35
  this.icon = icon;
36
+ this.preferredNetworks = preferredNetworks;
36
37
  this.addressType = addressType;
37
- this.appUri = appUri;
38
+ this._appUri = _appUri;
38
39
  this.connectionsRepo = connectionsRepo;
40
+ this.network = "btcTestnet";
41
+ }
42
+ async replaceClient(client) {
43
+ if (!(await super.replaceClient(client))) {
44
+ return false;
45
+ }
46
+ this.connection = undefined;
47
+ return true;
39
48
  }
40
49
  /**
41
50
  * Gets the configuration for JoyID.
42
51
  * @private
43
- * @returns {object} The configuration object.
52
+ * @returns The configuration object.
44
53
  */
45
54
  getConfig() {
55
+ const { network } = this.matchNetworkPreference(this.preferredNetworks, this.network) ?? { network: this.network };
56
+ if (this.network !== network) {
57
+ this.connection = undefined;
58
+ }
59
+ this.network = network;
60
+ const url = {
61
+ btc: "https://app.joy.id",
62
+ btcTestnet: "https://testnet.joyid.dev",
63
+ }[network];
64
+ if (!url) {
65
+ throw new Error(`JoyID wallet doesn't support the requested chain ${this.network}`);
66
+ }
46
67
  return {
47
68
  redirectURL: location.href,
48
- joyidAppURL: this.appUri,
69
+ joyidAppURL: this._appUri ?? url,
49
70
  requestNetwork: `btc-${this.addressType}`,
50
71
  name: this.name,
51
72
  logo: this.icon,
52
73
  };
53
74
  }
75
+ async disconnect() {
76
+ await super.disconnect();
77
+ await this.connectionsRepo.set({ uri: this.getConfig().joyidAppURL, addressType: "btc" }, undefined);
78
+ }
54
79
  /**
55
80
  * Gets the Bitcoin account address.
56
81
  * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
@@ -89,8 +114,8 @@ export class BitcoinSigner extends ccc.SignerBtc {
89
114
  keyType: res.keyType,
90
115
  };
91
116
  await Promise.all([
92
- this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
93
- this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
117
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
118
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
94
119
  ]);
95
120
  }
96
121
  /**
@@ -102,7 +127,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
102
127
  return true;
103
128
  }
104
129
  this.connection = await this.connectionsRepo.get({
105
- uri: this.appUri,
130
+ uri: this.getConfig().joyidAppURL,
106
131
  addressType: `btc-${this.addressType}`,
107
132
  });
108
133
  return this.connection !== undefined;
@@ -39,10 +39,11 @@ export declare class CkbSigner extends ccc.Signer {
39
39
  * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
40
40
  */
41
41
  constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
42
+ replaceClient(client: ccc.Client): Promise<boolean>;
42
43
  /**
43
44
  * Gets the configuration for JoyID.
44
45
  * @private
45
- * @returns {object} The configuration object.
46
+ * @returns The configuration object.
46
47
  */
47
48
  private getConfig;
48
49
  /**
@@ -56,6 +57,7 @@ export declare class CkbSigner extends ccc.Signer {
56
57
  * @returns {Promise<void>} A promise that resolves when the connection is established.
57
58
  */
58
59
  connect(): Promise<void>;
60
+ disconnect(): Promise<void>;
59
61
  /**
60
62
  * Checks if the signer is connected.
61
63
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IA4CrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IA/ClC;;;OAGG;IACH,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;YACW,gBAAgB;IAQ9B;;;;;;;;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AAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAmB3B;;;;;;OAMG;YACW,2BAA2B;IAuCzC;;;;OAIG;IACG,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IA8C3B;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BtE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
package/dist/ckb/index.js CHANGED
@@ -52,10 +52,17 @@ export class CkbSigner extends ccc.Signer {
52
52
  this._aggregatorUri = _aggregatorUri;
53
53
  this.connectionsRepo = connectionsRepo;
54
54
  }
55
+ async replaceClient(client) {
56
+ if (!(await super.replaceClient(client))) {
57
+ return false;
58
+ }
59
+ this.connection = undefined;
60
+ return true;
61
+ }
55
62
  /**
56
63
  * Gets the configuration for JoyID.
57
64
  * @private
58
- * @returns {object} The configuration object.
65
+ * @returns The configuration object.
59
66
  */
60
67
  getConfig() {
61
68
  return {
@@ -97,6 +104,11 @@ export class CkbSigner extends ccc.Signer {
97
104
  };
98
105
  await this.saveConnection();
99
106
  }
107
+ async disconnect() {
108
+ await super.disconnect();
109
+ this.connection = undefined;
110
+ await this.saveConnection();
111
+ }
100
112
  /**
101
113
  * Checks if the signer is connected.
102
114
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
@@ -15,7 +15,7 @@ export type AccountSelector = {
15
15
  * @param {AccountSelector} b - The second account selector.
16
16
  * @returns {boolean} True if the selectors are equal, false otherwise.
17
17
  */
18
- export declare function isSelectorEq(a: AccountSelector, b: AccountSelector): boolean;
18
+ export declare function isSelectorMatch(a: AccountSelector, filter: AccountSelector): boolean;
19
19
  /**
20
20
  * Type representing a connection with an address, public key, and key type.
21
21
  * @typedef {Object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E,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;CAoBjB"}
@@ -4,8 +4,8 @@
4
4
  * @param {AccountSelector} b - The second account selector.
5
5
  * @returns {boolean} True if the selectors are equal, false otherwise.
6
6
  */
7
- export function isSelectorEq(a, b) {
8
- return a.uri === b.uri && a.addressType === b.addressType;
7
+ export function isSelectorMatch(a, filter) {
8
+ return a.uri === filter.uri && a.addressType.startsWith(filter.addressType);
9
9
  }
10
10
  /**
11
11
  * Class representing a local storage-based repository for managing connections.
@@ -33,7 +33,7 @@ export class ConnectionsRepoLocalStorage {
33
33
  * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
34
34
  */
35
35
  async get(selector) {
36
- return (await this.readConnections()).find(([s]) => isSelectorEq(selector, s))?.[1];
36
+ return (await this.readConnections()).find(([s]) => isSelectorMatch(selector, s))?.[1];
37
37
  }
38
38
  /**
39
39
  * Sets a connection for the given selector.
@@ -44,7 +44,7 @@ export class ConnectionsRepoLocalStorage {
44
44
  async set(selector, connection) {
45
45
  const connections = await this.readConnections();
46
46
  if (connection) {
47
- const existed = connections.find(([s]) => isSelectorEq(s, selector));
47
+ const existed = connections.find(([s]) => isSelectorMatch(s, selector));
48
48
  if (existed) {
49
49
  existed[1] = connection;
50
50
  }
@@ -54,7 +54,7 @@ export class ConnectionsRepoLocalStorage {
54
54
  window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
55
55
  }
56
56
  else {
57
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorEq(s, selector))));
57
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
58
58
  }
59
59
  }
60
60
  }
@@ -8,7 +8,7 @@ import { ConnectionsRepo } from "../connectionsStorage";
8
8
  export declare class EvmSigner extends ccc.SignerEvm {
9
9
  private readonly name;
10
10
  private readonly icon;
11
- private readonly appUri;
11
+ private readonly _appUri?;
12
12
  private readonly connectionsRepo;
13
13
  private connection?;
14
14
  /**
@@ -20,13 +20,14 @@ export declare class EvmSigner extends ccc.SignerEvm {
20
20
  private assertConnection;
21
21
  /**
22
22
  * Creates an instance of EvmSigner.
23
- * @param {ccc.Client} client - The client instance.
24
- * @param {string} name - The name of the signer.
25
- * @param {string} icon - The icon URL of the signer.
26
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
27
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
23
+ * @param client - The client instance.
24
+ * @param name - The name of the signer.
25
+ * @param icon - The icon URL of the signer.
26
+ * @param appUri - The application URI.
27
+ * @param connectionsRepo - The connections repository.
28
28
  */
29
- constructor(client: ccc.Client, name: string, icon: string, appUri?: string, connectionsRepo?: ConnectionsRepo);
29
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
30
+ replaceClient(client: ccc.Client): Promise<boolean>;
30
31
  /**
31
32
  * Gets the configuration for JoyID.
32
33
  * @private
@@ -43,6 +44,7 @@ export declare class EvmSigner extends ccc.SignerEvm {
43
44
  * @returns {Promise<void>} A promise that resolves when the connection is established.
44
45
  */
45
46
  connect(): Promise<void>;
47
+ disconnect(): Promise<void>;
46
48
  /**
47
49
  * Checks if the signer is connected.
48
50
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IA2BxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,e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EAChB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAuBvE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
package/dist/evm/index.js CHANGED
@@ -22,19 +22,26 @@ export class EvmSigner extends ccc.SignerEvm {
22
22
  }
23
23
  /**
24
24
  * Creates an instance of EvmSigner.
25
- * @param {ccc.Client} client - The client instance.
26
- * @param {string} name - The name of the signer.
27
- * @param {string} icon - The icon URL of the signer.
28
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
25
+ * @param client - The client instance.
26
+ * @param name - The name of the signer.
27
+ * @param icon - The icon URL of the signer.
28
+ * @param appUri - The application URI.
29
+ * @param connectionsRepo - The connections repository.
30
30
  */
31
- constructor(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
31
+ constructor(client, name, icon, _appUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
32
32
  super(client);
33
33
  this.name = name;
34
34
  this.icon = icon;
35
- this.appUri = appUri;
35
+ this._appUri = _appUri;
36
36
  this.connectionsRepo = connectionsRepo;
37
37
  }
38
+ async replaceClient(client) {
39
+ if (!(await super.replaceClient(client))) {
40
+ return false;
41
+ }
42
+ this.connection = undefined;
43
+ return true;
44
+ }
38
45
  /**
39
46
  * Gets the configuration for JoyID.
40
47
  * @private
@@ -43,7 +50,9 @@ export class EvmSigner extends ccc.SignerEvm {
43
50
  getConfig() {
44
51
  return {
45
52
  redirectURL: location.href,
46
- joyidAppURL: this.appUri,
53
+ joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
54
+ ? "https://app.joy.id"
55
+ : "https://testnet.joyid.dev",
47
56
  requestNetwork: `ethereum`,
48
57
  name: this.name,
49
58
  logo: this.icon,
@@ -73,6 +82,11 @@ export class EvmSigner extends ccc.SignerEvm {
73
82
  };
74
83
  await this.saveConnection();
75
84
  }
85
+ async disconnect() {
86
+ await super.disconnect();
87
+ this.connection = undefined;
88
+ await this.saveConnection();
89
+ }
76
90
  /**
77
91
  * Checks if the signer is connected.
78
92
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
@@ -8,7 +8,7 @@ import { ConnectionsRepo } from "../connectionsStorage";
8
8
  export declare class NostrSigner extends ccc.SignerNostr {
9
9
  private readonly name;
10
10
  private readonly icon;
11
- private readonly appUri;
11
+ private readonly _appUri?;
12
12
  private readonly connectionsRepo;
13
13
  private connection?;
14
14
  /**
@@ -20,13 +20,13 @@ export declare class NostrSigner extends ccc.SignerNostr {
20
20
  private assertConnection;
21
21
  /**
22
22
  * Creates an instance of NostrSigner.
23
- * @param {ccc.Client} client - The client instance.
24
- * @param {string} name - The name of the signer.
25
- * @param {string} icon - The icon URL of the signer.
26
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
27
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
23
+ * @param client - The client instance.
24
+ * @param name - The name of the signer.
25
+ * @param icon - The icon URL of the signer.
26
+ * @param appUri - The application URI.
27
+ * @param connectionsRepo - The connections repository.
28
28
  */
29
- constructor(client: ccc.Client, name: string, icon: string, appUri?: string, connectionsRepo?: ConnectionsRepo);
29
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
30
30
  replaceClient(client: ccc.Client): Promise<boolean>;
31
31
  /**
32
32
  * Gets the configuration for JoyID.
@@ -39,6 +39,7 @@ export declare class NostrSigner extends ccc.SignerNostr {
39
39
  * @returns {Promise<void>} A promise that resolves when the connection is established.
40
40
  */
41
41
  connect(): Promise<void>;
42
+ disconnect(): Promise<void>;
42
43
  /**
43
44
  * Checks if the signer is connected.
44
45
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
@@ -46,5 +47,17 @@ export declare class NostrSigner extends ccc.SignerNostr {
46
47
  isConnected(): Promise<boolean>;
47
48
  getNostrPublicKey(): Promise<ccc.Hex>;
48
49
  signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
50
+ /**
51
+ * Saves the current connection.
52
+ * @private
53
+ * @returns {Promise<void>}
54
+ */
55
+ private saveConnection;
56
+ /**
57
+ * Restores the previous connection.
58
+ * @private
59
+ * @returns {Promise<void>}
60
+ */
61
+ private restoreConnection;
49
62
  }
50
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,G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D;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAexB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAS/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAYpC;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
@@ -22,21 +22,25 @@ export class NostrSigner extends ccc.SignerNostr {
22
22
  }
23
23
  /**
24
24
  * Creates an instance of NostrSigner.
25
- * @param {ccc.Client} client - The client instance.
26
- * @param {string} name - The name of the signer.
27
- * @param {string} icon - The icon URL of the signer.
28
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
25
+ * @param client - The client instance.
26
+ * @param name - The name of the signer.
27
+ * @param icon - The icon URL of the signer.
28
+ * @param appUri - The application URI.
29
+ * @param connectionsRepo - The connections repository.
30
30
  */
31
- constructor(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
31
+ constructor(client, name, icon, _appUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
32
32
  super(client);
33
33
  this.name = name;
34
34
  this.icon = icon;
35
- this.appUri = appUri;
35
+ this._appUri = _appUri;
36
36
  this.connectionsRepo = connectionsRepo;
37
37
  }
38
38
  async replaceClient(client) {
39
- return super.replaceClient(client);
39
+ if (!(await super.replaceClient(client))) {
40
+ return false;
41
+ }
42
+ this.connection = undefined;
43
+ return true;
40
44
  }
41
45
  /**
42
46
  * Gets the configuration for JoyID.
@@ -46,7 +50,9 @@ export class NostrSigner extends ccc.SignerNostr {
46
50
  getConfig() {
47
51
  return {
48
52
  redirectURL: location.href,
49
- joyidAppURL: this.appUri,
53
+ joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
54
+ ? "https://app.joy.id"
55
+ : "https://testnet.joyid.dev",
50
56
  requestNetwork: "nostr",
51
57
  name: this.name,
52
58
  logo: this.icon,
@@ -67,7 +73,12 @@ export class NostrSigner extends ccc.SignerNostr {
67
73
  publicKey: ccc.hexFrom(res.nostrPubkey),
68
74
  keyType: res.keyType,
69
75
  };
70
- await this.connectionsRepo.set({ uri: this.appUri, addressType: "nostr" }, this.connection);
76
+ await this.saveConnection();
77
+ }
78
+ async disconnect() {
79
+ await super.disconnect();
80
+ this.connection = undefined;
81
+ await this.saveConnection();
71
82
  }
72
83
  /**
73
84
  * Checks if the signer is connected.
@@ -77,10 +88,7 @@ export class NostrSigner extends ccc.SignerNostr {
77
88
  if (this.connection) {
78
89
  return true;
79
90
  }
80
- this.connection = await this.connectionsRepo.get({
81
- uri: this.appUri,
82
- addressType: "nostr",
83
- });
91
+ await this.restoreConnection();
84
92
  return this.connection !== undefined;
85
93
  }
86
94
  async getNostrPublicKey() {
@@ -94,4 +102,26 @@ export class NostrSigner extends ccc.SignerNostr {
94
102
  });
95
103
  return res.event;
96
104
  }
105
+ /**
106
+ * Saves the current connection.
107
+ * @private
108
+ * @returns {Promise<void>}
109
+ */
110
+ async saveConnection() {
111
+ return this.connectionsRepo.set({
112
+ uri: this.getConfig().joyidAppURL,
113
+ addressType: "nostr",
114
+ }, this.connection);
115
+ }
116
+ /**
117
+ * Restores the previous connection.
118
+ * @private
119
+ * @returns {Promise<void>}
120
+ */
121
+ async restoreConnection() {
122
+ this.connection = await this.connectionsRepo.get({
123
+ uri: this.getConfig().joyidAppURL,
124
+ addressType: "nostr",
125
+ });
126
+ }
97
127
  }
@@ -8,5 +8,5 @@ import { ccc } from "@ckb-ccc/core";
8
8
  * @param {string} icon - The icon URL of the signer.
9
9
  * @returns {ccc.SignerInfo[]} An array of signer information objects.
10
10
  */
11
- export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string): ccc.SignerInfo[];
11
+ export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string, preferredNetworks: ccc.NetworkPreference[]): ccc.SignerInfo[];
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,UAAU,EAAE,CAwClB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,EAAE,GACzC,GAAG,CAAC,UAAU,EAAE,CA8ClB"}
@@ -13,7 +13,7 @@ import { NostrSigner } from "../nostr";
13
13
  * @param {string} icon - The icon URL of the signer.
14
14
  * @returns {ccc.SignerInfo[]} An array of signer information objects.
15
15
  */
16
- export function getJoyIdSigners(client, name, icon) {
16
+ export function getJoyIdSigners(client, name, icon, preferredNetworks) {
17
17
  if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {
18
18
  return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map((type) => ({
19
19
  name: type,
@@ -27,7 +27,7 @@ export function getJoyIdSigners(client, name, icon) {
27
27
  },
28
28
  {
29
29
  name: "BTC",
30
- signer: new BitcoinSigner(client, name, icon),
30
+ signer: new BitcoinSigner(client, name, icon, preferredNetworks),
31
31
  },
32
32
  {
33
33
  name: "Nostr",
@@ -39,11 +39,11 @@ export function getJoyIdSigners(client, name, icon) {
39
39
  },
40
40
  {
41
41
  name: "BTC (P2WPKH)",
42
- signer: new BitcoinSigner(client, name, icon, "p2wpkh"),
42
+ signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2wpkh"),
43
43
  },
44
44
  {
45
45
  name: "BTC (P2TR)",
46
- signer: new BitcoinSigner(client, name, icon, "p2tr"),
46
+ signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
47
47
  },
48
48
  ];
49
49
  }
@@ -6,12 +6,14 @@ import { ConnectionsRepo } from "../connectionsStorage";
6
6
  * @extends {ccc.SignerBtc}
7
7
  */
8
8
  export declare class BitcoinSigner extends ccc.SignerBtc {
9
- private readonly name;
10
- private readonly icon;
11
- private readonly addressType;
12
- private readonly appUri;
9
+ readonly name: string;
10
+ readonly icon: string;
11
+ private readonly preferredNetworks;
12
+ readonly addressType: "auto" | "p2wpkh" | "p2tr";
13
+ private readonly _appUri?;
13
14
  private readonly connectionsRepo;
14
15
  private connection?;
16
+ private network;
15
17
  /**
16
18
  * Ensures that the signer is connected and returns the connection.
17
19
  * @private
@@ -21,20 +23,22 @@ export declare class BitcoinSigner extends ccc.SignerBtc {
21
23
  private assertConnection;
22
24
  /**
23
25
  * Creates an instance of BitcoinSigner.
24
- * @param {ccc.Client} client - The client instance.
25
- * @param {string} name - The name of the signer.
26
- * @param {string} icon - The icon URL of the signer.
27
- * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
28
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
26
+ * @param client - The client instance.
27
+ * @param name - The name of the signer.
28
+ * @param icon - The icon URL of the signer.
29
+ * @param addressType - The address type.
30
+ * @param _appUri - The application URI.
31
+ * @param connectionsRepo - The connections repository.
30
32
  */
31
- constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
33
+ constructor(client: ccc.Client, name: string, icon: string, preferredNetworks: ccc.NetworkPreference[], addressType?: "auto" | "p2wpkh" | "p2tr", _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
34
+ replaceClient(client: ccc.Client): Promise<boolean>;
32
35
  /**
33
36
  * Gets the configuration for JoyID.
34
37
  * @private
35
- * @returns {object} The configuration object.
38
+ * @returns The configuration object.
36
39
  */
37
40
  private getConfig;
41
+ disconnect(): Promise<void>;
38
42
  /**
39
43
  * Gets the Bitcoin account address.
40
44
  * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IA4B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA/BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;OAQG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAe,EAChD,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF;;;;O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