Litecoin
This article describes the process of completing a Litcoin transaction through the SDK.
Support List
Supports transactions for most Bitcoin-like cryptocurrencies.
- Bitcoin Cash
- Litecoin
- Doge
- Kaspa
GsWalletBTCSDK
The GsWalletBTCSDK class mainly implements the following functions:
- Construct Bitcoin-like transactions.
- Parse signature information.
class GsWalletBTCSDK {
static UR generateSignRequest({
String? uuid,
required String hexData,
required GsplDataType dataType,
List<Map<String, dynamic>>? inputs,
Map<String, dynamic>? change,
required String path,
required String xfp,
String? origin,
});
static Map<String, dynamic> parseSignature(UR ur);
}
generateSignRequest
static UR generateSignRequest({
String? uuid,
required String hexData,
required GsplDataType dataType,
List<Map<String, dynamic>>? inputs,
Map<String, dynamic>? change,
required String path,
required String xfp,
String? origin,
});
Input parameters
-
uuid:
StringoptionalRepresenting the unique ID of a transaction -
hexData:
StringrequiredUnsigned-transaction data, it's serialized hex for a Bitcoin-like transaction -
dataType:
GsplDataTyperequiredTransaction type -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
inputs:
MapoptionalTransaction input section, which includes the following optional attributes: path, amount, signature, signHashType, address. -
change:
MapoptionalChange section, which includes the following optional attributes: path, amount, signature, signHashType, address. -
xfp:
StringrequiredMasterFingerprint, used as a unique wallet ID -
origin:
StringoptionalNotes for transaction, usually source of the request
parseSignature
static Map<String, dynamic> parseSignature(UR ur);
Returns
-
uuid:
Uint8Listtransaction ID. -
gspl:
CryptoGsplComplete transaction content. -
origin:
Stringusually "GsWallet".
Example
Construct transaction
import 'package:gs_ur_dart/gs_ur_dart.dart';
UR ur = GsWalletBTCSDK.generateSignRequest(
uuid: "cf55cae0-8d24-11ef-90ac-6dae386eaee6",
hexData:
"0200000002c4d65606a1cb6e6d4c225af6c632d0155765c997789fbcdf91376295d924c4780100000000ffffffff538ee4444e981be55b49836f982813d771ff4cfc66cb0c587d3f8be1a7529ce40100000000ffffffff0109444304000000001976a914e274b8b609ea3d6ef60c90d84fb8f2e8445cdb5788ac00000000",
dataType: GsplDataType.transaction,
path: "m/44'/2'/0'/0/0",
inputs: [
{
"path": "m/44'/2'/0'/0/0",
"amount": 63517873,
"signature": null,
"signhashType": 1
},
{
"path": "m/44'/2'/0'/0/0",
"amount": 8006507,
"signature": null,
"signhashType": 1
}
],
change: null,
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 ltcSigned = GsWalletBTCSDK.parseSignature(ur);
}
// ltcSigned: {
// "uuid": [207, 85, 202, 224, 141, 36, 17, 239, 144, 172, 109, 174, 56, 110, 174, 230],
// "gspl":< Instance of CryptoGspl>,
// "origin":"GSWALLET",
// };