@stvor/sdk 2.4.0 → 3.0.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/dist/facade/app.cjs +29 -0
- package/dist/facade/app.d.ts +83 -76
- package/dist/facade/app.js +330 -195
- package/dist/facade/crypto-session.cjs +29 -0
- package/dist/facade/crypto-session.d.ts +49 -54
- package/dist/facade/crypto-session.js +117 -140
- package/dist/facade/errors.cjs +29 -0
- package/dist/facade/errors.d.ts +29 -12
- package/dist/facade/errors.js +49 -8
- package/dist/facade/index.cjs +29 -0
- package/dist/facade/index.d.ts +27 -8
- package/dist/facade/index.js +23 -3
- package/dist/facade/local-storage-identity-store.cjs +29 -0
- package/dist/facade/local-storage-identity-store.d.ts +50 -0
- package/dist/facade/local-storage-identity-store.js +100 -0
- package/dist/facade/metrics-attestation.cjs +29 -0
- package/dist/facade/metrics-attestation.d.ts +209 -0
- package/dist/facade/metrics-attestation.js +333 -0
- package/dist/facade/metrics-engine.cjs +29 -0
- package/dist/facade/metrics-engine.d.ts +91 -0
- package/dist/facade/metrics-engine.js +170 -0
- package/dist/facade/redis-replay-cache.cjs +29 -0
- package/dist/facade/redis-replay-cache.d.ts +88 -0
- package/dist/facade/redis-replay-cache.js +60 -0
- package/dist/facade/relay-client.cjs +29 -0
- package/dist/facade/relay-client.d.ts +22 -23
- package/dist/facade/relay-client.js +107 -128
- package/dist/facade/replay-manager.cjs +29 -0
- package/dist/facade/replay-manager.d.ts +28 -35
- package/dist/facade/replay-manager.js +102 -69
- package/dist/facade/sodium-singleton.cjs +29 -0
- package/dist/facade/tofu-manager.cjs +29 -0
- package/dist/facade/tofu-manager.d.ts +38 -36
- package/dist/facade/tofu-manager.js +109 -77
- package/dist/facade/types.cjs +29 -0
- package/dist/facade/types.d.ts +2 -0
- package/dist/index.cjs +29 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/legacy.cjs +29 -0
- package/dist/legacy.d.ts +31 -1
- package/dist/legacy.js +90 -2
- package/dist/ratchet/core-production.cjs +29 -0
- package/dist/ratchet/core-production.d.ts +95 -0
- package/dist/ratchet/core-production.js +286 -0
- package/dist/ratchet/index.cjs +29 -0
- package/dist/ratchet/index.d.ts +49 -78
- package/dist/ratchet/index.js +313 -288
- package/dist/ratchet/key-recovery.cjs +29 -0
- package/dist/ratchet/replay-protection.cjs +29 -0
- package/dist/ratchet/tofu.cjs +29 -0
- package/dist/src/facade/app.cjs +29 -0
- package/dist/src/facade/app.d.ts +105 -0
- package/dist/src/facade/app.js +245 -0
- package/dist/src/facade/crypto.cjs +29 -0
- package/dist/src/facade/errors.cjs +29 -0
- package/dist/src/facade/errors.d.ts +19 -0
- package/dist/src/facade/errors.js +21 -0
- package/dist/src/facade/index.cjs +29 -0
- package/dist/src/facade/index.d.ts +8 -0
- package/dist/src/facade/index.js +5 -0
- package/dist/src/facade/relay-client.cjs +29 -0
- package/dist/src/facade/relay-client.d.ts +36 -0
- package/dist/src/facade/relay-client.js +154 -0
- package/dist/src/facade/types.cjs +29 -0
- package/dist/src/facade/types.d.ts +50 -0
- package/dist/src/facade/types.js +4 -0
- package/dist/src/index.cjs +29 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/legacy.cjs +29 -0
- package/dist/src/legacy.d.ts +0 -0
- package/dist/src/legacy.js +1 -0
- package/dist/src/mock-relay-server.cjs +29 -0
- package/dist/src/mock-relay-server.d.ts +30 -0
- package/dist/src/mock-relay-server.js +236 -0
- package/package.json +37 -11
- package/dist/ratchet/tests/ratchet.test.d.ts +0 -1
- package/dist/ratchet/tests/ratchet.test.js +0 -160
- /package/dist/{facade → src/facade}/crypto.d.ts +0 -0
- /package/dist/{facade → src/facade}/crypto.js +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Auto-generated CommonJS wrapper for facade/app.js
|
|
4
|
+
// This allows `require('@stvor/sdk')` to work alongside ESM `import`.
|
|
5
|
+
|
|
6
|
+
const mod = require('module');
|
|
7
|
+
const url = require('url');
|
|
8
|
+
|
|
9
|
+
// Use dynamic import to load the ESM module
|
|
10
|
+
let _cached;
|
|
11
|
+
async function _load() {
|
|
12
|
+
if (!_cached) {
|
|
13
|
+
_cached = await import(url.pathToFileURL(__filename.replace(/\.cjs$/, '.js')).href);
|
|
14
|
+
}
|
|
15
|
+
return _cached;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// For simple CJS usage, expose a promise-based loader
|
|
19
|
+
module.exports = new Proxy({ load: _load }, {
|
|
20
|
+
get(target, prop) {
|
|
21
|
+
if (prop === '__esModule') return true;
|
|
22
|
+
if (prop === 'then') return undefined; // prevent treating as thenable
|
|
23
|
+
if (prop === 'load') return _load;
|
|
24
|
+
if (prop === 'default') {
|
|
25
|
+
return _load().then(m => m.default);
|
|
26
|
+
}
|
|
27
|
+
return _load().then(m => m[prop]);
|
|
28
|
+
}
|
|
29
|
+
});
|
package/dist/facade/app.d.ts
CHANGED
|
@@ -1,100 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* STVOR DX Facade - Main Application Classes
|
|
3
|
+
*
|
|
4
|
+
* Security Guarantees:
|
|
5
|
+
* - X3DH + Double Ratchet (Signal Protocol)
|
|
6
|
+
* - Forward Secrecy via automatic DH ratchet rotation
|
|
7
|
+
* - Post-Compromise Security via forced ratchet steps
|
|
8
|
+
* - TOFU (Trust On First Use) for identity verification
|
|
9
|
+
* - Replay protection via nonce validation
|
|
10
|
+
* - Cryptographically verified metrics (HMAC-SHA256)
|
|
11
|
+
* - Node.js crypto for all cryptographic operations
|
|
12
|
+
*/
|
|
13
|
+
import { StvorAppConfig, UserId, MessageContent } from './types';
|
|
14
|
+
import { DecryptedMessage } from './types';
|
|
15
|
+
import { Errors, StvorError, ErrorCode } from './errors';
|
|
16
|
+
import { SealedPayload } from './types';
|
|
17
|
+
export type { DecryptedMessage, SealedPayload, ErrorCode };
|
|
18
|
+
export { StvorError, Errors };
|
|
19
|
+
import { RelayClient } from './relay-client';
|
|
20
|
+
import { Counter, Gauge, register } from 'prom-client';
|
|
21
|
+
import { MetricsAttestationEngine } from './metrics-attestation';
|
|
22
|
+
declare const messagesDeliveredTotal: Counter<string>;
|
|
23
|
+
declare const quotaExceededTotal: Counter<string>;
|
|
24
|
+
declare const rateLimitedTotal: Counter<string>;
|
|
25
|
+
declare const activeTokens: Gauge<string>;
|
|
26
|
+
export { messagesDeliveredTotal, quotaExceededTotal, rateLimitedTotal, activeTokens, register };
|
|
27
|
+
export declare class StvorApp {
|
|
28
|
+
private relay;
|
|
29
|
+
private config;
|
|
30
|
+
private connectedClients;
|
|
31
|
+
private metricsAttestation;
|
|
32
|
+
private backendUrl;
|
|
33
|
+
private appToken;
|
|
34
|
+
constructor(config: Required<StvorAppConfig>);
|
|
35
|
+
isReady(): boolean;
|
|
17
36
|
/**
|
|
18
|
-
*
|
|
37
|
+
* Get attestation engine for recording metrics
|
|
19
38
|
*/
|
|
20
|
-
|
|
39
|
+
getMetricsAttestationEngine(): MetricsAttestationEngine;
|
|
21
40
|
/**
|
|
22
|
-
*
|
|
41
|
+
* Periodically send metrics attestations to backend
|
|
42
|
+
* Backend verifies and stores only valid attestations
|
|
23
43
|
*/
|
|
24
|
-
|
|
44
|
+
sendMetricsAttestation(): Promise<void>;
|
|
25
45
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param userId - The user to wait for
|
|
30
|
-
* @param timeoutMs - Maximum time to wait (default: 10000ms)
|
|
31
|
-
* @throws StvorError with RECIPIENT_TIMEOUT if timeout expires
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* await alice.waitForUser('bob@example.com');
|
|
36
|
-
* await alice.send('bob@example.com', 'Hello!');
|
|
37
|
-
* ```
|
|
46
|
+
* Flush metrics to backend
|
|
47
|
+
* Sends current metrics attestation (if there is any activity)
|
|
48
|
+
* Called explicitly by user or on disconnect
|
|
38
49
|
*/
|
|
39
|
-
|
|
50
|
+
flushMetrics(): Promise<void>;
|
|
51
|
+
connect(userId: UserId): Promise<StvorFacadeClient>;
|
|
52
|
+
disconnect(userId?: UserId): Promise<void>;
|
|
53
|
+
private initClient;
|
|
54
|
+
}
|
|
55
|
+
export declare class StvorFacadeClient {
|
|
56
|
+
private userId;
|
|
57
|
+
private relay;
|
|
58
|
+
private metricsAttestation;
|
|
59
|
+
private initialized;
|
|
60
|
+
private cryptoSession;
|
|
61
|
+
private messageHandlers;
|
|
62
|
+
private messageQueue;
|
|
63
|
+
private isReceiving;
|
|
64
|
+
constructor(userId: UserId, relay: RelayClient, metricsAttestation: MetricsAttestationEngine);
|
|
65
|
+
internalInitialize(): Promise<void>;
|
|
66
|
+
private initialize;
|
|
40
67
|
/**
|
|
41
68
|
* Send an encrypted message to a recipient.
|
|
42
69
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
70
|
+
* By default, if the recipient is not yet registered, the method will
|
|
71
|
+
* poll up to `options.timeout` ms for their keys to appear on the relay.
|
|
72
|
+
* Set `options.waitForRecipient: false` to throw immediately instead.
|
|
45
73
|
*
|
|
46
|
-
* @param recipientId
|
|
47
|
-
* @param content
|
|
48
|
-
* @param options
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* // Auto-waits for recipient (recommended)
|
|
54
|
-
* await alice.send('bob@example.com', 'Hello!');
|
|
55
|
-
*
|
|
56
|
-
* // Skip waiting (throws immediately if not available)
|
|
57
|
-
* await alice.send('bob@example.com', 'Hello!', { waitForRecipient: false });
|
|
58
|
-
* ```
|
|
74
|
+
* @param recipientId - The recipient's user ID
|
|
75
|
+
* @param content - Message content (string or Uint8Array)
|
|
76
|
+
* @param options - Optional settings:
|
|
77
|
+
* - `timeout` — Max wait time in ms (default: 10 000)
|
|
78
|
+
* - `waitForRecipient` — Auto-wait for recipient keys (default: true)
|
|
59
79
|
*/
|
|
60
80
|
send(recipientId: UserId, content: MessageContent, options?: {
|
|
61
81
|
timeout?: number;
|
|
62
82
|
waitForRecipient?: boolean;
|
|
63
83
|
}): Promise<void>;
|
|
64
84
|
/**
|
|
65
|
-
*
|
|
85
|
+
* Check current quota usage from the relay server
|
|
66
86
|
*/
|
|
67
|
-
|
|
87
|
+
private checkQuota;
|
|
68
88
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* **Edge-triggered**: Fires only ONCE per user, on first key discovery.
|
|
73
|
-
* Will NOT fire again if user reconnects with same identity.
|
|
89
|
+
* Wait for a specific recipient's public keys to become available on the relay.
|
|
90
|
+
* Polls the relay at 500ms intervals until the keys appear or timeout expires.
|
|
74
91
|
*
|
|
75
|
-
* @
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* console.log(`${userId} is now available for messaging`);
|
|
79
|
-
* });
|
|
80
|
-
* ```
|
|
92
|
+
* @param recipientId - The user ID of the recipient
|
|
93
|
+
* @param timeoutMs - Max time to wait in milliseconds (default: 10000)
|
|
94
|
+
* @returns The recipient's serialized public keys, or null if timeout
|
|
81
95
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
private
|
|
87
|
-
|
|
88
|
-
connect(userId: UserId): Promise<StvorFacadeClient>;
|
|
89
|
-
/**
|
|
90
|
-
* Get a connected client by user ID
|
|
91
|
-
*/
|
|
92
|
-
getClient(userId: UserId): StvorFacadeClient | undefined;
|
|
96
|
+
waitForUser(recipientId: UserId, timeoutMs?: number): Promise<boolean>;
|
|
97
|
+
private waitForRecipientKeys;
|
|
98
|
+
onMessage(handler: (msg: DecryptedMessage) => void): () => void;
|
|
99
|
+
getUserId(): UserId;
|
|
100
|
+
private decryptMessage;
|
|
101
|
+
private startMessagePolling;
|
|
93
102
|
/**
|
|
94
|
-
*
|
|
103
|
+
* Disconnect the client from the relay server.
|
|
95
104
|
*/
|
|
96
|
-
|
|
97
|
-
disconnect(userId?: UserId): Promise<void>;
|
|
105
|
+
disconnect(): Promise<void>;
|
|
98
106
|
}
|
|
99
107
|
export declare function init(config: StvorAppConfig): Promise<StvorApp>;
|
|
100
108
|
export declare const createApp: typeof init;
|
|
@@ -102,4 +110,3 @@ export declare const Stvor: {
|
|
|
102
110
|
init: typeof init;
|
|
103
111
|
createApp: typeof init;
|
|
104
112
|
};
|
|
105
|
-
export {};
|