Skip to content

Commit

Permalink
Feat/support more accounts (#64)
Browse files Browse the repository at this point in the history
* Bump gorm.io/driver/postgres from 1.5.9 to 1.5.10 (#59)

Bumps [gorm.io/driver/postgres](https://github.com/go-gorm/postgres) from 1.5.9 to 1.5.10.
- [Commits](go-gorm/postgres@v1.5.9...v1.5.10)

---
updated-dependencies:
- dependency-name: gorm.io/driver/postgres
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump micromatch (#56)

Bumps the npm_and_yarn group with 1 update in the /example/webauthn-relay-test directory: [micromatch](https://github.com/micromatch/micromatch).


Updates `micromatch` from 4.0.7 to 4.0.8
- [Release notes](https://github.com/micromatch/micromatch/releases)
- [Changelog](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md)
- [Commits](micromatch/micromatch@4.0.7...4.0.8)

---
updated-dependencies:
- dependency-name: micromatch
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump golang.org/x/time from 0.7.0 to 0.8.0 (#57)

Bumps [golang.org/x/time](https://github.com/golang/time) from 0.7.0 to 0.8.0.
- [Commits](golang/time@v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/time
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/golang-jwt/jwt/v4 in the go_modules group (#58)

Bumps the go_modules group with 1 update: [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt).


Updates `github.com/golang-jwt/jwt/v4` from 4.5.0 to 4.5.1
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md)
- [Commits](golang-jwt/jwt@v4.5.0...v4.5.1)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v4
  dependency-type: indirect
  dependency-group: go_modules
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/ethereum/go-ethereum from 1.14.11 to 1.14.12 (#60)

Bumps [github.com/ethereum/go-ethereum](https://github.com/ethereum/go-ethereum) from 1.14.11 to 1.14.12.
- [Release notes](https://github.com/ethereum/go-ethereum/releases)
- [Commits](ethereum/go-ethereum@v1.14.11...v1.14.12)

---
updated-dependencies:
- dependency-name: github.com/ethereum/go-ethereum
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump gorm.io/driver/postgres from 1.5.9 to 1.5.11

Bumps [gorm.io/driver/postgres](https://github.com/go-gorm/postgres) from 1.5.9 to 1.5.11.
- [Commits](go-gorm/postgres@v1.5.9...v1.5.11)

---
updated-dependencies:
- dependency-name: gorm.io/driver/postgres
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* WIP: signup with EOA

* WIP: eoa registry demo

* WIP: reg by account

* Bump golang.org/x/time from 0.7.0 to 0.8.0 (#63)

Bumps [golang.org/x/time](https://github.com/golang/time) from 0.7.0 to 0.8.0.
- [Commits](golang/time@v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/time
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/ethereum/go-ethereum from 1.14.11 to 1.14.12 (#61)

Bumps [github.com/ethereum/go-ethereum](https://github.com/ethereum/go-ethereum) from 1.14.11 to 1.14.12.
- [Release notes](https://github.com/ethereum/go-ethereum/releases)
- [Commits](ethereum/go-ethereum@v1.14.11...v1.14.12)

---
updated-dependencies:
- dependency-name: github.com/ethereum/go-ethereum
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* WIP: support account like eoa and etc as airaccount rather than email

* continue-on-error: true for TestAndCoverage(renamed from build)

* add required job in github action

* typo fix

* WIP: finish signup with eoa

* finish signin with eoa

* support create aa wallet

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: STW <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2024
1 parent 9d0ecbd commit 29b46fe
Show file tree
Hide file tree
Showing 23 changed files with 3,226 additions and 139 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ on:
- "*"

jobs:
build:
UnitTests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Go Module Downloads
run: go mod download
- name: Run tests
run: go test -v -short -race ./...

TestAndCoverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -25,3 +37,4 @@ jobs:
with:
token: ${{secrets.CODECOV_TOKEN}}
slug: AAStarCommunity/AnotherAirAccountCommunityNode
continue-on-error: true
3 changes: 3 additions & 0 deletions example/webauthn-relay-test/app/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
enum API {
PASSKEY_REG = "/api/passkey/v1/reg",
PASSKEY_REG_BY_ACCOUNT = "/api/passkey/v1/reg-account",
PASSKEY_REG_VERIFY = "/api/passkey/v1/reg/verify",
PASSKEY_REG_VERIFY_BY_ACCOUNT = "/api/passkey/v1/reg-account/verify",
PASSKEY_AUTH = "/api/passkey/v1/sign",
PASSKEY_AUTH_VERIFY = "/api/passkey/v1/sign/verify",
PASSKEY_PAYMENT = "/api/passkey/v1/tx/sign",
PASSKEY_PAYMENT_VERIFY = "/api/passkey/v1/tx/sign/verify",
SUPPORT_NETWORKS = "/api/passkey/v1/chains/support",
CREATE_AA = "/api/passkey/v1/account/chain",
}

export default API;
122 changes: 122 additions & 0 deletions example/webauthn-relay-test/app/connect-wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { ConnectButton } from '@rainbow-me/rainbowkit';
import './style.css';
import { useAccount } from 'wagmi';
import { useEffect } from 'react';
import api from "@/app/api";
import API from "./api/api";
import { PasskeyRegisterByEOA } from './passkey';

const ConnectWallet = () => {

const { isConnected, address } = useAccount();

useEffect(() => {
if (isConnected) {
let user = PasskeyRegisterByEOA(address!);
if (user != null) {
} else {
}

console.log(`Connected to ${address}`);
} else {
console.log('Disconnected');
}
}, [isConnected, address]);


return (
<ConnectButton.Custom>
{({
account,
chain,
openAccountModal,
openChainModal,
openConnectModal,
authenticationStatus,
mounted,
}) => {
// Note: If your app doesn't use authentication, you
// can remove all 'authenticationStatus' checks
const ready = mounted && authenticationStatus !== 'loading';
const connected =
ready &&
account &&
chain &&
(!authenticationStatus ||
authenticationStatus === 'authenticated');

return (
<div
{...(!ready && {
'aria-hidden': true,
'style': {
opacity: 0,
pointerEvents: 'none',
userSelect: 'none',
},
})}
>
{(() => {
if (!connected) {
return (
<button className="connect-wallet flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none" onClick={openConnectModal} type="button">
Connect Wallet
</button>
);
}

if (chain.unsupported) {
return (
<button onClick={openChainModal} type="button">
Wrong network
</button>
);
}

return (
<div style={{ display: 'flex', gap: 12 }}>
<button
onClick={openChainModal}
style={{ display: 'flex', alignItems: 'center' }}
type="button"
>
{chain.hasIcon && (
<div
style={{
background: chain.iconBackground,
width: 12,
height: 12,
borderRadius: 999,
overflow: 'hidden',
marginRight: 4,
}}
>
{chain.iconUrl && (
<img
alt={chain.name ?? 'Chain icon'}
src={chain.iconUrl}
style={{ width: 12, height: 12 }}
/>
)}
</div>
)}
{chain.name}
</button>

<button onClick={openAccountModal} type="button">
{account.displayName}
{account.displayBalance
? ` (${account.displayBalance})`
: ''}
</button>
</div>
);
})()}
</div>
);
}}
</ConnectButton.Custom>
);
};

export default ConnectWallet;
38 changes: 38 additions & 0 deletions example/webauthn-relay-test/app/passkey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ export const PasskeyRegister = async (formData: FormData) => {
}
};

export const PasskeyRegisterByEOA = async (eoaAddress: string) => {
let user = await generateRegPasskeyPublicKeyV2("eoa", eoaAddress);
if (user != null) {
return "User already exists"; // TODO: Handle errors with useFormStatus
} else {
alert("signup success");
}
};

const generateRegPasskeyPublicKeyV2 = async (type: string, account: string) => {
const origin = window.location.origin;
const resp = await api.post(API.PASSKEY_REG_BY_ACCOUNT, {
type,
account,
origin,
});
const json = resp.data.data as PublicKeyCredentialCreationOptionsJSON;
if (json !== null) {
const attest = await startRegistration(json);
const verifyResp = await api.post(
API.PASSKEY_REG_VERIFY_BY_ACCOUNT +
"?origin=" +
encodeURIComponent(origin) +
"&account=" +
account +
"&network=optimism-sepolia",
attest
);
const signInRlt = verifyResp.status === 200 && verifyResp.data.code === 200;
if (signInRlt) {
if (verifyResp.data.token) {
localStorage.setItem("token", verifyResp.data.token!);
}
}
}
};


const generateRegPasskeyPublicKey = async (email: string) => {
const origin = window.location.origin;
const resp = await api.post(API.PASSKEY_REG, {
Expand Down
145 changes: 87 additions & 58 deletions example/webauthn-relay-test/app/payment/payform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,80 @@ import API from "../api/api";
import api from "../api";

export function PayForm({
action,
children,
}: {
action: any;
children: React.ReactNode;
}) {
const [networks, setNetworks] = useState<{id: string; name: string}[]>([]);
const [selectedNetwork, setSelectedNetwork] = useState<string>('');

useEffect(() => {
api.get(
API.SUPPORT_NETWORKS,
).then(response => {
const data: { [key: string]: boolean } = response.data.data;
const networksArray = Object.keys(data)
action,
children,
}: {
action: any;
children: React.ReactNode;
}) {
const [networks, setNetworks] = useState<{ id: string; name: string }[]>([]);
const [selectedNetwork, setSelectedNetwork] = useState<string>('');

useEffect(() => {
api.get(API.SUPPORT_NETWORKS).then(response => {
const data: { [key: string]: boolean } = response.data.data;
const networksArray = Object.keys(data)
.filter(key => data[key] === true).map(key => ({
id: key,
name: key,
}));
setNetworks(networksArray);
})
}, []);
setNetworks(networksArray);
setSelectedNetwork(networksArray[0].id);
})
}, []);

const handleNetworkChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedNetwork(event.target.value);
};

return (
<form
action={action}
className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16"
>
<div>
<label
htmlFor="txdata"
className="block text-xs text-gray-600 uppercase"
>
TxData
</label>
<input
id="txdata"
name="txdata"
type="txdata"
value="48656c6c6f2c20576f726c6421"
placeholder="Hashed UserOp"
required
className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
/>
<label
htmlFor="network"
className="block text-xs text-gray-600 uppercase mt-4"
>
Network
</label>
const handleNetworkChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedNetwork(event.target.value);
};

const handleAddNetwork = async () => {
if (!selectedNetwork) return;
try {
const response = await api.post(
API.CREATE_AA,
{
network: selectedNetwork
},
{
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
},
}
);
alert("create aa success");
} catch (error) {
console.error('Error adding network:', error);
}
};

return (
<form
action={action}
className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16"
>
<div>
<label
htmlFor="txdata"
className="block text-xs text-gray-600 uppercase"
>
TxData
</label>
<input
id="txdata"
name="txdata"
type="txdata"
value="48656c6c6f2c20576f726c6421"
placeholder="Hashed UserOp"
required
className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
/>
<label
htmlFor="network"
className="block text-xs text-gray-600 uppercase mt-4"
>
Network
</label>
<div className="flex gap-2">
<select
value={selectedNetwork}
onChange={handleNetworkChange}
Expand All @@ -66,14 +86,23 @@ export function PayForm({
className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
>
{networks.map(network => (
<option key={network.id} value={network.id}>
{network.name}
</option>
))}
<option key={network.id} value={network.id}>
{network.name}
</option>
))}
</select>
<button
type="button"
onClick={handleAddNetwork}
className="mt-1 inline-flex items-center justify-center rounded-md border border-gray-300 px-3 py-2 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2"
>
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" clipRule="evenodd" />
</svg>
</button>
</div>
{children}
</form>
);
}
</div>
{children}
</form>
);
}
Loading

0 comments on commit 29b46fe

Please sign in to comment.