Skip to content

Commit

Permalink
separate direct status
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Jan 8, 2024
1 parent 0d9402c commit fe71e5b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 56 deletions.
56 changes: 0 additions & 56 deletions verifiable/credential_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"math/big"
"net/http"
"strings"
"sync"

Expand Down Expand Up @@ -221,60 +219,6 @@ func remarshalObj(dst, src any) error {
return json.Unmarshal(objBytes, dst)
}

func resolveRevocationStatusFromIssuerService(ctx context.Context,
url string) (out circuits.MTProof, err error) {

httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url,
http.NoBody)
if err != nil {
return out, err
}
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return out, err
}
defer func() {
err2 := httpResp.Body.Close()
if err == nil {
err = err2
}
}()
if httpResp.StatusCode != http.StatusOK {
return out, fmt.Errorf("unexpected status code: %v",
httpResp.StatusCode)
}
respData, err := io.ReadAll(io.LimitReader(httpResp.Body, 16*1024))
if err != nil {
return out, err
}
var obj struct {
TreeState struct {
State *hexHash `json:"state"` // identity state
ClaimsRoot *hexHash `json:"claimsTreeRoot"` // claims tree root
RevocationRoot *hexHash `json:"revocationTreeRoot"` // revocation tree root
RootOfRoots *hexHash `json:"rootOfRoots"` // root of roots tree root

} `json:"issuer"`
Proof *merkletree.Proof `json:"mtp"`
}
err = json.Unmarshal(respData, &obj)
if err != nil {
return out, err
}
out.Proof = obj.Proof
out.TreeState.State = (*merkletree.Hash)(obj.TreeState.State)
out.TreeState.ClaimsRoot = (*merkletree.Hash)(obj.TreeState.ClaimsRoot)
out.TreeState.RevocationRoot = (*merkletree.Hash)(obj.TreeState.RevocationRoot)
if out.TreeState.RevocationRoot == nil {
out.TreeState.RevocationRoot = &merkletree.Hash{}
}
out.TreeState.RootOfRoots = (*merkletree.Hash)(obj.TreeState.RootOfRoots)
if out.TreeState.RootOfRoots == nil {
out.TreeState.RootOfRoots = &merkletree.Hash{}
}
return out, nil
}

// check TreeState consistency
func validateTreeState(s circuits.TreeState) (bool, error) {
if s.State == nil {
Expand Down
67 changes: 67 additions & 0 deletions verifiable/status_direct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package verifiable

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/iden3/go-circuits/v2"
"github.com/iden3/go-merkletree-sql/v2"
"github.com/pkg/errors"
)

func resolveRevocationStatusFromIssuerService(ctx context.Context,
url string) (out circuits.MTProof, err error) {

httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url,
http.NoBody)
if err != nil {
return out, err
}
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return out, err
}
defer func() {
err2 := httpResp.Body.Close()
if err != nil {
err = errors.WithStack(err2)
}
}()
if httpResp.StatusCode != http.StatusOK {
return out, fmt.Errorf("unexpected status code: %v",
httpResp.StatusCode)
}
respData, err := io.ReadAll(io.LimitReader(httpResp.Body, 16*1024))
if err != nil {
return out, err
}
var obj struct {
TreeState struct {
State *hexHash `json:"state"` // identity state
ClaimsRoot *hexHash `json:"claimsTreeRoot"` // claims tree root
RevocationRoot *hexHash `json:"revocationTreeRoot"` // revocation tree root
RootOfRoots *hexHash `json:"rootOfRoots"` // root of roots tree root

} `json:"issuer"`
Proof *merkletree.Proof `json:"mtp"`
}
err = json.Unmarshal(respData, &obj)
if err != nil {
return out, err
}
out.Proof = obj.Proof
out.TreeState.State = (*merkletree.Hash)(obj.TreeState.State)
out.TreeState.ClaimsRoot = (*merkletree.Hash)(obj.TreeState.ClaimsRoot)
out.TreeState.RevocationRoot = (*merkletree.Hash)(obj.TreeState.RevocationRoot)
if out.TreeState.RevocationRoot == nil {
out.TreeState.RevocationRoot = &merkletree.Hash{}
}
out.TreeState.RootOfRoots = (*merkletree.Hash)(obj.TreeState.RootOfRoots)
if out.TreeState.RootOfRoots == nil {
out.TreeState.RootOfRoots = &merkletree.Hash{}
}
return out, nil
}

0 comments on commit fe71e5b

Please sign in to comment.