import "ec/misc.scrypt";import "ec/secp256k1.scrypt"; library Schnorr { static function verify(bytes sig, PubKey pubKey, bytes msg, Point R) : bool { bytes r = sig[0 : 32]; int s = unpack(reverseBytes(sig[32 : 64], 32) + b'00'); int e = unpack(reverseBytes(sha256(r + pubKey + msg), 32) + b'00'); e = SECP256K1.modReduce(e, 115792089237316195423570985008687907852837564279074904382605163141518161494337); Point P = SECP256K1.pubKey2Point(pubKey); Point E = SECP256K1.mulByScalar(P, e); Point A = SECP256K1.addPoints(R, E); Point S = SECP256K1.mulGeneratorByScalar(s); return SECP256K1.comparePoints(S, A); } }