ssi

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2022 License: GPL-3.0 Imports: 4 Imported by: 1

README

Forked from github.com/nuts-foundation/go-did

sonr-io/go-did

A library to parse and generate W3C DID Documents and W3C Verifiable Credentials.

Did usage:

Creation of a simple DID Document which is its own controller and contains an AssertionMethod.

didID, err := did.ParseDID("did:sonr:123")

// Empty did document:
doc := &did.Document{
    Context:            []did.URI{did.DIDContextV1URI()},
    ID:                 *didID,
}

// Add an assertionMethod
keyID, _ =: did.ParseDIDURL("did:sonr:123#key-1")

keyPair, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
verificationMethod, err := did.NewVerificationMethod(*keyID, did.JsonWebKey2020, did.DID{}, keyPair.Public())

// This adds the method to the VerificationMethod list and stores a reference to the assertion list
doc.AddAssertionMethod(verificationMethod)

didJson, _ := json.MarshalIndent(doc, "", "  ")
fmt.Println(string(didJson))

// Unmarshalling of a json did document:
parsedDIDDoc := did.Document{}
err = json.Unmarshal(didJson, &parsedDIDDoc)

// It can return the key in the convenient lestrrat-go/jwx JWK
parsedDIDDoc.AssertionMethod[0].JWK()

// Or return a native crypto.PublicKey
parsedDIDDoc.AssertionMethod[0].PublicKey()

Outputs:

{
  "assertionMethod": ["did:sonr:123#key-1"],
  "@context": "https://www.w3.org/ns/did/v1",
  "controller": "did:sonr:123",
  "id": "did:sonr:123",
  "verificationMethod": [
    {
      "controller": "did:sonr:123",
      "id": "did:sonr:123#key-1",
      "publicKeyJwk": {
        "crv": "P-256",
        "kty": "EC",
        "x": "UANQ8pgvJT33JbrnwMiu1L1JCGQFOEm1ThaNAJcFrWA=",
        "y": "UWm6q5n1iXyeCJLMGDInN40bkkKr8KkoTWDqJBZQXRo="
      },
      "type": "JsonWebKey2020"
    }
  ]
}

Installation

go get github.com/nuts-foundation/go-did

State of the library

Currently, the library is under development. The api can change without notice. Checkout the issues and PRs to be informed about any development.

Documentation

Index

Constants

View Source
const ECDSASECP256K1VerificationKey2019 = KeyType("EcdsaSecp256k1VerificationKey2019")

ECDSASECP256K1VerificationKey2019 is the EcdsaSecp256k1VerificationKey2019 verification key type as specified here: https://w3c-ccg.github.io/lds-ecdsa-secp256k1-2019/

View Source
const ED25519VerificationKey2018 = KeyType("Ed25519VerificationKey2018")

ED25519VerificationKey2018 is the Ed25519VerificationKey2018 verification key type as specified here: https://w3c-ccg.github.io/lds-ed25519-2018/

View Source
const JsonWebKey2020 = KeyType("JsonWebKey2020")

JsonWebKey2020 is a VerificationMethod type. https://w3c-ccg.github.io/lds-jws2020/

View Source
const JsonWebSignature2020 = ProofType("JsonWebSignature2020")

JsonWebSignature2020 is a Proof type. https://w3c-ccg.github.io/lds-jws2020

View Source
const RSAVerificationKey2018 = KeyType("RsaVerificationKey2018")

RSAVerificationKey2018 is the RsaVerificationKey2018 verification key type as specified here: https://w3c-ccg.github.io/lds-rsa2018/

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyType

type KeyType string

type ProofType

type ProofType string

type URI

type URI struct {
	url.URL
}

URI is a wrapper around url.URL to add json marshalling

func MustParseURI

func MustParseURI(input string) URI

func ParseURI

func ParseURI(input string) (*URI, error)

ParseURI parses a raw URI. If it can't be parsed, an error is returned.

func (URI) MarshalJSON

func (v URI) MarshalJSON() ([]byte, error)

func (URI) MarshalText

func (v URI) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (URI) String

func (v URI) String() string

func (*URI) UnmarshalJSON

func (v *URI) UnmarshalJSON(bytes []byte) error

Directories

Path Synopsis
did
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL