@sats-connect/core 0.7.0 → 0.7.1

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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,136 @@
1
1
  import * as v from 'valibot';
2
2
 
3
+ declare enum BitcoinNetworkType {
4
+ Mainnet = "Mainnet",
5
+ Testnet = "Testnet",
6
+ Testnet4 = "Testnet4",
7
+ Signet = "Signet",
8
+ Regtest = "Regtest"
9
+ }
10
+ declare enum StacksNetworkType {
11
+ Mainnet = "mainnet",
12
+ Testnet = "testnet"
13
+ }
14
+ declare enum StarknetNetworkType {
15
+ Mainnet = "mainnet",
16
+ Sepolia = "sepolia"
17
+ }
18
+ interface BitcoinNetwork {
19
+ type: BitcoinNetworkType;
20
+ address?: string;
21
+ }
22
+ interface RequestPayload {
23
+ network: BitcoinNetwork;
24
+ }
25
+ interface RequestOptions<Payload extends RequestPayload, Response> {
26
+ onFinish: (response: Response) => void;
27
+ onCancel: () => void;
28
+ payload: Payload;
29
+ getProvider?: () => Promise<BitcoinProvider | undefined>;
30
+ }
31
+ declare const RpcIdSchema: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
32
+ type RpcId = v.InferOutput<typeof RpcIdSchema>;
33
+ declare const rpcRequestMessageSchema: v.ObjectSchema<{
34
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
35
+ readonly method: v.StringSchema<undefined>;
36
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, undefined>;
37
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
38
+ }, undefined>;
39
+ type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
40
+ interface RpcBase {
41
+ jsonrpc: '2.0';
42
+ id: RpcId;
43
+ }
44
+ interface RpcRequest<T extends string, U> extends RpcBase {
45
+ method: T;
46
+ params: U;
47
+ }
48
+ interface MethodParamsAndResult<TParams, TResult> {
49
+ params: TParams;
50
+ result: TResult;
51
+ }
52
+ /**
53
+ * @enum {number} RpcErrorCode
54
+ * @description JSON-RPC error codes
55
+ * @see https://www.jsonrpc.org/specification#error_object
56
+ */
57
+ declare enum RpcErrorCode {
58
+ /**
59
+ * Parse error Invalid JSON
60
+ **/
61
+ PARSE_ERROR = -32700,
62
+ /**
63
+ * The JSON sent is not a valid Request object.
64
+ **/
65
+ INVALID_REQUEST = -32600,
66
+ /**
67
+ * The method does not exist/is not available.
68
+ **/
69
+ METHOD_NOT_FOUND = -32601,
70
+ /**
71
+ * Invalid method parameter(s).
72
+ */
73
+ INVALID_PARAMS = -32602,
74
+ /**
75
+ * Internal JSON-RPC error.
76
+ * This is a generic error, used when the server encounters an error in performing the request.
77
+ **/
78
+ INTERNAL_ERROR = -32603,
79
+ /**
80
+ * user rejected/canceled the request
81
+ */
82
+ USER_REJECTION = -32000,
83
+ /**
84
+ * method is not supported for the address provided
85
+ */
86
+ METHOD_NOT_SUPPORTED = -32001,
87
+ /**
88
+ * The client does not have permission to access the requested resource.
89
+ */
90
+ ACCESS_DENIED = -32002
91
+ }
92
+ declare const rpcSuccessResponseMessageSchema: v.ObjectSchema<{
93
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
94
+ readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
95
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
96
+ }, undefined>;
97
+ type RpcSuccessResponseMessage = v.InferOutput<typeof rpcSuccessResponseMessageSchema>;
98
+ declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
99
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
100
+ readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
101
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
102
+ }, undefined>;
103
+ type RpcErrorResponseMessage = v.InferOutput<typeof rpcErrorResponseMessageSchema>;
104
+ declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
105
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
106
+ readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
107
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
108
+ }, undefined>, v.ObjectSchema<{
109
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
110
+ readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
111
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
112
+ }, undefined>], undefined>;
113
+ type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
114
+ interface RpcError {
115
+ code: number | RpcErrorCode;
116
+ message: string;
117
+ data?: any;
118
+ }
119
+ interface RpcErrorResponse<TError extends RpcError = RpcError> extends RpcBase {
120
+ error: TError;
121
+ }
122
+ interface RpcSuccessResponse<Method extends keyof Requests> extends RpcBase {
123
+ result: Return<Method>;
124
+ }
125
+ type RpcResponse<Method extends keyof Requests> = RpcSuccessResponse<Method> | RpcErrorResponse;
126
+ type RpcResult<Method extends keyof Requests> = {
127
+ result: RpcSuccessResponse<Method>['result'];
128
+ status: 'success';
129
+ } | {
130
+ error: RpcErrorResponse['error'];
131
+ status: 'error';
132
+ };
133
+
3
134
  declare enum AddressPurpose {
4
135
  Ordinals = "ordinals",
5
136
  Payment = "payment",
@@ -255,137 +386,6 @@ declare function getDefaultProvider(): string | null;
255
386
  declare function removeDefaultProvider(): void;
256
387
  declare function getSupportedWallets(): SupportedWallet[];
257
388
 
258
- declare enum BitcoinNetworkType {
259
- Mainnet = "Mainnet",
260
- Testnet = "Testnet",
261
- Testnet4 = "Testnet4",
262
- Signet = "Signet",
263
- Regtest = "Regtest"
264
- }
265
- declare enum StacksNetworkType {
266
- Mainnet = "mainnet",
267
- Testnet = "testnet"
268
- }
269
- declare enum StarknetNetworkType {
270
- Mainnet = "mainnet",
271
- Sepolia = "sepolia"
272
- }
273
- interface BitcoinNetwork {
274
- type: BitcoinNetworkType;
275
- address?: string;
276
- }
277
- interface RequestPayload {
278
- network: BitcoinNetwork;
279
- }
280
- interface RequestOptions<Payload extends RequestPayload, Response> {
281
- onFinish: (response: Response) => void;
282
- onCancel: () => void;
283
- payload: Payload;
284
- getProvider?: () => Promise<BitcoinProvider | undefined>;
285
- }
286
- declare const RpcIdSchema: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
287
- type RpcId = v.InferOutput<typeof RpcIdSchema>;
288
- declare const rpcRequestMessageSchema: v.ObjectSchema<{
289
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
290
- readonly method: v.StringSchema<undefined>;
291
- readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, undefined>;
292
- readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
293
- }, undefined>;
294
- type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
295
- interface RpcBase {
296
- jsonrpc: '2.0';
297
- id: RpcId;
298
- }
299
- interface RpcRequest<T extends string, U> extends RpcBase {
300
- method: T;
301
- params: U;
302
- }
303
- interface MethodParamsAndResult<TParams, TResult> {
304
- params: TParams;
305
- result: TResult;
306
- }
307
- /**
308
- * @enum {number} RpcErrorCode
309
- * @description JSON-RPC error codes
310
- * @see https://www.jsonrpc.org/specification#error_object
311
- */
312
- declare enum RpcErrorCode {
313
- /**
314
- * Parse error Invalid JSON
315
- **/
316
- PARSE_ERROR = -32700,
317
- /**
318
- * The JSON sent is not a valid Request object.
319
- **/
320
- INVALID_REQUEST = -32600,
321
- /**
322
- * The method does not exist/is not available.
323
- **/
324
- METHOD_NOT_FOUND = -32601,
325
- /**
326
- * Invalid method parameter(s).
327
- */
328
- INVALID_PARAMS = -32602,
329
- /**
330
- * Internal JSON-RPC error.
331
- * This is a generic error, used when the server encounters an error in performing the request.
332
- **/
333
- INTERNAL_ERROR = -32603,
334
- /**
335
- * user rejected/canceled the request
336
- */
337
- USER_REJECTION = -32000,
338
- /**
339
- * method is not supported for the address provided
340
- */
341
- METHOD_NOT_SUPPORTED = -32001,
342
- /**
343
- * The client does not have permission to access the requested resource.
344
- */
345
- ACCESS_DENIED = -32002
346
- }
347
- declare const rpcSuccessResponseMessageSchema: v.ObjectSchema<{
348
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
349
- readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
350
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
351
- }, undefined>;
352
- type RpcSuccessResponseMessage = v.InferOutput<typeof rpcSuccessResponseMessageSchema>;
353
- declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
354
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
355
- readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
356
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
357
- }, undefined>;
358
- type RpcErrorResponseMessage = v.InferOutput<typeof rpcErrorResponseMessageSchema>;
359
- declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
360
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
361
- readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
362
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
363
- }, undefined>, v.ObjectSchema<{
364
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
365
- readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
366
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
367
- }, undefined>], undefined>;
368
- type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
369
- interface RpcError {
370
- code: number | RpcErrorCode;
371
- message: string;
372
- data?: any;
373
- }
374
- interface RpcErrorResponse<TError extends RpcError = RpcError> extends RpcBase {
375
- error: TError;
376
- }
377
- interface RpcSuccessResponse<Method extends keyof Requests> extends RpcBase {
378
- result: Return<Method>;
379
- }
380
- type RpcResponse<Method extends keyof Requests> = RpcSuccessResponse<Method> | RpcErrorResponse;
381
- type RpcResult<Method extends keyof Requests> = {
382
- result: RpcSuccessResponse<Method>['result'];
383
- status: 'success';
384
- } | {
385
- error: RpcErrorResponse['error'];
386
- status: 'error';
387
- };
388
-
389
389
  declare const getInfoMethodName = "getInfo";
