@provablehq/sdk 0.10.6-rc.1 → 0.11.0

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.
Files changed (47) hide show
  1. package/dist/mainnet/browser.cjs +105 -66
  2. package/dist/mainnet/browser.cjs.map +1 -1
  3. package/dist/mainnet/browser.d.cts +1 -1
  4. package/dist/mainnet/browser.d.ts +1 -1
  5. package/dist/mainnet/browser.js +102 -67
  6. package/dist/mainnet/browser.js.map +1 -1
  7. package/dist/mainnet/keys/keystore/indexeddb.d.cts +11 -0
  8. package/dist/mainnet/keys/keystore/indexeddb.d.ts +11 -0
  9. package/dist/mainnet/network-client.d.cts +5 -1
  10. package/dist/mainnet/network-client.d.ts +5 -1
  11. package/dist/mainnet/node.cjs +4 -0
  12. package/dist/mainnet/node.cjs.map +1 -1
  13. package/dist/mainnet/node.js +1 -1
  14. package/dist/mainnet/record-scanner.d.cts +11 -0
  15. package/dist/mainnet/record-scanner.d.ts +11 -0
  16. package/dist/mainnet/utils/logger.d.cts +4 -0
  17. package/dist/mainnet/utils/logger.d.ts +4 -0
  18. package/dist/mainnet/wasm-Bnb_v1_O.js +3 -0
  19. package/dist/mainnet/wasm-Bnb_v1_O.js.map +1 -0
  20. package/dist/mainnet/wasm.cjs +251 -0
  21. package/dist/mainnet/wasm.cjs.map +1 -0
  22. package/dist/mainnet/wasm.d.cts +1 -1
  23. package/dist/mainnet/wasm.d.ts +1 -1
  24. package/dist/testnet/browser.cjs +105 -66
  25. package/dist/testnet/browser.cjs.map +1 -1
  26. package/dist/testnet/browser.d.cts +1 -1
  27. package/dist/testnet/browser.d.ts +1 -1
  28. package/dist/testnet/browser.js +102 -67
  29. package/dist/testnet/browser.js.map +1 -1
  30. package/dist/testnet/keys/keystore/indexeddb.d.cts +11 -0
  31. package/dist/testnet/keys/keystore/indexeddb.d.ts +11 -0
  32. package/dist/testnet/network-client.d.cts +5 -1
  33. package/dist/testnet/network-client.d.ts +5 -1
  34. package/dist/testnet/node.cjs +4 -0
  35. package/dist/testnet/node.cjs.map +1 -1
  36. package/dist/testnet/node.js +1 -1
  37. package/dist/testnet/record-scanner.d.cts +11 -0
  38. package/dist/testnet/record-scanner.d.ts +11 -0
  39. package/dist/testnet/utils/logger.d.cts +4 -0
  40. package/dist/testnet/utils/logger.d.ts +4 -0
  41. package/dist/testnet/wasm-BCrMb35a.js +3 -0
  42. package/dist/testnet/wasm-BCrMb35a.js.map +1 -0
  43. package/dist/testnet/wasm.cjs +251 -0
  44. package/dist/testnet/wasm.cjs.map +1 -0
  45. package/dist/testnet/wasm.d.cts +1 -1
  46. package/dist/testnet/wasm.d.ts +1 -1
  47. package/package.json +2 -2
@@ -64,7 +64,7 @@ export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorization
64
64
  export { logAndThrow, TransportFunction } from "./utils/utils.js";
65
65
  export { setLogLevel, getLogLevel } from "./utils/logger.js";
66
66
  export type { LogLevel } from "./utils/logger.js";
67
- export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, QueryOption, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
67
+ export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, QueryOption, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, setWasmLogLevel, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
68
68
  export { initializeWasm };
69
69
  export { Key, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, RECORD_DOMAIN, VALID_TRANSFER_TYPES, } from "./constants.js";
