@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.
- package/dist/mainnet/browser.js +150 -36
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +133 -33
- package/dist/testnet/browser.js +150 -36
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +133 -33
- package/package.json +2 -2
|
@@ -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
|
-
*
|
|
337
|
-
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
354
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
338
355
|
*
|
|
339
|
-
*
|
|
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
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
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 =
|
|
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
|
-
*
|
|
366
|
-
*
|
|
392
|
+
* deploymentOrExecutionId: executionId,
|
|
393
|
+
* baseFeeCredits,
|
|
394
|
+
* privateKey
|
|
367
395
|
* });
|
|
368
396
|
*
|
|
369
|
-
*
|
|
397
|
+
* console.log("Executing authorizations");
|
|
398
|
+
*
|
|
399
|
+
* // Build and execute the transaction.
|
|
370
400
|
* const tx = await programManager.buildTransactionFromAuthorization({
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
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
|
-
*
|
|
382
|
-
*
|
|
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/dist/testnet/browser.js
CHANGED
|
@@ -425,7 +425,12 @@ async function post(url, options) {
|
|
|
425
425
|
options.method = "POST";
|
|
426
426
|
const response = await fetch(url, options);
|
|
427
427
|
if (!response.ok) {
|
|
428
|
-
|
|
428
|
+
const error = await response.text();
|
|
429
|
+
let message = `${response.status} error received from ${url}`;
|
|
430
|
+
if (error) {
|
|
431
|
+
message = `${error}`;
|
|
432
|
+
}
|
|
433
|
+
throw new Error(message);
|
|
429
434
|
}
|
|
430
435
|
return response;
|
|
431
436
|
}
|
|
@@ -492,7 +497,7 @@ class AleoNetworkClient {
|
|
|
492
497
|
else {
|
|
493
498
|
this.headers = {
|
|
494
499
|
// This is replaced by the actual version by a Rollup plugin
|
|
495
|
-
"X-Aleo-SDK-Version": "0.9.
|
|
500
|
+
"X-Aleo-SDK-Version": "0.9.11",
|
|
496
501
|
"X-Aleo-environment": environment(),
|
|
497
502
|
};
|
|
498
503
|
}
|
|
@@ -1807,7 +1812,7 @@ class AleoNetworkClient {
|
|
|
1807
1812
|
}
|
|
1808
1813
|
}
|
|
1809
1814
|
catch (error) {
|
|
1810
|
-
throw new Error(`Error posting transaction:
|
|
1815
|
+
throw new Error(`Error posting transaction: ${error}`);
|
|
1811
1816
|
}
|
|
1812
1817
|
}
|
|
1813
1818
|
/**
|
|
@@ -4206,53 +4211,65 @@ class ProgramManager {
|
|
|
4206
4211
|
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
|
|
4207
4212
|
*
|
|
4208
4213
|
* @example
|
|
4209
|
-
*
|
|
4210
|
-
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
4214
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
4211
4215
|
*
|
|
4212
|
-
*
|
|
4216
|
+
* await initThreadPool();
|
|
4217
|
+
*
|
|
4218
|
+
* // Create a new KeyProvider.
|
|
4213
4219
|
* const keyProvider = new AleoKeyProvider();
|
|
4214
4220
|
* keyProvider.useCache(true);
|
|
4215
4221
|
*
|
|
4216
|
-
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
4222
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
4217
4223
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
4218
4224
|
*
|
|
4219
4225
|
* // Build the `Authorization`.
|
|
4226
|
+
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
4220
4227
|
* const authorization = await programManager.buildAuthorization({
|
|
4221
|
-
*
|
|
4222
|
-
*
|
|
4223
|
-
*
|
|
4224
|
-
*
|
|
4225
|
-
*
|
|
4226
|
-
*
|
|
4228
|
+
* programName: "credits.aleo",
|
|
4229
|
+
* functionName: "transfer_public",
|
|
4230
|
+
* privateKey,
|
|
4231
|
+
* inputs: [
|
|
4232
|
+
* "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
|
|
4233
|
+
* "10000000u64",
|
|
4234
|
+
* ],
|
|
4227
4235
|
* });
|
|
4228
4236
|
*
|
|
4237
|
+
* console.log("Getting execution id");
|
|
4238
|
+
*
|
|
4229
4239
|
* // Derive the execution ID and base fee.
|
|
4230
4240
|
* const executionId = authorization.toExecutionId().toString();
|
|
4231
4241
|
*
|
|
4242
|
+
* console.log("Estimating fee");
|
|
4243
|
+
*
|
|
4232
4244
|
* // Get the base fee in microcredits.
|
|
4233
|
-
* const baseFeeMicrocredits =
|
|
4234
|
-
* const baseFeeCredits = baseFeeMicrocredits/1000000;
|
|
4245
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization(authorization, "credits.aleo");
|
|
4246
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
4247
|
+
*
|
|
4248
|
+
* console.log("Building fee authorization");
|
|
4235
4249
|
*
|
|
4236
4250
|
* // Build a credits.aleo/fee_public `Authorization`.
|
|
4237
4251
|
* const feeAuthorization = await programManager.buildFeeAuthorization({
|
|
4238
|
-
*
|
|
4239
|
-
*
|
|
4252
|
+
* deploymentOrExecutionId: executionId,
|
|
4253
|
+
* baseFeeCredits,
|
|
4254
|
+
* privateKey
|
|
4240
4255
|
* });
|
|
4241
4256
|
*
|
|
4242
|
-
*
|
|
4257
|
+
* console.log("Executing authorizations");
|
|
4258
|
+
*
|
|
4259
|
+
* // Build and execute the transaction.
|
|
4243
4260
|
* const tx = await programManager.buildTransactionFromAuthorization({
|
|
4244
|
-
*
|
|
4245
|
-
*
|
|
4246
|
-
*
|
|
4261
|
+
* programName: "credits.aleo",
|
|
4262
|
+
* authorization,
|
|
4263
|
+
* feeAuthorization,
|
|
4247
4264
|
* });
|
|
4248
4265
|
*
|
|
4249
|
-
* // Submit the transaction to the network
|
|
4266
|
+
* // Submit the transaction to the network.
|
|
4250
4267
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
4251
4268
|
*
|
|
4252
|
-
* // Verify the transaction was successful
|
|
4269
|
+
* // Verify the transaction was successful.
|
|
4253
4270
|
* setTimeout(async () => {
|
|
4254
|
-
*
|
|
4255
|
-
*
|
|
4271
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
4272
|
+
* console.log(transaction);
|
|
4256
4273
|
* }, 10000);
|
|
4257
4274
|
*/
|
|
4258
4275
|
async buildTransactionFromAuthorization(options) {
|
|
@@ -4299,6 +4316,7 @@ class ProgramManager {
|
|
|
4299
4316
|
}
|
|
4300
4317
|
}
|
|
4301
4318
|
// Resolve the program imports if they exist.
|
|
4319
|
+
console.log("Resolving program imports");
|
|
4302
4320
|
const numberOfImports = Program.fromString(program).getImports().length;
|
|
4303
4321
|
if (numberOfImports > 0 && !imports) {
|
|
4304
4322
|
try {
|
|
@@ -4310,6 +4328,7 @@ class ProgramManager {
|
|
|
4310
4328
|
}
|
|
4311
4329
|
// If the offline query exists, add the inclusion key.
|
|
4312
4330
|
if (offlineQuery && !this.inclusionKeysLoaded) {
|
|
4331
|
+
console.log("Loading inclusion keys for offline proving.");
|
|
4313
4332
|
try {
|
|
4314
4333
|
const inclusionKeys = await this.keyProvider.inclusionKeys();
|
|
4315
4334
|
ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
|
|
@@ -4321,6 +4340,7 @@ class ProgramManager {
|
|
|
4321
4340
|
}
|
|
4322
4341
|
}
|
|
4323
4342
|
// Build an execution transaction from the authorization.
|
|
4343
|
+
console.log("Executing authorizations");
|
|
4324
4344
|
return await ProgramManager$1.executeAuthorization(authorization, feeAuthorization, program, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, imports, this.host, offlineQuery);
|
|
4325
4345
|
}
|
|
4326
4346
|
/**
|
|
@@ -4511,7 +4531,6 @@ class ProgramManager {
|
|
|
4511
4531
|
* const provingRequest = await programManager.provingRequest({
|
|
4512
4532
|
* programName: "credits.aleo",
|
|
4513
4533
|
* functionName: "transfer_public",
|
|
4514
|
-
* baseFee: 100000,
|
|
4515
4534
|
* priorityFee: 0,
|
|
4516
4535
|
* privateFee: false,
|
|
4517
4536
|
* inputs: [
|
|
@@ -4523,8 +4542,9 @@ class ProgramManager {
|
|
|
4523
4542
|
*/
|
|
4524
4543
|
async provingRequest(options) {
|
|
4525
4544
|
// Destructure the options object to access the parameters.
|
|
4526
|
-
const { functionName,
|
|
4545
|
+
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
4527
4546
|
const privateKey = options.privateKey;
|
|
4547
|
+
const baseFee = options.baseFee ? options.baseFee : 0;
|
|
4528
4548
|
let program = options.programSource;
|
|
4529
4549
|
let programName = options.programName;
|
|
4530
4550
|
let feeRecord = options.feeRecord;
|
|
@@ -5719,15 +5739,6 @@ class ProgramManager {
|
|
|
5719
5739
|
return false;
|
|
5720
5740
|
}
|
|
5721
5741
|
}
|
|
5722
|
-
/**
|
|
5723
|
-
* Set the inclusion key bytes.
|
|
5724
|
-
*
|
|
5725
|
-
* @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
|
|
5726
|
-
* @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
|
|
5727
|
-
* @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
|
|
5728
|
-
* @returns {boolean} True if the proof is valid, false otherwise
|
|
5729
|
-
*
|
|
5730
|
-
|
|
5731
5742
|
/**
|
|
5732
5743
|
* Create a program object from a program's source code
|
|
5733
5744
|
*
|
|
@@ -5759,6 +5770,109 @@ class ProgramManager {
|
|
|
5759
5770
|
return false;
|
|
5760
5771
|
}
|
|
5761
5772
|
}
|
|
5773
|
+
/**
|
|
5774
|
+
* Estimate the execution fee for an authorization.
|
|
5775
|
+
*
|
|
5776
|
+
* @param {FeeEstimateOptions} options Options for fee estimate.
|
|
5777
|
+
*
|
|
5778
|
+
* @example
|
|
5779
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
5780
|
+
*
|
|
5781
|
+
* await initThreadPool();
|
|
5782
|
+
*
|
|
5783
|
+
* // Create a new KeyProvider.
|
|
5784
|
+
* const keyProvider = new AleoKeyProvider();
|
|
5785
|
+
* keyProvider.useCache(true);
|
|
5786
|
+
*
|
|
5787
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
5788
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
5789
|
+
*
|
|
5790
|
+
* // Build the `Authorization`.
|
|
5791
|
+
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
5792
|
+
* const authorization = await programManager.buildAuthorization({
|
|
5793
|
+
* programName: "credits.aleo",
|
|
5794
|
+
* functionName: "transfer_public",
|
|
5795
|
+
* privateKey,
|
|
5796
|
+
* inputs: [
|
|
5797
|
+
* "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
|
|
5798
|
+
* "10000000u64",
|
|
5799
|
+
* ],
|
|
5800
|
+
* });
|
|
5801
|
+
*
|
|
5802
|
+
* console.log("Getting execution id");
|
|
5803
|
+
*
|
|
5804
|
+
* // Derive the execution ID and base fee.
|
|
5805
|
+
* const executionId = authorization.toExecutionId().toString();
|
|
5806
|
+
*
|
|
5807
|
+
* console.log("Estimating fee");
|
|
5808
|
+
*
|
|
5809
|
+
* // Get the base fee in microcredits.
|
|
5810
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
|
|
5811
|
+
* authorization,
|
|
5812
|
+
* programName: "credits.aleo"
|
|
5813
|
+
* });
|
|
5814
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
5815
|
+
*
|
|
5816
|
+
* console.log("Building fee authorization");
|
|
5817
|
+
*
|
|
5818
|
+
* // Build a credits.aleo/fee_public `Authorization`.
|
|
5819
|
+
* const feeAuthorization = await programManager.buildFeeAuthorization({
|
|
5820
|
+
* deploymentOrExecutionId: executionId,
|
|
5821
|
+
* baseFeeCredits,
|
|
5822
|
+
* privateKey
|
|
5823
|
+
* });
|
|
5824
|
+
*/
|
|
5825
|
+
async estimateFeeForAuthorization(options) {
|
|
5826
|
+
const { authorization, programName, program, imports, edition } = options;
|
|
5827
|
+
if (!authorization) {
|
|
5828
|
+
throw new Error("Authorization must be provided if estimating fee for Authorization.");
|
|
5829
|
+
}
|
|
5830
|
+
const programSource = program ? program.toString() : await this.networkClient.getProgram(programName, edition);
|
|
5831
|
+
const programImports = imports ? imports : await this.networkClient.getProgramImports(programSource);
|
|
5832
|
+
console.log(JSON.stringify(programImports));
|
|
5833
|
+
if (Object.keys(programImports)) {
|
|
5834
|
+
return ProgramManager$1.estimateFeeForAuthorization(authorization, programSource, programImports, edition);
|
|
5835
|
+
}
|
|
5836
|
+
return ProgramManager$1.estimateFeeForAuthorization(authorization, programSource, imports, edition);
|
|
5837
|
+
}
|
|
5838
|
+
/**
|
|
5839
|
+
* Estimate the execution fee for an Aleo function.
|
|
5840
|
+
*
|
|
5841
|
+
* @param {FeeEstimateOptions} options Options for the fee estimate.
|
|
5842
|
+
*
|
|
5843
|
+
* @returns {Promise<bigint>} Execution fee in microcredits for the authorization.
|
|
5844
|
+
*
|
|
5845
|
+
* @example
|
|
5846
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
5847
|
+
*
|
|
5848
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
5849
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
5850
|
+
*
|
|
5851
|
+
* // Get the base fee in microcredits.
|
|
5852
|
+
* const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
|
|
5853
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
5854
|
+
*
|
|
5855
|
+
* console.log("Building fee authorization");
|
|
5856
|
+
*
|
|
5857
|
+
* // Build a credits.aleo/fee_public `Authorization`.
|
|
5858
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
|
|
5859
|
+
* programName: "credits.aleo",
|
|
5860
|
+
* functionName: "transfer_public",
|
|
5861
|
+
* });
|
|
5862
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
5863
|
+
*/
|
|
5864
|
+
async estimateExecutionFee(options) {
|
|
5865
|
+
const { functionName, programName, program, imports, edition } = options;
|
|
5866
|
+
if (!functionName) {
|
|
5867
|
+
throw new Error("Function name must be specified when estimating fee.");
|
|
5868
|
+
}
|
|
5869
|
+
const programSource = program ? program.toString() : await this.networkClient.getProgram(programName, edition);
|
|
5870
|
+
const programImports = imports ? imports : await this.networkClient.getProgramImports(programSource);
|
|
5871
|
+
if (Object.keys(programImports)) {
|
|
5872
|
+
return ProgramManager$1.estimateExecutionFee(programSource, functionName, programImports, edition);
|
|
5873
|
+
}
|
|
5874
|
+
return ProgramManager$1.estimateExecutionFee(programSource, functionName, imports, edition);
|
|
5875
|
+
}
|
|
5762
5876
|
// Internal utility function for getting a credits.aleo record
|
|
5763
5877
|
async getCreditsRecord(amount, nonces, record, params) {
|
|
5764
5878
|
try {
|