@feelyourprotocol/statemanager 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.
Files changed (169) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +331 -0
  3. package/dist/cjs/cache/account.d.ts +85 -0
  4. package/dist/cjs/cache/account.d.ts.map +1 -0
  5. package/dist/cjs/cache/account.js +252 -0
  6. package/dist/cjs/cache/account.js.map +1 -0
  7. package/dist/cjs/cache/cache.d.ts +23 -0
  8. package/dist/cjs/cache/cache.d.ts.map +1 -0
  9. package/dist/cjs/cache/cache.js +31 -0
  10. package/dist/cjs/cache/cache.js.map +1 -0
  11. package/dist/cjs/cache/caches.d.ts +19 -0
  12. package/dist/cjs/cache/caches.d.ts.map +1 -0
  13. package/dist/cjs/cache/caches.js +107 -0
  14. package/dist/cjs/cache/caches.js.map +1 -0
  15. package/dist/cjs/cache/code.d.ts +87 -0
  16. package/dist/cjs/cache/code.d.ts.map +1 -0
  17. package/dist/cjs/cache/code.js +258 -0
  18. package/dist/cjs/cache/code.js.map +1 -0
  19. package/dist/cjs/cache/index.d.ts +7 -0
  20. package/dist/cjs/cache/index.d.ts.map +1 -0
  21. package/dist/cjs/cache/index.js +23 -0
  22. package/dist/cjs/cache/index.js.map +1 -0
  23. package/dist/cjs/cache/originalStorageCache.d.ts +21 -0
  24. package/dist/cjs/cache/originalStorageCache.d.ts.map +1 -0
  25. package/dist/cjs/cache/originalStorageCache.js +52 -0
  26. package/dist/cjs/cache/originalStorageCache.js.map +1 -0
  27. package/dist/cjs/cache/storage.d.ts +101 -0
  28. package/dist/cjs/cache/storage.d.ts.map +1 -0
  29. package/dist/cjs/cache/storage.js +337 -0
  30. package/dist/cjs/cache/storage.js.map +1 -0
  31. package/dist/cjs/cache/types.d.ts +36 -0
  32. package/dist/cjs/cache/types.d.ts.map +1 -0
  33. package/dist/cjs/cache/types.js +8 -0
  34. package/dist/cjs/cache/types.js.map +1 -0
  35. package/dist/cjs/index.d.ts +8 -0
  36. package/dist/cjs/index.d.ts.map +1 -0
  37. package/dist/cjs/index.js +24 -0
  38. package/dist/cjs/index.js.map +1 -0
  39. package/dist/cjs/merkleStateManager.d.ts +260 -0
  40. package/dist/cjs/merkleStateManager.d.ts.map +1 -0
  41. package/dist/cjs/merkleStateManager.js +616 -0
  42. package/dist/cjs/merkleStateManager.js.map +1 -0
  43. package/dist/cjs/package.json +3 -0
  44. package/dist/cjs/proof/index.d.ts +3 -0
  45. package/dist/cjs/proof/index.d.ts.map +1 -0
  46. package/dist/cjs/proof/index.js +19 -0
  47. package/dist/cjs/proof/index.js.map +1 -0
  48. package/dist/cjs/proof/merkle.d.ts +40 -0
  49. package/dist/cjs/proof/merkle.d.ts.map +1 -0
  50. package/dist/cjs/proof/merkle.js +182 -0
  51. package/dist/cjs/proof/merkle.js.map +1 -0
  52. package/dist/cjs/proof/rpc.d.ts +10 -0
  53. package/dist/cjs/proof/rpc.d.ts.map +1 -0
  54. package/dist/cjs/proof/rpc.js +20 -0
  55. package/dist/cjs/proof/rpc.js.map +1 -0
  56. package/dist/cjs/rpcStateManager.d.ts +162 -0
  57. package/dist/cjs/rpcStateManager.d.ts.map +1 -0
  58. package/dist/cjs/rpcStateManager.js +313 -0
  59. package/dist/cjs/rpcStateManager.js.map +1 -0
  60. package/dist/cjs/simpleStateManager.d.ts +54 -0
  61. package/dist/cjs/simpleStateManager.d.ts.map +1 -0
  62. package/dist/cjs/simpleStateManager.js +125 -0
  63. package/dist/cjs/simpleStateManager.js.map +1 -0
  64. package/dist/cjs/statefulBinaryTreeStateManager.d.ts +69 -0
  65. package/dist/cjs/statefulBinaryTreeStateManager.d.ts.map +1 -0
  66. package/dist/cjs/statefulBinaryTreeStateManager.js +576 -0
  67. package/dist/cjs/statefulBinaryTreeStateManager.js.map +1 -0
  68. package/dist/cjs/types.d.ts +92 -0
  69. package/dist/cjs/types.d.ts.map +1 -0
  70. package/dist/cjs/types.js +3 -0
  71. package/dist/cjs/types.js.map +1 -0
  72. package/dist/cjs/util.d.ts +4 -0
  73. package/dist/cjs/util.d.ts.map +1 -0
  74. package/dist/cjs/util.js +21 -0
  75. package/dist/cjs/util.js.map +1 -0
  76. package/dist/esm/cache/account.d.ts +85 -0
  77. package/dist/esm/cache/account.d.ts.map +1 -0
  78. package/dist/esm/cache/account.js +248 -0
  79. package/dist/esm/cache/account.js.map +1 -0
  80. package/dist/esm/cache/cache.d.ts +23 -0
  81. package/dist/esm/cache/cache.d.ts.map +1 -0
  82. package/dist/esm/cache/cache.js +27 -0
  83. package/dist/esm/cache/cache.js.map +1 -0
  84. package/dist/esm/cache/caches.d.ts +19 -0
  85. package/dist/esm/cache/caches.d.ts.map +1 -0
  86. package/dist/esm/cache/caches.js +103 -0
  87. package/dist/esm/cache/caches.js.map +1 -0
  88. package/dist/esm/cache/code.d.ts +87 -0
  89. package/dist/esm/cache/code.d.ts.map +1 -0
  90. package/dist/esm/cache/code.js +254 -0
  91. package/dist/esm/cache/code.js.map +1 -0
  92. package/dist/esm/cache/index.d.ts +7 -0
  93. package/dist/esm/cache/index.d.ts.map +1 -0
  94. package/dist/esm/cache/index.js +7 -0
  95. package/dist/esm/cache/index.js.map +1 -0
  96. package/dist/esm/cache/originalStorageCache.d.ts +21 -0
  97. package/dist/esm/cache/originalStorageCache.d.ts.map +1 -0
  98. package/dist/esm/cache/originalStorageCache.js +48 -0
  99. package/dist/esm/cache/originalStorageCache.js.map +1 -0
  100. package/dist/esm/cache/storage.d.ts +101 -0
  101. package/dist/esm/cache/storage.d.ts.map +1 -0
  102. package/dist/esm/cache/storage.js +333 -0
  103. package/dist/esm/cache/storage.js.map +1 -0
  104. package/dist/esm/cache/types.d.ts +36 -0
  105. package/dist/esm/cache/types.d.ts.map +1 -0
  106. package/dist/esm/cache/types.js +5 -0
  107. package/dist/esm/cache/types.js.map +1 -0
  108. package/dist/esm/index.d.ts +8 -0
  109. package/dist/esm/index.d.ts.map +1 -0
  110. package/dist/esm/index.js +8 -0
  111. package/dist/esm/index.js.map +1 -0
  112. package/dist/esm/merkleStateManager.d.ts +260 -0
  113. package/dist/esm/merkleStateManager.d.ts.map +1 -0
  114. package/dist/esm/merkleStateManager.js +612 -0
  115. package/dist/esm/merkleStateManager.js.map +1 -0
  116. package/dist/esm/package.json +3 -0
  117. package/dist/esm/proof/index.d.ts +3 -0
  118. package/dist/esm/proof/index.d.ts.map +1 -0
  119. package/dist/esm/proof/index.js +3 -0
  120. package/dist/esm/proof/index.js.map +1 -0
  121. package/dist/esm/proof/merkle.d.ts +40 -0
  122. package/dist/esm/proof/merkle.d.ts.map +1 -0
  123. package/dist/esm/proof/merkle.js +175 -0
  124. package/dist/esm/proof/merkle.js.map +1 -0
  125. package/dist/esm/proof/rpc.d.ts +10 -0
  126. package/dist/esm/proof/rpc.d.ts.map +1 -0
  127. package/dist/esm/proof/rpc.js +17 -0
  128. package/dist/esm/proof/rpc.js.map +1 -0
  129. package/dist/esm/rpcStateManager.d.ts +162 -0
  130. package/dist/esm/rpcStateManager.d.ts.map +1 -0
  131. package/dist/esm/rpcStateManager.js +308 -0
  132. package/dist/esm/rpcStateManager.js.map +1 -0
  133. package/dist/esm/simpleStateManager.d.ts +54 -0
  134. package/dist/esm/simpleStateManager.d.ts.map +1 -0
  135. package/dist/esm/simpleStateManager.js +121 -0
  136. package/dist/esm/simpleStateManager.js.map +1 -0
  137. package/dist/esm/statefulBinaryTreeStateManager.d.ts +69 -0
  138. package/dist/esm/statefulBinaryTreeStateManager.d.ts.map +1 -0
  139. package/dist/esm/statefulBinaryTreeStateManager.js +572 -0
  140. package/dist/esm/statefulBinaryTreeStateManager.js.map +1 -0
  141. package/dist/esm/types.d.ts +92 -0
  142. package/dist/esm/types.d.ts.map +1 -0
  143. package/dist/esm/types.js +2 -0
  144. package/dist/esm/types.js.map +1 -0
  145. package/dist/esm/util.d.ts +4 -0
  146. package/dist/esm/util.d.ts.map +1 -0
  147. package/dist/esm/util.js +18 -0
  148. package/dist/esm/util.js.map +1 -0
  149. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  150. package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
  151. package/package.json +74 -0
  152. package/src/cache/account.ts +277 -0
  153. package/src/cache/cache.ts +35 -0
  154. package/src/cache/caches.ts +125 -0
  155. package/src/cache/code.ts +277 -0
  156. package/src/cache/index.ts +6 -0
  157. package/src/cache/originalStorageCache.ts +57 -0
  158. package/src/cache/storage.ts +369 -0
  159. package/src/cache/types.ts +38 -0
  160. package/src/index.ts +7 -0
  161. package/src/merkleStateManager.ts +737 -0
  162. package/src/proof/index.ts +2 -0
  163. package/src/proof/merkle.ts +264 -0
  164. package/src/proof/rpc.ts +24 -0
  165. package/src/rpcStateManager.ts +381 -0
  166. package/src/simpleStateManager.ts +154 -0
  167. package/src/statefulBinaryTreeStateManager.ts +789 -0
  168. package/src/types.ts +103 -0
  169. package/src/util.ts +28 -0
