@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,125 @@
|
|
|
1
|
+
import { generateAddress, generateAddress2, isValidAddress, privateToAddress, pubToAddress, } from "./account.js";
|
|
2
|
+
import { bigIntToBytes, bytesToBigInt, bytesToHex, equalsBytes, hexToBytes, setLengthLeft, } from "./bytes.js";
|
|
3
|
+
import { BIGINT_0 } from "./constants.js";
|
|
4
|
+
import { EthereumJSErrorWithoutCode } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Handling and generating Ethereum addresses
|
|
7
|
+
*/
|
|
8
|
+
export class Address {
|
|
9
|
+
constructor(bytes) {
|
|
10
|
+
if (bytes.length !== 20) {
|
|
11
|
+
throw EthereumJSErrorWithoutCode('Invalid address length');
|
|
12
|
+
}
|
|
13
|
+
this.bytes = bytes;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Is address equal to another.
|
|
17
|
+
*/
|
|
18
|
+
equals(address) {
|
|
19
|
+
return equalsBytes(this.bytes, address.bytes);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Is address zero.
|
|
23
|
+
*/
|
|
24
|
+
isZero() {
|
|
25
|
+
return this.equals(new Address(new Uint8Array(20)));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* True if address is in the address range defined
|
|
29
|
+
* by EIP-1352
|
|
30
|
+
*/
|
|
31
|
+
isPrecompileOrSystemAddress() {
|
|
32
|
+
const address = bytesToBigInt(this.bytes);
|
|
33
|
+
const rangeMin = BIGINT_0;
|
|
34
|
+
const rangeMax = BigInt('0xffff');
|
|
35
|
+
return address >= rangeMin && address <= rangeMax;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns hex encoding of address.
|
|
39
|
+
*/
|
|
40
|
+
toString() {
|
|
41
|
+
return bytesToHex(this.bytes);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns a new Uint8Array representation of address.
|
|
45
|
+
*/
|
|
46
|
+
toBytes() {
|
|
47
|
+
return new Uint8Array(this.bytes);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the zero address.
|
|
52
|
+
*/
|
|
53
|
+
export function createZeroAddress() {
|
|
54
|
+
return new Address(new Uint8Array(20));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns an Address object from a bigint address (they are stored as bigints on the stack)
|
|
58
|
+
* @param value The bigint address
|
|
59
|
+
*/
|
|
60
|
+
export function createAddressFromBigInt(value) {
|
|
61
|
+
const bytes = bigIntToBytes(value);
|
|
62
|
+
if (bytes.length > 20) {
|
|
63
|
+
throw EthereumJSErrorWithoutCode(`Invalid address, too long: ${bytes.length}`);
|
|
64
|
+
}
|
|
65
|
+
return new Address(setLengthLeft(bytes, 20));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns an Address object from a hex-encoded string.
|
|
69
|
+
* @param str - Hex-encoded address
|
|
70
|
+
*/
|
|
71
|
+
export function createAddressFromString(str) {
|
|
72
|
+
if (!isValidAddress(str)) {
|
|
73
|
+
throw EthereumJSErrorWithoutCode(`Invalid address input=${str}`);
|
|
74
|
+
}
|
|
75
|
+
return new Address(hexToBytes(str));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns an address for a given public key.
|
|
79
|
+
* @param pubKey The two points of an uncompressed key
|
|
80
|
+
*/
|
|
81
|
+
export function createAddressFromPublicKey(pubKey) {
|
|
82
|
+
if (!(pubKey instanceof Uint8Array)) {
|
|
83
|
+
throw EthereumJSErrorWithoutCode('Public key should be Uint8Array');
|
|
84
|
+
}
|
|
85
|
+
const bytes = pubToAddress(pubKey);
|
|
86
|
+
return new Address(bytes);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns an address for a given private key.
|
|
90
|
+
* @param privateKey A private key must be 256 bits wide
|
|
91
|
+
*/
|
|
92
|
+
export function createAddressFromPrivateKey(privateKey) {
|
|
93
|
+
if (!(privateKey instanceof Uint8Array)) {
|
|
94
|
+
throw EthereumJSErrorWithoutCode('Private key should be Uint8Array');
|
|
95
|
+
}
|
|
96
|
+
const bytes = privateToAddress(privateKey);
|
|
97
|
+
return new Address(bytes);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generates an address for a newly created contract.
|
|
101
|
+
* @param from The address which is creating this new address
|
|
102
|
+
* @param nonce The nonce of the from account
|
|
103
|
+
*/
|
|
104
|
+
export function createContractAddress(from, nonce) {
|
|
105
|
+
if (typeof nonce !== 'bigint') {
|
|
106
|
+
throw EthereumJSErrorWithoutCode('Expected nonce to be a bigint');
|
|
107
|
+
}
|
|
108
|
+
return new Address(generateAddress(from.bytes, bigIntToBytes(nonce)));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generates an address for a contract created using CREATE2.
|
|
112
|
+
* @param from The address which is creating this new address
|
|
113
|
+
* @param salt A salt
|
|
114
|
+
* @param initCode The init code of the contract being created
|
|
115
|
+
*/
|
|
116
|
+
export function createContractAddress2(from, salt, initCode) {
|
|
117
|
+
if (!(salt instanceof Uint8Array)) {
|
|
118
|
+
throw EthereumJSErrorWithoutCode('Expected salt to be a Uint8Array');
|
|
119
|
+
}
|
|
120
|
+
if (!(initCode instanceof Uint8Array)) {
|
|
121
|
+
throw EthereumJSErrorWithoutCode('Expected initCode to be a Uint8Array');
|
|
122
|
+
}
|
|
123
|
+
return new Address(generateAddress2(from.bytes, salt, initCode));
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAIxD;;GAEG;AACH,MAAM,OAAO,OAAO;IAGlB,YAAY,KAAiB;QAC3B,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACxB,MAAM,0BAA0B,CAAC,wBAAwB,CAAC,CAAA;QAC5D,CAAC;QACD,IAAI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AE,CAAC;QAClC,MAAM,0BAA0B,CAAC,kCAAkC,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC,EAAE,CAAC;QACtC,MAAM,0BAA0B,CAAC,sCAAsC,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,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,126 @@
|
|
|
1
|
+
// Utility helpers to convert authorization lists from the byte format and JSON format and vice versa
|
|
2
|
+
import { EthereumJSErrorWithoutCode, RLP } from '@feelyourprotocol/rlp';
|
|
3
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
4
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
5
|
+
import { publicToAddress } from "./account.js";
|
|
6
|
+
import { Address } from "./address.js";
|
|
7
|
+
import { bigIntToUnpaddedBytes, bytesToBigInt, bytesToHex, concatBytes, hexToBytes, setLengthLeft, unpadBytes, } from "./bytes.js";
|
|
8
|
+
import { ecrecover } from "./signature.js";
|
|
9
|
+
export const EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC = hexToBytes('0x05');
|
|
10
|
+
/**
|
|
11
|
+
* Converts an authorization list to a JSON format
|
|
12
|
+
* @param authorizationList
|
|
13
|
+
* @returns authorizationList in JSON format
|
|
14
|
+
*/
|
|
15
|
+
export function eoaCode7702AuthorizationListBytesItemToJSON(authorizationList) {
|
|
16
|
+
const [chainId, address, nonce, yParity, r, s] = authorizationList;
|
|
17
|
+
return {
|
|
18
|
+
chainId: bytesToHex(chainId),
|
|
19
|
+
address: bytesToHex(address),
|
|
20
|
+
nonce: bytesToHex(nonce),
|
|
21
|
+
yParity: bytesToHex(yParity),
|
|
22
|
+
r: bytesToHex(r),
|
|
23
|
+
s: bytesToHex(s),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Converts an authority list in JSON to a bytes format
|
|
28
|
+
* @param authorizationList
|
|
29
|
+
* @returns bytes format of the authority list
|
|
30
|
+
*/
|
|
31
|
+
export function eoaCode7702AuthorizationListJSONItemToBytes(authorizationList) {
|
|
32
|
+
const requiredFields = ['chainId', 'address', 'nonce', 'yParity', 'r', 's'];
|
|
33
|
+
// Validate all required fields are present
|
|
34
|
+
for (const field of requiredFields) {
|
|
35
|
+
if (authorizationList[field] === undefined) {
|
|
36
|
+
throw EthereumJSErrorWithoutCode(`EIP-7702 authorization list invalid: ${field} is not defined`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
unpadBytes(hexToBytes(authorizationList.chainId)),
|
|
41
|
+
hexToBytes(authorizationList.address),
|
|
42
|
+
unpadBytes(hexToBytes(authorizationList.nonce)),
|
|
43
|
+
unpadBytes(hexToBytes(authorizationList.yParity)),
|
|
44
|
+
unpadBytes(hexToBytes(authorizationList.r)),
|
|
45
|
+
unpadBytes(hexToBytes(authorizationList.s)),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
/** Authorization signing utility methods */
|
|
49
|
+
function unsignedAuthorizationListToBytes(input) {
|
|
50
|
+
const { chainId: chainIdHex, address: addressHex, nonce: nonceHex } = input;
|
|
51
|
+
const chainId = unpadBytes(hexToBytes(chainIdHex));
|
|
52
|
+
const address = setLengthLeft(hexToBytes(addressHex), 20);
|
|
53
|
+
const nonce = unpadBytes(hexToBytes(nonceHex));
|
|
54
|
+
return [chainId, address, nonce];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the bytes (RLP-encoded) to sign
|
|
58
|
+
* @param input Either the bytes or the object format of the authorization list item
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export function eoaCode7702AuthorizationMessageToSign(input) {
|
|
62
|
+
if (Array.isArray(input)) {
|
|
63
|
+
// The address is validated, the chainId and nonce will be `unpadBytes` such that these are valid
|
|
64
|
+
const [chainId, address, nonce] = input;
|
|
65
|
+
if (address.length !== 20) {
|
|
66
|
+
throw EthereumJSErrorWithoutCode('Cannot sign authority: address length should be 20 bytes');
|
|
67
|
+
}
|
|
68
|
+
return concatBytes(EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC, RLP.encode([unpadBytes(chainId), address, unpadBytes(nonce)]));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const [chainId, address, nonce] = unsignedAuthorizationListToBytes(input);
|
|
72
|
+
return concatBytes(EOA_CODE_7702_AUTHORITY_SIGNING_MAGIC, RLP.encode([chainId, address, nonce]));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Hashes the RLP-encoded message to sign
|
|
77
|
+
* @param input
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
export function eoaCode7702AuthorizationHashedMessageToSign(input) {
|
|
81
|
+
return keccak_256(eoaCode7702AuthorizationMessageToSign(input));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Signs an authorization list item and returns it in `bytes` format.
|
|
85
|
+
* To get the JSON format, use `authorizationListBytesToJSON([signed])[0] to convert it`
|
|
86
|
+
* @param input
|
|
87
|
+
* @param privateKey
|
|
88
|
+
* @param ecSign
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
export function eoaCode7702SignAuthorization(input, privateKey, ecSign) {
|
|
92
|
+
const msgHash = eoaCode7702AuthorizationHashedMessageToSign(input);
|
|
93
|
+
const secp256k1Sign = (msgHash, pk) => {
|
|
94
|
+
return (ecSign?.(msgHash, pk) ??
|
|
95
|
+
secp256k1.Signature.fromBytes(secp256k1.sign(msgHash, pk, { prehash: false, format: 'recovered' }), 'recovered'));
|
|
96
|
+
};
|
|
97
|
+
const signed = secp256k1Sign(msgHash, privateKey);
|
|
98
|
+
const [chainId, address, nonce] = Array.isArray(input)
|
|
99
|
+
? input
|
|
100
|
+
: unsignedAuthorizationListToBytes(input);
|
|
101
|
+
return [
|
|
102
|
+
unpadBytes(chainId),
|
|
103
|
+
address,
|
|
104
|
+
unpadBytes(nonce),
|
|
105
|
+
bigIntToUnpaddedBytes(BigInt(signed.recovery)),
|
|
106
|
+
bigIntToUnpaddedBytes(signed.r),
|
|
107
|
+
bigIntToUnpaddedBytes(signed.s),
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
export function eoaCode7702RecoverAuthority(input) {
|
|
111
|
+
const inputBytes = Array.isArray(input)
|
|
112
|
+
? input
|
|
113
|
+
: eoaCode7702AuthorizationListJSONItemToBytes(input);
|
|
114
|
+
const [chainId, address, nonce, yParity, r, s] = [
|
|
115
|
+
unpadBytes(inputBytes[0]),
|
|
116
|
+
inputBytes[1],
|
|
117
|
+
unpadBytes(inputBytes[2]),
|
|
118
|
+
unpadBytes(inputBytes[3]),
|
|
119
|
+
unpadBytes(inputBytes[4]),
|
|
120
|
+
unpadBytes(inputBytes[5]),
|
|
121
|
+
];
|
|
122
|
+
const msgHash = eoaCode7702AuthorizationHashedMessageToSign([chainId, address, nonce]);
|
|
123
|
+
const pubKey = ecrecover(msgHash, bytesToBigInt(yParity), r, s);
|
|
124
|
+
return new Address(publicToAddress(pubKey));
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../src/authorization.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAErG,OAAO,EAAE,0BAA0B,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ1C,MAAM,CAAC,MAAM,qCAAqC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;AAEvE;;;;GAIG;AACH,MAAM,UAAU,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,UAAU,CAAC,OAAO,CAAC;QAC5B,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;QAC5B,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC;QACxB,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;QAC5B,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;QAChB,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;KACjB,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2CAA2C,CACzD,iBAAmD;IAEnD,MAAM,cAAc,GA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AAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,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,iBAA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