Skip to content

Commit

Permalink
Fix missing serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 29, 2024
1 parent 5a0c824 commit 98e8690
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/cl

import { ContractData, ExtendedContractData } from '../../contract_data.js';
import { AztecNode } from '../../interfaces/aztec-node.js';
import { NullifierMembershipWitness } from '../../interfaces/nullifier_tree.js';
import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js';
import { L2Block } from '../../l2_block.js';
import { L2Tx } from '../../l2_tx.js';
Expand Down Expand Up @@ -40,7 +41,7 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN
SiblingPath,
L1ToL2MessageAndIndex,
},
{ Tx, L2BlockL2Logs },
{ Tx, L2BlockL2Logs, NullifierMembershipWitness },
false,
'node',
fetch,
Expand Down
16 changes: 16 additions & 0 deletions yarn-project/circuit-types/src/interfaces/nullifier_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,20 @@ export class NullifierMembershipWitness {
public toFields(): Fr[] {
return [new Fr(this.index), ...this.leafPreimage.toFields(), ...this.siblingPath.toFields()];
}

public toJSON() {
return {
index: '0x' + this.index.toString(16),
leafPreimage: this.leafPreimage.toJSON(),
siblingPath: this.siblingPath.toString(),
};
}

static fromJSON(json: any): NullifierMembershipWitness {
return new NullifierMembershipWitness(
BigInt(json.index),
NullifierLeafPreimage.fromJSON(json.leafPreimage),
SiblingPath.fromString<typeof NULLIFIER_TREE_HEIGHT>(json.siblingPath),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage {
return new NullifierLeafPreimage(this.nullifier, this.nextNullifier, this.nextIndex);
}

toJSON() {
return {
nullifier: this.nullifier.toString(),
nextNullifier: this.nextNullifier.toString(),
nextIndex: '0x' + this.nextIndex.toString(16),
};
}

static empty(): NullifierLeafPreimage {
return new NullifierLeafPreimage(Fr.ZERO, Fr.ZERO, 0n);
}
Expand All @@ -76,6 +84,14 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage {
static clone(preimage: NullifierLeafPreimage): NullifierLeafPreimage {
return new NullifierLeafPreimage(preimage.nullifier, preimage.nextNullifier, preimage.nextIndex);
}

static fromJSON(json: any): NullifierLeafPreimage {
return new NullifierLeafPreimage(
Fr.fromString(json.nullifier),
Fr.fromString(json.nextNullifier),
BigInt(json.nextIndex),
);
}
}

/**
Expand Down

0 comments on commit 98e8690

Please sign in to comment.