@aztec/aztec.js 0.1.0-alpha23 → 0.1.0-alpha25
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 +150 -0
- package/dest/abis/schnorr_account_contract.json +96 -0
- package/dest/abis/schnorr_single_key_account_contract.json +96 -0
- package/dest/account_impl/account_collection.d.ts.map +1 -1
- package/dest/account_impl/account_collection.js +1 -1
- package/dest/account_impl/entrypoint_payload.d.ts +26 -0
- package/dest/account_impl/entrypoint_payload.d.ts.map +1 -0
- package/dest/account_impl/entrypoint_payload.js +46 -0
- package/dest/account_impl/index.d.ts +2 -1
- package/dest/account_impl/index.d.ts.map +1 -1
- package/dest/account_impl/index.js +3 -2
- package/dest/account_impl/single_key_account_contract.d.ts +23 -0
- package/dest/account_impl/single_key_account_contract.d.ts.map +1 -0
- package/dest/account_impl/single_key_account_contract.js +66 -0
- package/dest/account_impl/stored_key_account_contract.d.ts +22 -0
- package/dest/account_impl/stored_key_account_contract.d.ts.map +1 -0
- package/dest/account_impl/stored_key_account_contract.js +65 -0
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts +2 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +1 -1
- package/dest/aztec_rpc_client/aztec_rpc_client.js +5 -5
- package/dest/aztec_rpc_client/wallet.d.ts +8 -6
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +19 -10
- package/dest/contract/contract.d.ts +3 -4
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +1 -1
- package/dest/contract/contract.test.js +3 -3
- package/dest/contract/contract_function_interaction.d.ts +1 -1
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +6 -6
- package/dest/contract_deployer/contract_deployer.d.ts.map +1 -1
- package/dest/contract_deployer/contract_deployer.js +2 -1
- package/dest/contract_deployer/contract_deployer.test.js +3 -3
- package/dest/contract_deployer/deploy_method.d.ts.map +1 -1
- package/dest/contract_deployer/deploy_method.js +5 -13
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -2
- package/dest/utils/account.d.ts +3 -2
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +13 -17
- package/dest/utils/l1_contracts.d.ts +8 -0
- package/dest/utils/l1_contracts.d.ts.map +1 -1
- package/dest/utils/l1_contracts.js +10 -2
- package/package.json +4 -5
- package/src/abis/ecdsa_account_contract.json +150 -0
- package/src/abis/schnorr_account_contract.json +96 -0
- package/src/abis/schnorr_single_key_account_contract.json +96 -0
- package/src/account_impl/account_collection.ts +1 -0
- package/src/account_impl/entrypoint_payload.ts +76 -0
- package/src/account_impl/index.ts +2 -1
- package/src/account_impl/single_key_account_contract.ts +82 -0
- package/src/account_impl/stored_key_account_contract.ts +80 -0
- package/src/aztec_rpc_client/aztec_rpc_client.ts +6 -4
- package/src/aztec_rpc_client/wallet.ts +22 -15
- package/src/contract/contract.test.ts +5 -3
- package/src/contract/contract.ts +4 -3
- package/src/contract/contract_function_interaction.ts +4 -4
- package/src/contract_deployer/contract_deployer.test.ts +4 -3
- package/src/contract_deployer/contract_deployer.ts +1 -0
- package/src/contract_deployer/deploy_method.ts +5 -17
- package/src/index.ts +1 -1
- package/src/utils/account.ts +19 -35
- package/src/utils/l1_contracts.ts +21 -1
- package/tsconfig.json +1 -4
- package/dest/account_impl/account_contract.d.ts +0 -44
- package/dest/account_impl/account_contract.d.ts.map +0 -1
- package/dest/account_impl/account_contract.js +0 -107
- package/dest/auth/ecdsa.d.ts +0 -13
- package/dest/auth/ecdsa.d.ts.map +0 -1
- package/dest/auth/ecdsa.js +0 -17
- package/dest/auth/index.d.ts +0 -19
- package/dest/auth/index.d.ts.map +0 -1
- package/dest/auth/index.js +0 -14
- package/dest/auth/schnorr.d.ts +0 -13
- package/dest/auth/schnorr.d.ts.map +0 -1
- package/dest/auth/schnorr.js +0 -14
- package/src/account_impl/account_contract.ts +0 -171
- package/src/auth/ecdsa.ts +0 -18
- package/src/auth/index.ts +0 -25
- package/src/auth/schnorr.ts +0 -14
package/dest/utils/account.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fr, getContractDeploymentInfo } from '@aztec/circuits.js';
|
|
2
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
2
3
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
3
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { TxStatus } from '@aztec/types';
|
|
5
|
-
import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/examples';
|
|
6
|
-
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
7
6
|
import { AccountWallet } from '../aztec_rpc_client/wallet.js';
|
|
8
|
-
import { AccountCollection,
|
|
7
|
+
import { AccountCollection, ContractDeployer, SingleKeyAccountContract, generatePublicKey } from '../index.js';
|
|
9
8
|
/**
|
|
10
9
|
* Creates an Aztec Account.
|
|
11
10
|
* @returns The account's address & public key.
|
|
12
11
|
*/
|
|
13
|
-
export async function createAccounts(aztecRpcClient, privateKey, salt = Fr.random(), numberOfAccounts = 1, logger = createDebugLogger('aztec:aztec.js:accounts')) {
|
|
14
|
-
const accountAbi = SchnorrAccountContractAbi;
|
|
12
|
+
export async function createAccounts(aztecRpcClient, accountContractAbi, privateKey, salt = Fr.random(), numberOfAccounts = 1, logger = createDebugLogger('aztec:aztec.js:accounts')) {
|
|
15
13
|
const accountImpls = new AccountCollection();
|
|
16
|
-
const wasm = await CircuitsWasm.get();
|
|
17
14
|
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
18
15
|
// TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key
|
|
19
16
|
const privKey = i == 0 && privateKey ? privateKey : randomBytes(32);
|
|
20
17
|
const publicKey = await generatePublicKey(privKey);
|
|
21
|
-
const deploymentInfo = await getContractDeploymentInfo(
|
|
22
|
-
await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress
|
|
23
|
-
const contractDeployer = new ContractDeployer(
|
|
18
|
+
const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
|
|
19
|
+
await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress);
|
|
20
|
+
const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey);
|
|
24
21
|
const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
|
|
25
22
|
await tx.isMined(0, 0.5);
|
|
26
23
|
const receipt = await tx.getReceipt();
|
|
@@ -32,7 +29,7 @@ export async function createAccounts(aztecRpcClient, privateKey, salt = Fr.rando
|
|
|
32
29
|
throw new Error(`Deployment address does not match for account contract (expected ${deploymentInfo.address.toString()} got ${address.toString()})`);
|
|
33
30
|
}
|
|
34
31
|
logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`);
|
|
35
|
-
accountImpls.registerAccount(address, new
|
|
32
|
+
accountImpls.registerAccount(address, new SingleKeyAccountContract(address, deploymentInfo.partialAddress, privKey, await Schnorr.new()));
|
|
36
33
|
}
|
|
37
34
|
return new AccountWallet(aztecRpcClient, accountImpls);
|
|
38
35
|
}
|
|
@@ -42,13 +39,12 @@ export async function createAccounts(aztecRpcClient, privateKey, salt = Fr.rando
|
|
|
42
39
|
* @param numberOfAccounts - The number of accounts to fetch.
|
|
43
40
|
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
44
41
|
*/
|
|
45
|
-
export async function getAccountWallet(aztecRpcClient, privateKey, salt) {
|
|
46
|
-
const wasm = await CircuitsWasm.get();
|
|
42
|
+
export async function getAccountWallet(aztecRpcClient, accountContractAbi, privateKey, salt) {
|
|
47
43
|
const accountCollection = new AccountCollection();
|
|
48
44
|
const publicKey = await generatePublicKey(privateKey);
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
accountCollection.registerAccount(address, new
|
|
45
|
+
const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
|
|
46
|
+
const address = deploymentInfo.address;
|
|
47
|
+
accountCollection.registerAccount(address, new SingleKeyAccountContract(address, deploymentInfo.partialAddress, privateKey, await Schnorr.new()));
|
|
52
48
|
return new AccountWallet(aztecRpcClient, accountCollection);
|
|
53
49
|
}
|
|
54
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9hY2NvdW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUseUJBQXlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNuRSxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFMUQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzFELE9BQU8sRUFBWSxRQUFRLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFbEQsT0FBTyxFQUFFLGFBQWEsRUFBVSxNQUFNLCtCQUErQixDQUFDO0FBQ3RFLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxnQkFBZ0IsRUFBRSx3QkFBd0IsRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUUvRzs7O0dBR0c7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLGNBQWMsQ0FDbEMsY0FBd0IsRUFDeEIsa0JBQStCLEVBQy9CLFVBQW1CLEVBQ25CLElBQUksR0FBRyxFQUFFLENBQUMsTUFBTSxFQUFFLEVB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FBQztJQUNsRCxNQUFNLFNBQVMsR0FBRyxNQUFNLGlCQUFpQixDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQ3RELE1BQU0sY0FBYyxHQUFHLE1BQU0seUJBQXlCLENBQUMsa0JBQWtCLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBRSxTQUFTLENBQUMsQ0FBQztJQUNoRyxNQUFNLE9BQU8sR0FBRyxjQUFjLENBQUMsT0FBTyxDQUFDO0lBRXZDLGlCQUFpQixDQUFDLGVBQWUsQ0FDL0IsT0FBTyxFQUNQLElBQUksd0JBQXdCLENBQUMsT0FBTyxFQUFFLGNBQWMsQ0FBQyxjQUFjLEVBQUUsVUFBVSxFQUFFLE1BQU0sT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDLENBQ3RHLENBQUM7SUFDRixPQUFPLElBQUksYUFBYSxDQUFDLGNBQWMsRUFBRSxpQkFBaUIsQ0FBQyxDQUFDO0FBQzlELENBQUMifQ==
|
|
@@ -15,6 +15,14 @@ export type L1ContractAddresses = {
|
|
|
15
15
|
* Address of the L1/L2 messaging inbox contract.
|
|
16
16
|
*/
|
|
17
17
|
inbox: EthAddress;
|
|
18
|
+
/**
|
|
19
|
+
* Address of the L1/L2 messaging outbox contract.
|
|
20
|
+
*/
|
|
21
|
+
outbox: EthAddress;
|
|
22
|
+
/**
|
|
23
|
+
* Address of the decoder helper contract
|
|
24
|
+
*/
|
|
25
|
+
decoderHelper?: EthAddress;
|
|
18
26
|
/**
|
|
19
27
|
* Registry Address.
|
|
20
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l1_contracts.d.ts","sourceRoot":"","sources":["../../src/utils/l1_contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"l1_contracts.d.ts","sourceRoot":"","sources":["../../src/utils/l1_contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,yBAAyB,EAAE,UAAU,CAAC;IACtC;;OAEG;IACH,KAAK,EAAE,UAAU,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC;IAE3B;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AASF,eAAO,MAAM,sBAAsB,QAAe,MAAM,KAAG,QAAQ,mBAAmB,CAkBrF,CAAC"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/circuits.js';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
2
3
|
export const getL1ContractAddresses = async (url) => {
|
|
3
4
|
const reqUrl = new URL(`${url}/api/l1-contract-addresses`);
|
|
4
|
-
const response =
|
|
5
|
+
const response = await retryUntil(async () => {
|
|
6
|
+
try {
|
|
7
|
+
return (await (await fetch(reqUrl.toString())).json());
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
// do nothing
|
|
11
|
+
}
|
|
12
|
+
}, 'isSandboxReady', 120, 1);
|
|
5
13
|
const result = Object.fromEntries(Object.entries(response).map(([key, value]) => [key, EthAddress.fromString(value)]));
|
|
6
14
|
return result;
|
|
7
15
|
};
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfY29udHJhY3RzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2wxX2NvbnRyYWN0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0J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
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@aztec/circuits.js": "0.1.0-
|
|
8
|
-
"@aztec/foundation": "0.1.0-
|
|
9
|
-
"@aztec/
|
|
10
|
-
"@aztec/types": "0.1.0-alpha23",
|
|
7
|
+
"@aztec/circuits.js": "0.1.0-alpha25",
|
|
8
|
+
"@aztec/foundation": "0.1.0-alpha25",
|
|
9
|
+
"@aztec/types": "0.1.0-alpha25",
|
|
11
10
|
"tslib": "^2.4.0"
|
|
12
11
|
}
|
|
13
12
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "EcdsaAccount",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "constructor",
|
|
6
|
+
"functionType": "secret",
|
|
7
|
+
"parameters": [
|
|
8
|
+
{
|
|
9
|
+
"name": "signing_pub_key_x",
|
|
10
|
+
"type": {
|
|
11
|
+
"kind": "array",
|
|
12
|
+
"length": 32,
|
|
13
|
+
"type": {
|
|
14
|
+
"kind": "integer",
|
|
15
|
+
"sign": "unsigned",
|
|
16
|
+
"width": 8
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"visibility": "public"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "signing_pub_key_y",
|
|
23
|
+
"type": {
|
|
24
|
+
"kind": "array",
|
|
25
|
+
"length": 32,
|
|
26
|
+
"type": {
|
|
27
|
+
"kind": "integer",
|
|
28
|
+
"sign": "unsigned",
|
|
29
|
+
"width": 8
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"visibility": "public"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"returnTypes": []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "entrypoint",
|
|
39
|
+
"functionType": "secret",
|
|
40
|
+
"parameters": [
|
|
41
|
+
{
|
|
42
|
+
"name": "payload",
|
|
43
|
+
"type": {
|
|
44
|
+
"kind": "struct",
|
|
45
|
+
"fields": [
|
|
46
|
+
{
|
|
47
|
+
"name": "flattened_args_hashes",
|
|
48
|
+
"type": {
|
|
49
|
+
"kind": "array",
|
|
50
|
+
"length": 2,
|
|
51
|
+
"type": {
|
|
52
|
+
"kind": "field"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "flattened_selectors",
|
|
58
|
+
"type": {
|
|
59
|
+
"kind": "array",
|
|
60
|
+
"length": 2,
|
|
61
|
+
"type": {
|
|
62
|
+
"kind": "field"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "flattened_targets",
|
|
68
|
+
"type": {
|
|
69
|
+
"kind": "array",
|
|
70
|
+
"length": 2,
|
|
71
|
+
"type": {
|
|
72
|
+
"kind": "field"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "nonce",
|
|
78
|
+
"type": {
|
|
79
|
+
"kind": "field"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"visibility": "public"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "signature",
|
|
88
|
+
"type": {
|
|
89
|
+
"kind": "array",
|
|
90
|
+
"length": 64,
|
|
91
|
+
"type": {
|
|
92
|
+
"kind": "integer",
|
|
93
|
+
"sign": "unsigned",
|
|
94
|
+
"width": 8
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"visibility": "public"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"returnTypes": []
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "stev",
|
|
104
|
+
"functionType": "unconstrained",
|
|
105
|
+
"parameters": [
|
|
106
|
+
{
|
|
107
|
+
"name": "contract_address",
|
|
108
|
+
"type": {
|
|
109
|
+
"kind": "field"
|
|
110
|
+
},
|
|
111
|
+
"visibility": "private"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "nonce",
|
|
115
|
+
"type": {
|
|
116
|
+
"kind": "field"
|
|
117
|
+
},
|
|
118
|
+
"visibility": "private"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "storage_slot",
|
|
122
|
+
"type": {
|
|
123
|
+
"kind": "field"
|
|
124
|
+
},
|
|
125
|
+
"visibility": "private"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "preimage",
|
|
129
|
+
"type": {
|
|
130
|
+
"kind": "array",
|
|
131
|
+
"length": 5,
|
|
132
|
+
"type": {
|
|
133
|
+
"kind": "field"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"visibility": "private"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"returnTypes": [
|
|
140
|
+
{
|
|
141
|
+
"kind": "array",
|
|
142
|
+
"length": 4,
|
|
143
|
+
"type": {
|
|
144
|
+
"kind": "field"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "SchnorrAccount",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "constructor",
|
|
6
|
+
"functionType": "secret",
|
|
7
|
+
"parameters": [],
|
|
8
|
+
"returnTypes": []
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "entrypoint",
|
|
12
|
+
"functionType": "secret",
|
|
13
|
+
"parameters": [
|
|
14
|
+
{
|
|
15
|
+
"name": "payload",
|
|
16
|
+
"type": {
|
|
17
|
+
"kind": "struct",
|
|
18
|
+
"fields": [
|
|
19
|
+
{
|
|
20
|
+
"name": "flattened_args_hashes",
|
|
21
|
+
"type": {
|
|
22
|
+
"kind": "array",
|
|
23
|
+
"length": 2,
|
|
24
|
+
"type": {
|
|
25
|
+
"kind": "field"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "flattened_selectors",
|
|
31
|
+
"type": {
|
|
32
|
+
"kind": "array",
|
|
33
|
+
"length": 2,
|
|
34
|
+
"type": {
|
|
35
|
+
"kind": "field"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "flattened_targets",
|
|
41
|
+
"type": {
|
|
42
|
+
"kind": "array",
|
|
43
|
+
"length": 2,
|
|
44
|
+
"type": {
|
|
45
|
+
"kind": "field"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "nonce",
|
|
51
|
+
"type": {
|
|
52
|
+
"kind": "field"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"visibility": "public"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "owner",
|
|
61
|
+
"type": {
|
|
62
|
+
"kind": "array",
|
|
63
|
+
"length": 64,
|
|
64
|
+
"type": {
|
|
65
|
+
"kind": "integer",
|
|
66
|
+
"sign": "unsigned",
|
|
67
|
+
"width": 8
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"visibility": "public"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "signature",
|
|
74
|
+
"type": {
|
|
75
|
+
"kind": "array",
|
|
76
|
+
"length": 64,
|
|
77
|
+
"type": {
|
|
78
|
+
"kind": "integer",
|
|
79
|
+
"sign": "unsigned",
|
|
80
|
+
"width": 8
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"visibility": "public"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "partial_address",
|
|
87
|
+
"type": {
|
|
88
|
+
"kind": "field"
|
|
89
|
+
},
|
|
90
|
+
"visibility": "public"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"returnTypes": []
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "SchnorrSingleKeyAccount",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "constructor",
|
|
6
|
+
"functionType": "secret",
|
|
7
|
+
"parameters": [],
|
|
8
|
+
"returnTypes": []
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "entrypoint",
|
|
12
|
+
"functionType": "secret",
|
|
13
|
+
"parameters": [
|
|
14
|
+
{
|
|
15
|
+
"name": "payload",
|
|
16
|
+
"type": {
|
|
17
|
+
"kind": "struct",
|
|
18
|
+
"fields": [
|
|
19
|
+
{
|
|
20
|
+
"name": "flattened_args_hashes",
|
|
21
|
+
"type": {
|
|
22
|
+
"kind": "array",
|
|
23
|
+
"length": 2,
|
|
24
|
+
"type": {
|
|
25
|
+
"kind": "field"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "flattened_selectors",
|
|
31
|
+
"type": {
|
|
32
|
+
"kind": "array",
|
|
33
|
+
"length": 2,
|
|
34
|
+
"type": {
|
|
35
|
+
"kind": "field"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "flattened_targets",
|
|
41
|
+
"type": {
|
|
42
|
+
"kind": "array",
|
|
43
|
+
"length": 2,
|
|
44
|
+
"type": {
|
|
45
|
+
"kind": "field"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "nonce",
|
|
51
|
+
"type": {
|
|
52
|
+
"kind": "field"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"visibility": "public"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "owner",
|
|
61
|
+
"type": {
|
|
62
|
+
"kind": "array",
|
|
63
|
+
"length": 64,
|
|
64
|
+
"type": {
|
|
65
|
+
"kind": "integer",
|
|
66
|
+
"sign": "unsigned",
|
|
67
|
+
"width": 8
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"visibility": "public"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "signature",
|
|
74
|
+
"type": {
|
|
75
|
+
"kind": "array",
|
|
76
|
+
"length": 64,
|
|
77
|
+
"type": {
|
|
78
|
+
"kind": "integer",
|
|
79
|
+
"sign": "unsigned",
|
|
80
|
+
"width": 8
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"visibility": "public"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "partial_address",
|
|
87
|
+
"type": {
|
|
88
|
+
"kind": "field"
|
|
89
|
+
},
|
|
90
|
+
"visibility": "public"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"returnTypes": []
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CircuitsWasm, Fr } from '@aztec/circuits.js';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
+
import { sha256 } from '@aztec/foundation/crypto';
|
|
4
|
+
import { ExecutionRequest, PackedArguments, emptyExecutionRequest } from '@aztec/types';
|
|
5
|
+
|
|
6
|
+
const ACCOUNT_MAX_PRIVATE_CALLS = 1;
|
|
7
|
+
const ACCOUNT_MAX_PUBLIC_CALLS = 1;
|
|
8
|
+
|
|
9
|
+
/** Encoded payload for the account contract entrypoint */
|
|
10
|
+
export type EntrypointPayload = {
|
|
11
|
+
// eslint-disable-next-line camelcase
|
|
12
|
+
/** Concatenated arguments for every call */
|
|
13
|
+
flattened_args_hashes: Fr[];
|
|
14
|
+
// eslint-disable-next-line camelcase
|
|
15
|
+
/** Concatenated selectors for every call */
|
|
16
|
+
flattened_selectors: Fr[];
|
|
17
|
+
// eslint-disable-next-line camelcase
|
|
18
|
+
/** Concatenated target addresses for every call */
|
|
19
|
+
flattened_targets: Fr[];
|
|
20
|
+
/** A nonce for replay protection */
|
|
21
|
+
nonce: Fr;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Assembles an entrypoint payload from a set of private and public function calls */
|
|
25
|
+
export async function buildPayload(
|
|
26
|
+
privateCalls: ExecutionRequest[],
|
|
27
|
+
publicCalls: ExecutionRequest[],
|
|
28
|
+
): Promise<{
|
|
29
|
+
/** The payload for the entrypoint function */
|
|
30
|
+
payload: EntrypointPayload;
|
|
31
|
+
/** The packed arguments of functions called */
|
|
32
|
+
packedArguments: PackedArguments[];
|
|
33
|
+
}> {
|
|
34
|
+
const nonce = Fr.random();
|
|
35
|
+
|
|
36
|
+
const calls = [
|
|
37
|
+
...padArrayEnd(privateCalls, emptyExecutionRequest(), ACCOUNT_MAX_PRIVATE_CALLS),
|
|
38
|
+
...padArrayEnd(publicCalls, emptyExecutionRequest(), ACCOUNT_MAX_PUBLIC_CALLS),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const packedArguments = [];
|
|
42
|
+
const wasm = await CircuitsWasm.get();
|
|
43
|
+
|
|
44
|
+
for (const call of calls) {
|
|
45
|
+
packedArguments.push(await PackedArguments.fromArgs(call.args, wasm));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
payload: {
|
|
50
|
+
// eslint-disable-next-line camelcase
|
|
51
|
+
flattened_args_hashes: packedArguments.map(args => args.hash),
|
|
52
|
+
// eslint-disable-next-line camelcase
|
|
53
|
+
flattened_selectors: calls.map(call => Fr.fromBuffer(call.functionData.functionSelectorBuffer)),
|
|
54
|
+
// eslint-disable-next-line camelcase
|
|
55
|
+
flattened_targets: calls.map(call => call.to.toField()),
|
|
56
|
+
nonce,
|
|
57
|
+
},
|
|
58
|
+
packedArguments,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Hashes an entrypoint payload (useful for signing) */
|
|
63
|
+
export function hashPayload(payload: EntrypointPayload) {
|
|
64
|
+
// TODO: Switch to keccak when avaiable in Noir
|
|
65
|
+
return sha256(Buffer.concat(flattenPayload(payload).map(fr => fr.toBuffer())));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Flattens an entrypoint payload */
|
|
69
|
+
export function flattenPayload(payload: EntrypointPayload) {
|
|
70
|
+
return [
|
|
71
|
+
...payload.flattened_args_hashes,
|
|
72
|
+
...payload.flattened_selectors,
|
|
73
|
+
...payload.flattened_targets,
|
|
74
|
+
payload.nonce,
|
|
75
|
+
];
|
|
76
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AztecAddress, TxContext } from '@aztec/circuits.js';
|
|
2
2
|
import { ExecutionRequest, TxExecutionRequest } from '@aztec/types';
|
|
3
3
|
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './single_key_account_contract.js';
|
|
5
|
+
export * from './stored_key_account_contract.js';
|
|
5
6
|
export * from './account_collection.js';
|
|
6
7
|
|
|
7
8
|
/** Represents an implementation for a user account contract. Knows how to encode and sign a tx for that particular implementation. */
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AztecAddress, CircuitsWasm, FunctionData, PartialContractAddress, TxContext } from '@aztec/circuits.js';
|
|
2
|
+
import { Signer } from '@aztec/circuits.js/barretenberg';
|
|
3
|
+
import { ContractAbi, encodeArguments, generateFunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { ExecutionRequest, PackedArguments, TxExecutionRequest } from '@aztec/types';
|
|
5
|
+
|
|
6
|
+
import partition from 'lodash.partition';
|
|
7
|
+
|
|
8
|
+
import SchnorrSingleKeyAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
|
|
9
|
+
import { generatePublicKey } from '../index.js';
|
|
10
|
+
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
11
|
+
import { AccountImplementation } from './index.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Account contract implementation that uses a single key for signing and encryption. This public key is not
|
|
15
|
+
* stored in the contract, but rather verified against the contract address. Note that this approach is not
|
|
16
|
+
* secure and should not be used in real use cases.
|
|
17
|
+
*/
|
|
18
|
+
export class SingleKeyAccountContract implements AccountImplementation {
|
|
19
|
+
constructor(
|
|
20
|
+
private address: AztecAddress,
|
|
21
|
+
private partialContractAddress: PartialContractAddress,
|
|
22
|
+
private privateKey: Buffer,
|
|
23
|
+
private signer: Signer,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
getAddress(): AztecAddress {
|
|
27
|
+
return this.address;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async createAuthenticatedTxRequest(
|
|
31
|
+
executions: ExecutionRequest[],
|
|
32
|
+
txContext: TxContext,
|
|
33
|
+
): Promise<TxExecutionRequest> {
|
|
34
|
+
this.checkSender(executions);
|
|
35
|
+
this.checkIsNotDeployment(txContext);
|
|
36
|
+
|
|
37
|
+
const [privateCalls, publicCalls] = partition(executions, exec => exec.functionData.isPrivate);
|
|
38
|
+
const wasm = await CircuitsWasm.get();
|
|
39
|
+
const { payload, packedArguments: callsPackedArguments } = await buildPayload(privateCalls, publicCalls);
|
|
40
|
+
const hash = hashPayload(payload);
|
|
41
|
+
|
|
42
|
+
const signature = this.signer.constructSignature(hash, this.privateKey).toBuffer();
|
|
43
|
+
const publicKey = await generatePublicKey(this.privateKey);
|
|
44
|
+
const args = [payload, publicKey.toBuffer(), signature, this.partialContractAddress];
|
|
45
|
+
const abi = this.getEntrypointAbi();
|
|
46
|
+
const selector = generateFunctionSelector(abi.name, abi.parameters);
|
|
47
|
+
const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, args), wasm);
|
|
48
|
+
const txRequest = TxExecutionRequest.from({
|
|
49
|
+
argsHash: packedArgs.hash,
|
|
50
|
+
origin: this.address,
|
|
51
|
+
functionData: new FunctionData(selector, true, false),
|
|
52
|
+
txContext,
|
|
53
|
+
packedArguments: [...callsPackedArguments, packedArgs],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return txRequest;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private getEntrypointAbi() {
|
|
60
|
+
// We use the SchnorrSingleKeyAccountContract because it implements the interface we need, but ideally
|
|
61
|
+
// we should have an interface that defines the entrypoint for SingleKeyAccountContracts and
|
|
62
|
+
// load the abi from it.
|
|
63
|
+
const abi = (SchnorrSingleKeyAccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
|
|
64
|
+
if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
|
|
65
|
+
return abi;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private checkIsNotDeployment(txContext: TxContext) {
|
|
69
|
+
if (txContext.isContractDeploymentTx) {
|
|
70
|
+
throw new Error(`Cannot yet deploy contracts from an account contract`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private checkSender(executions: ExecutionRequest[]) {
|
|
75
|
+
const wrongSender = executions.find(e => !e.from.equals(this.address));
|
|
76
|
+
if (wrongSender) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Sender ${wrongSender.from.toString()} does not match account address ${this.address.toString()}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|