@aztec/accounts 0.0.1-commit.b6e433891 → 0.0.1-commit.b8a057fa
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 +7591 -1927
- package/artifacts/EcdsaRAccount.json +7591 -1927
- package/artifacts/SchnorrAccount.json +7601 -1967
- package/artifacts/SchnorrInitializerlessAccount.json +8460 -0
- package/artifacts/SimulatedEcdsaAccount.d.json.ts +3 -0
- package/artifacts/SimulatedEcdsaAccount.json +10610 -0
- package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
- package/artifacts/SimulatedSchnorrAccount.json +10722 -0
- 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/account_contract.d.ts +1 -1
- package/dest/ecdsa/ecdsa_k/account_contract.js +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +8 -4
- package/dest/schnorr/account_contract.d.ts.map +1 -1
- package/dest/schnorr/account_contract.js +6 -5
- 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/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 +9 -1
- package/dest/testing/configuration.d.ts.map +1 -1
- package/dest/testing/index.d.ts +5 -5
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +11 -5
- package/dest/testing/lazy.d.ts +4 -4
- package/dest/testing/lazy.d.ts.map +1 -1
- package/dest/testing/lazy.js +11 -5
- 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 +10 -10
- package/src/defaults/account_contract.ts +9 -0
- package/src/ecdsa/ecdsa_k/account_contract.ts +1 -1
- package/src/ecdsa/ecdsa_k/lazy.ts +1 -1
- package/src/ecdsa/ecdsa_r/account_contract.ts +1 -1
- package/src/ecdsa/ecdsa_r/lazy.ts +1 -1
- package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +1 -1
- package/src/ecdsa/stub/index.ts +28 -0
- package/src/ecdsa/stub/lazy.ts +34 -0
- package/src/schnorr/account_contract.ts +18 -5
- 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/schnorr/stub/index.ts +30 -0
- package/src/schnorr/stub/lazy.ts +34 -0
- package/src/testing/configuration.ts +9 -0
- package/src/testing/index.ts +21 -5
- package/src/testing/lazy.ts +20 -5
- package/src/utils/ssh_agent.ts +2 -0
- package/artifacts/SimulatedAccount.json +0 -4735
- package/dest/stub/account_contract.d.ts.map +0 -1
- package/dest/stub/index.d.ts +0 -20
- package/dest/stub/index.d.ts.map +0 -1
- package/dest/stub/index.js +0 -28
- package/dest/stub/lazy.d.ts +0 -25
- package/dest/stub/lazy.d.ts.map +0 -1
- package/dest/stub/lazy.js +0 -37
- package/src/stub/index.ts +0 -40
- package/src/stub/lazy.ts +0 -51
- /package/artifacts/{SimulatedAccount.d.json.ts → SchnorrInitializerlessAccount.d.json.ts} +0 -0
- /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,28 @@
|
|
|
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 SimulatedEcdsaAccountJson from '../../../artifacts/SimulatedEcdsaAccount.json' with { type: 'json' };
|
|
8
|
+
import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
|
|
9
|
+
|
|
10
|
+
export const StubEcdsaAccountContractArtifact = loadContractArtifact(SimulatedEcdsaAccountJson as NoirCompiledContract);
|
|
11
|
+
|
|
12
|
+
/** Stub account contract for ECDSA accounts (secp256k1 and secp256r1). Eagerly loads the contract artifact. */
|
|
13
|
+
export class StubEcdsaAccountContract extends StubBaseAccountContract {
|
|
14
|
+
override getContractArtifact() {
|
|
15
|
+
return Promise.resolve(StubEcdsaAccountContractArtifact);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Creates an ECDSA stub account that impersonates the one with the provided address. */
|
|
20
|
+
export function createStubEcdsaAccount(originalAddress: CompleteAddress) {
|
|
21
|
+
const accountContract = new StubEcdsaAccountContract();
|
|
22
|
+
const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
|
|
23
|
+
return new BaseAccount(
|
|
24
|
+
new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
|
|
25
|
+
authWitnessProvider,
|
|
26
|
+
originalAddress,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -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 ECDSA stub contract artifact (browser-compatible).
|
|
10
|
+
*/
|
|
11
|
+
export async function getStubEcdsaAccountContractArtifact() {
|
|
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/SimulatedEcdsaAccount.json');
|
|
15
|
+
return loadContractArtifact(json);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Stub account contract for ECDSA accounts (secp256k1 and secp256r1). Lazily loads the contract artifact. */
|
|
19
|
+
export class StubEcdsaAccountContract extends StubBaseAccountContract {
|
|
20
|
+
override getContractArtifact() {
|
|
21
|
+
return getStubEcdsaAccountContractArtifact();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Creates an ECDSA stub account that impersonates the one with the provided address. */
|
|
26
|
+
export function createStubEcdsaAccount(originalAddress: CompleteAddress) {
|
|
27
|
+
const accountContract = new StubEcdsaAccountContract();
|
|
28
|
+
const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
|
|
29
|
+
return new BaseAccount(
|
|
30
|
+
new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
|
|
31
|
+
authWitnessProvider,
|
|
32
|
+
originalAddress,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -14,12 +14,25 @@ import { DefaultAccountContract } from '../defaults/account_contract.js';
|
|
|
14
14
|
* can be implemented with or without lazy loading.
|
|
15
15
|
*/
|
|
16
16
|
export abstract class SchnorrBaseAccountContract extends DefaultAccountContract {
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(protected signingPrivateKey: GrumpkinScalar) {
|
|
18
18
|
super();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/** The Grumpkin public key this account verifies signatures against. */
|
|
22
|
+
getSigningPublicKey() {
|
|
23
|
+
return new Schnorr().computePublicKey(this.signingPrivateKey);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getInitializationFunctionAndArgs(): Promise<
|
|
27
|
+
| {
|
|
28
|
+
/** The name of the function used to initialize the contract */
|
|
29
|
+
constructorName: string;
|
|
30
|
+
/** The args to the function used to initialize the contract */
|
|
31
|
+
constructorArgs: any[];
|
|
32
|
+
}
|
|
33
|
+
| undefined
|
|
34
|
+
> {
|
|
35
|
+
const signingPublicKey = await this.getSigningPublicKey();
|
|
23
36
|
return { constructorName: 'constructor', constructorArgs: [signingPublicKey.x, signingPublicKey.y] };
|
|
24
37
|
}
|
|
25
38
|
|
|
@@ -34,7 +47,7 @@ export class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
|
|
|
34
47
|
|
|
35
48
|
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
|
|
36
49
|
const schnorr = new Schnorr();
|
|
37
|
-
const signature = await schnorr.constructSignature(messageHash
|
|
38
|
-
return new AuthWitness(messageHash,
|
|
50
|
+
const signature = await schnorr.constructSignature(messageHash, this.signingPrivateKey);
|
|
51
|
+
return new AuthWitness(messageHash, signature.toLimbFields());
|
|
39
52
|
}
|
|
40
53
|
}
|
package/src/schnorr/index.ts
CHANGED
|
@@ -1,50 +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 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 { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
14
|
-
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
15
|
-
|
|
16
|
-
import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' with { type: 'json' };
|
|
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 secret - A seed for deriving the signing key and public keys.
|
|
39
|
-
* @param salt - The contract address salt.
|
|
40
|
-
* @param signingPrivateKey - A specific signing private key that's not derived from the secret.
|
|
41
|
-
*/
|
|
42
|
-
export async function getSchnorrAccountContractAddress(
|
|
43
|
-
secret: Fr,
|
|
44
|
-
salt: Fr,
|
|
45
|
-
signingPrivateKey?: GrumpkinScalar,
|
|
46
|
-
): Promise<AztecAddress> {
|
|
47
|
-
const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
|
|
48
|
-
const accountContract = new SchnorrAccountContract(signingKey);
|
|
49
|
-
return await getAccountContractAddress(accountContract, secret, salt);
|
|
50
|
-
}
|
|
1
|
+
export * from './private_immutable/index.js';
|
|
2
|
+
export * from './initializerless/index.js';
|
|
@@ -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 { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
15
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
16
|
+
|
|
17
|
+
import SchnorrInitializerlessAccountContractJson from '../../../artifacts/SchnorrInitializerlessAccount.json' with { type: 'json' };
|
|
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 secret - A seed for deriving the signing key and public keys.
|
|
51
|
+
* @param salt - The contract address salt.
|
|
52
|
+
* @param signingPrivateKey - A specific signing private key that's not derived from the secret.
|
|
53
|
+
*/
|
|
54
|
+
export async function getSchnorrInitializerlessAccountContractAddress(
|
|
55
|
+
secret: Fr,
|
|
56
|
+
salt: Fr,
|
|
57
|
+
signingPrivateKey?: GrumpkinScalar,
|
|
58
|
+
): Promise<AztecAddress> {
|
|
59
|
+
const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
|
|
60
|
+
const accountContract = new SchnorrInitializerlessAccountContract(signingKey);
|
|
61
|
+
return await getAccountContractAddress(accountContract, secret, 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
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
15
|
+
|
|
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 secret - A seed for deriving the signing key and public keys.
|
|
59
|
+
* @param salt - The contract address salt.
|
|
60
|
+
* @param signingPrivateKey - A specific signing private key that's not derived from the secret.
|
|
61
|
+
*/
|
|
62
|
+
export async function getSchnorrInitializerlessAccountContractAddress(
|
|
63
|
+
secret: Fr,
|
|
64
|
+
salt: Fr,
|
|
65
|
+
signingPrivateKey?: GrumpkinScalar,
|
|
66
|
+
): Promise<AztecAddress> {
|
|
67
|
+
const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
|
|
68
|
+
const accountContract = new SchnorrInitializerlessAccountContract(signingKey);
|
|
69
|
+
return await getAccountContractAddress(accountContract, secret, 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 { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
14
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
15
|
+
|
|
16
|
+
import SchnorrAccountContractJson from '../../../artifacts/SchnorrAccount.json' with { type: 'json' };
|
|
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 secret - A seed for deriving the signing key and public keys.
|
|
39
|
+
* @param salt - The contract address salt.
|
|
40
|
+
* @param signingPrivateKey - A specific signing private key that's not derived from the secret.
|
|
41
|
+
*/
|
|
42
|
+
export async function getSchnorrAccountContractAddress(
|
|
43
|
+
secret: Fr,
|
|
44
|
+
salt: Fr,
|
|
45
|
+
signingPrivateKey?: GrumpkinScalar,
|
|
46
|
+
): Promise<AztecAddress> {
|
|
47
|
+
const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
|
|
48
|
+
const accountContract = new SchnorrAccountContract(signingKey);
|
|
49
|
+
return await getAccountContractAddress(accountContract, secret, 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
|
+
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 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 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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -17,6 +17,11 @@ export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS;
|
|
|
17
17
|
|
|
18
18
|
export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The schnorr account contract variant a test account uses.
|
|
22
|
+
*/
|
|
23
|
+
export type InitialAccountType = 'schnorr' | 'schnorr_initializerless';
|
|
24
|
+
|
|
20
25
|
/**
|
|
21
26
|
* Data for generating an initial account.
|
|
22
27
|
*/
|
|
@@ -37,4 +42,8 @@ export interface InitialAccountData {
|
|
|
37
42
|
* Address of the schnorr account contract.
|
|
38
43
|
*/
|
|
39
44
|
address: AztecAddress;
|
|
45
|
+
/**
|
|
46
|
+
* Account contract variant.
|
|
47
|
+
*/
|
|
48
|
+
type?: InitialAccountType;
|
|
40
49
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
7
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
7
8
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
8
9
|
|
|
9
|
-
import {
|
|
10
|
+
import { getSchnorrInitializerlessAccountContractAddress } from '../schnorr/initializerless/index.js';
|
|
11
|
+
import { getSchnorrAccountContractAddress } from '../schnorr/private_immutable/index.js';
|
|
10
12
|
import {
|
|
11
13
|
INITIAL_TEST_ACCOUNT_SALTS,
|
|
12
14
|
INITIAL_TEST_ENCRYPTION_KEYS,
|
|
13
15
|
INITIAL_TEST_SECRET_KEYS,
|
|
14
16
|
INITIAL_TEST_SIGNING_KEYS,
|
|
15
17
|
type InitialAccountData,
|
|
18
|
+
type InitialAccountType,
|
|
16
19
|
} from './configuration.js';
|
|
17
20
|
|
|
18
21
|
export {
|
|
@@ -21,8 +24,16 @@ export {
|
|
|
21
24
|
INITIAL_TEST_SECRET_KEYS,
|
|
22
25
|
INITIAL_TEST_SIGNING_KEYS,
|
|
23
26
|
type InitialAccountData,
|
|
27
|
+
type InitialAccountType,
|
|
24
28
|
} from './configuration.js';
|
|
25
29
|
|
|
30
|
+
/** Derives the account contract address for the given type */
|
|
31
|
+
function getTestAccountAddress(type: InitialAccountType, secret: Fr, salt: Fr, signingKey?: GrumpkinScalar) {
|
|
32
|
+
return type === 'schnorr'
|
|
33
|
+
? getSchnorrAccountContractAddress(secret, salt, signingKey)
|
|
34
|
+
: getSchnorrInitializerlessAccountContractAddress(secret, salt, signingKey);
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
/**
|
|
27
38
|
* Gets the basic information for initial test accounts.
|
|
28
39
|
*/
|
|
@@ -32,7 +43,8 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
|
|
|
32
43
|
secret,
|
|
33
44
|
signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i],
|
|
34
45
|
salt: INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
35
|
-
|
|
46
|
+
type: 'schnorr_initializerless' as const,
|
|
47
|
+
address: await getSchnorrInitializerlessAccountContractAddress(
|
|
36
48
|
secret,
|
|
37
49
|
INITIAL_TEST_ACCOUNT_SALTS[i],
|
|
38
50
|
INITIAL_TEST_SIGNING_KEYS[i],
|
|
@@ -42,9 +54,12 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
|
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
/**
|
|
45
|
-
* Generate a fixed amount of random schnorr account contract
|
|
57
|
+
* Generate a fixed amount of random schnorr account contract instances of the given type
|
|
46
58
|
*/
|
|
47
|
-
export async function generateSchnorrAccounts(
|
|
59
|
+
export async function generateSchnorrAccounts(
|
|
60
|
+
numberOfAccounts: number,
|
|
61
|
+
type: InitialAccountType = 'schnorr_initializerless',
|
|
62
|
+
): Promise<InitialAccountData[]> {
|
|
48
63
|
const secrets = Array.from({ length: numberOfAccounts }, () => Fr.random());
|
|
49
64
|
return await Promise.all(
|
|
50
65
|
secrets.map(async secret => {
|
|
@@ -53,7 +68,8 @@ export async function generateSchnorrAccounts(numberOfAccounts: number): Promise
|
|
|
53
68
|
secret,
|
|
54
69
|
signingKey: deriveSigningKey(secret),
|
|
55
70
|
salt,
|
|
56
|
-
|
|
71
|
+
type,
|
|
72
|
+
address: await getTestAccountAddress(type, secret, salt),
|
|
57
73
|
};
|
|
58
74
|
}),
|
|
59
75
|
);
|