1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ <!-- Required meta tags -->
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
7+ < title > Segwit address decoder demo</ title >
8+ <!-- Bootstrap CSS -->
9+ < 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 ">
10+ < link rel ="stylesheet " href ="style.css ">
11+ < style >
12+ .monospace { font-family : Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; }
13+ </ style >
14+ </ head >
15+ < body >
16+ < script type ="text/javascript ">
17+
18+ function toHexString ( byteArray ) {
19+ return byteArray . map ( function ( byte ) {
20+ return ( '0' + ( byte & 0xFF ) . toString ( 16 ) ) . slice ( - 2 ) ;
21+ } ) . join ( '' )
22+ }
23+
24+ function update_status ( ) {
25+ var address = document . getElementById ( "address" ) . value ;
26+ var res = segwit_addr_ecc . check ( address , [ "bc" , "tb" ] ) ;
27+ var cp = "" ;
28+ if ( res . error === null ) {
29+ document . getElementById ( "result" ) . innerHTML = "<a style=\"color:green\">Ok, witness version " + res . version + ", program " + toHexString ( res . program ) + "</a>" ;
30+ cp = "<br/>" ;
31+ } else {
32+ document . getElementById ( "result" ) . innerHTML = res . error ;
33+ if ( res . pos !== null ) {
34+ for ( var p = 0 ; p < address . length ; ++ p ) {
35+ if ( res . pos . indexOf ( p ) != - 1 ) {
36+ cp += "<a style=\"color:red\">" + address . charAt ( p ) + "</a>" ;
37+ } else {
38+ cp += address . charAt ( p ) ;
39+ }
40+ }
41+ }
42+ }
43+ if ( ! address . length ) document . getElementById ( "result" ) . innerHTML = "" ;
44+ document . getElementById ( "copy" ) . innerHTML = cp ;
45+ }
46+ </ script >
47+ < div class ="container " style ="margin-top:50px ">
48+ < div class ="card text-left ">
49+ < h3 class ="card-header "> SegWit address decoder demo</ h3 >
50+ < div class ="card-block ">
51+ < div class ="form-group row ">
52+ < label for ="lgFormGroupInput " class ="col-sm-2 col-form-label col-form-label-lg "> Address</ label >
53+ < div class ="col-sm-10 ">
54+ < input type ="text " class ="form-control form-control-lg monospace " id ="address " placeholder ="SegWit address " size ="74 " oninput ="update_status(); " />
55+ </ div >
56+ </ div >
57+ < p > < a id ="result "> < br /> </ a > </ p >
58+ < p > < span class ="monospace "> < a id ="copy "> < br /> </ a > </ span > </ p >
59+ Fill field with:
60+ < ul >
61+ < li > < a style ="text-decoration:underline; " onclick ='document.getElementById("address").value = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4";update_status(); '> P2WPKH example</ a >
62+ < li > < a style ="text-decoration:underline; " onclick ='document.getElementById("address").value = "BC1QW508D6QEJXTDG4Y5R3ZARVAYR0C5XW7KV8F3T4";update_status(); '> P2WPKH example with errors</ a >
63+ < li > < a style ="text-decoration:underline; " onclick ='document.getElementById("address").value = "bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3";update_status(); '> P2WSH example</ a >
64+ </ ul >
65+ </ div >
66+ </ div >
67+ </ div >
68+
69+ < footer class ="footer ">
70+ < div class ="container text-center ">
71+ < img height ="80px " src ="SegWit.png " width ="288px ">
72+ </ div >
73+ </ footer >
74+ </ body >
75+ </ html >
76+
77+ < script src ="demo.js " type ="text/javascript "> </ script >
0 commit comments