1.0.1 • Published 4 years ago
chia-wallet-utils v1.0.1
chia-wallet-utils 
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
- Clone the repository.
npm install
to install build dependencies like TypeScriptnpm run build
to compile TypeScript codenpm run test
to run jest ontest/index.ts
License
MIT