@provablehq/sdk 0.9.16 → 0.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainnet/browser.d.ts +10 -3
- package/dist/mainnet/browser.js +251 -32
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/keys/keystore/error.d.ts +23 -0
- package/dist/mainnet/keys/keystore/file.d.ts +217 -0
- package/dist/mainnet/keys/keystore/interface.d.ts +85 -0
- package/dist/mainnet/keys/provider/interface.d.ts +170 -0
- package/dist/mainnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
- package/dist/mainnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
- package/dist/mainnet/keys/verifier/interface.d.ts +70 -0
- package/dist/mainnet/keys/verifier/memory.d.ts +37 -0
- package/dist/mainnet/models/keyPair.d.ts +4 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +1 -1
- package/dist/mainnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/mainnet/node.d.ts +1 -0
- package/dist/mainnet/node.js +399 -2
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +2 -1
- package/dist/mainnet/record-scanner.d.ts +16 -0
- package/dist/testnet/browser.d.ts +10 -3
- package/dist/testnet/browser.js +251 -32
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/keys/keystore/error.d.ts +23 -0
- package/dist/testnet/keys/keystore/file.d.ts +217 -0
- package/dist/testnet/keys/keystore/interface.d.ts +85 -0
- package/dist/testnet/keys/provider/interface.d.ts +170 -0
- package/dist/testnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
- package/dist/testnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
- package/dist/testnet/keys/verifier/interface.d.ts +70 -0
- package/dist/testnet/keys/verifier/memory.d.ts +37 -0
- package/dist/testnet/models/keyPair.d.ts +4 -0
- package/dist/testnet/models/record-scanner/error.d.ts +1 -1
- package/dist/testnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/testnet/node.d.ts +1 -0
- package/dist/testnet/node.js +399 -2
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +2 -1
- package/dist/testnet/record-scanner.d.ts +16 -0
- package/package.json +3 -3
package/dist/testnet/browser.js
CHANGED
|
@@ -713,7 +713,7 @@ class AleoNetworkClient {
|
|
|
713
713
|
else {
|
|
714
714
|
this.headers = {
|
|
715
715
|
// This is replaced by the actual version by a Rollup plugin
|
|
716
|
-
"X-Aleo-SDK-Version": "0.9.
|
|
716
|
+
"X-Aleo-SDK-Version": "0.9.17",
|
|
717
717
|
"X-Aleo-environment": environment(),
|
|
718
718
|
};
|
|
719
719
|
}
|
|
@@ -729,7 +729,7 @@ class AleoNetworkClient {
|
|
|
729
729
|
else {
|
|
730
730
|
this.headers = {
|
|
731
731
|
// This is replaced by the actual version by a Rollup plugin
|
|
732
|
-
"X-Aleo-SDK-Version": "0.9.
|
|
732
|
+
"X-Aleo-SDK-Version": "0.9.17",
|
|
733
733
|
"X-Aleo-environment": environment(),
|
|
734
734
|
};
|
|
735
735
|
}
|
|
@@ -2420,13 +2420,13 @@ class RecordNotFoundError extends Error {
|
|
|
2420
2420
|
Object.setPrototypeOf(this, RecordNotFoundError.prototype);
|
|
2421
2421
|
}
|
|
2422
2422
|
}
|
|
2423
|
-
/** Error thrown when a record scanner request fails due to an invalid response. */
|
|
2423
|
+
/** Error thrown when no UUID is configured, the UUID is invalid, or a record scanner request fails due to an invalid UUID/response. */
|
|
2424
2424
|
class UUIDError extends Error {
|
|
2425
2425
|
uuid;
|
|
2426
2426
|
filter;
|
|
2427
2427
|
constructor(message, uuid, filter) {
|
|
2428
2428
|
super(message);
|
|
2429
|
-
this.name = "
|
|
2429
|
+
this.name = "UUIDError";
|
|
2430
2430
|
this.uuid = uuid;
|
|
2431
2431
|
this.filter = filter;
|
|
2432
2432
|
Object.setPrototypeOf(this, UUIDError.prototype);
|
|
@@ -2458,8 +2458,8 @@ class AleoKeyProviderParams {
|
|
|
2458
2458
|
}
|
|
2459
2459
|
}
|
|
2460
2460
|
/**
|
|
2461
|
-
* AleoKeyProvider class. Implements the
|
|
2462
|
-
* verifying keys for the credits.aleo program over
|
|
2461
|
+
* AleoKeyProvider class. Implements the FunctionKeyProvider interface. Enables the retrieval of Aleo program proving and
|
|
2462
|
+
* verifying keys for the credits.aleo program over HTTP from official Aleo sources and storing and retrieving function
|
|
2463
2463
|
* keys from a local memory cache.
|
|
2464
2464
|
*/
|
|
2465
2465
|
class AleoKeyProvider {
|
|
@@ -2481,6 +2481,9 @@ class AleoKeyProvider {
|
|
|
2481
2481
|
this.cache = new Map();
|
|
2482
2482
|
this.cacheOption = false;
|
|
2483
2483
|
}
|
|
2484
|
+
async keyStore() {
|
|
2485
|
+
return undefined;
|
|
2486
|
+
}
|
|
2484
2487
|
/**
|
|
2485
2488
|
* Use local memory to store keys
|
|
2486
2489
|
*
|
|
@@ -2533,8 +2536,11 @@ class AleoKeyProvider {
|
|
|
2533
2536
|
getKeys(keyId) {
|
|
2534
2537
|
console.debug(`Checking if key exists in cache. KeyId: ${keyId}`);
|
|
2535
2538
|
if (this.cache.has(keyId)) {
|
|
2536
|
-
const [provingKeyBytes, verifyingKeyBytes] = this.cache.get(keyId);
|
|
2537
|
-
return [
|
|
2539
|
+
const [provingKeyBytes, verifyingKeyBytes] = (this.cache.get(keyId));
|
|
2540
|
+
return [
|
|
2541
|
+
ProvingKey.fromBytes(provingKeyBytes),
|
|
2542
|
+
VerifyingKey.fromBytes(verifyingKeyBytes),
|
|
2543
|
+
];
|
|
2538
2544
|
}
|
|
2539
2545
|
else {
|
|
2540
2546
|
throw new Error("Key not found in cache.");
|
|
@@ -2566,13 +2572,15 @@ class AleoKeyProvider {
|
|
|
2566
2572
|
let verifierUrl;
|
|
2567
2573
|
let cacheKey;
|
|
2568
2574
|
if ("name" in params && typeof params["name"] == "string") {
|
|
2569
|
-
|
|
2575
|
+
const key = CREDITS_PROGRAM_KEYS.getKey(params["name"]);
|
|
2570
2576
|
return this.fetchCreditsKeys(key);
|
|
2571
2577
|
}
|
|
2572
|
-
if ("proverUri" in params &&
|
|
2578
|
+
if ("proverUri" in params &&
|
|
2579
|
+
typeof params["proverUri"] == "string") {
|
|
2573
2580
|
proverUrl = params["proverUri"];
|
|
2574
2581
|
}
|
|
2575
|
-
if ("verifierUri" in params &&
|
|
2582
|
+
if ("verifierUri" in params &&
|
|
2583
|
+
typeof params["verifierUri"] == "string") {
|
|
2576
2584
|
verifierUrl = params["verifierUri"];
|
|
2577
2585
|
}
|
|
2578
2586
|
if ("cacheKey" in params && typeof params["cacheKey"] == "string") {
|
|
@@ -2621,20 +2629,26 @@ class AleoKeyProvider {
|
|
|
2621
2629
|
}
|
|
2622
2630
|
const value = this.cache.get(cacheKey);
|
|
2623
2631
|
if (typeof value !== "undefined") {
|
|
2624
|
-
return [
|
|
2632
|
+
return [
|
|
2633
|
+
ProvingKey.fromBytes(value[0]),
|
|
2634
|
+
VerifyingKey.fromBytes(value[1]),
|
|
2635
|
+
];
|
|
2625
2636
|
}
|
|
2626
2637
|
else {
|
|
2627
2638
|
console.debug("Fetching proving keys from url " + proverUrl);
|
|
2628
|
-
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2639
|
+
const provingKey = (ProvingKey.fromBytes(await this.fetchBytes(proverUrl)));
|
|
2629
2640
|
console.debug("Fetching verifying keys " + verifierUrl);
|
|
2630
2641
|
const verifyingKey = (await this.getVerifyingKey(verifierUrl));
|
|
2631
|
-
this.cache.set(cacheKey, [
|
|
2642
|
+
this.cache.set(cacheKey, [
|
|
2643
|
+
provingKey.toBytes(),
|
|
2644
|
+
verifyingKey.toBytes(),
|
|
2645
|
+
]);
|
|
2632
2646
|
return [provingKey, verifyingKey];
|
|
2633
2647
|
}
|
|
2634
2648
|
}
|
|
2635
2649
|
else {
|
|
2636
2650
|
// If cache is disabled, fetch the keys and return them
|
|
2637
|
-
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2651
|
+
const provingKey = (ProvingKey.fromBytes(await this.fetchBytes(proverUrl)));
|
|
2638
2652
|
const verifyingKey = (await this.getVerifyingKey(verifierUrl));
|
|
2639
2653
|
return [provingKey, verifyingKey];
|
|
2640
2654
|
}
|
|
@@ -2664,12 +2678,12 @@ class AleoKeyProvider {
|
|
|
2664
2678
|
}
|
|
2665
2679
|
else {
|
|
2666
2680
|
console.debug("Fetching proving keys from url " + proverUrl);
|
|
2667
|
-
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2681
|
+
const provingKey = (ProvingKey.fromBytes(await this.fetchBytes(proverUrl)));
|
|
2668
2682
|
return provingKey;
|
|
2669
2683
|
}
|
|
2670
2684
|
}
|
|
2671
2685
|
else {
|
|
2672
|
-
const provingKey = ProvingKey.fromBytes(await this.fetchBytes(proverUrl));
|
|
2686
|
+
const provingKey = (ProvingKey.fromBytes(await this.fetchBytes(proverUrl)));
|
|
2673
2687
|
return provingKey;
|
|
2674
2688
|
}
|
|
2675
2689
|
}
|
|
@@ -2681,7 +2695,7 @@ class AleoKeyProvider {
|
|
|
2681
2695
|
try {
|
|
2682
2696
|
if (!this.cache.has(key.locator) || !this.cacheOption) {
|
|
2683
2697
|
const verifying_key = key.verifyingKey();
|
|
2684
|
-
const proving_key = await this.fetchProvingKey(key.prover, key.locator);
|
|
2698
|
+
const proving_key = (await this.fetchProvingKey(key.prover, key.locator));
|
|
2685
2699
|
if (this.cacheOption) {
|
|
2686
2700
|
this.cache.set(CREDITS_PROGRAM_KEYS.getKey(key.name).locator, [proving_key.toBytes(), verifying_key.toBytes()]);
|
|
2687
2701
|
}
|
|
@@ -2689,7 +2703,10 @@ class AleoKeyProvider {
|
|
|
2689
2703
|
}
|
|
2690
2704
|
else {
|
|
2691
2705
|
const keyPair = this.cache.get(key.locator);
|
|
2692
|
-
return [
|
|
2706
|
+
return [
|
|
2707
|
+
ProvingKey.fromBytes(keyPair[0]),
|
|
2708
|
+
VerifyingKey.fromBytes(keyPair[1]),
|
|
2709
|
+
];
|
|
2693
2710
|
}
|
|
2694
2711
|
}
|
|
2695
2712
|
catch (error) {
|
|
@@ -2839,7 +2856,7 @@ class AleoKeyProvider {
|
|
|
2839
2856
|
catch (e) {
|
|
2840
2857
|
/// If that fails, try to fetch the verifying key from the network as bytes
|
|
2841
2858
|
try {
|
|
2842
|
-
return VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
|
|
2859
|
+
return (VerifyingKey.fromBytes(await this.fetchBytes(verifierUri)));
|
|
2843
2860
|
}
|
|
2844
2861
|
catch (inner) {
|
|
2845
2862
|
throw new Error("Invalid verifying key. Error: " + inner.message);
|
|
@@ -2852,6 +2869,156 @@ class AleoKeyProvider {
|
|
|
2852
2869
|
}
|
|
2853
2870
|
}
|
|
2854
2871
|
|
|
2872
|
+
/**
|
|
2873
|
+
* Error thrown when there is a mismatch between expected and actual key metadata.
|
|
2874
|
+
* This can occur during verification of either the checksum or size of a key.
|
|
2875
|
+
*
|
|
2876
|
+
* @extends Error
|
|
2877
|
+
*/
|
|
2878
|
+
class KeyVerificationError extends Error {
|
|
2879
|
+
locator;
|
|
2880
|
+
field;
|
|
2881
|
+
expected;
|
|
2882
|
+
actual;
|
|
2883
|
+
/**
|
|
2884
|
+
* Creates a new KeyVerificationError instance (error.name is "ChecksumMismatchError").
|
|
2885
|
+
*
|
|
2886
|
+
* @param {string} locator - The key locator where the mismatch occurred.
|
|
2887
|
+
* @param {"checksum" | "size"} field - The field that failed verification (either "checksum" or "size").
|
|
2888
|
+
* @param {string} expected - The expected value of the field.
|
|
2889
|
+
* @param {string} actual - The actual value encountered.
|
|
2890
|
+
*/
|
|
2891
|
+
constructor(locator, field, expected, actual) {
|
|
2892
|
+
super(`Key verification ${locator} ${field} mismatch: expected ${expected}, got ${actual}`);
|
|
2893
|
+
this.locator = locator;
|
|
2894
|
+
this.field = field;
|
|
2895
|
+
this.expected = expected;
|
|
2896
|
+
this.actual = actual;
|
|
2897
|
+
this.name = "ChecksumMismatchError";
|
|
2898
|
+
Object.setPrototypeOf(this, KeyVerificationError.prototype);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Computes the SHA-256 checksum of a given set of bytes.
|
|
2903
|
+
*
|
|
2904
|
+
* @param {Uint8Array} bytes - The bytes to compute the checksum of.
|
|
2905
|
+
*/
|
|
2906
|
+
async function sha256Hex(bytes) {
|
|
2907
|
+
const hash = await crypto.subtle.digest("SHA-256", bytes);
|
|
2908
|
+
return Array.from(new Uint8Array(hash))
|
|
2909
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
2910
|
+
.join("");
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2913
|
+
/**
|
|
2914
|
+
* In-memory implementation of KeyVerifier that stores and verifies key fingerprints.
|
|
2915
|
+
* Provides functionality to compute and verify cryptographic checksums of keys, storing them
|
|
2916
|
+
* in memory for subsequent verification. This implementation is primarily used for testing
|
|
2917
|
+
* and development purposes where persistence is not required.
|
|
2918
|
+
*
|
|
2919
|
+
* Key features:
|
|
2920
|
+
* - Computes SHA-256 checksums and sizes for key bytes.
|
|
2921
|
+
* - Stores key fingerprints in memory using string locators.
|
|
2922
|
+
* - Verifies key bytes against stored or provided fingerprints.
|
|
2923
|
+
*
|
|
2924
|
+
* @implements {KeyVerifier}
|
|
2925
|
+
*/
|
|
2926
|
+
class MemKeyVerifier {
|
|
2927
|
+
keyStore = {};
|
|
2928
|
+
/**
|
|
2929
|
+
* Computes and optionally stores key metadata. If a keyFingerprint is provided, this function will verify the computed checksum against it before storing it.
|
|
2930
|
+
*
|
|
2931
|
+
* @param {KeyMetadata} keyMetadata - Object containing key bytes and optional verification data.
|
|
2932
|
+
* @throws {KeyVerificationError} When provided keyFingerprint doesn't match computed values.
|
|
2933
|
+
* @returns {Promise<KeyFingerprint>} Computed key metadata.
|
|
2934
|
+
*/
|
|
2935
|
+
async computeKeyMetadata(keyMetadata) {
|
|
2936
|
+
// Compute the metadata from the key bytes
|
|
2937
|
+
const computedFingerprint = {
|
|
2938
|
+
checksum: await sha256Hex(keyMetadata.keyBytes),
|
|
2939
|
+
size: keyMetadata.keyBytes.length
|
|
2940
|
+
};
|
|
2941
|
+
// If a KeyFingerprint is provided, verify it matches computed values.
|
|
2942
|
+
if (keyMetadata.fingerprint) {
|
|
2943
|
+
if (keyMetadata.fingerprint.size !== computedFingerprint.size) {
|
|
2944
|
+
throw new KeyVerificationError(keyMetadata.locator ? keyMetadata.locator : "", "size", String(keyMetadata.fingerprint.size), String(computedFingerprint.size));
|
|
2945
|
+
}
|
|
2946
|
+
if (keyMetadata.fingerprint.checksum !== computedFingerprint.checksum) {
|
|
2947
|
+
throw new KeyVerificationError(keyMetadata.locator ? keyMetadata.locator : "", "checksum", keyMetadata.fingerprint.checksum, computedFingerprint.checksum);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
// If locator is provided, store only the fingerprint
|
|
2951
|
+
if (keyMetadata.locator) {
|
|
2952
|
+
this.keyStore[keyMetadata.locator] = computedFingerprint;
|
|
2953
|
+
}
|
|
2954
|
+
return computedFingerprint;
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* Verifies key bytes against stored or provided metadata. Follows a priority verification scheme:
|
|
2958
|
+
* 1. If KeyFingerprint is provided in the metadata, this method verifies against that first.
|
|
2959
|
+
* 2. If a locator is provided, attempts to verify against stored fingerprint.
|
|
2960
|
+
* 3. If neither is available, throws an error.
|
|
2961
|
+
*
|
|
2962
|
+
* @param {KeyMetadata} keyMetadata - Object containing the key bytes and optional verification metadata.
|
|
2963
|
+
* @throws {Error} When neither fingerprint nor valid locator is provided for verification.
|
|
2964
|
+
* @throws {KeyVerificationError} When size or checksum verification fails.
|
|
2965
|
+
* @returns {Promise<void>} Promise that resolves when verification succeeds.
|
|
2966
|
+
*/
|
|
2967
|
+
async verifyKeyBytes(keyMetadata) {
|
|
2968
|
+
if (!keyMetadata.keyBytes) {
|
|
2969
|
+
throw new Error("Key bytes must be provided for verification.");
|
|
2970
|
+
}
|
|
2971
|
+
// Compute the fingerprint for the provided bytes.
|
|
2972
|
+
const computedFingerprint = await this.computeKeyMetadata({
|
|
2973
|
+
keyBytes: keyMetadata.keyBytes
|
|
2974
|
+
});
|
|
2975
|
+
// Determine which fingerprint to verify against.
|
|
2976
|
+
let fingerprintToVerify;
|
|
2977
|
+
if (keyMetadata.fingerprint) {
|
|
2978
|
+
// If a key fingerprint is provided, use it.
|
|
2979
|
+
fingerprintToVerify = keyMetadata.fingerprint;
|
|
2980
|
+
}
|
|
2981
|
+
else if (keyMetadata.locator) {
|
|
2982
|
+
// Otherwise try to get stored fingerprint by locator.
|
|
2983
|
+
fingerprintToVerify = this.keyStore[keyMetadata.locator];
|
|
2984
|
+
}
|
|
2985
|
+
if (!fingerprintToVerify) {
|
|
2986
|
+
throw new Error("Either fingerprint or a valid locator must be provided for verification.");
|
|
2987
|
+
}
|
|
2988
|
+
// Verify the key size.
|
|
2989
|
+
if (fingerprintToVerify.size !== computedFingerprint.size) {
|
|
2990
|
+
throw new KeyVerificationError(keyMetadata.locator || "", "size", String(fingerprintToVerify.size), String(computedFingerprint.size));
|
|
2991
|
+
}
|
|
2992
|
+
// Verify the key checksum.
|
|
2993
|
+
if (fingerprintToVerify.checksum !== computedFingerprint.checksum) {
|
|
2994
|
+
throw new KeyVerificationError(keyMetadata.locator || "", "checksum", fingerprintToVerify.checksum, computedFingerprint.checksum);
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
/**
|
|
3000
|
+
* Error thrown when a key locator is invalid for filesystem use.
|
|
3001
|
+
* Used to prevent path traversal and other filesystem injection when deriving paths from locators.
|
|
3002
|
+
*
|
|
3003
|
+
* @extends Error
|
|
3004
|
+
*/
|
|
3005
|
+
class InvalidLocatorError extends Error {
|
|
3006
|
+
locator;
|
|
3007
|
+
reason;
|
|
3008
|
+
/**
|
|
3009
|
+
* @param message - Human-readable description of the validation failure.
|
|
3010
|
+
* @param locator - The invalid locator string that failed validation.
|
|
3011
|
+
* @param reason - Machine-readable reason code for the failure.
|
|
3012
|
+
*/
|
|
3013
|
+
constructor(message, locator, reason) {
|
|
3014
|
+
super(message);
|
|
3015
|
+
this.locator = locator;
|
|
3016
|
+
this.reason = reason;
|
|
3017
|
+
this.name = "InvalidLocatorError";
|
|
3018
|
+
Object.setPrototypeOf(this, InvalidLocatorError.prototype);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
|
|
2855
3022
|
/**
|
|
2856
3023
|
* Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
|
|
2857
3024
|
* a convenience method for creating a new instance of this class for each function of the credits.aleo program.
|
|
@@ -2891,7 +3058,7 @@ class OfflineSearchParams {
|
|
|
2891
3058
|
return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_validator.locator, true);
|
|
2892
3059
|
}
|
|
2893
3060
|
/**
|
|
2894
|
-
* Create a new OfflineSearchParams instance for the claim_unbond_public function of the
|
|
3061
|
+
* Create a new OfflineSearchParams instance for the claim_unbond_public function of the credits.aleo program.
|
|
2895
3062
|
*/
|
|
2896
3063
|
static claimUnbondPublicKeyParams() {
|
|
2897
3064
|
return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, true);
|
|
@@ -3025,6 +3192,9 @@ class OfflineKeyProvider {
|
|
|
3025
3192
|
constructor() {
|
|
3026
3193
|
this.cache = new Map();
|
|
3027
3194
|
}
|
|
3195
|
+
keyStore() {
|
|
3196
|
+
return Promise.resolve(undefined);
|
|
3197
|
+
}
|
|
3028
3198
|
/**
|
|
3029
3199
|
* Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
|
|
3030
3200
|
* method for it to work.
|
|
@@ -4005,6 +4175,56 @@ class RecordScanner {
|
|
|
4005
4175
|
return this.handleRequestError(err);
|
|
4006
4176
|
}
|
|
4007
4177
|
}
|
|
4178
|
+
/**
|
|
4179
|
+
* Remove all local scanner state associated with the given UUID (stored uuid, viewKeys entry, account if it matches).
|
|
4180
|
+
* Called after a successful revoke so the scanner does not retain view keys or account for a revoked registration.
|
|
4181
|
+
*/
|
|
4182
|
+
clearLocalStateForUuid(uuidStr) {
|
|
4183
|
+
if (this.uuid != null && this.uuid.toString() === uuidStr) {
|
|
4184
|
+
this.uuid = undefined;
|
|
4185
|
+
}
|
|
4186
|
+
if (this.viewKeys != null) {
|
|
4187
|
+
delete this.viewKeys[uuidStr];
|
|
4188
|
+
if (Object.keys(this.viewKeys).length === 0) {
|
|
4189
|
+
this.viewKeys = undefined;
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
if (this.account != null && this.computeUUID(this.account.viewKey()).toString() === uuidStr) {
|
|
4193
|
+
this.account = undefined;
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
/**
|
|
4197
|
+
* Revoke the account registration with the record scanning service (POST /revoke). On success, also removes
|
|
4198
|
+
* all local state for that UUID: the stored UUID (if it matches), the view key for that UUID, and the
|
|
4199
|
+
* account (if its view key corresponds to that UUID).
|
|
4200
|
+
*
|
|
4201
|
+
* @param {string | Field | undefined} uuid The UUID to revoke. If omitted, uses the UUID configured on the scanner.
|
|
4202
|
+
* @returns {Promise<RevokeResult>} `{ ok: true, data: { status } }` on success, or `{ ok: false, status, error }` on failure.
|
|
4203
|
+
* @throws {UUIDError} When no UUID is configured and none provided, or when the UUID string is invalid.
|
|
4204
|
+
*/
|
|
4205
|
+
async revoke(uuid) {
|
|
4206
|
+
const resolvedUuid = uuid ?? this.uuid;
|
|
4207
|
+
if (!resolvedUuid) {
|
|
4208
|
+
throw new UUIDError("No UUID configured for the record scanner and no UUID provided.");
|
|
4209
|
+
}
|
|
4210
|
+
const uuidStr = typeof resolvedUuid === "string" ? resolvedUuid : resolvedUuid.toString();
|
|
4211
|
+
if (!this.uuidIsValid(uuidStr)) {
|
|
4212
|
+
throw new UUIDError(`UUID provided ${uuidStr} is invalid`, uuidStr);
|
|
4213
|
+
}
|
|
4214
|
+
try {
|
|
4215
|
+
const response = await this.request(new Request(`${this.url}/revoke`, {
|
|
4216
|
+
method: "POST",
|
|
4217
|
+
headers: { "Content-Type": "application/json" },
|
|
4218
|
+
body: JSON.stringify(uuidStr),
|
|
4219
|
+
}));
|
|
4220
|
+
const data = await response.json();
|
|
4221
|
+
this.clearLocalStateForUuid(uuidStr);
|
|
4222
|
+
return { ok: true, data };
|
|
4223
|
+
}
|
|
4224
|
+
catch (err) {
|
|
4225
|
+
return this.handleRequestError(err);
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4008
4228
|
/**
|
|
4009
4229
|
* Get encrypted records from the record scanning service. This is a safe variant of /records/encrypted that returns
|
|
4010
4230
|
* a result instead of throwing on HTTP error.
|
|
@@ -4164,8 +4384,7 @@ class RecordScanner {
|
|
|
4164
4384
|
// Throw an error if none could be found, otherwise set the UUID on the filter with either the UUID configured
|
|
4165
4385
|
// within the filter or the UUID configured within the scanner.
|
|
4166
4386
|
if (!uuid) {
|
|
4167
|
-
throw new
|
|
4168
|
-
"provided in the record filter was invalid.");
|
|
4387
|
+
throw new UUIDError("Error while using the record scanner. UUID is not set on the scanner and the UUID provided in the record filter was invalid.", undefined, filter);
|
|
4169
4388
|
}
|
|
4170
4389
|
filter.uuid = uuid;
|
|
4171
4390
|
// Inner request used to retry once after 422 re-register without duplicating logic.
|
|
@@ -5240,8 +5459,8 @@ class ProgramManager {
|
|
|
5240
5459
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
5241
5460
|
}
|
|
5242
5461
|
catch (e) {
|
|
5243
|
-
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition
|
|
5244
|
-
edition =
|
|
5462
|
+
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 0.`);
|
|
5463
|
+
edition = 0;
|
|
5245
5464
|
}
|
|
5246
5465
|
}
|
|
5247
5466
|
// Get the private key from the account if it is not provided in the parameters
|
|
@@ -5524,8 +5743,8 @@ class ProgramManager {
|
|
|
5524
5743
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
5525
5744
|
}
|
|
5526
5745
|
catch (e) {
|
|
5527
|
-
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition
|
|
5528
|
-
edition =
|
|
5746
|
+
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 0.`);
|
|
5747
|
+
edition = 0;
|
|
5529
5748
|
}
|
|
5530
5749
|
}
|
|
5531
5750
|
// Resolve the program imports if they exist.
|
|
@@ -5617,8 +5836,8 @@ class ProgramManager {
|
|
|
5617
5836
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
5618
5837
|
}
|
|
5619
5838
|
catch (e) {
|
|
5620
|
-
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition
|
|
5621
|
-
edition =
|
|
5839
|
+
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 0.`);
|
|
5840
|
+
edition = 0;
|
|
5622
5841
|
}
|
|
5623
5842
|
}
|
|
5624
5843
|
// Build and return an `Authorization` for the desired function.
|
|
@@ -5687,8 +5906,8 @@ class ProgramManager {
|
|
|
5687
5906
|
edition = await this.networkClient.getLatestProgramEdition(programName);
|
|
5688
5907
|
}
|
|
5689
5908
|
catch (e) {
|
|
5690
|
-
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition
|
|
5691
|
-
edition =
|
|
5909
|
+
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 0.`);
|
|
5910
|
+
edition = 0;
|
|
5692
5911
|
}
|
|
5693
5912
|
}
|
|
5694
5913
|
// Get the private key from the account if it is not provided in the parameters.
|
|
@@ -7418,5 +7637,5 @@ async function initializeWasm() {
|
|
|
7418
7637
|
console.warn("initializeWasm is deprecated, you no longer need to use it");
|
|
7419
7638
|
}
|
|
7420
7639
|
|
|
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 };
|
|
7640
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KeyVerificationError as ChecksumMismatchError, DecryptionNotEnabledError, InvalidLocatorError, KEY_STORE, KeyVerificationError, MemKeyVerifier, 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, sha256Hex };
|
|
7422
7641
|
//# sourceMappingURL=browser.js.map
|