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

Commit

Permalink
chore: updare aries revision (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
  • Loading branch information
fqutishat authored Jan 20, 2021
1 parent 6441de1 commit 18c6f2a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 32 deletions.
2 changes: 1 addition & 1 deletion component/vdr/sidetree/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/hyperledger/aries-framework-go/pkg/common/log"
docdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/create"
"github.com/trustbloc/sidetree-core-go/pkg/commitment"
"github.com/trustbloc/sidetree-core-go/pkg/jws"
"github.com/trustbloc/sidetree-core-go/pkg/patch"
Expand All @@ -34,6 +33,7 @@ import (
"github.com/trustbloc/sidetree-core-go/pkg/versions/0_1/client"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/doc"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/create"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/deactivate"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/recovery"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/update"
Expand Down
34 changes: 17 additions & 17 deletions component/vdr/sidetree/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ import (
"testing"

"github.com/hyperledger/aries-framework-go/pkg/doc/did"
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/create"
vdrdoc "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/doc"
gojose "github.com/square/go-jose/v3"
"github.com/stretchr/testify/require"
"github.com/trustbloc/sidetree-core-go/pkg/commitment"
"github.com/trustbloc/sidetree-core-go/pkg/util/pubkey"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/doc"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/create"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/deactivate"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/recovery"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/option/update"
Expand Down Expand Up @@ -285,7 +284,7 @@ func TestClient_RecoverDID(t *testing.T) {
recovery.WithSigningKeyID("k1"), recovery.WithNextRecoveryPublicKey(pubKey),
recovery.WithSidetreeEndpoint(func() ([]string, error) {
return []string{"url"}, nil
}), recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&vdrdoc.PublicKey{
}), recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&doc.PublicKey{
ID: "key3",
Type: doc.JWSVerificationKey2020,
JWK: gojose.JSONWebKey{},
Expand Down Expand Up @@ -313,7 +312,7 @@ func TestClient_RecoverDID(t *testing.T) {
return []string{serv.URL}, nil
}), recovery.WithSigningKey(ecPrivKey), recovery.WithSigningKeyID("k1"),
recovery.WithNextRecoveryPublicKey(pubKey),
recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&vdrdoc.PublicKey{
recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&doc.PublicKey{
ID: "key3",
Type: doc.Ed25519VerificationKey2018,
JWK: gojose.JSONWebKey{Key: pubKey},
Expand Down Expand Up @@ -355,7 +354,7 @@ func TestClient_RecoverDID(t *testing.T) {
return []string{serv.URL}, nil
}), recovery.WithSigningKey(signingKey), recovery.WithRevealValue(rv),
recovery.WithSigningKeyID("k1"), recovery.WithNextRecoveryPublicKey(pubKey),
recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&vdrdoc.PublicKey{
recovery.WithNextUpdatePublicKey(pubKey), recovery.WithPublicKey(&doc.PublicKey{
ID: "key3",
Type: doc.Ed25519VerificationKey2018,
JWK: gojose.JSONWebKey{Key: pubKey},
Expand Down Expand Up @@ -482,7 +481,7 @@ func TestClient_UpdateDID(t *testing.T) {
}), update.WithSigningKey(signingKey), update.WithRevealValue(rv),
update.WithNextUpdatePublicKey(pubKey), update.WithRemoveService("svc1"),
update.WithRemoveService("svc1"), update.WithRemovePublicKey("k1"),
update.WithRemovePublicKey("k2"), update.WithAddPublicKey(&vdrdoc.PublicKey{
update.WithRemovePublicKey("k2"), update.WithAddPublicKey(&doc.PublicKey{
ID: "key3",
Type: doc.Ed25519VerificationKey2018,
JWK: gojose.JSONWebKey{Key: pubKey},
Expand Down Expand Up @@ -517,7 +516,7 @@ func TestClient_UpdateDID(t *testing.T) {
}), update.WithSigningKey(signingKey), update.WithRevealValue(rv),
update.WithNextUpdatePublicKey(pubKey), update.WithRemoveService("svc1"),
update.WithRemoveService("svc1"), update.WithRemovePublicKey("k1"),
update.WithRemovePublicKey("k2"), update.WithAddPublicKey(&vdrdoc.PublicKey{
update.WithRemovePublicKey("k2"), update.WithAddPublicKey(&doc.PublicKey{
ID: "key3",
Type: doc.Ed25519VerificationKey2018,
JWK: gojose.JSONWebKey{Key: pubKey},
Expand All @@ -540,7 +539,7 @@ func TestClient_CreateDID(t *testing.T) {
require.Nil(t, didResol)

didResol, err = v.CreateDID(create.WithUpdatePublicKey(pubKey), create.WithRecoveryPublicKey(pubKey),
create.WithEndpoints(func() ([]string, error) {
create.WithSidetreeEndpoint(func() ([]string, error) {
return nil, fmt.Errorf("failed to get endpoints")
}))
require.Error(t, err)
Expand All @@ -558,7 +557,7 @@ func TestClient_CreateDID(t *testing.T) {
require.NoError(t, err)

didResol, err := v.CreateDID(create.WithRecoveryPublicKey(ed25519RecoveryPubKey),
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithEndpoints(func() ([]string, error) {
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{"url"}, nil
}))
require.Error(t, err)
Expand All @@ -572,7 +571,7 @@ func TestClient_CreateDID(t *testing.T) {
defer serv.Close()

didResol, err = v.CreateDID(create.WithRecoveryPublicKey(ed25519RecoveryPubKey),
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithEndpoints(func() ([]string, error) {
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{serv.URL}, nil
}))
require.Error(t, err)
Expand All @@ -589,7 +588,7 @@ func TestClient_CreateDID(t *testing.T) {
defer serv.Close()

didResol, err = v.CreateDID(create.WithRecoveryPublicKey(ed25519RecoveryPubKey),
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithEndpoints(func() ([]string, error) {
create.WithUpdatePublicKey(ed25519UpdatePubKey), create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{serv.URL}, nil
}))
require.Error(t, err)
Expand Down Expand Up @@ -623,16 +622,16 @@ func TestClient_CreateDID(t *testing.T) {
v := sidetree.New(sidetree.WithTLSConfig(nil))

didResol, err := v.CreateDID(create.WithRecoveryPublicKey(ed25519RecoveryPubKey),
create.WithEndpoints(func() ([]string, error) {
create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{serv.URL}, nil
}), create.WithUpdatePublicKey(ecUpdatePrivKey.Public()),
create.WithPublicKey(&vdrdoc.PublicKey{
create.WithPublicKey(&doc.PublicKey{
ID: "key1",
Type: doc.JWSVerificationKey2020,
JWK: gojose.JSONWebKey{Key: ed25519RecoveryPubKey},
Purposes: []string{doc.KeyPurposeAuthentication},
}),
create.WithPublicKey(&vdrdoc.PublicKey{
create.WithPublicKey(&doc.PublicKey{
ID: "key2",
Type: doc.JWSVerificationKey2020,
JWK: gojose.JSONWebKey{Key: ecPrivKey.Public()},
Expand Down Expand Up @@ -664,7 +663,7 @@ func TestClient_CreateDID(t *testing.T) {
v := sidetree.New(sidetree.WithTLSConfig(nil))

_, err = v.CreateDID(create.WithRecoveryPublicKey(ed25519RecoveryPubKey),
create.WithEndpoints(func() ([]string, error) {
create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{serv.URL}, nil
}), create.WithUpdatePublicKey(ecUpdatePrivKey.Public()),
create.WithService(&did.Service{
Expand All @@ -689,7 +688,8 @@ func TestClient_CreateDID(t *testing.T) {
v := sidetree.New()

didResol, err := v.CreateDID(create.WithRecoveryPublicKey("wrongkey"),
create.WithUpdatePublicKey("wrongvalue"), create.WithEndpoints(func() ([]string, error) {
create.WithUpdatePublicKey("wrongvalue"),
create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{"url"}, nil
}))
require.Error(t, err)
Expand Down Expand Up @@ -729,7 +729,7 @@ func TestClient_CreateDID(t *testing.T) {
v := sidetree.New()

didResol, err := v.CreateDID(create.WithRecoveryPublicKey(pubKey),
create.WithEndpoints(func() ([]string, error) {
create.WithSidetreeEndpoint(func() ([]string, error) {
return []string{"url"}, nil
}))
require.Error(t, err)
Expand Down
16 changes: 12 additions & 4 deletions component/vdr/sidetree/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"fmt"

docdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
vdrdoc "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/doc"
gojose "github.com/square/go-jose/v3"
"github.com/trustbloc/sidetree-core-go/pkg/jws"
"github.com/trustbloc/sidetree-core-go/pkg/util/pubkey"
)
Expand Down Expand Up @@ -55,10 +55,18 @@ type rawDoc struct {

// Doc DID Document definition.
type Doc struct {
PublicKey []vdrdoc.PublicKey
PublicKey []PublicKey
Service []docdid.Service
}

// PublicKey struct.
type PublicKey struct {
ID string
Type string
Purposes []string
JWK gojose.JSONWebKey
}

// JSONBytes converts document to json bytes.
func (doc *Doc) JSONBytes() ([]byte, error) {
publicKeys, err := PopulateRawPublicKeys(doc.PublicKey)
Expand All @@ -80,7 +88,7 @@ func (doc *Doc) JSONBytes() ([]byte, error) {
}

// PopulateRawPublicKeys populate raw public keys.
func PopulateRawPublicKeys(pks []vdrdoc.PublicKey) ([]map[string]interface{}, error) {
func PopulateRawPublicKeys(pks []PublicKey) ([]map[string]interface{}, error) {
rawPKs := make([]map[string]interface{}, 0)

for i := range pks {
Expand All @@ -95,7 +103,7 @@ func PopulateRawPublicKeys(pks []vdrdoc.PublicKey) ([]map[string]interface{}, er
return rawPKs, nil
}

func populateRawPublicKey(pk *vdrdoc.PublicKey) (map[string]interface{}, error) {
func populateRawPublicKey(pk *PublicKey) (map[string]interface{}, error) {
rawPK := make(map[string]interface{})
rawPK[jsonldID] = pk.ID
rawPK[jsonldType] = pk.Type
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 @@ -6,7 +6,7 @@ module github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree
go 1.15

require (
github.com/hyperledger/aries-framework-go v0.1.6-0.20210115224010-cf2b2ff61f47
github.com/hyperledger/aries-framework-go v0.1.6-0.20210120000618-bdf82385e9df
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693
github.com/stretchr/testify v1.6.1
github.com/trustbloc/sidetree-core-go v0.1.6-0.20201217192009-0d2b4436912f
Expand Down
5 changes: 2 additions & 3 deletions component/vdr/sidetree/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvh
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hyperledger/aries-framework-go v0.1.6-0.20210115224010-cf2b2ff61f47 h1:6NJyNdq+0KDnADrWIJqxxbrzzwpOM81umCrGDM1zmY4=
github.com/hyperledger/aries-framework-go v0.1.6-0.20210115224010-cf2b2ff61f47/go.mod h1:CB1aCGsuCC/U+mJ43aU5Nx7s6iCYOVquO7kCUn8tVhY=
github.com/hyperledger/aries-framework-go-ext v0.0.0-20210115220449-21b97445a1d5 h1:8ndOr2XGVhEzaSKLJratcJkho6S1sOqWB4jwf7aRFLI=
github.com/hyperledger/aries-framework-go v0.1.6-0.20210120000618-bdf82385e9df h1:lJVRaV0nYqEI5pGOWlNjhsohV/cD5ckMKMeDlpvxHo0=
github.com/hyperledger/aries-framework-go v0.1.6-0.20210120000618-bdf82385e9df/go.mod h1:CB1aCGsuCC/U+mJ43aU5Nx7s6iCYOVquO7kCUn8tVhY=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
73 changes: 73 additions & 0 deletions component/vdr/sidetree/option/create/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// Package create implements sidetree create did option
//
package create

import (
"crypto"

docdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/doc"
)

// Opts create did opts.
type Opts struct {
PublicKeys []doc.PublicKey
Services []docdid.Service
GetEndpoints func() ([]string, error)
RecoveryPublicKey crypto.PublicKey
UpdatePublicKey crypto.PublicKey
SigningKey crypto.PrivateKey
SigningKeyID string
MultiHashAlgorithm uint
}

// Option is a create DID option.
type Option func(opts *Opts)

// WithPublicKey add DID public key.
func WithPublicKey(publicKey *doc.PublicKey) Option {
return func(opts *Opts) {
opts.PublicKeys = append(opts.PublicKeys, *publicKey)
}
}

// WithService add service.
func WithService(service *docdid.Service) Option {
return func(opts *Opts) {
opts.Services = append(opts.Services, *service)
}
}

// WithSidetreeEndpoint get sidetree endpoints.
func WithSidetreeEndpoint(getEndpoints func() ([]string, error)) Option {
return func(opts *Opts) {
opts.GetEndpoints = getEndpoints
}
}

// WithRecoveryPublicKey set recovery public key.
func WithRecoveryPublicKey(recoveryPublicKey crypto.PublicKey) Option {
return func(opts *Opts) {
opts.RecoveryPublicKey = recoveryPublicKey
}
}

// WithUpdatePublicKey set update public key.
func WithUpdatePublicKey(updatePublicKey crypto.PublicKey) Option {
return func(opts *Opts) {
opts.UpdatePublicKey = updatePublicKey
}
}

// WithMultiHashAlgorithm set multi hash algorithm for sidetree request.
func WithMultiHashAlgorithm(multiHashAlgorithm uint) Option {
return func(opts *Opts) {
opts.MultiHashAlgorithm = multiHashAlgorithm
}
}
7 changes: 4 additions & 3 deletions component/vdr/sidetree/option/recovery/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"crypto"

docdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
vdrdoc "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/doc"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/doc"
)

// Opts recover did opts.
type Opts struct {
PublicKeys []vdrdoc.PublicKey
PublicKeys []doc.PublicKey
Services []docdid.Service
GetEndpoints func() ([]string, error)
NextRecoveryPublicKey crypto.PublicKey
Expand All @@ -31,7 +32,7 @@ type Opts struct {
type Option func(opts *Opts)

// WithPublicKey add DID public key.
func WithPublicKey(publicKey *vdrdoc.PublicKey) Option {
func WithPublicKey(publicKey *doc.PublicKey) Option {
return func(opts *Opts) {
opts.PublicKeys = append(opts.PublicKeys, *publicKey)
}
Expand Down
7 changes: 4 additions & 3 deletions component/vdr/sidetree/option/update/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
"crypto"

docdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
vdrdoc "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr/doc"

"github.com/hyperledger/aries-framework-go-ext/component/vdr/sidetree/doc"
)

// Option is a update DID option.
type Option func(opts *Opts)

// Opts update did opts.
type Opts struct {
AddPublicKeys []vdrdoc.PublicKey
AddPublicKeys []doc.PublicKey
AddServices []docdid.Service
RemovePublicKeys []string
RemoveServices []string
Expand All @@ -32,7 +33,7 @@ type Opts struct {
}

// WithAddPublicKey add DID public key.
func WithAddPublicKey(publicKey *vdrdoc.PublicKey) Option {
func WithAddPublicKey(publicKey *doc.PublicKey) Option {
return func(opts *Opts) {
opts.AddPublicKeys = append(opts.AddPublicKeys, *publicKey)
}
Expand Down

0 comments on commit 18c6f2a

Please sign in to comment.