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