solidity-codecs 0.0.1-beta.3 → 0.1.1
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 -3
- package/dist/codecs/Int.d.ts +3 -6
- package/dist/codecs/Uint.d.ts +2 -5
- package/dist/codecs/Vector.d.ts +2 -6
- package/dist/codecs/address.d.ts +1 -0
- package/dist/codecs/bytes.d.ts +1 -0
- package/dist/codecs/index.d.ts +6 -4
- package/dist/solidity-codecs.cjs.development.js +306 -176
- 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 +304 -174
- package/dist/solidity-codecs.js.map +3 -3
- package/dist/solidity-codecs.mjs +304 -174
- package/dist/solidity-codecs.mjs.map +3 -3
- package/dist/types.d.ts +0 -4
- package/dist/utils.d.ts +0 -5
- package/package.json +7 -8
- package/dist/codecs/Bytes.d.ts +0 -6
@@ -0,0 +1,2 @@
|
|
1
|
+
import { Codec } from "../types";
|
2
|
+
export declare const bytes1: Codec<Uint8Array>, bytes2: Codec<Uint8Array>, bytes3: Codec<Uint8Array>, bytes4: Codec<Uint8Array>, bytes5: Codec<Uint8Array>, bytes6: Codec<Uint8Array>, bytes7: Codec<Uint8Array>, bytes8: Codec<Uint8Array>, bytes9: Codec<Uint8Array>, bytes10: Codec<Uint8Array>, bytes11: Codec<Uint8Array>, bytes12: Codec<Uint8Array>, bytes13: Codec<Uint8Array>, bytes14: Codec<Uint8Array>, bytes15: Codec<Uint8Array>, bytes16: Codec<Uint8Array>, bytes17: Codec<Uint8Array>, bytes18: Codec<Uint8Array>, bytes19: Codec<Uint8Array>, bytes20: Codec<Uint8Array>, bytes21: Codec<Uint8Array>, bytes22: Codec<Uint8Array>, bytes23: Codec<Uint8Array>, bytes24: Codec<Uint8Array>, bytes25: Codec<Uint8Array>, bytes26: Codec<Uint8Array>, bytes27: Codec<Uint8Array>, bytes28: Codec<Uint8Array>, bytes29: Codec<Uint8Array>, bytes30: Codec<Uint8Array>, bytes31: Codec<Uint8Array>, bytes32: Codec<Uint8Array>;
|
package/dist/codecs/Fixed.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
-
import { Codec
|
2
|
-
export
|
3
|
-
|
1
|
+
import { Codec } from "../types";
|
2
|
+
export interface Decimal<T extends number = number> {
|
3
|
+
value: bigint;
|
4
|
+
decimals: T;
|
5
|
+
}
|
6
|
+
export declare const Fixed: <D extends number>(baseCodec: Codec<bigint>, decimals: D) => Codec<Decimal<D>>;
|
package/dist/codecs/Int.d.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
export declare const
|
3
|
-
|
4
|
-
enc(nBits: number): Encoder<bigint>;
|
5
|
-
dec(nBits: number): import("../types").Decoder<bigint>;
|
6
|
-
};
|
1
|
+
import { Codec } from "../types";
|
2
|
+
export declare const int8: Codec<bigint>, int16: Codec<bigint>, int24: Codec<bigint>, int32: Codec<bigint>, int40: Codec<bigint>, int48: Codec<bigint>, int56: Codec<bigint>, int64: Codec<bigint>, int72: Codec<bigint>, int80: Codec<bigint>, int88: Codec<bigint>, int96: Codec<bigint>, int104: Codec<bigint>, int112: Codec<bigint>, int120: Codec<bigint>, int128: Codec<bigint>, int136: Codec<bigint>, int144: Codec<bigint>, int152: Codec<bigint>, int160: Codec<bigint>, int168: Codec<bigint>, int176: Codec<bigint>, int184: Codec<bigint>, int192: Codec<bigint>, int200: Codec<bigint>, int208: Codec<bigint>, int226: Codec<bigint>, int224: Codec<bigint>, int232: Codec<bigint>, int240: Codec<bigint>, int248: Codec<bigint>, int256: Codec<bigint>;
|
3
|
+
export declare const int: Codec<bigint>;
|
package/dist/codecs/Uint.d.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
1
|
import { Codec } from "../types";
|
2
|
-
export declare const
|
3
|
-
|
4
|
-
enc(nBits: number): import("../types").Encoder<bigint>;
|
5
|
-
dec(nBits: number): import("../types").Decoder<bigint>;
|
6
|
-
};
|
2
|
+
export declare const uint8: Codec<bigint>, uint16: Codec<bigint>, uint24: Codec<bigint>, uint32: Codec<bigint>, uint40: Codec<bigint>, uint48: Codec<bigint>, uint56: Codec<bigint>, uint64: Codec<bigint>, uint72: Codec<bigint>, uint80: Codec<bigint>, uint88: Codec<bigint>, uint96: Codec<bigint>, uint104: Codec<bigint>, uint112: Codec<bigint>, uint120: Codec<bigint>, uint128: Codec<bigint>, uint136: Codec<bigint>, uint144: Codec<bigint>, uint152: Codec<bigint>, uint160: Codec<bigint>, uint168: Codec<bigint>, uint176: Codec<bigint>, uint184: Codec<bigint>, uint192: Codec<bigint>, uint200: Codec<bigint>, uint208: Codec<bigint>, uint226: Codec<bigint>, uint224: Codec<bigint>, uint232: Codec<bigint>, uint240: Codec<bigint>, uint248: Codec<bigint>, uint256: Codec<bigint>;
|
3
|
+
export declare const uint: Codec<bigint>;
|
package/dist/codecs/Vector.d.ts
CHANGED
@@ -1,6 +1,2 @@
|
|
1
|
-
import { Codec
|
2
|
-
export declare const Vector:
|
3
|
-
<T>(inner: Codec<T>, size?: number | undefined): Codec<T[]>;
|
4
|
-
enc: <T_1>(inner: Encoder<T_1>, size?: number | undefined) => Encoder<T_1[]>;
|
5
|
-
dec: <T_2>(getter: Decoder<T_2>, size?: number | undefined) => Decoder<T_2[]>;
|
6
|
-
};
|
1
|
+
import { Codec } from "../types";
|
2
|
+
export declare const Vector: <T>(inner: Codec<T>, size?: number | undefined) => Codec<T[]>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const address: import("..").Codec<string>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const bytes: import("../types").Codec<Uint8Array>;
|
package/dist/codecs/index.d.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
export { address } from "./address";
|
1
2
|
export { bool } from "./bool";
|
3
|
+
export { bytes } from "./bytes";
|
2
4
|
export { str } from "./str";
|
3
|
-
export
|
4
|
-
export
|
5
|
-
export
|
5
|
+
export * from "./BytesX";
|
6
|
+
export * from "./Int";
|
7
|
+
export * from "./Uint";
|
8
|
+
export * from "./Fixed";
|
6
9
|
export { Struct } from "./Struct";
|
7
10
|
export { Tuple } from "./Tuple";
|
8
|
-
export { Uint } from "./Uint";
|
9
11
|
export { Vector } from "./Vector";
|
@@ -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
|
-
Bytes: () => Bytes,
|
28
27
|
Fixed: () => Fixed,
|
29
|
-
Int: () => Int,
|
30
28
|
Struct: () => Struct,
|
31
29
|
Tuple: () => Tuple,
|
32
|
-
Ufixed: () => Ufixed,
|
33
|
-
Uint: () => Uint,
|
34
30
|
Vector: () => Vector,
|
31
|
+
address: () => address,
|
35
32
|
bool: () => bool,
|
33
|
+
bytes: () => bytes,
|
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,
|
36
66
|
createCodec: () => createCodec,
|
37
|
-
dyn: () => dyn,
|
38
67
|
enhanceCodec: () => enhanceCodec,
|
39
68
|
enhanceDecoder: () => enhanceDecoder,
|
40
69
|
enhanceEncoder: () => enhanceEncoder,
|
41
|
-
|
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,
|
103
|
+
str: () => str,
|
104
|
+
uint: () => uint,
|
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
|
|
@@ -58,46 +153,12 @@ var enhanceEncoder = (encoder, mapper) => dyn(encoder, (value) => encoder(mapper
|
|
58
153
|
var enhanceDecoder = (decoder, mapper) => dyn(decoder, (value) => mapper(decoder(value)));
|
59
154
|
var enhanceCodec = (codec, toFrom, fromTo) => dyn(codec, createCodec(enhanceEncoder(codec[0], toFrom), enhanceDecoder(codec[1], fromTo)));
|
60
155
|
|
156
|
+
// src/codecs/address.ts
|
157
|
+
var import_utils2 = require("@unstoppablejs/utils");
|
158
|
+
var import_sha3 = require("@noble/hashes/sha3");
|
159
|
+
|
61
160
|
// src/internal/toInternalBytes.ts
|
62
|
-
var
|
63
|
-
0: 0,
|
64
|
-
1: 1,
|
65
|
-
2: 2,
|
66
|
-
3: 3,
|
67
|
-
4: 4,
|
68
|
-
5: 5,
|
69
|
-
6: 6,
|
70
|
-
7: 7,
|
71
|
-
8: 8,
|
72
|
-
9: 9,
|
73
|
-
a: 10,
|
74
|
-
b: 11,
|
75
|
-
c: 12,
|
76
|
-
d: 13,
|
77
|
-
e: 14,
|
78
|
-
f: 15,
|
79
|
-
A: 10,
|
80
|
-
B: 11,
|
81
|
-
C: 12,
|
82
|
-
D: 13,
|
83
|
-
E: 14,
|
84
|
-
F: 15
|
85
|
-
};
|
86
|
-
function fromHex(hexString) {
|
87
|
-
const isOdd = hexString.length % 2;
|
88
|
-
const base = (hexString[1] === "x" ? 2 : 0) + isOdd;
|
89
|
-
const nBytes = (hexString.length - base) / 2 + isOdd;
|
90
|
-
const bytes = new Uint8Array(nBytes);
|
91
|
-
if (isOdd)
|
92
|
-
bytes[0] = 0 | HEX_MAP[hexString[2]];
|
93
|
-
for (let i = 0; i < nBytes; ) {
|
94
|
-
const idx = base + i * 2;
|
95
|
-
const a = HEX_MAP[hexString[idx]];
|
96
|
-
const b = HEX_MAP[hexString[idx + 1]];
|
97
|
-
bytes[isOdd + i++] = a << 4 | b;
|
98
|
-
}
|
99
|
-
return bytes;
|
100
|
-
}
|
161
|
+
var import_utils = require("@unstoppablejs/utils");
|
101
162
|
var InternalUint8Array = class extends Uint8Array {
|
102
163
|
constructor(buffer) {
|
103
164
|
super(buffer);
|
@@ -106,22 +167,29 @@ var InternalUint8Array = class extends Uint8Array {
|
|
106
167
|
this.v = new DataView(buffer);
|
107
168
|
}
|
108
169
|
};
|
109
|
-
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));
|
110
171
|
|
111
|
-
// src/internal/
|
112
|
-
var
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
for (let idx = 0, at = 0; idx < len; idx++) {
|
119
|
-
const current = inputs[idx];
|
120
|
-
result.set(current, at);
|
121
|
-
at += current.byteLength;
|
122
|
-
}
|
172
|
+
// src/internal/range32.ts
|
173
|
+
var range32 = Array(32).fill(0).map((_, idx) => idx + 1);
|
174
|
+
|
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);
|
123
179
|
return result;
|
124
|
-
}
|
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
194
|
// src/codecs/Uint.ts
|
127
195
|
var getCodec = (nBytes) => {
|
@@ -135,74 +203,128 @@ var getCodec = (nBytes) => {
|
|
135
203
|
input >>= 64n;
|
136
204
|
}
|
137
205
|
return result;
|
138
|
-
}, toInternalBytes((
|
206
|
+
}, toInternalBytes((bytes33) => {
|
139
207
|
let result = 0n;
|
140
|
-
const nextBlock =
|
141
|
-
for (let idx =
|
142
|
-
result = result << 64n |
|
143
|
-
|
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;
|
144
212
|
return result;
|
145
213
|
}));
|
146
214
|
};
|
147
|
-
var
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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;
|
159
250
|
|
160
251
|
// src/codecs/bool.ts
|
161
|
-
var bool = enhanceCodec(
|
252
|
+
var bool = enhanceCodec(uint8, (value) => value ? 1n : 0n, Boolean);
|
162
253
|
|
163
|
-
// src/codecs/
|
164
|
-
var
|
165
|
-
var
|
166
|
-
|
167
|
-
const val = textEncoder.encode(str2);
|
168
|
-
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];
|
169
258
|
const extra = val.length % 32;
|
170
259
|
if (extra > 0) {
|
171
260
|
;
|
172
261
|
args.push(new Uint8Array(32 - extra));
|
173
262
|
}
|
174
|
-
return mergeUint8(...args);
|
263
|
+
return (0, import_utils5.mergeUint8)(...args);
|
175
264
|
};
|
176
|
-
|
177
|
-
var
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
const padding = extra && 32 - extra;
|
183
|
-
bytes.i += nElements + padding;
|
184
|
-
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;
|
185
271
|
});
|
186
|
-
|
187
|
-
var
|
188
|
-
|
272
|
+
bytesDec.dyn = true;
|
273
|
+
var bytes = createCodec(bytesEnc, bytesDec);
|
274
|
+
bytes.dyn = true;
|
275
|
+
|
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));
|
189
280
|
|
190
|
-
// src/codecs/
|
191
|
-
var
|
192
|
-
if (
|
193
|
-
return
|
281
|
+
// src/codecs/BytesX.ts
|
282
|
+
var bytesEnc2 = (nBytes) => (bytes33) => {
|
283
|
+
if (bytes33.length === nBytes && nBytes === 32)
|
284
|
+
return bytes33;
|
194
285
|
const result = new Uint8Array(32);
|
195
|
-
result.set(
|
286
|
+
result.set(bytes33.length === nBytes ? bytes33 : bytes33.slice(0, nBytes));
|
196
287
|
return result;
|
197
288
|
};
|
198
|
-
var
|
199
|
-
const result = new Uint8Array(
|
200
|
-
|
289
|
+
var bytesDec2 = (nBytes) => toInternalBytes((bytes33) => {
|
290
|
+
const result = new Uint8Array(bytes33.buffer, bytes33.i, nBytes);
|
291
|
+
bytes33.i += 32;
|
201
292
|
return result;
|
202
293
|
});
|
203
|
-
var
|
204
|
-
|
205
|
-
|
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)));
|
206
328
|
|
207
329
|
// src/codecs/Int.ts
|
208
330
|
var signGetters = {
|
@@ -243,62 +365,72 @@ var getCodec2 = (nBytes) => {
|
|
243
365
|
}
|
244
366
|
let idx = 32;
|
245
367
|
for (let i = sequence.length - 1; i > 0; i--) {
|
246
|
-
const [
|
247
|
-
idx -=
|
248
|
-
dv[usignSetters[
|
368
|
+
const [bytes34, shift, fn2] = sequence[i];
|
369
|
+
idx -= bytes34;
|
370
|
+
dv[usignSetters[bytes34]](idx, fn2(input));
|
249
371
|
input >>= shift;
|
250
372
|
}
|
251
|
-
const [
|
252
|
-
idx -=
|
253
|
-
dv[signSetters[
|
373
|
+
const [bytes33, , fn] = sequence[0];
|
374
|
+
idx -= bytes33;
|
375
|
+
dv[signSetters[bytes33]](idx, fn(input));
|
254
376
|
return result;
|
255
377
|
};
|
256
|
-
const dec = toInternalBytes((
|
257
|
-
let idx =
|
378
|
+
const dec = toInternalBytes((bytes33) => {
|
379
|
+
let idx = bytes33.i + 32 - nBytes;
|
258
380
|
const bits = sequence[0][0];
|
259
|
-
let result = BigInt(
|
381
|
+
let result = BigInt(bytes33.v[signGetters[bits]](idx));
|
260
382
|
idx += bits;
|
261
383
|
for (let i = 1; i < sequence.length; i++) {
|
262
384
|
const [bits2, shift] = sequence[i];
|
263
|
-
result = result << shift | BigInt(
|
385
|
+
result = result << shift | BigInt(bytes33.v[usignGetters[bits2]](idx));
|
264
386
|
idx += bits2;
|
265
387
|
}
|
266
|
-
|
388
|
+
bytes33.i += 32;
|
267
389
|
return result;
|
268
390
|
});
|
269
391
|
return createCodec(enc, dec);
|
270
392
|
};
|
271
|
-
var
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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;
|
283
428
|
|
284
429
|
// src/codecs/Fixed.ts
|
285
|
-
var
|
286
|
-
const cache3 = /* @__PURE__ */ new Map();
|
287
|
-
return (nBits, decimals) => {
|
288
|
-
const key = decimals << 8 | nBits;
|
289
|
-
let cached = cache3.get(key);
|
290
|
-
if (cached)
|
291
|
-
return cached;
|
292
|
-
cached = enhanceCodec(codec(nBits), (x) => x.value, (value) => ({ value, decimals }));
|
293
|
-
cache3.set(key, cached);
|
294
|
-
return cached;
|
295
|
-
};
|
296
|
-
};
|
297
|
-
var Fixed = creator(Int);
|
298
|
-
var Ufixed = creator(Uint);
|
430
|
+
var Fixed = (baseCodec, decimals) => enhanceCodec(baseCodec, (x) => x.value, (value) => ({ value, decimals }));
|
299
431
|
|
300
432
|
// src/codecs/Tuple.ts
|
301
|
-
var
|
433
|
+
var import_utils8 = require("@unstoppablejs/utils");
|
302
434
|
var dynamicEnc = (...encoders) => {
|
303
435
|
const res = (values) => {
|
304
436
|
const mapped = values.map((value, idx) => encoders[idx](value));
|
@@ -315,31 +447,31 @@ var dynamicEnc = (...encoders) => {
|
|
315
447
|
}
|
316
448
|
}
|
317
449
|
dinamics.forEach((idx) => {
|
318
|
-
resultArray[idx] =
|
450
|
+
resultArray[idx] = uint[0](len);
|
319
451
|
const data = mapped[idx];
|
320
452
|
resultArray.push(data);
|
321
453
|
len += BigInt(data.length);
|
322
454
|
});
|
323
|
-
return mergeUint8(...resultArray);
|
455
|
+
return (0, import_utils8.mergeUint8)(...resultArray);
|
324
456
|
};
|
325
457
|
res.dyn = true;
|
326
458
|
return res;
|
327
459
|
};
|
328
|
-
var staticEnc = (...encoders) => (values) => mergeUint8(...values.map((value, idx) => encoders[idx](value)));
|
329
|
-
var staticDec = (...decoders) => toInternalBytes((
|
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)));
|
330
462
|
var dynamicDec = (...decoders) => {
|
331
|
-
const res = toInternalBytes((
|
463
|
+
const res = toInternalBytes((bytes33) => {
|
332
464
|
const result = new Array(decoders.length);
|
333
|
-
let start =
|
465
|
+
let start = bytes33.i;
|
334
466
|
for (let i = 0; i < decoders.length; i++) {
|
335
467
|
if (decoders[i].dyn) {
|
336
|
-
const offset = Number(
|
337
|
-
const current =
|
338
|
-
|
339
|
-
result[i] = decoders[i](
|
340
|
-
|
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;
|
341
473
|
} else {
|
342
|
-
result[i] = decoders[i](
|
474
|
+
result[i] = decoders[i](bytes33);
|
343
475
|
}
|
344
476
|
}
|
345
477
|
return result;
|
@@ -362,36 +494,34 @@ var Struct = (codecs) => {
|
|
362
494
|
};
|
363
495
|
|
364
496
|
// src/codecs/Vector.ts
|
365
|
-
var
|
497
|
+
var import_utils11 = require("@unstoppablejs/utils");
|
366
498
|
var vectorEnc = (inner, size) => {
|
367
499
|
if (size >= 0) {
|
368
|
-
const
|
369
|
-
|
370
|
-
return
|
500
|
+
const encoder2 = (value) => (0, import_utils11.mergeUint8)(...value.map(inner));
|
501
|
+
encoder2.dyn = inner.dyn;
|
502
|
+
return encoder2;
|
371
503
|
}
|
372
|
-
const
|
373
|
-
|
374
|
-
return
|
504
|
+
const encoder = (value) => (0, import_utils11.mergeUint8)(uint[0](BigInt(value.length)), ...value.map(inner));
|
505
|
+
encoder.dyn = true;
|
506
|
+
return encoder;
|
375
507
|
};
|
376
508
|
var vectorDec = (getter, size) => {
|
377
|
-
const
|
378
|
-
const nElements = size >= 0 ? size : Number(
|
379
|
-
const
|
509
|
+
const decoder = toInternalBytes((bytes33) => {
|
510
|
+
const nElements = size >= 0 ? size : Number(uint[1](bytes33));
|
511
|
+
const decoded = new Array(nElements);
|
380
512
|
for (let i = 0; i < nElements; i++) {
|
381
|
-
|
513
|
+
decoded[i] = getter(bytes33);
|
382
514
|
}
|
383
|
-
return
|
515
|
+
return decoded;
|
384
516
|
});
|
385
517
|
if (size == null)
|
386
|
-
|
387
|
-
return
|
518
|
+
decoder.dyn = true;
|
519
|
+
return decoder;
|
388
520
|
};
|
389
521
|
var Vector = (inner, size) => {
|
390
|
-
const
|
522
|
+
const codec = createCodec(vectorEnc(inner[0], size), vectorDec(inner[1], size));
|
391
523
|
if (size == null)
|
392
|
-
|
393
|
-
return
|
524
|
+
codec.dyn = true;
|
525
|
+
return codec;
|
394
526
|
};
|
395
|
-
Vector.enc = vectorEnc;
|
396
|
-
Vector.dec = vectorDec;
|
397
527
|
//# sourceMappingURL=solidity-codecs.cjs.development.js.map
|