Remove unused comments and code (#3)

pull/37/head
HenryNguyen5 6 years ago committed by GitHub
parent 2805470ef3
commit 13bd665843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,7 +47,6 @@ var cnUtil = function(currencyConfig) {
config.coinUnits = new JSBigInt(10).pow(config.coinUnitPlaces);
var HASH_STATE_BYTES = 200;
var HASH_SIZE = 32;
var ADDRESS_CHECKSUM_SIZE = 4;
var INTEGRATED_ID_SIZE = 8;
@ -278,21 +277,6 @@ var cnUtil = function(currencyConfig) {
return swapEndianC((padding + a.toString(2)).slice(-64));
}
//convert integer string to 64bit base 4 little-endian string
function d2b4(integer) {
if (typeof integer !== "string" && integer.toString().length > 15) {
throw "integer should be entered as a string for precision";
}
var padding = "";
for (var i = 0; i < 31; i++) {
padding += "0";
}
var a = new JSBigInt(integer);
if (a.toString(2).length > 64) {
throw "amount overflows uint64!";
}
return swapEndianC((padding + a.toString(4)).slice(-32));
}
//end rct new functions
this.valid_hex = function(hex) {
@ -387,41 +371,16 @@ var cnUtil = function(currencyConfig) {
return bintohex(output);
};
this.cn_fast_hash = function(input, inlen) {
/*if (inlen === undefined || !inlen) {
inlen = Math.floor(input.length / 2);
}*/
this.cn_fast_hash = function(input) {
if (input.length % 2 !== 0 || !this.valid_hex(input)) {
throw "Input invalid";
}
//update to use new keccak impl (approx 45x faster)
//var state = this.keccak(input, inlen, HASH_STATE_BYTES);
//return state.substr(0, HASH_SIZE * 2);
const hasher = new SHA3(256);
hasher.update(hextobin(input));
return hasher.digest("hex");
};
//many functions below are commented out now, and duplicated with the faster nacl impl --luigi1111
// to be removed completely later
/*this.sec_key_to_pub = function(sec) {
var input = hextobin(sec);
if (input.length !== 32) {
throw "Invalid input length";
}
var input_mem = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(input, input_mem);
var ge_p3 = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var out_mem = CNCrypto._malloc(KEY_SIZE);
CNCrypto.ccall('ge_scalarmult_base', 'void', ['number', 'number'], [ge_p3, input_mem]);
CNCrypto.ccall('ge_p3_tobytes', 'void', ['number', 'number'], [out_mem, ge_p3]);
var output = CNCrypto.HEAPU8.subarray(out_mem, out_mem + KEY_SIZE);
CNCrypto._free(ge_p3);
CNCrypto._free(input_mem);
CNCrypto._free(out_mem);
return bintohex(output);
};*/
this.sec_key_to_pub = function(sec) {
if (sec.length !== 64) {
throw "Invalid sec length";
@ -434,33 +393,6 @@ var cnUtil = function(currencyConfig) {
return this.sec_key_to_pub(sec);
};
//accepts arbitrary point, rather than G
/*this.ge_scalarmult = function(pub, sec) {
if (pub.length !== 64 || sec.length !== 64) {
throw "Invalid input length";
}
var pub_b = hextobin(pub);
var sec_b = hextobin(sec);
var pub_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(pub_b, pub_m);
var sec_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(sec_b, sec_m);
var ge_p3_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var ge_p2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
if (CNCrypto.ccall("ge_frombytes_vartime", "bool", ["number", "number"], [ge_p3_m, pub_m]) !== 0) {
throw "ge_frombytes_vartime returned non-zero error code";
}
CNCrypto.ccall("ge_scalarmult", "void", ["number", "number", "number"], [ge_p2_m, sec_m, ge_p3_m]);
var derivation_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [derivation_m, ge_p2_m]);
var res = CNCrypto.HEAPU8.subarray(derivation_m, derivation_m + KEY_SIZE);
CNCrypto._free(pub_m);
CNCrypto._free(sec_m);
CNCrypto._free(ge_p3_m);
CNCrypto._free(ge_p2_m);
CNCrypto._free(derivation_m);
return bintohex(res);
};*/
this.ge_scalarmult = function(pub, sec) {
if (pub.length !== 64 || sec.length !== 64) {
throw "Invalid input length";
@ -526,24 +458,6 @@ var cnUtil = function(currencyConfig) {
// alias
this.skGen = random_scalar;
/* no longer used
this.keccak = function(hex, inlen, outlen) {
var input = hextobin(hex);
if (input.length !== inlen) {
throw "Invalid input length";
}
if (outlen <= 0) {
throw "Invalid output length";
}
var input_mem = CNCrypto._malloc(inlen);
CNCrypto.HEAPU8.set(input, input_mem);
var out_mem = CNCrypto._malloc(outlen);
CNCrypto._keccak(input_mem, inlen | 0, out_mem, outlen | 0);
var output = CNCrypto.HEAPU8.subarray(out_mem, out_mem + outlen);
CNCrypto._free(input_mem);
CNCrypto._free(out_mem);
return bintohex(output);
};*/
this.create_address = function(seed, nettype) {
var keys = {};
@ -656,37 +570,6 @@ var cnUtil = function(currencyConfig) {
return scalar;
};
/*this.generate_key_derivation = function(pub, sec) {
if (pub.length !== 64 || sec.length !== 64) {
throw "Invalid input length";
}
var pub_b = hextobin(pub);
var sec_b = hextobin(sec);
var pub_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(pub_b, pub_m);
var sec_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(sec_b, sec_m);
var ge_p3_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var ge_p2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
var ge_p1p1_m = CNCrypto._malloc(STRUCT_SIZES.GE_P1P1);
if (CNCrypto.ccall("ge_frombytes_vartime", "bool", ["number", "number"], [ge_p3_m, pub_m]) !== 0) {
throw "ge_frombytes_vartime returned non-zero error code";
}
CNCrypto.ccall("ge_scalarmult", "void", ["number", "number", "number"], [ge_p2_m, sec_m, ge_p3_m]);
CNCrypto.ccall("ge_mul8", "void", ["number", "number"], [ge_p1p1_m, ge_p2_m]);
CNCrypto.ccall("ge_p1p1_to_p2", "void", ["number", "number"], [ge_p2_m, ge_p1p1_m]);
var derivation_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [derivation_m, ge_p2_m]);
var res = CNCrypto.HEAPU8.subarray(derivation_m, derivation_m + KEY_SIZE);
CNCrypto._free(pub_m);
CNCrypto._free(sec_m);
CNCrypto._free(ge_p3_m);
CNCrypto._free(ge_p2_m);
CNCrypto._free(ge_p1p1_m);
CNCrypto._free(derivation_m);
return bintohex(res);
};*/
this.generate_key_derivation = function(pub, sec) {
if (pub.length !== 64 || sec.length !== 64) {
throw "Invalid input length";
@ -737,46 +620,6 @@ var cnUtil = function(currencyConfig) {
return bintohex(res);
};
/*this.derive_public_key = function(derivation, out_index, pub) {
if (derivation.length !== 64 || pub.length !== 64) {
throw "Invalid input length!";
}
var derivation_m = CNCrypto._malloc(KEY_SIZE);
var derivation_b = hextobin(derivation);
CNCrypto.HEAPU8.set(derivation_b, derivation_m);
var base_m = CNCrypto._malloc(KEY_SIZE);
var base_b = hextobin(pub);
CNCrypto.HEAPU8.set(base_b, base_m);
var point1_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var point2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var point3_m = CNCrypto._malloc(STRUCT_SIZES.GE_CACHED);
var point4_m = CNCrypto._malloc(STRUCT_SIZES.GE_P1P1);
var point5_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
var derived_key_m = CNCrypto._malloc(KEY_SIZE);
if (CNCrypto.ccall("ge_frombytes_vartime", "bool", ["number", "number"], [point1_m, base_m]) !== 0) {
throw "ge_frombytes_vartime returned non-zero error code";
}
var scalar_m = CNCrypto._malloc(STRUCT_SIZES.EC_SCALAR);
var scalar_b = hextobin(this.derivation_to_scalar(bintohex(CNCrypto.HEAPU8.subarray(derivation_m, derivation_m + STRUCT_SIZES.EC_POINT)), out_index));
CNCrypto.HEAPU8.set(scalar_b, scalar_m);
CNCrypto.ccall("ge_scalarmult_base", "void", ["number", "number"], [point2_m, scalar_m]);
CNCrypto.ccall("ge_p3_to_cached", "void", ["number", "number"], [point3_m, point2_m]);
CNCrypto.ccall("ge_add", "void", ["number", "number", "number"], [point4_m, point1_m, point3_m]);
CNCrypto.ccall("ge_p1p1_to_p2", "void", ["number", "number"], [point5_m, point4_m]);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [derived_key_m, point5_m]);
var res = CNCrypto.HEAPU8.subarray(derived_key_m, derived_key_m + KEY_SIZE);
CNCrypto._free(derivation_m);
CNCrypto._free(base_m);
CNCrypto._free(scalar_m);
CNCrypto._free(point1_m);
CNCrypto._free(point2_m);
CNCrypto._free(point3_m);
CNCrypto._free(point4_m);
CNCrypto._free(point5_m);
CNCrypto._free(derived_key_m);
return bintohex(res);
};*/
this.derive_public_key = function(derivation, out_index, pub) {
if (derivation.length !== 64 || pub.length !== 64) {
throw "Invalid input length!";
@ -1014,40 +857,6 @@ var cnUtil = function(currencyConfig) {
);
};
//adds two points together, order does not matter
/*this.ge_add2 = function(point1, point2) {
var point1_m = CNCrypto._malloc(KEY_SIZE);
var point2_m = CNCrypto._malloc(KEY_SIZE);
var point1_m2 = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var point2_m2 = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
CNCrypto.HEAPU8.set(hextobin(point1), point1_m);
CNCrypto.HEAPU8.set(hextobin(point2), point2_m);
if (CNCrypto.ccall("ge_frombytes_vartime", "bool", ["number", "number"], [point1_m2, point1_m]) !== 0) {
throw "ge_frombytes_vartime returned non-zero error code";
}
if (CNCrypto.ccall("ge_frombytes_vartime", "bool", ["number", "number"], [point2_m2, point2_m]) !== 0) {
throw "ge_frombytes_vartime returned non-zero error code";
}
var sum_m = CNCrypto._malloc(KEY_SIZE);
var p2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
var p1_m = CNCrypto._malloc(STRUCT_SIZES.GE_P1P1);
var p3_m = CNCrypto._malloc(STRUCT_SIZES.GE_CACHED);
CNCrypto.ccall("ge_p3_to_cached", "void", ["number", "number"], [p3_m, point2_m2]);
CNCrypto.ccall("ge_add", "void", ["number", "number", "number"], [p1_m, point1_m2, p3_m]);
CNCrypto.ccall("ge_p1p1_to_p2", "void", ["number", "number"], [p2_m, p1_m]);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [sum_m, p2_m]);
var res = CNCrypto.HEAPU8.subarray(sum_m, sum_m + KEY_SIZE);
CNCrypto._free(point1_m);
CNCrypto._free(point1_m2);
CNCrypto._free(point2_m);
CNCrypto._free(point2_m2);
CNCrypto._free(p2_m);
CNCrypto._free(p1_m);
CNCrypto._free(sum_m);
CNCrypto._free(p3_m);
return bintohex(res);
};*/
this.ge_add = function(p1, p2) {
if (p1.length !== 64 || p2.length !== 64) {
throw "Invalid input length!";
@ -1160,35 +969,6 @@ var cnUtil = function(currencyConfig) {
return bintohex(res);
};
//res = aB + cG; argument names copied from the signature implementation
/*this.ge_double_scalarmult_base_vartime = function(sigc, pub, sigr) {
var pub_m = CNCrypto._malloc(KEY_SIZE);
var pub2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
CNCrypto.HEAPU8.set(hextobin(pub), pub_m);
if (CNCrypto.ccall("ge_frombytes_vartime", "void", ["number", "number"], [pub2_m, pub_m]) !== 0) {
throw "Failed to call ge_frombytes_vartime";
}
var sigc_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(hextobin(sigc), sigc_m);
var sigr_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.HEAPU8.set(hextobin(sigr), sigr_m);
if (CNCrypto.ccall("sc_check", "number", ["number"], [sigc_m]) !== 0 || CNCrypto.ccall("sc_check", "number", ["number"], [sigr_m]) !== 0) {
throw "bad scalar(s)";
}
var tmp_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
var res_m = CNCrypto._malloc(KEY_SIZE);
CNCrypto.ccall("ge_double_scalarmult_base_vartime", "void", ["number", "number", "number", "number"], [tmp_m, sigc_m, pub2_m, sigr_m]);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [res_m, tmp_m]);
var res = CNCrypto. HEAPU8.subarray(res_m, res_m + KEY_SIZE);
CNCrypto._free(pub_m);
CNCrypto._free(pub2_m);
CNCrypto._free(sigc_m);
CNCrypto._free(sigr_m);
CNCrypto._free(tmp_m);
CNCrypto._free(res_m);
return bintohex(res);
};*/
this.ge_double_scalarmult_base_vartime = function(c, P, r) {
if (c.length !== 64 || P.length !== 64 || r.length !== 64) {
throw "Invalid input length!";
@ -1202,40 +982,6 @@ var cnUtil = function(currencyConfig) {
);
};
//res = a * Hp(B) + c*D
//res = sigr * Hp(pub) + sigc * k_image; argument names also copied from the signature implementation; note precomp AND hash_to_ec are done internally!!
/*this.ge_double_scalarmult_postcomp_vartime = function(sigr, pub, sigc, k_image) {
var image_m = CNCrypto._malloc(STRUCT_SIZES.KEY_IMAGE);
CNCrypto.HEAPU8.set(hextobin(k_image), image_m);
var image_unp_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var image_pre_m = CNCrypto._malloc(STRUCT_SIZES.GE_DSMP);
var tmp3_m = CNCrypto._malloc(STRUCT_SIZES.GE_P3);
var sigr_m = CNCrypto._malloc(STRUCT_SIZES.EC_SCALAR);
var sigc_m = CNCrypto._malloc(STRUCT_SIZES.EC_SCALAR);
var tmp2_m = CNCrypto._malloc(STRUCT_SIZES.GE_P2);
var res_m = CNCrypto._malloc(STRUCT_SIZES.EC_POINT);
if (CNCrypto.ccall("ge_frombytes_vartime", "void", ["number", "number"], [image_unp_m, image_m]) !== 0) {
throw "Failed to call ge_frombytes_vartime";
}
CNCrypto.ccall("ge_dsm_precomp", "void", ["number", "number"], [image_pre_m, image_unp_m]);
var ec = this.hash_to_ec(pub);
CNCrypto.HEAPU8.set(hextobin(ec), tmp3_m);
CNCrypto.HEAPU8.set(hextobin(sigc), sigc_m);
CNCrypto.HEAPU8.set(hextobin(sigr), sigr_m);
CNCrypto.ccall("ge_double_scalarmult_precomp_vartime", "void", ["number", "number", "number", "number", "number"], [tmp2_m, sigr_m, tmp3_m, sigc_m, image_pre_m]);
CNCrypto.ccall("ge_tobytes", "void", ["number", "number"], [res_m, tmp2_m]);
var res = CNCrypto. HEAPU8.subarray(res_m, res_m + STRUCT_SIZES.EC_POINT);
CNCrypto._free(image_m);
CNCrypto._free(image_unp_m);
CNCrypto._free(image_pre_m);
CNCrypto._free(tmp3_m);
CNCrypto._free(sigr_m);
CNCrypto._free(sigc_m);
CNCrypto._free(tmp2_m);
CNCrypto._free(res_m);
return bintohex(res);
};*/
this.ge_double_scalarmult_postcomp_vartime = function(r, P, c, I) {
if (
c.length !== 64 ||
@ -1376,13 +1122,7 @@ var cnUtil = function(currencyConfig) {
// thus this proves that "amount" is in [0, s^n] (we assume s to be 4) (2 for now with v2 txes)
// mask is a such that C = aG + bH, and b = amount
//commitMaskObj = {C: commit, mask: mask}
this.proveRange = function(
commitMaskObj,
amount,
nrings,
enc_seed,
exponent,
) {
this.proveRange = function(commitMaskObj, amount, nrings) {
var size = 2;
var C = I; //identity
var mask = Z; //zero scalar
@ -1391,13 +1131,7 @@ var cnUtil = function(currencyConfig) {
Ci: [],
//exp: exponent //doesn't exist for now
};
/*payload stuff - ignore for now
seeds = new Array(3);
for (var i = 0; i < seeds.length; i++){
seeds[i] = new Array(1);
}
genSeeds(seeds, enc_seed);
*/
var ai = [];
var PM = [];
for (var i = 0; i < size; i++) {
@ -1429,13 +1163,7 @@ var cnUtil = function(currencyConfig) {
sig.Ci[i] = PM[0][i];
C = ge_add(C, PM[0][i]);
}
/* exponent stuff - ignore for now
if (exponent){
n = JSBigInt(10);
n = n.pow(exponent).toString();
mask = sc_mul(mask, d2s(n)); //new sum
}
*/
sig.bsig = this.genBorromean(ai, PM, indices, size, nrings);
commitMaskObj.C = C;
commitMaskObj.mask = mask;
@ -1770,7 +1498,7 @@ var cnUtil = function(currencyConfig) {
message,
inSk,
kimg,
/*destinations, */ inAmounts,
inAmounts,
outAmounts,
mixRing,
amountKeys,
@ -3059,20 +2787,9 @@ var cnUtil = function(currencyConfig) {
};
this.decompose_amount_into_digits = function(amount) {
/*if (dust_threshold === undefined) {
dust_threshold = config.dustThreshold;
}*/
amount = amount.toString();
var ret = [];
while (amount.length > 0) {
//split all the way down since v2 fork
/*var remaining = new JSBigInt(amount);
if (remaining.compare(config.dustThreshold) <= 0) {
if (remaining.compare(0) > 0) {
ret.push(remaining);
}
break;
}*/
//check so we don't create 0s
if (amount[0] !== "0") {
var digit = amount[0];
@ -3164,12 +2881,6 @@ var cnUtil = function(currencyConfig) {
}
};
function assert(stmt, val) {
if (!stmt) {
throw "assert failed" + (val !== undefined ? ": " + val : "");
}
}
return this;
};
exports.cnUtil = cnUtil;

@ -44,6 +44,11 @@ declare namespace nacl {
*
* @description name changed to reflect not using precomp r*Pb + c*I
*
* sigr * Hp(pub) + sigc * k_image
*
* argument names also copied from the signature implementation
*
* note precomp AND hash_to_ec are done internally!!
* @param {Uint8Array} r
* @param {Uint8Array} Pb
* @param {Uint8Array} c

@ -28,9 +28,6 @@
//
"use strict";
//
const response_parser_utils = require("./response_parser_utils");
const JSBigInt = require("../cryptonote_utils/biginteger").BigInteger; // important: grab defined export
//
function New_ParametersForWalletRequest(address, view_key__private) {
return {
address: address,

Loading…
Cancel
Save