From 2c25b682c231bb4c75cfe7ccd165edd9dfd9a445 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 12 Jul 2024 18:22:35 +0000 Subject: [PATCH] Attept to use the BDC design, roughly --- clipboard-svg.js | 4 +- index.html | 184 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 131 insertions(+), 57 deletions(-) diff --git a/clipboard-svg.js b/clipboard-svg.js index e39ca35..3704aa8 100644 --- a/clipboard-svg.js +++ b/clipboard-svg.js @@ -2,5 +2,5 @@ // Copyright (c) 2019-2024 The Bootstrap Authors // Licensed under the MIT license, see https://github.com/twbs/icons/blob/main/LICENSE -export const CLIPBOARD_SVG = ''; -export const CLIPBOARD_CHECK_SVG =''; +export const CLIPBOARD_SVG = ''; +export const CLIPBOARD_CHECK_SVG =''; diff --git a/index.html b/index.html index cdda863..97bee84 100644 --- a/index.html +++ b/index.html @@ -5,66 +5,137 @@ BIP 353 Human Readable Names Resolver -

- BIP 353 Human Readable Names Resolver -

- +
+

BIP 353 Human Readable Names Resolver

BIP 353 defines the way to encode simple human-readable names and map them to Bitcoin payment intructions.

If your wallet doesn't yet resolve BIP 353 names natively, this site will resolve them for you, letting you pay human readable names seamlessly.

- -

-

-
- ₿
-
-
- Resolve name using  +
+
+
+ +
+ ₿ + +
+
+ Resolve name using  +
+
-
- -

-

- +
+
+ @@ -84,31 +155,31 @@ const addr_parts = address_box.value.split("@"); if (addr_parts.length != 2) { document.getElementById("paybutton").disabled = true; - document.getElementById("result").innerHTML = "Address should have exactly one @"; + document.getElementById("errors").innerHTML = "Address should have exactly one @"; return true; } if (addr_parts[0].length == 0) { document.getElementById("paybutton").disabled = true; - document.getElementById("result").innerHTML = "Missing user part"; + document.getElementById("errors").innerHTML = "Missing user part"; return true; } if (addr_parts[1].length == 0) { document.getElementById("paybutton").disabled = true; - document.getElementById("result").innerHTML = "Missing domain"; + document.getElementById("errors").innerHTML = "Missing domain"; return true; } if (!/^[\p{ASCII}]*$/u.test(addr_parts[0])) { document.getElementById("paybutton").disabled = true; - document.getElementById("result").innerHTML = "To protect against Homograph Attacks, the user part of addres must be ASCII"; + document.getElementById("errors").innerHTML = "To protect against Homograph Attacks, the user part of addres must be ASCII"; return true; } if (!/^[\p{ASCII}]*$/u.test(addr_parts[1])) { document.getElementById("paybutton").disabled = true; - document.getElementById("result").innerHTML = "To protect against Homograph Attacks, the domain part of addres must be ASCII"; + document.getElementById("errors").innerHTML = "To protect against Homograph Attacks, the domain part of addres must be ASCII"; return true; } document.getElementById("paybutton").disabled = false; - document.getElementById("result").innerHTML = ""; + document.getElementById("errors").innerHTML = ""; return true; } document.getElementById("address").onchange = check_text; @@ -125,6 +196,11 @@ lookup_doh(address_box.value, dom, source); } } + const set_result = function(val) { + const result_div = document.getElementById("result"); + result_div.innerHTML = val; + result_div.classList.add("result-populated"); + } window.lookup_http = function(addr, dom) { var request = "https://http-dns-prover.as397444.net/dnssecproof?d=" + dom + "&t=txt"; fetch(request).then((resp) => { @@ -133,64 +209,62 @@ var result = verify_byte_stream(buf, dom); handle_result(addr, JSON.parse(result)); }, () => { - document.getElementById("result").innerHTML = "Failed to read proof from server"; + set_result("Failed to read proof from server"); }) }, (e) => { - document.getElementById("result").innerHTML = "Failed to fetch proof: " + e; + set_result("Failed to fetch proof: " + e); }); } window.lookup_doh = function(addr, dom, doh_endpoint) { doh.lookup_doh(dom, "txt", doh_endpoint).then((res) => { handle_result(addr, res); }, (e) => { - document.getElementById("result").innerHTML = "Failed to fetch proof: " + e; + set_result("Failed to fetch proof: " + e); }); } window.handle_result = function(name, result) { if (!result.hasOwnProperty("valid_from") || !result.hasOwnProperty("expires") || !result.hasOwnProperty("verified_rrs")) { - document.getElementById("result").innerHTML = "Failed to fetch valid proof"; + set_result("Failed to fetch valid proof"); return; } if (Date.now() / 1000 < result.valid_from) { - document.getElementById("result").innerHTML = "Proof is not yet valid (check your system clock)"; + set_result("Proof is not yet valid (check your system clock)"); return; } if (Date.now() / 1000 > result.expires) { - document.getElementById("result").innerHTML = "Proof has expired (check your system clock?)"; + set_result("Proof has expired (check your system clock?)"); return; } var bip353 = null; for (const rr of result.verified_rrs) { if (rr.type != "txt") { - document.getElementById("result").innerHTML = "Proof was invalid"; + set_result("Proof was invalid"); return; } if (typeof rr.contents === "string" && rr.contents.toLowerCase().startsWith("bitcoin:")) { if (bip353 !== null) { - document.getElementById("result").innerHTML = "Address is BIP 353-invalid - it contains multiple results"; + set_result("Address is BIP 353-invalid - it contains multiple results"); return; } bip353 = rr.contents; } } if (bip353 === null) { - document.getElementById("result").innerHTML = "Address is BIP 353-invalid - it contains no bitcoin: URI"; + set_result("Address is BIP 353-invalid - it contains no bitcoin: URI"); return; } var addr_ty_table = ""; var addr_idx = 0; const base_and_params = bip353.substring(8).split("?"); const push_table_entry = function(ty, uri_pfx, contents) { - var value = ""; + var value = "

" + ty + "" + CLIPBOARD_SVG + "

"; if (!/^[\p{ASCII}]*$/u.test(contents)) { value = "Invalid"; - } else if (contents.length < 70) { - value = "" + contents + "" + CLIPBOARD_SVG + ""; } else { - value = "" + contents.substring(0, 70) + "..." + CLIPBOARD_SVG + ""; + value += "" + contents + ""; } addr_idx += 1; - addr_ty_table += "
" + ty + "" + value + "
"; + addr_ty_table += "
" + value + "

"; }; if (base_and_params[0].length != 0) { push_table_entry("On-Chain Non-Private Address", "", base_and_params[0]); @@ -207,11 +281,11 @@ } } } - const result_elem = document.getElementById("result"); - result_elem.innerHTML = "Opening your bitcoin wallet to pay " + name + "! If it doesn't work, click here."; + var res = "

It works!

" + name + " was successfully resolved to the following addresses.
Your wallet should have automatically opened to pay, but if not, click here to do so."; if (addr_ty_table != "") { - result_elem.innerHTML += "
" + addr_ty_table; + res += "
" + addr_ty_table; } + set_result(res); window.location = bip353; } window.copy = function(text, element_id) { -- 2.39.5