@aztec/key-store 0.16.4 → 0.16.5
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/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/key_pair.ts +0 -48
- package/src/test_key_store.ts +0 -60
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/key-store",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"typedocOptions": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"rootDir": "./src"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aztec/circuits.js": "0.16.
|
|
34
|
-
"@aztec/foundation": "0.16.
|
|
35
|
-
"@aztec/types": "0.16.
|
|
33
|
+
"@aztec/circuits.js": "0.16.5",
|
|
34
|
+
"@aztec/foundation": "0.16.5",
|
|
35
|
+
"@aztec/types": "0.16.5",
|
|
36
36
|
"tslib": "^2.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
package/src/index.ts
DELETED
package/src/key_pair.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { GrumpkinPrivateKey, GrumpkinScalar } from '@aztec/circuits.js';
|
|
2
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { KeyPair, PublicKey } from '@aztec/types';
|
|
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
|
-
}
|
package/src/test_key_store.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { GrumpkinPrivateKey } from '@aztec/circuits.js';
|
|
2
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { KeyPair, KeyStore, PublicKey } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { ConstantKeyPair } from './key_pair.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
|
|
9
|
-
* It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
|
|
10
|
-
*/
|
|
11
|
-
export class TestKeyStore implements KeyStore {
|
|
12
|
-
private accounts: KeyPair[] = [];
|
|
13
|
-
constructor(private curve: Grumpkin) {}
|
|
14
|
-
|
|
15
|
-
public addAccount(privKey: GrumpkinPrivateKey): PublicKey {
|
|
16
|
-
const keyPair = ConstantKeyPair.fromPrivateKey(this.curve, privKey);
|
|
17
|
-
|
|
18
|
-
// check if private key has already been used
|
|
19
|
-
const account = this.accounts.find(a => a.getPublicKey().equals(keyPair.getPublicKey()));
|
|
20
|
-
if (account) {
|
|
21
|
-
return account.getPublicKey();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.accounts.push(keyPair);
|
|
25
|
-
return keyPair.getPublicKey();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public createAccount(): Promise<PublicKey> {
|
|
29
|
-
const keyPair = ConstantKeyPair.random(this.curve);
|
|
30
|
-
this.accounts.push(keyPair);
|
|
31
|
-
return Promise.resolve(keyPair.getPublicKey());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public getAccounts(): Promise<PublicKey[]> {
|
|
35
|
-
return Promise.resolve(this.accounts.map(a => a.getPublicKey()));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public getAccountPrivateKey(pubKey: PublicKey): Promise<GrumpkinPrivateKey> {
|
|
39
|
-
const account = this.getAccount(pubKey);
|
|
40
|
-
return Promise.resolve(account.getPrivateKey());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieve the KeyPair object associated with a given pub key.
|
|
45
|
-
* Searches through the 'accounts' array for a matching public key and returns the corresponding account (KeyPair).
|
|
46
|
-
* Throws an error if no matching account is found in the 'accounts'.
|
|
47
|
-
*
|
|
48
|
-
* @param pubKey - The public key of the account to retrieve.
|
|
49
|
-
* @returns The KeyPair object associated with the provided key.
|
|
50
|
-
*/
|
|
51
|
-
private getAccount(pubKey: PublicKey) {
|
|
52
|
-
const account = this.accounts.find(a => a.getPublicKey().equals(pubKey));
|
|
53
|
-
if (!account) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
'Unknown account.\nSee docs for context: https://docs.aztec.network/dev_docs/contracts/common_errors#unknown-contract-error',
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return account;
|
|
59
|
-
}
|
|
60
|
-
}
|