prividium 0.18.1 → 0.19.1

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.
@@ -10,6 +10,10 @@ export const INTERNAL_RPC_ERROR = -32603;
10
10
  * Invalid Request (-32600). Standard JSON-RPC 2.0 code for malformed requests.
11
11
  */
12
12
  export const INVALID_REQUEST_ERROR_CODE = -32600;
13
+ /**
14
+ * Method not found (-32601). Standard JSON-RPC 2.0 code for unknown/unavailable methods.
15
+ */
16
+ export const METHOD_NOT_FOUND_ERROR_CODE = -32601;
13
17
  /**
14
18
  * Invalid params (-32602). Standard JSON-RPC 2.0 code for bad parameters.
15
19
  */
@@ -1,7 +1,7 @@
1
1
  export { createPrividiumClient } from './create-prividium-client.js';
2
2
  export { type AuthCallbackMessage, handleAuthCallback, type OauthScope, PopupAuth } from './popup-auth.js';
3
3
  export { createPrividiumChain } from './prividium-chain.js';
4
- export { FORBIDDEN_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
4
+ export { FORBIDDEN_ERROR_CODE, METHOD_NOT_FOUND_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
5
5
  export * from './selective-disclosure/index.js';
6
6
  export { LocalStorage, TokenManager } from './storage.js';
7
7
  export { generateRandomState } from './token-utils.js';
package/dist/sdk/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createPrividiumClient } from './create-prividium-client.js';
2
2
  export { handleAuthCallback, PopupAuth } from './popup-auth.js';
3
3
  export { createPrividiumChain } from './prividium-chain.js';
4
- export { FORBIDDEN_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
4
+ export { FORBIDDEN_ERROR_CODE, METHOD_NOT_FOUND_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
5
5
  export * from './selective-disclosure/index.js';
6
6
  export { LocalStorage, TokenManager } from './storage.js';
7
7
  export { generateRandomState } from './token-utils.js';
@@ -10,6 +10,10 @@ export declare const INTERNAL_RPC_ERROR = -32603;
10
10
  * Invalid Request (-32600). Standard JSON-RPC 2.0 code for malformed requests.
11
11
  */
12
12
  export declare const INVALID_REQUEST_ERROR_CODE = -32600;
13
+ /**
14
+ * Method not found (-32601). Standard JSON-RPC 2.0 code for unknown/unavailable methods.
15
+ */
16
+ export declare const METHOD_NOT_FOUND_ERROR_CODE = -32601;
13
17
  /**
14
18
  * Invalid params (-32602). Standard JSON-RPC 2.0 code for bad parameters.
15
19
  */
@@ -10,6 +10,10 @@ export const INTERNAL_RPC_ERROR = -32603;
10
10
  * Invalid Request (-32600). Standard JSON-RPC 2.0 code for malformed requests.
11
11
  */
12
12
  export const INVALID_REQUEST_ERROR_CODE = -32600;
13
+ /**
14
+ * Method not found (-32601). Standard JSON-RPC 2.0 code for unknown/unavailable methods.
15
+ */
16
+ export const METHOD_NOT_FOUND_ERROR_CODE = -32601;
13
17
  /**
14
18
  * Invalid params (-32602). Standard JSON-RPC 2.0 code for bad parameters.
15
19
  */
@@ -28,6 +28,8 @@ export type AccountStorageProofs = {
28
28
  */
29
29
  export type EthCallDisclosureResult = {
30
30
  result: Hex;
31
+ from: Address;
32
+ to: Address;
31
33
  callData: Hex;
32
34
  batchNumber: number;
33
35
  stateCommitmentPreimage: StateCommitmentPreimage;
@@ -5,6 +5,32 @@ import { calculateStateMerkleRoot } from './verifiy-proofs.js';
5
5
  export const DIAMOND_ABI = [
6
6
  parseAbiItem('function storedBatchHash(uint256 _batchNumber) external view returns (bytes32)')
7
7
  ];
8
+ const tracerStr = `{
9
+ prevTop: null,
10
+ state: {
11
+ reads: {},success: null, value: null
12
+ },
13
+ step: function (log, _db) {
14
+ if (log.op.toString() === 'SLOAD') {
15
+ const addr = log.contract.getAddress();
16
+ const slot = this.prevTop;
17
+ if (!this.state.reads[addr]) this.state.reads[addr] = [];
18
+ if (this.state.reads[addr].indexOf(slot) === -1) this.state.reads[addr].push(slot);
19
+ }
20
+
21
+ if (log.stack.length() > 0) {
22
+ this.prevTop = log.stack.peek(0).toString(16);
23
+ } else {
24
+ this.prevTop = null;
25
+ }
26
+ },
27
+ fault: (_log, _db) => {},
28
+ result: function (ctx, _db) {
29
+ this.state.success = ctx.error === null;
30
+ this.state.value = ctx.output.toString('hex');
31
+ return this.state;
32
+ }
33
+ }`;
8
34
  /**
9
35
  * Verifies an ethCall disclosure response end-to-end.
10
36
  *
@@ -60,31 +86,51 @@ export async function verifyEthCallDisclosure(disclosure, l1Client, l2Client, di
60
86
  if (batchInfoHash !== storedBatchHash) {
61
87
  return false;
62
88
  }
63
- // Step 5: Replay the call on L2 with state overrides to verify the proven
64
- // storage values produce the expected result.
65
- const contractAddress = disclosure.proofs[0].address;
66
- const stateOverride = disclosure.proofs.map((proof) => {
89
+ const contractAddress = disclosure.to;
90
+ const stateOverride = {};
91
+ for (const proof of disclosure.proofs) {
67
92
  const address = proof.address.toLowerCase();
68
93
  const code = contractBytecodes[address];
69
94
  if (!code) {
70
95
  throw new Error(`Missing bytecode for contract ${address}`);
71
96
  }
72
- return {
73
- address,
97
+ const state = {};
98
+ for (const sp of proof.storageProofs) {
99
+ state[sp.key] = sp.proof.type === 'existing' ? sp.proof.value : pad('0x0');
100
+ }
101
+ stateOverride[address] = {
74
102
  code,
75
- state: proof.storageProofs.map((sp) => ({
76
- slot: sp.key,
77
- value: sp.proof.type === 'existing' ? sp.proof.value : pad('0x0')
78
- }))
103
+ state: state
79
104
  };
105
+ }
106
+ const debugResult = await l2Client.request({
107
+ method: 'debug_traceCall',
108
+ params: [
109
+ {
110
+ from: disclosure.from,
111
+ to: contractAddress,
112
+ data: disclosure.callData
113
+ },
114
+ 'latest',
115
+ {
116
+ tracer: tracerStr,
117
+ stateOverrides: stateOverride
118
+ }
119
+ ]
80
120
  });
81
- const callResult = await l2Client.call({
82
- to: contractAddress,
83
- data: disclosure.callData,
84
- stateOverride
85
- });
86
- if (!callResult.data) {
121
+ if (!debugResult.success) {
87
122
  return false;
88
123
  }
89
- return BigInt(callResult.data) === BigInt(disclosure.result);
124
+ for (const address in debugResult.reads) {
125
+ for (const slot of debugResult.reads[address]) {
126
+ const realSlot = `0x${slot}`;
127
+ const exists = disclosure.proofs.find((p) => p.address.toLowerCase() === address.toLowerCase() &&
128
+ p.storageProofs.some((sp) => BigInt(sp.key) === BigInt(realSlot)));
129
+ if (!exists) {
130
+ return false;
131
+ }
132
+ }
133
+ }
134
+ const callResult = debugResult.value;
135
+ return BigInt(callResult) === BigInt(disclosure.result);
90
136
  }
@@ -1,6 +1,6 @@
1
1
  export { createPrividiumClient } from './create-prividium-client.js';
2
2
  export { MemoryStorage } from './memory-storage.js';
3
- export { FORBIDDEN_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
3
+ export { FORBIDDEN_ERROR_CODE, METHOD_NOT_FOUND_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
4
4
  export type { SiweAuthConfig } from './siwe-auth.js';
5
5
  export { SiweAuth } from './siwe-auth.js';
6
6
  export type { PrividiumSiweChain, PrividiumSiweConfig } from './siwe-chain.js';
package/dist/sdk/siwe.js CHANGED
@@ -3,7 +3,7 @@
3
3
  export { createPrividiumClient } from './create-prividium-client.js';
4
4
  // Storage (MemoryStorage is the default for SIWE, but expose both + interface)
5
5
  export { MemoryStorage } from './memory-storage.js';
6
- export { FORBIDDEN_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
6
+ export { FORBIDDEN_ERROR_CODE, METHOD_NOT_FOUND_ERROR_CODE, UNAUTHORIZED_ERROR_CODE } from './rpc-error-codes.js';
7
7
  // Auth strategy
8
8
  export { SiweAuth } from './siwe-auth.js';
9
9
  export { createPrividiumSiweChain } from './siwe-chain.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prividium",
3
- "version": "0.18.1",
3
+ "version": "0.19.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "prividium": "bin/cli.js"