-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
121 lines (110 loc) · 4.47 KB
/
index.html
File metadata and controls
121 lines (110 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Miniscript</title>
<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">
<!-- Optional theme -->
<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;
}
a.demo_link {
text-decoration-style: dashed;
text-underline-position: under;
}
</style>
</head>
<body>
<script src="miniscript.js"></script>
<script>
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
em_miniscript_compile = Module.cwrap('miniscript_compile', 'none', ['string', 'number', 'number', 'number', 'number', 'number', 'number']);
em_miniscript_analyze = Module.cwrap('miniscript_analyze', 'none', ['string', 'number', 'number', 'number', 'number']);
function miniscript_compile() {
document.getElementById("out").innerHTML = "Compiling...";
window.setTimeout(function() {
src = document.getElementById("source").value;
var msout = Module._malloc(10000);
var costout = Module._malloc(500);
var asmout = Module._malloc(100000);
em_miniscript_compile(src, msout, 10000, costout, 500, asmout, 100000);
document.getElementById("analyze_ms").value = Module.UTF8ToString(msout);
document.getElementById("analyze_out").innerHTML = "";
document.getElementById("out").innerHTML =
"<p><p><b>Miniscript output:</b><p><code>" + htmlEscape(Module.UTF8ToString(msout)) + "</code>" +
"<p><b>Spending cost analysis</b><p>" + Module.UTF8ToString(costout) + "" +
"<p><b>Resulting script structure</b><p><samp><pre>" + htmlEscape(Module.UTF8ToString(asmout)) + "</pre></samp>";
Module._free(msout)
Module._free(costout)
Module._free(asmout)
});
}
function load_policy(pol) {
document.getElementById("source").value = pol;
miniscript_compile();
}
function miniscript_analyze() {
document.getElementById("analyze_out").innerHTML = "Analyzing...";
window.setTimeout(function() {
src = document.getElementById("analyze_ms").value;
var analyze_out = Module._malloc(50000);
var asmout = Module._malloc(100000);
em_miniscript_analyze(src, analyze_out, 50000, asmout, 100000);
document.getElementById("analyze_out").innerHTML =
"<p><p><b>Analysis</b><p>" + Module.UTF8ToString(analyze_out) + "<p><small>Hover over the tree elements for more details</small>" +
"<p><b>Resulting script structure</b><p><samp><pre>" + htmlEscape(Module.UTF8ToString(asmout)) + "</pre></samp>";
Module._free(analyze_out)
Module._free(asmout)
});
}
</script>
<div class="container" style="margin-top:50px">
<div class="card mb-3 text-left">
<h3 class="card-header">
<a href="miniscript.html">Miniscript</a>
<a href="index.html">Compiler</a>
<a href="reference.html">Reference</a>
</h3>
</div>
</div>
<div class="card mb-3 text-left">
<div class="card-block">
<form>
<div class="form-group">
<h4><label for="source">Policy</label></h4>
<textarea class="form-control" id="source" rows="1">and(pk(A),or(pk(B),or(9@pk(C),older(1000))))</textarea><br>
<button type="button" class="btn btn-primary" onclick="miniscript_compile();">Compile</button>
</div>
</form>
<div class="card-block">
<div id="out"></div>
</div>
<div class="card-block">
<form>
<div class="form-group">
<label for="analyze_ms"><b>Miniscript</b></label>
<textarea class="form-control" id="analyze_ms" rows="1">and_v(v:pk(K),pk(A))</textarea>
<small class="form-text test-muted">Provide a well-typed miniscript expression of type "B".</small>
</div>
<button type="button" class="btn btn-primary" onclick="miniscript_analyze();">Analyze</button>
</form>
<div class="card-block">
<div id="out"></div>
<div id="analyze_out"></div>
</div>
</div>
</div>
</div>
</body>
</html>