@provablehq/sdk 0.9.7 → 0.9.8
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
CHANGED
|
@@ -478,18 +478,20 @@ class AleoNetworkClient {
|
|
|
478
478
|
headers;
|
|
479
479
|
account;
|
|
480
480
|
ctx;
|
|
481
|
+
verboseErrors;
|
|
481
482
|
network;
|
|
482
483
|
constructor(host, options) {
|
|
483
484
|
this.host = host + "/mainnet";
|
|
484
485
|
this.network = "mainnet";
|
|
485
486
|
this.ctx = {};
|
|
487
|
+
this.verboseErrors = true;
|
|
486
488
|
if (options && options.headers) {
|
|
487
489
|
this.headers = options.headers;
|
|
488
490
|
}
|
|
489
491
|
else {
|
|
490
492
|
this.headers = {
|
|
491
493
|
// This is replaced by the actual version by a Rollup plugin
|
|
492
|
-
"X-Aleo-SDK-Version": "0.9.
|
|
494
|
+
"X-Aleo-SDK-Version": "0.9.8",
|
|
493
495
|
"X-Aleo-environment": environment(),
|
|
494
496
|
};
|
|
495
497
|
}
|
|
@@ -521,7 +523,6 @@ class AleoNetworkClient {
|
|
|
521
523
|
* Set a new host for the networkClient
|
|
522
524
|
*
|
|
523
525
|
* @param {string} host The address of a node hosting the Aleo API
|
|
524
|
-
* @param host
|
|
525
526
|
*
|
|
526
527
|
* @example
|
|
527
528
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
@@ -535,6 +536,22 @@ class AleoNetworkClient {
|
|
|
535
536
|
setHost(host) {
|
|
536
537
|
this.host = host + "/mainnet";
|
|
537
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Set verbose errors to true or false for the `AleoNetworkClient`. When set to true, if `submitTransaction` fails, the failure responses will report descriptive information as to why the transaction failed.
|
|
541
|
+
*
|
|
542
|
+
* @param {boolean} verboseErrors Set verbose error mode to true or false for the AleoNetworkClient.
|
|
543
|
+
* @example
|
|
544
|
+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
545
|
+
*
|
|
546
|
+
* // Create a networkClient
|
|
547
|
+
* const networkClient = new AleoNetworkClient();
|
|
548
|
+
*
|
|
549
|
+
* // Set debug mode to true
|
|
550
|
+
* networkClient.setVerboseTransactionErrors(true);
|
|
551
|
+
**/
|
|
552
|
+
setVerboseErrors(verboseErrors) {
|
|
553
|
+
this.verboseErrors = verboseErrors;
|
|
554
|
+
}
|
|
538
555
|
/**
|
|
539
556
|
* Set a header in the `AleoNetworkClient`s header map
|
|
540
557
|
*
|
|
@@ -1773,7 +1790,8 @@ class AleoNetworkClient {
|
|
|
1773
1790
|
? transaction.toString()
|
|
1774
1791
|
: transaction;
|
|
1775
1792
|
try {
|
|
1776
|
-
const
|
|
1793
|
+
const endpoint = this.verboseErrors ? "transaction/broadcast?check_transaction=true" : "transaction/broadcast";
|
|
1794
|
+
const response = await retryWithBackoff(() => this._sendPost(`${this.host}/${endpoint}`, {
|
|
1777
1795
|
body: transactionString,
|
|
1778
1796
|
headers: Object.assign({}, { ...this.headers, "X-ALEO-METHOD": "submitTransaction" }, {
|
|
1779
1797
|
"Content-Type": "application/json",
|
|
@@ -1820,32 +1838,35 @@ class AleoNetworkClient {
|
|
|
1820
1838
|
/**
|
|
1821
1839
|
* Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor.
|
|
1822
1840
|
*
|
|
1823
|
-
* @param {
|
|
1824
|
-
* @param {string} url - (Optional) The url of the proving service.
|
|
1841
|
+
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
|
|
1825
1842
|
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
|
|
1826
1843
|
*/
|
|
1827
|
-
async submitProvingRequest(
|
|
1828
|
-
const
|
|
1829
|
-
const provingRequestString = provingRequest instanceof ProvingRequest
|
|
1830
|
-
? provingRequest.toString()
|
|
1831
|
-
: provingRequest;
|
|
1844
|
+
async submitProvingRequest(options) {
|
|
1845
|
+
const proverUri = options.url ?? this.host;
|
|
1846
|
+
const provingRequestString = options.provingRequest instanceof ProvingRequest
|
|
1847
|
+
? options.provingRequest.toString()
|
|
1848
|
+
: options.provingRequest;
|
|
1849
|
+
// Build headers with proper auth fallback
|
|
1850
|
+
const headers = {
|
|
1851
|
+
...this.headers,
|
|
1852
|
+
"X-ALEO-METHOD": "submitProvingRequest",
|
|
1853
|
+
"Content-Type": "application/json"
|
|
1854
|
+
};
|
|
1855
|
+
// Add auth header based on what's available
|
|
1856
|
+
if (options.apiKey) {
|
|
1857
|
+
headers["X-Provable-API-Key"] = options.apiKey;
|
|
1858
|
+
}
|
|
1832
1859
|
try {
|
|
1833
|
-
const response = await retryWithBackoff(() => post(
|
|
1860
|
+
const response = await retryWithBackoff(() => post(`${proverUri}/prove`, {
|
|
1834
1861
|
body: provingRequestString,
|
|
1835
|
-
headers
|
|
1836
|
-
"Content-Type": "application/json",
|
|
1837
|
-
}),
|
|
1862
|
+
headers
|
|
1838
1863
|
}));
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
return parseJSON(text);
|
|
1842
|
-
}
|
|
1843
|
-
catch (error) {
|
|
1844
|
-
throw new Error(`Error posting proving request. Aleo network response: ${error.message}`);
|
|
1845
|
-
}
|
|
1864
|
+
const responseText = await response.text();
|
|
1865
|
+
return parseJSON(responseText);
|
|
1846
1866
|
}
|
|
1847
1867
|
catch (error) {
|
|
1848
|
-
|
|
1868
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
1869
|
+
throw new Error(`Failed to submit proving request: ${errorMessage}`);
|
|
1849
1870
|
}
|
|
1850
1871
|
}
|
|
1851
1872
|
/**
|
|
@@ -3490,11 +3511,12 @@ class ProgramManager {
|
|
|
3490
3511
|
*/
|
|
3491
3512
|
async buildExecutionTransaction(options) {
|
|
3492
3513
|
// Destructure the options object to access the parameters
|
|
3493
|
-
const {
|
|
3514
|
+
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, keySearchParams, privateKey, offlineQuery, } = options;
|
|
3494
3515
|
let feeRecord = options.feeRecord;
|
|
3495
3516
|
let provingKey = options.provingKey;
|
|
3496
3517
|
let verifyingKey = options.verifyingKey;
|
|
3497
3518
|
let program = options.program;
|
|
3519
|
+
let programName = options.programName;
|
|
3498
3520
|
let imports = options.imports;
|
|
3499
3521
|
let edition = options.edition;
|
|
3500
3522
|
// Ensure the function exists on the network
|
|
@@ -3509,6 +3531,10 @@ class ProgramManager {
|
|
|
3509
3531
|
else if (program instanceof Program) {
|
|
3510
3532
|
program = program.toString();
|
|
3511
3533
|
}
|
|
3534
|
+
// Get the program name if it is not provided in the parameters.
|
|
3535
|
+
if (programName === undefined) {
|
|
3536
|
+
programName = Program.fromString(program).id();
|
|
3537
|
+
}
|
|
3512
3538
|
if (edition == undefined) {
|
|
3513
3539
|
try {
|
|
3514
3540
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
@@ -3599,9 +3625,10 @@ class ProgramManager {
|
|
|
3599
3625
|
*/
|
|
3600
3626
|
async buildAuthorization(options) {
|
|
3601
3627
|
// Destructure the options object to access the parameters.
|
|
3602
|
-
const {
|
|
3628
|
+
const { functionName, inputs, } = options;
|
|
3603
3629
|
const privateKey = options.privateKey;
|
|
3604
3630
|
let program = options.programSource;
|
|
3631
|
+
let programName = options.programName;
|
|
3605
3632
|
let imports = options.programImports;
|
|
3606
3633
|
let edition = options.edition;
|
|
3607
3634
|
// Ensure the function exists on the network.
|
|
@@ -3616,6 +3643,10 @@ class ProgramManager {
|
|
|
3616
3643
|
else if (program instanceof Program) {
|
|
3617
3644
|
program = program.toString();
|
|
3618
3645
|
}
|
|
3646
|
+
// Get the program name if it is not provided in the parameters.
|
|
3647
|
+
if (programName === undefined) {
|
|
3648
|
+
programName = Program.fromString(program).id();
|
|
3649
|
+
}
|
|
3619
3650
|
// Get the private key from the account if it is not provided in the parameters.
|
|
3620
3651
|
let executionPrivateKey = privateKey;
|
|
3621
3652
|
if (typeof privateKey === "undefined" &&
|
|
@@ -3677,9 +3708,10 @@ class ProgramManager {
|
|
|
3677
3708
|
*/
|
|
3678
3709
|
async buildAuthorizationUnchecked(options) {
|
|
3679
3710
|
// Destructure the options object to access the parameters.
|
|
3680
|
-
const {
|
|
3711
|
+
const { functionName, inputs, } = options;
|
|
3681
3712
|
const privateKey = options.privateKey;
|
|
3682
3713
|
let program = options.programSource;
|
|
3714
|
+
let programName = options.programName;
|
|
3683
3715
|
let imports = options.programImports;
|
|
3684
3716
|
let edition = options.edition;
|
|
3685
3717
|
// Ensure the function exists on the network.
|
|
@@ -3694,6 +3726,10 @@ class ProgramManager {
|
|
|
3694
3726
|
else if (program instanceof Program) {
|
|
3695
3727
|
program = program.toString();
|
|
3696
3728
|
}
|
|
3729
|
+
// Get the program name if it is not provided in the parameters.
|
|
3730
|
+
if (programName === undefined) {
|
|
3731
|
+
programName = Program.fromString(program).id();
|
|
3732
|
+
}
|
|
3697
3733
|
// Get the private key from the account if it is not provided in the parameters.
|
|
3698
3734
|
let executionPrivateKey = privateKey;
|
|
3699
3735
|
if (typeof privateKey === "undefined" &&
|
|
@@ -3759,9 +3795,10 @@ class ProgramManager {
|
|
|
3759
3795
|
*/
|
|
3760
3796
|
async provingRequest(options) {
|
|
3761
3797
|
// Destructure the options object to access the parameters.
|
|
3762
|
-
const {
|
|
3798
|
+
const { functionName, baseFee, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
3763
3799
|
const privateKey = options.privateKey;
|
|
3764
3800
|
let program = options.programSource;
|
|
3801
|
+
let programName = options.programName;
|
|
3765
3802
|
let feeRecord = options.feeRecord;
|
|
3766
3803
|
let imports = options.programImports;
|
|
3767
3804
|
let edition = options.edition;
|
|
@@ -3777,6 +3814,10 @@ class ProgramManager {
|
|
|
3777
3814
|
else if (program instanceof Program) {
|
|
3778
3815
|
program = program.toString();
|
|
3779
3816
|
}
|
|
3817
|
+
// Get the program name if it is not provided in the parameters.
|
|
3818
|
+
if (programName === undefined) {
|
|
3819
|
+
programName = Program.fromString(program).id();
|
|
3820
|
+
}
|
|
3780
3821
|
if (edition == undefined) {
|
|
3781
3822
|
try {
|
|
3782
3823
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|