Using up to date libraries for EC and BigNumber

This commit is contained in:
Jør∂¡
2021-02-04 14:03:32 +01:00
parent fc74a782e3
commit 1c8f9e6ffe
4 changed files with 222 additions and 123 deletions

View File

@@ -1,18 +1,27 @@
import * as assert from 'assert'
import * as BigInteger from 'bigi'
// import { Point } from 'ecurve'
import { keccak256 } from "@ethersproject/keccak256"
import { newBigFromString, ecparams, newKeyPair, newRequestParameters, blind, blindSign, unblind, verify } from "../src/index"
import {
bigNumberFromString,
ecParams,
newKeyPair,
newRequestParameters,
blind,
blindSign,
unblind,
verify,
hashBigNumber,
Point,
BigNumber
} from "../src/index"
describe("keccak256", function () {
it("keccak256", async () => {
const m = BigInteger.fromBuffer(Buffer.from("test", 'utf8'))
const mHex = m.toString(16)
const hHex = keccak256('0x' + mHex)
assert.strictEqual('0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658', hHex)
const h = BigInteger.fromHex(hHex.slice(2))
assert.strictEqual('70622639689279718371527342103894932928233838121221666359043189029713682937432', h.toString())
const msg = Buffer.from("test", 'utf8')
const m = new BigNumber(msg)
const hHex = hashBigNumber(m)
assert.strictEqual(hHex, '9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658')
const h = new BigNumber(Buffer.from(hHex, "hex"))
assert.strictEqual(h.toString(), '70622639689279718371527342103894932928233838121221666359043189029713682937432')
})
})
@@ -22,7 +31,7 @@ describe("test blind", function () {
const { k, signerR } = newRequestParameters()
const msg = BigInteger.fromBuffer(
const msg = new BigNumber(
Buffer.from("test", 'utf8')
)
assert.strictEqual('1952805748', msg.toString())