Documentation
¶
Overview ¶
Package did is a set of tools to work with Decentralized Identifiers (DIDs) as described in the DID spec https://w3c-ccg.github.io/did-spec
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DID ¶
type DID struct {
// DID Method
// https://w3c-ccg.github.io/did-spec#dfn-did-method
Method string
// The specific-idstring component of a DID
ID string
// specific-idstring may be composed of multiple `:` separated idstrings
// did = "did:" method ":" specific-idstring
// specific-idstring = idstring *( ":" idstring )
IDStrings []string
// DID Path, the portion of a DID reference that follows the first forward slash character.
// https://w3c-ccg.github.io/did-spec/#dfn-did-path
Path string
// Path may be composed of multiple `/` separated segments
// did-path = segment-nz *( "/" segment )
PathSegments []string
// DID Fragment, the portion of a DID reference that follows the first hash sign character ("#")
// https://w3c-ccg.github.io/did-spec/#dfn-did-fragment
Fragment string
}
A DID represents a parsed DID or a DID Reference
func Parse ¶
Parse parses the input string into a DID structure.
Example ¶
package main
import (
"fmt"
"log"
"github.com/ockam-network/did"
)
func main() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s", d.Method, d.ID)
}
Output: Method - example, ID - q7ckgxeq1lxmra0r
Example (WithFragment) ¶
package main
import (
"fmt"
"log"
"github.com/ockam-network/did"
)
func main() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r#keys-1")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s, Fragment - %s", d.Method, d.ID, d.Fragment)
}
Output: Method - example, ID - q7ckgxeq1lxmra0r, Fragment - keys-1
Example (WithPath) ¶
package main
import (
"fmt"
"log"
"github.com/ockam-network/did"
)
func main() {
d, err := did.Parse("did:example:q7ckgxeq1lxmra0r/a/b")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Method - %s, ID - %s, Path - %s", d.Method, d.ID, d.Path)
}
Output: Method - example, ID - q7ckgxeq1lxmra0r, Path - a/b
func (*DID) IsReference ¶
IsReference returns true if a DID has a Path or a Fragment https://w3c-ccg.github.io/did-spec/#dfn-did-reference
Example (NoPathOrFragment) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d.IsReference())
}
Output: false
Example (WithFragment) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.IsReference())
}
Output: true
Example (WithPath) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
fmt.Println(d.IsReference())
}
Output: true
func (*DID) String ¶
String encodes a DID struct into a valid DID string.
Example ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r"}
fmt.Println(d.String())
}
Output: did:example:q7ckgxeq1lxmra0r
Example (WithFragment) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Fragment: "keys-1"}
fmt.Println(d.String())
}
Output: did:example:q7ckgxeq1lxmra0r#keys-1
Example (WithPath) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", Path: "a/b"}
fmt.Println(d.String())
}
Output: did:example:q7ckgxeq1lxmra0r/a/b
Example (WithPathSegments) ¶
package main
import (
"fmt"
"github.com/ockam-network/did"
)
func main() {
d := &did.DID{Method: "example", ID: "q7ckgxeq1lxmra0r", PathSegments: []string{"a", "b"}}
fmt.Println(d.String())
}
Output: did:example:q7ckgxeq1lxmra0r/a/b
Click to show internal directories.
Click to hide internal directories.