@aztec/aztec.js 0.24.0 → 0.26.1
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/index.d.ts +4 -2
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +15 -6
- package/dest/api/fee.d.ts +2 -1
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/fee.js +3 -2
- package/dest/contract/base_contract_interaction.d.ts +5 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +1 -1
- package/dest/contract/batch_call.d.ts +3 -2
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +4 -3
- package/dest/contract/contract.d.ts +4 -2
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +7 -5
- package/dest/contract/contract_function_interaction.d.ts +2 -2
- 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 +37 -12
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +79 -35
- package/dest/contract/deploy_sent_tx.d.ts +3 -3
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +4 -7
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +10 -10
- package/dest/deployment/contract_deployer.d.ts +4 -3
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- package/dest/deployment/contract_deployer.js +5 -4
- package/dest/deployment/register_class.d.ts +1 -1
- package/dest/deployment/register_class.d.ts.map +1 -1
- package/dest/deployment/register_class.js +4 -3
- package/dest/fee/fee_payment_method.d.ts +1 -5
- package/dest/fee/fee_payment_method.d.ts.map +1 -1
- package/dest/fee/native_fee_payment_method.d.ts +3 -3
- package/dest/fee/native_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/native_fee_payment_method.js +5 -6
- package/dest/fee/{generic_fee_payment_method.d.ts → private_fee_payment_method.d.ts} +8 -14
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/private_fee_payment_method.js +62 -0
- package/dest/fee/public_fee_payment_method.d.ts +52 -0
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/public_fee_payment_method.js +62 -0
- package/dest/index.d.ts +4 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -4
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
- package/dest/rpc_clients/pxe_client.js +15 -15
- package/dest/utils/authwit.d.ts +30 -4
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +35 -5
- package/dest/utils/cheat_codes.js +2 -2
- package/dest/utils/index.d.ts +0 -1
- package/dest/utils/index.d.ts.map +1 -1
- package/dest/utils/index.js +1 -2
- package/dest/utils/l2_contracts.js +2 -2
- package/dest/wallet/account_wallet.d.ts +8 -1
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +32 -8
- package/dest/wallet/base_wallet.d.ts +5 -3
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +9 -3
- package/dest/wallet/signerless_wallet.js +2 -2
- package/package.json +7 -7
- package/src/account_manager/index.ts +20 -5
- package/src/api/fee.ts +2 -1
- package/src/contract/base_contract_interaction.ts +6 -0
- package/src/contract/batch_call.ts +4 -3
- package/src/contract/contract.ts +12 -4
- package/src/contract/contract_function_interaction.ts +3 -3
- package/src/contract/deploy_method.ts +105 -64
- package/src/contract/deploy_sent_tx.ts +4 -7
- package/src/contract/sent_tx.ts +9 -9
- package/src/deployment/contract_deployer.ts +15 -3
- package/src/deployment/register_class.ts +6 -2
- package/src/fee/fee_payment_method.ts +1 -6
- package/src/fee/native_fee_payment_method.ts +5 -6
- package/src/fee/{generic_fee_payment_method.ts → private_fee_payment_method.ts} +27 -29
- package/src/fee/public_fee_payment_method.ts +79 -0
- package/src/index.ts +8 -2
- package/src/rpc_clients/pxe_client.ts +15 -14
- package/src/utils/authwit.ts +45 -7
- package/src/utils/cheat_codes.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/l2_contracts.ts +1 -1
- package/src/wallet/account_wallet.ts +31 -7
- package/src/wallet/base_wallet.ts +10 -4
- package/src/wallet/signerless_wallet.ts +1 -1
- package/dest/fee/generic_fee_payment_method.d.ts.map +0 -1
- package/dest/fee/generic_fee_payment_method.js +0 -73
- package/dest/utils/secrets.d.ts +0 -8
- package/dest/utils/secrets.d.ts.map +0 -1
- package/dest/utils/secrets.js +0 -10
- package/src/utils/secrets.ts +0 -11
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
2
|
import { FunctionData } from '@aztec/circuits.js';
|
|
3
3
|
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token';
|
|
6
6
|
|
|
7
7
|
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
8
|
|
|
@@ -10,8 +10,7 @@ import { FeePaymentMethod } from './fee_payment_method.js';
|
|
|
10
10
|
* Pay fee directly in the native gas token.
|
|
11
11
|
*/
|
|
12
12
|
export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
13
|
-
|
|
14
|
-
static #GAS_TOKEN = AztecAddress.ZERO;
|
|
13
|
+
static #GAS_TOKEN = GasTokenAddress;
|
|
15
14
|
|
|
16
15
|
constructor() {}
|
|
17
16
|
|
|
@@ -44,8 +43,8 @@ export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
|
44
43
|
* @param feeLimit - The maximum fee to be paid in gas token.
|
|
45
44
|
* @returns A function call
|
|
46
45
|
*/
|
|
47
|
-
getFunctionCalls(feeLimit: Fr): FunctionCall[] {
|
|
48
|
-
return [
|
|
46
|
+
getFunctionCalls(feeLimit: Fr): Promise<FunctionCall[]> {
|
|
47
|
+
return Promise.resolve([
|
|
49
48
|
{
|
|
50
49
|
to: NativeFeePaymentMethod.#GAS_TOKEN,
|
|
51
50
|
functionData: new FunctionData(FunctionSelector.fromSignature('check_balance(Field)'), false, false, false),
|
|
@@ -56,6 +55,6 @@ export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
|
56
55
|
functionData: new FunctionData(FunctionSelector.fromSignature('pay_fee(Field)'), false, false, false),
|
|
57
56
|
args: [feeLimit],
|
|
58
57
|
},
|
|
59
|
-
];
|
|
58
|
+
]);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
@@ -4,12 +4,14 @@ import { FunctionSelector } from '@aztec/foundation/abi';
|
|
|
4
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
|
|
7
|
+
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
|
+
import { AccountWalletWithPrivateKey } from '../wallet/account_wallet_with_private_key.js';
|
|
7
9
|
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Holds information about how the fee for a transaction is to be paid.
|
|
11
13
|
*/
|
|
12
|
-
export class
|
|
14
|
+
export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
13
15
|
constructor(
|
|
14
16
|
/**
|
|
15
17
|
* The asset used to pay the fee.
|
|
@@ -19,10 +21,11 @@ export class GenericFeePaymentMethod implements FeePaymentMethod {
|
|
|
19
21
|
* Address which will hold the fee payment.
|
|
20
22
|
*/
|
|
21
23
|
private paymentContract: AztecAddress,
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
26
|
+
* An auth witness provider to authorize fee payments
|
|
24
27
|
*/
|
|
25
|
-
private
|
|
28
|
+
private wallet: AccountWalletWithPrivateKey,
|
|
26
29
|
) {}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -41,41 +44,36 @@ export class GenericFeePaymentMethod implements FeePaymentMethod {
|
|
|
41
44
|
return this.paymentContract;
|
|
42
45
|
}
|
|
43
46
|
|
|
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
47
|
/**
|
|
63
48
|
* Creates a function call to pay the fee in the given asset.
|
|
64
49
|
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
65
50
|
* @returns The function call to pay the fee.
|
|
66
51
|
*/
|
|
67
|
-
getFunctionCalls(maxFee: Fr): FunctionCall[] {
|
|
52
|
+
async getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
53
|
+
const nonce = Fr.random();
|
|
54
|
+
const messageHash = computeAuthWitMessageHash(this.paymentContract, {
|
|
55
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
56
|
+
functionData: new FunctionData(
|
|
57
|
+
FunctionSelector.fromSignature('unshield((Field),(Field),Field,Field)'),
|
|
58
|
+
false,
|
|
59
|
+
true,
|
|
60
|
+
false,
|
|
61
|
+
),
|
|
62
|
+
to: this.asset,
|
|
63
|
+
});
|
|
64
|
+
await this.wallet.createAuthWitness(messageHash);
|
|
65
|
+
|
|
68
66
|
return [
|
|
69
|
-
// TODO(fees) set up auth witnesses
|
|
70
67
|
{
|
|
71
68
|
to: this.getPaymentContract(),
|
|
72
|
-
functionData: new FunctionData(
|
|
73
|
-
|
|
69
|
+
functionData: new FunctionData(
|
|
70
|
+
FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field),Field)'),
|
|
71
|
+
false,
|
|
72
|
+
true,
|
|
73
|
+
false,
|
|
74
|
+
),
|
|
75
|
+
args: [maxFee, this.asset, nonce],
|
|
74
76
|
},
|
|
75
77
|
];
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
static empty(): GenericFeePaymentMethod {
|
|
79
|
-
return new GenericFeePaymentMethod(AztecAddress.ZERO, AztecAddress.ZERO, false);
|
|
80
|
-
}
|
|
81
79
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
|
+
import { AccountWallet } from '../wallet/account_wallet.js';
|
|
9
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
13
|
+
*/
|
|
14
|
+
export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
15
|
+
constructor(
|
|
16
|
+
/**
|
|
17
|
+
* The asset used to pay the fee.
|
|
18
|
+
*/
|
|
19
|
+
private asset: AztecAddress,
|
|
20
|
+
/**
|
|
21
|
+
* Address which will hold the fee payment.
|
|
22
|
+
*/
|
|
23
|
+
private paymentContract: AztecAddress,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An auth witness provider to authorize fee payments
|
|
27
|
+
*/
|
|
28
|
+
private wallet: AccountWallet,
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The asset used to pay the fee.
|
|
33
|
+
* @returns The asset used to pay the fee.
|
|
34
|
+
*/
|
|
35
|
+
getAsset() {
|
|
36
|
+
return this.asset;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The address which will facilitate the fee payment.
|
|
41
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
42
|
+
*/
|
|
43
|
+
getPaymentContract() {
|
|
44
|
+
return this.paymentContract;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a function call to pay the fee in the given asset.
|
|
49
|
+
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
50
|
+
* @returns The function call to pay the fee.
|
|
51
|
+
*/
|
|
52
|
+
getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
53
|
+
const nonce = Fr.random();
|
|
54
|
+
const messageHash = computeAuthWitMessageHash(this.paymentContract, {
|
|
55
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
56
|
+
functionData: new FunctionData(
|
|
57
|
+
FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
|
|
58
|
+
false,
|
|
59
|
+
false,
|
|
60
|
+
false,
|
|
61
|
+
),
|
|
62
|
+
to: this.asset,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return Promise.resolve([
|
|
66
|
+
this.wallet.setPublicAuth(messageHash, true).request(),
|
|
67
|
+
{
|
|
68
|
+
to: this.getPaymentContract(),
|
|
69
|
+
functionData: new FunctionData(
|
|
70
|
+
FunctionSelector.fromSignature('fee_entrypoint_public(Field,(Field),Field)'),
|
|
71
|
+
false,
|
|
72
|
+
true,
|
|
73
|
+
false,
|
|
74
|
+
),
|
|
75
|
+
args: [maxFee, this.asset, nonce],
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -37,7 +37,6 @@ export {
|
|
|
37
37
|
generatePublicKey,
|
|
38
38
|
FieldLike,
|
|
39
39
|
EthAddressLike,
|
|
40
|
-
computeMessageSecretHash,
|
|
41
40
|
CheatCodes,
|
|
42
41
|
AztecAddressLike,
|
|
43
42
|
FunctionSelectorLike,
|
|
@@ -45,6 +44,8 @@ export {
|
|
|
45
44
|
isContractDeployed,
|
|
46
45
|
EthCheatCodes,
|
|
47
46
|
computeAuthWitMessageHash,
|
|
47
|
+
computeInnerAuthWitHash,
|
|
48
|
+
computeOuterAuthWitHash,
|
|
48
49
|
waitForPXE,
|
|
49
50
|
waitForAccountSynch,
|
|
50
51
|
} from './utils/index.js';
|
|
@@ -70,13 +71,17 @@ export {
|
|
|
70
71
|
Point,
|
|
71
72
|
getContractInstanceFromDeployParams,
|
|
72
73
|
getContractClassFromArtifact,
|
|
74
|
+
INITIAL_L2_BLOCK_NUM,
|
|
73
75
|
} from '@aztec/circuits.js';
|
|
74
76
|
|
|
77
|
+
export { computeMessageSecretHash } from '@aztec/circuits.js/hash';
|
|
78
|
+
|
|
75
79
|
export { Grumpkin, Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
76
80
|
|
|
77
81
|
export {
|
|
78
82
|
AuthWitness,
|
|
79
83
|
AztecNode,
|
|
84
|
+
Body,
|
|
80
85
|
CompleteAddress,
|
|
81
86
|
ContractData,
|
|
82
87
|
DeployedContract,
|
|
@@ -84,7 +89,8 @@ export {
|
|
|
84
89
|
ExtendedNote,
|
|
85
90
|
FunctionCall,
|
|
86
91
|
GrumpkinPrivateKey,
|
|
87
|
-
|
|
92
|
+
L1ToL2Message,
|
|
93
|
+
L1Actor,
|
|
88
94
|
L2Actor,
|
|
89
95
|
L2Block,
|
|
90
96
|
L2BlockL2Logs,
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
ExtendedUnencryptedL2Log,
|
|
7
7
|
L2Block,
|
|
8
8
|
L2BlockL2Logs,
|
|
9
|
-
L2Tx,
|
|
10
9
|
LogId,
|
|
11
10
|
Note,
|
|
11
|
+
NullifierMembershipWitness,
|
|
12
12
|
PXE,
|
|
13
13
|
Tx,
|
|
14
|
+
TxEffect,
|
|
14
15
|
TxExecutionRequest,
|
|
15
16
|
TxHash,
|
|
16
17
|
TxReceipt,
|
|
@@ -32,30 +33,30 @@ import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/clien
|
|
|
32
33
|
* @param fetch - The fetch implementation to use.
|
|
33
34
|
* @returns A JSON-RPC client of PXE.
|
|
34
35
|
*/
|
|
35
|
-
export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3],
|
|
36
|
+
export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)): PXE =>
|
|
36
37
|
createJsonRpcClient<PXE>(
|
|
37
38
|
url,
|
|
38
39
|
{
|
|
39
|
-
|
|
40
|
-
FunctionSelector,
|
|
40
|
+
AuthWitness,
|
|
41
41
|
AztecAddress,
|
|
42
|
-
|
|
42
|
+
CompleteAddress,
|
|
43
43
|
ContractData,
|
|
44
|
+
FunctionSelector,
|
|
45
|
+
EthAddress,
|
|
44
46
|
ExtendedContractData,
|
|
47
|
+
ExtendedNote,
|
|
45
48
|
ExtendedUnencryptedL2Log,
|
|
46
|
-
TxHash,
|
|
47
|
-
EthAddress,
|
|
48
|
-
Point,
|
|
49
49
|
Fr,
|
|
50
50
|
GrumpkinScalar,
|
|
51
|
-
Note,
|
|
52
|
-
ExtendedNote,
|
|
53
|
-
AuthWitness,
|
|
54
|
-
L2Tx,
|
|
55
|
-
LogId,
|
|
56
51
|
L2Block,
|
|
52
|
+
TxEffect,
|
|
53
|
+
LogId,
|
|
54
|
+
Note,
|
|
55
|
+
Point,
|
|
56
|
+
TxExecutionRequest,
|
|
57
|
+
TxHash,
|
|
57
58
|
},
|
|
58
|
-
{ Tx, TxReceipt, L2BlockL2Logs },
|
|
59
|
+
{ Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness },
|
|
59
60
|
false,
|
|
60
61
|
'pxe',
|
|
61
62
|
fetch,
|
package/src/utils/authwit.ts
CHANGED
|
@@ -1,24 +1,62 @@
|
|
|
1
1
|
import { FunctionCall, PackedArguments } from '@aztec/circuit-types';
|
|
2
|
-
import { AztecAddress, GeneratorIndex } from '@aztec/circuits.js';
|
|
2
|
+
import { AztecAddress, Fr, GeneratorIndex } from '@aztec/circuits.js';
|
|
3
3
|
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
4
|
|
|
5
5
|
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
6
|
/**
|
|
7
7
|
* Compute an authentication witness message hash from a caller and a request
|
|
8
|
-
* H(
|
|
8
|
+
* H(target: AztecAddress, H(caller: AztecAddress, selector: Field, args_hash: Field))
|
|
9
|
+
* Example usage would be `bob` authenticating `alice` to perform a transfer of `10`
|
|
10
|
+
* tokens from his account to herself:
|
|
11
|
+
* H(token, H(alice, transfer_selector, H(bob, alice, 10, nonce)))
|
|
12
|
+
* `bob` then signs the message hash and gives it to `alice` who can then perform the
|
|
13
|
+
* action.
|
|
9
14
|
* @param caller - The caller approved to make the call
|
|
10
15
|
* @param request - The request to be made (function call)
|
|
11
16
|
* @returns The message hash for the witness
|
|
12
17
|
*/
|
|
13
18
|
export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => {
|
|
14
|
-
return
|
|
15
|
-
|
|
19
|
+
return computeOuterAuthWitHash(
|
|
20
|
+
request.to.toField(),
|
|
21
|
+
computeInnerAuthWitHash([
|
|
16
22
|
caller.toField(),
|
|
17
|
-
request.to.toField(),
|
|
18
23
|
request.functionData.selector.toField(),
|
|
19
24
|
PackedArguments.fromArgs(request.args).hash,
|
|
20
|
-
]
|
|
21
|
-
GeneratorIndex.SIGNATURE_PAYLOAD,
|
|
25
|
+
]),
|
|
22
26
|
);
|
|
23
27
|
};
|
|
24
28
|
// docs:end:authwit_computeAuthWitMessageHash
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compute the inner hash for an authentication witness.
|
|
32
|
+
* This is the "intent" of the message, before siloed with the consumer.
|
|
33
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
34
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
35
|
+
* @param args - The arguments to hash
|
|
36
|
+
* @returns The inner hash for the witness
|
|
37
|
+
*/
|
|
38
|
+
export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
39
|
+
return pedersenHash(
|
|
40
|
+
args.map(fr => fr.toBuffer()),
|
|
41
|
+
GeneratorIndex.AUTHWIT_INNER,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Compute the outer hash for an authentication witness.
|
|
47
|
+
* This is the value siloed with its "consumer" and what the `on_behalf_of`
|
|
48
|
+
* should be signing.
|
|
49
|
+
* The consumer is who will be consuming the message, for token approvals it
|
|
50
|
+
* is the token contract itself (because the token makes the call to check the approval).
|
|
51
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
52
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
53
|
+
* @param consumer - The address that can "consume" the authwit
|
|
54
|
+
* @param innerHash - The inner hash for the witness
|
|
55
|
+
* @returns The outer hash for the witness
|
|
56
|
+
*/
|
|
57
|
+
export const computeOuterAuthWitHash = (consumer: AztecAddress, innerHash: Fr) => {
|
|
58
|
+
return pedersenHash(
|
|
59
|
+
[consumer.toField(), innerHash].map(fr => fr.toBuffer()),
|
|
60
|
+
GeneratorIndex.AUTHWIT_OUTER,
|
|
61
|
+
);
|
|
62
|
+
};
|
package/src/utils/cheat_codes.ts
CHANGED
|
@@ -246,7 +246,7 @@ export class AztecCheatCodes {
|
|
|
246
246
|
public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr {
|
|
247
247
|
// Based on `at` function in
|
|
248
248
|
// aztec3-packages/aztec-nr/aztec/src/state_vars/map.nr
|
|
249
|
-
return
|
|
249
|
+
return pedersenHash([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()));
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
package/src/utils/index.ts
CHANGED
|
@@ -8,5 +8,5 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
8
8
|
* @returns A flag indicating whether the contract is deployed.
|
|
9
9
|
*/
|
|
10
10
|
export async function isContractDeployed(pxe: PXE, contractAddress: AztecAddress): Promise<boolean> {
|
|
11
|
-
return !!(await pxe.getContractData(contractAddress));
|
|
11
|
+
return !!(await pxe.getContractData(contractAddress)) || !!(await pxe.getContractInstance(contractAddress));
|
|
12
12
|
}
|
|
@@ -33,8 +33,21 @@ export class AccountWallet extends BaseWallet {
|
|
|
33
33
|
* @returns - A function interaction.
|
|
34
34
|
*/
|
|
35
35
|
public setPublicAuth(message: Fr | Buffer, authorized: boolean): ContractFunctionInteraction {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (authorized) {
|
|
37
|
+
return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]);
|
|
38
|
+
} else {
|
|
39
|
+
return this.cancelAuthWit(message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a function interaction to cancel a message hash as authorized in this account.
|
|
45
|
+
* @param message - Message hash to authorize.
|
|
46
|
+
* @returns - A function interaction.
|
|
47
|
+
*/
|
|
48
|
+
public cancelAuthWit(message: Fr | Buffer): ContractFunctionInteraction {
|
|
49
|
+
const args = [message];
|
|
50
|
+
return new ContractFunctionInteraction(this, this.getAddress(), this.getCancelAuthwitAbi(), args);
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
/** Returns the complete address of the account that implements this wallet. */
|
|
@@ -47,10 +60,10 @@ export class AccountWallet extends BaseWallet {
|
|
|
47
60
|
return this.getCompleteAddress().address;
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
private
|
|
63
|
+
private getApprovePublicAuthwitAbi(): FunctionAbi {
|
|
51
64
|
return {
|
|
52
|
-
name: '
|
|
53
|
-
functionType:
|
|
65
|
+
name: 'approve_public_authwit',
|
|
66
|
+
functionType: FunctionType.OPEN,
|
|
54
67
|
isInternal: true,
|
|
55
68
|
parameters: [
|
|
56
69
|
{
|
|
@@ -58,9 +71,20 @@ export class AccountWallet extends BaseWallet {
|
|
|
58
71
|
type: { kind: 'field' },
|
|
59
72
|
visibility: 'private' as ABIParameterVisibility,
|
|
60
73
|
},
|
|
74
|
+
],
|
|
75
|
+
returnTypes: [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private getCancelAuthwitAbi(): FunctionAbi {
|
|
80
|
+
return {
|
|
81
|
+
name: 'cancel_authwit',
|
|
82
|
+
functionType: FunctionType.SECRET,
|
|
83
|
+
isInternal: true,
|
|
84
|
+
parameters: [
|
|
61
85
|
{
|
|
62
|
-
name: '
|
|
63
|
-
type: { kind: '
|
|
86
|
+
name: 'message_hash',
|
|
87
|
+
type: { kind: 'field' },
|
|
64
88
|
visibility: 'private' as ABIParameterVisibility,
|
|
65
89
|
},
|
|
66
90
|
],
|
|
@@ -7,18 +7,18 @@ import {
|
|
|
7
7
|
FunctionCall,
|
|
8
8
|
GetUnencryptedLogsResponse,
|
|
9
9
|
L2Block,
|
|
10
|
-
L2Tx,
|
|
11
10
|
LogFilter,
|
|
12
11
|
NoteFilter,
|
|
13
12
|
PXE,
|
|
14
13
|
SyncStatus,
|
|
15
14
|
Tx,
|
|
15
|
+
TxEffect,
|
|
16
16
|
TxExecutionRequest,
|
|
17
17
|
TxHash,
|
|
18
18
|
TxReceipt,
|
|
19
19
|
} from '@aztec/circuit-types';
|
|
20
20
|
import { AztecAddress, CompleteAddress, Fr, GrumpkinPrivateKey, PartialAddress } from '@aztec/circuits.js';
|
|
21
|
-
import { ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
21
|
+
import { ContractClassWithId, ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
22
22
|
import { NodeInfo } from '@aztec/types/interfaces';
|
|
23
23
|
|
|
24
24
|
import { FeeOptions } from '../account/interface.js';
|
|
@@ -39,6 +39,9 @@ export abstract class BaseWallet implements Wallet {
|
|
|
39
39
|
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
40
40
|
return this.pxe.getContractInstance(address);
|
|
41
41
|
}
|
|
42
|
+
getContractClass(id: Fr): Promise<ContractClassWithId | undefined> {
|
|
43
|
+
return this.pxe.getContractClass(id);
|
|
44
|
+
}
|
|
42
45
|
addCapsule(capsule: Fr[]): Promise<void> {
|
|
43
46
|
return this.pxe.addCapsule(capsule);
|
|
44
47
|
}
|
|
@@ -72,8 +75,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
72
75
|
sendTx(tx: Tx): Promise<TxHash> {
|
|
73
76
|
return this.pxe.sendTx(tx);
|
|
74
77
|
}
|
|
75
|
-
|
|
76
|
-
return this.pxe.
|
|
78
|
+
getTxEffect(txHash: TxHash): Promise<TxEffect | undefined> {
|
|
79
|
+
return this.pxe.getTxEffect(txHash);
|
|
77
80
|
}
|
|
78
81
|
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
79
82
|
return this.pxe.getTxReceipt(txHash);
|
|
@@ -120,4 +123,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
120
123
|
addAuthWitness(authWitness: AuthWitness) {
|
|
121
124
|
return this.pxe.addAuthWitness(authWitness);
|
|
122
125
|
}
|
|
126
|
+
isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
127
|
+
return this.pxe.isContractClassPubliclyRegistered(id);
|
|
128
|
+
}
|
|
123
129
|
}
|
|
@@ -9,7 +9,7 @@ import { BaseWallet } from './base_wallet.js';
|
|
|
9
9
|
export class SignerlessWallet extends BaseWallet {
|
|
10
10
|
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
11
11
|
if (executions.length !== 1) {
|
|
12
|
-
throw new Error(`Unexpected number of executions. Expected 1 but received ${executions.length}
|
|
12
|
+
throw new Error(`Unexpected number of executions. Expected 1 but received ${executions.length}.`);
|
|
13
13
|
}
|
|
14
14
|
const [execution] = executions;
|
|
15
15
|
const packedArguments = PackedArguments.fromArgs(execution.args);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generic_fee_payment_method.d.ts","sourceRoot":"","sources":["../../src/fee/generic_fee_payment_method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;;IAE5D;;OAEG;IACH,OAAO,CAAC,KAAK;IACb;;OAEG;IACH,OAAO,CAAC,eAAe;IACvB;;OAEG;IACH,OAAO,CAAC,cAAc;;IAXtB;;OAEG;IACK,KAAK,EAAE,YAAY;IAC3B;;OAEG;IACK,eAAe,EAAE,YAAY;IACrC;;OAEG;IACK,cAAc,EAAE,OAAO;IAGjC;;;OAGG;IACH,QAAQ;IAIR;;;OAGG;IACH,kBAAkB;IAclB;;;OAGG;IACH,mBAAmB,IAAI,OAAO;IAI9B;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,EAAE,GAAG,YAAY,EAAE;IAW5C,MAAM,CAAC,KAAK,IAAI,uBAAuB;CAGxC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var _GenericFeePaymentMethod_instances, _GenericFeePaymentMethod_getFeePaymentEntrypoint;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
|
-
import { FunctionData } from '@aztec/circuits.js';
|
|
4
|
-
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
5
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
6
|
-
/**
|
|
7
|
-
* Holds information about how the fee for a transaction is to be paid.
|
|
8
|
-
*/
|
|
9
|
-
export class GenericFeePaymentMethod {
|
|
10
|
-
constructor(
|
|
11
|
-
/**
|
|
12
|
-
* The asset used to pay the fee.
|
|
13
|
-
*/
|
|
14
|
-
asset,
|
|
15
|
-
/**
|
|
16
|
-
* Address which will hold the fee payment.
|
|
17
|
-
*/
|
|
18
|
-
paymentContract,
|
|
19
|
-
/**
|
|
20
|
-
* Whether the fee payment is private
|
|
21
|
-
*/
|
|
22
|
-
privatePayment) {
|
|
23
|
-
_GenericFeePaymentMethod_instances.add(this);
|
|
24
|
-
this.asset = asset;
|
|
25
|
-
this.paymentContract = paymentContract;
|
|
26
|
-
this.privatePayment = privatePayment;
|
|
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
|
-
* The address which will facilitate the fee payment.
|
|
37
|
-
* @returns The contract address responsible for holding the fee payment.
|
|
38
|
-
*/
|
|
39
|
-
getPaymentContract() {
|
|
40
|
-
return this.paymentContract;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Whether the fee payment is private or not
|
|
44
|
-
* @returns Whether the fee payment is private or not
|
|
45
|
-
*/
|
|
46
|
-
isPrivateFeePayment() {
|
|
47
|
-
return this.privatePayment;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Creates a function call to pay the fee in the given asset.
|
|
51
|
-
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
52
|
-
* @returns The function call to pay the fee.
|
|
53
|
-
*/
|
|
54
|
-
getFunctionCalls(maxFee) {
|
|
55
|
-
return [
|
|
56
|
-
// TODO(fees) set up auth witnesses
|
|
57
|
-
{
|
|
58
|
-
to: this.getPaymentContract(),
|
|
59
|
-
functionData: new FunctionData(__classPrivateFieldGet(this, _GenericFeePaymentMethod_instances, "m", _GenericFeePaymentMethod_getFeePaymentEntrypoint).call(this), false, true, false),
|
|
60
|
-
args: [maxFee, this.asset],
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
static empty() {
|
|
65
|
-
return new GenericFeePaymentMethod(AztecAddress.ZERO, AztecAddress.ZERO, false);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
_GenericFeePaymentMethod_instances = new WeakSet(), _GenericFeePaymentMethod_getFeePaymentEntrypoint = function _GenericFeePaymentMethod_getFeePaymentEntrypoint() {
|
|
69
|
-
return this.privatePayment
|
|
70
|
-
? FunctionSelector.fromSignature('prepare_fee_private(Field, (Field))')
|
|
71
|
-
: FunctionSelector.fromSignature('prepare_fee_public(Field, (Field))');
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJpY19mZWVfcGF5bWVudF9tZXRob2QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmVlL2dlbmVyaWNfZmVlX3BheW1lbnRfbWV0aG9kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ2xELE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ3pELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUsvRDs7R0FFRztBQUNILE1BQU0sT0FBTyx1QkFBdUI7SUFDbEM7SUFDRTs7T0FFRztJQUNLLEtBQW1CO0lBQzNCOztPQUVHO0lBQ0ssZUFBNkI7SUFDckM7O09BRUc7SUFDSyxjQUF1Qjs7UUFSdkIsVUFBSyxHQUFMLEtBQUssQ0FBYztRQUluQixvQkFBZSxHQUFmLGVBQWUsQ0FBYztRQUk3QixtQkFBYyxHQUFkLGNBQWMsQ0FBUztJQUM5QixDQUFDO0lBRUo7OztPQUdHO0lBQ0gsUUFBUTtRQUNOLE9BQU8sSUFBSSxDQUFDLEtBQUssQ0FBQztJQUNwQixDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsa0JBQWtCO1FBQ2hCLE9BQU8sSUFBSSxDQUFDLGVBQWUsQ0FBQztJQUM5QixDQUFDO0lBWUQ7OztPQUdHO0lBQ0gsbUJBQW1CO1FBQ2pCLE9BQU8sSUFBSSxDQUFDLGNBQWMsQ0FBQztJQUM3QixDQUFDO0lBRUQ7Ozs7T0FJRztJQUNILGdCQUFnQixDQUFDLE1BQVU7UUFDekIsT0FBTztZQUNMLG1DQUFtQztZQUNuQztnQkFDRSxFQUFFLEVBQUUsSUFBSSxDQUFDLGtCQUFrQixFQUFFO2dCQUM3QixZQUFZLEVBQUUsSUFBSSxZQUFZLENBQUMsdUJBQUEsSUFBSSw0RkFBeUIsTUFBN0IsSUFBSSxDQUEyQixFQUFFLEtBQUssRUFBRSxJQUFJLEVBQUUsS0FBSyxDQUFDO2dCQUNuRixJQUFJLEVBQUUsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLEtBQUssQ0FBQzthQUMzQjtTQUNGLENBQUM7SUFDSixDQUFDO0lBRUQsTUFBTSxDQUFDLEtBQUs7UUFDVixPQUFPLElBQUksdUJBQXVCLENBQUMsWUFBWSxDQUFDLElBQUksRUFBRSxZQUFZLENBQUMsSUFBSSxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBQ2xGLENBQUM7Q0FDRjs7SUFoQ0csT0FBTyxJQUFJLENBQUMsY0FBYztRQUN4QixDQUFDLENBQUMsZ0JBQWdCLENBQUMsYUFBYSxDQUFDLHFDQUFxQyxDQUFDO1FBQ3ZFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxhQUFhLENBQUMsb0NBQW9DLENBQUMsQ0FBQztBQUMzRSxDQUFDIn0=
|
package/dest/utils/secrets.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/circuits.js';
|
|
2
|
-
/**
|
|
3
|
-
* Given a secret, it computes its pedersen hash - used to send l1 to l2 messages
|
|
4
|
-
* @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()`
|
|
5
|
-
* @returns the hash
|
|
6
|
-
*/
|
|
7
|
-
export declare function computeMessageSecretHash(secret: Fr): Fr;
|
|
8
|
-
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/utils/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAGxC;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,EAAE,MAElD"}
|
package/dest/utils/secrets.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';
|
|
2
|
-
/**
|
|
3
|
-
* Given a secret, it computes its pedersen hash - used to send l1 to l2 messages
|
|
4
|
-
* @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()`
|
|
5
|
-
* @returns the hash
|
|
6
|
-
*/
|
|
7
|
-
export function computeMessageSecretHash(secret) {
|
|
8
|
-
return computeSecretMessageHash(secret);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VjcmV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9zZWNyZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRW5FOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUsd0JBQXdCLENBQUMsTUFBVTtJQUNqRCxPQUFPLHdCQUF3QixDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQzFDLENBQUMifQ==
|
package/src/utils/secrets.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/circuits.js';
|
|
2
|
-
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Given a secret, it computes its pedersen hash - used to send l1 to l2 messages
|
|
6
|
-
* @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()`
|
|
7
|
-
* @returns the hash
|
|
8
|
-
*/
|
|
9
|
-
export function computeMessageSecretHash(secret: Fr) {
|
|
10
|
-
return computeSecretMessageHash(secret);
|
|
11
|
-
}
|