Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["holgerd77 <[email protected]>",
"cdetrio <[email protected]>",]

[dependencies]
bn = { git = "https://github.com/paritytech/bn" }
bn = { git = "https://github.com/cdetrio/bn", branch = "mont-repr-fix" }
rand = "0.3"
rustc-serialize = "0.3"
num = "0.1"
Expand Down
64 changes: 49 additions & 15 deletions exp/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<html>
<head>
<script>

console.log('running main.');
function bodyOnloadHandler() {
console.log("body onload");
main();
}
function overwriteConsoleLog () {
var old = console.log;
var logger = document.getElementById('log');
Expand All @@ -13,29 +17,59 @@
}
}
}

// This is read and used by `site.js`

/*
// for wasm
var Module = {
wasmBinaryFile: "rustbn.wasm",
onRuntimeInitialized: main,
}
*/

function main() {
overwriteConsoleLog();

//let add = Module.cwrap('add', 'number', ['number', 'number']);
//let bn128 = Module.cwrap('bn128', 'number', []);

console.log('Do something with the Rust functions exposed here!');
//console.log(add(1, 2));

//console.log('Doing ecadd and ecmul.');
//console.log(bn128());

const ecMul = Module.cwrap('ec_mul', 'string', ['string']);
const ecAdd = Module.cwrap('ec_add', 'string', ['string']);
const ecPairing = Module.cwrap('ec_pairing', 'string', ['string']);

// TODO: more test cases

//let points_input = p1 + p2;
//let points_input = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';

let p1 = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
let p2 = '30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001'

let ecMul_points_input = p1 + p2;
try {
let ecMul_result = ecMul(ecMul_points_input);
console.log('ecMul_result: ' + ecMul_result);
} catch (e) {
console.log('ecMul_result caught error.');
console.log(e);
}

//let ecAdd_points_input = '0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba0f25919bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba';
//let ecAdd_points_input = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
let add_p1 = '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002';
let add_p2 = '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002';

let ecAdd_points_input = add_p1 + add_p2;
try {
let ecAdd_result = ecAdd(ecAdd_points_input);
console.log('ecAdd_result: ' + ecAdd_result);
// 030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4
} catch (e) {
console.log('ecAdd caught error.');
console.log(e);
}

}
</script>
<script src="index.wasm.js"></script>
<script src="../lib/index.asm.js"></script>
</head>
<body>
<body onload="bodyOnloadHandler()">
<div id="log"></div>
</body>
</html>
4 changes: 0 additions & 4 deletions exp/index.wasm.js

This file was deleted.

Binary file removed exp/rustbn.wasm
Binary file not shown.
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
var exp = require('./lib/index.asm.js')
const bn128 = require('./lib/index.asm.js')

exp.add = exp._add
exp.bn128 = exp._bn128

module.exports = exp
module.exports = bn128
17 changes: 10 additions & 7 deletions lib/index.asm.js

Large diffs are not rendered by default.

Loading