Skip to content

Commit

Permalink
refactor: update sign function PE-1136
Browse files Browse the repository at this point in the history
  • Loading branch information
javdhu committed Apr 1, 2022
1 parent a52b706 commit 662eb40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/src/models/data_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ class DataItem implements TransactionBase {
/// Signs the [DataItem] using the specified wallet and sets the `id` and `signature` appropriately.
@override
Future<Uint8List> sign(Wallet wallet) async {
final rawSignature = await wallet.sign(this);

_signature = encodeBytesToBase64(rawSignature);
_signature = await wallet.sign(this);
final rawSignature = decodeBase64ToBytes(_signature);

final idHash = await sha256.hash(rawSignature);
_id = encodeBytesToBase64(idHash.bytes);
Expand Down
5 changes: 2 additions & 3 deletions lib/src/models/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ class Transaction implements TransactionBase {

@override
Future<void> sign(Wallet wallet) async {
final rawSignature = await wallet.sign(this);

_signature = encodeBytesToBase64(rawSignature);
_signature = await wallet.sign(this);
final rawSignature = decodeBase64ToBytes(_signature);

final idHash = await sha256.hash(rawSignature);
_id = encodeBytesToBase64(idHash.bytes);
Expand Down
10 changes: 8 additions & 2 deletions lib/src/models/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ class Wallet {
await _keyPair!.extractPublicKey().then((res) => res.n));
Future<String> getAddress() async => ownerToAddress(await getOwner());

Future<Uint8List> sign(TransactionBase transaction) async => rsaPssSign(
message: await transaction.getSignatureData(), keyPair: _keyPair!);
Future<String> sign(TransactionBase transaction) async {
return encodeBytesToBase64(
await rsaPssSign(
message: await transaction.getSignatureData(),
keyPair: _keyPair!,
),
);
}

Future<Uint8List> signMessage(Uint8List message) async =>
rsaPssSign(message: message, keyPair: _keyPair!);
Expand Down

0 comments on commit 662eb40

Please sign in to comment.