# @chainsafe/bls-hd-key

> BLS KDF and HD wallet utilities

Latest version **0.3.0** (published 2022-02-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @chainsafe/bls-hd-key
pnpm add @chainsafe/bls-hd-key
yarn add @chainsafe/bls-hd-key
bun add @chainsafe/bls-hd-key
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-02-09 |
| First published | 2019-12-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 42.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ChainSafe Systems |
| Maintainers | gregthegreek, priom, dapplion, wemeetagain, mpetrunic |

## Links

- npm: https://www.npmjs.com/package/@chainsafe/bls-hd-key
- Repository: https://github.com/ChainSafe/bls-hd-key
- Homepage: https://github.com/ChainSafe/bls-hd-key#readme
- Issues: https://github.com/ChainSafe/bls-hd-key/issues
- npm.io page: https://npm.io/package/@chainsafe/bls-hd-key

## Dependencies (1)

- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ^1.0.0

## Recent versions

- 0.3.0 (latest) — 2022-02-09
- 0.2.1 — 2021-04-20
- 0.2.0 — 2020-09-26
- 0.1.0 — 2020-07-30
- 0.0.1 — 2019-12-01

## README

# BLS HD Key Utilities

![npm (tag)](https://img.shields.io/npm/v/@chainsafe/bls-hd-key/latest)
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
![GitHub](https://img.shields.io/github/license/chainsafe/bls-hd-key)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-12.x-green)

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

---
_Source: https://npm.io/package/@chainsafe/bls-hd-key · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
