Skip to content

Commit

Permalink
fix(cat-voices): update key derivation path (#1301)
Browse files Browse the repository at this point in the history
* fix(cat-voices): update key derivation path

* docs: add source

* chore: code cleanup

* docs: move relevant docs

* chore: extract account constant

Co-authored-by: Steven Johnson <[email protected]>

* chore: reformat

---------

Co-authored-by: Steven Johnson <[email protected]>
  • Loading branch information
dtscalac and stevenj authored Dec 2, 2024
1 parent 8e18843 commit f9b60fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
enum AccountRole {
voter(roleNumber: 0),
/// An account role that is assigned to every account.
/// Allows to vote for proposals.
voter(number: 0),

// TODO(dtscalac): the RBAC specification doesn't define yet the role number
// for the proposer, replace this arbitrary number when it's specified.
proposer(roleNumber: 1),
/// A delegated representative that can vote on behalf of other accounts.
drep(number: 1),

// TODO(dtscalac): the RBAC specification doesn't define yet the role number
// for the drep, replace this arbitrary number when it's specified.
drep(roleNumber: 2);
/// An account role that can create new proposals.
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,10 @@ import 'package:catalyst_voices_models/catalyst_voices_models.dart';

/// Derives key pairs from a seed phrase.
final class KeyDerivation {
/// See: https://github.com/input-output-hk/catalyst-voices/pull/1300
static const int _purpose = 508;
static const int _type = 139;
static const int _account = 0; // Future Use
final CatalystKeyDerivation _keyDerivation;

const KeyDerivation(this._keyDerivation);
Expand Down Expand Up @@ -44,9 +48,7 @@ final class KeyDerivation {

/// The path feed into key derivation algorithm
/// to generate a key pair from a seed phrase.
///
// TODO(dtscalac): update when RBAC specifies it
String _roleKeyDerivationPath(AccountRole role) {
return "m/${role.roleNumber}'/1234'";
return "m/$_purpose'/$_type'/$_account'/${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 f9b60fa

Please sign in to comment.