Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed Nov 29, 2024
1 parent bd4dfe2 commit 470b1b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 470b1b9

Please sign in to comment.