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