@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ContractAbi } from '@aztec/foundation/abi';
|
|
2
|
+
import { CompleteAddress, NodeInfo } from '@aztec/types';
|
|
3
|
+
|
|
4
|
+
import { DefaultAccountInterface } from '../defaults/default_interface.js';
|
|
5
|
+
import { AccountInterface, AuthWitnessProvider } from '../interface.js';
|
|
6
|
+
import { AccountContract } from './index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base class for implementing an account contract. Requires that the account uses the
|
|
10
|
+
* default entrypoint method signature.
|
|
11
|
+
*/
|
|
12
|
+
export abstract class BaseAccountContract implements AccountContract {
|
|
13
|
+
abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
|
|
14
|
+
abstract getDeploymentArgs(): Promise<any[]>;
|
|
15
|
+
|
|
16
|
+
constructor(private abi: ContractAbi) {}
|
|
17
|
+
|
|
18
|
+
getContractAbi(): ContractAbi {
|
|
19
|
+
return this.abi;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getInterface(address: CompleteAddress, nodeInfo: NodeInfo): Promise<AccountInterface> {
|
|
23
|
+
return Promise.resolve(new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, nodeInfo));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,29 +1,38 @@
|
|
|
1
|
+
import { Fr } from '@aztec/circuits.js';
|
|
1
2
|
import { Ecdsa } from '@aztec/circuits.js/barretenberg';
|
|
2
3
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
3
|
-
import {
|
|
4
|
+
import { AuthWitness, CompleteAddress } from '@aztec/types';
|
|
4
5
|
|
|
5
6
|
import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' };
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { AuthWitnessProvider } from '../interface.js';
|
|
8
|
+
import { BaseAccountContract } from './base_account_contract.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Account contract that authenticates transactions using ECDSA signatures
|
|
11
12
|
* verified against a secp256k1 public key stored in an immutable encrypted note.
|
|
12
|
-
*/
|
|
13
|
-
|
|
13
|
+
*/
|
|
14
|
+
export class EcdsaAccountContract extends BaseAccountContract {
|
|
15
|
+
constructor(private signingPrivateKey: Buffer) {
|
|
16
|
+
super(EcdsaAccountContractAbi as unknown as ContractAbi);
|
|
17
|
+
}
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
async getDeploymentArgs() {
|
|
16
20
|
const signingPublicKey = await Ecdsa.new().then(e => e.computePublicKey(this.signingPrivateKey));
|
|
17
21
|
return [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)];
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const signClosure = (msg: Buffer) => ecdsa.constructSignature(msg, this.signingPrivateKey);
|
|
23
|
-
return new StoredKeyAccountEntrypoint(address, signClosure, chainId, version);
|
|
24
|
+
getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
|
|
25
|
+
return new EcdsaAuthWitnessProvider(this.signingPrivateKey);
|
|
24
26
|
}
|
|
27
|
+
}
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
/** Creates auth witnesses using ECDSA signatures. */
|
|
30
|
+
class EcdsaAuthWitnessProvider implements AuthWitnessProvider {
|
|
31
|
+
constructor(private signingPrivateKey: Buffer) {}
|
|
32
|
+
|
|
33
|
+
async createAuthWitness(message: Fr): Promise<AuthWitness> {
|
|
34
|
+
const ecdsa = await Ecdsa.new();
|
|
35
|
+
const signature = ecdsa.constructSignature(message.toBuffer(), this.signingPrivateKey);
|
|
36
|
+
return new AuthWitness(message, [...signature.r, ...signature.s]);
|
|
28
37
|
}
|
|
29
38
|
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
2
2
|
import { CompleteAddress, NodeInfo } from '@aztec/types';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AccountInterface } from '../interface.js';
|
|
5
5
|
|
|
6
6
|
export * from './ecdsa_account_contract.js';
|
|
7
7
|
export * from './schnorr_account_contract.js';
|
|
8
8
|
export * from './single_key_account_contract.js';
|
|
9
|
-
export * from './
|
|
9
|
+
export * from './base_account_contract.js';
|
|
10
10
|
|
|
11
11
|
// docs:start:account-contract-interface
|
|
12
12
|
/**
|
|
13
|
-
* An account contract instance. Knows its ABI, deployment arguments,
|
|
14
|
-
* transaction execution requests out of function calls
|
|
13
|
+
* An account contract instance. Knows its ABI, deployment arguments, how to create
|
|
14
|
+
* transaction execution requests out of function calls, and how to authorize actions.
|
|
15
15
|
*/
|
|
16
16
|
export interface AccountContract {
|
|
17
17
|
/**
|
|
18
18
|
* Returns the ABI of this account contract.
|
|
19
19
|
*/
|
|
20
20
|
getContractAbi(): ContractAbi;
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Returns the deployment arguments for this instance.
|
|
23
24
|
*/
|
|
24
25
|
getDeploymentArgs(): Promise<any[]>;
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* Returns the account interface for this account contract given a deployment at the provided address.
|
|
29
|
+
* The account interface is responsible for assembling tx requests given requested function calls, and
|
|
30
|
+
* for creating signed auth witnesses given action identifiers (message hashes).
|
|
31
|
+
* @param address - Address where this account contract is deployed.
|
|
32
|
+
* @param nodeInfo - Info on the chain where it is deployed.
|
|
33
|
+
* @returns An account interface instance for creating tx requests and authorizing actions.
|
|
29
34
|
*/
|
|
30
|
-
|
|
35
|
+
getInterface(address: CompleteAddress, nodeInfo: NodeInfo): Promise<AccountInterface>;
|
|
31
36
|
}
|
|
32
37
|
// docs:end:account-contract-interface
|
|
@@ -1,30 +1,38 @@
|
|
|
1
|
+
import { Fr } from '@aztec/circuits.js';
|
|
1
2
|
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
2
3
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
3
|
-
import { CompleteAddress, GrumpkinPrivateKey
|
|
4
|
+
import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
|
|
4
5
|
|
|
5
6
|
import SchnorrAccountContractAbi from '../../abis/schnorr_account_contract.json' assert { type: 'json' };
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { AuthWitnessProvider } from '../interface.js';
|
|
8
|
+
import { BaseAccountContract } from './base_account_contract.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Account contract that authenticates transactions using Schnorr signatures
|
|
11
12
|
* verified against a Grumpkin public key stored in an immutable encrypted note.
|
|
12
13
|
*/
|
|
13
|
-
export class SchnorrAccountContract
|
|
14
|
-
constructor(private signingPrivateKey: GrumpkinPrivateKey) {
|
|
14
|
+
export class SchnorrAccountContract extends BaseAccountContract {
|
|
15
|
+
constructor(private signingPrivateKey: GrumpkinPrivateKey) {
|
|
16
|
+
super(SchnorrAccountContractAbi as unknown as ContractAbi);
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
async getDeploymentArgs() {
|
|
17
20
|
const signingPublicKey = await Schnorr.new().then(e => e.computePublicKey(this.signingPrivateKey));
|
|
18
21
|
return [signingPublicKey.x, signingPublicKey.y];
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const signClosure = (msg: Buffer) => schnorr.constructSignature(msg, this.signingPrivateKey);
|
|
24
|
-
return new StoredKeyAccountEntrypoint(address, signClosure, chainId, version);
|
|
24
|
+
getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
|
|
25
|
+
return new SchnorrAuthWitnessProvider(this.signingPrivateKey);
|
|
25
26
|
}
|
|
27
|
+
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
/** Creates auth witnesses using Schnorr signatures. */
|
|
30
|
+
class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
|
|
31
|
+
constructor(private signingPrivateKey: GrumpkinPrivateKey) {}
|
|
32
|
+
|
|
33
|
+
async createAuthWitness(message: Fr): Promise<AuthWitness> {
|
|
34
|
+
const schnorr = await Schnorr.new();
|
|
35
|
+
const signature = schnorr.constructSignature(message.toBuffer(), this.signingPrivateKey).toBuffer();
|
|
36
|
+
return new AuthWitness(message, [...signature]);
|
|
29
37
|
}
|
|
30
38
|
}
|
|
@@ -1,28 +1,44 @@
|
|
|
1
|
+
import { Fr, PartialAddress } from '@aztec/circuits.js';
|
|
2
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
1
3
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
2
|
-
import { CompleteAddress, GrumpkinPrivateKey
|
|
4
|
+
import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
|
|
3
5
|
|
|
4
6
|
import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_account_contract.json' assert { type: 'json' };
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import { generatePublicKey } from '../../index.js';
|
|
8
|
+
import { AuthWitnessProvider } from '../interface.js';
|
|
9
|
+
import { BaseAccountContract } from './base_account_contract.js';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Account contract that authenticates transactions using Schnorr signatures verified against
|
|
10
13
|
* the note encryption key, relying on a single private key for both encryption and authentication.
|
|
11
14
|
*/
|
|
12
|
-
export class SingleKeyAccountContract
|
|
13
|
-
constructor(private encryptionPrivateKey: GrumpkinPrivateKey) {
|
|
15
|
+
export class SingleKeyAccountContract extends BaseAccountContract {
|
|
16
|
+
constructor(private encryptionPrivateKey: GrumpkinPrivateKey) {
|
|
17
|
+
super(SchnorrSingleKeyAccountContractAbi as unknown as ContractAbi);
|
|
18
|
+
}
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
getDeploymentArgs(): Promise<any[]> {
|
|
16
21
|
return Promise.resolve([]);
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
new SingleKeyAccountEntrypoint(address, partialAddress, this.encryptionPrivateKey, chainId, version),
|
|
22
|
-
);
|
|
24
|
+
getAuthWitnessProvider({ partialAddress }: CompleteAddress): AuthWitnessProvider {
|
|
25
|
+
return new SingleKeyAuthWitnessProvider(this.encryptionPrivateKey, partialAddress);
|
|
23
26
|
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates auth witnesses using Schnorr signatures and including the partial address and public key
|
|
31
|
+
* in the witness, so verifiers do not need to store the public key and can instead validate it
|
|
32
|
+
* by reconstructing the current address.
|
|
33
|
+
*/
|
|
34
|
+
class SingleKeyAuthWitnessProvider implements AuthWitnessProvider {
|
|
35
|
+
constructor(private privateKey: GrumpkinPrivateKey, private partialAddress: PartialAddress) {}
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
async createAuthWitness(message: Fr): Promise<AuthWitness> {
|
|
38
|
+
const schnorr = await Schnorr.new();
|
|
39
|
+
const signature = schnorr.constructSignature(message.toBuffer(), this.privateKey);
|
|
40
|
+
const publicKey = await generatePublicKey(this.privateKey);
|
|
41
|
+
const witness = [...publicKey.toFields(), ...signature.toBuffer(), this.partialAddress];
|
|
42
|
+
return new AuthWitness(message, witness);
|
|
27
43
|
}
|
|
28
44
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AztecAddress, Fr, FunctionData, TxContext } from '@aztec/circuits.js';
|
|
2
|
+
import { FunctionAbiHeader, encodeArguments } from '@aztec/foundation/abi';
|
|
3
|
+
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
6
|
+
import { AuthWitnessProvider, EntrypointInterface } from '../interface.js';
|
|
7
|
+
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Implementation for an entrypoint interface that follows the default entrypoint signature
|
|
11
|
+
* for an account, which accepts an EntrypointPayload as defined in noir-libs/aztec-noir/src/entrypoint.nr.
|
|
12
|
+
*/
|
|
13
|
+
export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
14
|
+
constructor(
|
|
15
|
+
private address: AztecAddress,
|
|
16
|
+
private auth: AuthWitnessProvider,
|
|
17
|
+
private chainId: number = DEFAULT_CHAIN_ID,
|
|
18
|
+
private version: number = DEFAULT_VERSION,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
22
|
+
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
23
|
+
const abi = this.getEntrypointAbi();
|
|
24
|
+
const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, [payload]));
|
|
25
|
+
const message = Fr.fromBuffer(await hashPayload(payload));
|
|
26
|
+
const authWitness = await this.auth.createAuthWitness(message);
|
|
27
|
+
const txRequest = TxExecutionRequest.from({
|
|
28
|
+
argsHash: packedArgs.hash,
|
|
29
|
+
origin: this.address,
|
|
30
|
+
functionData: FunctionData.fromAbi(abi),
|
|
31
|
+
txContext: TxContext.empty(this.chainId, this.version),
|
|
32
|
+
packedArguments: [...callsPackedArguments, packedArgs],
|
|
33
|
+
authWitnesses: [authWitness],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return txRequest;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private getEntrypointAbi() {
|
|
40
|
+
return {
|
|
41
|
+
name: 'entrypoint',
|
|
42
|
+
functionType: 'secret',
|
|
43
|
+
isInternal: false,
|
|
44
|
+
parameters: [
|
|
45
|
+
{
|
|
46
|
+
name: 'payload',
|
|
47
|
+
type: {
|
|
48
|
+
kind: 'struct',
|
|
49
|
+
path: 'aztec::entrypoint::EntrypointPayload',
|
|
50
|
+
fields: [
|
|
51
|
+
{
|
|
52
|
+
name: 'flattened_args_hashes',
|
|
53
|
+
type: {
|
|
54
|
+
kind: 'array',
|
|
55
|
+
length: 4,
|
|
56
|
+
type: {
|
|
57
|
+
kind: 'field',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'flattened_selectors',
|
|
63
|
+
type: {
|
|
64
|
+
kind: 'array',
|
|
65
|
+
length: 4,
|
|
66
|
+
type: {
|
|
67
|
+
kind: 'field',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'flattened_targets',
|
|
73
|
+
type: {
|
|
74
|
+
kind: 'array',
|
|
75
|
+
length: 4,
|
|
76
|
+
type: {
|
|
77
|
+
kind: 'field',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'nonce',
|
|
83
|
+
type: {
|
|
84
|
+
kind: 'field',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
visibility: 'public',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
returnTypes: [],
|
|
93
|
+
} as unknown as FunctionAbiHeader;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CompleteAddress, Fr } from '@aztec/circuits.js';
|
|
2
|
+
import { AuthWitness, FunctionCall, NodeInfo, TxExecutionRequest } from '@aztec/types';
|
|
3
|
+
|
|
4
|
+
import { AccountInterface, AuthWitnessProvider, EntrypointInterface } from '../interface.js';
|
|
5
|
+
import { DefaultAccountEntrypoint } from './default_entrypoint.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default implementation for an account interface. Requires that the account uses the default
|
|
9
|
+
* entrypoint signature, which accepts an EntrypointPayload as defined in noir-libs/aztec-noir/src/entrypoint.nr.
|
|
10
|
+
*/
|
|
11
|
+
export class DefaultAccountInterface implements AccountInterface {
|
|
12
|
+
private entrypoint: EntrypointInterface;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private authWitnessProvider: AuthWitnessProvider,
|
|
16
|
+
private address: CompleteAddress,
|
|
17
|
+
nodeInfo: Pick<NodeInfo, 'chainId' | 'version'>,
|
|
18
|
+
) {
|
|
19
|
+
this.entrypoint = new DefaultAccountEntrypoint(
|
|
20
|
+
address.address,
|
|
21
|
+
authWitnessProvider,
|
|
22
|
+
nodeInfo.chainId,
|
|
23
|
+
nodeInfo.version,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
28
|
+
return this.entrypoint.createTxExecutionRequest(executions);
|
|
29
|
+
}
|
|
30
|
+
createAuthWitness(message: Fr): Promise<AuthWitness> {
|
|
31
|
+
return this.authWitnessProvider.createAuthWitness(message);
|
|
32
|
+
}
|
|
33
|
+
getCompleteAddress(): CompleteAddress {
|
|
34
|
+
return this.address;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/account/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { AztecRPC, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
|
|
2
2
|
|
|
3
3
|
import { AccountContract, AccountWallet, AztecAddress, Fr } from '../index.js';
|
|
4
|
-
import { Account } from './account.js';
|
|
5
4
|
import { EcdsaAccountContract } from './contract/ecdsa_account_contract.js';
|
|
6
5
|
import { SchnorrAccountContract } from './contract/schnorr_account_contract.js';
|
|
7
6
|
import { SingleKeyAccountContract } from './contract/single_key_account_contract.js';
|
|
7
|
+
import { AccountManager } from './manager/index.js';
|
|
8
8
|
|
|
9
|
-
export { Account } from './account.js';
|
|
10
9
|
export * from './contract/index.js';
|
|
11
|
-
export * from './
|
|
12
|
-
export {
|
|
10
|
+
export * from './defaults/index.js';
|
|
11
|
+
export { AccountInterface, AuthWitnessProvider } from './interface.js';
|
|
12
|
+
export { AccountManager, CompleteAddress };
|
|
13
13
|
|
|
14
14
|
/** A contract deployment salt. */
|
|
15
15
|
export type Salt = Fr | number | bigint;
|
|
@@ -26,8 +26,8 @@ export function getEcdsaAccount(
|
|
|
26
26
|
encryptionPrivateKey: GrumpkinPrivateKey,
|
|
27
27
|
signingPrivateKey: Buffer,
|
|
28
28
|
saltOrAddress?: Salt | CompleteAddress,
|
|
29
|
-
):
|
|
30
|
-
return new
|
|
29
|
+
): AccountManager {
|
|
30
|
+
return new AccountManager(rpc, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -42,8 +42,8 @@ export function getSchnorrAccount(
|
|
|
42
42
|
encryptionPrivateKey: GrumpkinPrivateKey,
|
|
43
43
|
signingPrivateKey: GrumpkinPrivateKey,
|
|
44
44
|
saltOrAddress?: Salt | CompleteAddress,
|
|
45
|
-
):
|
|
46
|
-
return new
|
|
45
|
+
): AccountManager {
|
|
46
|
+
return new AccountManager(rpc, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -56,8 +56,8 @@ export function getUnsafeSchnorrAccount(
|
|
|
56
56
|
rpc: AztecRPC,
|
|
57
57
|
encryptionAndSigningPrivateKey: GrumpkinPrivateKey,
|
|
58
58
|
saltOrAddress?: Salt | CompleteAddress,
|
|
59
|
-
):
|
|
60
|
-
return new
|
|
59
|
+
): AccountManager {
|
|
60
|
+
return new AccountManager(
|
|
61
61
|
rpc,
|
|
62
62
|
encryptionAndSigningPrivateKey,
|
|
63
63
|
new SingleKeyAccountContract(encryptionAndSigningPrivateKey),
|
|
@@ -85,18 +85,18 @@ export function getUnsafeSchnorrWallet(
|
|
|
85
85
|
* @param rpc - An AztecRPC server instance.
|
|
86
86
|
* @param address - Address for the account.
|
|
87
87
|
* @param accountContract - Account contract implementation.
|
|
88
|
-
*
|
|
88
|
+
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
89
89
|
*/
|
|
90
90
|
export async function getWallet(
|
|
91
91
|
rpc: AztecRPC,
|
|
92
92
|
address: AztecAddress,
|
|
93
93
|
accountContract: AccountContract,
|
|
94
94
|
): Promise<AccountWallet> {
|
|
95
|
-
const completeAddress = await rpc.
|
|
95
|
+
const completeAddress = await rpc.getRegisteredAccount(address);
|
|
96
96
|
if (!completeAddress) {
|
|
97
97
|
throw new Error(`Account ${address} not found`);
|
|
98
98
|
}
|
|
99
99
|
const nodeInfo = await rpc.getNodeInfo();
|
|
100
|
-
const entrypoint = await accountContract.
|
|
101
|
-
return new AccountWallet(rpc, entrypoint
|
|
100
|
+
const entrypoint = await accountContract.getInterface(completeAddress, nodeInfo);
|
|
101
|
+
return new AccountWallet(rpc, entrypoint);
|
|
102
102
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Fr } from '@aztec/circuits.js';
|
|
2
|
+
import { AuthWitness, CompleteAddress, FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
3
|
+
|
|
4
|
+
// docs:start:account-interface
|
|
5
|
+
/** Creates authorization witnesses. */
|
|
6
|
+
export interface AuthWitnessProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Create an authorization witness for the given message.
|
|
9
|
+
* @param message - Message to authorize.
|
|
10
|
+
*/
|
|
11
|
+
createAuthWitness(message: Fr): Promise<AuthWitness>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Creates transaction execution requests out of a set of function calls. */
|
|
15
|
+
export interface EntrypointInterface {
|
|
16
|
+
/**
|
|
17
|
+
* Generates an authenticated request out of set of function calls.
|
|
18
|
+
* @param executions - The execution intents to be run.
|
|
19
|
+
* @param opts - Options.
|
|
20
|
+
* @returns The authenticated transaction execution request.
|
|
21
|
+
*/
|
|
22
|
+
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Handler for interfacing with an account. Knows how to create transaction execution
|
|
27
|
+
* requests and authorize actions for its corresponding account.
|
|
28
|
+
*/
|
|
29
|
+
export interface AccountInterface extends AuthWitnessProvider, EntrypointInterface {
|
|
30
|
+
/**
|
|
31
|
+
* Returns the complete address for this account.
|
|
32
|
+
*/
|
|
33
|
+
getCompleteAddress(): CompleteAddress;
|
|
34
|
+
}
|
|
35
|
+
// docs:end:account-interface
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FieldsOf } from '@aztec/circuits.js';
|
|
2
2
|
import { TxHash, TxReceipt } from '@aztec/types';
|
|
3
3
|
|
|
4
|
-
import { SentTx, WaitOpts, Wallet } from '
|
|
4
|
+
import { SentTx, WaitOpts, Wallet } from '../../index.js';
|
|
5
5
|
|
|
6
6
|
/** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
|
|
7
7
|
export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Fr, PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js';
|
|
2
2
|
import { AztecRPC, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
|
|
3
3
|
|
|
4
|
-
import { AccountWallet, ContractDeployer, DeployMethod, WaitOpts, generatePublicKey } from '
|
|
4
|
+
import { AccountWallet, ContractDeployer, DeployMethod, WaitOpts, generatePublicKey } from '../../index.js';
|
|
5
|
+
import { AccountContract, Salt } from '../index.js';
|
|
6
|
+
import { AccountInterface } from '../interface.js';
|
|
5
7
|
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
6
|
-
import { AccountContract, Entrypoint, Salt } from './index.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
|
|
10
11
|
* and creating and registering the user wallet in the RPC server.
|
|
11
12
|
*/
|
|
12
|
-
export class
|
|
13
|
+
export class AccountManager {
|
|
13
14
|
/** Deployment salt for the account contract. */
|
|
14
15
|
public readonly salt?: Fr;
|
|
15
16
|
|
|
@@ -41,10 +42,10 @@ export class Account {
|
|
|
41
42
|
* Returns the entrypoint for this account as defined by its account contract.
|
|
42
43
|
* @returns An entrypoint.
|
|
43
44
|
*/
|
|
44
|
-
public async
|
|
45
|
+
public async getAccount(): Promise<AccountInterface> {
|
|
45
46
|
const nodeInfo = await this.rpc.getNodeInfo();
|
|
46
47
|
const completeAddress = await this.getCompleteAddress();
|
|
47
|
-
return this.accountContract.
|
|
48
|
+
return this.accountContract.getInterface(completeAddress, nodeInfo);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -72,8 +73,8 @@ export class Account {
|
|
|
72
73
|
* @returns A Wallet instance.
|
|
73
74
|
*/
|
|
74
75
|
public async getWallet(): Promise<AccountWallet> {
|
|
75
|
-
const entrypoint = await this.
|
|
76
|
-
return new AccountWallet(this.rpc, entrypoint
|
|
76
|
+
const entrypoint = await this.getAccount();
|
|
77
|
+
return new AccountWallet(this.rpc, entrypoint);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AztecAddress, CompleteAddress, EthAddress, Fr, GrumpkinScalar, Point } from '@aztec/circuits.js';
|
|
2
2
|
import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client';
|
|
3
3
|
import {
|
|
4
|
+
AuthWitness,
|
|
4
5
|
AztecRPC,
|
|
5
6
|
ContractData,
|
|
6
7
|
ExtendedContractData,
|
|
@@ -29,6 +30,7 @@ export const createAztecRpcClient = (url: string, fetch = defaultFetch): AztecRP
|
|
|
29
30
|
Fr,
|
|
30
31
|
GrumpkinScalar,
|
|
31
32
|
NotePreimage,
|
|
33
|
+
AuthWitness,
|
|
32
34
|
},
|
|
33
35
|
{ Tx, TxReceipt, L2BlockL2Logs },
|
|
34
36
|
false,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
|
|
15
15
|
import { MockProxy, mock } from 'jest-mock-extended';
|
|
16
16
|
|
|
17
|
-
import { Wallet } from '../
|
|
17
|
+
import { Wallet } from '../wallet/index.js';
|
|
18
18
|
import { Contract } from './contract.js';
|
|
19
19
|
|
|
20
20
|
describe('Contract Class', () => {
|
|
@@ -28,7 +28,13 @@ describe('Contract Class', () => {
|
|
|
28
28
|
const mockTxHash = { type: 'TxHash' } as any as TxHash;
|
|
29
29
|
const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt;
|
|
30
30
|
const mockViewResultValue = 1;
|
|
31
|
-
const mockNodeInfo: NodeInfo = {
|
|
31
|
+
const mockNodeInfo: NodeInfo = {
|
|
32
|
+
version: 1,
|
|
33
|
+
chainId: 2,
|
|
34
|
+
rollupAddress: EthAddress.random(),
|
|
35
|
+
client: '',
|
|
36
|
+
nargoVersion: 'sdlhahf823',
|
|
37
|
+
};
|
|
32
38
|
|
|
33
39
|
const defaultAbi: ContractAbi = {
|
|
34
40
|
name: 'FooContract',
|
|
@@ -102,7 +108,7 @@ describe('Contract Class', () => {
|
|
|
102
108
|
wallet.getTxReceipt.mockResolvedValue(mockTxReceipt);
|
|
103
109
|
wallet.getNodeInfo.mockResolvedValue(mockNodeInfo);
|
|
104
110
|
wallet.simulateTx.mockResolvedValue(mockTx);
|
|
105
|
-
wallet.
|
|
111
|
+
wallet.getRegisteredAccounts.mockResolvedValue([account]);
|
|
106
112
|
});
|
|
107
113
|
|
|
108
114
|
it('should create and send a contract method tx', async () => {
|
package/src/contract/contract.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { ContractAbi } from '@aztec/foundation/abi';
|
|
|
2
2
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
3
|
import { PublicKey } from '@aztec/types';
|
|
4
4
|
|
|
5
|
-
import { Wallet } from '../aztec_rpc_client/wallet.js';
|
|
6
5
|
import { DeployMethod, Point } from '../index.js';
|
|
6
|
+
import { Wallet } from '../wallet/index.js';
|
|
7
7
|
import { ContractBase } from './contract_base.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -2,7 +2,7 @@ import { ContractAbi, FunctionAbi, FunctionSelector } from '@aztec/foundation/ab
|
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { CompleteAddress, DeployedContract } from '@aztec/types';
|
|
4
4
|
|
|
5
|
-
import { Wallet } from '../
|
|
5
|
+
import { Wallet } from '../wallet/index.js';
|
|
6
6
|
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AztecAddress, FunctionData } from '@aztec/circuits.js';
|
|
2
|
-
import {
|
|
2
|
+
import { FunctionAbiHeader, FunctionType, encodeArguments } from '@aztec/foundation/abi';
|
|
3
3
|
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
4
4
|
|
|
5
|
-
import { Wallet } from '../
|
|
5
|
+
import { Wallet } from '../wallet/index.js';
|
|
6
6
|
import { BaseContractInteraction, SendMethodOptions } from './base_contract_interaction.js';
|
|
7
7
|
|
|
8
8
|
export { SendMethodOptions };
|
|
@@ -26,7 +26,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
26
26
|
constructor(
|
|
27
27
|
protected wallet: Wallet,
|
|
28
28
|
protected contractAddress: AztecAddress,
|
|
29
|
-
protected functionDao:
|
|
29
|
+
protected functionDao: FunctionAbiHeader,
|
|
30
30
|
protected args: any[],
|
|
31
31
|
) {
|
|
32
32
|
super(wallet);
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from './contract/index.js';
|
|
2
2
|
export * from './contract_deployer/index.js';
|
|
3
3
|
export * from './utils/index.js';
|
|
4
|
-
export * from './aztec_rpc_client
|
|
4
|
+
export * from './aztec_rpc_client.js';
|
|
5
5
|
export * from './account/index.js';
|
|
6
6
|
export * from './contract_deployer/deploy_method.js';
|
|
7
7
|
export * from './sandbox/index.js';
|
|
8
|
+
export * from './wallet/index.js';
|
|
8
9
|
|
|
9
10
|
export { AztecAddress, EthAddress, Point, Fr, GrumpkinScalar } from '@aztec/circuits.js';
|
|
10
11
|
export {
|