-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
214 lines (200 loc) · 8.17 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Crypto Qubic</title>
<style>
textarea {
width: 400px;
height: 100px;
}
input {
width: 100%;
}
.result {
overflow-wrap: break-word;
word-wrap: break-word;
}
.qubic-box {
display: inline-block;
width:40%;
max-width: 250px;
height:40%;
}
</style>
</head>
<script src="qubic-js-tools.js"></script>
<body>
<script>
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
function writeToScreen(data) {
let el = document.createElement('pre')
el.className = "result"
el.innerHTML = data
document.getElementById("resultDiv").innerHTML = ""
document.getElementById("resultDiv").appendChild(el)
}
const qubic = QubicJsTools();
function genNewSeed() {
qubic.account.genSeed().then((seed) => {
writeToScreen(syntaxHighlight(seed))
})
}
function getPubKey() {
let id = document.getElementById('getPubKeyId').value
if(id.length < 1) {
return writeToScreen('Invalid Identity')
}
try {
const pubKey = qubic.account.getPublicKeyFromIdentity(id)
writeToScreen(pubKey)
} catch(error) {
writeToScreen(error)
}
}
function getId() {
let seed = document.getElementById('getIdSeed').value
if(seed.length !== 55) {
return writeToScreen('Invalid Seed')
}
qubic.account.getIdentityFromSeed(seed).then(writeToScreen)
}
function genShared() {
let seed = document.getElementById('mySeedId').value
let pubKey = document.getElementById('otherPubId').value
if(seed.length !== 55 || pubKey.length < 1) {
return writeToScreen('Invalid Seed Or PubKey To Generated Shared Secret')
}
qubic.generateSharedSecret(seed, pubKey).then(result => {
writeToScreen(result)
})
}
function encryptMessage() {
let passwordEncrypt = document.getElementById('passwordEncrypt').value
let messageToEncrypt = document.getElementById('messageToEncrypt').value
if(passwordEncrypt.length < 1 || messageToEncrypt.length < 1) {
return writeToScreen('Invalid Message/Password To Encrypt')
}
let aes = qubic.Aes256Gcm(passwordEncrypt);
aes.encrypt(messageToEncrypt).then(res => { writeToScreen(syntaxHighlight(res)) })
}
function decryptMessage() {
let passwordDecrypt = document.getElementById('passwordDecrypt').value
let messageToDecrypt = document.getElementById('messageToDecrypt').value
if(passwordDecrypt.length < 1 || messageToDecrypt.length < 1) {
return writeToScreen('Invalid Message/Password To Decrypt')
}
let aes = qubic.Aes256Gcm(passwordDecrypt);
aes.decrypt(JSON.parse(messageToDecrypt))
.then(writeToScreen)
.catch(writeToScreen)
}
function sign() {
let seed = document.getElementById('seedToUse').value
let message = document.getElementById('messageToSign').value
if(seed.length !== 55) {
return writeToScreen('Invalid Seed')
}
qubic.sig.signData(seed, message).then(sig => {
writeToScreen(syntaxHighlight(sig))
})
}
function verify() {
let message = document.getElementById('messageToVerify').value
let sig = document.getElementById('sigToVerify').value
if( message.length === 0 || sig.length === 0) {
return writeToScreen('Invalid Data to Verify')
}
qubic.sig.verifySignature(message, JSON.parse(sig)).then(result => {
writeToScreen(result == 1 ? "VERIFIED" : "NOT VERIFIED")
})
}
function KangarooTwelve() {
let input = document.getElementById('hashInput').value
let length = parseInt(document.getElementById('hashLength').value)
if(input.length < 1 || length < 1) {
return writeToScreen('Invalid Input or Length')
}
qubic.K12(input, length).then(data => {
writeToScreen(syntaxHighlight(data))
})
}
</script>
<div id="qubicToolsDiv" style="margin-left: 1%; margin-top: 1%">
<div id="inputDiv">
<div id="text">
<h3>Qubic JS Tools</h3>
</div>
<div id="accountDiv" style="margin-bottom: 1%">
<div id="seedDiv" class="qubic-box">
<button onclick="genNewSeed()">Generate New Seed</button> <br/><br/><br/>
</div>
<div id="getIdentityDiv" class="qubic-box" style="margin-left: 15%">
<input type="password" id="getIdSeed" placeholder="Seed"><br />
<button onclick="getId()">Get Identity</button>
</div>
<div id="getPubKeyDiv" class="qubic-box" style="margin-left: 15%">
<input type="password" id="getPubKeyId" placeholder="Identity"><br />
<button onclick="getPubKey()">Get Public Key</button>
</div>
</div>
<div id="encryptionDiv">
<div id="encryptDiv" class="qubic-box">
<textarea id="messageToEncrypt" placeholder="Message to Encrypt..."></textarea><br/>
<input type="password" id="passwordEncrypt" placeholder="Encrypt Password"><br/>
<button onclick="encryptMessage()">Encrypt Message</button><br/><br />
</div>
<div id="decryptDiv" class="qubic-box" style="margin-left: 15%">
<textarea id="messageToDecrypt" placeholder="JSON to Decrypt... {ct, salt, iv}"></textarea><br />
<input type="password" id="passwordDecrypt" placeholder="Decrypt Password"><br/>
<button onclick="decryptMessage()">Decrypt Message</button><br/><br />
</div>
<div id="sharedDiv" class="qubic-box" style="margin-left: 15%">
<input type="password" id="mySeedId" placeholder="My Seed"><br/>
<input type="text" id="otherPubId" placeholder="Other Identity"><br/>
<button onclick="genShared()">Generated Shared Secret</button>
</div>
</div>
<div id="signatureDiv">
<div id="signDiv" class="qubic-box">
<input type="password" id="seedToUse" placeholder="Seed To Use"><br/>
<textarea id="messageToSign" placeholder="Message to Sign..."></textarea><br />
<button onclick="sign()">Sign Message</button>
</div>
<div id="verifyDiv" class="qubic-box" style="margin-left: 15%">
<textarea id="messageToVerify" placeholder="Message to Verify"></textarea><br/>
<textarea id="sigToVerify" placeholder="Signature JSON to Verify... {pk, signature}"></textarea><br/>
<button onclick="verify()">Verify Signed Message</button>
</div>
<div id="hashDiv" class="qubic-box" style="margin-left: 15%">
<textarea id="hashInput" placeholder="Data to Hash"></textarea><br/>
<input type="number" id="hashLength" placeholder="Output Length"><br/>
<button onclick="KangarooTwelve()">K12 Hash</button>
</div>
</div>
</div>
<div class="result" id="resultDiv">
</div>
</div>
</body>
</html>