@provablehq/sdk 0.6.9

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.
@@ -0,0 +1,639 @@
1
+ import { Account, AleoNetworkClient, ExecutionResponse, FunctionKeyProvider, FunctionKeyPair, OfflineQuery, KeySearchParams, RecordPlaintext, RecordProvider, RecordSearchParams, PrivateKey, Program, ProgramImports, ProvingKey, VerifyingKey, Transaction } from "./index";
2
+ /**
3
+ * Represents the options for executing a transaction in the Aleo network.
4
+ * This interface is used to specify the parameters required for building and submitting an execution transaction.
5
+ *
6
+ * @property {string} programName - The name of the program containing the function to be executed.
7
+ * @property {string} functionName - The name of the function to execute within the program.
8
+ * @property {number} fee - The fee to be paid for the transaction.
9
+ * @property {boolean} privateFee - If true, uses a private record to pay the fee; otherwise, uses the account's public credit balance.
10
+ * @property {string[]} inputs - The inputs to the function being executed.
11
+ * @property {RecordSearchParams} [recordSearchParams] - Optional parameters for searching for a record to pay the execution transaction fee.
12
+ * @property {KeySearchParams} [keySearchParams] - Optional parameters for finding the matching proving & verifying keys for the function.
13
+ * @property {string | RecordPlaintext} [feeRecord] - Optional fee record to use for the transaction.
14
+ * @property {ProvingKey} [provingKey] - Optional proving key to use for the transaction.
15
+ * @property {VerifyingKey} [verifyingKey] - Optional verifying key to use for the transaction.
16
+ * @property {PrivateKey} [privateKey] - Optional private key to use for the transaction.
17
+ * @property {OfflineQuery} [offlineQuery] - Optional offline query if creating transactions in an offline environment.
18
+ * @property {string | Program} [program] - Optional program source code to use for the transaction.
19
+ * @property {ProgramImports} [imports] - Optional programs that the program being executed imports.
20
+ */
21
+ interface ExecuteOptions {
22
+ programName: string;
23
+ functionName: string;
24
+ fee: number;
25
+ privateFee: boolean;
26
+ inputs: string[];
27
+ recordSearchParams?: RecordSearchParams;
28
+ keySearchParams?: KeySearchParams;
29
+ feeRecord?: string | RecordPlaintext;
30
+ provingKey?: ProvingKey;
31
+ verifyingKey?: VerifyingKey;
32
+ privateKey?: PrivateKey;
33
+ offlineQuery?: OfflineQuery;
34
+ program?: string | Program;
35
+ imports?: ProgramImports;
36
+ }
37
+ /**
38
+ * The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
39
+ */
40
+ declare class ProgramManager {
41
+ account: Account | undefined;
42
+ keyProvider: FunctionKeyProvider;
43
+ host: string;
44
+ networkClient: AleoNetworkClient;
45
+ recordProvider: RecordProvider | undefined;
46
+ /** Create a new instance of the ProgramManager
47
+ *
48
+ * @param { string | undefined } host A host uri running the official Aleo API
49
+ * @param { FunctionKeyProvider | undefined } keyProvider A key provider that implements {@link FunctionKeyProvider} interface
50
+ * @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
51
+ */
52
+ constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined);
53
+ /**
54
+ * Set the account to use for transaction submission to the Aleo network
55
+ *
56
+ * @param {Account} account Account to use for transaction submission
57
+ */
58
+ setAccount(account: Account): void;
59
+ /**
60
+ * Set the key provider that provides the proving and verifying keys for programs
61
+ *
62
+ * @param {FunctionKeyProvider} keyProvider
63
+ */
64
+ setKeyProvider(keyProvider: FunctionKeyProvider): void;
65
+ /**
66
+ * Set the host peer to use for transaction submission to the Aleo network
67
+ *
68
+ * @param host {string} Peer url to use for transaction submission
69
+ */
70
+ setHost(host: string): void;
71
+ /**
72
+ * Set the record provider that provides records for transactions
73
+ *
74
+ * @param {RecordProvider} recordProvider
75
+ */
76
+ setRecordProvider(recordProvider: RecordProvider): void;
77
+ /**
78
+ * Deploy an Aleo program to the Aleo network
79
+ *
80
+ * @param {string} program Program source code
81
+ * @param {number} fee Fee to pay for the transaction
82
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
83
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to use
84
+ * pay the deployment fee
85
+ * @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
86
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
87
+ * @returns {string | Error} The transaction id of the deployed program or a failure message from the network
88
+ *
89
+ * @example
90
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
91
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
92
+ * const keyProvider = new AleoKeyProvider();
93
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
94
+ *
95
+ * // Initialize a program manager with the key provider to automatically fetch keys for deployments
96
+ * const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
97
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
98
+ *
99
+ * // Define a fee in credits
100
+ * const fee = 1.2;
101
+ *
102
+ * // Deploy the program
103
+ * const tx_id = await programManager.deploy(program, fee);
104
+ *
105
+ * // Verify the transaction was successful
106
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
107
+ */
108
+ deploy(program: string, fee: number, privateFee: boolean, recordSearchParams?: RecordSearchParams, feeRecord?: string | RecordPlaintext, privateKey?: PrivateKey): Promise<string | Error>;
109
+ /**
110
+ * Builds an execution transaction for submission to the Aleo network.
111
+ *
112
+ * @param {ExecuteOptions} options - The options for the execution transaction.
113
+ * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error.
114
+ *
115
+ * @example
116
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
117
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
118
+ * const keyProvider = new AleoKeyProvider();
119
+ * keyProvider.useCache = true;
120
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
121
+ *
122
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
123
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
124
+ *
125
+ * // Build and execute the transaction
126
+ * const transaction = await programManager.buildExecutionTransaction({
127
+ * programName: "hello_hello.aleo",
128
+ * functionName: "hello_hello",
129
+ * fee: 0.020,
130
+ * privateFee: false,
131
+ * inputs: ["5u32", "5u32"],
132
+ * keySearchParams: { "cacheKey": "hello_hello:hello" }
133
+ * });
134
+ * const result = await programManager.networkClient.submitTransaction(transaction);
135
+ */
136
+ buildExecutionTransaction(options: ExecuteOptions): Promise<Transaction | Error>;
137
+ /**
138
+ * Builds an execution transaction for submission to the Aleo network.
139
+ *
140
+ * @param {ExecuteOptions} options - The options for the execution transaction.
141
+ * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error.
142
+ *
143
+ * @example
144
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
145
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
146
+ * const keyProvider = new AleoKeyProvider();
147
+ * keyProvider.useCache = true;
148
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
149
+ *
150
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
151
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
152
+ *
153
+ * // Build and execute the transaction
154
+ * const transaction = await programManager.execute({
155
+ * programName: "hello_hello.aleo",
156
+ * functionName: "hello_hello",
157
+ * fee: 0.020,
158
+ * privateFee: false,
159
+ * inputs: ["5u32", "5u32"],
160
+ * keySearchParams: { "cacheKey": "hello_hello:hello" }
161
+ * });
162
+ * const result = await programManager.networkClient.submitTransaction(transaction);
163
+ */
164
+ execute(options: ExecuteOptions): Promise<string | Error>;
165
+ /**
166
+ * Run an Aleo program in offline mode
167
+ *
168
+ * @param {string} program Program source code containing the function to be executed
169
+ * @param {string} function_name Function name to execute
170
+ * @param {string[]} inputs Inputs to the function
171
+ * @param {number} proveExecution Whether to prove the execution of the function and return an execution transcript
172
+ * that contains the proof.
173
+ * @param {string[] | undefined} imports Optional imports to the program
174
+ * @param {KeySearchParams | undefined} keySearchParams Optional parameters for finding the matching proving &
175
+ * verifying keys for the function
176
+ * @param {ProvingKey | undefined} provingKey Optional proving key to use for the transaction
177
+ * @param {VerifyingKey | undefined} verifyingKey Optional verifying key to use for the transaction
178
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
179
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
180
+ * @returns {Promise<string | Error>}
181
+ *
182
+ * @example
183
+ * import { Account, Program } from '@provablehq/sdk';
184
+ *
185
+ * /// Create the source for the "helloworld" program
186
+ * const program = "program helloworld.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
187
+ * const programManager = new ProgramManager();
188
+ *
189
+ * /// Create a temporary account for the execution of the program
190
+ * const account = new Account();
191
+ * programManager.setAccount(account);
192
+ *
193
+ * /// Get the response and ensure that the program executed correctly
194
+ * const executionResponse = await programManager.executeOffline(program, "hello", ["5u32", "5u32"]);
195
+ * const result = executionResponse.getOutputs();
196
+ * assert(result === ["10u32"]);
197
+ */
198
+ run(program: string, function_name: string, inputs: string[], proveExecution: boolean, imports?: ProgramImports, keySearchParams?: KeySearchParams, provingKey?: ProvingKey, verifyingKey?: VerifyingKey, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<ExecutionResponse>;
199
+ /**
200
+ * Join two credits records into a single credits record
201
+ *
202
+ * @param {RecordPlaintext | string} recordOne First credits record to join
203
+ * @param {RecordPlaintext | string} recordTwo Second credits record to join
204
+ * @param {number} fee Fee in credits pay for the join transaction
205
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
206
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the fee record to use
207
+ * to pay the fee for the join transaction
208
+ * @param {RecordPlaintext | string | undefined} feeRecord Fee record to use for the join transaction
209
+ * @param {PrivateKey | undefined} privateKey Private key to use for the join transaction
210
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
211
+ * @returns {Promise<string | Error>}
212
+ */
213
+ join(recordOne: RecordPlaintext | string, recordTwo: RecordPlaintext | string, fee: number, privateFee: boolean, recordSearchParams?: RecordSearchParams | undefined, feeRecord?: RecordPlaintext | string | undefined, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<string | Error>;
214
+ /**
215
+ * Split credits into two new credits records
216
+ *
217
+ * @param {number} splitAmount Amount in microcredits to split from the original credits record
218
+ * @param {RecordPlaintext | string} amountRecord Amount record to use for the split transaction
219
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the split transaction
220
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
221
+ * @returns {Promise<string | Error>}
222
+ *
223
+ * @example
224
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
225
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
226
+ * const keyProvider = new AleoKeyProvider();
227
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
228
+ *
229
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
230
+ * const programName = "hello_hello.aleo";
231
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
232
+ * const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
233
+ * const tx_id = await programManager.split(25000000, record);
234
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
235
+ */
236
+ split(splitAmount: number, amountRecord: RecordPlaintext | string, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<string | Error>;
237
+ /**
238
+ * Pre-synthesize proving and verifying keys for a program
239
+ *
240
+ * @param program {string} The program source code to synthesize keys for
241
+ * @param function_id {string} The function id to synthesize keys for
242
+ * @param inputs {Array<string>} Sample inputs to the function
243
+ * @param privateKey {PrivateKey | undefined} Optional private key to use for the key synthesis
244
+ *
245
+ * @returns {Promise<FunctionKeyPair | Error>}
246
+ */
247
+ synthesizeKeys(program: string, function_id: string, inputs: Array<string>, privateKey?: PrivateKey): Promise<FunctionKeyPair | Error>;
248
+ /**
249
+ * Build a transaction to transfer credits to another account for later submission to the Aleo network
250
+ *
251
+ * @param {number} amount The amount of credits to transfer
252
+ * @param {string} recipient The recipient of the transfer
253
+ * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
254
+ * @param {number} fee The fee to pay for the transfer
255
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
256
+ * @param {string | undefined} caller The caller of the function (if calling transfer_public)
257
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
258
+ * records for the transfer transaction
259
+ * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
260
+ * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
261
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
262
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
263
+ * @returns {Promise<string | Error>} The transaction id of the transfer transaction
264
+ *
265
+ * @example
266
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
267
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
268
+ * const keyProvider = new AleoKeyProvider();
269
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
270
+ *
271
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
272
+ * const programName = "hello_hello.aleo";
273
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
274
+ * await programManager.initialize();
275
+ * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
276
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
277
+ */
278
+ buildTransferTransaction(amount: number, recipient: string, transferType: string, fee: number, privateFee: boolean, caller?: string, recordSearchParams?: RecordSearchParams, amountRecord?: RecordPlaintext | string, feeRecord?: RecordPlaintext | string, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<Transaction | Error>;
279
+ /**
280
+ * Build a transfer_public transaction to transfer credits to another account for later submission to the Aleo network
281
+ *
282
+ * @param {number} amount The amount of credits to transfer
283
+ * @param {string} caller The caller of the transfer (may be different from the signer)
284
+ * @param {string} recipient The recipient of the transfer
285
+ * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
286
+ * @param {number} fee The fee to pay for the transfer
287
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
288
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
289
+ * records for the transfer transaction
290
+ * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
291
+ * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
292
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
293
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
294
+ * @returns {Promise<string | Error>} The transaction id of the transfer transaction
295
+ */
296
+ buildTransferPublicTransaction(amount: number, caller: string, recipient: string, fee: number, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<Transaction | Error>;
297
+ /**
298
+ * Build a transfer_public_as_signer transaction to transfer credits to another account for later submission to the Aleo network
299
+ *
300
+ * @param {number} amount The amount of credits to transfer
301
+ * @param {string} recipient The recipient of the transfer
302
+ * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
303
+ * @param {number} fee The fee to pay for the transfer
304
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
305
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
306
+ * records for the transfer transaction
307
+ * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
308
+ * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
309
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
310
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
311
+ * @returns {Promise<string | Error>} The transaction id of the transfer transaction
312
+ */
313
+ buildTransferPublicAsSignerTransaction(amount: number, recipient: string, fee: number, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<Transaction | Error>;
314
+ /**
315
+ * Transfer credits to another account
316
+ *
317
+ * @param {number} amount The amount of credits to transfer
318
+ * @param {string} recipient The recipient of the transfer
319
+ * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
320
+ * @param {number} fee The fee to pay for the transfer
321
+ * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
322
+ * @param {string | undefined} caller The caller of the function (if calling transfer_public)
323
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
324
+ * records for the transfer transaction
325
+ * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
326
+ * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
327
+ * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
328
+ * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
329
+ * @returns {Promise<string | Error>} The transaction id of the transfer transaction
330
+ *
331
+ * @example
332
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
333
+ * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
334
+ * const keyProvider = new AleoKeyProvider();
335
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
336
+ *
337
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
338
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
339
+ * await programManager.initialize();
340
+ * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
341
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
342
+ */
343
+ transfer(amount: number, recipient: string, transferType: string, fee: number, privateFee: boolean, caller?: string, recordSearchParams?: RecordSearchParams, amountRecord?: RecordPlaintext | string, feeRecord?: RecordPlaintext | string, privateKey?: PrivateKey, offlineQuery?: OfflineQuery): Promise<string | Error>;
344
+ /**
345
+ * Build transaction to bond credits to a validator for later submission to the Aleo Network
346
+ *
347
+ * @example
348
+ * // Create a keyProvider to handle key management
349
+ * const keyProvider = new AleoKeyProvider();
350
+ * keyProvider.useCache = true;
351
+ *
352
+ * // Create a new ProgramManager with the key that will be used to bond credits
353
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
354
+ * programManager.setAccount(new Account("YourPrivateKey"));
355
+ *
356
+ * // Create the bonding transaction object for later submission
357
+ * const tx = await programManager.buildBondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
358
+ * console.log(tx);
359
+ *
360
+ * // The transaction can be later submitted to the network using the network client.
361
+ * const result = await programManager.networkClient.submitTransaction(tx);
362
+ *
363
+ * @returns string
364
+ * @param {string} staker_address Address of the staker who is bonding the credits
365
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
366
+ * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
367
+ * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
368
+ * validator and is different from the address of the executor of this function, it will bond the credits to that
369
+ * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
370
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
371
+ * @param {number} amount The amount of credits to bond
372
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
373
+ */
374
+ buildBondPublicTransaction(staker_address: string, validator_address: string, withdrawal_address: string, amount: number, options?: Partial<ExecuteOptions>): Promise<Error | Transaction>;
375
+ /**
376
+ * Bond credits to validator.
377
+ *
378
+ * @example
379
+ * // Create a keyProvider to handle key management
380
+ * const keyProvider = new AleoKeyProvider();
381
+ * keyProvider.useCache = true;
382
+ *
383
+ * // Create a new ProgramManager with the key that will be used to bond credits
384
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
385
+ * programManager.setAccount(new Account("YourPrivateKey"));
386
+ *
387
+ * // Create the bonding transaction
388
+ * const tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
389
+ *
390
+ * @returns string
391
+ * @param {string} staker_address Address of the staker who is bonding the credits
392
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the signer (i.e. the
393
+ * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
394
+ * requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing
395
+ * validator and is different from the address of the executor of this function, it will bond the credits to that
396
+ * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
397
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
398
+ * @param {number} amount The amount of credits to bond
399
+ * @param {Options} options Options for the execution
400
+ */
401
+ bondPublic(staker_address: string, validator_address: string, withdrawal_address: string, amount: number, options?: Partial<ExecuteOptions>): Promise<string | Error>;
402
+ /**
403
+ * Build a bond_validator transaction for later submission to the Aleo Network.
404
+ *
405
+ * @example
406
+ * // Create a keyProvider to handle key management
407
+ * const keyProvider = new AleoKeyProvider();
408
+ * keyProvider.useCache = true;
409
+ *
410
+ * // Create a new ProgramManager with the key that will be used to bond credits
411
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
412
+ * programManager.setAccount(new Account("YourPrivateKey"));
413
+ *
414
+ * // Create the bond validator transaction object for later use.
415
+ * const tx = await programManager.buildBondValidatorTransaction("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
416
+ * console.log(tx);
417
+ *
418
+ * // The transaction can later be submitted to the network using the network client.
419
+ * const tx_id = await programManager.networkClient.submitTransaction(tx);
420
+ *
421
+ * @returns string
422
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
423
+ * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
424
+ * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
425
+ * validator and is different from the address of the executor of this function, it will bond the credits to that
426
+ * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
427
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
428
+ * @param {number} amount The amount of credits to bond
429
+ * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
430
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
431
+ */
432
+ buildBondValidatorTransaction(validator_address: string, withdrawal_address: string, amount: number, commission: number, options?: Partial<ExecuteOptions>): Promise<Error | Transaction>;
433
+ /**
434
+ * Build transaction to bond a validator.
435
+ *
436
+ * @example
437
+ * // Create a keyProvider to handle key management
438
+ * const keyProvider = new AleoKeyProvider();
439
+ * keyProvider.useCache = true;
440
+ *
441
+ * // Create a new ProgramManager with the key that will be used to bond credits
442
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
443
+ * programManager.setAccount(new Account("YourPrivateKey"));
444
+ *
445
+ * // Create the bonding transaction
446
+ * const tx_id = await programManager.bondValidator("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
447
+ *
448
+ * @returns string
449
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
450
+ * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
451
+ * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
452
+ * validator and is different from the address of the executor of this function, it will bond the credits to that
453
+ * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
454
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
455
+ * @param {number} amount The amount of credits to bond
456
+ * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
457
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
458
+ */
459
+ bondValidator(validator_address: string, withdrawal_address: string, amount: number, commission: number, options?: Partial<ExecuteOptions>): Promise<string | Error>;
460
+ /**
461
+ * Build a transaction to unbond public credits from a validator in the Aleo network.
462
+ *
463
+ * @param {string} staker_address - The address of the staker who is unbonding the credits.
464
+ * @param {number} amount - The amount of credits to unbond (scaled by 1,000,000).
465
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
466
+ * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error message.
467
+ *
468
+ * @example
469
+ * // Create a keyProvider to handle key management.
470
+ * const keyProvider = new AleoKeyProvider();
471
+ * keyProvider.useCache = true;
472
+ *
473
+ * // Create a new ProgramManager with the key that will be used to unbond credits.
474
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
475
+ * const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
476
+ * console.log(tx);
477
+ *
478
+ * // The transaction can be submitted later to the network using the network client.
479
+ * programManager.networkClient.submitTransaction(tx);
480
+ */
481
+ buildUnbondPublicTransaction(staker_address: string, amount: number, options?: Partial<ExecuteOptions>): Promise<Transaction | Error>;
482
+ /**
483
+ * Unbond a specified amount of staked credits.
484
+ *
485
+ * @example
486
+ * // Create a keyProvider to handle key management
487
+ * const keyProvider = new AleoKeyProvider();
488
+ * keyProvider.useCache = true;
489
+ *
490
+ * // Create a new ProgramManager with the key that will be used to bond credits
491
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
492
+ * programManager.setAccount(new Account("YourPrivateKey"));
493
+ *
494
+ * // Create the bonding transaction and send it to the network
495
+ * const tx_id = await programManager.unbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 10);
496
+ *
497
+ * @returns string
498
+ * @param {string} staker_address Address of the staker who is unbonding the credits
499
+ * @param {number} amount Amount of credits to unbond. If the address of the executor of this function is an
500
+ * existing validator, it will subtract this amount of credits from the validator's staked credits. If there are
501
+ * less than 1,000,000 credits staked pool after the unbond, the validator will be removed from the validator set.
502
+ * If the address of the executor of this function is not a validator and has credits bonded as a delegator, it will
503
+ * subtract this amount of credits from the delegator's staked credits. If there are less than 10 credits bonded
504
+ * after the unbond operation, the delegator will be removed from the validator's staking pool.
505
+ * @param {ExecuteOptions} options Options for the execution
506
+ */
507
+ unbondPublic(staker_address: string, amount: number, options?: Partial<ExecuteOptions>): Promise<string | Error>;
508
+ /**
509
+ * Build a transaction to claim unbonded public credits in the Aleo network.
510
+ *
511
+ * @param {string} staker_address - The address of the staker who is claiming the credits.
512
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
513
+ * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error message.
514
+ *
515
+ * @example
516
+ * // Create a keyProvider to handle key management
517
+ * const keyProvider = new AleoKeyProvider();
518
+ * keyProvider.useCache = true;
519
+ *
520
+ * // Create a new ProgramManager with the key that will be used to claim unbonded credits.
521
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
522
+ *
523
+ * // Create the claim unbonded transaction object for later use.
524
+ * const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
525
+ * console.log(tx);
526
+ *
527
+ * // The transaction can be submitted later to the network using the network client.
528
+ * programManager.networkClient.submitTransaction(tx);
529
+ */
530
+ buildClaimUnbondPublicTransaction(staker_address: string, options?: Partial<ExecuteOptions>): Promise<Transaction | Error>;
531
+ /**
532
+ * Claim unbonded credits. If credits have been unbonded by the account executing this function, this method will
533
+ * claim them and add them to the public balance of the account.
534
+ *
535
+ * @example
536
+ * // Create a keyProvider to handle key management
537
+ * const keyProvider = new AleoKeyProvider();
538
+ * keyProvider.useCache = true;
539
+ *
540
+ * // Create a new ProgramManager with the key that will be used to bond credits
541
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
542
+ * programManager.setAccount(new Account("YourPrivateKey"));
543
+ *
544
+ * // Create the bonding transaction
545
+ * const tx_id = await programManager.claimUnbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
546
+ *
547
+ * @param {string} staker_address Address of the staker who is claiming the credits
548
+ * @param {ExecuteOptions} options
549
+ * @returns string
550
+ */
551
+ claimUnbondPublic(staker_address: string, options?: Partial<ExecuteOptions>): Promise<string | Error>;
552
+ /**
553
+ * Build a set_validator_state transaction for later usage.
554
+ *
555
+ * This function allows a validator to set their state to be either opened or closed to new stakers.
556
+ * When the validator is open to new stakers, any staker (including the validator) can bond or unbond from the validator.
557
+ * When the validator is closed to new stakers, existing stakers can still bond or unbond from the validator, but new stakers cannot bond.
558
+ *
559
+ * This function serves two primary purposes:
560
+ * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
561
+ * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
562
+ *
563
+ * @example
564
+ * // Create a keyProvider to handle key management
565
+ * const keyProvider = new AleoKeyProvider();
566
+ * keyProvider.useCache = true;
567
+ *
568
+ * // Create a new ProgramManager with the key that will be used to bond credits
569
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
570
+ * programManager.setAccount(new Account("ValidatorPrivateKey"));
571
+ *
572
+ * // Create the bonding transaction
573
+ * const tx = await programManager.buildSetValidatorStateTransaction(true);
574
+ *
575
+ * // The transaction can be submitted later to the network using the network client.
576
+ * programManager.networkClient.submitTransaction(tx);
577
+ *
578
+ * @returns string
579
+ * @param {boolean} validator_state
580
+ * @param {Partial<ExecuteOptions>} options - Override default execution options
581
+ */
582
+ buildSetValidatorStateTransaction(validator_state: boolean, options?: Partial<ExecuteOptions>): Promise<string | Error>;
583
+ /**
584
+ * Submit a set_validator_state transaction to the Aleo Network.
585
+ *
586
+ * This function allows a validator to set their state to be either opened or closed to new stakers.
587
+ * When the validator is open to new stakers, any staker (including the validator) can bond or unbond from the validator.
588
+ * When the validator is closed to new stakers, existing stakers can still bond or unbond from the validator, but new stakers cannot bond.
589
+ *
590
+ * This function serves two primary purposes:
591
+ * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
592
+ * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
593
+ *
594
+ * @example
595
+ * // Create a keyProvider to handle key management
596
+ * const keyProvider = new AleoKeyProvider();
597
+ * keyProvider.useCache = true;
598
+ *
599
+ * // Create a new ProgramManager with the key that will be used to bond credits
600
+ * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
601
+ * programManager.setAccount(new Account("ValidatorPrivateKey"));
602
+ *
603
+ * // Create the bonding transaction
604
+ * const tx_id = await programManager.setValidatorState(true);
605
+ *
606
+ * @returns string
607
+ * @param {boolean} validator_state
608
+ * @param {Partial<ExecuteOptions>} options - Override default execution options
609
+ */
610
+ setValidatorState(validator_state: boolean, options?: Partial<ExecuteOptions>): Promise<string | Error>;
611
+ /**
612
+ * Verify a proof of execution from an offline execution
613
+ *
614
+ * @param {executionResponse} executionResponse
615
+ * @returns {boolean} True if the proof is valid, false otherwise
616
+ */
617
+ verifyExecution(executionResponse: ExecutionResponse): boolean;
618
+ /**
619
+ * Create a program object from a program's source code
620
+ *
621
+ * @param {string} program Program source code
622
+ * @returns {Program | Error} The program object
623
+ */
624
+ createProgramFromSource(program: string): Program | Error;
625
+ /**
626
+ * Get the credits program object
627
+ *
628
+ * @returns {Program} The credits program object
629
+ */
630
+ creditsProgram(): Program;
631
+ /**
632
+ * Verify a program is valid
633
+ *
634
+ * @param {string} program The program source code
635
+ */
636
+ verifyProgram(program: string): boolean;
637
+ getCreditsRecord(amount: number, nonces: string[], record?: RecordPlaintext | string, params?: RecordSearchParams): Promise<RecordPlaintext | Error>;
638
+ }
639
+ export { ProgramManager };