@provablehq/sdk 0.9.10-testnet-rc → 0.9.11
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/dynamic/browser.d.ts +8 -0
- package/dist/dynamic/browser.js +8 -0
- package/dist/dynamic/node.d.ts +8 -0
- package/dist/dynamic/node.js +8 -0
- package/dist/mainnet/browser.d.ts +2 -1
- package/dist/mainnet/browser.js +478 -17
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.ts +4 -0
- package/dist/mainnet/integrations/sealance/merkle-tree.d.ts +121 -0
- package/dist/mainnet/node.js +2 -1
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +206 -24
- package/dist/testnet/browser.d.ts +2 -1
- package/dist/testnet/browser.js +478 -17
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.ts +4 -0
- package/dist/testnet/integrations/sealance/merkle-tree.d.ts +121 -0
- package/dist/testnet/node.js +2 -1
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +206 -24
- package/package.json +7 -2
|
@@ -33,3 +33,7 @@ export declare const PUBLIC_TRANSFER: Set<string>;
|
|
|
33
33
|
export declare const PUBLIC_TRANSFER_AS_SIGNER: Set<string>;
|
|
34
34
|
export declare const PUBLIC_TO_PRIVATE_TRANSFER: Set<string>;
|
|
35
35
|
export declare const RECORD_DOMAIN = "RecordScannerV0";
|
|
36
|
+
/**
|
|
37
|
+
* Zero address on Aleo blockchain that corresponds to field element 0. Used as padding in Merkle trees and as a sentinel value.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Field } from "../../wasm.js";
|
|
2
|
+
/**
|
|
3
|
+
* Client library that encapsulates methods for constructing Merkle exclusion proofs for compliant stablecoin programs following the Sealance architecture.
|
|
4
|
+
*
|
|
5
|
+
|
|
6
|
+
* @example
|
|
7
|
+
* Construct a Merkle exclusion proof.
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const sealance = new SealanceMerkleTree();
|
|
10
|
+
* const leaves = [
|
|
11
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
12
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
13
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
14
|
+
* ];
|
|
15
|
+
* const result = sealance.generateLeaves(leaves);
|
|
16
|
+
* const tree = sealance.buildTree(result);
|
|
17
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1kypwp5m7qtk9mwazgcpg0tq8aal23mnrvwfvug65qgcg9xvsrqgspyjm6n");
|
|
18
|
+
* const proof_left = sealance.getSiblingPath(tree, leftIdx, 15);
|
|
19
|
+
* const proof_right = sealance.getSiblingPath(tree, rightIdx, 15);
|
|
20
|
+
* const exclusion_proof = [proof_left, proof_right];
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare class SealanceMerkleTree {
|
|
24
|
+
private static hasher;
|
|
25
|
+
/**
|
|
26
|
+
* Converts an Aleo blockchain address to a field element.
|
|
27
|
+
*
|
|
28
|
+
* This function decodes a bech32m-encoded Aleo address and converts it to a field element
|
|
29
|
+
* represented as a BigInt. The address format follows the Aleo protocol specification,
|
|
30
|
+
* starting with the prefix "aleo1" followed by encoded data.
|
|
31
|
+
*
|
|
32
|
+
* @param address - The Aleo blockchain address (e.g., "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
|
|
33
|
+
* @returns A BigInt representing the field element.
|
|
34
|
+
* @throws Error if the address is invalid or cannot be decoded.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const address = "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px";
|
|
39
|
+
* const fieldValue = convertAddressToField(address);
|
|
40
|
+
* console.log(fieldValue); // 123456789...n
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
convertAddressToField(address: string): bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Hashes two elements using Poseidon4 hash function
|
|
46
|
+
* @param prefix - Prefix for the hash (e.g., "0field" for nodes, "1field" for leaves)
|
|
47
|
+
* @param el1 - First element to hash
|
|
48
|
+
* @param el2 - Second element to hash
|
|
49
|
+
* @returns The hash result as a Field
|
|
50
|
+
* @throws {Error} If inputs are empty or invalid
|
|
51
|
+
*/
|
|
52
|
+
hashTwoElements(prefix: string, el1: string, el2: string): Field;
|
|
53
|
+
/**
|
|
54
|
+
* Builds a Merkle tree from given leaves. The tree is built bottom-up, hashing pairs of elements at each level.
|
|
55
|
+
*
|
|
56
|
+
* @param leaves - Array of leaf elements (must have even number of elements).
|
|
57
|
+
* @returns Array representing the complete Merkle tree as BigInts.
|
|
58
|
+
* @throws {Error} If leaves array is empty or has odd number of elements.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const leaves = ["0field", "1field", "2field", "3field"];
|
|
63
|
+
* const tree = buildTree(leaves);
|
|
64
|
+
* const root = tree[tree.length - 1]; // Get the Merkle root
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
buildTree(leaves: string[]): bigint[];
|
|
68
|
+
/**
|
|
69
|
+
* Converts Aleo addresses to field elements, sorts them, pads with zero fields, and returns an array. This prepares addresses for Merkle tree construction.
|
|
70
|
+
*
|
|
71
|
+
* @param addresses - Array of Aleo addresses.
|
|
72
|
+
* @param maxTreeDepth - Maximum depth of the Merkle tree (default: 15).
|
|
73
|
+
* @returns Array of field elements ready for Merkle tree construction.
|
|
74
|
+
* @throws {Error} If the number of addresses exceeds the maximum capacity.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const addresses = [
|
|
79
|
+
* "aleo1...",
|
|
80
|
+
* "aleo1..."
|
|
81
|
+
* ];
|
|
82
|
+
* const leaves = generateLeaves(addresses, 15);
|
|
83
|
+
* const tree = buildTree(leaves);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
generateLeaves(addresses: string[], maxTreeDepth?: number): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Finds the leaf indices for non-inclusion proof of an address and returns the indices of the two adjacent leaves that surround the target address.
|
|
89
|
+
*
|
|
90
|
+
* @param merkleTree - The complete Merkle tree as array of BigInts.
|
|
91
|
+
* @param address - The Aleo address for which to find indices.
|
|
92
|
+
* @returns Tuple of [leftLeafIndex, rightLeafIndex].
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const tree = buildTree(leaves);
|
|
97
|
+
* const [leftIdx, rightIdx] = getLeafIndices(tree, "aleo1...");
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
getLeafIndices(merkleTree: bigint[], address: string): [number, number];
|
|
101
|
+
/**
|
|
102
|
+
* Generates the sibling path (Merkle proof) for a given leaf index
|
|
103
|
+
*
|
|
104
|
+
* @param tree - The complete Merkle tree.
|
|
105
|
+
* @param leafIndex - Index of the leaf for which to generate the proof.
|
|
106
|
+
* @param depth - Maximum depth of the tree.
|
|
107
|
+
* @returns Object containing siblings array and leaf_index.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const tree = buildTree(leaves);
|
|
112
|
+
* const proof = getSiblingPath(tree, 0, 15);
|
|
113
|
+
* // proof = { siblings: [0n, 1n, ...], leaf_index: 0 }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
getSiblingPath(tree: bigint[], leafIndex: number, depth: number): {
|
|
117
|
+
siblings: bigint[];
|
|
118
|
+
leaf_index: number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export { SealanceMerkleTree };
|
package/dist/testnet/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './node-polyfill.js';
|
|
2
|
-
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KEY_STORE, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, RECORD_DOMAIN, RecordScanner, VALID_TRANSFER_TYPES, initializeWasm, logAndThrow } from './browser.js';
|
|
2
|
+
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, logAndThrow } from './browser.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/testnet.js';
|
|
4
4
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
5
5
|
import 'node:crypto';
|
|
@@ -9,4 +9,5 @@ import 'xmlhttprequest-ssl';
|
|
|
9
9
|
import 'sync-request';
|
|
10
10
|
import 'node:worker_threads';
|
|
11
11
|
import 'node:os';
|
|
12
|
+
import '@scure/base';
|
|
12
13
|
//# sourceMappingURL=node.js.map
|
package/dist/testnet/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -45,12 +45,13 @@ interface ExecuteOptions {
|
|
|
45
45
|
/**
|
|
46
46
|
* Options for building an Authorization for a function.
|
|
47
47
|
*
|
|
48
|
-
* @property
|
|
49
|
-
* @property
|
|
50
|
-
* @property
|
|
51
|
-
* @property
|
|
52
|
-
* @property
|
|
53
|
-
* @property
|
|
48
|
+
* @property {string} programName Name of the program containing the function to build the authorization for.
|
|
49
|
+
* @property {string} functionName Name of the function name to build the authorization for.
|
|
50
|
+
* @property {string[]} inputs The inputs to the function.
|
|
51
|
+
* @property {string | Program} [programSource] The optional source code for the program to build an execution for.
|
|
52
|
+
* @property {PrivateKey} [privateKey] Optional private key to use to build the authorization.
|
|
53
|
+
* @property {ProgramImports} [programImports] The other programs the program imports.
|
|
54
|
+
* @property {edition} [edition]
|
|
54
55
|
*/
|
|
55
56
|
interface AuthorizationOptions {
|
|
56
57
|
programName: string;
|
|
@@ -64,11 +65,11 @@ interface AuthorizationOptions {
|
|
|
64
65
|
/**
|
|
65
66
|
* Options for executing a fee authorization.
|
|
66
67
|
*
|
|
67
|
-
* @property
|
|
68
|
-
* @property
|
|
69
|
-
* @property
|
|
70
|
-
* @property
|
|
71
|
-
* @property
|
|
68
|
+
* @property {string} deploymentOrExecutionId The id of a previously built Execution or Authorization.
|
|
69
|
+
* @property {number} baseFeeCredits The number of Aleo Credits to pay for the base fee.
|
|
70
|
+
* @property {number} [priorityFeeCredits] The number of Aleo Credits to pay for the priority fee.
|
|
71
|
+
* @property {PrivateKey} [privateKey] Optional private key to specify for the authorization.
|
|
72
|
+
* @property {RecordPlaintext} [feeRecord] A record to specify to pay the private fee. If this is specified a `fee_private` authorization will be built.
|
|
72
73
|
*/
|
|
73
74
|
interface FeeAuthorizationOptions {
|
|
74
75
|
deploymentOrExecutionId: string;
|
|
@@ -77,6 +78,28 @@ interface FeeAuthorizationOptions {
|
|
|
77
78
|
privateKey?: PrivateKey;
|
|
78
79
|
feeRecord?: RecordPlaintext;
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Represents the options for executing a transaction on the Aleo Network from an authorization.
|
|
83
|
+
*
|
|
84
|
+
* @property {string} programName - The name of the program containing the function to be executed.
|
|
85
|
+
* @property {KeySearchParams} [keySearchParams] - Optional parameters for finding the matching proving & verifying keys for the function.
|
|
86
|
+
* @property {ProvingKey} [provingKey] - Optional proving key to use for the transaction.
|
|
87
|
+
* @property {VerifyingKey} [verifyingKey] - Optional verifying key to use for the transaction.
|
|
88
|
+
* @property {OfflineQuery} [offlineQuery] - Optional offline query if creating transactions in an offline environment.
|
|
89
|
+
* @property {string | Program} [program] - Optional program source code to use for the transaction.
|
|
90
|
+
* @property {ProgramImports} [imports] - Optional programs that the program being executed imports.
|
|
91
|
+
*/
|
|
92
|
+
interface ExecuteAuthorizationOptions {
|
|
93
|
+
programName: string;
|
|
94
|
+
authorization: Authorization;
|
|
95
|
+
feeAuthorization?: Authorization;
|
|
96
|
+
keySearchParams?: KeySearchParams;
|
|
97
|
+
provingKey?: ProvingKey;
|
|
98
|
+
verifyingKey?: VerifyingKey;
|
|
99
|
+
offlineQuery?: OfflineQuery;
|
|
100
|
+
program?: string | Program;
|
|
101
|
+
imports?: ProgramImports;
|
|
102
|
+
}
|
|
80
103
|
/**
|
|
81
104
|
* Represents the options for executing a transaction in the Aleo network.
|
|
82
105
|
* This interface is used to specify the parameters required for building and submitting an execution transaction.
|
|
@@ -98,10 +121,10 @@ interface FeeAuthorizationOptions {
|
|
|
98
121
|
interface ProvingRequestOptions {
|
|
99
122
|
programName: string;
|
|
100
123
|
functionName: string;
|
|
101
|
-
baseFee: number;
|
|
102
124
|
priorityFee: number;
|
|
103
125
|
privateFee: boolean;
|
|
104
126
|
inputs: string[];
|
|
127
|
+
baseFee?: number;
|
|
105
128
|
recordSearchParams?: RecordSearchParams;
|
|
106
129
|
feeRecord?: string | RecordPlaintext;
|
|
107
130
|
privateKey?: PrivateKey;
|
|
@@ -111,6 +134,24 @@ interface ProvingRequestOptions {
|
|
|
111
134
|
unchecked?: boolean;
|
|
112
135
|
edition?: number;
|
|
113
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Fee estimate options.
|
|
139
|
+
*
|
|
140
|
+
* @property {string} programName - The name of the program containing the function to estimate the fee for.
|
|
141
|
+
* @property {string} functionName - The name of the function to execute within the program to estimate the fee for.
|
|
142
|
+
* @property {string} [program] - Program source code to use for the fee estimate.
|
|
143
|
+
* @property {ProgramImports} [imports] - Programs that the program imports.
|
|
144
|
+
* @property {number} [edition] - Edition of the program to estimate the fee for.
|
|
145
|
+
* @property {Authorization} authorization - An authorization to estimate the fee for.
|
|
146
|
+
*/
|
|
147
|
+
interface FeeEstimateOptions {
|
|
148
|
+
programName: string;
|
|
149
|
+
functionName?: string;
|
|
150
|
+
program?: string | Program;
|
|
151
|
+
imports?: ProgramImports;
|
|
152
|
+
edition?: number;
|
|
153
|
+
authorization?: Authorization;
|
|
154
|
+
}
|
|
114
155
|
/**
|
|
115
156
|
* The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
|
|
116
157
|
*/
|
|
@@ -301,6 +342,77 @@ declare class ProgramManager {
|
|
|
301
342
|
* }, 10000);
|
|
302
343
|
*/
|
|
303
344
|
buildExecutionTransaction(options: ExecuteOptions): Promise<Transaction>;
|
|
345
|
+
/**
|
|
346
|
+
* Builds an execution transaction for submission to the Aleo network from an Authorization and Fee Authorization.
|
|
347
|
+
* This method is helpful if signing and authorization needs to be done in a secure environment separate from where
|
|
348
|
+
* transactions are built.
|
|
349
|
+
*
|
|
350
|
+
* @param {ExecuteAuthorizationOptions} options - The options for executing the authorizations.
|
|
351
|
+
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
355
|
+
*
|
|
356
|
+
* await initThreadPool();
|
|
357
|
+
*
|
|
358
|
+
* // Create a new KeyProvider.
|
|
359
|
+
* const keyProvider = new AleoKeyProvider();
|
|
360
|
+
* keyProvider.useCache(true);
|
|
361
|
+
*
|
|
362
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
363
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
364
|
+
*
|
|
365
|
+
* // Build the `Authorization`.
|
|
366
|
+
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
367
|
+
* const authorization = await programManager.buildAuthorization({
|
|
368
|
+
* programName: "credits.aleo",
|
|
369
|
+
* functionName: "transfer_public",
|
|
370
|
+
* privateKey,
|
|
371
|
+
* inputs: [
|
|
372
|
+
* "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
|
|
373
|
+
* "10000000u64",
|
|
374
|
+
* ],
|
|
375
|
+
* });
|
|
376
|
+
*
|
|
377
|
+
* console.log("Getting execution id");
|
|
378
|
+
*
|
|
379
|
+
* // Derive the execution ID and base fee.
|
|
380
|
+
* const executionId = authorization.toExecutionId().toString();
|
|
381
|
+
*
|
|
382
|
+
* console.log("Estimating fee");
|
|
383
|
+
*
|
|
384
|
+
* // Get the base fee in microcredits.
|
|
385
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization(authorization, "credits.aleo");
|
|
386
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
387
|
+
*
|
|
388
|
+
* console.log("Building fee authorization");
|
|
389
|
+
*
|
|
390
|
+
* // Build a credits.aleo/fee_public `Authorization`.
|
|
391
|
+
* const feeAuthorization = await programManager.buildFeeAuthorization({
|
|
392
|
+
* deploymentOrExecutionId: executionId,
|
|
393
|
+
* baseFeeCredits,
|
|
394
|
+
* privateKey
|
|
395
|
+
* });
|
|
396
|
+
*
|
|
397
|
+
* console.log("Executing authorizations");
|
|
398
|
+
*
|
|
399
|
+
* // Build and execute the transaction.
|
|
400
|
+
* const tx = await programManager.buildTransactionFromAuthorization({
|
|
401
|
+
* programName: "credits.aleo",
|
|
402
|
+
* authorization,
|
|
403
|
+
* feeAuthorization,
|
|
404
|
+
* });
|
|
405
|
+
*
|
|
406
|
+
* // Submit the transaction to the network.
|
|
407
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
408
|
+
*
|
|
409
|
+
* // Verify the transaction was successful.
|
|
410
|
+
* setTimeout(async () => {
|
|
411
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
412
|
+
* console.log(transaction);
|
|
413
|
+
* }, 10000);
|
|
414
|
+
*/
|
|
415
|
+
buildTransactionFromAuthorization(options: ExecuteAuthorizationOptions): Promise<Transaction>;
|
|
304
416
|
/**
|
|
305
417
|
* Builds a SnarkVM `Authorization` for a specific function.
|
|
306
418
|
*
|
|
@@ -381,7 +493,6 @@ declare class ProgramManager {
|
|
|
381
493
|
* const provingRequest = await programManager.provingRequest({
|
|
382
494
|
* programName: "credits.aleo",
|
|
383
495
|
* functionName: "transfer_public",
|
|
384
|
-
* baseFee: 100000,
|
|
385
496
|
* priorityFee: 0,
|
|
386
497
|
* privateFee: false,
|
|
387
498
|
* inputs: [
|
|
@@ -411,14 +522,14 @@ declare class ProgramManager {
|
|
|
411
522
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
412
523
|
*
|
|
413
524
|
* // Build a credits.aleo/fee_public `Authorization`.
|
|
414
|
-
* const feePublicAuthorization = await programManager.
|
|
525
|
+
* const feePublicAuthorization = await programManager.buildFeeAuthorization({
|
|
415
526
|
* deploymentOrExecutionId: "2423957656946557501636078245035919227529640894159332581642187482178647335171field",
|
|
416
527
|
* baseFeeCredits: 0.1,
|
|
417
528
|
* });
|
|
418
529
|
*
|
|
419
530
|
* // Build a credits.aleo/fee_private `Authorization`.
|
|
420
531
|
* const record = "{ owner: aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3.private, microcredits: 1500000000000000u64.private, _nonce: 3077450429259593211617823051143573281856129402760267155982965992208217472983group.public }";
|
|
421
|
-
* const feePrivateAuthorization = await programManager.
|
|
532
|
+
* const feePrivateAuthorization = await programManager.buildFeeAuthorization({
|
|
422
533
|
* deploymentOrExecutionId: "2423957656946557501636078245035919227529640894159332581642187482178647335171field",
|
|
423
534
|
* baseFeeCredits: 0.1,
|
|
424
535
|
* feeRecord: record,
|
|
@@ -1069,15 +1180,6 @@ declare class ProgramManager {
|
|
|
1069
1180
|
* assert(isValid);
|
|
1070
1181
|
*/
|
|
1071
1182
|
verifyExecution(executionResponse: ExecutionResponse, blockHeight: number, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean;
|
|
1072
|
-
/**
|
|
1073
|
-
* Set the inclusion key bytes.
|
|
1074
|
-
*
|
|
1075
|
-
* @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
|
|
1076
|
-
* @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
|
|
1077
|
-
* @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
|
|
1078
|
-
* @returns {boolean} True if the proof is valid, false otherwise
|
|
1079
|
-
*
|
|
1080
|
-
|
|
1081
1183
|
/**
|
|
1082
1184
|
* Create a program object from a program's source code
|
|
1083
1185
|
*
|
|
@@ -1097,6 +1199,86 @@ declare class ProgramManager {
|
|
|
1097
1199
|
* @param {string} program The program source code
|
|
1098
1200
|
*/
|
|
1099
1201
|
verifyProgram(program: string): boolean;
|
|
1202
|
+
/**
|
|
1203
|
+
* Estimate the execution fee for an authorization.
|
|
1204
|
+
*
|
|
1205
|
+
* @param {FeeEstimateOptions} options Options for fee estimate.
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
1209
|
+
*
|
|
1210
|
+
* await initThreadPool();
|
|
1211
|
+
*
|
|
1212
|
+
* // Create a new KeyProvider.
|
|
1213
|
+
* const keyProvider = new AleoKeyProvider();
|
|
1214
|
+
* keyProvider.useCache(true);
|
|
1215
|
+
*
|
|
1216
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
1217
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
1218
|
+
*
|
|
1219
|
+
* // Build the `Authorization`.
|
|
1220
|
+
* const privateKey = new PrivateKey(); // Change this to a private key that has an aleo credit balance.
|
|
1221
|
+
* const authorization = await programManager.buildAuthorization({
|
|
1222
|
+
* programName: "credits.aleo",
|
|
1223
|
+
* functionName: "transfer_public",
|
|
1224
|
+
* privateKey,
|
|
1225
|
+
* inputs: [
|
|
1226
|
+
* "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
|
|
1227
|
+
* "10000000u64",
|
|
1228
|
+
* ],
|
|
1229
|
+
* });
|
|
1230
|
+
*
|
|
1231
|
+
* console.log("Getting execution id");
|
|
1232
|
+
*
|
|
1233
|
+
* // Derive the execution ID and base fee.
|
|
1234
|
+
* const executionId = authorization.toExecutionId().toString();
|
|
1235
|
+
*
|
|
1236
|
+
* console.log("Estimating fee");
|
|
1237
|
+
*
|
|
1238
|
+
* // Get the base fee in microcredits.
|
|
1239
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
|
|
1240
|
+
* authorization,
|
|
1241
|
+
* programName: "credits.aleo"
|
|
1242
|
+
* });
|
|
1243
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
1244
|
+
*
|
|
1245
|
+
* console.log("Building fee authorization");
|
|
1246
|
+
*
|
|
1247
|
+
* // Build a credits.aleo/fee_public `Authorization`.
|
|
1248
|
+
* const feeAuthorization = await programManager.buildFeeAuthorization({
|
|
1249
|
+
* deploymentOrExecutionId: executionId,
|
|
1250
|
+
* baseFeeCredits,
|
|
1251
|
+
* privateKey
|
|
1252
|
+
* });
|
|
1253
|
+
*/
|
|
1254
|
+
estimateFeeForAuthorization(options: FeeEstimateOptions): Promise<bigint>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Estimate the execution fee for an Aleo function.
|
|
1257
|
+
*
|
|
1258
|
+
* @param {FeeEstimateOptions} options Options for the fee estimate.
|
|
1259
|
+
*
|
|
1260
|
+
* @returns {Promise<bigint>} Execution fee in microcredits for the authorization.
|
|
1261
|
+
*
|
|
1262
|
+
* @example
|
|
1263
|
+
* import { AleoKeyProvider, PrivateKey, initThreadPool, ProgramManager } from "@provablehq/sdk";
|
|
1264
|
+
*
|
|
1265
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions.
|
|
1266
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider);
|
|
1267
|
+
*
|
|
1268
|
+
* // Get the base fee in microcredits.
|
|
1269
|
+
* const baseFeeMicrocredits = await programManager.estimateExecutionFee({programName: "credits.aleo"});
|
|
1270
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
1271
|
+
*
|
|
1272
|
+
* console.log("Building fee authorization");
|
|
1273
|
+
*
|
|
1274
|
+
* // Build a credits.aleo/fee_public `Authorization`.
|
|
1275
|
+
* const baseFeeMicrocredits = await programManager.estimateFeeForAuthorization({
|
|
1276
|
+
* programName: "credits.aleo",
|
|
1277
|
+
* functionName: "transfer_public",
|
|
1278
|
+
* });
|
|
1279
|
+
* const baseFeeCredits = Number(baseFeeMicrocredits)/1000000;
|
|
1280
|
+
*/
|
|
1281
|
+
estimateExecutionFee(options: FeeEstimateOptions): Promise<bigint>;
|
|
1100
1282
|
getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<OwnedRecord>;
|
|
1101
1283
|
}
|
|
1102
1284
|
export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@provablehq/sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
|
|
5
5
|
"collaborators": [
|
|
6
6
|
"The Provable Team"
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"./mainnet.js": {
|
|
22
22
|
"node": "./dist/mainnet/node.js",
|
|
23
23
|
"default": "./dist/mainnet/browser.js"
|
|
24
|
+
},
|
|
25
|
+
"./dynamic.js": {
|
|
26
|
+
"node": "./dist/dynamic/node.js",
|
|
27
|
+
"default": "./dist/dynamic/browser.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
@@ -47,7 +51,8 @@
|
|
|
47
51
|
},
|
|
48
52
|
"homepage": "https://github.com/ProvableHQ/sdk#readme",
|
|
49
53
|
"dependencies": {
|
|
50
|
-
"@provablehq/wasm": "^0.9.
|
|
54
|
+
"@provablehq/wasm": "^0.9.11",
|
|
55
|
+
"@scure/base": "^2.0.0",
|
|
51
56
|
"comlink": "^4.4.2",
|
|
52
57
|
"core-js": "^3.40.0",
|
|
53
58
|
"mime": "^4.0.6",
|