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

Commit

Permalink
chore: Add options to VDR accept; update long-form logic
Browse files Browse the repository at this point in the history
Currently VDR makes decision on whether to accept or reject request based on method only.
Add options to VDR Accept function so VDR can make more complex decisions (for example
long-form VDR should reject request if number of parts in DID is not at least four)

Closes #305

Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
  • Loading branch information
sandrask committed Dec 1, 2022
1 parent 132d491 commit 9d06a57
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 21 deletions.
2 changes: 1 addition & 1 deletion component/vdr/longform/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.19

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4
github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220610133818-119077b0ec85
github.com/piprate/json-gold v0.4.2
Expand Down
4 changes: 2 additions & 2 deletions component/vdr/longform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ 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.20221104133505-b2cd6a82a8e4 h1:M9FRYd7XTKkcLNkWP7s2wig7Sjbo0B40Nrn8k2aGLMg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4/go.mod h1:5lp5+NPjRngsjFLYYGg5mtkvw6I4Mr7CKz+wHYxROk0=
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-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122 h1:lLClFk/2sgr8B15E854dtgxK9b6R+B8qPJXin4mgTFo=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122/go.mod h1:kHGEwgl2Wo1dYj0rs6u8Kk/GjHmmwZI7445lU+9CJtI=
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220610133818-119077b0ec85 h1:P82lZe6zDjaP2j87nDYQBSBYrB6Nq6nc9MtyNMC3K4A=
Expand Down
41 changes: 39 additions & 2 deletions component/vdr/longform/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const (

sha2_256 = 18
defaultDIDMethod = "ion"

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

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

type sidetreeClient interface {
Expand Down Expand Up @@ -124,8 +130,39 @@ func createJSONLDDocumentLoader() (jsonld.DocumentLoader, error) {
}

// Accept did method.
func (v *VDR) Accept(method string) bool {
return method == v.method
func (v *VDR) Accept(method string, opts ...vdrapi.DIDMethodOption) bool {
if method != v.method {
return false
}

// method is valid; now check additional info (if present)
acceptOpts := &vdrapi.DIDMethodOpts{Values: make(map[string]interface{})}

// apply options
for _, opt := range opts {
opt(acceptOpts)
}

// vdr accept option can be provided as additional clue for choosing (or rejecting) VDR
vdrAcceptObj, ok := acceptOpts.Values[VDRAcceptOpt]
if ok {
vdrAccept, strOk := vdrAcceptObj.(string)
if strOk {
return vdrAccept == "long-form"
}
}

// DID accept option is always provided by registry for read, update and deactivate.
didObj, ok := acceptOpts.Values[DIDAcceptOpt]
if ok {
did, strOk := didObj.(string)
if strOk {
didParts := strings.Split(did, ":")
return len(didParts) > 3
}
}

return false
}

// Close vdr.
Expand Down
45 changes: 39 additions & 6 deletions component/vdr/longform/vdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,59 @@ const (
)

func TestVDRI_Accept(t *testing.T) {
t.Run("test success", func(t *testing.T) {
t.Run("test success - did accept option", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.True(t, v.Accept(defaultDIDMethod,
vdrapi.WithOption(DIDAcceptOpt, "did:ion:suffix:request")))
})

t.Run("test success - vdr accept option", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.True(t, v.Accept(defaultDIDMethod,
vdrapi.WithOption(VDRAcceptOpt, "long-form")))
})

t.Run("test success - vdr accept option and did accept option (vdr accept is processed first)", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.True(t, v.Accept(defaultDIDMethod))
require.True(t, v.Accept(defaultDIDMethod,
vdrapi.WithOption(VDRAcceptOpt, "long-form"),
vdrapi.WithOption(DIDAcceptOpt, "did:ion:suffix")))
})

t.Run("test return false", func(t *testing.T) {
t.Run("test return false - different method", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.False(t, v.Accept("different"))
})

t.Run("test return false - short form did", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.False(t, v.Accept(defaultDIDMethod,
vdrapi.WithOption(DIDAcceptOpt, "did:ion:suffix")))
})

t.Run("test return false - vdr accept option different", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.False(t, v.Accept(defaultDIDMethod,
vdrapi.WithOption(VDRAcceptOpt, "different")))
})

t.Run("test return false - no options provided", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.False(t, v.Accept(defaultDIDMethod))
})
}

