@provablehq/sdk 0.9.8 → 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.
- package/dist/mainnet/browser.d.ts +11 -4
- package/dist/mainnet/browser.js +492 -51
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.ts +1 -0
- package/dist/mainnet/function-key-provider.d.ts +18 -0
- 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 +42 -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/models/record-scanner/statusResponse.d.ts +13 -0
- package/dist/mainnet/node.js +2 -2
- package/dist/mainnet/offline-key-provider.d.ts +14 -0
- package/dist/mainnet/program-manager.d.ts +14 -2
- package/dist/mainnet/record-provider.d.ts +106 -68
- package/dist/mainnet/record-scanner.d.ts +151 -0
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/browser.d.ts +11 -4
- package/dist/testnet/browser.js +492 -51
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.ts +1 -0
- package/dist/testnet/function-key-provider.d.ts +18 -0
- 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 +42 -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/models/record-scanner/statusResponse.d.ts +13 -0
- package/dist/testnet/node.js +2 -2
- package/dist/testnet/offline-key-provider.d.ts +14 -0
- package/dist/testnet/program-manager.d.ts +14 -2
- package/dist/testnet/record-provider.d.ts +106 -68
- package/dist/testnet/record-scanner.d.ts +151 -0
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +3 -3
package/dist/testnet/browser.js
CHANGED
|
@@ -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, ProgramManager as ProgramManager$1,
|
|
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/testnet.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/testnet.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/testnet.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.
|
|
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
|
|
@@ -3032,7 +3073,7 @@ class NetworkRecordProvider {
|
|
|
3032
3073
|
/**
|
|
3033
3074
|
* Set the account used to search for records
|
|
3034
3075
|
*
|
|
3035
|
-
* @param {Account} account The account to use for searching for records
|
|
3076
|
+
* @param {Account} account The account used to use for searching for records.
|
|
3036
3077
|
*/
|
|
3037
3078
|
setAccount(account) {
|
|
3038
3079
|
this.account = account;
|
|
@@ -3040,11 +3081,9 @@ class NetworkRecordProvider {
|
|
|
3040
3081
|
/**
|
|
3041
3082
|
* Find a list of credit records with a given number of microcredits by via the official Aleo API
|
|
3042
3083
|
*
|
|
3043
|
-
* @param {number[]} microcredits The number of microcredits to search for
|
|
3044
|
-
* @param {
|
|
3045
|
-
* @
|
|
3046
|
-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
3047
|
-
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
3084
|
+
* @param {number[]} microcredits The number of microcredits to search for.
|
|
3085
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
3086
|
+
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
|
|
3048
3087
|
*
|
|
3049
3088
|
* @example
|
|
3050
3089
|
* // Create a new NetworkRecordProvider
|
|
@@ -3053,11 +3092,11 @@ class NetworkRecordProvider {
|
|
|
3053
3092
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3054
3093
|
*
|
|
3055
3094
|
* // The record provider can be used to find records with a given number of microcredits
|
|
3056
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
3095
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
3057
3096
|
*
|
|
3058
3097
|
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
3059
3098
|
* // found again if a subsequent search is performed
|
|
3060
|
-
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
3099
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
3061
3100
|
*
|
|
3062
3101
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3063
3102
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
@@ -3065,7 +3104,7 @@ class NetworkRecordProvider {
|
|
|
3065
3104
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3066
3105
|
*
|
|
3067
3106
|
* */
|
|
3068
|
-
async findCreditsRecords(microcredits,
|
|
3107
|
+
async findCreditsRecords(microcredits, searchParameters) {
|
|
3069
3108
|
let startHeight = 0;
|
|
3070
3109
|
let endHeight = 0;
|
|
3071
3110
|
let maxAmount = undefined;
|
|
@@ -3082,9 +3121,6 @@ class NetworkRecordProvider {
|
|
|
3082
3121
|
if ("maxAmount" in searchParameters && typeof searchParameters["maxAmount"] == "number") {
|
|
3083
3122
|
maxAmount = searchParameters["maxAmount"];
|
|
3084
3123
|
}
|
|
3085
|
-
if ("unspent" in searchParameters && typeof searchParameters["unspent"] == "boolean") {
|
|
3086
|
-
unspent = searchParameters["unspent"];
|
|
3087
|
-
}
|
|
3088
3124
|
}
|
|
3089
3125
|
// If the end height is not specified, use the current block height
|
|
3090
3126
|
if (endHeight == 0) {
|
|
@@ -3095,16 +3131,20 @@ class NetworkRecordProvider {
|
|
|
3095
3131
|
if (startHeight >= endHeight) {
|
|
3096
3132
|
logAndThrow("Start height must be less than end height");
|
|
3097
3133
|
}
|
|
3098
|
-
|
|
3134
|
+
const recordsPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, ["credits.aleo"], microcredits, maxAmount, searchParameters.nonces, this.account.privateKey());
|
|
3135
|
+
return recordsPts.map((record) => ({
|
|
3136
|
+
owner: record.owner().toString(),
|
|
3137
|
+
programName: 'credits.aleo',
|
|
3138
|
+
recordName: 'credits',
|
|
3139
|
+
recordPlaintext: record.toString(),
|
|
3140
|
+
}));
|
|
3099
3141
|
}
|
|
3100
3142
|
/**
|
|
3101
3143
|
* Find a credit record with a given number of microcredits by via the official Aleo API
|
|
3102
3144
|
*
|
|
3103
|
-
* @param {number} microcredits The number of microcredits to search for
|
|
3104
|
-
* @param {
|
|
3105
|
-
* @
|
|
3106
|
-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
|
|
3107
|
-
* @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
|
|
3145
|
+
* @param {number} microcredits The number of microcredits to search for.
|
|
3146
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
3147
|
+
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
|
|
3108
3148
|
*
|
|
3109
3149
|
* @example
|
|
3110
3150
|
* // Create a new NetworkRecordProvider
|
|
@@ -3113,21 +3153,21 @@ class NetworkRecordProvider {
|
|
|
3113
3153
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3114
3154
|
*
|
|
3115
3155
|
* // The record provider can be used to find records with a given number of microcredits
|
|
3116
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, []);
|
|
3156
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
3117
3157
|
*
|
|
3118
3158
|
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
|
|
3119
3159
|
* // found again if a subsequent search is performed
|
|
3120
|
-
* const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
|
|
3160
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
3121
3161
|
*
|
|
3122
3162
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3123
3163
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
3124
3164
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
3125
3165
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3126
3166
|
*/
|
|
3127
|
-
async findCreditsRecord(microcredits,
|
|
3167
|
+
async findCreditsRecord(microcredits, searchParameters) {
|
|
3128
3168
|
let records = null;
|
|
3129
3169
|
try {
|
|
3130
|
-
records = await this.findCreditsRecords([microcredits],
|
|
3170
|
+
records = await this.findCreditsRecords([microcredits], searchParameters);
|
|
3131
3171
|
}
|
|
3132
3172
|
catch (e) {
|
|
3133
3173
|
console.log("No records found with error:", e);
|
|
@@ -3141,13 +3181,24 @@ class NetworkRecordProvider {
|
|
|
3141
3181
|
/**
|
|
3142
3182
|
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
|
|
3143
3183
|
*/
|
|
3144
|
-
async findRecord(
|
|
3145
|
-
|
|
3184
|
+
async findRecord(searchParameters) {
|
|
3185
|
+
let records;
|
|
3186
|
+
try {
|
|
3187
|
+
records = await this.findRecords(searchParameters);
|
|
3188
|
+
}
|
|
3189
|
+
catch (e) {
|
|
3190
|
+
console.log("No records found with error:", e);
|
|
3191
|
+
}
|
|
3192
|
+
if (records && records.length > 0) {
|
|
3193
|
+
return records[0];
|
|
3194
|
+
}
|
|
3195
|
+
console.error("Record not found with error:", records);
|
|
3196
|
+
throw new Error("Record not found");
|
|
3146
3197
|
}
|
|
3147
3198
|
/**
|
|
3148
3199
|
* Find multiple records from a specified program.
|
|
3149
3200
|
*/
|
|
3150
|
-
async findRecords(
|
|
3201
|
+
async findRecords(searchParameters) {
|
|
3151
3202
|
let startHeight = 0;
|
|
3152
3203
|
let endHeight = 0;
|
|
3153
3204
|
let amounts = undefined;
|
|
@@ -3166,29 +3217,35 @@ class NetworkRecordProvider {
|
|
|
3166
3217
|
if ("maxAmount" in searchParameters && typeof searchParameters["maxAmount"] == "number") {
|
|
3167
3218
|
maxAmount = searchParameters["maxAmount"];
|
|
3168
3219
|
}
|
|
3169
|
-
if ("nonces" in searchParameters && Array.isArray(searchParameters["nonces"]) && searchParameters["nonces"].every((item) => typeof item === "string")) {
|
|
3170
|
-
nonces = searchParameters["nonces"];
|
|
3171
|
-
}
|
|
3172
3220
|
if ("program" in searchParameters && typeof searchParameters["program"] == "string") {
|
|
3173
3221
|
programs = [searchParameters["program"]];
|
|
3174
3222
|
}
|
|
3175
3223
|
if ("programs" in searchParameters && Array.isArray(searchParameters["programs"]) && searchParameters["programs"].every((item) => typeof item === "string")) {
|
|
3176
3224
|
programs = searchParameters["programs"];
|
|
3177
3225
|
}
|
|
3178
|
-
if ("unspent" in searchParameters && typeof searchParameters["unspent"] == "boolean") {
|
|
3179
|
-
unspent = searchParameters["unspent"];
|
|
3180
|
-
}
|
|
3181
3226
|
}
|
|
3182
|
-
// If the end height is not specified, use the current block height
|
|
3227
|
+
// If the end height is not specified, use the current block height.
|
|
3183
3228
|
if (endHeight == 0) {
|
|
3184
3229
|
const end = await this.networkClient.getLatestHeight();
|
|
3185
3230
|
endHeight = end;
|
|
3186
3231
|
}
|
|
3187
|
-
// If the start height is greater than the end height, throw an error
|
|
3232
|
+
// If the start height is greater than the end height, throw an error.
|
|
3188
3233
|
if (startHeight >= endHeight) {
|
|
3189
3234
|
logAndThrow("Start height must be less than end height");
|
|
3190
3235
|
}
|
|
3191
|
-
|
|
3236
|
+
const recordPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, programs, amounts, maxAmount, searchParameters.nonces, this.account.privateKey());
|
|
3237
|
+
return recordPts.map((record) => ({
|
|
3238
|
+
record_plaintext: record.toString(),
|
|
3239
|
+
}));
|
|
3240
|
+
}
|
|
3241
|
+
async encryptedRecords(recordsFilter, responseFilter) {
|
|
3242
|
+
throw new Error("Not implemented");
|
|
3243
|
+
}
|
|
3244
|
+
async checkSerialNumbers(serialNumbers) {
|
|
3245
|
+
throw new Error("Not implemented");
|
|
3246
|
+
}
|
|
3247
|
+
async checkTags(tags) {
|
|
3248
|
+
throw new Error("Not implemented");
|
|
3192
3249
|
}
|
|
3193
3250
|
}
|
|
3194
3251
|
/**
|
|
@@ -3206,15 +3263,327 @@ class NetworkRecordProvider {
|
|
|
3206
3263
|
*
|
|
3207
3264
|
* // The record provider can be used to find records with a given number of microcredits and the block height search
|
|
3208
3265
|
* // can be used to find records within a given block height range
|
|
3209
|
-
* const record = await recordProvider.findCreditsRecord(5000, true, [], params);
|
|
3266
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [], ...params });
|
|
3210
3267
|
*
|
|
3211
3268
|
*/
|
|
3212
3269
|
class BlockHeightSearch {
|
|
3213
3270
|
startHeight;
|
|
3214
3271
|
endHeight;
|
|
3215
|
-
|
|
3272
|
+
unspent;
|
|
3273
|
+
constructor(startHeight, endHeight, unspent) {
|
|
3216
3274
|
this.startHeight = startHeight;
|
|
3217
3275
|
this.endHeight = endHeight;
|
|
3276
|
+
this.unspent = !!unspent;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
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);
|
|
3218
3587
|
}
|
|
3219
3588
|
}
|
|
3220
3589
|
|
|
@@ -3227,6 +3596,7 @@ class ProgramManager {
|
|
|
3227
3596
|
host;
|
|
3228
3597
|
networkClient;
|
|
3229
3598
|
recordProvider;
|
|
3599
|
+
inclusionKeysLoaded = false;
|
|
3230
3600
|
/** Create a new instance of the ProgramManager
|
|
3231
3601
|
*
|
|
3232
3602
|
* @param { string | undefined } host A host uri running the official Aleo API
|
|
@@ -3392,7 +3762,7 @@ class ProgramManager {
|
|
|
3392
3762
|
// Get the fee record from the account if it is not provided in the parameters
|
|
3393
3763
|
try {
|
|
3394
3764
|
feeRecord = privateFee
|
|
3395
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
3765
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3396
3766
|
: undefined;
|
|
3397
3767
|
}
|
|
3398
3768
|
catch (e) {
|
|
@@ -3556,7 +3926,7 @@ class ProgramManager {
|
|
|
3556
3926
|
// Get the fee record from the account if it is not provided in the parameters
|
|
3557
3927
|
try {
|
|
3558
3928
|
feeRecord = privateFee
|
|
3559
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
3929
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3560
3930
|
: undefined;
|
|
3561
3931
|
}
|
|
3562
3932
|
catch (e) {
|
|
@@ -3592,6 +3962,17 @@ class ProgramManager {
|
|
|
3592
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.`);
|
|
3593
3963
|
}
|
|
3594
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
|
+
}
|
|
3595
3976
|
// Build an execution transaction
|
|
3596
3977
|
return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery, edition);
|
|
3597
3978
|
}
|
|
@@ -3839,7 +4220,7 @@ class ProgramManager {
|
|
|
3839
4220
|
// Get the fee record from the account if it is not provided in the parameters.
|
|
3840
4221
|
try {
|
|
3841
4222
|
feeRecord = privateFee
|
|
3842
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
4223
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
3843
4224
|
: undefined;
|
|
3844
4225
|
}
|
|
3845
4226
|
catch (e) {
|
|
@@ -4078,7 +4459,7 @@ class ProgramManager {
|
|
|
4078
4459
|
// Get the fee record from the account if it is not provided in the parameters
|
|
4079
4460
|
try {
|
|
4080
4461
|
feeRecord = privateFee
|
|
4081
|
-
? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
|
|
4462
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
4082
4463
|
: undefined;
|
|
4083
4464
|
}
|
|
4084
4465
|
catch (e) {
|
|
@@ -4098,6 +4479,18 @@ class ProgramManager {
|
|
|
4098
4479
|
catch (e) {
|
|
4099
4480
|
logAndThrow("Records provided are not valid. Please ensure they are valid plaintext records.");
|
|
4100
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
|
+
}
|
|
4101
4494
|
// Build an execution transaction and submit it to the network
|
|
4102
4495
|
const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
|
|
4103
4496
|
// Check if the account has sufficient credits to pay for the transaction
|
|
@@ -4162,6 +4555,18 @@ class ProgramManager {
|
|
|
4162
4555
|
catch (e) {
|
|
4163
4556
|
logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
|
|
4164
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
|
+
}
|
|
4165
4570
|
// Build an execution transaction and submit it to the network
|
|
4166
4571
|
const tx = await ProgramManager$1.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey, offlineQuery);
|
|
4167
4572
|
return await this.networkClient.submitTransaction(tx);
|
|
@@ -4268,19 +4673,33 @@ class ProgramManager {
|
|
|
4268
4673
|
const nonces = [];
|
|
4269
4674
|
if (requiresAmountRecord(transferType)) {
|
|
4270
4675
|
// If the transfer type is private and requires an amount record, get it from the record provider
|
|
4271
|
-
amountRecord = (await this.getCreditsRecord(priorityFee, [], amountRecord, recordSearchParams));
|
|
4676
|
+
amountRecord = RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, [], amountRecord, recordSearchParams)).record_plaintext ?? '');
|
|
4272
4677
|
nonces.push(amountRecord.nonce());
|
|
4273
4678
|
}
|
|
4274
4679
|
else {
|
|
4275
4680
|
amountRecord = undefined;
|
|
4276
4681
|
}
|
|
4277
4682
|
feeRecord = privateFee
|
|
4278
|
-
? (await this.getCreditsRecord(priorityFee, nonces, feeRecord, recordSearchParams))
|
|
4683
|
+
? RecordPlaintext.fromString((await this.getCreditsRecord(priorityFee, nonces, feeRecord, recordSearchParams)).record_plaintext ?? '')
|
|
4279
4684
|
: undefined;
|
|
4280
4685
|
}
|
|
4281
4686
|
catch (e) {
|
|
4282
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.`);
|
|
4283
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
|
+
}
|
|
4284
4703
|
// Build an execution transaction
|
|
4285
4704
|
return await ProgramManager$1.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
|
|
4286
4705
|
}
|
|
@@ -4451,6 +4870,7 @@ class ProgramManager {
|
|
|
4451
4870
|
privateFee,
|
|
4452
4871
|
inputs,
|
|
4453
4872
|
keySearchParams,
|
|
4873
|
+
program,
|
|
4454
4874
|
...additionalOptions,
|
|
4455
4875
|
};
|
|
4456
4876
|
return await this.buildExecutionTransaction(executeOptions);
|
|
@@ -4554,6 +4974,7 @@ class ProgramManager {
|
|
|
4554
4974
|
privateFee,
|
|
4555
4975
|
inputs,
|
|
4556
4976
|
keySearchParams,
|
|
4977
|
+
program,
|
|
4557
4978
|
...additionalOptions,
|
|
4558
4979
|
};
|
|
4559
4980
|
return await this.buildExecutionTransaction(executeOptions);
|
|
@@ -4648,6 +5069,7 @@ class ProgramManager {
|
|
|
4648
5069
|
privateFee,
|
|
4649
5070
|
inputs,
|
|
4650
5071
|
keySearchParams,
|
|
5072
|
+
program,
|
|
4651
5073
|
...additionalOptions,
|
|
4652
5074
|
};
|
|
4653
5075
|
return this.buildExecutionTransaction(executeOptions);
|
|
@@ -4745,6 +5167,7 @@ class ProgramManager {
|
|
|
4745
5167
|
privateFee,
|
|
4746
5168
|
inputs,
|
|
4747
5169
|
keySearchParams,
|
|
5170
|
+
program,
|
|
4748
5171
|
...additionalOptions,
|
|
4749
5172
|
};
|
|
4750
5173
|
// Check if the account has sufficient credits to pay for the transaction
|
|
@@ -4838,7 +5261,7 @@ class ProgramManager {
|
|
|
4838
5261
|
proverUri: CREDITS_PROGRAM_KEYS.set_validator_state.prover,
|
|
4839
5262
|
verifierUri: CREDITS_PROGRAM_KEYS.set_validator_state.verifier,
|
|
4840
5263
|
cacheKey: "credits.aleo/set_validator_state",
|
|
4841
|
-
}), ...additionalOptions } = options;
|
|
5264
|
+
}), program = this.creditsProgram(), ...additionalOptions } = options;
|
|
4842
5265
|
const executeOptions = {
|
|
4843
5266
|
programName,
|
|
4844
5267
|
functionName,
|
|
@@ -4846,6 +5269,7 @@ class ProgramManager {
|
|
|
4846
5269
|
privateFee,
|
|
4847
5270
|
inputs,
|
|
4848
5271
|
keySearchParams,
|
|
5272
|
+
program,
|
|
4849
5273
|
...additionalOptions,
|
|
4850
5274
|
};
|
|
4851
5275
|
return await this.buildExecutionTransaction(executeOptions);
|
|
@@ -4948,6 +5372,15 @@ class ProgramManager {
|
|
|
4948
5372
|
return false;
|
|
4949
5373
|
}
|
|
4950
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
|
+
|
|
4951
5384
|
/**
|
|
4952
5385
|
* Create a program object from a program's source code
|
|
4953
5386
|
*
|
|
@@ -4982,14 +5415,22 @@ class ProgramManager {
|
|
|
4982
5415
|
// Internal utility function for getting a credits.aleo record
|
|
4983
5416
|
async getCreditsRecord(amount, nonces, record, params) {
|
|
4984
5417
|
try {
|
|
4985
|
-
return record instanceof RecordPlaintext
|
|
4986
|
-
|
|
4987
|
-
|
|
5418
|
+
// return record instanceof RecordPlaintext
|
|
5419
|
+
// ? record
|
|
5420
|
+
// : RecordPlaintext.fromString(<string>record);
|
|
5421
|
+
if (record && record instanceof RecordPlaintext) {
|
|
5422
|
+
record = record.toString();
|
|
5423
|
+
}
|
|
5424
|
+
return ({
|
|
5425
|
+
recordPlaintext: record,
|
|
5426
|
+
programName: 'credits.aleo',
|
|
5427
|
+
recordName: 'credits',
|
|
5428
|
+
});
|
|
4988
5429
|
}
|
|
4989
5430
|
catch (e) {
|
|
4990
5431
|
try {
|
|
4991
5432
|
const recordProvider = this.recordProvider;
|
|
4992
|
-
return
|
|
5433
|
+
return await recordProvider.findCreditsRecord(amount, { ...params, unspent: true, nonces });
|
|
4993
5434
|
}
|
|
4994
5435
|
catch (e) {
|
|
4995
5436
|
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.`);
|
|
@@ -5013,5 +5454,5 @@ async function initializeWasm() {
|
|
|
5013
5454
|
console.warn("initializeWasm is deprecated, you no longer need to use it");
|
|
5014
5455
|
}
|
|
5015
5456
|
|
|
5016
|
-
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 };
|
|
5017
5458
|
//# sourceMappingURL=browser.js.map
|