solidity-codecs 0.0.1-beta.2 → 0.1.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 +2 -0
- package/dist/codecs/Fixed.d.ts +6 -0
- package/dist/codecs/Int.d.ts +3 -0
- package/dist/codecs/Struct.d.ts +2 -25
- package/dist/codecs/Tuple.d.ts +2 -25
- package/dist/codecs/Uint.d.ts +4 -0
- package/dist/codecs/Vector.d.ts +2 -14
- package/dist/codecs/address.d.ts +1 -0
- package/dist/codecs/bytes.d.ts +1 -6
- package/dist/codecs/index.d.ts +9 -8
- package/dist/solidity-codecs.cjs.development.js +379 -256
- 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 +377 -254
- package/dist/solidity-codecs.js.map +3 -3
- package/dist/solidity-codecs.mjs +377 -254
- package/dist/solidity-codecs.mjs.map +3 -3
- package/dist/types.d.ts +3 -7
- package/dist/utils.d.ts +1 -1
- package/package.json +7 -8
- package/dist/codecs/Bytes.d.ts +0 -6
- package/dist/codecs/Enum.d.ts +0 -57
- package/dist/codecs/Option.d.ts +0 -6
- package/dist/codecs/Result.d.ts +0 -22
- package/dist/codecs/call.d.ts +0 -6
- package/dist/codecs/compact.d.ts +0 -2
- package/dist/codecs/fixed-width-ints.d.ts +0 -11
- package/dist/codecs/fixed.d.ts +0 -3
- package/dist/codecs/int.d.ts +0 -6
- package/dist/codecs/struct.d.ts +0 -6
- package/dist/codecs/tuple.d.ts +0 -6
- package/dist/codecs/uint.d.ts +0 -2
- package/dist/codecs/vector.d.ts +0 -6
- package/dist/codecs/void.d.ts +0 -2
- package/dist/scale-ts.cjs.development.js +0 -427
- package/dist/scale-ts.cjs.development.js.map +0 -7
- package/dist/scale-ts.cjs.production.min.js +0 -318
- package/dist/scale-ts.cjs.production.min.js.map +0 -7
- package/dist/scale-ts.es2017.js +0 -403
- package/dist/scale-ts.es2017.js.map +0 -7
- package/dist/scale-ts.es2019.mjs +0 -348
- package/dist/scale-ts.es2019.mjs.map +0 -7
- package/dist/test-utils.d.ts +0 -5
package/dist/solidity-codecs.js
CHANGED
@@ -12,50 +12,21 @@ var createCodec = (encoder, decoder) => {
|
|
12
12
|
result.dec = decoder;
|
13
13
|
return result;
|
14
14
|
};
|
15
|
-
var
|
16
|
-
|
17
|
-
|
15
|
+
var dyn = (input, output) => {
|
16
|
+
if (input.dyn)
|
17
|
+
output.dyn = true;
|
18
|
+
return output;
|
19
|
+
};
|
20
|
+
var enhanceEncoder = (encoder, mapper) => dyn(encoder, (value) => encoder(mapper(value)));
|
21
|
+
var enhanceDecoder = (decoder, mapper) => dyn(decoder, (value) => mapper(decoder(value)));
|
22
|
+
var enhanceCodec = (codec, toFrom, fromTo) => dyn(codec, createCodec(enhanceEncoder(codec[0], toFrom), enhanceDecoder(codec[1], fromTo)));
|
23
|
+
|
24
|
+
// src/codecs/address.ts
|
25
|
+
import { fromHex as fromHex2, toHex } from "@unstoppablejs/utils";
|
26
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
18
27
|
|
19
28
|
// src/internal/toInternalBytes.ts
|
20
|
-
|
21
|
-
0: 0,
|
22
|
-
1: 1,
|
23
|
-
2: 2,
|
24
|
-
3: 3,
|
25
|
-
4: 4,
|
26
|
-
5: 5,
|
27
|
-
6: 6,
|
28
|
-
7: 7,
|
29
|
-
8: 8,
|
30
|
-
9: 9,
|
31
|
-
a: 10,
|
32
|
-
b: 11,
|
33
|
-
c: 12,
|
34
|
-
d: 13,
|
35
|
-
e: 14,
|
36
|
-
f: 15,
|
37
|
-
A: 10,
|
38
|
-
B: 11,
|
39
|
-
C: 12,
|
40
|
-
D: 13,
|
41
|
-
E: 14,
|
42
|
-
F: 15
|
43
|
-
};
|
44
|
-
function fromHex(hexString) {
|
45
|
-
const isOdd = hexString.length % 2;
|
46
|
-
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
47
|
-
const nBytes = (hexString.length - base) / 2 + isOdd;
|
48
|
-
const bytes2 = new Uint8Array(nBytes);
|
49
|
-
if (isOdd)
|
50
|
-
bytes2[0] = 0 | HEX_MAP[hexString[2]];
|
51
|
-
for (let i = 0; i < nBytes; ) {
|
52
|
-
const idx = base + i * 2;
|
53
|
-
const a = HEX_MAP[hexString[idx]];
|
54
|
-
const b = HEX_MAP[hexString[idx + 1]];
|
55
|
-
bytes2[isOdd + i++] = a << 4 | b;
|
56
|
-
}
|
57
|
-
return bytes2;
|
58
|
-
}
|
29
|
+
import { fromHex } from "@unstoppablejs/utils";
|
59
30
|
var InternalUint8Array = class extends Uint8Array {
|
60
31
|
constructor(buffer) {
|
61
32
|
super(buffer);
|
@@ -66,83 +37,92 @@ var InternalUint8Array = class extends Uint8Array {
|
|
66
37
|
};
|
67
38
|
var toInternalBytes = (fn) => (buffer) => fn(buffer instanceof InternalUint8Array ? buffer : new InternalUint8Array(buffer instanceof Uint8Array ? buffer.buffer : typeof buffer === "string" ? fromHex(buffer).buffer : buffer));
|
68
39
|
|
69
|
-
// src/internal/
|
70
|
-
var
|
71
|
-
const len = inputs.length;
|
72
|
-
let totalLen = 0;
|
73
|
-
for (let i = 0; i < len; i++)
|
74
|
-
totalLen += inputs[i].byteLength;
|
75
|
-
const result = new Uint8Array(totalLen);
|
76
|
-
for (let idx = 0, at = 0; idx < len; idx++) {
|
77
|
-
const current = inputs[idx];
|
78
|
-
result.set(current, at);
|
79
|
-
at += current.byteLength;
|
80
|
-
}
|
81
|
-
return result;
|
82
|
-
};
|
40
|
+
// src/internal/range32.ts
|
41
|
+
var range32 = Array(32).fill(0).map((_, idx) => idx + 1);
|
83
42
|
|
84
|
-
// src/
|
85
|
-
|
86
|
-
|
87
|
-
|
43
|
+
// src/codecs/address.ts
|
44
|
+
var address = createCodec((input) => {
|
45
|
+
const result = new Uint8Array(32);
|
46
|
+
result.set(fromHex2(input), 12);
|
47
|
+
return result;
|
48
|
+
}, toInternalBytes((bytes33) => {
|
49
|
+
const binaryAddress = new Uint8Array(bytes33.buffer, bytes33.i + 12, 20);
|
50
|
+
bytes33.i += 32;
|
51
|
+
const nonChecksum = toHex(binaryAddress);
|
52
|
+
const hashedAddres = toHex(keccak_256(nonChecksum.slice(2)));
|
53
|
+
const result = new Array(41);
|
54
|
+
result[0] = "0x";
|
55
|
+
for (let i = 2; i < 42; i++) {
|
56
|
+
const char = nonChecksum[i];
|
57
|
+
result.push(parseInt(hashedAddres[i], 16) > 7 ? char.toUpperCase() : char);
|
58
|
+
}
|
59
|
+
return result.join("");
|
60
|
+
}));
|
88
61
|
|
89
|
-
// src/codecs/
|
90
|
-
var
|
91
|
-
const n64 = nBytes / 8
|
92
|
-
|
93
|
-
const isOdd = nBytes % 2;
|
94
|
-
return (input) => {
|
62
|
+
// src/codecs/Uint.ts
|
63
|
+
var getCodec = (nBytes) => {
|
64
|
+
const n64 = Math.ceil(nBytes / 8);
|
65
|
+
return createCodec((input) => {
|
95
66
|
const result = new Uint8Array(32);
|
96
67
|
const dv = new DataView(result.buffer);
|
97
|
-
|
98
|
-
|
99
|
-
dv.setUint8(--idx, Number(input & 255n));
|
100
|
-
input >>= 8n;
|
101
|
-
}
|
102
|
-
for (let i = 0; i < n16; i++) {
|
103
|
-
idx -= 2;
|
104
|
-
dv.setUint16(idx, Number(input & 65535n));
|
105
|
-
input >>= 16n;
|
106
|
-
}
|
107
|
-
const idxLimit = idx - n64 * 8;
|
108
|
-
for (idx -= 8; idx >= idxLimit; idx -= 8) {
|
68
|
+
const idxLimit = 32 - n64 * 8;
|
69
|
+
for (let idx = 24; idx >= idxLimit; idx -= 8) {
|
109
70
|
dv.setBigUint64(idx, input);
|
110
71
|
input >>= 64n;
|
111
72
|
}
|
112
73
|
return result;
|
113
|
-
}
|
114
|
-
};
|
115
|
-
var decode = (nBytes) => {
|
116
|
-
const n64 = Math.ceil(nBytes / 8);
|
117
|
-
return toInternalBytes((bytes2) => {
|
74
|
+
}, toInternalBytes((bytes33) => {
|
118
75
|
let result = 0n;
|
119
|
-
const nextBlock =
|
120
|
-
for (let idx =
|
121
|
-
result = result << 64n |
|
122
|
-
|
76
|
+
const nextBlock = bytes33.i + 32;
|
77
|
+
for (let idx = bytes33.i + (32 - n64 * 8); idx < nextBlock; idx += 8)
|
78
|
+
result = result << 64n | bytes33.v.getBigUint64(idx);
|
79
|
+
bytes33.i = nextBlock;
|
123
80
|
return result;
|
124
|
-
});
|
125
|
-
};
|
126
|
-
var cache = /* @__PURE__ */ new Map();
|
127
|
-
var uint = (nBits) => {
|
128
|
-
let cached = cache.get(nBits);
|
129
|
-
if (cached)
|
130
|
-
return cached;
|
131
|
-
const nBytes = nBits / 8;
|
132
|
-
cached = createCodec(encode(nBytes), decode(nBytes));
|
133
|
-
cache.set(nBits, cached);
|
134
|
-
return cached;
|
81
|
+
}));
|
135
82
|
};
|
83
|
+
var [
|
84
|
+
uint8,
|
85
|
+
uint16,
|
86
|
+
uint24,
|
87
|
+
uint32,
|
88
|
+
uint40,
|
89
|
+
uint48,
|
90
|
+
uint56,
|
91
|
+
uint64,
|
92
|
+
uint72,
|
93
|
+
uint80,
|
94
|
+
uint88,
|
95
|
+
uint96,
|
96
|
+
uint104,
|
97
|
+
uint112,
|
98
|
+
uint120,
|
99
|
+
uint128,
|
100
|
+
uint136,
|
101
|
+
uint144,
|
102
|
+
uint152,
|
103
|
+
uint160,
|
104
|
+
uint168,
|
105
|
+
uint176,
|
106
|
+
uint184,
|
107
|
+
uint192,
|
108
|
+
uint200,
|
109
|
+
uint208,
|
110
|
+
uint226,
|
111
|
+
uint224,
|
112
|
+
uint232,
|
113
|
+
uint240,
|
114
|
+
uint248,
|
115
|
+
uint256
|
116
|
+
] = range32.map(getCodec);
|
117
|
+
var uint = uint256;
|
136
118
|
|
137
119
|
// src/codecs/bool.ts
|
138
|
-
var bool = enhanceCodec(
|
120
|
+
var bool = enhanceCodec(uint8, (value) => value ? 1n : 0n, Boolean);
|
139
121
|
|
140
|
-
// src/codecs/
|
141
|
-
|
142
|
-
var
|
143
|
-
|
144
|
-
const val = textEncoder.encode(str2);
|
145
|
-
const args = [uint256.enc(BigInt(val.length)), val];
|
122
|
+
// src/codecs/bytes.ts
|
123
|
+
import { mergeUint8 } from "@unstoppablejs/utils";
|
124
|
+
var bytesEnc = (val) => {
|
125
|
+
const args = [uint[0](BigInt(val.length)), val];
|
146
126
|
const extra = val.length % 32;
|
147
127
|
if (extra > 0) {
|
148
128
|
;
|
@@ -150,82 +130,71 @@ var strEnc = (str2) => {
|
|
150
130
|
}
|
151
131
|
return mergeUint8(...args);
|
152
132
|
};
|
153
|
-
|
154
|
-
var
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
const padding = extra && 32 - extra;
|
160
|
-
bytes2.i += nElements + padding;
|
161
|
-
return textDecoder.decode(dv);
|
133
|
+
bytesEnc.dyn = true;
|
134
|
+
var bytesDec = toInternalBytes((bytes33) => {
|
135
|
+
let nElements = Number(uint[1](bytes33));
|
136
|
+
const result = new Uint8Array(bytes33.buffer, bytes33.i, nElements);
|
137
|
+
bytes33.i += nElements + nElements % 32;
|
138
|
+
return result;
|
162
139
|
});
|
163
|
-
|
164
|
-
var
|
165
|
-
|
140
|
+
bytesDec.dyn = true;
|
141
|
+
var bytes = createCodec(bytesEnc, bytesDec);
|
142
|
+
bytes.dyn = true;
|
166
143
|
|
167
|
-
// src/codecs/
|
168
|
-
var
|
169
|
-
|
170
|
-
|
144
|
+
// src/codecs/str.ts
|
145
|
+
var textEncoder = new TextEncoder();
|
146
|
+
var textDecoder = new TextDecoder();
|
147
|
+
var str = enhanceCodec(bytes, textEncoder.encode.bind(textEncoder), textDecoder.decode.bind(textDecoder));
|
148
|
+
|
149
|
+
// src/codecs/BytesX.ts
|
150
|
+
var bytesEnc2 = (nBytes) => (bytes33) => {
|
151
|
+
if (bytes33.length === nBytes && nBytes === 32)
|
152
|
+
return bytes33;
|
171
153
|
const result = new Uint8Array(32);
|
172
|
-
result.set(
|
154
|
+
result.set(bytes33.length === nBytes ? bytes33 : bytes33.slice(0, nBytes));
|
173
155
|
return result;
|
174
156
|
};
|
175
|
-
var
|
176
|
-
const result = new Uint8Array(
|
177
|
-
|
178
|
-
return result;
|
179
|
-
});
|
180
|
-
var bytes = (nBytes) => createCodec(bytesEnc(nBytes), bytesDec(nBytes));
|
181
|
-
bytes.enc = bytesEnc;
|
182
|
-
bytes.dec = bytesDec;
|
183
|
-
|
184
|
-
// src/codecs/call.ts
|
185
|
-
var uint2562 = uint(256);
|
186
|
-
var callEnc = (...encoders) => (values) => {
|
187
|
-
const mapped = values.map((value, idx) => encoders[idx](value));
|
188
|
-
const resultArray = new Array(encoders.length);
|
189
|
-
const dinamics = [];
|
190
|
-
let len = 0n;
|
191
|
-
for (let i = 0; i < encoders.length; i++) {
|
192
|
-
if (encoders[i].din) {
|
193
|
-
dinamics.push(i);
|
194
|
-
len += 32n;
|
195
|
-
} else {
|
196
|
-
resultArray[i] = mapped[i];
|
197
|
-
len += BigInt(mapped[i].length);
|
198
|
-
}
|
199
|
-
}
|
200
|
-
dinamics.forEach((idx) => {
|
201
|
-
resultArray[idx] = uint2562.enc(len);
|
202
|
-
const data = mapped[idx];
|
203
|
-
resultArray.push(data);
|
204
|
-
len += BigInt(data.length);
|
205
|
-
});
|
206
|
-
return mergeUint8(...resultArray);
|
207
|
-
};
|
208
|
-
var callDec = (...decoders) => toInternalBytes((bytes2) => {
|
209
|
-
const result = new Array(decoders.length);
|
210
|
-
let start = bytes2.i;
|
211
|
-
for (let i = 0; i < decoders.length; i++) {
|
212
|
-
if (decoders[i].din) {
|
213
|
-
const offset = Number(uint2562.dec(bytes2));
|
214
|
-
const current = bytes2.i;
|
215
|
-
bytes2.i = start + offset;
|
216
|
-
result[i] = decoders[i](bytes2);
|
217
|
-
bytes2.i = current;
|
218
|
-
} else {
|
219
|
-
result[i] = decoders[i](bytes2);
|
220
|
-
}
|
221
|
-
}
|
157
|
+
var bytesDec2 = (nBytes) => toInternalBytes((bytes33) => {
|
158
|
+
const result = new Uint8Array(bytes33.buffer, bytes33.i, nBytes);
|
159
|
+
bytes33.i += 32;
|
222
160
|
return result;
|
223
161
|
});
|
224
|
-
var
|
225
|
-
|
226
|
-
|
162
|
+
var [
|
163
|
+
bytes1,
|
164
|
+
bytes2,
|
165
|
+
bytes3,
|
166
|
+
bytes4,
|
167
|
+
bytes5,
|
168
|
+
bytes6,
|
169
|
+
bytes7,
|
170
|
+
bytes8,
|
171
|
+
bytes9,
|
172
|
+
bytes10,
|
173
|
+
bytes11,
|
174
|
+
bytes12,
|
175
|
+
bytes13,
|
176
|
+
bytes14,
|
177
|
+
bytes15,
|
178
|
+
bytes16,
|
179
|
+
bytes17,
|
180
|
+
bytes18,
|
181
|
+
bytes19,
|
182
|
+
bytes20,
|
183
|
+
bytes21,
|
184
|
+
bytes22,
|
185
|
+
bytes23,
|
186
|
+
bytes24,
|
187
|
+
bytes25,
|
188
|
+
bytes26,
|
189
|
+
bytes27,
|
190
|
+
bytes28,
|
191
|
+
bytes29,
|
192
|
+
bytes30,
|
193
|
+
bytes31,
|
194
|
+
bytes32
|
195
|
+
] = range32.map((nBytes) => createCodec(bytesEnc2(nBytes), bytesDec2(nBytes)));
|
227
196
|
|
228
|
-
// src/codecs/
|
197
|
+
// src/codecs/Int.ts
|
229
198
|
var signGetters = {
|
230
199
|
"1": "getInt8",
|
231
200
|
"2": "getInt16",
|
@@ -246,7 +215,7 @@ var usignSetters = {
|
|
246
215
|
"2": "setUint16",
|
247
216
|
"8": "setBigUint64"
|
248
217
|
};
|
249
|
-
var
|
218
|
+
var getCodec2 = (nBytes) => {
|
250
219
|
const n64 = nBytes / 8 | 0;
|
251
220
|
const n16 = nBytes % 8 / 2 | 0;
|
252
221
|
const sequence = [
|
@@ -258,127 +227,281 @@ var getCodec = (nBytes) => {
|
|
258
227
|
const enc = (input) => {
|
259
228
|
const result = new Uint8Array(32);
|
260
229
|
const dv = new DataView(result.buffer);
|
230
|
+
if (input < 0n) {
|
231
|
+
for (let i = 0; i < 32 - nBytes; i += 8)
|
232
|
+
dv.setBigInt64(i, -1n);
|
233
|
+
}
|
261
234
|
let idx = 32;
|
262
235
|
for (let i = sequence.length - 1; i > 0; i--) {
|
263
|
-
const [
|
264
|
-
idx -=
|
265
|
-
dv[usignSetters[
|
236
|
+
const [bytes34, shift, fn2] = sequence[i];
|
237
|
+
idx -= bytes34;
|
238
|
+
dv[usignSetters[bytes34]](idx, fn2(input));
|
266
239
|
input >>= shift;
|
267
240
|
}
|
268
|
-
const [
|
269
|
-
idx -=
|
270
|
-
dv[signSetters[
|
241
|
+
const [bytes33, , fn] = sequence[0];
|
242
|
+
idx -= bytes33;
|
243
|
+
dv[signSetters[bytes33]](idx, fn(input));
|
271
244
|
return result;
|
272
245
|
};
|
273
|
-
const dec = toInternalBytes((
|
274
|
-
let idx =
|
246
|
+
const dec = toInternalBytes((bytes33) => {
|
247
|
+
let idx = bytes33.i + 32 - nBytes;
|
275
248
|
const bits = sequence[0][0];
|
276
|
-
let result = BigInt(
|
249
|
+
let result = BigInt(bytes33.v[signGetters[bits]](idx));
|
277
250
|
idx += bits;
|
278
251
|
for (let i = 1; i < sequence.length; i++) {
|
279
252
|
const [bits2, shift] = sequence[i];
|
280
|
-
result = result << shift | BigInt(
|
253
|
+
result = result << shift | BigInt(bytes33.v[usignGetters[bits2]](idx));
|
281
254
|
idx += bits2;
|
282
255
|
}
|
283
|
-
|
256
|
+
bytes33.i += 32;
|
284
257
|
return result;
|
285
258
|
});
|
286
259
|
return createCodec(enc, dec);
|
287
260
|
};
|
288
|
-
var
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
261
|
+
var [
|
262
|
+
int8,
|
263
|
+
int16,
|
264
|
+
int24,
|
265
|
+
int32,
|
266
|
+
int40,
|
267
|
+
int48,
|
268
|
+
int56,
|
269
|
+
int64,
|
270
|
+
int72,
|
271
|
+
int80,
|
272
|
+
int88,
|
273
|
+
int96,
|
274
|
+
int104,
|
275
|
+
int112,
|
276
|
+
int120,
|
277
|
+
int128,
|
278
|
+
int136,
|
279
|
+
int144,
|
280
|
+
int152,
|
281
|
+
int160,
|
282
|
+
int168,
|
283
|
+
int176,
|
284
|
+
int184,
|
285
|
+
int192,
|
286
|
+
int200,
|
287
|
+
int208,
|
288
|
+
int226,
|
289
|
+
int224,
|
290
|
+
int232,
|
291
|
+
int240,
|
292
|
+
int248,
|
293
|
+
int256
|
294
|
+
] = range32.map(getCodec2);
|
295
|
+
var int = int256;
|
296
|
+
|
297
|
+
// src/codecs/Fixed.ts
|
298
|
+
var Fixed = (baseCodec, decimals) => enhanceCodec(baseCodec, (x) => x.value, (value) => ({ value, decimals }));
|
300
299
|
|
301
|
-
// src/codecs/
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
const
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
300
|
+
// src/codecs/Tuple.ts
|
301
|
+
import { mergeUint8 as mergeUint82 } from "@unstoppablejs/utils";
|
302
|
+
var dynamicEnc = (...encoders) => {
|
303
|
+
const res = (values) => {
|
304
|
+
const mapped = values.map((value, idx) => encoders[idx](value));
|
305
|
+
const resultArray = new Array(encoders.length);
|
306
|
+
const dinamics = [];
|
307
|
+
let len = 0n;
|
308
|
+
for (let i = 0; i < encoders.length; i++) {
|
309
|
+
if (encoders[i].dyn) {
|
310
|
+
dinamics.push(i);
|
311
|
+
len += 32n;
|
312
|
+
} else {
|
313
|
+
resultArray[i] = mapped[i];
|
314
|
+
len += BigInt(mapped[i].length);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
dinamics.forEach((idx) => {
|
318
|
+
resultArray[idx] = uint[0](len);
|
319
|
+
const data = mapped[idx];
|
320
|
+
resultArray.push(data);
|
321
|
+
len += BigInt(data.length);
|
322
|
+
});
|
323
|
+
return mergeUint82(...resultArray);
|
312
324
|
};
|
325
|
+
res.dyn = true;
|
326
|
+
return res;
|
313
327
|
};
|
314
|
-
var
|
315
|
-
var
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
+
var staticEnc = (...encoders) => (values) => mergeUint82(...values.map((value, idx) => encoders[idx](value)));
|
329
|
+
var staticDec = (...decoders) => toInternalBytes((bytes33) => decoders.map((decoder) => decoder(bytes33)));
|
330
|
+
var dynamicDec = (...decoders) => {
|
331
|
+
const res = toInternalBytes((bytes33) => {
|
332
|
+
const result = new Array(decoders.length);
|
333
|
+
let start = bytes33.i;
|
334
|
+
for (let i = 0; i < decoders.length; i++) {
|
335
|
+
if (decoders[i].dyn) {
|
336
|
+
const offset = Number(uint[1](bytes33));
|
337
|
+
const current = bytes33.i;
|
338
|
+
bytes33.i = start + offset;
|
339
|
+
result[i] = decoders[i](bytes33);
|
340
|
+
bytes33.i = current;
|
341
|
+
} else {
|
342
|
+
result[i] = decoders[i](bytes33);
|
343
|
+
}
|
344
|
+
}
|
345
|
+
return result;
|
346
|
+
});
|
347
|
+
res.dyn = true;
|
348
|
+
return res;
|
349
|
+
};
|
350
|
+
var Tuple = (...codecs) => {
|
351
|
+
const isDyn = codecs.some((c) => c.dyn);
|
352
|
+
const [enc, dec] = isDyn ? [dynamicEnc, dynamicDec] : [staticEnc, staticDec];
|
353
|
+
const res = createCodec(enc(...codecs.map(([encoder]) => encoder)), dec(...codecs.map(([, decoder]) => decoder)));
|
354
|
+
res.dyn = isDyn;
|
355
|
+
return res;
|
328
356
|
};
|
329
|
-
|
330
|
-
|
331
|
-
|
357
|
+
|
358
|
+
// src/codecs/Struct.ts
|
359
|
+
var Struct = (codecs) => {
|
360
|
+
const keys = Object.keys(codecs);
|
361
|
+
return enhanceCodec(Tuple(...Object.values(codecs)), (input) => keys.map((k) => input[k]), (tuple) => Object.fromEntries(tuple.map((value, idx) => [keys[idx], value])));
|
332
362
|
};
|
333
|
-
var struct = (codecs) => createCodec(structEnc(mapObject(codecs, (x) => x[0])), structDec(mapObject(codecs, (x) => x[1])));
|
334
|
-
struct.enc = structEnc;
|
335
|
-
struct.dec = structDec;
|
336
363
|
|
337
|
-
// src/codecs/
|
338
|
-
|
364
|
+
// src/codecs/Vector.ts
|
365
|
+
import { mergeUint8 as mergeUint83 } from "@unstoppablejs/utils";
|
339
366
|
var vectorEnc = (inner, size) => {
|
340
|
-
if (size >= 0)
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
367
|
+
if (size >= 0) {
|
368
|
+
const encoder2 = (value) => mergeUint83(...value.map(inner));
|
369
|
+
encoder2.dyn = inner.dyn;
|
370
|
+
return encoder2;
|
371
|
+
}
|
372
|
+
const encoder = (value) => mergeUint83(uint[0](BigInt(value.length)), ...value.map(inner));
|
373
|
+
encoder.dyn = true;
|
374
|
+
return encoder;
|
345
375
|
};
|
346
376
|
var vectorDec = (getter, size) => {
|
347
|
-
const
|
348
|
-
const nElements = size >= 0 ? size : Number(
|
349
|
-
const
|
377
|
+
const decoder = toInternalBytes((bytes33) => {
|
378
|
+
const nElements = size >= 0 ? size : Number(uint[1](bytes33));
|
379
|
+
const decoded = new Array(nElements);
|
350
380
|
for (let i = 0; i < nElements; i++) {
|
351
|
-
|
381
|
+
decoded[i] = getter(bytes33);
|
352
382
|
}
|
353
|
-
return
|
383
|
+
return decoded;
|
354
384
|
});
|
355
385
|
if (size == null)
|
356
|
-
|
357
|
-
return
|
386
|
+
decoder.dyn = true;
|
387
|
+
return decoder;
|
358
388
|
};
|
359
|
-
var
|
360
|
-
const
|
389
|
+
var Vector = (inner, size) => {
|
390
|
+
const codec = createCodec(vectorEnc(inner[0], size), vectorDec(inner[1], size));
|
361
391
|
if (size == null)
|
362
|
-
|
363
|
-
return
|
392
|
+
codec.dyn = true;
|
393
|
+
return codec;
|
364
394
|
};
|
365
|
-
vector.enc = vectorEnc;
|
366
|
-
vector.dec = vectorDec;
|
367
395
|
export {
|
396
|
+
Fixed,
|
397
|
+
Struct,
|
398
|
+
Tuple,
|
399
|
+
Vector,
|
400
|
+
address,
|
368
401
|
bool,
|
369
402
|
bytes,
|
370
|
-
|
403
|
+
bytes1,
|
404
|
+
bytes10,
|
405
|
+
bytes11,
|
406
|
+
bytes12,
|
407
|
+
bytes13,
|
408
|
+
bytes14,
|
409
|
+
bytes15,
|
410
|
+
bytes16,
|
411
|
+
bytes17,
|
412
|
+
bytes18,
|
413
|
+
bytes19,
|
414
|
+
bytes2,
|
415
|
+
bytes20,
|
416
|
+
bytes21,
|
417
|
+
bytes22,
|
418
|
+
bytes23,
|
419
|
+
bytes24,
|
420
|
+
bytes25,
|
421
|
+
bytes26,
|
422
|
+
bytes27,
|
423
|
+
bytes28,
|
424
|
+
bytes29,
|
425
|
+
bytes3,
|
426
|
+
bytes30,
|
427
|
+
bytes31,
|
428
|
+
bytes32,
|
429
|
+
bytes4,
|
430
|
+
bytes5,
|
431
|
+
bytes6,
|
432
|
+
bytes7,
|
433
|
+
bytes8,
|
434
|
+
bytes9,
|
371
435
|
createCodec,
|
372
436
|
enhanceCodec,
|
373
437
|
enhanceDecoder,
|
374
438
|
enhanceEncoder,
|
375
|
-
fixed,
|
376
439
|
int,
|
440
|
+
int104,
|
441
|
+
int112,
|
442
|
+
int120,
|
443
|
+
int128,
|
444
|
+
int136,
|
445
|
+
int144,
|
446
|
+
int152,
|
447
|
+
int16,
|
448
|
+
int160,
|
449
|
+
int168,
|
450
|
+
int176,
|
451
|
+
int184,
|
452
|
+
int192,
|
453
|
+
int200,
|
454
|
+
int208,
|
455
|
+
int224,
|
456
|
+
int226,
|
457
|
+
int232,
|
458
|
+
int24,
|
459
|
+
int240,
|
460
|
+
int248,
|
461
|
+
int256,
|
462
|
+
int32,
|
463
|
+
int40,
|
464
|
+
int48,
|
465
|
+
int56,
|
466
|
+
int64,
|
467
|
+
int72,
|
468
|
+
int8,
|
469
|
+
int80,
|
470
|
+
int88,
|
471
|
+
int96,
|
377
472
|
str,
|
378
|
-
struct,
|
379
|
-
tuple,
|
380
|
-
ufixed,
|
381
473
|
uint,
|
382
|
-
|
474
|
+
uint104,
|
475
|
+
uint112,
|
476
|
+
uint120,
|
477
|
+
uint128,
|
478
|
+
uint136,
|
479
|
+
uint144,
|
480
|
+
uint152,
|
481
|
+
uint16,
|
482
|
+
uint160,
|
483
|
+
uint168,
|
484
|
+
uint176,
|
485
|
+
uint184,
|
486
|
+
uint192,
|
487
|
+
uint200,
|
488
|
+
uint208,
|
489
|
+
uint224,
|
490
|
+
uint226,
|
491
|
+
uint232,
|
492
|
+
uint24,
|
493
|
+
uint240,
|
494
|
+
uint248,
|
495
|
+
uint256,
|
496
|
+
uint32,
|
497
|
+
uint40,
|
498
|
+
uint48,
|
499
|
+
uint56,
|
500
|
+
uint64,
|
501
|
+
uint72,
|
502
|
+
uint8,
|
503
|
+
uint80,
|
504
|
+
uint88,
|
505
|
+
uint96
|
383
506
|
};
|
384
507
|
//# sourceMappingURL=solidity-codecs.js.map
|