@japofc/baileys 2.1.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/NOTICE.md +111 -0
- package/README.md +1254 -0
- package/WAProto/index.d.ts +9 -0
- package/WAProto/index.js +142276 -0
- package/engine-requirements.js +13 -0
- package/lib/Builders/A2UI.d.ts +242 -0
- package/lib/Builders/A2UI.js +308 -0
- package/lib/Builders/AIRich.d.ts +105 -0
- package/lib/Builders/AIRich.js +2286 -0
- package/lib/Builders/Button.d.ts +103 -0
- package/lib/Builders/Button.js +883 -0
- package/lib/Builders/ButtonV2.d.ts +28 -0
- package/lib/Builders/ButtonV2.js +144 -0
- package/lib/Builders/ButtonV3.d.ts +25 -0
- package/lib/Builders/ButtonV3.js +184 -0
- package/lib/Builders/Carousel.d.ts +22 -0
- package/lib/Builders/Carousel.js +111 -0
- package/lib/Builders/JapBaileys.d.ts +34 -0
- package/lib/Builders/JapBaileys.js +108 -0
- package/lib/Builders/Poll.d.ts +25 -0
- package/lib/Builders/Poll.js +128 -0
- package/lib/Builders/index.d.ts +17 -0
- package/lib/Builders/index.js +11 -0
- package/lib/Builders/shared.d.ts +67 -0
- package/lib/Builders/shared.js +652 -0
- package/lib/Defaults/index.d.ts +154 -0
- package/lib/Defaults/index.js +178 -0
- package/lib/Framework/Bot.d.ts +61 -0
- package/lib/Framework/Bot.js +248 -0
- package/lib/Framework/Context.d.ts +21 -0
- package/lib/Framework/Context.js +89 -0
- package/lib/Framework/MediaManager.d.ts +17 -0
- package/lib/Framework/MediaManager.js +151 -0
- package/lib/Framework/SessionManager.d.ts +13 -0
- package/lib/Framework/SessionManager.js +33 -0
- package/lib/Framework/StatsManager.d.ts +26 -0
- package/lib/Framework/StatsManager.js +119 -0
- package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
- package/lib/Framework/Store/SQLiteStore.js +73 -0
- package/lib/Framework/index.d.ts +9 -0
- package/lib/Framework/index.js +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +430 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +136 -0
- package/lib/Socket/chats.js +1327 -0
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +439 -0
- package/lib/Socket/dugong.d.ts +117 -0
- package/lib/Socket/dugong.js +798 -0
- package/lib/Socket/groups.d.ts +285 -0
- package/lib/Socket/groups.js +354 -0
- package/lib/Socket/index.d.ts +585 -0
- package/lib/Socket/index.js +52 -0
- package/lib/Socket/messages-recv.d.ts +333 -0
- package/lib/Socket/messages-recv.js +1781 -0
- package/lib/Socket/messages-send.d.ts +353 -0
- package/lib/Socket/messages-send.js +1524 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +286 -0
- package/lib/Socket/newsletter.js +364 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1012 -0
- package/lib/Socket/username.d.ts +82 -0
- package/lib/Socket/username.js +159 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +428 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +5 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +6 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +62 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +138 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +8 -0
- package/lib/Types/State.js +55 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/index.d.ts +68 -0
- package/lib/Types/index.js +27 -0
- package/lib/Utils/MessageBuilder.d.ts +2 -0
- package/lib/Utils/MessageBuilder.js +2 -0
- package/lib/Utils/PersistentStore.d.ts +60 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/anti-delete.d.ts +74 -0
- package/lib/Utils/anti-delete.js +221 -0
- package/lib/Utils/auth-secure.d.ts +86 -0
- package/lib/Utils/auth-secure.js +764 -0
- package/lib/Utils/auth-utils.d.ts +57 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/auto-reply.d.ts +47 -0
- package/lib/Utils/auto-reply.js +157 -0
- package/lib/Utils/baileys-event-stream.d.ts +8 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +8 -0
- package/lib/Utils/browser-utils.js +27 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +239 -0
- package/lib/Utils/button-helper-utils.d.ts +53 -0
- package/lib/Utils/button-helper-utils.js +312 -0
- package/lib/Utils/button-sender.d.ts +54 -0
- package/lib/Utils/button-sender.js +822 -0
- package/lib/Utils/chat-control.d.ts +159 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-history-helpers.d.ts +21 -0
- package/lib/Utils/chat-history-helpers.js +70 -0
- package/lib/Utils/chat-utils.d.ts +407 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +147 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +635 -0
- package/lib/Utils/generics.d.ts +69 -0
- package/lib/Utils/generics.js +438 -0
- package/lib/Utils/history-share.d.ts +11 -0
- package/lib/Utils/history-share.js +70 -0
- package/lib/Utils/history.d.ts +90 -0
- package/lib/Utils/history.js +146 -0
- package/lib/Utils/humanizer.d.ts +12 -0
- package/lib/Utils/humanizer.js +73 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +57 -0
- package/lib/Utils/index.js +56 -0
- package/lib/Utils/jid-tools.d.ts +6 -0
- package/lib/Utils/jid-tools.js +77 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +26 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/media-messages.d.ts +18 -0
- package/lib/Utils/media-messages.js +70 -0
- package/lib/Utils/media-set.d.ts +13 -0
- package/lib/Utils/media-set.js +171 -0
- package/lib/Utils/message-kind.d.ts +32 -0
- package/lib/Utils/message-kind.js +136 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +264 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +188 -0
- package/lib/Utils/messages-media.d.ts +135 -0
- package/lib/Utils/messages-media.js +868 -0
- package/lib/Utils/messages.d.ts +44 -0
- package/lib/Utils/messages.js +2326 -0
- package/lib/Utils/meta-ai.d.ts +13 -0
- package/lib/Utils/meta-ai.js +74 -0
- package/lib/Utils/mini-app.d.ts +35 -0
- package/lib/Utils/mini-app.js +213 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/past-participants.d.ts +14 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +82 -0
- package/lib/Utils/process-message.js +808 -0
- package/lib/Utils/qr-render.d.ts +59 -0
- package/lib/Utils/qr-render.js +179 -0
- package/lib/Utils/qrcodegen.d.ts +79 -0
- package/lib/Utils/qrcodegen.js +848 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +444 -0
- package/lib/Utils/router.d.ts +37 -0
- package/lib/Utils/router.js +165 -0
- package/lib/Utils/scheduled-posts.d.ts +30 -0
- package/lib/Utils/scheduled-posts.js +110 -0
- package/lib/Utils/scheduling.d.ts +42 -0
- package/lib/Utils/scheduling.js +139 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/status.d.ts +50 -0
- package/lib/Utils/status.js +107 -0
- package/lib/Utils/stickerpack.d.ts +51 -0
- package/lib/Utils/stickerpack.js +274 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tag.d.ts +12 -0
- package/lib/Utils/tag.js +44 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/templates.d.ts +76 -0
- package/lib/Utils/templates.js +150 -0
- package/lib/Utils/transcribe.d.ts +12 -0
- package/lib/Utils/transcribe.js +107 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
- package/lib/Utils/use-cache-manager-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +166 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +113 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +169 -0
- package/lib/Utils/validate-connection.d.ts +42 -0
- package/lib/Utils/validate-connection.js +198 -0
- package/lib/Utils/vcard.d.ts +58 -0
- package/lib/Utils/vcard.js +104 -0
- package/lib/Utils/voice-note.d.ts +15 -0
- package/lib/Utils/voice-note.js +63 -0
- package/lib/VoIP/audio-feeder.d.ts +18 -0
- package/lib/VoIP/audio-feeder.js +160 -0
- package/lib/VoIP/call-recorder.d.ts +13 -0
- package/lib/VoIP/call-recorder.js +73 -0
- package/lib/VoIP/index.d.ts +86 -0
- package/lib/VoIP/index.js +611 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +563 -0
- package/lib/VoIP/signaling.d.ts +26 -0
- package/lib/VoIP/signaling.js +662 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +120 -0
- package/lib/VoIP/wasm-engine.js +1358 -0
- package/lib/VoIP/worker-bootstrap.d.ts +4 -0
- package/lib/VoIP/worker-bootstrap.js +1046 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +74 -0
- package/lib/WABinary/generic-utils.js +276 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +7 -0
- package/lib/WAUSync/Protocols/index.js +7 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +121 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.d.ts +5 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.d.ts +5 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +23 -0
- package/package.json +180 -0
- package/postinstall-banner.js +82 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QR rendering utilities on top of the vendored qrcodegen engine.
|
|
3
|
+
* @author J.AP
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Error-correction level; accepts short and long names, case-insensitive. */
|
|
7
|
+
export type QRECC = 'L' | 'M' | 'Q' | 'H' | 'LOW' | 'MEDIUM' | 'QUARTILE' | 'HIGH';
|
|
8
|
+
|
|
9
|
+
export interface QRMatrixOptions {
|
|
10
|
+
/** Error-correction level (default 'M'). */
|
|
11
|
+
ecc?: QRECC;
|
|
12
|
+
/** Light border in modules on every side (default 2). */
|
|
13
|
+
quietZone?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface QRTerminalOptions extends QRMatrixOptions {
|
|
17
|
+
/**
|
|
18
|
+
* true (default): two module rows per text line using half-blocks (▀▄█),
|
|
19
|
+
* half the height of classic full-block renderers.
|
|
20
|
+
* false: double-width full blocks for terminals with poor unicode support.
|
|
21
|
+
*/
|
|
22
|
+
small?: boolean;
|
|
23
|
+
/** Flip light/dark for white-on-black terminals (default false). */
|
|
24
|
+
inverted?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface QRSVGOptions extends QRMatrixOptions {
|
|
28
|
+
/** Dark module color (default '#000000'). */
|
|
29
|
+
dark?: string;
|
|
30
|
+
/** Background color (default '#ffffff'). */
|
|
31
|
+
light?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Encode `text` and return the module matrix (true = dark), quiet zone included. */
|
|
35
|
+
export declare const qrToMatrix: (text: string, options?: QRMatrixOptions) => boolean[][];
|
|
36
|
+
|
|
37
|
+
/** Render a QR as a multi-line terminal string. */
|
|
38
|
+
export declare const renderQRToTerminal: (text: string, options?: QRTerminalOptions) => string;
|
|
39
|
+
|
|
40
|
+
/** Render a QR as a standalone SVG string (viewBox in module units). */
|
|
41
|
+
export declare const qrToSVG: (text: string, options?: QRSVGOptions) => string;
|
|
42
|
+
|
|
43
|
+
export interface QRPNGOptions extends QRMatrixOptions {
|
|
44
|
+
/** Pixels per module (default 8). */
|
|
45
|
+
scale?: number;
|
|
46
|
+
/** Dark module gray value 0-255 (default 0). */
|
|
47
|
+
dark?: number;
|
|
48
|
+
/** Background gray value 0-255 (default 255). */
|
|
49
|
+
light?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Render a QR as a PNG Buffer (grayscale, zero external dependencies —
|
|
54
|
+
* hand-rolled encoder on Node's zlib).
|
|
55
|
+
*/
|
|
56
|
+
export declare const qrToPNG: (text: string, options?: QRPNGOptions) => Buffer;
|
|
57
|
+
|
|
58
|
+
/** "ABCDEFGH" -> "ABCD-EFGH" for display; leaves non-8-char codes untouched. */
|
|
59
|
+
export declare const formatPairingCode: (code: string | null | undefined) => string;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QR rendering utilities on top of the vendored qrcodegen engine.
|
|
3
|
+
* Zero external dependencies.
|
|
4
|
+
*
|
|
5
|
+
* - qrToMatrix(text) -> boolean[][] (true = dark module)
|
|
6
|
+
* - renderQRToTerminal(text) -> string using ANSI half-blocks (▀▄█), half the
|
|
7
|
+
* height of classic full-block renderers so WA
|
|
8
|
+
* QRs fit in small terminals; `small: false`
|
|
9
|
+
* switches to double-width full blocks for
|
|
10
|
+
* terminals with poor unicode support.
|
|
11
|
+
* - qrToSVG(text) -> standalone SVG string (crisp at any size)
|
|
12
|
+
* - formatPairingCode(code) -> "ABCD-EFGH" display form
|
|
13
|
+
*
|
|
14
|
+
* @author J.AP
|
|
15
|
+
*/
|
|
16
|
+
import { deflateSync } from 'zlib';
|
|
17
|
+
import { QrCode } from './qrcodegen.js';
|
|
18
|
+
|
|
19
|
+
const DEFAULT_QUIET_ZONE = 2;
|
|
20
|
+
|
|
21
|
+
const eccFromName = (name) => {
|
|
22
|
+
switch (String(name ?? 'M').toUpperCase()) {
|
|
23
|
+
case 'L': case 'LOW': return QrCode.Ecc.LOW;
|
|
24
|
+
case 'Q': case 'QUARTILE': return QrCode.Ecc.QUARTILE;
|
|
25
|
+
case 'H': case 'HIGH': return QrCode.Ecc.HIGH;
|
|
26
|
+
case 'M': case 'MEDIUM':
|
|
27
|
+
default: return QrCode.Ecc.MEDIUM;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Encode `text` and return the module matrix (true = dark), quiet zone included. */
|
|
32
|
+
export const qrToMatrix = (text, { ecc = 'M', quietZone = DEFAULT_QUIET_ZONE } = {}) => {
|
|
33
|
+
if (typeof text !== 'string' || text.length === 0) {
|
|
34
|
+
throw new Error('qrToMatrix: text must be a non-empty string');
|
|
35
|
+
}
|
|
36
|
+
const qz = Math.max(0, quietZone | 0);
|
|
37
|
+
const qr = QrCode.encodeText(text, eccFromName(ecc));
|
|
38
|
+
const size = qr.size + qz * 2;
|
|
39
|
+
const rows = [];
|
|
40
|
+
for (let y = 0; y < size; y += 1) {
|
|
41
|
+
const row = new Array(size);
|
|
42
|
+
for (let x = 0; x < size; x += 1) {
|
|
43
|
+
row[x] = qr.getModule(x - qz, y - qz);
|
|
44
|
+
}
|
|
45
|
+
rows.push(row);
|
|
46
|
+
}
|
|
47
|
+
return rows;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const HALF = { both: '█', top: '▀', bottom: '▄', neither: ' ' };
|
|
51
|
+
const HALF_INVERTED = { both: ' ', top: '▄', bottom: '▀', neither: '█' };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Render a QR as a terminal string.
|
|
55
|
+
* `small: true` (default) packs two module rows per text line via half-blocks.
|
|
56
|
+
* `inverted: true` flips light/dark for white-on-black terminals where the
|
|
57
|
+
* default reads poorly (WhatsApp scans both polarities, but quiet zone must
|
|
58
|
+
* contrast; keep `inverted: false` unless you know your terminal).
|
|
59
|
+
*/
|
|
60
|
+
export const renderQRToTerminal = (text, { small = true, inverted = false, ecc = 'M', quietZone = DEFAULT_QUIET_ZONE } = {}) => {
|
|
61
|
+
const matrix = qrToMatrix(text, { ecc, quietZone });
|
|
62
|
+
const size = matrix.length;
|
|
63
|
+
const lines = [];
|
|
64
|
+
if (small) {
|
|
65
|
+
const glyphs = inverted ? HALF_INVERTED : HALF;
|
|
66
|
+
for (let y = 0; y < size; y += 2) {
|
|
67
|
+
let line = '';
|
|
68
|
+
for (let x = 0; x < size; x += 1) {
|
|
69
|
+
const top = matrix[y][x];
|
|
70
|
+
const bottom = y + 1 < size ? matrix[y + 1][x] : false;
|
|
71
|
+
line += top && bottom ? glyphs.both : top ? glyphs.top : bottom ? glyphs.bottom : glyphs.neither;
|
|
72
|
+
}
|
|
73
|
+
lines.push(line);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const dark = inverted ? ' ' : '██';
|
|
78
|
+
const light = inverted ? '██' : ' ';
|
|
79
|
+
for (let y = 0; y < size; y += 1) {
|
|
80
|
+
let line = '';
|
|
81
|
+
for (let x = 0; x < size; x += 1) {
|
|
82
|
+
line += matrix[y][x] ? dark : light;
|
|
83
|
+
}
|
|
84
|
+
lines.push(line);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return lines.join('\n');
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Render a QR as a standalone SVG string (viewBox in module units). */
|
|
91
|
+
export const qrToSVG = (text, { ecc = 'M', quietZone = DEFAULT_QUIET_ZONE, dark = '#000000', light = '#ffffff' } = {}) => {
|
|
92
|
+
const matrix = qrToMatrix(text, { ecc, quietZone });
|
|
93
|
+
const size = matrix.length;
|
|
94
|
+
const parts = [];
|
|
95
|
+
for (let y = 0; y < size; y += 1) {
|
|
96
|
+
for (let x = 0; x < size; x += 1) {
|
|
97
|
+
if (matrix[y][x]) {
|
|
98
|
+
parts.push(`M${x},${y}h1v1h-1z`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return [
|
|
103
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
104
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" shape-rendering="crispEdges">`,
|
|
105
|
+
`<rect width="100%" height="100%" fill="${light}"/>`,
|
|
106
|
+
`<path d="${parts.join('')}" fill="${dark}"/>`,
|
|
107
|
+
'</svg>',
|
|
108
|
+
].join('');
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// ---- minimal PNG encoder (grayscale 8-bit, filter 0) on Node's zlib ----
|
|
112
|
+
const CRC_TABLE = (() => {
|
|
113
|
+
const t = new Int32Array(256);
|
|
114
|
+
for (let n = 0; n < 256; n += 1) {
|
|
115
|
+
let c = n;
|
|
116
|
+
for (let k = 0; k < 8; k += 1) {
|
|
117
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
118
|
+
}
|
|
119
|
+
t[n] = c;
|
|
120
|
+
}
|
|
121
|
+
return t;
|
|
122
|
+
})();
|
|
123
|
+
|
|
124
|
+
const crc32 = (buf) => {
|
|
125
|
+
let c = 0xffffffff;
|
|
126
|
+
for (let i = 0; i < buf.length; i += 1) {
|
|
127
|
+
c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
|
|
128
|
+
}
|
|
129
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const pngChunk = (type, data) => {
|
|
133
|
+
const out = Buffer.alloc(12 + data.length);
|
|
134
|
+
out.writeUInt32BE(data.length, 0);
|
|
135
|
+
out.write(type, 4, 'latin1');
|
|
136
|
+
data.copy(out, 8);
|
|
137
|
+
out.writeUInt32BE(crc32(out.subarray(4, 8 + data.length)), 8 + data.length);
|
|
138
|
+
return out;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Render a QR as a PNG Buffer (grayscale, zero external dependencies —
|
|
143
|
+
* hand-rolled encoder on Node's zlib). `scale` is pixels per module.
|
|
144
|
+
*/
|
|
145
|
+
export const qrToPNG = (text, { ecc = 'M', quietZone = DEFAULT_QUIET_ZONE, scale = 8, dark = 0, light = 255 } = {}) => {
|
|
146
|
+
const matrix = qrToMatrix(text, { ecc, quietZone });
|
|
147
|
+
const px = Math.max(1, scale | 0);
|
|
148
|
+
const size = matrix.length * px;
|
|
149
|
+
// each scanline: 1 filter byte (0 = None) + `size` grayscale bytes
|
|
150
|
+
const raw = Buffer.alloc(size * (size + 1));
|
|
151
|
+
for (let y = 0; y < size; y += 1) {
|
|
152
|
+
const rowStart = y * (size + 1);
|
|
153
|
+
raw[rowStart] = 0;
|
|
154
|
+
const mRow = matrix[(y / px) | 0];
|
|
155
|
+
for (let x = 0; x < size; x += 1) {
|
|
156
|
+
raw[rowStart + 1 + x] = mRow[(x / px) | 0] ? dark : light;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const ihdr = Buffer.alloc(13);
|
|
160
|
+
ihdr.writeUInt32BE(size, 0); // width
|
|
161
|
+
ihdr.writeUInt32BE(size, 4); // height
|
|
162
|
+
ihdr[8] = 8; // bit depth
|
|
163
|
+
ihdr[9] = 0; // color type: grayscale
|
|
164
|
+
ihdr[10] = 0; // compression
|
|
165
|
+
ihdr[11] = 0; // filter
|
|
166
|
+
ihdr[12] = 0; // interlace
|
|
167
|
+
return Buffer.concat([
|
|
168
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
169
|
+
pngChunk('IHDR', ihdr),
|
|
170
|
+
pngChunk('IDAT', deflateSync(raw, { level: 9 })),
|
|
171
|
+
pngChunk('IEND', Buffer.alloc(0)),
|
|
172
|
+
]);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** "ABCDEFGH" -> "ABCD-EFGH" for display; leaves non-8-char codes untouched. */
|
|
176
|
+
export const formatPairingCode = (code) => {
|
|
177
|
+
const c = String(code ?? '');
|
|
178
|
+
return c.length === 8 ? `${c.slice(0, 4)}-${c.slice(4)}` : c;
|
|
179
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored Project Nayuki QR Code generator (MIT).
|
|
3
|
+
* Upstream: https://github.com/nayuki/QR-Code-generator
|
|
4
|
+
* Declarations mirror the upstream public API used by @japofc/baileys.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export declare class QrCode {
|
|
8
|
+
static encodeText(text: string, ecl: QrCode.Ecc): QrCode;
|
|
9
|
+
static encodeBinary(data: Readonly<Array<number>>, ecl: QrCode.Ecc): QrCode;
|
|
10
|
+
static encodeSegments(
|
|
11
|
+
segs: Readonly<Array<QrSegment>>,
|
|
12
|
+
ecl: QrCode.Ecc,
|
|
13
|
+
minVersion?: number,
|
|
14
|
+
maxVersion?: number,
|
|
15
|
+
mask?: number,
|
|
16
|
+
boostEcl?: boolean,
|
|
17
|
+
): QrCode;
|
|
18
|
+
|
|
19
|
+
static readonly MIN_VERSION: number;
|
|
20
|
+
static readonly MAX_VERSION: number;
|
|
21
|
+
|
|
22
|
+
readonly version: number;
|
|
23
|
+
readonly size: number;
|
|
24
|
+
readonly errorCorrectionLevel: QrCode.Ecc;
|
|
25
|
+
readonly mask: number;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
version: number,
|
|
29
|
+
errorCorrectionLevel: QrCode.Ecc,
|
|
30
|
+
dataCodewords: Readonly<Array<number>>,
|
|
31
|
+
msk: number,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/** true = dark module; coordinates outside the grid return false. */
|
|
35
|
+
getModule(x: number, y: number): boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare namespace QrCode {
|
|
39
|
+
class Ecc {
|
|
40
|
+
static readonly LOW: Ecc;
|
|
41
|
+
static readonly MEDIUM: Ecc;
|
|
42
|
+
static readonly QUARTILE: Ecc;
|
|
43
|
+
static readonly HIGH: Ecc;
|
|
44
|
+
readonly ordinal: number;
|
|
45
|
+
readonly formatBits: number;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare class QrSegment {
|
|
50
|
+
static makeBytes(data: Readonly<Array<number>>): QrSegment;
|
|
51
|
+
static makeNumeric(digits: string): QrSegment;
|
|
52
|
+
static makeAlphanumeric(text: string): QrSegment;
|
|
53
|
+
static makeSegments(text: string): Array<QrSegment>;
|
|
54
|
+
static makeEci(assignVal: number): QrSegment;
|
|
55
|
+
|
|
56
|
+
readonly mode: QrSegment.Mode;
|
|
57
|
+
readonly numChars: number;
|
|
58
|
+
|
|
59
|
+
constructor(mode: QrSegment.Mode, numChars: number, bitData: Readonly<Array<number>>);
|
|
60
|
+
getData(): Array<number>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export declare namespace QrSegment {
|
|
64
|
+
class Mode {
|
|
65
|
+
static readonly NUMERIC: Mode;
|
|
66
|
+
static readonly ALPHANUMERIC: Mode;
|
|
67
|
+
static readonly BYTE: Mode;
|
|
68
|
+
static readonly KANJI: Mode;
|
|
69
|
+
static readonly ECI: Mode;
|
|
70
|
+
readonly modeBits: number;
|
|
71
|
+
numCharCountBits(ver: number): number;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare const qrcodegen: {
|
|
76
|
+
QrCode: typeof QrCode;
|
|
77
|
+
QrSegment: typeof QrSegment;
|
|
78
|
+
};
|
|
79
|
+
export default qrcodegen;
|