diff --git a/ticc.js b/ticc.js index 391a328..c4c67aa 100644 --- a/ticc.js +++ b/ticc.js @@ -1097,7 +1097,7 @@ class TicCrypto { // hash为64hex字符,sig为128hex字符。返回用hex表达的距离。 if (this.is_signature({ sig: sig }) && this.is_hash({ hash })) { var hashSig = this.hash_easy(sig) // 把签名也转成32字节的哈希,同样长度方便比较 - return new BigInt(hash, 16).subtract(new BigInt(hashSig, 16)).abs().toString(16) + return (BigInt('0x' + hash) - BigInt('0x' + hashSig)).toString(16).replace(/^-/, '') } return null } @@ -1446,6 +1446,7 @@ class TicCrypto { const pIdent = new BigInt('3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c', 16) // prime.add(1).divide(4); var signY = new Number(compressed[1]) - 2 var x = new BigInt(compressed.substr(2), 16) + // 需要用到 big-integer 的 modPow 方法。如果直接用原生的 BigInt 会 "Maximum BigInt size exceeded" var y = x.modPow(3, prime).add(7).mod(prime).modPow(pIdent, prime) // y mod p = +-(x^3 + 7)^((p+1)/4) mod p if (y.mod(2).toJSNumber() !== signY) { // If the parity doesn't match it's the *other* root