@ckb-ccc/core 0.1.0-alpha.6 → 0.1.0-alpha.7
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/CHANGELOG.md +7 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/molecule/codec.d.ts +118 -0
- package/dist/molecule/codec.d.ts.map +1 -0
- package/dist/molecule/codec.js +446 -0
- package/dist/molecule/index.d.ts +3 -0
- package/dist/molecule/index.d.ts.map +1 -0
- package/dist/molecule/index.js +2 -0
- package/dist/molecule/predefined.d.ts +52 -0
- package/dist/molecule/predefined.d.ts.map +1 -0
- package/dist/molecule/predefined.js +95 -0
- package/dist.commonjs/barrel.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +14 -0
- package/dist.commonjs/molecule/codec.d.ts +118 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -0
- package/dist.commonjs/molecule/codec.js +461 -0
- package/dist.commonjs/molecule/index.d.ts +3 -0
- package/dist.commonjs/molecule/index.d.ts.map +1 -0
- package/dist.commonjs/molecule/index.js +18 -0
- package/dist.commonjs/molecule/predefined.d.ts +52 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -0
- package/dist.commonjs/molecule/predefined.js +121 -0
- package/package.json +1 -1
- package/src/barrel.ts +1 -0
- package/src/molecule/codec.ts +610 -0
- package/src/molecule/index.ts +2 -0
- package/src/molecule/predefined.ts +114 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { bytesFrom, bytesTo } from "../bytes/index.js";
|
|
2
|
+
import * as ckb from "../ckb/index.js";
|
|
3
|
+
import { Hex, hexFrom, HexLike } from "../hex/index.js";
|
|
4
|
+
import {
|
|
5
|
+
byteVec,
|
|
6
|
+
Codec,
|
|
7
|
+
option,
|
|
8
|
+
struct,
|
|
9
|
+
table,
|
|
10
|
+
uint,
|
|
11
|
+
uintNumber,
|
|
12
|
+
vector,
|
|
13
|
+
} from "./codec.js";
|
|
14
|
+
|
|
15
|
+
export const Uint8 = uintNumber(1, true);
|
|
16
|
+
export const Uint16LE = uintNumber(2, true);
|
|
17
|
+
export const Uint16BE = uintNumber(2);
|
|
18
|
+
export const Uint16 = Uint16LE;
|
|
19
|
+
export const Uint32LE = uintNumber(4, true);
|
|
20
|
+
export const Uint32BE = uintNumber(4);
|
|
21
|
+
export const Uint32 = Uint32LE;
|
|
22
|
+
export const Uint64LE = uint(8, true);
|
|
23
|
+
export const Uint64BE = uint(8);
|
|
24
|
+
export const Uint64 = Uint64LE;
|
|
25
|
+
export const Uint128LE = uint(16, true);
|
|
26
|
+
export const Uint128BE = uint(16);
|
|
27
|
+
export const Uint128 = Uint128LE;
|
|
28
|
+
export const Uint256LE = uint(32, true);
|
|
29
|
+
export const Uint256BE = uint(32);
|
|
30
|
+
export const Uint256 = Uint256LE;
|
|
31
|
+
export const Uint512LE = uint(64, true);
|
|
32
|
+
export const Uint512BE = uint(64);
|
|
33
|
+
export const Uint512 = Uint512LE;
|
|
34
|
+
|
|
35
|
+
export const Uint8Opt = option(Uint8);
|
|
36
|
+
export const Uint16Opt = option(Uint16);
|
|
37
|
+
export const Uint32Opt = option(Uint32);
|
|
38
|
+
export const Uint64Opt = option(Uint64);
|
|
39
|
+
export const Uint128Opt = option(Uint128);
|
|
40
|
+
export const Uint256Opt = option(Uint256);
|
|
41
|
+
export const Uint512Opt = option(Uint512);
|
|
42
|
+
|
|
43
|
+
export const Bytes: Codec<HexLike, Hex> = byteVec({
|
|
44
|
+
encode: (value) => bytesFrom(value),
|
|
45
|
+
decode: (buffer) => hexFrom(buffer),
|
|
46
|
+
});
|
|
47
|
+
export const BytesOpt = option(Bytes);
|
|
48
|
+
export const BytesVec = vector(Bytes);
|
|
49
|
+
|
|
50
|
+
export const Byte32: Codec<HexLike, Hex> = Codec.from({
|
|
51
|
+
byteLength: 32,
|
|
52
|
+
encode: (value) => bytesFrom(value),
|
|
53
|
+
decode: (buffer) => hexFrom(buffer),
|
|
54
|
+
});
|
|
55
|
+
export const Byte32Opt = option(Byte32);
|
|
56
|
+
export const Byte32Vec = vector(Byte32);
|
|
57
|
+
|
|
58
|
+
export const String = byteVec({
|
|
59
|
+
encode: (value: string) => bytesFrom(value, "utf8"),
|
|
60
|
+
decode: (buffer) => bytesTo(buffer, "utf8"),
|
|
61
|
+
});
|
|
62
|
+
export const StringVec = vector(String);
|
|
63
|
+
export const StringOpt = option(String);
|
|
64
|
+
|
|
65
|
+
export const Hash = Byte32;
|
|
66
|
+
export const HashType: Codec<ckb.HashTypeLike, ckb.HashType> = Codec.from({
|
|
67
|
+
byteLength: 1,
|
|
68
|
+
encode: ckb.hashTypeToBytes,
|
|
69
|
+
decode: ckb.hashTypeFromBytes,
|
|
70
|
+
});
|
|
71
|
+
export const Script: Codec<ckb.ScriptLike, ckb.Script> = table({
|
|
72
|
+
codeHash: Hash,
|
|
73
|
+
hashType: HashType,
|
|
74
|
+
args: Bytes,
|
|
75
|
+
}).map({ outMap: ckb.Script.from });
|
|
76
|
+
export const ScriptOpt = option(Script);
|
|
77
|
+
|
|
78
|
+
export const OutPoint: Codec<ckb.OutPointLike, ckb.OutPoint> = struct({
|
|
79
|
+
txHash: Hash,
|
|
80
|
+
index: Uint32,
|
|
81
|
+
}).map({ outMap: ckb.OutPoint.from });
|
|
82
|
+
export const CellInput: Codec<ckb.CellInputLike, ckb.CellInput> = struct({
|
|
83
|
+
previousOutput: OutPoint,
|
|
84
|
+
since: Uint64,
|
|
85
|
+
}).map({ outMap: ckb.CellInput.from });
|
|
86
|
+
export const CellInputVec = vector(CellInput);
|
|
87
|
+
|
|
88
|
+
export const CellOutput: Codec<ckb.CellOutputLike, ckb.CellOutput> = table({
|
|
89
|
+
capacity: Uint64,
|
|
90
|
+
lock: Script,
|
|
91
|
+
type: ScriptOpt,
|
|
92
|
+
}).map({ outMap: ckb.CellOutput.from });
|
|
93
|
+
export const CellOutputVec = vector(CellOutput);
|
|
94
|
+
|
|
95
|
+
export const DepType: Codec<ckb.DepTypeLike, ckb.DepType> = Codec.from({
|
|
96
|
+
byteLength: 1,
|
|
97
|
+
encode: ckb.depTypeToBytes,
|
|
98
|
+
decode: ckb.depTypeFromBytes,
|
|
99
|
+
});
|
|
100
|
+
export const CellDep: Codec<ckb.CellDepLike, ckb.CellDep> = struct({
|
|
101
|
+
outPoint: OutPoint,
|
|
102
|
+
depType: DepType,
|
|
103
|
+
}).map({ outMap: ckb.CellDep.from });
|
|
104
|
+
export const CellDepVec = vector(CellDep);
|
|
105
|
+
|
|
106
|
+
export const Transaction: Codec<ckb.TransactionLike, ckb.Transaction> = table({
|
|
107
|
+
version: Uint32,
|
|
108
|
+
cellDeps: CellDepVec,
|
|
109
|
+
headerDeps: Byte32Vec,
|
|
110
|
+
inputs: CellInputVec,
|
|
111
|
+
outputs: CellOutputVec,
|
|
112
|
+
outputsData: BytesVec,
|
|
113
|
+
witnesses: BytesVec,
|
|
114
|
+
}).map({ outMap: ckb.Transaction.from });
|