390
390
  declare const getInfoParamsSchema: v.NullishSchema<v.NullSchema<undefined>, undefined>;
391
391
  type GetInfoParams = v.InferOutput<typeof getInfoParamsSchema>;
@@ -432,18 +432,13 @@ declare const getAddressesResultSchema: v.ObjectSchema<{
432
432
  readonly addresses: v.ArraySchema<v.ObjectSchema<{
433
433
  readonly address: v.StringSchema<undefined>;
434
434
  readonly publicKey: v.StringSchema<undefined>;
435
- readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>; /**
436
- * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
437
- */
435
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
438
436
  readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
439
437
  readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
440
438
  }, undefined>, undefined>;
441
439
  readonly network: v.ObjectSchema<{
442
440
  readonly bitcoin: v.ObjectSchema<{
443
- readonly name: v.EnumSchema<typeof BitcoinNetworkType, undefined>; /**
444
- * The purposes for which to generate addresses. See
445
- * {@linkcode AddressPurpose} for available purposes.
446
- */
441
+ readonly name: v.EnumSchema<typeof BitcoinNetworkType, undefined>;
447
442
  }, undefined>;
448
443
  readonly stacks: v.ObjectSchema<{
449
444
  readonly name: v.StringSchema<undefined>;
@@ -633,9 +628,7 @@ declare const getAccountsResultSchema: v.ArraySchema<v.ObjectSchema<{
633
628
  readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
634
629
  readonly address: v.StringSchema<undefined>;
635
630
  readonly publicKey: v.StringSchema<undefined>;
636
- readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>; /**
637
- * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
638
- */
631
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
639
632
  readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
640
633
  }, undefined>, undefined>;
641
634
  type GetAccountsResult = v.InferOutput<typeof getAccountsResultSchema>;
@@ -1970,8 +1963,24 @@ type Requests = BtcRequests & StxRequests & RunesRequests & WalletRequests & Ord
1970
1963
  type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
1971
1964
  type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
1972
1965
 
1973
- declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletRequests | keyof OrdinalsRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
1974
- declare const addListener: (listenerInfo: ListenerInfo, providerId?: string) => ReturnType<AddListener>;
1966
+ declare const request: <Method extends keyof Requests>(method: Method, params: Params<Method>,
1967
+ /**
1968
+ * The providerId is the object path to the provider in the window object.
1969
+ * E.g., a provider available at `window.Foo.BarProvider` would have a
1970
+ * providerId of `Foo.BarProvider`.
1971
+ */
1972
+ providerId?: string) => Promise<RpcResult<Method>>;
1973
+ /**
1974
+ * Adds an event listener.
1975
+ *
1976
+ * Currently expects 2 arguments, although is also capable of handling legacy
1977
+ * calls with 3 arguments consisting of:
1978
+ *
1979
+ * - event name (string)
1980
+ * - callback (function)
1981
+ * - provider ID (optional string)
1982
+ */
1983
+ declare const addListener: (...rawArgs: unknown[]) => ReturnType<AddListener>;
1975
1984
 
1976
1985
  declare abstract class SatsConnectAdapter {
1977
1986
  abstract readonly id: string;
@@ -1990,7 +1999,7 @@ declare abstract class SatsConnectAdapter {
1990
1999
  declare class BaseAdapter extends SatsConnectAdapter {
1991
2000
  id: string;
1992
2001
  constructor(providerId: string);
1993
- requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletRequests | keyof OrdinalsRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
2002
+ requestInternal: <Method extends keyof Requests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
1994
2003
  addListener: AddListener;
1995
2004
  }
1996
2005
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,136 @@
1
1
  import * as v from 'valibot';
2
2
 
3
+ declare enum BitcoinNetworkType {
4
+ Mainnet = "Mainnet",
5
+ Testnet = "Testnet",
6
+ Testnet4 = "Testnet4",
7
+ Signet = "Signet",
8
+ Regtest = "Regtest"
9
+ }
10
+ declare enum StacksNetworkType {
11
+ Mainnet = "mainnet",
12
+ Testnet = "testnet"
13
+ }
14
+ declare enum StarknetNetworkType {
15
+ Mainnet = "mainnet",
16
+ Sepolia = "sepolia"
17
+ }
18
+ interface BitcoinNetwork {
19
+ type: BitcoinNetworkType;
20
+ address?: string;
21
+ }
22
+ interface RequestPayload {
23
+ network: BitcoinNetwork;
24
+ }
25
+ interface RequestOptions<Payload extends RequestPayload, Response> {
26
+ onFinish: (response: Response) => void;
27
+ onCancel: () => void;
28
+ payload: Payload;
29
+ getProvider?: () => Promise<BitcoinProvider | undefined>;
30
+ }
31
+ declare const RpcIdSchema: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
32
+ type RpcId = v.InferOutput<typeof RpcIdSchema>;
33
+ declare const rpcRequestMessageSchema: v.ObjectSchema<{
34
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
35
+ readonly method: v.StringSchema<undefined>;
36
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, undefined>;
37
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
38
+ }, undefined>;
39
+ type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
40
+ interface RpcBase {
41
+ jsonrpc: '2.0';
42
+ id: RpcId;
43
+ }
44
+ interface RpcRequest<T extends string, U> extends RpcBase {
45
+ method: T;
46
+ params: U;
47
+ }
48
+ interface MethodParamsAndResult<TParams, TResult> {
49
+ params: TParams;
50
+ result: TResult;
51
+ }
52
+ /**
53
+ * @enum {number} RpcErrorCode
54
+ * @description JSON-RPC error codes
55
+ * @see https://www.jsonrpc.org/specification#error_object
56
+ */
57
+ declare enum RpcErrorCode {
58
+ /**
59
+ * Parse error Invalid JSON
60
+ **/
61
+ PARSE_ERROR = -32700,
62
+ /**
63
+ * The JSON sent is not a valid Request object.
64
+ **/
65
+ INVALID_REQUEST = -32600,
66
+ /**
67
+ * The method does not exist/is not available.
68
+ **/
69
+ METHOD_NOT_FOUND = -32601,
70
+ /**
71
+ * Invalid method parameter(s).
72
+ */
73
+ INVALID_PARAMS = -32602,
74
+ /**
75
+ * Internal JSON-RPC error.
76
+ * This is a generic error, used when the server encounters an error in performing the request.
77
+ **/
78
+ INTERNAL_ERROR = -32603,
79
+ /**
80
+ * user rejected/canceled the request
81
+ */
82
+ USER_REJECTION = -32000,
83
+ /**
84
+ * method is not supported for the address provided
85
+ */
86
+ METHOD_NOT_SUPPORTED = -32001,
87
+ /**
88
+ * The client does not have permission to access the requested resource.
89
+ */
90
+ ACCESS_DENIED = -32002
91
+ }
92
+ declare const rpcSuccessResponseMessageSchema: v.ObjectSchema<{
93
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
94
+ readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
95
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
96
+ }, undefined>;
97
+ type RpcSuccessResponseMessage = v.InferOutput<typeof rpcSuccessResponseMessageSchema>;
98
+ declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
99
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
100
+ readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
101
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
102
+ }, undefined>;
103
+ type RpcErrorResponseMessage = v.InferOutput<typeof rpcErrorResponseMessageSchema>;
104
+ declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
105
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
106
+ readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
107
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
108
+ }, undefined>, v.ObjectSchema<{
109
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
110
+ readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
111
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
112
+ }, undefined>], undefined>;
113
+ type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
114
+ interface RpcError {
115
+ code: number | RpcErrorCode;
116
+ message: string;
117
+ data?: any;
118
+ }
119
+ interface RpcErrorResponse<TError extends RpcError = RpcError> extends RpcBase {
120
+ error: TError;
121
+ }
122
+ interface RpcSuccessResponse<Method extends keyof Requests> extends RpcBase {
123
+ result: Return<Method>;
124
+ }
125
+ type RpcResponse<Method extends keyof Requests> = RpcSuccessResponse<Method> | RpcErrorResponse;
126
+ type RpcResult<Method extends keyof Requests> = {
127
+ result: RpcSuccessResponse<Method>['result'];
128
+ status: 'success';
129
+ } | {
130
+ error: RpcErrorResponse['error'];
131
+ status: 'error';
132
+ };
133
+
3
134
  declare enum AddressPurpose {
4
135
  Ordinals = "ordinals",
5
136
  Payment = "payment",
@@ -255,137 +386,6 @@ declare function getDefaultProvider(): string | null;
255
386
  declare function removeDefaultProvider(): void;
256
387
  declare function getSupportedWallets(): SupportedWallet[];
257
388
 
258
- declare enum BitcoinNetworkType {
259
- Mainnet = "Mainnet",
260
- Testnet = "Testnet",
261
- Testnet4 = "Testnet4",
262
- Signet = "Signet",
263
- Regtest = "Regtest"
264
- }
265
- declare enum StacksNetworkType {
266
- Mainnet = "mainnet",
267
- Testnet = "testnet"
268
- }
269
- declare enum StarknetNetworkType {
270
- Mainnet = "mainnet",
271
- Sepolia = "sepolia"
272
- }
273
- interface BitcoinNetwork {
274
- type: BitcoinNetworkType;
275
- address?: string;
276
- }
277
- interface RequestPayload {
278
- network: BitcoinNetwork;
279
- }
280
- interface RequestOptions<Payload extends RequestPayload, Response> {
281
- onFinish: (response: Response) => void;
282
- onCancel: () => void;
283
- payload: Payload;
284
- getProvider?: () => Promise<BitcoinProvider | undefined>;
285
- }
286
- declare const RpcIdSchema: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
287
- type RpcId = v.InferOutput<typeof RpcIdSchema>;
288
- declare const rpcRequestMessageSchema: v.ObjectSchema<{
289
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
290
- readonly method: v.StringSchema<undefined>;
291
- readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, undefined>;
292
- readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>;
293
- }, undefined>;
294
- type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
295
- interface RpcBase {
296
- jsonrpc: '2.0';
297
- id: RpcId;
298
- }
299
- interface RpcRequest<T extends string, U> extends RpcBase {
300
- method: T;
301
- params: U;
302
- }
303
- interface MethodParamsAndResult<TParams, TResult> {
304
- params: TParams;
305
- result: TResult;
306
- }
307
- /**
308
- * @enum {number} RpcErrorCode
309
- * @description JSON-RPC error codes
310
- * @see https://www.jsonrpc.org/specification#error_object
311
- */
312
- declare enum RpcErrorCode {
313
- /**
314
- * Parse error Invalid JSON
315
- **/
316
- PARSE_ERROR = -32700,
317
- /**
318
- * The JSON sent is not a valid Request object.
319
- **/
320
- INVALID_REQUEST = -32600,
321
- /**
322
- * The method does not exist/is not available.
323
- **/
324
- METHOD_NOT_FOUND = -32601,
325
- /**
326
- * Invalid method parameter(s).
327
- */
328
- INVALID_PARAMS = -32602,
329
- /**
330
- * Internal JSON-RPC error.
331
- * This is a generic error, used when the server encounters an error in performing the request.
332
- **/
333
- INTERNAL_ERROR = -32603,
334
- /**
335
- * user rejected/canceled the request
336
- */
337
- USER_REJECTION = -32000,
338
- /**
339
- * method is not supported for the address provided
340
- */
341
- METHOD_NOT_SUPPORTED = -32001,
342
- /**
343
- * The client does not have permission to access the requested resource.
344
- */
345
- ACCESS_DENIED = -32002
346
- }
347
- declare const rpcSuccessResponseMessageSchema: v.ObjectSchema<{
348
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
349
- readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
350
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
351
- }, undefined>;
352
- type RpcSuccessResponseMessage = v.InferOutput<typeof rpcSuccessResponseMessageSchema>;
353
- declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
354
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
355
- readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
356
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
357
- }, undefined>;
358
- type RpcErrorResponseMessage = v.InferOutput<typeof rpcErrorResponseMessageSchema>;
359
- declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
360
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
361
- readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
362
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
363
- }, undefined>, v.ObjectSchema<{
364
- readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
365
- readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
366
- readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>;
367
- }, undefined>], undefined>;
368
- type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
369
- interface RpcError {
370
- code: number | RpcErrorCode;
371
- message: string;
372
- data?: any;
373
- }
374
- interface RpcErrorResponse<TError extends RpcError = RpcError> extends RpcBase {
375
- error: TError;
376
- }
377
- interface RpcSuccessResponse<Method extends keyof Requests> extends RpcBase {
378
- result: Return<Method>;
379
- }
380
- type RpcResponse<Method extends keyof Requests> = RpcSuccessResponse<Method> | RpcErrorResponse;
381
- type RpcResult<Method extends keyof Requests> = {
382
- result: RpcSuccessResponse<Method>['result'];
383
- status: 'success';
384
- } | {
385
- error: RpcErrorResponse['error'];
386
- status: 'error';
387
- };
388
-
389
389
  declare const getInfoMethodName = "getInfo";
