Fix rest of tsc errors, fix tests

pull/39/head
HenryNguyen5 6 years ago
parent 85b2e40c28
commit a7d28acca9

@ -26,7 +26,6 @@
// 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.
import assert from "assert";
import {
cn_fast_hash,
NetType,
@ -49,21 +48,19 @@ const nettype = NetType.MAINNET;
describe("cryptonote_utils tests", function() {
it("is valid hex", function() {
const valid = valid_hex(private_key);
assert.strictEqual(valid, true);
expect(valid).toEqual(true);
});
it("fast hash / keccak-256", function() {
const hash = cn_fast_hash(private_key);
assert.equal(
hash,
expect(hash).toEqual(
"64997ff54f0d82ee87d51e971a0329d4315481eaeb4ad2403c65d5843480c414",
);
});
it("generate key derivation", function() {
const derivation = generate_key_derivation(public_key, private_key);
assert.equal(
derivation,
expect(derivation).toEqual(
"591c749f1868c58f37ec3d2a9d2f08e7f98417ac4f8131e3a57c1fd71273ad00",
);
});
@ -79,7 +76,7 @@ describe("cryptonote_utils tests", function() {
view:
"576f0e61e250d941746ed147f602b5eb1ea250ca385b028a935e166e18f74bd7",
};
assert.deepEqual(decoded, expected);
expect(decoded).toEqual(expected);
});
it("decode mainnet integrated address", function() {
@ -94,13 +91,12 @@ describe("cryptonote_utils tests", function() {
"576f0e61e250d941746ed147f602b5eb1ea250ca385b028a935e166e18f74bd7",
intPaymentId: "83eab71fbee84eb9",
};
assert.deepEqual(decoded, expected);
expect(decoded).toEqual(expected);
});
it("hash_to_scalar", function() {
const scalar = hash_to_scalar(private_key);
assert.equal(
scalar,
expect(scalar).toEqual(
"77c5899835aa6f96b13827f43b094abf315481eaeb4ad2403c65d5843480c404",
);
});
@ -108,8 +104,7 @@ describe("cryptonote_utils tests", function() {
it("derivation_to_scalar", function() {
const derivation = generate_key_derivation(public_key, private_key);
const scalar = derivation_to_scalar(derivation, 1);
assert.equal(
scalar,
expect(scalar).toEqual(
"201ce3c258e09eeb6132ec266d24ee1ca957828f384ce052d5bc217c2c55160d",
);
});
@ -117,8 +112,7 @@ describe("cryptonote_utils tests", function() {
it("derive public key", function() {
const derivation = generate_key_derivation(public_key, private_key);
const output_key = derive_public_key(derivation, 1, public_key);
assert.equal(
output_key,
expect(output_key).toEqual(
"da26518ddb54cde24ccfc59f36df13bbe9bdfcb4ef1b223d9ab7bef0a50c8be3",
);
});
@ -130,8 +124,7 @@ describe("cryptonote_utils tests", function() {
derivation,
1,
);
assert.equal(
subaddress_public_key,
expect(subaddress_public_key).toEqual(
"dfc9e4a0039e913204c1c0f78e954a7ec7ce291d8ffe88265632f0da9d8de1be",
);
});

@ -355,7 +355,7 @@ export function cn_fast_hash(input: string) {
}
const hasher = new SHA3(256);
hasher.update(hextobin(input));
hasher.update(Buffer.from((hextobin(input).buffer as any) as Buffer));
return hasher.digest("hex");
}
@ -983,7 +983,7 @@ interface BorromeanSignature {
export function genBorromean(
xv: string[],
pm: string[][],
iv: string[],
iv: string[] | string,
size: number,
nrings: number,
) {
@ -1466,13 +1466,7 @@ function verRctMGSimple(
kimg: string,
) {
try {
const cols = pubs.length;
const M: string[][] = [];
for (let i = 0; i < cols; i++) {
M[i][0] = pubs[i].dest;
M[i][1] = ge_sub(pubs[i].mask, C);
}
const M: string[][] = pubs.map(pub => [pub.dest, ge_sub(pub.mask, C)]);
return MLSAG_ver(message, M, mg, kimg);
} catch (error) {
@ -2323,6 +2317,9 @@ function construct_tx(
}
console.log("Adding payment id: " + payment_id);
if (pid_encrypt) {
if (!realDestViewKey) {
throw Error("RealDestViewKey not found");
}
//get the derivation from our passed viewkey, then hash that + tail to get encryption key
const pid_key = cn_fast_hash(
generate_key_derivation(realDestViewKey, txkey.sec) +
@ -2522,10 +2519,15 @@ function construct_tx(
input.amount = "0";
}
mixRing[i] = sourcesWithKeyImgAndKeys[i].outputs.map(o => ({
dest: o.key,
mask: o.commit,
}));
mixRing[i] = sourcesWithKeyImgAndKeys[i].outputs.map(o => {
if (!o.commit) {
throw Error("Commit not found");
}
return {
dest: o.key,
mask: o.commit,
};
});
indices.push(sourcesWithKeyImgAndKeys[i].real_out);
});

@ -45,43 +45,33 @@ const __STAGENET_CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 25;
const __STAGENET_CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = 36;
export function cryptonoteBase58PrefixForStandardAddressOn(nettype: NetType) {
if (!nettype) {
console.warn("Unexpected nil nettype");
}
if (nettype == NetType.MAINNET) {
if (nettype === NetType.MAINNET) {
return __MAINNET_CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.TESTNET) {
} else if (nettype === NetType.TESTNET) {
return __TESTNET_CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.STAGENET) {
} else if (nettype === NetType.STAGENET) {
return __STAGENET_CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
}
throw Error("Illegal nettype");
}
export function cryptonoteBase58PrefixForIntegratedAddressOn(nettype: NetType) {
if (!nettype) {
console.warn("Unexpected nil nettype");
}
if (nettype == NetType.MAINNET) {
if (nettype === NetType.MAINNET) {
return __MAINNET_CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.TESTNET) {
} else if (nettype === NetType.TESTNET) {
return __TESTNET_CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.STAGENET) {
} else if (nettype === NetType.STAGENET) {
return __STAGENET_CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
}
throw Error("Illegal nettype");
}
export function cryptonoteBase58PrefixForSubAddressOn(nettype: NetType) {
if (!nettype) {
console.warn("Unexpected nil nettype");
}
if (nettype == NetType.MAINNET) {
if (nettype === NetType.MAINNET) {
return __MAINNET_CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.TESTNET) {
} else if (nettype === NetType.TESTNET) {
return __TESTNET_CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
} else if (nettype == NetType.STAGENET) {
} else if (nettype === NetType.STAGENET) {
return __STAGENET_CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
}
throw Error("Illegal nettype");

@ -2,6 +2,8 @@ declare module "keccakjs" {
type Message = Buffer | string;
class Hasher {
constructor(bitlength: number);
/**
* Update hash
*
@ -12,7 +14,7 @@ declare module "keccakjs" {
/**
* Return hash in integer array.
*/
digest(): number[];
digest(encoding?: "hex" | "binary"): string;
}
export = Hasher;

@ -123,7 +123,7 @@ export function parseAddressTransactions(
scanned_block_height: account_scanned_block_height,
scanned_height: account_scanned_height,
start_height: account_scan_start_height,
total_received,
/*total_received*/
transaction_height,
transactions,
} = normalizeAddressTransactions(data);

@ -2,7 +2,6 @@ import { ParsedTarget, RawTarget } from "./types";
import { NetType } from "cryptonote_utils/nettype";
import { ERR } from "./errors";
import { possibleOAAddress } from "./open_alias_lite";
import { BigInt } from "biginteger";
import { decode_address } from "cryptonote_utils";
import { parseMoney } from "cryptonote_utils/formatters";

Loading…
Cancel
Save