Skip to content

Commit

Permalink
Merge pull request #46 from proximax-storage/develop
Browse files Browse the repository at this point in the history
release v0.0.9
  • Loading branch information
shinneng authored Oct 9, 2023
2 parents d503733 + b001652 commit 67f72f3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/src/model/account/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class Account {
Transaction tx, String generationHash) async =>
signTransactionWith(tx, this, generationHash);

Future<SignedTransaction> signTransactionWithPayload(
String txnPayload, String generationHash) async =>
signTransactionWithTxnPayload(txnPayload, this, generationHash);

Future<SignedTransaction> signWithCosignatures(Transaction tx,
List<Account> cosignatories, String generationHash) async =>
signTransactionWithCosignatures(tx, this, cosignatories, generationHash);
Expand Down
44 changes: 44 additions & 0 deletions lib/src/model/transaction/transaction_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,50 @@ Future<SignedTransaction> signTransactionWith(
SignedTransaction(tx.absTransaction().type, pHex.toUpperCase(), hash));
}

Future<SignedTransaction> signTransactionWithTxnPayload(
String txnPayload, Account a, String generationHash) async {
final s = a.account;

final List<int> 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 = <int>[]
..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<SignedTransaction> signTransactionWithCosignatures(Transaction tx,
Account a, List<Account> cosignatories, String generationHash) async {
final stx = await signTransactionWith(tx, a, generationHash);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: xpx_chain_sdk
version: 0.0.8
version: 0.0.9
#author: 'Eleazar Garrido <[email protected]>, ProximaX Devops <[email protected]>'
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
Expand Down

0 comments on commit 67f72f3

Please sign in to comment.