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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
/*
This file is part of TALER
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
var EXPORTED_SYMBOLS = [
'TWRhelloWorld',
'TWRgetValue',
'TWRgetFraction',
'TWRgetCurrency',
'TamountCmp',
'TWRverifyConfirmation',
'TWRverifySignKey',
'TWRverifyDenom',
'TWRverifyDenoms',
'TWRALLrsaPublicKeyHash',
'TWRALLgetEncodingFromRsaSignature',
'DWRtestStringCmp',
'TWRmultiplyAmount',
'TWRmultiplyAmounts',
'DWRdumpAmount',
'TWRALLgetAmount',
'DWRtestString',
'DWRgetPurpose',
'TWReddsaVerify',
'TamountAdd',
'TamountSubtract',
'TWRALLmakeEddsaSignature',
'TWRALLamountAdd',
'TWRALLeddsaPublicKeyFromPrivate',
'TWRALLeddsaPublicKeyFromPrivString',
'TWRALLeddsaPrivateKeyFromString',
'TWRALLeccEcdh',
'TWRALLhash',
'TWRALLecdhePublicKeyFromPrivateKey',
'TWRALLrsaPublicKeyDecodeFromString',
'GCeddsaSign',
'TWRALLmakeWithdrawBundle',
'GCALLrsaSignatureDecode',
'GCrsaSignatureEncode',
'TWRALLsignDepositPermission',
'GCALLrsaPublicKeyDecode',
'GCALLrsaPublicKeyEncode',
'WRALLeddsaPublicKey',
'GCALLeddsaKeyCreate',
'WRALLecdhePublicKey ',
'GSALLdataToStringAlloc',
'TWRgnunetFree',
'GSstringToData',
'TWRALLgetCurrentTime',
'TWRgetFancyTime',
'GChash',
'getHashedArray',
'TWRALLsignTest',
'GCALLecdheKeyCreate',
'GCecdheKeyGetPublic',
'WRALLecdhePublicKey',
'WRverifyTest',
'GCeccEcdh',
'TWRALLgenSymmetricKey',
'TWRALLgenInitVector',
'GCsymmetricDecrypt',
'GCsymmetricEncrypt',
'TWRALLgenKeyFromBlob',
'GCALLrsaPrivateKeyGetPublic',
'GCALLrsaPrivateKeyCreate',
'GCALLrsaBlindingKeyCreate',
'GCrsaBlindingKeyFree',
'GCrsaPublicKeyFree',
'GCrsaPrivateKeyFree',
'GCALLrsaBlind',
'GCALLrsaUnblind',
'GCALLrsaSign',
'GCrsaVerify',
'GCrsaSignatureFree',
'GCeddsaKeyGetPublic',
'WRALLmakePurpose',
'GChkdf',
'emscMalloc',
'emscFree'
];
/* The following definition is needed to make emscripted library to remain
'alive' after its loading. Otherwise, the normal behaviour would be:
loading -> look for a 'main()' -> if one is found execute it then exit,
otherwise just exit. See https://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html
DO NOTE: this definition MUST precede the importing/loading of the emscripted
library */
/* FIXME
getLastWindow().Module = {
onRuntimeInitialized: function() {
}
};
*/
/* According to emscripten's design, we need our emscripted library to be executed
with a 'window' object as its global scope.
Note: that holds on emscripten's functions too, that is they need to be *explicitly*
run with some 'window' object as their global scope. In practice, given a function
'foo' pointing to some emscripted function, that is accomplished by the mean of 'call()'
or 'apply()' methods; so, being 'someWin' a 'window' object, the statements
foo.call('someWin', arg1, .., argN) or foo.apply('someWin', ['arg1', .., 'argN']) will
execute foo(arg1, .., argN) with 'someWin' as its global scope.
See http://www.bennadel.com/blog/2265-changing-the-execution-context-of-javascript
-functions-using-call-and-apply.htm. */
/* The naming convention is such that:
- 'GCfunctionName' takes its code from GNUNET_CRYPTO_function_name
- 'GCALLfunctionName' takes its code from GNUNET_CRYPTO_function_name and returns
a pointer that must be deallocated using 'WRgnunetFree' (that takes its code from
'GNUNET_free' in the wrapper)
- 'GSfunctionName' and 'GSALLfunctionName' comply to the same convention respect to
GNUNET_STRINGS_* realm.
- 'TWRfunctionName' takes its code from 'TALER_function_name' in the wrapper.
- 'TWRALLfunctionName' takes its code from 'TALER_ALL_function_name' in the wrapper
and returns a pointer that must be deallocated using 'TWRgnunetFree' (or a function
provided by some emscripted routine) (the 'wrapper' is an additional layer written in
C that does some struct(s) manipulations where that is uncovenient to do from JavaScript.
Currently located at '../../emscripten/testcases/wrap.c')
- The same applies to 'TfunctionName' and 'TALLfunctionName', to indicate that the
respective functions come from (the emscripted version of) TALER_* realm. */
// shortcut to emscr's 'malloc'
function emscMalloc(size) {
var ptr = Module._malloc(size);
return ptr;
}
/* shortcut to emscr's 'free'. This function is problematic:
it randomly stops working giving 'emscFree is not a function'
error */
function emscFree(ptr) {
Module._free(ptr);
}
var getEmsc = Module.cwrap;
var TWRhelloWorld = getEmsc('TALER_WR_hello_world', 'void', []);
var TWRverifyConfirmation = getEmsc('TALER_WR_verify_confirmation',
'number',
['number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number']);
var TWRgetValue = getEmsc('TALER_WR_get_value',
'number',
['number']);
var TWRgetFraction = getEmsc('TALER_WR_get_fraction',
'number',
['number']);
var TWRgetCurrency = getEmsc('TALER_WR_get_currency',
'string',
['number']);
var TWRmultiplyAmounts = getEmsc('TALER_WR_multiply_amounts',
'number',
['number',
'number'] );
var TWRmultiplyAmount = getEmsc('TALER_WR_multiply_amount',
'number',
['number',
'number'] );
var TWRALLrsaPublicKeyHash = getEmsc('TALER_WRALL_rsa_public_key_hash',
'number',
['number']);
var TWRverifyDenom = getEmsc('TALER_WR_verify_denom',
'number',
['number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number']);
var TWRverifyDenoms = getEmsc('TALER_WR_verify_denoms',
'number',
['number',
'number',
'number',
'number',
'number']);
var TWRverifySignKey = getEmsc('TALER_WR_verify_sign_key',
'number',
['number',
'number',
'number',
'number',
'number',
'number']);
var TWRALLgetEncodingFromRsaSignature = getEmsc('TALER_WRALL_get_encoding_from_rsa_signature',
'number',
['number']);
var TamountCmp = getEmsc('TALER_amount_cmp',
'number',
['number',
'number']);
var DWRdumpAmount = getEmsc('DEBUG_WR_dump_amount',
'void'
['number']);
var DWRtestStringCmp = getEmsc('DEBUG_WR_test_string_cmp',
'number',
['number',
'string']);
var TWRALLgetAmount = getEmsc('TALER_WRALL_get_amount',
'number',
['number',
'number',
'number',
'string']);
var DWRgetPurpose = getEmsc('DEBUG_WR_get_purpose',
'number',
['number']);
var TWReddsaVerify = getEmsc('TALER_WR_eddsa_verify',
'number',
['string',
'number',
'number',
'number']);
var TWRALLmakeEddsaSignature = getEmsc('TALER_WRALL_make_eddsa_signature',
'number',
['number',
'number']);
var TWRALLamountAdd = getEmsc('TALER_WRALL_amount_add',
'number',
['number',
'number',
'number',
'number',
'number',
'number',
'string']);
var TamountSubtract = getEmsc('TALER_amount_subtract',
'number',
['number',
'number',
'number']);
var TamountAdd = getEmsc('TALER_amount_add',
'number',
['number',
'number',
'number']);
var TWRALLeddsaPublicKeyFromPrivate = getEmsc('TALER_WRALL_eddsa_public_key_from_private',
'number',
['number']);
var TWRALLeddsaPublicKeyFromPrivString = getEmsc('TALER_WRALL_eddsa_public_key_from_priv_string',
'number',
['string']);
var TWRALLsignDepositPermission = getEmsc('TALER_WRALL_sign_deposit_permission',
'number',
['number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number',
'number']);
var TWRALLeddsaPrivateKeyFromString = getEmsc('TALER_WRALL_eddsa_private_key_from_string',
'number',
['string']);
var TWRALLrsaPublicKeyDecodeFromString = getEmsc('TALER_WRALL_rsa_public_key_decode_from_string',
'number',
['string']);
var TWRALLecdhePublicKeyFromPrivateKey = getEmsc('TALER_WRALL_ecdhe_public_key_from_private_key',
'number',
['number']);
var TWRALLeccEcdh = getEmsc('TALER_WRALL_ecc_ecdh',
'number',
['number',
'number',
'number']);
var TWRALLmakeWithdrawBundle = getEmsc('TALER_WRALL_make_withdraw_bundle',
'number',
['number',
'number',
'number',
'number',
'number',
'number']);
var WRALLmakePurpose = getEmsc('WRALL_make_purpose',
'number',
['string',
'number',
'number',
'number']);
var GCALLrsaSignatureDecode = getEmsc('GNUNET_CRYPTO_rsa_signature_decode',
'number',
['number',
'number']);
var GCALLrsaSignatureEncode = getEmsc('GNUNET_CRYPTO_rsa_signature_encode',
'number',
['number',
'number']);
var GCALLrsaPublicKeyEncode = getEmsc('GNUNET_CRYPTO_rsa_public_key_encode',
'number',
['number',
'number']);
var GCALLrsaPublicKeyDecode = getEmsc('GNUNET_CRYPTO_rsa_public_key_decode',
'number',
['number',
'number']);
var GCALLrsaPrivateKeyGetPublic = getEmsc('GNUNET_CRYPTO_rsa_private_key_get_public',
'number',
['number']);
var GCALLrsaPrivateKeyCreate = getEmsc('GNUNET_CRYPTO_rsa_private_key_create',
'number',
['number']);
var GCALLrsaBlindingKeyCreate = getEmsc('GNUNET_CRYPTO_rsa_blinding_key_create',
'number',
['number']);
var GCrsaBlindingKeyFree = getEmsc('GNUNET_CRYPTO_rsa_blinding_key_free',
'void',
['number']);
var GCrsaPublicKeyFree = getEmsc('GNUNET_CRYPTO_rsa_public_key_free',
'void',
['number']);
var GCrsaPrivateKeyFree = getEmsc('GNUNET_CRYPTO_rsa_private_key_free',
'void',
['number']);
var GCALLrsaBlind = getEmsc('GNUNET_CRYPTO_rsa_blind',
'number',
['number',
'number',
'number',
'number']);
var GCALLrsaUnblind = getEmsc('GNUNET_CRYPTO_rsa_unblind',
'number',
['number',
'number',
'number']);
var GCALLrsaSign = getEmsc('GNUNET_CRYPTO_rsa_sign',
'number',
['number',
'number',
'number']);
var GCrsaVerify = getEmsc('GNUNET_CRYPTO_rsa_verify',
'number',
['number',
'number',
'number']);
var GCrsaSignatureFree = getEmsc('GNUNET_CRYPTO_rsa_signature_free',
'void',
['number']);
var GChkdf = getEmsc('GNUNET_CRYPTO_hkdf',
'number',
['number',
'number',
'number',
'number',
'number',
'number',
'number',
'number']);
var TWRALLgenKeyFromBlob = getEmsc('TALER_WRALL_gen_key_from_blob',
'number',
['string',
'number',
'number']);
var DWRtestString = getEmsc('DEBUG_WR_test_string',
'void',
['number',
'number',
'string']);
var GCsymmetricDecrypt = getEmsc('GNUNET_CRYPTO_symmetric_decrypt',
'number',
['number',
'number',
'number',
'number',
'number']);
var GCsymmetricEncrypt = getEmsc('GNUNET_CRYPTO_symmetric_encrypt',
'number',
['number',
'number',
'number',
'number',
'number']);
/* returns a pointer to a symmetric session key strucure and takes a salt, a
(pointer to) binary data used to generate the key, and the length of that
data */
var TWRALLgenSymmetricKey = getEmsc('TALER_WRALL_gen_symmetric_key',
'number',
['string',
'number',
'number']);
/* returns a pointer to a init. vector strucure and takes a salt, a
(pointer to) binary data used to generate the key, and the length of that
data */
var TWRALLgenInitVector = getEmsc('TALER_WRALL_gen_init_vector',
'number',
['string',
'number',
'number']);
// return key material from ECC keys
var GCeccEcdh = getEmsc('GNUNET_CRYPTO_ecc_ecdh',
'number',
['number',
'number',
'number']);
// return a pointer to a freshly allocated EddsaPublicKey structure
/* var WRALLeddsaPublicKey = getEmsc('WRALL_eddsa_public_key',
'number'); */
// return a pointer to a freshly allocated EcdhePublicKey structure
/* var WRALLecdhePublicKey = getEmsc('WRALL_ecdhe_public_key',
'number'); */
/* generates a new eddsa private key, returning a pointer to EddsaPrivateKey
structure */
var GCALLeddsaKeyCreate = getEmsc('GNUNET_CRYPTO_eddsa_key_create',
'number');
/* extract eddsa public key from a pointer to a EddsaPrivateKey structure
and put it in second argument */
var GCeddsaKeyGetPublic = getEmsc('GNUNET_CRYPTO_eddsa_key_get_public',
'void',
['number',
'number']);
/* generates a new ecdhe private key, returning a pointer to EcdhePrivateKey
structure */
var GCALLecdheKeyCreate = getEmsc('GNUNET_CRYPTO_ecdhe_key_create',
'number');
/* extract eddsa public key from a pointer to a EddsaPrivateKey structure and
put it in second argument */
var GCecdheKeyGetPublic = getEmsc('GNUNET_CRYPTO_ecdhe_key_get_public',
'void',
['number',
'number']);
// what to sign, the reason to sign, the location to store the signature
var GCeddsaSign = getEmsc('GNUNET_CRYPTO_eddsa_sign',
'int',
['number',
'number',
'number']);
/* get reference to the emscripted primitive: the first parameter is a
pointer (note that it points to the emscripten's heap) to the data being
encoded, the second is its length */
var GSALLdataToStringAlloc = getEmsc('GNUNET_STRINGS_data_to_string_alloc',
'number',
['number',
'number']);
// import GNUnet's memory deallocator
var TWRgnunetFree = getEmsc('TALER_WR_GNUNET_free',
'void',
['number']);
// GNUnet's base32 decoder
var GSstringToData = getEmsc('GNUNET_STRINGS_string_to_data',
'number',
['number',
'number',
'number',
'number']);
// get absolute time. Returned value has to be freed by gnunetFree
var TWRALLgetCurrentTime = getEmsc('TALER_WRALL_get_current_time',
'number');
// prettyfy time
var TWRgetFancyTime = getEmsc('TALER_WR_get_fancy_time',
'string',
['number']);
var TWRALLhash = getEmsc('TALER_WRALL_hash',
'number',
['number',
'number']);
/* computes the hashcode of the value pointed to by 'val' and sets the
pointer to the location holding the hashcode (which has to be previously
allocated and is a reflection of GNUNET_HashCode type). The returned
pointer has to be freed by gnunetFree.
Its interface is hash('val', 'valSize', 'hashedBuf') */
var GChash = getEmsc('GNUNET_CRYPTO_hash',
'void',
['number',
'number',
'number']);
/* this test just takes the private key to sign a dummy hardcoded
message. Return a pointer to the signed message (to be freed) */
var TWRALLsignTest = getEmsc('TALER_WRALL_sign_test',
'number',
['number']);
/* this test just takes the public key and the signed dummy
message. Return GNUNET_OK (=1) if it succeeds, otherwise
GNUNET_SYSERR (=-1) */
var WRverifyTest = getEmsc('WR_verify_test',
'number',
['number']);
|