Skip to content

Commit

Permalink
Merge pull request #16 from iden3/feature/PID-2319-use-resolver-as-or…
Browse files Browse the repository at this point in the history
…acle-data-solution

Using resolver as data oracle solution
  • Loading branch information
vmidyllic authored Sep 11, 2024
2 parents 8613d0f + d7e4af1 commit 7ec71fc
Show file tree
Hide file tree
Showing 23 changed files with 601 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
run_e2e:
env:
STATE_CONTRACT_ADDRESS_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
STATE_CONTRACT_ADDRESS_POLYGON_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"

runs-on: ubuntu-20.04
steps:
Expand All @@ -21,7 +21,7 @@ jobs:
run: |
echo -e "polygon:" > resolvers.settings.yaml
echo -e " amoy:" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_AMOY }}" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_POLYGON_AMOY }}" >> resolvers.settings.yaml
echo -e " networkURL: ${{ secrets.POLYGON_AMOY_NODE_URL }}" >> resolvers.settings.yaml
- name: Docker build driver container
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publis-container-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ env:
jobs:
build_driver:
env:
STATE_CONTRACT_ADDRESS_MAIN: "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
STATE_CONTRACT_ADDRESS_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
STATE_CONTRACT_ADDRESS_PRIVADO_MAIN: "0x0DDd8701C91d8d1Ba35c9DbA98A45fe5bA8A877E"
STATE_CONTRACT_ADDRESS_PRIVADO_TEST: "0xE5BfD683F1Ca574B5be881b7DbbcFDCE9DDBAb90"
STATE_CONTRACT_ADDRESS_POLYGON_MAIN: "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
STATE_CONTRACT_ADDRESS_POLYGON_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
STATE_CONTRACT_ADDRESS_PRIVADO_MAIN: "0x975556428F077dB5877Ea2474D783D6C69233742"
STATE_CONTRACT_ADDRESS_PRIVADO_TEST: "0x975556428F077dB5877Ea2474D783D6C69233742"
runs-on: ubuntu-latest
permissions:
id-token: write
Expand Down Expand Up @@ -47,11 +47,11 @@ jobs:
cd driver-did-iden3
echo -e "polygon:" > resolvers.settings.yaml
echo -e " amoy:" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_AMOY }}" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_POLYGON_AMOY }}" >> resolvers.settings.yaml
echo -e " networkURL: ${{ secrets.POLYGON_AMOY_NODE_URL }}" >> resolvers.settings.yaml
echo -e " walletKey: ${{ secrets.SIGNER_PRIVATE_KEY }}" >> resolvers.settings.yaml
echo -e " main:" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_MAIN }}" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_POLYGON_MAIN }}" >> resolvers.settings.yaml
echo -e " networkURL: ${{ secrets.POLYGON_MAIN_NODE_URL }}" >> resolvers.settings.yaml
echo -e " walletKey: ${{ secrets.SIGNER_PRIVATE_KEY }}" >> resolvers.settings.yaml
echo -e "privado:" >> resolvers.settings.yaml
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/push-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:
jobs:
build_driver:
env:
STATE_CONTRACT_ADDRESS_MAIN: "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
STATE_CONTRACT_ADDRESS_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
STATE_CONTRACT_ADDRESS_POLYGON_MAIN: "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
STATE_CONTRACT_ADDRESS_POLYGON_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124"
STATE_CONTRACT_ADDRESS_PRIVADO: "0x975556428F077dB5877Ea2474D783D6C69233742"
runs-on: ubuntu-latest
steps:
Expand All @@ -33,10 +33,10 @@ jobs:
cd driver-did-iden3
echo -e "polygon:" > resolvers.settings.yaml
echo -e " amoy:" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_AMOY }}" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_POLYGON_AMOY }}" >> resolvers.settings.yaml
echo -e " networkURL: ${{ secrets.POLYGON_AMOY_NODE_URL }}" >> resolvers.settings.yaml
echo -e " main:" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_MAIN }}" >> resolvers.settings.yaml
echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_POLYGON_MAIN }}" >> resolvers.settings.yaml
echo -e " networkURL: ${{ secrets.POLYGON_MAIN_NODE_URL }}" >> resolvers.settings.yaml
echo -e "privado:" >> resolvers.settings.yaml
echo -e " main:" >> resolvers.settings.yaml
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
configs/driver.yaml
.env*
resolvers.settings.yaml
test.http
10 changes: 3 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,16 @@ linters-settings:
linters:
enable:
- bodyclose
- megacheck
- revive
- govet
- unconvert
- megacheck
- structcheck
- gas
- gosec
- gocyclo
- dupl
- misspell
- unparam
- varcheck
- deadcode
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- exportloopref
Expand All @@ -66,6 +60,8 @@ linters:
- errcheck
- gofmt
- goimports
- staticcheck
- unused
fast: false
disable-all: true

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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Driver for the iden3 DID method
```bash
docker run -p 8080:8080 driver-did-iden3:local
```

