@ckb-ccc/core 0.0.5-alpha.1 → 0.0.5-alpha.2

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 (105) hide show
  1. package/dist/address/index.d.ts +1 -1
  2. package/dist/address/index.d.ts.map +1 -1
  3. package/dist/address/index.js +4 -4
  4. package/dist/client/client.d.ts +2 -2
  5. package/dist/client/client.d.ts.map +1 -1
  6. package/dist/client/clientPublicMainnet.d.ts +1 -1
  7. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  8. package/dist/client/clientPublicMainnet.js +1 -1
  9. package/dist/client/clientPublicTestnet.d.ts +1 -1
  10. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  11. package/dist/client/clientPublicTestnet.js +1 -1
  12. package/dist/client/jsonRpc/index.d.ts +3 -3
  13. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  14. package/dist/client/jsonRpc/index.js +4 -4
  15. package/dist/signer/btc/index.d.ts +1 -0
  16. package/dist/signer/btc/index.d.ts.map +1 -1
  17. package/dist/signer/btc/index.js +1 -0
  18. package/dist/signer/btc/signerBtc.d.ts +9 -1
  19. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  20. package/dist/signer/btc/signerBtc.js +16 -2
  21. package/dist/signer/btc/verify.d.ts +3 -0
  22. package/dist/signer/btc/verify.d.ts.map +1 -0
  23. package/dist/signer/btc/verify.js +6 -0
  24. package/dist/signer/ckb/index.d.ts +1 -0
  25. package/dist/signer/ckb/index.d.ts.map +1 -1
  26. package/dist/signer/ckb/index.js +1 -0
  27. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +3 -1
  28. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  29. package/dist/signer/ckb/signerCkbScriptReadonly.js +8 -2
  30. package/dist/signer/ckb/verifyJoyId.d.ts +3 -0
  31. package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -0
  32. package/dist/signer/ckb/verifyJoyId.js +12 -0
  33. package/dist/signer/evm/index.d.ts +1 -0
  34. package/dist/signer/evm/index.d.ts.map +1 -1
  35. package/dist/signer/evm/index.js +1 -0
  36. package/dist/signer/evm/signerEvm.d.ts +3 -1
  37. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  38. package/dist/signer/evm/signerEvm.js +8 -2
  39. package/dist/signer/evm/verify.d.ts +3 -0
  40. package/dist/signer/evm/verify.d.ts.map +1 -0
  41. package/dist/signer/evm/verify.js +6 -0
  42. package/dist/signer/signer.d.ts +60 -14
  43. package/dist/signer/signer.d.ts.map +1 -1
  44. package/dist/signer/signer.js +95 -16
  45. package/dist.commonjs/address/index.d.ts +1 -1
  46. package/dist.commonjs/address/index.d.ts.map +1 -1
  47. package/dist.commonjs/address/index.js +4 -4
  48. package/dist.commonjs/client/client.d.ts +2 -2
  49. package/dist.commonjs/client/client.d.ts.map +1 -1
  50. package/dist.commonjs/client/clientPublicMainnet.d.ts +1 -1
  51. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  52. package/dist.commonjs/client/clientPublicMainnet.js +1 -1
  53. package/dist.commonjs/client/clientPublicTestnet.d.ts +1 -1
  54. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  55. package/dist.commonjs/client/clientPublicTestnet.js +1 -1
  56. package/dist.commonjs/client/jsonRpc/index.d.ts +3 -3
  57. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  58. package/dist.commonjs/client/jsonRpc/index.js +4 -4
  59. package/dist.commonjs/signer/btc/index.d.ts +1 -0
  60. package/dist.commonjs/signer/btc/index.d.ts.map +1 -1
  61. package/dist.commonjs/signer/btc/index.js +1 -0
  62. package/dist.commonjs/signer/btc/signerBtc.d.ts +9 -1
  63. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  64. package/dist.commonjs/signer/btc/signerBtc.js +15 -1
  65. package/dist.commonjs/signer/btc/verify.d.ts +3 -0
  66. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -0
  67. package/dist.commonjs/signer/btc/verify.js +10 -0
  68. package/dist.commonjs/signer/ckb/index.d.ts +1 -0
  69. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
  70. package/dist.commonjs/signer/ckb/index.js +1 -0
  71. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +3 -1
  72. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  73. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +7 -1
  74. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +3 -0
  75. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -0
  76. package/dist.commonjs/signer/ckb/verifyJoyId.js +16 -0
  77. package/dist.commonjs/signer/evm/index.d.ts +1 -0
  78. package/dist.commonjs/signer/evm/index.d.ts.map +1 -1
  79. package/dist.commonjs/signer/evm/index.js +1 -0
  80. package/dist.commonjs/signer/evm/signerEvm.d.ts +3 -1
  81. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  82. package/dist.commonjs/signer/evm/signerEvm.js +7 -1
  83. package/dist.commonjs/signer/evm/verify.d.ts +3 -0
  84. package/dist.commonjs/signer/evm/verify.d.ts.map +1 -0
  85. package/dist.commonjs/signer/evm/verify.js +10 -0
  86. package/dist.commonjs/signer/signer.d.ts +60 -14
  87. package/dist.commonjs/signer/signer.d.ts.map +1 -1
  88. package/dist.commonjs/signer/signer.js +97 -17
  89. package/package.json +6 -3
  90. package/src/address/index.ts +4 -7
  91. package/src/client/client.ts +2 -2
  92. package/src/client/clientPublicMainnet.ts +1 -1
  93. package/src/client/clientPublicTestnet.ts +1 -1
  94. package/src/client/jsonRpc/index.ts +3 -3
  95. package/src/signer/btc/index.ts +1 -0
  96. package/src/signer/btc/signerBtc.ts +19 -2
  97. package/src/signer/btc/verify.ts +14 -0
  98. package/src/signer/ckb/index.ts +1 -0
  99. package/src/signer/ckb/signerCkbScriptReadonly.ts +10 -2
  100. package/src/signer/ckb/verifyJoyId.ts +20 -0
  101. package/src/signer/evm/index.ts +1 -0
  102. package/src/signer/evm/signerEvm.ts +10 -2
  103. package/src/signer/evm/verify.ts +16 -0
  104. package/src/signer/signer.ts +125 -15
  105. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
