dart_chainsql_api 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

Chainsql的Dart API

1.0.0 #

  • 初始化版本

1.0.2 #

  • 添加非对称加解密接口

1.0.3 #

  • 添加字符串签名接口signFromString

1.0.4 #

格式化代码 导出接口的Model类

1.0.5 #

  • 支持对表的插入交易的签名

1.0.6 #

  • 支持对表的查询操作的Json字符串签名

1.0.7 #

  • 修改JsonObject 类型解析的Bug

example/main.dart

import 'package:dart_chainsql_api/dart_chainsql_api.dart';
import 'package:dart_chainsql_api/src/utils/Util.dart';
import 'dart:convert' as convert;

void signTrustSet() {
    String userSec       = "xnoPBzXtMeMyMHUVTgbuqAfg1SUTb";
    String userAddress   = "zHb9CJAWyB4zj91VRWn96DkukG4bwdtyTh";
    // String issuerAddress = "zpMZ2H58HFPB5QTycMGWSXUeF47eA8jyd4";

    Map signMap = new Map();
    signMap['TransactionType'] = "TrustSet";
    signMap["Account"] = userAddress;
    signMap["Sequence"] = 29;
    signMap["Fee"] = "500";

    Map limitAmount = new Map();
    limitAmount['currency'] = "AAA";
    limitAmount['issuer'] = "zKQwdkkzpUQC9haHFEe2EwUsKHvvwwPHsv";
    limitAmount['value'] = "20000";
    signMap['LimitAmount'] = limitAmount;

    Map txMap = new Map();
    txMap['tx_json'] = signMap;
    var signTxInfo = Chainsql.signTx(txMap, userSec);
    String jsonStr = convert.json.encode(signTxInfo);
    print(jsonStr);

    var signTxInfoMap = signTxInfo.toJson();
    assert(signTxInfoMap.containsKey("tx_blob"));
    assert(signTxInfoMap.containsKey("hash"));

    assert(signTxInfoMap["tx_blob"]==
        "1200142280000000240000001D63D5871AFD498D00000000000000000000000000004141410000000000C9D3DF7EEF4EB20D2C4F23DB7736182F42FEF2086840000000000001F473210330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD02074473045022100CE13BA8F3E0C76558E4750463151AE73B8758CCD4B0ECCA6481B6580A0FBD82E022062A711B14D357B8CB9045F0EAB29E5A687E4BBDAE7D156FB84E1AF045BC9BB608114B5F762798A53D543A014CAF8B297CFF8F2F937E8");
    assert(signTxInfoMap["hash"]==
        "7FD7A05AAA8A32C23D9DF7793692E9E239FF21461D230CB4D2D6EDCB63498A0F");
}

void signPayment() {
    String srcSec = "xnoPBzXtMeMyMHUVTgbuqAfg1SUTb";
    String srcAddress = "zHb9CJAWyB4zj91VRWn96DkukG4bwdtyTh";
    String desAddress = "zpMZ2H58HFPB5QTycMGWSXUeF47eA8jyd4";

    Map signMap = new Map();
    signMap['TransactionType'] = "Payment";
    signMap['Amount'] = "1000";
    signMap["Account"] = srcAddress;
    signMap["Sequence"] = 1;
    signMap["Fee"] = "500";
    signMap["Destination"] = desAddress;

    Map txMap = new Map();
    txMap['tx_json'] = signMap;

    var signTxInfo = Chainsql.signTx(txMap, srcSec);
    String jsonStr = convert.json.encode(signTxInfo);
    print(jsonStr);

    var signTxInfoMap = signTxInfo.toJson();
    assert(signTxInfoMap.containsKey("tx_blob"));
    assert(signTxInfoMap.containsKey("hash"));

    assert(signTxInfoMap["tx_blob"]==
        "120000228000000024000000016140000000000003E86840000000000001F473210330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD0207446304402203874C6642DFE53D6108964BE162E36D9809E198213221645DD282BADEBCF0AB40220133F403782CCE1DAB460A48C32F69352580F9058340A31ADE7EE94F4B80C4A988114B5F762798A53D543A014CAF8B297CFF8F2F937E883140EDBA2E944E1751BDA1FC4ACC7116C9B19394996");
    assert(signTxInfoMap["hash"]==
        "a24d1328315be59b70301ffaeb1f46c2b758f1c211e5f29c393114df4c1e30fb");
}


void generateWallet(){

    var walletInfo = Chainsql.generateAddress();
    String jsonStr = convert.json.encode(walletInfo);
    print(jsonStr);

    var walletMap = walletInfo.toJson();

    assert(walletMap.containsKey("address"));
    assert(walletMap.containsKey("secret"));
    assert(walletMap.containsKey("publicKey"));

    var walletFromSeed =
    Chainsql.generateAddressFromStr("xpkpdVP3LKhtdSfQX3uHNs1f7jN42");

    var walletFromSeedMap = walletFromSeed.toJson();


    assert(walletFromSeedMap.containsKey("address"));
    assert(walletFromSeedMap.containsKey("secret"));
    assert(walletFromSeedMap.containsKey("publicKey"));

    assert(walletFromSeedMap["address"] == "zKa9fxNT4KJwya73M4TYiCKxCQv97511Ve");
    assert(walletFromSeedMap["secret"] == "xpkpdVP3LKhtdSfQX3uHNs1f7jN42");
    assert(walletFromSeedMap["publicKey"] ==
        "cB4e4YpAbPTLyYHmHmEBpLHCNU9TQc8jBUgERoAoQJBkhxT5fRfw");
}

