Skip to content

Commit

Permalink
fix: registering PublicDataWitness in JsonRpcServer
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 7, 2024
1 parent 50b559d commit aa1b9c8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { type SequencerConfig } from './configs.js';
import { type L2BlockNumber } from './l2_block_number.js';
import { type NullifierMembershipWitness } from './nullifier_tree.js';
import { type ProverConfig } from './prover-client.js';
import { type PublicDataWitness } from './public_data_tree.js';
import { type PublicDataWitness } from './public_data_witness.js';

/**
* The aztec node.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from './pxe.js';
export * from './sync-status.js';
export * from './configs.js';
export * from './nullifier_tree.js';
export * from './public_data_tree.js';
export * from './public_data_witness.js';
export * from './prover-client.js';
export * from './proving-job.js';
export * from './block-prover.js';
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Fr, type PUBLIC_DATA_TREE_HEIGHT, type PublicDataTreeLeafPreimage } from '@aztec/circuits.js';
import { Fr, type PUBLIC_DATA_TREE_HEIGHT, PublicDataTreeLeafPreimage } from '@aztec/circuits.js';

import { type SiblingPath } from '../sibling_path/index.js';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';

/**
* Public data witness.
Expand Down Expand Up @@ -39,4 +41,43 @@ export class PublicDataWitness {
...this.siblingPath.toFields(),
];
}

toBuffer(): Buffer {
return serializeToBuffer([
this.index,
this.leafPreimage,
this.siblingPath,
]);
}

/**
* Returns a string representation of the TxEffect object.
*/
toString(): string {
return this.toBuffer().toString('hex');
}

/**
* Deserializes an PublicDataWitness object from a buffer.
* @param buf - Buffer to deserialize.
* @returns An instance of PublicDataWitness.
*/
static fromBuffer(buffer: Buffer | BufferReader): PublicDataWitness {
const reader = BufferReader.asReader(buffer);

return new PublicDataWitness(
toBigIntBE(reader.readBytes(32)),
reader.readObject(PublicDataTreeLeafPreimage),
reader.readObject(SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>),
);
}

/**
* Deserializes an PublicDataWitness object from a string.
* @param str - String to deserialize.
* @returns An instance of PublicDataWitness.
*/
static fromString(str: string) {
return PublicDataWitness.fromBuffer(Buffer.from(str, 'hex'));
}
}

0 comments on commit aa1b9c8

Please sign in to comment.