70
70
  export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, BroadcastResponse, BroadcastResult, CachedKeyPair, ConfirmedTransactionJSON, CryptoBoxPubKey, DecryptionNotEnabledError, DeploymentJSON, DeploymentObject, EncryptedProvingRequest, EncryptedRecord, EncryptedRegistrationRequest, EncryptedRecordsResult, EncryptedRecordsSuccess, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, isProvingResponse, isProveApiErrorBody, ImportedPrograms, ImportedVerifyingKeys, IndexedDBKeyStore, InputJSON, InputObject, InvalidLocatorError, InvalidLocatorReason, BaseFunctionKeyLocator, KeyFingerprint, KeyLocator, KeyMetadata, KeySearchParams, KeyStore, KeyType, KeyVerificationError, ProvingKeyLocator, provingKeyLocator, TranslationKeyLocator, translationKeyLocator, VerifyingKeyLocator, verifyingKeyLocator, KeyVerifier, MemKeyVerifier, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnedRecordsResult, OwnedRecordsResponseFilter, OwnedRecordsSuccess, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProveApiErrorBody, ProvingFailure, ProvingRequestError, ProvingRequestJSON, ProvingResult, ProvingSuccess, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordScannerErrorBody, RecordScannerFailure, RecordScannerJWTData, RecordScannerOptions, RecordNotFoundError, RecordScannerRequestError, ViewKeyNotStoredError, RecordSearchParams, RegisterResult, RegisterSuccess, RegistrationResponse, RevokeResult, RevokeSuccess, RevokeResponse, SealanceMerkleTree, SerialNumbersResult, SerialNumbersSuccess, sha256Hex, SolutionJSON, SolutionsJSON, StatusResponse, StatusResult, StatusSuccess, TagsResult, TagsSuccess, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, UUIDError, VerifyingKeys, };
@@ -64,7 +64,7 @@ export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorization
64
64
  export { logAndThrow, TransportFunction } from "./utils/utils.js";
65
65
  export { setLogLevel, getLogLevel } from "./utils/logger.js";
66
66
  export type { LogLevel } from "./utils/logger.js";
67
- export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, QueryOption, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
67
+ export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, QueryOption, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, setWasmLogLevel, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
68
68
  export { initializeWasm };
69
69
  export { Key, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, RECORD_DOMAIN, VALID_TRANSFER_TYPES, } from "./constants.js";
70
70
  export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, BroadcastResponse, BroadcastResult, CachedKeyPair, ConfirmedTransactionJSON, CryptoBoxPubKey, DecryptionNotEnabledError, DeploymentJSON, DeploymentObject, EncryptedProvingRequest, EncryptedRecord, EncryptedRegistrationRequest, EncryptedRecordsResult, EncryptedRecordsSuccess, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, isProvingResponse, isProveApiErrorBody, ImportedPrograms, ImportedVerifyingKeys, IndexedDBKeyStore, InputJSON, InputObject, InvalidLocatorError, InvalidLocatorReason, BaseFunctionKeyLocator, KeyFingerprint, KeyLocator, KeyMetadata, KeySearchParams, KeyStore, KeyType, KeyVerificationError, ProvingKeyLocator, provingKeyLocator, TranslationKeyLocator, translationKeyLocator, VerifyingKeyLocator, verifyingKeyLocator, KeyVerifier, MemKeyVerifier, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnedRecordsResult, OwnedRecordsResponseFilter, OwnedRecordsSuccess, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProveApiErrorBody, ProvingFailure, ProvingRequestError, ProvingRequestJSON, ProvingResult, ProvingSuccess, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordScannerErrorBody, RecordScannerFailure, RecordScannerJWTData, RecordScannerOptions, RecordNotFoundError, RecordScannerRequestError, ViewKeyNotStoredError, RecordSearchParams, RegisterResult, RegisterSuccess, RegistrationResponse, RevokeResult, RevokeSuccess, RevokeResponse, SealanceMerkleTree, SerialNumbersResult, SerialNumbersSuccess, sha256Hex, SolutionJSON, SolutionsJSON, StatusResponse, StatusResult, StatusSuccess, TagsResult, TagsSuccess, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, UUIDError, VerifyingKeys, };
