From c9220e60b9c51b1ab99d0e459d60882031bb3167 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 12 Dec 2024 00:52:51 +0000 Subject: [PATCH] init --- .../circuits.js/src/types/public_keys.test.ts | 13 +++++++++++++ yarn-project/circuits.js/src/types/public_keys.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuits.js/src/types/public_keys.test.ts b/yarn-project/circuits.js/src/types/public_keys.test.ts index 10dac1f65f70..b4a21a9e2c08 100644 --- a/yarn-project/circuits.js/src/types/public_keys.test.ts +++ b/yarn-project/circuits.js/src/types/public_keys.test.ts @@ -4,6 +4,19 @@ import { updateInlineTestData } from '@aztec/foundation/testing'; import { PublicKeys } from './public_keys.js'; describe('PublicKeys', () => { + it('serialization and deserialization', () => { + const pk = PublicKeys.random(); + const serialized = pk.toString(); + const deserialized = PublicKeys.fromString(serialized); + + expect(pk).toEqual(deserialized); + + const serializedWithoutPrefix = serialized.slice(2); + const deserializedWithoutPrefix = PublicKeys.fromString(serializedWithoutPrefix); + + expect(pk).toEqual(deserializedWithoutPrefix); + }); + it('computes public keys hash', () => { const keys = new PublicKeys( new Point(new Fr(1n), new Fr(2n), false), diff --git a/yarn-project/circuits.js/src/types/public_keys.ts b/yarn-project/circuits.js/src/types/public_keys.ts index d426ab2f3b84..2faa0f7a4887 100644 --- a/yarn-project/circuits.js/src/types/public_keys.ts +++ b/yarn-project/circuits.js/src/types/public_keys.ts @@ -2,7 +2,7 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto'; import { Fr, Point } from '@aztec/foundation/fields'; import { schemas } from '@aztec/foundation/schemas'; import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { bufferToHex } from '@aztec/foundation/string'; +import { bufferToHex, withoutHexPrefix } from '@aztec/foundation/string'; import { type FieldsOf } from '@aztec/foundation/types'; import { z } from 'zod'; @@ -189,6 +189,6 @@ export class PublicKeys { } static fromString(keys: string) { - return PublicKeys.fromBuffer(Buffer.from(keys, 'hex')); + return PublicKeys.fromBuffer(Buffer.from(withoutHexPrefix(keys), 'hex')); } }