@@ -4,6 +4,26 @@ import { Transaction, TransactionLike } from "../ckb";
4
4
  import { Client } from "../client";
5
5
  import { Hex } from "../hex";
6
6
  import { Num } from "../num";
7
+ export declare enum SignerSignType {
8
+ Unknown = "Unknown",
9
+ BtcEcdsa = "BtcEcdsa",
10
+ EvmPersonal = "EvmPersonal",
11
+ JoyId = "JoyId"
12
+ }
13
+ /**
14
+ * An enumeration of signer display types in wallet.
15
+ */
16
+ export declare enum SignerType {
17
+ EVM = "EVM",
18
+ BTC = "BTC",
19
+ CKB = "CKB"
20
+ }
21
+ export declare class Signature {
22
+ signature: string;
23
+ identity: string;
24
+ signType: SignerSignType;
25
+ constructor(signature: string, identity: string, signType: SignerSignType);
26
+ }
7
27
  /**
8
28
  * An abstract class representing a generic signer.
9
29
  * This class provides methods to connect, get addresses, and sign transactions.
@@ -11,7 +31,10 @@ import { Num } from "../num";
11
31
  export declare abstract class Signer {
12
32
  protected client_: Client;
13
33
  constructor(client_: Client);
34
+ abstract get type(): SignerType;
35
+ abstract get signType(): SignerSignType;
14
36
  get client(): Client;
37
+ static verifyMessage(message: string | BytesLike, signature: Signature): Promise<boolean>;
15
38
  /**
16
39
  * Construct a new signer with the client replaced.
17
40
  *
@@ -42,6 +65,12 @@ export declare abstract class Signer {
42
65
  * @returns A promise that resolves to a string representing the internal address.
43
66
  */
44
67
  abstract getInternalAddress(): Promise<string>;
