Skip to content

Commit

Permalink
More clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Mar 6, 2024
1 parent b53b71c commit ab5d663
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
"scripts": {
"build:node": "babel dist/esm --out-dir dist/cjs",
"build:esm": "tsc",
"build": "rm -rf dist && npm run build:esm && npm run build:node && cp dist/esm/*.map dist/cjs && cp dist/esm/*.d.ts dist/cjs",
"build": "rm -rf dist && scripts/ts-build.sh",
"prepare": "npm run build",
"test": "vitest run test/*",
"wasm2b64": "node scripts/wasmToB64.js"
},
"main": "dist/cjs/rustbn.js",
"module": "dist/esm/rustbn.js",
"exports": {
"require": "dist/cjs/rustbn.js",
"import": "dist/esm/rustbn.js"
},
"dependencies": {
"@scure/base": "^1.1.5"
},
Expand Down
5 changes: 3 additions & 2 deletions scripts/ts-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ build_node() {
}
EOT
echo "> npm run build:node"
printf "${BLUE}[Node build] Working... "
printf "${BLUE}[Node build] Working...\n"

cp dist/esm/*.map dist/cjs
cp dist/esm/*.d.ts dist/cjs

npm run build:node
pwd
npx babel --config-file ./.babelrc dist/esm --out-dir dist/cjs

green "DONE"

Expand Down
2 changes: 1 addition & 1 deletion scripts/wasmToB64.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Converts WASM bytecode to JSON object to create JSON that can be loaded in ESM module without requiring `fetch`
const wasmBytes = require('fs').readFileSync('./dist/cjs/rustbn_bg.wasm')
const wasmBytes = require('fs').readFileSync('./wasm/rustbn_bg.wasm')
const encoded = Buffer.from(wasmBytes, 'binary').toString('base64');
const json = {
wasm: encoded
Expand Down
15 changes: 10 additions & 5 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,42 @@ describe('Curve operations', () => {
beforeAll(async () => {
bn128 = await initRustBN()
})
it('successful addition', function (st) {
it('successful addition', function () {
let input = '0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002'
let output = '0x030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4'
assert.equal(bn128.ec_add(input), output)

})

it('successful multiplication', function (st) {
it('successful multiplication', function () {
let input = '000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000042'
let output = '0x12e017e752e718f7d1750138f3fd97d930073164499793d9b5405a9ff30e765a11d73265f2f8035c1eb99695a20bc0e550afbc7d506f9f1a1ffcb9f0ade01454'
assert.equal(bn128.ec_mul(input), output)

})

it('successful pairing #1', function (st) {
it('successful pairing #1', function () {
let input = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa'
let output = '0x0000000000000000000000000000000000000000000000000000000000000001'
assert.equal(bn128.ec_pairing(input), output)

})

it('successful pairing #2', function (st) {
it('successful pairing #2', function () {
let input = '1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa'
let output = '0x0000000000000000000000000000000000000000000000000000000000000000'
assert.equal(bn128.ec_pairing(input), output)

})

it('successful pairing #3', function (st) {
it('successful pairing #3', function () {
let input = '1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550'
let output = '0x0000000000000000000000000000000000000000000000000000000000000000'
assert.equal(bn128.ec_pairing(input), output)
})
it.only('should pair', function() {
let input = '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa000000000000000000000000000000000000000000000000000000000000000130644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd45198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa'
const res = bn128.ec_pairing(input)
console.log(res)
})
})
Binary file added wasm/rustbn_bg.wasm
Binary file not shown.

0 comments on commit ab5d663

Please sign in to comment.