Comparing version 0.0.0 to 0.0.1
@@ -6,25 +6,2 @@ function getValue(name) { return document.getElementsByName(name)[0].value } | ||
function setupWasm(fileName, nameSpace, setupFct) { | ||
console.log('setupWasm ' + fileName) | ||
let mod = {} | ||
fetch(fileName) | ||
.then(response => response.arrayBuffer()) | ||
.then(buffer => new Uint8Array(buffer)) | ||
.then(binary => { | ||
mod['wasmBinary'] = binary | ||
mod['onRuntimeInitialized'] = function() { | ||
setupFct(mod, nameSpace) | ||
console.log('setupWasm end') | ||
} | ||
Module(mod) | ||
}) | ||
return mod | ||
} | ||
const MCLBN_CURVE_FP254BNB = 0 | ||
const MCLBN_CURVE_FP382_1 = 1 | ||
const MCLBN_CURVE_FP382_2 = 2 | ||
const MCLBN_FP_UNIT_SIZE = 6 | ||
let moduleInited = false | ||
@@ -34,3 +11,3 @@ | ||
define_exported_bls(mod) | ||
define_extra_functions(mod) | ||
define_bls_extra_functions(mod) | ||
moduleInited = true | ||
@@ -40,204 +17,2 @@ onChangeSelectCurve() | ||
function define_extra_functions(mod) { | ||
wrap_outputString = function(func, doesReturnString = true) { | ||
return function(x, ioMode = 0) { | ||
let maxBufSize = 2048 | ||
let stack = mod.Runtime.stackSave() | ||
let pos = mod.Runtime.stackAlloc(maxBufSize) | ||
let n = func(pos, maxBufSize, x, ioMode) | ||
if (n < 0) { | ||
throw('err gen_str:' + x) | ||
} | ||
if (doesReturnString) { | ||
let s = '' | ||
for (let i = 0; i < n; i++) { | ||
s += String.fromCharCode(mod.HEAP8[pos + i]) | ||
} | ||
mod.Runtime.stackRestore(stack) | ||
return s | ||
} else { | ||
let a = new Uint8Array(n) | ||
for (let i = 0; i < n; i++) { | ||
a[i] = mod.HEAP8[pos + i] | ||
} | ||
mod.Runtime.stackRestore(stack) | ||
return a | ||
} | ||
} | ||
} | ||
wrap_outputArray = function(func) { | ||
return wrap_outputString(func, false) | ||
} | ||
wrap_input0 = function(func, returnValue = false) { | ||
return function(buf, ioMode = 0) { | ||
let stack = mod.Runtime.stackSave() | ||
let pos = mod.Runtime.stackAlloc(buf.length) | ||
if (typeof(buf) == "string") { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf.charCodeAt(i) | ||
} | ||
} else { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf[i] | ||
} | ||
} | ||
let r = func(pos, buf.length, ioMode) | ||
mod.Runtime.stackRestore(stack) | ||
if (returnValue) return r | ||
if (r) throw('err wrap_input0 ' + buf) | ||
} | ||
} | ||
wrap_input1 = function(func, returnValue = false) { | ||
return function(x1, buf, ioMode = 0) { | ||
let stack = mod.Runtime.stackSave() | ||
let pos = mod.Runtime.stackAlloc(buf.length) | ||
if (typeof(buf) == "string") { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf.charCodeAt(i) | ||
} | ||
} else { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf[i] | ||
} | ||
} | ||
let r = func(x1, pos, buf.length, ioMode) | ||
mod.Runtime.stackRestore(stack) | ||
if (returnValue) return r | ||
if (r) throw('err wrap_input1 ' + buf) | ||
} | ||
} | ||
wrap_input2 = function(func, returnValue = false) { | ||
return function(x1, x2, buf, ioMode = 0) { | ||
let stack = mod.Runtime.stackSave() | ||
let pos = mod.Runtime.stackAlloc(buf.length) | ||
if (typeof(buf) == "string") { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf.charCodeAt(i) | ||
} | ||
} else { | ||
for (let i = 0; i < buf.length; i++) { | ||
mod.HEAP8[pos + i] = buf[i] | ||
} | ||
} | ||
let r = func(x1, x2, pos, buf.length, ioMode) | ||
mod.Runtime.stackRestore(stack) | ||
if (returnValue) return r | ||
if (r) throw('err wrap_input2 ' + buf) | ||
} | ||
} | ||
wrap_keyShare = function(func, dataSize) { | ||
return function(x, vec, id) { | ||
let k = vec.length | ||
let p = mod._malloc(dataSize * k) | ||
for (let i = 0; i < k; i++) { | ||
mod._memcpy(p + i * dataSize, vec[i], dataSize) | ||
} | ||
let r = func(x, p, k, id) | ||
mod._free(p) | ||
if (r) throw('keyShare ' + k) | ||
} | ||
} | ||
wrap_recover = function(func, dataSize, idDataSize) { | ||
return function(x, vec, idVec) { | ||
let n = vec.length | ||
let p = mod._malloc(dataSize * n) | ||
let q = mod._malloc(idDataSize * n) | ||
for (let i = 0; i < n; i++) { | ||
mod._memcpy(p + i * dataSize, vec[i], dataSize) | ||
mod._memcpy(q + i * idDataSize, idVec[i], idDataSize) | ||
} | ||
let r = func(x, p, q, n) | ||
mod._free(q) | ||
mod._free(p) | ||
if (r) throw('recover ' + n) | ||
} | ||
} | ||
/////////////////////////////////////////////////////////////// | ||
const FR_SIZE = MCLBN_FP_UNIT_SIZE * 8 | ||
const G1_SIZE = FR_SIZE * 3 | ||
const G2_SIZE = FR_SIZE * 3 * 2 | ||
const GT_SIZE = FR_SIZE * 12 | ||
const ID_SIZE = FR_SIZE | ||
const SECRETKEY_SIZE = FR_SIZE | ||
const PUBLICKEY_SIZE = G2_SIZE | ||
const SIGNATURE_SIZE = G1_SIZE | ||
mclBnFr_malloc = function() { | ||
return mod._malloc(FR_SIZE) | ||
} | ||
mcl_free = function(x) { | ||
mod._free(x) | ||
} | ||
mclBnFr_deserialize = wrap_input1(_mclBnFr_deserialize) | ||
mclBnFr_setLittleEndian = wrap_input1(_mclBnFr_setLittleEndian) | ||
mclBnFr_setStr = wrap_input1(_mclBnFr_setStr) | ||
mclBnFr_getStr = wrap_outputString(_mclBnFr_getStr) | ||
mclBnFr_setHashOf = wrap_input1(_mclBnFr_setHashOf) | ||
/////////////////////////////////////////////////////////////// | ||
mclBnG1_malloc = function() { | ||
return mod._malloc(G1_SIZE) | ||
} | ||
mclBnG1_setStr = wrap_input1(_mclBnG1_setStr) | ||
mclBnG1_getStr = wrap_outputString(_mclBnG1_getStr) | ||
mclBnG1_deserialize = wrap_input1(_mclBnG1_deserialize) | ||
mclBnG1_serialize = wrap_outputArray(_mclBnG1_serialize) | ||
mclBnG1_hashAndMapTo = wrap_input1(_mclBnG1_hashAndMapTo) | ||
/////////////////////////////////////////////////////////////// | ||
mclBnG2_malloc = function() { | ||
return mod._malloc(G2_SIZE) | ||
} | ||
mclBnG2_setStr = wrap_input1(_mclBnG2_setStr) | ||
mclBnG2_getStr = wrap_outputString(_mclBnG2_getStr) | ||
mclBnG2_deserialize = wrap_input1(_mclBnG2_deserialize) | ||
mclBnG2_serialize = wrap_outputArray(_mclBnG2_serialize) | ||
mclBnG2_hashAndMapTo = wrap_input1(_mclBnG2_hashAndMapTo) | ||
/////////////////////////////////////////////////////////////// | ||
mclBnGT_malloc = function() { | ||
return mod._malloc(GT_SIZE) | ||
} | ||
mclBnGT_deserialize = wrap_input1(_mclBnGT_deserialize) | ||
mclBnGT_serialize = wrap_outputArray(_mclBnGT_serialize) | ||
mclBnGT_setStr = wrap_input1(_mclBnGT_setStr) | ||
mclBnGT_getStr = wrap_outputString(_mclBnGT_getStr) | ||
/////////////////////////////////////////////////////////////// | ||
bls_free = mcl_free | ||
blsId_malloc = mclBnFr_malloc | ||
blsSecretKey_malloc = mclBnFr_malloc | ||
blsPublicKey_malloc = mclBnG2_malloc | ||
blsSignature_malloc = mclBnG1_malloc | ||
blsGetCurveOrder = wrap_outputString(_blsGetCurveOrder) | ||
blsGetFieldOrder = wrap_outputString(_blsGetFieldOrder) | ||
blsIdSetDecStr = wrap_input1(_blsIdSetDecStr) | ||
blsIdSetHexStr = wrap_input1(_blsIdSetHexStr) | ||
blsIdGetDecStr = wrap_outputArray(_blsIdGetDecStr) | ||
blsIdGetHexStr = wrap_outputArray(_blsIdGetHexStr) | ||
blsIdSerialize = wrap_outputArray(_blsIdSerialize) | ||
blsSecretKeySerialize = wrap_outputArray(_blsSecretKeySerialize) | ||
blsPublicKeySerialize = wrap_outputArray(_blsPublicKeySerialize) | ||
blsSignatureSerialize = wrap_outputArray(_blsSignatureSerialize) | ||
blsIdDeserialize = wrap_input1(_blsIdDeserialize) | ||
blsSecretKeyDeserialize = wrap_input1(_blsSecretKeyDeserialize) | ||
blsPublicKeyDeserialize = wrap_input1(_blsPublicKeyDeserialize) | ||
blsSignatureDeserialize = wrap_input1(_blsSignatureDeserialize) | ||
blsHashToSecretKey = wrap_input1(_blsHashToSecretKey) | ||
blsSign = wrap_input2(_blsSign) | ||
blsVerify = wrap_input2(_blsVerify, true) | ||
blsSecretKeyShare = wrap_keyShare(_blsSecretKeyShare, SECRETKEY_SIZE) | ||
blsPublicKeyShare = wrap_keyShare(_blsPublicKeyShare, PUBLICKEY_SIZE) | ||
blsSecretKeyRecover = wrap_recover(_blsSecretKeyRecover, SECRETKEY_SIZE, ID_SIZE) | ||
blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, PUBLICKEY_SIZE, ID_SIZE) | ||
blsSignatureRecover = wrap_recover(_blsSignatureRecover, SIGNATURE_SIZE, ID_SIZE) | ||
} | ||
function putId(x, msg = "") { | ||
@@ -265,3 +40,3 @@ console.log(msg + ' id=' + Uint8ArrayToHexString(blsIdSerialize(x))) | ||
console.log('idx=' + idx) | ||
let r = blsInit(idx, MCLBN_FP_UNIT_SIZE) | ||
let r = blsInit(idx) | ||
setText('status', r ? 'err:' + r : 'ok') | ||
@@ -268,0 +43,0 @@ setText('curveOrder', blsGetCurveOrder()) |
function define_exported_bls(mod) { | ||
blsInit = mod.cwrap('blsInit', 'number', ['number', 'number', ]) | ||
blsInitNotThreadSafe = mod.cwrap('blsInitNotThreadSafe', 'number', ['number', 'number', ]) | ||
_blsInit = mod.cwrap('blsInit', 'number', ['number', 'number', ]) | ||
_blsInitNotThreadSafe = mod.cwrap('blsInitNotThreadSafe', 'number', ['number', 'number', ]) | ||
blsGetOpUnitSize = mod.cwrap('blsGetOpUnitSize', 'number', []) | ||
@@ -54,3 +54,3 @@ _blsGetCurveOrder = mod.cwrap('blsGetCurveOrder', 'number', ['number', 'number', ]) | ||
mclBn_setErrFile = mod.cwrap('mclBn_setErrFile', 'number', ['number', ]) | ||
mclBn_init = mod.cwrap('mclBn_init', 'number', ['number', 'number', ]) | ||
_mclBn_init = mod.cwrap('mclBn_init', 'number', ['number', 'number', ]) | ||
mclBn_getOpUnitSize = mod.cwrap('mclBn_getOpUnitSize', 'number', []) | ||
@@ -57,0 +57,0 @@ mclBn_getCurveOrder = mod.cwrap('mclBn_getCurveOrder', 'number', ['number', 'number', ]) |
@@ -79,2 +79,12 @@ [{ | ||
"args": ["number", "number", "number", "number"] | ||
}, { | ||
"name": "blsIdSetInt", | ||
"exportName": "idSetInt", | ||
"returns": "number", | ||
"args": ["number", "number"] | ||
}, { | ||
"name": "blsHashToSecretKey", | ||
"exportName": "_hashToSecretKey", | ||
"returns": "number", | ||
"args": ["number", "number", "number"] | ||
}] |
27
index.js
const mod = require('./build/bls_lib.js') | ||
const exportedFuncs = require('./exportedFuncs.json') | ||
exports.mod = mod | ||
let init = false | ||
@@ -122,2 +124,4 @@ let initCb = () => {} | ||
exports.hashToSecretKey = wrapInput(exports._hashToSecretKey, true) | ||
/** | ||
@@ -142,3 +146,3 @@ * write a secretKey to memory | ||
*/ | ||
exports.signatureDeserialize = wrapInput(exports._signatureDeserialize, true) | ||
exports.signatureDeserialize = wrapInput(exports._signatureDeserialize) | ||
@@ -188,16 +192,15 @@ /** | ||
function wrapInput (func, returnValue = false) { | ||
function wrapInput (func) { | ||
return function () { | ||
const args = [...arguments] | ||
const buf = args.pop() | ||
const ioMode = 0 | ||
const pos = mod._malloc(buf.length) | ||
let buf = args.pop() | ||
if (typeof buf === 'string') { | ||
mod.writeStringToMemory(buf, pos) | ||
} else { | ||
mod.HEAP8.set(buf, pos) | ||
buf = Buffer.from(buf) | ||
} | ||
let r = func(...args, pos, buf.length, ioMode) | ||
const pos = mod._malloc(buf.length) | ||
mod.HEAP8.set(buf, pos) | ||
let r = func(...args, pos, buf.length) | ||
mod._free(pos) | ||
if (returnValue) return r | ||
return r | ||
} | ||
@@ -207,5 +210,5 @@ } | ||
function wrapOutput (func, size) { | ||
return function (x, ioMode = 0) { | ||
return function (x) { | ||
const pos = mod._malloc(size) | ||
const n = func(pos, size, x, ioMode) | ||
const n = func(pos, size, x) | ||
const a = mod.HEAP8.slice(pos, pos + n) | ||
@@ -212,0 +215,0 @@ mod._free(pos) |
function define_exported_mcl(mod) { | ||
mclBn_setErrFile = mod.cwrap('mclBn_setErrFile', 'number', ['number', ]) | ||
mclBn_init = mod.cwrap('mclBn_init', 'number', ['number', 'number', ]) | ||
_mclBn_init = mod.cwrap('mclBn_init', 'number', ['number', 'number', ]) | ||
mclBn_getOpUnitSize = mod.cwrap('mclBn_getOpUnitSize', 'number', []) | ||
@@ -5,0 +5,0 @@ mclBn_getCurveOrder = mod.cwrap('mclBn_getCurveOrder', 'number', ['number', 'number', ]) |
@@ -28,3 +28,3 @@ function getValue(name) { return document.getElementsByName(name)[0].value } | ||
define_extra_functions(mod) | ||
var r = mclBn_init(0, MCLBN_FP_UNIT_SIZE) | ||
var r = mclBn_init(0) | ||
setText('status', r ? 'err:' + r : 'ok') | ||
@@ -103,2 +103,5 @@ }) | ||
/////////////////////////////////////////////////////////////// | ||
mclBn_init = function(curveType) { | ||
_mclBn_init(curveType, MCLBN_FP_UNIT_SIZE) | ||
} | ||
mclBnFr_malloc = function() { | ||
@@ -105,0 +108,0 @@ return mod._malloc(MCLBN_FP_UNIT_SIZE * 8) |
@@ -142,7 +142,7 @@ [![Build Status](https://travis-ci.org/herumi/mcl.png)](https://travis-ci.org/herumi/mcl) | ||
# How to initialize pairing library | ||
Call `mcl::bn256::bn256init` before calling any operations. | ||
Call `mcl::bn256::initPairing` before calling any operations. | ||
``` | ||
#include <mcl/bn256.hpp> | ||
mcl::bn::CurveParam cp = mcl::bn::CurveFp254BNb; // or mcl::bn::CurveSNARK1 | ||
mcl::bn256::bn256init(cp); | ||
mcl::bn256::initPairing(cp); | ||
mcl::bn256::G1 P(...); | ||
@@ -149,0 +149,0 @@ mcl::bn256::G2 Q(...); |
{ | ||
"name": "bls-lib", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "this libary provides primitives for creating and verify BLS threshold signatures", | ||
@@ -18,3 +18,5 @@ "main": "index.js", | ||
"license": "MPL-2.0", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"defined": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -21,0 +23,0 @@ "array-shuffle": "^1.0.1", |
@@ -44,3 +44,3 @@ # SYNOPSIS | ||
First install the dependancies [emcripten](https://github.com/kripken/emscripten) and [ninja](ninja-build.org) | ||
First install the dependancies [emscripten](https://github.com/kripken/emscripten) and [ninja](ninja-build.org) | ||
@@ -47,0 +47,0 @@ ``` |
@@ -7,5 +7,23 @@ const tape = require('tape') | ||
tape('basic', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
bls.onModuleInit(() => { | ||
t.pass(true) | ||
bls.init() | ||
const sec = bls.secretKey() | ||
const pub = bls.publicKey() | ||
const sig = bls.signature() | ||
const secString = '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08' | ||
const secArray = Buffer.from(secString, 'hex') | ||
bls.secretKeyDeserialize(sec, secArray) | ||
const pubString = '7ca19ff032c22a00b3d79d8961495af4c6c93c9c2b62bd7279570fcc2ca8d120fc75fd16f55ded79f6392a0769496817cded4760ed658d62627b9e6852b1100d' | ||
bls.publicKeyDeserialize(pub, Buffer.from(pubString, 'hex')) | ||
const msg = 'test' | ||
bls.sign(sig, sec, msg) | ||
const v = bls.verify(sig, pub, msg) | ||
t.equals(v, 1) | ||
}) | ||
@@ -21,3 +39,3 @@ }) | ||
bls.secretKeySetByCSPRNG(sec) | ||
const msg = 'hello world' | ||
const msg = Buffer.from('hello world') | ||
bls.sign(sig, sec, msg) | ||
@@ -24,0 +42,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 13 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
78081588
545
10150
1
8
48
+ Addeddefined@^1.0.0
+ Addeddefined@1.0.1(transitive)