UNPKG

hive-multisign

Version:

A typescript utility for multi-signature transactions on the Hive blockchain

111 lines (110 loc) 4.93 kB
import { AuthorityType, KeyRole, Operation, PrivateKey, PublicKey, SignedTransaction, Transaction, TransactionConfirmation } from '@hiveio/dhive'; export interface IAccountAuthority { weight_threshold: number; account_auths?: [string, number][]; key_auths?: [string, number][]; } /** * Get user authorities (owner, active, posting) * @param username * @returns */ export declare const getUserAuthorities: (username: string) => Promise<{ owner: IAccountAuthority; active: IAccountAuthority; posting: IAccountAuthority; }>; /** * Generate many private keys for the account. Each private key is associated with one password. * @param username account username * @param passwords array of passwords, one of which must be the account's master password * @param role key role (e.g. 'posting') */ export declare const generatePrivateKeys: (username: string, passwords: string[], role: KeyRole) => PrivateKey[]; /** * Generate the public keys associated with the specified private keys. * @param privateKeys private keys * @returns */ export declare const generatePublicKeys: (privateKeys: string[] | PrivateKey[]) => string[]; /** * Generate the object needed to send an account authority update. * @param username account username * @param threshold weight threshold * @param accountAuths account authorities [username, weight] * @param keyAuths key authorities [public_key, weight] * @param role key role (e.g. 'posting') * @param replace Replace the old authorities instead of appending to them * @returns */ export declare const generateAuthChangeObject: (username: string, threshold: number, accountAuths: [string, number][], keyAuths: [string, number][], role: KeyRole, replace?: { account?: boolean; key?: boolean; }) => Promise<{ account: string; owner?: AuthorityType | undefined; active?: AuthorityType | undefined; posting?: AuthorityType | undefined; memo_key: string | PublicKey; json_metadata: string; }>; /** * Replace the chosen authority with the keys specified. * @param username account username * @param privateActive private active key * @param threshold wight threshold required to broadcast a transaction * @param keyAuths [public_key, weight] * @param replace Replace the old authorities instead of appending to them * @returns */ export declare const updateAuths: (username: string, privateActive: string, threshold: number, accountAuths: [string, number][], keyAuths: [string, number][], role: KeyRole, replace?: { account?: boolean; key?: boolean; }) => Promise<TransactionConfirmation>; /** * Add an authority for each password. Set the threshold such that a signature from each of them is required. * @param username account username * @param privateActive private active key * @param passwords array of passowrds * @param role key role (e.g. 'posting') * @returns */ export declare const assignUnifromAuth: (username: string, privateActive: string, passwords: string[], role: KeyRole) => Promise<TransactionConfirmation>; /** * Prepare a transaction that needs to be signed. * @param operations operations * @param expireTime expire time [ms] in [0, 3590*1000] * @returns */ export declare const prepareTrx: (operations: Operation[], expireTime?: number) => Promise<Transaction>; /** * Check if the specified transaction has enough signatures to be broadcasted to the blockchain. * @param trx singed transaction * @returns */ export declare const hasEnoughSignatures: (trx: SignedTransaction) => Promise<boolean>; /** * Broadcast a signed transaction. * @param signedTrx signed transaction * @returns */ export declare const sendTrx: (signedTrx: SignedTransaction) => Promise<TransactionConfirmation>; /** * Test the multisign system. We reccomend testing on a disposable account. * The test changes the posting authorities, requiring 2 signatures to send transactions and sends a test transaction to * verify it works. * IMPORTANT: this method will change your posting authority keys, if you want to go back to the original one you need to run * the function 'resetOriginalKey'. * @param username account username * @param privateActive private active key * @returns */ export declare const demo: (username: string, privateActive: string) => Promise<TransactionConfirmation>; /** * Reset your posting key to the original. If you can't find your master password don't worry, choose a password now and * then go to your wallet and change your posting key to the one generated here. * @param username account username * @param privateActive private active key * @param masterPassword master password, it was given to you along with the other keys */ export declare const resetOriginalKey: (username: string, privateActive: string, masterPassword: string) => Promise<void>;