Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

feat: Add long form VDR #293

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/vdr-longform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
name: vdr-longform
on:
push:
paths:
- 'component/vdr/longform/**'
pull_request:
paths:
- 'component/vdr/longform/**'
jobs:
linter:
name: Go linter
timeout-minutes: 10
env:
LINT_PATH: component/vdr/longform
GOLANGCI_LINT_IMAGE: "golangci/golangci-lint:v1.50.0"
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

- name: Checks linter
timeout-minutes: 10
run: make lint
unitTest:
name: Unit test
runs-on: ubuntu-18.04
timeout-minutes: 15
env:
UNIT_TESTS_PATH: component/vdr/longform
steps:
- name: Setup Go 1.19
uses: actions/setup-go@v2
with:
go-version: 1.19
id: go

- uses: actions/checkout@v2

- name: Run unit test
timeout-minutes: 15
run: make unit-test

- name: Upload coverage to Codecov
timeout-minutes: 10
if: github.repository == 'hyperledger/aries-framework-go-ext'
uses: codecov/[email protected]
with:
file: ./coverage.out

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ license:

.PHONY: lint
lint:
@EXCLUDE_LINT_PATH=./component/vdr/indy scripts/check_lint.sh
@LINT_PATH=./component/vdr/indy GOLANGCI_LINT_IMAGE="canislabs/golangci-lint:latest" scripts/check_lint.sh
scripts/check_lint.sh

.PHONY: generate-vdr-trustbloc-test-keys
generate-vdr-trustbloc-test-keys:
Expand Down
176 changes: 176 additions & 0 deletions component/vdr/longform/.custom_golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

run:
concurrency: 4
deadline: 3m
issues-exit-code: 1
tests: true
build-tags: [""]
skip-dirs: [""]

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true


linters-settings:
depguard:
list-type: denylist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- unnamedResult
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
machine: false # don't require //nolint instead of // nolint
explain: false # don't require //nolint // my explanation instead of just //nolint

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- nakedret
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- dupl
- funlen
- bodyclose
- dupl
- goconst
- gosec
- noctx
- wrapcheck
- lll
- gocritic

- path: pkg/golinters/errcheck.go
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."

- path: pkg/golinters/gofumpt.go
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
- path: pkg/golinters/staticcheck_common.go
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
- path: pkg/lint/lintersdb/manager.go
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."

exclude:
- \`config\` is a global variable
- Line contains TODO/BUG/FIXME
# Add comments for package
- at least one file in a package should have a package comment
# Allow package logger variables (for now)
- logger is a global variable
107 changes: 107 additions & 0 deletions component/vdr/longform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 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.
Loading