68
+ /**
69
+ * Gets the identity for verifying signature, usually it's address
70
+ *
71
+ * @returns A promise that resolves to a string representing the identity
72
+ */
73
+ getIdentity(): Promise<string>;
45
74
  /**
46
75
  * Gets an array of Address objects associated with the signer.
47
76
  *
@@ -75,13 +104,39 @@ export declare abstract class Signer {
75
104
  */
76
105
  getBalance(): Promise<Num>;
77
106
  /**
78
- * Signs a message. This method is not implemented and should be overridden by subclasses.
107
+ * Signs a message.
108
+ *
109
+ * @param _ - The message to sign, as a string or BytesLike object.
110
+ * @returns A promise that resolves to the signature info.
111
+ * @throws Will throw an error if not implemented.
112
+ */
113
+ signMessage(message: string | BytesLike): Promise<Signature>;
114
+ /**
115
+ * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
79
116
  *
80
117
  * @param _ - The message to sign, as a string or BytesLike object.
81
- * @returns A promise that resolves to the signed message as a string.
118
+ * @returns A promise that resolves to the signature as a string.
119
+ * @throws Will throw an error if not implemented.
120
+ */
121
+ signMessageRaw(_: string | BytesLike): Promise<string>;
122
+ /**
123
+ * Verify a signature.
124
+ *
125
+ * @param _ - The original message.
126
+ * @param _ - The signature to verify.
127
+ * @returns A promise that resolves to the verification result.
128
+ * @throws Will throw an error if not implemented.
129
+ */
130
+ verifyMessage(message: string | BytesLike, signature: string | Signature): Promise<boolean>;
131
+ /**
132
+ * Verify a string signature. This method is not implemented and should be overridden by subclasses.
133
+ *
134
+ * @param _0 - The original message.
135
+ * @param _1 - The signature to verify.
136
+ * @returns A promise that resolves to the verification result.
82
137
  * @throws Will throw an error if not implemented.
83
138
  */
84
- signMessage(_: string | BytesLike): Promise<string>;
139
+ verifyMessageRaw(_0: string | BytesLike, _1: string): Promise<boolean>;
85
140
  /**
86
141
  * Sends a transaction after signing it.
87
142
  *
@@ -105,7 +160,7 @@ export declare abstract class Signer {
105
160
  */
106
161
  prepareTransaction(_: TransactionLike): Promise<Transaction>;
107
162
  /**
108
- * Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
163
+ * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
109
164
  *
110
165
  * @param _ - The transaction to sign, represented as a TransactionLike object.
111
166
  * @returns A promise that resolves to the signed Transaction object.
@@ -113,22 +168,13 @@ export declare abstract class Signer {
113
168
  */
114
169
  signOnlyTransaction(_: TransactionLike): Promise<Transaction>;
115
170
  }
116
- /**
117
- * An enumeration of signer types.
118
- */
119
- export declare enum SignerType {
120
- EVM = "EVM",
121
- BTC = "BTC",
122
- CKB = "CKB"
123
- }
124
171
  /**
125
172
  * A class representing information about a signer, including its type and the signer instance.
126
173
  */
127
174
  export declare class SignerInfo {
128
175
  name: string;
129
- type: SignerType;
130
176
  signer: Signer;
131
- constructor(name: string, type: SignerType, signer: Signer);
177
+ constructor(name: string, signer: Signer);
132
178
  }
