@provablehq/sdk 0.9.13 → 0.9.15-enc

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 (35) hide show
  1. package/dist/mainnet/account.d.ts +15 -0
  2. package/dist/mainnet/browser.d.ts +5 -2
  3. package/dist/mainnet/browser.js +669 -160
  4. package/dist/mainnet/browser.js.map +1 -1
  5. package/dist/mainnet/constants.d.ts +1 -0
  6. package/dist/mainnet/integrations/sealance/merkle-tree.d.ts +63 -17
  7. package/dist/mainnet/models/cryptoBoxPubkey.d.ts +4 -0
  8. package/dist/mainnet/models/encryptedProvingRequest.d.ts +4 -0
  9. package/dist/mainnet/models/provingResponse.d.ts +48 -2
  10. package/dist/mainnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
  11. package/dist/mainnet/models/record-scanner/registrationResult.d.ts +26 -0
  12. package/dist/mainnet/network-client.d.ts +77 -4
  13. package/dist/mainnet/node-polyfill.js +2 -49
  14. package/dist/mainnet/node-polyfill.js.map +1 -1
  15. package/dist/mainnet/node.js +2 -2
  16. package/dist/mainnet/record-scanner.d.ts +53 -5
  17. package/dist/mainnet/security.d.ts +38 -0
  18. package/dist/testnet/account.d.ts +15 -0
  19. package/dist/testnet/browser.d.ts +5 -2
  20. package/dist/testnet/browser.js +669 -160
  21. package/dist/testnet/browser.js.map +1 -1
  22. package/dist/testnet/constants.d.ts +1 -0
  23. package/dist/testnet/integrations/sealance/merkle-tree.d.ts +63 -17
  24. package/dist/testnet/models/cryptoBoxPubkey.d.ts +4 -0
  25. package/dist/testnet/models/encryptedProvingRequest.d.ts +4 -0
  26. package/dist/testnet/models/provingResponse.d.ts +48 -2
  27. package/dist/testnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
  28. package/dist/testnet/models/record-scanner/registrationResult.d.ts +26 -0
  29. package/dist/testnet/network-client.d.ts +77 -4
  30. package/dist/testnet/node-polyfill.js +2 -49
  31. package/dist/testnet/node-polyfill.js.map +1 -1
  32. package/dist/testnet/node.js +2 -2
  33. package/dist/testnet/record-scanner.d.ts +53 -5
  34. package/dist/testnet/security.d.ts +38 -0
  35. package/package.json +4 -4
@@ -1,17 +1,29 @@
1
1
  import { EncryptedRecord } from "./models/record-provider/encryptedRecord";
2
+ import { CryptoBoxPubKey } from "./models/cryptoBoxPubkey.js";
2
3
  import { OwnedFilter } from "./models/record-scanner/ownedFilter";
3
4
  import { OwnedRecord } from "./models/record-provider/ownedRecord";
4
5
  import { RecordProvider } from "./record-provider";
5
6
  import { Field, ViewKey } from "./wasm";
6
7
  import { RecordsFilter } from "./models/record-scanner/recordsFilter";
7
- import { RegistrationResponse } from "./models/record-scanner/registrationResponse";
8
+ import { RegisterResult } from "./models/record-scanner/registrationResult.js";
8
9
  import { StatusResponse } from "./models/record-scanner/statusResponse";
10
+ /**
11
+ * JWT data for optional authentication with the record scanning service (e.g. Provable API).
12
+ */
13
+ export interface RecordScannerJWTData {
14
+ jwt: string;
15
+ expiration: number;
16
+ }
9
17
  type RecordScannerOptions = {
10
18
  url: string;
11
19
  apiKey?: string | {
12
20
  header: string;
13
21
  value: string;
14
22
  };
23
+ /** Required for JWT refresh when using authenticated record scanner (e.g. Provable API). */
24
+ consumerId?: string;
25
+ /** Optional JWT for auth. If omitted and apiKey + consumerId are set, JWT is refreshed when needed. */
26
+ jwtData?: RecordScannerJWTData;
15
27
  };
