Skip to content

Commit

Permalink
🍴 Make verifyFields consume the Point publicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Aug 20, 2024
1 parent e449f82 commit 1ced555
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions crypto/minaSchnorr.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const signFields = (fields, privKey, pubKey) => {
* @param {!Array<bigint>} fields
* @param {bigint} r
* @param {bigint} s
* @param {!Point} pubKey
* @param {!Point} pubKey which is modified during the verification
*/
const verifyFields = (fields, r, s, pubKey) => {
/**
Expand All @@ -100,7 +100,7 @@ const verifyFields = (fields, r, s, pubKey) => {
* s.G = K + pubKey.e
* @const {!Point}
*/
const K = G.copy().multiply(s).increment(pubKey.copy().multiply(ne)).project();
const K = G.copy().multiply(s).increment(pubKey.multiply(ne)).project();
return (K.y & 1n) == 0n && K.x == r;
}

Expand Down Expand Up @@ -154,10 +154,12 @@ const signMessage = (message, privKey, pubKey) => {
}

/**
* Modifies the `pubKey` parameter.
*
* @param {string} message
* @param {bigint} r
* @param {bigint} s
* @param {!Point} pubKey
* @param {!Point} pubKey which is modified during verification
*/
const verifyMessage = (message, r, s, pubKey) => {
/**
Expand All @@ -169,7 +171,7 @@ const verifyMessage = (message, r, s, pubKey) => {
* s.G = K + pubKey.e
* @const {!Point}
*/
const K = G.copy().multiply(s).increment(pubKey.copy().multiply(ne)).project();
const K = G.copy().multiply(s).increment(pubKey.multiply(ne)).project();
return (K.y & 1n) == 0n && K.x == r;
}

Expand Down
5 changes: 1 addition & 4 deletions crypto/modular.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,15 @@ const tonelliShanks = (n, P, Q, c, M) => {
let t = exp(n, (Q - 1n) >> 1n, P);
/** @type {bigint} */
let R = t * n % P;
t = t * R % P;
for (; t != 1n;) {
for (t = t * R % P; t != 1n; t = t * c % P) {
let i = 0n;
for (let tt = t; tt != 1n; ++i)
tt = tt * tt % P;

if (i == M) return null; // n is not a quadratic residue
/** @type {bigint} */
let b = exp(c, 1n << (M - i - 1n), P);
M = i;
c = b * b % P;
t *= c; t %= P;
R *= b; R %= P;
}
return R;
Expand Down

0 comments on commit 1ced555

Please sign in to comment.