-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: change claim to add * feat: added documentation to package * feat: change claim to add * feat: claim to accept * feat: types * chore(release): publish - project: create-justaname-app 0.3.0 - project: @justaname.id/react 0.3.0 - project: @justaname.id/sdk 0.2.0 * feat: signature on connect * chore(release): publish - project: create-justaname-app 0.3.1 - project: @justaname.id/react 0.3.1 - project: @justaname.id/sdk 0.2.1 * chore(release): publish - project: create-justaname-app 0.3.2 - project: @justaname.id/react 0.3.2 - project: @justaname.id/sdk 0.2.2 * chore(release): publish - project: create-justaname-app 0.3.3 - project: @justaname.id/react 0.3.3 - project: @justaname.id/sdk 0.2.3 * fix react provider * chore(release): publish - project: @justaname.id/react 0.3.4 * fix version * chore(release): publish - project: @justaname.id/react 0.3.5 * chore(release): publish - project: @justaname.id/react 0.3.6 * chore(release): publish - project: @justaname.id/react 0.3.7 * chore(release): publish - project: @justaname.id/react 0.3.8 * fix merge conflict --------- Co-authored-by: AngeloAyranji <[email protected]>
- Loading branch information
1 parent
85830e3
commit f065b33
Showing
117 changed files
with
4,704 additions
and
3,150 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
JUSTANAME_API_KEY=your_api_key | ||
JUSTANAME_CHAIN_ID=your_chain_id | ||
JUSTANAME_DOMAIN=your-ens-domain.eth | ||
JUSTANAME_ORIGIN=yoursite.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": ["../../.eslintrc.base.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": { | ||
"@typescript-eslint/no-empty-interface": "off" | ||
} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'justaname-express-trial', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/apps/express-trial', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "justaname-express-trial", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/express-trial/src", | ||
"projectType": "application", | ||
"targets": { | ||
"serve": { | ||
"executor": "@nx/js:node", | ||
"defaultConfiguration": "development", | ||
"options": { | ||
"buildTarget": "justaname-express-trial:build" | ||
}, | ||
"configurations": { | ||
"development": { | ||
"buildTarget": "justaname-express-trial:build:development" | ||
}, | ||
"production": { | ||
"buildTarget": "justaname-express-trial:build:production" | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import express, { Request } from 'express'; | ||
import cors from 'cors'; | ||
import { JustaName, SubnameUpdateRequest } from '@justaname.id/sdk'; | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config(); | ||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.use(express.json()); | ||
|
||
interface RequestChallenge { | ||
address: string; | ||
} | ||
|
||
interface SubnameAdd { | ||
username: string; | ||
address: string; | ||
signature: string; | ||
message: string; | ||
} | ||
|
||
const chainId = parseInt(process.env.JUSTANAME_CHAIN_ID as string); | ||
const domain = process.env.JUSTANAME_DOMAIN as string; | ||
const origin = process.env.JUSTANAME_ORIGIN as string; | ||
const apiKey = process.env.JUSTANAME_API_KEY as string; | ||
|
||
if(!origin) { | ||
throw new Error('Origin is required'); | ||
} | ||
|
||
if(!chainId) { | ||
throw new Error('ChainId is required'); | ||
} | ||
|
||
if(chainId !== 1 && chainId !== 11155111) { | ||
throw new Error('ChainId is not supported'); | ||
} | ||
|
||
if (!domain) { | ||
throw new Error('Domain is required'); | ||
} | ||
|
||
if (!apiKey) { | ||
throw new Error('API Key is required'); | ||
} | ||
|
||
let justaname: JustaName; | ||
|
||
app.get('/api/request-challenge', async (req: Request<NonNullable<unknown>, NonNullable<unknown>, NonNullable<unknown>,RequestChallenge>, res) => { | ||
|
||
const address = req.query.address | ||
|
||
if(!address) { | ||
res.status(400).send({ message: 'Address is required' }); | ||
return; | ||
} | ||
|
||
const minutes = 30; | ||
try { | ||
const challenge = await justaname.siwe.requestChallenge({ | ||
// 30mins | ||
ttl:minutes * 60 * 1000, | ||
chainId, | ||
origin, | ||
address, | ||
domain, | ||
}); | ||
|
||
res.status(200).send(challenge); | ||
return; | ||
} | ||
catch (error) { | ||
if(error instanceof Error) | ||
res.status(500).send({ error: error.message }); | ||
} | ||
}); | ||
|
||
app.post('/api/subnames/add', async (req: Request<SubnameAdd>, res) => { | ||
const username = req.body.username; | ||
|
||
if(!username) { | ||
res.status(400).send({ message: 'Username is required' }); | ||
return; | ||
} | ||
|
||
if(!req.body.address || !req.body.signature || !req.body.message) { | ||
res.status(400).send({ message: 'Address, signature and message are required' }); | ||
return; | ||
} | ||
|
||
try { | ||
const add = await justaname.subnames.addSubname({ | ||
username: username, | ||
ensDomain: domain, | ||
chainId: chainId | ||
}, | ||
{ | ||
xSignature: req.body.signature, | ||
xAddress: req.body.address, | ||
xMessage: req.body.message | ||
}); | ||
|
||
res.status(201).send(add); | ||
return; | ||
} | ||
catch (error) { | ||
if(error instanceof Error) | ||
res.status(500).send({ error: error.message }); | ||
} | ||
}); | ||
|
||
export interface SubnameUpdate extends Omit<SubnameUpdateRequest, 'ensDomain' | 'chainId'> { | ||
address: string; | ||
signature: string; | ||
message: string; | ||
} | ||
|
||
app.post('/api/subnames/update', async (req: Request<SubnameUpdate>, res) => { | ||
|
||
const username = req.body.username; | ||
const addresses = req.body.addresses; | ||
const text = req.body.text; | ||
const contentHash = req.body.contentHash; | ||
const signature = req.body.signature; | ||
const address = req.body.address; | ||
const message = req.body.message; | ||
|
||
if(!username) { | ||
res.status(400).send({ message: 'Username is required' }); | ||
return; | ||
} | ||
|
||
if(!addresses) { | ||
res.status(400).send({ message: 'Addresses are required' }); | ||
return; | ||
} | ||
|
||
if(!text) { | ||
res.status(400).send({ message: 'Text records are required' }); | ||
return; | ||
} | ||
|
||
if(!contentHash && contentHash !== '') { | ||
res.status(400).send({ message: 'Content hash is required' }); | ||
return; | ||
} | ||
|
||
if(!req.body.address || !req.body.signature || !req.body.message) { | ||
res.status(400).send({ message: 'Address, signature and message are required' }); | ||
return; | ||
} | ||
|
||
|
||
try { | ||
const add = await justaname.subnames.updateSubname({ | ||
username: username, | ||
ensDomain: domain, | ||
chainId: chainId, | ||
addresses, | ||
text, | ||
contentHash | ||
}, | ||
{ | ||
xSignature: signature, | ||
xAddress: address, | ||
xMessage: message | ||
}); | ||
|
||
res.status(201).send(add); | ||
return; | ||
} | ||
catch (error) { | ||
if(error instanceof Error) | ||
res.status(500).send({ error: error.message }); | ||
} | ||
}) | ||
|
||
app.get('/api', (req, res) => { | ||
res.send({ message: 'Welcome to JustaName Express!' }); | ||
}); | ||
|
||
const port = process.env.PORT || 3333; | ||
const server = app.listen(port, async () => { | ||
justaname = await JustaName.init({ | ||
apiKey: process.env.JUSTANAME_API_KEY as string, | ||
}); | ||
|
||
|
||
console.log(`Listening at http://localhost:${port}/api`); | ||
}); | ||
|
||
server.on('error', console.error); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["node", "express"], | ||
"paths": { | ||
"@justaname.id/sdk": ["packages/@justaname.id/sdk/dist"] | ||
} | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { NxWebpackPlugin } = require('@nx/webpack'); | ||
const { join } = require('path'); | ||
|
||
module.exports = { | ||
output: { | ||
path: join(__dirname, '../../dist/apps/express-trial'), | ||
}, | ||
plugins: [ | ||
new NxWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'tsc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: false, | ||
outputHashing: 'none', | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["plugin:@nx/react", "../../.eslintrc.base.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>JustanameReactTrial</title> | ||
<base href="/" /> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" type="image/x-icon" href="/favicon.ico" /> | ||
<link rel="stylesheet" href="/src/styles.css" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.