ishumdz-bail 1.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/README.md +772 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +142 -0
- package/lib/Games/index.js +497 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/queue-job.js +53 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +84 -0
- package/lib/Socket/ban-checker.js +265 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1193 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/luxu.js +460 -0
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1469 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +261 -0
- package/lib/Socket/socket.js +988 -0
- package/lib/Socket/username.js +234 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +198 -0
- package/lib/Store/make-ordered-dictionary.js +75 -0
- package/lib/Store/object-repository.js +32 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +49 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/classify-disconnect.js +126 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +793 -0
- package/lib/Utils/messages.js +1586 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/rate-limiter.js +228 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +37 -0
- package/package.json +150 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
2
|
+
|
|
3
|
+
if (major < 20) {
|
|
4
|
+
console.error(
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
|
+
);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
|
+
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
const version = [2, 3000, 1035194821];
|
|
6
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
8
|
+
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
9
|
+
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
10
|
+
export const DEF_CALLBACK_PREFIX = 'CB:';
|
|
11
|
+
export const DEF_TAG_PREFIX = 'TAG:';
|
|
12
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong';
|
|
13
|
+
export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
|
|
14
|
+
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
15
|
+
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
16
|
+
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
17
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
|
+
/** Status messages older than 24 hours are considered expired */
|
|
19
|
+
export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
|
|
20
|
+
/** WA Web enforces a 14-day maximum age for placeholder resend requests */
|
|
21
|
+
export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
|
|
22
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
23
|
+
export const DICT_VERSION = 3;
|
|
24
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
25
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
|
|
26
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
27
|
+
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
28
|
+
export const WA_CERT_DETAILS = {
|
|
29
|
+
SERIAL: 0,
|
|
30
|
+
ISSUER: 'WhatsAppLongTerm1',
|
|
31
|
+
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
32
|
+
};
|
|
33
|
+
export const PROCESSABLE_HISTORY_TYPES = [
|
|
34
|
+
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
35
|
+
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
36
|
+
proto.HistorySync.HistorySyncType.RECENT,
|
|
37
|
+
proto.HistorySync.HistorySyncType.FULL,
|
|
38
|
+
proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
39
|
+
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
40
|
+
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
41
|
+
];
|
|
42
|
+
export const DEFAULT_CACHE_TTLS = {
|
|
43
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
44
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
45
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
46
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
47
|
+
};
|
|
48
|
+
export const DEFAULT_CONNECTION_CONFIG = {
|
|
49
|
+
version: version,
|
|
50
|
+
browser: Browsers.macOS('Chrome'),
|
|
51
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
52
|
+
connectTimeoutMs: 20000,
|
|
53
|
+
keepAliveIntervalMs: 30000,
|
|
54
|
+
logger: logger.child({ class: 'cpxbails' }),
|
|
55
|
+
emitOwnEvents: true,
|
|
56
|
+
defaultQueryTimeoutMs: 60000,
|
|
57
|
+
customUploadHosts: [],
|
|
58
|
+
retryRequestDelayMs: 250,
|
|
59
|
+
maxMsgRetryCount: 5,
|
|
60
|
+
fireInitQueries: true,
|
|
61
|
+
auth: undefined,
|
|
62
|
+
markOnlineOnConnect: true,
|
|
63
|
+
aiLabel: true,
|
|
64
|
+
syncFullHistory: true,
|
|
65
|
+
patchMessageBeforeSending: msg => msg,
|
|
66
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
67
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
68
|
+
},
|
|
69
|
+
shouldIgnoreJid: () => false,
|
|
70
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
71
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
72
|
+
generateHighQualityLinkPreview: false,
|
|
73
|
+
enableAutoSessionRecreation: true,
|
|
74
|
+
enableRecentMessageCache: true,
|
|
75
|
+
options: {},
|
|
76
|
+
appStateMacVerification: {
|
|
77
|
+
patch: false,
|
|
78
|
+
snapshot: false
|
|
79
|
+
},
|
|
80
|
+
countryCode: 'US',
|
|
81
|
+
getMessage: async () => undefined,
|
|
82
|
+
cachedGroupMetadata: async () => undefined,
|
|
83
|
+
makeSignalRepository: makeLibSignalRepository
|
|
84
|
+
};
|
|
85
|
+
export const MEDIA_PATH_MAP = {
|
|
86
|
+
image: '/mms/image',
|
|
87
|
+
video: '/mms/video',
|
|
88
|
+
document: '/mms/document',
|
|
89
|
+
audio: '/mms/audio',
|
|
90
|
+
sticker: '/mms/image',
|
|
91
|
+
'thumbnail-link': '/mms/image',
|
|
92
|
+
'product-catalog-image': '/product/image',
|
|
93
|
+
'md-app-state': '',
|
|
94
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
95
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
96
|
+
};
|
|
97
|
+
export const NEWSLETTER_MEDIA_PATH_MAP = {
|
|
98
|
+
image: '/newsletter/newsletter-image',
|
|
99
|
+
video: '/newsletter/newsletter-video',
|
|
100
|
+
document: '/newsletter/newsletter-document',
|
|
101
|
+
audio: '/newsletter/newsletter-audio',
|
|
102
|
+
sticker: '/newsletter/newsletter-image',
|
|
103
|
+
gif: '/newsletter/newsletter-gif',
|
|
104
|
+
ptt: '/newsletter/newsletter-ptt',
|
|
105
|
+
ptv: '/newsletter/newsletter-ptv',
|
|
106
|
+
'sticker-pack': '/newsletter/newsletter-sticker-pack',
|
|
107
|
+
'thumbnail-link': '/newsletter/newsletter-thumbnail-link'
|
|
108
|
+
};
|
|
109
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
110
|
+
audio: 'Audio',
|
|
111
|
+
document: 'Document',
|
|
112
|
+
gif: 'Video',
|
|
113
|
+
image: 'Image',
|
|
114
|
+
ppic: '',
|
|
115
|
+
product: 'Image',
|
|
116
|
+
ptt: 'Audio',
|
|
117
|
+
sticker: 'Image',
|
|
118
|
+
video: 'Video',
|
|
119
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
120
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
121
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
122
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
123
|
+
'md-msg-hist': 'History',
|
|
124
|
+
'md-app-state': 'App State',
|
|
125
|
+
'product-catalog-image': '',
|
|
126
|
+
'payment-bg-image': 'Payment Background',
|
|
127
|
+
ptv: 'Video',
|
|
128
|
+
'biz-cover-photo': 'Image'
|
|
129
|
+
};
|
|
130
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
131
|
+
/** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
|
|
132
|
+
export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
|
|
133
|
+
export const MIN_PREKEY_COUNT = 5;
|
|
134
|
+
export const INITIAL_PREKEY_COUNT = 812;
|
|
135
|
+
export const UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
136
|
+
export const TimeMs = {
|
|
137
|
+
Minute: 60 * 1000,
|
|
138
|
+
Hour: 60 * 60 * 1000,
|
|
139
|
+
Day: 24 * 60 * 60 * 1000,
|
|
140
|
+
Week: 7 * 24 * 60 * 60 * 1000
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhatsApp Games Module for ishu-md
|
|
3
|
+
* Add fun games to your WhatsApp bot!
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ==================== BLACKJACK ====================
|
|
7
|
+
const CARD_SUITS = ['♠️', '♥️', '♦️', '♣️'];
|
|
8
|
+
const CARD_VALUES = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
|
|
9
|
+
|
|
10
|
+
function createDeck() {
|
|
11
|
+
const deck = [];
|
|
12
|
+
for (const suit of CARD_SUITS) {
|
|
13
|
+
for (const value of CARD_VALUES) {
|
|
14
|
+
deck.push({ suit, value });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return shuffleArray(deck);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function shuffleArray(array) {
|
|
21
|
+
const arr = [...array];
|
|
22
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
|
23
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
24
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
25
|
+
}
|
|
26
|
+
return arr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getCardValue(card) {
|
|
30
|
+
if (['J', 'Q', 'K'].includes(card.value)) return 10;
|
|
31
|
+
if (card.value === 'A') return 11;
|
|
32
|
+
return parseInt(card.value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function calculateHand(hand) {
|
|
36
|
+
let sum = 0;
|
|
37
|
+
let aces = 0;
|
|
38
|
+
|
|
39
|
+
for (const card of hand) {
|
|
40
|
+
sum += getCardValue(card);
|
|
41
|
+
if (card.value === 'A') aces++;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
while (sum > 21 && aces > 0) {
|
|
45
|
+
sum -= 10;
|
|
46
|
+
aces--;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return sum;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatCard(card) {
|
|
53
|
+
return `${card.value}${card.suit}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function formatHand(hand) {
|
|
57
|
+
return hand.map(formatCard).join(' ');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function blackjack(action, playerHand = [], dealerHand = [], bet = 0) {
|
|
61
|
+
if (action === 'start') {
|
|
62
|
+
const deck = createDeck();
|
|
63
|
+
const player = [deck.pop(), deck.pop()];
|
|
64
|
+
const dealer = [deck.pop(), deck.pop()];
|
|
65
|
+
|
|
66
|
+
const playerSum = calculateHand(player);
|
|
67
|
+
const dealerVisible = dealer[0];
|
|
68
|
+
|
|
69
|
+
if (playerSum === 21) {
|
|
70
|
+
return {
|
|
71
|
+
status: 'blackjack',
|
|
72
|
+
playerHand: formatHand(player),
|
|
73
|
+
dealerHand: formatHand(dealer),
|
|
74
|
+
playerSum,
|
|
75
|
+
dealerSum: calculateHand(dealer),
|
|
76
|
+
win: true,
|
|
77
|
+
payout: Math.floor(bet * 2.5),
|
|
78
|
+
message: `🎰 *BLACKJACK!*\n\nYour cards: ${formatHand(player)}\nDealer cards: ${formatHand(dealer)}\n\nYou win ${Math.floor(bet * 2.5)} coins!`
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
status: 'playing',
|
|
84
|
+
playerHand: player,
|
|
85
|
+
dealerHand: dealer,
|
|
86
|
+
deck,
|
|
87
|
+
playerSum,
|
|
88
|
+
dealerVisible: formatCard(dealerVisible),
|
|
89
|
+
bet,
|
|
90
|
+
message: `🃏 *Blackjack*\n\nYour cards: ${formatHand(player)} (${playerSum})\nDealer shows: ${formatCard(dealerVisible)} ?\n\nHit / Stand / Double?`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (action === 'hit') {
|
|
95
|
+
const deck = playerHand.deck || createDeck();
|
|
96
|
+
playerHand.player.push(deck.pop());
|
|
97
|
+
const playerSum = calculateHand(playerHand.player);
|
|
98
|
+
|
|
99
|
+
if (playerSum > 21) {
|
|
100
|
+
return {
|
|
101
|
+
status: 'bust',
|
|
102
|
+
playerHand: formatHand(playerHand.player),
|
|
103
|
+
dealerHand: formatHand(playerHand.dealerHand),
|
|
104
|
+
playerSum,
|
|
105
|
+
win: false,
|
|
106
|
+
payout: 0,
|
|
107
|
+
message: `💥 *BUST!*\n\nYour cards: ${formatHand(playerHand.player)} (${playerSum})\nDealer cards: ${formatHand(playerHand.dealerHand)}\n\nYou lose ${playerHand.bet} coins!`
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (playerSum === 21) {
|
|
112
|
+
return blackjack('stand', playerHand, null, playerHand.bet);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
status: 'playing',
|
|
117
|
+
playerHand: playerHand.player,
|
|
118
|
+
dealerHand: playerHand.dealerHand,
|
|
119
|
+
deck,
|
|
120
|
+
playerSum,
|
|
121
|
+
bet: playerHand.bet,
|
|
122
|
+
message: `🃏 *Blackjack*\n\nYour cards: ${formatHand(playerHand.player)} (${playerSum})\nDealer shows: ${playerHand.dealerVisible} ?\n\nHit / Stand?`
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (action === 'stand') {
|
|
127
|
+
let dealer = [...playerHand.dealerHand];
|
|
128
|
+
const deck = createDeck();
|
|
129
|
+
|
|
130
|
+
while (calculateHand(dealer) < 17) {
|
|
131
|
+
dealer.push(deck.pop());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const playerSum = calculateHand(playerHand.player);
|
|
135
|
+
const dealerSum = calculateHand(dealer);
|
|
136
|
+
|
|
137
|
+
let result;
|
|
138
|
+
if (dealerSum > 21) {
|
|
139
|
+
result = 'win';
|
|
140
|
+
} else if (playerSum > dealerSum) {
|
|
141
|
+
result = 'win';
|
|
142
|
+
} else if (playerSum < dealerSum) {
|
|
143
|
+
result = 'lose';
|
|
144
|
+
} else {
|
|
145
|
+
result = 'push';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const payout = result === 'win' ? playerHand.bet * 2 : (result === 'push' ? playerHand.bet : 0);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
status: result,
|
|
152
|
+
playerHand: formatHand(playerHand.player),
|
|
153
|
+
dealerHand: formatHand(dealer),
|
|
154
|
+
playerSum,
|
|
155
|
+
dealerSum,
|
|
156
|
+
win: result === 'win',
|
|
157
|
+
push: result === 'push',
|
|
158
|
+
payout,
|
|
159
|
+
message: `🃏 *Blackjack Result*\n\nYour cards: ${formatHand(playerHand.player)} (${playerSum})\nDealer cards: ${formatHand(dealer)} (${dealerSum})\n\n${result === 'win' ? `You win ${payout} coins!` : result === 'push' ? 'Push! Bet returned.' : `You lose ${playerHand.bet} coins!`}`
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (action === 'double') {
|
|
164
|
+
if (playerHand.player.length !== 2) {
|
|
165
|
+
return { status: 'error', message: 'Can only double on first two cards!' };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const deck = playerHand.deck || createDeck();
|
|
169
|
+
playerHand.player.push(deck.pop());
|
|
170
|
+
const playerSum = calculateHand(playerHand.player);
|
|
171
|
+
|
|
172
|
+
if (playerSum > 21) {
|
|
173
|
+
return {
|
|
174
|
+
status: 'bust',
|
|
175
|
+
playerHand: formatHand(playerHand.player),
|
|
176
|
+
dealerHand: formatHand(playerHand.dealerHand),
|
|
177
|
+
playerSum,
|
|
178
|
+
win: false,
|
|
179
|
+
payout: 0,
|
|
180
|
+
message: `💥 *BUST!*\n\nYour cards: ${formatHand(playerHand.player)} (${playerSum})\nDealer cards: ${formatHand(playerHand.dealerHand)}\n\nYou lose ${playerHand.bet * 2} coins!`
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return blackjack('stand', { ...playerHand, bet: playerHand.bet * 2 }, null, playerHand.bet * 2);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { status: 'error', message: 'Invalid action!' };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ==================== SLOT MACHINE ====================
|
|
191
|
+
const SLOT_SYMBOLS = ['🍒', '🍋', '🍊', '🍇', '💎', '7️⃣', '⭐'];
|
|
192
|
+
const SLOT_WEIGHTS = [30, 25, 20, 15, 5, 3, 2];
|
|
193
|
+
|
|
194
|
+
function getWeightedRandom() {
|
|
195
|
+
const totalWeight = SLOT_WEIGHTS.reduce((a, b) => a + b, 0);
|
|
196
|
+
let random = Math.random() * totalWeight;
|
|
197
|
+
|
|
198
|
+
for (let i = 0; i < SLOT_SYMBOLS.length; i++) {
|
|
199
|
+
random -= SLOT_WEIGHTS[i];
|
|
200
|
+
if (random <= 0) return SLOT_SYMBOLS[i];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return SLOT_SYMBOLS[0];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function slotMachine(bet = 100) {
|
|
207
|
+
const reels = [
|
|
208
|
+
getWeightedRandom(),
|
|
209
|
+
getWeightedRandom(),
|
|
210
|
+
getWeightedRandom()
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
const display = `🎰 *SLOT MACHINE* 🎰\n\n[${reels[0]}] [${reels[1]}] [${reels[2]}]\n`;
|
|
214
|
+
|
|
215
|
+
let payout = 0;
|
|
216
|
+
let message = '';
|
|
217
|
+
|
|
218
|
+
if (reels[0] === reels[1] && reels[1] === reels[2]) {
|
|
219
|
+
// Three of a kind
|
|
220
|
+
if (reels[0] === '7️⃣') {
|
|
221
|
+
payout = bet * 100;
|
|
222
|
+
message = '🎉 *JACKPOT!* Three 7️⃣!';
|
|
223
|
+
} else if (reels[0] === '💎') {
|
|
224
|
+
payout = bet * 50;
|
|
225
|
+
message = '💎 *DIAMOND WIN!*';
|
|
226
|
+
} else {
|
|
227
|
+
payout = bet * 20;
|
|
228
|
+
message = '⭐ *THREE OF A KIND!*';
|
|
229
|
+
}
|
|
230
|
+
} else if (reels[0] === reels[1] || reels[1] === reels[2] || reels[0] === reels[2]) {
|
|
231
|
+
payout = bet * 2;
|
|
232
|
+
message = '✨ *TWO MATCH!*';
|
|
233
|
+
} else {
|
|
234
|
+
payout = 0;
|
|
235
|
+
message = '😔 *NO MATCH*';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
reels,
|
|
240
|
+
win: payout > 0,
|
|
241
|
+
payout,
|
|
242
|
+
bet,
|
|
243
|
+
message: `${display}\n${message}\n\n${payout > 0 ? `You win ${payout} coins!` : `You lose ${bet} coins!`}`
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ==================== DICE ====================
|
|
248
|
+
export function diceGame(bet = 100, prediction = 'high') {
|
|
249
|
+
const dice1 = Math.floor(Math.random() * 6) + 1;
|
|
250
|
+
const dice2 = Math.floor(Math.random() * 6) + 1;
|
|
251
|
+
const total = dice1 + dice2;
|
|
252
|
+
|
|
253
|
+
const diceEmojis = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅'];
|
|
254
|
+
|
|
255
|
+
let win = false;
|
|
256
|
+
if (prediction === 'high' && total >= 8) win = true;
|
|
257
|
+
if (prediction === 'low' && total <= 6) win = true;
|
|
258
|
+
if (prediction === 'seven' && total === 7) win = true;
|
|
259
|
+
|
|
260
|
+
const payout = prediction === 'seven' ? (win ? bet * 5 : 0) : (win ? bet * 2 : 0);
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
dice1,
|
|
264
|
+
dice2,
|
|
265
|
+
total,
|
|
266
|
+
win,
|
|
267
|
+
payout,
|
|
268
|
+
prediction,
|
|
269
|
+
message: `🎲 *DICE GAME* 🎲\n\n${diceEmojis[dice1-1]} ${diceEmojis[dice2-1]}\n\nTotal: *${total}*\n\n${win ? `🎉 *YOU WIN ${payout} coins!*` : `😔 *You lose ${bet} coins!*`}`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ==================== COIN FLIP ====================
|
|
274
|
+
export function coinFlip(bet = 100, prediction = 'heads') {
|
|
275
|
+
const result = Math.random() < 0.5 ? 'heads' : 'tails';
|
|
276
|
+
const emoji = result === 'heads' ? '👑' : '🌙';
|
|
277
|
+
|
|
278
|
+
const win = prediction === result;
|
|
279
|
+
const payout = win ? bet * 2 : 0;
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
result,
|
|
283
|
+
emoji,
|
|
284
|
+
win,
|
|
285
|
+
payout,
|
|
286
|
+
prediction,
|
|
287
|
+
message: `🪙 *COIN FLIP* 🪙\n\n${emoji} *${result.toUpperCase()}*\n\nYour prediction: ${prediction}\n\n${win ? `🎉 *YOU WIN ${payout} coins!*` : `😔 *You lose ${bet} coins!*`}`
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ==================== ROULETTE ====================
|
|
292
|
+
export function roulette(bet = 100, prediction = 'red') {
|
|
293
|
+
const numbers = {
|
|
294
|
+
red: [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36],
|
|
295
|
+
black: [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35],
|
|
296
|
+
green: [0]
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const result = Math.floor(Math.random() * 37);
|
|
300
|
+
const color = result === 0 ? 'green' : numbers.red.includes(result) ? 'red' : 'black';
|
|
301
|
+
|
|
302
|
+
const colorEmoji = { red: '🔴', black: '⚫', green: '🟢' };
|
|
303
|
+
|
|
304
|
+
let win = false;
|
|
305
|
+
let payout = 0;
|
|
306
|
+
|
|
307
|
+
if (prediction === color) {
|
|
308
|
+
win = true;
|
|
309
|
+
payout = color === 'green' ? bet * 36 : bet * 2;
|
|
310
|
+
} else if (prediction === 'odd' && result !== 0 && result % 2 !== 0) {
|
|
311
|
+
win = true;
|
|
312
|
+
payout = bet * 2;
|
|
313
|
+
} else if (prediction === 'even' && result !== 0 && result % 2 === 0) {
|
|
314
|
+
win = true;
|
|
315
|
+
payout = bet * 2;
|
|
316
|
+
} else if (prediction === 'low' && result >= 1 && result <= 18) {
|
|
317
|
+
win = true;
|
|
318
|
+
payout = bet * 2;
|
|
319
|
+
} else if (prediction === 'high' && result >= 19 && result <= 36) {
|
|
320
|
+
win = true;
|
|
321
|
+
payout = bet * 2;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
number: result,
|
|
326
|
+
color,
|
|
327
|
+
emoji: colorEmoji[color],
|
|
328
|
+
win,
|
|
329
|
+
payout,
|
|
330
|
+
prediction,
|
|
331
|
+
message: `🎰 *ROULETTE* 🎰\n\n${colorEmoji[color]} *${result} ${color.toUpperCase()}*\n\nYour bet: ${prediction}\n\n${win ? `🎉 *YOU WIN ${payout} coins!*` : `😔 *You lose ${bet} coins!*`}`
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ==================== MINES ====================
|
|
336
|
+
export function createMines(rows = 5, cols = 5, mineCount = 5) {
|
|
337
|
+
const grid = [];
|
|
338
|
+
const mines = new Set();
|
|
339
|
+
|
|
340
|
+
// Place mines randomly
|
|
341
|
+
while (mines.size < mineCount) {
|
|
342
|
+
const pos = Math.floor(Math.random() * (rows * cols));
|
|
343
|
+
mines.add(pos);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Create grid
|
|
347
|
+
for (let i = 0; i < rows; i++) {
|
|
348
|
+
const row = [];
|
|
349
|
+
for (let j = 0; j < cols; j++) {
|
|
350
|
+
const pos = i * cols + j;
|
|
351
|
+
row.push({
|
|
352
|
+
isMine: mines.has(pos),
|
|
353
|
+
revealed: false
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
grid.push(row);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
grid,
|
|
361
|
+
rows,
|
|
362
|
+
cols,
|
|
363
|
+
mineCount,
|
|
364
|
+
revealed: 0,
|
|
365
|
+
totalSafe: (rows * cols) - mineCount
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function revealTile(game, row, col) {
|
|
370
|
+
if (row < 0 || row >= game.rows || col < 0 || col >= game.cols) {
|
|
371
|
+
return { error: 'Invalid position!' };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const tile = game.grid[row][col];
|
|
375
|
+
if (tile.revealed) {
|
|
376
|
+
return { error: 'Already revealed!' };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
tile.revealed = true;
|
|
380
|
+
|
|
381
|
+
if (tile.isMine) {
|
|
382
|
+
// Reveal all mines
|
|
383
|
+
for (const row of game.grid) {
|
|
384
|
+
for (const t of row) {
|
|
385
|
+
t.revealed = true;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
mine: true,
|
|
390
|
+
game,
|
|
391
|
+
message: '💥 *BOOM!* You hit a mine!'
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
game.revealed++;
|
|
396
|
+
|
|
397
|
+
// Calculate multiplier based on revealed tiles
|
|
398
|
+
const multiplier = 1 + (game.revealed * 0.5);
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
mine: false,
|
|
402
|
+
multiplier: multiplier.toFixed(1),
|
|
403
|
+
game,
|
|
404
|
+
message: `✅ Safe! Multiplier: x${multiplier.toFixed(1)}`
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function cashoutMines(game, bet) {
|
|
409
|
+
const multiplier = 1 + (game.revealed * 0.5);
|
|
410
|
+
const payout = Math.floor(bet * multiplier);
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
payout,
|
|
414
|
+
multiplier: multiplier.toFixed(1),
|
|
415
|
+
message: `💰 *CASHOUT*\n\nRevealed: ${game.revealed} tiles\nMultiplier: x${multiplier.toFixed(1)}\n\nYou win ${payout} coins!`
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ==================== TRIVIA ====================
|
|
420
|
+
const TRIVIA_QUESTIONS = [
|
|
421
|
+
{ q: "What planet is known as the Red Planet?", options: ["A) Venus", "B) Mars", "C) Jupiter", "D) Saturn"], answer: "B" },
|
|
422
|
+
{ q: "What is the largest ocean on Earth?", options: ["A) Atlantic", "B) Indian", "C) Pacific", "D) Arctic"], answer: "C" },
|
|
423
|
+
{ q: "How many continents are there?", options: ["A) 5", "B) 6", "C) 7", "D) 8"], answer: "C" },
|
|
424
|
+
{ q: "What gas do plants absorb?", options: ["A) Oxygen", "B) Nitrogen", "C) Carbon Dioxide", "D) Hydrogen"], answer: "C" },
|
|
425
|
+
{ q: "What is the speed of light?", options: ["A) 300,000 km/s", "B) 150,000 km/s", "C) 450,000 km/s", "D) 600,000 km/s"], answer: "A" },
|
|
426
|
+
{ q: "What is the largest mammal?", options: ["A) Elephant", "B) Blue Whale", "C) Giraffe", "D) Hippo"], answer: "B" },
|
|
427
|
+
{ q: "How many days in a leap year?", options: ["A) 364", "B) 365", "C) 366", "D) 367"], answer: "C" },
|
|
428
|
+
{ q: "What element has symbol 'O'?", options: ["A) Gold", "B) Oxygen", "C) Osmium", "D) All"], answer: "D" },
|
|
429
|
+
{ q: "What is the smallest prime number?", options: ["A) 0", "B) 1", "C) 2", "D) 3"], answer: "C" },
|
|
430
|
+
{ q: "What year did WW2 end?", options: ["A) 1943", "B) 1944", "C) 1945", "D) 1946"], answer: "C" },
|
|
431
|
+
];
|
|
432
|
+
|
|
433
|
+
export function trivia(bet = 100) {
|
|
434
|
+
const question = TRIVIA_QUESTIONS[Math.floor(Math.random() * TRIVIA_QUESTIONS.length)];
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
question: question.q,
|
|
438
|
+
options: question.options,
|
|
439
|
+
answer: question.answer,
|
|
440
|
+
bet,
|
|
441
|
+
message: `🧠 *TRIVIA*\n\n${question.q}\n\n${question.options.join('\n')}\n\nReply with A, B, C, or D!`
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function checkTriviaAnswer(answer, correctAnswer, bet) {
|
|
446
|
+
const win = answer.toUpperCase() === correctAnswer;
|
|
447
|
+
const payout = win ? bet * 2 : 0;
|
|
448
|
+
|
|
449
|
+
return {
|
|
450
|
+
win,
|
|
451
|
+
payout,
|
|
452
|
+
correctAnswer,
|
|
453
|
+
message: win ? `✅ *CORRECT!* You win ${payout} coins!` : `❌ *WRONG!* The answer was ${correctAnswer}. You lose ${bet} coins!`
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// ==================== RPS (Rock Paper Scissors) ====================
|
|
458
|
+
export function rps(playerChoice = 'rock') {
|
|
459
|
+
const choices = ['rock', 'paper', 'scissors'];
|
|
460
|
+
const emojis = { rock: '🪨', paper: '📄', scissors: '✂️' };
|
|
461
|
+
|
|
462
|
+
const botChoice = choices[Math.floor(Math.random() * 3)];
|
|
463
|
+
|
|
464
|
+
let result;
|
|
465
|
+
if (playerChoice === botChoice) {
|
|
466
|
+
result = 'draw';
|
|
467
|
+
} else if (
|
|
468
|
+
(playerChoice === 'rock' && botChoice === 'scissors') ||
|
|
469
|
+
(playerChoice === 'paper' && botChoice === 'rock') ||
|
|
470
|
+
(playerChoice === 'scissors' && botChoice === 'paper')
|
|
471
|
+
) {
|
|
472
|
+
result = 'win';
|
|
473
|
+
} else {
|
|
474
|
+
result = 'lose';
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
playerChoice,
|
|
479
|
+
botChoice,
|
|
480
|
+
result,
|
|
481
|
+
message: `✊ *ROCK PAPER SCISSORS*\n\nYou: ${emojis[playerChoice]} ${playerChoice.toUpperCase()}\nBot: ${emojis[botChoice]} ${botChoice.toUpperCase()}\n\n${result === 'win' ? '🎉 *YOU WIN!*' : result === 'lose' ? '😔 *YOU LOSE!*' : '🤝 *DRAW!*'}`
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export default {
|
|
486
|
+
blackjack,
|
|
487
|
+
slotMachine,
|
|
488
|
+
diceGame,
|
|
489
|
+
coinFlip,
|
|
490
|
+
roulette,
|
|
491
|
+
createMines,
|
|
492
|
+
revealTile,
|
|
493
|
+
cashoutMines,
|
|
494
|
+
trivia,
|
|
495
|
+
checkTriviaAnswer,
|
|
496
|
+
rps
|
|
497
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class CiphertextMessage {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.UNSUPPORTED_VERSION = 1;
|
|
4
|
+
this.CURRENT_VERSION = 3;
|
|
5
|
+
this.WHISPER_TYPE = 2;
|
|
6
|
+
this.PREKEY_TYPE = 3;
|
|
7
|
+
this.SENDERKEY_TYPE = 4;
|
|
8
|
+
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
9
|
+
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ciphertext-message.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as keyhelper from './keyhelper.js';
|
|
2
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
+
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
+
export class GroupSessionBuilder {
|
|
6
|
+
constructor(senderKeyStore) {
|
|
7
|
+
this.senderKeyStore = senderKeyStore;
|
|
8
|
+
}
|
|
9
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
10
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
11
|
+
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
12
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
13
|
+
}
|
|
14
|
+
async create(senderKeyName) {
|
|
15
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
16
|
+
if (senderKeyRecord.isEmpty()) {
|
|
17
|
+
const keyId = keyhelper.generateSenderKeyId();
|
|
18
|
+
const senderKey = keyhelper.generateSenderKey();
|
|
19
|
+
const signingKey = keyhelper.generateSenderSigningKey();
|
|
20
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
21
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
22
|
+
}
|
|
23
|
+
const state = senderKeyRecord.getSenderKeyState();
|
|
24
|
+
if (!state) {
|
|
25
|
+
throw new Error('No session state available');
|
|
26
|
+
}
|
|
27
|
+
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=group-session-builder.js.map
|