@aztec/key-store 0.35.1 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,210 +0,0 @@
1
- var _NewTestKeyStore_keys;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
- import { AztecAddress, Fr, GeneratorIndex, GrumpkinScalar, Point, } from '@aztec/circuits.js';
4
- import { poseidon2Hash, sha512ToGrumpkinScalar } from '@aztec/foundation/crypto';
5
- /**
6
- * TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
7
- * It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
8
- */
9
- export class NewTestKeyStore {
10
- constructor(curve, database) {
11
- this.curve = curve;
12
- _NewTestKeyStore_keys.set(this, void 0);
13
- __classPrivateFieldSet(this, _NewTestKeyStore_keys, database.openMap('key_store'), "f");
14
- }
15
- /**
16
- * Creates a new account from a randomly generated secret key.
17
- * @returns A promise that resolves to the newly created account's AztecAddress.
18
- */
19
- createAccount() {
20
- const sk = Fr.random();
21
- const partialAddress = Fr.random();
22
- return this.addAccount(sk, partialAddress);
23
- }
24
- /**
25
- * Adds an account to the key store from the provided secret key.
26
- * @param sk - The secret key of the account.
27
- * @param partialAddress - The partial address of the account.
28
- * @returns The account's address.
29
- */
30
- async addAccount(sk, partialAddress) {
31
- // First we derive master secret keys - we use sha512 here because this derivation will never take place
32
- // in a circuit
33
- const masterNullifierSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.NSK_M]);
34
- const masterIncomingViewingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.IVSK_M]);
35
- const masterOutgoingViewingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.OVSK_M]);
36
- const masterTaggingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.TSK_M]);
37
- // Then we derive master public keys
38
- const masterNullifierPublicKey = this.curve.mul(this.curve.generator(), masterNullifierSecretKey);
39
- const masterIncomingViewingPublicKey = this.curve.mul(this.curve.generator(), masterIncomingViewingSecretKey);
40
- const masterOutgoingViewingPublicKey = this.curve.mul(this.curve.generator(), masterOutgoingViewingSecretKey);
41
- const masterTaggingPublicKey = this.curve.mul(this.curve.generator(), masterTaggingSecretKey);
42
- // We hash the public keys to get the public keys hash
43
- const publicKeysHash = poseidon2Hash([
44
- masterNullifierPublicKey,
45
- masterIncomingViewingPublicKey,
46
- masterOutgoingViewingPublicKey,
47
- masterTaggingPublicKey,
48
- GeneratorIndex.PUBLIC_KEYS_HASH,
49
- ]);
50
- // We hash the partial address and the public keys hash to get the account address
51
- // TODO(#5726): Should GeneratorIndex.CONTRACT_ADDRESS be removed given that we introduced CONTRACT_ADDRESS_V1?
52
- // TODO(#5726): Move the following line to AztecAddress class?
53
- const accountAddressFr = poseidon2Hash([partialAddress, publicKeysHash, GeneratorIndex.CONTRACT_ADDRESS_V1]);
54
- const accountAddress = AztecAddress.fromField(accountAddressFr);
55
- // We store all the public and secret keys in the database
56
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-nsk_m`, masterNullifierSecretKey.toBuffer());
57
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-ivsk_m`, masterIncomingViewingSecretKey.toBuffer());
58
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-ovsk_m`, masterOutgoingViewingSecretKey.toBuffer());
59
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-tsk_m`, masterTaggingSecretKey.toBuffer());
60
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-npk_m`, masterNullifierPublicKey.toBuffer());
61
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-ivpk_m`, masterIncomingViewingPublicKey.toBuffer());
62
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-ovpk_m`, masterOutgoingViewingPublicKey.toBuffer());
63
- await __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").set(`${accountAddress.toString()}-tpk_m`, masterTaggingPublicKey.toBuffer());
64
- // At last, we return the newly derived account address
65
- return Promise.resolve(accountAddress);
66
- }
67
- /**
68
- * Retrieves addresses of accounts stored in the key store.
69
- * @returns A Promise that resolves to an array of account addresses.
70
- */
71
- getAccounts() {
72
- const allMapKeys = Array.from(__classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").keys());
73
- // We return account addresses based on the map keys that end with '-nsk_m'
74
- const accounts = allMapKeys.filter(key => key.endsWith('-nsk_m')).map(key => key.split('-')[0]);
75
- return Promise.resolve(accounts.map(account => AztecAddress.fromString(account)));
76
- }
77
- /**
78
- * Gets the master nullifier public key for a given account.
79
- * @throws If the account does not exist in the key store.
80
- * @param account - The account address for which to retrieve the master nullifier public key.
81
- * @returns The master nullifier public key for the account.
82
- */
83
- getMasterNullifierPublicKey(account) {
84
- const masterNullifierPublicKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-npk_m`);
85
- if (!masterNullifierPublicKeyBuffer) {
86
- throw new Error(`Account ${account.toString()} does not exist.`);
87
- }
88
- return Promise.resolve(Point.fromBuffer(masterNullifierPublicKeyBuffer));
89
- }
90
- /**
91
- * Gets the master incoming viewing public key for a given account.
92
- * @throws If the account does not exist in the key store.
93
- * @param account - The account address for which to retrieve the master incoming viewing public key.
94
- * @returns The master incoming viewing public key for the account.
95
- */
96
- getMasterIncomingViewingPublicKey(account) {
97
- const masterIncomingViewingPublicKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-ivpk_m`);
98
- if (!masterIncomingViewingPublicKeyBuffer) {
99
- throw new Error(`Account ${account.toString()} does not exist.`);
100
- }
101
- return Promise.resolve(Point.fromBuffer(masterIncomingViewingPublicKeyBuffer));
102
- }
103
- /**
104
- * Retrieves the master outgoing viewing public key.
105
- * @throws If the account does not exist in the key store.
106
- * @param account - The account to retrieve the master outgoing viewing key for.
107
- * @returns A Promise that resolves to the master outgoing viewing key.
108
- */
109
- getMasterOutgoingViewingPublicKey(account) {
110
- const masterOutgoingViewingPublicKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-ovpk_m`);
111
- if (!masterOutgoingViewingPublicKeyBuffer) {
112
- throw new Error(`Account ${account.toString()} does not exist.`);
113
- }
114
- return Promise.resolve(Point.fromBuffer(masterOutgoingViewingPublicKeyBuffer));
115
- }
116
- /**
117
- * Retrieves the master tagging public key.
118
- * @throws If the account does not exist in the key store.
119
- * @param account - The account to retrieve the master tagging key for.
120
- * @returns A Promise that resolves to the master tagging key.
121
- */
122
- getMasterTaggingPublicKey(account) {
123
- const masterTaggingPublicKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-tpk_m`);
124
- if (!masterTaggingPublicKeyBuffer) {
125
- throw new Error(`Account ${account.toString()} does not exist.`);
126
- }
127
- return Promise.resolve(Point.fromBuffer(masterTaggingPublicKeyBuffer));
128
- }
129
- /**
130
- * Retrieves application nullifier secret key.
131
- * @throws If the account does not exist in the key store.
132
- * @param account - The account to retrieve the application nullifier secret key for.
133
- * @param app - The application address to retrieve the nullifier secret key for.
134
- * @returns A Promise that resolves to the application nullifier secret key.
135
- */
136
- getAppNullifierSecretKey(account, app) {
137
- const masterNullifierSecretKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-nsk_m`);
138
- if (!masterNullifierSecretKeyBuffer) {
139
- throw new Error(`Account ${account.toString()} does not exist.`);
140
- }
141
- const masterNullifierSecretKey = GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer);
142
- return Promise.resolve(poseidon2Hash([masterNullifierSecretKey.high, masterNullifierSecretKey.low, app, GeneratorIndex.NSK_M]));
143
- }
144
- /**
145
- * Retrieves application incoming viewing secret key.
146
- * @throws If the account does not exist in the key store.
147
- * @param account - The account to retrieve the application incoming viewing secret key for.
148
- * @param app - The application address to retrieve the incoming viewing secret key for.
149
- * @returns A Promise that resolves to the application incoming viewing secret key.
150
- */
151
- getAppIncomingViewingSecretKey(account, app) {
152
- const masterIncomingViewingSecretKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-ivsk_m`);
153
- if (!masterIncomingViewingSecretKeyBuffer) {
154
- throw new Error(`Account ${account.toString()} does not exist.`);
155
- }
156
- const masterIncomingViewingSecretKey = GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer);
157
- return Promise.resolve(poseidon2Hash([
158
- masterIncomingViewingSecretKey.high,
159
- masterIncomingViewingSecretKey.low,
160
- app,
161
- GeneratorIndex.IVSK_M,
162
- ]));
163
- }
164
- /**
165
- * Retrieves application outgoing viewing secret key.
166
- * @throws If the account does not exist in the key store.
167
- * @param account - The account to retrieve the application outgoing viewing secret key for.
168
- * @param app - The application address to retrieve the outgoing viewing secret key for.
169
- * @returns A Promise that resolves to the application outgoing viewing secret key.
170
- */
171
- getAppOutgoingViewingSecretKey(account, app) {
172
- const masterOutgoingViewingSecretKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${account.toString()}-ovsk_m`);
173
- if (!masterOutgoingViewingSecretKeyBuffer) {
174
- throw new Error(`Account ${account.toString()} does not exist.`);
175
- }
176
- const masterOutgoingViewingSecretKey = GrumpkinScalar.fromBuffer(masterOutgoingViewingSecretKeyBuffer);
177
- return Promise.resolve(poseidon2Hash([
178
- masterOutgoingViewingSecretKey.high,
179
- masterOutgoingViewingSecretKey.low,
180
- app,
181
- GeneratorIndex.OVSK_M,
182
- ]));
183
- }
184
- /**
185
- * Retrieves the master nullifier secret key (nsk_m) corresponding to the specified master nullifier public key
186
- * (Npk_m).
187
- * @throws If the provided public key is not associated with any of the registered accounts.
188
- * @param masterNullifierPublicKey - The master nullifier public key to get secret key for.
189
- * @returns A Promise that resolves to the master nullifier secret key.
190
- * @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
191
- */
192
- getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey) {
193
- // We iterate over the map keys to find the account address that corresponds to the provided public key
194
- for (const [key, value] of __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").entries()) {
195
- if (value.equals(masterNullifierPublicKey.toBuffer())) {
196
- // We extract the account address from the map key
197
- const accountAddress = key.split('-')[0];
198
- // We fetch the secret key and return it
199
- const masterNullifierSecretKeyBuffer = __classPrivateFieldGet(this, _NewTestKeyStore_keys, "f").get(`${accountAddress.toString()}-nsk_m`);
200
- if (!masterNullifierSecretKeyBuffer) {
201
- throw new Error(`Could not find master nullifier secret key for account ${accountAddress.toString()}`);
202
- }
203
- return Promise.resolve(GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer));
204
- }
205
- }
206
- throw new Error(`Could not find master nullifier secret key for public key ${masterNullifierPublicKey.toString()}`);
207
- }
208
- }
209
- _NewTestKeyStore_keys = new WeakMap();
210
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV3X3Rlc3Rfa2V5X3N0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL25ld190ZXN0X2tleV9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLE9BQU8sRUFDTCxZQUFZLEVBQ1osRUFBRSxFQUNGLGNBQWMsRUFFZCxjQUFjLEVBRWQsS0FBSyxHQUNOLE1BQU0sb0JBQW9CLENBQUM7QUFFNUIsT0FBTyxFQUFFLGFBQWEsRUFBRSxzQkFBc0IsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR2pGOzs7R0FHRztBQUNILE1BQU0sT0FBTyxlQUFlO0lBRzFCLFlBQW9CLEtBQWUsRUFBRSxRQUFzQjtRQUF2QyxVQUFLL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_pair.ts DELETED
@@ -1,48 +0,0 @@
1
- import { type KeyPair, type PublicKey } from '@aztec/circuit-types';
2
- import { type GrumpkinPrivateKey, GrumpkinScalar } from '@aztec/circuits.js';
3
- import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
4
-
5
- /**
6
- * The ConstantKeyPair class is an implementation of the KeyPair interface, which allows generation and management of
7
- * a constant public and private key pair. It provides methods for creating a random instance of the key pair,
8
- * retrieving the public key, getting the private key. This class ensures the persistence and consistency of
9
- * the generated keys, making it suitable for cryptographic operations where constant key pairs are required.
10
- */
11
- export class ConstantKeyPair implements KeyPair {
12
- /**
13
- * Generate a random ConstantKeyPair instance using the .
14
- * The random private key is generated using 32 random bytes, and the corresponding public key is calculated
15
- * by multiplying the Grumpkin generator point with the private key. This function provides an efficient
16
- * way of generating unique key pairs for cryptographic purposes.
17
- *
18
- * @param curve - The curve used for elliptic curve cryptography operations.
19
- * @returns A randomly generated ConstantKeyPair instance.
20
- */
21
- public static random(curve: Grumpkin) {
22
- const privateKey = GrumpkinScalar.random();
23
- const publicKey = curve.mul(curve.generator(), privateKey);
24
- return new ConstantKeyPair(publicKey, privateKey);
25
- }
26
-
27
- /**
28
- * Creates a new instance from a private key.
29
- * @param curve - The curve used for elliptic curve cryptography operations.
30
- * @param signer - The signer to be used on the account.
31
- * @param privateKey - The private key.
32
- * @returns A new instance.
33
- */
34
- public static fromPrivateKey(curve: Grumpkin, privateKey: GrumpkinPrivateKey) {
35
- const publicKey = curve.mul(curve.generator(), privateKey);
36
- return new ConstantKeyPair(publicKey, privateKey);
37
- }
38
-
39
- constructor(private publicKey: PublicKey, private privateKey: GrumpkinPrivateKey) {}
40
-
41
- public getPublicKey(): PublicKey {
42
- return this.publicKey;
43
- }
44
-
45
- public getPrivateKey(): GrumpkinPrivateKey {
46
- return this.privateKey;
47
- }
48
- }
@@ -1,245 +0,0 @@
1
- import { type NewKeyStore, type PublicKey } from '@aztec/circuit-types';
2
- import {
3
- AztecAddress,
4
- Fr,
5
- GeneratorIndex,
6
- type GrumpkinPrivateKey,
7
- GrumpkinScalar,
8
- type PartialAddress,
9
- Point,
10
- } from '@aztec/circuits.js';
11
- import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
12
- import { poseidon2Hash, sha512ToGrumpkinScalar } from '@aztec/foundation/crypto';
13
- import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';
14
-
15
- /**
16
- * TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
17
- * It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
18
- */
19
- export class NewTestKeyStore implements NewKeyStore {
20
- #keys: AztecMap<string, Buffer>;
21
-
22
- constructor(private curve: Grumpkin, database: AztecKVStore) {
23
- this.#keys = database.openMap('key_store');
24
- }
25
-
26
- /**
27
- * Creates a new account from a randomly generated secret key.
28
- * @returns A promise that resolves to the newly created account's AztecAddress.
29
- */
30
- public createAccount(): Promise<AztecAddress> {
31
- const sk = Fr.random();
32
- const partialAddress = Fr.random();
33
- return this.addAccount(sk, partialAddress);
34
- }
35
-
36
- /**
37
- * Adds an account to the key store from the provided secret key.
38
- * @param sk - The secret key of the account.
39
- * @param partialAddress - The partial address of the account.
40
- * @returns The account's address.
41
- */
42
- public async addAccount(sk: Fr, partialAddress: PartialAddress): Promise<AztecAddress> {
43
- // First we derive master secret keys - we use sha512 here because this derivation will never take place
44
- // in a circuit
45
- const masterNullifierSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.NSK_M]);
46
- const masterIncomingViewingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.IVSK_M]);
47
- const masterOutgoingViewingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.OVSK_M]);
48
- const masterTaggingSecretKey = sha512ToGrumpkinScalar([sk, GeneratorIndex.TSK_M]);
49
-
50
- // Then we derive master public keys
51
- const masterNullifierPublicKey = this.curve.mul(this.curve.generator(), masterNullifierSecretKey);
52
- const masterIncomingViewingPublicKey = this.curve.mul(this.curve.generator(), masterIncomingViewingSecretKey);
53
- const masterOutgoingViewingPublicKey = this.curve.mul(this.curve.generator(), masterOutgoingViewingSecretKey);
54
- const masterTaggingPublicKey = this.curve.mul(this.curve.generator(), masterTaggingSecretKey);
55
-
56
- // We hash the public keys to get the public keys hash
57
- const publicKeysHash = poseidon2Hash([
58
- masterNullifierPublicKey,
59
- masterIncomingViewingPublicKey,
60
- masterOutgoingViewingPublicKey,
61
- masterTaggingPublicKey,
62
- GeneratorIndex.PUBLIC_KEYS_HASH,
63
- ]);
64
-
65
- // We hash the partial address and the public keys hash to get the account address
66
- // TODO(#5726): Should GeneratorIndex.CONTRACT_ADDRESS be removed given that we introduced CONTRACT_ADDRESS_V1?
67
- // TODO(#5726): Move the following line to AztecAddress class?
68
- const accountAddressFr = poseidon2Hash([partialAddress, publicKeysHash, GeneratorIndex.CONTRACT_ADDRESS_V1]);
69
- const accountAddress = AztecAddress.fromField(accountAddressFr);
70
-
71
- // We store all the public and secret keys in the database
72
- await this.#keys.set(`${accountAddress.toString()}-nsk_m`, masterNullifierSecretKey.toBuffer());
73
- await this.#keys.set(`${accountAddress.toString()}-ivsk_m`, masterIncomingViewingSecretKey.toBuffer());
74
- await this.#keys.set(`${accountAddress.toString()}-ovsk_m`, masterOutgoingViewingSecretKey.toBuffer());
75
- await this.#keys.set(`${accountAddress.toString()}-tsk_m`, masterTaggingSecretKey.toBuffer());
76
-
77
- await this.#keys.set(`${accountAddress.toString()}-npk_m`, masterNullifierPublicKey.toBuffer());
78
- await this.#keys.set(`${accountAddress.toString()}-ivpk_m`, masterIncomingViewingPublicKey.toBuffer());
79
- await this.#keys.set(`${accountAddress.toString()}-ovpk_m`, masterOutgoingViewingPublicKey.toBuffer());
80
- await this.#keys.set(`${accountAddress.toString()}-tpk_m`, masterTaggingPublicKey.toBuffer());
81
-
82
- // At last, we return the newly derived account address
83
- return Promise.resolve(accountAddress);
84
- }
85
-
86
- /**
87
- * Retrieves addresses of accounts stored in the key store.
88
- * @returns A Promise that resolves to an array of account addresses.
89
- */
90
- public getAccounts(): Promise<AztecAddress[]> {
91
- const allMapKeys = Array.from(this.#keys.keys());
92
- // We return account addresses based on the map keys that end with '-nsk_m'
93
- const accounts = allMapKeys.filter(key => key.endsWith('-nsk_m')).map(key => key.split('-')[0]);
94
- return Promise.resolve(accounts.map(account => AztecAddress.fromString(account)));
95
- }
96
-
97
- /**
98
- * Gets the master nullifier public key for a given account.
99
- * @throws If the account does not exist in the key store.
100
- * @param account - The account address for which to retrieve the master nullifier public key.
101
- * @returns The master nullifier public key for the account.
102
- */
103
- public getMasterNullifierPublicKey(account: AztecAddress): Promise<PublicKey> {
104
- const masterNullifierPublicKeyBuffer = this.#keys.get(`${account.toString()}-npk_m`);
105
- if (!masterNullifierPublicKeyBuffer) {
106
- throw new Error(`Account ${account.toString()} does not exist.`);
107
- }
108
- return Promise.resolve(Point.fromBuffer(masterNullifierPublicKeyBuffer));
109
- }
110
-
111
- /**
112
- * Gets the master incoming viewing public key for a given account.
113
- * @throws If the account does not exist in the key store.
114
- * @param account - The account address for which to retrieve the master incoming viewing public key.
115
- * @returns The master incoming viewing public key for the account.
116
- */
117
- public getMasterIncomingViewingPublicKey(account: AztecAddress): Promise<PublicKey> {
118
- const masterIncomingViewingPublicKeyBuffer = this.#keys.get(`${account.toString()}-ivpk_m`);
119
- if (!masterIncomingViewingPublicKeyBuffer) {
120
- throw new Error(`Account ${account.toString()} does not exist.`);
121
- }
122
- return Promise.resolve(Point.fromBuffer(masterIncomingViewingPublicKeyBuffer));
123
- }
124
-
125
- /**
126
- * Retrieves the master outgoing viewing public key.
127
- * @throws If the account does not exist in the key store.
128
- * @param account - The account to retrieve the master outgoing viewing key for.
129
- * @returns A Promise that resolves to the master outgoing viewing key.
130
- */
131
- public getMasterOutgoingViewingPublicKey(account: AztecAddress): Promise<PublicKey> {
132
- const masterOutgoingViewingPublicKeyBuffer = this.#keys.get(`${account.toString()}-ovpk_m`);
133
- if (!masterOutgoingViewingPublicKeyBuffer) {
134
- throw new Error(`Account ${account.toString()} does not exist.`);
135
- }
136
- return Promise.resolve(Point.fromBuffer(masterOutgoingViewingPublicKeyBuffer));
137
- }
138
-
139
- /**
140
- * Retrieves the master tagging public key.
141
- * @throws If the account does not exist in the key store.
142
- * @param account - The account to retrieve the master tagging key for.
143
- * @returns A Promise that resolves to the master tagging key.
144
- */
145
- public getMasterTaggingPublicKey(account: AztecAddress): Promise<PublicKey> {
146
- const masterTaggingPublicKeyBuffer = this.#keys.get(`${account.toString()}-tpk_m`);
147
- if (!masterTaggingPublicKeyBuffer) {
148
- throw new Error(`Account ${account.toString()} does not exist.`);
149
- }
150
- return Promise.resolve(Point.fromBuffer(masterTaggingPublicKeyBuffer));
151
- }
152
-
153
- /**
154
- * Retrieves application nullifier secret key.
155
- * @throws If the account does not exist in the key store.
156
- * @param account - The account to retrieve the application nullifier secret key for.
157
- * @param app - The application address to retrieve the nullifier secret key for.
158
- * @returns A Promise that resolves to the application nullifier secret key.
159
- */
160
- public getAppNullifierSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
161
- const masterNullifierSecretKeyBuffer = this.#keys.get(`${account.toString()}-nsk_m`);
162
- if (!masterNullifierSecretKeyBuffer) {
163
- throw new Error(`Account ${account.toString()} does not exist.`);
164
- }
165
- const masterNullifierSecretKey = GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer);
166
-
167
- return Promise.resolve(
168
- poseidon2Hash([masterNullifierSecretKey.high, masterNullifierSecretKey.low, app, GeneratorIndex.NSK_M]),
169
- );
170
- }
171
-
172
- /**
173
- * Retrieves application incoming viewing secret key.
174
- * @throws If the account does not exist in the key store.
175
- * @param account - The account to retrieve the application incoming viewing secret key for.
176
- * @param app - The application address to retrieve the incoming viewing secret key for.
177
- * @returns A Promise that resolves to the application incoming viewing secret key.
178
- */
179
- public getAppIncomingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
180
- const masterIncomingViewingSecretKeyBuffer = this.#keys.get(`${account.toString()}-ivsk_m`);
181
- if (!masterIncomingViewingSecretKeyBuffer) {
182
- throw new Error(`Account ${account.toString()} does not exist.`);
183
- }
184
- const masterIncomingViewingSecretKey = GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer);
185
-
186
- return Promise.resolve(
187
- poseidon2Hash([
188
- masterIncomingViewingSecretKey.high,
189
- masterIncomingViewingSecretKey.low,
190
- app,
191
- GeneratorIndex.IVSK_M,
192
- ]),
193
- );
194
- }
195
-
196
- /**
197
- * Retrieves application outgoing viewing secret key.
198
- * @throws If the account does not exist in the key store.
199
- * @param account - The account to retrieve the application outgoing viewing secret key for.
200
- * @param app - The application address to retrieve the outgoing viewing secret key for.
201
- * @returns A Promise that resolves to the application outgoing viewing secret key.
202
- */
203
- public getAppOutgoingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
204
- const masterOutgoingViewingSecretKeyBuffer = this.#keys.get(`${account.toString()}-ovsk_m`);
205
- if (!masterOutgoingViewingSecretKeyBuffer) {
206
- throw new Error(`Account ${account.toString()} does not exist.`);
207
- }
208
- const masterOutgoingViewingSecretKey = GrumpkinScalar.fromBuffer(masterOutgoingViewingSecretKeyBuffer);
209
-
210
- return Promise.resolve(
211
- poseidon2Hash([
212
- masterOutgoingViewingSecretKey.high,
213
- masterOutgoingViewingSecretKey.low,
214
- app,
215
- GeneratorIndex.OVSK_M,
216
- ]),
217
- );
218
- }
219
-
220
- /**
221
- * Retrieves the master nullifier secret key (nsk_m) corresponding to the specified master nullifier public key
222
- * (Npk_m).
223
- * @throws If the provided public key is not associated with any of the registered accounts.
224
- * @param masterNullifierPublicKey - The master nullifier public key to get secret key for.
225
- * @returns A Promise that resolves to the master nullifier secret key.
226
- * @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
227
- */
228
- public getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey: PublicKey): Promise<GrumpkinPrivateKey> {
229
- // We iterate over the map keys to find the account address that corresponds to the provided public key
230
- for (const [key, value] of this.#keys.entries()) {
231
- if (value.equals(masterNullifierPublicKey.toBuffer())) {
232
- // We extract the account address from the map key
233
- const accountAddress = key.split('-')[0];
234
- // We fetch the secret key and return it
235
- const masterNullifierSecretKeyBuffer = this.#keys.get(`${accountAddress.toString()}-nsk_m`);
236
- if (!masterNullifierSecretKeyBuffer) {
237
- throw new Error(`Could not find master nullifier secret key for account ${accountAddress.toString()}`);
238
- }
239
- return Promise.resolve(GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer));
240
- }
241
- }
242
-
243
- throw new Error(`Could not find master nullifier secret key for public key ${masterNullifierPublicKey.toString()}`);
244
- }
245
- }