@ckb-ccc/core 0.0.7-alpha.0 → 0.0.7-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/ckb/transaction.d.ts.map +1 -1
  2. package/dist/ckb/transaction.js +6 -3
  3. package/dist.commonjs/address/address.advanced.d.ts +24 -29
  4. package/dist.commonjs/address/address.advanced.js +89 -115
  5. package/dist.commonjs/address/advanced.d.ts +1 -1
  6. package/dist.commonjs/address/advanced.js +14 -30
  7. package/dist.commonjs/address/index.d.ts +44 -51
  8. package/dist.commonjs/address/index.js +65 -84
  9. package/dist.commonjs/advanced.d.ts +1 -1
  10. package/dist.commonjs/advanced.js +22 -47
  11. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  12. package/dist.commonjs/advancedBarrel.js +14 -30
  13. package/dist.commonjs/barrel.d.ts +1 -1
  14. package/dist.commonjs/barrel.js +14 -30
  15. package/dist.commonjs/bytes/advanced.d.ts +2 -11
  16. package/dist.commonjs/bytes/index.d.ts +3 -9
  17. package/dist.commonjs/bytes/index.js +26 -28
  18. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  19. package/dist.commonjs/ckb/advanced.js +22 -47
  20. package/dist.commonjs/ckb/index.d.ts +1 -1
  21. package/dist.commonjs/ckb/index.js +14 -30
  22. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
  23. package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
  24. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  25. package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
  26. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  27. package/dist.commonjs/ckb/script.advanced.js +9 -12
  28. package/dist.commonjs/ckb/script.d.ts +117 -121
  29. package/dist.commonjs/ckb/script.js +176 -220
  30. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  31. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  32. package/dist.commonjs/ckb/transaction.d.ts +717 -792
  33. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  34. package/dist.commonjs/ckb/transaction.js +1156 -1382
  35. package/dist.commonjs/client/advanced.d.ts +1 -1
  36. package/dist.commonjs/client/advanced.js +14 -30
  37. package/dist.commonjs/client/client.advanced.d.ts +6 -23
  38. package/dist.commonjs/client/client.advanced.js +61 -89
  39. package/dist.commonjs/client/client.d.ts +53 -113
  40. package/dist.commonjs/client/client.js +181 -214
  41. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
  42. package/dist.commonjs/client/clientPublicMainnet.advanced.js +127 -144
  43. package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
  44. package/dist.commonjs/client/clientPublicMainnet.js +15 -17
  45. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
  46. package/dist.commonjs/client/clientPublicTestnet.advanced.js +179 -204
  47. package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
  48. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  49. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  50. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  51. package/dist.commonjs/client/clientTypes.d.ts +26 -51
  52. package/dist.commonjs/client/clientTypes.js +22 -56
  53. package/dist.commonjs/client/index.d.ts +1 -1
  54. package/dist.commonjs/client/index.js +14 -30
  55. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  56. package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
  57. package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
  58. package/dist.commonjs/client/jsonRpc/index.js +108 -135
  59. package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
  60. package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
  61. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  62. package/dist.commonjs/fixedPoint/index.d.ts +3 -9
  63. package/dist.commonjs/fixedPoint/index.js +20 -26
  64. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  65. package/dist.commonjs/fixedPoint/index.test.js +36 -42
  66. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  67. package/dist.commonjs/hasher/index.d.ts +36 -36
  68. package/dist.commonjs/hasher/index.js +47 -54
  69. package/dist.commonjs/hex/index.d.ts +1 -1
  70. package/dist.commonjs/hex/index.js +1 -1
  71. package/dist.commonjs/index.d.ts +1 -1
  72. package/dist.commonjs/index.js +22 -47
  73. package/dist.commonjs/num/index.d.ts +1 -1
  74. package/dist.commonjs/num/index.js +27 -39
  75. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  76. package/dist.commonjs/signer/btc/index.js +14 -30
  77. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  78. package/dist.commonjs/signer/btc/signerBtc.js +66 -89
  79. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  80. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  81. package/dist.commonjs/signer/btc/verify.d.ts +2 -6
  82. package/dist.commonjs/signer/btc/verify.js +3 -10
  83. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  84. package/dist.commonjs/signer/ckb/index.js +14 -30
  85. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  86. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  87. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
  88. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
  89. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  90. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  91. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  92. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  93. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  94. package/dist.commonjs/signer/dummy/index.js +14 -30
  95. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  96. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  97. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  98. package/dist.commonjs/signer/evm/index.js +14 -30
  99. package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
  100. package/dist.commonjs/signer/evm/signerEvm.js +70 -105
  101. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  102. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  103. package/dist.commonjs/signer/evm/verify.d.ts +2 -6
  104. package/dist.commonjs/signer/evm/verify.js +2 -7
  105. package/dist.commonjs/signer/index.d.ts +1 -1
  106. package/dist.commonjs/signer/index.js +14 -30
  107. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  108. package/dist.commonjs/signer/nostr/index.js +14 -30
  109. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  110. package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
  111. package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
  112. package/dist.commonjs/signer/nostr/verify.js +39 -50
  113. package/dist.commonjs/signer/signer/index.d.ts +150 -156
  114. package/dist.commonjs/signer/signer/index.js +181 -208
  115. package/dist.commonjs/utils/index.d.ts +8 -38
  116. package/dist.commonjs/utils/index.js +12 -18
  117. package/package.json +2 -2
  118. package/src/ckb/transaction.ts +9 -5
