chore: rename master keys

This commit is contained in:
moebius
2025-03-06 21:05:40 +01:00
parent 2f3307c4d5
commit 228df6775b
3 changed files with 19 additions and 14 deletions

View File

@@ -46,19 +46,19 @@ export class AccountService {
try {
this.logger.debug("Initializing account with mnemonic");
let key1 = bytesToNumber(
let masterNullifierSeed = bytesToNumber(
mnemonicToAccount(mnemonic, { accountIndex: 0 }).getHdKey().privateKey!,
);
let key2 = bytesToNumber(
let masterSecretSeed = bytesToNumber(
mnemonicToAccount(mnemonic, { accountIndex: 1 }).getHdKey().privateKey!,
);
let masterKey1 = poseidon([BigInt(key1)]) as Secret;
let masterKey2 = poseidon([BigInt(key2)]) as Secret;
let masterNullifier = poseidon([BigInt(masterNullifierSeed)]) as Secret;
let masterSecret = poseidon([BigInt(masterSecretSeed)]) as Secret;
return {
masterKeys: [masterKey1, masterKey2],
masterKeys: [masterNullifier, masterSecret],
poolAccounts: new Map(),
creationTimestamp: 0n,
lastUpdateTimestamp: 0n
@@ -71,19 +71,23 @@ export class AccountService {
}
private _genDepositNullifier(scope: Hash, index: bigint): Secret {
return poseidon([this.account.masterKeys[0], scope, index]) as Secret;
const [masterNullifier] = this.account.masterKeys;
return poseidon([masterNullifier, scope, index]) as Secret;
}
private _genDepositSecret(scope: Hash, index: bigint): Secret {
return poseidon([this.account.masterKeys[1], scope, index]) as Secret;
const [, masterSecret] = this.account.masterKeys;
return poseidon([masterSecret, scope, index]) as Secret;
}
private _genWithdrawalNullifier(label: Hash, index: bigint): Secret {
return poseidon([this.account.masterKeys[0], label, index]) as Secret;
const [masterNullifier] = this.account.masterKeys;
return poseidon([masterNullifier, label, index]) as Secret;
}
private _genWithdrawalSecret(label: Hash, index: bigint): Secret {
return poseidon([this.account.masterKeys[1], label, index]) as Secret;
const [, masterSecret] = this.account.masterKeys;
return poseidon([masterSecret, label, index]) as Secret;
}
private _hashCommitment(

View File

@@ -19,7 +19,7 @@ export interface AccountCommitment {
}
export interface PrivacyPoolAccount {
masterKeys: [Secret, Secret];
masterKeys: [masterNullifier: Secret, masterSecret: Secret];
poolAccounts: Map<Hash, PoolAccount[]>;
creationTimestamp: bigint;
lastUpdateTimestamp: bigint;

View File

@@ -66,13 +66,14 @@ describe("AccountService", () => {
for (let i = 0; i < NUM_DEPOSITS; ++i) {
const value = 100n;
const label = randomBigInt() as Hash;
const [masterNullifier, masterSecret] = masterKeys;
const nullifier = poseidon([
masterKeys[0],
masterNullifier,
POOL.scope,
BigInt(i),
]) as Secret;
const secret = poseidon([masterKeys[1], POOL.scope, BigInt(i)]) as Secret;
const secret = poseidon([masterSecret, POOL.scope, BigInt(i)]) as Secret;
const precommitment = poseidon([nullifier, secret]) as Hash;
const commitment = poseidon([value, label, precommitment]) as Hash;
@@ -110,12 +111,12 @@ describe("AccountService", () => {
// Generate withdrawal nullifier and secret using master keys
const withdrawalNullifier = poseidon([
masterKeys[0],
masterNullifier,
currentCommitment.label,
BigInt(j),
]) as Secret;
const withdrawalSecret = poseidon([
masterKeys[1],
masterSecret,
currentCommitment.label,
BigInt(j),
]) as Secret;