@leather.io/provider 1.6.14 → 1.6.16

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.
@@ -0,0 +1,367 @@
1
+ (function() {
2
+
3
+
4
+ //#region src/add-leather-to-providers.ts
5
+ function addLeatherToProviders() {
6
+ const win = window;
7
+ if (!win.btc_providers) win.btc_providers = [];
8
+ win.btc_providers.push({
9
+ id: "LeatherProvider",
10
+ name: "Leather",
11
+ icon: "data:image/svg;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiByeD0iMjYuODM4NyIgZmlsbD0iIzEyMTAwRiIvPgo8cGF0aCBkPSJNNzQuOTE3MSA1Mi43MTE0QzgyLjQ3NjYgNTEuNTQwOCA5My40MDg3IDQzLjU4MDQgOTMuNDA4NyAzNy4zNzYxQzkzLjQwODcgMzUuNTAzMSA5MS44OTY4IDM0LjIxNTQgODkuNjg3MSAzNC4yMTU0Qzg1LjUwMDQgMzQuMjE1NCA3OC40MDYxIDQwLjUzNjggNzQuOTE3MSA1Mi43MTE0Wk0zOS45MTEgODMuNDk5MUMzMC4wMjU2IDgzLjQ5OTEgMjkuMjExNSA5My4zMzI0IDM5LjA5NjkgOTMuMzMyNEM0My41MTYzIDkzLjMzMjQgNDguODY2MSA5MS41NzY0IDUxLjY1NzMgODguNDE1N0M0Ny41ODY4IDg0LjkwMzggNDQuMjE0MSA4My40OTkxIDM5LjkxMSA4My40OTkxWk0xMDIuODI5IDc5LjI4NDhDMTAzLjQxIDk1Ljc5MDcgOTUuMDM2OSAxMDUuMDM5IDgwLjg0ODQgMTA1LjAzOUM3Mi40NzQ4IDEwNS4wMzkgNjguMjg4MSAxMDEuODc4IDU5LjMzMyA5Ni4wMjQ4QzU0LjY4MSAxMDEuMTc2IDQ1Ljg0MjMgMTA1LjAzOSAzOC41MTU0IDEwNS4wMzlDMTMuMjc4NSAxMDUuMDM5IDE0LjMyNTIgNzIuODQ2MyA0MC4wMjczIDcyLjg0NjNDNDUuMzc3MSA3Mi44NDYzIDQ5LjkxMjggNzQuMjUxMSA1NS43Mjc3IDc3Ljg4TDU5LjU2NTYgNjQuNDE3N0M0My43NDg5IDYwLjA4NjQgMzUuODQwNSA0Ny45MTE4IDQzLjYzMjYgMzAuNDY5M0g1Ni4xOTI5QzQ5LjIxNSA0Mi4wNTg2IDUzLjk4MzIgNTEuNjU3OCA2Mi44MjIgNTIuNzExNEM2Ny41OTAzIDM1LjczNzIgNzcuODI0NiAyMi41MDkgOTEuNDMxNiAyMi41MDlDOTkuMTA3NCAyMi41MDkgMTA1LjE1NSAyNy41NDI4IDEwNS4xNTUgMzYuNjczN0MxMDUuMTU1IDUxLjMwNjYgODYuMDgxOSA2My4yNDcxIDcxLjY2MDcgNjQuNDE3N0w2NS43Mjk1IDg1LjM3MjFDNzIuNDc0OCA5My4yMTUzIDkxLjE5OSAxMDAuODI0IDkxLjE5OSA3OS4yODQ4SDEwMi44MjlaIiBmaWxsPSIjRjdGNUYzIi8+Cjwvc3ZnPgo=",
12
+ webUrl: "https://leather.io",
13
+ chromeWebStoreUrl: "https://chromewebstore.google.com/detail/leather/ldinpeekobnhjjdofggfgjlcehhmanlj",
14
+ methods: [
15
+ "open",
16
+ "getInfo",
17
+ "supportedMethods",
18
+ "openSwap",
19
+ "getAddresses",
20
+ "stx_updateProfile",
21
+ "stx_signMessage",
22
+ "stx_transferStx",
23
+ "stx_transferSip10Ft",
24
+ "stx_transferSip9Nft",
25
+ "stx_signTransaction",
26
+ "stx_signStructuredMessage",
27
+ "stx_getAddresses",
28
+ "stx_deployContract",
29
+ "stx_callContract",
30
+ "signPsbt",
31
+ "signMessage",
32
+ "sendTransfer"
33
+ ]
34
+ });
35
+ }
36
+
37
+ //#endregion
38
+ //#region src/crypto-random-uuid-polyfill.ts
39
+ function generateUUID() {
40
+ const array = new Uint8Array(16);
41
+ crypto.getRandomValues(array);
42
+ return [...array].map((b, i) => ([
43
+ 4,
44
+ 6,
45
+ 8,
46
+ 10
47
+ ].includes(i) ? "-" : "") + (b % 16).toString(16)).join("");
48
+ }
49
+ crypto.randomUUID = crypto.randomUUID ?? generateUUID;
50
+
51
+ //#endregion
52
+ //#region src/legacy-requests.ts
53
+ /**
54
+ * Inpage Script (LeatherProvider) <-> Content Script
55
+ */
56
+ var DomEventName = /* @__PURE__ */ function(DomEventName$1) {
57
+ DomEventName$1["request"] = "request";
58
+ DomEventName$1["authenticationRequest"] = "hiroWalletStacksAuthenticationRequest";
59
+ DomEventName$1["signatureRequest"] = "hiroWalletSignatureRequest";
60
+ DomEventName$1["structuredDataSignatureRequest"] = "hiroWalletStructuredDataSignatureRequest";
61
+ DomEventName$1["transactionRequest"] = "hiroWalletStacksTransactionRequest";
62
+ DomEventName$1["profileUpdateRequest"] = "hiroWalletProfileUpdateRequest";
63
+ DomEventName$1["psbtRequest"] = "hiroWalletPsbtRequest";
64
+ return DomEventName$1;
65
+ }(DomEventName || {});
66
+ const MESSAGE_SOURCE = "stacks-wallet";
67
+ var ExternalMethods = /* @__PURE__ */ function(ExternalMethods$1) {
68
+ ExternalMethods$1["transactionRequest"] = "hiroWalletTransactionRequest";
69
+ ExternalMethods$1["transactionResponse"] = "hiroWalletTransactionResponse";
70
+ ExternalMethods$1["authenticationRequest"] = "hiroWalletAuthenticationRequest";
71
+ ExternalMethods$1["authenticationResponse"] = "hiroWalletAuthenticationResponse";
72
+ ExternalMethods$1["signatureRequest"] = "hiroWalletSignatureRequest";
73
+ ExternalMethods$1["signatureResponse"] = "hiroWalletSignatureResponse";
74
+ ExternalMethods$1["structuredDataSignatureRequest"] = "hiroWalletStructuredDataSignatureRequest";
75
+ ExternalMethods$1["structuredDataSignatureResponse"] = "hiroWalletStructuredDataSignatureResponse";
76
+ ExternalMethods$1["profileUpdateRequest"] = "hiroWalletProfileUpdateRequest";
77
+ ExternalMethods$1["profileUpdateResponse"] = "hiroWalletProfileUpdateResponse";
78
+ ExternalMethods$1["psbtRequest"] = "hiroWalletPsbtRequest";
79
+ ExternalMethods$1["psbtResponse"] = "hiroWalletPsbtResponse";
80
+ return ExternalMethods$1;
81
+ }(ExternalMethods || {});
82
+ function isValidEvent(event, method) {
83
+ const { data } = event;
84
+ const correctSource = data.source === MESSAGE_SOURCE;
85
+ const correctMethod = data.method === method;
86
+ return correctSource && correctMethod && !!data.payload;
87
+ }
88
+ async function callAndReceive(methodName, opts = {}) {
89
+ return new Promise((resolve, reject) => {
90
+ const timeout = setTimeout(() => {
91
+ reject("Unable to get response from Blockstack extension");
92
+ }, 1e3);
93
+ function waitForResponse(event) {
94
+ if (event.data.source === "blockstack-extension" && event.data.method === `${methodName}Response`) {
95
+ clearTimeout(timeout);
96
+ window.removeEventListener("message", waitForResponse);
97
+ resolve(event.data);
98
+ }
99
+ }
100
+ window.addEventListener("message", waitForResponse);
101
+ window.postMessage({
102
+ method: methodName,
103
+ source: "blockstack-app",
104
+ ...opts
105
+ }, window.location.origin);
106
+ });
107
+ }
108
+ function placeholderLegacyRequests() {
109
+ return {
110
+ getURL: () => {
111
+ throw new Error("This function i deprecated");
112
+ },
113
+ structuredDataSignatureRequest: () => {
114
+ throw new Error("This function is deprecated");
115
+ },
116
+ signatureRequest: () => {
117
+ throw new Error("This function is deprecated");
118
+ },
119
+ authenticationRequest: () => {
120
+ throw new Error("This function is deprecated");
121
+ },
122
+ transactionRequest: () => {
123
+ throw new Error("This function is deprecated");
124
+ },
125
+ psbtRequest: () => {
126
+ throw new Error("This function is deprecated");
127
+ },
128
+ profileUpdateRequest: () => {
129
+ throw new Error("This function is deprecated");
130
+ }
131
+ };
132
+ }
133
+ function legacyRequests() {
134
+ return {
135
+ getURL: async () => {
136
+ const { url } = await callAndReceive("getURL");
137
+ return url;
138
+ },
139
+ structuredDataSignatureRequest: async (signatureRequest) => {
140
+ const event = new CustomEvent(DomEventName.structuredDataSignatureRequest, { detail: { signatureRequest } });
141
+ document.dispatchEvent(event);
142
+ return new Promise((resolve, reject) => {
143
+ function handleMessage(event$1) {
144
+ if (!isValidEvent(event$1, ExternalMethods.signatureResponse)) return;
145
+ if (event$1.data.payload?.signatureRequest !== signatureRequest) return;
146
+ window.removeEventListener("message", handleMessage);
147
+ if (event$1.data.payload.signatureResponse === "cancel") {
148
+ reject(event$1.data.payload.signatureResponse);
149
+ return;
150
+ }
151
+ if (typeof event$1.data.payload.signatureResponse !== "string") resolve(event$1.data.payload.signatureResponse);
152
+ }
153
+ window.addEventListener("message", handleMessage);
154
+ });
155
+ },
156
+ signatureRequest: async (signatureRequest) => {
157
+ const event = new CustomEvent(DomEventName.signatureRequest, { detail: { signatureRequest } });
158
+ document.dispatchEvent(event);
159
+ return new Promise((resolve, reject) => {
160
+ function handleMessage(event$1) {
161
+ if (!isValidEvent(event$1, ExternalMethods.signatureResponse)) return;
162
+ if (event$1.data.payload?.signatureRequest !== signatureRequest) return;
163
+ window.removeEventListener("message", handleMessage);
164
+ if (event$1.data.payload.signatureResponse === "cancel") {
165
+ reject(event$1.data.payload.signatureResponse);
166
+ return;
167
+ }
168
+ if (typeof event$1.data.payload.signatureResponse !== "string") resolve(event$1.data.payload.signatureResponse);
169
+ }
170
+ window.addEventListener("message", handleMessage);
171
+ });
172
+ },
173
+ authenticationRequest: async (authenticationRequest) => {
174
+ console.warn(`
175
+ WARNING: Legacy Leather request detected
176
+
177
+ Leather now uses an RPC-style API, that can be used directly,
178
+ rather than through libraries such as Stacks Connect. For example,
179
+ to get a user's addresses, you should use the
180
+ LeatherProvider.request('getAddresses') method.
181
+
182
+ See our docs for more information https://leather.gitbook.io/
183
+ `);
184
+ const event = new CustomEvent(DomEventName.authenticationRequest, { detail: { authenticationRequest } });
185
+ document.dispatchEvent(event);
186
+ return new Promise((resolve, reject) => {
187
+ function handleMessage(event$1) {
188
+ if (!isValidEvent(event$1, ExternalMethods.authenticationResponse)) return;
189
+ if (event$1.data.payload?.authenticationRequest !== authenticationRequest) return;
190
+ window.removeEventListener("message", handleMessage);
191
+ if (event$1.data.payload.authenticationResponse === "cancel") {
192
+ reject(event$1.data.payload.authenticationResponse);
193
+ return;
194
+ }
195
+ resolve(event$1.data.payload.authenticationResponse);
196
+ }
197
+ window.addEventListener("message", handleMessage);
198
+ });
199
+ },
200
+ transactionRequest: async (transactionRequest) => {
201
+ const event = new CustomEvent(DomEventName.transactionRequest, { detail: { transactionRequest } });
202
+ document.dispatchEvent(event);
203
+ return new Promise((resolve, reject) => {
204
+ function handleMessage(event$1) {
205
+ if (!isValidEvent(event$1, ExternalMethods.transactionResponse)) return;
206
+ if (event$1.data.payload?.transactionRequest !== transactionRequest) return;
207
+ window.removeEventListener("message", handleMessage);
208
+ if (event$1.data.payload.transactionResponse === "cancel") {
209
+ reject(event$1.data.payload.transactionResponse);
210
+ return;
211
+ }
212
+ if (typeof event$1.data.payload.transactionResponse !== "string") resolve(event$1.data.payload.transactionResponse);
213
+ }
214
+ window.addEventListener("message", handleMessage);
215
+ });
216
+ },
217
+ psbtRequest: async (psbtRequest) => {
218
+ const event = new CustomEvent(DomEventName.psbtRequest, { detail: { psbtRequest } });
219
+ document.dispatchEvent(event);
220
+ return new Promise((resolve, reject) => {
221
+ function handleMessage(event$1) {
222
+ if (!isValidEvent(event$1, ExternalMethods.psbtResponse)) return;
223
+ if (event$1.data.payload?.psbtRequest !== psbtRequest) return;
224
+ window.removeEventListener("message", handleMessage);
225
+ if (event$1.data.payload.psbtResponse === "cancel") {
226
+ reject(event$1.data.payload.psbtResponse);
227
+ return;
228
+ }
229
+ if (typeof event$1.data.payload.psbtResponse !== "string") resolve(event$1.data.payload.psbtResponse);
230
+ }
231
+ window.addEventListener("message", handleMessage);
232
+ });
233
+ },
234
+ profileUpdateRequest: async (profileUpdateRequest) => {
235
+ const event = new CustomEvent(DomEventName.profileUpdateRequest, { detail: { profileUpdateRequest } });
236
+ document.dispatchEvent(event);
237
+ return new Promise((resolve, reject) => {
238
+ function handleMessage(event$1) {
239
+ if (!isValidEvent(event$1, ExternalMethods.profileUpdateResponse)) return;
240
+ if (event$1.data.payload?.profileUpdateRequest !== profileUpdateRequest) return;
241
+ window.removeEventListener("message", handleMessage);
242
+ if (event$1.data.payload.profileUpdateResponse === "cancel") {
243
+ reject(event$1.data.payload.profileUpdateResponse);
244
+ return;
245
+ }
246
+ if (typeof event$1.data.payload.profileUpdateResponse !== "string") resolve(event$1.data.payload.profileUpdateResponse);
247
+ }
248
+ window.addEventListener("message", handleMessage);
249
+ });
250
+ }
251
+ };
252
+ }
253
+ function getLegacyRequests(platform) {
254
+ switch (platform) {
255
+ case "extension": return legacyRequests();
256
+ case "mobile":
257
+ default: return placeholderLegacyRequests();
258
+ }
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/index.ts
263
+ function initInpageProvider({ onDispatch, env }) {
264
+ addLeatherToProviders();
265
+ const provider = {
266
+ isLeather: true,
267
+ ...getLegacyRequests(env.platform),
268
+ getProductInfo() {
269
+ return {
270
+ version: env.version,
271
+ name: "Leather",
272
+ meta: {
273
+ tag: env.branch,
274
+ commit: env.commitSha
275
+ }
276
+ };
277
+ },
278
+ request(method, params) {
279
+ const id = crypto.randomUUID();
280
+ onDispatch({
281
+ jsonrpc: "2.0",
282
+ id,
283
+ method,
284
+ params: params ?? {}
285
+ });
286
+ return new Promise((resolve, reject) => {
287
+ function handleMessage(event) {
288
+ const response = typeof event.data === "object" ? event.data : JSON.parse(event.data);
289
+ if (response.id !== id) return;
290
+ window.removeEventListener("message", handleMessage);
291
+ if ("error" in response) return reject(response);
292
+ return resolve(response);
293
+ }
294
+ window.addEventListener("message", handleMessage);
295
+ });
296
+ }
297
+ };
298
+ function consoleDeprecationNotice(text) {
299
+ console.warn(`Deprecation warning: ${text}`);
300
+ }
301
+ function warnAboutDeprecatedProvider(legacyProvider) {
302
+ return Object.fromEntries(Object.entries(legacyProvider).map(([key, value]) => {
303
+ if (typeof value === "function") return [key, (...args) => {
304
+ switch (key) {
305
+ case "authenticationRequest":
306
+ consoleDeprecationNotice(`Use LeatherProvider.request('getAddresses') instead, see docs https://leather.gitbook.io/developers/bitcoin/connect-users/get-addresses`);
307
+ break;
308
+ case "psbtRequest":
309
+ consoleDeprecationNotice(`Use LeatherProvider.request('signPsbt') instead, see docs https://leather.gitbook.io/developers/bitcoin/sign-transactions/partially-signed-bitcoin-transactions-psbts`);
310
+ break;
311
+ case "structuredDataSignatureRequest":
312
+ case "signatureRequest":
313
+ consoleDeprecationNotice(`Use LeatherProvider.request('stx_signMessage') instead`);
314
+ break;
315
+ default: consoleDeprecationNotice("The provider object is deprecated. Use `LeatherProvider` instead");
316
+ }
317
+ return value(...args);
318
+ }];
319
+ return [key, value];
320
+ }));
321
+ }
322
+ try {
323
+ Object.defineProperty(window, "StacksProvider", {
324
+ get: () => warnAboutDeprecatedProvider(provider),
325
+ set: () => {}
326
+ });
327
+ } catch {
328
+ console.log("Unable to set StacksProvider");
329
+ }
330
+ try {
331
+ Object.defineProperty(window, "HiroWalletProvider", {
332
+ get: () => warnAboutDeprecatedProvider(provider),
333
+ set: () => {}
334
+ });
335
+ } catch {
336
+ console.log("Unable to set HiroWalletProvider");
337
+ }
338
+ try {
339
+ Object.defineProperty(window, "LeatherProvider", {
340
+ get: () => provider,
341
+ set: () => {}
342
+ });
343
+ } catch {
344
+ console.warn("Unable to set LeatherProvider");
345
+ }
346
+ if (typeof window.btc === "undefined") window.btc = warnAboutDeprecatedProvider(provider);
347
+ }
348
+
349
+ //#endregion
350
+ //#region src/mobile.ts
351
+ window.onMessageFromRN = function(str) {
352
+ window.postMessage(str, window.location.origin);
353
+ };
354
+ initInpageProvider({
355
+ onDispatch(rpcRequest) {
356
+ window.ReactNativeWebView.postMessage(JSON.stringify(rpcRequest));
357
+ },
358
+ env: {
359
+ platform: "mobile",
360
+ branch: "replace_branch",
361
+ commitSha: "replace_commit_sha",
362
+ version: "replace_version"
363
+ }
364
+ });
365
+
366
+ //#endregion
367
+ })();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@leather.io/provider",
3
3
  "author": "leather-wallet",
4
4
  "description": "LeatherProvider package for Leather",
5
- "version": "1.6.14",
5
+ "version": "1.6.16",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "exports": {
@@ -17,16 +17,16 @@
17
17
  "@stacks/profile": "7.0.2",
18
18
  "@stacks/transactions": "7.0.5",
19
19
  "zod": "4.0.17",
20
- "@leather.io/rpc": "2.21.6",
21
- "@leather.io/models": "0.52.0",
22
- "@leather.io/utils": "0.49.6"
20
+ "@leather.io/rpc": "2.21.8",
21
+ "@leather.io/utils": "0.49.8",
22
+ "@leather.io/models": "0.52.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "prettier": "3.5.1",
26
26
  "tsdown": "0.16.5",
27
27
  "vitest": "2.1.9",
28
28
  "@leather.io/prettier-config": "0.9.0",
29
- "@leather.io/test-config": "0.1.2"
29
+ "@leather.io/test-config": "0.1.3"
30
30
  },
31
31
  "files": [
32
32
  "dist"
@@ -45,6 +45,7 @@
45
45
  "lint:fix": "pnpm lint --fix",
46
46
  "prepublish": "pnpm build",
47
47
  "test": "echo \"Error: no test specified\" && exit 1",
48
+ "test:unit": "vitest run",
48
49
  "typecheck": "tsc --noEmit",
49
50
  "types": "tsc --declaration --emitDeclarationOnly"
50
51
  }
package/dist/mobile.d.ts DELETED
@@ -1 +0,0 @@
1
- export { };