@@ -59,14 +59,16 @@ pub async fn warn_unusual_keypath(
59
59
}
60
60
61
61
/// Does limit checks the keypath, whitelisting bip44 purpose, account and change.
62
- /// Only allows the well-known xpubs of m'/44'/60'/0'/0 and m'/44'/1'/0'/0 for now.
62
+ /// Only allows the well-known xpubs of m/44'/60'/0'/0 and m/44'/1'/0'/0 for now,
63
+ /// as well m/44'/60'/0' and m/44'/1'/0' (same but only the hardened prefix).
63
64
/// Since ethereum doesn't use the "change" path part it is always 0 and have become part of the
64
65
/// xpub keypath.
65
- /// @return true if the keypath is valid, false if it is invalid.
66
+ /// Returns true if the keypath is valid, false if it is invalid.
66
67
pub fn is_valid_keypath_xpub ( keypath : & [ u32 ] ) -> bool {
67
- keypath. len ( ) == 4
68
- && ( keypath[ ..4 ] == [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 ]
69
- || keypath[ ..4 ] == [ 44 + HARDENED , 1 + HARDENED , 0 + HARDENED , 0 ] )
68
+ keypath == [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 ]
69
+ || keypath == [ 44 + HARDENED , 1 + HARDENED , 0 + HARDENED , 0 ]
70
+ || keypath == [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED ]
71
+ || keypath == [ 44 + HARDENED , 1 + HARDENED , 0 + HARDENED ]
70
72
}
71
73
72
74
/// Does limit checks the keypath, whitelisting bip44 purpose, account and change.
@@ -96,25 +98,37 @@ mod tests {
96
98
0 + HARDENED ,
97
99
0
98
100
] ) ) ;
101
+ assert ! ( is_valid_keypath_xpub( & [
102
+ 44 + HARDENED ,
103
+ 60 + HARDENED ,
104
+ 0 + HARDENED ,
105
+ ] ) ) ;
99
106
assert ! ( is_valid_keypath_xpub( & [
100
107
44 + HARDENED ,
101
108
1 + HARDENED ,
102
109
0 + HARDENED ,
103
110
0
104
111
] ) ) ;
112
+
113
+ assert ! ( is_valid_keypath_xpub( & [
114
+ 44 + HARDENED ,
115
+ 1 + HARDENED ,
116
+ 0 + HARDENED ,
117
+ ] ) ) ;
105
118
// wrong coin.
106
119
assert ! ( !is_valid_keypath_xpub( & [
107
120
44 + HARDENED ,
108
121
0 + HARDENED ,
109
122
0 + HARDENED ,
110
123
0
111
124
] ) ) ;
112
- // too short
113
125
assert ! ( !is_valid_keypath_xpub( & [
114
126
44 + HARDENED ,
115
- 60 + HARDENED ,
116
- 0 + HARDENED
127
+ 0 + HARDENED ,
128
+ 0 + HARDENED ,
117
129
] ) ) ;
130
+ // too short
131
+ assert ! ( !is_valid_keypath_xpub( & [ 44 + HARDENED , 60 + HARDENED ] ) ) ;
118
132
// too long
119
133
assert ! ( !is_valid_keypath_xpub( & [
120
134
44 + HARDENED ,
0 commit comments