Skip to content

Commit

Permalink
🐛 Add Blockchain Version in newKeychainTransaction and newAccessKeych…
Browse files Browse the repository at this point in the history
…ainTransaction methods
  • Loading branch information
redDwarf03 committed Oct 29, 2023
1 parent a3e529b commit 93ace36
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changelog
=========

#### Version 3.3.2
* Add Blockchain Version in newKeychainTransaction and newAccessKeychainTransaction methods

#### Version 3.3.1
* TypedEncoding serialization introduced for the recipients' args
* Add Blockchain Version GraphQL request
Expand Down
16 changes: 13 additions & 3 deletions lib/src/services/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ class ApiService with JsonRPCUtil {
Transaction newKeychainTransaction(
String seed,
List<String> authorizedPublicKeys,
Uint8List originPrivateKey, {
Uint8List originPrivateKey,
int blockchainTxVersion, {
String? serviceName,
String? derivationPath,
}) {
Expand All @@ -635,7 +636,11 @@ class ApiService with JsonRPCUtil {
);
}

return Transaction(type: 'keychain', data: Transaction.initData())
return Transaction(
type: 'keychain',
version: blockchainTxVersion,
data: Transaction.initData(),
)
.setContent(jsonEncode(keychain.toDID()))
.addOwnership(
uint8ListToHex(aesEncrypt(keychain.encode(), aesKey)),
Expand All @@ -654,6 +659,7 @@ class ApiService with JsonRPCUtil {
String seed,
Uint8List keychainAddress,
Uint8List originPrivateKey,
int blockchainTxVersion,
) {
final aesKey = uint8ListToHex(
Uint8List.fromList(
Expand All @@ -674,7 +680,11 @@ class ApiService with JsonRPCUtil {
),
];

return Transaction(type: 'keychain_access', data: Transaction.initData())
return Transaction(
type: 'keychain_access',
version: blockchainTxVersion,
data: Transaction.initData(),
)
.addOwnership(
uint8ListToHex(aesEncrypt(keychainAddress, aesKey)),
authorizedKeys,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: archethic_lib_dart
description: Archethic dart library for Flutter for Node and Browser. This library aims to provide a easy way to create Archethic transaction and to send them over the network
homepage: https://github.com/archethic-foundation/libdart

version: 3.3.1
version: 3.3.2

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
18 changes: 18 additions & 0 deletions test/keychain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ void main() {
ApiService('https://mainnet.archethic.net').getOriginKey();
log('originPrivateKey: $originPrivateKey');

final blockchainTxVersion = int.parse(
(await ApiService('https://mainnet.archethic.net')
.getBlockchainVersion())
.version
.transaction,
);

/// Create Keychain from keyChain seed and wallet public key to encrypt secret
final keychainTransaction =
ApiService('https://mainnet.archethic.net').newKeychainTransaction(
Expand All @@ -190,6 +197,7 @@ void main() {
),
],
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
serviceName: kServiceName,
derivationPath: kDerivationPath,
);
Expand All @@ -203,6 +211,7 @@ void main() {
hexToUint8List(keychainTransaction.address!.address!),
),
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
);
log('accessKeychainTx: ${accessKeychainTx.convertToJSON()}');

Expand Down Expand Up @@ -318,6 +327,13 @@ void main() {
ApiService('https://mainnet.archethic.net').getOriginKey();
log('originPrivateKey: $originPrivateKey');

final blockchainTxVersion = int.parse(
(await ApiService('https://mainnet.archethic.net')
.getBlockchainVersion())
.version
.transaction,
);

/// Create Keychain from keyChain seed and wallet public key to encrypt secret
final keychainTransaction =
ApiService('https://mainnet.archethic.net').newKeychainTransaction(
Expand All @@ -328,6 +344,7 @@ void main() {
),
],
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
serviceName: kServiceName,
derivationPath: kDerivationPath,
);
Expand All @@ -341,6 +358,7 @@ void main() {
hexToUint8List(keychainTransaction.address!.address!),
),
Uint8List.fromList(hexToUint8List(originPrivateKey)),
blockchainTxVersion,
);
log('accessKeychainTx: ${accessKeychainTx.convertToJSON()}');

Expand Down

0 comments on commit 93ace36

Please sign in to comment.