emusks 2.0.18 → 2.1.1

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.
@@ -0,0 +1,41 @@
1
+ function realmIdToHex(arg) {
2
+ let bytes = null;
3
+ if (arg instanceof Uint8Array || Array.isArray(arg)) bytes = Array.from(arg);
4
+ else if (arg && typeof arg === "object") bytes = Object.values(arg);
5
+ if (bytes?.length && bytes.every((b) => Number.isInteger(b) && b >= 0 && b <= 255)) {
6
+ return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
7
+ }
8
+ return null;
9
+ }
10
+
11
+ function resolverFor(tokenMap) {
12
+ const entries = tokenMap.token_map ?? [];
13
+ return (realmId) => {
14
+ const candidates = [realmIdToHex(realmId), String(realmId)].filter(Boolean);
15
+ for (const e of entries) {
16
+ if (candidates.includes(String(e.key))) return e.value?.token;
17
+ }
18
+ return null;
19
+ };
20
+ }
21
+
22
+ export async function juiceboxRegister(tokenMap, pin, secret, { timeoutMs = 90_000 } = {}) {
23
+ if (!tokenMap?.key_store_token_map_json) throw new Error("juicebox: missing token_map from AddXChatPublicKey");
24
+ const { Client, Configuration, setAuthTokenResolver } = await import("./juicebox/index.js");
25
+ setAuthTokenResolver(resolverFor(tokenMap));
26
+ const client = new Client(new Configuration(tokenMap.key_store_token_map_json), []);
27
+ const timeout = new Promise((_, rej) => setTimeout(() => rej(new Error("juicebox register timed out")), timeoutMs));
28
+ await Promise.race([
29
+ client.register(new TextEncoder().encode(pin), secret, new Uint8Array(0), Number(tokenMap.max_guess_count) || 20),
30
+ timeout,
31
+ ]);
32
+ }
33
+
34
+ // recover the secret with the PIN (for loading an identity on a new device)
35
+ export async function juiceboxRecover(tokenMap, pin) {
36
+ if (!tokenMap?.key_store_token_map_json) throw new Error("juicebox: missing token_map");
37
+ const { Client, Configuration, setAuthTokenResolver } = await import("./juicebox/index.js");
38
+ setAuthTokenResolver(resolverFor(tokenMap));
39
+ const client = new Client(new Configuration(tokenMap.key_store_token_map_json), []);
40
+ return new Uint8Array(await client.recover(new TextEncoder().encode(pin), new Uint8Array(0)));
41
+ }
@@ -0,0 +1,3 @@
1
+ // generated from the chat.x.com bundle; do not edit by hand
2
+ export const GET_INITIAL_CHAT_PAGE = "query GetInitialXChatPageQuery($max_local_sequence_id: NumericString, $query_settings: XChatPageQuerySettingsInput, $message_pull_version: Int, $include_user_public_keys: Boolean! = false , $include_juicebox_tokens: Boolean! = false , $include_all_group_member_user_objects: Boolean! = false , $include_participants_results_for_inbox_preview: Boolean! = true ) { get_initial_chat_page(max_local_sequence_id: $max_local_sequence_id, query_settings: $query_settings, message_pull_version: $message_pull_version, safety_level: XChat) { __typename ...InboxPageFragment ...MessageEventsPageResponseFragment } } fragment GroupInviteDetails on XChatGroupInviteDetails { __typename admin_user_id affiliate_id conversation_id expires_at_msec group_avatar_url group_name invite_url join_state member_count token welcome_message } fragment ApiTimelineUrl on TimelineUrl { __typename url url_type urt_endpoint_options { __typename timeline { __typename id } request_params { __typename key value } title subtitle } } fragment TimelineRichTextEntity on TimelineRichTextEntity { __typename from_index to_index ref { __typename ... on TimelineUrl { ...ApiTimelineUrl } ... on TimelineRichTextUser { user_results { __typename rest_id } } ... on TimelineRichTextMention { screen_name user_results { __typename rest_id } } ... on TimelineRichTextHashtag { text } ... on TimelineRichTextCashtag { text } ... on TimelineRichTextList { id url } } format } fragment TimelineRichText on TimelineRichText { __typename alignment entities { __typename ...TimelineRichTextEntity } rtl text } fragment AuxiliaryUserLabel on AuxiliaryUserLabel { __typename badge { __typename url } description long_description { __typename ...TimelineRichText } url { __typename ...ApiTimelineUrl } user_label_display_type user_label_type icon { __typename icon_type } } fragment HighlightedUserLabel on HighlightedUserLabel { __typename auxiliary_user_labels { __typename ...AuxiliaryUserLabel } badge { __typename url } description long_description { __typename ...TimelineRichText } url { __typename ...ApiTimelineUrl } user_label_display_type user_label_type icon { __typename icon_type } } fragment VerificationFragment on UserVerification { __typename is_blue_verified is_verified_organization is_verified_organization_affiliate verified verified_type } fragment XChatUserFragment on User { __typename rest_id avatar { __typename image_url } chat_permissions { __typename can_dm can_dm_on_xchat has_public_key can_be_added_to_group passes_premium_check dm_blocking is_trusted can_dm_reason } core @priority(value: Required) { __typename name screen_name created_at_ms } privacy { __typename protected suspended } identity_profile_labels_highlighted_label { __typename label { __typename ...HighlightedUserLabel } } verification { __typename ...VerificationFragment } profile_image_shape super_followed_by @priority(value: Low) has_welcome_message @priority(value: Low) } fragment UserUnavailableFragment on UserUnavailable { __typename message unavailable_message { __typename ...TimelineRichText } unavailable_reason unavailable_header { __typename ...TimelineRichText } } fragment TokenMapFragment on KeyStoreTokenMap { __typename realm_state realm_state_string max_guess_count recover_threshold register_threshold token_map { __typename key value { __typename token address public_key } } key_store_token_map_json } fragment UserPublicKeysFragment on User { __typename get_public_keys { __typename ... on GetPublicKeysResult { public_keys_with_token_map { __typename public_key_with_metadata { __typename public_key { __typename public_key signing_public_key identity_public_key_signature registration_method } version } token_map @include(if: $include_juicebox_tokens) { __typename ...TokenMapFragment } target_token_map @include(if: $include_juicebox_tokens) { __typename ...TokenMapFragment } } is_managed_pin_user registration_method } ... on GetPublicKeysError { error } } } fragment XChatUserResultsFragment on UserResults { __typename rest_id result { __typename ...XChatUserFragment ...UserUnavailableFragment ...UserPublicKeysFragment @include(if: $include_user_public_keys) } } fragment InboxPageConversationDataFragment on XChatGetInboxPageConversationData { __typename latest_message_events conversation_detail { __typename ... on XChatGroupConversationDetail { group_metadata { __typename group_name created_at_msec updated_at_msec group_avatar_url message_ttl_msec group_invite_details { __typename ...GroupInviteDetails } screen_capture_blocking_enabled admin_settings { __typename add_member edit_group_info send_message start_call edit_message_ttl block_screen_capture } } group_admins_results { __typename rest_id } group_members_results { __typename rest_id ...XChatUserResultsFragment @include(if: $include_all_group_member_user_objects) } group_removed_users_results { __typename rest_id } is_muted conversation_id latest_group_title_change_message_event participants_results @priority(value: Low) @include(if: $include_participants_results_for_inbox_preview) { __typename ...XChatUserResultsFragment } } ... on XChatDirectConversationDetail { message_ttl_msec screen_capture_blocking_enabled is_muted conversation_id participants_results @priority(value: Low) @include(if: $include_participants_results_for_inbox_preview) { __typename ...XChatUserResultsFragment } } } latest_conversation_key_change_events latest_notifiable_message_create_event latest_non_notifiable_message_create_event latest_read_events_per_participant { __typename participant_id_results { __typename rest_id } latest_mark_conversation_read_event } has_more latest_message_sequence_id is_deleted_by_viewer } fragment InboxPageFragment on XChatGetInboxPageResponse { __typename inboxCursor: cursor { __typename ... on XChatGetInboxPageContinueCursor { cursor_id graph_snapshot_id graph_snapshot_restarted } ... on XChatGetInboxPageEndCursor { inbox_exhausted graph_snapshot_id } } items { __typename ...InboxPageConversationDataFragment } message_requests_count message_pull_version max_user_sequence_id } fragment MessageEventsPageResponseFragment on XChatGetMessageEventsPageResponse { __typename cursor { __typename ... on XChatGetMessageEventsPageEndCursor { pull_finished } ... on XChatGetMessageEventsPageContinueCursor { max_local_sequence_id } } encoded_message_events message_requests_count error_code }";
3
+ export const GET_CONVERSATION_PAGE = "query GetConversationPageQuery($conversation_id: String, $min_local_sequence_id: NumericString!, $min_conversation_key_version: NumericString!, $query_settings: XChatPageQuerySettingsInput) { get_conversation_page(conversation_id: $conversation_id, min_local_sequence_id: $min_local_sequence_id, min_conversation_key_version: $min_conversation_key_version, query_settings: $query_settings, safety_level: XChat) { __typename encoded_message_events missing_conversation_key_change_events has_more } }";