@kangwifi-pro/waliwa 1.1.3 → 1.1.5
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/core/noise.d.ts +46 -63
- package/dist/core/noise.d.ts.map +1 -1
- package/dist/core/noise.js +217 -193
- package/dist/core/noise.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/socket/ws-socket.d.ts +27 -19
- package/dist/socket/ws-socket.d.ts.map +1 -1
- package/dist/socket/ws-socket.js +72 -60
- package/dist/socket/ws-socket.js.map +1 -1
- package/package.json +1 -1
- package/src/core/noise.ts +242 -245
- package/src/index.ts +1 -1
- package/src/socket/ws-socket.ts +75 -60
package/dist/core/noise.d.ts
CHANGED
|
@@ -1,98 +1,85 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Waliwa - Noise Protocol XX handshake implementation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* <- s, se
|
|
11
|
-
*
|
|
12
|
-
* Handshake ini menghasilkan encryption key untuk semua komunikasi WebSocket selanjutnya.
|
|
13
|
-
*
|
|
14
|
-
* Original implementation - tidak copy dari Baileys/ZapoJS.
|
|
4
|
+
* Matches Baileys implementation exactly:
|
|
5
|
+
* - authenticate(NOISE_HEADER) + authenticate(staticPublic) at init
|
|
6
|
+
* - mixIntoKey: HKDF with empty info, 64 bytes, split [0:32]=salt, [32:64]=encKey
|
|
7
|
+
* - IV: 12 bytes with 32-bit counter at offset 8
|
|
8
|
+
* - AAD: current hash value
|
|
9
|
+
* - finalize: HKDF(empty, salt, empty, 64) → [0:32]=encKey, [32:64]=decKey
|
|
15
10
|
*/
|
|
16
11
|
import { KeyPair } from './crypto.js';
|
|
17
12
|
export declare class NoiseHandshake {
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
13
|
+
private hash;
|
|
14
|
+
private salt;
|
|
15
|
+
private encKey;
|
|
16
|
+
private decKey;
|
|
17
|
+
private readCounter;
|
|
18
|
+
private writeCounter;
|
|
19
|
+
private isFinished;
|
|
20
|
+
private s;
|
|
21
|
+
private e;
|
|
22
|
+
private rs;
|
|
23
|
+
private re;
|
|
22
24
|
constructor(staticKey?: KeyPair, initiator?: boolean);
|
|
23
|
-
private initializeSymmetric;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* Authenticate - mix data into handshake hash
|
|
26
27
|
*/
|
|
27
|
-
private
|
|
28
|
+
private authenticate;
|
|
28
29
|
/**
|
|
29
|
-
* Mix
|
|
30
|
+
* Mix key into chaining key via HKDF
|
|
31
|
+
* Result: [0:32] = new salt, [32:64] = new encKey (= decKey during handshake)
|
|
30
32
|
*/
|
|
31
|
-
private
|
|
33
|
+
private mixIntoKey;
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* Generate IV: 12 bytes, 4-byte counter at offset 8 (big-endian)
|
|
34
36
|
*/
|
|
35
|
-
private
|
|
37
|
+
private generateIV;
|
|
36
38
|
/**
|
|
37
|
-
*
|
|
39
|
+
* Encrypt with current encKey, AAD = hash
|
|
40
|
+
* Result: ciphertext + GCM tag (concatenated)
|
|
38
41
|
*/
|
|
39
|
-
private
|
|
42
|
+
private encrypt;
|
|
40
43
|
/**
|
|
41
|
-
*
|
|
44
|
+
* Decrypt with current decKey, AAD = hash
|
|
42
45
|
*/
|
|
43
|
-
private
|
|
46
|
+
private decrypt;
|
|
44
47
|
/**
|
|
45
|
-
*
|
|
46
|
-
* Output: bytes untuk dikirim ke server
|
|
48
|
+
* Finish init - derive final traffic keys
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
private finishInit;
|
|
51
|
+
/**
|
|
52
|
+
* Build Message 1: Send client ephemeral (protobuf-wrapped)
|
|
53
|
+
* Returns: protobuf field 2 { field 1: ephemeral }
|
|
54
|
+
*/
|
|
55
|
+
buildClientHello(): Uint8Array;
|
|
49
56
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
57
|
+
* Process Message 2: Server handshake response
|
|
58
|
+
* Expects protobuf with field 3 containing { field 1: ephemeral, field 2: enc_static, field 3: enc_payload }
|
|
52
59
|
*/
|
|
53
60
|
readResponderHandshake(payload: Uint8Array): {
|
|
54
61
|
plaintext: Uint8Array;
|
|
55
62
|
};
|
|
56
63
|
/**
|
|
57
|
-
*
|
|
58
|
-
* Returns:
|
|
59
|
-
* MUST be called AFTER readResponderHandshake (needs remote ephemeral)
|
|
64
|
+
* Build Message 3: Send our static (encrypted) + payload (encrypted)
|
|
65
|
+
* Returns: protobuf field 4 { field 1: enc_static, field 3: enc_payload }
|
|
60
66
|
*/
|
|
61
67
|
writeClientResponse(payload: Uint8Array): Uint8Array;
|
|
62
68
|
/**
|
|
63
|
-
* Finalize
|
|
69
|
+
* Finalize - return traffic keys for post-handshake communication
|
|
64
70
|
*/
|
|
65
71
|
finalize(): {
|
|
66
72
|
sendKey: Uint8Array;
|
|
67
73
|
recvKey: Uint8Array;
|
|
68
74
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
private extractProtobufField;
|
|
76
|
+
private encodeProtobufField;
|
|
77
|
+
private readVarint;
|
|
78
|
+
private skipField;
|
|
79
|
+
private encodeVarint;
|
|
72
80
|
static encryptFrame(key: Uint8Array, counter: number, plaintext: Uint8Array): Uint8Array;
|
|
73
|
-
/**
|
|
74
|
-
* Decrypt a frame post-handshake
|
|
75
|
-
*/
|
|
76
81
|
static decryptFrame(key: Uint8Array, counter: number, ciphertext: Uint8Array): Uint8Array;
|
|
77
|
-
/**
|
|
78
|
-
* Encode WA noise frame: [WA_HEADER] [VERSION] [LENGTH:3] [PAYLOAD]
|
|
79
|
-
*/
|
|
80
|
-
static encodeFrame(payload: Uint8Array): Uint8Array;
|
|
81
|
-
/**
|
|
82
|
-
* Encode WA client payload (untuk handshake init message)
|
|
83
|
-
* Format: [ephemeral_pubkey:32] [static_encrypted] [payload_encrypted]
|
|
84
|
-
*/
|
|
85
|
-
static encodeClientHello(ephemeralPub: Uint8Array, encryptedStatic: Uint8Array, encryptedPayload: Uint8Array): Uint8Array;
|
|
86
|
-
/**
|
|
87
|
-
* Build initial client hello - ONLY the ephemeral key for message 1
|
|
88
|
-
* The encrypted static + payload (message 3) is sent separately
|
|
89
|
-
* after receiving the server's response (message 2)
|
|
90
|
-
*/
|
|
91
|
-
buildClientHello(): Uint8Array;
|
|
92
82
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Traffic cipher untuk encrypt/decrypt frames setelah handshake done
|
|
95
|
-
*/
|
|
96
83
|
export declare class TrafficCipher {
|
|
97
84
|
private sendKey;
|
|
98
85
|
private recvKey;
|
|
@@ -103,9 +90,5 @@ export declare class TrafficCipher {
|
|
|
103
90
|
decrypt(ciphertext: Uint8Array): Uint8Array;
|
|
104
91
|
reset(): void;
|
|
105
92
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Build initial client payload untuk WA Web multi-device connect
|
|
108
|
-
* Berisi info browser, version, dan props
|
|
109
|
-
*/
|
|
110
93
|
export declare function buildClientPayload(browser: [string, string, string]): Uint8Array;
|
|
111
94
|
//# sourceMappingURL=noise.d.ts.map
|
package/dist/core/noise.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../../src/core/noise.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../../src/core/noise.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAOL,OAAO,EACR,MAAM,aAAa,CAAC;AAWrB,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAA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