@aztec/accounts 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +0 -1
- package/artifacts/EcdsaKAccount.json +7999 -2080
- package/artifacts/EcdsaRAccount.json +7999 -2080
- package/artifacts/SchnorrAccount.json +7912 -2027
- package/artifacts/SchnorrInitializerlessAccount.json +8526 -0
- package/artifacts/SimulatedEcdsaAccount.json +10972 -0
- package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
- package/artifacts/SimulatedSchnorrAccount.json +11084 -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/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/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 -13
- 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 +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/src/utils/ssh_agent.ts +2 -0
- package/artifacts/SchnorrSingleKeyAccount.json +0 -4716
- package/artifacts/SimulatedAccount.json +0 -4496
- 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 -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/single_key/account_contract.ts +0 -47
- package/src/single_key/index.ts +0 -32
- package/src/single_key/lazy.ts +0 -40
- package/src/stub/index.ts +0 -40
- package/src/stub/lazy.ts +0 -51
- /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
- /package/src/{stub/account_contract.ts → defaults/stub_account_contract.ts} +0 -0
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
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([
|