UNPKG

@bitgo/utxo-lib

Version:

Client-side Bitcoin JavaScript library

146 lines 5.75 kB
import { ScriptType, ScriptType2Of3 } from '../bitgo/outputScripts'; import { KeyName, RootWalletKeys, Unspent, UtxoPsbt, UtxoTransaction } from '../bitgo'; import { Network } from '../networks'; /** * This is a bit of a misnomer, as it actually specifies the spend type of the input. * This makes a difference for p2trMusig2 inputs, as they can be spent either by key path or script path. * The value p2trMusig2 is used for p2trMusig2 script path. * The value taprootKeyPathSpend is used for p2trMusig2 key path. */ export type InputScriptType = ScriptType | 'taprootKeyPathSpend'; export type OutputScriptType = ScriptType2Of3; /** * input script type and value */ export type Input = { scriptType: InputScriptType; value: bigint; }; export declare const signStages: readonly ["unsigned", "halfsigned", "fullsigned"]; export type SignStage = (typeof signStages)[number]; /** * Set isInternalAddress=true for internal output address */ export type Output = { value: bigint; isInternalAddress?: boolean; walletKeys?: RootWalletKeys | null; } & ({ scriptType: OutputScriptType; } | { address: string; } | { script: string; } | { opReturn: string; }); /** * array of supported input script types. * use p2trMusig2 for p2trMusig2 script path. * use taprootKeyPathSpend for p2trMusig2 key path. */ export declare const inputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2", "taprootKeyPathSpend", "p2shP2pk"]; /** * array of supported output script types. */ export declare const outputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2tr", "p2trMusig2"]; /** * create unspent object from input script type, index, network and root wallet key. */ export declare function toUnspent(input: Input, index: number, network: Network, rootWalletKeys: RootWalletKeys, { p2shP2pkKey }?: { p2shP2pkKey?: Buffer; }): Unspent<bigint>; /** * returns signer and cosigner names for InputScriptType. * user and undefined as signer and cosigner respectively for p2shP2pk. * user and backup as signer and cosigner respectively for p2trMusig2. * user and bitgo as signer and cosigner respectively for other input script types. */ export declare function getSigners(inputType: InputScriptType): { signerName: KeyName; cosignerName?: KeyName; }; /** * signs with first or second signature for single input. * p2shP2pk is signed only with first sign. */ export declare function signPsbtInput(psbt: UtxoPsbt, input: Input, inputIndex: number, rootWalletKeys: RootWalletKeys, sign: 'halfsigned' | 'fullsigned', params?: { signers?: { signerName: KeyName; cosignerName?: KeyName; }; deterministic?: boolean; skipNonWitnessUtxo?: boolean; }): void; /** * signs with first or second signature for all inputs. * p2shP2pk is signed only with first sign. */ export declare function signAllPsbtInputs(psbt: UtxoPsbt, inputs: Input[], rootWalletKeys: RootWalletKeys, sign: 'halfsigned' | 'fullsigned', params?: { signers?: { signerName: KeyName; cosignerName?: KeyName; }; deterministic?: boolean; skipNonWitnessUtxo?: boolean; }): void; /** * construct psbt for given inputs, outputs, network and root wallet keys. */ export declare function constructPsbt(inputs: Input[], outputs: Output[], network: Network, rootWalletKeys: RootWalletKeys, signStage: SignStage, params?: { p2shP2pkKey?: Buffer; signers?: { signerName: KeyName; cosignerName?: KeyName; }; deterministic?: boolean; skipNonWitnessUtxo?: boolean; addGlobalXPubs?: boolean; }): UtxoPsbt; export declare const txFormats: readonly ["psbt", "psbt-lite"]; export type TxFormat = (typeof txFormats)[number]; type SuiteConfig = { /** * By default, we include p2trMusig2 script path in the inputs. * This input is a bit of a weirdo because it is signed by the user and the * backup key, which usually is not mixed with other inputs and outputs. * * This option allows to exclude this input from the inputs. */ includeP2trMusig2ScriptPath?: boolean; }; /** * Creates a valid PSBT with as many features as possible. * * - Inputs: * - All wallet script types that are supported by the network. * - A p2shP2pk input (for replay protection) * - Outputs: * - All wallet script types that are supported by the network. * - A p2sh output with derivation info of a different wallet (not in the global psbt xpubs) * - A p2sh output with no derivation info (external output) * - An OP_RETURN output */ export declare class AcidTest { readonly network: Network; readonly signStage: SignStage; readonly txFormat: TxFormat; readonly rootWalletKeys: RootWalletKeys; readonly otherWalletKeys: RootWalletKeys; readonly inputs: Input[]; readonly outputs: Output[]; constructor(network: Network, signStage: SignStage, txFormat: TxFormat, rootWalletKeys: RootWalletKeys, otherWalletKeys: RootWalletKeys, inputs: Input[], outputs: Output[]); static withConfig(network: Network, signStage: SignStage, txFormat: TxFormat, suiteConfig: SuiteConfig): AcidTest; get name(): string; getReplayProtectionPublicKey(): Buffer; getReplayProtectionOutputScript(): Buffer; createPsbt(): UtxoPsbt; static suite(suiteConfig?: SuiteConfig): AcidTest[]; } /** * Verifies signatures of fully signed tx (with taproot key path support). * NOTE: taproot key path tx can only be built and signed with PSBT. */ export declare function verifyFullySignedSignatures(tx: UtxoTransaction<bigint>, unspents: Unspent<bigint>[], walletKeys: RootWalletKeys, signer: KeyName, cosigner: KeyName): boolean; export {}; //# sourceMappingURL=psbt.d.ts.map