Skip to content

Commit

Permalink
Add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Jul 1, 2024
1 parent e3fb45e commit daca9f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/request/types/btcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { MethodParamsAndResult, rpcRequestMessageSchema } from '../../types';
import * as v from 'valibot';

export const getInfoMethodName = 'getInfo';
export const getInfoParamsSchema = v.null();
export const getInfoParamsSchema = v.nullish(v.null());
export type GetInfoParams = v.InferOutput<typeof getInfoParamsSchema>;
export const getInfoResultSchema = v.object({
/**
* Version of the wallet.
Expand All @@ -24,14 +25,16 @@ export const getInfoResultSchema = v.object({
*/
supports: v.array(v.string()),
});
export const getInfoSchema = v.object({
export type GetInfoResult = v.InferOutput<typeof getInfoResultSchema>;
export const getInfoRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
method: v.literal(getInfoMethodName),
params: getInfoParamsSchema,
id: v.string(),
}).entries,
});
export type GetInfoRequestMessage = v.InferOutput<typeof getInfoRequestMessageSchema>;
export type GetInfo = MethodParamsAndResult<
v.InferOutput<typeof getInfoParamsSchema>,
v.InferOutput<typeof getInfoResultSchema>
Expand All @@ -49,12 +52,14 @@ export const getAddressesParamsSchema = v.object({
*/
message: v.optional(v.string()),
});
export type GetAddressesParams = v.InferOutput<typeof getAddressesParamsSchema>;
export const getAddressesResultSchema = v.object({
/**
* The addresses generated for the given purposes.
*/
addresses: v.array(addressSchema),
});
export type GetAddressesResult = v.InferOutput<typeof getAddressesResultSchema>;
export const getAddressesRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
Expand All @@ -63,6 +68,7 @@ export const getAddressesRequestMessageSchema = v.object({
id: v.string(),
}).entries,
});
export type GetAddressesRequestMessage = v.InferOutput<typeof getAddressesRequestMessageSchema>;
export type GetAddresses = MethodParamsAndResult<
v.InferOutput<typeof getAddressesParamsSchema>,
v.InferOutput<typeof getAddressesResultSchema>
Expand All @@ -79,6 +85,7 @@ export const signMessageParamsSchema = v.object({
**/
message: v.string(),
});
export type SignMessageParams = v.InferOutput<typeof signMessageParamsSchema>;
export const signMessageResultSchema = v.object({
/**
* The signature of the message.
Expand All @@ -93,6 +100,7 @@ export const signMessageResultSchema = v.object({
*/
address: v.string(),
});
export type SignMessageResult = v.InferOutput<typeof signMessageResultSchema>;
export const signMessageRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
Expand All @@ -101,6 +109,7 @@ export const signMessageRequestMessageSchema = v.object({
id: v.string(),
}).entries,
});
export type SignMessageRequestMessage = v.InferOutput<typeof signMessageRequestMessageSchema>;
export type SignMessage = MethodParamsAndResult<
v.InferOutput<typeof signMessageParamsSchema>,
v.InferOutput<typeof signMessageResultSchema>
Expand Down Expand Up @@ -170,7 +179,9 @@ export type SignPsbt = MethodParamsAndResult<SignPsbtParams, SignPsbtResult>;

export const getAccountsMethodName = 'getAccounts';
export const getAccountsParamsSchema = getAddressesParamsSchema;
export type GetAccountsParams = v.InferOutput<typeof getAccountsParamsSchema>;
export const getAccountsResultSchema = v.array(addressSchema);
export type GetAccountsResult = v.InferOutput<typeof getAccountsResultSchema>;
export const getAccountsRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
Expand All @@ -179,14 +190,15 @@ export const getAccountsRequestMessageSchema = v.object({
id: v.string(),
}).entries,
});
export type GetAccountsRequestMessage = v.InferOutput<typeof getAccountsRequestMessageSchema>;
export type GetAccounts = MethodParamsAndResult<
v.InferOutput<typeof getAccountsParamsSchema>,
v.InferOutput<typeof getAccountsResultSchema>
>;

// Get the balance of the current Bitcoin account.
export const getBalanceMethodName = 'getBalance';
export const getBalanceParamsSchema = v.undefined();
export const getBalanceParamsSchema = v.nullish(v.null());
export const getBalanceResultSchema = v.object({
/**
* The confirmed balance of the wallet in sats. Using a string due to chrome
Expand Down
7 changes: 6 additions & 1 deletion src/request/types/runesMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ interface RbfOrderResult {
export type RbfOrder = MethodParamsAndResult<RbfOrderParams, RbfOrderResult>;

export const getRunesBalanceMethodName = 'runes_getBalance';
export const getRunesBalanceParamsSchema = v.null();
export const getRunesBalanceParamsSchema = v.nullish(v.null());
export type GetRunesBalanceParams = v.InferOutput<typeof getRunesBalanceParamsSchema>;
export const getRunesBalanceResultSchema = v.object({
balances: v.array(
v.object({
Expand All @@ -95,6 +96,7 @@ export const getRunesBalanceResultSchema = v.object({
})
),
});
export type GetRunesBalanceResult = v.InferOutput<typeof getRunesBalanceResultSchema>;
export const getRunesBalanceRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
Expand All @@ -103,6 +105,9 @@ export const getRunesBalanceRequestMessageSchema = v.object({
id: v.string(),
}).entries,
});
export type GetRunesBalanceRequestMessage = v.InferOutput<
typeof getRunesBalanceRequestMessageSchema
>;
export type GetRunesBalance = MethodParamsAndResult<
v.InferOutput<typeof getRunesBalanceParamsSchema>,
v.InferOutput<typeof getRunesBalanceResultSchema>
Expand Down
9 changes: 7 additions & 2 deletions src/request/types/stxMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ export type DeployContractResult = TxId & Transaction;
export type StxDeployContract = MethodParamsAndResult<DeployContractParams, DeployContractResult>;

// Types for `stx_getAccounts` request
export type GetAccountsResult = {
export type StxGetAccountsResult = {
addresses: Array<Address & PublicKey & { gaiaHubUrl: string; gaiaAppKey: string }>;
};
export type StxGetAccounts = MethodParamsAndResult<{}, GetAccountsResult>;
export type StxGetAccounts = MethodParamsAndResult<{}, StxGetAccountsResult>;

export const stxGetAddressesMethodName = 'stx_getAddresses';
export const stxGetAddressesParamsSchema = v.nullish(
Expand All @@ -263,12 +263,14 @@ export const stxGetAddressesParamsSchema = v.nullish(
message: v.optional(v.string()),
})
);
export type StxGetAddressesParams = v.InferOutput<typeof stxGetAddressesParamsSchema>;
export const stxGetAddressesResultSchema = v.object({
/**
* The addresses generated for the given purposes.
*/
addresses: v.array(addressSchema),
});
export type StxGetAddressesResult = v.InferOutput<typeof stxGetAddressesResultSchema>;
export const stxGetAddressesRequestMessageSchema = v.object({
...rpcRequestMessageSchema.entries,
...v.object({
Expand All @@ -277,6 +279,9 @@ export const stxGetAddressesRequestMessageSchema = v.object({
id: v.string(),
}).entries,
});
export type StxGetAddressesRequestMessage = v.InferOutput<
typeof stxGetAddressesRequestMessageSchema
>;
export type StxGetAddresses = MethodParamsAndResult<
v.InferOutput<typeof stxGetAddressesParamsSchema>,
v.InferOutput<typeof stxGetAddressesResultSchema>
Expand Down

0 comments on commit daca9f6

Please sign in to comment.