@sats-connect/core 0.4.0-791813d → 0.4.0-954ad8d
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 +528 -58
- package/dist/index.d.ts +1653 -0
- package/dist/index.js +1889 -0
- package/dist/index.mjs +185 -25
- package/package.json +9 -12
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
|
|
54
|
-
const
|
|
55
|
-
|
|
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,6 @@ var getAddress = async (options) => {
|
|
|
165
163
|
};
|
|
166
164
|
|
|
167
165
|
// src/request/types/stxMethods.ts
|
|
168
|
-
import * as v4 from "valibot";
|
|
169
166
|
var stxGetAddressesMethodName = "stx_getAddresses";
|
|
170
167
|
var stxGetAddressesParamsSchema = v4.nullish(
|
|
171
168
|
v4.object({
|
|
@@ -325,6 +322,69 @@ var signMessageRequestMessageSchema = v6.object({
|
|
|
325
322
|
id: v6.string()
|
|
326
323
|
}).entries
|
|
327
324
|
});
|
|
325
|
+
var sendTransferMethodName = "sendTransfer";
|
|
326
|
+
var sendTransferParamsSchema = v6.object({
|
|
327
|
+
/**
|
|
328
|
+
* Array of recipients to send to.
|
|
329
|
+
* The amount to send to each recipient is in satoshis.
|
|
330
|
+
*/
|
|
331
|
+
recipients: v6.array(
|
|
332
|
+
v6.object({
|
|
333
|
+
address: v6.string(),
|
|
334
|
+
amount: v6.number()
|
|
335
|
+
})
|
|
336
|
+
)
|
|
337
|
+
});
|
|
338
|
+
var sendTransferResultSchema = v6.object({
|
|
339
|
+
/**
|
|
340
|
+
* The transaction id as a hex-encoded string.
|
|
341
|
+
*/
|
|
342
|
+
txid: v6.string()
|
|
343
|
+
});
|
|
344
|
+
var sendTransferRequestMessageSchema = v6.object({
|
|
345
|
+
...rpcRequestMessageSchema.entries,
|
|
346
|
+
...v6.object({
|
|
347
|
+
method: v6.literal(sendTransferMethodName),
|
|
348
|
+
params: sendTransferParamsSchema,
|
|
349
|
+
id: v6.string()
|
|
350
|
+
}).entries
|
|
351
|
+
});
|
|
352
|
+
var signPsbtMethodName = "signPsbt";
|
|
353
|
+
var signPsbtParamsSchema = v6.object({
|
|
354
|
+
/**
|
|
355
|
+
* The base64 encoded PSBT to sign.
|
|
356
|
+
*/
|
|
357
|
+
psbt: v6.string(),
|
|
358
|
+
/**
|
|
359
|
+
* The inputs to sign.
|
|
360
|
+
* The key is the address and the value is an array of indexes of the inputs to sign.
|
|
361
|
+
*/
|
|
362
|
+
signInputs: v6.record(v6.string(), v6.array(v6.number())),
|
|
363
|
+
allowedSignHash: v6.optional(v6.number()),
|
|
364
|
+
/**
|
|
365
|
+
* Whether to broadcast the transaction after signing.
|
|
366
|
+
**/
|
|
367
|
+
broadcast: v6.optional(v6.boolean())
|
|
368
|
+
});
|
|
369
|
+
var signPsbtResultSchema = v6.object({
|
|
370
|
+
/**
|
|
371
|
+
* The base64 encoded PSBT after signing.
|
|
372
|
+
*/
|
|
373
|
+
psbt: v6.string(),
|
|
374
|
+
/**
|
|
375
|
+
* The transaction id as a hex-encoded string.
|
|
376
|
+
* This is only returned if the transaction was broadcast.
|
|
377
|
+
**/
|
|
378
|
+
txid: v6.optional(v6.string())
|
|
379
|
+
});
|
|
380
|
+
var signPsbtRequestMessageSchema = v6.object({
|
|
381
|
+
...rpcRequestMessageSchema.entries,
|
|
382
|
+
...v6.object({
|
|
383
|
+
method: v6.literal(signPsbtMethodName),
|
|
384
|
+
params: signPsbtParamsSchema,
|
|
385
|
+
id: v6.string()
|
|
386
|
+
}).entries
|
|
387
|
+
});
|
|
328
388
|
var getAccountsMethodName = "getAccounts";
|
|
329
389
|
var getAccountsParamsSchema = v6.object({
|
|
330
390
|
/**
|
|
@@ -386,8 +446,18 @@ var getBalanceRequestMessageSchema = v6.object({
|
|
|
386
446
|
// src/request/types/walletMethods.ts
|
|
387
447
|
import * as v7 from "valibot";
|
|
388
448
|
import { permissions } from "@secretkeylabs/xverse-core";
|
|
449
|
+
var permissionTemplate = v7.variant("type", [
|
|
450
|
+
v7.object({
|
|
451
|
+
...v7.omit(permissions.resources.account.accountPermissionSchema, ["clientId", "actions"]).entries,
|
|
452
|
+
actions: v7.partial(permissions.resources.account.accountActionsSchema)
|
|
453
|
+
}),
|
|
454
|
+
v7.object({
|
|
455
|
+
...v7.omit(permissions.resources.wallet.walletPermissionSchema, ["clientId"]).entries,
|
|
456
|
+
actions: v7.partial(permissions.resources.wallet.walletActionsSchema)
|
|
457
|
+
})
|
|
458
|
+
]);
|
|
389
459
|
var requestPermissionsMethodName = "wallet_requestPermissions";
|
|
390
|
-
var requestPermissionsParamsSchema = v7.
|
|
460
|
+
var requestPermissionsParamsSchema = v7.nullish(v7.array(permissionTemplate));
|
|
391
461
|
var requestPermissionsResultSchema = v7.literal(true);
|
|
392
462
|
var requestPermissionsRequestMessageSchema = v7.object({
|
|
393
463
|
...rpcRequestMessageSchema.entries,
|
|
@@ -398,8 +468,8 @@ var requestPermissionsRequestMessageSchema = v7.object({
|
|
|
398
468
|
}).entries
|
|
399
469
|
});
|
|
400
470
|
var renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
401
|
-
var renouncePermissionsParamsSchema = v7.
|
|
402
|
-
var renouncePermissionsResultSchema = v7.
|
|
471
|
+
var renouncePermissionsParamsSchema = v7.nullish(v7.null());
|
|
472
|
+
var renouncePermissionsResultSchema = v7.nullish(v7.null());
|
|
403
473
|
var renouncePermissionsRequestMessageSchema = v7.object({
|
|
404
474
|
...rpcRequestMessageSchema.entries,
|
|
405
475
|
...v7.object({
|
|
@@ -408,6 +478,17 @@ var renouncePermissionsRequestMessageSchema = v7.object({
|
|
|
408
478
|
id: v7.string()
|
|
409
479
|
}).entries
|
|
410
480
|
});
|
|
481
|
+
var disconnectMethodName = "wallet_disconnect";
|
|
482
|
+
var disconnectParamsSchema = v7.nullish(v7.null());
|
|
483
|
+
var disconnectResultSchema = v7.nullish(v7.null());
|
|
484
|
+
var disconnectRequestMessageSchema = v7.object({
|
|
485
|
+
...rpcRequestMessageSchema.entries,
|
|
486
|
+
...v7.object({
|
|
487
|
+
method: v7.literal(disconnectMethodName),
|
|
488
|
+
params: disconnectParamsSchema,
|
|
489
|
+
id: v7.string()
|
|
490
|
+
}).entries
|
|
491
|
+
});
|
|
411
492
|
var getWalletTypeMethodName = "wallet_getWalletType";
|
|
412
493
|
var getWalletTypeParamsSchema = v7.nullish(v7.null());
|
|
413
494
|
var getWalletTypeResultSchema = walletTypeSchema;
|
|
@@ -415,18 +496,48 @@ var getWalletTypeRequestMessageSchema = v7.object({
|
|
|
415
496
|
...rpcRequestMessageSchema.entries,
|
|
416
497
|
...v7.object({
|
|
417
498
|
method: v7.literal(getWalletTypeMethodName),
|
|
499
|
+
params: getWalletTypeParamsSchema,
|
|
418
500
|
id: v7.string()
|
|
419
501
|
}).entries
|
|
420
502
|
});
|
|
421
503
|
var getCurrentPermissionsMethodName = "wallet_getCurrentPermissions";
|
|
422
504
|
var getCurrentPermissionsParamsSchema = v7.nullish(v7.null());
|
|
423
|
-
var getCurrentPermissionsResultSchema = v7.array(
|
|
424
|
-
v7.object({ ...permissions.schemas.permission.entries, resource: permissions.schemas.resource })
|
|
425
|
-
);
|
|
505
|
+
var getCurrentPermissionsResultSchema = v7.array(permissions.store.permission);
|
|
426
506
|
var getCurrentPermissionsRequestMessageSchema = v7.object({
|
|
427
507
|
...rpcRequestMessageSchema.entries,
|
|
428
508
|
...v7.object({
|
|
429
509
|
method: v7.literal(getCurrentPermissionsMethodName),
|
|
510
|
+
params: getCurrentPermissionsParamsSchema,
|
|
511
|
+
id: v7.string()
|
|
512
|
+
}).entries
|
|
513
|
+
});
|
|
514
|
+
var getAccountMethodName = "wallet_getAccount";
|
|
515
|
+
var getAccountParamsSchema = v7.nullish(v7.null());
|
|
516
|
+
var getAccountResultSchema = v7.object({
|
|
517
|
+
id: permissions.utils.account.accountIdSchema,
|
|
518
|
+
addresses: v7.array(addressSchema),
|
|
519
|
+
walletType: walletTypeSchema
|
|
520
|
+
});
|
|
521
|
+
var getAccountRequestMessageSchema = v7.object({
|
|
522
|
+
...rpcRequestMessageSchema.entries,
|
|
523
|
+
...v7.object({
|
|
524
|
+
method: v7.literal(getAccountMethodName),
|
|
525
|
+
params: getAccountParamsSchema,
|
|
526
|
+
id: v7.string()
|
|
527
|
+
}).entries
|
|
528
|
+
});
|
|
529
|
+
var connectMethodName = "wallet_connect";
|
|
530
|
+
var connectParamsSchema = v7.nullish(
|
|
531
|
+
v7.object({
|
|
532
|
+
permissions: v7.optional(v7.array(permissionTemplate))
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
var connectResultSchema = getAccountResultSchema;
|
|
536
|
+
var connectRequestMessageSchema = v7.object({
|
|
537
|
+
...rpcRequestMessageSchema.entries,
|
|
538
|
+
...v7.object({
|
|
539
|
+
method: v7.literal(connectMethodName),
|
|
540
|
+
params: connectParamsSchema,
|
|
430
541
|
id: v7.string()
|
|
431
542
|
}).entries
|
|
432
543
|
});
|
|
@@ -1062,17 +1173,16 @@ var XverseAdapter = class extends SatsConnectAdapter {
|
|
|
1062
1173
|
};
|
|
1063
1174
|
|
|
1064
1175
|
// src/adapters/unisat.ts
|
|
1065
|
-
import { Buffer } from "buffer";
|
|
1066
1176
|
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
1067
|
-
|
|
1177
|
+
import { Buffer } from "buffer";
|
|
1178
|
+
function convertSignInputsToInputType(signInputs) {
|
|
1068
1179
|
let result = [];
|
|
1069
1180
|
for (let address in signInputs) {
|
|
1070
1181
|
let indexes = signInputs[address];
|
|
1071
1182
|
for (let index of indexes) {
|
|
1072
1183
|
result.push({
|
|
1073
1184
|
index,
|
|
1074
|
-
address
|
|
1075
|
-
sighashTypes: allowedSignHash ? [allowedSignHash] : void 0
|
|
1185
|
+
address
|
|
1076
1186
|
});
|
|
1077
1187
|
}
|
|
1078
1188
|
}
|
|
@@ -1104,10 +1214,10 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
1104
1214
|
};
|
|
1105
1215
|
const response = [];
|
|
1106
1216
|
if (purposes.includes("payment" /* Payment */)) {
|
|
1107
|
-
response.push(paymentAddress);
|
|
1217
|
+
response.push({ ...paymentAddress, walletType: "software" });
|
|
1108
1218
|
}
|
|
1109
1219
|
if (purposes.includes("ordinals" /* Ordinals */)) {
|
|
1110
|
-
response.push(ordinalsAddress);
|
|
1220
|
+
response.push({ ...ordinalsAddress, walletType: "software" });
|
|
1111
1221
|
}
|
|
1112
1222
|
return response;
|
|
1113
1223
|
}
|
|
@@ -1120,14 +1230,16 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
1120
1230
|
return {
|
|
1121
1231
|
address,
|
|
1122
1232
|
messageHash: "",
|
|
1123
|
-
signature: response2
|
|
1233
|
+
signature: response2,
|
|
1234
|
+
protocol: "BIP322" /* BIP322 */
|
|
1124
1235
|
};
|
|
1125
1236
|
}
|
|
1126
1237
|
const response = await window.unisat.signMessage(message, "ecdsa");
|
|
1127
1238
|
return {
|
|
1128
1239
|
address,
|
|
1129
1240
|
messageHash: "",
|
|
1130
|
-
signature: response
|
|
1241
|
+
signature: response,
|
|
1242
|
+
protocol: "ECDSA" /* ECDSA */
|
|
1131
1243
|
};
|
|
1132
1244
|
}
|
|
1133
1245
|
async sendTransfer(params) {
|
|
@@ -1141,11 +1253,11 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
1141
1253
|
};
|
|
1142
1254
|
}
|
|
1143
1255
|
async signPsbt(params) {
|
|
1144
|
-
const { psbt, signInputs,
|
|
1256
|
+
const { psbt, signInputs, broadcast } = params;
|
|
1145
1257
|
const psbtHex = Buffer.from(psbt, "base64").toString("hex");
|
|
1146
1258
|
const signedPsbt = await window.unisat.signPsbt(psbtHex, {
|
|
1147
1259
|
autoFinalized: broadcast,
|
|
1148
|
-
toSignInputs: convertSignInputsToInputType(signInputs
|
|
1260
|
+
toSignInputs: convertSignInputsToInputType(signInputs)
|
|
1149
1261
|
});
|
|
1150
1262
|
if (broadcast) {
|
|
1151
1263
|
const txid = await window.unisat.pushPsbt(psbtHex);
|
|
@@ -1215,6 +1327,33 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
1215
1327
|
};
|
|
1216
1328
|
}
|
|
1217
1329
|
};
|
|
1330
|
+
addListener = (eventName, cb) => {
|
|
1331
|
+
switch (eventName) {
|
|
1332
|
+
case "accountChange": {
|
|
1333
|
+
const handler = () => {
|
|
1334
|
+
cb({ type: "accountChange" });
|
|
1335
|
+
};
|
|
1336
|
+
window.unisat.on("accountsChanged", handler);
|
|
1337
|
+
return () => {
|
|
1338
|
+
window.unisat.removeListener("accountsChanged", handler);
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
case "networkChange": {
|
|
1342
|
+
const handler = () => {
|
|
1343
|
+
cb({ type: "networkChange" });
|
|
1344
|
+
};
|
|
1345
|
+
window.unisat.on("networkChanged", handler);
|
|
1346
|
+
return () => {
|
|
1347
|
+
window.unisat.removeListener("networkChanged", handler);
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
default: {
|
|
1351
|
+
console.error("Event not supported by the selected wallet");
|
|
1352
|
+
return () => {
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1218
1357
|
};
|
|
1219
1358
|
|
|
1220
1359
|
// src/adapters/BaseAdapter.ts
|
|
@@ -1479,11 +1618,23 @@ export {
|
|
|
1479
1618
|
accountChangeSchema,
|
|
1480
1619
|
addListener,
|
|
1481
1620
|
addressSchema,
|
|
1621
|
+
connectMethodName,
|
|
1622
|
+
connectParamsSchema,
|
|
1623
|
+
connectRequestMessageSchema,
|
|
1624
|
+
connectResultSchema,
|
|
1482
1625
|
createInscription,
|
|
1483
1626
|
createRepeatInscriptions,
|
|
1484
1627
|
defaultAdapters,
|
|
1485
1628
|
disconnectEventName,
|
|
1629
|
+
disconnectMethodName,
|
|
1630
|
+
disconnectParamsSchema,
|
|
1631
|
+
disconnectRequestMessageSchema,
|
|
1632
|
+
disconnectResultSchema,
|
|
1486
1633
|
disconnectSchema,
|
|
1634
|
+
getAccountMethodName,
|
|
1635
|
+
getAccountParamsSchema,
|
|
1636
|
+
getAccountRequestMessageSchema,
|
|
1637
|
+
getAccountResultSchema,
|
|
1487
1638
|
getAccountsMethodName,
|
|
1488
1639
|
getAccountsParamsSchema,
|
|
1489
1640
|
getAccountsRequestMessageSchema,
|
|
@@ -1526,6 +1677,7 @@ export {
|
|
|
1526
1677
|
isProviderInstalled,
|
|
1527
1678
|
networkChangeEventName,
|
|
1528
1679
|
networkChangeSchema,
|
|
1680
|
+
permissionTemplate,
|
|
1529
1681
|
removeDefaultProvider,
|
|
1530
1682
|
renouncePermissionsMethodName,
|
|
1531
1683
|
renouncePermissionsParamsSchema,
|
|
@@ -1545,6 +1697,10 @@ export {
|
|
|
1545
1697
|
sendInscriptionsParamsSchema,
|
|
1546
1698
|
sendInscriptionsResultSchema,
|
|
1547
1699
|
sendInscriptionsSchema,
|
|
1700
|
+
sendTransferMethodName,
|
|
1701
|
+
sendTransferParamsSchema,
|
|
1702
|
+
sendTransferRequestMessageSchema,
|
|
1703
|
+
sendTransferResultSchema,
|
|
1548
1704
|
setDefaultProvider,
|
|
1549
1705
|
signMessage,
|
|
1550
1706
|
signMessageMethodName,
|
|
@@ -1552,6 +1708,10 @@ export {
|
|
|
1552
1708
|
signMessageRequestMessageSchema,
|
|
1553
1709
|
signMessageResultSchema,
|
|
1554
1710
|
signMultipleTransactions,
|
|
1711
|
+
signPsbtMethodName,
|
|
1712
|
+
signPsbtParamsSchema,
|
|
1713
|
+
signPsbtRequestMessageSchema,
|
|
1714
|
+
signPsbtResultSchema,
|
|
1555
1715
|
signTransaction,
|
|
1556
1716
|
stxGetAddressesMethodName,
|
|
1557
1717
|
stxGetAddressesParamsSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-connect/core",
|
|
3
|
-
"version": "0.4.0-
|
|
3
|
+
"version": "0.4.0-954ad8d",
|
|
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
|
|
13
|
-
"build": "
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
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,17 +26,15 @@
|
|
|
25
26
|
]
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@secretkeylabs/xverse-core": "
|
|
29
|
+
"@secretkeylabs/xverse-core": "24.0.0-4db3b55",
|
|
29
30
|
"axios": "1.7.4",
|
|
30
31
|
"bitcoin-address-validation": "2.2.3",
|
|
31
32
|
"buffer": "6.0.3",
|
|
32
33
|
"jsontokens": "4.0.1",
|
|
33
|
-
"lodash.omit": "4.5.0",
|
|
34
34
|
"valibot": "0.42.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/jest": "^29.2.6",
|
|
38
|
-
"@types/lodash.omit": "4.5.9",
|
|
39
38
|
"husky": "^8.0.3",
|
|
40
39
|
"lint-staged": "^13.2.3",
|
|
41
40
|
"prettier": "3.3.3",
|
|
@@ -47,9 +46,7 @@
|
|
|
47
46
|
"tsup": "^8.0.2",
|
|
48
47
|
"typescript": "5.4.5",
|
|
49
48
|
"util": "^0.12.4",
|
|
50
|
-
"vm-browserify": "^1.1.2"
|
|
51
|
-
"webpack": "^5.74.0",
|
|
52
|
-
"webpack-cli": "^4.10.0"
|
|
49
|
+
"vm-browserify": "^1.1.2"
|
|
53
50
|
},
|
|
54
51
|
"repository": {
|
|
55
52
|
"type": "git",
|