@aztec/key-store
Advanced tools
Comparing version 0.1.0-alpha23 to 0.1.0-alpha40
@@ -1,5 +0,4 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { Curve } from '@aztec/circuits.js/barretenberg'; | ||
import { Point } from '@aztec/foundation/fields'; | ||
import { KeyPair } from '@aztec/types'; | ||
import { PrivateKey } from '@aztec/circuits.js'; | ||
import { Grumpkin } from '@aztec/circuits.js/barretenberg'; | ||
import { KeyPair, PublicKey } from '@aztec/types'; | ||
/** | ||
@@ -20,3 +19,3 @@ * The ConstantKeyPair class is an implementation of the KeyPair interface, which allows generation and management of a constant public and private key pair. It provides methods for creating a random instance of the key pair, retrieving the public key, getting the private key. This class ensures the persistence and consistency of the generated keys, making it suitable for cryptographic operations where constant key pairs are required. | ||
*/ | ||
static random(curve: Curve): ConstantKeyPair; | ||
static random(curve: Grumpkin): ConstantKeyPair; | ||
/** | ||
@@ -29,19 +28,7 @@ * Creates a new instance from a private key. | ||
*/ | ||
static fromPrivateKey(curve: Curve, privateKey: Buffer): ConstantKeyPair; | ||
constructor(publicKey: Point, privateKey: Buffer); | ||
/** | ||
* Retrieve the public key from the KeyPair instance. | ||
* The returned public key is a Point object which represents a point on the elliptic curve secp256k1. | ||
* | ||
* @returns The public key as an elliptic curve point. | ||
*/ | ||
getPublicKey(): Point; | ||
/** | ||
* Retrieves the private key of the KeyPair instance. | ||
* The function returns a Promise that resolves to a Buffer containing the private key. | ||
* | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
*/ | ||
getPrivateKey(): Promise<Buffer>; | ||
static fromPrivateKey(curve: Grumpkin, privateKey: PrivateKey): ConstantKeyPair; | ||
constructor(publicKey: PublicKey, privateKey: PrivateKey); | ||
getPublicKey(): PublicKey; | ||
getPrivateKey(): Promise<PrivateKey>; | ||
} | ||
//# sourceMappingURL=key_pair.d.ts.map |
@@ -1,3 +0,2 @@ | ||
import { randomBytes } from '@aztec/foundation/crypto'; | ||
import { Point } from '@aztec/foundation/fields'; | ||
import { PrivateKey } from '@aztec/circuits.js'; | ||
/** | ||
@@ -17,4 +16,4 @@ * The ConstantKeyPair class is an implementation of the KeyPair interface, which allows generation and management of a constant public and private key pair. It provides methods for creating a random instance of the key pair, retrieving the public key, getting the private key. This class ensures the persistence and consistency of the generated keys, making it suitable for cryptographic operations where constant key pairs are required. | ||
static random(curve) { | ||
const privateKey = randomBytes(32); | ||
const publicKey = Point.fromBuffer(curve.mul(curve.generator(), privateKey)); | ||
const privateKey = PrivateKey.random(); | ||
const publicKey = curve.mul(curve.generator(), privateKey); | ||
return new ConstantKeyPair(publicKey, privateKey); | ||
@@ -30,3 +29,3 @@ } | ||
static fromPrivateKey(curve, privateKey) { | ||
const publicKey = Point.fromBuffer(curve.mul(curve.generator(), privateKey)); | ||
const publicKey = curve.mul(curve.generator(), privateKey); | ||
return new ConstantKeyPair(publicKey, privateKey); | ||
@@ -38,17 +37,5 @@ } | ||
} | ||
/** | ||
* Retrieve the public key from the KeyPair instance. | ||
* The returned public key is a Point object which represents a point on the elliptic curve secp256k1. | ||
* | ||
* @returns The public key as an elliptic curve point. | ||
*/ | ||
getPublicKey() { | ||
return this.publicKey; | ||
} | ||
/** | ||
* Retrieves the private key of the KeyPair instance. | ||
* The function returns a Promise that resolves to a Buffer containing the private key. | ||
* | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
*/ | ||
getPrivateKey() { | ||
@@ -58,2 +45,2 @@ return Promise.resolve(this.privateKey); | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia2V5X3BhaXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMva2V5X3BhaXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxLQUFLLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQU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UFDbEIsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0YifQ== |
@@ -1,4 +0,3 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { Curve } from '@aztec/circuits.js/barretenberg'; | ||
import { Point } from '@aztec/circuits.js'; | ||
import { PrivateKey } from '@aztec/circuits.js'; | ||
import { Grumpkin } from '@aztec/circuits.js/barretenberg'; | ||
import { KeyStore, PublicKey } from '@aztec/types'; | ||
@@ -12,35 +11,8 @@ /** | ||
private accounts; | ||
constructor(curve: Curve); | ||
constructor(curve: Grumpkin); | ||
addAccount(privKey: PrivateKey): PublicKey; | ||
createAccount(): Promise<PublicKey>; | ||
getAccounts(): Promise<PublicKey[]>; | ||
getAccountPrivateKey(pubKey: PublicKey): Promise<PrivateKey>; | ||
/** | ||
* Adds an account to the key store from the provided private key. | ||
* @param curve - The curve to use for generating the public key. | ||
* @param privKey - The private key of the account. | ||
* @returns - The account's public key. | ||
*/ | ||
addAccount(privKey: Buffer): PublicKey; | ||
/** | ||
* Adds a new account to the TestKeyStore with a randomly generated ConstantKeyPair. | ||
* The account will have its own private and public key pair, which can be used for signing transactions. | ||
* @param curve - The curve to use for generating the public key. | ||
* @returns A promise that resolves to the newly created account's AztecAddress. | ||
*/ | ||
createAccount(): Promise<Point>; | ||
/** | ||
* Retrieves the public addresses of all accounts stored in the TestKeyStore. | ||
* The returned addresses are instances of `AztecAddress` and can be used for subsequent operations | ||
* such as signing transactions or fetching public/private keys. | ||
* | ||
* @returns A Promise that resolves to an array of AztecAddress instances. | ||
*/ | ||
getAccounts(): Promise<Point[]>; | ||
/** | ||
* Retrieves the private key of the account associated with the specified AztecAddress. | ||
* Throws an error if the provided address is not found in the list of registered accounts. | ||
* | ||
* @param pubKey - The AztecAddress instance representing the account for which the private key is requested. | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
* @deprecated We should not require a keystore to expose private keys in plain. | ||
*/ | ||
getAccountPrivateKey(pubKey: PublicKey): Promise<Buffer>; | ||
/** | ||
* Retrieve the KeyPair object associated with a given pub key. | ||
@@ -47,0 +19,0 @@ * Searches through the 'accounts' array for a matching public key and returns the corresponding account (KeyPair). |
@@ -11,8 +11,2 @@ import { ConstantKeyPair } from './key_pair.js'; | ||
} | ||
/** | ||
* Adds an account to the key store from the provided private key. | ||
* @param curve - The curve to use for generating the public key. | ||
* @param privKey - The private key of the account. | ||
* @returns - The account's public key. | ||
*/ | ||
addAccount(privKey) { | ||
@@ -28,8 +22,2 @@ const keyPair = ConstantKeyPair.fromPrivateKey(this.curve, privKey); | ||
} | ||
/** | ||
* Adds a new account to the TestKeyStore with a randomly generated ConstantKeyPair. | ||
* The account will have its own private and public key pair, which can be used for signing transactions. | ||
* @param curve - The curve to use for generating the public key. | ||
* @returns A promise that resolves to the newly created account's AztecAddress. | ||
*/ | ||
createAccount() { | ||
@@ -40,20 +28,5 @@ const keyPair = ConstantKeyPair.random(this.curve); | ||
} | ||
/** | ||
* Retrieves the public addresses of all accounts stored in the TestKeyStore. | ||
* The returned addresses are instances of `AztecAddress` and can be used for subsequent operations | ||
* such as signing transactions or fetching public/private keys. | ||
* | ||
* @returns A Promise that resolves to an array of AztecAddress instances. | ||
*/ | ||
getAccounts() { | ||
return Promise.resolve(this.accounts.map(a => a.getPublicKey())); | ||
} | ||
/** | ||
* Retrieves the private key of the account associated with the specified AztecAddress. | ||
* Throws an error if the provided address is not found in the list of registered accounts. | ||
* | ||
* @param pubKey - The AztecAddress instance representing the account for which the private key is requested. | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
* @deprecated We should not require a keystore to expose private keys in plain. | ||
*/ | ||
getAccountPrivateKey(pubKey) { | ||
@@ -79,2 +52,2 @@ const account = this.getAccount(pubKey); | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF9rZXlfc3RvcmUuanMiLCJzb3VyY2V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BQ2hCLE9BQU8sT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQyxZQUFZLEVBQUUsQ0FBQyxDQUFDLENBQUM7SUFDbkUsQ0FBQztJQUVNLG9CQUFvQixDQUFDLE1BQWlCO1FBQzNDLE1BQU0sT0FBTyxHQUFHLElBQUksQ0FBQyxVQUFVLENBQUMsTUFBTSxDQUFDLENBQUM7UUFDeEMsT0FBTyxPQUFPLENBQUMsYUFBYSxFQUFFLENBQUM7SUFDakMsQ0FBQztJQUVEOzs7Ozs7O09BT0c7SUFDSyxVQUFVLENBQUMsTUFBaUI7UUFDbEMsTUFBTSxPQUFPLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsWUFBWSxFQUFFLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDekUsSUFBSSxDQUFDLE9BQU8sRUFBRTtZQUNaLE1BQU0sSUFBSSxLQUFLLENBQUMsa0JBQWtCLENBQUMsQ0FBQztTQUNyQztRQUNELE9BQU8sT0FBTyxDQUFDO0lBQ2pCLENBQUM7Q0FDRiJ9 |
{ | ||
"name": "@aztec/key-store", | ||
"version": "0.1.0-alpha23", | ||
"version": "0.1.0-alpha40", | ||
"exports": "./dest/index.js", | ||
"type": "module", | ||
"dependencies": { | ||
"@aztec/circuits.js": "0.1.0-alpha23", | ||
"@aztec/foundation": "0.1.0-alpha23", | ||
"@aztec/types": "0.1.0-alpha23", | ||
"@aztec/circuits.js": "0.1.0-alpha40", | ||
"@aztec/foundation": "0.1.0-alpha40", | ||
"@aztec/types": "0.1.0-alpha40", | ||
"tslib": "^2.4.0" | ||
} | ||
} |
@@ -1,5 +0,4 @@ | ||
import { Curve } from '@aztec/circuits.js/barretenberg'; | ||
import { randomBytes } from '@aztec/foundation/crypto'; | ||
import { Point } from '@aztec/foundation/fields'; | ||
import { KeyPair } from '@aztec/types'; | ||
import { PrivateKey } from '@aztec/circuits.js'; | ||
import { Grumpkin } from '@aztec/circuits.js/barretenberg'; | ||
import { KeyPair, PublicKey } from '@aztec/types'; | ||
@@ -19,5 +18,5 @@ /** | ||
*/ | ||
public static random(curve: Curve) { | ||
const privateKey = randomBytes(32); | ||
const publicKey = Point.fromBuffer(curve.mul(curve.generator(), privateKey)); | ||
public static random(curve: Grumpkin) { | ||
const privateKey = PrivateKey.random(); | ||
const publicKey = curve.mul(curve.generator(), privateKey); | ||
return new ConstantKeyPair(publicKey, privateKey); | ||
@@ -33,25 +32,13 @@ } | ||
*/ | ||
public static fromPrivateKey(curve: Curve, privateKey: Buffer) { | ||
const publicKey = Point.fromBuffer(curve.mul(curve.generator(), privateKey)); | ||
public static fromPrivateKey(curve: Grumpkin, privateKey: PrivateKey) { | ||
const publicKey = curve.mul(curve.generator(), privateKey); | ||
return new ConstantKeyPair(publicKey, privateKey); | ||
} | ||
constructor(private publicKey: Point, private privateKey: Buffer) {} | ||
constructor(private publicKey: PublicKey, private privateKey: PrivateKey) {} | ||
/** | ||
* Retrieve the public key from the KeyPair instance. | ||
* The returned public key is a Point object which represents a point on the elliptic curve secp256k1. | ||
* | ||
* @returns The public key as an elliptic curve point. | ||
*/ | ||
public getPublicKey() { | ||
public getPublicKey(): PublicKey { | ||
return this.publicKey; | ||
} | ||
/** | ||
* Retrieves the private key of the KeyPair instance. | ||
* The function returns a Promise that resolves to a Buffer containing the private key. | ||
* | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
*/ | ||
public getPrivateKey() { | ||
@@ -58,0 +45,0 @@ return Promise.resolve(this.privateKey); |
@@ -1,6 +0,7 @@ | ||
import { Curve } from '@aztec/circuits.js/barretenberg'; | ||
import { ConstantKeyPair } from './key_pair.js'; | ||
import { Point } from '@aztec/circuits.js'; | ||
import { PrivateKey } from '@aztec/circuits.js'; | ||
import { Grumpkin } from '@aztec/circuits.js/barretenberg'; | ||
import { KeyPair, KeyStore, PublicKey } from '@aztec/types'; | ||
import { ConstantKeyPair } from './key_pair.js'; | ||
/** | ||
@@ -12,11 +13,5 @@ * TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment. | ||
private accounts: KeyPair[] = []; | ||
constructor(private curve: Curve) {} | ||
constructor(private curve: Grumpkin) {} | ||
/** | ||
* Adds an account to the key store from the provided private key. | ||
* @param curve - The curve to use for generating the public key. | ||
* @param privKey - The private key of the account. | ||
* @returns - The account's public key. | ||
*/ | ||
public addAccount(privKey: Buffer): PublicKey { | ||
public addAccount(privKey: PrivateKey): PublicKey { | ||
const keyPair = ConstantKeyPair.fromPrivateKey(this.curve, privKey); | ||
@@ -34,9 +29,3 @@ | ||
/** | ||
* Adds a new account to the TestKeyStore with a randomly generated ConstantKeyPair. | ||
* The account will have its own private and public key pair, which can be used for signing transactions. | ||
* @param curve - The curve to use for generating the public key. | ||
* @returns A promise that resolves to the newly created account's AztecAddress. | ||
*/ | ||
public createAccount(): Promise<Point> { | ||
public createAccount(): Promise<PublicKey> { | ||
const keyPair = ConstantKeyPair.random(this.curve); | ||
@@ -47,22 +36,7 @@ this.accounts.push(keyPair); | ||
/** | ||
* Retrieves the public addresses of all accounts stored in the TestKeyStore. | ||
* The returned addresses are instances of `AztecAddress` and can be used for subsequent operations | ||
* such as signing transactions or fetching public/private keys. | ||
* | ||
* @returns A Promise that resolves to an array of AztecAddress instances. | ||
*/ | ||
public getAccounts() { | ||
public getAccounts(): Promise<PublicKey[]> { | ||
return Promise.resolve(this.accounts.map(a => a.getPublicKey())); | ||
} | ||
/** | ||
* Retrieves the private key of the account associated with the specified AztecAddress. | ||
* Throws an error if the provided address is not found in the list of registered accounts. | ||
* | ||
* @param pubKey - The AztecAddress instance representing the account for which the private key is requested. | ||
* @returns A Promise that resolves to a Buffer containing the private key. | ||
* @deprecated We should not require a keystore to expose private keys in plain. | ||
*/ | ||
public getAccountPrivateKey(pubKey: PublicKey): Promise<Buffer> { | ||
public getAccountPrivateKey(pubKey: PublicKey): Promise<PrivateKey> { | ||
const account = this.getAccount(pubKey); | ||
@@ -69,0 +43,0 @@ return account.getPrivateKey(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92329
264
+ Added@aztec/circuits.js@0.1.0-alpha40(transitive)
+ Added@aztec/foundation@0.1.0-alpha40(transitive)
+ Added@aztec/types@0.1.0-alpha40(transitive)
- Removed@aztec/circuits.js@0.1.0-alpha23(transitive)
- Removed@aztec/foundation@0.1.0-alpha23(transitive)
- Removed@aztec/types@0.1.0-alpha23(transitive)
Updated@aztec/types@0.1.0-alpha40