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

@poolsea-nestjs/key-validation

v1.2.0

Published

NestJS key validation for Lido Finance projects. Part of [Lido NestJS Modules](https://github.com/lidofinance/lido-nestjs-modules/#readme)

Downloads

3

Readme

Key-validation

NestJS key validation for Lido Finance projects. Part of Lido NestJS Modules

Install

yarn add @poolsea-nestjs/key-validation

Usage

Basic key validation

import { Module } from '@nestjs/common';
import {
  KeyValidatorModule,
  Key,
  KeyValidatorInterface,
  GENESIS_FORK_VERSION,
} from '@poolsea-nestjs/key-validation';
import { CHAINS } from '@poolsea-nestjs/constants';

@Module({
  imports: [KeyValidatorModule.forFeature({ multithreaded: true })], //
  providers: [Example],
  exports: [Example],
})
export class ExampleModule {}

export class Example {
  public constructor(
    // note that `KeyValidatorInterface` is a Symbol-like interface tag
    // which point to specific implementation
    private readonly keyValidator: KeyValidatorInterface,
  ) {}

  public async basicValidation() {
    const key: Key = {
      key: '0x00...1',
      depositSignature: '0x00...1',
      withdrawalCredentials: Buffer.alloc(32),
      genesisForkVersion:
        GENESIS_FORK_VERSION[CHAINS.Mainnet] ?? Buffer.alloc(32),
    };

    const resultSingleKey: boolean = await this.keyValidator.validateKey(key);

    const resultMultipleKeys: [Key, boolean][] =
      await this.keyValidator.validateKeys([key]);
  }
}

Lido key validation

import { Module } from '@nestjs/common';
import {
  Key,
  LidoKey,
  LidoKeyValidatorInterface,
  LidoKeyValidatorModule,
} from '@poolsea-nestjs/key-validation';
import { LidoContractModule } from '@poolsea-nestjs/contracts';
import {
  SimpleFallbackJsonRpcBatchProvider,
  FallbackProviderModule,
} from '@poolsea-nestjs/execution';

export class Example {
  public constructor(
    // note that `LidoKeyValidatorInterface` is a Symbol-like interface tag
    // which point to specific implementation
    private readonly lidoKeyValidator: LidoKeyValidatorInterface,
  ) {}

  public async someMethod() {
    const key1: LidoKey = {
      key: '0x00...1',
      depositSignature: '0x00...1',
      used: true,
    };

    const key2: LidoKey = {
      key: '0x00...1',
      depositSignature: '0x00...1',
      used: true,
    };

    // single key
    const resultSingleKey: [Key & LidoKey, boolean] =
      await this.lidoKeyValidator.validateKey(key1);

    // multiple keys
    const resultMultupleKeys: [Key & LidoKey, boolean][] =
      await this.lidoKeyValidator.validateKeys([key1, key2]);
  }
}

@Module({
  imports: [
    FallbackProviderModule.forRoot({
      urls: ['http://localhost:8545'],
      network: 1,
    }),
    LidoContractModule.forRootAsync({
      // needed for getting WithdrawalCredentials and Network chain id
      async useFactory(provider: SimpleFallbackJsonRpcBatchProvider) {
        return { provider: provider };
      },
      inject: [SimpleFallbackJsonRpcBatchProvider],
    }),
    LidoKeyValidatorModule.forFeature({ multithreaded: true }), // can be multithreaded or single-threaded
  ],
  providers: [Example],
  exports: [Example],
})
export class ExampleModule {}

Troubleshooting

When you try to install the key-validation module, you may encounter an unexpected problem related to the inability to install @chainsafe/blst dependencies under darwin arm64.

Why does it happen?!

It happens because https://www.npmjs.com/package/@chainsafe/blst doesn't provide native C binding to https://github.com/supranational/blst under darwin arm64. Such as there no native binding, a user has to compile C binding to blst lab manually for darwin arm64. @chainsafe/blst has compile option but inside itself for downloading dependencies this lib uses Python language. Historically MacOs uses alias python3 for python. So then @chainsafe/blst fails with an error that it could not install all dependencies. To fix it on MacOs just create alias python for python3.

ln -s /opt/homebrew/bin/python3 /usr/local/bin/python

More info here - https://github.com/ChainSafe/lodestar/issues/4767#issuecomment-1640631566

See more examples in the ./examples/ folder.