@provablehq/sdk 0.10.4 → 0.10.5-rc.1
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.cjs +102 -70
- package/dist/mainnet/browser.cjs.map +1 -1
- package/dist/mainnet/browser.js +103 -71
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/network-client.d.cts +8 -0
- package/dist/mainnet/network-client.d.ts +8 -0
- package/dist/mainnet/program-manager.d.cts +14 -0
- package/dist/mainnet/program-manager.d.ts +14 -0
- package/dist/mainnet/wasm.d.cts +1 -1
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/browser.cjs +102 -70
- package/dist/testnet/browser.cjs.map +1 -1
- package/dist/testnet/browser.js +103 -71
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/network-client.d.cts +8 -0
- package/dist/testnet/network-client.d.ts +8 -0
- package/dist/testnet/program-manager.d.cts +14 -0
- package/dist/testnet/program-manager.d.ts +14 -0
- package/dist/testnet/wasm.d.cts +1 -1
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +2 -2
package/dist/mainnet/browser.cjs
CHANGED
|
@@ -842,6 +842,7 @@ class AleoNetworkClient {
|
|
|
842
842
|
verboseErrors;
|
|
843
843
|
network;
|
|
844
844
|
transport;
|
|
845
|
+
hasCustomTransport;
|
|
845
846
|
apiKey;
|
|
846
847
|
consumerId;
|
|
847
848
|
jwtData;
|
|
@@ -856,6 +857,7 @@ class AleoNetworkClient {
|
|
|
856
857
|
this.ctx = {};
|
|
857
858
|
this.verboseErrors = true;
|
|
858
859
|
this.transport = options?.transport ?? defaultTransport;
|
|
860
|
+
this.hasCustomTransport = !!options?.transport;
|
|
859
861
|
if (options) {
|
|
860
862
|
if (options.headers) {
|
|
861
863
|
this.headers = options.headers;
|
|
@@ -863,7 +865,7 @@ class AleoNetworkClient {
|
|
|
863
865
|
else {
|
|
864
866
|
this.headers = {
|
|
865
867
|
// This is replaced by the actual version by a Rollup plugin
|
|
866
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
868
|
+
"X-Aleo-SDK-Version": "0.10.5-rc.1",
|
|
867
869
|
"X-Aleo-environment": environment(),
|
|
868
870
|
};
|
|
869
871
|
}
|
|
@@ -879,7 +881,7 @@ class AleoNetworkClient {
|
|
|
879
881
|
else {
|
|
880
882
|
this.headers = {
|
|
881
883
|
// This is replaced by the actual version by a Rollup plugin
|
|
882
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
884
|
+
"X-Aleo-SDK-Version": "0.10.5-rc.1",
|
|
883
885
|
"X-Aleo-environment": environment(),
|
|
884
886
|
};
|
|
885
887
|
}
|
|
@@ -1596,6 +1598,25 @@ class AleoNetworkClient {
|
|
|
1596
1598
|
this.ctx = {};
|
|
1597
1599
|
}
|
|
1598
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Returns state paths for the given record commitments.
|
|
1603
|
+
*
|
|
1604
|
+
* @param {string[]} commitments - Array of commitment field strings.
|
|
1605
|
+
* @returns {Promise<string[]>} Array of state path strings corresponding to the commitments.
|
|
1606
|
+
*/
|
|
1607
|
+
async getStatePaths(commitments) {
|
|
1608
|
+
try {
|
|
1609
|
+
this.ctx = { "X-ALEO-METHOD": "getStatePaths" };
|
|
1610
|
+
const csv = commitments.map(c => encodeURIComponent(c)).join(",");
|
|
1611
|
+
return await this.fetchData(`/statePaths?commitments=${csv}`);
|
|
1612
|
+
}
|
|
1613
|
+
catch (error) {
|
|
1614
|
+
throw new Error(`Error fetching state paths for commitments: ${error}`);
|
|
1615
|
+
}
|
|
1616
|
+
finally {
|
|
1617
|
+
this.ctx = {};
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1599
1620
|
/**
|
|
1600
1621
|
* Returns the latest block hash.
|
|
1601
1622
|
*
|
|
@@ -5188,6 +5209,40 @@ class ProgramManager {
|
|
|
5188
5209
|
this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider({ transport: networkClientOptions?.transport });
|
|
5189
5210
|
this.recordProvider = recordProvider;
|
|
5190
5211
|
}
|
|
5212
|
+
/**
|
|
5213
|
+
* Pre-load the inclusion prover for offline execution. Required when the
|
|
5214
|
+
* user provides an explicit OfflineQuery (truly offline — can't fetch lazily).
|
|
5215
|
+
* For CallbackQuery, snarkVM handles inclusion key loading on demand.
|
|
5216
|
+
*/
|
|
5217
|
+
async ensureInclusionKeys(isOffline) {
|
|
5218
|
+
if (isOffline && !this.inclusionKeysLoaded) {
|
|
5219
|
+
try {
|
|
5220
|
+
const inclusionKeys = await this.keyProvider.inclusionKeys();
|
|
5221
|
+
mainnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
5222
|
+
this.inclusionKeysLoaded = true;
|
|
5223
|
+
}
|
|
5224
|
+
catch {
|
|
5225
|
+
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Create a CallbackQuery that delegates all state fetching to the
|
|
5231
|
+
* transport-aware network client. WASM calls back into these functions
|
|
5232
|
+
* during trace.prepare_async() instead of making its own reqwest calls.
|
|
5233
|
+
*
|
|
5234
|
+
* This handles ALL programs including those with DynamicRecord inputs.
|
|
5235
|
+
*/
|
|
5236
|
+
buildCallbackQuery() {
|
|
5237
|
+
const networkClient = this.networkClient;
|
|
5238
|
+
return new mainnet_js.CallbackQuery(
|
|
5239
|
+
// getStateRoot: () => Promise<string>
|
|
5240
|
+
async () => await networkClient.getStateRoot(),
|
|
5241
|
+
// getStatePaths: (commitments: string[]) => Promise<string[]>
|
|
5242
|
+
async (commitments) => await networkClient.getStatePaths(commitments),
|
|
5243
|
+
// getBlockHeight: () => Promise<number>
|
|
5244
|
+
async () => await networkClient.getLatestHeight());
|
|
5245
|
+
}
|
|
5191
5246
|
/**
|
|
5192
5247
|
* Check if the fee is sufficient to pay for the transaction
|
|
5193
5248
|
*/
|
|
@@ -5732,21 +5787,19 @@ class ProgramManager {
|
|
|
5732
5787
|
catch (e) {
|
|
5733
5788
|
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.`);
|
|
5734
5789
|
}
|
|
5735
|
-
if (offlineQuery && !this.inclusionKeysLoaded) {
|
|
5736
|
-
try {
|
|
5737
|
-
const inclusionKeys = await this.keyProvider.inclusionKeys();
|
|
5738
|
-
mainnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
5739
|
-
this.inclusionKeysLoaded = true;
|
|
5740
|
-
console.log("Successfully loaded inclusion key");
|
|
5741
|
-
}
|
|
5742
|
-
catch {
|
|
5743
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5744
|
-
}
|
|
5745
|
-
}
|
|
5746
5790
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
5747
5791
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
5792
|
+
// Build the query: user-provided OfflineQuery for truly offline execution,
|
|
5793
|
+
// CallbackQuery when a custom transport is configured, or undefined to
|
|
5794
|
+
// let WASM use its internal SnapshotQuery with the default fetch.
|
|
5795
|
+
const query = offlineQuery
|
|
5796
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
5797
|
+
: this.networkClient.hasCustomTransport
|
|
5798
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
5799
|
+
: undefined;
|
|
5800
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
5748
5801
|
// Build an execution transaction
|
|
5749
|
-
return await mainnet_js.ProgramManager.buildExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey,
|
|
5802
|
+
return await mainnet_js.ProgramManager.buildExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, query, edition);
|
|
5750
5803
|
}
|
|
5751
5804
|
/**
|
|
5752
5805
|
* Builds an execution transaction for submission to the Aleo network from an Authorization and Fee Authorization.
|
|
@@ -5872,22 +5925,15 @@ class ProgramManager {
|
|
|
5872
5925
|
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.`);
|
|
5873
5926
|
}
|
|
5874
5927
|
}
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
this.inclusionKeysLoaded = true;
|
|
5882
|
-
console.log("Successfully loaded inclusion key");
|
|
5883
|
-
}
|
|
5884
|
-
catch {
|
|
5885
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5928
|
+
const query = offlineQuery
|
|
5929
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
5930
|
+
: this.networkClient.hasCustomTransport
|
|
5931
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
5932
|
+
: undefined;
|
|
5933
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
5888
5934
|
// Build an execution transaction from the authorization.
|
|
5889
5935
|
console.log("Executing authorizations");
|
|
5890
|
-
return await mainnet_js.ProgramManager.executeAuthorization(authorization, feeAuthorization, program, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, imports, this.host,
|
|
5936
|
+
return await mainnet_js.ProgramManager.executeAuthorization(authorization, feeAuthorization, program, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, imports, this.host, query);
|
|
5891
5937
|
}
|
|
5892
5938
|
/**
|
|
5893
5939
|
* Builds a SnarkVM `Authorization` for a specific function.
|
|
@@ -6374,11 +6420,17 @@ class ProgramManager {
|
|
|
6374
6420
|
}
|
|
6375
6421
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6376
6422
|
const preparedInputs = this.prepareInputs(program, function_name, inputs);
|
|
6423
|
+
const query = offlineQuery
|
|
6424
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6425
|
+
: this.networkClient.hasCustomTransport
|
|
6426
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6427
|
+
: undefined;
|
|
6428
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6377
6429
|
// Run the program offline and return the result
|
|
6378
6430
|
console.log("Running program offline");
|
|
6379
6431
|
console.log("Proving key: ", provingKey);
|
|
6380
6432
|
console.log("Verifying key: ", verifyingKey);
|
|
6381
|
-
return mainnet_js.ProgramManager.executeFunctionOffline(executionPrivateKey, program, function_name, preparedInputs, proveExecution, false, imports, provingKey, verifyingKey, this.host,
|
|
6433
|
+
return mainnet_js.ProgramManager.executeFunctionOffline(executionPrivateKey, program, function_name, preparedInputs, proveExecution, false, imports, provingKey, verifyingKey, this.host, query, edition);
|
|
6382
6434
|
}
|
|
6383
6435
|
/**
|
|
6384
6436
|
* Join two credits records into a single credits record
|
|
@@ -6477,20 +6529,14 @@ class ProgramManager {
|
|
|
6477
6529
|
catch (e) {
|
|
6478
6530
|
logAndThrow("Records provided are not valid. Please ensure they are valid plaintext records.");
|
|
6479
6531
|
}
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
console.log("Successfully loaded inclusion key");
|
|
6487
|
-
}
|
|
6488
|
-
catch {
|
|
6489
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6490
|
-
}
|
|
6491
|
-
}
|
|
6532
|
+
const query = offlineQuery
|
|
6533
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6534
|
+
: this.networkClient.hasCustomTransport
|
|
6535
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6536
|
+
: undefined;
|
|
6537
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6492
6538
|
// Build an execution transaction and submit it to the network
|
|
6493
|
-
const tx = await mainnet_js.ProgramManager.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey,
|
|
6539
|
+
const tx = await mainnet_js.ProgramManager.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, query);
|
|
6494
6540
|
// Check if the account has sufficient credits to pay for the transaction
|
|
6495
6541
|
if (!privateFee) {
|
|
6496
6542
|
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
@@ -6555,20 +6601,14 @@ class ProgramManager {
|
|
|
6555
6601
|
catch (e) {
|
|
6556
6602
|
logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
|
|
6557
6603
|
}
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
console.log("Successfully loaded inclusion key");
|
|
6565
|
-
}
|
|
6566
|
-
catch {
|
|
6567
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6568
|
-
}
|
|
6569
|
-
}
|
|
6604
|
+
const query = offlineQuery
|
|
6605
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6606
|
+
: this.networkClient.hasCustomTransport
|
|
6607
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6608
|
+
: undefined;
|
|
6609
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6570
6610
|
// Build an execution transaction and submit it to the network
|
|
6571
|
-
const tx = await mainnet_js.ProgramManager.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey,
|
|
6611
|
+
const tx = await mainnet_js.ProgramManager.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey, query);
|
|
6572
6612
|
return await this.networkClient.submitTransaction(tx);
|
|
6573
6613
|
}
|
|
6574
6614
|
/**
|
|
@@ -6693,22 +6733,14 @@ class ProgramManager {
|
|
|
6693
6733
|
catch (e) {
|
|
6694
6734
|
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.`);
|
|
6695
6735
|
}
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
mainnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
6703
|
-
this.inclusionKeysLoaded = true;
|
|
6704
|
-
console.log("Successfully loaded inclusion key");
|
|
6705
|
-
}
|
|
6706
|
-
catch {
|
|
6707
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6708
|
-
}
|
|
6709
|
-
}
|
|
6736
|
+
const query = offlineQuery
|
|
6737
|
+
? mainnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6738
|
+
: this.networkClient.hasCustomTransport
|
|
6739
|
+
? mainnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6740
|
+
: undefined;
|
|
6741
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6710
6742
|
// Build an execution transaction
|
|
6711
|
-
return await mainnet_js.ProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey,
|
|
6743
|
+
return await mainnet_js.ProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, query);
|
|
6712
6744
|
}
|
|
6713
6745
|
/**
|
|
6714
6746
|
* Build a transfer_public transaction to transfer credits to another account for later submission to the Aleo network
|