diff --git a/src/provider/types.ts b/src/provider/types.ts index cfcf3ef..e2d7fc1 100644 --- a/src/provider/types.ts +++ b/src/provider/types.ts @@ -27,8 +27,23 @@ export type AccountChangeEvent = v.InferOutput; // networkChange export const networkChangeEventName = 'networkChange'; +// NOTE1: This next value is copied from xverse-core to avoid having it as a +// dependency. It has side effects and doesn't support tree-shaking, and would +// make sats-connect-core too heavy. +// +// NOTE2: The version of Webpack currently being used in the extension is unable +// to properly handle imports. As such, this value may be defined more than once +// in different files, and should remain this way until the extension's build +// system has been updated. +const networkType = ['Mainnet', 'Testnet', 'Testnet4', 'Signet', 'Regtest'] as const; export const networkChangeSchema = v.object({ type: v.literal(networkChangeEventName), + bitcoin: v.object({ + name: v.picklist(networkType), + }), + stacks: v.object({ + name: v.string(), + }), }); export type NetworkChangeEvent = v.InferOutput; diff --git a/src/request/types/walletMethods.ts b/src/request/types/walletMethods.ts index d873584..5ff9251 100644 --- a/src/request/types/walletMethods.ts +++ b/src/request/types/walletMethods.ts @@ -1,4 +1,4 @@ -import { BitcoinNetworkType, MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; +import { MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; import * as v from 'valibot'; import { walletTypeSchema } from './common'; import { AddressPurpose, addressSchema } from '../../addresses'; @@ -168,37 +168,17 @@ export const getAccountRequestMessageSchema = v.object({ export type GetAccountRequestMessage = v.InferOutput; export type GetAccount = MethodParamsAndResult; -export const connectMethodName = 'wallet_connect'; -export const connectParamsSchema = v.nullish( - v.object({ - permissions: v.optional(v.array(PermissionRequestParams)), - addresses: v.optional(v.array(v.enum(AddressPurpose))), - message: v.optional( - v.pipe(v.string(), v.maxLength(80, 'The message must not exceed 80 characters.')) - ), - }) -); - -export type ConnectParams = v.InferOutput; -export const connectResultSchema = getAccountResultSchema; -export type ConnectResult = v.InferOutput; -export const connectRequestMessageSchema = v.object({ - ...rpcRequestMessageSchema.entries, - ...v.object({ - method: v.literal(connectMethodName), - params: connectParamsSchema, - id: v.string(), - }).entries, -}); -export type ConnectRequestMessage = v.InferOutput; -export type Connect = MethodParamsAndResult; - export const getNetworkMethodName = 'wallet_getNetwork'; export const getNetworkParamsSchema = v.nullish(v.null()); export type GetNetworkParams = v.InferOutput; -// NOTE: This next value is copied from xverse-core to avoid having it as a +// NOTE1: This next value is copied from xverse-core to avoid having it as a // dependency. It has side effects and doesn't support tree-shaking, and would // make sats-connect-core too heavy. +// +// NOTE2: The version of Webpack currently being used in the extension is unable +// to properly handle imports. As such, this value may be defined more than once +// in different files, and should remain this way until the extension's build +// system has been updated. const networkType = ['Mainnet', 'Testnet', 'Testnet4', 'Signet', 'Regtest'] as const; export const getNetworkResultSchema = v.object({ bitcoin: v.object({ @@ -219,3 +199,32 @@ export const getNetworkRequestMessageSchema = v.object({ }); export type GetNetworkRequestMessage = v.InferOutput; export type GetNetwork = MethodParamsAndResult; + +export const connectMethodName = 'wallet_connect'; +export const connectParamsSchema = v.nullish( + v.object({ + permissions: v.optional(v.array(PermissionRequestParams)), + addresses: v.optional(v.array(v.enum(AddressPurpose))), + message: v.optional( + v.pipe(v.string(), v.maxLength(80, 'The message must not exceed 80 characters.')) + ), + }) +); +export type ConnectParams = v.InferOutput; +export const connectResultSchema = v.object({ + id: v.string(), + addresses: v.array(addressSchema), + walletType: walletTypeSchema, + network: getNetworkResultSchema, +}); +export type ConnectResult = v.InferOutput; +export const connectRequestMessageSchema = v.object({ + ...rpcRequestMessageSchema.entries, + ...v.object({ + method: v.literal(connectMethodName), + params: connectParamsSchema, + id: v.string(), + }).entries, +}); +export type ConnectRequestMessage = v.InferOutput; +export type Connect = MethodParamsAndResult;