16
28
  /**
17
29
  * RecordScanner is a RecordProvider implementation that uses the record scanner service to find records.
@@ -22,7 +34,8 @@ type RecordScannerOptions = {
22
34
  * const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });
23
35
  * recordScanner.setAccount(account);
24
36
  * recordScanner.setApiKey("your-api-key");
25
- * const uuid = await recordScanner.register(0);
37
+ * const result = await recordScanner.register(viewKey, 0);
38
+ * if (result.ok) { const uuid = result.data.uuid; }
26
39
  *
27
40
  * const filter = {
28
41
  * uuid,
@@ -58,6 +71,8 @@ declare class RecordScanner implements RecordProvider {
58
71
  readonly url: string;
59
72
  private apiKey?;
60
73
  private uuid?;
74
+ private consumerId?;
75
+ private jwtData?;
61
76
  constructor(options: RecordScannerOptions);
62
77
  /**
63
78
  * Set the API key to use for the record scanner.
@@ -68,6 +83,22 @@ declare class RecordScanner implements RecordProvider {
68
83
  header: string;
69
84
  value: string;
70
85
  }): Promise<void>;
86
+ /**
87
+ * Set the consumer ID used for JWT refresh when using authenticated record scanner (e.g. Provable API).
88
+ */
89
+ setConsumerId(consumerId: string): Promise<void>;
90
+ /**
91
+ * Set JWT data for authentication. Optional; when not set, JWT can be refreshed from apiKey + consumerId if provided.
92
+ */
93
+ setJwtData(jwtData: RecordScannerJWTData | undefined): Promise<void>;
94
+ /**
95
+ * Refreshes the JWT by making a POST request to /jwts/{consumer_id}. Used when authentication is required.
96
+ */
97
+ private refreshJwt;
98
+ /**
99
+ * Returns auth headers (e.g. Authorization with JWT). Refreshes JWT if expired and apiKey + consumerId are set. Empty when auth is not configured.
100
+ */
101
+ private getAuthHeaders;
71
102
  /**
72
103
  * Set the UUID to use for the record scanner.
73
104
  *
@@ -75,12 +106,28 @@ declare class RecordScanner implements RecordProvider {
75
106
  */
76
107
  setUuid(uuidOrViewKey: Field | ViewKey): Promise<void>;
77
108
  /**
78
- * Register the account with the record scanner service.
109
+ * Register the account with the record scanner service (unencrypted POST /register). Does not throw if a valid error response from the record scanner is received; returns a result object instead.
110
+ *
111
+ * @param {ViewKey} viewKey The view key to register.
112
+ * @param {number} startBlock The block height to start scanning from.
113
+ * @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
114
+ */
115
+ register(viewKey: ViewKey, startBlock: number): Promise<RegisterResult>;
116
+ /**
117
+ * Fetches an ephemeral public key from the record scanner service for use with registerEncrypted.
118
+ * Follows the same pattern as the delegated proving service /pubkey endpoint.
119
+ *
120
+ * @returns {Promise<CryptoBoxPubKey>} The service's ephemeral public key and key_id.
121
+ */
122
+ getPubkey(): Promise<CryptoBoxPubKey>;
123
+ /**
124
+ * Registers the account with the record scanner 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.
79
125
  *
126
+ * @param {ViewKey} viewKey The view key to register.
80
127
  * @param {number} startBlock The block height to start scanning from.
81
- * @returns {Promise<RegistrationResponse>} The response from the record scanner service.
128
+ * @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
82
129
  */
83
- register(viewKey: ViewKey, startBlock: number): Promise<RegistrationResponse>;
130
+ registerEncrypted(viewKey: ViewKey, startBlock: number): Promise<RegisterResult>;
84
131
  /**
85
132
  * Get encrypted records from the record scanner service.
86
133
  *
@@ -141,6 +188,7 @@ declare class RecordScanner implements RecordProvider {
141
188
  findCreditsRecords(microcreditAmounts: number[], searchParameters: OwnedFilter): Promise<OwnedRecord[]>;
142
189
  /**
143
190
  * Wrapper function to make a request to the record scanner service and handle any errors.
191
+ * Optionally adds JWT Authorization header when consumerId/jwtData (or apiKey+consumerId) are configured.
144
192
  *
145
193
  * @param {Request} req The request to make.
146
194
  * @returns {Promise<Response>} The response.
@@ -0,0 +1,38 @@
1
+ import { ViewKey, Authorization, ProvingRequest } from "@provablehq/wasm";
2
+ /**
3
+ * Encrypt an authorization with a libsodium cryptobox public key.
4
+ *
5
+ * @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
6
+ * @param {Authorization} authorization the authorization to encrypt.
7
+ *
8
+ * @returns {string} the encrypted authorization in RFC 4648 standard Base64.
9
+ */
10
+ export declare function encryptAuthorization(publicKey: string, authorization: Authorization): string;
11
+ /**
12
+ * Encrypt a ProvingRequest with a libsodium cryptobox public key.
13
+ *
14
+ * @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
15
+ * @param {Authorization} provingRequest the ProvingRequest to encrypt.
16
+ *
17
+ * @returns {string} the encrypted ProvingRequest in RFC 4648 standard Base64.
18
+ */
19
+ export declare function encryptProvingRequest(publicKey: string, provingRequest: ProvingRequest): string;
20
+ /**
21
+ * Encrypt a view key with a libsodium cryptobox public key.
22
+ *
23
+ * @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
24
+ * @param {ViewKey} viewKey the view key to encrypt.
25
+ *
26
+ * @returns {string} the encrypted view key in RFC 4648 standard Base64.
27
+ */
28
+ export declare function encryptViewKey(publicKey: string, viewKey: ViewKey): string;
29
+ /**
30
+ * Encrypt a record scanner registration request.
31
+ *
32
+ * @param {string} publicKey The cryptobox X25519 public key to encrypt with (encoded in RFC 4648 standard Base64).
33
+ * @param {ViewKey} viewKey the view key to encrypt.
34
+ * @param {number} start the start height of the registration request.
35
+ *
36
+ * @returns {string} the encrypted view key in RFC 4648 standard Base64.
37
+ */
38
+ export declare function encryptRegistrationRequest(publicKey: string, viewKey: ViewKey, start: number): string;
@@ -52,6 +52,21 @@ export declare class Account {
52
52
  * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
53
53
  */
54
54
  static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string): Account;
