Skip to content

Commit

Permalink
Bech32
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Mar 20, 2017
0 parents commit 52b5a0f
Show file tree
Hide file tree
Showing 16 changed files with 1,867 additions and 0 deletions.
360 changes: 360 additions & 0 deletions bip-witaddr.mediawiki

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
demo.js: ../ecc/javascript/*.js
cd ../ecc/javascript && browserify --s segwit_addr_ecc segwit_addr_ecc.js | uglifyjs -c -m >../../demo/demo.js
Binary file added demo/SegWit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions demo/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Segwit address decoder demo</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<style>
.monospace { font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace; }
</style>
</head>
<body>
<script type="text/javascript">

function toHexString(byteArray) {
return byteArray.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('')
}

function update_status() {
var address = document.getElementById("address").value;
var res = segwit_addr_ecc.check(address, ["bc", "tb"]);
var cp = "";
if (res.error === null) {
document.getElementById("result").innerHTML = "<a style=\"color:green\">Ok, witness version " + res.version + ", program " + toHexString(res.program) + "</a>";
cp = "<br/>";
} else {
document.getElementById("result").innerHTML = res.error;
if (res.pos !== null) {
for (var p = 0; p < address.length; ++p) {
if (res.pos.indexOf(p) != -1) {
cp += "<a style=\"color:red\">" + address.charAt(p) + "</a>";
} else {
cp += address.charAt(p);
}
}
}
}
if(!address.length) document.getElementById("result").innerHTML = "";
document.getElementById("copy").innerHTML = cp;
}
</script>
<div class="container" style="margin-top:50px">
<div class="card text-left">
<h3 class="card-header">SegWit address decoder demo</h3>
<div class="card-block">
<div class="form-group row">
<label for="lgFormGroupInput" class="col-sm-2 col-form-label col-form-label-lg">Address</label>
<div class="col-sm-10">
<input type="text" class="form-control form-control-lg monospace" id="address" placeholder="SegWit address" size="74" oninput="update_status();" />
</div>
</div>
<p><a id="result"><br/></a></p>
<p><span class="monospace"><a id="copy"><br/></a></span></p>
Fill field with:
<ul>
<li> <a style="text-decoration:underline;" onclick='document.getElementById("address").value = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4";update_status();'>P2WPKH example</a>
<li> <a style="text-decoration:underline;" onclick='document.getElementById("address").value = "BC1QW508D6QEJXTDG4Y5R3ZARVAYR0C5XW7KV8F3T4";update_status();'>P2WPKH example with errors</a>
<li> <a style="text-decoration:underline;" onclick='document.getElementById("address").value = "bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3";update_status();'>P2WSH example</a>
</ul>
</div>
</div>
</div>

<footer class="footer">
<div class="container text-center">
<img height="80px" src="SegWit.png" width="288px">
</div>
</footer>
</body>
</html>

<script src="demo.js" type="text/javascript"></script>
1 change: 1 addition & 0 deletions demo/demo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions demo/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.footer {
right: 0;
bottom: 0;
left: 0;
padding: 4rem;
text-align: center;
}
Loading

0 comments on commit 52b5a0f

Please sign in to comment.