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

release v0.0.9 #46

Merged
merged 3 commits into from
Oct 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <eleazartovar123@gmail.com>, ProximaX Devops <proximax.devops@gmail.com>'
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