@ckb-ccc/core 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 (265) hide show
  1. package/dist/address/address.advanced.d.ts.map +1 -1
  2. package/dist/address/address.advanced.js +2 -5
  3. package/dist/address/index.d.ts +1 -1
  4. package/dist/address/index.d.ts.map +1 -1
  5. package/dist/address/index.js +2 -5
  6. package/dist/ckb/script.d.ts +43 -1
  7. package/dist/ckb/script.d.ts.map +1 -1
  8. package/dist/ckb/script.js +51 -0
  9. package/dist/ckb/transaction.d.ts +215 -27
  10. package/dist/ckb/transaction.d.ts.map +1 -1
  11. package/dist/ckb/transaction.js +472 -32
  12. package/dist/client/advanced.d.ts +2 -0
  13. package/dist/client/advanced.d.ts.map +1 -1
  14. package/dist/client/advanced.js +2 -0
  15. package/dist/client/client.advanced.d.ts +10 -0
  16. package/dist/client/client.advanced.d.ts.map +1 -0
  17. package/dist/client/client.advanced.js +80 -0
  18. package/dist/client/client.d.ts +50 -13
  19. package/dist/client/client.d.ts.map +1 -1
  20. package/dist/client/client.js +145 -15
  21. package/dist/client/clientPublicMainnet.advanced.d.ts +4 -2
  22. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  23. package/dist/client/clientPublicMainnet.advanced.js +103 -0
  24. package/dist/client/clientPublicMainnet.d.ts +4 -2
  25. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  26. package/dist/client/clientPublicMainnet.js +9 -1
  27. package/dist/client/clientPublicTestnet.advanced.d.ts +4 -2
  28. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  29. package/dist/client/clientPublicTestnet.advanced.js +155 -0
  30. package/dist/client/clientPublicTestnet.d.ts +4 -2
  31. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.js +6 -1
  33. package/dist/client/clientTypes.advanced.d.ts +23 -0
  34. package/dist/client/clientTypes.advanced.d.ts.map +1 -0
  35. package/dist/client/clientTypes.advanced.js +4 -0
  36. package/dist/client/clientTypes.d.ts +22 -36
  37. package/dist/client/clientTypes.d.ts.map +1 -1
  38. package/dist/client/clientTypes.js +15 -12
  39. package/dist/client/jsonRpc/index.d.ts +3 -3
  40. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  41. package/dist/client/jsonRpc/index.js +3 -3
  42. package/dist/client/jsonRpc/transformers.d.ts +5 -7
  43. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  44. package/dist/client/jsonRpc/transformers.js +8 -6
  45. package/dist/hasher/index.d.ts +1 -1
  46. package/dist/hasher/index.d.ts.map +1 -1
  47. package/dist/hasher/index.js +4 -2
  48. package/dist/num/index.d.ts +12 -0
  49. package/dist/num/index.d.ts.map +1 -1
  50. package/dist/num/index.js +21 -0
  51. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  52. package/dist/signer/btc/signerBtc.js +6 -3
  53. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  54. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  55. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  56. package/dist/signer/btc/verify.d.ts.map +1 -1
  57. package/dist/signer/btc/verify.js +5 -2
  58. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  59. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  60. package/dist/signer/ckb/signerCkbScriptReadonly.js +0 -8
  61. package/dist/signer/dummy/alwaysError.d.ts +0 -1
  62. package/dist/signer/dummy/alwaysError.d.ts.map +1 -1
  63. package/dist/signer/dummy/alwaysError.js +0 -3
  64. package/dist/signer/dummy/openLink.d.ts +0 -1
  65. package/dist/signer/dummy/openLink.d.ts.map +1 -1
  66. package/dist/signer/dummy/openLink.js +0 -3
  67. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  68. package/dist/signer/evm/signerEvm.js +7 -5
  69. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  70. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  71. package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
  72. package/dist/signer/index.d.ts +1 -0
  73. package/dist/signer/index.d.ts.map +1 -1
  74. package/dist/signer/index.js +1 -0
  75. package/dist/signer/nostr/index.d.ts +2 -0
  76. package/dist/signer/nostr/index.d.ts.map +1 -0
  77. package/dist/signer/nostr/index.js +1 -0
  78. package/dist/signer/nostr/signerNostr.d.ts +66 -0
  79. package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
  80. package/dist/signer/nostr/signerNostr.js +85 -0
  81. package/dist/signer/nostr/verify.d.ts +5 -0
  82. package/dist/signer/nostr/verify.d.ts.map +1 -0
  83. package/dist/signer/nostr/verify.js +48 -0
  84. package/dist/signer/signer/index.d.ts +7 -12
  85. package/dist/signer/signer/index.d.ts.map +1 -1
  86. package/dist/signer/signer/index.js +11 -4
  87. package/dist/utils/index.d.ts +59 -0
  88. package/dist/utils/index.d.ts.map +1 -1
  89. package/dist/utils/index.js +17 -0
  90. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  91. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  92. package/dist.commonjs/address/address.advanced.js +115 -92
  93. package/dist.commonjs/address/advanced.d.ts +1 -1
  94. package/dist.commonjs/address/advanced.js +30 -14
  95. package/dist.commonjs/address/index.d.ts +51 -44
  96. package/dist.commonjs/address/index.d.ts.map +1 -1
  97. package/dist.commonjs/address/index.js +84 -68
  98. package/dist.commonjs/advanced.d.ts +1 -1
  99. package/dist.commonjs/advanced.js +47 -22
  100. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  101. package/dist.commonjs/advancedBarrel.js +30 -14
  102. package/dist.commonjs/barrel.d.ts +1 -1
  103. package/dist.commonjs/barrel.js +30 -14
  104. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  105. package/dist.commonjs/bytes/index.d.ts +9 -3
  106. package/dist.commonjs/bytes/index.js +28 -26
  107. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  108. package/dist.commonjs/ckb/advanced.js +47 -22
  109. package/dist.commonjs/ckb/index.d.ts +1 -1
  110. package/dist.commonjs/ckb/index.js +30 -14
  111. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  112. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  113. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  114. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  115. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  116. package/dist.commonjs/ckb/script.advanced.js +12 -9
  117. package/dist.commonjs/ckb/script.d.ts +123 -77
  118. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  119. package/dist.commonjs/ckb/script.js +221 -126
  120. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  121. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  122. package/dist.commonjs/ckb/transaction.d.ts +796 -533
  123. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  124. package/dist.commonjs/ckb/transaction.js +1372 -702
  125. package/dist.commonjs/client/advanced.d.ts +3 -1
  126. package/dist.commonjs/client/advanced.d.ts.map +1 -1
  127. package/dist.commonjs/client/advanced.js +32 -14
  128. package/dist.commonjs/client/client.advanced.d.ts +27 -0
  129. package/dist.commonjs/client/client.advanced.d.ts.map +1 -0
  130. package/dist.commonjs/client/client.advanced.js +116 -0
  131. package/dist.commonjs/client/client.d.ts +118 -21
  132. package/dist.commonjs/client/client.d.ts.map +1 -1
  133. package/dist.commonjs/client/client.js +219 -55
  134. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +9 -3
  135. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  136. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -24
  137. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -5
  138. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  139. package/dist.commonjs/client/clientPublicMainnet.js +18 -8
  140. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +8 -3
  141. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  142. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -24
  143. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -5
  144. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  145. package/dist.commonjs/client/clientPublicTestnet.js +14 -9
  146. package/dist.commonjs/client/clientTypes.advanced.d.ts +23 -0
  147. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -0
  148. package/dist.commonjs/client/clientTypes.advanced.js +8 -0
  149. package/dist.commonjs/client/clientTypes.d.ts +57 -46
  150. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  151. package/dist.commonjs/client/clientTypes.js +60 -22
  152. package/dist.commonjs/client/index.d.ts +1 -1
  153. package/dist.commonjs/client/index.js +30 -14
  154. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  155. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  156. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  157. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  158. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  159. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -38
  160. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  161. package/dist.commonjs/client/jsonRpc/transformers.js +174 -150
  162. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  163. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  164. package/dist.commonjs/fixedPoint/index.js +26 -20
  165. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  166. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  167. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  168. package/dist.commonjs/hasher/index.d.ts +37 -37
  169. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  170. package/dist.commonjs/hasher/index.js +55 -46
  171. package/dist.commonjs/hex/index.d.ts +1 -1
  172. package/dist.commonjs/hex/index.js +1 -1
  173. package/dist.commonjs/index.d.ts +1 -1
  174. package/dist.commonjs/index.js +47 -22
  175. package/dist.commonjs/num/index.d.ts +13 -1
  176. package/dist.commonjs/num/index.d.ts.map +1 -1
  177. package/dist.commonjs/num/index.js +53 -19
  178. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  179. package/dist.commonjs/signer/btc/index.js +30 -14
  180. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  181. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  182. package/dist.commonjs/signer/btc/signerBtc.js +89 -63
  183. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -51
  184. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  185. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -60
  186. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  187. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  188. package/dist.commonjs/signer/btc/verify.js +13 -3
  189. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  190. package/dist.commonjs/signer/ckb/index.js +30 -14
  191. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -51
  192. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  193. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -64
  194. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  195. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  196. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -5
  197. package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -1
  198. package/dist.commonjs/signer/dummy/alwaysError.js +7 -10
  199. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  200. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  201. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  202. package/dist.commonjs/signer/dummy/index.js +30 -14
  203. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -5
  204. package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -1
  205. package/dist.commonjs/signer/dummy/openLink.js +7 -10
  206. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  207. package/dist.commonjs/signer/evm/index.js +30 -14
  208. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  209. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  210. package/dist.commonjs/signer/evm/signerEvm.js +106 -69
  211. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -43
  212. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  213. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -50
  214. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  215. package/dist.commonjs/signer/evm/verify.js +7 -2
  216. package/dist.commonjs/signer/index.d.ts +2 -1
  217. package/dist.commonjs/signer/index.d.ts.map +1 -1
  218. package/dist.commonjs/signer/index.js +31 -14
  219. package/dist.commonjs/signer/nostr/index.d.ts +2 -0
  220. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
  221. package/dist.commonjs/signer/nostr/index.js +33 -0
  222. package/dist.commonjs/signer/nostr/signerNostr.d.ts +66 -0
  223. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
  224. package/dist.commonjs/signer/nostr/signerNostr.js +118 -0
  225. package/dist.commonjs/signer/nostr/verify.d.ts +11 -0
  226. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
  227. package/dist.commonjs/signer/nostr/verify.js +64 -0
  228. package/dist.commonjs/signer/signer/index.d.ts +156 -155
  229. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  230. package/dist.commonjs/signer/signer/index.js +209 -175
  231. package/dist.commonjs/utils/index.d.ts +95 -6
  232. package/dist.commonjs/utils/index.d.ts.map +1 -1
  233. package/dist.commonjs/utils/index.js +30 -6
  234. package/package.json +4 -3
  235. package/src/address/address.advanced.ts +2 -5
  236. package/src/address/index.ts +2 -5
  237. package/src/ckb/script.ts +62 -2
  238. package/src/ckb/transaction.ts +678 -58
  239. package/src/client/advanced.ts +2 -0
  240. package/src/client/client.advanced.ts +134 -0
  241. package/src/client/client.ts +236 -25
  242. package/src/client/clientPublicMainnet.advanced.ts +117 -2
  243. package/src/client/clientPublicMainnet.ts +14 -3
  244. package/src/client/clientPublicTestnet.advanced.ts +176 -2
  245. package/src/client/clientPublicTestnet.ts +9 -3
  246. package/src/client/clientTypes.advanced.ts +26 -0
  247. package/src/client/clientTypes.ts +41 -43
  248. package/src/client/jsonRpc/index.ts +4 -4
  249. package/src/client/jsonRpc/transformers.ts +13 -11
  250. package/src/hasher/index.ts +4 -2
  251. package/src/num/index.ts +22 -0
  252. package/src/signer/btc/signerBtc.ts +6 -8
  253. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
  254. package/src/signer/btc/verify.ts +6 -3
  255. package/src/signer/ckb/signerCkbScriptReadonly.ts +0 -9
  256. package/src/signer/dummy/alwaysError.ts +0 -4
  257. package/src/signer/dummy/openLink.ts +0 -4
  258. package/src/signer/evm/signerEvm.ts +11 -11
  259. package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
  260. package/src/signer/index.ts +1 -0
  261. package/src/signer/nostr/index.ts +1 -0
  262. package/src/signer/nostr/signerNostr.ts +135 -0
  263. package/src/signer/nostr/verify.ts +63 -0
  264. package/src/signer/signer/index.ts +15 -11
  265. package/src/utils/index.ts +108 -0
