diff --git a/bindings/nodejs/examples/exchange/1-create-account.ts b/bindings/nodejs/examples/exchange/1-create-account.ts index c89c3489de..2af8800162 100644 --- a/bindings/nodejs/examples/exchange/1-create-account.ts +++ b/bindings/nodejs/examples/exchange/1-create-account.ts @@ -12,32 +12,23 @@ require('dotenv').config({ path: '.env' }); async function run() { try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); - } - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_SNAPSHOT_PATH) { - throw new Error( - '.env STRONGHOLD_SNAPSHOT_PATH is undefined, see .env.example', - ); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } + 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], + nodes: [process.env.NODE_URL as string], }, coinType: CoinType.IOTA, secretManager: { @@ -51,7 +42,7 @@ async function run() { const wallet = new Wallet(walletOptions); // Mnemonic only needs to be set the first time. - await wallet.storeMnemonic(process.env.MNEMONIC); + await wallet.storeMnemonic(process.env.MNEMONIC as string); const account = await wallet.createAccount({ alias: 'Alice', diff --git a/bindings/nodejs/examples/exchange/2-generate-address.ts b/bindings/nodejs/examples/exchange/2-generate-address.ts index 7f0ffede5d..6ad4ac8b32 100644 --- a/bindings/nodejs/examples/exchange/2-generate-address.ts +++ b/bindings/nodejs/examples/exchange/2-generate-address.ts @@ -12,22 +12,20 @@ require('dotenv').config({ path: '.env' }); async function run() { try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + 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); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const account = await wallet.getAccount('Alice'); diff --git a/bindings/nodejs/examples/exchange/5-send-amount.ts b/bindings/nodejs/examples/exchange/5-send-amount.ts index e1f32ef304..f493e2abd9 100644 --- a/bindings/nodejs/examples/exchange/5-send-amount.ts +++ b/bindings/nodejs/examples/exchange/5-send-amount.ts @@ -12,25 +12,24 @@ require('dotenv').config({ path: '.env' }); async function run() { try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - if (!process.env.EXPLORER_URL) { - throw new Error('.env EXPLORER_URL is undefined, see .env.example'); - } + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) + 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); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const account = await wallet.getAccount('Alice'); console.log('Account:', account); 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 fcb278c9f5..e103e0168c 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 @@ -14,21 +14,16 @@ require('dotenv').config({ path: '.env' }); async function run() { initLogger(); try { - if (!process.env.WALLET_DB_PATH) { - throw new Error( - '.env WALLET_DB_PATH is undefined, see .env.example', - ); - } - - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - - if (!process.env.EXPLORER_URL) { - throw new Error('.env EXPLORER_URL is undefined, see .env.example'); - } + for (const envVar of [ + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + 'EXPLORER_URL', + ]) + 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, @@ -37,7 +32,9 @@ async function run() { const account = await wallet.getAccount('Alice'); // To create an address we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); // Sync account to make sure account is updated with outputs from previous examples account.sync(); diff --git a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-account.ts b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-account.ts index 3f7f67d669..6c4d08f274 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-account.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-account.ts @@ -12,30 +12,22 @@ require('dotenv').config({ path: '.env' }); // This example creates a new database and account. async function run() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - if (!process.env.STRONGHOLD_SNAPSHOT_PATH) { - throw new Error( - '.env STRONGHOLD_SNAPSHOT_PATH is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } + for (const envVar of [ + 'NODE_URL', + 'STRONGHOLD_PASSWORD', + 'STRONGHOLD_SNAPSHOT_PATH', + 'MNEMONIC', + 'WALLET_DB_PATH', + ]) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { const walletOptions: WalletOptions = { storagePath: process.env.WALLET_DB_PATH, clientOptions: { - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }, coinType: CoinType.Shimmer, secretManager: { @@ -51,7 +43,7 @@ async function run() { // 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 wallet.storeMnemonic(process.env.MNEMONIC); + await wallet.storeMnemonic(process.env.MNEMONIC as string); // Create a new account const account = await wallet.createAccount({ 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 index 63a74b82da..c525a4e16f 100644 --- a/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts +++ b/bindings/nodejs/examples/how_tos/accounts_and_addresses/create-address.ts @@ -10,14 +10,11 @@ require('dotenv').config({ path: '.env' }); // This example creates an address async function run() { initLogger(); - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + 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, @@ -26,7 +23,9 @@ async function run() { const account = await wallet.getAccount('Alice'); // To create an address we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const address = (await account.generateEd25519Addresses(1))[0]; diff --git a/bindings/nodejs/examples/how_tos/alias/create.ts b/bindings/nodejs/examples/how_tos/alias/create.ts index 6ec3b21b7d..7a69e07591 100644 --- a/bindings/nodejs/examples/how_tos/alias/create.ts +++ b/bindings/nodejs/examples/how_tos/alias/create.ts @@ -16,17 +16,15 @@ require('dotenv').config({ path: '.env' }); // In this example we create alias. async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of [ + 'FAUCET_URL', + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + ]) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { // Create the wallet const wallet = new Wallet({ @@ -42,7 +40,9 @@ async function run() { console.log(`Aliases BEFORE:\n`, balance.aliases); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); console.log('Sending the create-alias transaction...'); diff --git a/bindings/nodejs/examples/how_tos/alias/destroy.ts b/bindings/nodejs/examples/how_tos/alias/destroy.ts index daf06145a4..32d3ec9a7d 100644 --- a/bindings/nodejs/examples/how_tos/alias/destroy.ts +++ b/bindings/nodejs/examples/how_tos/alias/destroy.ts @@ -12,17 +12,15 @@ require('dotenv').config({ path: '.env' }); // In this example we destroy alias. async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of [ + 'FAUCET_URL', + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + ]) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { // Create the wallet const wallet = new Wallet({ @@ -48,7 +46,9 @@ async function run() { ); // To sign a transaction we need to unlock stronghold. - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); console.log('Sending the destroy-alias transaction...'); diff --git a/bindings/nodejs/examples/how_tos/alias/governance-transition.ts b/bindings/nodejs/examples/how_tos/alias/governance-transition.ts index b6bd8eda97..87a77deb54 100644 --- a/bindings/nodejs/examples/how_tos/alias/governance-transition.ts +++ b/bindings/nodejs/examples/how_tos/alias/governance-transition.ts @@ -19,17 +19,15 @@ require('dotenv').config({ path: '.env' }); // In this example we will update the state controller of an alias output. async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of [ + 'FAUCET_URL', + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + ]) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { // Create the wallet const wallet = new Wallet({ @@ -56,7 +54,9 @@ async function run() { `Alias ${aliasId} found in unspent output: ${aliasOutputData.outputId}`, ); - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); const newStateController = Utils.parseBech32Address( (await account.generateEd25519Addresses(1))[0].address, diff --git a/bindings/nodejs/examples/how_tos/alias/state-transition.ts b/bindings/nodejs/examples/how_tos/alias/state-transition.ts index ca09fd7aeb..d1b230504a 100644 --- a/bindings/nodejs/examples/how_tos/alias/state-transition.ts +++ b/bindings/nodejs/examples/how_tos/alias/state-transition.ts @@ -14,17 +14,15 @@ const NEW_STATE_METADATA = 'updated state metadata 1'; // In this example we will update the state metadata of an alias output. async function run() { initLogger(); - if (!process.env.FAUCET_URL) { - throw new Error('.env FAUCET_URL is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of [ + 'FAUCET_URL', + 'WALLET_DB_PATH', + 'STRONGHOLD_PASSWORD', + ]) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { // Create the wallet const wallet = new Wallet({ @@ -65,7 +63,9 @@ async function run() { features: aliasOutput.features, }); - await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD); + await wallet.setStrongholdPassword( + process.env.STRONGHOLD_PASSWORD as string, + ); console.log('Sending transaction...'); diff --git a/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts b/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts index 9fc3b99e6e..5b1e992e7b 100644 --- a/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts +++ b/bindings/nodejs/examples/how_tos/sign_and_verify_ed25519/sign-ed25519.ts @@ -30,14 +30,13 @@ async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env stronghold password is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } + for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } + const secretManager = new SecretManager({ stronghold: { password: process.env.STRONGHOLD_PASSWORD, @@ -48,7 +47,7 @@ async function run() { // 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); + await secretManager.storeMnemonic(process.env.MNEMONIC as string); const bip44Chain = { coinType: CoinType.Shimmer, diff --git a/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts b/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts index b5998c76c8..333a5bd0ed 100644 --- a/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts +++ b/bindings/nodejs/examples/how_tos/sign_secp256k1_ecdsa/sign-secp256k1_ecdsa.ts @@ -24,14 +24,13 @@ async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env stronghold password is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } + for (const envVar of ['STRONGHOLD_PASSWORD', 'MNEMONIC']) + if (!(envVar in process.env)) { + throw new Error( + `.env ${envVar} is undefined, see .env.example`, + ); + } + const secretManager = new SecretManager({ stronghold: { password: process.env.STRONGHOLD_PASSWORD, @@ -42,7 +41,7 @@ async function run() { // 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); + await secretManager.storeMnemonic(process.env.MNEMONIC as string); const bip44Chain = { coinType: CoinType.Ether, diff --git a/bindings/nodejs/examples/secret_manager/stronghold.ts b/bindings/nodejs/examples/secret_manager/stronghold.ts index 960703e68f..869204b125 100644 --- a/bindings/nodejs/examples/secret_manager/stronghold.ts +++ b/bindings/nodejs/examples/secret_manager/stronghold.ts @@ -12,13 +12,10 @@ async function run() { initLogger(); try { - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env stronghold password is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); + for (const envVar of ['MNEMONIC', 'STRONGHOLD_PASSWORD']) { + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is not defined`); + } } const strongholdSecretManager = new SecretManager({ stronghold: { @@ -30,7 +27,9 @@ async function run() { // 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 strongholdSecretManager.storeMnemonic(process.env.MNEMONIC); + await strongholdSecretManager.storeMnemonic( + process.env.MNEMONIC as string, + ); const address = await strongholdSecretManager.generateEd25519Addresses({ accountIndex: 0, diff --git a/bindings/nodejs/examples/wallet/common.ts b/bindings/nodejs/examples/wallet/common.ts index 88d85facd2..642d28ff88 100644 --- a/bindings/nodejs/examples/wallet/common.ts +++ b/bindings/nodejs/examples/wallet/common.ts @@ -8,30 +8,21 @@ require('dotenv').config({ path: '.env' }); async function getUnlockedWallet() { initLogger(); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } - if (!process.env.STRONGHOLD_SNAPSHOT_PATH) { - throw new Error( - '.env STRONGHOLD_SNAPSHOT_PATH is undefined, see .env.example', - ); - } - if (!process.env.MNEMONIC) { - throw new Error('.env MNEMONIC is undefined, see .env.example'); - } - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } + for (const envVar of [ + 'NODE_URL', + 'STRONGHOLD_PASSWORD', + 'STRONGHOLD_SNAPSHOT_PATH', + 'MNEMONIC', + 'WALLET_DB_PATH', + ]) + 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], + nodes: [process.env.NODE_URL as string], }, coinType: CoinType.Shimmer, secretManager: { diff --git a/bindings/nodejs/examples/wallet/events.ts b/bindings/nodejs/examples/wallet/events.ts index d087ae5687..0657f4c831 100644 --- a/bindings/nodejs/examples/wallet/events.ts +++ b/bindings/nodejs/examples/wallet/events.ts @@ -15,14 +15,11 @@ require('dotenv').config({ path: '.env' }); // This example listens to wallet events. async function run() { - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } + try { // Create the wallet const wallet = await getUnlockedWallet(); diff --git a/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts b/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts index f33a29de93..5fa766969c 100644 --- a/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts +++ b/bindings/nodejs/examples/wallet/migrate-db-chrysalis-to-stardust.ts @@ -16,21 +16,17 @@ async function run() { levelFilter: 'debug', targetExclusions: ['h2', 'hyper', 'rustls'], }); - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } - if (!process.env.STRONGHOLD_PASSWORD) { - throw new Error( - '.env STRONGHOLD_PASSWORD is undefined, see .env.example', - ); - } + for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) + if (!(envVar in process.env)) { + throw new Error(`.env ${envVar} is undefined, see .env.example`); + } migrateDbChrysalisToStardust(walletDbPath, 'password'); const walletOptions: WalletOptions = { storagePath: walletDbPath, clientOptions: { - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }, secretManager: { stronghold: { 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 55154a1ac2..0a3663a269 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 @@ -16,17 +16,15 @@ const v3Path = './v3.stronghold'; // yarn run-example wallet/migrate-stronghold-snapshot-v2-to-v3.ts async function run() { - if (!process.env.WALLET_DB_PATH) { - throw new Error('.env WALLET_DB_PATH is undefined, see .env.example'); - } - if (!process.env.NODE_URL) { - throw new Error('.env NODE_URL is undefined, see .env.example'); - } + for (const envVar of ['NODE_URL', 'STRONGHOLD_PASSWORD']) + if (!(envVar in process.env)) { + 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], + nodes: [process.env.NODE_URL as string], }, coinType: CoinType.Shimmer, secretManager: { @@ -56,7 +54,7 @@ async function run() { walletOptions = { storagePath: process.env.WALLET_DB_PATH, clientOptions: { - nodes: [process.env.NODE_URL], + nodes: [process.env.NODE_URL as string], }, coinType: CoinType.Shimmer, secretManager: {