@ckb-ccc/core 0.0.2-alpha.1 → 0.0.2-alpha.3
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/.prettierignore +12 -0
- package/dist/address/address.advanced.d.ts +29 -3
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +69 -22
- package/dist/address/advanced.d.ts +1 -28
- package/dist/address/advanced.d.ts.map +1 -1
- package/dist/address/advanced.js +3 -61
- package/dist/address/index.d.ts +10 -13
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +18 -18
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +4 -2
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +4 -2
- package/dist/bytes/index.d.ts +7 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +41 -0
- package/dist/ckb/advanced.d.ts +3 -2
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +16 -2
- package/dist/ckb/index.d.ts +2 -3
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +2 -3
- package/dist/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +378 -97
- package/dist/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/index.js +8 -0
- package/dist/ckb/{types/script.advanced.d.ts → script.advanced.d.ts} +1 -0
- package/dist/ckb/script.advanced.d.ts.map +1 -0
- package/dist/ckb/{types/script.advanced.js → script.advanced.js} +2 -1
- package/dist/ckb/script.d.ts +29 -0
- package/dist/ckb/script.d.ts.map +1 -0
- package/dist/ckb/script.js +91 -0
- package/dist/ckb/{types/transaction.advanced.d.ts → transaction.advanced.d.ts} +1 -0
- package/dist/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist/ckb/{types/transaction.advanced.js → transaction.advanced.js} +2 -1
- package/dist/ckb/transaction.d.ts +142 -0
- package/dist/ckb/transaction.d.ts.map +1 -0
- package/dist/ckb/transaction.js +262 -0
- package/dist/client/client.d.ts +4 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.d.ts +2 -2
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +2 -2
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.d.ts +36 -36
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +11 -11
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +1 -1
- package/dist/fixedPoint/index.d.ts +7 -0
- package/dist/fixedPoint/index.d.ts.map +1 -0
- package/dist/{fixedPoint.js → fixedPoint/index.js} +9 -12
- package/dist/{ckb/hasher.advanced.d.ts → hasher/advanced.d.ts} +1 -1
- package/dist/hasher/advanced.d.ts.map +1 -0
- package/dist/{ckb/hasher.d.ts → hasher/index.d.ts} +3 -2
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/{ckb/hasher.js → hasher/index.js} +4 -4
- package/dist/hex/index.d.ts +5 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +9 -0
- package/dist/num/index.d.ts +13 -0
- package/dist/num/index.d.ts.map +1 -0
- package/dist/num/index.js +47 -0
- package/dist/signer/helpers.d.ts +3 -3
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +7 -4
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +2 -0
- package/dist/signer/signer.d.ts +12 -3
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +13 -2
- package/dist/signer/signerReadonly.d.ts +8 -0
- package/dist/signer/signerReadonly.d.ts.map +1 -0
- package/dist/signer/signerReadonly.js +13 -0
- package/dist/{ckb/viewerCkbScript.d.ts → signer/signerReadonlyCkbScript.d.ts} +6 -5
- package/dist/signer/signerReadonlyCkbScript.d.ts.map +1 -0
- package/dist/{ckb/viewerCkbScript.js → signer/signerReadonlyCkbScript.js} +7 -4
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/package.json +5 -3
- package/src/address/address.advanced.ts +76 -19
- package/src/address/advanced.ts +1 -59
- package/src/address/index.ts +46 -28
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +4 -2
- package/src/bytes/index.ts +46 -0
- package/src/ckb/advanced.ts +3 -2
- package/src/ckb/index.ts +2 -3
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +18 -7
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +551 -123
- package/src/ckb/molecule.advanced/index.ts +11 -0
- package/src/ckb/{types/script.advanced.ts → script.advanced.ts} +1 -0
- package/src/ckb/script.ts +94 -0
- package/src/ckb/{types/transaction.advanced.ts → transaction.advanced.ts} +1 -0
- package/src/ckb/transaction.ts +357 -0
- package/src/client/client.ts +4 -4
- package/src/client/clientPublicMainnet.advanced.ts +2 -2
- package/src/client/clientPublicMainnet.ts +2 -2
- package/src/client/clientPublicTestnet.advanced.ts +2 -2
- package/src/client/clientPublicTestnet.ts +2 -2
- package/src/client/clientTypes.ts +1 -1
- package/src/client/jsonRpc/advanced.ts +25 -25
- package/src/client/jsonRpc/index.ts +1 -3
- package/src/fixedPoint/index.ts +30 -0
- package/src/{ckb/hasher.ts → hasher/index.ts} +5 -5
- package/src/hex/index.ts +9 -0
- package/src/index.ts +1 -1
- package/src/num/index.ts +53 -0
- package/src/signer/helpers.ts +9 -6
- package/src/signer/index.ts +3 -1
- package/src/signer/signer.ts +23 -3
- package/src/signer/signerReadonly.ts +13 -0
- package/src/{ckb/viewerCkbScript.ts → signer/signerReadonlyCkbScript.ts} +8 -4
- package/src/utils/index.ts +28 -0
- package/dist/bytes.d.ts +0 -15
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -114
- package/dist/ckb/hasher.advanced.d.ts.map +0 -1
- package/dist/ckb/hasher.d.ts.map +0 -1
- package/dist/ckb/types/advanced.d.ts +0 -4
- package/dist/ckb/types/advanced.d.ts.map +0 -1
- package/dist/ckb/types/advanced.js +0 -32
- package/dist/ckb/types/index.d.ts +0 -3
- package/dist/ckb/types/index.d.ts.map +0 -1
- package/dist/ckb/types/index.js +0 -18
- package/dist/ckb/types/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.d.ts +0 -2
- package/dist/ckb/types/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/types/script.advanced.d.ts.map +0 -1
- package/dist/ckb/types/script.d.ts +0 -26
- package/dist/ckb/types/script.d.ts.map +0 -1
- package/dist/ckb/types/script.js +0 -75
- package/dist/ckb/types/transaction.advanced.d.ts.map +0 -1
- package/dist/ckb/types/transaction.d.ts +0 -127
- package/dist/ckb/types/transaction.d.ts.map +0 -1
- package/dist/ckb/types/transaction.js +0 -266
- package/dist/ckb/viewerCkbScript.d.ts.map +0 -1
- package/dist/fixedPoint.d.ts +0 -9
- package/dist/fixedPoint.d.ts.map +0 -1
- package/dist/primitive.d.ts +0 -5
- package/dist/primitive.d.ts.map +0 -1
- package/dist/primitive.js +0 -2
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/viewer.d.ts +0 -12
- package/dist/viewer.d.ts.map +0 -1
- package/dist/viewer.js +0 -19
- package/src/bytes.ts +0 -127
- package/src/ckb/types/advanced.ts +0 -3
- package/src/ckb/types/index.ts +0 -2
- package/src/ckb/types/molecule.advanced/index.ts +0 -1
- package/src/ckb/types/script.ts +0 -70
- package/src/ckb/types/transaction.ts +0 -366
- package/src/fixedPoint.ts +0 -53
- package/src/primitive.ts +0 -8
- package/src/viewer.ts +0 -22
- /package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +0 -0
- /package/dist/{ckb/hasher.advanced.js → hasher/advanced.js} +0 -0
- /package/src/ckb/{types/molecule.advanced → molecule.advanced}/blockchain.mol +0 -0
- /package/src/{ckb/hasher.advanced.ts → hasher/advanced.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ckb/molecule.advanced/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE;IAClC,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC,CAAC;CAChB,GAAG,CAAC,GAAG,SAAS,CAKhB"}
|
|
@@ -14,4 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.molOptional = void 0;
|
|
17
18
|
__exportStar(require("./generated"), exports);
|
|
19
|
+
function molOptional(mol) {
|
|
20
|
+
if (mol.hasValue()) {
|
|
21
|
+
return mol.value();
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
exports.molOptional = molOptional;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/script.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAKrD,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAKrD,CAAC;AACF,eAAO,MAAM,UAAU,EAAE,MAAM,EAAkC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NUM_TO_HASH_TYPE = exports.HASH_TYPE_TO_NUM = void 0;
|
|
3
|
+
exports.HASH_TYPES = exports.NUM_TO_HASH_TYPE = exports.HASH_TYPE_TO_NUM = void 0;
|
|
4
4
|
exports.HASH_TYPE_TO_NUM = {
|
|
5
5
|
type: 0x01,
|
|
6
6
|
data: 0x00,
|
|
@@ -13,3 +13,4 @@ exports.NUM_TO_HASH_TYPE = {
|
|
|
13
13
|
0x02: "data1",
|
|
14
14
|
0x04: "data2",
|
|
15
15
|
};
|
|
16
|
+
exports.HASH_TYPES = Object.keys(exports.HASH_TYPE_TO_NUM);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Bytes, BytesLike } from "../bytes";
|
|
2
|
+
import { Hex } from "../hex";
|
|
3
|
+
import * as mol from "./molecule.advanced";
|
|
4
|
+
export type HashTypeLike = string | number | bigint;
|
|
5
|
+
export type HashType = "type" | "data" | "data1" | "data2";
|
|
6
|
+
export declare function hashTypeFrom(val: HashTypeLike): HashType;
|
|
7
|
+
export declare function hashTypeToBytes(hashType: HashType): Bytes;
|
|
8
|
+
export declare function hashTypeFromBytes(bytes: BytesLike): HashType;
|
|
9
|
+
export type ScriptLike = {
|
|
10
|
+
codeHash: BytesLike;
|
|
11
|
+
hashType: HashTypeLike;
|
|
12
|
+
args: BytesLike;
|
|
13
|
+
};
|
|
14
|
+
export declare class Script {
|
|
15
|
+
codeHash: Hex;
|
|
16
|
+
hashType: HashType;
|
|
17
|
+
args: Hex;
|
|
18
|
+
constructor(codeHash: Hex, hashType: HashType, args: Hex);
|
|
19
|
+
static from(script: ScriptLike): Script;
|
|
20
|
+
_toMolData(): {
|
|
21
|
+
codeHash: Uint8Array;
|
|
22
|
+
hashType: Uint8Array;
|
|
23
|
+
args: Uint8Array;
|
|
24
|
+
};
|
|
25
|
+
toBytes(): Bytes;
|
|
26
|
+
static fromBytes(bytes: BytesLike | mol.Script): Script;
|
|
27
|
+
eq(val: ScriptLike): boolean;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../src/ckb/script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,GAAG,EAAW,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAO3C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAC3D,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,QAAQ,CAmBxD;AACD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAEzD;AACD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,CAE5D;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AACF,qBAAa,MAAM;IAER,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,GAAG;gBAFT,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,GAAG;IAGlB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAYvC,UAAU;;;;;IAQV,OAAO,IAAI,KAAK;IAIhB,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAC,MAAM,GAAG,MAAM;IAWvD,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO;CAQ7B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Script = exports.hashTypeFromBytes = exports.hashTypeToBytes = exports.hashTypeFrom = void 0;
|
|
27
|
+
const bytes_1 = require("../bytes");
|
|
28
|
+
const hex_1 = require("../hex");
|
|
29
|
+
const mol = __importStar(require("./molecule.advanced"));
|
|
30
|
+
const script_advanced_1 = require("./script.advanced");
|
|
31
|
+
function hashTypeFrom(val) {
|
|
32
|
+
const hashType = (() => {
|
|
33
|
+
if (typeof val === "number") {
|
|
34
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[val];
|
|
35
|
+
}
|
|
36
|
+
if (typeof val === "bigint") {
|
|
37
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[Number(val)];
|
|
38
|
+
}
|
|
39
|
+
if (!script_advanced_1.HASH_TYPES.includes(val)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return val;
|
|
43
|
+
})();
|
|
44
|
+
if (hashType === undefined) {
|
|
45
|
+
throw new Error(`Invalid hash type ${val}`);
|
|
46
|
+
}
|
|
47
|
+
return hashType;
|
|
48
|
+
}
|
|
49
|
+
exports.hashTypeFrom = hashTypeFrom;
|
|
50
|
+
function hashTypeToBytes(hashType) {
|
|
51
|
+
return (0, bytes_1.bytesFrom)([script_advanced_1.HASH_TYPE_TO_NUM[hashType]]);
|
|
52
|
+
}
|
|
53
|
+
exports.hashTypeToBytes = hashTypeToBytes;
|
|
54
|
+
function hashTypeFromBytes(bytes) {
|
|
55
|
+
return script_advanced_1.NUM_TO_HASH_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
|
|
56
|
+
}
|
|
57
|
+
exports.hashTypeFromBytes = hashTypeFromBytes;
|
|
58
|
+
class Script {
|
|
59
|
+
constructor(codeHash, hashType, args) {
|
|
60
|
+
this.codeHash = codeHash;
|
|
61
|
+
this.hashType = hashType;
|
|
62
|
+
this.args = args;
|
|
63
|
+
}
|
|
64
|
+
static from(script) {
|
|
65
|
+
if (script instanceof Script) {
|
|
66
|
+
return script;
|
|
67
|
+
}
|
|
68
|
+
return new Script((0, hex_1.hexFrom)(script.codeHash), hashTypeFrom(script.hashType), (0, hex_1.hexFrom)(script.args));
|
|
69
|
+
}
|
|
70
|
+
_toMolData() {
|
|
71
|
+
return {
|
|
72
|
+
codeHash: (0, bytes_1.bytesFrom)(this.codeHash),
|
|
73
|
+
hashType: hashTypeToBytes(this.hashType),
|
|
74
|
+
args: (0, bytes_1.bytesFrom)(this.args),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
toBytes() {
|
|
78
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeScript(this._toMolData()));
|
|
79
|
+
}
|
|
80
|
+
static fromBytes(bytes) {
|
|
81
|
+
const view = bytes instanceof mol.Script ? bytes : new mol.Script((0, bytes_1.bytesFrom)(bytes));
|
|
82
|
+
return new Script((0, hex_1.hexFrom)(view.getCodeHash().raw()), hashTypeFromBytes([view.getHashType()]), (0, hex_1.hexFrom)(view.getArgs().raw()));
|
|
83
|
+
}
|
|
84
|
+
eq(val) {
|
|
85
|
+
const script = Script.from(val);
|
|
86
|
+
return (this.codeHash === script.codeHash &&
|
|
87
|
+
this.args === script.args &&
|
|
88
|
+
this.hashType === script.hashType);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.Script = Script;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
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
|
+
export declare const DEP_TYPES: string[];
|
|
4
5
|
//# sourceMappingURL=transaction.advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/transaction.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAGnD,CAAC;AACF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAGnD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,EAAiC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NUM_TO_DEP_TYPE = exports.DEP_TYPE_TO_NUM = void 0;
|
|
3
|
+
exports.DEP_TYPES = exports.NUM_TO_DEP_TYPE = exports.DEP_TYPE_TO_NUM = void 0;
|
|
4
4
|
exports.DEP_TYPE_TO_NUM = {
|
|
5
5
|
code: 0x00,
|
|
6
6
|
depGroup: 0x01,
|
|
@@ -9,3 +9,4 @@ exports.NUM_TO_DEP_TYPE = {
|
|
|
9
9
|
0x00: "code",
|
|
10
10
|
0x01: "depGroup",
|
|
11
11
|
};
|
|
12
|
+
exports.DEP_TYPES = Object.keys(exports.DEP_TYPE_TO_NUM);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { TransactionSkeletonType } from "@ckb-lumos/helpers";
|
|
2
|
+
import { Bytes, BytesLike } from "../bytes";
|
|
3
|
+
import { Hasher } from "../hasher";
|
|
4
|
+
import { Hex, HexLike } from "../hex";
|
|
5
|
+
import { Num, NumLike } from "../num";
|
|
6
|
+
import * as mol from "./molecule.advanced";
|
|
7
|
+
import { Script, ScriptLike } from "./script";
|
|
8
|
+
export type DepTypeLike = string | number | bigint;
|
|
9
|
+
export type DepType = "depGroup" | "code";
|
|
10
|
+
export declare function depTypeFrom(val: DepTypeLike): DepType;
|
|
11
|
+
export declare function depTypeToBytes(depType: DepType): Bytes;
|
|
12
|
+
export declare function depTypeFromBytes(bytes: BytesLike): DepType;
|
|
13
|
+
export type OutPointLike = {
|
|
14
|
+
txHash: HexLike;
|
|
15
|
+
index: NumLike;
|
|
16
|
+
};
|
|
17
|
+
export declare class OutPoint {
|
|
18
|
+
txHash: Hex;
|
|
19
|
+
index: Num;
|
|
20
|
+
constructor(txHash: Hex, index: Num);
|
|
21
|
+
static from(outPoint: OutPointLike): OutPoint;
|
|
22
|
+
_toMolData(): {
|
|
23
|
+
txHash: Uint8Array;
|
|
24
|
+
index: Uint8Array;
|
|
25
|
+
};
|
|
26
|
+
encode(): Bytes;
|
|
27
|
+
static fromBytes(bytes: BytesLike | mol.OutPoint): OutPoint;
|
|
28
|
+
}
|
|
29
|
+
export type CellOutputLike = {
|
|
30
|
+
capacity: NumLike;
|
|
31
|
+
lock: ScriptLike;
|
|
32
|
+
type?: ScriptLike;
|
|
33
|
+
};
|
|
34
|
+
export declare class CellOutput {
|
|
35
|
+
capacity: Num;
|
|
36
|
+
lock: Script;
|
|
37
|
+
type?: Script | undefined;
|
|
38
|
+
constructor(capacity: Num, lock: Script, type?: Script | undefined);
|
|
39
|
+
static from(cellOutput: CellOutputLike): CellOutput;
|
|
40
|
+
_toMolData(): {
|
|
41
|
+
capacity: Uint8Array;
|
|
42
|
+
lock: {
|
|
43
|
+
codeHash: Uint8Array;
|
|
44
|
+
hashType: Uint8Array;
|
|
45
|
+
args: Uint8Array;
|
|
46
|
+
};
|
|
47
|
+
type: {
|
|
48
|
+
codeHash: Uint8Array;
|
|
49
|
+
hashType: Uint8Array;
|
|
50
|
+
args: Uint8Array;
|
|
51
|
+
} | undefined;
|
|
52
|
+
};
|
|
53
|
+
toBytes(): Bytes;
|
|
54
|
+
static fromBytes(bytes: BytesLike | mol.CellOutput): CellOutput;
|
|
55
|
+
}
|
|
56
|
+
export type CellInputLike = {
|
|
57
|
+
previousOutput: OutPointLike;
|
|
58
|
+
since: NumLike;
|
|
59
|
+
cellOutput?: CellOutputLike;
|
|
60
|
+
outputData?: HexLike;
|
|
61
|
+
};
|
|
62
|
+
export declare class CellInput {
|
|
63
|
+
previousOutput: OutPoint;
|
|
64
|
+
since: Num;
|
|
65
|
+
cellOutput?: CellOutput | undefined;
|
|
66
|
+
outputData?: `0x${string}` | undefined;
|
|
67
|
+
constructor(previousOutput: OutPoint, since: Num, cellOutput?: CellOutput | undefined, outputData?: `0x${string}` | undefined);
|
|
68
|
+
static from(cellInput: CellInputLike): CellInput;
|
|
69
|
+
_toMolData(): {
|
|
70
|
+
previousOutput: {
|
|
71
|
+
txHash: Uint8Array;
|
|
72
|
+
index: Uint8Array;
|
|
73
|
+
};
|
|
74
|
+
since: Uint8Array;
|
|
75
|
+
};
|
|
76
|
+
toBytes(): Bytes;
|
|
77
|
+
static fromBytes(bytes: BytesLike | mol.CellInput): CellInput;
|
|
78
|
+
}
|
|
79
|
+
export type CellDepLike = {
|
|
80
|
+
outPoint: OutPointLike;
|
|
81
|
+
depType: DepTypeLike;
|
|
82
|
+
};
|
|
83
|
+
export declare class CellDep {
|
|
84
|
+
outPoint: OutPoint;
|
|
85
|
+
depType: DepType;
|
|
86
|
+
constructor(outPoint: OutPoint, depType: DepType);
|
|
87
|
+
static from(cellDep: CellDepLike): CellDep;
|
|
88
|
+
_toMolData(): {
|
|
89
|
+
outPoint: {
|
|
90
|
+
txHash: Uint8Array;
|
|
91
|
+
index: Uint8Array;
|
|
92
|
+
};
|
|
93
|
+
depType: Uint8Array;
|
|
94
|
+
};
|
|
95
|
+
toBytes(): Bytes;
|
|
96
|
+
fromBytes(bytes: BytesLike | mol.CellDep): CellDep;
|
|
97
|
+
}
|
|
98
|
+
export type WitnessArgsLike = {
|
|
99
|
+
lock?: HexLike;
|
|
100
|
+
inputType?: HexLike;
|
|
101
|
+
outputType?: HexLike;
|
|
102
|
+
};
|
|
103
|
+
export declare class WitnessArgs {
|
|
104
|
+
lock?: `0x${string}` | undefined;
|
|
105
|
+
inputType?: `0x${string}` | undefined;
|
|
106
|
+
outputType?: `0x${string}` | undefined;
|
|
107
|
+
constructor(lock?: `0x${string}` | undefined, inputType?: `0x${string}` | undefined, outputType?: `0x${string}` | undefined);
|
|
108
|
+
static from(witnessArgs: WitnessArgsLike): WitnessArgs;
|
|
109
|
+
_toMolData(): {
|
|
110
|
+
lock: Uint8Array | undefined;
|
|
111
|
+
inputType: Uint8Array | undefined;
|
|
112
|
+
outputType: Uint8Array | undefined;
|
|
113
|
+
};
|
|
114
|
+
toBytes(): Bytes;
|
|
115
|
+
static fromBytes(bytes: BytesLike | mol.WitnessArgs): WitnessArgs;
|
|
116
|
+
}
|
|
117
|
+
export type TransactionLike = {
|
|
118
|
+
version: NumLike;
|
|
119
|
+
cellDeps: CellDepLike[];
|
|
120
|
+
headerDeps: HexLike[];
|
|
121
|
+
inputs: CellInputLike[];
|
|
122
|
+
outputs: CellOutputLike[];
|
|
123
|
+
outputsData: HexLike[];
|
|
124
|
+
witnesses: HexLike[];
|
|
125
|
+
};
|
|
126
|
+
export declare class Transaction {
|
|
127
|
+
version: Num;
|
|
128
|
+
cellDeps: CellDep[];
|
|
129
|
+
headerDeps: Hex[];
|
|
130
|
+
inputs: CellInput[];
|
|
131
|
+
outputs: CellOutput[];
|
|
132
|
+
outputsData: Hex[];
|
|
133
|
+
witnesses: Hex[];
|
|
134
|
+
constructor(version: Num, cellDeps: CellDep[], headerDeps: Hex[], inputs: CellInput[], outputs: CellOutput[], outputsData: Hex[], witnesses: Hex[]);
|
|
135
|
+
static default(): Transaction;
|
|
136
|
+
static from(tx: TransactionLike): Transaction;
|
|
137
|
+
static fromLumosSkeleton(skeleton: TransactionSkeletonType): Transaction;
|
|
138
|
+
rawToBytes(): Bytes;
|
|
139
|
+
hash(): `0x${string}`;
|
|
140
|
+
static hashWitnessToHasher(witness: HexLike, hasher: Hasher): void;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/ckb/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,MAAM,EAAW,MAAM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O,IAAI,WAAW;IAI7B,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,eAAe,GAAG,WAAW;IAgB7C,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,WAAW;IAuBxE,UAAU,IAAI,KAAK;IAanB,IAAI;IAIJ,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;CAK5D"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Transaction = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.CellOutput = exports.OutPoint = exports.depTypeFromBytes = exports.depTypeToBytes = exports.depTypeFrom = void 0;
|
|
27
|
+
const bytes_1 = require("../bytes");
|
|
28
|
+
const hasher_1 = require("../hasher");
|
|
29
|
+
const hex_1 = require("../hex");
|
|
30
|
+
const num_1 = require("../num");
|
|
31
|
+
const utils_1 = require("../utils");
|
|
32
|
+
const mol = __importStar(require("./molecule.advanced"));
|
|
33
|
+
const script_1 = require("./script");
|
|
34
|
+
const transaction_advanced_1 = require("./transaction.advanced");
|
|
35
|
+
function depTypeFrom(val) {
|
|
36
|
+
const depType = (() => {
|
|
37
|
+
if (typeof val === "number") {
|
|
38
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
|
|
39
|
+
}
|
|
40
|
+
if (typeof val === "bigint") {
|
|
41
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
|
|
42
|
+
}
|
|
43
|
+
return val;
|
|
44
|
+
})();
|
|
45
|
+
if (depType === undefined) {
|
|
46
|
+
throw new Error(`Invalid dep type ${val}`);
|
|
47
|
+
}
|
|
48
|
+
return depType;
|
|
49
|
+
}
|
|
50
|
+
exports.depTypeFrom = depTypeFrom;
|
|
51
|
+
function depTypeToBytes(depType) {
|
|
52
|
+
return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depType]]);
|
|
53
|
+
}
|
|
54
|
+
exports.depTypeToBytes = depTypeToBytes;
|
|
55
|
+
function depTypeFromBytes(bytes) {
|
|
56
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
|
|
57
|
+
}
|
|
58
|
+
exports.depTypeFromBytes = depTypeFromBytes;
|
|
59
|
+
class OutPoint {
|
|
60
|
+
constructor(txHash, index) {
|
|
61
|
+
this.txHash = txHash;
|
|
62
|
+
this.index = index;
|
|
63
|
+
}
|
|
64
|
+
static from(outPoint) {
|
|
65
|
+
if (outPoint instanceof OutPoint) {
|
|
66
|
+
return outPoint;
|
|
67
|
+
}
|
|
68
|
+
return new OutPoint((0, hex_1.hexFrom)(outPoint.txHash), (0, num_1.numFrom)(outPoint.index));
|
|
69
|
+
}
|
|
70
|
+
_toMolData() {
|
|
71
|
+
return {
|
|
72
|
+
txHash: (0, bytes_1.bytesFrom)(this.txHash),
|
|
73
|
+
index: (0, num_1.numToBytes)(this.index, 4),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
encode() {
|
|
77
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
|
|
78
|
+
}
|
|
79
|
+
static fromBytes(bytes) {
|
|
80
|
+
const view = bytes instanceof mol.OutPoint
|
|
81
|
+
? bytes
|
|
82
|
+
: new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
|
|
83
|
+
return new OutPoint((0, hex_1.hexFrom)(view.getTxHash().raw()), (0, num_1.numFromBytes)(view.getIndex().raw()));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.OutPoint = OutPoint;
|
|
87
|
+
class CellOutput {
|
|
88
|
+
constructor(capacity, lock, type) {
|
|
89
|
+
this.capacity = capacity;
|
|
90
|
+
this.lock = lock;
|
|
91
|
+
this.type = type;
|
|
92
|
+
}
|
|
93
|
+
static from(cellOutput) {
|
|
94
|
+
if (cellOutput instanceof CellOutput) {
|
|
95
|
+
return cellOutput;
|
|
96
|
+
}
|
|
97
|
+
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));
|
|
98
|
+
}
|
|
99
|
+
_toMolData() {
|
|
100
|
+
return {
|
|
101
|
+
capacity: (0, num_1.numToBytes)(this.capacity, 8),
|
|
102
|
+
lock: this.lock._toMolData(),
|
|
103
|
+
type: this.type?._toMolData(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
toBytes() {
|
|
107
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
|
|
108
|
+
}
|
|
109
|
+
static fromBytes(bytes) {
|
|
110
|
+
const view = bytes instanceof mol.CellOutput
|
|
111
|
+
? bytes
|
|
112
|
+
: new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
|
|
113
|
+
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())));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.CellOutput = CellOutput;
|
|
117
|
+
class CellInput {
|
|
118
|
+
constructor(previousOutput, since, cellOutput, outputData) {
|
|
119
|
+
this.previousOutput = previousOutput;
|
|
120
|
+
this.since = since;
|
|
121
|
+
this.cellOutput = cellOutput;
|
|
122
|
+
this.outputData = outputData;
|
|
123
|
+
}
|
|
124
|
+
static from(cellInput) {
|
|
125
|
+
if (cellInput instanceof CellInput) {
|
|
126
|
+
return cellInput;
|
|
127
|
+
}
|
|
128
|
+
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));
|
|
129
|
+
}
|
|
130
|
+
_toMolData() {
|
|
131
|
+
return {
|
|
132
|
+
previousOutput: this.previousOutput._toMolData(),
|
|
133
|
+
since: (0, num_1.numToBytes)(this.since, 8),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
toBytes() {
|
|
137
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
|
|
138
|
+
}
|
|
139
|
+
static fromBytes(bytes) {
|
|
140
|
+
const view = bytes instanceof mol.CellInput
|
|
141
|
+
? bytes
|
|
142
|
+
: new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
|
|
143
|
+
return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.CellInput = CellInput;
|
|
147
|
+
class CellDep {
|
|
148
|
+
constructor(outPoint, depType) {
|
|
149
|
+
this.outPoint = outPoint;
|
|
150
|
+
this.depType = depType;
|
|
151
|
+
}
|
|
152
|
+
static from(cellDep) {
|
|
153
|
+
if (cellDep instanceof CellDep) {
|
|
154
|
+
return cellDep;
|
|
155
|
+
}
|
|
156
|
+
return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
157
|
+
}
|
|
158
|
+
_toMolData() {
|
|
159
|
+
return {
|
|
160
|
+
outPoint: this.outPoint._toMolData(),
|
|
161
|
+
depType: depTypeToBytes(this.depType),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
toBytes() {
|
|
165
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
|
|
166
|
+
}
|
|
167
|
+
fromBytes(bytes) {
|
|
168
|
+
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
|
|
169
|
+
return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.CellDep = CellDep;
|
|
173
|
+
class WitnessArgs {
|
|
174
|
+
constructor(lock, inputType, outputType) {
|
|
175
|
+
this.lock = lock;
|
|
176
|
+
this.inputType = inputType;
|
|
177
|
+
this.outputType = outputType;
|
|
178
|
+
}
|
|
179
|
+
static from(witnessArgs) {
|
|
180
|
+
if (witnessArgs instanceof WitnessArgs) {
|
|
181
|
+
return witnessArgs;
|
|
182
|
+
}
|
|
183
|
+
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));
|
|
184
|
+
}
|
|
185
|
+
_toMolData() {
|
|
186
|
+
return {
|
|
187
|
+
lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
|
|
188
|
+
inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
|
|
189
|
+
outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
toBytes() {
|
|
193
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
|
|
194
|
+
}
|
|
195
|
+
static fromBytes(bytes) {
|
|
196
|
+
const view = bytes instanceof mol.WitnessArgs
|
|
197
|
+
? bytes
|
|
198
|
+
: new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
|
|
199
|
+
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()));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.WitnessArgs = WitnessArgs;
|
|
203
|
+
class Transaction {
|
|
204
|
+
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
205
|
+
this.version = version;
|
|
206
|
+
this.cellDeps = cellDeps;
|
|
207
|
+
this.headerDeps = headerDeps;
|
|
208
|
+
this.inputs = inputs;
|
|
209
|
+
this.outputs = outputs;
|
|
210
|
+
this.outputsData = outputsData;
|
|
211
|
+
this.witnesses = witnesses;
|
|
212
|
+
}
|
|
213
|
+
static default() {
|
|
214
|
+
return new Transaction(0n, [], [], [], [], [], []);
|
|
215
|
+
}
|
|
216
|
+
static from(tx) {
|
|
217
|
+
if (tx instanceof Transaction) {
|
|
218
|
+
return tx;
|
|
219
|
+
}
|
|
220
|
+
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));
|
|
221
|
+
}
|
|
222
|
+
static fromLumosSkeleton(skeleton) {
|
|
223
|
+
return Transaction.from({
|
|
224
|
+
version: 0n,
|
|
225
|
+
cellDeps: skeleton.cellDeps.toArray(),
|
|
226
|
+
headerDeps: skeleton.headerDeps.toArray(),
|
|
227
|
+
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
228
|
+
if (!input.outPoint) {
|
|
229
|
+
throw new Error("outPoint is required in input");
|
|
230
|
+
}
|
|
231
|
+
return CellInput.from({
|
|
232
|
+
previousOutput: input.outPoint,
|
|
233
|
+
since: skeleton.inputSinces.get(i, "0x0"),
|
|
234
|
+
cellOutput: input.cellOutput,
|
|
235
|
+
outputData: input.data,
|
|
236
|
+
});
|
|
237
|
+
}),
|
|
238
|
+
outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
|
|
239
|
+
outputsData: skeleton.outputs.toArray().map((output) => output.data),
|
|
240
|
+
witnesses: skeleton.witnesses.toArray(),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
rawToBytes() {
|
|
244
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
|
|
245
|
+
version: (0, num_1.numToBytes)(this.version, 4),
|
|
246
|
+
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
247
|
+
headerDeps: this.headerDeps.map(bytes_1.bytesFrom),
|
|
248
|
+
inputs: this.inputs.map((i) => i._toMolData()),
|
|
249
|
+
outputs: this.outputs.map((o) => o._toMolData()),
|
|
250
|
+
outputsData: this.outputsData.map(bytes_1.bytesFrom),
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
hash() {
|
|
254
|
+
return (0, hasher_1.ckbHash)(this.rawToBytes());
|
|
255
|
+
}
|
|
256
|
+
static hashWitnessToHasher(witness, hasher) {
|
|
257
|
+
const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
|
|
258
|
+
hasher.update((0, num_1.numToBytes)(raw.length, 8));
|
|
259
|
+
hasher.update(raw);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.Transaction = Transaction;
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ScriptLike, TransactionLike } from "../ckb";
|
|
2
|
+
import { Hex } from "../hex";
|
|
3
3
|
import { OutputsValidator } from "./clientTypes";
|
|
4
4
|
export declare enum KnownScript {
|
|
5
5
|
Secp256k1Blake160 = 0,
|
|
@@ -10,7 +10,7 @@ export declare enum KnownScript {
|
|
|
10
10
|
}
|
|
11
11
|
export interface Client {
|
|
12
12
|
getAddressPrefix(): Promise<string>;
|
|
13
|
-
getKnownScript(script: KnownScript): Promise<Omit<
|
|
14
|
-
sendTransaction(transaction:
|
|
13
|
+
getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
|
|
14
|
+
sendTransaction(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,oBAAY,WAAW;IACrB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;IACjB,YAAY,IAAA;IACZ,KAAK,IAAA;IACL,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,MAAM;IACrB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvE,eAAe,CACb,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ScriptLike } from "../ckb";
|
|
2
2
|
import { KnownScript } from "./client";
|
|
3
|
-
export declare const MAINNET_SCRIPTS: Record<KnownScript, Omit<
|
|
3
|
+
export declare const MAINNET_SCRIPTS: Record<KnownScript, Omit<ScriptLike, "args">>;
|
|
4
4
|
//# sourceMappingURL=clientPublicMainnet.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CA0BzE,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ScriptLike } from "../ckb";
|
|
2
2
|
import { KnownScript } from "./client";
|
|
3
3
|
import { ClientJsonRpc } from "./jsonRpc";
|
|
4
4
|
export declare class ClientPublicMainnet extends ClientJsonRpc {
|
|
5
5
|
constructor(timeout?: number);
|
|
6
6
|
getAddressPrefix(): Promise<string>;
|
|
7
|
-
getKnownScript(script: KnownScript): Promise<Omit<
|
|
7
|
+
getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=clientPublicMainnet.d.ts.map
|