-
Notifications
You must be signed in to change notification settings - Fork 0
TmpCommit #31
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
TmpCommit #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,29 @@ | ||||||
| const express = require('express'); | ||||||
| import express from 'express'; | ||||||
| const router = express.Router(); | ||||||
| const jwt = require("jsonwebtoken"); | ||||||
| const cookieParser = require("cookie-parser"); | ||||||
| const dotenv = require("dotenv"); | ||||||
| const path = require("path"); | ||||||
| const multer = require("multer"); | ||||||
| const fs = require("fs"); | ||||||
| const VCM = require('../Tools/VerifyCookieMiddleware'); | ||||||
| const DBPerf = require('../Tools/DBPerf'); | ||||||
| import jwt from 'jsonwebtoken'; | ||||||
| import cookieParser from 'cookie-parser'; | ||||||
| import dotenv from 'dotenv'; | ||||||
| import path from 'path'; | ||||||
| import multer from 'multer'; | ||||||
| import fs from 'fs'; | ||||||
| import { fileURLToPath } from 'url'; | ||||||
| import VCM from '../Tools/VerifyCookieMiddleware.js'; | ||||||
| import DBPerf from '../Tools/DBPerf.js'; | ||||||
| import CreateMosaic from '../Tools/CreateMosaicTx.js'; | ||||||
| import { decrypt } from '../Tools/AESControl.js'; | ||||||
|
|
||||||
| // DB から取得した encryptedPrivateKey を復号 | ||||||
| const decryptedPrivateKey = decrypt(passwordWithPepper, encryptedPrivateKey); | ||||||
|
|
||||||
| // mosaic 作成時に渡す | ||||||
| const { mosaicId, mosaicDefinitionTx } = CreateMosaicTx({ | ||||||
| senderPrivateKey: decryptedPrivateKey, | ||||||
| networkType: 'testnet' | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| const __filename = fileURLToPath(import.meta.url); | ||||||
| const __dirname = path.dirname(__filename); | ||||||
|
|
||||||
| // cookieを使う | ||||||
| router.use(cookieParser()); | ||||||
|
|
@@ -42,30 +58,49 @@ function createFileName(originalName) { | |||||
|
|
||||||
|
|
||||||
| // ===ルーム作成API=== | ||||||
| router.post("/", VCM('LoginToken', process.env.LOGIN_SECRET), upload.fields([{ name: "RoomIcon", maxCount: 1 },{ name: "TokenIcon", maxCount: 1 }]), async (req, res) => { | ||||||
| router.post("/", VCM('LOGIN_TOKEN', process.env.LOGIN_SECRET), upload.fields([{ name: "RoomIcon", maxCount: 1 },{ name: "MosaicIcon", maxCount: 1 }]), async (req, res) => { | ||||||
|
||||||
| router.post("/", VCM('LOGIN_TOKEN', process.env.LOGIN_SECRET), upload.fields([{ name: "RoomIcon", maxCount: 1 },{ name: "MosaicIcon", maxCount: 1 }]), async (req, res) => { | |
| router.post("/", VCM('LoginToken', process.env.LOGIN_SECRET), upload.fields([{ name: "RoomIcon", maxCount: 1 },{ name: "MosaicIcon", maxCount: 1 }]), async (req, res) => { |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'isAdmin' column was removed from the INSERT statement. If this column exists in the database schema and has no default value, this query will fail.
| "INSERT INTO Rooms(UserID, RoomName) VALUES (?, ?)",[userID, RoomName] | |
| "INSERT INTO Rooms(UserID, RoomName, isAdmin) VALUES (?, ?, ?)", [userID, RoomName, 1] |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table name changed from 'RoomsDetail' to 'RoomsDetails'. Ensure this matches the actual database schema, as inconsistent table names will cause database errors.
| "INSERT INTO RoomsDetails (RoomName, RoomIconPath, MosaicName) VALUES (?, ?, ?)", | |
| "INSERT INTO RoomsDetail (RoomName, RoomIconPath, MosaicName) VALUES (?, ?, ?)", |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The private key is used directly from the database without decryption. Based on the Register.js code, private keys are stored encrypted and should be decrypted using the decrypt function with passwordWithPepper before use.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Register.js | ||
| import express from 'express'; | ||
| import dotenv from 'dotenv'; | ||
| import cookieParser from 'cookie-parser'; | ||
| import argon2 from 'argon2'; | ||
| import DBPerf from '../Tools/DBPerf.js'; | ||
| import { encrypt } from '../Tools/AESControl.js'; | ||
| import { PrivateKey } from 'symbol-sdk'; | ||
| import { SymbolFacade } from 'symbol-sdk/symbol'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname, join } from 'path'; | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| // ES Module で __dirname を使えるようにする | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| // 環境変数読み込み | ||
| dotenv.config({ path: join(__dirname, '..', '.env') }); | ||
|
|
||
| // use系 | ||
| router.use(cookieParser()); | ||
| router.use(express.json()); | ||
|
|
||
| // ========== 画面表示 ========== | ||
| // /Register/へのアクセスでRegister画面表示 | ||
| router.get('/', (req, res) => { | ||
| console.log("/Register-API is running"); | ||
| res.sendFile(join(__dirname, "..", "..", "..", "Frontend", "dist", "index.html")); | ||
| }); | ||
|
|
||
| // ========== 情報送信 ========== | ||
| // /Register/SubmitへのアクセスでRegister情報を登録 | ||
| router.post('/Submit', async (req, res) => { | ||
| console.log("Submit-API is running"); | ||
| try { | ||
| // 情報の取得 | ||
| const { userId, password } = req.body; | ||
|
|
||
| if (!userId || !password) { | ||
| return res.status(400).json({ message: "Bad Request: UserIDかPasswordが不足しています。" }); | ||
| } | ||
|
|
||
| // ユーザーIDが被っていないか確認 | ||
| const exist = await DBPerf( | ||
| "Duplicate Check For UserID", | ||
| "SELECT * FROM Identify WHERE UserID = ?", | ||
| [userId] | ||
| ); | ||
| if (exist.length > 0) { | ||
| return res.status(409).json({ message: "Conflict: このユーザーIDはすでに使われています" }); | ||
| } | ||
|
|
||
| // ========== 秘密鍵保存 ========== | ||
| const privateKeyObject = PrivateKey.random(); | ||
| const privateKey = privateKeyObject.toString(); | ||
| const facade = new SymbolFacade('testnet'); | ||
| const account = facade.createAccount(privateKeyObject); | ||
| const address = account.address.toString(); | ||
|
|
||
| // Pepper を .env から取得 | ||
| const pepper = process.env.PEPPER; | ||
| if (!pepper) { | ||
| return res.status(500).json({ message: "Internal Server Error: サーバー設定エラー" }); | ||
| } | ||
|
|
||
| const passwordWithPepper = password + pepper; | ||
|
|
||
| // 秘密鍵の暗号化 | ||
| const encryptedPrivateKey = encrypt(passwordWithPepper, privateKey); | ||
|
|
||
| // パスワード + Pepper を Hash 化 | ||
| const hashedPassword = await argon2.hash(passwordWithPepper, { | ||
| type: argon2.argon2id, | ||
| memoryCost: 2 ** 16, // 推奨: 64MB | ||
| timeCost: 5, // 計算回数 | ||
| parallelism: 1 // 並列数 | ||
| }); | ||
|
|
||
| // DB に登録 | ||
| await DBPerf( | ||
| "Insert Into Identify", | ||
| "INSERT INTO Identify (UserID, Password, PrivateKey, Address) VALUES (?, ?, ?, ?)", | ||
| [userId, hashedPassword, encryptedPrivateKey, address] | ||
| ); | ||
|
|
||
| res.status(200).json({ redirect: "/Home" }); | ||
| } catch (err) { | ||
| console.error("Register Error:", err); | ||
| res.status(500).json({ message: "Internal Server Error: サーバーエラーが発生しました。" }); | ||
| } | ||
| }); | ||
|
|
||
| export default router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables
passwordWithPepper,encryptedPrivateKey, andCreateMosaicTxare referenced at the module level but are not defined. These lines appear to be code that should be inside the route handler function where the necessary data is available.