You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/src/program-manager.ts
+98-2Lines changed: 98 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -696,6 +696,100 @@ class ProgramManager {
696
696
);
697
697
}
698
698
699
+
/**
700
+
* Builds a SnarkVM `Authorization` for a specific function without building a circuit first. This should be used when fast authorization generation is needed and the invoker is confident inputs are coorect.
701
+
*
702
+
* @param {AuthorizationOptions} options - The options for building the `Authorization`
703
+
* @returns {Promise<Authorization>} - A promise that resolves to an `Authorization` or throws an Error.
704
+
*
705
+
* @example
706
+
* /// Import the mainnet version of the sdk.
707
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
708
+
*
709
+
* // Create a new NetworkClient, KeyProvider, and RecordProvider.
710
+
* const keyProvider = new AleoKeyProvider();
711
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
712
+
* keyProvider.useCache = true;
713
+
*
714
+
* // Initialize a ProgramManager with the key and record providers.
715
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
// Destructure the options object to access the parameters.
731
+
const{
732
+
programName,
733
+
functionName,
734
+
inputs,
735
+
}=options;
736
+
737
+
constprivateKey=options.privateKey;
738
+
letprogram=options.programSource;
739
+
letimports=options.programImports;
740
+
741
+
// Ensure the function exists on the network.
742
+
if(program===undefined){
743
+
try{
744
+
program=<string>(
745
+
awaitthis.networkClient.getProgram(programName)
746
+
);
747
+
}catch(e: any){
748
+
logAndThrow(
749
+
`Error finding ${programName}. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network the program is deployed to the network.`,
750
+
);
751
+
}
752
+
}elseif(programinstanceofProgram){
753
+
program=program.toString();
754
+
}
755
+
756
+
// Get the private key from the account if it is not provided in the parameters.
757
+
letexecutionPrivateKey=privateKey;
758
+
if(
759
+
typeofprivateKey==="undefined"&&
760
+
typeofthis.account!=="undefined"
761
+
){
762
+
executionPrivateKey=this.account.privateKey();
763
+
}
764
+
765
+
if(typeofexecutionPrivateKey==="undefined"){
766
+
throw"No private key provided and no private key set in the ProgramManager";
`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`,
779
+
);
780
+
}
781
+
}
782
+
783
+
// Build and return an `Authorization` for the desired function.
* Builds a SnarkVM fee `Authorization` for `credits.aleo/fee_private` or `credits.aleo/fee_public`. If a record is provided `fee_private` will be executed, otherwise `fee_public` will be executed.
701
795
*
@@ -2153,6 +2247,7 @@ class ProgramManager {
2153
2247
* Verify a proof from an offline execution. This is useful when it is desired to do offchain proving and verification.
2154
2248
*
2155
2249
* @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
2250
+
* @param {blockHeight} blockHeight The ledger height when the execution was generated.
2156
2251
* @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
2157
2252
* @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
2158
2253
* @returns {boolean} True if the proof is valid, false otherwise
0 commit comments