Skip to content

Commit

Permalink
Include wallet type
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Jul 9, 2024
1 parent a5593ec commit 63ca21b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/request/types/btcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -188,13 +189,17 @@ export const getAccountsParamsSchema = v.object({
* A message to be displayed to the user in the request prompt.
*/
message: v.optional(v.string()),
/**
* Includes wallet type (software / ledger) info in the response.
*/
includeWalletType: v.optional(v.boolean()),
});
export type GetAccountsParams = v.InferOutput<typeof getAccountsParamsSchema>;
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<typeof getAccountsResultSchema>;
export const getAccountsRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
Expand Down
5 changes: 5 additions & 0 deletions src/request/types/common.ts
Original file line number Diff line number Diff line change
@@ -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<typeof walletTypeSchema>;
16 changes: 11 additions & 5 deletions src/request/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> = Method extends keyof Requests ? Requests[Method]['result'] : never;
export type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
Expand All @@ -63,3 +68,4 @@ export * from './btcMethods';
export * from './walletMethods';
export * from './runesMethods';
export * from './ordinalsMethods';
export * from './common';
17 changes: 17 additions & 0 deletions src/request/types/walletMethods.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -32,3 +33,19 @@ export type RenouncePermissions = MethodParamsAndResult<
v.InferOutput<typeof renouncePermissionsParamsSchema>,
v.InferOutput<typeof renouncePermissionsResultSchema>
>;

// Get the wallet type of the current account
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<typeof getWalletTypeParamsSchema>,
v.InferOutput<typeof getWalletTypeResultSchema>
>;

0 comments on commit 63ca21b

Please sign in to comment.