From 1144f182cb2704ca39d6acc3ee4b4c6d8bbfd14f Mon Sep 17 00:00:00 2001 From: Pierre Michard Date: Thu, 27 Oct 2022 20:55:00 +0200 Subject: [PATCH] Revert "Magic signer" --- lib/src/keystore/impl/keystore.dart | 56 ++++++------------- .../operations_list/impl/operations_list.dart | 8 +-- lib/src/signature/impl/signature.dart | 39 ++++--------- pubspec.yaml | 1 - 4 files changed, 32 insertions(+), 72 deletions(-) diff --git a/lib/src/keystore/impl/keystore.dart b/lib/src/keystore/impl/keystore.dart index c6d65263..e9f2c6a1 100644 --- a/lib/src/keystore/impl/keystore.dart +++ b/lib/src/keystore/impl/keystore.dart @@ -1,5 +1,4 @@ import 'dart:typed_data'; -import 'package:blockchain_signer/blockchain_signer.dart'; import 'package:meta/meta.dart'; import 'package:equatable/equatable.dart'; @@ -30,18 +29,8 @@ class Keystore extends Equatable { final String? mnemonic; - RemoteSigner? signer; - Keystore._({required this.secretKey, this.mnemonic}); - /// Generate a keyStore with a remote signer - /// - /// ```dart - /// await magic.tezos.fetchRemoteSigner(); - /// Keystore.fromRemoteSigner(magic.tezos); - /// ``` - Keystore.fromRemoteSigner(RemoteSigner this.signer) : secretKey = '', mnemonic = null; - /// A factory that generates a keystore from a secret key. /// /// ```dart @@ -136,37 +125,28 @@ class Keystore extends Equatable { /// The public key of this. String get publicKey => crypto.catchUnhandledErrors(() { - if (signer != null) { - return signer?.publicKey as String; - } - - final seedBytes = crypto.decodeWithoutPrefix(seed); - var pk = crypto.publicKeyBytesFromSeedBytes(seedBytes); + final seedBytes = crypto.decodeWithoutPrefix(seed); + var pk = crypto.publicKeyBytesFromSeedBytes(seedBytes); - return crypto.encodeWithPrefix( - prefix: _publicKeyPrefix, - bytes: Uint8List.fromList(pk.toList()), - ); - }); + return crypto.encodeWithPrefix( + prefix: _publicKeyPrefix, + bytes: Uint8List.fromList(pk.toList()), + ); + }); /// The address of this. String get address => crypto.catchUnhandledErrors(() { - if (signer != null) { - return signer?.address as String; - } - - final publicKeyBytes = crypto.decodeWithoutPrefix(publicKey); - final hash = crypto.hashWithDigestSize( - size: 160, - bytes: publicKeyBytes, - ); - - return crypto.encodeWithPrefix( - prefix: _addressPrefix, - bytes: hash, - ); - - }); + final publicKeyBytes = crypto.decodeWithoutPrefix(publicKey); + final hash = crypto.hashWithDigestSize( + size: 160, + bytes: publicKeyBytes, + ); + + return crypto.encodeWithPrefix( + prefix: _addressPrefix, + bytes: hash, + ); + }); /// The seed of this. String get seed => crypto.catchUnhandledErrors(() { diff --git a/lib/src/models/operations_list/impl/operations_list.dart b/lib/src/models/operations_list/impl/operations_list.dart index 91ee1f94..226d6644 100644 --- a/lib/src/models/operations_list/impl/operations_list.dart +++ b/lib/src/models/operations_list/impl/operations_list.dart @@ -46,11 +46,9 @@ class OperationsList { await _catchHttpError(() async { if (result.signature == null) throw ArgumentError.notNull('result.signature'); - final edsig = await result.signature!.edsig; - final simulationResults = await rpcInterface.preapplyOperations( operationsList: this, - signature: edsig, + signature: result.signature!.edsig, ); for (var i = 0; i < simulationResults.length; i++) { @@ -102,9 +100,7 @@ class OperationsList { await _catchHttpError(() async { if (result.signature == null) throw ArgumentError.notNull('result.signature'); - final signatureWithPayload = await result.signature!.hexIncludingPayload; - - result.id = await rpcInterface.injectOperation(signatureWithPayload); + result.id = await rpcInterface.injectOperation(result.signature!.hexIncludingPayload); }); } diff --git a/lib/src/signature/impl/signature.dart b/lib/src/signature/impl/signature.dart index 960f04dd..998837dd 100644 --- a/lib/src/signature/impl/signature.dart +++ b/lib/src/signature/impl/signature.dart @@ -1,5 +1,3 @@ -import 'package:blockchain_signer/signer/response/signed_result.dart'; -import 'package:convert/convert.dart'; import 'package:equatable/equatable.dart'; import 'package:meta/meta.dart'; import 'package:pinenacl/ed25519.dart'; @@ -27,7 +25,7 @@ class Signature extends Equatable { final Keystore keystore; final Watermarks? watermark; - static final watermarkToHex = { + static final _watermarkToHex = { Watermarks.block: '01', Watermarks.endorsement: '02', Watermarks.generic: '03', @@ -62,42 +60,29 @@ class Signature extends Equatable { } /// Signed bytes of this. - Future get signedBytes async { - return crypto.catchUnhandledErrors(() async { + ByteList get signedBytes { + return crypto.catchUnhandledErrors(() { final watermarkedBytes = - watermark == null ? bytes : Uint8List.fromList(crypto.hexDecode(watermarkToHex[watermark]!) + bytes); - - if (keystore.signer != null) { - SignedResult res = await keystore.signer?.sign(hex.encode(bytes), Uint8List.fromList(crypto.hexDecode(watermarkToHex[watermark]!))) as SignedResult; - - /// sbytes from Taquito remoteSign is in the format of bytes+signature, - /// extract the signature out and return - String signedBytesHex = res.sbytes.replaceAll(res.bytes, ''); - final signedBytesInList = hex.decode(signedBytesHex); - final signed = ByteList.fromList(Uint8List.fromList(signedBytesInList)); - return signed; - } - + watermark == null ? bytes : Uint8List.fromList(crypto.hexDecode(_watermarkToHex[watermark]!) + bytes); var hashedBytes = crypto.hashWithDigestSize(size: 256, bytes: watermarkedBytes); var secretKey = keystore.secretKey; var secretKeyBytes = crypto.decodeWithoutPrefix(secretKey); - var signed = crypto.signDetached( - bytes: hashedBytes, secretKey: secretKeyBytes); - return signed; + + return crypto.signDetached(bytes: hashedBytes, secretKey: secretKeyBytes); }); } /// Base 58 encoding of this using 'edsig' prefix. - Future get edsig { - return crypto.catchUnhandledErrors(() async { - return crypto.encodeWithPrefix(prefix: crypto.Prefixes.edsig, bytes: Uint8List.fromList((await signedBytes).toList())); + String get edsig { + return crypto.catchUnhandledErrors(() { + return crypto.encodeWithPrefix(prefix: crypto.Prefixes.edsig, bytes: Uint8List.fromList(signedBytes.toList())); }); } /// Hexadecimal signature of this prefixed with hexadecimal payload to sign. - Future get hexIncludingPayload { - return crypto.catchUnhandledErrors(() async { - return crypto.hexEncode(Uint8List.fromList(bytes + (await signedBytes))); + String get hexIncludingPayload { + return crypto.catchUnhandledErrors(() { + return crypto.hexEncode(Uint8List.fromList(bytes + signedBytes)); }); } diff --git a/pubspec.yaml b/pubspec.yaml index fd019730..70c43b8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,6 @@ dependencies: quiver: ^3.0.1 # used to zip two lists meta: ^1.3.0 pretty_dio_logger: ^1.1.1 - blockchain_signer: 0.1.0 # Remote Signer dev_dependencies: lints: ^1.0.1 # linter