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

PublicKeys.toString does not produce the same format expected by PublicKeys.fromString #10622

Closed
FilipHarald opened this issue Dec 11, 2024 · 1 comment · Fixed by #10647
Closed
Assignees
Labels
from-community This originated from the community :)

Comments

@FilipHarald
Copy link
Contributor

This is not a bug, it's just a bit unintuitive that below code produce an error. I only tested this on 0.66.0.

import {PublicKeys} from "@aztec/aztec.js";
const pk = PublicKeys.random();
const pk2 = PublicKeys.fromString(pk.toString());

Error:

file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/serialize/buffer_reader.js:298
        throw new Error(`Attempted to read beyond buffer length. Start index: ${this.index}, Num bytes to read: ${numBytes}, Buffer length: ${this.buffer.length}`);
              ^

Error: Attempted to read beyond buffer length. Start index: 0, Num bytes to read: 32, Buffer length: 0
    at BufferReader._BufferReader_rangeCheck (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/serialize/buffer_reader.js:298:15)
    at BufferReader.readBytes (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/serialize/buffer_reader.js:127:94)
    at fromBuffer (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/fields/fields.js:118:25)
    at Fr.fromBuffer (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/fields/fields.js:171:16)
    at Point.fromBuffer (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/fields/point.js:68:28)
    at BufferReader.readObject (file:///home/filip/c/tonatiu/node_modules/@aztec/foundation/dest/serialize/buffer_reader.js:226:29)
    at PublicKeys.fromBuffer (file:///home/filip/c/tonatiu/node_modules/@aztec/circuits.js/dest/types/public_keys.js:95:49)
    at PublicKeys.fromString (file:///home/filip/c/tonatiu/node_modules/@aztec/circuits.js/dest/types/public_keys.js:139:27)
    at file:///home/filip/c/tonatiu/services/aztec-scraper/build/src/index.js:7:24

Node.js v18.18.2
@FilipHarald
Copy link
Contributor Author

The reason it's not working is that fromString does not expect a value prepended with "0x". So the following code will work:

import {PublicKeys} from "@aztec/aztec.js";
const pk = PublicKeys.random();
const pk2 = PublicKeys.fromString(pk.toString().slice(2));

@iAmMichaelConnor iAmMichaelConnor added the from-community This originated from the community :) label Dec 11, 2024
@sklppy88 sklppy88 self-assigned this Dec 12, 2024
@sklppy88 sklppy88 linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from-community This originated from the community :)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants