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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1a8e848
Merge pull request #62 from Portkey-Wallet/release/1.15.0
chaoxkang May 9, 2024
9784e99
Create test-with-code-coverage.yml
chaoxkang May 10, 2024
8fa021c
feat: change dotnet version
chaoxkang May 10, 2024
4582bec
feat: fix workflows
chaoxkang May 11, 2024
8c9faa7
feat: change ubuntu version
chaoxkang May 13, 2024
d33733b
Merge pull request #66 from Portkey-Wallet/release/1.17.0
Edward-BXS Jun 4, 2024
0325605
guardian logic that supports zk login
Edward-BXS Jul 4, 2024
88fdc99
guardian/generate verifier/pr problems
Edward-BXS Jul 8, 2024
4da291a
transfer verifier pb code from cacontract to cacontractimpl,because c…
Edward-BXS Jul 11, 2024
6c2957d
add admin permission logic
Edward-BXS Jul 15, 2024
0bbb3df
change some parameter names
Edward-BXS Jul 15, 2024
7ade3d3
change parameter names
Edward-BXS Jul 15, 2024
1928c5a
some unit tests
Edward-BXS Jul 17, 2024
1067d42
change zk definition
Edward-BXS Jul 17, 2024
4c680d5
add zk auth rule
Edward-BXS Jul 18, 2024
35e9aa6
extract zkproof data
Edward-BXS Jul 18, 2024
2602953
update contract
Edward-BXS Jul 18, 2024
78693da
opt the code style
Edward-BXS Jul 19, 2024
93220a9
remove useless log
Edward-BXS Jul 19, 2024
7110f1f
add ut
Edward-BXS Jul 20, 2024
c918684
guardian adjustment
Edward-BXS Jul 24, 2024
93ef7ea
change the method of setting public key and chunks, support poseidon …
Edward-BXS Jul 27, 2024
4e9dd1b
nonce datetime
Edward-BXS Jul 27, 2024
c31f2f9
adjustment of test problems
Edward-BXS Aug 16, 2024
0a21aa4
update the latest package, fix the code check problems
Edward-BXS Aug 19, 2024
35802cb
issue template
Edward-BXS Aug 19, 2024
975a558
Merge branch 'master' into feature/zklogin
Edward-BXS Aug 19, 2024
bb9c39a
Merge pull request #75 from Portkey-Wallet/feature/add-workflows
Edward-BXS Aug 20, 2024
2057dc5
change dotnet 6.0 to 8.0
Edward-BXS Aug 20, 2024
b1e1704
change pipeline's .net sdk version to 8.0
Edward-BXS Aug 20, 2024
abe2e52
Merge branch 'master' into feature/zklogin
Edward-BXS Aug 20, 2024
6e7c870
adjustment the unit test
Edward-BXS Aug 20, 2024
cf87591
ut adjustment
Edward-BXS Aug 20, 2024
f4f0c24
remove global.json
Edward-BXS Aug 20, 2024
da49c5b
change .net 8.0 to 6.0
Edward-BXS Aug 20, 2024
082ce86
recover the sdk and dotnet version
Edward-BXS Aug 20, 2024
7dcb54c
change dotnet 8.0.107
Edward-BXS Aug 20, 2024
f4914a4
return the sdk version
Edward-BXS Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: 👾 Bug Report
about: Report a bug or issue with the project.
title: ''
labels: 'bug'
assignees: ''

---

### Description
A clear and concise description of what the bug is.

### Steps To Reproduce
1. Log in...
2. Ensure that...
3. Allow a long period of inactivity to pass...
4. Observe that...
5. Attempt to log in...

### Current Behavior
- After the period of inactivity...
- When the user tries to log in using another method...
- This causes a bug due to...

### Expected Behavior
- After a long period of inactivity...
- When a user logs in successfully...
- This ensures that only...

### Environment
- Platform: PC
- Node: v18.18.0
- Browser: Chrome 126.0.6478.56
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
blank_issues_enabled: false
issue_template:
- name: 👾 Bug Report
description: Report a bug or issue with the project.
labels: ["bug"]
template: bug_report.md
- name: 💡 Feature Request
description: Create a new ticket for a new feature request.
labels: ["enhancement"]
template: feature_request.md
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: 💡 Feature Request
about: Create a new ticket for a new feature request
title: ''
labels: 'enhancement'
assignees: ''

---

### Expected Behavior
Describe the expected behavior here.

### Specifications
As a `user`, I would like to `action` so that `reason`.

**Features:**
- describe feature details here.

**Development Tasks:**
- [ ] Task 1
- [ ] Task 2

### Dependencies
List any dependencies that are required for this feature by providing links to the issues or repositories.

### References
List any references that are related to this feature request.
88 changes: 88 additions & 0 deletions .github/workflows/test-with-code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: Test with code coverage

on:
push:
branches:
- '**'

env:
DOTNET_INSTALL_DIR: "./.dotnet"

jobs:
test:
runs-on: ubuntu-20.04
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'

- name: 'Download AElf build tools'
run: bash scripts/download_binary.sh

- name: 'Install protobuf'
run: bash scripts/install.sh

- name: Install dependencies
run: dotnet restore --verbosity quiet

- name: Build
run: dotnet build --no-restore /clp:ErrorsOnly /p:GeneratePackageOnBuild=false --verbosity quiet

