-
Notifications
You must be signed in to change notification settings - Fork 6
/
EthrDIDTestHelpers.kt
39 lines (33 loc) · 1.34 KB
/
EthrDIDTestHelpers.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package me.uport.sdk.jwt.test
import me.uport.sdk.ethrdid.EthrDIDDocument
import me.uport.sdk.universaldid.AuthenticationEntry
import me.uport.sdk.universaldid.PublicKeyEntry
import me.uport.sdk.universaldid.PublicKeyType
object EthrDIDTestHelpers {
//language=RegExp
private val didParsePattern = "^(did:)?((\\w+):)?((\\w+):)?(0x[0-9a-fA-F]{40})".toRegex()
fun mockDocForAddress(potentialDID: String): EthrDIDDocument {
val matchResult = didParsePattern.find(potentialDID)
?: throw IllegalArgumentException("can't parse potentialDID or did")
val (_, _, _, _, network, address) = matchResult.destructured
val did =
if (network.isBlank() || network == "mainnet") "did:ethr:$address" else "did:ethr:$network:$address"
return EthrDIDDocument(
id = did,
publicKey = listOf(
PublicKeyEntry(
id = "$did#owner",
type = PublicKeyType.Secp256k1VerificationKey2018,
owner = did,
ethereumAddress = address
)
),
authentication = listOf(
AuthenticationEntry(
type = PublicKeyType.Secp256k1SignatureAuthentication2018,
publicKey = "$did#owner"
)
)
)
}
}