chaingate
Version:
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
171 lines (170 loc) • 6.41 kB
TypeScript
import { PhraseLanguage, PhraseNumOfWords } from './Wallet/SigningWallet/HDWallet/PhraseWallet/Phrase';
import { PhraseWallet } from './Wallet/SigningWallet/HDWallet/PhraseWallet/PhraseWallet';
import { SeedWallet } from './Wallet/SigningWallet/HDWallet/SeedWallet/SeedWallet';
import { XprivWallet } from './Wallet/SigningWallet/HDWallet/XprivWallet/XprivWallet';
import { PrivateKeyWallet } from './Wallet/SigningWallet/PrivateKeyWallet/PrivateKeyWallet';
import { XpubWallet } from './Wallet/ViewOnlyWallet/XpubWallet/XpubWallet';
import { PublicKeyWallet } from './Wallet/ViewOnlyWallet/PublicKeyWallet/PublicKeyWallet';
import { WalletSerialized } from './Wallet/WalletSerialized';
/** Detected input format. Returned by {@link detectWalletImportType}. */
export type InputType = 'phrase' | 'xpriv' | 'xpub' | 'wif' | 'seed' | 'privateKey' | 'publicKey';
/** Parameters for {@link importWallet}. Provide exactly one property. */
export type WalletParams = {
phrase: string;
} | {
seed: string | Uint8Array;
} | {
xpriv: string;
} | {
privateKey: string | Uint8Array;
} | {
xpub: string;
} | {
publicKey: string | Uint8Array;
};
/**
* Detects what type of wallet input a string is (phrase, xpriv, xpub, WIF, seed, private/public key).
*
* @param input - The string to analyze.
* @throws {@link UnrecognizedFormatError} if the format cannot be identified.
*/
export declare function detectWalletImportType(input: string): InputType;
export type AnyWallet = PhraseWallet | SeedWallet | XprivWallet | PrivateKeyWallet | XpubWallet | PublicKeyWallet;
/**
* Generates a new random mnemonic phrase and creates an HD wallet.
*
* @param language - Wordlist language. Defaults to `'english'`.
* @param numberOfWords - Word count. Defaults to `12`.
* @returns The mnemonic `phrase` and the created `wallet`.
*
* @example
* ```ts
* const { phrase, wallet } = newWallet();
* const key = await wallet.derive("m/44'/60'/0'/0/0");
* ```
*/
export declare function newWallet(language?: PhraseLanguage, numberOfWords?: PhraseNumOfWords): {
phrase: string;
wallet: PhraseWallet;
};
/**
* Creates a wallet from explicit parameters.
*
* @param params - Exactly one property: `phrase`, `seed`, `xpriv`, `privateKey`, `xpub`, or `publicKey`.
* @throws {@link InvalidWalletParamsError} if invalid.
*
* @example
* ```ts
* const wallet = importWallet({ phrase: 'abandon abandon ... about' });
* const wallet = importWallet({ privateKey: 'deadbeef...' });
* ```
*/
export declare function importWallet(params: {
phrase: string;
}): PhraseWallet;
export declare function importWallet(params: {
seed: string | Uint8Array;
}): SeedWallet;
export declare function importWallet(params: {
xpriv: string;
}): XprivWallet;
export declare function importWallet(params: {
privateKey: string | Uint8Array;
}): PrivateKeyWallet;
export declare function importWallet(params: {
xpub: string;
}): XpubWallet;
export declare function importWallet(params: {
publicKey: string | Uint8Array;
}): PublicKeyWallet;
export declare function importWallet(params: WalletParams): AnyWallet;
/**
* Type guard — checks if unknown data is a valid {@link WalletSerialized}.
*
* @param data - The data to validate.
*/
export declare function isValidSerialized(data: unknown): data is WalletSerialized;
/**
* Restores a wallet from serialized data (produced by {@link Wallet.serialize}).
*
* @param data - The serialized wallet data.
* @param askForPassword - Password prompt callback. Required for encrypted wallets.
* @throws {@link InvalidWalletExportError} if the data is invalid.
*
* @example
* ```ts
* const wallet = deserializeWallet(JSON.parse(stored), async () => {
* return prompt('Enter password:');
* });
* ```
*/
export declare function deserializeWallet(data: unknown, askForPassword?: () => Promise<string | null>): AnyWallet;
/**
* Auto-detects the format of a string and creates the appropriate wallet.
*
* @param input - Phrase, xpriv, xpub, WIF, hex key, etc.
* @throws {@link UnrecognizedFormatError} if the format cannot be identified.
*
* @example
* ```ts
* const wallet = createWalletFromString('abandon abandon ... about');
* const wallet = createWalletFromString('xpub6CUGRUo...');
* ```
*/
export declare function createWalletFromString(input: string): AnyWallet;
/**
* Checks whether a JSON string is a recognized keystore format (V1 Legacy or V3 Web3).
*
* @param keystore - The JSON string to check.
* @returns `true` if the JSON is a valid V1 or V3 keystore.
*
* @example
* ```ts
* if (isValidKeystore(jsonString)) {
* const wallet = await importFromKeystore(jsonString, 'myPassword');
* }
* ```
*/
export declare function isValidKeystore(keystore: string): boolean;
/**
* Imports a wallet from an encrypted keystore JSON (V1 Legacy or V3 Web3
* format, as used by MetaMask, MyEtherWallet, Geth, etc.).
*
* The keystore is decrypted with the given password. The decrypted secret is
* auto-detected as either a mnemonic phrase (returns {@link PhraseWallet}) or
* a raw private key (returns {@link PrivateKeyWallet}).
*
* @param keystore - The keystore JSON string.
* @param password - The decryption password.
* @returns The appropriate wallet type based on the decrypted contents.
*
* @throws {@link InvalidKeystoreError} if the JSON is not a recognized keystore.
* @throws {@link IncorrectKeystorePasswordError} if the password is wrong.
*
* @example
* ```ts
* const wallet = await importFromKeystore(keystoreJson, 'my-password');
* ```
*/
export declare function importFromKeystore(keystore: string, password: string): Promise<PhraseWallet | PrivateKeyWallet>;
/**
* Checks whether a string is a valid BIP-39 mnemonic phrase.
*
* @param phrase - The mnemonic phrase to validate.
* @returns `true` if valid.
*/
export declare function isValidPhrase(phrase: string): boolean;
/**
* Checks whether a value is a valid HD seed (hex string or bytes).
*
* @param seed - The seed to validate (hex string or `Uint8Array`).
* @returns `true` if valid.
*/
export declare function isValidSeed(seed: string | Uint8Array): boolean;
/**
* Checks whether a value is a valid secp256k1 private key (hex, WIF, or bytes).
*
* @param privateKey - The private key to validate.
* @returns `true` if valid.
*/
export declare function isValidPrivateKey(privateKey: string | Uint8Array): boolean;