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

Commit e11f0d1

Browse files
committed
chore: update to orb v0.1
Signed-off-by: Firas Qutishat <[email protected]>
1 parent 6c349de commit e11f0d1

File tree

7 files changed

+281
-33
lines changed

7 files changed

+281
-33
lines changed

component/vdr/orb/README.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# Orb VDR
2+
Orb vdr used to manage DID operation.
3+
4+
5+
## New VDR
6+
```
7+
import (
8+
"crypto"
9+
"github.com/hyperledger/aries-framework-go-ext/component/vdr/orb"
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+
func (k *keyRetrieverImpl) GetSigningKey(didID string, ot orb.OperationType) (crypto.PrivateKey, error) {
28+
if ot == orb.Update {
29+
return k.updateKey, nil
30+
}
31+
32+
return k.recoverKey, nil
33+
}
34+
35+
36+
keyRetrieverImpl := &keyRetrieverImpl{}
37+
38+
vdr, err := orb.New(keyRetrieverImpl, orb.WithDomain("https://testnet.devel.trustbloc.dev"))
39+
if err != nil {
40+
return err
41+
}
42+
```
43+
44+
## Create DID
45+
For creating DID use vdr create and pass DID document. To discover orb instance there are two ways explicitly or
46+
through domain.
47+
48+
```
49+
import (
50+
"crypto"
51+
"crypto/ed25519"
52+
"crypto/rand"
53+
"fmt"
54+
55+
ariesdid "github.com/hyperledger/aries-framework-go/pkg/doc/did"
56+
"github.com/hyperledger/aries-framework-go/pkg/doc/jose"
57+
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
58+
59+
"github.com/hyperledger/aries-framework-go-ext/component/vdr/orb"
60+
)
61+
62+
recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
63+
if err != nil {
64+
return err
65+
}
66+
67+
updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
68+
if err != nil {
69+
return err
70+
}
71+
72+
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
73+
if err != nil {
74+
return err
75+
}
76+
77+
jwk, err := jose.JWKFromKey(didPublicKey)
78+
if err != nil {
79+
return err
80+
}
81+
82+
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
83+
if err != nil {
84+
return err
85+
}
86+
87+
didDoc := &ariesdid.Doc{}
88+
89+
// add did keys
90+
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm,
91+
ariesdid.Authentication))
92+
93+
// add did services
94+
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}}
95+
96+
// create did
97+
createdDocResolution, err := vdr.Create(didDoc,
98+
vdrapi.WithOption(orb.RecoveryPublicKeyOpt, recoveryKey),
99+
vdrapi.WithOption(orb.UpdatePublicKeyOpt, updateKey),
100+
// No need to use this option because we already use domain
101+
// vdrapi.WithOption(orb.OperationEndpointsOpt, []string{"https://orb-1.devel.trustbloc.dev/sidetree/v1/operations"}),
102+
vdrapi.WithOption(orb.AnchorOriginOpt, "https://orb-2.devel.trustbloc.dev/services/orb"))
103+
if err != nil {
104+
return err
105+
}
106+
107+
fmt.Println(createdDocResolution.DIDDocument.ID)
108+
109+
// recovery private key be will used to sign next recovery request
110+
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey
111+
// update private key will be used to sign next update request
112+
keyRetrieverImpl.updateKey = updateKeyPrivateKey
113+
114+
115+
// if you need did to be discoverable just add domain to did URI (did:orb:123 => did:orb:domain.com:123)
116+
discoverableDID := strings.ReplaceAll(createdDocResolution.DIDDocument.ID, "did:orb", "did:orb:testnet.devel.trustbloc.dev")
117+
fmt.Println(discoverableDID)
118+
```
119+
120+
## Resolve DID
121+
For resolving DID use vdr read and pass DID URI. To discover orb instance there are two ways explicitly or
122+
through did URI.
123+
124+
```
125+
docResolution, err := vdr.Read(discoverableDID)
126+
if err != nil {
127+
return err
128+
}
129+
130+
fmt.Println(docResolution.DIDDocument.ID)
131+
```
132+
133+
## Update DID
134+
For updating DID use vdr update and pass DID document. To discover orb instance there are two ways explicitly or
135+
through domain.
136+
137+
```
138+
updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
139+
if err != nil {
140+
return err
141+
}
142+
143+
// this key will used for next update request
144+
keyRetrieverImpl.nextUpdatePublicKey = updateKey
145+
146+
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
147+
if err != nil {
148+
return err
149+
}
150+
151+
jwk, err := jose.JWKFromKey(didPublicKey)
152+
if err != nil {
153+
return err
154+
}
155+
156+
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
157+
if err != nil {
158+
return err
159+
}
160+
161+
162+
didDoc := &ariesdid.Doc{ID: discoverableDID}
163+
164+
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm,
165+
ariesdid.Authentication))
166+
167+
didDoc.CapabilityInvocation = append(didDoc.CapabilityInvocation, *ariesdid.NewReferencedVerification(vm,
168+
ariesdid.CapabilityInvocation))
169+
170+
didDoc.Service = []ariesdid.Service{
171+
{
172+
ID: "svc1",
173+
Type: "typeUpdated",
174+
ServiceEndpoint: "http://www.example.com/",
175+
},
176+
{
177+
ID: "svc2",
178+
Type: "type",
179+
ServiceEndpoint: "http://www.example.com/",
180+
},
181+
}
182+
183+
if err := vdr.Update(didDoc); err != nil {
184+
return err
185+
}
186+
187+
// update private key will be used to sign next update request
188+
keyRetrieverImpl.updateKey = updateKeyPrivateKey
189+
```
190+
191+
## Recover DID
192+
For recovering DID use vdr recover and pass DID document. To discover orb instance there are two ways explicitly or
193+
through domain.
194+
195+
```
196+
recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader)
197+
if err != nil {
198+
return err
199+
}
200+
201+
// this key will used for next recover request
202+
keyRetriever.nextRecoveryPublicKey = recoveryKey
203+
204+
didDoc := &ariesdid.Doc{ID: discoverableDID}
205+
206+
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader)
207+
if err != nil {
208+
return err
209+
}
210+
211+
jwk, err := jose.JWKFromKey(didPublicKey)
212+
if err != nil {
213+
return err
214+
}
215+
216+
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk)
217+
if err != nil {
218+
return err
219+
}
220+
221+
222+
didDoc.CapabilityInvocation = append(didDoc.CapabilityInvocation, *ariesdid.NewReferencedVerification(vm,
223+
ariesdid.CapabilityDelegation))
224+
225+
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}}
226+
227+
if err := e.vdr.Update(didDoc,
228+
vdrapi.WithOption(orb.RecoverOpt, true),
229+
vdrapi.WithOption(orb.AnchorOriginOpt, "https://orb-2.devel.trustbloc.dev/services/orb")); err != nil {
230+
return err
231+
}
232+
233+
// recover private key will be used to sign next recover request
234+
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey
235+
```
236+
237+
## Deactivate DID
238+
For deactivating DID use vdr recover and pass DID URI. To discover orb instance there are two ways explicitly or
239+
through domain.
240+
241+
```
242+
if err:=vdr.Deactivate(discoverableDID);err!=nil{
243+
return err
244+
}
245+
```

