-
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 20 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
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 |
---|---|---|
|
@@ -216,66 +216,66 @@ func PLGNAuthV2InputsMarshal(jsonResponse **C.char, in *C.char, | |
return true | ||
} | ||
|
||
// Deprecated: Use PLGNNewGenesisID instead. It supports environment | ||
// configuration, giving the ability to register custom DID methods. | ||
// | ||
//export PLGNCalculateGenesisID | ||
func PLGNCalculateGenesisID(jsonResponse **C.char, in *C.char, | ||
status **C.PLGNStatus) bool { | ||
|
||
_, cancel := logAPITime() | ||
ctx, cancel := logAPITime() | ||
defer cancel() | ||
|
||
var req struct { | ||
ClaimsTreeRoot *jsonIntStr `json:"claimsTreeRoot"` | ||
Blockchain core.Blockchain `json:"blockchain"` | ||
Network core.NetworkID `json:"network"` | ||
} | ||
|
||
if in == nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_NIL_POINTER, | ||
"pointer to request is nil") | ||
return false | ||
} | ||
|
||
err := json.Unmarshal([]byte(C.GoString(in)), &req) | ||
inStr := C.GoString(in) | ||
resp, err := c_polygonid.NewGenesysID(ctx, c_polygonid.EnvConfig{}, | ||
[]byte(inStr)) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
state, err := merkletree.HashElems(req.ClaimsTreeRoot.Int(), | ||
merkletree.HashZero.BigInt(), merkletree.HashZero.BigInt()) | ||
respB, err := json.Marshal(resp) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
typ, err := core.BuildDIDType(core.DIDMethodPolygonID, req.Blockchain, | ||
req.Network) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
*jsonResponse = C.CString(string(respB)) | ||
return true | ||
} | ||
|
||
//export PLGNNewGenesisID | ||
func PLGNNewGenesisID(jsonResponse **C.char, in *C.char, cfg *C.char, | ||
status **C.PLGNStatus) bool { | ||
|
||
ctx, cancel := logAPITime() | ||
defer cancel() | ||
|
||
if in == nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_NIL_POINTER, | ||
"pointer to request is nil") | ||
return false | ||
} | ||
|
||
coreID, err := core.NewIDFromIdenState(typ, state.BigInt()) | ||
envCfg, err := createEnvConfig(cfg) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
did, err := core.ParseDIDFromID(*coreID) | ||
inStr := C.GoString(in) | ||
resp, err := c_polygonid.NewGenesysID(ctx, envCfg, []byte(inStr)) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
resp := struct { | ||
DID string `json:"did"` | ||
ID string `json:"id"` | ||
IDAsInt string `json:"idAsInt"` | ||
}{ | ||
DID: did.String(), | ||
ID: coreID.String(), | ||
IDAsInt: coreID.BigInt().String(), | ||
} | ||
respB, err := json.Marshal(resp) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
|
@@ -861,15 +861,73 @@ func PLGNCacheCredentials(in *C.char, cfg *C.char, status **C.PLGNStatus) bool { | |
return true | ||
} | ||
|
||
// PLGNW3CCredentialFromOnchainHex returns a verifiable credential from an onchain data hex string. | ||
// | ||
// Sample configuration: | ||
// | ||
// { | ||
// "issuerDID": "did:polygonid:polygon:mumbai:2qCU58EJgrEMJvPfhUCnFCwuKQTkX8VmJX2sJCH6C8", | ||
// "hexdata": "0x0...", | ||
// "version": "0.0.1" | ||
// } | ||
// | ||
//export PLGNW3CCredentialFromOnchainHex | ||
func PLGNW3CCredentialFromOnchainHex(jsonResponse **C.char, in *C.char, | ||
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. Could you add a documentation to this function? |
||
cfg *C.char, status **C.PLGNStatus) bool { | ||
|
||
if jsonResponse == nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_NIL_POINTER, | ||
"jsonResponse pointer is nil") | ||
return false | ||
} | ||
|
||
if in == nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_NIL_POINTER, | ||
"pointer to request is nil") | ||
return false | ||
} | ||
|
||
ctx, cancel := logAPITime() | ||
defer cancel() | ||
|
||
ctx2, cancel2 := context.WithTimeout(ctx, defaultTimeout) | ||
defer cancel2() | ||
|
||
inData := C.GoBytes(unsafe.Pointer(in), C.int(C.strlen(in))) | ||
|
||
envCfg, err := createEnvConfig(cfg) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
credential, err := c_polygonid.W3CCredentialFromOnchainHex( | ||
ctx2, | ||
envCfg, | ||
inData, | ||
) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
credentialJSON, err := json.Marshal(credential) | ||
if err != nil { | ||
maybeCreateStatus(status, C.PLGNSTATUSCODE_ERROR, err.Error()) | ||
return false | ||
} | ||
|
||
*jsonResponse = C.CString(string(credentialJSON)) | ||
return true | ||
} | ||
|
||
// createEnvConfig returns empty config if input json is nil. | ||
func createEnvConfig(cfgJson *C.char) (c_polygonid.EnvConfig, error) { | ||
var cfg c_polygonid.EnvConfig | ||
var err error | ||
var cfgData []byte | ||
if cfgJson != nil { | ||
cfgData := C.GoBytes(unsafe.Pointer(cfgJson), C.int(C.strlen(cfgJson))) | ||
err = json.Unmarshal(cfgData, &cfg) | ||
cfgData = C.GoBytes(unsafe.Pointer(cfgJson), C.int(C.strlen(cfgJson))) | ||
} | ||
return cfg, err | ||
return c_polygonid.NewEnvConfigFromJSON(cfgData) | ||
} | ||
|
||
type atomicQueryInputsFn func(ctx context.Context, cfg c_polygonid.EnvConfig, | ||
|
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.
it's an input, not a configuration