void  eciesTest(){

    String userSecret = "xnnUqirFepEKzVdsoBKkMf577upwT";

    Wallet wallet = Chainsql.generateAddressFromStr(userSecret);
    String plainText = "hello,you";
    var res = Chainsql.eciesEncrypt(convert.utf8.encode(plainText), wallet.publicKey);
    print("encrypted:" + Util.formatBytesAsHexString(res));
    var dec = Chainsql.eciesDecrypt(res, userSecret);
    var strDec = convert.utf8.decode(dec);
    print("decrypted:" + strDec);

    assert(plainText == strDec);

}

void main() {

    generateWallet();
   // signPayment();
    signTrustSet();

    eciesTest();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_chainsql_api: ^1.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_chainsql_api/dart_chainsql_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
85
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_chainsql_api/dart_chainsql_api.dart.

Health suggestions

Fix lib/src/core/coretypes/STObject.dart. (-1.99 points)

Analysis of lib/src/core/coretypes/STObject.dart reported 4 hints:

line 1 col 8: Unused import: 'dart:convert'.

line 7 col 8: Unused import: 'package:dart_chainsql_api/src/utils/Util.dart'.

line 119 col 11: The value of the local variable 'tmp' isn't used.

line 338 col 9: DO use curly braces for all flow control structures.

Fix lib/src/core/fields/Field.dart. (-1.99 points)

Analysis of lib/src/core/fields/Field.dart reported 4 hints:

line 70 col 10: Don't explicitly initialize variables to null.

line 98 col 9: DO use curly braces for all flow control structures.

line 215 col 11: Don't explicitly initialize variables to null.

line 226 col 13: The value of the local variable 'tetst' isn't used.

Fix lib/src/core/coretypes/STObjectFormatter.dart. (-1.49 points)

Analysis of lib/src/core/coretypes/STObjectFormatter.dart reported 3 hints:

line 43 col 9: Equality operator == invocation with references of unrelated types.

line 44 col 9: Equality operator == invocation with references of unrelated types.

line 46 col 16: Equality operator == invocation with references of unrelated types.

Fix additional 29 files with analysis or formatting issues. (-10.50 points)

Additional issues in the following files:

  • lib/src/core/serialized/MultiSink.dart (2 hints)
  • lib/src/model/native_pay_tx.dart (2 hints)
  • lib/src/core/coretypes/Amount.dart (1 hint)
  • lib/src/core/coretypes/Currency.dart (1 hint)
  • lib/src/core/coretypes/STArray.dart (1 hint)
  • lib/src/core/coretypes/hash/HalfSha512.dart (1 hint)
  • lib/src/core/coretypes/hash/Hash160.dart (1 hint)
  • lib/src/core/coretypes/hash/Hash256.dart (1 hint)
  • lib/src/core/fields/Type.dart (1 hint)
  • lib/src/core/fields/UInt32Field.dart (1 hint)
  • lib/src/core/serialized/TypeTranslator.dart (1 hint)
  • lib/src/core/serialized/enums/TransactionType.dart (1 hint)
  • lib/src/core/types/signed/SignedTransaction.dart (1 hint)
  • lib/src/core/types/txns/Payment.dart (1 hint)
  • lib/src/core/types/txns/SQLStatement.dart (1 hint)
  • lib/src/core/types/txns/TrustSet.dart (1 hint)
  • lib/src/ecdsa/Ecies.dart (1 hint)
  • lib/src/utils/B58IdentiferCodecs.dart (1 hint)
  • lib/src/utils/Util.dart (1 hint)
  • lib/src/chainsql_api.dart (Run dartfmt to format lib/src/chainsql_api.dart.)
  • lib/src/core/format/TxFormat.dart (Run dartfmt to format lib/src/core/format/TxFormat.dart.)
  • lib/src/core/runtime/Value.dart (Run dartfmt to format lib/src/core/runtime/Value.dart.)
  • lib/src/core/serialized/BinaryParser.dart (Run dartfmt to format lib/src/core/serialized/BinaryParser.dart.)
  • lib/src/ecdsa/K256KeyPair.dart (Run dartfmt to format lib/src/ecdsa/K256KeyPair.dart.)
  • lib/src/model/amount.dart (Run dartfmt to format lib/src/model/amount.dart.)
  • lib/src/model/gateway_pay_tx.dart (Run dartfmt to format lib/src/model/gateway_pay_tx.dart.)
  • lib/src/model/gateway_pay_tx.g.dart (Run dartfmt to format lib/src/model/gateway_pay_tx.g.dart.)
  • lib/src/model/send_max.dart (Run dartfmt to format lib/src/model/send_max.dart.)
  • lib/src/model/tx_json.dart (Run dartfmt to format lib/src/model/tx_json.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (json_annotation).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
asn1lib ^0.5.8 0.5.11
base58check ^1.0.1 1.0.1
collection ^1.14.11 1.14.12
crypto ^2.1.2 2.1.3
cryptoutils ^0.4.0 0.4.0
decimal ^0.3.0 0.3.5
encrypt ^3.3.1 3.3.1
hex ^0.1.2 0.1.2
json_annotation ^2.0.0 2.4.0 3.0.0
pointycastle ^1.0.1 1.0.1
secp256k1cipher ^0.2.0 0.2.1
Transitive dependencies
args 1.5.2
charcode 1.1.2
clock 1.0.1
convert 2.1.1
meta 1.1.7
rational 0.3.6
typed_data 1.1.6
Dev dependencies
build_runner ^1.0.0
json_serializable ^2.0.0
test ^1.6.8