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

Minor review/arc31 #5

Draft
wants to merge 33 commits into
base: arc-0031
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b4c3dce
WIP minor changes
deanstef Feb 13, 2024
7f67abd
must assumptions
deanstef Feb 14, 2024
ea432f9
auth mech section
deanstef Feb 14, 2024
fd00b7a
updates
deanstef Feb 15, 2024
227a69a
minor edits
deanstef Feb 16, 2024
9a4006a
rekey auth
deanstef Feb 16, 2024
1b170ce
CR arc31
deanstef Feb 16, 2024
0fae190
nit
deanstef Feb 16, 2024
d094b24
nit2
deanstef Feb 16, 2024
f6a4165
nit abstract
deanstef Feb 16, 2024
cb5e901
nits
deanstef Feb 16, 2024
6efd121
typo
deanstef Feb 16, 2024
b4b2337
more nits
deanstef Feb 16, 2024
93449eb
more nits 2
deanstef Feb 16, 2024
0c52b2c
structure nits
deanstef Feb 16, 2024
775ebe0
more nits
deanstef Feb 16, 2024
8c8ad65
final nits
deanstef Feb 16, 2024
bfb2108
ref impl update
deanstef Feb 18, 2024
9fea035
CR
deanstef Feb 19, 2024
0243075
Refactor as monorepo
mrcointreau Feb 19, 2024
8e81a9e
Merge pull request #3 from deanstef/update/arc31-ref
deanstef Feb 20, 2024
9f6b705
Align with latest protocol updates
mrcointreau Feb 20, 2024
1286cf3
Merge branch 'minor-review/arc31' into monorepo
mrcointreau Feb 20, 2024
d7921dc
Restore hardcoded values for env.client.algorandChainId in the useEnv…
mrcointreau Feb 21, 2024
057fa7a
Fix User interface
mrcointreau Feb 21, 2024
a803750
Fix Dockerfile paths
mrcointreau Feb 21, 2024
54cd767
Merge pull request #4 from deanstef/monorepo
deanstef Feb 21, 2024
17ccf92
Refactor eslint/rollup/typescript configs
mrcointreau Feb 21, 2024
601b296
Clear session cookie when wallet connect session is expired
mrcointreau Feb 21, 2024
b5c89da
Add @mrcointreau/eslint-config-typescript dev dependency
mrcointreau Feb 21, 2024
9849d36
Merge branch 'eslint-rollup-typescript-refactoring' into bugfix/sessi…
mrcointreau Feb 21, 2024
00b0076
Merge pull request #7 from deanstef/bugfix/session-cookie
deanstef Feb 22, 2024
607f1e3
Merge pull request #6 from deanstef/eslint-rollup-typescript-refactoring
mrcointreau Feb 22, 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
345 changes: 186 additions & 159 deletions ARCs/arc-0031.md

Large diffs are not rendered by default.

File renamed without changes.
10 changes: 10 additions & 0 deletions assets/arc-0031/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions assets/arc-0031/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
extends: ['@mrcointreau/eslint-config-typescript'],
parserOptions: {
project: ['./tsconfig.eslint.json']
},
ignorePatterns: [
'*.min.*',
'*.d.ts',
'dist',
'package-lock.json'
]
}
24 changes: 18 additions & 6 deletions assets/arc-0031/.gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
# Logs
logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
# node_modules
node_modules/

# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist
dist-ssr
coverage

# Misc files and directories
.DS_Store
.fleet
.idea
*.local

# Local environment files
.env
.env.*.
.env.*
!.env.example

# Editor directories and files
Expand Down
6 changes: 4 additions & 2 deletions assets/arc-0031/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The example shows the entire workflow of authentication using a standalone Algor

## User registration

Add registered users to the `server/mock/users.db.json` array. The `nonce` field must be left empty `''`.
Add registered users to the `server/mock/users.db.ts` array. The `challenge` field must be left empty `''`.

## Run via Docker Compose

Expand All @@ -27,7 +27,7 @@ Visit `localhost`
- `node.js`
- `npm`

From both `client`and `server` folders run
From the root folder run:

```
cp .env.example .env
Expand All @@ -36,3 +36,5 @@ npm run dev
```

Visit `localhost:3001`

