chatly-sdk 1.0.0 → 2.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/CONTRIBUTING.md +658 -0
- package/IMPROVEMENTS.md +402 -0
- package/LICENSE +21 -0
- package/README.md +1576 -162
- package/dist/index.d.ts +502 -11
- package/dist/index.js +1619 -66
- package/examples/01-basic-chat/README.md +61 -0
- package/examples/01-basic-chat/index.js +58 -0
- package/examples/01-basic-chat/package.json +13 -0
- package/examples/02-group-chat/README.md +78 -0
- package/examples/02-group-chat/index.js +76 -0
- package/examples/02-group-chat/package.json +13 -0
- package/examples/03-offline-messaging/README.md +73 -0
- package/examples/03-offline-messaging/index.js +80 -0
- package/examples/03-offline-messaging/package.json +13 -0
- package/examples/04-live-chat/README.md +80 -0
- package/examples/04-live-chat/index.js +114 -0
- package/examples/04-live-chat/package.json +13 -0
- package/examples/05-hybrid-messaging/README.md +71 -0
- package/examples/05-hybrid-messaging/index.js +106 -0
- package/examples/05-hybrid-messaging/package.json +13 -0
- package/examples/06-postgresql-integration/README.md +101 -0
- package/examples/06-postgresql-integration/adapters/groupStore.js +73 -0
- package/examples/06-postgresql-integration/adapters/messageStore.js +47 -0
- package/examples/06-postgresql-integration/adapters/userStore.js +40 -0
- package/examples/06-postgresql-integration/index.js +92 -0
- package/examples/06-postgresql-integration/package.json +14 -0
- package/examples/06-postgresql-integration/schema.sql +58 -0
- package/examples/08-customer-support/README.md +70 -0
- package/examples/08-customer-support/index.js +104 -0
- package/examples/08-customer-support/package.json +13 -0
- package/examples/README.md +105 -0
- package/jest.config.cjs +28 -0
- package/package.json +15 -6
- package/src/chat/ChatSession.ts +160 -3
- package/src/chat/GroupSession.ts +108 -1
- package/src/constants.ts +61 -0
- package/src/crypto/e2e.ts +9 -20
- package/src/crypto/utils.ts +3 -1
- package/src/index.ts +530 -63
- package/src/models/mediaTypes.ts +62 -0
- package/src/models/message.ts +4 -1
- package/src/storage/adapters.ts +36 -0
- package/src/storage/localStorage.ts +49 -0
- package/src/storage/s3Storage.ts +84 -0
- package/src/stores/adapters.ts +2 -0
- package/src/stores/memory/messageStore.ts +8 -0
- package/src/transport/adapters.ts +51 -1
- package/src/transport/memoryTransport.ts +75 -13
- package/src/transport/websocketClient.ts +269 -21
- package/src/transport/websocketServer.ts +26 -26
- package/src/utils/errors.ts +97 -0
- package/src/utils/logger.ts +96 -0
- package/src/utils/mediaUtils.ts +235 -0
- package/src/utils/messageQueue.ts +162 -0
- package/src/utils/validation.ts +99 -0
- package/test/crypto.test.ts +122 -35
- package/test/sdk.test.ts +276 -0
- package/test/validation.test.ts +64 -0
- package/tsconfig.json +11 -10
- package/tsconfig.test.json +11 -0
- package/src/ChatManager.ts +0 -103
- package/src/crypto/keyManager.ts +0 -28
package/src/crypto/e2e.ts
CHANGED
|
@@ -11,26 +11,6 @@
|
|
|
11
11
|
const TAG_LENGTH = 16;
|
|
12
12
|
const PBKDF2_ITERATIONS = 100000;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Derive a shared secret using ECDH key exchange
|
|
16
|
-
*/
|
|
17
|
-
// export function deriveSharedSecret(local: KeyPair, remotePublicKey: string): Buffer {
|
|
18
|
-
// const ecdh = createECDH(SUPPORTED_CURVE);
|
|
19
|
-
// ecdh.setPrivateKey(base64ToBuffer(local.privateKey));
|
|
20
|
-
|
|
21
|
-
// const remotePublicKeyBuffer = base64ToBuffer(remotePublicKey);
|
|
22
|
-
// const sharedSecret = ecdh.computeSecret(remotePublicKeyBuffer);
|
|
23
|
-
|
|
24
|
-
// // Derive a symmetric key from the shared secret using PBKDF2
|
|
25
|
-
// // Use a deterministic salt based on both public keys for consistency
|
|
26
|
-
// const salt = Buffer.concat([
|
|
27
|
-
// base64ToBuffer(local.publicKey),
|
|
28
|
-
// base64ToBuffer(remotePublicKey)
|
|
29
|
-
// ]).slice(0, SALT_LENGTH);
|
|
30
|
-
// const derivedKey = pbkdf2Sync(sharedSecret, salt, PBKDF2_ITERATIONS, KEY_LENGTH, "sha256");
|
|
31
|
-
|
|
32
|
-
// return derivedKey;
|
|
33
|
-
// }
|
|
34
14
|
|
|
35
15
|
export function deriveSharedSecret(local: KeyPair, remotePublicKey: string): Buffer {
|
|
36
16
|
const ecdh = createECDH(SUPPORTED_CURVE);
|
|
@@ -53,6 +33,15 @@
|
|
|
53
33
|
return derivedKey;
|
|
54
34
|
}
|
|
55
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Legacy secret derivation without salt (for backward compatibility)
|
|
38
|
+
*/
|
|
39
|
+
export function deriveLegacySharedSecret(local: KeyPair, remotePublicKey: string): Buffer {
|
|
40
|
+
const ecdh = createECDH(SUPPORTED_CURVE);
|
|
41
|
+
ecdh.setPrivateKey(base64ToBuffer(local.privateKey));
|
|
42
|
+
return ecdh.computeSecret(base64ToBuffer(remotePublicKey));
|
|
43
|
+
}
|
|
44
|
+
|
|
56
45
|
/**
|
|
57
46
|
* Encrypt a message using AES-GCM
|
|
58
47
|
*/
|
package/src/crypto/utils.ts
CHANGED
|
@@ -2,6 +2,8 @@ export function bufferToBase64(buffer: Buffer): string {
|
|
|
2
2
|
return buffer.toString("base64");
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function base64ToBuffer(data: string): Buffer {
|
|
5
|
+
export function base64ToBuffer(data: string | Buffer): Buffer {
|
|
6
|
+
if (Buffer.isBuffer(data)) return data;
|
|
7
|
+
if (!data) return Buffer.alloc(0);
|
|
6
8
|
return Buffer.from(data, "base64");
|
|
7
9
|
}
|