@provablehq/sdk 0.9.9 → 0.9.10-testnet-rc

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.
@@ -36,10 +36,11 @@ import { TransitionObject } from "./models/transition/transitionObject.js";
36
36
  import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
37
37
  import { OfflineKeyProvider, OfflineSearchParams } from "./offline-key-provider.js";
38
38
  import { BlockHeightSearch, NetworkRecordProvider, RecordProvider } from "./record-provider.js";
39
+ import { RecordScanner } from "./record-scanner.js";
39
40
  declare function initializeWasm(): Promise<void>;
40
41
  export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorizationOptions, AuthorizationOptions } from "./program-manager.js";
41
42
  export { logAndThrow } from "./utils.js";
42
- export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, Transaction, Transition, U8, U16, U32, U64, U128, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution, } from "./wasm.js";
43
+ export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, Transaction, Transition, U8, U16, U32, U64, U128, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, verifyFunctionExecution, } from "./wasm.js";
43
44
  export { initializeWasm };
44
- export { Key, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, VALID_TRANSFER_TYPES, } from "./constants.js";
45
- export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordSearchParams, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
45
+ export { Key, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, RECORD_DOMAIN, VALID_TRANSFER_TYPES, } from "./constants.js";
46
+ export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordSearchParams, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
@@ -1,6 +1,6 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
- import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Program, Plaintext, Transaction, ProvingRequest, Metadata, VerifyingKey, ProvingKey, RecordPlaintext, ProgramManager as ProgramManager$1, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
3
- export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
2
+ import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Program, Plaintext, Transaction, ProvingRequest, Metadata, VerifyingKey, ProvingKey, RecordPlaintext, Field, Poseidon4, ProgramManager as ProgramManager$1, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
3
+ export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
4
4
 