@@ -0,0 +1,40 @@
1
+ import { MerkleStateManager } from '../merkleStateManager.ts';
2
+ import type { Proof, StorageProof } from '@feelyourprotocol/common';
3
+ import type { Address, PrefixedHexString } from '@feelyourprotocol/util';
4
+ import type { MerkleStateManagerOpts } from '../index.ts';
5
+ /**
6
+ * Get an EIP-1186 proof
7
+ * @param address address to get proof of
8
+ * @param storageSlots storage slots to get proof of
9
+ */
10
+ export declare function getMerkleStateProof(sm: MerkleStateManager, address: Address, storageSlots?: Uint8Array[]): Promise<Proof>;
11
+ /**
12
+ * Adds a storage proof to the state manager
13
+ * @param storageProof The storage proof
14
+ * @param storageHash The root hash of the storage trie
15
+ * @param address The address
16
+ * @param safe Whether or not to verify if the reported roots match the current storage root
17
+ */
18
+ export declare function addMerkleStateStorageProof(sm: MerkleStateManager, storageProof: StorageProof[], storageHash: PrefixedHexString, address: Address, safe?: boolean): Promise<void>;
19
+ /**
20
+ * Create a StateManager and initialize this with proof(s) gotten previously from getProof
21
+ * This generates a (partial) StateManager where one can retrieve all items from the proof
22
+ * @param proof Either a proof retrieved from `getProof`, or an array of those proofs
23
+ * @param safe Whether or not to verify that the roots of the proof items match the reported roots
24
+ * @param opts a dictionary of StateManager opts
25
+ * @returns A new MerkleStateManager with elements from the given proof included in its backing state trie
26
+ */
27
+ export declare function fromMerkleStateProof(proof: Proof | Proof[], safe?: boolean, opts?: MerkleStateManagerOpts): Promise<MerkleStateManager>;
28
+ /**
29
+ * Add proof(s) into an already existing trie
30
+ * @param proof The proof(s) retrieved from `getProof`
31
+ * @param verifyRoot verify that all proof root nodes match statemanager's stateroot - should be
32
+ * set to `false` when constructing a state manager where the underlying trie has proof nodes from different state roots
33
+ */
34
+ export declare function addMerkleStateProofData(sm: MerkleStateManager, proof: Proof | Proof[], safe?: boolean): Promise<void>;
35
+ /**
36
+ * Verify an EIP-1186 proof. Throws if proof is invalid, otherwise returns true.
37
+ * @param proof the proof to prove
38
+ */
39
+ export declare function verifyMerkleStateProof(sm: MerkleStateManager, proof: Proof): Promise<boolean>;
40
+ //# sourceMappingURL=merkle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../../src/proof/merkle.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,OAAO,EAChB,YAAY,GAAE,UAAU,EAAO,GAC9B,OAAO,CAAC,KAAK,CAAC,CA0ChB;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,kBAAkB,EACtB,YAAY,EAAE,YAAY,EAAE,EAC5B,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,GAAE,OAAe,iBAWtB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,EACtB,IAAI,GAAE,OAAe,EACrB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,kBAAkB,CAAC,CA8B7B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,EACtB,IAAI,GAAE,OAAe,iBAoBtB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,OAAO,CAAC,CA0ElB"}
@@ -0,0 +1,175 @@
1
+ import { createMPTFromProof, createMerkleProof, updateMPTFromMerkleProof, verifyMerkleProof, } from '@feelyourprotocol/mpt';
2
+ import { RLP } from '@feelyourprotocol/rlp';
3
+ import { EthereumJSErrorWithoutCode, KECCAK256_NULL, KECCAK256_NULL_S, KECCAK256_RLP, KECCAK256_RLP_S, bigIntToHex, bytesToHex, createAccountFromRLP, createAddressFromString, equalsBytes, hexToBytes, setLengthLeft, unpadBytes, } from '@feelyourprotocol/util';
4
+ import { MerkleStateManager } from "../merkleStateManager.js";
5
+ /**
6
+ * Get an EIP-1186 proof
7
+ * @param address address to get proof of
8
+ * @param storageSlots storage slots to get proof of
9
+ */
10
+ export async function getMerkleStateProof(sm, address, storageSlots = []) {
11
+ await sm['flush']();
12
+ const account = await sm.getAccount(address);
13
+ if (!account) {
14
+ const returnValue = {
15
+ address: address.toString(),
16
+ balance: '0x0',
17
+ codeHash: KECCAK256_NULL_S,
18
+ nonce: '0x0',
19
+ storageHash: KECCAK256_RLP_S,
20
+ accountProof: (await createMerkleProof(sm['_trie'], address.bytes)).map((p) => bytesToHex(p)),
21
+ storageProof: [],
22
+ };
23
+ return returnValue;
24
+ }
25
+ const accountProof = (await createMerkleProof(sm['_trie'], address.bytes)).map((p) => bytesToHex(p));
26
+ const storageProof = [];
27
+ const storageTrie = sm['_getStorageTrie'](address, account);
28
+ for (const storageKey of storageSlots) {
29
+ const proof = (await createMerkleProof(storageTrie, storageKey)).map((p) => bytesToHex(p));
30
+ const value = bytesToHex(await sm.getStorage(address, storageKey));
31
+ const proofItem = {
32
+ key: bytesToHex(storageKey),
33
+ value: value === '0x' ? '0x0' : value, // Return '0x' values as '0x0' since this is a JSON RPC response
34
+ proof,
35
+ };
36
+ storageProof.push(proofItem);
37
+ }
38
+ const returnValue = {
39
+ address: address.toString(),
40
+ balance: bigIntToHex(account.balance),
41
+ codeHash: bytesToHex(account.codeHash),
42
+ nonce: bigIntToHex(account.nonce),
43
+ storageHash: bytesToHex(account.storageRoot),
44
+ accountProof,
45
+ storageProof,
46
+ };
47
+ return returnValue;
48
+ }
49
+ /**
50
+ * Adds a storage proof to the state manager
51
+ * @param storageProof The storage proof
52
+ * @param storageHash The root hash of the storage trie
53
+ * @param address The address
54
+ * @param safe Whether or not to verify if the reported roots match the current storage root
55
+ */
56
+ export async function addMerkleStateStorageProof(sm, storageProof, storageHash, address, safe = false) {
57
+ const trie = sm['_getStorageTrie'](address);
58
+ trie.root(hexToBytes(storageHash));
59
+ for (let i = 0; i < storageProof.length; i++) {
60
+ await updateMPTFromMerkleProof(trie, storageProof[i].proof.map((e) => hexToBytes(e)), safe);
61
+ }
62
+ }
63
+ /**
64
+ * Create a StateManager and initialize this with proof(s) gotten previously from getProof
65
+ * This generates a (partial) StateManager where one can retrieve all items from the proof
66
+ * @param proof Either a proof retrieved from `getProof`, or an array of those proofs
67
+ * @param safe Whether or not to verify that the roots of the proof items match the reported roots
68
+ * @param opts a dictionary of StateManager opts
69
+ * @returns A new MerkleStateManager with elements from the given proof included in its backing state trie
70
+ */
71
+ export async function fromMerkleStateProof(proof, safe = false, opts = {}) {
72
+ if (Array.isArray(proof)) {
73
+ if (proof.length === 0) {
74
+ return new MerkleStateManager(opts);
75
+ }
76
+ else {
77
+ const trie = opts.trie ??
78
+ (await createMPTFromProof(proof[0].accountProof.map((e) => hexToBytes(e)), { useKeyHashing: true }));
79
+ const sm = new MerkleStateManager({ ...opts, trie });
80
+ const address = createAddressFromString(proof[0].address);
81
+ await addMerkleStateStorageProof(sm, proof[0].storageProof, proof[0].storageHash, address, safe);
82
+ for (let i = 1; i < proof.length; i++) {
83
+ const proofItem = proof[i];
84
+ await addMerkleStateProofData(sm, proofItem, true);
85
+ }
86
+ await sm.flush(); // TODO verify if this is necessary
87
+ return sm;
88
+ }
89
+ }
90
+ else {
91
+ return fromMerkleStateProof([proof], safe, opts);
92
+ }
93
+ }
94
+ /**
95
+ * Add proof(s) into an already existing trie
96
+ * @param proof The proof(s) retrieved from `getProof`
97
+ * @param verifyRoot verify that all proof root nodes match statemanager's stateroot - should be
98
+ * set to `false` when constructing a state manager where the underlying trie has proof nodes from different state roots
99
+ */
100
+ export async function addMerkleStateProofData(sm, proof, safe = false) {
101
+ if (Array.isArray(proof)) {
102
+ for (let i = 0; i < proof.length; i++) {
103
+ await updateMPTFromMerkleProof(sm['_trie'], proof[i].accountProof.map((e) => hexToBytes(e)), safe);
104
+ await addMerkleStateStorageProof(sm, proof[i].storageProof, proof[i].storageHash, createAddressFromString(proof[i].address), safe);
105
+ }
106
+ }
107
+ else {
108
+ await addMerkleStateProofData(sm, [proof], safe);
109
+ }
110
+ }
111
+ /**
112
+ * Verify an EIP-1186 proof. Throws if proof is invalid, otherwise returns true.
113
+ * @param proof the proof to prove
114
+ */
115
+ export async function verifyMerkleStateProof(sm, proof) {
116
+ const key = hexToBytes(proof.address);
117
+ const accountProof = proof.accountProof.map((rlpString) => hexToBytes(rlpString));
118
+ // This returns the account if the proof is valid.
119
+ // Verify that it matches the reported account.
120
+ const value = await verifyMerkleProof(key, accountProof, {
121
+ useKeyHashing: true,
122
+ });
123
+ if (value === null) {
124
+ // Verify that the account is empty in the proof.
125
+ const emptyBytes = new Uint8Array(0);
126
+ const notEmptyErrorMsg = 'Invalid proof provided: account is not empty';
127
+ const nonce = unpadBytes(hexToBytes(proof.nonce));
128
+ if (!equalsBytes(nonce, emptyBytes)) {
129
+ throw EthereumJSErrorWithoutCode(`${notEmptyErrorMsg} (nonce is not zero)`);
130
+ }
131
+ const balance = unpadBytes(hexToBytes(proof.balance));
132
+ if (!equalsBytes(balance, emptyBytes)) {
133
+ throw EthereumJSErrorWithoutCode(`${notEmptyErrorMsg} (balance is not zero)`);
134
+ }
135
+ const storageHash = hexToBytes(proof.storageHash);
136
+ if (!equalsBytes(storageHash, KECCAK256_RLP)) {
137
+ throw EthereumJSErrorWithoutCode(`${notEmptyErrorMsg} (storageHash does not equal KECCAK256_RLP)`);
138
+ }
139
+ const codeHash = hexToBytes(proof.codeHash);
140
+ if (!equalsBytes(codeHash, KECCAK256_NULL)) {
141
+ throw EthereumJSErrorWithoutCode(`${notEmptyErrorMsg} (codeHash does not equal KECCAK256_NULL)`);
142
+ }
143
+ }
144
+ else {
145
+ const account = createAccountFromRLP(value);
146
+ const { nonce, balance, storageRoot, codeHash } = account;
147
+ const invalidErrorMsg = 'Invalid proof provided:';
148
+ if (nonce !== BigInt(proof.nonce)) {
149
+ throw EthereumJSErrorWithoutCode(`${invalidErrorMsg} nonce does not match`);
150
+ }
151
+ if (balance !== BigInt(proof.balance)) {
152
+ throw EthereumJSErrorWithoutCode(`${invalidErrorMsg} balance does not match`);
153
+ }
154
+ if (!equalsBytes(storageRoot, hexToBytes(proof.storageHash))) {
155
+ throw EthereumJSErrorWithoutCode(`${invalidErrorMsg} storageHash does not match`);
156
+ }
157
+ if (!equalsBytes(codeHash, hexToBytes(proof.codeHash))) {
158
+ throw EthereumJSErrorWithoutCode(`${invalidErrorMsg} codeHash does not match`);
159
+ }
160
+ }
161
+ for (const stProof of proof.storageProof) {
162
+ const storageProof = stProof.proof.map((value) => hexToBytes(value));
163
+ const storageValue = setLengthLeft(hexToBytes(stProof.value), 32);
164
+ const storageKey = hexToBytes(stProof.key);
165
+ const proofValue = await verifyMerkleProof(storageKey, storageProof, {
166
+ useKeyHashing: true,
167
+ });
168
+ const reportedValue = setLengthLeft(RLP.decode(proofValue ?? new Uint8Array(0)), 32);
169
+ if (!equalsBytes(reportedValue, storageValue)) {
170
+ throw EthereumJSErrorWithoutCode(`Reported trie value does not match storage, key: ${stProof.key}, reported: ${bytesToHex(reportedValue)}, actual: ${bytesToHex(storageValue)}`);
171
+ }
172
+ }
173
+ return true;
174
+ }
175
+ //# sourceMappingURL=merkle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../../src/proof/merkle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EACL,0BAA0B,EAC1B,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,GACX,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAM7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAsB,EACtB,OAAgB,EAChB,eAA6B,EAAE;IAE/B,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAA;IACnB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,WAAW,GAAU;YACzB,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;YAC3B,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,gBAAgB;YAC1B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@feelyourprotocol/util';
2
+ import type { Proof, RPCStateManager } from '../index.ts';
3
+ /**
4
+ * Get an EIP-1186 proof from the provider
5
+ * @param address address to get proof of
6
+ * @param storageSlots storage slots to get proof of
7
+ * @returns an EIP-1186 formatted proof
8
+ */
9
+ export declare function getRPCStateProof(sm: RPCStateManager, address: Address, storageSlots?: Uint8Array[]): Promise<Proof>;
10
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/proof/rpc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,eAAe,EACnB,OAAO,EAAE,OAAO,EAChB,YAAY,GAAE,UAAU,EAAO,GAC9B,OAAO,CAAC,KAAK,CAAC,CAQhB"}
@@ -0,0 +1,17 @@
1
+ import { bytesToHex, fetchFromProvider } from '@feelyourprotocol/util';
2
+ /**
3
+ * Get an EIP-1186 proof from the provider
4
+ * @param address address to get proof of
5
+ * @param storageSlots storage slots to get proof of
6
+ * @returns an EIP-1186 formatted proof
7
+ */
8
+ export async function getRPCStateProof(sm, address, storageSlots = []) {
9
+ if (sm['DEBUG'])
10
+ sm['_debug'](`retrieving proof from provider for ${address.toString()}`);
11
+ const proof = await fetchFromProvider(sm['_provider'], {
12
+ method: 'eth_getProof',
13
+ params: [address.toString(), storageSlots.map(bytesToHex), sm['_blockTag']],
14
+ });
15
+ return proof;
16
+ }
17
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/proof/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAKhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,EAAmB,EACnB,OAAgB,EAChB,eAA6B,EAAE;IAE/B,IAAI,EAAE,CAAC,OAAO,CAAC;QAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,sCAAsC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACzF,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE;QACrD,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;KAC5E,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,162 @@
1
+ import { Common } from '@feelyourprotocol/common';
2
+ import { Account } from '@feelyourprotocol/util';
3
+ import { Caches, OriginalStorageCache } from './cache/index.ts';
4
+ import type { AccountFields, StateManagerInterface, StorageDump } from '@feelyourprotocol/common';
5
+ import type { Address } from '@feelyourprotocol/util';
6
+ import type { Debugger } from 'debug';
7
+ import type { RPCStateManagerOpts } from './index.ts';
8
+ export declare class RPCStateManager implements StateManagerInterface {
9
+ protected _provider: string;
10
+ protected _caches: Caches;
11
+ protected _blockTag: string;
12
+ originalStorageCache: OriginalStorageCache;
13
+ protected _debug: Debugger;
14
+ protected DEBUG: boolean;
15
+ private keccakFunction;
16
+ readonly common: Common;
17
+ constructor(opts: RPCStateManagerOpts);
18
+ /**
19
+ * Note that the returned statemanager will share the same JSONRPCProvider as the original
20
+ *
21
+ * @returns RPCStateManager
22
+ */
23
+ shallowCopy(): RPCStateManager;
24
+ /**
25
+ * Sets the new block tag used when querying the provider and clears the
26
+ * internal cache.
27
+ * @param blockTag - the new block tag to use when querying the provider
28
+ */
29
+ setBlockTag(blockTag: bigint | 'earliest'): void;
30
+ /**
31
+ * Clears the internal cache so all accounts, contract code, and storage slots will
32
+ * initially be retrieved from the provider
33
+ */
34
+ clearCaches(): void;
35
+ /**
36
+ * Gets the code corresponding to the provided `address`.
37
+ * @param address - Address to get the `code` for
38
+ * @returns {Promise<Uint8Array>} - Resolves with the code corresponding to the provided address.
39
+ * Returns an empty `Uint8Array` if the account has no associated code.
40
+ */
41
+ getCode(address: Address): Promise<Uint8Array>;
42
+ getCodeSize(address: Address): Promise<number>;
43
+ /**
44
+ * Adds `value` to the state trie as code, and sets `codeHash` on the account
45
+ * corresponding to `address` to reference this.
46
+ * @param address - Address of the `account` to add the `code` for
47
+ * @param value - The value of the `code`
48
+ */
49
+ putCode(address: Address, value: Uint8Array): Promise<void>;
50
+ /**
51
+ * Gets the storage value associated with the provided `address` and `key`. This method returns
52
+ * the shortest representation of the stored value.
53
+ * @param address - Address of the account to get the storage for
54
+ * @param key - Key in the account's storage to get the value for. Must be 32 bytes long.
55
+ * @returns {Uint8Array} - The storage value for the account
56
+ * corresponding to the provided address at the provided key.
57
+ * If this does not exist an empty `Uint8Array` is returned.
58
+ */
59
+ getStorage(address: Address, key: Uint8Array): Promise<Uint8Array>;
60
+ /**
61
+ * Adds value to the cache for the `account`
62
+ * corresponding to `address` at the provided `key`.
63
+ * @param address - Address to set a storage value for
64
+ * @param key - Key to set the value at. Must be 32 bytes long.
65
+ * @param value - Value to set at `key` for account corresponding to `address`.
66
+ * Cannot be more than 32 bytes. Leading zeros are stripped.
67
+ * If it is empty or filled with zeros, deletes the value.
68
+ */
69
+ putStorage(address: Address, key: Uint8Array, value: Uint8Array): Promise<void>;
70
+ /**
71
+ * Clears all storage entries for the account corresponding to `address`.
72
+ * @param address - Address to clear the storage of
73
+ */
74
+ clearStorage(address: Address): Promise<void>;
75
+ /**
76
+ * Dumps the RLP-encoded storage values for an `account` specified by `address`.
77
+ * @param address - The address of the `account` to return storage for
78
+ * @returns {Promise<StorageDump>} - The state of the account as an `Object` map.
79
+ * Keys are the storage keys, values are the storage values as strings.
80
+ * Both are represented as `0x` prefixed hex strings.
81
+ */
82
+ dumpStorage(address: Address): Promise<StorageDump>;
83
+ /**
84
+ * Gets the account associated with `address` or `undefined` if account does not exist
85
+ * @param address - Address of the `account` to get
86
+ */
87
+ getAccount(address: Address): Promise<Account | undefined>;
88
+ /**
89
+ * Retrieves an account from the provider and stores in the local trie
90
+ * @param address Address of account to be retrieved from provider
91
+ * @private
92
+ */
93
+ getAccountFromProvider(address: Address): Promise<Account>;
94
+ /**
95
+ * Saves an account into state under the provided `address`.
96
+ * @param address - Address under which to store `account`
97
+ * @param account - The account to store
98
+ */
99
+ putAccount(address: Address, account: Account | undefined): Promise<void>;
100
+ /**
101
+ * Gets the account associated with `address`, modifies the given account
102
+ * fields, then saves the account into state. Account fields can include
103
+ * `nonce`, `balance`, `storageRoot`, and `codeHash`.
104
+ * @param address - Address of the account to modify
105
+ * @param accountFields - Object containing account fields and values to modify
106
+ */
107
+ modifyAccountFields(address: Address, accountFields: AccountFields): Promise<void>;
108
+ /**
109
+ * Deletes an account from state under the provided `address`.
110
+ * @param address - Address of the account which should be deleted
111
+ */
112
+ deleteAccount(address: Address): Promise<void>;
113
+ /**
114
+ * Returns the applied key for a given address
115
+ * Used for saving preimages
116
+ * @param address - The address to return the applied key
117
+ * @returns {Uint8Array} - The applied key (e.g. hashed address)
118
+ */
119
+ getAppliedKey(address: Uint8Array): Uint8Array;
120
+ /**
121
+ * Checkpoints the current state of the StateManager instance.
122
+ * State changes that follow can then be committed by calling
123
+ * `commit` or `reverted` by calling rollback.
124
+ */
125
+ checkpoint(): Promise<void>;
126
+ /**
127
+ * Commits the current change-set to the instance since the
128
+ * last call to checkpoint.
129
+ *
130
+ * Partial implementation, called from the subclass.
131
+ */
132
+ commit(): Promise<void>;
133
+ /**
134
+ * Reverts the current change-set to the instance since the
135
+ * last call to checkpoint.
136
+ *
137
+ * Partial implementation , called from the subclass.
138
+ */
139
+ revert(): Promise<void>;
140
+ flush(): Promise<void>;
141
+ /**
142
+ * @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
143
+ */
144
+ getStateRoot: () => Promise<Uint8Array<ArrayBuffer>>;
145
+ /**
146
+ * @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
147
+ */
148
+ setStateRoot: (_root: Uint8Array) => Promise<void>;
149
+ /**
150
+ * @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
151
+ */
152
+ hasStateRoot: () => never;
153
+ }
154
+ export declare class RPCBlockChain {
155
+ readonly provider: string;
156
+ constructor(provider: string);
157
+ getBlock(blockId: number): Promise<{
158
+ hash: () => Uint8Array<ArrayBufferLike>;
159
+ }>;
160
+ shallowCopy(): this;
161
+ }
162
+ //# sourceMappingURL=rpcStateManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcStateManager.d.ts","sourceRoot":"","sources":["../../src/rpcStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAW,MAAM,oBAAoB,CAAA;AAEpD,OAAO,EACL,OAAO,EAYR,MAAM,kBAAkB,CAAA;AAIzB,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAG/D,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC3F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAIrD,qBAAa,eAAgB,YAAW,qBAAqB;IAC3D,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAA;IAC1B,SAAS,CA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