@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
|
@@ -2,8 +2,9 @@ import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/circu
|
|
|
2
2
|
import { AztecAddress, Fr } from '@aztec/circuits.js';
|
|
3
3
|
import { ABIParameterVisibility, FunctionAbi, FunctionType } from '@aztec/foundation/abi';
|
|
4
4
|
|
|
5
|
-
import { AccountInterface
|
|
5
|
+
import { AccountInterface } from '../account/interface.js';
|
|
6
6
|
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
7
|
+
import { FeeOptions } from '../entrypoint/entrypoint.js';
|
|
7
8
|
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
9
|
import { BaseWallet } from './base_wallet.js';
|
|
9
10
|
|
|
@@ -19,6 +20,14 @@ export class AccountWallet extends BaseWallet {
|
|
|
19
20
|
return this.account.createTxExecutionRequest(execs, fee);
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
getChainId(): Fr {
|
|
24
|
+
return this.account.getChainId();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getVersion(): Fr {
|
|
28
|
+
return this.account.getVersion();
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
/**
|
|
23
32
|
* Computes an authentication witness from either a message or a caller and an action.
|
|
24
33
|
* If a message is provided, it will create a witness for the message directly.
|
|
@@ -35,6 +44,10 @@ export class AccountWallet extends BaseWallet {
|
|
|
35
44
|
caller: AztecAddress;
|
|
36
45
|
/** The action to approve */
|
|
37
46
|
action: ContractFunctionInteraction | FunctionCall;
|
|
47
|
+
/** The chain id to approve */
|
|
48
|
+
chainId?: Fr;
|
|
49
|
+
/** The version to approve */
|
|
50
|
+
version?: Fr;
|
|
38
51
|
},
|
|
39
52
|
): Promise<AuthWitness> {
|
|
40
53
|
const messageHash = this.getMessageHash(messageHashOrIntent);
|
|
@@ -43,6 +56,37 @@ export class AccountWallet extends BaseWallet {
|
|
|
43
56
|
return witness;
|
|
44
57
|
}
|
|
45
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Returns a function interaction to set a message hash as authorized or revoked in this account.
|
|
61
|
+
* Public calls can then consume this authorization.
|
|
62
|
+
* @param messageHashOrIntent - The message or the caller and action to authorize/revoke
|
|
63
|
+
* @param authorized - True to authorize, false to revoke authorization.
|
|
64
|
+
* @returns - A function interaction.
|
|
65
|
+
*/
|
|
66
|
+
public setPublicAuthWit(
|
|
67
|
+
messageHashOrIntent:
|
|
68
|
+
| Fr
|
|
69
|
+
| Buffer
|
|
70
|
+
| {
|
|
71
|
+
/** The caller to approve */
|
|
72
|
+
caller: AztecAddress;
|
|
73
|
+
/** The action to approve */
|
|
74
|
+
action: ContractFunctionInteraction | FunctionCall;
|
|
75
|
+
/** The chain id to approve */
|
|
76
|
+
chainId?: Fr;
|
|
77
|
+
/** The version to approve */
|
|
78
|
+
version?: Fr;
|
|
79
|
+
},
|
|
80
|
+
authorized: boolean,
|
|
81
|
+
): ContractFunctionInteraction {
|
|
82
|
+
const message = this.getMessageHash(messageHashOrIntent);
|
|
83
|
+
if (authorized) {
|
|
84
|
+
return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]);
|
|
85
|
+
} else {
|
|
86
|
+
return this.cancelAuthWit(message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
46
90
|
/**
|
|
47
91
|
* Returns the message hash for the given message or authwit input.
|
|
48
92
|
* @param messageHashOrIntent - The message hash or the caller and action to authorize
|
|
@@ -57,26 +101,37 @@ export class AccountWallet extends BaseWallet {
|
|
|
57
101
|
caller: AztecAddress;
|
|
58
102
|
/** The action to approve */
|
|
59
103
|
action: ContractFunctionInteraction | FunctionCall;
|
|
104
|
+
/** The chain id to approve */
|
|
105
|
+
chainId?: Fr;
|
|
106
|
+
/** The version to approve */
|
|
107
|
+
version?: Fr;
|
|
60
108
|
},
|
|
61
109
|
): Fr {
|
|
62
110
|
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
63
111
|
return Fr.fromBuffer(messageHashOrIntent);
|
|
64
112
|
} else if (messageHashOrIntent instanceof Fr) {
|
|
65
113
|
return messageHashOrIntent;
|
|
66
|
-
} else
|
|
67
|
-
return computeAuthWitMessageHash(
|
|
114
|
+
} else {
|
|
115
|
+
return computeAuthWitMessageHash(
|
|
116
|
+
messageHashOrIntent.caller,
|
|
117
|
+
messageHashOrIntent.chainId || this.getChainId(),
|
|
118
|
+
messageHashOrIntent.version || this.getVersion(),
|
|
119
|
+
messageHashOrIntent.action instanceof ContractFunctionInteraction
|
|
120
|
+
? messageHashOrIntent.action.request()
|
|
121
|
+
: messageHashOrIntent.action,
|
|
122
|
+
);
|
|
68
123
|
}
|
|
69
|
-
return computeAuthWitMessageHash(messageHashOrIntent.caller, messageHashOrIntent.action);
|
|
70
124
|
}
|
|
71
125
|
|
|
72
126
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @returns - A
|
|
127
|
+
* Lookup the validity of an authwit in private and public contexts.
|
|
128
|
+
* If the authwit have been consumed already (nullifier spent), will return false in both contexts.
|
|
129
|
+
* @param target - The target contract address
|
|
130
|
+
* @param messageHashOrIntent - The message hash or the caller and action to authorize/revoke
|
|
131
|
+
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
78
132
|
*/
|
|
79
|
-
|
|
133
|
+
async lookupValidity(
|
|
134
|
+
target: AztecAddress,
|
|
80
135
|
messageHashOrIntent:
|
|
81
136
|
| Fr
|
|
82
137
|
| Buffer
|
|
@@ -85,15 +140,29 @@ export class AccountWallet extends BaseWallet {
|
|
|
85
140
|
caller: AztecAddress;
|
|
86
141
|
/** The action to approve */
|
|
87
142
|
action: ContractFunctionInteraction | FunctionCall;
|
|
143
|
+
/** The chain id to approve */
|
|
144
|
+
chainId?: Fr;
|
|
145
|
+
/** The version to approve */
|
|
146
|
+
version?: Fr;
|
|
88
147
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
148
|
+
): Promise<{
|
|
149
|
+
/** boolean flag indicating if the authwit is valid in private context */
|
|
150
|
+
isValidInPrivate: boolean;
|
|
151
|
+
/** boolean flag indicating if the authwit is valid in public context */
|
|
152
|
+
isValidInPublic: boolean;
|
|
153
|
+
}> {
|
|
154
|
+
const messageHash = this.getMessageHash(messageHashOrIntent);
|
|
155
|
+
const witness = await this.getAuthWitness(messageHash);
|
|
156
|
+
const blockNumber = await this.getBlockNumber();
|
|
157
|
+
const interaction = new ContractFunctionInteraction(this, target, this.getLookupValidityAbi(), [
|
|
158
|
+
target,
|
|
159
|
+
blockNumber,
|
|
160
|
+
witness != undefined,
|
|
161
|
+
messageHash,
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
const [isValidInPrivate, isValidInPublic] = await interaction.view();
|
|
165
|
+
return { isValidInPrivate, isValidInPublic };
|
|
97
166
|
}
|
|
98
167
|
|
|
99
168
|
/**
|
|
@@ -110,6 +179,10 @@ export class AccountWallet extends BaseWallet {
|
|
|
110
179
|
caller: AztecAddress;
|
|
111
180
|
/** The action to approve */
|
|
112
181
|
action: ContractFunctionInteraction | FunctionCall;
|
|
182
|
+
/** The chain id to approve */
|
|
183
|
+
chainId?: Fr;
|
|
184
|
+
/** The version to approve */
|
|
185
|
+
version?: Fr;
|
|
113
186
|
},
|
|
114
187
|
): ContractFunctionInteraction {
|
|
115
188
|
const message = this.getMessageHash(messageHashOrIntent);
|
|
@@ -160,4 +233,36 @@ export class AccountWallet extends BaseWallet {
|
|
|
160
233
|
returnTypes: [],
|
|
161
234
|
};
|
|
162
235
|
}
|
|
236
|
+
|
|
237
|
+
private getLookupValidityAbi(): FunctionAbi {
|
|
238
|
+
return {
|
|
239
|
+
name: 'lookup_validity',
|
|
240
|
+
isInitializer: false,
|
|
241
|
+
functionType: FunctionType.UNCONSTRAINED,
|
|
242
|
+
isInternal: false,
|
|
243
|
+
parameters: [
|
|
244
|
+
{
|
|
245
|
+
name: 'myself',
|
|
246
|
+
type: {
|
|
247
|
+
kind: 'struct',
|
|
248
|
+
path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
|
|
249
|
+
fields: [{ name: 'inner', type: { kind: 'field' } }],
|
|
250
|
+
},
|
|
251
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: 'block_number',
|
|
255
|
+
type: { kind: 'integer', sign: 'unsigned', width: 32 },
|
|
256
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'check_private',
|
|
260
|
+
type: { kind: 'boolean' },
|
|
261
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
262
|
+
},
|
|
263
|
+
{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
|
|
264
|
+
],
|
|
265
|
+
returnTypes: [{ kind: 'array', length: 2, type: { kind: 'boolean' } }],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
163
268
|
}
|
|
@@ -19,9 +19,9 @@ import { ContractArtifact } from '@aztec/foundation/abi';
|
|
|
19
19
|
import { ContractClassWithId, ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
20
20
|
import { NodeInfo } from '@aztec/types/interfaces';
|
|
21
21
|
|
|
22
|
-
import { FeeOptions } from '../account/interface.js';
|
|
23
22
|
import { Wallet } from '../account/wallet.js';
|
|
24
23
|
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
24
|
+
import { FeeOptions } from '../entrypoint/entrypoint.js';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* A base class for Wallet implementations
|
|
@@ -31,6 +31,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
31
31
|
|
|
32
32
|
abstract getCompleteAddress(): CompleteAddress;
|
|
33
33
|
|
|
34
|
+
abstract getChainId(): Fr;
|
|
35
|
+
|
|
36
|
+
abstract getVersion(): Fr;
|
|
37
|
+
|
|
34
38
|
abstract createTxExecutionRequest(execs: FunctionCall[], fee?: FeeOptions): Promise<TxExecutionRequest>;
|
|
35
39
|
|
|
36
40
|
abstract createAuthWit(
|
|
@@ -42,6 +46,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
42
46
|
caller: AztecAddress;
|
|
43
47
|
/** The action to approve */
|
|
44
48
|
action: ContractFunctionInteraction | FunctionCall;
|
|
49
|
+
/** The chain id to approve */
|
|
50
|
+
chainId?: Fr;
|
|
51
|
+
/** The version to approve */
|
|
52
|
+
version?: Fr;
|
|
45
53
|
},
|
|
46
54
|
): Promise<AuthWitness>;
|
|
47
55
|
|
|
@@ -139,6 +147,9 @@ export abstract class BaseWallet implements Wallet {
|
|
|
139
147
|
addAuthWitness(authWitness: AuthWitness) {
|
|
140
148
|
return this.pxe.addAuthWitness(authWitness);
|
|
141
149
|
}
|
|
150
|
+
getAuthWitness(messageHash: Fr) {
|
|
151
|
+
return this.pxe.getAuthWitness(messageHash);
|
|
152
|
+
}
|
|
142
153
|
isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
143
154
|
return this.pxe.isContractClassPubliclyRegistered(id);
|
|
144
155
|
}
|
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
import { AuthWitness, FunctionCall,
|
|
2
|
-
import { CompleteAddress, Fr
|
|
1
|
+
import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
|
+
import { CompleteAddress, Fr } from '@aztec/circuits.js';
|
|
3
3
|
|
|
4
|
+
import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
|
|
5
|
+
import { EntrypointInterface } from '../entrypoint/entrypoint.js';
|
|
4
6
|
import { BaseWallet } from './base_wallet.js';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Wallet implementation which creates a transaction request directly to the requested contract without any signing.
|
|
8
10
|
*/
|
|
9
11
|
export class SignerlessWallet extends BaseWallet {
|
|
12
|
+
constructor(pxe: PXE, private entrypoint?: EntrypointInterface) {
|
|
13
|
+
super(pxe);
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
let entrypoint = this.entrypoint;
|
|
18
|
+
if (!entrypoint) {
|
|
19
|
+
const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
|
|
20
|
+
entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
[packedArguments],
|
|
25
|
-
[],
|
|
26
|
-
),
|
|
27
|
-
);
|
|
22
|
+
|
|
23
|
+
return entrypoint.createTxExecutionRequest(executions);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getChainId(): Fr {
|
|
27
|
+
throw new Error('Method not implemented.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getVersion(): Fr {
|
|
31
|
+
throw new Error('Method not implemented.');
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
getCompleteAddress(): CompleteAddress {
|
|
31
35
|
throw new Error('Method not implemented.');
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
createAuthWit(
|
|
38
|
+
createAuthWit(_messageHash: Fr): Promise<AuthWitness> {
|
|
35
39
|
throw new Error('Method not implemented.');
|
|
36
40
|
}
|
|
37
41
|
}
|