@sats-connect/core 0.0.11 → 0.0.12-635f56e
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 +333 -86
- package/dist/index.mjs +392 -44
- package/package.json +6 -2
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[];
|
|
@@ -114,7 +116,7 @@ interface Provider {
|
|
|
114
116
|
mozillaAddOnsUrl?: string;
|
|
115
117
|
googlePlayStoreUrl?: string;
|
|
116
118
|
iOSAppStoreUrl?: string;
|
|
117
|
-
methods?: (StxRequestMethod | BtcRequestMethod | RunesRequestMethod)[];
|
|
119
|
+
methods?: (StxRequestMethod | BtcRequestMethod | RunesRequestMethod | OrdinalsRequestMethod)[];
|
|
118
120
|
}
|
|
119
121
|
interface SupportedWallet extends Provider {
|
|
120
122
|
isInstalled: boolean;
|
|
@@ -157,7 +159,15 @@ interface RequestOptions<Payload extends RequestPayload, Response> {
|
|
|
157
159
|
payload: Payload;
|
|
158
160
|
getProvider?: () => Promise<BitcoinProvider | undefined>;
|
|
159
161
|
}
|
|
160
|
-
|
|
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,34 @@ 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.NonOptionalSchema<v.UnknownSchema, undefined>;
|
|
226
|
+
readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
|
|
227
|
+
}, undefined>;
|
|
228
|
+
type RpcSuccessResponseMessage = v.InferOutput<typeof rpcSuccessResponseMessageSchema>;
|
|
229
|
+
declare const rpcErrorResponseMessageSchema: v.ObjectSchema<{
|
|
230
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
231
|
+
readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
|
|
232
|
+
readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
|
|
233
|
+
}, undefined>;
|
|
234
|
+
type RpcErrorResponseMessage = v.InferOutput<typeof rpcErrorResponseMessageSchema>;
|
|
235
|
+
declare const rpcResponseMessageSchema: v.UnionSchema<[v.ObjectSchema<{
|
|
236
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
237
|
+
readonly result: v.NonOptionalSchema<v.UnknownSchema, undefined>;
|
|
238
|
+
readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
|
|
239
|
+
}, undefined>, v.ObjectSchema<{
|
|
240
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
241
|
+
readonly error: v.NonOptionalSchema<v.UnknownSchema, undefined>;
|
|
242
|
+
readonly id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.NullSchema<undefined>], undefined>, never>;
|
|
243
|
+
}, undefined>], undefined>;
|
|
244
|
+
type RpcResponseMessage = v.InferOutput<typeof rpcResponseMessageSchema>;
|
|
209
245
|
interface RpcError {
|
|
210
246
|
code: number | RpcErrorCode;
|
|
211
247
|
message: string;
|
|
@@ -243,12 +279,13 @@ declare enum AddressType {
|
|
|
243
279
|
p2tr = "p2tr",
|
|
244
280
|
stacks = "stacks"
|
|
245
281
|
}
|
|
246
|
-
|
|
247
|
-
address:
|
|
248
|
-
publicKey:
|
|
249
|
-
purpose
|
|
250
|
-
addressType
|
|
251
|
-
}
|
|
282
|
+
declare const addressSchema: v.ObjectSchema<{
|
|
283
|
+
readonly address: v.StringSchema<undefined>;
|
|
284
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
285
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
286
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
287
|
+
}, undefined>;
|
|
288
|
+
type Address$1 = v.InferOutput<typeof addressSchema>;
|
|
252
289
|
interface GetAddressResponse {
|
|
253
290
|
addresses: Address$1[];
|
|
254
291
|
}
|
|
@@ -256,59 +293,119 @@ type GetAddressOptions = RequestOptions<GetAddressPayload, GetAddressResponse>;
|
|
|
256
293
|
|
|
257
294
|
declare const getAddress: (options: GetAddressOptions) => Promise<void>;
|
|
258
295
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
*
|
|
273
|
-
*/
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
type
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
296
|
+
declare const getInfoMethodName = "getInfo";
|
|
297
|
+
declare const getInfoParamsSchema: v.NullishSchema<v.NullSchema<undefined>, never>;
|
|
298
|
+
type GetInfoParams = v.InferOutput<typeof getInfoParamsSchema>;
|
|
299
|
+
declare const getInfoResultSchema: v.ObjectSchema<{
|
|
300
|
+
/**
|
|
301
|
+
* Version of the wallet.
|
|
302
|
+
*/
|
|
303
|
+
readonly version: v.StringSchema<undefined>;
|
|
304
|
+
/**
|
|
305
|
+
* [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
|
|
306
|
+
*/
|
|
307
|
+
readonly methods: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, never>;
|
|
308
|
+
/**
|
|
309
|
+
* List of WBIP standards supported by the wallet. Not currently used.
|
|
310
|
+
*/
|
|
311
|
+
readonly supports: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
312
|
+
}, undefined>;
|
|
313
|
+
type GetInfoResult = v.InferOutput<typeof getInfoResultSchema>;
|
|
314
|
+
declare const getInfoRequestMessageSchema: v.ObjectSchema<{
|
|
315
|
+
readonly method: v.LiteralSchema<"getInfo", undefined>;
|
|
316
|
+
readonly params: v.NullishSchema<v.NullSchema<undefined>, never>;
|
|
317
|
+
readonly id: v.StringSchema<undefined>;
|
|
318
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
319
|
+
}, undefined>;
|
|
320
|
+
type GetInfoRequestMessage = v.InferOutput<typeof getInfoRequestMessageSchema>;
|
|
321
|
+
type GetInfo = MethodParamsAndResult<v.InferOutput<typeof getInfoParamsSchema>, v.InferOutput<typeof getInfoResultSchema>>;
|
|
322
|
+
declare const getAddressesMethodName = "getAddresses";
|
|
323
|
+
declare const getAddressesParamsSchema: v.ObjectSchema<{
|
|
324
|
+
/**
|
|
325
|
+
* The purposes for which to generate addresses. See
|
|
326
|
+
* {@linkcode AddressPurpose} for available purposes.
|
|
327
|
+
*/
|
|
328
|
+
readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
|
|
329
|
+
/**
|
|
330
|
+
* A message to be displayed to the user in the request prompt.
|
|
331
|
+
*/
|
|
332
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
333
|
+
}, undefined>;
|
|
334
|
+
type GetAddressesParams = v.InferOutput<typeof getAddressesParamsSchema>;
|
|
335
|
+
declare const getAddressesResultSchema: v.ObjectSchema<{
|
|
336
|
+
/**
|
|
337
|
+
* The addresses generated for the given purposes.
|
|
338
|
+
*/
|
|
339
|
+
readonly addresses: v.ArraySchema<v.ObjectSchema<{
|
|
340
|
+
readonly address: v.StringSchema<undefined>;
|
|
341
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
342
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
343
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
344
|
+
}, undefined>, undefined>;
|
|
345
|
+
}, undefined>;
|
|
346
|
+
type GetAddressesResult = v.InferOutput<typeof getAddressesResultSchema>;
|
|
347
|
+
declare const getAddressesRequestMessageSchema: v.ObjectSchema<{
|
|
348
|
+
readonly method: v.LiteralSchema<"getAddresses", undefined>;
|
|
349
|
+
readonly params: v.ObjectSchema<{
|
|
350
|
+
/**
|
|
351
|
+
* The purposes for which to generate addresses. See
|
|
352
|
+
* {@linkcode AddressPurpose} for available purposes.
|
|
353
|
+
*/
|
|
354
|
+
readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
|
|
355
|
+
/**
|
|
356
|
+
* A message to be displayed to the user in the request prompt.
|
|
357
|
+
*/
|
|
358
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
359
|
+
}, undefined>;
|
|
360
|
+
readonly id: v.StringSchema<undefined>;
|
|
361
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
362
|
+
}, undefined>;
|
|
363
|
+
type GetAddressesRequestMessage = v.InferOutput<typeof getAddressesRequestMessageSchema>;
|
|
364
|
+
type GetAddresses = MethodParamsAndResult<v.InferOutput<typeof getAddressesParamsSchema>, v.InferOutput<typeof getAddressesResultSchema>>;
|
|
365
|
+
declare const signMessageMethodName = "signMessage";
|
|
366
|
+
declare const signMessageParamsSchema: v.ObjectSchema<{
|
|
288
367
|
/**
|
|
289
368
|
* The address used for signing.
|
|
290
369
|
**/
|
|
291
|
-
address:
|
|
370
|
+
readonly address: v.StringSchema<undefined>;
|
|
292
371
|
/**
|
|
293
372
|
* The message to sign.
|
|
294
373
|
**/
|
|
295
|
-
message:
|
|
296
|
-
}
|
|
297
|
-
type
|
|
374
|
+
readonly message: v.StringSchema<undefined>;
|
|
375
|
+
}, undefined>;
|
|
376
|
+
type SignMessageParams = v.InferOutput<typeof signMessageParamsSchema>;
|
|
377
|
+
declare const signMessageResultSchema: v.ObjectSchema<{
|
|
298
378
|
/**
|
|
299
379
|
* The signature of the message.
|
|
300
380
|
*/
|
|
301
|
-
signature:
|
|
381
|
+
readonly signature: v.StringSchema<undefined>;
|
|
302
382
|
/**
|
|
303
383
|
* hash of the message.
|
|
304
384
|
*/
|
|
305
|
-
messageHash:
|
|
385
|
+
readonly messageHash: v.StringSchema<undefined>;
|
|
306
386
|
/**
|
|
307
387
|
* The address used for signing.
|
|
308
388
|
*/
|
|
309
|
-
address:
|
|
310
|
-
}
|
|
311
|
-
type
|
|
389
|
+
readonly address: v.StringSchema<undefined>;
|
|
390
|
+
}, undefined>;
|
|
391
|
+
type SignMessageResult = v.InferOutput<typeof signMessageResultSchema>;
|
|
392
|
+
declare const signMessageRequestMessageSchema: v.ObjectSchema<{
|
|
393
|
+
readonly method: v.LiteralSchema<"signMessage", undefined>;
|
|
394
|
+
readonly params: v.ObjectSchema<{
|
|
395
|
+
/**
|
|
396
|
+
* The address used for signing.
|
|
397
|
+
**/
|
|
398
|
+
readonly address: v.StringSchema<undefined>;
|
|
399
|
+
/**
|
|
400
|
+
* The message to sign.
|
|
401
|
+
**/
|
|
402
|
+
readonly message: v.StringSchema<undefined>;
|
|
403
|
+
}, undefined>;
|
|
404
|
+
readonly id: v.StringSchema<undefined>;
|
|
405
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
406
|
+
}, undefined>;
|
|
407
|
+
type SignMessageRequestMessage = v.InferOutput<typeof signMessageRequestMessageSchema>;
|
|
408
|
+
type SignMessage = MethodParamsAndResult<v.InferOutput<typeof signMessageParamsSchema>, v.InferOutput<typeof signMessageResultSchema>>;
|
|
312
409
|
type Recipient$1 = {
|
|
313
410
|
/**
|
|
314
411
|
* The recipient's address.
|
|
@@ -365,22 +462,104 @@ type SignPsbtResult = {
|
|
|
365
462
|
txid?: string;
|
|
366
463
|
};
|
|
367
464
|
type SignPsbt = MethodParamsAndResult<SignPsbtParams, SignPsbtResult>;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
*
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
465
|
+
declare const getAccountsMethodName = "getAccounts";
|
|
466
|
+
declare const getAccountsParamsSchema: v.ObjectSchema<{
|
|
467
|
+
/**
|
|
468
|
+
* The purposes for which to generate addresses. See
|
|
469
|
+
* {@linkcode AddressPurpose} for available purposes.
|
|
470
|
+
*/
|
|
471
|
+
readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
|
|
472
|
+
/**
|
|
473
|
+
* A message to be displayed to the user in the request prompt.
|
|
474
|
+
*/
|
|
475
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
476
|
+
}, undefined>;
|
|
477
|
+
type GetAccountsParams = v.InferOutput<typeof getAccountsParamsSchema>;
|
|
478
|
+
declare const getAccountsResultSchema: v.ArraySchema<v.ObjectSchema<{
|
|
479
|
+
readonly address: v.StringSchema<undefined>;
|
|
480
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
481
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
482
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
483
|
+
}, undefined>, undefined>;
|
|
484
|
+
type GetAccountsResult = v.InferOutput<typeof getAccountsResultSchema>;
|
|
485
|
+
declare const getAccountsRequestMessageSchema: v.ObjectSchema<{
|
|
486
|
+
readonly method: v.LiteralSchema<"getAccounts", undefined>;
|
|
487
|
+
readonly params: v.ObjectSchema<{
|
|
488
|
+
/**
|
|
489
|
+
* The purposes for which to generate addresses. See
|
|
490
|
+
* {@linkcode AddressPurpose} for available purposes.
|
|
491
|
+
*/
|
|
492
|
+
readonly purposes: v.ArraySchema<v.EnumSchema<typeof AddressPurpose, undefined>, undefined>;
|
|
493
|
+
/**
|
|
494
|
+
* A message to be displayed to the user in the request prompt.
|
|
495
|
+
*/
|
|
496
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
497
|
+
}, undefined>;
|
|
498
|
+
readonly id: v.StringSchema<undefined>;
|
|
499
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
500
|
+
}, undefined>;
|
|
501
|
+
type GetAccountsRequestMessage = v.InferOutput<typeof getAccountsRequestMessageSchema>;
|
|
502
|
+
type GetAccounts = MethodParamsAndResult<v.InferOutput<typeof getAccountsParamsSchema>, v.InferOutput<typeof getAccountsResultSchema>>;
|
|
503
|
+
declare const getBalanceMethodName = "getBalance";
|
|
504
|
+
declare const getBalanceParamsSchema: v.NullishSchema<v.NullSchema<undefined>, never>;
|
|
505
|
+
declare const getBalanceResultSchema: v.ObjectSchema<{
|
|
506
|
+
/**
|
|
507
|
+
* The confirmed balance of the wallet in sats. Using a string due to chrome
|
|
508
|
+
* messages not supporting bigint
|
|
509
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
510
|
+
*/
|
|
511
|
+
readonly confirmed: v.StringSchema<undefined>;
|
|
512
|
+
/**
|
|
513
|
+
* The unconfirmed balance of the wallet in sats. Using a string due to chrome
|
|
514
|
+
* messages not supporting bigint
|
|
515
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
516
|
+
*/
|
|
517
|
+
readonly unconfirmed: v.StringSchema<undefined>;
|
|
518
|
+
/**
|
|
519
|
+
* The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
|
|
520
|
+
* sats. Using a string due to chrome messages not supporting bigint
|
|
521
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
522
|
+
*/
|
|
523
|
+
readonly total: v.StringSchema<undefined>;
|
|
524
|
+
}, undefined>;
|
|
525
|
+
declare const getBalanceRequestMessageSchema: v.ObjectSchema<{
|
|
526
|
+
readonly method: v.LiteralSchema<"getBalance", undefined>;
|
|
527
|
+
readonly id: v.StringSchema<undefined>;
|
|
528
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
529
|
+
readonly params: v.OptionalSchema<v.UnionSchema<[v.ArraySchema<v.UnknownSchema, undefined>, v.LooseObjectSchema<{}, undefined>, v.NullSchema<undefined>], undefined>, never>;
|
|
530
|
+
}, undefined>;
|
|
531
|
+
type GetBalance = MethodParamsAndResult<v.InferOutput<typeof getBalanceParamsSchema>, v.InferOutput<typeof getBalanceResultSchema>>;
|
|
532
|
+
|
|
533
|
+
declare const getInscriptionsMethodName = "ord_getInscriptions";
|
|
534
|
+
declare const getInscriptionsParamsSchema: v.ObjectSchema<{
|
|
535
|
+
readonly offset: v.NumberSchema<undefined>;
|
|
536
|
+
readonly limit: v.NumberSchema<undefined>;
|
|
537
|
+
}, undefined>;
|
|
538
|
+
declare const getInscriptionsResultSchema: v.ObjectSchema<{
|
|
539
|
+
readonly inscriptions: v.ArraySchema<v.ObjectSchema<{
|
|
540
|
+
readonly inscriptionId: v.StringSchema<undefined>;
|
|
541
|
+
readonly inscriptionNumber: v.StringSchema<undefined>;
|
|
542
|
+
readonly address: v.StringSchema<undefined>;
|
|
543
|
+
readonly collectionName: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
544
|
+
readonly postage: v.StringSchema<undefined>;
|
|
545
|
+
readonly contentLength: v.StringSchema<undefined>;
|
|
546
|
+
readonly contentType: v.StringSchema<undefined>;
|
|
547
|
+
readonly timestamp: v.NumberSchema<undefined>;
|
|
548
|
+
readonly offset: v.NumberSchema<undefined>;
|
|
549
|
+
readonly genesisTransaction: v.StringSchema<undefined>;
|
|
550
|
+
readonly output: v.StringSchema<undefined>;
|
|
551
|
+
}, undefined>, undefined>;
|
|
552
|
+
}, undefined>;
|
|
553
|
+
declare const getInscriptionsSchema: v.ObjectSchema<{
|
|
554
|
+
readonly method: v.LiteralSchema<"ord_getInscriptions", undefined>;
|
|
555
|
+
readonly params: v.ObjectSchema<{
|
|
556
|
+
readonly offset: v.NumberSchema<undefined>;
|
|
557
|
+
readonly limit: v.NumberSchema<undefined>;
|
|
558
|
+
}, undefined>;
|
|
559
|
+
readonly id: v.StringSchema<undefined>;
|
|
560
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
561
|
+
}, undefined>;
|
|
562
|
+
type GetInscriptions = MethodParamsAndResult<v.InferOutput<typeof getInscriptionsParamsSchema>, v.InferOutput<typeof getInscriptionsResultSchema>>;
|
|
384
563
|
|
|
385
564
|
type CreateMintOrderRequest = {
|
|
386
565
|
runeName: string;
|
|
@@ -493,17 +672,27 @@ interface RbfOrderResult {
|
|
|
493
672
|
fundingAddress: string;
|
|
494
673
|
}
|
|
495
674
|
type RbfOrder = MethodParamsAndResult<RbfOrderParams, RbfOrderResult>;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
675
|
+
declare const getRunesBalanceMethodName = "runes_getBalance";
|
|
676
|
+
declare const getRunesBalanceParamsSchema: v.NullishSchema<v.NullSchema<undefined>, never>;
|
|
677
|
+
type GetRunesBalanceParams = v.InferOutput<typeof getRunesBalanceParamsSchema>;
|
|
678
|
+
declare const getRunesBalanceResultSchema: v.ObjectSchema<{
|
|
679
|
+
readonly balances: v.ArraySchema<v.ObjectSchema<{
|
|
680
|
+
readonly runeName: v.StringSchema<undefined>;
|
|
681
|
+
readonly amount: v.StringSchema<undefined>;
|
|
682
|
+
readonly divisibility: v.NumberSchema<undefined>;
|
|
683
|
+
readonly symbol: v.StringSchema<undefined>;
|
|
684
|
+
readonly inscriptionId: v.NullishSchema<v.StringSchema<undefined>, never>;
|
|
685
|
+
}, undefined>, undefined>;
|
|
686
|
+
}, undefined>;
|
|
687
|
+
type GetRunesBalanceResult = v.InferOutput<typeof getRunesBalanceResultSchema>;
|
|
688
|
+
declare const getRunesBalanceRequestMessageSchema: v.ObjectSchema<{
|
|
689
|
+
readonly method: v.LiteralSchema<"runes_getBalance", undefined>;
|
|
690
|
+
readonly params: v.NullishSchema<v.NullSchema<undefined>, never>;
|
|
691
|
+
readonly id: v.StringSchema<undefined>;
|
|
692
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
693
|
+
}, undefined>;
|
|
694
|
+
type GetRunesBalanceRequestMessage = v.InferOutput<typeof getRunesBalanceRequestMessageSchema>;
|
|
695
|
+
type GetRunesBalance = MethodParamsAndResult<v.InferOutput<typeof getRunesBalanceParamsSchema>, v.InferOutput<typeof getRunesBalanceResultSchema>>;
|
|
507
696
|
|
|
508
697
|
interface Pubkey {
|
|
509
698
|
/**
|
|
@@ -669,22 +858,71 @@ interface DeployContractParams {
|
|
|
669
858
|
}
|
|
670
859
|
type DeployContractResult = TxId & Transaction;
|
|
671
860
|
type StxDeployContract = MethodParamsAndResult<DeployContractParams, DeployContractResult>;
|
|
672
|
-
type
|
|
861
|
+
type StxGetAccountsResult = {
|
|
673
862
|
addresses: Array<Address & PublicKey & {
|
|
674
863
|
gaiaHubUrl: string;
|
|
675
864
|
gaiaAppKey: string;
|
|
676
865
|
}>;
|
|
677
866
|
};
|
|
678
|
-
type StxGetAccounts = MethodParamsAndResult<{},
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
867
|
+
type StxGetAccounts = MethodParamsAndResult<{}, StxGetAccountsResult>;
|
|
868
|
+
declare const stxGetAddressesMethodName = "stx_getAddresses";
|
|
869
|
+
declare const stxGetAddressesParamsSchema: v.NullishSchema<v.ObjectSchema<{
|
|
870
|
+
/**
|
|
871
|
+
* A message to be displayed to the user in the request prompt.
|
|
872
|
+
*/
|
|
873
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
874
|
+
}, undefined>, never>;
|
|
875
|
+
type StxGetAddressesParams = v.InferOutput<typeof stxGetAddressesParamsSchema>;
|
|
876
|
+
declare const stxGetAddressesResultSchema: v.ObjectSchema<{
|
|
877
|
+
/**
|
|
878
|
+
* The addresses generated for the given purposes.
|
|
879
|
+
*/
|
|
880
|
+
readonly addresses: v.ArraySchema<v.ObjectSchema<{
|
|
881
|
+
readonly address: v.StringSchema<undefined>;
|
|
882
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
883
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
884
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
885
|
+
}, undefined>, undefined>;
|
|
886
|
+
}, undefined>;
|
|
887
|
+
type StxGetAddressesResult = v.InferOutput<typeof stxGetAddressesResultSchema>;
|
|
888
|
+
declare const stxGetAddressesRequestMessageSchema: v.ObjectSchema<{
|
|
889
|
+
readonly method: v.LiteralSchema<"stx_getAddresses", undefined>;
|
|
890
|
+
readonly params: v.NullishSchema<v.ObjectSchema<{
|
|
891
|
+
/**
|
|
892
|
+
* A message to be displayed to the user in the request prompt.
|
|
893
|
+
*/
|
|
894
|
+
readonly message: v.OptionalSchema<v.StringSchema<undefined>, never>;
|
|
895
|
+
}, undefined>, never>;
|
|
896
|
+
readonly id: v.StringSchema<undefined>;
|
|
897
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
898
|
+
}, undefined>;
|
|
899
|
+
type StxGetAddressesRequestMessage = v.InferOutput<typeof stxGetAddressesRequestMessageSchema>;
|
|
900
|
+
type StxGetAddresses = MethodParamsAndResult<v.InferOutput<typeof stxGetAddressesParamsSchema>, v.InferOutput<typeof stxGetAddressesResultSchema>>;
|
|
684
901
|
type SignTransactionParams = Transaction & Partial<Pubkey>;
|
|
685
902
|
type SignTransactionResult = Transaction;
|
|
686
903
|
type StxSignTransaction = MethodParamsAndResult<SignTransactionParams, SignTransactionResult>;
|
|
687
904
|
|
|
905
|
+
declare const requestPermissionsMethodName = "wallet_requestPermissions";
|
|
906
|
+
declare const requestPermissionsParamsSchema: v.UndefinedSchema<undefined>;
|
|
907
|
+
declare const requestPermissionsResultSchema: v.LiteralSchema<true, undefined>;
|
|
908
|
+
declare const requestPermissionsRequestMessageSchema: v.ObjectSchema<{
|
|
909
|
+
readonly method: v.LiteralSchema<"wallet_requestPermissions", undefined>;
|
|
910
|
+
readonly params: v.UndefinedSchema<undefined>;
|
|
911
|
+
readonly id: v.StringSchema<undefined>;
|
|
912
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
913
|
+
}, undefined>;
|
|
914
|
+
type RequestPermissions = MethodParamsAndResult<v.InferOutput<typeof requestPermissionsParamsSchema>, v.InferOutput<typeof requestPermissionsResultSchema>>;
|
|
915
|
+
declare const renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
916
|
+
declare const renouncePermissionsParamsSchema: v.UndefinedSchema<undefined>;
|
|
917
|
+
declare const renouncePermissionsResultSchema: v.LiteralSchema<true, undefined>;
|
|
918
|
+
declare const renouncePermissionsRequestMessageSchema: v.ObjectSchema<{
|
|
919
|
+
readonly method: v.LiteralSchema<"wallet_renouncePermissions", undefined>;
|
|
920
|
+
readonly params: v.UndefinedSchema<undefined>;
|
|
921
|
+
readonly id: v.StringSchema<undefined>;
|
|
922
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
923
|
+
}, undefined>;
|
|
924
|
+
type RenouncePermissions = MethodParamsAndResult<v.InferOutput<typeof renouncePermissionsParamsSchema>, v.InferOutput<typeof renouncePermissionsResultSchema>>;
|
|
925
|
+
|
|
688
926
|
interface StxRequests {
|
|
689
927
|
stx_callContract: StxCallContract;
|
|
690
928
|
stx_deployContract: StxDeployContract;
|
|
@@ -700,6 +938,7 @@ interface BtcRequests {
|
|
|
700
938
|
getInfo: GetInfo;
|
|
701
939
|
getAddresses: GetAddresses;
|
|
702
940
|
getAccounts: GetAccounts;
|
|
941
|
+
getBalance: GetBalance;
|
|
703
942
|
signMessage: SignMessage;
|
|
704
943
|
sendTransfer: SendTransfer;
|
|
705
944
|
signPsbt: SignPsbt;
|
|
@@ -716,11 +955,19 @@ interface RunesRequests {
|
|
|
716
955
|
runes_getBalance: GetRunesBalance;
|
|
717
956
|
}
|
|
718
957
|
type RunesRequestMethod = keyof RunesRequests;
|
|
719
|
-
|
|
958
|
+
interface OrdinalsRequests {
|
|
959
|
+
ord_getInscriptions: GetInscriptions;
|
|
960
|
+
}
|
|
961
|
+
type OrdinalsRequestMethod = keyof OrdinalsRequests;
|
|
962
|
+
interface WalletMethods {
|
|
963
|
+
wallet_requestPermissions: RequestPermissions;
|
|
964
|
+
wallet_renouncePermissions: RenouncePermissions;
|
|
965
|
+
}
|
|
966
|
+
type Requests = BtcRequests & StxRequests & RunesRequests & WalletMethods & OrdinalsRequests;
|
|
720
967
|
type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
|
|
721
968
|
type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
|
|
722
969
|
|
|
723
|
-
declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
|
|
970
|
+
declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods | "ord_getInscriptions">(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
|
|
724
971
|
|
|
725
972
|
declare abstract class SatsConnectAdapter {
|
|
726
973
|
abstract readonly id: string;
|
|
@@ -738,10 +985,10 @@ declare abstract class SatsConnectAdapter {
|
|
|
738
985
|
declare class BaseAdapter extends SatsConnectAdapter {
|
|
739
986
|
id: string;
|
|
740
987
|
constructor(providerId: string);
|
|
741
|
-
requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
|
|
988
|
+
requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests | keyof WalletMethods | "ord_getInscriptions">(method: Method, params: Params<Method>) => Promise<RpcResult<Method>>;
|
|
742
989
|
}
|
|
743
990
|
|
|
744
991
|
declare const DefaultAdaptersInfo: Record<string, Provider>;
|
|
745
992
|
declare const defaultAdapters: Record<string, new () => SatsConnectAdapter>;
|
|
746
993
|
|
|
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
|
|
994
|
+
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 EstimateRbfOrder, type EstimateRunesEtch, type EstimateRunesEtchParams, type EstimateRunesEtchResult, type EstimateRunesMint, type EstimateRunesMintParams, type EstimateRunesMintResult, type EtchRunes, type EtchRunesParams, type EtchRunesResult, type GetAccounts, type GetAccountsParams, type GetAccountsRequestMessage, type GetAccountsResult, type GetAddressOptions, type GetAddressPayload, type GetAddressResponse, type GetAddresses, type GetAddressesParams, type GetAddressesRequestMessage, type GetAddressesResult, type GetBalance, type GetCapabilitiesOptions, type GetCapabilitiesPayload, type GetCapabilitiesResponse, type GetInfo, type GetInfoParams, type GetInfoRequestMessage, type GetInfoResult, type GetInscriptions, type GetOrder, type GetRunesBalance, type GetRunesBalanceParams, type GetRunesBalanceRequestMessage, type GetRunesBalanceResult, type InputToSign, type MethodParamsAndResult, type MintRunes, type MintRunesParams, type MintRunesResult, type OrdinalsRequestMethod, type OrdinalsRequests, type Params, type Provider, type PsbtPayload, type RbfOrder, type Recipient$2 as Recipient, type RenouncePermissions, type RequestOptions, type RequestPayload, type RequestPermissions, type Requests, type Return, type RpcBase, type RpcError, RpcErrorCode, type RpcErrorResponse, type RpcErrorResponseMessage, type RpcId, RpcIdSchema, type RpcRequest, type RpcRequestMessage, type RpcResponse, type RpcResponseMessage, type RpcResult, type RpcSuccessResponse, type RpcSuccessResponseMessage, 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 SignMessageRequestMessage, type SignMessageResponse, type SignMessageResult, 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 StxGetAccountsResult, type StxGetAddresses, type StxGetAddressesParams, type StxGetAddressesRequestMessage, type StxGetAddressesResult, type StxRequestMethod, type StxRequests, type StxSignStructuredMessage, type StxSignStxMessage, type StxSignTransaction, type StxTransferStx, type SupportedWallet, type TransferStxParams, type TransferStxResult, type WalletMethods, addressSchema, createInscription, createRepeatInscriptions, defaultAdapters, getAccountsMethodName, getAccountsParamsSchema, getAccountsRequestMessageSchema, getAccountsResultSchema, getAddress, getAddressesMethodName, getAddressesParamsSchema, getAddressesRequestMessageSchema, getAddressesResultSchema, getBalanceMethodName, getBalanceParamsSchema, getBalanceRequestMessageSchema, getBalanceResultSchema, getCapabilities, getDefaultProvider, getInfoMethodName, getInfoParamsSchema, getInfoRequestMessageSchema, getInfoResultSchema, getInscriptionsMethodName, getInscriptionsParamsSchema, getInscriptionsResultSchema, getInscriptionsSchema, getProviderById, getProviderOrThrow, getProviders, getRunesBalanceMethodName, getRunesBalanceParamsSchema, getRunesBalanceRequestMessageSchema, getRunesBalanceResultSchema, getSupportedWallets, isProviderInstalled, removeDefaultProvider, renouncePermissionsMethodName, renouncePermissionsParamsSchema, renouncePermissionsRequestMessageSchema, renouncePermissionsResultSchema, request, requestPermissionsMethodName, requestPermissionsParamsSchema, requestPermissionsRequestMessageSchema, requestPermissionsResultSchema, rpcErrorResponseMessageSchema, rpcRequestMessageSchema, rpcResponseMessageSchema, rpcSuccessResponseMessageSchema, sendBtcTransaction, setDefaultProvider, signMessage, signMessageMethodName, signMessageParamsSchema, signMessageRequestMessageSchema, signMessageResultSchema, signMultipleTransactions, signTransaction, stxGetAddressesMethodName, stxGetAddressesParamsSchema, stxGetAddressesRequestMessageSchema, stxGetAddressesResultSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
// src/types.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType3) => {
|
|
4
|
+
BitcoinNetworkType3["Mainnet"] = "Mainnet";
|
|
5
|
+
BitcoinNetworkType3["Testnet"] = "Testnet";
|
|
6
|
+
BitcoinNetworkType3["Signet"] = "Signet";
|
|
7
|
+
return BitcoinNetworkType3;
|
|
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.nonOptional(v.unknown()),
|
|
40
|
+
id: RpcIdSchema
|
|
41
|
+
});
|
|
42
|
+
var rpcErrorResponseMessageSchema = v.object({
|
|
43
|
+
jsonrpc: v.literal("2.0"),
|
|
44
|
+
error: v.nonOptional(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,6 +202,16 @@ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
|
169
202
|
var SatsConnectAdapter = class {
|
|
170
203
|
async mintRunes(params) {
|
|
171
204
|
try {
|
|
205
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
206
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
207
|
+
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
208
|
+
if (isMintSupported) {
|
|
209
|
+
const response = await this.requestInternal("runes_mint", params);
|
|
210
|
+
if (response) {
|
|
211
|
+
return response;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
172
215
|
const mintRequest = {
|
|
173
216
|
destinationAddress: params.destinationAddress,
|
|
174
217
|
feeRate: params.feeRate,
|
|
@@ -238,6 +281,16 @@ var SatsConnectAdapter = class {
|
|
|
238
281
|
appServiceFeeAddress: params.appServiceFeeAddress
|
|
239
282
|
};
|
|
240
283
|
try {
|
|
284
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
285
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
286
|
+
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
287
|
+
if (isEtchSupported) {
|
|
288
|
+
const response = await this.requestInternal("runes_etch", params);
|
|
289
|
+
if (response) {
|
|
290
|
+
return response;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
241
294
|
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
242
295
|
if (!orderResponse.data) {
|
|
243
296
|
return {
|
|
@@ -493,49 +546,13 @@ function getSupportedWallets() {
|
|
|
493
546
|
}
|
|
494
547
|
|
|
495
548
|
// src/request/index.ts
|
|
496
|
-
|
|
497
|
-
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
498
|
-
if (providerId) {
|
|
499
|
-
provider = await getProviderById(providerId);
|
|
500
|
-
}
|
|
501
|
-
if (!provider) {
|
|
502
|
-
throw new Error("no wallet provider was found");
|
|
503
|
-
}
|
|
504
|
-
if (!method) {
|
|
505
|
-
throw new Error("A wallet method is required");
|
|
506
|
-
}
|
|
507
|
-
const response = await provider.request(method, params);
|
|
508
|
-
if (isRpcSuccessResponse(response)) {
|
|
509
|
-
return {
|
|
510
|
-
status: "success",
|
|
511
|
-
result: response.result
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
status: "error",
|
|
516
|
-
error: response.error
|
|
517
|
-
};
|
|
518
|
-
};
|
|
519
|
-
var isRpcSuccessResponse = (response) => {
|
|
520
|
-
return Object.hasOwn(response, "result") && !!response.result;
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
// src/adapters/xverse.ts
|
|
524
|
-
var XverseAdapter = class extends SatsConnectAdapter {
|
|
525
|
-
id = DefaultAdaptersInfo.xverse.id;
|
|
526
|
-
requestInternal = async (method, params) => {
|
|
527
|
-
return request(method, params, this.id);
|
|
528
|
-
};
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
// src/adapters/unisat.ts
|
|
532
|
-
import { Buffer } from "buffer";
|
|
533
|
-
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
549
|
+
import * as v8 from "valibot";
|
|
534
550
|
|
|
535
551
|
// src/addresses/index.ts
|
|
536
552
|
import { createUnsecuredToken } from "jsontokens";
|
|
537
553
|
|
|
538
554
|
// src/addresses/types.ts
|
|
555
|
+
import * as v2 from "valibot";
|
|
539
556
|
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
540
557
|
AddressPurpose2["Ordinals"] = "ordinals";
|
|
541
558
|
AddressPurpose2["Payment"] = "payment";
|
|
@@ -551,6 +568,12 @@ var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
|
551
568
|
AddressType3["stacks"] = "stacks";
|
|
552
569
|
return AddressType3;
|
|
553
570
|
})(AddressType || {});
|
|
571
|
+
var addressSchema = v2.object({
|
|
572
|
+
address: v2.string(),
|
|
573
|
+
publicKey: v2.string(),
|
|
574
|
+
purpose: v2.enum(AddressPurpose),
|
|
575
|
+
addressType: v2.enum(AddressType)
|
|
576
|
+
});
|
|
554
577
|
|
|
555
578
|
// src/addresses/index.ts
|
|
556
579
|
var getAddress = async (options) => {
|
|
@@ -569,7 +592,286 @@ var getAddress = async (options) => {
|
|
|
569
592
|
}
|
|
570
593
|
};
|
|
571
594
|
|
|
595
|
+
// src/request/types/stxMethods.ts
|
|
596
|
+
import * as v3 from "valibot";
|
|
597
|
+
var stxGetAddressesMethodName = "stx_getAddresses";
|
|
598
|
+
var stxGetAddressesParamsSchema = v3.nullish(
|
|
599
|
+
v3.object({
|
|
600
|
+
/**
|
|
601
|
+
* A message to be displayed to the user in the request prompt.
|
|
602
|
+
*/
|
|
603
|
+
message: v3.optional(v3.string())
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
var stxGetAddressesResultSchema = v3.object({
|
|
607
|
+
/**
|
|
608
|
+
* The addresses generated for the given purposes.
|
|
609
|
+
*/
|
|
610
|
+
addresses: v3.array(addressSchema)
|
|
611
|
+
});
|
|
612
|
+
var stxGetAddressesRequestMessageSchema = v3.object({
|
|
613
|
+
...rpcRequestMessageSchema.entries,
|
|
614
|
+
...v3.object({
|
|
615
|
+
method: v3.literal(stxGetAddressesMethodName),
|
|
616
|
+
params: stxGetAddressesParamsSchema,
|
|
617
|
+
id: v3.string()
|
|
618
|
+
}).entries
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
// src/request/types/btcMethods.ts
|
|
622
|
+
import * as v4 from "valibot";
|
|
623
|
+
var getInfoMethodName = "getInfo";
|
|
624
|
+
var getInfoParamsSchema = v4.nullish(v4.null());
|
|
625
|
+
var getInfoResultSchema = v4.object({
|
|
626
|
+
/**
|
|
627
|
+
* Version of the wallet.
|
|
628
|
+
*/
|
|
629
|
+
version: v4.string(),
|
|
630
|
+
/**
|
|
631
|
+
* [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
|
|
632
|
+
*/
|
|
633
|
+
methods: v4.optional(v4.array(v4.string())),
|
|
634
|
+
/**
|
|
635
|
+
* List of WBIP standards supported by the wallet. Not currently used.
|
|
636
|
+
*/
|
|
637
|
+
supports: v4.array(v4.string())
|
|
638
|
+
});
|
|
639
|
+
var getInfoRequestMessageSchema = v4.object({
|
|
640
|
+
...rpcRequestMessageSchema.entries,
|
|
641
|
+
...v4.object({
|
|
642
|
+
method: v4.literal(getInfoMethodName),
|
|
643
|
+
params: getInfoParamsSchema,
|
|
644
|
+
id: v4.string()
|
|
645
|
+
}).entries
|
|
646
|
+
});
|
|
647
|
+
var getAddressesMethodName = "getAddresses";
|
|
648
|
+
var getAddressesParamsSchema = v4.object({
|
|
649
|
+
/**
|
|
650
|
+
* The purposes for which to generate addresses. See
|
|
651
|
+
* {@linkcode AddressPurpose} for available purposes.
|
|
652
|
+
*/
|
|
653
|
+
purposes: v4.array(v4.enum(AddressPurpose)),
|
|
654
|
+
/**
|
|
655
|
+
* A message to be displayed to the user in the request prompt.
|
|
656
|
+
*/
|
|
657
|
+
message: v4.optional(v4.string())
|
|
658
|
+
});
|
|
659
|
+
var getAddressesResultSchema = v4.object({
|
|
660
|
+
/**
|
|
661
|
+
* The addresses generated for the given purposes.
|
|
662
|
+
*/
|
|
663
|
+
addresses: v4.array(addressSchema)
|
|
664
|
+
});
|
|
665
|
+
var getAddressesRequestMessageSchema = v4.object({
|
|
666
|
+
...rpcRequestMessageSchema.entries,
|
|
667
|
+
...v4.object({
|
|
668
|
+
method: v4.literal(getAddressesMethodName),
|
|
669
|
+
params: getAddressesParamsSchema,
|
|
670
|
+
id: v4.string()
|
|
671
|
+
}).entries
|
|
672
|
+
});
|
|
673
|
+
var signMessageMethodName = "signMessage";
|
|
674
|
+
var signMessageParamsSchema = v4.object({
|
|
675
|
+
/**
|
|
676
|
+
* The address used for signing.
|
|
677
|
+
**/
|
|
678
|
+
address: v4.string(),
|
|
679
|
+
/**
|
|
680
|
+
* The message to sign.
|
|
681
|
+
**/
|
|
682
|
+
message: v4.string()
|
|
683
|
+
});
|
|
684
|
+
var signMessageResultSchema = v4.object({
|
|
685
|
+
/**
|
|
686
|
+
* The signature of the message.
|
|
687
|
+
*/
|
|
688
|
+
signature: v4.string(),
|
|
689
|
+
/**
|
|
690
|
+
* hash of the message.
|
|
691
|
+
*/
|
|
692
|
+
messageHash: v4.string(),
|
|
693
|
+
/**
|
|
694
|
+
* The address used for signing.
|
|
695
|
+
*/
|
|
696
|
+
address: v4.string()
|
|
697
|
+
});
|
|
698
|
+
var signMessageRequestMessageSchema = v4.object({
|
|
699
|
+
...rpcRequestMessageSchema.entries,
|
|
700
|
+
...v4.object({
|
|
701
|
+
method: v4.literal(signMessageMethodName),
|
|
702
|
+
params: signMessageParamsSchema,
|
|
703
|
+
id: v4.string()
|
|
704
|
+
}).entries
|
|
705
|
+
});
|
|
706
|
+
var getAccountsMethodName = "getAccounts";
|
|
707
|
+
var getAccountsParamsSchema = getAddressesParamsSchema;
|
|
708
|
+
var getAccountsResultSchema = v4.array(addressSchema);
|
|
709
|
+
var getAccountsRequestMessageSchema = v4.object({
|
|
710
|
+
...rpcRequestMessageSchema.entries,
|
|
711
|
+
...v4.object({
|
|
712
|
+
method: v4.literal(getAccountsMethodName),
|
|
713
|
+
params: getAccountsParamsSchema,
|
|
714
|
+
id: v4.string()
|
|
715
|
+
}).entries
|
|
716
|
+
});
|
|
717
|
+
var getBalanceMethodName = "getBalance";
|
|
718
|
+
var getBalanceParamsSchema = v4.nullish(v4.null());
|
|
719
|
+
var getBalanceResultSchema = v4.object({
|
|
720
|
+
/**
|
|
721
|
+
* The confirmed balance of the wallet in sats. Using a string due to chrome
|
|
722
|
+
* messages not supporting bigint
|
|
723
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
724
|
+
*/
|
|
725
|
+
confirmed: v4.string(),
|
|
726
|
+
/**
|
|
727
|
+
* The unconfirmed balance of the wallet in sats. Using a string due to chrome
|
|
728
|
+
* messages not supporting bigint
|
|
729
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
730
|
+
*/
|
|
731
|
+
unconfirmed: v4.string(),
|
|
732
|
+
/**
|
|
733
|
+
* The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
|
|
734
|
+
* sats. Using a string due to chrome messages not supporting bigint
|
|
735
|
+
* (https://issues.chromium.org/issues/40116184).
|
|
736
|
+
*/
|
|
737
|
+
total: v4.string()
|
|
738
|
+
});
|
|
739
|
+
var getBalanceRequestMessageSchema = v4.object({
|
|
740
|
+
...rpcRequestMessageSchema.entries,
|
|
741
|
+
...v4.object({
|
|
742
|
+
method: v4.literal(getBalanceMethodName),
|
|
743
|
+
id: v4.string()
|
|
744
|
+
}).entries
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// src/request/types/walletMethods.ts
|
|
748
|
+
import * as v5 from "valibot";
|
|
749
|
+
var requestPermissionsMethodName = "wallet_requestPermissions";
|
|
750
|
+
var requestPermissionsParamsSchema = v5.undefined();
|
|
751
|
+
var requestPermissionsResultSchema = v5.literal(true);
|
|
752
|
+
var requestPermissionsRequestMessageSchema = v5.object({
|
|
753
|
+
...rpcRequestMessageSchema.entries,
|
|
754
|
+
...v5.object({
|
|
755
|
+
method: v5.literal(requestPermissionsMethodName),
|
|
756
|
+
params: requestPermissionsParamsSchema,
|
|
757
|
+
id: v5.string()
|
|
758
|
+
}).entries
|
|
759
|
+
});
|
|
760
|
+
var renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
761
|
+
var renouncePermissionsParamsSchema = v5.undefined();
|
|
762
|
+
var renouncePermissionsResultSchema = v5.literal(true);
|
|
763
|
+
var renouncePermissionsRequestMessageSchema = v5.object({
|
|
764
|
+
...rpcRequestMessageSchema.entries,
|
|
765
|
+
...v5.object({
|
|
766
|
+
method: v5.literal(renouncePermissionsMethodName),
|
|
767
|
+
params: renouncePermissionsParamsSchema,
|
|
768
|
+
id: v5.string()
|
|
769
|
+
}).entries
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
// src/request/types/runesMethods.ts
|
|
773
|
+
import * as v6 from "valibot";
|
|
774
|
+
var getRunesBalanceMethodName = "runes_getBalance";
|
|
775
|
+
var getRunesBalanceParamsSchema = v6.nullish(v6.null());
|
|
776
|
+
var getRunesBalanceResultSchema = v6.object({
|
|
777
|
+
balances: v6.array(
|
|
778
|
+
v6.object({
|
|
779
|
+
runeName: v6.string(),
|
|
780
|
+
amount: v6.string(),
|
|
781
|
+
divisibility: v6.number(),
|
|
782
|
+
symbol: v6.string(),
|
|
783
|
+
inscriptionId: v6.nullish(v6.string())
|
|
784
|
+
})
|
|
785
|
+
)
|
|
786
|
+
});
|
|
787
|
+
var getRunesBalanceRequestMessageSchema = v6.object({
|
|
788
|
+
...rpcRequestMessageSchema.entries,
|
|
789
|
+
...v6.object({
|
|
790
|
+
method: v6.literal(getRunesBalanceMethodName),
|
|
791
|
+
params: getRunesBalanceParamsSchema,
|
|
792
|
+
id: v6.string()
|
|
793
|
+
}).entries
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
// src/request/types/ordinalsMethods.ts
|
|
797
|
+
import * as v7 from "valibot";
|
|
798
|
+
var getInscriptionsMethodName = "ord_getInscriptions";
|
|
799
|
+
var getInscriptionsParamsSchema = v7.object({
|
|
800
|
+
offset: v7.number(),
|
|
801
|
+
limit: v7.number()
|
|
802
|
+
});
|
|
803
|
+
var getInscriptionsResultSchema = v7.object({
|
|
804
|
+
inscriptions: v7.array(
|
|
805
|
+
v7.object({
|
|
806
|
+
inscriptionId: v7.string(),
|
|
807
|
+
inscriptionNumber: v7.string(),
|
|
808
|
+
address: v7.string(),
|
|
809
|
+
collectionName: v7.optional(v7.string()),
|
|
810
|
+
postage: v7.string(),
|
|
811
|
+
contentLength: v7.string(),
|
|
812
|
+
contentType: v7.string(),
|
|
813
|
+
timestamp: v7.number(),
|
|
814
|
+
offset: v7.number(),
|
|
815
|
+
genesisTransaction: v7.string(),
|
|
816
|
+
output: v7.string()
|
|
817
|
+
})
|
|
818
|
+
)
|
|
819
|
+
});
|
|
820
|
+
var getInscriptionsSchema = v7.object({
|
|
821
|
+
...rpcRequestMessageSchema.entries,
|
|
822
|
+
...v7.object({
|
|
823
|
+
method: v7.literal(getInscriptionsMethodName),
|
|
824
|
+
params: getInscriptionsParamsSchema,
|
|
825
|
+
id: v7.string()
|
|
826
|
+
}).entries
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// src/request/index.ts
|
|
830
|
+
var request = async (method, params, providerId) => {
|
|
831
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
832
|
+
if (providerId) {
|
|
833
|
+
provider = await getProviderById(providerId);
|
|
834
|
+
}
|
|
835
|
+
if (!provider) {
|
|
836
|
+
throw new Error("no wallet provider was found");
|
|
837
|
+
}
|
|
838
|
+
if (!method) {
|
|
839
|
+
throw new Error("A wallet method is required");
|
|
840
|
+
}
|
|
841
|
+
const response = await provider.request(method, params);
|
|
842
|
+
if (v8.is(rpcErrorResponseMessageSchema, response)) {
|
|
843
|
+
return {
|
|
844
|
+
status: "error",
|
|
845
|
+
error: response.error
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
if (v8.is(rpcSuccessResponseMessageSchema, response)) {
|
|
849
|
+
return {
|
|
850
|
+
status: "success",
|
|
851
|
+
result: response.result
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
return {
|
|
855
|
+
status: "error",
|
|
856
|
+
error: {
|
|
857
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
858
|
+
message: "Received unknown response from provider.",
|
|
859
|
+
data: response
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
// src/adapters/xverse.ts
|
|
865
|
+
var XverseAdapter = class extends SatsConnectAdapter {
|
|
866
|
+
id = DefaultAdaptersInfo.xverse.id;
|
|
867
|
+
requestInternal = async (method, params) => {
|
|
868
|
+
return request(method, params, this.id);
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
|
|
572
872
|
// src/adapters/unisat.ts
|
|
873
|
+
import { Buffer } from "buffer";
|
|
874
|
+
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
573
875
|
function convertSignInputsToInputType(signInputs, allowedSignHash) {
|
|
574
876
|
let result = [];
|
|
575
877
|
for (let address in signInputs) {
|
|
@@ -973,23 +1275,69 @@ export {
|
|
|
973
1275
|
BitcoinNetworkType,
|
|
974
1276
|
DefaultAdaptersInfo,
|
|
975
1277
|
RpcErrorCode,
|
|
1278
|
+
RpcIdSchema,
|
|
976
1279
|
SatsConnectAdapter,
|
|
1280
|
+
addressSchema,
|
|
977
1281
|
createInscription,
|
|
978
1282
|
createRepeatInscriptions,
|
|
979
1283
|
defaultAdapters,
|
|
1284
|
+
getAccountsMethodName,
|
|
1285
|
+
getAccountsParamsSchema,
|
|
1286
|
+
getAccountsRequestMessageSchema,
|
|
1287
|
+
getAccountsResultSchema,
|
|
980
1288
|
getAddress,
|
|
1289
|
+
getAddressesMethodName,
|
|
1290
|
+
getAddressesParamsSchema,
|
|
1291
|
+
getAddressesRequestMessageSchema,
|
|
1292
|
+
getAddressesResultSchema,
|
|
1293
|
+
getBalanceMethodName,
|
|
1294
|
+
getBalanceParamsSchema,
|
|
1295
|
+
getBalanceRequestMessageSchema,
|
|
1296
|
+
getBalanceResultSchema,
|
|
981
1297
|
getCapabilities,
|
|
982
1298
|
getDefaultProvider,
|
|
1299
|
+
getInfoMethodName,
|
|
1300
|
+
getInfoParamsSchema,
|
|
1301
|
+
getInfoRequestMessageSchema,
|
|
1302
|
+
getInfoResultSchema,
|
|
1303
|
+
getInscriptionsMethodName,
|
|
1304
|
+
getInscriptionsParamsSchema,
|
|
1305
|
+
getInscriptionsResultSchema,
|
|
1306
|
+
getInscriptionsSchema,
|
|
983
1307
|
getProviderById,
|
|
984
1308
|
getProviderOrThrow,
|
|
985
1309
|
getProviders,
|
|
1310
|
+
getRunesBalanceMethodName,
|
|
1311
|
+
getRunesBalanceParamsSchema,
|
|
1312
|
+
getRunesBalanceRequestMessageSchema,
|
|
1313
|
+
getRunesBalanceResultSchema,
|
|
986
1314
|
getSupportedWallets,
|
|
987
1315
|
isProviderInstalled,
|
|
988
1316
|
removeDefaultProvider,
|
|
1317
|
+
renouncePermissionsMethodName,
|
|
1318
|
+
renouncePermissionsParamsSchema,
|
|
1319
|
+
renouncePermissionsRequestMessageSchema,
|
|
1320
|
+
renouncePermissionsResultSchema,
|
|
989
1321
|
request,
|
|
1322
|
+
requestPermissionsMethodName,
|
|
1323
|
+
requestPermissionsParamsSchema,
|
|
1324
|
+
requestPermissionsRequestMessageSchema,
|
|
1325
|
+
requestPermissionsResultSchema,
|
|
1326
|
+
rpcErrorResponseMessageSchema,
|
|
1327
|
+
rpcRequestMessageSchema,
|
|
1328
|
+
rpcResponseMessageSchema,
|
|
1329
|
+
rpcSuccessResponseMessageSchema,
|
|
990
1330
|
sendBtcTransaction,
|
|
991
1331
|
setDefaultProvider,
|
|
992
1332
|
signMessage,
|
|
1333
|
+
signMessageMethodName,
|
|
1334
|
+
signMessageParamsSchema,
|
|
1335
|
+
signMessageRequestMessageSchema,
|
|
1336
|
+
signMessageResultSchema,
|
|
993
1337
|
signMultipleTransactions,
|
|
994
|
-
signTransaction
|
|
1338
|
+
signTransaction,
|
|
1339
|
+
stxGetAddressesMethodName,
|
|
1340
|
+
stxGetAddressesParamsSchema,
|
|
1341
|
+
stxGetAddressesRequestMessageSchema,
|
|
1342
|
+
stxGetAddressesResultSchema
|
|
995
1343
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-connect/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12-635f56e",
|
|
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": "
|
|
49
|
+
"typescript": "5.4.5",
|
|
46
50
|
"util": "^0.12.4",
|
|
47
51
|
"vm-browserify": "^1.1.2",
|
|
48
52
|
"webpack": "^5.74.0",
|