@aztec/aztec.js 0.1.0-alpha21 → 0.1.0-alpha23
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/README.md +1 -1
- package/dest/account_impl/account_collection.d.ts.map +1 -1
- package/dest/account_impl/account_collection.js +5 -4
- package/dest/account_impl/account_contract.d.ts +3 -4
- package/dest/account_impl/account_contract.d.ts.map +1 -1
- package/dest/account_impl/account_contract.js +3 -4
- package/dest/auth/ecdsa.d.ts.map +1 -1
- package/dest/auth/ecdsa.js +1 -1
- package/dest/auth/schnorr.d.ts +1 -1
- package/dest/auth/schnorr.d.ts.map +1 -1
- package/dest/auth/schnorr.js +1 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts +1 -23
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +1 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.js +3 -9
- package/dest/aztec_rpc_client/wallet.d.ts +3 -3
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +4 -1
- package/dest/contract/contract.d.ts +1 -1
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +2 -2
- package/dest/contract/contract.test.js +4 -4
- package/dest/contract/contract_function_interaction.d.ts +2 -3
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +3 -5
- package/dest/contract/sent_tx.d.ts +1 -1
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +2 -2
- package/dest/contract_deployer/contract_deployer.d.ts +2 -1
- package/dest/contract_deployer/contract_deployer.d.ts.map +1 -1
- package/dest/contract_deployer/contract_deployer.js +2 -2
- package/dest/contract_deployer/contract_deployer.test.js +4 -4
- package/dest/contract_deployer/deploy_method.d.ts +2 -3
- package/dest/contract_deployer/deploy_method.d.ts.map +1 -1
- package/dest/contract_deployer/deploy_method.js +2 -3
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/utils/account.d.ts +11 -3
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +28 -12
- package/dest/utils/index.d.ts +1 -0
- package/dest/utils/index.d.ts.map +1 -1
- package/dest/utils/index.js +2 -1
- package/dest/utils/l1_contracts.d.ts +24 -0
- package/dest/utils/l1_contracts.d.ts.map +1 -0
- package/dest/utils/l1_contracts.js +8 -0
- package/dest/utils/pub_key.d.ts +0 -9
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/utils/pub_key.js +1 -14
- package/package.json +5 -6
- package/src/account_impl/account_collection.ts +4 -4
- package/src/account_impl/account_contract.ts +5 -7
- package/src/auth/ecdsa.ts +2 -2
- package/src/auth/schnorr.ts +2 -1
- package/src/aztec_rpc_client/aztec_rpc_client.ts +10 -41
- package/src/aztec_rpc_client/wallet.ts +18 -3
- package/src/contract/contract.test.ts +4 -4
- package/src/contract/contract.ts +2 -2
- package/src/contract/contract_function_interaction.ts +5 -6
- package/src/contract/sent_tx.ts +1 -1
- package/src/contract_deployer/contract_deployer.test.ts +5 -5
- package/src/contract_deployer/contract_deployer.ts +3 -2
- package/src/contract_deployer/deploy_method.ts +9 -4
- package/src/index.ts +4 -1
- package/src/utils/account.ts +42 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/l1_contracts.ts +40 -0
- package/src/utils/pub_key.ts +1 -14
- package/tsconfig.json +2 -5
package/src/utils/account.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AztecAddress, CircuitsWasm, Fr, Point } from '@aztec/circuits.js';
|
|
1
|
+
import { CircuitsWasm, Fr, getContractDeploymentInfo } from '@aztec/circuits.js';
|
|
3
2
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
4
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
4
|
+
import { AztecRPC, TxStatus } from '@aztec/types';
|
|
5
|
+
import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/examples';
|
|
6
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
7
|
+
|
|
6
8
|
import { AccountWallet, Wallet } from '../aztec_rpc_client/wallet.js';
|
|
7
9
|
import {
|
|
8
10
|
AccountCollection,
|
|
9
11
|
AccountContract,
|
|
10
12
|
ContractDeployer,
|
|
11
|
-
|
|
13
|
+
SchnorrAuthProvider,
|
|
12
14
|
generatePublicKey,
|
|
13
15
|
} from '../index.js';
|
|
14
16
|
|
|
@@ -19,41 +21,71 @@ import {
|
|
|
19
21
|
export async function createAccounts(
|
|
20
22
|
aztecRpcClient: AztecRPC,
|
|
21
23
|
privateKey?: Buffer,
|
|
24
|
+
salt = Fr.random(),
|
|
22
25
|
numberOfAccounts = 1,
|
|
23
26
|
logger = createDebugLogger('aztec:aztec.js:accounts'),
|
|
24
27
|
): Promise<Wallet> {
|
|
28
|
+
const accountAbi = SchnorrAccountContractAbi;
|
|
25
29
|
const accountImpls = new AccountCollection();
|
|
26
|
-
const results: [AztecAddress, Point][] = [];
|
|
27
30
|
const wasm = await CircuitsWasm.get();
|
|
28
31
|
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
29
32
|
// TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key
|
|
30
33
|
const privKey = i == 0 && privateKey ? privateKey : randomBytes(32);
|
|
31
|
-
const accountAbi = EcdsaAccountContractAbi;
|
|
32
34
|
const publicKey = await generatePublicKey(privKey);
|
|
33
|
-
const salt = Fr.random();
|
|
34
35
|
const deploymentInfo = await getContractDeploymentInfo(accountAbi, [], salt, publicKey);
|
|
35
36
|
await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress, accountAbi);
|
|
36
37
|
const contractDeployer = new ContractDeployer(accountAbi, aztecRpcClient, publicKey);
|
|
37
38
|
const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
|
|
38
|
-
await tx.isMined(0, 0.
|
|
39
|
+
await tx.isMined(0, 0.5);
|
|
39
40
|
const receipt = await tx.getReceipt();
|
|
40
41
|
if (receipt.status !== TxStatus.MINED) {
|
|
41
42
|
throw new Error(`Deployment tx not mined (status is ${receipt.status})`);
|
|
42
43
|
}
|
|
43
44
|
const address = receipt.contractAddress!;
|
|
45
|
+
if (!address.equals(deploymentInfo.address)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Deployment address does not match for account contract (expected ${deploymentInfo.address.toString()} got ${address.toString()})`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
44
50
|
logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`);
|
|
45
51
|
accountImpls.registerAccount(
|
|
46
52
|
address,
|
|
47
53
|
new AccountContract(
|
|
48
54
|
address,
|
|
49
55
|
publicKey,
|
|
50
|
-
new
|
|
56
|
+
new SchnorrAuthProvider(await Schnorr.new(), privKey),
|
|
51
57
|
deploymentInfo.partialAddress,
|
|
52
58
|
accountAbi,
|
|
53
59
|
wasm,
|
|
54
60
|
),
|
|
55
61
|
);
|
|
56
|
-
results.push([address, publicKey]);
|
|
57
62
|
}
|
|
58
63
|
return new AccountWallet(aztecRpcClient, accountImpls);
|
|
59
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Gets the Aztec accounts that are stored in an Aztec RPC instance.
|
|
68
|
+
* @param aztecRpcClient - An instance of the Aztec RPC interface.
|
|
69
|
+
* @param numberOfAccounts - The number of accounts to fetch.
|
|
70
|
+
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
71
|
+
*/
|
|
72
|
+
export async function getAccountWallet(aztecRpcClient: AztecRPC, privateKey: Buffer, salt: Fr) {
|
|
73
|
+
const wasm = await CircuitsWasm.get();
|
|
74
|
+
const accountCollection = new AccountCollection();
|
|
75
|
+
const publicKey = await generatePublicKey(privateKey);
|
|
76
|
+
const address = await aztecRpcClient.getAccountAddress(publicKey);
|
|
77
|
+
const deploymentInfo = await getContractDeploymentInfo(SchnorrAccountContractAbi, [], salt, publicKey);
|
|
78
|
+
|
|
79
|
+
accountCollection.registerAccount(
|
|
80
|
+
address,
|
|
81
|
+
new AccountContract(
|
|
82
|
+
address,
|
|
83
|
+
publicKey,
|
|
84
|
+
new SchnorrAuthProvider(await Schnorr.new(), privateKey),
|
|
85
|
+
deploymentInfo.partialAddress,
|
|
86
|
+
SchnorrAccountContractAbi,
|
|
87
|
+
wasm,
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
return new AccountWallet(aztecRpcClient, accountCollection);
|
|
91
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/circuits.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A dictionary of the Aztec-deployed L1 contracts.
|
|
5
|
+
*/
|
|
6
|
+
export type L1ContractAddresses = {
|
|
7
|
+
/**
|
|
8
|
+
* Address fo the main Aztec rollup contract.
|
|
9
|
+
*/
|
|
10
|
+
rollup: EthAddress;
|
|
11
|
+
/**
|
|
12
|
+
* Address of the contract that emits events on public contract deployment.
|
|
13
|
+
*/
|
|
14
|
+
contractDeploymentEmitter: EthAddress;
|
|
15
|
+
/**
|
|
16
|
+
* Address of the L1/L2 messaging inbox contract.
|
|
17
|
+
*/
|
|
18
|
+
inbox: EthAddress;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Registry Address.
|
|
22
|
+
*/
|
|
23
|
+
registry: EthAddress;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* string dictionary of aztec contract addresses that we receive over http.
|
|
28
|
+
*/
|
|
29
|
+
type L1ContractAddressesResp = {
|
|
30
|
+
[K in keyof L1ContractAddresses]: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getL1ContractAddresses = async (url: string): Promise<L1ContractAddresses> => {
|
|
34
|
+
const reqUrl = new URL(`${url}/api/l1-contract-addresses`);
|
|
35
|
+
const response = (await (await fetch(reqUrl.toString())).json()) as unknown as L1ContractAddressesResp;
|
|
36
|
+
const result = Object.fromEntries(
|
|
37
|
+
Object.entries(response).map(([key, value]) => [key, EthAddress.fromString(value)]),
|
|
38
|
+
);
|
|
39
|
+
return result as L1ContractAddresses;
|
|
40
|
+
};
|
package/src/utils/pub_key.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
2
|
-
import { Point } from '../index.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
* Converts a Point type to a public key represented by BigInt coordinates
|
|
6
|
-
* @param point - The Point to convert.
|
|
7
|
-
* @returns An object with x & y coordinates represented as bigints.
|
|
8
|
-
*/
|
|
9
|
-
export function pointToPublicKey(point: Point) {
|
|
10
|
-
const x = point.x.toBigInt();
|
|
11
|
-
const y = point.y.toBigInt();
|
|
12
|
-
return {
|
|
13
|
-
x,
|
|
14
|
-
y,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
3
|
+
import { Point } from '../index.js';
|
|
17
4
|
|
|
18
5
|
/**
|
|
19
6
|
* Method for generating a public grumpkin key from a private key.
|
package/tsconfig.json
CHANGED
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
"tsBuildInfoFile": ".tsbuildinfo"
|
|
7
7
|
},
|
|
8
8
|
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../aztec-rpc"
|
|
11
|
-
},
|
|
12
9
|
{
|
|
13
10
|
"path": "../circuits.js"
|
|
14
11
|
},
|
|
@@ -16,10 +13,10 @@
|
|
|
16
13
|
"path": "../foundation"
|
|
17
14
|
},
|
|
18
15
|
{
|
|
19
|
-
"path": "../
|
|
16
|
+
"path": "../noir-contracts"
|
|
20
17
|
},
|
|
21
18
|
{
|
|
22
|
-
"path": "../
|
|
19
|
+
"path": "../types"
|
|
23
20
|
}
|
|
24
21
|
],
|
|
25
22
|
"include": ["src"]
|