@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,461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./codec.js"), exports);
|
|
18
|
+
__exportStar(require("./predefined.js"), exports);
|
|
@@ -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":"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"}
|
|
@@ -0,0 +1,121 @@
|
|
|
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.CellDepVec = exports.CellDep = exports.DepType = exports.CellOutputVec = exports.CellOutput = exports.CellInputVec = exports.CellInput = exports.OutPoint = exports.ScriptOpt = exports.Script = exports.HashType = exports.Hash = exports.StringOpt = exports.StringVec = exports.String = exports.Byte32Vec = exports.Byte32Opt = exports.Byte32 = exports.BytesVec = exports.BytesOpt = exports.Bytes = exports.Uint512Opt = exports.Uint256Opt = exports.Uint128Opt = exports.Uint64Opt = exports.Uint32Opt = exports.Uint16Opt = exports.Uint8Opt = exports.Uint512 = exports.Uint512BE = exports.Uint512LE = exports.Uint256 = exports.Uint256BE = exports.Uint256LE = exports.Uint128 = exports.Uint128BE = exports.Uint128LE = exports.Uint64 = exports.Uint64BE = exports.Uint64LE = exports.Uint32 = exports.Uint32BE = exports.Uint32LE = exports.Uint16 = exports.Uint16BE = exports.Uint16LE = exports.Uint8 = void 0;
|
|
27
|
+
const index_js_1 = require("../bytes/index.js");
|
|
28
|
+
const ckb = __importStar(require("../ckb/index.js"));
|
|
29
|
+
const index_js_2 = require("../hex/index.js");
|
|
30
|
+
const codec_js_1 = require("./codec.js");
|
|
31
|
+
exports.Uint8 = (0, codec_js_1.uintNumber)(1, true);
|
|
32
|
+
exports.Uint16LE = (0, codec_js_1.uintNumber)(2, true);
|
|
33
|
+
exports.Uint16BE = (0, codec_js_1.uintNumber)(2);
|
|
34
|
+
exports.Uint16 = exports.Uint16LE;
|
|
35
|
+
exports.Uint32LE = (0, codec_js_1.uintNumber)(4, true);
|
|
36
|
+
exports.Uint32BE = (0, codec_js_1.uintNumber)(4);
|
|
37
|
+
exports.Uint32 = exports.Uint32LE;
|
|
38
|
+
exports.Uint64LE = (0, codec_js_1.uint)(8, true);
|
|
39
|
+
exports.Uint64BE = (0, codec_js_1.uint)(8);
|
|
40
|
+
exports.Uint64 = exports.Uint64LE;
|
|
41
|
+
exports.Uint128LE = (0, codec_js_1.uint)(16, true);
|
|
42
|
+
exports.Uint128BE = (0, codec_js_1.uint)(16);
|
|
43
|
+
exports.Uint128 = exports.Uint128LE;
|
|
44
|
+
exports.Uint256LE = (0, codec_js_1.uint)(32, true);
|
|
45
|
+
exports.Uint256BE = (0, codec_js_1.uint)(32);
|
|
46
|
+
exports.Uint256 = exports.Uint256LE;
|
|
47
|
+
exports.Uint512LE = (0, codec_js_1.uint)(64, true);
|
|
48
|
+
exports.Uint512BE = (0, codec_js_1.uint)(64);
|
|
49
|
+
exports.Uint512 = exports.Uint512LE;
|
|
50
|
+
exports.Uint8Opt = (0, codec_js_1.option)(exports.Uint8);
|
|
51
|
+
exports.Uint16Opt = (0, codec_js_1.option)(exports.Uint16);
|
|
52
|
+
exports.Uint32Opt = (0, codec_js_1.option)(exports.Uint32);
|
|
53
|
+
exports.Uint64Opt = (0, codec_js_1.option)(exports.Uint64);
|
|
54
|
+
exports.Uint128Opt = (0, codec_js_1.option)(exports.Uint128);
|
|
55
|
+
exports.Uint256Opt = (0, codec_js_1.option)(exports.Uint256);
|
|
56
|
+
exports.Uint512Opt = (0, codec_js_1.option)(exports.Uint512);
|
|
57
|
+
exports.Bytes = (0, codec_js_1.byteVec)({
|
|
58
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
59
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
60
|
+
});
|
|
61
|
+
exports.BytesOpt = (0, codec_js_1.option)(exports.Bytes);
|
|
62
|
+
exports.BytesVec = (0, codec_js_1.vector)(exports.Bytes);
|
|
63
|
+
exports.Byte32 = codec_js_1.Codec.from({
|
|
64
|
+
byteLength: 32,
|
|
65
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
66
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
67
|
+
});
|
|
68
|
+
exports.Byte32Opt = (0, codec_js_1.option)(exports.Byte32);
|
|
69
|
+
exports.Byte32Vec = (0, codec_js_1.vector)(exports.Byte32);
|
|
70
|
+
exports.String = (0, codec_js_1.byteVec)({
|
|
71
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value, "utf8"),
|
|
72
|
+
decode: (buffer) => (0, index_js_1.bytesTo)(buffer, "utf8"),
|
|
73
|
+
});
|
|
74
|
+
exports.StringVec = (0, codec_js_1.vector)(exports.String);
|
|
75
|
+
exports.StringOpt = (0, codec_js_1.option)(exports.String);
|
|
76
|
+
exports.Hash = exports.Byte32;
|
|
77
|
+
exports.HashType = codec_js_1.Codec.from({
|
|
78
|
+
byteLength: 1,
|
|
79
|
+
encode: ckb.hashTypeToBytes,
|
|
80
|
+
decode: ckb.hashTypeFromBytes,
|
|
81
|
+
});
|
|
82
|
+
exports.Script = (0, codec_js_1.table)({
|
|
83
|
+
codeHash: exports.Hash,
|
|
84
|
+
hashType: exports.HashType,
|
|
85
|
+
args: exports.Bytes,
|
|
86
|
+
}).map({ outMap: ckb.Script.from });
|
|
87
|
+
exports.ScriptOpt = (0, codec_js_1.option)(exports.Script);
|
|
88
|
+
exports.OutPoint = (0, codec_js_1.struct)({
|
|
89
|
+
txHash: exports.Hash,
|
|
90
|
+
index: exports.Uint32,
|
|
91
|
+
}).map({ outMap: ckb.OutPoint.from });
|
|
92
|
+
exports.CellInput = (0, codec_js_1.struct)({
|
|
93
|
+
previousOutput: exports.OutPoint,
|
|
94
|
+
since: exports.Uint64,
|
|
95
|
+
}).map({ outMap: ckb.CellInput.from });
|
|
96
|
+
exports.CellInputVec = (0, codec_js_1.vector)(exports.CellInput);
|
|
97
|
+
exports.CellOutput = (0, codec_js_1.table)({
|
|
98
|
+
capacity: exports.Uint64,
|
|
99
|
+
lock: exports.Script,
|
|
100
|
+
type: exports.ScriptOpt,
|
|
101
|
+
}).map({ outMap: ckb.CellOutput.from });
|
|
102
|
+
exports.CellOutputVec = (0, codec_js_1.vector)(exports.CellOutput);
|
|
103
|
+
exports.DepType = codec_js_1.Codec.from({
|
|
104
|
+
byteLength: 1,
|
|
105
|
+
encode: ckb.depTypeToBytes,
|
|
106
|
+
decode: ckb.depTypeFromBytes,
|
|
107
|
+
});
|
|
108
|
+
exports.CellDep = (0, codec_js_1.struct)({
|
|
109
|
+
outPoint: exports.OutPoint,
|
|
110
|
+
depType: exports.DepType,
|
|
111
|
+
}).map({ outMap: ckb.CellDep.from });
|
|
112
|
+
exports.CellDepVec = (0, codec_js_1.vector)(exports.CellDep);
|
|
113
|
+
exports.Transaction = (0, codec_js_1.table)({
|
|
114
|
+
version: exports.Uint32,
|
|
115
|
+
cellDeps: exports.CellDepVec,
|
|
116
|
+
headerDeps: exports.Byte32Vec,
|
|
117
|
+
inputs: exports.CellInputVec,
|
|
118
|
+
outputs: exports.CellOutputVec,
|
|
119
|
+
outputsData: exports.BytesVec,
|
|
120
|
+
witnesses: exports.BytesVec,
|
|
121
|
+
}).map({ outMap: ckb.Transaction.from });
|