mirror of
https://github.com/stjet/banani.git
synced 2025-12-29 09:39:23 +00:00
the important stuff
This commit is contained in:
25
wallet.ts
Normal file
25
wallet.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as util from "./util";
|
||||
import type { RPCInterface } from "./rpc";
|
||||
|
||||
/** Wallets are created from seeds, so they can have multiple addresses by changing the index. Use Wallets to "write" (send, receive, change rep) to the network */
|
||||
export class Wallet {
|
||||
readonly seed: string;
|
||||
readonly rpc: RPCInterface;
|
||||
index: number = 0;
|
||||
|
||||
/**
|
||||
* @param {string} [seed] Seed for the wallet from which private keys are derived. 64 character hex string (32 bytes)
|
||||
*/
|
||||
constructor(rpc: RPCInterface, seed: string) {
|
||||
this.seed = seed;
|
||||
}
|
||||
/** Generate a cryptographically secure random wallet using [crypto.getRandomValues](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) */
|
||||
static gen_random_wallet(rpc: RPCInterface): Wallet {
|
||||
let random_bytes = new Uint8Array(32);
|
||||
crypto.getRandomValues(random_bytes);
|
||||
const random_seed = util.uint8array_to_hex(random_bytes);
|
||||
return new Wallet(rpc, random_seed);
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user