npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@myetherwallet/eth2-keystore

v0.3.1

Published

eth2 keystore

Downloads

107

Readme

Eth2 Keystore

npm (tag) GitHub Node Version

Utility functions for generating BLS secret keys, built for NodeJs and Browser.

  • Create keystore from BIP-39 mnemonic.
  • Create a derived child key from BIP-39 mnemonic.
  • Create Eth2 validator keystore from mnemonic.

Implementation follows EIPS: EIP-2334, EIP-2333

For low-level EIP-2333 and EIP-2334 functionality, see @chainsafe/bls-hd-key.

Examples

//New mnemonic
import KeyStore, { verifyKeystore } from '@myetherwallet/eth2-keystore';
const PASSWORD = 'testwallet';
const ks = new KeyStore();
console.log(await ks.getMnemonic());
const genSigningKeystore = await ks.toSigningKeystore(PASSWORD); //generates the keystore json
const res = await verifyKeystore(genSigningKeystore, PASSWORD); //verify generated keystore
//res === true
const genWithdrawalKeystore = await ks.toWithdrawalKeystore(PASSWORD); //generates the keystore json
const res2 = await verifyKeystore(genWithdrawalKeystore, PASSWORD); //verify generated keystore
//res2 === true

//Existing mnemonic
import KeyStore, { verifyKeystore } from '@myetherwallet/eth2-keystore';
const MNEMONIC =
    'tenant glimpse solve letter chest ankle jealous movie subway exhibit cream garden scene grunt below patrol hurt fatigue escape trap phrase mandate feature one';
const PASSWORD = 'testwallet';
const ks = new KeyStore({
    mnemonic: MNEMONIC
});
console.log(ks.getMnemonic());
//tenant glimpse solve letter chest ankle jealous movie subway exhibit cream garden scene grunt below patrol hurt fatigue escape trap phrase mandate feature one
const genSigningKeystore = await ks.toSigningKeystore(PASSWORD); //generates the keystore json
const res = await verifyKeystore(genSigningKeystore, PASSWORD); //verify generated keystore
//res === true
const genWithdrawalKeystore = await ks.toWithdrawalKeystore(PASSWORD); //generates the keystore json
const res2 = await verifyKeystore(genWithdrawalKeystore, PASSWORD); //verify generated keystore
//res2 === true

//BLS To Execution Change
import KeyStore, {
    verifyKeystore,
    keystoreToBLSExecution,
    mnemonicToBLSExecution
    CHAIN_NAMES
} from '@myetherwallet/eth2-keystore';
const MNEMONIC =
    'sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry';
const PASSWORD = 'testwallet';
const ks = new KeyStore({
    mnemonic: MNEMONIC
});
console.log(ks.getMnemonic());
//tenant glimpse solve letter chest ankle jealous movie subway exhibit cream garden scene grunt below patrol hurt fatigue escape trap phrase mandate feature one
const genWithdrawalKeystore = await ks.toWithdrawalKeystore(PASSWORD); //generates the keystore json
const res2 = await verifyKeystore(genWithdrawalKeystore, PASSWORD); //verify generated keystore
//res2 === true
const VALIDATOR_INDEX = 5000;
const EXECUTION_ADDRESS = '0x3434343434343434343434343434343434343434';
const CHAIN_NAME = CHAIN_NAMES.mainnet;
const currentWithdrawalCredential =
    '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de'; // you have to get it onchain
const blsExecution = await keystoreToBLSExecution(
    genWithdrawalKeystore,
    PASSWORD,
    EXECUTION_ADDRESS,
    VALIDATOR_INDEX,
    currentWithdrawalCredential,
    CHAIN_NAME
); //generate blstoExecution
console.log(blsExecution);
// {
//     message: {
//         validator_index: '50000',
//         from_bls_pubkey:
//             '0x86248e64705987236ec3c41f6a81d96f98e7b85e842a1d71405b216fa75a9917512f3c94c85779a9729c927ea2aa9ed1',
//         to_execution_address: '0x3434343434343434343434343434343434343434'
//     },
//     signature:
//         '0x95e5ceccbaa2e3983c7fbaf693cbe6f5033f73850ace3b0fbbccb9f652198b17d895e339c0a5462cda6c093754e04a0902da3525fac66312ce00c3af19235d722ffe9541a145e2c60a440196f343447ff55bcb62a0f35a4dddaccbaab5025bf6',
//     metadata: {
//         network_name: 'mainnet',
//         genesis_validators_root:
//             '0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95',
//         deposit_cli_version: '2.5.0'
//     }
// };
//  you have to submit this to curl -X POST -H “Content-type: application/json” -d @<@FILENAME DESTINATION> http://<BEACON_NODE_HTTP_API_URL>/eth/v1/beacon/pool/bls_to_execution_changes

// You can also go directly from mnemonic
const blsSig = await mnemonicToBLSExecution(
                {
                    mnemonic: MNEMONIC
                },
                EXECUTION_ADDRESS,
                VALIDATOR_INDEX,
                currentWithdrawalCredential,
                CHAIN_NAME
            );

//get withdrawal credential from public key
import { pubKeyToWithdrawalCredential } from '@myetherwallet/eth2-keystore';
const PUBKEY =
    '0x86248e64705987236ec3c41f6a81d96f98e7b85e842a1d71405b216fa75a9917512f3c94c85779a9729c927ea2aa9ed1';
console.log(pubKeyToWithdrawalCredential(PUBKEY));
// 0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de

Contribution

Requirements:

  • nodejs
  • npm
    npm install
    npm run test

Audit

This repo is using the library audited by this security audit, released 2020-03-23. Commit 767c998 verified in the report.

Special Thanks

to @chainsafe for providing necessary libraries

License

MIT