Skip to main content

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.

ParametersTypeDescription
paramsAleoKeyProviderInitParamsOptional 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

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
keyIdundefinedkeyId 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(verifierUrl, proverUrl, cacheKey)
ParametersTypeDescription
verifierUrlstringUrl of the proving key
proverUrlstringUrl 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.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)
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

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

getVerifyingKey()
ParametersTypeDescription
returnPromise.<VerifyingKey>Verifying key for the function