@provablehq/sdk 0.9.7 → 0.9.9
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.d.ts +8 -2
- package/dist/mainnet/browser.js +140 -73
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/models/record-provider/encryptedRecord.d.ts +58 -0
- package/dist/mainnet/models/record-provider/ownedRecord.d.ts +60 -0
- package/dist/mainnet/models/record-provider/recordSearchParams.d.ts +19 -0
- package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +24 -0
- package/dist/mainnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
- package/dist/mainnet/models/record-scanner/recordsFilter.d.ts +35 -0
- package/dist/mainnet/models/record-scanner/recordsResponseFilter.d.ts +38 -0
- package/dist/mainnet/models/record-scanner/registrationRequest.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResponse.d.ts +15 -0
- package/dist/mainnet/network-client.d.ts +29 -4
- package/dist/mainnet/program-manager.d.ts +4 -2
- package/dist/mainnet/record-provider.d.ts +106 -68
- package/dist/testnet/browser.d.ts +8 -2
- package/dist/testnet/browser.js +140 -73
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/models/record-provider/encryptedRecord.d.ts +58 -0
- package/dist/testnet/models/record-provider/ownedRecord.d.ts +60 -0
- package/dist/testnet/models/record-provider/recordSearchParams.d.ts +19 -0
- package/dist/testnet/models/record-scanner/ownedFilter.d.ts +24 -0
- package/dist/testnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
- package/dist/testnet/models/record-scanner/recordsFilter.d.ts +35 -0
- package/dist/testnet/models/record-scanner/recordsResponseFilter.d.ts +38 -0
- package/dist/testnet/models/record-scanner/registrationRequest.d.ts +13 -0
- package/dist/testnet/models/record-scanner/registrationResponse.d.ts +15 -0
- package/dist/testnet/network-client.d.ts +29 -4
- package/dist/testnet/program-manager.d.ts +4 -2
- package/dist/testnet/record-provider.d.ts +106 -68
- package/package.json +2 -2
|
@@ -5,6 +5,7 @@ import { BlockJSON, Header, Metadata } from "./models/blockJSON.js";
|
|
|
5
5
|
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
|
|
6
6
|
import { DeploymentJSON, VerifyingKeys } from "./models/deployment/deploymentJSON.js";
|
|
7
7
|
import { DeploymentObject } from "./models/deployment/deploymentObject.js";
|
|
8
|
+
import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
|
|
8
9
|
import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSON.js";
|
|
9
10
|
import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject.js";
|
|
10
11
|
import { FinalizeJSON } from "./models/finalizeJSON.js";
|
|
@@ -14,6 +15,8 @@ import { InputJSON } from "./models/input/inputJSON.js";
|
|
|
14
15
|
import { InputObject } from "./models/input/inputObject.js";
|
|
15
16
|
import { OutputJSON } from "./models/output/outputJSON.js";
|
|
16
17
|
import { OutputObject } from "./models/output/outputObject.js";
|
|
18
|
+
import { OwnedFilter } from "./models/record-scanner/ownedFilter.js";
|
|
19
|
+
import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
|
|
17
20
|
import { OwnerJSON } from "./models/owner/ownerJSON.js";
|
|
18
21
|
import { PlaintextArray } from "./models/plaintext/array.js";
|
|
19
22
|
import { PlaintextLiteral } from "./models/plaintext/literal.js";
|
|
@@ -22,6 +25,9 @@ import { PlaintextStruct } from "./models/plaintext/struct.js";
|
|
|
22
25
|
import { ProvingRequestJSON } from "./models/provingRequest.js";
|
|
23
26
|
import { ProvingResponse } from "./models/provingResponse.js";
|
|
24
27
|
import { RatificationJSON } from "./models/ratification.js";
|
|
28
|
+
import { RecordsFilter } from "./models/record-scanner/recordsFilter.js";
|
|
29
|
+
import { RecordsResponseFilter } from "./models/record-scanner/recordsResponseFilter.js";
|
|
30
|
+
import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
|
|
25
31
|
import { SolutionsJSON, SolutionJSON, PartialSolutionJSON } from "./models/solution.js";
|
|
26
32
|
import { TransactionJSON } from "./models/transaction/transactionJSON.js";
|
|
27
33
|
import { TransactionObject } from "./models/transaction/transactionObject.js";
|
|
@@ -29,11 +35,11 @@ import { TransitionJSON } from "./models/transition/transitionJSON.js";
|
|
|
29
35
|
import { TransitionObject } from "./models/transition/transitionObject.js";
|
|
30
36
|
import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
|
|
31
37
|
import { OfflineKeyProvider, OfflineSearchParams } from "./offline-key-provider.js";
|
|
32
|
-
import { BlockHeightSearch, NetworkRecordProvider, RecordProvider
|
|
38
|
+
import { BlockHeightSearch, NetworkRecordProvider, RecordProvider } from "./record-provider.js";
|
|
33
39
|
declare function initializeWasm(): Promise<void>;
|
|
34
40
|
export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorizationOptions, AuthorizationOptions } from "./program-manager.js";
|
|
35
41
|
export { logAndThrow } from "./utils.js";
|
|
36
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";
|
|
37
43
|
export { initializeWasm };
|
|
38
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";
|
|
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, };
|
|
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, };
|
package/dist/mainnet/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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, ProgramManager as ProgramManager$1,
|
|
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
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
|
/**
|
|
@@ -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.9",
|
|
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
|
/**
|
|
@@ -3011,7 +3032,7 @@ class NetworkRecordProvider {
|
|
|
3011
3032
|
/**
|
|
3012
3033
|
* Set the account used to search for records
|
|
3013
3034
|
*
|
|
3014
|
-
* @param {Account} account The account to use for searching for records
|
|
3035
|
+
* @param {Account} account The account used to use for searching for records.
|
|
3015
3036
|
*/
|
|
3016
3037
|
setAccount(account) {
|
|
3017
3038
|
this.account = account;
|
|
@@ -3019,11 +3040,9 @@ class NetworkRecordProvider {
|
|
|
3019
3040
|
/**
|
|
3020
3041
|
* Find a list of credit records with a given number of microcredits by via the official Aleo API
|
|
3021
3042
|
*
|
|
3022
|
-
* @param {number[]} microcredits The number of microcredits to search for
|
|
3023
|
-
* @param {
|
|
3024
|
-
* @
|
|
3025
|
-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
3026
|
-
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
3043
|
+
* @param {number[]} microcredits The number of microcredits to search for.
|
|
3044
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
3045
|
+
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
|
|
3027
3046
|
*
|
|
3028
3047
|
* @example
|
|
3029
3048
|
* // Create a new NetworkRecordProvider
|
|
@@ -3032,11 +3051,11 @@ class NetworkRecordProvider {
|
|
|
3032
3051
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3033
3052
|
*
|
|
3034
3053
|
* // The record provider can be used to find records with a given number of microcredits
|
|
3035
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
3054
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
3036
3055
|
*
|
|
3037
3056
|
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
3038
3057
|
* // found again if a subsequent search is performed
|
|
3039
|
-
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
3058
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
3040
3059
|
*
|
|
3041
3060
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3042
3061
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
@@ -3044,7 +3063,7 @@ class NetworkRecordProvider {
|
|
|
3044
3063
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3045
3064
|
*
|
|
3046
3065
|
* */
|
|
3047
|
-
async findCreditsRecords(microcredits,
|
|
3066
|
+
async findCreditsRecords(microcredits, searchParameters) {
|
|
3048
3067
|
let startHeight = 0;
|
|
3049
3068
|
let endHeight = 0;
|
|
3050
3069
|
let maxAmount = undefined;
|
|
@@ -3061,9 +3080,6 @@ class NetworkRecordProvider {
|
|
|
3061
3080
|
if ("maxAmount" in searchParameters && typeof searchParameters["maxAmount"] == "number") {
|
|
3062
3081
|
maxAmount = searchParameters["maxAmount"];
|
|
3063
3082
|
}
|
|
3064
|
-
if ("unspent" in searchParameters && typeof searchParameters["unspent"] == "boolean") {
|
|
3065
|
-
unspent = searchParameters["unspent"];
|
|
3066
|
-
}
|
|
3067
3083
|
}
|
|
3068
3084
|
// If the end height is not specified, use the current block height
|
|
3069
3085
|
if (endHeight == 0) {
|
|
@@ -3074,16 +3090,20 @@ class NetworkRecordProvider {
|
|
|
3074
3090
|
if (startHeight >= endHeight) {
|
|
3075
3091
|
logAndThrow("Start height must be less than end height");
|
|
3076
3092
|
}
|
|
3077
|
-
|
|
3093
|
+
const recordsPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, ["credits.aleo"], microcredits, maxAmount, searchParameters.nonces, this.account.privateKey());
|
|
3094
|
+
return recordsPts.map((record) => ({
|
|
3095
|
+
owner: record.owner().toString(),
|
|
3096
|
+
programName: 'credits.aleo',
|
|
3097
|
+
recordName: 'credits',
|
|
3098
|
+
recordPlaintext: record.toString(),
|
|
3099
|
+
}));
|
|
3078
3100
|
}
|
|
3079
3101
|
/**
|
|
3080
3102
|
* Find a credit record with a given number of microcredits by via the official Aleo API
|
|
3081
3103
|
*
|
|
3082
|
-
* @param {number} microcredits The number of microcredits to search for
|
|
3083
|
-
* @param {
|
|
3084
|
-
* @
|
|
3085
|
-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
3086
|
-
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
3104
|
+
* @param {number} microcredits The number of microcredits to search for.
|
|
3105
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
3106
|
+
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
|
|
3087
3107
|
*
|
|
3088
3108
|
* @example
|
|
3089
3109
|
* // Create a new NetworkRecordProvider
|
|
@@ -3092,21 +3112,21 @@ class NetworkRecordProvider {
|
|
|
3092
3112
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3093
3113
|
*
|
|
3094
3114
|
* // The record provider can be used to find records with a given number of microcredits
|
|
3095
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
3115
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
3096
3116
|
*
|
|
3097
3117
|
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
3098
3118
|
* // found again if a subsequent search is performed
|
|
3099
|
-
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
3119
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
3100
3120
|
*
|
|
3101
3121
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3102
3122
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
3103
3123
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
3104
3124
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3105
3125
|
*/
|
|
3106
|
-
async findCreditsRecord(microcredits,
|
|
3126
|
+
async findCreditsRecord(microcredits, searchParameters) {
|
|
3107
3127
|
let records = null;
|
|
3108
3128
|
try {
|
|
3109
|
-
records = await this.findCreditsRecords([microcredits],
|
|
3129
|
+
records = await this.findCreditsRecords([microcredits], searchParameters);
|
|
3110
3130
|
}
|
|
3111
3131
|
catch (e) {
|
|
3112
3132
|
console.log("No records found with error:", e);
|
|
@@ -3120,13 +3140,24 @@ class NetworkRecordProvider {
|
|
|
3120
3140
|
/**
|
|
3121
3141
|
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
|
|
3122
3142
|
*/
|
|
3123
|
-
async findRecord(
|
|
3124
|
-
|
|
3143
|
+
async findRecord(searchParameters) {
|
|
3144
|
+
let records;
|
|
3145
|
+
try {
|
|
3146
|
+
records = await this.findRecords(searchParameters);
|
|
3147
|
+
}
|
|
3148
|
+
catch (e) {
|
|
3149
|
+
console.log("No records found with error:", e);
|
|
3150
|
+
}
|
|
3151
|
+
if (records && records.length > 0) {
|
|
3152
|
+
return records[0];
|
|
3153
|
+
}
|
|
3154
|
+
console.error("Record not found with error:", records);
|
|
3155
|
+
throw new Error("Record not found");
|
|
3125
3156
|
}
|
|
3126
3157
|
/**
|
|
3127
3158
|
* Find multiple records from a specified program.
|
|
3128
3159
|
*/
|
|
3129
|
-
async findRecords(
|
|
3160
|
+
async findRecords(searchParameters) {
|
|
3130
3161
|
let startHeight = 0;
|
|
3131
3162
|
let endHeight = 0;
|
|
3132
3163
|
let amounts = undefined;
|
|
@@ -3145,29 +3176,35 @@ class NetworkRecordProvider {
|
|
|
3145
3176
|
if ("maxAmount" in searchParameters && typeof searchParameters["maxAmount"] == "number") {
|
|
3146
3177
|
maxAmount = searchParameters["maxAmount"];
|
|
3147
3178
|
}
|
|
3148
|
-
if ("nonces" in searchParameters && Array.isArray(searchParameters["nonces"]) && searchParameters["nonces"].every((item) => typeof item === "string")) {
|
|
3149
|
-
nonces = searchParameters["nonces"];
|
|
3150
|
-
}
|
|
3151
3179
|
if ("program" in searchParameters && typeof searchParameters["program"] == "string") {
|
|
3152
3180
|
programs = [searchParameters["program"]];
|
|
3153
3181
|
}
|
|
3154
3182
|
if ("programs" in searchParameters && Array.isArray(searchParameters["programs"]) && searchParameters["programs"].every((item) => typeof item === "string")) {
|
|
3155
3183
|
programs = searchParameters["programs"];
|
|
3156
3184
|
}
|
|
3157
|
-
if ("unspent" in searchParameters && typeof searchParameters["unspent"] == "boolean") {
|
|
3158
|
-
unspent = searchParameters["unspent"];
|
|
3159
|
-
}
|
|
3160
3185
|
}
|
|
3161
|
-
// If the end height is not specified, use the current block height
|
|
3186
|
+
// If the end height is not specified, use the current block height.
|
|
3162
3187
|
if (endHeight == 0) {
|
|
3163
3188
|
const end = await this.networkClient.getLatestHeight();
|
|
3164
3189
|
endHeight = end;
|
|
3165
3190
|
}
|
|
3166
|
-
// If the start height is greater than the end height, throw an error
|
|
3191
|
+
// If the start height is greater than the end height, throw an error.
|
|
3167
3192
|
if (startHeight >= endHeight) {
|
|
3168
3193
|
logAndThrow("Start height must be less than end height");
|
|
3169
3194
|
}
|
|
3170
|
-
|
|
3195
|
+
const recordPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, programs, amounts, maxAmount, searchParameters.nonces, this.account.privateKey());
|
|
3196
|
+
return recordPts.map((record) => ({
|
|
3197
|
+
record_plaintext: record.toString(),
|
|
3198
|
+
}));
|
|
3199
|
+
}
|
|
3200
|
+
async encryptedRecords(recordsFilter, responseFilter) {
|
|
3201
|
+
throw new Error("Not implemented");
|
|
3202
|
+
}
|
|
3203
|
+
async checkSerialNumbers(serialNumbers) {
|
|
3204
|
+
throw new Error("Not implemented");
|
|
3205
|
+
}
|
|
3206
|
+
async checkTags(tags) {
|
|
3207
|
+
throw new Error("Not implemented");
|
|
3171
3208
|
}
|
|
3172
3209
|
}
|
|
3173
3210
|
/**
|
|
@@ -3185,15 +3222,17 @@ class NetworkRecordProvider {
|
|
|
3185
3222
|
*
|
|
3186
3223
|
* // The record provider can be used to find records with a given number of microcredits and the block height search
|
|
3187
3224
|
* // can be used to find records within a given block height range
|
|
3188
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, [], params);
|
|
3225
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [], ...params });
|
|
3189
3226
|
*
|
|
3190
3227
|
*/
|
|
3191
3228
|
class BlockHeightSearch {
|
|
3192
3229
|
startHeight;
|
|
3193
3230
|
endHeight;
|
|
3194
|
-
|
|
3231
|
+
unspent;
|
|
3232
|
+
constructor(startHeight, endHeight, unspent) {
|
|
3195
3233
|
this.startHeight = startHeight;
|
|
3196
3234
|
this.endHeight = endHeight;
|
|
3235
|
+
this.unspent = !!unspent;
|
|
3197
3236
|
}
|
|
3198
3237
|
}
|
|
3199
3238
|
|
|
@@ -3371,7 +3410,7 @@ class ProgramManager {
|
|
|
3371
3410
|
// Get the fee record from the account if it is not provided in the parameters
|
|
3372
3411
|
try {
|
|
3373
3412
|
feeRecord = privateFee
|
|
3374
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
3413
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3375
3414
|
: undefined;
|
|
3376
3415
|
}
|
|
3377
3416
|
catch (e) {
|
|
@@ -3490,11 +3529,12 @@ class ProgramManager {
|
|
|
3490
3529
|
*/
|
|
3491
3530
|
async buildExecutionTransaction(options) {
|
|
3492
3531
|
// Destructure the options object to access the parameters
|
|
3493
|
-
const {
|
|
3532
|
+
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, keySearchParams, privateKey, offlineQuery, } = options;
|
|
3494
3533
|
let feeRecord = options.feeRecord;
|
|
3495
3534
|
let provingKey = options.provingKey;
|
|
3496
3535
|
let verifyingKey = options.verifyingKey;
|
|
3497
3536
|
let program = options.program;
|
|
3537
|
+
let programName = options.programName;
|
|
3498
3538
|
let imports = options.imports;
|
|
3499
3539
|
let edition = options.edition;
|
|
3500
3540
|
// Ensure the function exists on the network
|
|
@@ -3509,6 +3549,10 @@ class ProgramManager {
|
|
|
3509
3549
|
else if (program instanceof Program) {
|
|
3510
3550
|
program = program.toString();
|
|
3511
3551
|
}
|
|
3552
|
+
// Get the program name if it is not provided in the parameters.
|
|
3553
|
+
if (programName === undefined) {
|
|
3554
|
+
programName = Program.fromString(program).id();
|
|
3555
|
+
}
|
|
3512
3556
|
if (edition == undefined) {
|
|
3513
3557
|
try {
|
|
3514
3558
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
@@ -3530,7 +3574,7 @@ class ProgramManager {
|
|
|
3530
3574
|
// Get the fee record from the account if it is not provided in the parameters
|
|
3531
3575
|
try {
|
|
3532
3576
|
feeRecord = privateFee
|
|
3533
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
3577
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3534
3578
|
: undefined;
|
|
3535
3579
|
}
|
|
3536
3580
|
catch (e) {
|
|
@@ -3599,9 +3643,10 @@ class ProgramManager {
|
|
|
3599
3643
|
*/
|
|
3600
3644
|
async buildAuthorization(options) {
|
|
3601
3645
|
// Destructure the options object to access the parameters.
|
|
3602
|
-
const {
|
|
3646
|
+
const { functionName, inputs, } = options;
|
|
3603
3647
|
const privateKey = options.privateKey;
|
|
3604
3648
|
let program = options.programSource;
|
|
3649
|
+
let programName = options.programName;
|
|
3605
3650
|
let imports = options.programImports;
|
|
3606
3651
|
let edition = options.edition;
|
|
3607
3652
|
// Ensure the function exists on the network.
|
|
@@ -3616,6 +3661,10 @@ class ProgramManager {
|
|
|
3616
3661
|
else if (program instanceof Program) {
|
|
3617
3662
|
program = program.toString();
|
|
3618
3663
|
}
|
|
3664
|
+
// Get the program name if it is not provided in the parameters.
|
|
3665
|
+
if (programName === undefined) {
|
|
3666
|
+
programName = Program.fromString(program).id();
|
|
3667
|
+
}
|
|
3619
3668
|
// Get the private key from the account if it is not provided in the parameters.
|
|
3620
3669
|
let executionPrivateKey = privateKey;
|
|
3621
3670
|
if (typeof privateKey === "undefined" &&
|
|
@@ -3677,9 +3726,10 @@ class ProgramManager {
|
|
|
3677
3726
|
*/
|
|
3678
3727
|
async buildAuthorizationUnchecked(options) {
|
|
3679
3728
|
// Destructure the options object to access the parameters.
|
|
3680
|
-
const {
|
|
3729
|
+
const { functionName, inputs, } = options;
|
|
3681
3730
|
const privateKey = options.privateKey;
|
|
3682
3731
|
let program = options.programSource;
|
|
3732
|
+
let programName = options.programName;
|
|
3683
3733
|
let imports = options.programImports;
|
|
3684
3734
|
let edition = options.edition;
|
|
3685
3735
|
// Ensure the function exists on the network.
|
|
@@ -3694,6 +3744,10 @@ class ProgramManager {
|
|
|
3694
3744
|
else if (program instanceof Program) {
|
|
3695
3745
|
program = program.toString();
|
|
3696
3746
|
}
|
|
3747
|
+
// Get the program name if it is not provided in the parameters.
|
|
3748
|
+
if (programName === undefined) {
|
|
3749
|
+
programName = Program.fromString(program).id();
|
|
3750
|
+
}
|
|
3697
3751
|
// Get the private key from the account if it is not provided in the parameters.
|
|
3698
3752
|
let executionPrivateKey = privateKey;
|
|
3699
3753
|
if (typeof privateKey === "undefined" &&
|
|
@@ -3759,9 +3813,10 @@ class ProgramManager {
|
|
|
3759
3813
|
*/
|
|
3760
3814
|
async provingRequest(options) {
|
|
3761
3815
|
// Destructure the options object to access the parameters.
|
|
3762
|
-
const {
|
|
3816
|
+
const { functionName, baseFee, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
3763
3817
|
const privateKey = options.privateKey;
|
|
3764
3818
|
let program = options.programSource;
|
|
3819
|
+
let programName = options.programName;
|
|
3765
3820
|
let feeRecord = options.feeRecord;
|
|
3766
3821
|
let imports = options.programImports;
|
|
3767
3822
|
let edition = options.edition;
|
|
@@ -3777,6 +3832,10 @@ class ProgramManager {
|
|
|
3777
3832
|
else if (program instanceof Program) {
|
|
3778
3833
|
program = program.toString();
|
|
3779
3834
|
}
|
|
3835
|
+
// Get the program name if it is not provided in the parameters.
|
|
3836
|
+
if (programName === undefined) {
|
|
3837
|
+
programName = Program.fromString(program).id();
|
|
3838
|
+
}
|
|
3780
3839
|
if (edition == undefined) {
|
|
3781
3840
|
try {
|
|
3782
3841
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
@@ -3798,7 +3857,7 @@ class ProgramManager {
|
|
|
3798
3857
|
// Get the fee record from the account if it is not provided in the parameters.
|
|
3799
3858
|
try {
|
|
3800
3859
|
feeRecord = privateFee
|
|
3801
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
3860
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3802
3861
|
: undefined;
|
|
3803
3862
|
}
|
|
3804
3863
|
catch (e) {
|
|
@@ -4037,7 +4096,7 @@ class ProgramManager {
|
|
|
4037
4096
|
// Get the fee record from the account if it is not provided in the parameters
|
|
4038
4097
|
try {
|
|
4039
4098
|
feeRecord = privateFee
|
|
4040
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
4099
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
4041
4100
|
: undefined;
|
|
4042
4101
|
}
|
|
4043
4102
|
catch (e) {
|
|
@@ -4227,14 +4286,14 @@ class ProgramManager {
|
|
|
4227
4286
|
const nonces = [];
|
|
4228
4287
|
if (requiresAmountRecord(transferType)) {
|
|
4229
4288
|
// If the transfer type is private and requires an amount record, get it from the record provider
|
|
4230
|
-
amountRecord = (await this.getCreditsRecord(priorityFee, [], amountRecord, recordSearchParams));
|
|
4289
|
+
amountRecord = RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], amountRecord, recordSearchParams)).record_plaintext ?? '');
|
|
4231
4290
|
nonces.push(amountRecord.nonce());
|
|
4232
4291
|
}
|
|
4233
4292
|
else {
|
|
4234
4293
|
amountRecord = undefined;
|
|
4235
4294
|
}
|
|
4236
4295
|
feeRecord = privateFee
|
|
4237
|
-
? (await this.getCreditsRecord(priorityFee, nonces, feeRecord, recordSearchParams))
|
|
4296
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, nonces, feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
4238
4297
|
: undefined;
|
|
4239
4298
|
}
|
|
4240
4299
|
catch (e) {
|
|
@@ -4941,14 +5000,22 @@ class ProgramManager {
|
|
|
4941
5000
|
// Internal utility function for getting a credits.aleo record
|
|
4942
5001
|
async getCreditsRecord(amount, nonces, record, params) {
|
|
4943
5002
|
try {
|
|
4944
|
-
return record instanceof RecordPlaintext
|
|
4945
|
-
|
|
4946
|
-
|
|
5003
|
+
// return record instanceof RecordPlaintext
|
|
5004
|
+
// ? record
|
|
5005
|
+
// : RecordPlaintext.fromString(<string>record);
|
|
5006
|
+
if (record && record instanceof RecordPlaintext) {
|
|
5007
|
+
record = record.toString();
|
|
5008
|
+
}
|
|
5009
|
+
return ({
|
|
5010
|
+
recordPlaintext: record,
|
|
5011
|
+
programName: 'credits.aleo',
|
|
5012
|
+
recordName: 'credits',
|
|
5013
|
+
});
|
|
4947
5014
|
}
|
|
4948
5015
|
catch (e) {
|
|
4949
5016
|
try {
|
|
4950
5017
|
const recordProvider = this.recordProvider;
|
|
4951
|
-
return
|
|
5018
|
+
return await recordProvider.findCreditsRecord(amount, { ...params, unspent: true, nonces });
|
|
4952
5019
|
}
|
|
4953
5020
|
catch (e) {
|
|
4954
5021
|
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.`);
|