Skip to main content

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 generateSignRequest({
uuid,
hexData,
dataType,
inputs,
change,
path,
xfp,
origin,
}: {
uuid: string;
hexData: string;
dataType: GsplDataType;
inputs?: Record<string, any>[];
change?: Record<string, any>;
path: string;
xfp: string;
origin?: string;
}): UR

static parseSignature(ur: UR): Record<string, any>;

}

generateSignRequest

static generateSignRequest({
uuid,
hexData,
dataType,
inputs,
change,
path,
xfp,
origin,
}: {
uuid: string;
hexData: string;
dataType: GsplDataType;
inputs?: Record<string, any>[];
change?: Record<string, any>;
path: string;
xfp: string;
origin?: string;
}): UR

Input parameters

  • uuid: String required Representing the unique ID of a transaction

  • hexData: String required Unsigned-transaction data, it's serialized hex for a Bitcoin-like transaction

  • dataType: GsplDataType required Transaction type

  • path: String required BIP32 derivation path for from-address of the transaction

  • inputs: Map optional Transaction input section, which includes the following optional attributes: path, amount, signature, signHashType, address.

  • change: Map optional Change section, which includes the following optional attributes: path, amount, signature, signHashType, address.

  • xfp: String required MasterFingerprint, used as a unique wallet ID

  • origin: String optional Notes for transaction, usually source of the request

parseSignature

static parseSignature(ur: UR): Record<string, any>;

Returns

  • uuid: Uint8List transaction ID.

  • gspl: CryptoGspl Complete transaction content.

  • origin: String usually "GsWallet".

Example

Construct transaction && Parse signature

import { GsWalletBTCSDK } from "gs-ur-js";

export const Litecoin = () => {
const [isScanning, setIsScanning] = useState(false);
const [ltcSignedData, setltcSignedData] = useState(null);

const 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);

const onSucceed = ({type, cbor}) => {
const ltcSigned = GsWalletBTCSDK.parseSignResult(new UR(Buffer.from(cbor, "hex"), type))
setltcSignedData(ltcSigned["gspl"].inputs.map((e) => e.signature?.toString('hex')));
setIsScanning(false);
}

const onError = (errorMessage) => {
console.log("error: ",errorMessage);
setltcSignedData(null);
setIsScanning(false);
}

return (
<div style={{ display: 'flex', alignItems: 'center' }}> {/* Use flexbox for layout */}
{isScanning ? (
<AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.BTC_SIGNATURE]}
options={{ width: 400, height: 300 }}
/>
) : (
<>
<AnimatedQRCode type={ur.type} cbor={ur.cbor.toString("hex")} />
<button style={{marginLeft: '20px'}} onClick={() => setIsScanning(true)}>Scan GsWallet</button>
{ltcSignedData && ( // Conditionally render the box
<div style={{
marginLeft: '20px', // Add some spacing
border: '1px solid #ccc',
padding: '10px',
backgroundColor: '#f9f9f9'
}}>
<h3>ltcSigned Data:</h3>
<pre>{ltcSignedData}</pre> {/* Display ltcSigned directly */}
</div>
)}
{ltcSignedData === null && <div style={{marginLeft: '40px'}}>Waiting for scan...</div>}
</>
)}
</div>
);
}


// ltcSigned: {
// "uuid": [207, 85, 202, 224, 141, 36, 17, 239, 144, 172, 109, 174, 56, 110, 174, 230],
// "gspl":< Instance of CryptoGspl>,
// "origin":"GSWALLET",
// };