mcl ; A portable and fast pairing-based cryptography library for Node.js by WebAssembly
npm install mcl-wasm
{G1,G2}::isValidOrder()
v0.6.0 breaks backward compatibility of the entry point.
const mcl = require('mcl-wasm')
const mcl = require('mcl-wasm')
node test/test.js
`
browser demo
ID-based encryption
usages
init
`
// Ethereum 2.0 spec mode
mcl.init(mcl.BLS12_381)
.then(() => {
mcl.setETHserialization(true) // Ethereum serialization
mcl.setMapToMode(mcl.IRTF) // for G2.setHashOf(msg)
...
})
`
string conversion
`
a = new mcl.Fr()
a.setStr('255') // set 255
a.setStr('0xff') // set 0xff = 255
a.setStr('ff', 16) // set ff as hex-string
a.getStr() // '255'
a.getStr(16) // 'ff'
`
serialization
`
// byte array serialization
b.deserialize(a.serialize()) // b.isEqualTo(a)
// hex string of serialization()
b.deserializeHexStr(a.serializeToHexStr())
`
`
// serialization like Ethereum 2.0 only for BLS12-381
mcl.setETHserialization(true)
`
deserialization
`
/*
it is big cost to to verify the order
call once after init() if you want to disable it
cf. sub group problem
*/
mcl.verifyOrderG1(false)
mcl.verifyOrderG2(false)
`
see test.js
Secret Sharing
`typescript
shareFr = (cVec: Fr[], id: Fr): Fr
shareG1 = (cVec: G1[], id: Fr): G1
shareG2 = (cVec: G2[], id: Fr): G2
`
Evaluate the value of the polynomial f(x) whose coefficients cVec[] are vec with x=id.
Return f(id).
`typescript
recoverFr = (idVec: Fr[], yVec: Fr[]): Fr
recoverG1 = (idVec: Fr[], yVec: G1[]): G1
recoverG2 = (idVec: Fr[], yVec: G2[]): G2
`
Recover the polynomial f(x) through the point (idVec[0], yVec[0]), (idVec[1], yVec[1]), ... and return f(0)`.