Repository navigation
Expand file tree
/
Copy pathdeploy_account.ts
More file actions
59 lines (49 loc) · 2.58 KB
/
Copy pathdeploy_account.ts
File metadata and controls
59 lines (49 loc) · 2.58 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
52
53
54
55
56
57
58
59
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 { AccountManager } from "@aztec/aztec.js/wallet";
import { NO_FROM } from "@aztec/aztec.js/account";
import { EmbeddedWallet } from "@aztec/wallets/embedded";
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');
// Simulate before sending to surface revert reasons
await deployMethod.simulate({
from: NO_FROM,
});
logger.info('✅ Simulation successful, sending deployment transaction...');
// Deploy account
await deployMethod.send({
from: NO_FROM,
fee: { paymentMethod: sponsoredPaymentMethod },
wait: { timeout: 120 },
});
logger.info(`✅ Account deployment transaction successful!`);
return account;
}