@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
@@ -1,48 +1,27 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  exports.JoyIdA = void 0;
48
27
  exports.JoyIdA = __importStar(require("./advancedBarrel"));
@@ -1,3 +1,3 @@
1
1
  export * from "./common";
2
2
  export * from "./connectionsStorage";
3
- //# sourceMappingURL=advancedBarrel.d.ts.map
3
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./common"), exports);
34
18
  __exportStar(require("./connectionsStorage"), exports);
@@ -3,4 +3,4 @@ export * from "./ckb";
3
3
  export * from "./evm";
4
4
  export * from "./nostr";
5
5
  export * from "./signerFactory";
6
- //# sourceMappingURL=barrel.d.ts.map
6
+ //# sourceMappingURL=barrel.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./btc"), exports);
34
18
  __exportStar(require("./ckb"), exports);
@@ -6,67 +6,64 @@ 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;
13
- private readonly connectionsRepo;
14
- private connection?;
15
- /**
16
- * Ensures that the signer is connected and returns the connection.
17
- * @private
18
- * @throws Will throw an error if not connected.
19
- * @returns {Connection} The current connection.
20
- */
21
- private assertConnection;
22
- /**
23
- * 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.
30
- */
31
- constructor(
32
- client: ccc.Client,
33
- name: string,
34
- icon: string,
35
- addressType?: "auto" | "p2wpkh" | "p2tr",
36
- appUri?: string,
37
- connectionsRepo?: ConnectionsRepo,
38
- );
39
- /**
40
- * Gets the configuration for JoyID.
41
- * @private
42
- * @returns {object} The configuration object.
43
- */
44
- private getConfig;
45
- /**
46
- * Gets the Bitcoin account address.
47
- * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
48
- */
49
- getBtcAccount(): Promise<string>;
50
- /**
51
- * Gets the Bitcoin public key.
52
- * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
53
- */
54
- getBtcPublicKey(): Promise<ccc.Hex>;
55
- /**
56
- * Connects to the provider by requesting authentication.
57
- * @returns {Promise<void>} A promise that resolves when the connection is established.
58
- */
59
- connect(): Promise<void>;
60
- /**
61
- * Checks if the signer is connected.
62
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
63
- */
64
- isConnected(): Promise<boolean>;
65
- /**
66
- * Signs a raw message with the Bitcoin account.
67
- * @param {string | ccc.BytesLike} message - The message to sign.
68
- * @returns {Promise<string>} A promise that resolves to the signed message.
69
- */
70
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
9
+ readonly name: string;
10
+ readonly icon: string;
11
+ private readonly preferredNetworks;
12
+ readonly addressType: "auto" | "p2wpkh" | "p2tr";
13
+ private readonly _appUri?;
14
+ private readonly connectionsRepo;
15
+ private connection?;
16
+ private network;
17
+ /**
18
+ * Ensures that the signer is connected and returns the connection.
19
+ * @private
20
+ * @throws Will throw an error if not connected.
21
+ * @returns {Connection} The current connection.
22
+ */
23
+ private assertConnection;
24
+ /**
25
+ * Creates an instance of BitcoinSigner.
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.
32
+ */
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>;
35
+ /**
36
+ * Gets the configuration for JoyID.
37
+ * @private
38
+ * @returns The configuration object.
39
+ */
40
+ private getConfig;
41
+ disconnect(): Promise<void>;
42
+ /**
43
+ * Gets the Bitcoin account address.
44
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
45
+ */
46
+ getBtcAccount(): Promise<string>;
47
+ /**
48
+ * Gets the Bitcoin public key.
49
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
50
+ */
51
+ getBtcPublicKey(): Promise<ccc.Hex>;
52
+ /**
53
+ * Connects to the provider by requesting authentication.
54
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
55
+ */
56
+ connect(): Promise<void>;
57
+ /**
58
+ * Checks if the signer is connected.
59
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
60
+ */
61
+ isConnected(): Promise<boolean>;
62
+ /**
63
+ * Signs a raw message with the Bitcoin account.
64
+ * @param {string | ccc.BytesLike} message - The message to sign.
65
+ * @returns {Promise<string>} A promise that resolves to the signed message.
66
+ */
67
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
71
68
  }
72
- //# sourceMappingURL=index.d.ts.map
69
+ //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
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;aA6B5B,IAAI,EAAE,MAAM;aACZ,IAAI,EAAE,MAAM;IAC5B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;aAClB,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAjClC,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;OAQG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACX,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,EAAE,EAC3C,WAAW,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAe,EAC/C,OAAO,CAAC,oBAAQ,EAChB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IA6BX,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;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"}
@@ -11,147 +11,146 @@ const connectionsStorage_1 = require("../connectionsStorage");
11
11
  * @extends {ccc.SignerBtc}
