Namechange ecdh

pull/40/head
HenryNguyen5 6 years ago
parent 57b1dff928
commit 44836567b6

@ -1,10 +1,7 @@
import { BigInt } from "biginteger";
import { skGen } from "xmr-key-utils";
import { d2s } from "xmr-str-utils/integer-strings";
import {
encode_rct_ecdh,
decode_rct_ecdh,
} from "xmr-transaction/libs/ringct/components/ecdh";
import { encode_ecdh, decode_ecdh } from "xmr-crypto-ops/rct";
// Copyright (c) 2014-2018, MyMonero.com
//
@ -62,9 +59,9 @@ it("ecdh_roundtrip", () => {
// both are strings so we can shallow copy
let t1 = { ...t0 };
t1 = encode_rct_ecdh(t1, k);
t1 = encode_ecdh(t1, k);
t1 = decode_rct_ecdh(t1, k);
t1 = decode_ecdh(t1, k);
expect(t1.mask).toEqual(t0.mask);
expect(t1.amount).toEqual(t0.amount);
}

@ -0,0 +1,46 @@
import {
ge_double_scalarmult_base_vartime,
sc_sub,
sc_add,
} from "./primitive_ops";
import { H, I } from "./constants";
import { valid_hex } from "xmr-str-utils/hex-strings";
import { hash_to_scalar } from "./hash_ops";
import { Commit } from "xmr-types";
//creates a Pedersen commitment from an amount (in scalar form) and a mask
//C = bG + aH where b = mask, a = amount
export function commit(amount: string, mask: string) {
if (
!valid_hex(mask) ||
mask.length !== 64 ||
!valid_hex(amount) ||
amount.length !== 64
) {
throw Error("invalid amount or mask!");
}
const C = ge_double_scalarmult_base_vartime(amount, H, mask);
return C;
}
export function zeroCommit(amount: string) {
return commit(amount, I);
}
export function decode_ecdh(ecdh: Commit, key: string): Commit {
const first = hash_to_scalar(key);
const second = hash_to_scalar(first);
return {
mask: sc_sub(ecdh.mask, first),
amount: sc_sub(ecdh.amount, second),
};
}
export function encode_ecdh(ecdh: Commit, key: string): Commit {
const first = hash_to_scalar(key);
const second = hash_to_scalar(first);
return {
mask: sc_add(ecdh.mask, first),
amount: sc_add(ecdh.amount, second),
};
}

@ -1,26 +0,0 @@
import { ge_double_scalarmult_base_vartime } from "./primitive_ops";
import { H, I } from "./constants";
import { valid_hex } from "xmr-str-utils/hex-strings";
//creates a Pedersen commitment from an amount (in scalar form) and a mask
//C = bG + aH where b = mask, a = amount
export function commit(amount: string, mask: string) {
if (
!valid_hex(mask) ||
mask.length !== 64 ||
!valid_hex(amount) ||
amount.length !== 64
) {
throw Error("invalid amount or mask!");
}
const C = ge_double_scalarmult_base_vartime(amount, H, mask);
return C;
}
export function zeroCommit(amount: string) {
if (!valid_hex(amount) || amount.length !== 64) {
throw Error("invalid amount!");
}
const C = ge_double_scalarmult_base_vartime(amount, H, I);
return C;
}

@ -1,21 +0,0 @@
import { Commit } from "./types";
import { hash_to_scalar } from "xmr-crypto-ops/hash_ops";
import { sc_add, sc_sub } from "xmr-crypto-ops/primitive_ops";
export function decode_rct_ecdh(ecdh: Commit, key: string): Commit {
const first = hash_to_scalar(key);
const second = hash_to_scalar(first);
return {
mask: sc_sub(ecdh.mask, first),
amount: sc_sub(ecdh.amount, second),
};
}
export function encode_rct_ecdh(ecdh: Commit, key: string): Commit {
const first = hash_to_scalar(key);
const second = hash_to_scalar(first);
return {
mask: sc_add(ecdh.mask, first),
amount: sc_add(ecdh.amount, second),
};
}

@ -1,2 +0,0 @@
export * from "./ecdh";
export * from "./types";

@ -1,4 +0,0 @@
export interface Commit {
mask: string;
amount: string;
}

@ -1,4 +1,4 @@
import { encode_rct_ecdh, decode_rct_ecdh } from "./components/ecdh";
import { encode_ecdh, decode_ecdh } from "xmr-crypto-ops/rct";
import { proveRange, verRange } from "./components/prove_range";
import {
proveRctMG,
@ -18,7 +18,7 @@ import {
} from "xmr-crypto-ops/primitive_ops";
import { d2s } from "xmr-str-utils/integer-strings";
import { random_scalar } from "xmr-rand";
import { commit } from "xmr-crypto-ops/rctOps";
import { commit } from "xmr-crypto-ops/rct";
import { get_pre_mlsag_hash } from "./utils";
import { verBulletProof } from "./components/bullet_proofs";
@ -92,8 +92,9 @@ export function genRct(
const testfinish = new Date().getTime() - teststart;
console.log("Time take for range proof " + i + ": " + testfinish);
rv.outPk[i] = cmObj.C;
// the mask is the sum
sumout = sc_add(sumout, cmObj.mask);
rv.ecdhInfo[i] = encode_rct_ecdh(
rv.ecdhInfo[i] = encode_ecdh(
{ mask: cmObj.mask, amount: d2s(outAmounts[i]) },
amountKeys[i],
);
@ -105,14 +106,16 @@ export function genRct(
throw Error("mismatched inAmounts/inSk");
}
const ai = [];
const ai = []; // blinding factor
let sumpouts = Z;
//create pseudoOuts
for (i = 0; i < inAmounts.length - 1; i++) {
// set each blinding factor to be random except for the last
ai[i] = random_scalar();
sumpouts = sc_add(sumpouts, ai[i]);
rv.pseudoOuts[i] = commit(d2s(inAmounts[i]), ai[i]);
}
ai[i] = sc_sub(sumout, sumpouts);
rv.pseudoOuts[i] = commit(d2s(inAmounts[i]), ai[i]);
const full_message = get_pre_mlsag_hash(rv);
@ -371,7 +374,7 @@ export function decodeRct(rv: RCTSignatures, sk: string, i: number) {
// mask amount and mask
const ecdh_info = rv.ecdhInfo[i];
const { mask, amount } = decode_rct_ecdh(ecdh_info, sk);
const { mask, amount } = decode_ecdh(ecdh_info, sk);
const C = rv.outPk[i];
const Ctmp = ge_double_scalarmult_base_vartime(amount, H, mask);
@ -398,7 +401,7 @@ export function decodeRctSimple(rv: RCTSignatures, sk: string, i: number) {
// mask amount and mask
const ecdh_info = rv.ecdhInfo[i];
const { mask, amount } = decode_rct_ecdh(ecdh_info, sk);
const { mask, amount } = decode_ecdh(ecdh_info, sk);
const C = rv.outPk[i];
const Ctmp = ge_double_scalarmult_base_vartime(amount, H, mask);

Loading…
Cancel
Save