@provablehq/sdk 0.9.5 → 0.9.6

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.
@@ -33,7 +33,7 @@ import { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchP
33
33
  declare function initializeWasm(): Promise<void>;
34
34
  export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorizationOptions, AuthorizationOptions } from "./program-manager.js";
35
35
  export { logAndThrow } from "./utils.js";
36
- export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, 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";
36
+ 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";
37
37
  export { initializeWasm };
38
38
  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";
39
39
  export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordProvider, RecordSearchParams, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
@@ -1,6 +1,6 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
2
  import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Program, Plaintext, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
3
- export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, 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';
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';
4
4
 
5
5
  /**
6
6
  * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
@@ -489,7 +489,7 @@ class AleoNetworkClient {
489
489
  else {
490
490
  this.headers = {
491
491
  // This is replaced by the actual version by a Rollup plugin
492
- "X-Aleo-SDK-Version": "0.9.5",
492
+ "X-Aleo-SDK-Version": "0.9.6",
493
493
  "X-Aleo-environment": environment(),
494
494
  };
495
495
  }
@@ -1244,7 +1244,8 @@ class AleoNetworkClient {
1244
1244
  async getLatestProgramEdition(programId) {
1245
1245
  try {
1246
1246
  this.ctx = { "X-ALEO-METHOD": "getLatestProgramEdition" };
1247
- return await this.fetchData("/program/" + programId + "/latest_edition");
1247
+ const raw = await this.fetchRaw("/program/" + programId + "/latest_edition");
1248
+ return JSON.parse(raw);
1248
1249
  }
1249
1250
  catch (error) {
1250
1251
  throw new Error(`Error fetching program ${programId}: ${error}`);
@@ -3464,6 +3465,7 @@ class ProgramManager {
3464
3465
  let verifyingKey = options.verifyingKey;
3465
3466
  let program = options.program;
3466
3467
  let imports = options.imports;
3468
+ let edition = options.edition;
3467
3469
  // Ensure the function exists on the network
3468
3470
  if (program === undefined) {
3469
3471
  try {
@@ -3476,6 +3478,15 @@ class ProgramManager {
3476
3478
  else if (program instanceof Program) {
3477
3479
  program = program.toString();
3478
3480
  }
3481
+ if (edition == undefined) {
3482
+ try {
3483
+ edition = await this.networkClient.getLatestProgramEdition(programName);
3484
+ }
3485
+ catch (e) {
3486
+ console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 1.`);
3487
+ edition = 1;
3488
+ }
3489
+ }
3479
3490
  // Get the private key from the account if it is not provided in the parameters
3480
3491
  let executionPrivateKey = privateKey;
3481
3492
  if (typeof privateKey === "undefined" &&
@@ -3525,7 +3536,7 @@ class ProgramManager {
3525
3536
  }
3526
3537
  }
3527
3538
  // Build an execution transaction
3528
- return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
3539
+ return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery, edition);
3529
3540
  }
3530
3541
  /**
3531
3542
  * Builds a SnarkVM `Authorization` for a specific function.
@@ -3561,6 +3572,7 @@ class ProgramManager {
3561
3572
  const privateKey = options.privateKey;
3562
3573
  let program = options.programSource;
3563
3574
  let imports = options.programImports;
3575
+ let edition = options.edition;
3564
3576
  // Ensure the function exists on the network.
3565
3577
  if (program === undefined) {
3566
3578
  try {
@@ -3582,6 +3594,15 @@ class ProgramManager {
3582
3594
  if (typeof executionPrivateKey === "undefined") {
3583
3595
  throw "No private key provided and no private key set in the ProgramManager";
3584
3596
  }
3597
+ if (edition == undefined) {
3598
+ try {
3599
+ edition = await this.networkClient.getLatestProgramEdition(programName);
3600
+ }
3601
+ catch (e) {
3602
+ console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 1.`);
3603
+ edition = 1;
3604
+ }
3605
+ }
3585
3606
  // Resolve the program imports if they exist.
3586
3607
  const numberOfImports = Program.fromString(program).getImports().length;
3587
3608
  if (numberOfImports > 0 && !imports) {
@@ -3593,7 +3614,7 @@ class ProgramManager {
3593
3614
  }
3594
3615
  }
3595
3616
  // Build and return an `Authorization` for the desired function.
3596
- return await ProgramManager$1.authorize(executionPrivateKey, program, functionName, inputs, imports);
3617
+ return await ProgramManager$1.authorize(executionPrivateKey, program, functionName, inputs, imports, edition);
3597
3618
  }
3598
3619
  /**
3599
3620
  * Builds a SnarkVM `Authorization` for a specific function without building a circuit first. This should be used when fast authorization generation is needed and the invoker is confident inputs are coorect.
@@ -3629,6 +3650,7 @@ class ProgramManager {
3629
3650
  const privateKey = options.privateKey;
3630
3651
  let program = options.programSource;
3631
3652
  let imports = options.programImports;
3653
+ let edition = options.edition;
3632
3654
  // Ensure the function exists on the network.
3633
3655
  if (program === undefined) {
3634
3656
  try {
@@ -3660,8 +3682,17 @@ class ProgramManager {
3660
3682
  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.`);
3661
3683
  }
3662
3684
  }
3685
+ if (edition == undefined) {
3686
+ try {
3687
+ edition = await this.networkClient.getLatestProgramEdition(programName);
3688
+ }
3689
+ catch (e) {
3690
+ console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 1.`);
3691
+ edition = 1;
3692
+ }
3693
+ }
3663
3694
  // Build and return an `Authorization` for the desired function.
3664
- return await ProgramManager$1.buildAuthorizationUnchecked(executionPrivateKey, program, functionName, inputs, imports);
3695
+ return await ProgramManager$1.buildAuthorizationUnchecked(executionPrivateKey, program, functionName, inputs, imports, edition);
3665
3696
  }
3666
3697
  /**
3667
3698
  * Builds a `ProvingRequest` for submission to a prover for execution.
@@ -3702,6 +3733,7 @@ class ProgramManager {
3702
3733
  let program = options.programSource;
3703
3734
  let feeRecord = options.feeRecord;
3704
3735
  let imports = options.programImports;
3736
+ let edition = options.edition;
3705
3737
  // Ensure the function exists on the network.
3706
3738
  if (program === undefined) {
3707
3739
  try {
@@ -3714,6 +3746,15 @@ class ProgramManager {
3714
3746
  else if (program instanceof Program) {
3715
3747
  program = program.toString();
3716
3748
  }
3749
+ if (edition == undefined) {
3750
+ try {
3751
+ edition = await this.networkClient.getLatestProgramEdition(programName);
3752
+ }
3753
+ catch (e) {
3754
+ console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 1.`);
3755
+ edition = 1;
3756
+ }
3757
+ }
3717
3758
  // Get the private key from the account if it is not provided in the parameters.
3718
3759
  let executionPrivateKey = privateKey;
3719
3760
  if (typeof privateKey === "undefined" &&
@@ -3743,7 +3784,7 @@ class ProgramManager {
3743
3784
  }
3744
3785
  }
3745
3786
  // Build and return the `ProvingRequest`.
3746
- return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName, inputs, baseFee, priorityFee, feeRecord, imports, broadcast, unchecked);
3787
+ return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName, inputs, baseFee, priorityFee, feeRecord, imports, broadcast, unchecked, edition);
3747
3788
  }
3748
3789
  /**
3749
3790
  * Builds a SnarkVM fee `Authorization` for `credits.aleo/fee_private` or `credits.aleo/fee_public`. If a record is provided `fee_private` will be executed, otherwise `fee_public` will be executed.
@@ -3874,7 +3915,7 @@ class ProgramManager {
3874
3915
  * const result = executionResponse.getOutputs();
3875
3916
  * assert(result === ["10u32"]);
3876
3917
  */
3877
- async run(program, function_name, inputs, proveExecution, imports, keySearchParams, provingKey, verifyingKey, privateKey, offlineQuery) {
3918
+ async run(program, function_name, inputs, proveExecution, imports, keySearchParams, provingKey, verifyingKey, privateKey, offlineQuery, edition) {
3878
3919
  // Get the private key from the account if it is not provided in the parameters
3879
3920
  let executionPrivateKey = privateKey;
3880
3921
  if (typeof privateKey === "undefined" &&
@@ -3897,7 +3938,7 @@ class ProgramManager {
3897
3938
  console.log("Running program offline");
3898
3939
  console.log("Proving key: ", provingKey);
3899
3940
  console.log("Verifying key: ", verifyingKey);
3900
- return ProgramManager$1.executeFunctionOffline(executionPrivateKey, program, function_name, inputs, proveExecution, false, imports, provingKey, verifyingKey, this.host, offlineQuery);
3941
+ return ProgramManager$1.executeFunctionOffline(executionPrivateKey, program, function_name, inputs, proveExecution, false, imports, provingKey, verifyingKey, this.host, offlineQuery, edition);
3901
3942
  }
3902
3943
  /**
3903
3944
  * Join two credits records into a single credits record