# @0xbigboss/pocketjs-signer

> Signer for Pocket Network V0 accounts

Latest version **2.1.1** (published 2022-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @0xbigboss/pocketjs-signer
pnpm add @0xbigboss/pocketjs-signer
yarn add @0xbigboss/pocketjs-signer
bun add @0xbigboss/pocketjs-signer
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2022-10-30 |
| First published | 2022-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 226.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | 0xbigboss |

## Links

- npm: https://www.npmjs.com/package/@0xbigboss/pocketjs-signer
- npm.io page: https://npm.io/package/@0xbigboss/pocketjs-signer

## Dependencies (9)

- [debug](https://npm.io/package/debug.md) ^4.3.3
- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [scrypt-js](https://npm.io/package/scrypt-js.md) ^3.0.1
- [@noble/ed25519](https://npm.io/package/@noble/ed25519.md) ^1.5.3
- [isomorphic-crypto](https://npm.io/package/isomorphic-crypto.md) ^3.0.0
- [libsodium-wrappers](https://npm.io/package/libsodium-wrappers.md) ^0.7.9
- [@0xbigboss/pocketjs-utils](https://npm.io/package/@0xbigboss/pocketjs-utils.md) 2.1.1
- [@0xbigboss/pocketjs-provider](https://npm.io/package/@0xbigboss/pocketjs-provider.md) 2.1.1
- [@0xbigboss/pocketjs-abstract-provider](https://npm.io/package/@0xbigboss/pocketjs-abstract-provider.md) 2.1.1

## Recent versions

- 2.1.1 (latest) — 2022-10-30
- 2.1.0 — 2022-10-02

## 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

```js 
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<KeyManager>
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<KeyManager>
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<KeyManager>
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<string>
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<string>
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<string>
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.

---
_Source: https://npm.io/package/@0xbigboss/pocketjs-signer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
