From b95e2050198c04c728846bd32472b0cffa960145 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Thu, 7 Aug 2025 21:56:29 -0700 Subject: [PATCH 1/9] added local key saving and loading to expedite transfer execution --- docs/examples/01_transfer_public.md | 42 ++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/examples/01_transfer_public.md b/docs/examples/01_transfer_public.md index c74df0c4c..4aed1b930 100644 --- a/docs/examples/01_transfer_public.md +++ b/docs/examples/01_transfer_public.md @@ -1,5 +1,5 @@ ```typescript -import { Account, ProgramManager, initThreadPool } from '@provable.sdk'; +import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; // Initialize multi-threading to allow WASM execution. await initThreadPoool(); @@ -13,8 +13,44 @@ const keyProvider = new AleoKeyProvider(); keyProvider.useCache = true; const recordProvider = new NetworkRecordProvider(account, networkClient); -// Create program manager using the KeyProvider and NetworkProvider. -const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); +// Fetch the proving and verifying keys for the transfer_public and fee_public methods. +const [feePk, feeVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public); +const [txPk, txVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public); + +// Optionally save the keys to a local directory for future use +async function writeKeyToFile(key, filePath) { + // Serialize the key into a Uint8Array + const raw = key.toBytes(); // or key.to_bytes() depending on your SDK version + // Then write it as binary + await fs.writeFile(filePath, Buffer.from(raw)); + console.log(`Wrote ${filePath}`); +} + +const keyDir = "./keys"; +await fs.mkdir(keyDir, { recursive: true }); + +await writeKeyToFile(feePk, path.join(keyDir, "fee_public.prover")); +await writeKeyToFile(feeVk, path.join(keyDir, "fee_public.verifier")); +await writeKeyToFile(txPk, path.join(keyDir, "transfer_public.prover")); +await writeKeyToFile(txVk, path.join(keyDir, "transfer_public.verifier")); + + + +// Create an offline key provider. +const offlineKeyProvider = new OfflineKeyProvider(); + +// Load the stored keys into a cache them into an OfflineKeyProvider +const transferPublicProvingKey = await getLocalKey("./keys/transfer_public.prover"); +const transferPublicVerifyingKey = await getLocalKey("./keys/transfer_public.verifier"); + +const feeProvingKey = await getLocalKey("./keys/fee_public.prover"); +const feeVerifyingKey = await getLocalKey("./keys/fee_public.verifier"); + +offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); +offlineKeyProvider.insertFeePublicKeys(feeProvingKey); + +// Create program manager using the OfflineKeyProvider and NetworkProvider. +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); // Set the account as the program caller. programManager.setAccount(account); From 32508c1682ab8931f010bb8cc225e3f3c3bbbd32 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Tue, 12 Aug 2025 16:41:03 -0700 Subject: [PATCH 2/9] added example for saving keys locally --- .../05_download_and_save_keys_to_disc.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs/examples/05_download_and_save_keys_to_disc.md diff --git a/docs/examples/05_download_and_save_keys_to_disc.md b/docs/examples/05_download_and_save_keys_to_disc.md new file mode 100644 index 000000000..551851d22 --- /dev/null +++ b/docs/examples/05_download_and_save_keys_to_disc.md @@ -0,0 +1,46 @@ +This example will demonstrate how to save proving and verifying keys locally for the "transfer_public" in credits.aleo and for any arbitrary Aleo program. + +```typescript +import { + AleoKeyProvider, + CREDITS_PROGRAM_KEYS, + ProvingKey, // these are WASM-backed types + VerifyingKey, +} from "@provablehq/sdk + +const keyProvider = new AleoKeyProvider(); + +// Fetch the on-chain "fee" and "transfer_public" proving and verifying keys +const [feePk, feeVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public); +const [txPk, txVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public); + +// For methods that consume or mint a record, the inclusion circuit will be required. +const [incPk, incVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.inclusion); + +// For a transition method in any deployed Aleo program, use the following pattern to fetch the proving and verifying +// keys associated with that transition. +const keySearchParams = { "cacheKey": "myProgram:myFunction" }; +const [transition_Pk, transition_vK] = await keyProvider.functionKeys(searchParams); + +// You can use this method for saving the keys to disc. +async function writeKeyToFile(key, filePath) { + // Serialize the key into a Uint8Array + const raw = key.toBytes(); // or key.to_bytes() depending on your SDK version + // Then write it as binary + await fs.writeFile(filePath, Buffer.from(raw)); + console.log(`Wrote ${filePath}`); +} + +const keyDir = "./keys"; +await fs.mkdir(keyDir, { recursive: true }); + +await writeKeyToFile(feePk, path.join(keyDir, "fee_public.prover")); +await writeKeyToFile(feeVk, path.join(keyDir, "fee_public.verifier")); +await writeKeyToFile(txPk, path.join(keyDir, "transfer_public.prover")); +await writeKeyToFile(txVk, path.join(keyDir, "transfer_public.verifier")); +await writeKeyToFile(incPk, path.join(keyDir, "inclusion.prover")); +await writeKeyToFile(incVk, path.join(keyDir, "inclusion.verifier")); + +await writeKeyToFile(transition_Pk, path.join(keyDir, "transition.prover")); +await writeKeyToFile(transition_Vk, path.join(keyDir, "transition.verifier")); + From c207c8c3e08a8cb0b3f980ab6640060cfe414a26 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Tue, 12 Aug 2025 16:53:03 -0700 Subject: [PATCH 3/9] added transfer_public using stored keys --- .../06_transfer_public_using_stored_keys.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/examples/06_transfer_public_using_stored_keys.md diff --git a/docs/examples/06_transfer_public_using_stored_keys.md b/docs/examples/06_transfer_public_using_stored_keys.md new file mode 100644 index 000000000..fb505e9b3 --- /dev/null +++ b/docs/examples/06_transfer_public_using_stored_keys.md @@ -0,0 +1,61 @@ +This example demonstrates how to execute public_transfer using locally saved proving and verifying keys. +```typescript +import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; + +// Initialize multi-threading to allow WASM execution. +await initThreadPoool(); + +// Helper method to load the keys from storage. +async function loadFunctionKeyPair(proverPath, verifierPath) { + const proverBytes = await fs.readFile(proverPath); + const verifierBytes = await fs.readFile(verifierPath); + + const provingKey = ProvingKey.fromBytes(new Uint8Array(proverBytes)); + const verifyingKey = VerifyingKey.fromBytes(new Uint8Array(verifierBytes)); + + return [provingKey, verifyingKey]; +} + +// Load the proving and verifying keys for public_transfer and fee_public from local storage. +const [feeProvingKey, feeVerifyingKey] = await loadFunctionKeyPair( + "./keys/fee_public.prover", + "./keys/fee_public.verifier" +); + +const [transferPublicProvingKey, transferPublicVerifyingKey] = await loadFunctionKeyPair( + "./keys/transfer_public.prover", + "./keys/transfer_public.verifier" +); + +// Create an offline Key provider +const keyProvider = new OfflineKeyProvider(); + +// Store it in the cache under a key name of your choice +keyProvider.insertTransferPublicKeys(transferPublicProvingKey); +keyProvider.insertFeePublicKeys(feeProvingKey); + +// Create an execution transaction +offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); +offlineKeyProvider.insertFeePublicKeys(feeProvingKey); + +// Create program manager using the OfflineKeyProvider and NetworkProvider. +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); +// Set the account as the program caller. +programManager.setAccount(account); + +// Create recipient account. +const recipient = new Account(); + +// Build a transfer_public transaction. +// Publicly send 5 microcredits to the recipient +const transaction = await programManager + .buildTransferPublicTransaction( + 5, // The amount to be transferred in credits (not microcredits) + recipient // The address of the recipient. + .address() + .to_string(), + 0.0 // The optional priority fee amount. + ); + +// Broadcast the transaction to the Aleo network. +const result = await programManager.networkClient.submitTransaction(transaction); \ No newline at end of file From afed2f16e1a55cf7cc5661e94be93030c6ea36b5 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Tue, 12 Aug 2025 16:54:05 -0700 Subject: [PATCH 4/9] reverted transfer_public without local key storage --- docs/examples/01_transfer_public.md | 42 +++-------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/docs/examples/01_transfer_public.md b/docs/examples/01_transfer_public.md index 4aed1b930..c74df0c4c 100644 --- a/docs/examples/01_transfer_public.md +++ b/docs/examples/01_transfer_public.md @@ -1,5 +1,5 @@ ```typescript -import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; +import { Account, ProgramManager, initThreadPool } from '@provable.sdk'; // Initialize multi-threading to allow WASM execution. await initThreadPoool(); @@ -13,44 +13,8 @@ const keyProvider = new AleoKeyProvider(); keyProvider.useCache = true; const recordProvider = new NetworkRecordProvider(account, networkClient); -// Fetch the proving and verifying keys for the transfer_public and fee_public methods. -const [feePk, feeVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public); -const [txPk, txVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public); - -// Optionally save the keys to a local directory for future use -async function writeKeyToFile(key, filePath) { - // Serialize the key into a Uint8Array - const raw = key.toBytes(); // or key.to_bytes() depending on your SDK version - // Then write it as binary - await fs.writeFile(filePath, Buffer.from(raw)); - console.log(`Wrote ${filePath}`); -} - -const keyDir = "./keys"; -await fs.mkdir(keyDir, { recursive: true }); - -await writeKeyToFile(feePk, path.join(keyDir, "fee_public.prover")); -await writeKeyToFile(feeVk, path.join(keyDir, "fee_public.verifier")); -await writeKeyToFile(txPk, path.join(keyDir, "transfer_public.prover")); -await writeKeyToFile(txVk, path.join(keyDir, "transfer_public.verifier")); - - - -// Create an offline key provider. -const offlineKeyProvider = new OfflineKeyProvider(); - -// Load the stored keys into a cache them into an OfflineKeyProvider -const transferPublicProvingKey = await getLocalKey("./keys/transfer_public.prover"); -const transferPublicVerifyingKey = await getLocalKey("./keys/transfer_public.verifier"); - -const feeProvingKey = await getLocalKey("./keys/fee_public.prover"); -const feeVerifyingKey = await getLocalKey("./keys/fee_public.verifier"); - -offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); -offlineKeyProvider.insertFeePublicKeys(feeProvingKey); - -// Create program manager using the OfflineKeyProvider and NetworkProvider. -const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); +// Create program manager using the KeyProvider and NetworkProvider. +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); // Set the account as the program caller. programManager.setAccount(account); From f37cfcab5ac3b41b9b5a64661149ca19de68df59 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Wed, 13 Aug 2025 09:06:21 -0700 Subject: [PATCH 5/9] added transfer_private example with proving keys loaded --- .../06_transfer_public_using_stored_keys.md | 5 +- .../07_transfer_private_using_stored_keys.md | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 docs/examples/07_transfer_private_using_stored_keys.md diff --git a/docs/examples/06_transfer_public_using_stored_keys.md b/docs/examples/06_transfer_public_using_stored_keys.md index fb505e9b3..e3c15cf96 100644 --- a/docs/examples/06_transfer_public_using_stored_keys.md +++ b/docs/examples/06_transfer_public_using_stored_keys.md @@ -30,11 +30,8 @@ const [transferPublicProvingKey, transferPublicVerifyingKey] = await loadFunctio // Create an offline Key provider const keyProvider = new OfflineKeyProvider(); -// Store it in the cache under a key name of your choice -keyProvider.insertTransferPublicKeys(transferPublicProvingKey); -keyProvider.insertFeePublicKeys(feeProvingKey); -// Create an execution transaction +// Store the proving keys in the offline key provider. offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); offlineKeyProvider.insertFeePublicKeys(feeProvingKey); diff --git a/docs/examples/07_transfer_private_using_stored_keys.md b/docs/examples/07_transfer_private_using_stored_keys.md new file mode 100644 index 000000000..3805c9a58 --- /dev/null +++ b/docs/examples/07_transfer_private_using_stored_keys.md @@ -0,0 +1,70 @@ +This example demonstrates how to execute transfer_private using locally saved proving and verifying keys. +```typescript +import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; + +// Helper method to load the keys from storage. +async function loadFunctionKeyPair(proverPath, verifierPath) { + const proverBytes = await fs.readFile(proverPath); + const verifierBytes = await fs.readFile(verifierPath); + + const provingKey = ProvingKey.fromBytes(new Uint8Array(proverBytes)); + const verifyingKey = VerifyingKey.fromBytes(new Uint8Array(verifierBytes)); + + return [provingKey, verifyingKey]; +} + +// Download the inclusion proving and verifying keys. +const [inclusionProver, inclusionVerifier] = await loadFunctionKeyPair( + "./keys/inclusion.prover", + "./keys/inclusion.verifier" +); + +// Download the transfer_private proving and verifying keys. +const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await loadFunctionKeyPair( + "./keys/transfer_private.prover", + "./keys/transfer_private.verifier" +); + +// Download the fee_private proving and verifying keys. +const [feeProvingKey, feeVerifyingKey] = await loadFunctionKeyPair( + "./keys/fee_private.prover", + "./keys/fee_private.verifier" +); + +// Initialize multi-threading to allow WASM execution. +await initThreadPoool(); + +// Create a new Account, Program Manager, NetworkClient, KeyProvider, and RecordProvider. +const account = new Account(); +const programManager = new ProgramManager(); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); +const offlineKeyProvider = new OfflineKeyProvider(); +const recordProvider = new NetworkRecordProvider(account, networkClient); + +// Add the keys for fee_private, transfer_private, and the inclusion circuit to the key provider. +offlineKeyProvider.insertFeePrivateKeys(feeProvingKey) +offlineKeyProvider.insertTransferPrivateKeys(transferPrivateProvingKey) +offlineKeyProvider.insertInclusionKeys(inclusionProver); + +// Create an offline query using the latest state root for the inclusion proof. +const offlineQuery = new OfflineQuery("latestStateRoot"); + +// Create the program manager +const programManager = new ProgramManager(); +programManager.setAccount(account); +programManager.setKeyProvider(offlineKeyProvider); + +// Build the execution. +const offlineExecuteTx = await programManager.buildExecutionTransaction( + programName: "credits.aleo", + functionName: "transfer_private", + priorityFee: 0.0, + privateFee: true, + inputs: 5u32, + offlienQuery + ); + + + + + From 5b1f973fea92d0d9ce1f556366fac431f27e6fc4 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Wed, 13 Aug 2025 11:57:46 -0700 Subject: [PATCH 6/9] added execution with proving key loading example --- .../07_transfer_private_using_stored_keys.md | 7 +- .../08_execute_program_with_records.md | 72 +++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 docs/examples/08_execute_program_with_records.md diff --git a/docs/examples/07_transfer_private_using_stored_keys.md b/docs/examples/07_transfer_private_using_stored_keys.md index 3805c9a58..62126db0e 100644 --- a/docs/examples/07_transfer_private_using_stored_keys.md +++ b/docs/examples/07_transfer_private_using_stored_keys.md @@ -50,9 +50,8 @@ offlineKeyProvider.insertInclusionKeys(inclusionProver); const offlineQuery = new OfflineQuery("latestStateRoot"); // Create the program manager -const programManager = new ProgramManager(); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); programManager.setAccount(account); -programManager.setKeyProvider(offlineKeyProvider); // Build the execution. const offlineExecuteTx = await programManager.buildExecutionTransaction( @@ -61,9 +60,11 @@ const offlineExecuteTx = await programManager.buildExecutionTransaction( priorityFee: 0.0, privateFee: true, inputs: 5u32, - offlienQuery + offlineQuery ); +// Broadcast the transaction to the network + const txId = await networkClient.broadcastTransaction(offlineExecuteTx); diff --git a/docs/examples/08_execute_program_with_records.md b/docs/examples/08_execute_program_with_records.md new file mode 100644 index 000000000..3bc0ba1cf --- /dev/null +++ b/docs/examples/08_execute_program_with_records.md @@ -0,0 +1,72 @@ +The following template demonstrates how to create an execution using saved proving keys for transactions that either mint or consumer records. + +```typescript +import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; + +// Helper method to load the keys from storage. +async function loadFunctionKeyPair(proverPath, verifierPath) { + const proverBytes = await fs.readFile(proverPath); + const verifierBytes = await fs.readFile(verifierPath); + + const provingKey = ProvingKey.fromBytes(new Uint8Array(proverBytes)); + const verifyingKey = VerifyingKey.fromBytes(new Uint8Array(verifierBytes)); + + return [provingKey, verifyingKey]; +} + +// Load the inclusion proving and verifying keys. +const [inclusionProver, inclusionVerifier] = await loadFunctionKeyPair( + "./keys/inclusion.prover", + "./keys/inclusion.verifier" +); + +// Load the fee public proving and verifying keys. +const [feeProvingKey, feeVerifyingKey] = await loadFunctionKeyPair( + "./keys/fee_public.prover", + "./keys/fee_public.verifier" +); + +// Load the proving and verifying keys associate with the transition method. +const [transitionProvingKey, transitionVerifyingKey] = await loadFunctionKeyPair( + "./keys/transition.prover", + "./keys/transition.verifier" +); + +// Create a new Account, Program Manager, NetworkClient, KeyProvider, and RecordProvider. +const account = new Account(); +const programManager = new ProgramManager(); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); +const offlineKeyProvider = new OfflineKeyProvider(); +const recordProvider = new NetworkRecordProvider(account, networkClient); + +// Add the keys for fee_public and the inclusion circuit to the key provider. +offlineKeyProvider.insertFeePublicKeys(feeProvingKey) +offlineKeyProvider.insertInclusionKeys(inclusionProver); + +// Cache the proving key for the transition method. +// Replace "program_name" and "transition_name" with the your program and transition method. +OfflineKeyProvider.cacheKeys("program_name.aleo/transition_name", transitionProvingKey, transitionerifyingKey); + +// Create an offline search params object. +const offlineSearchParams = new OfflineSearchParams("program_name.aleo/transition_name"); + +// Create an offline query using the latest state root for the inclusion proof. +const offlineQuery = new OfflineQuery("latestStateRoot"); + +// Create the program manager +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); +programManager.setAccount(account); + +// Build the execution. +const offlineExecuteTx = await programManager.buildExecutionTransaction( + programName: "program_name.aleo", + functionName: "transition_method", + priorityFee: 0.0, + privateFee: false, + inputs: 5u32, // replace with whatever input(s) your transition method requires + offlineSearchParams, + offlineQuery + ); + +// Broadcast the transaction to the network + const txId = await networkClient.broadcastTransaction(offlineExecuteTx); \ No newline at end of file From 84949559ca301e9e8d73b85019161692e394964b Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Wed, 13 Aug 2025 12:06:41 -0700 Subject: [PATCH 7/9] fixed typo --- docs/examples/08_execute_program_with_records.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/08_execute_program_with_records.md b/docs/examples/08_execute_program_with_records.md index 3bc0ba1cf..043118e14 100644 --- a/docs/examples/08_execute_program_with_records.md +++ b/docs/examples/08_execute_program_with_records.md @@ -1,4 +1,4 @@ -The following template demonstrates how to create an execution using saved proving keys for transactions that either mint or consumer records. +The following template demonstrates how to create an execution using saved proving keys for transactions that either mint or consume records. ```typescript import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; From ba12b434ab2df575713e8f2c8a96184ea498502c Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Thu, 14 Aug 2025 16:59:20 -0700 Subject: [PATCH 8/9] updated script for saving keys to disc --- docs/examples/05_download_and_save_keys_to_disc.md | 7 +++++-- docs/examples/06_transfer_public_using_stored_keys.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/examples/05_download_and_save_keys_to_disc.md b/docs/examples/05_download_and_save_keys_to_disc.md index 551851d22..a8690b2b4 100644 --- a/docs/examples/05_download_and_save_keys_to_disc.md +++ b/docs/examples/05_download_and_save_keys_to_disc.md @@ -6,7 +6,9 @@ import { CREDITS_PROGRAM_KEYS, ProvingKey, // these are WASM-backed types VerifyingKey, -} from "@provablehq/sdk +} from "@provablehq/sdk"; +import fs from "node:fs/promises"; +import path from "node:path"; const keyProvider = new AleoKeyProvider(); @@ -20,7 +22,7 @@ const [incPk, incVk] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.i // For a transition method in any deployed Aleo program, use the following pattern to fetch the proving and verifying // keys associated with that transition. const keySearchParams = { "cacheKey": "myProgram:myFunction" }; -const [transition_Pk, transition_vK] = await keyProvider.functionKeys(searchParams); +const [transition_Pk, transition_Vk] = await keyProvider.functionKeys(keySearchParams); // You can use this method for saving the keys to disc. async function writeKeyToFile(key, filePath) { @@ -44,3 +46,4 @@ await writeKeyToFile(incVk, path.join(keyDir, "inclusion.verifier")); await writeKeyToFile(transition_Pk, path.join(keyDir, "transition.prover")); await writeKeyToFile(transition_Vk, path.join(keyDir, "transition.verifier")); + diff --git a/docs/examples/06_transfer_public_using_stored_keys.md b/docs/examples/06_transfer_public_using_stored_keys.md index e3c15cf96..61435e1b5 100644 --- a/docs/examples/06_transfer_public_using_stored_keys.md +++ b/docs/examples/06_transfer_public_using_stored_keys.md @@ -36,7 +36,7 @@ offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); offlineKeyProvider.insertFeePublicKeys(feeProvingKey); // Create program manager using the OfflineKeyProvider and NetworkProvider. -const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider); // Set the account as the program caller. programManager.setAccount(account); From 0dfcd3653144b39dc011959059f9e92469de6ec4 Mon Sep 17 00:00:00 2001 From: Roee-87 Date: Thu, 14 Aug 2025 17:30:22 -0700 Subject: [PATCH 9/9] fixed key import --- .../06_transfer_public_using_stored_keys.md | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/docs/examples/06_transfer_public_using_stored_keys.md b/docs/examples/06_transfer_public_using_stored_keys.md index 61435e1b5..f0d45c818 100644 --- a/docs/examples/06_transfer_public_using_stored_keys.md +++ b/docs/examples/06_transfer_public_using_stored_keys.md @@ -1,31 +1,23 @@ This example demonstrates how to execute public_transfer using locally saved proving and verifying keys. ```typescript -import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provable.sdk'; - -// Initialize multi-threading to allow WASM execution. -await initThreadPoool(); +import { Account, ProgramManager, ProvingKey, VerifyingKey, initThreadPool, OfflineKeyProvider} from '@provablehq/sdk'; +import fs from "node:fs/promises"; // Helper method to load the keys from storage. -async function loadFunctionKeyPair(proverPath, verifierPath) { +async function loadFunctionKeyPair(proverPath) { const proverBytes = await fs.readFile(proverPath); - const verifierBytes = await fs.readFile(verifierPath); const provingKey = ProvingKey.fromBytes(new Uint8Array(proverBytes)); - const verifyingKey = VerifyingKey.fromBytes(new Uint8Array(verifierBytes)); - return [provingKey, verifyingKey]; + return provingKey; } -// Load the proving and verifying keys for public_transfer and fee_public from local storage. -const [feeProvingKey, feeVerifyingKey] = await loadFunctionKeyPair( - "./keys/fee_public.prover", - "./keys/fee_public.verifier" -); +// Initialize multi-threading to allow WASM execution. +await initThreadPoool(); -const [transferPublicProvingKey, transferPublicVerifyingKey] = await loadFunctionKeyPair( - "./keys/transfer_public.prover", - "./keys/transfer_public.verifier" -); +// Load the proving and verifying keys for public_transfer and fee_public from local storage. +const feeProvingKey = await loadFunctionKeyPair("./keys/fee_public.prover"); +const transferPublicProvingKey = await loadFunctionKeyPair("./keys/transfer_public.prover"); // Create an offline Key provider const keyProvider = new OfflineKeyProvider(); @@ -37,6 +29,10 @@ offlineKeyProvider.insertFeePublicKeys(feeProvingKey); // Create program manager using the OfflineKeyProvider and NetworkProvider. const programManager = new ProgramManager("https://api.explorer.provable.com/v1", offlineKeyProvider); + +// Create or import an account. +const account = new Account(); + // Set the account as the program caller. programManager.setAccount(account);