@aztec/accounts 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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/artifacts/EcdsaKAccount.json +2985 -1826
- package/artifacts/EcdsaRAccount.json +2988 -1829
- package/artifacts/SchnorrAccount.json +3024 -1869
- package/artifacts/SchnorrInitializerlessAccount.d.json.ts +3 -0
- package/artifacts/SchnorrInitializerlessAccount.json +8526 -0
- package/artifacts/SimulatedEcdsaAccount.json +2356 -1494
- package/artifacts/SimulatedSchnorrAccount.json +2142 -1260
- package/dest/defaults/account_contract.d.ts +7 -1
- package/dest/defaults/account_contract.d.ts.map +1 -1
- package/dest/defaults/account_contract.js +6 -0
- package/dest/{stub/account_contract.d.ts → defaults/stub_account_contract.d.ts} +1 -1
- package/dest/defaults/stub_account_contract.d.ts.map +1 -0
- package/dest/ecdsa/ecdsa_k/lazy.js +1 -1
- package/dest/ecdsa/ecdsa_r/lazy.js +1 -1
- package/dest/{stub/ecdsa → ecdsa/stub}/index.d.ts +2 -2
- package/dest/ecdsa/stub/index.d.ts.map +1 -0
- package/dest/{stub/ecdsa → ecdsa/stub}/index.js +1 -1
- package/dest/{stub/ecdsa → ecdsa/stub}/lazy.d.ts +2 -2
- package/dest/ecdsa/stub/lazy.d.ts.map +1 -0
- package/dest/{stub/ecdsa → ecdsa/stub}/lazy.js +1 -1
- package/dest/schnorr/account_contract.d.ts +8 -4
- package/dest/schnorr/account_contract.d.ts.map +1 -1
- package/dest/schnorr/account_contract.js +4 -1
- package/dest/schnorr/index.d.ts +3 -23
- 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 -27
- 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/{stub/schnorr → schnorr/stub}/index.d.ts +2 -2
- package/dest/schnorr/stub/index.d.ts.map +1 -0
- package/dest/{stub/schnorr → schnorr/stub}/index.js +1 -1
- package/dest/{stub/schnorr → schnorr/stub}/lazy.d.ts +2 -2
- package/dest/schnorr/stub/lazy.d.ts.map +1 -0
- package/dest/{stub/schnorr → schnorr/stub}/lazy.js +1 -1
- package/dest/testing/configuration.d.ts +9 -1
- package/dest/testing/configuration.d.ts.map +1 -1
- package/dest/testing/configuration.js +6 -2
- 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/package.json +10 -12
- package/src/defaults/account_contract.ts +9 -0
- package/src/ecdsa/ecdsa_k/lazy.ts +1 -1
- package/src/ecdsa/ecdsa_r/lazy.ts +1 -1
- package/src/{stub/ecdsa → ecdsa/stub}/index.ts +1 -1
- package/src/{stub/ecdsa → ecdsa/stub}/lazy.ts +1 -1
- package/src/schnorr/account_contract.ts +16 -3
- package/src/schnorr/index.ts +2 -50
- package/src/schnorr/initializerless/index.ts +62 -0
- package/src/schnorr/initializerless/lazy.ts +70 -0
- package/src/schnorr/lazy.ts +2 -60
- package/src/schnorr/private_immutable/index.ts +50 -0
- package/src/schnorr/private_immutable/lazy.ts +60 -0
- package/src/{stub/schnorr → schnorr/stub}/index.ts +1 -1
- package/src/{stub/schnorr → schnorr/stub}/lazy.ts +1 -1
- package/src/testing/configuration.ts +15 -2
- 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/dest/stub/account_contract.d.ts.map +0 -1
- package/dest/stub/ecdsa/index.d.ts.map +0 -1
- package/dest/stub/ecdsa/lazy.d.ts.map +0 -1
- package/dest/stub/schnorr/index.d.ts.map +0 -1
- package/dest/stub/schnorr/lazy.d.ts.map +0 -1
- /package/dest/{stub/account_contract.js → defaults/stub_account_contract.js} +0 -0
- /package/src/{stub/account_contract.ts → defaults/stub_account_contract.ts} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
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 { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
12
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
13
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
14
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
15
|
+
|
|
16
|
+
import SchnorrInitializerlessAccountContractJson from '../../../artifacts/SchnorrInitializerlessAccount.json' with { type: 'json' };
|
|
17
|
+
import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
|
|
18
|
+
import { SchnorrBaseAccountContract } from '../account_contract.js';
|
|
19
|
+
|
|
20
|
+
export const SchnorrInitializerlessAccountContractArtifact = loadContractArtifact(
|
|
21
|
+
SchnorrInitializerlessAccountContractJson as NoirCompiledContract,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Account contract that authenticates transactions using Schnorr signatures
|
|
26
|
+
* verified against a Grumpkin public key stored in an immutable encrypted note.
|
|
27
|
+
* Eagerly loads the contract artifact
|
|
28
|
+
*/
|
|
29
|
+
export class SchnorrInitializerlessAccountContract extends SchnorrBaseAccountContract {
|
|
30
|
+
constructor(signingPrivateKey: GrumpkinScalar) {
|
|
31
|
+
super(signingPrivateKey);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override getInitializationFunctionAndArgs() {
|
|
35
|
+
return Promise.resolve(undefined);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override async getImmutablesHash(): Promise<Fr> {
|
|
39
|
+
const signingPublicKey = await this.getSigningPublicKey();
|
|
40
|
+
return poseidon2Hash([signingPublicKey.x, signingPublicKey.y]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
44
|
+
return Promise.resolve(SchnorrInitializerlessAccountContractArtifact);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Compute the address of a schnorr account contract.
|
|
50
|
+
* @param signingPrivateKey - The account's signing private key.
|
|
51
|
+
* @param salt - The contract address salt.
|
|
52
|
+
* @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
|
|
53
|
+
*/
|
|
54
|
+
export async function getSchnorrInitializerlessAccountContractAddress(
|
|
55
|
+
signingPrivateKey: GrumpkinScalar,
|
|
56
|
+
salt: Fr,
|
|
57
|
+
secretKey?: Fr,
|
|
58
|
+
): Promise<AztecAddress> {
|
|
59
|
+
const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
|
|
60
|
+
const accountContract = new SchnorrInitializerlessAccountContract(signingPrivateKey);
|
|
61
|
+
return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
|
|
62
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
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 { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
+
|
|
15
|
+
import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
|
|
16
|
+
import { SchnorrBaseAccountContract } from '../account_contract.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Lazily loads the contract artifact
|
|
20
|
+
* @returns The contract artifact for the schnorr account contract
|
|
21
|
+
*/
|
|
22
|
+
export async function getSchnorrInitializerlessAccountContractArtifact() {
|
|
23
|
+
// Cannot assert this import as it's incompatible with bundlers like vite
|
|
24
|
+
// https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
|
|
25
|
+
// Even if now supported by all major browsers, the MIME type is replaced with
|
|
26
|
+
// "text/javascript"
|
|
27
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
28
|
+
const { default: schnorrAccountContractJson } = await import('../../../artifacts/SchnorrInitializerlessAccount.json');
|
|
29
|
+
return loadContractArtifact(schnorrAccountContractJson);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Account contract that authenticates transactions using Schnorr signatures
|
|
34
|
+
* verified against a Grumpkin public key stored in an immutable encrypted note.
|
|
35
|
+
* Lazily loads the contract artifact
|
|
36
|
+
*/
|
|
37
|
+
export class SchnorrInitializerlessAccountContract extends SchnorrBaseAccountContract {
|
|
38
|
+
constructor(signingPrivateKey: GrumpkinScalar) {
|
|
39
|
+
super(signingPrivateKey);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override getInitializationFunctionAndArgs() {
|
|
43
|
+
return Promise.resolve(undefined);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override async getImmutablesHash(): Promise<Fr> {
|
|
47
|
+
const signingPublicKey = await this.getSigningPublicKey();
|
|
48
|
+
return poseidon2Hash([signingPublicKey.x, signingPublicKey.y]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override getContractArtifact(): Promise<ContractArtifact> {
|
|
52
|
+
return getSchnorrInitializerlessAccountContractArtifact();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compute the address of a schnorr account contract.
|
|
58
|
+
* @param signingPrivateKey - The account's signing private key.
|
|
59
|
+
* @param salt - The contract address salt.
|
|
60
|
+
* @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
|
|
61
|
+
*/
|
|
62
|
+
export async function getSchnorrInitializerlessAccountContractAddress(
|
|
63
|
+
signingPrivateKey: GrumpkinScalar,
|
|
64
|
+
salt: Fr,
|
|
65
|
+
secretKey?: Fr,
|
|
66
|
+
): Promise<AztecAddress> {
|
|
67
|
+
const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
|
|
68
|
+
const accountContract = new SchnorrInitializerlessAccountContract(signingPrivateKey);
|
|
69
|
+
return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
|
|
70
|
+
}
|
package/src/schnorr/lazy.ts
CHANGED
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
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
|
-
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
14
|
-
|
|
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 al 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 secret - A seed for deriving the signing key and public keys.
|
|
49
|
-
* @param salt - The contract address salt.
|
|
50
|
-
* @param signingPrivateKey - A specific signing private key that's not derived from the secret.
|
|
51
|
-
*/
|
|
52
|
-
export async function getSchnorrAccountContractAddress(
|
|
53
|
-
secret: Fr,
|
|
54
|
-
salt: Fr,
|
|
55
|
-
signingPrivateKey?: GrumpkinScalar,
|
|
56
|
-
): Promise<AztecAddress> {
|
|
57
|
-
const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
|
|
58
|
-
const accountContract = new SchnorrAccountContract(signingKey);
|
|
59
|
-
return await getAccountContractAddress(accountContract, secret, salt);
|
|
60
|
-
}
|
|
1
|
+
export * from './private_immutable/lazy.js';
|
|
2
|
+
export * from './initializerless/lazy.js';
|
|
@@ -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
|
+
}
|
|
@@ -5,7 +5,7 @@ import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
|
5
5
|
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
6
6
|
|
|
7
7
|
import SimulatedSchnorrAccountJson from '../../../artifacts/SimulatedSchnorrAccount.json' with { type: 'json' };
|
|
8
|
-
import { StubBaseAccountContract } from '
|
|
8
|
+
import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
|
|
9
9
|
|
|
10
10
|
export const StubSchnorrAccountContractArtifact = loadContractArtifact(
|
|
11
11
|
SimulatedSchnorrAccountJson as NoirCompiledContract,
|
|
@@ -3,7 +3,7 @@ import type { CompleteAddress } from '@aztec/aztec.js/addresses';
|
|
|
3
3
|
import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account';
|
|
4
4
|
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
5
5
|
|
|
6
|
-
import { StubBaseAccountContract } from '
|
|
6
|
+
import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Lazily loads the Schnorr stub contract artifact (browser-compatible).
|
|
@@ -12,11 +12,20 @@ export const INITIAL_TEST_SECRET_KEYS = [
|
|
|
12
12
|
export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey =>
|
|
13
13
|
deriveMasterIncomingViewingSecretKey(secretKey),
|
|
14
14
|
);
|
|
15
|
-
|
|
16
|
-
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
|
+
];
|
|
17
21
|
|
|
18
22
|
export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
19
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The schnorr account contract variant a test account uses.
|
|
26
|
+
*/
|
|
27
|
+
export type InitialAccountType = 'schnorr' | 'schnorr_initializerless';
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* Data for generating an initial account.
|
|
22
31
|
*/
|
|
@@ -37,4 +46,8 @@ export interface InitialAccountData {
|
|
|
37
46
|
* Address of the schnorr account contract.
|
|
38
47
|
*/
|
|
39
48
|
address: AztecAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Account contract variant.
|
|
51
|
+
*/
|
|
52
|
+
type?: InitialAccountType;
|
|
40
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
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account_contract.d.ts","sourceRoot":"","sources":["../../src/stub/account_contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,sBAAsB;IAC1E,cAEC;IAED,gCAAgC;;;OAE/B;IAED,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,mBAAmB,CAErE;CACF;AAED,oDAAoD;AACpD,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,cAAgB;IAEhB;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAEnD;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stub/ecdsa/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAMjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,eAAO,MAAM,gCAAgC,8CAA0E,CAAC;AAExH,+GAA+G;AAC/G,qBAAa,wBAAyB,SAAQ,uBAAuB;IAC1D,mBAAmB,0DAE3B;CACF;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,eAAe,eAQtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../src/stub/ecdsa/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAIjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;GAEG;AACH,wBAAsB,mCAAmC,0DAKxD;AAED,8GAA8G;AAC9G,qBAAa,wBAAyB,SAAQ,uBAAuB;IAC1D,mBAAmB,0DAE3B;CACF;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,eAAe,eAQtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stub/schnorr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAMjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,eAAO,MAAM,kCAAkC,8CAE9C,CAAC;AAEF,uFAAuF;AACvF,qBAAa,0BAA2B,SAAQ,uBAAuB;IAC5D,mBAAmB,0DAE3B;CACF;AAED,0FAA0F;AAC1F,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,eAAe,eAQxE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../src/stub/schnorr/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAIjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;GAEG;AACH,wBAAsB,qCAAqC,0DAK1D;AAED,sFAAsF;AACtF,qBAAa,0BAA2B,SAAQ,uBAAuB;IAC5D,mBAAmB,0DAE3B;CACF;AAED,0FAA0F;AAC1F,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,eAAe,eAQxE"}
|
|
File without changes
|
|
File without changes
|