Skip to content
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

Open
wants to merge 38 commits into
base: dev
Choose a base branch
from
Open

Conversation

Edward-BXS
Copy link
Collaborator

No description provided.

Copy link

@stevenportkey stevenportkey left a 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?

Comment on lines 418 to 452
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];
}

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.

Comment on lines 454 to 485
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();
}

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.

Comment on lines 508 to 521
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; }
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -237,13 +272,57 @@ message GuardianInfo {
GuardianType type = 1;
aelf.Hash identifier_hash = 2;
VerificationInfo verification_info = 3;
ZkJwtAuthInfo zk_oidc_info = 4;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,

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.

Comment on lines 97 to 120
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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to DecodeBase64Url.

Comment on lines 385 to 388
if (CanVerifyWithZkLogin(guardianInfo))
{
continue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

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?

@Edward-BXS Edward-BXS linked an issue Aug 19, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZkLogin
3 participants