Skip to main content

Function Key Provider

Overview

This module provides classes and interfaces for managing Aleo program proving and verifying keys.

Kind: global module


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)
ParamTypeDescription
paramsAleoKeyProviderInitParamsOptional search parameters

Interface

interface AleoKeyProviderInitParams {
proverUri?: string;
verifierUri?: string;
cacheKey?: string;
}
PropertyTypeDescription
proverUristringOptional URL to fetch the proving key
verifierUristringOptional URL to fetch the verifying key
cacheKeystringOptional 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)
ParametersTypeDescription
useCachebooleanwhether 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)
ParametersTypeDescription
keyIdstringaccess key for the cache
keysFunctionKeyPairkeys to cache

containsKeys

Determine if a keyId exists in the cache

containsKeys(keyId)
ParametersTypeDescription
keyIdstringkeyId of a proving and verifying key pair
returnbooleantrue if the keyId exists in the cache, false otherwise

deleteKeys

Delete a set of keys from the cache

deleteKeys(keyId)
ParametersTypeDescription
keyIdstringkeyId of a proving and verifying key pair to delete from memory
returnbooleantrue 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)
ParametersTypeDescription
keyIdstringkeyId of a proving and verifying key pair
returnFunctionKeyPairProving and verifying keys for the specified program

functionKeys

Get arbitrary function keys from a provider

functionKeys(params)
ParametersTypeDescription
paramsKeySearchParamsparameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string}
returnPromise.<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)
ParametersTypeDescription
proverUrlstringUrl of the proving key
verifierUrlstringUrl of the verifying key
cacheKeystringKey to store the keys in the cache
returnPromise.<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)
ParametersTypeDescription
proverUrlstringUrl of the proving key
cacheKeystringOptional key to store the key in the cache
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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)
ParametersTypeDescription
visibilitystringVisibility of the transfer function
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<FunctionKeyPair>Proving and verifying keys for the transfer_public function

inclusionKeys

Returns the proving and verifying keys for the inclusion proof.

inclusionKeys()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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()
ParametersTypeDescription
returnPromise.<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)
ParametersTypeDescription
verifierUristringThe URI of the verifying key to fetch
returnPromise.<VerifyingKey>Verifying key for the function

unBondPublicKeys

Returns the proving and verifying keys for the unbond_public function in the credits.aleo program

unBondPublicKeys()
ParametersTypeDescription
returnPromise.<FunctionKeyPair>Proving and verifying keys for the unbond_public function