133
179
  /**
134
180
  * Represents a wallet with a name, icon, and an array of signer information.
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B;;;GAGG;AACH,8BAAsB,MAAM;IACd,SAAS,CAAC,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;IAErC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAEvD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAExC;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IA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AC;IAKhE;;;;;;OAMG;IACH,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAG9D;AAED;;GAEG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1,6 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerInfo = exports.SignerType = exports.Signer = void 0;
3
+ exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = exports.SignerSignType = void 0;
4
+ const btc_1 = require("./btc");
5
+ const verifyJoyId_1 = require("./ckb/verifyJoyId");
6
+ const verify_1 = require("./evm/verify");
7
+ var SignerSignType;
8
+ (function (SignerSignType) {
9
+ SignerSignType["Unknown"] = "Unknown";
10
+ SignerSignType["BtcEcdsa"] = "BtcEcdsa";
11
+ SignerSignType["EvmPersonal"] = "EvmPersonal";
12
+ SignerSignType["JoyId"] = "JoyId";
13
+ })(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
14
+ /**
15
+ * An enumeration of signer display types in wallet.
16
+ */
17
+ var SignerType;
18
+ (function (SignerType) {
19
+ SignerType["EVM"] = "EVM";
20
+ SignerType["BTC"] = "BTC";
21
+ SignerType["CKB"] = "CKB";
22
+ })(SignerType || (exports.SignerType = SignerType = {}));
23
+ class Signature {
24
+ constructor(signature, identity, signType) {
25
+ this.signature = signature;
26
+ this.identity = identity;
27
+ this.signType = signType;
28
+ }
29
+ }
30
+ exports.Signature = Signature;
4
31
  /**
5
32
  * An abstract class representing a generic signer.
6
33
  * This class provides methods to connect, get addresses, and sign transactions.
@@ -12,12 +39,32 @@ class Signer {
12
39
  get client() {
13
40
  return this.client_;
14
41
  }
42
+ static async verifyMessage(message, signature) {
43
+ switch (signature.signType) {
44
+ case SignerSignType.EvmPersonal:
45
+ return (0, verify_1.verifyMessageEvmPersonal)(message, signature.signature, signature.identity);
46
+ case SignerSignType.BtcEcdsa:
47
+ return (0, btc_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
48
+ case SignerSignType.JoyId:
49
+ return (0, verifyJoyId_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
50
+ case SignerSignType.Unknown:
51
+ throw new Error("Unknown signer sign type");
52
+ }
53
+ }
15
54
  /**
16
55
  * Disconnects to the signer.
17
56
  *
18
57
  * @returns A promise that resolves when disconnected.
19
58
  */
20
59
  async disconnect() { }
60
+ /**
61
+ * Gets the identity for verifying signature, usually it's address
62
+ *
63
+ * @returns A promise that resolves to a string representing the identity
64
+ */
65
+ async getIdentity() {
66
+ return this.getInternalAddress();
67
+ }
21
68
  /**
22
69
  * Gets the recommended Address object for the signer.
23
70
  *
@@ -53,14 +100,57 @@ class Signer {
53
100
  return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
54
101
  }
55
102
  /**
56
- * Signs a message. This method is not implemented and should be overridden by subclasses.
103
+ * Signs a message.
57
104
  *
58
105
  * @param _ - The message to sign, as a string or BytesLike object.
59
- * @returns A promise that resolves to the signed message as a string.
106
+ * @returns A promise that resolves to the signature info.
60
107
  * @throws Will throw an error if not implemented.
61
108
  */
