@sats-connect/core 0.4.0-e7d3e8d → 0.4.0-ff58e17

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.mjs CHANGED
@@ -1,6 +1,3 @@
1
- // src/provider/index.ts
2
- import omit from "lodash.omit";
3
-
4
1
  // src/provider/types.ts
5
2
  import * as v from "valibot";
6
3
  var accountChangeEventName = "accountChange";
@@ -50,11 +47,9 @@ function removeDefaultProvider() {
50
47
  localStorage.removeItem("sats-connect_defaultProvider");
51
48
  }
52
49
  function getSupportedWallets() {
53
- const btc_providers = getProviders();
54
- const allProviders = [...btc_providers];
55
- for (const key in omit(DefaultAdaptersInfo, ["xverse"])) {
56
- allProviders.push(DefaultAdaptersInfo[key]);
57
- }
50
+ const ambientProviders = getProviders();
51
+ const { xverse, ...defaultProviders } = DefaultAdaptersInfo;
52
+ const allProviders = [...ambientProviders, ...Object.values(defaultProviders)];
58
53
  const wallets = allProviders.map((provider) => {
59
54
  {
60
55
  return {
@@ -120,6 +115,9 @@ var rpcResponseMessageSchema = v2.union([
120
115
  // src/request/index.ts
121
116
  import * as v10 from "valibot";
122
117
 
118
+ // src/request/types/stxMethods.ts
119
+ import * as v4 from "valibot";
120
+
123
121
  // src/addresses/index.ts
124
122
  import { createUnsecuredToken } from "jsontokens";
125
123
 
@@ -165,7 +163,55 @@ var getAddress = async (options) => {
165
163
  };
166
164
 
167
165
  // src/request/types/stxMethods.ts
168
- import * as v4 from "valibot";
166
+ var stxCallContractMethodName = "stx_callContract";
167
+ var stxCallContractParamsSchema = v4.object({
168
+ /**
169
+ * The contract principal.
170
+ *
171
+ * E.g. `"SPKE...GD5C.my-contract"`
172
+ */
173
+ contract: v4.string(),
174
+ /**
175
+ * The name of the function to call.
176
+ *
177
+ * Note: spec changes ongoing,
178
+ * https://github.com/stacksgov/sips/pull/166#pullrequestreview-1914236999
179
+ */
180
+ functionName: v4.string(),
181
+ /**
182
+ * The function's arguments. The arguments are expected to be hex-encoded
183
+ * strings of Clarity values.
184
+ *
185
+ * To convert Clarity values to their hex representation, the `cvToString`
186
+ * helper from the `@stacks/transactions` package may be helpful.
187
+ *
188
+ * ```js
189
+ * import { cvToString } from '@stacks/transactions';
190
+ *
191
+ * const functionArgs = [someClarityValue1, someClarityValue2];
192
+ * const hexArgs = functionArgs.map(cvToString);
193
+ * ```
194
+ */
195
+ arguments: v4.optional(v4.array(v4.string()))
196
+ });
197
+ var stxCallContractResultSchema = v4.object({
198
+ /**
199
+ * The ID of the transaction.
200
+ */
201
+ txid: v4.string(),
202
+ /**
203
+ * A Stacks transaction as a hex-encoded string.
204
+ */
205
+ transaction: v4.string()
206
+ });
207
+ var stxCallContractRequestMessageSchema = v4.object({
208
+ ...rpcRequestMessageSchema.entries,
209
+ ...v4.object({
210
+ method: v4.literal(stxCallContractMethodName),
211
+ params: stxCallContractParamsSchema,
212
+ id: v4.string()
213
+ }).entries
214
+ });
169
215
  var stxGetAddressesMethodName = "stx_getAddresses";
170
216
  var stxGetAddressesParamsSchema = v4.nullish(
171
217
  v4.object({
@@ -325,6 +371,69 @@ var signMessageRequestMessageSchema = v6.object({
325
371
  id: v6.string()
326
372
  }).entries
327
373
  });
374
+ var sendTransferMethodName = "sendTransfer";
375
+ var sendTransferParamsSchema = v6.object({
376
+ /**
377
+ * Array of recipients to send to.
378
+ * The amount to send to each recipient is in satoshis.
379
+ */
380
+ recipients: v6.array(
381
+ v6.object({
382
+ address: v6.string(),
383
+ amount: v6.number()
384
+ })
385
+ )
386
+ });
387
+ var sendTransferResultSchema = v6.object({
388
+ /**
389
+ * The transaction id as a hex-encoded string.
390
+ */
391
+ txid: v6.string()
392
+ });
393
+ var sendTransferRequestMessageSchema = v6.object({
394
+ ...rpcRequestMessageSchema.entries,
395
+ ...v6.object({
396
+ method: v6.literal(sendTransferMethodName),
397
+ params: sendTransferParamsSchema,
398
+ id: v6.string()
399
+ }).entries
400
+ });
401
+ var signPsbtMethodName = "signPsbt";
402
+ var signPsbtParamsSchema = v6.object({
403
+ /**
404
+ * The base64 encoded PSBT to sign.
405
+ */
406
+ psbt: v6.string(),
407
+ /**
408
+ * The inputs to sign.
409
+ * The key is the address and the value is an array of indexes of the inputs to sign.
410
+ */
411
+ signInputs: v6.record(v6.string(), v6.array(v6.number())),
412
+ allowedSignHash: v6.optional(v6.number()),
413
+ /**
414
+ * Whether to broadcast the transaction after signing.
415
+ **/
416
+ broadcast: v6.optional(v6.boolean())
417
+ });
418
+ var signPsbtResultSchema = v6.object({
419
+ /**
420
+ * The base64 encoded PSBT after signing.
421
+ */
422
+ psbt: v6.string(),
423
+ /**
424
+ * The transaction id as a hex-encoded string.
425
+ * This is only returned if the transaction was broadcast.
426
+ **/
427
+ txid: v6.optional(v6.string())
428
+ });
429
+ var signPsbtRequestMessageSchema = v6.object({
430
+ ...rpcRequestMessageSchema.entries,
431
+ ...v6.object({
432
+ method: v6.literal(signPsbtMethodName),
433
+ params: signPsbtParamsSchema,
434
+ id: v6.string()
435
+ }).entries
436
+ });
328
437
  var getAccountsMethodName = "getAccounts";
329
438
  var getAccountsParamsSchema = v6.object({
330
439
  /**
@@ -385,8 +494,19 @@ var getBalanceRequestMessageSchema = v6.object({
385
494
 
386
495
  // src/request/types/walletMethods.ts
387
496
  import * as v7 from "valibot";
497
+ import { permissions } from "@secretkeylabs/xverse-core";
498
+ var permissionTemplate = v7.variant("type", [
499
+ v7.object({
500
+ ...v7.omit(permissions.resources.account.accountPermissionSchema, ["clientId", "actions"]).entries,
501
+ actions: v7.partial(permissions.resources.account.accountActionsSchema)
502
+ }),
503
+ v7.object({
504
+ ...v7.omit(permissions.resources.wallet.walletPermissionSchema, ["clientId"]).entries,
505
+ actions: v7.partial(permissions.resources.wallet.walletActionsSchema)
506
+ })
507
+ ]);
388
508
  var requestPermissionsMethodName = "wallet_requestPermissions";
389
- var requestPermissionsParamsSchema = v7.undefined();
509
+ var requestPermissionsParamsSchema = v7.nullish(v7.array(permissionTemplate));
390
510
  var requestPermissionsResultSchema = v7.literal(true);
391
511
  var requestPermissionsRequestMessageSchema = v7.object({
392
512
  ...rpcRequestMessageSchema.entries,
@@ -397,8 +517,8 @@ var requestPermissionsRequestMessageSchema = v7.object({
397
517
  }).entries
398
518
  });
399
519
  var renouncePermissionsMethodName = "wallet_renouncePermissions";
400
- var renouncePermissionsParamsSchema = v7.undefined();
401
- var renouncePermissionsResultSchema = v7.literal(true);
520
+ var renouncePermissionsParamsSchema = v7.nullish(v7.null());
521
+ var renouncePermissionsResultSchema = v7.nullish(v7.null());
402
522
  var renouncePermissionsRequestMessageSchema = v7.object({
403
523
  ...rpcRequestMessageSchema.entries,
404
524
  ...v7.object({
@@ -407,6 +527,17 @@ var renouncePermissionsRequestMessageSchema = v7.object({
407
527
  id: v7.string()
408
528
  }).entries
409
529
  });
530
+ var disconnectMethodName = "wallet_disconnect";
531
+ var disconnectParamsSchema = v7.nullish(v7.null());
532
+ var disconnectResultSchema = v7.nullish(v7.null());
533
+ var disconnectRequestMessageSchema = v7.object({
534
+ ...rpcRequestMessageSchema.entries,
535
+ ...v7.object({
536
+ method: v7.literal(disconnectMethodName),
537
+ params: disconnectParamsSchema,
538
+ id: v7.string()
539
+ }).entries
540
+ });
410
541
  var getWalletTypeMethodName = "wallet_getWalletType";
411
542
  var getWalletTypeParamsSchema = v7.nullish(v7.null());
412
543
  var getWalletTypeResultSchema = walletTypeSchema;
@@ -414,16 +545,48 @@ var getWalletTypeRequestMessageSchema = v7.object({
414
545
  ...rpcRequestMessageSchema.entries,
415
546
  ...v7.object({
416
547
  method: v7.literal(getWalletTypeMethodName),
548
+ params: getWalletTypeParamsSchema,
417
549
  id: v7.string()
418
550
  }).entries
419
551
  });
420
552
  var getCurrentPermissionsMethodName = "wallet_getCurrentPermissions";
421
553
  var getCurrentPermissionsParamsSchema = v7.nullish(v7.null());
422
- var getCurrentPermissionsResultSchema = v7.array(v7.string());
554
+ var getCurrentPermissionsResultSchema = v7.array(permissions.store.permission);
423
555
  var getCurrentPermissionsRequestMessageSchema = v7.object({
424
556
  ...rpcRequestMessageSchema.entries,
425
557
  ...v7.object({
426
558
  method: v7.literal(getCurrentPermissionsMethodName),
559
+ params: getCurrentPermissionsParamsSchema,
560
+ id: v7.string()
561
+ }).entries
562
+ });
563
+ var getAccountMethodName = "wallet_getAccount";
564
+ var getAccountParamsSchema = v7.nullish(v7.null());
565
+ var getAccountResultSchema = v7.object({
566
+ id: permissions.utils.account.accountIdSchema,
567
+ addresses: v7.array(addressSchema),
568
+ walletType: walletTypeSchema
569
+ });
570
+ var getAccountRequestMessageSchema = v7.object({
571
+ ...rpcRequestMessageSchema.entries,
572
+ ...v7.object({
573
+ method: v7.literal(getAccountMethodName),
574
+ params: getAccountParamsSchema,
575
+ id: v7.string()
576
+ }).entries
577
+ });
578
+ var connectMethodName = "wallet_connect";
579
+ var connectParamsSchema = v7.nullish(
580
+ v7.object({
581
+ permissions: v7.optional(v7.array(permissionTemplate))
582
+ })
583
+ );
584
+ var connectResultSchema = getAccountResultSchema;
585
+ var connectRequestMessageSchema = v7.object({
586
+ ...rpcRequestMessageSchema.entries,
587
+ ...v7.object({
588
+ method: v7.literal(connectMethodName),
589
+ params: connectParamsSchema,
427
590
  id: v7.string()
428
591
  }).entries
429
592
  });
@@ -1059,17 +1222,16 @@ var XverseAdapter = class extends SatsConnectAdapter {
1059
1222
  };
1060
1223
 
1061
1224
  // src/adapters/unisat.ts
1062
- import { Buffer } from "buffer";
1063
1225
  import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
1064
- function convertSignInputsToInputType(signInputs, allowedSignHash) {
1226
+ import { Buffer } from "buffer";
1227
+ function convertSignInputsToInputType(signInputs) {
1065
1228
  let result = [];
1066
1229
  for (let address in signInputs) {
1067
1230
  let indexes = signInputs[address];
1068
1231
  for (let index of indexes) {
1069
1232
  result.push({
1070
1233
  index,
1071
- address,
1072
- sighashTypes: allowedSignHash ? [allowedSignHash] : void 0
1234
+ address
1073
1235
  });
1074
1236
  }
1075
1237
  }
@@ -1101,10 +1263,10 @@ var UnisatAdapter = class extends SatsConnectAdapter {
1101
1263
  };
1102
1264
  const response = [];
1103
1265
  if (purposes.includes("payment" /* Payment */)) {
1104
- response.push(paymentAddress);
1266
+ response.push({ ...paymentAddress, walletType: "software" });
1105
1267
  }
1106
1268
  if (purposes.includes("ordinals" /* Ordinals */)) {
1107
- response.push(ordinalsAddress);
1269
+ response.push({ ...ordinalsAddress, walletType: "software" });
1108
1270
  }
1109
1271
  return response;
1110
1272
  }
@@ -1117,14 +1279,16 @@ var UnisatAdapter = class extends SatsConnectAdapter {
1117
1279
  return {
1118
1280
  address,
1119
1281
  messageHash: "",
1120
- signature: response2
1282
+ signature: response2,
1283
+ protocol: "BIP322" /* BIP322 */
1121
1284
  };
1122
1285
  }
1123
1286
  const response = await window.unisat.signMessage(message, "ecdsa");
1124
1287
  return {
1125
1288
  address,
1126
1289
  messageHash: "",
1127
- signature: response
1290
+ signature: response,
1291
+ protocol: "ECDSA" /* ECDSA */
1128
1292
  };
1129
1293
  }
1130
1294
  async sendTransfer(params) {
@@ -1138,11 +1302,11 @@ var UnisatAdapter = class extends SatsConnectAdapter {
1138
1302
  };
1139
1303
  }
1140
1304
  async signPsbt(params) {
1141
- const { psbt, signInputs, allowedSignHash, broadcast } = params;
1305
+ const { psbt, signInputs, broadcast } = params;
1142
1306
  const psbtHex = Buffer.from(psbt, "base64").toString("hex");
1143
1307
  const signedPsbt = await window.unisat.signPsbt(psbtHex, {
1144
1308
  autoFinalized: broadcast,
1145
- toSignInputs: convertSignInputsToInputType(signInputs, allowedSignHash)
1309
+ toSignInputs: convertSignInputsToInputType(signInputs)
1146
1310
  });
1147
1311
  if (broadcast) {
1148
1312
  const txid = await window.unisat.pushPsbt(psbtHex);
@@ -1212,6 +1376,33 @@ var UnisatAdapter = class extends SatsConnectAdapter {
1212
1376
  };
1213
1377
  }
1214
1378
  };
1379
+ addListener = (eventName, cb) => {
1380
+ switch (eventName) {
1381
+ case "accountChange": {
1382
+ const handler = () => {
1383
+ cb({ type: "accountChange" });
1384
+ };
1385
+ window.unisat.on("accountsChanged", handler);
1386
+ return () => {
1387
+ window.unisat.removeListener("accountsChanged", handler);
1388
+ };
1389
+ }
1390
+ case "networkChange": {
1391
+ const handler = () => {
1392
+ cb({ type: "networkChange" });
1393
+ };
1394
+ window.unisat.on("networkChanged", handler);
1395
+ return () => {
1396
+ window.unisat.removeListener("networkChanged", handler);
1397
+ };
1398
+ }
1399
+ default: {
1400
+ console.error("Event not supported by the selected wallet");
1401
+ return () => {
1402
+ };
1403
+ }
1404
+ }
1405
+ };
1215
1406
  };
1216
1407
 
1217
1408
  // src/adapters/BaseAdapter.ts
@@ -1476,11 +1667,23 @@ export {
1476
1667
  accountChangeSchema,
1477
1668
  addListener,
1478
1669
  addressSchema,
1670
+ connectMethodName,
1671
+ connectParamsSchema,
1672
+ connectRequestMessageSchema,
1673
+ connectResultSchema,
1479
1674
  createInscription,
1480
1675
  createRepeatInscriptions,
1481
1676
  defaultAdapters,
1482
1677
  disconnectEventName,
1678
+ disconnectMethodName,
1679
+ disconnectParamsSchema,
1680
+ disconnectRequestMessageSchema,
1681
+ disconnectResultSchema,
1483
1682
  disconnectSchema,
1683
+ getAccountMethodName,
1684
+ getAccountParamsSchema,
1685
+ getAccountRequestMessageSchema,
1686
+ getAccountResultSchema,
1484
1687
  getAccountsMethodName,
1485
1688
  getAccountsParamsSchema,
1486
1689
  getAccountsRequestMessageSchema,
@@ -1523,6 +1726,7 @@ export {
1523
1726
  isProviderInstalled,
1524
1727
  networkChangeEventName,
1525
1728
  networkChangeSchema,
1729
+ permissionTemplate,
1526
1730
  removeDefaultProvider,
1527
1731
  renouncePermissionsMethodName,
1528
1732
  renouncePermissionsParamsSchema,
@@ -1542,6 +1746,10 @@ export {
1542
1746
  sendInscriptionsParamsSchema,
1543
1747
  sendInscriptionsResultSchema,
1544
1748
  sendInscriptionsSchema,
1749
+ sendTransferMethodName,
1750
+ sendTransferParamsSchema,
1751
+ sendTransferRequestMessageSchema,
1752
+ sendTransferResultSchema,
1545
1753
  setDefaultProvider,
1546
1754
  signMessage,
1547
1755
  signMessageMethodName,
@@ -1549,7 +1757,15 @@ export {
1549
1757
  signMessageRequestMessageSchema,
1550
1758
  signMessageResultSchema,
1551
1759
  signMultipleTransactions,
1760
+ signPsbtMethodName,
1761
+ signPsbtParamsSchema,
1762
+ signPsbtRequestMessageSchema,
1763
+ signPsbtResultSchema,
1552
1764
  signTransaction,
1765
+ stxCallContractMethodName,
1766
+ stxCallContractParamsSchema,
1767
+ stxCallContractRequestMessageSchema,
1768
+ stxCallContractResultSchema,
1553
1769
  stxGetAddressesMethodName,
1554
1770
  stxGetAddressesParamsSchema,
1555
1771
  stxGetAddressesRequestMessageSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.4.0-e7d3e8d",
3
+ "version": "0.4.0-ff58e17",
4
4
  "main": "dist/index.mjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -9,11 +9,12 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "test": "jest",
12
- "build-debug": "webpack --mode development",
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",
15
- "clean": "rimraf dist",
16
- "lint": "prettier --write .",
12
+ "build": "tsup",
13
+ "build:watch": "tsup --watch",
14
+ "check-types": "tsc --noEmit",
15
+ "check-format": "prettier --check .",
16
+ "format": "prettier --write .",
17
+ "ci": "npm run check-types && npm run check-format && npm run build",
17
18
  "prepare": "husky install"
18
19
  },
19
20
  "lint-staged": {
@@ -25,16 +26,15 @@
25
26
  ]
26
27
  },
27
28
  "dependencies": {
29
+ "@secretkeylabs/xverse-core": "24.0.0-4db3b55",
28
30
  "axios": "1.7.4",
29
31
  "bitcoin-address-validation": "2.2.3",
30
32
  "buffer": "6.0.3",
31
33
  "jsontokens": "4.0.1",
32
- "lodash.omit": "4.5.0",
33
- "valibot": "0.33.2"
34
+ "valibot": "0.42.1"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/jest": "^29.2.6",
37
- "@types/lodash.omit": "4.5.9",
38
38
  "husky": "^8.0.3",
39
39
  "lint-staged": "^13.2.3",
40
40
  "prettier": "3.3.3",
@@ -46,9 +46,7 @@
46
46
  "tsup": "^8.0.2",
47
47
  "typescript": "5.4.5",
48
48
  "util": "^0.12.4",
49
- "vm-browserify": "^1.1.2",
50
- "webpack": "^5.74.0",
51
- "webpack-cli": "^4.10.0"
49
+ "vm-browserify": "^1.1.2"
52
50
  },
53
51
  "repository": {
54
52
  "type": "git",