Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions treasury/src/kv/vault.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class PrivateKeyService {
this.initLogin();
}

public async getAsync(address: string, pkKey: string = 'private_key'): Promise<string> {
public async getAsync(address: string, pkKey: string = this.pkKey): Promise<string> {
try {
await this.getTokenAsync();
const { data } = await this.vault.read(`${this.privateKeyConfig.mountPath}/data/${address}`);
Expand All @@ -29,9 +29,11 @@ export class PrivateKeyService {
}
}

public async setAsync(address: string, privateKey: string, pkKey: string = 'private_key'): Promise<void> {
public async setAsync(address: string, privateKey: string, pkKey: string = this.pkKey): Promise<void> {
try {

await this.getTokenAsync();

await this.vault.write(`${this.privateKeyConfig.mountPath}/data/${address}`, {
data: { [pkKey]: privateKey }
});
Expand All @@ -41,6 +43,20 @@ export class PrivateKeyService {
}
}

public async setDictAsync(address: string, keyVaulePair: Record<string, string>): Promise<void> {
try {

await this.getTokenAsync();

await this.vault.write(`${this.privateKeyConfig.mountPath}/data/${address}`, {
data: { keyVaulePair }
});
}
catch (error) {
this.handleVaultError(error);
}
}

private initLogin(): void {
this.getTokenAsync =
this.privateKeyConfig.isK8sAuthEnabled
Expand Down
12 changes: 7 additions & 5 deletions treasury/src/treasury/aztec/aztec.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,17 @@ export class AztecTreasuryService extends TreasuryService {
}

async generate(): Promise<GenerateResponse> {

const prKey = Fr.random();
const salt = Fr.random();
const addressResponse = await getSchnorrAccountContractAddress(prKey, salt);
const address = (await getSchnorrAccountContractAddress(prKey, salt)).toString();

await this.privateKeyService.setAsync(addressResponse.toString(), prKey.toString());
await this.privateKeyService.setAsync(addressResponse.toString(), salt.toString(), "private_salt");
const dict: Record<string, string> = {
"private_key": prKey.toString(),
"private_salt": salt.toString(),
};

const address = addressResponse.toString()
await this.privateKeyService.setDictAsync(address.toString(), dict);

await createStore(address, {
dataDirectory: this.configService.storePath,
Expand Down