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

Commit 92b6afc

Browse files
committed
feat: Add long form VDR
Add long form VDR. Closes #288 Signed-off-by: Sandra Vrtikapa <[email protected]>
1 parent 07bfbe4 commit 92b6afc

28 files changed

+2859
-10
lines changed

.github/workflows/vdr-longform.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
name: vdr-longform
7+
on:
8+
push:
9+
paths:
10+
- 'component/vdr/longform/**'
11+
pull_request:
12+
paths:
13+
- 'component/vdr/longform/**'
14+
jobs:
15+
linter:
16+
name: Go linter
17+
timeout-minutes: 10
18+
env:
19+
LINT_PATH: component/vdr/longform
20+
GOLANGCI_LINT_IMAGE: "golangci/golangci-lint:v1.50.0"
21+
runs-on: ubuntu-18.04
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Checks linter
26+
timeout-minutes: 10
27+
run: make lint
28+
unitTest:
29+
name: Unit test
30+
runs-on: ubuntu-18.04
31+
timeout-minutes: 15
32+
env:
33+
UNIT_TESTS_PATH: component/vdr/longform
34+
steps:
35+
- name: Setup Go 1.19
36+
uses: actions/setup-go@v2
37+
with:
38+
go-version: 1.19
39+
id: go
40+
41+
- uses: actions/checkout@v2
42+
43+
- name: Run unit test
44+
timeout-minutes: 15
45+
run: make unit-test
46+
47+
- name: Upload coverage to Codecov
48+
timeout-minutes: 10
49+
if: github.repository == 'hyperledger/aries-framework-go-ext'
50+
uses: codecov/[email protected]
51+
with:
52+
file: ./coverage.out
53+

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ license:
2626

2727
.PHONY: lint
2828
lint:
29-
@EXCLUDE_LINT_PATH=./component/vdr/indy scripts/check_lint.sh
30-
@LINT_PATH=./component/vdr/indy GOLANGCI_LINT_IMAGE="canislabs/golangci-lint:latest" scripts/check_lint.sh
29+
scripts/check_lint.sh
3130

