https://github.com/chainsafe/bls-hd-key
BLS key derivation and hd key utilities
https://github.com/chainsafe/bls-hd-key
bls12-381 eth2
Last synced: 3 months ago
JSON representation
BLS key derivation and hd key utilities
- Host: GitHub
- URL: https://github.com/chainsafe/bls-hd-key
- Owner: ChainSafe
- License: apache-2.0
- Created: 2019-11-26T19:39:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T12:16:22.000Z (almost 3 years ago)
- Last Synced: 2025-10-02T02:53:24.313Z (4 months ago)
- Topics: bls12-381, eth2
- Language: TypeScript
- Size: 1.34 MB
- Stars: 6
- Watchers: 10
- Forks: 3
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# BLS HD Key Utilities

[](https://discord.gg/aMxzVcr)



Utility functions for managing BLS heirarchical deterministic accounts.
1. Create a master private key from entropy
2. Create a child private key from a private key and index
3. Convert a standard path into an array of indices
4. Create a decendent private key from a private key and array of indices
Implementation is following EIPS: [EIP-2334](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2334.md), [EIP-2333](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2333.md)
For a higher-level interface, see [@chainsafe/bls-keygen](https://github.com/chainsafe/bls-keygen).
### Example
```typescript
import {deriveMasterSK, deriveChildSK, deriveChildSKMultiple, pathToIndices} from "@chainsafe/bls-hd-key";
// Create master private key (according to EIP-2333)
const entropy: Uint8Array = Uint8Array.from(...);
const masterKey: Uint8Array = deriveMasterSK(entropy);
// Create child private key one level deep
const childIndex: number = ...;
const childKey: Uint8Array = deriveChildSK(masterKey, childIndex);
// Convert a "path" into an array of indices (using validation rules of EIP-2334)
cont path = "m/12381/3600/0/0";
const childIndices: number[] = pathToIndices(path);
// Convert a "path" into an array of indices (validating an alternate key type)
const eth1KeyType = 60;
cont path = "m/12381/60/0/0";
const childIndices: number[] = pathToIndices(path, eth1KeyType);
// Create a child private key `childIndices.length` levels deep
const childIndices: number[] = [...];
const childKey = deriveChildSKMultiple(masterKey, childIndices);
// Compose functions to derive a child key from entropy and a path
const entropy: Uint8Array = Uint8Array.from(...);
cont path = "m/12381/3600/0/0";
const childKey = deriveChildSKMultiple(deriveMasterSK(entropy), pathToIndices(path));
```
### Contrubuting
Requirements:
- nodejs
- yarn
```bash
yarn install
yarn run test
```
### Audit
This repo was audited by Least Authority as part of [this security audit](https://github.com/ChainSafe/lodestar/blob/master/audits/2020-03-23_UTILITY_LIBRARIES.pdf), released 2020-03-23. Commit [`767c998`](https://github.com/ChainSafe/bls-hd-key/commit/767c998) verified in the report.
### License
Apache-2.0