@aztec/aztec.js 0.22.0 → 0.24.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/index.d.ts +1 -1
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/interface.d.ts +12 -2
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -1
- package/dest/account_manager/index.js +2 -2
- package/dest/api/account.d.ts +1 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -1
- package/dest/api/deployment.d.ts +4 -0
- package/dest/api/deployment.d.ts.map +1 -0
- package/dest/api/deployment.js +4 -0
- package/dest/api/fee.d.ts +4 -0
- package/dest/api/fee.d.ts.map +1 -0
- package/dest/api/fee.js +3 -0
- package/dest/contract/unsafe_contract.d.ts +15 -0
- package/dest/contract/unsafe_contract.d.ts.map +1 -0
- package/dest/contract/unsafe_contract.js +14 -0
- package/dest/deployment/broadcast_function.d.ts +24 -0
- package/dest/deployment/broadcast_function.d.ts.map +1 -0
- package/dest/deployment/broadcast_function.js +67 -0
- package/dest/deployment/contract_deployer.d.ts.map +1 -0
- package/dest/{contract_deployer → deployment}/contract_deployer.js +1 -1
- package/dest/deployment/deploy_instance.d.ts +13 -0
- package/dest/deployment/deploy_instance.d.ts.map +1 -0
- package/dest/deployment/deploy_instance.js +13 -0
- package/dest/deployment/index.d.ts.map +1 -0
- package/dest/{contract_deployer → deployment}/index.js +1 -1
- package/dest/deployment/protocol_contracts.d.ts +7 -0
- package/dest/deployment/protocol_contracts.d.ts.map +1 -0
- package/dest/deployment/protocol_contracts.js +14 -0
- package/dest/deployment/register_class.d.ts +6 -0
- package/dest/deployment/register_class.d.ts.map +1 -0
- package/dest/deployment/register_class.js +11 -0
- package/dest/fee/fee_payment_method.d.ts +28 -0
- package/dest/fee/fee_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_payment_method.js +2 -0
- package/dest/fee/generic_fee_payment_method.d.ts +58 -0
- package/dest/fee/generic_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/generic_fee_payment_method.js +73 -0
- package/dest/fee/native_fee_payment_method.d.ts +32 -0
- package/dest/fee/native_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/native_fee_payment_method.js +55 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/utils/cheat_codes.js +2 -2
- package/dest/wallet/account_wallet.d.ts +2 -2
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +3 -3
- package/dest/wallet/base_wallet.d.ts +2 -1
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +1 -1
- package/package.json +9 -6
- package/src/account/contract.ts +33 -0
- package/src/account/index.ts +16 -0
- package/src/account/interface.ts +47 -0
- package/src/account/wallet.ts +8 -0
- package/src/account_manager/deploy_account_sent_tx.ts +42 -0
- package/src/account_manager/index.ts +173 -0
- package/src/api/README.md +7 -0
- package/src/api/abi.ts +3 -0
- package/src/api/account.ts +13 -0
- package/src/api/aztec_address.ts +1 -0
- package/src/api/deployment.ts +3 -0
- package/src/api/eth_address.ts +1 -0
- package/src/api/ethereum.ts +6 -0
- package/src/api/fee.ts +3 -0
- package/src/api/fields.ts +1 -0
- package/src/api/init.ts +10 -0
- package/src/api/interfaces/pxe.ts +1 -0
- package/src/api/log_id.ts +1 -0
- package/src/api/tx_hash.ts +1 -0
- package/src/api/wallet.ts +1 -0
- package/src/contract/base_contract_interaction.ts +61 -0
- package/src/contract/batch_call.ts +23 -0
- package/src/contract/checker.ts +117 -0
- package/src/contract/contract.ts +56 -0
- package/src/contract/contract_base.ts +72 -0
- package/src/contract/contract_function_interaction.ts +80 -0
- package/src/contract/deploy_method.ts +151 -0
- package/src/contract/deploy_sent_tx.ts +69 -0
- package/src/contract/index.ts +44 -0
- package/src/contract/sent_tx.ts +135 -0
- package/src/contract/unsafe_contract.ts +19 -0
- package/src/deployment/broadcast_function.ts +118 -0
- package/src/deployment/contract_deployer.ts +30 -0
- package/src/deployment/deploy_instance.ts +28 -0
- package/src/deployment/index.ts +1 -0
- package/src/deployment/protocol_contracts.ts +17 -0
- package/src/deployment/register_class.ts +15 -0
- package/src/fee/fee_payment_method.ts +30 -0
- package/src/fee/generic_fee_payment_method.ts +81 -0
- package/src/fee/native_fee_payment_method.ts +61 -0
- package/src/index.ts +144 -0
- package/src/rpc_clients/index.ts +1 -0
- package/src/rpc_clients/pxe_client.ts +62 -0
- package/src/utils/abi_types.ts +16 -0
- package/src/utils/account.ts +32 -0
- package/src/utils/authwit.ts +24 -0
- package/src/utils/cheat_codes.ts +297 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/l1_contracts.ts +21 -0
- package/src/utils/l2_contracts.ts +12 -0
- package/src/utils/pub_key.ts +12 -0
- package/src/utils/pxe.ts +16 -0
- package/src/utils/secrets.ts +11 -0
- package/src/wallet/account_wallet.ts +70 -0
- package/src/wallet/account_wallet_with_private_key.ts +28 -0
- package/src/wallet/base_wallet.ts +123 -0
- package/src/wallet/create_recipient.ts +13 -0
- package/src/wallet/index.ts +31 -0
- package/src/wallet/signerless_wallet.ts +37 -0
- package/dest/contract_deployer/contract_deployer.d.ts.map +0 -1
- package/dest/contract_deployer/index.d.ts.map +0 -1
- /package/dest/{contract_deployer → deployment}/contract_deployer.d.ts +0 -0
- /package/dest/{contract_deployer → deployment}/index.d.ts +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { FunctionData } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
|
|
7
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
11
|
+
*/
|
|
12
|
+
export class GenericFeePaymentMethod implements FeePaymentMethod {
|
|
13
|
+
constructor(
|
|
14
|
+
/**
|
|
15
|
+
* The asset used to pay the fee.
|
|
16
|
+
*/
|
|
17
|
+
private asset: AztecAddress,
|
|
18
|
+
/**
|
|
19
|
+
* Address which will hold the fee payment.
|
|
20
|
+
*/
|
|
21
|
+
private paymentContract: AztecAddress,
|
|
22
|
+
/**
|
|
23
|
+
* Whether the fee payment is private
|
|
24
|
+
*/
|
|
25
|
+
private privatePayment: boolean,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The asset used to pay the fee.
|
|
30
|
+
* @returns The asset used to pay the fee.
|
|
31
|
+
*/
|
|
32
|
+
getAsset() {
|
|
33
|
+
return this.asset;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The address which will facilitate the fee payment.
|
|
38
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
39
|
+
*/
|
|
40
|
+
getPaymentContract() {
|
|
41
|
+
return this.paymentContract;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The fee payment function selector on the fee payment contract.
|
|
46
|
+
* @returns The fee payment function selector on the fee payment contract.
|
|
47
|
+
*/
|
|
48
|
+
#getFeePaymentEntrypoint() {
|
|
49
|
+
return this.privatePayment
|
|
50
|
+
? FunctionSelector.fromSignature('prepare_fee_private(Field, (Field))')
|
|
51
|
+
: FunctionSelector.fromSignature('prepare_fee_public(Field, (Field))');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether the fee payment is private or not
|
|
56
|
+
* @returns Whether the fee payment is private or not
|
|
57
|
+
*/
|
|
58
|
+
isPrivateFeePayment(): boolean {
|
|
59
|
+
return this.privatePayment;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a function call to pay the fee in the given asset.
|
|
64
|
+
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
65
|
+
* @returns The function call to pay the fee.
|
|
66
|
+
*/
|
|
67
|
+
getFunctionCalls(maxFee: Fr): FunctionCall[] {
|
|
68
|
+
return [
|
|
69
|
+
// TODO(fees) set up auth witnesses
|
|
70
|
+
{
|
|
71
|
+
to: this.getPaymentContract(),
|
|
72
|
+
functionData: new FunctionData(this.#getFeePaymentEntrypoint(), false, true, false),
|
|
73
|
+
args: [maxFee, this.asset],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static empty(): GenericFeePaymentMethod {
|
|
79
|
+
return new GenericFeePaymentMethod(AztecAddress.ZERO, AztecAddress.ZERO, false);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { FunctionData } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
|
|
7
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Pay fee directly in the native gas token.
|
|
11
|
+
*/
|
|
12
|
+
export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
13
|
+
// TODO(fees) replace this with the address of the gas token when that's deployed.
|
|
14
|
+
static #GAS_TOKEN = AztecAddress.ZERO;
|
|
15
|
+
|
|
16
|
+
constructor() {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets the native gas asset used to pay the fee.
|
|
20
|
+
* @returns The asset used to pay the fee.
|
|
21
|
+
*/
|
|
22
|
+
getAsset() {
|
|
23
|
+
return NativeFeePaymentMethod.#GAS_TOKEN;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The contract responsible for fee payment. This will be the same as the asset.
|
|
28
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
29
|
+
*/
|
|
30
|
+
getPaymentContract() {
|
|
31
|
+
return NativeFeePaymentMethod.#GAS_TOKEN;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fee payments in the native gas token are always public.
|
|
36
|
+
* @returns false
|
|
37
|
+
*/
|
|
38
|
+
isPrivateFeePayment(): boolean {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a function call to pay the fee in gas token..
|
|
44
|
+
* @param feeLimit - The maximum fee to be paid in gas token.
|
|
45
|
+
* @returns A function call
|
|
46
|
+
*/
|
|
47
|
+
getFunctionCalls(feeLimit: Fr): FunctionCall[] {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
to: NativeFeePaymentMethod.#GAS_TOKEN,
|
|
51
|
+
functionData: new FunctionData(FunctionSelector.fromSignature('check_balance(Field)'), false, false, false),
|
|
52
|
+
args: [feeLimit],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
to: NativeFeePaymentMethod.#GAS_TOKEN,
|
|
56
|
+
functionData: new FunctionData(FunctionSelector.fromSignature('pay_fee(Field)'), false, false, false),
|
|
57
|
+
args: [feeLimit],
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is our public api.
|
|
3
|
+
* Do NOT "export * from ..." here.
|
|
4
|
+
* Everything here should be explicit, to ensure we can clearly see everything we're exposing to the world.
|
|
5
|
+
* If it's exposed, people will use it, and then we can't remove/change the api without breaking client code.
|
|
6
|
+
* At the time of writing we overexpose things that should only be internal.
|
|
7
|
+
*
|
|
8
|
+
* TODO: Review and narrow scope of public api.
|
|
9
|
+
* We should also consider exposing subsections of the api via package.json exports, like we do with foundation.
|
|
10
|
+
* This can allow consumers to import much smaller parts of the library to incur less overhead.
|
|
11
|
+
* It will also allow web bundlers do perform intelligent chunking of bundles etc.
|
|
12
|
+
* Some work as been done on this within the api folder, providing the alternative import style of e.g.:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { TxHash } from '@aztec.js/tx_hash'
|
|
15
|
+
* import { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/aztec.js/abi';
|
|
16
|
+
* import { AztecAddress } from '@aztec/aztec.js/aztec_address';
|
|
17
|
+
* import { EthAddress } from '@aztec/aztec.js/eth_address';
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* TODO: Ultimately reimplement this mega exporter by mega exporting a granular api (then deprecate it).
|
|
21
|
+
*/
|
|
22
|
+
export {
|
|
23
|
+
WaitOpts,
|
|
24
|
+
ContractFunctionInteraction,
|
|
25
|
+
Contract,
|
|
26
|
+
ContractBase,
|
|
27
|
+
ContractMethod,
|
|
28
|
+
SentTx,
|
|
29
|
+
BatchCall,
|
|
30
|
+
DeployMethod,
|
|
31
|
+
DeploySentTx,
|
|
32
|
+
} from './contract/index.js';
|
|
33
|
+
|
|
34
|
+
export { ContractDeployer } from './deployment/index.js';
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
generatePublicKey,
|
|
38
|
+
FieldLike,
|
|
39
|
+
EthAddressLike,
|
|
40
|
+
computeMessageSecretHash,
|
|
41
|
+
CheatCodes,
|
|
42
|
+
AztecAddressLike,
|
|
43
|
+
FunctionSelectorLike,
|
|
44
|
+
WrappedFieldLike,
|
|
45
|
+
isContractDeployed,
|
|
46
|
+
EthCheatCodes,
|
|
47
|
+
computeAuthWitMessageHash,
|
|
48
|
+
waitForPXE,
|
|
49
|
+
waitForAccountSynch,
|
|
50
|
+
} from './utils/index.js';
|
|
51
|
+
|
|
52
|
+
export { createPXEClient } from './rpc_clients/index.js';
|
|
53
|
+
|
|
54
|
+
export { AuthWitnessProvider } from './account/index.js';
|
|
55
|
+
|
|
56
|
+
export { AccountContract } from './account/index.js';
|
|
57
|
+
export { AccountManager } from './account_manager/index.js';
|
|
58
|
+
|
|
59
|
+
export { AccountWalletWithPrivateKey, AccountWallet, Wallet, SignerlessWallet } from './wallet/index.js';
|
|
60
|
+
|
|
61
|
+
// // TODO https://github.com/AztecProtocol/aztec-packages/issues/2632 --> FunctionSelector might not need to be exposed
|
|
62
|
+
// // here once the issue is resolved.
|
|
63
|
+
export {
|
|
64
|
+
AztecAddress,
|
|
65
|
+
EthAddress,
|
|
66
|
+
Fr,
|
|
67
|
+
Fq,
|
|
68
|
+
GlobalVariables,
|
|
69
|
+
GrumpkinScalar,
|
|
70
|
+
Point,
|
|
71
|
+
getContractInstanceFromDeployParams,
|
|
72
|
+
getContractClassFromArtifact,
|
|
73
|
+
} from '@aztec/circuits.js';
|
|
74
|
+
|
|
75
|
+
export { Grumpkin, Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
AuthWitness,
|
|
79
|
+
AztecNode,
|
|
80
|
+
CompleteAddress,
|
|
81
|
+
ContractData,
|
|
82
|
+
DeployedContract,
|
|
83
|
+
ExtendedContractData,
|
|
84
|
+
ExtendedNote,
|
|
85
|
+
FunctionCall,
|
|
86
|
+
GrumpkinPrivateKey,
|
|
87
|
+
INITIAL_L2_BLOCK_NUM,
|
|
88
|
+
L2Actor,
|
|
89
|
+
L2Block,
|
|
90
|
+
L2BlockL2Logs,
|
|
91
|
+
LogFilter,
|
|
92
|
+
LogId,
|
|
93
|
+
LogType,
|
|
94
|
+
MerkleTreeId,
|
|
95
|
+
Note,
|
|
96
|
+
PXE,
|
|
97
|
+
PackedArguments,
|
|
98
|
+
PartialAddress,
|
|
99
|
+
PublicKey,
|
|
100
|
+
SyncStatus,
|
|
101
|
+
Tx,
|
|
102
|
+
TxExecutionRequest,
|
|
103
|
+
TxHash,
|
|
104
|
+
TxReceipt,
|
|
105
|
+
TxStatus,
|
|
106
|
+
UnencryptedL2Log,
|
|
107
|
+
createAztecNodeClient,
|
|
108
|
+
emptyFunctionCall,
|
|
109
|
+
merkleTreeIds,
|
|
110
|
+
mockTx,
|
|
111
|
+
Comparator,
|
|
112
|
+
} from '@aztec/circuit-types';
|
|
113
|
+
export { NodeInfo } from '@aztec/types/interfaces';
|
|
114
|
+
|
|
115
|
+
export { ContractInstanceWithAddress, ContractClassWithId } from '@aztec/types/contracts';
|
|
116
|
+
|
|
117
|
+
// TODO: These kinds of things have no place on our public api.
|
|
118
|
+
// External devs will almost certainly have their own methods of doing these things.
|
|
119
|
+
// If we want to use them in our own "aztec.js consuming code", import them from foundation as needed.
|
|
120
|
+
export { encodeArguments } from '@aztec/foundation/abi';
|
|
121
|
+
export { sha256 } from '@aztec/foundation/crypto';
|
|
122
|
+
export { DebugLogger, createDebugLogger, onLog } from '@aztec/foundation/log';
|
|
123
|
+
export { retry, retryUntil } from '@aztec/foundation/retry';
|
|
124
|
+
export { sleep } from '@aztec/foundation/sleep';
|
|
125
|
+
export { elapsed } from '@aztec/foundation/timer';
|
|
126
|
+
export { fileURLToPath } from '@aztec/foundation/url';
|
|
127
|
+
export { to2Fields, toBigInt } from '@aztec/foundation/serialize';
|
|
128
|
+
export { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
129
|
+
export { makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
130
|
+
export { FieldsOf } from '@aztec/foundation/types';
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
DeployL1Contracts,
|
|
134
|
+
L1ContractArtifactsForDeployment,
|
|
135
|
+
deployL1Contract,
|
|
136
|
+
deployL1Contracts,
|
|
137
|
+
} from '@aztec/ethereum';
|
|
138
|
+
|
|
139
|
+
// Start of section that exports public api via granular api.
|
|
140
|
+
// Here you *can* do `export *` as the granular api defacto exports things explicitly.
|
|
141
|
+
// This entire index file will be deprecated at some point after we're satisfied.
|
|
142
|
+
export * from './api/init.js';
|
|
143
|
+
export * from './api/abi.js';
|
|
144
|
+
export * from './api/fee.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pxe_client.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthWitness,
|
|
3
|
+
ContractData,
|
|
4
|
+
ExtendedContractData,
|
|
5
|
+
ExtendedNote,
|
|
6
|
+
ExtendedUnencryptedL2Log,
|
|
7
|
+
L2Block,
|
|
8
|
+
L2BlockL2Logs,
|
|
9
|
+
L2Tx,
|
|
10
|
+
LogId,
|
|
11
|
+
Note,
|
|
12
|
+
PXE,
|
|
13
|
+
Tx,
|
|
14
|
+
TxExecutionRequest,
|
|
15
|
+
TxHash,
|
|
16
|
+
TxReceipt,
|
|
17
|
+
} from '@aztec/circuit-types';
|
|
18
|
+
import {
|
|
19
|
+
AztecAddress,
|
|
20
|
+
CompleteAddress,
|
|
21
|
+
EthAddress,
|
|
22
|
+
Fr,
|
|
23
|
+
FunctionSelector,
|
|
24
|
+
GrumpkinScalar,
|
|
25
|
+
Point,
|
|
26
|
+
} from '@aztec/circuits.js';
|
|
27
|
+
import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a JSON-RPC client to remotely talk to PXE.
|
|
31
|
+
* @param url - The URL of the PXE.
|
|
32
|
+
* @param fetch - The fetch implementation to use.
|
|
33
|
+
* @returns A JSON-RPC client of PXE.
|
|
34
|
+
*/
|
|
35
|
+
export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], true)): PXE =>
|
|
36
|
+
createJsonRpcClient<PXE>(
|
|
37
|
+
url,
|
|
38
|
+
{
|
|
39
|
+
CompleteAddress,
|
|
40
|
+
FunctionSelector,
|
|
41
|
+
AztecAddress,
|
|
42
|
+
TxExecutionRequest,
|
|
43
|
+
ContractData,
|
|
44
|
+
ExtendedContractData,
|
|
45
|
+
ExtendedUnencryptedL2Log,
|
|
46
|
+
TxHash,
|
|
47
|
+
EthAddress,
|
|
48
|
+
Point,
|
|
49
|
+
Fr,
|
|
50
|
+
GrumpkinScalar,
|
|
51
|
+
Note,
|
|
52
|
+
ExtendedNote,
|
|
53
|
+
AuthWitness,
|
|
54
|
+
L2Tx,
|
|
55
|
+
LogId,
|
|
56
|
+
L2Block,
|
|
57
|
+
},
|
|
58
|
+
{ Tx, TxReceipt, L2BlockL2Logs },
|
|
59
|
+
false,
|
|
60
|
+
'pxe',
|
|
61
|
+
fetch,
|
|
62
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AztecAddress, EthAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
|
|
2
|
+
|
|
3
|
+
/** Any type that can be converted into a field for a contract call. */
|
|
4
|
+
export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
|
|
5
|
+
|
|
6
|
+
/** Any type that can be converted into an EthAddress Aztec.nr struct. */
|
|
7
|
+
export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | EthAddress;
|
|
8
|
+
|
|
9
|
+
/** Any type that can be converted into an AztecAddress Aztec.nr struct. */
|
|
10
|
+
export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
|
|
11
|
+
|
|
12
|
+
/** Any type that can be converted into an FunctionSelector Aztec.nr struct. */
|
|
13
|
+
export type FunctionSelectorLike = FieldLike | FunctionSelector;
|
|
14
|
+
|
|
15
|
+
/** Any type that can be converted into a struct with a single `inner` field. */
|
|
16
|
+
export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CompleteAddress, PXE } from '@aztec/circuit-types';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
|
|
4
|
+
import { DefaultWaitOpts, WaitOpts } from '../contract/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Waits for the account to finish synchronizing with the PXE Service.
|
|
8
|
+
* @param pxe - PXE instance
|
|
9
|
+
* @param address - Address to wait for synch
|
|
10
|
+
* @param opts - Wait options
|
|
11
|
+
*/
|
|
12
|
+
export async function waitForAccountSynch(
|
|
13
|
+
pxe: PXE,
|
|
14
|
+
address: CompleteAddress,
|
|
15
|
+
{ interval, timeout }: WaitOpts = DefaultWaitOpts,
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
const publicKey = address.publicKey.toString();
|
|
18
|
+
await retryUntil(
|
|
19
|
+
async () => {
|
|
20
|
+
const status = await pxe.getSyncStatus();
|
|
21
|
+
const accountSynchedToBlock = status.notes[publicKey];
|
|
22
|
+
if (typeof accountSynchedToBlock === 'undefined') {
|
|
23
|
+
return false;
|
|
24
|
+
} else {
|
|
25
|
+
return accountSynchedToBlock >= status.blocks;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
'waitForAccountSynch',
|
|
29
|
+
timeout,
|
|
30
|
+
interval,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FunctionCall, PackedArguments } from '@aztec/circuit-types';
|
|
2
|
+
import { AztecAddress, GeneratorIndex } from '@aztec/circuits.js';
|
|
3
|
+
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
|
+
|
|
5
|
+
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
|
+
/**
|
|
7
|
+
* Compute an authentication witness message hash from a caller and a request
|
|
8
|
+
* H(caller: AztecAddress, target: AztecAddress, selector: Field, args_hash: Field)
|
|
9
|
+
* @param caller - The caller approved to make the call
|
|
10
|
+
* @param request - The request to be made (function call)
|
|
11
|
+
* @returns The message hash for the witness
|
|
12
|
+
*/
|
|
13
|
+
export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => {
|
|
14
|
+
return pedersenHash(
|
|
15
|
+
[
|
|
16
|
+
caller.toField(),
|
|
17
|
+
request.to.toField(),
|
|
18
|
+
request.functionData.selector.toField(),
|
|
19
|
+
PackedArguments.fromArgs(request.args).hash,
|
|
20
|
+
].map(fr => fr.toBuffer()),
|
|
21
|
+
GeneratorIndex.SIGNATURE_PAYLOAD,
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
// docs:end:authwit_computeAuthWitMessageHash
|