@ckb-ccc/core 0.0.10-alpha.4 → 0.0.10-alpha.6

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