mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-05 11:57:41 +00:00
51 lines
1.9 KiB
Dart
51 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:bip47/bip47.dart';
|
|
import 'package:bitcoindart/bitcoindart.dart';
|
|
import 'package:pointycastle/digests/sha256.dart';
|
|
import 'package:stackwallet/hive/db.dart';
|
|
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
extension PayNym on DogecoinWallet {
|
|
// fetch or generate this wallet's bip47 payment code
|
|
Future<PaymentCode> getPaymentCode() async {
|
|
final paymentCodeString = DB.instance
|
|
.get<dynamic>(boxName: walletId, key: "paymentCodeString") as String?;
|
|
PaymentCode paymentCode;
|
|
if (paymentCodeString == null) {
|
|
final node = getBip32Root((await mnemonic).join(" "), network)
|
|
.derivePath("m/47'/0'/0'");
|
|
paymentCode =
|
|
PaymentCode.initFromPubKey(node.publicKey, node.chainCode, network);
|
|
await DB.instance.put<dynamic>(
|
|
boxName: walletId,
|
|
key: "paymentCodeString",
|
|
value: paymentCode.toString());
|
|
} else {
|
|
paymentCode = PaymentCode.fromPaymentCode(paymentCodeString, network);
|
|
}
|
|
return paymentCode;
|
|
}
|
|
|
|
Future<Uint8List> signWithNotificationKey(Uint8List data) async {
|
|
final node = getBip32Root((await mnemonic).join(" "), network)
|
|
.derivePath("m/47'/0'/0'");
|
|
final pair = ECPair.fromPrivateKey(node.privateKey!, network: network);
|
|
final signed = pair.sign(SHA256Digest().process(data));
|
|
return signed;
|
|
}
|
|
|
|
Future<String> signStringWithNotificationKey(String data) async {
|
|
final bytes =
|
|
await signWithNotificationKey(Uint8List.fromList(utf8.encode(data)));
|
|
return Format.uint8listToString(bytes);
|
|
// final bytes =
|
|
// await signWithNotificationKey(Uint8List.fromList(utf8.encode(data)));
|
|
// return Format.uint8listToString(bytes);
|
|
}
|
|
|
|
// Future<Map<String, dynamic>> prepareNotificationTransaction(
|
|
// String targetPaymentCode) async {}
|
|
}
|