1.0.1 • Published 3 years ago

chia-wallet-utils v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

chia-wallet-utils code style: prettier

Typescript implementation for Chia Offline Wallet for node and browser.

Usage

Use NPM in node.js / browser

npm install chia-wallet-utils

Example

import { Wallet, TxInput, SpendBundle } from 'chia-wallet-utils';

// Create a wallet  with privatekey.
// FromPrivatekey(privatekey: string | Uint8Array, password: string | Uint8Array, description?: string, path?: string): Promise<Wallet>;
let wallet = await Wallet.FromPrivatekey(
    myWallet.privateKey,
    passowrd,
    'test for sign',
    'm/12381/8444/2/0'
);

// Create a wallet  with mnemonic.
// FromMnemonic(mnemonic: string, password: string | Uint8Array, description?: string, path?: string): Promise<Wallet>;
let wallet = await Wallet.FromMnemonic(
    myWallet.mnemonic,
    passowrd,
    'test for sign',
    'm/12381/8444/2/0'
);

// generate a Wallet.
// generateWallet(password: string | Uint8Array, description?: string, strength?: number): Promise<{mnemonic: string; wallet: Wallet;}>;
let { mnemonic, wallet } = await Wallet.generateWallet(passowrd, 'test for sign');

await wallet.verifyPassword('wrong'); // false

let input = new TxInput(passowrd, amount, to, coins);
let spend = await wallet.generateSignedTransaction(input);

let txhash = spendBundle.name();

API

address_to_pk(privateKey)
function address_to_pk(address: string): string;
pk_to_address(privateKey)
function pk_to_address(publickey: ArrayLike<number>): string;
create_puzzlehash_for_pk(publickey)
function create_puzzlehash_for_pk(publickey: string | Uint8Array): string;

Contributing

  1. Clone the repository.
  2. npm install to install build dependencies like TypeScript
  3. npm run build to compile TypeScript code
  4. npm run test to run jest on test/index.ts

License

MIT