Skip to content

Commit

Permalink
nit: fixup variable names to match BIP352
Browse files Browse the repository at this point in the history
  • Loading branch information
josibake authored and Overtorment committed May 1, 2024
1 parent 3f32f97 commit 4aa7ce8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,29 @@ export class SilentPayment {
const A = Buffer.from(ecc.pointFromScalar(a) as Uint8Array);
const outpoint_hash = SilentPayment._outpointsHash(utxos, A);

// Generating Pmn for each Bm in the group
// Generating Pmk for each Bm in the group
for (const group of silentPaymentGroups) {
// Bscan * a * outpoint_hash
const ecdh_shared_secret_step1 = Buffer.from(ecc.privateMultiply(outpoint_hash, a) as Uint8Array);
const ecdh_shared_secret = ecc.pointMultiply(group.Bscan, ecdh_shared_secret_step1);

let n = 0;
let k = 0;
for (const [Bm, amount] of group.BmValues) {
const tn = taggedHash(
const tk = taggedHash(
"BIP0352/SharedSecret",
Buffer.concat([ecdh_shared_secret!, SilentPayment._ser32(n)])
Buffer.concat([ecdh_shared_secret!, SilentPayment._ser32(k)])
);

// Let Pmn = tn·G + Bm
const Pmn = Buffer.from(ecc.pointAdd(ecc.pointMultiply(G, tn) as Uint8Array, Bm) as Uint8Array);
// Let Pmk = tk·G + Bm
const Pmk = Buffer.from(ecc.pointAdd(ecc.pointMultiply(G, tk) as Uint8Array, Bm) as Uint8Array);

// Encode Pmn as a BIP341 taproot output
const address = Pmn.slice(1).toString("hex");
// Encode Pmk as a BIP341 taproot output
const address = Pmk.slice(1).toString("hex");
const newTarget: Target = { address };
newTarget.value = amount;
ret.push(newTarget);
n += 1;
k += 1;
}
n += 1;
}
return ret;
}
Expand Down

0 comments on commit 4aa7ce8

Please sign in to comment.