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

Commit

Permalink
Merge pull request #128 from sandrask/issue-125
Browse files Browse the repository at this point in the history
chore: Update to latest sidetree-core
  • Loading branch information
fqutishat authored Feb 14, 2020
2 parents a410340 + efe9007 commit dcad027
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cmd/chaincode/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (

couchDB = "couchdb"
docsCollIndex = `{"index": {"fields": ["id"]}, "ddoc": "indexIDDoc", "name": "indexID", "type": "json"}`
queryByIDTemplate = `{"selector":{"id":"%s"},"use_index":["_design/indexIDDoc","indexID"],"fields":["id","encodedPayload","hashAlgorithmInMultiHashCode","operationIndex","patch","signature","signingKeyID","transactionNumber","transactionTime","type","uniqueSuffix"]}`
queryByIDTemplate = `{"selector":{"id":"%s"},"use_index":["_design/indexIDDoc","indexID"],"fields":["id","encodedPayload","encodedProtectedHeader","document","updateOTP","recoveryOTP","nextUpdateOTPHash","nextRecoveryOTPHash","hashAlgorithmInMultiHashCode","operationIndex","patch","signature","signingKeyID","transactionNumber","transactionTime","type","uniqueSuffix"]}`
)

// funcMap is a map of functions by function name
Expand Down
4 changes: 2 additions & 2 deletions cmd/peer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ github.com/trustbloc/fabric-peer-ext/mod/peer v0.0.0-20200211231405-e21ab2bc259f
github.com/trustbloc/fabric-peer-ext/mod/peer v0.0.0-20200211231405-e21ab2bc259f/go.mod h1:ot55KksVO/lnRDVVNDF14AtdS7CSs//NE20WU6x/eiw=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81 h1:iant8lATTlHYUWVdL3llKZuGgZUHBL4q7JUkLmcBQXk=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403 h1:AZxj9IhfiLeH0ggsX6WU1SYaKscXuxPxdMXMX4pvhFs=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416 h1:t9FawNEHc0R1PTYdDhWd/Q643KAN9IpJZMdlu2FlBxM=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/viper2015 v1.3.2
github.com/stretchr/testify v1.4.0
github.com/trustbloc/fabric-peer-ext v0.0.0
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416
)

replace github.com/hyperledger/fabric => github.com/trustbloc/fabric-mod v0.1.2-0.20200211211900-62c249e072e2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ github.com/trustbloc/fabric-peer-ext/mod/peer v0.0.0-20200211231405-e21ab2bc259f
github.com/trustbloc/fabric-peer-ext/mod/peer v0.0.0-20200211231405-e21ab2bc259f/go.mod h1:ot55KksVO/lnRDVVNDF14AtdS7CSs//NE20WU6x/eiw=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81 h1:iant8lATTlHYUWVdL3llKZuGgZUHBL4q7JUkLmcBQXk=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403 h1:AZxj9IhfiLeH0ggsX6WU1SYaKscXuxPxdMXMX4pvhFs=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416 h1:t9FawNEHc0R1PTYdDhWd/Q643KAN9IpJZMdlu2FlBxM=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
const (
documentCC = "document_cc"
collection = "docs"
queryByIDTemplate = `{"selector":{"id":"%s"},"use_index":["_design/indexIDDoc","indexID"],"fields":["id","encodedPayload","hashAlgorithmInMultiHashCode","operationIndex","patch","signature","signingKeyID","transactionNumber","transactionTime","type","uniqueSuffix"]}`
queryByIDTemplate = `{"selector":{"id":"%s"},"use_index":["_design/indexIDDoc","indexID"],"fields":["id","encodedPayload","encodedProtectedHeader","document","updateOTP","recoveryOTP","nextUpdateOTPHash","nextRecoveryOTPHash","hashAlgorithmInMultiHashCode","operationIndex","patch","signature","signingKeyID","transactionNumber","transactionTime","type","uniqueSuffix"]}`
)

