@feelyourprotocol/rlp 8141.0.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/LICENSE +373 -0
- package/README.md +89 -0
- package/bin/rlp.cjs +58 -0
- package/dist/cjs/errors.d.ts +39 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +44 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +42 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +300 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/errors.d.ts +39 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +39 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +42 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +280 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +78 -0
- package/src/errors.ts +57 -0
- package/src/index.ts +327 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.RLP = exports.utils = void 0;
|
|
18
|
+
exports.hexToBytes = hexToBytes;
|
|
19
|
+
exports.encode = encode;
|
|
20
|
+
exports.decode = decode;
|
|
21
|
+
const errors_ts_1 = require("./errors.js");
|
|
22
|
+
__exportStar(require("./errors.js"), exports);
|
|
23
|
+
/**
|
|
24
|
+
* Parse integers. Check if there is no leading zeros
|
|
25
|
+
* @param v The value to parse
|
|
26
|
+
*/
|
|
27
|
+
function decodeLength(v) {
|
|
28
|
+
if (v[0] === 0) {
|
|
29
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: extra zeros');
|
|
30
|
+
}
|
|
31
|
+
return parseHexByte(bytesToHex(v));
|
|
32
|
+
}
|
|
33
|
+
function encodeLength(len, offset) {
|
|
34
|
+
if (len < 56) {
|
|
35
|
+
return Uint8Array.from([len + offset]);
|
|
36
|
+
}
|
|
37
|
+
const hexLength = numberToHex(len);
|
|
38
|
+
const lLength = hexLength.length / 2;
|
|
39
|
+
const firstByte = numberToHex(offset + 55 + lLength);
|
|
40
|
+
return Uint8Array.from(hexToBytes(firstByte + hexLength));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Slices a Uint8Array, throws if the slice goes out-of-bounds of the Uint8Array.
|
|
44
|
+
* E.g. `safeSlice(hexToBytes('aa'), 1, 2)` will throw.
|
|
45
|
+
* @param input
|
|
46
|
+
* @param start
|
|
47
|
+
* @param end
|
|
48
|
+
*/
|
|
49
|
+
function safeSlice(input, start, end) {
|
|
50
|
+
if (end > input.length) {
|
|
51
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP (safeSlice): end slice of Uint8Array out-of-bounds');
|
|
52
|
+
}
|
|
53
|
+
return input.slice(start, end);
|
|
54
|
+
}
|
|
55
|
+
/** Decode an input with RLP */
|
|
56
|
+
function _decode(input) {
|
|
57
|
+
let length, lLength, data, innerRemainder, d;
|
|
58
|
+
const decoded = [];
|
|
59
|
+
const firstByte = input[0];
|
|
60
|
+
if (firstByte <= 0x7f) {
|
|
61
|
+
// a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.
|
|
62
|
+
return {
|
|
63
|
+
data: input.slice(0, 1),
|
|
64
|
+
remainder: input.subarray(1),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else if (firstByte <= 0xb7) {
|
|
68
|
+
// string is 0-55 bytes long. A single byte with value 0x80 plus the length of the string followed by the string
|
|
69
|
+
// The range of the first byte is [0x80, 0xb7]
|
|
70
|
+
length = firstByte - 0x7f;
|
|
71
|
+
// set 0x80 null to 0
|
|
72
|
+
if (firstByte === 0x80) {
|
|
73
|
+
data = Uint8Array.from([]);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
data = safeSlice(input, 1, length);
|
|
77
|
+
}
|
|
78
|
+
if (length === 2 && data[0] < 0x80) {
|
|
79
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP encoding: invalid prefix, single byte < 0x80 are not prefixed');
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
data,
|
|
83
|
+
remainder: input.subarray(length),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (firstByte <= 0xbf) {
|
|
87
|
+
// string is greater than 55 bytes long. A single byte with the value (0xb7 plus the length of the length),
|
|
88
|
+
// followed by the length, followed by the string
|
|
89
|
+
lLength = firstByte - 0xb6;
|
|
90
|
+
if (input.length - 1 < lLength) {
|
|
91
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: not enough bytes for string length');
|
|
92
|
+
}
|
|
93
|
+
length = decodeLength(safeSlice(input, 1, lLength));
|
|
94
|
+
if (length <= 55) {
|
|
95
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: expected string length to be greater than 55');
|
|
96
|
+
}
|
|
97
|
+
data = safeSlice(input, lLength, length + lLength);
|
|
98
|
+
return {
|
|
99
|
+
data,
|
|
100
|
+
remainder: input.subarray(length + lLength),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else if (firstByte <= 0xf7) {
|
|
104
|
+
// a list between 0-55 bytes long
|
|
105
|
+
length = firstByte - 0xbf;
|
|
106
|
+
innerRemainder = safeSlice(input, 1, length);
|
|
107
|
+
while (innerRemainder.length) {
|
|
108
|
+
d = _decode(innerRemainder);
|
|
109
|
+
decoded.push(d.data);
|
|
110
|
+
innerRemainder = d.remainder;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
data: decoded,
|
|
114
|
+
remainder: input.subarray(length),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// a list over 55 bytes long
|
|
119
|
+
lLength = firstByte - 0xf6;
|
|
120
|
+
length = decodeLength(safeSlice(input, 1, lLength));
|
|
121
|
+
if (length < 56) {
|
|
122
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: encoded list too short');
|
|
123
|
+
}
|
|
124
|
+
const totalLength = lLength + length;
|
|
125
|
+
if (totalLength > input.length) {
|
|
126
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: total length is larger than the data');
|
|
127
|
+
}
|
|
128
|
+
innerRemainder = safeSlice(input, lLength, totalLength);
|
|
129
|
+
while (innerRemainder.length) {
|
|
130
|
+
d = _decode(innerRemainder);
|
|
131
|
+
decoded.push(d.data);
|
|
132
|
+
innerRemainder = d.remainder;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
data: decoded,
|
|
136
|
+
remainder: input.subarray(totalLength),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const cachedHexes = Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, '0'));
|
|
141
|
+
function bytesToHex(uint8a) {
|
|
142
|
+
// Pre-caching chars with `cachedHexes` speeds this up 6x
|
|
143
|
+
let hex = '';
|
|
144
|
+
for (let i = 0; i < uint8a.length; i++) {
|
|
145
|
+
hex += cachedHexes[uint8a[i]];
|
|
146
|
+
}
|
|
147
|
+
return hex;
|
|
148
|
+
}
|
|
149
|
+
function parseHexByte(hexByte) {
|
|
150
|
+
const byte = Number.parseInt(hexByte, 16);
|
|
151
|
+
if (Number.isNaN(byte))
|
|
152
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid byte sequence');
|
|
153
|
+
return byte;
|
|
154
|
+
}
|
|
155
|
+
// Borrowed from @noble/curves to avoid dependency
|
|
156
|
+
// Original code here - https://github.com/paulmillr/noble-curves/blob/d0a8d2134c5737d9d0aa81be13581cd416ebdeb4/src/abstract/utils.ts#L63-L91
|
|
157
|
+
const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
|
|
158
|
+
function asciiToBase16(char) {
|
|
159
|
+
if (char >= asciis._0 && char <= asciis._9)
|
|
160
|
+
return char - asciis._0;
|
|
161
|
+
if (char >= asciis._A && char <= asciis._F)
|
|
162
|
+
return char - (asciis._A - 10);
|
|
163
|
+
if (char >= asciis._a && char <= asciis._f)
|
|
164
|
+
return char - (asciis._a - 10);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @example hexToBytes('0xcafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
169
|
+
*/
|
|
170
|
+
function hexToBytes(hex) {
|
|
171
|
+
if (hex.slice(0, 2) === '0x')
|
|
172
|
+
hex = hex.slice(0, 2);
|
|
173
|
+
if (typeof hex !== 'string')
|
|
174
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('hex string expected, got ' + typeof hex);
|
|
175
|
+
const hl = hex.length;
|
|
176
|
+
const al = hl / 2;
|
|
177
|
+
if (hl % 2)
|
|
178
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('padded hex string expected, got unpadded hex of length ' + hl);
|
|
179
|
+
const array = new Uint8Array(al);
|
|
180
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
181
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
182
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
183
|
+
if (n1 === undefined || n2 === undefined) {
|
|
184
|
+
const char = hex[hi] + hex[hi + 1];
|
|
185
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
186
|
+
}
|
|
187
|
+
array[ai] = n1 * 16 + n2;
|
|
188
|
+
}
|
|
189
|
+
return array;
|
|
190
|
+
}
|
|
191
|
+
/** Concatenates two Uint8Arrays into one. */
|
|
192
|
+
function concatBytes(...arrays) {
|
|
193
|
+
if (arrays.length === 1)
|
|
194
|
+
return arrays[0];
|
|
195
|
+
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
196
|
+
const result = new Uint8Array(length);
|
|
197
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
198
|
+
const arr = arrays[i];
|
|
199
|
+
result.set(arr, pad);
|
|
200
|
+
pad += arr.length;
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
function utf8ToBytes(utf) {
|
|
205
|
+
return new TextEncoder().encode(utf);
|
|
206
|
+
}
|
|
207
|
+
/** Transform an integer into its hexadecimal value */
|
|
208
|
+
function numberToHex(integer) {
|
|
209
|
+
if (integer < 0) {
|
|
210
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid integer as argument, must be unsigned!');
|
|
211
|
+
}
|
|
212
|
+
const hex = integer.toString(16);
|
|
213
|
+
return hex.length % 2 ? `0${hex}` : hex;
|
|
214
|
+
}
|
|
215
|
+
/** Pad a string to be even */
|
|
216
|
+
function padToEven(a) {
|
|
217
|
+
return a.length % 2 ? `0${a}` : a;
|
|
218
|
+
}
|
|
219
|
+
/** Check if a string is prefixed by 0x */
|
|
220
|
+
function isHexString(str) {
|
|
221
|
+
return str.length >= 2 && str[0] === '0' && str[1] === 'x';
|
|
222
|
+
}
|
|
223
|
+
/** Removes 0x from a given String */
|
|
224
|
+
function stripHexPrefix(str) {
|
|
225
|
+
if (typeof str !== 'string') {
|
|
226
|
+
return str;
|
|
227
|
+
}
|
|
228
|
+
return isHexString(str) ? str.slice(2) : str;
|
|
229
|
+
}
|
|
230
|
+
/** Transform anything into a Uint8Array */
|
|
231
|
+
function toBytes(v) {
|
|
232
|
+
if (v instanceof Uint8Array) {
|
|
233
|
+
return v;
|
|
234
|
+
}
|
|
235
|
+
if (typeof v === 'string') {
|
|
236
|
+
if (isHexString(v)) {
|
|
237
|
+
return hexToBytes(padToEven(stripHexPrefix(v)));
|
|
238
|
+
}
|
|
239
|
+
return utf8ToBytes(v);
|
|
240
|
+
}
|
|
241
|
+
if (typeof v === 'number' || typeof v === 'bigint') {
|
|
242
|
+
if (!v) {
|
|
243
|
+
return Uint8Array.from([]);
|
|
244
|
+
}
|
|
245
|
+
return hexToBytes(numberToHex(v));
|
|
246
|
+
}
|
|
247
|
+
if (v === null || v === undefined) {
|
|
248
|
+
return Uint8Array.from([]);
|
|
249
|
+
}
|
|
250
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('toBytes: received unsupported type ' + typeof v);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* RLP Encoding based on https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/
|
|
254
|
+
* This function takes in data, converts it to Uint8Array if not,
|
|
255
|
+
* and adds a length for recursion.
|
|
256
|
+
* @param input Will be converted to Uint8Array
|
|
257
|
+
* @returns Uint8Array of encoded data
|
|
258
|
+
**/
|
|
259
|
+
function encode(input) {
|
|
260
|
+
if (Array.isArray(input)) {
|
|
261
|
+
const output = [];
|
|
262
|
+
let outputLength = 0;
|
|
263
|
+
for (let i = 0; i < input.length; i++) {
|
|
264
|
+
const encoded = encode(input[i]);
|
|
265
|
+
output.push(encoded);
|
|
266
|
+
outputLength += encoded.length;
|
|
267
|
+
}
|
|
268
|
+
return concatBytes(encodeLength(outputLength, 192), ...output);
|
|
269
|
+
}
|
|
270
|
+
const inputBuf = toBytes(input);
|
|
271
|
+
if (inputBuf.length === 1 && inputBuf[0] < 128) {
|
|
272
|
+
return inputBuf;
|
|
273
|
+
}
|
|
274
|
+
return concatBytes(encodeLength(inputBuf.length, 128), inputBuf);
|
|
275
|
+
}
|
|
276
|
+
function decode(input, stream = false) {
|
|
277
|
+
if (typeof input === 'undefined' || input === null || input.length === 0) {
|
|
278
|
+
return Uint8Array.from([]);
|
|
279
|
+
}
|
|
280
|
+
const inputBytes = toBytes(input);
|
|
281
|
+
const decoded = _decode(inputBytes);
|
|
282
|
+
if (stream) {
|
|
283
|
+
return {
|
|
284
|
+
data: decoded.data,
|
|
285
|
+
remainder: decoded.remainder.slice(),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (decoded.remainder.length !== 0) {
|
|
289
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('invalid RLP: remainder must be zero');
|
|
290
|
+
}
|
|
291
|
+
return decoded.data;
|
|
292
|
+
}
|
|
293
|
+
exports.utils = {
|
|
294
|
+
bytesToHex,
|
|
295
|
+
concatBytes,
|
|
296
|
+
hexToBytes,
|
|
297
|
+
utf8ToBytes,
|
|
298
|
+
};
|
|
299
|
+
exports.RLP = { encode, decode };
|
|
300
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA2KA,gCAqBC;AAgFD,wBAgBC;AAUD,wBAmBC;AA7TD,2CAAwD;AAExD,8CAA2B;AAW3B;;;GAGG;AACH,SAAS,YAAY,CAAC,CAAa;IACjC,IA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AAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC;QAC/C,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAA;AAClE,CAAC;AAUD,SAAgB,MAAM,CAAC,KAAY,EAAE,MAAM,GAAG,KAAK;IACjD,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,IAAK,KAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClF,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC5B,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEnC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE;SACrC,CAAA;IACH,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAA,sCAA0B,EAAC,qCAAqC,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAA;AACrB,CAAC;AAEY,QAAA,KAAK,GAAG;IACnB,UAAU;IACV,WAAW;IACX,UAAU;IACV,WAAW;CACZ,CAAA;AAEY,QAAA,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic EthereumJS error class with metadata attached
|
|
3
|
+
*
|
|
4
|
+
* Kudos to https://github.com/ChainSafe/lodestar monorepo
|
|
5
|
+
* for the inspiration :-)
|
|
6
|
+
* See: https://github.com/ChainSafe/lodestar/blob/unstable/packages/utils/src/errors.ts
|
|
7
|
+
*/
|
|
8
|
+
export type EthereumJSErrorMetaData = Record<string, string | number | null>;
|
|
9
|
+
export type EthereumJSErrorObject = {
|
|
10
|
+
message: string;
|
|
11
|
+
stack: string;
|
|
12
|
+
className: string;
|
|
13
|
+
type: EthereumJSErrorMetaData;
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_ERROR_CODE = "ETHEREUMJS_DEFAULT_ERROR_CODE";
|
|
16
|
+
/**
|
|
17
|
+
* Generic EthereumJS error with attached metadata
|
|
18
|
+
*/
|
|
19
|
+
export declare class EthereumJSError<T extends {
|
|
20
|
+
code: string;
|
|
21
|
+
}> extends Error {
|
|
22
|
+
type: T;
|
|
23
|
+
constructor(type: T, message?: string, stack?: string);
|
|
24
|
+
getMetadata(): EthereumJSErrorMetaData;
|
|
25
|
+
/**
|
|
26
|
+
* Get the metadata and the stacktrace for the error.
|
|
27
|
+
*/
|
|
28
|
+
toObject(): EthereumJSErrorObject;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `EthereumJSError` with a set error code instead
|
|
32
|
+
* @param message Optional error message
|
|
33
|
+
* @param stack Optional stack trace
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function EthereumJSErrorWithoutCode(message?: string, stack?: string): EthereumJSError<{
|
|
37
|
+
code: string;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAA;AAC5E,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,uBAAuB,CAAA;CAC9B,CAAA;AAKD,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AAEjE;;GAEG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAE,SAAQ,KAAK;IACpE,IAAI,EAAE,CAAC,CAAA;gBACK,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAMrD,WAAW,IAAI,uBAAuB;IAItC;;OAEG;IACH,QAAQ,IAAI,qBAAqB;CAQlC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;GAE1E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// In order to update all our errors to use `EthereumJSError`, temporarily include the
|
|
2
|
+
// unset error code. All errors throwing this code should be updated to use the relevant
|
|
3
|
+
// error code.
|
|
4
|
+
export const DEFAULT_ERROR_CODE = 'ETHEREUMJS_DEFAULT_ERROR_CODE';
|
|
5
|
+
/**
|
|
6
|
+
* Generic EthereumJS error with attached metadata
|
|
7
|
+
*/
|
|
8
|
+
export class EthereumJSError extends Error {
|
|
9
|
+
constructor(type, message, stack) {
|
|
10
|
+
super(message ?? type.code);
|
|
11
|
+
this.type = type;
|
|
12
|
+
if (stack !== undefined)
|
|
13
|
+
this.stack = stack;
|
|
14
|
+
}
|
|
15
|
+
getMetadata() {
|
|
16
|
+
return this.type;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the metadata and the stacktrace for the error.
|
|
20
|
+
*/
|
|
21
|
+
toObject() {
|
|
22
|
+
return {
|
|
23
|
+
type: this.getMetadata(),
|
|
24
|
+
message: this.message ?? '',
|
|
25
|
+
stack: this.stack ?? '',
|
|
26
|
+
className: this.constructor.name,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `EthereumJSError` with a set error code instead
|
|
32
|
+
* @param message Optional error message
|
|
33
|
+
* @param stack Optional stack trace
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export function EthereumJSErrorWithoutCode(message, stack) {
|
|
37
|
+
return new EthereumJSError({ code: DEFAULT_ERROR_CODE }, message, stack);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAeA,sFAAsF;AACtF,wFAAwF;AACxF,cAAc;AACd,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAA;AAEjE;;GAEG;AACH,MAAM,OAAO,eAA4C,SAAQ,KAAK;IAEpE,YAAY,IAAO,EAAE,OAAgB,EAAE,KAAc;QACnD,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IAC7C,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE;YACxB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;YACvB,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;SACjC,CAAA;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAgB,EAAE,KAAc;IACzE,OAAO,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export * from './errors.ts';
|
|
2
|
+
export type Input = string | number | bigint | Uint8Array | Array<Input> | null | undefined;
|
|
3
|
+
export type NestedUint8Array = Array<Uint8Array | NestedUint8Array>;
|
|
4
|
+
export interface Decoded {
|
|
5
|
+
data: Uint8Array | NestedUint8Array;
|
|
6
|
+
remainder: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
declare function bytesToHex(uint8a: Uint8Array): string;
|
|
9
|
+
/**
|
|
10
|
+
* @example hexToBytes('0xcafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
11
|
+
*/
|
|
12
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
13
|
+
/** Concatenates two Uint8Arrays into one. */
|
|
14
|
+
declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
15
|
+
declare function utf8ToBytes(utf: string): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* RLP Encoding based on https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/
|
|
18
|
+
* This function takes in data, converts it to Uint8Array if not,
|
|
19
|
+
* and adds a length for recursion.
|
|
20
|
+
* @param input Will be converted to Uint8Array
|
|
21
|
+
* @returns Uint8Array of encoded data
|
|
22
|
+
**/
|
|
23
|
+
export declare function encode(input: Input): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* RLP Decoding based on https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/
|
|
26
|
+
* @param input Will be converted to Uint8Array
|
|
27
|
+
* @param stream Is the input a stream (false by default)
|
|
28
|
+
* @returns decoded Array of Uint8Arrays containing the original message
|
|
29
|
+
**/
|
|
30
|
+
export declare function decode(input: Input, stream?: false): Uint8Array | NestedUint8Array;
|
|
31
|
+
export declare function decode(input: Input, stream?: true): Decoded;
|
|
32
|
+
export declare const utils: {
|
|
33
|
+
bytesToHex: typeof bytesToHex;
|
|
34
|
+
concatBytes: typeof concatBytes;
|
|
35
|
+
hexToBytes: typeof hexToBytes;
|
|
36
|
+
utf8ToBytes: typeof utf8ToBytes;
|
|
37
|
+
};
|
|
38
|
+
export declare const RLP: {
|
|
39
|
+
encode: typeof encode;
|
|
40
|
+
decode: typeof decode;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAE3B,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;AAE3F,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,GAAG,gBAAgB,CAAC,CAAA;AAEnE,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAAA;IACnC,SAAS,EAAE,UAAU,CAAA;CACtB;AAoID,iBAAS,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAO9C;AAkBD;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAqBlD;AAED,6CAA6C;AAC7C,iBAAS,WAAW,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAUxD;AAMD,iBAAS,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAE5C;AAoDD;;;;;;IAMI;AACJ,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAgB/C;AAED;;;;;IAKI;AACJ,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,gBAAgB,CAAA;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,OAAO,CAAA;AAsB5D,eAAO,MAAM,KAAK;;;;;CAKjB,CAAA;AAED,eAAO,MAAM,GAAG;;;CAAqB,CAAA"}
|