12
12
  */
13
13
  class BitcoinSigner extends core_1.ccc.SignerBtc {
14
- /**
15
- * Ensures that the signer is connected and returns the connection.
16
- * @private
17
- * @throws Will throw an error if not connected.
18
- * @returns {Connection} The current connection.
19
- */
20
- assertConnection() {
21
- if (!this.isConnected() || !this.connection) {
22
- throw new Error("Not connected");
14
+ /**
15
+ * Ensures that the signer is connected and returns the connection.
16
+ * @private
17
+ * @throws Will throw an error if not connected.
18
+ * @returns {Connection} The current connection.
19
+ */
20
+ assertConnection() {
21
+ if (!this.isConnected() || !this.connection) {
22
+ throw new Error("Not connected");
23
+ }
24
+ return this.connection;
23
25
  }
24
- return this.connection;
25
- }
26
- /**
27
- * Creates an instance of BitcoinSigner.
28
- * @param {ccc.Client} client - The client instance.
29
- * @param {string} name - The name of the signer.
30
- * @param {string} icon - The icon URL of the signer.
31
- * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
32
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
33
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
34
- */
35
- constructor(
36
- client,
37
- name,
38
- icon,
39
- addressType = "auto",
40
- appUri = "https://app.joy.id",
41
- connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
42
- ) {
43
- super(client);
44
- this.name = name;
45
- this.icon = icon;
46
- this.addressType = addressType;
47
- this.appUri = appUri;
48
- this.connectionsRepo = connectionsRepo;
49
- }
50
- /**
51
- * Gets the configuration for JoyID.
52
- * @private
53
- * @returns {object} The configuration object.
54
- */
55
- getConfig() {
56
- return {
57
- redirectURL: location.href,
58
- joyidAppURL: this.appUri,
59
- requestNetwork: `btc-${this.addressType}`,
60
- name: this.name,
61
- logo: this.icon,
62
- };
63
- }
64
- /**
65
- * Gets the Bitcoin account address.
66
- * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
67
- */
68
- async getBtcAccount() {
69
- const { address } = this.assertConnection();
70
- return address;
71
- }
72
- /**
73
- * Gets the Bitcoin public key.
74
- * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
75
- */
76
- async getBtcPublicKey() {
77
- const { publicKey } = this.assertConnection();
78
- return publicKey;
79
- }
80
- /**
81
- * Connects to the provider by requesting authentication.
82
- * @returns {Promise<void>} A promise that resolves when the connection is established.
83
- */
84
- async connect() {
85
- const config = this.getConfig();
86
- const res = await (0, common_2.createPopup)(
87
- (0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
88
- {
89
- ...config,
90
- type: common_1.DappRequestType.Auth,
91
- },
92
- );
93
- const { address, pubkey } = (() => {
94
- if (this.addressType === "auto") {
95
- return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
96
- }
97
- return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
98
- })();
99
- this.connection = {
100
- address,
101
- publicKey: core_1.ccc.hexFrom(pubkey),
102
- keyType: res.keyType,
103
- };
104
- await Promise.all([
105
- this.connectionsRepo.set(
106
- { uri: this.appUri, addressType: `btc-${res.btcAddressType}` },
107
- this.connection,
108
- ),
109
- this.connectionsRepo.set(
110
- { uri: this.appUri, addressType: "btc-auto" },
111
- this.connection,
112
- ),
113
- ]);
114
- }
115
- /**
116
- * Checks if the signer is connected.
117
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
118
- */
119
- async isConnected() {
120
- if (this.connection) {
121
- return true;
26
+ /**
27
+ * Creates an instance of BitcoinSigner.
28
+ * @param client - The client instance.
29
+ * @param name - The name of the signer.
30
+ * @param icon - The icon URL of the signer.
31
+ * @param addressType - The address type.
32
+ * @param _appUri - The application URI.
33
+ * @param connectionsRepo - The connections repository.
34
+ */
35
+ constructor(client, name, icon, preferredNetworks, addressType = "auto", _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
36
+ super(client);
37
+ this.name = name;
38
+ this.icon = icon;
39
+ this.preferredNetworks = preferredNetworks;
40
+ this.addressType = addressType;
41
+ this._appUri = _appUri;
42
+ this.connectionsRepo = connectionsRepo;
43
+ this.network = "btcTestnet";
44
+ }
45
+ async replaceClient(client) {
46
+ if (!(await super.replaceClient(client))) {
47
+ return false;
48
+ }
49
+ this.connection = undefined;
50
+ return true;
51
+ }
52
+ /**
53
+ * Gets the configuration for JoyID.
54
+ * @private
55
+ * @returns The configuration object.
56
+ */
57
+ getConfig() {
58
+ const { network } = this.matchNetworkPreference(this.preferredNetworks, this.network) ?? { network: this.network };
59
+ if (this.network !== network) {
60
+ this.connection = undefined;
61
+ }
62
+ this.network = network;
63
+ const url = {
64
+ btc: "https://app.joy.id",
65
+ btcTestnet: "https://testnet.joyid.dev",
66
+ }[network];
67
+ if (!url) {
68
+ throw new Error(`JoyID wallet doesn't support the requested chain ${this.network}`);
69
+ }
70
+ return {
71
+ redirectURL: location.href,
72
+ joyidAppURL: this._appUri ?? url,
73
+ requestNetwork: `btc-${this.addressType}`,
74
+ name: this.name,
75
+ logo: this.icon,
76
+ };
77
+ }
78
+ async disconnect() {
79
+ await super.disconnect();
80
+ await this.connectionsRepo.set({ uri: this.getConfig().joyidAppURL, addressType: "btc" }, undefined);
81
+ }
82
+ /**
83
+ * Gets the Bitcoin account address.
84
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
85
+ */
86
+ async getBtcAccount() {
87
+ const { address } = this.assertConnection();
88
+ return address;
89
+ }
90
+ /**
91
+ * Gets the Bitcoin public key.
92
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
93
+ */
94
+ async getBtcPublicKey() {
95
+ const { publicKey } = this.assertConnection();
96
+ return publicKey;
97
+ }
98
+ /**
99
+ * Connects to the provider by requesting authentication.
100
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
101
+ */
102
+ async connect() {
103
+ const config = this.getConfig();
104
+ const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
105
+ ...config,
106
+ type: common_1.DappRequestType.Auth,
107
+ });
108
+ const { address, pubkey } = (() => {
109
+ if (this.addressType === "auto") {
110
+ return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
111
+ }
112
+ return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
113
+ })();
114
+ this.connection = {
115
+ address,
116
+ publicKey: core_1.ccc.hexFrom(pubkey),
117
+ keyType: res.keyType,
118
+ };
119
+ await Promise.all([
120
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
121
+ this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
122
+ ]);
123
+ }
124
+ /**
125
+ * Checks if the signer is connected.
126
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
127
+ */
128
+ async isConnected() {
129
+ if (this.connection) {
130
+ return true;
131
+ }
132
+ this.connection = await this.connectionsRepo.get({
133
+ uri: this.getConfig().joyidAppURL,
134
+ addressType: `btc-${this.addressType}`,
135
+ });
136
+ return this.connection !== undefined;
137
+ }
138
+ /**
139
+ * Signs a raw message with the Bitcoin account.
140
+ * @param {string | ccc.BytesLike} message - The message to sign.
141
+ * @returns {Promise<string>} A promise that resolves to the signed message.
142
+ */
143
+ async signMessageRaw(message) {
144
+ const { address } = this.assertConnection();
145
+ const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
146
+ const config = this.getConfig();
147
+ const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
148
+ ...config,
149
+ challenge,
150
+ address,
151
+ signMessageType: "ecdsa",
152
+ }, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
153
+ return signature;
122
154
  }
123
- this.connection = await this.connectionsRepo.get({
124
- uri: this.appUri,
125
- addressType: `btc-${this.addressType}`,
126
- });
127
- return this.connection !== undefined;
128
- }
129
- /**
130
- * Signs a raw message with the Bitcoin account.
131
- * @param {string | ccc.BytesLike} message - The message to sign.
132
- * @returns {Promise<string>} A promise that resolves to the signed message.
133
- */
134
- async signMessageRaw(message) {
135
- const { address } = this.assertConnection();
136
- const challenge =
137
- typeof message === "string"
138
- ? message
139
- : core_1.ccc.hexFrom(message).slice(2);
140
- const config = this.getConfig();
141
- const { signature } = await (0, common_2.createPopup)(
142
- (0, common_1.buildJoyIDURL)(
143
- {
144
- ...config,
145
- challenge,
146
- address,
147
- signMessageType: "ecdsa",
148
- },
149
- "popup",
150
- "/sign-message",
151
- ),
152
- { ...config, type: common_1.DappRequestType.SignMessage },
153
- );
154
- return signature;
155
- }
156
155
  }
157
156
  exports.BitcoinSigner = BitcoinSigner;