blake2b 0.1.2

  • Readme
  • Changelog
  • Installing
  • 71

blake2b #

A dart implement of blake2b referenced from blacknet and it's source code.

Getting Started #

///
/// CASE 1
///

// what we expect
// bip = mean fury common entire zoo cash fragile dilemma retire appear insect park
// hash = A064E3C0E7D606F7EE717718FD23B943328ACD8CC20DE29B4053FC1C9D3888F6
// bytes = -96 100 -29 -64 -25 -42 6 -9 -18 113 119 24 -3 35 -71 67 50 -118 -51 -116 -62 13 -30 -101 64 83 -4 28 -99 56 -120 -10

Int8List expect = Int8List.fromList([-96,100,-29,-64,-25,-42,6,-9,-18,113,119,24,-3,35,-71,67,50,-118,-51,-116,-62,13,-30,-101,64,83,-4,28,-99,56,-120,-10]);
Uint8List uexpect = Utils.int8list2uint8list(expect);

var bip = "mean fury common entire zoo cash fragile dilemma retire appear insect park";
var upperCaseHash = "A064E3C0E7D606F7EE717718FD23B943328ACD8CC20DE29B4053FC1C9D3888F6";

Int8List message = Int8List(bip.length);
for (int i = 0; i < bip.length; i++) {
    message[i] = bip.codeUnitAt(i);
}

// hash from bytes to bytes
var umessage = Utils.int8list2uint8list(message);

var bytes = Blake2bHash.hash(umessage, 0, umessage.length);
assert(_uint8ListEqual(bytes, uexpect));

// hash from hex string to hex string
var lowerCaseHash = Blake2bHash.hashHexString2HexString(HEX.encode(message));
assert(lowerCaseHash == upperCaseHash.toLowerCase());

// hash from utf8 string to hex string
lowerCaseHash = Blake2bHash.hashUtf8String2HexString(bip);
assert(lowerCaseHash == upperCaseHash.toLowerCase());


///
/// CASE 2
///

// another test
// hexString = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000eea2f40ef9c40caffc91d82c3332456039d9562290fe0957bad9ca7bc8e9159900000014d7338a9fc7b42de9c2045635a2bf2ec628f47adec76f8ee6caaa5397025b74e400000000000186a000ae0000000000989680a54407d81a2e4d5c72b8d784a56f88736c64bdf90883c12b6ffff6ec892b2b0c00846d656d6f
// hash = ff773f774a4489c98429d37ba1e8c91ce0ac26af27cd32c1b6ef17843e87eb39
var hexString = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000eea2f40ef9c40caffc91d82c3332456039d9562290fe0957bad9ca7bc8e9159900000014d7338a9fc7b42de9c2045635a2bf2ec628f47adec76f8ee6caaa5397025b74e400000000000186a000ae0000000000989680a54407d81a2e4d5c72b8d784a56f88736c64bdf90883c12b6ffff6ec892b2b0c00846d656d6f";
var messageBytes = Utils.int8list2uint8list(Int8List.fromList(HEX.decode(hexString)));
var hash = Blake2bHash.hash(messageBytes, 64, messageBytes.length - 64);
var expectedHash = Utils.int8list2uint8list(Int8List.fromList(HEX.decode("ff773f774a4489c98429d37ba1e8c91ce0ac26af27cd32c1b6ef17843e87eb39")));
assert(_uint8ListEqual(hash, expectedHash));

[0.0.1] - basic implement of blake2b

  • just follow the blacknet's blake2b to implment it with dart.

[0.0.2] - wrap a Blake2bHash for common use

[0.1.0] - use Uint8List instead of Int8List

[0.1.2] - fix bug due to a wrong implement of array copy

Use this package as a library

1. Depend on it

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


dependencies:
  blake2b: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:blake2b/blake2b.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
83
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/blake2b.dart.

Run flutter format to format lib/blake2b.dart.

Format lib/blake2b_hash.dart.

Run flutter format to format lib/blake2b_hash.dart.

Format lib/utils.dart.

Run flutter format to format lib/utils.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and blake2b.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

The package description is too short. (-7 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
fixnum ^0.10.9 0.10.11
flutter 0.0.0
hex ^0.1.2 0.1.2
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test