@ckb-ccc/joy-id 0.0.5-alpha.8 → 0.0.7-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 (58) hide show
  1. package/dist/btc/index.d.ts +46 -1
  2. package/dist/btc/index.d.ts.map +1 -1
  3. package/dist/btc/index.js +46 -3
  4. package/dist/ckb/index.d.ts +94 -2
  5. package/dist/ckb/index.d.ts.map +1 -1
  6. package/dist/ckb/index.js +115 -14
  7. package/dist/common/index.d.ts +13 -0
  8. package/dist/common/index.d.ts.map +1 -1
  9. package/dist/common/index.js +9 -0
  10. package/dist/connectionsStorage/index.d.ts +58 -0
  11. package/dist/connectionsStorage/index.d.ts.map +1 -1
  12. package/dist/connectionsStorage/index.js +30 -0
  13. package/dist/evm/index.d.ts +51 -1
  14. package/dist/evm/index.d.ts.map +1 -1
  15. package/dist/evm/index.js +52 -4
  16. package/dist/nostr/index.d.ts +51 -0
  17. package/dist/nostr/index.d.ts.map +1 -0
  18. package/dist/nostr/index.js +106 -0
  19. package/dist/signerFactory/index.d.ts +9 -0
  20. package/dist/signerFactory/index.d.ts.map +1 -1
  21. package/dist/signerFactory/index.js +14 -0
  22. package/dist.commonjs/advanced.d.ts +1 -1
  23. package/dist.commonjs/advanced.js +40 -19
  24. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  25. package/dist.commonjs/advancedBarrel.js +30 -14
  26. package/dist.commonjs/barrel.d.ts +1 -1
  27. package/dist.commonjs/barrel.js +30 -14
  28. package/dist.commonjs/btc/index.d.ts +68 -16
  29. package/dist.commonjs/btc/index.d.ts.map +1 -1
  30. package/dist.commonjs/btc/index.js +145 -76
  31. package/dist.commonjs/ckb/index.d.ts +126 -27
  32. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  33. package/dist.commonjs/ckb/index.js +312 -154
  34. package/dist.commonjs/common/index.d.ts +47 -21
  35. package/dist.commonjs/common/index.d.ts.map +1 -1
  36. package/dist.commonjs/common/index.js +59 -45
  37. package/dist.commonjs/connectionsStorage/index.d.ts +81 -14
  38. package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
  39. package/dist.commonjs/connectionsStorage/index.js +58 -25
  40. package/dist.commonjs/evm/index.d.ts +72 -16
  41. package/dist.commonjs/evm/index.d.ts.map +1 -1
  42. package/dist.commonjs/evm/index.js +140 -70
  43. package/dist.commonjs/index.d.ts +1 -1
  44. package/dist.commonjs/index.js +40 -19
  45. package/dist.commonjs/nostr/index.d.ts +57 -0
  46. package/dist.commonjs/nostr/index.d.ts.map +1 -0
  47. package/dist.commonjs/nostr/index.js +129 -0
  48. package/dist.commonjs/signerFactory/index.d.ts +15 -2
  49. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  50. package/dist.commonjs/signerFactory/index.js +52 -27
  51. package/package.json +5 -5
  52. package/src/btc/index.ts +47 -12
  53. package/src/ckb/index.ts +127 -25
  54. package/src/common/index.ts +13 -0
  55. package/src/connectionsStorage/index.ts +64 -2
  56. package/src/evm/index.ts +56 -15
  57. package/src/nostr/index.ts +135 -0
  58. package/src/signerFactory/index.ts +14 -0
@@ -1,18 +1,34 @@
1
1
  "use strict";
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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./common"), exports);
18
34
  __exportStar(require("./connectionsStorage"), exports);
@@ -2,4 +2,4 @@ export * from "./btc";
2
2
  export * from "./ckb";
3
3
  export * from "./evm";
4
4
  export * from "./signerFactory";
5
- //# sourceMappingURL=barrel.d.ts.map
5
+ //# sourceMappingURL=barrel.d.ts.map
@@ -1,18 +1,34 @@
1
1
  "use strict";
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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./btc"), exports);
18
34
  __exportStar(require("./ckb"), exports);
