dart_chainsql_api 1.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

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

1.0.8 #

  • 修改release下签名交易的异常

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.8

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]
37
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

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

Analysis of lib/src/core/fields/Field.dart reported 35 hints, including:

line 6 col 26: Unnecessary new keyword.

line 8 col 34: Unnecessary new keyword.

line 9 col 34: Unnecessary new keyword.

line 10 col 25: Unnecessary new keyword.

line 12 col 32: Unnecessary new keyword.

Fix lib/src/core/serialized/TypeTranslator.dart. (-8.63 points)

Analysis of lib/src/core/serialized/TypeTranslator.dart reported 18 hints, including:

line 44 col 11: Unnecessary new keyword.

line 48 col 11: Unnecessary new keyword.

line 52 col 11: Unnecessary new keyword.

line 56 col 11: Unnecessary new keyword.

line 65 col 11: Unnecessary new keyword.

Fix lib/src/ecdsa/Ecies.dart. (-8.63 points)

Analysis of lib/src/ecdsa/Ecies.dart reported 18 hints, including:

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

line 25 col 27: Unnecessary new keyword.

line 32 col 26: Unnecessary new keyword.

line 37 col 17: Unnecessary new keyword.

line 38 col 16: Unnecessary new keyword.

Fix additional 42 files with analysis or formatting issues. (-101.59 points)

Additional issues in the following files:

  • lib/src/core/fields/Type.dart (15 hints)
  • lib/src/ecdsa/K256KeyPair.dart (15 hints)
  • lib/src/core/coretypes/Amount.dart (14 hints)
  • lib/src/chainsql_api.dart (13 hints)
  • lib/src/core/coretypes/STObject.dart (12 hints)
  • lib/src/utils/Util.dart (12 hints)
  • lib/src/core/coretypes/hash/prefixes/HashPrefix.dart (9 hints)
  • lib/src/core/types/signed/SignedTransaction.dart (9 hints)
  • lib/src/core/coretypes/Currency.dart (8 hints)
  • lib/src/core/coretypes/AccountID.dart (7 hints)
  • lib/src/core/serialized/enums/TransactionType.dart (7 hints)
  • lib/src/core/coretypes/STArray.dart (6 hints)
  • lib/src/core/coretypes/STObjectFormatter.dart (6 hints)
  • lib/src/core/coretypes/hash/Hash.dart (6 hints)
  • lib/src/core/coretypes/hash/HalfSha512.dart (5 hints)
  • lib/src/ecdsa/Seed.dart (5 hints)
  • lib/src/utils/B58IdentiferCodecs.dart (5 hints)
  • lib/src/core/coretypes/uint/UInt.dart (4 hints)
  • lib/src/core/coretypes/uint/UInt32.dart (4 hints)
  • lib/src/core/coretypes/uint/UInt64.dart (4 hints)
  • lib/src/core/format/TxFormat.dart (4 hints)
  • lib/src/core/serialized/BinarySerializer.dart (4 hints)
  • lib/src/core/serialized/ByteList.dart (4 hints)
  • lib/src/core/coretypes/Blob.dart (3 hints)
  • lib/src/core/coretypes/hash/Hash160.dart (3 hints)
  • lib/src/core/coretypes/hash/Hash256.dart (3 hints)
  • lib/src/core/coretypes/uint/UInt16.dart (3 hints)
  • lib/src/core/serialized/BinaryParser.dart (3 hints)
  • lib/src/core/types/tx/Transaction.dart (3 hints)
  • lib/src/utils/Sha512half.dart (3 hints)
  • lib/src/core/format/Format.dart (2 hints)
  • lib/src/core/serialized/MultiSink.dart (2 hints)
  • lib/src/core/fields/UInt32Field.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/core/runtime/Value.dart (Run dartfmt to format lib/src/core/runtime/Value.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. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (asn1lib, encrypt, json_annotation).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
asn1lib ^0.5.8 0.5.15 0.6.4
base58check ^1.0.1 1.0.1
collection ^1.14.11 1.14.12
crypto ^2.1.2 2.1.5
cryptoutils ^0.4.0 0.4.0
decimal ^0.3.0 0.3.5
encrypt ^3.3.1 3.3.1 4.0.2
hex ^0.1.2 0.1.2
json_annotation ^2.0.0 2.4.0 3.0.1
pointycastle ^1.0.1 1.0.2
secp256k1cipher ^0.2.0 0.2.1
Transitive dependencies
args 1.6.0
charcode 1.1.3
clock 1.0.1
convert 2.1.1
meta 1.1.8
rational 0.3.8
typed_data 1.1.6
Dev dependencies
build_runner ^1.0.0
json_serializable ^2.0.0
test ^1.6.8