@aztec/aztec.js 0.30.1 → 0.32.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/README.md +1 -1
- package/dest/account/index.d.ts +1 -1
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/interface.d.ts +12 -21
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -1
- 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/entrypoint.d.ts +2 -0
- package/dest/api/entrypoint.d.ts.map +1 -0
- package/dest/api/entrypoint.js +2 -0
- package/dest/contract/base_contract_interaction.d.ts +1 -1
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/checker.js +2 -2
- package/dest/contract/deploy_method.d.ts +2 -2
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +4 -9
- package/dest/contract/sent_tx.d.ts +2 -0
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +3 -3
- package/dest/deployment/broadcast_function.d.ts.map +1 -1
- package/dest/deployment/broadcast_function.js +16 -31
- package/dest/entrypoint/default_entrypoint.d.ts +12 -0
- package/dest/entrypoint/default_entrypoint.d.ts.map +1 -0
- package/dest/entrypoint/default_entrypoint.js +18 -0
- package/dest/entrypoint/entrypoint.d.ts +23 -0
- package/dest/entrypoint/entrypoint.d.ts.map +1 -0
- package/dest/entrypoint/entrypoint.js +2 -0
- package/dest/fee/native_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/native_fee_payment_method.js +1 -6
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +2 -2
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -2
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
- package/dest/rpc_clients/pxe_client.js +3 -3
- package/dest/utils/authwit.d.ts +8 -4
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +12 -8
- package/dest/utils/cheat_codes.js +2 -2
- package/dest/wallet/account_wallet.d.ts +45 -7
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +75 -17
- package/dest/wallet/base_wallet.d.ts +8 -1
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +4 -1
- package/dest/wallet/signerless_wallet.d.ts +7 -2
- package/dest/wallet/signerless_wallet.d.ts.map +1 -1
- package/dest/wallet/signerless_wallet.js +18 -11
- package/package.json +8 -7
- package/src/account/index.ts +1 -1
- package/src/account/interface.ts +14 -23
- package/src/api/account.ts +1 -9
- package/src/api/entrypoint.ts +1 -0
- package/src/contract/base_contract_interaction.ts +1 -1
- package/src/contract/checker.ts +1 -1
- package/src/contract/deploy_method.ts +3 -9
- package/src/contract/sent_tx.ts +4 -2
- package/src/deployment/broadcast_function.ts +39 -47
- package/src/entrypoint/default_entrypoint.ts +27 -0
- package/src/entrypoint/entrypoint.ts +25 -0
- package/src/fee/native_fee_payment_method.ts +0 -5
- package/src/fee/private_fee_payment_method.ts +10 -5
- package/src/fee/public_fee_payment_method.ts +14 -8
- package/src/index.ts +2 -0
- package/src/rpc_clients/pxe_client.ts +3 -2
- package/src/utils/authwit.ts +12 -12
- package/src/utils/cheat_codes.ts +1 -1
- package/src/wallet/account_wallet.ts +123 -18
- package/src/wallet/base_wallet.ts +12 -1
- package/src/wallet/signerless_wallet.ts +23 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerless_wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/signerless_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"signerless_wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/signerless_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IACxB,OAAO,CAAC,UAAU,CAAC;gBAA7B,GAAG,EAAE,GAAG,EAAU,UAAU,CAAC,iCAAqB;IAIxD,wBAAwB,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUvF,UAAU,IAAI,EAAE;IAIhB,UAAU,IAAI,EAAE;IAIhB,kBAAkB,IAAI,eAAe;IAIrC,aAAa,CAAC,YAAY,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;CAGtD"}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TxContext } from '@aztec/circuits.js';
|
|
1
|
+
import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
|
|
3
2
|
import { BaseWallet } from './base_wallet.js';
|
|
4
3
|
/**
|
|
5
4
|
* Wallet implementation which creates a transaction request directly to the requested contract without any signing.
|
|
6
5
|
*/
|
|
7
6
|
export class SignerlessWallet extends BaseWallet {
|
|
7
|
+
constructor(pxe, entrypoint) {
|
|
8
|
+
super(pxe);
|
|
9
|
+
this.entrypoint = entrypoint;
|
|
10
|
+
}
|
|
8
11
|
async createTxExecutionRequest(executions) {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
let entrypoint = this.entrypoint;
|
|
13
|
+
if (!entrypoint) {
|
|
14
|
+
const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
|
|
15
|
+
entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
return entrypoint.createTxExecutionRequest(executions);
|
|
18
|
+
}
|
|
19
|
+
getChainId() {
|
|
20
|
+
throw new Error('Method not implemented.');
|
|
21
|
+
}
|
|
22
|
+
getVersion() {
|
|
23
|
+
throw new Error('Method not implemented.');
|
|
17
24
|
}
|
|
18
25
|
getCompleteAddress() {
|
|
19
26
|
throw new Error('Method not implemented.');
|
|
20
27
|
}
|
|
21
|
-
createAuthWit(
|
|
28
|
+
createAuthWit(_messageHash) {
|
|
22
29
|
throw new Error('Method not implemented.');
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2lnbmVybGVzc193YWxsZXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd2FsbGV0L3NpZ25lcmxlc3Nfd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHFDQUFxQyxDQUFDO0FBRXhFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUU5Qzs7R0FFRztBQUNILE1BQU0sT0FBTyxnQkFBaUIsU0FBUSxVQUFVO0lBQzlDLFlBQVksR0FBUSxFQUFVLFVBQWdDO1FBQzVELEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQztRQURpQixlQUFVLEdBQVYsVUFBVSxDQUFzQjtJQUU5RCxDQUFDO0lBRUQsS0FBSyxDQUFDLHdCQUF3QixDQUFDLFVBQTBCO1FBQ3ZELElBQUksVUFBVSxHQUFHLElBQUksQ0FBQyxVQUFVLENBQUM7UUFDakMsSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDO1lBQ2hCLE1BQU0sRUFBRSxPQUFPLEVBQUUsZUFBZSxFQUFFLEdBQUcsTUFBTSxJQUFJLENBQUMsR0FBRyxDQUFDLFdBQVcsRUFBRSxDQUFDO1lBQ2xFLFVBQVUsR0FBRyxJQUFJLGlCQUFpQixDQUFDLE9BQU8sRUFBRSxlQUFlLENBQUMsQ0FBQztRQUMvRCxDQUFDO1FBRUQsT0FBTyxVQUFVLENBQUMsd0JBQXdCLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDekQsQ0FBQztJQUVELFVBQVU7UUFDUixNQUFNLElBQUksS0FBSyxDQUFDLHlCQUF5QixDQUFDLENBQUM7SUFDN0MsQ0FBQztJQUVELFVBQVU7UUFDUixNQUFNLElBQUksS0FBSyxDQUFDLHlCQUF5QixDQUFDLENBQUM7SUFDN0MsQ0FBQztJQUVELGtCQUFrQjtRQUNoQixNQUFNLElBQUksS0FBSyxDQUFDLHlCQUF5QixDQUFDLENBQUM7SUFDN0MsQ0FBQztJQUVELGFBQWEsQ0FBQyxZQUFnQjtRQUM1QixNQUFNLElBQUksS0FBSyxDQUFDLHlCQUF5QixDQUFDLENBQUM7SUFDN0MsQ0FBQztDQUNGIn0=
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec.js",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dest/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"./account": "./dest/api/account.js",
|
|
11
11
|
"./aztec_address": "./dest/api/aztec_address.js",
|
|
12
12
|
"./deployment": "./dest/api/deployment.js",
|
|
13
|
+
"./entrypoint": "./dest/api/entrypoint.js",
|
|
13
14
|
"./eth_address": "./dest/api/eth_address.js",
|
|
14
15
|
"./ethereum": "./dest/api/ethereum.js",
|
|
15
16
|
"./fee": "./dest/api/fee.js",
|
|
@@ -49,12 +50,12 @@
|
|
|
49
50
|
"rootDir": "./src"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@aztec/circuit-types": "0.
|
|
53
|
-
"@aztec/circuits.js": "0.
|
|
54
|
-
"@aztec/ethereum": "0.
|
|
55
|
-
"@aztec/foundation": "0.
|
|
56
|
-
"@aztec/protocol-contracts": "0.
|
|
57
|
-
"@aztec/types": "0.
|
|
53
|
+
"@aztec/circuit-types": "0.32.0",
|
|
54
|
+
"@aztec/circuits.js": "0.32.0",
|
|
55
|
+
"@aztec/ethereum": "0.32.0",
|
|
56
|
+
"@aztec/foundation": "0.32.0",
|
|
57
|
+
"@aztec/protocol-contracts": "0.32.0",
|
|
58
|
+
"@aztec/types": "0.32.0",
|
|
58
59
|
"tslib": "^2.4.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
package/src/account/index.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { Fr } from '@aztec/circuits.js';
|
|
10
10
|
|
|
11
11
|
export { AccountContract } from './contract.js';
|
|
12
|
-
export { AccountInterface, AuthWitnessProvider
|
|
12
|
+
export { AccountInterface, AuthWitnessProvider } from './interface.js';
|
|
13
13
|
export * from './wallet.js';
|
|
14
14
|
|
|
15
15
|
/** A contract deployment salt. */
|
package/src/account/interface.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { AuthWitness, CompleteAddress, FunctionCall
|
|
1
|
+
import { AuthWitness, CompleteAddress, FunctionCall } from '@aztec/circuit-types';
|
|
2
2
|
import { AztecAddress } from '@aztec/circuits.js';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
|
|
5
5
|
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Fee payment options for a transaction.
|
|
10
|
-
*/
|
|
11
|
-
export type FeeOptions = {
|
|
12
|
-
/** The fee payment method to use */
|
|
13
|
-
paymentMethod: FeePaymentMethod;
|
|
14
|
-
/** The fee limit to pay */
|
|
15
|
-
maxFee: bigint | number | Fr;
|
|
16
|
-
};
|
|
6
|
+
import { EntrypointInterface } from '../entrypoint/entrypoint.js';
|
|
17
7
|
|
|
18
8
|
// docs:start:account-interface
|
|
19
9
|
/** Creates authorization witnesses. */
|
|
@@ -23,6 +13,8 @@ export interface AuthWitnessProvider {
|
|
|
23
13
|
* If a message hash is provided, it will create a witness for that directly.
|
|
24
14
|
* Otherwise, it will compute the message hash using the caller and the action of the intent.
|
|
25
15
|
* @param messageHashOrIntent - The message hash or the intent (caller and action) to approve
|
|
16
|
+
* @param chainId - The chain id for the message, will default to the current chain id
|
|
17
|
+
* @param version - The version for the message, will default to the current protocol version
|
|
26
18
|
* @returns The authentication witness
|
|
27
19
|
*/
|
|
28
20
|
createAuthWit(
|
|
@@ -34,21 +26,14 @@ export interface AuthWitnessProvider {
|
|
|
34
26
|
caller: AztecAddress;
|
|
35
27
|
/** The action to approve */
|
|
36
28
|
action: ContractFunctionInteraction | FunctionCall;
|
|
29
|
+
/** The chain id to approve */
|
|
30
|
+
chainId?: Fr;
|
|
31
|
+
/** The version to approve */
|
|
32
|
+
version?: Fr;
|
|
37
33
|
},
|
|
38
34
|
): Promise<AuthWitness>;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
/** Creates transaction execution requests out of a set of function calls. */
|
|
42
|
-
export interface EntrypointInterface {
|
|
43
|
-
/**
|
|
44
|
-
* Generates an authenticated request out of set of function calls.
|
|
45
|
-
* @param executions - The execution intents to be run.
|
|
46
|
-
* @param feeOpts - The fee to be paid for the transaction.
|
|
47
|
-
* @returns The authenticated transaction execution request.
|
|
48
|
-
*/
|
|
49
|
-
createTxExecutionRequest(executions: FunctionCall[], feeOpts?: FeeOptions): Promise<TxExecutionRequest>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
37
|
/**
|
|
53
38
|
* Handler for interfacing with an account. Knows how to create transaction execution
|
|
54
39
|
* requests and authorize actions for its corresponding account.
|
|
@@ -59,5 +44,11 @@ export interface AccountInterface extends AuthWitnessProvider, EntrypointInterfa
|
|
|
59
44
|
|
|
60
45
|
/** Returns the address for this account. */
|
|
61
46
|
getAddress(): AztecAddress;
|
|
47
|
+
|
|
48
|
+
/** Returns the chain id for this account */
|
|
49
|
+
getChainId(): Fr;
|
|
50
|
+
|
|
51
|
+
/** Returns the rollup version for this account */
|
|
52
|
+
getVersion(): Fr;
|
|
62
53
|
}
|
|
63
54
|
// docs:end:account-interface
|
package/src/api/account.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
AccountContract,
|
|
3
|
-
AccountInterface,
|
|
4
|
-
AuthWitnessProvider,
|
|
5
|
-
EntrypointInterface,
|
|
6
|
-
Salt,
|
|
7
|
-
Wallet,
|
|
8
|
-
FeeOptions,
|
|
9
|
-
} from '../account/index.js';
|
|
1
|
+
export { AccountContract, AccountInterface, AuthWitnessProvider, Salt, Wallet } from '../account/index.js';
|
|
10
2
|
|
|
11
3
|
export { AccountManager } from '../account_manager/index.js';
|
|
12
4
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../entrypoint/entrypoint.js';
|
package/src/contract/checker.ts
CHANGED
|
@@ -25,7 +25,7 @@ export function abiChecker(artifact: ContractArtifact) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// TODO: implement a better check for bytecode (right now only checks if it's > 0)
|
|
28
|
-
if (!('bytecode' in func &&
|
|
28
|
+
if (!('bytecode' in func && func.bytecode.length > 0)) {
|
|
29
29
|
throw new Error('ABI function parameter has incorrect bytecode');
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
getContractClassFromArtifact,
|
|
6
6
|
getContractInstanceFromDeployParams,
|
|
7
7
|
} from '@aztec/circuits.js';
|
|
8
|
-
import { ContractArtifact, FunctionArtifact,
|
|
8
|
+
import { ContractArtifact, FunctionArtifact, getInitializer } from '@aztec/foundation/abi';
|
|
9
9
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import { Fr } from '@aztec/foundation/fields';
|
|
11
11
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -63,16 +63,10 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
63
63
|
private artifact: ContractArtifact,
|
|
64
64
|
private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
|
|
65
65
|
private args: any[] = [],
|
|
66
|
-
|
|
66
|
+
constructorNameOrArtifact?: string | FunctionArtifact,
|
|
67
67
|
) {
|
|
68
68
|
super(wallet);
|
|
69
|
-
this.constructorArtifact =
|
|
70
|
-
? artifact.functions.find(f => f.name === constructorName)
|
|
71
|
-
: getDefaultInitializer(artifact);
|
|
72
|
-
|
|
73
|
-
if (constructorName && !this.constructorArtifact) {
|
|
74
|
-
throw new Error(`Constructor method ${constructorName} not found in contract artifact`);
|
|
75
|
-
}
|
|
69
|
+
this.constructorArtifact = getInitializer(artifact, constructorNameOrArtifact);
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
/**
|
package/src/contract/sent_tx.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type WaitOpts = {
|
|
|
15
15
|
waitForNotesSync?: boolean;
|
|
16
16
|
/** Whether to include information useful for debugging/testing in the receipt. */
|
|
17
17
|
debug?: boolean;
|
|
18
|
+
/** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
|
|
19
|
+
dontThrowOnRevert?: boolean;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const DefaultWaitOpts: WaitOpts = {
|
|
@@ -60,10 +62,10 @@ export class SentTx {
|
|
|
60
62
|
*/
|
|
61
63
|
public async wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>> {
|
|
62
64
|
if (opts?.debug && opts.waitForNotesSync === false) {
|
|
63
|
-
throw new Error('Cannot set
|
|
65
|
+
throw new Error('Cannot set debug to true if waitForNotesSync is false');
|
|
64
66
|
}
|
|
65
67
|
const receipt = await this.waitForReceipt(opts);
|
|
66
|
-
if (receipt.status
|
|
68
|
+
if (!(receipt.status === TxStatus.MINED || (receipt.status === TxStatus.REVERTED && opts?.dontThrowOnRevert))) {
|
|
67
69
|
throw new Error(
|
|
68
70
|
`Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
|
|
69
71
|
);
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
3
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
computeFunctionArtifactHash,
|
|
8
|
-
computePrivateFunctionsTree,
|
|
4
|
+
computeVerificationKeyHash,
|
|
5
|
+
createPrivateFunctionMembershipProof,
|
|
6
|
+
createUnconstrainedFunctionMembershipProof,
|
|
9
7
|
getContractClassFromArtifact,
|
|
10
8
|
} from '@aztec/circuits.js';
|
|
11
9
|
import { ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/foundation/abi';
|
|
@@ -31,42 +29,38 @@ export function broadcastPrivateFunction(
|
|
|
31
29
|
selector: FunctionSelector,
|
|
32
30
|
): ContractFunctionInteraction {
|
|
33
31
|
const contractClass = getContractClassFromArtifact(artifact);
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
32
|
+
const privateFunctionArtifact = artifact.functions.find(fn => selector.equals(fn));
|
|
33
|
+
if (!privateFunctionArtifact) {
|
|
36
34
|
throw new Error(`Private function with selector ${selector.toString()} not found`);
|
|
37
35
|
}
|
|
38
|
-
const privateFunctionArtifact = artifact.functions.find(fn =>
|
|
39
|
-
FunctionSelector.fromNameAndParameters(fn).equals(selector),
|
|
40
|
-
)!;
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const {
|
|
38
|
+
artifactTreeSiblingPath,
|
|
39
|
+
artifactTreeLeafIndex,
|
|
40
|
+
artifactMetadataHash,
|
|
41
|
+
functionMetadataHash,
|
|
42
|
+
unconstrainedFunctionsArtifactTreeRoot,
|
|
43
|
+
privateFunctionTreeSiblingPath,
|
|
44
|
+
privateFunctionTreeLeafIndex,
|
|
45
|
+
} = createPrivateFunctionMembershipProof(selector, artifact);
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
// The "private function tree" captures the selectors and verification keys, and is used in the kernel circuit for verifying the proof generated by the app circuit.
|
|
50
|
-
// The "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits.
|
|
51
|
-
const privateFunctionTreePath = computePrivateFunctionsTree(contractClass.privateFunctions).getSiblingPath(0);
|
|
52
|
-
const artifactFunctionTreePath = computeArtifactFunctionTree(artifact, FunctionType.SECRET)!.getSiblingPath(0);
|
|
53
|
-
|
|
54
|
-
const vkHash = privateFunction.vkHash;
|
|
55
|
-
const metadataHash = computeFunctionArtifactHash(privateFunctionArtifact);
|
|
47
|
+
const vkHash = computeVerificationKeyHash(privateFunctionArtifact.verificationKey!);
|
|
56
48
|
const bytecode = bufferAsFields(
|
|
57
|
-
|
|
49
|
+
privateFunctionArtifact.bytecode,
|
|
58
50
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
59
51
|
);
|
|
60
52
|
|
|
61
53
|
const registerer = getRegistererContract(wallet);
|
|
62
54
|
return registerer.methods.broadcast_private_function(
|
|
63
55
|
contractClass.id,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
artifactMetadataHash,
|
|
57
|
+
unconstrainedFunctionsArtifactTreeRoot,
|
|
58
|
+
privateFunctionTreeSiblingPath,
|
|
59
|
+
privateFunctionTreeLeafIndex,
|
|
60
|
+
padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
|
|
61
|
+
artifactTreeLeafIndex,
|
|
68
62
|
// eslint-disable-next-line camelcase
|
|
69
|
-
{ selector, metadata_hash:
|
|
63
|
+
{ selector, metadata_hash: functionMetadataHash, bytecode, vk_hash: vkHash },
|
|
70
64
|
);
|
|
71
65
|
}
|
|
72
66
|
|
|
@@ -84,35 +78,33 @@ export function broadcastUnconstrainedFunction(
|
|
|
84
78
|
artifact: ContractArtifact,
|
|
85
79
|
selector: FunctionSelector,
|
|
86
80
|
): ContractFunctionInteraction {
|
|
81
|
+
const contractClass = getContractClassFromArtifact(artifact);
|
|
87
82
|
const functionArtifactIndex = artifact.functions.findIndex(
|
|
88
|
-
fn => fn.functionType === FunctionType.UNCONSTRAINED &&
|
|
83
|
+
fn => fn.functionType === FunctionType.UNCONSTRAINED && selector.equals(fn),
|
|
89
84
|
);
|
|
90
85
|
if (functionArtifactIndex < 0) {
|
|
91
86
|
throw new Error(`Unconstrained function with selector ${selector.toString()} not found`);
|
|
92
87
|
}
|
|
93
88
|
const functionArtifact = artifact.functions[functionArtifactIndex];
|
|
94
89
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
const {
|
|
91
|
+
artifactMetadataHash,
|
|
92
|
+
artifactTreeLeafIndex,
|
|
93
|
+
artifactTreeSiblingPath,
|
|
94
|
+
functionMetadataHash,
|
|
95
|
+
privateFunctionsArtifactTreeRoot,
|
|
96
|
+
} = createUnconstrainedFunctionMembershipProof(selector, artifact);
|
|
101
97
|
|
|
102
|
-
const
|
|
103
|
-
const metadataHash = computeFunctionArtifactHash(functionArtifact);
|
|
104
|
-
const bytecode = bufferAsFields(
|
|
105
|
-
Buffer.from(functionArtifact.bytecode, 'hex'),
|
|
106
|
-
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
107
|
-
);
|
|
98
|
+
const bytecode = bufferAsFields(functionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS);
|
|
108
99
|
|
|
109
100
|
const registerer = getRegistererContract(wallet);
|
|
110
101
|
return registerer.methods.broadcast_unconstrained_function(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
padArrayEnd(
|
|
102
|
+
contractClass.id,
|
|
103
|
+
artifactMetadataHash,
|
|
104
|
+
privateFunctionsArtifactTreeRoot,
|
|
105
|
+
padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
|
|
106
|
+
artifactTreeLeafIndex,
|
|
115
107
|
// eslint-disable-next-line camelcase
|
|
116
|
-
{ selector, metadata_hash:
|
|
108
|
+
{ selector, metadata_hash: functionMetadataHash, bytecode },
|
|
117
109
|
);
|
|
118
110
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
|
+
import { TxContext } from '@aztec/circuits.js';
|
|
3
|
+
|
|
4
|
+
import { EntrypointInterface } from './entrypoint.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Default implementation of the entrypoint interface. It calls a function on a contract directly
|
|
8
|
+
*/
|
|
9
|
+
export class DefaultEntrypoint implements EntrypointInterface {
|
|
10
|
+
constructor(private chainId: number, private protocolVersion: number) {}
|
|
11
|
+
|
|
12
|
+
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
13
|
+
const [execution] = executions;
|
|
14
|
+
const packedArguments = PackedArguments.fromArgs(execution.args);
|
|
15
|
+
const txContext = TxContext.empty(this.chainId, this.protocolVersion);
|
|
16
|
+
return Promise.resolve(
|
|
17
|
+
new TxExecutionRequest(
|
|
18
|
+
execution.to,
|
|
19
|
+
execution.functionData,
|
|
20
|
+
packedArguments.hash,
|
|
21
|
+
txContext,
|
|
22
|
+
[packedArguments],
|
|
23
|
+
[],
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FunctionCall, TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
|
|
4
|
+
import { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fee payment options for a transaction.
|
|
8
|
+
*/
|
|
9
|
+
export type FeeOptions = {
|
|
10
|
+
/** The fee payment method to use */
|
|
11
|
+
paymentMethod: FeePaymentMethod;
|
|
12
|
+
/** The fee limit to pay */
|
|
13
|
+
maxFee: bigint | number | Fr;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Creates transaction execution requests out of a set of function calls. */
|
|
17
|
+
export interface EntrypointInterface {
|
|
18
|
+
/**
|
|
19
|
+
* Generates an execution request out of set of function calls.
|
|
20
|
+
* @param executions - The execution intents to be run.
|
|
21
|
+
* @param feeOpts - The fee to be paid for the transaction.
|
|
22
|
+
* @returns The authenticated transaction execution request.
|
|
23
|
+
*/
|
|
24
|
+
createTxExecutionRequest(executions: FunctionCall[], feeOpts?: FeeOptions): Promise<TxExecutionRequest>;
|
|
25
|
+
}
|
|
@@ -53,11 +53,6 @@ export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
|
53
53
|
*/
|
|
54
54
|
getFunctionCalls(feeLimit: Fr): Promise<FunctionCall[]> {
|
|
55
55
|
return Promise.resolve([
|
|
56
|
-
{
|
|
57
|
-
to: this.#gasTokenAddress,
|
|
58
|
-
functionData: new FunctionData(FunctionSelector.fromSignature('check_balance(Field)'), false),
|
|
59
|
-
args: [feeLimit],
|
|
60
|
-
},
|
|
61
56
|
{
|
|
62
57
|
to: this.#gasTokenAddress,
|
|
63
58
|
functionData: new FunctionData(FunctionSelector.fromSignature('pay_fee(Field)'), false),
|
|
@@ -58,11 +58,16 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
58
58
|
*/
|
|
59
59
|
async getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
60
60
|
const nonce = Fr.random();
|
|
61
|
-
const messageHash = computeAuthWitMessageHash(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
const messageHash = computeAuthWitMessageHash(
|
|
62
|
+
this.paymentContract,
|
|
63
|
+
this.wallet.getChainId(),
|
|
64
|
+
this.wallet.getVersion(),
|
|
65
|
+
{
|
|
66
|
+
args: [this.wallet.getCompleteAddress().address, this.paymentContract, maxFee, nonce],
|
|
67
|
+
functionData: new FunctionData(FunctionSelector.fromSignature('unshield((Field),(Field),Field,Field)'), true),
|
|
68
|
+
to: this.asset,
|
|
69
|
+
},
|
|
70
|
+
);
|
|
66
71
|
await this.wallet.createAuthWit(messageHash);
|
|
67
72
|
|
|
68
73
|
const secretHashForRebate = computeMessageSecretHash(this.rebateSecret);
|
|
@@ -51,14 +51,20 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
51
51
|
*/
|
|
52
52
|
getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
53
53
|
const nonce = Fr.random();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
|
|
55
|
+
const messageHash = computeAuthWitMessageHash(
|
|
56
|
+
this.paymentContract,
|
|
57
|
+
this.wallet.getChainId(),
|
|
58
|
+
this.wallet.getVersion(),
|
|
59
|
+
{
|
|
60
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
61
|
+
functionData: new FunctionData(
|
|
62
|
+
FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
|
|
63
|
+
false,
|
|
64
|
+
),
|
|
65
|
+
to: this.asset,
|
|
66
|
+
},
|
|
67
|
+
);
|
|
62
68
|
|
|
63
69
|
return Promise.resolve([
|
|
64
70
|
this.wallet.setPublicAuthWit(messageHash, true).request(),
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
|
+
EncryptedL2BlockL2Logs,
|
|
3
4
|
ExtendedNote,
|
|
4
5
|
ExtendedUnencryptedL2Log,
|
|
5
6
|
L2Block,
|
|
6
|
-
L2BlockL2Logs,
|
|
7
7
|
LogId,
|
|
8
8
|
Note,
|
|
9
9
|
NullifierMembershipWitness,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
TxExecutionRequest,
|
|
14
14
|
TxHash,
|
|
15
15
|
TxReceipt,
|
|
16
|
+
UnencryptedL2BlockL2Logs,
|
|
16
17
|
} from '@aztec/circuit-types';
|
|
17
18
|
import {
|
|
18
19
|
AztecAddress,
|
|
@@ -52,7 +53,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)
|
|
|
52
53
|
TxExecutionRequest,
|
|
53
54
|
TxHash,
|
|
54
55
|
},
|
|
55
|
-
{ Tx, TxReceipt,
|
|
56
|
+
{ Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
|
|
56
57
|
false,
|
|
57
58
|
'pxe',
|
|
58
59
|
fetch,
|
package/src/utils/authwit.ts
CHANGED
|
@@ -5,19 +5,23 @@ import { pedersenHash } from '@aztec/foundation/crypto';
|
|
|
5
5
|
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
6
|
/**
|
|
7
7
|
* Compute an authentication witness message hash from a caller and a request
|
|
8
|
-
* H(target: AztecAddress, H(caller: AztecAddress, selector: Field, args_hash: Field))
|
|
8
|
+
* H(target: AztecAddress, chainId: Field, version: Field, H(caller: AztecAddress, selector: Field, args_hash: Field))
|
|
9
9
|
* Example usage would be `bob` authenticating `alice` to perform a transfer of `10`
|
|
10
10
|
* tokens from his account to herself:
|
|
11
|
-
* H(token, H(alice, transfer_selector, H(bob, alice, 10, nonce)))
|
|
11
|
+
* H(token, 1, 1, H(alice, transfer_selector, H(bob, alice, 10, nonce)))
|
|
12
12
|
* `bob` then signs the message hash and gives it to `alice` who can then perform the
|
|
13
13
|
* action.
|
|
14
14
|
* @param caller - The caller approved to make the call
|
|
15
|
+
* @param chainId - The chain id for the message
|
|
16
|
+
* @param version - The version for the message
|
|
15
17
|
* @param action - The request to be made (function call)
|
|
16
18
|
* @returns The message hash for the witness
|
|
17
19
|
*/
|
|
18
|
-
export const computeAuthWitMessageHash = (caller: AztecAddress, action: FunctionCall) => {
|
|
20
|
+
export const computeAuthWitMessageHash = (caller: AztecAddress, chainId: Fr, version: Fr, action: FunctionCall) => {
|
|
19
21
|
return computeOuterAuthWitHash(
|
|
20
22
|
action.to.toField(),
|
|
23
|
+
chainId,
|
|
24
|
+
version,
|
|
21
25
|
computeInnerAuthWitHash([
|
|
22
26
|
caller.toField(),
|
|
23
27
|
action.functionData.selector.toField(),
|
|
@@ -36,10 +40,7 @@ export const computeAuthWitMessageHash = (caller: AztecAddress, action: Function
|
|
|
36
40
|
* @returns The inner hash for the witness
|
|
37
41
|
*/
|
|
38
42
|
export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
39
|
-
return pedersenHash(
|
|
40
|
-
args.map(fr => fr.toBuffer()),
|
|
41
|
-
GeneratorIndex.AUTHWIT_INNER,
|
|
42
|
-
);
|
|
43
|
+
return pedersenHash(args, GeneratorIndex.AUTHWIT_INNER);
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -51,12 +52,11 @@ export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
|
51
52
|
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
52
53
|
* in case the message is not a "call" to a function, but arbitrary data.
|
|
53
54
|
* @param consumer - The address that can "consume" the authwit
|
|
55
|
+
* @param chainId - The chain id that can "consume" the authwit
|
|
56
|
+
* @param version - The version that can "consume" the authwit
|
|
54
57
|
* @param innerHash - The inner hash for the witness
|
|
55
58
|
* @returns The outer hash for the witness
|
|
56
59
|
*/
|
|
57
|
-
export const computeOuterAuthWitHash = (consumer: AztecAddress, innerHash: Fr) => {
|
|
58
|
-
return pedersenHash(
|
|
59
|
-
[consumer.toField(), innerHash].map(fr => fr.toBuffer()),
|
|
60
|
-
GeneratorIndex.AUTHWIT_OUTER,
|
|
61
|
-
);
|
|
60
|
+
export const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
|
|
61
|
+
return pedersenHash([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER);
|
|
62
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 pedersenHash([new Fr(baseSlot), new Fr(key)]
|
|
249
|
+
return pedersenHash([new Fr(baseSlot), new Fr(key)]);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|