@sats-connect/core 0.0.2-2bfa1ee → 0.0.2
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/README.md +0 -1
- package/dist/index.d.mts +609 -0
- package/dist/index.mjs +596 -0
- package/package.json +6 -3
- package/dist/adapters/BaseAdapter.d.ts +0 -9
- package/dist/adapters/BaseAdapter.js +0 -17
- package/dist/adapters/BaseAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -6
- package/dist/adapters/index.js +0 -43
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/satsConnectAdapter.d.ts +0 -7
- package/dist/adapters/satsConnectAdapter.js +0 -7
- package/dist/adapters/satsConnectAdapter.js.map +0 -1
- package/dist/adapters/unisat.d.ts +0 -38
- package/dist/adapters/unisat.js +0 -164
- package/dist/adapters/unisat.js.map +0 -1
- package/dist/adapters/xverse.d.ts +0 -8
- package/dist/adapters/xverse.js +0 -14
- package/dist/adapters/xverse.js.map +0 -1
- package/dist/addresses/index.d.ts +0 -3
- package/dist/addresses/index.js +0 -38
- package/dist/addresses/index.js.map +0 -1
- package/dist/addresses/types.d.ts +0 -28
- package/dist/addresses/types.js +0 -19
- package/dist/addresses/types.js.map +0 -1
- package/dist/capabilities/index.d.ts +0 -3
- package/dist/capabilities/index.js +0 -70
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/types.d.ts +0 -6
- package/dist/capabilities/types.js +0 -3
- package/dist/capabilities/types.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -27
- package/dist/index.js.map +0 -1
- package/dist/inscriptions/createInscription.d.ts +0 -2
- package/dist/inscriptions/createInscription.js +0 -22
- package/dist/inscriptions/createInscription.js.map +0 -1
- package/dist/inscriptions/createRepeatInscriptions.d.ts +0 -2
- package/dist/inscriptions/createRepeatInscriptions.js +0 -22
- package/dist/inscriptions/createRepeatInscriptions.js.map +0 -1
- package/dist/inscriptions/index.d.ts +0 -3
- package/dist/inscriptions/index.js +0 -20
- package/dist/inscriptions/index.js.map +0 -1
- package/dist/inscriptions/types.d.ts +0 -21
- package/dist/inscriptions/types.js +0 -3
- package/dist/inscriptions/types.js.map +0 -1
- package/dist/inscriptions/utils.d.ts +0 -2
- package/dist/inscriptions/utils.js +0 -26
- package/dist/inscriptions/utils.js.map +0 -1
- package/dist/messages/index.d.ts +0 -3
- package/dist/messages/index.js +0 -41
- package/dist/messages/index.js.map +0 -1
- package/dist/messages/types.d.ts +0 -7
- package/dist/messages/types.js +0 -3
- package/dist/messages/types.js.map +0 -1
- package/dist/provider/index.d.ts +0 -10
- package/dist/provider/index.js +0 -74
- package/dist/provider/index.js.map +0 -1
- package/dist/provider/types.d.ts +0 -46
- package/dist/provider/types.js +0 -3
- package/dist/provider/types.js.map +0 -1
- package/dist/request/index.d.ts +0 -4
- package/dist/request/index.js +0 -47
- package/dist/request/index.js.map +0 -1
- package/dist/request/types/btcMethods.d.ts +0 -127
- package/dist/request/types/btcMethods.js +0 -6
- package/dist/request/types/btcMethods.js.map +0 -1
- package/dist/request/types/index.d.ts +0 -27
- package/dist/request/types/index.js +0 -19
- package/dist/request/types/index.js.map +0 -1
- package/dist/request/types/stxMethods.d.ts +0 -181
- package/dist/request/types/stxMethods.js +0 -3
- package/dist/request/types/stxMethods.js.map +0 -1
- package/dist/transactions/index.d.ts +0 -4
- package/dist/transactions/index.js +0 -21
- package/dist/transactions/index.js.map +0 -1
- package/dist/transactions/sendBtcTransaction.d.ts +0 -2
- package/dist/transactions/sendBtcTransaction.js +0 -45
- package/dist/transactions/sendBtcTransaction.js.map +0 -1
- package/dist/transactions/signMultipleTransactions.d.ts +0 -2
- package/dist/transactions/signMultipleTransactions.js +0 -26
- package/dist/transactions/signMultipleTransactions.js.map +0 -1
- package/dist/transactions/signTransaction.d.ts +0 -2
- package/dist/transactions/signTransaction.js +0 -26
- package/dist/transactions/signTransaction.js.map +0 -1
- package/dist/transactions/types.d.ts +0 -46
- package/dist/transactions/types.js +0 -3
- package/dist/transactions/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -87
- package/dist/types.js +0 -46
- package/dist/types.js.map +0 -1
- package/dist/ui/index.d.ts +0 -5
- package/dist/ui/index.js +0 -27
- package/dist/ui/index.js.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
// src/adapters/satsConnectAdapter.ts
|
|
2
|
+
var SatsConnectAdapter = class {
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
// src/provider/index.ts
|
|
6
|
+
import omit from "lodash.omit";
|
|
7
|
+
async function getProviderOrThrow(getProvider) {
|
|
8
|
+
const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
9
|
+
if (!provider) {
|
|
10
|
+
throw new Error("No Bitcoin wallet installed");
|
|
11
|
+
}
|
|
12
|
+
return provider;
|
|
13
|
+
}
|
|
14
|
+
function getProviders() {
|
|
15
|
+
if (!window.btc_providers)
|
|
16
|
+
window.btc_providers = [];
|
|
17
|
+
return window.btc_providers;
|
|
18
|
+
}
|
|
19
|
+
function getProviderById(providerId) {
|
|
20
|
+
return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
|
|
21
|
+
}
|
|
22
|
+
function isProviderInstalled(providerId) {
|
|
23
|
+
return !!getProviderById(providerId);
|
|
24
|
+
}
|
|
25
|
+
function setDefaultProvider(providerId) {
|
|
26
|
+
localStorage.setItem("sats-connect_defaultProvider", providerId);
|
|
27
|
+
}
|
|
28
|
+
function getDefaultProvider() {
|
|
29
|
+
return localStorage.getItem("sats-connect_defaultProvider");
|
|
30
|
+
}
|
|
31
|
+
function removeDefaultProvider() {
|
|
32
|
+
localStorage.removeItem("sats-connect_defaultProvider");
|
|
33
|
+
}
|
|
34
|
+
function getSupportedWallets() {
|
|
35
|
+
const btc_providers = getProviders();
|
|
36
|
+
for (const key in omit(DefaultAdaptersInfo, ["xverse"])) {
|
|
37
|
+
btc_providers.push(DefaultAdaptersInfo[key]);
|
|
38
|
+
}
|
|
39
|
+
const wallets = btc_providers.map((provider) => {
|
|
40
|
+
{
|
|
41
|
+
return {
|
|
42
|
+
...provider,
|
|
43
|
+
isInstalled: isProviderInstalled(provider.id)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return wallets;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/request/index.ts
|
|
51
|
+
var request = async (method, params, providerId) => {
|
|
52
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
53
|
+
if (providerId) {
|
|
54
|
+
provider = await getProviderById(providerId);
|
|
55
|
+
}
|
|
56
|
+
if (!provider) {
|
|
57
|
+
throw new Error("no wallet provider was found");
|
|
58
|
+
}
|
|
59
|
+
if (!method) {
|
|
60
|
+
throw new Error("A wallet method is required");
|
|
61
|
+
}
|
|
62
|
+
const response = await provider.request(method, params);
|
|
63
|
+
if (isRpcSuccessResponse(response)) {
|
|
64
|
+
return {
|
|
65
|
+
status: "success",
|
|
66
|
+
result: response.result
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
status: "error",
|
|
71
|
+
error: response.error
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var isRpcSuccessResponse = (response) => {
|
|
75
|
+
return Object.hasOwn(response, "result") && !!response.result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/adapters/xverse.ts
|
|
79
|
+
var XverseAdapter = class extends SatsConnectAdapter {
|
|
80
|
+
id = DefaultAdaptersInfo.xverse.id;
|
|
81
|
+
request = async (method, params) => {
|
|
82
|
+
return request(method, params, this.id);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/adapters/unisat.ts
|
|
87
|
+
import { Buffer } from "buffer";
|
|
88
|
+
|
|
89
|
+
// src/types.ts
|
|
90
|
+
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
91
|
+
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
92
|
+
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
93
|
+
return BitcoinNetworkType2;
|
|
94
|
+
})(BitcoinNetworkType || {});
|
|
95
|
+
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
96
|
+
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
97
|
+
RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
98
|
+
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
99
|
+
RpcErrorCode2[RpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
100
|
+
RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
101
|
+
RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
|
|
102
|
+
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
|
|
103
|
+
return RpcErrorCode2;
|
|
104
|
+
})(RpcErrorCode || {});
|
|
105
|
+
|
|
106
|
+
// src/adapters/unisat.ts
|
|
107
|
+
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
108
|
+
|
|
109
|
+
// src/addresses/index.ts
|
|
110
|
+
import { createUnsecuredToken } from "jsontokens";
|
|
111
|
+
|
|
112
|
+
// src/addresses/types.ts
|
|
113
|
+
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
114
|
+
AddressPurpose2["Ordinals"] = "ordinals";
|
|
115
|
+
AddressPurpose2["Payment"] = "payment";
|
|
116
|
+
AddressPurpose2["Stacks"] = "stacks";
|
|
117
|
+
return AddressPurpose2;
|
|
118
|
+
})(AddressPurpose || {});
|
|
119
|
+
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
120
|
+
AddressType3["p2pkh"] = "p2pkh";
|
|
121
|
+
AddressType3["p2sh"] = "p2sh";
|
|
122
|
+
AddressType3["p2wpkh"] = "p2wpkh";
|
|
123
|
+
AddressType3["p2wsh"] = "p2wsh";
|
|
124
|
+
AddressType3["p2tr"] = "p2tr";
|
|
125
|
+
AddressType3["stacks"] = "stacks";
|
|
126
|
+
return AddressType3;
|
|
127
|
+
})(AddressType || {});
|
|
128
|
+
|
|
129
|
+
// src/addresses/index.ts
|
|
130
|
+
var getAddress = async (options) => {
|
|
131
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
132
|
+
const { purposes } = options.payload;
|
|
133
|
+
if (!purposes) {
|
|
134
|
+
throw new Error("Address purposes are required");
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const request2 = createUnsecuredToken(options.payload);
|
|
138
|
+
const response = await provider.connect(request2);
|
|
139
|
+
options.onFinish?.(response);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error("[Connect] Error during address request", error);
|
|
142
|
+
options.onCancel?.();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/adapters/unisat.ts
|
|
147
|
+
function convertSignInputsToInputType(signInputs, allowedSignHash) {
|
|
148
|
+
let result = [];
|
|
149
|
+
for (let address in signInputs) {
|
|
150
|
+
let indexes = signInputs[address];
|
|
151
|
+
for (let index of indexes) {
|
|
152
|
+
result.push({
|
|
153
|
+
index,
|
|
154
|
+
address,
|
|
155
|
+
sighashTypes: allowedSignHash ? [allowedSignHash] : void 0
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
var UnisatAdapter = class extends SatsConnectAdapter {
|
|
162
|
+
id = DefaultAdaptersInfo.unisat.id;
|
|
163
|
+
async getAccounts(params) {
|
|
164
|
+
const { purposes } = params;
|
|
165
|
+
if (!purposes.includes("stacks" /* Stacks */)) {
|
|
166
|
+
throw new Error("Only bitcoin addresses are supported");
|
|
167
|
+
}
|
|
168
|
+
const [accounts, publicKey] = await Promise.all([
|
|
169
|
+
window.unisat.requestAccounts(),
|
|
170
|
+
window.unisat.getPublicKey()
|
|
171
|
+
]);
|
|
172
|
+
const address = accounts[0];
|
|
173
|
+
const addressType = getAddressInfo(accounts[0]).type;
|
|
174
|
+
const pk = addressType === AddressType2.p2tr ? publicKey.slice(2) : publicKey;
|
|
175
|
+
const paymentAddress = {
|
|
176
|
+
address,
|
|
177
|
+
publicKey: pk,
|
|
178
|
+
addressType,
|
|
179
|
+
purpose: "payment" /* Payment */
|
|
180
|
+
};
|
|
181
|
+
const ordinalsAddress = {
|
|
182
|
+
address,
|
|
183
|
+
publicKey: pk,
|
|
184
|
+
addressType,
|
|
185
|
+
purpose: "ordinals" /* Ordinals */
|
|
186
|
+
};
|
|
187
|
+
const response = [];
|
|
188
|
+
if (purposes.includes("payment" /* Payment */)) {
|
|
189
|
+
response.push(paymentAddress);
|
|
190
|
+
}
|
|
191
|
+
if (purposes.includes("ordinals" /* Ordinals */)) {
|
|
192
|
+
response.push(ordinalsAddress);
|
|
193
|
+
}
|
|
194
|
+
return response;
|
|
195
|
+
}
|
|
196
|
+
async signMessage(params) {
|
|
197
|
+
const { message, address } = params;
|
|
198
|
+
const addressType = getAddressInfo(address).type;
|
|
199
|
+
const Bip322supportedTypes = [AddressType2.p2wpkh, AddressType2.p2tr];
|
|
200
|
+
if (Bip322supportedTypes.includes(addressType)) {
|
|
201
|
+
const response2 = await window.unisat.signMessage(message, "bip322-simple");
|
|
202
|
+
return {
|
|
203
|
+
address,
|
|
204
|
+
messageHash: "",
|
|
205
|
+
signature: response2
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const response = await window.unisat.signMessage(message, "ecdsa");
|
|
209
|
+
return {
|
|
210
|
+
address,
|
|
211
|
+
messageHash: "",
|
|
212
|
+
signature: response
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
async sendTransfer(params) {
|
|
216
|
+
const { recipients } = params;
|
|
217
|
+
if (recipients.length > 1) {
|
|
218
|
+
throw new Error("Only one recipient is supported by this wallet provider");
|
|
219
|
+
}
|
|
220
|
+
const txid = await window.unisat.sendBitcoin(recipients[0].address, recipients[0].amount);
|
|
221
|
+
return {
|
|
222
|
+
txid
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async signPsbt(params) {
|
|
226
|
+
const { psbt, signInputs, allowedSignHash, broadcast } = params;
|
|
227
|
+
const psbtHex = Buffer.from(psbt, "base64").toString("hex");
|
|
228
|
+
const signedPsbt = await window.unisat.signPsbt(psbtHex, {
|
|
229
|
+
autoFinalized: broadcast,
|
|
230
|
+
toSignInputs: convertSignInputsToInputType(signInputs, allowedSignHash)
|
|
231
|
+
});
|
|
232
|
+
if (broadcast) {
|
|
233
|
+
const txid = await window.unisat.pushPsbt(psbtHex);
|
|
234
|
+
return {
|
|
235
|
+
psbt: signedPsbt,
|
|
236
|
+
txid
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
psbt: psbtHex
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
request = async (method, params) => {
|
|
244
|
+
try {
|
|
245
|
+
switch (method) {
|
|
246
|
+
case "getAccounts": {
|
|
247
|
+
const response = await this.getAccounts(
|
|
248
|
+
params
|
|
249
|
+
);
|
|
250
|
+
return {
|
|
251
|
+
status: "success",
|
|
252
|
+
result: response
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
case "sendTransfer": {
|
|
256
|
+
const response = await this.sendTransfer(params);
|
|
257
|
+
return {
|
|
258
|
+
status: "success",
|
|
259
|
+
result: response
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
case "signMessage": {
|
|
263
|
+
const response = await this.signMessage(params);
|
|
264
|
+
return {
|
|
265
|
+
status: "success",
|
|
266
|
+
result: response
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
case "signPsbt": {
|
|
270
|
+
const response = await this.signPsbt(params);
|
|
271
|
+
return {
|
|
272
|
+
status: "success",
|
|
273
|
+
result: response
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
default: {
|
|
277
|
+
const error = {
|
|
278
|
+
code: -32001 /* METHOD_NOT_SUPPORTED */,
|
|
279
|
+
message: "Method not supported by the selected wallet"
|
|
280
|
+
};
|
|
281
|
+
console.error("Error calling the method", error);
|
|
282
|
+
return {
|
|
283
|
+
status: "error",
|
|
284
|
+
error
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error("Error calling the method", error);
|
|
290
|
+
return {
|
|
291
|
+
status: "error",
|
|
292
|
+
error: {
|
|
293
|
+
code: error.code === 4001 ? -32e3 /* USER_REJECTION */ : -32603 /* INTERNAL_ERROR */,
|
|
294
|
+
message: error.message ? error.message : "Wallet method call error",
|
|
295
|
+
data: error
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/adapters/BaseAdapter.ts
|
|
303
|
+
var BaseAdapter = class extends SatsConnectAdapter {
|
|
304
|
+
id = "";
|
|
305
|
+
constructor(providerId) {
|
|
306
|
+
super();
|
|
307
|
+
this.id = providerId;
|
|
308
|
+
}
|
|
309
|
+
request = async (method, params) => {
|
|
310
|
+
return request(method, params, this.id);
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// src/adapters/index.ts
|
|
315
|
+
var DefaultAdaptersInfo = {
|
|
316
|
+
xverse: {
|
|
317
|
+
id: "XverseProviders.BitcoinProvider",
|
|
318
|
+
name: "Xverse",
|
|
319
|
+
webUrl: "https://www.xverse.app/",
|
|
320
|
+
googlePlayStoreUrl: "https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse",
|
|
321
|
+
iOSAppStoreUrl: "https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513",
|
|
322
|
+
chromeWebStoreUrl: "https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg",
|
|
323
|
+
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5MzggMjcuNDUwNiAyNy4wOTM4IDI3Ljg3OFYzNS45MjExQzI3LjA5MzggMzYuMjY0NCAyNy4yMzAyIDM2LjU5MTcgMjcuNDczNCAzNi44MzVMNDAuNjk1MiA1MC4wNTY3QzQwLjk5NzUgNTAuMzU5MSA0MC45OTc1IDUwLjg1MDEgNDAuNjk1MiA1MS4xNTI0TDI3LjMyMTEgNjQuNTI2NUMyNy4xNzU2IDY0LjY3MiAyNy4wOTM4IDY0Ljg2OTggMjcuMDkzOCA2NS4wNzQ0VjczLjg4ODNDMjcuMDkzOCA3NC4zMTUzIDI3LjQ0MTYgNzQuNjYzNSAyNy44Njkg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mcz4KPC9zdmc+Cg=="
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var defaultAdapters = {
|
|
333
|
+
[DefaultAdaptersInfo.xverse.id]: XverseAdapter,
|
|
334
|
+
[DefaultAdaptersInfo.unisat.id]: UnisatAdapter
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/capabilities/index.ts
|
|
338
|
+
import { createUnsecuredToken as createUnsecuredToken2 } from "jsontokens";
|
|
339
|
+
var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
|
|
340
|
+
const validateCapability = (capability) => {
|
|
341
|
+
if (!provider[capability]) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (reportedCapabilities && !reportedCapabilities.has(capability)) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
return true;
|
|
348
|
+
};
|
|
349
|
+
const capabilityMap = {
|
|
350
|
+
request: validateCapability("request"),
|
|
351
|
+
connect: validateCapability("connect"),
|
|
352
|
+
signMessage: validateCapability("signMessage"),
|
|
353
|
+
signTransaction: validateCapability("signTransaction"),
|
|
354
|
+
sendBtcTransaction: validateCapability("sendBtcTransaction"),
|
|
355
|
+
createInscription: validateCapability("createInscription"),
|
|
356
|
+
createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
|
|
357
|
+
signMultipleTransactions: validateCapability("signMultipleTransactions")
|
|
358
|
+
};
|
|
359
|
+
return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
|
|
360
|
+
if (value)
|
|
361
|
+
return [...acc, capability];
|
|
362
|
+
return acc;
|
|
363
|
+
}, []);
|
|
364
|
+
};
|
|
365
|
+
var getCapabilities = async (options) => {
|
|
366
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
367
|
+
const request2 = createUnsecuredToken2(options.payload);
|
|
368
|
+
if (provider.getCapabilities) {
|
|
369
|
+
try {
|
|
370
|
+
const response = await provider.getCapabilities(request2);
|
|
371
|
+
options.onFinish?.(extractOrValidateCapabilities(provider, new Set(response)));
|
|
372
|
+
} catch (error) {
|
|
373
|
+
console.error("[Connect] Error during capabilities request", error);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
const inferredCapabilities = extractOrValidateCapabilities(provider);
|
|
378
|
+
options.onFinish?.(inferredCapabilities);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.error("[Connect] Error during capabilities request", error);
|
|
381
|
+
options.onCancel?.();
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// src/inscriptions/createInscription.ts
|
|
386
|
+
import { createUnsecuredToken as createUnsecuredToken3 } from "jsontokens";
|
|
387
|
+
|
|
388
|
+
// src/inscriptions/utils.ts
|
|
389
|
+
var MAX_CONTENT_LENGTH_MAINNET = 4e5;
|
|
390
|
+
var MAX_CONTENT_LENGTH_TESTNET = 6e4;
|
|
391
|
+
var validateInscriptionPayload = (payload) => {
|
|
392
|
+
const { contentType, content, payloadType, network, appFeeAddress, appFee } = payload;
|
|
393
|
+
if (!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(contentType)) {
|
|
394
|
+
throw new Error("Invalid content type detected");
|
|
395
|
+
}
|
|
396
|
+
if (!content || content.length === 0) {
|
|
397
|
+
throw new Error("Empty content not allowed");
|
|
398
|
+
}
|
|
399
|
+
if (!payloadType || payloadType !== "BASE_64" && payloadType !== "PLAIN_TEXT") {
|
|
400
|
+
throw new Error("Empty invalid payloadType specified");
|
|
401
|
+
}
|
|
402
|
+
if (content.length > (network.type === "Mainnet" ? MAX_CONTENT_LENGTH_MAINNET : MAX_CONTENT_LENGTH_TESTNET)) {
|
|
403
|
+
throw new Error("Content too large");
|
|
404
|
+
}
|
|
405
|
+
if ((appFeeAddress?.length ?? 0) > 0 && (appFee ?? 0) <= 0) {
|
|
406
|
+
throw new Error("Invalid combination of app fee address and fee provided");
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// src/inscriptions/createInscription.ts
|
|
411
|
+
var createInscription = async (options) => {
|
|
412
|
+
const { getProvider } = options;
|
|
413
|
+
const provider = await getProviderOrThrow(getProvider);
|
|
414
|
+
validateInscriptionPayload(options.payload);
|
|
415
|
+
try {
|
|
416
|
+
const request2 = createUnsecuredToken3(options.payload);
|
|
417
|
+
const response = await provider.createInscription(request2);
|
|
418
|
+
options.onFinish?.(response);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error("[Connect] Error during create inscription", error);
|
|
421
|
+
options.onCancel?.();
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
// src/inscriptions/createRepeatInscriptions.ts
|
|
426
|
+
import { createUnsecuredToken as createUnsecuredToken4 } from "jsontokens";
|
|
427
|
+
var createRepeatInscriptions = async (options) => {
|
|
428
|
+
const { getProvider } = options;
|
|
429
|
+
const provider = await getProviderOrThrow(getProvider);
|
|
430
|
+
validateInscriptionPayload(options.payload);
|
|
431
|
+
try {
|
|
432
|
+
const request2 = createUnsecuredToken4(options.payload);
|
|
433
|
+
const response = await provider.createRepeatInscriptions(request2);
|
|
434
|
+
options.onFinish?.(response);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
console.error("[Connect] Error during create repeat inscriptions", error);
|
|
437
|
+
options.onCancel?.();
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// src/messages/index.ts
|
|
442
|
+
import { createUnsecuredToken as createUnsecuredToken5 } from "jsontokens";
|
|
443
|
+
var signMessage = async (options) => {
|
|
444
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
445
|
+
const { address, message } = options.payload;
|
|
446
|
+
if (!address) {
|
|
447
|
+
throw new Error("An address is required to sign a message");
|
|
448
|
+
}
|
|
449
|
+
if (!message) {
|
|
450
|
+
throw new Error("A message to be signed is required");
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
const request2 = createUnsecuredToken5(options.payload);
|
|
454
|
+
const response = await provider.signMessage(request2);
|
|
455
|
+
options.onFinish?.(response);
|
|
456
|
+
} catch (error) {
|
|
457
|
+
console.error("[Connect] Error during sign message request", error);
|
|
458
|
+
options.onCancel?.();
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/transactions/sendBtcTransaction.ts
|
|
463
|
+
import { createUnsecuredToken as createUnsecuredToken6 } from "jsontokens";
|
|
464
|
+
var serializer = (recipient) => {
|
|
465
|
+
return recipient.map((value) => {
|
|
466
|
+
const { address, amountSats } = value;
|
|
467
|
+
return {
|
|
468
|
+
address,
|
|
469
|
+
amountSats: amountSats.toString()
|
|
470
|
+
};
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
var sendBtcTransaction = async (options) => {
|
|
474
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
475
|
+
const { recipients, senderAddress, network, message } = options.payload;
|
|
476
|
+
if (!recipients || recipients.length === 0) {
|
|
477
|
+
throw new Error("At least one recipient is required");
|
|
478
|
+
}
|
|
479
|
+
if (recipients.some(
|
|
480
|
+
(item) => typeof item.address !== "string" || typeof item.amountSats !== "bigint"
|
|
481
|
+
)) {
|
|
482
|
+
throw new Error("Incorrect recipient format");
|
|
483
|
+
}
|
|
484
|
+
if (!senderAddress) {
|
|
485
|
+
throw new Error("The sender address is required");
|
|
486
|
+
}
|
|
487
|
+
try {
|
|
488
|
+
const serializedRecipients = serializer(recipients);
|
|
489
|
+
const serializedPayload = {
|
|
490
|
+
network,
|
|
491
|
+
senderAddress,
|
|
492
|
+
message,
|
|
493
|
+
recipients: serializedRecipients
|
|
494
|
+
};
|
|
495
|
+
const request2 = createUnsecuredToken6(serializedPayload);
|
|
496
|
+
const response = await provider.sendBtcTransaction(request2);
|
|
497
|
+
options.onFinish?.(response);
|
|
498
|
+
} catch (error) {
|
|
499
|
+
console.error("[Connect] Error during send BTC transaction request", error);
|
|
500
|
+
options.onCancel?.();
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/transactions/signTransaction.ts
|
|
505
|
+
import { createUnsecuredToken as createUnsecuredToken7 } from "jsontokens";
|
|
506
|
+
var signTransaction = async (options) => {
|
|
507
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
508
|
+
const { psbtBase64, inputsToSign } = options.payload;
|
|
509
|
+
if (!psbtBase64) {
|
|
510
|
+
throw new Error("A value for psbtBase64 representing the tx hash is required");
|
|
511
|
+
}
|
|
512
|
+
if (!inputsToSign) {
|
|
513
|
+
throw new Error("An array specifying the inputs to be signed by the wallet is required");
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
const request2 = createUnsecuredToken7(options.payload);
|
|
517
|
+
const response = await provider.signTransaction(request2);
|
|
518
|
+
options.onFinish?.(response);
|
|
519
|
+
} catch (error) {
|
|
520
|
+
console.error("[Connect] Error during sign transaction request", error);
|
|
521
|
+
options.onCancel?.();
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// src/transactions/signMultipleTransactions.ts
|
|
526
|
+
import { createUnsecuredToken as createUnsecuredToken8 } from "jsontokens";
|
|
527
|
+
var signMultipleTransactions = async (options) => {
|
|
528
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
529
|
+
const { psbts } = options.payload;
|
|
530
|
+
if (!psbts || !psbts.length) {
|
|
531
|
+
throw new Error("psbts array is required");
|
|
532
|
+
}
|
|
533
|
+
if (psbts.length > 100) {
|
|
534
|
+
throw new Error("psbts array must contain less than 100 psbts");
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
const request2 = createUnsecuredToken8(options.payload);
|
|
538
|
+
const response = await provider.signMultipleTransactions(request2);
|
|
539
|
+
options.onFinish?.(response);
|
|
540
|
+
} catch (error) {
|
|
541
|
+
console.error("[Connect] Error during sign Multiple transactions request", error);
|
|
542
|
+
options.onCancel?.();
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// src/ui/index.ts
|
|
547
|
+
function createDefaultConfig(providers) {
|
|
548
|
+
const config = { providers: [] };
|
|
549
|
+
const xverseProvider = providers.find(
|
|
550
|
+
(provider) => provider.id === DefaultAdaptersInfo.xverse.id
|
|
551
|
+
);
|
|
552
|
+
config.providers.push(
|
|
553
|
+
xverseProvider ? xverseProvider : {
|
|
554
|
+
...DefaultAdaptersInfo.xverse,
|
|
555
|
+
isInstalled: false
|
|
556
|
+
}
|
|
557
|
+
);
|
|
558
|
+
const unisatProvider = providers.find((provider) => provider.id === "unisat");
|
|
559
|
+
if (unisatProvider && unisatProvider.isInstalled) {
|
|
560
|
+
config.providers.push(unisatProvider);
|
|
561
|
+
}
|
|
562
|
+
config.providers.concat(
|
|
563
|
+
providers.filter((provider) => {
|
|
564
|
+
return provider.id !== DefaultAdaptersInfo.xverse.id && provider.id !== "unisat";
|
|
565
|
+
})
|
|
566
|
+
);
|
|
567
|
+
return config;
|
|
568
|
+
}
|
|
569
|
+
export {
|
|
570
|
+
AddressPurpose,
|
|
571
|
+
AddressType,
|
|
572
|
+
BaseAdapter,
|
|
573
|
+
BitcoinNetworkType,
|
|
574
|
+
DefaultAdaptersInfo,
|
|
575
|
+
RpcErrorCode,
|
|
576
|
+
SatsConnectAdapter,
|
|
577
|
+
createDefaultConfig,
|
|
578
|
+
createInscription,
|
|
579
|
+
createRepeatInscriptions,
|
|
580
|
+
defaultAdapters,
|
|
581
|
+
getAddress,
|
|
582
|
+
getCapabilities,
|
|
583
|
+
getDefaultProvider,
|
|
584
|
+
getProviderById,
|
|
585
|
+
getProviderOrThrow,
|
|
586
|
+
getProviders,
|
|
587
|
+
getSupportedWallets,
|
|
588
|
+
isProviderInstalled,
|
|
589
|
+
removeDefaultProvider,
|
|
590
|
+
request,
|
|
591
|
+
sendBtcTransaction,
|
|
592
|
+
setDefaultProvider,
|
|
593
|
+
signMessage,
|
|
594
|
+
signMultipleTransactions,
|
|
595
|
+
signTransaction
|
|
596
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-connect/core",
|
|
3
|
-
"version": "0.0.2
|
|
4
|
-
"main": "dist/index.
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "dist/index.mjs",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
5
7
|
"files": [
|
|
6
8
|
"dist"
|
|
7
9
|
],
|
|
8
10
|
"scripts": {
|
|
9
11
|
"test": "jest",
|
|
10
12
|
"build-debug": "webpack --mode development",
|
|
11
|
-
"build": "npm run clean &&
|
|
13
|
+
"build": "npm run clean && tsup src/index.ts --format esm --dts",
|
|
12
14
|
"clean": "rimraf dist",
|
|
13
15
|
"lint": "prettier --write .",
|
|
14
16
|
"prepare": "husky install"
|
|
@@ -38,6 +40,7 @@
|
|
|
38
40
|
"stream-browserify": "^3.0.0",
|
|
39
41
|
"ts-jest": "^29.0.5",
|
|
40
42
|
"ts-loader": "^9.4.1",
|
|
43
|
+
"tsup": "^8.0.2",
|
|
41
44
|
"typescript": "^4.9.4",
|
|
42
45
|
"util": "^0.12.4",
|
|
43
46
|
"vm-browserify": "^1.1.2",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Params } from '../request';
|
|
2
|
-
import { SatsConnectAdapter } from './satsConnectAdapter';
|
|
3
|
-
import { RpcResult } from '../types';
|
|
4
|
-
declare class BaseAdapter extends SatsConnectAdapter {
|
|
5
|
-
id: string;
|
|
6
|
-
constructor(providerId: string);
|
|
7
|
-
request: <Method extends keyof import("../request").BtcRequests | keyof import("../request").StxRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method> | undefined>;
|
|
8
|
-
}
|
|
9
|
-
export { BaseAdapter };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseAdapter = void 0;
|
|
4
|
-
const satsConnectAdapter_1 = require("./satsConnectAdapter");
|
|
5
|
-
const request_1 = require("../request");
|
|
6
|
-
class BaseAdapter extends satsConnectAdapter_1.SatsConnectAdapter {
|
|
7
|
-
id = '';
|
|
8
|
-
constructor(providerId) {
|
|
9
|
-
super();
|
|
10
|
-
this.id = providerId;
|
|
11
|
-
}
|
|
12
|
-
request = async (method, params) => {
|
|
13
|
-
return (0, request_1.request)(method, params, this.id);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
exports.BaseAdapter = BaseAdapter;
|
|
17
|
-
//# sourceMappingURL=BaseAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAdapter.js","sourceRoot":"","sources":["../../src/adapters/BaseAdapter.ts"],"names":[],"mappings":";;;AACA,6DAA0D;AAC1D,wCAAqC;AAGrC,MAAM,WAAY,SAAQ,uCAAkB;IAC1C,EAAE,GAAG,EAAE,CAAC;IAER,YAAY,UAAkB;QAC5B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC;IACvB,CAAC;IAED,OAAO,GAAG,KAAK,EACb,MAAc,EACd,MAAsB,EACkB,EAAE;QAC1C,OAAO,IAAA,iBAAO,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC;CACH;AAEQ,kCAAW"}
|
package/dist/adapters/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SatsConnectAdapter } from './satsConnectAdapter';
|
|
2
|
-
import { Provider } from '../provider';
|
|
3
|
-
export declare const DefaultAdaptersInfo: Record<string, Provider>;
|
|
4
|
-
export declare const defaultAdapters: Record<string, new () => SatsConnectAdapter>;
|
|
5
|
-
export * from './satsConnectAdapter';
|
|
6
|
-
export * from './BaseAdapter';
|