Skip to content

Commit

Permalink
Cleanup, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Aug 1, 2023
1 parent 516d1fa commit 1a2eab6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changes/stronghold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nodejs-binding": patch
---

Added migrateStrongholdSnapshotV2ToV3();
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

const { AccountManager } = require('@iota/wallet');
require('dotenv').config({ path: '.env' });

const v2Path = '../../../../tests/fixtures/v2_with_backup.stronghold';
const v3Path = './migration-database/wallet.stronghold';

// Run with command:
// node run-example wallet/migrate-stronghold-snapshot-v2-to-v3.js

async function run() {
const manager = new AccountManager({
storagePath: './migration-database',
});

manager.migrateStrongholdSnapshotV2ToV3(
v2Path,
'current_password',
'wallet.rs',
100,
v3Path,
// Optional, can also stay the same password
'new_password',
);
console.log('Migrated stronghold');

// This shouldn't fail anymore as snapshot has been migrated.
manager.setStrongholdPassword('new_password');
}

run().then(() => process.exit());
10 changes: 3 additions & 7 deletions bindings/nodejs/src/classes/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,9 @@ pub fn migrate_stronghold_snapshot_v2_to_v3(mut cx: FunctionContext) -> JsResult
new_path.as_ref(),
new_password.as_deref(),
)
.unwrap();
// .or_else(|e| {
// cx.throw_error(
// serde_json::to_string(&Response::Error(e.into()))
// .expect("the response is generated manually, so unwrap is safe."),
// )
// })?;
.or_else(|e| {
cx.throw_error(serde_json::to_string(&e).expect("the response is generated manually, so unwrap is safe."))
})?;

Ok(cx.undefined())
}
11 changes: 0 additions & 11 deletions examples/migrate_stronghold_snapshot_v2_to_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,5 @@ async fn main() -> Result<(), Error> {
// This shouldn't fail anymore as snapshot has been migrated.
manager.set_stronghold_password("new_password").await?;

// Generate addresses with custom account index and range
// let addresses = GetAddressesBuilder::new(&SecretManager::Stronghold(stronghold_secret_manager))
// .with_bech32_hrp(SHIMMER_TESTNET_BECH32_HRP)
// .with_coin_type(SHIMMER_COIN_TYPE)
// .with_account_index(0)
// .with_range(0..1)
// .finish()
// .await?;

// println!("First public address: {}", addresses[0]);

Ok(())
}
10 changes: 1 addition & 9 deletions src/stronghold/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ use std::{
path::{Path, PathBuf},
};

// use crypto::ciphers::chacha::{self};
// use iota_stronghold::{Client, SnapshotPath, Stronghold};
use zeroize::Zeroize;

// use super::common::PRIVATE_DATA_CLIENT_PATH;
use crate::{
actor::AccountManager,
// stronghold::{check_or_create_snapshot, storage::insert as v3_insert},
Result,
StrongholdError,
};
use crate::{actor::AccountManager, Result, StrongholdError};

impl AccountManager {
/// Migrates a stronghold snapshot from version 2 to version 3.
Expand Down

0 comments on commit 1a2eab6

Please sign in to comment.