390
390
  declare const getInfoParamsSchema: v.NullishSchema<v.NullSchema<undefined>, undefined>;
391
391
  type GetInfoParams = v.InferOutput<typeof getInfoParamsSchema>;
@@ -432,18 +432,13 @@ declare const getAddressesResultSchema: v.ObjectSchema<{
432
432
  readonly addresses: v.ArraySchema<v.ObjectSchema<{
433
433
  readonly address: v.StringSchema<undefined>;
434
434
  readonly publicKey: v.StringSchema<undefined>;
435
- readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>; /**
436
- * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
437
- */
435
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
438
436
  readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
439
437
  readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
440
438
  }, undefined>, undefined>;
441
439
  readonly network: v.ObjectSchema<{
442
440
  readonly bitcoin: v.ObjectSchema<{
443
- readonly name: v.EnumSchema<typeof BitcoinNetworkType, undefined>; /**
444
- * The purposes for which to generate addresses. See
445
- * {@linkcode AddressPurpose} for available purposes.
446
- */
441
+ readonly name: v.EnumSchema<typeof BitcoinNetworkType, undefined>;
447
442
  }, undefined>;
448
443
  readonly stacks: v.ObjectSchema<{
449
444
  readonly name: v.StringSchema<undefined>;
@@ -633,9 +628,7 @@ declare const getAccountsResultSchema: v.ArraySchema<v.ObjectSchema<{
633
628
  readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
634
629
  readonly address: v.StringSchema<undefined>;
635
630
  readonly publicKey: v.StringSchema<undefined>;
636
- readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>; /**
637
- * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
638
- */
631
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
639
632
  readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
640
633
  }, undefined>, undefined>;
641
634
  type GetAccountsResult = v.InferOutput<typeof getAccountsResultSchema>;
@@ -1970,8 +1963,24 @@ type Requests = BtcRequests & StxRequests & RunesRequests & WalletRequests & Ord
1970
1963
  type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
1971
1964
  type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
1972
1965
 
1973
- declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletRequests | keyof OrdinalsRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
1974
- declare const addListener: (listenerInfo: ListenerInfo, providerId?: string) => ReturnType<AddListener>;
1966
+ declare const request: <Method extends keyof Requests>(method: Method, params: Params<Method>,
1967
+ /**
1968
+ * The providerId is the object path to the provider in the window object.
1969
+ * E.g., a provider available at `window.Foo.BarProvider` would have a
1970
+ * providerId of `Foo.BarProvider`.
1971
+ */
1972
+ providerId?: string) => Promise<RpcResult<Method>>;
1973
+ /**
1974
+ * Adds an event listener.
1975
+ *
1976
+ * Currently expects 2 arguments, although is also capable of handling legacy
1977
+ * calls with 3 arguments consisting of:
1978
+ *
1979
+ * - event name (string)
1980
+ * - callback (function)
1981
+ * - provider ID (optional string)
1982
+ */
1983
+ declare const addListener: (...rawArgs: unknown[]) => ReturnType<AddListener>;
1975
1984
 
1976
1985
  declare abstract class SatsConnectAdapter {
1977
1986
  abstract readonly id: string;
@@ -1990,7 +1999,7 @@ declare abstract class SatsConnectAdapter {
1990
1999
  declare class BaseAdapter extends SatsConnectAdapter {
1991
2000
  id: string;
1992
2001
  constructor(providerId: string);
1993
- requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletRequests | keyof OrdinalsRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
2002
+ requestInternal: <Method extends keyof Requests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
1994
2003
  addListener: AddListener;
1995
2004
  }
1996
2005
 
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  AddressPurpose: () => AddressPurpose,
34
34
  AddressType: () => AddressType,
35
35
  BaseAdapter: () => BaseAdapter,
@@ -213,7 +213,7 @@ __export(src_exports, {
213
213
  walletTypeSchema: () => walletTypeSchema,
214
214
  walletTypes: () => walletTypes
215
215
  });
216
- module.exports = __toCommonJS(src_exports);
216
+ module.exports = __toCommonJS(index_exports);
217
217
 
218
218
  // src/provider/types.ts
219
219
  var v4 = __toESM(require("valibot"));
@@ -1414,7 +1414,37 @@ var request = async (method, params, providerId) => {
1414
1414
  }
1415
1415
  };
1416
1416
  };
1417
- var addListener = (listenerInfo, providerId) => {
1417
+ var addListener = (...rawArgs) => {
1418
+ const [listenerInfo, providerId] = (() => {
1419
+ if (rawArgs.length === 1) {
1420
+ return [rawArgs[0], void 0];
1421
+ }
1422
+ if (rawArgs.length === 2) {
1423
+ if (typeof rawArgs[1] === "function") {
1424
+ return [
1425
+ {
1426
+ eventName: rawArgs[0],
1427
+ cb: rawArgs[1]
1428
+ },
1429
+ void 0
1430
+ ];
1431
+ } else {
1432
+ return rawArgs;
1433
+ }
1434
+ }
1435
+ if (rawArgs.length === 3) {
1436
+ return [
1437
+ {
1438
+ eventName: rawArgs[0],
1439
+ cb: rawArgs[1]
1440
+ },
1441
+ rawArgs[2]
1442
+ ];
1443
+ }
1444
+ throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
1445
+ cause: rawArgs
1446
+ });
1447
+ })();
1418
1448
  let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1419
1449
  if (providerId) {
1420
1450
  provider = getProviderById(providerId);
package/dist/index.mjs CHANGED
@@ -1197,7 +1197,37 @@ var request = async (method, params, providerId) => {
1197
1197
  }
1198
1198
  };
1199
1199
  };
1200
- var addListener = (listenerInfo, providerId) => {
1200
+ var addListener = (...rawArgs) => {
1201
+ const [listenerInfo, providerId] = (() => {
1202
+ if (rawArgs.length === 1) {
1203
+ return [rawArgs[0], void 0];
1204
+ }
1205
+ if (rawArgs.length === 2) {
1206
+ if (typeof rawArgs[1] === "function") {
1207
+ return [
1208
+ {
1209
+ eventName: rawArgs[0],
1210
+ cb: rawArgs[1]
1211
+ },
1212
+ void 0
1213
+ ];
1214
+ } else {
1215
+ return rawArgs;
1216
+ }
1217
+ }
1218
+ if (rawArgs.length === 3) {
1219
+ return [
1220
+ {
1221
+ eventName: rawArgs[0],
1222
+ cb: rawArgs[1]
1223
+ },
1224
+ rawArgs[2]
1225
+ ];
1226
+ }
1227
+ throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
1228
+ cause: rawArgs
1229
+ });
1230
+ })();
1201
1231
  let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1202
1232
  if (providerId) {
1203
1233
  provider = getProviderById(providerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "main": "dist/index.mjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -8,7 +8,6 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "test": "jest",
12
11
  "build": "tsup",
13
12
  "build:watch": "tsup --watch",
14
13
  "check-types": "tsc --noEmit",
@@ -27,22 +26,20 @@
27
26
  },
28
27
  "dependencies": {
29
28
  "axios": "1.11.0",
30
- "bitcoin-address-validation": "2.2.3",
29
+ "bitcoin-address-validation": "3.0.0",
31
30
  "buffer": "6.0.3",
32
31
  "jsontokens": "4.0.1"
33
32
  },
34
33
  "devDependencies": {
35
- "@types/jest": "29.5.14",
36
- "husky": "8.0.3",
37
- "lint-staged": "13.3.0",
38
- "prettier": "3.3.3",
34
+ "husky": "9.1.7",
35
+ "lint-staged": "16.1.5",
36
+ "prettier": "3.6.2",
39
37
  "process": "0.11.10",
40
- "rimraf": "3.0.2",
38
+ "rimraf": "6.0.1",
41
39
  "stream-browserify": "3.0.0",
42
- "ts-jest": "29.2.5",
43
- "ts-loader": "9.5.1",
44
- "tsup": "8.3.0",
45
- "typescript": "5.4.5",
40
+ "ts-loader": "9.5.4",
41
+ "tsup": "8.5.0",
42
+ "typescript": "5.9.2",
46
43
  "util": "0.12.5",
47
44
  "vm-browserify": "1.1.2"
48
45
  },