@aztec/accounts 0.35.1 → 0.37.0
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/dest/artifacts/EcdsaAccount.json +1 -1
- package/dest/artifacts/SchnorrAccount.json +1 -1
- package/dest/artifacts/SchnorrSingleKeyAccount.json +1 -1
- package/dest/defaults/account_contract.d.ts +2 -1
- package/dest/defaults/account_contract.d.ts.map +1 -1
- package/dest/defaults/account_contract.js +3 -3
- package/dest/defaults/account_interface.d.ts +3 -1
- package/dest/defaults/account_interface.d.ts.map +1 -1
- package/dest/defaults/account_interface.js +6 -2
- package/dest/ecdsa/index.d.ts +4 -4
- package/dest/ecdsa/index.d.ts.map +1 -1
- package/dest/ecdsa/index.js +4 -4
- package/dest/schnorr/index.d.ts +3 -3
- package/dest/schnorr/index.d.ts.map +1 -1
- package/dest/schnorr/index.js +4 -4
- package/dest/single_key/index.d.ts +4 -4
- package/dest/single_key/index.d.ts.map +1 -1
- package/dest/single_key/index.js +8 -5
- package/dest/testing/configuration.d.ts +5 -4
- package/dest/testing/configuration.d.ts.map +1 -1
- package/dest/testing/configuration.js +22 -13
- package/dest/testing/create_account.d.ts +3 -3
- package/dest/testing/create_account.d.ts.map +1 -1
- package/dest/testing/create_account.js +9 -4
- package/package.json +16 -8
- package/src/artifacts/EcdsaAccount.json +1 -1
- package/src/artifacts/SchnorrAccount.json +1 -1
- package/src/artifacts/SchnorrSingleKeyAccount.json +1 -1
- package/src/defaults/account_contract.ts +3 -2
- package/src/defaults/account_interface.ts +5 -0
- package/src/ecdsa/index.ts +5 -10
- package/src/schnorr/index.ts +4 -4
- package/src/single_key/index.ts +7 -14
- package/src/testing/configuration.ts +26 -17
- package/src/testing/create_account.ts +11 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AccountContract, type AccountInterface, type AuthWitnessProvider } from '@aztec/aztec.js/account';
|
|
2
2
|
import { type CompleteAddress } from '@aztec/circuit-types';
|
|
3
|
+
import { type Fr } from '@aztec/circuits.js';
|
|
3
4
|
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
4
5
|
import { type NodeInfo } from '@aztec/types/interfaces';
|
|
5
6
|
|
|
@@ -19,7 +20,7 @@ export abstract class DefaultAccountContract implements AccountContract {
|
|
|
19
20
|
return this.artifact;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
getInterface(address: CompleteAddress, nodeInfo: NodeInfo): AccountInterface {
|
|
23
|
-
return new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, nodeInfo);
|
|
23
|
+
getInterface(address: CompleteAddress, publicKeysHash: Fr, nodeInfo: NodeInfo): AccountInterface {
|
|
24
|
+
return new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, publicKeysHash, nodeInfo);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -17,6 +17,7 @@ export class DefaultAccountInterface implements AccountInterface {
|
|
|
17
17
|
constructor(
|
|
18
18
|
private authWitnessProvider: AuthWitnessProvider,
|
|
19
19
|
private address: CompleteAddress,
|
|
20
|
+
private publicKeysHash: Fr,
|
|
20
21
|
nodeInfo: Pick<NodeInfo, 'chainId' | 'protocolVersion'>,
|
|
21
22
|
) {
|
|
22
23
|
this.entrypoint = new DefaultAccountEntrypoint(
|
|
@@ -37,6 +38,10 @@ export class DefaultAccountInterface implements AccountInterface {
|
|
|
37
38
|
return this.authWitnessProvider.createAuthWit(messageHash);
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
getPublicKeysHash(): Fr {
|
|
42
|
+
return this.publicKeysHash;
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
getCompleteAddress(): CompleteAddress {
|
|
41
46
|
return this.address;
|
|
42
47
|
}
|
package/src/ecdsa/index.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { AccountManager, type Salt } from '@aztec/aztec.js/account';
|
|
8
8
|
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
|
|
9
|
-
import { type
|
|
10
|
-
import { type AztecAddress } from '@aztec/circuits.js';
|
|
9
|
+
import { type PXE } from '@aztec/circuit-types';
|
|
10
|
+
import { type AztecAddress, type Fr } from '@aztec/circuits.js';
|
|
11
11
|
|
|
12
12
|
import { EcdsaAccountContract } from './account_contract.js';
|
|
13
13
|
|
|
@@ -17,17 +17,12 @@ export { EcdsaAccountContract };
|
|
|
17
17
|
/**
|
|
18
18
|
* Creates an Account that relies on an ECDSA signing key for authentication.
|
|
19
19
|
* @param pxe - An PXE server instance.
|
|
20
|
-
* @param
|
|
20
|
+
* @param secretKey - Secret key used to derive all the keystore keys.
|
|
21
21
|
* @param signingPrivateKey - Secp256k1 key used for signing transactions.
|
|
22
22
|
* @param salt - Deployment salt.
|
|
23
23
|
*/
|
|
24
|
-
export function getEcdsaAccount(
|
|
25
|
-
pxe
|
|
26
|
-
encryptionPrivateKey: GrumpkinPrivateKey,
|
|
27
|
-
signingPrivateKey: Buffer,
|
|
28
|
-
salt?: Salt,
|
|
29
|
-
): AccountManager {
|
|
30
|
-
return new AccountManager(pxe, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), salt);
|
|
24
|
+
export function getEcdsaAccount(pxe: PXE, secretKey: Fr, signingPrivateKey: Buffer, salt?: Salt): AccountManager {
|
|
25
|
+
return new AccountManager(pxe, secretKey, new EcdsaAccountContract(signingPrivateKey), salt);
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
/**
|
package/src/schnorr/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { AccountManager, type Salt } from '@aztec/aztec.js/account';
|
|
8
8
|
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
|
|
9
9
|
import { type GrumpkinPrivateKey, type PXE } from '@aztec/circuit-types';
|
|
10
|
-
import { type AztecAddress } from '@aztec/circuits.js';
|
|
10
|
+
import { type AztecAddress, type Fr } from '@aztec/circuits.js';
|
|
11
11
|
|
|
12
12
|
import { SchnorrAccountContract } from './account_contract.js';
|
|
13
13
|
|
|
@@ -18,17 +18,17 @@ export { SchnorrAccountContractArtifact } from './artifact.js';
|
|
|
18
18
|
/**
|
|
19
19
|
* Creates an Account Manager that relies on a Grumpkin signing key for authentication.
|
|
20
20
|
* @param pxe - An PXE server instance.
|
|
21
|
-
* @param
|
|
21
|
+
* @param secretKey - Secret key used to derive all the keystore keys.
|
|
22
22
|
* @param signingPrivateKey - Grumpkin key used for signing transactions.
|
|
23
23
|
* @param salt - Deployment salt.
|
|
24
24
|
*/
|
|
25
25
|
export function getSchnorrAccount(
|
|
26
26
|
pxe: PXE,
|
|
27
|
-
|
|
27
|
+
secretKey: Fr,
|
|
28
28
|
signingPrivateKey: GrumpkinPrivateKey,
|
|
29
29
|
salt?: Salt,
|
|
30
30
|
): AccountManager {
|
|
31
|
-
return new AccountManager(pxe,
|
|
31
|
+
return new AccountManager(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
package/src/single_key/index.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { AccountManager, type Salt } from '@aztec/aztec.js/account';
|
|
8
8
|
import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
|
|
9
9
|
import { type GrumpkinPrivateKey, type PXE } from '@aztec/circuit-types';
|
|
10
|
-
import { type AztecAddress } from '@aztec/circuits.js';
|
|
10
|
+
import { type AztecAddress, type Fr, GeneratorIndex } from '@aztec/circuits.js';
|
|
11
|
+
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto';
|
|
11
12
|
|
|
12
13
|
import { SingleKeyAccountContract } from './account_contract.js';
|
|
13
14
|
|
|
@@ -18,20 +19,12 @@ export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArti
|
|
|
18
19
|
/**
|
|
19
20
|
* Creates an Account that uses the same Grumpkin key for encryption and authentication.
|
|
20
21
|
* @param pxe - An PXE server instance.
|
|
21
|
-
* @param
|
|
22
|
-
* @param salt - Deployment salt
|
|
22
|
+
* @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key).
|
|
23
|
+
* @param salt - Deployment salt.
|
|
23
24
|
*/
|
|
24
|
-
export function getSingleKeyAccount(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
salt?: Salt,
|
|
28
|
-
): AccountManager {
|
|
29
|
-
return new AccountManager(
|
|
30
|
-
pxe,
|
|
31
|
-
encryptionAndSigningPrivateKey,
|
|
32
|
-
new SingleKeyAccountContract(encryptionAndSigningPrivateKey),
|
|
33
|
-
salt,
|
|
34
|
-
);
|
|
25
|
+
export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt): AccountManager {
|
|
26
|
+
const encryptionPrivateKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]);
|
|
27
|
+
return new AccountManager(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
/**
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { generatePublicKey } from '@aztec/aztec.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet';
|
|
3
3
|
import { type PXE } from '@aztec/circuit-types';
|
|
4
|
-
import {
|
|
4
|
+
import { GeneratorIndex } from '@aztec/circuits.js/constants';
|
|
5
|
+
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto';
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
7
|
|
|
6
8
|
import { getSchnorrAccount } from '../schnorr/index.js';
|
|
7
9
|
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export const INITIAL_TEST_SECRET_KEYS = [
|
|
11
|
+
Fr.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
|
|
12
|
+
Fr.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'),
|
|
13
|
+
Fr.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'),
|
|
12
14
|
];
|
|
13
15
|
|
|
16
|
+
export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey =>
|
|
17
|
+
sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]),
|
|
18
|
+
);
|
|
19
|
+
// TODO(#5837): come up with a standard signing key derivation scheme instead of using ivsk_m as signing keys here
|
|
14
20
|
export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS;
|
|
15
21
|
|
|
16
22
|
export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
@@ -20,9 +26,9 @@ export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
|
20
26
|
* @param pxe - PXE instance.
|
|
21
27
|
* @returns A set of AccountWallet implementations for each of the initial accounts.
|
|
22
28
|
*/
|
|
23
|
-
export function getInitialTestAccountsWallets(pxe: PXE): Promise<
|
|
29
|
+
export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
|
|
24
30
|
return Promise.all(
|
|
25
|
-
|
|
31
|
+
INITIAL_TEST_SECRET_KEYS.map((encryptionKey, i) =>
|
|
26
32
|
getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(),
|
|
27
33
|
),
|
|
28
34
|
);
|
|
@@ -33,15 +39,18 @@ export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWi
|
|
|
33
39
|
* @param pxe - PXE instance.
|
|
34
40
|
* @returns A set of AccountWallet implementations for each of the initial accounts.
|
|
35
41
|
*/
|
|
36
|
-
export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<
|
|
42
|
+
export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
|
|
37
43
|
const registeredAccounts = await pxe.getRegisteredAccounts();
|
|
38
44
|
return Promise.all(
|
|
39
|
-
|
|
40
|
-
const
|
|
45
|
+
INITIAL_TEST_SECRET_KEYS.filter(initialSecretKey => {
|
|
46
|
+
const initialEncryptionKey = sha512ToGrumpkinScalar([initialSecretKey, GeneratorIndex.IVSK_M]);
|
|
47
|
+
const publicKey = generatePublicKey(initialEncryptionKey);
|
|
41
48
|
return registeredAccounts.find(registered => registered.publicKey.equals(publicKey)) != undefined;
|
|
42
|
-
}).map(
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
}).map(secretKey => {
|
|
50
|
+
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]);
|
|
51
|
+
// TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO
|
|
52
|
+
return getSchnorrAccount(pxe, secretKey, signingKey, Fr.ZERO).getWallet();
|
|
53
|
+
}),
|
|
45
54
|
);
|
|
46
55
|
}
|
|
47
56
|
|
|
@@ -51,11 +60,11 @@ export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountW
|
|
|
51
60
|
* @returns The set of deployed Account objects and associated private encryption keys
|
|
52
61
|
*/
|
|
53
62
|
export async function deployInitialTestAccounts(pxe: PXE) {
|
|
54
|
-
const accounts =
|
|
55
|
-
const account = getSchnorrAccount(pxe,
|
|
63
|
+
const accounts = INITIAL_TEST_SECRET_KEYS.map((secretKey, i) => {
|
|
64
|
+
const account = getSchnorrAccount(pxe, secretKey, INITIAL_TEST_SIGNING_KEYS[i], INITIAL_TEST_ACCOUNT_SALTS[i]);
|
|
56
65
|
return {
|
|
57
66
|
account,
|
|
58
|
-
|
|
67
|
+
secretKey,
|
|
59
68
|
};
|
|
60
69
|
});
|
|
61
70
|
// Attempt to get as much parallelism as possible
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { type PXE } from '@aztec/circuit-types';
|
|
3
|
-
import {
|
|
3
|
+
import { Fr, GeneratorIndex } from '@aztec/circuits.js';
|
|
4
|
+
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto';
|
|
4
5
|
|
|
5
6
|
import { getSchnorrAccount } from '../schnorr/index.js';
|
|
6
7
|
|
|
@@ -9,8 +10,10 @@ import { getSchnorrAccount } from '../schnorr/index.js';
|
|
|
9
10
|
* @param pxe - PXE.
|
|
10
11
|
* @returns - A wallet for a fresh account.
|
|
11
12
|
*/
|
|
12
|
-
export function createAccount(pxe: PXE): Promise<
|
|
13
|
-
|
|
13
|
+
export function createAccount(pxe: PXE): Promise<AccountWalletWithSecretKey> {
|
|
14
|
+
const secretKey = Fr.random();
|
|
15
|
+
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]);
|
|
16
|
+
return getSchnorrAccount(pxe, secretKey, signingKey).waitSetup();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -19,12 +22,14 @@ export function createAccount(pxe: PXE): Promise<AccountWalletWithPrivateKey> {
|
|
|
19
22
|
* @param numberOfAccounts - How many accounts to create.
|
|
20
23
|
* @returns The created account wallets.
|
|
21
24
|
*/
|
|
22
|
-
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<
|
|
25
|
+
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWalletWithSecretKey[]> {
|
|
23
26
|
const accounts = [];
|
|
24
27
|
|
|
25
28
|
// Prepare deployments
|
|
26
29
|
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
27
|
-
const
|
|
30
|
+
const secretKey = Fr.random();
|
|
31
|
+
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]);
|
|
32
|
+
const account = getSchnorrAccount(pxe, secretKey, signingKey);
|
|
28
33
|
// Unfortunately the function below is not stateless and we call it here because it takes a long time to run and
|
|
29
34
|
// the results get stored within the account object. By calling it here we increase the probability of all the
|
|
30
35
|
// accounts being deployed in the same block because it makes the deploy() method basically instant.
|