Skip to content

Commit 4c266e1

Browse files
committed
Changing fetchRemoteKeys and fetchProvingKey to use object params
1 parent a870300 commit 4c266e1

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

sdk/src/function-key-provider.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class AleoKeyProvider implements FunctionKeyProvider {
353353
}
354354

355355
if (proverUrl && verifierUrl) {
356-
return await this.fetchRemoteKeys(proverUrl, verifierUrl, cacheKey);
356+
return await this.fetchRemoteKeys({ proverUrl, verifierUrl, cacheKey });
357357
}
358358

359359
if (cacheKey) {
@@ -366,9 +366,10 @@ class AleoKeyProvider implements FunctionKeyProvider {
366366
/**
367367
* Returns the proving and verifying keys for a specified program from a specified url.
368368
*
369-
* @param {string} verifierUrl Url of the proving key
370-
* @param {string} proverUrl Url the verifying key
371-
* @param {string} cacheKey Key to store the keys in the cache
369+
* @param {Object} params
370+
* @param {string} params.verifierUrl Url of the proving key
371+
* @param {string} params.proverUrl Url the verifying key
372+
* @param {string} [params.cacheKey] Key to store the keys in the cache
372373
*
373374
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
374375
*
@@ -383,12 +384,18 @@ class AleoKeyProvider implements FunctionKeyProvider {
383384
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
384385
*
385386
* // Keys can also be fetched manually
386-
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys(
387-
* CREDITS_PROGRAM_KEYS.transfer_private.prover,
388-
* CREDITS_PROGRAM_KEYS.transfer_private.verifier,
389-
* );
387+
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchRemoteKeys({
388+
* proverUrl: CREDITS_PROGRAM_KEYS.transfer_private.prover,
389+
* verifierUrl: CREDITS_PROGRAM_KEYS.transfer_private.verifier,
390+
* });
390391
*/
391-
async fetchRemoteKeys(proverUrl: string, verifierUrl: string, cacheKey?: string): Promise<FunctionKeyPair> {
392+
async fetchRemoteKeys(params: {
393+
proverUrl: string,
394+
verifierUrl: string,
395+
cacheKey?: string,
396+
}): Promise<FunctionKeyPair> {
397+
let { proverUrl, verifierUrl, cacheKey } = params;
398+
392399
try {
393400
// If cache is enabled, check if the keys have already been fetched and return them if they have
394401
if (this.cacheOption) {
@@ -421,12 +428,18 @@ class AleoKeyProvider implements FunctionKeyProvider {
421428
/***
422429
* Fetches the proving key from a remote source.
423430
*
424-
* @param proverUrl
425-
* @param cacheKey
431+
* @param {Object} params
432+
* @param {string} params.proverUrl
433+
* @param {string} [params.cacheKey]
426434
*
427435
* @returns {Promise<ProvingKey>} Proving key for the specified program
428436
*/
429-
async fetchProvingKey(proverUrl: string, cacheKey?: string): Promise<ProvingKey> {
437+
async fetchProvingKey(params: {
438+
proverUrl: string,
439+
cacheKey?: string,
440+
}): Promise<ProvingKey> {
441+
let { proverUrl, cacheKey } = params;
442+
430443
try {
431444
// If cache is enabled, check if the keys have already been fetched and return them if they have
432445
if (this.cacheOption) {
@@ -455,7 +468,7 @@ class AleoKeyProvider implements FunctionKeyProvider {
455468
try {
456469
if (!this.cache.has(key.locator) || !this.cacheOption) {
457470
const verifying_key = key.verifyingKey()
458-
const proving_key = <ProvingKey>await this.fetchProvingKey(key.prover, key.locator);
471+
const proving_key = <ProvingKey>await this.fetchProvingKey({ proverUrl: key.prover, cacheKey: key.locator });
459472
if (this.cacheOption) {
460473
this.cache.set(CREDITS_PROGRAM_KEYS.bond_public.locator, [proving_key.toBytes(), verifying_key.toBytes()]);
461474
}

0 commit comments

Comments
 (0)