@@ -1,6 +1,6 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
2
  import { ProvingKey, VerifyingKey, ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Metadata, Program, Plaintext, Transaction, ProvingRequest, RecordPlaintext, Field, Poseidon4, ProgramManager as ProgramManager$1, CallbackQuery, ProgramImports, QueryOption, ExecutionRequest, stringToField, verifyFunctionExecution, Value, Proof, Signature } from '@provablehq/wasm/testnet.js';
3
- export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImports as ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, QueryOption, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, Value, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, snarkVerify, snarkVerifyBatch, stringToField, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
3
+ export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramImports as ProgramImportsBuilder, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, QueryOption, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, Value, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, setWasmLogLevel, snarkVerify, snarkVerifyBatch, stringToField, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
4
4
  import { cryptoBoxSeal } from '@serenity-kit/noble-sodium';
5
5
  import { base64, bech32m } from '@scure/base';
6
6
 
@@ -19,9 +19,16 @@ let currentLevel = "info";
19
19
  * - "warn" — errors + warnings
20
20
  * - "info" — errors + warnings + info (default)
21
21
  * - "debug" — everything including debug traces
22
+ *
23
+ * This controls both TS-side and WASM-side logging. WASM log calls
24
+ * (e.g., "Loading program", "Executing program") are silenced when
25
+ * the level is below "info".
22
26
  */
23
27
  function setLogLevel(level) {
24
28
  currentLevel = level;
29
+ import('./wasm-BCrMb35a.js')
30
+ .then(({ setWasmLogLevel }) => setWasmLogLevel(LEVEL_PRIORITY[level]))
31
+ .catch(() => { }); // WASM not loaded yet — will use default level (info)
25
32
  }
26
33
  /** Returns the current SDK log level. */