@@ -1,20 +1,72 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
+ /**
4
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
5
+ * @class
6
+ * @extends {ccc.SignerBtc}
7
+ */
3
8
  export declare class BitcoinSigner extends ccc.SignerBtc {
4
- private readonly name;
5
- private readonly icon;
6
- private readonly addressType;
7
- private readonly appUri;
8
- private readonly connectionsRepo;
9
- private connection?;
10
- private assertConnection;
11
- constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
12
- replaceClient(client: ccc.Client): Promise<BitcoinSigner>;
13
- private getConfig;
14
- getBtcAccount(): Promise<string>;
15
- getBtcPublicKey(): Promise<ccc.Hex>;
16
- connect(): Promise<void>;
17
- isConnected(): Promise<boolean>;
18
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
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>;
19
71
  }
20
- //# sourceMappingURL=index.d.ts.map
72
+ //# 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,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IAa5C,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;IAhBlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,CAAC,gBAAgB;gBAStB,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;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAW/D,OAAO,CAAC,SAAS;IAUX,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAKnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,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;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"}
@@ -5,84 +5,153 @@ const core_1 = require("@ckb-ccc/core");
5
5
  const common_1 = require("@joyid/common");
6
6
  const common_2 = require("../common");
7
7
  const connectionsStorage_1 = require("../connectionsStorage");
8
+ /**
9
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
10
+ * @class
11
+ * @extends {ccc.SignerBtc}
12
+ */
8
13
  class BitcoinSigner extends core_1.ccc.SignerBtc {
9
- assertConnection() {
10
- if (!this.isConnected() || !this.connection) {
11
- throw new Error("Not connected");
12
- }
13
- return this.connection;
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
23
  }
15
- constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
16
- super(client);
17
- this.name = name;
18
- this.icon = icon;
19
- this.addressType = addressType;
20
- this.appUri = appUri;
21
- this.connectionsRepo = connectionsRepo;
22
- }
23
- async replaceClient(client) {
24
- return new BitcoinSigner(client, this.name, this.icon, this.addressType, this.appUri, this.connectionsRepo);
25
- }
26
- getConfig() {
27
- return {
28
- redirectURL: location.href,
29
- joyidAppURL: this.appUri,
30
- requestNetwork: `btc-${this.addressType}`,
31
- name: this.name,
32
- logo: this.icon,
33
- };
34
- }
35
- async getBtcAccount() {
36
- const { address } = this.assertConnection();
37
- return address;
38
- }
39
- async getBtcPublicKey() {
40
- const { publicKey } = this.assertConnection();
41
- return publicKey;
42
- }
43
- async connect() {
44
- const config = this.getConfig();
45
- const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
46
- ...config,
47
- type: common_1.DappRequestType.Auth,
48
- });
49
- const { address, pubkey } = (() => {
50
- if (this.addressType === "auto") {
51
- return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
52
- }
53
- return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
54
- })();
55
- this.connection = {
56
- address,
57
- publicKey: core_1.ccc.hexFrom(pubkey),
58
- keyType: res.keyType,
59
- };
60
- await Promise.all([
61
- this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
62
- this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
63
- ]);
64
- }
65
- async isConnected() {
66
- if (this.connection) {
67
- return true;
68
- }
69
- this.connection = await this.connectionsRepo.get({
70
- uri: this.appUri,
71
- addressType: `btc-${this.addressType}`,
72
- });
73
- return this.connection !== undefined;
74
- }
75
- async signMessageRaw(message) {
76
- const { address } = this.assertConnection();
77
- const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
78
- const config = this.getConfig();
79
- const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
80
- ...config,
81
- challenge,
82
- address,
83
- signMessageType: "ecdsa",
84
- }, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
85
- return signature;
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;
86
122
  }
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
+ }
87
156
  }
88
157
  exports.BitcoinSigner = BitcoinSigner;
