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

@pokt-foundation/pocketjs-signer

v2.2.1

Published

Signer for Pocket Network V0 accounts

Downloads

299

Readme

Key Manager

This package houses both the abstract Key Manager interface we expose to people so that they build their own KeyManager, and an actual KeyManager ready to use for handling account-related operations.

Installation

Install through your package manager of choice:

pnpm install @pokt-foundation/pocketjs-signer

Usage

import { AbstractSigner, KeyManager } from '@pokt-foundation/pocketjs-signer'

// For the AbstractSigner, just implement it!
class MySigner extends AbstractSigner {
 // Now override the required methods...
}

// For the KeyManager, there's a few ways you can initialize it:
// 1. Create a random (new) account with the KeyManager
const randomAccount = await KeyManager.createRandom()

// 2. Use a private key you own
const account = await KeyManager.fromPrivateKey(process.env.PRIVATE_KEY);

// 3. Use a Portable-Private-Key file, stringified.
// A PPK is generated by exporting an account through the `exportPPK` method.
const ppkAccount = await KeyManager.fromPPK({ password: process.env.PASS, ppk: process.env.PPK })

// Now, you can use it!
// Get your address
const address = account.getAddress()

// Get your public key 
const publicKey = account.getPublicKey()

// Sign a message
const signedCoffee = account.sign("0xcafe")

KeyManager API

Constructor

Instanciating through the constructor is only possible if all params are known beforehand. If not, use one of the initialization methods provided.

address

  • type: 'String' The address of the account to instanciate manually.

privateKey

  • type: 'String' The private key of the account to instanciate manually.

publicKey

  • type: 'String' The public key of the account to instanciate manually.

Methods

static createRandom(): Promise

Creates a new, random pocket account. Can be called from the base class as it's static.

Returns a Promise<KeyManager>: The new key manager instance with the account attached.

static fromPrivateKey(privateKey): Promise

Instanciates a new KeyManager from a valid ED25519 private key.

Returns a Promise<KeyManager>: The new key manager instance with the account attached.

| Param | Type | Description | |------------|----------|-------------------------------------------------------| | privateKey | string | The private key to use for instanciating the account. |

static fromPPK({ password, ppk }): Promise

Instanciates a new KeyManager from a valid Portable-Private-Key file.

Returns a Promise<KeyManager>: The new key manager instance with the account attached.

| Param | Type | Description | |----------|----------|----------------------------------------------------------| | password | string | The password of the account to instanciate from the PPK. | | ppk | string | PPK, stringified. (PPKs are valid JSON files) |

exportPPK({ privateKey, password, hint }): Promise

Exports a provided private key as a Portable-Private-Key, unlockable with the provided password.

Returns a Promise<string>: A PPK, in stringified manner.

| Param | Type | Description | |------------|----------|-----------------------------------------| | password | string | The password to use in the PPK. | | privateKey | string | The private key to create the PPK from. | | hint | string | The password hint. |

exportPPK({ password, hint }): Promise

Exports the current account's private key as a Portable-Private-Key, unlockable with the provided password.

Returns a Promise<string>: A PPK, in stringified manner.

| Param | Type | Description | |------------|----------|-----------------------------------------| | password | string | The password to use in the PPK. | | hint | string | The password hint. |

sign(payload): Promise

Signs a valid hex-string payload with the imported private key.

Returns a Promise<string>: The signed payload as a string.

| Param | Type | Description | |---------|----------|--------------------------| | payload | string | The hex payload to sign. |

getAddress(): string

Gets the account address.

Returns string: The attached account's address.

getPublicKey(): string.

Gets teh account public key.

Returns string: The attached account's public key.

getPrivateKey(): string

Gets the account private key.

Returns string: The attached account's private key.

getAccount(): Account

Gets the attached account.

Returns Account: The attached account in its entirety in an object.