Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add get network method [ENG-6213] #59

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/request/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
37 changes: 35 additions & 2 deletions src/request/types/walletMethods.ts
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down Expand Up @@ -186,3 +192,30 @@ export const connectRequestMessageSchema = v.object({
});
export type ConnectRequestMessage = v.InferOutput<typeof connectRequestMessageSchema>;
export type Connect = MethodParamsAndResult<ConnectParams, ConnectResult>;

export const getNetworkMethodName = 'wallet_getNetwork';
export const getNetworkParamsSchema = v.nullish(v.null());
export type GetNetworkParams = v.InferOutput<typeof getNetworkParamsSchema>;
// 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(),
}),
aryzing marked this conversation as resolved.
Show resolved Hide resolved
});
export type GetNetworkResult = v.InferOutput<typeof getNetworkResultSchema>;
export const getNetworkRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
method: v.literal(getNetworkMethodName),
params: getNetworkParamsSchema,
id: v.string(),
}).entries,
});
export type GetNetworkRequestMessage = v.InferOutput<typeof getNetworkRequestMessageSchema>;
export type GetNetwork = MethodParamsAndResult<GetNetworkParams, GetNetworkResult>;
Loading