diff --git a/package-lock.json b/package-lock.json index 3b15dca..0860e0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sats-connect/core", - "version": "0.5.2", + "version": "0.5.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@sats-connect/core", - "version": "0.5.2", + "version": "0.5.3", "license": "ISC", "dependencies": { "axios": "1.7.7", diff --git a/package.json b/package.json index 0685ea4..8afc0cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sats-connect/core", - "version": "0.5.2", + "version": "0.5.3", "main": "dist/index.mjs", "module": "dist/index.mjs", "types": "dist/index.d.mts", diff --git a/src/request/types/index.ts b/src/request/types/index.ts index 874755d..0f5449f 100644 --- a/src/request/types/index.ts +++ b/src/request/types/index.ts @@ -59,6 +59,7 @@ export interface WalletRequests { wallet_getWalletType: WalletMethods.GetWalletType; wallet_renouncePermissions: WalletMethods.RenouncePermissions; wallet_requestPermissions: WalletMethods.RequestPermissions; + wallet_getNetwork: WalletMethods.GetNetwork; } export type Requests = BtcRequests & diff --git a/src/request/types/walletMethods.ts b/src/request/types/walletMethods.ts index 3bde7d4..d873584 100644 --- a/src/request/types/walletMethods.ts +++ b/src/request/types/walletMethods.ts @@ -1,13 +1,19 @@ -import { MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; +import { BitcoinNetworkType, MethodParamsAndResult, rpcRequestMessageSchema } from '../../types'; import * as v from 'valibot'; import { walletTypeSchema } from './common'; import { AddressPurpose, addressSchema } from '../../addresses'; +// NOTE: These next 4 values are 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. + export const accountActionsSchema = v.object({ read: v.optional(v.boolean()), }); -export const walletActionsSchema = v.object({}); +export const walletActionsSchema = v.object({ + readNetwork: v.optional(v.boolean()), +}); export const accountPermissionSchema = v.object({ type: v.literal('account'), @@ -186,3 +192,30 @@ export const connectRequestMessageSchema = v.object({ }); 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 +// dependency. It has side effects and doesn't support tree-shaking, and would +// make sats-connect-core too heavy. +const networkType = ['Mainnet', 'Testnet', 'Testnet4', 'Signet', 'Regtest'] as const; +export const getNetworkResultSchema = v.object({ + bitcoin: v.object({ + name: v.picklist(networkType), + }), + stacks: v.object({ + name: v.string(), + }), +}); +export type GetNetworkResult = v.InferOutput; +export const getNetworkRequestMessageSchema = v.object({ + ...rpcRequestMessageSchema.entries, + ...v.object({ + method: v.literal(getNetworkMethodName), + params: getNetworkParamsSchema, + id: v.string(), + }).entries, +}); +export type GetNetworkRequestMessage = v.InferOutput; +export type GetNetwork = MethodParamsAndResult;