@aztec/key-store 0.35.0 → 0.36.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.
- package/dest/index.d.ts +0 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/test_key_store.d.ts +96 -22
- package/dest/test_key_store.d.ts.map +1 -1
- package/dest/test_key_store.js +203 -50
- package/package.json +13 -5
- package/src/index.ts +0 -1
- package/src/test_key_store.ts +254 -55
- package/dest/key_pair.d.ts +0 -35
- package/dest/key_pair.d.ts.map +0 -1
- package/dest/key_pair.js +0 -45
- package/dest/new_test_key_store.d.ts +0 -92
- package/dest/new_test_key_store.d.ts.map +0 -1
- package/dest/new_test_key_store.js +0 -210
- package/src/key_pair.ts +0 -48
- package/src/new_test_key_store.ts +0 -245
package/src/test_key_store.ts
CHANGED
|
@@ -1,96 +1,295 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type KeyStore, type PublicKey } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
AztecAddress,
|
|
4
|
+
Fr,
|
|
5
|
+
GeneratorIndex,
|
|
4
6
|
type GrumpkinPrivateKey,
|
|
5
7
|
GrumpkinScalar,
|
|
8
|
+
type PartialAddress,
|
|
6
9
|
Point,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
derivePublicKey,
|
|
10
|
+
computeAppNullifierSecretKey,
|
|
11
|
+
deriveKeys,
|
|
10
12
|
} from '@aztec/circuits.js';
|
|
11
|
-
import {
|
|
13
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
12
14
|
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';
|
|
13
15
|
|
|
14
|
-
import { ConstantKeyPair } from './key_pair.js';
|
|
15
|
-
|
|
16
16
|
/**
|
|
17
17
|
* TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
|
|
18
18
|
* It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
|
|
19
|
-
* TODO(#5627): 💣💣💣
|
|
20
19
|
*/
|
|
21
20
|
export class TestKeyStore implements KeyStore {
|
|
22
21
|
#keys: AztecMap<string, Buffer>;
|
|
23
22
|
|
|
24
|
-
constructor(
|
|
23
|
+
constructor(database: AztecKVStore) {
|
|
25
24
|
this.#keys = database.openMap('key_store');
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new account from a randomly generated secret key.
|
|
29
|
+
* @returns A promise that resolves to the newly created account's AztecAddress.
|
|
30
|
+
*/
|
|
31
|
+
public createAccount(): Promise<AztecAddress> {
|
|
32
|
+
const sk = Fr.random();
|
|
33
|
+
const partialAddress = Fr.random();
|
|
34
|
+
return this.addAccount(sk, partialAddress);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Adds an account to the key store from the provided secret key.
|
|
39
|
+
* @param sk - The secret key of the account.
|
|
40
|
+
* @param partialAddress - The partial address of the account.
|
|
41
|
+
* @returns The account's address.
|
|
42
|
+
*/
|
|
43
|
+
public async addAccount(sk: Fr, partialAddress: PartialAddress): Promise<AztecAddress> {
|
|
44
|
+
const {
|
|
45
|
+
publicKeysHash,
|
|
46
|
+
masterNullifierSecretKey,
|
|
47
|
+
masterIncomingViewingSecretKey,
|
|
48
|
+
masterOutgoingViewingSecretKey,
|
|
49
|
+
masterTaggingSecretKey,
|
|
50
|
+
masterNullifierPublicKey,
|
|
51
|
+
masterIncomingViewingPublicKey,
|
|
52
|
+
masterOutgoingViewingPublicKey,
|
|
53
|
+
masterTaggingPublicKey,
|
|
54
|
+
} = deriveKeys(sk);
|
|
55
|
+
|
|
56
|
+
// We hash the partial address and the public keys hash to get the account address
|
|
57
|
+
// TODO(#5726): Move the following line to AztecAddress class?
|
|
58
|
+
const accountAddressFr = poseidon2Hash([publicKeysHash, partialAddress, GeneratorIndex.CONTRACT_ADDRESS_V1]);
|
|
59
|
+
const accountAddress = AztecAddress.fromField(accountAddressFr);
|
|
60
|
+
|
|
61
|
+
// We save the keys to db
|
|
62
|
+
await this.#keys.set(`${accountAddress.toString()}-public_keys_hash`, publicKeysHash.toBuffer());
|
|
63
|
+
|
|
64
|
+
await this.#keys.set(`${accountAddress.toString()}-nsk_m`, masterNullifierSecretKey.toBuffer());
|
|
65
|
+
await this.#keys.set(`${accountAddress.toString()}-ivsk_m`, masterIncomingViewingSecretKey.toBuffer());
|
|
66
|
+
await this.#keys.set(`${accountAddress.toString()}-ovsk_m`, masterOutgoingViewingSecretKey.toBuffer());
|
|
67
|
+
await this.#keys.set(`${accountAddress.toString()}-tsk_m`, masterTaggingSecretKey.toBuffer());
|
|
68
|
+
|
|
69
|
+
await this.#keys.set(`${accountAddress.toString()}-npk_m`, masterNullifierPublicKey.toBuffer());
|
|
70
|
+
await this.#keys.set(`${accountAddress.toString()}-ivpk_m`, masterIncomingViewingPublicKey.toBuffer());
|
|
71
|
+
await this.#keys.set(`${accountAddress.toString()}-ovpk_m`, masterOutgoingViewingPublicKey.toBuffer());
|
|
72
|
+
await this.#keys.set(`${accountAddress.toString()}-tpk_m`, masterTaggingPublicKey.toBuffer());
|
|
73
|
+
|
|
74
|
+
// At last, we return the newly derived account address
|
|
75
|
+
return Promise.resolve(accountAddress);
|
|
38
76
|
}
|
|
39
77
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves addresses of accounts stored in the key store.
|
|
80
|
+
* @returns A Promise that resolves to an array of account addresses.
|
|
81
|
+
*/
|
|
82
|
+
public getAccounts(): Promise<AztecAddress[]> {
|
|
83
|
+
const allMapKeys = Array.from(this.#keys.keys());
|
|
84
|
+
// We return account addresses based on the map keys that end with '-nsk_m'
|
|
85
|
+
const accounts = allMapKeys.filter(key => key.endsWith('-nsk_m')).map(key => key.split('-')[0]);
|
|
86
|
+
return Promise.resolve(accounts.map(account => AztecAddress.fromString(account)));
|
|
43
87
|
}
|
|
44
88
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Gets the master nullifier public key for a given account.
|
|
91
|
+
* @throws If the account does not exist in the key store.
|
|
92
|
+
* @param account - The account address for which to retrieve the master nullifier public key.
|
|
93
|
+
* @returns The master nullifier public key for the account.
|
|
94
|
+
*/
|
|
95
|
+
public async getMasterNullifierPublicKey(account: AztecAddress): Promise<PublicKey> {
|
|
96
|
+
const masterNullifierPublicKeyBuffer = this.#keys.get(`${account.toString()}-npk_m`);
|
|
97
|
+
if (!masterNullifierPublicKeyBuffer) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return Promise.resolve(Point.fromBuffer(masterNullifierPublicKeyBuffer));
|
|
48
103
|
}
|
|
49
104
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Gets the master incoming viewing public key for a given account.
|
|
107
|
+
* @throws If the account does not exist in the key store.
|
|
108
|
+
* @param account - The account address for which to retrieve the master incoming viewing public key.
|
|
109
|
+
* @returns The master incoming viewing public key for the account.
|
|
110
|
+
*/
|
|
111
|
+
public async getMasterIncomingViewingPublicKey(account: AztecAddress): Promise<PublicKey> {
|
|
112
|
+
const masterIncomingViewingPublicKeyBuffer = this.#keys.get(`${account.toString()}-ivpk_m`);
|
|
113
|
+
if (!masterIncomingViewingPublicKeyBuffer) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return Promise.resolve(Point.fromBuffer(masterIncomingViewingPublicKeyBuffer));
|
|
53
119
|
}
|
|
54
120
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves the master outgoing viewing public key.
|
|
123
|
+
* @throws If the account does not exist in the key store.
|
|
124
|
+
* @param account - The account to retrieve the master outgoing viewing key for.
|
|
125
|
+
* @returns A Promise that resolves to the master outgoing viewing key.
|
|
126
|
+
*/
|
|
127
|
+
public async getMasterOutgoingViewingPublicKey(account: AztecAddress): Promise<PublicKey> {
|
|
128
|
+
const masterOutgoingViewingPublicKeyBuffer = this.#keys.get(`${account.toString()}-ovpk_m`);
|
|
129
|
+
if (!masterOutgoingViewingPublicKeyBuffer) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
132
|
+
);
|
|
65
133
|
}
|
|
66
|
-
|
|
134
|
+
return Promise.resolve(Point.fromBuffer(masterOutgoingViewingPublicKeyBuffer));
|
|
67
135
|
}
|
|
68
136
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves the master tagging public key.
|
|
139
|
+
* @throws If the account does not exist in the key store.
|
|
140
|
+
* @param account - The account to retrieve the master tagging key for.
|
|
141
|
+
* @returns A Promise that resolves to the master tagging key.
|
|
142
|
+
*/
|
|
143
|
+
public async getMasterTaggingPublicKey(account: AztecAddress): Promise<PublicKey> {
|
|
144
|
+
const masterTaggingPublicKeyBuffer = this.#keys.get(`${account.toString()}-tpk_m`);
|
|
145
|
+
if (!masterTaggingPublicKeyBuffer) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return Promise.resolve(Point.fromBuffer(masterTaggingPublicKeyBuffer));
|
|
72
151
|
}
|
|
73
152
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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 async getAppNullifierSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
|
|
161
|
+
const masterNullifierSecretKeyBuffer = this.#keys.get(`${account.toString()}-nsk_m`);
|
|
162
|
+
if (!masterNullifierSecretKeyBuffer) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const masterNullifierSecretKey = GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer);
|
|
168
|
+
const appNullifierSecretKey = computeAppNullifierSecretKey(masterNullifierSecretKey, app);
|
|
169
|
+
return Promise.resolve(appNullifierSecretKey);
|
|
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 async getAppIncomingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
|
|
180
|
+
const masterIncomingViewingSecretKeyBuffer = this.#keys.get(`${account.toString()}-ivsk_m`);
|
|
181
|
+
if (!masterIncomingViewingSecretKeyBuffer) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const masterIncomingViewingSecretKey = GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer);
|
|
187
|
+
|
|
188
|
+
return Promise.resolve(
|
|
189
|
+
poseidon2Hash([
|
|
190
|
+
masterIncomingViewingSecretKey.high,
|
|
191
|
+
masterIncomingViewingSecretKey.low,
|
|
192
|
+
app,
|
|
193
|
+
GeneratorIndex.IVSK_M,
|
|
194
|
+
]),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves application outgoing viewing secret key.
|
|
200
|
+
* @throws If the account does not exist in the key store.
|
|
201
|
+
* @param account - The account to retrieve the application outgoing viewing secret key for.
|
|
202
|
+
* @param app - The application address to retrieve the outgoing viewing secret key for.
|
|
203
|
+
* @returns A Promise that resolves to the application outgoing viewing secret key.
|
|
204
|
+
*/
|
|
205
|
+
public async getAppOutgoingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr> {
|
|
206
|
+
const masterOutgoingViewingSecretKeyBuffer = this.#keys.get(`${account.toString()}-ovsk_m`);
|
|
207
|
+
if (!masterOutgoingViewingSecretKeyBuffer) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const masterOutgoingViewingSecretKey = GrumpkinScalar.fromBuffer(masterOutgoingViewingSecretKeyBuffer);
|
|
213
|
+
|
|
214
|
+
return Promise.resolve(
|
|
215
|
+
poseidon2Hash([
|
|
216
|
+
masterOutgoingViewingSecretKey.high,
|
|
217
|
+
masterOutgoingViewingSecretKey.low,
|
|
218
|
+
app,
|
|
219
|
+
GeneratorIndex.OVSK_M,
|
|
220
|
+
]),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Retrieves the master nullifier secret key (nsk_m) corresponding to the specified master nullifier public key
|
|
226
|
+
* (Npk_m).
|
|
227
|
+
* @throws If the provided public key is not associated with any of the registered accounts.
|
|
228
|
+
* @param masterNullifierPublicKey - The master nullifier public key to get secret key for.
|
|
229
|
+
* @returns A Promise that resolves to the master nullifier secret key.
|
|
230
|
+
* @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
|
|
231
|
+
*/
|
|
232
|
+
public getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey: PublicKey): Promise<GrumpkinPrivateKey> {
|
|
233
|
+
// We iterate over the map keys to find the account address that corresponds to the provided public key
|
|
234
|
+
for (const [key, value] of this.#keys.entries()) {
|
|
235
|
+
if (value.equals(masterNullifierPublicKey.toBuffer())) {
|
|
236
|
+
// We extract the account address from the map key
|
|
237
|
+
const accountAddress = key.split('-')[0];
|
|
238
|
+
// We fetch the secret key and return it
|
|
239
|
+
const masterNullifierSecretKeyBuffer = this.#keys.get(`${accountAddress.toString()}-nsk_m`);
|
|
240
|
+
if (!masterNullifierSecretKeyBuffer) {
|
|
241
|
+
throw new Error(`Could not find master nullifier secret key for account ${accountAddress.toString()}`);
|
|
242
|
+
}
|
|
243
|
+
return Promise.resolve(GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
throw new Error(`Could not find master nullifier secret key for public key ${masterNullifierPublicKey.toString()}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Retrieves the master incoming viewing secret key (ivsk_m) corresponding to the specified master incoming viewing
|
|
252
|
+
* public key (Ivpk_m).
|
|
253
|
+
* @throws If the provided public key is not associated with any of the registered accounts.
|
|
254
|
+
* @param masterIncomingViewingPublicKey - The master nullifier public key to get secret key for.
|
|
255
|
+
* @returns A Promise that resolves to the master nullifier secret key.
|
|
256
|
+
* @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
|
|
257
|
+
*/
|
|
258
|
+
public getMasterIncomingViewingSecretKeyForPublicKey(
|
|
259
|
+
masterIncomingViewingPublicKey: PublicKey,
|
|
260
|
+
): Promise<GrumpkinPrivateKey> {
|
|
261
|
+
// We iterate over the map keys to find the account address that corresponds to the provided public key
|
|
262
|
+
for (const [key, value] of this.#keys.entries()) {
|
|
263
|
+
if (value.equals(masterIncomingViewingPublicKey.toBuffer())) {
|
|
264
|
+
// We extract the account address from the map key
|
|
265
|
+
const accountAddress = key.split('-')[0];
|
|
266
|
+
// We fetch the secret key and return it
|
|
267
|
+
const masterIncomingViewingSecretKeyBuffer = this.#keys.get(`${accountAddress.toString()}-ivsk_m`);
|
|
268
|
+
if (!masterIncomingViewingSecretKeyBuffer) {
|
|
269
|
+
throw new Error(`Could not find master incoming viewing secret key for account ${accountAddress.toString()}`);
|
|
270
|
+
}
|
|
271
|
+
return Promise.resolve(GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Could not find master incoming viewing secret key for public key ${masterIncomingViewingPublicKey.toString()}`,
|
|
277
|
+
);
|
|
77
278
|
}
|
|
78
279
|
|
|
79
280
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param pubKey - The public key of the account to retrieve.
|
|
85
|
-
* @returns The KeyPair object associated with the provided key.
|
|
281
|
+
* Retrieves public keys hash of the account
|
|
282
|
+
* @throws If the provided account address is not associated with any of the registered accounts.
|
|
283
|
+
* @param account - The account address to get public keys hash for.
|
|
284
|
+
* @returns A Promise that resolves to the public keys hash.
|
|
86
285
|
*/
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
286
|
+
public async getPublicKeysHash(account: AztecAddress): Promise<Fr> {
|
|
287
|
+
const publicKeysHashBuffer = this.#keys.get(`${account.toString()}-public_keys_hash`);
|
|
288
|
+
if (!publicKeysHashBuffer) {
|
|
90
289
|
throw new Error(
|
|
91
|
-
|
|
290
|
+
`Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`,
|
|
92
291
|
);
|
|
93
292
|
}
|
|
94
|
-
return
|
|
293
|
+
return Promise.resolve(Fr.fromBuffer(publicKeysHashBuffer));
|
|
95
294
|
}
|
|
96
295
|
}
|
package/dest/key_pair.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { type KeyPair, type PublicKey } from '@aztec/circuit-types';
|
|
2
|
-
import { type GrumpkinPrivateKey } from '@aztec/circuits.js';
|
|
3
|
-
import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
4
|
-
/**
|
|
5
|
-
* The ConstantKeyPair class is an implementation of the KeyPair interface, which allows generation and management of
|
|
6
|
-
* a constant public and private key pair. It provides methods for creating a random instance of the key pair,
|
|
7
|
-
* retrieving the public key, getting the private key. This class ensures the persistence and consistency of
|
|
8
|
-
* the generated keys, making it suitable for cryptographic operations where constant key pairs are required.
|
|
9
|
-
*/
|
|
10
|
-
export declare class ConstantKeyPair implements KeyPair {
|
|
11
|
-
private publicKey;
|
|
12
|
-
private privateKey;
|
|
13
|
-
/**
|
|
14
|
-
* Generate a random ConstantKeyPair instance using the .
|
|
15
|
-
* The random private key is generated using 32 random bytes, and the corresponding public key is calculated
|
|
16
|
-
* by multiplying the Grumpkin generator point with the private key. This function provides an efficient
|
|
17
|
-
* way of generating unique key pairs for cryptographic purposes.
|
|
18
|
-
*
|
|
19
|
-
* @param curve - The curve used for elliptic curve cryptography operations.
|
|
20
|
-
* @returns A randomly generated ConstantKeyPair instance.
|
|
21
|
-
*/
|
|
22
|
-
static random(curve: Grumpkin): ConstantKeyPair;
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new instance from a private key.
|
|
25
|
-
* @param curve - The curve used for elliptic curve cryptography operations.
|
|
26
|
-
* @param signer - The signer to be used on the account.
|
|
27
|
-
* @param privateKey - The private key.
|
|
28
|
-
* @returns A new instance.
|
|
29
|
-
*/
|
|
30
|
-
static fromPrivateKey(curve: Grumpkin, privateKey: GrumpkinPrivateKey): ConstantKeyPair;
|
|
31
|
-
constructor(publicKey: PublicKey, privateKey: GrumpkinPrivateKey);
|
|
32
|
-
getPublicKey(): PublicKey;
|
|
33
|
-
getPrivateKey(): GrumpkinPrivateKey;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=key_pair.d.ts.map
|
package/dest/key_pair.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"key_pair.d.ts","sourceRoot":"","sources":["../src/key_pair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,OAAO;IA4BjC,OAAO,CAAC,SAAS;IAAa,OAAO,CAAC,UAAU;IA3B5D;;;;;;;;OAQG;WACW,MAAM,CAAC,KAAK,EAAE,QAAQ;IAMpC;;;;;;OAMG;WACW,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB;gBAKxD,SAAS,EAAE,SAAS,EAAU,UAAU,EAAE,kBAAkB;IAEzE,YAAY,IAAI,SAAS;IAIzB,aAAa,IAAI,kBAAkB;CAG3C"}
|
package/dest/key_pair.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { GrumpkinScalar } from '@aztec/circuits.js';
|
|
2
|
-
/**
|
|
3
|
-
* The ConstantKeyPair class is an implementation of the KeyPair interface, which allows generation and management of
|
|
4
|
-
* a constant public and private key pair. It provides methods for creating a random instance of the key pair,
|
|
5
|
-
* retrieving the public key, getting the private key. This class ensures the persistence and consistency of
|
|
6
|
-
* the generated keys, making it suitable for cryptographic operations where constant key pairs are required.
|
|
7
|
-
*/
|
|
8
|
-
export class ConstantKeyPair {
|
|
9
|
-
/**
|
|
10
|
-
* Generate a random ConstantKeyPair instance using the .
|
|
11
|
-
* The random private key is generated using 32 random bytes, and the corresponding public key is calculated
|
|
12
|
-
* by multiplying the Grumpkin generator point with the private key. This function provides an efficient
|
|
13
|
-
* way of generating unique key pairs for cryptographic purposes.
|
|
14
|
-
*
|
|
15
|
-
* @param curve - The curve used for elliptic curve cryptography operations.
|
|
16
|
-
* @returns A randomly generated ConstantKeyPair instance.
|
|
17
|
-
*/
|
|
18
|
-
static random(curve) {
|
|
19
|
-
const privateKey = GrumpkinScalar.random();
|
|
20
|
-
const publicKey = curve.mul(curve.generator(), privateKey);
|
|
21
|
-
return new ConstantKeyPair(publicKey, privateKey);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new instance from a private key.
|
|
25
|
-
* @param curve - The curve used for elliptic curve cryptography operations.
|
|
26
|
-
* @param signer - The signer to be used on the account.
|
|
27
|
-
* @param privateKey - The private key.
|
|
28
|
-
* @returns A new instance.
|
|
29
|
-
*/
|
|
30
|
-
static fromPrivateKey(curve, privateKey) {
|
|
31
|
-
const publicKey = curve.mul(curve.generator(), privateKey);
|
|
32
|
-
return new ConstantKeyPair(publicKey, privateKey);
|
|
33
|
-
}
|
|
34
|
-
constructor(publicKey, privateKey) {
|
|
35
|
-
this.publicKey = publicKey;
|
|
36
|
-
this.privateKey = privateKey;
|
|
37
|
-
}
|
|
38
|
-
getPublicKey() {
|
|
39
|
-
return this.publicKey;
|
|
40
|
-
}
|
|
41
|
-
getPrivateKey() {
|
|
42
|
-
return this.privateKey;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2V5X3BhaXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMva2V5X3BhaXIudHMiXSwibmFt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@aztec/circuit-types';
|
|
2
|
-
import { AztecAddress, Fr, type GrumpkinPrivateKey, type PartialAddress } from '@aztec/circuits.js';
|
|
3
|
-
import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
4
|
-
import { type AztecKVStore } from '@aztec/kv-store';
|
|
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 declare class NewTestKeyStore implements NewKeyStore {
|
|
10
|
-
#private;
|
|
11
|
-
private curve;
|
|
12
|
-
constructor(curve: Grumpkin, database: AztecKVStore);
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new account from a randomly generated secret key.
|
|
15
|
-
* @returns A promise that resolves to the newly created account's AztecAddress.
|
|
16
|
-
*/
|
|
17
|
-
createAccount(): Promise<AztecAddress>;
|
|
18
|
-
/**
|
|
19
|
-
* Adds an account to the key store from the provided secret key.
|
|
20
|
-
* @param sk - The secret key of the account.
|
|
21
|
-
* @param partialAddress - The partial address of the account.
|
|
22
|
-
* @returns The account's address.
|
|
23
|
-
*/
|
|
24
|
-
addAccount(sk: Fr, partialAddress: PartialAddress): Promise<AztecAddress>;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves addresses of accounts stored in the key store.
|
|
27
|
-
* @returns A Promise that resolves to an array of account addresses.
|
|
28
|
-
*/
|
|
29
|
-
getAccounts(): Promise<AztecAddress[]>;
|
|
30
|
-
/**
|
|
31
|
-
* Gets the master nullifier public key for a given account.
|
|
32
|
-
* @throws If the account does not exist in the key store.
|
|
33
|
-
* @param account - The account address for which to retrieve the master nullifier public key.
|
|
34
|
-
* @returns The master nullifier public key for the account.
|
|
35
|
-
*/
|
|
36
|
-
getMasterNullifierPublicKey(account: AztecAddress): Promise<PublicKey>;
|
|
37
|
-
/**
|
|
38
|
-
* Gets the master incoming viewing public key for a given account.
|
|
39
|
-
* @throws If the account does not exist in the key store.
|
|
40
|
-
* @param account - The account address for which to retrieve the master incoming viewing public key.
|
|
41
|
-
* @returns The master incoming viewing public key for the account.
|
|
42
|
-
*/
|
|
43
|
-
getMasterIncomingViewingPublicKey(account: AztecAddress): Promise<PublicKey>;
|
|
44
|
-
/**
|
|
45
|
-
* Retrieves the master outgoing viewing public key.
|
|
46
|
-
* @throws If the account does not exist in the key store.
|
|
47
|
-
* @param account - The account to retrieve the master outgoing viewing key for.
|
|
48
|
-
* @returns A Promise that resolves to the master outgoing viewing key.
|
|
49
|
-
*/
|
|
50
|
-
getMasterOutgoingViewingPublicKey(account: AztecAddress): Promise<PublicKey>;
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves the master tagging public key.
|
|
53
|
-
* @throws If the account does not exist in the key store.
|
|
54
|
-
* @param account - The account to retrieve the master tagging key for.
|
|
55
|
-
* @returns A Promise that resolves to the master tagging key.
|
|
56
|
-
*/
|
|
57
|
-
getMasterTaggingPublicKey(account: AztecAddress): Promise<PublicKey>;
|
|
58
|
-
/**
|
|
59
|
-
* Retrieves application nullifier secret key.
|
|
60
|
-
* @throws If the account does not exist in the key store.
|
|
61
|
-
* @param account - The account to retrieve the application nullifier secret key for.
|
|
62
|
-
* @param app - The application address to retrieve the nullifier secret key for.
|
|
63
|
-
* @returns A Promise that resolves to the application nullifier secret key.
|
|
64
|
-
*/
|
|
65
|
-
getAppNullifierSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr>;
|
|
66
|
-
/**
|
|
67
|
-
* Retrieves application incoming viewing secret key.
|
|
68
|
-
* @throws If the account does not exist in the key store.
|
|
69
|
-
* @param account - The account to retrieve the application incoming viewing secret key for.
|
|
70
|
-
* @param app - The application address to retrieve the incoming viewing secret key for.
|
|
71
|
-
* @returns A Promise that resolves to the application incoming viewing secret key.
|
|
72
|
-
*/
|
|
73
|
-
getAppIncomingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr>;
|
|
74
|
-
/**
|
|
75
|
-
* Retrieves application outgoing viewing secret key.
|
|
76
|
-
* @throws If the account does not exist in the key store.
|
|
77
|
-
* @param account - The account to retrieve the application outgoing viewing secret key for.
|
|
78
|
-
* @param app - The application address to retrieve the outgoing viewing secret key for.
|
|
79
|
-
* @returns A Promise that resolves to the application outgoing viewing secret key.
|
|
80
|
-
*/
|
|
81
|
-
getAppOutgoingViewingSecretKey(account: AztecAddress, app: AztecAddress): Promise<Fr>;
|
|
82
|
-
/**
|
|
83
|
-
* Retrieves the master nullifier secret key (nsk_m) corresponding to the specified master nullifier public key
|
|
84
|
-
* (Npk_m).
|
|
85
|
-
* @throws If the provided public key is not associated with any of the registered accounts.
|
|
86
|
-
* @param masterNullifierPublicKey - The master nullifier public key to get secret key for.
|
|
87
|
-
* @returns A Promise that resolves to the master nullifier secret key.
|
|
88
|
-
* @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
|
|
89
|
-
*/
|
|
90
|
-
getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey: PublicKey): Promise<GrumpkinPrivateKey>;
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=new_test_key_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new_test_key_store.d.ts","sourceRoot":"","sources":["../src/new_test_key_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,YAAY,EACZ,EAAE,EAEF,KAAK,kBAAkB,EAEvB,KAAK,cAAc,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAEnE;;;GAGG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IAGrC,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,QAAQ,EAAE,QAAQ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