Alephium
This article describes the process of completing a Alephium transaction through the SDK.
Support List
Supports transactions for Alephium cryptocurrency.
- Alephium
GsWalletAlphSDK
The GsWalletAlphSDK class mainly implements the following functions:
- Construct Alephium transactions.
- Parse signature information.
class GsWalletAlphSDK {
static generateSignRequest({
uuid,
hexData,
dataType,
outputs,
path,
xfp,
origin,
}: {
uuid: string;
hexData: string;
dataType?: GsplDataType;
outputs?: Record<string, any>[];
path: string;
xfp: string;
origin?: string;
}): UR;
static parseSignature(ur: UR): Record<string, any>;
}
generateSignRequest
static generateSignRequest({
uuid,
hexData,
dataType,
outputs,
path,
xfp,
origin,
}: {
uuid: string;
hexData: string;
dataType?: GsplDataType;
outputs?: Record<string, any>[];
path: string;
xfp: string;
origin?: string;
}): UR ;
Input parameters
-
uuid:
StringrequiredRepresenting the unique ID of a transaction -
hexData:
StringrequiredUnsigned-transaction data, it's serialized hex for a Alephium transaction -
dataType:
GsplDataTypeoptionalTransaction type -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
outputs:
MapoptionalTransaction output 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 parseSignature(ur: UR): Record<string, any>;
Returns
-
uuid:
Uint8Listtransaction ID. -
signature:
Stringsignature of transaction. -
origin:
Stringusually "GsWallet".
Example
Construct transaction && Parse signature
import { GsWalletAlphSDK } from 'gs-ur-js';
export const Alph = () => {
const [isScanning, setIsScanning] = useState(false);
const [alphSignedData, setAlphSignedData] = useState(null);
const ur = GsWalletAlphSDK.generateSignRequest(
uuid: "cf75aef0-8d24-11ef-90ac-6dae386eaee6",
hexData:
"00000080004e20c1174876e80001a883fcf30592c310ce05ec7021ca3514a830dd3b6b73641f34c977146ba73b66abc447120002f27628958e3daf580e8e4fe120e1ded5761ea6b035d865a540726de65f08555a02c378cad1e25d0000000624efe13e0e7a9522c289253619a07da7787681d9d76031d9374333202469f100000000000000000000c40a68372bfb836000000624efe13e0e7a9522c289253619a07da7787681d9d76031d9374333202469f100000000000000000000",
dataType: GsplDataType.transaction,
path: "m/44'/1234'/0'/0/0",
outputs: [
{
"address": "1Qz7am3MSYoiZuPhYBJfaSrC46HaHwnbt62ycFNbK9DA",
"amount": "0034000000000000000"
}
],
xfp: "27c3831f",
origin: "GsWallet");
const onSucceed = ({ type, cbor }) => {
const alphSigned = GsWalletAlphSDK.parseSignature(new UR(Buffer.from(cbor, "hex"), type))
console.log("alphSigned: ", alphSigned);
setAlphSignedData(alphSigned);
setIsScanning(false);
}
const onError = (errorMessage) => {
console.log("error: ", errorMessage);
setAlphSignedData(null);
setIsScanning(false);
}
return (
<div style={{ display: 'flex', alignItems: 'center' }}> {/* Use flexbox for layout */}
{isScanning
? <AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.ALPH_SIGNATURE]}
options={{
width: 400,
height: 300
}}
/>
: (
<>
<AnimatedQRCode
type={ur.type}
cbor={ur.cbor.toString("hex")}
options={{
capacity: 200,
interval: 300
}}
/>
<button style={{ marginLeft: '20px' }} onClick={() => setIsScanning(true)}>Scan GsWallet</button>
{alphData && ( // Conditionally render the box
<div style={{
marginLeft: '20px', // Add some spacing
border: '1px solid #ccc',
padding: '10px',
backgroundColor: '#f9f9f9'
}}>
<h3>alphSigned Data:</h3>
<pre>{alphSignedData}</pre> {/* Display bnbSigned directly */}
</div>
)}
{alphSignedData === null && <div style={{ marginLeft: '40px' }}>Waiting for scan...</div>}
</>
)}
</div>
);
}
// alphSigned: {
// "uuid": [207,117,174,240,141,36,17,239,144,172,109,174,56,110,174,230],
// "signature":[228,162,92,69,221,37,94,111,94,162,91,89,128,41,159,51,52,93,63,117,181,179,83,149,157,24,57,0,97,15,225,31,81,96,201,114,209,77,77,30,210,58,86,13,143,81,222,221,189,140,242,139,88,105,190,118,150,27,41,156,30,56,63,133],
// "origin":"GSWALLET",
// };