File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,15 @@ pub fn generate_ss58_did_from_phrase(
122
122
123
123
pub fn did_to_hex_public_key ( did : String , address_type : AddressType ) -> Result < String , Error > {
124
124
let splited_did: Vec < & str > = did. split ( ":" ) . collect ( ) ;
125
- let address = splited_did[ 3 ] ;
125
+ let method_name = splited_did[ 1 ] ; // DID method name. See DID spec document
126
+ let address = if method_name == "infra" {
127
+ if splited_did. len ( ) < 4 {
128
+ return Err ( Error :: InvalidDID )
129
+ }
130
+ splited_did[ 3 ]
131
+ } else {
132
+ todo ! ( )
133
+ } ;
126
134
127
135
let decoded_address = bs58:: decode ( address) . into_vec ( ) ?;
128
136
@@ -222,6 +230,18 @@ mod tests {
222
230
) ;
223
231
}
224
232
233
+ #[ test]
234
+ fn test_wrong_did_format ( ) {
235
+ // DID method name "infra" requires format of {network_name}:{public_key}
236
+ assert ! (
237
+ did_to_hex_public_key(
238
+ "did:infra:5GM7RtekqU8cGiS4MKQ7tufoH4Q1itzmoFpVcvcPfjksyPrw" . to_string( ) ,
239
+ AddressType :: Ed25519
240
+ )
241
+ . is_err( )
242
+ )
243
+ }
244
+
225
245
#[ test]
226
246
fn test_ss58_address_to_did ( ) {
227
247
assert_eq ! (
You can’t perform that action at this time.
0 commit comments