Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using resolver as data oracle solution #10

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,15 @@ linters-settings:
linters:
enable:
- bodyclose
- megacheck
- revive
- govet
- unconvert
- megacheck
- structcheck
- gas
- gocyclo
- dupl
- misspell
- unparam
- varcheck
- deadcode
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- exportloopref
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
## Build did driver
##
FROM golang:1.18-alpine as base
FROM golang:1.18-alpine AS base

WORKDIR /build

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Driver for the polygonid DID method.
amoy:
contractAddress: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
networkURL: "https://polygon-amoy..."
walletKey: "<private ethereum key for signing EIP712>"
```
`walletKey` is only needed for the resolver if it's a trusted resolver that includes signature of EIP712 message when requested in the resolution with `signature=EthereumEip712Signature2021`.
2. Build docker container:
```bash
docker build -t driver-did-polygonid:local .
Expand All @@ -26,6 +28,7 @@ Driver for the polygonid DID method.
amoy:
contractAddress: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
networkURL: "<POLYGON_AMOY_RPC_URL>"
walletKey: "<private ethereum key for signing EIP712>"
```
2. Build docker container:
```bash
Expand Down
2 changes: 1 addition & 1 deletion cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func initResolvers() *services.ResolverRegistry {
for chainName, chainSettings := range rs {
for networkName, networkSettings := range chainSettings {
prefix := fmt.Sprintf("%s:%s", chainName, networkName)
resolver, err := eth.NewResolver(networkSettings.NetworkURL, networkSettings.ContractAddress)
resolver, err := eth.NewResolver(networkSettings.NetworkURL, networkSettings.ContractAddress, networkSettings.WalletKey)
if err != nil {
log.Fatalf("failed configure resolver for network '%s': %v", prefix, err)
}
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ require (
)

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/dchest/blake512 v1.0.0 // indirect
github.com/deckarep/golang-set/v2 v2.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand Down Expand Up @@ -55,6 +57,8 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/wealdtech/go-multicodec v1.4.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/sys v0.15.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -20,6 +24,7 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f
github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU=
github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoGMWEhDvS3zToKcDpRsLuRolQJBVGdozk=
Expand Down Expand Up @@ -147,6 +152,7 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
Expand All @@ -155,7 +161,10 @@ github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+Kd
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q=
github.com/wealdtech/go-ens/v3 v3.5.5 h1:/jq3CDItK0AsFnZtiFJK44JthkAMD5YE3WAJOh4i7lc=
github.com/wealdtech/go-ens/v3 v3.5.5/go.mod h1:w0EDKIm0dIQnqEKls6ORat/or+AVfPEdEXVfN71EeEE=
Expand All @@ -166,11 +175,13 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg=
Expand Down Expand Up @@ -220,5 +231,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
1 change: 1 addition & 0 deletions pkg/app/configs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const defaultPathToResolverSettings = "./resolvers.settings.yaml"
type ResolverSettings map[string]map[string]struct {
ContractAddress string `yaml:"contractAddress"`
NetworkURL string `yaml:"networkURL"`
WalletKey string `yaml:"walletKey"`
}

// Config structure represent yaml config for did driver.
Expand Down
11 changes: 9 additions & 2 deletions pkg/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (d *DidDocumentHandler) Get(w http.ResponseWriter, r *http.Request) {
opts, err := getResolverOpts(
r.URL.Query().Get("state"),
r.URL.Query().Get("gist"),
r.URL.Query().Get("signature"),
)
if err != nil {
log.Println("invalid options query:", err)
Expand Down Expand Up @@ -96,7 +97,7 @@ func (d *DidDocumentHandler) GetGist(w http.ResponseWriter, r *http.Request) {
gistInfo, err := d.DidDocumentService.GetGist(r.Context(), chain, networkid, nil)
if errors.Is(err, services.ErrNetworkIsNotSupported) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, `{"error":"resolver for '%s:%s' network not found"}`, chain, networkid)
log.Printf(`{"error":"resolver for '%s:%s' network not found"}`, chain, networkid)
return
} else if err != nil {
log.Printf("failed get info about latest gist from network '%s:%s': %v\n", chain, networkid, err)
Expand All @@ -110,7 +111,7 @@ func (d *DidDocumentHandler) GetGist(w http.ResponseWriter, r *http.Request) {
}
}

func getResolverOpts(state, gistRoot string) (ro services.ResolverOpts, err error) {
func getResolverOpts(state, gistRoot, signature string) (ro services.ResolverOpts, err error) {
if state != "" && gistRoot != "" {
return ro, errors.New("'state' and 'gist root' cannot be used together")
}
Expand All @@ -128,5 +129,11 @@ func getResolverOpts(state, gistRoot string) (ro services.ResolverOpts, err erro
}
ro.GistRoot = g.BigInt()
}
if signature != "" {
if signature != "EthereumEip712Signature2021" {
return ro, fmt.Errorf("not supported signature type %s", signature)
}
ro.Signature = signature
}
return
}
28 changes: 20 additions & 8 deletions pkg/document/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ const (
ErrUnknownNetwork ErrorCode = "unknownNetwork"

StateType = "Iden3StateInfo2023"
Iden3ResolutionMetadataType = "Iden3ResolutionMetadata"
EcdsaSecp256k1RecoveryMethod2020Type = "EcdsaSecp256k1RecoveryMethod2020"
)

const (
defaultContext = "https://w3id.org/did-resolution/v1"
defaultDidDocContext = "https://www.w3.org/ns/did/v1"
iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld"
defaultContentType = "application/did+ld+json"
defaultContext = "https://w3id.org/did-resolution/v1"
defaultDidDocContext = "https://www.w3.org/ns/did/v1"
iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld"
defaultContentType = "application/did+ld+json"
iden3ResolutionContext = "https://schema.iden3.io/core/jsonld/resolution.jsonld"
eip712sigContext = "https://w3id.org/security/suites/eip712sig-2021/v1"
)

// DidResolution representation of did resolution.
Expand All @@ -44,13 +47,19 @@ func NewDidResolution() *DidResolution {
VerificationMethod: []verifiable.CommonVerificationMethod{},
},
DidResolutionMetadata: &DidResolutionMetadata{
Context: []string{iden3ResolutionContext},
Type: Iden3ResolutionMetadataType,
ContentType: defaultContentType,
Retrieved: time.Now(),
},
DidDocumentMetadata: &DidDocumentMetadata{},
}
}

func DidResolutionMetadataSigContext() []string {
return []string{iden3ResolutionContext, eip712sigContext}
}

func NewDidMethodNotSupportedResolution(msg string) *DidResolution {
return NewDidErrorResolution(ErrMethodNotSupported, msg)
}
Expand Down Expand Up @@ -80,10 +89,13 @@ func NewDidErrorResolution(errCode ErrorCode, errMsg string) *DidResolution {

// DidResolutionMetadata representation of resolution metadata.
type DidResolutionMetadata struct {
Error ErrorCode `json:"error,omitempty"`
Message string `json:"message,omitempty"`
ContentType string `json:"contentType,omitempty"`
Retrieved time.Time `json:"retrieved,omitempty"`
Context interface{} `json:"@context,omitempty"`
Error ErrorCode `json:"error,omitempty"`
Message string `json:"message,omitempty"`
ContentType string `json:"contentType,omitempty"`
Retrieved time.Time `json:"retrieved,omitempty"`
Type string `json:"type,omitempty"`
Proof DidResolutionProofs `json:"proof,omitempty"`
}

// DidDocumentMetadata metadata of did document.
Expand Down
62 changes: 62 additions & 0 deletions pkg/document/proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package document

import (
"encoding/json"
"errors"
"time"

"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/iden3/go-schema-processor/v2/verifiable"
)

type DidResolutionProof interface {
ProofType() verifiable.ProofType
}

type DidResolutionProofs []DidResolutionProof

type EthereumEip712SignatureProof2021 struct {
Type verifiable.ProofType `json:"type"`
ProofPursopose string `json:"proofPurpose"`
ProofValue string `json:"proofValue"`
VerificationMethod string `json:"verificationMethod"`
Created time.Time `json:"created"`
Eip712 apitypes.TypedData `json:"eip712"`
}

// EthereumEip712Signature2021Type is a proof type for EIP172 signature proofs
// nolint:stylecheck // we need to keep the name as it is
const EthereumEip712SignatureProof2021Type verifiable.ProofType = "EthereumEip712Signature2021"

func (p *EthereumEip712SignatureProof2021) ProofType() verifiable.ProofType {
return p.Type
}

func (p *EthereumEip712SignatureProof2021) UnmarshalJSON(in []byte) error {
var obj struct {
Type verifiable.ProofType `json:"type"`
ProofPursopose string `json:"proofPurpose"`
ProofValue string `json:"proofValue"`
VerificationMethod string `json:"verificationMethod"`
Created time.Time `json:"created"`
Eip712 json.RawMessage `json:"eip712"`
}
err := json.Unmarshal(in, &obj)
if err != nil {
return err
}
if obj.Type != EthereumEip712SignatureProof2021Type {
return errors.New("invalid proof type")
}
p.Type = obj.Type
err = json.Unmarshal(obj.Eip712, &p.Eip712)
if err != nil {
return err
}
p.VerificationMethod = obj.VerificationMethod
p.ProofPursopose = obj.ProofPursopose
// TODO: validate proof value
p.ProofValue = obj.ProofValue
p.Created = obj.Created
return nil
}
Loading
Loading