bip21 1.0.0

bip-21 #

build status

Dart implementation of the BIP-21 Bitcoin URI scheme.

Based on the bitcoinjs implementation.

Example #

import 'dart:convert';
import 'package:bip21/bip21.dart';

main() {
  var decoded = Bip21.decode(
      "bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar");
  print(decoded.toJson());
  // => {"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}

  var request = BitcoinRequest(address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH");
  print(Bip21.encode(request));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

  var optionRequest = BitcoinRequest(
    address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
    options: {"amount": 20.3, "label": "Foo"},
  );
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foo

  optionRequest.amount = 50.0;
  optionRequest.label = "Bar";
  optionRequest.message = "Hello World";
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=50.0&label=Bar&message=Hello%20World

  var jsonDecoded = BitcoinRequest.fromJson(
    json.decode(
      '{"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}',
    ),
  );
  print(jsonDecoded.toString());
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?label=Foobar&amount=20.3
}

License #

This library is licensed under the MIT license. Please read the LICENSE file for more information.

1.0.0 #

  • Initial version

example/bip21_example.dart

import 'dart:convert';
import 'package:bip21/bip21.dart';

main() {
  var decoded = Bip21.decode(
      "bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar");
  print(decoded.toJson());
  // => {"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}

  var request = BitcoinRequest(address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH");
  print(Bip21.encode(request));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

  var optionRequest = BitcoinRequest(
    address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
    options: {"amount": 20.3, "label": "Foo"},
  );
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foo

  optionRequest.amount = 50.0;
  optionRequest.label = "Bar";
  optionRequest.message = "Hello World";
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=50.0&label=Bar&message=Hello%20World

  var jsonDecoded = BitcoinRequest.fromJson(
    json.decode(
      '{"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}',
    ),
  );
  print(jsonDecoded.toString());
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?label=Foobar&amount=20.3
}

Use this package as a library

1. Depend on it

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


dependencies:
  bip21: ^1.0.0

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:bip21/bip21.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
92
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/bip21_base.dart. (-1.99 points)

Analysis of lib/src/bip21_base.dart reported 4 hints:

line 45 col 7: DO use curly braces for all flow control structures.

line 59 col 11: Use contains instead of indexOf

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

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

Maintenance suggestions

The package description is too short. (-8 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
meta ^1.1.7 1.1.7
Dev dependencies
test ^1.0.0