@@ -1,31 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = exports.SignerSignType = void 0;
3
+ exports.SignerInfo =
4
+ exports.Signer =
5
+ exports.Signature =
6
+ exports.SignerType =
7
+ exports.SignerSignType =
8
+ void 0;
4
9
  const btc_1 = require("../btc");
5
10
  const verifyJoyId_1 = require("../ckb/verifyJoyId");
6
11
  const verify_1 = require("../evm/verify");
12
+ const verify_2 = require("../nostr/verify");
7
13
  var SignerSignType;
8
14
  (function (SignerSignType) {
9
- SignerSignType["Unknown"] = "Unknown";
10
- SignerSignType["BtcEcdsa"] = "BtcEcdsa";
11
- SignerSignType["EvmPersonal"] = "EvmPersonal";
12
- SignerSignType["JoyId"] = "JoyId";
15
+ SignerSignType["Unknown"] = "Unknown";
16
+ SignerSignType["BtcEcdsa"] = "BtcEcdsa";
17
+ SignerSignType["EvmPersonal"] = "EvmPersonal";
18
+ SignerSignType["JoyId"] = "JoyId";
19
+ SignerSignType["NostrEvent"] = "NostrEvent";
13
20
  })(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
14
21
  /**
15
22
  * An enumeration of signer display types in wallet.
16
23
  */
17
24
  var SignerType;
18
25
  (function (SignerType) {
19
- SignerType["EVM"] = "EVM";
20
- SignerType["BTC"] = "BTC";
21
- SignerType["CKB"] = "CKB";
26
+ SignerType["EVM"] = "EVM";
27
+ SignerType["BTC"] = "BTC";
28
+ SignerType["CKB"] = "CKB";
29
+ SignerType["Nostr"] = "Nostr";
22
30
  })(SignerType || (exports.SignerType = SignerType = {}));
23
31
  class Signature {
24
- constructor(signature, identity, signType) {
25
- this.signature = signature;
26
- this.identity = identity;
27
- this.signType = signType;
28
- }
32
+ constructor(signature, identity, signType) {
33
+ this.signature = signature;
34
+ this.identity = identity;
35
+ this.signType = signType;
36
+ }
29
37
  }
30
38
  exports.Signature = Signature;
31
39
  /**
@@ -33,173 +41,199 @@ exports.Signature = Signature;
33
41
  * This class provides methods to connect, get addresses, and sign transactions.
34
42
  */
35
43
  class Signer {
36
- constructor(client_) {
37
- this.client_ = client_;
38
- }
39
- get client() {
40
- return this.client_;
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
- }
54
- /**
55
- * Disconnects to the signer.
56
- *
57
- * @returns A promise that resolves when disconnected.
58
- */
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
- }
68
- /**
69
- * Gets the recommended Address object for the signer.
70
- *
71
- * @param _preference - Optional preference parameter.
72
- * @returns A promise that resolves to the recommended Address object.
73
- */
74
- async getRecommendedAddressObj(_preference) {
75
- return (await this.getAddressObjs())[0];
76
- }
77
- /**
78
- * Gets the recommended address for the signer as a string.
79
- *
80
- * @param preference - Optional preference parameter.
81
- * @returns A promise that resolves to the recommended address as a string.
82
- */
83
- async getRecommendedAddress(preference) {
84
- return (await this.getRecommendedAddressObj(preference)).toString();
85
- }
86
- /**
87
- * Gets an array of addresses associated with the signer as strings.
88
- *
89
- * @returns A promise that resolves to an array of addresses as strings.
90
- */
91
- async getAddresses() {
92
- return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
93
- }
94
- /**
95
- * Gets balance of all addresses
96
- *
97
- * @returns A promise that resolves to the balance
98
- */
99
- async getBalance() {
100
- return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
101
- }
102
- /**
103
- * Signs a message.
104
- *
105
- * @param _ - The message to sign, as a string or BytesLike object.
106
- * @returns A promise that resolves to the signature info.
107
- * @throws Will throw an error if not implemented.
108
- */
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");
154
- }
155
- /**
156
- * Sends a transaction after signing it.
157
- *
158
- * @param tx - The transaction to send, represented as a TransactionLike object.
159
- * @returns A promise that resolves to the transaction hash as a Hex string.
160
- */
161
- async sendTransaction(tx) {
162
- return this.client.sendTransaction(await this.signTransaction(tx));
163
- }
164
- /**
165
- * Signs a transaction.
166
- *
167
- * @param tx - The transaction to sign, represented as a TransactionLike object.
168
- * @returns A promise that resolves to the signed Transaction object.
169
- */
170
- async signTransaction(tx) {
171
- const preparedTx = await this.prepareTransaction(tx);
172
- return this.signOnlyTransaction(preparedTx);
173
- }
174
- /**
175
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
176
- *
177
- * @param _ - The transaction to prepare, represented as a TransactionLike object.
178
- * @returns A promise that resolves to the prepared Transaction object.
179
- * @throws Will throw an error if not implemented.
180
- */
181
- prepareTransaction(_) {
182
- throw Error("Signer.prepareTransaction not implemented");
183
- }
184
- /**
185
- * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
186
- *
187
- * @param _ - The transaction to sign, represented as a TransactionLike object.
188
- * @returns A promise that resolves to the signed Transaction object.
189
- * @throws Will throw an error if not implemented.
190
- */
191
- signOnlyTransaction(_) {
192
- throw Error("Signer.signOnlyTransaction not implemented");
193
- }
44
+ constructor(client_) {
45
+ this.client_ = client_;
46
+ }
47
+ get client() {
48
+ return this.client_;
49
+ }
50
+ static async verifyMessage(message, signature) {
51
+ switch (signature.signType) {
52
+ case SignerSignType.EvmPersonal:
53
+ return (0, verify_1.verifyMessageEvmPersonal)(
54
+ message,
55
+ signature.signature,
56
+ signature.identity,
57
+ );
58
+ case SignerSignType.BtcEcdsa:
59
+ return (0, btc_1.verifyMessageBtcEcdsa)(
60
+ message,
61
+ signature.signature,
62
+ signature.identity,
63
+ );
64
+ case SignerSignType.JoyId:
65
+ return (0, verifyJoyId_1.verifyMessageJoyId)(
66
+ message,
67
+ signature.signature,
68
+ signature.identity,
69
+ );
70
+ case SignerSignType.NostrEvent:
71
+ return (0, verify_2.verifyMessageNostrEvent)(
72
+ message,
73
+ signature.signature,
74
+ signature.identity,
75
+ );
76
+ case SignerSignType.Unknown:
77
+ throw new Error("Unknown signer sign type");
78
+ }
79
+ }
80
+ /**
81
+ * Replace the current client.
82
+ * returns false if the new client is invalid for this signer.
83
+ */
84
+ async replaceClient(client) {
85
+ this.client_ = client;
86
+ return true;
87
+ }
88
+ /**
89
+ * Gets the identity for verifying signature, usually it's address
90
+ *
91
+ * @returns A promise that resolves to a string representing the identity
92
+ */
93
+ async getIdentity() {
94
+ return this.getInternalAddress();
95
+ }
96
+ /**
97
+ * Gets the recommended Address object for the signer.
98
+ *
99
+ * @param _preference - Optional preference parameter.
100
+ * @returns A promise that resolves to the recommended Address object.
101
+ */
102
+ async getRecommendedAddressObj(_preference) {
103
+ return (await this.getAddressObjs())[0];
104
+ }
105
+ /**
106
+ * Gets the recommended address for the signer as a string.
107
+ *
108
+ * @param preference - Optional preference parameter.
109
+ * @returns A promise that resolves to the recommended address as a string.
110
+ */
111
+ async getRecommendedAddress(preference) {
112
+ return (await this.getRecommendedAddressObj(preference)).toString();
113
+ }
114
+ /**
115
+ * Gets an array of addresses associated with the signer as strings.
116
+ *
117
+ * @returns A promise that resolves to an array of addresses as strings.
118
+ */
119
+ async getAddresses() {
120
+ return this.getAddressObjs().then((addresses) =>
121
+ addresses.map((address) => address.toString()),
122
+ );
123
+ }
124
+ /**
125
+ * Gets balance of all addresses
126
+ *
127
+ * @returns A promise that resolves to the balance
128
+ */
129
+ async getBalance() {
130
+ return this.client.getBalance(
131
+ (await this.getAddressObjs()).map(({ script }) => script),
132
+ );
133
+ }
134
+ /**
135
+ * Signs a message.
136
+ *
137
+ * @param _ - The message to sign, as a string or BytesLike object.
138
+ * @returns A promise that resolves to the signature info.
139
+ * @throws Will throw an error if not implemented.
140
+ */
141
+ async signMessage(message) {
142
+ return {
143
+ signature: await this.signMessageRaw(message),
144
+ identity: await this.getIdentity(),
145
+ signType: this.signType,
146
+ };
147
+ }
148
+ /**
149
+ * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
150
+ *
151
+ * @param _ - The message to sign, as a string or BytesLike object.
152
+ * @returns A promise that resolves to the signature as a string.
153
+ * @throws Will throw an error if not implemented.
154
+ */
155
+ signMessageRaw(_) {
156
+ throw Error("Signer.signMessageRaw not implemented");
157
+ }
158
+ /**
159
+ * Verify a signature.
160
+ *
161
+ * @param _ - The original message.
162
+ * @param _ - The signature to verify.
163
+ * @returns A promise that resolves to the verification result.
164
+ * @throws Will throw an error if not implemented.
165
+ */
166
+ async verifyMessage(message, signature) {
167
+ if (typeof signature === "string") {
168
+ return this.verifyMessageRaw(message, signature);
169
+ }
170
+ if (
171
+ signature.identity !== (await this.getIdentity()) ||
172
+ ![SignerSignType.Unknown, this.signType].includes(signature.signType)
173
+ ) {
174
+ return false;
175
+ }
176
+ return this.verifyMessageRaw(message, signature.signature);
177
+ }
178
+ /**
179
+ * Verify a string signature. This method is not implemented and should be overridden by subclasses.
180
+ *
181
+ * @param _0 - The original message.
182
+ * @param _1 - The signature to verify.
183
+ * @returns A promise that resolves to the verification result.
184
+ * @throws Will throw an error if not implemented.
185
+ */
186
+ verifyMessageRaw(_0, _1) {
187
+ throw Error("Signer.verifyMessageRaw not implemented");
188
+ }
189
+ /**
190
+ * Sends a transaction after signing it.
191
+ *
192
+ * @param tx - The transaction to send, represented as a TransactionLike object.
193
+ * @returns A promise that resolves to the transaction hash as a Hex string.
194
+ */
195
+ async sendTransaction(tx) {
196
+ return this.client.sendTransaction(await this.signTransaction(tx));
197
+ }
198
+ /**
199
+ * Signs a transaction.
200
+ *
201
+ * @param tx - The transaction to sign, represented as a TransactionLike object.
202
+ * @returns A promise that resolves to the signed Transaction object.
203
+ */
204
+ async signTransaction(tx) {
205
+ const preparedTx = await this.prepareTransaction(tx);
206
+ return this.signOnlyTransaction(preparedTx);
207
+ }
208
+ /**
209
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
210
+ *
211
+ * @param _ - The transaction to prepare, represented as a TransactionLike object.
212
+ * @returns A promise that resolves to the prepared Transaction object.
213
+ * @throws Will throw an error if not implemented.
214
+ */
215
+ prepareTransaction(_) {
216
+ throw Error("Signer.prepareTransaction not implemented");
217
+ }
218
+ /**
219
+ * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
220
+ *
221
+ * @param _ - The transaction to sign, represented as a TransactionLike object.
222
+ * @returns A promise that resolves to the signed Transaction object.
223
+ * @throws Will throw an error if not implemented.
224
+ */
225
+ signOnlyTransaction(_) {
226
+ throw Error("Signer.signOnlyTransaction not implemented");
227
+ }
194
228
  }
