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

@decentstake/beaconchain-utils

v1.0.7

Published

Typescript Ethereum BeaconChain Utils

Downloads

6

Readme

BeaconChain Utils

Module type: CJS node 18.x npm version

This package contains typescript utilities for working with the Eth2 Beacon Chain, wrapping around @Lodestar and @Chainsafe packages.

Installation

npm install @decentstake/beaconchain-utils

Usage

  • Sign and create a DepositData object with a BIP39 mnemonic:
import {
    generateDepositData,
    generatePackedDepositData,
    parseAddressToBLS,
    Validator,
    SecretProvider
} from '@decentstake/beaconchain-utils';

import type {
	IDepositData,
	IDepositDataSignature,
	IPackedDepositData
} from '@decentstake/beaconchain-utils/interfaces';

import { Chains } from '@decentstake/beaconchain-utils/chainParams';

const mnemonic: string = 'sister protect...'
const withdrawal_credential: Uint8Array = parseAddressToBLS('0x8FB4...');
const validatorIndex: number = 0;

// Create a new mnemonic.
const secretProvider = new SecretProvider();

// Or use an existing mnemonic.
const secretProvider = new SecretProvider(mnemonic);

const secretKey = secretProvider.deriveValidator(validatorIndex).secretKey;
const validator = new Validator(secretKey, validatorIndex, Chains.mainnet);

// Signs data for generating a  deposit data object.
const depositDataSignature: IDepositDataSignature = await validator.signDepositData(
	withdrawal_credential,
);

// Generates a deposit data object.
const depositData: IDepositData[] = generateDepositData([depositDataSignature]);

// `packed` version of `generateDepositData`.
const packedDepositData: IPackedDepositData = generatePackedDepositData([depositDataSignature]);
  • Generate EIP 2335 keystores for a list of validator indices:
    Generating 100 keystores takes about 90 seconds. May vary depending on your machine.
import { SecretProvider } from '@decentstake/beaconchain-utils';
import type { IKeystore, IKeystoreObject } from '@decentstake/beaconchain-utils/interfaces';

const password: string = "somePassword";
const mnemonic: string = 'sister protect...';
const startIndex = 0;
const numberOfValidators = 100; //ValidatorIndexes 0-99

// Create a new mnemonic.
const secretProvider = new SecretProvider();

// Or use an existing mnemonic.
const secretProvider = new SecretProvider(mnemonic);

const keystoreObject: IKeystoreObject = await secretProvider.generateKeystores(
	startIndex,
	numberOfValidators,
	password
);

const keystores: Array<IKeystore> = keystoreObject.keystores;
const psw: string = keystoreObject.password;

//OR export keystore from a single validator
//...
const validator = new Validator(secretKey, validatorIndex, Chains.mainnet);
const keystore: IKeystore = await validator.generateKeystore(password);
  • Derive a validator public and secret key from a BIP39 mnemonic:
import { SecretProvider, hexStringToBytes } from '@decentstake/beaconchain-utils';
import type { IValidatorKeyPair } from '@decentstake/beaconchain-utils/interfaces';

const mnemonic: string = 'sister protect...';
const startIndex = 0;
const numberOfValidators = 100; //ValidatorIndexes 0-99

// Create a new mnemonic.
const secretProvider = new SecretProvider();

// Or use an existing mnemonic.
const secretProvider = new SecretProvider(mnemonic);

//Derive a single validator.
const validator0KeyPair: IValidatorKeyPair = secretProvider.deriveValidator(0);
const validator0secretKey = validator0KeyPair.secretKey;
const validator0pubkey = validator0KeyPair.pubkey;

// OR Derive multiple validators.
// The nth validator has a secretKey secretKey[n] and a public key pubkey[n]
// Values are returned as hexstrings.
const { pubkeys, secretKeys } = secretProvider.exportValidators(startIndex, numberOfValidators);
const validator0secretKey = hexStringToBytes(secretKeys[0]);
const validator0pubkey = hexStringToBytes(pubkeys[0]);