-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
242 lines (209 loc) · 7.22 KB
/
index.html
File metadata and controls
242 lines (209 loc) · 7.22 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BRFCgen — Easily generate BRFC IDs</title>
<meta name="title" content="BRFCgen — Easily generate BRFC IDs">
<meta name="description" content="Easily generate BRFC (Bitcoin Request for Comment) IDs for your Bitcoin Specifications">
<meta name="keywords" content="Bitcoin, BSV, BRFC Specifications">
<link rel="icon" type="image/png" href="/images/favicon.png">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.11.1/tachyons.min.css"
integrity="sha512-d0v474klOFSF7qD9WDvyRxAvXaWSxCHDZdnBSZQjo8BpVr6vpjwAgqetpqkKP38DzlOzdVPaLVnzzW1Ba8wB9w=="
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.8.0/dist/alpine.min.js"
crossorigin="anonymous" defer></script>
<style>
/*
A sprinkling of CSS to power light/dark mode and some snazzy and
(admittedly) superfluous background colour effects. I just wanted to play
with CSS custom properties.
*/
html, body {
height: 100%;
}
body {
--col: #333333;
--bg1: #F4F4F4;
--bg2: #F4F4F4;
color: var(--col, #F4F4F4);
background-color: var(--bg2, #F4F4F4);
background-image: radial-gradient(circle, var(--bg1, #F4F4F4) 6rem, var(--bg2, #F4F4F4));
}
.panel {
background-color: rgba(255, 255, 255, 0.65);
box-shadow: 0 0 1rem 1px rgba(0, 0, 0, 0.1);
}
.input {
color: #222222;
background-color: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(0, 0, 0, 0.1);
}
.input:focus {
box-shadow: 0 0 3px 1px rgba(150, 204, 255, 0.5);
}
.link {
color: inherit;
}
.link:hover {
color: #FF41B4;
}
@media (prefers-color-scheme: dark) {
body {
--col: #F4F4F4;
--bg1: #333333;
--bg2: #333333;
}
.panel {
background-color: rgba(0, 0, 0, 0.35);
}
.input {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.1);
border: 1px solid rgba(0, 0, 0, 0.3);
}
}
</style>
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://libitx.github.io/brfcgen/">
<meta property="og:title" content="BRFCgen — Easily generate BRFC IDs">
<meta property="og:description" content="Easily generate BRFC (Bitcoin Request for Comment) IDs for your Bitcoin Specifications">
<meta property="og:image" content="https://libitx.github.io/brfcgen/images/card.jpg">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://libitx.github.io/brfcgen/">
<meta property="twitter:title" content="BRFCgen — Easily generate BRFC IDs">
<meta property="twitter:description" content="Easily generate BRFC (Bitcoin Request for Comment) IDs for your Bitcoin Specifications">
<meta property="twitter:image" content="https://libitx.github.io/brfcgen/images/card.jpg">
</head>
<body class="sans-serif ph3 ph4-l">
<div class="flex flex-column min-h-100 mw6 pt3 center">
<div class="flex flex-auto flex-column justify-center">
<div class="pa3 pa4-ns br4 | panel"
x-data="brfcGen()"
x-init="$watch('brfc', onChange)">
<h1 class="mt0 mb2 f3 lh-title fw9 tracked underline">
BRFC<span class="fw7 o-70">gen</span>
</h1>
<p class="mt0 mb3 f7 lh-copy fw3 o-80">
Generate <a href="http://bsvalias.org/01-02-brfc-id-assignment.html" class="link fw6 underline">BRFC IDs</a>
with <span class="fw6 tracked ttu">snazzy</span> colours just for the f<span class="fw4">*</span>ck of it.
</p>
<div class="mv3 mv4-l">
<label class="db mb2 f7 fw3 lh-block o-60"
for="title">
Title
</label>
<input type="text"
class="input-reset w-100 pa2 f4 fw5 br2 bn outline-0 | input"
id="title"
x-model="title"
x-on:keyup="recalc()"
x-on:blur="recalc(true)" />
</div>
<div class="mv3 mv4-l">
<label class="db mb2 f7 fw3 lh-block o-60"
for="author">
Author(s)
</label>
<input type="text"
class="input-reset w-100 pa2 f4 fw5 br2 bn outline-0 | input"
id="author"
x-model="author"
x-on:keyup="recalc()"
x-on:blur="recalc(true)" />
</div>
<div class="mv3 mv4-l">
<label class="db mb2 f7 fw3 lh-block o-60"
for="version">
Version
</label>
<input type="text"
class="input-reset w-100 pa2 f4 fw5 br2 bn outline-0 | input"
id="version"
x-model="version"
x-on:keyup="recalc()"
x-on:blur="recalc(true)" />
</div>
<div class="mv3 mv4-l">
<label class="db mb2 f7 fw3 lh-block o-60"
for="brfc">
BRFC
</label>
<input type="text"
class="input-reset w-100 pa2 code f3 fw5 br2 bn outline-0 | input"
id="brfc"
x-model="brfc"
x-on:focus="setTimeout(_ => $event.target.select())"
readonly />
</div>
</div>
</div>
<footer class="pv3">
<p class="ma0 f7 fw3 tc">
Created by <a href="https://twitter.com/libitx" class="link fw6 underline">Libs</a>.
See <a href="https://github.com/libitx/brfcgen" class="link fw6 underline">source code</a>.
</p>
</footer>
</div>
<script>
const enc = new TextEncoder()
/**
* BRFC ID Generator Alpine component
*/
function brfcGen() {
return {
title: null,
author: null,
version: null,
brfc: null,
/**
* Recalculates the BRFC ID
*/
recalc(force = false) {
if ((force || this.brfc) && this.payloadBuf().length > 0) {
sha256x2(this.payloadBuf())
.then(hash => [...new Uint8Array(hash)].slice(26).reverse())
.then(brfc => this.brfc = toHex(brfc))
}
},
/**
* Concatenates attributes into ArrayBuffer
*/
payloadBuf() {
const str = (this.title || '').trim() +
(this.author || '').trim() +
(this.version || '').trim();
return enc.encode(str)
},
/**
* Fired when BRFC is changed
*/
onChange(val) {
const bg1 = val.substring(0, 6),
bg2 = val.substring(6);
document.body.style.setProperty('--bg1', '#'+bg1)
document.body.style.setProperty('--bg2', '#'+bg2)
}
}
}
/**
* Double sha256 hash
*/
function sha256x2(buf) {
return crypto.subtle.digest('SHA-256', buf)
.then(hash => crypto.subtle.digest('SHA-256', hash))
}
/**
* Encodes typed array as hex
*/
function toHex(buf) {
return [...new Uint8Array(buf)]
.map(b => b.toString(16).padStart(2, '0'))
.join('')
}
</script>
</body>
</html>