#How to sign & verify

10 messages · Page 1 of 1 (latest)

paper cargo
#

The Oracle tutorial (https://docs.minaprotocol.com/zkapps/tutorials/oracle) shows an example on how to verify a pre-created signature. And I found an example on how to sign messages (#1161103584428032080 message), but I can't get those two to play nicely with each other

Is there an example on how to sign any message and verify it immediately?

Here's some of the stuff I've tried so far:

let strData1 = 'a'; //'[1, 787]';
  const fieldStr = BigInt(CircuitString.fromString(strData1).hash());
  const signature = client.signFields([fieldStr], privateKey);

  //   let verified = client.verifyFields({
  //     data: BigInt(CircuitString.fromString(strData1).hash()),
  //     signature: signature.signature,
  //     publicKey: publicKey,
  //   });

  let verified = Signature.fromBase58(signature.signature).verify(
    PublicKey.fromBase58(publicKey),
    ['a']
  );

Website for documentation about Mina Protocol

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

swift vigil
#

ah, so Signature.verify() takes field elements for the message

signature.verify(publicKey, [Field(bigint)])
#

also there's no need/benefit in hashing before signing

#

signature.create() will already hash the message

paper cargo
#

ok that seems to work - easier than I expected. just had to figure out how to convert string to bigint[] - this seems to work: let fields = CircuitString.fromString("a").toFields().map(BigInt)

#

thanks!

orchid monolith
#

CircuitString is depreciated, you can use:

import { Encoding } from "o1js";
const fields: Field[] = Encoding.stringToFields(str);
paper cargo
#

ah, cool. saw that it was deprecated but the suggested alternative was Struct, which I didn't quite understand why.

timid parrot