Skip to content

Commit

Permalink
Fix signature size
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Sep 14, 2023
1 parent f5809f4 commit 54e42ff
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EcdsaAuthWitnessProvider implements AuthWitnessProvider {

async createAuthWitness(message: Fr): Promise<AuthWitness> {
const ecdsa = await Ecdsa.new();
const signature = ecdsa.constructSignature(message.toBuffer(), this.signingPrivateKey).toFields();
return new AuthWitness(message, signature);
const signature = ecdsa.constructSignature(message.toBuffer(), this.signingPrivateKey);
return new AuthWitness(message, [...signature.r, ...signature.s]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SchnorrAuthWitnessProvider implements AuthWitnessProvider {

async createAuthWitness(message: Fr): Promise<AuthWitness> {
const schnorr = await Schnorr.new();
const signature = schnorr.constructSignature(message.toBuffer(), this.signingPrivateKey).toFields();
return new AuthWitness(message, signature);
const signature = schnorr.constructSignature(message.toBuffer(), this.signingPrivateKey).toBuffer();
return new AuthWitness(message, [...signature]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SingleKeyAuthWitnessProvider implements AuthWitnessProvider {
const schnorr = await Schnorr.new();
const signature = schnorr.constructSignature(message.toBuffer(), this.privateKey);
const publicKey = await generatePublicKey(this.privateKey);
const witness = [...publicKey.toFields(), ...signature.toFields(), this.partialAddress];
const witness = [...publicKey.toFields(), ...signature.toBuffer(), this.partialAddress];
return new AuthWitness(message, witness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class SchnorrSignature implements Signature {
}

/**
* Converts the signature to an array of fields.
* @returns The signature components as an array of fields
* Converts the signature to an array of three fields.
* @returns The signature components as an array of three fields
*/
toFields(): Fr[] {
const sig = this.toBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ impl AuthWitness {
}

unconstrained fn get_auth_witness(message_hash: Field) -> AuthWitness {
AuthWitness::deserialize(auth_witness::get_auth_witness(message_hash))
let witness: [Field; 67] = auth_witness::get_auth_witness(message_hash);
AuthWitness::deserialize(witness)
}
9 changes: 7 additions & 2 deletions yarn-project/types/src/auth_witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
* An authentication witness. Used to authorise an action by a user.
*/
export class AuthWitness {
/** Authentication witness for the hash */
public readonly witness: Fr[];

constructor(
/** Hash of the request to authorize */
public readonly requestHash: Fr,
/** Authentication witness for the hash */
public readonly witness: Fr[],
) {}
witness: (Fr | number)[],
) {
this.witness = witness.map(x => new Fr(x));
}

toBuffer() {
return serializeToBuffer(this.requestHash, new Vector(this.witness));
Expand Down

0 comments on commit 54e42ff

Please sign in to comment.