-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support go-onchain-credential-adapter #57
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c268244
Add didMethods config option to register custom DID methods
olomix 23c29eb
Get rid of custom ChainID type and knownChainIDs map. Use the ones fr…
olomix b848380
Add tests for custom DID methods registration and do refactorings bas…
olomix 8dd29f6
Resolve recocation status using go-schema-processor CredentialStatusR…
olomix 430371d
Supress badger logging in tests
olomix 118fc6b
Upgrade GitHub action version to suppress warnings
olomix c49a53b
Migrate to local ipfs node instead of from secrets (#56)
olomix 1e0d12c
Add a new function PLGNNewGenesisID similar to PLGNCalculateGenesisID…
olomix 585ee1d
fix test
olomix b04721c
Add deprecation comment to PLGNCalculateGenesisID
olomix 358e688
Merge branch 'register_chain' into migrate_core_proof
olomix 1ab6004
fix merge issuers
olomix 4c36446
check if somebody uses old fields in configuration and return an error
olomix 26d2f55
fix typing
olomix d033030
fix TestNewEnvConfigFromJSON test
olomix c1912aa
fix TestEnvConfig_UnmarshalJSON test
olomix a27536e
Fix handling error in PLGNNewGenesisID function
olomix c71a923
support go-onchain-credential-adapter
ilya-korotya 88a00a3
dump golang version
ilya-korotya 406e224
fix comments
ilya-korotya 84a2e56
add input and config samples for PLGNW3CCredentialFromOnchainHex method
ilya-korotya e013f28
Remove legacy configuration options from doc comments
olomix 1aa987a
fix docstring links
olomix 3866a9c
merged main
olomix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 c_polygonid | ||||||||
|
||||||||
import ( | ||||||||
"context" | ||||||||
"encoding/json" | ||||||||
"fmt" | ||||||||
|
||||||||
"github.com/ethereum/go-ethereum/ethclient" | ||||||||
core "github.com/iden3/go-iden3-core/v2" | ||||||||
"github.com/iden3/go-iden3-core/v2/w3c" | ||||||||
convertor "github.com/iden3/go-onchain-credential-adapter" | ||||||||
"github.com/iden3/go-schema-processor/v2/merklize" | ||||||||
"github.com/iden3/go-schema-processor/v2/verifiable" | ||||||||
) | ||||||||
|
||||||||
type w3CCredentialFromOnchainHexRequest struct { | ||||||||
IssuerDID coreDID `json:"issuerDID"` | ||||||||
Hexdata string `json:"hexdata"` | ||||||||
Version string `json:"version"` | ||||||||
} | ||||||||
|
||||||||
func W3CCredentialFromOnchainHex( | ||||||||
ctx context.Context, | ||||||||
envCfg EnvConfig, | ||||||||
in []byte, | ||||||||
) (*verifiable.W3CCredential, error) { | ||||||||
var inParams w3CCredentialFromOnchainHexRequest | ||||||||
if err := json.Unmarshal(in, &inParams); err != nil { | ||||||||
return nil, fmt.Errorf("failed to unmarshal input params: %w", err) | ||||||||
} | ||||||||
|
||||||||
issuerDID := w3c.DID(inParams.IssuerDID) | ||||||||
|
||||||||
chainID, err := core.ChainIDfromDID(issuerDID) | ||||||||
if err != nil { | ||||||||
return nil, fmt.Errorf("failed to get chain id from issuer: %w", err) | ||||||||
} | ||||||||
chainConfig, ok := envCfg.ChainConfigs[chainID] | ||||||||
if !ok { | ||||||||
return nil, fmt.Errorf("chain id '%d' not found in config", chainID) | ||||||||
} | ||||||||
|
||||||||
ethcli, err := ethclient.DialContext(ctx, chainConfig.RPCUrl) | ||||||||
if err != nil { | ||||||||
return nil, | ||||||||
fmt.Errorf("failed to connect to ethereum: %w", err) | ||||||||
} | ||||||||
defer ethcli.Close() | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
credential, err := convertor.W3CCredentialFromOnchainHex( | ||||||||
ctx, | ||||||||
ethcli, | ||||||||
&issuerDID, | ||||||||
inParams.Hexdata, | ||||||||
inParams.Version, | ||||||||
convertor.WithMerklizeOptions( | ||||||||
merklize.Options{ | ||||||||
DocumentLoader: envCfg.documentLoader(), | ||||||||
}, | ||||||||
), | ||||||||
) | ||||||||
if err != nil { | ||||||||
return nil, | ||||||||
fmt.Errorf("failed to convert onchain hex to W3C credential: %w", err) | ||||||||
} | ||||||||
return credential, nil | ||||||||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a documentation to this function?