Skip to content

Commit 044cd64

Browse files
authored
Merge pull request #2 from cdetrio/initial-release
initial release
2 parents 01e5f3c + 782df14 commit 044cd64

File tree

8 files changed

+213
-155
lines changed

8 files changed

+213
-155
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["holgerd77 <[email protected]>",
55
"cdetrio <[email protected]>",]
66

77
[dependencies]
8-
bn = { git = "https://github.com/paritytech/bn" }
8+
bn = { git = "https://github.com/cdetrio/bn", branch = "mont-repr-fix" }
99
rand = "0.3"
1010
rustc-serialize = "0.3"
1111
num = "0.1"

exp/index.html

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
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');
@@ -13,29 +17,59 @@
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>

exp/index.wasm.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

exp/rustbn.wasm

-135 KB
Binary file not shown.

index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
var exp = require('./lib/index.asm.js')
1+
const bn128 = require('./lib/index.asm.js')
22

3-
exp.add = exp._add
4-
exp.bn128 = exp._bn128
5-
6-
module.exports = exp
3+
module.exports = bn128

lib/index.asm.js

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)