longform

package module
v0.0.0-...-1a43f7c Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 2

README

Long Form VDR

Long form VDR is used to resolve long form DID and to create long-form DID. Update, recover and deactivate operations are currently not supported.

New VDR

import (
	"crypto"
	"github.com/hyperledger/aries-framework-go-ext/component/vdr/longform"
)

vdr, err := longform.New()
	if err != nil {
		return err
}

Create DID

For creating DID use vdr create and pass DID document.

import (
"crypto"
"crypto/ed25519"
"crypto/rand"
"fmt"

ariesdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
"github.com/hyperledger/aries-framework-go/pkg/doc/jose"
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/longform"
)

recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
	return err
}

updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
	return err
}

didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
	return err
}

jwk, err := jose.JWKFromKey(didPublicKey)
if err != nil {
	return err
}

vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
if err != nil {
	return err
}

didDoc := &ariesdid.Doc{}

// add did keys
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm,
		ariesdid.Authentication))

// add did services
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}}

// create did
createdDocResolution, err := vdr.Create(didDoc,
		vdrapi.WithOption(longform.RecoveryPublicKeyOpt, recoveryKey),
		vdrapi.WithOption(longform.UpdatePublicKeyOpt, updateKey),
if err != nil {
	return err
}

fmt.Println(createdDocResolution.DIDDocument.ID)

// recovery private key should be saved for future use.
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey
// update private key should be saved for future use.
keyRetrieverImpl.updateKey = updateKeyPrivateKey


longFormDID := createdDocResolution.DIDDocument.ID

Resolve DID

For resolving DID use vdr read and pass long form DID.

docResolution, err := vdr.Read(longFormDID)
if err != nil {
	return err
}

fmt.Println(docResolution.DIDDocument.ID)

Update DID

Not supported.

Recover DID

Not supported.

Deactivate DID

Not supported.

Documentation

Overview

Package longform implement long-form vdr

Index

Constants

View Source
const (
	// UpdatePublicKeyOpt update public key opt.
	UpdatePublicKeyOpt = "updatePublicKey"
	// RecoveryPublicKeyOpt recovery public key opt.
	RecoveryPublicKeyOpt = "recoveryPublicKey"

	// DIDAcceptOpt is DID accept option.
	DIDAcceptOpt = "didAcceptOpt"

	// VDRAcceptOpt is VDR accept option.
	VDRAcceptOpt = "vdrAcceptOpt"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(opts *VDR)

Option configures the long-form vdr.

func WithDIDMethod

func WithDIDMethod(method string) Option

WithDIDMethod overrides the default did method.

func WithDocumentLoader

func WithDocumentLoader(l jsonld.DocumentLoader) Option

WithDocumentLoader overrides the default JSONLD document loader used when processing JSONLD DID Documents.

type VDR

type VDR struct {
	// contains filtered or unexported fields
}

VDR bloc.

func New

func New(opts ...Option) (*VDR, error)

New creates new long form VDR.

func (*VDR) Accept

func (v *VDR) Accept(method string, opts ...vdrapi.DIDMethodOption) bool

Accept did method.

func (*VDR) Close

func (v *VDR) Close() error

Close vdr.

func (*VDR) Create

func (v *VDR) Create(did *docdid.Doc,
	opts ...vdrapi.DIDMethodOption) (*docdid.DocResolution, error)

Create did doc.

func (*VDR) Deactivate

func (v *VDR) Deactivate(_ string, _ ...vdrapi.DIDMethodOption) error

Deactivate did doc.

func (*VDR) Read

func (v *VDR) Read(longFormDID string, _ ...vdrapi.DIDMethodOption) (*docdid.DocResolution, error)

Read long-form DID.

func (*VDR) Update

func (v *VDR) Update(_ *docdid.Doc, _ ...vdrapi.DIDMethodOption) error

Update did doc.

Directories

Path Synopsis
Package dochandler performs document operation processing and document resolution.
Package dochandler performs document operation processing and document resolution.
protocolversion/clientregistry/mocks
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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