add retrieve address function and btc key generation

This commit is contained in:
raviycoder 2024-07-11 21:21:53 +05:30
parent 3d9a6909d3
commit ee26b801b8
2 changed files with 1216 additions and 27 deletions

1049
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -230,6 +230,99 @@
</header>
<div id="transaction_result_popup__content" class="grid gap-2"></div>
</sm-popup>
<sm-popup id="retrieve_btc_addr_popup">
<header slot="header" class="popup__header">
<div class="flex align-center">
<button class="popup__header__close" onclick="closePopup()">
<svg
class="icon"
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"
/>
</svg>
</button>
</div>
</header>
<section class="grid gap-1-5">
<div class="grid gap-0-5">
<h4>Did you forget your Binance Address?</h4>
<p>
If you have your Binance Private Key, enter it here and recover your
Binance Address.
</p>
</div>
<sm-form>
<div id="recovered_btc_addr_wrapper" class="hidden">
<h5>Recovered Binance Address</h5>
<sm-copy id="recovered_btc_addr"></sm-copy>
</div>
<sm-input
id="retrieve_btc_addr_field"
type="password"
placeholder="Binance Private Key"
class="password-field"
data-private-key
required
autofocus
>
<label slot="right" class="interact">
<input
type="checkbox"
class="hidden"
autocomplete="off"
readonly
onchange="togglePrivateKeyVisibility(this)"
/>
<svg
class="icon invisible"
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
>
<title>Hide password</title>
<path
d="M0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0z"
fill="none"
/>
<path
d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"
/>
</svg>
<svg
class="icon visible"
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
>
<title>Show password</title>
<path d="M0 0h24v24H0z" fill="none" />
<path
d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
/>
</svg>
</label>
</sm-input>
<button
class="button button--primary cta"
type="submit"
onclick="retrieveBinanceAddr()"
>
Recover
</button>
</sm-form>
</section>
</sm-popup>
<script>
/* Constants for FLO blockchain operations !!Make sure to add this at beginning!! */
const floGlobals = {
@ -979,7 +1072,7 @@
.closest(".contact")
.querySelector("sm-copy").value = e.target.value)}
>
<sm-chip value=${floAddress} selected>FLO</sm-chip>
<sm-chip value=${floAddress} selected>${floAddress.startsWith("F")?"FLO":"BTC"}</sm-chip>
<sm-chip value=${BSCAddress}>BSC</sm-chip>
</sm-chips>
`}
@ -1020,9 +1113,12 @@
if (/^[0-9a-fA-F]{64}$/.test(keyToConvert)) {
keyToConvert = coinjs.privkey2wif(keyToConvert);
}
console.log("lkkkk", keyToConvert);
const ethPrivateKey = coinjs.wif2privkey(keyToConvert).privkey;
BSCAddress = floEthereum.ethAddressFromPrivateKey(ethPrivateKey);
floAddress = floCrypto.getFloID(keyToConvert);
floAddress = keyToConvert.startsWith("R")
? floCrypto.getFloID(keyToConvert)
: btcOperator.bech32Address(keyToConvert);
}
}
if (!BSCAddress) return;
@ -1062,7 +1158,7 @@
${floAddress && floAddress !== BSCAddress
? html`
<div class="grid">
<div class="label">FLO address</div>
<div class="label">${floAddress.startsWith("F")?"FLO":"BTC"} address</div>
<sm-copy
id="flo_address"
value="${floAddress}"
@ -1622,32 +1718,53 @@
html`
<div class="grid gap-1">
<h2>Don't have an Binance address? Create one</h2>
<button
class="button button--primary interactive gap-0-5 margin-right-auto"
onclick=${generateNewID}
>
<svg
class="icon"
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
<section class="create-buttons">
<button
class="button button--primary interactive gap-0-5 margin-right-auto"
onclick=${generateNewID}
>
<g>
<rect fill="none" height="24" width="24" />
</g>
<g>
<svg
class="icon"
xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
>
<g>
<path
d="M18.32,4.26C16.84,3.05,15.01,2.25,13,2.05v2.02c1.46,0.18,2.79,0.76,3.9,1.62L18.32,4.26z M19.93,11h2.02 c-0.2-2.01-1-3.84-2.21-5.32L18.31,7.1C19.17,8.21,19.75,9.54,19.93,11z M18.31,16.9l1.43,1.43c1.21-1.48,2.01-3.32,2.21-5.32 h-2.02C19.75,14.46,19.17,15.79,18.31,16.9z M13,19.93v2.02c2.01-0.2,3.84-1,5.32-2.21l-1.43-1.43 C15.79,19.17,14.46,19.75,13,19.93z M13,12V7h-2v5H7l5,5l5-5H13z M11,19.93v2.02c-5.05-0.5-9-4.76-9-9.95s3.95-9.45,9-9.95v2.02 C7.05,4.56,4,7.92,4,12S7.05,19.44,11,19.93z"
/>
<rect fill="none" height="24" width="24" />
</g>
</g>
</svg>
Generate new address
</button>
<g>
<g>
<path
d="M18.32,4.26C16.84,3.05,15.01,2.25,13,2.05v2.02c1.46,0.18,2.79,0.76,3.9,1.62L18.32,4.26z M19.93,11h2.02 c-0.2-2.01-1-3.84-2.21-5.32L18.31,7.1C19.17,8.21,19.75,9.54,19.93,11z M18.31,16.9l1.43,1.43c1.21-1.48,2.01-3.32,2.21-5.32 h-2.02C19.75,14.46,19.17,15.79,18.31,16.9z M13,19.93v2.02c2.01-0.2,3.84-1,5.32-2.21l-1.43-1.43 C15.79,19.17,14.46,19.75,13,19.93z M13,12V7h-2v5H7l5,5l5-5H13z M11,19.93v2.02c-5.05-0.5-9-4.76-9-9.95s3.95-9.45,9-9.95v2.02 C7.05,4.56,4,7.92,4,12S7.05,19.44,11,19.93z"
/>
</g>
</g>
</svg>
Generate new address
</button>
<button
class="button button--primary interactive gap-0-5 margin-right-auto"
onclick="openPopup('retrieve_btc_addr_popup')"
>
<svg
class="icon"
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 0 24 24"
width="24px"
fill="#000000"
>
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M14 12c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm-2-9c-4.97 0-9 4.03-9 9H0l4 4 4-4H5c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.51 0-2.91-.49-4.06-1.3l-1.42 1.44C8.04 20.3 9.94 21 12 21c4.97 0 9-4.03 9-9s-4.03-9-9-9z"
/>
</svg>
Retrieve Binance address
</button>
</section>
</div>
<div id="created_address_wrapper" class="grid gap-1"></div>
`
@ -1657,6 +1774,8 @@
const { floID, privKey } = floCrypto.generateNewID();
const ethPrivateKey = coinjs.wif2privkey(privKey).privkey;
const BSCAddress = floEthereum.ethAddressFromPrivateKey(ethPrivateKey);
const btcPrivKey = btcOperator.convert.wif(privKey);
const btcAddr = btcOperator.bech32Address(btcPrivKey);
renderElem(
getRef("created_address_wrapper"),
html`
@ -1671,6 +1790,16 @@
<sm-copy value="${privKey}"></sm-copy>
</div>
</li>
<li class="grid gap-0-5">
<div>
<h5>Bitcoin Private Key</h5>
<sm-copy value="${btcPrivKey}"></sm-copy>
</div>
<div>
<h5>Bitcoin Address</h5>
<sm-copy value="${btcAddr}"></sm-copy>
</div>
</li>
<li class="grid gap-0-5">
<div>
<h5>Equivalent Binance Address</h5>
@ -1685,6 +1814,19 @@
`
);
}
function retrieveBinanceAddr() {
function retrieve() {
let bscPrivateKey = getRef("retrieve_btc_addr_field").value.trim();
getRef("recovered_btc_addr_wrapper").classList.remove("hidden");
getRef("recovered_btc_addr").value =
floEthereum.ethAddressFromPrivateKey(bscPrivateKey);
}
if (document.startViewTransition) {
document.startViewTransition(() => {
retrieve();
});
} else retrieve();
}
</script>
</body>
</html>