Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/bls_lib.js

Large diffs are not rendered by default.

Binary file modified build/bls_lib.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion build/build.ninja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cflags = -I../mcl/include/ -I../cybozulib/include -I../bls/include -I../bls

rule buildExLib
command = emcc -O3 -o $out ../bls/src/bls_c.cpp ../mcl/src/fp.cpp --pre-js ../pre.js $cflags -s WASM=1 -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -DNDEBUG
command = emcc -O3 -o $out ../bls/src/bls_c.cpp ../mcl/src/fp.cpp --pre-js ../pre.js $cflags -s WASM=1 -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -DNDEBUG -DMCLBN_USE_NEW_DESERIALIZE_API

build bls_lib.js : buildExLib
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod.onRuntimeInitialized = function () {
* @param {number} sk - a pointer to a secret key
* @param {TypedArray} array - the secret key as a 32 byte TypedArray
*/
exports.secretKeyDeserialize = wrapInput(mod._blsSecretKeyDeserialize)
exports.secretKeyDeserialize = wrapDeserialize(mod._blsSecretKeyDeserialize)

/**
* write a secretKey to memory and returns a pointer to it
Expand All @@ -195,7 +195,7 @@ mod.onRuntimeInitialized = function () {
* @param {number} sk - a pointer to a public key
* @param {TypedArray} array - the secret key as a 64 byte TypedArray
*/
exports.publicKeyDeserialize = wrapInput(mod._blsPublicKeyDeserialize)
exports.publicKeyDeserialize = wrapDeserialize(mod._blsPublicKeyDeserialize)

/**
* write a publicKey to memory and returns a pointer to it
Expand All @@ -213,7 +213,7 @@ mod.onRuntimeInitialized = function () {
* @param {number} sig - a pointer to a signature
* @param {TypedArray} array - the signature as a 32 byte TypedArray
*/
exports.signatureDeserialize = wrapInput(mod._blsSignatureDeserialize)
exports.signatureDeserialize = wrapDeserialize(mod._blsSignatureDeserialize)

/**
* write a signature to memory and returns a pointer to it
Expand Down Expand Up @@ -334,6 +334,16 @@ function wrapInput (func) {
}
}

function wrapDeserialize (func) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this replicates a bit of what is in wrapInput maybe we could use something like this instead

function wrapDeserialize (func) {
  func = wrapInput(func)
  return function () {
    const r = func.apply(null, arguments)
    if (r === 0) {
      throw new Error('Deserialize err')
    }
  }
}

what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I fixed it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! looking good 👍

func = wrapInput(func)
return function (p, buf) {
const r = func(p, buf)
if (r === 0) {
throw new Error('Deserialize err')
}
}
}

function wrapOutput (func, size) {
return function (x) {
const pos = mod._malloc(size)
Expand Down
11 changes: 11 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ bls.onModuleInit(() => {
t.end()
})

tape('bad import', t => {
bls.init()
t.plan(1)
try {
bls.secretKeyImport(new Uint8Array([1, 2, 3]))
} catch (e) {
t.pass(true)
}
t.end()
})

tape('shares', t => {
bls.init()
const numOfPlayers = 5
Expand Down