195
229
  exports.Signer = Signer;
196
230
  /**
197
231
  * A class representing information about a signer, including its type and the signer instance.
198
232
  */
199
233
  class SignerInfo {
200
- constructor(name, signer) {
201
- this.name = name;
202
- this.signer = signer;
203
- }
234
+ constructor(name, signer) {
235
+ this.name = name;
236
+ this.signer = signer;
237
+ }
204
238
  }
205
239
  exports.SignerInfo = SignerInfo;
@@ -1,8 +1,97 @@
1
- export declare function apply<T, R>(transformer: (val: T) => R, value: undefined): undefined;
2
- export declare function apply<T, R>(transformer: (val: T) => R, value: null): null;
1
+ /**
2
+ * A type safe way to apply a transformer on a value if it's not empty.
3
+ *
4
+ * @param transformer - The transformer.
5
+ * @param value - The value to be transformed.
6
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
7
+ */
8
+ export declare function apply<T, R>(
9
+ transformer: (val: T) => R,
10
+ value: undefined,
11
+ ): undefined;
12
+ /**
13
+ * A type safe way to apply a transformer on a value if it's not empty.
14
+ *
15
+ * @param transformer - The transformer.
16
+ * @param value - The value to be transformed.
17
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
18
+ */
19
+ export declare function apply<T, R>(
20
+ transformer: (val: T) => R,
21
+ value: null,
22
+ ): null;
23
+ /**
24
+ * A type safe way to apply a transformer on a value if it's not empty.
25
+ *
26
+ * @param transformer - The transformer.
27
+ * @param value - The value to be transformed.
28
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
29
+ */
3
30
  export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