5
5
  /**
6
6
  * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
@@ -491,7 +491,7 @@ class AleoNetworkClient {
491
491
  else {
492
492
  this.headers = {
493
493
  // This is replaced by the actual version by a Rollup plugin
494
- "X-Aleo-SDK-Version": "0.9.9",
494
+ "X-Aleo-SDK-Version": "0.9.10-testnet-rc",
495
495
  "X-Aleo-environment": environment(),
496
496
  };
497
497
  }
@@ -2044,6 +2044,7 @@ const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
2044
2044
  "transfer_public_to_private",
2045
2045
  "transferPublicToPrivate",
2046
2046
  ]);
2047
+ const RECORD_DOMAIN = "RecordScannerV0";
2047
2048
 
2048
2049
  /**
2049
2050
  * AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
@@ -2355,6 +2356,22 @@ class AleoKeyProvider {
2355
2356
  throw new Error("Invalid visibility type");
2356
2357
  }
2357
2358
  }
2359
+ /**
2360
+ * Returns the proving and verifying keys for the transfer_public function.
2361
+ *
2362
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the transfer_public function
2363
+ */
2364
+ async transferPublicKeys() {
2365
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
2366
+ }
2367
+ /**
2368
+ * Returns the proving and verifying keys for the inclusion proof.
2369
+ *
2370
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the inclusion proof.
2371
+ */
2372
+ async inclusionKeys() {
2373
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.inclusion);
2374
+ }
2358
2375
  /**
2359
2376
  * Returns the proving and verifying keys for the join function in the credits.aleo program
2360
2377
  *
@@ -2771,6 +2788,15 @@ class OfflineKeyProvider {
2771
2788
  return this.functionKeys(OfflineSearchParams.feePublicKeyParams());
2772
2789
  }
2773
2790
  ;
2791
+ /**
2792
+ * Get the inclusion prover keys from. The keys must be cached prior to calling this method for it to work.
2793
+ *
2794
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the inclusion prover
2795
+ */
2796
+ inclusionKeys() {
2797
+ return this.functionKeys(OfflineSearchParams.inclusionKeyParams());
2798
+ }
2799
+ ;
2774
2800
  /**
2775
2801
  * Get join function keys from the credits.aleo program. The keys must be cached prior to calling this
2776
2802
  * method for it to work.
@@ -2903,6 +2929,21 @@ class OfflineKeyProvider {
2903
2929
  throw new Error("Attempted to insert invalid proving keys for fee_public");
2904
2930
  }
2905
2931
  }
2932
+ /**
2933
+ * Insert the proving and verifying keys for the inclusion prover into the cache. Only the proving key needs
2934
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
2935
+ * that the keys match the expected checksum for the inclusion prover.
2936
+ *
2937
+ * @param provingKey
2938
+ */
2939
+ insertInclusionKeys(provingKey) {
2940
+ if (provingKey.isInclusionProver()) {
2941
+ this.cache.set(CREDITS_PROGRAM_KEYS.inclusion.locator, [provingKey.toBytes(), VerifyingKey.inclusionVerifier().toBytes()]);
2942
+ }
2943
+ else {
2944
+ throw new Error("Attempted to insert invalid proving keys for the inclusion prover");
2945
+ }
2946
+ }
2906
2947
  /**
2907
2948
  * Insert the proving and verifying keys for the join function into the cache. Only the proving key needs
2908
2949
  * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
@@ -3236,6 +3277,316 @@ class BlockHeightSearch {
3236
3277
  }
3237
3278
  }
3238
3279
 
3280
+ /**
3281
+ * RecordScanner is a RecordProvider implementation that uses the record scanner service to find records.
3282
+ *
3283
+ * @example
3284
+ * const account = new Account({ privateKey: 'APrivateKey1...' });
3285
+ *
3286
+ * const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });
3287
+ * recordScanner.setAccount(account);
3288
+ * recordScanner.setApiKey("your-api-key");
3289
+ * const uuid = await recordScanner.register(0);
3290
+ *
3291
+ * const filter = {
3292
+ * uuid,
3293
+ * filter: {
3294
+ * program: "credits.aleo",
3295
+ * records: ["credits"],
3296
+ * },
3297
+ * responseFilter: {
3298
+ * commitment: true,
3299
+ * owner: true,
3300
+ * tag: true,
3301
+ * tag?: boolean;
3302
+ * sender: true,
3303
+ * spent: true,
3304
+ * record_ciphertext: true,
3305
+ * block_height: true;
3306
+ * block_timestamp: true;
3307
+ * output_index: true;
3308
+ * record_name: true;
3309
+ * function_name: true;
3310
+ * program_name: true;
3311
+ * transition_id: true;
3312
+ * transaction_id: true;
3313
+ * transaction_index: true;
3314
+ * transition_index: true;
3315
+ * },
3316
+ * unspent: true,
3317
+ * };
3318
+ *
3319
+ * const records = await recordScanner.findRecords(filter);
3320
+ */
3321
+ class RecordScanner {
3322
+ url;
3323
+ apiKey;
3324
+ uuid;
3325
+ constructor(options) {
3326
+ this.url = options.url;
3327
+ this.apiKey = typeof options.apiKey === "string" ? { header: "X-Provable-API-Key", value: options.apiKey } : options.apiKey;
3328
+ }
3329
+ /**
3330
+ * Set the API key to use for the record scanner.
3331
+ *
3332
+ * @param {string} apiKey The API key to use for the record scanner.
3333
+ */
3334
+ async setApiKey(apiKey) {
3335
+ this.apiKey = typeof apiKey === "string" ? { header: "X-Provable-API-Key", value: apiKey } : apiKey;
3336
+ }
3337
+ /**
3338
+ * Set the UUID to use for the record scanner.
3339
+ *
3340
+ * @param {Field} uuid The UUID to use for the record scanner.
3341
+ */
3342
+ async setUuid(uuidOrViewKey) {
3343
+ this.uuid = uuidOrViewKey instanceof ViewKey ? this.computeUUID(uuidOrViewKey) : uuidOrViewKey;
3344
+ }
3345
+ /**
3346
+ * Register the account with the record scanner service.
3347
+ *
3348
+ * @param {number} startBlock The block height to start scanning from.
3349
+ * @returns {Promise<RegistrationResponse>} The response from the record scanner service.
3350
+ */
3351
+ async register(viewKey, startBlock) {
3352
+ try {
3353
+ let request = {
3354
+ view_key: viewKey.to_string(),
3355
+ start: startBlock,
3356
+ };
3357
+ const response = await this.request(new Request(`${this.url}/register`, {
3358
+ method: "POST",
3359
+ headers: { "Content-Type": "application/json" },
3360
+ body: JSON.stringify(request),
3361
+ }));
3362
+ const data = await response.json();
3363
+ this.uuid = data.uuid;
3364
+ return data;
3365
+ }
3366
+ catch (error) {
3367
+ console.error(`Failed to register view key: ${error}`);
3368
+ throw error;
3369
+ }
3370
+ }
3371
+ /**
3372
+ * Get encrypted records from the record scanner service.
3373
+ *
3374
+ * @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
3375
+ * @returns {Promise<EncryptedRecord[]>} The encrypted records.
3376
+ */
3377
+ async encryptedRecords(recordsFilter) {
3378
+ try {
3379
+ const response = await this.request(new Request(`${this.url}/records/encrypted`, {
3380
+ method: "POST",
3381
+ headers: { "Content-Type": "application/json" },
3382
+ body: JSON.stringify(recordsFilter),
3383
+ }));
3384
+ return await response.json();
3385
+ }
3386
+ catch (error) {
3387
+ console.error(`Failed to get encrypted records: ${error}`);
3388
+ throw error;
3389
+ }
3390
+ }
3391
+ /**
3392
+ * Check if a list of serial numbers exist in the record scanner service.
3393
+ *
3394
+ * @param {string[]} serialNumbers The serial numbers to check.
3395
+ * @returns {Promise<Record<string, boolean>>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
3396
+ */
3397
+ async checkSerialNumbers(serialNumbers) {
3398
+ try {
3399
+ const response = await this.request(new Request(`${this.url}/records/sns`, {
3400
+ method: "POST",
3401
+ headers: { "Content-Type": "application/json" },
3402
+ body: JSON.stringify(serialNumbers),
3403
+ }));
3404
+ return await response.json();
3405
+ }
3406
+ catch (error) {
3407
+ console.error(`Failed to check if serial numbers exist: ${error}`);
3408
+ throw error;
3409
+ }
3410
+ }
3411
+ /**
3412
+ * Check if a list of tags exist in the record scanner service.
3413
+ *
3414
+ * @param {string[]} tags The tags to check.
3415
+ * @returns {Promise<Record<string, boolean>>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
3416
+ */
3417
+ async checkTags(tags) {
3418
+ try {
3419
+ const response = await this.request(new Request(`${this.url}/records/tags`, {
3420
+ method: "POST",
3421
+ headers: { "Content-Type": "application/json" },
3422
+ body: JSON.stringify(tags),
3423
+ }));
3424
+ return await response.json();
3425
+ }
3426
+ catch (error) {
3427
+ console.error(`Failed to check if tags exist: ${error}`);
3428
+ throw error;
3429
+ }
3430
+ }
3431
+ /**
3432
+ * Check the status of a record scanner indexing job.
3433
+ *
3434
+ * @param {string} jobId The job id to check.
3435
+ * @returns {Promise<StatusResponse>} The status of the job.
3436
+ */
3437
+ async checkStatus() {
3438
+ try {
3439
+ const response = await this.request(new Request(`${this.url}/status`, {
3440
+ method: "POST",
3441
+ headers: { "Content-Type": "application/json" },
3442
+ body: JSON.stringify(this.uuid?.toString()),
3443
+ }));
3444
+ return await response.json();
3445
+ }
3446
+ catch (error) {
3447
+ console.error(`Failed to check status of job: ${error}`);
3448
+ throw error;
3449
+ }
3450
+ }
3451
+ /**
3452
+ * Find a record in the record scanner service.
3453
+ *
3454
+ * @param {OwnedFilter} searchParameters The filter to use to find the record.
3455
+ * @returns {Promise<OwnedRecord>} The record.
3456
+ */
3457
+ async findRecord(searchParameters) {
3458
+ try {
3459
+ const records = await this.findRecords(searchParameters);
3460
+ if (records.length > 0) {
3461
+ return records[0];
3462
+ }
3463
+ throw new Error("Record not found");
3464
+ }
3465
+ catch (error) {
3466
+ console.error(`Failed to find record: ${error}`);
3467
+ throw error;
3468
+ }
3469
+ }
3470
+ /**
3471
+ * Find records in the record scanner service.
3472
+ *
3473
+ * @param {OwnedFilter} filter The filter to use to find the records.
3474
+ * @returns {Promise<OwnedRecord[]>} The records.
3475
+ */
3476
+ async findRecords(filter) {
3477
+ if (!this.uuid) {
3478
+ throw new Error("You are using the RecordScanner implementation of the RecordProvider. No account has been registered with the RecordScanner which is required to use the findRecords method. Please set an with the setAccount method before calling the findRecords method again.");
3479
+ }
3480
+ filter.uuid = this.uuid?.toString();
3481
+ try {
3482
+ const response = await this.request(new Request(`${this.url}/records/owned`, {
3483
+ method: "POST",
3484
+ headers: { "Content-Type": "application/json" },
3485
+ body: JSON.stringify(filter),
3486
+ }));
3487
+ return await response.json();
3488
+ }
3489
+ catch (error) {
3490
+ console.error(`Failed to get owned records: ${error}`);
3491
+ throw error;
3492
+ }
3493
+ }
3494
+ /**
3495
+ * Find a credits record in the record scanner service.
3496
+ *
3497
+ * @param {number} microcredits The amount of microcredits to find.
3498
+ * @param {OwnedFilter} searchParameters The filter to use to find the record.
3499
+ * @returns {Promise<OwnedRecord>} The record.
3500
+ */
3501
+ async findCreditsRecord(microcredits, searchParameters) {
3502
+ try {
3503
+ const records = await this.findRecords({
3504
+ decrypt: true,
3505
+ unspent: searchParameters.unspent,
3506
+ filter: {
3507
+ start: searchParameters.filter?.start ?? 0,
3508
+ program: "credits.aleo",
3509
+ record: "credits",
3510
+ },
3511
+ uuid: this.uuid?.toString(),
3512
+ });
3513
+ const record = records.find(record => {
3514
+ const plaintext = RecordPlaintext.fromString(record.record_plaintext ?? '');
3515
+ const amountStr = plaintext.getMember("microcredits").toString();
3516
+ const amount = parseInt(amountStr.replace("u64", ""));
3517
+ return amount >= microcredits;
3518
+ });
3519
+ if (!record) {
3520
+ throw new Error(`No records found matching the supplied search filter:\n${JSON.stringify(searchParameters, null, 2)}`);
3521
+ }
3522
+ return record;
3523
+ }
3524
+ catch (error) {
3525
+ console.error(`Failed to find credits record: ${error}`);
3526
+ throw error;
3527
+ }
3528
+ }
3529
+ /**
3530
+ * Find credits records using a record scanning service.
3531
+ *
3532
+ * @param {number[]} microcreditAmounts The amounts of microcredits to find.
3533
+ * @param {OwnedFilter} searchParameters The filter to use to find the records.
3534
+ * @returns {Promise<OwnedRecord[]>} The records
3535
+ */
3536
+ async findCreditsRecords(microcreditAmounts, searchParameters) {
3537
+ try {
3538
+ const records = await this.findRecords({
3539
+ decrypt: true,
3540
+ unspent: searchParameters.unspent,
3541
+ filter: {
3542
+ start: searchParameters.filter?.start ?? 0,
3543
+ program: "credits.aleo",
3544
+ record: "credits",
3545
+ },
3546
+ uuid: this.uuid?.toString(),
3547
+ });
3548
+ return records.filter(record => {
3549
+ const plaintext = RecordPlaintext.fromString(record.record_plaintext ?? '');
3550
+ const amount = plaintext.getMember("microcredits").toString();
3551
+ return microcreditAmounts.includes(parseInt(amount.replace("u64", "")));
3552
+ });
3553
+ }
3554
+ catch (error) {
3555
+ console.error(`Failed to find credits records: ${error}`);
3556
+ throw error;
3557
+ }
3558
+ }
3559
+ /**
3560
+ * Wrapper function to make a request to the record scanner service and handle any errors.
3561
+ *
3562
+ * @param {Request} req The request to make.
3563
+ * @returns {Promise<Response>} The response.
3564
+ */
3565
+ async request(req) {
3566
+ try {
3567
+ if (this.apiKey) {
3568
+ req.headers.set(this.apiKey.header, this.apiKey.value);
3569
+ }
3570
+ const response = await fetch(req);
3571
+ if (!response.ok) {
3572
+ throw new Error(await response.text() ?? `Request to ${req.url} failed with status ${response.status}`);
3573
+ }
3574
+ return response;
3575
+ }
3576
+ catch (error) {
3577
+ console.error(`Failed to make request to ${req.url}: ${error}`);
3578
+ throw error;
3579
+ }
3580
+ }
3581
+ computeUUID(vk) {
3582
+ // Construct the material needed for the Poseidon oracle.
3583
+ const inputs = [Field.newDomainSeparator(RECORD_DOMAIN), vk.toField(), Field.one()];
3584
+ // Calculate the uuid.
3585
+ const hasher = new Poseidon4();
3586
+ return hasher.hash(inputs);
3587
+ }
3588
+ }
3589
+
3239
3590
  /**
3240
3591
  * The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
3241
3592
  */
