@aztec/aztec.js 0.1.0-alpha37 → 0.1.0-alpha39
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 +3 -3
- package/dest/abis/ecdsa_account_contract.json +3 -2
- package/dest/abis/schnorr_account_contract.json +3 -2
- package/dest/abis/schnorr_single_key_account_contract.json +2 -1
- package/dest/account/account.d.ts +1 -2
- package/dest/account/account.d.ts.map +1 -1
- package/dest/account/account.js +7 -6
- package/dest/account/contract/ecdsa_account_contract.d.ts +1 -2
- package/dest/account/contract/ecdsa_account_contract.d.ts.map +1 -1
- package/dest/account/contract/ecdsa_account_contract.js +1 -1
- package/dest/account/contract/index.d.ts +1 -2
- package/dest/account/contract/index.d.ts.map +1 -1
- package/dest/account/contract/index.js +1 -1
- package/dest/account/contract/schnorr_account_contract.d.ts +1 -2
- package/dest/account/contract/schnorr_account_contract.d.ts.map +1 -1
- package/dest/account/contract/schnorr_account_contract.js +1 -1
- package/dest/account/contract/single_key_account_contract.d.ts +1 -2
- package/dest/account/contract/single_key_account_contract.d.ts.map +1 -1
- package/dest/account/contract/single_key_account_contract.js +1 -1
- package/dest/account/index.d.ts +1 -2
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +7 -3
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +1 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.js +3 -2
- package/dest/aztec_rpc_client/wallet.d.ts +7 -5
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +14 -8
- 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 +14 -13
- package/dest/contract_deployer/deploy_method.js +6 -6
- package/dest/contract_deployer/deploy_sent_tx.js +2 -2
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/main.js +1 -1
- package/dest/sandbox/index.d.ts +110 -0
- package/dest/sandbox/index.d.ts.map +1 -0
- package/dest/sandbox/index.js +66 -0
- package/dest/utils/abi_types.d.ts +6 -0
- package/dest/utils/abi_types.d.ts.map +1 -0
- package/dest/utils/abi_types.js +2 -0
- package/dest/utils/account.d.ts +5 -2
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +21 -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/package.json +4 -4
- package/src/abis/ecdsa_account_contract.json +3 -2
- package/src/abis/schnorr_account_contract.json +3 -2
- package/src/abis/schnorr_single_key_account_contract.json +2 -1
- package/src/account/account.ts +6 -6
- package/src/account/contract/ecdsa_account_contract.ts +1 -2
- package/src/account/contract/index.ts +1 -2
- package/src/account/contract/schnorr_account_contract.ts +1 -2
- package/src/account/contract/single_key_account_contract.ts +1 -2
- package/src/account/index.ts +5 -4
- package/src/aztec_rpc_client/aztec_rpc_client.ts +2 -1
- package/src/aztec_rpc_client/wallet.ts +15 -13
- package/src/contract/contract.test.ts +13 -12
- package/src/contract/contract.ts +1 -1
- package/src/contract_deployer/deploy_method.ts +5 -5
- package/src/contract_deployer/deploy_sent_tx.ts +1 -1
- package/src/index.ts +2 -0
- package/src/sandbox/index.ts +83 -0
- package/src/utils/abi_types.ts +4 -0
- package/src/utils/account.ts +36 -16
- package/src/utils/index.ts +1 -0
- package/dest/account/complete_address.d.ts +0 -13
- package/dest/account/complete_address.d.ts.map +0 -1
- package/dest/account/complete_address.js +0 -8
- package/src/account/complete_address.ts +0 -18
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Fr, PrivateKey } from '@aztec/circuits.js';
|
|
2
|
+
import { ContractAbi } from '@aztec/foundation/abi';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
+
|
|
5
|
+
import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
|
|
6
|
+
import { AztecRPC, getAccountWallets, getSchnorrAccount } from '../index.js';
|
|
7
|
+
|
|
8
|
+
export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
|
|
9
|
+
new PrivateKey(Buffer.from('b2803ec899f76f6b2ac011480d24028f1a29587f8a3a92f7ee9d48d8c085c284', 'hex')),
|
|
10
|
+
new PrivateKey(Buffer.from('6bb46e9a80da2ff7bfff71c2c50eaaa4b15f7ed5ad1ade4261b574ef80b0cdb0', 'hex')),
|
|
11
|
+
new PrivateKey(Buffer.from('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c', 'hex')),
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const INITIAL_SANDBOX_SIGNING_KEYS = INITIAL_SANDBOX_ENCRYPTION_KEYS;
|
|
15
|
+
|
|
16
|
+
export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
17
|
+
|
|
18
|
+
export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets a wallet for the Aztec accounts that are initially stored in the sandbox.
|
|
22
|
+
* @param aztecRpc - An instance of the Aztec RPC interface.
|
|
23
|
+
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
24
|
+
*/
|
|
25
|
+
export async function getSandboxAccountsWallet(aztecRpc: AztecRPC) {
|
|
26
|
+
return await getAccountWallets(
|
|
27
|
+
aztecRpc,
|
|
28
|
+
INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI as ContractAbi,
|
|
29
|
+
INITIAL_SANDBOX_ENCRYPTION_KEYS,
|
|
30
|
+
INITIAL_SANDBOX_SIGNING_KEYS,
|
|
31
|
+
INITIAL_SANDBOX_SALTS,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Deploys the initial set of schnorr signature accounts to the sandbox
|
|
37
|
+
* @param aztecRpc - An instance of the Aztec RPC interface.
|
|
38
|
+
* @returns The set of deployed Account objects and associated private encryption keys
|
|
39
|
+
*/
|
|
40
|
+
export async function deployInitialSandboxAccounts(aztecRpc: AztecRPC) {
|
|
41
|
+
const accounts = INITIAL_SANDBOX_ENCRYPTION_KEYS.map((privateKey, i) => {
|
|
42
|
+
const account = getSchnorrAccount(aztecRpc, privateKey, INITIAL_SANDBOX_SIGNING_KEYS[i], INITIAL_SANDBOX_SALTS[i]);
|
|
43
|
+
return {
|
|
44
|
+
account,
|
|
45
|
+
privateKey,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
// Attempt to get as much parallelism as possible
|
|
49
|
+
const deployMethods = await Promise.all(
|
|
50
|
+
accounts.map(async x => {
|
|
51
|
+
const deployMethod = await x.account.getDeployMethod();
|
|
52
|
+
await deployMethod.create({ contractAddressSalt: x.account.salt });
|
|
53
|
+
await deployMethod.simulate({});
|
|
54
|
+
return deployMethod;
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
// Send tx together to try and get them in the same rollup
|
|
58
|
+
const sentTxs = deployMethods.map(dm => {
|
|
59
|
+
return dm.send();
|
|
60
|
+
});
|
|
61
|
+
await Promise.all(
|
|
62
|
+
sentTxs.map(async (tx, i) => {
|
|
63
|
+
const wallet = await accounts[i].account.getWallet();
|
|
64
|
+
return tx.wait({ wallet });
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
return accounts;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Function to wait until the sandbox becomes ready for use.
|
|
72
|
+
* @param rpcServer - The rpc client connected to the sandbox.
|
|
73
|
+
*/
|
|
74
|
+
export const waitForSandbox = async (rpcServer: AztecRPC) => {
|
|
75
|
+
while (true) {
|
|
76
|
+
try {
|
|
77
|
+
await rpcServer.getNodeInfo();
|
|
78
|
+
break;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
await sleep(1000);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
package/src/utils/account.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { AztecRPC, TxStatus } from '@aztec/types';
|
|
|
6
6
|
|
|
7
7
|
import { SingleKeyAccountEntrypoint } from '../account/entrypoint/single_key_account_entrypoint.js';
|
|
8
8
|
import { EntrypointWallet, Wallet } from '../aztec_rpc_client/wallet.js';
|
|
9
|
-
import { ContractDeployer, EntrypointCollection, generatePublicKey } from '../index.js';
|
|
9
|
+
import { ContractDeployer, EntrypointCollection, StoredKeyAccountEntrypoint, generatePublicKey } from '../index.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates an Aztec Account.
|
|
@@ -27,7 +27,7 @@ export async function createAccounts(
|
|
|
27
27
|
const privKey = i == 0 && privateKey ? privateKey : PrivateKey.random();
|
|
28
28
|
const publicKey = await generatePublicKey(privKey);
|
|
29
29
|
const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
|
|
30
|
-
await aztecRpcClient.
|
|
30
|
+
await aztecRpcClient.registerAccount(privKey, deploymentInfo.completeAddress);
|
|
31
31
|
const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey);
|
|
32
32
|
const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
|
|
33
33
|
await tx.isMined({ interval: 0.5 });
|
|
@@ -36,15 +36,20 @@ export async function createAccounts(
|
|
|
36
36
|
throw new Error(`Deployment tx not mined (status is ${receipt.status})`);
|
|
37
37
|
}
|
|
38
38
|
const address = receipt.contractAddress!;
|
|
39
|
-
if (!address.equals(deploymentInfo.address)) {
|
|
39
|
+
if (!address.equals(deploymentInfo.completeAddress.address)) {
|
|
40
40
|
throw new Error(
|
|
41
|
-
`Deployment address does not match for account contract (expected ${deploymentInfo.address.toString()} got ${address.toString()})`,
|
|
41
|
+
`Deployment address does not match for account contract (expected ${deploymentInfo.completeAddress.address.toString()} got ${address.toString()})`,
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`);
|
|
45
45
|
accountImpls.registerAccount(
|
|
46
46
|
address,
|
|
47
|
-
new SingleKeyAccountEntrypoint(
|
|
47
|
+
new SingleKeyAccountEntrypoint(
|
|
48
|
+
address,
|
|
49
|
+
deploymentInfo.completeAddress.partialAddress,
|
|
50
|
+
privKey,
|
|
51
|
+
await Schnorr.new(),
|
|
52
|
+
),
|
|
48
53
|
);
|
|
49
54
|
}
|
|
50
55
|
return new EntrypointWallet(aztecRpcClient, accountImpls);
|
|
@@ -53,23 +58,38 @@ export async function createAccounts(
|
|
|
53
58
|
/**
|
|
54
59
|
* Gets the Aztec accounts that are stored in an Aztec RPC instance.
|
|
55
60
|
* @param aztecRpcClient - An instance of the Aztec RPC interface.
|
|
56
|
-
* @param
|
|
61
|
+
* @param accountContractAbi - The abi of the account contract used when the accounts were deployed
|
|
62
|
+
* @param privateKeys - The encryption private keys used to create the accounts.
|
|
63
|
+
* @param signingKeys - The signing private keys used to create the accounts.
|
|
64
|
+
* @param salts - The salt values used to create the accounts.
|
|
57
65
|
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
58
66
|
*/
|
|
59
|
-
export async function
|
|
67
|
+
export async function getAccountWallets(
|
|
60
68
|
aztecRpcClient: AztecRPC,
|
|
61
69
|
accountContractAbi: ContractAbi,
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
privateKeys: PrivateKey[],
|
|
71
|
+
signingKeys: PrivateKey[],
|
|
72
|
+
salts: Fr[],
|
|
64
73
|
) {
|
|
74
|
+
if (privateKeys.length != salts.length || signingKeys.length != privateKeys.length) {
|
|
75
|
+
throw new Error('Keys and salts must be the same length');
|
|
76
|
+
}
|
|
65
77
|
const accountCollection = new EntrypointCollection();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
for (let i = 0; i < privateKeys.length; i++) {
|
|
79
|
+
const publicKey = await generatePublicKey(privateKeys[i]);
|
|
80
|
+
const signingPublicKey = await generatePublicKey(signingKeys[i]);
|
|
81
|
+
const deploymentInfo = await getContractDeploymentInfo(
|
|
82
|
+
accountContractAbi,
|
|
83
|
+
[signingPublicKey.x, signingPublicKey.y],
|
|
84
|
+
salts[i],
|
|
85
|
+
publicKey,
|
|
86
|
+
);
|
|
87
|
+
const address = deploymentInfo.completeAddress.address;
|
|
69
88
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
accountCollection.registerAccount(
|
|
90
|
+
address,
|
|
91
|
+
new StoredKeyAccountEntrypoint(address, signingKeys[i], await Schnorr.new()),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
74
94
|
return new EntrypointWallet(aztecRpcClient, accountCollection);
|
|
75
95
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, PartialAddress, PublicKey } from '@aztec/circuits.js';
|
|
2
|
-
/** Address and preimages associated with an account. */
|
|
3
|
-
export type CompleteAddress = {
|
|
4
|
-
/** Address of an account. Derived from the partial address and public key. */
|
|
5
|
-
address: AztecAddress;
|
|
6
|
-
/** Partial address of the account. Required for deriving the address from the encryption public key. */
|
|
7
|
-
partialAddress: PartialAddress;
|
|
8
|
-
/** Encryption public key associated with this address. */
|
|
9
|
-
publicKey: PublicKey;
|
|
10
|
-
};
|
|
11
|
-
/** Returns whether the argument looks like a CompleteAddress. */
|
|
12
|
-
export declare function isCompleteAddress(obj: any): obj is CompleteAddress;
|
|
13
|
-
//# sourceMappingURL=complete_address.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"complete_address.d.ts","sourceRoot":"","sources":["../../src/account/complete_address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE7E,wDAAwD;AACxD,MAAM,MAAM,eAAe,GAAG;IAC5B,8EAA8E;IAC9E,OAAO,EAAE,YAAY,CAAC;IACtB,wGAAwG;IACxG,cAAc,EAAE,cAAc,CAAC;IAC/B,0DAA0D;IAC1D,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,eAAe,CAIlE"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Returns whether the argument looks like a CompleteAddress. */
|
|
2
|
-
export function isCompleteAddress(obj) {
|
|
3
|
-
if (!obj)
|
|
4
|
-
return false;
|
|
5
|
-
const maybe = obj;
|
|
6
|
-
return !!maybe.address && !!maybe.partialAddress && !!maybe.publicKey;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGxldGVfYWRkcmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hY2NvdW50L2NvbXBsZXRlX2FkZHJlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBWUEsaUVBQWlFO0FBQ2pFLE1BQU0sVUFBVSxpQkFBaUIsQ0FBQyxHQUFRO0lBQ3hDLElBQUksQ0FBQyxHQUFHO1FBQUUsT0FBTyxLQUFLLENBQUM7SUFDdkIsTUFBTSxLQUFLLEdBQUcsR0FBc0IsQ0FBQztJQUNyQyxPQUFPLENBQUMsQ0FBQyxLQUFLLENBQUMsT0FBTyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsY0FBYyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsU0FBUyxDQUFDO0FBQ3hFLENBQUMifQ==
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, PartialAddress, PublicKey } from '@aztec/circuits.js';
|
|
2
|
-
|
|
3
|
-
/** Address and preimages associated with an account. */
|
|
4
|
-
export type CompleteAddress = {
|
|
5
|
-
/** Address of an account. Derived from the partial address and public key. */
|
|
6
|
-
address: AztecAddress;
|
|
7
|
-
/** Partial address of the account. Required for deriving the address from the encryption public key. */
|
|
8
|
-
partialAddress: PartialAddress;
|
|
9
|
-
/** Encryption public key associated with this address. */
|
|
10
|
-
publicKey: PublicKey;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/** Returns whether the argument looks like a CompleteAddress. */
|
|
14
|
-
export function isCompleteAddress(obj: any): obj is CompleteAddress {
|
|
15
|
-
if (!obj) return false;
|
|
16
|
-
const maybe = obj as CompleteAddress;
|
|
17
|
-
return !!maybe.address && !!maybe.partialAddress && !!maybe.publicKey;
|
|
18
|
-
}
|