@aztec/aztec.js 0.72.1 → 0.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account_manager/deploy_account_method.js +6 -6
- package/dest/account_manager/index.d.ts +1 -1
- package/dest/account_manager/index.js +2 -2
- package/dest/api/ethereum.d.ts +2 -1
- package/dest/api/ethereum.d.ts.map +1 -1
- package/dest/api/ethereum.js +3 -2
- package/dest/barretenberg-threads.wasm.gz +0 -0
- package/dest/barretenberg.wasm.gz +0 -0
- package/dest/contract/contract.js +2 -2
- package/dest/contract/contract_base.d.ts +2 -2
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +2 -2
- package/dest/contract/contract_function_interaction.d.ts +1 -1
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +4 -4
- package/dest/contract/deploy_method.d.ts +1 -1
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +7 -6
- package/dest/deployment/broadcast_function.d.ts +1 -1
- package/dest/deployment/broadcast_function.d.ts.map +1 -1
- package/dest/deployment/broadcast_function.js +21 -12
- package/dest/deployment/register_class.js +2 -2
- package/dest/entrypoint/default_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_entrypoint.js +3 -3
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +5 -5
- package/dest/entrypoint/payload.d.ts +20 -7
- package/dest/entrypoint/payload.d.ts.map +1 -1
- package/dest/entrypoint/payload.js +35 -28
- package/dest/fee/fee_juice_payment_method_with_claim.js +2 -2
- package/dest/fee/private_fee_payment_method.js +5 -5
- package/dest/fee/public_fee_payment_method.js +17 -18
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -4
- package/dest/main.js +2 -0
- package/dest/main.js.LICENSE.txt +25 -0
- package/dest/utils/anvil_test_watcher.d.ts +5 -1
- package/dest/utils/anvil_test_watcher.d.ts.map +1 -1
- package/dest/utils/anvil_test_watcher.js +47 -7
- package/dest/utils/authwit.d.ts +3 -3
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +9 -5
- package/dest/utils/chain_monitor.d.ts +2 -1
- package/dest/utils/chain_monitor.d.ts.map +1 -1
- package/dest/utils/chain_monitor.js +7 -2
- package/dest/utils/cheat_codes.d.ts +3 -2
- package/dest/utils/cheat_codes.d.ts.map +1 -1
- package/dest/utils/cheat_codes.js +5 -5
- package/dest/utils/l1_contracts.d.ts +1 -1
- package/dest/utils/l1_contracts.d.ts.map +1 -1
- package/dest/utils/portal_manager.d.ts +1 -1
- package/dest/utils/portal_manager.d.ts.map +1 -1
- package/dest/utils/portal_manager.js +5 -5
- package/dest/wallet/account_wallet.d.ts +1 -1
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +9 -9
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +1 -1
- package/dest/wallet/account_wallet_with_private_key.js +3 -3
- package/dest/wallet/base_wallet.d.ts +4 -8
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +7 -19
- package/package.json +9 -8
- package/src/account_manager/deploy_account_method.ts +5 -5
- package/src/account_manager/index.ts +1 -1
- package/src/api/ethereum.ts +2 -1
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +2 -2
- package/src/contract/contract_function_interaction.ts +3 -3
- package/src/contract/deploy_method.ts +6 -5
- package/src/deployment/broadcast_function.ts +26 -12
- package/src/deployment/register_class.ts +1 -1
- package/src/entrypoint/default_entrypoint.ts +2 -2
- package/src/entrypoint/default_multi_call_entrypoint.ts +4 -4
- package/src/entrypoint/payload.ts +51 -25
- package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
- package/src/fee/private_fee_payment_method.ts +4 -4
- package/src/fee/public_fee_payment_method.ts +20 -20
- package/src/index.ts +2 -4
- package/src/utils/anvil_test_watcher.ts +54 -6
- package/src/utils/authwit.ts +9 -5
- package/src/utils/chain_monitor.ts +8 -2
- package/src/utils/cheat_codes.ts +6 -5
- package/src/utils/l1_contracts.ts +1 -1
- package/src/utils/portal_manager.ts +4 -4
- package/src/wallet/account_wallet.ts +12 -11
- package/src/wallet/account_wallet_with_private_key.ts +2 -2
- package/src/wallet/base_wallet.ts +8 -19
- package/dest/api/init.d.ts +0 -7
- package/dest/api/init.d.ts.map +0 -1
- package/dest/api/init.js +0 -10
- package/src/api/init.ts +0 -10
|
@@ -56,19 +56,22 @@ type EncodedFunctionCall = {
|
|
|
56
56
|
|
|
57
57
|
/** Assembles an entrypoint payload */
|
|
58
58
|
export abstract class EntrypointPayload {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
protected constructor(
|
|
60
|
+
private functionCalls: EncodedFunctionCall[],
|
|
61
|
+
private _hashedArguments: HashedValues[],
|
|
62
|
+
private generatorIndex: number,
|
|
63
|
+
private _nonce: Fr,
|
|
64
|
+
) {}
|
|
65
|
+
|
|
66
|
+
protected static async create(functionCalls: FunctionCall[]) {
|
|
67
|
+
const hashedArguments: HashedValues[] = [];
|
|
65
68
|
for (const call of functionCalls) {
|
|
66
|
-
|
|
69
|
+
hashedArguments.push(await HashedValues.fromValues(call.args));
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
/* eslint-disable camelcase */
|
|
70
|
-
|
|
71
|
-
args_hash:
|
|
73
|
+
const encodedFunctionCalls = functionCalls.map((call, index) => ({
|
|
74
|
+
args_hash: hashedArguments[index].hash,
|
|
72
75
|
function_selector: call.selector.toField(),
|
|
73
76
|
target_address: call.to.toField(),
|
|
74
77
|
is_public: call.type == FunctionType.PUBLIC,
|
|
@@ -76,8 +79,10 @@ export abstract class EntrypointPayload {
|
|
|
76
79
|
}));
|
|
77
80
|
/* eslint-enable camelcase */
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
return {
|
|
83
|
+
encodedFunctionCalls,
|
|
84
|
+
hashedArguments,
|
|
85
|
+
};
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
/* eslint-disable camelcase */
|
|
@@ -86,7 +91,7 @@ export abstract class EntrypointPayload {
|
|
|
86
91
|
* @internal
|
|
87
92
|
*/
|
|
88
93
|
get function_calls() {
|
|
89
|
-
return this
|
|
94
|
+
return this.functionCalls;
|
|
90
95
|
}
|
|
91
96
|
/* eslint-enable camelcase */
|
|
92
97
|
|
|
@@ -95,14 +100,14 @@ export abstract class EntrypointPayload {
|
|
|
95
100
|
* @internal
|
|
96
101
|
*/
|
|
97
102
|
get nonce() {
|
|
98
|
-
return this
|
|
103
|
+
return this._nonce;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
/**
|
|
102
107
|
* The hashed arguments for the function calls
|
|
103
108
|
*/
|
|
104
109
|
get hashedArguments() {
|
|
105
|
-
return this
|
|
110
|
+
return this._hashedArguments;
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
/**
|
|
@@ -116,12 +121,12 @@ export abstract class EntrypointPayload {
|
|
|
116
121
|
* @returns The hash of the payload
|
|
117
122
|
*/
|
|
118
123
|
hash() {
|
|
119
|
-
return poseidon2HashWithSeparator(this.toFields(), this
|
|
124
|
+
return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex);
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
/** Serializes the function calls to an array of fields. */
|
|
123
128
|
protected functionCallsToFields() {
|
|
124
|
-
return this
|
|
129
|
+
return this.functionCalls.flatMap(call => [
|
|
125
130
|
call.args_hash,
|
|
126
131
|
call.function_selector,
|
|
127
132
|
call.target_address,
|
|
@@ -135,8 +140,9 @@ export abstract class EntrypointPayload {
|
|
|
135
140
|
* @param functionCalls - The function calls to execute
|
|
136
141
|
* @returns The execution payload
|
|
137
142
|
*/
|
|
138
|
-
static fromFunctionCalls(functionCalls: FunctionCall[]) {
|
|
139
|
-
|
|
143
|
+
static async fromFunctionCalls(functionCalls: FunctionCall[]) {
|
|
144
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(functionCalls);
|
|
145
|
+
return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, 0, Fr.random());
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
/**
|
|
@@ -145,12 +151,13 @@ export abstract class EntrypointPayload {
|
|
|
145
151
|
* @param nonce - The nonce for the payload, used to emit a nullifier identifying the call
|
|
146
152
|
* @returns The execution payload
|
|
147
153
|
*/
|
|
148
|
-
static fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, 4>, nonce = Fr.random()) {
|
|
154
|
+
static async fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, 4>, nonce = Fr.random()) {
|
|
149
155
|
if (functionCalls.length > APP_MAX_CALLS) {
|
|
150
156
|
throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`);
|
|
151
157
|
}
|
|
152
158
|
const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
|
|
153
|
-
|
|
159
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls);
|
|
160
|
+
return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, GeneratorIndex.SIGNATURE_PAYLOAD, nonce);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
/**
|
|
@@ -164,7 +171,14 @@ export abstract class EntrypointPayload {
|
|
|
164
171
|
const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings);
|
|
165
172
|
const isFeePayer = !!feePayer && feePayer.equals(sender);
|
|
166
173
|
const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS);
|
|
167
|
-
|
|
174
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls);
|
|
175
|
+
return new FeeEntrypointPayload(
|
|
176
|
+
encodedFunctionCalls,
|
|
177
|
+
hashedArguments,
|
|
178
|
+
GeneratorIndex.FEE_PAYLOAD,
|
|
179
|
+
Fr.random(),
|
|
180
|
+
isFeePayer,
|
|
181
|
+
);
|
|
168
182
|
}
|
|
169
183
|
}
|
|
170
184
|
|
|
@@ -179,8 +193,14 @@ class AppEntrypointPayload extends EntrypointPayload {
|
|
|
179
193
|
class FeeEntrypointPayload extends EntrypointPayload {
|
|
180
194
|
#isFeePayer: boolean;
|
|
181
195
|
|
|
182
|
-
constructor(
|
|
183
|
-
|
|
196
|
+
constructor(
|
|
197
|
+
functionCalls: EncodedFunctionCall[],
|
|
198
|
+
hashedArguments: HashedValues[],
|
|
199
|
+
generatorIndex: number,
|
|
200
|
+
nonce: Fr,
|
|
201
|
+
isFeePayer: boolean,
|
|
202
|
+
) {
|
|
203
|
+
super(functionCalls, hashedArguments, generatorIndex, nonce);
|
|
184
204
|
this.#isFeePayer = isFeePayer;
|
|
185
205
|
}
|
|
186
206
|
|
|
@@ -202,6 +222,12 @@ class FeeEntrypointPayload extends EntrypointPayload {
|
|
|
202
222
|
* @param feePayload - A fee payload.
|
|
203
223
|
* @returns A hash of a combined payload.
|
|
204
224
|
*/
|
|
205
|
-
export function computeCombinedPayloadHash(
|
|
206
|
-
|
|
225
|
+
export async function computeCombinedPayloadHash(
|
|
226
|
+
appPayload: AppEntrypointPayload,
|
|
227
|
+
feePayload: FeeEntrypointPayload,
|
|
228
|
+
): Promise<Fr> {
|
|
229
|
+
return poseidon2HashWithSeparator(
|
|
230
|
+
[await appPayload.hash(), await feePayload.hash()],
|
|
231
|
+
GeneratorIndex.COMBINED_PAYLOAD,
|
|
232
|
+
);
|
|
207
233
|
}
|
|
@@ -24,7 +24,7 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
|
|
|
24
24
|
*/
|
|
25
25
|
override async getFunctionCalls(): Promise<FunctionCall[]> {
|
|
26
26
|
const canonicalFeeJuice = await getCanonicalFeeJuice();
|
|
27
|
-
const selector = FunctionSelector.fromNameAndParameters(
|
|
27
|
+
const selector = await FunctionSelector.fromNameAndParameters(
|
|
28
28
|
canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!,
|
|
29
29
|
);
|
|
30
30
|
|
|
@@ -94,9 +94,9 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
94
94
|
await this.wallet.createAuthWit({
|
|
95
95
|
caller: this.paymentContract,
|
|
96
96
|
action: {
|
|
97
|
-
name: '
|
|
98
|
-
args: [this.wallet.getAddress().toField(), ...maxFee.toFields(), nonce],
|
|
99
|
-
selector: FunctionSelector.fromSignature('
|
|
97
|
+
name: 'transfer_to_public',
|
|
98
|
+
args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), ...maxFee.toFields(), nonce],
|
|
99
|
+
selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),(Field,Field),Field)'),
|
|
100
100
|
type: FunctionType.PRIVATE,
|
|
101
101
|
isStatic: false,
|
|
102
102
|
to: await this.getAsset(),
|
|
@@ -108,7 +108,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
108
108
|
{
|
|
109
109
|
name: 'fee_entrypoint_private',
|
|
110
110
|
to: this.paymentContract,
|
|
111
|
-
selector: FunctionSelector.fromSignature('fee_entrypoint_private((Field,Field),Field)'),
|
|
111
|
+
selector: await FunctionSelector.fromSignature('fee_entrypoint_private((Field,Field),Field)'),
|
|
112
112
|
type: FunctionType.PRIVATE,
|
|
113
113
|
isStatic: false,
|
|
114
114
|
args: [...maxFee.toFields(), nonce],
|
|
@@ -82,33 +82,33 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
82
82
|
const nonce = Fr.random();
|
|
83
83
|
const maxFee = new U128(gasSettings.getFeeLimit().toBigInt());
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
const setPublicAuthWitInteraction = await this.wallet.setPublicAuthWit(
|
|
86
|
+
{
|
|
87
|
+
caller: this.paymentContract,
|
|
88
|
+
action: {
|
|
89
|
+
name: 'transfer_in_public',
|
|
90
|
+
args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), ...maxFee.toFields(), nonce],
|
|
91
|
+
selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),(Field,Field),Field)'),
|
|
92
|
+
type: FunctionType.PUBLIC,
|
|
93
|
+
isStatic: false,
|
|
94
|
+
to: await this.getAsset(),
|
|
95
|
+
returnTypes: [],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
true,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return [
|
|
102
|
+
await setPublicAuthWitInteraction.request(),
|
|
103
103
|
{
|
|
104
104
|
name: 'fee_entrypoint_public',
|
|
105
105
|
to: this.paymentContract,
|
|
106
|
-
selector: FunctionSelector.fromSignature('fee_entrypoint_public((Field,Field),Field)'),
|
|
106
|
+
selector: await FunctionSelector.fromSignature('fee_entrypoint_public((Field,Field),Field)'),
|
|
107
107
|
type: FunctionType.PRIVATE,
|
|
108
108
|
isStatic: false,
|
|
109
109
|
args: [...maxFee.toFields(), nonce],
|
|
110
110
|
returnTypes: [],
|
|
111
111
|
},
|
|
112
|
-
]
|
|
112
|
+
];
|
|
113
113
|
}
|
|
114
114
|
}
|
package/src/index.ts
CHANGED
|
@@ -147,14 +147,12 @@ export { elapsed } from '@aztec/foundation/timer';
|
|
|
147
147
|
export { type FieldsOf } from '@aztec/foundation/types';
|
|
148
148
|
export { fileURLToPath } from '@aztec/foundation/url';
|
|
149
149
|
|
|
150
|
-
export { EthCheatCodes, deployL1Contract, deployL1Contracts, type DeployL1Contracts } from '@aztec/ethereum';
|
|
151
|
-
|
|
152
150
|
// Start of section that exports public api via granular api.
|
|
153
151
|
// Here you *can* do `export *` as the granular api defacto exports things explicitly.
|
|
154
152
|
// This entire index file will be deprecated at some point after we're satisfied.
|
|
155
153
|
export * from './api/abi.js';
|
|
156
154
|
export * from './api/fee.js';
|
|
157
|
-
export * from './api/
|
|
155
|
+
export * from './api/addresses.js';
|
|
156
|
+
export * from './api/ethereum.js';
|
|
158
157
|
// Granular export, even if not in the api folder
|
|
159
158
|
export * from './contract/index.js';
|
|
160
|
-
export * from './api/addresses.js';
|
|
@@ -15,9 +15,12 @@ import type * as chains from 'viem/chains';
|
|
|
15
15
|
* block within the slot. And if so, it will time travel into the next slot.
|
|
16
16
|
*/
|
|
17
17
|
export class AnvilTestWatcher {
|
|
18
|
+
private isSandbox: boolean = false;
|
|
19
|
+
|
|
18
20
|
private rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;
|
|
19
21
|
|
|
20
22
|
private filledRunningPromise?: RunningPromise;
|
|
23
|
+
private mineIfOutdatedPromise?: RunningPromise;
|
|
21
24
|
|
|
22
25
|
private logger: Logger = createLogger(`aztecjs:utils:watcher`);
|
|
23
26
|
|
|
@@ -36,6 +39,10 @@ export class AnvilTestWatcher {
|
|
|
36
39
|
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
setIsSandbox(isSandbox: boolean) {
|
|
43
|
+
this.isSandbox = isSandbox;
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
async start() {
|
|
40
47
|
if (this.filledRunningPromise) {
|
|
41
48
|
throw new Error('Watcher already watching for filled slot');
|
|
@@ -48,8 +55,10 @@ export class AnvilTestWatcher {
|
|
|
48
55
|
const isAutoMining = await this.cheatcodes.isAutoMining();
|
|
49
56
|
|
|
50
57
|
if (isAutoMining) {
|
|
51
|
-
this.filledRunningPromise = new RunningPromise(() => this.
|
|
58
|
+
this.filledRunningPromise = new RunningPromise(() => this.warpTimeIfNeeded(), this.logger, 1000);
|
|
52
59
|
this.filledRunningPromise.start();
|
|
60
|
+
this.mineIfOutdatedPromise = new RunningPromise(() => this.mineIfOutdated(), this.logger, 1000);
|
|
61
|
+
this.mineIfOutdatedPromise.start();
|
|
53
62
|
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
54
63
|
} else {
|
|
55
64
|
this.logger.info(`Watcher not started because not auto mining`);
|
|
@@ -58,25 +67,64 @@ export class AnvilTestWatcher {
|
|
|
58
67
|
|
|
59
68
|
async stop() {
|
|
60
69
|
await this.filledRunningPromise?.stop();
|
|
70
|
+
await this.mineIfOutdatedPromise?.stop();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async mineIfOutdated() {
|
|
74
|
+
// this doesn't apply to the sandbox, because we don't have a date provider in the sandbox
|
|
75
|
+
if (!this.dateProvider) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const l1Time = (await this.cheatcodes.timestamp()) * 1000;
|
|
80
|
+
const wallTime = this.dateProvider.now();
|
|
81
|
+
|
|
82
|
+
// If the wall time is more than 24 seconds away from L1 time,
|
|
83
|
+
// mine a block and sync the clocks
|
|
84
|
+
if (Math.abs(wallTime - l1Time) > 24 * 1000) {
|
|
85
|
+
this.logger.warn(`Wall time is more than 24 seconds away from L1 time, mining a block and syncing clocks`);
|
|
86
|
+
await this.cheatcodes.evmMine();
|
|
87
|
+
const newL1Time = await this.cheatcodes.timestamp();
|
|
88
|
+
this.logger.info(`New L1 time: ${newL1Time}`);
|
|
89
|
+
this.dateProvider.setTime(newL1Time * 1000);
|
|
90
|
+
}
|
|
61
91
|
}
|
|
62
92
|
|
|
63
|
-
async
|
|
93
|
+
async warpTimeIfNeeded() {
|
|
64
94
|
try {
|
|
65
95
|
const currentSlot = await this.rollup.read.getCurrentSlot();
|
|
66
96
|
const pendingBlockNumber = BigInt(await this.rollup.read.getPendingBlockNumber());
|
|
67
97
|
const blockLog = await this.rollup.read.getBlock([pendingBlockNumber]);
|
|
98
|
+
const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([currentSlot + 1n]));
|
|
68
99
|
|
|
69
100
|
if (currentSlot === blockLog.slotNumber) {
|
|
70
101
|
// We should jump to the next slot
|
|
71
|
-
const timestamp = await this.rollup.read.getTimestampForSlot([currentSlot + 1n]);
|
|
72
102
|
try {
|
|
73
|
-
await this.cheatcodes.warp(
|
|
74
|
-
this.dateProvider?.setTime(
|
|
103
|
+
await this.cheatcodes.warp(nextSlotTimestamp);
|
|
104
|
+
this.dateProvider?.setTime(nextSlotTimestamp * 1000);
|
|
75
105
|
} catch (e) {
|
|
76
|
-
this.logger.error(`Failed to warp to timestamp ${
|
|
106
|
+
this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
|
|
77
107
|
}
|
|
78
108
|
|
|
79
109
|
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// If we are not in sandbox, we don't need to warp time
|
|
114
|
+
if (!this.isSandbox) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const currentTimestamp = this.dateProvider?.now() ?? Date.now();
|
|
119
|
+
if (currentTimestamp > nextSlotTimestamp * 1000) {
|
|
120
|
+
try {
|
|
121
|
+
await this.cheatcodes.warp(nextSlotTimestamp);
|
|
122
|
+
this.dateProvider?.setTime(nextSlotTimestamp * 1000);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
|
|
80
128
|
}
|
|
81
129
|
} catch (err) {
|
|
82
130
|
this.logger.error('mineIfSlotFilled failed');
|
package/src/utils/authwit.ts
CHANGED
|
@@ -50,17 +50,17 @@ export type IntentAction = {
|
|
|
50
50
|
* @param metadata - The metadata for the intent (chainId, version)
|
|
51
51
|
* @returns The message hash for the action
|
|
52
52
|
*/
|
|
53
|
-
export const computeAuthWitMessageHash = (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
|
|
53
|
+
export const computeAuthWitMessageHash = async (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
|
|
54
54
|
const chainId = metadata.chainId;
|
|
55
55
|
const version = metadata.version;
|
|
56
56
|
|
|
57
57
|
if ('caller' in intent) {
|
|
58
|
-
const action = intent.action instanceof ContractFunctionInteraction ? intent.action.request() : intent.action;
|
|
58
|
+
const action = intent.action instanceof ContractFunctionInteraction ? await intent.action.request() : intent.action;
|
|
59
59
|
return computeOuterAuthWitHash(
|
|
60
60
|
action.to,
|
|
61
61
|
chainId,
|
|
62
62
|
version,
|
|
63
|
-
computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
63
|
+
await computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
64
64
|
);
|
|
65
65
|
} else {
|
|
66
66
|
const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
|
|
@@ -69,8 +69,12 @@ export const computeAuthWitMessageHash = (intent: IntentInnerHash | IntentAction
|
|
|
69
69
|
};
|
|
70
70
|
// docs:end:authwit_computeAuthWitMessageHash
|
|
71
71
|
|
|
72
|
-
export const computeInnerAuthWitHashFromAction = (caller: AztecAddress, action: FunctionCall) =>
|
|
73
|
-
computeInnerAuthWitHash([
|
|
72
|
+
export const computeInnerAuthWitHashFromAction = async (caller: AztecAddress, action: FunctionCall) =>
|
|
73
|
+
computeInnerAuthWitHash([
|
|
74
|
+
caller.toField(),
|
|
75
|
+
action.selector.toField(),
|
|
76
|
+
(await HashedValues.fromValues(action.args)).hash,
|
|
77
|
+
]);
|
|
74
78
|
|
|
75
79
|
/**
|
|
76
80
|
* Compute the inner hash for an authentication witness.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RollupContract } from '@aztec/ethereum';
|
|
1
|
+
import { type RollupContract } from '@aztec/ethereum/contracts';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
|
|
4
4
|
import { type PublicClient } from 'viem';
|
|
@@ -27,7 +27,7 @@ export class ChainMonitor {
|
|
|
27
27
|
if (this.handle) {
|
|
28
28
|
throw new Error('Chain monitor already started');
|
|
29
29
|
}
|
|
30
|
-
this.handle = setInterval(
|
|
30
|
+
this.handle = setInterval(this.safeRun.bind(this), this.intervalMs);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
stop() {
|
|
@@ -37,6 +37,12 @@ export class ChainMonitor {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
private safeRun() {
|
|
41
|
+
void this.run().catch(error => {
|
|
42
|
+
this.logger.error('Error in chain monitor loop', error);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
async run() {
|
|
41
47
|
const newL1BlockNumber = Number(await this.l1Client.getBlockNumber({ cacheTime: 0 }));
|
|
42
48
|
if (this.l1BlockNumber === newL1BlockNumber) {
|
package/src/utils/cheat_codes.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type EpochProofClaim, type Note, type PXE } from '@aztec/circuit-types';
|
|
2
2
|
import { type AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
|
|
3
3
|
import { deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
|
|
4
|
-
import { EthCheatCodes
|
|
4
|
+
import { EthCheatCodes } from '@aztec/ethereum/eth-cheatcodes';
|
|
5
|
+
import { type L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
7
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
7
8
|
|
|
@@ -95,8 +96,8 @@ export class RollupCheatCodes {
|
|
|
95
96
|
/** Slot duration */ slotDuration: bigint;
|
|
96
97
|
}> {
|
|
97
98
|
const [epochDuration, slotDuration] = await Promise.all([
|
|
98
|
-
this.rollup.read.
|
|
99
|
-
this.rollup.read.
|
|
99
|
+
this.rollup.read.getEpochDuration(),
|
|
100
|
+
this.rollup.read.getSlotDuration(),
|
|
100
101
|
]);
|
|
101
102
|
return { epochDuration, slotDuration };
|
|
102
103
|
}
|
|
@@ -127,7 +128,7 @@ export class RollupCheatCodes {
|
|
|
127
128
|
*/
|
|
128
129
|
public async advanceSlots(howMany: number) {
|
|
129
130
|
const l1Timestamp = (await this.client.getBlock()).timestamp;
|
|
130
|
-
const slotDuration = await this.rollup.read.
|
|
131
|
+
const slotDuration = await this.rollup.read.getSlotDuration();
|
|
131
132
|
const timeToWarp = BigInt(howMany) * slotDuration;
|
|
132
133
|
await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, true);
|
|
133
134
|
const [slot, epoch] = await Promise.all([this.getSlot(), this.getEpoch()]);
|
|
@@ -223,7 +224,7 @@ export class AztecCheatCodes {
|
|
|
223
224
|
* @param key - The key to lookup in the map
|
|
224
225
|
* @returns The storage slot of the value in the map
|
|
225
226
|
*/
|
|
226
|
-
public computeSlotInMap(mapSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr {
|
|
227
|
+
public computeSlotInMap(mapSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Promise<Fr> {
|
|
227
228
|
const keyFr = typeof key === 'bigint' ? new Fr(key) : key.toField();
|
|
228
229
|
return deriveStorageSlotInMap(mapSlot, keyFr);
|
|
229
230
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type SiblingPath,
|
|
8
8
|
computeSecretHash,
|
|
9
9
|
} from '@aztec/aztec.js';
|
|
10
|
-
import { extractEvent } from '@aztec/ethereum';
|
|
10
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
11
11
|
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
12
12
|
import { FeeJuicePortalAbi, OutboxAbi, TestERC20Abi, TokenPortalAbi } from '@aztec/l1-artifacts';
|
|
13
13
|
|
|
@@ -49,9 +49,9 @@ function stringifyEthAddress(address: EthAddress | Hex, name?: string) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** Generates a pair secret and secret hash */
|
|
52
|
-
export function generateClaimSecret(logger?: Logger): [Fr, Fr] {
|
|
52
|
+
export async function generateClaimSecret(logger?: Logger): Promise<[Fr, Fr]> {
|
|
53
53
|
const secret = Fr.random();
|
|
54
|
-
const secretHash = computeSecretHash(secret);
|
|
54
|
+
const secretHash = await computeSecretHash(secret);
|
|
55
55
|
logger?.verbose(`Generated claim secret=${secret.toString()} hash=${secretHash.toString()}`);
|
|
56
56
|
return [secret, secretHash];
|
|
57
57
|
}
|
|
@@ -144,7 +144,7 @@ export class L1FeeJuicePortalManager {
|
|
|
144
144
|
* @param mint - Whether to mint the tokens before sending (only during testing).
|
|
145
145
|
*/
|
|
146
146
|
public async bridgeTokensPublic(to: AztecAddress, amount: bigint, mint = false): Promise<L2AmountClaim> {
|
|
147
|
-
const [claimSecret, claimSecretHash] = generateClaimSecret();
|
|
147
|
+
const [claimSecret, claimSecretHash] = await generateClaimSecret();
|
|
148
148
|
if (mint) {
|
|
149
149
|
await this.tokenManager.mint(amount, this.walletClient.account.address);
|
|
150
150
|
}
|
|
@@ -55,7 +55,7 @@ export class AccountWallet extends BaseWallet {
|
|
|
55
55
|
} else if (messageHashOrIntent instanceof Fr) {
|
|
56
56
|
messageHash = messageHashOrIntent;
|
|
57
57
|
} else {
|
|
58
|
-
messageHash = this.getMessageHash(messageHashOrIntent);
|
|
58
|
+
messageHash = await this.getMessageHash(messageHashOrIntent);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const witness = await this.account.createAuthWit(messageHash);
|
|
@@ -72,17 +72,17 @@ export class AccountWallet extends BaseWallet {
|
|
|
72
72
|
* @param authorized - True to authorize, false to revoke authorization.
|
|
73
73
|
* @returns - A function interaction.
|
|
74
74
|
*/
|
|
75
|
-
public setPublicAuthWit(
|
|
75
|
+
public async setPublicAuthWit(
|
|
76
76
|
messageHashOrIntent: Fr | Buffer | IntentInnerHash | IntentAction,
|
|
77
77
|
authorized: boolean,
|
|
78
|
-
): ContractFunctionInteraction {
|
|
78
|
+
): Promise<ContractFunctionInteraction> {
|
|
79
79
|
let messageHash: Fr;
|
|
80
80
|
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
81
81
|
messageHash = Fr.fromBuffer(messageHashOrIntent);
|
|
82
82
|
} else if (messageHashOrIntent instanceof Fr) {
|
|
83
83
|
messageHash = messageHashOrIntent;
|
|
84
84
|
} else {
|
|
85
|
-
messageHash = this.getMessageHash(messageHashOrIntent);
|
|
85
|
+
messageHash = await this.getMessageHash(messageHashOrIntent);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
return new ContractFunctionInteraction(this, ProtocolContractAddress.AuthRegistry, this.getSetAuthorizedAbi(), [
|
|
@@ -91,16 +91,17 @@ export class AccountWallet extends BaseWallet {
|
|
|
91
91
|
]);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
private getInnerHashAndConsumer(intent: IntentInnerHash | IntentAction): {
|
|
94
|
+
private async getInnerHashAndConsumer(intent: IntentInnerHash | IntentAction): Promise<{
|
|
95
95
|
/** The inner hash */
|
|
96
96
|
innerHash: Fr;
|
|
97
97
|
/** The consumer of the authwit */
|
|
98
98
|
consumer: AztecAddress;
|
|
99
|
-
} {
|
|
99
|
+
}> {
|
|
100
100
|
if ('caller' in intent && 'action' in intent) {
|
|
101
|
-
const action =
|
|
101
|
+
const action =
|
|
102
|
+
intent.action instanceof ContractFunctionInteraction ? await intent.action.request() : intent.action;
|
|
102
103
|
return {
|
|
103
|
-
innerHash: computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
104
|
+
innerHash: await computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
104
105
|
consumer: action.to,
|
|
105
106
|
};
|
|
106
107
|
} else if (Buffer.isBuffer(intent.innerHash)) {
|
|
@@ -115,7 +116,7 @@ export class AccountWallet extends BaseWallet {
|
|
|
115
116
|
* @param intent - A tuple of (consumer and inner hash) or (caller and action)
|
|
116
117
|
* @returns The message hash
|
|
117
118
|
*/
|
|
118
|
-
private getMessageHash(intent: IntentInnerHash | IntentAction): Fr {
|
|
119
|
+
private getMessageHash(intent: IntentInnerHash | IntentAction): Promise<Fr> {
|
|
119
120
|
const chainId = this.getChainId();
|
|
120
121
|
const version = this.getVersion();
|
|
121
122
|
return computeAuthWitMessageHash(intent, { chainId, version });
|
|
@@ -140,9 +141,9 @@ export class AccountWallet extends BaseWallet {
|
|
|
140
141
|
/** boolean flag indicating if the authwit is valid in public context */
|
|
141
142
|
isValidInPublic: boolean;
|
|
142
143
|
}> {
|
|
143
|
-
const { innerHash, consumer } = this.getInnerHashAndConsumer(intent);
|
|
144
|
+
const { innerHash, consumer } = await this.getInnerHashAndConsumer(intent);
|
|
144
145
|
|
|
145
|
-
const messageHash = this.getMessageHash(intent);
|
|
146
|
+
const messageHash = await this.getMessageHash(intent);
|
|
146
147
|
const results = { isValidInPrivate: false, isValidInPublic: false };
|
|
147
148
|
|
|
148
149
|
// Check private
|
|
@@ -30,9 +30,9 @@ export class AccountWalletWithSecretKey extends AccountWallet {
|
|
|
30
30
|
* note - this ensures that the address secret always corresponds to an address point with y being positive
|
|
31
31
|
* dev - this is also referred to as the address secret, which decrypts payloads encrypted to an address point
|
|
32
32
|
*/
|
|
33
|
-
public getEncryptionSecret() {
|
|
33
|
+
public async getEncryptionSecret() {
|
|
34
34
|
return computeAddressSecret(
|
|
35
|
-
this.getCompleteAddress().getPreaddress(),
|
|
35
|
+
await this.getCompleteAddress().getPreaddress(),
|
|
36
36
|
deriveMasterIncomingViewingSecretKey(this.getSecretKey()),
|
|
37
37
|
);
|
|
38
38
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AuthWitness,
|
|
3
|
+
type ContractClassMetadata,
|
|
4
|
+
type ContractMetadata,
|
|
3
5
|
type EventMetadataDefinition,
|
|
4
6
|
type ExtendedNote,
|
|
5
7
|
type GetContractClassLogsResponse,
|
|
@@ -22,7 +24,6 @@ import {
|
|
|
22
24
|
import {
|
|
23
25
|
type AztecAddress,
|
|
24
26
|
type CompleteAddress,
|
|
25
|
-
type ContractClassWithId,
|
|
26
27
|
type ContractInstanceWithAddress,
|
|
27
28
|
type Fr,
|
|
28
29
|
type GasFees,
|
|
@@ -66,15 +67,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
66
67
|
getAddress() {
|
|
67
68
|
return this.getCompleteAddress().address;
|
|
68
69
|
}
|
|
69
|
-
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
70
|
-
return this.pxe.getContractInstance(address);
|
|
71
|
-
}
|
|
72
|
-
getContractClass(id: Fr): Promise<ContractClassWithId | undefined> {
|
|
73
|
-
return this.pxe.getContractClass(id);
|
|
74
|
-
}
|
|
75
|
-
getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
76
|
-
return this.pxe.getContractArtifact(id);
|
|
77
|
-
}
|
|
78
70
|
addCapsule(capsule: Fr[]): Promise<void> {
|
|
79
71
|
return this.pxe.addCapsule(capsule);
|
|
80
72
|
}
|
|
@@ -182,18 +174,15 @@ export abstract class BaseWallet implements Wallet {
|
|
|
182
174
|
getAuthWitness(messageHash: Fr) {
|
|
183
175
|
return this.pxe.getAuthWitness(messageHash);
|
|
184
176
|
}
|
|
185
|
-
isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
186
|
-
return this.pxe.isContractClassPubliclyRegistered(id);
|
|
187
|
-
}
|
|
188
|
-
isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
|
|
189
|
-
return this.pxe.isContractPubliclyDeployed(address);
|
|
190
|
-
}
|
|
191
|
-
isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
192
|
-
return this.pxe.isContractInitialized(address);
|
|
193
|
-
}
|
|
194
177
|
getPXEInfo(): Promise<PXEInfo> {
|
|
195
178
|
return this.pxe.getPXEInfo();
|
|
196
179
|
}
|
|
180
|
+
getContractClassMetadata(id: Fr, includeArtifact: boolean = false): Promise<ContractClassMetadata> {
|
|
181
|
+
return this.pxe.getContractClassMetadata(id, includeArtifact);
|
|
182
|
+
}
|
|
183
|
+
getContractMetadata(address: AztecAddress): Promise<ContractMetadata> {
|
|
184
|
+
return this.pxe.getContractMetadata(address);
|
|
185
|
+
}
|
|
197
186
|
getPrivateEvents<T>(
|
|
198
187
|
event: EventMetadataDefinition,
|
|
199
188
|
from: number,
|
package/dest/api/init.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This should only be needed to be called in CJS environments that don't have top level await.
|
|
3
|
-
* Initializes any asynchronous subsystems required to use the library.
|
|
4
|
-
* At time of writing, this is just our foundation crypto lib.
|
|
5
|
-
*/
|
|
6
|
-
export declare function initAztecJs(): Promise<void>;
|
|
7
|
-
//# sourceMappingURL=init.d.ts.map
|
package/dest/api/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/api/init.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAsB,WAAW,kBAEhC"}
|