@neuraiproject/neurai-key
Version:
Generate Neurai addresses from mnemonic code. BIP32, BIP39, BIP44
154 lines (148 loc) • 7.29 kB
TypeScript
interface IAddressObject {
address: string;
mnemonic?: string;
network?: string;
path: string;
publicKey: string;
privateKey: string;
WIF: string;
}
type AuthType = 0x00 | 0x01 | 0x02;
interface AuthScriptOptions {
authType?: AuthType;
witnessScript?: Uint8Array | string;
}
type PQAddressOptions = AuthScriptOptions;
interface IPQAddressObject {
address: string;
mnemonic?: string;
path: string;
publicKey: string;
privateKey: string;
seedKey: string;
authType: 0x01;
authDescriptor: string;
commitment: string;
witnessScript: string;
}
interface INoAuthAddressObject {
address: string;
authType: 0x00;
commitment: string;
witnessScript: string;
}
interface ILegacyAuthScriptAddressObject {
address: string;
path?: string;
publicKey: string;
privateKey: string;
WIF: string;
authType: 0x02;
authDescriptor: string;
commitment: string;
witnessScript: string;
}
type PQNetwork = "xna-pq" | "xna-pq-test";
type Network = "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test";
interface Bip32Versions {
private: number;
public: number;
}
declare class HDKey {
versions: Bip32Versions;
depth: number;
index: number;
chainCode: Uint8Array;
parentFingerprint: number;
privateKey?: Uint8Array;
publicKey: Uint8Array;
constructor(versions: Bip32Versions, chainCode: Uint8Array, publicKey: Uint8Array, privateKey?: Uint8Array, depth?: number, index?: number, parentFingerprint?: number);
static fromMasterSeed(seed: Uint8Array, versions: Bip32Versions): HDKey;
get fingerprint(): number;
get privateExtendedKey(): string | null;
get publicExtendedKey(): string;
derive(path: string): HDKey;
deriveChild(index: number): HDKey;
}
declare const BIP32_PQ_EXTKEY_SIZE = 74;
declare class PQHDKey {
readonly depth: number;
readonly index: number;
readonly parentFingerprint: Uint8Array;
readonly chainCode: Uint8Array;
readonly pqSeed: Uint8Array;
private _publicKey?;
private _secretKey?;
constructor(depth: number, index: number, parentFingerprint: Uint8Array, chainCode: Uint8Array, pqSeed: Uint8Array);
static fromMasterSeed(seed: Uint8Array): PQHDKey;
private ensureKeypair;
get publicKey(): Uint8Array;
get secretKey(): Uint8Array;
get fingerprint(): Uint8Array;
deriveChild(index: number): PQHDKey;
encode(): Uint8Array;
encodeBase58Check(version: number): string;
static decode(raw: Uint8Array, parentFingerprint?: Uint8Array): PQHDKey;
static decodeBase58Check(extKey: string, expectedVersion: number): PQHDKey;
derive(path: string): PQHDKey;
}
declare function getCoinType(network: Network): number;
declare function getAddressPair(network: Network, mnemonic: string, account: number, position: number, passphrase?: string): {
internal: IAddressObject;
external: IAddressObject;
position: number;
};
declare function getHDKey(network: Network, mnemonic: string, passphrase?: string): HDKey;
declare function getAddressByPath(network: Network, hdKey: HDKey, path: string): IAddressObject;
declare function generateMnemonic(): string;
declare function isMnemonicValid(mnemonic: string): boolean;
declare function getAddressByWIF(network: Network, privateKeyWIF: string): {
address: string;
privateKey: string;
WIF: string;
};
declare function getPubkeyByWIF(_network: Network, privateKeyWIF: string): string;
declare function entropyToMnemonic(entropy: Uint8Array | string): string;
declare function generateAddressObject(network?: Network, passphrase?: string): IAddressObject;
declare function publicKeyToAddress(network: Network, publicKey: Uint8Array | string): string;
declare function generateAddress(network?: Network): IAddressObject;
declare function getPQHDKey(_network: PQNetwork, mnemonic: string, passphrase?: string): PQHDKey;
declare function pqExtendedPrivateKey(network: PQNetwork, hdKey: PQHDKey): string;
declare function pqHDKeyFromExtended(network: PQNetwork, extKey: string): PQHDKey;
declare function getPQAddressByPath(network: PQNetwork, hdKey: PQHDKey, path: string, options?: PQAddressOptions): IPQAddressObject;
declare function getNoAuthAddress(network: PQNetwork, options?: AuthScriptOptions): INoAuthAddressObject;
declare function getLegacyAuthScriptAddress(network: PQNetwork, legacyNetwork: Network, mnemonic: string, account: number, index: number, passphrase?: string, options?: AuthScriptOptions): ILegacyAuthScriptAddressObject;
declare function getLegacyAuthScriptAddressByWIF(network: PQNetwork, wif: string, options?: AuthScriptOptions): ILegacyAuthScriptAddressObject;
declare function getPQAddress(network: PQNetwork, mnemonic: string, account: number, index: number, passphrase?: string, options?: PQAddressOptions): IPQAddressObject;
declare function pqPublicKeyToAddress(network: PQNetwork, publicKey: Uint8Array | string, options?: PQAddressOptions): string;
declare function pqPublicKeyToCommitmentHex(publicKey: Uint8Array | string, options?: PQAddressOptions): string;
declare function pqPublicKeyToAuthDescriptorHex(publicKey: Uint8Array | string): string;
declare function generatePQAddressObject(network?: PQNetwork, passphrase?: string, options?: PQAddressOptions): IPQAddressObject;
declare const NeuraiKey: {
entropyToMnemonic: typeof entropyToMnemonic;
generateAddress: typeof generateAddress;
generateAddressObject: typeof generateAddressObject;
generateMnemonic: typeof generateMnemonic;
getAddressByPath: typeof getAddressByPath;
getAddressByWIF: typeof getAddressByWIF;
getPubkeyByWIF: typeof getPubkeyByWIF;
getAddressPair: typeof getAddressPair;
getCoinType: typeof getCoinType;
getHDKey: typeof getHDKey;
isMnemonicValid: typeof isMnemonicValid;
publicKeyToAddress: typeof publicKeyToAddress;
getPQAddress: typeof getPQAddress;
getPQAddressByPath: typeof getPQAddressByPath;
getPQHDKey: typeof getPQHDKey;
pqExtendedPrivateKey: typeof pqExtendedPrivateKey;
pqHDKeyFromExtended: typeof pqHDKeyFromExtended;
getNoAuthAddress: typeof getNoAuthAddress;
getLegacyAuthScriptAddress: typeof getLegacyAuthScriptAddress;
getLegacyAuthScriptAddressByWIF: typeof getLegacyAuthScriptAddressByWIF;
pqPublicKeyToAddress: typeof pqPublicKeyToAddress;
pqPublicKeyToAuthDescriptorHex: typeof pqPublicKeyToAuthDescriptorHex;
pqPublicKeyToCommitmentHex: typeof pqPublicKeyToCommitmentHex;
generatePQAddressObject: typeof generatePQAddressObject;
};
export { BIP32_PQ_EXTKEY_SIZE, HDKey, PQHDKey, NeuraiKey as default, entropyToMnemonic, generateAddress, generateAddressObject, generateMnemonic, generatePQAddressObject, getAddressByPath, getAddressByWIF, getAddressPair, getCoinType, getHDKey, getLegacyAuthScriptAddress, getLegacyAuthScriptAddressByWIF, getNoAuthAddress, getPQAddress, getPQAddressByPath, getPQHDKey, getPubkeyByWIF, isMnemonicValid, pqExtendedPrivateKey, pqHDKeyFromExtended, pqPublicKeyToAddress, pqPublicKeyToAuthDescriptorHex, pqPublicKeyToCommitmentHex, publicKeyToAddress };
export type { AuthScriptOptions, IAddressObject, ILegacyAuthScriptAddressObject, INoAuthAddressObject, IPQAddressObject, Network, PQAddressOptions, PQNetwork };