@@ -1,31 +1,130 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
+ /**
4
+ * Class representing a CKB signer that extends Signer from @ckb-ccc/core.
5
+ * @class
6
+ * @extends {ccc.Signer}
7
+ */
3
8
  export declare class CkbSigner extends ccc.Signer {
4
- private readonly name;
5
- private readonly icon;
6
- private readonly _appUri?;
7
- private readonly _aggregatorUri?;
8
- private readonly connectionsRepo;
9
- get type(): ccc.SignerType;
10
- get signType(): ccc.SignerSignType;
11
- private connection?;
12
- private assertConnection;
13
- constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
14
- replaceClient(client: ccc.Client): Promise<CkbSigner>;
15
- private getConfig;
16
- private getAggregatorUri;
17
- connect(): Promise<void>;
18
- disconnect(): Promise<void>;
19
- isConnected(): Promise<boolean>;
20
- getInternalAddress(): Promise<string>;
21
- getIdentity(): Promise<string>;
22
- getAddressObj(): Promise<ccc.Address>;
23
- getAddressObjs(): Promise<ccc.Address[]>;
24
- prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
25
- private prepareTransactionForSubKey;
26
- signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
27
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
28
- private saveConnection;
29
- private restoreConnection;
9
+ private readonly name;
10
+ private readonly icon;
11
+ private readonly _appUri?;
12
+ private readonly _aggregatorUri?;
13
+ private readonly connectionsRepo;
14
+ /**
15
+ * Gets the signer type.
16
+ * @returns {ccc.SignerType} The type of the signer.
17
+ */
18
+ get type(): ccc.SignerType;
19
+ /**
20
+ * Gets the sign type.
21
+ * @returns {ccc.SignerSignType} The sign type.
22
+ */
23
+ get signType(): ccc.SignerSignType;
24
+ private connection?;
25
+ /**
26
+ * Ensures that the signer is connected and returns the connection.
27
+ * @private
28
+ * @throws Will throw an error if not connected.
29
+ * @returns {Promise<Connection>} A promise that resolves to the current connection.
30
+ */
31
+ private assertConnection;
32
+ /**
33
+ * Creates an instance of CkbSigner.
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] - The application URI.
38
+ * @param {string} [_aggregatorUri] - The aggregator URI.
39
+ * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
40
+ */
41
+ constructor(
42
+ client: ccc.Client,
43
+ name: string,
44
+ icon: string,
45
+ _appUri?: string | undefined,
46
+ _aggregatorUri?: string | undefined,
47
+ connectionsRepo?: ConnectionsRepo,
48
+ );
49
+ /**
50
+ * Gets the configuration for JoyID.
51
+ * @private
52
+ * @returns {object} The configuration object.
53
+ */
54
+ private getConfig;
55
+ /**
56
+ * Gets the aggregator URI.
57
+ * @private
58
+ * @returns {string} The aggregator URI.
59
+ */
60
+ private getAggregatorUri;
61
+ /**
62
+ * Connects to the provider by requesting authentication.
63
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
64
+ */
65
+ connect(): Promise<void>;
66
+ /**
67
+ * Checks if the signer is connected.
68
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
69
+ */
70
+ isConnected(): Promise<boolean>;
71
+ /**
72
+ * Gets the internal address.
73
+ * @returns {Promise<string>} A promise that resolves to the internal address.
74
+ */
75
+ getInternalAddress(): Promise<string>;
76
+ /**
77
+ * Gets the identity of the signer.
78
+ * @returns {Promise<string>} A promise that resolves to the identity.
79
+ */
80
+ getIdentity(): Promise<string>;
81
+ /**
82
+ * Gets the address object.
83
+ * @returns {Promise<ccc.Address>} A promise that resolves to the address object.
84
+ */
85
+ getAddressObj(): Promise<ccc.Address>;
86
+ /**
87
+ * Gets the address objects.
88
+ * @returns {Promise<ccc.Address[]>} A promise that resolves to an array of address objects.
89
+ */
90
+ getAddressObjs(): Promise<ccc.Address[]>;
91
+ /**
92
+ * Prepares a transaction.
93
+ * @param {ccc.TransactionLike} txLike - The transaction-like object.
94
+ * @returns {Promise<ccc.Transaction>} A promise that resolves to the prepared transaction.
95
+ */
96
+ prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
97
+ /**
98
+ * Prepares a transaction for a sub key.
99
+ * @private
100
+ * @param tx - The transaction object.
101
+ * @param witness - The witness arguments.
102
+ * @throws Will throw an error if no COTA cells are found for the sub key wallet.
103
+ */
104
+ private prepareTransactionForSubKey;
105
+ /**
106
+ * Signs a transaction.
107
+ * @param {ccc.TransactionLike} txLike - The transaction-like object.
108
+ * @returns {Promise<ccc.Transaction>} A promise that resolves to the signed transaction.
109
+ */
110
+ signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
111
+ /**
112
+ * Signs a raw message with the account.
113
+ * @param {string | ccc.BytesLike} message - The message to sign.
114
+ * @returns {Promise<string>} A promise that resolves to the signed message.
115
+ */
116
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
117
+ /**
118
+ * Saves the current connection.
119
+ * @private
120
+ * @returns {Promise<void>}
121
+ */
122
+ private saveConnection;
123
+ /**
124
+ * Restores the previous connection.
125
+ * @private
126
+ * @returns {Promise<void>}
127
+ */
128
+ private restoreConnection;
30
129
  }
31
- //# sourceMappingURL=index.d.ts.map
130
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../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