summaryrefslogtreecommitdiff
path: root/src/server/utils.ts
diff options
context:
space:
mode:
authorPawel Zelawski <pawel.zelawski@outlook.com>2025-04-10 10:50:57 +0200
committerPawel Zelawski <pawel.zelawski@outlook.com>2025-04-10 10:50:57 +0200
commit326caf949ec8622c04b0e3352c5eac5370f161e4 (patch)
tree5b4d1dbeeb693e25dce770e393645a60f1e409a9 /src/server/utils.ts
parentef435a15ca67c829ce6cd8551ac45c419cb9792e (diff)
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).
Diffstat (limited to 'src/server/utils.ts')
-rw-r--r--src/server/utils.ts20
1 files changed, 20 insertions, 0 deletions
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