4
- export declare function apply<T, R>(transformer: (val: T) => R, value: T | undefined): R | undefined;
5
- export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R | null;
6
- export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined | null;
31
+ /**
32
+ * A type safe way to apply a transformer on a value if it's not empty.
33
+ *
34
+ * @param transformer - The transformer.
35
+ * @param value - The value to be transformed.
36
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
37
+ */
38
+ export declare function apply<T, R>(
39
+ transformer: (val: T) => R,
40
+ value: T | undefined,
41
+ ): R | undefined;
42
+ /**
43
+ * A type safe way to apply a transformer on a value if it's not empty.
44
+ *
45
+ * @param transformer - The transformer.
46
+ * @param value - The value to be transformed.
47
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
48
+ */
49
+ export declare function apply<T, R>(
50
+ transformer: (val: T) => R,
51
+ value: T | null,
52
+ ): R | null;
53
+ /**
54
+ * A type safe way to apply a transformer on a value if it's not empty.
55
+ *
56
+ * @param transformer - The transformer.
57
+ * @param value - The value to be transformed.
58
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
59
+ */
60
+ export declare function apply<T, R>(
61
+ transformer: (val: T) => R,
62
+ value: undefined | null,
63
+ ): undefined | null;
64
+ /**
65
+ * Similar to Array.reduce, but the accumulator can returns Promise.
66
+ *
67
+ * @param values - The array to be reduced.
68
+ * @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
69
+ * @returns The accumulated result.
70
+ */
71
+ export declare function reduceAsync<T, V>(
72
+ values: T[],
73
+ accumulator: (
74
+ a: T,
75
+ b: T,
76
+ ) => Promise<T | undefined | null | void> | T | undefined | null | void,
77
+ ): Promise<T>;
78
+ /**
79
+ * Similar to Array.reduce, but the accumulator can returns Promise.
80
+ *
81
+ * @param values - The array to be reduced.
82
+ * @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
83
+ * @param init - The initial value.
84
+ * @returns The accumulated result.
85
+ */
86
+ export declare function reduceAsync<T, V>(
87
+ values: V[],
88
+ accumulator: (
89
+ a: T,
90
+ b: V,
91
+ i: number,
92
+ values: V[],
93
+ ) => Promise<T | undefined | null | void> | T | undefined | null | void,
94
+ init: T,
95
+ ): Promise<T>;
7
96
  export declare function isWebview(userAgent: string): boolean;
