From 40cf894a6124d21187d41312b7a0cf2ea6a0de97 Mon Sep 17 00:00:00 2001 From: jiaming Date: Mon, 9 Oct 2023 17:55:08 +0800 Subject: [PATCH 1/2] sign txn with payload --- lib/src/model/account/account.dart | 4 ++ .../transaction/transaction_internal.dart | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/src/model/account/account.dart b/lib/src/model/account/account.dart index 8e308a5..b443c4a 100644 --- a/lib/src/model/account/account.dart +++ b/lib/src/model/account/account.dart @@ -78,6 +78,10 @@ class Account { Transaction tx, String generationHash) async => signTransactionWith(tx, this, generationHash); + Future signTransactionWithPayload( + String txnPayload, String generationHash) async => + signTransactionWithTxnPayload(txnPayload, this, generationHash); + Future signWithCosignatures(Transaction tx, List cosignatories, String generationHash) async => signTransactionWithCosignatures(tx, this, cosignatories, generationHash); diff --git a/lib/src/model/transaction/transaction_internal.dart b/lib/src/model/transaction/transaction_internal.dart index 14a21d0..beae715 100644 --- a/lib/src/model/transaction/transaction_internal.dart +++ b/lib/src/model/transaction/transaction_internal.dart @@ -261,6 +261,50 @@ Future signTransactionWith( SignedTransaction(tx.absTransaction().type, pHex.toUpperCase(), hash)); } +Future signTransactionWithTxnPayload( + String txnPayload, Account a, String generationHash) async { + final s = a.account; + + final List bytes = []; + for (int i = 0; i < txnPayload.length; i += 2) { + final hexPair = txnPayload.substring(i, i + 2); + final byte = int.parse(hexPair, radix: 16); + bytes.add(byte); + } + + final b = Uint8List.fromList(bytes); + + var sb = Uint8List.fromList(b.skip(100).take(b.length).toList()); + + sb = Uint8List.fromList(hex.decode(generationHash) + sb); + + final signature = await s.sign(sb); + + final p = [] + ..insertAll(0, b.skip(0).take(4)) + ..insertAll(4, signature.bytes) + ..insertAll(4 + 64, a.account.publicKey) + ..insertAll(100, b.skip(100).take(b.length)); + + final String pHex = hex.encode(p); + + final hash = _createTransactionHash(pHex, generationHash); + const versionLength = 8; + const publicKeyLength = 64; + const typeLength = 4; + const sizeLength = 8; + const signatureLength = 128; + const signatureOffset = sizeLength; + const publicKeyOffset = signatureOffset + signatureLength; + const versionOffset = publicKeyOffset + publicKeyLength; + const typeOffset = versionOffset + versionLength; + const feeOffset = typeOffset + typeLength; + final type = + extractNumberFromHex(txnPayload.substring(typeOffset, feeOffset)); + return SignedTransaction( + TransactionType.fromInt(type), pHex.toUpperCase(), hash); +} + Future signTransactionWithCosignatures(Transaction tx, Account a, List cosignatories, String generationHash) async { final stx = await signTransactionWith(tx, a, generationHash); From b001652f8d87bbe53d6042999955fa0036a8fc93 Mon Sep 17 00:00:00 2001 From: shinneng Date: Mon, 9 Oct 2023 18:33:11 +0800 Subject: [PATCH 2/2] bump version --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30669a1..f494875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.8 +### Updates +[ADD] sign txn with Payload + ## 0.0.8 ### Updates [ADD] function to get encrypted private key with password diff --git a/README.md b/README.md index 00595de..785351e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Add this to your package's pubspec.yaml file: ```dart dependencies: - xpx_chain_sdk: 0.0.7+8 + xpx_chain_sdk: 0.0.9 ``` **2. Install it** @@ -52,4 +52,4 @@ For more examples, go to our [wiki](https://github.com/proximax-storage/dart-xpx We'd love to get more people involved in the project. Please feel free to raise any issues or PR and we'll review your contribution. -Copyright (c) 2019 ProximaX Limited +Copyright (c) 2023 ProximaX Limited diff --git a/pubspec.yaml b/pubspec.yaml index d8a8fff..242da58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: xpx_chain_sdk -version: 0.0.8 +version: 0.0.9 #author: 'Eleazar Garrido , ProximaX Devops ' description: 'The ProximaX Sirius Chain Dart SDK works as a async lightweight Dart library for interacting with the Sirius Blockchain.' homepage: https://github.com/proximax-storage