Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Dec 12, 2024
1 parent e1e5864 commit c9220e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions yarn-project/circuits.js/src/types/public_keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/types/public_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit c9220e6

Please sign in to comment.