@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.
- package/dist/injected-provider.js +330 -328
- package/dist/mobile.iife.js +367 -0
- package/package.json +6 -5
- package/dist/mobile.d.ts +0 -1
- package/dist/mobile.js +0 -365
- package/dist/mobile.js.map +0 -1
|
@@ -1,174 +1,177 @@
|
|
|
1
|
-
export default ({branch, commitSha, version}) =>
|
|
2
|
-
|
|
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
|
-
|
|
1
|
+
export default ({branch, commitSha, version}) => `(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
|
+
}
|
|
33
36
|
|
|
34
37
|
//#endregion
|
|
35
38
|
//#region src/crypto-random-uuid-polyfill.ts
|
|
36
|
-
function generateUUID() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
crypto.randomUUID = crypto.randomUUID ?? generateUUID;
|
|
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;
|
|
47
50
|
|
|
48
51
|
//#endregion
|
|
49
52
|
//#region src/legacy-requests.ts
|
|
50
53
|
/**
|
|
51
|
-
* Inpage Script (LeatherProvider) <-> Content Script
|
|
52
|
-
*/
|
|
53
|
-
var DomEventName = /* @__PURE__ */ function(DomEventName\$1) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}(DomEventName || {});
|
|
63
|
-
const MESSAGE_SOURCE = "stacks-wallet";
|
|
64
|
-
var ExternalMethods = /* @__PURE__ */ function(ExternalMethods\$1) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}(ExternalMethods || {});
|
|
79
|
-
function isValidEvent(event, method) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
async function callAndReceive(methodName, opts = {}) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
}
|
|
95
99
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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);
|
|
147
152
|
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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);
|
|
164
169
|
}
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
authenticationRequest: async (authenticationRequest) => {
|
|
171
|
-
console.warn(\`
|
|
170
|
+
window.addEventListener("message", handleMessage);
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
authenticationRequest: async (authenticationRequest) => {
|
|
174
|
+
console.warn(\`
|
|
172
175
|
WARNING: Legacy Leather request detected
|
|
173
176
|
|
|
174
177
|
Leather now uses an RPC-style API, that can be used directly,
|
|
@@ -178,188 +181,187 @@ function legacyRequests() {
|
|
|
178
181
|
|
|
179
182
|
See our docs for more information https://leather.gitbook.io/
|
|
180
183
|
\`);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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);
|
|
191
196
|
}
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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);
|
|
208
213
|
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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);
|
|
225
230
|
}
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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);
|
|
242
247
|
}
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
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();
|
|
247
258
|
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function getLegacyRequests(platform) {
|
|
251
|
-
switch (platform) {
|
|
252
|
-
case "extension": return legacyRequests();
|
|
253
|
-
case "mobile":
|
|
254
|
-
default: return placeholderLegacyRequests();
|
|
255
259
|
}
|
|
256
|
-
}
|
|
257
260
|
|
|
258
261
|
//#endregion
|
|
259
262
|
//#region src/index.ts
|
|
260
|
-
function initInpageProvider({ onDispatch, env }) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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: () => {}
|
|
282
326
|
});
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
window.addEventListener("message", handleMessage);
|
|
327
|
+
} catch {
|
|
328
|
+
console.log("Unable to set StacksProvider");
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
Object.defineProperty(window, "HiroWalletProvider", {
|
|
332
|
+
get: () => warnAboutDeprecatedProvider(provider),
|
|
333
|
+
set: () => {}
|
|
292
334
|
});
|
|
335
|
+
} catch {
|
|
336
|
+
console.log("Unable to set HiroWalletProvider");
|
|
293
337
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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");
|
|
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);
|
|
342
347
|
}
|
|
343
|
-
if (typeof window.btc === "undefined") window.btc = warnAboutDeprecatedProvider(provider);
|
|
344
|
-
}
|
|
345
348
|
|
|
346
349
|
//#endregion
|
|
347
350
|
//#region src/mobile.ts
|
|
348
|
-
window.onMessageFromRN = function(str) {
|
|
349
|
-
|
|
350
|
-
};
|
|
351
|
-
initInpageProvider({
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
});
|
|
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: "${branch}",
|
|
361
|
+
commitSha: "${commitSha}",
|
|
362
|
+
version: "${version}"
|
|
363
|
+
}
|
|
364
|
+
});
|
|
362
365
|
|
|
363
366
|
//#endregion
|
|
364
|
-
|
|
365
|
-
//# sourceMappingURL=mobile.js.map`
|
|
367
|
+
})();`
|