@@ -1,39 +1,34 @@
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 verifyJoyId_1 = require("../ckb/verifyJoyId");
11
6
  const verify_1 = require("../evm/verify");
12
7
  const verify_2 = require("../nostr/verify");
13
8
  var SignerSignType;
14
9
  (function (SignerSignType) {
15
- SignerSignType["Unknown"] = "Unknown";
16
- SignerSignType["BtcEcdsa"] = "BtcEcdsa";
17
- SignerSignType["EvmPersonal"] = "EvmPersonal";
18
- SignerSignType["JoyId"] = "JoyId";
19
- SignerSignType["NostrEvent"] = "NostrEvent";
10
+ SignerSignType["Unknown"] = "Unknown";
11
+ SignerSignType["BtcEcdsa"] = "BtcEcdsa";
12
+ SignerSignType["EvmPersonal"] = "EvmPersonal";
13
+ SignerSignType["JoyId"] = "JoyId";
14
+ SignerSignType["NostrEvent"] = "NostrEvent";
20
15
  })(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
21
16
  /**
22
17
  * An enumeration of signer display types in wallet.
23
18
  */
24
19
  var SignerType;
25
20
  (function (SignerType) {
26
- SignerType["EVM"] = "EVM";
27
- SignerType["BTC"] = "BTC";
28
- SignerType["CKB"] = "CKB";
29
- SignerType["Nostr"] = "Nostr";
21
+ SignerType["EVM"] = "EVM";
22
+ SignerType["BTC"] = "BTC";
23
+ SignerType["CKB"] = "CKB";
24
+ SignerType["Nostr"] = "Nostr";
30
25
  })(SignerType || (exports.SignerType = SignerType = {}));
31
26
  class Signature {
32
- constructor(signature, identity, signType) {
33
- this.signature = signature;
34
- this.identity = identity;
35
- this.signType = signType;
36
- }
27
+ constructor(signature, identity, signType) {
28
+ this.signature = signature;
29
+ this.identity = identity;
30
+ this.signType = signType;
31
+ }
37
32
  }
38
33
  exports.Signature = Signature;
39
34
  /**
@@ -41,199 +36,177 @@ exports.Signature = Signature;
41
36
  * This class provides methods to connect, get addresses, and sign transactions.
42
37
  */
43
38
  class Signer {
44
- constructor(client_) {
45
- this.client_ = client_;
46
- }
47
- get client() {
48
- return this.client_;
49
- }
50
- static async verifyMessage(message, signature) {
51
- switch (signature.signType) {
52
- case SignerSignType.EvmPersonal:
53
- return (0, verify_1.verifyMessageEvmPersonal)(
54
- message,
55
- signature.signature,
56
- signature.identity,
57
- );
58
- case SignerSignType.BtcEcdsa:
59
- return (0, btc_1.verifyMessageBtcEcdsa)(
60
- message,
61
- signature.signature,
62
- signature.identity,
63
- );
64
- case SignerSignType.JoyId:
65
- return (0, verifyJoyId_1.verifyMessageJoyId)(
66
- message,
67
- signature.signature,
68
- signature.identity,
69
- );
70
- case SignerSignType.NostrEvent:
71
- return (0, verify_2.verifyMessageNostrEvent)(
72
- message,
73
- signature.signature,
74
- signature.identity,
75
- );
76
- case SignerSignType.Unknown:
77
- throw new Error("Unknown signer sign type");
78
- }
79
- }
80
- /**
81
- * Replace the current client.
82
- * returns false if the new client is invalid for this signer.
83
- */
84
- async replaceClient(client) {
85
- this.client_ = client;
86
- return true;
87
- }
88
- /**
89
- * Gets the identity for verifying signature, usually it's address
90
- *
91
- * @returns A promise that resolves to a string representing the identity
92
- */
93
- async getIdentity() {
94
- return this.getInternalAddress();
95
- }
96
- /**
97
- * Gets the recommended Address object for the signer.
98
- *
99
- * @param _preference - Optional preference parameter.
100
- * @returns A promise that resolves to the recommended Address object.
101
- */
102
- async getRecommendedAddressObj(_preference) {
103
- return (await this.getAddressObjs())[0];
104
- }
105
- /**
106
- * Gets the recommended address for the signer as a string.
107
- *
108
- * @param preference - Optional preference parameter.
109
- * @returns A promise that resolves to the recommended address as a string.
110
- */
111
- async getRecommendedAddress(preference) {
112
- return (await this.getRecommendedAddressObj(preference)).toString();
113
- }
114
- /**
115
- * Gets an array of addresses associated with the signer as strings.
116
- *
117
- * @returns A promise that resolves to an array of addresses as strings.
118
- */
119
- async getAddresses() {
120
- return this.getAddressObjs().then((addresses) =>
121
- addresses.map((address) => address.toString()),
122
- );
123
- }
124
- /**
125
- * Gets balance of all addresses
126
- *
127
- * @returns A promise that resolves to the balance
128
- */
129
- async getBalance() {
130
- return this.client.getBalance(
131
- (await this.getAddressObjs()).map(({ script }) => script),
132
- );
133
- }
134
- /**
135
- * Signs a message.
136
- *
137
- * @param _ - The message to sign, as a string or BytesLike object.
138
- * @returns A promise that resolves to the signature info.
139
- * @throws Will throw an error if not implemented.
140
- */
141
- async signMessage(message) {
142
- return {
143
- signature: await this.signMessageRaw(message),
144
- identity: await this.getIdentity(),
145
- signType: this.signType,
146
- };
147
- }
148
- /**
149
- * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
150
- *
151
- * @param _ - The message to sign, as a string or BytesLike object.
152
- * @returns A promise that resolves to the signature as a string.
153
- * @throws Will throw an error if not implemented.
154
- */
155
- signMessageRaw(_) {
156
- throw Error("Signer.signMessageRaw not implemented");
157
- }
158
- /**
159
- * Verify a signature.
160
- *
161
- * @param _ - The original message.
162
- * @param _ - The signature to verify.
163
- * @returns A promise that resolves to the verification result.
164
- * @throws Will throw an error if not implemented.
165
- */
166
- async verifyMessage(message, signature) {
167
- if (typeof signature === "string") {
168
- return this.verifyMessageRaw(message, signature);
169
- }
170
- if (
171
- signature.identity !== (await this.getIdentity()) ||
172
- ![SignerSignType.Unknown, this.signType].includes(signature.signType)
173
- ) {
174
- return false;
175
- }
176
- return this.verifyMessageRaw(message, signature.signature);
177
- }
178
- /**
179
- * Verify a string signature. This method is not implemented and should be overridden by subclasses.
180
- *
181
- * @param _0 - The original message.
182
- * @param _1 - The signature to verify.
183
- * @returns A promise that resolves to the verification result.
184
- * @throws Will throw an error if not implemented.
185
- */
186
- verifyMessageRaw(_0, _1) {
187
- throw Error("Signer.verifyMessageRaw not implemented");
188
- }
189
- /**
190
- * Sends a transaction after signing it.
191
- *
192
- * @param tx - The transaction to send, represented as a TransactionLike object.
193
- * @returns A promise that resolves to the transaction hash as a Hex string.
194
- */
195
- async sendTransaction(tx) {
196
- return this.client.sendTransaction(await this.signTransaction(tx));
197
- }
198
- /**
199
- * Signs a transaction.
200
- *
201
- * @param tx - The transaction to sign, represented as a TransactionLike object.
202
- * @returns A promise that resolves to the signed Transaction object.
203
- */
204
- async signTransaction(tx) {
205
- const preparedTx = await this.prepareTransaction(tx);
206
- return this.signOnlyTransaction(preparedTx);
207
- }
208
- /**
209
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
210
- *
211
- * @param _ - The transaction to prepare, represented as a TransactionLike object.
212
- * @returns A promise that resolves to the prepared Transaction object.
213
- * @throws Will throw an error if not implemented.
214
- */
215
- prepareTransaction(_) {
216
- throw Error("Signer.prepareTransaction not implemented");
217
- }
218
- /**
219
- * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
220
- *
221
- * @param _ - The transaction to sign, represented as a TransactionLike object.
222
- * @returns A promise that resolves to the signed Transaction object.
223
- * @throws Will throw an error if not implemented.
224
- */
225
- signOnlyTransaction(_) {
226
- throw Error("Signer.signOnlyTransaction not implemented");
227
- }
39
+ constructor(client_) {
40
+ this.client_ = client_;
41
+ }
42
+ get client() {
43
+ return this.client_;
44
+ }
45
+ static async verifyMessage(message, signature) {
46
+ switch (signature.signType) {
47
+ case SignerSignType.EvmPersonal:
48
+ return (0, verify_1.verifyMessageEvmPersonal)(message, signature.signature, signature.identity);
49
+ case SignerSignType.BtcEcdsa:
50
+ return (0, btc_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
51
+ case SignerSignType.JoyId:
52
+ return (0, verifyJoyId_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
53
+ case SignerSignType.NostrEvent:
54
+ return (0, verify_2.verifyMessageNostrEvent)(message, signature.signature, signature.identity);
55
+ case SignerSignType.Unknown:
56
+ throw new Error("Unknown signer sign type");
57
+ }
58
+ }
59
+ /**
60
+ * Replace the current client.
61
+ * returns false if the new client is invalid for this signer.
62
+ */
63
+ async replaceClient(client) {
64
+ this.client_ = client;
65
+ return true;
66
+ }
67
+ /**
68
+ * Gets the identity for verifying signature, usually it's address
69
+ *
70
+ * @returns A promise that resolves to a string representing the identity
71
+ */
72
+ async getIdentity() {
73
+ return this.getInternalAddress();
74
+ }
75
+ /**
76
+ * Gets the recommended Address object for the signer.
77
+ *
78
+ * @param _preference - Optional preference parameter.
79
+ * @returns A promise that resolves to the recommended Address object.
80
+ */
81
+ async getRecommendedAddressObj(_preference) {
82
+ return (await this.getAddressObjs())[0];
83
+ }
84
+ /**
85
+ * Gets the recommended address for the signer as a string.
86
+ *
87
+ * @param preference - Optional preference parameter.
88
+ * @returns A promise that resolves to the recommended address as a string.
89
+ */
90
+ async getRecommendedAddress(preference) {
91
+ return (await this.getRecommendedAddressObj(preference)).toString();
92
+ }
93
+ /**
94
+ * Gets an array of addresses associated with the signer as strings.
95
+ *
96
+ * @returns A promise that resolves to an array of addresses as strings.
97
+ */
98
+ async getAddresses() {
99
+ return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
100
+ }
101
+ /**
102
+ * Gets balance of all addresses
103
+ *
104
+ * @returns A promise that resolves to the balance
105
+ */
106
+ async getBalance() {
107
+ return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
108
+ }
109
+ /**
110
+ * Signs a message.
111
+ *
112
+ * @param _ - The message to sign, as a string or BytesLike object.
113
+ * @returns A promise that resolves to the signature info.
114
+ * @throws Will throw an error if not implemented.
115
+ */
116
+ async signMessage(message) {
117
+ return {
118
+ signature: await this.signMessageRaw(message),
119
+ identity: await this.getIdentity(),
120
+ signType: this.signType,
121
+ };
122
+ }
123
+ /**
124
+ * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
125
+ *
126
+ * @param _ - The message to sign, as a string or BytesLike object.
127
+ * @returns A promise that resolves to the signature as a string.
128
+ * @throws Will throw an error if not implemented.
129
+ */
130
+ signMessageRaw(_) {
131
+ throw Error("Signer.signMessageRaw not implemented");
132
+ }
133
+ /**
134
+ * Verify a signature.
135
+ *
136
+ * @param _ - The original message.
137
+ * @param _ - The signature to verify.
138
+ * @returns A promise that resolves to the verification result.
139
+ * @throws Will throw an error if not implemented.
140
+ */
141
+ async verifyMessage(message, signature) {
142
+ if (typeof signature === "string") {
143
+ return this.verifyMessageRaw(message, signature);
144
+ }
145
+ if (signature.identity !== (await this.getIdentity()) ||
146
+ ![SignerSignType.Unknown, this.signType].includes(signature.signType)) {
147
+ return false;
148
+ }
149
+ return this.verifyMessageRaw(message, signature.signature);
150
+ }
151
+ /**
152
+ * Verify a string signature. This method is not implemented and should be overridden by subclasses.
153
+ *
154
+ * @param _0 - The original message.
155
+ * @param _1 - 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
+ verifyMessageRaw(_0, _1) {
160
+ throw Error("Signer.verifyMessageRaw not implemented");
161
+ }
162
+ /**
163
+ * Sends a transaction after signing it.
164
+ *
165
+ * @param tx - The transaction to send, represented as a TransactionLike object.
166
+ * @returns A promise that resolves to the transaction hash as a Hex string.
167
+ */
168
+ async sendTransaction(tx) {
169
+ return this.client.sendTransaction(await this.signTransaction(tx));
170
+ }
171
+ /**
172
+ * Signs a transaction.
173
+ *
174
+ * @param tx - The transaction to sign, represented as a TransactionLike object.
175
+ * @returns A promise that resolves to the signed Transaction object.
176
+ */
177
+ async signTransaction(tx) {
178
+ const preparedTx = await this.prepareTransaction(tx);
179
+ return this.signOnlyTransaction(preparedTx);
180
+ }
181
+ /**
182
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
183
+ *
184
+ * @param _ - The transaction to prepare, represented as a TransactionLike object.
185
+ * @returns A promise that resolves to the prepared Transaction object.
186
+ * @throws Will throw an error if not implemented.
187
+ */
188
+ prepareTransaction(_) {
189
+ throw Error("Signer.prepareTransaction not implemented");
190
+ }
191
+ /**
192
+ * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
193
+ *
194
+ * @param _ - The transaction to sign, represented as a TransactionLike object.
195
+ * @returns A promise that resolves to the signed Transaction object.
196
+ * @throws Will throw an error if not implemented.
197
+ */
198
+ signOnlyTransaction(_) {
199
+ throw Error("Signer.signOnlyTransaction not implemented");
200
+ }
228
201
  }
229
202
  exports.Signer = Signer;
230
203
  /**
231
204
  * A class representing information about a signer, including its type and the signer instance.
232
205
  */
233
206
  class SignerInfo {
234
- constructor(name, signer) {
235
- this.name = name;
236
- this.signer = signer;
237
- }
207
+ constructor(name, signer) {
208
+ this.name = name;
209
+ this.signer = signer;
210
+ }
238
211
  }
239
212
  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 remains its type. 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 remains its type. Otherwise it will be transformed.
18
15
  */
19
- export declare function apply<T, R>(
20
- transformer: (val: T) => R,
21
- value: null,
22
- ): null;
16
+ export declare function apply<T, R>(transformer: (val: T) => R, value: null): null;
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 remains its type. 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 remains its type. 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 | null;
40
+ export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R | null;
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 remains its type. 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 | null;
48
+ export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined | null;
64
49
  /**
65
50
  * Similar to Array.reduce, but the accumulator can returns Promise.
66
51
  *
@@ -68,13 +53,7 @@ export declare function apply<T, R>(
68
53
  * @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
69
54
  * @returns The accumulated result.
70
55
  */
71
- export declare function reduceAsync<T, V>(
72
- values: T[],
73
- accumulator: (
74
- a: T,
75
- b: T,
76
- ) => Promise<T | undefined | null | void> | T | undefined | null | void,
77
- ): Promise<T>;
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>;
78
57
  /**
79
58
  * Similar to Array.reduce, but the accumulator can returns Promise.
80
59
  *
@@ -83,15 +62,6 @@ export declare function reduceAsync<T, V>(
83
62
  * @param init - The initial value.
84
63
  * @returns The accumulated result.
85
64
  */
86
- export declare function reduceAsync<T, V>(
87
- values: V[],
88
- accumulator: (
89
- a: T,
90
- b: V,
91
- i: number,
92
- values: V[],
93
- ) => Promise<T | undefined | null | void> | T | undefined | null | void,
94
- init: T,
95
- ): Promise<T>;
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>;
96
66
  export declare function isWebview(userAgent: string): boolean;
97
- //# sourceMappingURL=index.d.ts.map
67
+ //# 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 remains its type. 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 value;
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.7-alpha.0",
3
+ "version": "0.0.7-alpha.2",
4
4
  "description": "Common Chains Connector Core",
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": "99d88c6179e7af6f592b1b39f8df6f6968cc0df3"
71
+ "gitHead": "4b773c10f39944c6380d556dbf0b35e911935d13"
72
72
  }
@@ -888,9 +888,12 @@ export class Transaction {
888
888
  ...output,
889
889
  capacity: output.capacity ?? 0,
890
890
  });
891
- o.capacity = fixedPointFrom(
892
- o.occupiedSize + (apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0),
893
- );
891
+ if (o.capacity === Zero) {
892
+ o.capacity = fixedPointFrom(
893
+ o.occupiedSize +
894
+ (apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0),
895
+ );
896
+ }
894
897
  return o;
895
898
  }) ?? [];
896
899
  const outputsData = outputs.map((_, i) =>
@@ -1071,9 +1074,10 @@ export class Transaction {
1071
1074
  hasher.update(this.hash());
1072
1075
 
1073
1076
  for (let i = 0; i < this.witnesses.length; i += 1) {
1074
- const input = await this.inputs[i];
1075
- await input.completeExtraInfos(client);
1077
+ const input = this.inputs[i];
1076
1078
  if (input) {
1079
+ await input.completeExtraInfos(client);
1080
+
1077
1081
  if (!input.cellOutput) {
1078
1082
  throw new Error("Unable to complete input");
1079
1083
  }