@provablehq/sdk 0.9.10 → 0.9.12

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.
@@ -0,0 +1,7 @@
1
+ export interface FunctionInput {
2
+ type: string;
3
+ visibility: string;
4
+ record?: string;
5
+ register?: string;
6
+ members?: FunctionInput[];
7
+ }
@@ -5,7 +5,6 @@ import { RecordProvider } from "./record-provider.js";
5
5
  import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
6
6
  import { FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
7
7
  import { Authorization, ExecutionResponse, OfflineQuery, RecordPlaintext, PrivateKey, Program, ProvingKey, ProvingRequest, VerifyingKey, Transaction } from "./wasm.js";
8
- import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
9
8
  /**
10
9
  * Represents the options for executing a transaction in the Aleo network.
11
10
  * This interface is used to specify the parameters required for building and submitting an execution transaction.
@@ -121,10 +120,10 @@ interface ExecuteAuthorizationOptions {
121
120
  interface ProvingRequestOptions {
122
121
  programName: string;
123
122
  functionName: string;
124
- baseFee: number;
125
123
  priorityFee: number;
126
124
  privateFee: boolean;
127
125
  inputs: string[];
126
+ baseFee?: number;
128
127
  recordSearchParams?: RecordSearchParams;
129
128
  feeRecord?: string | RecordPlaintext;
130
129
  privateKey?: PrivateKey;
@@ -134,6 +133,24 @@ interface ProvingRequestOptions {
134
133
  unchecked?: boolean;
135
134
  edition?: number;
136
135
  }
136
+ /**
137
+ * Fee estimate options.
138
+ *
139
+ * @property {string} programName - The name of the program containing the function to estimate the fee for.
140
+ * @property {string} functionName - The name of the function to execute within the program to estimate the fee for.
141
+ * @property {string} [program] - Program source code to use for the fee estimate.
142
+ * @property {ProgramImports} [imports] - Programs that the program imports.
143
+ * @property {number} [edition] - Edition of the program to estimate the fee for.
144
+ * @property {Authorization} authorization - An authorization to estimate the fee for.
145
+ */
146
+ interface FeeEstimateOptions {
147
+ programName: string;
148
+ functionName?: string;
149
+ program?: string | Program;
150
+ imports?: ProgramImports;
151
+ edition?: number;
152
+ authorization?: Authorization;
153
+ }
137
154
  /**
138
155
  * The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
139
156
  */
@@ -195,6 +212,25 @@ declare class ProgramManager {
195
212
  * programManager.setHeader('Accept-Language', 'en-US');
196
213
  */
197
214
  setHeader(headerName: string, value: string): void;
215
+ /**
216
+ * Set the inclusion prover into the wasm memory. This should be done prior to any execution of a function with a
217
+ * private record.
218
+ *
219
+ * @param {ProvingKey} [provingKey]
220
+ *
221
+ * @example
222
+ * import { ProgramManager, AleoKeyProvider } from "@provablehq/sdk/mainnet.js";
223
+ *
224
+ * const keyProvider = new AleoKeyProvider();
225
+ * keyProvider.useCache(true);
226
+ *
227
+ * // Create a ProgramManager
228
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
229
+ *
230
+ * // Set the inclusion keys.
231
+ * programManager.setInclusionProver();
232
+ */
233
+ setInclusionProver(provingKey?: ProvingKey): Promise<void>;
198
234
  /**
199
235
  * Remove a header from the `AleoNetworkClient`s header map
200
236
  *
@@ -333,53 +369,65 @@ declare class ProgramManager {
333
369
  * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
334
370
  *
335
371
  * @example
336
- * /// Import the mainnet version of the sdk.
337
- * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
372
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
338
373
  *
339
- * // Create a new NetworkClient, KeyProvider, and RecordProvider.
374
+ * await initThreadPool();
375
+ *
376
+ * // Create a new KeyProvider.
340
377
  * const keyProvider = new AleoKeyProvider();
341
378
  * keyProvider.useCache(true);
342
379
  *
343
- * // Initialize a program manager with the key provider to automatically fetch keys for executions
380
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
344
381
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
345
382
  *
346
383
  * // Build the `Authorization`.
384
+ * const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
347
385
  * const authorization = await programManager.buildAuthorization({
348
- * programName: "credits.aleo",
349
- * functionName: "transfer_public",
350
- * inputs: [
351
- * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
352
- * "10000000u64",
353
- * ],
386
+ * programName: "credits.aleo",
387
+ * functionName: "transfer_public",
388
+ * privateKey,
389
+ * inputs: [
390
+ * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
391
+ * "10000000u64",
392
+ * ],
354
393
  * });
355
394
  *
395
+ * console.log("Getting execution id");
396
+ *
356
397
  * // Derive the execution ID and base fee.
357
398
  * const executionId = authorization.toExecutionId().toString();
358
399
  *
400
+ * console.log("Estimating fee");
401
+ *
359
402
  * // Get the base fee in microcredits.
360
- * const baseFeeMicrocredits = ProgramManager.estimateFeeForAuthorization(authorization, "credits.aleo");
361
- * const baseFeeCredits = baseFeeMicrocredits/1000000;
403
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization(authorization, "credits.aleo");
404
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
405
+ *
406
+ * console.log("Building fee authorization");
362
407
  *
363
408
  * // Build a credits.aleo/fee_public `Authorization`.
364
409
  * const feeAuthorization = await programManager.buildFeeAuthorization({
365
- * deploymentOrExecutionId: executionId,
366
- * baseFeeCredits,
410
+ * deploymentOrExecutionId: executionId,
411
+ * baseFeeCredits,
412
+ * privateKey
367
413
  * });
368
414
  *
369
- * // Build and execute the transaction
415
+ * console.log("Executing authorizations");
416
+ *
417
+ * // Build and execute the transaction.
370
418
  * const tx = await programManager.buildTransactionFromAuthorization({
371
- * programName: "hello_hello.aleo",
372
- * authorization,
373
- * feeAuthorization,
419
+ * programName: "credits.aleo",
420
+ * authorization,
421
+ * feeAuthorization,
374
422
  * });
375
423
  *
376
- * // Submit the transaction to the network
424
+ * // Submit the transaction to the network.
377
425
  * await programManager.networkClient.submitTransaction(tx.toString());
378
426
  *
379
- * // Verify the transaction was successful
427
+ * // Verify the transaction was successful.
380
428
  * setTimeout(async () => {
381
- * const transaction = await programManager.networkClient.getTransaction(tx.id());
382
- * assert(transaction.id() === tx.id());
429
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
430
+ * console.log(transaction);
383
431
  * }, 10000);
384
432
  */
385
433
  buildTransactionFromAuthorization(options: ExecuteAuthorizationOptions): Promise<Transaction>;
@@ -463,7 +511,6 @@ declare class ProgramManager {
463
511
  * const provingRequest = await programManager.provingRequest({
464
512
  * programName: "credits.aleo",
465
513
  * functionName: "transfer_public",
466
- * baseFee: 100000,
467
514
  * priorityFee: 0,
468
515
  * privateFee: false,
469
516
  * inputs: [
@@ -1151,15 +1198,6 @@ declare class ProgramManager {
1151
1198
  * assert(isValid);
1152
1199
  */
1153
1200
  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
1201
  /**
1164
1202
  * Create a program object from a program's source code
1165
1203
  *
@@ -1179,6 +1217,86 @@ declare class ProgramManager {
1179
1217
  * @param {string} program The program source code
1180
1218
  */
1181
1219
  verifyProgram(program: string): boolean;
1182
- getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<OwnedRecord>;
1220
+ /**
1221
+ * Estimate the execution fee for an authorization.
1222
+ *
1223
+ * @param {FeeEstimateOptions} options Options for fee estimate.
1224
+ *
1225
+ * @example
1226
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
1227
+ *
1228
+ * await initThreadPool();
1229
+ *
1230
+ * // Create a new KeyProvider.
1231
+ * const keyProvider = new AleoKeyProvider();
1232
+ * keyProvider.useCache(true);
1233
+ *
1234
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
1235
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
1236
+ *
1237
+ * // Build the `Authorization`.
1238
+ * const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
1239
+ * const authorization = await programManager.buildAuthorization({
1240
+ * programName: "credits.aleo",
1241
+ * functionName: "transfer_public",
1242
+ * privateKey,
1243
+ * inputs: [
1244
+ * "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
1245
+ * "10000000u64",
1246
+ * ],
1247
+ * });
1248
+ *
1249
+ * console.log("Getting execution id");
1250
+ *
1251
+ * // Derive the execution ID and base fee.
1252
+ * const executionId = authorization.toExecutionId().toString();
1253
+ *
1254
+ * console.log("Estimating fee");
1255
+ *
1256
+ * // Get the base fee in microcredits.
1257
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
1258
+ * authorization,
1259
+ * programName: "credits.aleo"
1260
+ * });
1261
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1262
+ *
1263
+ * console.log("Building fee authorization");
1264
+ *
1265
+ * // Build a credits.aleo/fee_public `Authorization`.
1266
+ * const feeAuthorization = await programManager.buildFeeAuthorization({
1267
+ * deploymentOrExecutionId: executionId,
1268
+ * baseFeeCredits,
1269
+ * privateKey
1270
+ * });
1271
+ */
1272
+ estimateFeeForAuthorization(options: FeeEstimateOptions): Promise<bigint>;
1273
+ /**
1274
+ * Estimate the execution fee for an Aleo function.
1275
+ *
1276
+ * @param {FeeEstimateOptions} options Options for the fee estimate.
1277
+ *
1278
+ * @returns {Promise<bigint>} Execution fee in microcredits for the authorization.
1279
+ *
1280
+ * @example
1281
+ * import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
1282
+ *
1283
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions.
1284
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
1285
+ *
1286
+ * // Get the base fee in microcredits.
1287
+ * const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
1288
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1289
+ *
1290
+ * console.log("Building fee authorization");
1291
+ *
1292
+ * // Build a credits.aleo/fee_public `Authorization`.
1293
+ * const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
1294
+ * programName: "credits.aleo",
1295
+ * functionName: "transfer_public",
1296
+ * });
1297
+ * const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
1298
+ */
1299
+ estimateExecutionFee(options: FeeEstimateOptions): Promise<bigint>;
1300
+ getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<RecordPlaintext>;
1183
1301
  }
1184
1302
  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.12",
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.12",
55
55
  "@scure/base": "^2.0.0",
56
56
  "comlink": "^4.4.2",
57
57
  "core-js": "^3.40.0",