@sats-connect/core 0.0.11-760c033 → 0.0.11-799c3e5

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,3 +1,5 @@
1
+ import * as v from 'valibot';
2
+
1
3
  interface GetCapabilitiesPayload extends RequestPayload {
2
4
  }
3
5
  type GetCapabilitiesResponse = Capability[];
@@ -157,7 +159,15 @@ interface RequestOptions<Payload extends RequestPayload, Response> {
157
159
  payload: Payload;
158
160
  getProvider?: () => Promise<BitcoinProvider | undefined>;
159
161
  }
160
- type RpcId = string | null;
162
+ declare const RpcIdSchema: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
163
+ type RpcId = v.InferOutput<typeof RpcIdSchema>;
164
+ declare const rpcRequestMessageSchema: v.ObjectSchema<{
165
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
166
+ readonly method: v.StringSchema<undefined>;
167
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, never>;
168
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
169
+ }, undefined>;
170
+ type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
161
171
  interface RpcBase {
162
172
  jsonrpc: '2.0';
163
173
  id: RpcId;
@@ -204,8 +214,31 @@ declare enum RpcErrorCode {
204
214
  /**
205
215
  * method is not supported for the address provided
206
216
  */
207
- METHOD_NOT_SUPPORTED = -32001
208
- }
217
+ METHOD_NOT_SUPPORTED = -32001,
218
+ /**
219
+ * The client does not have permission to access the requested resource.
220
+ */
221
+ ACCESS_DENIED = -32002
222
+ }
223
+ declare const rpcSuccessResponseMessageSchema: v.ObjectSchema<{
224
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
225
+ readonly result: v.UnknownSchema;
226
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
227
+ }, undefined>;
228
+ declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
229
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
230
+ readonly error: v.UnknownSchema;
231
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
232
+ }, undefined>;
233
+ declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
234
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
235
+ readonly result: v.UnknownSchema;
236
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
237
+ }, undefined>, v.ObjectSchema<{
238
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
239
+ readonly error: v.UnknownSchema;
240
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
241
+ }, undefined>], undefined>;
209
242
  interface RpcError {
210
243
  code: number | RpcErrorCode;
211
244
  message: string;
@@ -243,12 +276,13 @@ declare enum AddressType {
243
276
  p2tr = "p2tr",
244
277
  stacks = "stacks"
245
278
  }
246
- interface Address$1 {
247
- address: string;
248
- publicKey: string;
249
- purpose?: AddressPurpose;
250
- addressType?: AddressType;
251
- }
279
+ declare const addressSchema: v.ObjectSchema<{
280
+ readonly address: v.StringSchema<undefined>;
281
+ readonly publicKey: v.StringSchema<undefined>;
282
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
283
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
284
+ }, undefined>;
285
+ type Address$1 = v.InferOutput<typeof addressSchema>;
252
286
  interface GetAddressResponse {
253
287
  addresses: Address$1[];
254
288
  }
@@ -256,59 +290,110 @@ type GetAddressOptions = RequestOptions<GetAddressPayload, GetAddressResponse>;
256
290
 
257
291
  declare const getAddress: (options: GetAddressOptions) => Promise<void>;
258
292
 
259
- /**
260
- * Represents the types and interfaces related to BTC methods.
261
- */
262
-
263
- type GetInfoResult = {
264
- version: number | string;
265
- methods?: Array<string>;
266
- supports?: Array<string>;
267
- };
268
- type GetInfo = MethodParamsAndResult<null, GetInfoResult>;
269
- type GetAddressesParams$1 = {
270
- /**
271
- * The purposes for which to generate addresses.
272
- * possible values are "payment", "ordinals", ...
273
- */
274
- purposes: Array<AddressPurpose>;
275
- /**
276
- * a message to be displayed to the user in the request prompt.
277
- */
278
- message?: string;
279
- };
280
- /**
281
- * The addresses generated for the given purposes.
282
- */
283
- type GetAddressesResult$1 = {
284
- addresses: Array<Address$1>;
285
- };
286
- type GetAddresses = MethodParamsAndResult<GetAddressesParams$1, GetAddressesResult$1>;
287
- type SignMessageParams = {
293
+ declare const getInfoMethodName = "getInfo";
294
+ declare const getInfoParamsSchema: v.NullSchema<undefined>;
295
+ declare const getInfoResultSchema: v.ObjectSchema<{
296
+ /**
297
+ * Version of the wallet.
298
+ */
299
+ readonly version: v.StringSchema<undefined>;
300
+ /**
301
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
302
+ */
303
+ readonly methods: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
304
+ /**
305
+ * List of WBIP standards supported by the wallet. Not currently used.
306
+ */
307
+ readonly supports: v.ArraySchema<v.StringSchema<undefined>, undefined>;
308
+ }, undefined>;
309
+ declare const getInfoSchema: v.ObjectSchema<{
310
+ readonly method: v.LiteralSchema<"getInfo", undefined>;
311
+ readonly params: v.NullSchema<undefined>;
312
+ readonly id: v.StringSchema<undefined>;
313
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
314
+ }, undefined>;
315
+ type GetInfo = MethodParamsAndResult<v.InferOutput<typeof getInfoParamsSchema>, v.InferOutput<typeof getInfoResultSchema>>;
316
+ declare const getAddressesMethodName = "getAddresses";
317
+ declare const getAddressesParamsSchema: v.ObjectSchema<{
318
+ /**
319
+ * The purposes for which to generate addresses. See
320
+ * {@linkcode AddressPurpose} for available purposes.
321
+ */
322
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
323
+ /**
324
+ * A message to be displayed to the user in the request prompt.
325
+ */
326
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
327
+ }, undefined>;
328
+ declare const getAddressesResultSchema: v.ObjectSchema<{
329
+ /**
330
+ * The addresses generated for the given purposes.
331
+ */
332
+ readonly addresses: v.ArraySchema<v.ObjectSchema<{
333
+ readonly address: v.StringSchema<undefined>;
334
+ readonly publicKey: v.StringSchema<undefined>;
335
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
336
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
337
+ }, undefined>, undefined>;
338
+ }, undefined>;
339
+ declare const getAddressesRequestMessageSchema: v.ObjectSchema<{
340
+ readonly method: v.LiteralSchema<"getAddresses", undefined>;
341
+ readonly params: v.ObjectSchema<{
342
+ /**
343
+ * The purposes for which to generate addresses. See
344
+ * {@linkcode AddressPurpose} for available purposes.
345
+ */
346
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
347
+ /**
348
+ * A message to be displayed to the user in the request prompt.
349
+ */
350
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
351
+ }, undefined>;
352
+ readonly id: v.StringSchema<undefined>;
353
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
354
+ }, undefined>;
355
+ type GetAddresses = MethodParamsAndResult<v.InferOutput<typeof getAddressesParamsSchema>, v.InferOutput<typeof getAddressesResultSchema>>;
356
+ declare const signMessageMethodName = "signMessage";
357
+ declare const signMessageParamsSchema: v.ObjectSchema<{
288
358
  /**
289
359
  * The address used for signing.
290
360
  **/
291
- address: string;
361
+ readonly address: v.StringSchema<undefined>;
292
362
  /**
293
363
  * The message to sign.
294
364
  **/
295
- message: string;
296
- };
297
- type SignMessageResult = {
365
+ readonly message: v.StringSchema<undefined>;
366
+ }, undefined>;
367
+ declare const signMessageResultSchema: v.ObjectSchema<{
298
368
  /**
299
369
  * The signature of the message.
300
370
  */
301
- signature: string;
371
+ readonly signature: v.StringSchema<undefined>;
302
372
  /**
303
373
  * hash of the message.
304
374
  */
305
- messageHash: string;
375
+ readonly messageHash: v.StringSchema<undefined>;
306
376
  /**
307
377
  * The address used for signing.
308
378
  */
309
- address: string;
310
- };
311
- type SignMessage = MethodParamsAndResult<SignMessageParams, SignMessageResult>;
379
+ readonly address: v.StringSchema<undefined>;
380
+ }, undefined>;
381
+ declare const signMessageRequestMessageSchema: v.ObjectSchema<{
382
+ readonly method: v.LiteralSchema<"signMessage", undefined>;
383
+ readonly params: v.ObjectSchema<{
384
+ /**
385
+ * The address used for signing.
386
+ **/
387
+ readonly address: v.StringSchema<undefined>;
388
+ /**
389
+ * The message to sign.
390
+ **/
391
+ readonly message: v.StringSchema<undefined>;
392
+ }, undefined>;
393
+ readonly id: v.StringSchema<undefined>;
394
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
395
+ }, undefined>;
396
+ type SignMessage = MethodParamsAndResult<v.InferOutput<typeof signMessageParamsSchema>, v.InferOutput<typeof signMessageResultSchema>>;
312
397
  type Recipient$1 = {
313
398
  /**
314
399
  * The recipient's address.
@@ -365,22 +450,57 @@ type SignPsbtResult = {
365
450
  txid?: string;
366
451
  };
367
452
  type SignPsbt = MethodParamsAndResult<SignPsbtParams, SignPsbtResult>;
368
- type GetAccountsParams = {
369
- /**
370
- * The purposes for which to generate addresses.
371
- * possible values are "payment", "ordinals", ...
372
- */
373
- purposes: Array<AddressPurpose>;
374
- /**
375
- * a message to be displayed to the user in the request prompt.
376
- */
377
- /**
378
- * a message to be displayed to the user in the request prompt.
379
- */
380
- message?: string;
381
- };
382
- type GetAccountResult = Address$1[];
383
- type GetAccounts = MethodParamsAndResult<GetAccountsParams, GetAccountResult>;
453
+ declare const getAccountsMethodName = "getAccounts";
454
+ declare const getAccountsParamsSchema: v.ObjectSchema<{
455
+ /**
456
+ * The purposes for which to generate addresses. See
457
+ * {@linkcode AddressPurpose} for available purposes.
458
+ */
459
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
460
+ /**
461
+ * A message to be displayed to the user in the request prompt.
462
+ */
463
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
464
+ }, undefined>;
465
+ declare const getAccountsResultSchema: v.ArraySchema<v.ObjectSchema<{
466
+ readonly address: v.StringSchema<undefined>;
467
+ readonly publicKey: v.StringSchema<undefined>;
468
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
469
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
470
+ }, undefined>, undefined>;
471
+ declare const getAccountsRequestMessageSchema: v.ObjectSchema<{
472
+ readonly method: v.LiteralSchema<"getAccounts", undefined>;
473
+ readonly params: v.ObjectSchema<{
474
+ /**
475
+ * The purposes for which to generate addresses. See
476
+ * {@linkcode AddressPurpose} for available purposes.
477
+ */
478
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
479
+ /**
480
+ * A message to be displayed to the user in the request prompt.
481
+ */
482
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
483
+ }, undefined>;
484
+ readonly id: v.StringSchema<undefined>;
485
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
486
+ }, undefined>;
487
+ type GetAccounts = MethodParamsAndResult<v.InferOutput<typeof getAccountsParamsSchema>, v.InferOutput<typeof getAccountsResultSchema>>;
488
+ declare const getBalanceMethodName = "getBalance";
489
+ declare const getBalanceParamsSchema: v.UndefinedSchema<undefined>;
490
+ declare const getBalanceResultSchema: v.ObjectSchema<{
491
+ /**
492
+ * The balance of the wallet in sats.
493
+ */
494
+ readonly confirmedBalance: v.BigintSchema<undefined>;
495
+ readonly unconfirmedUtxosBalance: v.BigintSchema<undefined>;
496
+ }, undefined>;
497
+ declare const getBalanceSchema: v.ObjectSchema<{
498
+ readonly method: v.LiteralSchema<"getBalance", undefined>;
499
+ readonly id: v.StringSchema<undefined>;
500
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
501
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, never>;
502
+ }, undefined>;
503
+ type GetBalance = MethodParamsAndResult<v.InferOutput<typeof getBalanceParamsSchema>, v.InferOutput<typeof getBalanceResultSchema>>;
384
504
 
385
505
  type CreateMintOrderRequest = {
386
506
  runeName: string;
@@ -685,6 +805,27 @@ type SignTransactionParams = Transaction & Partial<Pubkey>;
685
805
  type SignTransactionResult = Transaction;
686
806
  type StxSignTransaction = MethodParamsAndResult<SignTransactionParams, SignTransactionResult>;
687
807
 
808
+ declare const connectMethodName = "wallet_connect";
809
+ declare const connectParamsSchema: v.UndefinedSchema<undefined>;
810
+ declare const connectResultSchema: v.UndefinedSchema<undefined>;
811
+ declare const connectSchema: v.ObjectSchema<{
812
+ readonly method: v.LiteralSchema<"wallet_connect", undefined>;
813
+ readonly params: v.UndefinedSchema<undefined>;
814
+ readonly id: v.StringSchema<undefined>;
815
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
816
+ }, undefined>;
817
+ type Connect = MethodParamsAndResult<v.InferOutput<typeof connectParamsSchema>, v.InferOutput<typeof connectResultSchema>>;
818
+ declare const disconnectMethodName = "wallet_disconnect";
819
+ declare const disconnectParamsSchema: v.UndefinedSchema<undefined>;
820
+ declare const disconnectResultSchema: v.UndefinedSchema<undefined>;
821
+ declare const disconnectSchema: v.ObjectSchema<{
822
+ readonly method: v.LiteralSchema<"wallet_disconnect", undefined>;
823
+ readonly params: v.UndefinedSchema<undefined>;
824
+ readonly id: v.StringSchema<undefined>;
825
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
826
+ }, undefined>;
827
+ type Disconnect = MethodParamsAndResult<v.InferOutput<typeof disconnectParamsSchema>, v.InferOutput<typeof disconnectResultSchema>>;
828
+
688
829
  interface StxRequests {
689
830
  stx_callContract: StxCallContract;
690
831
  stx_deployContract: StxDeployContract;
@@ -700,6 +841,7 @@ interface BtcRequests {
700
841
  getInfo: GetInfo;
701
842
  getAddresses: GetAddresses;
702
843
  getAccounts: GetAccounts;
844
+ getBalance: GetBalance;
703
845
  signMessage: SignMessage;
704
846
  sendTransfer: SendTransfer;
705
847
  signPsbt: SignPsbt;
@@ -716,11 +858,15 @@ interface RunesRequests {
716
858
  runes_getBalance: GetRunesBalance;
717
859
  }
718
860
  type RunesRequestMethod = keyof RunesRequests;
719
- type Requests = BtcRequests & StxRequests & RunesRequests;
861
+ interface WalletMethods {
862
+ wallet_connect: Connect;
863
+ wallet_disconnect: Disconnect;
864
+ }
865
+ type Requests = BtcRequests & StxRequests & RunesRequests & WalletMethods;
720
866
  type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
721
867
  type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
722
868
 
723
- declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
869
+ declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
724
870
 
725
871
  declare abstract class SatsConnectAdapter {
726
872
  abstract readonly id: string;
@@ -738,10 +884,10 @@ declare abstract class SatsConnectAdapter {
738
884
  declare class BaseAdapter extends SatsConnectAdapter {
739
885
  id: string;
740
886
  constructor(providerId: string);
741
- requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
887
+ requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
742
888
  }
743
889
 
744
890
  declare const DefaultAdaptersInfo: Record<string, Provider>;
745
891
  declare const defaultAdapters: Record<string, new () => SatsConnectAdapter>;
746
892
 
747
- export { type Address$1 as Address, AddressPurpose, AddressType, BaseAdapter, type BitcoinNetwork, BitcoinNetworkType, type BitcoinProvider, type BtcRequestMethod, type BtcRequests, type CallContractParams, type CallContractResult, type Capability, type CreateInscriptionOptions, type CreateInscriptionPayload, type CreateInscriptionResponse, type CreateRepeatInscriptionsOptions, type CreateRepeatInscriptionsPayload, type CreateRepeatInscriptionsResponse, DefaultAdaptersInfo, type DeployContractParams, type DeployContractResult, type GetAccountResult, type GetAccounts, type GetAccountsParams, type GetAccountsResult, type GetAddressOptions, type GetAddressPayload, type GetAddressResponse, type GetAddresses, type GetAddressesParams, type GetAddressesResult, type GetCapabilitiesOptions, type GetCapabilitiesPayload, type GetCapabilitiesResponse, type GetInfo, type InputToSign, type MethodParamsAndResult, type Params, type Provider, type PsbtPayload, type Recipient$2 as Recipient, type RequestOptions, type RequestPayload, type Requests, type Return, type RpcBase, type RpcError, RpcErrorCode, type RpcErrorResponse, type RpcId, type RpcRequest, type RpcResponse, type RpcResult, type RpcSuccessResponse, type RunesRequestMethod, type RunesRequests, SatsConnectAdapter, type SendBtcTransactionOptions, type SendBtcTransactionPayload, type SendBtcTransactionResponse, type SendTransfer, type SendTransferParams, type SerializedRecipient, type SerializedSendBtcTransactionPayload, type SignMessage, type SignMessageOptions, type SignMessageParams, type SignMessagePayload, type SignMessageResponse, type SignMultiplePsbtPayload, type SignMultipleTransactionOptions, type SignMultipleTransactionsPayload, type SignMultipleTransactionsResponse, type SignPsbt, type SignPsbtParams, type SignPsbtResult, type SignStructuredMessageResult, type SignStxMessageParams, type SignStxMessageResult, type SignTransactionOptions, type SignTransactionParams, type SignTransactionPayload, type SignTransactionResponse, type SignTransactionResult, type StxCallContract, type StxDeployContract, type StxGetAccounts, type StxGetAddresses, type StxRequestMethod, type StxRequests, type StxSignStructuredMessage, type StxSignStxMessage, type StxSignTransaction, type StxTransferStx, type SupportedWallet, type TransferStxParams, type TransferStxResult, createInscription, createRepeatInscriptions, defaultAdapters, getAddress, getCapabilities, getDefaultProvider, getProviderById, getProviderOrThrow, getProviders, getSupportedWallets, isProviderInstalled, removeDefaultProvider, request, sendBtcTransaction, setDefaultProvider, signMessage, signMultipleTransactions, signTransaction };
893
+ export { type Address$1 as Address, AddressPurpose, AddressType, BaseAdapter, type BitcoinNetwork, BitcoinNetworkType, type BitcoinProvider, type BtcRequestMethod, type BtcRequests, type CallContractParams, type CallContractResult, type Capability, type Connect, type CreateInscriptionOptions, type CreateInscriptionPayload, type CreateInscriptionResponse, type CreateRepeatInscriptionsOptions, type CreateRepeatInscriptionsPayload, type CreateRepeatInscriptionsResponse, DefaultAdaptersInfo, type DeployContractParams, type DeployContractResult, type Disconnect, type GetAccounts, type GetAccountsResult, type GetAddressOptions, type GetAddressPayload, type GetAddressResponse, type GetAddresses, type GetAddressesParams, type GetAddressesResult, type GetBalance, type GetCapabilitiesOptions, type GetCapabilitiesPayload, type GetCapabilitiesResponse, type GetInfo, type InputToSign, type MethodParamsAndResult, type Params, type Provider, type PsbtPayload, type Recipient$2 as Recipient, type RequestOptions, type RequestPayload, type Requests, type Return, type RpcBase, type RpcError, RpcErrorCode, type RpcErrorResponse, type RpcId, RpcIdSchema, type RpcRequest, type RpcRequestMessage, type RpcResponse, type RpcResult, type RpcSuccessResponse, type RunesRequestMethod, type RunesRequests, SatsConnectAdapter, type SendBtcTransactionOptions, type SendBtcTransactionPayload, type SendBtcTransactionResponse, type SendTransfer, type SendTransferParams, type SerializedRecipient, type SerializedSendBtcTransactionPayload, type SignMessage, type SignMessageOptions, type SignMessagePayload, type SignMessageResponse, type SignMultiplePsbtPayload, type SignMultipleTransactionOptions, type SignMultipleTransactionsPayload, type SignMultipleTransactionsResponse, type SignPsbt, type SignPsbtParams, type SignPsbtResult, type SignStructuredMessageResult, type SignStxMessageParams, type SignStxMessageResult, type SignTransactionOptions, type SignTransactionParams, type SignTransactionPayload, type SignTransactionResponse, type SignTransactionResult, type StxCallContract, type StxDeployContract, type StxGetAccounts, type StxGetAddresses, type StxRequestMethod, type StxRequests, type StxSignStructuredMessage, type StxSignStxMessage, type StxSignTransaction, type StxTransferStx, type SupportedWallet, type TransferStxParams, type TransferStxResult, type WalletMethods, addressSchema, connectMethodName, connectParamsSchema, connectResultSchema, connectSchema, createInscription, createRepeatInscriptions, defaultAdapters, disconnectMethodName, disconnectParamsSchema, disconnectResultSchema, disconnectSchema, getAccountsMethodName, getAccountsParamsSchema, getAccountsRequestMessageSchema, getAccountsResultSchema, getAddress, getAddressesMethodName, getAddressesParamsSchema, getAddressesRequestMessageSchema, getAddressesResultSchema, getBalanceMethodName, getBalanceParamsSchema, getBalanceResultSchema, getBalanceSchema, getCapabilities, getDefaultProvider, getInfoMethodName, getInfoParamsSchema, getInfoResultSchema, getInfoSchema, getProviderById, getProviderOrThrow, getProviders, getSupportedWallets, isProviderInstalled, removeDefaultProvider, request, rpcErrorResponseMessageSchema, rpcRequestMessageSchema, rpcResponseMessageSchema, rpcSuccessResponseMessageSchema, sendBtcTransaction, setDefaultProvider, signMessage, signMessageMethodName, signMessageParamsSchema, signMessageRequestMessageSchema, signMessageResultSchema, signMultipleTransactions, signTransaction };
package/dist/index.mjs CHANGED
@@ -1,10 +1,28 @@
1
1
  // src/types.ts
2
+ import * as v from "valibot";
2
3
  var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
3
4
  BitcoinNetworkType2["Mainnet"] = "Mainnet";
4
5
  BitcoinNetworkType2["Testnet"] = "Testnet";
5
6
  BitcoinNetworkType2["Signet"] = "Signet";
6
7
  return BitcoinNetworkType2;
7
8
  })(BitcoinNetworkType || {});
9
+ var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
10
+ var rpcRequestMessageSchema = v.object({
11
+ jsonrpc: v.literal("2.0"),
12
+ method: v.string(),
13
+ params: v.optional(
14
+ v.union([
15
+ v.array(v.unknown()),
16
+ v.looseObject({}),
17
+ // Note: This is to support current incorrect usage of RPC 2.0. Params need
18
+ // to be either an array or an object when provided. Changing this now would
19
+ // be a breaking change, so accepting null values for now. Tracking in
20
+ // https://linear.app/xverseapp/issue/ENG-4538.
21
+ v.null()
22
+ ])
23
+ ),
24
+ id: RpcIdSchema
25
+ });
8
26
  var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
9
27
  RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
10
28
  RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
@@ -13,8 +31,23 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
13
31
  RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
14
32
  RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
15
33
  RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
34
+ RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
16
35
  return RpcErrorCode2;
17
36
  })(RpcErrorCode || {});
37
+ var rpcSuccessResponseMessageSchema = v.object({
38
+ jsonrpc: v.literal("2.0"),
39
+ result: v.unknown(),
40
+ id: RpcIdSchema
41
+ });
42
+ var rpcErrorResponseMessageSchema = v.object({
43
+ jsonrpc: v.literal("2.0"),
44
+ error: v.unknown(),
45
+ id: RpcIdSchema
46
+ });
47
+ var rpcResponseMessageSchema = v.union([
48
+ rpcSuccessResponseMessageSchema,
49
+ rpcErrorResponseMessageSchema
50
+ ]);
18
51
 
19
52
  // src/runes/api.ts
20
53
  import axios from "axios";
@@ -169,16 +202,6 @@ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
169
202
  var SatsConnectAdapter = class {
170
203
  async mintRunes(params) {
171
204
  try {
172
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
173
- if (walletInfo && walletInfo.status === "success") {
174
- const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
175
- if (isMintSupported) {
176
- const response = await this.requestInternal("runes_mint", params);
177
- if (response) {
178
- return response;
179
- }
180
- }
181
- }
182
205
  const mintRequest = {
183
206
  destinationAddress: params.destinationAddress,
184
207
  feeRate: params.feeRate,
@@ -248,16 +271,6 @@ var SatsConnectAdapter = class {
248
271
  appServiceFeeAddress: params.appServiceFeeAddress
249
272
  };
250
273
  try {
251
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
252
- if (walletInfo && walletInfo.status === "success") {
253
- const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
254
- if (isEtchSupported) {
255
- const response = await this.requestInternal("runes_etch", params);
256
- if (response) {
257
- return response;
258
- }
259
- }
260
- }
261
274
  const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
262
275
  if (!orderResponse.data) {
263
276
  return {
@@ -513,49 +526,13 @@ function getSupportedWallets() {
513
526
  }
514
527
 
515
528
  // src/request/index.ts
516
- var request = async (method, params, providerId) => {
517
- let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
518
- if (providerId) {
519
- provider = await getProviderById(providerId);
520
- }
521
- if (!provider) {
522
- throw new Error("no wallet provider was found");
523
- }
524
- if (!method) {
525
- throw new Error("A wallet method is required");
526
- }
527
- const response = await provider.request(method, params);
528
- if (isRpcSuccessResponse(response)) {
529
- return {
530
- status: "success",
531
- result: response.result
532
- };
533
- }
534
- return {
535
- status: "error",
536
- error: response.error
537
- };
538
- };
539
- var isRpcSuccessResponse = (response) => {
540
- return Object.hasOwn(response, "result") && !!response.result;
541
- };
542
-
543
- // src/adapters/xverse.ts
544
- var XverseAdapter = class extends SatsConnectAdapter {
545
- id = DefaultAdaptersInfo.xverse.id;
546
- requestInternal = async (method, params) => {
547
- return request(method, params, this.id);
548
- };
549
- };
550
-
551
- // src/adapters/unisat.ts
552
- import { Buffer } from "buffer";
553
- import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
529
+ import * as v5 from "valibot";
554
530
 
555
531
  // src/addresses/index.ts
556
532
  import { createUnsecuredToken } from "jsontokens";
557
533
 
558
534
  // src/addresses/types.ts
535
+ import * as v2 from "valibot";
559
536
  var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
560
537
  AddressPurpose2["Ordinals"] = "ordinals";
561
538
  AddressPurpose2["Payment"] = "payment";
@@ -571,6 +548,12 @@ var AddressType = /* @__PURE__ */ ((AddressType3) => {
571
548
  AddressType3["stacks"] = "stacks";
572
549
  return AddressType3;
573
550
  })(AddressType || {});
551
+ var addressSchema = v2.object({
552
+ address: v2.string(),
553
+ publicKey: v2.string(),
554
+ purpose: v2.enum(AddressPurpose),
555
+ addressType: v2.enum(AddressType)
556
+ });
574
557
 
575
558
  // src/addresses/index.ts
576
559
  var getAddress = async (options) => {
@@ -589,7 +572,192 @@ var getAddress = async (options) => {
589
572
  }
590
573
  };
591
574
 
575
+ // src/request/types/btcMethods.ts
576
+ import * as v3 from "valibot";
577
+ var getInfoMethodName = "getInfo";
578
+ var getInfoParamsSchema = v3.null();
579
+ var getInfoResultSchema = v3.object({
580
+ /**
581
+ * Version of the wallet.
582
+ */
583
+ version: v3.string(),
584
+ /**
585
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
586
+ */
587
+ methods: v3.optional(v3.array(v3.string())),
588
+ /**
589
+ * List of WBIP standards supported by the wallet. Not currently used.
590
+ */
591
+ supports: v3.array(v3.string())
592
+ });
593
+ var getInfoSchema = v3.object({
594
+ ...rpcRequestMessageSchema.entries,
595
+ ...v3.object({
596
+ method: v3.literal(getInfoMethodName),
597
+ params: getInfoParamsSchema,
598
+ id: v3.string()
599
+ }).entries
600
+ });
601
+ var getAddressesMethodName = "getAddresses";
602
+ var getAddressesParamsSchema = v3.object({
603
+ /**
604
+ * The purposes for which to generate addresses. See
605
+ * {@linkcode AddressPurpose} for available purposes.
606
+ */
607
+ purposes: v3.array(v3.enum(AddressPurpose)),
608
+ /**
609
+ * A message to be displayed to the user in the request prompt.
610
+ */
611
+ message: v3.optional(v3.string())
612
+ });
613
+ var getAddressesResultSchema = v3.object({
614
+ /**
615
+ * The addresses generated for the given purposes.
616
+ */
617
+ addresses: v3.array(addressSchema)
618
+ });
619
+ var getAddressesRequestMessageSchema = v3.object({
620
+ ...rpcRequestMessageSchema.entries,
621
+ ...v3.object({
622
+ method: v3.literal(getAddressesMethodName),
623
+ params: getAddressesParamsSchema,
624
+ id: v3.string()
625
+ }).entries
626
+ });
627
+ var signMessageMethodName = "signMessage";
628
+ var signMessageParamsSchema = v3.object({
629
+ /**
630
+ * The address used for signing.
631
+ **/
632
+ address: v3.string(),
633
+ /**
634
+ * The message to sign.
635
+ **/
636
+ message: v3.string()
637
+ });
638
+ var signMessageResultSchema = v3.object({
639
+ /**
640
+ * The signature of the message.
641
+ */
642
+ signature: v3.string(),
643
+ /**
644
+ * hash of the message.
645
+ */
646
+ messageHash: v3.string(),
647
+ /**
648
+ * The address used for signing.
649
+ */
650
+ address: v3.string()
651
+ });
652
+ var signMessageRequestMessageSchema = v3.object({
653
+ ...rpcRequestMessageSchema.entries,
654
+ ...v3.object({
655
+ method: v3.literal(signMessageMethodName),
656
+ params: signMessageParamsSchema,
657
+ id: v3.string()
658
+ }).entries
659
+ });
660
+ var getAccountsMethodName = "getAccounts";
661
+ var getAccountsParamsSchema = getAddressesParamsSchema;
662
+ var getAccountsResultSchema = v3.array(addressSchema);
663
+ var getAccountsRequestMessageSchema = v3.object({
664
+ ...rpcRequestMessageSchema.entries,
665
+ ...v3.object({
666
+ method: v3.literal(getAccountsMethodName),
667
+ params: getAccountsParamsSchema,
668
+ id: v3.string()
669
+ }).entries
670
+ });
671
+ var getBalanceMethodName = "getBalance";
672
+ var getBalanceParamsSchema = v3.undefined();
673
+ var getBalanceResultSchema = v3.object({
674
+ /**
675
+ * The balance of the wallet in sats.
676
+ */
677
+ confirmedBalance: v3.bigint(),
678
+ unconfirmedUtxosBalance: v3.bigint()
679
+ });
680
+ var getBalanceSchema = v3.object({
681
+ ...rpcRequestMessageSchema.entries,
682
+ ...v3.object({
683
+ method: v3.literal(getBalanceMethodName),
684
+ id: v3.string()
685
+ }).entries
686
+ });
687
+
688
+ // src/request/types/walletMethods.ts
689
+ import * as v4 from "valibot";
690
+ var connectMethodName = "wallet_connect";
691
+ var connectParamsSchema = v4.undefined();
692
+ var connectResultSchema = v4.undefined();
693
+ var connectSchema = v4.object({
694
+ ...rpcRequestMessageSchema.entries,
695
+ ...v4.object({
696
+ method: v4.literal(connectMethodName),
697
+ params: connectParamsSchema,
698
+ id: v4.string()
699
+ }).entries
700
+ });
701
+ var disconnectMethodName = "wallet_disconnect";
702
+ var disconnectParamsSchema = v4.undefined();
703
+ var disconnectResultSchema = v4.undefined();
704
+ var disconnectSchema = v4.object({
705
+ ...rpcRequestMessageSchema.entries,
706
+ ...v4.object({
707
+ method: v4.literal(disconnectMethodName),
708
+ params: disconnectParamsSchema,
709
+ id: v4.string()
710
+ }).entries
711
+ });
712
+
713
+ // src/request/index.ts
714
+ var request = async (method, params, providerId) => {
715
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
716
+ if (providerId) {
717
+ provider = await getProviderById(providerId);
718
+ }
719
+ if (!provider) {
720
+ throw new Error("no wallet provider was found");
721
+ }
722
+ if (!method) {
723
+ throw new Error("A wallet method is required");
724
+ }
725
+ const response = await provider.request(method, params);
726
+ const parseResult = v5.safeParse(rpcResponseMessageSchema, response);
727
+ if (!parseResult.success) {
728
+ return {
729
+ status: "error",
730
+ error: {
731
+ code: -32603 /* INTERNAL_ERROR */,
732
+ message: "Received unknown response from provider.",
733
+ data: response
734
+ }
735
+ };
736
+ }
737
+ const parsedResponse = parseResult.output;
738
+ if ("error" in parsedResponse) {
739
+ return {
740
+ status: "error",
741
+ error: parsedResponse.error
742
+ };
743
+ }
744
+ return {
745
+ status: "success",
746
+ result: parsedResponse.result
747
+ };
748
+ };
749
+
750
+ // src/adapters/xverse.ts
751
+ var XverseAdapter = class extends SatsConnectAdapter {
752
+ id = DefaultAdaptersInfo.xverse.id;
753
+ requestInternal = async (method, params) => {
754
+ return request(method, params, this.id);
755
+ };
756
+ };
757
+
592
758
  // src/adapters/unisat.ts
759
+ import { Buffer } from "buffer";
760
+ import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
593
761
  function convertSignInputsToInputType(signInputs, allowedSignHash) {
594
762
  let result = [];
595
763
  for (let address in signInputs) {
@@ -993,13 +1161,39 @@ export {
993
1161
  BitcoinNetworkType,
994
1162
  DefaultAdaptersInfo,
995
1163
  RpcErrorCode,
1164
+ RpcIdSchema,
996
1165
  SatsConnectAdapter,
1166
+ addressSchema,
1167
+ connectMethodName,
1168
+ connectParamsSchema,
1169
+ connectResultSchema,
1170
+ connectSchema,
997
1171
  createInscription,
998
1172
  createRepeatInscriptions,
999
1173
  defaultAdapters,
1174
+ disconnectMethodName,
1175
+ disconnectParamsSchema,
1176
+ disconnectResultSchema,
1177
+ disconnectSchema,
1178
+ getAccountsMethodName,
1179
+ getAccountsParamsSchema,
1180
+ getAccountsRequestMessageSchema,
1181
+ getAccountsResultSchema,
1000
1182
  getAddress,
1183
+ getAddressesMethodName,
1184
+ getAddressesParamsSchema,
1185
+ getAddressesRequestMessageSchema,
1186
+ getAddressesResultSchema,
1187
+ getBalanceMethodName,
1188
+ getBalanceParamsSchema,
1189
+ getBalanceResultSchema,
1190
+ getBalanceSchema,
1001
1191
  getCapabilities,
1002
1192
  getDefaultProvider,
1193
+ getInfoMethodName,
1194
+ getInfoParamsSchema,
1195
+ getInfoResultSchema,
1196
+ getInfoSchema,
1003
1197
  getProviderById,
1004
1198
  getProviderOrThrow,
1005
1199
  getProviders,
@@ -1007,9 +1201,17 @@ export {
1007
1201
  isProviderInstalled,
1008
1202
  removeDefaultProvider,
1009
1203
  request,
1204
+ rpcErrorResponseMessageSchema,
1205
+ rpcRequestMessageSchema,
1206
+ rpcResponseMessageSchema,
1207
+ rpcSuccessResponseMessageSchema,
1010
1208
  sendBtcTransaction,
1011
1209
  setDefaultProvider,
1012
1210
  signMessage,
1211
+ signMessageMethodName,
1212
+ signMessageParamsSchema,
1213
+ signMessageRequestMessageSchema,
1214
+ signMessageResultSchema,
1013
1215
  signMultipleTransactions,
1014
1216
  signTransaction
1015
1217
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.11-760c033",
3
+ "version": "0.0.11-799c3e5",
4
4
  "main": "dist/index.mjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -11,6 +11,7 @@
11
11
  "test": "jest",
12
12
  "build-debug": "webpack --mode development",
13
13
  "build": "npm run clean && tsup src/index.ts --format esm --dts",
14
+ "build:watch": "npm run clean && tsup src/index.ts --format esm --dts --watch",
14
15
  "clean": "rimraf dist",
15
16
  "lint": "prettier --write .",
16
17
  "prepare": "husky install"
@@ -30,6 +31,9 @@
30
31
  "jsontokens": "4.0.1",
31
32
  "lodash.omit": "4.5.0"
32
33
  },
34
+ "peerDependencies": {
35
+ "valibot": "0.33.2"
36
+ },
33
37
  "devDependencies": {
34
38
  "@types/jest": "^29.2.6",
35
39
  "@types/lodash.omit": "4.5.9",
@@ -42,7 +46,7 @@
42
46
  "ts-jest": "^29.0.5",
43
47
  "ts-loader": "^9.4.1",
44
48
  "tsup": "^8.0.2",
45
- "typescript": "^4.9.4",
49
+ "typescript": "5.4.5",
46
50
  "util": "^0.12.4",
47
51
  "vm-browserify": "^1.1.2",
48
52
  "webpack": "^5.74.0",