@feelyourprotocol/util 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 +297 -0
- package/dist/cjs/account.d.ts +165 -0
- package/dist/cjs/account.d.ts.map +1 -0
- package/dist/cjs/account.js +530 -0
- package/dist/cjs/account.js.map +1 -0
- package/dist/cjs/address.d.ts +67 -0
- package/dist/cjs/address.d.ts.map +1 -0
- package/dist/cjs/address.js +136 -0
- package/dist/cjs/address.js.map +1 -0
- package/dist/cjs/authorization.d.ts +41 -0
- package/dist/cjs/authorization.d.ts.map +1 -0
- package/dist/cjs/authorization.js +135 -0
- package/dist/cjs/authorization.js.map +1 -0
- package/dist/cjs/bal.d.ts +129 -0
- package/dist/cjs/bal.d.ts.map +1 -0
- package/dist/cjs/bal.js +529 -0
- package/dist/cjs/bal.js.map +1 -0
- package/dist/cjs/binaryTree.d.ts +148 -0
- package/dist/cjs/binaryTree.d.ts.map +1 -0
- package/dist/cjs/binaryTree.js +240 -0
- package/dist/cjs/binaryTree.js.map +1 -0
- package/dist/cjs/blobs.d.ts +76 -0
- package/dist/cjs/blobs.d.ts.map +1 -0
- package/dist/cjs/blobs.js +175 -0
- package/dist/cjs/blobs.js.map +1 -0
- package/dist/cjs/bytes.d.ts +291 -0
- package/dist/cjs/bytes.d.ts.map +1 -0
- package/dist/cjs/bytes.js +606 -0
- package/dist/cjs/bytes.js.map +1 -0
- package/dist/cjs/constants.d.ts +91 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +97 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/db.d.ts +65 -0
- package/dist/cjs/db.d.ts.map +1 -0
- package/dist/cjs/db.js +14 -0
- package/dist/cjs/db.js.map +1 -0
- package/dist/cjs/env.d.ts +9 -0
- package/dist/cjs/env.d.ts.map +1 -0
- package/dist/cjs/env.js +13 -0
- package/dist/cjs/env.js.map +1 -0
- package/dist/cjs/errors.d.ts +3 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +19 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/helpers.d.ts +21 -0
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +50 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.d.ts +67 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +93 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internal.d.ts +72 -0
- package/dist/cjs/internal.d.ts.map +1 -0
- package/dist/cjs/internal.js +182 -0
- package/dist/cjs/internal.js.map +1 -0
- package/dist/cjs/kzg.d.ts +14 -0
- package/dist/cjs/kzg.d.ts.map +1 -0
- package/dist/cjs/kzg.js +3 -0
- package/dist/cjs/kzg.js.map +1 -0
- package/dist/cjs/lock.d.ts +15 -0
- package/dist/cjs/lock.d.ts.map +1 -0
- package/dist/cjs/lock.js +45 -0
- package/dist/cjs/lock.js.map +1 -0
- package/dist/cjs/mapDB.d.ts +17 -0
- package/dist/cjs/mapDB.d.ts.map +1 -0
- package/dist/cjs/mapDB.js +46 -0
- package/dist/cjs/mapDB.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/provider.d.ts +46 -0
- package/dist/cjs/provider.d.ts.map +1 -0
- package/dist/cjs/provider.js +84 -0
- package/dist/cjs/provider.js.map +1 -0
- package/dist/cjs/request.d.ts +20 -0
- package/dist/cjs/request.d.ts.map +1 -0
- package/dist/cjs/request.js +35 -0
- package/dist/cjs/request.js.map +1 -0
- package/dist/cjs/signature.d.ts +47 -0
- package/dist/cjs/signature.d.ts.map +1 -0
- package/dist/cjs/signature.js +147 -0
- package/dist/cjs/signature.js.map +1 -0
- package/dist/cjs/tasks.d.ts +32 -0
- package/dist/cjs/tasks.d.ts.map +1 -0
- package/dist/cjs/tasks.js +51 -0
- package/dist/cjs/tasks.js.map +1 -0
- package/dist/cjs/types.d.ts +64 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +78 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/units.d.ts +22 -0
- package/dist/cjs/units.d.ts.map +1 -0
- package/dist/cjs/units.js +51 -0
- package/dist/cjs/units.js.map +1 -0
- package/dist/cjs/withdrawal.d.ts +72 -0
- package/dist/cjs/withdrawal.d.ts.map +1 -0
- package/dist/cjs/withdrawal.js +93 -0
- package/dist/cjs/withdrawal.js.map +1 -0
- package/dist/esm/account.d.ts +165 -0
- package/dist/esm/account.d.ts.map +1 -0
- package/dist/esm/account.js +505 -0
- package/dist/esm/account.js.map +1 -0
- package/dist/esm/address.d.ts +67 -0
- package/dist/esm/address.d.ts.map +1 -0
- package/dist/esm/address.js +125 -0
- package/dist/esm/address.js.map +1 -0
- package/dist/esm/authorization.d.ts +41 -0
- package/dist/esm/authorization.d.ts.map +1 -0
- package/dist/esm/authorization.js +126 -0
- package/dist/esm/authorization.js.map +1 -0
- package/dist/esm/bal.d.ts +129 -0
- package/dist/esm/bal.d.ts.map +1 -0
- package/dist/esm/bal.js +522 -0
- package/dist/esm/bal.js.map +1 -0
- package/dist/esm/binaryTree.d.ts +148 -0
- package/dist/esm/binaryTree.d.ts.map +1 -0
- package/dist/esm/binaryTree.js +226 -0
- package/dist/esm/binaryTree.js.map +1 -0
- package/dist/esm/blobs.d.ts +76 -0
- package/dist/esm/blobs.d.ts.map +1 -0
- package/dist/esm/blobs.js +163 -0
- package/dist/esm/blobs.js.map +1 -0
- package/dist/esm/bytes.d.ts +291 -0
- package/dist/esm/bytes.d.ts.map +1 -0
- package/dist/esm/bytes.js +562 -0
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/constants.d.ts +91 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +94 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/db.d.ts +65 -0
- package/dist/esm/db.d.ts.map +1 -0
- package/dist/esm/db.js +11 -0
- package/dist/esm/db.js.map +1 -0
- package/dist/esm/env.d.ts +9 -0
- package/dist/esm/env.d.ts.map +1 -0
- package/dist/esm/env.js +9 -0
- package/dist/esm/env.js.map +1 -0
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +14 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/helpers.d.ts +21 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +43 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.d.ts +67 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +67 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.d.ts +72 -0
- package/dist/esm/internal.d.ts.map +1 -0
- package/dist/esm/internal.js +170 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/kzg.d.ts +14 -0
- package/dist/esm/kzg.d.ts.map +1 -0
- package/dist/esm/kzg.js +2 -0
- package/dist/esm/kzg.js.map +1 -0
- package/dist/esm/lock.d.ts +15 -0
- package/dist/esm/lock.d.ts.map +1 -0
- package/dist/esm/lock.js +41 -0
- package/dist/esm/lock.js.map +1 -0
- package/dist/esm/mapDB.d.ts +17 -0
- package/dist/esm/mapDB.d.ts.map +1 -0
- package/dist/esm/mapDB.js +42 -0
- package/dist/esm/mapDB.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/provider.d.ts +46 -0
- package/dist/esm/provider.d.ts.map +1 -0
- package/dist/esm/provider.js +79 -0
- package/dist/esm/provider.js.map +1 -0
- package/dist/esm/request.d.ts +20 -0
- package/dist/esm/request.d.ts.map +1 -0
- package/dist/esm/request.js +30 -0
- package/dist/esm/request.js.map +1 -0
- package/dist/esm/signature.d.ts +47 -0
- package/dist/esm/signature.d.ts.map +1 -0
- package/dist/esm/signature.js +137 -0
- package/dist/esm/signature.js.map +1 -0
- package/dist/esm/tasks.d.ts +32 -0
- package/dist/esm/tasks.d.ts.map +1 -0
- package/dist/esm/tasks.js +47 -0
- package/dist/esm/tasks.js.map +1 -0
- package/dist/esm/types.d.ts +64 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +71 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/units.d.ts +22 -0
- package/dist/esm/units.d.ts.map +1 -0
- package/dist/esm/units.js +46 -0
- package/dist/esm/units.js.map +1 -0
- package/dist/esm/withdrawal.d.ts +72 -0
- package/dist/esm/withdrawal.d.ts.map +1 -0
- package/dist/esm/withdrawal.js +86 -0
- package/dist/esm/withdrawal.js.map +1 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +116 -0
- package/src/account.ts +630 -0
- package/src/address.ts +158 -0
- package/src/authorization.ts +180 -0
- package/src/bal.ts +761 -0
- package/src/binaryTree.ts +353 -0
- package/src/blobs.ts +209 -0
- package/src/bytes.ts +659 -0
- package/src/constants.ts +125 -0
- package/src/db.ts +86 -0
- package/src/env.ts +9 -0
- package/src/errors.ts +28 -0
- package/src/helpers.ts +46 -0
- package/src/index.ts +88 -0
- package/src/internal.ts +212 -0
- package/src/kzg.ts +24 -0
- package/src/lock.ts +42 -0
- package/src/mapDB.ts +57 -0
- package/src/provider.ts +109 -0
- package/src/request.ts +48 -0
- package/src/signature.ts +202 -0
- package/src/tasks.ts +59 -0
- package/src/types.ts +177 -0
- package/src/units.ts +56 -0
- package/src/withdrawal.ts +133 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2016 Nick Dodson. nickdodson.com
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE
|
|
23
|
+
*/
|
|
24
|
+
import { bytesToUnprefixedHex, utf8ToBytes } from "./bytes.js";
|
|
25
|
+
import { EthereumJSErrorWithoutCode } from "./errors.js";
|
|
26
|
+
/**
|
|
27
|
+
* Returns a boolean on whether or not the the input starts with '0x' and matches the optional length
|
|
28
|
+
* @param {string} value the string input value
|
|
29
|
+
* @param {number|undefined} length the optional length of the hex string in bytes
|
|
30
|
+
* @returns {boolean} Whether or not the string is a valid PrefixedHexString matching the optional length
|
|
31
|
+
*/
|
|
32
|
+
export function isHexString(value, length) {
|
|
33
|
+
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/))
|
|
34
|
+
return false;
|
|
35
|
+
if (typeof length !== 'undefined' && length > 0 && value.length !== 2 + 2 * length)
|
|
36
|
+
return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Removes '0x' from a given `String` if present
|
|
41
|
+
* @param str the string value
|
|
42
|
+
* @returns the string without 0x prefix
|
|
43
|
+
*/
|
|
44
|
+
export const stripHexPrefix = (str) => {
|
|
45
|
+
if (typeof str !== 'string')
|
|
46
|
+
throw EthereumJSErrorWithoutCode(`[stripHexPrefix] input must be type 'string', received ${typeof str}`);
|
|
47
|
+
return isHexString(str) ? str.slice(2) : str;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Pads a `String` to have an even length
|
|
51
|
+
* @param value
|
|
52
|
+
* @return output
|
|
53
|
+
*/
|
|
54
|
+
export function padToEven(value) {
|
|
55
|
+
let a = value;
|
|
56
|
+
if (typeof a !== 'string') {
|
|
57
|
+
throw EthereumJSErrorWithoutCode(`[padToEven] value must be type 'string', received ${typeof a}`);
|
|
58
|
+
}
|
|
59
|
+
if (a.length % 2)
|
|
60
|
+
a = `0${a}`;
|
|
61
|
+
return a;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the binary size of a string
|
|
65
|
+
* @param str
|
|
66
|
+
* @returns the number of bytes contained within the string
|
|
67
|
+
*/
|
|
68
|
+
export function getBinarySize(str) {
|
|
69
|
+
if (typeof str !== 'string') {
|
|
70
|
+
throw EthereumJSErrorWithoutCode(`[getBinarySize] method requires input type 'string', received ${typeof str}`);
|
|
71
|
+
}
|
|
72
|
+
return utf8ToBytes(str).byteLength;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns TRUE if the first specified array contains all elements
|
|
76
|
+
* from the second one. FALSE otherwise.
|
|
77
|
+
*
|
|
78
|
+
* @param superset
|
|
79
|
+
* @param subset
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
export function arrayContainsArray(superset, subset, some) {
|
|
83
|
+
if (Array.isArray(superset) !== true) {
|
|
84
|
+
throw EthereumJSErrorWithoutCode(`[arrayContainsArray] method requires input 'superset' to be an array, got type '${typeof superset}'`);
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(subset) !== true) {
|
|
87
|
+
throw EthereumJSErrorWithoutCode(`[arrayContainsArray] method requires input 'subset' to be an array, got type '${typeof subset}'`);
|
|
88
|
+
}
|
|
89
|
+
return subset[some === true ? 'some' : 'every']((value) => superset.indexOf(value) >= 0);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Should be called to get ascii from its hex representation
|
|
93
|
+
*
|
|
94
|
+
* @param string in hex
|
|
95
|
+
* @returns ascii string representation of hex value
|
|
96
|
+
*/
|
|
97
|
+
export function toAscii(hex) {
|
|
98
|
+
let str = '';
|
|
99
|
+
let i = 0;
|
|
100
|
+
const l = hex.length;
|
|
101
|
+
if (hex.substring(0, 2) === '0x')
|
|
102
|
+
i = 2;
|
|
103
|
+
for (; i < l; i += 2) {
|
|
104
|
+
const code = parseInt(hex.substr(i, 2), 16);
|
|
105
|
+
str += String.fromCharCode(code);
|
|
106
|
+
}
|
|
107
|
+
return str;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Should be called to get hex representation (prefixed by 0x) of utf8 string.
|
|
111
|
+
* Strips leading and trailing 0's.
|
|
112
|
+
*
|
|
113
|
+
* @param string
|
|
114
|
+
* @param optional padding
|
|
115
|
+
* @returns hex representation of input string
|
|
116
|
+
*/
|
|
117
|
+
export function fromUtf8(stringValue) {
|
|
118
|
+
const str = utf8ToBytes(stringValue);
|
|
119
|
+
// Using deprecated bytesToUnprefixedHex for performance: we're building a hex string with 0x prefix,
|
|
120
|
+
// so using bytesToUnprefixedHex avoids creating an intermediate prefixed string and then stripping it.
|
|
121
|
+
return `0x${padToEven(bytesToUnprefixedHex(str)).replace(/^0+|0+$/g, '')}`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Should be called to get hex representation (prefixed by 0x) of ascii string
|
|
125
|
+
*
|
|
126
|
+
* @param string
|
|
127
|
+
* @param optional padding
|
|
128
|
+
* @returns hex representation of input string
|
|
129
|
+
*/
|
|
130
|
+
export function fromAscii(stringValue) {
|
|
131
|
+
let hex = '';
|
|
132
|
+
for (let i = 0; i < stringValue.length; i++) {
|
|
133
|
+
const code = stringValue.charCodeAt(i);
|
|
134
|
+
const n = code.toString(16);
|
|
135
|
+
hex += n.length < 2 ? `0${n}` : n;
|
|
136
|
+
}
|
|
137
|
+
return `0x${hex}`;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the keys from an array of objects.
|
|
141
|
+
* @example
|
|
142
|
+
* ```js
|
|
143
|
+
* getKeys([{a: '1', b: '2'}, {a: '3', b: '4'}], 'a') => ['1', '3']
|
|
144
|
+
*````
|
|
145
|
+
* @param params
|
|
146
|
+
* @param key
|
|
147
|
+
* @param allowEmpty
|
|
148
|
+
* @returns output just a simple array of output keys
|
|
149
|
+
*/
|
|
150
|
+
export function getKeys(params, key, allowEmpty) {
|
|
151
|
+
if (!Array.isArray(params)) {
|
|
152
|
+
throw EthereumJSErrorWithoutCode(`[getKeys] method expects input 'params' to be an array, got ${typeof params}`);
|
|
153
|
+
}
|
|
154
|
+
if (typeof key !== 'string') {
|
|
155
|
+
throw EthereumJSErrorWithoutCode(`[getKeys] method expects input 'key' to be type 'string', got ${typeof params}`);
|
|
156
|
+
}
|
|
157
|
+
const result = [];
|
|
158
|
+
for (let i = 0; i < params.length; i++) {
|
|
159
|
+
let value = params[i][key];
|
|
160
|
+
if (allowEmpty === true && !value) {
|
|
161
|
+
value = '';
|
|
162
|
+
}
|
|
163
|
+
else if (typeof value !== 'string') {
|
|
164
|
+
throw EthereumJSErrorWithoutCode(`invalid abi - expected type 'string', received ${typeof value}`);
|
|
165
|
+
}
|
|
166
|
+
result.push(value);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,oBAAoB,EA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G,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAC1B,IAAI,UAAU,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAClC,KAAK,GAAG,EAAE,CAAA;QACZ,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,0BAA0B,CAC9B,kDAAkD,OAAO,KAAK,EAAE,CACjE,CAAA;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for an externally provided kzg library used when creating blob transactions
|
|
3
|
+
*/
|
|
4
|
+
export interface KZG {
|
|
5
|
+
blobToKzgCommitment(blob: string): string;
|
|
6
|
+
computeBlobProof(blob: string, commitment: string): string;
|
|
7
|
+
verifyProof(polynomialKZG: string, z: string, y: string, KZGProof: string): boolean;
|
|
8
|
+
verifyBlobProofBatch(blobs: string[], expectedKZGCommitments: string[], KZGProofs: string[]): boolean;
|
|
9
|
+
computeCells(blob: string): string[];
|
|
10
|
+
computeCellsAndProofs(blob: string): [string[], string[]];
|
|
11
|
+
recoverCellsAndProofs(indices: number[], cells: string[]): [string[], string[]];
|
|
12
|
+
verifyCellKzgProofBatch(commitments: string[], indices: number[], cells: string[], proofs: string[]): boolean;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=kzg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kzg.d.ts","sourceRoot":"","sources":["../../src/kzg.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,GAAG;IAElB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACzC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1D,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;IACnF,oBAAoB,CAClB,KAAK,EAAE,MAAM,EAAE,EACf,sBAAsB,EAAE,MAAM,EAAE,EAChC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAA;IAEV,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACpC,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IACzD,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IAC/E,uBAAuB,CACrB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EAAE,GACf,OAAO,CAAA;CACX"}
|
package/dist/esm/kzg.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kzg.js","sourceRoot":"","sources":["../../src/kzg.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class Lock {
|
|
2
|
+
private permits;
|
|
3
|
+
private promiseResolverQueue;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
6
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
7
|
+
*/
|
|
8
|
+
acquire(): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Increases the number of permits by one. If there are other functions waiting, one of them will
|
|
11
|
+
* continue to execute in a future iteration of the event loop.
|
|
12
|
+
*/
|
|
13
|
+
release(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../src/lock.ts"],"names":[],"mappings":"AACA,qBAAa,IAAI;IACf,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,oBAAoB,CAAkC;IAE9D;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAWxC;;;OAGG;IACI,OAAO,IAAI,IAAI;CAiBvB"}
|
package/dist/esm/lock.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Based on https://github.com/jsoendermann/semaphore-async-await/blob/master/src/Semaphore.ts
|
|
2
|
+
export class Lock {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.permits = 1;
|
|
5
|
+
this.promiseResolverQueue = [];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
9
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
10
|
+
*/
|
|
11
|
+
async acquire() {
|
|
12
|
+
if (this.permits > 0) {
|
|
13
|
+
this.permits -= 1;
|
|
14
|
+
return Promise.resolve(true);
|
|
15
|
+
}
|
|
16
|
+
// If there is no permit available, we return a promise that resolves once the semaphore gets
|
|
17
|
+
// signaled enough times that permits is equal to one.
|
|
18
|
+
return new Promise((resolver) => this.promiseResolverQueue.push(resolver));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Increases the number of permits by one. If there are other functions waiting, one of them will
|
|
22
|
+
* continue to execute in a future iteration of the event loop.
|
|
23
|
+
*/
|
|
24
|
+
release() {
|
|
25
|
+
this.permits += 1;
|
|
26
|
+
if (this.permits > 1 && this.promiseResolverQueue.length > 0) {
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.warn('Lock.permits should never be > 0 when there is someone waiting.');
|
|
29
|
+
}
|
|
30
|
+
else if (this.permits === 1 && this.promiseResolverQueue.length > 0) {
|
|
31
|
+
// If there is someone else waiting, immediately consume the permit that was released
|
|
32
|
+
// at the beginning of this function and let the waiting function resume.
|
|
33
|
+
this.permits -= 1;
|
|
34
|
+
const nextResolver = this.promiseResolverQueue.shift();
|
|
35
|
+
if (nextResolver) {
|
|
36
|
+
nextResolver(true);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/lock.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,OAAO,IAAI;IAAjB;QACU,YAAO,GAAW,CAAC,CAAA;QACnB,yBAAoB,GAAgC,EAAE,CAAA;IAsChE,CAAC;IApCC;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;YACjB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;QAED,6FAA6F;QAC7F,sDAAsD;QACtD,OAAO,IAAI,OAAO,CAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IACrF,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;QAEjB,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7D,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAA;QACjF,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtE,qFAAqF;YACrF,yEAAyE;YACzE,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;YAEjB,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAA;YACtD,IAAI,YAAY,EAAE,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,CAAA;YACpB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BatchDBOp, DB, DBObject } from './db.ts';
|
|
2
|
+
export declare class MapDB<TKey extends Uint8Array | string | number, TValue extends Uint8Array | string | DBObject> implements DB<TKey, TValue> {
|
|
3
|
+
_database: Map<TKey, TValue>;
|
|
4
|
+
constructor(database?: Map<TKey, TValue>);
|
|
5
|
+
get(key: TKey): Promise<TValue | undefined>;
|
|
6
|
+
put(key: TKey, val: TValue): Promise<void>;
|
|
7
|
+
del(key: TKey): Promise<void>;
|
|
8
|
+
batch(opStack: BatchDBOp<TKey, TValue>[]): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Note that the returned shallow copy will share the underlying database with the original
|
|
11
|
+
*
|
|
12
|
+
* @returns DB
|
|
13
|
+
*/
|
|
14
|
+
shallowCopy(): DB<TKey, TValue>;
|
|
15
|
+
open(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=mapDB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapDB.d.ts","sourceRoot":"","sources":["../../src/mapDB.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEtD,qBAAa,KAAK,CAChB,IAAI,SAAS,UAAU,GAAG,MAAM,GAAG,MAAM,EACzC,MAAM,SAAS,UAAU,GAAG,MAAM,GAAG,QAAQ,CAC7C,YAAW,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;IAE3B,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;gBAEhB,QAAQ,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC;IAIlC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAK3C,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7B,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9D;;;;OAIG;IACH,WAAW,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;IAI/B,IAAI;CAGL"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { bytesToUnprefixedHex } from "./bytes.js";
|
|
2
|
+
export class MapDB {
|
|
3
|
+
constructor(database) {
|
|
4
|
+
this._database = database ?? new Map();
|
|
5
|
+
}
|
|
6
|
+
async get(key) {
|
|
7
|
+
const dbKey = key instanceof Uint8Array ? bytesToUnprefixedHex(key) : key.toString();
|
|
8
|
+
return this._database.get(dbKey);
|
|
9
|
+
}
|
|
10
|
+
async put(key, val) {
|
|
11
|
+
// Using deprecated bytesToUnprefixedHex for performance: used as Map keys (string encoding).
|
|
12
|
+
const dbKey = key instanceof Uint8Array ? bytesToUnprefixedHex(key) : key.toString();
|
|
13
|
+
this._database.set(dbKey, val);
|
|
14
|
+
}
|
|
15
|
+
async del(key) {
|
|
16
|
+
// Using deprecated bytesToUnprefixedHex for performance: used as Map keys (string encoding).
|
|
17
|
+
const dbKey = key instanceof Uint8Array ? bytesToUnprefixedHex(key) : key.toString();
|
|
18
|
+
this._database.delete(dbKey);
|
|
19
|
+
}
|
|
20
|
+
async batch(opStack) {
|
|
21
|
+
for (const op of opStack) {
|
|
22
|
+
if (op.type === 'del') {
|
|
23
|
+
await this.del(op.key);
|
|
24
|
+
}
|
|
25
|
+
if (op.type === 'put') {
|
|
26
|
+
await this.put(op.key, op.value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Note that the returned shallow copy will share the underlying database with the original
|
|
32
|
+
*
|
|
33
|
+
* @returns DB
|
|
34
|
+
*/
|
|
35
|
+
shallowCopy() {
|
|
36
|
+
return new MapDB(this._database);
|
|
37
|
+
}
|
|
38
|
+
open() {
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mapDB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapDB.js","sourceRoot":"","sources":["../../src/mapDB.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAIjD,MAAM,OAAO,KAAK;IAOhB,YAAY,QAA4B;QACtC,IAAI,CAAC,SAAS,GAAG,QAAQ,IAAI,IAAI,GAAG,EAAgB,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAS;QACjB,MAAM,KAAK,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QACpF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAa,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAS,EAAE,GAAW;QAC9B,6FAA6F;QAC7F,MAAM,KAAK,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QACpF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAa,EAAE,GAAG,CAAC,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAS;QACjB,6FAA6F;QAC7F,MAAM,KAAK,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QACpF,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAa,CAAC,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAkC;QAC5C,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;YACzB,IAAI,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACtB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;YACxB,CAAC;YAED,IAAI,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACtB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,IAAI,KAAK,CAAe,IAAI,CAAC,SAAS,CAAC,CAAA;IAChD,CAAC;IAED,IAAI;QACF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
type rpcParams = {
|
|
2
|
+
method: string;
|
|
3
|
+
params: (string | string[] | boolean | number)[];
|
|
4
|
+
};
|
|
5
|
+
export type FetchFromProviderOptions = {
|
|
6
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Makes a simple RPC call to a remote Ethereum JSON-RPC provider and passes through the response.
|
|
11
|
+
* No parameter or response validation is done.
|
|
12
|
+
*
|
|
13
|
+
* @param url the URL for the JSON RPC provider
|
|
14
|
+
* @param params the parameters for the JSON-RPC method - refer to
|
|
15
|
+
* https://ethereum.org/en/developers/docs/apis/json-rpc/ for details on RPC methods
|
|
16
|
+
* @param options optional settings (e.g. timeout)
|
|
17
|
+
* @returns the `result` field from the JSON-RPC response
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const provider = 'https://mainnet.infura.io/v3/...'
|
|
21
|
+
* const params = {
|
|
22
|
+
* method: 'eth_getBlockByNumber',
|
|
23
|
+
* params: ['latest', false],
|
|
24
|
+
* }
|
|
25
|
+
* const block = await fetchFromProvider(provider, params)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const fetchFromProvider: (url: string, params: rpcParams, options?: FetchFromProviderOptions) => Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param provider a URL string or {@link EthersProvider}
|
|
32
|
+
* @returns the extracted URL string for the JSON-RPC Provider
|
|
33
|
+
*/
|
|
34
|
+
export declare const getProvider: (provider: string | EthersProvider) => string;
|
|
35
|
+
/**
|
|
36
|
+
* A partial interface for an `ethers` `JSONRPCProvider`
|
|
37
|
+
* We only use the url string since we do raw `fetch` calls to
|
|
38
|
+
* retrieve the necessary data
|
|
39
|
+
*/
|
|
40
|
+
export interface EthersProvider {
|
|
41
|
+
_getConnection: () => {
|
|
42
|
+
url: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAEA,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,MAAM,CAAC,EAAE,CAAA;CACjD,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,MAAM,EACX,QAAQ,SAAS,EACjB,UAAU,wBAAwB,iBAgDnC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,GAAG,cAAc,WAQ5D,CAAA;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM;QACpB,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { EthereumJSErrorWithoutCode } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Makes a simple RPC call to a remote Ethereum JSON-RPC provider and passes through the response.
|
|
4
|
+
* No parameter or response validation is done.
|
|
5
|
+
*
|
|
6
|
+
* @param url the URL for the JSON RPC provider
|
|
7
|
+
* @param params the parameters for the JSON-RPC method - refer to
|
|
8
|
+
* https://ethereum.org/en/developers/docs/apis/json-rpc/ for details on RPC methods
|
|
9
|
+
* @param options optional settings (e.g. timeout)
|
|
10
|
+
* @returns the `result` field from the JSON-RPC response
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const provider = 'https://mainnet.infura.io/v3/...'
|
|
14
|
+
* const params = {
|
|
15
|
+
* method: 'eth_getBlockByNumber',
|
|
16
|
+
* params: ['latest', false],
|
|
17
|
+
* }
|
|
18
|
+
* const block = await fetchFromProvider(provider, params)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const fetchFromProvider = async (url, params, options) => {
|
|
22
|
+
const timeout = options?.timeout ?? 60000;
|
|
23
|
+
const data = JSON.stringify({
|
|
24
|
+
method: params.method,
|
|
25
|
+
params: params.params,
|
|
26
|
+
jsonrpc: '2.0',
|
|
27
|
+
id: 1,
|
|
28
|
+
});
|
|
29
|
+
let signal;
|
|
30
|
+
let timer;
|
|
31
|
+
if (typeof AbortSignal.timeout === 'function') {
|
|
32
|
+
signal = AbortSignal.timeout(timeout);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
signal = controller.signal;
|
|
37
|
+
timer = setTimeout(() => controller.abort(), timeout);
|
|
38
|
+
}
|
|
39
|
+
const res = await fetch(url, {
|
|
40
|
+
headers: {
|
|
41
|
+
'content-type': 'application/json',
|
|
42
|
+
},
|
|
43
|
+
method: 'POST',
|
|
44
|
+
body: data,
|
|
45
|
+
signal,
|
|
46
|
+
}).finally(() => {
|
|
47
|
+
if (timer !== undefined)
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
throw EthereumJSErrorWithoutCode(`JSONRPCError: ${JSON.stringify({
|
|
52
|
+
method: params.method,
|
|
53
|
+
status: res.status,
|
|
54
|
+
message: await res.text().catch(() => {
|
|
55
|
+
return 'Could not parse error message likely because of a network error';
|
|
56
|
+
}),
|
|
57
|
+
}, null, 2)}`);
|
|
58
|
+
}
|
|
59
|
+
const json = await res.json();
|
|
60
|
+
// TODO we should check json.error here
|
|
61
|
+
return json.result;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param provider a URL string or {@link EthersProvider}
|
|
66
|
+
* @returns the extracted URL string for the JSON-RPC Provider
|
|
67
|
+
*/
|
|
68
|
+
export const getProvider = (provider) => {
|
|
69
|
+
if (typeof provider === 'string') {
|
|
70
|
+
return provider;
|
|
71
|
+
}
|
|
72
|
+
else if (typeof provider === 'object' && provider._getConnection !== undefined) {
|
|
73
|
+
return provider._getConnection().url;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw EthereumJSErrorWithoutCode('Must provide valid provider URL or Web3Provider');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 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C;QACZ,MAAM,0BAA0B,CAC9B,iBAAiB,IAAI,CAAC,SAAS,CAC7B;YACE,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;gBACnC,OAAO,iEAAiE,CAAA;YAC1E,CAAC,CAAC;SACH,EACD,IAAI,EACJ,CAAC,CACF,EAAE,CACJ,CAAA;IACH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAC7B,uCAAuC;IACvC,OAAO,IAAI,CAAC,MAAM,CAAA;AACpB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAiC,EAAE,EAAE;IAC/D,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAA;IACjB,CAAC;SAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACjF,OAAO,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,CAAA;IACtC,CAAC;SAAM,CAAC;QACN,MAAM,0BAA0B,CAAC,iDAAiD,CAAC,CAAA;IACrF,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PrefixedHexString } from './types.ts';
|
|
2
|
+
export type RequestBytes = Uint8Array;
|
|
3
|
+
export type CLRequestType = (typeof CLRequestType)[keyof typeof CLRequestType];
|
|
4
|
+
export declare const CLRequestType: {
|
|
5
|
+
readonly Deposit: 0;
|
|
6
|
+
readonly Withdrawal: 1;
|
|
7
|
+
readonly Consolidation: 2;
|
|
8
|
+
};
|
|
9
|
+
export interface RequestJSON {
|
|
10
|
+
type: PrefixedHexString;
|
|
11
|
+
data: PrefixedHexString;
|
|
12
|
+
}
|
|
13
|
+
export declare class CLRequest<T extends CLRequestType> {
|
|
14
|
+
readonly bytes: Uint8Array;
|
|
15
|
+
get type(): T;
|
|
16
|
+
get data(): Uint8Array<ArrayBufferLike>;
|
|
17
|
+
constructor(requestType: T, requestData: Uint8Array);
|
|
18
|
+
}
|
|
19
|
+
export declare function createCLRequest(bytes: Uint8Array): CLRequest<CLRequestType>;
|
|
20
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,MAAM,MAAM,YAAY,GAAG,UAAU,CAAA;AAErC,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAA;AAE9E,eAAO,MAAM,aAAa;;;;CAIhB,CAAA;AAEV,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,iBAAiB,CAAA;IACvB,IAAI,EAAE,iBAAiB,CAAA;CACxB;AAED,qBAAa,SAAS,CAAC,CAAC,SAAS,aAAa;IAE5C,SAAgB,KAAK,EAAE,UAAU,CAAA;IAEjC,IAAI,IAAI,IACkB,CAAC,CAC1B;IAED,IAAI,IAAI,gCAEP;gBAEW,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,UAAU;CAGpD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,aAAa,CAAC,CAW3E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { concatBytes } from "./bytes.js";
|
|
2
|
+
export const CLRequestType = {
|
|
3
|
+
Deposit: 0,
|
|
4
|
+
Withdrawal: 1,
|
|
5
|
+
Consolidation: 2,
|
|
6
|
+
};
|
|
7
|
+
export class CLRequest {
|
|
8
|
+
get type() {
|
|
9
|
+
return this.bytes[0];
|
|
10
|
+
}
|
|
11
|
+
get data() {
|
|
12
|
+
return this.bytes.subarray(1);
|
|
13
|
+
}
|
|
14
|
+
constructor(requestType, requestData) {
|
|
15
|
+
this.bytes = concatBytes(new Uint8Array([requestType]), requestData);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function createCLRequest(bytes) {
|
|
19
|
+
switch (bytes[0]) {
|
|
20
|
+
case CLRequestType.Deposit:
|
|
21
|
+
return new CLRequest(CLRequestType.Deposit, bytes.subarray(1));
|
|
22
|
+
case CLRequestType.Withdrawal:
|
|
23
|
+
return new CLRequest(CLRequestType.Withdrawal, bytes.subarray(1));
|
|
24
|
+
case CLRequestType.Consolidation:
|
|
25
|
+
return new CLRequest(CLRequestType.Consolidation, bytes.subarray(1));
|
|
26
|
+
default:
|
|
27
|
+
throw Error(`Invalid request type=${bytes[0]}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAQxC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,CAAC;CACR,CAAA;AAOV,MAAM,OAAO,SAAS;IAIpB,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAM,CAAA;IAC3B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC/B,CAAC;IAED,YAAY,WAAc,EAAE,WAAuB;QACjD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;IACtE,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,KAAK,aAAa,CAAC,OAAO;YACxB,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QAChE,KAAK,aAAa,CAAC,UAAU;YAC3B,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QACnE,KAAK,aAAa,CAAC,aAAa;YAC9B,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QACtE;YACE,MAAM,KAAK,CAAC,wBAAwB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACnD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PrefixedHexString } from './types.ts';
|
|
2
|
+
export declare function calculateSigRecovery(v: bigint, chainId?: bigint): bigint;
|
|
3
|
+
/**
|
|
4
|
+
* ECDSA public key recovery from signature.
|
|
5
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
6
|
+
* @returns Recovered public key
|
|
7
|
+
*/
|
|
8
|
+
export declare const ecrecover: (msgHash: Uint8Array, v: bigint, r: Uint8Array, s: Uint8Array, chainId?: bigint) => Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Convert signature parameters into the format of `eth_sign` RPC method.
|
|
11
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
12
|
+
* @returns Signature
|
|
13
|
+
*/
|
|
14
|
+
export declare const toRPCSig: (v: bigint, r: Uint8Array, s: Uint8Array, chainId?: bigint) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
|
|
17
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
18
|
+
* @returns Signature
|
|
19
|
+
*/
|
|
20
|
+
export declare const toCompactSig: (v: bigint, r: Uint8Array, s: Uint8Array, chainId?: bigint) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Convert signature format of the `eth_sign` RPC method to signature parameters
|
|
23
|
+
*
|
|
24
|
+
* NOTE: For an extracted `v` value < 27 (see Geth bug https://github.com/ethereum/go-ethereum/issues/2053)
|
|
25
|
+
* `v + 27` is returned for the `v` value
|
|
26
|
+
* NOTE: After EIP1559, `v` could be `0` or `1` but this function assumes
|
|
27
|
+
* it's a signed message (EIP-191 or EIP-712) adding `27` at the end. Remove if needed.
|
|
28
|
+
*/
|
|
29
|
+
export declare const fromRPCSig: (sig: PrefixedHexString) => {
|
|
30
|
+
v: bigint;
|
|
31
|
+
r: Uint8Array;
|
|
32
|
+
s: Uint8Array;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Validate a ECDSA signature.
|
|
36
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
37
|
+
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
|
|
38
|
+
*/
|
|
39
|
+
export declare const isValidSignature: (v: bigint, r: Uint8Array, s: Uint8Array, homesteadOrLater?: boolean, chainId?: bigint) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
|
|
42
|
+
* The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
|
|
43
|
+
* call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
|
|
44
|
+
* used to produce the signature.
|
|
45
|
+
*/
|
|
46
|
+
export declare const hashPersonalMessage: (message: Uint8Array) => Uint8Array;
|
|
47
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAOxE;AAMD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,UAAU,EACnB,GAAG,MAAM,EACT,GAAG,UAAU,EACb,GAAG,UAAU,EACb,UAAU,MAAM,KACf,UAUF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GACnB,GAAG,MAAM,EACT,GAAG,UAAU,EACb,GAAG,UAAU,EACb,UAAU,MAAM,KACf,MASF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,GAAG,MAAM,EACT,GAAG,UAAU,EACb,GAAG,UAAU,EACb,UAAU,MAAM,KACf,MAYF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GAAa,KAAK,iBAAiB,KAAG;IAC3D,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,UAAU,CAAA;IACb,CAAC,EAAE,UAAU,CAAA;CAgCd,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,GAAG,MAAM,EACT,GAAG,UAAU,EACb,GAAG,UAAU,EACb,mBAAkB,OAAc,EAChC,UAAU,MAAM,KACf,OA0BF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAa,SAAS,UAAU,KAAG,UAIlE,CAAA"}
|