62
- signMessage(_) {
63
- throw Error("Signer.signMessage not implemented");
109
+ async signMessage(message) {
110
+ return {
111
+ signature: await this.signMessageRaw(message),
112
+ identity: await this.getIdentity(),
113
+ signType: this.signType,
114
+ };
115
+ }
116
+ /**
117
+ * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
118
+ *
119
+ * @param _ - The message to sign, as a string or BytesLike object.
120
+ * @returns A promise that resolves to the signature as a string.
121
+ * @throws Will throw an error if not implemented.
122
+ */
123
+ signMessageRaw(_) {
124
+ throw Error("Signer.signMessageRaw not implemented");
125
+ }
126
+ /**
127
+ * Verify a signature.
128
+ *
129
+ * @param _ - The original message.
130
+ * @param _ - The signature to verify.
131
+ * @returns A promise that resolves to the verification result.
132
+ * @throws Will throw an error if not implemented.
133
+ */
134
+ async verifyMessage(message, signature) {
135
+ if (typeof signature === "string") {
136
+ return this.verifyMessageRaw(message, signature);
137
+ }
138
+ if (signature.identity !== (await this.getIdentity()) ||
139
+ ![SignerSignType.Unknown, this.signType].includes(signature.signType)) {
140
+ return false;
141
+ }
142
+ return this.verifyMessageRaw(message, signature.signature);
143
+ }
144
+ /**
145
+ * Verify a string signature. This method is not implemented and should be overridden by subclasses.
146
+ *
147
+ * @param _0 - The original message.
148
+ * @param _1 - The signature to verify.
149
+ * @returns A promise that resolves to the verification result.
150
+ * @throws Will throw an error if not implemented.
151
+ */
152
+ verifyMessageRaw(_0, _1) {
153
+ throw Error("Signer.verifyMessageRaw not implemented");
64
154
  }
65
155
  /**
66
156
  * Sends a transaction after signing it.
@@ -92,7 +182,7 @@ class Signer {
92
182
  throw Error("Signer.prepareTransaction not implemented");
93
183
  }
94
184
  /**
95
- * Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
185
+ * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
96
186
  *
97
187
  * @param _ - The transaction to sign, represented as a TransactionLike object.
98
188
  * @returns A promise that resolves to the signed Transaction object.
@@ -103,22 +193,12 @@ class Signer {
103
193
  }
104
194
  }
105
195
  exports.Signer = Signer;
106
- /**
107
- * An enumeration of signer types.
108
- */
109
- var SignerType;
110
- (function (SignerType) {
111
- SignerType["EVM"] = "EVM";
112
- SignerType["BTC"] = "BTC";
113
- SignerType["CKB"] = "CKB";
114
- })(SignerType || (exports.SignerType = SignerType = {}));
115
196
  /**
116
197
  * A class representing information about a signer, including its type and the signer instance.
117
198
  */
118
199
  class SignerInfo {
119
- constructor(name, type, signer) {
200
+ constructor(name, signer) {
120
201
  this.name = name;
121
- this.type = type;
122
202
  this.signer = signer;
123
203
  }
124
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.5-alpha.1",
3
+ "version": "0.0.5-alpha.2",
4
4
  "description": "Common Chains Connector Core",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -57,12 +57,15 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@ckb-lumos/helpers": "^0.22.2",
60
+ "@joyid/ckb": "^0.0.11",
60
61
  "@noble/hashes": "^1.4.0",
62
+ "@unisat/wallet-utils": "^1.0.0",
61
63
  "abort-controller": "^3.0.0",
62
64
  "bech32": "^2.0.0",
63
65
  "blake2b": "^2.1.4",
64
66
  "buffer": "^6.0.3",
65
- "cross-fetch": "^4.0.0"
67
+ "cross-fetch": "^4.0.0",
68
+ "ethers": "^6.13.1"
66
69
  },
67
- "gitHead": "98d6d902fff0cc3d65f536cb85b32c867045d15d"
70
+ "gitHead": "abbcbe8e25dc561e0a134d3906f40bb49b8a035f"
68
71
  }
@@ -66,7 +66,7 @@ export class Address {
66
66
  if (!client) {
67
67
  throw new Error(`Unknown address prefix ${prefix}`);
68
68
  }
69
- const expectedPrefix = await client.getAddressPrefix();
69
+ const expectedPrefix = client.addressPrefix;
70
70
  if (expectedPrefix !== prefix) {
71
71
  throw new Error(
72
72
  `Unknown address prefix ${prefix}, expected ${expectedPrefix}`,
@@ -86,11 +86,8 @@ export class Address {
86
86
  * @returns A promise that resolves to an Address instance.
87
87
  */
88
88
 
89
- static async fromScript(
90
- script: ScriptLike,
91
- client: Client,
92
- ): Promise<Address> {
93
- return Address.from({ script, prefix: await client.getAddressPrefix() });
89
+ static fromScript(script: ScriptLike, client: Client): Address {
90
+ return Address.from({ script, prefix: client.addressPrefix });
94
91
  }
95
92
 
96
93
  static async fromKnownScript(
@@ -103,7 +100,7 @@ export class Address {
103
100
  ...(await client.getKnownScript(script)),
104
101
  args,
105
102
  },
106
- prefix: await client.getAddressPrefix(),
103
+ prefix: client.addressPrefix,
107
104
  });
108
105
  }
109
106
 
@@ -25,9 +25,9 @@ export enum KnownScript {
25
25
  }
26
26
 
27
27
  export abstract class Client {
28
- abstract getUrl(): string;
28
+ abstract get url(): string;
29
+ abstract get addressPrefix(): string;
29
30
 
30
- abstract getAddressPrefix(): Promise<string>;
31
31
  abstract getKnownScript(
32
32
  script: KnownScript,
33
33
  ): Promise<Pick<Script, "codeHash" | "hashType">>;
@@ -8,7 +8,7 @@ export class ClientPublicMainnet extends ClientJsonRpc {
8
8
  super(url, timeout);
9
9
  }
10
10
 
11
- async getAddressPrefix(): Promise<string> {
11
+ get addressPrefix(): string {
12
12
  return "ckb";
13
13
  }
14
14
 
@@ -8,7 +8,7 @@ export class ClientPublicTestnet extends ClientJsonRpc {
8
8
  super(url, timeout);
9
9
  }
10
10
 
11
- async getAddressPrefix(): Promise<string> {
11
+ get addressPrefix(): string {
12
12
  return "ckt";
13
13
  }
14
14
 
@@ -49,7 +49,7 @@ export abstract class ClientJsonRpc extends Client {
49
49
  */
50
50
 
51
51
  constructor(
52
- private readonly url: string,
52
+ private readonly url_: string,
53
53
  private readonly timeout = 30000,
54
54
  ) {
55
55
  super();
@@ -61,8 +61,8 @@ export abstract class ClientJsonRpc extends Client {
61
61
  * @returns The URL of the JSON-RPC server.
62
62
  */
63
63
 
64
- getUrl() {
65
- return this.url;
64
+ get url() {
65
+ return this.url_;
66
66
  }
67
67
 
68
68
  /**
@@ -1,2 +1,3 @@
1
1
  export * from "./signerBtc";
2
2
  export * from "./signerBtcPublicKeyReadonly";
3
+ export * from "./verify";
@@ -6,7 +6,7 @@ import { Transaction, TransactionLike, WitnessArgs } from "../../ckb";
6
6
  import { KnownScript } from "../../client";
7
7
  import { HexLike, hexFrom } from "../../hex";
8
8
  import { numToBytes } from "../../num";
9
- import { Signer } from "../signer";
9
+ import { Signer, SignerSignType, SignerType } from "../signer";
10
10
 
11
11
  /**
12
12
  * An abstract class extending the Signer class for Bitcoin-like signing operations.
@@ -14,6 +14,14 @@ import { Signer } from "../signer";
14
14
  * as well as signing transactions.
15
15
  */
16
16
  export abstract class SignerBtc extends Signer {
17
+ get type(): SignerType {
18
+ return SignerType.BTC;
19
+ }
20
+
21
+ get signType(): SignerSignType {
22
+ return SignerSignType.BtcEcdsa;
23
+ }
24
+
17
25
  /**
18
26
  * Gets the Bitcoin account associated with the signer.
19
27
  *
@@ -37,6 +45,15 @@ export abstract class SignerBtc extends Signer {
37
45
  return this.getBtcAccount();
38
46
  }
39
47
 
48
+ /**
49
+ * Gets the identity, which is the Bitcoin public key in this case.
50
+ *
51
+ * @returns A promise that resolves to a string representing the identity
52
+ */
53
+ async getIdentity(): Promise<string> {
54
+ return hexFrom(await this.getBtcPublicKey()).slice(2);
55
+ }
56
+
40
57
  /**
41
58
  * Gets an array of Address objects representing the known script addresses for the signer.
42
59
  *
@@ -85,7 +102,7 @@ export abstract class SignerBtc extends Signer {
85
102
  }
86
103
 
87
104
  const signature = bytesFrom(
88
- await this.signMessage(
105
+ await this.signMessageRaw(
89
106
  `CKB (Bitcoin Layer) transaction: ${info.message}`,
90
107
  ),
91
108
  "base64",
@@ -0,0 +1,14 @@
1
+ import { verifyMessage } from "@unisat/wallet-utils";
2
+ import { BytesLike } from "../../bytes";
3
+ import { hexFrom } from "../../hex";
4
+
5
+ export function verifyMessageBtcEcdsa(
6
+ message: string | BytesLike,
7
+ signature: string,
8
+ publicKey: string,
9
+ ): boolean {
10
+ const challenge =
11
+ typeof message === "string" ? message : hexFrom(message).slice(2);
12
+
13
+ return verifyMessage(publicKey, challenge, signature);
14
+ }
@@ -1 +1,2 @@
1
1
  export * from "./signerCkbScriptReadonly";
2
+ export * from "./verifyJoyId";
@@ -1,13 +1,21 @@
1
1
  import { Address } from "../../address";
2
2
  import { Script, ScriptLike } from "../../ckb";
3
3
  import { Client } from "../../client";
4
- import { Signer } from "../signer";
4
+ import { Signer, SignerSignType, SignerType } from "../signer";
5
5
 
6
6
  /**
7
7
  * A class extending Signer that provides read-only access to a CKB script.
8
8
  * This class does not support signing operations.
9
9
  */
10
10
  export class SignerCkbScriptReadonly extends Signer {
11
+ get type(): SignerType {
12
+ return SignerType.CKB;
13
+ }
14
+
15
+ get signType(): SignerSignType {
16
+ return SignerSignType.Unknown;
17
+ }
18
+
11
19
  private readonly script: Script;
12
20
 
13
21
  /**
@@ -73,6 +81,6 @@ export class SignerCkbScriptReadonly extends Signer {
73
81
  */
74
82
 
75
83
  async getAddressObjs(): Promise<Address[]> {
76
- return [await Address.fromScript(this.script, this.client)];
84
+ return [Address.fromScript(this.script, this.client)];
77
85
  }
78
86
  }
@@ -0,0 +1,20 @@
1
+ import { verifySignature } from "@joyid/ckb";
2
+ import { BytesLike } from "../../bytes";
3
+ import { hexFrom } from "../../hex";
4
+
5
+ export function verifyMessageJoyId(
6
+ message: string | BytesLike,
7
+ signature: string,
8
+ identity: string,
9
+ ): Promise<boolean> {
10
+ const challenge =
11
+ typeof message === "string" ? message : hexFrom(message).slice(2);
12
+ const { publicKey, keyType } = JSON.parse(identity);
13
+
14
+ return verifySignature({
15
+ challenge,
16
+ pubkey: publicKey,
17
+ keyType,
18
+ ...JSON.parse(signature),
19
+ });
20
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./signerEvm";
2
2
  export * from "./signerEvmAddressReadonly";
3
+ export * from "./verify";
@@ -4,13 +4,21 @@ import { Script, Transaction, TransactionLike, WitnessArgs } from "../../ckb";
4
4
  import { KnownScript } from "../../client";
5
5
  import { hexFrom } from "../../hex";
6
6
  import { numToBytes } from "../../num";
7
- import { Signer } from "../signer";
7
+ import { Signer, SignerSignType, SignerType } from "../signer";
8
8
 
9
9
  /**
10
10
  * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
11
11
  * This class provides methods to get EVM account, internal address, and signing transactions.
12
12
  */
13
13
  export abstract class SignerEvm extends Signer {
14
+ get type(): SignerType {
15
+ return SignerType.EVM;
16
+ }
17
+
18
+ get signType(): SignerSignType {
19
+ return SignerSignType.EvmPersonal;
20
+ }
21
+
14
22
  /**
15
23
  * Gets the EVM account associated with the signer.
16
24
  *
@@ -113,7 +121,7 @@ export abstract class SignerEvm extends Signer {
113
121
  }
114
122
 
115
123
  const signature = bytesFrom(
116
- await this.signMessage(messageTransformer(info.message)),
124
+ await this.signMessageRaw(messageTransformer(info.message)),
117
125
  );
118
126
  if (signature[signature.length - 1] >= 27) {
119
127
  signature[signature.length - 1] -= 27;
@@ -0,0 +1,16 @@
1
+ import { verifyMessage } from "ethers";
2
+ import { BytesLike, bytesFrom } from "../../bytes";
3
+
4
+ export function verifyMessageEvmPersonal(
5
+ message: string | BytesLike,
6
+ signature: string,
7
+ address: string,
8
+ ): boolean {
9
+ return (
10
+ address.toLowerCase() ===
11
+ verifyMessage(
12
+ typeof message === "string" ? message : bytesFrom(message),
13
+ signature,
14
+ ).toLowerCase()
15
+ );
16
+ }