@aztec/accounts 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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/README.md +1 -2
- package/artifacts/EcdsaKAccount.json +10501 -4885
- package/artifacts/EcdsaRAccount.json +10521 -4905
- package/artifacts/SchnorrAccount.json +10632 -5192
- package/artifacts/SchnorrInitializerlessAccount.json +8526 -0
- package/artifacts/SimulatedEcdsaAccount.json +10976 -0
- package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
- package/artifacts/SimulatedSchnorrAccount.json +11088 -0
- package/dest/defaults/account_contract.d.ts +9 -3
- package/dest/defaults/account_contract.d.ts.map +1 -1
- package/dest/defaults/account_contract.js +11 -3
- package/dest/defaults/index.d.ts +1 -2
- package/dest/defaults/index.d.ts.map +1 -1
- package/dest/defaults/index.js +1 -2
- package/dest/{stub/account_contract.d.ts → defaults/stub_account_contract.d.ts} +2 -2
- package/dest/defaults/stub_account_contract.d.ts.map +1 -0
- package/dest/ecdsa/ecdsa_k/account_contract.d.ts +1 -1
- package/dest/ecdsa/ecdsa_k/account_contract.js +7 -3
- package/dest/ecdsa/ecdsa_k/lazy.js +1 -1
- package/dest/ecdsa/ecdsa_r/account_contract.d.ts +1 -1
- package/dest/ecdsa/ecdsa_r/account_contract.js +7 -3
- package/dest/ecdsa/ecdsa_r/lazy.js +1 -1
- package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +1 -1
- package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +7 -3
- package/dest/ecdsa/stub/index.d.ts +11 -0
- package/dest/ecdsa/stub/index.d.ts.map +1 -0
- package/dest/ecdsa/stub/index.js +18 -0
- package/dest/ecdsa/stub/lazy.d.ts +14 -0
- package/dest/ecdsa/stub/lazy.d.ts.map +1 -0
- package/dest/ecdsa/stub/lazy.js +22 -0
- package/dest/schnorr/account_contract.d.ts +10 -5
- package/dest/schnorr/account_contract.d.ts.map +1 -1
- package/dest/schnorr/account_contract.js +7 -6
- package/dest/schnorr/index.d.ts +3 -22
- package/dest/schnorr/index.d.ts.map +1 -1
- package/dest/schnorr/index.js +2 -35
- package/dest/schnorr/initializerless/index.d.ts +25 -0
- package/dest/schnorr/initializerless/index.d.ts.map +1 -0
- package/dest/schnorr/initializerless/index.js +46 -0
- package/dest/schnorr/initializerless/lazy.d.ts +29 -0
- package/dest/schnorr/initializerless/lazy.d.ts.map +1 -0
- package/dest/schnorr/initializerless/lazy.js +54 -0
- package/dest/schnorr/lazy.d.ts +3 -26
- package/dest/schnorr/lazy.d.ts.map +1 -1
- package/dest/schnorr/lazy.js +2 -43
- package/dest/schnorr/private_immutable/index.d.ts +23 -0
- package/dest/schnorr/private_immutable/index.d.ts.map +1 -0
- package/dest/schnorr/private_immutable/index.js +35 -0
- package/dest/schnorr/private_immutable/lazy.d.ts +27 -0
- package/dest/schnorr/private_immutable/lazy.d.ts.map +1 -0
- package/dest/schnorr/private_immutable/lazy.js +43 -0
- package/dest/schnorr/stub/index.d.ts +11 -0
- package/dest/schnorr/stub/index.d.ts.map +1 -0
- package/dest/schnorr/stub/index.js +18 -0
- package/dest/schnorr/stub/lazy.d.ts +14 -0
- package/dest/schnorr/stub/lazy.d.ts.map +1 -0
- package/dest/schnorr/stub/lazy.js +22 -0
- package/dest/testing/configuration.d.ts +13 -4
- package/dest/testing/configuration.d.ts.map +1 -1
- package/dest/testing/configuration.js +7 -3
- package/dest/testing/index.d.ts +5 -5
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +20 -12
- package/dest/testing/lazy.d.ts +4 -4
- package/dest/testing/lazy.d.ts.map +1 -1
- package/dest/testing/lazy.js +20 -12
- package/dest/utils/index.d.ts +2 -1
- package/dest/utils/index.d.ts.map +1 -1
- package/dest/utils/index.js +1 -0
- package/dest/utils/key_derivation.d.ts +9 -0
- package/dest/utils/key_derivation.d.ts.map +1 -0
- package/dest/utils/key_derivation.js +16 -0
- package/dest/utils/ssh_agent.d.ts +1 -1
- package/dest/utils/ssh_agent.d.ts.map +1 -1
- package/dest/utils/ssh_agent.js +2 -0
- package/package.json +12 -15
- package/src/defaults/account_contract.ts +18 -5
- package/src/defaults/index.ts +0 -1
- package/src/{stub/account_contract.ts → defaults/stub_account_contract.ts} +1 -1
- package/src/ecdsa/ecdsa_k/account_contract.ts +3 -3
- package/src/ecdsa/ecdsa_k/lazy.ts +1 -1
- package/src/ecdsa/ecdsa_r/account_contract.ts +3 -3
- package/src/ecdsa/ecdsa_r/lazy.ts +1 -1
- package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +3 -3
- package/src/ecdsa/stub/index.ts +28 -0
- package/src/ecdsa/stub/lazy.ts +34 -0
- package/src/schnorr/account_contract.ts +21 -7
- package/src/schnorr/index.ts +2 -49
- package/src/schnorr/initializerless/index.ts +62 -0
- package/src/schnorr/initializerless/lazy.ts +70 -0
- package/src/schnorr/lazy.ts +2 -59
- package/src/schnorr/private_immutable/index.ts +50 -0
- package/src/schnorr/private_immutable/lazy.ts +60 -0
- package/src/schnorr/stub/index.ts +30 -0
- package/src/schnorr/stub/lazy.ts +34 -0
- package/src/testing/configuration.ts +17 -3
- package/src/testing/index.ts +29 -13
- package/src/testing/lazy.ts +28 -13
- package/src/utils/index.ts +1 -0
- package/src/utils/key_derivation.ts +15 -0
- package/src/utils/ssh_agent.ts +2 -0
- package/artifacts/SchnorrSingleKeyAccount.json +0 -4679
- package/artifacts/SimulatedAccount.json +0 -4623
- package/dest/defaults/account_interface.d.ts +0 -28
- package/dest/defaults/account_interface.d.ts.map +0 -1
- package/dest/defaults/account_interface.js +0 -36
- package/dest/single_key/account_contract.d.ts +0 -17
- package/dest/single_key/account_contract.d.ts.map +0 -1
- package/dest/single_key/account_contract.js +0 -42
- package/dest/single_key/index.d.ts +0 -20
- package/dest/single_key/index.d.ts.map +0 -1
- package/dest/single_key/index.js +0 -23
- package/dest/single_key/lazy.d.ts +0 -24
- package/dest/single_key/lazy.d.ts.map +0 -1
- package/dest/single_key/lazy.js +0 -31
- package/dest/stub/account_contract.d.ts.map +0 -1
- package/dest/stub/index.d.ts +0 -21
- package/dest/stub/index.d.ts.map +0 -1
- package/dest/stub/index.js +0 -29
- package/dest/stub/lazy.d.ts +0 -23
- package/dest/stub/lazy.d.ts.map +0 -1
- package/dest/stub/lazy.js +0 -35
- package/src/defaults/account_interface.ts +0 -63
- package/src/single_key/account_contract.ts +0 -46
- package/src/single_key/index.ts +0 -32
- package/src/single_key/lazy.ts +0 -40
- package/src/stub/index.ts +0 -41
- package/src/stub/lazy.ts +0 -49
- /package/artifacts/{SchnorrSingleKeyAccount.d.json.ts → SchnorrInitializerlessAccount.d.json.ts} +0 -0
- /package/artifacts/{SimulatedAccount.d.json.ts → SimulatedEcdsaAccount.d.json.ts} +0 -0
- /package/dest/{stub/account_contract.js → defaults/stub_account_contract.js} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@aztec/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
|
|
3
|
+
* This is the suggested account contract type for most use cases within Aztec.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { getAccountContractAddress } from '@aztec/aztec.js/account';
|
|
8
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
11
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
12
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
13
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
14
|
+
|
|
15
|
+
import SchnorrAccountContractJson from '../../../artifacts/SchnorrAccount.json' with { type: 'json' };
|
|
16
|
+
import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
|
|
17
|
+
import { SchnorrBaseAccountContract } from '../account_contract.js';
|
|
18
|
+
|
|
19
|
+
export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Account contract that authenticates transactions using Schnorr signatures
|
|
23
|
+
* verified against a Grumpkin public key stored in an immutable encrypted note.
|
|
24
|
+
* Eagerly loads the contract artifact
|
|
25
|
+
*/
|
|
26
|
+
export class SchnorrAccountContract extends SchnorrBaseAccountContract {
|
|
27
|
+
constructor(signingPrivateKey: GrumpkinScalar) {
|
|
28
|
+
super(signingPrivateKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
32
|
+
return Promise.resolve(SchnorrAccountContractArtifact);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Compute the address of a schnorr account contract.
|
|
38
|
+
* @param signingPrivateKey - The account's signing private key.
|
|
39
|
+
* @param salt - The contract address salt.
|
|
40
|
+
* @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
|
|
41
|
+
*/
|
|
42
|
+
export async function getSchnorrAccountContractAddress(
|
|
43
|
+
signingPrivateKey: GrumpkinScalar,
|
|
44
|
+
salt: Fr,
|
|
45
|
+
secretKey?: Fr,
|
|
46
|
+
): Promise<AztecAddress> {
|
|
47
|
+
const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
|
|
48
|
+
const accountContract = new SchnorrAccountContract(signingPrivateKey);
|
|
49
|
+
return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
|
|
50
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@aztec/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
|
|
3
|
+
* This is the suggested account contract type for most use cases within Aztec.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { getAccountContractAddress } from '@aztec/aztec.js/account';
|
|
8
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
10
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
11
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
12
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
|
|
14
|
+
import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
|
|
15
|
+
import { SchnorrBaseAccountContract } from '../account_contract.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Lazily loads the contract artifact
|
|
19
|
+
* @returns The contract artifact for the schnorr account contract
|
|
20
|
+
*/
|
|
21
|
+
export async function getSchnorrAccountContractArtifact() {
|
|
22
|
+
// Cannot assert this import as it's incompatible with bundlers like vite
|
|
23
|
+
// https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
|
|
24
|
+
// Even if now supported by all major browsers, the MIME type is replaced with
|
|
25
|
+
// "text/javascript"
|
|
26
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
27
|
+
const { default: schnorrAccountContractJson } = await import('../../../artifacts/SchnorrAccount.json');
|
|
28
|
+
return loadContractArtifact(schnorrAccountContractJson);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Account contract that authenticates transactions using Schnorr signatures
|
|
33
|
+
* verified against a Grumpkin public key stored in an immutable encrypted note.
|
|
34
|
+
* Lazily loads the contract artifact
|
|
35
|
+
*/
|
|
36
|
+
export class SchnorrAccountContract extends SchnorrBaseAccountContract {
|
|
37
|
+
constructor(signingPrivateKey: GrumpkinScalar) {
|
|
38
|
+
super(signingPrivateKey);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
42
|
+
return getSchnorrAccountContractArtifact();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Compute the address of a schnorr account contract.
|
|
48
|
+
* @param signingPrivateKey - The account's signing private key.
|
|
49
|
+
* @param salt - The contract address salt.
|
|
50
|
+
* @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
|
|
51
|
+
*/
|
|
52
|
+
export async function getSchnorrAccountContractAddress(
|
|
53
|
+
signingPrivateKey: GrumpkinScalar,
|
|
54
|
+
salt: Fr,
|
|
55
|
+
secretKey?: Fr,
|
|
56
|
+
): Promise<AztecAddress> {
|
|
57
|
+
const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
|
|
58
|
+
const accountContract = new SchnorrAccountContract(signingPrivateKey);
|
|
59
|
+
return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseAccount } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account';
|
|
4
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
6
|
+
|
|
7
|
+
import SimulatedSchnorrAccountJson from '../../../artifacts/SimulatedSchnorrAccount.json' with { type: 'json' };
|
|
8
|
+
import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
|
|
9
|
+
|
|
10
|
+
export const StubSchnorrAccountContractArtifact = loadContractArtifact(
|
|
11
|
+
SimulatedSchnorrAccountJson as NoirCompiledContract,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/** Stub account contract for Schnorr accounts. Eagerly loads the contract artifact. */
|
|
15
|
+
export class StubSchnorrAccountContract extends StubBaseAccountContract {
|
|
16
|
+
override getContractArtifact() {
|
|
17
|
+
return Promise.resolve(StubSchnorrAccountContractArtifact);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Creates a Schnorr stub account that impersonates the one with the provided address. */
|
|
22
|
+
export function createStubSchnorrAccount(originalAddress: CompleteAddress) {
|
|
23
|
+
const accountContract = new StubSchnorrAccountContract();
|
|
24
|
+
const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
|
|
25
|
+
return new BaseAccount(
|
|
26
|
+
new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
|
|
27
|
+
authWitnessProvider,
|
|
28
|
+
originalAddress,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseAccount } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account';
|
|
4
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
5
|
+
|
|
6
|
+
import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lazily loads the Schnorr stub contract artifact (browser-compatible).
|
|
10
|
+
*/
|
|
11
|
+
export async function getStubSchnorrAccountContractArtifact() {
|
|
12
|
+
// Cannot assert this import as it's incompatible with bundlers like vite
|
|
13
|
+
// https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
|
|
14
|
+
const { default: json } = await import('../../../artifacts/SimulatedSchnorrAccount.json');
|
|
15
|
+
return loadContractArtifact(json);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Stub account contract for Schnorr accounts. Lazily loads the contract artifact. */
|
|
19
|
+
export class StubSchnorrAccountContract extends StubBaseAccountContract {
|
|
20
|
+
override getContractArtifact() {
|
|
21
|
+
return getStubSchnorrAccountContractArtifact();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Creates a Schnorr stub account that impersonates the one with the provided address. */
|
|
26
|
+
export function createStubSchnorrAccount(originalAddress: CompleteAddress) {
|
|
27
|
+
const accountContract = new StubSchnorrAccountContract();
|
|
28
|
+
const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
|
|
29
|
+
return new BaseAccount(
|
|
30
|
+
new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
|
|
31
|
+
authWitnessProvider,
|
|
32
|
+
originalAddress,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Fr
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
2
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
4
|
import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys';
|
|
4
5
|
|
|
@@ -11,11 +12,20 @@ export const INITIAL_TEST_SECRET_KEYS = [
|
|
|
11
12
|
export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey =>
|
|
12
13
|
deriveMasterIncomingViewingSecretKey(secretKey),
|
|
13
14
|
);
|
|
14
|
-
|
|
15
|
-
export const INITIAL_TEST_SIGNING_KEYS =
|
|
15
|
+
|
|
16
|
+
export const INITIAL_TEST_SIGNING_KEYS = [
|
|
17
|
+
GrumpkinScalar.fromHexString('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'),
|
|
18
|
+
GrumpkinScalar.fromHexString('202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e'),
|
|
19
|
+
GrumpkinScalar.fromHexString('404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e'),
|
|
20
|
+
];
|
|
16
21
|
|
|
17
22
|
export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
18
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The schnorr account contract variant a test account uses.
|
|
26
|
+
*/
|
|
27
|
+
export type InitialAccountType = 'schnorr' | 'schnorr_initializerless';
|
|
28
|
+
|
|
19
29
|
/**
|
|
20
30
|
* Data for generating an initial account.
|
|
21
31
|
*/
|
|
@@ -36,4 +46,8 @@ export interface InitialAccountData {
|
|
|
36
46
|
* Address of the schnorr account contract.
|
|
37
47
|
*/
|
|
38
48
|
address: AztecAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Account contract variant.
|
|
51
|
+
*/
|
|
52
|
+
type?: InitialAccountType;
|
|
39
53
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
7
|
-
import {
|
|
7
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { getSchnorrInitializerlessAccountContractAddress } from '../schnorr/initializerless/index.js';
|
|
10
|
+
import { getSchnorrAccountContractAddress } from '../schnorr/private_immutable/index.js';
|
|
11
|
+
import { deriveSecretKeyFromSigningKey } from '../utils/key_derivation.js';
|
|
10
12
|
import {
|
|
11
13
|
INITIAL_TEST_ACCOUNT_SALTS,
|
|
12
|
-
INITIAL_TEST_ENCRYPTION_KEYS,
|
|
13
14
|
INITIAL_TEST_SECRET_KEYS,
|
|
14
15
|
INITIAL_TEST_SIGNING_KEYS,
|
|
15
16
|
type InitialAccountData,
|
|
17
|
+
type InitialAccountType,
|
|
16
18
|
} from './configuration.js';
|
|
17
19
|
|
|
18
20
|
export {
|
|
@@ -21,8 +23,16 @@ export {
|
|
|
21
23
|
INITIAL_TEST_SECRET_KEYS,
|
|
22
24
|
INITIAL_TEST_SIGNING_KEYS,
|
|
23
25
|
type InitialAccountData,
|
|
26
|
+
type InitialAccountType,
|
|
24
27
|
} from './configuration.js';
|
|
25
28
|
|
|
29
|
+
/** Derives the account contract address for the given type */
|
|
30
|
+
function getTestAccountAddress(type: InitialAccountType, signingKey: GrumpkinScalar, salt: Fr, secret?: Fr) {
|
|
31
|
+
return type === 'schnorr'
|
|
32
|
+
? getSchnorrAccountContractAddress(signingKey, salt, secret)
|
|
33
|
+
: getSchnorrInitializerlessAccountContractAddress(signingKey, salt, secret);
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
/**
|
|
27
37
|
* Gets the basic information for initial test accounts.
|
|
28
38
|
*/
|
|
@@ -30,30 +40,36 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
|
|
|
30
40
|
return Promise.all(
|
|
31
41
|
INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
|
|
32
42
|
secret,
|
|
33
|
-
signingKey:
|
|
43
|
+
signingKey: INITIAL_TEST_SIGNING_KEYS[i],
|
|
34
44
|
salt: INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
45
|
+
type: 'schnorr_initializerless' as const,
|
|
46
|
+
address: await getSchnorrInitializerlessAccountContractAddress(
|
|
38
47
|
INITIAL_TEST_SIGNING_KEYS[i],
|
|
48
|
+
INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
49
|
+
secret,
|
|
39
50
|
),
|
|
40
51
|
})),
|
|
41
52
|
);
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
/**
|
|
45
|
-
* Generate a fixed amount of random schnorr account contract
|
|
56
|
+
* Generate a fixed amount of random schnorr account contract instances of the given type
|
|
46
57
|
*/
|
|
47
|
-
export async function generateSchnorrAccounts(
|
|
48
|
-
|
|
58
|
+
export async function generateSchnorrAccounts(
|
|
59
|
+
numberOfAccounts: number,
|
|
60
|
+
type: InitialAccountType = 'schnorr_initializerless',
|
|
61
|
+
): Promise<InitialAccountData[]> {
|
|
62
|
+
const signingKeys = Array.from({ length: numberOfAccounts }, () => GrumpkinScalar.random());
|
|
49
63
|
return await Promise.all(
|
|
50
|
-
|
|
64
|
+
signingKeys.map(async signingKey => {
|
|
51
65
|
const salt = Fr.random();
|
|
66
|
+
const secret = await deriveSecretKeyFromSigningKey(signingKey);
|
|
52
67
|
return {
|
|
53
68
|
secret,
|
|
54
|
-
signingKey
|
|
69
|
+
signingKey,
|
|
55
70
|
salt,
|
|
56
|
-
|
|
71
|
+
type,
|
|
72
|
+
address: await getTestAccountAddress(type, signingKey, salt, secret),
|
|
57
73
|
};
|
|
58
74
|
}),
|
|
59
75
|
);
|
package/src/testing/lazy.ts
CHANGED
|
@@ -4,19 +4,28 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
7
|
-
import {
|
|
7
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { getSchnorrInitializerlessAccountContractAddress } from '../schnorr/initializerless/lazy.js';
|
|
10
|
+
import { getSchnorrAccountContractAddress } from '../schnorr/private_immutable/lazy.js';
|
|
11
|
+
import { deriveSecretKeyFromSigningKey } from '../utils/key_derivation.js';
|
|
10
12
|
import {
|
|
11
13
|
INITIAL_TEST_ACCOUNT_SALTS,
|
|
12
|
-
INITIAL_TEST_ENCRYPTION_KEYS,
|
|
13
14
|
INITIAL_TEST_SECRET_KEYS,
|
|
14
15
|
INITIAL_TEST_SIGNING_KEYS,
|
|
15
16
|
type InitialAccountData,
|
|
17
|
+
type InitialAccountType,
|
|
16
18
|
} from './configuration.js';
|
|
17
19
|
|
|
18
20
|
export { INITIAL_TEST_ACCOUNT_SALTS, INITIAL_TEST_SECRET_KEYS } from './configuration.js';
|
|
19
21
|
|
|
22
|
+
/** Derives the account contract address for the given type */
|
|
23
|
+
function getTestAccountAddress(type: InitialAccountType, signingKey: GrumpkinScalar, salt: Fr, secret?: Fr) {
|
|
24
|
+
return type === 'schnorr'
|
|
25
|
+
? getSchnorrAccountContractAddress(signingKey, salt, secret)
|
|
26
|
+
: getSchnorrInitializerlessAccountContractAddress(signingKey, salt, secret);
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* Gets the basic information for initial test accounts.
|
|
22
31
|
*/
|
|
@@ -24,30 +33,36 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
|
|
|
24
33
|
return Promise.all(
|
|
25
34
|
INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
|
|
26
35
|
secret,
|
|
27
|
-
signingKey:
|
|
36
|
+
signingKey: INITIAL_TEST_SIGNING_KEYS[i],
|
|
28
37
|
salt: INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
38
|
+
type: 'schnorr_initializerless' as const,
|
|
39
|
+
address: await getSchnorrInitializerlessAccountContractAddress(
|
|
32
40
|
INITIAL_TEST_SIGNING_KEYS[i],
|
|
41
|
+
INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
42
|
+
secret,
|
|
33
43
|
),
|
|
34
44
|
})),
|
|
35
45
|
);
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
/**
|
|
39
|
-
* Generate a fixed amount of random schnorr account contract
|
|
49
|
+
* Generate a fixed amount of random schnorr account contract instances of the given type
|
|
40
50
|
*/
|
|
41
|
-
export async function generateSchnorrAccounts(
|
|
42
|
-
|
|
51
|
+
export async function generateSchnorrAccounts(
|
|
52
|
+
numberOfAccounts: number,
|
|
53
|
+
type: InitialAccountType = 'schnorr_initializerless',
|
|
54
|
+
): Promise<InitialAccountData[]> {
|
|
55
|
+
const signingKeys = Array.from({ length: numberOfAccounts }, () => GrumpkinScalar.random());
|
|
43
56
|
return await Promise.all(
|
|
44
|
-
|
|
57
|
+
signingKeys.map(async signingKey => {
|
|
45
58
|
const salt = Fr.random();
|
|
59
|
+
const secret = await deriveSecretKeyFromSigningKey(signingKey);
|
|
46
60
|
return {
|
|
47
61
|
secret,
|
|
48
|
-
signingKey
|
|
62
|
+
signingKey,
|
|
49
63
|
salt,
|
|
50
|
-
|
|
64
|
+
type,
|
|
65
|
+
address: await getTestAccountAddress(type, signingKey, salt, secret),
|
|
51
66
|
};
|
|
52
67
|
}),
|
|
53
68
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
2
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
5
|
+
|
|
6
|
+
const SIGNING_KEY_TO_SECRET_KEY_SEPARATOR = sha256ToField([Buffer.from('@aztec/accounts/signing_key_to_secret_key')]);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Derives the privacy secret key (the seed for the viewing/nullifier keyset that PXE holds) from the account's signing
|
|
10
|
+
* key. The signing key is the ownership root the user controls; the privacy keyset hangs off it through this one-way
|
|
11
|
+
* hash, so a value handled by PXE can never be used to recover the signing key.
|
|
12
|
+
*/
|
|
13
|
+
export function deriveSecretKeyFromSigningKey(signingKey: GrumpkinScalar): Promise<Fr> {
|
|
14
|
+
return poseidon2Hash([SIGNING_KEY_TO_SECRET_KEY_SEPARATOR, signingKey.hi, signingKey.lo]);
|
|
15
|
+
}
|
package/src/utils/ssh_agent.ts
CHANGED
|
@@ -41,6 +41,7 @@ type StoredKey = {
|
|
|
41
41
|
export function getIdentities(): Promise<StoredKey[]> {
|
|
42
42
|
return new Promise((resolve, reject) => {
|
|
43
43
|
const stream = connectToAgent();
|
|
44
|
+
stream.on('error', reject);
|
|
44
45
|
stream.on('connect', () => {
|
|
45
46
|
const request = Buffer.concat([
|
|
46
47
|
Buffer.from([0, 0, 0, 5 + 4]), // length
|
|
@@ -96,6 +97,7 @@ export function getIdentities(): Promise<StoredKey[]> {
|
|
|
96
97
|
export function signWithAgent(keyType: Buffer, curveName: Buffer, publicKey: Buffer, data: Buffer) {
|
|
97
98
|
return new Promise<Buffer>((resolve, reject) => {
|
|
98
99
|
const stream = connectToAgent();
|
|
100
|
+
stream.on('error', reject);
|
|
99
101
|
stream.on('connect', () => {
|
|
100
102
|
// Construct the key blob
|
|
101
103
|
const keyBlob = Buffer.concat([
|