@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,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"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashPersonalMessage = exports.isValidSignature = exports.fromRPCSig = exports.toCompactSig = exports.toRPCSig = exports.ecrecover = void 0;
|
|
4
|
+
exports.calculateSigRecovery = calculateSigRecovery;
|
|
5
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
6
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
7
|
+
const bytes_ts_1 = require("./bytes.js");
|
|
8
|
+
const constants_ts_1 = require("./constants.js");
|
|
9
|
+
const errors_ts_1 = require("./errors.js");
|
|
10
|
+
const helpers_ts_1 = require("./helpers.js");
|
|
11
|
+
function calculateSigRecovery(v, chainId) {
|
|
12
|
+
if (v === constants_ts_1.BIGINT_0 || v === constants_ts_1.BIGINT_1)
|
|
13
|
+
return v;
|
|
14
|
+
if (chainId === undefined) {
|
|
15
|
+
return v - constants_ts_1.BIGINT_27;
|
|
16
|
+
}
|
|
17
|
+
return v - (chainId * constants_ts_1.BIGINT_2 + BigInt(35));
|
|
18
|
+
}
|
|
19
|
+
function isValidSigRecovery(recovery) {
|
|
20
|
+
return recovery === constants_ts_1.BIGINT_0 || recovery === constants_ts_1.BIGINT_1;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ECDSA public key recovery from signature.
|
|
24
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
25
|
+
* @returns Recovered public key
|
|
26
|
+
*/
|
|
27
|
+
const ecrecover = function (msgHash, v, r, s, chainId) {
|
|
28
|
+
const signature = (0, bytes_ts_1.concatBytes)((0, bytes_ts_1.setLengthLeft)(r, 32), (0, bytes_ts_1.setLengthLeft)(s, 32));
|
|
29
|
+
const recovery = calculateSigRecovery(v, chainId);
|
|
30
|
+
if (!isValidSigRecovery(recovery)) {
|
|
31
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid signature v value');
|
|
32
|
+
}
|
|
33
|
+
const sig = secp256k1_js_1.secp256k1.Signature.fromBytes(signature).addRecoveryBit(Number(recovery));
|
|
34
|
+
const senderPubKey = sig.recoverPublicKey(msgHash);
|
|
35
|
+
return senderPubKey.toBytes(false).slice(1);
|
|
36
|
+
};
|
|
37
|
+
exports.ecrecover = ecrecover;
|
|
38
|
+
/**
|
|
39
|
+
* Convert signature parameters into the format of `eth_sign` RPC method.
|
|
40
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
41
|
+
* @returns Signature
|
|
42
|
+
*/
|
|
43
|
+
const toRPCSig = function (v, r, s, chainId) {
|
|
44
|
+
const recovery = calculateSigRecovery(v, chainId);
|
|
45
|
+
if (!isValidSigRecovery(recovery)) {
|
|
46
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid signature v value');
|
|
47
|
+
}
|
|
48
|
+
// geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin
|
|
49
|
+
return (0, bytes_ts_1.bytesToHex)((0, bytes_ts_1.concatBytes)((0, bytes_ts_1.setLengthLeft)(r, 32), (0, bytes_ts_1.setLengthLeft)(s, 32), (0, bytes_ts_1.bigIntToBytes)(v)));
|
|
50
|
+
};
|
|
51
|
+
exports.toRPCSig = toRPCSig;
|
|
52
|
+
/**
|
|
53
|
+
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
|
|
54
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
55
|
+
* @returns Signature
|
|
56
|
+
*/
|
|
57
|
+
const toCompactSig = function (v, r, s, chainId) {
|
|
58
|
+
const recovery = calculateSigRecovery(v, chainId);
|
|
59
|
+
if (!isValidSigRecovery(recovery)) {
|
|
60
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid signature v value');
|
|
61
|
+
}
|
|
62
|
+
const ss = Uint8Array.from([...s]);
|
|
63
|
+
if ((v > BigInt(28) && v % constants_ts_1.BIGINT_2 === constants_ts_1.BIGINT_1) || v === constants_ts_1.BIGINT_1 || v === BigInt(28)) {
|
|
64
|
+
ss[0] |= 0x80;
|
|
65
|
+
}
|
|
66
|
+
return (0, bytes_ts_1.bytesToHex)((0, bytes_ts_1.concatBytes)((0, bytes_ts_1.setLengthLeft)(r, 32), (0, bytes_ts_1.setLengthLeft)(ss, 32)));
|
|
67
|
+
};
|
|
68
|
+
exports.toCompactSig = toCompactSig;
|
|
69
|
+
/**
|
|
70
|
+
* Convert signature format of the `eth_sign` RPC method to signature parameters
|
|
71
|
+
*
|
|
72
|
+
* NOTE: For an extracted `v` value < 27 (see Geth bug https://github.com/ethereum/go-ethereum/issues/2053)
|
|
73
|
+
* `v + 27` is returned for the `v` value
|
|
74
|
+
* NOTE: After EIP1559, `v` could be `0` or `1` but this function assumes
|
|
75
|
+
* it's a signed message (EIP-191 or EIP-712) adding `27` at the end. Remove if needed.
|
|
76
|
+
*/
|
|
77
|
+
const fromRPCSig = function (sig) {
|
|
78
|
+
const bytes = (0, bytes_ts_1.hexToBytes)(sig);
|
|
79
|
+
let r;
|
|
80
|
+
let s;
|
|
81
|
+
let v;
|
|
82
|
+
if (bytes.length >= 65) {
|
|
83
|
+
r = bytes.subarray(0, 32);
|
|
84
|
+
s = bytes.subarray(32, 64);
|
|
85
|
+
v = (0, bytes_ts_1.bytesToBigInt)(bytes.subarray(64));
|
|
86
|
+
}
|
|
87
|
+
else if (bytes.length === 64) {
|
|
88
|
+
// Compact Signature Representation (https://eips.ethereum.org/EIPS/eip-2098)
|
|
89
|
+
r = bytes.subarray(0, 32);
|
|
90
|
+
s = bytes.subarray(32, 64);
|
|
91
|
+
v = BigInt((0, bytes_ts_1.bytesToInt)(bytes.subarray(32, 33)) >> 7);
|
|
92
|
+
s[0] &= 0x7f;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid signature length');
|
|
96
|
+
}
|
|
97
|
+
// support both versions of `eth_sign` responses
|
|
98
|
+
if (v < 27) {
|
|
99
|
+
// TODO: verify this behavior, and verify in which context this method (`fromRPCSig`) is used
|
|
100
|
+
v = v + constants_ts_1.BIGINT_27;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
v,
|
|
104
|
+
r,
|
|
105
|
+
s,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
exports.fromRPCSig = fromRPCSig;
|
|
109
|
+
/**
|
|
110
|
+
* Validate a ECDSA signature.
|
|
111
|
+
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions
|
|
112
|
+
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
|
|
113
|
+
*/
|
|
114
|
+
const isValidSignature = function (v, r, s, homesteadOrLater = true, chainId) {
|
|
115
|
+
if (r.length !== 32 || s.length !== 32) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (!isValidSigRecovery(calculateSigRecovery(v, chainId))) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const rBigInt = (0, bytes_ts_1.bytesToBigInt)(r);
|
|
122
|
+
const sBigInt = (0, bytes_ts_1.bytesToBigInt)(s);
|
|
123
|
+
if (rBigInt === constants_ts_1.BIGINT_0 ||
|
|
124
|
+
rBigInt >= constants_ts_1.SECP256K1_ORDER ||
|
|
125
|
+
sBigInt === constants_ts_1.BIGINT_0 ||
|
|
126
|
+
sBigInt >= constants_ts_1.SECP256K1_ORDER) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (homesteadOrLater && sBigInt >= constants_ts_1.SECP256K1_ORDER_DIV_2) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
exports.isValidSignature = isValidSignature;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
|
|
137
|
+
* The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
|
|
138
|
+
* call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
|
|
139
|
+
* used to produce the signature.
|
|
140
|
+
*/
|
|
141
|
+
const hashPersonalMessage = function (message) {
|
|
142
|
+
(0, helpers_ts_1.assertIsBytes)(message);
|
|
143
|
+
const prefix = (0, bytes_ts_1.utf8ToBytes)(`\u0019Ethereum Signed Message:\n${message.length}`);
|
|
144
|
+
return (0, sha3_js_1.keccak_256)((0, bytes_ts_1.concatBytes)(prefix, message));
|
|
145
|
+
};
|
|
146
|
+
exports.hashPersonalMessage = hashPersonalMessage;
|
|
147
|
+
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":";;;AA0BA,oDAOC;AAjCD,6DAAsD;AACtD,mDAAkD;AAElD,yCASmB;AACnB,iDAOuB;AACvB,2CAAwD;AACxD,6CAA4C;AAI5C,SAAgB,oBAAoB,CAAC,CAAS,EAAE,OAAgB;IAC9D,IAAI,CAAC,KAAK,uBAAQ,IAAI,CAAC,KAAK,uBAAQ;QAAE,OAAO,CAAC,CAAA;IAE9C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,wBAAS,CAAA;IACtB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,uBAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,OAAO,QAAQ,KAAK,uBAAQ,IAAI,QAAQ,KAAK,uBAAQ,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACI,MAAM,SAAS,GAAG,UACvB,OAAmB,EACnB,CAAS,EACT,CAAa,EACb,CAAa,EACb,OAAg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;IAEhC,IACE,OAAO,KAAK,uBAAQ;QACpB,OAAO,IAAI,8BAAe;QAC1B,OAAO,KAAK,uBAAQ;QACpB,OAAO,IAAI,8BAAe,EAC1B,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,gBAAgB,IAAI,OAAO,IAAI,oCAAqB,EAAE,CAAC;QACzD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAhCY,QAAA,gBAAgB,oBAgC5B;AAED;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,UAAU,OAAmB;IAC9D,IAAA,0BAAa,EAAC,OAAO,CAAC,CAAA;IACtB,MAAM,MAAM,GAAG,IAAA,sBAAW,EAAC,mCAAmC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/E,OAAO,IAAA,oBAAU,EAAC,IAAA,sBAAW,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AACjD,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class PrioritizedTaskExecutor {
|
|
2
|
+
/** The maximum size of the pool */
|
|
3
|
+
private maxPoolSize;
|
|
4
|
+
/** The current size of the pool */
|
|
5
|
+
private currentPoolSize;
|
|
6
|
+
/** The task queue */
|
|
7
|
+
private queue;
|
|
8
|
+
/**
|
|
9
|
+
* Executes tasks up to maxPoolSize at a time, other items are put in a priority queue.
|
|
10
|
+
* @class PrioritizedTaskExecutor
|
|
11
|
+
* @private
|
|
12
|
+
* @param maxPoolSize The maximum size of the pool
|
|
13
|
+
*/
|
|
14
|
+
constructor(maxPoolSize: number);
|
|
15
|
+
/**
|
|
16
|
+
* Executes the task or queues it if no spots are available.
|
|
17
|
+
* When a task is added, check if there are spots left in the pool.
|
|
18
|
+
* If a spot is available, claim that spot and give back the spot once the asynchronous task has been resolved.
|
|
19
|
+
* When no spots are available, add the task to the task queue. The task will be executed at some point when another task has been resolved.
|
|
20
|
+
* @private
|
|
21
|
+
* @param priority The priority of the task
|
|
22
|
+
* @param fn The function that accepts the callback, which must be called upon the task completion.
|
|
23
|
+
*/
|
|
24
|
+
executeOrQueue(priority: number, fn: Function): void;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the taskExecutor is finished.
|
|
27
|
+
* @private
|
|
28
|
+
* @returns Returns `true` if the taskExecutor is finished, otherwise returns `false`.
|
|
29
|
+
*/
|
|
30
|
+
finished(): boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/tasks.ts"],"names":[],"mappings":"AAKA,qBAAa,uBAAuB;IAClC,mCAAmC;IACnC,OAAO,CAAC,WAAW,CAAQ;IAC3B,mCAAmC;IACnC,OAAO,CAAC,eAAe,CAAQ;IAC/B,qBAAqB;IACrB,OAAO,CAAC,KAAK,CAAQ;IAErB;;;;;OAKG;gBACS,WAAW,EAAE,MAAM;IAM/B;;;;;;;;OAQG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ;IAgB7C;;;;OAIG;IACH,QAAQ,IAAI,OAAO;CAGpB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrioritizedTaskExecutor = void 0;
|
|
4
|
+
class PrioritizedTaskExecutor {
|
|
5
|
+
/**
|
|
6
|
+
* Executes tasks up to maxPoolSize at a time, other items are put in a priority queue.
|
|
7
|
+
* @class PrioritizedTaskExecutor
|
|
8
|
+
* @private
|
|
9
|
+
* @param maxPoolSize The maximum size of the pool
|
|
10
|
+
*/
|
|
11
|
+
constructor(maxPoolSize) {
|
|
12
|
+
this.maxPoolSize = maxPoolSize;
|
|
13
|
+
this.currentPoolSize = 0;
|
|
14
|
+
this.queue = [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Executes the task or queues it if no spots are available.
|
|
18
|
+
* When a task is added, check if there are spots left in the pool.
|
|
19
|
+
* If a spot is available, claim that spot and give back the spot once the asynchronous task has been resolved.
|
|
20
|
+
* When no spots are available, add the task to the task queue. The task will be executed at some point when another task has been resolved.
|
|
21
|
+
* @private
|
|
22
|
+
* @param priority The priority of the task
|
|
23
|
+
* @param fn The function that accepts the callback, which must be called upon the task completion.
|
|
24
|
+
*/
|
|
25
|
+
executeOrQueue(priority, fn) {
|
|
26
|
+
if (this.currentPoolSize < this.maxPoolSize) {
|
|
27
|
+
this.currentPoolSize++;
|
|
28
|
+
fn(() => {
|
|
29
|
+
this.currentPoolSize--;
|
|
30
|
+
if (this.queue.length > 0) {
|
|
31
|
+
this.queue.sort((a, b) => b.priority - a.priority);
|
|
32
|
+
const item = this.queue.shift();
|
|
33
|
+
this.executeOrQueue(item.priority, item.fn);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.queue.push({ priority, fn });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the taskExecutor is finished.
|
|
43
|
+
* @private
|
|
44
|
+
* @returns Returns `true` if the taskExecutor is finished, otherwise returns `false`.
|
|
45
|
+
*/
|
|
46
|
+
finished() {
|
|
47
|
+
return this.currentPoolSize === 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PrioritizedTaskExecutor = PrioritizedTaskExecutor;
|
|
51
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/tasks.ts"],"names":[],"mappings":";;;AAKA,MAAa,uBAAuB;IAQlC;;;;;OAKG;IACH,YAAY,WAAmB;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,eAAe,GAAG,CAAC,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACjB,CAAC;IAED;;;;;;;;OAQG;IACH,cAAc,CAAC,QAAgB,EAAE,EAAY;QAC3C,IAAI,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,CAAC,eAAe,EAAE,CAAA;YACtB,EAAE,CAAC,GAAG,EAAE;gBACN,IAAI,CAAC,eAAe,EAAE,CAAA;gBACtB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA;oBAClD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;oBAC/B,IAAI,CAAC,cAAc,CAAC,IAAK,CAAC,QAAQ,EAAE,IAAK,CAAC,EAAE,CAAC,CAAA;gBAC/C,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,eAAe,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AArDD,0DAqDC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Address } from './address.ts';
|
|
2
|
+
import type { ToBytesInputTypes } from './bytes.ts';
|
|
3
|
+
export type BigIntLike = bigint | PrefixedHexString | number | Uint8Array;
|
|
4
|
+
export type BytesLike = Uint8Array | number[] | number | bigint | TransformableToBytes | PrefixedHexString;
|
|
5
|
+
export type NumericString = `${number}`;
|
|
6
|
+
export type PrefixedHexString = `0x${string}`;
|
|
7
|
+
/**
|
|
8
|
+
* A type that represents an input that can be converted to an Address.
|
|
9
|
+
*/
|
|
10
|
+
export type AddressLike = Address | Uint8Array | PrefixedHexString;
|
|
11
|
+
export interface TransformableToBytes {
|
|
12
|
+
toBytes?(): Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export type NestedUint8Array = Array<Uint8Array | NestedUint8Array>;
|
|
15
|
+
export declare function isNestedUint8Array(value: unknown): value is NestedUint8Array;
|
|
16
|
+
export type TypeOutput = (typeof TypeOutput)[keyof typeof TypeOutput];
|
|
17
|
+
export declare const TypeOutput: {
|
|
18
|
+
readonly Number: 0;
|
|
19
|
+
readonly BigInt: 1;
|
|
20
|
+
readonly Uint8Array: 2;
|
|
21
|
+
readonly PrefixedHexString: 3;
|
|
22
|
+
};
|
|
23
|
+
export type TypeOutputReturnType = {
|
|
24
|
+
[TypeOutput.Number]: number;
|
|
25
|
+
[TypeOutput.BigInt]: bigint;
|
|
26
|
+
[TypeOutput.Uint8Array]: Uint8Array;
|
|
27
|
+
[TypeOutput.PrefixedHexString]: PrefixedHexString;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Convert an input to a specified type.
|
|
31
|
+
* Input of null/undefined returns null/undefined regardless of the output type.
|
|
32
|
+
* @param input value to convert
|
|
33
|
+
* @param outputType type to output
|
|
34
|
+
*/
|
|
35
|
+
export declare function toType<T extends TypeOutput>(input: null, outputType: T): null;
|
|
36
|
+
export declare function toType<T extends TypeOutput>(input: undefined, outputType: T): undefined;
|
|
37
|
+
export declare function toType<T extends TypeOutput>(input: ToBytesInputTypes, outputType: T): TypeOutputReturnType[T];
|
|
38
|
+
/**
|
|
39
|
+
* EIP-7702 Authorization list types
|
|
40
|
+
*/
|
|
41
|
+
export type EOACode7702AuthorizationListItemUnsigned = {
|
|
42
|
+
chainId: PrefixedHexString;
|
|
43
|
+
address: PrefixedHexString;
|
|
44
|
+
nonce: PrefixedHexString;
|
|
45
|
+
};
|
|
46
|
+
export type EOACode7702AuthorizationListItem = {
|
|
47
|
+
yParity: PrefixedHexString;
|
|
48
|
+
r: PrefixedHexString;
|
|
49
|
+
s: PrefixedHexString;
|
|
50
|
+
} & EOACode7702AuthorizationListItemUnsigned;
|
|
51
|
+
export type EOACode7702AuthorizationListBytesItem = [
|
|
52
|
+
Uint8Array,
|
|
53
|
+
Uint8Array,
|
|
54
|
+
Uint8Array,
|
|
55
|
+
Uint8Array,
|
|
56
|
+
Uint8Array,
|
|
57
|
+
Uint8Array
|
|
58
|
+
];
|
|
59
|
+
export type EOACode7702AuthorizationListBytes = EOACode7702AuthorizationListBytesItem[];
|
|
60
|
+
export type EOACode7702AuthorizationList = EOACode7702AuthorizationListItem[];
|
|
61
|
+
export type EOACode7702AuthorizationListBytesItemUnsigned = [Uint8Array, Uint8Array, Uint8Array];
|
|
62
|
+
export declare function isEOACode7702AuthorizationListBytes(input: EOACode7702AuthorizationListBytes | EOACode7702AuthorizationList): input is EOACode7702AuthorizationListBytes;
|
|
63
|
+
export declare function isEOACode7702AuthorizationList(input: EOACode7702AuthorizationListBytes | EOACode7702AuthorizationList): input is EOACode7702AuthorizationList;
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAKnD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,iBAAiB,GAAG,MAAM,GAAG,UAAU,CAAA;AAKzE,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,MAAM,EAAE,GACR,MAAM,GACN,MAAM,GACN,oBAAoB,GACpB,iBAAiB,CAAA;AAKrB,MAAM,MAAM,aAAa,GAAG,GAAG,MAAM,EAAE,CAAA;AAKvC,MAAM,MAAM,iBAAiB,GAAG,KAAK,MAAM,EAA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CACzB,CAAA;AAED,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,iBAAiB,CAAA;IAC1B,CAAC,EAAE,iBAAiB,CAAA;IACpB,CAAC,EAAE,iBAAiB,CAAA;CACrB,GAAG,wCAAwC,CAAA;AAG5C,MAAM,MAAM,qCAAqC,GAAG;IAClD,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;CACX,CAAA;AACD,MAAM,MAAM,iCAAiC,GAAG,qCAAqC,EAAE,CAAA;AACvF,MAAM,MAAM,4BAA4B,GAAG,gCAAgC,EAAE,CAAA;AAE7E,MAAM,MAAM,6CAA6C,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;AAEhG,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,iCAAiC,GAAG,4BAA4B,GACtE,KAAK,IAAI,iCAAiC,CAS5C;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,iCAAiC,GAAG,4BAA4B,GACtE,KAAK,IAAI,4BAA4B,CAEvC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOutput = void 0;
|
|
4
|
+
exports.isNestedUint8Array = isNestedUint8Array;
|
|
5
|
+
exports.toType = toType;
|
|
6
|
+
exports.isEOACode7702AuthorizationListBytes = isEOACode7702AuthorizationListBytes;
|
|
7
|
+
exports.isEOACode7702AuthorizationList = isEOACode7702AuthorizationList;
|
|
8
|
+
const bytes_ts_1 = require("./bytes.js");
|
|
9
|
+
const errors_ts_1 = require("./errors.js");
|
|
10
|
+
const internal_ts_1 = require("./internal.js");
|
|
11
|
+
function isNestedUint8Array(value) {
|
|
12
|
+
if (!Array.isArray(value)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
for (const item of value) {
|
|
16
|
+
if (Array.isArray(item)) {
|
|
17
|
+
if (!isNestedUint8Array(item)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (!(item instanceof Uint8Array)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
exports.TypeOutput = {
|
|
28
|
+
Number: 0,
|
|
29
|
+
BigInt: 1,
|
|
30
|
+
Uint8Array: 2,
|
|
31
|
+
PrefixedHexString: 3,
|
|
32
|
+
};
|
|
33
|
+
function toType(input, outputType) {
|
|
34
|
+
if (input === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (input === undefined) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (typeof input === 'string' && !(0, internal_ts_1.isHexString)(input)) {
|
|
41
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)(`A string must be provided with a 0x-prefix, given: ${input}`);
|
|
42
|
+
}
|
|
43
|
+
else if (typeof input === 'number' && !Number.isSafeInteger(input)) {
|
|
44
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('The provided number is greater than MAX_SAFE_INTEGER (please use an alternative input type)');
|
|
45
|
+
}
|
|
46
|
+
const output = (0, bytes_ts_1.toBytes)(input);
|
|
47
|
+
switch (outputType) {
|
|
48
|
+
case exports.TypeOutput.Uint8Array:
|
|
49
|
+
return output;
|
|
50
|
+
case exports.TypeOutput.BigInt:
|
|
51
|
+
return (0, bytes_ts_1.bytesToBigInt)(output);
|
|
52
|
+
case exports.TypeOutput.Number: {
|
|
53
|
+
const bigInt = (0, bytes_ts_1.bytesToBigInt)(output);
|
|
54
|
+
if (bigInt > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
55
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('The provided number is greater than MAX_SAFE_INTEGER (please use an alternative output type)');
|
|
56
|
+
}
|
|
57
|
+
return Number(bigInt);
|
|
58
|
+
}
|
|
59
|
+
case exports.TypeOutput.PrefixedHexString:
|
|
60
|
+
return (0, bytes_ts_1.bytesToHex)(output);
|
|
61
|
+
default:
|
|
62
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('unknown outputType');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function isEOACode7702AuthorizationListBytes(input) {
|
|
66
|
+
if (input.length === 0) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const firstItem = input[0];
|
|
70
|
+
if (Array.isArray(firstItem)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function isEOACode7702AuthorizationList(input) {
|
|
76
|
+
return !isEOACode7702AuthorizationListBytes(input); // This is exactly the same method, except the output is negated.
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA4CA,gDAcC;AA8BD,wBAwCC;AA+BD,kFAWC;AAED,wEAIC;AAhLD,yCAA+D;AAC/D,2CAAwD;AACxD,+CAA2C;AA0C3C,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,YAAY,UAAU,CAAC,EAAE,CAAC;YACzC,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAIY,QAAA,UAAU,GAAG;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BAAU,EAAC,MAAM,CAA4B,CAAA;QACtD;YACE,MAAM,IAAA,sCAA0B,EAAC,oBAAoB,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC;AA+BD,SAAgB,mCAAmC,CACjD,KAAuE;IAEvE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAgB,8BAA8B,CAC5C,KAAuE;IAEvE,OAAO,CAAC,mCAAmC,CAAC,KAAK,CAAC,CAAA,CAAC,iEAAiE;AACtH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Conversion constants to wei */
|
|
2
|
+
export declare const GWEI_TO_WEI: bigint;
|
|
3
|
+
export declare const ETHER_TO_WEI: bigint;
|
|
4
|
+
export declare function formatBigDecimal(numerator: bigint, denominator: bigint, maxDecimalFactor: bigint): string;
|
|
5
|
+
export declare class Units {
|
|
6
|
+
static validateInput(amount: number | bigint): void;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a number or bigint input of ether to wei
|
|
9
|
+
*
|
|
10
|
+
* @param {number | bigint} amount amount of units of ether to convert to wei
|
|
11
|
+
* @returns {bigint} amount of units in wei
|
|
12
|
+
*/
|
|
13
|
+
static ether(amount: number | bigint): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a number or bigint input of gwei to wei
|
|
16
|
+
*
|
|
17
|
+
* @param amount amount of units of gwei to convert to wei
|
|
18
|
+
* @returns {bigint} amount of units in wei
|
|
19
|
+
*/
|
|
20
|
+
static gwei(amount: number | bigint): bigint;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAGA,kCAAkC;AAClC,eAAO,MAAM,WAAW,QAAkB,CAAA;AAC1C,eAAO,MAAM,YAAY,QAAmB,CAAA;AAE5C,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAWR;AAED,qBAAa,KAAK;IAChB,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IASnD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAK7C;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;CAI7C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Units = exports.ETHER_TO_WEI = exports.GWEI_TO_WEI = void 0;
|
|
4
|
+
exports.formatBigDecimal = formatBigDecimal;
|
|
5
|
+
const constants_ts_1 = require("./constants.js");
|
|
6
|
+
const errors_ts_1 = require("./errors.js");
|
|
7
|
+
/** Conversion constants to wei */
|
|
8
|
+
exports.GWEI_TO_WEI = BigInt(10 ** 9); // Multiplier to convert from Gwei to Wei
|
|
9
|
+
exports.ETHER_TO_WEI = BigInt(10 ** 18); // Multiplier to convert from Ether to Wei
|
|
10
|
+
function formatBigDecimal(numerator, denominator, maxDecimalFactor) {
|
|
11
|
+
if (denominator === constants_ts_1.BIGINT_0) {
|
|
12
|
+
denominator = constants_ts_1.BIGINT_1;
|
|
13
|
+
}
|
|
14
|
+
const full = numerator / denominator;
|
|
15
|
+
const fraction = ((numerator - full * denominator) * maxDecimalFactor) / denominator;
|
|
16
|
+
// zeros to be added post decimal are number of zeros in maxDecimalFactor - number of digits in fraction
|
|
17
|
+
const zerosPostDecimal = String(maxDecimalFactor).length - 1 - String(fraction).length;
|
|
18
|
+
return `${full}.${'0'.repeat(zerosPostDecimal)}${fraction}`;
|
|
19
|
+
}
|
|
20
|
+
class Units {
|
|
21
|
+
static validateInput(amount) {
|
|
22
|
+
if (typeof amount === 'number' && !Number.isInteger(amount)) {
|
|
23
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Input must be an integer number');
|
|
24
|
+
}
|
|
25
|
+
if (BigInt(amount) < 0) {
|
|
26
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Input must be a positive number');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert a number or bigint input of ether to wei
|
|
31
|
+
*
|
|
32
|
+
* @param {number | bigint} amount amount of units of ether to convert to wei
|
|
33
|
+
* @returns {bigint} amount of units in wei
|
|
34
|
+
*/
|
|
35
|
+
static ether(amount) {
|
|
36
|
+
Units.validateInput(amount);
|
|
37
|
+
return BigInt(amount) * exports.ETHER_TO_WEI;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert a number or bigint input of gwei to wei
|
|
41
|
+
*
|
|
42
|
+
* @param amount amount of units of gwei to convert to wei
|
|
43
|
+
* @returns {bigint} amount of units in wei
|
|
44
|
+
*/
|
|
45
|
+
static gwei(amount) {
|
|
46
|
+
Units.validateInput(amount);
|
|
47
|
+
return BigInt(amount) * exports.GWEI_TO_WEI;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Units = Units;
|
|
51
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":";;;AAOA,4CAeC;AAtBD,iDAAmD;AACnD,2CAAwD;AAExD,kCAAkC;AACrB,QAAA,WAAW,GAAG,MAAM,CAAC,EAAE,IAAI,CAA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,CAAC,MAAuB;QACjC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,mBAAW,CAAA;IACrC,CAAC;CACF;AA/BD,sBA+BC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Address } from './address.ts';
|
|
2
|
+
import type { AddressLike, BigIntLike, PrefixedHexString } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Flexible input data type for EIP-4895 withdrawal data with amount in Gwei to
|
|
5
|
+
* match CL representation and for eventual ssz withdrawalsRoot
|
|
6
|
+
*/
|
|
7
|
+
export type WithdrawalData = {
|
|
8
|
+
index: BigIntLike;
|
|
9
|
+
validatorIndex: BigIntLike;
|
|
10
|
+
address: AddressLike;
|
|
11
|
+
amount: BigIntLike;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* JSON RPC interface for EIP-4895 withdrawal data with amount in Gwei to
|
|
15
|
+
* match CL representation and for eventual ssz withdrawalsRoot
|
|
16
|
+
*/
|
|
17
|
+
export interface JSONRPCWithdrawal {
|
|
18
|
+
index: PrefixedHexString;
|
|
19
|
+
validatorIndex: PrefixedHexString;
|
|
20
|
+
address: PrefixedHexString;
|
|
21
|
+
amount: PrefixedHexString;
|
|
22
|
+
}
|
|
23
|
+
export type WithdrawalBytes = [Uint8Array, Uint8Array, Uint8Array, Uint8Array];
|
|
24
|
+
/**
|
|
25
|
+
* Convert a withdrawal to a byte array
|
|
26
|
+
* @param withdrawal the withdrawal to convert
|
|
27
|
+
* @returns byte array of the withdrawal
|
|
28
|
+
*/
|
|
29
|
+
export declare function withdrawalToBytesArray(withdrawal: Withdrawal | WithdrawalData): WithdrawalBytes;
|
|
30
|
+
/**
|
|
31
|
+
* Representation of EIP-4895 withdrawal data
|
|
32
|
+
*/
|
|
33
|
+
export declare class Withdrawal {
|
|
34
|
+
readonly index: bigint;
|
|
35
|
+
readonly validatorIndex: bigint;
|
|
36
|
+
readonly address: Address;
|
|
37
|
+
readonly amount: bigint;
|
|
38
|
+
/**
|
|
39
|
+
* This constructor assigns and validates the values.
|
|
40
|
+
* Use the static factory methods to assist in creating a Withdrawal object from varying data types.
|
|
41
|
+
* Its amount is in Gwei to match CL representation and for eventual ssz withdrawalsRoot
|
|
42
|
+
*/
|
|
43
|
+
constructor(index: bigint, validatorIndex: bigint, address: Address, amount: bigint);
|
|
44
|
+
raw(): WithdrawalBytes;
|
|
45
|
+
toValue(): {
|
|
46
|
+
index: bigint;
|
|
47
|
+
validatorIndex: bigint;
|
|
48
|
+
address: Uint8Array<ArrayBufferLike>;
|
|
49
|
+
amount: bigint;
|
|
50
|
+
};
|
|
51
|
+
toJSON(): {
|
|
52
|
+
index: `0x${string}`;
|
|
53
|
+
validatorIndex: `0x${string}`;
|
|
54
|
+
address: `0x${string}`;
|
|
55
|
+
amount: `0x${string}`;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a validator withdrawal request to be submitted to the consensus layer
|
|
60
|
+
* @param withdrawalData the consensus layer index and validator index values for the
|
|
61
|
+
* validator requesting the withdrawal and the address and withdrawal amount of the request
|
|
62
|
+
* @returns a {@link Withdrawal} object
|
|
63
|
+
*/
|
|
64
|
+
export declare function createWithdrawal(withdrawalData: WithdrawalData): Withdrawal;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a validator withdrawal request to be submitted to the consensus layer from
|
|
67
|
+
* an RLP list
|
|
68
|
+
* @param withdrawalArray decoded RLP list of withdrawal data elements
|
|
69
|
+
* @returns a {@link Withdrawal} object
|
|
70
|
+
*/
|
|
71
|
+
export declare function createWithdrawalFromBytesArray(withdrawalArray: WithdrawalBytes): Withdrawal;
|
|
72
|
+
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../src/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OA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