-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.htm
308 lines (278 loc) · 14.5 KB
/
wallet.htm
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE HTML>
<!--
Credible Explorer v0.1.1
Created by Thorsten Neumann and Bao Trung
Experimental code. Use with care. Prototype
-->
<html>
<head>
<title>SmartPesa Credible Explorer</title>
<script type="text/javascript" src="https://cdn.rawgit.com/ricmoo/aes-js/e27b99df/index.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tweetnacl/1.0.0/nacl.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="credible-driver.js"></script>
<script type="text/javascript" src="secrets.min.js"></script>
<script type="text/javascript" src="ed2curve.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<style>
.fixed-top {
top: 0;
right: 0;
left: 0;
z-index: 1030;
position: sticky;
background-color: whitesmoke;
}
.full-width {
margin: 0 auto;
width: 80% !important;
}
</style>
</head>
<body>
<div class="container" style="height: 100%;width: 100%;">
<div class="row fixed-top">
<a href="https://smartpesa.io">
<img class="logo logo-dark" style="margin: 5px; margin-left: 10px; " alt="logo" src="https://files.smartpesa.io/public/Credible.png" width="240">
</a>
</div>
<div class="row" style="margin-top: 10px;">
<div class="col-sm-12">
<div class="float-left col-sm-4">
<h3>Wallet Generator</h3>
<div class="form-group">
<label class="control-label">Private Key:</label>
<input type="text" class="form-control" id="key_private" value="8p8sk3ZQ2XKwp7PTSxDSC99j33pdo48Z8g6AJE5fF5An"/>
</div>
<div class="form-group">
<label class="control-label">Public Key:</label>
<input type="text" class="form-control" id="key_public" value="9U95xGb6E2hendFE2F4aGvX5vrepYrht8LFjkVyaazdM"/>
</div>
<div class="form-group">
<input type="button" class="btn btn-default" id="btn_generate" value="Generate New" />
</div>
</div>
<div class="float-right col-sm-8">
<h3>Data Post</h3>
<label class="control-label">New Credit Data:</label>
<div class="form-group form-inline">
<select name="schema" class="form-control">
<option value="business">business</option>
<option value="address">address</option>
</select>
<select id="type" class="form-control">
<option value="business.name">business.name</option>
<option value="business.registered_name">business.registered_name</option>
<option value="business.trading_name">business.trading_name</option>
<option value="business.tax.code">business.tax.code</option>
<option value="business.tax.enrol_date">business.tax.enrol_date</option>
</select>
<input type="text" class="form-control" id="claim" value="Founders Bakuteh"/>
</div>
<div class="form-group form-inline">
<label class="control-label">Node:</label>
<select name="node" id="node" class="form-control">
<option value="credible-1.testnet.smartpesa.com">credible-1.testnet.smartpesa.com</option>
<option value="credible-2.testnet.smartpesa.com">credible-2.testnet.smartpesa.com</option>
<option value="credible-3.testnet.smartpesa.com">credible-3.testnet.smartpesa.com</option>
</select>
<input type="button" class="btn btn-default" id="btn_submit" value="Post to blockchain" />
<input type="button" class="btn btn-default" id="btn_transfer" value="Transfer on blockchain" />
</div>
<div class="form-group">
<div class="form-group">
<label class="control-label">Output:</label>
</div>
<div class="form-group">
<label class="control-label" style="padding-left:10px;">Claim: </label>
<span class="" id="claim_hex"></span>
</div>
<div class="form-group">
<label class="control-label" style="padding-left:10px;">Nonce:</label>
<span class="" id="nonce_hex"></span>
</div>
<div class="form-group">
<label class="control-label" style="padding-left:10px;">Sign ID:</label>
<span class="" id="sign_id"></span>
</div>
<div class="form-group">
<label class="control-label" style="padding-left:10px;">Txn ID:</label>
<span class="" id="txn_id"></span>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="float-left col-sm-4">
<h3>Token Balance</h3>
<div class="form-group form-inline">
<label class="control-label">Wallet Token Balance:</label>
<span class="control-label" id="token_balance">0</span> PESA
</div>
<div class="form-group">
<input type="button" class="btn btn-default" id="btn_tokenBalance" value="Retrieve Balance PESA" />
</div>
</div>
<div class="float-right col-sm-8">
<h3>Encryption</h3>
<div class="form-group form-inline">
<label class="control-label">Result:</label>
<span class="control-label" id="encrypt_result"></span>
</div>
<input type="button" class="btn btn-default" id="btn_encrypt" value="Shamir" onclick="JavaScript:shamir()" />
<input type="button" class="btn btn-default" id="btn_convert" value="Convert To Curve25519" onclick="JavaScript:edToCurve()" />
</div>
</div>
<div class="col-sm-12">
<div class="float-left col-sm-4">
<h3>Search</h3>
<div class="form-group form-inline">
<label class="control-label">Meta data:</label>
<input type="text" class="form-control" id="search_metadata" value="" />
</div>
<div class="form-group form-inline">
<input type="button" class="btn btn-default" id="btn_search_metadata" value="Search by meta-data" />
<input type="button" class="btn btn-default" id="btn_search" value="Search by public key" />
</div>
</div>
</div>
<div class="col-sm-12">
<div class="float-left col-sm-4">
<h3>Transaction ID List</h3>
<div class="form-group">
<div id="div_transaction_ids"></div>
</div>
</div>
<div class="float-right col-sm-8">
<h3>Transaction Detail</h3>
<div class="form-group">
<div id="div_transaction_detail"></div>
</div>
</div>
</div>
</div>
</div>
<p/>
<div style="width:100%;">
<div id="div_transaction_detail" style="float:right;width:60%;"></div>
</div>
<script>
function shamir() {
var pw = 'oneTIMEnonce';
var pwHex = secrets.str2hex(pw); // => 240-bit password
// split into 3 shares, with a threshold of 2
var shares = secrets.share(pwHex, 3, 2, 256); // 3 x 256-bit shares
var comb = secrets.combine([shares[1], shares[2]]);
decrypt = secrets.hex2str(comb);
$("#encrypt_result").text(comb + ' = ' + decrypt);
}
function edToCurve() {
// But first, we need to convert our secret key and their public key
// from Ed25519 into the format accepted by Curve25519.
var ed_private_key = $("#key_private").val();
var curve_private_key = ed2curve.convertSecretKey(ed_private_key);
var ed_public_key = $("#key_public").val();
var curve_public_key = ed2curve.convertPublicKey(ed_public_key);
var key = _arrayBufferToBase64(curve_public_key);
$("#encrypt_result").text(key);
var _nonce = 'oneTIMEnonce';
var _claim = $("#claim").val();
var _claim_encode = secrets.str2hex(_claim);
//var encryptedMessage = nacl.box(_claim_encode, _nonce, curve_public_key, curve_private_key);
}
function _arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
</script>
<script>
/* init hooks */
/* init hooks */
$(function () {
var previous_private = $("#key_private").val();
setNode();
$("#btn_generate").click(generateNewKey);
$("#btn_submit").click(onSubmit);
$("#btn_transfer").click(onTransfer);
$("#btn_search").click(onSearch);
$("#btn_tokenBalance").click(onTokenBalance);
$("#btn_search_metadata").click(onSearchMetadata);
});
$("#node").change(function () {
setNode();
});
function setNode() {
var _node = $("#node").val();
Credible.setEndpoint("http://" + _node);
}
function generateNewKey() {
previous_private = $("#key_private").val();
/* call to driver */
const merchant = Credible.GenerateKey();
$("#key_private").val(merchant.privateKey);
$("#key_public").val(merchant.publicKey);
}
function onSubmit() {
let postData = {
claim: $("#claim").val(),
type: $("#type").val(),
private_key: $("#key_private").val(),
public_key: $("#key_public").val(),
}
Credible.Submit(postData, function (data) {
$("#claim_hex").text(data.claim);
$("#nonce_hex").text(data.nonce_hex);
$("#sign_id").text(data.sign_id);
$("#txn_id").text(data.txn_id);
});
}
function onTransfer() {
$("#txn_id").text("");
let postData = {
sign_id: $("#sign_id").text(),
from_private_key: previous_private,
to_public_key: $("#key_public").val(),
}
Credible.Transfer(postData, function (data) {
$("#sign_id").text(data.sign_id);
$("#txn_id").text(data.txn_id);
//assign current private key to be the new previous
previous_private = $("#key_private").val();
});
}
function onSearch() {
Credible.Search($("#key_public").val(), function (data) {
$("#div_transaction_ids").html('');
for (var i = 0; i < data.length; i++) {
$("#div_transaction_ids").append("<p><a href='javascript:onDetail(\"" + data[i].transaction_id + "\")'>" + data[i].transaction_id + "</a></p>");
}
});
}
function onDetail(transaction_id) {
Credible.Detail(transaction_id, function (data) {
$("#div_transaction_detail").html("<pre>" + JSON.stringify(data, null, 4) + "</pre>");
});
}
function onTokenBalance() {
Credible.TokenBalance($("#key_public").val(), function (data) {
console.log(`Token balance: ${data}`);
$('#token_balance').text(data.toLocaleString());
});
}
function onSearchMetadata() {
Credible.SearchMetadata($("#search_metadata").val(), function (data) {
$("#div_transaction_ids").html('');
data.forEach(elm => {
$("#div_transaction_ids").append("<p><a href='javascript:onDetail(\"" + elm.id + "\")'>" + elm.id + "</a></p>");
});
});
}
</script>
</body>
</html>