@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,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Address = void 0;
|
|
4
|
+
exports.createZeroAddress = createZeroAddress;
|
|
5
|
+
exports.createAddressFromBigInt = createAddressFromBigInt;
|
|
6
|
+
exports.createAddressFromString = createAddressFromString;
|
|
7
|
+
exports.createAddressFromPublicKey = createAddressFromPublicKey;
|
|
8
|
+
exports.createAddressFromPrivateKey = createAddressFromPrivateKey;
|
|
9
|
+
exports.createContractAddress = createContractAddress;
|
|
10
|
+
exports.createContractAddress2 = createContractAddress2;
|
|
11
|
+
const account_ts_1 = require("./account.js");
|
|
12
|
+
const bytes_ts_1 = require("./bytes.js");
|
|
13
|
+
const constants_ts_1 = require("./constants.js");
|
|
14
|
+
const errors_ts_1 = require("./errors.js");
|
|
15
|
+
/**
|
|
16
|
+
* Handling and generating Ethereum addresses
|
|
17
|
+
*/
|
|
18
|
+
class Address {
|
|
19
|
+
constructor(bytes) {
|
|
20
|
+
if (bytes.length !== 20) {
|
|
21
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Invalid address length');
|
|
22
|
+
}
|
|
23
|
+
this.bytes = bytes;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Is address equal to another.
|
|
27
|
+
*/
|
|
28
|
+
equals(address) {
|
|
29
|
+
return (0, bytes_ts_1.equalsBytes)(this.bytes, address.bytes);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Is address zero.
|
|
33
|
+
*/
|
|
34
|
+
isZero() {
|
|
35
|
+
return this.equals(new Address(new Uint8Array(20)));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* True if address is in the address range defined
|
|
39
|
+
* by EIP-1352
|
|
40
|
+
*/
|
|
41
|
+
isPrecompileOrSystemAddress() {
|
|
42
|
+
const address = (0, bytes_ts_1.bytesToBigInt)(this.bytes);
|
|
43
|
+
const rangeMin = constants_ts_1.BIGINT_0;
|
|
44
|
+
const rangeMax = BigInt('0xffff');
|
|
45
|
+
return address >= rangeMin && address <= rangeMax;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns hex encoding of address.
|
|
49
|
+
*/
|
|
50
|
+
toString() {
|
|
51
|
+
return (0, bytes_ts_1.bytesToHex)(this.bytes);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns a new Uint8Array representation of address.
|
|
55
|
+
*/
|
|
56
|
+
toBytes() {
|
|
57
|
+
return new Uint8Array(this.bytes);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Address = Address;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the zero address.
|
|
63
|
+
*/
|
|
64
|
+
function createZeroAddress() {
|
|
65
|
+
return new Address(new Uint8Array(20));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns an Address object from a bigint address (they are stored as bigints on the stack)
|
|
69
|
+
* @param value The bigint address
|
|
70
|
+
*/
|
|
71
|
+
function createAddressFromBigInt(value) {
|
|
72
|
+
const bytes = (0, bytes_ts_1.bigIntToBytes)(value);
|
|
73
|
+
if (bytes.length > 20) {
|
|
74
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)(`Invalid address, too long: ${bytes.length}`);
|
|
75
|
+
}
|
|
76
|
+
return new Address((0, bytes_ts_1.setLengthLeft)(bytes, 20));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns an Address object from a hex-encoded string.
|
|
80
|
+
* @param str - Hex-encoded address
|
|
81
|
+
*/
|
|
82
|
+
function createAddressFromString(str) {
|
|
83
|
+
if (!(0, account_ts_1.isValidAddress)(str)) {
|
|
84
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)(`Invalid address input=${str}`);
|
|
85
|
+
}
|
|
86
|
+
return new Address((0, bytes_ts_1.hexToBytes)(str));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns an address for a given public key.
|
|
90
|
+
* @param pubKey The two points of an uncompressed key
|
|
91
|
+
*/
|
|
92
|
+
function createAddressFromPublicKey(pubKey) {
|
|
93
|
+
if (!(pubKey instanceof Uint8Array)) {
|
|
94
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Public key should be Uint8Array');
|
|
95
|
+
}
|
|
96
|
+
const bytes = (0, account_ts_1.pubToAddress)(pubKey);
|
|
97
|
+
return new Address(bytes);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns an address for a given private key.
|
|
101
|
+
* @param privateKey A private key must be 256 bits wide
|
|
102
|
+
*/
|
|
103
|
+
function createAddressFromPrivateKey(privateKey) {
|
|
104
|
+
if (!(privateKey instanceof Uint8Array)) {
|
|
105
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Private key should be Uint8Array');
|
|
106
|
+
}
|
|
107
|
+
const bytes = (0, account_ts_1.privateToAddress)(privateKey);
|
|
108
|
+
return new Address(bytes);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generates an address for a newly created contract.
|
|
112
|
+
* @param from The address which is creating this new address
|
|
113
|
+
* @param nonce The nonce of the from account
|
|
114
|
+
*/
|
|
115
|
+
function createContractAddress(from, nonce) {
|
|
116
|
+
if (typeof nonce !== 'bigint') {
|
|
117
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Expected nonce to be a bigint');
|
|
118
|
+
}
|
|
119
|
+
return new Address((0, account_ts_1.generateAddress)(from.bytes, (0, bytes_ts_1.bigIntToBytes)(nonce)));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Generates an address for a contract created using CREATE2.
|
|
123
|
+
* @param from The address which is creating this new address
|
|
124
|
+
* @param salt A salt
|
|
125
|
+
* @param initCode The init code of the contract being created
|
|
126
|
+
*/
|
|
127
|
+
function createContractAddress2(from, salt, initCode) {
|
|
128
|
+
if (!(salt instanceof Uint8Array)) {
|
|
129
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Expected salt to be a Uint8Array');
|
|
130
|
+
}
|
|
131
|
+
if (!(initCode instanceof Uint8Array)) {
|
|
132
|
+
throw (0, errors_ts_1.EthereumJSErrorWithoutCode)('Expected initCode to be a Uint8Array');
|
|
133
|
+
}
|
|
134
|
+
return new Address((0, account_ts_1.generateAddress2)(from.bytes, salt, initCode));
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingUR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AAA,6BAAgB,EAAC,UAAU,CAAC,CAAA;IAC1C,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,IAAa,EAAE,KAAa;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAA,sCAA0B,EAAC,+BAA+B,CAAC,CAAA;IACnE,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,IAAA,4BAAe,EAAC,IAAI,CAAC,KAAK,EAAE,IAAA,wBAAa,EAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACvE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,IAAa,EACb,IAAgB,EAChB,QAAoB;IAEpB,IAAI,CAAC,CAAC,IAAI,YAAY,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,IAAA,sCAA0B,EAAC,kCAAkC,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC,EAAE,CAAC;QACtC,MAAM,IAAA,sCAA0B,EAAC,sCAAsC,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,IAAA,6BAAgB,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
2
|
+
import { Address } from './address.ts';
|
|
3
|
+
import type { EOACode7702AuthorizationListBytesItem, EOACode7702AuthorizationListBytesItemUnsigned, EOACode7702AuthorizationListItem, EOACode7702AuthorizationListItemUnsigned } from './types.ts';
|
|
4
|
+
export declare const EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC: Uint8Array<ArrayBufferLike>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts an authorization list to a JSON format
|
|
7
|
+
* @param authorizationList
|
|
8
|
+
* @returns authorizationList in JSON format
|
|
9
|
+
*/
|
|
10
|
+
export declare function eoaCode7702AuthorizationListBytesItemToJSON(authorizationList: EOACode7702AuthorizationListBytesItem): EOACode7702AuthorizationListItem;
|
|
11
|
+
/**
|
|
12
|
+
* Converts an authority list in JSON to a bytes format
|
|
13
|
+
* @param authorizationList
|
|
14
|
+
* @returns bytes format of the authority list
|
|
15
|
+
*/
|
|
16
|
+
export declare function eoaCode7702AuthorizationListJSONItemToBytes(authorizationList: EOACode7702AuthorizationListItem): EOACode7702AuthorizationListBytesItem;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the bytes (RLP-encoded) to sign
|
|
19
|
+
* @param input Either the bytes or the object format of the authorization list item
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function eoaCode7702AuthorizationMessageToSign(input: EOACode7702AuthorizationListItemUnsigned | EOACode7702AuthorizationListBytesItemUnsigned): Uint8Array<ArrayBuffer>;
|
|
23
|
+
/**
|
|
24
|
+
* Hashes the RLP-encoded message to sign
|
|
25
|
+
* @param input
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function eoaCode7702AuthorizationHashedMessageToSign(input: EOACode7702AuthorizationListItemUnsigned | EOACode7702AuthorizationListBytesItemUnsigned): Uint8Array<ArrayBufferLike>;
|
|
29
|
+
/**
|
|
30
|
+
* Signs an authorization list item and returns it in `bytes` format.
|
|
31
|
+
* To get the JSON format, use `authorizationListBytesToJSON([signed])[0] to convert it`
|
|
32
|
+
* @param input
|
|
33
|
+
* @param privateKey
|
|
34
|
+
* @param ecSign
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function eoaCode7702SignAuthorization(input: EOACode7702AuthorizationListItemUnsigned | EOACode7702AuthorizationListBytesItemUnsigned, privateKey: Uint8Array, ecSign?: (msg: Uint8Array, pk: Uint8Array, ecSignOpts?: {
|
|
38
|
+
extraEntropy?: Uint8Array | boolean;
|
|
39
|
+
}) => Pick<ReturnType<typeof secp256k1.Signature.fromBytes>, 'recovery' | 'r' | 's'>): EOACode7702AuthorizationListBytesItem;
|
|
40
|
+
export declare function eoaCode7702RecoverAuthority(input: EOACode7702AuthorizationListItem | EOACode7702AuthorizationListBytesItem): Address;
|
|
41
|
+
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/authorization.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAGtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAWtC,OAAO,KAAK,EACV,qCAAqC,EACrC,6CAA6C,EAC7C,gCAAgC,EAChC,wCAAwC,EACzC,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,qCAAqC,6BAAqB,CAAA;AAEvE;;;;GAIG;AACH,wBAAgB,2CAA2C,CACzD,iBAAiB,EAAE,qCAAqC,GACvD,gCAAgC,CAUlC;AAED;;;;GAIG;AACH,wBAAgB,2CAA2C,CACzD,iBAAiB,EAAE,gCAAgC,GAClD,qCAAqC,CAoBvC;AAWD;;;;GAIG;AACH,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,wCAAwC,GAAG,6CAA6C,2BAgBhG;AAED;;;;GAIG;AACH,wBAAgB,2CAA2C,CACzD,KAAK,EAAE,wCAAwC,GAAG,6CAA6C,+BAGhG;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,wCAAwC,GAAG,6CAA6C,EAC/F,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,CACP,GAAG,EAAE,UAAU,EACf,EAAE,EAAE,UAAU,EACd,UAAU,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,UAAU,GAAG,OAAO,CAAA;CAAE,KACjD,IAAI,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,UAAU,GAAG,GAAG,GAAG,GAAG,CAAC,GAClF,qCAAqC,CA0BvC;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,gCAAgC,GAAG,qCAAqC,GAC9E,OAAO,CAeT"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Utility helpers to convert authorization lists from the byte format and JSON format and vice versa
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC = void 0;
|
|
5
|
+
exports.eoaCode7702AuthorizationListBytesItemToJSON = eoaCode7702AuthorizationListBytesItemToJSON;
|
|
6
|
+
exports.eoaCode7702AuthorizationListJSONItemToBytes = eoaCode7702AuthorizationListJSONItemToBytes;
|
|
7
|
+
exports.eoaCode7702AuthorizationMessageToSign = eoaCode7702AuthorizationMessageToSign;
|
|
8
|
+
exports.eoaCode7702AuthorizationHashedMessageToSign = eoaCode7702AuthorizationHashedMessageToSign;
|
|
9
|
+
exports.eoaCode7702SignAuthorization = eoaCode7702SignAuthorization;
|
|
10
|
+
exports.eoaCode7702RecoverAuthority = eoaCode7702RecoverAuthority;
|
|
11
|
+
const rlp_1 = require("@feelyourprotocol/rlp");
|
|
12
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
13
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
14
|
+
const account_ts_1 = require("./account.js");
|
|
15
|
+
const address_ts_1 = require("./address.js");
|
|
16
|
+
const bytes_ts_1 = require("./bytes.js");
|
|
17
|
+
const signature_ts_1 = require("./signature.js");
|
|
18
|
+
exports.EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC = (0, bytes_ts_1.hexToBytes)('0x05');
|
|
19
|
+
/**
|
|
20
|
+
* Converts an authorization list to a JSON format
|
|
21
|
+
* @param authorizationList
|
|
22
|
+
* @returns authorizationList in JSON format
|
|
23
|
+
*/
|
|
24
|
+
function eoaCode7702AuthorizationListBytesItemToJSON(authorizationList) {
|
|
25
|
+
const [chainId, address, nonce, yParity, r, s] = authorizationList;
|
|
26
|
+
return {
|
|
27
|
+
chainId: (0, bytes_ts_1.bytesToHex)(chainId),
|
|
28
|
+
address: (0, bytes_ts_1.bytesToHex)(address),
|
|
29
|
+
nonce: (0, bytes_ts_1.bytesToHex)(nonce),
|
|
30
|
+
yParity: (0, bytes_ts_1.bytesToHex)(yParity),
|
|
31
|
+
r: (0, bytes_ts_1.bytesToHex)(r),
|
|
32
|
+
s: (0, bytes_ts_1.bytesToHex)(s),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Converts an authority list in JSON to a bytes format
|
|
37
|
+
* @param authorizationList
|
|
38
|
+
* @returns bytes format of the authority list
|
|
39
|
+
*/
|
|
40
|
+
function eoaCode7702AuthorizationListJSONItemToBytes(authorizationList) {
|
|
41
|
+
const requiredFields = ['chainId', 'address', 'nonce', 'yParity', 'r', 's'];
|
|
42
|
+
// Validate all required fields are present
|
|
43
|
+
for (const field of requiredFields) {
|
|
44
|
+
if (authorizationList[field] === undefined) {
|
|
45
|
+
throw (0, rlp_1.EthereumJSErrorWithoutCode)(`EIP-7702 authorization list invalid: ${field} is not defined`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
(0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(authorizationList.chainId)),
|
|
50
|
+
(0, bytes_ts_1.hexToBytes)(authorizationList.address),
|
|
51
|
+
(0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(authorizationList.nonce)),
|
|
52
|
+
(0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(authorizationList.yParity)),
|
|
53
|
+
(0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(authorizationList.r)),
|
|
54
|
+
(0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(authorizationList.s)),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
/** Authorization signing utility methods */
|
|
58
|
+
function unsignedAuthorizationListToBytes(input) {
|
|
59
|
+
const { chainId: chainIdHex, address: addressHex, nonce: nonceHex } = input;
|
|
60
|
+
const chainId = (0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(chainIdHex));
|
|
61
|
+
const address = (0, bytes_ts_1.setLengthLeft)((0, bytes_ts_1.hexToBytes)(addressHex), 20);
|
|
62
|
+
const nonce = (0, bytes_ts_1.unpadBytes)((0, bytes_ts_1.hexToBytes)(nonceHex));
|
|
63
|
+
return [chainId, address, nonce];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the bytes (RLP-encoded) to sign
|
|
67
|
+
* @param input Either the bytes or the object format of the authorization list item
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
function eoaCode7702AuthorizationMessageToSign(input) {
|
|
71
|
+
if (Array.isArray(input)) {
|
|
72
|
+
// The address is validated, the chainId and nonce will be `unpadBytes` such that these are valid
|
|
73
|
+
const [chainId, address, nonce] = input;
|
|
74
|
+
if (address.length !== 20) {
|
|
75
|
+
throw (0, rlp_1.EthereumJSErrorWithoutCode)('Cannot sign authority: address length should be 20 bytes');
|
|
76
|
+
}
|
|
77
|
+
return (0, bytes_ts_1.concatBytes)(exports.EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC, rlp_1.RLP.encode([(0, bytes_ts_1.unpadBytes)(chainId), address, (0, bytes_ts_1.unpadBytes)(nonce)]));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const [chainId, address, nonce] = unsignedAuthorizationListToBytes(input);
|
|
81
|
+
return (0, bytes_ts_1.concatBytes)(exports.EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC, rlp_1.RLP.encode([chainId, address, nonce]));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Hashes the RLP-encoded message to sign
|
|
86
|
+
* @param input
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
function eoaCode7702AuthorizationHashedMessageToSign(input) {
|
|
90
|
+
return (0, sha3_js_1.keccak_256)(eoaCode7702AuthorizationMessageToSign(input));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Signs an authorization list item and returns it in `bytes` format.
|
|
94
|
+
* To get the JSON format, use `authorizationListBytesToJSON([signed])[0] to convert it`
|
|
95
|
+
* @param input
|
|
96
|
+
* @param privateKey
|
|
97
|
+
* @param ecSign
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
function eoaCode7702SignAuthorization(input, privateKey, ecSign) {
|
|
101
|
+
const msgHash = eoaCode7702AuthorizationHashedMessageToSign(input);
|
|
102
|
+
const secp256k1Sign = (msgHash, pk) => {
|
|
103
|
+
return (ecSign?.(msgHash, pk) ??
|
|
104
|
+
secp256k1_js_1.secp256k1.Signature.fromBytes(secp256k1_js_1.secp256k1.sign(msgHash, pk, { prehash: false, format: 'recovered' }), 'recovered'));
|
|
105
|
+
};
|
|
106
|
+
const signed = secp256k1Sign(msgHash, privateKey);
|
|
107
|
+
const [chainId, address, nonce] = Array.isArray(input)
|
|
108
|
+
? input
|
|
109
|
+
: unsignedAuthorizationListToBytes(input);
|
|
110
|
+
return [
|
|
111
|
+
(0, bytes_ts_1.unpadBytes)(chainId),
|
|
112
|
+
address,
|
|
113
|
+
(0, bytes_ts_1.unpadBytes)(nonce),
|
|
114
|
+
(0, bytes_ts_1.bigIntToUnpaddedBytes)(BigInt(signed.recovery)),
|
|
115
|
+
(0, bytes_ts_1.bigIntToUnpaddedBytes)(signed.r),
|
|
116
|
+
(0, bytes_ts_1.bigIntToUnpaddedBytes)(signed.s),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
function eoaCode7702RecoverAuthority(input) {
|
|
120
|
+
const inputBytes = Array.isArray(input)
|
|
121
|
+
? input
|
|
122
|
+
: eoaCode7702AuthorizationListJSONItemToBytes(input);
|
|
123
|
+
const [chainId, address, nonce, yParity, r, s] = [
|
|
124
|
+
(0, bytes_ts_1.unpadBytes)(inputBytes[0]),
|
|
125
|
+
inputBytes[1],
|
|
126
|
+
(0, bytes_ts_1.unpadBytes)(inputBytes[2]),
|
|
127
|
+
(0, bytes_ts_1.unpadBytes)(inputBytes[3]),
|
|
128
|
+
(0, bytes_ts_1.unpadBytes)(inputBytes[4]),
|
|
129
|
+
(0, bytes_ts_1.unpadBytes)(inputBytes[5]),
|
|
130
|
+
];
|
|
131
|
+
const msgHash = eoaCode7702AuthorizationHashedMessageToSign([chainId, address, nonce]);
|
|
132
|
+
const pubKey = (0, signature_ts_1.ecrecover)(msgHash, (0, bytes_ts_1.bytesToBigInt)(yParity), r, s);
|
|
133
|
+
return new address_ts_1.Address((0, account_ts_1.publicToAddress)(pubKey));
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../src/authorization.ts"],"names":[],"mappings":";AAAA,qGAAqG;;;AA+BrG,kGAYC;AAOD,kGAsBC;AAgBD,sFAiBC;AAOD,kGAIC;AAUD,oEAkCC;AAED,kEAiBC;AAjLD,yCAAiE;AACjE,6DAAsD;AACtD,mDAAkD;AAClD,6CAA8C;AAC9C,6CAAsC;AACtC,yCAQmB;AACnB,iDAA0C;AAQ7B,QAAA,qCAAqC,GAAG,IAAA,qBAAU,EAAC,MAAM,CAAC,CAAA;AAEvE;;;;GAIG;AACH,SAAgB,2CAA2C,CACzD,iBAAwD;IAExD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAA;IAClE,OAAO;QACL,OAAO,EAAE,IAAA,qBAAU,EAAC,OAAO,CAAC;QAC5B,OAAO,EAAE,IAAA,qBAAU,EAAC,OAAO,CAAC;QAC5B,KAAK,EAAE,I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AAC,GAAG;QAC/C,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzB,UAAU,CAAC,CAAC,CAAC;QACb,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzB,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzB,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzB,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KAC1B,CAAA;IACD,MAAM,OAAO,GAAG,2CAA2C,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IACtF,MAAM,MAAM,GAAG,IAAA,wBAAS,EAAC,OAAO,EAAE,IAAA,wBAAa,EAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,OAAO,IAAI,oBAAO,CAAC,IAAA,4BAAe,EAAC,MAAM,CAAC,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { PrefixedHexString } from './types.ts';
|
|
2
|
+
type BALAddressHex = PrefixedHexString;
|
|
3
|
+
type BALStorageKeyBytes = Uint8Array;
|
|
4
|
+
type BALStorageKeyHex = PrefixedHexString;
|
|
5
|
+
type BALStorageValueBytes = Uint8Array;
|
|
6
|
+
type BALStorageValueHex = PrefixedHexString;
|
|
7
|
+
type BALAccessIndexNumber = number;
|
|
8
|
+
type BALAccessIndexHex = PrefixedHexString;
|
|
9
|
+
type BALBalanceBigInt = bigint;
|
|
10
|
+
type BALBalanceHex = PrefixedHexString;
|
|
11
|
+
type BALNonceBigInt = bigint;
|
|
12
|
+
type BALNonceHex = PrefixedHexString;
|
|
13
|
+
type BALByteCodeBytes = Uint8Array;
|
|
14
|
+
type BALByteCodeHex = PrefixedHexString;
|
|
15
|
+
type BALRawStorageChange = [BALAccessIndexNumber, BALStorageValueBytes];
|
|
16
|
+
type BALRawBalanceChange = [BALAccessIndexNumber, BALBalanceHex];
|
|
17
|
+
type BALRawNonceChange = [BALAccessIndexNumber, BALNonceHex];
|
|
18
|
+
type BALRawCodeChange = [BALAccessIndexNumber, BALByteCodeBytes];
|
|
19
|
+
type BALRawSlotChanges = [BALStorageKeyHex, BALRawStorageChange[]];
|
|
20
|
+
type BALRawAccountChanges = [
|
|
21
|
+
BALAddressHex,
|
|
22
|
+
BALRawSlotChanges[],
|
|
23
|
+
BALStorageKeyHex[],
|
|
24
|
+
BALRawBalanceChange[],
|
|
25
|
+
BALRawNonceChange[],
|
|
26
|
+
BALRawCodeChange[]
|
|
27
|
+
];
|
|
28
|
+
type BALRawBlockAccessList = BALRawAccountChanges[];
|
|
29
|
+
export type Accesses = Record<BALAddressHex, {
|
|
30
|
+
nonceChanges: Map<BALAccessIndexNumber, BALNonceHex>;
|
|
31
|
+
balanceChanges: Map<BALAccessIndexNumber, BALBalanceHex>;
|
|
32
|
+
codeChanges: BALRawCodeChange[];
|
|
33
|
+
storageChanges: Record<BALStorageKeyHex, BALRawStorageChange[]>;
|
|
34
|
+
storageReads: Set<BALStorageKeyHex>;
|
|
35
|
+
}>;
|
|
36
|
+
interface BALJSONBalanceChange {
|
|
37
|
+
blockAccessIndex: BALAccessIndexHex;
|
|
38
|
+
postBalance: BALBalanceHex;
|
|
39
|
+
}
|
|
40
|
+
interface BALJSONNonceChange {
|
|
41
|
+
blockAccessIndex: BALAccessIndexHex;
|
|
42
|
+
postNonce: BALNonceHex;
|
|
43
|
+
}
|
|
44
|
+
interface BALJSONCodeChange {
|
|
45
|
+
blockAccessIndex: BALAccessIndexHex;
|
|
46
|
+
newCode: BALByteCodeHex;
|
|
47
|
+
}
|
|
48
|
+
interface BALJSONStorageChange {
|
|
49
|
+
blockAccessIndex: BALAccessIndexHex;
|
|
50
|
+
postValue: BALStorageValueHex;
|
|
51
|
+
}
|
|
52
|
+
interface BALJSONSlotChanges {
|
|
53
|
+
slot: BALStorageKeyHex;
|
|
54
|
+
slotChanges: BALJSONStorageChange[];
|
|
55
|
+
}
|
|
56
|
+
interface BALJSONAccountChanges {
|
|
57
|
+
address: BALAddressHex;
|
|
58
|
+
balanceChanges: BALJSONBalanceChange[];
|
|
59
|
+
nonceChanges: BALJSONNonceChange[];
|
|
60
|
+
codeChanges: BALJSONCodeChange[];
|
|
61
|
+
storageChanges: BALJSONSlotChanges[];
|
|
62
|
+
storageReads: BALStorageKeyHex[];
|
|
63
|
+
}
|
|
64
|
+
export type BALJSONBlockAccessList = BALJSONAccountChanges[];
|
|
65
|
+
export type { BALJSONAccountChanges, BALJSONStorageChange, BALJSONSlotChanges, BALJSONBalanceChange, BALJSONNonceChange, BALJSONCodeChange, };
|
|
66
|
+
/**
|
|
67
|
+
* Structural helper class for block level access lists
|
|
68
|
+
*
|
|
69
|
+
* EXPERIMENTAL: DO NOT USE IN PRODUCTION!
|
|
70
|
+
*/
|
|
71
|
+
export declare class BlockLevelAccessList {
|
|
72
|
+
accesses: Accesses;
|
|
73
|
+
blockAccessIndex: number;
|
|
74
|
+
private checkpoints;
|
|
75
|
+
private originalBalances;
|
|
76
|
+
private originalCodesAtIndex;
|
|
77
|
+
constructor(accesses?: Accesses);
|
|
78
|
+
/**
|
|
79
|
+
* Serializes the block level access list to RLP.
|
|
80
|
+
*
|
|
81
|
+
* @returns the RLP encoded block level access list
|
|
82
|
+
*/
|
|
83
|
+
serialize(): Uint8Array;
|
|
84
|
+
/**
|
|
85
|
+
* This hash is used in the block header
|
|
86
|
+
*
|
|
87
|
+
* @returns the hash of the serialized block level access list
|
|
88
|
+
*/
|
|
89
|
+
hash(): Uint8Array;
|
|
90
|
+
checkpoint(): void;
|
|
91
|
+
commit(): void;
|
|
92
|
+
revert(): void;
|
|
93
|
+
private cloneAccesses;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the raw block level access list with values
|
|
96
|
+
* correctly sorted.
|
|
97
|
+
*
|
|
98
|
+
* @returns the raw block level access list
|
|
99
|
+
*/
|
|
100
|
+
raw(): BALRawBlockAccessList;
|
|
101
|
+
addAddress(address: BALAddressHex): void;
|
|
102
|
+
addStorageWrite(address: BALAddressHex, storageKey: BALStorageKeyBytes, value: BALStorageValueBytes, blockAccessIndex: BALAccessIndexNumber, originalValue?: BALStorageValueBytes): void;
|
|
103
|
+
addStorageRead(address: BALAddressHex, storageKey: BALStorageKeyBytes): void;
|
|
104
|
+
addBalanceChange(address: BALAddressHex, balance: BALBalanceBigInt, blockAccessIndex: BALAccessIndexNumber, originalBalance?: BALBalanceBigInt): void;
|
|
105
|
+
/**
|
|
106
|
+
* EIP-7928: Remove balance changes for addresses where final balance equals first balance.
|
|
107
|
+
* Call this at the end of each transaction to clean up net-zero balance changes.
|
|
108
|
+
*/
|
|
109
|
+
cleanupNetZeroBalanceChanges(): void;
|
|
110
|
+
addNonceChange(address: BALAddressHex, nonce: BALNonceBigInt, blockAccessIndex: BALAccessIndexNumber): void;
|
|
111
|
+
addCodeChange(address: BALAddressHex, code: BALByteCodeBytes, blockAccessIndex: BALAccessIndexNumber, originalCode?: BALByteCodeBytes): void;
|
|
112
|
+
/**
|
|
113
|
+
* EIP-7928: For selfdestructed accounts, drop all state changes while
|
|
114
|
+
* preserving read footprints. Any storageChanges are converted to storageReads.
|
|
115
|
+
*
|
|
116
|
+
* Per EIP-7928: "if the account had a positive balance pre-transaction,
|
|
117
|
+
* the balance change to zero MUST be recorded."
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* Converts the internal representation to the JSON format (BALJSONBlockAccessList).
|
|
121
|
+
* Inverse of createBlockLevelAccessListFromJSON().
|
|
122
|
+
*/
|
|
123
|
+
toJSON(): BALJSONBlockAccessList;
|
|
124
|
+
cleanupSelfdestructed(addresses: Array<BALAddressHex>): void;
|
|
125
|
+
}
|
|
126
|
+
export declare function createBlockLevelAccessList(): BlockLevelAccessList;
|
|
127
|
+
export declare function createBlockLevelAccessListFromJSON(json: BALJSONBlockAccessList): BlockLevelAccessList;
|
|
128
|
+
export declare function createBlockLevelAccessListFromRLP(rlp: Uint8Array): BlockLevelAccessList;
|
|
129
|
+
//# sourceMappingURL=bal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bal.d.ts","sourceRoot":"","sources":["../../src/bal.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGnD,KAAK,aAAa,GAAG,iBAAiB,CAAA;AACtC,KAAK,kBAAkB,GAAG,UAAU,CAAA;AACpC,KAAK,gBAAgB,GAAG,iBAAiB,CAAA;AACzC,KAAK,oBAAoB,GAAG,UAAU,CAAA;AACtC,KAAK,kBAAkB,GAAG,iBAAiB,CAAA;AAC3C,KAAK,oBAAoB,GAAG,MAAM,CAAA;AAClC,KAAK,iBAAiB,GAAG,iBAAiB,CAAA;AAC1C,KAAK,gBAAgB,GAAG,MAAM,CAAA;AAC9B,KAAK,aAAa,GAAG,iBAAiB,CAAA;AACtC,KAAK,cAAc,GAAG,MAAM,CAAA;AAC5B,KAAK,WAAW,GAAG,iBAAiB,CAAA;AACpC,KAAK,gBAAgB,GAAG,UAAU,CAAA;AAClC,KAAK,cAAc,GAAG,iBAAiB,CAAA;AAGvC,KAAK,mBAAmB,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAA;AACvE,KAAK,mBAAmB,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAA;AAChE,KAAK,iBAAiB,GAAG,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAA;AAC5D,KAAK,gBAAgB,GAAG,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAA;AAChE,KAAK,iBAAiB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,CAAC,CAAA;AAGlE,KAAK,oBAAoB,GAAG;IAC1B,aAAa;IACb,iBAAiB,EAAE;IACnB,gBAAgB,EAAE;IAClB,mBAAmB,EAAE;IACrB,iBAAiB,EAAE;IACnB,gBA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