@sats-connect/core 0.0.10 → 0.0.11-1501a20

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[];
@@ -141,7 +143,8 @@ declare function getSupportedWallets(): SupportedWallet[];
141
143
 
142
144
  declare enum BitcoinNetworkType {
143
145
  Mainnet = "Mainnet",
144
- Testnet = "Testnet"
146
+ Testnet = "Testnet",
147
+ Signet = "Signet"
145
148
  }
146
149
  interface BitcoinNetwork {
147
150
  type: BitcoinNetworkType;
@@ -156,6 +159,13 @@ interface RequestOptions<Payload extends RequestPayload, Response> {
156
159
  payload: Payload;
157
160
  getProvider?: () => Promise<BitcoinProvider | undefined>;
158
161
  }
162
+ declare const rpcRequestMessageSchema: v.ObjectSchema<{
163
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
164
+ readonly method: v.StringSchema<undefined>;
165
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, never>;
166
+ readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
167
+ }, undefined>;
168
+ type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
159
169
  type RpcId = string | null;
160
170
  interface RpcBase {
161
171
  jsonrpc: '2.0';
@@ -203,7 +213,11 @@ declare enum RpcErrorCode {
203
213
  /**
204
214
  * method is not supported for the address provided
205
215
  */
206
- METHOD_NOT_SUPPORTED = -32001
216
+ METHOD_NOT_SUPPORTED = -32001,
217
+ /**
218
+ * The client does not have permission to access the requested resource.
219
+ */
220
+ ACCESS_DENIED = -32002
207
221
  }
208
222
  interface RpcError {
209
223
  code: number | RpcErrorCode;
@@ -242,12 +256,13 @@ declare enum AddressType {
242
256
  p2tr = "p2tr",
243
257
  stacks = "stacks"
244
258
  }
245
- interface Address$1 {
246
- address: string;
247
- publicKey: string;
248
- purpose?: AddressPurpose;
249
- addressType?: AddressType;
250
- }
259
+ declare const addressSchema: v.ObjectSchema<{
260
+ readonly address: v.StringSchema<undefined>;
261
+ readonly publicKey: v.StringSchema<undefined>;
262
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
263
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
264
+ }, undefined>;
265
+ type Address$1 = v.InferOutput<typeof addressSchema>;
251
266
  interface GetAddressResponse {
252
267
  addresses: Address$1[];
253
268
  }
@@ -255,59 +270,110 @@ type GetAddressOptions = RequestOptions<GetAddressPayload, GetAddressResponse>;
255
270
 
256
271
  declare const getAddress: (options: GetAddressOptions) => Promise<void>;
257
272
 
258
- /**
259
- * Represents the types and interfaces related to BTC methods.
260
- */
261
-
262
- type GetInfoResult = {
263
- version: number | string;
264
- methods?: Array<string>;
265
- supports?: Array<string>;
266
- };
267
- type GetInfo = MethodParamsAndResult<null, GetInfoResult>;
268
- type GetAddressesParams$1 = {
269
- /**
270
- * The purposes for which to generate addresses.
271
- * possible values are "payment", "ordinals", ...
272
- */
273
- purposes: Array<AddressPurpose>;
274
- /**
275
- * a message to be displayed to the user in the request prompt.
276
- */
277
- message?: string;
278
- };
279
- /**
280
- * The addresses generated for the given purposes.
281
- */
282
- type GetAddressesResult$1 = {
283
- addresses: Array<Address$1>;
284
- };
285
- type GetAddresses = MethodParamsAndResult<GetAddressesParams$1, GetAddressesResult$1>;
286
- type SignMessageParams = {
273
+ declare const getInfoMethodName = "getInfo";
274
+ declare const getInfoParamsSchema: v.NullSchema<undefined>;
275
+ declare const getInfoResultSchema: v.ObjectSchema<{
276
+ /**
277
+ * Version of the wallet.
278
+ */
279
+ readonly version: v.StringSchema<undefined>;
280
+ /**
281
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
282
+ */
283
+ readonly methods: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
284
+ /**
285
+ * List of WBIP standards supported by the wallet. Not currently used.
286
+ */
287
+ readonly supports: v.ArraySchema<v.StringSchema<undefined>, undefined>;
288
+ }, undefined>;
289
+ declare const getInfoSchema: v.ObjectSchema<{
290
+ readonly method: v.LiteralSchema<"getInfo", undefined>;
291
+ readonly params: v.NullSchema<undefined>;
292
+ readonly id: v.StringSchema<undefined>;
293
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
294
+ }, undefined>;
295
+ type GetInfo = MethodParamsAndResult<v.InferOutput<typeof getInfoParamsSchema>, v.InferOutput<typeof getInfoResultSchema>>;
296
+ declare const getAddressesMethodName = "getAddresses";
297
+ declare const getAddressesParamsSchema: v.ObjectSchema<{
298
+ /**
299
+ * The purposes for which to generate addresses. See
300
+ * {@linkcode AddressPurpose} for available purposes.
301
+ */
302
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
303
+ /**
304
+ * A message to be displayed to the user in the request prompt.
305
+ */
306
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
307
+ }, undefined>;
308
+ declare const getAddressesResultSchema: v.ObjectSchema<{
309
+ /**
310
+ * The addresses generated for the given purposes.
311
+ */
312
+ readonly addresses: v.ArraySchema<v.ObjectSchema<{
313
+ readonly address: v.StringSchema<undefined>;
314
+ readonly publicKey: v.StringSchema<undefined>;
315
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
316
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
317
+ }, undefined>, undefined>;
318
+ }, undefined>;
319
+ declare const getAddressesRequestMessageSchema: v.ObjectSchema<{
320
+ readonly method: v.LiteralSchema<"getAddresses", undefined>;
321
+ readonly params: v.ObjectSchema<{
322
+ /**
323
+ * The purposes for which to generate addresses. See
324
+ * {@linkcode AddressPurpose} for available purposes.
325
+ */
326
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
327
+ /**
328
+ * A message to be displayed to the user in the request prompt.
329
+ */
330
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
331
+ }, undefined>;
332
+ readonly id: v.StringSchema<undefined>;
333
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
334
+ }, undefined>;
335
+ type GetAddresses = MethodParamsAndResult<v.InferOutput<typeof getAddressesParamsSchema>, v.InferOutput<typeof getAddressesResultSchema>>;
336
+ declare const signMessageMethodName = "signMessage";
337
+ declare const signMessageParamsSchema: v.ObjectSchema<{
287
338
  /**
288
339
  * The address used for signing.
289
340
  **/
290
- address: string;
341
+ readonly address: v.StringSchema<undefined>;
291
342
  /**
292
343
  * The message to sign.
293
344
  **/
294
- message: string;
295
- };
296
- type SignMessageResult = {
345
+ readonly message: v.StringSchema<undefined>;
346
+ }, undefined>;
347
+ declare const signMessageResultSchema: v.ObjectSchema<{
297
348
  /**
298
349
  * The signature of the message.
299
350
  */
300
- signature: string;
351
+ readonly signature: v.StringSchema<undefined>;
301
352
  /**
302
353
  * hash of the message.
303
354
  */
304
- messageHash: string;
355
+ readonly messageHash: v.StringSchema<undefined>;
305
356
  /**
306
357
  * The address used for signing.
307
358
  */
308
- address: string;
309
- };
310
- type SignMessage = MethodParamsAndResult<SignMessageParams, SignMessageResult>;
359
+ readonly address: v.StringSchema<undefined>;
360
+ }, undefined>;
361
+ declare const signMessageRequestMessageSchema: v.ObjectSchema<{
362
+ readonly method: v.LiteralSchema<"signMessage", undefined>;
363
+ readonly params: v.ObjectSchema<{
364
+ /**
365
+ * The address used for signing.
366
+ **/
367
+ readonly address: v.StringSchema<undefined>;
368
+ /**
369
+ * The message to sign.
370
+ **/
371
+ readonly message: v.StringSchema<undefined>;
372
+ }, undefined>;
373
+ readonly id: v.StringSchema<undefined>;
374
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
375
+ }, undefined>;
376
+ type SignMessage = MethodParamsAndResult<v.InferOutput<typeof signMessageParamsSchema>, v.InferOutput<typeof signMessageResultSchema>>;
311
377
  type Recipient$1 = {
312
378
  /**
313
379
  * The recipient's address.
@@ -364,22 +430,57 @@ type SignPsbtResult = {
364
430
  txid?: string;
365
431
  };
366
432
  type SignPsbt = MethodParamsAndResult<SignPsbtParams, SignPsbtResult>;
367
- type GetAccountsParams = {
368
- /**
369
- * The purposes for which to generate addresses.
370
- * possible values are "payment", "ordinals", ...
371
- */
372
- purposes: Array<AddressPurpose>;
373
- /**
374
- * a message to be displayed to the user in the request prompt.
375
- */
376
- /**
377
- * a message to be displayed to the user in the request prompt.
378
- */
379
- message?: string;
380
- };
381
- type GetAccountResult = Address$1[];
382
- type GetAccounts = MethodParamsAndResult<GetAccountsParams, GetAccountResult>;
433
+ declare const getAccountsMethodName = "getAccounts";
434
+ declare const getAccountsParamsSchema: v.ObjectSchema<{
435
+ /**
436
+ * The purposes for which to generate addresses. See
437
+ * {@linkcode AddressPurpose} for available purposes.
438
+ */
439
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
440
+ /**
441
+ * A message to be displayed to the user in the request prompt.
442
+ */
443
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
444
+ }, undefined>;
445
+ declare const getAccountsResultSchema: v.ArraySchema<v.ObjectSchema<{
446
+ readonly address: v.StringSchema<undefined>;
447
+ readonly publicKey: v.StringSchema<undefined>;
448
+ readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
449
+ readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
450
+ }, undefined>, undefined>;
451
+ declare const getAccountsRequestMessageSchema: v.ObjectSchema<{
452
+ readonly method: v.LiteralSchema<"getAccounts", undefined>;
453
+ readonly params: v.ObjectSchema<{
454
+ /**
455
+ * The purposes for which to generate addresses. See
456
+ * {@linkcode AddressPurpose} for available purposes.
457
+ */
458
+ readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
459
+ /**
460
+ * A message to be displayed to the user in the request prompt.
461
+ */
462
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
463
+ }, undefined>;
464
+ readonly id: v.StringSchema<undefined>;
465
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
466
+ }, undefined>;
467
+ type GetAccounts = MethodParamsAndResult<v.InferOutput<typeof getAccountsParamsSchema>, v.InferOutput<typeof getAccountsResultSchema>>;
468
+ declare const getBalanceMethodName = "getBalance";
469
+ declare const getBalanceParamsSchema: v.UndefinedSchema<undefined>;
470
+ declare const getBalanceResultSchema: v.ObjectSchema<{
471
+ /**
472
+ * The balance of the wallet in sats.
473
+ */
474
+ readonly confirmedBalance: v.BigintSchema<undefined>;
475
+ readonly unconfirmedUtxosBalance: v.BigintSchema<undefined>;
476
+ }, undefined>;
477
+ declare const getBalanceSchema: v.ObjectSchema<{
478
+ readonly method: v.LiteralSchema<"getBalance", undefined>;
479
+ readonly id: v.StringSchema<undefined>;
480
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
481
+ readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, never>;
482
+ }, undefined>;
483
+ type GetBalance = MethodParamsAndResult<v.InferOutput<typeof getBalanceParamsSchema>, v.InferOutput<typeof getBalanceResultSchema>>;
383
484
 
384
485
  type CreateMintOrderRequest = {
385
486
  runeName: string;
@@ -684,6 +785,27 @@ type SignTransactionParams = Transaction & Partial<Pubkey>;
684
785
  type SignTransactionResult = Transaction;
685
786
  type StxSignTransaction = MethodParamsAndResult<SignTransactionParams, SignTransactionResult>;
686
787
 
788
+ declare const connectMethodName = "wallet_connect";
789
+ declare const connectParamsSchema: v.UndefinedSchema<undefined>;
790
+ declare const connectResultSchema: v.UndefinedSchema<undefined>;
791
+ declare const connectSchema: v.ObjectSchema<{
792
+ readonly method: v.LiteralSchema<"wallet_connect", undefined>;
793
+ readonly params: v.UndefinedSchema<undefined>;
794
+ readonly id: v.StringSchema<undefined>;
795
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
796
+ }, undefined>;
797
+ type Connect = MethodParamsAndResult<v.InferOutput<typeof connectParamsSchema>, v.InferOutput<typeof connectResultSchema>>;
798
+ declare const disconnectMethodName = "wallet_disconnect";
799
+ declare const disconnectParamsSchema: v.UndefinedSchema<undefined>;
800
+ declare const disconnectResultSchema: v.UndefinedSchema<undefined>;
801
+ declare const disconnectSchema: v.ObjectSchema<{
802
+ readonly method: v.LiteralSchema<"wallet_disconnect", undefined>;
803
+ readonly params: v.UndefinedSchema<undefined>;
804
+ readonly id: v.StringSchema<undefined>;
805
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
806
+ }, undefined>;
807
+ type Disconnect = MethodParamsAndResult<v.InferOutput<typeof disconnectParamsSchema>, v.InferOutput<typeof disconnectResultSchema>>;
808
+
687
809
  interface StxRequests {
688
810
  stx_callContract: StxCallContract;
689
811
  stx_deployContract: StxDeployContract;
@@ -699,6 +821,7 @@ interface BtcRequests {
699
821
  getInfo: GetInfo;
700
822
  getAddresses: GetAddresses;
701
823
  getAccounts: GetAccounts;
824
+ getBalance: GetBalance;
702
825
  signMessage: SignMessage;
703
826
  sendTransfer: SendTransfer;
704
827
  signPsbt: SignPsbt;
@@ -715,11 +838,15 @@ interface RunesRequests {
715
838
  runes_getBalance: GetRunesBalance;
716
839
  }
717
840
  type RunesRequestMethod = keyof RunesRequests;
718
- type Requests = BtcRequests & StxRequests & RunesRequests;
841
+ interface WalletMethods {
842
+ wallet_connect: Connect;
843
+ wallet_disconnect: Disconnect;
844
+ }
845
+ type Requests = BtcRequests & StxRequests & RunesRequests & WalletMethods;
719
846
  type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
720
847
  type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
721
848
 
722
- declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
849
+ declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
723
850
 
724
851
  declare abstract class SatsConnectAdapter {
725
852
  abstract readonly id: string;
@@ -737,10 +864,10 @@ declare abstract class SatsConnectAdapter {
737
864
  declare class BaseAdapter extends SatsConnectAdapter {
738
865
  id: string;
739
866
  constructor(providerId: string);
740
- requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
867
+ requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
741
868
  }
742
869
 
743
870
  declare const DefaultAdaptersInfo: Record<string, Provider>;
744
871
  declare const defaultAdapters: Record<string, new () => SatsConnectAdapter>;
745
872
 
746
- 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 };
873
+ 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, 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, rpcRequestMessageSchema, sendBtcTransaction, setDefaultProvider, signMessage, signMessageMethodName, signMessageParamsSchema, signMessageRequestMessageSchema, signMessageResultSchema, signMultipleTransactions, signTransaction };
package/dist/index.mjs CHANGED
@@ -1,9 +1,27 @@
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";
6
+ BitcoinNetworkType2["Signet"] = "Signet";
5
7
  return BitcoinNetworkType2;
6
8
  })(BitcoinNetworkType || {});
9
+ var rpcRequestMessageSchema = v.object({
10
+ jsonrpc: v.literal("2.0"),
11
+ method: v.string(),
12
+ params: v.optional(
13
+ v.union([
14
+ v.array(v.unknown()),
15
+ v.looseObject({}),
16
+ // Note: This is to support current incorrect usage of RPC 2.0. Params need
17
+ // to be either an array or an object when provided. Changing this now would
18
+ // be a breaking change, so accepting null values for now. Tracking in
19
+ // https://linear.app/xverseapp/issue/ENG-4538.
20
+ v.null()
21
+ ])
22
+ ),
23
+ id: v.optional(v.union([v.string(), v.number(), v.null()]))
24
+ });
7
25
  var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
8
26
  RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
9
27
  RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
@@ -12,12 +30,18 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
12
30
  RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
13
31
  RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
14
32
  RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
33
+ RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
15
34
  return RpcErrorCode2;
16
35
  })(RpcErrorCode || {});
17
36
 
18
37
  // src/runes/api.ts
19
38
  import axios from "axios";
20
- var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${network === "Testnet" /* Testnet */ ? "-testnet" : ""}.xverse.app/v1`;
39
+ var urlNetworkSuffix = {
40
+ ["Mainnet" /* Mainnet */]: "",
41
+ ["Testnet" /* Testnet */]: "-testnet",
42
+ ["Signet" /* Signet */]: "-signet"
43
+ };
44
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
21
45
  var RunesApi = class {
22
46
  client;
23
47
  constructor(network) {
@@ -151,9 +175,13 @@ var RunesApi = class {
151
175
  }
152
176
  };
153
177
  };
154
- var testnetClient = new RunesApi("Testnet" /* Testnet */);
155
- var mainnetClient = new RunesApi("Mainnet" /* Mainnet */);
156
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => network === "Mainnet" /* Mainnet */ ? mainnetClient : testnetClient;
178
+ var clients = {};
179
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
180
+ if (!clients[network]) {
181
+ clients[network] = new RunesApi(network);
182
+ }
183
+ return clients[network];
184
+ };
157
185
 
158
186
  // src/adapters/satsConnectAdapter.ts
159
187
  var SatsConnectAdapter = class {
@@ -482,6 +510,188 @@ function getSupportedWallets() {
482
510
  return wallets;
483
511
  }
484
512
 
513
+ // src/addresses/index.ts
514
+ import { createUnsecuredToken } from "jsontokens";
515
+
516
+ // src/addresses/types.ts
517
+ import * as v2 from "valibot";
518
+ var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
519
+ AddressPurpose2["Ordinals"] = "ordinals";
520
+ AddressPurpose2["Payment"] = "payment";
521
+ AddressPurpose2["Stacks"] = "stacks";
522
+ return AddressPurpose2;
523
+ })(AddressPurpose || {});
524
+ var AddressType = /* @__PURE__ */ ((AddressType3) => {
525
+ AddressType3["p2pkh"] = "p2pkh";
526
+ AddressType3["p2sh"] = "p2sh";
527
+ AddressType3["p2wpkh"] = "p2wpkh";
528
+ AddressType3["p2wsh"] = "p2wsh";
529
+ AddressType3["p2tr"] = "p2tr";
530
+ AddressType3["stacks"] = "stacks";
531
+ return AddressType3;
532
+ })(AddressType || {});
533
+ var addressSchema = v2.object({
534
+ address: v2.string(),
535
+ publicKey: v2.string(),
536
+ purpose: v2.enum(AddressPurpose),
537
+ addressType: v2.enum(AddressType)
538
+ });
539
+
540
+ // src/addresses/index.ts
541
+ var getAddress = async (options) => {
542
+ const provider = await getProviderOrThrow(options.getProvider);
543
+ const { purposes } = options.payload;
544
+ if (!purposes) {
545
+ throw new Error("Address purposes are required");
546
+ }
547
+ try {
548
+ const request2 = createUnsecuredToken(options.payload);
549
+ const response = await provider.connect(request2);
550
+ options.onFinish?.(response);
551
+ } catch (error) {
552
+ console.error("[Connect] Error during address request", error);
553
+ options.onCancel?.();
554
+ }
555
+ };
556
+
557
+ // src/request/types/btcMethods.ts
558
+ import * as v3 from "valibot";
559
+ var getInfoMethodName = "getInfo";
560
+ var getInfoParamsSchema = v3.null();
561
+ var getInfoResultSchema = v3.object({
562
+ /**
563
+ * Version of the wallet.
564
+ */
565
+ version: v3.string(),
566
+ /**
567
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
568
+ */
569
+ methods: v3.optional(v3.array(v3.string())),
570
+ /**
571
+ * List of WBIP standards supported by the wallet. Not currently used.
572
+ */
573
+ supports: v3.array(v3.string())
574
+ });
575
+ var getInfoSchema = v3.object({
576
+ ...rpcRequestMessageSchema.entries,
577
+ ...v3.object({
578
+ method: v3.literal(getInfoMethodName),
579
+ params: getInfoParamsSchema,
580
+ id: v3.string()
581
+ }).entries
582
+ });
583
+ var getAddressesMethodName = "getAddresses";
584
+ var getAddressesParamsSchema = v3.object({
585
+ /**
586
+ * The purposes for which to generate addresses. See
587
+ * {@linkcode AddressPurpose} for available purposes.
588
+ */
589
+ purposes: v3.array(v3.enum(AddressPurpose)),
590
+ /**
591
+ * A message to be displayed to the user in the request prompt.
592
+ */
593
+ message: v3.optional(v3.string())
594
+ });
595
+ var getAddressesResultSchema = v3.object({
596
+ /**
597
+ * The addresses generated for the given purposes.
598
+ */
599
+ addresses: v3.array(addressSchema)
600
+ });
601
+ var getAddressesRequestMessageSchema = v3.object({
602
+ ...rpcRequestMessageSchema.entries,
603
+ ...v3.object({
604
+ method: v3.literal(getAddressesMethodName),
605
+ params: getAddressesParamsSchema,
606
+ id: v3.string()
607
+ }).entries
608
+ });
609
+ var signMessageMethodName = "signMessage";
610
+ var signMessageParamsSchema = v3.object({
611
+ /**
612
+ * The address used for signing.
613
+ **/
614
+ address: v3.string(),
615
+ /**
616
+ * The message to sign.
617
+ **/
618
+ message: v3.string()
619
+ });
620
+ var signMessageResultSchema = v3.object({
621
+ /**
622
+ * The signature of the message.
623
+ */
624
+ signature: v3.string(),
625
+ /**
626
+ * hash of the message.
627
+ */
628
+ messageHash: v3.string(),
629
+ /**
630
+ * The address used for signing.
631
+ */
632
+ address: v3.string()
633
+ });
634
+ var signMessageRequestMessageSchema = v3.object({
635
+ ...rpcRequestMessageSchema.entries,
636
+ ...v3.object({
637
+ method: v3.literal(signMessageMethodName),
638
+ params: signMessageParamsSchema,
639
+ id: v3.string()
640
+ }).entries
641
+ });
642
+ var getAccountsMethodName = "getAccounts";
643
+ var getAccountsParamsSchema = getAddressesParamsSchema;
644
+ var getAccountsResultSchema = v3.array(addressSchema);
645
+ var getAccountsRequestMessageSchema = v3.object({
646
+ ...rpcRequestMessageSchema.entries,
647
+ ...v3.object({
648
+ method: v3.literal(getAccountsMethodName),
649
+ params: getAccountsParamsSchema,
650
+ id: v3.string()
651
+ }).entries
652
+ });
653
+ var getBalanceMethodName = "getBalance";
654
+ var getBalanceParamsSchema = v3.undefined();
655
+ var getBalanceResultSchema = v3.object({
656
+ /**
657
+ * The balance of the wallet in sats.
658
+ */
659
+ confirmedBalance: v3.bigint(),
660
+ unconfirmedUtxosBalance: v3.bigint()
661
+ });
662
+ var getBalanceSchema = v3.object({
663
+ ...rpcRequestMessageSchema.entries,
664
+ ...v3.object({
665
+ method: v3.literal(getBalanceMethodName),
666
+ id: v3.string()
667
+ }).entries
668
+ });
669
+
670
+ // src/request/types/walletMethods.ts
671
+ import * as v4 from "valibot";
672
+ var connectMethodName = "wallet_connect";
673
+ var connectParamsSchema = v4.undefined();
674
+ var connectResultSchema = v4.undefined();
675
+ var connectSchema = v4.object({
676
+ ...rpcRequestMessageSchema.entries,
677
+ ...v4.object({
678
+ method: v4.literal(connectMethodName),
679
+ params: connectParamsSchema,
680
+ id: v4.string()
681
+ }).entries
682
+ });
683
+ var disconnectMethodName = "wallet_disconnect";
684
+ var disconnectParamsSchema = v4.undefined();
685
+ var disconnectResultSchema = v4.undefined();
686
+ var disconnectSchema = v4.object({
687
+ ...rpcRequestMessageSchema.entries,
688
+ ...v4.object({
689
+ method: v4.literal(disconnectMethodName),
690
+ params: disconnectParamsSchema,
691
+ id: v4.string()
692
+ }).entries
693
+ });
694
+
485
695
  // src/request/index.ts
486
696
  var request = async (method, params, providerId) => {
487
697
  let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
@@ -521,45 +731,6 @@ var XverseAdapter = class extends SatsConnectAdapter {
521
731
  // src/adapters/unisat.ts
522
732
  import { Buffer } from "buffer";
523
733
  import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
524
-
525
- // src/addresses/index.ts
526
- import { createUnsecuredToken } from "jsontokens";
527
-
528
- // src/addresses/types.ts
529
- var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
530
- AddressPurpose2["Ordinals"] = "ordinals";
531
- AddressPurpose2["Payment"] = "payment";
532
- AddressPurpose2["Stacks"] = "stacks";
533
- return AddressPurpose2;
534
- })(AddressPurpose || {});
535
- var AddressType = /* @__PURE__ */ ((AddressType3) => {
536
- AddressType3["p2pkh"] = "p2pkh";
537
- AddressType3["p2sh"] = "p2sh";
538
- AddressType3["p2wpkh"] = "p2wpkh";
539
- AddressType3["p2wsh"] = "p2wsh";
540
- AddressType3["p2tr"] = "p2tr";
541
- AddressType3["stacks"] = "stacks";
542
- return AddressType3;
543
- })(AddressType || {});
544
-
545
- // src/addresses/index.ts
546
- var getAddress = async (options) => {
547
- const provider = await getProviderOrThrow(options.getProvider);
548
- const { purposes } = options.payload;
549
- if (!purposes) {
550
- throw new Error("Address purposes are required");
551
- }
552
- try {
553
- const request2 = createUnsecuredToken(options.payload);
554
- const response = await provider.connect(request2);
555
- options.onFinish?.(response);
556
- } catch (error) {
557
- console.error("[Connect] Error during address request", error);
558
- options.onCancel?.();
559
- }
560
- };
561
-
562
- // src/adapters/unisat.ts
563
734
  function convertSignInputsToInputType(signInputs, allowedSignHash) {
564
735
  let result = [];
565
736
  for (let address in signInputs) {
@@ -964,12 +1135,37 @@ export {
964
1135
  DefaultAdaptersInfo,
965
1136
  RpcErrorCode,
966
1137
  SatsConnectAdapter,
1138
+ addressSchema,
1139
+ connectMethodName,
1140
+ connectParamsSchema,
1141
+ connectResultSchema,
1142
+ connectSchema,
967
1143
  createInscription,
968
1144
  createRepeatInscriptions,
969
1145
  defaultAdapters,
1146
+ disconnectMethodName,
1147
+ disconnectParamsSchema,
1148
+ disconnectResultSchema,
1149
+ disconnectSchema,
1150
+ getAccountsMethodName,
1151
+ getAccountsParamsSchema,
1152
+ getAccountsRequestMessageSchema,
1153
+ getAccountsResultSchema,
970
1154
  getAddress,
1155
+ getAddressesMethodName,
1156
+ getAddressesParamsSchema,
1157
+ getAddressesRequestMessageSchema,
1158
+ getAddressesResultSchema,
1159
+ getBalanceMethodName,
1160
+ getBalanceParamsSchema,
1161
+ getBalanceResultSchema,
1162
+ getBalanceSchema,
971
1163
  getCapabilities,
972
1164
  getDefaultProvider,
1165
+ getInfoMethodName,
1166
+ getInfoParamsSchema,
1167
+ getInfoResultSchema,
1168
+ getInfoSchema,
973
1169
  getProviderById,
974
1170
  getProviderOrThrow,
975
1171
  getProviders,
@@ -977,9 +1173,14 @@ export {
977
1173
  isProviderInstalled,
978
1174
  removeDefaultProvider,
979
1175
  request,
1176
+ rpcRequestMessageSchema,
980
1177
  sendBtcTransaction,
981
1178
  setDefaultProvider,
982
1179
  signMessage,
1180
+ signMessageMethodName,
1181
+ signMessageParamsSchema,
1182
+ signMessageRequestMessageSchema,
1183
+ signMessageResultSchema,
983
1184
  signMultipleTransactions,
984
1185
  signTransaction
985
1186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.10",
3
+ "version": "0.0.11-1501a20",
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",