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