3231
.PHONY: generate-vdr-trustbloc-test-keys
3332
generate-vdr-trustbloc-test-keys:
+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
run:
8+
concurrency: 4
9+
deadline: 3m
10+
issues-exit-code: 1
11+
tests: true
12+
build-tags: [""]
13+
skip-dirs: [""]
14+
15+
output:
16+
format: colored-line-number
17+
print-issued-lines: true
18+
print-linter-name: true
19+
20+
21+
linters-settings:
22+
depguard:
23+
list-type: denylist
24+
packages:
25+
# logging is allowed only by logutils.Log, logrus
26+
# is allowed to use only in logutils package
27+
- github.com/sirupsen/logrus
28+
packages-with-error-message:
29+
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
30+
dupl:
31+
threshold: 100
32+
funlen:
33+
lines: 100
34+
statements: 50
35+
goconst:
36+
min-len: 2
37+
min-occurrences: 3
38+
gocritic:
39+
enabled-tags:
40+
- diagnostic
41+
- experimental
42+
- opinionated
43+
- performance
44+
- style
45+
disabled-checks:
46+
- dupImport # https://github.com/go-critic/go-critic/issues/845
47+
- ifElseChain
48+
- octalLiteral
49+
- whyNoLint
50+
- unnamedResult
51+
gocyclo:
52+
min-complexity: 15
53+
goimports:
54+
local-prefixes: github.com/golangci/golangci-lint
55+
gomnd:
56+
# don't include the "operation" and "assign"
57+
checks:
58+
- argument
59+
- case
60+
- condition
61+
- return
62+
ignored-numbers:
63+
- '0'
64+
- '1'
65+
- '2'
66+
- '3'
67+
ignored-functions:
68+
- strings.SplitN
69+
70+
govet:
71+
check-shadowing: true
72+
settings:
73+
printf:
74+
funcs:
75+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
76+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
77+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
78+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
79+
lll:
80+
line-length: 140
81+
misspell:
82+
locale: US
83+
nolintlint:
84+
allow-unused: false # report any unused nolint directives
85+
require-explanation: false # don't require an explanation for nolint directives
86+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
87+
machine: false # don't require //nolint instead of // nolint
88+
explain: false # don't require //nolint // my explanation instead of just //nolint
89+
90+
linters:
91+
disable-all: true
92+
enable:
93+
- bodyclose
94+
- depguard
95+
- dogsled
96+
- dupl
97+
- errcheck
98+
- exportloopref
99+
- funlen
100+
- gochecknoinits
101+
- goconst
102+
- gocritic
103+
- gocyclo
104+
- goimports
105+
- gomnd
106+
- goprintffuncname
107+
- gosec
108+
- gosimple
109+
- govet
110+
- ineffassign
111+
- lll
112+
- nakedret
113+
- noctx
114+
- nolintlint
115+
- staticcheck
116+
- stylecheck
117+
- typecheck
118+
- unconvert
119+
- unparam
120+
- unused
121+
- whitespace
122+
123+
# don't enable:
124+
# - asciicheck
125+
# - scopelint
126+
# - gochecknoglobals
127+
# - gocognit
128+
# - godot
129+
# - godox
130+
# - goerr113
131+
# - interfacer
132+
# - maligned
133+
# - nestif
134+
# - prealloc
135+
# - testpackage
136+
# - revive
137+
# - wsl
138+
139+
issues:
140+
# Excluding configuration per-path, per-linter, per-text and per-source
141+
exclude-rules:
142+
- path: _test\.go
143+
linters:
144+
- gomnd
145+
- dupl
146+
- funlen
147+
- bodyclose
148+
- dupl
149+
- goconst
150+
- gosec
151+
- noctx
152+
- wrapcheck
153+
- lll
154+
- gocritic
155+
156+
- path: pkg/golinters/errcheck.go
157+
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
158+
- path: pkg/commands/run.go
159+
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
160+
- path: pkg/commands/run.go
161+
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
162+
163+
- path: pkg/golinters/gofumpt.go
164+
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
165+
- path: pkg/golinters/staticcheck_common.go
166+
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
167+
- path: pkg/lint/lintersdb/manager.go
168+
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
169+
170+
exclude:
171+
- \`config\` is a global variable
172+
- Line contains TODO/BUG/FIXME
173+
# Add comments for package
174+
- at least one file in a package should have a package comment
175+
# Allow package logger variables (for now)
176+
- logger is a global variable

component/vdr/longform/README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Long Form VDR
2+
Long form VDR is used to resolve long form DID and to create long-form DID.
3+
Update, recover and deactivate operations are currently not supported.
4+
5+
## New VDR
6+
```
7+
import (
8+
"crypto"
9+
"github.com/hyperledger/aries-framework-go-ext/component/vdr/longform"
10+
)
11+
12+
vdr, err := longform.New()
13+
if err != nil {
14+
return err
15+
}
16+
```
17+
18+
## Create DID
19+
For creating DID use vdr create and pass DID document.
20+
21+
```
22+
import (
23+
"crypto"
24+
"crypto/ed25519"
25+
"crypto/rand"
26+
"fmt"
27+
28+
ariesdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
29+
"github.com/hyperledger/aries-framework-go/pkg/doc/jose"
30+
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
31+
32+
"github.com/hyperledger/aries-framework-go-ext/component/vdr/longform"
33+
)
34+
35+
recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
36+
if err != nil {
37+
return err
38+
}
39+
40+
updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
41+
if err != nil {
42+
return err
43+
}
44+
45+
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
46+
if err != nil {
47+
return err
48+
}
49+
50+
jwk, err := jose.JWKFromKey(didPublicKey)
51+
if err != nil {
52+
return err
53+
}
54+
55+
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
56+
if err != nil {
57+
return err
58+
}
59+
60+
didDoc := &ariesdid.Doc{}
61+
62+
// add did keys
63+
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm,
64+
ariesdid.Authentication))
65+
66+
// add did services
67+
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}}
68+
69+
// create did
70+
createdDocResolution, err := vdr.Create(didDoc,
71+
vdrapi.WithOption(longform.RecoveryPublicKeyOpt, recoveryKey),
72+
vdrapi.WithOption(longform.UpdatePublicKeyOpt, updateKey),
73+
if err != nil {
74+
return err
75+
}
76+
77+
fmt.Println(createdDocResolution.DIDDocument.ID)
78+
79+
// recovery private key should be saved for future use.
80+
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey
81+
// update private key should be saved for future use.
82+
keyRetrieverImpl.updateKey = updateKeyPrivateKey
83+
84+
85+
longFormDID := createdDocResolution.DIDDocument.ID
86+
```
87+
88+
## Resolve DID
89+
For resolving DID use vdr read and pass long form DID.
90+
91+
```
92+
docResolution, err := vdr.Read(longFormDID)
93+
if err != nil {
94+
return err
95+
}
96+
97+
fmt.Println(docResolution.DIDDocument.ID)
98+
```
99+
100+
## Update DID
101+
Not supported.
102+
103+
## Recover DID
104+
Not supported.
105+
106+
## Deactivate DID
107+
Not supported.

0 commit comments

Comments
 (0)