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

signFields does not work with Fields from o1js #1

Open
Pfed-prog opened this issue Mar 20, 2024 · 4 comments
Open

signFields does not work with Fields from o1js #1

Pfed-prog opened this issue Mar 20, 2024 · 4 comments

Comments

@Pfed-prog
Copy link

https://docs.aurowallet.com/general/reference/api-reference/methods/mina_signfields

takes Fields like [1,2,3]

But this is not the way o1js interprets Fields

@Pfed-prog
Copy link
Author

Pfed-prog commented Mar 20, 2024

type SignMessageArgs = {
  message: Field[];
};

const signContent: SignMessageArgs = {
  message: CircuitString.fromString(newMessage).toFields(),
};
const signResult= await window.mina?.signFields({
  message: [signContent.message.toString()],
});

My attempt at merging o1js Fields with BigInt failed so far

@lvshaoping007
Copy link
Collaborator

We currently support (string | number)[]
The result of CircuitString.fromString(newMessage).toFields().toString() is string, so an exception is now returned.

We will add support for toFields().toString() in the next version

type SignedFieldsData = {
   data: (string | number)[] | string;
   publicKey: string;
   signature: string;
};

You can first use the following solution

let signContent = CircuitString.fromString(newMessage).toFields();
let realSignContent = signContent.toString().split(",").map(Number);

const signResult: SignedData | ProviderError = await (window as any)?.mina
        ?.signFields({
          message: realSignContent,
        })
        .catch((err: any) => err);

@Pfed-prog
Copy link
Author

We currently support (string | number)[] The result of CircuitString.fromString(newMessage).toFields().toString() is string, so an exception is now returned.

We will add support for toFields().toString() in the next version

type SignedFieldsData = {
   data: (string | number)[] | string;
   publicKey: string;
   signature: string;
};

You can first use the following solution

let signContent = CircuitString.fromString(newMessage).toFields();
let realSignContent = signContent.toString().split(",").map(Number);

const signResult: SignedData | ProviderError = await (window as any)?.mina
        ?.signFields({
          message: realSignContent,
        })
        .catch((err: any) => err);

thank you so much for providing code, any chance there is a solution for verifying the data on the backend

@lvshaoping007
Copy link
Collaborator

It doesn't matter, I'm happy to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants