summaryrefslogtreecommitdiff
path: root/src/types.ts
diff options
context:
space:
mode:
authorPawel Zelawski <pawel.zelawski@outlook.com>2025-04-09 19:12:23 +0200
committerPawel Zelawski <pawel.zelawski@outlook.com>2025-04-09 19:12:23 +0200
commit8092ceaf10dd5951d0b5011fc8d5a05b49335a6e (patch)
treedc2400fb38245b51270609a6715fd6d349d13259 /src/types.ts
parent753fcaebe44fa1b4e8e6e496fbade9508fac1dc1 (diff)
feat: Implement DigiID URI generation and define core types
- Create initial source directory structure (src/). - Define core interfaces (DigiIDUriOptions, DigiIDCallbackData, etc.) and DigiIDError class in src/types.ts. - Set up main export file src/index.ts. - Implement the generateDigiIDUri function in src/digiid.ts for creating DigiID authentication URIs according to the specification. - Include helper function for generating secure nonces using Node crypto. - Add TSDoc comments for clarity and maintainability.
Diffstat (limited to 'src/types.ts')
-rw-r--r--src/types.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/types.ts b/src/types.ts
new file mode 100644
index 0000000..937cfd2
--- /dev/null
+++ b/src/types.ts
@@ -0,0 +1,55 @@
+/**
+ * Options for generating a DigiID URI.
+ */
+export interface DigiIDUriOptions {
+ /** The full URL that the user's DigiID wallet will send the verification data back to. */
+ callbackUrl: string;
+ /** A unique, unpredictable nonce (number used once) for this authentication request. If not provided, a secure random one might be generated (implementation specific). */
+ nonce?: string;
+ /** Set to true for testing over HTTP (insecure), defaults to false (HTTPS required). */
+ unsecure?: boolean;
+}
+
+/**
+ * Data structure typically received from the DigiID wallet callback.
+ */
+export interface DigiIDCallbackData {
+ /** The DigiByte address used for signing. */
+ address: string;
+ /** The DigiID URI that was originally presented to the user. */
+ uri: string;
+ /** The signature proving ownership of the address, signing the URI. */
+ signature: string;
+}
+
+/**
+ * Options for verifying a DigiID callback.
+ */
+export interface DigiIDVerifyOptions {
+ /** The expected callback URL (or parts of it, like domain/path) that should match the one in the received URI. */
+ expectedCallbackUrl: string | URL;
+ /** The specific nonce that was originally generated for this authentication attempt, to prevent replay attacks. */
+ expectedNonce?: string;
+}
+
+/**
+ * Result of a successful DigiID verification.
+ */
+export interface DigiIDVerificationResult {
+ /** Indicates the verification was successful. */
+ isValid: true;
+ /** The DigiByte address that was successfully verified. */
+ address: string;
+ /** The nonce extracted from the verified URI. */
+ nonce: string;
+}
+
+/**
+ * Represents an error during DigiID processing.
+ */
+export class DigiIDError extends Error {
+ constructor(message: string) {
+ super(message);
+ this.name = 'DigiIDError';
+ }
+}