@ckb-ccc/xverse 0.0.15-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +51 -0
  3. package/dist/advanced.d.ts +2 -0
  4. package/dist/advanced.d.ts.map +1 -0
  5. package/dist/advanced.js +1 -0
  6. package/dist/advancedBarrel.d.ts +2 -0
  7. package/dist/advancedBarrel.d.ts.map +1 -0
  8. package/dist/advancedBarrel.js +1 -0
  9. package/dist/barrel.d.ts +3 -0
  10. package/dist/barrel.d.ts.map +1 -0
  11. package/dist/barrel.js +2 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/package.json +3 -0
  16. package/dist/sat-connect-core/advanced.d.ts +5 -0
  17. package/dist/sat-connect-core/advanced.d.ts.map +1 -0
  18. package/dist/sat-connect-core/advanced.js +4 -0
  19. package/dist/sat-connect-core/btcMethods.advanced.d.ts +280 -0
  20. package/dist/sat-connect-core/btcMethods.advanced.d.ts.map +1 -0
  21. package/dist/sat-connect-core/btcMethods.advanced.js +179 -0
  22. package/dist/sat-connect-core/provider.advanced.d.ts +48 -0
  23. package/dist/sat-connect-core/provider.advanced.d.ts.map +1 -0
  24. package/dist/sat-connect-core/provider.advanced.js +21 -0
  25. package/dist/sat-connect-core/requests.advanced.d.ts +21 -0
  26. package/dist/sat-connect-core/requests.advanced.d.ts.map +1 -0
  27. package/dist/sat-connect-core/requests.advanced.js +1 -0
  28. package/dist/sat-connect-core/types.advanced.d.ts +124 -0
  29. package/dist/sat-connect-core/types.advanced.d.ts.map +1 -0
  30. package/dist/sat-connect-core/types.advanced.js +79 -0
  31. package/dist/sat-connect-core/walletMethods.advanced.d.ts +36 -0
  32. package/dist/sat-connect-core/walletMethods.advanced.d.ts.map +1 -0
  33. package/dist/sat-connect-core/walletMethods.advanced.js +37 -0
  34. package/dist/signer.d.ts +47 -0
  35. package/dist/signer.d.ts.map +1 -0
  36. package/dist/signer.js +123 -0
  37. package/dist/signersFactory.d.ts +13 -0
  38. package/dist/signersFactory.d.ts.map +1 -0
  39. package/dist/signersFactory.js +30 -0
  40. package/dist.commonjs/advanced.d.ts +2 -0
  41. package/dist.commonjs/advanced.d.ts.map +1 -0
  42. package/dist.commonjs/advanced.js +27 -0
  43. package/dist.commonjs/advancedBarrel.d.ts +2 -0
  44. package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
  45. package/dist.commonjs/advancedBarrel.js +17 -0
  46. package/dist.commonjs/barrel.d.ts +3 -0
  47. package/dist.commonjs/barrel.d.ts.map +1 -0
  48. package/dist.commonjs/barrel.js +18 -0
  49. package/dist.commonjs/index.d.ts +2 -0
  50. package/dist.commonjs/index.d.ts.map +1 -0
  51. package/dist.commonjs/index.js +27 -0
  52. package/dist.commonjs/package.json +3 -0
  53. package/dist.commonjs/sat-connect-core/advanced.d.ts +5 -0
  54. package/dist.commonjs/sat-connect-core/advanced.d.ts.map +1 -0
  55. package/dist.commonjs/sat-connect-core/advanced.js +20 -0
  56. package/dist.commonjs/sat-connect-core/btcMethods.advanced.d.ts +280 -0
  57. package/dist.commonjs/sat-connect-core/btcMethods.advanced.d.ts.map +1 -0
  58. package/dist.commonjs/sat-connect-core/btcMethods.advanced.js +205 -0
  59. package/dist.commonjs/sat-connect-core/provider.advanced.d.ts +48 -0
  60. package/dist.commonjs/sat-connect-core/provider.advanced.d.ts.map +1 -0
  61. package/dist.commonjs/sat-connect-core/provider.advanced.js +47 -0
  62. package/dist.commonjs/sat-connect-core/requests.advanced.d.ts +21 -0
  63. package/dist.commonjs/sat-connect-core/requests.advanced.d.ts.map +1 -0
  64. package/dist.commonjs/sat-connect-core/requests.advanced.js +2 -0
  65. package/dist.commonjs/sat-connect-core/types.advanced.d.ts +124 -0
  66. package/dist.commonjs/sat-connect-core/types.advanced.d.ts.map +1 -0
  67. package/dist.commonjs/sat-connect-core/types.advanced.js +105 -0
  68. package/dist.commonjs/sat-connect-core/walletMethods.advanced.d.ts +36 -0
  69. package/dist.commonjs/sat-connect-core/walletMethods.advanced.d.ts.map +1 -0
  70. package/dist.commonjs/sat-connect-core/walletMethods.advanced.js +63 -0
  71. package/dist.commonjs/signer.d.ts +47 -0
  72. package/dist.commonjs/signer.d.ts.map +1 -0
  73. package/dist.commonjs/signer.js +150 -0
  74. package/dist.commonjs/signersFactory.d.ts +13 -0
  75. package/dist.commonjs/signersFactory.d.ts.map +1 -0
  76. package/dist.commonjs/signersFactory.js +34 -0
  77. package/package.json +57 -0
  78. package/src/advanced.ts +1 -0
  79. package/src/advancedBarrel.ts +1 -0
  80. package/src/barrel.ts +2 -0
  81. package/src/index.ts +1 -0
  82. package/src/sat-connect-core/advanced.ts +4 -0
  83. package/src/sat-connect-core/btcMethods.advanced.ts +304 -0
  84. package/src/sat-connect-core/provider.advanced.ts +61 -0
  85. package/src/sat-connect-core/requests.advanced.ts +41 -0
  86. package/src/sat-connect-core/types.advanced.ts +159 -0
  87. package/src/sat-connect-core/walletMethods.advanced.ts +58 -0
  88. package/src/signer.ts +170 -0
  89. package/src/signersFactory.ts +50 -0
  90. package/typedoc.json +6 -0
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@ckb-ccc/xverse",
3
+ "version": "0.0.15-alpha.0",
4
+ "description": "CCC - CKBer's Codebase. Common Chains Connector's support for Xverse",
5
+ "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "homepage": "https://github.com/ckb-ecofund/ccc",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git://github.com/ckb-ecofund/ccc.git"
12
+ },
13
+ "main": "dist.commonjs/index.js",
14
+ "module": "dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "default": "./dist.commonjs/index.js"
19
+ },
20
+ "./barrel": {
21
+ "import": "./dist/barrel.js",
22
+ "default": "./dist.commonjs/barrel.js"
23
+ },
24
+ "./advanced": {
25
+ "import": "./dist/advanced.js",
26
+ "default": "./dist.commonjs/advanced.js"
27
+ },
28
+ "./advancedBarrel": {
29
+ "import": "./dist/advancedBarrel.js",
30
+ "default": "./dist.commonjs/advancedBarrel.js"
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@eslint/js": "^9.1.1",
35
+ "copyfiles": "^2.4.1",
36
+ "eslint": "^9.1.0",
37
+ "eslint-config-prettier": "^9.1.0",
38
+ "eslint-plugin-prettier": "^5.1.3",
39
+ "prettier": "^3.2.5",
40
+ "prettier-plugin-organize-imports": "^3.2.4",
41
+ "rimraf": "^5.0.5",
42
+ "typescript": "^5.4.5",
43
+ "typescript-eslint": "^7.7.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "valibot": "^0.42.1",
50
+ "@ckb-ccc/core": "0.0.15"
51
+ },
52
+ "scripts": {
53
+ "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
54
+ "lint": "eslint",
55
+ "format": "prettier --write . && eslint --fix"
56
+ }
57
+ }
@@ -0,0 +1 @@
1
+ export * as XverseA from "./advancedBarrel.js";
@@ -0,0 +1 @@
1
+ export * from "./sat-connect-core/advanced.js";
package/src/barrel.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./signer.js";
2
+ export * from "./signersFactory.js";
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * as Xverse from "./barrel.js";
@@ -0,0 +1,4 @@
1
+ export * from "./btcMethods.advanced";
2
+ export * from "./provider.advanced";
3
+ export * from "./requests.advanced";
4
+ export * from "./types.advanced";
@@ -0,0 +1,304 @@
1
+ // From https://github.com/secretkeylabs/sats-connect-core/
2
+
3
+ /**
4
+ * Represents the types and interfaces related to BTC methods.
5
+ */
6
+
7
+ import * as v from "valibot";
8
+ import {
9
+ MethodParamsAndResult,
10
+ rpcRequestMessageSchema,
11
+ } from "./types.advanced";
12
+ import { walletTypeSchema } from "./walletMethods.advanced";
13
+
14
+ export enum AddressPurpose {
15
+ Ordinals = "ordinals",
16
+ Payment = "payment",
17
+ Stacks = "stacks",
18
+ }
19
+
20
+ export enum AddressType {
21
+ p2pkh = "p2pkh",
22
+ p2sh = "p2sh",
23
+ p2wpkh = "p2wpkh",
24
+ p2wsh = "p2wsh",
25
+ p2tr = "p2tr",
26
+ stacks = "stacks",
27
+ }
28
+
29
+ export const addressSchema = v.object({
30
+ address: v.string(),
31
+ publicKey: v.string(),
32
+ purpose: v.enum(AddressPurpose),
33
+ addressType: v.enum(AddressType),
34
+ });
35
+ export type Address = v.InferOutput<typeof addressSchema>;
36
+
37
+ export const getInfoMethodName = "getInfo";
38
+ export const getInfoParamsSchema = v.nullish(v.null());
39
+ export type GetInfoParams = v.InferOutput<typeof getInfoParamsSchema>;
40
+ export const getInfoResultSchema = v.object({
41
+ /**
42
+ * Version of the wallet.
43
+ */
44
+ version: v.string(),
45
+
46
+ /**
47
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
48
+ */
49
+ methods: v.optional(v.array(v.string())),
50
+
51
+ /**
52
+ * List of WBIP standards supported by the wallet. Not currently used.
53
+ */
54
+ supports: v.array(v.string()),
55
+ });
56
+ export type GetInfoResult = v.InferOutput<typeof getInfoResultSchema>;
57
+ export const getInfoRequestMessageSchema = v.object({
58
+ ...rpcRequestMessageSchema.entries,
59
+ ...v.object({
60
+ method: v.literal(getInfoMethodName),
61
+ params: getInfoParamsSchema,
62
+ id: v.string(),
63
+ }).entries,
64
+ });
65
+ export type GetInfoRequestMessage = v.InferOutput<
66
+ typeof getInfoRequestMessageSchema
67
+ >;
68
+ export type GetInfo = MethodParamsAndResult<
69
+ v.InferOutput<typeof getInfoParamsSchema>,
70
+ v.InferOutput<typeof getInfoResultSchema>
71
+ >;
72
+
73
+ export const getAddressesMethodName = "getAddresses";
74
+ export const getAddressesParamsSchema = v.object({
75
+ /**
76
+ * The purposes for which to generate addresses. See
77
+ * {@linkcode AddressPurpose} for available purposes.
78
+ */
79
+ purposes: v.array(v.enum(AddressPurpose)),
80
+ /**
81
+ * A message to be displayed to the user in the request prompt.
82
+ */
83
+ message: v.optional(v.string()),
84
+ });
85
+ export type GetAddressesParams = v.InferOutput<typeof getAddressesParamsSchema>;
86
+ export const getAddressesResultSchema = v.object({
87
+ /**
88
+ * The addresses generated for the given purposes.
89
+ */
90
+ addresses: v.array(addressSchema),
91
+ });
92
+ export type GetAddressesResult = v.InferOutput<typeof getAddressesResultSchema>;
93
+ export const getAddressesRequestMessageSchema = v.object({
94
+ ...rpcRequestMessageSchema.entries,
95
+ ...v.object({
96
+ method: v.literal(getAddressesMethodName),
97
+ params: getAddressesParamsSchema,
98
+ id: v.string(),
99
+ }).entries,
100
+ });
101
+ export type GetAddressesRequestMessage = v.InferOutput<
102
+ typeof getAddressesRequestMessageSchema
103
+ >;
104
+ export type GetAddresses = MethodParamsAndResult<
105
+ v.InferOutput<typeof getAddressesParamsSchema>,
106
+ v.InferOutput<typeof getAddressesResultSchema>
107
+ >;
108
+
109
+ export const signMessageMethodName = "signMessage";
110
+
111
+ export enum MessageSigningProtocols {
112
+ ECDSA = "ECDSA",
113
+ BIP322 = "BIP322",
114
+ }
115
+
116
+ export const signMessageParamsSchema = v.object({
117
+ /**
118
+ * The address used for signing.
119
+ **/
120
+ address: v.string(),
121
+ /**
122
+ * The message to sign.
123
+ **/
124
+ message: v.string(),
125
+ /**
126
+ * The protocol to use for signing the message.
127
+ */
128
+ protocol: v.optional(v.enum(MessageSigningProtocols)),
129
+ });
130
+ export type SignMessageParams = v.InferOutput<typeof signMessageParamsSchema>;
131
+ export const signMessageResultSchema = v.object({
132
+ /**
133
+ * The signature of the message.
134
+ */
135
+ signature: v.string(),
136
+ /**
137
+ * hash of the message.
138
+ */
139
+ messageHash: v.string(),
140
+ /**
141
+ * The address used for signing.
142
+ */
143
+ address: v.string(),
144
+ /**
145
+ * The protocol to use for signing the message.
146
+ */
147
+ protocol: v.enum(MessageSigningProtocols),
148
+ });
149
+ export type SignMessageResult = v.InferOutput<typeof signMessageResultSchema>;
150
+ export const signMessageRequestMessageSchema = v.object({
151
+ ...rpcRequestMessageSchema.entries,
152
+ ...v.object({
153
+ method: v.literal(signMessageMethodName),
154
+ params: signMessageParamsSchema,
155
+ id: v.string(),
156
+ }).entries,
157
+ });
158
+ export type SignMessageRequestMessage = v.InferOutput<
159
+ typeof signMessageRequestMessageSchema
160
+ >;
161
+ export type SignMessage = MethodParamsAndResult<
162
+ v.InferOutput<typeof signMessageParamsSchema>,
163
+ v.InferOutput<typeof signMessageResultSchema>
164
+ >;
165
+
166
+ type Recipient = {
167
+ /**
168
+ * The recipient's address.
169
+ **/
170
+ address: string;
171
+ /**
172
+ * The amount to send to the recipient in satoshis.
173
+ */
174
+ amount: number;
175
+ };
176
+
177
+ export type SendTransferParams = {
178
+ /**
179
+ * Array of recipients to send to.
180
+ * The amount to send to each recipient is in satoshis.
181
+ */
182
+ recipients: Array<Recipient>;
183
+ };
184
+ type SendTransferResult = {
185
+ /**
186
+ * The transaction id as a hex-encoded string.
187
+ */
188
+ txid: string;
189
+ };
190
+
191
+ export type SendTransfer = MethodParamsAndResult<
192
+ SendTransferParams,
193
+ SendTransferResult
194
+ >;
195
+
196
+ export type SignPsbtParams = {
197
+ /**
198
+ * The base64 encoded PSBT to sign.
199
+ */
200
+ psbt: string;
201
+ /**
202
+ * The inputs to sign.
203
+ * The key is the address and the value is an array of indexes of the inputs to sign.
204
+ */
205
+ signInputs: Record<string, number[]>;
206
+ /**
207
+ * the sigHash type to use for signing.
208
+ * will default to the sighash type of the input if not provided.
209
+ **/
210
+ allowedSignHash?: number;
211
+ /**
212
+ * Whether to broadcast the transaction after signing.
213
+ **/
214
+ broadcast?: boolean;
215
+ };
216
+
217
+ export type SignPsbtResult = {
218
+ /**
219
+ * The base64 encoded PSBT after signing.
220
+ */
221
+ psbt: string;
222
+ /**
223
+ * The transaction id as a hex-encoded string.
224
+ * This is only returned if the transaction was broadcast.
225
+ **/
226
+ txid?: string;
227
+ };
228
+
229
+ export type SignPsbt = MethodParamsAndResult<SignPsbtParams, SignPsbtResult>;
230
+
231
+ export const getAccountsMethodName = "getAccounts";
232
+ export const getAccountsParamsSchema = v.object({
233
+ /**
234
+ * The purposes for which to generate addresses. See
235
+ * {@linkcode AddressPurpose} for available purposes.
236
+ */
237
+ purposes: v.array(v.enum(AddressPurpose)),
238
+ /**
239
+ * A message to be displayed to the user in the request prompt.
240
+ */
241
+ message: v.optional(v.string()),
242
+ });
243
+ export type GetAccountsParams = v.InferOutput<typeof getAccountsParamsSchema>;
244
+
245
+ export const getAccountsResultSchema = v.array(
246
+ v.object({
247
+ ...addressSchema.entries,
248
+ ...v.object({
249
+ walletType: walletTypeSchema,
250
+ }).entries,
251
+ }),
252
+ );
253
+ export type GetAccountsResult = v.InferOutput<typeof getAccountsResultSchema>;
254
+ export const getAccountsRequestMessageSchema = v.object({
255
+ ...rpcRequestMessageSchema.entries,
256
+ ...v.object({
257
+ method: v.literal(getAccountsMethodName),
258
+ params: getAccountsParamsSchema,
259
+ id: v.string(),
260
+ }).entries,
261
+ });
262
+ export type GetAccountsRequestMessage = v.InferOutput<
263
+ typeof getAccountsRequestMessageSchema
264
+ >;
265
+ export type GetAccounts = MethodParamsAndResult<
266
+ v.InferOutput<typeof getAccountsParamsSchema>,
267
+ v.InferOutput<typeof getAccountsResultSchema>
268
+ >;
269
+
270
+ export const getBalanceMethodName = "getBalance";
271
+ export const getBalanceParamsSchema = v.nullish(v.null());
272
+ export const getBalanceResultSchema = v.object({
273
+ /**
274
+ * The confirmed balance of the wallet in sats. Using a string due to chrome
275
+ * messages not supporting bigint
276
+ * (https://issues.chromium.org/issues/40116184).
277
+ */
278
+ confirmed: v.string(),
279
+
280
+ /**
281
+ * The unconfirmed balance of the wallet in sats. Using a string due to chrome
282
+ * messages not supporting bigint
283
+ * (https://issues.chromium.org/issues/40116184).
284
+ */
285
+ unconfirmed: v.string(),
286
+
287
+ /**
288
+ * The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
289
+ * sats. Using a string due to chrome messages not supporting bigint
290
+ * (https://issues.chromium.org/issues/40116184).
291
+ */
292
+ total: v.string(),
293
+ });
294
+ export const getBalanceRequestMessageSchema = v.object({
295
+ ...rpcRequestMessageSchema.entries,
296
+ ...v.object({
297
+ method: v.literal(getBalanceMethodName),
298
+ id: v.string(),
299
+ }).entries,
300
+ });
301
+ export type GetBalance = MethodParamsAndResult<
302
+ v.InferOutput<typeof getBalanceParamsSchema>,
303
+ v.InferOutput<typeof getBalanceResultSchema>
304
+ >;
@@ -0,0 +1,61 @@
1
+ import * as v from "valibot";
2
+ import { Requests, Params } from "./requests.advanced";
3
+ import { RpcResponse } from "./types.advanced";
4
+
5
+ // accountChange
6
+ export const accountChangeEventName = "accountChange";
7
+ export const accountChangeSchema = v.object({
8
+ type: v.literal(accountChangeEventName),
9
+ });
10
+ export type AccountChangeEvent = v.InferOutput<typeof accountChangeSchema>;
11
+
12
+ // networkChange
13
+ export const networkChangeEventName = "networkChange";
14
+ export const networkChangeSchema = v.object({
15
+ type: v.literal(networkChangeEventName),
16
+ });
17
+ export type NetworkChangeEvent = v.InferOutput<typeof networkChangeSchema>;
18
+
19
+ // disconnect
20
+ export const disconnectEventName = "disconnect";
21
+ export const disconnectSchema = v.object({
22
+ type: v.literal(disconnectEventName),
23
+ });
24
+ export type DisconnectEvent = v.InferOutput<typeof disconnectSchema>;
25
+
26
+ export const walletEventSchema = v.variant("type", [
27
+ accountChangeSchema,
28
+ networkChangeSchema,
29
+ disconnectSchema,
30
+ ]);
31
+
32
+ export type WalletEvent = v.InferOutput<typeof walletEventSchema>;
33
+ export type AddListener = <const WalletEventName extends WalletEvent["type"]>(
34
+ eventName: WalletEventName,
35
+ cb: (event: Extract<WalletEvent, { type: WalletEventName }>) => void,
36
+ ) => () => void;
37
+
38
+ /**
39
+ * Interface representing a provider for interacting with accounts and signing messages.
40
+ */
41
+ export interface BtcProvider {
42
+ request: <Method extends keyof Requests>(
43
+ method: Method,
44
+ options: Params<Method>,
45
+ providerId?: string,
46
+ ) => Promise<RpcResponse<Method>>;
47
+
48
+ addListener: AddListener;
49
+ }
50
+
51
+ export interface Provider {
52
+ id: string;
53
+ name: string;
54
+ icon: string;
55
+ webUrl?: string;
56
+ chromeWebStoreUrl?: string;
57
+ mozillaAddOnsUrl?: string;
58
+ googlePlayStoreUrl?: string;
59
+ iOSAppStoreUrl?: string;
60
+ methods?: string[];
61
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ GetAccounts,
3
+ GetAddresses,
4
+ GetBalance,
5
+ GetInfo,
6
+ SendTransfer,
7
+ SignMessage,
8
+ SignPsbt,
9
+ } from "./btcMethods.advanced";
10
+ import {
11
+ GetWalletType,
12
+ RenouncePermissions,
13
+ RequestPermissions,
14
+ } from "./walletMethods.advanced";
15
+
16
+ export interface BtcRequests {
17
+ getInfo: GetInfo;
18
+ getAddresses: GetAddresses;
19
+ getAccounts: GetAccounts;
20
+ getBalance: GetBalance;
21
+ signMessage: SignMessage;
22
+ sendTransfer: SendTransfer;
23
+ signPsbt: SignPsbt;
24
+ }
25
+
26
+ export type BtcRequestMethod = keyof BtcRequests;
27
+
28
+ export interface WalletRequests {
29
+ wallet_requestPermissions: RequestPermissions;
30
+ wallet_renouncePermissions: RenouncePermissions;
31
+ wallet_getWalletType: GetWalletType;
32
+ }
33
+
34
+ export type Requests = BtcRequests & WalletRequests;
35
+
36
+ export type Return<Method> = Method extends keyof Requests
37
+ ? Requests[Method]["result"]
38
+ : never;
39
+ export type Params<Method> = Method extends keyof Requests
40
+ ? Requests[Method]["params"]
41
+ : never;
@@ -0,0 +1,159 @@
1
+ // From https://github.com/secretkeylabs/sats-connect-core/
2
+
3
+ import * as v from "valibot";
4
+ import type { BtcProvider } from "./provider.advanced";
5
+ import type { Requests, Return } from "./requests.advanced";
6
+
7
+ export enum BitcoinNetworkType {
8
+ Mainnet = "Mainnet",
9
+ Testnet = "Testnet",
10
+ Signet = "Signet",
11
+ }
12
+
13
+ export interface BitcoinNetwork {
14
+ type: BitcoinNetworkType;
15
+ address?: string;
16
+ }
17
+
18
+ export interface RequestPayload {
19
+ network: BitcoinNetwork;
20
+ }
21
+
22
+ export interface RequestOptions<Payload extends RequestPayload, Response> {
23
+ onFinish: (response: Response) => void;
24
+ onCancel: () => void;
25
+ payload: Payload;
26
+ getProvider?: () => Promise<BtcProvider | undefined>;
27
+ }
28
+
29
+ // RPC Request and Response types
30
+
31
+ export const RpcIdSchema = v.optional(
32
+ v.union([v.string(), v.number(), v.null()]),
33
+ );
34
+ export type RpcId = v.InferOutput<typeof RpcIdSchema>;
35
+ export const rpcRequestMessageSchema = v.object({
36
+ jsonrpc: v.literal("2.0"),
37
+ method: v.string(),
38
+ params: v.optional(
39
+ v.union([
40
+ v.array(v.unknown()),
41
+ v.looseObject({}),
42
+ // Note: This is to support current incorrect usage of RPC 2.0. Params need
43
+ // to be either an array or an object when provided. Changing this now would
44
+ // be a breaking change, so accepting null values for now. Tracking in
45
+ // https://linear.app/xverseapp/issue/ENG-4538.
46
+ v.null(),
47
+ ]),
48
+ ),
49
+ id: RpcIdSchema,
50
+ });
51
+ export type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
52
+
53
+ export interface RpcBase {
54
+ jsonrpc: "2.0";
55
+ id: RpcId;
56
+ }
57
+ export interface RpcRequest<T extends string, U> extends RpcBase {
58
+ method: T;
59
+ params: U;
60
+ }
61
+
62
+ export interface MethodParamsAndResult<TParams, TResult> {
63
+ params: TParams;
64
+ result: TResult;
65
+ }
66
+
67
+ /**
68
+ * @enum {number} RpcErrorCode
69
+ * @description JSON-RPC error codes
70
+ * @see https://www.jsonrpc.org/specification#error_object
71
+ */
72
+ export enum RpcErrorCode {
73
+ /**
74
+ * Parse error Invalid JSON
75
+ **/
76
+ PARSE_ERROR = -32700,
77
+ /**
78
+ * The JSON sent is not a valid Request object.
79
+ **/
80
+ INVALID_REQUEST = -32600,
81
+ /**
82
+ * The method does not exist/is not available.
83
+ **/
84
+ METHOD_NOT_FOUND = -32601,
85
+ /**
86
+ * Invalid method parameter(s).
87
+ */
88
+ INVALID_PARAMS = -32602,
89
+ /**
90
+ * Internal JSON-RPC error.
91
+ * This is a generic error, used when the server encounters an error in performing the request.
92
+ **/
93
+ INTERNAL_ERROR = -32603,
94
+ /**
95
+ * user rejected/canceled the request
96
+ */
97
+ USER_REJECTION = -32000,
98
+ /**
99
+ * method is not supported for the address provided
100
+ */
101
+ METHOD_NOT_SUPPORTED = -32001,
102
+ /**
103
+ * The client does not have permission to access the requested resource.
104
+ */
105
+ ACCESS_DENIED = -32002,
106
+ }
107
+
108
+ export const rpcSuccessResponseMessageSchema = v.object({
109
+ jsonrpc: v.literal("2.0"),
110
+ result: v.nonOptional(v.unknown()),
111
+ id: RpcIdSchema,
112
+ });
113
+ export type RpcSuccessResponseMessage = v.InferOutput<
114
+ typeof rpcSuccessResponseMessageSchema
115
+ >;
116
+
117
+ export const rpcErrorResponseMessageSchema = v.object({
118
+ jsonrpc: v.literal("2.0"),
119
+ error: v.nonOptional(v.unknown()),
120
+ id: RpcIdSchema,
121
+ });
122
+ export type RpcErrorResponseMessage = v.InferOutput<
123
+ typeof rpcErrorResponseMessageSchema
124
+ >;
125
+ export const rpcResponseMessageSchema = v.union([
126
+ rpcSuccessResponseMessageSchema,
127
+ rpcErrorResponseMessageSchema,
128
+ ]);
129
+ export type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
130
+
131
+ export interface RpcError {
132
+ code: number | RpcErrorCode;
133
+ message: string;
134
+ data?: any;
135
+ }
136
+
137
+ export interface RpcErrorResponse<TError extends RpcError = RpcError>
138
+ extends RpcBase {
139
+ error: TError;
140
+ }
141
+
142
+ export interface RpcSuccessResponse<Method extends keyof Requests>
143
+ extends RpcBase {
144
+ result: Return<Method>;
145
+ }
146
+
147
+ export type RpcResponse<Method extends keyof Requests> =
148
+ | RpcSuccessResponse<Method>
149
+ | RpcErrorResponse;
150
+
151
+ export type RpcResult<Method extends keyof Requests> =
152
+ | {
153
+ result: RpcSuccessResponse<Method>["result"];
154
+ status: "success";
155
+ }
156
+ | {
157
+ error: RpcErrorResponse["error"];
158
+ status: "error";
159
+ };
@@ -0,0 +1,58 @@
1
+ // From https://github.com/secretkeylabs/sats-connect-core/
2
+
3
+ import * as v from "valibot";
4
+ import {
5
+ MethodParamsAndResult,
6
+ rpcRequestMessageSchema,
7
+ } from "./types.advanced.js";
8
+
9
+ export const walletTypes = ["software", "ledger"] as const;
10
+ export const walletTypeSchema = v.picklist(walletTypes);
11
+ export type WalletType = v.InferOutput<typeof walletTypeSchema>;
12
+
13
+ export const requestPermissionsMethodName = "wallet_requestPermissions";
14
+ export const requestPermissionsParamsSchema = v.undefined();
15
+ export const requestPermissionsResultSchema = v.literal(true);
16
+ export const requestPermissionsRequestMessageSchema = v.object({
17
+ ...rpcRequestMessageSchema.entries,
18
+ ...v.object({
19
+ method: v.literal(requestPermissionsMethodName),
20
+ params: requestPermissionsParamsSchema,
21
+ id: v.string(),
22
+ }).entries,
23
+ });
24
+ export type RequestPermissions = MethodParamsAndResult<
25
+ v.InferOutput<typeof requestPermissionsParamsSchema>,
26
+ v.InferOutput<typeof requestPermissionsResultSchema>
27
+ >;
28
+
29
+ export const renouncePermissionsMethodName = "wallet_renouncePermissions";
30
+ export const renouncePermissionsParamsSchema = v.undefined();
31
+ export const renouncePermissionsResultSchema = v.literal(true);
32
+ export const renouncePermissionsRequestMessageSchema = v.object({
33
+ ...rpcRequestMessageSchema.entries,
34
+ ...v.object({
35
+ method: v.literal(renouncePermissionsMethodName),
36
+ params: renouncePermissionsParamsSchema,
37
+ id: v.string(),
38
+ }).entries,
39
+ });
40
+ export type RenouncePermissions = MethodParamsAndResult<
41
+ v.InferOutput<typeof renouncePermissionsParamsSchema>,
42
+ v.InferOutput<typeof renouncePermissionsResultSchema>
43
+ >;
44
+
45
+ export const getWalletTypeMethodName = "wallet_getWalletType";
46
+ export const getWalletTypeParamsSchema = v.nullish(v.null());
47
+ export const getWalletTypeResultSchema = walletTypeSchema;
48
+ export const getWalletTypeRequestMessageSchema = v.object({
49
+ ...rpcRequestMessageSchema.entries,
50
+ ...v.object({
51
+ method: v.literal(getWalletTypeMethodName),
52
+ id: v.string(),
53
+ }).entries,
54
+ });
55
+ export type GetWalletType = MethodParamsAndResult<
56
+ v.InferOutput<typeof getWalletTypeParamsSchema>,
57
+ v.InferOutput<typeof getWalletTypeResultSchema>
58
+ >;