From 470b1b98e63e09550a2c79968815f2bb8596aaef Mon Sep 17 00:00:00 2001 From: Dominik Toton Date: Fri, 29 Nov 2024 13:46:15 +0100 Subject: [PATCH] chore: code cleanup --- .../lib/src/user/account_role.dart | 10 +++++----- .../lib/src/crypto/key_derivation.dart | 5 ++++- .../registration/registration_transaction_builder.dart | 2 +- .../test/src/crypto/key_derivation_test.dart | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/user/account_role.dart b/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/user/account_role.dart index 2012970413..43ab75824d 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/user/account_role.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/user/account_role.dart @@ -1,18 +1,18 @@ enum AccountRole { /// An account role that is assigned to every account. /// Allows to vote for proposals. - voter(roleNumber: 0), + voter(number: 0), /// A delegated representative that can vote on behalf of other accounts. - drep(roleNumber: 1), + drep(number: 1), /// An account role that can create new proposals. - proposer(roleNumber: 3); + proposer(number: 3); /// The RBAC specified role number. - final int roleNumber; + final int number; - const AccountRole({required this.roleNumber}); + const AccountRole({required this.number}); /// Returns the role which is assigned to every user. static AccountRole get root => voter; diff --git a/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/crypto/key_derivation.dart b/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/crypto/key_derivation.dart index abf23274de..c7492b6da5 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/crypto/key_derivation.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/crypto/key_derivation.dart @@ -3,6 +3,9 @@ import 'package:catalyst_voices_models/catalyst_voices_models.dart'; /// Derives key pairs from a seed phrase. final class KeyDerivation { + static const int _purpose = 508; + static const int _type = 139; + final CatalystKeyDerivation _keyDerivation; const KeyDerivation(this._keyDerivation); @@ -47,6 +50,6 @@ final class KeyDerivation { /// /// See: https://github.com/input-output-hk/catalyst-voices/pull/1300 String _roleKeyDerivationPath(AccountRole role) { - return "m/508'/139'/0'/${role.roleNumber}/0"; + return "m/$_purpose'/$_type'/0'/${role.number}/0"; } } diff --git a/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/registration/registration_transaction_builder.dart b/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/registration/registration_transaction_builder.dart index 3e60e15c51..9cce251193 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/registration/registration_transaction_builder.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_services/lib/src/registration/registration_transaction_builder.dart @@ -82,7 +82,7 @@ final class RegistrationTransactionBuilder { // TODO(dtscalac): when RBAC specification will define other roles // they should be registered here RoleData( - roleNumber: AccountRole.root.roleNumber, + roleNumber: AccountRole.root.number, roleSigningKey: const LocalKeyReference( keyType: LocalKeyReferenceType.x509Certs, offset: 0, diff --git a/catalyst_voices/packages/internal/catalyst_voices_services/test/src/crypto/key_derivation_test.dart b/catalyst_voices/packages/internal/catalyst_voices_services/test/src/crypto/key_derivation_test.dart index 7c9098c8be..71e6d6a30e 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_services/test/src/crypto/key_derivation_test.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_services/test/src/crypto/key_derivation_test.dart @@ -31,7 +31,7 @@ void main() { for (final role in AccountRole.values) { final keyPair = await keyDerivation.deriveKeyPair( masterKey: masterKey, - path: "m/${role.roleNumber}'/1234'", + path: "m/${role.number}'/1234'", ); expect(keyPair, isNotNull); }