From 0c8728c64c260ef1f00eb7c4f668f3621b065828 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 9 Apr 2024 23:39:15 +0300 Subject: [PATCH] support iden3 core v2 (#5) --- go.mod | 6 +- go.sum | 21 ++----- pkg/app/handler.go | 4 +- pkg/services/blockchain/eth/resolver.go | 17 ++++-- pkg/services/blockchain/eth/resolver_test.go | 20 ++++--- pkg/services/did.go | 60 +++++++++++--------- pkg/services/registry.go | 6 +- 7 files changed, 72 insertions(+), 62 deletions(-) diff --git a/go.mod b/go.mod index fd134f7..8170822 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ require ( github.com/ethereum/go-ethereum v1.11.5 github.com/golang/mock v1.6.0 github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 - github.com/iden3/go-iden3-core v1.0.0 + github.com/iden3/go-iden3-core/v2 v2.1.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.2 github.com/wealdtech/go-ens/v3 v3.5.5 golang.org/x/crypto v0.7.0 golang.org/x/net v0.8.0 @@ -33,7 +33,7 @@ require ( github.com/go-stack/stack v1.8.1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/iden3/go-iden3-crypto v0.0.13 // indirect + github.com/iden3/go-iden3-crypto v0.0.15 // indirect github.com/iden3/go-merkletree-sql/v2 v2.0.0 github.com/ipfs/go-cid v0.3.2 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect diff --git a/go.sum b/go.sum index 3112524..4294748 100644 --- a/go.sum +++ b/go.sum @@ -29,7 +29,6 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI= github.com/deckarep/golang-set/v2 v2.2.0 h1:2pMQd3Soi6qfw7E5MMKaEh5W5ES18bW3AbFFnGl6LgQ= github.com/deckarep/golang-set/v2 v2.2.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= @@ -70,10 +69,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 h1:iPvYa/AhhGo3juoUFDm/fBE2CZKy4WfQu7JY90tRf9Q= github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w= -github.com/iden3/go-iden3-core v1.0.0 h1:GNwuYOHZD7hiWjmW+wv26RW9f/JwF4lRQu7/55f2YB8= -github.com/iden3/go-iden3-core v1.0.0/go.mod h1:wJtcMK/bSazyW/JrQaRrbpUMgSMg79Pke3xgtfPxDnQ= -github.com/iden3/go-iden3-crypto v0.0.13 h1:ixWRiaqDULNyIDdOWz2QQJG5t4PpNHkQk2P6GV94cok= -github.com/iden3/go-iden3-crypto v0.0.13/go.mod h1:swXIv0HFbJKobbQBtsB50G7IHr6PbTowutSew/iBEoo= +github.com/iden3/go-iden3-core/v2 v2.1.0 h1:R1s7Tj3tIx5lDy8S7OJrSNuxXIFeRzWRmTBaQoQHJps= +github.com/iden3/go-iden3-core/v2 v2.1.0/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw= +github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= +github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/iden3/go-merkletree-sql/v2 v2.0.0 h1:7tMgHCUJCo0jxyM15fjCc7G9Dy0x2rmX+lwa8tqEfho= github.com/iden3/go-merkletree-sql/v2 v2.0.0/go.mod h1:hQbfImlyOJiI+c8FFuFiEMrjpZN0PylRb0aT8uAa+Sg= github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc= @@ -94,7 +93,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= -github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= @@ -144,11 +142,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= @@ -170,7 +167,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk 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-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= @@ -180,7 +176,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -193,10 +188,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -205,7 +197,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y= diff --git a/pkg/app/handler.go b/pkg/app/handler.go index 997fcfa..03c886b 100644 --- a/pkg/app/handler.go +++ b/pkg/app/handler.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/iden3/driver-did-polygonid/pkg/services" - core "github.com/iden3/go-iden3-core" + core "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-merkletree-sql/v2" "github.com/pkg/errors" ) @@ -31,7 +31,7 @@ func (d *DidDocumentHandler) Get(w http.ResponseWriter, r *http.Request) { } state, err := d.DidDocumentService.GetDidDocument(r.Context(), rawURL[len(rawURL)-1], &opts) - if errors.Is(err, core.ErrInvalidDID) { + if errors.Is(err, core.ErrIncorrectDID) { log.Println("invalid did:", err) } else if err != nil { diff --git a/pkg/services/blockchain/eth/resolver.go b/pkg/services/blockchain/eth/resolver.go index fcc7eec..a42bcf2 100644 --- a/pkg/services/blockchain/eth/resolver.go +++ b/pkg/services/blockchain/eth/resolver.go @@ -11,7 +11,8 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/iden3/contracts-abi/state/go/abi" "github.com/iden3/driver-did-polygonid/pkg/services" - core "github.com/iden3/go-iden3-core" + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" ) //go:generate mockgen -destination=contract/mock/contract.go . StateContract @@ -95,7 +96,7 @@ func (r *Resolver) ResolveGist( func (r *Resolver) Resolve( ctx context.Context, - did core.DID, + did w3c.DID, opts *services.ResolverOpts, ) (services.IdentityState, error) { if opts.GistRoot != nil && opts.State != nil { @@ -109,13 +110,19 @@ func (r *Resolver) Resolve( err error ) + userID, err := core.IDFromDID(did) + if err != nil { + return services.IdentityState{}, + fmt.Errorf("invalid did format for did '%s': %v", did, err) + } + switch { case opts.GistRoot != nil: - stateInfo, gistInfo, err = r.resolveStateByGistRoot(ctx, did.ID, opts.GistRoot) + stateInfo, gistInfo, err = r.resolveStateByGistRoot(ctx, userID, opts.GistRoot) case opts.State != nil: - stateInfo, err = r.resolveState(ctx, did.ID, opts.State) + stateInfo, err = r.resolveState(ctx, userID, opts.State) default: - stateInfo, gistInfo, err = r.resolveLatest(ctx, did.ID) + stateInfo, gistInfo, err = r.resolveLatest(ctx, userID) } identityState := services.IdentityState{} diff --git a/pkg/services/blockchain/eth/resolver_test.go b/pkg/services/blockchain/eth/resolver_test.go index 19fc3a4..a0875a0 100644 --- a/pkg/services/blockchain/eth/resolver_test.go +++ b/pkg/services/blockchain/eth/resolver_test.go @@ -10,12 +10,13 @@ import ( "github.com/iden3/contracts-abi/state/go/abi" "github.com/iden3/driver-did-polygonid/pkg/services" cm "github.com/iden3/driver-did-polygonid/pkg/services/blockchain/eth/contract/mock" - core "github.com/iden3/go-iden3-core" + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" "github.com/pkg/errors" "github.com/stretchr/testify/require" ) -var userDID, _ = core.ParseDID("did:polygonid:polygon:mumbai:2qJEaVmT5jBrtgBQ4m7b7bRYzWmvMyDjBZGP24QwvD") +var userDID, _ = w3c.ParseDID("did:polygonid:polygon:mumbai:2qJEaVmT5jBrtgBQ4m7b7bRYzWmvMyDjBZGP24QwvD") func TestResolveGist_Success(t *testing.T) { tests := []struct { @@ -72,7 +73,7 @@ func TestResolve_Success(t *testing.T) { tests := []struct { name string opts *services.ResolverOpts - userDID *core.DID + userDID *w3c.DID contractMock func(c *cm.MockStateContract) expectedIdentityState services.IdentityState }{ @@ -88,10 +89,11 @@ func TestResolve_Success(t *testing.T) { Existence: true, Value: big.NewInt(5), } - c.EXPECT().GetGISTProofByRoot(gomock.Any(), userDID.ID.BigInt(), big.NewInt(1)).Return(proof, nil) + userID, _ := core.IDFromDID(*userDID) + c.EXPECT().GetGISTProofByRoot(gomock.Any(), userID.BigInt(), big.NewInt(1)).Return(proof, nil) gistInfo := abi.IStateGistRootInfo{Root: big.NewInt(555)} c.EXPECT().GetGISTRootInfo(gomock.Any(), big.NewInt(4)).Return(gistInfo, nil) - stateInfo := abi.IStateStateInfo{Id: userDID.ID.BigInt(), State: big.NewInt(444)} + stateInfo := abi.IStateStateInfo{Id: userID.BigInt(), State: big.NewInt(444)} c.EXPECT().GetStateInfoByIdAndState(gomock.Any(), gomock.Any(), big.NewInt(5)).Return(stateInfo, nil) }, expectedIdentityState: services.IdentityState{ @@ -111,7 +113,8 @@ func TestResolve_Success(t *testing.T) { }, userDID: userDID, contractMock: func(c *cm.MockStateContract) { - res := abi.IStateStateInfo{Id: userDID.ID.BigInt(), State: big.NewInt(555)} + userID, _ := core.IDFromDID(*userDID) + res := abi.IStateStateInfo{Id: userID.BigInt(), State: big.NewInt(555)} c.EXPECT().GetStateInfoByIdAndState(gomock.Any(), gomock.Any(), big.NewInt(1)).Return(res, nil) }, expectedIdentityState: services.IdentityState{ @@ -127,12 +130,13 @@ func TestResolve_Success(t *testing.T) { opts: &services.ResolverOpts{}, userDID: userDID, contractMock: func(c *cm.MockStateContract) { + userID, _ := core.IDFromDID(*userDID) latestGist := big.NewInt(100) c.EXPECT().GetGISTRoot(gomock.Any()).Return(latestGist, nil) latestGistInfo := abi.IStateGistRootInfo{Root: big.NewInt(400)} c.EXPECT().GetGISTRootInfo(gomock.Any(), latestGist).Return(latestGistInfo, nil) - stateInfo := abi.IStateStateInfo{Id: userDID.ID.BigInt(), State: big.NewInt(555)} - c.EXPECT().GetStateInfoById(gomock.Any(), userDID.ID.BigInt()).Return(stateInfo, nil) + stateInfo := abi.IStateStateInfo{Id: userID.BigInt(), State: big.NewInt(555)} + c.EXPECT().GetStateInfoById(gomock.Any(), userID.BigInt()).Return(stateInfo, nil) }, expectedIdentityState: services.IdentityState{ StateInfo: &services.StateInfo{ diff --git a/pkg/services/did.go b/pkg/services/did.go index ba1b44c..e316527 100644 --- a/pkg/services/did.go +++ b/pkg/services/did.go @@ -8,7 +8,8 @@ import ( "github.com/iden3/driver-did-polygonid/pkg/document" "github.com/iden3/driver-did-polygonid/pkg/services/ens" - core "github.com/iden3/go-iden3-core" + core "github.com/iden3/go-iden3-core/v2" + "github.com/iden3/go-iden3-core/v2/w3c" "github.com/pkg/errors" ) @@ -36,13 +37,31 @@ func (d *DidDocumentServices) GetDidDocument(ctx context.Context, did string, op opts = &ResolverOpts{} } - userDID, err := core.ParseDID(did) + userDID, err := w3c.ParseDID(did) errResolution, err := expectedError(err) if err != nil { return errResolution, err } - resolver, err := d.resolvers.GetResolverByNetwork(string(userDID.Blockchain), string(userDID.NetworkID)) + userID, err := core.IDFromDID(*userDID) + errResolution, err = expectedError(err) + if err != nil { + return errResolution, err + } + + b, err := core.BlockchainFromID(userID) + errResolution, err = expectedError(err) + if err != nil { + return errResolution, err + } + + n, err := core.NetworkIDFromID(userID) + errResolution, err = expectedError(err) + if err != nil { + return errResolution, err + } + + resolver, err := d.resolvers.GetResolverByNetwork(string(b), string(n)) errResolution, err = expectedError(err) if err != nil { return errResolution, err @@ -50,7 +69,7 @@ func (d *DidDocumentServices) GetDidDocument(ctx context.Context, did string, op identityState, err := resolver.Resolve(ctx, *userDID, opts) if errors.Is(err, ErrNotFound) && (opts.State != nil || opts.GistRoot != nil) { - gen, errr := isGenesis(userDID.ID.BigInt(), opts.State) + gen, errr := isGenesis(userID.BigInt(), opts.State) if errr != nil { return nil, fmt.Errorf("invalid state: %v", errr) } @@ -102,12 +121,12 @@ func (d *DidDocumentServices) ResolveDNSDomain(ctx context.Context, domain strin } var ( - did *core.DID + did *w3c.DID v string ) // try to find correct did. for _, v = range records { - did, err = core.ParseDID(v) + did, err = w3c.ParseDID(v) if did != nil && err == nil { break } @@ -167,25 +186,12 @@ func isGenesis(id, state *big.Int) (bool, error) { return false, nil } - userID, err := core.IDFromInt(id) - if err != nil { - return false, err - } - userDID, err := core.ParseDIDFromID(userID) - if err != nil { - return false, err - } - - didType, err := core.BuildDIDType(userDID.Method, userDID.Blockchain, userDID.NetworkID) - if err != nil { - return false, err - } - identifier, err := core.IdGenesisFromIdenState(didType, state) + isGenesis, err := core.CheckGenesisStateID(id, state) if err != nil { return false, err } - return id.Cmp(identifier.BigInt()) == 0, nil + return isGenesis, nil } func expectedError(err error) (*document.DidResolution, error) { @@ -193,13 +199,15 @@ func expectedError(err error) (*document.DidResolution, error) { return nil, nil } - if errors.Is(err, core.ErrInvalidDID) { + switch { + case errors.Is(err, core.ErrIncorrectDID): return document.NewDidInvalidResolution(err.Error()), err - } - if errors.Is(err, core.ErrNetworkNotSupportedForDID) { + case + errors.Is(err, core.ErrBlockchainNotSupportedForDID), + errors.Is(err, core.ErrNetworkNotSupportedForDID): + return document.NewNetworkNotSupportedForDID(err.Error()), err - } - if errors.Is(err, core.ErrDIDMethodNotSupported) { + case errors.Is(err, core.ErrDIDMethodNotSupported): return document.NewDidMethodNotSupportedResolution(err.Error()), err } diff --git a/pkg/services/registry.go b/pkg/services/registry.go index f3a1aa1..225a1d1 100644 --- a/pkg/services/registry.go +++ b/pkg/services/registry.go @@ -6,7 +6,7 @@ import ( "math/big" "github.com/iden3/driver-did-polygonid/pkg/document" - core "github.com/iden3/go-iden3-core" + "github.com/iden3/go-iden3-core/v2/w3c" "github.com/iden3/go-merkletree-sql/v2" "github.com/pkg/errors" ) @@ -24,7 +24,7 @@ type IdentityState struct { } type StateInfo struct { - ID core.DID + ID w3c.DID State *big.Int ReplacedByState *big.Int CreatedAtTimestamp *big.Int @@ -92,7 +92,7 @@ func (gi *GistInfo) ToDidRepresentation() (*document.GistInfo, error) { } type Resolver interface { - Resolve(ctx context.Context, did core.DID, opts *ResolverOpts) (IdentityState, error) + Resolve(ctx context.Context, did w3c.DID, opts *ResolverOpts) (IdentityState, error) ResolveGist(ctx context.Context, opts *ResolverOpts) (*GistInfo, error) BlockchainID() string }