Skip to content

Commit a1c9485

Browse files
committed
feat: Add long form VDR
Add long form VDR. Closes hyperledger-aries#288 Signed-off-by: Sandra Vrtikapa <[email protected]>
1 parent 0c41ff0 commit a1c9485

27 files changed

+2857
-19
lines changed

.github/workflows/common.yml .github/workflows/vdr-longform.yml

+12-19
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,39 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
name: common
6+
name: vdr-longform
77
on:
88
push:
9-
paths-ignore:
10-
- 'component/storage/couchdb/**'
11-
- 'component/storage/mysql/**'
12-
- 'component/storage/mongodb/**'
13-
- 'component/didcomm/transport/amqp/**'
14-
- 'component/vdr/indy/**'
9+
paths:
10+
- 'component/vdr/longform/**'
1511
pull_request:
16-
paths-ignore:
17-
- 'component/storage/couchdb/**'
18-
- 'component/storage/mysql/**'
19-
- 'component/storage/mongodb/**'
20-
- 'component/didcomm/transport/amqp/**'
21-
- 'component/vdr/indy/**'
12+
paths:
13+
- 'component/vdr/longform/**'
2214
jobs:
2315
linter:
2416
name: Go linter
2517
timeout-minutes: 10
26-
runs-on: ubuntu-18.04
2718
env:
28-
EXCLUDE_LINT_PATH: ./component/vdr/indy
19+
LINT_PATH: component/vdr/longform
20+
GOLANGCI_LINT_IMAGE: "golangci/golangci-lint:v1.50.0"
21+
runs-on: ubuntu-18.04
2922
steps:
3023
- uses: actions/checkout@v2
3124

3225
- name: Checks linter
3326
timeout-minutes: 10
3427
run: make lint
35-
3628
unitTest:
3729
name: Unit test
3830
runs-on: ubuntu-18.04
3931
timeout-minutes: 15
4032
env:
41-
EXCLUDE_TEST_PATH: ./component/vdr/indy
33+
UNIT_TESTS_PATH: component/vdr/longform
4234
steps:
43-
- name: Setup Go 1.17
35+
- name: Setup Go 1.19
4436
uses: actions/setup-go@v2
4537
with:
46-
go-version: 1.17
38+
go-version: 1.19
4739
id: go
4840

4941
- uses: actions/checkout@v2
@@ -58,3 +50,4 @@ jobs:
5850
uses: codecov/[email protected]
5951
with:
6052
file: ./coverage.out
53+
+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

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
type keyRetrieverImpl struct {
13+
nextRecoveryPublicKey crypto.PublicKey
14+
nextUpdatePublicKey crypto.PublicKey
15+
updateKey crypto.PrivateKey
16+
recoverKey crypto.PrivateKey
17+
}
18+
19+
func (k *keyRetrieverImpl) GetNextRecoveryPublicKey(didID string) (crypto.PublicKey, error) {
20+
return k.nextRecoveryPublicKey, nil
21+
}
22+
23+
func (k *keyRetrieverImpl) GetNextUpdatePublicKey(didID string) (crypto.PublicKey, error) {
24+
return k.nextUpdatePublicKey, nil
25+
}
26+
27+
keyRetrieverImpl := &keyRetrieverImpl{}
28+
29+
vdr, err := longform.New(keyRetrieverImpl)
30+
if err != nil {
31+
return err
32+
}
33+
```
34+
35+
## Create DID
36+
For creating DID use vdr create and pass DID document.
37+
38+
```
39+
import (
40+
"crypto"
41+
"crypto/ed25519"
42+
"crypto/rand"
43+
"fmt"
44+
45+
ariesdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
46+
"github.com/hyperledger/aries-framework-go/pkg/doc/jose"
47+
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
48+
49+
"github.com/hyperledger/aries-framework-go-ext/component/vdr/longform"
50+
)
51+
52+
recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
53+
if err != nil {
54+
return err
55+
}
56+
57+
updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
58+
if err != nil {
59+
return err
60+
}
61+
62+
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
63+
if err != nil {
64+
return err
65+
}
66+
67+
jwk, err := jose.JWKFromKey(didPublicKey)
68+
if err != nil {
69+
return err
70+
}
71+
72+
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
73+
if err != nil {
74+
return err
75+
}
76+
77+
didDoc := &ariesdid.Doc{}
78+
79+
// add did keys
80+
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm,
81+
ariesdid.Authentication))
82+
83+
// add did services
84+
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}}
85+
86+
// create did
87+
createdDocResolution, err := vdr.Create(didDoc,
88+
vdrapi.WithOption(longform.RecoveryPublicKeyOpt, recoveryKey),
89+
vdrapi.WithOption(longform.UpdatePublicKeyOpt, updateKey),
90+
if err != nil {
91+
return err
92+
}
93+
94+
fmt.Println(createdDocResolution.DIDDocument.ID)
95+
96+
// recovery private key should be saved for future use.
97+
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey
98+
// update private key should be saved for future use.
99+
keyRetrieverImpl.updateKey = updateKeyPrivateKey
100+
101+
102+
longFormDID := createdDocResolution.DIDDocument.ID
103+
```
104+
105+
## Resolve DID
106+
For resolving DID use vdr read and pass long form DID.
107+
108+
```
109+
docResolution, err := vdr.Read(longFormDID)
110+
if err != nil {
111+
return err
112+
}
113+
114+
fmt.Println(docResolution.DIDDocument.ID)
115+
```
116+
117+
## Update DID
118+
Not supported.
119+
120+
## Recover DID
121+
Not supported.
122+
123+
## Deactivate DID
124+
Not supported.

0 commit comments

Comments
 (0)