var logger = flogging.MustGetLogger("sidetree_context")
Expand Down
81 changes: 66 additions & 15 deletions pkg/httpserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,11 @@ const (
clientURL = "http://" + url

didDocNamespace = "did:sidetree"
didID = didDocNamespace + docutil.NamespaceDelimiter + "EiDOQXC2GnoVyHwIRbjhLx_cNc6vmZaS04SZjZdlLLAPRg=="
didDocPath = "/document"

sampleNamespace = "sample:sidetree"
samplePath = "/sample"
sampleID = sampleNamespace + docutil.NamespaceDelimiter + "EiDOQXC2GnoVyHwIRbjhLx_cNc6vmZaS04SZjZdlLLAPRg=="

createRequest = `{
"header": {
"operation": "create",
"kid": "#key1",
"alg": "ES256K"
},
"payload": "ewogICJAY29udGV4dCI6ICJodHRwczovL3czaWQub3JnL2RpZC92MSIsCiAgInB1YmxpY0tleSI6IFt7CiAgICAiaWQiOiAiI2tleTEiLAogICAgInR5cGUiOiAiU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOCIsCiAgICAicHVibGljS2V5SGV4IjogIjAyZjQ5ODAyZmIzZTA5YzZkZDQzZjE5YWE0MTI5M2QxZTBkYWQwNDRiNjhjZjgxY2Y3MDc5NDk5ZWRmZDBhYTlmMSIKICB9XSwKICAic2VydmljZSI6IFt7CiAgICAiaWQiOiAiSWRlbnRpdHlIdWIiLAogICAgInR5cGUiOiAiSWRlbnRpdHlIdWIiLAogICAgInNlcnZpY2VFbmRwb2ludCI6IHsKICAgICAgIkBjb250ZXh0IjogInNjaGVtYS5pZGVudGl0eS5mb3VuZGF0aW9uL2h1YiIsCiAgICAgICJAdHlwZSI6ICJVc2VyU2VydmljZUVuZHBvaW50IiwKICAgICAgImluc3RhbmNlIjogWyJkaWQ6YmFyOjQ1NiIsICJkaWQ6emF6Ojc4OSJdCiAgICB9CiAgfV0KfQo=",
"signature": "mAJp4ZHwY5UMA05OEKvoZreRo0XrYe77s3RLyGKArG85IoBULs4cLDBtdpOToCtSZhPvCC2xOUXMGyGXDmmEHg"
}
`
sha2_256 = 18
)