`WALLET_KEY` 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`.
In this case you have to run:
```bash
docker run -p 8080:8080 -e WALLET_KEY=<your_wallet_key> driver-did-iden3:local
```
41 changes: 38 additions & 3 deletions cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/iden3/driver-did-iden3/pkg/app"
"github.com/iden3/driver-did-iden3/pkg/app/configs"
"github.com/iden3/driver-did-iden3/pkg/document"
"github.com/iden3/driver-did-iden3/pkg/services"
"github.com/iden3/driver-did-iden3/pkg/services/blockchain/eth"
"github.com/iden3/driver-did-iden3/pkg/services/ens"
"github.com/iden3/driver-did-iden3/pkg/services/provers"
)

func main() {
Expand All @@ -32,15 +34,21 @@ func main() {
log.Fatal("can't create registry:", err)
}
}
var proverRegistry *services.DIDResolutionProverRegistry
if cfg.WalletKey != "" {
proverRegistry, err = initDIDResolutionProverRegistry(*cfg)
if err != nil {
log.Fatal("can't create registry:", err)
}
}

mux := app.Handlers{DidDocumentHandler: &app.DidDocumentHandler{
DidDocumentService: services.NewDidDocumentServices(initResolvers(), r),
},
DidDocumentService: services.NewDidDocumentServices(initResolvers(), r, services.WithProvers(proverRegistry))},
}

server := http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port),
Handler: mux.Routes(),
Handler: addCORSHeaders(mux.Routes()),
ReadHeaderTimeout: time.Second,
}
log.Printf("HTTP server start on '%s:%d'\n", cfg.Server.Host, cfg.Server.Port)
Expand Down Expand Up @@ -73,3 +81,30 @@ func initResolvers() *services.ResolverRegistry {

return resolvers
}

func initDIDResolutionProverRegistry(cfg configs.Config) (*services.DIDResolutionProverRegistry, error) {

proverRegistry := services.NewDIDResolutionProverRegistry()

prover, err := provers.NewEIP712Prover(cfg.WalletKey)
if err != nil {
return nil, err
}
proverRegistry.Add(document.EthereumEip712SignatureProof2021Type, prover)

return proverRegistry, nil
}

func addCORSHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")

if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}

next.ServeHTTP(w, r)
})
}
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=
3 changes: 2 additions & 1 deletion pkg/app/configs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type ResolverSettings map[string]map[string]struct {

// Config structure represent yaml config for did driver.
type Config struct {
Server struct {
WalletKey string `envconfig:"WALLET_KEY" default:""`
Server struct {
Port int `envconfig:"PORT" default:"8080"`
Host string `envconfig:"HOST" default:"localhost"`
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"

"github.com/iden3/driver-did-iden3/pkg/document"
"github.com/iden3/driver-did-iden3/pkg/services"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-merkletree-sql/v2"
Expand All @@ -23,6 +24,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 +98,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 +112,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 +130,11 @@ func getResolverOpts(state, gistRoot string) (ro services.ResolverOpts, err erro
}
ro.GistRoot = g.BigInt()
}
if signature != "" && signature != string(document.EthereumEip712SignatureProof2021Type) {
return ro, fmt.Errorf("not supported signature type %s", signature)
}
if signature != "" {
ro.Signature = signature
}
return
}
20 changes: 16 additions & 4 deletions pkg/document/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
ErrUnknownNetwork ErrorCode = "unknownNetwork"

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

Expand All @@ -24,6 +25,8 @@ const (
iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld"
EcdsaSecp256k1RecoveryContext = "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-2.0.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 @@ -45,13 +48,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 @@ -81,10 +90,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 []string `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
Loading

0 comments on commit 7ec71fc

Please sign in to comment.