From 316d1b6367c14d16af352d3917eb9154cddbd567 Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 19:20:31 -0400 Subject: [PATCH 1/6] Update SnarkVM version to d170a9f and update sdk methods to use new credits.aleo methods and method signatures --- .../src/index.ts | 24 +- .../template-react-ts/src/workers/worker.ts | 4 +- sdk/README.md | 6 +- sdk/src/function-key-provider.ts | 36 +- sdk/src/index.ts | 13 +- sdk/src/offline-key-provider.ts | 60 ++- sdk/src/program-manager.ts | 346 +++++++++++++----- sdk/tests/key-provider.test.ts | 2 - wasm/Cargo.lock | 113 +++--- wasm/Cargo.toml | 16 +- wasm/src/programs/manager/transfer.rs | 10 +- wasm/src/programs/offline_query.rs | 6 +- wasm/src/programs/program.rs | 5 + wasm/src/programs/proving_key/credits.rs | 58 +-- wasm/src/programs/verifying_key/credits.rs | 163 +++++---- wasm/src/programs/verifying_key/metadata.rs | 33 +- wasm/src/programs/verifying_key/mod.rs | 11 +- wasm/tests/offchain.rs | 2 + 18 files changed, 584 insertions(+), 324 deletions(-) diff --git a/create-aleo-app/template-offline-public-transaction-ts/src/index.ts b/create-aleo-app/template-offline-public-transaction-ts/src/index.ts index 3597e3597..1fddf826a 100644 --- a/create-aleo-app/template-offline-public-transaction-ts/src/index.ts +++ b/create-aleo-app/template-offline-public-transaction-ts/src/index.ts @@ -15,9 +15,9 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n // Create the proving keys from the key bytes on the offline machine console.log("Creating proving keys from local key files"); const feePublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.fee_public.locator]); - const transferPublicKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.transfer_public.locator]); + const transferPublicAsSignerKeyBytes = await getLocalKey(keyPaths[CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator]); const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes); - const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicKeyBytes); + const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicAsSignerKeyBytes); // Create an offline key provider console.log("Creating offline key provider"); @@ -37,7 +37,7 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n // Build tne transfer_public transaction offline console.log("Building transfer transaction offline"); - return programManager.buildTransferPublicTransaction( + return programManager.buildTransferPublicAsSignerTransaction( amount, recipientAddress.to_string(), 0.28, @@ -47,7 +47,7 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n } /// Build bonding and unbonding transactions without connection to the internet -async function buildBondingTxOffline(recipientAddress: Address, amount: number, latestStateRoot: string, keyPaths: {}): Promise { +async function buildBondingTxOffline(stakerAddress: Address, validatorAddress: Address, withdrawalAddress: Address, amount: number, latestStateRoot: string, keyPaths: {}): Promise { // Create an offline program manager const programManager = new ProgramManager(); @@ -93,7 +93,9 @@ async function buildBondingTxOffline(recipientAddress: Address, amount: number, } const bondTx = await programManager.buildBondPublicTransaction( - recipientAddress.to_string(), + stakerAddress.to_string(), + validatorAddress.to_string(), + withdrawalAddress.to_string(), amount, bondPublicOptions, ) @@ -109,7 +111,7 @@ async function buildBondingTxOffline(recipientAddress: Address, amount: number, } } - const unBondTx = await programManager.buildUnbondPublicTransaction(amount, unbondPublicOptions); + const unBondTx = await programManager.buildUnbondPublicTransaction(stakerAddress.to_string(), amount, unbondPublicOptions); console.log("\nunbond_public transaction built!\n"); console.log("Building a claim_unbond_public transaction offline") @@ -123,7 +125,7 @@ async function buildBondingTxOffline(recipientAddress: Address, amount: number, } } - const claimUnbondTx = await programManager.buildClaimUnbondPublicTransaction(claimUnbondPublicOptions); + const claimUnbondTx = await programManager.buildClaimUnbondPublicTransaction(stakerAddress.to_string(), claimUnbondPublicOptions); console.log("\nclaim_unbond_public transaction built!\n"); return [bondTx, unBondTx, claimUnbondTx]; } @@ -142,14 +144,16 @@ const bondingKeyPaths = await preDownloadBondingKeys(); const latestStateRoot = "sr1p93gpsezrjzdhcd2wujznx5s07k8qa39t6vfcej35zew8vn2jyrs46te8q"; // Build a transfer_public transaction -const recipientAddress = new Account().address(); -const transferTx = await buildTransferPublicTxOffline(recipientAddress, 100, latestStateRoot, transferKeyPaths); +const stakerAddress = new Account().address(); +const validatorAddress = new Account().address(); +const withdrawalAddress = new Account().address(); +const transferTx = await buildTransferPublicTxOffline(stakerAddress, 10000, latestStateRoot, transferKeyPaths); console.log("Transfer transaction built offline!"); console.log(`\n---------------transfer_public transaction---------------\n${transferTx}`); console.log(`---------------------------------------------------------`); // Build bonding & unbonding transactions -const bondTransactions = await buildBondingTxOffline(recipientAddress, 100, latestStateRoot, bondingKeyPaths); +const bondTransactions = await buildBondingTxOffline(stakerAddress, validatorAddress, withdrawalAddress, 100, latestStateRoot, bondingKeyPaths); console.log("Bonding transactions built offline!"); console.log(`\n-----------------bond_public transaction-----------------\n${bondTransactions[0]}`); console.log(`---------------------------------------------------------`); diff --git a/create-aleo-app/template-react-ts/src/workers/worker.ts b/create-aleo-app/template-react-ts/src/workers/worker.ts index af3f3f24e..ab72bb68c 100644 --- a/create-aleo-app/template-react-ts/src/workers/worker.ts +++ b/create-aleo-app/template-react-ts/src/workers/worker.ts @@ -38,7 +38,7 @@ async function deployProgram(program) { keyProvider.useCache(true); // Create a record provider that will be used to find records and transaction data for Aleo programs - const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); // Use existing account with funds const account = new Account({ @@ -49,7 +49,7 @@ async function deployProgram(program) { // Initialize a program manager to talk to the Aleo network with the configured key and record providers const programManager = new ProgramManager( - "https://vm.aleo.org/api", + "https://api.explorer.aleo.org/v1", keyProvider, recordProvider, ); diff --git a/sdk/README.md b/sdk/README.md index 32ad6707a..b15c7cc8b 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -1095,7 +1095,7 @@ read the value of a specific key within a mapping. ```typescript import { AleoNetworkClient } from '@aleo/sdk'; -const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); +const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); const creditsMappings = networkClient.getMappings("credits.aleo"); assert(creditsMappings === ["account"]); @@ -1142,13 +1142,13 @@ import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNe // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); -const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); +const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const RECIPIENT_ADDRESS = "user1Address"; -const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); programManager.setAccount(account); // Update or initialize a public balance diff --git a/sdk/src/function-key-provider.ts b/sdk/src/function-key-provider.ts index ccc6bbef1..9a13d44a9 100644 --- a/sdk/src/function-key-provider.ts +++ b/sdk/src/function-key-provider.ts @@ -1,4 +1,14 @@ -import { ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from "./index"; +import { + ProvingKey, + VerifyingKey, + CREDITS_PROGRAM_KEYS, + KEY_STORE, + PRIVATE_TRANSFER, + PRIVATE_TO_PUBLIC_TRANSFER, + PUBLIC_TRANSFER, + PUBLIC_TO_PRIVATE_TRANSFER, + PUBLIC_TRANSFER_AS_SIGNER +} from "./index"; import { get } from "./utils"; type FunctionKeyPair = [ProvingKey, VerifyingKey]; @@ -52,6 +62,12 @@ interface FunctionKeyProvider { */ bondPublicKeys(): Promise; + /** + * Get bond_validator function keys from the credits.aleo program + * + * @returns {Promise} Proving and verifying keys for the bond_validator function + */ + bondValidatorKeys(): Promise; /** * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId @@ -351,7 +367,7 @@ class AleoKeyProvider implements FunctionKeyProvider { * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually @@ -394,6 +410,10 @@ class AleoKeyProvider implements FunctionKeyProvider { return this.fetchKeys(CREDITS_PROGRAM_KEYS.bond_public.prover, CREDITS_PROGRAM_KEYS.bond_public.verifier, CREDITS_PROGRAM_KEYS.bond_public.locator) } + bondValidatorKeys(): Promise { + return this.fetchKeys(CREDITS_PROGRAM_KEYS.bond_validator.prover, CREDITS_PROGRAM_KEYS.bond_validator.verifier, CREDITS_PROGRAM_KEYS.bond_validator.locator) + } + claimUnbondPublicKeys(): Promise { return this.fetchKeys(CREDITS_PROGRAM_KEYS.claim_unbond_public.prover, CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier, CREDITS_PROGRAM_KEYS.claim_unbond_public.locator) } @@ -405,12 +425,12 @@ class AleoKeyProvider implements FunctionKeyProvider { * * @example * // Create a new AleoKeyProvider - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually @@ -423,6 +443,8 @@ class AleoKeyProvider implements FunctionKeyProvider { return await this.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_private_to_public.prover, CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifier, CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator); } else if (PUBLIC_TRANSFER.has(visibility)) { return await this.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_public.prover, CREDITS_PROGRAM_KEYS.transfer_public.verifier, CREDITS_PROGRAM_KEYS.transfer_public.locator); + } else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) { + return await this.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_public_as_signer.prover, CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifier, CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator); } else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) { return await this.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_public_to_private.prover, CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifier, CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator); } else { @@ -476,6 +498,8 @@ class AleoKeyProvider implements FunctionKeyProvider { switch (verifierUri) { case CREDITS_PROGRAM_KEYS.bond_public.verifier: return CREDITS_PROGRAM_KEYS.bond_public.verifyingKey(); + case CREDITS_PROGRAM_KEYS.bond_validator.verifier: + return CREDITS_PROGRAM_KEYS.bond_validator.verifyingKey(); case CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier: return CREDITS_PROGRAM_KEYS.claim_unbond_public.verifyingKey(); case CREDITS_PROGRAM_KEYS.fee_private.verifier: @@ -496,10 +520,10 @@ class AleoKeyProvider implements FunctionKeyProvider { return CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifyingKey(); case CREDITS_PROGRAM_KEYS.transfer_public.verifier: return CREDITS_PROGRAM_KEYS.transfer_public.verifyingKey(); + case CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifier: + return CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifyingKey(); case CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifier: return CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifyingKey(); - case CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.verifier: - return CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.verifyingKey(); case CREDITS_PROGRAM_KEYS.unbond_public.verifier: return CREDITS_PROGRAM_KEYS.unbond_public.verifyingKey(); default: diff --git a/sdk/src/index.ts b/sdk/src/index.ts index 249c8ee8a..ddf3d4d28 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -27,6 +27,7 @@ function convert(metadata: Metadata): Key { const CREDITS_PROGRAM_KEYS = { bond_public: convert(Metadata.bond_public()), + bond_validator: convert(Metadata.bond_validator()), claim_unbond_public: convert(Metadata.claim_unbond_public()), fee_private: convert(Metadata.fee_private()), fee_public: convert(Metadata.fee_public()), @@ -37,8 +38,8 @@ const CREDITS_PROGRAM_KEYS = { transfer_private: convert(Metadata.transfer_private()), transfer_private_to_public: convert(Metadata.transfer_private_to_public()), transfer_public: convert(Metadata.transfer_public()), + transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()), transfer_public_to_private: convert(Metadata.transfer_public_to_private()), - unbond_delegator_as_validator: convert(Metadata.unbond_delegator_as_validator()), unbond_public: convert(Metadata.unbond_public()), }; @@ -58,10 +59,14 @@ const VALID_TRANSFER_TYPES = new Set([ "privateToPublic", "transferPrivateToPublic", "transfer_public", + "transfer_public_as_signer", "public", + "public_as_signer", "transferPublic", + "transferPublicAsSigner", "transfer_public_to_private", "publicToPrivate", + "publicAsSigner", "transferPublicToPrivate", ]); const PRIVATE_TRANSFER = new Set([ @@ -80,6 +85,11 @@ const PUBLIC_TRANSFER = new Set([ "transfer_public", "transferPublic", ]); +const PUBLIC_TRANSFER_AS_SIGNER = new Set([ + "public_as_signer", + "transfer_public_as_signer", + "transferPublicAsSigner", +]); const PUBLIC_TO_PRIVATE_TRANSFER = new Set([ "public_to_private", "publicToPrivate", @@ -181,6 +191,7 @@ export { PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, + PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, VALID_TRANSFER_TYPES, logAndThrow, diff --git a/sdk/src/offline-key-provider.ts b/sdk/src/offline-key-provider.ts index 0a1eb8fe9..b8b404ea4 100644 --- a/sdk/src/offline-key-provider.ts +++ b/sdk/src/offline-key-provider.ts @@ -1,4 +1,17 @@ -import { FunctionKeyProvider, KeySearchParams, FunctionKeyPair, CachedKeyPair, ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from "./index"; +import { + FunctionKeyProvider, + KeySearchParams, + FunctionKeyPair, + CachedKeyPair, + ProvingKey, + VerifyingKey, + CREDITS_PROGRAM_KEYS, + PRIVATE_TRANSFER, + PRIVATE_TO_PUBLIC_TRANSFER, + PUBLIC_TRANSFER, + PUBLIC_TO_PRIVATE_TRANSFER, + PUBLIC_TRANSFER_AS_SIGNER +} from "./index"; /** * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes @@ -9,7 +22,7 @@ import { FunctionKeyProvider, KeySearchParams, FunctionKeyPair, CachedKeyPair, P * offlineSearchParams = new OfflineSearchParams("myprogram.aleo/myfunction"); * * // If storing a key for a credits.aleo program function - * unbondDelegatorAsValidatorSearchParams = OfflineSearchParams.unbondDelegatorAsValidatorKeyParams(); + * bondPublicKeyParams = OfflineSearchParams.bondPublicKeyParams(); */ class OfflineSearchParams implements KeySearchParams { cacheKey: string | undefined; @@ -35,6 +48,13 @@ class OfflineSearchParams implements KeySearchParams { return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_public.locator, true); } + /** + * Create a new OfflineSearchParams instance for the bond_validator function of the credits.aleo program. + */ + static bondValidatorKeyParams(): OfflineSearchParams { + return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_validator.locator, true); + } + /** * Create a new OfflineSearchParams instance for the claim_unbond_public function of the */ @@ -106,21 +126,21 @@ class OfflineSearchParams implements KeySearchParams { } /** - * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program. + * Create a new OfflineSearchParams instance for the transfer_public_as_signer function of the credits.aleo program. */ - static transferPublicToPrivateKeyParams(): OfflineSearchParams { - return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, true); + static transferPublicAsSignerKeyParams(): OfflineSearchParams { + return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator, true); } /** - * Create a new OfflineSearchParams instance for the unbond_delegator_as_validator function of the credits.aleo program. + * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program. */ - static unbondDelegatorAsValidatorKeyParams(): OfflineSearchParams { - return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.locator, true); + static transferPublicToPrivateKeyParams(): OfflineSearchParams { + return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, true); } /** - * Create a new OfflineSearchParams instance for the unbond_delegator function of the credits.aleo program. + * Create a new OfflineSearchParams instance for the unbond_public function of the credits.aleo program. */ static unbondPublicKeyParams(): OfflineSearchParams { return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.unbond_public.locator, true); @@ -195,6 +215,16 @@ class OfflineKeyProvider implements FunctionKeyProvider { return this.functionKeys(OfflineSearchParams.bondPublicKeyParams()); }; + /** + * Get bond_validator function keys from the credits.aleo program. The keys must be cached prior to calling this + * method for it to work. + * + * @returns {Promise} Proving and verifying keys for the bond_public function + */ + bondValidatorKeys(): Promise { + return this.functionKeys(OfflineSearchParams.bondValidatorKeyParams()); + }; + /** * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId @@ -298,8 +328,6 @@ class OfflineKeyProvider implements FunctionKeyProvider { return provingKey.isTransferPublicProver() && verifyingKey.isTransferPublicVerifier(); case CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator: return provingKey.isTransferPublicToPrivateProver() && verifyingKey.isTransferPublicToPrivateVerifier(); - case CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.locator: - return provingKey.isUnbondDelegatorAsValidatorProver() && verifyingKey.isUnbondDelegatorAsValidatorVerifier(); case CREDITS_PROGRAM_KEYS.unbond_public.locator: return provingKey.isUnbondPublicProver() && verifyingKey.isUnbondPublicVerifier(); default: @@ -376,6 +404,8 @@ class OfflineKeyProvider implements FunctionKeyProvider { return this.functionKeys(OfflineSearchParams.transferPrivateToPublicKeyParams()); } else if (PUBLIC_TRANSFER.has(visibility)) { return this.functionKeys(OfflineSearchParams.transferPublicKeyParams()); + } else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) { + return this.functionKeys(OfflineSearchParams.transferPublicAsSignerKeyParams()); } else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) { return this.functionKeys(OfflineSearchParams.transferPublicToPrivateKeyParams()); } else { @@ -557,14 +587,6 @@ class OfflineKeyProvider implements FunctionKeyProvider { } } - insertUnbondDelegatorAsValidatorKeys(provingKey: ProvingKey) { - if (provingKey.isUnbondDelegatorAsValidatorProver()) { - this.cache.set(CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.locator, [provingKey.toBytes(), VerifyingKey.unbondDelegatorAsValidatorVerifier().toBytes()]); - } else { - throw new Error("Attempted to insert invalid proving keys for unbond_delegator_as_validator"); - } - } - insertUnbondPublicKeys(provingKey: ProvingKey) { if (provingKey.isUnbondPublicProver()) { this.cache.set(CREDITS_PROGRAM_KEYS.unbond_public.locator, [provingKey.toBytes(), VerifyingKey.unbondPublicVerifier().toBytes()]); diff --git a/sdk/src/program-manager.ts b/sdk/src/program-manager.ts index a8a2ac8de..bf737514e 100644 --- a/sdk/src/program-manager.ts +++ b/sdk/src/program-manager.ts @@ -223,13 +223,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * keyProvider.useCache = true; * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * * // Build and execute the transaction * const transaction = await programManager.buildExecutionTransaction({ @@ -330,13 +330,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * keyProvider.useCache = true; * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * * // Build and execute the transaction * const transaction = await programManager.execute({ @@ -502,13 +502,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}" * const tx_id = await programManager.split(25000000, record); * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -597,6 +597,7 @@ class ProgramManager { * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate' * @param {number} fee The fee to pay for the transfer * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance + * @param {string | undefined} caller The caller of the function (if calling transfer_public) * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee * records for the transfer transaction * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer @@ -607,13 +608,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * await programManager.initialize(); * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2) * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -624,6 +625,7 @@ class ProgramManager { transferType: string, fee: number, privateFee: boolean, + caller?: string, recordSearchParams?: RecordSearchParams, amountRecord?: RecordPlaintext | string, feeRecord?: RecordPlaintext | string, @@ -672,13 +674,14 @@ class ProgramManager { } // Build an execution transaction and submit it to the network - return await WasmProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, fee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery); + return await WasmProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, caller, amountRecord, fee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery); } /** * Build a transfer_public transaction to transfer credits to another account for later submission to the Aleo network * * @param {number} amount The amount of credits to transfer + * @param {string} caller The caller of the transfer (may be different from the signer) * @param {string} recipient The recipient of the transfer * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate' * @param {number} fee The fee to pay for the transfer @@ -690,28 +693,42 @@ class ProgramManager { * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment * @returns {Promise} The transaction id of the transfer transaction - * - * @example - * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); - * const keyProvider = new AleoKeyProvider(); - * const recordProvider = new NetworkRecordProvider(account, networkClient); - * - * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); - * await programManager.initialize(); - * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2) - * const transaction = await programManager.networkClient.getTransaction(tx_id); */ async buildTransferPublicTransaction( + amount: number, + caller: string, + recipient: string, + fee: number, + privateKey?: PrivateKey, + offlineQuery?: OfflineQuery + ): Promise { + return this.buildTransferTransaction(amount, recipient, "public", fee, false, caller, undefined, undefined, undefined, privateKey, offlineQuery); + } + + /** + * Build a transfer_public_as_signer transaction to transfer credits to another account for later submission to the Aleo network + * + * @param {number} amount The amount of credits to transfer + * @param {string} recipient The recipient of the transfer + * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate' + * @param {number} fee The fee to pay for the transfer + * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance + * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee + * records for the transfer transaction + * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer + * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer + * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction + * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment + * @returns {Promise} The transaction id of the transfer transaction + */ + async buildTransferPublicAsSignerTransaction( amount: number, recipient: string, fee: number, privateKey?: PrivateKey, offlineQuery?: OfflineQuery ): Promise { - return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery); + return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, undefined, privateKey, offlineQuery); } /** @@ -722,6 +739,7 @@ class ProgramManager { * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate' * @param {number} fee The fee to pay for the transfer * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance + * @param {string | undefined} caller The caller of the function (if calling transfer_public) * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee * records for the transfer transaction * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer @@ -732,13 +750,12 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://vm.aleo.org/api"); + * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://vm.aleo.org/api", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); * await programManager.initialize(); * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2) * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -749,18 +766,19 @@ class ProgramManager { transferType: string, fee: number, privateFee: boolean, + caller?: string, recordSearchParams?: RecordSearchParams, amountRecord?: RecordPlaintext | string, feeRecord?: RecordPlaintext | string, privateKey?: PrivateKey, offlineQuery?: OfflineQuery ): Promise { - const tx = await this.buildTransferTransaction(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery); + const tx = await this.buildTransferTransaction(amount, recipient, transferType, fee, privateFee, caller, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery); return await this.networkClient.submitTransaction(tx); } /** - * Build transaction to bond credits to a staking committee for later submission to the Aleo Network + * Build transaction to bond credits to a validator for later submission to the Aleo Network * * @example * // Create a keyProvider to handle key management @@ -771,19 +789,25 @@ class ProgramManager { * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * - * // Create the bonding transaction - * const tx_id = await programManager.bondPublic("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 2000000); + * // Create the bonding transaction object for later submission + * const tx = await programManager.buildBondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000); + * console.log(tx); + * + * // The transaction can be later submitted to the network using the network client. + * const result = await programManager.networkClient.submitTransaction(tx); * * @returns string - * @param {string} address Address of the validator to bond to, if this address is the same as the signer (i.e. the + * @param {string} staker_address Address of the staker who is bonding the credits + * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently - * requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing + * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing * validator and is different from the address of the executor of this function, it will bond the credits to that * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator. + * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called. * @param {number} amount The amount of credits to bond * @param {Partial} options - Override default execution options. */ - async buildBondPublicTransaction(address: string, amount: number, options: Partial = {}) { + async buildBondPublicTransaction(staker_address: string, validator_address: string, withdrawal_address: string, amount: number, options: Partial = {}) { const scaledAmount = Math.trunc(amount * 1000000); const { @@ -791,7 +815,7 @@ class ProgramManager { functionName = "bond_public", fee = options.fee || 0.86, privateFee = false, - inputs = [address, `${scaledAmount.toString()}u64`], + inputs = [staker_address, validator_address, withdrawal_address, `${scaledAmount.toString()}u64`], keySearchParams = new AleoKeyProviderParams({ proverUri: CREDITS_PROGRAM_KEYS.bond_public.prover, verifierUri: CREDITS_PROGRAM_KEYS.bond_public.verifier, @@ -815,7 +839,7 @@ class ProgramManager { } /** - * Bond credits to a staking committee + * Bond credits to validator. * * @example * // Create a keyProvider to handle key management @@ -827,35 +851,140 @@ class ProgramManager { * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction - * const tx_id = await programManager.bondPublic("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 2000000); + * const tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000); * * @returns string - * @param {string} address Address of the validator to bond to, if this address is the same as the signer (i.e. the + * @param {string} staker_address Address of the staker who is bonding the credits + * @param {string} validator_address Address of the validator to bond to, if this address is the same as the signer (i.e. the * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently * requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing * validator and is different from the address of the executor of this function, it will bond the credits to that * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator. + * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called. * @param {number} amount The amount of credits to bond * @param {Options} options Options for the execution */ - async bondPublic(address: string, amount: number, options: Partial = {}) { - const tx = await this.buildBondPublicTransaction(address, amount, options); + async bondPublic(staker_address: string, validator_address: string, withdrawal_address:string, amount: number, options: Partial = {}) { + const tx = await this.buildBondPublicTransaction(staker_address, validator_address, withdrawal_address, amount, options); + return await this.networkClient.submitTransaction(tx); + } + + /** + * Build a bond_validator transaction for later submission to the Aleo Network. + * + * @example + * // Create a keyProvider to handle key management + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to bond credits + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * programManager.setAccount(new Account("YourPrivateKey")); + * + * // Create the bond validator transaction object for later use. + * const tx = await programManager.buildBondValidatorTransaction("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000); + * console.log(tx); + * + * // The transaction can later be submitted to the network using the network client. + * const tx_id = await programManager.networkClient.submitTransaction(tx); + * + * @returns string + * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the + * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently + * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing + * validator and is different from the address of the executor of this function, it will bond the credits to that + * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator. + * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called. + * @param {number} amount The amount of credits to bond + * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not) + * @param {Partial} options - Override default execution options. + */ + async buildBondValidatorTransaction(validator_address: string, withdrawal_address: string, amount: number, commission: number, options: Partial = {}) { + const scaledAmount = Math.trunc(amount * 1000000); + + const adjustedCommission = Math.trunc(commission) + + const { + programName = "credits.aleo", + functionName = "bond_validator", + fee = options.fee || 0.86, + privateFee = false, + inputs = [validator_address, withdrawal_address, `${scaledAmount.toString()}u64`, `${adjustedCommission.toString()}u8`], + keySearchParams = new AleoKeyProviderParams({ + proverUri: CREDITS_PROGRAM_KEYS.bond_validator.prover, + verifierUri: CREDITS_PROGRAM_KEYS.bond_validator.verifier, + cacheKey: "credits.aleo/bond_validator" + }), + program = this.creditsProgram(), + ...additionalOptions + } = options; + + const executeOptions: ExecuteOptions = { + programName, + functionName, + fee, + privateFee, + inputs, + keySearchParams, + ...additionalOptions + }; + + return await this.buildExecutionTransaction(executeOptions); + } + + /** + * Build transaction to bond a validator. + * + * @example + * // Create a keyProvider to handle key management + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to bond credits + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * programManager.setAccount(new Account("YourPrivateKey")); + * + * // Create the bonding transaction + * const tx_id = await programManager.bondValidator("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000); + * + * @returns string + * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the + * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently + * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing + * validator and is different from the address of the executor of this function, it will bond the credits to that + * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator. + * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called. + * @param {number} amount The amount of credits to bond + * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not) + * @param {Partial} options - Override default execution options. + */ + async bondValidator(validator_address: string, withdrawal_address: string, amount: number, commission: number, options: Partial = {}) { + const tx = await this.buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options); return await this.networkClient.submitTransaction(tx); } /** - * Build a transaction to unbond public credits in the Aleo network. + * Build a transaction to unbond public credits from a validator in the Aleo network. * + * @param {string} staker_address - The address of the staker who is unbonding the credits. * @param {number} amount - The amount of credits to unbond (scaled by 1,000,000). * @param {Partial} options - Override default execution options. * @returns {Promise} - A promise that resolves to the transaction or an error message. * * @example + * // Create a keyProvider to handle key management. + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to unbond credits. * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); - * const transaction = await programManager.buildUnbondPublicTransaction(2000000); - * console.log(transaction); + * const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000); + * console.log(tx); + * + * // The transaction can be submitted later to the network using the network client. + * programManager.networkClient.submitTransaction(tx); */ - async buildUnbondPublicTransaction(amount: number, options: Partial = {}): Promise { + async buildUnbondPublicTransaction(staker_address: string, amount: number, options: Partial = {}): Promise { const scaledAmount = Math.trunc(amount * 1000000); const { @@ -863,7 +992,7 @@ class ProgramManager { functionName = "unbond_public", fee = options.fee || 1.3, privateFee = false, - inputs = [`${scaledAmount.toString()}u64`], + inputs = [staker_address, `${scaledAmount.toString()}u64`], keySearchParams = new AleoKeyProviderParams({ proverUri: CREDITS_PROGRAM_KEYS.unbond_public.prover, verifierUri: CREDITS_PROGRAM_KEYS.unbond_public.verifier, @@ -887,7 +1016,7 @@ class ProgramManager { } /** - * Unbond a specified amount of staked credits to be used later + * Unbond a specified amount of staked credits. * * @example * // Create a keyProvider to handle key management @@ -898,41 +1027,53 @@ class ProgramManager { * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * - * // Create the bonding transaction - * const tx_id = await programManager.unbondPublic(10); + * // Create the bonding transaction and send it to the network + * const tx_id = await programManager.unbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 10); * * @returns string + * @param {string} staker_address Address of the staker who is unbonding the credits * @param {number} amount Amount of credits to unbond. If the address of the executor of this function is an * existing validator, it will subtract this amount of credits from the validator's staked credits. If there are * less than 1,000,000 credits staked pool after the unbond, the validator will be removed from the validator set. * If the address of the executor of this function is not a validator and has credits bonded as a delegator, it will * subtract this amount of credits from the delegator's staked credits. If there are less than 10 credits bonded * after the unbond operation, the delegator will be removed from the validator's staking pool. - * @param {Options} options Options for the execution + * @param {ExecuteOptions} options Options for the execution */ - async unbondPublic(amount: number, options: Partial = {}): Promise { - const tx = await this.buildUnbondPublicTransaction(amount, options); + async unbondPublic(staker_address: string, amount: number, options: Partial = {}): Promise { + const tx = await this.buildUnbondPublicTransaction(staker_address, amount, options); return await this.networkClient.submitTransaction(tx); } /** * Build a transaction to claim unbonded public credits in the Aleo network. * + * @param {string} staker_address - The address of the staker who is claiming the credits. * @param {Partial} options - Override default execution options. * @returns {Promise} - A promise that resolves to the transaction or an error message. * * @example + * // Create a keyProvider to handle key management + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to claim unbonded credits. * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); - * const transaction = await programManager.buildClaimUnbondPublicTransaction(); - * console.log(transaction); + * + * // Create the claim unbonded transaction object for later use. + * const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j"); + * console.log(tx); + * + * // The transaction can be submitted later to the network using the network client. + * programManager.networkClient.submitTransaction(tx); */ - async buildClaimUnbondPublicTransaction(options: Partial = {}): Promise { + async buildClaimUnbondPublicTransaction(staker_address: string, options: Partial = {}): Promise { const { programName = "credits.aleo", functionName = "claim_unbond_public", fee = options.fee || 2, privateFee = false, - inputs = [], + inputs = [staker_address], keySearchParams = new AleoKeyProviderParams({ proverUri: CREDITS_PROGRAM_KEYS.claim_unbond_public.prover, verifierUri: CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier, @@ -969,23 +1110,48 @@ class ProgramManager { * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction - * const tx_id = await programManager.claimUnbondPublic(); + * const tx_id = await programManager.claimUnbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j"); * + * @param {string} staker_address Address of the staker who is claiming the credits + * @param {ExecuteOptions} options * @returns string - * @param {Options} options */ - async claimUnbondPublic(options: Partial = {}): Promise { - const tx = await this.buildClaimUnbondPublicTransaction(options); + async claimUnbondPublic(staker_address: string, options: Partial = {}): Promise { + const tx = await this.buildClaimUnbondPublicTransaction(staker_address, options); return await this.networkClient.submitTransaction(tx); } /** - * Set Validator State + * Build a set_validator_state transaction for later usage. + * + * This function allows a validator to set their state to be either opened or closed to new stakers. + * When the validator is open to new stakers, any staker (including the validator) can bond or unbond from the validator. + * When the validator is closed to new stakers, existing stakers can still bond or unbond from the validator, but new stakers cannot bond. + * + * This function serves two primary purposes: + * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers. + * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them. + * + * @example + * // Create a keyProvider to handle key management + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to bond credits + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * programManager.setAccount(new Account("ValidatorPrivateKey")); + * + * // Create the bonding transaction + * const tx = await programManager.buildSetValidatorStateTransaction(true); + * + * // The transaction can be submitted later to the network using the network client. + * programManager.networkClient.submitTransaction(tx); + * * @returns string * @param {boolean} validator_state * @param {Partial} options - Override default execution options */ - async setValidatorState(validator_state: boolean, options: Partial = {}) { + async buildSetValidatorStateTransaction(validator_state: boolean, options: Partial = {}) { const { programName = "credits.aleo", functionName = "set_validator_state", @@ -1014,41 +1180,37 @@ class ProgramManager { } /** - * Unbond Delegator As Validator - * @returns {Promise} A promise that resolves to the transaction ID or an error message. - * @param {string} address - The address of the delegator. - * @param {Partial} options - Override default execution options. + * Submit a set_validator_state transaction to the Aleo Network. + * + * This function allows a validator to set their state to be either opened or closed to new stakers. + * When the validator is open to new stakers, any staker (including the validator) can bond or unbond from the validator. + * When the validator is closed to new stakers, existing stakers can still bond or unbond from the validator, but new stakers cannot bond. + * + * This function serves two primary purposes: + * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers. + * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them. + * + * @example + * // Create a keyProvider to handle key management + * const keyProvider = new AleoKeyProvider(); + * keyProvider.useCache = true; + * + * // Create a new ProgramManager with the key that will be used to bond credits + * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * programManager.setAccount(new Account("ValidatorPrivateKey")); + * + * // Create the bonding transaction + * const tx_id = await programManager.setValidatorState(true); + * + * @returns string + * @param {boolean} validator_state + * @param {Partial} options - Override default execution options */ - async unbondDelegatorAsValidator(address: string, options: Partial = {}) { - const { - programName = "credits.aleo", - functionName = "unbond_delegator_as_validator", - fee = 1, - privateFee = false, - inputs = [address], - keySearchParams = new AleoKeyProviderParams({ - proverUri: CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.prover, - verifierUri: CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.verifier, - cacheKey: "credits.aleo/unbond_delegator_as_validator" - }), - ...additionalOptions - } = options; - - const executeOptions: ExecuteOptions = { - programName, - functionName, - fee, - privateFee, - inputs, - keySearchParams, - ...additionalOptions - }; - - return await this.execute(executeOptions); + async setValidatorState(validator_state: boolean, options: Partial = {}) { + const tx = await this.buildSetValidatorStateTransaction(validator_state, options); + return this.networkClient.submitTransaction(tx); } - - /** * Verify a proof of execution from an offline execution * diff --git a/sdk/tests/key-provider.test.ts b/sdk/tests/key-provider.test.ts index 50e69b838..30acb20d8 100644 --- a/sdk/tests/key-provider.test.ts +++ b/sdk/tests/key-provider.test.ts @@ -62,7 +62,6 @@ describe('KeyProvider', () => { const [transferPrivateToPublicProver, transferPrivateToPublicVerifier] = await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_private_to_public.prover, CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifier, CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator); const [transferPublicProver, transferPublicVerifier] = await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_public.prover, CREDITS_PROGRAM_KEYS.transfer_public.verifier, CREDITS_PROGRAM_KEYS.transfer_public.locator); const [transferPublicToPrivateProver, transferPublicToPrivateVerifier] = await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.transfer_public_to_private.prover, CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifier, CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator); - const [unbondDelegatorAsValidatorProver, unbondDelegatorAsValidatorVerifier] = await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.prover, CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.verifier, CREDITS_PROGRAM_KEYS.unbond_delegator_as_validator.locator); const [unbondPublicProver, unbondPublicVerifier] = await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.unbond_public.prover, CREDITS_PROGRAM_KEYS.unbond_public.verifier, CREDITS_PROGRAM_KEYS.unbond_public.locator); // Ensure the insertion methods work as expected without throwing an exception @@ -77,7 +76,6 @@ describe('KeyProvider', () => { offlineKeyProvider.insertTransferPrivateToPublicKeys(transferPrivateToPublicProver); offlineKeyProvider.insertTransferPublicKeys(transferPublicProver); offlineKeyProvider.insertTransferPublicToPrivateKeys(transferPublicToPrivateProver); - offlineKeyProvider.insertUnbondDelegatorAsValidatorKeys(unbondDelegatorAsValidatorProver); offlineKeyProvider.insertUnbondPublicKeys(unbondPublicProver); // Ensure the offline key provider methods for credits.aleo return the correct keys diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 1e245b5a2..53765fbfb 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -1539,7 +1539,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -1570,7 +1570,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -1584,7 +1584,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-network", @@ -1595,7 +1595,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-types", "snarkvm-console-algorithms", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-types", @@ -1615,7 +1615,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "itertools", @@ -1633,12 +1633,12 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" [[package]] name = "snarkvm-circuit-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -1649,7 +1649,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "paste", "snarkvm-circuit-account", @@ -1664,7 +1664,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -1679,7 +1679,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1692,7 +1692,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-console-types-boolean", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1711,7 +1711,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1735,7 +1735,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1746,7 +1746,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1758,7 +1758,7 @@ dependencies = [ [[package]] name = "snarkvm-console" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -1771,7 +1771,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bs58", "snarkvm-console-network", @@ -1782,7 +1782,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "blake2s_simd", "smallvec", @@ -1795,7 +1795,7 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "rayon", @@ -1806,7 +1806,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "indexmap", @@ -1829,7 +1829,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "bech32", @@ -1847,7 +1847,7 @@ dependencies = [ [[package]] name = "snarkvm-console-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "enum-iterator", "enum_index", @@ -1869,7 +1869,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-address", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1895,7 +1895,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", ] @@ -1903,7 +1903,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1913,7 +1913,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1924,7 +1924,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1935,7 +1935,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1946,7 +1946,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1957,7 +1957,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "rand", "rayon", @@ -1971,7 +1971,7 @@ dependencies = [ [[package]] name = "snarkvm-fields" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -1988,7 +1988,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "rand", @@ -2000,7 +2000,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "rayon", @@ -2019,7 +2019,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "rayon", @@ -2031,7 +2031,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "rayon", @@ -2044,7 +2044,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "rayon", @@ -2056,7 +2056,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "rayon", @@ -2071,7 +2071,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console", "snarkvm-ledger-puzzle", @@ -2080,7 +2080,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -2100,22 +2100,28 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle-epoch" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ + "aleo-std", "anyhow", "colored", "indexmap", + "lru", + "parking_lot", "rand", "rand_chacha", "rayon", + "snarkvm-circuit", "snarkvm-console", "snarkvm-ledger-puzzle", + "snarkvm-synthesizer-process", + "snarkvm-synthesizer-program", ] [[package]] name = "snarkvm-ledger-query" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "async-trait", "reqwest", @@ -2128,7 +2134,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std-storage", "anyhow", @@ -2151,7 +2157,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -2179,7 +2185,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -2189,6 +2195,7 @@ dependencies = [ "parking_lot", "rand", "rayon", + "serde_json", "snarkvm-algorithms", "snarkvm-circuit", "snarkvm-console", @@ -2208,7 +2215,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "colored", @@ -2231,7 +2238,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap", "paste", @@ -2245,7 +2252,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bincode", "once_cell", @@ -2258,7 +2265,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -2279,7 +2286,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "proc-macro2", "quote 1.0.36", @@ -2289,7 +2296,7 @@ dependencies = [ [[package]] name = "snarkvm-wasm" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=f197796f23e5c7678d600a7ecfea4c31a6452dba#f197796f23e5c7678d600a7ecfea4c31a6452dba" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f7c5ef980f9392301dc899dee355599ca6#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "getrandom", "snarkvm-circuit-network", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 886bced5d..b9019ae8b 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -24,47 +24,47 @@ doctest = false [dependencies.snarkvm-circuit-network] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" [dependencies.snarkvm-console] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "wasm" ] [dependencies.snarkvm-ledger-block] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "wasm" ] [dependencies.snarkvm-ledger-query] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "async", "wasm" ] [dependencies.snarkvm-ledger-store] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" [dependencies.snarkvm-parameters] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "wasm" ] [dependencies.snarkvm-synthesizer] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "async", "wasm" ] [dependencies.snarkvm-wasm] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "f197796f23e5c7678d600a7ecfea4c31a6452dba" +rev = "d170a9f7c5ef980f9392301dc899dee355599ca6" features = [ "console", "fields", "utilities" ] [dependencies.anyhow] diff --git a/wasm/src/programs/manager/transfer.rs b/wasm/src/programs/manager/transfer.rs index 9df09ab2a..fe69bb160 100644 --- a/wasm/src/programs/manager/transfer.rs +++ b/wasm/src/programs/manager/transfer.rs @@ -63,6 +63,7 @@ impl ProgramManager { amount_credits: f64, recipient: &str, transfer_type: &str, + caller: Option, amount_record: Option, fee_credits: f64, fee_record: Option, @@ -113,10 +114,17 @@ impl ProgramManager { ("transfer_private_to_public", inputs) } "public" | "transfer_public" | "transferPublic" => { + let inputs = Array::new_with_length(3); + inputs.set(0u32, wasm_bindgen::JsValue::from_str(&caller.unwrap())); + inputs.set(1u32, wasm_bindgen::JsValue::from_str(recipient)); + inputs.set(2u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + ("transfer_public", inputs) + } + "public_as_signer" | "transfer_public_as_signer" | "transferPublicAsSigner" => { let inputs = Array::new_with_length(2); inputs.set(0u32, wasm_bindgen::JsValue::from_str(recipient)); inputs.set(1u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); - ("transfer_public", inputs) + ("transfer_public_as_signer", inputs) } "public_to_private" | "publicToPrivate" | "transfer_public_to_private" | "transferPublicToPrivate" => { let inputs = Array::new_with_length(2); diff --git a/wasm/src/programs/offline_query.rs b/wasm/src/programs/offline_query.rs index 2c343efb3..14f3e4cc9 100644 --- a/wasm/src/programs/offline_query.rs +++ b/wasm/src/programs/offline_query.rs @@ -99,14 +99,12 @@ impl QueryTrait for OfflineQuery { mod tests { use super::*; - use crate::RecordPlaintext; - use wasm_bindgen_test::*; const OFFLINE_QUERY: &str = r#"{"state_paths":{},"state_root":"sr1wjueje6hy86yw9j4lhl7jwvhjxwunw34paj4k3cn2wm5h5r2syfqd83yw4"}"#; - const RECORD: &str = "{ owner: aleo1rlwt9w0fl242h40w454m68vttd6vm4lmetu5r57unm5g354y9yzsyexf0y.private, microcredits: 1000000u64.private, _nonce: 2899260364216345893364017846447050369739821279831870104066405119445828210771group.public}"; - const RECORD_STATE_PATH: &str = "path1q96tnxt82uslg3ck2h7ll6fej7gemjd6x58k2k68zdfmwj7sd2q39u24qgqqqqqqqz8vhmupdu4wg3cv08ul4sjlz6je764cznh6ye9qkuc57272er7qzzy3nhhnyfxkvfs2m8zplzsxq2ctf2u5edwp0yavvyxsz54c99qrfs9aay3vhyecmc8f560glgmqv9c0awkg3upuj9rtm5u8t36dyyz7jsksttvfdkd75znvh6h83lqpq6q0eclym87t8ra2days24ew5racm54fffl3z4u2c29tzwykys7plxmct7khyuddgh6268ywgzyfzxe4uqm5svma27ptqccznezwmkj0vcpma3e9vu5lun96knvf5qus44sz5093p5wcdxwkjjr356knt65wjpnzpek2ad789req5e67rqqwrln54hlvhefl2xg36g6n2dn06k6l5jwn3y8xtlfg60wcr5huzvxluvc62x7sx74rpvjldq67v7fmtj0n3mvmczqg5dunz8aa7dumzpkehlddjk7gpjcn0fselmwx08ggf0vtfr4lvr6mpjycgtvfres5qwsgsu25xd27p23f4czqalhf3fhyvg4evwa2u4y27f2q59khvhjsfkqrr67gkw23s47vrmql5q0uk8cp63dpr4ttdehtq8rls0zmj2qvtns3uqeg2fann8e777nhmsddggxn3x67203309kngauujtuw0g8436902ggxze9cfprv8nh8n265phfls95ud9lfzwnvj80let33cpt2x5c5avy0czx3m5vv3ra8r0cw2f2e22dz72lzwkl3c5z8qfuupgs7xhpg42areg227kkflyhpn0cj260yhpeg567fkskljmv7zckqwz6rnk6l2yg7xpeyc3dy907wefjn5w35prnacapd4acn20qeldgwwmuev0d8t6tz02x2kv8qg9sxhakx6fmw5rd35fda735pchuct5gcg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyxqgy0ryzze4sllaq3hvhsk90h2qhx308xmfg63n740w6wjrk3qgl99r8gr9efj5yeddqdetk6n8cww9sawuhes4l5tan0zctne6n6px58ez93eujhk4qrreq9m0a9m54s93f4zvfa25k0a4w79gfl9grp5qsqqqqqqqqqqzr7mae3y6kkgqc3q3u2cte5vu328u7slgw9dnw9zu4x6uyvt5apykyzgq7g2pjq384shpxqvenrf2xzqpe6era69vcprljemjfu7rq98km83fkceft37tef3l5yd0u3d0vklnrre0xxus0x4cuy48dafs9q8a9z296cvk40q48sva0ndq7uhz4fk87xxrkku9x487afcaus0fpqqsqqqqqqqqqqzzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqgcnhf9dy704t3qcqwfz2zn23tyaax8uyfw9rflmz807edsq542qdss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfvfkqsgfjgwe874pq983afd72ptcv6hx664appmslfk2jptvjecdqqqqqqqqqqqqppq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqgqgqqzk3ftj0dmy8gphrl85l8cfgrf8vpzdflzw7zu4ppfnxsn3vv2wqvatgjpp5234t647yyh37w3jmz37yyur5c5cg4rxgpwjecnpm2xsrceze3ptsf2gw50t0zznhzx0an9ezz8zfa37kxkw8ucw7f3gwlvqsyqqqqqqqqqqq0ylf8je3k7c464x6fpcur8s7ju93yum7kyq0p6hjkqdg24smwsz9vllufwczy2t0v3elfsv5ymkh8rp34acu9cc0rhjut7d9x684cqvyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyqypq8m5dp6ejcmzg46vm4ng7xvxrya7dd4z5qam2afc8gclnkz50cgsgkwy6dt"; + //const RECORD: &str = "{ owner: aleo1rlwt9w0fl242h40w454m68vttd6vm4lmetu5r57unm5g354y9yzsyexf0y.private, microcredits: 1000000u64.private, _nonce: 2899260364216345893364017846447050369739821279831870104066405119445828210771group.public}"; + //const RECORD_STATE_PATH: &str = "path1q96tnxt82uslg3ck2h7ll6fej7gemjd6x58k2k68zdfmwj7sd2q39u24qgqqqqqqqz8vhmupdu4wg3cv08ul4sjlz6je764cznh6ye9qkuc57272er7qzzy3nhhnyfxkvfs2m8zplzsxq2ctf2u5edwp0yavvyxsz54c99qrfs9aay3vhyecmc8f560glgmqv9c0awkg3upuj9rtm5u8t36dyyz7jsksttvfdkd75znvh6h83lqpq6q0eclym87t8ra2days24ew5racm54fffl3z4u2c29tzwykys7plxmct7khyuddgh6268ywgzyfzxe4uqm5svma27ptqccznezwmkj0vcpma3e9vu5lun96knvf5qus44sz5093p5wcdxwkjjr356knt65wjpnzpek2ad789req5e67rqqwrln54hlvhefl2xg36g6n2dn06k6l5jwn3y8xtlfg60wcr5huzvxluvc62x7sx74rpvjldq67v7fmtj0n3mvmczqg5dunz8aa7dumzpkehlddjk7gpjcn0fselmwx08ggf0vtfr4lvr6mpjycgtvfres5qwsgsu25xd27p23f4czqalhf3fhyvg4evwa2u4y27f2q59khvhjsfkqrr67gkw23s47vrmql5q0uk8cp63dpr4ttdehtq8rls0zmj2qvtns3uqeg2fann8e777nhmsddggxn3x67203309kngauujtuw0g8436902ggxze9cfprv8nh8n265phfls95ud9lfzwnvj80let33cpt2x5c5avy0czx3m5vv3ra8r0cw2f2e22dz72lzwkl3c5z8qfuupgs7xhpg42areg227kkflyhpn0cj260yhpeg567fkskljmv7zckqwz6rnk6l2yg7xpeyc3dy907wefjn5w35prnacapd4acn20qeldgwwmuev0d8t6tz02x2kv8qg9sxhakx6fmw5rd35fda735pchuct5gcg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyxqgy0ryzze4sllaq3hvhsk90h2qhx308xmfg63n740w6wjrk3qgl99r8gr9efj5yeddqdetk6n8cww9sawuhes4l5tan0zctne6n6px58ez93eujhk4qrreq9m0a9m54s93f4zvfa25k0a4w79gfl9grp5qsqqqqqqqqqqzr7mae3y6kkgqc3q3u2cte5vu328u7slgw9dnw9zu4x6uyvt5apykyzgq7g2pjq384shpxqvenrf2xzqpe6era69vcprljemjfu7rq98km83fkceft37tef3l5yd0u3d0vklnrre0xxus0x4cuy48dafs9q8a9z296cvk40q48sva0ndq7uhz4fk87xxrkku9x487afcaus0fpqqsqqqqqqqqqqzzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqgcnhf9dy704t3qcqwfz2zn23tyaax8uyfw9rflmz807edsq542qdss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfvfkqsgfjgwe874pq983afd72ptcv6hx664appmslfk2jptvjecdqqqqqqqqqqqqppq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyss2eafg236dqunyghdd0p7pttvey0765ry52vccqmlp859j9tgzgg9v7559gaxswfjytkkhslq44kvj8ld2pj29xvvqdlsn6zez45pyyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqgqgqqzk3ftj0dmy8gphrl85l8cfgrf8vpzdflzw7zu4ppfnxsn3vv2wqvatgjpp5234t647yyh37w3jmz37yyur5c5cg4rxgpwjecnpm2xsrceze3ptsf2gw50t0zznhzx0an9ezz8zfa37kxkw8ucw7f3gwlvqsyqqqqqqqqqqq0ylf8je3k7c464x6fpcur8s7ju93yum7kyq0p6hjkqdg24smwsz9vllufwczy2t0v3elfsv5ymkh8rp34acu9cc0rhjut7d9x684cqvyzk022z5wng8yez9mttc0s26mxfrlk4qe9znxxqxlcfapv326qjzpt849p28f5rjv3za44u8c9ddny3lm2svj3fnrqr0uy7skg4dqfpq4n6js4r56pexg3w667ruzkkejgla4gxfg5e3sph7z0gty2ksyqypq8m5dp6ejcmzg46vm4ng7xvxrya7dd4z5qam2afc8gclnkz50cgsgkwy6dt"; const STATE_ROOT: &str = "sr1wjueje6hy86yw9j4lhl7jwvhjxwunw34paj4k3cn2wm5h5r2syfqd83yw4"; #[wasm_bindgen_test] diff --git a/wasm/src/programs/program.rs b/wasm/src/programs/program.rs index 81e26eee1..f40b0465e 100644 --- a/wasm/src/programs/program.rs +++ b/wasm/src/programs/program.rs @@ -579,6 +579,11 @@ function add_and_double: "key_type": "address", "value_type": "committee_state", }, + object! { + "name": "delegated", + "key_type": "address", + "value_type": "u64", + }, object! { "name": "metadata", "key_type": "address", diff --git a/wasm/src/programs/proving_key/credits.rs b/wasm/src/programs/proving_key/credits.rs index 8e8c31600..45ff7b573 100644 --- a/wasm/src/programs/proving_key/credits.rs +++ b/wasm/src/programs/proving_key/credits.rs @@ -36,6 +36,18 @@ impl ProvingKey { self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::BondPublicProver::METADATA) } + /// Verify if the proving key is for the bond_validator function + /// + /// @example + /// const provingKey = ProvingKey.fromBytes("bond_validator_proving_key.bin"); + /// provingKey.isBondPublicProver() ? console.log("Key verified") : throw new Error("Invalid key"); + /// + /// @returns {boolean} returns true if the proving key is for the bond_validator function, false if otherwise + #[wasm_bindgen(js_name = "isBondValidatorProver")] + pub fn is_bond_validator_prover(&self) -> bool { + self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::BondValidatorProver::METADATA) + } + /// Verify if the proving key is for the claim_unbond function /// /// @example @@ -157,6 +169,19 @@ impl ProvingKey { self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicProver::METADATA) } + /// Verify if the proving key is for the transfer_public_as_signer function + /// + /// @example + /// const provingKey = ProvingKey.fromBytes("transfer_public_as_signer_proving_key.bin"); + /// provingKey.isTransferPublicAsSignerProver() ? console.log("Key verified") : throw new Error("Invalid key"); + /// + /// @returns {boolean} returns true if the proving key is for the transfer_public function, false if otherwise + #[wasm_bindgen(js_name = "isTransferPublicAsSignerProver")] + pub fn is_transfer_public_as_signer_prover(&self) -> bool { + self.checksum() + == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicAsSignerProver::METADATA) + } + /// Verify if the proving key is for the transfer_public_to_private function /// /// @example @@ -170,26 +195,13 @@ impl ProvingKey { == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicToPrivateProver::METADATA) } - /// Verify if the proving key is for the unbond_delegator_as_validator function + /// Verify if the proving key is for the unbond_public function /// /// @example - /// const provingKey = ProvingKey.fromBytes("unbond_delegator_as_validator_proving_key.bin"); - /// provingKey.isUnbondDelegatorAsValidatorProver() ? console.log("Key verified") : throw new Error("Invalid key"); + /// const provingKey = ProvingKey.fromBytes("unbond_public.bin"); + /// provingKey.isUnbondPublicProver() ? console.log("Key verified") : throw new Error("Invalid key"); /// - /// @returns {boolean} returns true if the proving key is for the unbond_delegator_as_validator function, false if otherwise - #[wasm_bindgen(js_name = "isUnbondDelegatorAsValidatorProver")] - pub fn is_unbond_delegator_as_validator_prover(&self) -> bool { - self.checksum() - == ProvingKey::prover_checksum(snarkvm_parameters::testnet::UnbondDelegatorAsValidatorProver::METADATA) - } - - /// Verify if the proving key is for the unbond_delegator_as_delegator function - /// - /// @example - /// const provingKey = ProvingKey.fromBytes("unbond_delegator_as_delegator_proving_key.bin"); - /// provingKey.isUnbondDelegatorAsDelegatorProver() ? console.log("Key verified") : throw new Error("Invalid key"); - /// - /// @returns {boolean} returns true if the proving key is for the unbond_delegator_as_delegator function, false if otherwise + /// @returns {boolean} returns true if the proving key is for the unbond_public_prover function, false if otherwise #[wasm_bindgen(js_name = "isUnbondPublicProver")] pub fn is_unbond_public_prover(&self) -> bool { self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::UnbondPublicProver::METADATA) @@ -256,7 +268,6 @@ mod tests { let prover = ProvingKey::from_bytes(&proving_key_bytes).unwrap(); assert!(prover.is_set_validator_state_prover()); assert!(!prover.is_split_prover()); - sleep(DELAY).await; let prover_uri = Metadata::split().prover; @@ -264,7 +275,6 @@ mod tests { let prover = ProvingKey::from_bytes(&proving_key_bytes).unwrap(); assert!(prover.is_split_prover()); assert!(!prover.is_transfer_private_prover()); - sleep(DELAY).await; let prover_uri = Metadata::transfer_private().prover; @@ -295,16 +305,6 @@ mod tests { let proving_key_bytes = reqwest::get(prover_uri).await.unwrap().bytes().await.unwrap().to_vec(); let prover = ProvingKey::from_bytes(&proving_key_bytes).unwrap(); assert!(prover.is_transfer_public_to_private_prover()); - assert!(!prover.is_unbond_delegator_as_validator_prover()); - - sleep(DELAY).await; - - let prover_uri = Metadata::unbond_delegator_as_validator().prover; - let proving_key_bytes = reqwest::get(prover_uri).await.unwrap().bytes().await.unwrap().to_vec(); - let prover = ProvingKey::from_bytes(&proving_key_bytes).unwrap(); - assert!(prover.is_unbond_delegator_as_validator_prover()); - assert!(!prover.is_unbond_public_prover()); - sleep(DELAY).await; let prover_uri = Metadata::unbond_public().prover; diff --git a/wasm/src/programs/verifying_key/credits.rs b/wasm/src/programs/verifying_key/credits.rs index e981b95d4..f35cc11c3 100644 --- a/wasm/src/programs/verifying_key/credits.rs +++ b/wasm/src/programs/verifying_key/credits.rs @@ -26,13 +26,24 @@ impl VerifyingKey { VerifyingKey::from_bytes(&snarkvm_parameters::testnet::BondPublicVerifier::load_bytes().unwrap()).unwrap() } + /// Returns the verifying key for the bond_validator function + /// + /// @returns {VerifyingKey} Verifying key for the bond_validator function + #[wasm_bindgen(js_name = "bondValidatorVerifier")] + pub fn bond_validator_verifier() -> VerifyingKey { + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) + } + /// Returns the verifying key for the claim_delegator function /// /// @returns {VerifyingKey} Verifying key for the claim_unbond_public function #[wasm_bindgen(js_name = "claimUnbondPublicVerifier")] pub fn claim_unbond_public_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::ClaimUnbondPublicVerifier::load_bytes().unwrap()) - .unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the fee_private function @@ -40,7 +51,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the fee_private function #[wasm_bindgen(js_name = "feePrivateVerifier")] pub fn fee_private_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePrivateVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the fee_public function @@ -48,7 +61,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the fee_public function #[wasm_bindgen(js_name = "feePublicVerifier")] pub fn fee_public_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePublicVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the inclusion function @@ -56,7 +71,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the inclusion function #[wasm_bindgen(js_name = "inclusionVerifier")] pub fn inclusion_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::InclusionVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the join function @@ -64,7 +81,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the join function #[wasm_bindgen(js_name = "joinVerifier")] pub fn join_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::JoinVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the set_validator_state function @@ -72,8 +91,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the set_validator_state function #[wasm_bindgen(js_name = "setValidatorStateVerifier")] pub fn set_validator_state_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::SetValidatorStateVerifier::load_bytes().unwrap()) - .unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the split function @@ -81,7 +101,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the split function #[wasm_bindgen(js_name = "splitVerifier")] pub fn split_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::SplitVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the transfer_private function @@ -89,7 +111,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the transfer_private function #[wasm_bindgen(js_name = "transferPrivateVerifier")] pub fn transfer_private_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPrivateVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the transfer_private_to_public function @@ -97,8 +121,9 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the transfer_private_to_public function #[wasm_bindgen(js_name = "transferPrivateToPublicVerifier")] pub fn transfer_private_to_public_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPrivateToPublicVerifier::load_bytes().unwrap()) - .unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the transfer_public function @@ -106,7 +131,19 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the transfer_public function #[wasm_bindgen(js_name = "transferPublicVerifier")] pub fn transfer_public_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) + } + + /// Returns the verifying key for the transfer_public_as_signer function + /// + /// @returns {VerifyingKey} Verifying key for the transfer_public_as_signer function + #[wasm_bindgen(js_name = "transferPublicAsSignerVerifier")] + pub fn transfer_public_as_signer_verifier() -> VerifyingKey { + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the transfer_public_to_private function @@ -114,27 +151,19 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the transfer_public_to_private function #[wasm_bindgen(js_name = "transferPublicToPrivateVerifier")] pub fn transfer_public_to_private_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPublicToPrivateVerifier::load_bytes().unwrap()) - .unwrap() - } - - /// Returns the verifying key for the unbond_delegator_as_delegator function - /// - /// @returns {VerifyingKey} Verifying key for the unbond_delegator_as_delegator function - #[wasm_bindgen(js_name = "unbondDelegatorAsValidatorVerifier")] - pub fn unbond_delegator_as_validator_verifier() -> VerifyingKey { - VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::UnbondDelegatorAsValidatorVerifier::load_bytes().unwrap(), - ) - .unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } - /// Returns the verifying key for the unbond_delegator_as_delegator function + /// Returns the verifying key for the unbond_public function /// - /// @returns {VerifyingKey} Verifying key for the unbond_delegator_as_delegator function + /// @returns {VerifyingKey} Verifying key for the unbond_public function #[wasm_bindgen(js_name = "unbondPublicVerifier")] pub fn unbond_public_verifier() -> VerifyingKey { - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::UnbondPublicVerifier::load_bytes().unwrap()).unwrap() + let vk = CurrentNetwork::get_credits_verifying_key("bond_validator".to_string()).unwrap().clone(); + let num_variables = vk.circuit_info.num_public_and_private_variables as u64; + VerifyingKey::from(VerifyingKeyNative::new(vk, num_variables)) } /// Returns the verifying key for the bond_public function @@ -142,8 +171,15 @@ impl VerifyingKey { /// @returns {VerifyingKey} Verifying key for the bond_public function #[wasm_bindgen(js_name = "isBondPublicVerifier")] pub fn is_bond_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::BondPublicVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::bond_public_verifier() + } + + /// Returns the verifying key for the bond_validator function + /// + /// @returns {VerifyingKey} Verifying key for the bond_validator function + #[wasm_bindgen(js_name = "isBondValidatorVerifier")] + pub fn is_bond_validator_verifier(&self) -> bool { + self == &Self::bond_validator_verifier() } /// Verifies the verifying key is for the claim_delegator function @@ -151,10 +187,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isClaimUnbondPublicVerifier")] pub fn is_claim_unbond_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::ClaimUnbondPublicVerifier::load_bytes().unwrap(), - ) - .unwrap() + self == &Self::claim_unbond_public_verifier() } /// Verifies the verifying key is for the fee_private function @@ -162,8 +195,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isFeePrivateVerifier")] pub fn is_fee_private_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePrivateVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::fee_private_verifier() } /// Verifies the verifying key is for the fee_public function @@ -171,8 +203,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isFeePublicVerifier")] pub fn is_fee_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePublicVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::fee_public_verifier() } /// Verifies the verifying key is for the inclusion function @@ -180,8 +211,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isInclusionVerifier")] pub fn is_inclusion_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::InclusionVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::inclusion_verifier() } /// Verifies the verifying key is for the join function @@ -189,7 +219,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isJoinVerifier")] pub fn is_join_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::JoinVerifier::load_bytes().unwrap()).unwrap() + self == &Self::join_verifier() } /// Verifies the verifying key is for the set_validator_state function @@ -197,10 +227,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isSetValidatorStateVerifier")] pub fn is_set_validator_state_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::SetValidatorStateVerifier::load_bytes().unwrap(), - ) - .unwrap() + self == &Self::set_validator_state_verifier() } /// Verifies the verifying key is for the split function @@ -208,7 +235,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isSplitVerifier")] pub fn is_split_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::SplitVerifier::load_bytes().unwrap()).unwrap() + self == &Self::split_verifier() } /// Verifies the verifying key is for the transfer_private function @@ -216,8 +243,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isTransferPrivateVerifier")] pub fn is_transfer_private_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPrivateVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::transfer_private_verifier() } /// Verifies the verifying key is for the transfer_private_to_public function @@ -225,10 +251,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isTransferPrivateToPublicVerifier")] pub fn is_transfer_private_to_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::TransferPrivateToPublicVerifier::load_bytes().unwrap(), - ) - .unwrap() + self == &Self::transfer_private_to_public_verifier() } /// Verifies the verifying key is for the transfer_public function @@ -236,30 +259,23 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isTransferPublicVerifier")] pub fn is_transfer_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::transfer_public_verifier() } - /// Verifies the verifying key is for the transfer_public_to_private function + /// Verifies the verifying key is for the transfer_public_as_signer function /// /// @returns {bool} - #[wasm_bindgen(js_name = "isTransferPublicToPrivateVerifier")] - pub fn is_transfer_public_to_private_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::TransferPublicToPrivateVerifier::load_bytes().unwrap(), - ) - .unwrap() + #[wasm_bindgen(js_name = "isTransferPublicAsSignerVerifier")] + pub fn is_transfer_public_as_signer_verifier(&self) -> bool { + self == &Self::transfer_public_as_signer_verifier() } - /// Verifies the verifying key is for the unbond_delegator_as_delegator function + /// Verifies the verifying key is for the transfer_public_to_private function /// /// @returns {bool} - #[wasm_bindgen(js_name = "isUnbondDelegatorAsValidatorVerifier")] - pub fn is_unbond_delegator_as_validator_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::UnbondDelegatorAsValidatorVerifier::load_bytes().unwrap(), - ) - .unwrap() + #[wasm_bindgen(js_name = "isTransferPublicToPrivateVerifier")] + pub fn is_transfer_public_to_private_verifier(&self) -> bool { + self == &Self::transfer_public_to_private_verifier() } /// Verifies the verifying key is for the unbond_public function @@ -267,8 +283,7 @@ impl VerifyingKey { /// @returns {bool} #[wasm_bindgen(js_name = "isUnbondPublicVerifier")] pub fn is_unbond_public_verifier(&self) -> bool { - self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet::UnbondPublicVerifier::load_bytes().unwrap()) - .unwrap() + self == &Self::unbond_public_verifier() } } @@ -281,6 +296,8 @@ mod tests { fn test_key_loading() { let bond_public = VerifyingKey::bond_public_verifier(); assert!(bond_public.is_bond_public_verifier()); + let bond_validator = VerifyingKey::bond_validator_verifier(); + assert!(bond_validator.is_bond_validator_verifier()); let claim_unbond_public = VerifyingKey::claim_unbond_public_verifier(); assert!(claim_unbond_public.is_claim_unbond_public_verifier()); let fee_private = VerifyingKey::fee_private_verifier(); @@ -301,10 +318,10 @@ mod tests { assert!(transfer_private_to_public.is_transfer_private_to_public_verifier()); let transfer_public = VerifyingKey::transfer_public_verifier(); assert!(transfer_public.is_transfer_public_verifier()); + let transfer_public_as_signer = VerifyingKey::transfer_public_as_signer_verifier(); + assert!(transfer_public_as_signer.is_transfer_public_as_signer_verifier()); let transfer_public_to_private = VerifyingKey::transfer_public_to_private_verifier(); assert!(transfer_public_to_private.is_transfer_public_to_private_verifier()); - let unbond_delegator_as_validator = VerifyingKey::unbond_delegator_as_validator_verifier(); - assert!(unbond_delegator_as_validator.is_unbond_delegator_as_validator_verifier()); let unbond_public = VerifyingKey::unbond_public_verifier(); assert!(unbond_public.is_unbond_public_verifier()); } diff --git a/wasm/src/programs/verifying_key/metadata.rs b/wasm/src/programs/verifying_key/metadata.rs index 7848b8107..02a391be4 100644 --- a/wasm/src/programs/verifying_key/metadata.rs +++ b/wasm/src/programs/verifying_key/metadata.rs @@ -70,6 +70,17 @@ impl Metadata { ) } + #[wasm_bindgen] + pub fn bond_validator() -> Metadata { + Metadata::new( + "bond_validator", + "bondValidatorVerifier", + "credits.aleo/bond_validator", + snarkvm_parameters::testnet::BondValidatorProver::METADATA, + snarkvm_parameters::testnet::BondValidatorVerifier::METADATA, + ) + } + #[wasm_bindgen] pub fn claim_unbond_public() -> Metadata { Metadata::new( @@ -180,6 +191,17 @@ impl Metadata { ) } + #[wasm_bindgen] + pub fn transfer_public_as_signer() -> Metadata { + Metadata::new( + "transfer_public_as_signer", + "transferPublicAsSignerVerifier", + "credits.aleo/transfer_public_as_signer", + snarkvm_parameters::testnet::TransferPublicAsSignerProver::METADATA, + snarkvm_parameters::testnet::TransferPublicAsSignerVerifier::METADATA, + ) + } + #[wasm_bindgen] pub fn transfer_public_to_private() -> Metadata { Metadata::new( @@ -191,17 +213,6 @@ impl Metadata { ) } - #[wasm_bindgen] - pub fn unbond_delegator_as_validator() -> Metadata { - Metadata::new( - "unbond_delegator_as_validator", - "unbondDelegatorAsValidatorVerifier", - "credits.aleo/unbond_delegator_as_validator", - snarkvm_parameters::testnet::UnbondDelegatorAsValidatorProver::METADATA, - snarkvm_parameters::testnet::UnbondDelegatorAsValidatorVerifier::METADATA, - ) - } - #[wasm_bindgen] pub fn unbond_public() -> Metadata { Metadata::new( diff --git a/wasm/src/programs/verifying_key/mod.rs b/wasm/src/programs/verifying_key/mod.rs index 480e3b2b8..5dbc5400f 100644 --- a/wasm/src/programs/verifying_key/mod.rs +++ b/wasm/src/programs/verifying_key/mod.rs @@ -17,7 +17,7 @@ mod credits; mod metadata; -use crate::types::native::{FromBytes, ToBytes, VerifyingKeyNative}; +use crate::types::native::{CurrentNetwork, FromBytes, Network, ToBytes, VerifyingKeyNative}; use sha2::Digest; use wasm_bindgen::prelude::wasm_bindgen; @@ -176,11 +176,6 @@ mod tests { ) .unwrap() .to_string(); - let unbond_delegator_as_validator_verifier_string = VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::UnbondDelegatorAsValidatorVerifier::load_bytes().unwrap(), - ) - .unwrap() - .to_string(); let unbond_public_verifier_string = VerifyingKey::from_bytes(&snarkvm_parameters::testnet::UnbondPublicVerifier::load_bytes().unwrap()) .unwrap() @@ -203,10 +198,6 @@ mod tests { "transfer_public_to_private_verifier:\nverifying_key: \"{}\"", transfer_public_to_private_verifier_string ); - println!( - "unbond_delegator_as_validator_verifier:\nverifying_key: \"{}\"", - unbond_delegator_as_validator_verifier_string - ); println!("unbond_public_verifier:\nverifying_key: \"{}\"", unbond_public_verifier_string); } diff --git a/wasm/tests/offchain.rs b/wasm/tests/offchain.rs index cae5eaebf..6d227d34d 100644 --- a/wasm/tests/offchain.rs +++ b/wasm/tests/offchain.rs @@ -190,6 +190,7 @@ async fn test_fee_validation() { 100.00, "aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4", "private", + None, Some(fee_record.clone()), 0.9, Some(fee_record.clone()), @@ -208,6 +209,7 @@ async fn test_fee_validation() { 0.5, "aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4", "private", + None, Some(fee_record.clone()), 100.00, Some(fee_record.clone()), From e6ebf9998c185bcd66b9d27ce790a51bf1a5649d Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 20:13:09 -0400 Subject: [PATCH 2/6] Update provable.tools to use new transfer method syntax --- wasm/src/lib.rs | 2 ++ wasm/src/programs/manager/execute.rs | 2 +- wasm/src/thread_pool/mod.rs | 1 + website/src/workers/worker.js | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 27aaa7ebd..d55a71d0c 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -171,6 +171,8 @@ mod thread_pool; mod thread_pool { use std::future::Future; + #[allow(dead_code)] + #[allow(clippy::manual_async_fn)] pub fn spawn(f: F) -> impl Future where A: Send + 'static, diff --git a/wasm/src/programs/manager/execute.rs b/wasm/src/programs/manager/execute.rs index dc55fa905..7ea1d3e64 100644 --- a/wasm/src/programs/manager/execute.rs +++ b/wasm/src/programs/manager/execute.rs @@ -306,7 +306,7 @@ impl ProgramManager { let stack = process.get_stack(program_id).map_err(|e| e.to_string())?; // Calculate the finalize cost for the function identified in the transition - let cost = cost_in_microcredits(&stack, function_name).map_err(|e| e.to_string())?; + let cost = cost_in_microcredits(stack, function_name).map_err(|e| e.to_string())?; // Accumulate the finalize cost. finalize_cost = finalize_cost diff --git a/wasm/src/thread_pool/mod.rs b/wasm/src/thread_pool/mod.rs index 98d45db45..d0df6f54b 100644 --- a/wasm/src/thread_pool/mod.rs +++ b/wasm/src/thread_pool/mod.rs @@ -88,6 +88,7 @@ extern "C" { /// /// This will keep the NodeJS process alive until the /// Future is resolved. +#[allow(dead_code)] pub fn spawn(f: F) -> impl Future where A: Send + 'static, diff --git a/website/src/workers/worker.js b/website/src/workers/worker.js index d7fe710ad..e1547971f 100644 --- a/website/src/workers/worker.js +++ b/website/src/workers/worker.js @@ -264,6 +264,7 @@ self.addEventListener("message", (ev) => { transfer_type, fee, privateFee, + Address.from_private_key(PrivateKey.from_string(privateKey)).to_string(), undefined, amountRecord, feeRecord, From 05b9fb0e4409b1cc97e946f7c61dca800620edda Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 20:57:29 -0400 Subject: [PATCH 3/6] Refactor JSValue in transfer method --- wasm/src/programs/manager/transfer.rs | 43 +++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/wasm/src/programs/manager/transfer.rs b/wasm/src/programs/manager/transfer.rs index fe69bb160..a514b6ee0 100644 --- a/wasm/src/programs/manager/transfer.rs +++ b/wasm/src/programs/manager/transfer.rs @@ -35,8 +35,8 @@ use crate::types::native::{ RecordPlaintextNative, TransactionNative, }; -use js_sys::Array; use rand::{rngs::StdRng, SeedableRng}; +use wasm_bindgen::JsValue; use std::{ops::Add, str::FromStr}; #[wasm_bindgen] @@ -97,39 +97,44 @@ impl ProgramManager { if amount_record.is_none() { return Err("Amount record must be provided for private transfers".to_string()); } - let inputs = Array::new_with_length(3); - inputs.set(0u32, wasm_bindgen::JsValue::from_str(&amount_record.unwrap().to_string())); - inputs.set(1u32, wasm_bindgen::JsValue::from_str(recipient)); - inputs.set(2u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + let inputs = [ + JsValue::from_str(&amount_record.unwrap().to_string()), + JsValue::from(recipient), + JsValue::from(&amount_microcredits.to_string().add("u64")), + ].into_iter().collect::(); ("transfer_private", inputs) } "private_to_public" | "privateToPublic" | "transfer_private_to_public" | "transferPrivateToPublic" => { if amount_record.is_none() { return Err("Amount record must be provided for private transfers".to_string()); } - let inputs = Array::new_with_length(3); - inputs.set(0u32, wasm_bindgen::JsValue::from_str(&amount_record.unwrap().to_string())); - inputs.set(1u32, wasm_bindgen::JsValue::from_str(recipient)); - inputs.set(2u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + let inputs = [ + JsValue::from_str(&amount_record.unwrap().to_string()), + JsValue::from(recipient), + JsValue::from(&amount_microcredits.to_string().add("u64")), + ].into_iter().collect::(); ("transfer_private_to_public", inputs) } "public" | "transfer_public" | "transferPublic" => { - let inputs = Array::new_with_length(3); - inputs.set(0u32, wasm_bindgen::JsValue::from_str(&caller.unwrap())); - inputs.set(1u32, wasm_bindgen::JsValue::from_str(recipient)); - inputs.set(2u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + let inputs = [ + JsValue::from(&caller.unwrap()), + JsValue::from(recipient), + JsValue::from(&amount_microcredits.to_string().add("u64")), + ].into_iter().collect::(); ("transfer_public", inputs) } "public_as_signer" | "transfer_public_as_signer" | "transferPublicAsSigner" => { - let inputs = Array::new_with_length(2); - inputs.set(0u32, wasm_bindgen::JsValue::from_str(recipient)); - inputs.set(1u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + let inputs = [ + JsValue::from(recipient), + JsValue::from(&amount_microcredits.to_string().add("u64")), + ].into_iter().collect::(); ("transfer_public_as_signer", inputs) } "public_to_private" | "publicToPrivate" | "transfer_public_to_private" | "transferPublicToPrivate" => { - let inputs = Array::new_with_length(2); - inputs.set(0u32, wasm_bindgen::JsValue::from_str(recipient)); - inputs.set(1u32, wasm_bindgen::JsValue::from_str(&amount_microcredits.to_string().add("u64"))); + let inputs = [ + JsValue::from(recipient), + JsValue::from(&amount_microcredits.to_string().add("u64")), + ].into_iter().collect::(); ("transfer_public_to_private", inputs) } _ => return Err("Invalid transfer type".to_string()), From bd77062821dd1a3e6c8bbacd124160ebb1ce7103 Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 21:01:49 -0400 Subject: [PATCH 4/6] Bump SDK versions to next minor version (0.6.X -> 0.7.X) --- sdk/package.json | 2 +- wasm/Cargo.lock | 2 +- wasm/Cargo.toml | 2 +- wasm/package.json | 2 +- website/package.json | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/package.json b/sdk/package.json index f84f6d255..70fb55603 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@aleohq/sdk", - "version": "0.6.9", + "version": "0.7.0", "description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions", "collaborators": [ "The Aleo Team " diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 53765fbfb..ae27638a1 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -94,7 +94,7 @@ checksum = "7e4f181fc1a372e8ceff89612e5c9b13f72bff5b066da9f8d6827ae65af492c4" [[package]] name = "aleo-wasm" -version = "0.6.9" +version = "0.7.0" dependencies = [ "anyhow", "async-trait", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index b9019ae8b..3c8bb666f 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleo-wasm" -version = "0.6.9" +version = "0.7.0" authors = [ "The Aleo Team " ] description = "WebAssembly based toolkit for developing zero knowledge applications with Aleo" homepage = "https://aleo.org" diff --git a/wasm/package.json b/wasm/package.json index 39211132c..76db9fba9 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -1,6 +1,6 @@ { "name": "@aleohq/wasm", - "version": "0.6.9", + "version": "0.7.0", "description": "Wasm build for the SDK", "collaborators": [ "The Aleo Team " diff --git a/website/package.json b/website/package.json index a69696037..0d70cab64 100644 --- a/website/package.json +++ b/website/package.json @@ -1,6 +1,6 @@ { - "name": "aleo-website", - "version": "0.1.0", + "name": "provable-dot-tools-website", + "version": "0.2.0", "private": true, "type": "module", "scripts": { @@ -13,7 +13,7 @@ "preview": "vite preview" }, "dependencies": { - "@aleohq/sdk": "^0.6.2", + "@provablehq/sdk": "^0.7.0", "@ant-design/icons": "^4.4.0", "@codemirror/language": "^6.8.0", "@codemirror/legacy-modes": "^6.3.3", @@ -53,5 +53,5 @@ "webpack-cli": "^5.1.4", "webpack-dev-server": "^4.15.1" }, - "homepage": "https://aleo.tools" + "homepage": "https://provable.tools" } From 41013f253de016406aebed5e9b9b01b7c3cae199 Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 21:35:02 -0400 Subject: [PATCH 5/6] Revert "Bump SDK versions to next minor version (0.6.X -> 0.7.X)" This reverts commit bd77062821dd1a3e6c8bbacd124160ebb1ce7103. --- sdk/package.json | 2 +- wasm/Cargo.lock | 2 +- wasm/Cargo.toml | 2 +- wasm/package.json | 2 +- website/package.json | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/package.json b/sdk/package.json index 70fb55603..f84f6d255 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@aleohq/sdk", - "version": "0.7.0", + "version": "0.6.9", "description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions", "collaborators": [ "The Aleo Team " diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index ae27638a1..53765fbfb 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -94,7 +94,7 @@ checksum = "7e4f181fc1a372e8ceff89612e5c9b13f72bff5b066da9f8d6827ae65af492c4" [[package]] name = "aleo-wasm" -version = "0.7.0" +version = "0.6.9" dependencies = [ "anyhow", "async-trait", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 3c8bb666f..b9019ae8b 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleo-wasm" -version = "0.7.0" +version = "0.6.9" authors = [ "The Aleo Team " ] description = "WebAssembly based toolkit for developing zero knowledge applications with Aleo" homepage = "https://aleo.org" diff --git a/wasm/package.json b/wasm/package.json index 76db9fba9..39211132c 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -1,6 +1,6 @@ { "name": "@aleohq/wasm", - "version": "0.7.0", + "version": "0.6.9", "description": "Wasm build for the SDK", "collaborators": [ "The Aleo Team " diff --git a/website/package.json b/website/package.json index 0d70cab64..a69696037 100644 --- a/website/package.json +++ b/website/package.json @@ -1,6 +1,6 @@ { - "name": "provable-dot-tools-website", - "version": "0.2.0", + "name": "aleo-website", + "version": "0.1.0", "private": true, "type": "module", "scripts": { @@ -13,7 +13,7 @@ "preview": "vite preview" }, "dependencies": { - "@provablehq/sdk": "^0.7.0", + "@aleohq/sdk": "^0.6.2", "@ant-design/icons": "^4.4.0", "@codemirror/language": "^6.8.0", "@codemirror/legacy-modes": "^6.3.3", @@ -53,5 +53,5 @@ "webpack-cli": "^5.1.4", "webpack-dev-server": "^4.15.1" }, - "homepage": "https://provable.tools" + "homepage": "https://aleo.tools" } From aa7b75fdbe8e83c9128c06311b76da37ba36bfb9 Mon Sep 17 00:00:00 2001 From: Michael Turner Date: Mon, 1 Jul 2024 21:38:48 -0400 Subject: [PATCH 6/6] Formatting lints --- wasm/src/programs/manager/transfer.rs | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/wasm/src/programs/manager/transfer.rs b/wasm/src/programs/manager/transfer.rs index a514b6ee0..f41906024 100644 --- a/wasm/src/programs/manager/transfer.rs +++ b/wasm/src/programs/manager/transfer.rs @@ -36,8 +36,8 @@ use crate::types::native::{ TransactionNative, }; use rand::{rngs::StdRng, SeedableRng}; -use wasm_bindgen::JsValue; use std::{ops::Add, str::FromStr}; +use wasm_bindgen::JsValue; #[wasm_bindgen] impl ProgramManager { @@ -101,7 +101,9 @@ impl ProgramManager { JsValue::from_str(&amount_record.unwrap().to_string()), JsValue::from(recipient), JsValue::from(&amount_microcredits.to_string().add("u64")), - ].into_iter().collect::(); + ] + .into_iter() + .collect::(); ("transfer_private", inputs) } "private_to_public" | "privateToPublic" | "transfer_private_to_public" | "transferPrivateToPublic" => { @@ -112,7 +114,9 @@ impl ProgramManager { JsValue::from_str(&amount_record.unwrap().to_string()), JsValue::from(recipient), JsValue::from(&amount_microcredits.to_string().add("u64")), - ].into_iter().collect::(); + ] + .into_iter() + .collect::(); ("transfer_private_to_public", inputs) } "public" | "transfer_public" | "transferPublic" => { @@ -120,21 +124,21 @@ impl ProgramManager { JsValue::from(&caller.unwrap()), JsValue::from(recipient), JsValue::from(&amount_microcredits.to_string().add("u64")), - ].into_iter().collect::(); + ] + .into_iter() + .collect::(); ("transfer_public", inputs) } "public_as_signer" | "transfer_public_as_signer" | "transferPublicAsSigner" => { - let inputs = [ - JsValue::from(recipient), - JsValue::from(&amount_microcredits.to_string().add("u64")), - ].into_iter().collect::(); + let inputs = [JsValue::from(recipient), JsValue::from(&amount_microcredits.to_string().add("u64"))] + .into_iter() + .collect::(); ("transfer_public_as_signer", inputs) } "public_to_private" | "publicToPrivate" | "transfer_public_to_private" | "transferPublicToPrivate" => { - let inputs = [ - JsValue::from(recipient), - JsValue::from(&amount_microcredits.to_string().add("u64")), - ].into_iter().collect::(); + let inputs = [JsValue::from(recipient), JsValue::from(&amount_microcredits.to_string().add("u64"))] + .into_iter() + .collect::(); ("transfer_public_to_private", inputs) } _ => return Err("Invalid transfer type".to_string()),