generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 80
/
HowToCreateDidTest.kt
84 lines (62 loc) · 2.32 KB
/
HowToCreateDidTest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package website.tbd.developer.site.docs.web5.build.decentralizedidentifiers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions.*
import web5.sdk.crypto.InMemoryKeyManager
import web5.sdk.dids.methods.dht.DidDht
import web5.sdk.dids.methods.dht.CreateDidDhtOptions
import web5.sdk.dids.methods.jwk.DidJwk
/**
* Tests backing the Create a DID Guide
*/
internal class HowToCreateDidTest {
@Test
fun `create DidDht`() {
// :snippet-start: createDidDhtKt
//Creates a DID using the DHT method and publishes the DID Document to the DHT
val didDht = DidDht.create(InMemoryKeyManager(), CreateDidDhtOptions(publish = true))
//DID and its associated data which can be exported and used in different contexts/apps
val portableDid = DidDht.resolve(didDht.uri)
//DID string
val did = didDht.uri
//DID Document
val didDocument = portableDid.didDocument
//Republish Did
DidDht.publish( didDht.keyManager, didDht.document )
// :snippet-end:
assertNotNull(did, "DID should not be null")
assertTrue(did.startsWith("did:dht"), "DID should start with 'did:dht'")
assertEquals(did.toString(), didDocument?.id!!.toString(), "id of DID Document should match DID")
}
@Test
fun `create DidJwk`() {
// :snippet-start: createDidJwkKt
// Creates a DID using the did:jwk method
val didJwk = DidJwk.create(InMemoryKeyManager());
//DID and its associated data which can be exported and used in different contexts/apps
val portableDid = DidJwk.resolve(didJwk.uri)
//DID string
val did = didJwk.uri
//DID Document
val didDocument = portableDid.didDocument
// :snippet-end:
assertNotNull(did, "DID should not be null")
assertTrue(did.startsWith("did:jwk"), "DID should start with 'did:jwk'")
assertNotNull(didDocument, "DID Document should not be null")
assertEquals(did.toString(), didDocument?.id!!.toString(), "id of DID Document should match DID")
}
@Test
fun `imports for creating Did`() {
val requiredImports =
"""
// :snippet-start: requiredDidImportsKt
//did:dht
import web5.sdk.dids.methods.dht.DidDht
import web5.sdk.dids.methods.dht.CreateDidDhtOptions
//did:jwk
import web5.sdk.dids.methods.jwk.DidJwk
// key manager
import web5.sdk.crypto.InMemoryKeyManager
// :snippet-end:
"""
}
}