@provablehq/sdk 0.9.10 → 0.9.11

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.
@@ -121,10 +121,10 @@ interface ExecuteAuthorizationOptions {
121
121
  interface ProvingRequestOptions {
122
122
  programName: string;
123
123
  functionName: string;
124
- baseFee: number;
125
124
  priorityFee: number;
126
125
  privateFee: boolean;
127
126
  inputs: string[];
127
+ baseFee?: number;
128
128
  recordSearchParams?: RecordSearchParams;
129
129
  feeRecord?: string | RecordPlaintext;
130
130
  privateKey?: PrivateKey;
@@ -134,6 +134,24 @@ interface ProvingRequestOptions {
134
134
  unchecked?: boolean;
135
135
  edition?: number;
136
136
  }
137
+ /**
138
+ * Fee estimate options.
139
+ *
140
+ * @property {string} programName - The name of the program containing the function to estimate the fee for.
141
+ * @property {string} functionName - The name of the function to execute within the program to estimate the fee for.
142
+ * @property {string} [program] - Program source code to use for the fee estimate.
143
+ * @property {ProgramImports} [imports] - Programs that the program imports.
144
+ * @property {number} [edition] - Edition of the program to estimate the fee for.
145
+ * @property {Authorization} authorization - An authorization to estimate the fee for.
146
+ */
147
+ interface FeeEstimateOptions {
148
+ programName: string;
149
+ functionName?: string;
150
+ program?: string | Program;
151
+ imports?: ProgramImports;
152
+ edition?: number;
153
+ authorization?: Authorization;
154
+ }
137
155
  /**
138
156
  * The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
139
157
  */
@@ -333,53 +351,65 @@ declare class ProgramManager {
333
351
  * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
334
352
  *
335
353
  * @example
336
- * /// Import the mainnet version of the sdk.
337
- * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
354
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
338
355
  *
339
- * // Create a new NetworkClient, KeyProvider, and RecordProvider.
356
+ * await initThreadPool();
357
+ *
358
+ * // Create a new KeyProvider.
340
359
  * const keyProvider = new AleoKeyProvider();
341
360
  * keyProvider.useCache(true);
342
361
  *
343
- * // Initialize a program manager with the key provider to automatically fetch keys for executions
362
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
344
363
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
345
364
  *
346
365
  * // Build the `Authorization`.
366
+ * const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
347
367
  * const authorization = await programManager.buildAuthorization({
348
- * programName: "credits.aleo",
349
- * functionName: "transfer_public",
350
- * inputs: [
351
- * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
352
- * "10000000u64",
353
- * ],
368
+ * programName: "credits.aleo",
369
+ * functionName: "transfer_public",
370
+ * privateKey,
371
+ * inputs: [
372
+ * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
373
+ * "10000000u64",
374
+ * ],
354
375
  * });
355
376
  *
377
+ * console.log("Getting execution id");
378
+ *
356
379
  * // Derive the execution ID and base fee.
357
380
  * const executionId = authorization.toExecutionId().toString();
358
381
  *
382
+ * console.log("Estimating fee");
383
+ *
359
384
  * // Get the base fee in microcredits.
360
- * const baseFeeMicrocredits = ProgramManager.estimateFeeForAuthorization(authorization, "credits.aleo");
361
- * const baseFeeCredits = baseFeeMicrocredits/1000000;
385
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization(authorization, "credits.aleo");
386
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
387
+ *
388
+ * console.log("Building fee authorization");
362
389
  *
363
390
  * // Build a credits.aleo/fee_public `Authorization`.
364
391
  * const feeAuthorization = await programManager.buildFeeAuthorization({
365
- * deploymentOrExecutionId: executionId,
366
- * baseFeeCredits,
392
+ * deploymentOrExecutionId: executionId,
393
+ * baseFeeCredits,
394
+ * privateKey
367
395
  * });
368
396
  *
369
- * // Build and execute the transaction
397
+ * console.log("Executing authorizations");
398
+ *
399
+ * // Build and execute the transaction.
370
400
  * const tx = await programManager.buildTransactionFromAuthorization({
371
- * programName: "hello_hello.aleo",
372
- * authorization,
373
- * feeAuthorization,
401
+ * programName: "credits.aleo",
402
+ * authorization,
403
+ * feeAuthorization,
374
404
  * });
375
405
  *
376
- * // Submit the transaction to the network
406
+ * // Submit the transaction to the network.
377
407
  * await programManager.networkClient.submitTransaction(tx.toString());
378
408
  *
379
- * // Verify the transaction was successful
409
+ * // Verify the transaction was successful.
380
410
  * setTimeout(async () => {
381
- * const transaction = await programManager.networkClient.getTransaction(tx.id());
382
- * assert(transaction.id() === tx.id());
411
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
412
+ * console.log(transaction);
383
413
  * }, 10000);
384
414
  */
385
415
  buildTransactionFromAuthorization(options: ExecuteAuthorizationOptions): Promise<Transaction>;
@@ -463,7 +493,6 @@ declare class ProgramManager {
463
493
  * const provingRequest = await programManager.provingRequest({
464
494
  * programName: "credits.aleo",
465
495
  * functionName: "transfer_public",
466
- * baseFee: 100000,
467
496
  * priorityFee: 0,
468
497
  * privateFee: false,
469
498
  * inputs: [
@@ -1151,15 +1180,6 @@ declare class ProgramManager {
1151
1180
  * assert(isValid);
1152
1181
  */
1153
1182
  verifyExecution(executionResponse: ExecutionResponse, blockHeight: number, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean;
1154
- /**
1155
- * Set the inclusion key bytes.
1156
- *
1157
- * @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
1158
- * @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
1159
- * @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
1160
- * @returns {boolean} True if the proof is valid, false otherwise
1161
- *
1162
-
1163
1183
  /**
1164
1184
  * Create a program object from a program's source code
1165
1185
  *
@@ -1179,6 +1199,86 @@ declare class ProgramManager {
1179
1199
  * @param {string} program The program source code
1180
1200
  */
1181
1201
  verifyProgram(program: string): boolean;
1202
+ /**
1203
+ * Estimate the execution fee for an authorization.
1204
+ *
1205
+ * @param {FeeEstimateOptions} options Options for fee estimate.
1206
+ *
1207
+ * @example
1208
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
1209
+ *
1210
+ * await initThreadPool();
1211
+ *
1212
+ * // Create a new KeyProvider.
1213
+ * const keyProvider = new AleoKeyProvider();
1214
+ * keyProvider.useCache(true);
1215
+ *
1216
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
1217
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
1218
+ *
1219
+ * // Build the `Authorization`.
1220
+ * const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
1221
+ * const authorization = await programManager.buildAuthorization({
1222
+ * programName: "credits.aleo",
1223
+ * functionName: "transfer_public",
1224
+ * privateKey,
1225
+ * inputs: [
1226
+ * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
1227
+ * "10000000u64",
1228
+ * ],
1229
+ * });
1230
+ *
1231
+ * console.log("Getting execution id");
1232
+ *
1233
+ * // Derive the execution ID and base fee.
1234
+ * const executionId = authorization.toExecutionId().toString();
1235
+ *
1236
+ * console.log("Estimating fee");
1237
+ *
1238
+ * // Get the base fee in microcredits.
1239
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
1240
+ * authorization,
1241
+ * programName: "credits.aleo"
1242
+ * });
1243
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1244
+ *
1245
+ * console.log("Building fee authorization");
1246
+ *
1247
+ * // Build a credits.aleo/fee_public `Authorization`.
1248
+ * const feeAuthorization = await programManager.buildFeeAuthorization({
1249
+ * deploymentOrExecutionId: executionId,
1250
+ * baseFeeCredits,
1251
+ * privateKey
1252
+ * });
1253
+ */
1254
+ estimateFeeForAuthorization(options: FeeEstimateOptions): Promise<bigint>;
1255
+ /**
1256
+ * Estimate the execution fee for an Aleo function.
1257
+ *
1258
+ * @param {FeeEstimateOptions} options Options for the fee estimate.
1259
+ *
1260
+ * @returns {Promise<bigint>} Execution fee in microcredits for the authorization.
1261
+ *
1262
+ * @example
1263
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
1264
+ *
1265
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
1266
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
1267
+ *
1268
+ * // Get the base fee in microcredits.
1269
+ * const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
1270
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1271
+ *
1272
+ * console.log("Building fee authorization");
1273
+ *
1274
+ * // Build a credits.aleo/fee_public `Authorization`.
1275
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
1276
+ * programName: "credits.aleo",
1277
+ * functionName: "transfer_public",
1278
+ * });
1279
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1280
+ */
1281
+ estimateExecutionFee(options: FeeEstimateOptions): Promise<bigint>;
1182
1282
  getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<OwnedRecord>;
1183
1283
  }
1184
1284
  export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provablehq/sdk",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
5
5
  "collaborators": [
6
6
  "The Provable Team"
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "homepage": "https://github.com/ProvableHQ/sdk#readme",
53
53
  "dependencies": {
54
- "@provablehq/wasm": "^0.9.10",
54
+ "@provablehq/wasm": "^0.9.11",
55
55
  "@scure/base": "^2.0.0",
56
56
  "comlink": "^4.4.2",
57
57
  "core-js": "^3.40.0",