> Reference implementation credits: [deanstef](https://github.com/deanstef) and [mrcointreau](https://github.com/mrcointreau)
5 changes: 4 additions & 1 deletion assets/arc-0031/client/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"rules": {
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/indent": ["error", 2]
"@typescript-eslint/indent": [
"error",
2
]
},
"overrides": [
{
Expand Down
33 changes: 0 additions & 33 deletions assets/arc-0031/client/.gitignore

This file was deleted.

14 changes: 9 additions & 5 deletions assets/arc-0031/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM node:20-slim AS base
WORKDIR /client
FROM node:20-alpine AS base
WORKDIR /arc31

FROM base AS build
COPY package*.json ./
RUN npm ci && npm cache clean --force
COPY tsconfig.json ./
COPY packages/arc31/package*.json ./packages/arc31/
COPY client/package*.json ./client/
COPY client/tsconfig.json ./client/
RUN npm ci
COPY . .
RUN npm run build
RUN npm run build --workspace=arc31 && npm run build --workspace=client

FROM base AS production
COPY --from=build /client/.output /client/.output
COPY --from=build /arc31/client/.output ./.output
EXPOSE 3000
ENTRYPOINT ["node", ".output/server/index.mjs"]
42 changes: 0 additions & 42 deletions assets/arc-0031/client/README.md

This file was deleted.

9 changes: 8 additions & 1 deletion assets/arc-0031/client/app.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<script setup lang="ts">
import { useSessionCookie } from './utils/hooks/useSessionCookie'

import { usePeraWallet } from '@/utils/hooks/usePeraWallet'

if (import.meta.client) {
const { reconnectWallet } = usePeraWallet()
await reconnectWallet()
const sessionCookie = useSessionCookie()
const address = await reconnectWallet()
if (sessionCookie.session.value && !address?.value) {
sessionCookie.clear()
window.location.reload()
}
}

useHead({
Expand Down
4 changes: 2 additions & 2 deletions assets/arc-0031/client/middleware/guard.global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Session } from '@/utils/hooks/useAuth'
import { useSessionCookie } from '@/utils/hooks/useSessionCookie'

export default defineNuxtRouteMiddleware((to) => {
if (import.meta.server) {
const session = useCookie<Session>('session')
const { session } = useSessionCookie()
if (!session.value && to.path !== '/signin') {
return '/signin'
}
Expand Down
3 changes: 2 additions & 1 deletion assets/arc-0031/client/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
// @ts-ignore
telemetry: false,
modules: ['@nuxt/ui'],
modulesDir: ['../node_modules'],
runtimeConfig: {
apiUrl: process.env.NUXT_API_URL,
public: {
Expand Down
18 changes: 7 additions & 11 deletions assets/arc-0031/client/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
{
"name": "arc-0031-client",
"version": "0.0.1",
"type": "module",
"author": "Luca Martini",
"license": "UNLICENSED",
"version": "0.0.1",
"author": "[deanstef](https://github.com/deanstef) and [mrcointreau](https://github.com/mrcointreau)",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"lint": "tsc --noEmit && eslint .",
"lint:fix": "tsc --noEmit && eslint . --fix"
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@msgpack/msgpack": "2.8.0",
"dependencies": {
"@nuxt/ui": "2.13.0",
"@nuxtjs/eslint-config-typescript": "12.1.0",
"@perawallet/connect": "1.3.4",
"eslint": "8.56.0",
"arc31": "0.0.1",
"normalize.css": "8.0.1",
"nuxt": "3.10.1",
"vue": "3.4.15",
"nuxt": "3.10.2",
"vue": "3.4.19",
"vue-router": "4.2.5",
"zod": "3.22.4"
}
Expand Down
4 changes: 2 additions & 2 deletions assets/arc-0031/client/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAuth } from '@/utils/hooks/useAuth'

useHead({ title: 'Home' })

const { address, signOut } = useAuth()
const { session, signOut } = useAuth()
</script>

<template>
Expand All @@ -12,7 +12,7 @@ const { address, signOut } = useAuth()
<div>
<p>www.servicedomain.com</p>
<p class="text-primary break-all">
{{ address }}
{{ session?.authAcc }}
</p>
</div>
<UButton
Expand Down
5 changes: 3 additions & 2 deletions assets/arc-0031/client/plugins/peraWalletClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PeraWalletConnect } from '@perawallet/connect'

import { useEnv } from '@/utils/hooks/useEnv'

enum AlgorandChainId {
Expand All @@ -6,8 +8,7 @@ enum AlgorandChainId {
BetaNet = 416003
}

export default defineNuxtPlugin(async () => {
const { PeraWalletConnect } = await import('@perawallet/connect')
export default defineNuxtPlugin(() => {
const env = useEnv()
const peraWalletClient = new PeraWalletConnect({ chainId: AlgorandChainId[env.client.algorandChainId] })

Expand Down
7 changes: 5 additions & 2 deletions assets/arc-0031/client/utils/Arc31ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AlgorandChainId } from 'arc31'

import type { Session } from '@/utils/hooks/useAuth'

export class Arc31ApiClient {
Expand All @@ -7,10 +9,11 @@ export class Arc31ApiClient {
this.apiFetch = $fetch.create({ baseURL })
}

public request = (authAcc: string) => this.apiFetch<string>('/signin/request', {
public request = (authAcc: string, chainId: AlgorandChainId) => this.apiFetch<string>('/signin/request', {
method: 'POST',
body: {
authAcc
authAcc,
chainId
}
})

Expand Down
Loading
Loading