diff --git a/src/request/types/btcMethods.ts b/src/request/types/btcMethods.ts index 53ec675..70ba45e 100644 --- a/src/request/types/btcMethods.ts +++ b/src/request/types/btcMethods.ts @@ -5,6 +5,7 @@ import { AddressPurpose, addressSchema } from '../../addresses'; import { MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; import * as v from 'valibot'; +import { walletTypeSchema } from './common'; export const getInfoMethodName = 'getInfo'; export const getInfoParamsSchema = v.nullish(v.null()); @@ -178,9 +179,27 @@ export type SignPsbtResult = { export type SignPsbt = MethodParamsAndResult; export const getAccountsMethodName = 'getAccounts'; -export const getAccountsParamsSchema = getAddressesParamsSchema; +export const getAccountsParamsSchema = v.object({ + /** + * The purposes for which to generate addresses. See + * {@linkcode AddressPurpose} for available purposes. + */ + purposes: v.array(v.enum(AddressPurpose)), + /** + * A message to be displayed to the user in the request prompt. + */ + message: v.optional(v.string()), +}); export type GetAccountsParams = v.InferOutput; -export const getAccountsResultSchema = v.array(addressSchema); + +export const getAccountsResultSchema = v.array( + v.object({ + ...addressSchema.entries, + ...v.object({ + walletType: walletTypeSchema, + }).entries, + }) +); export type GetAccountsResult = v.InferOutput; export const getAccountsRequestMessageSchema = v.object({ ...rpcRequestMessageSchema.entries, @@ -196,7 +215,6 @@ export type GetAccounts = MethodParamsAndResult< v.InferOutput >; -// Get the balance of the current Bitcoin account. export const getBalanceMethodName = 'getBalance'; export const getBalanceParamsSchema = v.nullish(v.null()); export const getBalanceResultSchema = v.object({ diff --git a/src/request/types/common.ts b/src/request/types/common.ts new file mode 100644 index 0000000..6c4f69c --- /dev/null +++ b/src/request/types/common.ts @@ -0,0 +1,5 @@ +import * as v from 'valibot'; + +export const walletTypes = ['software', 'ledger'] as const; +export const walletTypeSchema = v.picklist(walletTypes); +export type WalletType = v.InferOutput; diff --git a/src/request/types/index.ts b/src/request/types/index.ts index 419e970..8b212fa 100644 --- a/src/request/types/index.ts +++ b/src/request/types/index.ts @@ -2,7 +2,7 @@ import type * as BtcMethods from './btcMethods'; import { GetInscriptions } from './ordinalsMethods'; import type * as RunesMethods from './runesMethods'; import type * as StxMethods from './stxMethods'; -import { RequestPermissions, RenouncePermissions } from './walletMethods'; +import type * as WalletMethods from './walletMethods'; export interface StxRequests { stx_callContract: StxMethods.StxCallContract; @@ -48,12 +48,17 @@ export interface OrdinalsRequests { export type OrdinalsRequestMethod = keyof OrdinalsRequests; -export interface WalletMethods { - wallet_requestPermissions: RequestPermissions; - wallet_renouncePermissions: RenouncePermissions; +export interface WalletRequests { + wallet_requestPermissions: WalletMethods.RequestPermissions; + wallet_renouncePermissions: WalletMethods.RenouncePermissions; + wallet_getWalletType: WalletMethods.GetWalletType; } -export type Requests = BtcRequests & StxRequests & RunesRequests & WalletMethods & OrdinalsRequests; +export type Requests = BtcRequests & + StxRequests & + RunesRequests & + WalletRequests & + OrdinalsRequests; export type Return = Method extends keyof Requests ? Requests[Method]['result'] : never; export type Params = Method extends keyof Requests ? Requests[Method]['params'] : never; @@ -63,3 +68,4 @@ export * from './btcMethods'; export * from './walletMethods'; export * from './runesMethods'; export * from './ordinalsMethods'; +export * from './common'; diff --git a/src/request/types/walletMethods.ts b/src/request/types/walletMethods.ts index 5fffc50..8cec896 100644 --- a/src/request/types/walletMethods.ts +++ b/src/request/types/walletMethods.ts @@ -1,5 +1,6 @@ import { MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; import * as v from 'valibot'; +import { walletTypeSchema } from './common'; export const requestPermissionsMethodName = 'wallet_requestPermissions'; export const requestPermissionsParamsSchema = v.undefined(); @@ -32,3 +33,18 @@ export type RenouncePermissions = MethodParamsAndResult< v.InferOutput, v.InferOutput >; + +export const getWalletTypeMethodName = 'wallet_getWalletType'; +export const getWalletTypeParamsSchema = v.nullish(v.null()); +export const getWalletTypeResultSchema = walletTypeSchema; +export const getWalletTypeRequestMessageSchema = v.object({ + ...rpcRequestMessageSchema.entries, + ...v.object({ + method: v.literal(getWalletTypeMethodName), + id: v.string(), + }).entries, +}); +export type GetWalletType = MethodParamsAndResult< + v.InferOutput, + v.InferOutput +>;