@ckb-ccc/core 0.0.9-alpha.1 → 0.0.10-alpha.4

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