- name: Test
run: |
for name in `ls ./test/*.Tests/*.csproj | awk '{print $NF}'`;
do
dotnet test ${name} --no-restore --no-build --logger trx --settings CodeCoverage.runsettings --results-directory coverage --collect:"XPlat Code Coverage"
done

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: coverage/*/coverage.cobertura.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 6.0.x
version: 8.0.x
- script: bash scripts/install_protobuf.sh
- script: bash scripts/download_binary.sh
- script: bash build.sh -target=Test-with-Codecov
Expand Down
83 changes: 83 additions & 0 deletions contract/Portkey.Contracts.CA/BytesExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections.Generic;

namespace Portkey.Contracts.CA;

public static class BytesExtension
{
private static void ShiftArrayRight(byte[] array, int shiftBits)
{
int shiftBytes = shiftBits / 8;
int num1 = shiftBits % 8;
if (num1 == 0)
{
ShiftBytesRight(array, shiftBytes);
}
else
{
int num2 = (8 - num1) % 8;
int length = array.Length;
int num3 = length - shiftBytes;
int num4 = length - 1;
for (int index1 = 0; index1 < num3; ++index1)
{
int num5 = index1 + shiftBytes;
int index2 = num4 - index1;
int index3 = num4 - num5;
int num6 = (int) array[index3];
byte num7 = (byte) ((index3 > 0 ? (int) array[index3 - 1] : 0) << num2 & 0xff); //& 0xff
int num8 = num1 & 31;
byte num9 = (byte) (num6 >> num8);
array[index2] = (byte) ((uint) num7 | (uint) num9);
}
for (int index = 0; index < shiftBytes; ++index)
array[index] = (byte) 0;
}
}

private static void ShiftBytesRight(byte[] array, int shiftBytes)
{
int length = array.Length;
int num1 = length - shiftBytes;
int num2 = length - 1;
for (int index1 = 0; index1 < num1; ++index1)
{
int num3 = index1 + shiftBytes;
int index2 = num2 - index1;
int index3 = num2 - num3;
array[index2] = array[index3];
}
for (int index = 0; index < shiftBytes; ++index)
array[index] = (byte) 0;
}

private static byte[] Mask(byte[] array, int maskBits)
{
int length1 = (maskBits - 1) / 8 + 1;
int num1 = maskBits % 8;
int length2 = array.Length;
var numList = new List<byte>(length1);
for (var i = 0; i < length1; i++)
numList.Add(0);
int num2 = length1 - 1;
int num3 = length2 - 1;
for (int index = 0; index < length1; ++index)
numList[num2 - index] = array[num3 - index];
byte num4 = 0;
for (int index = 0; index < num1; ++index)
num4 |= (byte) (1 << index);
if (num1 > 0)
numList[0] = (byte) ((uint) numList[0] & (uint) num4);
return numList.ToArray();
}

public static IList<byte[]> ToChunked(this byte[] bytes, int bytesPerChunk, int numOfChunks)
{
List<byte[]> chunked = new List<byte[]>();
for (int index = 0; index < numOfChunks; ++index)
{
chunked.Add(Mask(bytes, bytesPerChunk));
ShiftArrayRight(bytes, bytesPerChunk);
}
return chunked;
}
}
3 changes: 2 additions & 1 deletion contract/Portkey.Contracts.CA/CAContractReferenceState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AElf.Contracts.Configuration;
using AElf.Contracts.MultiToken;
using AElf.Standards.ACS0;
using AetherLink.Contracts.Oracle;

namespace Portkey.Contracts.CA;

Expand All @@ -10,5 +11,5 @@ public partial class CAContractState
internal ACS0Container.ACS0ReferenceState GenesisContract { get; set; }
internal ConfigurationContainer.ConfigurationReferenceState ConfigurationContract { get; set; }


internal OracleContractContainer.OracleContractReferenceState OracleContract { get; set; }
}
12 changes: 11 additions & 1 deletion contract/Portkey.Contracts.CA/CAContractState.cs
Edward-BXS marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,15 @@ public partial class CAContractState : ContractState
/// </summary>
public MappedState<Hash, Hash> PreCrossChainSyncHolderInfoMarks { get; set; }


//zklogin admin operations key is the verifier type(Google/Apple...) value is the issuer
public MappedState<GuardianType, ZkBasicAdminData> OidcProviderData { get; set; }
//key is circuitId, value is VerifyingKeys
public MappedState<string, VerifyingKey> CircuitVerifyingKeys { get; set; }
//guardian type,kid, value is public key
public MappedState<GuardianType, string, ZkPublicKeyInfo> PublicKeysChunksByKid { get; set; }
//guardian type, current kid list, keep the same with aetherlink invacation
public MappedState<GuardianType, CurrentKids> KidsByGuardianType { get; set; }

//differentiate the used nonce by caHash
public MappedState<Hash, ZkNonceList> ZkNonceInfosByCaHash { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void AddPathForDelegatees(ResourceInfo resourceInfo, Address from, Addre
if (delegateeList.Count <= 0) return;
var secondDelegateeList = new List<string>();
//get and add second-level delegatee list
foreach (var delegateeAddress in delegateeList.Select(Address.FromBase58))
foreach (var delegateeAddress in delegateeList.Select(ConvertAddress))
{
//delegatee of the first-level delegate is delegator of the second-level delegate
secondDelegateeList.AddRange(GetDelegateeList(delegateeAddress, to, methodName));
Expand All @@ -92,6 +92,12 @@ private void AddPathForDelegatees(ResourceInfo resourceInfo, Address from, Addre
AddPathForTransactionFeeFreeAllowance(resourceInfo, Address.FromBase58(delegatee));
}
}

//code check not supports static invocation in linq
private Address ConvertAddress(string address)
{
return Address.FromBase58(address);
}

private void AddPathForTransactionFee(ResourceInfo resourceInfo, string from, string methodName)
{
Expand Down
Loading
Loading