Skip to main content

QR Code Protocol

The Goldshell hardware wallet uses QR codes for data exchange. Based on the UR protocol, a set of upper-layer protocols are designed for various scenarios and implemented in the SDK. This article will introduce how to use APIs to implement data encoding and decoding.

APIs​

UREncoder​

The UREncoder class encodes a UR object into the data of animated QR codes. The following code shows how to encode a EVM transaction:

import 'package:gs_ur_dart/gs_ur_dart.dart';

UR ur = GsWalletEthereumSDK.generateSignRequest(
uuid: "6c3633c0-02c0-4313-9cd7-e25f4f296729",
signData:
"337B718878426CA568BA103A5048A8D920945CE651C0A5360A79DA7E872E672D46C224866FEAF80F3D948682CCF31B683C1ACC29FA7D9BF6527BF627F545692A00",
dataType: EthDataType.typedTransaction,
path: "m/44'/60'/0'/0/0",
xfp: "F23F9FD2",
chainId: 1,
origin: "GsWallet");

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

tip

In order to maintain a smooth QR code scanning speed, UREncoder will keep the generated QR code version to be lower than 15.

URDecoder​

The URDecoder class decodes the animated QR codes and convert them into a UR object. The following code shows the process:

import 'package:gs_ur_dart/gs_ur_dart.dart';

final QRViewController controller;

controller.scannedDataStream.listen((event) {
URDecoder urDecoder = URDecoder();
urDecoder.receivePart(event.code); //event.code means page-data of a QR Code
double progress = urDecoder.getProgress();
if (urDecoder.isComplete()) {
final UR result = urDecoder.resultUR();
}
});

Examples​

UREncoder​

GS-UR-DART/example/animated_qr_code.dart.

URDecoder​

GS-UR-DART/example/animated_qr_scan.dart.