diff --git a/.github/workflows/vdr-jwk.yml b/.github/workflows/vdr-jwk.yml new file mode 100644 index 00000000..2ab8142a --- /dev/null +++ b/.github/workflows/vdr-jwk.yml @@ -0,0 +1,53 @@ +# +# Copyright SecureKey Technologies Inc. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +name: vdr-jwk +on: + push: + paths: + - 'component/vdr/jwk/**' + pull_request: + paths: + - 'component/vdr/jwk/**' +jobs: + linter: + name: Go linter + timeout-minutes: 10 + env: + LINT_PATH: component/vdr/jwk + 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/jwk + 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/codecov-action@v1.0.14 + with: + file: ./coverage.out + diff --git a/component/vdr/jwk/.custom_golangci.yml b/component/vdr/jwk/.custom_golangci.yml new file mode 100644 index 00000000..c99c36b6 --- /dev/null +++ b/component/vdr/jwk/.custom_golangci.yml @@ -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 diff --git a/component/vdr/jwk/creator.go b/component/vdr/jwk/creator.go new file mode 100644 index 00000000..b333e07b --- /dev/null +++ b/component/vdr/jwk/creator.go @@ -0,0 +1,19 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jwk + +import ( + "fmt" + + "github.com/hyperledger/aries-framework-go/pkg/doc/did" + vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" +) + +// Create new DID document for didDoc. +func (v *VDR) Create(didDoc *did.Doc, opts ...vdrapi.DIDMethodOption) (*did.DocResolution, error) { + return nil, fmt.Errorf("TODO") +} diff --git a/component/vdr/jwk/creator_test.go b/component/vdr/jwk/creator_test.go new file mode 100644 index 00000000..542ee643 --- /dev/null +++ b/component/vdr/jwk/creator_test.go @@ -0,0 +1,25 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jwk_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk" +) + +func TestCreate(t *testing.T) { + t.Run("test create", func(t *testing.T) { + v := jwk.New() + doc, err := v.Create(nil) + require.Error(t, err) + require.Nil(t, doc) + require.Contains(t, err.Error(), "TODO") + }) +} diff --git a/component/vdr/jwk/go.mod b/component/vdr/jwk/go.mod new file mode 100644 index 00000000..19c13aea --- /dev/null +++ b/component/vdr/jwk/go.mod @@ -0,0 +1,36 @@ +// Copyright SecureKey Technologies Inc. All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +module github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk + +go 1.19 + +require ( + github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301 + github.com/stretchr/testify v1.8.1 +) + +require ( + github.com/btcsuite/btcd v0.22.0-beta // indirect + github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/hyperledger/aries-framework-go/spi v0.0.0-20221025204933-b807371b6f1e // indirect + github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect + github.com/multiformats/go-base32 v0.1.0 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/multiformats/go-multibase v0.1.1 // indirect + github.com/piprate/json-gold v0.4.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pquerna/cachecontrol v0.1.0 // indirect + github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect + github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/xeipuuv/gojsonschema v1.2.0 // indirect + golang.org/x/crypto v0.1.0 // indirect + golang.org/x/sys v0.1.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/component/vdr/jwk/go.sum b/component/vdr/jwk/go.sum new file mode 100644 index 00000000..144eb906 --- /dev/null +++ b/component/vdr/jwk/go.sum @@ -0,0 +1,116 @@ +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= +github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/tink/go v1.7.0 h1:6Eox8zONGebBFcCBqkVmt60LaWZa6xg1cl/DwAh/J1w= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301 h1:NBu2JJwjCrolvQj4/fcdVHwiBRMOUFi3TjjmX3FW5rs= +github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301/go.mod h1:5lp5+NPjRngsjFLYYGg5mtkvw6I4Mr7CKz+wHYxROk0= +github.com/hyperledger/aries-framework-go/spi v0.0.0-20221025204933-b807371b6f1e h1:SxbXlF39661T9w/L9PhVdtbJfJ51Pm4JYEEW6XfZHEQ= +github.com/hyperledger/aries-framework-go/spi v0.0.0-20221025204933-b807371b6f1e/go.mod h1:oryUyWb23l/a3tAP9KW+GBbfcfqp9tZD4y5hSkFrkqI= +github.com/hyperledger/ursa-wrapper-go v0.3.1 h1:Do+QrVNniY77YK2jTIcyWqj9rm/Yb5SScN0bqCjiibA= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 h1:kMJlf8z8wUcpyI+FQJIdGjAhfTww1y0AbQEv86bpVQI= +github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69/go.mod h1:tlkavyke+Ac7h8R3gZIjI5LKBcvMlSWnXNMgT3vZXo8= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= +github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= +github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI= +github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/piprate/json-gold v0.4.2 h1:Rq8V+637HOFcj20KdTqW/g/llCwX2qtau0g5d1pD79o= +github.com/piprate/json-gold v0.4.2/go.mod h1:OK1z7UgtBZk06n2cDE2OSq1kffmjFFp5/2yhLLCz9UM= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= +github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc= +github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= +github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y= +github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693/go.mod h1:6hSY48PjDm4UObWmGLyJE9DxYVKTgR9kbCspXXJEhcU= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 h1:RBkacARv7qY5laaXGlF4wFB/tk5rnthhPb8oIBGoagY= +github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8/go.mod h1:9PdLyPiZIiW3UopXyRnPYyjUXSpiQNHRLu8fOsR3o8M= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/component/vdr/jwk/resolver.go b/component/vdr/jwk/resolver.go new file mode 100644 index 00000000..dba8c43e --- /dev/null +++ b/component/vdr/jwk/resolver.go @@ -0,0 +1,96 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jwk + +import ( + "encoding/base64" + "encoding/json" + "fmt" + + "github.com/hyperledger/aries-framework-go/pkg/doc/did" + "github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk" + vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" +) + +const ( + schemaResV1 = "https://w3id.org/did-resolution/v1" + schemaDIDV1 = "https://w3id.org/did/v1" + jwsSuiteV1 = "https://w3id.org/security/suites/jws-2020/v1" + jsonWebKey2020 = "JsonWebKey2020" +) + +// Read expands did:jwk value to a DID document. +func (v *VDR) Read(didJWK string, _ ...vdrapi.DIDMethodOption) (*did.DocResolution, error) { + parsed, err := did.Parse(didJWK) + if err != nil { + return nil, fmt.Errorf("jwk-vdr read: failed to parse DID: %w", err) + } + + if parsed.Method != DIDMethod { + return nil, fmt.Errorf("jwk-vdr read: invalid method: %s", parsed.Method) + } + + key, err := getJWK(parsed.MethodSpecificID) + if err != nil { + return nil, fmt.Errorf("jwk-vdr read: failed to get key: %w", err) + } + + didDoc, err := createJSONWebKey2020DIDDoc(didJWK, key) + if err != nil { + return nil, fmt.Errorf("jwk-vdr read: creating did document from JWK key failed: %w", err) + } + + return &did.DocResolution{Context: []string{schemaResV1}, DIDDocument: didDoc}, nil //nolint:exhaustruct +} + +func createJSONWebKey2020DIDDoc(didJWK string, key *jwk.JWK) (*did.Doc, error) { + vm, err := did.NewVerificationMethodFromJWK(fmt.Sprintf("%s#0", didJWK), jsonWebKey2020, didJWK, key) + if err != nil { + return nil, fmt.Errorf("error creating verification method %w", err) + } + + didDoc := createDoc(vm, didJWK) + + return didDoc, nil +} + +func createDoc(pubKey *did.VerificationMethod, didJWK string) *did.Doc { + didDoc := &did.Doc{ //nolint:exhaustruct + Context: []string{schemaDIDV1, jwsSuiteV1}, + ID: didJWK, + VerificationMethod: []did.VerificationMethod{*pubKey}, + } + + if pubKey.JSONWebKey().Use == "" || pubKey.JSONWebKey().Use == "sig" { + didDoc.Authentication = []did.Verification{*did.NewReferencedVerification(pubKey, did.Authentication)} + didDoc.AssertionMethod = []did.Verification{*did.NewReferencedVerification(pubKey, did.AssertionMethod)} + didDoc.CapabilityDelegation = []did.Verification{*did.NewReferencedVerification(pubKey, did.CapabilityDelegation)} + didDoc.CapabilityInvocation = []did.Verification{*did.NewReferencedVerification(pubKey, did.CapabilityInvocation)} + } + + if pubKey.JSONWebKey().Use == "" || pubKey.JSONWebKey().Use == "enc" { + didDoc.KeyAgreement = []did.Verification{*did.NewReferencedVerification(pubKey, did.KeyAgreement)} + } + + return didDoc +} + +func getJWK(jwkMethodID string) (*jwk.JWK, error) { + decoded, err := base64.RawURLEncoding.DecodeString(jwkMethodID) + if err != nil { + return nil, fmt.Errorf("failed to decode key: %w", err) + } + + var key jwk.JWK + + err = json.Unmarshal(decoded, &key) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal key: %w", err) + } + + return &key, nil +} diff --git a/component/vdr/jwk/resolver_test.go b/component/vdr/jwk/resolver_test.go new file mode 100644 index 00000000..4411b32e --- /dev/null +++ b/component/vdr/jwk/resolver_test.go @@ -0,0 +1,201 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jwk_test + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/hyperledger/aries-framework-go/pkg/doc/did" + "github.com/stretchr/testify/require" + + "github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk" +) + +func TestReadInvalidDID(t *testing.T) { + t.Run("validate an invalid did", func(t *testing.T) { + v := jwk.New() + + doc, err := v.Read("whatever") + require.Error(t, err) + require.Contains(t, err.Error(), "jwk-vdr read: failed to parse DID: invalid did") + require.Nil(t, doc) + }) + + t.Run("validate an invalid did method", func(t *testing.T) { + v := jwk.New() + + doc, err := v.Read("did:different:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH") + require.Error(t, err) + require.Contains(t, err.Error(), "jwk-vdr read: invalid method: different") + require.Nil(t, doc) + }) + + t.Run("get JWK from method specific ID - unmarshal error", func(t *testing.T) { + v := jwk.New() + + doc, err := v.Read("did:jwk:invalid") + require.Error(t, err) + require.Contains(t, err.Error(), + "jwk-vdr read: failed to get key: failed to unmarshal key: invalid character") + require.Nil(t, doc) + }) + + t.Run("get JWK from method specific ID - decode error", func(t *testing.T) { + v := jwk.New() + + doc, err := v.Read("did:jwk:1-2-3") + require.Error(t, err) + require.Contains(t, err.Error(), + "jwk-vdr read: failed to get key: failed to decode key: illegal base64 data") + require.Nil(t, doc) + }) +} + +func TestReadP256(t *testing.T) { + v := jwk.New() + + t.Run("success", func(t *testing.T) { + docResolution, err := v.Read(p256JWK) + require.NoError(t, err) + require.NotNil(t, docResolution.DIDDocument) + + didDoc := docResolution.DIDDocument + err = prettyPrint(didDoc) + require.NoError(t, err) + + expectedDoc, err := did.ParseDocument([]byte(expectedP256DIDDocument)) + require.NoError(t, err) + + require.Equal(t, didDoc.ID, expectedDoc.ID) + + require.Equal(t, 1, len(didDoc.VerificationMethod)) + require.Equal(t, expectedDoc.VerificationMethod[0].ID, didDoc.VerificationMethod[0].ID) + require.Equal(t, expectedDoc.VerificationMethod[0].Controller, didDoc.VerificationMethod[0].Controller) + require.Equal(t, expectedDoc.VerificationMethod[0].Type, didDoc.VerificationMethod[0].Type) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Kty, didDoc.VerificationMethod[0].JSONWebKey().Kty) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Crv, didDoc.VerificationMethod[0].JSONWebKey().Crv) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Use, didDoc.VerificationMethod[0].JSONWebKey().Use) + + require.Equal(t, 1, len(didDoc.AssertionMethod)) + require.Equal(t, expectedDoc.AssertionMethod[0], didDoc.AssertionMethod[0]) + require.Equal(t, 1, len(didDoc.Authentication)) + require.Equal(t, expectedDoc.Authentication[0], didDoc.Authentication[0]) + require.Equal(t, 1, len(didDoc.CapabilityDelegation)) + require.Equal(t, expectedDoc.CapabilityDelegation[0], didDoc.CapabilityDelegation[0]) + require.Equal(t, 1, len(didDoc.CapabilityInvocation)) + require.Equal(t, expectedDoc.CapabilityInvocation[0], didDoc.CapabilityInvocation[0]) + require.Equal(t, 1, len(didDoc.KeyAgreement)) + require.Equal(t, expectedDoc.KeyAgreement[0], didDoc.KeyAgreement[0]) + }) +} + +func TestReadX25519(t *testing.T) { + v := jwk.New() + + t.Run("success", func(t *testing.T) { + docResolution, err := v.Read(x25519) + require.NoError(t, err) + require.NotNil(t, docResolution.DIDDocument) + + didDoc := docResolution.DIDDocument + + err = prettyPrint(didDoc) + require.NoError(t, err) + + expectedDoc, err := did.ParseDocument([]byte(expectedX25519Document)) + require.NoError(t, err) + + require.Equal(t, didDoc.ID, expectedDoc.ID) + + require.Equal(t, 1, len(didDoc.VerificationMethod)) + require.Equal(t, expectedDoc.VerificationMethod[0].ID, didDoc.VerificationMethod[0].ID) + require.Equal(t, expectedDoc.VerificationMethod[0].Controller, didDoc.VerificationMethod[0].Controller) + require.Equal(t, expectedDoc.VerificationMethod[0].Type, didDoc.VerificationMethod[0].Type) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Kty, didDoc.VerificationMethod[0].JSONWebKey().Kty) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Crv, didDoc.VerificationMethod[0].JSONWebKey().Crv) + require.Equal(t, expectedDoc.VerificationMethod[0].JSONWebKey().Use, didDoc.VerificationMethod[0].JSONWebKey().Use) + + require.Equal(t, 0, len(didDoc.AssertionMethod)) + require.Equal(t, 0, len(didDoc.Authentication)) + require.Equal(t, 0, len(didDoc.CapabilityDelegation)) + require.Equal(t, 0, len(didDoc.CapabilityInvocation)) + require.Equal(t, 1, len(didDoc.KeyAgreement)) + require.Equal(t, expectedDoc.KeyAgreement[0], didDoc.KeyAgreement[0]) + }) +} + +func TestCreateJsonWeKey(t *testing.T) { + t.Run("test invalid code", func(t *testing.T) { + }) +} + +func prettyPrint(result interface{}) error { + b, err := json.MarshalIndent(result, "", " ") + if err != nil { + return err + } + + fmt.Println(string(b)) + + return nil +} + +const p256JWK = `did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9` + +const x25519 = `did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJYMjU1MTkiLCJ1c2UiOiJlbmMiLCJ4IjoiM3A3YmZYdDl3YlRUVzJIQzdPUTFOei1EUThoYmVHZE5yZngtRkctSUswOCJ9` + +const expectedP256DIDDocument = ` +{ + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9", + "verificationMethod": [ + { + "id": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0", + "type": "JsonWebKey2020", + "controller": "did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9", + "publicKeyJwk": { + "crv": "P-256", + "kty": "EC", + "x": "acbIQiuMs3i8_uszEjJ2tpTtRM4EU3yz91PH6CdH2V0", + "y": "_KcyLj9vWMptnmKtm46GqDz8wf74I5LKgrl2GzH3nSE" + } + } + ], + "assertionMethod": ["did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0"], + "authentication": ["did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0"], + "capabilityInvocation": ["did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0"], + "capabilityDelegation": ["did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0"], + "keyAgreement": ["did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9#0"] +}` + +const expectedX25519Document = ` +{ + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3id.org/security/suites/jws-2020/v1" + ], + "id": "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJYMjU1MTkiLCJ1c2UiOiJlbmMiLCJ4IjoiM3A3YmZYdDl3YlRUVzJIQzdPUTFOei1EUThoYmVHZE5yZngtRkctSUswOCJ9", + "verificationMethod": [ + { + "id": "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJYMjU1MTkiLCJ1c2UiOiJlbmMiLCJ4IjoiM3A3YmZYdDl3YlRUVzJIQzdPUTFOei1EUThoYmVHZE5yZngtRkctSUswOCJ9#0", + "type": "JsonWebKey2020", + "controller": "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJYMjU1MTkiLCJ1c2UiOiJlbmMiLCJ4IjoiM3A3YmZYdDl3YlRUVzJIQzdPUTFOei1EUThoYmVHZE5yZngtRkctSUswOCJ9", + "publicKeyJwk": { + "kty":"OKP", + "crv":"X25519", + "use":"enc", + "x":"3p7bfXt9wbTTW2HC7OQ1Nz-DQ8hbeGdNrfx-FG-IK08" + } + } + ], + "keyAgreement": ["did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJYMjU1MTkiLCJ1c2UiOiJlbmMiLCJ4IjoiM3A3YmZYdDl3YlRUVzJIQzdPUTFOei1EUThoYmVHZE5yZngtRkctSUswOCJ9#0"] +}` diff --git a/component/vdr/jwk/vdr.go b/component/vdr/jwk/vdr.go new file mode 100644 index 00000000..3deba6ec --- /dev/null +++ b/component/vdr/jwk/vdr.go @@ -0,0 +1,48 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package jwk implements did:jwk method +package jwk + +import ( + "fmt" + + diddoc "github.com/hyperledger/aries-framework-go/pkg/doc/did" + vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" +) + +const ( + // DIDMethod did method. + DIDMethod = "jwk" +) + +// VDR implements did:jwk method support. +type VDR struct{} + +// New returns new instance of VDR that works with did:jwk method. +func New() *VDR { + return &VDR{} +} + +// Accept accepts did:jwk method. +func (v *VDR) Accept(method string, opts ...vdrapi.DIDMethodOption) bool { + return method == DIDMethod +} + +// Close frees resources being maintained by VDR. +func (v *VDR) Close() error { + return nil +} + +// Update did doc. +func (v *VDR) Update(didDoc *diddoc.Doc, opts ...vdrapi.DIDMethodOption) error { + return fmt.Errorf("not supported") +} + +// Deactivate did doc. +func (v *VDR) Deactivate(didID string, opts ...vdrapi.DIDMethodOption) error { + return fmt.Errorf("not supported") +} diff --git a/component/vdr/jwk/vdr_test.go b/component/vdr/jwk/vdr_test.go new file mode 100644 index 00000000..01ca516a --- /dev/null +++ b/component/vdr/jwk/vdr_test.go @@ -0,0 +1,62 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package jwk_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/hyperledger/aries-framework-go-ext/component/vdr/jwk" + "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" +) + +var _ vdr.VDR = (*jwk.VDR)(nil) // verify interface compliance + +func TestAccept(t *testing.T) { + t.Run("jwk method", func(t *testing.T) { + v := jwk.New() + require.NotNil(t, v) + + accept := v.Accept("jwk") + require.True(t, accept) + }) + + t.Run("other method", func(t *testing.T) { + v := jwk.New() + require.NotNil(t, v) + + accept := v.Accept("other") + require.False(t, accept) + }) +} + +func TestUpdate(t *testing.T) { + t.Run("test update", func(t *testing.T) { + v := jwk.New() + err := v.Update(nil) + require.Error(t, err) + require.Contains(t, err.Error(), "not supported") + }) +} + +func TestDeactivate(t *testing.T) { + t.Run("test deactivate", func(t *testing.T) { + v := jwk.New() + err := v.Deactivate("") + require.Error(t, err) + require.Contains(t, err.Error(), "not supported") + }) +} + +func TestClose(t *testing.T) { + t.Run("test success", func(t *testing.T) { + v := jwk.New() + require.NotNil(t, v) + require.NoError(t, v.Close()) + }) +}