-
Notifications
You must be signed in to change notification settings - Fork 1
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
guardian logic that supports zk login #70
base: dev
Are you sure you want to change the base?
Conversation
guardianApprove verify operate details
Release/1.17.0
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.
Now we only implemented logics for CAHolder creation. What about other scenarios where Guardian approval is needed?
public override Empty AddJwtIssuer(/*GuardianType guardianType, */StringValue input) | ||
{ | ||
Assert(input != null, "Invalid Issuer."); | ||
Assert(!input.Equals(State.JwtIssuers[GuardianType.OfGoogle]), "Google jwt issuer exists"); | ||
State.JwtIssuers[GuardianType.OfGoogle] = input.Value; | ||
return new Empty(); | ||
} | ||
|
||
public override Empty AddVerifyingKey(VerifyingKey input) | ||
{ | ||
Assert(input != null, "Invalid verifying key."); | ||
Assert(!string.IsNullOrEmpty(input.CircuitId), "circuitId is required."); | ||
Assert(!string.IsNullOrEmpty(input.VerifyingKey_), "verifying key is required."); | ||
State.CircuitIdToVerifyingKey[input.CircuitId] = input; | ||
return base.AddVerifyingKey(input); | ||
} | ||
|
||
public override BoolValue IsValidIssuer(/*GuardianType guardianType, */StringValue input) | ||
{ | ||
Assert(input != null, "Invalid verifying key."); | ||
Assert(State.JwtIssuers[GuardianType.OfGoogle] != null | ||
|| State.JwtIssuers[GuardianType.OfApple] != null | ||
|| State.JwtIssuers[GuardianType.OfFacebook] != null, "verifying key doesn't exist."); | ||
return new BoolValue | ||
{ | ||
Value = true//State.JwtIssuers[guardianType].Equals(input) | ||
}; | ||
} | ||
|
||
public override VerifyingKey GetVerifyingKey(StringValue input) | ||
{ | ||
Assert(input != null, "Invalid circuitId."); | ||
Assert(State.CircuitIdToVerifyingKey[input.Value] != null, "circuitId not exist"); | ||
return State.CircuitIdToVerifyingKey[input.Value]; | ||
} |
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.
These are different group of methods. Please move them into a separate file.
public override Empty StartOracleRequest(StartOracleRequestInput input) | ||
{ | ||
Assert(input != null, "Invalid input."); | ||
Assert(input.SubscriptionId > 0, "Invalid input subscription id."); | ||
Assert(input.RequestTypeIndex > 0, "Invalid request type index."); | ||
|
||
State.OracleContract.SendRequest.Send(new SendRequestInput | ||
{ | ||
SubscriptionId = input.SubscriptionId, | ||
RequestTypeIndex = input.RequestTypeIndex, | ||
SpecificData = input.SpecificData | ||
}); | ||
|
||
return new Empty(); | ||
} | ||
|
||
public override Empty HandleOracleFulfillment(HandleOracleFulfillmentInput input) | ||
{ | ||
Assert(input != null, "Invalid input."); | ||
// Assert(IsHashValid(input.RequestId), "Invalid input request id."); | ||
Assert(input.RequestTypeIndex > 0, "Invalid request type index."); | ||
Assert(!input.Response.IsNullOrEmpty() || !input.Err.IsNullOrEmpty(), "Invalid input response or err."); | ||
GoogleResponse reponse = JsonConvert.DeserializeObject<GoogleResponse>(System.Text.Encoding.UTF8.GetString(input.Response.ToByteArray())); | ||
Assert(reponse != null, "Invalid input."); | ||
//todo aetherlink can't differentiate apple/google/facebook | ||
foreach (var googleKeyDto in reponse.Keys) | ||
{ | ||
State.KidToPublicKey[GuardianType.OfGoogle][googleKeyDto.Kid] = googleKeyDto.N; | ||
} | ||
|
||
return new Empty(); | ||
} |
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.
These are different group of methods. Please move them into a separate file.
internal class GoogleResponse | ||
{ | ||
public List<GoogleKeyDto> Keys { get; set; } | ||
} | ||
|
||
internal class GoogleKeyDto | ||
{ | ||
public string N { get; set; } | ||
public string Kid { get; set; } | ||
public string E { get; set; } | ||
public string Alg { get; set; } | ||
public string Kty { get; set; } | ||
public string Use { get; set; } | ||
} |
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.
Move into separate file.
public List<GoogleKeyDto> Keys { get; set; } | ||
} | ||
|
||
internal class GoogleKeyDto |
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.
This is not specific to Google. Other providers follow the same.
protobuf/ca_contract.proto
Outdated
@@ -237,13 +272,57 @@ message GuardianInfo { | |||
GuardianType type = 1; | |||
aelf.Hash identifier_hash = 2; | |||
VerificationInfo verification_info = 3; | |||
ZkJwtAuthInfo zk_oidc_info = 4; |
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.
ZkJwtAuthInfo zk_oidc_info = 4; | |
ZkLoginInfo zk_login_info = 4; |
@@ -162,13 +198,70 @@ public override Empty ReportPreCrossChainSyncHolderInfo(ReportPreCrossChainSyncH | |||
|
|||
return new Empty(); | |||
} | |||
|
|||
private bool CreateCaHolderInfoWithCaHashAndCreateChainIdForZkLogin(ManagerInfo managerInfo, GuardianInfo guardianApproved, |
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.
NoncePayload
needs to be checked again actual operation taken in current transaction, e.g. AddManager
for CreateCAHolder
.
private byte[] Decode(string input) | ||
{ | ||
if (input.IsNullOrEmpty()) | ||
throw new ArgumentException(nameof(input)); | ||
|
||
var output = input; | ||
output = output.Replace('-', '+'); // 62nd char of encoding | ||
output = output.Replace('_', '/'); // 63rd char of encoding | ||
switch (output.Length % 4) // Pad with trailing '='s | ||
{ | ||
case 0: | ||
break; // No pad chars in this case | ||
case 2: | ||
output += "=="; | ||
break; // Two pad chars | ||
case 3: | ||
output += "="; | ||
break; // One pad char | ||
default: | ||
throw new FormatException("Illegal base64url string."); | ||
} | ||
var converted = Convert.FromBase64String(output); // Standard base64 decoder | ||
return converted; | ||
} |
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.
Rename this to DecodeBase64Url
.
if (CanVerifyWithZkLogin(guardianInfo)) | ||
{ | ||
continue; | ||
} |
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.
What is this for?
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.
Now we only implemented logics for CAHolder creation. What about other scenarios where Guardian approval is needed?
…acontract need add zk definitions,verifiers logic should be tested by qa
…hash when verifying zk
c0cc42e
to
0a21aa4
Compare
Feature/add workflows
No description provided.