micro-stacks
Version:
Tiny libraries for building Stacks apps.
133 lines (114 loc) • 5.25 kB
TypeScript
import { Profile } from 'micro-stacks/connect';
import { HDKey } from '@scure/bip32';
import { StacksNetworkVersion } from 'micro-stacks/crypto';
import * as micro_stacks_storage from 'micro-stacks/storage';
import { GaiaHubConfig } from 'micro-stacks/storage';
declare type AllowedKeyEntropyBits = 128 | 256;
interface WalletKeys {
salt: string;
rootKey: string;
configPrivateKey: string;
}
interface Wallet extends WalletKeys {
encryptedSecretKey: string;
accounts: Account[];
}
interface LockedWallet {
encryptedSecretKey: string;
}
interface Account {
stxPrivateKey: string;
dataPrivateKey: string;
salt: string;
username?: string;
profile?: Profile;
appsKey: string;
index: number;
}
interface ConfigApp {
origin: string;
scopes: string[];
lastLoginAt: number;
appIcon: string;
name: string;
}
interface ConfigAccount {
username?: string;
apps: {
[origin: string]: ConfigApp;
};
}
interface WalletConfig {
accounts: ConfigAccount[];
meta?: {
[key: string]: any;
};
}
declare function generateSecretKey(entropy?: AllowedKeyEntropyBits): string;
declare function generateWallet(mnemonic: string, password: string): Promise<Wallet>;
declare function generateAndInsertNewAccount(wallet: Wallet): Wallet;
declare const deriveConfigPrivateKey: (rootNode: HDKey) => string;
declare const deriveLegacyConfigPrivateKey: (rootKey: string) => string;
declare function deriveSalt(rootNode: HDKey): string;
declare function deriveWalletKeys(rootNode: HDKey): WalletKeys;
declare function deriveAccount(rootNode: HDKey, index: number, salt: string): Account;
declare function deriveNextAccountFromWallet(wallet: Wallet): Account;
declare function deriveManyAccountsForWallet(wallet: Wallet, count: number, startingIndex?: number): Account[];
declare function getStxAddressFromAccount(account: Account, networkVersion?: StacksNetworkVersion): string;
declare function getAppPrivateKey(account: Account, appDomain: string, legacy?: boolean): string;
declare function getGaiaAddress(account: Account): string;
declare function encryptMnemonic(mnemonic: string, password: string, salt?: Uint8Array): Promise<Uint8Array>;
declare function decryptMnemonic(encryptedMnemonic: Uint8Array | string, password: string): Promise<string>;
declare function makeDIDFromAddress(address: string): string;
declare function nextMonth(): Date;
declare function makeUUID4(): string;
interface MakeAuthResponseParams {
privateKey: string;
profile?: any;
username?: string;
metadata?: any;
coreToken?: string;
appPrivateKey?: string;
expiresAt?: number;
transitPublicKey?: string;
hubUrl?: string;
blockstackAPIUrl?: string;
associationToken?: string;
}
declare function encryptPrivateKey(publicKey: string, privateKey: string): Promise<string>;
declare function makeAuthResponse(params: MakeAuthResponseParams): Promise<string>;
declare function createWalletConfigGaiaHubConfig(privateKey: string, gaiaHubUrl?: string): Promise<micro_stacks_storage.GaiaHubConfig>;
declare function fetchWalletConfig(privateKey: string, options?: {
gaiaHubConfig?: GaiaHubConfig;
gaiaHubUrl?: string;
}): Promise<WalletConfig | undefined>;
interface GetOrSetWalletConfig {
wallet: Wallet;
gaiaHubConfig?: GaiaHubConfig;
gaiaHubUrl?: string;
}
declare function getOrSetWalletConfig({ wallet, gaiaHubConfig, gaiaHubUrl, }: GetOrSetWalletConfig): Promise<WalletConfig>;
declare function makeWalletConfig(wallet: Wallet): WalletConfig;
declare function restoreWalletAccountsFromWalletConfig({ wallet, walletConfig, }: {
wallet: Wallet;
walletConfig: WalletConfig;
}): Wallet;
interface SaveWalletConfig {
walletConfig: WalletConfig;
gaiaHubConfig?: GaiaHubConfig;
gaiaHubUrl?: string;
privateKey: string;
}
declare function saveWalletConfig({ walletConfig, privateKey, gaiaHubConfig, gaiaHubUrl, }: SaveWalletConfig): Promise<void>;
interface UpdateAppsMeta {
wallet: Wallet;
app: ConfigApp;
account: Account;
walletConfig: WalletConfig;
}
interface UpdateWalletConfigWithApp extends UpdateAppsMeta {
gaiaHubConfig?: GaiaHubConfig;
}
declare const updateWalletConfigWithApp: ({ wallet, account, app, walletConfig, gaiaHubConfig, }: UpdateWalletConfigWithApp) => Promise<WalletConfig>;
declare const addNewAccountToWalletConfig: ({ wallet, walletConfig, gaiaHubConfig, }: UpdateWalletConfigWithApp) => Promise<WalletConfig>;
export { Account, AllowedKeyEntropyBits, ConfigAccount, ConfigApp, GetOrSetWalletConfig, LockedWallet, Wallet, WalletConfig, WalletKeys, addNewAccountToWalletConfig, createWalletConfigGaiaHubConfig, decryptMnemonic, deriveAccount, deriveConfigPrivateKey, deriveLegacyConfigPrivateKey, deriveManyAccountsForWallet, deriveNextAccountFromWallet, deriveSalt, deriveWalletKeys, encryptMnemonic, encryptPrivateKey, fetchWalletConfig, generateAndInsertNewAccount, generateSecretKey, generateWallet, getAppPrivateKey, getGaiaAddress, getOrSetWalletConfig, getStxAddressFromAccount, makeAuthResponse, makeDIDFromAddress, makeUUID4, makeWalletConfig, nextMonth, restoreWalletAccountsFromWalletConfig, saveWalletConfig, updateWalletConfigWithApp };