@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,60 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}
|
|
21
|
-
: function (o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
});
|
|
25
|
-
var __setModuleDefault =
|
|
26
|
-
(this && this.__setModuleDefault) ||
|
|
27
|
-
(Object.create
|
|
28
|
-
? function (o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}
|
|
31
|
-
: function (o, v) {
|
|
32
|
-
o["default"] = v;
|
|
33
|
-
});
|
|
34
|
-
var __importStar =
|
|
35
|
-
(this && this.__importStar) ||
|
|
36
|
-
function (mod) {
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
39
|
-
if (mod != null)
|
|
40
|
-
for (var k in mod)
|
|
41
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
-
__createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
24
|
+
};
|
|
46
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.Transaction =
|
|
48
|
-
exports.WitnessArgs =
|
|
49
|
-
exports.CellDep =
|
|
50
|
-
exports.CellInput =
|
|
51
|
-
exports.Cell =
|
|
52
|
-
exports.CellOutput =
|
|
53
|
-
exports.OutPoint =
|
|
54
|
-
exports.depTypeFromBytes =
|
|
55
|
-
exports.depTypeToBytes =
|
|
56
|
-
exports.depTypeFrom =
|
|
57
|
-
void 0;
|
|
26
|
+
exports.Transaction = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.Cell = exports.CellOutput = exports.OutPoint = exports.depTypeFromBytes = exports.depTypeToBytes = exports.depTypeFrom = void 0;
|
|
58
27
|
const bytes_1 = require("../bytes");
|
|
59
28
|
const hasher_1 = require("../hasher");
|
|
60
29
|
const hex_1 = require("../hex");
|
|
@@ -78,19 +47,19 @@ const transaction_advanced_1 = require("./transaction.advanced");
|
|
|
78
47
|
* ```
|
|
79
48
|
*/
|
|
80
49
|
function depTypeFrom(val) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
50
|
+
const depType = (() => {
|
|
51
|
+
if (typeof val === "number") {
|
|
52
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
|
|
53
|
+
}
|
|
54
|
+
if (typeof val === "bigint") {
|
|
55
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
|
|
56
|
+
}
|
|
57
|
+
return val;
|
|
58
|
+
})();
|
|
59
|
+
if (depType === undefined) {
|
|
60
|
+
throw new Error(`Invalid dep type ${val}`);
|
|
61
|
+
}
|
|
62
|
+
return depType;
|
|
94
63
|
}
|
|
95
64
|
exports.depTypeFrom = depTypeFrom;
|
|
96
65
|
/**
|
|
@@ -105,9 +74,7 @@ exports.depTypeFrom = depTypeFrom;
|
|
|
105
74
|
* ```
|
|
106
75
|
*/
|
|
107
76
|
function depTypeToBytes(depType) {
|
|
108
|
-
|
|
109
|
-
transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)],
|
|
110
|
-
]);
|
|
77
|
+
return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
111
78
|
}
|
|
112
79
|
exports.depTypeToBytes = depTypeToBytes;
|
|
113
80
|
/**
|
|
@@ -124,803 +91,719 @@ exports.depTypeToBytes = depTypeToBytes;
|
|
|
124
91
|
* ```
|
|
125
92
|
*/
|
|
126
93
|
function depTypeFromBytes(bytes) {
|
|
127
|
-
|
|
128
|
-
(0, bytes_1.bytesFrom)(bytes)[0]
|
|
129
|
-
];
|
|
94
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
|
|
130
95
|
}
|
|
131
96
|
exports.depTypeFromBytes = depTypeFromBytes;
|
|
132
97
|
class OutPoint {
|
|
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
|
-
? bytes
|
|
202
|
-
: new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
|
|
203
|
-
return new OutPoint(
|
|
204
|
-
(0, hex_1.hexFrom)(view.getTxHash().raw()),
|
|
205
|
-
(0, num_1.numFromBytes)(view.getIndex().raw()),
|
|
206
|
-
);
|
|
207
|
-
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates an instance of OutPoint.
|
|
100
|
+
*
|
|
101
|
+
* @param txHash - The transaction hash.
|
|
102
|
+
* @param index - The index of the output in the transaction.
|
|
103
|
+
*/
|
|
104
|
+
constructor(txHash, index) {
|
|
105
|
+
this.txHash = txHash;
|
|
106
|
+
this.index = index;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates an OutPoint instance from an OutPointLike object.
|
|
110
|
+
*
|
|
111
|
+
* @param outPoint - An OutPointLike object or an instance of OutPoint.
|
|
112
|
+
* @returns An OutPoint instance.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
static from(outPoint) {
|
|
120
|
+
if (outPoint instanceof OutPoint) {
|
|
121
|
+
return outPoint;
|
|
122
|
+
}
|
|
123
|
+
return new OutPoint((0, hex_1.hexFrom)(outPoint.txHash), (0, num_1.numFrom)(outPoint.index));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Converts the OutPoint instance to molecule data format.
|
|
127
|
+
*
|
|
128
|
+
* @returns An object representing the outpoint in molecule data format.
|
|
129
|
+
*/
|
|
130
|
+
_toMolData() {
|
|
131
|
+
return {
|
|
132
|
+
txHash: (0, bytes_1.bytesFrom)(this.txHash),
|
|
133
|
+
index: (0, num_1.numToBytes)(this.index, 4),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Converts the OutPoint instance to bytes.
|
|
138
|
+
*
|
|
139
|
+
* @returns A Uint8Array containing the outpoint bytes.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const outPointBytes = outPoint.encode();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
encode() {
|
|
147
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Creates an OutPoint instance from a byte-like value or molecule OutPoint.
|
|
151
|
+
*
|
|
152
|
+
* @param bytes - The byte-like value or molecule OutPoint to convert.
|
|
153
|
+
* @returns An OutPoint instance.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
static fromBytes(bytes) {
|
|
161
|
+
const view = bytes instanceof mol.OutPoint
|
|
162
|
+
? bytes
|
|
163
|
+
: new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
|
|
164
|
+
return new OutPoint((0, hex_1.hexFrom)(view.getTxHash().raw()), (0, num_1.numFromBytes)(view.getIndex().raw()));
|
|
165
|
+
}
|
|
208
166
|
}
|
|
209
167
|
exports.OutPoint = OutPoint;
|
|
210
168
|
class CellOutput {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
bytes instanceof mol.CellOutput
|
|
287
|
-
? bytes
|
|
288
|
-
: new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
|
|
289
|
-
return new CellOutput(
|
|
290
|
-
(0, num_1.numFromBytes)(view.getCapacity().raw()),
|
|
291
|
-
script_1.Script.fromBytes(view.getLock()),
|
|
292
|
-
(0, utils_1.apply)(
|
|
293
|
-
script_1.Script.fromBytes,
|
|
294
|
-
mol.molOptional(view.getType()),
|
|
295
|
-
),
|
|
296
|
-
);
|
|
297
|
-
}
|
|
169
|
+
/**
|
|
170
|
+
* Creates an instance of CellOutput.
|
|
171
|
+
*
|
|
172
|
+
* @param capacity - The capacity of the cell.
|
|
173
|
+
* @param lock - The lock script of the cell.
|
|
174
|
+
* @param type - The optional type script of the cell.
|
|
175
|
+
*/
|
|
176
|
+
constructor(capacity, lock, type) {
|
|
177
|
+
this.capacity = capacity;
|
|
178
|
+
this.lock = lock;
|
|
179
|
+
this.type = type;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Creates a CellOutput instance from a CellOutputLike object.
|
|
183
|
+
*
|
|
184
|
+
* @param cellOutput - A CellOutputLike object or an instance of CellOutput.
|
|
185
|
+
* @returns A CellOutput instance.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const cellOutput = CellOutput.from({
|
|
190
|
+
* capacity: 1000n,
|
|
191
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
|
|
192
|
+
* type: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
static from(cellOutput) {
|
|
197
|
+
if (cellOutput instanceof CellOutput) {
|
|
198
|
+
return cellOutput;
|
|
199
|
+
}
|
|
200
|
+
return new CellOutput((0, num_1.numFrom)(cellOutput.capacity), script_1.Script.from(cellOutput.lock), (0, utils_1.apply)(script_1.Script.from, cellOutput.type));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Converts the CellOutput instance to molecule data format.
|
|
204
|
+
*
|
|
205
|
+
* @returns An object representing the cell output in molecule data format.
|
|
206
|
+
*/
|
|
207
|
+
_toMolData() {
|
|
208
|
+
return {
|
|
209
|
+
capacity: (0, num_1.numToBytes)(this.capacity, 8),
|
|
210
|
+
lock: this.lock._toMolData(),
|
|
211
|
+
type: this.type?._toMolData(),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Converts the CellOutput instance to bytes.
|
|
216
|
+
*
|
|
217
|
+
* @returns A Uint8Array containing the cell output bytes.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const cellOutputBytes = cellOutput.toBytes();
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
toBytes() {
|
|
225
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Creates a CellOutput instance from a byte-like value or molecule CellOutput.
|
|
229
|
+
*
|
|
230
|
+
* @param bytes - The byte-like value or molecule CellOutput to convert.
|
|
231
|
+
* @returns A CellOutput instance.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
static fromBytes(bytes) {
|
|
239
|
+
const view = bytes instanceof mol.CellOutput
|
|
240
|
+
? bytes
|
|
241
|
+
: new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
|
|
242
|
+
return new CellOutput((0, num_1.numFromBytes)(view.getCapacity().raw()), script_1.Script.fromBytes(view.getLock()), (0, utils_1.apply)(script_1.Script.fromBytes, mol.molOptional(view.getType())));
|
|
243
|
+
}
|
|
298
244
|
}
|
|
299
245
|
exports.CellOutput = CellOutput;
|
|
300
246
|
class Cell {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
CellOutput.from(cell.cellOutput),
|
|
328
|
-
(0, hex_1.hexFrom)(cell.outputData),
|
|
329
|
-
(0, num_1.numFrom)(cell.blockNumber),
|
|
330
|
-
);
|
|
331
|
-
}
|
|
247
|
+
/**
|
|
248
|
+
* Creates an instance of Cell.
|
|
249
|
+
*
|
|
250
|
+
* @param outPoint - The output point of the cell.
|
|
251
|
+
* @param cellOutput - The cell output of the cell.
|
|
252
|
+
* @param outputData - The output data of the cell.
|
|
253
|
+
* @param blockNumber - The block number of the cell.
|
|
254
|
+
*/
|
|
255
|
+
constructor(outPoint, cellOutput, outputData, blockNumber) {
|
|
256
|
+
this.outPoint = outPoint;
|
|
257
|
+
this.cellOutput = cellOutput;
|
|
258
|
+
this.outputData = outputData;
|
|
259
|
+
this.blockNumber = blockNumber;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Creates a Cell instance from a CellLike object.
|
|
263
|
+
*
|
|
264
|
+
* @param cell - A CellLike object or an instance of Cell.
|
|
265
|
+
* @returns A Cell instance.
|
|
266
|
+
*/
|
|
267
|
+
static from(cell) {
|
|
268
|
+
if (cell instanceof Cell) {
|
|
269
|
+
return cell;
|
|
270
|
+
}
|
|
271
|
+
return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), (0, hex_1.hexFrom)(cell.outputData), (0, num_1.numFrom)(cell.blockNumber));
|
|
272
|
+
}
|
|
332
273
|
}
|
|
333
274
|
exports.Cell = Cell;
|
|
334
275
|
class CellInput {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
static fromBytes(bytes) {
|
|
437
|
-
const view =
|
|
438
|
-
bytes instanceof mol.CellInput
|
|
439
|
-
? bytes
|
|
440
|
-
: new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
|
|
441
|
-
return new CellInput(
|
|
442
|
-
OutPoint.fromBytes(view.getPreviousOutput()),
|
|
443
|
-
(0, num_1.numFromBytes)(view.getSince().raw()),
|
|
444
|
-
);
|
|
445
|
-
}
|
|
276
|
+
/**
|
|
277
|
+
* Creates an instance of CellInput.
|
|
278
|
+
*
|
|
279
|
+
* @param previousOutput - The previous outpoint of the cell.
|
|
280
|
+
* @param since - The since value of the cell input.
|
|
281
|
+
* @param cellOutput - The optional cell output associated with the cell input.
|
|
282
|
+
* @param outputData - The optional output data associated with the cell input.
|
|
283
|
+
* @param blockNumber - The optional block number associated with the cell input.
|
|
284
|
+
*/
|
|
285
|
+
constructor(previousOutput, since, cellOutput, outputData, blockNumber) {
|
|
286
|
+
this.previousOutput = previousOutput;
|
|
287
|
+
this.since = since;
|
|
288
|
+
this.cellOutput = cellOutput;
|
|
289
|
+
this.outputData = outputData;
|
|
290
|
+
this.blockNumber = blockNumber;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Creates a CellInput instance from a CellInputLike object.
|
|
294
|
+
*
|
|
295
|
+
* @param cellInput - A CellInputLike object or an instance of CellInput.
|
|
296
|
+
* @returns A CellInput instance.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const cellInput = CellInput.from({
|
|
301
|
+
* previousOutput: { txHash: "0x...", index: 0 },
|
|
302
|
+
* since: 0n
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
static from(cellInput) {
|
|
307
|
+
if (cellInput instanceof CellInput) {
|
|
308
|
+
return cellInput;
|
|
309
|
+
}
|
|
310
|
+
return new CellInput(OutPoint.from(cellInput.previousOutput), (0, num_1.numFrom)(cellInput.since), (0, utils_1.apply)(CellOutput.from, cellInput.cellOutput), (0, utils_1.apply)(hex_1.hexFrom, cellInput.outputData), (0, utils_1.apply)(num_1.numFrom, cellInput.blockNumber));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Complete extra infos in the input. Like the output of the out point.
|
|
314
|
+
* The instance will be modified.
|
|
315
|
+
*
|
|
316
|
+
* @returns The completed instance.
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* await cellInput.completeExtraInfos();
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
async completeExtraInfos(client) {
|
|
323
|
+
if (this.cellOutput && this.outputData && this.blockNumber) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const cell = await client.getCell(this.previousOutput);
|
|
327
|
+
if (!cell) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.cellOutput = cell.cellOutput;
|
|
331
|
+
this.outputData = cell.outputData;
|
|
332
|
+
this.blockNumber = cell.blockNumber;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Converts the CellInput instance to molecule data format.
|
|
336
|
+
*
|
|
337
|
+
* @returns An object representing the cell input in molecule data format.
|
|
338
|
+
*/
|
|
339
|
+
_toMolData() {
|
|
340
|
+
return {
|
|
341
|
+
previousOutput: this.previousOutput._toMolData(),
|
|
342
|
+
since: (0, num_1.numToBytes)(this.since, 8),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Converts the CellInput instance to bytes.
|
|
347
|
+
*
|
|
348
|
+
* @returns A Uint8Array containing the cell input bytes.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* const cellInputBytes = cellInput.toBytes();
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
toBytes() {
|
|
356
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Creates a CellInput instance from a byte-like value or molecule CellInput.
|
|
360
|
+
*
|
|
361
|
+
* @param bytes - The byte-like value or molecule CellInput to convert.
|
|
362
|
+
* @returns A CellInput instance.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
static fromBytes(bytes) {
|
|
370
|
+
const view = bytes instanceof mol.CellInput
|
|
371
|
+
? bytes
|
|
372
|
+
: new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
|
|
373
|
+
return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
|
|
374
|
+
}
|
|
446
375
|
}
|
|
447
376
|
exports.CellInput = CellInput;
|
|
448
377
|
class CellDep {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const view =
|
|
519
|
-
bytes instanceof mol.CellDep
|
|
520
|
-
? bytes
|
|
521
|
-
: new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
|
|
522
|
-
return new CellDep(
|
|
523
|
-
OutPoint.fromBytes(view.getOutPoint()),
|
|
524
|
-
depTypeFromBytes([view.getDepType()]),
|
|
525
|
-
);
|
|
526
|
-
}
|
|
378
|
+
/**
|
|
379
|
+
* Creates an instance of CellDep.
|
|
380
|
+
*
|
|
381
|
+
* @param outPoint - The outpoint of the cell dependency.
|
|
382
|
+
* @param depType - The dependency type.
|
|
383
|
+
*/
|
|
384
|
+
constructor(outPoint, depType) {
|
|
385
|
+
this.outPoint = outPoint;
|
|
386
|
+
this.depType = depType;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Creates a CellDep instance from a CellDepLike object.
|
|
390
|
+
*
|
|
391
|
+
* @param cellDep - A CellDepLike object or an instance of CellDep.
|
|
392
|
+
* @returns A CellDep instance.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const cellDep = CellDep.from({
|
|
397
|
+
* outPoint: { txHash: "0x...", index: 0 },
|
|
398
|
+
* depType: "depGroup"
|
|
399
|
+
* });
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
static from(cellDep) {
|
|
403
|
+
if (cellDep instanceof CellDep) {
|
|
404
|
+
return cellDep;
|
|
405
|
+
}
|
|
406
|
+
return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Converts the CellDep instance to molecule data format.
|
|
410
|
+
*
|
|
411
|
+
* @returns An object representing the cell dependency in molecule data format.
|
|
412
|
+
*/
|
|
413
|
+
_toMolData() {
|
|
414
|
+
return {
|
|
415
|
+
outPoint: this.outPoint._toMolData(),
|
|
416
|
+
depType: depTypeToBytes(this.depType),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Converts the CellDep instance to bytes.
|
|
421
|
+
*
|
|
422
|
+
* @returns A Uint8Array containing the cell dependency bytes.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* const cellDepBytes = cellDep.toBytes();
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
toBytes() {
|
|
430
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Creates a CellDep instance from a byte-like value or molecule CellDep.
|
|
434
|
+
*
|
|
435
|
+
* @param bytes - The byte-like value or molecule CellDep to convert.
|
|
436
|
+
* @returns A CellDep instance.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```typescript
|
|
440
|
+
* const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
fromBytes(bytes) {
|
|
444
|
+
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
|
|
445
|
+
return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
|
|
446
|
+
}
|
|
527
447
|
}
|
|
528
448
|
exports.CellDep = CellDep;
|
|
529
449
|
class WitnessArgs {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
bytes instanceof mol.WitnessArgs
|
|
606
|
-
? bytes
|
|
607
|
-
: new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
|
|
608
|
-
return new WitnessArgs(
|
|
609
|
-
(0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()),
|
|
610
|
-
(0, utils_1.apply)(
|
|
611
|
-
hex_1.hexFrom,
|
|
612
|
-
mol.molOptional(view.getInputType())?.raw(),
|
|
613
|
-
),
|
|
614
|
-
(0, utils_1.apply)(
|
|
615
|
-
hex_1.hexFrom,
|
|
616
|
-
mol.molOptional(view.getOutputType())?.raw(),
|
|
617
|
-
),
|
|
618
|
-
);
|
|
619
|
-
}
|
|
450
|
+
/**
|
|
451
|
+
* Creates an instance of WitnessArgs.
|
|
452
|
+
*
|
|
453
|
+
* @param lock - The optional lock field of the witness.
|
|
454
|
+
* @param inputType - The optional input type field of the witness.
|
|
455
|
+
* @param outputType - The optional output type field of the witness.
|
|
456
|
+
*/
|
|
457
|
+
constructor(lock, inputType, outputType) {
|
|
458
|
+
this.lock = lock;
|
|
459
|
+
this.inputType = inputType;
|
|
460
|
+
this.outputType = outputType;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Creates a WitnessArgs instance from a WitnessArgsLike object.
|
|
464
|
+
*
|
|
465
|
+
* @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
|
|
466
|
+
* @returns A WitnessArgs instance.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* const witnessArgs = WitnessArgs.from({
|
|
471
|
+
* lock: "0x...",
|
|
472
|
+
* inputType: "0x...",
|
|
473
|
+
* outputType: "0x..."
|
|
474
|
+
* });
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
static from(witnessArgs) {
|
|
478
|
+
if (witnessArgs instanceof WitnessArgs) {
|
|
479
|
+
return witnessArgs;
|
|
480
|
+
}
|
|
481
|
+
return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, witnessArgs.lock), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.inputType), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.outputType));
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Converts the WitnessArgs instance to molecule data format.
|
|
485
|
+
*
|
|
486
|
+
* @returns An object representing the witness arguments in molecule data format.
|
|
487
|
+
*/
|
|
488
|
+
_toMolData() {
|
|
489
|
+
return {
|
|
490
|
+
lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
|
|
491
|
+
inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
|
|
492
|
+
outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Converts the WitnessArgs instance to bytes.
|
|
497
|
+
*
|
|
498
|
+
* @returns A Uint8Array containing the witness arguments bytes.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const witnessArgsBytes = witnessArgs.toBytes();
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
toBytes() {
|
|
506
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
|
|
510
|
+
*
|
|
511
|
+
* @param bytes - The byte-like value or molecule WitnessArgs to convert.
|
|
512
|
+
* @returns A WitnessArgs instance.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
static fromBytes(bytes) {
|
|
520
|
+
const view = bytes instanceof mol.WitnessArgs
|
|
521
|
+
? bytes
|
|
522
|
+
: new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
|
|
523
|
+
return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getInputType())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getOutputType())?.raw()));
|
|
524
|
+
}
|
|
620
525
|
}
|
|
621
526
|
exports.WitnessArgs = WitnessArgs;
|
|
622
527
|
class Transaction {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
* outputsData: [],
|
|
679
|
-
* witnesses: []
|
|
680
|
-
* });
|
|
681
|
-
* ```
|
|
682
|
-
*/
|
|
683
|
-
static from(tx) {
|
|
684
|
-
if (tx instanceof Transaction) {
|
|
685
|
-
return tx;
|
|
686
|
-
}
|
|
687
|
-
return new Transaction(
|
|
688
|
-
(0, num_1.numFrom)(tx.version),
|
|
689
|
-
tx.cellDeps.map((cellDep) => CellDep.from(cellDep)),
|
|
690
|
-
tx.headerDeps.map(hex_1.hexFrom),
|
|
691
|
-
tx.inputs.map((input) => CellInput.from(input)),
|
|
692
|
-
tx.outputs.map((output) => CellOutput.from(output)),
|
|
693
|
-
tx.outputsData.map(hex_1.hexFrom),
|
|
694
|
-
tx.witnesses.map(hex_1.hexFrom),
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Creates a Transaction instance from a Lumos skeleton.
|
|
699
|
-
*
|
|
700
|
-
* @param skeleton - The Lumos transaction skeleton.
|
|
701
|
-
* @returns A Transaction instance.
|
|
702
|
-
*
|
|
703
|
-
* @throws Will throw an error if an input's outPoint is missing.
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* ```typescript
|
|
707
|
-
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
708
|
-
* ```
|
|
709
|
-
*/
|
|
710
|
-
static fromLumosSkeleton(skeleton) {
|
|
711
|
-
return Transaction.from({
|
|
712
|
-
version: 0n,
|
|
713
|
-
cellDeps: skeleton.cellDeps.toArray(),
|
|
714
|
-
headerDeps: skeleton.headerDeps.toArray(),
|
|
715
|
-
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
716
|
-
if (!input.outPoint) {
|
|
717
|
-
throw new Error("outPoint is required in input");
|
|
528
|
+
/**
|
|
529
|
+
* Creates an instance of Transaction.
|
|
530
|
+
*
|
|
531
|
+
* @param version - The version of the transaction.
|
|
532
|
+
* @param cellDeps - The cell dependencies of the transaction.
|
|
533
|
+
* @param headerDeps - The header dependencies of the transaction.
|
|
534
|
+
* @param inputs - The inputs of the transaction.
|
|
535
|
+
* @param outputs - The outputs of the transaction.
|
|
536
|
+
* @param outputsData - The data associated with the outputs.
|
|
537
|
+
* @param witnesses - The witnesses of the transaction.
|
|
538
|
+
*/
|
|
539
|
+
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
540
|
+
this.version = version;
|
|
541
|
+
this.cellDeps = cellDeps;
|
|
542
|
+
this.headerDeps = headerDeps;
|
|
543
|
+
this.inputs = inputs;
|
|
544
|
+
this.outputs = outputs;
|
|
545
|
+
this.outputsData = outputsData;
|
|
546
|
+
this.witnesses = witnesses;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Creates a default Transaction instance with empty fields.
|
|
550
|
+
*
|
|
551
|
+
* @returns A default Transaction instance.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const defaultTx = Transaction.default();
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
static default() {
|
|
559
|
+
return new Transaction(0n, [], [], [], [], [], []);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Creates a Transaction instance from a TransactionLike object.
|
|
563
|
+
*
|
|
564
|
+
* @param tx - A TransactionLike object or an instance of Transaction.
|
|
565
|
+
* @returns A Transaction instance.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const transaction = Transaction.from({
|
|
570
|
+
* version: 0,
|
|
571
|
+
* cellDeps: [],
|
|
572
|
+
* headerDeps: [],
|
|
573
|
+
* inputs: [],
|
|
574
|
+
* outputs: [],
|
|
575
|
+
* outputsData: [],
|
|
576
|
+
* witnesses: []
|
|
577
|
+
* });
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
static from(tx) {
|
|
581
|
+
if (tx instanceof Transaction) {
|
|
582
|
+
return tx;
|
|
718
583
|
}
|
|
719
|
-
return CellInput.from(
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
584
|
+
return new Transaction((0, num_1.numFrom)(tx.version), tx.cellDeps.map((cellDep) => CellDep.from(cellDep)), tx.headerDeps.map(hex_1.hexFrom), tx.inputs.map((input) => CellInput.from(input)), tx.outputs.map((output) => CellOutput.from(output)), tx.outputsData.map(hex_1.hexFrom), tx.witnesses.map(hex_1.hexFrom));
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Creates a Transaction instance from a Lumos skeleton.
|
|
588
|
+
*
|
|
589
|
+
* @param skeleton - The Lumos transaction skeleton.
|
|
590
|
+
* @returns A Transaction instance.
|
|
591
|
+
*
|
|
592
|
+
* @throws Will throw an error if an input's outPoint is missing.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```typescript
|
|
596
|
+
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
static fromLumosSkeleton(skeleton) {
|
|
600
|
+
return Transaction.from({
|
|
601
|
+
version: 0n,
|
|
602
|
+
cellDeps: skeleton.cellDeps.toArray(),
|
|
603
|
+
headerDeps: skeleton.headerDeps.toArray(),
|
|
604
|
+
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
605
|
+
if (!input.outPoint) {
|
|
606
|
+
throw new Error("outPoint is required in input");
|
|
607
|
+
}
|
|
608
|
+
return CellInput.from({
|
|
609
|
+
previousOutput: input.outPoint,
|
|
610
|
+
since: skeleton.inputSinces.get(i, "0x0"),
|
|
611
|
+
cellOutput: input.cellOutput,
|
|
612
|
+
outputData: input.data,
|
|
613
|
+
});
|
|
614
|
+
}),
|
|
615
|
+
outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
|
|
616
|
+
outputsData: skeleton.outputs.toArray().map((output) => output.data),
|
|
617
|
+
witnesses: skeleton.witnesses.toArray(),
|
|
724
618
|
});
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
continue;
|
|
619
|
+
}
|
|
620
|
+
stringify() {
|
|
621
|
+
return JSON.stringify(this, (_, value) => {
|
|
622
|
+
if (typeof value === "bigint") {
|
|
623
|
+
return (0, num_1.numToHex)(value);
|
|
624
|
+
}
|
|
625
|
+
return value;
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Converts the raw transaction data to bytes.
|
|
630
|
+
*
|
|
631
|
+
* @returns A Uint8Array containing the raw transaction bytes.
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
* ```typescript
|
|
635
|
+
* const rawTxBytes = transaction.rawToBytes();
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
rawToBytes() {
|
|
639
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
|
|
640
|
+
version: (0, num_1.numToBytes)(this.version, 4),
|
|
641
|
+
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
642
|
+
headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
643
|
+
inputs: this.inputs.map((i) => i._toMolData()),
|
|
644
|
+
outputs: this.outputs.map((o) => o._toMolData()),
|
|
645
|
+
outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
646
|
+
}));
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Calculates the hash of the transaction.
|
|
650
|
+
*
|
|
651
|
+
* @returns The hash of the transaction.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```typescript
|
|
655
|
+
* const txHash = transaction.hash();
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
hash() {
|
|
659
|
+
return (0, hasher_1.ckbHash)(this.rawToBytes());
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Hashes a witness and updates the hasher.
|
|
663
|
+
*
|
|
664
|
+
* @param witness - The witness to hash.
|
|
665
|
+
* @param hasher - The hasher instance to update.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* Transaction.hashWitnessToHasher("0x...", hasher);
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
static hashWitnessToHasher(witness, hasher) {
|
|
673
|
+
const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
|
|
674
|
+
hasher.update((0, num_1.numToBytes)(raw.length, 8));
|
|
675
|
+
hasher.update(raw);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Computes the signing hash information for a given script.
|
|
679
|
+
*
|
|
680
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
681
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
682
|
+
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
683
|
+
* or undefined if no matching input is found.
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* ```typescript
|
|
687
|
+
* const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
|
|
688
|
+
* if (signHashInfo) {
|
|
689
|
+
* console.log(signHashInfo.message); // Outputs the signing message
|
|
690
|
+
* console.log(signHashInfo.position); // Outputs the witness position
|
|
691
|
+
* }
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
async getSignHashInfo(scriptLike, client) {
|
|
695
|
+
const script = script_1.Script.from(scriptLike);
|
|
696
|
+
let position = -1;
|
|
697
|
+
const hasher = new hasher_1.Hasher();
|
|
698
|
+
hasher.update(this.hash());
|
|
699
|
+
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
700
|
+
const input = this.inputs[i];
|
|
701
|
+
if (input) {
|
|
702
|
+
await input.completeExtraInfos(client);
|
|
703
|
+
if (!input.cellOutput) {
|
|
704
|
+
throw Error("Unable to resolve inputs info");
|
|
705
|
+
}
|
|
706
|
+
if (!script.eq(input.cellOutput.lock)) {
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (position === -1) {
|
|
710
|
+
position = i;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (position === -1) {
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
824
717
|
}
|
|
825
718
|
if (position === -1) {
|
|
826
|
-
|
|
719
|
+
return undefined;
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
message: hasher.digest(),
|
|
723
|
+
position,
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Find the first occurrence of a input with the specified lock
|
|
728
|
+
*
|
|
729
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
730
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
731
|
+
* @returns A promise that resolves to the prepared transaction
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```typescript
|
|
735
|
+
* const index = await tx.findInputIndexByLock(scriptLike, client);
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
async findInputIndexByLock(scriptLike, client) {
|
|
739
|
+
const script = script_1.Script.from(scriptLike);
|
|
740
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
741
|
+
const input = this.inputs[i];
|
|
742
|
+
await input.completeExtraInfos(client);
|
|
743
|
+
if (!input.cellOutput) {
|
|
744
|
+
throw Error("Unable to resolve inputs info");
|
|
745
|
+
}
|
|
746
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
747
|
+
return i;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Get witness at index as WitnessArgs
|
|
753
|
+
*
|
|
754
|
+
* @param index - The index of the witness.
|
|
755
|
+
* @returns The witness parsed as WitnessArgs.
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```typescript
|
|
759
|
+
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
getWitnessArgsAt(index) {
|
|
763
|
+
const rawWitness = this.witnesses[index];
|
|
764
|
+
return (rawWitness ?? "0x") !== "0x"
|
|
765
|
+
? WitnessArgs.fromBytes(rawWitness)
|
|
766
|
+
: undefined;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Set witness at index by WitnessArgs
|
|
770
|
+
*
|
|
771
|
+
* @param index - The index of the witness.
|
|
772
|
+
* @param witness - The WitnessArgs to set.
|
|
773
|
+
* @returns The transaction itself.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```typescript
|
|
777
|
+
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
setWitnessArgsAt(index, witness) {
|
|
781
|
+
if (this.witnesses.length < index) {
|
|
782
|
+
this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
|
|
827
783
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
* ```
|
|
853
|
-
*/
|
|
854
|
-
async findInputIndexByLock(scriptLike, client) {
|
|
855
|
-
const script = script_1.Script.from(scriptLike);
|
|
856
|
-
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
857
|
-
const input = await this.inputs[i].completeExtraInfos(client);
|
|
858
|
-
if (!input.cellOutput) {
|
|
859
|
-
throw Error("Unable to resolve inputs info");
|
|
860
|
-
}
|
|
861
|
-
if (script.eq(input.cellOutput.lock)) {
|
|
862
|
-
return i;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* Get witness at index as WitnessArgs
|
|
868
|
-
*
|
|
869
|
-
* @param index - The index of the witness.
|
|
870
|
-
* @returns The witness parsed as WitnessArgs.
|
|
871
|
-
*
|
|
872
|
-
* @example
|
|
873
|
-
* ```typescript
|
|
874
|
-
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
875
|
-
* ```
|
|
876
|
-
*/
|
|
877
|
-
getWitnessArgsAt(index) {
|
|
878
|
-
const rawWitness = this.witnesses[index];
|
|
879
|
-
return (rawWitness ?? "0x") !== "0x"
|
|
880
|
-
? WitnessArgs.fromBytes(rawWitness)
|
|
881
|
-
: undefined;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Set witness at index by WitnessArgs
|
|
885
|
-
*
|
|
886
|
-
* @param index - The index of the witness.
|
|
887
|
-
* @param witness - The WitnessArgs to set.
|
|
888
|
-
* @returns The transaction itself.
|
|
889
|
-
*
|
|
890
|
-
* @example
|
|
891
|
-
* ```typescript
|
|
892
|
-
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
893
|
-
* ```
|
|
894
|
-
*/
|
|
895
|
-
setWitnessArgsAt(index, witness) {
|
|
896
|
-
if (this.witnesses.length < index) {
|
|
897
|
-
this.witnesses.push(
|
|
898
|
-
...Array.from(new Array(index - this.witnesses.length), () => "0x"),
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Prepare dummy witness for sighash all method
|
|
905
|
-
*
|
|
906
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
907
|
-
* @param lockLen - The length of dummy lock bytes.
|
|
908
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
909
|
-
* @returns A promise that resolves to the prepared transaction
|
|
910
|
-
*
|
|
911
|
-
* @example
|
|
912
|
-
* ```typescript
|
|
913
|
-
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
914
|
-
* ```
|
|
915
|
-
*/
|
|
916
|
-
async prepareSighashAllWitness(scriptLike, lockLen, client) {
|
|
917
|
-
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
918
|
-
if (position === undefined) {
|
|
919
|
-
return;
|
|
920
|
-
}
|
|
921
|
-
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
922
|
-
witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
|
|
923
|
-
this.setWitnessArgsAt(position, witness);
|
|
924
|
-
}
|
|
784
|
+
this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Prepare dummy witness for sighash all method
|
|
788
|
+
*
|
|
789
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
790
|
+
* @param lockLen - The length of dummy lock bytes.
|
|
791
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
792
|
+
* @returns A promise that resolves to the prepared transaction
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
797
|
+
* ```
|
|
798
|
+
*/
|
|
799
|
+
async prepareSighashAllWitness(scriptLike, lockLen, client) {
|
|
800
|
+
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
801
|
+
if (position === undefined) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
805
|
+
witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
|
|
806
|
+
this.setWitnessArgsAt(position, witness);
|
|
807
|
+
}
|
|
925
808
|
}
|
|
926
809
|
exports.Transaction = Transaction;
|