@ckb-ccc/core 0.0.10-alpha.0 → 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 (173) 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/clientPublicTestnet.advanced.js +3 -3
  9. package/dist/client/clientTypes.advanced.d.ts +8 -8
  10. package/dist/client/clientTypes.advanced.d.ts.map +1 -1
  11. package/dist/client/clientTypes.d.ts +2 -2
  12. package/dist/client/clientTypes.d.ts.map +1 -1
  13. package/dist/client/clientTypes.js +2 -2
  14. package/dist/signer/ckb/index.d.ts +2 -0
  15. package/dist/signer/ckb/index.d.ts.map +1 -1
  16. package/dist/signer/ckb/index.js +2 -0
  17. package/dist/signer/ckb/signerCkbPrivateKey.d.ts +4 -13
  18. package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  19. package/dist/signer/ckb/signerCkbPrivateKey.js +10 -37
  20. package/dist/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  21. package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  22. package/dist/signer/ckb/signerCkbPublicKey.js +44 -0
  23. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts +5 -0
  24. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  25. package/dist/signer/ckb/verifyCkbSecp256k1.js +14 -0
  26. package/dist/signer/signer/index.d.ts.map +1 -1
  27. package/dist/signer/signer/index.js +2 -0
  28. package/dist/utils/index.d.ts +18 -9
  29. package/dist/utils/index.d.ts.map +1 -1
  30. package/dist/utils/index.js +2 -2
  31. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  32. package/dist.commonjs/address/address.advanced.js +115 -89
  33. package/dist.commonjs/address/advanced.d.ts +1 -1
  34. package/dist.commonjs/address/advanced.js +30 -14
  35. package/dist.commonjs/address/index.d.ts +51 -44
  36. package/dist.commonjs/address/index.js +84 -65
  37. package/dist.commonjs/advanced.d.ts +1 -1
  38. package/dist.commonjs/advanced.js +47 -22
  39. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  40. package/dist.commonjs/advancedBarrel.js +30 -14
  41. package/dist.commonjs/barrel.d.ts +1 -1
  42. package/dist.commonjs/barrel.js +30 -14
  43. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  44. package/dist.commonjs/bytes/index.d.ts +9 -3
  45. package/dist.commonjs/bytes/index.js +28 -26
  46. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  47. package/dist.commonjs/ckb/advanced.js +47 -22
  48. package/dist.commonjs/ckb/index.d.ts +1 -1
  49. package/dist.commonjs/ckb/index.js +30 -14
  50. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  51. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  52. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  53. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  54. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  55. package/dist.commonjs/ckb/script.advanced.js +12 -9
  56. package/dist.commonjs/ckb/script.d.ts +121 -117
  57. package/dist.commonjs/ckb/script.js +220 -176
  58. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  59. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  60. package/dist.commonjs/ckb/transaction.d.ts +806 -718
  61. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  62. package/dist.commonjs/ckb/transaction.js +1425 -1158
  63. package/dist.commonjs/client/advanced.d.ts +1 -1
  64. package/dist.commonjs/client/advanced.js +30 -14
  65. package/dist.commonjs/client/client.advanced.d.ts +23 -6
  66. package/dist.commonjs/client/client.advanced.js +89 -61
  67. package/dist.commonjs/client/client.d.ts +114 -54
  68. package/dist.commonjs/client/client.d.ts.map +1 -1
  69. package/dist.commonjs/client/client.js +215 -182
  70. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
  71. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  72. package/dist.commonjs/client/clientPublicMainnet.advanced.js +215 -161
  73. package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
  74. package/dist.commonjs/client/clientPublicMainnet.js +17 -15
  75. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
  76. package/dist.commonjs/client/clientPublicTestnet.advanced.js +227 -199
  77. package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
  78. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  79. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  80. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
  81. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  82. package/dist.commonjs/client/clientTypes.d.ts +52 -27
  83. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  84. package/dist.commonjs/client/clientTypes.js +56 -22
  85. package/dist.commonjs/client/index.d.ts +1 -1
  86. package/dist.commonjs/client/index.js +30 -14
  87. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  88. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  89. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  90. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  91. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
  92. package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
  93. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  94. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  95. package/dist.commonjs/fixedPoint/index.js +26 -20
  96. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  97. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  98. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  99. package/dist.commonjs/hasher/index.d.ts +40 -37
  100. package/dist.commonjs/hasher/index.js +58 -48
  101. package/dist.commonjs/hex/index.d.ts +1 -1
  102. package/dist.commonjs/hex/index.js +1 -1
  103. package/dist.commonjs/index.d.ts +1 -1
  104. package/dist.commonjs/index.js +47 -22
  105. package/dist.commonjs/num/index.d.ts +1 -1
  106. package/dist.commonjs/num/index.js +39 -27
  107. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  108. package/dist.commonjs/signer/btc/index.js +30 -14
  109. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  110. package/dist.commonjs/signer/btc/signerBtc.js +89 -66
  111. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  112. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  113. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  114. package/dist.commonjs/signer/btc/verify.js +10 -3
  115. package/dist.commonjs/signer/ckb/index.d.ts +3 -1
  116. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
  117. package/dist.commonjs/signer/ckb/index.js +32 -14
  118. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +8 -17
  119. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  120. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +45 -58
  121. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  122. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  123. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +58 -0
  124. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  125. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  126. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +11 -0
  127. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  128. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +27 -0
  129. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  130. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  131. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  132. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  133. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  134. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  135. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  136. package/dist.commonjs/signer/dummy/index.js +30 -14
  137. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  138. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  139. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  140. package/dist.commonjs/signer/evm/index.js +30 -14
  141. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  142. package/dist.commonjs/signer/evm/signerEvm.js +105 -70
  143. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  144. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  145. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  146. package/dist.commonjs/signer/evm/verify.js +7 -2
  147. package/dist.commonjs/signer/index.d.ts +1 -1
  148. package/dist.commonjs/signer/index.js +30 -14
  149. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  150. package/dist.commonjs/signer/nostr/index.js +30 -14
  151. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  152. package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
  153. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  154. package/dist.commonjs/signer/nostr/verify.js +50 -39
  155. package/dist.commonjs/signer/signer/index.d.ts +171 -162
  156. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  157. package/dist.commonjs/signer/signer/index.js +235 -197
  158. package/dist.commonjs/utils/index.d.ts +56 -14
  159. package/dist.commonjs/utils/index.d.ts.map +1 -1
  160. package/dist.commonjs/utils/index.js +19 -13
  161. package/package.json +2 -2
  162. package/src/ckb/transaction.ts +87 -33
  163. package/src/client/client.ts +1 -1
  164. package/src/client/clientPublicMainnet.advanced.ts +34 -2
  165. package/src/client/clientPublicTestnet.advanced.ts +3 -3
  166. package/src/client/clientTypes.advanced.ts +8 -8
  167. package/src/client/clientTypes.ts +4 -4
  168. package/src/signer/ckb/index.ts +2 -0
  169. package/src/signer/ckb/signerCkbPrivateKey.ts +14 -54
  170. package/src/signer/ckb/signerCkbPublicKey.ts +63 -0
  171. package/src/signer/ckb/verifyCkbSecp256k1.ts +27 -0
  172. package/src/signer/signer/index.ts +6 -0
  173. package/src/utils/index.ts +24 -12
