Skip to content

Commit f9b60fa

Browse files
dtscalacstevenj
andauthored
fix(cat-voices): update key derivation path (#1301)
* 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]>
1 parent 8e18843 commit f9b60fa

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

catalyst_voices/packages/internal/catalyst_voices_models/lib/src/user/account_role.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
enum AccountRole {
2-
voter(roleNumber: 0),
2+
/// An account role that is assigned to every account.
3+
/// Allows to vote for proposals.
4+
voter(number: 0),
35

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

8-
// TODO(dtscalac): the RBAC specification doesn't define yet the role number
9-
// for the drep, replace this arbitrary number when it's specified.
10-
drep(roleNumber: 2);
9+
/// An account role that can create new proposals.
10+
proposer(number: 3);
1111

1212
/// The RBAC specified role number.
13-
final int roleNumber;
13+
final int number;
1414

15-
const AccountRole({required this.roleNumber});
15+
const AccountRole({required this.number});
1616

1717
/// Returns the role which is assigned to every user.
1818
static AccountRole get root => voter;

catalyst_voices/packages/internal/catalyst_voices_services/lib/src/crypto/key_derivation.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import 'package:catalyst_voices_models/catalyst_voices_models.dart';
33

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

812
const KeyDerivation(this._keyDerivation);
@@ -44,9 +48,7 @@ final class KeyDerivation {
4448

4549
/// The path feed into key derivation algorithm
4650
/// to generate a key pair from a seed phrase.
47-
///
48-
// TODO(dtscalac): update when RBAC specifies it
4951
String _roleKeyDerivationPath(AccountRole role) {
50-
return "m/${role.roleNumber}'/1234'";
52+
return "m/$_purpose'/$_type'/$_account'/${role.number}/0";
5153
}
5254
}

catalyst_voices/packages/internal/catalyst_voices_services/lib/src/registration/registration_transaction_builder.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ final class RegistrationTransactionBuilder {
8282
// TODO(dtscalac): when RBAC specification will define other roles
8383
// they should be registered here
8484
RoleData(
85-
roleNumber: AccountRole.root.roleNumber,
85+
roleNumber: AccountRole.root.number,
8686
roleSigningKey: const LocalKeyReference(
8787
keyType: LocalKeyReferenceType.x509Certs,
8888
offset: 0,

catalyst_voices/packages/internal/catalyst_voices_services/test/src/crypto/key_derivation_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
for (final role in AccountRole.values) {
3232
final keyPair = await keyDerivation.deriveKeyPair(
3333
masterKey: masterKey,
34-
path: "m/${role.roleNumber}'/1234'",
34+
path: "m/${role.number}'/1234'",
3535
);
3636
expect(keyPair, isNotNull);
3737
}

0 commit comments

Comments
 (0)