@provablehq/sdk 0.9.16-rc → 0.9.16
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/account.d.ts +18 -3
- package/dist/mainnet/browser.d.ts +20 -8
- package/dist/mainnet/browser.js +997 -266
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/{testnet/keys/provider → mainnet}/function-key-provider.d.ts +15 -23
- package/dist/mainnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/mainnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/mainnet/models/provingResponse.d.ts +48 -2
- package/dist/mainnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/mainnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +47 -0
- package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +0 -2
- package/dist/mainnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResponse.d.ts +0 -2
- package/dist/mainnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/mainnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/mainnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/mainnet/network-client.d.ts +81 -35
- package/dist/mainnet/node.d.ts +0 -1
- package/dist/mainnet/node.js +2 -129
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/{keys/provider/offline-key-provider.d.ts → offline-key-provider.d.ts} +3 -6
- package/dist/mainnet/program-manager.d.ts +53 -48
- package/dist/mainnet/record-provider.d.ts +7 -7
- package/dist/mainnet/record-scanner.d.ts +231 -31
- package/dist/mainnet/security.d.ts +38 -0
- package/dist/mainnet/utils.d.ts +1 -0
- package/dist/testnet/account.d.ts +18 -3
- package/dist/testnet/browser.d.ts +20 -8
- package/dist/testnet/browser.js +997 -266
- package/dist/testnet/browser.js.map +1 -1
- package/dist/{mainnet/keys/provider → testnet}/function-key-provider.d.ts +15 -23
- package/dist/testnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/testnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/testnet/models/provingResponse.d.ts +48 -2
- package/dist/testnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/testnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/testnet/models/record-scanner/error.d.ts +47 -0
- package/dist/testnet/models/record-scanner/ownedFilter.d.ts +0 -2
- package/dist/testnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/registrationResponse.d.ts +0 -2
- package/dist/testnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/testnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/testnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/testnet/network-client.d.ts +81 -35
- package/dist/testnet/node.d.ts +0 -1
- package/dist/testnet/node.js +2 -129
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/{keys/provider/offline-key-provider.d.ts → offline-key-provider.d.ts} +3 -6
- package/dist/testnet/program-manager.d.ts +53 -48
- package/dist/testnet/record-provider.d.ts +7 -7
- package/dist/testnet/record-scanner.d.ts +231 -31
- package/dist/testnet/security.d.ts +38 -0
- package/dist/testnet/utils.d.ts +1 -0
- package/package.json +3 -2
- package/dist/mainnet/keys/keystore/file.d.ts +0 -23
- package/dist/mainnet/keys/keystore/keystore.d.ts +0 -81
- package/dist/mainnet/keys/keystore/memory.d.ts +0 -8
- package/dist/mainnet/models/keyPair.d.ts +0 -4
- package/dist/testnet/keys/keystore/file.d.ts +0 -23
- package/dist/testnet/keys/keystore/keystore.d.ts +0 -81
- package/dist/testnet/keys/keystore/memory.d.ts +0 -8
- package/dist/testnet/models/keyPair.d.ts +0 -4
package/dist/mainnet/browser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
2
2
|
import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Metadata, VerifyingKey, Program, Plaintext, Transaction, ProvingRequest, ProvingKey, RecordPlaintext, Field, Poseidon4, 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, getOrInitConsensusVersionTestHeights, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
4
|
+
import sodium from 'libsodium-wrappers';
|
|
4
5
|
import { bech32m } from '@scure/base';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -72,6 +73,23 @@ class Account {
|
|
|
72
73
|
throw new Error("Wrong password or invalid ciphertext");
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Validates whether the given input is a valid Aleo address.
|
|
78
|
+
* @param {string | Uint8Array} address The address to validate, either as a string or bytes
|
|
79
|
+
* @returns {boolean} True if the address is valid, false otherwise
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
83
|
+
*
|
|
84
|
+
* const isValid = Account.isValidAddress("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
85
|
+
* console.log(isValid); // true
|
|
86
|
+
*
|
|
87
|
+
* const isInvalid = Account.isValidAddress("invalid_address");
|
|
88
|
+
* console.log(isInvalid); // false
|
|
89
|
+
*/
|
|
90
|
+
static isValidAddress(address) {
|
|
91
|
+
return Address.isValid(address);
|
|
92
|
+
}
|
|
75
93
|
/**
|
|
76
94
|
* Creates a PrivateKey from the provided parameters.
|
|
77
95
|
* @param {AccountParam} params The parameters containing either a private key string or a seed
|
|
@@ -186,7 +204,7 @@ class Account {
|
|
|
186
204
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
187
205
|
*
|
|
188
206
|
* // Create a connection to the Aleo network and an account
|
|
189
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
207
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
190
208
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
191
209
|
*
|
|
192
210
|
* // Get the record ciphertexts from a transaction.
|
|
@@ -215,7 +233,7 @@ class Account {
|
|
|
215
233
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
216
234
|
*
|
|
217
235
|
* // Create a connection to the Aleo network and an account
|
|
218
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
236
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
219
237
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
220
238
|
*
|
|
221
239
|
* // Get the record ciphertexts from a transaction.
|
|
@@ -286,7 +304,7 @@ class Account {
|
|
|
286
304
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
287
305
|
*
|
|
288
306
|
* // Create a connection to the Aleo network and an account
|
|
289
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
307
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
290
308
|
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
291
309
|
*
|
|
292
310
|
* // Get the record ciphertexts from a transaction and check ownership of them.
|
|
@@ -387,6 +405,11 @@ function detectBrowser() {
|
|
|
387
405
|
return "browser";
|
|
388
406
|
}
|
|
389
407
|
}
|
|
408
|
+
function isNode() {
|
|
409
|
+
return typeof process !== "undefined" &&
|
|
410
|
+
process.versions != null &&
|
|
411
|
+
process.versions.node != null;
|
|
412
|
+
}
|
|
390
413
|
function environment() {
|
|
391
414
|
if ((typeof process !== 'undefined') &&
|
|
392
415
|
(process.release?.name === 'node')) {
|
|
@@ -466,6 +489,91 @@ async function retryWithBackoff(fn, { maxAttempts = 5, baseDelay = 100, jitter,
|
|
|
466
489
|
throw new Error("retryWithBackoff: unreachable");
|
|
467
490
|
}
|
|
468
491
|
|
|
492
|
+
/** Type guard: value is a ProvingResponse. */
|
|
493
|
+
function isProvingResponse(value) {
|
|
494
|
+
return (typeof value === "object" &&
|
|
495
|
+
value !== null &&
|
|
496
|
+
"transaction" in value &&
|
|
497
|
+
"broadcast_result" in value &&
|
|
498
|
+
typeof value.broadcast_result === "object");
|
|
499
|
+
}
|
|
500
|
+
/** Type guard: value is a ProveApiErrorBody. */
|
|
501
|
+
function isProveApiErrorBody(value) {
|
|
502
|
+
return (typeof value === "object" &&
|
|
503
|
+
value !== null &&
|
|
504
|
+
"message" in value);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
await sodium.ready;
|
|
508
|
+
/**
|
|
509
|
+
* Encrypt an authorization with a libsodium cryptobox public key.
|
|
510
|
+
*
|
|
511
|
+
* @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
|
|
512
|
+
* @param {Authorization} authorization the authorization to encrypt.
|
|
513
|
+
*
|
|
514
|
+
* @returns {string} the encrypted authorization in RFC 4648 standard Base64.
|
|
515
|
+
*/
|
|
516
|
+
function encryptAuthorization(publicKey, authorization) {
|
|
517
|
+
// Ready the cryptobox lib.
|
|
518
|
+
return encryptMessage(publicKey, authorization.toBytesLe());
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Encrypt a ProvingRequest with a libsodium cryptobox public key.
|
|
522
|
+
*
|
|
523
|
+
* @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
|
|
524
|
+
* @param {Authorization} provingRequest the ProvingRequest to encrypt.
|
|
525
|
+
*
|
|
526
|
+
* @returns {string} the encrypted ProvingRequest in RFC 4648 standard Base64.
|
|
527
|
+
*/
|
|
528
|
+
function encryptProvingRequest(publicKey, provingRequest) {
|
|
529
|
+
return encryptMessage(publicKey, provingRequest.toBytesLe());
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Encrypt a view key with a libsodium cryptobox public key.
|
|
533
|
+
*
|
|
534
|
+
* @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
|
|
535
|
+
* @param {ViewKey} viewKey the view key to encrypt.
|
|
536
|
+
*
|
|
537
|
+
* @returns {string} the encrypted view key in RFC 4648 standard Base64.
|
|
538
|
+
*/
|
|
539
|
+
function encryptViewKey(publicKey, viewKey) {
|
|
540
|
+
return encryptMessage(publicKey, viewKey.toBytesLe());
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Encrypt a record scanner registration request.
|
|
544
|
+
*
|
|
545
|
+
* @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
|
|
546
|
+
* @param {ViewKey} viewKey the view key to encrypt.
|
|
547
|
+
* @param {number} start the start height of the registration request.
|
|
548
|
+
*
|
|
549
|
+
* @returns {string} the encrypted view key in RFC 4648 standard Base64.
|
|
550
|
+
*/
|
|
551
|
+
function encryptRegistrationRequest(publicKey, viewKey, start) {
|
|
552
|
+
// Turn the view key into a Uint8Array.
|
|
553
|
+
const vk_bytes = viewKey.toBytesLe();
|
|
554
|
+
// Create a new array to hold the original bytes and the 4-byte start height.
|
|
555
|
+
const bytes = new Uint8Array(vk_bytes.length + 4);
|
|
556
|
+
// Copy existing bytes.
|
|
557
|
+
bytes.set(vk_bytes, 0);
|
|
558
|
+
// Write the 4-byte number in LE format at the end of the array.
|
|
559
|
+
const view = new DataView(bytes.buffer);
|
|
560
|
+
view.setUint32(vk_bytes.length, start, true);
|
|
561
|
+
// Encrypt the encoded bytes.
|
|
562
|
+
return encryptMessage(publicKey, bytes);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Encrypt arbitrary bytes with a libsodium cryptobox public key.
|
|
566
|
+
*
|
|
567
|
+
* @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
|
|
568
|
+
* @param {Uint8Array} message the bytes to encrypt.
|
|
569
|
+
*
|
|
570
|
+
* @returns {string} the encrypted bytes in RFC 4648 standard Base64.
|
|
571
|
+
*/
|
|
572
|
+
function encryptMessage(publicKey, message) {
|
|
573
|
+
const publicKeyBytes = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
|
|
574
|
+
return sodium.to_base64(sodium.crypto_box_seal(message, publicKeyBytes), sodium.base64_variants.ORIGINAL);
|
|
575
|
+
}
|
|
576
|
+
|
|
469
577
|
const KEY_STORE = Metadata.baseUrl();
|
|
470
578
|
function convert(metadata) {
|
|
471
579
|
// This looks up the method name in VerifyingKey
|
|
@@ -579,7 +687,7 @@ const FIVE_MINUTES = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
|
579
687
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
580
688
|
* const apiKey = process.env.apiKey;
|
|
581
689
|
* const consumerId = process.env.consumerId;
|
|
582
|
-
* const publicNetworkClient = new AleoNetworkClient("
|
|
690
|
+
* const publicNetworkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined, account);
|
|
583
691
|
*/
|
|
584
692
|
class AleoNetworkClient {
|
|
585
693
|
host;
|
|
@@ -591,18 +699,37 @@ class AleoNetworkClient {
|
|
|
591
699
|
apiKey;
|
|
592
700
|
consumerId;
|
|
593
701
|
jwtData;
|
|
702
|
+
proverUri;
|
|
703
|
+
recordScannerUri;
|
|
594
704
|
constructor(host, options) {
|
|
595
705
|
this.host = host + "/mainnet";
|
|
596
706
|
this.network = "mainnet";
|
|
597
707
|
this.ctx = {};
|
|
598
708
|
this.verboseErrors = true;
|
|
599
|
-
if (options
|
|
600
|
-
|
|
709
|
+
if (options) {
|
|
710
|
+
if (options.headers) {
|
|
711
|
+
this.headers = options.headers;
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
this.headers = {
|
|
715
|
+
// This is replaced by the actual version by a Rollup plugin
|
|
716
|
+
"X-Aleo-SDK-Version": "0.9.16",
|
|
717
|
+
"X-Aleo-environment": environment(),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
// If a prover uri was specified, set the prover uri.
|
|
721
|
+
if (options.proverUri) {
|
|
722
|
+
this.proverUri = options.proverUri + "/mainnet";
|
|
723
|
+
}
|
|
724
|
+
// If a record scanner uri was specified, set the record scanner uri.
|
|
725
|
+
if (options.recordScannerUri) {
|
|
726
|
+
this.recordScannerUri = options.recordScannerUri + "/mainnet";
|
|
727
|
+
}
|
|
601
728
|
}
|
|
602
729
|
else {
|
|
603
730
|
this.headers = {
|
|
604
731
|
// This is replaced by the actual version by a Rollup plugin
|
|
605
|
-
"X-Aleo-SDK-Version": "0.9.16
|
|
732
|
+
"X-Aleo-SDK-Version": "0.9.16",
|
|
606
733
|
"X-Aleo-environment": environment(),
|
|
607
734
|
};
|
|
608
735
|
}
|
|
@@ -614,7 +741,7 @@ class AleoNetworkClient {
|
|
|
614
741
|
* @example
|
|
615
742
|
* import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
616
743
|
*
|
|
617
|
-
* const networkClient = new AleoNetworkClient("
|
|
744
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
618
745
|
* const account = new Account();
|
|
619
746
|
* networkClient.setAccount(account);
|
|
620
747
|
*/
|
|
@@ -642,11 +769,45 @@ class AleoNetworkClient {
|
|
|
642
769
|
* const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined);
|
|
643
770
|
*
|
|
644
771
|
* // Set the host to a public node.
|
|
645
|
-
* networkClient.setHost("
|
|
772
|
+
* networkClient.setHost("https://api.provable.com/v2");
|
|
646
773
|
*/
|
|
647
774
|
setHost(host) {
|
|
648
775
|
this.host = host + "/mainnet";
|
|
649
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Set a new uri for a remote prover.
|
|
779
|
+
*
|
|
780
|
+
* @param {string} proverUri The uri of the remote prover.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
784
|
+
*
|
|
785
|
+
* // Create a networkClient that connects to the provable explorer api.
|
|
786
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
787
|
+
*
|
|
788
|
+
* // Set the prover uri.
|
|
789
|
+
* networkClient.setProverUri("https://prover.provable.prove");
|
|
790
|
+
*/
|
|
791
|
+
setProverUri(proverUri) {
|
|
792
|
+
this.proverUri = proverUri + "/mainnet";
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Set a new uri for a remote record scanner.
|
|
796
|
+
*
|
|
797
|
+
* @param {string} recordScannerUri The uri of the remote record scanner.
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
801
|
+
*
|
|
802
|
+
* // Create a networkClient that connects to the provable explorer api.
|
|
803
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
804
|
+
*
|
|
805
|
+
* // Set the record scanner uri.
|
|
806
|
+
* networkClient.setRecordScannerUri("https://scanner.provable.scan");
|
|
807
|
+
*/
|
|
808
|
+
setRecordScannerUri(recordScannerUri) {
|
|
809
|
+
this.recordScannerUri = recordScannerUri + "/mainnet";
|
|
810
|
+
}
|
|
650
811
|
/**
|
|
651
812
|
* 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.
|
|
652
813
|
*
|
|
@@ -753,7 +914,7 @@ class AleoNetworkClient {
|
|
|
753
914
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
754
915
|
*
|
|
755
916
|
* // Create a network client.
|
|
756
|
-
* const networkClient = new AleoNetworkClient("
|
|
917
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
757
918
|
* networkClient.setAccount(account);
|
|
758
919
|
*
|
|
759
920
|
* // Find specific amounts
|
|
@@ -976,7 +1137,7 @@ class AleoNetworkClient {
|
|
|
976
1137
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
977
1138
|
*
|
|
978
1139
|
* // Create a network client and set an account to search for records with.
|
|
979
|
-
* const networkClient = new AleoNetworkClient("
|
|
1140
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
980
1141
|
* networkClient.setAccount(account);
|
|
981
1142
|
*
|
|
982
1143
|
* // Find specific amounts
|
|
@@ -1032,7 +1193,7 @@ class AleoNetworkClient {
|
|
|
1032
1193
|
* @example
|
|
1033
1194
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1034
1195
|
*
|
|
1035
|
-
* const networkClient = new AleoNetworkClient("
|
|
1196
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1036
1197
|
* const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
1037
1198
|
*/
|
|
1038
1199
|
async getBlockByHash(blockHash) {
|
|
@@ -1090,7 +1251,7 @@ class AleoNetworkClient {
|
|
|
1090
1251
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
1091
1252
|
*
|
|
1092
1253
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
1093
|
-
* const networkClient = new AleoNetworkClient("
|
|
1254
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1094
1255
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
1095
1256
|
*
|
|
1096
1257
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -1125,7 +1286,7 @@ class AleoNetworkClient {
|
|
|
1125
1286
|
* import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js";
|
|
1126
1287
|
*
|
|
1127
1288
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
1128
|
-
* const networkClient = new AleoNetworkClient("
|
|
1289
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1129
1290
|
* const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo");
|
|
1130
1291
|
*
|
|
1131
1292
|
* // Get the verifying keys for each function in the deployment.
|
|
@@ -1158,7 +1319,7 @@ class AleoNetworkClient {
|
|
|
1158
1319
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
1159
1320
|
*
|
|
1160
1321
|
* // Get the transaction ID of the deployment transaction for a program.
|
|
1161
|
-
* const networkClient = new AleoNetworkClient("
|
|
1322
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1162
1323
|
* const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
|
|
1163
1324
|
*
|
|
1164
1325
|
* // Get the transaction data for the deployment transaction.
|
|
@@ -1189,7 +1350,7 @@ class AleoNetworkClient {
|
|
|
1189
1350
|
* import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
|
|
1190
1351
|
*
|
|
1191
1352
|
* // Create a network client.
|
|
1192
|
-
* const networkClient = new AleoNetworkClient("
|
|
1353
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1193
1354
|
*
|
|
1194
1355
|
* const latestHeight = networkClient.getLatestBlock();
|
|
1195
1356
|
*/
|
|
@@ -1214,10 +1375,10 @@ class AleoNetworkClient {
|
|
|
1214
1375
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1215
1376
|
*
|
|
1216
1377
|
* // Create a network client.
|
|
1217
|
-
* const networkClient = new AleoNetworkClient("
|
|
1378
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1218
1379
|
*
|
|
1219
1380
|
* // Create a network client and get the latest committee.
|
|
1220
|
-
* const networkClient = new AleoNetworkClient("
|
|
1381
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1221
1382
|
* const latestCommittee = await networkClient.getLatestCommittee();
|
|
1222
1383
|
*/
|
|
1223
1384
|
async getLatestCommittee() {
|
|
@@ -1242,10 +1403,10 @@ class AleoNetworkClient {
|
|
|
1242
1403
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1243
1404
|
*
|
|
1244
1405
|
* // Create a network client.
|
|
1245
|
-
* const networkClient = new AleoNetworkClient("
|
|
1406
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1246
1407
|
*
|
|
1247
1408
|
* // Create a network client and get the committee for a specific block.
|
|
1248
|
-
* const networkClient = new AleoNetworkClient("
|
|
1409
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1249
1410
|
* const committee = await networkClient.getCommitteeByBlockHeight(1234);
|
|
1250
1411
|
*/
|
|
1251
1412
|
async getCommitteeByBlockHeight(blockHeight) {
|
|
@@ -1269,7 +1430,7 @@ class AleoNetworkClient {
|
|
|
1269
1430
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1270
1431
|
*
|
|
1271
1432
|
* // Create a network client.
|
|
1272
|
-
* const networkClient = new AleoNetworkClient("
|
|
1433
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1273
1434
|
*
|
|
1274
1435
|
* const latestHeight = networkClient.getLatestHeight();
|
|
1275
1436
|
*/
|
|
@@ -1294,7 +1455,7 @@ class AleoNetworkClient {
|
|
|
1294
1455
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1295
1456
|
*
|
|
1296
1457
|
* // Create a network client.
|
|
1297
|
-
* const networkClient = new AleoNetworkClient("
|
|
1458
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1298
1459
|
*
|
|
1299
1460
|
* // Get the latest block hash.
|
|
1300
1461
|
* const latestHash = networkClient.getLatestBlockHash();
|
|
@@ -1322,7 +1483,7 @@ class AleoNetworkClient {
|
|
|
1322
1483
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1323
1484
|
*
|
|
1324
1485
|
* // Create a network client.
|
|
1325
|
-
* const networkClient = new AleoNetworkClient("
|
|
1486
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1326
1487
|
*
|
|
1327
1488
|
* // Get the source code of a program.)
|
|
1328
1489
|
* @returns {Promise<string>} Source code of the program
|
|
@@ -1331,7 +1492,7 @@ class AleoNetworkClient {
|
|
|
1331
1492
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1332
1493
|
*
|
|
1333
1494
|
* // Create a network client.
|
|
1334
|
-
* const networkClient = new AleoNetworkClient("
|
|
1495
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1335
1496
|
*
|
|
1336
1497
|
* const program = networkClient.getProgram("hello_hello.aleo");
|
|
1337
1498
|
* const expectedSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
|
|
@@ -1364,7 +1525,7 @@ class AleoNetworkClient {
|
|
|
1364
1525
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1365
1526
|
*
|
|
1366
1527
|
* // Create a network client.
|
|
1367
|
-
* const networkClient = new AleoNetworkClient("
|
|
1528
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1368
1529
|
*
|
|
1369
1530
|
* const programVersion = networkClient.getLatestProgramEdition("hello_hello.aleo");
|
|
1370
1531
|
* assert.equal(programVersion, 1);
|
|
@@ -1393,7 +1554,7 @@ class AleoNetworkClient {
|
|
|
1393
1554
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1394
1555
|
*
|
|
1395
1556
|
* // Create a network client.
|
|
1396
|
-
* const networkClient = new AleoNetworkClient("
|
|
1557
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1397
1558
|
*
|
|
1398
1559
|
* const programID = "hello_hello.aleo";
|
|
1399
1560
|
* const programSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
|
|
@@ -1433,7 +1594,7 @@ class AleoNetworkClient {
|
|
|
1433
1594
|
* }
|
|
1434
1595
|
*
|
|
1435
1596
|
* // Create a network client.
|
|
1436
|
-
* const networkClient = new AleoNetworkClient("
|
|
1597
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1437
1598
|
*
|
|
1438
1599
|
* // Imports can be fetched using the program ID, source code, or program object
|
|
1439
1600
|
* let programImports = await networkClient.getProgramImports("double_test.aleo");
|
|
@@ -1503,7 +1664,7 @@ class AleoNetworkClient {
|
|
|
1503
1664
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1504
1665
|
*
|
|
1505
1666
|
* // Create a network client.
|
|
1506
|
-
* const networkClient = new AleoNetworkClient("
|
|
1667
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1507
1668
|
*
|
|
1508
1669
|
* const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo");
|
|
1509
1670
|
* const expectedImportsNames = ["credits.aleo"];
|
|
@@ -1534,7 +1695,7 @@ class AleoNetworkClient {
|
|
|
1534
1695
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1535
1696
|
*
|
|
1536
1697
|
* // Create a network client.
|
|
1537
|
-
* const networkClient = new AleoNetworkClient("
|
|
1698
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1538
1699
|
*
|
|
1539
1700
|
* const mappings = networkClient.getProgramMappingNames("credits.aleo");
|
|
1540
1701
|
* const expectedMappings = [
|
|
@@ -1572,7 +1733,7 @@ class AleoNetworkClient {
|
|
|
1572
1733
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1573
1734
|
*
|
|
1574
1735
|
* // Create a network client.
|
|
1575
|
-
* const networkClient = new AleoNetworkClient("
|
|
1736
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1576
1737
|
*
|
|
1577
1738
|
* // Get public balance of an account
|
|
1578
1739
|
* const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -1604,7 +1765,7 @@ class AleoNetworkClient {
|
|
|
1604
1765
|
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
|
|
1605
1766
|
*
|
|
1606
1767
|
* // Create a network client.
|
|
1607
|
-
* const networkClient = new AleoNetworkClient("
|
|
1768
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1608
1769
|
*
|
|
1609
1770
|
* // Get the bond state as an account.
|
|
1610
1771
|
* const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
|
|
@@ -1650,7 +1811,7 @@ class AleoNetworkClient {
|
|
|
1650
1811
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1651
1812
|
*
|
|
1652
1813
|
* // Create a network client.
|
|
1653
|
-
* const networkClient = new AleoNetworkClient("
|
|
1814
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1654
1815
|
*
|
|
1655
1816
|
* // Get the balance of an account from either an address object or address string.
|
|
1656
1817
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
@@ -1681,7 +1842,7 @@ class AleoNetworkClient {
|
|
|
1681
1842
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1682
1843
|
*
|
|
1683
1844
|
* // Create a network client.
|
|
1684
|
-
* const networkClient = new AleoNetworkClient("
|
|
1845
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1685
1846
|
*
|
|
1686
1847
|
* // Get the latest state root.
|
|
1687
1848
|
* const stateRoot = networkClient.getStateRoot();
|
|
@@ -1708,7 +1869,7 @@ class AleoNetworkClient {
|
|
|
1708
1869
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1709
1870
|
*
|
|
1710
1871
|
* // Create a network client.
|
|
1711
|
-
* const networkClient = new AleoNetworkClient("
|
|
1872
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1712
1873
|
*
|
|
1713
1874
|
* const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
1714
1875
|
*/
|
|
@@ -1734,7 +1895,7 @@ class AleoNetworkClient {
|
|
|
1734
1895
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1735
1896
|
*
|
|
1736
1897
|
* // Create a network client.
|
|
1737
|
-
* const networkClient = new AleoNetworkClient("
|
|
1898
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1738
1899
|
*
|
|
1739
1900
|
* const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
|
|
1740
1901
|
* assert.equal(transaction.status, "confirmed");
|
|
@@ -1799,7 +1960,7 @@ class AleoNetworkClient {
|
|
|
1799
1960
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1800
1961
|
*
|
|
1801
1962
|
* // Create a network client.
|
|
1802
|
-
* const networkClient = new AleoNetworkClient("
|
|
1963
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1803
1964
|
*
|
|
1804
1965
|
* const transactions = networkClient.getTransactions(654);
|
|
1805
1966
|
*/
|
|
@@ -1825,7 +1986,7 @@ class AleoNetworkClient {
|
|
|
1825
1986
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1826
1987
|
*
|
|
1827
1988
|
* // Create a network client.
|
|
1828
|
-
* const networkClient = new AleoNetworkClient("
|
|
1989
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1829
1990
|
*
|
|
1830
1991
|
* const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
|
|
1831
1992
|
*/
|
|
@@ -1852,7 +2013,7 @@ class AleoNetworkClient {
|
|
|
1852
2013
|
* import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
|
|
1853
2014
|
*
|
|
1854
2015
|
* // Create a network client.
|
|
1855
|
-
* const networkClient = new AleoNetworkClient("
|
|
2016
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
1856
2017
|
*
|
|
1857
2018
|
* // Get the current transactions in the mempool.
|
|
1858
2019
|
* const transactions = networkClient.getTransactionsInMempool();
|
|
@@ -1972,33 +2133,87 @@ class AleoNetworkClient {
|
|
|
1972
2133
|
};
|
|
1973
2134
|
}
|
|
1974
2135
|
/**
|
|
1975
|
-
*
|
|
2136
|
+
* Parses a /prove or /prove/encrypted response. Returns a result object (never throws for 200/400/500/503).
|
|
2137
|
+
*/
|
|
2138
|
+
async handleProvingResponse(response) {
|
|
2139
|
+
// Get the proving response text.
|
|
2140
|
+
const text = await response.text();
|
|
2141
|
+
let body;
|
|
2142
|
+
// Parse the body.
|
|
2143
|
+
try {
|
|
2144
|
+
body = parseJSON(text);
|
|
2145
|
+
}
|
|
2146
|
+
catch {
|
|
2147
|
+
body = {};
|
|
2148
|
+
}
|
|
2149
|
+
// If the status is 200, attempt to parse the Proving Request along its expected structure.
|
|
2150
|
+
if (response.status === 200) {
|
|
2151
|
+
if (isProvingResponse(body)) {
|
|
2152
|
+
return { ok: true, data: body };
|
|
2153
|
+
}
|
|
2154
|
+
return {
|
|
2155
|
+
ok: false,
|
|
2156
|
+
status: response.status,
|
|
2157
|
+
error: { message: "Invalid response from proving service" },
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
// If the response is non 200, return the information back to the caller so it can be handled.
|
|
2161
|
+
if (response.status === 400 || response.status === 500 || response.status === 503) {
|
|
2162
|
+
const error = isProveApiErrorBody(body)
|
|
2163
|
+
? body
|
|
2164
|
+
: { message: text || `${response.status} error` };
|
|
2165
|
+
return { ok: false, status: response.status, error };
|
|
2166
|
+
}
|
|
2167
|
+
return {
|
|
2168
|
+
ok: false,
|
|
2169
|
+
status: response.status,
|
|
2170
|
+
error: { message: text || `${response.status} error` },
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* 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. Throws on HTTP 400, 500, 503 (and retries on 500/503). Callers should {@link submitProvingRequestSafe} to handle proving request failures without throwing.
|
|
1976
2175
|
*
|
|
1977
2176
|
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
|
|
1978
2177
|
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
|
|
1979
2178
|
*/
|
|
1980
2179
|
async submitProvingRequest(options) {
|
|
1981
|
-
const
|
|
2180
|
+
const result = await this.submitProvingRequestSafe(options);
|
|
2181
|
+
if (result.ok) {
|
|
2182
|
+
return result.data;
|
|
2183
|
+
}
|
|
2184
|
+
const err = new Error(result.error.message);
|
|
2185
|
+
err.status = result.status;
|
|
2186
|
+
throw err;
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Submit a proving request and return a result object instead of throwing. This method is usable when callers want to handle HTTP status (400, 500, 503) yourself. Retries on 500/503 and returns on 200 or 400.
|
|
2190
|
+
*
|
|
2191
|
+
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
|
|
2192
|
+
* @returns {Promise<ProvingResult>} `{ ok: true, data }` on success (200), or `{ ok: false, status, error }` on 400/500/503. Check `result.ok` and then either `result.data` or `result.status` / `result.error.message`.
|
|
2193
|
+
*/
|
|
2194
|
+
async submitProvingRequestSafe(options) {
|
|
2195
|
+
// Attempt to get the Prover URI first from the options, then from any configured globally, or third try the main configured host.
|
|
2196
|
+
const proverUri = (options.url ?? this.proverUri) ?? this.host;
|
|
1982
2197
|
const provingRequestString = options.provingRequest instanceof ProvingRequest
|
|
1983
2198
|
? options.provingRequest.toString()
|
|
1984
2199
|
: options.provingRequest;
|
|
2200
|
+
// Try to get JWT data to access the Provable API.
|
|
1985
2201
|
const apiKey = options.apiKey ?? this.apiKey;
|
|
1986
2202
|
const consumerId = options.consumerId ?? this.consumerId;
|
|
1987
2203
|
let jwtData = options.jwtData ?? this.jwtData;
|
|
1988
|
-
// Check if JWT
|
|
1989
|
-
const
|
|
1990
|
-
const isExpired = jwtData && Date.now() >= jwtData.expiration - bufferTime;
|
|
2204
|
+
// Check to see if the JWT needs refreshing.
|
|
2205
|
+
const isExpired = jwtData && Date.now() >= jwtData.expiration - FIVE_MINUTES;
|
|
1991
2206
|
if (!jwtData || isExpired) {
|
|
1992
2207
|
if (options.apiKey && options.consumerId) {
|
|
1993
2208
|
jwtData = await this.refreshJwt(apiKey, consumerId);
|
|
1994
|
-
// Update both the class and the options with the new JWT
|
|
1995
2209
|
this.jwtData = jwtData;
|
|
1996
2210
|
options.jwtData = jwtData;
|
|
1997
2211
|
}
|
|
1998
2212
|
else {
|
|
1999
|
-
|
|
2213
|
+
console.warn('JWT or both apiKey and consumerId are required when using the Provable API');
|
|
2000
2214
|
}
|
|
2001
2215
|
}
|
|
2216
|
+
// Create the necessary headers to hit the provable api.
|
|
2002
2217
|
const headers = {
|
|
2003
2218
|
...this.headers,
|
|
2004
2219
|
"X-ALEO-METHOD": "submitProvingRequest",
|
|
@@ -2007,17 +2222,75 @@ class AleoNetworkClient {
|
|
|
2007
2222
|
if (jwtData?.jwt) {
|
|
2008
2223
|
headers["Authorization"] = jwtData.jwt;
|
|
2009
2224
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2225
|
+
// Encapsulate the requests in a locally scoped function that can be run with a retry closure.
|
|
2226
|
+
const runRequest = async () => {
|
|
2227
|
+
// If DPS privacy is set, call invoke the encrypted flow.
|
|
2228
|
+
if (options.dpsPrivacy) {
|
|
2229
|
+
// Get an ephemeral public key from a DPS service.
|
|
2230
|
+
const pubKeyResponse = await get(proverUri + "/pubkey", {
|
|
2231
|
+
headers,
|
|
2232
|
+
credentials: "include",
|
|
2233
|
+
});
|
|
2234
|
+
// Encrypt the provingRequest.
|
|
2235
|
+
const pubkey = parseJSON(await pubKeyResponse.text());
|
|
2236
|
+
const ciphertext = encryptProvingRequest(pubkey.public_key, ProvingRequest.fromString(provingRequestString));
|
|
2237
|
+
// Form the expected query a DPS service expects (including the key_id).
|
|
2238
|
+
const payload = {
|
|
2239
|
+
key_id: pubkey.key_id,
|
|
2240
|
+
ciphertext: ciphertext,
|
|
2241
|
+
};
|
|
2242
|
+
// We're in node, attempt to set the cookie manually.
|
|
2243
|
+
const cookie = isNode() ? pubKeyResponse.headers.get("set-cookie") : undefined;
|
|
2244
|
+
// Send the encrypted proving request to the DPS service.
|
|
2245
|
+
const res = await fetch(`${proverUri}/prove/encrypted`, {
|
|
2246
|
+
method: "POST",
|
|
2247
|
+
body: JSON.stringify(payload),
|
|
2248
|
+
headers: {
|
|
2249
|
+
...headers,
|
|
2250
|
+
...(cookie ? { Cookie: cookie } : {})
|
|
2251
|
+
},
|
|
2252
|
+
credentials: "include",
|
|
2253
|
+
});
|
|
2254
|
+
// Properly handle the proving response.
|
|
2255
|
+
return this.handleProvingResponse(res);
|
|
2256
|
+
}
|
|
2257
|
+
// If encrypted usage is not specified use the unencrypted endpoint.
|
|
2258
|
+
const proveEndpoint = proverUri.endsWith("/prove")
|
|
2259
|
+
? proverUri
|
|
2260
|
+
: proverUri + "/prove";
|
|
2261
|
+
const res = await fetch(proveEndpoint, {
|
|
2262
|
+
method: "POST",
|
|
2012
2263
|
body: provingRequestString,
|
|
2013
|
-
headers
|
|
2014
|
-
})
|
|
2015
|
-
|
|
2016
|
-
return
|
|
2264
|
+
headers,
|
|
2265
|
+
});
|
|
2266
|
+
// Properly handle the proving response.
|
|
2267
|
+
return this.handleProvingResponse(res);
|
|
2268
|
+
};
|
|
2269
|
+
try {
|
|
2270
|
+
// Run the request with retries.
|
|
2271
|
+
return await retryWithBackoff(async () => {
|
|
2272
|
+
// Run the encrypted or non-encrypted flow as specified by the flags.
|
|
2273
|
+
const result = await runRequest();
|
|
2274
|
+
if (result.ok) {
|
|
2275
|
+
return result;
|
|
2276
|
+
}
|
|
2277
|
+
// If 500s are hit responses are returned, attempt retries.
|
|
2278
|
+
if (result.status === 500 || result.status === 503) {
|
|
2279
|
+
const err = new Error(result.error.message);
|
|
2280
|
+
err.status = result.status;
|
|
2281
|
+
throw err;
|
|
2282
|
+
}
|
|
2283
|
+
return result;
|
|
2284
|
+
});
|
|
2017
2285
|
}
|
|
2018
|
-
catch (
|
|
2019
|
-
|
|
2020
|
-
|
|
2286
|
+
catch (err) {
|
|
2287
|
+
// If an error is returned, provide usable information to the caller.
|
|
2288
|
+
const e = err;
|
|
2289
|
+
return {
|
|
2290
|
+
ok: false,
|
|
2291
|
+
status: e.status ?? 500,
|
|
2292
|
+
error: { message: e.message },
|
|
2293
|
+
};
|
|
2021
2294
|
}
|
|
2022
2295
|
}
|
|
2023
2296
|
/**
|
|
@@ -2032,7 +2305,7 @@ class AleoNetworkClient {
|
|
|
2032
2305
|
* import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2033
2306
|
*
|
|
2034
2307
|
* // Create a network client and program manager.
|
|
2035
|
-
* const networkClient = new AleoNetworkClient("
|
|
2308
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined);
|
|
2036
2309
|
* const programManager = new ProgramManager(networkClient);
|
|
2037
2310
|
*
|
|
2038
2311
|
* // Set the account for the program manager.
|
|
@@ -2103,45 +2376,61 @@ class AleoNetworkClient {
|
|
|
2103
2376
|
}
|
|
2104
2377
|
|
|
2105
2378
|
/**
|
|
2106
|
-
*
|
|
2107
|
-
*
|
|
2108
|
-
* @returns {KeyStore} The map decorated as a keystore.
|
|
2379
|
+
* Error thrown when a record scanner request fails (e.g. /register, /register/encrypted).
|
|
2380
|
+
* Includes HTTP status so callers can handle 422 vs 500 etc.
|
|
2109
2381
|
*/
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2382
|
+
class RecordScannerRequestError extends Error {
|
|
2383
|
+
status;
|
|
2384
|
+
constructor(message, status) {
|
|
2385
|
+
super(message);
|
|
2386
|
+
this.name = "RecordScannerRequestError";
|
|
2387
|
+
this.status = status;
|
|
2388
|
+
Object.setPrototypeOf(this, RecordScannerRequestError.prototype);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
/** Error thrown when findCreditsRecord or findCreditsRecords is called but decryption is not enabled on the record scanner. */
|
|
2392
|
+
class DecryptionNotEnabledError extends Error {
|
|
2393
|
+
filter;
|
|
2394
|
+
constructor(message, filter) {
|
|
2395
|
+
super(message);
|
|
2396
|
+
this.name = "DecryptionNotEnabledError";
|
|
2397
|
+
this.filter = filter;
|
|
2398
|
+
Object.setPrototypeOf(this, DecryptionNotEnabledError.prototype);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
/** Error thrown when findCreditsRecord or findCreditsRecords is called but no view key for the UUID is stored in viewKeys or the account. */
|
|
2402
|
+
class ViewKeyNotStoredError extends Error {
|
|
2403
|
+
uuid;
|
|
2404
|
+
filter;
|
|
2405
|
+
constructor(message, uuid, filter) {
|
|
2406
|
+
super(message);
|
|
2407
|
+
this.name = "ViewKeyNotStoredError";
|
|
2408
|
+
this.uuid = uuid;
|
|
2409
|
+
this.filter = filter;
|
|
2410
|
+
Object.setPrototypeOf(this, ViewKeyNotStoredError.prototype);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
/** Error thrown when no record matches the supplied search filter (e.g. findCreditsRecord / findCreditsRecords). */
|
|
2414
|
+
class RecordNotFoundError extends Error {
|
|
2415
|
+
filter;
|
|
2416
|
+
constructor(message, filter) {
|
|
2417
|
+
super(message);
|
|
2418
|
+
this.name = "RecordNotFoundError";
|
|
2419
|
+
this.filter = filter;
|
|
2420
|
+
Object.setPrototypeOf(this, RecordNotFoundError.prototype);
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
/** Error thrown when a record scanner request fails due to an invalid response. */
|
|
2424
|
+
class UUIDError extends Error {
|
|
2425
|
+
uuid;
|
|
2426
|
+
filter;
|
|
2427
|
+
constructor(message, uuid, filter) {
|
|
2428
|
+
super(message);
|
|
2429
|
+
this.name = "InvalidResponseError";
|
|
2430
|
+
this.uuid = uuid;
|
|
2431
|
+
this.filter = filter;
|
|
2432
|
+
Object.setPrototypeOf(this, UUIDError.prototype);
|
|
2433
|
+
}
|
|
2145
2434
|
}
|
|
2146
2435
|
|
|
2147
2436
|
/**
|
|
@@ -2192,11 +2481,6 @@ class AleoKeyProvider {
|
|
|
2192
2481
|
this.cache = new Map();
|
|
2193
2482
|
this.cacheOption = false;
|
|
2194
2483
|
}
|
|
2195
|
-
keyStore() {
|
|
2196
|
-
if (!this.cacheOption)
|
|
2197
|
-
return Promise.resolve(undefined);
|
|
2198
|
-
return Promise.resolve(promoteMapToKeyStore(this.cache));
|
|
2199
|
-
}
|
|
2200
2484
|
/**
|
|
2201
2485
|
* Use local memory to store keys
|
|
2202
2486
|
*
|
|
@@ -2249,11 +2533,8 @@ class AleoKeyProvider {
|
|
|
2249
2533
|
getKeys(keyId) {
|
|
2250
2534
|
console.debug(`Checking if key exists in cache. KeyId: ${keyId}`);
|
|
2251
2535
|
if (this.cache.has(keyId)) {
|
|
2252
|
-
const [provingKeyBytes, verifyingKeyBytes] =
|
|
2253
|
-
return [
|
|
2254
|
-
ProvingKey.fromBytes(provingKeyBytes),
|
|
2255
|
-
VerifyingKey.fromBytes(verifyingKeyBytes),
|
|
2256
|
-
];
|
|
2536
|
+
const [provingKeyBytes, verifyingKeyBytes] = this.cache.get(keyId);
|
|
2537
|
+
return [ProvingKey.fromBytes(provingKeyBytes), VerifyingKey.fromBytes(verifyingKeyBytes)];
|
|
2257
2538
|
}
|
|
2258
2539
|
else {
|
|
2259
2540
|
throw new Error("Key not found in cache.");
|
|
@@ -2267,12 +2548,12 @@ class AleoKeyProvider {
|
|
|
2267
2548
|
*
|
|
2268
2549
|
* @example
|
|
2269
2550
|
* // Create a new object which implements the KeyProvider interface
|
|
2270
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
2551
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
2271
2552
|
* const keyProvider = new AleoKeyProvider();
|
|
2272
2553
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2273
2554
|
*
|
|
2274
2555
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
2275
|
-
* const programManager = new ProgramManager("https://api.
|
|
2556
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
2276
2557
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
2277
2558
|
*
|
|
2278
2559
|
* // Keys can also be fetched manually using the key provider
|
|
@@ -2288,12 +2569,10 @@ class AleoKeyProvider {
|
|
|
2288
2569
|
let key = CREDITS_PROGRAM_KEYS.getKey(params["name"]);
|
|
2289
2570
|
return this.fetchCreditsKeys(key);
|
|
2290
2571
|
}
|
|
2291
|
-
if ("proverUri" in params &&
|
|
2292
|
-
typeof params["proverUri"] == "string") {
|
|
2572
|
+
if ("proverUri" in params && typeof params["proverUri"] == "string") {
|
|
2293
2573
|
proverUrl = params["proverUri"];
|
|
2294
2574
|
}
|
|
2295
|
-
if ("verifierUri" in params &&
|
|
2296
|
-
typeof params["verifierUri"] == "string") {
|
|
2575
|
+
if ("verifierUri" in params && typeof params["verifierUri"] == "string") {
|
|
2297
2576
|
verifierUrl = params["verifierUri"];
|
|
2298
2577
|
}
|
|
2299
2578
|
if ("cacheKey" in params && typeof params["cacheKey"] == "string") {
|
|
@@ -2319,12 +2598,12 @@ class AleoKeyProvider {
|
|
|
2319
2598
|
*
|
|
2320
2599
|
* @example
|
|
2321
2600
|
* // Create a new AleoKeyProvider object
|
|
2322
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
2601
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
2323
2602
|
* const keyProvider = new AleoKeyProvider();
|
|
2324
2603
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2325
2604
|
*
|
|
2326
2605
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
2327
|
-
* const programManager = new ProgramManager("https://api.
|
|
2606
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
2328
2607
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
2329
2608
|
*
|
|
2330
2609
|
* // Keys can also be fetched manually
|
|
@@ -2342,26 +2621,20 @@ class AleoKeyProvider {
|
|
|
2342
2621
|
}
|
|
2343
2622
|
const value = this.cache.get(cacheKey);
|
|
2344
2623
|
if (typeof value !== "undefined") {
|
|
2345
|
-
return [
|
|
2346
|
-
ProvingKey.fromBytes(value[0]),
|
|
2347
|
-
VerifyingKey.fromBytes(value[1]),
|
|
2348
|
-
];
|
|
2624
|
+
return [ProvingKey.fromBytes(value[0]), VerifyingKey.fromBytes(value[1])];
|
|
2349
2625
|
}
|
|
2350
2626
|
else {
|
|
2351
2627
|
console.debug("Fetching proving keys from url " + proverUrl);
|
|
2352
|
-
const provingKey =
|
|
2628
|
+
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2353
2629
|
console.debug("Fetching verifying keys " + verifierUrl);
|
|
2354
2630
|
const verifyingKey = (await this.getVerifyingKey(verifierUrl));
|
|
2355
|
-
this.cache.set(cacheKey, [
|
|
2356
|
-
provingKey.toBytes(),
|
|
2357
|
-
verifyingKey.toBytes(),
|
|
2358
|
-
]);
|
|
2631
|
+
this.cache.set(cacheKey, [provingKey.toBytes(), verifyingKey.toBytes()]);
|
|
2359
2632
|
return [provingKey, verifyingKey];
|
|
2360
2633
|
}
|
|
2361
2634
|
}
|
|
2362
2635
|
else {
|
|
2363
2636
|
// If cache is disabled, fetch the keys and return them
|
|
2364
|
-
const provingKey =
|
|
2637
|
+
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2365
2638
|
const verifyingKey = (await this.getVerifyingKey(verifierUrl));
|
|
2366
2639
|
return [provingKey, verifyingKey];
|
|
2367
2640
|
}
|
|
@@ -2391,12 +2664,12 @@ class AleoKeyProvider {
|
|
|
2391
2664
|
}
|
|
2392
2665
|
else {
|
|
2393
2666
|
console.debug("Fetching proving keys from url " + proverUrl);
|
|
2394
|
-
const provingKey =
|
|
2667
|
+
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2395
2668
|
return provingKey;
|
|
2396
2669
|
}
|
|
2397
2670
|
}
|
|
2398
2671
|
else {
|
|
2399
|
-
const provingKey =
|
|
2672
|
+
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2400
2673
|
return provingKey;
|
|
2401
2674
|
}
|
|
2402
2675
|
}
|
|
@@ -2408,7 +2681,7 @@ class AleoKeyProvider {
|
|
|
2408
2681
|
try {
|
|
2409
2682
|
if (!this.cache.has(key.locator) || !this.cacheOption) {
|
|
2410
2683
|
const verifying_key = key.verifyingKey();
|
|
2411
|
-
const proving_key =
|
|
2684
|
+
const proving_key = await this.fetchProvingKey(key.prover, key.locator);
|
|
2412
2685
|
if (this.cacheOption) {
|
|
2413
2686
|
this.cache.set(CREDITS_PROGRAM_KEYS.getKey(key.name).locator, [proving_key.toBytes(), verifying_key.toBytes()]);
|
|
2414
2687
|
}
|
|
@@ -2416,10 +2689,7 @@ class AleoKeyProvider {
|
|
|
2416
2689
|
}
|
|
2417
2690
|
else {
|
|
2418
2691
|
const keyPair = this.cache.get(key.locator);
|
|
2419
|
-
return [
|
|
2420
|
-
ProvingKey.fromBytes(keyPair[0]),
|
|
2421
|
-
VerifyingKey.fromBytes(keyPair[1]),
|
|
2422
|
-
];
|
|
2692
|
+
return [ProvingKey.fromBytes(keyPair[0]), VerifyingKey.fromBytes(keyPair[1])];
|
|
2423
2693
|
}
|
|
2424
2694
|
}
|
|
2425
2695
|
catch (error) {
|
|
@@ -2442,12 +2712,12 @@ class AleoKeyProvider {
|
|
|
2442
2712
|
*
|
|
2443
2713
|
* @example
|
|
2444
2714
|
* // Create a new AleoKeyProvider
|
|
2445
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
2715
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
2446
2716
|
* const keyProvider = new AleoKeyProvider();
|
|
2447
2717
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2448
2718
|
*
|
|
2449
2719
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
2450
|
-
* const programManager = new ProgramManager("https://api.
|
|
2720
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
2451
2721
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
2452
2722
|
*
|
|
2453
2723
|
* // Keys can also be fetched manually
|
|
@@ -2569,7 +2839,7 @@ class AleoKeyProvider {
|
|
|
2569
2839
|
catch (e) {
|
|
2570
2840
|
/// If that fails, try to fetch the verifying key from the network as bytes
|
|
2571
2841
|
try {
|
|
2572
|
-
return
|
|
2842
|
+
return VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
|
|
2573
2843
|
}
|
|
2574
2844
|
catch (inner) {
|
|
2575
2845
|
throw new Error("Invalid verifying key. Error: " + inner.message);
|
|
@@ -2747,7 +3017,7 @@ class OfflineSearchParams {
|
|
|
2747
3017
|
* const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
|
|
2748
3018
|
*
|
|
2749
3019
|
* // Broadcast the transaction later on a machine with internet access
|
|
2750
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
3020
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
2751
3021
|
* const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
|
|
2752
3022
|
*/
|
|
2753
3023
|
class OfflineKeyProvider {
|
|
@@ -2755,9 +3025,6 @@ class OfflineKeyProvider {
|
|
|
2755
3025
|
constructor() {
|
|
2756
3026
|
this.cache = new Map();
|
|
2757
3027
|
}
|
|
2758
|
-
keyStore() {
|
|
2759
|
-
return Promise.resolve(promoteMapToKeyStore(this.cache));
|
|
2760
|
-
}
|
|
2761
3028
|
/**
|
|
2762
3029
|
* Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
|
|
2763
3030
|
* method for it to work.
|
|
@@ -3207,7 +3474,7 @@ class NetworkRecordProvider {
|
|
|
3207
3474
|
*
|
|
3208
3475
|
* @example
|
|
3209
3476
|
* // Create a new NetworkRecordProvider
|
|
3210
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
3477
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
3211
3478
|
* const keyProvider = new AleoKeyProvider();
|
|
3212
3479
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3213
3480
|
*
|
|
@@ -3220,7 +3487,7 @@ class NetworkRecordProvider {
|
|
|
3220
3487
|
*
|
|
3221
3488
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3222
3489
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
3223
|
-
* const programManager = new ProgramManager("https://api.
|
|
3490
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
3224
3491
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3225
3492
|
*
|
|
3226
3493
|
* */
|
|
@@ -3254,9 +3521,9 @@ class NetworkRecordProvider {
|
|
|
3254
3521
|
const recordsPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, ["credits.aleo"], microcredits, maxAmount, searchParameters.nonces, this.account.privateKey());
|
|
3255
3522
|
return recordsPts.map((record) => ({
|
|
3256
3523
|
owner: record.owner().toString(),
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3524
|
+
program_name: 'credits.aleo',
|
|
3525
|
+
record_name: 'credits',
|
|
3526
|
+
record_plaintext: record.toString(),
|
|
3260
3527
|
}));
|
|
3261
3528
|
}
|
|
3262
3529
|
/**
|
|
@@ -3268,7 +3535,7 @@ class NetworkRecordProvider {
|
|
|
3268
3535
|
*
|
|
3269
3536
|
* @example
|
|
3270
3537
|
* // Create a new NetworkRecordProvider
|
|
3271
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
3538
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
3272
3539
|
* const keyProvider = new AleoKeyProvider();
|
|
3273
3540
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3274
3541
|
*
|
|
@@ -3281,7 +3548,7 @@ class NetworkRecordProvider {
|
|
|
3281
3548
|
*
|
|
3282
3549
|
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
3283
3550
|
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
3284
|
-
* const programManager = new ProgramManager("https://api.
|
|
3551
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
3285
3552
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
3286
3553
|
*/
|
|
3287
3554
|
async findCreditsRecord(microcredits, searchParameters) {
|
|
@@ -3377,7 +3644,7 @@ class NetworkRecordProvider {
|
|
|
3377
3644
|
* const params = new BlockHeightSearch(89995, 99995);
|
|
3378
3645
|
*
|
|
3379
3646
|
* // Create a new NetworkRecordProvider
|
|
3380
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
3647
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
3381
3648
|
* const keyProvider = new AleoKeyProvider();
|
|
3382
3649
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
3383
3650
|
*
|
|
@@ -3398,15 +3665,17 @@ class BlockHeightSearch {
|
|
|
3398
3665
|
}
|
|
3399
3666
|
|
|
3400
3667
|
/**
|
|
3401
|
-
* RecordScanner is a RecordProvider implementation that uses
|
|
3668
|
+
* RecordScanner is a RecordProvider implementation that uses Provable's confidential record scanning service to find
|
|
3669
|
+
* records.
|
|
3402
3670
|
*
|
|
3403
3671
|
* @example
|
|
3404
3672
|
* const account = new Account({ privateKey: 'APrivateKey1...' });
|
|
3405
3673
|
*
|
|
3406
3674
|
* const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });
|
|
3407
3675
|
* recordScanner.setAccount(account);
|
|
3408
|
-
* recordScanner.setApiKey("
|
|
3409
|
-
* const
|
|
3676
|
+
* recordScanner.setApiKey("example-api-key");
|
|
3677
|
+
* const result = await recordScanner.register(viewKey, 0);
|
|
3678
|
+
* if (result.ok) { const uuid = result.data.uuid; }
|
|
3410
3679
|
*
|
|
3411
3680
|
* const filter = {
|
|
3412
3681
|
* uuid,
|
|
@@ -3439,38 +3708,231 @@ class BlockHeightSearch {
|
|
|
3439
3708
|
* const records = await recordScanner.findRecords(filter);
|
|
3440
3709
|
*/
|
|
3441
3710
|
class RecordScanner {
|
|
3711
|
+
cacheViewKeysOnRegister;
|
|
3442
3712
|
url;
|
|
3443
3713
|
apiKey;
|
|
3714
|
+
consumerId;
|
|
3715
|
+
jwtData;
|
|
3444
3716
|
uuid;
|
|
3717
|
+
viewKeys;
|
|
3718
|
+
autoReRegister;
|
|
3719
|
+
decryptEnabled;
|
|
3720
|
+
account;
|
|
3721
|
+
/**
|
|
3722
|
+
* @param {RecordScannerOptions} options Configuration for the record scanner.
|
|
3723
|
+
*/
|
|
3445
3724
|
constructor(options) {
|
|
3446
|
-
|
|
3447
|
-
|
|
3725
|
+
// Set the network by detecting which version of the SDK is being used.
|
|
3726
|
+
const network = "/mainnet";
|
|
3727
|
+
// If the user has configured a network in their uri, throw.
|
|
3728
|
+
if (options.url.endsWith("/mainnet") || options.url.endsWith("/testnet")) {
|
|
3729
|
+
throw new Error("The record scanning url should not include the specific network, this is automatically configured by the Provable SDK.");
|
|
3730
|
+
}
|
|
3731
|
+
// Configure the url to use the network the SDK is using.
|
|
3732
|
+
this.url = options.url + network;
|
|
3733
|
+
// Get any view keys passed in the options.
|
|
3734
|
+
this.viewKeys = options.viewKeys ?
|
|
3735
|
+
Object.fromEntries(options.viewKeys.map(viewKey => [this.computeUUID(viewKey), viewKey]))
|
|
3736
|
+
: undefined;
|
|
3737
|
+
// Set the view key caching flag if provided (default: true).
|
|
3738
|
+
this.cacheViewKeysOnRegister = options.cacheViewKeysOnRegister ??= true;
|
|
3739
|
+
// Set the account if provided.
|
|
3740
|
+
this.account = options.account;
|
|
3741
|
+
if (this.account) {
|
|
3742
|
+
// Compute the UUID from the view key and set it on the scanner.
|
|
3743
|
+
this.setUuid(this.account.viewKey());
|
|
3744
|
+
// Add the view key to the scanner's view keys.
|
|
3745
|
+
this.addViewKey(this.account.viewKey());
|
|
3746
|
+
}
|
|
3747
|
+
// Configure authentication options.
|
|
3748
|
+
this.apiKey = typeof options.apiKey === "string" ? {
|
|
3749
|
+
header: "X-Provable-API-Key",
|
|
3750
|
+
value: options.apiKey
|
|
3751
|
+
} : options.apiKey;
|
|
3752
|
+
this.consumerId = options.consumerId;
|
|
3753
|
+
this.jwtData = options.jwtData;
|
|
3754
|
+
this.autoReRegister = options.autoReRegister;
|
|
3755
|
+
this.decryptEnabled = options.decryptEnabled;
|
|
3448
3756
|
}
|
|
3449
3757
|
/**
|
|
3450
3758
|
* Set the API key to use for the record scanner.
|
|
3451
3759
|
*
|
|
3452
|
-
* @param {string} apiKey The API key to use for the record scanner.
|
|
3760
|
+
* @param {string | { header: string, value: string }} apiKey The API key to use for the record scanner.
|
|
3453
3761
|
*/
|
|
3454
|
-
|
|
3762
|
+
setApiKey(apiKey) {
|
|
3455
3763
|
this.apiKey = typeof apiKey === "string" ? { header: "X-Provable-API-Key", value: apiKey } : apiKey;
|
|
3456
3764
|
}
|
|
3457
3765
|
/**
|
|
3458
|
-
* Set the
|
|
3766
|
+
* Set the consumer ID used for JWT refresh when using authenticated record scanner (e.g. Provable API).
|
|
3767
|
+
*
|
|
3768
|
+
* @param {string} consumerId The consumer ID to use for JWT refresh.
|
|
3769
|
+
*/
|
|
3770
|
+
setConsumerId(consumerId) {
|
|
3771
|
+
this.consumerId = consumerId;
|
|
3772
|
+
}
|
|
3773
|
+
/**
|
|
3774
|
+
* Set JWT data for authentication. Optional; when not set, JWT can be refreshed from apiKey + consumerId if provided.
|
|
3775
|
+
*
|
|
3776
|
+
* @param {RecordScannerJWTData | undefined} jwtData The JWT data to use, or undefined to clear.
|
|
3777
|
+
*/
|
|
3778
|
+
setJwtData(jwtData) {
|
|
3779
|
+
this.jwtData = jwtData;
|
|
3780
|
+
}
|
|
3781
|
+
/**
|
|
3782
|
+
* Set whether /owned should automatically re-register on 422 (when a view key for the UUID is in viewKeys or account) and retry once.
|
|
3783
|
+
*
|
|
3784
|
+
* @param {boolean} enabled Whether to enable auto re-register on 422.
|
|
3785
|
+
*/
|
|
3786
|
+
setAutoReRegister(enabled) {
|
|
3787
|
+
this.autoReRegister = enabled;
|
|
3788
|
+
}
|
|
3789
|
+
/**
|
|
3790
|
+
* Set whether decryption of owned records is enabled (e.g. for use with the decrypt method).
|
|
3791
|
+
*
|
|
3792
|
+
* @param {boolean} enabled Whether to enable decryption of owned records received from the scanner using the `owned` or any `findRecords` methods.
|
|
3793
|
+
*/
|
|
3794
|
+
setDecryptEnabled(enabled) {
|
|
3795
|
+
this.decryptEnabled = enabled;
|
|
3796
|
+
}
|
|
3797
|
+
/**
|
|
3798
|
+
* Add a view key to the record scanner for usage in local decryption. This is REQUIRED for findCreditsRecord/findCreditsRecords to work properly.
|
|
3799
|
+
*
|
|
3800
|
+
* @param {ViewKey} viewKey The view key to add.
|
|
3801
|
+
*/
|
|
3802
|
+
addViewKey(viewKey) {
|
|
3803
|
+
const uuid = this.computeUUID(viewKey).toString();
|
|
3804
|
+
this.viewKeys = this.viewKeys ? { ...this.viewKeys, [uuid]: viewKey } : { [uuid]: viewKey };
|
|
3805
|
+
}
|
|
3806
|
+
/**
|
|
3807
|
+
* Remove a view key from the record scanner.
|
|
3808
|
+
*
|
|
3809
|
+
* @param {string} uuid The uuid of the view key to remove.
|
|
3810
|
+
*/
|
|
3811
|
+
removeViewKey(uuid) {
|
|
3812
|
+
if (this.viewKeys) {
|
|
3813
|
+
delete this.viewKeys[uuid];
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
/**
|
|
3817
|
+
* Return the view key for the given record-scanner UUID if one is configured
|
|
3818
|
+
* (in viewKeys or as the account's view key). Used to decide if re-registration on 422 is possible.
|
|
3819
|
+
*
|
|
3820
|
+
* @param {string} uuid The record-scanner UUID to look up.
|
|
3821
|
+
* @returns {ViewKey | undefined} The view key for that UUID, or undefined.
|
|
3822
|
+
*/
|
|
3823
|
+
getViewKeyForUuid(uuid) {
|
|
3824
|
+
// Prefer view key from the cached map (keyed by UUID string).
|
|
3825
|
+
const cachedVk = this.viewKeys?.[uuid];
|
|
3826
|
+
if (cachedVk)
|
|
3827
|
+
return cachedVk;
|
|
3828
|
+
// Otherwise use the account's view key if it matches this UUID.
|
|
3829
|
+
const accountVk = this.account?.viewKey();
|
|
3830
|
+
if (accountVk && this.computeUUID(accountVk).toString() === uuid)
|
|
3831
|
+
return accountVk;
|
|
3832
|
+
return undefined;
|
|
3833
|
+
}
|
|
3834
|
+
/**
|
|
3835
|
+
* Set the primary account for the record scanner.
|
|
3836
|
+
*
|
|
3837
|
+
* @param {Account} account The account to set as the primary account.
|
|
3838
|
+
*/
|
|
3839
|
+
setAccount(account) {
|
|
3840
|
+
const existingVk = this.account?.viewKey();
|
|
3841
|
+
// Set the account on the scanner.
|
|
3842
|
+
this.account = account;
|
|
3843
|
+
// Set the uuid on the scanner using the view key from the account.
|
|
3844
|
+
this.setUuid(account.viewKey());
|
|
3845
|
+
// Add the view key to the scanner's view keys.
|
|
3846
|
+
this.addViewKey(account.viewKey());
|
|
3847
|
+
// Remove the existing view key from the scanner's view keys if it exists.
|
|
3848
|
+
if (existingVk) {
|
|
3849
|
+
this.removeViewKey(this.computeUUID(existingVk).toString());
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
/**
|
|
3853
|
+
* Refreshes the JWT by making a POST request to /jwts/{consumer_id}. Used when authentication is required.
|
|
3854
|
+
*
|
|
3855
|
+
* @param {string} apiKey The API key to use for the refresh request.
|
|
3856
|
+
* @param {string} consumerId The consumer ID for the JWT endpoint.
|
|
3857
|
+
* @returns {Promise<RecordScannerJWTData>} The new JWT data.
|
|
3858
|
+
*/
|
|
3859
|
+
async refreshJwt(apiKey, consumerId) {
|
|
3860
|
+
const response = await post(`${this.url}/jwts/${consumerId}`, {
|
|
3861
|
+
headers: {
|
|
3862
|
+
"X-Provable-API-Key": apiKey,
|
|
3863
|
+
},
|
|
3864
|
+
});
|
|
3865
|
+
const authHeader = response.headers.get("authorization");
|
|
3866
|
+
if (!authHeader) {
|
|
3867
|
+
throw new Error("No authorization header in JWT refresh response");
|
|
3868
|
+
}
|
|
3869
|
+
const body = await response.json();
|
|
3870
|
+
return {
|
|
3871
|
+
jwt: authHeader,
|
|
3872
|
+
expiration: body.exp * 1000, // Convert to milliseconds
|
|
3873
|
+
};
|
|
3874
|
+
}
|
|
3875
|
+
/**
|
|
3876
|
+
* Returns auth headers (e.g. Authorization with JWT). Refreshes JWT if expired and apiKey + consumerId are set. Empty when auth is not configured.
|
|
3877
|
+
*
|
|
3878
|
+
* @returns {Promise<Record<string, string>>} Auth headers to add to requests, or empty object when not configured.
|
|
3879
|
+
*/
|
|
3880
|
+
async getAuthHeaders() {
|
|
3881
|
+
let jwtData = this.jwtData;
|
|
3882
|
+
// Consider JWT expired a few minutes early to avoid race at boundary.
|
|
3883
|
+
const isExpired = jwtData && Date.now() >= jwtData.expiration - FIVE_MINUTES;
|
|
3884
|
+
if (!jwtData || isExpired) {
|
|
3885
|
+
const apiKey = this.apiKey?.value;
|
|
3886
|
+
if (apiKey && this.consumerId) {
|
|
3887
|
+
jwtData = await this.refreshJwt(apiKey, this.consumerId);
|
|
3888
|
+
this.jwtData = jwtData;
|
|
3889
|
+
}
|
|
3890
|
+
else if (jwtData?.jwt) {
|
|
3891
|
+
// Use existing JWT even if expired when refresh is not possible.
|
|
3892
|
+
return { Authorization: jwtData.jwt };
|
|
3893
|
+
}
|
|
3894
|
+
else {
|
|
3895
|
+
return {};
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
return jwtData?.jwt ? { Authorization: jwtData.jwt } : {};
|
|
3899
|
+
}
|
|
3900
|
+
/**
|
|
3901
|
+
* Set the UUID for the record scanner.
|
|
3459
3902
|
*
|
|
3460
|
-
* @param {Field}
|
|
3903
|
+
* @param {Field | ViewKey} keyMaterial The UUID to use for the record scanner. If a ViewKey is provided, the UUID will be computed from the key.
|
|
3461
3904
|
*/
|
|
3462
|
-
|
|
3463
|
-
this.uuid =
|
|
3905
|
+
setUuid(keyMaterial) {
|
|
3906
|
+
this.uuid = keyMaterial instanceof ViewKey ? this.computeUUID(keyMaterial) : keyMaterial;
|
|
3464
3907
|
}
|
|
3465
3908
|
/**
|
|
3466
|
-
*
|
|
3909
|
+
* If the error is a RecordScannerRequestError (from request()), return a RecordScannerFailure result;
|
|
3910
|
+
* otherwise re-throw the error.
|
|
3467
3911
|
*
|
|
3912
|
+
* @param {unknown} err The error from a failed request (e.g. from request() or from a catch after calling it).
|
|
3913
|
+
* @returns {RecordScannerFailure} When err is RecordScannerRequestError.
|
|
3914
|
+
* @throws Re-throws err when it is not a RecordScannerRequestError.
|
|
3915
|
+
*/
|
|
3916
|
+
handleRequestError(err) {
|
|
3917
|
+
if (err instanceof RecordScannerRequestError) {
|
|
3918
|
+
return {
|
|
3919
|
+
ok: false,
|
|
3920
|
+
status: err.status,
|
|
3921
|
+
error: { message: err.message, status: err.status },
|
|
3922
|
+
};
|
|
3923
|
+
}
|
|
3924
|
+
throw err;
|
|
3925
|
+
}
|
|
3926
|
+
/**
|
|
3927
|
+
* Register the account with the record scanning service (unencrypted POST /register). Does not throw if a valid error response from the record scanner is received; returns a result object instead.
|
|
3928
|
+
*
|
|
3929
|
+
* @param {ViewKey} viewKey The view key to register.
|
|
3468
3930
|
* @param {number} startBlock The block height to start scanning from.
|
|
3469
|
-
* @returns {Promise<
|
|
3931
|
+
* @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
|
|
3470
3932
|
*/
|
|
3471
3933
|
async register(viewKey, startBlock) {
|
|
3472
3934
|
try {
|
|
3473
|
-
|
|
3935
|
+
const request = {
|
|
3474
3936
|
view_key: viewKey.to_string(),
|
|
3475
3937
|
start: startBlock,
|
|
3476
3938
|
};
|
|
@@ -3480,96 +3942,199 @@ class RecordScanner {
|
|
|
3480
3942
|
body: JSON.stringify(request),
|
|
3481
3943
|
}));
|
|
3482
3944
|
const data = await response.json();
|
|
3483
|
-
|
|
3484
|
-
|
|
3945
|
+
// If the uuid is not set, set it on the scanner.
|
|
3946
|
+
if (!this.uuid) {
|
|
3947
|
+
this.uuid = data.uuid;
|
|
3948
|
+
}
|
|
3949
|
+
// Add the view key to the local scanner's view keys if configured to do so.
|
|
3950
|
+
if (this.cacheViewKeysOnRegister) {
|
|
3951
|
+
this.addViewKey(viewKey);
|
|
3952
|
+
}
|
|
3953
|
+
return { ok: true, data };
|
|
3485
3954
|
}
|
|
3486
|
-
catch (
|
|
3487
|
-
console.error(`Failed to register view key: ${
|
|
3488
|
-
|
|
3955
|
+
catch (err) {
|
|
3956
|
+
console.error(`Failed to register view key: ${err}`);
|
|
3957
|
+
return this.handleRequestError(err);
|
|
3489
3958
|
}
|
|
3490
3959
|
}
|
|
3491
3960
|
/**
|
|
3492
|
-
*
|
|
3961
|
+
* Fetches an ephemeral public key from the record scanning service for use with registerEncrypted.
|
|
3962
|
+
* Follows the same pattern as the delegated proving service /pubkey endpoint.
|
|
3963
|
+
*
|
|
3964
|
+
* @returns {Promise<CryptoBoxPubKey>} The service's ephemeral public key and key_id.
|
|
3965
|
+
*/
|
|
3966
|
+
async getPubkey() {
|
|
3967
|
+
const response = await this.request(new Request(`${this.url}/pubkey`, { method: "GET" }));
|
|
3968
|
+
return parseJSON(await response.text());
|
|
3969
|
+
}
|
|
3970
|
+
/**
|
|
3971
|
+
* Registers the account with the record scanning service using the encrypted flow: 1. fetches an ephemeral public key from /pubkey - 2. encrypts the registration request (view key + start block) - 3. POSTs to /register/encrypted. Does not HTTP error on a proper error response from the record scanner; returns a result object instead.
|
|
3972
|
+
*
|
|
3973
|
+
* @param {ViewKey} viewKey The view key to register.
|
|
3974
|
+
* @param {number} startBlock The block height to start scanning from.
|
|
3975
|
+
* @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
|
|
3976
|
+
*/
|
|
3977
|
+
async registerEncrypted(viewKey, startBlock) {
|
|
3978
|
+
try {
|
|
3979
|
+
// Get the ephemeral public key from the record scanner.
|
|
3980
|
+
const pubkey = await this.getPubkey();
|
|
3981
|
+
// Encrypt the registration request using the ephemeral public key.
|
|
3982
|
+
const ciphertext = encryptRegistrationRequest(pubkey.public_key, viewKey, startBlock);
|
|
3983
|
+
const payload = {
|
|
3984
|
+
key_id: pubkey.key_id,
|
|
3985
|
+
ciphertext,
|
|
3986
|
+
};
|
|
3987
|
+
// Send the encrypted registration request to the record scanner.
|
|
3988
|
+
const response = await this.request(new Request(`${this.url}/register/encrypted`, {
|
|
3989
|
+
method: "POST",
|
|
3990
|
+
headers: { "Content-Type": "application/json" },
|
|
3991
|
+
body: JSON.stringify(payload),
|
|
3992
|
+
}));
|
|
3993
|
+
const data = await response.json();
|
|
3994
|
+
// If the uuid is not set, set it on the scanner.
|
|
3995
|
+
if (!this.uuid) {
|
|
3996
|
+
this.uuid = data.uuid;
|
|
3997
|
+
}
|
|
3998
|
+
// Add the view key to the local scanner's view keys if configured to do so.
|
|
3999
|
+
if (this.cacheViewKeysOnRegister) {
|
|
4000
|
+
this.addViewKey(viewKey);
|
|
4001
|
+
}
|
|
4002
|
+
return { ok: true, data };
|
|
4003
|
+
}
|
|
4004
|
+
catch (err) {
|
|
4005
|
+
return this.handleRequestError(err);
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
/**
|
|
4009
|
+
* Get encrypted records from the record scanning service. This is a safe variant of /records/encrypted that returns
|
|
4010
|
+
* a result instead of throwing on HTTP error.
|
|
3493
4011
|
*
|
|
3494
4012
|
* @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
|
|
3495
|
-
* @returns {Promise<
|
|
4013
|
+
* @returns {Promise<EncryptedRecordsResult>} The encrypted records or an error if the request failed.
|
|
3496
4014
|
*/
|
|
3497
|
-
async
|
|
4015
|
+
async encrypted(recordsFilter) {
|
|
3498
4016
|
try {
|
|
3499
4017
|
const response = await this.request(new Request(`${this.url}/records/encrypted`, {
|
|
3500
4018
|
method: "POST",
|
|
3501
4019
|
headers: { "Content-Type": "application/json" },
|
|
3502
4020
|
body: JSON.stringify(recordsFilter),
|
|
3503
4021
|
}));
|
|
3504
|
-
|
|
4022
|
+
const data = await response.json();
|
|
4023
|
+
return { ok: true, data };
|
|
3505
4024
|
}
|
|
3506
|
-
catch (
|
|
3507
|
-
|
|
3508
|
-
throw error;
|
|
4025
|
+
catch (err) {
|
|
4026
|
+
return this.handleRequestError(err);
|
|
3509
4027
|
}
|
|
3510
4028
|
}
|
|
3511
4029
|
/**
|
|
3512
|
-
*
|
|
4030
|
+
* Get encrypted records from the record scanning service.
|
|
4031
|
+
*
|
|
4032
|
+
* @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
|
|
4033
|
+
* @returns {Promise<EncryptedRecord[]>} The encrypted records.
|
|
4034
|
+
*/
|
|
4035
|
+
async encryptedRecords(recordsFilter) {
|
|
4036
|
+
const result = await this.encrypted(recordsFilter);
|
|
4037
|
+
if (result.ok)
|
|
4038
|
+
return result.data;
|
|
4039
|
+
throw new RecordScannerRequestError(result.error.message, result.status);
|
|
4040
|
+
}
|
|
4041
|
+
/**
|
|
4042
|
+
* Check if serial numbers appear in any record inputs on-chain, indicating that the records they belong to have been spent. This is a safe variant of /records/sns that returns a result instead of throwing on HTTP error.
|
|
3513
4043
|
*
|
|
3514
4044
|
* @param {string[]} serialNumbers The serial numbers to check.
|
|
3515
|
-
* @returns {Promise<
|
|
4045
|
+
* @returns {Promise<SerialNumbersResult>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If a boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
|
|
3516
4046
|
*/
|
|
3517
|
-
async
|
|
4047
|
+
async serialNumbers(serialNumbers) {
|
|
3518
4048
|
try {
|
|
3519
4049
|
const response = await this.request(new Request(`${this.url}/records/sns`, {
|
|
3520
4050
|
method: "POST",
|
|
3521
4051
|
headers: { "Content-Type": "application/json" },
|
|
3522
4052
|
body: JSON.stringify(serialNumbers),
|
|
3523
4053
|
}));
|
|
3524
|
-
|
|
4054
|
+
const data = await response.json();
|
|
4055
|
+
return { ok: true, data };
|
|
3525
4056
|
}
|
|
3526
|
-
catch (
|
|
3527
|
-
|
|
3528
|
-
throw error;
|
|
4057
|
+
catch (err) {
|
|
4058
|
+
return this.handleRequestError(err);
|
|
3529
4059
|
}
|
|
3530
4060
|
}
|
|
3531
4061
|
/**
|
|
3532
|
-
* Check if
|
|
4062
|
+
* Check if serial numbers appear in any record inputs on-chain, indicating that the records they belong to have been spent.
|
|
3533
4063
|
*
|
|
4064
|
+
* @param {string[]} serialNumbers The serial numbers to check.
|
|
4065
|
+
* @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.
|
|
4066
|
+
*/
|
|
4067
|
+
async checkSerialNumbers(serialNumbers) {
|
|
4068
|
+
const result = await this.serialNumbers(serialNumbers);
|
|
4069
|
+
if (result.ok)
|
|
4070
|
+
return result.data;
|
|
4071
|
+
throw new RecordScannerRequestError(result.error.message, result.status);
|
|
4072
|
+
}
|
|
4073
|
+
/**
|
|
4074
|
+
* Check if tags appear in any record inputs on-chain, indicating that the records they belong to have been spent. This is a safe variant of /records/tags that returns a result instead of throwing on HTTP error.
|
|
4075
|
+
*
|
|
4076
|
+
* *
|
|
3534
4077
|
* @param {string[]} tags The tags to check.
|
|
3535
|
-
* @returns {Promise<
|
|
4078
|
+
* @returns {Promise<TagsResult>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If a boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
|
|
3536
4079
|
*/
|
|
3537
|
-
async
|
|
4080
|
+
async tags(tags) {
|
|
3538
4081
|
try {
|
|
3539
4082
|
const response = await this.request(new Request(`${this.url}/records/tags`, {
|
|
3540
4083
|
method: "POST",
|
|
3541
4084
|
headers: { "Content-Type": "application/json" },
|
|
3542
4085
|
body: JSON.stringify(tags),
|
|
3543
4086
|
}));
|
|
3544
|
-
|
|
4087
|
+
const data = await response.json();
|
|
4088
|
+
return { ok: true, data };
|
|
3545
4089
|
}
|
|
3546
|
-
catch (
|
|
3547
|
-
|
|
3548
|
-
throw error;
|
|
4090
|
+
catch (err) {
|
|
4091
|
+
return this.handleRequestError(err);
|
|
3549
4092
|
}
|
|
3550
4093
|
}
|
|
3551
4094
|
/**
|
|
3552
|
-
* Check
|
|
4095
|
+
* Check if tags appear in any record inputs on-chain, indicating that the records they belong to have been spent.
|
|
4096
|
+
*
|
|
4097
|
+
* @param {string[]} tags The tags to check.
|
|
4098
|
+
* @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.
|
|
4099
|
+
*/
|
|
4100
|
+
async checkTags(tags) {
|
|
4101
|
+
const result = await this.tags(tags);
|
|
4102
|
+
if (result.ok)
|
|
4103
|
+
return result.data;
|
|
4104
|
+
throw new RecordScannerRequestError(result.error.message, result.status);
|
|
4105
|
+
}
|
|
4106
|
+
/**
|
|
4107
|
+
* Check the scan completion job status for a specific UUID.
|
|
3553
4108
|
*
|
|
3554
|
-
* @param {string}
|
|
3555
|
-
* @returns {Promise<
|
|
4109
|
+
* @param {string | Field | undefined} uuid The UUID of the job to check. If no UUID is provided as input, the UUID configured for the scanner will be used.
|
|
4110
|
+
* @returns {Promise<StatusResult>} The status of the job or an error if the job could not be found.
|
|
3556
4111
|
*/
|
|
3557
|
-
async
|
|
4112
|
+
async status(uuid) {
|
|
4113
|
+
// Attempt to get the UUID from the parameter or use the configured UUID within the scanner.
|
|
4114
|
+
uuid = uuid ?? this.uuid;
|
|
4115
|
+
if (!uuid) {
|
|
4116
|
+
throw new UUIDError("No UUID configured for the record scanner.");
|
|
4117
|
+
}
|
|
4118
|
+
// If the UUID is a string, verify that it is valid.
|
|
4119
|
+
if (typeof uuid === "string" && !this.uuidIsValid(uuid)) {
|
|
4120
|
+
throw new UUIDError(`UUID ${uuid} is invalid`, uuid);
|
|
4121
|
+
}
|
|
4122
|
+
// Check the status of the job for the specified UUID.
|
|
3558
4123
|
try {
|
|
3559
4124
|
const response = await this.request(new Request(`${this.url}/status`, {
|
|
3560
4125
|
method: "POST",
|
|
3561
4126
|
headers: { "Content-Type": "application/json" },
|
|
3562
|
-
body: JSON.stringify(
|
|
4127
|
+
body: JSON.stringify(uuid.toString()),
|
|
3563
4128
|
}));
|
|
3564
|
-
|
|
4129
|
+
const data = await response.json();
|
|
4130
|
+
return { ok: true, data };
|
|
3565
4131
|
}
|
|
3566
|
-
catch (
|
|
3567
|
-
|
|
3568
|
-
throw error;
|
|
4132
|
+
catch (err) {
|
|
4133
|
+
return this.handleRequestError(err);
|
|
3569
4134
|
}
|
|
3570
4135
|
}
|
|
3571
4136
|
/**
|
|
3572
|
-
* Find a record in the record
|
|
4137
|
+
* Find a record in the record scanning service.
|
|
3573
4138
|
*
|
|
3574
4139
|
* @param {OwnedFilter} searchParameters The filter to use to find the record.
|
|
3575
4140
|
* @returns {Promise<OwnedRecord>} The record.
|
|
@@ -3588,56 +4153,159 @@ class RecordScanner {
|
|
|
3588
4153
|
}
|
|
3589
4154
|
}
|
|
3590
4155
|
/**
|
|
3591
|
-
*
|
|
4156
|
+
* Get owned records. Throws if the UUID passed in the OwnedFilter is invalid or is not configured in the record scanner otherwise returns the RESTFUL response from the record scanner.
|
|
3592
4157
|
*
|
|
3593
|
-
* @param {OwnedFilter} filter The
|
|
3594
|
-
* @returns {Promise<
|
|
4158
|
+
* @param {OwnedFilter} filter The OwnedFilter used to specify the subset of owned records to select.
|
|
4159
|
+
* @returns {Promise<OwnedRecordsResult>} Record belonging to the uuid passed in the filter or set on the Record Scanner.
|
|
3595
4160
|
*/
|
|
3596
|
-
async
|
|
3597
|
-
|
|
3598
|
-
|
|
4161
|
+
async owned(filter) {
|
|
4162
|
+
// Extract and verify the correctness of the UUID from the filter or get the configured UUID within the scanner.
|
|
4163
|
+
const uuid = this.getUUID(filter);
|
|
4164
|
+
// Throw an error if none could be found, otherwise set the UUID on the filter with either the UUID configured
|
|
4165
|
+
// within the filter or the UUID configured within the scanner.
|
|
4166
|
+
if (!uuid) {
|
|
4167
|
+
throw new Error("Error while using the record scanner. UUID is not set on the scanner and the UUID " +
|
|
4168
|
+
"provided in the record filter was invalid.");
|
|
3599
4169
|
}
|
|
3600
|
-
filter.uuid =
|
|
3601
|
-
|
|
4170
|
+
filter.uuid = uuid;
|
|
4171
|
+
// Inner request used to retry once after 422 re-register without duplicating logic.
|
|
4172
|
+
const ownedRequest = async () => {
|
|
3602
4173
|
const response = await this.request(new Request(`${this.url}/records/owned`, {
|
|
3603
4174
|
method: "POST",
|
|
3604
4175
|
headers: { "Content-Type": "application/json" },
|
|
3605
4176
|
body: JSON.stringify(filter),
|
|
3606
4177
|
}));
|
|
3607
|
-
|
|
4178
|
+
const data = await response.json();
|
|
4179
|
+
return { ok: true, data };
|
|
4180
|
+
};
|
|
4181
|
+
// When decryption is enabled and a view key exists for this UUID, decrypt records in place before returning.
|
|
4182
|
+
const attemptDecrypt = (result) => {
|
|
4183
|
+
if (result.ok && this.decryptEnabled) {
|
|
4184
|
+
const viewKey = this.getViewKeyForUuid(uuid);
|
|
4185
|
+
if (viewKey)
|
|
4186
|
+
this.decrypt(viewKey, result.data);
|
|
4187
|
+
}
|
|
4188
|
+
return result;
|
|
4189
|
+
};
|
|
4190
|
+
try {
|
|
4191
|
+
return attemptDecrypt(await ownedRequest());
|
|
3608
4192
|
}
|
|
3609
|
-
catch (
|
|
3610
|
-
|
|
3611
|
-
|
|
4193
|
+
catch (err) {
|
|
4194
|
+
const failure = this.handleRequestError(err);
|
|
4195
|
+
// On 422 (e.g. not registered), optionally re-register with registerEncrypted and retry once.
|
|
4196
|
+
if (failure.status === 422 && this.autoReRegister) {
|
|
4197
|
+
const viewKey = this.getViewKeyForUuid(uuid);
|
|
4198
|
+
if (viewKey) {
|
|
4199
|
+
const regResult = await this.registerEncrypted(viewKey, 0);
|
|
4200
|
+
if (regResult.ok) {
|
|
4201
|
+
try {
|
|
4202
|
+
return attemptDecrypt(await ownedRequest());
|
|
4203
|
+
}
|
|
4204
|
+
catch (retryErr) {
|
|
4205
|
+
return this.handleRequestError(retryErr);
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
return failure;
|
|
3612
4211
|
}
|
|
3613
4212
|
}
|
|
3614
4213
|
/**
|
|
3615
|
-
* Find
|
|
4214
|
+
* Find records using the record scanning service.
|
|
4215
|
+
*
|
|
4216
|
+
* @param {OwnedFilter} searchParameters The filter to use to find the records.
|
|
4217
|
+
* @returns {Promise<OwnedRecord[]>} The records.
|
|
4218
|
+
*/
|
|
4219
|
+
async findRecords(searchParameters) {
|
|
4220
|
+
// Get the records from the record scanner.
|
|
4221
|
+
const result = await this.owned(searchParameters);
|
|
4222
|
+
// If the request was successful, return the records otherwise throw an error.
|
|
4223
|
+
if (result.ok)
|
|
4224
|
+
return result.data;
|
|
4225
|
+
throw new RecordScannerRequestError(result.error.message, result.status);
|
|
4226
|
+
}
|
|
4227
|
+
/**
|
|
4228
|
+
* Get RecordPlaintext from an OwnedRecord by parsing record_plaintext (trimmed). Returns null if missing or parse fails. Does not decrypt; decryption is handled only in owned().
|
|
4229
|
+
*/
|
|
4230
|
+
getPlaintext(record) {
|
|
4231
|
+
// Only read record_plaintext (decrypted by the owned() callwhen decryptEnabled is true).
|
|
4232
|
+
const plaintextStr = record.record_plaintext?.trim();
|
|
4233
|
+
if (!plaintextStr)
|
|
4234
|
+
return null;
|
|
4235
|
+
try {
|
|
4236
|
+
return RecordPlaintext.fromString(plaintextStr);
|
|
4237
|
+
}
|
|
4238
|
+
catch {
|
|
4239
|
+
return null;
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
/**
|
|
4243
|
+
* For each owned record provided, attempt to decrypt with the given view key. On success, sets record_plaintext on that record to the decrypted plaintext string. Records that fail to decrypt (e.g. wrong view key) or have no record_ciphertext are left unchanged.
|
|
4244
|
+
*
|
|
4245
|
+
* @param {ViewKey} viewKey The view key to use for decryption.
|
|
4246
|
+
* @param {OwnedRecord[]} records The owned records to decrypt (mutated in place).
|
|
4247
|
+
*/
|
|
4248
|
+
decrypt(viewKey, records) {
|
|
4249
|
+
for (const record of records) {
|
|
4250
|
+
const ciphertextStr = record.record_ciphertext?.trim();
|
|
4251
|
+
if (!ciphertextStr)
|
|
4252
|
+
continue;
|
|
4253
|
+
try {
|
|
4254
|
+
const ciphertext = RecordCiphertext.fromString(ciphertextStr);
|
|
4255
|
+
const plaintext = ciphertext.decrypt(viewKey);
|
|
4256
|
+
record.record_plaintext = plaintext.toString();
|
|
4257
|
+
}
|
|
4258
|
+
catch {
|
|
4259
|
+
// Wrong view key or invalid ciphertext; leave this record unchanged.
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
/**
|
|
4264
|
+
* Find a credits.aleo record in the record scanning service.
|
|
3616
4265
|
*
|
|
3617
4266
|
* @param {number} microcredits The amount of microcredits to find.
|
|
3618
4267
|
* @param {OwnedFilter} searchParameters The filter to use to find the record.
|
|
3619
4268
|
* @returns {Promise<OwnedRecord>} The record.
|
|
3620
4269
|
*/
|
|
3621
4270
|
async findCreditsRecord(microcredits, searchParameters) {
|
|
4271
|
+
const uuid = this.getUUID(searchParameters);
|
|
4272
|
+
if (!uuid) {
|
|
4273
|
+
throw new UUIDError(`No uuid found in the record scanner filter`, uuid, searchParameters);
|
|
4274
|
+
}
|
|
4275
|
+
if (!this.decryptEnabled) {
|
|
4276
|
+
throw new DecryptionNotEnabledError("Decryption of owned records must be enabled (set decryptEnabled in options or call setDecryptEnabled(true)) to use findCreditsRecord.", searchParameters);
|
|
4277
|
+
}
|
|
4278
|
+
if (!this.getViewKeyForUuid(uuid)) {
|
|
4279
|
+
throw new ViewKeyNotStoredError(`No view key for UUID ${uuid} is stored in the record scanner. Add the view key via viewKeys in options, addViewKey(), or setAccount().`, uuid, searchParameters);
|
|
4280
|
+
}
|
|
3622
4281
|
try {
|
|
4282
|
+
// Fetch credits records (owned() will decrypt when decryptEnabled and view key are set).
|
|
3623
4283
|
const records = await this.findRecords({
|
|
3624
|
-
|
|
3625
|
-
unspent: searchParameters.unspent,
|
|
4284
|
+
unspent: searchParameters.unspent ?? true,
|
|
3626
4285
|
filter: {
|
|
3627
|
-
start: searchParameters.filter?.start ?? 0,
|
|
3628
4286
|
program: "credits.aleo",
|
|
3629
4287
|
record: "credits",
|
|
4288
|
+
...(searchParameters.filter ? searchParameters.filter : {}),
|
|
3630
4289
|
},
|
|
3631
|
-
|
|
4290
|
+
responseFilter: searchParameters.responseFilter,
|
|
4291
|
+
uuid,
|
|
3632
4292
|
});
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
const
|
|
3636
|
-
|
|
3637
|
-
|
|
4293
|
+
// First record whose plaintext microcredits >= requested amount.
|
|
4294
|
+
const record = records.find(r => {
|
|
4295
|
+
const plaintext = this.getPlaintext(r);
|
|
4296
|
+
if (!plaintext)
|
|
4297
|
+
return false;
|
|
4298
|
+
try {
|
|
4299
|
+
const amountStr = plaintext.getMember("microcredits").toString();
|
|
4300
|
+
const amount = parseInt(amountStr.replace("u64", ""));
|
|
4301
|
+
return amount >= microcredits;
|
|
4302
|
+
}
|
|
4303
|
+
catch {
|
|
4304
|
+
return false;
|
|
4305
|
+
}
|
|
3638
4306
|
});
|
|
3639
4307
|
if (!record) {
|
|
3640
|
-
throw new
|
|
4308
|
+
throw new RecordNotFoundError(`No records found matching the supplied search filter:\n${JSON.stringify(searchParameters, null, 2)}. Decryption of owned records MUST be enabled and the ViewKey matching the UUID must be stored in the RecordScanner object to perform decryption.`, searchParameters);
|
|
3641
4309
|
}
|
|
3642
4310
|
return record;
|
|
3643
4311
|
}
|
|
@@ -3647,28 +4315,47 @@ class RecordScanner {
|
|
|
3647
4315
|
}
|
|
3648
4316
|
}
|
|
3649
4317
|
/**
|
|
3650
|
-
* Find credits records using
|
|
4318
|
+
* Find credits records greater than or equal to the specified amounts using the record scanning service.
|
|
3651
4319
|
*
|
|
3652
4320
|
* @param {number[]} microcreditAmounts The amounts of microcredits to find.
|
|
3653
4321
|
* @param {OwnedFilter} searchParameters The filter to use to find the records.
|
|
3654
4322
|
* @returns {Promise<OwnedRecord[]>} The records
|
|
3655
4323
|
*/
|
|
3656
4324
|
async findCreditsRecords(microcreditAmounts, searchParameters) {
|
|
4325
|
+
const uuid = this.getUUID(searchParameters);
|
|
4326
|
+
if (!uuid) {
|
|
4327
|
+
throw new UUIDError(`No uuid found in the record scanner filter, and none configured within the record scanner`, uuid, searchParameters);
|
|
4328
|
+
}
|
|
4329
|
+
if (!this.decryptEnabled) {
|
|
4330
|
+
throw new DecryptionNotEnabledError("Decryption of owned records must be enabled (set decryptEnabled in options or call setDecryptEnabled(true)) to use findCreditsRecords.", searchParameters);
|
|
4331
|
+
}
|
|
4332
|
+
if (!this.getViewKeyForUuid(uuid)) {
|
|
4333
|
+
throw new ViewKeyNotStoredError(`No view key for UUID ${uuid} is stored in the record scanner. Add the view key via viewKeys in options, addViewKey(), or setAccount().`, uuid, searchParameters);
|
|
4334
|
+
}
|
|
3657
4335
|
try {
|
|
4336
|
+
// Fetch credits records (owned() decrypts when decryptEnabled and a view key matching the UUID are set).
|
|
3658
4337
|
const records = await this.findRecords({
|
|
3659
|
-
|
|
3660
|
-
unspent: searchParameters.unspent,
|
|
4338
|
+
unspent: searchParameters.unspent ?? true,
|
|
3661
4339
|
filter: {
|
|
3662
|
-
start: searchParameters.filter?.start ?? 0,
|
|
3663
4340
|
program: "credits.aleo",
|
|
3664
4341
|
record: "credits",
|
|
4342
|
+
...(searchParameters.filter ? searchParameters.filter : {}),
|
|
3665
4343
|
},
|
|
3666
|
-
|
|
4344
|
+
responseFilter: searchParameters.responseFilter,
|
|
4345
|
+
uuid,
|
|
3667
4346
|
});
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
const
|
|
3671
|
-
|
|
4347
|
+
// Keep only records whose plaintext microcredits match one of the requested amounts.
|
|
4348
|
+
return records.filter(r => {
|
|
4349
|
+
const plaintext = this.getPlaintext(r);
|
|
4350
|
+
if (!plaintext)
|
|
4351
|
+
return false;
|
|
4352
|
+
try {
|
|
4353
|
+
const amount = plaintext.getMember("microcredits").toString();
|
|
4354
|
+
return microcreditAmounts.includes(parseInt(amount.replace("u64", "")));
|
|
4355
|
+
}
|
|
4356
|
+
catch {
|
|
4357
|
+
return false;
|
|
4358
|
+
}
|
|
3672
4359
|
});
|
|
3673
4360
|
}
|
|
3674
4361
|
catch (error) {
|
|
@@ -3677,19 +4364,28 @@ class RecordScanner {
|
|
|
3677
4364
|
}
|
|
3678
4365
|
}
|
|
3679
4366
|
/**
|
|
3680
|
-
* Wrapper function to make a request to the record
|
|
4367
|
+
* Wrapper function to make a request to the record scanning service and handle any errors. Optionally adds JWT Authorization header when consumerId/jwtData (or apiKey+consumerId) are configured.
|
|
3681
4368
|
*
|
|
3682
4369
|
* @param {Request} req The request to make.
|
|
3683
|
-
* @returns {Promise<Response>} The response.
|
|
4370
|
+
* @returns {Promise<Response>} The response when the request succeeds.
|
|
4371
|
+
* @throws {RecordScannerRequestError} When the server returns a non-2xx status (e.g. 4xx, 5xx).
|
|
4372
|
+
* @throws Re-throws any error from fetch (e.g. network failure) or from getAuthHeaders().
|
|
3684
4373
|
*/
|
|
3685
4374
|
async request(req) {
|
|
3686
4375
|
try {
|
|
4376
|
+
// Attach JWT (if configured) and API key before sending.
|
|
4377
|
+
const authHeaders = await this.getAuthHeaders();
|
|
4378
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
4379
|
+
req.headers.set(key, value);
|
|
4380
|
+
}
|
|
3687
4381
|
if (this.apiKey) {
|
|
3688
4382
|
req.headers.set(this.apiKey.header, this.apiKey.value);
|
|
3689
4383
|
}
|
|
3690
4384
|
const response = await fetch(req);
|
|
4385
|
+
// Non-2xx: throw so callers can handleRequestError or re-register on 422 if autoReRegister is enabled.
|
|
3691
4386
|
if (!response.ok) {
|
|
3692
|
-
|
|
4387
|
+
const text = await response.text();
|
|
4388
|
+
throw new RecordScannerRequestError(text || `Request to ${req.url} failed with status ${response.status}`, response.status);
|
|
3693
4389
|
}
|
|
3694
4390
|
return response;
|
|
3695
4391
|
}
|
|
@@ -3698,13 +4394,47 @@ class RecordScanner {
|
|
|
3698
4394
|
throw error;
|
|
3699
4395
|
}
|
|
3700
4396
|
}
|
|
3701
|
-
|
|
4397
|
+
/**
|
|
4398
|
+
* Compute the record scanner UUID for a view key.
|
|
4399
|
+
*
|
|
4400
|
+
* @param {ViewKey} viewKey The view key to compute the UUID for.
|
|
4401
|
+
* @returns {Field} The computed UUID corresponding to the view key.
|
|
4402
|
+
*/
|
|
4403
|
+
computeUUID(viewKey) {
|
|
3702
4404
|
// Construct the material needed for the Poseidon oracle.
|
|
3703
|
-
const inputs = [Field.newDomainSeparator(RECORD_DOMAIN),
|
|
4405
|
+
const inputs = [Field.newDomainSeparator(RECORD_DOMAIN), viewKey.toField(), Field.one()];
|
|
3704
4406
|
// Calculate the uuid.
|
|
3705
4407
|
const hasher = new Poseidon4();
|
|
3706
4408
|
return hasher.hash(inputs);
|
|
3707
4409
|
}
|
|
4410
|
+
/**
|
|
4411
|
+
* Validate a UUID string to ensure it represents a valid Aleo Record Scanner UUID.
|
|
4412
|
+
*
|
|
4413
|
+
* @param {string} uuid The UUID to validate.
|
|
4414
|
+
* @returns {boolean} Whether the UUID is valid.
|
|
4415
|
+
*/
|
|
4416
|
+
uuidIsValid(uuid) {
|
|
4417
|
+
try {
|
|
4418
|
+
Field.fromString(uuid);
|
|
4419
|
+
return true;
|
|
4420
|
+
}
|
|
4421
|
+
catch {
|
|
4422
|
+
return false;
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
/**
|
|
4426
|
+
* Get the uuid for the filter, first by extracting the UUID from the filter, then falling back to the uuid configured within the record scanner.
|
|
4427
|
+
*
|
|
4428
|
+
* @param {OwnedFilter} filter The filter to extract the UUID from.
|
|
4429
|
+
* @returns {string | undefined} The UUID for the filter, or undefined if the filter does not contain a UUID.
|
|
4430
|
+
*/
|
|
4431
|
+
getUUID(filter) {
|
|
4432
|
+
// Filter may specify a UUID; otherwise use the scanner's configured UUID.
|
|
4433
|
+
if (filter.uuid && this.uuidIsValid(filter.uuid)) {
|
|
4434
|
+
return filter.uuid;
|
|
4435
|
+
}
|
|
4436
|
+
return this.uuid?.toString();
|
|
4437
|
+
}
|
|
3708
4438
|
}
|
|
3709
4439
|
|
|
3710
4440
|
/**
|
|
@@ -4024,7 +4754,7 @@ class ProgramManager {
|
|
|
4024
4754
|
* @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
|
|
4025
4755
|
*/
|
|
4026
4756
|
constructor(host, keyProvider, recordProvider, networkClientOptions) {
|
|
4027
|
-
this.host = host ? host : "https://api.
|
|
4757
|
+
this.host = host ? host : "https://api.provable.com/v2";
|
|
4028
4758
|
this.networkClient = new AleoNetworkClient(this.host, networkClientOptions);
|
|
4029
4759
|
this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider();
|
|
4030
4760
|
this.recordProvider = recordProvider;
|
|
@@ -4081,7 +4811,7 @@ class ProgramManager {
|
|
|
4081
4811
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
4082
4812
|
*
|
|
4083
4813
|
* // Create a ProgramManager
|
|
4084
|
-
* const programManager = new ProgramManager("https://api.
|
|
4814
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2");
|
|
4085
4815
|
*
|
|
4086
4816
|
* // Set the value of the `Accept-Language` header to `en-US`
|
|
4087
4817
|
* programManager.setHeader('Accept-Language', 'en-US');
|
|
@@ -4102,7 +4832,7 @@ class ProgramManager {
|
|
|
4102
4832
|
* keyProvider.useCache(true);
|
|
4103
4833
|
*
|
|
4104
4834
|
* // Create a ProgramManager
|
|
4105
|
-
* const programManager = new ProgramManager("https://api.
|
|
4835
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider);
|
|
4106
4836
|
*
|
|
4107
4837
|
* // Set the inclusion keys.
|
|
4108
4838
|
* programManager.setInclusionProver();
|
|
@@ -4136,7 +4866,7 @@ class ProgramManager {
|
|
|
4136
4866
|
* import { ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
4137
4867
|
*
|
|
4138
4868
|
* // Create a ProgramManager
|
|
4139
|
-
* const programManager = new ProgramManager("https://api.
|
|
4869
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2");
|
|
4140
4870
|
*
|
|
4141
4871
|
* // Remove the default `X-Aleo-SDK-Version` header
|
|
4142
4872
|
* programManager.removeHeader('X-Aleo-SDK-Version');
|
|
@@ -4166,7 +4896,7 @@ class ProgramManager {
|
|
|
4166
4896
|
*
|
|
4167
4897
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
4168
4898
|
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
4169
|
-
* const programManager = new ProgramManager("https://api.
|
|
4899
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4170
4900
|
* programManager.setAccount(Account);
|
|
4171
4901
|
*
|
|
4172
4902
|
* // Define a fee in credits
|
|
@@ -4278,7 +5008,7 @@ class ProgramManager {
|
|
|
4278
5008
|
*
|
|
4279
5009
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
4280
5010
|
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
4281
|
-
* const programManager = new ProgramManager("https://api.
|
|
5011
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4282
5012
|
* programManager.setAccount(Account);
|
|
4283
5013
|
*
|
|
4284
5014
|
* // Define a fee in credits
|
|
@@ -4396,7 +5126,7 @@ class ProgramManager {
|
|
|
4396
5126
|
*
|
|
4397
5127
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
4398
5128
|
* const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
|
|
4399
|
-
* const programManager = new ProgramManager("https://api.
|
|
5129
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4400
5130
|
*
|
|
4401
5131
|
* // Define a fee in credits
|
|
4402
5132
|
* const priorityFee = 0.0;
|
|
@@ -4444,7 +5174,7 @@ class ProgramManager {
|
|
|
4444
5174
|
* keyProvider.useCache(true);
|
|
4445
5175
|
*
|
|
4446
5176
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
4447
|
-
* const programManager = new ProgramManager("https://api.
|
|
5177
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4448
5178
|
*
|
|
4449
5179
|
* // Build and execute the transaction
|
|
4450
5180
|
* const tx = await programManager.buildExecutionTransaction({
|
|
@@ -4605,7 +5335,7 @@ class ProgramManager {
|
|
|
4605
5335
|
* keyProvider.useCache(true);
|
|
4606
5336
|
*
|
|
4607
5337
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
4608
|
-
* const programManager = new ProgramManager("https://api.
|
|
5338
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider);
|
|
4609
5339
|
*
|
|
4610
5340
|
* // Build the `Authorization`.
|
|
4611
5341
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -4744,7 +5474,7 @@ class ProgramManager {
|
|
|
4744
5474
|
* keyProvider.useCache(true);
|
|
4745
5475
|
*
|
|
4746
5476
|
* // Initialize a ProgramManager with the key and record providers.
|
|
4747
|
-
* const programManager = new ProgramManager("https://api.
|
|
5477
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4748
5478
|
*
|
|
4749
5479
|
* // Build the `Authorization`.
|
|
4750
5480
|
* const authorization = await programManager.buildAuthorization({
|
|
@@ -4827,7 +5557,7 @@ class ProgramManager {
|
|
|
4827
5557
|
* keyProvider.useCache(true);
|
|
4828
5558
|
*
|
|
4829
5559
|
* // Initialize a ProgramManager with the key and record providers.
|
|
4830
|
-
* const programManager = new ProgramManager("https://api.
|
|
5560
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4831
5561
|
*
|
|
4832
5562
|
* // Build the unchecked `Authorization`.
|
|
4833
5563
|
* const authorization = await programManager.buildAuthorizationUnchecked({
|
|
@@ -4910,7 +5640,7 @@ class ProgramManager {
|
|
|
4910
5640
|
* keyProvider.useCache(true);
|
|
4911
5641
|
*
|
|
4912
5642
|
* // Initialize a ProgramManager with the key and record providers.
|
|
4913
|
-
* const programManager = new ProgramManager("https://api.
|
|
5643
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
4914
5644
|
*
|
|
4915
5645
|
* // Build the proving request.
|
|
4916
5646
|
* const provingRequest = await programManager.provingRequest({
|
|
@@ -4928,8 +5658,9 @@ class ProgramManager {
|
|
|
4928
5658
|
async provingRequest(options) {
|
|
4929
5659
|
// Destructure the options object to access the parameters.
|
|
4930
5660
|
const { functionName, priorityFee, privateFee, inputs, recordSearchParams, broadcast = false, unchecked = false, } = options;
|
|
4931
|
-
const privateKey = options.privateKey;
|
|
4932
5661
|
const baseFee = options.baseFee ? options.baseFee : 0;
|
|
5662
|
+
const privateKey = options.privateKey;
|
|
5663
|
+
const useFeeMaster = options.useFeeMaster ? options.useFeeMaster : false;
|
|
4933
5664
|
let program = options.programSource;
|
|
4934
5665
|
let programName = options.programName;
|
|
4935
5666
|
let feeRecord = options.feeRecord;
|
|
@@ -4981,7 +5712,7 @@ class ProgramManager {
|
|
|
4981
5712
|
}
|
|
4982
5713
|
// Get the fee record from the account if it is not provided in the parameters
|
|
4983
5714
|
try {
|
|
4984
|
-
if (privateFee) {
|
|
5715
|
+
if (privateFee && !useFeeMaster) {
|
|
4985
5716
|
let fee = priorityFee;
|
|
4986
5717
|
// If a fee record wasn't provided, estimate the fee that needs to be paid.
|
|
4987
5718
|
if (!feeRecord) {
|
|
@@ -5000,7 +5731,7 @@ class ProgramManager {
|
|
|
5000
5731
|
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.`);
|
|
5001
5732
|
}
|
|
5002
5733
|
// Build and return the `ProvingRequest`.
|
|
5003
|
-
return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName, inputs, baseFee, priorityFee, feeRecord, imports, broadcast, unchecked, edition);
|
|
5734
|
+
return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName, inputs, baseFee, priorityFee, feeRecord, imports, broadcast, unchecked, edition, useFeeMaster);
|
|
5004
5735
|
}
|
|
5005
5736
|
/**
|
|
5006
5737
|
* Builds a SnarkVM fee `Authorization` for `credits.aleo/fee_private` or `credits.aleo/fee_public`. If a record is provided `fee_private` will be executed, otherwise `fee_public` will be executed.
|
|
@@ -5018,7 +5749,7 @@ class ProgramManager {
|
|
|
5018
5749
|
* keyProvider.useCache(true);
|
|
5019
5750
|
*
|
|
5020
5751
|
* // Initialize a ProgramManager with the key and record providers.
|
|
5021
|
-
* const programManager = new ProgramManager("https://api.
|
|
5752
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5022
5753
|
*
|
|
5023
5754
|
* // Build a credits.aleo/fee_public `Authorization`.
|
|
5024
5755
|
* const feePublicAuthorization = await programManager.buildFeeAuthorization({
|
|
@@ -5065,7 +5796,7 @@ class ProgramManager {
|
|
|
5065
5796
|
* keyProvider.useCache(true);
|
|
5066
5797
|
*
|
|
5067
5798
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5068
|
-
* const programManager = new ProgramManager("https://api.
|
|
5799
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5069
5800
|
*
|
|
5070
5801
|
* // Build and execute the transaction
|
|
5071
5802
|
* const tx_id = await programManager.execute({
|
|
@@ -5181,7 +5912,7 @@ class ProgramManager {
|
|
|
5181
5912
|
* keyProvider.useCache(true);
|
|
5182
5913
|
*
|
|
5183
5914
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5184
|
-
* const programManager = new ProgramManager("https://api.
|
|
5915
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5185
5916
|
* const record_1 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
5186
5917
|
* const record_2 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 1540945439182663264862696551825005342995406165131907382295858612069623286213group.public}"
|
|
5187
5918
|
* const tx_id = await programManager.join(record_1, record_2, 0.05, false);
|
|
@@ -5294,7 +6025,7 @@ class ProgramManager {
|
|
|
5294
6025
|
* keyProvider.useCache(true);
|
|
5295
6026
|
*
|
|
5296
6027
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5297
|
-
* const programManager = new ProgramManager("https://api.
|
|
6028
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5298
6029
|
* const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
5299
6030
|
* const tx_id = await programManager.split(25000000, record);
|
|
5300
6031
|
*
|
|
@@ -5409,7 +6140,7 @@ class ProgramManager {
|
|
|
5409
6140
|
* keyProvider.useCache(true);
|
|
5410
6141
|
*
|
|
5411
6142
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5412
|
-
* const programManager = new ProgramManager("https://api.
|
|
6143
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5413
6144
|
* const tx = await programManager.buildTransferTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
5414
6145
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
5415
6146
|
*
|
|
@@ -5506,7 +6237,7 @@ class ProgramManager {
|
|
|
5506
6237
|
* keyProvider.useCache(true);
|
|
5507
6238
|
*
|
|
5508
6239
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5509
|
-
* const programManager = new ProgramManager("https://api.
|
|
6240
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5510
6241
|
* const tx = await programManager.buildTransferPublicTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
5511
6242
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
5512
6243
|
*
|
|
@@ -5539,7 +6270,7 @@ class ProgramManager {
|
|
|
5539
6270
|
* keyProvider.useCache(true);
|
|
5540
6271
|
*
|
|
5541
6272
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5542
|
-
* const programManager = new ProgramManager("https://api.
|
|
6273
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5543
6274
|
* const tx = await programManager.buildTransferPublicAsSignerTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
5544
6275
|
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
5545
6276
|
*
|
|
@@ -5577,7 +6308,7 @@ class ProgramManager {
|
|
|
5577
6308
|
* keyProvider.useCache(true);
|
|
5578
6309
|
*
|
|
5579
6310
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
5580
|
-
* const programManager = new ProgramManager("https://api.
|
|
6311
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
5581
6312
|
* const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
5582
6313
|
*
|
|
5583
6314
|
* // Verify the transaction was successful
|
|
@@ -5622,7 +6353,7 @@ class ProgramManager {
|
|
|
5622
6353
|
* keyProvider.useCache(true);
|
|
5623
6354
|
*
|
|
5624
6355
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5625
|
-
* const programManager = new ProgramManager("https://api.
|
|
6356
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5626
6357
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
5627
6358
|
*
|
|
5628
6359
|
* // Create the bonding transaction object for later submission
|
|
@@ -5678,7 +6409,7 @@ class ProgramManager {
|
|
|
5678
6409
|
* keyProvider.useCache(true);
|
|
5679
6410
|
*
|
|
5680
6411
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5681
|
-
* const programManager = new ProgramManager("https://api.
|
|
6412
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5682
6413
|
*
|
|
5683
6414
|
* // Create the bonding transaction
|
|
5684
6415
|
* tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
@@ -5726,7 +6457,7 @@ class ProgramManager {
|
|
|
5726
6457
|
* keyProvider.useCache(true);
|
|
5727
6458
|
*
|
|
5728
6459
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5729
|
-
* const programManager = new ProgramManager("https://api.
|
|
6460
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5730
6461
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
5731
6462
|
*
|
|
5732
6463
|
* // Create the bond validator transaction object for later use.
|
|
@@ -5785,7 +6516,7 @@ class ProgramManager {
|
|
|
5785
6516
|
* keyProvider.useCache(true);
|
|
5786
6517
|
*
|
|
5787
6518
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5788
|
-
* const programManager = new ProgramManager("https://api.
|
|
6519
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5789
6520
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
5790
6521
|
*
|
|
5791
6522
|
* // Create the bonding transaction
|
|
@@ -5832,7 +6563,7 @@ class ProgramManager {
|
|
|
5832
6563
|
* keyProvider.useCache(true);
|
|
5833
6564
|
*
|
|
5834
6565
|
* // Create a new ProgramManager with the key that will be used to unbond credits.
|
|
5835
|
-
* const programManager = new ProgramManager("https://api.
|
|
6566
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5836
6567
|
* const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
|
|
5837
6568
|
*
|
|
5838
6569
|
* // The transaction can be submitted later to the network using the network client.
|
|
@@ -5885,7 +6616,7 @@ class ProgramManager {
|
|
|
5885
6616
|
* keyProvider.useCache(true);
|
|
5886
6617
|
*
|
|
5887
6618
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5888
|
-
* const programManager = new ProgramManager("https://api.
|
|
6619
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5889
6620
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
5890
6621
|
*
|
|
5891
6622
|
* // Create the unbond_public transaction and send it to the network
|
|
@@ -5931,7 +6662,7 @@ class ProgramManager {
|
|
|
5931
6662
|
* keyProvider.useCache(true);
|
|
5932
6663
|
*
|
|
5933
6664
|
* // Create a new ProgramManager with the key that will be used to claim unbonded credits.
|
|
5934
|
-
* const programManager = new ProgramManager("https://api.
|
|
6665
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5935
6666
|
*
|
|
5936
6667
|
* // Create the claim_unbond_public transaction object for later use.
|
|
5937
6668
|
* const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
|
|
@@ -5981,7 +6712,7 @@ class ProgramManager {
|
|
|
5981
6712
|
* keyProvider.useCache(true);
|
|
5982
6713
|
*
|
|
5983
6714
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
5984
|
-
* const programManager = new ProgramManager("https://api.
|
|
6715
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
5985
6716
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
5986
6717
|
*
|
|
5987
6718
|
* // Create the claim_unbond_public transaction
|
|
@@ -6035,7 +6766,7 @@ class ProgramManager {
|
|
|
6035
6766
|
* keyProvider.useCache(true);
|
|
6036
6767
|
*
|
|
6037
6768
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
6038
|
-
* const programManager = new ProgramManager("https://api.
|
|
6769
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
6039
6770
|
*
|
|
6040
6771
|
* // Create the set_validator_state transaction
|
|
6041
6772
|
* const tx = await programManager.buildSetValidatorStateTransaction(true);
|
|
@@ -6091,7 +6822,7 @@ class ProgramManager {
|
|
|
6091
6822
|
* keyProvider.useCache(true);
|
|
6092
6823
|
*
|
|
6093
6824
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
6094
|
-
* const programManager = new ProgramManager("https://api.
|
|
6825
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, undefined);
|
|
6095
6826
|
*
|
|
6096
6827
|
* // Create the set_validator_state transaction
|
|
6097
6828
|
* const tx_id = await programManager.setValidatorState(true);
|
|
@@ -6213,7 +6944,7 @@ class ProgramManager {
|
|
|
6213
6944
|
* keyProvider.useCache(true);
|
|
6214
6945
|
*
|
|
6215
6946
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
6216
|
-
* const programManager = new ProgramManager("https://api.
|
|
6947
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider);
|
|
6217
6948
|
*
|
|
6218
6949
|
* // Build the `Authorization`.
|
|
6219
6950
|
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
@@ -6274,7 +7005,7 @@ class ProgramManager {
|
|
|
6274
7005
|
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
6275
7006
|
*
|
|
6276
7007
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
6277
|
-
* const programManager = new ProgramManager("https://api.
|
|
7008
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider);
|
|
6278
7009
|
*
|
|
6279
7010
|
* // Get the base fee in microcredits.
|
|
6280
7011
|
* const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
|
|
@@ -6687,5 +7418,5 @@ async function initializeWasm() {
|
|
|
6687
7418
|
console.warn("initializeWasm is deprecated, you no longer need to use it");
|
|
6688
7419
|
}
|
|
6689
7420
|
|
|
6690
|
-
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, SealanceMerkleTree, VALID_TRANSFER_TYPES, initializeWasm,
|
|
7421
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, DecryptionNotEnabledError, 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, RecordNotFoundError, RecordScanner, RecordScannerRequestError, SealanceMerkleTree, UUIDError, VALID_TRANSFER_TYPES, ViewKeyNotStoredError, encryptAuthorization, encryptProvingRequest, encryptRegistrationRequest, encryptViewKey, initializeWasm, isProveApiErrorBody, isProvingResponse, logAndThrow };
|
|
6691
7422
|
//# sourceMappingURL=browser.js.map
|