8
- //# sourceMappingURL=index.d.ts.map
97
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,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AM,EAAE,CAAC,EAAE,KACR,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,EACvE,IAAI,EAAE,CAAC,GACN,OAAO,CAAC,CAAC,CAAC,CAAC;AA4Bd,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpD"}
@@ -1,14 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isWebview = exports.apply = void 0;
3
+ exports.isWebview = exports.reduceAsync = exports.apply = void 0;
4
+ /**
5
+ * A type safe way to apply a transformer on a value if it's not empty.
6
+ *
7
+ * @param transformer - The transformer.
8
+ * @param value - The value to be transformed.
9
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
10
+ */
4
11
  function apply(transformer, value) {
5
- if (value == null) {
6
- return value;
7
- }
8
- return transformer(value);
12
+ if (value == null) {
13
+ return value;
14
+ }
15
+ return transformer(value);
9
16
  }
10
17
  exports.apply = apply;
18
+ async function reduceAsync(values, accumulator, init) {
19
+ if (init === undefined) {
20
+ if (values.length === 0) {
21
+ throw new TypeError("Reduce of empty array with no initial value");
22
+ }
23
+ init = values[0];
24
+ values = values.slice(1);
25
+ }
26
+ return values.reduce(
27
+ (current, b, i, array) =>
28
+ current.then((v) =>
29
+ Promise.resolve(accumulator(v, b, i, array)).then((r) => r ?? v),
30
+ ),
31
+ Promise.resolve(init),
32
+ );
33
+ }
34
+ exports.reduceAsync = reduceAsync;
11
35
  function isWebview(userAgent) {
12
- return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
36
+ return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
13
37
  }
