Skip to content

Commit 595827d

Browse files
committed
fix: migrate address book
1 parent 7b66de5 commit 595827d

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

packages/adena-extension/src/migrates/migrations/v009/storage-migration-v009.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { StorageModel } from '@common/storage';
22
import { encryptWalletPassword } from '@common/utils/crypto-utils';
33
import { Migration } from '@migrates/migrator';
4-
import { AdenaWallet, decryptAES, mnemonicToEntropy } from 'adena-module';
4+
import { AdenaWallet, decryptAES, encryptAES, mnemonicToEntropy } from 'adena-module';
55
import {
6+
AddressBookModelV008,
67
SerializedModelV008,
78
StorageModelDataV008,
89
WalletModelV008,
910
} from '../v008/storage-model-v008';
10-
import { SerializedModelV009, StorageModelDataV009 } from './storage-model-v009';
11+
import {
12+
AddressBookModelV009,
13+
SerializedModelV009,
14+
StorageModelDataV009,
15+
} from './storage-model-v009';
1116

1217
export class StorageMigration009 implements Migration<StorageModelDataV009> {
1318
public readonly version = 9;
@@ -25,10 +30,12 @@ export class StorageMigration009 implements Migration<StorageModelDataV009> {
2530
}
2631
const previous: StorageModelDataV008 = current.data;
2732
const serialized = await this.migrateSerialized(previous.SERIALIZED, password || '');
33+
const addressBook = await this.migrateAddressBook(previous.ADDRESS_BOOK, password || '');
2834
return {
2935
version: this.version,
3036
data: {
3137
...previous,
38+
ADDRESS_BOOK: addressBook,
3239
SERIALIZED: serialized,
3340
},
3441
};
@@ -128,4 +135,26 @@ export class StorageMigration009 implements Migration<StorageModelDataV009> {
128135

129136
return serializedWallet;
130137
}
138+
139+
private async migrateAddressBook(
140+
addressBook: AddressBookModelV008,
141+
password: string,
142+
): Promise<AddressBookModelV009> {
143+
if (!addressBook) {
144+
return addressBook;
145+
}
146+
147+
if (!password) {
148+
return addressBook;
149+
}
150+
151+
let decrypted = await decryptAES(addressBook, password);
152+
153+
const sha256Password = encryptWalletPassword(password);
154+
const encryptedAddressBook = await encryptAES(decrypted, sha256Password);
155+
156+
decrypted = '';
157+
158+
return encryptedAddressBook;
159+
}
131160
}

0 commit comments

Comments
 (0)