How to use bls-wasm - 10 common examples

To help you get started, we’ve selected a few bls-wasm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfinity-side-projects / dkg / test / index.js View on Github external
const tape = require('tape')
const bls = require('bls-wasm')
const threshold = 4
const dkg = require('../')

bls.init().then(() => {
  tape('dkg', t => {
    // create the ids
    const ids = [0, 1, 2, 3, 4, 5, 6].map(id => {
      const sk = new bls.SecretKey()
      sk.setHashOf(Buffer.from([id]))
      return sk
    })

    // this stores an array of verifcation vectors. One for each ID
    const vvecs = []
    // this stores an array of secertKey contrubutions. One for each ID
    const skContributions = []

    // setup
    ids.forEach(id => {
      const {verificationVector, secretKeyContribution} = dkg.generateContribution(bls, ids, threshold)
github dfinity-side-projects / dkg / test / index.js View on Github external
const groupsVvec = dkg.addVerificationVectors(vvecs)

    // derive the public key for each id from there secert key share
    const groupsPks = []
    ids.forEach((id, i) => {
      const pk = new bls.PublicKey()
      pk.share(groupsVvec, id)
      groupsPks.push(pk)

      const sk = groupsSks[i]
      const pk2 = sk.getPublicKey()
      const equal = pk.isEqual(pk2)
      t.true(equal, 'public key derived from groups vvec should equal pk from secert share')
    })

    const groupsPk = new bls.PublicKey()
    groupsPk.recover(groupsPks.slice(0, threshold), ids.slice(0, threshold))
    const equal = groupsPk.isEqual(groupsVvec[0])
    t.true(equal, 'groups public key should equal pk derived from pk shares')
    t.end()
  })
})
github spacemeshos / app / src / services / signatures.ts View on Github external
public GenerateSecretDerivedKey(sec: bls.SecretKey, idx: number) : bls.SecretKey {
      // todo: implement key deriviation
      const sec1 = bls.SecretKey();
      sec1.setByCPRNG();
      return sec1;
  }
github dfinity-side-projects / dkg / test / index.js View on Github external
ids.forEach((id, i) => {
      const pk = new bls.PublicKey()
      pk.share(groupsVvec, id)
      groupsPks.push(pk)

      const sk = groupsSks[i]
      const pk2 = sk.getPublicKey()
      const equal = pk.isEqual(pk2)
      t.true(equal, 'public key derived from groups vvec should equal pk from secert share')
    })
github dfinity-side-projects / dkg / test / index.js View on Github external
const ids = [0, 1, 2, 3, 4, 5, 6].map(id => {
      const sk = new bls.SecretKey()
      sk.setHashOf(Buffer.from([id]))
      return sk
    })
github spacemeshos / app / src / services / signatures.ts View on Github external
public async Init() : Promise {
      await bls.init(bls.BLS12_381);
      return Promise.resolve();
  }
github spacemeshos / app / src / services / signatures.ts View on Github external
public NewSecretKeyFromSeed(hexStr: string) : bls.SecretKey {
      const sec = bls.SecretKey();
      const a = bls.fromHexStr(hexStr);
      sec.setLittleEndian(a);
      return sec;
  }
github spacemeshos / app / src / services / signatures.ts View on Github external
public NewSecretKeyFromHex(hexStr: string) : bls.SecretKey {
      const sec = bls.SecretKey();
      sec.deserialize(hexStr);
      return sec;
  }
github spacemeshos / app / src / services / sigs / secretkeyex.ts View on Github external
public constructor(seed: string) {
        if (seed.length != 128) throw new Error('Unexpected input length. Expected 128 chars hex string.');

        const rndSeed = seed.substring(0,96);
        const chainCode = seed.substring(96,128);
        this.s = new bls.SecretKey();
        this.rndSeed = rndSeed;
        this.chainCode = chainCode;
        const a = bls.fromHexStr(rndSeed);
        this.s.setLittleEndian(a);
    }
github spacemeshos / app / src / services / signatures.ts View on Github external
public NewSecretKeyFromSeed(hexStr: string) : bls.SecretKey {
      const sec = bls.SecretKey();
      const a = bls.fromHexStr(hexStr);
      sec.setLittleEndian(a);
      return sec;
  }

bls-wasm

BLS signature for Node.js by WebAssembly

BSD-3-Clause
Latest version published 2 months ago

Package Health Score

65 / 100
Full package analysis