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

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
@@ -159,6 +159,8 @@ interface RequestOptions<Payload extends RequestPayload, Response> {
159
159
  payload: Payload;
160
160
  getProvider?: () => Promise<BitcoinProvider | undefined>;
161
161
  }
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>;
162
164
  declare const rpcRequestMessageSchema: v.ObjectSchema<{
163
165
  readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
164
166
  readonly method: v.StringSchema<undefined>;
@@ -166,7 +168,6 @@ declare const rpcRequestMessageSchema: v.ObjectSchema<{
166
168
  readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
167
169
  }, undefined>;
168
170
  type RpcRequestMessage = v.InferOutput<typeof rpcRequestMessageSchema>;
169
- type RpcId = string | null;
170
171
  interface RpcBase {
171
172
  jsonrpc: '2.0';
172
173
  id: RpcId;
@@ -219,6 +220,25 @@ declare enum RpcErrorCode {
219
220
  */
220
221
  ACCESS_DENIED = -32002
221
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>;
222
242
  interface RpcError {
223
243
  code: number | RpcErrorCode;
224
244
  message: string;
@@ -469,10 +489,18 @@ declare const getBalanceMethodName = "getBalance";
469
489
  declare const getBalanceParamsSchema: v.UndefinedSchema<undefined>;
470
490
  declare const getBalanceResultSchema: v.ObjectSchema<{
471
491
  /**
472
- * The balance of the wallet in sats.
492
+ * The confirmed balance of the wallet in sats.
493
+ */
494
+ readonly confirmed: v.BigintSchema<undefined>;
495
+ /**
496
+ * The unconfirmed balance of the wallet in sats.
497
+ */
498
+ readonly unconfirmed: v.BigintSchema<undefined>;
499
+ /**
500
+ * The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
501
+ * sats.
473
502
  */
474
- readonly confirmedBalance: v.BigintSchema<undefined>;
475
- readonly unconfirmedUtxosBalance: v.BigintSchema<undefined>;
503
+ readonly total: v.BigintSchema<undefined>;
476
504
  }, undefined>;
477
505
  declare const getBalanceSchema: v.ObjectSchema<{
478
506
  readonly method: v.LiteralSchema<"getBalance", undefined>;
@@ -870,4 +898,4 @@ declare class BaseAdapter extends SatsConnectAdapter {
870
898
  declare const DefaultAdaptersInfo: Record<string, Provider>;
871
899
  declare const defaultAdapters: Record<string, new () => SatsConnectAdapter>;
872
900
 
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 };
901
+ 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
@@ -6,6 +6,7 @@ var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
6
6
  BitcoinNetworkType2["Signet"] = "Signet";
7
7
  return BitcoinNetworkType2;
8
8
  })(BitcoinNetworkType || {});
9
+ var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
9
10
  var rpcRequestMessageSchema = v.object({
10
11
  jsonrpc: v.literal("2.0"),
11
12
  method: v.string(),
@@ -20,7 +21,7 @@ var rpcRequestMessageSchema = v.object({
20
21
  v.null()
21
22
  ])
22
23
  ),
23
- id: v.optional(v.union([v.string(), v.number(), v.null()]))
24
+ id: RpcIdSchema
24
25
  });
25
26
  var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
26
27
  RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
@@ -33,6 +34,20 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
33
34
  RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
34
35
  return RpcErrorCode2;
35
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
+ ]);
36
51
 
37
52
  // src/runes/api.ts
38
53
  import axios from "axios";
@@ -510,6 +525,9 @@ function getSupportedWallets() {
510
525
  return wallets;
511
526
  }
512
527
 
528
+ // src/request/index.ts
529
+ import * as v5 from "valibot";
530
+
513
531
  // src/addresses/index.ts
514
532
  import { createUnsecuredToken } from "jsontokens";
515
533
 
@@ -654,10 +672,18 @@ var getBalanceMethodName = "getBalance";
654
672
  var getBalanceParamsSchema = v3.undefined();
655
673
  var getBalanceResultSchema = v3.object({
656
674
  /**
657
- * The balance of the wallet in sats.
675
+ * The confirmed balance of the wallet in sats.
676
+ */
677
+ confirmed: v3.bigint(),
678
+ /**
679
+ * The unconfirmed balance of the wallet in sats.
680
+ */
681
+ unconfirmed: v3.bigint(),
682
+ /**
683
+ * The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
684
+ * sats.
658
685
  */
659
- confirmedBalance: v3.bigint(),
660
- unconfirmedUtxosBalance: v3.bigint()
686
+ total: v3.bigint()
661
687
  });
662
688
  var getBalanceSchema = v3.object({
663
689
  ...rpcRequestMessageSchema.entries,
@@ -705,20 +731,29 @@ var request = async (method, params, providerId) => {
705
731
  throw new Error("A wallet method is required");
706
732
  }
707
733
  const response = await provider.request(method, params);
708
- if (isRpcSuccessResponse(response)) {
734
+ const parseResult = v5.safeParse(rpcResponseMessageSchema, response);
735
+ if (!parseResult.success) {
709
736
  return {
710
- status: "success",
711
- result: response.result
737
+ status: "error",
738
+ error: {
739
+ code: -32603 /* INTERNAL_ERROR */,
740
+ message: "Received unknown response from provider.",
741
+ data: response
742
+ }
743
+ };
744
+ }
745
+ const parsedResponse = parseResult.output;
746
+ if ("error" in parsedResponse) {
747
+ return {
748
+ status: "error",
749
+ error: parsedResponse.error
712
750
  };
713
751
  }
714
752
  return {
715
- status: "error",
716
- error: response.error
753
+ status: "success",
754
+ result: parsedResponse.result
717
755
  };
718
756
  };
719
- var isRpcSuccessResponse = (response) => {
720
- return Object.hasOwn(response, "result") && !!response.result;
721
- };
722
757
 
723
758
  // src/adapters/xverse.ts
724
759
  var XverseAdapter = class extends SatsConnectAdapter {
@@ -1134,6 +1169,7 @@ export {
1134
1169
  BitcoinNetworkType,
1135
1170
  DefaultAdaptersInfo,
1136
1171
  RpcErrorCode,
1172
+ RpcIdSchema,
1137
1173
  SatsConnectAdapter,
1138
1174
  addressSchema,
1139
1175
  connectMethodName,
@@ -1173,7 +1209,10 @@ export {
1173
1209
  isProviderInstalled,
1174
1210
  removeDefaultProvider,
1175
1211
  request,
1212
+ rpcErrorResponseMessageSchema,
1176
1213
  rpcRequestMessageSchema,
1214
+ rpcResponseMessageSchema,
1215
+ rpcSuccessResponseMessageSchema,
1177
1216
  sendBtcTransaction,
1178
1217
  setDefaultProvider,
1179
1218
  signMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.11-1501a20",
3
+ "version": "0.0.11-2768523",
4
4
  "main": "dist/index.mjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",