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

@dsrv/kms

v0.4.10

Published

blockchain key managament system

Downloads

218

Readme

@dsrv/kms

dsrv key management store. @dsrv/kms provides the following methods for Ethereum, Celo, Near, Solana, Cosmos, Aptos, Sui

0. Live Demo

  • Through WELLDONE Docs, you may see a live demonstration of kms and a more thorough theoretical foundation.

1. getAccount

Through getAccount method, you can get account of your mnemonic.

import { Account, CHAIN, Ethereum } from '@dsrv/kms';

/* Ethereum getAccount */
export const getEthereumAccount = (mnemonic: string): Account => {
  const ethereumAccount = Ethereum.getAccount({
    mnemonic,
    path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
  });
  return ethereumAccount;
};

A. Returns

interface Account {
  address: string;
  publicKey: string;
}

B. Params

typeof mnemonic === string; // "your private mnemonic"

C. Examples

  • By following this link, you can see the example code.

  • You can execute the example code through the command below.

    1. git clone https://github.com/dsrvlabs/kms-monorepo
    2. Create the mnemonic.json file inside the packages/examples (follow the format of this link)
    3. yarn && yarn build
    4. yarn start:example getAccountPlayground.ts

2. getPrivateKey

Through getPrivateKey method, you can get a private key of your mnemonic.

import { CHAIN, Ethereum } from '@dsrv/kms';

/* Ethereum getPrivateKey */
export const getEthereumPrivateKey = (mnemonic: string): string => {
  const ethereumPrivateKey = Ethereum.getPrivateKey({
    mnemonic,
    path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
  });
  return ethereumPrivateKey;
};

A. Returns

typeof privateKey === string;

B. Params

typeof mnemonic === string; // "your private mnemonic"

C. Examples

  • By following this link, you can see the example code.

  • You can execute the example code through the command below.

    1. git clone https://github.com/dsrvlabs/kms-monorepo
    2. Create the mnemonic.json file inside the packages/examples (follow the format of this link)
    3. yarn && yarn build
    4. yarn start:example getPrivateKeyPlayground.ts

3. signTx (getSignature)

Through signTx method, you can get a signature for the transaction.

import { CHAIN, Ethereum } from '@dsrv/kms';

const { signature } = Ethereum.signTx(
  {
    mnemonic,
    path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
  },
  serializedTx, // must be hex string
);

A. Returns

interface SignedTx {
  unsignedTx: string;
  signature: string;
}

B. Params

typeof serializedTx === string; // must be hex string

C. Useage

Through kms, you can get a signature for the transaction. The steps listed below should be followed in order to sign the transaction through kms.

  1. Create raw transactions for each chain using the SDK.
  2. To obtain a signature for the transaction, add the created raw transaction as a signTx method factor of kms.
  3. The raw transaction is joined with the signature from kms to create a signed transaction.
import { Ethereum } from '@dsrv/kms';

export const getEthereumSignedTx = async (mnemonic: string) => {
  // 1. Create raw transactions for each chain using the SDK.
  // getEthereumTx is a custom method created to get raw transaction back.
  const { serializedTx, unSignedTx } = await getEthereumTx(mnemonic);

  // 2. The signature value for transaction is received through the signTx method of kms.
  const ethereumSignature = Ethereum.signTx(
    {
      mnemonic,
      path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
    },
    serializedTx,
  );

  // 3.The raw transaction generated above and the signature received through kms are combined to create a signed transaction.
  // createEthereumSignedTx is a custom method for returning signedTransaction by combining signature and raw transaction.
  const ethereumSignedTx = createEthereumSignedTx({
    unSignedTx,
    signature: ethereumSignature.signature,
  });

  return { ethereumSignedTx, signature: ethereumSignature.signature };
};

D. Example

  • By following this link, you can see the example code.

  • You can execute the example code through the command below.

    1. git clone https://github.com/dsrvlabs/kms-monorepo
    2. Create the mnemonic.json file inside the packages/examples (follow the format of this link)
    3. yarn && yarn build
    4. yarn start:example signTxPlayground.ts

4. sendTransaction

Transactions can be transferred via the signedTransaction created above. However, a faucet is required to transmit the transaction.

  • By following this link, you can see the example code.

  • You can execute the example code through the command below.

    1. git clone https://github.com/dsrvlabs/kms-monorepo
    2. Create the mnemonic.json file inside the packages/examples (follow the format of this link)
    3. yarn && yarn build
    4. yarn start:example sendTransactionPlayground.ts

Test getAccount, signature

  1. yarn && yarn build:kms
  2. yarn test:examples