@2waychain/2wayjs
Version:
API wrapper to access the AIBlock 2 Way Chain
115 lines (114 loc) • 4.36 kB
TypeScript
import { IKeypair, IMasterKey, IResult } from '../interfaces';
/**
* Get the address version for either a given public key and address
* , or a version number
*
* The result is formatted for network operations
*
* @param {Uint8Array} publicKey - Public key
* @param {string} address - Public address associated with public key
* @param version - Address version
* @return {*} {(number | null)}
*/
export declare function getAddressVersion(publicKey?: Uint8Array, address?: string, version?: number | null): IResult<number | null>;
/**
* Generates a new seed phrase
*/
export declare function generateSeed(): IResult<string>;
/**
* Converts the given passphrase to a 32 byte Uint8Array
*
* @param passphrase {string} - Passphrase as a string
*/
export declare function getPassphraseBuffer(passphrase: string): IResult<Uint8Array>;
/**
* Generates a new master key, seed phrase optional.
* If no seed phrase is provided, a new one will be generated and returned.
* If a seed phrase is provided, it's assumed to be in `Buffer` format
*
* @param seed {string} - Seed phrase
* @param passphrase {string} - Passphrase as a string
*/
export declare function generateMasterKey(seed?: string, passphrase?: string): IResult<IMasterKey>;
/**
* Generates a new keypair, potentially from seed
*
* @export
* @param {*} [version=ADDRESS_VERSION] - Address version
* @param {Uint8Array} [seed] - Seed phrase as UInt8Array
* @return {*} {IResult<IKeypair>}
*/
export declare function generateKeypair(version?: null, seed?: Uint8Array): IResult<IKeypair>;
/**
* Generates the next keypair at a given derivation depth
*
* @export
* @param {IMasterKey} masterKey - Master key in an unencrypted format
* @param {number} depth - Desired derivation depth
* @param {*} [version=ADDRESS_VERSION] - Address version
* @return {*} {IResult<IKeypair>}
*/
export declare function getNextDerivedKeypair(masterKey: IMasterKey, depth: number, version?: null): IResult<IKeypair>;
/**
* Constructs an address from the provided public key
*
* @param publicKey {Uint8Array} - Public key as Uint8Array
* @param version {number} - Address version
*/
export declare function constructAddress(publicKey: Uint8Array, version: number | null): IResult<string>;
/**
* Constructs the address from the provided public key given the old address version.
*
* @param publicKey {Uint8Array}- Public key as Uint8Array
* @returns
*/
export declare function constructVersionOldAddress(publicKey: Uint8Array): IResult<string>;
/**
* Constructs the address from the provided public key given the default version.
*
* @param publicKey {Uint8Array}- Public key as Uint8Array
* @returns
*/
export declare function constructVersionDefaultAddress(publicKey: Uint8Array): IResult<string>;
/**
* Constructs the address from the provided public key given the temporary version.
* NOTE: Not to be used unless specifically needed
*
* @param publicKey {Uint8Array} - Public key as Uint8Array
* @returns
*/
export declare function constructVersionTempAddress(publicKey: Uint8Array): IResult<string>;
/**
* Signs a message with a provided private key
*
* @param secretKey {Uint8Array} - Secret key used to sign the message as Uint8Array
* @param message {Uint8Array} - Message to sign as Uint8Array
*/
export declare function createSignature(secretKey: Uint8Array, message: Uint8Array): Uint8Array;
/**
* Generates a new keypair from a given master key and address version
*
* TODO: Use a provided depth instead of the entire address list
*
* @export
* @param {IMasterKey} masterKey - Master key in an unencrypted format
* @param {(number | null)} addressVersion - Address version
* @param {string[]} addresses - A list of all existing public addresses
* @return {*} {IResult<IKeypair>}
*/
export declare function generateNewKeypairAndAddress(masterKey: IMasterKey, addressVersion: number | null | undefined, addresses: string[]): IResult<IKeypair>;
/**
* Test a seed phrase
*
* @export
* @param {string} seed
* @return {*} {boolean}
*/
export declare function testSeedPhrase(seed: string): boolean;
/**
* Generate a seed phrase
*
* @export
* @return {*} {string}
*/
export declare function generateSeedPhrase(): string;