11< html >
22 < head >
33 < script >
4-
4+ console . log ( 'running main.' ) ;
5+ function bodyOnloadHandler ( ) {
6+ console . log ( "body onload" ) ;
7+ main ( ) ;
8+ }
59 function overwriteConsoleLog ( ) {
610 var old = console . log ;
711 var logger = document . getElementById ( 'log' ) ;
1317 }
1418 }
1519 }
16-
17-
18- // This is read and used by `site.js`
20+
21+ /*
22+ // for wasm
1923 var Module = {
2024 wasmBinaryFile: "rustbn.wasm",
2125 onRuntimeInitialized: main,
2226 }
27+ */
28+
2329 function main ( ) {
2430 overwriteConsoleLog ( ) ;
25-
26- //let add = Module.cwrap('add', 'number', ['number', 'number']);
27- //let bn128 = Module.cwrap('bn128', 'number', []);
28-
29- console . log ( 'Do something with the Rust functions exposed here!' ) ;
30- //console.log(add(1, 2));
31-
32- //console.log('Doing ecadd and ecmul.');
33- //console.log(bn128());
31+
32+ const ecMul = Module . cwrap ( 'ec_mul' , 'string' , [ 'string' ] ) ;
33+ const ecAdd = Module . cwrap ( 'ec_add' , 'string' , [ 'string' ] ) ;
34+ const ecPairing = Module . cwrap ( 'ec_pairing' , 'string' , [ 'string' ] ) ;
35+
36+ // TODO: more test cases
37+
38+ //let points_input = p1 + p2;
39+ //let points_input = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
40+
41+ let p1 = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
42+ let p2 = '30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001'
43+
44+ let ecMul_points_input = p1 + p2 ;
45+ try {
46+ let ecMul_result = ecMul ( ecMul_points_input ) ;
47+ console . log ( 'ecMul_result: ' + ecMul_result ) ;
48+ } catch ( e ) {
49+ console . log ( 'ecMul_result caught error.' ) ;
50+ console . log ( e ) ;
51+ }
52+
53+ //let ecAdd_points_input = '0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba0f25919bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba';
54+ //let ecAdd_points_input = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
55+ let add_p1 = '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002' ;
56+ let add_p2 = '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002' ;
57+
58+ let ecAdd_points_input = add_p1 + add_p2 ;
59+ try {
60+ let ecAdd_result = ecAdd ( ecAdd_points_input ) ;
61+ console . log ( 'ecAdd_result: ' + ecAdd_result ) ;
62+ // 030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4
63+ } catch ( e ) {
64+ console . log ( 'ecAdd caught error.' ) ;
65+ console . log ( e ) ;
66+ }
67+
3468 }
3569 </ script >
36- < script src ="index.wasm .js "> </ script >
70+ < script src ="../lib/ index.asm .js "> </ script >
3771 </ head >
38- < body >
72+ < body onload =" bodyOnloadHandler() " >
3973 < div id ="log "> </ div >
4074 </ body >
4175</ html >
0 commit comments