@openeudi/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +198 -0
- package/dist/index.cjs +278 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +262 -0
- package/dist/index.d.ts +262 -0
- package/dist/index.js +268 -0
- package/dist/index.js.map +1 -0
- package/dist/qr.cjs +22 -0
- package/dist/qr.cjs.map +1 -0
- package/dist/qr.d.cts +13 -0
- package/dist/qr.d.ts +13 -0
- package/dist/qr.js +20 -0
- package/dist/qr.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/verification.ts","../src/errors.ts","../src/storage/memory.store.ts","../src/modes/demo.mode.ts","../src/modes/mock.mode.ts","../src/verification.service.ts","../src/index.ts"],"names":["VerificationType","VerificationStatus","EventEmitter","uuidv4"],"mappings":";;;;;;AAGO,IAAK,gBAAA,qBAAAA,iBAAAA,KAAL;AAEH,EAAAA,kBAAA,KAAA,CAAA,GAAM,KAAA;AAEN,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,MAAA,CAAA,GAAO,MAAA;AANC,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA;AAYL,IAAK,kBAAA,qBAAAC,mBAAAA,KAAL;AAEH,EAAAA,oBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,oBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,oBAAA,UAAA,CAAA,GAAW,UAAA;AAEX,EAAAA,oBAAA,UAAA,CAAA,GAAW,UAAA;AAEX,EAAAA,oBAAA,SAAA,CAAA,GAAU,SAAA;AAVF,EAAA,OAAAA,mBAAAA;AAAA,CAAA,EAAA,kBAAA,IAAA,EAAA;;;ACZL,IAAM,oBAAA,GAAN,cAAmC,KAAA,CAAM;AAAA,EAC5C,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A,CAAM,MAAA,CAAO,EAAE,CAAA;AAC1B,QAAA,IAAA,CAAK,UAAA,CAAW,OAAO,EAAE,CAAA;AACzB,QAAA,IAAA,CAAK,IAAA,CAAK,mBAAmB,OAAO,CAAA;AACpC,QAAA,KAAA,EAAA;AAAA,MACJ;AAAA,IACJ;AAEA,IAAA,OAAO,KAAA;AAAA,EACX;AAAA,EAEA,MAAc,eAAA,CAAgB,OAAA,EAA8B,MAAA,EAA2C;AACnG,IAAA,MAAM,SAAS,MAAA,CAAO,QAAA,GAAA,UAAA,kBAAA,UAAA;AACtB,IAAA,MAAM,OAAA,GAA+B;AAAA,MACjC,GAAG,OAAA;AAAA,MACH,MAAA;AAAA,MACA,WAAA,sBAAiB,IAAA,EAAK;AAAA,MACtB;AAAA,KACJ;AAEA,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,OAAO,CAAA;AAE5B,IAAA,IAAI,OAAO,QAAA,EAAU;AACjB,MAAA,IAAA,CAAK,IAAA,CAAK,kBAAA,EAAoB,OAAA,EAAS,MAAM,CAAA;AAAA,IACjD,CAAA,MAAO;AACH,MAAA,IAAA,CAAK,IAAA,CAAK,kBAAA,EAAoB,OAAA,EAAS,MAAA,CAAO,eAAe,CAAA;AAAA,IACjE;AAAA,EACJ;AACJ;;;AChKO,IAAM,OAAA,GAAU","file":"index.cjs","sourcesContent":["/**\n * Type of verification to perform\n */\nexport enum VerificationType {\n /** Verify age (over_18 attribute) */\n AGE = 'AGE',\n /** Verify country of residence */\n COUNTRY = 'COUNTRY',\n /** Verify both age and country */\n BOTH = 'BOTH',\n}\n\n/**\n * Status of a verification session\n */\nexport enum VerificationStatus {\n /** Session created, waiting for wallet scan */\n PENDING = 'PENDING',\n /** QR code scanned, credential exchange in progress */\n SCANNED = 'SCANNED',\n /** Verification completed successfully */\n VERIFIED = 'VERIFIED',\n /** Verification rejected (age, country, or policy) */\n REJECTED = 'REJECTED',\n /** Session expired before completion */\n EXPIRED = 'EXPIRED',\n}\n","/**\n * Thrown when a session ID is not found in the store\n */\nexport class SessionNotFoundError extends Error {\n constructor(sessionId: string) {\n super(`Session not found: ${sessionId}`);\n this.name = 'SessionNotFoundError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Thrown when an operation is attempted on an expired session\n */\nexport class SessionExpiredError extends Error {\n constructor(sessionId: string) {\n super(`Session expired: ${sessionId}`);\n this.name = 'SessionExpiredError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import type { VerificationSession } from '../types/session.js';\n\nimport type { ISessionStore } from './store.interface.js';\n\n/**\n * In-memory session store using a Map.\n * Suitable for development, testing, and single-process deployments.\n * Sessions are lost on process restart.\n */\nexport class InMemorySessionStore implements ISessionStore {\n private sessions = new Map<string, VerificationSession>();\n\n async get(id: string): Promise<VerificationSession | null> {\n return this.sessions.get(id) ?? null;\n }\n\n async set(session: VerificationSession): Promise<void> {\n this.sessions.set(session.id, session);\n }\n\n async delete(id: string): Promise<void> {\n this.sessions.delete(id);\n }\n}\n","import type { VerificationSession, VerificationResult } from '../types/session.js';\nimport { VerificationType } from '../types/verification.js';\n\nimport type { IVerificationMode } from './mode.interface.js';\n\nconst EU_COUNTRIES = [\n 'AT',\n 'BE',\n 'BG',\n 'HR',\n 'CY',\n 'CZ',\n 'DK',\n 'EE',\n 'FI',\n 'FR',\n 'DE',\n 'GR',\n 'HU',\n 'IE',\n 'IT',\n 'LV',\n 'LT',\n 'LU',\n 'MT',\n 'NL',\n 'PL',\n 'PT',\n 'RO',\n 'SK',\n 'SI',\n 'ES',\n 'SE',\n];\n\nexport interface DemoModeConfig {\n /** Delay in ms before auto-completion (default: 3000) */\n delayMs?: number;\n}\n\n/**\n * Demo mode — auto-completes verification with randomized EU data.\n * Used for product demos and landing page previews.\n */\nexport class DemoMode implements IVerificationMode {\n readonly name = 'demo';\n private delayMs: number;\n\n constructor(config: DemoModeConfig = {}) {\n this.delayMs = config.delayMs ?? 3000;\n }\n\n async processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult> {\n const country = this.pickCountry(session.countryWhitelist);\n return this.buildResult(session.type, country);\n }\n\n async simulateCompletion(session: VerificationSession): Promise<VerificationResult> {\n await new Promise((resolve) => setTimeout(resolve, this.delayMs));\n return this.processCallback(session, {});\n }\n\n private pickCountry(whitelist?: string[]): string {\n const pool = whitelist && whitelist.length > 0 ? whitelist : EU_COUNTRIES;\n return pool[Math.floor(Math.random() * pool.length)];\n }\n\n private buildResult(type: VerificationType, country: string): VerificationResult {\n const includeAge = type === VerificationType.AGE || type === VerificationType.BOTH;\n const includeCountry = type === VerificationType.COUNTRY || type === VerificationType.BOTH;\n\n return {\n verified: true,\n country,\n ageVerified: includeAge ? true : undefined,\n countryVerified: includeCountry ? true : undefined,\n };\n }\n}\n","import type { VerificationSession, VerificationResult } from '../types/session.js';\n\nimport type { IVerificationMode } from './mode.interface.js';\n\nexport interface MockModeConfig {\n /** Default result returned for all sessions (default: verified with DE) */\n defaultResult?: VerificationResult;\n /** Delay in ms before returning result (default: 0) */\n delayMs?: number;\n}\n\nconst DEFAULT_RESULT: VerificationResult = {\n verified: true,\n country: 'DE',\n ageVerified: true,\n countryVerified: true,\n};\n\n/**\n * Mock mode — configurable responses for integration testing.\n * Supports global defaults and per-session overrides.\n */\nexport class MockMode implements IVerificationMode {\n readonly name = 'mock';\n private defaultResult: VerificationResult;\n private delayMs: number;\n private sessionOverrides = new Map<string, VerificationResult>();\n\n constructor(config: MockModeConfig = {}) {\n this.defaultResult = config.defaultResult ?? { ...DEFAULT_RESULT };\n this.delayMs = config.delayMs ?? 0;\n }\n\n /** Set a per-session result override */\n setSessionResult(sessionId: string, result: VerificationResult): void {\n this.sessionOverrides.set(sessionId, result);\n }\n\n /** Clear a per-session result override */\n clearSessionResult(sessionId: string): void {\n this.sessionOverrides.delete(sessionId);\n }\n\n async processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult> {\n if (this.delayMs > 0) {\n await new Promise((resolve) => setTimeout(resolve, this.delayMs));\n }\n return this.sessionOverrides.get(session.id) ?? { ...this.defaultResult };\n }\n\n async simulateCompletion(session: VerificationSession): Promise<VerificationResult> {\n return this.processCallback(session, {});\n }\n}\n","import { EventEmitter } from 'node:events';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { SessionNotFoundError, SessionExpiredError } from './errors.js';\nimport type { IVerificationMode } from './modes/mode.interface.js';\nimport { InMemorySessionStore } from './storage/memory.store.js';\nimport type { ISessionStore } from './storage/store.interface.js';\nimport type { VerificationServiceConfig } from './types/config.js';\nimport type { VerificationSession, VerificationResult, CreateSessionInput } from './types/session.js';\nimport { VerificationStatus } from './types/verification.js';\n\nconst DEFAULT_TTL_MS = 300_000; // 5 minutes\nconst DEFAULT_WALLET_BASE_URL = 'openid4vp://verify';\n\n/**\n * EUDI Wallet verification session orchestrator.\n *\n * Manages the lifecycle of verification sessions: creation, status tracking,\n * wallet callback handling, expiration, and event emission.\n *\n * Transport-agnostic — consumers wire events to SSE, WebSocket, polling, etc.\n */\nexport class VerificationService extends EventEmitter {\n private store: ISessionStore;\n private mode: IVerificationMode;\n private sessionTtlMs: number;\n private walletBaseUrl: string;\n /** Track session IDs for cleanup (store interface has no list method) */\n private sessionIds = new Set<string>();\n\n constructor(config: VerificationServiceConfig) {\n super();\n this.mode = config.mode;\n this.store = config.store ?? new InMemorySessionStore();\n this.sessionTtlMs = config.sessionTtlMs ?? DEFAULT_TTL_MS;\n this.walletBaseUrl = config.walletBaseUrl ?? DEFAULT_WALLET_BASE_URL;\n }\n\n /**\n * Create a new verification session\n */\n async createSession(input: CreateSessionInput): Promise<VerificationSession> {\n const id = uuidv4();\n const now = new Date();\n\n const session: VerificationSession = {\n id,\n type: input.type,\n status: VerificationStatus.PENDING,\n walletUrl: '', // set below, may be async from mode\n countryWhitelist: input.countryWhitelist,\n countryBlacklist: input.countryBlacklist,\n redirectUrl: input.redirectUrl,\n metadata: input.metadata,\n createdAt: now,\n expiresAt: new Date(now.getTime() + this.sessionTtlMs),\n };\n\n session.walletUrl = this.mode.buildWalletUrl\n ? await this.mode.buildWalletUrl(id, input)\n : `${this.walletBaseUrl}?session=${id}`;\n\n await this.store.set(session);\n this.sessionIds.add(id);\n this.emit('session:created', session);\n\n // If mode supports auto-completion (DemoMode), trigger it in background\n if (this.mode.simulateCompletion) {\n this.mode\n .simulateCompletion(session)\n .then(async (result) => {\n // Only auto-complete if session is still pending\n const current = await this.store.get(id);\n if (current && current.status === VerificationStatus.PENDING) {\n await this.completeSession(current, result);\n }\n })\n .catch(() => {\n // Ignore simulation errors (session may have been completed manually)\n });\n }\n\n return session;\n }\n\n /**\n * Get a session by ID\n * @throws SessionNotFoundError\n */\n async getSession(id: string): Promise<VerificationSession> {\n const session = await this.store.get(id);\n if (!session) {\n throw new SessionNotFoundError(id);\n }\n return session;\n }\n\n /**\n * Handle a callback from the wallet\n * @throws SessionNotFoundError\n * @throws SessionExpiredError\n */\n async handleCallback(sessionId: string, walletResponse: unknown): Promise<VerificationResult> {\n const session = await this.store.get(sessionId);\n if (!session) {\n throw new SessionNotFoundError(sessionId);\n }\n if (new Date() > session.expiresAt) {\n throw new SessionExpiredError(sessionId);\n }\n\n const result = await this.mode.processCallback(session, walletResponse);\n await this.completeSession(session, result);\n return result;\n }\n\n /**\n * Remove expired sessions from the store\n * @returns Number of sessions cleaned up\n */\n async cleanupExpired(): Promise<number> {\n const now = new Date();\n let count = 0;\n\n for (const id of this.sessionIds) {\n const session = await this.store.get(id);\n if (!session) {\n this.sessionIds.delete(id);\n continue;\n }\n if (now > session.expiresAt && session.status === VerificationStatus.PENDING) {\n const expired = { ...session, status: VerificationStatus.EXPIRED };\n await this.store.set(expired);\n await this.store.delete(id);\n this.sessionIds.delete(id);\n this.emit('session:expired', expired);\n count++;\n }\n }\n\n return count;\n }\n\n private async completeSession(session: VerificationSession, result: VerificationResult): Promise<void> {\n const status = result.verified ? VerificationStatus.VERIFIED : VerificationStatus.REJECTED;\n const updated: VerificationSession = {\n ...session,\n status,\n completedAt: new Date(),\n result,\n };\n\n await this.store.set(updated);\n\n if (result.verified) {\n this.emit('session:verified', updated, result);\n } else {\n this.emit('session:rejected', updated, result.rejectionReason);\n }\n }\n}\n","// @openeudi/core — EUDI Wallet verification protocol engine\nexport const VERSION = '0.1.0';\n\n// Types\nexport { VerificationType, VerificationStatus } from './types/index.js';\n\nexport type {\n VerificationSession,\n VerificationResult,\n CreateSessionInput,\n VerificationServiceConfig,\n} from './types/index.js';\n\n// Errors\nexport { SessionNotFoundError, SessionExpiredError } from './errors.js';\n\n// Storage\nexport type { ISessionStore } from './storage/store.interface.js';\nexport { InMemorySessionStore } from './storage/memory.store.js';\n\n// Modes\nexport type { IVerificationMode } from './modes/mode.interface.js';\nexport { DemoMode } from './modes/demo.mode.js';\nexport type { DemoModeConfig } from './modes/demo.mode.js';\nexport { MockMode } from './modes/mock.mode.js';\nexport type { MockModeConfig } from './modes/mock.mode.js';\n\n// Service\nexport { VerificationService } from './verification.service.js';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type of verification to perform
|
|
5
|
+
*/
|
|
6
|
+
declare enum VerificationType {
|
|
7
|
+
/** Verify age (over_18 attribute) */
|
|
8
|
+
AGE = "AGE",
|
|
9
|
+
/** Verify country of residence */
|
|
10
|
+
COUNTRY = "COUNTRY",
|
|
11
|
+
/** Verify both age and country */
|
|
12
|
+
BOTH = "BOTH"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Status of a verification session
|
|
16
|
+
*/
|
|
17
|
+
declare enum VerificationStatus {
|
|
18
|
+
/** Session created, waiting for wallet scan */
|
|
19
|
+
PENDING = "PENDING",
|
|
20
|
+
/** QR code scanned, credential exchange in progress */
|
|
21
|
+
SCANNED = "SCANNED",
|
|
22
|
+
/** Verification completed successfully */
|
|
23
|
+
VERIFIED = "VERIFIED",
|
|
24
|
+
/** Verification rejected (age, country, or policy) */
|
|
25
|
+
REJECTED = "REJECTED",
|
|
26
|
+
/** Session expired before completion */
|
|
27
|
+
EXPIRED = "EXPIRED"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A verification session tracked by the service
|
|
32
|
+
*/
|
|
33
|
+
interface VerificationSession {
|
|
34
|
+
/** Unique session identifier (UUIDv4) */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Type of verification requested */
|
|
37
|
+
type: VerificationType;
|
|
38
|
+
/** Current session status */
|
|
39
|
+
status: VerificationStatus;
|
|
40
|
+
/** URL for wallet to initiate OpenID4VP flow */
|
|
41
|
+
walletUrl: string;
|
|
42
|
+
/** Allowed countries (ISO 3166-1 alpha-2) */
|
|
43
|
+
countryWhitelist?: string[];
|
|
44
|
+
/** Blocked countries (ISO 3166-1 alpha-2) */
|
|
45
|
+
countryBlacklist?: string[];
|
|
46
|
+
/** Redirect URL after verification completes */
|
|
47
|
+
redirectUrl?: string;
|
|
48
|
+
/** Custom metadata attached to session */
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
/** Session creation timestamp */
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
/** Session expiry timestamp */
|
|
53
|
+
expiresAt: Date;
|
|
54
|
+
/** Completion timestamp (if verified/rejected) */
|
|
55
|
+
completedAt?: Date;
|
|
56
|
+
/** Verification result (populated after completion) */
|
|
57
|
+
result?: VerificationResult;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Result of a completed verification
|
|
61
|
+
*/
|
|
62
|
+
interface VerificationResult {
|
|
63
|
+
/** Whether the verification passed all checks */
|
|
64
|
+
verified: boolean;
|
|
65
|
+
/** Detected country (ISO 3166-1 alpha-2) */
|
|
66
|
+
country?: string;
|
|
67
|
+
/** Whether age check passed */
|
|
68
|
+
ageVerified?: boolean;
|
|
69
|
+
/** Whether country check passed */
|
|
70
|
+
countryVerified?: boolean;
|
|
71
|
+
/** Reason for rejection (if rejected) */
|
|
72
|
+
rejectionReason?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Input for creating a new verification session
|
|
76
|
+
*/
|
|
77
|
+
interface CreateSessionInput {
|
|
78
|
+
/** Type of verification to perform */
|
|
79
|
+
type: VerificationType;
|
|
80
|
+
/** Allowed countries (ISO 3166-1 alpha-2) */
|
|
81
|
+
countryWhitelist?: string[];
|
|
82
|
+
/** Blocked countries (ISO 3166-1 alpha-2) */
|
|
83
|
+
countryBlacklist?: string[];
|
|
84
|
+
/** Redirect URL after verification completes */
|
|
85
|
+
redirectUrl?: string;
|
|
86
|
+
/** Custom metadata to attach to session */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Strategy interface for verification modes.
|
|
92
|
+
* Implement this to create custom modes (e.g., production with real WRPAC).
|
|
93
|
+
*/
|
|
94
|
+
interface IVerificationMode {
|
|
95
|
+
/** Human-readable mode name (e.g., 'demo', 'mock', 'production') */
|
|
96
|
+
readonly name: string;
|
|
97
|
+
/**
|
|
98
|
+
* Process a callback from a wallet (or simulated callback).
|
|
99
|
+
* Called when the wallet sends credential data back.
|
|
100
|
+
*
|
|
101
|
+
* @param session - The current verification session
|
|
102
|
+
* @param walletResponse - Raw data from the wallet (format depends on mode)
|
|
103
|
+
* @returns Verification result
|
|
104
|
+
*/
|
|
105
|
+
processCallback(session: VerificationSession, walletResponse: unknown): Promise<VerificationResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional: simulate automatic completion (used by DemoMode).
|
|
108
|
+
* If implemented, the service calls this after session creation
|
|
109
|
+
* to auto-complete verification without a real wallet.
|
|
110
|
+
*
|
|
111
|
+
* @param session - The session to auto-complete
|
|
112
|
+
* @returns Verification result after simulated delay
|
|
113
|
+
*/
|
|
114
|
+
simulateCompletion?(session: VerificationSession): Promise<VerificationResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Optional: build a custom wallet URL for the session.
|
|
117
|
+
* Used by ProductionMode to generate proper OpenID4VP authorization requests.
|
|
118
|
+
* If not implemented, the service uses a default URL format.
|
|
119
|
+
*
|
|
120
|
+
* @param sessionId - The session ID
|
|
121
|
+
* @param input - The session creation input
|
|
122
|
+
* @returns Custom wallet URL
|
|
123
|
+
*/
|
|
124
|
+
buildWalletUrl?(sessionId: string, input: CreateSessionInput): Promise<string>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Pluggable session storage interface.
|
|
129
|
+
* Implement this to use Redis, PostgreSQL, or any other backend.
|
|
130
|
+
*/
|
|
131
|
+
interface ISessionStore {
|
|
132
|
+
/** Retrieve a session by ID, or null if not found */
|
|
133
|
+
get(id: string): Promise<VerificationSession | null>;
|
|
134
|
+
/** Store or update a session */
|
|
135
|
+
set(session: VerificationSession): Promise<void>;
|
|
136
|
+
/** Delete a session by ID */
|
|
137
|
+
delete(id: string): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Configuration for VerificationService
|
|
142
|
+
*/
|
|
143
|
+
interface VerificationServiceConfig {
|
|
144
|
+
/** Verification mode implementation (DemoMode, MockMode, or custom) */
|
|
145
|
+
mode: IVerificationMode;
|
|
146
|
+
/** Session storage (defaults to InMemorySessionStore) */
|
|
147
|
+
store?: ISessionStore;
|
|
148
|
+
/** Session time-to-live in milliseconds (default: 300_000 = 5 minutes) */
|
|
149
|
+
sessionTtlMs?: number;
|
|
150
|
+
/** Base URL for wallet deep links (default: 'openid4vp://') */
|
|
151
|
+
walletBaseUrl?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Thrown when a session ID is not found in the store
|
|
156
|
+
*/
|
|
157
|
+
declare class SessionNotFoundError extends Error {
|
|
158
|
+
constructor(sessionId: string);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Thrown when an operation is attempted on an expired session
|
|
162
|
+
*/
|
|
163
|
+
declare class SessionExpiredError extends Error {
|
|
164
|
+
constructor(sessionId: string);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* In-memory session store using a Map.
|
|
169
|
+
* Suitable for development, testing, and single-process deployments.
|
|
170
|
+
* Sessions are lost on process restart.
|
|
171
|
+
*/
|
|
172
|
+
declare class InMemorySessionStore implements ISessionStore {
|
|
173
|
+
private sessions;
|
|
174
|
+
get(id: string): Promise<VerificationSession | null>;
|
|
175
|
+
set(session: VerificationSession): Promise<void>;
|
|
176
|
+
delete(id: string): Promise<void>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface DemoModeConfig {
|
|
180
|
+
/** Delay in ms before auto-completion (default: 3000) */
|
|
181
|
+
delayMs?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Demo mode — auto-completes verification with randomized EU data.
|
|
185
|
+
* Used for product demos and landing page previews.
|
|
186
|
+
*/
|
|
187
|
+
declare class DemoMode implements IVerificationMode {
|
|
188
|
+
readonly name = "demo";
|
|
189
|
+
private delayMs;
|
|
190
|
+
constructor(config?: DemoModeConfig);
|
|
191
|
+
processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult>;
|
|
192
|
+
simulateCompletion(session: VerificationSession): Promise<VerificationResult>;
|
|
193
|
+
private pickCountry;
|
|
194
|
+
private buildResult;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface MockModeConfig {
|
|
198
|
+
/** Default result returned for all sessions (default: verified with DE) */
|
|
199
|
+
defaultResult?: VerificationResult;
|
|
200
|
+
/** Delay in ms before returning result (default: 0) */
|
|
201
|
+
delayMs?: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Mock mode — configurable responses for integration testing.
|
|
205
|
+
* Supports global defaults and per-session overrides.
|
|
206
|
+
*/
|
|
207
|
+
declare class MockMode implements IVerificationMode {
|
|
208
|
+
readonly name = "mock";
|
|
209
|
+
private defaultResult;
|
|
210
|
+
private delayMs;
|
|
211
|
+
private sessionOverrides;
|
|
212
|
+
constructor(config?: MockModeConfig);
|
|
213
|
+
/** Set a per-session result override */
|
|
214
|
+
setSessionResult(sessionId: string, result: VerificationResult): void;
|
|
215
|
+
/** Clear a per-session result override */
|
|
216
|
+
clearSessionResult(sessionId: string): void;
|
|
217
|
+
processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult>;
|
|
218
|
+
simulateCompletion(session: VerificationSession): Promise<VerificationResult>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* EUDI Wallet verification session orchestrator.
|
|
223
|
+
*
|
|
224
|
+
* Manages the lifecycle of verification sessions: creation, status tracking,
|
|
225
|
+
* wallet callback handling, expiration, and event emission.
|
|
226
|
+
*
|
|
227
|
+
* Transport-agnostic — consumers wire events to SSE, WebSocket, polling, etc.
|
|
228
|
+
*/
|
|
229
|
+
declare class VerificationService extends EventEmitter {
|
|
230
|
+
private store;
|
|
231
|
+
private mode;
|
|
232
|
+
private sessionTtlMs;
|
|
233
|
+
private walletBaseUrl;
|
|
234
|
+
/** Track session IDs for cleanup (store interface has no list method) */
|
|
235
|
+
private sessionIds;
|
|
236
|
+
constructor(config: VerificationServiceConfig);
|
|
237
|
+
/**
|
|
238
|
+
* Create a new verification session
|
|
239
|
+
*/
|
|
240
|
+
createSession(input: CreateSessionInput): Promise<VerificationSession>;
|
|
241
|
+
/**
|
|
242
|
+
* Get a session by ID
|
|
243
|
+
* @throws SessionNotFoundError
|
|
244
|
+
*/
|
|
245
|
+
getSession(id: string): Promise<VerificationSession>;
|
|
246
|
+
/**
|
|
247
|
+
* Handle a callback from the wallet
|
|
248
|
+
* @throws SessionNotFoundError
|
|
249
|
+
* @throws SessionExpiredError
|
|
250
|
+
*/
|
|
251
|
+
handleCallback(sessionId: string, walletResponse: unknown): Promise<VerificationResult>;
|
|
252
|
+
/**
|
|
253
|
+
* Remove expired sessions from the store
|
|
254
|
+
* @returns Number of sessions cleaned up
|
|
255
|
+
*/
|
|
256
|
+
cleanupExpired(): Promise<number>;
|
|
257
|
+
private completeSession;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
declare const VERSION = "0.1.0";
|
|
261
|
+
|
|
262
|
+
export { type CreateSessionInput, DemoMode, type DemoModeConfig, type ISessionStore, type IVerificationMode, InMemorySessionStore, MockMode, type MockModeConfig, SessionExpiredError, SessionNotFoundError, VERSION, type VerificationResult, VerificationService, type VerificationServiceConfig, type VerificationSession, VerificationStatus, VerificationType };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type of verification to perform
|
|
5
|
+
*/
|
|
6
|
+
declare enum VerificationType {
|
|
7
|
+
/** Verify age (over_18 attribute) */
|
|
8
|
+
AGE = "AGE",
|
|
9
|
+
/** Verify country of residence */
|
|
10
|
+
COUNTRY = "COUNTRY",
|
|
11
|
+
/** Verify both age and country */
|
|
12
|
+
BOTH = "BOTH"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Status of a verification session
|
|
16
|
+
*/
|
|
17
|
+
declare enum VerificationStatus {
|
|
18
|
+
/** Session created, waiting for wallet scan */
|
|
19
|
+
PENDING = "PENDING",
|
|
20
|
+
/** QR code scanned, credential exchange in progress */
|
|
21
|
+
SCANNED = "SCANNED",
|
|
22
|
+
/** Verification completed successfully */
|
|
23
|
+
VERIFIED = "VERIFIED",
|
|
24
|
+
/** Verification rejected (age, country, or policy) */
|
|
25
|
+
REJECTED = "REJECTED",
|
|
26
|
+
/** Session expired before completion */
|
|
27
|
+
EXPIRED = "EXPIRED"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A verification session tracked by the service
|
|
32
|
+
*/
|
|
33
|
+
interface VerificationSession {
|
|
34
|
+
/** Unique session identifier (UUIDv4) */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Type of verification requested */
|
|
37
|
+
type: VerificationType;
|
|
38
|
+
/** Current session status */
|
|
39
|
+
status: VerificationStatus;
|
|
40
|
+
/** URL for wallet to initiate OpenID4VP flow */
|
|
41
|
+
walletUrl: string;
|
|
42
|
+
/** Allowed countries (ISO 3166-1 alpha-2) */
|
|
43
|
+
countryWhitelist?: string[];
|
|
44
|
+
/** Blocked countries (ISO 3166-1 alpha-2) */
|
|
45
|
+
countryBlacklist?: string[];
|
|
46
|
+
/** Redirect URL after verification completes */
|
|
47
|
+
redirectUrl?: string;
|
|
48
|
+
/** Custom metadata attached to session */
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
/** Session creation timestamp */
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
/** Session expiry timestamp */
|
|
53
|
+
expiresAt: Date;
|
|
54
|
+
/** Completion timestamp (if verified/rejected) */
|
|
55
|
+
completedAt?: Date;
|
|
56
|
+
/** Verification result (populated after completion) */
|
|
57
|
+
result?: VerificationResult;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Result of a completed verification
|
|
61
|
+
*/
|
|
62
|
+
interface VerificationResult {
|
|
63
|
+
/** Whether the verification passed all checks */
|
|
64
|
+
verified: boolean;
|
|
65
|
+
/** Detected country (ISO 3166-1 alpha-2) */
|
|
66
|
+
country?: string;
|
|
67
|
+
/** Whether age check passed */
|
|
68
|
+
ageVerified?: boolean;
|
|
69
|
+
/** Whether country check passed */
|
|
70
|
+
countryVerified?: boolean;
|
|
71
|
+
/** Reason for rejection (if rejected) */
|
|
72
|
+
rejectionReason?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Input for creating a new verification session
|
|
76
|
+
*/
|
|
77
|
+
interface CreateSessionInput {
|
|
78
|
+
/** Type of verification to perform */
|
|
79
|
+
type: VerificationType;
|
|
80
|
+
/** Allowed countries (ISO 3166-1 alpha-2) */
|
|
81
|
+
countryWhitelist?: string[];
|
|
82
|
+
/** Blocked countries (ISO 3166-1 alpha-2) */
|
|
83
|
+
countryBlacklist?: string[];
|
|
84
|
+
/** Redirect URL after verification completes */
|
|
85
|
+
redirectUrl?: string;
|
|
86
|
+
/** Custom metadata to attach to session */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Strategy interface for verification modes.
|
|
92
|
+
* Implement this to create custom modes (e.g., production with real WRPAC).
|
|
93
|
+
*/
|
|
94
|
+
interface IVerificationMode {
|
|
95
|
+
/** Human-readable mode name (e.g., 'demo', 'mock', 'production') */
|
|
96
|
+
readonly name: string;
|
|
97
|
+
/**
|
|
98
|
+
* Process a callback from a wallet (or simulated callback).
|
|
99
|
+
* Called when the wallet sends credential data back.
|
|
100
|
+
*
|
|
101
|
+
* @param session - The current verification session
|
|
102
|
+
* @param walletResponse - Raw data from the wallet (format depends on mode)
|
|
103
|
+
* @returns Verification result
|
|
104
|
+
*/
|
|
105
|
+
processCallback(session: VerificationSession, walletResponse: unknown): Promise<VerificationResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional: simulate automatic completion (used by DemoMode).
|
|
108
|
+
* If implemented, the service calls this after session creation
|
|
109
|
+
* to auto-complete verification without a real wallet.
|
|
110
|
+
*
|
|
111
|
+
* @param session - The session to auto-complete
|
|
112
|
+
* @returns Verification result after simulated delay
|
|
113
|
+
*/
|
|
114
|
+
simulateCompletion?(session: VerificationSession): Promise<VerificationResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Optional: build a custom wallet URL for the session.
|
|
117
|
+
* Used by ProductionMode to generate proper OpenID4VP authorization requests.
|
|
118
|
+
* If not implemented, the service uses a default URL format.
|
|
119
|
+
*
|
|
120
|
+
* @param sessionId - The session ID
|
|
121
|
+
* @param input - The session creation input
|
|
122
|
+
* @returns Custom wallet URL
|
|
123
|
+
*/
|
|
124
|
+
buildWalletUrl?(sessionId: string, input: CreateSessionInput): Promise<string>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Pluggable session storage interface.
|
|
129
|
+
* Implement this to use Redis, PostgreSQL, or any other backend.
|
|
130
|
+
*/
|
|
131
|
+
interface ISessionStore {
|
|
132
|
+
/** Retrieve a session by ID, or null if not found */
|
|
133
|
+
get(id: string): Promise<VerificationSession | null>;
|
|
134
|
+
/** Store or update a session */
|
|
135
|
+
set(session: VerificationSession): Promise<void>;
|
|
136
|
+
/** Delete a session by ID */
|
|
137
|
+
delete(id: string): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Configuration for VerificationService
|
|
142
|
+
*/
|
|
143
|
+
interface VerificationServiceConfig {
|
|
144
|
+
/** Verification mode implementation (DemoMode, MockMode, or custom) */
|
|
145
|
+
mode: IVerificationMode;
|
|
146
|
+
/** Session storage (defaults to InMemorySessionStore) */
|
|
147
|
+
store?: ISessionStore;
|
|
148
|
+
/** Session time-to-live in milliseconds (default: 300_000 = 5 minutes) */
|
|
149
|
+
sessionTtlMs?: number;
|
|
150
|
+
/** Base URL for wallet deep links (default: 'openid4vp://') */
|
|
151
|
+
walletBaseUrl?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Thrown when a session ID is not found in the store
|
|
156
|
+
*/
|
|
157
|
+
declare class SessionNotFoundError extends Error {
|
|
158
|
+
constructor(sessionId: string);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Thrown when an operation is attempted on an expired session
|
|
162
|
+
*/
|
|
163
|
+
declare class SessionExpiredError extends Error {
|
|
164
|
+
constructor(sessionId: string);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* In-memory session store using a Map.
|
|
169
|
+
* Suitable for development, testing, and single-process deployments.
|
|
170
|
+
* Sessions are lost on process restart.
|
|
171
|
+
*/
|
|
172
|
+
declare class InMemorySessionStore implements ISessionStore {
|
|
173
|
+
private sessions;
|
|
174
|
+
get(id: string): Promise<VerificationSession | null>;
|
|
175
|
+
set(session: VerificationSession): Promise<void>;
|
|
176
|
+
delete(id: string): Promise<void>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface DemoModeConfig {
|
|
180
|
+
/** Delay in ms before auto-completion (default: 3000) */
|
|
181
|
+
delayMs?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Demo mode — auto-completes verification with randomized EU data.
|
|
185
|
+
* Used for product demos and landing page previews.
|
|
186
|
+
*/
|
|
187
|
+
declare class DemoMode implements IVerificationMode {
|
|
188
|
+
readonly name = "demo";
|
|
189
|
+
private delayMs;
|
|
190
|
+
constructor(config?: DemoModeConfig);
|
|
191
|
+
processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult>;
|
|
192
|
+
simulateCompletion(session: VerificationSession): Promise<VerificationResult>;
|
|
193
|
+
private pickCountry;
|
|
194
|
+
private buildResult;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface MockModeConfig {
|
|
198
|
+
/** Default result returned for all sessions (default: verified with DE) */
|
|
199
|
+
defaultResult?: VerificationResult;
|
|
200
|
+
/** Delay in ms before returning result (default: 0) */
|
|
201
|
+
delayMs?: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Mock mode — configurable responses for integration testing.
|
|
205
|
+
* Supports global defaults and per-session overrides.
|
|
206
|
+
*/
|
|
207
|
+
declare class MockMode implements IVerificationMode {
|
|
208
|
+
readonly name = "mock";
|
|
209
|
+
private defaultResult;
|
|
210
|
+
private delayMs;
|
|
211
|
+
private sessionOverrides;
|
|
212
|
+
constructor(config?: MockModeConfig);
|
|
213
|
+
/** Set a per-session result override */
|
|
214
|
+
setSessionResult(sessionId: string, result: VerificationResult): void;
|
|
215
|
+
/** Clear a per-session result override */
|
|
216
|
+
clearSessionResult(sessionId: string): void;
|
|
217
|
+
processCallback(session: VerificationSession, _walletResponse: unknown): Promise<VerificationResult>;
|
|
218
|
+
simulateCompletion(session: VerificationSession): Promise<VerificationResult>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* EUDI Wallet verification session orchestrator.
|
|
223
|
+
*
|
|
224
|
+
* Manages the lifecycle of verification sessions: creation, status tracking,
|
|
225
|
+
* wallet callback handling, expiration, and event emission.
|
|
226
|
+
*
|
|
227
|
+
* Transport-agnostic — consumers wire events to SSE, WebSocket, polling, etc.
|
|
228
|
+
*/
|
|
229
|
+
declare class VerificationService extends EventEmitter {
|
|
230
|
+
private store;
|
|
231
|
+
private mode;
|
|
232
|
+
private sessionTtlMs;
|
|
233
|
+
private walletBaseUrl;
|
|
234
|
+
/** Track session IDs for cleanup (store interface has no list method) */
|
|
235
|
+
private sessionIds;
|
|
236
|
+
constructor(config: VerificationServiceConfig);
|
|
237
|
+
/**
|
|
238
|
+
* Create a new verification session
|
|
239
|
+
*/
|
|
240
|
+
createSession(input: CreateSessionInput): Promise<VerificationSession>;
|
|
241
|
+
/**
|
|
242
|
+
* Get a session by ID
|
|
243
|
+
* @throws SessionNotFoundError
|
|
244
|
+
*/
|
|
245
|
+
getSession(id: string): Promise<VerificationSession>;
|
|
246
|
+
/**
|
|
247
|
+
* Handle a callback from the wallet
|
|
248
|
+
* @throws SessionNotFoundError
|
|
249
|
+
* @throws SessionExpiredError
|
|
250
|
+
*/
|
|
251
|
+
handleCallback(sessionId: string, walletResponse: unknown): Promise<VerificationResult>;
|
|
252
|
+
/**
|
|
253
|
+
* Remove expired sessions from the store
|
|
254
|
+
* @returns Number of sessions cleaned up
|
|
255
|
+
*/
|
|
256
|
+
cleanupExpired(): Promise<number>;
|
|
257
|
+
private completeSession;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
declare const VERSION = "0.1.0";
|
|
261
|
+
|
|
262
|
+
export { type CreateSessionInput, DemoMode, type DemoModeConfig, type ISessionStore, type IVerificationMode, InMemorySessionStore, MockMode, type MockModeConfig, SessionExpiredError, SessionNotFoundError, VERSION, type VerificationResult, VerificationService, type VerificationServiceConfig, type VerificationSession, VerificationStatus, VerificationType };
|