Function Key Provider
Overview
This module provides classes and interfaces for managing Aleo program proving and verifying keys.
Kind: global module
-
AleoKeyProviderParams
- constructor
-
FunctionKeyProvider (Interface)
- interface methods
- .bondPublicKeys() ⇒
Promise.<FunctionKeyPair> - .bondValidatorKeys() ⇒
Promise.<FunctionKeyPair> - .cacheKeys(keyId, keys)
- .claimUnbondPublicKeys() ⇒
Promise.<FunctionKeyPair> - .functionKeys(params) ⇒
Promise.<FunctionKeyPair> - .feePrivateKeys() ⇒
Promise.<FunctionKeyPair> - .feePublicKeys() ⇒
Promise.<FunctionKeyPair> - .inclusionKeys() ⇒
Promise.<FunctionKeyPair> - .joinKeys() ⇒
Promise.<FunctionKeyPair> - .splitKeys() ⇒
Promise.<FunctionKeyPair> - .transferKeys(visibility) ⇒
Promise.<FunctionKeyPair> - .unBondPublicKeys() ⇒
Promise.<FunctionKeyPair>
- .bondPublicKeys() ⇒
- interface methods
-
AleoKeyProvider
- constructor
- instance
- .useCache(useCache)
- .clearCache()
- .cacheKeys(keyId, keys)
- .containsKeys(keyId) ⇒
boolean - .deleteKeys(keyId) ⇒
boolean - .getKeys(keyId) ⇒
FunctionKeyPair - .functionKeys(params) ⇒
Promise.<FunctionKeyPair> - .fetchRemoteKeys(proverUrl, verifierUrl, cacheKey) ⇒
Promise.<FunctionKeyPair> - .fetchProvingKey(proverUrl, cacheKey) ⇒
Promise.<ProvingKey> - .bondPublicKeys() ⇒
Promise.<FunctionKeyPair> - .bondValidatorKeys() ⇒
Promise.<FunctionKeyPair> - .claimUnbondPublicKeys() ⇒
Promise.<FunctionKeyPair> - .transferKeys(visibility) ⇒
Promise.<FunctionKeyPair> - .transferPublicKeys() ⇒
Promise.<FunctionKeyPair> - .inclusionKeys() ⇒
Promise.<FunctionKeyPair> - .joinKeys() ⇒
Promise.<FunctionKeyPair> - .splitKeys() ⇒
Promise.<FunctionKeyPair> - .feePrivateKeys() ⇒
Promise.<FunctionKeyPair> - .feePublicKeys() ⇒
Promise.<FunctionKeyPair> - .getVerifyingKey(verifierUri) ⇒
Promise.<VerifyingKey> - .unBondPublicKeys() ⇒
Promise.<FunctionKeyPair>
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
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.
new AleoKeyProviderParams(params)
| Param | Type | Description |
|---|---|---|
| params | AleoKeyProviderInitParams | Optional search parameters |
Interface
interface AleoKeyProviderInitParams {
proverUri?: string;
verifierUri?: string;
cacheKey?: string;
}
| Property | Type | Description |
|---|---|---|
| proverUri | string | Optional URL to fetch the proving key |
| verifierUri | string | Optional URL to fetch the verifying key |
| cacheKey | string | Optional key to store the keys in the cache |
Example
import { AleoKeyProviderParams } from "@provablehq/sdk/mainnet.js";
// Create search params with remote URLs
const remoteParams = new AleoKeyProviderParams({
proverUri: "https://example.com/myprogram.prover",
verifierUri: "https://example.com/myprogram.verifier",
cacheKey: "myprogram.aleo/myfunction"
});
// Create search params with only a cache key
const cacheParams = new AleoKeyProviderParams({
cacheKey: "myprogram.aleo/myfunction"
});
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.
Constructor
Create a new AleoKeyProvider instance for managing proving and verifying keys.
new AleoKeyProvider()
Example
import { AleoKeyProvider } from "@provablehq/sdk/mainnet.js";
// Create a new AleoKeyProvider
const keyProvider = new AleoKeyProvider();
// Enable caching for better performance
keyProvider.useCache(true);
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 | string | 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(proverUrl, verifierUrl, cacheKey)
| Parameters | Type | Description |
|---|---|---|
| proverUrl | string | Url of the proving key |
| verifierUrl | string | Url of 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.fetchRemoteKeys(
CREDITS_PROGRAM_KEYS.transfer_private.prover,
CREDITS_PROGRAM_KEYS.transfer_private.verifier,
);
fetchProvingKey
Fetches the proving key from a remote source.
fetchProvingKey(proverUrl, cacheKey)
| Parameters | Type | Description |
|---|---|---|
| proverUrl | string | Url of the proving key |
| cacheKey | string | Optional key to store the key in the cache |
| return | Promise.<ProvingKey> | Proving key for the specified program |
bondPublicKeys
Returns the proving and verifying keys for the bond_public function in the credits.aleo program
bondPublicKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the bond_public function |
bondValidatorKeys
Returns the proving and verifying keys for the bond_validator function in the credits.aleo program
bondValidatorKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the bond_validator function |
claimUnbondPublicKeys
Returns the proving and verifying keys for the claim_unbond_public function in the credits.aleo program
claimUnbondPublicKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the claim_unbond_public function |
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 |
transferPublicKeys
Returns the proving and verifying keys for the transfer_public function in the credits.aleo program
transferPublicKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the transfer_public function |
inclusionKeys
Returns the proving and verifying keys for the inclusion proof.
inclusionKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the inclusion proof |
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 attempt to fetch it from the network.
getVerifyingKey(verifierUri)
| Parameters | Type | Description |
|---|---|---|
| verifierUri | string | The URI of the verifying key to fetch |
| return | Promise.<VerifyingKey> | Verifying key for the function |
unBondPublicKeys
Returns the proving and verifying keys for the unbond_public function in the credits.aleo program
unBondPublicKeys()
| Parameters | Type | Description |
|---|---|---|
| return | Promise.<FunctionKeyPair> | Proving and verifying keys for the unbond_public function |