From 326caf949ec8622c04b0e3352c5eac5370f161e4 Mon Sep 17 00:00:00 2001 From: Pawel Zelawski Date: Thu, 10 Apr 2025 10:50:57 +0200 Subject: feat(server): implement basic backend API - Added basic Express server setup in `src/server/main.ts`. - Configured `dotenv` to load environment variables. - Implemented in-memory storage for session state (pending, success, failed). - Created `/api/digiid/start` endpoint: - Generates session ID and nonce. - Constructs callback URL from `PUBLIC_URL`. - Determines `unsecure` flag based on URL scheme. - Stores initial session state. - Generates QR code data URL. - Returns `sessionId` and `qrCodeDataUrl`. - Includes placeholder for `digiidTs.generateDigiIDUri`. - Created `/api/digiid/callback` endpoint: - Receives address, uri, signature from DigiID app. - Parses nonce from received URI. - Looks up session by nonce. - Reconstructs expected callback URL. - Updates session state based on placeholder verification. - Includes placeholder for `digiidTs.verifyDigiIDCallback`. - Responds 200 OK as per DigiID protocol. - Created `/api/digiid/status/:sessionId` endpoint: - Retrieves and returns session status, address, and error. - Added address type helper `getDigiByteAddressType` in `src/server/utils.ts` (with placeholder logic for DGA). - Added `dev:backend` script to `package.json` using `nodemon` and `ts-node/esm`. - Added `"type": "module"` to `package.json`. - Installed `@types/dotenv`. - (Note: Outstanding TypeScript linter errors related to async Express handlers require further investigation). --- src/server/utils.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/server/utils.ts (limited to 'src/server/utils.ts') diff --git a/src/server/utils.ts b/src/server/utils.ts new file mode 100644 index 0000000..0b1333f --- /dev/null +++ b/src/server/utils.ts @@ -0,0 +1,20 @@ +// Simple utility to determine DigiByte address type based on prefix + +export type DigiByteAddressType = 'DigiByte (DGB)' | 'DigiAsset (DGA)' | 'Unknown'; + +export function getDigiByteAddressType(address: string): DigiByteAddressType { + if (address.startsWith('dgb1')) { + return 'DigiByte (DGB)'; + } + // Add other prefixes if DigiAssets use a distinct one, e.g., 'dga1' + // For now, assume non-DGB is DigiAsset, but this might need refinement + // depending on actual DigiAsset address formats. + // If the digiid-ts library provides a helper for this, use that instead. + else if (address) { // Basic check to differentiate from empty/null + // Assuming DigiAssets might start differently or be the fallback + // This is a placeholder assumption. + // A more robust check based on DigiAsset address specification is needed. + return 'DigiAsset (DGA)'; // Placeholder - ADJUST BASED ON ACTUAL DGA PREFIX + } + return 'Unknown'; +} \ No newline at end of file -- cgit v1.2.3