@provablehq/sdk 0.8.8 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { Account } from "./account";
2
- import { AleoNetworkClient, ProgramImports } from "./network-client";
2
+ import { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports } from "./network-client";
3
+ import { ImportedPrograms, ImportedVerifyingKeys } from "./models/imports";
3
4
  import { RecordProvider, RecordSearchParams } from "./record-provider";
4
5
  import { FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider";
5
6
  import { ExecutionResponse, OfflineQuery, RecordPlaintext, PrivateKey, Program, ProvingKey, VerifyingKey, Transaction } from "./wasm";
@@ -53,7 +54,7 @@ declare class ProgramManager {
53
54
  * @param { FunctionKeyProvider | undefined } keyProvider A key provider that implements {@link FunctionKeyProvider} interface
54
55
  * @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
55
56
  */
56
- constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined);
57
+ constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined, networkClientOptions?: AleoNetworkClientOptions | undefined);
57
58
  /**
58
59
  * Check if the fee is sufficient to pay for the transaction
59
60
  */
@@ -82,6 +83,37 @@ declare class ProgramManager {
82
83
  * @param {RecordProvider} recordProvider
83
84
  */
84
85
  setRecordProvider(recordProvider: RecordProvider): void;
86
+ /**
87
+ * Set a header in the `AleoNetworkClient`s header map
88
+ *
89
+ * @param {string} headerName The name of the header to set
90
+ * @param {string} value The header value
91
+ *
92
+ * @example
93
+ * import { ProgramManager } from "@provablehq/sdk/mainnet.js";
94
+ *
95
+ * // Create a ProgramManager
96
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1");
97
+ *
98
+ * // Set the value of the `Accept-Language` header to `en-US`
99
+ * programManager.setHeader('Accept-Language', 'en-US');
100
+ */
101
+ setHeader(headerName: string, value: string): void;
102
+ /**
103
+ * Remove a header from the `AleoNetworkClient`s header map
104
+ *
105
+ * @param {string} headerName The name of the header to be removed
106
+ *
107
+ * @example
108
+ * import { ProgramManager } from "@provablehq/sdk/mainnet.js";
109
+ *
110
+ * // Create a ProgramManager
111
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1");
112
+ *
113
+ * // Remove the default `X-Aleo-SDK-Version` header
114
+ * programManager.removeHeader('X-Aleo-SDK-Version');
115
+ */
116
+ removeHeader(headerName: string): void;
85
117
  /**
86
118
  * Builds a deployment transaction for submission to the Aleo network.
87
119
  *
@@ -806,12 +838,38 @@ declare class ProgramManager {
806
838
  */
807
839
  setValidatorState(validator_state: boolean, options?: Partial<ExecuteOptions>): Promise<string>;
808
840
  /**
809
- * Verify a proof of execution from an offline execution
841
+ * Verify a proof from an offline execution. This is useful when it is desired to do offchain proving and verification.
810
842
  *
811
- * @param {executionResponse} executionResponse
843
+ * @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
844
+ * @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
845
+ * @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
812
846
  * @returns {boolean} True if the proof is valid, false otherwise
847
+ *
848
+ * @example
849
+ * /// Import the mainnet version of the sdk used to build executions.
850
+ * import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
851
+ *
852
+ * /// Create the source for two programs.
853
+ * const program = "import add_it_up.aleo; \n\n program mul_add.aleo;\n\nfunction mul_and_add:\n input r0 as u32.public;\n input r1 as u32.private;\n mul r0 r1 into r2;\n call add_it_up.aleo/add_it r1 r2 into r3; output r3 as u32.private;\n";
854
+ * const program_import = "program add_it_up.aleo;\n\nfunction add_it:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
855
+ * const programManager = new ProgramManager(undefined, undefined, undefined);
856
+ *
857
+ * /// Create a temporary account for the execution of the program
858
+ * const account = Account.fromCipherText(process.env.ciphertext, process.env.password);
859
+ * programManager.setAccount(account);
860
+ *
861
+ * /// Get the response and ensure that the program executed correctly
862
+ * const executionResponse = await programManager.run(program, "mul_and_add", ["5u32", "5u32"], true);
863
+ *
864
+ * /// Construct the imports and verifying keys
865
+ * const imports = { "add_it_up.aleo": program_import };
866
+ * const importedVerifyingKeys = { "add_it_up.aleo": [["add_it", "verifyingKey1..."]] };
867
+ *
868
+ * /// Verify the execution.
869
+ * const isValid = programManager.verifyExecution(executionResponse, imports, importedVerifyingKeys);
870
+ * assert(isValid);
813
871
  */
814
- verifyExecution(executionResponse: ExecutionResponse): boolean;
872
+ verifyExecution(executionResponse: ExecutionResponse, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean;
815
873
  /**
816
874
  * Create a program object from a program's source code
817
875
  *
@@ -1,4 +1,14 @@
1
+ export declare function environment(): "chrome" | "firefox" | "safari" | "edge" | "opera" | "browser" | "node" | "unknown";
1
2
  export declare function logAndThrow(message: string): never;
2
3
  export declare function parseJSON(json: string): any;
3
4
  export declare function get(url: URL | string, options?: RequestInit): Promise<Response>;
4
5
  export declare function post(url: URL | string, options: RequestInit): Promise<Response>;
6
+ type RetryOptions = {
7
+ maxAttempts?: number;
8
+ baseDelay?: number;
9
+ jitter?: number;
10
+ retryOnStatus?: number[];
11
+ shouldRetry?: (err: any) => boolean;
12
+ };
13
+ export declare function retryWithBackoff<T>(fn: () => Promise<T>, { maxAttempts, baseDelay, jitter, retryOnStatus, shouldRetry, }?: RetryOptions): Promise<T>;
14
+ export {};
@@ -1,6 +1,6 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
2
  import { initThreadPool, PrivateKey, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
3
- import { A as AleoKeyProvider, P as ProgramManager, a as AleoKeyProviderParams } from './program-manager-BuK9g9xJ.js';
3
+ import { P as ProgramManager, A as AleoKeyProvider, a as AleoKeyProviderParams } from './program-manager-BTHjM8b7.js';
4
4
  import { expose } from 'comlink';
5
5
 
6
6
  await initThreadPool();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provablehq/sdk",
3
- "version": "0.8.8",
3
+ "version": "0.9.1",
4
4
  "description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
5
5
  "collaborators": [
6
6
  "The Provable Team"
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "homepage": "https://github.com/ProvableHQ/sdk#readme",
49
49
  "dependencies": {
50
- "@provablehq/wasm": "^0.8.8",
50
+ "@provablehq/wasm": "^0.9.1",
51
51
  "comlink": "^4.4.2",
52
52
  "core-js": "^3.40.0",
53
53
  "mime": "^4.0.6",