-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathdeploy_account.ts
More file actions
51 lines (42 loc) Β· 2.48 KB
/
deploy_account.ts
File metadata and controls
51 lines (42 loc) Β· 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee";
import { getSponsoredFPCInstance } from "./sponsored_fpc.js";
import { SponsoredFPCContractArtifact } from "@aztec/noir-contracts.js/SponsoredFPC";
import { Fr } from "@aztec/aztec.js/fields";
import { GrumpkinScalar } from "@aztec/foundation/curves/grumpkin";
import { type Logger, createLogger } from "@aztec/foundation/log";
import { setupWallet } from "./setup_wallet.js";
import { AztecAddress } from "@aztec/aztec.js/addresses";
import { AccountManager } from "@aztec/aztec.js/wallet";
import { EmbeddedWallet } from "@aztec/wallets/embedded";
import { getTimeouts } from "../../config/config.js";
export async function deploySchnorrAccount(wallet?: EmbeddedWallet): Promise<AccountManager> {
let logger: Logger;
logger = createLogger('aztec:aztec-starter');
logger.info('π€ Starting Schnorr account deployment...');
// Generate account keys
logger.info('π Generating account keys...');
let secretKey = Fr.random();
let signingKey = GrumpkinScalar.random();
let salt = Fr.random();
logger.info(`Save the following SECRET and SALT in .env for future use.`);
logger.info(`π Secret key generated: ${secretKey.toString()}`);
logger.info(`ποΈ Signing key generated: ${signingKey.toString()}`);
logger.info(`π§ Salt generated: ${salt.toString()}`);
const activeWallet = wallet ?? await setupWallet()
const account = await activeWallet.createSchnorrAccount(secretKey, salt, signingKey)
logger.info(`π Account address will be: ${account.address}`);
const deployMethod = await account.getDeployMethod();
// Setup sponsored FPC
logger.info('π° Setting up sponsored fee payment for account deployment...');
const sponsoredFPC = await getSponsoredFPCInstance();
logger.info(`π° Sponsored FPC instance obtained at: ${sponsoredFPC.address}`);
logger.info('π Registering sponsored FPC contract with PXE...');
await activeWallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact);
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
logger.info('β
Sponsored fee payment method configured for account deployment');
// Deploy account
const timeouts = getTimeouts();
await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod: sponsoredPaymentMethod }, wait: { timeout: timeouts.deployTimeout } });
logger.info(`β
Account deployment transaction successful!`);
return account;
}