stack_wallet/lib/wallets/crypto_currency/coins/particl.dart

240 lines
6.7 KiB
Dart
Raw Normal View History

import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
2024-05-27 23:56:22 +00:00
import '../../../models/isar/models/blockchain_data/address.dart';
import '../../../models/node_model.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/default_nodes.dart';
import '../../../utilities/enums/derive_path_type_enum.dart';
import '../crypto_currency.dart';
import '../interfaces/electrumx_currency_interface.dart';
import '../intermediate/bip39_hd_currency.dart';
2024-05-15 21:20:45 +00:00
class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
Particl(super.network) {
2024-05-15 21:20:45 +00:00
_idMain = "particl";
_uriScheme = "particl";
switch (network) {
case CryptoCurrencyNetwork.main:
2024-05-15 21:20:45 +00:00
_id = _idMain;
_name = "Particl";
_ticker = "PART";
default:
throw Exception("Unsupported network: $network");
}
}
2024-05-15 21:20:45 +00:00
late final String _id;
@override
String get identifier => _id;
late final String _idMain;
@override
String get mainNetId => _idMain;
late final String _name;
@override
String get prettyName => _name;
late final String _uriScheme;
@override
String get uriScheme => _uriScheme;
late final String _ticker;
@override
String get ticker => _ticker;
@override
2024-01-09 23:24:51 +00:00
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L57
int get minConfirms => 1;
@override
bool get torSupport => true;
@override
2024-01-09 23:24:51 +00:00
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L68
2024-05-27 23:56:22 +00:00
String constructDerivePath({
required DerivePathType derivePathType,
int account = 0,
required int chain,
required int index,
}) {
2024-01-09 23:24:51 +00:00
String coinType;
switch (networkParams.wifPrefix) {
case 0x6c: // PART mainnet wif.
coinType = "44"; // PART mainnet.
break;
// TODO: [prio=low] Add testnet.
default:
throw Exception("Invalid Particl network wif used!");
}
int purpose;
switch (derivePathType) {
case DerivePathType.bip44:
purpose = 44;
break;
case DerivePathType.bip84:
purpose = 84;
break;
default:
throw Exception("DerivePathType $derivePathType not supported");
}
return "m/$purpose'/$coinType'/$account'/$chain/$index";
}
@override
NodeModel get defaultNode {
switch (network) {
case CryptoCurrencyNetwork.main:
return NodeModel(
host: "particl.stackwallet.com",
port: 58002,
name: DefaultNodes.defaultName,
2024-05-15 21:20:45 +00:00
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
2024-05-15 21:20:45 +00:00
coinName: identifier,
isFailover: true,
isDown: false,
);
2024-01-09 23:24:51 +00:00
// case CryptoCurrencyNetwork.test:
// TODO: [prio=low] Add testnet.
default:
throw UnimplementedError();
}
}
@override
2024-01-09 23:24:51 +00:00
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L58
Amount get dustLimit => Amount(
rawValue: BigInt.from(294),
2024-05-15 21:20:45 +00:00
fractionDigits: fractionDigits,
2024-01-09 23:24:51 +00:00
);
@override
2024-01-09 23:24:51 +00:00
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L63
String get genesisHash {
switch (network) {
case CryptoCurrencyNetwork.main:
return "0000ee0784c195317ac95623e22fddb8c7b8825dc3998e0bb924d66866eccf4c";
case CryptoCurrencyNetwork.test:
return "0000594ada5310b367443ee0afd4fa3d0bbd5850ea4e33cdc7d6a904a7ec7c90";
default:
throw Exception("Unsupported network: $network");
}
}
@override
2024-01-10 16:24:29 +00:00
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey({
required coinlib.ECPublicKey publicKey,
required DerivePathType derivePathType,
}) {
2024-01-09 23:24:51 +00:00
switch (derivePathType) {
case DerivePathType.bip44:
final addr = coinlib.P2PKHAddress.fromPublicKey(
publicKey,
version: networkParams.p2pkhPrefix,
);
return (address: addr, addressType: AddressType.p2pkh);
case DerivePathType.bip84:
final addr = coinlib.P2WPKHAddress.fromPublicKey(
publicKey,
hrp: networkParams.bech32Hrp,
);
return (address: addr, addressType: AddressType.p2wpkh);
default:
throw Exception("DerivePathType $derivePathType not supported");
}
}
@override
2024-01-09 23:24:51 +00:00
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L3532
coinlib.Network get networkParams {
2024-01-09 23:24:51 +00:00
switch (network) {
case CryptoCurrencyNetwork.main:
return coinlib.Network(
2024-01-09 23:24:51 +00:00
wifPrefix: 0x6c,
p2pkhPrefix: 0x38,
p2shPrefix: 0x3c,
privHDPrefix: 0x8f1daeb8,
pubHDPrefix: 0x696e82d1,
bech32Hrp: "pw",
messagePrefix: '\x18Bitcoin Signed Message:\n',
2024-06-07 14:45:56 +00:00
minFee: BigInt.from(1), // Not used in stack wallet currently
minOutput: dustLimit.raw, // Not used in stack wallet currently
feePerKb: BigInt.from(1), // Not used in stack wallet currently
2024-01-09 23:24:51 +00:00
);
// case CryptoCurrencyNetwork.test:
// TODO: [prio=low] Add testnet.
default:
throw Exception("Unsupported network: $network");
}
}
@override
2024-01-09 23:24:51 +00:00
List<DerivePathType> get supportedDerivationPathTypes => [
DerivePathType.bip44,
DerivePathType.bip84,
];
@override
bool validateAddress(String address) {
2024-01-09 23:24:51 +00:00
try {
coinlib.Address.fromString(address, networkParams);
return true;
} catch (_) {
return false;
}
}
@override
2024-05-15 21:20:45 +00:00
int get defaultSeedPhraseLength => 12;
@override
int get fractionDigits => 8;
@override
bool get hasBuySupport => false;
@override
bool get hasMnemonicPassphraseSupport => true;
@override
2024-05-15 21:20:45 +00:00
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 24];
@override
AddressType get defaultAddressType => defaultDerivePathType.getAddressType();
2024-05-15 21:20:45 +00:00
@override
BigInt get satsPerCoin => BigInt.from(100000000);
@override
int get targetBlockTimeSeconds => 600;
@override
DerivePathType get defaultDerivePathType => DerivePathType.bip84;
2024-05-15 21:20:45 +00:00
@override
Uri defaultBlockExplorer(String txid) {
switch (network) {
case CryptoCurrencyNetwork.main:
return Uri.parse("https://chainz.cryptoid.info/part/tx.dws?$txid.htm");
default:
throw Exception(
"Unsupported network for defaultBlockExplorer(): $network",
);
}
}
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(20000);
}