solidity-codecs 0.1.2 → 0.2.0
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/dist/codecs/BytesX.d.ts +1 -1
- package/dist/codecs/Tuple.d.ts +1 -1
- package/dist/codecs/bool.d.ts +1 -1
- package/dist/codecs/str.d.ts +1 -1
- package/dist/solidity-codecs.cjs.development.js +93 -50
- package/dist/solidity-codecs.cjs.development.js.map +3 -3
- package/dist/solidity-codecs.cjs.production.min.js +1 -1
- package/dist/solidity-codecs.cjs.production.min.js.map +3 -3
- package/dist/solidity-codecs.js +92 -49
- package/dist/solidity-codecs.js.map +3 -3
- package/dist/solidity-codecs.mjs +92 -49
- package/dist/solidity-codecs.mjs.map +3 -3
- package/dist/types.d.ts +6 -3
- package/dist/utils.d.ts +0 -1
- package/package.json +1 -1
- package/dist/codecs/Bytes.d.ts +0 -6
package/dist/solidity-codecs.mjs
CHANGED
|
@@ -5,26 +5,17 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// src/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// src/internal/createCodec.ts
|
|
9
|
+
var createCodec = (encoder, decoder, selector) => {
|
|
10
|
+
;
|
|
11
|
+
encoder.s = selector;
|
|
12
|
+
decoder.s = selector;
|
|
12
13
|
const result = [encoder, decoder];
|
|
13
14
|
result.enc = encoder;
|
|
14
15
|
result.dec = decoder;
|
|
16
|
+
result.s = selector;
|
|
15
17
|
return result;
|
|
16
18
|
};
|
|
17
|
-
var dyn = (input, output) => {
|
|
18
|
-
if (input.dyn)
|
|
19
|
-
output.dyn = true;
|
|
20
|
-
return output;
|
|
21
|
-
};
|
|
22
|
-
var enhanceEncoder = (encoder, mapper) => dyn(encoder, (value) => encoder(mapper(value)));
|
|
23
|
-
var enhanceDecoder = (decoder, mapper) => dyn(decoder, (value) => mapper(decoder(value)));
|
|
24
|
-
var enhanceCodec = (codec, toFrom, fromTo) => dyn(codec, createCodec(enhanceEncoder(codec[0], toFrom), enhanceDecoder(codec[1], fromTo)));
|
|
25
|
-
|
|
26
|
-
// src/codecs/address.ts
|
|
27
|
-
import { fromHex as fromHex2, toHex } from "@unstoppablejs/utils";
|
|
28
19
|
|
|
29
20
|
// src/internal/toInternalBytes.ts
|
|
30
21
|
import { fromHex } from "@unstoppablejs/utils";
|
|
@@ -41,7 +32,21 @@ var toInternalBytes = (fn) => (buffer) => fn(buffer instanceof InternalUint8Arra
|
|
|
41
32
|
// src/internal/range32.ts
|
|
42
33
|
var range32 = Array(32).fill(0).map((_, idx) => idx + 1);
|
|
43
34
|
|
|
35
|
+
// src/utils.ts
|
|
36
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
37
|
+
var keccak = keccak_256;
|
|
38
|
+
var dyn = (input, output) => {
|
|
39
|
+
if (input.d)
|
|
40
|
+
output.d = true;
|
|
41
|
+
output.s = input.s;
|
|
42
|
+
return output;
|
|
43
|
+
};
|
|
44
|
+
var enhanceEncoder = (encoder, mapper) => dyn(encoder, (value) => encoder(mapper(value)));
|
|
45
|
+
var enhanceDecoder = (decoder, mapper) => dyn(decoder, (value) => mapper(decoder(value)));
|
|
46
|
+
var enhanceCodec = (codec, toFrom, fromTo) => dyn(codec, createCodec(enhanceEncoder(codec[0], toFrom), enhanceDecoder(codec[1], fromTo), codec.s));
|
|
47
|
+
|
|
44
48
|
// src/codecs/address.ts
|
|
49
|
+
import { fromHex as fromHex2, toHex } from "@unstoppablejs/utils";
|
|
45
50
|
var address = createCodec((input) => {
|
|
46
51
|
const result = new Uint8Array(32);
|
|
47
52
|
result.set(fromHex2(input), 12);
|
|
@@ -58,7 +63,7 @@ var address = createCodec((input) => {
|
|
|
58
63
|
result.push(parseInt(hashedAddres[i], 16) > 7 ? char.toUpperCase() : char);
|
|
59
64
|
}
|
|
60
65
|
return result.join("");
|
|
61
|
-
}));
|
|
66
|
+
}), "address");
|
|
62
67
|
|
|
63
68
|
// src/codecs/Uint.ts
|
|
64
69
|
var getCodec = (nBytes) => {
|
|
@@ -79,7 +84,7 @@ var getCodec = (nBytes) => {
|
|
|
79
84
|
result = result << 64n | bytes33.v.getBigUint64(idx);
|
|
80
85
|
bytes33.i = nextBlock;
|
|
81
86
|
return result;
|
|
82
|
-
}));
|
|
87
|
+
}), "uint" + nBytes);
|
|
83
88
|
};
|
|
84
89
|
var [
|
|
85
90
|
uint8,
|
|
@@ -118,7 +123,9 @@ var [
|
|
|
118
123
|
var uint = uint256;
|
|
119
124
|
|
|
120
125
|
// src/codecs/bool.ts
|
|
121
|
-
var
|
|
126
|
+
var base = Object.assign([], uint8);
|
|
127
|
+
base.s = "bool";
|
|
128
|
+
var bool = enhanceCodec(base, (value) => value ? 1n : 0n, Boolean);
|
|
122
129
|
|
|
123
130
|
// src/codecs/bytes.ts
|
|
124
131
|
import { mergeUint8 } from "@unstoppablejs/utils";
|
|
@@ -131,21 +138,26 @@ var bytesEnc = (val) => {
|
|
|
131
138
|
}
|
|
132
139
|
return mergeUint8(...args);
|
|
133
140
|
};
|
|
134
|
-
bytesEnc.
|
|
141
|
+
bytesEnc.d = true;
|
|
135
142
|
var bytesDec = toInternalBytes((bytes33) => {
|
|
136
143
|
let nElements = Number(uint[1](bytes33));
|
|
137
144
|
const result = new Uint8Array(bytes33.buffer, bytes33.i, nElements);
|
|
138
|
-
bytes33.i += nElements
|
|
145
|
+
bytes33.i += nElements;
|
|
146
|
+
const extra = nElements % 32;
|
|
147
|
+
if (extra > 0)
|
|
148
|
+
bytes33.i += 32 - extra;
|
|
139
149
|
return result;
|
|
140
150
|
});
|
|
141
|
-
bytesDec.
|
|
142
|
-
var bytes = createCodec(bytesEnc, bytesDec);
|
|
143
|
-
bytes.
|
|
151
|
+
bytesDec.d = true;
|
|
152
|
+
var bytes = createCodec(bytesEnc, bytesDec, "bytes");
|
|
153
|
+
bytes.d = true;
|
|
144
154
|
|
|
145
155
|
// src/codecs/str.ts
|
|
146
156
|
var textEncoder = new TextEncoder();
|
|
147
157
|
var textDecoder = new TextDecoder();
|
|
148
|
-
var
|
|
158
|
+
var base2 = Object.assign([], bytes);
|
|
159
|
+
base2.s = "string";
|
|
160
|
+
var str = enhanceCodec(base2, textEncoder.encode.bind(textEncoder), textDecoder.decode.bind(textDecoder));
|
|
149
161
|
|
|
150
162
|
// src/codecs/BytesX.ts
|
|
151
163
|
var bytesEnc2 = (nBytes) => (bytes33) => {
|
|
@@ -193,7 +205,7 @@ var [
|
|
|
193
205
|
bytes30,
|
|
194
206
|
bytes31,
|
|
195
207
|
bytes32
|
|
196
|
-
] = range32.map((nBytes) => createCodec(bytesEnc2(nBytes), bytesDec2(nBytes)));
|
|
208
|
+
] = range32.map((nBytes) => createCodec(bytesEnc2(nBytes), bytesDec2(nBytes), "bytes" + nBytes));
|
|
197
209
|
|
|
198
210
|
// src/codecs/Int.ts
|
|
199
211
|
var signGetters = {
|
|
@@ -257,7 +269,7 @@ var getCodec2 = (nBytes) => {
|
|
|
257
269
|
bytes33.i += 32;
|
|
258
270
|
return result;
|
|
259
271
|
});
|
|
260
|
-
return createCodec(enc, dec);
|
|
272
|
+
return createCodec(enc, dec, "int" + nBytes);
|
|
261
273
|
};
|
|
262
274
|
var [
|
|
263
275
|
int8,
|
|
@@ -296,7 +308,12 @@ var [
|
|
|
296
308
|
var int = int256;
|
|
297
309
|
|
|
298
310
|
// src/codecs/Fixed.ts
|
|
299
|
-
var Fixed = (baseCodec, decimals) =>
|
|
311
|
+
var Fixed = (baseCodec, decimals) => {
|
|
312
|
+
const baseSelector = baseCodec.s;
|
|
313
|
+
const eBaseCodec = Object.assign([], baseCodec);
|
|
314
|
+
eBaseCodec.s = (baseSelector[0] === "u" ? "ufixed" + baseSelector.slice(4) : "fixed" + baseSelector.slice(3)) + "x" + decimals;
|
|
315
|
+
return enhanceCodec(eBaseCodec, (x) => x.value, (value) => ({ value, decimals }));
|
|
316
|
+
};
|
|
300
317
|
|
|
301
318
|
// src/codecs/Tuple.ts
|
|
302
319
|
import { mergeUint8 as mergeUint82 } from "@unstoppablejs/utils";
|
|
@@ -307,7 +324,7 @@ var dynamicEnc = (...encoders) => {
|
|
|
307
324
|
const dinamics = [];
|
|
308
325
|
let len = 0n;
|
|
309
326
|
for (let i = 0; i < encoders.length; i++) {
|
|
310
|
-
if (encoders[i].
|
|
327
|
+
if (encoders[i].d) {
|
|
311
328
|
dinamics.push(i);
|
|
312
329
|
len += 32n;
|
|
313
330
|
} else {
|
|
@@ -323,7 +340,7 @@ var dynamicEnc = (...encoders) => {
|
|
|
323
340
|
});
|
|
324
341
|
return mergeUint82(...resultArray);
|
|
325
342
|
};
|
|
326
|
-
res.
|
|
343
|
+
res.d = true;
|
|
327
344
|
return res;
|
|
328
345
|
};
|
|
329
346
|
var staticEnc = (...encoders) => (values) => mergeUint82(...values.map((value, idx) => encoders[idx](value)));
|
|
@@ -333,7 +350,7 @@ var dynamicDec = (...decoders) => {
|
|
|
333
350
|
const result = new Array(decoders.length);
|
|
334
351
|
let start = bytes33.i;
|
|
335
352
|
for (let i = 0; i < decoders.length; i++) {
|
|
336
|
-
if (decoders[i].
|
|
353
|
+
if (decoders[i].d) {
|
|
337
354
|
const offset = Number(uint[1](bytes33));
|
|
338
355
|
const current = bytes33.i;
|
|
339
356
|
bytes33.i = start + offset;
|
|
@@ -345,14 +362,14 @@ var dynamicDec = (...decoders) => {
|
|
|
345
362
|
}
|
|
346
363
|
return result;
|
|
347
364
|
});
|
|
348
|
-
res.
|
|
365
|
+
res.d = true;
|
|
349
366
|
return res;
|
|
350
367
|
};
|
|
351
368
|
var Tuple = (...codecs) => {
|
|
352
|
-
const isDyn = codecs.some((c) => c.
|
|
369
|
+
const isDyn = codecs.some((c) => c.d);
|
|
353
370
|
const [enc, dec] = isDyn ? [dynamicEnc, dynamicDec] : [staticEnc, staticDec];
|
|
354
|
-
const res = createCodec(enc(...codecs.map(([encoder]) => encoder)), dec(...codecs.map(([, decoder]) => decoder)));
|
|
355
|
-
res.
|
|
371
|
+
const res = createCodec(enc(...codecs.map(([encoder]) => encoder)), dec(...codecs.map(([, decoder]) => decoder)), `(${codecs.map((c) => c.s).join(",")})`);
|
|
372
|
+
res.d = isDyn;
|
|
356
373
|
return res;
|
|
357
374
|
};
|
|
358
375
|
|
|
@@ -365,32 +382,59 @@ var Struct = (codecs) => {
|
|
|
365
382
|
// src/codecs/Vector.ts
|
|
366
383
|
import { mergeUint8 as mergeUint83 } from "@unstoppablejs/utils";
|
|
367
384
|
var vectorEnc = (inner, size) => {
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
385
|
+
const result = (value) => {
|
|
386
|
+
const isNotFixed = size == null ? 1 : 0;
|
|
387
|
+
const actualSize = isNotFixed ? value.length : size;
|
|
388
|
+
let data;
|
|
389
|
+
if (inner.d) {
|
|
390
|
+
data = new Array(actualSize * 2);
|
|
391
|
+
let offset = actualSize * 32;
|
|
392
|
+
for (let i = 0; i < actualSize; i++) {
|
|
393
|
+
const encoded = inner(value[i]);
|
|
394
|
+
data[i] = uint.enc(BigInt(offset));
|
|
395
|
+
offset += encoded.byteLength;
|
|
396
|
+
data[i + actualSize] = encoded;
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
data = new Array(actualSize);
|
|
400
|
+
for (let i = 0; i < actualSize; i++)
|
|
401
|
+
data[i] = inner(value[i]);
|
|
402
|
+
}
|
|
403
|
+
if (isNotFixed)
|
|
404
|
+
data.unshift(uint.enc(BigInt(value.length)));
|
|
405
|
+
return mergeUint83(...data);
|
|
406
|
+
};
|
|
407
|
+
result.d = true;
|
|
408
|
+
return result;
|
|
376
409
|
};
|
|
377
410
|
var vectorDec = (getter, size) => {
|
|
378
411
|
const decoder = toInternalBytes((bytes33) => {
|
|
379
412
|
const nElements = size >= 0 ? size : Number(uint[1](bytes33));
|
|
380
413
|
const decoded = new Array(nElements);
|
|
381
|
-
|
|
382
|
-
|
|
414
|
+
if (getter.d) {
|
|
415
|
+
const init = bytes33.i;
|
|
416
|
+
let current = init;
|
|
417
|
+
for (let i = 0; i < nElements; i++) {
|
|
418
|
+
bytes33.i = current;
|
|
419
|
+
const offset = Number(uint.dec(bytes33));
|
|
420
|
+
current = bytes33.i;
|
|
421
|
+
bytes33.i = init + offset;
|
|
422
|
+
decoded[i] = getter(bytes33);
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
for (let i = 0; i < nElements; i++) {
|
|
426
|
+
decoded[i] = getter(bytes33);
|
|
427
|
+
}
|
|
383
428
|
}
|
|
384
429
|
return decoded;
|
|
385
430
|
});
|
|
386
|
-
|
|
387
|
-
decoder.dyn = true;
|
|
431
|
+
decoder.d = true;
|
|
388
432
|
return decoder;
|
|
389
433
|
};
|
|
390
434
|
var Vector = (inner, size) => {
|
|
391
|
-
const codec = createCodec(vectorEnc(inner[0], size), vectorDec(inner[1], size));
|
|
435
|
+
const codec = createCodec(vectorEnc(inner[0], size), vectorDec(inner[1], size), inner.s + `[${size == null ? "" : size}]`);
|
|
392
436
|
if (size == null)
|
|
393
|
-
codec.
|
|
437
|
+
codec.d = true;
|
|
394
438
|
return codec;
|
|
395
439
|
};
|
|
396
440
|
export {
|
|
@@ -433,7 +477,6 @@ export {
|
|
|
433
477
|
bytes7,
|
|
434
478
|
bytes8,
|
|
435
479
|
bytes9,
|
|
436
|
-
createCodec,
|
|
437
480
|
enhanceCodec,
|
|
438
481
|
enhanceDecoder,
|
|
439
482
|
enhanceEncoder,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import type { Codec, Decoder, Encoder } from \"./types\"\nimport { keccak_256 } from \"@noble/hashes/sha3\"\n\nexport const keccak = keccak_256\n\nexport const createCodec = <T>(\n encoder: Encoder<T>,\n decoder: Decoder<T>,\n): Codec<T> => {\n const result = [encoder, decoder] as any\n result.enc = encoder\n result.dec = decoder\n return result\n}\n\nconst dyn = <T extends { dyn?: boolean }>(\n input: { dyn?: boolean },\n output: T,\n): T => {\n if (input.dyn) output.dyn = true\n return output\n}\n\nexport const enhanceEncoder = <I, O>(\n encoder: Encoder<I>,\n mapper: (value: O) => I,\n): Encoder<O> => dyn(encoder, ((value) => encoder(mapper(value))) as Encoder<O>)\n\nexport const enhanceDecoder = <I, O>(\n decoder: Decoder<I>,\n mapper: (value: I) => O,\n): Decoder<O> => dyn(decoder, ((value) => mapper(decoder(value))) as Decoder<O>)\n\nexport const enhanceCodec = <I, O>(\n codec: Codec<I>,\n toFrom: (value: O) => I,\n fromTo: (value: I) => O,\n): Codec<O> =>\n dyn(\n codec,\n createCodec(\n enhanceEncoder(codec[0], toFrom),\n enhanceDecoder(codec[1], fromTo),\n ),\n )\n", "import { fromHex, toHex } from \"@unstoppablejs/utils\"\nimport { toInternalBytes } from \"../internal\"\nimport { createCodec, keccak } from \"../utils\"\n\nexport const address = createCodec(\n (input: string) => {\n const result = new Uint8Array(32)\n result.set(fromHex(input), 12)\n return result\n },\n toInternalBytes((bytes) => {\n const binaryAddress = new Uint8Array(bytes.buffer, bytes.i + 12, 20)\n bytes.i += 32\n const nonChecksum = toHex(binaryAddress)\n const hashedAddres = toHex(keccak(nonChecksum.slice(2)))\n\n const result = new Array(41)\n result[0] = \"0x\"\n for (let i = 2; i < 42; i++) {\n const char = nonChecksum[i]\n result.push(parseInt(hashedAddres[i], 16) > 7 ? char.toUpperCase() : char)\n }\n\n return result.join(\"\")\n }),\n)\n", "import { fromHex } from \"@unstoppablejs/utils\"\nimport { Decoder } from \"../types\"\n\nclass InternalUint8Array extends Uint8Array {\n i: number = 0\n v: DataView\n\n constructor(buffer: ArrayBuffer) {\n super(buffer)\n this.v = new DataView(buffer)\n }\n}\n\nexport const toInternalBytes =\n <T>(fn: (input: InternalUint8Array) => T): Decoder<T> =>\n (buffer: string | ArrayBuffer | Uint8Array | InternalUint8Array) =>\n fn(\n buffer instanceof InternalUint8Array\n ? buffer\n : new InternalUint8Array(\n buffer instanceof Uint8Array\n ? buffer.buffer\n : typeof buffer === \"string\"\n ? fromHex(buffer).buffer\n : buffer,\n ),\n )\n", "export const range32 = Array(32)\n .fill(0)\n .map((_, idx) => idx + 1)\n", "import { Codec } from \"../types\"\nimport { range32, toInternalBytes } from \"../internal\"\nimport { createCodec } from \"../utils\"\n\nconst getCodec = (nBytes: number): Codec<bigint> => {\n const n64 = Math.ceil(nBytes / 8)\n return createCodec(\n (input) => {\n const result = new Uint8Array(32)\n const dv = new DataView(result.buffer)\n\n const idxLimit = 32 - n64 * 8\n for (let idx = 24; idx >= idxLimit; idx -= 8) {\n dv.setBigUint64(idx, input)\n input >>= 64n\n }\n\n return result\n },\n toInternalBytes((bytes) => {\n let result = 0n\n\n const nextBlock = bytes.i + 32\n for (let idx = bytes.i + (32 - n64 * 8); idx < nextBlock; idx += 8)\n result = (result << 64n) | bytes.v.getBigUint64(idx)\n\n bytes.i = nextBlock\n return result\n }),\n )\n}\n\nexport const [\n uint8,\n uint16,\n uint24,\n uint32,\n uint40,\n uint48,\n uint56,\n uint64,\n uint72,\n uint80,\n uint88,\n uint96,\n uint104,\n uint112,\n uint120,\n uint128,\n uint136,\n uint144,\n uint152,\n uint160,\n uint168,\n uint176,\n uint184,\n uint192,\n uint200,\n uint208,\n uint226,\n uint224,\n uint232,\n uint240,\n uint248,\n uint256,\n] = range32.map(getCodec)\nexport const uint = uint256\n", "import { Codec } from \"../types\"\nimport { enhanceCodec } from \"../\"\nimport { uint8 } from \"./Uint\"\n\nexport const bool: Codec<boolean> = enhanceCodec(\n uint8,\n (value: boolean) => (value ? 1n : 0n),\n Boolean,\n)\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport { createCodec, Decoder, Encoder } from \"../\"\nimport { toInternalBytes } from \"../internal\"\nimport { uint } from \"./Uint\"\n\nconst bytesEnc: Encoder<Uint8Array> = (val) => {\n const args = [uint[0](BigInt(val.length)), val] as const\n const extra = val.length % 32\n if (extra > 0) {\n ;(args as any).push(new Uint8Array(32 - extra))\n }\n return mergeUint8(...args)\n}\nbytesEnc.dyn = true\n\nconst bytesDec: Decoder<Uint8Array> = toInternalBytes((bytes) => {\n let nElements = Number(uint[1](bytes))\n const result = new Uint8Array(bytes.buffer, bytes.i, nElements)\n bytes.i += nElements + (nElements % 32)\n return result\n})\nbytesDec.dyn = true\n\nexport const bytes = createCodec(bytesEnc, bytesDec)\nbytes.dyn = true\n", "import { enhanceCodec } from \"../\"\nimport { bytes } from \"./bytes\"\n\nconst textEncoder = new TextEncoder()\nconst textDecoder = new TextDecoder()\n\nexport const str = enhanceCodec<Uint8Array, string>(\n bytes,\n textEncoder.encode.bind(textEncoder),\n textDecoder.decode.bind(textDecoder),\n)\n", "import { Encoder, Decoder, Codec } from \"../types\"\nimport { createCodec } from \"../\"\nimport { range32, toInternalBytes } from \"../internal\"\n\nconst bytesEnc =\n (nBytes: number): Encoder<Uint8Array> =>\n (bytes) => {\n if (bytes.length === nBytes && nBytes === 32) return bytes\n const result = new Uint8Array(32)\n result.set(bytes.length === nBytes ? bytes : bytes.slice(0, nBytes))\n return result\n }\n\nconst bytesDec = (nBytes: number): Decoder<Uint8Array> =>\n toInternalBytes((bytes) => {\n const result = new Uint8Array(bytes.buffer, bytes.i, nBytes)\n bytes.i += 32\n return result\n })\n\nexport const [\n bytes1,\n bytes2,\n bytes3,\n bytes4,\n bytes5,\n bytes6,\n bytes7,\n bytes8,\n bytes9,\n bytes10,\n bytes11,\n bytes12,\n bytes13,\n bytes14,\n bytes15,\n bytes16,\n bytes17,\n bytes18,\n bytes19,\n bytes20,\n bytes21,\n bytes22,\n bytes23,\n bytes24,\n bytes25,\n bytes26,\n bytes27,\n bytes28,\n bytes29,\n bytes30,\n bytes31,\n bytes32,\n] = range32.map(\n (nBytes: number): Codec<Uint8Array> =>\n createCodec(bytesEnc(nBytes), bytesDec(nBytes)),\n)\n", "import { Encoder, Codec } from \"../types\"\nimport { range32, toInternalBytes } from \"../internal\"\nimport { createCodec } from \"../utils\"\n\nconst signGetters: Record<1 | 2 | 8, \"getBigInt64\" | \"getInt16\" | \"getInt8\"> = {\n \"1\": \"getInt8\",\n \"2\": \"getInt16\",\n \"8\": \"getBigInt64\",\n}\n\nconst signSetters: Record<1 | 2 | 8, \"setBigInt64\" | \"setInt16\" | \"setInt8\"> = {\n \"1\": \"setInt8\",\n \"2\": \"setInt16\",\n \"8\": \"setBigInt64\",\n}\n\nconst usignGetters: Record<\n 1 | 2 | 8,\n \"getBigUint64\" | \"getUint16\" | \"getUint8\"\n> = {\n \"1\": \"getUint8\",\n \"2\": \"getUint16\",\n \"8\": \"getBigUint64\",\n}\n\nconst usignSetters: Record<\n 1 | 2 | 8,\n \"setBigUint64\" | \"setUint16\" | \"setUint8\"\n> = {\n \"1\": \"setUint8\",\n \"2\": \"setUint16\",\n \"8\": \"setBigUint64\",\n}\n\nconst getCodec = (nBytes: number): Codec<bigint> => {\n const n64 = (nBytes / 8) | 0\n const n16 = ((nBytes % 8) / 2) | 0\n const sequence = [\n ...Array(n64).fill([8, 64n, (x: bigint) => x]),\n ...Array(n16).fill([2, 16n, (x: bigint) => Number(x & 65535n)]),\n ]\n if (nBytes % 2) sequence.push([1, 8n, (x: bigint) => Number(x & 255n)])\n\n const enc: Encoder<bigint> = (input) => {\n const result = new Uint8Array(32)\n const dv = new DataView(result.buffer)\n\n if (input < 0n) {\n for (let i = 0; i < 32 - nBytes; i += 8) dv.setBigInt64(i, -1n)\n }\n\n let idx = 32\n for (let i = sequence.length - 1; i > 0; i--) {\n const [bytes, shift, fn] = sequence[i] as [1, 8n, (x: bigint) => any]\n idx -= bytes\n dv[usignSetters[bytes]](idx, fn(input) as never)\n input >>= shift\n }\n const [bytes, , fn] = sequence[0] as [1, 8n, (x: bigint) => any]\n idx -= bytes\n dv[signSetters[bytes]](idx, fn(input) as never)\n\n return result\n }\n\n const dec = toInternalBytes((bytes) => {\n let idx = bytes.i + 32 - nBytes\n\n const bits = sequence[0][0] as 8\n let result = BigInt(bytes.v[signGetters[bits]](idx))\n idx += bits\n\n for (let i = 1; i < sequence.length; i++) {\n const [bits, shift] = sequence[i] as [1, 8n]\n result = (result << shift) | BigInt(bytes.v[usignGetters[bits]](idx))\n idx += bits\n }\n\n bytes.i += 32\n return result\n })\n\n return createCodec(enc, dec)\n}\n\nexport const [\n int8,\n int16,\n int24,\n int32,\n int40,\n int48,\n int56,\n int64,\n int72,\n int80,\n int88,\n int96,\n int104,\n int112,\n int120,\n int128,\n int136,\n int144,\n int152,\n int160,\n int168,\n int176,\n int184,\n int192,\n int200,\n int208,\n int226,\n int224,\n int232,\n int240,\n int248,\n int256,\n] = range32.map(getCodec)\nexport const int = int256\n", "import { Codec } from \"../types\"\nimport { enhanceCodec } from \"../utils\"\n\nexport interface Decimal<T extends number = number> {\n value: bigint\n decimals: T\n}\n\nexport const Fixed = <D extends number>(\n baseCodec: Codec<bigint>,\n decimals: D,\n) =>\n enhanceCodec<bigint, Decimal<D>>(\n baseCodec,\n (x) => x.value,\n (value) => ({ value, decimals }),\n )\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport { Codec, Decoder, Encoder } from \"../types\"\nimport { uint } from \"./Uint\"\nimport { toInternalBytes } from \"../internal\"\nimport { createCodec } from \"../utils\"\n\nconst dynamicEnc = <\n A extends Array<Encoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Encoder<infer D> ? D : unknown },\n>(\n ...encoders: A\n): Encoder<[...OT]> => {\n const res: Encoder<[...OT]> = (values) => {\n const mapped = values.map((value, idx) => encoders[idx](value))\n const resultArray = new Array<Uint8Array>(encoders.length)\n const dinamics = []\n let len = 0n\n for (let i = 0; i < encoders.length; i++) {\n if (encoders[i].dyn) {\n dinamics.push(i)\n len += 32n\n } else {\n resultArray[i] = mapped[i]\n len += BigInt(mapped[i].length)\n }\n }\n\n dinamics.forEach((idx) => {\n resultArray[idx] = uint[0](len)\n const data = mapped[idx]\n resultArray.push(data)\n len += BigInt(data.length)\n })\n\n return mergeUint8(...resultArray)\n }\n\n res.dyn = true\n return res\n}\n\nconst staticEnc =\n <\n A extends Array<Encoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Encoder<infer D> ? D : unknown },\n >(\n ...encoders: A\n ): Encoder<[...OT]> =>\n (values) =>\n mergeUint8(...values.map((value, idx) => encoders[idx](value)))\n\nconst staticDec = <\n A extends Array<Decoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Decoder<infer D> ? D : unknown },\n>(\n ...decoders: A\n): Decoder<[...OT]> =>\n toInternalBytes(\n (bytes) => decoders.map((decoder) => decoder(bytes)) as [...OT],\n )\nconst dynamicDec = <\n A extends Array<Decoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Decoder<infer D> ? D : unknown },\n>(\n ...decoders: A\n): Decoder<[...OT]> => {\n const res: Decoder<[...OT]> = toInternalBytes((bytes) => {\n const result = new Array(decoders.length) as [...OT]\n let start = bytes.i\n for (let i = 0; i < decoders.length; i++) {\n if (decoders[i].dyn) {\n const offset = Number(uint[1](bytes))\n const current = bytes.i\n bytes.i = start + offset\n result[i] = decoders[i](bytes)\n bytes.i = current\n } else {\n result[i] = decoders[i](bytes)\n }\n }\n return result\n })\n res.dyn = true\n return res\n}\n\nexport const Tuple = <\n A extends Array<Codec<any>>,\n OT extends { [K in keyof A]: A[K] extends Codec<infer D> ? D : unknown },\n>(\n ...codecs: A\n): Codec<[...OT]> => {\n const isDyn = codecs.some((c) => c.dyn)\n const [enc, dec] = isDyn\n ? ([dynamicEnc, dynamicDec] as const)\n : ([staticEnc, staticDec] as const)\n\n const res: Codec<[...OT]> = createCodec(\n enc(...codecs.map(([encoder]) => encoder)),\n dec(...codecs.map(([, decoder]) => decoder)),\n )\n res.dyn = isDyn\n return res\n}\n", "import { Codec, StringRecord } from \"../types\"\nimport { enhanceCodec } from \"../utils\"\nimport { Tuple } from \"./Tuple\"\n\nexport const Struct = <\n A extends StringRecord<Codec<any>>,\n OT extends { [K in keyof A]: A[K] extends Codec<infer D> ? D : unknown },\n>(\n codecs: A,\n): Codec<OT> => {\n const keys = Object.keys(codecs)\n return enhanceCodec(\n Tuple(...Object.values(codecs)),\n (input: OT) => keys.map((k) => input[k]),\n (tuple: Array<any>) =>\n Object.fromEntries(tuple.map((value, idx) => [keys[idx], value])) as OT,\n )\n}\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport { toInternalBytes } from \"../internal\"\nimport { createCodec } from \"../utils\"\nimport { Codec, Decoder, Encoder } from \"../types\"\nimport { uint } from \"./Uint\"\n\nconst vectorEnc = <T>(inner: Encoder<T>, size?: number): Encoder<Array<T>> => {\n if (size! >= 0) {\n const encoder: Encoder<Array<T>> = (value) =>\n mergeUint8(...value.map(inner))\n encoder.dyn = inner.dyn\n return encoder\n }\n const encoder: Encoder<Array<T>> = (value) =>\n mergeUint8(uint[0](BigInt(value.length)), ...value.map(inner))\n encoder.dyn = true\n return encoder\n}\n\nconst vectorDec = <T>(getter: Decoder<T>, size?: number): Decoder<Array<T>> => {\n const decoder = toInternalBytes((bytes) => {\n const nElements = size! >= 0 ? size! : Number(uint[1](bytes))\n const decoded = new Array(nElements)\n\n for (let i = 0; i < nElements; i++) {\n decoded[i] = getter(bytes)\n }\n\n return decoded\n })\n if (size == null) decoder.dyn = true\n return decoder\n}\n\nexport const Vector = <T>(inner: Codec<T>, size?: number): Codec<Array<T>> => {\n const codec = createCodec(\n vectorEnc(inner[0], size),\n vectorDec(inner[1], size),\n )\n if (size == null) codec.dyn = true\n return codec\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;
|
|
3
|
+
"sources": ["../src/internal/createCodec.ts", "../src/internal/toInternalBytes.ts", "../src/internal/range32.ts", "../src/utils.ts", "../src/codecs/address.ts", "../src/codecs/Uint.ts", "../src/codecs/bool.ts", "../src/codecs/bytes.ts", "../src/codecs/str.ts", "../src/codecs/BytesX.ts", "../src/codecs/Int.ts", "../src/codecs/Fixed.ts", "../src/codecs/Tuple.ts", "../src/codecs/Struct.ts", "../src/codecs/Vector.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Codec } from \"../types\"\n\nexport const createCodec = <T>(\n encoder: (value: T) => Uint8Array,\n decoder: (value: Uint8Array) => T,\n selector: string,\n): Codec<T> => {\n ;(encoder as any).s = selector\n ;(decoder as any).s = selector\n const result = [encoder, decoder] as any\n result.enc = encoder\n result.dec = decoder\n result.s = selector\n return result\n}\n", "import { fromHex } from \"@unstoppablejs/utils\"\nimport { Decoder } from \"../types\"\n\nclass InternalUint8Array extends Uint8Array {\n i: number = 0\n v: DataView\n\n constructor(buffer: ArrayBuffer) {\n super(buffer)\n this.v = new DataView(buffer)\n }\n}\n\nexport const toInternalBytes = <T>(\n fn: (input: InternalUint8Array) => T,\n): Decoder<T> =>\n ((buffer: string | ArrayBuffer | Uint8Array | InternalUint8Array) =>\n fn(\n buffer instanceof InternalUint8Array\n ? buffer\n : new InternalUint8Array(\n buffer instanceof Uint8Array\n ? buffer.buffer\n : typeof buffer === \"string\"\n ? fromHex(buffer).buffer\n : buffer,\n ),\n )) as Decoder<T>\n", "export const range32 = Array(32)\n .fill(0)\n .map((_, idx) => idx + 1)\n", "import type { Codec, Decoder, Encoder } from \"./types\"\nimport { createCodec } from \"./internal\"\nimport { keccak_256 } from \"@noble/hashes/sha3\"\n\nexport const keccak = keccak_256\n\nconst dyn = <T extends { d?: boolean; s: string }>(\n input: { d?: boolean; s: string },\n output: T,\n): T => {\n if (input.d) output.d = true\n output.s = input.s\n return output\n}\n\nexport const enhanceEncoder = <I, O>(\n encoder: Encoder<I>,\n mapper: (value: O) => I,\n): Encoder<O> => dyn(encoder, ((value) => encoder(mapper(value))) as Encoder<O>)\n\nexport const enhanceDecoder = <I, O>(\n decoder: Decoder<I>,\n mapper: (value: I) => O,\n): Decoder<O> => dyn(decoder, ((value) => mapper(decoder(value))) as Decoder<O>)\n\nexport const enhanceCodec = <I, O>(\n codec: Codec<I>,\n toFrom: (value: O) => I,\n fromTo: (value: I) => O,\n): Codec<O> =>\n dyn(\n codec,\n createCodec(\n enhanceEncoder(codec[0], toFrom),\n enhanceDecoder(codec[1], fromTo),\n codec.s,\n ),\n )\n", "import { fromHex, toHex } from \"@unstoppablejs/utils\"\nimport { createCodec, toInternalBytes } from \"../internal\"\nimport { keccak } from \"../utils\"\n\nexport const address = createCodec<string>(\n (input: string) => {\n const result = new Uint8Array(32)\n result.set(fromHex(input), 12)\n return result\n },\n toInternalBytes((bytes) => {\n const binaryAddress = new Uint8Array(bytes.buffer, bytes.i + 12, 20)\n bytes.i += 32\n const nonChecksum = toHex(binaryAddress)\n const hashedAddres = toHex(keccak(nonChecksum.slice(2)))\n\n const result = new Array(41)\n result[0] = \"0x\"\n for (let i = 2; i < 42; i++) {\n const char = nonChecksum[i]\n result.push(parseInt(hashedAddres[i], 16) > 7 ? char.toUpperCase() : char)\n }\n\n return result.join(\"\")\n }),\n \"address\",\n)\n", "import { Codec } from \"../types\"\nimport { range32, toInternalBytes, createCodec } from \"../internal\"\n\nconst getCodec = (nBytes: number): Codec<bigint> => {\n const n64 = Math.ceil(nBytes / 8)\n return createCodec(\n (input) => {\n const result = new Uint8Array(32)\n const dv = new DataView(result.buffer)\n\n const idxLimit = 32 - n64 * 8\n for (let idx = 24; idx >= idxLimit; idx -= 8) {\n dv.setBigUint64(idx, input)\n input >>= 64n\n }\n\n return result\n },\n toInternalBytes((bytes) => {\n let result = 0n\n\n const nextBlock = bytes.i + 32\n for (let idx = bytes.i + (32 - n64 * 8); idx < nextBlock; idx += 8)\n result = (result << 64n) | bytes.v.getBigUint64(idx)\n\n bytes.i = nextBlock\n return result\n }),\n \"uint\" + nBytes,\n )\n}\n\nexport const [\n uint8,\n uint16,\n uint24,\n uint32,\n uint40,\n uint48,\n uint56,\n uint64,\n uint72,\n uint80,\n uint88,\n uint96,\n uint104,\n uint112,\n uint120,\n uint128,\n uint136,\n uint144,\n uint152,\n uint160,\n uint168,\n uint176,\n uint184,\n uint192,\n uint200,\n uint208,\n uint226,\n uint224,\n uint232,\n uint240,\n uint248,\n uint256,\n] = range32.map(getCodec)\nexport const uint = uint256\n", "import type { Codec } from \"../types\"\nimport { enhanceCodec } from \"../utils\"\nimport { uint8 } from \"./Uint\"\n\nconst base = Object.assign([], uint8)\nbase.s = \"bool\"\n\nexport const bool: Codec<boolean> = enhanceCodec(\n base,\n (value: boolean) => (value ? 1n : 0n),\n Boolean,\n)\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport type { Decoder, Encoder } from \"../types\"\nimport { toInternalBytes, createCodec } from \"../internal\"\nimport { uint } from \"./Uint\"\n\nconst bytesEnc = ((val) => {\n const args = [uint[0](BigInt(val.length)), val] as const\n const extra = val.length % 32\n if (extra > 0) {\n ;(args as any).push(new Uint8Array(32 - extra))\n }\n return mergeUint8(...args)\n}) as Encoder<Uint8Array>\nbytesEnc.d = true\n\nconst bytesDec: Decoder<Uint8Array> = toInternalBytes((bytes) => {\n let nElements = Number(uint[1](bytes))\n const result = new Uint8Array(bytes.buffer, bytes.i, nElements)\n bytes.i += nElements\n const extra = nElements % 32\n if (extra > 0) bytes.i += 32 - extra\n return result\n})\nbytesDec.d = true\n\nexport const bytes = createCodec(bytesEnc, bytesDec, \"bytes\")\nbytes.d = true\n", "import { enhanceCodec } from \"../utils\"\nimport { bytes } from \"./bytes\"\n\nconst textEncoder = new TextEncoder()\nconst textDecoder = new TextDecoder()\n\nconst base = Object.assign([], bytes)\nbase.s = \"string\"\n\nexport const str = enhanceCodec<Uint8Array, string>(\n base,\n textEncoder.encode.bind(textEncoder),\n textDecoder.decode.bind(textDecoder),\n)\n", "import type { Encoder, Decoder, Codec } from \"../types\"\nimport { range32, toInternalBytes, createCodec } from \"../internal\"\n\nconst bytesEnc = (nBytes: number): Encoder<Uint8Array> =>\n ((bytes) => {\n if (bytes.length === nBytes && nBytes === 32) return bytes\n const result = new Uint8Array(32)\n result.set(bytes.length === nBytes ? bytes : bytes.slice(0, nBytes))\n return result\n }) as Encoder<Uint8Array>\n\nconst bytesDec = (nBytes: number): Decoder<Uint8Array> =>\n toInternalBytes((bytes) => {\n const result = new Uint8Array(bytes.buffer, bytes.i, nBytes)\n bytes.i += 32\n return result\n })\n\nexport const [\n bytes1,\n bytes2,\n bytes3,\n bytes4,\n bytes5,\n bytes6,\n bytes7,\n bytes8,\n bytes9,\n bytes10,\n bytes11,\n bytes12,\n bytes13,\n bytes14,\n bytes15,\n bytes16,\n bytes17,\n bytes18,\n bytes19,\n bytes20,\n bytes21,\n bytes22,\n bytes23,\n bytes24,\n bytes25,\n bytes26,\n bytes27,\n bytes28,\n bytes29,\n bytes30,\n bytes31,\n bytes32,\n] = range32.map(\n (nBytes: number): Codec<Uint8Array> =>\n createCodec(bytesEnc(nBytes), bytesDec(nBytes), \"bytes\" + nBytes),\n)\n", "import { Encoder, Codec } from \"../types\"\nimport { range32, toInternalBytes, createCodec } from \"../internal\"\n\nconst signGetters: Record<1 | 2 | 8, \"getBigInt64\" | \"getInt16\" | \"getInt8\"> = {\n \"1\": \"getInt8\",\n \"2\": \"getInt16\",\n \"8\": \"getBigInt64\",\n}\n\nconst signSetters: Record<1 | 2 | 8, \"setBigInt64\" | \"setInt16\" | \"setInt8\"> = {\n \"1\": \"setInt8\",\n \"2\": \"setInt16\",\n \"8\": \"setBigInt64\",\n}\n\nconst usignGetters: Record<\n 1 | 2 | 8,\n \"getBigUint64\" | \"getUint16\" | \"getUint8\"\n> = {\n \"1\": \"getUint8\",\n \"2\": \"getUint16\",\n \"8\": \"getBigUint64\",\n}\n\nconst usignSetters: Record<\n 1 | 2 | 8,\n \"setBigUint64\" | \"setUint16\" | \"setUint8\"\n> = {\n \"1\": \"setUint8\",\n \"2\": \"setUint16\",\n \"8\": \"setBigUint64\",\n}\n\nconst getCodec = (nBytes: number): Codec<bigint> => {\n const n64 = (nBytes / 8) | 0\n const n16 = ((nBytes % 8) / 2) | 0\n const sequence = [\n ...Array(n64).fill([8, 64n, (x: bigint) => x]),\n ...Array(n16).fill([2, 16n, (x: bigint) => Number(x & 65535n)]),\n ]\n if (nBytes % 2) sequence.push([1, 8n, (x: bigint) => Number(x & 255n)])\n\n const enc = ((input) => {\n const result = new Uint8Array(32)\n const dv = new DataView(result.buffer)\n\n if (input < 0n) {\n for (let i = 0; i < 32 - nBytes; i += 8) dv.setBigInt64(i, -1n)\n }\n\n let idx = 32\n for (let i = sequence.length - 1; i > 0; i--) {\n const [bytes, shift, fn] = sequence[i] as [1, 8n, (x: bigint) => any]\n idx -= bytes\n dv[usignSetters[bytes]](idx, fn(input) as never)\n input >>= shift\n }\n const [bytes, , fn] = sequence[0] as [1, 8n, (x: bigint) => any]\n idx -= bytes\n dv[signSetters[bytes]](idx, fn(input) as never)\n\n return result\n }) as Encoder<bigint>\n\n const dec = toInternalBytes((bytes) => {\n let idx = bytes.i + 32 - nBytes\n\n const bits = sequence[0][0] as 8\n let result = BigInt(bytes.v[signGetters[bits]](idx))\n idx += bits\n\n for (let i = 1; i < sequence.length; i++) {\n const [bits, shift] = sequence[i] as [1, 8n]\n result = (result << shift) | BigInt(bytes.v[usignGetters[bits]](idx))\n idx += bits\n }\n\n bytes.i += 32\n return result\n })\n\n return createCodec(enc, dec, \"int\" + nBytes)\n}\n\nexport const [\n int8,\n int16,\n int24,\n int32,\n int40,\n int48,\n int56,\n int64,\n int72,\n int80,\n int88,\n int96,\n int104,\n int112,\n int120,\n int128,\n int136,\n int144,\n int152,\n int160,\n int168,\n int176,\n int184,\n int192,\n int200,\n int208,\n int226,\n int224,\n int232,\n int240,\n int248,\n int256,\n] = range32.map(getCodec)\nexport const int = int256\n", "import { Codec } from \"../types\"\nimport { enhanceCodec } from \"../utils\"\n\nexport interface Decimal<T extends number = number> {\n value: bigint\n decimals: T\n}\n\nexport const Fixed = <D extends number>(\n baseCodec: Codec<bigint>,\n decimals: D,\n) => {\n const baseSelector = baseCodec.s\n const eBaseCodec = Object.assign([], baseCodec)\n eBaseCodec.s =\n (baseSelector[0] === \"u\"\n ? \"ufixed\" + baseSelector.slice(4)\n : \"fixed\" + baseSelector.slice(3)) +\n \"x\" +\n decimals\n return enhanceCodec<bigint, Decimal<D>>(\n eBaseCodec,\n (x) => x.value,\n (value) => ({ value, decimals }),\n )\n}\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport type { Codec, Decoder, Encoder } from \"../types\"\nimport { toInternalBytes, createCodec } from \"../internal\"\nimport { uint } from \"./Uint\"\n\nconst dynamicEnc = <\n A extends Array<Encoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Encoder<infer D> ? D : unknown },\n>(\n ...encoders: A\n): Encoder<[...OT]> => {\n const res = ((values) => {\n const mapped = values.map((value, idx) => encoders[idx](value))\n const resultArray = new Array<Uint8Array>(encoders.length)\n const dinamics = []\n let len = 0n\n for (let i = 0; i < encoders.length; i++) {\n if (encoders[i].d) {\n dinamics.push(i)\n len += 32n\n } else {\n resultArray[i] = mapped[i]\n len += BigInt(mapped[i].length)\n }\n }\n\n dinamics.forEach((idx) => {\n resultArray[idx] = uint[0](len)\n const data = mapped[idx]\n resultArray.push(data)\n len += BigInt(data.length)\n })\n\n return mergeUint8(...resultArray)\n }) as Encoder<[...OT]>\n\n res.d = true\n return res\n}\n\nconst staticEnc = <\n A extends Array<Encoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Encoder<infer D> ? D : unknown },\n>(\n ...encoders: A\n) =>\n ((values) =>\n mergeUint8(...values.map((value, idx) => encoders[idx](value)))) as Encoder<\n [...OT]\n >\n\nconst staticDec = <\n A extends Array<Decoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Decoder<infer D> ? D : unknown },\n>(\n ...decoders: A\n): Decoder<[...OT]> =>\n toInternalBytes(\n (bytes) => decoders.map((decoder) => decoder(bytes)) as [...OT],\n )\nconst dynamicDec = <\n A extends Array<Decoder<any>>,\n OT extends { [K in keyof A]: A[K] extends Decoder<infer D> ? D : unknown },\n>(\n ...decoders: A\n): Decoder<[...OT]> => {\n const res: Decoder<[...OT]> = toInternalBytes((bytes) => {\n const result = new Array(decoders.length) as [...OT]\n let start = bytes.i\n for (let i = 0; i < decoders.length; i++) {\n if (decoders[i].d) {\n const offset = Number(uint[1](bytes))\n const current = bytes.i\n bytes.i = start + offset\n result[i] = decoders[i](bytes)\n bytes.i = current\n } else {\n result[i] = decoders[i](bytes)\n }\n }\n return result\n })\n res.d = true\n return res\n}\n\nexport const Tuple = <\n A extends Array<Codec<any>>,\n OT extends { [K in keyof A]: A[K] extends Codec<infer D> ? D : unknown },\n>(\n ...codecs: A\n): Codec<[...OT]> => {\n const isDyn = codecs.some((c) => c.d)\n const [enc, dec] = isDyn\n ? ([dynamicEnc, dynamicDec] as const)\n : ([staticEnc, staticDec] as const)\n\n const res: Codec<[...OT]> = createCodec(\n enc(...codecs.map(([encoder]) => encoder)),\n dec(...codecs.map(([, decoder]) => decoder)),\n `(${codecs.map((c) => c.s).join(\",\")})`,\n )\n res.d = isDyn\n return res\n}\n", "import { Codec, StringRecord } from \"../types\"\nimport { enhanceCodec } from \"../utils\"\nimport { Tuple } from \"./Tuple\"\n\nexport const Struct = <\n A extends StringRecord<Codec<any>>,\n OT extends { [K in keyof A]: A[K] extends Codec<infer D> ? D : unknown },\n>(\n codecs: A,\n): Codec<OT> => {\n const keys = Object.keys(codecs)\n return enhanceCodec(\n Tuple(...Object.values(codecs)),\n (input: OT) => keys.map((k) => input[k]),\n (tuple: Array<any>) =>\n Object.fromEntries(tuple.map((value, idx) => [keys[idx], value])) as OT,\n )\n}\n", "import { mergeUint8 } from \"@unstoppablejs/utils\"\nimport { toInternalBytes, createCodec } from \"../internal\"\nimport { Codec, Decoder, Encoder } from \"../types\"\nimport { uint } from \"./Uint\"\n\nconst vectorEnc = <T>(inner: Encoder<T>, size?: number): Encoder<Array<T>> => {\n const result = ((value) => {\n const isNotFixed = size == null ? 1 : 0\n const actualSize = isNotFixed ? value.length : size!\n let data: Array<Uint8Array>\n if (inner.d) {\n data = new Array<Uint8Array>(actualSize * 2)\n let offset = actualSize * 32\n for (let i = 0; i < actualSize; i++) {\n const encoded = inner(value[i])\n data[i] = uint.enc(BigInt(offset))\n offset += encoded.byteLength\n data[i + actualSize] = encoded\n }\n } else {\n data = new Array<Uint8Array>(actualSize)\n for (let i = 0; i < actualSize; i++) data[i] = inner(value[i])\n }\n if (isNotFixed) data!.unshift(uint.enc(BigInt(value.length)))\n return mergeUint8(...data)\n }) as Encoder<Array<T>>\n result.d = true\n return result\n}\n\nconst vectorDec = <T>(getter: Decoder<T>, size?: number): Decoder<Array<T>> => {\n const decoder = toInternalBytes((bytes) => {\n const nElements = size! >= 0 ? size! : Number(uint[1](bytes))\n const decoded = new Array(nElements)\n\n if (getter.d) {\n const init = bytes.i\n let current = init\n for (let i = 0; i < nElements; i++) {\n bytes.i = current\n const offset = Number(uint.dec(bytes))\n current = bytes.i\n bytes.i = init + offset\n decoded[i] = getter(bytes)\n }\n } else {\n for (let i = 0; i < nElements; i++) {\n decoded[i] = getter(bytes)\n }\n }\n\n return decoded\n })\n decoder.d = true\n return decoder\n}\n\nexport const Vector = <T>(inner: Codec<T>, size?: number): Codec<Array<T>> => {\n const codec = createCodec(\n vectorEnc(inner[0], size),\n vectorDec(inner[1], size),\n inner.s + `[${size == null ? \"\" : size}]`,\n )\n if (size == null) codec.d = true\n return codec\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAEO,IAAM,cAAc,CACzB,SACA,SACA,aACa;AACb;AAAC,EAAC,QAAgB,IAAI;AACrB,EAAC,QAAgB,IAAI;AACtB,QAAM,SAAS,CAAC,SAAS,OAAO;AAChC,SAAO,MAAM;AACb,SAAO,MAAM;AACb,SAAO,IAAI;AACX,SAAO;AACT;;;ACdA;AAGA,uCAAiC,WAAW;AAAA,EAI1C,YAAY,QAAqB;AAC/B,UAAM,MAAM;AAJd,6BAAY;AACZ;AAIE,SAAK,IAAI,IAAI,SAAS,MAAM;AAAA,EAC9B;AACF;AAEO,IAAM,kBAAkB,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AAS,IAAI,GAAG,IAAI,WAAW,KAAK;AAClC,gBAAQ,KAAK,OAAO,OAAK;AAAA,MAC3B;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AACD,UAAQ,IAAI;AACZ,SAAO;AACT;AAEO,IAAM,SAAS,CAAI,OAAiB,SAAmC;AAC5E,QAAM,QAAQ,YACZ,UAAU,MAAM,IAAI,IAAI,GACxB,UAAU,MAAM,IAAI,IAAI,GACxB,MAAM,IAAI,IAAI,QAAQ,OAAO,KAAK,OACpC;AACA,MAAI,QAAQ;AAAM,UAAM,IAAI;AAC5B,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export declare type Encoder<T> = ((value: T) => Uint8Array) & {
|
|
2
|
-
|
|
2
|
+
s: string;
|
|
3
|
+
d?: boolean;
|
|
3
4
|
};
|
|
4
5
|
export declare type Decoder<T> = ((value: Uint8Array | ArrayBuffer | string) => T) & {
|
|
5
|
-
|
|
6
|
+
s: string;
|
|
7
|
+
d?: boolean;
|
|
6
8
|
};
|
|
7
9
|
export declare type Codec<T> = [Encoder<T>, Decoder<T>] & {
|
|
8
10
|
enc: Encoder<T>;
|
|
9
11
|
dec: Decoder<T>;
|
|
10
|
-
|
|
12
|
+
s: string;
|
|
13
|
+
d?: boolean;
|
|
11
14
|
};
|
|
12
15
|
export declare type CodecType<T extends Codec<any>> = T extends Codec<infer V> ? V : unknown;
|
|
13
16
|
export declare type StringRecord<T> = {
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export declare const keccak: {
|
|
|
5
5
|
blockLen: number;
|
|
6
6
|
create(): import("@noble/hashes/utils").Hash<import("@noble/hashes/sha3").Keccak>;
|
|
7
7
|
};
|
|
8
|
-
export declare const createCodec: <T>(encoder: Encoder<T>, decoder: Decoder<T>) => Codec<T>;
|
|
9
8
|
export declare const enhanceEncoder: <I, O>(encoder: Encoder<I>, mapper: (value: O) => I) => Encoder<O>;
|
|
10
9
|
export declare const enhanceDecoder: <I, O>(decoder: Decoder<I>, mapper: (value: I) => O) => Decoder<O>;
|
|
11
10
|
export declare const enhanceCodec: <I, O>(codec: Codec<I>, toFrom: (value: O) => I, fromTo: (value: I) => O) => Codec<O>;
|
package/package.json
CHANGED