Bitcoin
This article describes the process of completing a Bitcoin transaction through the SDK.
Support List
Supports PSBT transactions for BTC in both legacy and taproot formats.
- Bitcoin Legacy
- Bitcoin Taproot
GsWalletPsbtSDK
The GsWalletPsbtSDK class mainly implements the following functions:
- Construct BTC transactions.
- Parse signature information.
class GsWalletPsbtSDK {
static UR generateSignRequest({
String? uuid,
required String psbt,
required String path,
required String xfp,
String? origin,
});
static Map<String, dynamic> parseSignature(UR ur);
}
generateSignRequest
static UR generateSignRequest({
String? uuid,
required String psbt,
required String path,
required String xfp,
String? origin,
});
Input parameters
-
uuid:
StringoptionalRepresenting the unique ID of a transaction -
psbt:
StringrequiredPartially Signed Bitcoin Transaction for transmiting the unsigned transaction data (Buffer in hex format). -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
xfp:
StringrequiredMasterFingerprint, used as a unique wallet ID -
origin:
StringoptionalNotes for transaction, usually the name of the cryptocurrency wallet
parseSignature
static Map<String, dynamic> parseSignature(UR ur);
Returns
-
uuid:
Uint8Listtransaction ID. -
psbt:
StringThe hexadecimal information of PSBT. -
origin:
Stringusually "GsWallet".
Example
Construct transaction
import 'package:gs_ur_dart/gs_ur_dart.dart';
UR ur = GsWalletPsbtSDK.generateSignRequest(
uuid: "93dc01f0-8d1a-11ef-9718-cfc8ba00addb",
psbt:
"70736274ff0100b202000000026ec5f5168621d3294db516139b86aba4ec923bba2718503e935898cc47e6d8600000000000ffffffff84a87fa6a6354ea4197aa6f22620ec84118b27eb84d45659984aa8587f3389f30100000000ffffffff02fc0300000000000022512095aff4da1c10e41953deacc322064aab1781c2dcfac1fc72bc9680402b7ab10b6c0b00000000000022512095aff4da1c10e41953deacc322064aab1781c2dcfac1fc72bc9680402b7ab10b000000000001012b0f0800000000000022512095aff4da1c10e41953deacc322064aab1781c2dcfac1fc72bc9680402b7ab10b011720926b23b2ef8ac33cbb881a8673fcd34ca8ce3ae4965b0fba3b0ab268e3ce84c92116926b23b2ef8ac33cbb881a8673fcd34ca8ce3ae4965b0fba3b0ab268e3ce84c919005fcedec356000080000000800000008000000000000000000001012be51600000000000022512095aff4da1c10e41953deacc322064aab1781c2dcfac1fc72bc9680402b7ab10b011720926b23b2ef8ac33cbb881a8673fcd34ca8ce3ae4965b0fba3b0ab268e3ce84c92116926b23b2ef8ac33cbb881a8673fcd34ca8ce3ae4965b0fba3b0ab268e3ce84c919005fcedec356000080000000800000008000000000000000000000220202926b23b2ef8ac33cbb881a8673fcd34ca8ce3ae4965b0fba3b0ab268e3ce84c9185fcedec356000080000000800000008000000000000000000000",
path: "m/86'/0'/0'/0/0",
xfp: "27c3831f",
origin: null);
final UREncoder urEncoder = UREncoder(ur);
String _currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
timer = Timer.periodic(const Duration(milliseconds: 250), (_) {
_currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
});
Parse signature
import 'package:gs_ur_dart/gs_ur_dart.dart';
typedef SuccessCallback = void Function(UR);
final SuccessCallback onSuccess;
final QRViewController controller;
controller.scannedDataStream.listen((event) {
URDecoder urDecoder = URDecoder();
urDecoder.receivePart(event.code);
double progress = urDecoder.getProgress();
if (urDecoder.isComplete()) {
final UR result = urDecoder.resultUR();
if (!succeed) {
onSuccess(result);
succeed = true;
}
}
});
onSuccess(UR ur){
final psbtSigned = GsWalletPsbtSDK.parseSignature(ur);
}
// psbtSigned: {
// "uuid": [147,220,1,240,141,26,17,239,151,24,207,200,186,0,173,219],
// "psbt":
// "70736274ff012cb2b4ad2c714000000000000000000000000000000000000000e0c42e7100000000a11ea01e809ca470dcad2c7154ad2c7100000000000000007472616e58ae2c7128c02e710000000010000000f8ad2c7100000000000000000000000030ae2c7100000000a11ea01e809ca47014ae2c7198ad2c7100000000000000007472616e546875204a616e2020312030383a30303a303020313937300a002206a11ea01e809ca4703cae2c71dcad2c710000000000000001742b616e64617465000022512095aff4a11ea01e809ca47080ae2c7114ae2c7100000000000000007472616e8c012e20b4ad2c71c4ae2c7120000000000000000000000000000000000000009cae2c7121000000a11ea01e809ca470a8ae2c713cae2c7100000000000000007472616e696e1964647200c356000080a11ea01e809ca470ecae2c7180ae2c71011340bbb03cb34b8e10ca81df5682c5afd9d7f2db4b54e6b6c5f4f2cc6e5e9347f68c074275d4388e405c03dcae61a8523228aa12722cb6c163efa538ac70365773fa0001002b000000007472616e00000000c4ae2c71000000001000000008af2c710000000000000000000000000000000100200000a11ea01e809ca47048af2c71a8ae2c7100000000000000007472616e626321706a6b686c666b73757a726a706a353737346e706a79706a323476746372736b751974716c637534756a36717971326d366b7939736b66737577380113409262dc13b5af475cdd04d7d1d1f3c4e8b4ce95261f363fb818fb79b4926958651d9ee014b9b00af3c3151eeaa6ccb49864d7533530b291f2987cf04f2eabc30a0000221ea01e809ca47088af2c71ecae2c71b8a82e7104622f71202020200ab268e3ce84c9185fcedec3560000800000008000000080000000000000000000",
// "origin": "GSWALLET"
// };