Skip to content

Commit

Permalink
updated btc methods types and added jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aboelenein committed Feb 29, 2024
1 parent cde3670 commit 5ccafbd
Showing 1 changed file with 70 additions and 10 deletions.
80 changes: 70 additions & 10 deletions src/request/types/btcMethods.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,124 @@
/**
* Represents the types and interfaces related to BTC methods.
*/

import { Address, AddressPurpose } from '../../addresses';
import { MethodParamsAndResult } from '../../types';

type GetInfoResult = {
version: Number | String;
version: number | string;
methods?: Array<string>;
supports?: Array<string>;
};

export type GetInfo = MethodParamsAndResult<null, GetInfoResult>;

type GetAddressesParams = {
purposes: AddressPurpose[];
/**
* The purposes for which to generate addresses.
* possible values are "payment", "ordinals", ...
*/
purposes: Array<AddressPurpose>;
/**
* a message to be displayed to the user in the request prompt.
*/
message?: string;
};

/**
* The addresses generated for the given purposes.
*/
type GetAddressesResult = {
addresses: Address[];
addresses: Array<Address>;
};

export type GetAddresses = MethodParamsAndResult<GetAddressesParams, GetAddressesResult>;

type SignMessageParams = {
/**
* The address used for signing.
**/
address: string;
/**
* The message to sign.
**/
message: string;
};

type SignMessageResult = {
/**
* The signature of the message.
*/
signature: string;
/**
* hash of the message.
*/
messageHash: string;
/**
* The address used for signing.
*/
address: string;
};

export type SignMessage = MethodParamsAndResult<SignMessageParams, SignMessageResult>;

type Recipient = {
/**
* The recipient's address.
**/
address: string;
amount: bigint;
/**
* The amount to send to the recipient in satoshis.
*/
amount: number;
};

type SendTransferParams = {
recipients: Recipient[];
/**
* Array of recipients to send to.
* The amount to send to each recipient is in satoshis.
*/
recipients: Array<Recipient>;
};
type SendTransferResult = {
/**
* The transaction id as a hex-encoded string.
*/
txid: string;
};

export type SendTransfer = MethodParamsAndResult<SendTransferParams, SendTransferResult>;

type SignInputsByAddress = {
[address: string]: number[];
};

export type SignPsbtParams = {
/**
* The base64 encoded PSBT to sign.
*/
psbt: string;
signInputs: number[] | SignInputsByAddress;
/**
* The inputs to sign.
* The key is the address and the value is an array of indexes of the inputs to sign.
*/
signInputs: Record<string, number[]>;
/**
* the sigHash type to use for signing.
* will default to the sighash type of the input if not provided.
**/
allowedSignHash?: number;
/**
* Whether to broadcast the transaction after signing.
**/
broadcast?: boolean;
};

export type SignPsbtResult = {
/**
* The base64 encoded PSBT after signing.
*/
psbt: string;
/**
* The transaction id as a hex-encoded string.
* This is only returned if the transaction was broadcast.
**/
txid?: string;
};

Expand Down

0 comments on commit 5ccafbd

Please sign in to comment.