@@ -3245,6 +3596,7 @@ class ProgramManager {
3245
3596
  host;
3246
3597
  networkClient;
3247
3598
  recordProvider;
3599
+ inclusionKeysLoaded = false;
3248
3600
  /** Create a new instance of the ProgramManager
3249
3601
  *
3250
3602
  * @param { string | undefined } host A host uri running the official Aleo API
@@ -3610,6 +3962,17 @@ class ProgramManager {
3610
3962
  logAndThrow(`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.`);
3611
3963
  }
3612
3964
  }
3965
+ if (offlineQuery && !this.inclusionKeysLoaded) {
3966
+ try {
3967
+ const inclusionKeys = await this.keyProvider.inclusionKeys();
3968
+ ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
3969
+ this.inclusionKeysLoaded = true;
3970
+ console.log("Successfully loaded inclusion key");
3971
+ }
3972
+ catch {
3973
+ logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
3974
+ }
3975
+ }
3613
3976
  // Build an execution transaction
3614
3977
  return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery, edition);
3615
3978
  }
@@ -4116,6 +4479,18 @@ class ProgramManager {
4116
4479
  catch (e) {
4117
4480
  logAndThrow("Records provided are not valid. Please ensure they are valid plaintext records.");
4118
4481
  }
4482
+ // Load the inclusion prover offline.
4483
+ if (offlineQuery && !this.inclusionKeysLoaded) {
4484
+ try {
4485
+ const inclusionKeys = await this.keyProvider.inclusionKeys();
4486
+ ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
4487
+ this.inclusionKeysLoaded = true;
4488
+ console.log("Successfully loaded inclusion key");
4489
+ }
4490
+ catch {
4491
+ logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
4492
+ }
4493
+ }
4119
4494
  // Build an execution transaction and submit it to the network
4120
4495
  const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
4121
4496
  // Check if the account has sufficient credits to pay for the transaction
@@ -4180,6 +4555,18 @@ class ProgramManager {
4180
4555
  catch (e) {
4181
4556
  logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
4182
4557
  }
4558
+ // Load the inclusion prover offline.
4559
+ if (offlineQuery && !this.inclusionKeysLoaded) {
4560
+ try {
4561
+ const inclusionKeys = await this.keyProvider.inclusionKeys();
4562
+ ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
4563
+ this.inclusionKeysLoaded = true;
4564
+ console.log("Successfully loaded inclusion key");
4565
+ }
4566
+ catch {
4567
+ logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
4568
+ }
4569
+ }
4183
4570
  // Build an execution transaction and submit it to the network
4184
4571
  const tx = await ProgramManager$1.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey, offlineQuery);
4185
4572
  return await this.networkClient.submitTransaction(tx);
@@ -4299,6 +4686,20 @@ class ProgramManager {
4299
4686
  catch (e) {
4300
4687
  logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
4301
4688
  }
4689
+ // Load the inclusion prover offline.
4690
+ if (offlineQuery && !this.inclusionKeysLoaded) {
4691
+ const inclusionKeys = await this.keyProvider.inclusionKeys();
4692
+ ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
4693
+ try {
4694
+ const inclusionKeys = await this.keyProvider.inclusionKeys();
4695
+ ProgramManager$1.loadInclusionProver(inclusionKeys[0]);
4696
+ this.inclusionKeysLoaded = true;
4697
+ console.log("Successfully loaded inclusion key");
4698
+ }
4699
+ catch {
4700
+ logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
4701
+ }
4702
+ }
4302
4703
  // Build an execution transaction
4303
4704
  return await ProgramManager$1.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
4304
4705
  }
@@ -4469,6 +4870,7 @@ class ProgramManager {
4469
4870
  privateFee,
4470
4871
  inputs,
4471
4872
  keySearchParams,
4873
+ program,
4472
4874
  ...additionalOptions,
4473
4875
  };
4474
4876
  return await this.buildExecutionTransaction(executeOptions);
@@ -4572,6 +4974,7 @@ class ProgramManager {
4572
4974
  privateFee,
4573
4975
  inputs,
4574
4976
  keySearchParams,
4977
+ program,
4575
4978
  ...additionalOptions,
4576
4979
  };
4577
4980
  return await this.buildExecutionTransaction(executeOptions);
@@ -4666,6 +5069,7 @@ class ProgramManager {
4666
5069
  privateFee,
4667
5070
  inputs,
4668
5071
  keySearchParams,
5072
+ program,
4669
5073
  ...additionalOptions,
4670
5074
  };
4671
5075
  return this.buildExecutionTransaction(executeOptions);
@@ -4763,6 +5167,7 @@ class ProgramManager {
4763
5167
  privateFee,
4764
5168
  inputs,
4765
5169
  keySearchParams,
5170
+ program,
4766
5171
  ...additionalOptions,
4767
5172
  };
4768
5173
  // Check if the account has sufficient credits to pay for the transaction
@@ -4856,7 +5261,7 @@ class ProgramManager {
4856
5261
  proverUri: CREDITS_PROGRAM_KEYS.set_validator_state.prover,
4857
5262
  verifierUri: CREDITS_PROGRAM_KEYS.set_validator_state.verifier,
4858
5263
  cacheKey: "credits.aleo/set_validator_state",
4859
- }), ...additionalOptions } = options;
5264
+ }), program = this.creditsProgram(), ...additionalOptions } = options;
4860
5265
  const executeOptions = {
4861
5266
  programName,
4862
5267
  functionName,
@@ -4864,6 +5269,7 @@ class ProgramManager {
4864
5269
  privateFee,
4865
5270
  inputs,
4866
5271
  keySearchParams,
5272
+ program,
4867
5273
  ...additionalOptions,
4868
5274
  };
4869
5275
  return await this.buildExecutionTransaction(executeOptions);
@@ -4966,6 +5372,15 @@ class ProgramManager {
4966
5372
  return false;
4967
5373
  }
4968
5374
  }
5375
+ /**
5376
+ * Set the inclusion key bytes.
5377
+ *
5378
+ * @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
5379
+ * @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
5380
+ * @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
5381
+ * @returns {boolean} True if the proof is valid, false otherwise
5382
+ *
5383
+
4969
5384
  /**
4970
5385
  * Create a program object from a program's source code
4971
5386
  *
@@ -5039,5 +5454,5 @@ async function initializeWasm() {
5039
5454
  console.warn("initializeWasm is deprecated, you no longer need to use it");
5040
5455
  }
5041
5456
 
5042
- export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KEY_STORE, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, VALID_TRANSFER_TYPES, initializeWasm, logAndThrow };
5457
+ export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KEY_STORE, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, RECORD_DOMAIN, RecordScanner, VALID_TRANSFER_TYPES, initializeWasm, logAndThrow };
5043
5458
  //# sourceMappingURL=browser.js.map