@provablehq/sdk 0.9.13 → 0.9.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainnet/browser.js +246 -136
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.ts +1 -0
- package/dist/mainnet/integrations/sealance/merkle-tree.d.ts +63 -17
- package/dist/mainnet/network-client.d.ts +29 -2
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/testnet/browser.js +246 -136
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.ts +1 -0
- package/dist/testnet/integrations/sealance/merkle-tree.d.ts +63 -17
- package/dist/testnet/network-client.d.ts +29 -2
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/package.json +2 -2
package/dist/mainnet/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
2
|
-
import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Program, Plaintext, Transaction, ProvingRequest,
|
|
2
|
+
import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Metadata, VerifyingKey, Program, Plaintext, Transaction, ProvingRequest, ProvingKey, RecordPlaintext, Field, Poseidon4, ProgramManager as ProgramManager$1, verifyFunctionExecution } from '@provablehq/wasm/mainnet.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/mainnet.js';
|
|
4
4
|
import { bech32m } from '@scure/base';
|
|
5
5
|
|
|
@@ -466,6 +466,106 @@ async function retryWithBackoff(fn, { maxAttempts = 5, baseDelay = 100, jitter,
|
|
|
466
466
|
throw new Error("retryWithBackoff: unreachable");
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
const KEY_STORE = Metadata.baseUrl();
|
|
470
|
+
function convert(metadata) {
|
|
471
|
+
// This looks up the method name in VerifyingKey
|
|
472
|
+
const verifyingKey = VerifyingKey[metadata.verifyingKey];
|
|
473
|
+
if (!verifyingKey) {
|
|
474
|
+
throw new Error("Invalid method name: " + metadata.verifyingKey);
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
name: metadata.name,
|
|
478
|
+
locator: metadata.locator,
|
|
479
|
+
prover: metadata.prover,
|
|
480
|
+
verifier: metadata.verifier,
|
|
481
|
+
verifyingKey,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
const CREDITS_PROGRAM_KEYS = {
|
|
485
|
+
bond_public: convert(Metadata.bond_public()),
|
|
486
|
+
bond_validator: convert(Metadata.bond_validator()),
|
|
487
|
+
claim_unbond_public: convert(Metadata.claim_unbond_public()),
|
|
488
|
+
fee_private: convert(Metadata.fee_private()),
|
|
489
|
+
fee_public: convert(Metadata.fee_public()),
|
|
490
|
+
inclusion: convert(Metadata.inclusion()),
|
|
491
|
+
join: convert(Metadata.join()),
|
|
492
|
+
set_validator_state: convert(Metadata.set_validator_state()),
|
|
493
|
+
split: convert(Metadata.split()),
|
|
494
|
+
transfer_private: convert(Metadata.transfer_private()),
|
|
495
|
+
transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
|
|
496
|
+
transfer_public: convert(Metadata.transfer_public()),
|
|
497
|
+
transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
|
|
498
|
+
transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
|
|
499
|
+
unbond_public: convert(Metadata.unbond_public()),
|
|
500
|
+
getKey: function (key) {
|
|
501
|
+
if (this.hasOwnProperty(key)) {
|
|
502
|
+
return this[key];
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
throw new Error(`Key "${key}" not found.`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const PRIVATE_TRANSFER_TYPES = new Set([
|
|
510
|
+
"transfer_private",
|
|
511
|
+
"private",
|
|
512
|
+
"transferPrivate",
|
|
513
|
+
"transfer_private_to_public",
|
|
514
|
+
"privateToPublic",
|
|
515
|
+
"transferPrivateToPublic",
|
|
516
|
+
]);
|
|
517
|
+
const VALID_TRANSFER_TYPES = new Set([
|
|
518
|
+
"transfer_private",
|
|
519
|
+
"private",
|
|
520
|
+
"transferPrivate",
|
|
521
|
+
"transfer_private_to_public",
|
|
522
|
+
"privateToPublic",
|
|
523
|
+
"transferPrivateToPublic",
|
|
524
|
+
"transfer_public",
|
|
525
|
+
"transfer_public_as_signer",
|
|
526
|
+
"public",
|
|
527
|
+
"public_as_signer",
|
|
528
|
+
"transferPublic",
|
|
529
|
+
"transferPublicAsSigner",
|
|
530
|
+
"transfer_public_to_private",
|
|
531
|
+
"publicToPrivate",
|
|
532
|
+
"publicAsSigner",
|
|
533
|
+
"transferPublicToPrivate",
|
|
534
|
+
]);
|
|
535
|
+
const PRIVATE_TRANSFER = new Set([
|
|
536
|
+
"private",
|
|
537
|
+
"transfer_private",
|
|
538
|
+
"transferPrivate",
|
|
539
|
+
]);
|
|
540
|
+
const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
|
|
541
|
+
"private_to_public",
|
|
542
|
+
"privateToPublic",
|
|
543
|
+
"transfer_private_to_public",
|
|
544
|
+
"transferPrivateToPublic",
|
|
545
|
+
]);
|
|
546
|
+
const PUBLIC_TRANSFER = new Set([
|
|
547
|
+
"public",
|
|
548
|
+
"transfer_public",
|
|
549
|
+
"transferPublic",
|
|
550
|
+
]);
|
|
551
|
+
const PUBLIC_TRANSFER_AS_SIGNER = new Set([
|
|
552
|
+
"public_as_signer",
|
|
553
|
+
"transfer_public_as_signer",
|
|
554
|
+
"transferPublicAsSigner",
|
|
555
|
+
]);
|
|
556
|
+
const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
|
|
557
|
+
"public_to_private",
|
|
558
|
+
"publicToPrivate",
|
|
559
|
+
"transfer_public_to_private",
|
|
560
|
+
"transferPublicToPrivate",
|
|
561
|
+
]);
|
|
562
|
+
const RECORD_DOMAIN = "RecordScannerV0";
|
|
563
|
+
/**
|
|
564
|
+
* Zero address on Aleo blockchain that corresponds to field element 0. Used as padding in Merkle trees and as a sentinel value.
|
|
565
|
+
*/
|
|
566
|
+
const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
|
|
567
|
+
const FIVE_MINUTES = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
568
|
+
|
|
469
569
|
/**
|
|
470
570
|
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
|
|
471
571
|
* allow users to query public information from the Aleo blockchain and submit transactions to the network.
|
|
@@ -477,6 +577,8 @@ async function retryWithBackoff(fn, { maxAttempts = 5, baseDelay = 100, jitter,
|
|
|
477
577
|
*
|
|
478
578
|
* // Connection to a public beacon node
|
|
479
579
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
580
|
+
* const apiKey = process.env.apiKey;
|
|
581
|
+
* const consumerId = process.env.consumerId;
|
|
480
582
|
* const publicNetworkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined, account);
|
|
481
583
|
*/
|
|
482
584
|
class AleoNetworkClient {
|
|
@@ -486,6 +588,9 @@ class AleoNetworkClient {
|
|
|
486
588
|
ctx;
|
|
487
589
|
verboseErrors;
|
|
488
590
|
network;
|
|
591
|
+
apiKey;
|
|
592
|
+
consumerId;
|
|
593
|
+
jwtData;
|
|
489
594
|
constructor(host, options) {
|
|
490
595
|
this.host = host + "/mainnet";
|
|
491
596
|
this.network = "mainnet";
|
|
@@ -497,7 +602,7 @@ class AleoNetworkClient {
|
|
|
497
602
|
else {
|
|
498
603
|
this.headers = {
|
|
499
604
|
// This is replaced by the actual version by a Rollup plugin
|
|
500
|
-
"X-Aleo-SDK-Version": "0.9.
|
|
605
|
+
"X-Aleo-SDK-Version": "0.9.14",
|
|
501
606
|
"X-Aleo-environment": environment(),
|
|
502
607
|
};
|
|
503
608
|
}
|
|
@@ -1342,10 +1447,9 @@ class AleoNetworkClient {
|
|
|
1342
1447
|
* programImports = await networkClient.getProgramImports(double_test);
|
|
1343
1448
|
* assert.deepStrictEqual(programImports, expectedImports);
|
|
1344
1449
|
*/
|
|
1345
|
-
async getProgramImports(inputProgram) {
|
|
1450
|
+
async getProgramImports(inputProgram, imports = {}) {
|
|
1346
1451
|
try {
|
|
1347
1452
|
this.ctx = { "X-ALEO-METHOD": "getProgramImports" };
|
|
1348
|
-
const imports = {};
|
|
1349
1453
|
// Normalize input to a Program object
|
|
1350
1454
|
let program;
|
|
1351
1455
|
if (inputProgram instanceof Program) {
|
|
@@ -1371,7 +1475,7 @@ class AleoNetworkClient {
|
|
|
1371
1475
|
const import_id = importList[i];
|
|
1372
1476
|
if (!imports.hasOwnProperty(import_id)) {
|
|
1373
1477
|
const programSource = await this.getProgram(import_id);
|
|
1374
|
-
const nestedImports = await this.getProgramImports(
|
|
1478
|
+
const nestedImports = await this.getProgramImports(programSource, imports);
|
|
1375
1479
|
for (const key in nestedImports) {
|
|
1376
1480
|
if (!imports.hasOwnProperty(key)) {
|
|
1377
1481
|
imports[key] = nestedImports[key];
|
|
@@ -1841,6 +1945,32 @@ class AleoNetworkClient {
|
|
|
1841
1945
|
throw new Error(`Error posting solution: No response received: ${error.message}`);
|
|
1842
1946
|
}
|
|
1843
1947
|
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Refreshes the JWT by making a POST request to /jwts/{consumer_id}
|
|
1950
|
+
*
|
|
1951
|
+
* @param {string} apiKey - The API key for authentication.
|
|
1952
|
+
* @param {string} consumerId - The consumer ID associated with the API key.
|
|
1953
|
+
* @returns {Promise<JwtData>} The JWT token and expiration time
|
|
1954
|
+
*/
|
|
1955
|
+
async refreshJwt(apiKey, consumerId) {
|
|
1956
|
+
if (!apiKey || !consumerId) {
|
|
1957
|
+
throw new Error('API key and consumer ID are required to refresh JWT');
|
|
1958
|
+
}
|
|
1959
|
+
const response = await post(`https://api.provable.com/jwts/${consumerId}`, {
|
|
1960
|
+
headers: {
|
|
1961
|
+
'X-Provable-API-Key': apiKey
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
const authHeader = response.headers.get('authorization');
|
|
1965
|
+
if (!authHeader) {
|
|
1966
|
+
throw new Error('No authorization header in JWT refresh response');
|
|
1967
|
+
}
|
|
1968
|
+
const body = await response.json();
|
|
1969
|
+
return {
|
|
1970
|
+
jwt: authHeader,
|
|
1971
|
+
expiration: body.exp * 1000 // Convert to milliseconds
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1844
1974
|
/**
|
|
1845
1975
|
* Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor.
|
|
1846
1976
|
*
|
|
@@ -1852,18 +1982,33 @@ class AleoNetworkClient {
|
|
|
1852
1982
|
const provingRequestString = options.provingRequest instanceof ProvingRequest
|
|
1853
1983
|
? options.provingRequest.toString()
|
|
1854
1984
|
: options.provingRequest;
|
|
1855
|
-
|
|
1985
|
+
const apiKey = options.apiKey ?? this.apiKey;
|
|
1986
|
+
const consumerId = options.consumerId ?? this.consumerId;
|
|
1987
|
+
let jwtData = options.jwtData ?? this.jwtData;
|
|
1988
|
+
// Check if JWT is expired or missing
|
|
1989
|
+
const bufferTime = FIVE_MINUTES; // 5 minutes buffer
|
|
1990
|
+
const isExpired = jwtData && Date.now() >= jwtData.expiration - bufferTime;
|
|
1991
|
+
if (!jwtData || isExpired) {
|
|
1992
|
+
if (options.apiKey && options.consumerId) {
|
|
1993
|
+
jwtData = await this.refreshJwt(apiKey, consumerId);
|
|
1994
|
+
// Update both the class and the options with the new JWT
|
|
1995
|
+
this.jwtData = jwtData;
|
|
1996
|
+
options.jwtData = jwtData;
|
|
1997
|
+
}
|
|
1998
|
+
else {
|
|
1999
|
+
throw new Error('JWT or both apiKey and consumerId are required');
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
1856
2002
|
const headers = {
|
|
1857
2003
|
...this.headers,
|
|
1858
2004
|
"X-ALEO-METHOD": "submitProvingRequest",
|
|
1859
|
-
"Content-Type": "application/json"
|
|
2005
|
+
"Content-Type": "application/json",
|
|
1860
2006
|
};
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
headers["X-Provable-API-Key"] = options.apiKey;
|
|
2007
|
+
if (jwtData?.jwt) {
|
|
2008
|
+
headers["Authorization"] = jwtData.jwt;
|
|
1864
2009
|
}
|
|
1865
2010
|
try {
|
|
1866
|
-
const response = await retryWithBackoff(() => post(`${proverUri}
|
|
2011
|
+
const response = await retryWithBackoff(() => post(`${proverUri}`, {
|
|
1867
2012
|
body: provingRequestString,
|
|
1868
2013
|
headers
|
|
1869
2014
|
}));
|
|
@@ -1957,105 +2102,6 @@ class AleoNetworkClient {
|
|
|
1957
2102
|
}
|
|
1958
2103
|
}
|
|
1959
2104
|
|
|
1960
|
-
const KEY_STORE = Metadata.baseUrl();
|
|
1961
|
-
function convert(metadata) {
|
|
1962
|
-
// This looks up the method name in VerifyingKey
|
|
1963
|
-
const verifyingKey = VerifyingKey[metadata.verifyingKey];
|
|
1964
|
-
if (!verifyingKey) {
|
|
1965
|
-
throw new Error("Invalid method name: " + metadata.verifyingKey);
|
|
1966
|
-
}
|
|
1967
|
-
return {
|
|
1968
|
-
name: metadata.name,
|
|
1969
|
-
locator: metadata.locator,
|
|
1970
|
-
prover: metadata.prover,
|
|
1971
|
-
verifier: metadata.verifier,
|
|
1972
|
-
verifyingKey,
|
|
1973
|
-
};
|
|
1974
|
-
}
|
|
1975
|
-
const CREDITS_PROGRAM_KEYS = {
|
|
1976
|
-
bond_public: convert(Metadata.bond_public()),
|
|
1977
|
-
bond_validator: convert(Metadata.bond_validator()),
|
|
1978
|
-
claim_unbond_public: convert(Metadata.claim_unbond_public()),
|
|
1979
|
-
fee_private: convert(Metadata.fee_private()),
|
|
1980
|
-
fee_public: convert(Metadata.fee_public()),
|
|
1981
|
-
inclusion: convert(Metadata.inclusion()),
|
|
1982
|
-
join: convert(Metadata.join()),
|
|
1983
|
-
set_validator_state: convert(Metadata.set_validator_state()),
|
|
1984
|
-
split: convert(Metadata.split()),
|
|
1985
|
-
transfer_private: convert(Metadata.transfer_private()),
|
|
1986
|
-
transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
|
|
1987
|
-
transfer_public: convert(Metadata.transfer_public()),
|
|
1988
|
-
transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
|
|
1989
|
-
transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
|
|
1990
|
-
unbond_public: convert(Metadata.unbond_public()),
|
|
1991
|
-
getKey: function (key) {
|
|
1992
|
-
if (this.hasOwnProperty(key)) {
|
|
1993
|
-
return this[key];
|
|
1994
|
-
}
|
|
1995
|
-
else {
|
|
1996
|
-
throw new Error(`Key "${key}" not found.`);
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
};
|
|
2000
|
-
const PRIVATE_TRANSFER_TYPES = new Set([
|
|
2001
|
-
"transfer_private",
|
|
2002
|
-
"private",
|
|
2003
|
-
"transferPrivate",
|
|
2004
|
-
"transfer_private_to_public",
|
|
2005
|
-
"privateToPublic",
|
|
2006
|
-
"transferPrivateToPublic",
|
|
2007
|
-
]);
|
|
2008
|
-
const VALID_TRANSFER_TYPES = new Set([
|
|
2009
|
-
"transfer_private",
|
|
2010
|
-
"private",
|
|
2011
|
-
"transferPrivate",
|
|
2012
|
-
"transfer_private_to_public",
|
|
2013
|
-
"privateToPublic",
|
|
2014
|
-
"transferPrivateToPublic",
|
|
2015
|
-
"transfer_public",
|
|
2016
|
-
"transfer_public_as_signer",
|
|
2017
|
-
"public",
|
|
2018
|
-
"public_as_signer",
|
|
2019
|
-
"transferPublic",
|
|
2020
|
-
"transferPublicAsSigner",
|
|
2021
|
-
"transfer_public_to_private",
|
|
2022
|
-
"publicToPrivate",
|
|
2023
|
-
"publicAsSigner",
|
|
2024
|
-
"transferPublicToPrivate",
|
|
2025
|
-
]);
|
|
2026
|
-
const PRIVATE_TRANSFER = new Set([
|
|
2027
|
-
"private",
|
|
2028
|
-
"transfer_private",
|
|
2029
|
-
"transferPrivate",
|
|
2030
|
-
]);
|
|
2031
|
-
const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
|
|
2032
|
-
"private_to_public",
|
|
2033
|
-
"privateToPublic",
|
|
2034
|
-
"transfer_private_to_public",
|
|
2035
|
-
"transferPrivateToPublic",
|
|
2036
|
-
]);
|
|
2037
|
-
const PUBLIC_TRANSFER = new Set([
|
|
2038
|
-
"public",
|
|
2039
|
-
"transfer_public",
|
|
2040
|
-
"transferPublic",
|
|
2041
|
-
]);
|
|
2042
|
-
const PUBLIC_TRANSFER_AS_SIGNER = new Set([
|
|
2043
|
-
"public_as_signer",
|
|
2044
|
-
"transfer_public_as_signer",
|
|
2045
|
-
"transferPublicAsSigner",
|
|
2046
|
-
]);
|
|
2047
|
-
const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
|
|
2048
|
-
"public_to_private",
|
|
2049
|
-
"publicToPrivate",
|
|
2050
|
-
"transfer_public_to_private",
|
|
2051
|
-
"transferPublicToPrivate",
|
|
2052
|
-
]);
|
|
2053
|
-
const RECORD_DOMAIN = "RecordScannerV0";
|
|
2054
|
-
/**
|
|
2055
|
-
* Zero address on Aleo blockchain that corresponds to field element 0. Used as padding in Merkle trees and as a sentinel value.
|
|
2056
|
-
*/
|
|
2057
|
-
const ZERO_ADDRESS = "aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc";
|
|
2058
|
-
|
|
2059
2105
|
/**
|
|
2060
2106
|
* AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
|
|
2061
2107
|
* verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
|
|
@@ -3616,6 +3662,7 @@ class RecordScanner {
|
|
|
3616
3662
|
* const proof_left = sealance.getSiblingPath(tree, leftIdx, 15);
|
|
3617
3663
|
* const proof_right = sealance.getSiblingPath(tree, rightIdx, 15);
|
|
3618
3664
|
* const exclusion_proof = [proof_left, proof_right];
|
|
3665
|
+
* const formatted_proof = sealance.formatMerkleProof(exclusion_proof);
|
|
3619
3666
|
* ```
|
|
3620
3667
|
*/
|
|
3621
3668
|
class SealanceMerkleTree {
|
|
@@ -3633,8 +3680,9 @@ class SealanceMerkleTree {
|
|
|
3633
3680
|
*
|
|
3634
3681
|
* @example
|
|
3635
3682
|
* ```typescript
|
|
3683
|
+
* const sealance = new SealanceMerkleTree();
|
|
3636
3684
|
* const address = "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px";
|
|
3637
|
-
* const fieldValue = convertAddressToField(address);
|
|
3685
|
+
* const fieldValue = sealance.convertAddressToField(address);
|
|
3638
3686
|
* console.log(fieldValue); // 123456789...n
|
|
3639
3687
|
* ```
|
|
3640
3688
|
*/
|
|
@@ -3673,8 +3721,9 @@ class SealanceMerkleTree {
|
|
|
3673
3721
|
*
|
|
3674
3722
|
* @example
|
|
3675
3723
|
* ```typescript
|
|
3724
|
+
* const sealance = new SealanceMerkleTree();
|
|
3676
3725
|
* const leaves = ["0field", "1field", "2field", "3field"];
|
|
3677
|
-
* const tree = buildTree(leaves);
|
|
3726
|
+
* const tree = sealance.buildTree(leaves);
|
|
3678
3727
|
* const root = tree[tree.length - 1]; // Get the Merkle root
|
|
3679
3728
|
* ```
|
|
3680
3729
|
*/
|
|
@@ -3703,10 +3752,23 @@ class SealanceMerkleTree {
|
|
|
3703
3752
|
}
|
|
3704
3753
|
return tree.map(element => BigInt(element.slice(0, element.length - "field".length)));
|
|
3705
3754
|
}
|
|
3706
|
-
/**
|
|
3755
|
+
/**
|
|
3756
|
+
* Converts an array of decimal string representations of U256 numbers to an array of BigInts.
|
|
3707
3757
|
*
|
|
3708
3758
|
* @param tree - Array of decimal string representations of U256 numbers.
|
|
3709
3759
|
* @returns Array of BigInts.
|
|
3760
|
+
*
|
|
3761
|
+
* @example
|
|
3762
|
+
* ```typescript
|
|
3763
|
+
* const treeStrings = ["0","4328470178059738374782465505490977516512210899136548187530607227309847251692","1741259420362056497457198439964202806733137875365061915996980524089960046336"];
|
|
3764
|
+
* const sealance = new SealanceMerkleTree();
|
|
3765
|
+
* const treeBigInts = sealance.convertTreeToBigInt(treeStrings);
|
|
3766
|
+
* console.log(treeBigInts); // [
|
|
3767
|
+
* 0,
|
|
3768
|
+
* 4328470178059738374782465505490977516512210899136548187530607227309847251692,
|
|
3769
|
+
* 1741259420362056497457198439964202806733137875365061915996980524089960046336
|
|
3770
|
+
* ]
|
|
3771
|
+
* ```
|
|
3710
3772
|
*/
|
|
3711
3773
|
convertTreeToBigInt(tree) {
|
|
3712
3774
|
return tree.map((element) => {
|
|
@@ -3730,11 +3792,18 @@ class SealanceMerkleTree {
|
|
|
3730
3792
|
* @example
|
|
3731
3793
|
* ```typescript
|
|
3732
3794
|
* const addresses = [
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
* const
|
|
3795
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
3796
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3797
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3798
|
+
* ];
|
|
3799
|
+
* const sealance = new SealanceMerkleTree();
|
|
3800
|
+
* const leaves = sealance.generateLeaves(addresses, 15);
|
|
3801
|
+
* console.log(leaves); // [
|
|
3802
|
+
* "0field",
|
|
3803
|
+
* "1295133970529764960316948294624974168921228814652993007266766481909235735940field",
|
|
3804
|
+
* "1295133970529764960316948294624974168921228814652993007266766481909235735940field",
|
|
3805
|
+
* "3501665755452795161867664882580888971213780722176652848275908626939553697821field"
|
|
3806
|
+
* ]
|
|
3738
3807
|
* ```
|
|
3739
3808
|
*/
|
|
3740
3809
|
generateLeaves(addresses, maxTreeDepth = 15) {
|
|
@@ -3773,8 +3842,15 @@ class SealanceMerkleTree {
|
|
|
3773
3842
|
*
|
|
3774
3843
|
* @example
|
|
3775
3844
|
* ```typescript
|
|
3776
|
-
* const
|
|
3777
|
-
|
|
3845
|
+
* const addresses = [
|
|
3846
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
3847
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3848
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3849
|
+
* ];
|
|
3850
|
+
* const sealance = new SealanceMerkleTree();
|
|
3851
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
3852
|
+
* const tree = sealance.buildTree(leaves);
|
|
3853
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
3778
3854
|
* ```
|
|
3779
3855
|
*/
|
|
3780
3856
|
getLeafIndices(merkleTree, address) {
|
|
@@ -3802,9 +3878,17 @@ class SealanceMerkleTree {
|
|
|
3802
3878
|
*
|
|
3803
3879
|
* @example
|
|
3804
3880
|
* ```typescript
|
|
3805
|
-
* const
|
|
3806
|
-
*
|
|
3807
|
-
*
|
|
3881
|
+
* const addresses = [
|
|
3882
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
3883
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3884
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3885
|
+
* ];
|
|
3886
|
+
* const sealance = new SealanceMerkleTree();
|
|
3887
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
3888
|
+
* const tree = sealance.buildTree(leaves);
|
|
3889
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
3890
|
+
* const proof = sealance.getSiblingPath(tree, leftIdx, 15);
|
|
3891
|
+
* // proof = { siblings: [0n, 1n, ...], leaf_index: leftIdx }
|
|
3808
3892
|
* ```
|
|
3809
3893
|
*/
|
|
3810
3894
|
getSiblingPath(tree, leafIndex, depth) {
|
|
@@ -3835,10 +3919,18 @@ class SealanceMerkleTree {
|
|
|
3835
3919
|
*
|
|
3836
3920
|
* @example
|
|
3837
3921
|
* ```typescript
|
|
3838
|
-
* const
|
|
3839
|
-
*
|
|
3840
|
-
*
|
|
3841
|
-
*
|
|
3922
|
+
* const addresses = [
|
|
3923
|
+
* "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
|
|
3924
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3925
|
+
* "aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t",
|
|
3926
|
+
* ];
|
|
3927
|
+
* const sealance = new SealanceMerkleTree();
|
|
3928
|
+
* const leaves = sealance.generateLeaves(addresses);
|
|
3929
|
+
* const tree = sealance.buildTree(leaves);
|
|
3930
|
+
* const [leftIdx, rightIdx] = sealance.getLeafIndices(tree, "aleo1...");
|
|
3931
|
+
* const proof1 = getSiblingPath(tree, leftIdx, 15);
|
|
3932
|
+
* const proof2 = getSiblingPath(tree, rightIdx, 15);
|
|
3933
|
+
* const formattedProof = formatMerkleProof([proof1, proof2]);
|
|
3842
3934
|
* // formattedProof = "[{ siblings: [0field, 1field, ...], leaf_index: 0u32 }, { siblings: [0field, 2field, ...], leaf_index: 1u32 }]"
|
|
3843
3935
|
* ```
|
|
3844
3936
|
*/
|
|
@@ -4267,7 +4359,9 @@ class ProgramManager {
|
|
|
4267
4359
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
4268
4360
|
}
|
|
4269
4361
|
// Check if the account has sufficient credits to pay for the transaction
|
|
4270
|
-
|
|
4362
|
+
if (!privateFee) {
|
|
4363
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
4364
|
+
}
|
|
4271
4365
|
return await this.networkClient.submitTransaction(tx);
|
|
4272
4366
|
}
|
|
4273
4367
|
/**
|
|
@@ -4938,7 +5032,9 @@ class ProgramManager {
|
|
|
4938
5032
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
4939
5033
|
}
|
|
4940
5034
|
// Check if the account has sufficient credits to pay for the transaction
|
|
4941
|
-
|
|
5035
|
+
if (!options.privateFee) {
|
|
5036
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5037
|
+
}
|
|
4942
5038
|
return await this.networkClient.submitTransaction(tx);
|
|
4943
5039
|
}
|
|
4944
5040
|
/**
|
|
@@ -5110,7 +5206,9 @@ class ProgramManager {
|
|
|
5110
5206
|
// Build an execution transaction and submit it to the network
|
|
5111
5207
|
const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
|
|
5112
5208
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5113
|
-
|
|
5209
|
+
if (!privateFee) {
|
|
5210
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5211
|
+
}
|
|
5114
5212
|
return await this.networkClient.submitTransaction(tx);
|
|
5115
5213
|
}
|
|
5116
5214
|
/**
|
|
@@ -5437,7 +5535,9 @@ class ProgramManager {
|
|
|
5437
5535
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5438
5536
|
}
|
|
5439
5537
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5440
|
-
|
|
5538
|
+
if (!privateFee) {
|
|
5539
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5540
|
+
}
|
|
5441
5541
|
return await this.networkClient.submitTransaction(tx);
|
|
5442
5542
|
}
|
|
5443
5543
|
/**
|
|
@@ -5538,7 +5638,9 @@ class ProgramManager {
|
|
|
5538
5638
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5539
5639
|
}
|
|
5540
5640
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5541
|
-
|
|
5641
|
+
if (!options.privateFee) {
|
|
5642
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5643
|
+
}
|
|
5542
5644
|
return await this.networkClient.submitTransaction(tx);
|
|
5543
5645
|
}
|
|
5544
5646
|
/**
|
|
@@ -5644,7 +5746,9 @@ class ProgramManager {
|
|
|
5644
5746
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5645
5747
|
}
|
|
5646
5748
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5647
|
-
|
|
5749
|
+
if (!options.privateFee) {
|
|
5750
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5751
|
+
}
|
|
5648
5752
|
return await this.networkClient.submitTransaction(tx);
|
|
5649
5753
|
}
|
|
5650
5754
|
/**
|
|
@@ -5742,7 +5846,9 @@ class ProgramManager {
|
|
|
5742
5846
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5743
5847
|
}
|
|
5744
5848
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5745
|
-
|
|
5849
|
+
if (!options.privateFee) {
|
|
5850
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5851
|
+
}
|
|
5746
5852
|
return await this.networkClient.submitTransaction(tx);
|
|
5747
5853
|
}
|
|
5748
5854
|
/**
|
|
@@ -5836,7 +5942,9 @@ class ProgramManager {
|
|
|
5836
5942
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5837
5943
|
}
|
|
5838
5944
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5839
|
-
|
|
5945
|
+
if (!options.privateFee) {
|
|
5946
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
5947
|
+
}
|
|
5840
5948
|
return await this.networkClient.submitTransaction(tx);
|
|
5841
5949
|
}
|
|
5842
5950
|
/**
|
|
@@ -5943,7 +6051,9 @@ class ProgramManager {
|
|
|
5943
6051
|
throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
|
|
5944
6052
|
}
|
|
5945
6053
|
// Check if the account has sufficient credits to pay for the transaction
|
|
5946
|
-
|
|
6054
|
+
if (!options.privateFee) {
|
|
6055
|
+
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
6056
|
+
}
|
|
5947
6057
|
return this.networkClient.submitTransaction(tx);
|
|
5948
6058
|
}
|
|
5949
6059
|
/**
|