Skip to content

Commit

Permalink
chore: remove sparseMerkleTreeProof
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsaporiti committed May 29, 2024
1 parent fdbebde commit 3a5e44e
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 103 deletions.
3 changes: 1 addition & 2 deletions cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
vault "github.com/hashicorp/vault/api"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-schema-processor/v2/verifiable"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand Down Expand Up @@ -155,7 +154,7 @@ func main() {
Network: core.NetworkID(cfg.APIUI.IdentityNetwork),
Blockchain: core.Blockchain(cfg.APIUI.IdentityBlockchain),
KeyType: kms.KeyType(cfg.APIUI.KeyType),
AuthBJJCredentialStatus: verifiable.CredentialStatusType(cfg.CredentialStatus.CredentialStatusType),
AuthBJJCredentialStatus: cfg.CredentialStatus.CredentialStatusType,
}

identity, err := identityService.Create(ctx, cfg.APIUI.ServerURL, didCreationOptions)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Server) CreateIdentity(ctx context.Context, request CreateIdentityReque
Network: core.NetworkID(network),
Blockchain: core.Blockchain(blockchain),
KeyType: kms.KeyType(keyType),
AuthBJJCredentialStatus: verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType),
AuthBJJCredentialStatus: s.cfg.CredentialStatus.CredentialStatusType,
})
if err != nil {
if errors.Is(err, services.ErrWrongDIDMetada) {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (s *Server) CreateClaim(ctx context.Context, request CreateClaimRequestObje
expiration = common.ToPointer(time.Unix(*request.Body.Expiration, 0))
}

req := ports.NewCreateClaimRequest(did, request.Body.CredentialSchema, request.Body.CredentialSubject, expiration, request.Body.Type, request.Body.Version, request.Body.SubjectPosition, request.Body.MerklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType), toVerifiableRefreshService(request.Body.RefreshService), request.Body.RevNonce,
req := ports.NewCreateClaimRequest(did, request.Body.CredentialSchema, request.Body.CredentialSubject, expiration, request.Body.Type, request.Body.Version, request.Body.SubjectPosition, request.Body.MerklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, s.cfg.CredentialStatus.CredentialStatusType, toVerifiableRefreshService(request.Body.RefreshService), request.Body.RevNonce,
toVerifiableDisplayMethod(request.Body.DisplayMethod))

resp, err := s.claimService.Save(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ func TestServer_GetRevocationStatus(t *testing.T) {
typeC := "KYCAgeCredential"

merklizedRootPosition := "value"
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, common.ToPointer(time.Now()), typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, common.ToPointer(time.Now()), typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
assert.NoError(t, err)

type expected struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/api_ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (s *Server) CreateCredential(ctx context.Context, request CreateCredentialR
if request.Body.SignatureProof == nil && request.Body.MtProof == nil {
return CreateCredential400JSONResponse{N400JSONResponse{Message: "you must to provide at least one proof type"}}, nil
}
req := ports.NewCreateClaimRequest(&s.cfg.APIUI.IssuerDID, request.Body.CredentialSchema, request.Body.CredentialSubject, request.Body.Expiration, request.Body.Type, nil, nil, nil, request.Body.SignatureProof, request.Body.MtProof, nil, true, verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType), toVerifiableRefreshService(request.Body.RefreshService), nil,
req := ports.NewCreateClaimRequest(&s.cfg.APIUI.IssuerDID, request.Body.CredentialSchema, request.Body.CredentialSubject, request.Body.Expiration, request.Body.Type, nil, nil, nil, request.Body.SignatureProof, request.Body.MtProof, nil, true, s.cfg.CredentialStatus.CredentialStatusType, toVerifiableRefreshService(request.Body.RefreshService), nil,
toDisplayMethodService(request.Body.DisplayMethod))
resp, err := s.claimService.Save(ctx, req)
if err != nil {
Expand Down Expand Up @@ -670,7 +670,7 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin
return CreateLinkQrCodeCallback500JSONResponse{}, nil
}

err = s.linkService.IssueClaim(ctx, request.Params.SessionID.String(), s.cfg.APIUI.IssuerDID, *userDID, request.Params.LinkID, s.cfg.APIUI.ServerURL, verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType))
err = s.linkService.IssueClaim(ctx, request.Params.SessionID.String(), s.cfg.APIUI.IssuerDID, *userDID, request.Params.LinkID, s.cfg.APIUI.ServerURL, s.cfg.CredentialStatus.CredentialStatusType)
if err != nil {
log.Debug(ctx, "error issuing the claim", "error", err)
return CreateLinkQrCodeCallback500JSONResponse{}, nil
Expand Down
34 changes: 17 additions & 17 deletions internal/api_ui/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,13 +1465,13 @@ func TestServer_GetCredential(t *testing.T) {
typeC := "KYCAgeCredential"
merklizedRootPosition := "index"
schema := "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json"
createdClaim1, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdClaim1, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

createdClaim2, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdClaim2, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

createdClaim3, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdClaim3, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
handler := getHandler(ctx, server)

Expand Down Expand Up @@ -1665,19 +1665,19 @@ func TestServer_GetCredentials(t *testing.T) {
_, err = schemaService.ImportSchema(ctx, *did, iReq)
require.NoError(t, err)
// Never expires
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

// Expires in future
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &future, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &future, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

// Expired
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &past, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &past, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

// non expired, but revoked
revoked, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &future, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
revoked, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, &future, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

id, err := w3c.ParseDID(*revoked.Identifier)
Expand Down Expand Up @@ -2127,9 +2127,9 @@ func TestServer_GetCredentialQrCode(t *testing.T) {
typeC := "KYCAgeCredential"
merklizedRootPosition := "index"
schema := "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json"
createdSIGClaim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdSIGClaim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
createdMTPClaim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdMTPClaim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(false), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

type expected struct {
Expand Down Expand Up @@ -2486,9 +2486,9 @@ func TestServer_GetConnections(t *testing.T) {
}

merklizedRootPosition := "index"
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, nil, schemaType, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject, nil, schemaType, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject2, nil, schemaType, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schemaURL, credentialSubject2, nil, schemaType, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

usrDID, err := w3c.ParseDID("did:polygonid:polygon:mumbai:2qE1BZ7gcmEoP2KppvFPCZqyzyb5tK9T6Gec5HFANQ")
Expand Down Expand Up @@ -3715,7 +3715,7 @@ func TestServer_GetLink(t *testing.T) {
SchemaType: link.Schema.Type,
SchemaUrl: link.Schema.URL,
Status: LinkStatusActive,
ProofTypes: []string{"SparseMerkleTreeProof", "BJJSignature2021"},
ProofTypes: []string{"Iden3commRevocationStatusV1", "BJJSignature2021"},
CreatedAt: TimeUTC(link.CreatedAt),
SchemaHash: string(hash),
CredentialExpiration: common.ToPointer(TimeUTC(tomorrow)),
Expand All @@ -3738,7 +3738,7 @@ func TestServer_GetLink(t *testing.T) {
SchemaType: linkExpired.Schema.Type,
SchemaUrl: linkExpired.Schema.URL,
Status: LinkStatusExceeded,
ProofTypes: []string{"SparseMerkleTreeProof", "BJJSignature2021"},
ProofTypes: []string{"Iden3commRevocationStatusV1", "BJJSignature2021"},
CredentialExpiration: nil,
},
},
Expand Down Expand Up @@ -4636,7 +4636,7 @@ func TestServer_GetStateStatus(t *testing.T) {
}

serverWithSignatureClaim := NewServer(cfg1, identityService, claimsService, NewSchemaMock(), connectionsService, NewLinkMock(), nil, NewPublisherMock(), NewPackageManagerMock(), nil)
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(didSignatureClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, true, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(didSignatureClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, true, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
handlerWithSignatureClaim := getHandler(ctx, serverWithSignatureClaim)

Expand All @@ -4652,7 +4652,7 @@ func TestServer_GetStateStatus(t *testing.T) {
},
}
serverWithMTPClaim := NewServer(cfgWithMTPClaim, identityService, claimsService, NewSchemaMock(), connectionsService, NewLinkMock(), nil, NewPublisherMock(), NewPackageManagerMock(), nil)
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(didWithMTPClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, true, verifiable.SparseMerkleTreeProof, nil, nil, nil))
_, err = claimsService.Save(ctx, ports.NewCreateClaimRequest(didWithMTPClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, true, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
handlerWithMTPClaim := getHandler(ctx, serverWithMTPClaim)

Expand All @@ -4668,7 +4668,7 @@ func TestServer_GetStateStatus(t *testing.T) {
},
}
serverWithRevokedClaim := NewServer(cfgWithRevokedClaim, identityService, claimsService, NewSchemaMock(), connectionsService, NewLinkMock(), nil, NewPublisherMock(), NewPackageManagerMock(), nil)
cred, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(didWithRevokedClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, true, verifiable.SparseMerkleTreeProof, nil, nil, nil))
cred, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(didWithRevokedClaim, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(false), nil, true, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)
require.NoError(t, claimsService.Revoke(ctx, cfgWithRevokedClaim.APIUI.IssuerDID, uint64(cred.RevNonce), "not valid"))
handlerWithRevokedClaim := getHandler(ctx, serverWithRevokedClaim)
Expand Down Expand Up @@ -4867,7 +4867,7 @@ func TestServer_GetRevocationStatus(t *testing.T) {
typeC := "KYCAgeCredential"
merklizedRootPosition := "index"
schema := "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json"
createdCredential, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
createdCredential, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, nil, typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
require.NoError(t, err)

handler := getHandler(ctx, server)
Expand Down
7 changes: 4 additions & 3 deletions internal/config/credential_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package config

import (
"strings"

"github.com/iden3/go-schema-processor/v2/verifiable"
)

const (
sparseMerkleTreeProof = "SparseMerkleTreeProof"
iden3commRevocationStatusV1 = "Iden3commRevocationStatusV1.0"
iden3commRevocationStatusV1 = verifiable.Iden3commRevocationStatusV1
iden3ReverseSparseMerkleTreeProof = "Iden3ReverseSparseMerkleTreeProof"
iden3OnchainSparseMerkleTreeProof2023 = "Iden3OnchainSparseMerkleTreeProof2023"
onChain = "OnChain"
Expand All @@ -24,7 +25,7 @@ type CredentialStatus struct {
OnchainTreeStore OnchainTreeStore `mapstructure:"OnchainTreeStore"`
RHSMode RHSMode `tip:"Reverse hash service mode (OffChain, OnChain, Mixed, None)"`
SingleIssuer bool
CredentialStatusType string `mapstructure:"CredentialStatusType" default:"Iden3commRevocationStatusV1"`
CredentialStatusType verifiable.CredentialStatusType `mapstructure:"CredentialStatusType" default:"Iden3commRevocationStatusV1"`
}

// Iden3CommAgentStatus is the type of direct status
Expand Down
Loading

0 comments on commit 3a5e44e

Please sign in to comment.