@ckb-ccc/core 0.0.10-alpha.4 → 0.0.10-alpha.5
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.map +1 -1
- package/dist/ckb/transaction.js +1 -2
- package/dist.commonjs/address/address.advanced.d.ts +24 -29
- package/dist.commonjs/address/address.advanced.js +89 -115
- 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 +65 -84
- 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 +117 -121
- package/dist.commonjs/ckb/script.js +176 -220
- 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 +722 -806
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +1190 -1424
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +14 -30
- package/dist.commonjs/client/client.advanced.d.ts +6 -23
- package/dist.commonjs/client/client.advanced.js +61 -89
- package/dist.commonjs/client/client.d.ts +54 -114
- package/dist.commonjs/client/client.js +182 -215
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +189 -215
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicMainnet.js +15 -17
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -227
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicTestnet.js +13 -13
- package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
- package/dist.commonjs/client/clientTypes.advanced.js +1 -1
- package/dist.commonjs/client/clientTypes.d.ts +26 -51
- package/dist.commonjs/client/clientTypes.js +22 -56
- 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 -94
- package/dist.commonjs/client/jsonRpc/index.js +108 -135
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
- package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
- 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 +37 -40
- package/dist.commonjs/hasher/index.js +48 -58
- 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 +27 -39
- 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 +66 -89
- 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 +3 -10
- package/dist.commonjs/signer/ckb/index.d.ts +1 -1
- package/dist.commonjs/signer/ckb/index.js +14 -30
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +5 -5
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +27 -41
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +11 -11
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +35 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +3 -9
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +5 -13
- 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 +70 -105
- 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/nostr/index.d.ts +1 -1
- package/dist.commonjs/signer/nostr/index.js +14 -30
- package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
- package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
- package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
- package/dist.commonjs/signer/nostr/verify.js +39 -50
- package/dist.commonjs/signer/signer/index.d.ts +162 -171
- package/dist.commonjs/signer/signer/index.js +198 -234
- package/dist.commonjs/utils/index.d.ts +9 -42
- package/dist.commonjs/utils/index.js +12 -18
- package/package.json +3 -3
|
@@ -1,54 +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.Script =
|
|
48
|
-
exports.hashTypeFromBytes =
|
|
49
|
-
exports.hashTypeToBytes =
|
|
50
|
-
exports.hashTypeFrom =
|
|
51
|
-
void 0;
|
|
26
|
+
exports.Script = exports.hashTypeFromBytes = exports.hashTypeToBytes = exports.hashTypeFrom = void 0;
|
|
52
27
|
const bytes_1 = require("../bytes");
|
|
53
28
|
const hasher_1 = require("../hasher");
|
|
54
29
|
const hex_1 = require("../hex");
|
|
@@ -69,22 +44,22 @@ const script_advanced_1 = require("./script.advanced");
|
|
|
69
44
|
* ```
|
|
70
45
|
*/
|
|
71
46
|
function hashTypeFrom(val) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
47
|
+
const hashType = (() => {
|
|
48
|
+
if (typeof val === "number") {
|
|
49
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[val];
|
|
50
|
+
}
|
|
51
|
+
if (typeof val === "bigint") {
|
|
52
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[Number(val)];
|
|
53
|
+
}
|
|
54
|
+
if (!script_advanced_1.HASH_TYPES.includes(val)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return val;
|
|
58
|
+
})();
|
|
59
|
+
if (hashType === undefined) {
|
|
60
|
+
throw new Error(`Invalid hash type ${val}`);
|
|
81
61
|
}
|
|
82
|
-
return
|
|
83
|
-
})();
|
|
84
|
-
if (hashType === undefined) {
|
|
85
|
-
throw new Error(`Invalid hash type ${val}`);
|
|
86
|
-
}
|
|
87
|
-
return hashType;
|
|
62
|
+
return hashType;
|
|
88
63
|
}
|
|
89
64
|
exports.hashTypeFrom = hashTypeFrom;
|
|
90
65
|
/**
|
|
@@ -99,9 +74,7 @@ exports.hashTypeFrom = hashTypeFrom;
|
|
|
99
74
|
* ```
|
|
100
75
|
*/
|
|
101
76
|
function hashTypeToBytes(hashType) {
|
|
102
|
-
|
|
103
|
-
script_advanced_1.HASH_TYPE_TO_NUM[hashTypeFrom(hashType)],
|
|
104
|
-
]);
|
|
77
|
+
return (0, bytes_1.bytesFrom)([script_advanced_1.HASH_TYPE_TO_NUM[hashTypeFrom(hashType)]]);
|
|
105
78
|
}
|
|
106
79
|
exports.hashTypeToBytes = hashTypeToBytes;
|
|
107
80
|
/**
|
|
@@ -118,166 +91,149 @@ exports.hashTypeToBytes = hashTypeToBytes;
|
|
|
118
91
|
* ```
|
|
119
92
|
*/
|
|
120
93
|
function hashTypeFromBytes(bytes) {
|
|
121
|
-
|
|
94
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
|
|
122
95
|
}
|
|
123
96
|
exports.hashTypeFromBytes = hashTypeFromBytes;
|
|
124
97
|
class Script {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Creates an instance of Script.
|
|
100
|
+
*
|
|
101
|
+
* @param codeHash - The code hash of the script.
|
|
102
|
+
* @param hashType - The hash type of the script.
|
|
103
|
+
* @param args - The arguments for the script.
|
|
104
|
+
*/
|
|
105
|
+
constructor(codeHash, hashType, args) {
|
|
106
|
+
this.codeHash = codeHash;
|
|
107
|
+
this.hashType = hashType;
|
|
108
|
+
this.args = args;
|
|
109
|
+
}
|
|
110
|
+
get occupiedSize() {
|
|
111
|
+
return 33 + (0, bytes_1.bytesFrom)(this.args).length;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Clone a script.
|
|
115
|
+
*
|
|
116
|
+
* @returns A cloned Script instance.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const script1 = script0.clone();
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
clone() {
|
|
124
|
+
return new Script(this.codeHash, this.hashType, this.args);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates a Script instance from a ScriptLike object.
|
|
128
|
+
*
|
|
129
|
+
* @param script - A ScriptLike object or an instance of Script.
|
|
130
|
+
* @returns A Script instance.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const script = Script.from({
|
|
135
|
+
* codeHash: "0x1234...",
|
|
136
|
+
* hashType: "type",
|
|
137
|
+
* args: "0xabcd..."
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
static from(script) {
|
|
142
|
+
if (script instanceof Script) {
|
|
143
|
+
return script;
|
|
144
|
+
}
|
|
145
|
+
return new Script((0, hex_1.hexFrom)(script.codeHash), hashTypeFrom(script.hashType), (0, hex_1.hexFrom)(script.args));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a Script instance from client and known script.
|
|
149
|
+
*
|
|
150
|
+
* @param knownScript - A KnownScript enum.
|
|
151
|
+
* @param args - Args for the script.
|
|
152
|
+
* @param client - A ScriptLike object or an instance of Script.
|
|
153
|
+
* @returns A promise that resolves to the script instance.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const script = await Script.fromKnownScript(
|
|
158
|
+
* client,
|
|
159
|
+
* KnownScript.XUdt,
|
|
160
|
+
* args: "0xabcd..."
|
|
161
|
+
* );
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
static async fromKnownScript(client, knownScript, args) {
|
|
165
|
+
const script = await client.getKnownScript(knownScript);
|
|
166
|
+
return new Script(script.codeHash, script.hashType, (0, hex_1.hexFrom)(args));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Converts the Script instance to molecule data format.
|
|
170
|
+
*
|
|
171
|
+
* @returns An object representing the script in molecule data format.
|
|
172
|
+
*/
|
|
173
|
+
_toMolData() {
|
|
174
|
+
return {
|
|
175
|
+
codeHash: (0, bytes_1.bytesFrom)(this.codeHash),
|
|
176
|
+
hashType: hashTypeToBytes(this.hashType),
|
|
177
|
+
args: (0, bytes_1.bytesFrom)(this.args),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Converts the Script instance to bytes.
|
|
182
|
+
*
|
|
183
|
+
* @returns A Uint8Array containing the script bytes.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const scriptBytes = script.toBytes();
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
toBytes() {
|
|
191
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeScript(this._toMolData()));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get hash of a script
|
|
195
|
+
*
|
|
196
|
+
* @returns Hash of this script
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const hash = script.hash();
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
hash() {
|
|
204
|
+
return (0, hasher_1.hashCkb)(this.toBytes());
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Creates a Script instance from a byte-like value or molecule Script.
|
|
208
|
+
*
|
|
209
|
+
* @param bytes - The byte-like value or molecule Script to convert.
|
|
210
|
+
* @returns A Script instance.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const script = Script.fromBytes(new Uint8Array([/* script bytes *\/]));
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
static fromBytes(bytes) {
|
|
218
|
+
const view = bytes instanceof mol.Script ? bytes : new mol.Script((0, bytes_1.bytesFrom)(bytes));
|
|
219
|
+
return new Script((0, hex_1.hexFrom)(view.getCodeHash().raw()), hashTypeFromBytes([view.getHashType()]), (0, hex_1.hexFrom)(view.getArgs().raw()));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Compares the current Script instance with another ScriptLike object for equality.
|
|
223
|
+
*
|
|
224
|
+
* @param val - The ScriptLike object to compare with.
|
|
225
|
+
* @returns True if the scripts are equal, otherwise false.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const isEqual = script.eq(anotherScript);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
eq(val) {
|
|
233
|
+
const script = Script.from(val);
|
|
234
|
+
return (this.codeHash === script.codeHash &&
|
|
235
|
+
this.args === script.args &&
|
|
236
|
+
this.hashType === script.hashType);
|
|
171
237
|
}
|
|
172
|
-
return new Script(
|
|
173
|
-
(0, hex_1.hexFrom)(script.codeHash),
|
|
174
|
-
hashTypeFrom(script.hashType),
|
|
175
|
-
(0, hex_1.hexFrom)(script.args),
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Creates a Script instance from client and known script.
|
|
180
|
-
*
|
|
181
|
-
* @param knownScript - A KnownScript enum.
|
|
182
|
-
* @param args - Args for the script.
|
|
183
|
-
* @param client - A ScriptLike object or an instance of Script.
|
|
184
|
-
* @returns A promise that resolves to the script instance.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```typescript
|
|
188
|
-
* const script = await Script.fromKnownScript(
|
|
189
|
-
* client,
|
|
190
|
-
* KnownScript.XUdt,
|
|
191
|
-
* args: "0xabcd..."
|
|
192
|
-
* );
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
static async fromKnownScript(client, knownScript, args) {
|
|
196
|
-
const script = await client.getKnownScript(knownScript);
|
|
197
|
-
return new Script(
|
|
198
|
-
script.codeHash,
|
|
199
|
-
script.hashType,
|
|
200
|
-
(0, hex_1.hexFrom)(args),
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Converts the Script instance to molecule data format.
|
|
205
|
-
*
|
|
206
|
-
* @returns An object representing the script in molecule data format.
|
|
207
|
-
*/
|
|
208
|
-
_toMolData() {
|
|
209
|
-
return {
|
|
210
|
-
codeHash: (0, bytes_1.bytesFrom)(this.codeHash),
|
|
211
|
-
hashType: hashTypeToBytes(this.hashType),
|
|
212
|
-
args: (0, bytes_1.bytesFrom)(this.args),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Converts the Script instance to bytes.
|
|
217
|
-
*
|
|
218
|
-
* @returns A Uint8Array containing the script bytes.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const scriptBytes = script.toBytes();
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
toBytes() {
|
|
226
|
-
return (0, bytes_1.bytesFrom)(mol.SerializeScript(this._toMolData()));
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Get hash of a script
|
|
230
|
-
*
|
|
231
|
-
* @returns Hash of this script
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```typescript
|
|
235
|
-
* const hash = script.hash();
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
hash() {
|
|
239
|
-
return (0, hasher_1.hashCkb)(this.toBytes());
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Creates a Script instance from a byte-like value or molecule Script.
|
|
243
|
-
*
|
|
244
|
-
* @param bytes - The byte-like value or molecule Script to convert.
|
|
245
|
-
* @returns A Script instance.
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```typescript
|
|
249
|
-
* const script = Script.fromBytes(new Uint8Array([/* script bytes *\/]));
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
static fromBytes(bytes) {
|
|
253
|
-
const view =
|
|
254
|
-
bytes instanceof mol.Script
|
|
255
|
-
? bytes
|
|
256
|
-
: new mol.Script((0, bytes_1.bytesFrom)(bytes));
|
|
257
|
-
return new Script(
|
|
258
|
-
(0, hex_1.hexFrom)(view.getCodeHash().raw()),
|
|
259
|
-
hashTypeFromBytes([view.getHashType()]),
|
|
260
|
-
(0, hex_1.hexFrom)(view.getArgs().raw()),
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Compares the current Script instance with another ScriptLike object for equality.
|
|
265
|
-
*
|
|
266
|
-
* @param val - The ScriptLike object to compare with.
|
|
267
|
-
* @returns True if the scripts are equal, otherwise false.
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* const isEqual = script.eq(anotherScript);
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
eq(val) {
|
|
275
|
-
const script = Script.from(val);
|
|
276
|
-
return (
|
|
277
|
-
this.codeHash === script.codeHash &&
|
|
278
|
-
this.args === script.args &&
|
|
279
|
-
this.hashType === script.hashType
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
238
|
}
|
|
283
239
|
exports.Script = Script;
|
|
@@ -2,4 +2,4 @@ import { type DepType } from "./transaction";
|
|
|
2
2
|
export declare const DEP_TYPE_TO_NUM: Record<DepType, number>;
|
|
3
3
|
export declare const NUM_TO_DEP_TYPE: Record<number, DepType>;
|
|
4
4
|
export declare const DEP_TYPES: string[];
|
|
5
|
-
//# sourceMappingURL=transaction.advanced.d.ts.map
|
|
5
|
+
//# sourceMappingURL=transaction.advanced.d.ts.map
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEP_TYPES = exports.NUM_TO_DEP_TYPE = exports.DEP_TYPE_TO_NUM = void 0;
|
|
4
4
|
exports.DEP_TYPE_TO_NUM = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
code: 0x00,
|
|
6
|
+
depGroup: 0x01,
|
|
7
7
|
};
|
|
8
8
|
exports.NUM_TO_DEP_TYPE = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
0x00: "code",
|
|
10
|
+
0x01: "depGroup",
|
|
11
11
|
};
|
|
12
12
|
exports.DEP_TYPES = Object.keys(exports.DEP_TYPE_TO_NUM);
|