diff --git a/bindings/nodejs/README.md b/bindings/nodejs/README.md index 1c560ab0d4..abac727e55 100644 --- a/bindings/nodejs/README.md +++ b/bindings/nodejs/README.md @@ -108,7 +108,7 @@ run().then(() => process.exit()); ## Wallet Usage The following example will create a -new [`Wallet`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Wallet/) [`Account`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Account/) +new [`Wallet`](https://wiki.iota.org/shimmer/iota-sdk/references/nodejs/classes/Wallet/) that connects to the [Shimmer Testnet](https://api.testnet.shimmer.network) using the [`StrongholdSecretManager`](https://wiki.iota.org/shimmer/iota-sdk/references/python/iota_sdk/secret_manager/#strongholdsecretmanager-objects). @@ -116,7 +116,7 @@ that connects to the [Shimmer Testnet](https://api.testnet.shimmer.network) usin import { Wallet, CoinType, WalletOptions } from '@iota/sdk'; const walletOptions: WalletOptions = { - storagePath: `Alice`, // A name to associate with the created account. + storagePath: `Alice`, // A name to associate with the created wallet. clientOptions: { nodes: ['https://api.testnet.shimmer.network'], // The node to connect to. }, @@ -124,7 +124,7 @@ const walletOptions: WalletOptions = { secretManager: { // Setup Stronghold secret manager stronghold: { - snapshotPath: 'vault.stronghold', // The path to store the account snapshot. + snapshotPath: 'vault.stronghold', // The path to store the wallet snapshot. password: 'a-secure-password', // A password to encrypt the stored data. WARNING: Never hardcode passwords in production code. }, }, diff --git a/bindings/nodejs/examples/exchange/1-create-account.ts b/bindings/nodejs/examples/exchange/1-create-account.ts deleted file mode 100644 index c48bf4f490..0000000000 --- a/bindings/nodejs/examples/exchange/1-create-account.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -// This example creates a new database and account. -// Run with command: -// yarn run-example ./exchange/1-create-account.ts - -import { Wallet, WalletOptions, CoinType } from '@iota/sdk'; - -// This example uses secrets in environment variables for simplicity which should not be done in production. -require('dotenv').config({ path: '.env' }); - -async function run() { - try { - for (const envVar of [ - 'WALLET_DB_PATH', - 'NODE_URL', - 'STRONGHOLD_SNAPSHOT_PATH', - 'STRONGHOLD_PASSWORD', - 'MNEMONIC', - ]) - if (!(envVar in process.env)) { - throw new Error( - `.env ${envVar} is undefined, see .env.example`, - ); - } - - const walletOptions: WalletOptions = { - storagePath: process.env.WALLET_DB_PATH, - clientOptions: { - nodes: [process.env.NODE_URL as string], - }, - coinType: CoinType.IOTA, - secretManager: { - stronghold: { - snapshotPath: process.env.STRONGHOLD_SNAPSHOT_PATH, - password: process.env.STRONGHOLD_PASSWORD, - }, - }, - }; - - const wallet = new Wallet(walletOptions); - - // Mnemonic only needs to be set the first time. - await wallet.storeMnemonic(process.env.MNEMONIC as string); - - const account = await wallet.createAccount({ - alias: 'Alice', - }); - - // Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked, - // have a storage deposit return, expiration or are nft/account/foundry outputs. - account.setDefaultSyncOptions({ syncOnlyMostBasicOutputs: true }); - - console.log(account); - } catch (error) { - console.error(error); - } -} - -run().then(() => process.exit()); diff --git a/bindings/nodejs/examples/exchange/1-create-wallet.ts b/bindings/nodejs/examples/exchange/1-create-wallet.ts new file mode 100644 index 0000000000..a7266456f9 --- /dev/null +++ b/bindings/nodejs/examples/exchange/1-create-wallet.ts @@ -0,0 +1,74 @@ +// Copyright 2023 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +// This example creates a new database and wallet. +// Run with command: +// yarn run-example ./exchange/1-create-wallet.ts + +import { Wallet, WalletOptions, CoinType, SecretManager } from '@iota/sdk'; + +// This example uses secrets in environment variables for simplicity which should not be done in production. +require('dotenv').config({ path: '.env' }); + +async function run() { + try { + for (const envVar of [ + 'WALLET_DB_PATH', + 'NODE_URL', + 'STRONGHOLD_SNAPSHOT_PATH', + 'STRONGHOLD_PASSWORD', + 'MNEMONIC', + ]) + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } + + const strongholdSecretManager = { + stronghold: { + snapshotPath: process.env.STRONGHOLD_SNAPSHOT_PATH, + password: process.env.STRONGHOLD_PASSWORD, + }, + }; + + const secretManager = new SecretManager(strongholdSecretManager); + + // A mnemonic can be generated with `Utils.generateMnemonic()`. + // Store the mnemonic in the Stronghold snapshot, this needs to be done only the first time. + // The mnemonic can't be retrieved from the Stronghold file, so make a backup in a secure place! + await secretManager.storeMnemonic(process.env.MNEMONIC as string); + + const walletAddress = await secretManager.generateEd25519Addresses({ + coinType: CoinType.IOTA, + accountIndex: 0, + range: { + start: 0, + end: 1, + }, + bech32Hrp: 'tst', + }); + + const walletOptions: WalletOptions = { + address: walletAddress[0], + storagePath: process.env.WALLET_DB_PATH, + clientOptions: { + nodes: [process.env.NODE_URL as string], + }, + bipPath: { + coinType: CoinType.IOTA, + }, + secretManager: strongholdSecretManager, + }; + + const wallet = new Wallet(walletOptions); + + // Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked, + // have a storage deposit return, expiration or are nft/account/foundry outputs. + wallet.setDefaultSyncOptions({ syncOnlyMostBasicOutputs: true }); + } catch (error) { + console.error(error); + } +} + +run().then(() => process.exit()); diff --git a/bindings/nodejs/examples/exchange/2-generate-address.ts b/bindings/nodejs/examples/exchange/2-generate-address.ts deleted file mode 100644 index 6ad4ac8b32..0000000000 --- a/bindings/nodejs/examples/exchange/2-generate-address.ts +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -// This example generates an address for an account. -// Run with command: -// yarn run-example ./exchange/2-generate-address.ts - -import { Wallet } from '@iota/sdk'; - -// This example uses secrets in environment variables for simplicity which should not be done in production. -require('dotenv').config({ path: '.env' }); - -async function run() { - try { - for (const envVar of ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']) - if (!(envVar in process.env)) { - throw new Error( - `.env ${envVar} is undefined, see .env.example`, - ); - } - - const wallet = new Wallet({ - storagePath: process.env.WALLET_DB_PATH, - }); - - await wallet.setStrongholdPassword( - process.env.STRONGHOLD_PASSWORD as string, - ); - - const account = await wallet.getAccount('Alice'); - - const address = (await account.generateEd25519Addresses(1))[0]; - - console.log('Address:', address); - } catch (error) { - console.error(error); - } -} - -run().then(() => process.exit()); diff --git a/bindings/nodejs/examples/exchange/3-check-balance.ts b/bindings/nodejs/examples/exchange/3-check-balance.ts index 53d43b6093..ed9346243a 100644 --- a/bindings/nodejs/examples/exchange/3-check-balance.ts +++ b/bindings/nodejs/examples/exchange/3-check-balance.ts @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -// This example gets the balance of an account. +// This example gets the balance of a wallet. // Run with command: // yarn run-example ./exchange/3-check-balance.ts @@ -21,15 +21,13 @@ async function run() { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, }); + const address = await wallet.address(); - const account = await wallet.getAccount('Alice'); - const addresses = await account.addresses(); - - console.log('Addresses:', addresses); + console.log('Address:', address); // Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked, // have a storage deposit return, expiration or are nft/account/foundry outputs. - const balance = await account.sync({ syncOnlyMostBasicOutputs: true }); + const balance = await wallet.sync({ syncOnlyMostBasicOutputs: true }); console.log('Balance', balance); diff --git a/bindings/nodejs/examples/exchange/4-listen-events.ts b/bindings/nodejs/examples/exchange/4-listen-events.ts index ac1cd83838..88a6a58d7a 100644 --- a/bindings/nodejs/examples/exchange/4-listen-events.ts +++ b/bindings/nodejs/examples/exchange/4-listen-events.ts @@ -33,15 +33,13 @@ async function run() { // Only interested in new outputs here. await wallet.listen([WalletEventType.NewOutput], callback); - const account = await wallet.getAccount('Alice'); - // Use the faucet to send testnet tokens to your address. console.log( 'Fill your address with the faucet: https://faucet.testnet.shimmer.network/', ); - const addresses = await account.addresses(); - console.log('Send funds to:', addresses[0].address); + const address = await wallet.address(); + console.log('Send funds to:', address); // Sync every 5 seconds until the faucet transaction gets confirmed. for (let i = 0; i < 100; i++) { @@ -50,7 +48,7 @@ async function run() { // Sync to detect new outputs // Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked, // have a storage deposit return, expiration or are nft/account/foundry outputs. - await account.sync({ syncOnlyMostBasicOutputs: true }); + await wallet.sync({ syncOnlyMostBasicOutputs: true }); } } catch (error) { console.error(error); diff --git a/bindings/nodejs/examples/exchange/5-send-amount.ts b/bindings/nodejs/examples/exchange/5-send-amount.ts index 1c09592ee8..e387f1587a 100644 --- a/bindings/nodejs/examples/exchange/5-send-amount.ts +++ b/bindings/nodejs/examples/exchange/5-send-amount.ts @@ -31,14 +31,11 @@ async function run() { process.env.STRONGHOLD_PASSWORD as string, ); - const account = await wallet.getAccount('Alice'); - console.log('Account:', account); - // Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked, // have a storage deposit return, expiration or are nft/account/foundry outputs. - await account.sync({ syncOnlyMostBasicOutputs: true }); + await wallet.sync({ syncOnlyMostBasicOutputs: true }); - const response = await account.send( + const response = await wallet.send( BigInt(1000000), // Replace with the address of your choice! 'rms1qrrv7flg6lz5cssvzv2lsdt8c673khad060l4quev6q09tkm9mgtupgf0h0', diff --git a/bindings/nodejs/examples/how_tos/account_output/create.ts b/bindings/nodejs/examples/how_tos/account_output/create.ts index d5872abc0b..335b3884ba 100644 --- a/bindings/nodejs/examples/how_tos/account_output/create.ts +++ b/bindings/nodejs/examples/how_tos/account_output/create.ts @@ -6,7 +6,7 @@ import { Wallet, initLogger } from '@iota/sdk'; // This example uses secrets in environment variables for simplicity which should not be done in production. // // Make sure that `example.stronghold` and `example.walletdb` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // require('dotenv').config({ path: '.env' }); @@ -31,11 +31,8 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); console.log(`Accounts BEFORE:\n`, balance.accounts); @@ -47,19 +44,19 @@ async function run() { console.log('Sending the create-account transaction...'); // Create an account output - const transaction = await account.createAccountOutput(); + const transaction = await wallet.createAccountOutput(); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); console.log(`Accounts AFTER:\n`, balance.accounts); } catch (error) { console.log('Error: ', error); diff --git a/bindings/nodejs/examples/how_tos/account_output/destroy.ts b/bindings/nodejs/examples/how_tos/account_output/destroy.ts index 78d369b0f2..b5f6eb23d9 100644 --- a/bindings/nodejs/examples/how_tos/account_output/destroy.ts +++ b/bindings/nodejs/examples/how_tos/account_output/destroy.ts @@ -27,17 +27,14 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); if (balance.accounts.length == 0) { throw new Error(`No Account output available in account 'Alice'`); } - // We try to destroy the first account output in the account + // We try to destroy the first account output in the wallet const accountId = balance.accounts[0]; console.log( @@ -53,14 +50,14 @@ async function run() { console.log('Sending the destroy-account transaction...'); // Destroy an account output - const transaction = await account + const transaction = await wallet .prepareDestroyAccount(accountId) .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( @@ -68,7 +65,7 @@ async function run() { ); console.log(`Destroyed account output ${accountId}`); - balance = await account.sync(); + balance = await wallet.sync(); console.log( `Accounts AFTER destroying (${balance.accounts.length}):\n`, balance.accounts, diff --git a/bindings/nodejs/examples/how_tos/account_wallet/request-funds.ts b/bindings/nodejs/examples/how_tos/account_wallet/request-funds.ts index f754bd1e3e..3e1ec12583 100644 --- a/bindings/nodejs/examples/how_tos/account_wallet/request-funds.ts +++ b/bindings/nodejs/examples/how_tos/account_wallet/request-funds.ts @@ -6,7 +6,7 @@ import { Utils, Wallet, initLogger } from '@iota/sdk'; // This example uses secrets in environment variables for simplicity which should not be done in production. // // Make sure that `example.stronghold` and `example.walletdb` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // require('dotenv').config({ path: '.env' }); @@ -27,10 +27,7 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `create_wallet` - const account = await wallet.getAccount('Alice'); - - const balance = await account.sync(); + const balance = await wallet.sync(); const totalBaseTokenBalance = balance.baseCoin.total; console.log( @@ -57,7 +54,7 @@ async function run() { basicOutputs: true, }, }; - const totalBaseTokenBalanceAfter = (await account.sync(syncOptions)) + const totalBaseTokenBalanceAfter = (await wallet.sync(syncOptions)) .baseCoin.total; console.log( `Balance after requesting funds on account address: ${totalBaseTokenBalanceAfter}`, diff --git a/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts b/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts index aa7176e992..8fe6b32a4b 100644 --- a/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts +++ b/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts @@ -6,7 +6,7 @@ import { Wallet, initLogger, Utils } from '@iota/sdk'; // This example uses secrets in environment variables for simplicity which should not be done in production. // // Make sure that `example.stronghold` and `example.walletdb` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // require('dotenv').config({ path: '.env' }); @@ -33,11 +33,9 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); - const balance = await account.sync(syncOptions); + const balance = await wallet.sync(syncOptions); const totalBaseTokenBalance = balance.baseCoin.total; console.log( @@ -72,15 +70,13 @@ async function run() { mandatoryInputs: [input], allowMicroAmount: false, }; - const transaction = await account.sendWithParams(params, options); - await account.reissueTransactionUntilIncluded( - transaction.transactionId, - ); + const transaction = await wallet.sendWithParams(params, options); + await wallet.reissueTransactionUntilIncluded(transaction.transactionId); console.log( `Transaction with custom input: https://explorer.iota.org/testnet/transaction/${transaction.transactionId}`, ); - const totalBaseTokenBalanceAfter = (await account.sync(syncOptions)) + const totalBaseTokenBalanceAfter = (await wallet.sync(syncOptions)) .baseCoin.total; console.log( `Balance after sending funds from account: ${totalBaseTokenBalanceAfter}`, diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts index 042db1296a..af11654fb0 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/check-balance.ts @@ -20,14 +20,12 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - // Sync new outputs from the node. // eslint-disable-next-line @typescript-eslint/no-unused-vars - const _syncBalance = await account.sync(); + const _syncBalance = await wallet.sync(); // After syncing the balance can also be computed with the local data - const balance = await account.getBalance(); + const balance = await wallet.getBalance(); console.log('Balance', balance); } catch (error) { console.error('Error: ', error); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/consolidate-outputs.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/consolidate-outputs.ts index 50c1e3c330..e7619c3288 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/consolidate-outputs.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/consolidate-outputs.ts @@ -9,7 +9,7 @@ require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/consolidate-outputs.ts -// In this example we will consolidate basic outputs from an account with only an AddressUnlockCondition by sending +// In this example we will consolidate basic outputs from an wallet with only an AddressUnlockCondition by sending // them to the same address again. async function run() { initLogger(); @@ -29,23 +29,21 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - // To create an address we need to unlock stronghold. await wallet.setStrongholdPassword( process.env.STRONGHOLD_PASSWORD as string, ); - // Sync account to make sure account is updated with outputs from previous examples - account.sync(); - console.log('Account synced'); + // Sync wallet to make sure wallet is updated with outputs from previous examples + await wallet.sync(); + console.log('Wallet synced'); // List unspent outputs before consolidation. // The output we created with example `request_funds` and the basic output from `mint` have only one // unlock condition and it is an `AddressUnlockCondition`, and so they are valid for consolidation. They have the - // same `AddressUnlockCondition`(the first address of the account), so they will be consolidated into one + // same `AddressUnlockCondition`(the address of the wallet), so they will be consolidated into one // output. - const outputs = await account.unspentOutputs(); + const outputs = await wallet.unspentOutputs(); console.log('Outputs BEFORE consolidation:'); outputs.forEach(({ output, address }, i) => { @@ -64,13 +62,13 @@ async function run() { // Consolidate unspent outputs and print the consolidation transaction ID // Set `force` to true to force the consolidation even though the `output_threshold` isn't reached - const transaction = await account.consolidateOutputs({ + const transaction = await wallet.consolidateOutputs({ force: true, }); console.log('Transaction sent: %s', transaction.transactionId); // Wait for the consolidation transaction to get confirmed - const blockId = account.reissueTransactionUntilIncluded( + const blockId = wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -80,9 +78,9 @@ async function run() { blockId, ); - // Sync account - account.sync(); - console.log('Account synced'); + // Sync wallet + await wallet.sync(); + console.log('Wallet synced'); // Outputs after consolidation console.log('Outputs AFTER consolidation:'); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts deleted file mode 100644 index c525a4e16f..0000000000 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { Wallet, initLogger } from '@iota/sdk'; -require('dotenv').config({ path: '.env' }); - -// Run with command: -// yarn run-example ./how_tos/accounts_and_addresses/create-address.ts - -// This example creates an address -async function run() { - initLogger(); - for (const envVar of ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']) - if (!(envVar in process.env)) { - throw new Error(`.env ${envVar} is undefined, see .env.example`); - } - - try { - const wallet = new Wallet({ - storagePath: process.env.WALLET_DB_PATH, - }); - - const account = await wallet.getAccount('Alice'); - - // To create an address we need to unlock stronghold. - await wallet.setStrongholdPassword( - process.env.STRONGHOLD_PASSWORD as string, - ); - - const address = (await account.generateEd25519Addresses(1))[0]; - - console.log(`Generated address:`, address.address); - } catch (error) { - console.error('Error: ', error); - } -} - -run().then(() => process.exit()); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-wallet.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-wallet.ts index d6fdfa4553..e713c26fb3 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-wallet.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-wallet.ts @@ -44,7 +44,7 @@ async function run() { // The mnemonic can't be retrieved from the Stronghold file, so make a backup in a secure place! await secretManager.storeMnemonic(process.env.MNEMONIC as string); - const wallet_address = await secretManager.generateEd25519Addresses({ + const walletAddress = await secretManager.generateEd25519Addresses({ coinType: CoinType.IOTA, accountIndex: 0, range: { @@ -55,7 +55,7 @@ async function run() { }); const walletOptions: WalletOptions = { - address: wallet_address[0], + address: walletAddress[0], storagePath: process.env.WALLET_DB_PATH, clientOptions: { nodes: [process.env.NODE_URL as string], diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts index f3e5662372..2ba9ac7942 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-accounts.ts @@ -9,7 +9,7 @@ require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-accounts.ts -// This example lists all accounts in the wallet. +// This example lists all account outputs in the wallet. async function run() { initLogger(); if (!process.env.WALLET_DB_PATH) { @@ -20,10 +20,9 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const accounts = await wallet.getAccounts(); + const accounts = await wallet.accounts(); - for (const account of accounts) - console.log(account.getMetadata().alias); + for (const account of accounts) console.log(account); } catch (error) { console.error('Error: ', error); } diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts deleted file mode 100644 index 02e56eb9b5..0000000000 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-addresses.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { Wallet, initLogger } from '@iota/sdk'; - -// This example uses secrets in environment variables for simplicity which should not be done in production. -require('dotenv').config({ path: '.env' }); - -// Run with command: -// yarn run-example ./how_tos/accounts_and_addresses/list-addresses.ts - -// This example lists all addresses in the account. -async function run() { - initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - try { - const wallet = new Wallet({ - storagePath: process.env.WALLET_DB_PATH, - }); - - const account = await wallet.getAccount('Alice'); - - const addresses = await account.addresses(); - - for (const address of addresses) console.log(address.address); - } catch (error) { - console.error('Error: ', error); - } -} - -run().then(() => process.exit()); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts index a3fe14be53..a25192d276 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-outputs.ts @@ -9,7 +9,7 @@ require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-outputs.ts -// This example lists all outputs in the account. +// This example lists all outputs in the wallet. async function run() { initLogger(); if (!process.env.WALLET_DB_PATH) { @@ -20,16 +20,14 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); + await wallet.sync(); - await account.sync(); - - const outputs = await account.outputs(); + const outputs = await wallet.outputs(); console.log('Output ids:'); for (const output of outputs) console.log(output.outputId); - const unspentOutputs = await account.unspentOutputs(); + const unspentOutputs = await wallet.unspentOutputs(); console.log('Unspent output ids:'); for (const output of unspentOutputs) console.log(output.outputId); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts index 0cfd55dd81..feb53b0898 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/list-transactions.ts @@ -9,7 +9,7 @@ require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/accounts_and_addresses/list-transactions.ts -// This example lists all transactions in the account. +// This example lists all transactions in the wallet. async function run() { initLogger(); if (!process.env.WALLET_DB_PATH) { @@ -19,16 +19,14 @@ async function run() { const wallet = new Wallet({ storagePath: process.env.WALLET_DB_PATH, }); + await wallet.sync({ syncIncomingTransactions: true }); - const account = await wallet.getAccount('Alice'); - await account.sync({ syncIncomingTransactions: true }); - - const transactions = await account.transactions(); + const transactions = await wallet.transactions(); console.log('Sent transactions:'); for (const transaction of transactions) console.log(transaction.transactionId); - const incomingTransactions = await account.incomingTransactions(); + const incomingTransactions = await wallet.incomingTransactions(); console.log('Incoming transactions:'); for (const transaction of incomingTransactions) { console.log(transaction.transactionId); diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts index 13d22cd700..199fab2471 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/advanced_transaction.ts @@ -28,9 +28,7 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - - await account.sync(); + await wallet.sync(); // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); @@ -53,11 +51,11 @@ async function run() { ], }); - const transaction = await account.sendOutputs([basicOutput]); + const transaction = await wallet.sendOutputs([basicOutput]); console.log(`Transaction sent: ${transaction.transactionId}`); console.log('Waiting until included in block...'); - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log(`Block sent: ${process.env.EXPLORER_URL}/block/${blockId}`); diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts index 5d586875ed..67a1fb7b53 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/claim_transaction.ts @@ -7,7 +7,7 @@ require('dotenv').config({ path: '.env' }); // Run with command: // yarn run-example ./how_tos/advanced_transactions/claim_transaction.ts -// This example claims all claimable outputs in the account. +// This example claims all claimable outputs in the wallet. async function run() { initLogger(); try { @@ -21,24 +21,22 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - - await account.sync(); + await wallet.sync(); // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); // Get all claimable outputs - const output_ids = await account.claimableOutputs(OutputsToClaim.All); + const output_ids = await wallet.claimableOutputs(OutputsToClaim.All); console.log(`Available outputs to claim:`); for (const output_id of output_ids) { console.log(output_id); } - const transaction = await account.claimOutputs(output_ids); + const transaction = await wallet.claimOutputs(output_ids); console.log(`Transaction sent: ${transaction.transactionId}`); - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log(`Block sent: ${process.env.EXPLORER_URL}/block/${blockId}`); diff --git a/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts b/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts index 22da16ac31..6cb5e31db1 100644 --- a/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts +++ b/bindings/nodejs/examples/how_tos/advanced_transactions/send_micro_transaction.ts @@ -21,9 +21,7 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - - await account.sync(); + await wallet.sync(); // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); @@ -33,13 +31,13 @@ async function run() { 'rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu'; const amount = BigInt(1); - const transaction = await account.send(amount, address, { + const transaction = await wallet.send(amount, address, { allowMicroAmount: true, }); console.log(`Transaction sent: ${transaction.transactionId}`); - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/burn.ts b/bindings/nodejs/examples/how_tos/native_tokens/burn.ts index 5f68f0fa76..432895eae3 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/burn.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/burn.ts @@ -3,7 +3,7 @@ import { getUnlockedWallet } from '../../wallet/common'; -// The minimum available native token amount to search for in the account. +// The minimum available native token amount to search for in the wallet. const MIN_AVAILABLE_AMOUNT = BigInt(11); // The amount of the native token to burn. const BURN_AMOUNT = BigInt(1); @@ -13,7 +13,7 @@ const BURN_AMOUNT = BigInt(1); // output that minted it. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/burn.ts @@ -22,11 +22,8 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); // Get a token with sufficient balance const tokenId = balance.nativeTokens.find( @@ -42,21 +39,21 @@ async function run() { throw new Error( `Native token '${tokenId}' doesn't exist or there's not at least '${Number( MIN_AVAILABLE_AMOUNT, - )}' tokens of it in account 'Alice'`, + )}' tokens of it in the wallet`, ); } console.log(`Balance before burning: ${token.available}`); // Burn a native token - const transaction = await account + const transaction = await wallet .prepareBurnNativeToken(token.tokenId, BURN_AMOUNT) .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -64,7 +61,7 @@ async function run() { `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); token = balance.nativeTokens.find( (nativeToken) => nativeToken.tokenId == tokenId, diff --git a/bindings/nodejs/examples/how_tos/native_tokens/create.ts b/bindings/nodejs/examples/how_tos/native_tokens/create.ts index 6011237381..81035d82e1 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/create.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/create.ts @@ -13,7 +13,7 @@ const MAXIMUM_SUPPLY = BigInt(100); // In this example we will create a native token. // // Make sure that `example.stronghold` and `example.walletdb` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/create.ts @@ -22,22 +22,19 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - const balance = await account.sync(); + const balance = await wallet.sync(); // We can first check if we already have an account output in our account, because an account output can have // many foundry outputs and therefore we can reuse an existing one if (balance.accounts.length == 0) { // If we don't have an account output, we need to create one - const transaction = await account + const transaction = await wallet .prepareCreateAccountOutput() .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -45,8 +42,8 @@ async function run() { `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - await account.sync(); - console.log('Account synced'); + await wallet.sync(); + console.log('Wallet synced'); } console.log('Preparing transaction to create native token...'); @@ -57,20 +54,20 @@ async function run() { 10, ).withDescription('A native token to test the iota-sdk.'); - // If we omit the AccountAddress field the first address of the account is used by default + // If we omit the AccountAddress field the wallet address is used by default const params: CreateNativeTokenParams = { circulatingSupply: CIRCULATING_SUPPLY, maximumSupply: MAXIMUM_SUPPLY, foundryMetadata: metadata.asHex(), }; - const prepared = await account.prepareCreateNativeToken(params); + const prepared = await wallet.prepareCreateNativeToken(params); const transaction = await prepared.send(); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -81,8 +78,8 @@ async function run() { console.log(`Created token: ${prepared.tokenId()}`); // Ensure the account is synced after creating the native token. - await account.sync(); - console.log('Account synced'); + await wallet.sync(); + console.log('Wallet synced'); } catch (error) { console.log('Error: ', error); } diff --git a/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts b/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts index 50ac1e83fe..90c557b856 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/destroy-foundry.ts @@ -3,11 +3,11 @@ import { getUnlockedWallet } from '../../wallet/common'; -// In this example we will try to destroy the first foundry there is in the account. This is only possible if its +// In this example we will try to destroy the first foundry there is in the wallet. This is only possible if its // circulating supply is 0 and no native tokens were burned. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/destroy-foundry.ts @@ -16,37 +16,34 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); if (balance.foundries.length == 0) { - throw new Error(`No Foundry available in account 'Alice'`); + throw new Error(`No Foundry available in the wallet`); } - // We try to destroy the first foundry in the account + // We try to destroy the first foundry in the wallet const foundry = balance.foundries[0]; console.log(`Foundries before destroying: ${balance.foundries.length}`); // Burn a foundry - const transaction = await account + const transaction = await wallet .prepareDestroyFoundry(foundry) .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); console.log(`Foundries after destroying: ${balance.foundries.length}`); } catch (error) { console.log('Error: ', error); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/melt.ts b/bindings/nodejs/examples/how_tos/native_tokens/melt.ts index d2381f0888..5826a1c851 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/melt.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/melt.ts @@ -9,7 +9,7 @@ const MELT_AMOUNT = BigInt(10); // In this example we will melt an existing native token with its foundry. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/melt.ts @@ -18,11 +18,8 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); if (balance.foundries.length == 0) { throw new Error(`No Foundry available in account 'Alice'`); @@ -36,14 +33,14 @@ async function run() { ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance before melting: ${token.available}`); // Melt some of the circulating supply - const transaction = await account.meltNativeToken( + const transaction = await wallet.meltNativeToken( token.tokenId, MELT_AMOUNT, ); @@ -51,7 +48,7 @@ async function run() { console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -59,13 +56,13 @@ async function run() { `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); token = balance.nativeTokens.find( (nativeToken) => nativeToken.tokenId == tokenId, ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance after melting: ${token.available}`); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/mint.ts b/bindings/nodejs/examples/how_tos/native_tokens/mint.ts index 6fa0aead4b..56a7362824 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/mint.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/mint.ts @@ -9,7 +9,7 @@ const MINT_AMOUNT = BigInt(10); // In this example we will mint an existing native token with its foundry. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/mint.ts @@ -18,11 +18,8 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); if (balance.foundries.length == 0) { throw new Error(`No Foundry available in account 'Alice'`); @@ -36,20 +33,20 @@ async function run() { ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance before minting: ${token.available}`); // Mint some more native tokens - const transaction = await account + const transaction = await wallet .prepareMintNativeToken(token.tokenId, MINT_AMOUNT) .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -57,13 +54,13 @@ async function run() { `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); token = balance.nativeTokens.find( (nativeToken) => nativeToken.tokenId == tokenId, ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance after minting: ${token.available}`); diff --git a/bindings/nodejs/examples/how_tos/native_tokens/send.ts b/bindings/nodejs/examples/how_tos/native_tokens/send.ts index 4b3824eec8..a42a1459b4 100644 --- a/bindings/nodejs/examples/how_tos/native_tokens/send.ts +++ b/bindings/nodejs/examples/how_tos/native_tokens/send.ts @@ -14,7 +14,7 @@ const RECV_ADDRESS = // In this example we will send native tokens. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/native_tokens/send.ts @@ -23,11 +23,8 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); // Get a token with sufficient balance const tokenId = balance.nativeTokens.find( @@ -47,17 +44,17 @@ async function run() { ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance before sending: ${token.available}`); - const transaction = await account.sendNativeTokens(outputs); + const transaction = await wallet.sendNativeTokens(outputs); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -65,13 +62,13 @@ async function run() { `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`, ); - balance = await account.sync(); + balance = await wallet.sync(); token = balance.nativeTokens.find( (nativeToken) => nativeToken.tokenId == tokenId, ); if (token == null) { throw new Error( - `Couldn't find native token '${tokenId}' in the account`, + `Couldn't find native token '${tokenId}' in the wallet`, ); } console.log(`Balance after sending: ${token.available}`); diff --git a/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts b/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts index 9850ec2e81..1106c6ecbd 100644 --- a/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts +++ b/bindings/nodejs/examples/how_tos/nft_collection/00_mint_issuer_nft.ts @@ -14,7 +14,7 @@ require('dotenv').config({ path: '.env' }); // In this example we will mint the issuer NFT for the NFT collection. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/nft_collection/00_mint_issuer_nft.ts @@ -34,11 +34,8 @@ async function run() { // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - await account.sync(); - console.log(`Account synced!`); + await wallet.sync(); + console.log(`Wallet synced!`); // Issue the minting transaction and wait for its inclusion console.log(`Sending NFT minting transaction...`); @@ -47,10 +44,10 @@ async function run() { 'This NFT will be the issuer from the awesome NFT collection', ), }; - const transaction = await account.mintNfts([params]); + const transaction = await wallet.mintNfts([params]); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( diff --git a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts index f5f607ce3b..6f7a6034ea 100644 --- a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts +++ b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts @@ -12,7 +12,7 @@ const NUM_NFTS_MINTED_PER_TRANSACTION = 50; // In this example we will mint the issuer NFT for the NFT collection. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/nfts/01_mint_collection_nft.ts @@ -32,11 +32,9 @@ async function run() { // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); - // Get the account we generated with `how_tos/accounts_and_addresses/create-account` - const account = await wallet.getAccount('Alice'); - - await account.sync(); - console.log(`Account synced!`); + // Get the wallet we generated with `how_tos/accounts_and_addresses/create-wallet` + await wallet.sync(); + console.log(`Wallet synced!`); // Get the id we generated with `00_mint_issuer_nft` const issuerNftId: NftId = process.argv[2]; @@ -70,10 +68,10 @@ async function run() { i + chunk.length }/${NFT_COLLECTION_SIZE})`, ); - const transaction = await account.mintNfts(chunk); + const transaction = await wallet.mintNfts(chunk); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( @@ -81,7 +79,7 @@ async function run() { ); // Sync so the new outputs are available again for new transactions - await account.sync(); + await wallet.sync(); } // After the NFTs are minted, the issuer nft can be sent to the so called "null address" diff --git a/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts index c9ac0ef987..d72d9dba05 100644 --- a/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts @@ -7,7 +7,7 @@ require('dotenv').config({ path: '.env' }); // In this example we will burn an existing nft output. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/nfts/burn_nft.ts @@ -24,19 +24,14 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - // We need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); - // May want to ensure the account is synced before sending a transaction. - let balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + let balance = await wallet.sync(); if (balance.nfts.length == 0) { - throw new Error( - `No NFT available in account '${process.env.ACCOUNT_ALIAS_1}'`, - ); + throw new Error(`No NFT available in the wallet`); } // Get the first nft const nftId = balance.nfts[0]; @@ -44,14 +39,14 @@ async function run() { console.log(`Balance BEFORE burning:\n`, balance); // Burn an NFT - const transaction = await account + const transaction = await wallet .prepareBurnNft(nftId) .then((prepared) => prepared.send()); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); console.log( @@ -59,7 +54,7 @@ async function run() { ); console.log(`Burned NFT ${nftId}`); - balance = await account.sync(); + balance = await wallet.sync(); console.log(`Balance AFTER burning:\n`, balance); } catch (error) { console.log('Error: ', error); diff --git a/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts index de78ab4d04..98378daacf 100644 --- a/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts @@ -27,7 +27,7 @@ const NFT2_AMOUNT = '1000000'; // In this example we will mint a new nft. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/nfts/mint_nft.ts @@ -43,10 +43,8 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - - // We send from the first address in the account. - const senderAddress = (await account.addresses())[0].address; + // We send from the address in the wallet. + const senderAddress = await wallet.address(); // We need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); @@ -65,11 +63,11 @@ async function run() { issuer: senderAddress, immutableMetadata: metadata.asHex(), }; - let transaction = await account.mintNfts([params]); + let transaction = await wallet.mintNfts([params]); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - let blockId = await account.reissueTransactionUntilIncluded( + let blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -96,11 +94,11 @@ async function run() { features: [new SenderFeature(new Ed25519Address(hexAddress))], }); - transaction = await account.sendOutputs([output]); + transaction = await wallet.sendOutputs([output]); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - blockId = await account.reissueTransactionUntilIncluded( + blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -110,8 +108,8 @@ async function run() { console.log('Minted NFT 2'); - // Ensure the account is synced after minting. - await account.sync(); + // Ensure the wallet is synced after minting. + await wallet.sync(); } catch (error) { console.error('Error: ', error); } diff --git a/bindings/nodejs/examples/how_tos/nfts/send_nft.ts b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts index 77097345c2..907efaa23c 100644 --- a/bindings/nodejs/examples/how_tos/nfts/send_nft.ts +++ b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts @@ -11,7 +11,7 @@ const RECV_ADDRESS = // In this example we will send an NFT (Non-fungible token). // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./how_tos/nfts/send_nft.ts @@ -27,14 +27,11 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - // We need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); - // May want to ensure the account is synced before sending a transaction. - const balance = await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + const balance = await wallet.sync(); if (balance.nfts.length == 0) { throw new Error('No available NFTs'); @@ -50,12 +47,12 @@ async function run() { ]; // Send the full NFT output to the specified address - const transaction = await account.sendNft(outputs); + const transaction = await wallet.sendNft(outputs); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); @@ -64,7 +61,7 @@ async function run() { ); // To send an NFT with expiration unlock condition prepareOutput() can be used like this: - // const output = await account.prepareOutput({ + // const output = await wallet.prepareOutput({ // recipientAddress: 'rms1qz6aj69rumk3qu0ra5ag6p6kk8ga3j8rfjlaym3wefugs3mmxgzfwa6kw3l', // amount: "47000", // unlocks: { @@ -76,7 +73,7 @@ async function run() { // storageDeposit: { returnStrategy: 'Gift' } // }); - // const transaction = await account.sendOutputs([output]); + // const transaction = await wallet.sendOutputs([output]); } catch (error) { console.log('Error: ', error); } diff --git a/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts b/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts index 2a86b934ef..8236e5d3dc 100644 --- a/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts +++ b/bindings/nodejs/examples/how_tos/simple_transaction/request-funds.ts @@ -23,10 +23,7 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - // Get the account we generated with `create-account` - const account = await wallet.getAccount('Alice'); - - const address = (await account.addresses())[0].address; + const address = await wallet.address(); console.log(address); const faucetResponse = await ( diff --git a/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts b/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts index 78c4079e5b..ec1249840b 100644 --- a/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts +++ b/bindings/nodejs/examples/how_tos/simple_transaction/simple-transaction.ts @@ -23,9 +23,7 @@ async function run() { storagePath: process.env.WALLET_DB_PATH, }); - const account = await wallet.getAccount('Alice'); - - await account.sync(); + await wallet.sync(); // To sign a transaction we need to unlock stronghold. await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); @@ -35,7 +33,7 @@ async function run() { 'rms1qrrv7flg6lz5cssvzv2lsdt8c673khad060l4quev6q09tkm9mgtupgf0h0'; const amount = BigInt(1000000); - const response = await account.send(amount, address); + const response = await wallet.send(amount, address); console.log( `Block sent: ${process.env.EXPLORER_URL}/block/${response.blockId}`, diff --git a/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts b/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts index d466cd282e..ff839d0746 100644 --- a/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts +++ b/bindings/nodejs/examples/wallet/06-send-micro-transaction.ts @@ -14,7 +14,7 @@ const RECV_ADDRESS = // In this example we will send an amount below the minimum storage deposit. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./wallet/06-send-micro-transaction.ts @@ -23,11 +23,8 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); - - // May want to ensure the account is synced before sending a transaction. - await account.sync(); + // May want to ensure the wallet is synced before sending a transaction. + await wallet.sync(); console.log( `Sending '${SEND_MICRO_AMOUNT}' coin(s) to '${RECV_ADDRESS}'...`, @@ -36,13 +33,13 @@ async function run() { { address: RECV_ADDRESS, amount: SEND_MICRO_AMOUNT }, ]; - const transaction = await account.sendWithParams(params, { + const transaction = await wallet.sendWithParams(params, { allowMicroAmount: true, }); console.log(`Transaction sent: ${transaction.transactionId}`); // Wait for transaction to get included - const blockId = await account.reissueTransactionUntilIncluded( + const blockId = await wallet.reissueTransactionUntilIncluded( transaction.transactionId, ); diff --git a/bindings/nodejs/examples/wallet/17-check-unlock-conditions.ts b/bindings/nodejs/examples/wallet/17-check-unlock-conditions.ts index 0b48964e74..2e1faa23e5 100644 --- a/bindings/nodejs/examples/wallet/17-check-unlock-conditions.ts +++ b/bindings/nodejs/examples/wallet/17-check-unlock-conditions.ts @@ -8,10 +8,10 @@ import { getUnlockedWallet } from './common'; // The amount to build the basic output with const AMOUNT = BigInt(1000000); -// In this example we check if an output has only an address unlock condition and that the address is from the account. +// In this example we check if an output has only an address unlock condition and that the address is from the wallet. // // Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by -// running the `how_tos/accounts_and_addresses/create-account` example! +// running the `how_tos/accounts_and_addresses/create-wallet` example! // // Rename `.env.example` to `.env` first, then run // yarn run-example ./wallet/17-check-unlock-conditions.ts @@ -20,40 +20,35 @@ async function run() { // Create the wallet const wallet = await getUnlockedWallet(); - // Get the account we generated with `01-create-wallet` - const account = await wallet.getAccount('Alice'); + const walletAddress = await wallet.address(); - const accountAddresses = await account.addresses(); - - const output: Output = await account.prepareOutput({ - recipientAddress: accountAddresses[0].address, + const output: Output = await wallet.prepareOutput({ + recipientAddress: walletAddress, amount: AMOUNT, }); - const hexEncodedAccountAddresses = accountAddresses.map((a) => - Utils.bech32ToHex(a.address), - ); + const hexEncodedwalletAddress = Utils.bech32ToHex(walletAddress); if (output instanceof BasicOutput) { const basicOutput = output as BasicOutput; - let controlledByAccount = false; + let controlledByWallet = false; if ( basicOutput.unlockConditions.length === 1 && basicOutput.unlockConditions[0] instanceof AddressUnlockCondition && - hexEncodedAccountAddresses.includes( + hexEncodedwalletAddress.includes( ( basicOutput .unlockConditions[0] as AddressUnlockCondition ).address.toString(), ) ) { - controlledByAccount = true; + controlledByWallet = true; } console.log( - 'The output has only an address unlock condition and the address is from the account: ' + - controlledByAccount, + 'The output has only an address unlock condition and the address is from the wallet: ' + + controlledByWallet, ); } } catch (error) { diff --git a/bindings/nodejs/examples/wallet/common.ts b/bindings/nodejs/examples/wallet/common.ts index 642d28ff88..4479a2a00f 100644 --- a/bindings/nodejs/examples/wallet/common.ts +++ b/bindings/nodejs/examples/wallet/common.ts @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { initLogger, Wallet, CoinType, WalletOptions } from '@iota/sdk'; +import { initLogger, Wallet, WalletOptions } from '@iota/sdk'; // This example uses secrets in environment variables for simplicity which should not be done in production. require('dotenv').config({ path: '.env' }); @@ -21,16 +21,6 @@ async function getUnlockedWallet() { const walletOptions: WalletOptions = { storagePath: process.env.WALLET_DB_PATH, - clientOptions: { - nodes: [process.env.NODE_URL as string], - }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: process.env.STRONGHOLD_SNAPSHOT_PATH, - password: process.env.STRONGHOLD_PASSWORD, - }, - }, }; const wallet = new Wallet(walletOptions); diff --git a/bindings/nodejs/examples/wallet/events.ts b/bindings/nodejs/examples/wallet/events.ts index 0657f4c831..13e7663064 100644 --- a/bindings/nodejs/examples/wallet/events.ts +++ b/bindings/nodejs/examples/wallet/events.ts @@ -25,12 +25,7 @@ async function run() { const wallet = await getUnlockedWallet(); const callback = function (err: any, event: Event) { - console.log( - 'AccountIndex:', - event.accountIndex, - ', Event:', - event.event, - ); + console.log('Event:', event); }; await wallet.listen([], callback); diff --git a/bindings/nodejs/examples/wallet/getting-started.ts b/bindings/nodejs/examples/wallet/getting-started.ts index 1913122e68..541020e59b 100644 --- a/bindings/nodejs/examples/wallet/getting-started.ts +++ b/bindings/nodejs/examples/wallet/getting-started.ts @@ -1,7 +1,13 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { Wallet, CoinType, WalletOptions, Utils } from '@iota/sdk'; +import { + Wallet, + CoinType, + WalletOptions, + Utils, + SecretManager, +} from '@iota/sdk'; // Run with command: // yarn run-example ./wallet/getting-started.ts @@ -9,9 +15,6 @@ import { Wallet, CoinType, WalletOptions, Utils } from '@iota/sdk'; // The database path. const WALLET_DB_PATH = 'getting-started-db'; -// A name to associate with the created account. -const ACCOUNT_ALIAS = 'Alice'; - // The node to connect to. const NODE_URL = 'https://api.testnet.shimmer.network'; @@ -19,40 +22,53 @@ const NODE_URL = 'https://api.testnet.shimmer.network'; // WARNING: Never hardcode passwords in production code. const STRONGHOLD_PASSWORD = 'a-secure-password'; -// The path to store the account snapshot. +// The path to store the wallet snapshot. const STRONGHOLD_SNAPSHOT_PATH = 'vault.stronghold'; async function main() { - const walletOptions: WalletOptions = { - storagePath: WALLET_DB_PATH, - clientOptions: { - nodes: [NODE_URL], - }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: STRONGHOLD_SNAPSHOT_PATH, - password: STRONGHOLD_PASSWORD, - }, + const strongholdSecretManager = { + stronghold: { + snapshotPath: STRONGHOLD_SNAPSHOT_PATH, + password: STRONGHOLD_PASSWORD, }, }; - const wallet = new Wallet(walletOptions); + const secretManager = new SecretManager(strongholdSecretManager); // Generate a mnemonic and store its seed in the Stronghold vault. // INFO: It is best practice to back up the mnemonic somewhere secure. const mnemonic = Utils.generateMnemonic(); console.log('Mnemonic:' + mnemonic); - await wallet.storeMnemonic(mnemonic); - // Create an account. - const account = await wallet.createAccount({ - alias: ACCOUNT_ALIAS, + // Store the mnemonic in the Stronghold snapshot, this needs to be done only the first time. + // The mnemonic can't be retrieved from the Stronghold file, so make a backup in a secure place! + await secretManager.storeMnemonic(mnemonic); + + const wallet_address = await secretManager.generateEd25519Addresses({ + coinType: CoinType.IOTA, + accountIndex: 0, + range: { + start: 0, + end: 1, + }, + bech32Hrp: 'tst', }); - // Get the first address and print it. - const address = (await account.addresses())[0]; - console.log(`Address: ${address.address}\n`); + const walletOptions: WalletOptions = { + address: wallet_address[0], + storagePath: WALLET_DB_PATH, + clientOptions: { + nodes: [NODE_URL as string], + }, + bipPath: { + coinType: CoinType.IOTA, + }, + secretManager: strongholdSecretManager, + }; + + const wallet = new Wallet(walletOptions); + + console.log('Generated wallet with address: ' + (await wallet.address())); process.exit(0); } diff --git a/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts b/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts index 0a3663a269..04d67eb36c 100644 --- a/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts +++ b/bindings/nodejs/examples/wallet/migrate-stronghold-snapshot-v2-to-v3.ts @@ -1,12 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { - CoinType, - WalletOptions, - Wallet, - migrateStrongholdSnapshotV2ToV3, -} from '@iota/sdk'; +import { migrateStrongholdSnapshotV2ToV3, SecretManager } from '@iota/sdk'; require('dotenv').config({ path: '.env' }); const v2Path = '../../../sdk/tests/wallet/fixtures/v2.stronghold'; @@ -21,23 +16,16 @@ async function run() { throw new Error(`.env ${envVar} is undefined, see .env.example`); } - let walletOptions: WalletOptions = { - storagePath: process.env.WALLET_DB_PATH, - clientOptions: { - nodes: [process.env.NODE_URL as string], - }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: v2Path, - password: 'current_password', - }, + const strongholdSecretManager = { + stronghold: { + snapshotPath: process.env.STRONGHOLD_SNAPSHOT_PATH, + password: process.env.STRONGHOLD_PASSWORD, }, }; try { // This should fail with error, migration required. - new Wallet(walletOptions); + new SecretManager(strongholdSecretManager); } catch (error) { console.error(error); } @@ -51,22 +39,8 @@ async function run() { 'new_password', ); - walletOptions = { - storagePath: process.env.WALLET_DB_PATH, - clientOptions: { - nodes: [process.env.NODE_URL as string], - }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: v3Path, - password: 'new_password', - }, - }, - }; - // This shouldn't fail anymore as snapshot has been migrated. - new Wallet(walletOptions); + new SecretManager(strongholdSecretManager); } run().then(() => process.exit()); diff --git a/bindings/nodejs/lib/types/wallet/address.ts b/bindings/nodejs/lib/types/wallet/address.ts index 04bc9b84b0..c88fbf5fde 100644 --- a/bindings/nodejs/lib/types/wallet/address.ts +++ b/bindings/nodejs/lib/types/wallet/address.ts @@ -24,7 +24,7 @@ export interface SendParams { /** * Bech32 encoded address, to which the storage deposit will be returned if one is necessary * given the provided amount. If a storage deposit is needed and a return address is not provided, it will - * default to the first address of the account. + * default to the address of the wallet. */ returnAddress?: string; /** @@ -43,7 +43,7 @@ export interface SendNativeTokensParams { nativeTokens: [TokenId, u256][]; /** * Bech32 encoded address, to which the storage deposit will be returned. - * Default will use the first address of the account. + * Default will use the address of the wallet. */ returnAddress?: Bech32Address; /** diff --git a/bindings/nodejs/lib/types/wallet/transaction-options.ts b/bindings/nodejs/lib/types/wallet/transaction-options.ts index eebf1c2e2c..5184335c61 100644 --- a/bindings/nodejs/lib/types/wallet/transaction-options.ts +++ b/bindings/nodejs/lib/types/wallet/transaction-options.ts @@ -77,7 +77,7 @@ export interface CreateNativeTokenParams { /** Options for minting NFTs. */ export interface MintNftParams { /** Bech32 encoded address to which the Nft will be minted. Default will use the - * first address of the account + * address of the wallet. */ address?: Bech32Address; /** Bech32 encoded sender address **/ @@ -95,7 +95,7 @@ export interface MintNftParams { /** Options for the account output creation */ export interface AccountOutputParams { /** Bech32 encoded address to which the Nft will be minted. Default will use the - * first address of the account + * address of the wallet. */ address?: Bech32Address; /** Hex encoded bytes */ diff --git a/bindings/nodejs/lib/types/wallet/wallet.ts b/bindings/nodejs/lib/types/wallet/wallet.ts index e40cc53203..85e2d77d92 100644 --- a/bindings/nodejs/lib/types/wallet/wallet.ts +++ b/bindings/nodejs/lib/types/wallet/wallet.ts @@ -78,7 +78,7 @@ export interface NativeTokenBalance { available: u256; } -/** Sync options for an account */ +/** Sync options for a wallet */ export interface SyncOptions { /** * Usually syncing is skipped if it's called in between 200ms, because there can only be new changes every diff --git a/bindings/nodejs/lib/wallet/wallet.ts b/bindings/nodejs/lib/wallet/wallet.ts index c4f70b9683..545d7e7fa3 100644 --- a/bindings/nodejs/lib/wallet/wallet.ts +++ b/bindings/nodejs/lib/wallet/wallet.ts @@ -399,7 +399,7 @@ export class Wallet { /** * Claim basic or nft outputs that have additional unlock conditions - * to their `AddressUnlockCondition` from the account. + * to their `AddressUnlockCondition` from the wallet. * @param outputIds The outputs to claim. * @returns The resulting transaction. */ @@ -419,7 +419,7 @@ export class Wallet { } /** - * Consolidate basic outputs with only an `AddressUnlockCondition` from an account + * Consolidate basic outputs with only an `AddressUnlockCondition` from a wallet * by sending them to an own address again if the output amount is greater or * equal to the output consolidation threshold. * @param params Consolidation options. @@ -432,7 +432,7 @@ export class Wallet { } /** - * Consolidate basic outputs with only an `AddressUnlockCondition` from an account + * Consolidate basic outputs with only an `AddressUnlockCondition` from a wallet * by sending them to an own address again if the output amount is greater or * equal to the output consolidation threshold. * @param params Consolidation options. @@ -757,7 +757,7 @@ export class Wallet { /** * Get a `FoundryOutput` by native token ID. It will try to get the foundry from - * the account, if it isn't in the account it will try to get it from the node. + * the account, if it isn't in the wallet it will try to get it from the node. * * @param tokenId The native token ID to get the foundry for. * @returns The `FoundryOutput` that minted the token. @@ -789,7 +789,7 @@ export class Wallet { } /** - * Get a transaction stored in the account. + * Get a transaction stored in the wallet. * * @param transactionId The ID of the transaction to get. * @returns The transaction. @@ -810,7 +810,7 @@ export class Wallet { } /** - * Get the transaction with inputs of an incoming transaction stored in the account + * Get the transaction with inputs of an incoming transaction stored in the wallet * List might not be complete, if the node pruned the data already * * @param transactionId The ID of the transaction to get. @@ -1229,7 +1229,7 @@ export class Wallet { } /** - * Reissues a transaction sent from the account for a provided transaction id until it's + * Reissues a transaction sent from the wallet for a provided transaction id until it's * included (referenced by a milestone). Returns the included block id. */ async reissueTransactionUntilIncluded( @@ -1493,7 +1493,7 @@ export class Wallet { } /** - * Validate the transaction, submit it to a node and store it in the account. + * Validate the transaction, submit it to a node and store it in the wallet. * * @param signedTransactionData A signed transaction to submit and store. * @returns The sent transaction. @@ -1584,7 +1584,7 @@ export class Wallet { } /** - * Calculates the voting overview of an account. + * Calculates the voting overview of a wallet. * * @param eventIds Optional, filters participations only for provided events. * @returns An instance of `ParticipationOverview` diff --git a/bindings/nodejs/tests/wallet/wallet.spec.ts b/bindings/nodejs/tests/wallet/wallet.spec.ts index 09e1d48784..427d374559 100644 --- a/bindings/nodejs/tests/wallet/wallet.spec.ts +++ b/bindings/nodejs/tests/wallet/wallet.spec.ts @@ -4,119 +4,93 @@ import 'reflect-metadata'; import { describe, it, expect } from '@jest/globals'; -import { Wallet, CoinType, WalletOptions } from '../../lib/'; +import { Wallet, CoinType, WalletOptions, SecretManager } from '../../lib/'; describe('Wallet', () => { - it('create account', async () => { - let storagePath = 'test-create-account'; + it('create wallet', async () => { + let storagePath = 'test-create-wallet'; removeDir(storagePath); - const walletOptions = { - storagePath: './test-create-account', - clientOptions: { - nodes: ['https://api.testnet.shimmer.network'], - }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: `./${storagePath}/wallet.stronghold`, - password: `A12345678*`, - }, + const strongholdSecretManager = { + stronghold: { + snapshotPath: `./${storagePath}/wallet.stronghold`, + password: `A12345678*`, }, }; - const wallet = new Wallet(walletOptions); - await wallet.storeMnemonic( - 'vital give early extra blind skin eight discover scissors there globe deal goat fat load robot return rate fragile recycle select live ordinary claim', - ); - - const account = await wallet.createAccount({ - alias: 'Alice', - }); - - expect(account.getMetadata().index).toStrictEqual(0); + const secretManager = new SecretManager(strongholdSecretManager); - await wallet.destroy() - removeDir(storagePath) - }, 8000); + await secretManager.storeMnemonic('vital give early extra blind skin eight discover scissors there globe deal goat fat load robot return rate fragile recycle select live ordinary claim',); - it('generate address', async () => { - let storagePath = 'test-generate-address'; - removeDir(storagePath); + const wallet_address = await secretManager.generateEd25519Addresses({ + coinType: CoinType.IOTA, + accountIndex: 0, + range: { + start: 0, + end: 1, + }, + bech32Hrp: 'tst', + }); const walletOptions: WalletOptions = { - storagePath, + address: wallet_address[0], + storagePath: './test-create-wallet', clientOptions: { nodes: ['https://api.testnet.shimmer.network'], }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: `./${storagePath}/wallet.stronghold`, - password: `A12345678*`, - }, + bipPath: { + coinType: CoinType.IOTA, }, + secretManager: strongholdSecretManager, }; + const wallet = new Wallet(walletOptions); - await wallet.storeMnemonic( - 'vital give early extra blind skin eight discover scissors there globe deal goat fat load robot return rate fragile recycle select live ordinary claim', - ); - - const address = await wallet.generateEd25519Address( - 0, - 0, - { internal: false, ledgerNanoPrompt: false }, - 'rms', - ); - - expect(address).toStrictEqual( - 'rms1qpqzgvcehafmlxh87zrf9w8ck8q2kw5070ztf68ylhzk89en9a4fy5jqrg8', - ); - - const anotherAddress = await wallet.generateEd25519Address( - 10, - 10, - { internal: true, ledgerNanoPrompt: false }, - 'tst', - ); - - expect(anotherAddress).toStrictEqual( - 'tst1qzp37j45rkfmqn05fapq66vyw0vkmz5zqhmeuey5fked0wt4ry43jeqp2wv', - ); await wallet.destroy() removeDir(storagePath) }, 8000); + it('recreate wallet', async () => { let storagePath = 'test-recreate-wallet'; removeDir(storagePath); - const walletOptions = { - storagePath, + const strongholdSecretManager = { + stronghold: { + snapshotPath: `./${storagePath}/wallet.stronghold`, + password: `A12345678*`, + }, + }; + + const secretManager = new SecretManager(strongholdSecretManager); + + await secretManager.storeMnemonic('vital give early extra blind skin eight discover scissors there globe deal goat fat load robot return rate fragile recycle select live ordinary claim',); + + const wallet_address = await secretManager.generateEd25519Addresses({ + coinType: CoinType.IOTA, + accountIndex: 0, + range: { + start: 0, + end: 1, + }, + bech32Hrp: 'tst', + }); + + const walletOptions: WalletOptions = { + address: wallet_address[0], + storagePath: './test-recreate-wallet', clientOptions: { nodes: ['https://api.testnet.shimmer.network'], }, - coinType: CoinType.Shimmer, - secretManager: { - stronghold: { - snapshotPath: `./${storagePath}/wallet.stronghold`, - password: `A12345678*`, - }, + bipPath: { + coinType: CoinType.IOTA, }, + secretManager: strongholdSecretManager, }; - const wallet = new Wallet(walletOptions); - await wallet.storeMnemonic( - 'vital give early extra blind skin eight discover scissors there globe deal goat fat load robot return rate fragile recycle select live ordinary claim', - ); - const account = await wallet.createAccount({ - alias: 'Alice', - }); - - expect(account.getMetadata().index).toStrictEqual(0); + const wallet = new Wallet(walletOptions); const client = await wallet.getClient(); const hrp = await client.getBech32Hrp(); @@ -124,9 +98,7 @@ describe('Wallet', () => { await wallet.destroy(); - const recreatedWallet = new Wallet(walletOptions); - const accounts = await recreatedWallet.getAccounts(); - expect(accounts.length).toStrictEqual(1); + const recreatedWallet = new Wallet({ storagePath: './test-recreate-wallet' }); await recreatedWallet.destroy() removeDir(storagePath) diff --git a/bindings/python/examples/client/05_get_address_balance.py b/bindings/python/examples/client/05_get_address_balance.py index be1745f320..d849fd69ea 100644 --- a/bindings/python/examples/client/05_get_address_balance.py +++ b/bindings/python/examples/client/05_get_address_balance.py @@ -2,7 +2,7 @@ from dotenv import load_dotenv -from iota_sdk import Client, NodeIndexerAPI +from iota_sdk import Client, NodeIndexerAPI, FeatureType load_dotenv() @@ -35,8 +35,10 @@ for output_with_metadata in outputs: output = output_with_metadata.output total_amount += output.amount - if output.native_tokens: - native_tokens.append(output.native_tokens) + native_token = [feature for feature in output.features if feature.type + == FeatureType.NativeToken] + if native_token: + native_tokens.append(native_token) print( f'Outputs controlled by {ADDRESS} have {total_amount} glow and native tokens: {native_tokens}') diff --git a/bindings/python/examples/exchange/1_create_account.py b/bindings/python/examples/exchange/1_create_account.py index 6146522fe0..d870accd6d 100644 --- a/bindings/python/examples/exchange/1_create_account.py +++ b/bindings/python/examples/exchange/1_create_account.py @@ -1,7 +1,7 @@ # Copyright 2023 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -# This example creates a new database and account. +# This example creates a new database and wallet. import os diff --git a/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py b/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py index 129a53de1e..261446ff26 100644 --- a/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py +++ b/bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py @@ -2,7 +2,7 @@ from dotenv import load_dotenv -from iota_sdk import ConsolidationParams, Utils, Wallet +from iota_sdk import ConsolidationParams, Utils, Wallet, FeatureType # In this example we will consolidate basic outputs from an account with only an AddressUnlockCondition by sending # them to the same address again. @@ -27,7 +27,7 @@ # List unspent outputs before consolidation. # The output we created with example `request_funds` and the basic output from `mint` have only one # unlock condition and it is an `AddressUnlockCondition`, and so they are valid for consolidation. They have the -# same `AddressUnlockCondition`(the first address of the account), so they will be consolidated into one +# same `AddressUnlockCondition`(the address of the wallet), so they will be consolidated into one # output. outputs = account.unspent_outputs() print('Outputs BEFORE consolidation:') @@ -38,7 +38,8 @@ '- address: {}\n- amount: {}\n- native tokens: {}'.format( Utils.hex_to_bech32(output_data.address.pub_key_hash, 'rms'), output_data.output.amount, - output_data.output.native_tokens + [feature for feature in output_data.output.features if feature.type + == FeatureType.NativeToken] ) ) @@ -71,6 +72,7 @@ '- address: {}\n- amount: {}\n- native tokens: {}'.format( Utils.hex_to_bech32(output_data.address.pub_key_hash, 'rms'), output_data.output.amount, - output_data.output.native_tokens + [feature for feature in output_data.output.features if feature.type + == FeatureType.NativeToken] ) ) diff --git a/bindings/python/examples/how_tos/accounts_and_addresses/create_account.py b/bindings/python/examples/how_tos/accounts_and_addresses/create_account.py index 55dbc1abb0..09758a6c23 100644 --- a/bindings/python/examples/how_tos/accounts_and_addresses/create_account.py +++ b/bindings/python/examples/how_tos/accounts_and_addresses/create_account.py @@ -6,7 +6,7 @@ load_dotenv() -# This example creates a new database and account +# This example creates a new database and wallet node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') client_options = ClientOptions(nodes=[node_url]) diff --git a/bindings/python/examples/wallet/backup.py b/bindings/python/examples/wallet/backup.py index b34ad45433..b5302bb3df 100644 --- a/bindings/python/examples/wallet/backup.py +++ b/bindings/python/examples/wallet/backup.py @@ -6,7 +6,7 @@ load_dotenv() -# This example creates a new database and account +# This example creates a new database and wallet node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network') client_options = ClientOptions(nodes=[node_url]) diff --git a/bindings/python/examples/wallet/logger.py b/bindings/python/examples/wallet/logger.py index c10b2aa806..30c0019a14 100644 --- a/bindings/python/examples/wallet/logger.py +++ b/bindings/python/examples/wallet/logger.py @@ -9,7 +9,7 @@ load_dotenv() -# This example creates a new database and account and write debug logs in +# This example creates a new database and wallet and write debug logs in # `wallet.log`. log_config = { diff --git a/bindings/python/iota_sdk/client/client.py b/bindings/python/iota_sdk/client/client.py index fbcd621509..06e38a42cc 100644 --- a/bindings/python/iota_sdk/client/client.py +++ b/bindings/python/iota_sdk/client/client.py @@ -14,7 +14,6 @@ from iota_sdk.types.block.signed_block import UnsignedBlock from iota_sdk.types.common import HexStr, Node from iota_sdk.types.feature import Feature -from iota_sdk.types.native_token import NativeToken from iota_sdk.types.network_info import NetworkInfo from iota_sdk.types.output import AccountOutput, BasicOutput, FoundryOutput, NftOutput, deserialize_output from iota_sdk.types.payload import Payload @@ -151,7 +150,6 @@ def build_account_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, foundry_counter: Optional[int] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> AccountOutput: @@ -162,7 +160,6 @@ def build_account_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. foundry_counter: A counter that denotes the number of foundries created by this account output. features: A list of features. immutable_features: A list of immutable features. @@ -174,10 +171,6 @@ def build_account_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.to_dict() - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -195,7 +188,6 @@ def build_account_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'foundryCounter': foundry_counter, 'features': features, 'immutableFeatures': immutable_features @@ -205,7 +197,6 @@ def build_basic_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None) -> BasicOutput: """Build a BasicOutput. @@ -213,7 +204,6 @@ def build_basic_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. Returns: @@ -223,10 +213,6 @@ def build_basic_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.to_dict() - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] @@ -240,7 +226,6 @@ def build_basic_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'features': features, })) @@ -249,7 +234,6 @@ def build_foundry_output(self, token_scheme: SimpleTokenScheme, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> FoundryOutput: """Build a FoundryOutput. @@ -259,7 +243,6 @@ def build_foundry_output(self, token_scheme: Defines the supply control scheme of the tokens controlled by the foundry. Currently only a simple scheme is supported. unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. immutable_features: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. @@ -270,10 +253,6 @@ def build_foundry_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.__dict__ - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -288,7 +267,6 @@ def build_foundry_output(self, 'tokenScheme': token_scheme.to_dict(), 'unlockConditions': unlock_conditions, 'amount': amount, - 'nativeTokens': native_tokens, 'features': features, 'immutableFeatures': immutable_features })) @@ -298,7 +276,6 @@ def build_nft_output(self, unlock_conditions: List[UnlockCondition], amount: Optional[int] = None, mana: Optional[int] = None, - native_tokens: Optional[List[NativeToken]] = None, features: Optional[List[Feature]] = None, immutable_features: Optional[List[Feature]] = None) -> NftOutput: """Build an NftOutput. @@ -308,7 +285,6 @@ def build_nft_output(self, unlock_conditions: The unlock conditions for the new output. amount: The amount of base coins in the new output. mana: Amount of stored Mana held by this output. - native_tokens: Native tokens added to the new output. features: Features that add utility to the output but do not impose unlocking conditions. immutable_features: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. @@ -319,10 +295,6 @@ def build_nft_output(self, unlock_conditions = [unlock_condition.to_dict() for unlock_condition in unlock_conditions] - if native_tokens: - native_tokens = [native_token.__dict__ - for native_token in native_tokens] - if features: features = [feature.to_dict() for feature in features] if immutable_features: @@ -340,7 +312,6 @@ def build_nft_output(self, 'unlockConditions': unlock_conditions, 'amount': amount, 'mana': mana, - 'nativeTokens': native_tokens, 'features': features, 'immutableFeatures': immutable_features })) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 7b392f2ca1..cb4064f4ac 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -7,7 +7,7 @@ from dataclasses_json import config from iota_sdk.types.address import Address, deserialize_address from iota_sdk.types.block_issuer_key import BlockIssuerKey -from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex +from iota_sdk.types.common import EpochIndex, HexStr, hex_str_decoder, json, SlotIndex class FeatureType(IntEnum): @@ -18,15 +18,17 @@ class FeatureType(IntEnum): Issuer (1): The issuer feature. Metadata (2): The metadata feature. Tag (3): The tag feature. - BlockIssuer (4): The block issuer feature. - Staking (5): The staking feature. + NativeToken (4): The native token feature. + BlockIssuer (5): The block issuer feature. + Staking (6): The staking feature. """ Sender = 0 Issuer = 1 Metadata = 2 Tag = 3 - BlockIssuer = 4 - Staking = 5 + NativeToken = 4 + BlockIssuer = 5 + Staking = 6 @json @@ -88,6 +90,22 @@ class TagFeature: type: int = field(default_factory=lambda: int(FeatureType.Tag), init=False) +@json +@dataclass +class NativeTokenFeature: + """Contains a native token. + id: The unique identifier of the native token. + amount: The amount of native tokens. + """ + id: HexStr + amount: int = field(metadata=config( + encoder=hex, + decoder=hex_str_decoder, + )) + type: int = field(default_factory=lambda: int( + FeatureType.NativeToken), init=False) + + @json @dataclass class BlockIssuerFeature: @@ -129,7 +147,7 @@ class StakingFeature: Feature: TypeAlias = Union[SenderFeature, IssuerFeature, - MetadataFeature, TagFeature, BlockIssuerFeature, StakingFeature] + MetadataFeature, TagFeature, NativeTokenFeature, BlockIssuerFeature, StakingFeature] def deserialize_feature(d: Dict[str, Any]) -> Feature: @@ -148,6 +166,8 @@ def deserialize_feature(d: Dict[str, Any]) -> Feature: return MetadataFeature.from_dict(d) if feature_type == FeatureType.Tag: return TagFeature.from_dict(d) + if feature_type == FeatureType.NativeToken: + return NativeTokenFeature.from_dict(d) if feature_type == FeatureType.BlockIssuer: return BlockIssuerFeature.from_dict(d) if feature_type == FeatureType.Staking: diff --git a/bindings/python/iota_sdk/types/output.py b/bindings/python/iota_sdk/types/output.py index 92769c780a..345bd73fab 100644 --- a/bindings/python/iota_sdk/types/output.py +++ b/bindings/python/iota_sdk/types/output.py @@ -7,8 +7,7 @@ from dataclasses import dataclass, field from dataclasses_json import config from iota_sdk.types.common import HexStr, json, EpochIndex -from iota_sdk.types.feature import deserialize_features, SenderFeature, IssuerFeature, MetadataFeature, TagFeature -from iota_sdk.types.native_token import NativeToken +from iota_sdk.types.feature import deserialize_features, SenderFeature, IssuerFeature, MetadataFeature, TagFeature, NativeTokenFeature from iota_sdk.types.token_scheme import SimpleTokenScheme from iota_sdk.types.unlock_condition import deserialize_unlock_conditions, AddressUnlockCondition, StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition, ExpirationUnlockCondition, ImmutableAccountAddressUnlockCondition @@ -46,8 +45,6 @@ class BasicOutput: The conditions to unlock the output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. type : The type of output. """ @@ -62,11 +59,10 @@ class BasicOutput: decoder=deserialize_unlock_conditions )) features: Optional[List[Union[SenderFeature, - MetadataFeature, TagFeature]]] = field(default=None, - metadata=config( - decoder=deserialize_features - )) - native_tokens: Optional[List[NativeToken]] = None + MetadataFeature, TagFeature, NativeTokenFeature]]] = field(default=None, + metadata=config( + decoder=deserialize_features + )) type: int = field( default_factory=lambda: int( OutputType.Basic), @@ -90,8 +86,6 @@ class AccountOutput: A counter that denotes the number of foundries created by this account output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. type : @@ -119,7 +113,6 @@ class AccountOutput: metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Account), @@ -147,8 +140,6 @@ class AnchorOutput: Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. state_metadata : Metadata that can only be changed by the state controller. - native_tokens : - Native tokens added to the new output. type : The type of output. """ @@ -176,7 +167,6 @@ class AnchorOutput: decoder=deserialize_features )) state_metadata: Optional[HexStr] = None - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Anchor), @@ -194,8 +184,6 @@ class FoundryOutput: The conditions to unlock the output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. serial_number : @@ -211,15 +199,14 @@ class FoundryOutput: serial_number: int token_scheme: SimpleTokenScheme unlock_conditions: List[ImmutableAccountAddressUnlockCondition] - features: Optional[List[MetadataFeature]] = field(default=None, - metadata=config( - decoder=deserialize_features - )) + features: Optional[List[Union[MetadataFeature, NativeTokenFeature]]] = field(default=None, + metadata=config( + decoder=deserialize_features + )) immutable_features: Optional[List[MetadataFeature]] = field(default=None, metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field( default_factory=lambda: int( OutputType.Foundry), @@ -241,8 +228,6 @@ class NftOutput: The NFT ID if it's an NFT output. features : Features that add utility to the output but do not impose unlocking conditions. - native_tokens : - Native tokens added to the new output. immutable_features : Features that add utility to the output but do not impose unlocking conditions. These features need to be kept in future transitions of the UTXO state machine. type : @@ -270,7 +255,6 @@ class NftOutput: metadata=config( decoder=deserialize_features )) - native_tokens: Optional[List[NativeToken]] = None type: int = field(default_factory=lambda: int(OutputType.Nft), init=False) diff --git a/bindings/python/iota_sdk/types/send_params.py b/bindings/python/iota_sdk/types/send_params.py index cd3e404472..c8f47f5e0d 100644 --- a/bindings/python/iota_sdk/types/send_params.py +++ b/bindings/python/iota_sdk/types/send_params.py @@ -89,7 +89,7 @@ class MintNftParams(): """Parameters for minting NFTs. Attributes: - address: A Bech32 encoded address to which the NFT will be minted. Default will use the first address of the account. + address: A Bech32 encoded address to which the NFT will be minted. Default will use the address of the wallet. sender: An NFT sender feature. metadata: An NFT metadata feature. tag: An NFT tag feature. @@ -110,7 +110,7 @@ class CreateAccountOutputParams(): """Parameters for creating accounts. Attributes: - address: A Bech32 encoded address which will control the account. Default will use the first address of the account. + address: A Bech32 encoded address which will control the account. Default will use the address of the wallet. immutable_metadata: Immutable account metadata. metadata: Account metadata. """ diff --git a/bindings/python/iota_sdk/wallet/account.py b/bindings/python/iota_sdk/wallet/account.py index 7219e560e9..1d0a463097 100644 --- a/bindings/python/iota_sdk/wallet/account.py +++ b/bindings/python/iota_sdk/wallet/account.py @@ -283,7 +283,7 @@ def accounts(self) -> List[OutputData]: """ outputs = self._call_account_method( 'accounts' - ) + ) return [from_dict(OutputData, o) for o in outputs] def implicit_accounts(self) -> List[OutputData]: @@ -291,7 +291,7 @@ def implicit_accounts(self) -> List[OutputData]: """ outputs = self._call_account_method( 'implicitAccounts' - ) + ) return [from_dict(OutputData, o) for o in outputs] def incoming_transactions(self) -> List[TransactionWithMetadata]: diff --git a/bindings/wasm/examples/node.js b/bindings/wasm/examples/node.js index 6a779abebb..57489f2303 100644 --- a/bindings/wasm/examples/node.js +++ b/bindings/wasm/examples/node.js @@ -3,7 +3,7 @@ const console = require('console'); const fs = require('fs'); -const { Wallet, CoinType, initLogger } = require('../node/lib'); +const { Wallet, CoinType, initLogger, SecretManager } = require('../node/lib'); async function run() { try { @@ -19,27 +19,36 @@ async function run() { colorEnabled: true, }); + const mnemonicSecretManager = { + mnemonic: + 'inhale gorilla deny three celery song category owner lottery rent author wealth penalty crawl hobby obtain glad warm early rain clutch slab august bleak', + }; + + const secretManager = new SecretManager(mnemonicSecretManager); + + const walletAddress = await secretManager.generateEd25519Addresses({ + coinType: CoinType.IOTA, + accountIndex: 0, + range: { + start: 0, + end: 1, + }, + bech32Hrp: 'tst', + }); + const wallet = new Wallet({ + address: walletAddress[0], storagePath: './alice-database', - coinType: CoinType.Shimmer, + bipPath: { + coinType: CoinType.IOTA, + }, clientOptions: { nodes: ['https://api.testnet.shimmer.network'], }, - secretManager: { - mnemonic: - 'inhale gorilla deny three celery song category owner lottery rent author wealth penalty crawl hobby obtain glad warm early rain clutch slab august bleak', - }, + secretManager: mnemonicSecretManager, }); - const account = await wallet.createAccount({ - alias: 'Alice', - bech32Hrp: 'rms', - }); - - console.log('Account created:', account); - account.setAlias('new alias'); - - const balance = await account.sync(); + const balance = await wallet.sync(); console.log(balance); } diff --git a/bindings/wasm/test/account.spec.ts b/bindings/wasm/test/account.spec.ts index 37ac3ef02b..56a206d467 100644 --- a/bindings/wasm/test/account.spec.ts +++ b/bindings/wasm/test/account.spec.ts @@ -29,7 +29,7 @@ async function run() { expect(account.getMetadata().alias).toBe('Alice'); - const balance: Balance = await account.sync(); + const balance: Balance = await wallet.sync(); expect(balance.baseCoin.available).not.toBeNaN(); await account.setAlias('new alias'); diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 62dfbaec12..f534b2e41b 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -19,9 +19,9 @@ use iota_sdk::{ }, payload::signed_transaction::TransactionId, slot::SlotIndex, - ConvertTo, }, }, + utils::ConvertTo, wallet::{ types::{OutputData, TransactionWithMetadata}, ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim, SendNativeTokensParams, diff --git a/sdk/src/client/api/address.rs b/sdk/src/client/api/address.rs index 173de7289f..6d5501d4d7 100644 --- a/sdk/src/client/api/address.rs +++ b/sdk/src/client/api/address.rs @@ -12,10 +12,8 @@ use crate::{ secret::{GenerateAddressOptions, SecretManage, SecretManager}, Client, Result, }, - types::block::{ - address::{Address, Bech32Address, Hrp, ToBech32Ext}, - ConvertTo, - }, + types::block::address::{Address, Bech32Address, Hrp, ToBech32Ext}, + utils::ConvertTo, }; #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/sdk/src/client/node_api/participation.rs b/sdk/src/client/node_api/participation.rs index 68c721fa2f..5f9dddc4a4 100644 --- a/sdk/src/client/node_api/participation.rs +++ b/sdk/src/client/node_api/participation.rs @@ -15,8 +15,9 @@ use crate::{ ParticipationEventType, }, }, - block::{address::Bech32Address, output::OutputId, ConvertTo}, + block::{address::Bech32Address, output::OutputId}, }, + utils::ConvertTo, }; impl ClientInner { diff --git a/sdk/src/client/utils.rs b/sdk/src/client/utils.rs index da07957425..ba2f0056aa 100644 --- a/sdk/src/client/utils.rs +++ b/sdk/src/client/utils.rs @@ -21,8 +21,9 @@ use crate::{ address::{Address, Bech32Address, Ed25519Address, Hrp, ToBech32Ext}, output::{AccountId, NftId}, payload::TaggedDataPayload, - BlockId, ConvertTo, SignedBlock, + BlockId, SignedBlock, }, + utils::ConvertTo, }; /// Transforms bech32 to hex diff --git a/sdk/src/types/block/address/bech32.rs b/sdk/src/types/block/address/bech32.rs index cbc8d26d5b..36cbe7bbea 100644 --- a/sdk/src/types/block/address/bech32.rs +++ b/sdk/src/types/block/address/bech32.rs @@ -16,9 +16,12 @@ use packable::{ Packable, PackableExt, }; -use crate::types::block::{ - address::{Address, MultiAddress}, - ConvertTo, Error, +use crate::{ + types::block::{ + address::{Address, MultiAddress}, + Error, + }, + utils::ConvertTo, }; #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, Display)] diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index 4857bf4093..4a8021ad8e 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -26,12 +26,15 @@ pub use self::{ nft::NftAddress, restricted::{AddressCapabilities, AddressCapabilityFlag, RestrictedAddress}, }; -use crate::types::block::{ - output::Output, - semantic::{SemanticValidationContext, TransactionFailureReason}, - signature::Signature, - unlock::Unlock, - ConvertTo, Error, +use crate::{ + types::block::{ + output::Output, + semantic::{SemanticValidationContext, TransactionFailureReason}, + signature::Signature, + unlock::Unlock, + Error, + }, + utils::ConvertTo, }; /// A generic address supporting different address kinds. diff --git a/sdk/src/types/block/macro.rs b/sdk/src/types/block/macro.rs index d4783a93cd..b7a5b6695a 100644 --- a/sdk/src/types/block/macro.rs +++ b/sdk/src/types/block/macro.rs @@ -75,13 +75,13 @@ macro_rules! impl_id { } } - impl $crate::types::block::ConvertTo<$hash_name> for &alloc::string::String { + impl $crate::utils::ConvertTo<$hash_name> for &alloc::string::String { fn convert(self) -> Result<$hash_name, $crate::types::block::Error> { self.try_into() } } - impl $crate::types::block::ConvertTo<$hash_name> for &str { + impl $crate::utils::ConvertTo<$hash_name> for &str { fn convert(self) -> Result<$hash_name, $crate::types::block::Error> { self.try_into() } @@ -205,13 +205,13 @@ macro_rules! impl_id { } } - impl $crate::types::block::ConvertTo<$id_name> for &alloc::string::String { + impl $crate::utils::ConvertTo<$id_name> for &alloc::string::String { fn convert(self) -> Result<$id_name, $crate::types::block::Error> { self.try_into() } } - impl $crate::types::block::ConvertTo<$id_name> for &str { + impl $crate::utils::ConvertTo<$id_name> for &str { fn convert(self) -> Result<$id_name, $crate::types::block::Error> { self.try_into() } diff --git a/sdk/src/types/block/mod.rs b/sdk/src/types/block/mod.rs index d010281bab..df210e8224 100644 --- a/sdk/src/types/block/mod.rs +++ b/sdk/src/types/block/mod.rs @@ -4,7 +4,6 @@ //! Core data types for blocks in the tangle. mod block_id; -mod convert; mod error; mod issuer_id; mod r#macro; @@ -46,7 +45,6 @@ pub use self::core::dto::{BlockDto, SignedBlockDto, UnsignedBlockDto}; pub(crate) use self::r#macro::*; pub use self::{ block_id::{BlockHash, BlockId}, - convert::ConvertTo, core::{Block, SignedBlock, UnsignedBlock}, error::Error, issuer_id::IssuerId, diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 3dee4b05f3..e389d899c8 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -1,7 +1,7 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use alloc::{collections::BTreeSet, vec::Vec}; +use alloc::collections::BTreeSet; use hashbrown::HashMap; use packable::{ @@ -11,24 +11,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -623,13 +618,15 @@ fn verify_unlock_conditions(unlock_conditions: &UnlockConditions, account_id: &A #[cfg(feature = "serde")] pub(crate) mod dto { + use alloc::vec::Vec; + use serde::{Deserialize, Serialize}; use super::*; use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 8dccff6276..e6d5c03e8d 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -13,24 +13,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{Address, AnchorAddress}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{Address, AnchorAddress}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -711,7 +706,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::{prefix_hex_bytes, string}, }; diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 7b99c1c574..0eb2281963 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -5,23 +5,18 @@ use alloc::collections::BTreeSet; use packable::Packable; -use crate::types::{ - block::{ - address::Address, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, - }, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::Address, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, }, - ValidationParams, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; /// Builder for a [`BasicOutput`]. @@ -313,7 +308,7 @@ impl BasicOutput { /// Checks whether the basic output is an implicit account. pub fn is_implicit_account(&self) -> bool { if let [UnlockCondition::Address(uc)] = self.unlock_conditions().as_ref() { - uc.address().is_implicit_account_creation() && self.native_tokens.is_empty() && self.features.is_empty() + uc.address().is_implicit_account_creation() } else { false } @@ -361,7 +356,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index 0097d54dc4..1562a35169 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -5,24 +5,19 @@ use alloc::collections::BTreeSet; use packable::Packable; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - chain_id::ChainId, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, Output, OutputBuilderAmount, OutputId, Rent, - RentStructure, StateTransitionError, StateTransitionVerifier, - }, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - slot::EpochIndex, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + chain_id::ChainId, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, Output, OutputBuilderAmount, OutputId, Rent, + RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + slot::EpochIndex, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -442,7 +437,7 @@ pub(crate) mod dto { output::{unlock_condition::dto::UnlockConditionDto, OutputBuilderAmount}, Error, }, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index f979bc1a5d..f918872ca5 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -12,26 +12,21 @@ use packable::{ }; use primitive_types::U256; -use crate::types::{ - block::{ - address::{AccountAddress, Address}, - output::{ - account::AccountId, - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, TokenId, - TokenScheme, - }, - payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{AccountAddress, Address}, + output::{ + account::AccountId, + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, TokenId, + TokenScheme, }, - ValidationParams, + payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -679,7 +674,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 28c32ff138..599d451d07 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -10,24 +10,19 @@ use packable::{ Packable, }; -use crate::types::{ - block::{ - address::{Address, NftAddress}, - output::{ - feature::{verify_allowed_features, Feature, FeatureFlags, Features}, - unlock_condition::{ - verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions, - }, - verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, - }, - payload::signed_transaction::TransactionCapabilityFlag, - protocol::ProtocolParameters, - semantic::{SemanticValidationContext, TransactionFailureReason}, - unlock::Unlock, - Error, +use crate::types::block::{ + address::{Address, NftAddress}, + output::{ + feature::{verify_allowed_features, Feature, FeatureFlags, Features}, + unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, + verify_output_amount_min, verify_output_amount_packable, ChainId, NativeToken, NativeTokens, Output, + OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError, StateTransitionVerifier, }, - ValidationParams, + payload::signed_transaction::TransactionCapabilityFlag, + protocol::ProtocolParameters, + semantic::{SemanticValidationContext, TransactionFailureReason}, + unlock::Unlock, + Error, }; crate::impl_id!( @@ -541,7 +536,7 @@ pub(crate) mod dto { use crate::{ types::{ block::{output::unlock_condition::dto::UnlockConditionDto, Error}, - TryFromDto, + TryFromDto, ValidationParams, }, utils::serde::string, }; diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 25556c4fd2..30ecf8e94f 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -13,7 +13,10 @@ use super::{ mana::{ManaParameters, RewardsParameters}, slot::{EpochIndex, SlotIndex}, }; -use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION}; +use crate::{ + types::block::{helper::network_name_to_id, output::RentStructure, Error, PROTOCOL_VERSION}, + utils::ConvertTo, +}; /// Defines the parameters of the protocol at a particular version. #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable, Getters, CopyGetters)] diff --git a/sdk/src/types/block/unlock/account.rs b/sdk/src/types/block/unlock/account.rs index 25ade32fcd..f8f7872ac3 100644 --- a/sdk/src/types/block/unlock/account.rs +++ b/sdk/src/types/block/unlock/account.rs @@ -36,6 +36,7 @@ impl AccountUnlock { } } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/anchor.rs b/sdk/src/types/block/unlock/anchor.rs index cc9f6d9e64..aad3c49b78 100644 --- a/sdk/src/types/block/unlock/anchor.rs +++ b/sdk/src/types/block/unlock/anchor.rs @@ -36,6 +36,7 @@ impl AnchorUnlock { } } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/empty.rs b/sdk/src/types/block/unlock/empty.rs index a4b89ff15a..2449e7668f 100644 --- a/sdk/src/types/block/unlock/empty.rs +++ b/sdk/src/types/block/unlock/empty.rs @@ -11,6 +11,7 @@ impl EmptyUnlock { pub const KIND: u8 = 6; } +#[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; diff --git a/sdk/src/types/block/unlock/multi.rs b/sdk/src/types/block/unlock/multi.rs index 024a9d8c88..99a2f2f0fd 100644 --- a/sdk/src/types/block/unlock/multi.rs +++ b/sdk/src/types/block/unlock/multi.rs @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use alloc::{boxed::Box, vec::Vec}; +use alloc::boxed::Box; use derive_more::Deref; use packable::{prefix::BoxedSlicePrefix, Packable}; @@ -46,7 +46,10 @@ fn verify_unlocks(unlocks: &[Unlock], _visitor: &()) -> Resu } } +#[cfg(feature = "serde")] mod dto { + use alloc::vec::Vec; + use serde::{Deserialize, Serialize}; use super::*; diff --git a/sdk/src/types/block/convert.rs b/sdk/src/utils/convert.rs similarity index 100% rename from sdk/src/types/block/convert.rs rename to sdk/src/utils/convert.rs diff --git a/sdk/src/utils/mod.rs b/sdk/src/utils/mod.rs index 9671dfe13d..1341ced35a 100644 --- a/sdk/src/utils/mod.rs +++ b/sdk/src/utils/mod.rs @@ -1,6 +1,10 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +mod convert; + pub mod merkle_hasher; #[cfg(feature = "serde")] pub mod serde; + +pub use convert::ConvertTo; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs index 76246b9b14..779227f649 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs @@ -13,9 +13,9 @@ use crate::{ block::{ address::{AccountAddress, Bech32Address, ToBech32Ext}, output::{Output, OutputId}, - ConvertTo, }, }, + utils::ConvertTo, wallet::{operations::syncing::SyncOptions, task, Wallet}, }; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs index d709c49a22..4374d0c859 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs @@ -3,7 +3,8 @@ use crate::{ client::{node_api::indexer::query_parameters::BasicOutputQueryParameters, secret::SecretManage}, - types::block::{address::Bech32Address, output::OutputId, ConvertTo}, + types::block::{address::Bech32Address, output::OutputId}, + utils::ConvertTo, wallet::Wallet, }; diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs index b445d4dfd1..5430bcb009 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs @@ -3,7 +3,8 @@ use crate::{ client::{node_api::indexer::query_parameters::NftOutputQueryParameters, secret::SecretManage}, - types::block::{address::Bech32Address, output::OutputId, ConvertTo}, + types::block::{address::Bech32Address, output::OutputId}, + utils::ConvertTo, wallet::Wallet, }; diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs index c9c4400023..3bef7fc38d 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs @@ -13,8 +13,8 @@ use crate::{ unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, }, - ConvertTo, }, + utils::ConvertTo, wallet::{ operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, @@ -26,7 +26,7 @@ use crate::{ #[serde(rename_all = "camelCase")] pub struct MintNftParams { /// Bech32 encoded address to which the NFT will be minted. Default will use the - /// first address of the account. + /// address of the wallet. #[getset(get = "pub")] address: Option, /// NFT sender feature. diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index 235572f0e7..e1e36f24b7 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -15,9 +15,8 @@ use crate::{ BasicOutputBuilder, MinimumStorageDepositBasicOutput, }, slot::SlotIndex, - ConvertTo, }, - utils::serde::string, + utils::{serde::string, ConvertTo}, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, operations::transaction::{TransactionOptions, TransactionWithMetadata}, @@ -37,7 +36,7 @@ pub struct SendParams { address: Bech32Address, /// Bech32 encoded return address, to which the storage deposit will be returned if one is necessary /// given the provided amount. If a storage deposit is needed and a return address is not provided, it will - /// default to the first address of the account. + /// default to the address of the wallet. #[getset(get = "pub")] return_address: Option, /// Expiration in slot indices, after which the output will be available for the sender again, if not spent by the diff --git a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs index bf02fd7797..c487b043a9 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs @@ -16,8 +16,8 @@ use crate::{ BasicOutputBuilder, MinimumStorageDepositBasicOutput, NativeToken, NativeTokens, TokenId, }, slot::SlotIndex, - ConvertTo, }, + utils::ConvertTo, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, operations::transaction::{TransactionOptions, TransactionWithMetadata}, @@ -36,7 +36,7 @@ pub struct SendNativeTokensParams { #[getset(get = "pub")] native_tokens: Vec<(TokenId, U256)>, /// Bech32 encoded address return address, to which the storage deposit will be returned. Default will use the - /// first address of the account + /// address of the wallet. #[getset(get = "pub")] return_address: Option, /// Expiration in slot indices, after which the output will be available for the sender again, if not spent by the diff --git a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs index 1eb3dc31f6..33212d22a5 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -9,8 +9,8 @@ use crate::{ types::block::{ address::Bech32Address, output::{unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, Output}, - ConvertTo, }, + utils::ConvertTo, wallet::{ operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, diff --git a/sdk/src/wallet/types/address.rs b/sdk/src/wallet/types/address.rs index a1539ad157..2eced539d4 100644 --- a/sdk/src/wallet/types/address.rs +++ b/sdk/src/wallet/types/address.rs @@ -6,9 +6,12 @@ use std::hash::Hash; use getset::{Getters, Setters}; use serde::{Deserialize, Serialize}; -use crate::types::{ - self, - block::{address::Bech32Address, output::OutputId, ConvertTo}, +use crate::{ + types::{ + self, + block::{address::Bech32Address, output::OutputId}, + }, + utils::ConvertTo, }; /// A BIP44 address.