-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
284 lines (250 loc) · 11 KB
/
index.html
1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elraulito BTC Connect</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
body {
background-color: #f0f0f0; /* Light grey background */
padding: 20px; /* Add some padding to the body */
}
#container {
text-align: center; /* Center the contents */
background-color: white; /* White background for the container */
padding: 20px; /* Add some padding to the container */
border-radius: 8px; /* Rounded corners for the container */
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Box shadow for a subtle effect */
max-width: 600px; /* Limit the width of the container */
margin: 0 auto; /* Center the container horizontally */
}
.image-button-container {
display: flex;
align-items: center; /* Center items vertically */
justify-content: center; /* Center items horizontally */
margin-bottom: 20px; /* Add some spacing between each image-button pair */
}
.material-button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 4px;
color: white;
background-color: #2196F3;
transition: background-color 0.3s ease;
margin-left: 10px; /* Add some spacing between the image and button */
}
.material-button:hover {
background-color: #0e7cbb;
}
.material-button i {
margin-right: 8px;
}
.text-field {
margin: 10px 0;
padding: 10px;
font-size: 16px;
width: 100%;
max-width: 400px;
box-sizing: border-box;
}
#title {
font-size: 24px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div id="container">
<h1 id="title">Elraulito BTC Connect</h1>
<div class="image-button-container">
<img src="xverse-logo.png" alt="Xverse Logo" width="100">
<button id="xverseButton" class="material-button"><i class="material-icons">cloud</i>Xverse</button>
</div>
<div class="image-button-container">
<img src="leather-logo.png" alt="Leather Logo" width="100">
<button id="leatherButton" class="material-button"><i class="material-icons">wallet_giftcard</i>Leather</button>
</div>
<div class="image-button-container">
<img src="unisat-logo.png" alt="Unisat Logo" width="100">
<button id="unisatButton" class="material-button"><i class="material-icons">satellite</i>Unisat</button>
</div>
<div class="image-button-container">
<img src="okx-logo.png" alt="OKX Logo" width="100">
<button id="okxButton" class="material-button"><i class="material-icons">verified_user</i>OKX</button>
</div>
<div>
<input type="text" id="hexPsbt" class="text-field" placeholder="PSBT Hex String">
<button id="signButton" class="material-button"><i class="material-icons">done</i>Sign PSBT Leather</button>
<button id="signButtonXverse" class="material-button"><i class="material-icons">done</i>Sign PSBT Xverse</button>
</div>
<div>
<input type="text" id="btcAddress" class="text-field" placeholder="BTC Address" readonly>
<input type="text" id="ordinalAddress" class="text-field" placeholder="Ordinal Address" readonly>
<input type="text" id="btcKey" class="text-field" placeholder="BTC Key" readonly>
<input type="text" id="ordinalKey" class="text-field" placeholder="Ordinal Key" readonly>
</div>
</div>
<script>
async function connectXverse() {
try {
let walletData = await xverseconnect();
const btcAddressField = document.getElementById('btcAddress');
const ordinalAddressField = document.getElementById('ordinalAddress');
const btcKeyField = document.getElementById('btcKey');
const ordinalKeyField = document.getElementById('ordinalKey');
walletData.addresses.forEach(addressInfo => {
if (addressInfo.purpose === 'payment') {
btcAddressField.value = addressInfo.address;
btcKeyField.value = addressInfo.publicKey;
} else if (addressInfo.purpose === 'ordinals') {
ordinalAddressField.value = addressInfo.address;
ordinalKeyField.value = addressInfo.publicKey.slice(2);
}
});
} catch (error) {
console.error('Error connecting with Xverse:', error);
}
}
async function getAddressFromLeather() {
try {
const response = await window.LeatherProvider?.request("getAddresses");
const btcAddressField = document.getElementById('btcAddress');
const ordinalAddressField = document.getElementById('ordinalAddress');
const btcKeyField = document.getElementById('btcKey');
const ordinalKeyField = document.getElementById('ordinalKey');
response.result.addresses.forEach(addressInfo => {
if (addressInfo.type === 'p2wpkh' && addressInfo.symbol === 'BTC') {
btcAddressField.value = addressInfo.address;
btcKeyField.value = addressInfo.publicKey;
} else if (addressInfo.type === 'p2tr' && addressInfo.symbol === 'BTC') {
ordinalAddressField.value = addressInfo.address;
ordinalKeyField.value = addressInfo.publicKey.slice(2); // Remove first 2 characters
}
});
} catch (error) {
console.error('Error connecting with Leather:', error);
}
}
async function requestAccountsFromUnisat() {
try {
const addresses = await window.unisat.requestAccounts();
const keys = await window.unisat.getPublicKey();
const btcAddressField = document.getElementById('btcAddress');
const ordinalAddressField = document.getElementById('ordinalAddress');
const btcKeyField = document.getElementById('btcKey');
const ordinalKeyField = document.getElementById('ordinalKey');
if (addresses.length > 0) {
btcAddressField.value = addresses[0];
if (keys.length > 0) {
btcKeyField.value = keys;
}
}
if (addresses.length > 0) {
ordinalAddressField.value = addresses[0];
if (keys.length > 0) {
ordinalKeyField.value = keys; // Remove first 2 characters
}
}
} catch (error) {
console.error('Error connecting with Unisat:', error);
}
}
async function connectBitcoinFromOkx() {
try {
const addresses = await window.okxwallet.bitcoin.requestAccounts();
const keys = await window.okxwallet.bitcoin.getPublicKey();
const btcAddressField = document.getElementById('btcAddress');
const ordinalAddressField = document.getElementById('ordinalAddress');
const btcKeyField = document.getElementById('btcKey');
const ordinalKeyField = document.getElementById('ordinalKey');
if (addresses.length > 0) {
btcAddressField.value = addresses[0];
if (keys.length > 0) {
btcKeyField.value = keys;
}
}
if (addresses.length > 0) {
ordinalAddressField.value = addresses[0];
if (keys.length > 0) {
ordinalKeyField.value = keys; // Remove first 2 characters
}
}
} catch (error) {
console.error('Error connecting with Unisat:', error);
}
}
async function signPsbtLeather(hexPsbt) {
try {
// Get the hex PSBT value from the input field
const hexPsbt = document.getElementById('hexPsbt').value.trim();
// Example request parameters
const exampleParams = {
hex: hexPsbt,
network: 'mainnet', // Or 'Testnet' or other supported networks
broadcast: true // Whether to finalize and broadcast the transaction
};
// Prepare request parameters
const requestParams = { ...exampleParams };
// Make request to sign the PSBT
const response = await window.LeatherProvider.request('signPsbt', requestParams);
// Handle the response as needed
console.log(response);
} catch (error) {
// Handle errors
console.error(error);
}
}
async function signPsbtXverse() {
try {
// Get the hex PSBT value from the input field
const base64Psbt = document.getElementById('hexPsbt').value.trim();
console.log(base64Psbt)
// Make request to sign the PSBT
const response = await window.xversesign("33av9pdn8Xi6RCAkaXx99jnGkvd1MVnJJu",base64Psbt,[0])
// Handle the response as needed
console.log(response);
} catch (error) {
// Handle errors
console.error(error);
}
}
document.getElementById("signButton").addEventListener("click", () => {
signPsbtLeather();
});
document.getElementById("signButtonXverse").addEventListener("click", () => {
signPsbtXverse();
});
document.addEventListener("DOMContentLoaded", function() {
var script = document.createElement('script');
script.src = "dist/bundle.js";
document.body.appendChild(script);
// Attach event listeners after the script is loaded
script.onload = function() {
console.log("Exported functions from bundle.js:", window);
document.getElementById("xverseButton").addEventListener("click", connectXverse);
if (window.LeatherProvider) {
console.log("Leather installed");
document.getElementById("leatherButton").addEventListener("click", getAddressFromLeather);
} else {
console.log("Leather not found");
}
if (window.unisat) {
console.log("Unisat installed");
document.getElementById("unisatButton").addEventListener("click", requestAccountsFromUnisat);
} else {
console.log("Unisat not found");
}
if (window.okxwallet) {
console.log("OKX installed");
document.getElementById("okxButton").addEventListener("click", connectBitcoinFromOkx);
} else {
console.log("OKX not found");
}
};
});
</script>
</body>
</html>