-
Notifications
You must be signed in to change notification settings - Fork 0
/
nostr-vanity.js
43 lines (43 loc) · 1.08 KB
/
nostr-vanity.js
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
let keys, npub, main, prefix;
/* */
function HexToBech32(hrp, data, spec){
let dec = [];
for(let i=0,c=data.length; i<c; i+=2){
dec.push(parseInt(data.substring(i, i+2), 16));
}
data = convertbits(dec, 8, 5, true);
return encode(hrp, data, spec);
}
/* */
function GetKeys(){
let keypair = bitcoinjs.ECPair.makeRandom();
let privKey = keypair.privateKey.toString("hex");
let pubKey = keypair.publicKey.toString("hex");
//
return [
privKey,
pubKey.substring(2)
];
}
/* */
window.addEventListener("load", ()=>{
main = document.getElementById("main-frame");
prefix = document.getElementById("vanity-prefix");
//
prefix.addEventListener("keypress", function(e){
if(this.value.length<1 || this.value.length>20)
return;
if(e.key === "Enter"){
do{
keys = GetKeys();
npub = HexToBech32("npub", keys[1], "BECH32");
}while(npub.substring(5, this.value.length-(-5)) != prefix.value);
//
main.innerHTML += "<div>"+
"<div>private key: "+ keys[0] +"</div>"+
"<div>public key: "+ keys[1] +"</div>"+
"<div>npub: "+ npub +"</div>"+
"</div>";
}
});
});