func TestServer_Start(t *testing.T) {
Expand All @@ -67,8 +55,16 @@ func TestServer_Start(t *testing.T) {
time.Sleep(time.Second)

t.Run("DID doc", func(t *testing.T) {
payload, err := getEncodedPayload([]byte(validDoc))
require.NoError(t,err)
createReq, err := getCreateRequest(payload)
require.NoError(t, err)

didID, err := docutil.CalculateID(didDocNamespace,payload, sha2_256)
require.NoError(t, err)

request := &model.Request{}
err := json.Unmarshal([]byte(createRequest), request)
err = json.Unmarshal(createReq, request)
require.NoError(t, err)

resp, err := httpPut(t, clientURL+didDocPath, request)
Expand All @@ -88,8 +84,16 @@ func TestServer_Start(t *testing.T) {
require.Equal(t, didID, resolvedDoc["id"])
})
t.Run("Sample doc", func(t *testing.T) {
payload, err := getEncodedPayload([]byte(validDoc))
require.NoError(t,err)
createReq, err := getCreateRequest(payload)
require.NoError(t, err)

sampleID, err := docutil.CalculateID(sampleNamespace, payload, sha2_256)
require.NoError(t, err)

request := &model.Request{}
err := json.Unmarshal([]byte(createRequest), request)
err = json.Unmarshal(createReq, request)
require.NoError(t, err)

resp, err := httpPut(t, clientURL+samplePath, request)
Expand Down Expand Up @@ -269,3 +273,50 @@ func (h *sampleResolveHandler) Method() string {
func (h *sampleResolveHandler) Handler() common.HTTPRequestHandler {
return h.Resolve
}

func getID(code uint, content []byte) (string, error) {
mh, err := docutil.ComputeMultihash(code, content)
if err != nil {
return "", err
}

return docutil.EncodeToString(mh), nil
}

func getCreateRequest(payload string) ([]byte, error) {

req := model.Request{
Protected: &model.Header{
Alg: "ES256K",
Kid: "#key1",
},
Payload: payload,
Signature: "",
}

return json.Marshal(req)
}

func getEncodedPayload(doc []byte) (string, error) {
payload, err := json.Marshal(
struct {
Operation model.OperationType `json:"type"`
DIDDocument string `json:"didDocument"`
}{model.OperationTypeCreate, docutil.EncodeToString(doc)})
if err != nil {
return "", err
}

return docutil.EncodeToString(payload), nil
}

const validDoc = `{
"@context": ["https://w3id.org/did/v1"],
"created": "2019-09-23T14:16:59.261024-04:00",
"publicKey": [{
"id": "#key-1",
"publicKeyBase58": "GY4GunSXBPBfhLCzDL7iGmP5dR3sBDCJZkkaGK8VgYQf",
"type": "Ed25519VerificationKey2018"
}],
"updated": "2019-09-23T14:16:59.261024-04:00"
}`
55 changes: 34 additions & 21 deletions test/bddtests/did_sidetree_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package bddtests

import (
"encoding/base64"
"encoding/json"
"io/ioutil"
"net/http"
"os"
Expand All @@ -31,7 +32,8 @@ const initialValuesParam = ";initial-values="

// DIDSideSteps
type DIDSideSteps struct {
reqEncodedDIDDoc string
encodedCreatePayload string
encodedDoc string
reqNamespace string
resp *restclient.HttpResponse
bddContext *bddtests.BDDContext
Expand All @@ -45,24 +47,29 @@ func NewDIDSideSteps(context *bddtests.BDDContext) *DIDSideSteps {
func (d *DIDSideSteps) sendDIDDocument(url, didDocumentPath, namespace string) error {
logger.Infof("Creating DID document at %s", url)

req := newCreateRequest(didDocumentPath, "")
d.reqEncodedDIDDoc = req.Payload
d.reqNamespace = namespace
encodedDidDoc := encodeDidDocument(didDocumentPath, "")
payload, err := getCreatePayload(encodedDidDoc)
if err != nil {
return err
}

logger.Infof("Sending request payload: %s", req.Payload)
req := request("ES256K", "#key1", payload, "")

d.encodedCreatePayload = payload
d.encodedDoc = encodedDidDoc
d.reqNamespace = namespace

var err error
d.resp, err = restclient.SendRequest(url, req)
return err
}

func (d *DIDSideSteps) resolveDIDDocumentWithInitialValue(url string) error {
did, err := docutil.CalculateID(d.reqNamespace, d.reqEncodedDIDDoc, sha2256)
did, err := docutil.CalculateID(d.reqNamespace, d.encodedCreatePayload, sha2256)
if err != nil {
return err
}

req := url + "/" + did + initialValuesParam + d.reqEncodedDIDDoc
req := url + "/" + did + initialValuesParam + d.encodedDoc
logger.Infof("Sending request: %s", req)
d.resp, err = restclient.SendResolveRequest(req)
logger.Infof("... got response: %s", d.resp.Payload)
Expand All @@ -77,7 +84,7 @@ func (d *DIDSideSteps) checkErrorResp(errorMsg string) error {
}

func (d *DIDSideSteps) checkSuccessResp(msg string) error {
documentHash, err := docutil.CalculateID(d.reqNamespace, d.reqEncodedDIDDoc, sha2256)
documentHash, err := docutil.CalculateID(d.reqNamespace, d.encodedCreatePayload, sha2256)
if err != nil {
return err
}
Expand All @@ -97,7 +104,7 @@ func (d *DIDSideSteps) checkSuccessResp(msg string) error {
}

func (d *DIDSideSteps) resolveDIDDocument(url string) error {
documentHash, err := docutil.CalculateID(d.reqNamespace, d.reqEncodedDIDDoc, sha2256)
documentHash, err := docutil.CalculateID(d.reqNamespace, d.encodedCreatePayload, sha2256)
if err != nil {
return err
}
Expand All @@ -122,28 +129,34 @@ func (d *DIDSideSteps) resolveDIDDocument(url string) error {
}
}

func newCreateRequest(didDocumentPath, didID string) *model.Request {
operation := model.OperationTypeCreate
alg := "ES256K"
kid := "#key1"
payload := encodeDidDocument(didDocumentPath, didID)
signature := "mAJp4ZHwY5UMA05OEKvoZreRo0XrYe77s3RLyGKArG85IoBULs4cLDBtdpOToCtSZhPvCC2xOUXMGyGXDmmEHg"
return request(alg, kid, payload, signature, operation)
}

func request(alg, kid, payload, signature string, operation model.OperationType) *model.Request {
func request(alg, kid, payload, signature string) *model.Request {
header := &model.Header{
Alg: alg,
Kid: kid,
Operation: operation,
}
req := &model.Request{
Header: header,
Protected: header,
Payload: payload,
Signature: signature}
return req
}

func getCreatePayload(encodedDoc string) (string, error) {
payload, err := json.Marshal(
struct {
Operation model.OperationType `json:"type"`
DIDDocument string `json:"didDocument"`
}{model.OperationTypeCreate, encodedDoc})

if err != nil {
return "", err
}

return docutil.EncodeToString(payload), nil
}


func encodeDidDocument(didDocumentPath, didID string) string {
r, _ := os.Open(didDocumentPath)
data, _ := ioutil.ReadAll(r)
Expand Down
2 changes: 1 addition & 1 deletion test/bddtests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/sirupsen/logrus v1.3.0
github.com/spf13/viper v1.3.2
github.com/trustbloc/fabric-peer-test-common v0.1.2-0.20200213155832-06af5163b73f
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416
)

replace github.com/hyperledger/fabric-protos-go => github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81
Expand Down
4 changes: 2 additions & 2 deletions test/bddtests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/trustbloc/fabric-peer-test-common v0.1.2-0.20200213155832-06af5163b73
github.com/trustbloc/fabric-peer-test-common v0.1.2-0.20200213155832-06af5163b73f/go.mod h1:ckJnW99sXm7Y9F3993rIeffz20vlIhwvF4+YyEgmxfk=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81 h1:iant8lATTlHYUWVdL3llKZuGgZUHBL4q7JUkLmcBQXk=
github.com/trustbloc/fabric-protos-go-ext v0.1.2-0.20200205170340-c69bba6d7b81/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403 h1:AZxj9IhfiLeH0ggsX6WU1SYaKscXuxPxdMXMX4pvhFs=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200207213740-40ada19e1403/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416 h1:t9FawNEHc0R1PTYdDhWd/Q643KAN9IpJZMdlu2FlBxM=
github.com/trustbloc/sidetree-core-go v0.1.2-0.20200214144924-3e7aa7825416/go.mod h1:qJ7oOPveEqrxTsO4KJsSHUM/Yivym221Dvd+IUq1V1U=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCOJgSM=
github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
Expand Down

0 comments on commit dcad027

Please sign in to comment.