Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: serialize public kernel private inputs #5971

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ describe('PublicKernelCircuitPrivateInputs', () => {
expect(original).toEqual(serialized);
expect(original).not.toBe(serialized);
});

it('serializes to and deserializes from a string', () => {
const original = makePublicKernelCircuitPrivateInputs(123);
const serialized = PublicKernelCircuitPrivateInputs.fromString(original.toString());
expect(original).toEqual(serialized);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,47 @@ export class PublicKernelCircuitPrivateInputs {
public readonly publicCall: PublicCallData,
) {}

/**
* Serializes the object to a buffer.
* @returns - Buffer representation of the object.
*/
toBuffer() {
return serializeToBuffer(this.previousKernel, this.publicCall);
}

/**
* Serializes the object to a hex string.
* @returns - Hex string representation of the object.
*/
toString() {
return this.toBuffer().toString('hex');
}

/**
* Deserializes the object from a buffer.
* @param buffer - Buffer to deserialize.
* @returns - Deserialized object.
*/
static fromBuffer(buffer: BufferReader | Buffer) {
const reader = BufferReader.asReader(buffer);
const previousKernel = reader.readObject(PublicKernelData);
const publicCall = reader.readObject(PublicCallData);
return new PublicKernelCircuitPrivateInputs(previousKernel, publicCall);
}

/**
* Deserializes the object from a hex string.
* @param str - Hex string to deserialize.
* @returns - Deserialized object.
*/
static fromString(str: string) {
return PublicKernelCircuitPrivateInputs.fromBuffer(Buffer.from(str, 'hex'));
}

/**
* Clones the object.
* @returns - Cloned object.
*/
clone() {
return PublicKernelCircuitPrivateInputs.fromBuffer(this.toBuffer());
}
Expand Down
Loading