-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d9402c
commit fe71e5b
Showing
2 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |