@ckb-ccc/core 0.1.0-alpha.5 → 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 +13 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +9 -7
- 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/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +7 -5
- 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/ckb/transaction.ts +9 -12
- package/src/molecule/codec.ts +610 -0
- package/src/molecule/index.ts +2 -0
- package/src/molecule/predefined.ts +114 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/ckb/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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AAG,OAAO,EACtE,eAAe,CAAC,EAAE,OAAO,EACzB,MAAM,CAAC,EAAE,oCAAoC,GAC5C,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA2E7B,uBAAuB,CACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,oCAAoC,GAC5C,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAoBvB,aAAa,CACjB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,oCAAoC,GAC5C,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAM7B,yBAAyB,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,oCAAoC,GAC5C,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAe9B"}
|
|
@@ -354,11 +354,11 @@ function epochFrom(epochLike) {
|
|
|
354
354
|
* @public
|
|
355
355
|
*/
|
|
356
356
|
function epochFromHex(hex) {
|
|
357
|
-
const
|
|
357
|
+
const num = (0, index_js_5.numFrom)((0, index_js_4.hexFrom)(hex));
|
|
358
358
|
return [
|
|
359
|
-
(0, index_js_5.numFrom)(
|
|
360
|
-
(0, index_js_5.numFrom)(
|
|
361
|
-
(0, index_js_5.numFrom)(
|
|
359
|
+
num & (0, index_js_5.numFrom)("0xffffff"),
|
|
360
|
+
(num >> (0, index_js_5.numFrom)(24)) & (0, index_js_5.numFrom)("0xffff"),
|
|
361
|
+
(num >> (0, index_js_5.numFrom)(40)) & (0, index_js_5.numFrom)("0xffff"),
|
|
362
362
|
];
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
@@ -366,7 +366,9 @@ function epochFromHex(hex) {
|
|
|
366
366
|
*/
|
|
367
367
|
function epochToHex(epochLike) {
|
|
368
368
|
const epoch = epochFrom(epochLike);
|
|
369
|
-
return (0,
|
|
369
|
+
return (0, index_js_5.numToHex)((0, index_js_5.numFrom)(epoch[0]) +
|
|
370
|
+
((0, index_js_5.numFrom)(epoch[1]) << (0, index_js_5.numFrom)(24)) +
|
|
371
|
+
((0, index_js_5.numFrom)(epoch[2]) << (0, index_js_5.numFrom)(40)));
|
|
370
372
|
}
|
|
371
373
|
/**
|
|
372
374
|
* @public
|
|
@@ -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,GAAG,SAAS,EAAE,EAC1C,MAAM,EACN,MAAM,EACN,UAAU,GACX,EAAE,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC;IAI5D,GAAG,CAAC,YAAY,GAAG,SAAS,EAAE,UAAU,GAAG,OAAO,EAAE,EAClD,KAAK,EACL,MAAM,GACP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int/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Codec = void 0;
|
|
5
|
+
exports.fixedItemVec = fixedItemVec;
|
|
6
|
+
exports.dynItemVec = dynItemVec;
|
|
7
|
+
exports.vector = vector;
|
|
8
|
+
exports.option = option;
|
|
9
|
+
exports.byteVec = byteVec;
|
|
10
|
+
exports.table = table;
|
|
11
|
+
exports.union = union;
|
|
12
|
+
exports.struct = struct;
|
|
13
|
+
exports.array = array;
|
|
14
|
+
exports.uint = uint;
|
|
15
|
+
exports.uintNumber = uintNumber;
|
|
16
|
+
const index_js_1 = require("../bytes/index.js");
|
|
17
|
+
const index_js_2 = require("../num/index.js");
|
|
18
|
+
class Codec {
|
|
19
|
+
constructor(encode, decode, byteLength) {
|
|
20
|
+
this.encode = encode;
|
|
21
|
+
this.decode = decode;
|
|
22
|
+
this.byteLength = byteLength;
|
|
23
|
+
}
|
|
24
|
+
static from({ encode, decode, byteLength, }) {
|
|
25
|
+
return new Codec(encode, decode, byteLength);
|
|
26
|
+
}
|
|
27
|
+
map({ inMap, outMap, }) {
|
|
28
|
+
return Codec.from({
|
|
29
|
+
byteLength: this.byteLength,
|
|
30
|
+
encode: (encodable) => this.encode((inMap ? inMap(encodable) : encodable)),
|
|
31
|
+
decode: (buffer) => (outMap
|
|
32
|
+
? outMap(this.decode(buffer))
|
|
33
|
+
: this.decode(buffer)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Codec = Codec;
|
|
38
|
+
function uint32To(numLike) {
|
|
39
|
+
return (0, index_js_2.numToBytes)(numLike, 4);
|
|
40
|
+
}
|
|
41
|
+
function uint32From(bytesLike) {
|
|
42
|
+
return Number((0, index_js_2.numFromBytes)(bytesLike));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Vector with fixed size item codec
|
|
46
|
+
* @param itemCodec fixed-size vector item codec
|
|
47
|
+
*/
|
|
48
|
+
function fixedItemVec(itemCodec) {
|
|
49
|
+
const itemByteLength = itemCodec.byteLength;
|
|
50
|
+
if (itemByteLength === undefined) {
|
|
51
|
+
throw new Error("fixedItemVec: itemCodec requires a byte length");
|
|
52
|
+
}
|
|
53
|
+
return Codec.from({
|
|
54
|
+
encode(userDefinedItems) {
|
|
55
|
+
try {
|
|
56
|
+
return userDefinedItems.reduce((concatted, item) => (0, index_js_1.bytesConcat)(concatted, itemCodec.encode(item)), uint32To(userDefinedItems.length));
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Error(`fixedItemVec(${e?.toString()})`);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
decode(buffer) {
|
|
63
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
64
|
+
if (value.byteLength < 4) {
|
|
65
|
+
throw new Error(`fixedItemVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`);
|
|
66
|
+
}
|
|
67
|
+
const itemCount = uint32From(value.slice(0, 4));
|
|
68
|
+
const byteLength = 4 + itemCount * itemByteLength;
|
|
69
|
+
if (value.byteLength !== byteLength) {
|
|
70
|
+
throw new Error(`fixedItemVec: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const decodedArray = [];
|
|
74
|
+
for (let offset = 0; offset < byteLength; offset += itemByteLength) {
|
|
75
|
+
decodedArray.push(itemCodec.decode(value.slice(offset, offset + itemByteLength)));
|
|
76
|
+
}
|
|
77
|
+
return decodedArray;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
throw new Error(`fixedItemVec(${e?.toString()})`);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Vector with dynamic size item codec, you can create a recursive vector with this function
|
|
87
|
+
* @param itemCodec the vector item codec. It can be fixed-size or dynamic-size.
|
|
88
|
+
*/
|
|
89
|
+
function dynItemVec(itemCodec) {
|
|
90
|
+
return Codec.from({
|
|
91
|
+
encode(userDefinedItems) {
|
|
92
|
+
try {
|
|
93
|
+
const encoded = userDefinedItems.reduce(({ offset, header, body }, item) => {
|
|
94
|
+
const encodedItem = itemCodec.encode(item);
|
|
95
|
+
const packedHeader = uint32To(offset);
|
|
96
|
+
return {
|
|
97
|
+
header: (0, index_js_1.bytesConcat)(header, packedHeader),
|
|
98
|
+
body: (0, index_js_1.bytesConcat)(body, encodedItem),
|
|
99
|
+
offset: offset + (0, index_js_1.bytesFrom)(encodedItem).byteLength,
|
|
100
|
+
};
|
|
101
|
+
}, {
|
|
102
|
+
header: (0, index_js_1.bytesFrom)([]),
|
|
103
|
+
body: (0, index_js_1.bytesFrom)([]),
|
|
104
|
+
offset: 4 + userDefinedItems.length * 4,
|
|
105
|
+
});
|
|
106
|
+
const packedTotalSize = uint32To(encoded.header.byteLength + encoded.body.byteLength + 4);
|
|
107
|
+
return (0, index_js_1.bytesConcat)(packedTotalSize, encoded.header, encoded.body);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
throw new Error(`dynItemVec(${e?.toString()})`);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
decode(buffer) {
|
|
114
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
115
|
+
const byteLength = uint32From(value.slice(0, 4));
|
|
116
|
+
if (byteLength !== value.byteLength) {
|
|
117
|
+
throw new Error(`dynItemVec: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
118
|
+
}
|
|
119
|
+
if (value.byteLength < 4) {
|
|
120
|
+
throw new Error(`fixedItemVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`);
|
|
121
|
+
}
|
|
122
|
+
const offset = uint32From(value.slice(4, 8));
|
|
123
|
+
const itemCount = (offset - 4) / 4;
|
|
124
|
+
const offsets = Array.from(new Array(itemCount), (_, index) => uint32From(value.slice(4 + index * 4, 8 + index * 4)));
|
|
125
|
+
offsets.push(byteLength);
|
|
126
|
+
try {
|
|
127
|
+
const decodedArray = [];
|
|
128
|
+
for (let index = 0; index < offsets.length - 1; index++) {
|
|
129
|
+
const start = offsets[index];
|
|
130
|
+
const end = offsets[index + 1];
|
|
131
|
+
const itemBuffer = value.slice(start, end);
|
|
132
|
+
decodedArray.push(itemCodec.decode(itemBuffer));
|
|
133
|
+
}
|
|
134
|
+
return decodedArray;
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
throw new Error(`dynItemVec(${e?.toString()})`);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* General vector codec, if `itemCodec` is fixed size type, it will create a fixvec codec, otherwise a dynvec codec will be created.
|
|
144
|
+
* @param itemCodec
|
|
145
|
+
*/
|
|
146
|
+
function vector(itemCodec) {
|
|
147
|
+
if (itemCodec.byteLength !== undefined) {
|
|
148
|
+
return fixedItemVec(itemCodec);
|
|
149
|
+
}
|
|
150
|
+
return dynItemVec(itemCodec);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Option is a dynamic-size type.
|
|
154
|
+
* Serializing an option depends on whether it is empty or not:
|
|
155
|
+
* - if it's empty, there is zero bytes (the size is 0).
|
|
156
|
+
* - if it's not empty, just serialize the inner item (the size is same as the inner item's size).
|
|
157
|
+
* @param innerCodec
|
|
158
|
+
*/
|
|
159
|
+
function option(innerCodec) {
|
|
160
|
+
return Codec.from({
|
|
161
|
+
encode(userDefinedOrNull) {
|
|
162
|
+
if (!userDefinedOrNull) {
|
|
163
|
+
return (0, index_js_1.bytesFrom)([]);
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return innerCodec.encode(userDefinedOrNull);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
throw new Error(`option(${e?.toString()})`);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
decode(buffer) {
|
|
173
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
174
|
+
if (value.byteLength === 0) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
return innerCodec.decode(buffer);
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
throw new Error(`option(${e?.toString()})`);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Wrap the encoded value with a fixed-length buffer
|
|
188
|
+
* @param codec
|
|
189
|
+
*/
|
|
190
|
+
function byteVec(codec) {
|
|
191
|
+
return Codec.from({
|
|
192
|
+
encode(userDefined) {
|
|
193
|
+
try {
|
|
194
|
+
const payload = (0, index_js_1.bytesFrom)(codec.encode(userDefined));
|
|
195
|
+
const byteLength = uint32To(payload.byteLength);
|
|
196
|
+
return (0, index_js_1.bytesConcat)(byteLength, payload);
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
throw new Error(`byteVec(${e?.toString()})`);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
decode(buffer) {
|
|
203
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
204
|
+
if (value.byteLength < 4) {
|
|
205
|
+
throw new Error(`byteVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`);
|
|
206
|
+
}
|
|
207
|
+
const byteLength = uint32From(value.slice(0, 4));
|
|
208
|
+
if (byteLength !== value.byteLength - 4) {
|
|
209
|
+
throw new Error(`byteVec: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
return codec.decode(value.slice(4));
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
throw new Error(`byteVec(${e?.toString()})`);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Table is a dynamic-size type. It can be considered as a dynvec but the length is fixed.
|
|
222
|
+
* @param codecLayout
|
|
223
|
+
*/
|
|
224
|
+
function table(codecLayout) {
|
|
225
|
+
const keys = Object.keys(codecLayout);
|
|
226
|
+
return Codec.from({
|
|
227
|
+
encode(object) {
|
|
228
|
+
const headerLength = 4 + keys.length * 4;
|
|
229
|
+
const { header, body } = keys.reduce((result, key) => {
|
|
230
|
+
try {
|
|
231
|
+
const encodedItem = codecLayout[key].encode(object[key]);
|
|
232
|
+
const packedOffset = uint32To(result.offset);
|
|
233
|
+
return {
|
|
234
|
+
header: (0, index_js_1.bytesConcat)(result.header, packedOffset),
|
|
235
|
+
body: (0, index_js_1.bytesConcat)(result.body, encodedItem),
|
|
236
|
+
offset: result.offset + (0, index_js_1.bytesFrom)(encodedItem).byteLength,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
throw new Error(`table.${key}(${e?.toString()})`);
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
header: (0, index_js_1.bytesFrom)([]),
|
|
244
|
+
body: (0, index_js_1.bytesFrom)([]),
|
|
245
|
+
offset: headerLength,
|
|
246
|
+
});
|
|
247
|
+
const packedTotalSize = uint32To(header.byteLength + body.byteLength + 4);
|
|
248
|
+
return (0, index_js_1.bytesConcat)(packedTotalSize, header, body);
|
|
249
|
+
},
|
|
250
|
+
decode(buffer) {
|
|
251
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
252
|
+
const byteLength = uint32From(value.slice(0, 4));
|
|
253
|
+
if (byteLength !== value.byteLength) {
|
|
254
|
+
throw new Error(`table: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
255
|
+
}
|
|
256
|
+
if (byteLength <= 4) {
|
|
257
|
+
throw new Error("table: empty buffer");
|
|
258
|
+
}
|
|
259
|
+
const offsets = keys.map((_, index) => uint32From(value.slice(4 + index * 4, 8 + index * 4)));
|
|
260
|
+
offsets.push(byteLength);
|
|
261
|
+
const object = {};
|
|
262
|
+
for (let i = 0; i < offsets.length - 1; i++) {
|
|
263
|
+
const start = offsets[i];
|
|
264
|
+
const end = offsets[i + 1];
|
|
265
|
+
const field = keys[i];
|
|
266
|
+
const codec = codecLayout[field];
|
|
267
|
+
const payload = value.slice(start, end);
|
|
268
|
+
try {
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
270
|
+
Object.assign(object, { [field]: codec.decode(payload) });
|
|
271
|
+
}
|
|
272
|
+
catch (e) {
|
|
273
|
+
throw new Error(`table.${field}(${e?.toString()})`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return object;
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Union is a dynamic-size type.
|
|
282
|
+
* Serializing a union has two steps:
|
|
283
|
+
* - 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.
|
|
284
|
+
* - Serialize the inner item.
|
|
285
|
+
* @param codecLayout the union item record
|
|
286
|
+
* @param fields the custom item type id record
|
|
287
|
+
* @example
|
|
288
|
+
* // without custom id
|
|
289
|
+
* union({ cafe: Uint8, bee: Uint8 })
|
|
290
|
+
* // with custom id
|
|
291
|
+
* union({ cafe: Uint8, bee: Uint8 }, { cafe: 0xcafe, bee: 0xbee })
|
|
292
|
+
*/
|
|
293
|
+
function union(codecLayout, fields) {
|
|
294
|
+
const keys = Object.keys(codecLayout);
|
|
295
|
+
return Codec.from({
|
|
296
|
+
encode({ type, value }) {
|
|
297
|
+
const typeStr = type.toString();
|
|
298
|
+
const codec = codecLayout[typeStr];
|
|
299
|
+
if (!codec) {
|
|
300
|
+
throw new Error(`union: invalid type, expected ${keys.toString()}, but got ${typeStr}`);
|
|
301
|
+
}
|
|
302
|
+
const fieldId = fields ? (fields[typeStr] ?? -1) : keys.indexOf(typeStr);
|
|
303
|
+
if (fieldId < 0) {
|
|
304
|
+
throw new Error(`union: invalid field id ${fieldId} of ${typeStr}`);
|
|
305
|
+
}
|
|
306
|
+
const header = uint32To(fieldId);
|
|
307
|
+
try {
|
|
308
|
+
const body = codec.encode(value);
|
|
309
|
+
return (0, index_js_1.bytesConcat)(header, body);
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
throw new Error(`union.(${typeStr})(${e?.toString()})`);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
decode(buffer) {
|
|
316
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
317
|
+
const fieldIndex = uint32From(value.slice(0, 4));
|
|
318
|
+
const keys = Object.keys(codecLayout);
|
|
319
|
+
const field = (() => {
|
|
320
|
+
if (!fields) {
|
|
321
|
+
return keys[fieldIndex];
|
|
322
|
+
}
|
|
323
|
+
const entry = Object.entries(fields).find(([, id]) => id === fieldIndex);
|
|
324
|
+
return entry?.[0];
|
|
325
|
+
})();
|
|
326
|
+
if (!field) {
|
|
327
|
+
if (!fields) {
|
|
328
|
+
throw new Error(`union: unknown union field index ${fieldIndex}, only ${keys.toString()} are allowed`);
|
|
329
|
+
}
|
|
330
|
+
const fieldKeys = Object.keys(fields);
|
|
331
|
+
throw new Error(`union: unknown union field index ${fieldIndex}, only ${fieldKeys.toString()} and ${keys.toString()} are allowed`);
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
type: field,
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
336
|
+
value: codecLayout[field].decode(value.slice(4)),
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Struct is a fixed-size type: all fields in struct are fixed-size and it has a fixed quantity of fields.
|
|
343
|
+
* The size of a struct is the sum of all fields' size.
|
|
344
|
+
* @param codecLayout a object contains all fields' codec
|
|
345
|
+
*/
|
|
346
|
+
function struct(codecLayout) {
|
|
347
|
+
const codecArray = Object.values(codecLayout);
|
|
348
|
+
if (codecArray.some((codec) => codec.byteLength === undefined)) {
|
|
349
|
+
throw new Error("struct: all fields must be fixed-size");
|
|
350
|
+
}
|
|
351
|
+
const keys = Object.keys(codecLayout);
|
|
352
|
+
return Codec.from({
|
|
353
|
+
byteLength: codecArray.reduce((sum, codec) => sum + codec.byteLength, 0),
|
|
354
|
+
encode(object) {
|
|
355
|
+
return keys.reduce((result, key) => {
|
|
356
|
+
try {
|
|
357
|
+
const encodedItem = codecLayout[key].encode(object[key]);
|
|
358
|
+
return (0, index_js_1.bytesConcat)(result, encodedItem);
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
throw new Error(`struct.${key}(${e?.toString()})`);
|
|
362
|
+
}
|
|
363
|
+
}, (0, index_js_1.bytesFrom)([]));
|
|
364
|
+
},
|
|
365
|
+
decode(buffer) {
|
|
366
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
367
|
+
const object = {};
|
|
368
|
+
let offset = 0;
|
|
369
|
+
Object.entries(codecLayout).forEach(([key, codec]) => {
|
|
370
|
+
const payload = value.slice(offset, offset + codec.byteLength);
|
|
371
|
+
try {
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
373
|
+
Object.assign(object, { [key]: codec.decode(payload) });
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
throw new Error(`struct.${key}(${e.toString()})`);
|
|
377
|
+
}
|
|
378
|
+
offset = offset + codec.byteLength;
|
|
379
|
+
});
|
|
380
|
+
return object;
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The array is a fixed-size type: it has a fixed-size inner type and a fixed length.
|
|
386
|
+
* The size of an array is the size of inner type times the length.
|
|
387
|
+
* @param itemCodec the fixed-size array item codec
|
|
388
|
+
* @param itemCount
|
|
389
|
+
*/
|
|
390
|
+
function array(itemCodec, itemCount) {
|
|
391
|
+
if (itemCodec.byteLength === undefined) {
|
|
392
|
+
throw new Error("array: itemCodec requires a byte length");
|
|
393
|
+
}
|
|
394
|
+
const byteLength = itemCodec.byteLength * itemCount;
|
|
395
|
+
return Codec.from({
|
|
396
|
+
byteLength,
|
|
397
|
+
encode(items) {
|
|
398
|
+
try {
|
|
399
|
+
return items.reduce((concatted, item) => (0, index_js_1.bytesConcat)(concatted, itemCodec.encode(item)), (0, index_js_1.bytesFrom)([]));
|
|
400
|
+
}
|
|
401
|
+
catch (e) {
|
|
402
|
+
throw new Error(`array(${e?.toString()})`);
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
decode(buffer) {
|
|
406
|
+
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
407
|
+
if (value.byteLength != byteLength) {
|
|
408
|
+
throw new Error(`array: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
const result = [];
|
|
412
|
+
for (let i = 0; i < value.byteLength; i += itemCodec.byteLength) {
|
|
413
|
+
result.push(itemCodec.decode(value.slice(i, i + itemCodec.byteLength)));
|
|
414
|
+
}
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
catch (e) {
|
|
418
|
+
throw new Error(`array(${e?.toString()})`);
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Create a codec to deal with fixed LE or BE bytes.
|
|
425
|
+
* @param byteLength
|
|
426
|
+
* @param littleEndian
|
|
427
|
+
*/
|
|
428
|
+
function uint(byteLength, littleEndian = false) {
|
|
429
|
+
return Codec.from({
|
|
430
|
+
byteLength,
|
|
431
|
+
encode: (numLike) => {
|
|
432
|
+
if (littleEndian) {
|
|
433
|
+
return (0, index_js_2.numToBytes)(numLike, byteLength);
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
return (0, index_js_2.numBeToBytes)(numLike, byteLength);
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
decode: (buffer) => {
|
|
440
|
+
if (littleEndian) {
|
|
441
|
+
return (0, index_js_2.numFromBytes)(buffer);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
return (0, index_js_2.numBeFromBytes)(buffer);
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Create a codec to deal with fixed LE or BE bytes.
|
|
451
|
+
* @param byteLength
|
|
452
|
+
* @param littleEndian
|
|
453
|
+
*/
|
|
454
|
+
function uintNumber(byteLength, littleEndian = false) {
|
|
455
|
+
if (byteLength > 4) {
|
|
456
|
+
throw new Error("uintNumber: byteLength must be less than or equal to 4");
|
|
457
|
+
}
|
|
458
|
+
return uint(byteLength, littleEndian).map({
|
|
459
|
+
outMap: (num) => Number(num),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/molecule/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|