55
+ /**
56
+ * Validates whether the given input is a valid Aleo address.
57
+ * @param {string | Uint8Array} address The address to validate, either as a string or bytes
58
+ * @returns {boolean} True if the address is valid, false otherwise
59
+ *
60
+ * @example
61
+ * import { Account } from "@provablehq/sdk/testnet.js";
62
+ *
63
+ * const isValid = Account.isValidAddress("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
64
+ * console.log(isValid); // true
65
+ *
66
+ * const isInvalid = Account.isValidAddress("invalid_address");
67
+ * console.log(isInvalid); // false
68
+ */
69
+ static isValidAddress(address: string | Uint8Array): boolean;
55
70
  /**
56
71
  * Creates a PrivateKey from the provided parameters.
57
72
  * @param {AccountParam} params The parameters containing either a private key string or a seed
@@ -3,8 +3,10 @@ import { Account } from "./account.js";
3
3
  import { AleoNetworkClient, ProgramImports } from "./network-client.js";
4
4
  import { BlockJSON, Header, Metadata } from "./models/blockJSON.js";
5
5
  import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
6
+ import { CryptoBoxPubKey } from "./models/cryptoBoxPubkey.js";
6
7
  import { DeploymentJSON, VerifyingKeys } from "./models/deployment/deploymentJSON.js";
7
8
  import { DeploymentObject } from "./models/deployment/deploymentObject.js";
9
+ import { EncryptedProvingRequest } from "./models/encryptedProvingRequest.js";
8
10
  import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
9
11
  import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSON.js";
10
12
  import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject.js";
@@ -24,7 +26,7 @@ import { PlaintextLiteral } from "./models/plaintext/literal.js";
24
26
  import { PlaintextObject } from "./models/plaintext/plaintext.js";
25
27
  import { PlaintextStruct } from "./models/plaintext/struct.js";
26
28
  import { ProvingRequestJSON } from "./models/provingRequest.js";
27
- import { ProvingResponse } from "./models/provingResponse.js";
29
+ import { ProvingResponse, BroadcastResponse, BroadcastResult, ProvingResult, ProvingFailure, ProvingSuccess, ProveApiErrorBody, ProvingRequestError, isProvingResponse, isProveApiErrorBody } from "./models/provingResponse.js";
28
30
  import { RatificationJSON } from "./models/ratification.js";
29
31
  import { RecordsFilter } from "./models/record-scanner/recordsFilter.js";
30
32
  import { RecordsResponseFilter } from "./models/record-scanner/recordsResponseFilter.js";
@@ -45,4 +47,5 @@ export { logAndThrow } from "./utils.js";
45
47
  export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, Transaction, Transition, U8, U16, U32, U64, U128, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, verifyFunctionExecution, } from "./wasm.js";
46
48
  export { initializeWasm };
47
49
  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";
48
- export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordSearchParams, SealanceMerkleTree, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
50
+ export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, BroadcastResponse, BroadcastResult, CachedKeyPair, ConfirmedTransactionJSON, CryptoBoxPubKey, DeploymentJSON, DeploymentObject, EncryptedProvingRequest, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, isProvingResponse, isProveApiErrorBody, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProveApiErrorBody, ProvingFailure, ProvingRequestError, ProvingRequestJSON, ProvingResult, ProvingSuccess, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordSearchParams, SealanceMerkleTree, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
51
+ export { encryptAuthorization, encryptProvingRequest, encryptViewKey, encryptRegistrationRequest } from "./security.js";