@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,52 @@
|
|
|
1
|
+
import * as ckb from "../ckb/index.js";
|
|
2
|
+
import { Hex, HexLike } from "../hex/index.js";
|
|
3
|
+
import { Codec } from "./codec.js";
|
|
4
|
+
export declare const Uint8: Codec<import("../barrel.js").NumLike, number>;
|
|
5
|
+
export declare const Uint16LE: Codec<import("../barrel.js").NumLike, number>;
|
|
6
|
+
export declare const Uint16BE: Codec<import("../barrel.js").NumLike, number>;
|
|
7
|
+
export declare const Uint16: Codec<import("../barrel.js").NumLike, number>;
|
|
8
|
+
export declare const Uint32LE: Codec<import("../barrel.js").NumLike, number>;
|
|
9
|
+
export declare const Uint32BE: Codec<import("../barrel.js").NumLike, number>;
|
|
10
|
+
export declare const Uint32: Codec<import("../barrel.js").NumLike, number>;
|
|
11
|
+
export declare const Uint64LE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
12
|
+
export declare const Uint64BE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
13
|
+
export declare const Uint64: Codec<import("../barrel.js").NumLike, bigint>;
|
|
14
|
+
export declare const Uint128LE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
15
|
+
export declare const Uint128BE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
16
|
+
export declare const Uint128: Codec<import("../barrel.js").NumLike, bigint>;
|
|
17
|
+
export declare const Uint256LE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
18
|
+
export declare const Uint256BE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
19
|
+
export declare const Uint256: Codec<import("../barrel.js").NumLike, bigint>;
|
|
20
|
+
export declare const Uint512LE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
21
|
+
export declare const Uint512BE: Codec<import("../barrel.js").NumLike, bigint>;
|
|
22
|
+
export declare const Uint512: Codec<import("../barrel.js").NumLike, bigint>;
|
|
23
|
+
export declare const Uint8Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
|
|
24
|
+
export declare const Uint16Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
|
|
25
|
+
export declare const Uint32Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
|
|
26
|
+
export declare const Uint64Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
|
|
27
|
+
export declare const Uint128Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
|
|
28
|
+
export declare const Uint256Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
|
|
29
|
+
export declare const Uint512Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
|
|
30
|
+
export declare const Bytes: Codec<HexLike, Hex>;
|
|
31
|
+
export declare const BytesOpt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
32
|
+
export declare const BytesVec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
33
|
+
export declare const Byte32: Codec<HexLike, Hex>;
|
|
34
|
+
export declare const Byte32Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
35
|
+
export declare const Byte32Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
36
|
+
export declare const String: Codec<string, string>;
|
|
37
|
+
export declare const StringVec: Codec<string[], string[]>;
|
|
38
|
+
export declare const StringOpt: Codec<string | null | undefined, string | undefined>;
|
|
39
|
+
export declare const Hash: Codec<import("../bytes/index.js").BytesLike, `0x${string}`>;
|
|
40
|
+
export declare const HashType: Codec<ckb.HashTypeLike, ckb.HashType>;
|
|
41
|
+
export declare const Script: Codec<ckb.ScriptLike, ckb.Script>;
|
|
42
|
+
export declare const ScriptOpt: Codec<ckb.ScriptLike | null | undefined, ckb.Script | undefined>;
|
|
43
|
+
export declare const OutPoint: Codec<ckb.OutPointLike, ckb.OutPoint>;
|
|
44
|
+
export declare const CellInput: Codec<ckb.CellInputLike, ckb.CellInput>;
|
|
45
|
+
export declare const CellInputVec: Codec<ckb.CellInputLike[], ckb.CellInput[]>;
|
|
46
|
+
export declare const CellOutput: Codec<ckb.CellOutputLike, ckb.CellOutput>;
|
|
47
|
+
export declare const CellOutputVec: Codec<ckb.CellOutputLike[], ckb.CellOutput[]>;
|
|
48
|
+
export declare const DepType: Codec<ckb.DepTypeLike, ckb.DepType>;
|
|
49
|
+
export declare const CellDep: Codec<ckb.CellDepLike, ckb.CellDep>;
|
|
50
|
+
export declare const CellDepVec: Codec<ckb.CellDepLike[], ckb.CellDep[]>;
|
|
51
|
+
export declare const Transaction: Codec<ckb.TransactionLike, ckb.Transaction>;
|
|
52
|
+
//# sourceMappingURL=predefined.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predefined.d.ts","sourceRoot":"","sources":["../../src/molecule/predefined.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,GAAG,EAAW,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAEL,KAAK,EAON,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,KAAK,+CAAsB,CAAC;AACzC,eAAO,MAAM,QAAQ,+CAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,+CAAgB,CAAC;AACtC,eAAO,MAAM,MAAM,+CAAW,CAAC;AAC/B,eAAO,MAAM,QAAQ,+CAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,+CAAgB,CAAC;AACtC,eAAO,MAAM,MAAM,+CAAW,CAAC;AAC/B,eAAO,MAAM,QAAQ,+CAAgB,CAAC;AACtC,eAAO,MAAM,QAAQ,+CAAU,CAAC;AAChC,eAAO,MAAM,MAAM,+CAAW,CAAC;AAC/B,eAAO,MAAM,SAAS,+CAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,+CAAW,CAAC;AAClC,eAAO,MAAM,OAAO,+CAAY,CAAC;AACjC,eAAO,MAAM,SAAS,+CAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,+CAAW,CAAC;AAClC,eAAO,MAAM,OAAO,+CAAY,CAAC;AACjC,eAAO,MAAM,SAAS,+CAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,+CAAW,CAAC;AAClC,eAAO,MAAM,OAAO,+CAAY,CAAC;AAEjC,eAAO,MAAM,QAAQ,8EAAgB,CAAC;AACtC,eAAO,MAAM,SAAS,8EAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,8EAAiB,CAAC;AACxC,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,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAItD,CAAC;AACH,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAGpB,CAAC;AACrC,eAAO,MAAM,UAAU,yCAAkB,CAAC;AAE1C,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAQ5B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { bytesFrom, bytesTo } from "../bytes/index.js";
|
|
2
|
+
import * as ckb from "../ckb/index.js";
|
|
3
|
+
import { hexFrom } from "../hex/index.js";
|
|
4
|
+
import { byteVec, Codec, option, struct, table, uint, uintNumber, vector, } from "./codec.js";
|
|
5
|
+
export const Uint8 = uintNumber(1, true);
|
|
6
|
+
export const Uint16LE = uintNumber(2, true);
|
|
7
|
+
export const Uint16BE = uintNumber(2);
|
|
8
|
+
export const Uint16 = Uint16LE;
|
|
9
|
+
export const Uint32LE = uintNumber(4, true);
|
|
10
|
+
export const Uint32BE = uintNumber(4);
|
|
11
|
+
export const Uint32 = Uint32LE;
|
|
12
|
+
export const Uint64LE = uint(8, true);
|
|
13
|
+
export const Uint64BE = uint(8);
|
|
14
|
+
export const Uint64 = Uint64LE;
|
|
15
|
+
export const Uint128LE = uint(16, true);
|
|
16
|
+
export const Uint128BE = uint(16);
|
|
17
|
+
export const Uint128 = Uint128LE;
|
|
18
|
+
export const Uint256LE = uint(32, true);
|
|
19
|
+
export const Uint256BE = uint(32);
|
|
20
|
+
export const Uint256 = Uint256LE;
|
|
21
|
+
export const Uint512LE = uint(64, true);
|
|
22
|
+
export const Uint512BE = uint(64);
|
|
23
|
+
export const Uint512 = Uint512LE;
|
|
24
|
+
export const Uint8Opt = option(Uint8);
|
|
25
|
+
export const Uint16Opt = option(Uint16);
|
|
26
|
+
export const Uint32Opt = option(Uint32);
|
|
27
|
+
export const Uint64Opt = option(Uint64);
|
|
28
|
+
export const Uint128Opt = option(Uint128);
|
|
29
|
+
export const Uint256Opt = option(Uint256);
|
|
30
|
+
export const Uint512Opt = option(Uint512);
|
|
31
|
+
export const Bytes = byteVec({
|
|
32
|
+
encode: (value) => bytesFrom(value),
|
|
33
|
+
decode: (buffer) => hexFrom(buffer),
|
|
34
|
+
});
|
|
35
|
+
export const BytesOpt = option(Bytes);
|
|
36
|
+
export const BytesVec = vector(Bytes);
|
|
37
|
+
export const Byte32 = Codec.from({
|
|
38
|
+
byteLength: 32,
|
|
39
|
+
encode: (value) => bytesFrom(value),
|
|
40
|
+
decode: (buffer) => hexFrom(buffer),
|
|
41
|
+
});
|
|
42
|
+
export const Byte32Opt = option(Byte32);
|
|
43
|
+
export const Byte32Vec = vector(Byte32);
|
|
44
|
+
export const String = byteVec({
|
|
45
|
+
encode: (value) => bytesFrom(value, "utf8"),
|
|
46
|
+
decode: (buffer) => bytesTo(buffer, "utf8"),
|
|
47
|
+
});
|
|
48
|
+
export const StringVec = vector(String);
|
|
49
|
+
export const StringOpt = option(String);
|
|
50
|
+
export const Hash = Byte32;
|
|
51
|
+
export const HashType = Codec.from({
|
|
52
|
+
byteLength: 1,
|
|
53
|
+
encode: ckb.hashTypeToBytes,
|
|
54
|
+
decode: ckb.hashTypeFromBytes,
|
|
55
|
+
});
|
|
56
|
+
export const Script = table({
|
|
57
|
+
codeHash: Hash,
|
|
58
|
+
hashType: HashType,
|
|
59
|
+
args: Bytes,
|
|
60
|
+
}).map({ outMap: ckb.Script.from });
|
|
61
|
+
export const ScriptOpt = option(Script);
|
|
62
|
+
export const OutPoint = struct({
|
|
63
|
+
txHash: Hash,
|
|
64
|
+
index: Uint32,
|
|
65
|
+
}).map({ outMap: ckb.OutPoint.from });
|
|
66
|
+
export const CellInput = struct({
|
|
67
|
+
previousOutput: OutPoint,
|
|
68
|
+
since: Uint64,
|
|
69
|
+
}).map({ outMap: ckb.CellInput.from });
|
|
70
|
+
export const CellInputVec = vector(CellInput);
|
|
71
|
+
export const CellOutput = table({
|
|
72
|
+
capacity: Uint64,
|
|
73
|
+
lock: Script,
|
|
74
|
+
type: ScriptOpt,
|
|
75
|
+
}).map({ outMap: ckb.CellOutput.from });
|
|
76
|
+
export const CellOutputVec = vector(CellOutput);
|
|
77
|
+
export const DepType = Codec.from({
|
|
78
|
+
byteLength: 1,
|
|
79
|
+
encode: ckb.depTypeToBytes,
|
|
80
|
+
decode: ckb.depTypeFromBytes,
|
|
81
|
+
});
|
|
82
|
+
export const CellDep = struct({
|
|
83
|
+
outPoint: OutPoint,
|
|
84
|
+
depType: DepType,
|
|
85
|
+
}).map({ outMap: ckb.CellDep.from });
|
|
86
|
+
export const CellDepVec = vector(CellDep);
|
|
87
|
+
export const Transaction = table({
|
|
88
|
+
version: Uint32,
|
|
89
|
+
cellDeps: CellDepVec,
|
|
90
|
+
headerDeps: Byte32Vec,
|
|
91
|
+
inputs: CellInputVec,
|
|
92
|
+
outputs: CellOutputVec,
|
|
93
|
+
outputsData: BytesVec,
|
|
94
|
+
witnesses: BytesVec,
|
|
95
|
+
}).map({ outMap: ckb.Transaction.from });
|
|
@@ -6,6 +6,7 @@ export * from "./fixedPoint/index.js";
|
|
|
6
6
|
export * from "./hasher/index.js";
|
|
7
7
|
export * from "./hex/index.js";
|
|
8
8
|
export * from "./keystore/index.js";
|
|
9
|
+
export * as mol from "./molecule/index.js";
|
|
9
10
|
export * from "./num/index.js";
|
|
10
11
|
export * from "./signer/index.js";
|
|
11
12
|
export * from "./utils/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -10,10 +10,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
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
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.mol = void 0;
|
|
17
30
|
__exportStar(require("./address/index.js"), exports);
|
|
18
31
|
__exportStar(require("./bytes/index.js"), exports);
|
|
19
32
|
__exportStar(require("./ckb/index.js"), exports);
|
|
@@ -22,6 +35,7 @@ __exportStar(require("./fixedPoint/index.js"), exports);
|
|
|
22
35
|
__exportStar(require("./hasher/index.js"), exports);
|
|
23
36
|
__exportStar(require("./hex/index.js"), exports);
|
|
24
37
|
__exportStar(require("./keystore/index.js"), exports);
|
|
38
|
+
exports.mol = __importStar(require("./molecule/index.js"));
|
|
25
39
|
__exportStar(require("./num/index.js"), exports);
|
|
26
40
|
__exportStar(require("./signer/index.js"), exports);
|
|
27
41
|
__exportStar(require("./utils/index.js"), exports);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Bytes, BytesLike } from "../bytes/index.js";
|
|
2
|
+
import { Num, NumLike } from "../num/index.js";
|
|
3
|
+
export type CodecLike<Encodable, Decoded = Encodable> = {
|
|
4
|
+
readonly encode: (encodable: Encodable) => Bytes;
|
|
5
|
+
readonly decode: (decodable: BytesLike) => Decoded;
|
|
6
|
+
readonly byteLength?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare class Codec<Encodable, Decoded = Encodable> {
|
|
9
|
+
readonly encode: (encodable: Encodable) => Bytes;
|
|
10
|
+
readonly decode: (decodable: BytesLike) => Decoded;
|
|
11
|
+
readonly byteLength?: number | undefined;
|
|
12
|
+
constructor(encode: (encodable: Encodable) => Bytes, decode: (decodable: BytesLike) => Decoded, byteLength?: number | undefined);
|
|
13
|
+
static from<Encodable, Decoded = Encodable>({ encode, decode, byteLength, }: CodecLike<Encodable, Decoded>): Codec<Encodable, Decoded>;
|
|
14
|
+
map<NewEncodable = Encodable, NewDecoded = Decoded>({ inMap, outMap, }: {
|
|
15
|
+
inMap?: (encodable: NewEncodable) => Encodable;
|
|
16
|
+
outMap?: (decoded: Decoded) => NewDecoded;
|
|
17
|
+
}): Codec<NewEncodable, NewDecoded>;
|
|
18
|
+
}
|
|
19
|
+
export type EncodableType<T extends CodecLike<any, any>> = T extends CodecLike<infer Encodable, unknown> ? Encodable : never;
|
|
20
|
+
export type DecodedType<T extends CodecLike<any, any>> = T extends CodecLike<any, infer Decoded> ? Decoded : never;
|
|
21
|
+
/**
|
|
22
|
+
* Vector with fixed size item codec
|
|
23
|
+
* @param itemCodec fixed-size vector item codec
|
|
24
|
+
*/
|
|
25
|
+
export declare function fixedItemVec<Encodable, Decoded>(itemCodec: CodecLike<Encodable, Decoded>): Codec<Array<Encodable>, Array<Decoded>>;
|
|
26
|
+
/**
|
|
27
|
+
* Vector with dynamic size item codec, you can create a recursive vector with this function
|
|
28
|
+
* @param itemCodec the vector item codec. It can be fixed-size or dynamic-size.
|
|
29
|
+
*/
|
|
30
|
+
export declare function dynItemVec<Encodable, Decoded>(itemCodec: CodecLike<Encodable, Decoded>): Codec<Array<Encodable>, Array<Decoded>>;
|
|
31
|
+
/**
|
|
32
|
+
* General vector codec, if `itemCodec` is fixed size type, it will create a fixvec codec, otherwise a dynvec codec will be created.
|
|
33
|
+
* @param itemCodec
|
|
34
|
+
*/
|
|
35
|
+
export declare function vector<Encodable, Decoded>(itemCodec: CodecLike<Encodable, Decoded>): Codec<Array<Encodable>, Array<Decoded>>;
|
|
36
|
+
/**
|
|
37
|
+
* Option is a dynamic-size type.
|
|
38
|
+
* Serializing an option depends on whether it is empty or not:
|
|
39
|
+
* - if it's empty, there is zero bytes (the size is 0).
|
|
40
|
+
* - if it's not empty, just serialize the inner item (the size is same as the inner item's size).
|
|
41
|
+
* @param innerCodec
|
|
42
|
+
*/
|
|
43
|
+
export declare function option<Encodable, Decoded>(innerCodec: CodecLike<Encodable, Decoded>): Codec<Encodable | undefined | null, Decoded | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Wrap the encoded value with a fixed-length buffer
|
|
46
|
+
* @param codec
|
|
47
|
+
*/
|
|
48
|
+
export declare function byteVec<Encodable, Decoded>(codec: CodecLike<Encodable, Decoded>): Codec<Encodable, Decoded>;
|
|
49
|
+
export type EncodableRecordOptionalKeys<T extends Record<string, CodecLike<any, any>>> = {
|
|
50
|
+
[K in keyof T]: Extract<EncodableType<T[K]>, undefined> extends never ? never : K;
|
|
51
|
+
}[keyof T];
|
|
52
|
+
export type EncodableRecord<T extends Record<string, CodecLike<any, any>>> = {
|
|
53
|
+
[key in keyof Pick<T, EncodableRecordOptionalKeys<T>>]+?: EncodableType<T[key]>;
|
|
54
|
+
} & {
|
|
55
|
+
[key in keyof Omit<T, EncodableRecordOptionalKeys<T>>]: EncodableType<T[key]>;
|
|
56
|
+
};
|
|
57
|
+
export type DecodedRecordOptionalKeys<T extends Record<string, CodecLike<any, any>>> = {
|
|
58
|
+
[K in keyof T]: Extract<DecodedType<T[K]>, undefined> extends never ? never : K;
|
|
59
|
+
}[keyof T];
|
|
60
|
+
export type DecodedRecord<T extends Record<string, CodecLike<any, any>>> = {
|
|
61
|
+
[key in keyof Pick<T, DecodedRecordOptionalKeys<T>>]+?: DecodedType<T[key]>;
|
|
62
|
+
} & {
|
|
63
|
+
[key in keyof Omit<T, DecodedRecordOptionalKeys<T>>]: DecodedType<T[key]>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Table is a dynamic-size type. It can be considered as a dynvec but the length is fixed.
|
|
67
|
+
* @param codecLayout
|
|
68
|
+
*/
|
|
69
|
+
export declare function table<T extends Record<string, CodecLike<any, any>>, Encodable extends EncodableRecord<T>, Decoded extends DecodedRecord<T>>(codecLayout: T): Codec<Encodable, Decoded>;
|
|
70
|
+
type UnionEncodable<T extends Record<string, CodecLike<any, any>>, K extends keyof T = keyof T> = K extends unknown ? {
|
|
71
|
+
type: K;
|
|
72
|
+
value: EncodableType<T[K]>;
|
|
73
|
+
} : never;
|
|
74
|
+
type UnionDecoded<T extends Record<string, CodecLike<any, any>>, K extends keyof T = keyof T> = K extends unknown ? {
|
|
75
|
+
type: K;
|
|
76
|
+
value: DecodedType<T[K]>;
|
|
77
|
+
} : never;
|
|
78
|
+
/**
|
|
79
|
+
* Union is a dynamic-size type.
|
|
80
|
+
* Serializing a union has two steps:
|
|
81
|
+
* - Serialize an item type id in bytes as a 32 bit unsigned integer in little-endian. The item type id is the index of the inner items, and it's starting at 0.
|
|
82
|
+
* - Serialize the inner item.
|
|
83
|
+
* @param codecLayout the union item record
|
|
84
|
+
* @param fields the custom item type id record
|
|
85
|
+
* @example
|
|
86
|
+
* // without custom id
|
|
87
|
+
* union({ cafe: Uint8, bee: Uint8 })
|
|
88
|
+
* // with custom id
|
|
89
|
+
* union({ cafe: Uint8, bee: Uint8 }, { cafe: 0xcafe, bee: 0xbee })
|
|
90
|
+
*/
|
|
91
|
+
export declare function union<T extends Record<string, CodecLike<any, any>>>(codecLayout: T, fields?: Record<keyof T, number | undefined | null>): Codec<UnionEncodable<T>, UnionDecoded<T>>;
|
|
92
|
+
/**
|
|
93
|
+
* Struct is a fixed-size type: all fields in struct are fixed-size and it has a fixed quantity of fields.
|
|
94
|
+
* The size of a struct is the sum of all fields' size.
|
|
95
|
+
* @param codecLayout a object contains all fields' codec
|
|
96
|
+
*/
|
|
97
|
+
export declare function struct<T extends Record<string, CodecLike<any, any>>, Encodable extends EncodableRecord<T>, Decoded extends DecodedRecord<T>>(codecLayout: T): Codec<Encodable, Decoded>;
|
|
98
|
+
/**
|
|
99
|
+
* The array is a fixed-size type: it has a fixed-size inner type and a fixed length.
|
|
100
|
+
* The size of an array is the size of inner type times the length.
|
|
101
|
+
* @param itemCodec the fixed-size array item codec
|
|
102
|
+
* @param itemCount
|
|
103
|
+
*/
|
|
104
|
+
export declare function array<Encodable, Decoded>(itemCodec: CodecLike<Encodable, Decoded>, itemCount: number): Codec<Array<Encodable>, Array<Decoded>>;
|
|
105
|
+
/**
|
|
106
|
+
* Create a codec to deal with fixed LE or BE bytes.
|
|
107
|
+
* @param byteLength
|
|
108
|
+
* @param littleEndian
|
|
109
|
+
*/
|
|
110
|
+
export declare function uint(byteLength: number, littleEndian?: boolean): Codec<NumLike, Num>;
|
|
111
|
+
/**
|
|
112
|
+
* Create a codec to deal with fixed LE or BE bytes.
|
|
113
|
+
* @param byteLength
|
|
114
|
+
* @param littleEndian
|
|
115
|
+
*/
|
|
116
|
+
export declare function uintNumber(byteLength: number, littleEndian?: boolean): Codec<NumLike, number>;
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/molecule/codec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAA0B,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EACL,GAAG,EAIH,OAAO,EAER,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI;IACtD,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,KAAK,CAAC;IACjD,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,qBAAa,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS;aAE7B,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,KAAK;aACvC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO;aACzC,UAAU,CAAC,EAAE,MAAM;gBAFnB,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,KAAK,EACvC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,EACzC,UAAU,CAAC,EAAE,MAAM,YAAA;IAGrC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,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