Merge pull request #29 from HenryNguyen5/test/add-tests
[Test/add tests] Add tests for genBorromean and MLSAG_genpull/30/head
commit
ff3e2361f2
@ -0,0 +1,114 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const monero_utils = require("../").monero_utils;
|
||||
|
||||
it("MG_sigs", () => {
|
||||
function skvGen(len) {
|
||||
let skVec = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
skVec.push(monero_utils.skGen());
|
||||
}
|
||||
return skVec;
|
||||
}
|
||||
//initializes a key matrix;
|
||||
//first parameter is rows,
|
||||
//second is columns
|
||||
function keyMInit(rows, cols) {
|
||||
let rv = [];
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rv.push([]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
let j = 0;
|
||||
|
||||
//Tests for MG Sigs
|
||||
//#MG sig: true one
|
||||
let N = 3; // cols
|
||||
let R = 2; // rows
|
||||
|
||||
let xtmp = skvGen(R);
|
||||
let xm = keyMInit(R, N); // = [[None]*N] #just used to generate test public keys
|
||||
let sk = skvGen(R);
|
||||
|
||||
// [
|
||||
// [pubkey1, commitment1],
|
||||
// [pubkey2, commitment2],
|
||||
// ...
|
||||
// [pubkeyn, commitmentn]]
|
||||
// // Gen creates a signature which proves that for some column in the keymatrix "pk"
|
||||
// the signer knows a secret key for each row in that column
|
||||
let P = keyMInit(R, N); // = keyM[[None]*N] #stores the public keys;
|
||||
|
||||
let ind = 2;
|
||||
let i = 0;
|
||||
|
||||
for (j = 0; j < R; j++) {
|
||||
for (i = 0; i < N; i++) {
|
||||
xm[i][j] = monero_utils.skGen();
|
||||
P[i][j] = monero_utils.ge_scalarmult_base(xm[i][j]); // generate fake [pubkey, commit]
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < R; j++) {
|
||||
// our secret vector of [onetimesec, z]
|
||||
sk[j] = xm[ind][j];
|
||||
}
|
||||
|
||||
let message = monero_utils.identity();
|
||||
let kimg = monero_utils.ge_scalarmult(
|
||||
monero_utils.hashToPoint(P[ind][0]),
|
||||
sk[0],
|
||||
);
|
||||
let rv = monero_utils.MLSAG_Gen(message, P, sk, kimg, ind);
|
||||
let c = monero_utils.MLSAG_ver(message, P, rv, kimg);
|
||||
|
||||
expect(Number(c)).toEqual(0);
|
||||
|
||||
xtmp = skvGen(R);
|
||||
xm = keyMInit(R, N); // = [[None]*N] #just used to generate test public keys
|
||||
sk = skvGen(R);
|
||||
|
||||
for (j = 0; j < R; j++) {
|
||||
for (i = 0; i < N; i++) {
|
||||
xm[i][j] = monero_utils.skGen();
|
||||
P[i][j] = monero_utils.ge_scalarmult_base(xm[i][j]); // generate fake [pubkey, commit]
|
||||
}
|
||||
}
|
||||
|
||||
sk[1] = skGen(); //assume we don't know one of the private keys..
|
||||
kimg = monero_utils.ge_scalarmult(
|
||||
monero_utils.hashToPoint(P[ind][0]),
|
||||
sk[0],
|
||||
);
|
||||
rv = monero_utils.MLSAG_Gen(message, P, sk, kimg, ind);
|
||||
c = monero_utils.MLSAG_ver(message, P, rv, kimg);
|
||||
|
||||
expect(Number(c)).toBeFalsy();
|
||||
});
|
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const monero_utils = require("../../").monero_utils;
|
||||
const { generate_parameters } = require("./test_parameters");
|
||||
const { indi, P1v, P2v, xv, N } = generate_parameters();
|
||||
|
||||
it("borromean_3", () => {
|
||||
// #true one
|
||||
const bb = monero_utils.genBorromean(xv, [P1v, P2v], indi, 2, N); /*?.*/
|
||||
const valid = monero_utils.verifyBorromean(bb, P1v, P2v); /*?.*/
|
||||
expect(valid).toBe(true);
|
||||
});
|
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const monero_utils = require("../../").monero_utils;
|
||||
const { generate_parameters } = require("./test_parameters");
|
||||
const { indi, P1v, P2v, xv, N } = generate_parameters();
|
||||
|
||||
it("borromean_2", () => {
|
||||
//#false one
|
||||
indi[3] = `${(+indi[3] + 1) % 2}`;
|
||||
const bb = monero_utils.genBorromean(xv, [P1v, P2v], indi, 2, N); /*?.*/
|
||||
const valid = monero_utils.verifyBorromean(bb, P1v, P2v); /*?.*/
|
||||
expect(valid).toBe(false);
|
||||
});
|
@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const monero_utils = require("../../").monero_utils;
|
||||
const { generate_parameters } = require("./test_parameters");
|
||||
const { indi, P1v, P2v, xv, N } = generate_parameters();
|
||||
|
||||
it("borromean_3", () => {
|
||||
//#true one again
|
||||
indi[3] = `${(+indi[3] + 1) % 2}`;
|
||||
indi[3] = `${(+indi[3] + 1) % 2}`;
|
||||
|
||||
const bb = monero_utils.genBorromean(xv, [P1v, P2v], indi, 2, N); /*?.*/
|
||||
const valid = monero_utils.verifyBorromean(bb, P1v, P2v); /*?.*/
|
||||
expect(valid).toBe(true);
|
||||
});
|
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const monero_utils = require("../../").monero_utils;
|
||||
const { generate_parameters } = require("./test_parameters");
|
||||
const { indi, P1v, P2v, xv, N } = generate_parameters();
|
||||
|
||||
it("borromean_4", () => {
|
||||
// #false one
|
||||
const bb = monero_utils.genBorromean(xv, [P2v, P1v], indi, 2, N); /*?.*/
|
||||
const valid = monero_utils.verifyBorromean(bb, P1v, P2v); /*?.*/
|
||||
expect(valid).toBe(false);
|
||||
});
|
@ -0,0 +1,83 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const mnemonic = require("../../cryptonote_utils/mnemonic");
|
||||
const monero_utils = require("../../").monero_utils;
|
||||
|
||||
function randomBit() {
|
||||
// get random 32 bits in hex
|
||||
const rand32bits = mnemonic.mn_random(32);
|
||||
// take 4 bits "nibble" and convert to binary
|
||||
// then take last index
|
||||
return monero_utils.padLeft(
|
||||
parseInt(rand32bits[0], 16).toString(2),
|
||||
4,
|
||||
0,
|
||||
)[3];
|
||||
}
|
||||
|
||||
//Tests for Borromean signatures
|
||||
//#boro true one, false one, C != sum Ci, and one out of the range..
|
||||
const N = 64;
|
||||
let xv = [], // vector of secret keys, 1 per ring (nrings)
|
||||
P1v = [], //key64, arr of commitments Ci
|
||||
P2v = [], //key64
|
||||
indi = []; // vector of secret indexes, 1 per ring (nrings), can be a string
|
||||
|
||||
let indi_2 = [];
|
||||
let indi_3 = [];
|
||||
let indi_4 = [];
|
||||
|
||||
let generated = false;
|
||||
|
||||
function generate_parameters() {
|
||||
if (generated) {
|
||||
const indiCopy = [...indi];
|
||||
|
||||
return { xv, P1v, P2v, indi: indiCopy, N };
|
||||
} else {
|
||||
for (let j = 0; j < N; j++) {
|
||||
indi[j] = randomBit(); /*?.*/
|
||||
|
||||
xv[j] = monero_utils.skGen(); /*?.*/
|
||||
|
||||
if (+indi[j] === 0) {
|
||||
P1v[j] = monero_utils.ge_scalarmult_base(xv[j]); /*?.*/
|
||||
} else {
|
||||
P1v[j] = monero_utils.ge_scalarmult_base(xv[j]); // calculate aG = xv[j].G /*?.*/
|
||||
P1v[j] = monero_utils.ge_add(P1v[j], monero_utils.H2[j]); // calculate aG + H2 /*?.*/
|
||||
}
|
||||
|
||||
P2v[j] = monero_utils.ge_sub(P1v[j], monero_utils.H2[j]); /*?.*/
|
||||
}
|
||||
generated = true;
|
||||
return { xv, P1v, P2v, indi, N };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { generate_parameters };
|
@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const JSBigInt = require("../cryptonote_utils/biginteger").BigInteger;
|
||||
const monero_utils = require("../").monero_utils;
|
||||
|
||||
it("ecdh_roundtrip", () => {
|
||||
const test_amounts = [
|
||||
new JSBigInt(1),
|
||||
new JSBigInt(1),
|
||||
new JSBigInt(2),
|
||||
new JSBigInt(3),
|
||||
new JSBigInt(4),
|
||||
new JSBigInt(5),
|
||||
new JSBigInt(10000),
|
||||
|
||||
new JSBigInt("10000000000000000000"),
|
||||
new JSBigInt("10203040506070809000"),
|
||||
|
||||
new JSBigInt("123456789123456789"),
|
||||
];
|
||||
|
||||
for (const amount of test_amounts) {
|
||||
const k = monero_utils.skGen();
|
||||
const scalar = monero_utils.skGen(); /*?*/
|
||||
const amt = monero_utils.d2s(amount.toString());
|
||||
const t0 = {
|
||||
mask: scalar,
|
||||
amount: amt,
|
||||
};
|
||||
|
||||
// both are strings so we can shallow copy
|
||||
let t1 = { ...t0 };
|
||||
|
||||
t1 = monero_utils.encode_rct_ecdh(t1, k);
|
||||
|
||||
t1 = monero_utils.decode_rct_ecdh(t1, k);
|
||||
expect(t1.mask).toEqual(t0.mask);
|
||||
expect(t1.amount).toEqual(t0.amount);
|
||||
}
|
||||
});
|
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2014-2018, MyMonero.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
module.exports = function(wallaby) {
|
||||
process.env.NODE_ENV = "development";
|
||||
|
||||
return {
|
||||
name: "mymonero-core-js",
|
||||
files: [
|
||||
"cryptonote_utils/**/*.js",
|
||||
"hostAPI/**/*.js",
|
||||
"monero_utils/**/*.js",
|
||||
"index.js",
|
||||
"tests/borromean/test_parameters.js",
|
||||
],
|
||||
|
||||
filesWithNoCoverageCalculated: [
|
||||
"cryptonote_utils/nacl-fast-cn.js",
|
||||
"cryptonote_utils/biginteger.js",
|
||||
"cryptonote_utils/sha3.js",
|
||||
"cryptonote_utils/cryptonote_crypto_EMSCRIPTEN.js",
|
||||
],
|
||||
|
||||
tests: ["./tests/**/*spec.js"],
|
||||
|
||||
testFramework: "jest",
|
||||
|
||||
env: { type: "node", runner: "node" },
|
||||
};
|
||||
};
|
Loading…
Reference in new issue