func TestVDRI_Close(t *testing.T) {
t.Run("test success", func(t *testing.T) {
v, err := New()
require.NoError(t, err)
require.True(t, v.Accept(defaultDIDMethod))

err = v.Close()
require.NoError(t, err)
Expand All @@ -69,8 +104,6 @@ func TestVDRI_Options(t *testing.T) {

v, err := New(WithDIDMethod("different"), WithDocumentLoader(docLoader))
require.NoError(t, err)
require.False(t, v.Accept(defaultDIDMethod))
require.True(t, v.Accept("different"))

err = v.Close()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion component/vdr/orb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.19

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4
github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220610133818-119077b0ec85
github.com/opentracing/opentracing-go v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions component/vdr/orb/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4 h1:M9FRYd7XTKkcLNkWP7s2wig7Sjbo0B40Nrn8k2aGLMg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4/go.mod h1:5lp5+NPjRngsjFLYYGg5mtkvw6I4Mr7CKz+wHYxROk0=
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-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf h1:F12zbOSRsye3IWK3Zb6prgrqQQFYnz5zjGSCh9pfYzk=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf/go.mod h1:GDANCnJONcCqBvv6QgKuk5Y2FWHyD/Hu26kyc7NTyfY=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122 h1:lLClFk/2sgr8B15E854dtgxK9b6R+B8qPJXin4mgTFo=
Expand Down
2 changes: 1 addition & 1 deletion component/vdr/orb/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func createJSONLDDocumentLoader() (jsonld.DocumentLoader, error) {
}

// Accept did method.
func (v *VDR) Accept(method string) bool {
func (v *VDR) Accept(method string, opts ...vdrapi.DIDMethodOption) bool {
return method == DIDMethod
}

Expand Down
2 changes: 1 addition & 1 deletion component/vdr/sidetree/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.19

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4
github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693
github.com/stretchr/testify v1.8.1
github.com/trustbloc/sidetree-core-go v1.0.0-rc3.0.20221028171319-8d44bd1cace7
Expand Down
4 changes: 2 additions & 2 deletions component/vdr/sidetree/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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.20221104133505-b2cd6a82a8e4 h1:M9FRYd7XTKkcLNkWP7s2wig7Sjbo0B40Nrn8k2aGLMg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4/go.mod h1:5lp5+NPjRngsjFLYYGg5mtkvw6I4Mr7CKz+wHYxROk0=
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=
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/vdr/orb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go 1.19
require (
github.com/cucumber/godog v0.9.0
github.com/fsouza/go-dockerclient v1.7.4
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4
github.com/hyperledger/aries-framework-go v0.1.9-0.20221201073943-47b08f16c301
github.com/hyperledger/aries-framework-go-ext/component/vdr/orb v0.0.0
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220610133818-119077b0ec85
Expand Down
4 changes: 2 additions & 2 deletions test/bdd/vdr/orb/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4 h1:M9FRYd7XTKkcLNkWP7s2wig7Sjbo0B40Nrn8k2aGLMg=
github.com/hyperledger/aries-framework-go v0.1.9-0.20221104133505-b2cd6a82a8e4/go.mod h1:5lp5+NPjRngsjFLYYGg5mtkvw6I4Mr7CKz+wHYxROk0=
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-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf h1:F12zbOSRsye3IWK3Zb6prgrqQQFYnz5zjGSCh9pfYzk=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20220615170242-cda5092b4faf/go.mod h1:GDANCnJONcCqBvv6QgKuk5Y2FWHyD/Hu26kyc7NTyfY=
github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree v1.0.0-rc3.0.20221104150937-07bfbe450122 h1:lLClFk/2sgr8B15E854dtgxK9b6R+B8qPJXin4mgTFo=
Expand Down

0 comments on commit 9d06a57

Please sign in to comment.