@oxidezap/whatsapp-rust-bridge 0.6.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/README.md +17 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +2 -0
- package/dist/proto-namespace.d.ts +34 -0
- package/dist/proto-reader.d.ts +20 -0
- package/dist/proto-types.d.ts +16917 -0
- package/dist/proto-types.js +1 -0
- package/dist/proto.d.ts +8 -0
- package/dist/whatsapp_rust_bridge.d.ts +3804 -0
- package/dist/whatsapp_rust_bridge_bg.wasm +0 -0
- package/dist/wire-info.d.ts +107 -0
- package/package.json +59 -0
|
Binary file
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Packed wire-batch codecs (message metadata, receipts, server acks).
|
|
3
|
+
*
|
|
4
|
+
* The bridge crosses hot per-event metadata as fixed-width numeric records
|
|
5
|
+
* plus a per-batch deduplicated string table: repeated addresses, push names
|
|
6
|
+
* and ack classes pay one decode per batch instead of one FFI object build
|
|
7
|
+
* per event. This module is the single host-side owner of every record
|
|
8
|
+
* layout; the Rust writers live in `src/wasm_client.rs`.
|
|
9
|
+
*/
|
|
10
|
+
/** Serde shape of the core's `Jid` as carried by bridge events. */
|
|
11
|
+
export interface WireJid {
|
|
12
|
+
user: string;
|
|
13
|
+
server: string;
|
|
14
|
+
agent: number;
|
|
15
|
+
device: number;
|
|
16
|
+
integrator: number;
|
|
17
|
+
}
|
|
18
|
+
/** Decoded per-message metadata envelope. */
|
|
19
|
+
export interface MessageWireInfo {
|
|
20
|
+
/** Canonical device-independent chat address. */
|
|
21
|
+
chat: string;
|
|
22
|
+
/** Canonical device-independent author address. */
|
|
23
|
+
sender: string;
|
|
24
|
+
senderAlt?: string;
|
|
25
|
+
recipientAlt?: string;
|
|
26
|
+
isFromMe: boolean;
|
|
27
|
+
isGroup: boolean;
|
|
28
|
+
id: string;
|
|
29
|
+
/** Unix timestamp in seconds. */
|
|
30
|
+
timestamp: number;
|
|
31
|
+
pushName: string;
|
|
32
|
+
isViewOnce: boolean;
|
|
33
|
+
isOffline: boolean;
|
|
34
|
+
unavailableRequestId?: string;
|
|
35
|
+
/** Raw protocol edit attribute; absent when the attribute was empty. */
|
|
36
|
+
edit?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const MESSAGE_WIRE_INFO_RECORD_WIDTH = 10;
|
|
39
|
+
/** Decoded message batch: payload slices plus one envelope per message. */
|
|
40
|
+
export interface MessageWireBatchView {
|
|
41
|
+
/** Concatenated `proto.Message` payloads, in event order. */
|
|
42
|
+
messageData: Uint8Array;
|
|
43
|
+
/** N + 1 byte offsets delimiting the N payloads in `messageData`. */
|
|
44
|
+
messageOffsets: Uint32Array;
|
|
45
|
+
/** One decoded envelope per message, parallel to the payload offsets. */
|
|
46
|
+
infos: MessageWireInfo[];
|
|
47
|
+
}
|
|
48
|
+
/** Decode a packed message batch into payload slices and metadata envelopes. */
|
|
49
|
+
export declare function decodeMessageWireBatch(batch: PackedWireBatch): MessageWireBatchView;
|
|
50
|
+
/** One message as a caller supplies it to `encodeMessageWireBatch`. */
|
|
51
|
+
export interface MessageWireEntry {
|
|
52
|
+
/** Encoded `proto.Message` payload. */
|
|
53
|
+
payload: Uint8Array;
|
|
54
|
+
info: MessageWireInfo;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Inverse of `decodeMessageWireBatch`, for hosts that need to fabricate batches
|
|
58
|
+
* (tests, replay tooling). Mirrors the Rust writer byte for byte.
|
|
59
|
+
*/
|
|
60
|
+
export declare function encodeMessageWireBatch(entries: readonly MessageWireEntry[]): PackedWireBatch;
|
|
61
|
+
/**
|
|
62
|
+
* A packed batch IS its buffer: one flat run of header, cache definitions,
|
|
63
|
+
* fixed-width records and string bytes. See the Rust writers in
|
|
64
|
+
* `src/wire_batch.rs`.
|
|
65
|
+
*
|
|
66
|
+
* Crossing the bare typed array rather than a `{ buffer }` object saves an
|
|
67
|
+
* object construction and a property write per batch, and a single message
|
|
68
|
+
* produces three batches (its own, its receipt, its ack).
|
|
69
|
+
*/
|
|
70
|
+
export type PackedWireBatch = Uint8Array;
|
|
71
|
+
/** Serde shape of the core's `Receipt` payload, as the single-event path emits it. */
|
|
72
|
+
export interface ReceiptWireData {
|
|
73
|
+
source: {
|
|
74
|
+
chat: WireJid;
|
|
75
|
+
sender: WireJid;
|
|
76
|
+
is_from_me: boolean;
|
|
77
|
+
is_group: boolean;
|
|
78
|
+
addressing_mode?: string;
|
|
79
|
+
sender_alt?: WireJid;
|
|
80
|
+
recipient_alt?: WireJid;
|
|
81
|
+
broadcast_list_owner?: WireJid;
|
|
82
|
+
recipient?: WireJid;
|
|
83
|
+
};
|
|
84
|
+
message_ids: string[];
|
|
85
|
+
/** Unix timestamp in seconds. */
|
|
86
|
+
timestamp: number;
|
|
87
|
+
/** Variant name, or `{ Other: value }` for unrecognized wire values. */
|
|
88
|
+
type: string | {
|
|
89
|
+
Other: string;
|
|
90
|
+
};
|
|
91
|
+
offline: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Serde shape of the core's `ServerAck` payload. */
|
|
94
|
+
export interface ServerAckWireData {
|
|
95
|
+
id: string;
|
|
96
|
+
class?: string;
|
|
97
|
+
from?: WireJid;
|
|
98
|
+
/** Unix timestamp in seconds. */
|
|
99
|
+
timestamp?: number;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
export declare function decodeReceiptWireBatch(batch: PackedWireBatch): ReceiptWireData[];
|
|
103
|
+
export declare function decodeServerAckWireBatch(batch: PackedWireBatch): ServerAckWireData[];
|
|
104
|
+
/** Inverse of `decodeReceiptWireBatch`, for tests and replay tooling. */
|
|
105
|
+
export declare function encodeReceiptWireBatch(receipts: readonly ReceiptWireData[]): PackedWireBatch;
|
|
106
|
+
/** Inverse of `decodeServerAckWireBatch`, for tests and replay tooling. */
|
|
107
|
+
export declare function encodeServerAckWireBatch(acks: readonly ServerAckWireData[]): PackedWireBatch;
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oxidezap/whatsapp-rust-bridge",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "A high-performance utilities for WhatsApp, powered by Rust and WebAssembly.",
|
|
5
|
+
"author": "João Lucas <jlucaso@hotmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/oxidezap/whatsapp-rust-bridge.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/**/*"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./proto-types": {
|
|
26
|
+
"import": "./dist/proto-types.js",
|
|
27
|
+
"types": "./dist/proto-types.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"bench": "bun run build && bun run benches/binary.ts && bun run benches/signal.ts && bun run benches/curve.ts && bun run benches/crypto.ts",
|
|
32
|
+
"bench:node": "bun run build && node --expose-gc benches/binary.ts && node --expose-gc benches/signal.ts && node --expose-gc benches/curve.ts && node --expose-gc benches/crypto.ts",
|
|
33
|
+
"gen:bridge-types": "cd codegen && cargo run -q --bin gen-types --target $(rustc -vV | grep host | cut -d' ' -f2) > ../src/generated_types.rs.tmp && mv ../src/generated_types.rs.tmp ../src/generated_types.rs",
|
|
34
|
+
"gen:proto-codec": "bun run scripts/gen-ts-proto.ts",
|
|
35
|
+
"gen:proto-types": "bun run scripts/gen-protobufjs-dts.ts",
|
|
36
|
+
"gen": "bun run gen:bridge-types && bun run gen:proto-codec && bun run gen:proto-types",
|
|
37
|
+
"build:wasm": "wasm-pack build --target web --out-dir pkg --no-pack",
|
|
38
|
+
"build:wasm:dev": "wasm-pack build --target web --out-dir pkg --no-pack --dev",
|
|
39
|
+
"build:ts": "bun build ts/index.ts --minify --outfile dist/index.js --target node && cp pkg/whatsapp_rust_bridge_bg.wasm dist/ && cp ts/proto-types.d.ts dist/proto-types.d.ts && cp ts/proto-types.d.ts pkg/proto-types.d.ts && printf 'export { proto } from \"./index.js\";\\n' > dist/proto-types.js",
|
|
40
|
+
"postbuild": "tsc -p tsconfig.json --outDir dist && rm -f dist/macro.d.ts && rm -rf dist/generated && bun run scripts/finalize-dist.ts",
|
|
41
|
+
"build": "bun run gen && bun run build:wasm && bun run build:ts && bun run postbuild",
|
|
42
|
+
"build:dev": "bun run gen && bun run build:wasm:dev && bun run build:ts && bun run postbuild",
|
|
43
|
+
"build:profile": "cargo build --profile profiling --target wasm32-unknown-unknown && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run postbuild",
|
|
44
|
+
"build:memory-profile": "cargo build --profile profiling --target wasm32-unknown-unknown --features memory-profiling && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run postbuild",
|
|
45
|
+
"bump:wacore": "cargo update -p whatsapp-rust && bun run build",
|
|
46
|
+
"example": "NODE_TLS_REJECT_UNAUTHORIZED=0 bun run examples/connect.ts",
|
|
47
|
+
"test:rust": "wasm-pack test --node",
|
|
48
|
+
"prepack": "bun run scripts/check-pack.ts",
|
|
49
|
+
"prepublishOnly": "bun run build"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@bufbuild/protobuf": "^2.12.0",
|
|
53
|
+
"@types/bun": "^1.3.13",
|
|
54
|
+
"@types/node": "^25.6.0",
|
|
55
|
+
"ts-proto": "^2.11.6",
|
|
56
|
+
"typescript": "^6.0.3"
|
|
57
|
+
},
|
|
58
|
+
"private": false
|
|
59
|
+
}
|