Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* initial commit #1

Merged
merged 7 commits into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions flutter/.gitignore
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
../.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
10 changes: 10 additions & 0 deletions flutter/.metadata
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 5464c5bac742001448fe4fc0597be939379f88ea
channel: stable

project_type: package
3 changes: 3 additions & 0 deletions flutter/CHANGELOG.md
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions flutter/analysis_options.yaml
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
72 changes: 72 additions & 0 deletions flutter/example/example.dart
@@ -0,0 +1,72 @@
// Copyright (c), Magic Labs
// All rights reserved. Use of this source code is governed by a
// MIT license that can be found in the LICENSE file.

import 'package:blockchain_signer/signer/remote/remote_signer.dart';
import 'package:blockchain_signer/signer/response/signed_result.dart';

///
/// This is a simple example of using blockchain signer interface to sign
/// given payloads. The payload will be sent to designated wallet provider for signature
///
Future<void> main() async {
TezosSigner signer = TezosSigner(provider);

await signer.init();

/// operation in hex
const operationInHex = 'a356d122';
/// watermark in bytes
const watermarkInBytes = Uint8List.fromList(crypto.hexDecode('03'));
SignedResult res = await signer.sign(operationInHex, watermarkInBytes);

/// This creates a signature object from taquito
/// https://github.com/ecadlabs/taquito/blob/e5c9dcc54b5a806dbe7c0d0a2e8232a8bcde2074/packages/taquito-signer/src/ec-key.ts#L62
print(res.sig);
print(res.sbytes);
print(res.bytes);
print(res.prefixSig);
}

///
/// This is a simple example of using blockchain signer interface to build
/// Tezos remote signer module on the wallet provider side
///
class TezosSigner extends BlockchainModule implements RemoteSigner {
TezosSigner(RpcProvider provider)
: super(provider);

late String _pk;
late String _pkh;

static TezosSigner? instance;

@override
String get address => _pkh;

@override
String get publicKey => _pk;


@override
String get secretKey =>
throw UnsupportedError('Secret key is not available');

/// sends unsigned payload to the Signer and wait for it to be signed
///
/// @param [op] Operation to sign
/// @param [magicByte] Magic bytes 1 for block, 2 for endorsement, 3 for generic, 5 for the PACK format of michelson
Future<void> init() async {
await response = sendToProvider(method: TezosMethod.taquito_getPublicKeyAndHash, params: []);
_pk = response.result.pk;
_pkh = response.result.pkh;
}
@override
Future<SignedResult> sign(String op, Uint8List magicByte) async {
final params = {"bytes": op, "watermark": magicByte};

await response = sendToProvider(method: TezosMethod.taquito_sign, params: [params]);
return response;
}
}

3 changes: 3 additions & 0 deletions flutter/lib/blockchain_signer.dart
@@ -0,0 +1,3 @@
library blockchain_signer;

export 'signer/remote/remote_signer.dart';
21 changes: 21 additions & 0 deletions flutter/lib/signer/remote/remote_signer.dart
@@ -0,0 +1,21 @@
import 'dart:typed_data';
import 'package:blockchain_signer/signer/signer.dart';
import '../response/signed_result.dart';

/// Remote Sign
/// A remote signer layer that provides signature service from non-custodial key management solutions
abstract class RemoteSigner extends Signer {
@override
Future<SignedResult> sign(String op, Uint8List bytes);

@override
String? get publicKey;

@override
String? get address;

@override
String? get secretKey;

// <Bool>verifySignature
}
26 changes: 26 additions & 0 deletions flutter/lib/signer/response/signed_result.dart
@@ -0,0 +1,26 @@
import 'package:json_annotation/json_annotation.dart';

part 'signed_result.g.dart';

@JsonSerializable(explicitToJson: true)
class SignedResult {
// https://github.com/ecadlabs/taquito/blob/e5c9dcc54b5a806dbe7c0d0a2e8232a8bcde2074/packages/taquito-utils/src/taquito-utils.ts#L56
// signature is hex 64

/// b58c encoded signature from bytes hash
String sig; // b58cencode(signature, prefix.sig),
String prefixSig; // b58cencode(signature, pref[this.curve].sig),
String bytes; // Original bytes
String sbytes; // bytes + hex signature

SignedResult(
{required this.bytes,
required this.sig,
required this.prefixSig,
required this.sbytes});

factory SignedResult.fromJson(Map<String, dynamic> json) =>
_$SignedResultFromJson(json);

Map<String, dynamic> toJson() => _$SignedResultToJson(this);
}
22 changes: 22 additions & 0 deletions flutter/lib/signer/response/signed_result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions flutter/lib/signer/signer.dart
@@ -0,0 +1,15 @@
import 'dart:typed_data';
import 'package:blockchain_signer/signer/response/signed_result.dart';

/// Basic Signer that provides developers with signing interfaces for any blockchain.
/// This is not yet the final version yet. Anything would be subjected to change
///
abstract class Signer {
Future<SignedResult> sign(String op, Uint8List bytes);

String? get publicKey;
String? get address;
String? get secretKey;

// <Bool>verifySignature
}
21 changes: 21 additions & 0 deletions flutter/prepublish.sh
@@ -0,0 +1,21 @@
#!/bin/bash

prepublishCheck (){

echo "=== Formatting source package $1 ==="
flutter format "$1"
tempFolderPath="./$1_copy/"

echo
echo "=== Start prepublish check $1 ==="

cp -r "./$1" "$tempFolderPath"
dart pub global run pana "$tempFolderPath"
rm -r "$tempFolderPath"

echo
echo "=== Prepublish Check for $1 is completed! === "
echo
}

prepublishCheck "lib"
58 changes: 58 additions & 0 deletions flutter/pubspec.yaml
@@ -0,0 +1,58 @@
name: blockchain_signer
description: A flutter universal blockchain signer protocol for third-party library to enable Remote signing and third part wallet provider
version: 0.1.0
homepage: https://github.com/magiclabs/blockchain-mobile-signer
repository: https://github.com/magiclabs/blockchain-mobile-signer

environment:
sdk: ">=2.16.2 <3.0.0"
flutter: ">=1.17.0"

dependencies:
flutter:
sdk: flutter
json_annotation: ^4.5.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
build_runner: ^2.1.11
json_serializable: ^6.2.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
6 changes: 6 additions & 0 deletions flutter/test/blockchain_signer_test.dart
@@ -0,0 +1,6 @@
import 'package:flutter_test/flutter_test.dart';

import 'package:blockchain_signer/blockchain_signer.dart';

void main() {
}