From 355218753d373921c242c77eae8f06c4c56caaf5 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 13 May 2025 10:31:43 +0200 Subject: [PATCH] fix: add UR to cw_bitcoin, fix payjoin issue --- cw_bitcoin/lib/bitcoin_wallet_service.dart | 1 + cw_bitcoin/lib/pending_bitcoin_transaction.dart | 13 ++++++++++++- cw_bitcoin/pubspec.lock | 17 +++++++++++++++++ cw_bitcoin/pubspec.yaml | 4 ++++ pubspec_base.yaml | 4 ++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cw_bitcoin/lib/bitcoin_wallet_service.dart b/cw_bitcoin/lib/bitcoin_wallet_service.dart index 74be5e231..0e30c4319 100644 --- a/cw_bitcoin/lib/bitcoin_wallet_service.dart +++ b/cw_bitcoin/lib/bitcoin_wallet_service.dart @@ -181,6 +181,7 @@ class BitcoinWalletService extends WalletService< unspentCoinsInfo: unspentCoinsInfoSource, networkParam: network, encryptionFileUtils: encryptionFileUtilsFor(isDirect), + payjoinBox: payjoinSessionSource, ); await wallet.save(); diff --git a/cw_bitcoin/lib/pending_bitcoin_transaction.dart b/cw_bitcoin/lib/pending_bitcoin_transaction.dart index c95d4e1d7..e07786f76 100644 --- a/cw_bitcoin/lib/pending_bitcoin_transaction.dart +++ b/cw_bitcoin/lib/pending_bitcoin_transaction.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; +import 'dart:typed_data'; + import 'package:cw_bitcoin/electrum_wallet.dart'; import 'package:grpc/grpc.dart'; import 'package:cw_bitcoin/exceptions.dart'; @@ -11,6 +14,9 @@ import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cw_mweb/cw_mweb.dart'; import 'package:cw_mweb/mwebd.pb.dart'; +import 'package:ur/cbor_lite.dart'; +import 'package:ur/ur.dart'; +import 'package:ur/ur_encoder.dart'; class PendingBitcoinTransaction with PendingTransaction { PendingBitcoinTransaction( @@ -165,6 +171,11 @@ class PendingBitcoinTransaction with PendingTransaction { @override Future commitUR() { - return Future.value("test"); + var sourceBytes = Uint8List.fromList(utf8.encode(hex)); + var cborEncoder = CBOREncoder(); + cborEncoder.encodeBytes(sourceBytes); + var ur = UR("psbt", cborEncoder.getBytes()); + var encoded = UREncoder.encode(ur); + return Future.value(encoded); } } diff --git a/cw_bitcoin/pubspec.lock b/cw_bitcoin/pubspec.lock index c2987894c..fe3f87e17 100644 --- a/cw_bitcoin/pubspec.lock +++ b/cw_bitcoin/pubspec.lock @@ -1101,6 +1101,23 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.0" + ur: + dependency: "direct main" + description: + path: "." + ref: "5738f70d0ec3d50977ac3dd01fed62939600238b" + resolved-ref: "5738f70d0ec3d50977ac3dd01fed62939600238b" + url: "https://github.com/bukata-sa/bc-ur-dart" + source: git + version: "0.1.0" + uuid: + dependency: transitive + description: + name: uuid + sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff + url: "https://pub.dev" + source: hosted + version: "4.5.1" vector_math: dependency: transitive description: diff --git a/cw_bitcoin/pubspec.yaml b/cw_bitcoin/pubspec.yaml index c24732c3a..7b82cd61b 100644 --- a/cw_bitcoin/pubspec.yaml +++ b/cw_bitcoin/pubspec.yaml @@ -58,6 +58,10 @@ dependencies: git: url: https://github.com/sneurlax/socks_socket ref: e6232c53c1595469931ababa878759a067c02e94 + ur: + git: + url: https://github.com/bukata-sa/bc-ur-dart + ref: 5738f70d0ec3d50977ac3dd01fed62939600238b dev_dependencies: flutter_test: diff --git a/pubspec_base.yaml b/pubspec_base.yaml index 9f7f17ae4..78eff5f95 100644 --- a/pubspec_base.yaml +++ b/pubspec_base.yaml @@ -130,6 +130,10 @@ dependencies: url: https://github.com/MrCyjaneK/flutter_daemon ref: c24ee99f2f3070ea02d8108bbdd7727d73f7e5f1 flutter_local_notifications: ^19.0.0 + ur: + git: + url: https://github.com/bukata-sa/bc-ur-dart + ref: 5738f70d0ec3d50977ac3dd01fed62939600238b dev_dependencies: flutter_test: