Function Key Provider
Class AleoKeyProviderParams
AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
Constructor
AleoKeyProviderParams(params)
Create a new AleoKeyProviderParams object which implements the KeySearchParams interface. Users can optionally specify a url for the proverUri & verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory for future use. If no proverUri or verifierUri is specified, a cachekey must be provided.
| Parameters | Type | Description |
|---|---|---|
| params | AleoKeyProviderInitParams | Optional search parameters |
Class AleoKeyProvider
AleoKeyProvider class. Implements the KeyProvider interface. Enables the retrieval of Aleo program proving and verifying keys for the credits.aleo program over http from official Aleo sources and storing and retrieving function keys from a local memory cache.
Kind: global class
- AleoKeyProvider
- instance
- .useCache(useCache)
- .clearCache()
- .cacheKeys(keyId, keys)
- .containsKeys(keyId) ⇒
boolean - .deleteKeys(keyId) ⇒
boolean - .getKeys(keyId) ⇒
FunctionKeyPair - .functionKeys(params) ⇒
Promise.<FunctionKeyPair> - .fetchRemoteKeys(verifierUrl, proverUrl, cacheKey) ⇒
Promise.<FunctionKeyPair> - .transferKeys(visibility) ⇒
Promise.<FunctionKeyPair> - .joinKeys() ⇒
Promise.<FunctionKeyPair> - .splitKeys() ⇒
Promise.<FunctionKeyPair> - .feePrivateKeys() ⇒
Promise.<FunctionKeyPair> - .feePublicKeys() ⇒
Promise.<FunctionKeyPair> - .getVerifyingKey() ⇒
Promise.<VerifyingKey>
- instance
Methods
useCache
Use local memory to store keys
useCache(useCache)
| Parameters | Type | Description |
|---|---|---|
| useCache | boolean | whether to store keys in local memory |
clearCache
Clear the key cache
clearCache()
cacheKeys
Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
cacheKeys(keyId, keys)
| Parameters | Type | Description |
|---|---|---|
| keyId | string | access key for the cache |
| keys | FunctionKeyPair | keys to cache |
containsKeys
Determine if a keyId exists in the cache
containsKeys(keyId)
| Parameters | Type | Description |
|---|---|---|
| keyId | string | keyId of a proving and verifying key pair |
| return | boolean | true if the keyId exists in the cache, false otherwise |
deleteKeys
Delete a set of keys from the cache
deleteKeys(keyId)
| Parameters | Type | Description |
|---|---|---|
| keyId | string | keyId of a proving and verifying key pair to delete from memory |
| return | boolean | true if the keyId exists in the cache and was deleted, false if the key did not exist |
getKeys
Get a set of keys from the cache
getKeys(keyId)
| Parameters | Type | Description |
|---|---|---|
| keyId | undefined | keyId of a proving and verifying key pair |
| return | FunctionKeyPair | Proving and verifying keys for the specified program |
functionKeys
Get arbitrary function keys from a provider
functionKeys(params)
| Parameters | Type | Description |
|---|---|---|
| params | KeySearchParams | parameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string} |
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the specified program |
Examples
// Create a new object which implements the KeyProvider interface
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);
// Initialize a program manager with the key provider to automatically fetch keys for value transfers
const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
// Keys can also be fetched manually using the key provider
const keySearchParams = { "cacheKey": "myProgram:myFunction" };
const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(keySearchParams);
fetchRemoteKeys
Returns the proving and verifying keys for a specified program from a specified url.
fetchRemoteKeys(verifierUrl, proverUrl, cacheKey)
| Parameters | Type | Description |
|---|---|---|
| verifierUrl | string | Url of the proving key |
| proverUrl | string | Url the verifying key |
| cacheKey | string | Key to store the keys in the cache |
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the specified program |
Examples
// Create a new AleoKeyProvider object
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);
// Initialize a program manager with the key provider to automatically fetch keys for value transfers
const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
// Keys can also be fetched manually
const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys(
CREDITS_PROGRAM_KEYS.transfer_private.prover,
CREDITS_PROGRAM_KEYS.transfer_private.verifier,
);
transferKeys
Returns the proving and verifying keys for the transfer functions in the credits.aleo program
transferKeys(visibility)
| Parameters | Type | Description |
|---|---|---|
| visibility | string | Visibility of the transfer function |
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the transfer functions |
Examples
// Create a new AleoKeyProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);
// Initialize a program manager with the key provider to automatically fetch keys for value transfers
const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
// Keys can also be fetched manually
const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
joinKeys
Returns the proving and verifying keys for the join function in the credits.aleo program
joinKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the join function |
splitKeys
Returns the proving and verifying keys for the split function in the credits.aleo program
splitKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the split function |
feePrivateKeys
Returns the proving and verifying keys for the fee_private function in the credits.aleo program
feePrivateKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the fee function |
feePublicKeys
Returns the proving and verifying keys for the fee_public function in the credits.aleo program
feePublicKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the fee function |
getVerifyingKey
Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise
getVerifyingKey()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<VerifyingKey> | Verifying key for the function |