apiUOS.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:polkawallet_sdk/api/api.dart';
  2. import 'package:polkawallet_sdk/api/types/txInfoData.dart';
  3. import 'package:polkawallet_sdk/api/types/uosQrParseResultData.dart';
  4. import 'package:polkawallet_sdk/service/uos.dart';
  5. import 'package:polkawallet_sdk/storage/keyring.dart';
  6. /// Steps to complete offline-signature as a cold-wallet:
  7. /// 1. parseQrCode: parse raw data of QR code, and get signer address from it.
  8. /// 2. signAsync: sign the extrinsic with password, get signature.
  9. /// 3. addSignatureAndSend: send tx with address of step1 & signature of step2.
  10. ///
  11. /// Support offline-signature as a hot-wallet: makeQrCode
  12. class ApiUOS {
  13. ApiUOS(this.apiRoot, this.service);
  14. final PolkawalletApi apiRoot;
  15. final ServiceUOS service;
  16. /// parse data of QR code.
  17. /// @return: [UosQrParseResultData]
  18. Future<UosQrParseResultData> parseQrCode(Keyring keyring, String data) async {
  19. final res = await service.parseQrCode(keyring.store.list.toList(), data);
  20. return UosQrParseResultData.fromJson(res);
  21. }
  22. /// this function must be called after parseQrCode.
  23. /// @return: signature [String]
  24. Future<String?> signAsync(String chain, password) async {
  25. return service.signAsync(chain, password);
  26. }
  27. /// [onStatusChange] is a callback when tx status change.
  28. /// @return txHash [string] if tx finalized success.
  29. Future<Map?> addSignatureAndSend(
  30. String address,
  31. signed,
  32. Function(String) onStatusChange,
  33. ) async {
  34. final res = service.addSignatureAndSend(
  35. address,
  36. signed,
  37. onStatusChange,
  38. );
  39. return res;
  40. }
  41. Future<Map?> makeQrCode(TxInfoData txInfo, List params,
  42. {String? rawParam}) async {
  43. final Map? res = await service.makeQrCode(
  44. txInfo.toJson(),
  45. params,
  46. rawParam: rawParam,
  47. ss58: apiRoot.connectedNode!.ss58,
  48. );
  49. return res;
  50. }
  51. }