SatoshiPortal / bullbitcoin-mobile

The Bull Bitcoin Mobile Wallet and Exchange App
MIT License
54 stars 18 forks source link

[Migration] Update from 0.1.98-1.1 to 0.2.0-alpha #253

Closed i5hi closed 1 month ago

i5hi commented 2 months ago

Main concerns:

class Seed with _$Seed {
  const factory Seed({
    @Default('') String mnemonic,
    @Default('') String mnemonicFingerprint,
    required BBNetwork network,
    required List<Passphrase> passphrases,
  }) = _Seed;

There is nothing in this model that indicates that this is the BullWallet Seed.

For those users who only have one seed, this wont be a problem. We just use that seed.

Looking at _pkg/wallet/repository/secure_storage.dart newSeed


  Future<Err?> newSeed({
    required Seed seed,
  }) async {
    try {
      final fingerprintIndex = seed.getSeedStorageString();
      final (fingerprintIndexes, err) = await _secureStorage.getValue(StorageKeys.seeds);
      if (err != null) {
        // no seeds exist make this the first
        final jsn = jsonEncode({
          'seeds': [fingerprintIndex],
        });
        final _ = await _secureStorage.saveValue(
          key: StorageKeys.seeds,
          value: jsn,
        );
      } else {
        final fingerprintIdsJson = jsonDecode(fingerprintIndexes!)['seeds'] as List<dynamic>;

        final List<String> fingerprints = [];
        for (final fingerprint in fingerprintIdsJson) {
          if (fingerprint == fingerprintIndex)
            return Err('Seed Exists');
          else
            fingerprints.add(fingerprint as String);
        }

        fingerprints.add(fingerprintIndex);

        final jsn = jsonEncode({
          'seeds': [...fingerprints],
        });
        final _ = await _secureStorage.saveValue(
          key: StorageKeys.seeds,
          value: jsn,
        );
      }
      // why are we also storing the seed with the index directly? easier to read? backup?
      await _secureStorage.saveValue(
        key: fingerprintIndex,
        value: jsonEncode(seed),
      );
      return null;
    }

I'm guessing seeds end up being stored in chronological order i.e. the first element is the Bull Wallet seed.

i5hi commented 2 months ago
saiy2k commented 2 months ago

Updates @ https://github.com/SatoshiPortal/bullbitcoin-mobile/pull/270