27
34
  function getLogLevel() {
@@ -210,6 +217,17 @@ class MemKeyVerifier {
210
217
  * It persists proving and verifying keys across page reloads and browser sessions using the
211
218
  * IndexedDB API available in all modern browsers and Web Workers.
212
219
  *
220
+ * **Environment**: Browser / Web Worker only. Instantiating this class is safe in any
221
+ * environment, but the first IndexedDB operation will reject with a clear error when
222
+ * `globalThis.indexedDB` is not available (e.g., Node.js, SSR contexts). Guard your
223
+ * imports accordingly if you bundle for server-side rendering.
224
+ *
225
+ * **Security**: Keys are stored as plaintext `Uint8Array` in IndexedDB. Any script
226
+ * running on the same origin — including scripts injected via XSS — can read the stored
227
+ * proving and verifying keys. Do **not** use this keystore for data that must remain
228
+ * confidential under an XSS-capable adversary; encrypt sensitive material at the
229
+ * application layer before persisting, or use an in-memory store.
230
+ *
213
231
  * @example
214
232
  * ```ts
215
233
  * import { IndexedDBKeyStore, ProgramManager } from "@provablehq/sdk";
@@ -239,6 +257,13 @@ class IndexedDBKeyStore {
239
257
  openDB() {
240
258
  if (this.dbPromise)
241
259
  return this.dbPromise;
260
+ // Env check sits outside the Promise constructor so a failure doesn't
261
+ // poison the cache; a later call (e.g. after a polyfill loads) can retry.
262
+ if (typeof indexedDB === "undefined") {
263
+ return Promise.reject(new Error("IndexedDBKeyStore requires a browser or Web Worker environment: " +
264
+ "`indexedDB` is not defined. If you are in Node.js or an SSR " +
265
+ "context, use LocalFileKeyStore or an in-memory key provider instead."));
266
+ }
242
267
  this.dbPromise = new Promise((resolve, reject) => {
243
268
  const request = indexedDB.open(this.dbName, 1);
244
269
  request.onupgradeneeded = () => {
@@ -1264,7 +1289,7 @@ class AleoNetworkClient {
1264
1289
  else {
1265
1290
  this.headers = {
1266
1291
  // This is replaced by the actual version by a Rollup plugin
1267
- "X-Aleo-SDK-Version": "0.10.6-rc.1",
1292
+ "X-Aleo-SDK-Version": "0.11.0",
1268
1293
  "X-Aleo-environment": environment(),
1269
1294
  };
1270
1295
  }
@@ -1280,7 +1305,7 @@ class AleoNetworkClient {
1280
1305
  else {
1281
1306
  this.headers = {
1282
1307
  // This is replaced by the actual version by a Rollup plugin
1283
- "X-Aleo-SDK-Version": "0.10.6-rc.1",
1308
+ "X-Aleo-SDK-Version": "0.11.0",
1284
1309
  "X-Aleo-environment": environment(),
1285
1310
  };
1286
1311
  }
@@ -2727,7 +2752,7 @@ class AleoNetworkClient {
2727
2752
  };
2728
2753
  }
2729
2754
  /**
2730
- * Parses a /prove or /prove/encrypted response. Returns a result object (never throws for 200/400/500/503).
2755
+ * Parses a /prove/authorization or /prove/request response. Returns a result object (never throws for 200/400/500/503).
2731
2756
  */
2732
2757
  async handleProvingResponse(response) {
2733
2758
  // Get the proving response text.
@@ -2788,14 +2813,12 @@ class AleoNetworkClient {
2788
2813
  async submitProvingRequestSafe(options) {
2789
2814
  // Attempt to get the Prover URI first from the options, then from any configured globally, or third try the main configured host.
2790
2815
  const proverUri = (options.url ?? this.proverUri) ?? this.host;
2791
- const provingRequestString = options.provingRequest instanceof ProvingRequest
2792
- ? options.provingRequest.toString()
2793
- : options.provingRequest;
2794
2816
  // Try to get JWT data to access the Provable API.
2795
2817
  const apiKey = options.apiKey ?? this.apiKey;
2796
2818
  const consumerId = options.consumerId ?? this.consumerId;
2797
2819
  let jwtData = options.jwtData ?? this.jwtData;
2798
- // Check to see if the JWT needs refreshing.
2820
+ // Check to see if the JWT needs refreshing. Runs before parsing the
2821
+ // proving request so JWT refresh errors propagate as they always have.
2799
2822
  const isExpired = jwtData && Date.now() >= jwtData.expiration - FIVE_MINUTES;
2800
2823
  if (!jwtData || isExpired) {
2801
2824
  if (apiKey && consumerId) {
@@ -2816,59 +2839,58 @@ class AleoNetworkClient {
2816
2839
  if (jwtData?.jwt) {
2817
2840
  headers["Authorization"] = jwtData.jwt;
2818
2841
  }
2819
- // Encapsulate the requests in a locally scoped function that can be run with a retry closure.
2820
- const runRequest = async () => {
2821
- // If DPS privacy is set, call invoke the encrypted flow.
2822
- if (options.dpsPrivacy) {
2823
- // Get an ephemeral public key from a DPS service.
2824
- const pubKeyResponse = await get(proverUri + "/pubkey", {
2825
- headers,
2826
- credentials: "include",
2827
- }, this.transport);
2828
- // Encrypt the provingRequest.
2829
- const pubkey = parseJSON(await pubKeyResponse.text());
2830
- const ciphertext = encryptProvingRequest(pubkey.public_key, ProvingRequest.fromString(provingRequestString));
2831
- // Form the expected query a DPS service expects (including the key_id).
2832
- const payload = {
2833
- key_id: pubkey.key_id,
2834
- ciphertext: ciphertext,
2835
- };
2836
- // We're in node, attempt to set the cookie manually.
2837
- const cookie = isNode() ? pubKeyResponse.headers.get("set-cookie") : undefined;
2838
- // Send the encrypted proving request to the DPS service.
2839
- const res = await this.transport(`${proverUri}/prove/encrypted`, {
2840
- method: "POST",
2841
- body: JSON.stringify(payload),
2842
- headers: {
2843
- ...headers,
2844
- ...(cookie ? { Cookie: cookie } : {})
2845
- },
2846
- credentials: "include",
2847
- });
2848
- // Properly handle the proving response.
2849
- return this.handleProvingResponse(res);
2850
- }
2851
- // If encrypted usage is not specified use the unencrypted endpoint.
2852
- const proveEndpoint = proverUri.endsWith("/prove")
2853
- ? proverUri
2854
- : proverUri + "/prove";
2855
- const res = await this.transport(proveEndpoint, {
2856
- method: "POST",
2857
- body: provingRequestString,
2842
+ // Send the proving request encrypted (libsodium-compatible sealed box).
2843
+ // Used by both `/prove/authorization` (Authorization variant) and
2844
+ // `/prove/request` (Request variant). The legacy plaintext `/prove`
2845
+ // route is no longer used.
2846
+ const sendEncrypted = async (endpoint, provingRequestObj) => {
2847
+ // Get an ephemeral public key from the DPS.
2848
+ const pubKeyResponse = await get(proverUri + "/pubkey", {
2858
2849
  headers,
2850
+ credentials: "include",
2851
+ }, this.transport);
2852
+ // Encrypt the provingRequest using the ephemeral pubkey.
2853
+ const pubkey = parseJSON(await pubKeyResponse.text());
2854
+ const ciphertext = encryptProvingRequest(pubkey.public_key, provingRequestObj);
2855
+ const payload = {
2856
+ key_id: pubkey.key_id,
2857
+ ciphertext: ciphertext,
2858
+ };
2859
+ // We're in node, attempt to set the cookie manually.
2860
+ const cookie = isNode() ? pubKeyResponse.headers.get("set-cookie") : undefined;
2861
+ const res = await this.transport(`${proverUri}${endpoint}`, {
2862
+ method: "POST",
2863
+ body: JSON.stringify(payload),
2864
+ headers: {
2865
+ ...headers,
2866
+ ...(cookie ? { Cookie: cookie } : {})
2867
+ },
2868
+ credentials: "include",
2859
2869
  });
2860
- // Properly handle the proving response.
2861
2870
  return this.handleProvingResponse(res);
2862
2871
  };
2872
+ // Parse the proving request once, up front, so the variant the SDK
2873
+ // routes on matches the bytes it will eventually send (a Request-
2874
+ // variant string must hit /prove/request, not /prove/authorization).
2875
+ // A malformed input string throws synchronously — the safe-API
2876
+ // contract only promises to return `{ ok: false, ... }` for HTTP
2877
+ // failures (400/500/503); a parse error is a caller-side bug and
2878
+ // surfacing it as a fake 500 would mislead callers debugging it.
2879
+ // `options.dpsPrivacy` is ignored; the legacy plaintext `/prove`
2880
+ // route is deprecated.
2881
+ const provingRequestObj = options.provingRequest instanceof ProvingRequest
2882
+ ? options.provingRequest
2883
+ : ProvingRequest.fromString(options.provingRequest);
2884
+ const endpoint = provingRequestObj.kind() === "request"
2885
+ ? "/prove/request"
2886
+ : "/prove/authorization";
2863
2887
  try {
2864
- // Run the request with retries.
2865
2888
  return await retryWithBackoff(async () => {
2866
- // Run the encrypted or non-encrypted flow as specified by the flags.
2867
- const result = await runRequest();
2889
+ const result = await sendEncrypted(endpoint, provingRequestObj);
2868
2890
  if (result.ok) {
2869
2891
  return result;
2870
2892
  }
2871
- // If 500s are hit responses are returned, attempt retries.
2893
+ // Retry on 500/503; surface 400 verbatim.
2872
2894
  if (result.status === 500 || result.status === 503) {
2873
2895
  const err = new Error(result.error.message);
2874
2896
  err.status = result.status;
@@ -2878,7 +2900,7 @@ class AleoNetworkClient {
2878
2900
  });
2879
2901
  }
2880
2902
  catch (err) {
2881
- // If an error is returned, provide usable information to the caller.
2903
+ // HTTP failure inside the retry loop convert to a result object.
2882
2904
  const e = err;
2883
2905
  return {
2884
2906
  ok: false,
@@ -4600,6 +4622,19 @@ class RecordScanner {
4600
4622
  const response = await this.request(new Request(`${this.url}/pubkey`, { method: "GET" }));
4601
4623
  return parseJSON(await response.text());
4602
4624
  }
4625
+ /**
4626
+ * Registers the account with the record scanning service using the encrypted flow.
4627
+ * Alias of {@link registerEncrypted} — preserved so existing callers using the
4628
+ * previous unencrypted `register(viewKey, startBlock)` API continue to work
4629
+ * unchanged while transparently using the encrypted endpoint.
4630
+ *
4631
+ * @param {ViewKey} viewKey The view key to register.
4632
+ * @param {number} startBlock The block height to start scanning from.
4633
+ * @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
4634
+ */
4635
+ async register(viewKey, startBlock) {
4636
+ return this.registerEncrypted(viewKey, startBlock);
4637
+ }
4603
4638
  /**
4604
4639
  * 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.
4605
4640
  *
@@ -5560,7 +5595,7 @@ class ProgramManager {
5560
5595
  resolvedImports = await this.networkClient.getProgramImports(programSource);
5561
5596
  }
5562
5597
  catch (e) {
5563
- console.warn(`Failed to resolve program imports from network: ${e}.`);
5598
+ logger.warn(`Failed to resolve program imports from network: ${e}.`);
5564
5599
  }
5565
5600
  }
5566
5601
  // Build a map of which functions each import actually calls,
@@ -5608,7 +5643,7 @@ class ProgramManager {
5608
5643
  }
5609
5644
  }
5610
5645
  catch (e) {
5611
- console.warn(`Failed to resolve transitive imports for ${name}: ${e}`);
5646
+ logger.warn(`Failed to resolve transitive imports for ${name}: ${e}`);
5612
5647
  }
5613
5648
  }
5614
5649
  // Phase 2: Add programs in topological order (leaves first).
@@ -5656,7 +5691,7 @@ class ProgramManager {
5656
5691
  }
5657
5692
  }
5658
5693
  catch (e) {
5659
- console.warn(`Failed to trace call graph for ${name}: ${e}`);
5694
+ logger.warn(`Failed to trace call graph for ${name}: ${e}`);
5660
5695
  }
5661
5696
  }
5662
5697
  }
@@ -5674,7 +5709,7 @@ class ProgramManager {
5674
5709
  builder.addProgram(name, source, importEdition);
5675
5710
  }
5676
5711
  catch (e) {
5677
- console.warn(`Failed to add import ${name} to builder: ${e}`);
5712
+ logger.warn(`Failed to add import ${name} to builder: ${e}`);
5678
5713
  continue;
5679
5714
  }
5680
5715
  if (loadKeys) {
@@ -5732,7 +5767,7 @@ class ProgramManager {
5732
5767
  return { edition: info.edition, amendment: info.amendment_count };
5733
5768
  }
5734
5769
  catch (e) {
5735
- console.warn(`Error finding edition/amendment for ${programName}. Network response: '${e.message}'. Defaulting to edition ${fallbackEdition ?? 1}, amendment 0.`);
5770
+ logger.warn(`Error finding edition/amendment for ${programName}. Network response: '${e.message}'. Defaulting to edition ${fallbackEdition ?? 1}, amendment 0.`);
5736
5771
  return { edition: fallbackEdition ?? 1, amendment: 0 };
5737
5772
  }
5738
5773
  }
@@ -5767,7 +5802,7 @@ class ProgramManager {
5767
5802
  builder.addVerifyingKey(programName, fnName, vk);
5768
5803
  }
5769
5804
  catch (e) {
5770
- console.debug(`Failed to load keys for ${programName}/${fnName}: ${e}`);
5805
+ logger.debug(`Failed to load keys for ${programName}/${fnName}: ${e}`);
5771
5806
  }
5772
5807
  }
5773
5808
  }
@@ -5799,7 +5834,7 @@ class ProgramManager {
5799
5834
  fns = Array.from(builder.functionKeysAvailable(programName));
5800
5835
  }
5801
5836
  catch (e) {
5802
- console.debug(`Failed to query keys for ${programName}: ${e}`);
5837
+ logger.debug(`Failed to query keys for ${programName}: ${e}`);
5803
5838
  continue;
5804
5839
  }
5805
5840
  for (const fnName of fns) {
@@ -5817,7 +5852,7 @@ class ProgramManager {
5817
5852
  }
5818
5853
  }
5819
5854
  catch (e) {
5820
- console.debug(`Failed to persist key for ${programName}/${fnName}: ${e}`);
5855
+ logger.debug(`Failed to persist key for ${programName}/${fnName}: ${e}`);
5821
5856
  }
5822
5857
  }
5823
5858
  }
@@ -6319,7 +6354,7 @@ class ProgramManager {
6319
6354
  [provingKey, verifyingKey] = keys;
6320
6355
  }
6321
6356
  else {
6322
- console.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
6357
+ logger.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
6323
6358
  }
6324
6359
  }
6325
6360
  // Get the fee record from the account if it is not provided in the parameters
@@ -6358,7 +6393,7 @@ class ProgramManager {
6358
6393
  await this.persistExtractedKeys(programImportsBuilder, importEditions);
6359
6394
  }
6360
6395
  catch (e) {
6361
- console.debug(`Failed to persist extracted keys: ${e}`);
6396
+ logger.debug(`Failed to persist extracted keys: ${e}`);
6362
6397
  }
6363
6398
  return result;
6364
6399
  }
@@ -6480,7 +6515,7 @@ class ProgramManager {
6480
6515
  [provingKey, verifyingKey] = keys;
6481
6516
  }
6482
6517
  else {
6483
- console.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
6518
+ logger.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
6484
6519
  }
6485
6520
  }
6486
6521
  const query = offlineQuery
@@ -6498,7 +6533,7 @@ class ProgramManager {
6498
6533
  await this.persistExtractedKeys(programImportsBuilder, importEditions);
6499
6534
  }
6500
6535
  catch (e) {
6501
- console.debug(`Failed to persist extracted keys: ${e}`);
6536
+ logger.debug(`Failed to persist extracted keys: ${e}`);
6502
6537
  }
6503
6538
  return result;
6504
6539
  }
@@ -6981,7 +7016,7 @@ class ProgramManager {
6981
7016
  [provingKey, verifyingKey] = keys;
6982
7017
  }
6983
7018
  else {
6984
- console.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
7019
+ logger.log("Function keys not found in KeyStore or KeyProvider. The function keys will be synthesized");
6985
7020
  }
6986
7021
  }
6987
7022
  // Auto-convert bare string inputs to field elements where the function expects field type.
@@ -7000,7 +7035,7 @@ class ProgramManager {
7000
7035
  await this.persistExtractedKeys(builder, importEditions);
7001
7036
  }
7002
7037
  catch (e) {
7003
- console.debug(`Failed to persist extracted keys: ${e}`);
7038
+ logger.debug(`Failed to persist extracted keys: ${e}`);
7004
7039
  }
7005
7040
  return result;
7006
7041
  }