waves_sdk 0.0.1 copy "waves_sdk: ^0.0.1" to clipboard
waves_sdk: ^0.0.1 copied to clipboard

outdated

Flutter Waves SDK

example/lib/main.dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:waves_sdk/waves_sdk.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String seed;
  String publicKeyValue, privateKeyValue;
  String address, address2;
  Uint8List signature;
  String balance;
  KeyPair keyPairValue;

  Map<String, bool> results = {};

  @override
  void initState() {
    super.initState();

    WavesSdk.init();
    // WavesSdk.init(env: Environment.TEST_NET);
  }

  Future randomSeed() async {
    // var value = await WavesCrypto.randomSeed();
    var value = "tomorrow puppy car cabin treat ticket weapon soda slush camp idea mountain name erupt broom";
    results['randomSeed'] = value != null;
    setState(() => seed = value);
  }

  Future addressBySeed() async {
    var value = await WavesCrypto.addressBySeed(seed);
    results['addressBySeed'] = value != null;
    setState(() => address = value);
  }

  Future publicKey() async {
    var value = await WavesCrypto.publicKey(seed);
    results['publicKey'] = value != null;
    setState(() => publicKeyValue = value);
  }

  Future privateKey() async {
    var value = await WavesCrypto.privateKey(seed);
    results['privateKey'] = value != null;
    setState(() => privateKeyValue = value);
  }

  Future keyPair() async {
    final value = await WavesCrypto.keyPair(seed);
    results['keyPair'] = value.publicKey == publicKeyValue && value.privateKey == privateKeyValue;
    setState(() => keyPairValue = value);
  }

  Future addressByPublicKey() async {
    var value = await WavesCrypto.addressByPublicKey(publicKeyValue);
    results['addressByPublicKey'] = address == value;
    setState(() => address2 = address);
  }

  Future verifyAddress() async {
    results['verifyAddress'] = await WavesCrypto.verifyAddress(address, publicKey: publicKeyValue);
    setState(() => {});
  }

  Future verifyPublicKey() async {
    results['verifyPublicKey'] = await WavesCrypto.verifyPublicKey(publicKeyValue);
    setState(() => {});
  }

  Future signBytesWithPrivateKey() async {
    var value = await WavesCrypto.signBytesWithPrivateKey(Uint8List(1), privateKeyValue);
    results['signBytesWithPrivateKey'] = value != null;
    setState(() => signature = value);
  }

  Future signBytesWithSeed() async {
    var value = await WavesCrypto.signBytesWithSeed(Uint8List(1), seed);
    results['signBytesWithSeed'] = value != null;
    setState(() => signature = value);
  }

  Future verifySignature() async {
    results['verifySignature'] = await WavesCrypto.verifySignature(publicKeyValue, Uint8List(1), signature);
    setState(() => {});
  }

  Future getBalance() async {
    var value = await WavesSdk.service().getNode().addressesBalance(address);
    results['getBalance'] = value != null;
    setState(() => balance = value);
  }

  void test() async {
    // WavesCrypto tests
    try { await randomSeed(); } catch (e) { results['randomSeed'] = false; }
    try { await addressBySeed(); } catch (e) { results['addressBySeed'] = false; }
    try { await publicKey(); } catch (e) { results['publicKey'] = false; }
    try { await privateKey(); } catch (e) { results['privateKey'] = false; }
    try { await keyPair(); } catch (e) { results['keyPair'] = false; }
    try { await addressByPublicKey(); } catch (e) { results['addressByPublicKey'] = false; }
    try { await verifyAddress(); } catch (e) { results['verifyAddress'] = false; }
    try { await verifyPublicKey(); } catch (e) { results['verifyPublicKey'] = false; }
    try { await signBytesWithPrivateKey(); } catch (e) { results['signBytesWithPrivateKey'] = false;}
    try { await signBytesWithSeed(); } catch (e) { results['signBytesWithSeed'] = false; }
    try { await verifySignature(); } catch (e) { results['verifySignature'] = false; }

    // Waves Node Service tests
    try { await getBalance(); } catch (e) { results['getBalance'] = false; }
  }

  buildTestResult(name, [value = '']) {
    return Container(
      padding: EdgeInsets.only(bottom: 10, top: 10),
      decoration: BoxDecoration(
        border: Border(bottom: BorderSide(color: Colors.black26))
      ),
      child: Column(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(name, style: TextStyle(fontWeight: FontWeight.w500)),
              results[name] != null ? Text(results[name] ? 'OK' : 'ERROR') : Container()
            ],
          ),
          value != null ? Text(value) : Container()
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Waves SDK'),
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: EdgeInsets.all(10),
            child: Column(
              children: <Widget>[
                FlatButton(color: Colors.blue, child: Text('Test'), onPressed: test),

                // Waves Crypto
                buildTestResult('randomSeed', seed),
                buildTestResult('addressBySeed', address),
                buildTestResult('publicKey', publicKeyValue),
                buildTestResult('privateKey', privateKeyValue),
                buildTestResult('keyPair', keyPairValue.toString()),
                buildTestResult('addressByPublicKey', address2),
                buildTestResult('verifyAddress'),
                buildTestResult('verifyPublicKey'),
                buildTestResult('signBytesWithPrivateKey'),
                buildTestResult('signBytesWithSeed'),
                buildTestResult('verifySignature'),

                // Waves Node Service
                buildTestResult('getBalance', balance),
              ],
            ),
          )
        ),
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Flutter Waves SDK

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on waves_sdk