GithubHelp home page GithubHelp logo

bls-wasm's Introduction

Build Status

BLS signature for Node.js by WebAssembly

Abstract

How to use

The version v0.4.2 breaks backward compatibility of the entry point.

  • Node.js : const bls = require('bls-wasm')
  • React : const bls = require('bls-wasm/browser')
  • HTML : <script src="https://herumi.github.io/bls-wasm/browser/bls.js"></script>

for Node.js

node test/test.js

for browser

Include browser/bls.js

for React

const bls = require('bls-wasm/browser')

License

modified new BSD License http://opensource.org/licenses/BSD-3-Clause

Author

MITSUNARI Shigeo([email protected])

Sponsors welcome

GitHub Sponsor

bls-wasm's People

Contributors

ameba23 avatar dependabot[bot] avatar herumi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bls-wasm's Issues

BLS

The page cannot be accessed. What is the length of the BLS signature, the time of the word signature and the time of the word verification?

LittleEndian

Please what is the reason behind the use of LittleEndian during secret key generation.

      setLittleEndian (s) {
        this._setter(mod.blsSecretKeySetLittleEndian, s)
      }
      setByCSPRNG () {
        const a = new Uint8Array(BLS_SECRETKEY_SIZE)
        crypto.getRandomValues(a)
        this.setLittleEndian(a)
}```

How to recover keys using bls-wasm.

Is there any way in bls-wasm to recover keys from a mnemonic/seed. I saw the bls-go package also and there I found, we can recover keys like this:

seed := bip39.NewSeed(b0.Mnemonic,'Some random string')
r := bytes.NewReader(seed)
bls.SetRandFunc(r)

Currently, I am generating keys like this:

const blsSecret = new bls.SecretKey();
blsSecret.setByCSPRNG()
const key = blsSecret.getPublicKey().serializeToHexStr();
const id = sha3.sha3_256(utils.hexStringToByte(key));
const sKey = blsSecret.serializeToHexStr();

but not sure, how we can use mnemonic to get/recover the keys?

Public Key Generator

We need to have a basepoint other than what is provided by default. as in go library, there is a function named SetGeneratorOfPublicKey providing this I was wondering how we can achieve the same with the js library
I've added it to the js library on my fork ready to PR but the problem is my tests are failing can you help me out?

added section:

    // change curveType
    exports.blsInit = (curveType = exports.ethMode ? exports.BLS12_381 : exports.BN254) => {
      const r = mod._blsInit(curveType, MCLBN_COMPILED_TIME_VAR)
      if (r) throw ('blsInit err ' + r)
    }
    exports.blsSetGeneratorOfPublicKey = (gen) => {
      const r = mod._blsSetGeneratorOfPublicKey(gen)
      if (r) throw ('blsSetGeneratorOfPublicKey err ' + r)
    }

test that is failing:

function generatorOfPublicKeyTest() {
  let gen = new bls.PublicKey();
  gen.deserializeUncompressed("1 24aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8 13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801 606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be");
  bls.blsSetGeneratorOfPublicKey(gen)
  let sk = new bls.SecretKey()
  sk.setInt(1);
  let pk = sk.getPublicKey();
  console.log(sk.serializeToHexStr())
  console.log(pk.serializeToHexStr())
  assert(pk.serializeToHexStr() == "93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8");
}

the output of failing test:

> [email protected] test
> node test/test.js

name=BLS12_381 curve order=52435875175126190479447740508185965837690552500527637822603658699938581184513
secretKey b51e7aeee544971b65965c9fb2da8e0312ed852c16d90344516ec2a2160c713b
publicKey 7ac55e61b8dac68f1edb723c8dca51e1af6091c7f4f10272d5e2fdb2ef59809dd50111c48ef817977dabd11ef0ec33188ca054ea19321c12d2f39129df7cf6d8f6a5848f2f567a45dc6551220e5837fe1b2b2ad93328db7955f978976d695a0c
msg doremifa
signature 804d0732e3fe750c9a6a4c3b676880e2d749fd68221b56bdd231f2d60acb88313c08a1ad47682c48bcfea8a38b3d820d
idxVec=4,7,8,9
/work/bls-wasm/src/bls.js:112
        if (r === 0 || r !== buf.length) throw new Error('err _wrapDeserialize', buf)
                                               ^

Error: err _wrapDeserialize
    at work/bls-wasm/src/bls.js:112:48
    at exports.PublicKey._setter (work/bls-wasm/src/bls.js:273:19)
    at exports.PublicKey.deserializeUncompressed (work/bls-wasm/src/bls.js:522:14)
    at generatorOfPublicKeyTest (work/bls-wasm/test/test.js:230:7)
    at work/bls-wasm/test/test.js:16:7

Wasm read but not used

I have searched through bls.js to see how wasm file is used. But it is not clear to me. And I found this function call strange , Module(). Where is this function calling from?

``` fetch(./${name}.wasm) // eslint-disable-line
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer))
.then(() => {
exports.mod = Module() // eslint-disable-line
exports.mod.cryptoGetRandomValues = _cryptoGetRandomValues
exports.mod.onRuntimeInitialized = () => {
setup(exports, curveType)
resolve()
}
})

Facing issues while using bls-wasm in a React App.

When I try to initialize the bls-wasm library via the react app, it throws an error which can be seen on the browser console:
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0
Please guide me through the issue and how can this be resolved.

Standalone WASM?

As far as the WASM build, is it possible to build the standalone WASM file like
emcc ... -o output.wasm omits generating either JavaScript or HTML launcher file, and produces a single Wasm file built in standalone mode as if the -sSTANDALONE_WASM settting had been used.
I wasn't having much success poking at it, but im looking to just have the raw WASM that I can utilize in C# vs in the browser.

Question: how to verify BLS has been initialized?

Hey Shigeo, hajimemashite

First, thanks for the excellent lib!
On our web app we use it on multiple locations asynchronously.
To avoid running init multiple times, I have written a small getter fn:

export const getBls = async () => {
  const bls = window.bls

  if (!bls?.mod?.calledRun) await bls.init(bls.BN254)

  return bls
}

It seems to work for now, but I'm thinking about future compatibility.

Does this method look ok to you?
Would you suggest another approach?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.