@ckb-ccc/core 0.0.5-alpha.10 → 0.0.5-alpha.11
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.
- package/dist/ckb/transaction.d.ts +2 -4
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +12 -12
- package/dist/client/client.js +1 -1
- package/dist.commonjs/address/address.advanced.d.ts +24 -29
- package/dist.commonjs/address/address.advanced.js +92 -114
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +14 -30
- package/dist.commonjs/address/index.d.ts +44 -51
- package/dist.commonjs/address/index.js +68 -87
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +22 -47
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/bytes/advanced.d.ts +2 -11
- package/dist.commonjs/bytes/index.d.ts +3 -9
- package/dist.commonjs/bytes/index.js +26 -28
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +22 -47
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +14 -30
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +9 -12
- package/dist.commonjs/ckb/script.d.ts +76 -76
- package/dist.commonjs/ckb/script.js +126 -166
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +530 -570
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +722 -839
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +14 -30
- package/dist.commonjs/client/client.d.ts +21 -52
- package/dist.commonjs/client/client.js +57 -66
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +24 -30
- package/dist.commonjs/client/clientPublicMainnet.d.ts +4 -6
- package/dist.commonjs/client/clientPublicMainnet.js +9 -9
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +24 -30
- package/dist.commonjs/client/clientPublicTestnet.d.ts +4 -6
- package/dist.commonjs/client/clientPublicTestnet.js +9 -9
- package/dist.commonjs/client/clientTypes.d.ts +36 -51
- package/dist.commonjs/client/clientTypes.js +19 -34
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +14 -30
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
- package/dist.commonjs/client/jsonRpc/index.d.ts +75 -92
- package/dist.commonjs/client/jsonRpc/index.js +108 -135
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +38 -78
- package/dist.commonjs/client/jsonRpc/transformers.js +150 -175
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +3 -9
- package/dist.commonjs/fixedPoint/index.js +20 -26
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +36 -42
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +36 -36
- package/dist.commonjs/hasher/index.js +45 -52
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +22 -47
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +19 -30
- package/dist.commonjs/signer/btc/index.d.ts +1 -1
- package/dist.commonjs/signer/btc/index.js +14 -30
- package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
- package/dist.commonjs/signer/btc/signerBtc.js +65 -85
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
- package/dist.commonjs/signer/btc/verify.d.ts +2 -6
- package/dist.commonjs/signer/btc/verify.js +2 -5
- package/dist.commonjs/signer/ckb/index.d.ts +1 -1
- package/dist.commonjs/signer/ckb/index.js +14 -30
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
- package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
- package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
- package/dist.commonjs/signer/dummy/dummy.js +16 -16
- package/dist.commonjs/signer/dummy/index.d.ts +1 -1
- package/dist.commonjs/signer/dummy/index.js +14 -30
- package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
- package/dist.commonjs/signer/dummy/openLink.js +7 -7
- package/dist.commonjs/signer/evm/index.d.ts +1 -1
- package/dist.commonjs/signer/evm/index.js +14 -30
- package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
- package/dist.commonjs/signer/evm/signerEvm.js +68 -100
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
- package/dist.commonjs/signer/evm/verify.d.ts +2 -6
- package/dist.commonjs/signer/evm/verify.js +2 -7
- package/dist.commonjs/signer/index.d.ts +1 -1
- package/dist.commonjs/signer/index.js +14 -30
- package/dist.commonjs/signer/signer/index.d.ts +153 -159
- package/dist.commonjs/signer/signer/index.js +181 -204
- package/dist.commonjs/utils/index.d.ts +8 -36
- package/dist.commonjs/utils/index.js +12 -18
- package/package.json +2 -2
- package/src/ckb/transaction.ts +14 -13
|
@@ -1,36 +1,31 @@
|
|
|
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
|
var SignerSignType;
|
|
13
8
|
(function (SignerSignType) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
SignerSignType["Unknown"] = "Unknown";
|
|
10
|
+
SignerSignType["BtcEcdsa"] = "BtcEcdsa";
|
|
11
|
+
SignerSignType["EvmPersonal"] = "EvmPersonal";
|
|
12
|
+
SignerSignType["JoyId"] = "JoyId";
|
|
18
13
|
})(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
|
|
19
14
|
/**
|
|
20
15
|
* An enumeration of signer display types in wallet.
|
|
21
16
|
*/
|
|
22
17
|
var SignerType;
|
|
23
18
|
(function (SignerType) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
SignerType["EVM"] = "EVM";
|
|
20
|
+
SignerType["BTC"] = "BTC";
|
|
21
|
+
SignerType["CKB"] = "CKB";
|
|
27
22
|
})(SignerType || (exports.SignerType = SignerType = {}));
|
|
28
23
|
class Signature {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
constructor(signature, identity, signType) {
|
|
25
|
+
this.signature = signature;
|
|
26
|
+
this.identity = identity;
|
|
27
|
+
this.signType = signType;
|
|
28
|
+
}
|
|
34
29
|
}
|
|
35
30
|
exports.Signature = Signature;
|
|
36
31
|
/**
|
|
@@ -38,197 +33,179 @@ exports.Signature = Signature;
|
|
|
38
33
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
39
34
|
*/
|
|
40
35
|
class Signer {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*
|
|
206
|
-
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
207
|
-
* @returns A promise that resolves to the prepared Transaction object.
|
|
208
|
-
* @throws Will throw an error if not implemented.
|
|
209
|
-
*/
|
|
210
|
-
prepareTransaction(_) {
|
|
211
|
-
throw Error("Signer.prepareTransaction not implemented");
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
|
|
215
|
-
*
|
|
216
|
-
* @param _ - The transaction to sign, represented as a TransactionLike object.
|
|
217
|
-
* @returns A promise that resolves to the signed Transaction object.
|
|
218
|
-
* @throws Will throw an error if not implemented.
|
|
219
|
-
*/
|
|
220
|
-
signOnlyTransaction(_) {
|
|
221
|
-
throw Error("Signer.signOnlyTransaction not implemented");
|
|
222
|
-
}
|
|
36
|
+
constructor(client_) {
|
|
37
|
+
this.client_ = client_;
|
|
38
|
+
}
|
|
39
|
+
get client() {
|
|
40
|
+
return this.client_;
|
|
41
|
+
}
|
|
42
|
+
static async verifyMessage(message, signature) {
|
|
43
|
+
switch (signature.signType) {
|
|
44
|
+
case SignerSignType.EvmPersonal:
|
|
45
|
+
return (0, verify_1.verifyMessageEvmPersonal)(message, signature.signature, signature.identity);
|
|
46
|
+
case SignerSignType.BtcEcdsa:
|
|
47
|
+
return (0, btc_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
|
|
48
|
+
case SignerSignType.JoyId:
|
|
49
|
+
return (0, verifyJoyId_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
|
|
50
|
+
case SignerSignType.Unknown:
|
|
51
|
+
throw new Error("Unknown signer sign type");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Replace the current client.
|
|
56
|
+
*/
|
|
57
|
+
async replaceClient(client) {
|
|
58
|
+
this.client_ = client;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Disconnects to the signer.
|
|
62
|
+
*
|
|
63
|
+
* @returns A promise that resolves when disconnected.
|
|
64
|
+
*/
|
|
65
|
+
async disconnect() { }
|
|
66
|
+
/**
|
|
67
|
+
* Gets the identity for verifying signature, usually it's address
|
|
68
|
+
*
|
|
69
|
+
* @returns A promise that resolves to a string representing the identity
|
|
70
|
+
*/
|
|
71
|
+
async getIdentity() {
|
|
72
|
+
return this.getInternalAddress();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets the recommended Address object for the signer.
|
|
76
|
+
*
|
|
77
|
+
* @param _preference - Optional preference parameter.
|
|
78
|
+
* @returns A promise that resolves to the recommended Address object.
|
|
79
|
+
*/
|
|
80
|
+
async getRecommendedAddressObj(_preference) {
|
|
81
|
+
return (await this.getAddressObjs())[0];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gets the recommended address for the signer as a string.
|
|
85
|
+
*
|
|
86
|
+
* @param preference - Optional preference parameter.
|
|
87
|
+
* @returns A promise that resolves to the recommended address as a string.
|
|
88
|
+
*/
|
|
89
|
+
async getRecommendedAddress(preference) {
|
|
90
|
+
return (await this.getRecommendedAddressObj(preference)).toString();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets an array of addresses associated with the signer as strings.
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise that resolves to an array of addresses as strings.
|
|
96
|
+
*/
|
|
97
|
+
async getAddresses() {
|
|
98
|
+
return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets balance of all addresses
|
|
102
|
+
*
|
|
103
|
+
* @returns A promise that resolves to the balance
|
|
104
|
+
*/
|
|
105
|
+
async getBalance() {
|
|
106
|
+
return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Signs a message.
|
|
110
|
+
*
|
|
111
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
112
|
+
* @returns A promise that resolves to the signature info.
|
|
113
|
+
* @throws Will throw an error if not implemented.
|
|
114
|
+
*/
|
|
115
|
+
async signMessage(message) {
|
|
116
|
+
return {
|
|
117
|
+
signature: await this.signMessageRaw(message),
|
|
118
|
+
identity: await this.getIdentity(),
|
|
119
|
+
signType: this.signType,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
|
|
124
|
+
*
|
|
125
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
126
|
+
* @returns A promise that resolves to the signature as a string.
|
|
127
|
+
* @throws Will throw an error if not implemented.
|
|
128
|
+
*/
|
|
129
|
+
signMessageRaw(_) {
|
|
130
|
+
throw Error("Signer.signMessageRaw not implemented");
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Verify a signature.
|
|
134
|
+
*
|
|
135
|
+
* @param _ - The original message.
|
|
136
|
+
* @param _ - The signature to verify.
|
|
137
|
+
* @returns A promise that resolves to the verification result.
|
|
138
|
+
* @throws Will throw an error if not implemented.
|
|
139
|
+
*/
|
|
140
|
+
async verifyMessage(message, signature) {
|
|
141
|
+
if (typeof signature === "string") {
|
|
142
|
+
return this.verifyMessageRaw(message, signature);
|
|
143
|
+
}
|
|
144
|
+
if (signature.identity !== (await this.getIdentity()) ||
|
|
145
|
+
![SignerSignType.Unknown, this.signType].includes(signature.signType)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return this.verifyMessageRaw(message, signature.signature);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Verify a string signature. This method is not implemented and should be overridden by subclasses.
|
|
152
|
+
*
|
|
153
|
+
* @param _0 - The original message.
|
|
154
|
+
* @param _1 - The signature to verify.
|
|
155
|
+
* @returns A promise that resolves to the verification result.
|
|
156
|
+
* @throws Will throw an error if not implemented.
|
|
157
|
+
*/
|
|
158
|
+
verifyMessageRaw(_0, _1) {
|
|
159
|
+
throw Error("Signer.verifyMessageRaw not implemented");
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sends a transaction after signing it.
|
|
163
|
+
*
|
|
164
|
+
* @param tx - The transaction to send, represented as a TransactionLike object.
|
|
165
|
+
* @returns A promise that resolves to the transaction hash as a Hex string.
|
|
166
|
+
*/
|
|
167
|
+
async sendTransaction(tx) {
|
|
168
|
+
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Signs a transaction.
|
|
172
|
+
*
|
|
173
|
+
* @param tx - The transaction to sign, represented as a TransactionLike object.
|
|
174
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
175
|
+
*/
|
|
176
|
+
async signTransaction(tx) {
|
|
177
|
+
const preparedTx = await this.prepareTransaction(tx);
|
|
178
|
+
return this.signOnlyTransaction(preparedTx);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
182
|
+
*
|
|
183
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
184
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
185
|
+
* @throws Will throw an error if not implemented.
|
|
186
|
+
*/
|
|
187
|
+
prepareTransaction(_) {
|
|
188
|
+
throw Error("Signer.prepareTransaction not implemented");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
|
|
192
|
+
*
|
|
193
|
+
* @param _ - The transaction to sign, represented as a TransactionLike object.
|
|
194
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
195
|
+
* @throws Will throw an error if not implemented.
|
|
196
|
+
*/
|
|
197
|
+
signOnlyTransaction(_) {
|
|
198
|
+
throw Error("Signer.signOnlyTransaction not implemented");
|
|
199
|
+
}
|
|
223
200
|
}
|
|
224
201
|
exports.Signer = Signer;
|
|
225
202
|
/**
|
|
226
203
|
* A class representing information about a signer, including its type and the signer instance.
|
|
227
204
|
*/
|
|
228
205
|
class SignerInfo {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
206
|
+
constructor(name, signer) {
|
|
207
|
+
this.name = name;
|
|
208
|
+
this.signer = signer;
|
|
209
|
+
}
|
|
233
210
|
}
|
|
234
211
|
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,13 +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
|
-
) => Promise<T | undefined | null | void> | T | undefined | null | void,
|
|
92
|
-
init: T,
|
|
93
|
-
): Promise<T>;
|
|
65
|
+
export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T): Promise<T>;
|
|
94
66
|
export declare function isWebview(userAgent: string): boolean;
|
|
95
|
-
//# 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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
values = values.slice(1);
|
|
25
|
-
}
|
|
26
|
-
return values.reduce(
|
|
27
|
-
(current, b) =>
|
|
28
|
-
current.then((v) =>
|
|
29
|
-
Promise.resolve(accumulator(v, b)).then((r) => r ?? v),
|
|
30
|
-
),
|
|
31
|
-
Promise.resolve(init),
|
|
32
|
-
);
|
|
26
|
+
return values.reduce((current, b) => current.then((v) => Promise.resolve(accumulator(v, b)).then((r) => r ?? v)), Promise.resolve(init));
|
|
33
27
|
}
|
|
34
28
|
exports.reduceAsync = reduceAsync;
|
|
35
29
|
function isWebview(userAgent) {
|
|
36
|
-
|
|
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.5-alpha.
|
|
3
|
+
"version": "0.0.5-alpha.11",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"cross-fetch": "^4.0.0",
|
|
68
68
|
"ethers": "^6.13.1"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "91d312cf8246dbe772ed163a8d970e6af6c55368"
|
|
71
71
|
}
|
package/src/ckb/transaction.ts
CHANGED
|
@@ -384,24 +384,23 @@ export class CellInput {
|
|
|
384
384
|
* @returns The completed instance.
|
|
385
385
|
* @example
|
|
386
386
|
* ```typescript
|
|
387
|
-
*
|
|
388
|
-
* await cellInput.completeExtraInfos();
|
|
389
|
-
* }
|
|
387
|
+
* await cellInput.completeExtraInfos();
|
|
390
388
|
* ```
|
|
391
389
|
*/
|
|
392
390
|
|
|
393
|
-
async completeExtraInfos(client: Client): Promise<
|
|
391
|
+
async completeExtraInfos(client: Client): Promise<void> {
|
|
394
392
|
if (this.cellOutput && this.outputData && this.blockNumber) {
|
|
395
|
-
return
|
|
393
|
+
return;
|
|
396
394
|
}
|
|
397
395
|
|
|
398
396
|
const cell = await client.getCell(this.previousOutput);
|
|
399
|
-
if (cell) {
|
|
400
|
-
|
|
401
|
-
this.outputData = cell.outputData;
|
|
402
|
-
this.blockNumber = cell.blockNumber;
|
|
397
|
+
if (!cell) {
|
|
398
|
+
return;
|
|
403
399
|
}
|
|
404
|
-
|
|
400
|
+
|
|
401
|
+
this.cellOutput = cell.cellOutput;
|
|
402
|
+
this.outputData = cell.outputData;
|
|
403
|
+
this.blockNumber = cell.blockNumber;
|
|
405
404
|
}
|
|
406
405
|
|
|
407
406
|
/**
|
|
@@ -867,8 +866,9 @@ export class Transaction {
|
|
|
867
866
|
hasher.update(this.hash());
|
|
868
867
|
|
|
869
868
|
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
870
|
-
|
|
871
|
-
|
|
869
|
+
const input = this.inputs[i];
|
|
870
|
+
if (input) {
|
|
871
|
+
await input.completeExtraInfos(client);
|
|
872
872
|
|
|
873
873
|
if (!input.cellOutput) {
|
|
874
874
|
throw Error("Unable to resolve inputs info");
|
|
@@ -919,7 +919,8 @@ export class Transaction {
|
|
|
919
919
|
const script = Script.from(scriptLike);
|
|
920
920
|
|
|
921
921
|
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
922
|
-
const input =
|
|
922
|
+
const input = this.inputs[i];
|
|
923
|
+
await input.completeExtraInfos(client);
|
|
923
924
|
|
|
924
925
|
if (!input.cellOutput) {
|
|
925
926
|
throw Error("Unable to resolve inputs info");
|