Skip to content

Instantly share code, notes, and snippets.

@hcheng826
Last active December 8, 2022 07:00
Show Gist options
  • Save hcheng826/c494f639a7646f1758e0b6fab8c6d3d3 to your computer and use it in GitHub Desktop.
Save hcheng826/c494f639a7646f1758e0b6fab8c6d3d3 to your computer and use it in GitHub Desktop.
let elliptic = require("elliptic");
let sha3 = require("js-sha3");
let ec = new elliptic.ec("secp256k1");
const y_sum_s = [
2, 105, 56, 31, 30, 34, 155, 165, 65, 238, 163, 12, 224, 138, 193, 138, 163,
33, 108, 184, 199, 29, 146, 179, 134, 203, 218, 180, 48, 140, 69, 88, 38,
];
const compressed = Buffer.from(y_sum).toString("hex");
const pubKey = Buffer.from(compressed, "hex");
const pk = ec.keyFromPublic(pubKey);
const sigRaw = {
r: {
curve: "secp256k1",
scalar: [
247, 64, 179, 61, 87, 30, 200, 144, 71, 143, 209, 207, 74, 220, 49, 28,
187, 187, 198, 208, 114, 175, 178, 139, 60, 26, 33, 238, 187, 162, 168,
167,
],
},
s: {
curve: "secp256k1",
scalar: [
121, 27, 184, 36, 65, 158, 251, 177, 93, 95, 2, 218, 214, 118, 43, 150,
98, 242, 90, 0, 126, 3, 150, 149, 195, 216, 146, 163, 116, 13, 100, 120,
],
},
recid: 1,
};
const sig = {
r: Buffer.from(sigRaw.r.scalar).toString("hex"),
s: Buffer.from(sigRaw.s.scalar).toString("hex")
};
const msg = "hello";
const result = pk.verify(Buffer.from(sha3.keccak256(msg), "hex"), sig);
console.log(result);
@hcheng826
Copy link
Author

It will give false in the end 😥

  1. Got the y_sum_s value from the generated local-share.json (The value is identical across all shares)
  2. Got the signature value from the gg20_signing command
    image

@iamnivekx
Copy link

the msg is wrong

const msg = "68656c6c6f";
const result = pk.verify(Buffer.from(msg, "hex"), sig);

@hcheng826
Copy link
Author

Thanks for the comment! I am not changing the original copy. Leaving the fix for processing raw message here

const msg = "hello";
const msgHex = Buffer.from(msg).toString("hex");
const result = pk.verify(Buffer.from(msgHex, "hex"), sig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment