Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.45 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.45 KB

bls12-381-keygen-chia

This is a fork of bls12-381-keygen adjusting only one line to be compatible with chia's implementation.

BLS12-381 Key Generation compatible with EIP-2333.

If you're looking for actual implementation of the elliptic curve, use module noble-bls12-381. The bls12-381-keygen-chia only generates private keys, by EIP-2333 specification.

Just one small dependency on SHA256.

Usage

Node.js and browser:

npm install bls12-381-keygen-chia

  • deriveMaster takes Uint8Array and returns Uint8Array
  • deriveChild takes Uint8Array, number and returns Uint8Array
const {deriveMaster, deriveChild} = require('bls12-381-keygen-chia');
const master = deriveMaster(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
const child = deriveChild(master, 0); // 0 is numeric index

Generating BIP32 seeds for ETH2

const bls = require('noble-bls12-381');
const keygen = require('bls12-381-keygen-chia');
const bip39 = require('bip39');
function eth2PrivFromBytes(bytes, path = 'm/12381/3600/0/0/0') {
  const mnemonic = bip39.entropyToMnemonic(bytes);
  const seed = bip39.mnemonicToSeedSync(mnemonic);
  return keygen.deriveSeedTree(seed, path);
}
function eth2PubFromBytes(bytes, path) {
  return bls.getPublicKey(eth2PrivFromBytes(bytes, path));
}

License

MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.