@aztec/aztec.js 0.1.0-alpha20 → 0.1.0-alpha22
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/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 +2 -2
- package/dest/account_impl/account_contract.d.ts.map +1 -1
- package/dest/account_impl/account_contract.js +1 -1
- package/dest/auth/ecdsa.d.ts +3 -3
- package/dest/auth/ecdsa.d.ts.map +1 -1
- package/dest/auth/ecdsa.js +2 -2
- package/dest/auth/index.d.ts +2 -8
- package/dest/auth/index.d.ts.map +1 -1
- package/dest/auth/index.js +2 -1
- package/dest/auth/schnorr.d.ts +13 -0
- package/dest/auth/schnorr.d.ts.map +1 -0
- package/dest/auth/schnorr.js +14 -0
- 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 +1 -0
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +4 -1
- package/dest/utils/account.d.ts +10 -2
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +26 -10
- 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 +6 -6
- package/src/account_impl/account_collection.ts +4 -4
- package/src/account_impl/account_contract.ts +2 -2
- package/src/auth/ecdsa.ts +5 -5
- package/src/auth/index.ts +2 -9
- package/src/auth/schnorr.ts +13 -0
- package/src/aztec_rpc_client/aztec_rpc_client.ts +2 -41
- package/src/aztec_rpc_client/wallet.ts +3 -0
- package/src/utils/account.ts +40 -9
- package/src/utils/index.ts +1 -0
- package/src/utils/l1_contracts.ts +40 -0
- package/src/utils/pub_key.ts +0 -14
|
@@ -8,7 +8,7 @@ import partition from 'lodash.partition';
|
|
|
8
8
|
import { generateFunctionSelector } from '../index.js';
|
|
9
9
|
import { AccountImplementation } from './index.js';
|
|
10
10
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
11
|
-
import {
|
|
11
|
+
import { EcdsaAuthProvider, SchnorrAuthProvider } from '../auth/index.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Account backed by an account contract
|
|
@@ -17,7 +17,7 @@ export class AccountContract implements AccountImplementation {
|
|
|
17
17
|
constructor(
|
|
18
18
|
private address: AztecAddress,
|
|
19
19
|
private pubKey: PublicKey,
|
|
20
|
-
private authProvider:
|
|
20
|
+
private authProvider: EcdsaAuthProvider | SchnorrAuthProvider,
|
|
21
21
|
private partialContractAddress: PartialContractAddress,
|
|
22
22
|
private contractAbi: ContractAbi,
|
|
23
23
|
private wasm: CircuitsWasm,
|
package/src/auth/ecdsa.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
-
import {
|
|
3
|
-
import { AuthPayload, TxAuthProvider } from './index.js';
|
|
2
|
+
import { EcdsaSignature } from '@aztec/circuits.js/barretenberg';
|
|
4
3
|
|
|
4
|
+
import { AztecAddress } from '../index.js';
|
|
5
|
+
import { AuthPayload } from './index.js';
|
|
5
6
|
import { EntrypointPayload } from '../account_impl/account_contract.js';
|
|
6
|
-
import { EcdsaSignature } from '@aztec/circuits.js/barretenberg';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* An ecdsa implementation of
|
|
9
|
+
* An ecdsa implementation of auth provider.
|
|
10
10
|
*/
|
|
11
|
-
export class EcdsaAuthProvider
|
|
11
|
+
export class EcdsaAuthProvider {
|
|
12
12
|
constructor(private privKey: Buffer) {}
|
|
13
13
|
authenticateTx(payload: EntrypointPayload, payloadHash: Buffer, _address: AztecAddress): Promise<AuthPayload> {
|
|
14
14
|
const sig = secp256k1.sign(payloadHash, this.privKey);
|
package/src/auth/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AztecAddress, Fr } from '@aztec/circuits.js';
|
|
|
2
2
|
import { EntrypointPayload } from '../account_impl/account_contract.js';
|
|
3
3
|
|
|
4
4
|
export * from './ecdsa.js';
|
|
5
|
+
export * from './schnorr.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* An interface for the payload returned from auth operations.
|
|
@@ -11,18 +12,10 @@ export interface AuthPayload {
|
|
|
11
12
|
toFields(): Fr[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
-
* The interface for an auth operations provider.
|
|
16
|
-
* TODO: How coupled should the auth provider be a to a specific account contract implementation? Can we remove the dependency on a specific EntrypointPayload format here?
|
|
17
|
-
*/
|
|
18
|
-
export interface TxAuthProvider {
|
|
19
|
-
authenticateTx(payload: EntrypointPayload, payloadHash: Buffer, address: AztecAddress): Promise<AuthPayload>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
15
|
/**
|
|
23
16
|
* A dummy implementation of the auth provider
|
|
24
17
|
*/
|
|
25
|
-
export class DummyAuthProvider
|
|
18
|
+
export class DummyAuthProvider {
|
|
26
19
|
authenticateTx(_payload: EntrypointPayload, _payloadHash: Buffer, _address: AztecAddress): Promise<AuthPayload> {
|
|
27
20
|
return Promise.resolve({
|
|
28
21
|
toBuffer: () => Buffer.alloc(0),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
2
|
+
import { AuthPayload, AztecAddress, EntrypointPayload } from '@aztec/aztec.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Implementation of a schnorr signature provider
|
|
6
|
+
*/
|
|
7
|
+
export class SchnorrAuthProvider {
|
|
8
|
+
constructor(private signer: Schnorr, private privateKey: Buffer) {}
|
|
9
|
+
authenticateTx(_payload: EntrypointPayload, _payloadHash: Buffer, _address: AztecAddress): Promise<AuthPayload> {
|
|
10
|
+
const sig = this.signer.constructSignature(_payloadHash, this.privateKey);
|
|
11
|
+
return Promise.resolve(sig as AuthPayload);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,36 +1,6 @@
|
|
|
1
|
-
import { AztecAddress, AztecRPC, EthAddress, Fr, Point, Tx
|
|
1
|
+
import { AztecAddress, AztecRPC, EthAddress, Fr, Point, Tx } from '@aztec/aztec-rpc';
|
|
2
2
|
import { createJsonRpcClient } from '@aztec/foundation/json-rpc';
|
|
3
|
-
import { ContractData, ContractDeploymentTx, ContractPublicData, TxExecutionRequest } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A dictionary of the Aztec-deployed L1 contracts.
|
|
7
|
-
*/
|
|
8
|
-
export type L1ContractAddresses = {
|
|
9
|
-
/**
|
|
10
|
-
* Address fo the main Aztec rollup contract.
|
|
11
|
-
*/
|
|
12
|
-
rollup: EthAddress;
|
|
13
|
-
/**
|
|
14
|
-
* Address of the contract that emits events on public contract deployment.
|
|
15
|
-
*/
|
|
16
|
-
contractDeploymentEmitter: EthAddress;
|
|
17
|
-
/**
|
|
18
|
-
* Address of the L1/L2 messaging inbox contract.
|
|
19
|
-
*/
|
|
20
|
-
inbox: EthAddress;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Registry Address.
|
|
24
|
-
*/
|
|
25
|
-
registry: EthAddress;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* string dictionary of aztec contract addresses that we receive over http.
|
|
30
|
-
*/
|
|
31
|
-
type L1ContractAddressesResp = {
|
|
32
|
-
[K in keyof L1ContractAddresses]: string;
|
|
33
|
-
};
|
|
3
|
+
import { ContractData, ContractDeploymentTx, ContractPublicData, TxExecutionRequest, TxHash } from '@aztec/types';
|
|
34
4
|
|
|
35
5
|
export const createAztecRpcClient = (url: string): AztecRPC =>
|
|
36
6
|
createJsonRpcClient<AztecRPC>(
|
|
@@ -48,12 +18,3 @@ export const createAztecRpcClient = (url: string): AztecRPC =>
|
|
|
48
18
|
{ Tx, ContractDeploymentTx },
|
|
49
19
|
false,
|
|
50
20
|
);
|
|
51
|
-
|
|
52
|
-
export const getL1ContractAddresses = async (url: string): Promise<L1ContractAddresses> => {
|
|
53
|
-
const reqUrl = new URL(`${url}/api/l1-contract-addresses`);
|
|
54
|
-
const response = (await (await fetch(reqUrl.toString())).json()) as unknown as L1ContractAddressesResp;
|
|
55
|
-
const result = Object.fromEntries(
|
|
56
|
-
Object.entries(response).map(([key, value]) => [key, EthAddress.fromString(value)]),
|
|
57
|
-
);
|
|
58
|
-
return result as L1ContractAddresses;
|
|
59
|
-
};
|
|
@@ -33,6 +33,9 @@ export abstract class BaseWallet implements Wallet {
|
|
|
33
33
|
getAccountPublicKey(address: AztecAddress): Promise<Point> {
|
|
34
34
|
return this.rpc.getAccountPublicKey(address);
|
|
35
35
|
}
|
|
36
|
+
getAccountAddress(publicKey: Point): Promise<AztecAddress> {
|
|
37
|
+
return this.rpc.getAccountAddress(publicKey);
|
|
38
|
+
}
|
|
36
39
|
addContracts(contracts: DeployedContract[]): Promise<void> {
|
|
37
40
|
return this.rpc.addContracts(contracts);
|
|
38
41
|
}
|
package/src/utils/account.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { AztecRPC, TxStatus, getContractDeploymentInfo } from '@aztec/aztec-rpc';
|
|
2
|
-
import {
|
|
2
|
+
import { CircuitsWasm, Fr } from '@aztec/circuits.js';
|
|
3
3
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
4
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
5
|
+
import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/examples';
|
|
6
6
|
import { AccountWallet, Wallet } from '../aztec_rpc_client/wallet.js';
|
|
7
7
|
import {
|
|
8
8
|
AccountCollection,
|
|
9
9
|
AccountContract,
|
|
10
10
|
ContractDeployer,
|
|
11
|
-
|
|
11
|
+
SchnorrAuthProvider,
|
|
12
12
|
generatePublicKey,
|
|
13
13
|
} from '../index.js';
|
|
14
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Creates an Aztec Account.
|
|
@@ -19,41 +20,71 @@ import {
|
|
|
19
20
|
export async function createAccounts(
|
|
20
21
|
aztecRpcClient: AztecRPC,
|
|
21
22
|
privateKey?: Buffer,
|
|
23
|
+
salt = Fr.random(),
|
|
22
24
|
numberOfAccounts = 1,
|
|
23
25
|
logger = createDebugLogger('aztec:aztec.js:accounts'),
|
|
24
26
|
): Promise<Wallet> {
|
|
27
|
+
const accountAbi = SchnorrAccountContractAbi;
|
|
25
28
|
const accountImpls = new AccountCollection();
|
|
26
|
-
const results: [AztecAddress, Point][] = [];
|
|
27
29
|
const wasm = await CircuitsWasm.get();
|
|
28
30
|
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
29
31
|
// TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key
|
|
30
32
|
const privKey = i == 0 && privateKey ? privateKey : randomBytes(32);
|
|
31
|
-
const accountAbi = EcdsaAccountContractAbi;
|
|
32
33
|
const publicKey = await generatePublicKey(privKey);
|
|
33
|
-
const salt = Fr.random();
|
|
34
34
|
const deploymentInfo = await getContractDeploymentInfo(accountAbi, [], salt, publicKey);
|
|
35
35
|
await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress, accountAbi);
|
|
36
36
|
const contractDeployer = new ContractDeployer(accountAbi, aztecRpcClient, publicKey);
|
|
37
37
|
const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
|
|
38
|
-
await tx.isMined(0, 0.
|
|
38
|
+
await tx.isMined(0, 0.5);
|
|
39
39
|
const receipt = await tx.getReceipt();
|
|
40
40
|
if (receipt.status !== TxStatus.MINED) {
|
|
41
41
|
throw new Error(`Deployment tx not mined (status is ${receipt.status})`);
|
|
42
42
|
}
|
|
43
43
|
const address = receipt.contractAddress!;
|
|
44
|
+
if (!address.equals(deploymentInfo.address)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Deployment address does not match for account contract (expected ${deploymentInfo.address.toString()} got ${address.toString()})`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
44
49
|
logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`);
|
|
45
50
|
accountImpls.registerAccount(
|
|
46
51
|
address,
|
|
47
52
|
new AccountContract(
|
|
48
53
|
address,
|
|
49
54
|
publicKey,
|
|
50
|
-
new
|
|
55
|
+
new SchnorrAuthProvider(await Schnorr.new(), privKey),
|
|
51
56
|
deploymentInfo.partialAddress,
|
|
52
57
|
accountAbi,
|
|
53
58
|
wasm,
|
|
54
59
|
),
|
|
55
60
|
);
|
|
56
|
-
results.push([address, publicKey]);
|
|
57
61
|
}
|
|
58
62
|
return new AccountWallet(aztecRpcClient, accountImpls);
|
|
59
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Gets the Aztec accounts that are stored in an Aztec RPC instance.
|
|
67
|
+
* @param aztecRpcClient - An instance of the Aztec RPC interface.
|
|
68
|
+
* @param numberOfAccounts - The number of accounts to fetch.
|
|
69
|
+
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
70
|
+
*/
|
|
71
|
+
export async function getAccountWallet(aztecRpcClient: AztecRPC, privateKey: Buffer, salt: Fr) {
|
|
72
|
+
const wasm = await CircuitsWasm.get();
|
|
73
|
+
const accountCollection = new AccountCollection();
|
|
74
|
+
const publicKey = await generatePublicKey(privateKey);
|
|
75
|
+
const address = await aztecRpcClient.getAccountAddress(publicKey);
|
|
76
|
+
const deploymentInfo = await getContractDeploymentInfo(SchnorrAccountContractAbi, [], salt, publicKey);
|
|
77
|
+
|
|
78
|
+
accountCollection.registerAccount(
|
|
79
|
+
address,
|
|
80
|
+
new AccountContract(
|
|
81
|
+
address,
|
|
82
|
+
publicKey,
|
|
83
|
+
new SchnorrAuthProvider(await Schnorr.new(), privateKey),
|
|
84
|
+
deploymentInfo.partialAddress,
|
|
85
|
+
SchnorrAccountContractAbi,
|
|
86
|
+
wasm,
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
return new AccountWallet(aztecRpcClient, accountCollection);
|
|
90
|
+
}
|
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,20 +1,6 @@
|
|
|
1
1
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
2
2
|
import { Point } from '../index.js';
|
|
3
3
|
|
|
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
|
-
}
|
|
17
|
-
|
|
18
4
|
/**
|
|
19
5
|
* Method for generating a public grumpkin key from a private key.
|
|
20
6
|
* @param privateKey - The private key.
|