]> git.bitcoin.ninja Git - satsto.me/commitdiff
Decode URIs somewhat
authorMatt Corallo <git@bluematt.me>
Fri, 12 Jul 2024 14:53:55 +0000 (14:53 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 12 Jul 2024 14:59:28 +0000 (14:59 +0000)
index.html

index 2e4735c64c393d836ea6114e6f159a56eed683f3..f017f439b426f2f37ac599ead1f37e109e418838 100644 (file)
                                                document.getElementById("result").innerHTML = "Address is BIP 353-invalid - it contains no bitcoin: URI";
                                                return;
                                        }
-                                       document.getElementById("result").innerHTML = "<a href=\"" + bip353 + "\">Opening your bitcoin wallet to pay " + name + "! If it doesn't work, click here.</a>";
+                                       var addr_ty_table = "";
+                                       const base_and_params = bip353.substring(8).split("?");
+                                       if (base_and_params[0].length != 0) {
+                                               if (!/^[\p{ASCII}]*$/u.test(base_and_params[0])) {
+                                                       addr_ty_table += "<tr><th>On-Chain Non-Private Address</th><th>Invalid</th></tr>";
+                                               } else {
+                                                       addr_ty_table += "<tr><th>On-Chain Non-Private Address</th><th><a href='bitcoin:" + base_and_params[0] + "'>" + base_and_params[0] + "</a></th></tr>";
+                                               }
+                                       }
+                                       if (base_and_params.length > 1 && base_and_params[1].length > 0) {
+                                               for (const param of base_and_params[1].split("&")) {
+                                                       const key_value = param.split("=");
+                                                       if (key_value.length == 2 && key_value[1].length != 0) {
+                                                               var value = "";
+                                                               if (!/^[\p{ASCII}]*$/u.test(key_value[1])) {
+                                                                       value = "<th>Invalid</th>";
+                                                               } else if (key_value[1].length < 75) {
+                                                                       value = "<th><a href='bitcoin:?" + key_value[0] + "=" + key_value[1] + "'>" + key_value[1] + "</a></th>";
+                                                               } else {
+                                                                       value = "<th><a href='bitcoin:?" + key_value[0] + "=" + key_value[1] + "'>" + key_value[1].substring(0, 75) + "...</a></th>";
+                                                               }
+                                                               if (key_value[0] == "lno") {
+                                                                       addr_ty_table += "<tr><th>BOLT 12 Offer</th>" + value + "</tr>";
+                                                               } else if (key_value[0] == "sp") {
+                                                                       addr_ty_table += "<tr><th>Silent Payments</th>" + value + "</tr>";
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       const result_elem = document.getElementById("result");
+                                       result_elem.innerHTML = "<a href=\"" + bip353 + "\">Opening your bitcoin wallet to pay " + name + "! If it doesn't work, click here.</a>";
+                                       if (addr_ty_table != "") {
+                                               result_elem.innerHTML += "<br><table><tr><th>Type</th><th>Address</th></tr>" + addr_ty_table + "</table>";
+                                       }
                                        window.location = bip353;
                                }
                        });