14
38
  exports.isWebview = isWebview;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.5-alpha.8",
3
+ "version": "0.0.7-alpha.0",
4
4
  "description": "Common Chains Connector Core",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -58,14 +58,15 @@
58
58
  "dependencies": {
59
59
  "@ckb-lumos/helpers": "^0.22.2",
60
60
  "@joyid/ckb": "^0.0.11",
61
+ "@noble/curves": "^1.4.2",
61
62
  "@noble/hashes": "^1.4.0",
62
- "@unisat/wallet-utils": "^1.0.0",
63
63
  "abort-controller": "^3.0.0",
64
64
  "bech32": "^2.0.0",
65
+ "bitcoinjs-message": "^2.2.0",
65
66
  "blake2b": "^2.1.4",
66
67
  "buffer": "^6.0.3",
67
68
  "cross-fetch": "^4.0.0",
68
69
  "ethers": "^6.13.1"
69
70
  },
70
- "gitHead": "f12b8758d8581bfae0c9a00abbb5f7d2c6d03147"
71
+ "gitHead": "99d88c6179e7af6f592b1b39f8df6f6968cc0df3"
71
72
  }
@@ -1,5 +1,5 @@
1
1
  import { bech32, bech32m } from "bech32";
2
- import { hashTypeFromBytes } from "../ckb";
2
+ import { Script, hashTypeFromBytes } from "../ckb";
3
3
  import { Client, KnownScript } from "../client";
4
4
  import { hexFrom } from "../hex";
5
5
  import { type AddressLike } from "./index";
@@ -148,10 +148,7 @@ export async function addressFromPayload(
148
148
  }
149
149
 
150
150
  return {
151
- script: {
152
- ...(await client.getKnownScript(script)),
153
- args: payload.slice(1),
154
- },
151
+ script: await Script.fromKnownScript(client, script, payload.slice(1)),
155
152
  prefix,
156
153
  };
157
154
  }
@@ -91,15 +91,12 @@ export class Address {
91
91
  }
92
92
 
93
93
  static async fromKnownScript(
94
+ client: Client,
94
95
  script: KnownScript,
95
96
  args: HexLike,
96
- client: Client,
97
97
  ) {
98
98
  return Address.from({
99
- script: {
100
- ...(await client.getKnownScript(script)),
101
- args,
102
- },
99
+ script: await Script.fromKnownScript(client, script, args),
103
100
  prefix: client.addressPrefix,
104
101
  });
105
102
  }