component/vdr/orb/config/service.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (cs *Service) getSidetreeConfig() (*models.SidetreeConfig, error) { //nolin
144144
return &models.SidetreeConfig{MultiHashAlgorithm: sha2_256, MaxAge: maxAge}, nil
145145
}
146146

147-
func (cs *Service) getEndpoint(domain string) (*models.Endpoint, error) { //nolint: funlen,gocyclo
147+
func (cs *Service) getEndpoint(domain string) (*models.Endpoint, error) { //nolint: funlen,gocyclo,gocognit
148148
var wellKnownResponse restapi.WellKnownResponse
149149

150150
if !strings.HasPrefix(domain, "http://") && !strings.HasPrefix(domain, "https://") {
@@ -158,8 +158,13 @@ func (cs *Service) getEndpoint(domain string) (*models.Endpoint, error) { //noli
158158

159159
var webFingerResponse restapi.WebFingerResponse
160160

161-
err = cs.sendRequest(nil, http.MethodGet, fmt.Sprintf("%s/.well-known/webfinger?resource=%s",
162-
domain, url.PathEscape(wellKnownResponse.ResolutionEndpoint)), &webFingerResponse)
161+
parsedURL, err := url.Parse(wellKnownResponse.ResolutionEndpoint)
162+
if err != nil {
163+
return nil, err
164+
}
165+
166+
err = cs.sendRequest(nil, http.MethodGet, fmt.Sprintf("%s://%s/.well-known/webfinger?resource=%s",
167+
parsedURL.Scheme, parsedURL.Host, url.PathEscape(wellKnownResponse.ResolutionEndpoint)), &webFingerResponse)
163168
if err != nil {
164169
return nil, err
165170
}
@@ -222,8 +227,8 @@ func (cs *Service) getEndpoint(domain string) (*models.Endpoint, error) { //noli
222227
endpoint.ResolutionEndpoints = append(endpoint.ResolutionEndpoints, v.Href)
223228
}
224229

225-
err = cs.sendRequest(nil, http.MethodGet, fmt.Sprintf("%s/.well-known/webfinger?resource=%s",
226-
domain, url.PathEscape(wellKnownResponse.OperationEndpoint)), &webFingerResponse)
230+
err = cs.sendRequest(nil, http.MethodGet, fmt.Sprintf("%s://%s/.well-known/webfinger?resource=%s",
231+
parsedURL.Scheme, parsedURL.Host, url.PathEscape(wellKnownResponse.OperationEndpoint)), &webFingerResponse)
227232
if err != nil {
228233
return nil, err
229234
}

component/vdr/orb/config/service_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
3636
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
3737
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
3838
b, err := json.Marshal(restapi.WellKnownResponse{
39-
OperationEndpoint: "/op",
40-
ResolutionEndpoint: "/resolve1",
39+
OperationEndpoint: "https://localhost/op",
40+
ResolutionEndpoint: "https://localhost/resolve1",
4141
})
4242
require.NoError(t, err)
4343
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -102,8 +102,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
102102
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
103103
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
104104
b, err := json.Marshal(restapi.WellKnownResponse{
105-
OperationEndpoint: "/op",
106-
ResolutionEndpoint: "/resolve1",
105+
OperationEndpoint: "https://localhost/op",
106+
ResolutionEndpoint: "https://localhost/resolve1",
107107
})
108108
require.NoError(t, err)
109109
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -148,8 +148,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
148148
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
149149
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
150150
b, err := json.Marshal(restapi.WellKnownResponse{
151-
OperationEndpoint: "/op",
152-
ResolutionEndpoint: "/resolve1",
151+
OperationEndpoint: "https://localhost/op",
152+
ResolutionEndpoint: "https://localhost/resolve1",
153153
})
154154
require.NoError(t, err)
155155
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -214,8 +214,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
214214
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
215215
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
216216
b, err := json.Marshal(restapi.WellKnownResponse{
217-
OperationEndpoint: "/op",
218-
ResolutionEndpoint: "/resolve1",
217+
OperationEndpoint: "https://localhost/op",
218+
ResolutionEndpoint: "https://localhost/resolve1",
219219
})
220220
require.NoError(t, err)
221221
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -304,8 +304,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
304304
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
305305
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
306306
b, err := json.Marshal(restapi.WellKnownResponse{
307-
OperationEndpoint: "/op",
308-
ResolutionEndpoint: "/resolve",
307+
OperationEndpoint: "https://localhost/op",
308+
ResolutionEndpoint: "https://localhost/resolve",
309309
})
310310
require.NoError(t, err)
311311
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -322,16 +322,17 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
322322
_, err := cs.GetEndpoint("d1")
323323
require.Error(t, err)
324324
require.Contains(t, err.Error(),
325-
"got unexpected response from https://d1/.well-known/webfinger?resource=%2Fresolve status")
325+
"got unexpected response from https://localhost/.well-known"+
326+
"/webfinger?resource=https:%2F%2Flocalhost%2Fresolve status")
326327
})
327328

328329
t.Run("web finger operation return 500 status", func(t *testing.T) {
329330
cs := NewService(WithHTTPClient(
330331
&mockHTTPClient{doFunc: func(req *http.Request) (*http.Response, error) {
331332
if strings.Contains(req.URL.Path, ".well-known/did-orb") {
332333
b, err := json.Marshal(restapi.WellKnownResponse{
333-
OperationEndpoint: "/op",
334-
ResolutionEndpoint: "/resolve",
334+
OperationEndpoint: "https://localhost/op",
335+
ResolutionEndpoint: "https://localhost/resolve",
335336
})
336337
require.NoError(t, err)
337338
r := ioutil.NopCloser(bytes.NewReader(b))
@@ -360,7 +361,8 @@ func TestConfigService_GetEndpoint(t *testing.T) { //nolint: gocyclo,gocognit
360361
_, err := cs.GetEndpoint("d1")
361362
require.Error(t, err)
362363
require.Contains(t, err.Error(),
363-
"got unexpected response from https://d1/.well-known/webfinger?resource=%2Fop status")
364+
"got unexpected response from https://localhost/.well-known/"+
365+
"webfinger?resource=https:%2F%2Flocalhost%2Fop status")
364366
})
365367
}
366368

test/bdd/vdr/orb/create_follow_activity.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ inviteWitnessID=2
1515
curl -o /dev/null -s -w "%{http_code}" --header "Content-Type: application/json" \
1616
--request POST \
1717
--data '{"@context":"https://www.w3.org/ns/activitystreams","id":"'$domain2IRI'/activities/'$followID'","type":"Follow","actor":"'$domain2IRI'","to":"'$domain1IRI'","object":"'$domain1IRI'"}' \
18-
--insecure https://testnet.orb.local/services/orb/inbox
18+
--insecure https://localhost:8009/services/orb/outbox
1919

2020

2121
curl -o /dev/null -s -w "%{http_code}" --header "Content-Type: application/json" \
2222
--request POST \
2323
--data '{"@context":["https://www.w3.org/ns/activitystreams","https://trustbloc.github.io/did-method-orb/contexts/anchor/v1"],"id":"'$domain1IRI'/activities/'$inviteWitnessID'","type":"InviteWitness","actor":"'$domain1IRI'","to":"'$domain2IRI'","object":"'$domain2IRI'"}' \
24-
--insecure https://localhost:8009/services/orb/inbox
24+
--insecure https://testnet.orb.local/services/orb/outbox

test/bdd/vdr/orb/fixtures/orb/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7-
ORB_IMAGE=ghcr.io/trustbloc-cicd/orb
8-
ORB_IMAGE_TAG=v0.1.0-snapshot-f3d673f
7+
ORB_IMAGE=ghcr.io/trustbloc/orb
8+
ORB_IMAGE_TAG=v0.1.0
99

1010
# couch settings
1111
COUCHDB_IMAGE=couchdb

0 commit comments

Comments
 (0)