@aztec/aztec.js 0.7.3 → 0.7.4
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/.tsbuildinfo +1 -1
- package/dest/abis/ecdsa_account_contract.json +530 -11
- package/dest/abis/schnorr_account_contract.json +530 -11
- package/dest/abis/schnorr_single_key_account_contract.json +523 -24
- package/dest/account/contract/base_account_contract.d.ts +17 -0
- package/dest/account/contract/base_account_contract.d.ts.map +1 -0
- package/dest/account/contract/base_account_contract.js +17 -0
- package/dest/account/contract/ecdsa_account_contract.d.ts +6 -7
- package/dest/account/contract/ecdsa_account_contract.d.ts.map +1 -1
- package/dest/account/contract/ecdsa_account_contract.js +18 -9
- package/dest/account/contract/index.d.ts +11 -8
- package/dest/account/contract/index.d.ts.map +1 -1
- package/dest/account/contract/index.js +2 -2
- package/dest/account/contract/schnorr_account_contract.d.ts +7 -8
- package/dest/account/contract/schnorr_account_contract.d.ts.map +1 -1
- package/dest/account/contract/schnorr_account_contract.js +17 -9
- package/dest/account/contract/single_key_account_contract.d.ts +6 -8
- package/dest/account/contract/single_key_account_contract.d.ts.map +1 -1
- package/dest/account/contract/single_key_account_contract.js +26 -7
- package/dest/account/defaults/default_entrypoint.d.ts +17 -0
- package/dest/account/defaults/default_entrypoint.d.ts.map +1 -0
- package/dest/account/defaults/default_entrypoint.js +90 -0
- package/dest/account/defaults/default_interface.d.ts +17 -0
- package/dest/account/defaults/default_interface.d.ts.map +1 -0
- package/dest/account/defaults/default_interface.js +22 -0
- package/dest/account/defaults/entrypoint_payload.d.ts.map +1 -0
- package/dest/account/defaults/entrypoint_payload.js +48 -0
- package/dest/account/defaults/index.d.ts +4 -0
- package/dest/account/defaults/index.d.ts.map +1 -0
- package/dest/account/defaults/index.js +4 -0
- package/dest/account/index.d.ts +8 -8
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +11 -12
- package/dest/account/interface.d.ts +31 -0
- package/dest/account/interface.d.ts.map +1 -0
- package/dest/account/interface.js +3 -0
- package/dest/account/{deploy_account_sent_tx.d.ts → manager/deploy_account_sent_tx.d.ts} +1 -1
- package/dest/account/manager/deploy_account_sent_tx.d.ts.map +1 -0
- package/dest/account/{deploy_account_sent_tx.js → manager/deploy_account_sent_tx.js} +2 -2
- package/dest/account/{account.d.ts → manager/index.d.ts} +7 -6
- package/dest/account/manager/index.d.ts.map +1 -0
- package/dest/account/{account.js → manager/index.js} +7 -7
- package/dest/aztec_rpc_client.d.ts.map +1 -0
- package/dest/aztec_rpc_client.js +19 -0
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +1 -1
- package/dest/contract/contract.test.js +9 -3
- package/dest/contract/contract_base.d.ts +1 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +4 -4
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +1 -1
- package/dest/contract_deployer/deploy_method.d.ts.map +1 -1
- package/dest/contract_deployer/deploy_method.js +2 -1
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/main.js +1 -1
- package/dest/sandbox/index.d.ts +70 -14
- package/dest/sandbox/index.d.ts.map +1 -1
- package/dest/utils/account.d.ts +1 -1
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +1 -1
- package/dest/wallet/account_wallet.d.ts +29 -0
- package/dest/wallet/account_wallet.d.ts.map +1 -0
- package/dest/wallet/account_wallet.js +61 -0
- package/dest/wallet/base_wallet.d.ts +38 -0
- package/dest/wallet/base_wallet.d.ts.map +1 -0
- package/dest/wallet/base_wallet.js +78 -0
- package/dest/wallet/index.d.ts +9 -0
- package/dest/wallet/index.d.ts.map +1 -0
- package/dest/wallet/index.js +4 -0
- package/dest/wallet/signerless_wallet.d.ts +13 -0
- package/dest/wallet/signerless_wallet.d.ts.map +1 -0
- package/dest/wallet/signerless_wallet.js +26 -0
- package/package.json +4 -4
- package/src/abis/ecdsa_account_contract.json +530 -11
- package/src/abis/schnorr_account_contract.json +530 -11
- package/src/abis/schnorr_single_key_account_contract.json +523 -24
- package/src/account/contract/base_account_contract.ts +25 -0
- package/src/account/contract/ecdsa_account_contract.ts +21 -12
- package/src/account/contract/index.ts +13 -8
- package/src/account/contract/schnorr_account_contract.ts +20 -12
- package/src/account/contract/single_key_account_contract.ts +28 -12
- package/src/account/defaults/default_entrypoint.ts +95 -0
- package/src/account/defaults/default_interface.ts +36 -0
- package/src/account/defaults/index.ts +3 -0
- package/src/account/index.ts +14 -14
- package/src/account/interface.ts +35 -0
- package/src/account/{deploy_account_sent_tx.ts → manager/deploy_account_sent_tx.ts} +1 -1
- package/src/account/{account.ts → manager/index.ts} +8 -7
- package/src/{aztec_rpc_client/aztec_rpc_client.ts → aztec_rpc_client.ts} +2 -0
- package/src/contract/contract.test.ts +9 -3
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +1 -1
- package/src/contract/contract_function_interaction.ts +3 -3
- package/src/contract_deployer/deploy_method.ts +1 -0
- package/src/index.ts +2 -1
- package/src/utils/account.ts +1 -1
- package/src/wallet/account_wallet.ts +70 -0
- package/src/wallet/base_wallet.ts +103 -0
- package/src/wallet/index.ts +10 -0
- package/src/wallet/signerless_wallet.ts +39 -0
- package/dest/abis/schnorr_auth_witness_account_contract.json +0 -643
- package/dest/account/account.d.ts.map +0 -1
- package/dest/account/contract/auth_witness_account_contract.d.ts +0 -17
- package/dest/account/contract/auth_witness_account_contract.d.ts.map +0 -1
- package/dest/account/contract/auth_witness_account_contract.js +0 -23
- package/dest/account/deploy_account_sent_tx.d.ts.map +0 -1
- package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts +0 -74
- package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts.map +0 -1
- package/dest/account/entrypoint/auth_witness_account_entrypoint.js +0 -68
- package/dest/account/entrypoint/entrypoint_payload.d.ts.map +0 -1
- package/dest/account/entrypoint/entrypoint_payload.js +0 -48
- package/dest/account/entrypoint/entrypoint_utils.d.ts +0 -14
- package/dest/account/entrypoint/entrypoint_utils.d.ts.map +0 -1
- package/dest/account/entrypoint/entrypoint_utils.js +0 -24
- package/dest/account/entrypoint/index.d.ts +0 -20
- package/dest/account/entrypoint/index.d.ts.map +0 -1
- package/dest/account/entrypoint/index.js +0 -7
- package/dest/account/entrypoint/single_key_account_entrypoint.d.ts +0 -19
- package/dest/account/entrypoint/single_key_account_entrypoint.d.ts.map +0 -1
- package/dest/account/entrypoint/single_key_account_entrypoint.js +0 -50
- package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts +0 -20
- package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts.map +0 -1
- package/dest/account/entrypoint/stored_key_account_entrypoint.js +0 -47
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +0 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.js +0 -18
- package/dest/aztec_rpc_client/index.d.ts +0 -3
- package/dest/aztec_rpc_client/index.d.ts.map +0 -1
- package/dest/aztec_rpc_client/index.js +0 -3
- package/dest/aztec_rpc_client/wallet.d.ts +0 -109
- package/dest/aztec_rpc_client/wallet.d.ts.map +0 -1
- package/dest/aztec_rpc_client/wallet.js +0 -186
- package/src/abis/schnorr_auth_witness_account_contract.json +0 -643
- package/src/account/contract/auth_witness_account_contract.ts +0 -35
- package/src/account/entrypoint/auth_witness_account_entrypoint.ts +0 -125
- package/src/account/entrypoint/entrypoint_utils.ts +0 -31
- package/src/account/entrypoint/index.ts +0 -23
- package/src/account/entrypoint/single_key_account_entrypoint.ts +0 -55
- package/src/account/entrypoint/stored_key_account_entrypoint.ts +0 -56
- package/src/aztec_rpc_client/index.ts +0 -2
- package/src/aztec_rpc_client/wallet.ts +0 -219
- /package/dest/account/{entrypoint → defaults}/entrypoint_payload.d.ts +0 -0
- /package/dest/{aztec_rpc_client/aztec_rpc_client.d.ts → aztec_rpc_client.d.ts} +0 -0
- /package/src/account/{entrypoint → defaults}/entrypoint_payload.ts +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
2
|
-
import { ContractAbi } from '@aztec/foundation/abi';
|
|
3
|
-
import { CompleteAddress, GrumpkinPrivateKey, NodeInfo } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import AuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witness_account_contract.json' assert { type: 'json' };
|
|
6
|
-
import { AuthWitnessAccountEntrypoint } from '../entrypoint/auth_witness_account_entrypoint.js';
|
|
7
|
-
import { AccountContract } from './index.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Account contract that authenticates transactions using Schnorr signatures verified against
|
|
11
|
-
* the note encryption key, relying on a single private key for both encryption and authentication.
|
|
12
|
-
* Extended to pull verification data from the oracle instead of passed as arguments.
|
|
13
|
-
*/
|
|
14
|
-
export class AuthWitnessAccountContract implements AccountContract {
|
|
15
|
-
constructor(private encryptionPrivateKey: GrumpkinPrivateKey) {}
|
|
16
|
-
|
|
17
|
-
public getDeploymentArgs() {
|
|
18
|
-
return Promise.resolve([]);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async getEntrypoint({ address, partialAddress }: CompleteAddress, { chainId, version }: NodeInfo) {
|
|
22
|
-
return new AuthWitnessAccountEntrypoint(
|
|
23
|
-
address,
|
|
24
|
-
partialAddress,
|
|
25
|
-
this.encryptionPrivateKey,
|
|
26
|
-
await Schnorr.new(),
|
|
27
|
-
chainId,
|
|
28
|
-
version,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public getContractAbi(): ContractAbi {
|
|
33
|
-
return AuthWitnessAccountContractAbi as unknown as ContractAbi;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Fr, FunctionData, GrumpkinPrivateKey, PartialAddress, TxContext } from '@aztec/circuits.js';
|
|
2
|
-
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { ContractAbi, FunctionAbi, encodeArguments } from '@aztec/foundation/abi';
|
|
4
|
-
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
5
|
-
|
|
6
|
-
import SchnorrAuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witness_account_contract.json' assert { type: 'json' };
|
|
7
|
-
import { generatePublicKey } from '../../index.js';
|
|
8
|
-
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
|
-
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import { Entrypoint } from './index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* An extended interface for entrypoints that support signing and adding auth witnesses.
|
|
14
|
-
*/
|
|
15
|
-
export interface IAuthWitnessAccountEntrypoint extends Entrypoint {
|
|
16
|
-
/**
|
|
17
|
-
* Sign a message hash with the private key.
|
|
18
|
-
* @param message - The message hash to sign.
|
|
19
|
-
* @returns The signature as a Buffer.
|
|
20
|
-
*/
|
|
21
|
-
sign(message: Buffer): Buffer;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates an AuthWitness witness for the given message. In this case, witness is the public key, the signature
|
|
25
|
-
* and the partial address, to be used for verification.
|
|
26
|
-
* @param message - The message hash to sign.
|
|
27
|
-
* @param opts - Options.
|
|
28
|
-
* @returns [publicKey, signature, partialAddress] as Fr[].
|
|
29
|
-
*/
|
|
30
|
-
createAuthWitness(message: Buffer): Promise<Fr[]>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns the transaction request and the auth witness for the given function calls.
|
|
34
|
-
* Returning the witness here as a nonce is generated in the buildPayload action.
|
|
35
|
-
* @param executions - The function calls to execute
|
|
36
|
-
* @param opts - The options
|
|
37
|
-
* @returns The TxRequest, the auth witness to insert in db and the message signed
|
|
38
|
-
*/
|
|
39
|
-
createTxExecutionRequestWithWitness(executions: FunctionCall[]): Promise<{
|
|
40
|
-
/** The transaction request */
|
|
41
|
-
txRequest: TxExecutionRequest;
|
|
42
|
-
/** The auth witness */
|
|
43
|
-
witness: Fr[];
|
|
44
|
-
/** The message signed */
|
|
45
|
-
message: Buffer;
|
|
46
|
-
}>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Account contract implementation that uses a single key for signing and encryption. This public key is not
|
|
51
|
-
* stored in the contract, but rather verified against the contract address. Note that this approach is not
|
|
52
|
-
* secure and should not be used in real use cases.
|
|
53
|
-
* The entrypoint is extended to support signing and creating eip1271-like witnesses.
|
|
54
|
-
*/
|
|
55
|
-
export class AuthWitnessAccountEntrypoint implements IAuthWitnessAccountEntrypoint {
|
|
56
|
-
constructor(
|
|
57
|
-
private address: AztecAddress,
|
|
58
|
-
private partialAddress: PartialAddress,
|
|
59
|
-
private privateKey: GrumpkinPrivateKey,
|
|
60
|
-
private signer: Schnorr,
|
|
61
|
-
private chainId: number = DEFAULT_CHAIN_ID,
|
|
62
|
-
private version: number = DEFAULT_VERSION,
|
|
63
|
-
) {}
|
|
64
|
-
|
|
65
|
-
public sign(message: Buffer): Buffer {
|
|
66
|
-
return this.signer.constructSignature(message, this.privateKey).toBuffer();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async createAuthWitness(message: Buffer): Promise<Fr[]> {
|
|
70
|
-
const signature = this.sign(message);
|
|
71
|
-
const publicKey = await generatePublicKey(this.privateKey);
|
|
72
|
-
|
|
73
|
-
const sigFr: Fr[] = [];
|
|
74
|
-
for (let i = 0; i < 64; i++) {
|
|
75
|
-
sigFr.push(new Fr(signature[i]));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return [...publicKey.toFields(), ...sigFr, this.partialAddress];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns the transaction request and the auth witness for the given function calls.
|
|
83
|
-
* Returning the witness here as a nonce is generated in the buildPayload action.
|
|
84
|
-
* @param executions - The function calls to execute
|
|
85
|
-
* @param opts - The options
|
|
86
|
-
* @returns The TxRequest, the auth witness to insert in db and the message signed
|
|
87
|
-
*/
|
|
88
|
-
async createTxExecutionRequestWithWitness(executions: FunctionCall[]): Promise<{
|
|
89
|
-
/** The transaction request */
|
|
90
|
-
txRequest: TxExecutionRequest;
|
|
91
|
-
/** The auth witness */
|
|
92
|
-
witness: Fr[];
|
|
93
|
-
/** The message signed */
|
|
94
|
-
message: Buffer;
|
|
95
|
-
}> {
|
|
96
|
-
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
97
|
-
const message = await hashPayload(payload);
|
|
98
|
-
const witness = await this.createAuthWitness(message);
|
|
99
|
-
|
|
100
|
-
const args = [payload];
|
|
101
|
-
const abi = this.getEntrypointAbi();
|
|
102
|
-
const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, args));
|
|
103
|
-
const txRequest = TxExecutionRequest.from({
|
|
104
|
-
argsHash: packedArgs.hash,
|
|
105
|
-
origin: this.address,
|
|
106
|
-
functionData: FunctionData.fromAbi(abi),
|
|
107
|
-
txContext: TxContext.empty(this.chainId, this.version),
|
|
108
|
-
packedArguments: [...callsPackedArguments, packedArgs],
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return { txRequest, message, witness };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
createTxExecutionRequest(_executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
115
|
-
throw new Error(`Not implemented, use createTxExecutionRequestWithWitness instead`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private getEntrypointAbi(): FunctionAbi {
|
|
119
|
-
const abi = (SchnorrAuthWitnessAccountContractAbi as any as ContractAbi).functions.find(
|
|
120
|
-
f => f.name === 'entrypoint',
|
|
121
|
-
);
|
|
122
|
-
if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
|
|
123
|
-
return abi;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, FunctionData, TxContext } from '@aztec/circuits.js';
|
|
2
|
-
import { FunctionAbi, encodeArguments } from '@aztec/foundation/abi';
|
|
3
|
-
import { NodeInfo, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility for building a TxExecutionRequest in the context of an Entrypoint.
|
|
7
|
-
* @param origin - Address of the account contract sending this transaction.
|
|
8
|
-
* @param entrypointMethod - Initial method called in the account contract.
|
|
9
|
-
* @param args - Arguments used when calling this initial method.
|
|
10
|
-
* @param callsPackedArguments - Packed arguments of nested calls (if any).
|
|
11
|
-
* @param nodeInfo - Node info with chain id and version.
|
|
12
|
-
* @returns A TxExecutionRequest ready to be simulated, proven, and sent.
|
|
13
|
-
*/
|
|
14
|
-
export async function buildTxExecutionRequest(
|
|
15
|
-
origin: AztecAddress,
|
|
16
|
-
entrypointMethod: FunctionAbi,
|
|
17
|
-
args: any[],
|
|
18
|
-
callsPackedArguments: PackedArguments[],
|
|
19
|
-
nodeInfo: NodeInfo,
|
|
20
|
-
): Promise<TxExecutionRequest> {
|
|
21
|
-
const packedArgs = await PackedArguments.fromArgs(encodeArguments(entrypointMethod, args));
|
|
22
|
-
const { chainId, version } = nodeInfo;
|
|
23
|
-
|
|
24
|
-
return TxExecutionRequest.from({
|
|
25
|
-
argsHash: packedArgs.hash,
|
|
26
|
-
origin,
|
|
27
|
-
functionData: FunctionData.fromAbi(entrypointMethod),
|
|
28
|
-
txContext: TxContext.empty(chainId, version),
|
|
29
|
-
packedArguments: [...callsPackedArguments, packedArgs],
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
export * from './auth_witness_account_entrypoint.js';
|
|
4
|
-
export * from './entrypoint_payload.js';
|
|
5
|
-
export * from './entrypoint_utils.js';
|
|
6
|
-
export * from './single_key_account_entrypoint.js';
|
|
7
|
-
export * from './stored_key_account_entrypoint.js';
|
|
8
|
-
|
|
9
|
-
// docs:start:entrypoint-interface
|
|
10
|
-
/**
|
|
11
|
-
* Represents a transaction entrypoint in an account contract.
|
|
12
|
-
* Knows how to assemble a transaction execution request given a set of function calls.
|
|
13
|
-
*/
|
|
14
|
-
export interface Entrypoint {
|
|
15
|
-
/**
|
|
16
|
-
* Generates an authenticated request out of set of intents
|
|
17
|
-
* @param executions - The execution intents to be run.
|
|
18
|
-
* @param opts - Options.
|
|
19
|
-
* @returns The authenticated transaction execution request.
|
|
20
|
-
*/
|
|
21
|
-
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
22
|
-
}
|
|
23
|
-
// docs:end:entrypoint-interface
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, FunctionData, GrumpkinPrivateKey, PartialAddress, TxContext } from '@aztec/circuits.js';
|
|
2
|
-
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { ContractAbi, encodeArguments } from '@aztec/foundation/abi';
|
|
4
|
-
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
5
|
-
|
|
6
|
-
import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_account_contract.json' assert { type: 'json' };
|
|
7
|
-
import { generatePublicKey } from '../../index.js';
|
|
8
|
-
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
|
-
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import { Entrypoint } from './index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Account contract implementation that uses a single key for signing and encryption. This public key is not
|
|
14
|
-
* stored in the contract, but rather verified against the contract address. Note that this approach is not
|
|
15
|
-
* secure and should not be used in real use cases.
|
|
16
|
-
*/
|
|
17
|
-
export class SingleKeyAccountEntrypoint implements Entrypoint {
|
|
18
|
-
constructor(
|
|
19
|
-
private address: AztecAddress,
|
|
20
|
-
private partialAddress: PartialAddress,
|
|
21
|
-
private privateKey: GrumpkinPrivateKey,
|
|
22
|
-
private chainId: number = DEFAULT_CHAIN_ID,
|
|
23
|
-
private version: number = DEFAULT_VERSION,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
27
|
-
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
28
|
-
const message = await hashPayload(payload);
|
|
29
|
-
|
|
30
|
-
const signer = await Schnorr.new();
|
|
31
|
-
const signature = signer.constructSignature(message, this.privateKey).toBuffer();
|
|
32
|
-
const publicKey = await generatePublicKey(this.privateKey);
|
|
33
|
-
const args = [payload, publicKey.toBuffer(), signature, this.partialAddress];
|
|
34
|
-
const abi = this.getEntrypointAbi();
|
|
35
|
-
const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, args));
|
|
36
|
-
const txRequest = TxExecutionRequest.from({
|
|
37
|
-
argsHash: packedArgs.hash,
|
|
38
|
-
origin: this.address,
|
|
39
|
-
functionData: FunctionData.fromAbi(abi),
|
|
40
|
-
txContext: TxContext.empty(this.chainId, this.version),
|
|
41
|
-
packedArguments: [...callsPackedArguments, packedArgs],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return txRequest;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private getEntrypointAbi() {
|
|
48
|
-
// We use the SchnorrSingleKeyAccountContract because it implements the interface we need, but ideally
|
|
49
|
-
// we should have an interface that defines the entrypoint for SingleKeyAccountContracts and
|
|
50
|
-
// load the abi from it.
|
|
51
|
-
const abi = (SchnorrSingleKeyAccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
|
|
52
|
-
if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
|
|
53
|
-
return abi;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, FunctionData, TxContext } from '@aztec/circuits.js';
|
|
2
|
-
import { Signature } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { ContractAbi, encodeArguments } from '@aztec/foundation/abi';
|
|
4
|
-
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
6
|
-
|
|
7
|
-
import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' };
|
|
8
|
-
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
|
-
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import { Entrypoint } from './index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Account contract implementation that keeps a signing public key in storage, and is retrieved on
|
|
14
|
-
* every new request in order to validate the payload signature.
|
|
15
|
-
*/
|
|
16
|
-
export class StoredKeyAccountEntrypoint implements Entrypoint {
|
|
17
|
-
private log: DebugLogger;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
private address: AztecAddress,
|
|
21
|
-
private sign: (msg: Buffer) => Signature,
|
|
22
|
-
private chainId: number = DEFAULT_CHAIN_ID,
|
|
23
|
-
private version: number = DEFAULT_VERSION,
|
|
24
|
-
) {
|
|
25
|
-
this.log = createDebugLogger('aztec:client:accounts:stored_key');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
29
|
-
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
30
|
-
const message = await hashPayload(payload);
|
|
31
|
-
const signature = this.sign(message).toBuffer();
|
|
32
|
-
this.log(`Signed challenge ${message.toString('hex')} as ${signature.toString('hex')}`);
|
|
33
|
-
|
|
34
|
-
const args = [payload, signature];
|
|
35
|
-
const abi = this.getEntrypointAbi();
|
|
36
|
-
const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, args));
|
|
37
|
-
const txRequest = TxExecutionRequest.from({
|
|
38
|
-
argsHash: packedArgs.hash,
|
|
39
|
-
origin: this.address,
|
|
40
|
-
functionData: FunctionData.fromAbi(abi),
|
|
41
|
-
txContext: TxContext.empty(this.chainId, this.version),
|
|
42
|
-
packedArguments: [...callsPackedArguments, packedArgs],
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return txRequest;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private getEntrypointAbi() {
|
|
49
|
-
// We use the EcdsaAccountContractAbi because it implements the interface we need, but ideally
|
|
50
|
-
// we should have an interface that defines the entrypoint for StoredKeyAccountContracts and
|
|
51
|
-
// load the abi from it.
|
|
52
|
-
const abi = (EcdsaAccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
|
|
53
|
-
if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
|
|
54
|
-
return abi;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, CircuitsWasm, Fr, GrumpkinPrivateKey, PartialAddress, TxContext } from '@aztec/circuits.js';
|
|
2
|
-
import {
|
|
3
|
-
AztecRPC,
|
|
4
|
-
ContractData,
|
|
5
|
-
DeployedContract,
|
|
6
|
-
ExtendedContractData,
|
|
7
|
-
FunctionCall,
|
|
8
|
-
L2BlockL2Logs,
|
|
9
|
-
NodeInfo,
|
|
10
|
-
NotePreimage,
|
|
11
|
-
PackedArguments,
|
|
12
|
-
SyncStatus,
|
|
13
|
-
Tx,
|
|
14
|
-
TxExecutionRequest,
|
|
15
|
-
TxHash,
|
|
16
|
-
TxReceipt,
|
|
17
|
-
} from '@aztec/types';
|
|
18
|
-
|
|
19
|
-
import { Entrypoint, IAuthWitnessAccountEntrypoint } from '../account/entrypoint/index.js';
|
|
20
|
-
import { CompleteAddress } from '../index.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The wallet interface.
|
|
24
|
-
*/
|
|
25
|
-
export type Wallet = Entrypoint & AztecRPC;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A base class for Wallet implementations
|
|
29
|
-
*/
|
|
30
|
-
export abstract class BaseWallet implements Wallet {
|
|
31
|
-
constructor(protected readonly rpc: AztecRPC) {}
|
|
32
|
-
|
|
33
|
-
abstract createTxExecutionRequest(execs: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
34
|
-
|
|
35
|
-
registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise<void> {
|
|
36
|
-
return this.rpc.registerAccount(privKey, partialAddress);
|
|
37
|
-
}
|
|
38
|
-
registerRecipient(account: CompleteAddress): Promise<void> {
|
|
39
|
-
return this.rpc.registerRecipient(account);
|
|
40
|
-
}
|
|
41
|
-
getAccounts(): Promise<CompleteAddress[]> {
|
|
42
|
-
return this.rpc.getAccounts();
|
|
43
|
-
}
|
|
44
|
-
getAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
45
|
-
return this.rpc.getAccount(address);
|
|
46
|
-
}
|
|
47
|
-
getRecipients(): Promise<CompleteAddress[]> {
|
|
48
|
-
return this.rpc.getRecipients();
|
|
49
|
-
}
|
|
50
|
-
getRecipient(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
51
|
-
return this.rpc.getRecipient(address);
|
|
52
|
-
}
|
|
53
|
-
addContracts(contracts: DeployedContract[]): Promise<void> {
|
|
54
|
-
return this.rpc.addContracts(contracts);
|
|
55
|
-
}
|
|
56
|
-
getContracts(): Promise<AztecAddress[]> {
|
|
57
|
-
return this.rpc.getContracts();
|
|
58
|
-
}
|
|
59
|
-
simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean): Promise<Tx> {
|
|
60
|
-
return this.rpc.simulateTx(txRequest, simulatePublic);
|
|
61
|
-
}
|
|
62
|
-
sendTx(tx: Tx): Promise<TxHash> {
|
|
63
|
-
return this.rpc.sendTx(tx);
|
|
64
|
-
}
|
|
65
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
66
|
-
return this.rpc.getTxReceipt(txHash);
|
|
67
|
-
}
|
|
68
|
-
getPrivateStorageAt(owner: AztecAddress, contract: AztecAddress, storageSlot: Fr): Promise<NotePreimage[]> {
|
|
69
|
-
return this.rpc.getPrivateStorageAt(owner, contract, storageSlot);
|
|
70
|
-
}
|
|
71
|
-
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
|
|
72
|
-
return this.rpc.getPublicStorageAt(contract, storageSlot);
|
|
73
|
-
}
|
|
74
|
-
viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise<any> {
|
|
75
|
-
return this.rpc.viewTx(functionName, args, to, from);
|
|
76
|
-
}
|
|
77
|
-
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
|
|
78
|
-
return this.rpc.getExtendedContractData(contractAddress);
|
|
79
|
-
}
|
|
80
|
-
getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
|
|
81
|
-
return this.rpc.getContractData(contractAddress);
|
|
82
|
-
}
|
|
83
|
-
getUnencryptedLogs(from: number, limit: number): Promise<L2BlockL2Logs[]> {
|
|
84
|
-
return this.rpc.getUnencryptedLogs(from, limit);
|
|
85
|
-
}
|
|
86
|
-
getBlockNumber(): Promise<number> {
|
|
87
|
-
return this.rpc.getBlockNumber();
|
|
88
|
-
}
|
|
89
|
-
getNodeInfo(): Promise<NodeInfo> {
|
|
90
|
-
return this.rpc.getNodeInfo();
|
|
91
|
-
}
|
|
92
|
-
isGlobalStateSynchronised() {
|
|
93
|
-
return this.rpc.isGlobalStateSynchronised();
|
|
94
|
-
}
|
|
95
|
-
isAccountStateSynchronised(account: AztecAddress) {
|
|
96
|
-
return this.rpc.isAccountStateSynchronised(account);
|
|
97
|
-
}
|
|
98
|
-
getSyncStatus(): Promise<SyncStatus> {
|
|
99
|
-
return this.rpc.getSyncStatus();
|
|
100
|
-
}
|
|
101
|
-
addAuthWitness(messageHash: Fr, witness: Fr[]) {
|
|
102
|
-
return this.rpc.addAuthWitness(messageHash, witness);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* A simple wallet implementation that forwards authentication requests to a provided entrypoint implementation.
|
|
108
|
-
*/
|
|
109
|
-
export class EntrypointWallet extends BaseWallet {
|
|
110
|
-
constructor(rpc: AztecRPC, protected accountImpl: Entrypoint) {
|
|
111
|
-
super(rpc);
|
|
112
|
-
}
|
|
113
|
-
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
114
|
-
return this.accountImpl.createTxExecutionRequest(executions);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* A wallet implementation supporting auth witnesses.
|
|
120
|
-
* This wallet inserts eip1271-like witnesses into the RPC, which are then fetched using an oracle
|
|
121
|
-
* to provide authentication data to the contract during execution.
|
|
122
|
-
*/
|
|
123
|
-
export class AuthWitnessEntrypointWallet extends BaseWallet {
|
|
124
|
-
constructor(rpc: AztecRPC, protected accountImpl: IAuthWitnessAccountEntrypoint, protected address: CompleteAddress) {
|
|
125
|
-
super(rpc);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Create a transaction request and add the auth witness to the RPC.
|
|
130
|
-
* Note: When used in simulations, the witness that is inserted could be used later by attacker with
|
|
131
|
-
* access to the RPC.
|
|
132
|
-
* Meaning that if you were to use someone elses rpc with db you could send these transactions.
|
|
133
|
-
* For simulations it would be desirable to bypass such that no data is generated.
|
|
134
|
-
*
|
|
135
|
-
* @param executions - The function calls to execute.
|
|
136
|
-
* @param opts - The options.
|
|
137
|
-
* @returns - The TxRequest
|
|
138
|
-
*/
|
|
139
|
-
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
140
|
-
const { txRequest, message, witness } = await this.accountImpl.createTxExecutionRequestWithWitness(executions);
|
|
141
|
-
await this.rpc.addAuthWitness(Fr.fromBuffer(message), witness);
|
|
142
|
-
return txRequest;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
sign(messageHash: Buffer): Promise<Buffer> {
|
|
146
|
-
return Promise.resolve(this.accountImpl.sign(messageHash));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Signs the `messageHash` and adds the witness to the RPC.
|
|
151
|
-
* This is useful for signing messages that are not directly part of the transaction payload, such as
|
|
152
|
-
* approvals .
|
|
153
|
-
* @param messageHash - The message hash to sign
|
|
154
|
-
* @param opts - The options.
|
|
155
|
-
*/
|
|
156
|
-
async signAndAddAuthWitness(messageHash: Buffer): Promise<void> {
|
|
157
|
-
const witness = await this.accountImpl.createAuthWitness(messageHash);
|
|
158
|
-
await this.rpc.addAuthWitness(Fr.fromBuffer(messageHash), witness);
|
|
159
|
-
return Promise.resolve();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Signs the `messageHash` and adds the witness to the RPC.
|
|
164
|
-
* This is useful for signing messages that are not directly part of the transaction payload, such as
|
|
165
|
-
* approvals .
|
|
166
|
-
* @param messageHash - The message hash to sign
|
|
167
|
-
*/
|
|
168
|
-
async signAndGetAuthWitness(messageHash: Buffer): Promise<Fr[]> {
|
|
169
|
-
return await this.accountImpl.createAuthWitness(messageHash);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Returns the complete address of the account that implements this wallet. */
|
|
173
|
-
public getCompleteAddress() {
|
|
174
|
-
return this.address;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** Returns the address of the account that implements this wallet. */
|
|
178
|
-
public getAddress() {
|
|
179
|
-
return this.address.address;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* A wallet implementation that forwards authentication requests to a provided account.
|
|
185
|
-
*/
|
|
186
|
-
export class AccountWallet extends EntrypointWallet {
|
|
187
|
-
constructor(rpc: AztecRPC, protected accountImpl: Entrypoint, protected address: CompleteAddress) {
|
|
188
|
-
super(rpc, accountImpl);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** Returns the complete address of the account that implements this wallet. */
|
|
192
|
-
public getCompleteAddress() {
|
|
193
|
-
return this.address;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/** Returns the address of the account that implements this wallet. */
|
|
197
|
-
public getAddress() {
|
|
198
|
-
return this.address.address;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Wallet implementation which creates a transaction request directly to the requested contract without any signing.
|
|
204
|
-
*/
|
|
205
|
-
export class SignerlessWallet extends BaseWallet {
|
|
206
|
-
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
207
|
-
if (executions.length !== 1) {
|
|
208
|
-
throw new Error(`Unexpected number of executions. Expected 1, received ${executions.length})`);
|
|
209
|
-
}
|
|
210
|
-
const [execution] = executions;
|
|
211
|
-
const wasm = await CircuitsWasm.get();
|
|
212
|
-
const packedArguments = await PackedArguments.fromArgs(execution.args, wasm);
|
|
213
|
-
const { chainId, version } = await this.rpc.getNodeInfo();
|
|
214
|
-
const txContext = TxContext.empty(chainId, version);
|
|
215
|
-
return Promise.resolve(
|
|
216
|
-
new TxExecutionRequest(execution.to, execution.functionData, packedArguments.hash, txContext, [packedArguments]),
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|