pm_curve25519 0.5.7

pm_curve25519 #

Generate curve25519 key-pair. Sign messages with the same key-pair by translating the point curves to do ed25519 signing.

Getting Started #

dependencies:
  ...
  pm_curve25519: any

Important: For iOS, manually update your podfile. Go into iOS folder in terminal and execute the command:

pod install --repo-update

Usage example #


import 'package:pm_curve25519/pm_curve25519.dart';
import 'dart:async';
import 'dart:typed_data';

//Generate curve25519 key-pair
PmKeyPair pair = await PmCurve25519.generateIdentityPair();

Uint8List publicKey = pair.publicKey;
Uint8List secretKey = pair.secretKey;
//on iOS, secret-key is actually an encoded object which is a key-pair. Treat it as if its a secret-key

print(publicKey);
//very lengthy on iOS(secret-key)
print(secretKey);


//Calculate signature with input Message and your secret-key
String msg = "Hello World";
//Convert msg string into uint8list type
Uint8List message = Uint8List.fromList(fakeMessage.codeUnits);
Uint8List signature = await PmCurve25519.getSignature(message, secretKey);
print(signature);

//verify signature
bool valid = await PmCurve25519.verifySignature(publicKey, message, signature);

assert(valid);

Slight issues #

The iOS secret-key is actually a pair itself. The pair is archived on the iOS platform native side and thus the byte array is actually very long compared to a normal 32 byte secret-key. Currently its about on average 355 bytes in output.

This shouldnt be an issue, just treat it as if its an secret-key. Might be an issue storing this key-pair(secretKey) somewhere secure.

Source of the code #

I have only just created an API because I couldnt find a package that would fully allow signing a message with your original curve25519 key-pair.

I have these as my sources:

For iOS:

For android:

0.5.7 - April 29, 2019 #

  • Fixed typo in README.md

0.5.6 - April 29, 2019 #

  • Formatted pm_curve25519.dart

0.5.5 - April 29, 2019 #

  • Edited README

0.5.4 - April 29, 2019 #

  • Added missing iOS dependency

0.5.3 - April 29, 2019 #

  • Fixed example README.md again

0.5.2 - April 29, 2019 #

  • Fixed example README.md

0.5.1 - April 29, 2019 #

  • Added License
  • Added example README.md

0.5.0 - April 29, 2019 #

  • Initial release
  • API for curve25519
  • Curve25519 key-pair generation
  • Ed25519 translated from curve25519 points for signing messages

example/README.md

pm_curve25519_example #

Demonstrates how to use the pm_curve25519 plugin.

Getting Started #

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:pm_curve25519/pm_curve25519.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'pm_curve25519plugin',
      theme: ThemeData(
        brightness: Brightness.dark,
        accentColor: Colors.lightBlue,
        accentColorBrightness: Brightness.light
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static const platform = const MethodChannel('PmCurve25519');
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('pm_curve25519 test'),
        centerTitle: true,
      ),
      body: testCrypto(context),
    );
  }
  Uint8List publicKey;
  Uint8List _secret;
  Uint8List secretKey;
  Uint8List _signature;
  bool _valid;

  Widget testCrypto(BuildContext context){
   // print(publicKey.lengthInBytes);
   // print(secretKey.lengthInBytes);
    return ListView(
      padding: const EdgeInsets.symmetric(horizontal: 10),
      children: <Widget>[
        FlatButton(
          child: const Text('Press to generate curve25519 key-pair'),
          onPressed: _getKeyPair,
          color: Colors.blue,
        ),
        Text('Public key:\n$publicKey'),
        Text('Secret Key or Pair:\n$secretKey'),
        FlatButton(
          child: const Text('Get shared secret'),
          onPressed: _getSecret,
          color: Colors.blue,
        ),
        Text('Shared secret:\n$_secret'),
        FlatButton(
          child: const Text('Get Signature'),
          onPressed: _getSignature,
          color: Colors.blue,
        ),
        Text('signature:\n$_signature'),
        FlatButton(
          child: const Text('Verify signature'),
          onPressed: _verifySignature,
          color: Colors.blue,
        ),
        Text('Is valid signature?:\n$_valid'),    
        const Padding(
          padding: const EdgeInsets.all(30.0),
        )                 
      ],
    );
  }
  Future<void> _getSecret() async {
    Uint8List sharedSecret = await PmCurve25519.getSharedSecret(publicKey, secretKey);

    setState(() {
      _secret = sharedSecret; 
    });
  }
  Future<void> _getKeyPair() async {
    PmKeyPair getPair = await PmCurve25519.generateIdentityPair();
    setState(() {
     publicKey = getPair.publicKey;
     secretKey = getPair.secretKey;
    });
  }
  Future<void> _getSignature()async {
    String fakeMessage = "Hello world";
    Uint8List message = Uint8List.fromList(fakeMessage.codeUnits);
    Uint8List signature = await PmCurve25519.getSignature(message, secretKey);
    setState(() {
      _signature = signature;
    });
  }
  Future<void> _verifySignature()async {
    String fakeMessage = "Hello world";
    Uint8List message = Uint8List.fromList(fakeMessage.codeUnits);
    bool valid = await PmCurve25519.verifySignature(publicKey, message, _signature);
    setState(() {
      _valid = valid;
    });
  }
 }

Use this package as a library

1. Depend on it

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


dependencies:
  pm_curve25519: ^0.5.7

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:pm_curve25519/pm_curve25519.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
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
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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