@@ -1,35 +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";
15
- SignerSignType["CkbSecp256k1"] = "CkbSecp256k1";
16
+ SignerSignType["Unknown"] = "Unknown";
17
+ SignerSignType["BtcEcdsa"] = "BtcEcdsa";
18
+ SignerSignType["EvmPersonal"] = "EvmPersonal";
19
+ SignerSignType["JoyId"] = "JoyId";
20
+ SignerSignType["NostrEvent"] = "NostrEvent";
21
+ SignerSignType["CkbSecp256k1"] = "CkbSecp256k1";
16
22
  })(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
17
23
  /**
18
24
  * An enumeration of signer display types in wallet.
19
25
  */
20
26
  var SignerType;
21
27
  (function (SignerType) {
22
- SignerType["EVM"] = "EVM";
23
- SignerType["BTC"] = "BTC";
24
- SignerType["CKB"] = "CKB";
25
- SignerType["Nostr"] = "Nostr";
28
+ SignerType["EVM"] = "EVM";
29
+ SignerType["BTC"] = "BTC";
30
+ SignerType["CKB"] = "CKB";
31
+ SignerType["Nostr"] = "Nostr";
26
32
  })(SignerType || (exports.SignerType = SignerType = {}));
27
33
  class Signature {
28
- constructor(signature, identity, signType) {
29
- this.signature = signature;
30
- this.identity = identity;
31
- this.signType = signType;
32
- }
34
+ constructor(signature, identity, signType) {
35
+ this.signature = signature;
36
+ this.identity = identity;
37
+ this.signType = signType;
38
+ }
33
39
  }
34
40
  exports.Signature = Signature;
35
41
  /**
@@ -37,196 +43,228 @@ exports.Signature = Signature;
37
43
  * This class provides methods to connect, get addresses, and sign transactions.
38
44
  */
39
45
  class Signer {
40
- constructor(client_) {
41
- this.client_ = client_;
42
- }
43
- get client() {
44
- return this.client_;
45
- }
46
- // Returns the preference if we need to switch network
47
- // undefined otherwise
48
- matchNetworkPreference(preferences, currentNetwork) {
49
- if (preferences.some(({ signerType, addressPrefix, network }) => {
50
- signerType === this.type &&
51
- addressPrefix === this.client.addressPrefix &&
52
- network === currentNetwork;
53
- })) {
54
- return;
55
- }
56
- return preferences.find(({ signerType, addressPrefix }) => signerType === this.type && addressPrefix === this.client.addressPrefix);
57
- }
58
- static async verifyMessage(message, signature) {
59
- switch (signature.signType) {
60
- case SignerSignType.EvmPersonal:
61
- return (0, verify_1.verifyMessageEvmPersonal)(message, signature.signature, signature.identity);
62
- case SignerSignType.BtcEcdsa:
63
- return (0, btc_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
64
- case SignerSignType.JoyId:
65
- return (0, verifyJoyId_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
66
- case SignerSignType.NostrEvent:
67
- return (0, verify_2.verifyMessageNostrEvent)(message, signature.signature, signature.identity);
68
- case SignerSignType.CkbSecp256k1:
69
- case SignerSignType.Unknown:
70
- throw new Error("Unknown signer sign type");
71
- }
72
- }
73
- /**
74
- * Register a listener to be called when this signer is replaced.
75
- *
76
- * @returns A function for unregister
77
- */
78
- onReplaced(_) {
79
- return () => { };
80
- }
81
- /**
82
- * Disconnects to the signer.
83
- *
84
- * @returns A promise that resolves when the signer is disconnected.
85
- */
86
- async disconnect() { }
87
- /**
88
- * Gets the identity for verifying signature, usually it's address
89
- *
90
- * @returns A promise that resolves to a string representing the identity
91
- */
92
- async getIdentity() {
93
- return this.getInternalAddress();
94
- }
95
- /**
96
- * Gets the recommended Address object for the signer.
97
- *
98
- * @param _preference - Optional preference parameter.
99
- * @returns A promise that resolves to the recommended Address object.
100
- */
101
- async getRecommendedAddressObj(_preference) {
102
- return (await this.getAddressObjs())[0];
103
- }
104
- /**
105
- * Gets the recommended address for the signer as a string.
106
- *
107
- * @param preference - Optional preference parameter.
108
- * @returns A promise that resolves to the recommended address as a string.
109
- */
110
- async getRecommendedAddress(preference) {
111
- 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;
112
63
  }
113
- /**
114
- * Gets an array of addresses associated with the signer as strings.
115
- *
116
- * @returns A promise that resolves to an array of addresses as strings.
117
- */
118
- async getAddresses() {
119
- 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");
120
103
  }
121
- /**
122
- * Gets balance of all addresses
123
- *
124
- * @returns A promise that resolves to the balance
125
- */
126
- async getBalance() {
127
- 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);
128
200
  }
129
- /**
130
- * Signs a message.
131
- *
132
- * @param _ - The message to sign, as a string or BytesLike object.
133
- * @returns A promise that resolves to the signature info.
134
- * @throws Will throw an error if not implemented.
135
- */
136
- async signMessage(message) {
137
- return {
138
- signature: await this.signMessageRaw(message),
139
- identity: await this.getIdentity(),
140
- signType: this.signType,
141
- };
142
- }
143
- /**
144
- * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
145
- *
146
- * @param _ - The message to sign, as a string or BytesLike object.
147
- * @returns A promise that resolves to the signature as a string.
148
- * @throws Will throw an error if not implemented.
149
- */
150
- signMessageRaw(_) {
151
- throw Error("Signer.signMessageRaw not implemented");
152
- }
153
- /**
154
- * Verify a signature.
155
- *
156
- * @param _ - The original message.
157
- * @param _ - The signature to verify.
158
- * @returns A promise that resolves to the verification result.
159
- * @throws Will throw an error if not implemented.
160
- */
161
- async verifyMessage(message, signature) {
162
- if (typeof signature === "string") {
163
- return this.verifyMessageRaw(message, signature);
164
- }
165
- if (signature.identity !== (await this.getIdentity()) ||
166
- ![SignerSignType.Unknown, this.signType].includes(signature.signType)) {
167
- return false;
168
- }
169
- return this.verifyMessageRaw(message, signature.signature);
170
- }
171
- /**
172
- * Verify a string signature. This method is not implemented and should be overridden by subclasses.
173
- *
174
- * @param _0 - The original message.
175
- * @param _1 - The signature to verify.
176
- * @returns A promise that resolves to the verification result.
177
- * @throws Will throw an error if not implemented.
178
- */
179
- verifyMessageRaw(_0, _1) {
180
- throw Error("Signer.verifyMessageRaw not implemented");
181
- }
182
- /**
183
- * Sends a transaction after signing it.
184
- *
185
- * @param tx - The transaction to send, represented as a TransactionLike object.
186
- * @returns A promise that resolves to the transaction hash as a Hex string.
187
- */
188
- async sendTransaction(tx) {
189
- return this.client.sendTransaction(await this.signTransaction(tx));
190
- }
191
- /**
192
- * Signs a transaction.
193
- *
194
- * @param tx - The transaction to sign, represented as a TransactionLike object.
195
- * @returns A promise that resolves to the signed Transaction object.
196
- */
197
- async signTransaction(tx) {
198
- const preparedTx = await this.prepareTransaction(tx);
199
- return this.signOnlyTransaction(preparedTx);
200
- }
201
- /**
202
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
203
- *
204
- * @param _ - The transaction to prepare, represented as a TransactionLike object.
205
- * @returns A promise that resolves to the prepared Transaction object.
206
- * @throws Will throw an error if not implemented.
207
- */
208
- prepareTransaction(_) {
209
- throw Error("Signer.prepareTransaction not implemented");
210
- }
211
- /**
212
- * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
213
- *
214
- * @param _ - The transaction to sign, represented as a TransactionLike object.
215
- * @returns A promise that resolves to the signed Transaction object.
216
- * @throws Will throw an error if not implemented.
217
- */
218
- signOnlyTransaction(_) {
219
- 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;
220
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
+ }
221
259
  }
222
260
  exports.Signer = Signer;
223
261
  /**
224
262
  * A class representing information about a signer, including its type and the signer instance.
225
263
  */
226
264
  class SignerInfo {
227
- constructor(name, signer) {
228
- this.name = name;
229
- this.signer = signer;
230
- }
265
+ constructor(name, signer) {
266
+ this.name = name;
267
+ this.signer = signer;
268
+ }
231
269
  }
232
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,CAA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A4Bd,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.10-alpha.0",
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": "8a4c789419f5e12e1f230cead213c59373834a1a"
71
+ "gitHead": "61228337bbf4bdc0bc082e3c9530f843c2182106"
72
72
  }