JSPM

@plugnet/wallet

0.20.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q63386F
  • License Apache-2.0

wallet implementation for Plugnet

Package Exports

  • @plugnet/wallet
  • @plugnet/wallet/decorators
  • @plugnet/wallet/types

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@plugnet/wallet) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@plugnet/wallet

a wallet and raw payload signer implementation for plugnet

Usage

Create a Wallet with HD-Keyring

import {Wallet} from '@plugnet/wallet';

const wallet = new Wallet();
await wallet.createNewVault('a passphrase');
// By default it comes with a HD Keyring
// to specify hdPath of HDKeyring, 
await wallet.createNewVault('a passphrase', {hdPath: '...'});

Backup your wallet

const backup = await wallet.export('a passphrase');
// [{mnemonic, numberOfAccounts,hdPath}]

Reload your wallet

vault = wallet.vault;
wallet2 = new Wallet({vault});
//add keyringTypes: [HDKeyring, SimpleKeyring] if SimpleKeyring is used
await wallet2.unlock(<same passphrase>)

Restore wallet and reset password

mnemonic='ready whisper vapor penalty load gesture elite brick select light caution clever';
hdKeyring=new HDKeyring({mnemonic});
wallet = new Wallet();
wallet.createNewVaultAndRestore('newpass', [hdKeyring]);

Backup an account

const json = await wallet.exportAccount(address, passphrase);

Import single account

const TEST_ACCOUNT = {
    seed: '0x3cf2ec6ffd26587529ab06c82ba9b33110198085f5c6b8d882653d056bf9e0d3',
    address: '5DHzypfuQH7FPhCsrqMxpxkBaPHe8QNhc5s1PwEMDc5p5Nb7',
    publicKey: '0x366010e706af618a6037731b07663d4b6f10eac201c7fdd5fb0bd4727742524d',
    mnemonic: 'insane push cradle toilet token gate chair trim spare blush rebuild top',
};
const keyring = new SimpleKeyring();
await keyring.addPair(alice);
//or
keyring.addFromSeed(hexToU8a(TEST_ACCOUNT.seed));
//or
keyring.addFromMnemonic(TEST_ACCOUNT.mnemonic);
await wallet.addKeyring(keyring);

lock/unlock

await wallet.lock();
// methods marked as @requireUnlocked such as sign, addAccount and etc will fail
await wallet.unlock(passphrase);

generate random account via the default keyring

const address = await wallet.addAccount();

Sign a payload

const payload = {
type: 'payload',
data: '0x01a1f9000051',
address: ...[signing account address]
}

const signature = await wallet.sign(payload);