-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathbase_wallet.ts
208 lines (197 loc) · 6.7 KB
/
base_wallet.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import {
type AuthWitness,
type EventMetadataDefinition,
type ExtendedNote,
type GetUnencryptedLogsResponse,
type IncomingNotesFilter,
type L2Block,
type LogFilter,
type PXE,
type PXEInfo,
type PrivateExecutionResult,
type SiblingPath,
type Tx,
type TxExecutionRequest,
type TxHash,
type TxProvingResult,
type TxReceipt,
type TxSimulationResult,
type UniqueNote,
} from '@aztec/circuit-types';
import {
type AztecAddress,
type CompleteAddress,
type ContractClassWithId,
type ContractInstanceWithAddress,
type Fr,
type GasFees,
type L1_TO_L2_MSG_TREE_HEIGHT,
type NodeInfo,
type PartialAddress,
type Point,
} from '@aztec/circuits.js';
import type { AbiDecoded, ContractArtifact } from '@aztec/foundation/abi';
import { type Wallet } from '../account/wallet.js';
import { type ExecutionRequestInit } from '../entrypoint/entrypoint.js';
import { type IntentAction, type IntentInnerHash } from '../utils/authwit.js';
/**
* A base class for Wallet implementations
*/
export abstract class BaseWallet implements Wallet {
constructor(protected readonly pxe: PXE, private scopes?: AztecAddress[]) {}
abstract isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;
abstract getCompleteAddress(): CompleteAddress;
abstract getChainId(): Fr;
abstract getVersion(): Fr;
abstract createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
abstract createAuthWit(intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise<AuthWitness>;
setScopes(scopes: AztecAddress[]) {
this.scopes = scopes;
}
getScopes() {
return this.scopes;
}
getAddress() {
return this.getCompleteAddress().address;
}
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
return this.pxe.getContractInstance(address);
}
getContractClass(id: Fr): Promise<ContractClassWithId | undefined> {
return this.pxe.getContractClass(id);
}
getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
return this.pxe.getContractArtifact(id);
}
addCapsule(capsule: Fr[]): Promise<void> {
return this.pxe.addCapsule(capsule);
}
registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
return this.pxe.registerAccount(secretKey, partialAddress);
}
getRegisteredAccounts(): Promise<CompleteAddress[]> {
return this.pxe.getRegisteredAccounts();
}
getRegisteredAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
return this.pxe.getRegisteredAccount(address);
}
registerContact(address: AztecAddress): Promise<AztecAddress> {
return this.pxe.registerContact(address);
}
getContacts(): Promise<AztecAddress[]> {
return this.pxe.getContacts();
}
async removeContact(address: AztecAddress): Promise<void> {
await this.pxe.removeContact(address);
}
registerContract(contract: {
/** Instance */ instance: ContractInstanceWithAddress;
/** Associated artifact */ artifact?: ContractArtifact;
}): Promise<void> {
return this.pxe.registerContract(contract);
}
registerContractClass(artifact: ContractArtifact): Promise<void> {
return this.pxe.registerContractClass(artifact);
}
getContracts(): Promise<AztecAddress[]> {
return this.pxe.getContracts();
}
proveTx(txRequest: TxExecutionRequest, privateExecutionResult: PrivateExecutionResult): Promise<TxProvingResult> {
return this.pxe.proveTx(txRequest, privateExecutionResult);
}
simulateTx(
txRequest: TxExecutionRequest,
simulatePublic: boolean,
msgSender?: AztecAddress,
skipTxValidation?: boolean,
profile?: boolean,
): Promise<TxSimulationResult> {
return this.pxe.simulateTx(txRequest, simulatePublic, msgSender, skipTxValidation, profile, this.scopes);
}
sendTx(tx: Tx): Promise<TxHash> {
return this.pxe.sendTx(tx);
}
getTxEffect(txHash: TxHash) {
return this.pxe.getTxEffect(txHash);
}
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
return this.pxe.getTxReceipt(txHash);
}
getIncomingNotes(filter: IncomingNotesFilter): Promise<UniqueNote[]> {
return this.pxe.getIncomingNotes(filter);
}
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
return this.pxe.getPublicStorageAt(contract, storageSlot);
}
addNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNote(note, this.getAddress());
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNullifiedNote(note);
}
getBlock(number: number): Promise<L2Block | undefined> {
return this.pxe.getBlock(number);
}
getCurrentBaseFees(): Promise<GasFees> {
return this.pxe.getCurrentBaseFees();
}
simulateUnconstrained(
functionName: string,
args: any[],
to: AztecAddress,
from?: AztecAddress | undefined,
): Promise<AbiDecoded> {
return this.pxe.simulateUnconstrained(functionName, args, to, from);
}
getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
return this.pxe.getUnencryptedLogs(filter);
}
getContractClassLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
return this.pxe.getContractClassLogs(filter);
}
getBlockNumber(): Promise<number> {
return this.pxe.getBlockNumber();
}
getProvenBlockNumber(): Promise<number> {
return this.pxe.getProvenBlockNumber();
}
getNodeInfo(): Promise<NodeInfo> {
return this.pxe.getNodeInfo();
}
addAuthWitness(authWitness: AuthWitness) {
return this.pxe.addAuthWitness(authWitness);
}
getAuthWitness(messageHash: Fr) {
return this.pxe.getAuthWitness(messageHash);
}
isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
return this.pxe.isContractClassPubliclyRegistered(id);
}
isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
return this.pxe.isContractPubliclyDeployed(address);
}
isContractInitialized(address: AztecAddress): Promise<boolean> {
return this.pxe.isContractInitialized(address);
}
getPXEInfo(): Promise<PXEInfo> {
return this.pxe.getPXEInfo();
}
getEncryptedEvents<T>(
event: EventMetadataDefinition,
from: number,
limit: number,
vpks: Point[] = [this.getCompleteAddress().publicKeys.masterIncomingViewingPublicKey],
): Promise<T[]> {
return this.pxe.getEncryptedEvents(event, from, limit, vpks);
}
getUnencryptedEvents<T>(event: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
return this.pxe.getUnencryptedEvents(event, from, limit);
}
public getL1ToL2MembershipWitness(
contractAddress: AztecAddress,
messageHash: Fr,
secret: Fr,
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
return this.pxe.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
}
}