import { BitcoinProvider, InputToSign as SatsConnectInputToSign } from 'sats-connect'; import { SignPsbtResponse as BtcKitSignPsbtResponse } from '@btckit/types'; import { IdentifierString, WalletAccount } from '@wallet-standard/base'; import type { Network } from 'bitcoinjs-lib'; import type { GenericNetwork, WalletUiUtils } from '@dynamic-labs/types'; import type { InternalWalletConnector } from '@dynamic-labs/wallet-connector-core'; import type { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core'; import type { BitcoinWalletConnectorOpts } from './connectors'; import { SATSCONNECT_FEATURE } from './const'; export type ErrorWithCode = Error & { code: string; }; export type SatsConnectFeature = { [SATSCONNECT_FEATURE]: { provider: BitcoinProvider; }; }; export type BitcoinAddress = { address: string; publicKey?: string; }; export type ConnectedAccountWithAddressesProps = { mainAddress?: string; ordinalsAddress?: BitcoinAddress; paymentAddress?: BitcoinAddress; active?: boolean; }; export type BitcoinConnectedAccount = { additionalAddresses: WalletAdditionalAddress[]; active?: boolean; }; export type BitcoinTransaction = { amount: bigint; recipientAddress: string; feePriority?: FeePriority; }; export type SignPsbtOptions = { autoFinalized: boolean; toSignInputs?: { index: number; address: string; sighashTypes?: number[]; disableAddressValidation?: boolean; }[]; }; export type BitcoinSignPsbtRequest = { allowedSighash: number[]; unsignedPsbtBase64: string; signature?: BitcoinSignPsbtRequestSignature[]; }; export type BitcoinSignPsbtRequestSignature = { address: string; signingIndexes: number[] | undefined; disableAddressValidation?: boolean; }; /** * PSBT signing request specifically for embedded wallets (DynamicWaasBitcoinConnector) * * Embedded wallets: * - Only support PSBT format (Base64) * - Automatically sign all inputs that belong to the wallet address * - Always use SIGHASH_ALL (0x01) */ export type EmbeddedWalletSignPsbtRequest = { /** * The unsigned PSBT in Base64 format. * Embedded wallets only support PSBT format, not raw transaction hex. */ unsignedPsbtBase64: string; /** * Optional subset of PSBT input indexes to sign. When provided, only these * indexes are signed (they must still belong to the wallet's own address). * When omitted, behavior is unchanged: all wallet-owned inputs are signed. */ signingIndexes?: number[]; /** * Optional allow-list of sighash types. The sighash type itself is read from * the PSBT (BIP-174 `PSBT_IN_SIGHASH_TYPE`) — this only restricts which * declared types are accepted, and signing throws if an input declares one * outside the list. When omitted, any declared type is signed. */ allowedSighash?: number[]; }; export type SatsConnectSignTransactionInput = { message?: string; psbtBase64: string; inputsToSign: SatsConnectInputToSign[]; broadcast?: boolean; allowedSignHash?: number; }; export type BtcKitSignPsbtResponseExtended = BtcKitSignPsbtResponse & { result: { hex: string; }; }; export type BitcoinSignPsbtResponse = { signedPsbt: string; }; export type BitcoinAddressPurpose = 'ordinals' | 'payment'; export interface BitcoinConnectInput { purposes: BitcoinAddressPurpose[]; } export interface BitcoinConnectOutput { /** * The accounts will have addresses that correspond with the `purposes` in the {@link BitcoinConnectInput}, and will * be returned in the same order. */ accounts: WalletAccount[]; } export type BitcoinConnectMethod = (input?: BitcoinConnectInput) => Promise; export type BitcoinSignMessageMethod = (...inputs: BitcoinSignMessageInput[]) => Promise; export interface BitcoinSignMessageInput { /** Account to use. */ account: WalletAccount; /** Message to sign, as raw bytes. */ message: Uint8Array; } export interface BitcoinSignMessageOutput { /** * Message bytes that were signed. * The wallet may prefix or otherwise modify the message before signing it. */ signedMessage: Uint8Array; /** Message signature produced. */ signature: Uint8Array; } export type BitcoinSignTransactionMethod = (...inputs: BitcoinSignTransactionInput[]) => Promise; export interface BitcoinSignTransactionInput { /** Partially Signed Bitcoin Transaction (PSBT), as raw bytes. */ psbt: Uint8Array; /** Transaction inputs to sign. */ inputsToSign: InputToSign[]; /** Chain to use. */ chain?: IdentifierString; } export interface InputToSign { /** Account to use. */ account: WalletAccount; /** List of input indexes that should be signed by the account. */ signingIndexes: number[]; /** A SIGHASH flag. */ sigHash?: BitcoinSigHashFlag; } export interface BitcoinSignTransactionOutput { /** Signed Partially Signed Bitcoin Transaction (PSBT), as raw bytes. */ signedPsbt: Uint8Array; } /** SIGHASH flag. */ export type BitcoinSigHashFlag = 'ALL' | 'NONE' | 'SINGLE' | 'ALL|ANYONECANPAY' | 'NONE|ANYONECANPAY' | 'SINGLE|ANYONECANPAY'; export type BitcoinSignAndSendTransactionMethod = (...inputs: BitcoinSignAndSendTransactionInput[]) => Promise; export interface BitcoinSignAndSendTransactionInput extends BitcoinSignTransactionInput { chain: IdentifierString; } export interface BitcoinSignAndSendTransactionOutput { /** Transaction ID (transaction hash). */ txId: string; } export type BitcoinWalletStandardMethods = { connect?: BitcoinConnectMethod; signMessage?: BitcoinSignMessageMethod; signTransaction?: BitcoinSignTransactionMethod; signAndSendTransaction?: BitcoinSignAndSendTransactionMethod; }; export type BitcoinSignProtocol = 'ecdsa' | 'bip322-simple'; interface ProviderBalance { confirmed: number; unconfirmed: number; total: number; } export interface ProviderWithBalance { getBalance: () => Promise; } export type DynamicWaasBitcoinConnectorProps = BitcoinWalletConnectorOpts & { walletUiUtils: WalletUiUtils; bitcoinNetworks?: GenericNetwork[]; }; export interface UTXO { txid: string; vout: number; value: number; status?: { confirmed: boolean; }; } export interface FeeRecommendations { fastestFee?: number; halfHourFee?: number; hourFee?: number; economyFee?: number; minimumFee?: number; } export interface ParsedTransactionInput { txid: string; vout: number; address?: string; value?: number; } export interface ParsedTransactionOutput { address?: string; value: number; } export interface ParsedTransaction { inputs: ParsedTransactionInput[]; outputs: ParsedTransactionOutput[]; } export type FeePriority = 'high' | 'medium' | 'low'; export interface BuildPsbtOptions { accountAddress: string; recipientAddress: string; amountInSatoshis: bigint; publicKeyHex: string; network: Network; feePriority?: FeePriority; } export {};