@stridge/pay-sdk 0.0.0-stage → 0.1.0-alpha.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,3617 @@
1
+ //#region src/encoding/utf8.ts
2
+ /**
3
+ * Encodes a string as UTF-8 bytes. These are the exact bytes a signature covers and the relay forwards, so every
4
+ * signing and relay-body helper goes through here rather than through `btoa` or a Latin-1 shortcut.
5
+ *
6
+ * A lone surrogate becomes U+FFFD, as `TextEncoder` defines. `JSON.stringify` never produces one, so a body built
7
+ * with it round-trips exactly.
8
+ */
9
+ function utf8ToBytes(text) {
10
+ return new TextEncoder().encode(text);
11
+ }
12
+ /**
13
+ * Decodes UTF-8 bytes into a string, refusing malformed input rather than replacing it.
14
+ *
15
+ * @throws {TypeError} when `bytes` is not well-formed UTF-8.
16
+ */
17
+ function bytesToUtf8(bytes) {
18
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
19
+ }
20
+ //#endregion
21
+ //#region src/protocol/constants.ts
22
+ /**
23
+ * The literal protocol tag every app↔hub message carries. Anything posted to the window without it is not ours.
24
+ */
25
+ const PAY_PROTOCOL = "stridge-sua";
26
+ /**
27
+ * The protocol version this SDK speaks. A message with another version is rejected by the message guards.
28
+ */
29
+ const SUA_PROTOCOL_VERSION = 1;
30
+ /**
31
+ * The longest correlation id the guards accept, in UTF-16 code units.
32
+ */
33
+ const MAX_MESSAGE_ID_LENGTH = 128;
34
+ /**
35
+ * The longest message a sign request may carry, in **UTF-8 bytes** (a CJK character is 3, an emoji 4). It bounds what
36
+ * the hub renders and relays: the Coordinator caps a request body at 64 KiB, and the relay body carries the payload
37
+ * as hex (2 characters a byte) inside base64 (4 characters for 3). At this limit, with an EIP-191 prefix and the
38
+ * stamp, the relay request stays near 45 KB, well under the cap.
39
+ */
40
+ const MAX_SIGN_MESSAGE_BYTES = 16384;
41
+ /**
42
+ * The longest `error.message` the guards accept.
43
+ */
44
+ const MAX_ERROR_MESSAGE_LENGTH = 1024;
45
+ /**
46
+ * The longest label the Pay element guards accept, in UTF-16 code units. An empty label is valid; the renderer owns
47
+ * any accessibility fallback.
48
+ */
49
+ const MAX_ELEMENT_LABEL_LENGTH = 1024;
50
+ /** The most wallets one link C `pay-source-funds` names. */
51
+ const MAX_PAY_SOURCE_FUNDS_WALLETS = 20;
52
+ /**
53
+ * The longest app origin the relay guards accept, in UTF-16 code units.
54
+ */
55
+ const MAX_APP_ORIGIN_LENGTH = 2048;
56
+ /**
57
+ * The longest app page address (`element-page-url` and its forwards) the guards accept, in UTF-16 code units. A bound
58
+ * for validation, not a browser limit.
59
+ */
60
+ const MAX_PAGE_URL_LENGTH = 8192;
61
+ /**
62
+ * The tallest block size a Pay element may report, in CSS pixels. A bound for validation, not a measured browser
63
+ * limit.
64
+ */
65
+ const MAX_ELEMENT_BLOCK_SIZE = 16384;
66
+ /**
67
+ * The longest resize animation a Pay element may report, in milliseconds.
68
+ */
69
+ const MAX_ELEMENT_RESIZE_DURATION_MS = 1e4;
70
+ /**
71
+ * The geometry easing identifiers. `standard` means `cubic-bezier(0.4, 0, 0.2, 1)`; arbitrary CSS is never accepted.
72
+ */
73
+ const SUA_ELEMENT_GEOMETRY_EASINGS = { standard: "standard" };
74
+ /**
75
+ * The largest magnitude of any menu rect coordinate or size, in CSS pixels. A bound for validation, not a measured
76
+ * browser limit.
77
+ */
78
+ const MAX_MENU_RECT_VALUE = 1e6;
79
+ /**
80
+ * An app id: `app_` and a 26-character Crockford base32 ULID in **uppercase only**, whose first character is `0`–`7`
81
+ * (it carries 3 bits; anything above `7` overflows 128 bits). The Coordinator's `pkg/id/id.go` refuses a lowercase
82
+ * id and an overflowing one, and answers every call that carries one with `403 APP_SUSPENDED`.
83
+ */
84
+ const APP_ID_PATTERN = /^app_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
85
+ /**
86
+ * A hub frame name, as `element-init`'s `hubFrame` and the Pay element URL's `hubFrame` hint carry it: an ASCII letter
87
+ * or digit, then ASCII letters, digits, `_` or `-`. The first character excludes the reserved underscore-prefixed
88
+ * browsing-context names such as `_top`. A reader checks the length bound, 1 to {@link MAX_MESSAGE_ID_LENGTH}
89
+ * characters, first, so a huge string never reaches the pattern.
90
+ */
91
+ const HUB_FRAME_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
92
+ /**
93
+ * An EVM address: `0x` and 40 hex digits, any case.
94
+ */
95
+ const EVM_ADDRESS_PATTERN = /^0x[0-9a-fA-F]{40}$/;
96
+ /**
97
+ * The `message` of the `internal` error a framed hub page answers a request with when the request belongs in the Sua
98
+ * window: the frame cannot reach the hub's first-party storage, so it can open no round and register no keypair. It
99
+ * is the one `error.message` the app reads: on it, the app sends its next request to the Pay window. The code stays
100
+ * `internal`, so an app that does not know the value reads it as an internal error. Never rename it: the app and the
101
+ * hub ship apart, and a renamed value silently stops the switch.
102
+ */
103
+ const HUB_NEEDS_POPUP_MESSAGE = "needs-popup";
104
+ /**
105
+ * The wire type of the Fund request (app → hub): open Fund in the hub's Stridge Wallet dialog. Never rename it: the
106
+ * app and the hub ship apart, and a hub that does not know the value drops the request.
107
+ */
108
+ const PAY_FUND_REQUEST_TYPE = "fund";
109
+ /**
110
+ * The screens a Fund request may start on, as its `start` carries them. `FundStartScreen` derives from this object.
111
+ *
112
+ * - `home` — the account home.
113
+ * - `fund` — the Fund surface. A missing `start` means this one.
114
+ */
115
+ const PAY_FUND_START_SCREENS = {
116
+ home: "home",
117
+ fund: "fund"
118
+ };
119
+ /** Fund ownership notices shared by the app and hub across independently deployed versions. */
120
+ const PAY_FUND_MESSAGE_TYPES = {
121
+ received: "fund-received",
122
+ cancel: "fund-cancel"
123
+ };
124
+ /**
125
+ * The query parameters of the hub page's URL: the app sets them on the configured hub URL when it builds the
126
+ * iframe's `src` and the Pay window's URL, and the hub page reads them. Never rename one: the app and the hub ship
127
+ * apart.
128
+ *
129
+ * - `theme` — the colour scheme the hub page paints before `init` arrives. Cosmetic only.
130
+ * - `surface` — {@link HUB_SURFACE_POPUP} marks the page as the Pay window.
131
+ * - `app`, `origin` — the app id and the app page's origin, which the Pay window uses only to pick where its `ready`
132
+ * goes, and only when its registry lists that origin for that app. Untrusted: `init` is checked as in a frame.
133
+ * - `hubFrame` — the name of the app's hub frame, a discovery hint for the Pay element. It authorizes no peer.
134
+ *
135
+ * A missing, repeated or conflicting hint never selects another app.
136
+ */
137
+ const HUB_URL_PARAMS = {
138
+ theme: "theme",
139
+ surface: "surface",
140
+ app: "app",
141
+ origin: "origin",
142
+ hubFrame: "hubFrame"
143
+ };
144
+ /**
145
+ * The value of the `surface` query parameter (`HUB_URL_PARAMS.surface`) that marks the hub page as the Pay window.
146
+ */
147
+ const HUB_SURFACE_POPUP = "popup";
148
+ /**
149
+ * The value of the `surface` query parameter (`HUB_URL_PARAMS.surface`) that marks the hub page as a Pay element.
150
+ */
151
+ const HUB_SURFACE_ELEMENT = "element";
152
+ /**
153
+ * The fixed route of the Pay element on the hub origin.
154
+ */
155
+ const PAY_ELEMENT_PATH = "/elements/pay";
156
+ /**
157
+ * The failure codes a Pay element adds to `HubErrorCode` on `failed`. `ElementFailureCode` derives from this object.
158
+ * No hub sends them, so `HubErrorCode` stays as it is.
159
+ *
160
+ * - `unavailable` — the hub never completed the handshake, or reloaded while the request was in flight.
161
+ * - `popup-blocked` — the browser refused to open the Pay window the Pay element opens from the user's click.
162
+ */
163
+ const PAY_ELEMENT_FAILURE_CODES = {
164
+ unavailable: "unavailable",
165
+ popupBlocked: "popup-blocked"
166
+ };
167
+ /** Closed pay wire vocabulary and input bounds. */
168
+ const PAY_JOBS = ["pay", "deposit"];
169
+ const PAY_CURRENCIES = ["USD"];
170
+ /**
171
+ * The first steps a chosen-amount Deposit's Pay window may take: ask the `amount` (the default) or the `method`. Only
172
+ * `method` travels on the wire; a request without `firstStep` asks the amount first.
173
+ */
174
+ const PAY_FIRST_STEPS = ["amount", "method"];
175
+ const PAY_AMOUNT_PATTERN = /^(?:0|[1-9]\d{0,8})(?:\.\d{1,2})?$/;
176
+ const MAX_PAY_AMOUNT = "100000.00";
177
+ const MAX_PAY_ITEM_LENGTH = 64;
178
+ /**
179
+ * The longest payout address a pay request carries, in UTF-16 code units. The wire only bounds the string; the hub
180
+ * decides whether it is a usable address.
181
+ */
182
+ const MAX_PAY_PAYOUT_ADDRESS_LENGTH = 128;
183
+ /**
184
+ * A checkout rule id a pay request may name as its `destination`: `ckr_`, then 1 to 60 ASCII letters or digits. The
185
+ * wire checks only the shape; whether the app has the rule is the Coordinator's answer.
186
+ */
187
+ const PAY_DESTINATION_RULE_PATTERN = /^ckr_[0-9A-Za-z]{1,60}$/;
188
+ /**
189
+ * The asset of a pay request's destination address: a CAIP-19 id on an `eip155` chain (an asset namespace of 3 to 8
190
+ * lowercase letters, digits or hyphens, then a reference of 1 to 128 letters, digits, hyphens, dots or `%`). The wire
191
+ * checks only the shape; the hub decides whether the asset is listed and payable.
192
+ */
193
+ const PAY_DESTINATION_ASSET_PATTERN = /^eip155:[1-9][0-9]{0,31}\/[-a-z0-9]{3,8}:[-.%a-zA-Z0-9]{1,128}$/;
194
+ const PAY_MESSAGE_TYPES = {
195
+ payRequest: "element-pay-request",
196
+ /**
197
+ * A Deposit whose amount the user chooses in the window, within the app's optional limits. It is its own type, not
198
+ * optional keys on `element-pay-request`, so an element from before it drops this message alone.
199
+ */
200
+ depositRequest: "element-deposit-request",
201
+ payRequestAck: "element-pay-request-ack",
202
+ paid: "element-paid",
203
+ checkoutResult: "element-checkout-result",
204
+ held: "element-held",
205
+ unconfirmed: "element-unconfirmed"
206
+ };
207
+ const SUA_PAY_REQUEST_TYPE = "pay";
208
+ const PAY_ELEMENT_MESSAGE_TYPES = {
209
+ payRequest: PAY_MESSAGE_TYPES.payRequest,
210
+ depositRequest: PAY_MESSAGE_TYPES.depositRequest,
211
+ payRequestAck: PAY_MESSAGE_TYPES.payRequestAck,
212
+ init: "element-init",
213
+ config: "element-config",
214
+ focus: "focus",
215
+ ready: "element-ready",
216
+ accepted: "element-accepted",
217
+ refused: "element-refused",
218
+ configAck: "element-config-ack",
219
+ resize: "resize",
220
+ signed: "signed",
221
+ failed: "failed",
222
+ menuAnchor: "menu-anchor",
223
+ menuEnded: "element-menu-ended",
224
+ checkStatusCapability: "element-check-status-capability",
225
+ checkStatusSettled: "element-check-status-settled",
226
+ pageUrl: "element-page-url",
227
+ geometryCapabilities: "element-geometry-capabilities",
228
+ geometryTarget: "element-geometry-target",
229
+ geometryComplete: "element-geometry-complete",
230
+ geometryCancelled: "element-geometry-cancelled"
231
+ };
232
+ /**
233
+ * Pay element → app notifications on link B. Only `checkStatusRequest` has a reply.
234
+ *
235
+ * - `connected` — a connected address the element observed over link C.
236
+ * - `viewShown` — the element's real view is on screen, in place of its placeholder.
237
+ * - `loadFailed` — the view the element shows is a load failure, with a {@link PAY_ELEMENT_LOAD_FAILURE_REASONS} value.
238
+ * - `checkStatusRequest` — request to check a spent attempt; the app answers with `element-check-status-settled`
239
+ * and the same envelope id and correlation payload when its check finishes, including failure.
240
+ *
241
+ * The element posts one of `viewShown` and `loadFailed` after the `resize` for the view it revealed, and again only
242
+ * when the view turns from one to the other. An app that predates them drops them as unknown types.
243
+ */
244
+ const PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES = {
245
+ paid: PAY_MESSAGE_TYPES.paid,
246
+ connected: "element-connected",
247
+ viewShown: "element-view-shown",
248
+ loadFailed: "element-load-failed",
249
+ checkStatusRequest: "element-check-status-request"
250
+ };
251
+ /**
252
+ * Why the view a Pay element shows is a load failure, as `element-load-failed` carries it.
253
+ * `PayElementLoadFailureReason` derives from this object.
254
+ *
255
+ * - `hub-frame` — link C, the element's link to the app's hub frame, failed for this document.
256
+ * - `internal` — the element failed to load for a reason of its own.
257
+ */
258
+ const PAY_ELEMENT_LOAD_FAILURE_REASONS = {
259
+ hubFrame: "hub-frame",
260
+ internal: "internal"
261
+ };
262
+ /**
263
+ * The message types the app and its hub frame add to the existing app↔hub messages. `overlayHidden` is also reused
264
+ * from hub frame to initiating element on link C, with that operation's id.
265
+ */
266
+ const PAY_HUB_FRAME_MESSAGE_TYPES = {
267
+ diagnosticsSubscribe: "diagnostics-subscribe",
268
+ diagnosticsUnsubscribe: "diagnostics-unsubscribe",
269
+ diagnosticsStatus: "diagnostics-status",
270
+ diagnosticsInspect: "diagnostics-inspect",
271
+ diagnosticsDetails: "diagnostics-details",
272
+ diagnosticsDisconnect: "diagnostics-disconnect",
273
+ activity: "activity",
274
+ showMenu: "show-menu",
275
+ menuAccepted: "menu-accepted",
276
+ menuRefused: "menu-refused",
277
+ menuEnded: "menu-ended",
278
+ overlayHidden: "overlay-hidden"
279
+ };
280
+ /**
281
+ * The handshake message types between a Pay element and the Pay window it opens. The Pay window sends `build`, its
282
+ * own build id, immediately before `accepted` with the same id, so the Pay element can trust a sign's release code only
283
+ * from a Pay window that runs its own build.
284
+ */
285
+ const SUA_RELAY_MESSAGE_TYPES = {
286
+ init: "relay-init",
287
+ accepted: "relay-accepted",
288
+ refused: "relay-refused",
289
+ build: "relay-build"
290
+ };
291
+ /**
292
+ * The message types between a Pay element and its hub frame (link C), in both directions. The Pay element sends
293
+ * `probe`, `attach`, `confirm`, `detach`, `windowOpened`, `windowResult`, `windowError`, `windowEnded`,
294
+ * `windowState` and `pageUrl`; the hub frame sends the others. Link C also reuses the six ceremony requests, `state`, `transport`,
295
+ * `activity`, `result`, `error` and `overlay-hidden`, with their payloads unchanged.
296
+ */
297
+ const SUA_LINK_C_MESSAGE_TYPES = {
298
+ paySource: "pay-source",
299
+ /**
300
+ * The first wallet saved to the signed-in account, beside a `pay-source` that names the Stridge Wallet: the card
301
+ * shows it in the account's place when the balance does not cover the amount.
302
+ */
303
+ paySourceSaved: "pay-source-saved",
304
+ /**
305
+ * Says that the `pay-source` and `pay-source-saved` before it on the same stream are the hub frame's current pick,
306
+ * read from the session and the hub's own storage, as a Pay window reads it. A hub frame that only reports never
307
+ * sends it, so the card keeps its own record of the last pick.
308
+ */
309
+ paySourceCurrent: "pay-source-current",
310
+ /**
311
+ * The money of the wallets the card may show for the current `pay-source`: the picked wallet, or the wallets saved
312
+ * to the signed-in account beside a Stridge Wallet pick. The hub never knows the amount, so the card weighs it: a
313
+ * wallet that covers it stands in for a Stridge Wallet balance that does not. Display only.
314
+ */
315
+ paySourceFunds: "pay-source-funds",
316
+ menuPayment: "menu-payment",
317
+ payOwner: "pay-owner",
318
+ payProgress: "pay-progress",
319
+ /**
320
+ * The hub's proof, sent right after a failed `pay-progress` that allows a retry, that this payment was never sent:
321
+ * `progressId` names that `pay-progress` envelope. Only then may the card say "No money moved".
322
+ */
323
+ payUnsent: "pay-unsent",
324
+ checkoutResult: "checkout-result",
325
+ /**
326
+ * The wallet that paid a guest checkout in full, by its brand, so the card leads its paid row with that wallet's
327
+ * logo. Display only.
328
+ */
329
+ checkoutWallet: "checkout-wallet",
330
+ /**
331
+ * A guest checkout the hub holds in storage for a payment, sent before its Coordinator read answers: Pay on that
332
+ * payment reopens the checkout and starts no new one. `request` `null` says the hub holds it no longer.
333
+ */
334
+ checkoutHeld: "checkout-held",
335
+ probe: "hub-probe",
336
+ probeAck: "hub-probe-ack",
337
+ attach: "attach",
338
+ accepted: "attach-accepted",
339
+ refused: "attach-refused",
340
+ confirm: "attach-confirm",
341
+ detach: "detach",
342
+ balance: "balance",
343
+ windowOpened: "window-opened",
344
+ windowAccepted: "window-accepted",
345
+ windowRefused: "window-refused",
346
+ windowResult: "window-result",
347
+ windowError: "window-error",
348
+ windowEnded: "window-ended",
349
+ windowCancel: "window-cancel",
350
+ windowState: "window-state",
351
+ pageUrl: "page-url",
352
+ /**
353
+ * The method the card's source row showed when the person pressed Pay, for the `pay` the element sends right after
354
+ * it: the Pay window opens that method and never decides another one itself.
355
+ */
356
+ payShown: "pay-shown"
357
+ };
358
+ /**
359
+ * Why a Pay window that a Pay element opened ended, as `window-ended` reports it. `SuaWindowEndCause` derives from
360
+ * this object.
361
+ *
362
+ * - `settled` — the ceremony finished and the window closed.
363
+ * - `window-cancel` — "Cancel" on the hub frame's backdrop closed it.
364
+ * - `window-lost` — the user closed the window, or it was lost.
365
+ * - `teardown` — the provider or the Pay element went away.
366
+ */
367
+ const SUA_WINDOW_END_CAUSES = {
368
+ settled: "settled",
369
+ windowCancel: "window-cancel",
370
+ windowLost: "window-lost",
371
+ teardown: "teardown"
372
+ };
373
+ /**
374
+ * Why the hub frame asks a Pay element to close the Pay window it owns, as `window-cancel` and link E's
375
+ * `relay-close` carry it. `SuaWindowCancelCause` derives from this object; each value is also a
376
+ * {@link SUA_WINDOW_END_CAUSES} value.
377
+ */
378
+ const SUA_WINDOW_CANCEL_CAUSES = {
379
+ windowCancel: "window-cancel",
380
+ teardown: "teardown"
381
+ };
382
+ /**
383
+ * The longest hub build id link C carries, in characters: ASCII letters, digits, `_` or `-`, starting with a letter or
384
+ * digit. The build-id source emits a UUID.
385
+ */
386
+ const MAX_HUB_BUILD_ID_LENGTH = 128;
387
+ /**
388
+ * A hub build id, as link C's `attach-accepted` and `attach-confirm` and link E's `relay-build` carry it and the hub
389
+ * page's build marker emits it:
390
+ * an ASCII letter or digit, then ASCII letters, digits, `_` or `-`. A reader checks the length bound, 1 to
391
+ * {@link MAX_HUB_BUILD_ID_LENGTH} characters, first, so a huge string never reaches the pattern.
392
+ */
393
+ const HUB_BUILD_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
394
+ /**
395
+ * The longest link C balance amount, in characters: `2^256 - 1` base units as dollars with six decimals.
396
+ */
397
+ const MAX_HUB_BALANCE_AMOUNT_LENGTH = 79;
398
+ /**
399
+ * The separator of a namespaced link C id, `<attachmentId>:<nonce>`. A 36-character attachment id, the separator and a
400
+ * nonce of at most 91 characters fit {@link MAX_MESSAGE_ID_LENGTH}. The guards check only the ordinary id; the link
401
+ * checks the namespace.
402
+ */
403
+ const SUA_LINK_C_ID_SEPARATOR = ":";
404
+ /**
405
+ * The nonce prefixes of link C's ordered streams. A stream message's id is `<attachmentId>:<prefix><sequence>`, the
406
+ * sequence a canonical decimal from 1 that each stream counts on its own per attachment.
407
+ */
408
+ const SUA_LINK_C_STREAM_PREFIXES = {
409
+ state: "s_",
410
+ transport: "t_",
411
+ activity: "a_",
412
+ balance: "b_"
413
+ };
414
+ /**
415
+ * The graceful-close and ordered-state message types a Pay element and the Pay window it opened add to link E.
416
+ */
417
+ const SUA_RELAY_CONTROL_MESSAGE_TYPES = {
418
+ close: "relay-close",
419
+ closeAccepted: "relay-close-accepted",
420
+ state: "relay-state",
421
+ /** The Pay window's `pay-progress` for the element that opened it, on the operation's own stream (R1-05). */
422
+ payOwner: "relay-pay-owner",
423
+ payProgress: "relay-pay-progress",
424
+ /** Link C's `pay-unsent`, naming the `relay-pay-progress` it proves by its sequence. */
425
+ payUnsent: "relay-pay-unsent",
426
+ checkoutResult: "relay-checkout-result",
427
+ /** Link C's `checkout-wallet`, on the operation's pay stream. */
428
+ checkoutWallet: "relay-checkout-wallet",
429
+ /** The app page's address for the `pay` the element relays next: the element sends it right before. */
430
+ pageUrl: "relay-page-url",
431
+ /**
432
+ * The source the Pay window picks for the person it serves, for the card of the element that opened it, on the
433
+ * operation's pay stream with `relay-pay-progress`.
434
+ */
435
+ paySource: "relay-pay-source",
436
+ /** The first saved wallet beside the Pay window's account pick, as link C's `pay-source-saved`, on the same stream. */
437
+ paySourceSaved: "relay-pay-source-saved",
438
+ /** Link C's `pay-shown`, for the `pay` the element relays right after it. */
439
+ payShown: "relay-pay-shown"
440
+ };
441
+ /**
442
+ * The message type an app-owned Pay window (the hub page at the root with `surface=popup`, opened by the app page)
443
+ * posts to the app's hub frame, both on the hub's origin. `state` carries the window's state, ordered per window
444
+ * document, so a hub frame that only reports keeps its display-only connected copy in step with a sign-in, a sign-out
445
+ * or a switch of account the app's own Pay window ran. The app page never sends it: only a hub-origin document can post
446
+ * at the hub's origin, and the hub frame checks the sender's document before it reads the data.
447
+ */
448
+ const SUA_APP_WINDOW_MESSAGE_TYPES = { state: "app-window-state" };
449
+ /**
450
+ * The private account-email messages between Stridge-origin documents: one report per authenticated route a hub frame
451
+ * that only reports learns its state on, and the refresh request and reply of the app-owned route. Each report carries
452
+ * the account the sending Pay window shows (its identity, address and email) or `null` to clear it, beside the public
453
+ * state stream it refers to. They are new types, never new fields on `relay-state`, `window-state` or
454
+ * `app-window-state`, so a peer that predates them drops only them; they never reach an app page, an app hook or an app
455
+ * event.
456
+ *
457
+ * - `relay` — a Pay window → the Pay element or hub frame that opened it (link E), beside `relay-state`.
458
+ * - `window` — a Pay element → its confirmed hub frame attachment (link C), forwarding a `relay` report, beside
459
+ * `window-state`.
460
+ * - `appWindow` — an app-owned Pay window → the app page's hub frames, beside `app-window-state`.
461
+ * - `appWindowRefresh` — a hub frame → the app-owned Pay window whose state it shows: asks it to read its session again
462
+ * now (the frame's menu opened, or the frame gained focus). Never to the app page that opened the window.
463
+ * - `appWindowRefreshReply` — that Pay window → the asking hub frame only: the account after a session read that
464
+ * answered after the request, and that read's time.
465
+ */
466
+ const SUA_ACCOUNT_EMAIL_MESSAGE_TYPES = {
467
+ relay: "relay-account-email",
468
+ window: "window-account-email",
469
+ appWindow: "app-window-account-email",
470
+ appWindowRefresh: "app-window-account-email-refresh",
471
+ appWindowRefreshReply: "app-window-account-email-refresh-reply"
472
+ };
473
+ /**
474
+ * The longest identity id an account-email report carries, in characters. A defensive wire bound, not a format rule.
475
+ */
476
+ const MAX_ACCOUNT_IDENTITY_LENGTH = 256;
477
+ /**
478
+ * The longest email an account-email report carries, in characters. A defensive wire bound: a well-formed email is no
479
+ * proof of ownership.
480
+ */
481
+ const MAX_ACCOUNT_EMAIL_LENGTH = 320;
482
+ /**
483
+ * The longest time an account-email report may be shown, in milliseconds: a report's `validUntil` is at most this long
484
+ * after the sender's last authenticated session read and never after the session's known expiry (a sender with no
485
+ * fresh read reports `account: null`), and a receiver drops a report whose `validUntil` lies further ahead of its own
486
+ * clock.
487
+ */
488
+ const MAX_ACCOUNT_EMAIL_LEASE_MS = 5 * 6e4;
489
+ /**
490
+ * The longest keypair expiry the ordered state wrappers (`relay-state`, `window-state`, `app-window-state`) accept, in
491
+ * characters. The
492
+ * existing `state` keeps its own rule.
493
+ */
494
+ const MAX_RELAY_STATE_EXPIRY_LENGTH = 64;
495
+ /**
496
+ * The lifetime message types an app and a Pay element add to links A and B: the per-config action eligibility check
497
+ * and the element-only reload request. The Pay element sends `actionCheck` and `reloadRequest`; the app answers.
498
+ */
499
+ const PAY_ELEMENT_LIFETIME_MESSAGE_TYPES = {
500
+ actionCheck: "element-action-check",
501
+ actionEligibility: "element-action-eligibility",
502
+ reloadRequest: "element-reload-request",
503
+ reloadGrant: "element-reload-grant"
504
+ };
505
+ /**
506
+ * Why a Pay element asks the app for its one reload. `SuaElementReloadReason` derives from this object.
507
+ *
508
+ * - `build-mismatch` — the hub frame runs another hub build than the Pay element.
509
+ */
510
+ const SUA_ELEMENT_RELOAD_REASONS = { buildMismatch: "build-mismatch" };
511
+ /**
512
+ * The cookie on the hub's origin that holds the session's `csrf_token`: the hub proxy writes it beside the session
513
+ * cookie, and the hub page reads it. It is not part of the app↔hub channel; it lives here so the proxy, which runs on
514
+ * the server, and the hub page share one spelling. The `__Host-` prefix makes the browser refuse it unless it is
515
+ * `Secure`, `Path=/` and host-only, so no sibling subdomain can plant one.
516
+ */
517
+ const HUB_CSRF_COOKIE_NAME = "__Host-sua_csrf";
518
+ /**
519
+ * The Coordinator's guest cookie for a page with unpartitioned cookie access: a top-level hub page, or a hub frame with
520
+ * storage access. `HttpOnly`; the hub proxy passes it both ways and hub script never reads it. A login takes this
521
+ * guest in and clears the cookie.
522
+ */
523
+ const HUB_GUEST_COOKIE_NAME = "__Host-sua_gid";
524
+ /**
525
+ * The Coordinator's guest cookie for a partitioned hub frame (`Partitioned`, so one per top-level site). The hub opens
526
+ * no guest in such a frame; the proxy still passes the cookie both ways, so a guest the backend scopes there keeps
527
+ * working.
528
+ */
529
+ const HUB_PARTITIONED_GUEST_COOKIE_NAME = "__Host-sua_pgid";
530
+ /**
531
+ * The request header that names the guest cookie a guest write uses (`unpartitioned` or `partitioned`). The guest open
532
+ * states it in its body instead.
533
+ */
534
+ const GUEST_COOKIE_ACCESS_HEADER = "X-Stridge-Cookie-Access";
535
+ /**
536
+ * The request header a session call with `omitCredentials` sends, with the value {@link SESSION_HEADER_OMIT}. The
537
+ * hub proxy then drops the session cookie `__Host-sua_session` from what it forwards and keeps every other Coordinator
538
+ * cookie. It never forwards this header.
539
+ */
540
+ const SESSION_HEADER = "X-Stridge-Session";
541
+ /**
542
+ * The value of {@link SESSION_HEADER} that tells the hub proxy to drop the session cookie.
543
+ */
544
+ const SESSION_HEADER_OMIT = "omit";
545
+ /** One-use guest code on the accepted hub-to-window relay. */
546
+ const SUA_GUEST_HANDOFF_MESSAGE_TYPE = "relay-guest-handoff";
547
+ /** Private hub-frame continuation of an already pending Fund request. */
548
+ const SUA_FUND_WINDOW_MESSAGE_TYPE = "relay-fund-continuation";
549
+ //#endregion
550
+ //#region src/protocol/codec.ts
551
+ function createPayEnvelope(...[id, type, payload]) {
552
+ return {
553
+ protocol: PAY_PROTOCOL,
554
+ version: 1,
555
+ id,
556
+ type,
557
+ payload
558
+ };
559
+ }
560
+ /** {@link createPayEnvelope} over every message, the legacy key included; the internal entry names it `createPayEnvelope`. */
561
+ function createHubSuaEnvelope(...[id, type, payload]) {
562
+ return {
563
+ protocol: PAY_PROTOCOL,
564
+ version: 1,
565
+ id,
566
+ type,
567
+ payload
568
+ };
569
+ }
570
+ //#endregion
571
+ //#region src/protocol/shape.ts
572
+ /**
573
+ * Reports whether `value` is a plain object: non-null, not an array, with a prototype of `Object.prototype` or `null`.
574
+ * Rejects functions, `Date`, `Map`, class instances and every other exotic object.
575
+ */
576
+ function isPlainObject(value) {
577
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
578
+ const prototype = Object.getPrototypeOf(value);
579
+ return prototype === Object.prototype || prototype === null;
580
+ }
581
+ /**
582
+ * Reads `value` as a plain object whose own enumerable string keys all belong to `allowed`, and returns a snapshot of
583
+ * its values (an absent key reads as `undefined`). Returns `undefined` when `value` is not a plain object or holds a
584
+ * key outside `allowed`. Symbol keys are ignored, as `Object.keys` ignores them.
585
+ */
586
+ function readExactFields(value, allowed) {
587
+ if (!isPlainObject(value)) return;
588
+ const keys = Object.keys(value);
589
+ if (keys.length > allowed.size) return;
590
+ const fields = Object.create(null);
591
+ for (const key of keys) {
592
+ if (!allowed.has(key)) return;
593
+ fields[key] = value[key];
594
+ }
595
+ return fields;
596
+ }
597
+ /**
598
+ * Reads the listed keys of a plain object, allowing any other key, and returns a snapshot of their values. Returns
599
+ * `undefined` when `value` is not a plain object.
600
+ */
601
+ function readSomeFields(value, wanted) {
602
+ if (!isPlainObject(value)) return;
603
+ const fields = Object.create(null);
604
+ for (const key of wanted) fields[key] = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
605
+ return fields;
606
+ }
607
+ /**
608
+ * Reports whether every key of a snapshot belongs to `allowed`. A snapshot from {@link readExactFields} holds exactly
609
+ * the keys the input held, so this narrows an earlier, wider read without touching the input again.
610
+ */
611
+ function hasOnlyKeys(fields, allowed) {
612
+ return fields !== void 0 && Object.keys(fields).every((key) => allowed.has(key));
613
+ }
614
+ /**
615
+ * Reports whether `value` is a string of `minLength` to `maxLength` UTF-16 code units, inclusive.
616
+ */
617
+ function isStringOfLength(value, minLength, maxLength) {
618
+ return typeof value === "string" && value.length >= minLength && value.length <= maxLength;
619
+ }
620
+ /**
621
+ * Reports whether `value` is a string of exactly `length` UTF-16 code units that matches `pattern`. The length is
622
+ * checked first, so a huge string never reaches the regex.
623
+ */
624
+ function matchesOfLength(value, length, pattern) {
625
+ return typeof value === "string" && value.length === length && pattern.test(value);
626
+ }
627
+ /**
628
+ * Builds the set of a string union's members from a record keyed by every member, so the compiler flags a member
629
+ * added to the union and missing here.
630
+ */
631
+ function memberSet(members) {
632
+ return new Set(Object.keys(members));
633
+ }
634
+ const REFUSED = Symbol("refused");
635
+ function createSnapshotReader() {
636
+ const snapshots = /* @__PURE__ */ new Map();
637
+ const read = (value, allowed) => {
638
+ const previous = snapshots.get(value);
639
+ if (previous !== void 0) return previous !== REFUSED && hasOnlyKeys(previous, allowed) ? previous : void 0;
640
+ const fields = readExactFields(value, allowed);
641
+ snapshots.set(value, fields ?? REFUSED);
642
+ return fields;
643
+ };
644
+ function freeze(root) {
645
+ for (const fields of snapshots.values()) {
646
+ if (fields === REFUSED) continue;
647
+ for (const key of Object.keys(fields)) {
648
+ const value = fields[key];
649
+ if (typeof value !== "object" || value === null) continue;
650
+ const captured = snapshots.get(value);
651
+ if (captured === void 0 || captured === REFUSED) throw new TypeError("Unvalidated protocol record");
652
+ fields[key] = captured;
653
+ }
654
+ Object.freeze(fields);
655
+ }
656
+ return root;
657
+ }
658
+ return {
659
+ read,
660
+ freeze
661
+ };
662
+ }
663
+ //#endregion
664
+ //#region src/protocol/pay.ts
665
+ const NOTICE_KEYS = /* @__PURE__ */ new Set(["paymentId", "reference"]);
666
+ /** Exact-key and snapshot-reader validation, shared by the two separate notice types. */
667
+ function checkPaymentNotice(read, value) {
668
+ const fields = read(value, NOTICE_KEYS);
669
+ return fields !== void 0 && Object.keys(fields).length === 2 && text(fields.paymentId) && reference(fields.reference);
670
+ }
671
+ /**
672
+ * The request keys that ask where the money goes, spread into every request and terms key set below. A new destination
673
+ * key goes here once: a set that misses it makes the exact-key guard drop the whole message.
674
+ */
675
+ const PAY_DESTINATION_KEYS = ["payoutAddress", "destination"];
676
+ const DESTINATION_ADDRESS_KEYS = /* @__PURE__ */ new Set(["address", "asset"]);
677
+ const REQUEST_KEYS = /* @__PURE__ */ new Set([
678
+ "revision",
679
+ "paymentId",
680
+ "job",
681
+ "amount",
682
+ "currency",
683
+ "item",
684
+ ...PAY_DESTINATION_KEYS
685
+ ]);
686
+ const DEPOSIT_REQUEST_KEYS = /* @__PURE__ */ new Set([
687
+ "revision",
688
+ "paymentId",
689
+ "currency",
690
+ "item",
691
+ "min",
692
+ "max",
693
+ ...PAY_DESTINATION_KEYS,
694
+ "firstStep"
695
+ ]);
696
+ const HUB_REQUEST_KEYS = /* @__PURE__ */ new Set([
697
+ "paymentId",
698
+ "job",
699
+ "amount",
700
+ "currency",
701
+ "item",
702
+ "entry",
703
+ ...PAY_DESTINATION_KEYS,
704
+ "min",
705
+ "max",
706
+ "firstStep"
707
+ ]);
708
+ const HUB_ENTRIES = /* @__PURE__ */ new Set([
709
+ "pay",
710
+ "sources",
711
+ "progress",
712
+ "receipt"
713
+ ]);
714
+ const ACK_KEYS = /* @__PURE__ */ new Set(["revision"]);
715
+ const PAID_KEYS = /* @__PURE__ */ new Set([
716
+ "paymentId",
717
+ "job",
718
+ "amount",
719
+ "currency",
720
+ "method",
721
+ "reference",
722
+ "transactionHash",
723
+ "received",
724
+ "outcome"
725
+ ]);
726
+ const SOURCE_KEYS = /* @__PURE__ */ new Set([
727
+ "account",
728
+ "remembered",
729
+ "detected",
730
+ "methods"
731
+ ]);
732
+ const METHODS_KEYS = /* @__PURE__ */ new Set(["wallet", "cash"]);
733
+ const RECEIVED_KEYS = /* @__PURE__ */ new Set([
734
+ "amountBaseUnits",
735
+ "assetSymbol",
736
+ "networkId"
737
+ ]);
738
+ const TRANSACTION_KEYS = /* @__PURE__ */ new Set(["hash", "networkId"]);
739
+ /**
740
+ * C0 and C1 control characters and the bidirectional override and isolate marks: an item name holding one could hide
741
+ * or reorder what a person reads in the window. The match is on control characters on purpose.
742
+ */
743
+ const UNSAFE_ITEM_CHARACTERS = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/;
744
+ const REMEMBERED_KEYS = /* @__PURE__ */ new Set([
745
+ "kind",
746
+ "brand",
747
+ "name",
748
+ "addressTail"
749
+ ]);
750
+ const SAVED_WALLET_KEYS = /* @__PURE__ */ new Set([
751
+ "brand",
752
+ "name",
753
+ "addressTail"
754
+ ]);
755
+ const PROGRESS_KEYS = /* @__PURE__ */ new Set([
756
+ "reason",
757
+ "paymentId",
758
+ "phase",
759
+ "logo",
760
+ "brand",
761
+ "reference",
762
+ "fromLabel",
763
+ "startedAt",
764
+ "source",
765
+ "delivery",
766
+ "retry",
767
+ "received",
768
+ "receivedDisplay",
769
+ "binding",
770
+ "outcome",
771
+ "request"
772
+ ]);
773
+ const TERMS_KEYS = /* @__PURE__ */ new Set([
774
+ "job",
775
+ "amount",
776
+ "currency",
777
+ "item"
778
+ ]);
779
+ const ANY_PROGRESS_KEYS = PROGRESS_KEYS;
780
+ /** A token amount with exactly two fraction digits, as the hub formats it for the card ("23.90"). */
781
+ const DISPLAY_AMOUNT_PATTERN = /^(?:0|[1-9][0-9]{0,29})\.[0-9]{2}$/;
782
+ const text = (value) => isStringOfLength(value, 1, 128);
783
+ /** When a payment started: whole milliseconds since the epoch, from 0. */
784
+ const startedAt = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
785
+ const revision = (value) => Number.isSafeInteger(value) && typeof value === "number" && value >= 1;
786
+ const reference = (value) => typeof value === "string" && value.length <= 32 && /^[0-9A-Z-]+$/.test(value);
787
+ const hash = (value) => value === null || typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
788
+ function cents(amount) {
789
+ const [whole = "0", fraction = ""] = amount.split(".");
790
+ return BigInt(whole) * 100n + BigInt(fraction.padEnd(2, "0"));
791
+ }
792
+ /** Compares validated decimal pay amounts without floating point arithmetic. */
793
+ function comparePayAmounts(left, right) {
794
+ const a = cents(left), b = cents(right);
795
+ return a < b ? -1 : a > b ? 1 : 0;
796
+ }
797
+ /** A pay amount: {@link PAY_AMOUNT_PATTERN}, greater than zero, within {@link MAX_PAY_AMOUNT}. */
798
+ function payAmount(value) {
799
+ return typeof value === "string" && value.length <= 12 && PAY_AMOUNT_PATTERN.test(value) && comparePayAmounts(value, "0") > 0 && comparePayAmounts(value, "100000.00") <= 0;
800
+ }
801
+ function requestFields(fields) {
802
+ return payAmount(fields.amount) && termFields(fields);
803
+ }
804
+ /** Every request field but the amount. */
805
+ function termFields(fields) {
806
+ return text(fields.paymentId) && (fields.job === "pay" || fields.job === "deposit") && fields.currency === "USD" && (fields.item === null || isStringOfLength(fields.item, 1, 64) && !UNSAFE_ITEM_CHARACTERS.test(fields.item)) && (fields.payoutAddress === void 0 || isStringOfLength(fields.payoutAddress, 0, 128));
807
+ }
808
+ /**
809
+ * A request's `destination`: absent, a checkout rule id, or exactly an address and an `eip155` asset. A request that
810
+ * also carries `payoutAddress` fails: the two asks never travel together. The address object is read through `read`,
811
+ * so the decoded payload holds a detached, frozen copy.
812
+ */
813
+ function destinationField(read, fields) {
814
+ const { destination } = fields;
815
+ if (destination === void 0) return true;
816
+ if (fields.payoutAddress !== void 0) return false;
817
+ if (typeof destination === "string") return isStringOfLength(destination, 5, 64) && PAY_DESTINATION_RULE_PATTERN.test(destination);
818
+ const ask = read(destination, DESTINATION_ADDRESS_KEYS);
819
+ return ask !== void 0 && matchesOfLength(ask.address, 42, EVM_ADDRESS_PATTERN) && !/^0x0{40}$/.test(ask.address) && isStringOfLength(ask.asset, 1, 180) && PAY_DESTINATION_ASSET_PATTERN.test(ask.asset);
820
+ }
821
+ /** A chosen-amount Deposit's first step: absent (the amount first) or `method`, the one value the wire carries. */
822
+ function firstStepField(fields) {
823
+ return fields.firstStep === void 0 || fields.firstStep === "method";
824
+ }
825
+ /** A chosen-amount Deposit's limits: each absent or a pay amount, and `min` at most `max`. */
826
+ function limitFields(fields) {
827
+ const { min, max } = fields;
828
+ return (min === void 0 || payAmount(min)) && (max === void 0 || payAmount(max)) && (min === void 0 || max === void 0 || comparePayAmounts(min, max) <= 0);
829
+ }
830
+ /**
831
+ * Shares the enclosing decoder's one-read snapshots. The hub's `pay` carries either an `amount` (a fixed request) or
832
+ * `amount: null` with optional `min` and `max` (a chosen-amount Deposit).
833
+ */
834
+ function checkPayRequest(read, value, hub = false) {
835
+ const fields = read(value, hub ? HUB_REQUEST_KEYS : REQUEST_KEYS);
836
+ if (fields === void 0 || !destinationField(read, fields)) return false;
837
+ if (!hub) return requestFields(fields) && revision(fields.revision);
838
+ return (fields.amount === null ? fields.job === "deposit" && termFields(fields) && limitFields(fields) && firstStepField(fields) : requestFields(fields) && fields.min === void 0 && fields.max === void 0 && fields.firstStep === void 0) && HUB_ENTRIES.has(fields.entry);
839
+ }
840
+ /** The request's job word: a chosen-amount Deposit request is always `deposit`. Pure. */
841
+ function payJobOf(request) {
842
+ return "job" in request ? request.job : "deposit";
843
+ }
844
+ /**
845
+ * Whether a payment of `amount` (a validated pay amount, "40.00") answers `request`: the same amount for a fixed
846
+ * request; for a chosen-amount Deposit, any amount within its limits. Pure.
847
+ */
848
+ function answersPayAmount(request, amount) {
849
+ if ("amount" in request) return comparePayAmounts(request.amount, amount) === 0;
850
+ return (request.min === void 0 || comparePayAmounts(request.min, amount) <= 0) && (request.max === void 0 || comparePayAmounts(amount, request.max) <= 0);
851
+ }
852
+ /**
853
+ * Whether two requests ask the same money under the same `paymentId`: the same kind, job, currency, item, and the
854
+ * same amount or the same limits (decimal-equal: "20" is "20.00"). The destination ask and the first step are not
855
+ * terms ({@link samePayDestinationAsk} compares the ask). Pure.
856
+ */
857
+ function samePayTerms(left, right) {
858
+ if (left.paymentId !== right.paymentId || left.currency !== right.currency || left.item !== right.item) return false;
859
+ if ("amount" in left) return "amount" in right && left.job === right.job && comparePayAmounts(left.amount, right.amount) === 0;
860
+ return !("amount" in right) && sameLimit(left.min, right.min) && sameLimit(left.max, right.max);
861
+ }
862
+ /**
863
+ * Whether two requests ask for the same destination, exactly as the app sent it: the same `destination` (the same rule
864
+ * id, or the same address and asset, byte for byte); absent equals absent. The app face's revision check uses it. Pure.
865
+ */
866
+ function samePayDestinationAsk(left, right) {
867
+ return sameLegacyPayDestinationAsk(left, right);
868
+ }
869
+ /**
870
+ * {@link samePayDestinationAsk} with the older key too: the same `destination` and the same raw `payoutAddress`,
871
+ * absent equal to absent. The hub's ask identity uses it, so a saved or resumed payment compares against what the app
872
+ * asked, never against a later resolution. Internal. Pure.
873
+ */
874
+ function sameLegacyPayDestinationAsk(left, right) {
875
+ if (left.payoutAddress !== right.payoutAddress) return false;
876
+ const a = left.destination, b = right.destination;
877
+ if (a === void 0 || b === void 0 || typeof a === "string" || typeof b === "string") return a === b;
878
+ return a.address === b.address && a.asset === b.asset;
879
+ }
880
+ function sameLimit(left, right) {
881
+ return left === void 0 || right === void 0 ? left === right : comparePayAmounts(left, right) === 0;
882
+ }
883
+ /** Shares the enclosing decoder's one-read snapshots. */
884
+ function checkDepositRequest(read, value) {
885
+ const fields = read(value, DEPOSIT_REQUEST_KEYS);
886
+ return fields !== void 0 && destinationField(read, fields) && termFields({
887
+ ...fields,
888
+ job: "deposit"
889
+ }) && limitFields(fields) && firstStepField(fields) && revision(fields.revision);
890
+ }
891
+ function checkPayAck(read, value) {
892
+ const fields = read(value, ACK_KEYS);
893
+ return fields !== void 0 && revision(fields.revision);
894
+ }
895
+ function checkPaid(read, value) {
896
+ const fields = read(value, PAID_KEYS);
897
+ return fields !== void 0 && paidFields(read, fields);
898
+ }
899
+ function paidFields(read, fields) {
900
+ return requestFields({
901
+ ...fields,
902
+ item: null
903
+ }) && (fields.method === "wallet" || fields.method === "cash" || fields.method === "account" || fields.method === "transfer") && reference(fields.reference) && hash(fields.transactionHash) && checkReceived(read, fields.received) && (fields.outcome === "paid" || fields.outcome === "short");
904
+ }
905
+ function networkId(value) {
906
+ return typeof value === "string" && value.length <= 20 && /^[1-9][0-9]*$/.test(value);
907
+ }
908
+ function checkReceived(read, value) {
909
+ const f = read(value, RECEIVED_KEYS);
910
+ return f !== void 0 && typeof f.amountBaseUnits === "string" && f.amountBaseUnits.length <= 78 && /^(?:0|[1-9][0-9]*)$/.test(f.amountBaseUnits) && BigInt(f.amountBaseUnits) < 2n ** 256n && typeof f.assetSymbol === "string" && /^[A-Z0-9]{1,16}$/.test(f.assetSymbol) && networkId(f.networkId);
911
+ }
912
+ function checkTransaction(read, value) {
913
+ if (value === null) return true;
914
+ const f = read(value, TRANSACTION_KEYS);
915
+ return f !== void 0 && f.hash !== null && hash(f.hash) && networkId(f.networkId);
916
+ }
917
+ /** Exact-key pay request guard. Never throws. */
918
+ function isElementPayRequestPayload(value) {
919
+ try {
920
+ return checkPayRequest(createSnapshotReader().read, value);
921
+ } catch {
922
+ return false;
923
+ }
924
+ }
925
+ /** Exact-key chosen-amount Deposit request guard. Never throws. */
926
+ function isElementDepositRequestPayload(value) {
927
+ try {
928
+ return checkDepositRequest(createSnapshotReader().read, value);
929
+ } catch {
930
+ return false;
931
+ }
932
+ }
933
+ /** Exact-key acknowledgment guard. Never throws. */
934
+ function isElementPayRequestAckPayload(value) {
935
+ try {
936
+ return checkPayAck(createSnapshotReader().read, value);
937
+ } catch {
938
+ return false;
939
+ }
940
+ }
941
+ /** Exact-key payment notice guard. Never throws. */
942
+ function isElementPaidPayload(value) {
943
+ try {
944
+ return checkPaid(createSnapshotReader().read, value);
945
+ } catch {
946
+ return false;
947
+ }
948
+ }
949
+ /** Copies source arrays because the generic record snapshot reader accepts records only. */
950
+ function readPaySource(read, value) {
951
+ const f = read(value, SOURCE_KEYS);
952
+ if (!f || !(f.account === null || f.account === "on" || f.account === "off")) return void 0;
953
+ const detected = f.detected;
954
+ if (!Array.isArray(detected) || detected.length > 100) return void 0;
955
+ const brands = [];
956
+ for (const brand of detected) {
957
+ if (!text(brand)) return void 0;
958
+ brands.push(brand);
959
+ }
960
+ const methods = read(f.methods, METHODS_KEYS);
961
+ if (methods === void 0 || methods.wallet !== true || !(methods.cash === "direct" || methods.cash === "none" || methods.cash === "account")) return void 0;
962
+ f.methods = Object.freeze(methods);
963
+ const remembered = readPaySourceRemembered(read, f.remembered);
964
+ if (remembered === void 0) return void 0;
965
+ f.remembered = remembered;
966
+ f.detected = Object.freeze(brands);
967
+ return Object.freeze(f);
968
+ }
969
+ /** A `pay-source` `remembered`: `null`, the Stridge Wallet, or a wallet's card fields. `undefined` when it is none. */
970
+ function readPaySourceRemembered(read, value) {
971
+ if (value === null) return null;
972
+ const r = read(value, REMEMBERED_KEYS);
973
+ if (!r) return void 0;
974
+ const account = r.kind === "account" && Object.keys(r).length === 1;
975
+ const wallet = (r.kind === "last-used" || r.kind === "saved") && text(r.brand) && text(r.name) && text(r.addressTail);
976
+ return account || wallet ? Object.freeze(r) : void 0;
977
+ }
978
+ const FUNDS_WALLET_KEYS = /* @__PURE__ */ new Set([
979
+ "kind",
980
+ "brand",
981
+ "name",
982
+ "addressTail",
983
+ "cents",
984
+ "lastUsed"
985
+ ]);
986
+ /**
987
+ * Reads a `pay-source-funds` payload: exactly `wallets`, an array of at most {@link MAX_PAY_SOURCE_FUNDS_WALLETS}
988
+ * wallets, each with exactly a `kind` (`saved` or `last-used`), the card fields, `cents` (a safe integer from 0) and a
989
+ * boolean `lastUsed`. `undefined` when any part breaks its rule.
990
+ */
991
+ function readPaySourceFunds(read, value) {
992
+ const f = read(value, PAY_SOURCE_FUNDS_KEYS);
993
+ if (!f || !Array.isArray(f.wallets) || f.wallets.length > 20) return void 0;
994
+ const wallets = [];
995
+ for (const each of f.wallets) {
996
+ const w = read(each, FUNDS_WALLET_KEYS);
997
+ if (!w || Object.keys(w).length !== FUNDS_WALLET_KEYS.size || w.kind !== "saved" && w.kind !== "last-used" || !text(w.brand) || !text(w.name) || !text(w.addressTail) || !Number.isSafeInteger(w.cents) || w.cents < 0 || typeof w.lastUsed !== "boolean") return void 0;
998
+ wallets.push(Object.freeze(w));
999
+ }
1000
+ f.wallets = Object.freeze(wallets);
1001
+ return Object.freeze(f);
1002
+ }
1003
+ const PAY_SOURCE_FUNDS_KEYS = /* @__PURE__ */ new Set(["wallets"]);
1004
+ /** A `pay-source-saved` `saved`: `null`, or a saved wallet's card fields. `undefined` when it is none. */
1005
+ function readPaySavedWallet(read, value) {
1006
+ if (value === null) return null;
1007
+ const w = read(value, SAVED_WALLET_KEYS);
1008
+ return w && text(w.brand) && text(w.name) && text(w.addressTail) ? w : void 0;
1009
+ }
1010
+ function checkTerms(read, value) {
1011
+ const f = read(value, TERMS_KEYS);
1012
+ return f !== void 0 && requestFields({
1013
+ ...f,
1014
+ paymentId: "terms"
1015
+ });
1016
+ }
1017
+ /** Account terms accept explicit no-ask evidence (`null`) and legacy terms with no evidence. */
1018
+ function checkAccountTerms(read, value) {
1019
+ const f = read(value, CHECKOUT_TERMS_KEYS);
1020
+ if (f === void 0 || !requestFields({
1021
+ ...f,
1022
+ paymentId: "terms"
1023
+ })) return false;
1024
+ return f.destination === null ? f.payoutAddress === void 0 : destinationField(read, f);
1025
+ }
1026
+ const ACCOUNT_BINDING_KEYS = /* @__PURE__ */ new Set([
1027
+ "destination",
1028
+ "payout",
1029
+ "testApp"
1030
+ ]);
1031
+ const PAYOUT_KEYS = /* @__PURE__ */ new Set([
1032
+ "address",
1033
+ "networkId",
1034
+ "assetSymbol"
1035
+ ]);
1036
+ /** Account receipt bindings stay inside the hub build and never enter the public element-paid notice. */
1037
+ function checkAccountBinding(read, value) {
1038
+ const binding = read(value, ACCOUNT_BINDING_KEYS);
1039
+ if (binding === void 0 || Object.keys(binding).length !== 3 || typeof binding.testApp !== "boolean") return false;
1040
+ const validPayout = (value, allowsPayer) => {
1041
+ const payout = read(value, PAYOUT_KEYS);
1042
+ return payout !== void 0 && Object.keys(payout).length === 3 && (allowsPayer && payout.address === null || typeof payout.address === "string" && EVM_ADDRESS_PATTERN.test(payout.address) && !/^0x0{40}$/.test(payout.address)) && typeof payout.networkId === "string" && /^[1-9][0-9]*$/.test(payout.networkId) && (payout.assetSymbol === "USDC" || payout.assetSymbol === "USDT");
1043
+ };
1044
+ return validPayout(binding.destination, false) && (binding.payout === null || validPayout(binding.payout, true));
1045
+ }
1046
+ function checkPayProgress(read, value) {
1047
+ const f = read(value, ANY_PROGRESS_KEYS);
1048
+ if (!f || !hasOnlyKeys(f, PROGRESS_KEYS) || !text(f.paymentId) || !checkTransaction(read, f.source) || !checkTransaction(read, f.delivery)) return false;
1049
+ const count = Object.keys(f).length;
1050
+ if (f.phase === "failed") return (count === 6 || count === 7 && f.retry === "support" && (f.reason === "unconfirmed" || f.reason === "held" || f.reason === "reverted")) && (f.retry === "allowed" || f.retry === "support") && reference(f.reference);
1051
+ if (!(f.logo === "wallet" || f.logo === "cash" || f.logo === "account" || f.logo === "transfer") || !(f.brand === null || text(f.brand))) return false;
1052
+ if (f.phase === "paying") return (count === 7 || count === 8 && "startedAt" in f && startedAt(f.startedAt)) && (f.fromLabel === null || text(f.fromLabel));
1053
+ return f.phase === "paid" && (f.logo === "account" ? count === 13 && checkAccountBinding(read, f.binding) && checkAccountTerms(read, f.request) : count === 12 && checkTerms(read, f.request)) && reference(f.reference) && text(f.fromLabel) && checkReceived(read, f.received) && (f.receivedDisplay === null || typeof f.receivedDisplay === "string" && DISPLAY_AMOUNT_PATTERN.test(f.receivedDisplay)) && (f.outcome === "paid" || f.outcome === "short");
1054
+ }
1055
+ const CHECKOUT_KEYS = /* @__PURE__ */ new Set([
1056
+ "paymentId",
1057
+ "id",
1058
+ "state",
1059
+ "amount",
1060
+ "delivered",
1061
+ "destinationTxs"
1062
+ ]);
1063
+ const CHECKOUT_NOTICE_KEYS = /* @__PURE__ */ new Set([
1064
+ "result",
1065
+ "request",
1066
+ "payee"
1067
+ ]);
1068
+ /** The longest payee name a checkout notice carries. */
1069
+ const MAX_PAYEE_LENGTH = 512;
1070
+ const CHECKOUT_TERMS_KEYS = /* @__PURE__ */ new Set([...TERMS_KEYS, ...PAY_DESTINATION_KEYS]);
1071
+ const BASE_UNITS = /^(?:0|[1-9][0-9]{0,77})$/;
1072
+ /** Reads each untrusted field once and detaches the bounded destination transaction array. */
1073
+ function readCheckoutResult(read, value) {
1074
+ const f = read(value, CHECKOUT_KEYS);
1075
+ if (!f || Object.keys(f).length !== 6 || !text(f.paymentId) || !text(f.id) || !(f.state === "completed" || f.state === "failed" || f.state === "canceled" || f.state === "expired") || typeof f.amount !== "string" || !BASE_UNITS.test(f.amount) || f.amount === "0" || typeof f.delivered !== "string" || !BASE_UNITS.test(f.delivered)) return void 0;
1076
+ const source = f.destinationTxs;
1077
+ if (!Array.isArray(source)) return void 0;
1078
+ const length = source.length;
1079
+ if (!Number.isSafeInteger(length) || length < 0 || length > 32) return void 0;
1080
+ const txs = [];
1081
+ for (let index = 0; index < length; index += 1) {
1082
+ const tx = source[index];
1083
+ if (!isStringOfLength(tx, 1, 128) || txs.includes(tx)) return void 0;
1084
+ txs.push(tx);
1085
+ }
1086
+ f.destinationTxs = Object.freeze(txs);
1087
+ return Object.freeze(f);
1088
+ }
1089
+ /** Reads the internal checkout notice without adding fields to the public result. */
1090
+ function readHubCheckoutResult(read, value) {
1091
+ const f = read(value, CHECKOUT_NOTICE_KEYS);
1092
+ if (!f || Object.keys(f).length !== 3) return void 0;
1093
+ if (f.payee !== null && !isStringOfLength(f.payee, 1, MAX_PAYEE_LENGTH)) return void 0;
1094
+ const result = readCheckoutResult(read, f.result);
1095
+ const request = read(f.request, CHECKOUT_TERMS_KEYS);
1096
+ if (!result || !request || !destinationField(read, request) || !requestFields({
1097
+ ...request,
1098
+ paymentId: result.paymentId
1099
+ })) return void 0;
1100
+ f.result = result;
1101
+ f.request = Object.freeze(request);
1102
+ return Object.freeze(f);
1103
+ }
1104
+ const CHECKOUT_WALLET_KEYS = /* @__PURE__ */ new Set(["paymentId", "brand"]);
1105
+ /** The longest wallet brand a checkout wallet notice carries. */
1106
+ const MAX_CHECKOUT_BRAND_LENGTH = 64;
1107
+ /** Reads a checkout wallet notice: exactly `paymentId` and `brand`, each a non-empty bounded string. */
1108
+ function readCheckoutWallet(read, value) {
1109
+ const f = read(value, CHECKOUT_WALLET_KEYS);
1110
+ if (!f || Object.keys(f).length !== 2 || !text(f.paymentId) || !isStringOfLength(f.brand, 1, MAX_CHECKOUT_BRAND_LENGTH)) return void 0;
1111
+ return Object.freeze(f);
1112
+ }
1113
+ const CHECKOUT_HELD_KEYS = /* @__PURE__ */ new Set(["paymentId", "request"]);
1114
+ /** Checks a checkout hold: exactly `paymentId` and `request`, the checkout result's terms or `null`. */
1115
+ function checkCheckoutHeld(read, value) {
1116
+ const f = read(value, CHECKOUT_HELD_KEYS);
1117
+ if (!f || Object.keys(f).length !== 2 || !text(f.paymentId)) return false;
1118
+ if (f.request === null) return true;
1119
+ const request = read(f.request, CHECKOUT_TERMS_KEYS);
1120
+ return request !== void 0 && destinationField(read, request) && requestFields({
1121
+ ...request,
1122
+ paymentId: f.paymentId
1123
+ });
1124
+ }
1125
+ /** Exact-key checkout guard. Never throws; ids are 1–128 code units, amounts at most 78 digits. */
1126
+ function isElementCheckoutResultPayload(value) {
1127
+ try {
1128
+ return readCheckoutResult(createSnapshotReader().read, value) !== void 0;
1129
+ } catch {
1130
+ return false;
1131
+ }
1132
+ }
1133
+ function checkAppPayPayload(read, type, payload) {
1134
+ switch (type) {
1135
+ case PAY_MESSAGE_TYPES.payRequest: return checkPayRequest(read, payload);
1136
+ case PAY_MESSAGE_TYPES.depositRequest: return checkDepositRequest(read, payload);
1137
+ default: return false;
1138
+ }
1139
+ }
1140
+ function checkElementPayPayload(read, type, payload) {
1141
+ switch (type) {
1142
+ case PAY_MESSAGE_TYPES.payRequestAck: return checkPayAck(read, payload);
1143
+ case PAY_MESSAGE_TYPES.checkoutResult: return readCheckoutResult(read, payload) !== void 0;
1144
+ case PAY_MESSAGE_TYPES.paid: return checkPaid(read, payload);
1145
+ case PAY_MESSAGE_TYPES.held:
1146
+ case PAY_MESSAGE_TYPES.unconfirmed: return checkPaymentNotice(read, payload);
1147
+ default: return false;
1148
+ }
1149
+ }
1150
+ function checkHubPayPayload(read, type, payload) {
1151
+ switch (type) {
1152
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutResult: return readHubCheckoutResult(read, payload) !== void 0;
1153
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutWallet: return readCheckoutWallet(read, payload) !== void 0;
1154
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutHeld: return checkCheckoutHeld(read, payload);
1155
+ case SUA_LINK_C_MESSAGE_TYPES.payOwner: return checkPayOwner(read, payload);
1156
+ case SUA_LINK_C_MESSAGE_TYPES.payProgress: return checkPayProgress(read, payload);
1157
+ case SUA_LINK_C_MESSAGE_TYPES.payUnsent: {
1158
+ const fields = read(payload, PAY_UNSENT_KEYS);
1159
+ return fields !== void 0 && text(fields.paymentId) && text(fields.progressId);
1160
+ }
1161
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceSaved: {
1162
+ const fields = read(payload, PAY_SOURCE_SAVED_KEYS);
1163
+ return fields !== void 0 && readPaySavedWallet(read, fields.saved) !== void 0;
1164
+ }
1165
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceCurrent: return read(payload, EMPTY_KEYS$1) !== void 0;
1166
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceFunds: return readPaySourceFunds(read, payload) !== void 0;
1167
+ default: return false;
1168
+ }
1169
+ }
1170
+ function checkPayOwner(read, payload) {
1171
+ const fields = read(payload, /* @__PURE__ */ new Set(["paymentId", "held"]));
1172
+ return fields !== void 0 && text(fields.paymentId) && (fields.held === null || fields.held === "nothing-sent" || fields.held === "may-sent");
1173
+ }
1174
+ const PAY_SOURCE_SAVED_KEYS = /* @__PURE__ */ new Set(["saved"]);
1175
+ const PAY_UNSENT_KEYS = /* @__PURE__ */ new Set(["paymentId", "progressId"]);
1176
+ const EMPTY_KEYS$1 = /* @__PURE__ */ new Set();
1177
+ /**
1178
+ * A relayed checkout notice (`relayId`, `requestId`, `sequence` and the hub's checkout notice), read once and detached,
1179
+ * or `undefined` when any part breaks its rule. The validator and the decoder share it.
1180
+ */
1181
+ function readRelayCheckoutResult(read, value, isMessageId, isRevision) {
1182
+ const fields = read(value, RELAY_CHECKOUT_KEYS);
1183
+ if (!fields || !isMessageId(fields.relayId) || !isMessageId(fields.requestId) || !isRevision(fields.sequence)) return void 0;
1184
+ const checkout = readHubCheckoutResult(read, fields.checkout);
1185
+ if (!checkout) return void 0;
1186
+ fields.checkout = checkout;
1187
+ return Object.freeze(fields);
1188
+ }
1189
+ function checkRelayPayPayload(read, type, payload, isMessageId, isRevision) {
1190
+ switch (type) {
1191
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.checkoutResult: return readRelayCheckoutResult(read, payload, isMessageId, isRevision) !== void 0;
1192
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.checkoutWallet: {
1193
+ const fields = read(payload, RELAY_CHECKOUT_WALLET_KEYS);
1194
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && readCheckoutWallet(read, fields.wallet) !== void 0;
1195
+ }
1196
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payOwner: {
1197
+ const fields = read(payload, /* @__PURE__ */ new Set([
1198
+ "relayId",
1199
+ "requestId",
1200
+ "sequence",
1201
+ "owner"
1202
+ ]));
1203
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && checkPayOwner(read, fields.owner);
1204
+ }
1205
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payProgress: {
1206
+ const fields = read(payload, RELAY_PAY_PROGRESS_KEYS);
1207
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && checkPayProgress(read, fields.progress);
1208
+ }
1209
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payUnsent: {
1210
+ const fields = read(payload, RELAY_PAY_UNSENT_KEYS);
1211
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && text(fields.paymentId) && isRevision(fields.progressSequence);
1212
+ }
1213
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.paySource: {
1214
+ const fields = read(payload, RELAY_PAY_SOURCE_KEYS);
1215
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && readPaySourceRemembered(read, fields.remembered) !== void 0;
1216
+ }
1217
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.paySourceSaved: {
1218
+ const fields = read(payload, RELAY_PAY_SOURCE_SAVED_KEYS);
1219
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && readPaySavedWallet(read, fields.saved) !== void 0;
1220
+ }
1221
+ default: return false;
1222
+ }
1223
+ }
1224
+ const RELAY_PAY_PROGRESS_KEYS = /* @__PURE__ */ new Set([
1225
+ "relayId",
1226
+ "requestId",
1227
+ "sequence",
1228
+ "progress"
1229
+ ]);
1230
+ const RELAY_PAY_UNSENT_KEYS = /* @__PURE__ */ new Set([
1231
+ "relayId",
1232
+ "requestId",
1233
+ "sequence",
1234
+ "paymentId",
1235
+ "progressSequence"
1236
+ ]);
1237
+ const RELAY_PAY_SOURCE_KEYS = /* @__PURE__ */ new Set([
1238
+ "relayId",
1239
+ "requestId",
1240
+ "sequence",
1241
+ "remembered"
1242
+ ]);
1243
+ const RELAY_PAY_SOURCE_SAVED_KEYS = /* @__PURE__ */ new Set([
1244
+ "relayId",
1245
+ "requestId",
1246
+ "sequence",
1247
+ "saved"
1248
+ ]);
1249
+ const RELAY_CHECKOUT_KEYS = /* @__PURE__ */ new Set([
1250
+ "relayId",
1251
+ "requestId",
1252
+ "sequence",
1253
+ "checkout"
1254
+ ]);
1255
+ const RELAY_CHECKOUT_WALLET_KEYS = /* @__PURE__ */ new Set([
1256
+ "relayId",
1257
+ "requestId",
1258
+ "sequence",
1259
+ "wallet"
1260
+ ]);
1261
+ //#endregion
1262
+ //#region src/protocol/guards.ts
1263
+ /**
1264
+ * The length of every string `APP_ID_PATTERN` matches: `app_` and 26 ULID characters.
1265
+ */
1266
+ const APP_ID_LENGTH = 30;
1267
+ /**
1268
+ * The length of every string `EVM_ADDRESS_PATTERN` matches: `0x` and 40 hex digits.
1269
+ */
1270
+ const EVM_ADDRESS_LENGTH = 42;
1271
+ /**
1272
+ * The length of an EVM signature: `0x` and 65 bytes as hex.
1273
+ */
1274
+ const EVM_SIGNATURE_LENGTH = 132;
1275
+ /**
1276
+ * An EVM signature as the hub returns it: `0x`, r and s as 128 lowercase hex digits, then v as `1b` or `1c`. Applied
1277
+ * after an exact length check.
1278
+ */
1279
+ const EVM_SIGNATURE_PATTERN = /^0x[0-9a-f]{128}(?:1b|1c)$/;
1280
+ /**
1281
+ * The length of a canonical UUID: 32 hex digits and 4 dashes.
1282
+ */
1283
+ const UUID_LENGTH = 36;
1284
+ /**
1285
+ * A lowercase canonical version-4 UUID: version nibble `4`, variant nibble `8`, `9`, `a` or `b`. Applied after an exact
1286
+ * length check. Link C's attachment id and link A/B's document id use it.
1287
+ */
1288
+ const UUID_V4_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
1289
+ /**
1290
+ * A link C balance amount: canonical unsigned whole dollars (no leading zero, no sign, grouping or exponent) and
1291
+ * exactly six decimals. Applied after the `MAX_HUB_BALANCE_AMOUNT_LENGTH` check.
1292
+ */
1293
+ const BALANCE_AMOUNT_PATTERN = /^(?:0|[1-9][0-9]*)\.[0-9]{6}$/;
1294
+ /**
1295
+ * The most base units a link C balance amount may stand for: `2^256 - 1`.
1296
+ */
1297
+ const MAX_BALANCE_BASE_UNITS = 2n ** 256n - 1n;
1298
+ /**
1299
+ * The one currency a ready link C balance may name.
1300
+ */
1301
+ const BALANCE_CURRENCY = "USD";
1302
+ /**
1303
+ * The allowed keys of each object shape, for the exact-key checks.
1304
+ */
1305
+ const EMPTY_KEYS = /* @__PURE__ */ new Set();
1306
+ const ENVELOPE_KEYS = /* @__PURE__ */ new Set([
1307
+ "protocol",
1308
+ "version",
1309
+ "id",
1310
+ "type",
1311
+ "payload"
1312
+ ]);
1313
+ const ENVELOPE_KEY_LIST = [...ENVELOPE_KEYS];
1314
+ const INIT_KEYS = /* @__PURE__ */ new Set(["appId", "appearance"]);
1315
+ const APPEARANCE_PAYLOAD_KEYS = /* @__PURE__ */ new Set(["appearance"]);
1316
+ const APPEARANCE_KEYS = /* @__PURE__ */ new Set(["theme"]);
1317
+ const WIRE_APPEARANCE_KEYS = /* @__PURE__ */ new Set([...APPEARANCE_KEYS, "accent"]);
1318
+ const SIGN_KEYS = /* @__PURE__ */ new Set(["message"]);
1319
+ const FUND_KEYS = /* @__PURE__ */ new Set(["start"]);
1320
+ const FUND_START_SCREENS = new Set(Object.values(PAY_FUND_START_SCREENS));
1321
+ const TRANSPORT_KEYS = /* @__PURE__ */ new Set(["mode"]);
1322
+ const STATE_KEYS = /* @__PURE__ */ new Set([
1323
+ "status",
1324
+ "evmAddress",
1325
+ "keypairExpiresAt"
1326
+ ]);
1327
+ const REQUEST_ONLY_KEYS = /* @__PURE__ */ new Set(["request"]);
1328
+ const SIGN_IN_RESULT_KEYS = /* @__PURE__ */ new Set(["request", "evmAddress"]);
1329
+ const SIGN_RESULT_KEYS = /* @__PURE__ */ new Set(["request", "signature"]);
1330
+ const RESULT_KEYS = /* @__PURE__ */ new Set([...SIGN_IN_RESULT_KEYS, ...SIGN_RESULT_KEYS]);
1331
+ const ERROR_KEYS = /* @__PURE__ */ new Set([
1332
+ "request",
1333
+ "code",
1334
+ "message",
1335
+ "retryAfterSeconds"
1336
+ ]);
1337
+ const CARD_CONFIG_KEYS = /* @__PURE__ */ new Set([
1338
+ "revision",
1339
+ "labels",
1340
+ "action",
1341
+ "showBalance"
1342
+ ]);
1343
+ const CARD_LABEL_KEYS = /* @__PURE__ */ new Set([
1344
+ "button",
1345
+ "actionExpired",
1346
+ "done",
1347
+ "doneDescription",
1348
+ "balanceLabel"
1349
+ ]);
1350
+ const SIGN_ACTION_KEYS = /* @__PURE__ */ new Set([
1351
+ "attemptId",
1352
+ "message",
1353
+ "label"
1354
+ ]);
1355
+ const REFUSAL_KEYS = /* @__PURE__ */ new Set(["code", "message"]);
1356
+ const CONFIG_ACK_KEYS = /* @__PURE__ */ new Set(["revision"]);
1357
+ const RESIZE_KEYS = /* @__PURE__ */ new Set(["blockSize", "durationMs"]);
1358
+ const GEOMETRY_LIFETIME_KEYS = /* @__PURE__ */ new Set(["documentId", "initId"]);
1359
+ const GEOMETRY_CAPABILITIES_KEYS = /* @__PURE__ */ new Set([...GEOMETRY_LIFETIME_KEYS, "supported"]);
1360
+ const GEOMETRY_TARGET_KEYS = /* @__PURE__ */ new Set([
1361
+ ...GEOMETRY_LIFETIME_KEYS,
1362
+ ...RESIZE_KEYS,
1363
+ "easing"
1364
+ ]);
1365
+ const GEOMETRY_EASINGS = new Set(Object.values(SUA_ELEMENT_GEOMETRY_EASINGS));
1366
+ const SIGNED_KEYS = /* @__PURE__ */ new Set([
1367
+ "signature",
1368
+ "message",
1369
+ "attemptId"
1370
+ ]);
1371
+ const CEREMONY_FAILURE_KEYS = /* @__PURE__ */ new Set([
1372
+ "request",
1373
+ "code",
1374
+ "message",
1375
+ "retryAfterSeconds"
1376
+ ]);
1377
+ const FAILED_KEYS = /* @__PURE__ */ new Set([...CEREMONY_FAILURE_KEYS, "attemptId"]);
1378
+ const MENU_ANCHOR_KEYS = /* @__PURE__ */ new Set(["rect"]);
1379
+ const MENU_RECT_KEYS = /* @__PURE__ */ new Set([
1380
+ "x",
1381
+ "y",
1382
+ "width",
1383
+ "height"
1384
+ ]);
1385
+ const ACTIVITY_KEYS = /* @__PURE__ */ new Set(["pending"]);
1386
+ const SHOW_MENU_KEYS = /* @__PURE__ */ new Set(["anchor"]);
1387
+ const MENU_ENDED_KEYS = /* @__PURE__ */ new Set(["restoreFocus", "closeId"]);
1388
+ const ELEMENT_MENU_ENDED_KEYS = /* @__PURE__ */ new Set(["restoreFocus"]);
1389
+ const MENU_REFUSAL_KEYS = /* @__PURE__ */ new Set([...REFUSAL_KEYS, "retryAfterSeconds"]);
1390
+ const GUEST_HANDOFF_KEYS = /* @__PURE__ */ new Set(["handoff"]);
1391
+ const FUND_WINDOW_KEYS = /* @__PURE__ */ new Set([
1392
+ "relayId",
1393
+ "requestId",
1394
+ "walletId"
1395
+ ]);
1396
+ const RELAY_INIT_KEYS = /* @__PURE__ */ new Set([
1397
+ "appId",
1398
+ "appOrigin",
1399
+ "appearance"
1400
+ ]);
1401
+ const ELEMENT_INIT_KEYS = /* @__PURE__ */ new Set([
1402
+ "appId",
1403
+ "hubFrame",
1404
+ "appearance"
1405
+ ]);
1406
+ const ATTACHMENT_KEYS = /* @__PURE__ */ new Set(["attachmentId", "buildId"]);
1407
+ const RELAY_BUILD_KEYS = /* @__PURE__ */ new Set(["buildId"]);
1408
+ const DETACH_KEYS = /* @__PURE__ */ new Set(["attachmentId"]);
1409
+ const BALANCE_PAYLOAD_KEYS = /* @__PURE__ */ new Set(["balance"]);
1410
+ const BALANCE_KEYS = /* @__PURE__ */ new Set([
1411
+ "status",
1412
+ "amount",
1413
+ "currency"
1414
+ ]);
1415
+ const BALANCE_STATUS_ONLY_KEYS = /* @__PURE__ */ new Set(["status"]);
1416
+ const WINDOW_OPENED_KEYS = /* @__PURE__ */ new Set([
1417
+ "windowId",
1418
+ "requestId",
1419
+ "request"
1420
+ ]);
1421
+ const WINDOW_ACCEPTED_KEYS = /* @__PURE__ */ new Set(["windowId", "operationId"]);
1422
+ const WINDOW_REFUSED_KEYS = /* @__PURE__ */ new Set([
1423
+ "windowId",
1424
+ "code",
1425
+ "message"
1426
+ ]);
1427
+ const WINDOW_RESULT_KEYS = /* @__PURE__ */ new Set([
1428
+ "operationId",
1429
+ "windowId",
1430
+ "requestId",
1431
+ "result"
1432
+ ]);
1433
+ const WINDOW_ERROR_KEYS = /* @__PURE__ */ new Set([
1434
+ "operationId",
1435
+ "windowId",
1436
+ "requestId",
1437
+ "error"
1438
+ ]);
1439
+ const WINDOW_ENDED_KEYS = /* @__PURE__ */ new Set([
1440
+ "operationId",
1441
+ "windowId",
1442
+ "cause"
1443
+ ]);
1444
+ const WINDOW_CANCEL_KEYS = WINDOW_ENDED_KEYS;
1445
+ const WINDOW_STATE_KEYS = /* @__PURE__ */ new Set([
1446
+ "operationId",
1447
+ "windowId",
1448
+ "requestId",
1449
+ "relayId",
1450
+ "sequence",
1451
+ "state"
1452
+ ]);
1453
+ const RELAY_CLOSE_KEYS = /* @__PURE__ */ new Set([
1454
+ "relayId",
1455
+ "requestId",
1456
+ "request",
1457
+ "cause"
1458
+ ]);
1459
+ const PAGE_URL_KEYS = /* @__PURE__ */ new Set(["url"]);
1460
+ const RELAY_PAGE_URL_KEYS = /* @__PURE__ */ new Set(["relayId", "url"]);
1461
+ const PAY_SHOWN_KEYS = /* @__PURE__ */ new Set(["paymentId", "shown"]);
1462
+ const RELAY_PAY_SHOWN_KEYS = /* @__PURE__ */ new Set([
1463
+ "relayId",
1464
+ "paymentId",
1465
+ "shown"
1466
+ ]);
1467
+ const RELAY_STATE_KEYS = /* @__PURE__ */ new Set([
1468
+ "relayId",
1469
+ "requestId",
1470
+ "sequence",
1471
+ "state"
1472
+ ]);
1473
+ const APP_WINDOW_STATE_KEYS = /* @__PURE__ */ new Set([
1474
+ "appId",
1475
+ "appOrigin",
1476
+ "sequence",
1477
+ "state"
1478
+ ]);
1479
+ const ACCOUNT_EMAIL_ACCOUNT_KEYS = /* @__PURE__ */ new Set([
1480
+ "identityId",
1481
+ "evmAddress",
1482
+ "email",
1483
+ "validUntil"
1484
+ ]);
1485
+ const RELAY_ACCOUNT_EMAIL_KEYS = /* @__PURE__ */ new Set([
1486
+ "relayId",
1487
+ "requestId",
1488
+ "sequence",
1489
+ "stateSequence",
1490
+ "account"
1491
+ ]);
1492
+ const WINDOW_ACCOUNT_EMAIL_KEYS = /* @__PURE__ */ new Set([
1493
+ "operationId",
1494
+ "windowId",
1495
+ "requestId",
1496
+ "relayId",
1497
+ "sequence",
1498
+ "stateSequence",
1499
+ "account"
1500
+ ]);
1501
+ const APP_WINDOW_ACCOUNT_EMAIL_KEYS = /* @__PURE__ */ new Set([
1502
+ "appId",
1503
+ "appOrigin",
1504
+ "sequence",
1505
+ "stateSequence",
1506
+ "account"
1507
+ ]);
1508
+ const APP_WINDOW_ACCOUNT_EMAIL_REFRESH_KEYS = /* @__PURE__ */ new Set([
1509
+ "appId",
1510
+ "appOrigin",
1511
+ "refreshId",
1512
+ "stateSequence"
1513
+ ]);
1514
+ const APP_WINDOW_ACCOUNT_EMAIL_REFRESH_REPLY_KEYS = /* @__PURE__ */ new Set([
1515
+ "appId",
1516
+ "appOrigin",
1517
+ "refreshId",
1518
+ "stateSequence",
1519
+ "checkedAt",
1520
+ "account"
1521
+ ]);
1522
+ const ACTION_CHECK_KEYS = /* @__PURE__ */ new Set([
1523
+ "documentId",
1524
+ "initId",
1525
+ "configId",
1526
+ "revision",
1527
+ "attemptId"
1528
+ ]);
1529
+ const ACTION_ELIGIBILITY_KEYS = /* @__PURE__ */ new Set([...ACTION_CHECK_KEYS, "eligible"]);
1530
+ const RELOAD_REQUEST_KEYS = /* @__PURE__ */ new Set([
1531
+ "documentId",
1532
+ "initId",
1533
+ "reason"
1534
+ ]);
1535
+ const RELOAD_GRANT_KEYS = /* @__PURE__ */ new Set([
1536
+ "documentId",
1537
+ "initId",
1538
+ "granted"
1539
+ ]);
1540
+ const ELEMENT_CONNECTED_KEYS = /* @__PURE__ */ new Set([
1541
+ "documentId",
1542
+ "initId",
1543
+ "sequence",
1544
+ "evmAddress"
1545
+ ]);
1546
+ const ELEMENT_LOAD_FAILED_KEYS = /* @__PURE__ */ new Set(["reason"]);
1547
+ const CHECK_STATUS_CAPABILITY_KEYS = /* @__PURE__ */ new Set([
1548
+ "documentId",
1549
+ "initId",
1550
+ "supported"
1551
+ ]);
1552
+ /**
1553
+ * The runtime members of the protocol's string unions, each checked for exhaustiveness against its type.
1554
+ */
1555
+ const HUB_STATUSES = memberSet({
1556
+ checking: true,
1557
+ "signed-out": true,
1558
+ "signed-in": true,
1559
+ "session-locked": true,
1560
+ "app-suspended": true,
1561
+ "wallet-closed": true,
1562
+ unavailable: true
1563
+ });
1564
+ const DIAGNOSTICS_SESSIONS = memberSet({
1565
+ checking: true,
1566
+ signedOut: true,
1567
+ provisioning: true,
1568
+ signedIn: true,
1569
+ keypairExpired: true,
1570
+ sessionLocked: true,
1571
+ appSuspended: true,
1572
+ walletClosed: true,
1573
+ unavailable: true,
1574
+ signingOut: true
1575
+ });
1576
+ const DIAGNOSTICS_SUBSCRIPTION_KEYS = /* @__PURE__ */ new Set(["subscriptionId"]);
1577
+ const DIAGNOSTICS_DISABLED_KEYS = /* @__PURE__ */ new Set([
1578
+ "subscriptionId",
1579
+ "sequence",
1580
+ "observedAt",
1581
+ "state"
1582
+ ]);
1583
+ const DIAGNOSTICS_READY_KEYS = /* @__PURE__ */ new Set([
1584
+ ...DIAGNOSTICS_DISABLED_KEYS,
1585
+ "phase",
1586
+ "hubStatus",
1587
+ "session",
1588
+ "storage",
1589
+ "source"
1590
+ ]);
1591
+ /** Exact bounded metadata. Reporting and partitioned frames never claim a shared session. */
1592
+ function isDiagnosticsStatus(read, payload) {
1593
+ const fields = read(payload, DIAGNOSTICS_READY_KEYS);
1594
+ if (fields === void 0 || !isMessageId(fields.subscriptionId) || typeof fields.sequence !== "number" || !Number.isSafeInteger(fields.sequence) || fields.sequence < 0 || typeof fields.observedAt !== "number" || !Number.isFinite(fields.observedAt) || fields.observedAt < 0) return false;
1595
+ if (fields.state === "disabled") return hasOnlyKeys(fields, DIAGNOSTICS_DISABLED_KEYS);
1596
+ return fields.state === "ready" && (fields.phase === "connected" || fields.phase === "reporting") && isMember(fields.hubStatus, HUB_STATUSES) && (fields.session === null || isMember(fields.session, DIAGNOSTICS_SESSIONS)) && (fields.storage === "unpartitioned" || fields.storage === "partitioned") && fields.source === "provider-frame" && (!(fields.phase === "reporting" || fields.storage === "partitioned") || fields.session === null);
1597
+ }
1598
+ const DIAGNOSTICS_TARGET_KEYS = /* @__PURE__ */ new Set(["subscriptionId", "targetId"]);
1599
+ const DETAILS_WITHHELD_KEYS = /* @__PURE__ */ new Set([
1600
+ "subscriptionId",
1601
+ "sequence",
1602
+ "observedAt",
1603
+ "schemaVersion",
1604
+ "state"
1605
+ ]);
1606
+ const DETAILS_AVAILABLE_KEYS = /* @__PURE__ */ new Set([
1607
+ ...DETAILS_WITHHELD_KEYS,
1608
+ "provenance",
1609
+ "controllerProvenance",
1610
+ "heldKey",
1611
+ "sessionRead",
1612
+ "effectiveExpiresAt",
1613
+ "rememberedEmailPresent",
1614
+ "appAuthorized",
1615
+ "busy",
1616
+ "persistedKey",
1617
+ "cookieAuthority",
1618
+ "token",
1619
+ "disconnect"
1620
+ ]);
1621
+ const DETAILS_KEY_KEYS = /* @__PURE__ */ new Set([
1622
+ "status",
1623
+ "publicKeyHex",
1624
+ "registeredExpiresAt"
1625
+ ]);
1626
+ const DETAILS_SESSION_KEYS = /* @__PURE__ */ new Set(["status", "credentialExpiresAt"]);
1627
+ const DETAILS_DISCONNECT_KEYS = /* @__PURE__ */ new Set([
1628
+ "targetId",
1629
+ "appName",
1630
+ "evmAddress"
1631
+ ]);
1632
+ const DETAILS_ENTITY_STATUSES = /* @__PURE__ */ new Set([
1633
+ "idle",
1634
+ "loading",
1635
+ "ready",
1636
+ "stale",
1637
+ "error"
1638
+ ]);
1639
+ function isDiagnosticsExpiry(value) {
1640
+ return value === null || typeof value === "string" && value.length <= 64 && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(value) && Number.isFinite(Date.parse(value));
1641
+ }
1642
+ function isDiagnosticsDetails(read, payload) {
1643
+ const fields = read(payload, DETAILS_AVAILABLE_KEYS);
1644
+ if (fields === void 0 || !isMessageId(fields.subscriptionId) || fields.schemaVersion !== 1 || typeof fields.sequence !== "number" || !Number.isSafeInteger(fields.sequence) || fields.sequence < 0 || typeof fields.observedAt !== "number" || !Number.isFinite(fields.observedAt) || fields.observedAt < 0) return false;
1645
+ if (fields.state === "withheld") return hasOnlyKeys(fields, DETAILS_WITHHELD_KEYS);
1646
+ const key = read(fields.heldKey, DETAILS_KEY_KEYS);
1647
+ const session = read(fields.sessionRead, DETAILS_SESSION_KEYS);
1648
+ if (fields.state !== "available" || fields.provenance !== "driver-memory" || fields.controllerProvenance !== "controller-observation" || key === void 0 || session === void 0 || typeof key.status !== "string" || !DETAILS_ENTITY_STATUSES.has(key.status) || typeof session.status !== "string" || !DETAILS_ENTITY_STATUSES.has(session.status) || !(key.publicKeyHex === null || typeof key.publicKeyHex === "string" && /^0[23][0-9a-f]{64}$/.test(key.publicKeyHex)) || !isDiagnosticsExpiry(key.registeredExpiresAt) || !isDiagnosticsExpiry(session.credentialExpiresAt) || !isDiagnosticsExpiry(fields.effectiveExpiresAt) || typeof fields.rememberedEmailPresent !== "boolean" || fields.appAuthorized !== true || typeof fields.busy !== "boolean" || fields.persistedKey !== "not-inspected" || fields.cookieAuthority !== "not-directly-observable" || fields.token !== "not-inspected") return false;
1649
+ if (key.status !== "ready" && key.status !== "stale" && (key.publicKeyHex !== null || key.registeredExpiresAt !== null)) return false;
1650
+ if (session.status !== "ready" && session.status !== "stale" && session.credentialExpiresAt !== null) return false;
1651
+ if (fields.disconnect === null) return true;
1652
+ const target = read(fields.disconnect, DETAILS_DISCONNECT_KEYS);
1653
+ return target !== void 0 && !fields.busy && isMessageId(target.targetId) && typeof target.appName === "string" && target.appName.length > 0 && target.appName.length <= 256 && isEvmAddress(target.evmAddress);
1654
+ }
1655
+ const HUB_TRANSPORTS = memberSet({
1656
+ overlay: true,
1657
+ popup: true
1658
+ });
1659
+ const HUB_REQUEST_TYPES = memberSet({
1660
+ init: true,
1661
+ "sign-in": true,
1662
+ sign: true,
1663
+ "sign-out": true,
1664
+ disconnect: true,
1665
+ [PAY_FUND_REQUEST_TYPE]: true,
1666
+ ["pay"]: true
1667
+ });
1668
+ /**
1669
+ * Every `HubErrorCode`, as a record for {@link memberSet}, so `ElementFailureCode` extends it without a second list.
1670
+ */
1671
+ const HUB_ERROR_CODE_MEMBERS = {
1672
+ cancelled: true,
1673
+ busy: true,
1674
+ "not-initialized": true,
1675
+ "signed-out": true,
1676
+ refused: true,
1677
+ "outcome-unknown": true,
1678
+ "cosignature-required": true,
1679
+ "session-locked": true,
1680
+ "app-suspended": true,
1681
+ "rate-limited": true,
1682
+ "wallet-closed": true,
1683
+ "wallet-not-ready": true,
1684
+ network: true,
1685
+ internal: true
1686
+ };
1687
+ const HUB_ERROR_CODES = memberSet(HUB_ERROR_CODE_MEMBERS);
1688
+ const ELEMENT_FAILURE_CODES = memberSet({
1689
+ ...HUB_ERROR_CODE_MEMBERS,
1690
+ [PAY_ELEMENT_FAILURE_CODES.unavailable]: true,
1691
+ [PAY_ELEMENT_FAILURE_CODES.popupBlocked]: true
1692
+ });
1693
+ /**
1694
+ * The ceremony requests: every `HubRequestType` except `init`. A Pay window answers only these to a Pay element.
1695
+ */
1696
+ const CEREMONY_REQUESTS = memberSet({
1697
+ "sign-in": true,
1698
+ sign: true,
1699
+ "sign-out": true,
1700
+ disconnect: true,
1701
+ [PAY_FUND_REQUEST_TYPE]: true,
1702
+ ["pay"]: true
1703
+ });
1704
+ /**
1705
+ * Why a Pay window ended, as `window-ended` carries it.
1706
+ */
1707
+ const WINDOW_END_CAUSES = memberSet({
1708
+ [SUA_WINDOW_END_CAUSES.settled]: true,
1709
+ [SUA_WINDOW_END_CAUSES.windowCancel]: true,
1710
+ [SUA_WINDOW_END_CAUSES.windowLost]: true,
1711
+ [SUA_WINDOW_END_CAUSES.teardown]: true
1712
+ });
1713
+ /**
1714
+ * Why the hub frame cancels a Pay window, as `window-cancel` and `relay-close` carry it.
1715
+ */
1716
+ const WINDOW_CANCEL_CAUSES = memberSet({
1717
+ [SUA_WINDOW_CANCEL_CAUSES.windowCancel]: true,
1718
+ [SUA_WINDOW_CANCEL_CAUSES.teardown]: true
1719
+ });
1720
+ /**
1721
+ * Why a Pay element asks for its reload.
1722
+ */
1723
+ const ELEMENT_RELOAD_REASONS = memberSet({ [SUA_ELEMENT_RELOAD_REASONS.buildMismatch]: true });
1724
+ /**
1725
+ * Why a Pay element's view is a load failure, as `element-load-failed` carries it.
1726
+ */
1727
+ const ELEMENT_LOAD_FAILURE_REASONS = memberSet({
1728
+ [PAY_ELEMENT_LOAD_FAILURE_REASONS.hubFrame]: true,
1729
+ [PAY_ELEMENT_LOAD_FAILURE_REASONS.internal]: true
1730
+ });
1731
+ /**
1732
+ * The ceremony requests whose `failed` carries no attempt id.
1733
+ */
1734
+ const NON_SIGN_CEREMONY_REQUESTS = memberSet({
1735
+ "sign-in": true,
1736
+ "sign-out": true,
1737
+ disconnect: true,
1738
+ [PAY_FUND_REQUEST_TYPE]: true,
1739
+ ["pay"]: true
1740
+ });
1741
+ /**
1742
+ * Reports whether `value` is a correlation id: a non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters.
1743
+ */
1744
+ function isMessageId(value) {
1745
+ return isStringOfLength(value, 1, 128);
1746
+ }
1747
+ /**
1748
+ * Reports whether `value` is one of `members`.
1749
+ */
1750
+ function isMember(value, members) {
1751
+ return typeof value === "string" && members.has(value);
1752
+ }
1753
+ /**
1754
+ * Reports whether `value` is an app id matching `APP_ID_PATTERN`.
1755
+ */
1756
+ function isAppId(value) {
1757
+ return matchesOfLength(value, APP_ID_LENGTH, APP_ID_PATTERN);
1758
+ }
1759
+ /**
1760
+ * Reports whether `value` is an app origin: a string of 1 to `MAX_APP_ORIGIN_LENGTH` characters that `URL` reads as
1761
+ * an `http:` or `https:` URL whose `origin` is the string itself. So no path, trailing slash, credentials, query,
1762
+ * fragment, default port, opaque origin or other spelling of the same origin. Its length is checked first, so a huge
1763
+ * string is never parsed.
1764
+ */
1765
+ function isAppOrigin(value) {
1766
+ if (!isStringOfLength(value, 1, 2048)) return false;
1767
+ let url;
1768
+ try {
1769
+ url = new URL(value);
1770
+ } catch {
1771
+ return false;
1772
+ }
1773
+ return (url.protocol === "http:" || url.protocol === "https:") && url.origin === value;
1774
+ }
1775
+ /** A `pay-shown` payment id and method: a message id, and `null` or a `pay-source` `remembered`. */
1776
+ function isPayShown(read, fields) {
1777
+ return isMessageId(fields.paymentId) && readPaySourceRemembered(read, fields.shown) !== void 0;
1778
+ }
1779
+ /**
1780
+ * Reports whether `value` is an app page address: a string of 1 to `MAX_PAGE_URL_LENGTH` characters that `URL` reads
1781
+ * as an `http:` or `https:` URL whose `href` is the string itself (so the spelling `location.href` gives), with no
1782
+ * user name or password. Its length is checked first, so a huge string is never parsed.
1783
+ */
1784
+ function isPageUrl(value) {
1785
+ if (!isStringOfLength(value, 1, 8192)) return false;
1786
+ let url;
1787
+ try {
1788
+ url = new URL(value);
1789
+ } catch {
1790
+ return false;
1791
+ }
1792
+ return (url.protocol === "http:" || url.protocol === "https:") && url.href === value && url.username === "" && url.password === "";
1793
+ }
1794
+ /**
1795
+ * Reports whether `value` is an EVM address matching `EVM_ADDRESS_PATTERN`.
1796
+ */
1797
+ function isEvmAddress(value) {
1798
+ return matchesOfLength(value, EVM_ADDRESS_LENGTH, EVM_ADDRESS_PATTERN);
1799
+ }
1800
+ /** Reads the theme and discards the legacy accent from the decoded snapshot. */
1801
+ function hasWireAppearance(read, value) {
1802
+ const fields = read(value, WIRE_APPEARANCE_KEYS);
1803
+ if (fields === void 0 || !hasAppearanceTheme(fields)) return false;
1804
+ delete fields.accent;
1805
+ return true;
1806
+ }
1807
+ function hasAppearanceTheme(fields) {
1808
+ return fields?.theme === "dark" || fields?.theme === "light";
1809
+ }
1810
+ /**
1811
+ * Checks an `appearance` payload: exactly `appearance`, a valid appearance.
1812
+ */
1813
+ function isAppearancePayload(read, payload) {
1814
+ const fields = read(payload, APPEARANCE_PAYLOAD_KEYS);
1815
+ return fields !== void 0 && hasWireAppearance(read, fields.appearance);
1816
+ }
1817
+ /**
1818
+ * Reports whether `value` is a message to sign: a non-empty string whose UTF-8 encoding is at most
1819
+ * `MAX_SIGN_MESSAGE_BYTES` bytes. Its UTF-16 length is checked first, so a huge string is never encoded.
1820
+ */
1821
+ function isSignText(value) {
1822
+ return isStringOfLength(value, 1, 16384) && utf8ToBytes(value).length <= 16384;
1823
+ }
1824
+ /**
1825
+ * Reads a strict envelope: exactly the envelope keys, this protocol and version, a valid id and a plain-object
1826
+ * payload. Returns the snapshot, or `undefined` when any rule fails.
1827
+ */
1828
+ function readStrictEnvelope(read, value) {
1829
+ const fields = read(value, ENVELOPE_KEYS);
1830
+ if (fields === void 0) return;
1831
+ if (fields.protocol !== "stridge-sua" || fields.version !== 1) return;
1832
+ if (!isMessageId(fields.id) || typeof fields.type !== "string" || !isPlainObject(fields.payload)) return;
1833
+ return fields;
1834
+ }
1835
+ /**
1836
+ * Checks an app → hub payload against its type's rules.
1837
+ */
1838
+ function isAppPayload(read, type, payload) {
1839
+ switch (type) {
1840
+ case "init": {
1841
+ const fields = read(payload, INIT_KEYS);
1842
+ return fields !== void 0 && isAppId(fields.appId) && hasWireAppearance(read, fields.appearance);
1843
+ }
1844
+ case "appearance": return isAppearancePayload(read, payload);
1845
+ case "sign-in":
1846
+ case "sign-out":
1847
+ case "disconnect":
1848
+ case PAY_FUND_MESSAGE_TYPES.cancel: return read(payload, EMPTY_KEYS) !== void 0;
1849
+ case "sign": {
1850
+ const fields = read(payload, SIGN_KEYS);
1851
+ return fields !== void 0 && isSignText(fields.message);
1852
+ }
1853
+ case PAY_FUND_REQUEST_TYPE: {
1854
+ const fields = read(payload, FUND_KEYS);
1855
+ return fields !== void 0 && (fields.start === void 0 || isMember(fields.start, FUND_START_SCREENS));
1856
+ }
1857
+ default: return false;
1858
+ }
1859
+ }
1860
+ /**
1861
+ * Checks a `transport` payload: exactly `mode`, a `HubTransport`.
1862
+ */
1863
+ function isTransportPayload(read, payload) {
1864
+ const fields = read(payload, TRANSPORT_KEYS);
1865
+ return fields !== void 0 && isMember(fields.mode, HUB_TRANSPORTS);
1866
+ }
1867
+ /**
1868
+ * Checks a state snapshot: a `HubStatus`, and an optional EVM address and keypair expiry. An expiry is a string of 1 to
1869
+ * `maxExpiryLength` characters, its length checked before `Date.parse` reads it as a finite number. The existing
1870
+ * `state` passes no bound; the ordered state wrappers pass `MAX_RELAY_STATE_EXPIRY_LENGTH`.
1871
+ */
1872
+ function isStateSnapshot(read, value, maxExpiryLength = Number.POSITIVE_INFINITY) {
1873
+ const fields = read(value, STATE_KEYS);
1874
+ if (fields === void 0 || !isMember(fields.status, HUB_STATUSES)) return false;
1875
+ if (fields.evmAddress !== void 0 && !isEvmAddress(fields.evmAddress)) return false;
1876
+ const expiresAt = fields.keypairExpiresAt;
1877
+ return expiresAt === void 0 || isStringOfLength(expiresAt, 1, maxExpiryLength) && Number.isFinite(Date.parse(expiresAt));
1878
+ }
1879
+ /**
1880
+ * Checks a `state` payload: a `HubStatus`, and an optional EVM address and keypair expiry, with no bound on the
1881
+ * expiry's length.
1882
+ */
1883
+ function isStatePayload(read, payload) {
1884
+ return isStateSnapshot(read, payload);
1885
+ }
1886
+ /**
1887
+ * Reports whether `value` is an EVM signature matching `EVM_SIGNATURE_PATTERN`.
1888
+ */
1889
+ function isEvmSignature(value) {
1890
+ return matchesOfLength(value, EVM_SIGNATURE_LENGTH, EVM_SIGNATURE_PATTERN);
1891
+ }
1892
+ /**
1893
+ * Checks a `result` payload, keyed by the `request` it answers, which must be one of `requests`.
1894
+ */
1895
+ function isResultPayload(read, payload, requests = HUB_REQUEST_TYPES) {
1896
+ const fields = read(payload, RESULT_KEYS);
1897
+ if (!isMember(fields?.request, requests)) return false;
1898
+ switch (fields?.request) {
1899
+ case "init":
1900
+ case "sign-out":
1901
+ case "disconnect":
1902
+ case PAY_FUND_REQUEST_TYPE:
1903
+ case "pay": return hasOnlyKeys(fields, REQUEST_ONLY_KEYS);
1904
+ case "sign-in": return hasOnlyKeys(fields, SIGN_IN_RESULT_KEYS) && isEvmAddress(fields.evmAddress);
1905
+ case "sign": return hasOnlyKeys(fields, SIGN_RESULT_KEYS) && isEvmSignature(fields.signature);
1906
+ default: return false;
1907
+ }
1908
+ }
1909
+ /**
1910
+ * Reports whether `value` is a developer-facing error description: a string of at most `MAX_ERROR_MESSAGE_LENGTH`
1911
+ * characters, possibly empty.
1912
+ */
1913
+ function isErrorDetail(value) {
1914
+ return isStringOfLength(value, 0, MAX_ERROR_MESSAGE_LENGTH);
1915
+ }
1916
+ /**
1917
+ * Reports whether `value` is an optional wait: absent (`undefined`), or a non-negative safe integer of seconds.
1918
+ */
1919
+ function isOptionalRetryAfterSeconds(value) {
1920
+ return value === void 0 || Number.isSafeInteger(value) && value >= 0;
1921
+ }
1922
+ /**
1923
+ * Checks an `error` payload: a request type of `requests`, an error code, a bounded message and an optional wait.
1924
+ */
1925
+ function isErrorPayload(read, payload, requests = HUB_REQUEST_TYPES) {
1926
+ const fields = read(payload, ERROR_KEYS);
1927
+ if (fields === void 0) return false;
1928
+ if (!isMember(fields.request, requests) || !isMember(fields.code, HUB_ERROR_CODES)) return false;
1929
+ return isErrorDetail(fields.message) && isOptionalRetryAfterSeconds(fields.retryAfterSeconds);
1930
+ }
1931
+ /**
1932
+ * Checks a hub → app payload against its type's rules.
1933
+ */
1934
+ function isHubPayload(read, type, payload) {
1935
+ switch (type) {
1936
+ case "ready":
1937
+ case "overlay-open":
1938
+ case "overlay-close":
1939
+ case PAY_FUND_MESSAGE_TYPES.received: return read(payload, EMPTY_KEYS) !== void 0;
1940
+ case "transport": return isTransportPayload(read, payload);
1941
+ case "state": return isStatePayload(read, payload);
1942
+ case "result": return isResultPayload(read, payload);
1943
+ case "error": return isErrorPayload(read, payload);
1944
+ default: return false;
1945
+ }
1946
+ }
1947
+ /**
1948
+ * Reports whether `value` is a config bundle's revision: a safe integer from 1.
1949
+ */
1950
+ function isRevision(value) {
1951
+ return Number.isSafeInteger(value) && value >= 1;
1952
+ }
1953
+ /**
1954
+ * Reports whether `value` is a label set: a plain object whose keys all belong to `allowed`, each absent, `undefined`
1955
+ * or a string of at most `MAX_ELEMENT_LABEL_LENGTH` characters.
1956
+ */
1957
+ function isLabels(read, value, allowed) {
1958
+ const fields = read(value, allowed);
1959
+ return fields !== void 0 && Object.values(fields).every((label) => label === void 0 || isStringOfLength(label, 0, 1024));
1960
+ }
1961
+ /**
1962
+ * Reports whether `value` is a card's sign action: exactly an attempt id, a message to sign and a label.
1963
+ */
1964
+ function isSignAction(read, value) {
1965
+ const fields = read(value, SIGN_ACTION_KEYS);
1966
+ return fields !== void 0 && isMessageId(fields.attemptId) && isSignText(fields.message) && isStringOfLength(fields.label, 0, 1024);
1967
+ }
1968
+ /**
1969
+ * Checks an `element-config` payload against the exact bundle keys and field rules.
1970
+ */
1971
+ function isElementConfigPayload(read, payload) {
1972
+ const fields = read(payload, CARD_CONFIG_KEYS);
1973
+ return fields !== void 0 && isRevision(fields.revision) && isLabels(read, fields.labels, CARD_LABEL_KEYS) && (fields.action === null || isSignAction(read, fields.action)) && typeof fields.showBalance === "boolean";
1974
+ }
1975
+ /**
1976
+ * Reports whether `value` is a hub frame name: a string of 1 to `MAX_MESSAGE_ID_LENGTH` characters matching
1977
+ * {@link HUB_FRAME_NAME_PATTERN}. The length is checked first, so a huge string never reaches the regex.
1978
+ */
1979
+ function isHubFrameName(value) {
1980
+ return isStringOfLength(value, 1, 128) && HUB_FRAME_NAME_PATTERN.test(value);
1981
+ }
1982
+ /**
1983
+ * Checks an `element-init` payload: exactly an app id, a hub frame name and a valid appearance.
1984
+ */
1985
+ function isElementInitPayload(read, payload) {
1986
+ const fields = read(payload, ELEMENT_INIT_KEYS);
1987
+ return fields !== void 0 && isAppId(fields.appId) && isHubFrameName(fields.hubFrame) && hasWireAppearance(read, fields.appearance);
1988
+ }
1989
+ /**
1990
+ * Checks an app → Pay element payload against its type's rules.
1991
+ */
1992
+ function isAppElementPayload(read, type, payload) {
1993
+ switch (type) {
1994
+ case PAY_MESSAGE_TYPES.payRequest:
1995
+ case PAY_MESSAGE_TYPES.depositRequest: return checkAppPayPayload(read, type, payload);
1996
+ case PAY_ELEMENT_MESSAGE_TYPES.geometryCapabilities: return isGeometryCapabilitiesPayload(read, payload);
1997
+ case PAY_ELEMENT_MESSAGE_TYPES.geometryComplete:
1998
+ case PAY_ELEMENT_MESSAGE_TYPES.geometryCancelled: return hasGeometryLifetime(read(payload, GEOMETRY_LIFETIME_KEYS));
1999
+ case PAY_ELEMENT_MESSAGE_TYPES.menuEnded: {
2000
+ const fields = read(payload, ELEMENT_MENU_ENDED_KEYS);
2001
+ return fields !== void 0 && typeof fields.restoreFocus === "boolean";
2002
+ }
2003
+ case PAY_ELEMENT_MESSAGE_TYPES.init: return isElementInitPayload(read, payload);
2004
+ case PAY_ELEMENT_MESSAGE_TYPES.config: return isElementConfigPayload(read, payload);
2005
+ case PAY_ELEMENT_MESSAGE_TYPES.focus: return read(payload, EMPTY_KEYS) !== void 0;
2006
+ case "appearance": return isAppearancePayload(read, payload);
2007
+ case PAY_ELEMENT_LIFETIME_MESSAGE_TYPES.actionEligibility: return isActionEligibilityPayload(read, payload);
2008
+ case PAY_ELEMENT_LIFETIME_MESSAGE_TYPES.reloadGrant: return isReloadGrantPayload(read, payload);
2009
+ case PAY_ELEMENT_MESSAGE_TYPES.checkStatusCapability: {
2010
+ const fields = read(payload, CHECK_STATUS_CAPABILITY_KEYS);
2011
+ return fields !== void 0 && isUuid(fields.documentId) && isMessageId(fields.initId) && typeof fields.supported === "boolean";
2012
+ }
2013
+ case PAY_ELEMENT_MESSAGE_TYPES.checkStatusSettled: return isActionCheckPayload(read, payload);
2014
+ case PAY_ELEMENT_MESSAGE_TYPES.pageUrl: {
2015
+ const fields = read(payload, PAGE_URL_KEYS);
2016
+ return fields !== void 0 && isPageUrl(fields.url);
2017
+ }
2018
+ default: return false;
2019
+ }
2020
+ }
2021
+ /**
2022
+ * Reports whether `value` is a finite number from `min` to `max`, inclusive. Fractions are valid.
2023
+ */
2024
+ function isFiniteWithin(value, min, max) {
2025
+ return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
2026
+ }
2027
+ /**
2028
+ * Checks a handshake refusal payload: exactly a `HubErrorCode` and a bounded message. It names no request.
2029
+ */
2030
+ function isRefusalPayload(read, payload) {
2031
+ const fields = read(payload, REFUSAL_KEYS);
2032
+ return fields !== void 0 && isMember(fields.code, HUB_ERROR_CODES) && isErrorDetail(fields.message);
2033
+ }
2034
+ /**
2035
+ * Checks a `resize` payload: a finite block size from 0 to `MAX_ELEMENT_BLOCK_SIZE`, and a whole duration from 0 to
2036
+ * `MAX_ELEMENT_RESIZE_DURATION_MS`. Both are required.
2037
+ */
2038
+ function isResizePayload(read, payload) {
2039
+ const fields = read(payload, RESIZE_KEYS);
2040
+ if (fields === void 0 || !isFiniteWithin(fields.blockSize, 0, 16384)) return false;
2041
+ const durationMs = fields.durationMs;
2042
+ return Number.isSafeInteger(durationMs) && isFiniteWithin(durationMs, 0, 1e4);
2043
+ }
2044
+ /** Checks the document and accepted-init correlation after one exact-key read. */
2045
+ function hasGeometryLifetime(fields) {
2046
+ return fields !== void 0 && isUuid(fields.documentId) && isMessageId(fields.initId);
2047
+ }
2048
+ /** Checks the bidirectional geometry advertisement without changing either handshake. */
2049
+ function isGeometryCapabilitiesPayload(read, payload) {
2050
+ const fields = read(payload, GEOMETRY_CAPABILITIES_KEYS);
2051
+ return hasGeometryLifetime(fields) && typeof fields.supported === "boolean";
2052
+ }
2053
+ /** Checks a target's lifetime, bounded geometry and fixed easing vocabulary in one payload read. */
2054
+ function isGeometryTargetPayload(read, payload) {
2055
+ const fields = read(payload, GEOMETRY_TARGET_KEYS);
2056
+ return hasGeometryLifetime(fields) && isFiniteWithin(fields.blockSize, 0, 16384) && Number.isSafeInteger(fields.durationMs) && isFiniteWithin(fields.durationMs, 0, 1e4) && isMember(fields.easing, GEOMETRY_EASINGS);
2057
+ }
2058
+ /**
2059
+ * Checks a `signed` payload: exactly a signature, the signed message and the attempt id.
2060
+ */
2061
+ function isSignedPayload(read, payload) {
2062
+ const fields = read(payload, SIGNED_KEYS);
2063
+ return fields !== void 0 && isEvmSignature(fields.signature) && isSignText(fields.message) && isMessageId(fields.attemptId);
2064
+ }
2065
+ /**
2066
+ * Checks a `failed` payload, keyed by the `request` that failed. The payload is read once over the sign branch's
2067
+ * keys; a sign failure needs an attempt id, and every other ceremony's failure must not hold the key at all.
2068
+ */
2069
+ function isFailedPayload(read, payload) {
2070
+ const fields = read(payload, FAILED_KEYS);
2071
+ if (fields === void 0 || !isMember(fields.code, ELEMENT_FAILURE_CODES)) return false;
2072
+ if (!isErrorDetail(fields.message) || !isOptionalRetryAfterSeconds(fields.retryAfterSeconds)) return false;
2073
+ if (fields.request === "sign") return isMessageId(fields.attemptId);
2074
+ return isMember(fields.request, NON_SIGN_CEREMONY_REQUESTS) && hasOnlyKeys(fields, CEREMONY_FAILURE_KEYS);
2075
+ }
2076
+ /**
2077
+ * Reports whether `value` is a menu rect: exactly `x`, `y`, `width` and `height`, each finite; `x` and `y` within
2078
+ * ±`MAX_MENU_RECT_VALUE`, `width` and `height` from 0 to `MAX_MENU_RECT_VALUE`.
2079
+ */
2080
+ function isMenuRect(read, value) {
2081
+ const fields = read(value, MENU_RECT_KEYS);
2082
+ return fields !== void 0 && isFiniteWithin(fields.x, -1e6, 1e6) && isFiniteWithin(fields.y, -1e6, 1e6) && isFiniteWithin(fields.width, 0, 1e6) && isFiniteWithin(fields.height, 0, 1e6);
2083
+ }
2084
+ /**
2085
+ * Checks a Pay element → app payload against its type's rules.
2086
+ */
2087
+ function isElementPayload(read, type, payload) {
2088
+ switch (type) {
2089
+ case PAY_MESSAGE_TYPES.payRequestAck:
2090
+ case PAY_MESSAGE_TYPES.checkoutResult:
2091
+ case PAY_MESSAGE_TYPES.paid:
2092
+ case PAY_MESSAGE_TYPES.held:
2093
+ case PAY_MESSAGE_TYPES.unconfirmed: return checkElementPayPayload(read, type, payload);
2094
+ case PAY_ELEMENT_MESSAGE_TYPES.geometryCapabilities: return isGeometryCapabilitiesPayload(read, payload);
2095
+ case PAY_ELEMENT_MESSAGE_TYPES.geometryTarget: return isGeometryTargetPayload(read, payload);
2096
+ case PAY_ELEMENT_MESSAGE_TYPES.ready:
2097
+ case PAY_ELEMENT_MESSAGE_TYPES.accepted: return read(payload, EMPTY_KEYS) !== void 0;
2098
+ case PAY_ELEMENT_MESSAGE_TYPES.refused: return isRefusalPayload(read, payload);
2099
+ case PAY_ELEMENT_MESSAGE_TYPES.configAck: {
2100
+ const fields = read(payload, CONFIG_ACK_KEYS);
2101
+ return fields !== void 0 && isRevision(fields.revision);
2102
+ }
2103
+ case PAY_ELEMENT_MESSAGE_TYPES.resize: return isResizePayload(read, payload);
2104
+ case PAY_ELEMENT_MESSAGE_TYPES.signed: return isSignedPayload(read, payload);
2105
+ case PAY_ELEMENT_MESSAGE_TYPES.failed: return isFailedPayload(read, payload);
2106
+ case PAY_ELEMENT_MESSAGE_TYPES.menuAnchor: {
2107
+ const fields = read(payload, MENU_ANCHOR_KEYS);
2108
+ return fields !== void 0 && isMenuRect(read, fields.rect);
2109
+ }
2110
+ case PAY_ELEMENT_LIFETIME_MESSAGE_TYPES.actionCheck:
2111
+ case PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES.checkStatusRequest: return isActionCheckPayload(read, payload);
2112
+ case PAY_ELEMENT_LIFETIME_MESSAGE_TYPES.reloadRequest: return isReloadRequestPayload(read, payload);
2113
+ case PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES.connected: {
2114
+ const fields = read(payload, ELEMENT_CONNECTED_KEYS);
2115
+ return fields !== void 0 && isUuid(fields.documentId) && isMessageId(fields.initId) && isRevision(fields.sequence) && isEvmAddress(fields.evmAddress);
2116
+ }
2117
+ case PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES.viewShown: return read(payload, EMPTY_KEYS) !== void 0;
2118
+ case PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES.loadFailed: {
2119
+ const fields = read(payload, ELEMENT_LOAD_FAILED_KEYS);
2120
+ return fields !== void 0 && isMember(fields.reason, ELEMENT_LOAD_FAILURE_REASONS);
2121
+ }
2122
+ default: return false;
2123
+ }
2124
+ }
2125
+ /**
2126
+ * Checks an app → hub frame payload: `show-menu`, or any app → hub payload.
2127
+ */
2128
+ function isAppHubFramePayload(read, type, payload) {
2129
+ switch (type) {
2130
+ case PAY_HUB_FRAME_MESSAGE_TYPES.overlayHidden: return read(payload, EMPTY_KEYS) !== void 0;
2131
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsSubscribe: return read(payload, EMPTY_KEYS) !== void 0;
2132
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsInspect:
2133
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsUnsubscribe: {
2134
+ const fields = read(payload, DIAGNOSTICS_SUBSCRIPTION_KEYS);
2135
+ return fields !== void 0 && isMessageId(fields.subscriptionId);
2136
+ }
2137
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsDisconnect: {
2138
+ const fields = read(payload, DIAGNOSTICS_TARGET_KEYS);
2139
+ return fields !== void 0 && isMessageId(fields.subscriptionId) && isMessageId(fields.targetId);
2140
+ }
2141
+ case PAY_HUB_FRAME_MESSAGE_TYPES.showMenu: {
2142
+ const fields = read(payload, SHOW_MENU_KEYS);
2143
+ return fields !== void 0 && isMenuRect(read, fields.anchor);
2144
+ }
2145
+ default: return isAppPayload(read, type, payload);
2146
+ }
2147
+ }
2148
+ /**
2149
+ * Checks a `menu-refused` payload: exactly a `HubErrorCode` and a bounded message, and an optional wait. It names no
2150
+ * request.
2151
+ */
2152
+ function isMenuRefusalPayload(read, payload) {
2153
+ const fields = read(payload, MENU_REFUSAL_KEYS);
2154
+ return fields !== void 0 && isMember(fields.code, HUB_ERROR_CODES) && isErrorDetail(fields.message) && isOptionalRetryAfterSeconds(fields.retryAfterSeconds);
2155
+ }
2156
+ /**
2157
+ * Checks an `activity` payload: exactly `pending`, a boolean.
2158
+ */
2159
+ function isActivityPayload(read, payload) {
2160
+ const fields = read(payload, ACTIVITY_KEYS);
2161
+ return fields !== void 0 && typeof fields.pending === "boolean";
2162
+ }
2163
+ /**
2164
+ * Checks a hub frame → app payload: `activity`, the two `show-menu` answers, or any hub → app payload.
2165
+ */
2166
+ function isHubFrameAppPayload(read, type, payload) {
2167
+ switch (type) {
2168
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsDetails: return isDiagnosticsDetails(read, payload);
2169
+ case PAY_HUB_FRAME_MESSAGE_TYPES.diagnosticsStatus: return isDiagnosticsStatus(read, payload);
2170
+ case PAY_HUB_FRAME_MESSAGE_TYPES.activity: return isActivityPayload(read, payload);
2171
+ case PAY_HUB_FRAME_MESSAGE_TYPES.menuEnded: {
2172
+ const fields = read(payload, MENU_ENDED_KEYS);
2173
+ return fields !== void 0 && (fields.restoreFocus === true ? isMessageId(fields.closeId) : fields.restoreFocus === false && hasOnlyKeys(fields, ELEMENT_MENU_ENDED_KEYS));
2174
+ }
2175
+ case PAY_HUB_FRAME_MESSAGE_TYPES.menuAccepted: return read(payload, EMPTY_KEYS) !== void 0;
2176
+ case PAY_HUB_FRAME_MESSAGE_TYPES.menuRefused: return isMenuRefusalPayload(read, payload);
2177
+ default: return isHubPayload(read, type, payload);
2178
+ }
2179
+ }
2180
+ /**
2181
+ * Checks a Pay element → Pay window payload: `relay-init`, or an app → hub payload other than `init`.
2182
+ */
2183
+ function isElementWindowPayload(read, type, payload) {
2184
+ switch (type) {
2185
+ case "pay": return checkPayRequest(read, payload, true);
2186
+ case SUA_GUEST_HANDOFF_MESSAGE_TYPE: {
2187
+ const fields = read(payload, GUEST_HANDOFF_KEYS);
2188
+ return fields !== void 0 && typeof fields.handoff === "string" && fields.handoff.length > 0;
2189
+ }
2190
+ case SUA_FUND_WINDOW_MESSAGE_TYPE: {
2191
+ const fields = read(payload, FUND_WINDOW_KEYS);
2192
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && (fields.walletId === null || isMessageId(fields.walletId));
2193
+ }
2194
+ case SUA_RELAY_MESSAGE_TYPES.init: {
2195
+ const fields = read(payload, RELAY_INIT_KEYS);
2196
+ return fields !== void 0 && isAppId(fields.appId) && isAppOrigin(fields.appOrigin) && hasWireAppearance(read, fields.appearance);
2197
+ }
2198
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.close: return isRelayClosePayload(read, payload);
2199
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.pageUrl: {
2200
+ const fields = read(payload, RELAY_PAGE_URL_KEYS);
2201
+ return fields !== void 0 && isMessageId(fields.relayId) && isPageUrl(fields.url);
2202
+ }
2203
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payShown: {
2204
+ const fields = read(payload, RELAY_PAY_SHOWN_KEYS);
2205
+ return fields !== void 0 && isMessageId(fields.relayId) && isPayShown(read, fields);
2206
+ }
2207
+ case "init": return false;
2208
+ default: return isAppPayload(read, type, payload);
2209
+ }
2210
+ }
2211
+ /**
2212
+ * Checks a Pay window → Pay element payload: `relay-build`, the two `relay-init` answers, a `result` or `error` for a ceremony
2213
+ * request, or any other hub → app payload.
2214
+ */
2215
+ function isWindowElementPayload(read, type, payload) {
2216
+ switch (type) {
2217
+ case SUA_RELAY_MESSAGE_TYPES.build: {
2218
+ const fields = read(payload, RELAY_BUILD_KEYS);
2219
+ return fields !== void 0 && isHubBuildId(fields.buildId);
2220
+ }
2221
+ case SUA_RELAY_MESSAGE_TYPES.accepted: return read(payload, EMPTY_KEYS) !== void 0;
2222
+ case SUA_RELAY_MESSAGE_TYPES.refused: return isRefusalPayload(read, payload);
2223
+ case "result": return isResultPayload(read, payload, CEREMONY_REQUESTS);
2224
+ case "error": return isErrorPayload(read, payload, CEREMONY_REQUESTS);
2225
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.closeAccepted: return isRelayClosePayload(read, payload);
2226
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.state: return isRelayStatePayload(read, payload);
2227
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.checkoutResult:
2228
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.checkoutWallet:
2229
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payOwner:
2230
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payProgress:
2231
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.payUnsent:
2232
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.paySource:
2233
+ case SUA_RELAY_CONTROL_MESSAGE_TYPES.paySourceSaved: return checkRelayPayPayload(read, type, payload, isMessageId, isRevision);
2234
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutHeld: return checkHubPayPayload(read, type, payload);
2235
+ default: return isHubPayload(read, type, payload);
2236
+ }
2237
+ }
2238
+ /**
2239
+ * Reports whether `value` is a lowercase canonical version-4 UUID.
2240
+ */
2241
+ function isUuid(value) {
2242
+ return matchesOfLength(value, UUID_LENGTH, UUID_V4_PATTERN);
2243
+ }
2244
+ /**
2245
+ * Reports whether `value` is a hub build id: 1 to `MAX_HUB_BUILD_ID_LENGTH` characters matching
2246
+ * {@link HUB_BUILD_ID_PATTERN}. The length is checked first, so a huge string never reaches the regex.
2247
+ */
2248
+ function isHubBuildId(value) {
2249
+ return isStringOfLength(value, 1, 128) && HUB_BUILD_ID_PATTERN.test(value);
2250
+ }
2251
+ /**
2252
+ * Reports whether `value` is a link C balance amount: at most `MAX_HUB_BALANCE_AMOUNT_LENGTH` characters matching
2253
+ * {@link BALANCE_AMOUNT_PATTERN}, whose base units (the digits without the point) are at most `2^256 - 1`. The length
2254
+ * and the pattern are checked before the integer conversion.
2255
+ */
2256
+ function isBalanceAmount(value) {
2257
+ if (!isStringOfLength(value, 1, 79) || !BALANCE_AMOUNT_PATTERN.test(value)) return false;
2258
+ return BigInt(value.replace(".", "")) <= MAX_BALANCE_BASE_UNITS;
2259
+ }
2260
+ /**
2261
+ * Reports whether `value` is a link C balance: `loading` or `unavailable` with no other key, or `ready` with an amount
2262
+ * and an optional `USD` currency.
2263
+ */
2264
+ function isElementBalance(read, value) {
2265
+ const fields = read(value, BALANCE_KEYS);
2266
+ switch (fields?.status) {
2267
+ case "loading":
2268
+ case "unavailable": return hasOnlyKeys(fields, BALANCE_STATUS_ONLY_KEYS);
2269
+ case "ready": return isBalanceAmount(fields.amount) && (fields.currency === void 0 || fields.currency === BALANCE_CURRENCY);
2270
+ default: return false;
2271
+ }
2272
+ }
2273
+ /**
2274
+ * Checks an `attach-accepted` or `attach-confirm` payload: exactly an attachment id and a hub build id.
2275
+ */
2276
+ function isAttachmentPayload(read, payload) {
2277
+ const fields = read(payload, ATTACHMENT_KEYS);
2278
+ return fields !== void 0 && isUuid(fields.attachmentId) && isHubBuildId(fields.buildId);
2279
+ }
2280
+ /**
2281
+ * Checks a `window-result` payload: exactly the window operation's three ids and a ceremony result.
2282
+ */
2283
+ function isWindowResultPayload(read, payload) {
2284
+ const fields = read(payload, WINDOW_RESULT_KEYS);
2285
+ return fields !== void 0 && isMessageId(fields.operationId) && isMessageId(fields.windowId) && isMessageId(fields.requestId) && isResultPayload(read, fields.result, CEREMONY_REQUESTS);
2286
+ }
2287
+ /**
2288
+ * Checks a `window-error` payload: exactly the window operation's three ids and a ceremony error.
2289
+ */
2290
+ function isWindowErrorPayload(read, payload) {
2291
+ const fields = read(payload, WINDOW_ERROR_KEYS);
2292
+ return fields !== void 0 && isMessageId(fields.operationId) && isMessageId(fields.windowId) && isMessageId(fields.requestId) && isErrorPayload(read, fields.error, CEREMONY_REQUESTS);
2293
+ }
2294
+ /**
2295
+ * Checks a `window-ended` payload: an operation id or `null`, a window id and a window end cause.
2296
+ */
2297
+ function isWindowEndedPayload(read, payload) {
2298
+ const fields = read(payload, WINDOW_ENDED_KEYS);
2299
+ return fields !== void 0 && (fields.operationId === null || isMessageId(fields.operationId)) && isMessageId(fields.windowId) && isMember(fields.cause, WINDOW_END_CAUSES);
2300
+ }
2301
+ /**
2302
+ * Checks a `window-state` payload: the window operation's three ids, the relay id, a sequence (a safe integer from 1)
2303
+ * and a state whose expiry is at most `MAX_RELAY_STATE_EXPIRY_LENGTH` characters.
2304
+ */
2305
+ function isWindowStatePayload(read, payload) {
2306
+ const fields = read(payload, WINDOW_STATE_KEYS);
2307
+ return fields !== void 0 && isMessageId(fields.operationId) && isMessageId(fields.windowId) && isMessageId(fields.requestId) && isMessageId(fields.relayId) && isRevision(fields.sequence) && isStateSnapshot(read, fields.state, 64);
2308
+ }
2309
+ /**
2310
+ * Checks a Pay element → hub frame payload: a link C request or report, or one of the six ceremony requests.
2311
+ */
2312
+ function isElementHubPayload(read, type, payload) {
2313
+ switch (type) {
2314
+ case SUA_LINK_C_MESSAGE_TYPES.menuPayment: {
2315
+ const fields = read(payload, /* @__PURE__ */ new Set(["paymentId", "held"]));
2316
+ return fields !== void 0 && typeof fields.held === "boolean" && (fields.paymentId === null || typeof fields.paymentId === "string" && fields.paymentId.length > 0 && fields.paymentId.length <= 128);
2317
+ }
2318
+ case "pay": return checkPayRequest(read, payload, true);
2319
+ case SUA_LINK_C_MESSAGE_TYPES.probe:
2320
+ case SUA_LINK_C_MESSAGE_TYPES.attach: return read(payload, EMPTY_KEYS) !== void 0;
2321
+ case SUA_LINK_C_MESSAGE_TYPES.confirm: return isAttachmentPayload(read, payload);
2322
+ case SUA_LINK_C_MESSAGE_TYPES.detach: {
2323
+ const fields = read(payload, DETACH_KEYS);
2324
+ return fields !== void 0 && isUuid(fields.attachmentId);
2325
+ }
2326
+ case SUA_LINK_C_MESSAGE_TYPES.windowOpened: {
2327
+ const fields = read(payload, WINDOW_OPENED_KEYS);
2328
+ return fields !== void 0 && isMessageId(fields.windowId) && isMessageId(fields.requestId) && isMember(fields.request, CEREMONY_REQUESTS);
2329
+ }
2330
+ case SUA_LINK_C_MESSAGE_TYPES.windowResult: return isWindowResultPayload(read, payload);
2331
+ case SUA_LINK_C_MESSAGE_TYPES.windowError: return isWindowErrorPayload(read, payload);
2332
+ case SUA_LINK_C_MESSAGE_TYPES.windowEnded: return isWindowEndedPayload(read, payload);
2333
+ case SUA_LINK_C_MESSAGE_TYPES.windowState: return isWindowStatePayload(read, payload);
2334
+ case SUA_LINK_C_MESSAGE_TYPES.pageUrl: {
2335
+ const fields = read(payload, PAGE_URL_KEYS);
2336
+ return fields !== void 0 && (fields.url === null || isPageUrl(fields.url));
2337
+ }
2338
+ case SUA_LINK_C_MESSAGE_TYPES.payShown: {
2339
+ const fields = read(payload, PAY_SHOWN_KEYS);
2340
+ return fields !== void 0 && isPayShown(read, fields);
2341
+ }
2342
+ case "sign-in":
2343
+ case "sign":
2344
+ case "sign-out":
2345
+ case "disconnect":
2346
+ case PAY_FUND_REQUEST_TYPE: return isAppPayload(read, type, payload);
2347
+ default: return false;
2348
+ }
2349
+ }
2350
+ /**
2351
+ * Checks a hub frame → Pay element payload: a link C answer or notice, or the reused `state`, `transport`,
2352
+ * `activity`, or a `result` or `error` for a ceremony request.
2353
+ */
2354
+ function isHubElementPayload(read, type, payload) {
2355
+ switch (type) {
2356
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutResult:
2357
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutWallet:
2358
+ case SUA_LINK_C_MESSAGE_TYPES.checkoutHeld:
2359
+ case SUA_LINK_C_MESSAGE_TYPES.payOwner:
2360
+ case SUA_LINK_C_MESSAGE_TYPES.payProgress:
2361
+ case SUA_LINK_C_MESSAGE_TYPES.payUnsent:
2362
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceSaved:
2363
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceCurrent:
2364
+ case SUA_LINK_C_MESSAGE_TYPES.paySourceFunds: return checkHubPayPayload(read, type, payload);
2365
+ case PAY_HUB_FRAME_MESSAGE_TYPES.overlayHidden: return read(payload, EMPTY_KEYS) !== void 0;
2366
+ case SUA_LINK_C_MESSAGE_TYPES.probeAck: return read(payload, EMPTY_KEYS) !== void 0;
2367
+ case SUA_LINK_C_MESSAGE_TYPES.accepted: return isAttachmentPayload(read, payload);
2368
+ case SUA_LINK_C_MESSAGE_TYPES.refused: return isRefusalPayload(read, payload);
2369
+ case SUA_LINK_C_MESSAGE_TYPES.balance: {
2370
+ const fields = read(payload, BALANCE_PAYLOAD_KEYS);
2371
+ return fields !== void 0 && isElementBalance(read, fields.balance);
2372
+ }
2373
+ case SUA_LINK_C_MESSAGE_TYPES.windowAccepted: {
2374
+ const fields = read(payload, WINDOW_ACCEPTED_KEYS);
2375
+ return fields !== void 0 && isMessageId(fields.windowId) && isMessageId(fields.operationId);
2376
+ }
2377
+ case SUA_LINK_C_MESSAGE_TYPES.windowRefused: {
2378
+ const fields = read(payload, WINDOW_REFUSED_KEYS);
2379
+ return fields !== void 0 && isMessageId(fields.windowId) && isMember(fields.code, HUB_ERROR_CODES) && isErrorDetail(fields.message);
2380
+ }
2381
+ case SUA_LINK_C_MESSAGE_TYPES.windowCancel: {
2382
+ const fields = read(payload, WINDOW_CANCEL_KEYS);
2383
+ return fields !== void 0 && isMessageId(fields.operationId) && isMessageId(fields.windowId) && isMember(fields.cause, WINDOW_CANCEL_CAUSES);
2384
+ }
2385
+ case "state": return isStatePayload(read, payload);
2386
+ case "transport": return isTransportPayload(read, payload);
2387
+ case PAY_HUB_FRAME_MESSAGE_TYPES.activity: return isActivityPayload(read, payload);
2388
+ case "result": return isResultPayload(read, payload, CEREMONY_REQUESTS);
2389
+ case "error": return isErrorPayload(read, payload, CEREMONY_REQUESTS);
2390
+ default: return false;
2391
+ }
2392
+ }
2393
+ /**
2394
+ * Checks a `relay-close` or `relay-close-accepted` payload: exactly the relay id, the request id, a ceremony request
2395
+ * and a cancel cause.
2396
+ */
2397
+ function isRelayClosePayload(read, payload) {
2398
+ const fields = read(payload, RELAY_CLOSE_KEYS);
2399
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isMember(fields.request, CEREMONY_REQUESTS) && isMember(fields.cause, WINDOW_CANCEL_CAUSES);
2400
+ }
2401
+ /**
2402
+ * Checks a `relay-state` payload: exactly the relay id, the request id, a sequence (a safe integer from 1) and a state
2403
+ * whose expiry is at most `MAX_RELAY_STATE_EXPIRY_LENGTH` characters.
2404
+ */
2405
+ function isRelayStatePayload(read, payload) {
2406
+ const fields = read(payload, RELAY_STATE_KEYS);
2407
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && isStateSnapshot(read, fields.state, 64);
2408
+ }
2409
+ /**
2410
+ * Reports whether a snapshot holds the fields every action check names: a document id, an init id, a config id, a
2411
+ * revision and an attempt id.
2412
+ */
2413
+ function hasActionCheckFields(fields) {
2414
+ return isUuid(fields.documentId) && isMessageId(fields.initId) && isMessageId(fields.configId) && isRevision(fields.revision) && isMessageId(fields.attemptId);
2415
+ }
2416
+ /**
2417
+ * Checks an `element-action-check` payload: exactly the five correlation fields.
2418
+ */
2419
+ function isActionCheckPayload(read, payload) {
2420
+ const fields = read(payload, ACTION_CHECK_KEYS);
2421
+ return fields !== void 0 && hasActionCheckFields(fields);
2422
+ }
2423
+ /**
2424
+ * Checks an `element-action-eligibility` payload: exactly the five correlation fields and a boolean `eligible`.
2425
+ */
2426
+ function isActionEligibilityPayload(read, payload) {
2427
+ const fields = read(payload, ACTION_ELIGIBILITY_KEYS);
2428
+ return fields !== void 0 && hasActionCheckFields(fields) && typeof fields.eligible === "boolean";
2429
+ }
2430
+ /**
2431
+ * Checks an `element-reload-request` payload: exactly a document id, an init id and a reload reason.
2432
+ */
2433
+ function isReloadRequestPayload(read, payload) {
2434
+ const fields = read(payload, RELOAD_REQUEST_KEYS);
2435
+ return fields !== void 0 && isUuid(fields.documentId) && isMessageId(fields.initId) && isMember(fields.reason, ELEMENT_RELOAD_REASONS);
2436
+ }
2437
+ /**
2438
+ * Checks an `element-reload-grant` payload: exactly a document id, an init id and a boolean `granted`.
2439
+ */
2440
+ function isReloadGrantPayload(read, payload) {
2441
+ const fields = read(payload, RELOAD_GRANT_KEYS);
2442
+ return fields !== void 0 && isUuid(fields.documentId) && isMessageId(fields.initId) && typeof fields.granted === "boolean";
2443
+ }
2444
+ /**
2445
+ * Reports whether `value` is shaped like an envelope of this protocol, whatever its version, type or payload: a plain
2446
+ * object (prototype `Object.prototype` or `null`) with `protocol === "stridge-sua"`, a positive integer `version`, a
2447
+ * non-empty string `id` of at most `MAX_MESSAGE_ID_LENGTH` characters, a non-empty string `type`, and a plain-object
2448
+ * `payload`. Extra keys are allowed here.
2449
+ *
2450
+ * The channel uses it to drop foreign `postMessage` traffic cheaply and to tell "ours, but another version" (log it)
2451
+ * from noise. It does not check the sender's origin; the channel does.
2452
+ */
2453
+ function isSuaEnvelope(value) {
2454
+ try {
2455
+ const fields = readSomeFields(value, ENVELOPE_KEY_LIST);
2456
+ if (fields === void 0 || fields.protocol !== "stridge-sua") return false;
2457
+ const version = fields.version;
2458
+ if (!Number.isSafeInteger(version) || version < 1) return false;
2459
+ return isMessageId(fields.id) && typeof fields.type === "string" && fields.type.length > 0 && isPlainObject(fields.payload);
2460
+ } catch {
2461
+ return false;
2462
+ }
2463
+ }
2464
+ /**
2465
+ * Reports whether `value` is a well-formed app → hub message ({@link AppMessage}), and rejects every other shape.
2466
+ *
2467
+ * Envelope: exactly the keys `protocol`, `version`, `id`, `type`, `payload`; `protocol === PAY_PROTOCOL`; `version
2468
+ * === SUA_PROTOCOL_VERSION`; `id` a non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters; `payload` a plain
2469
+ * object. Then, by `type` (any other type is rejected):
2470
+ *
2471
+ * - `init` — payload keys exactly `appId` and `appearance`; `appId` matches `APP_ID_PATTERN`; `appearance` is a valid
2472
+ * appearance.
2473
+ * - `appearance` — payload key exactly `appearance`, a valid appearance.
2474
+ * - `sign-in`, `sign-out`, `disconnect` — payload is `{}` (no keys).
2475
+ * - `fund` — payload is `{}` or exactly `start`, one of `PAY_FUND_START_SCREENS`.
2476
+ * - `fund-cancel` — payload is `{}`; the hub matches its envelope id to the pending Fund request.
2477
+ * - `sign` — payload key exactly `message`: a non-empty string whose UTF-8 encoding is at most
2478
+ * `MAX_SIGN_MESSAGE_BYTES` bytes (its UTF-16 length is checked first, so a huge string is never encoded).
2479
+ *
2480
+ * An appearance carries `theme` `"dark"` or `"light"`. The decoder also accepts and discards a legacy `accent` key.
2481
+ *
2482
+ * Throughout, "plain object" means a non-null, non-array object whose prototype is `Object.prototype` or `null`; "exact
2483
+ * keys" means no key outside the listed ones; an optional key whose value is `undefined` counts as absent. Never
2484
+ * throws.
2485
+ */
2486
+ function isAppMessage(value) {
2487
+ return decodeAppMessage(value) !== void 0;
2488
+ }
2489
+ function decodeAppMessage(value) {
2490
+ return decodeMessage(value, isAppPayload);
2491
+ }
2492
+ /**
2493
+ * Reports whether `value` is a well-formed hub → app message ({@link HubMessage}), and rejects every other shape.
2494
+ *
2495
+ * Envelope: the same rules as {@link isAppMessage}. Then, by `type` (any other type is rejected):
2496
+ *
2497
+ * - `ready`, `overlay-open`, `overlay-close`, `fund-received` — payload is `{}`. The app matches the Fund receipt's id.
2498
+ * - `transport` — payload key exactly `mode`: `"overlay"` or `"popup"`.
2499
+ * - `state` — payload keys within `status`, `evmAddress`, `keypairExpiresAt`; `status` is a `HubStatus`;
2500
+ * `evmAddress`, when present, matches `EVM_ADDRESS_PATTERN`; `keypairExpiresAt`, when present, is a string that
2501
+ * `Date.parse` reads as a finite number.
2502
+ * - `result` — payload keyed by `request`: `init`, `sign-out`, `disconnect` and `fund` have no other
2503
+ * key;
2504
+ * `sign-in` has exactly `evmAddress` (matching `EVM_ADDRESS_PATTERN`); `sign` has exactly `signature`: `0x`, 128
2505
+ * lowercase hex digits, then `1b` or `1c` (132 characters). Any other `request` is rejected.
2506
+ * - `error` — payload keys within `request`, `code`, `message`, `retryAfterSeconds`; `request` is a `HubRequestType`;
2507
+ * `code` is a `HubErrorCode`; `message` is a string of at most `MAX_ERROR_MESSAGE_LENGTH` characters (it may be
2508
+ * empty); `retryAfterSeconds`, when present, is a non-negative safe integer.
2509
+ *
2510
+ * The same plain-object, exact-key and `undefined`-as-absent rules apply. Never throws.
2511
+ */
2512
+ function isHubMessage(value) {
2513
+ return decodeHubMessage(value) !== void 0;
2514
+ }
2515
+ function decodeHubMessage(value) {
2516
+ return decodeMessage(value, isHubPayload);
2517
+ }
2518
+ /**
2519
+ * Reports whether `value` is a well-formed app → Pay element message ({@link AppElementMessage}), and rejects every
2520
+ * other shape, including the app → hub `init` and ceremony requests.
2521
+ *
2522
+ * Envelope: the same rules as {@link isAppMessage}. Then, by `type` (any other type is rejected):
2523
+ *
2524
+ * - `element-init` — payload keys exactly `appId` (matching `APP_ID_PATTERN`), `hubFrame` (1 to
2525
+ * `MAX_MESSAGE_ID_LENGTH` characters: an ASCII letter or digit, then ASCII letters, digits, `_` or `-`) and
2526
+ * `appearance` (a valid appearance, as for {@link isAppMessage}). All three are required; any
2527
+ * other key, a build id included, is rejected.
2528
+ * - `element-config` — one full bundle with exactly `revision`, `labels`, `action` and `showBalance`; `labels` has
2529
+ * at most `button`, `actionExpired`, `done`, `doneDescription`, `balanceLabel`; `action` is `null` or exactly
2530
+ * `attemptId` (a non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters), `message` (as for `sign`) and
2531
+ * `label`; `showBalance` is a boolean.
2532
+ *
2533
+ * `revision` is a safe integer from 1. Every label, the action's included, is a string of at most
2534
+ * `MAX_ELEMENT_LABEL_LENGTH` characters and may be empty.
2535
+ * - `focus` — payload is `{}`.
2536
+ * - `appearance` — as for {@link isAppMessage}.
2537
+ * - `element-action-eligibility` — payload keys exactly `documentId` (a lowercase canonical version-4 UUID),
2538
+ * `initId`, `configId` and `attemptId` (each a non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters),
2539
+ * `revision` (a safe integer from 1) and `eligible` (a boolean).
2540
+ * - `element-reload-grant` — payload keys exactly `documentId` and `initId`, as above, and `granted` (a boolean). No
2541
+ * URL, build id or counter.
2542
+ * - `element-check-status-capability` — payload keys exactly `documentId` and `initId`, as above, and `supported`
2543
+ * (a boolean). The receiver matches the accepted document and init.
2544
+ * - `element-check-status-settled` — exactly the five correlation fields of `element-action-eligibility` without
2545
+ * `eligible`. The receiver matches the pending Check status request's envelope id and all payload fields.
2546
+ *
2547
+ * The same plain-object, exact-key and `undefined`-as-absent rules apply. A legacy `kind` key is rejected, even when
2548
+ * its value is `undefined`. It checks shape only: the channel checks the sender and origin, binds `element-init`'s
2549
+ * app id to the served app and its hub frame to any URL hint, and matches each lifetime answer to its pending
2550
+ * request. Never throws.
2551
+ */
2552
+ function isAppElementMessage(value) {
2553
+ return decodeAppElementMessage(value) !== void 0;
2554
+ }
2555
+ function decodeAppElementMessage(value) {
2556
+ return decodeMessage(value, isAppElementPayload);
2557
+ }
2558
+ /**
2559
+ * Reports whether `value` is a well-formed Pay element → app message ({@link ElementMessage}), and rejects every other
2560
+ * shape, including every app → hub, hub → app and app → Pay element message.
2561
+ *
2562
+ * Envelope: the same rules as {@link isAppMessage}. Then, by `type` (any other type is rejected):
2563
+ *
2564
+ * - `element-ready`, `element-accepted` — payload is `{}`.
2565
+ * - `element-refused` — payload keys exactly `code` (a `HubErrorCode`) and `message` (a string of at most
2566
+ * `MAX_ERROR_MESSAGE_LENGTH` characters, possibly empty). No `request` key.
2567
+ * - `element-config-ack` — payload key exactly `revision`, a safe integer from 1.
2568
+ * - `resize` — payload keys exactly `blockSize`, a finite number from 0 to `MAX_ELEMENT_BLOCK_SIZE`, and `durationMs`,
2569
+ * a safe integer from 0 to `MAX_ELEMENT_RESIZE_DURATION_MS`. Both are required.
2570
+ * - `signed` — payload keys exactly `signature` (as for a sign `result`), `message` (as for `sign`) and `attemptId` (a
2571
+ * non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters).
2572
+ * - `failed` — payload keyed by `request`, with `code` an `ElementFailureCode`, `message` as for `element-refused`,
2573
+ * and an optional `retryAfterSeconds`, a non-negative safe integer. `sign` also requires `attemptId`, as for
2574
+ * `signed`; `sign-in`, `sign-out`, `disconnect` and `fund` must not hold the `attemptId` key. Any other
2575
+ * `request`, `init` included, is rejected.
2576
+ * - `menu-anchor` — payload key exactly `rect`: exactly `x`, `y`, `width`, `height`, each a finite number; `x` and `y`
2577
+ * within ±`MAX_MENU_RECT_VALUE`, `width` and `height` from 0 to `MAX_MENU_RECT_VALUE`. Fractions are valid.
2578
+ * - `element-action-check` — payload keys exactly `documentId` (a lowercase canonical version-4 UUID), `initId`,
2579
+ * `configId` and `attemptId` (each a non-empty string of at most `MAX_MESSAGE_ID_LENGTH` characters) and `revision`
2580
+ * (a safe integer from 1).
2581
+ * - `element-reload-request` — payload keys exactly `documentId` and `initId`, as above, and `reason`
2582
+ * (`build-mismatch`). No build id or URL.
2583
+ * - `element-connected` — payload keys exactly `documentId` and `initId`, as above, `sequence` (a safe integer from 1)
2584
+ * and `evmAddress` (matching `EVM_ADDRESS_PATTERN`). The receiver checks the current init, pinned document and
2585
+ * increasing sequence; this guard checks only their shape.
2586
+ * - `element-view-shown` — payload is `{}`.
2587
+ * - `element-load-failed` — payload key exactly `reason` (`hub-frame` or `internal`).
2588
+ * - `element-check-status-request` — exactly the five correlation fields of `element-action-check`. Requires a
2589
+ * settlement response despite its notification-table entry. The receiver checks the current config and spent
2590
+ * attempt before invoking the app's callback; shape validation alone does not prove either.
2591
+ *
2592
+ * The same plain-object, exact-key and `undefined`-as-absent rules apply. It checks shape only: the channel checks the
2593
+ * sender, correlates answers by `id`, and matches a `signed` or `failed` notice to its captured attempt. Never throws.
2594
+ */
2595
+ function isElementMessage(value) {
2596
+ return decodeElementMessage(value) !== void 0;
2597
+ }
2598
+ function decodeElementMessage(value) {
2599
+ return decodeMessage(value, isElementPayload);
2600
+ }
2601
+ /**
2602
+ * Reports whether `value` is a well-formed app → hub frame message ({@link AppHubFrameMessage}), and rejects every
2603
+ * other shape. It accepts every message {@link isAppMessage} accepts, by the same rules, and adds:
2604
+ *
2605
+ * - `show-menu` — payload key exactly `anchor`: a rect as for `menu-anchor`, in the app's viewport.
2606
+ *
2607
+ * The same envelope, plain-object, exact-key and `undefined`-as-absent rules apply. It checks shape only: the channel
2608
+ * checks the sender. Never throws.
2609
+ */
2610
+ function isAppHubFrameMessage(value) {
2611
+ return decodeAppHubFrameMessage(value) !== void 0;
2612
+ }
2613
+ function decodeAppHubFrameMessage(value) {
2614
+ return decodeMessage(value, isAppHubFramePayload);
2615
+ }
2616
+ /**
2617
+ * Reports whether `value` is a well-formed hub frame → app message ({@link HubFrameAppMessage}), and rejects every
2618
+ * other shape. It accepts every message {@link isHubMessage} accepts, by the same rules, and adds:
2619
+ *
2620
+ * - `activity` — payload key exactly `pending`, a boolean.
2621
+ * - `menu-accepted` — payload is `{}`.
2622
+ * - `menu-refused` — payload keys `code` (a `HubErrorCode`), `message` (a string of at most
2623
+ * `MAX_ERROR_MESSAGE_LENGTH` characters, possibly empty) and an optional `retryAfterSeconds`, a non-negative safe
2624
+ * integer. No `request` key.
2625
+ *
2626
+ * `show-menu` is not a `HubRequestType`, so a `result` or `error` for it is rejected. The same envelope, plain-object,
2627
+ * exact-key and `undefined`-as-absent rules apply. It checks shape only: the channel checks the sender and correlates
2628
+ * the menu answers by `id`. Never throws.
2629
+ */
2630
+ function isHubFrameAppMessage(value) {
2631
+ return decodeHubFrameAppMessage(value) !== void 0;
2632
+ }
2633
+ function decodeHubFrameAppMessage(value) {
2634
+ return decodeMessage(value, isHubFrameAppPayload);
2635
+ }
2636
+ /**
2637
+ * Reports whether `value` is a well-formed Pay element → Pay window message ({@link ElementWindowMessage}), and
2638
+ * rejects every other shape, the ordinary `init` included. By `type`:
2639
+ *
2640
+ * - `relay-init` — payload keys exactly `appId` (matching `APP_ID_PATTERN`), `appOrigin` and `appearance` (a valid
2641
+ * appearance). `appOrigin` is a string of 1 to `MAX_APP_ORIGIN_LENGTH` characters that `URL` reads as an `http:` or
2642
+ * `https:` URL whose `origin` is the string itself: no path, trailing slash, credentials, query, fragment, default
2643
+ * port or other spelling of the same origin.
2644
+ * - `appearance`, `sign-in`, `sign`, `sign-out`, `disconnect`, `fund` — as for {@link isAppMessage}.
2645
+ * - `relay-close` — payload keys exactly `relayId` and `requestId` (each a non-empty string of at most
2646
+ * `MAX_MESSAGE_ID_LENGTH` characters), `request` (a ceremony request, never `init`) and `cause` (`window-cancel` or
2647
+ * `teardown`).
2648
+ *
2649
+ * The same envelope, plain-object, exact-key and `undefined`-as-absent rules apply. It checks shape only: the Sua
2650
+ * window checks the sender, binds `appId` to the app it serves, checks `appOrigin` against the app's registry and
2651
+ * matches a `relay-close` to its current operation. Never throws.
2652
+ */
2653
+ function isElementWindowMessage(value) {
2654
+ return decodeElementWindowMessage(value) !== void 0;
2655
+ }
2656
+ function decodeElementWindowMessage(value) {
2657
+ return decodeMessage(value, isElementWindowPayload);
2658
+ }
2659
+ /**
2660
+ * Reports whether `value` is a well-formed Pay window → Pay element message ({@link WindowElementMessage}), and
2661
+ * rejects every other shape. By `type`:
2662
+ *
2663
+ * - `relay-build` — payload key exactly `buildId` (1 to `MAX_HUB_BUILD_ID_LENGTH` ASCII letters, digits, `_` or `-`,
2664
+ * starting with a letter or digit), as for `attach-accepted`.
2665
+ * - `relay-accepted` — payload is `{}`.
2666
+ * - `relay-refused` — payload keys exactly `code` (a `HubErrorCode`) and `message` (a string of at most
2667
+ * `MAX_ERROR_MESSAGE_LENGTH` characters, possibly empty). No `request` key.
2668
+ * - `ready`, `transport`, `state`, `overlay-open`, `overlay-close` — as for {@link isHubMessage}.
2669
+ * - `result`, `error` — as for {@link isHubMessage}, but `request` is `sign-in`, `sign`, `sign-out`, `disconnect`,
2670
+ * `fund`. An answer to `init` is rejected: `relay-init` has its own answers.
2671
+ * - `relay-close-accepted` — the `relay-close` payload rules of {@link isElementWindowMessage}.
2672
+ * - `relay-state` — payload keys exactly `relayId` and `requestId` (as for `relay-close`), `sequence` (a safe integer
2673
+ * from 1) and `state` (as for `state`, with a `keypairExpiresAt` of at most `MAX_RELAY_STATE_EXPIRY_LENGTH`
2674
+ * characters, its length checked before it is parsed).
2675
+ * - `relay-pay-progress` — payload keys exactly `relayId`, `requestId`, `sequence` (as for `relay-state`) and
2676
+ * `progress` (a link C `pay-progress` payload).
2677
+ * - `relay-pay-source` — payload keys exactly `relayId`, `requestId`, `sequence` (as for `relay-state`) and
2678
+ * `remembered` (`null`, or a link C `pay-source` `remembered`).
2679
+ * - `relay-pay-source-saved` — payload keys exactly `relayId`, `requestId`, `sequence` (as for `relay-state`) and
2680
+ * `saved` (`null`, or a link C `pay-source-saved` `saved`).
2681
+ * - `checkout-held` — the link C payload: the Pay window's own stored checkout for the `pay` it admitted.
2682
+ *
2683
+ * The same envelope, plain-object, exact-key and `undefined`-as-absent rules apply. It checks shape only: the Sua
2684
+ * element checks the sender and correlates each answer and state with its relay and operation. Never throws.
2685
+ */
2686
+ function isWindowElementMessage(value) {
2687
+ return decodeWindowElementMessage(value) !== void 0;
2688
+ }
2689
+ function decodeWindowElementMessage(value) {
2690
+ return decodeMessage(value, isWindowElementPayload);
2691
+ }
2692
+ /**
2693
+ * Reports whether `value` is a well-formed Pay element → hub frame message ({@link ElementHubMessage}, link C), and
2694
+ * rejects every other shape. By `type`:
2695
+ *
2696
+ * - `hub-probe`, `attach` — payload is exactly `{}`; a legacy `kind` key is rejected, even when its value is `undefined`.
2697
+ * - `attach-confirm` — payload keys exactly `attachmentId` (a lowercase canonical version-4 UUID) and `buildId` (1 to
2698
+ * `MAX_HUB_BUILD_ID_LENGTH` ASCII letters, digits, `_` or `-`, starting with a letter or digit).
2699
+ * - `detach` — payload key exactly `attachmentId`, as above.
2700
+ * - `window-opened` — payload keys exactly `windowId` and `requestId` (each a non-empty string of at most
2701
+ * `MAX_MESSAGE_ID_LENGTH` characters) and `request` (a ceremony request, never `init`).
2702
+ * - `window-result` — payload keys exactly `operationId`, `windowId`, `requestId` (ids as above) and `result` (a
2703
+ * ceremony `result` payload, as for {@link isWindowElementMessage}).
2704
+ * - `window-error` — the same ids and `error` (a ceremony `error` payload, as for {@link isWindowElementMessage}).
2705
+ * - `window-ended` — payload keys exactly `operationId` (an id, or `null`), `windowId` and `cause` (`settled`,
2706
+ * `window-cancel`, `window-lost` or `teardown`).
2707
+ * - `window-state` — payload keys exactly `operationId`, `windowId`, `requestId`, `relayId` (ids), `sequence` (a safe
2708
+ * integer from 1) and `state` (as for {@link isWindowElementMessage}'s `relay-state`).
2709
+ * - `sign-in`, `sign`, `sign-out`, `disconnect`, `fund` — as for {@link isAppMessage}.
2710
+ *
2711
+ * `init`, `appearance`, `result` and `error` are rejected. The same envelope, plain-object, exact-key and
2712
+ * `undefined`-as-absent rules apply. It checks shape only, and only the ordinary envelope id: the hub frame checks the
2713
+ * sender's document and relationship, the attachment's namespace and stream order, and matches every message to its
2714
+ * pending table. Never throws.
2715
+ */
2716
+ function isElementHubMessage(value) {
2717
+ return decodeElementHubMessage(value) !== void 0;
2718
+ }
2719
+ function decodeElementHubMessage(value) {
2720
+ return decodeMessage(value, isElementHubPayload);
2721
+ }
2722
+ /**
2723
+ * Reports whether `value` is a well-formed hub frame → Pay element message ({@link HubElementMessage}, link C), and
2724
+ * rejects every other shape. By `type`:
2725
+ *
2726
+ * - `hub-probe-ack`, `pay-source-current` — payload is `{}`.
2727
+ * - `attach-accepted` — the `attach-confirm` payload rules of {@link isElementHubMessage}.
2728
+ * - `attach-refused` — payload keys exactly `code` (a `HubErrorCode`) and `message` (a string of at most
2729
+ * `MAX_ERROR_MESSAGE_LENGTH` characters, possibly empty).
2730
+ * - `balance` — payload key exactly `balance`: `{status: "loading"}` or `{status: "unavailable"}` with no other key,
2731
+ * or `{status: "ready", amount, currency?}` where `amount` is canonical dollars with exactly six decimals (no leading
2732
+ * zero, sign, grouping or exponent), at most `MAX_HUB_BALANCE_AMOUNT_LENGTH` characters and at most `2^256 - 1`
2733
+ * base units, and `currency`, when present, is `USD`.
2734
+ * - `window-accepted` — payload keys exactly `windowId` and `operationId`, each a non-empty string of at most
2735
+ * `MAX_MESSAGE_ID_LENGTH` characters.
2736
+ * - `window-refused` — payload keys exactly `windowId` (an id), `code` and `message` (as for `attach-refused`).
2737
+ * - `window-cancel` — payload keys exactly `operationId`, `windowId` (ids) and `cause` (`window-cancel` or
2738
+ * `teardown`).
2739
+ * - `state`, `transport` — as for {@link isHubMessage}.
2740
+ * - `activity` — as for {@link isHubFrameAppMessage}.
2741
+ * - `result`, `error` — as for {@link isWindowElementMessage}: never an answer to `init`.
2742
+ *
2743
+ * `overlay-hidden` requires an empty payload; its id names the initiating ceremony. `ready`, `overlay-open` and
2744
+ * `overlay-close` are rejected. The same envelope, plain-object, exact-key and `undefined`-as-absent
2745
+ * rules apply. It checks shape only, and only the ordinary envelope id: the Pay element checks the sender's document
2746
+ * and relationship, the attachment's namespace and stream order, and matches every answer to its pending request.
2747
+ * Never throws.
2748
+ */
2749
+ function isHubElementMessage(value) {
2750
+ return decodeHubElementMessage(value) !== void 0;
2751
+ }
2752
+ function decodeHubElementMessage(value) {
2753
+ return decodeMessage(value, isHubElementPayload);
2754
+ }
2755
+ /**
2756
+ * Checks an app-owned Pay window → hub frame payload by `type`: only `app-window-state`, whose payload keys are
2757
+ * exactly `appId` (matching `APP_ID_PATTERN`), `appOrigin` (as for `relay-init`), `sequence` (a safe integer from 1)
2758
+ * and `state` (as for `relay-state`).
2759
+ */
2760
+ function isAppWindowHubPayload(read, type, payload) {
2761
+ if (type !== SUA_APP_WINDOW_MESSAGE_TYPES.state) return false;
2762
+ const fields = read(payload, APP_WINDOW_STATE_KEYS);
2763
+ return fields !== void 0 && isAppId(fields.appId) && isAppOrigin(fields.appOrigin) && isRevision(fields.sequence) && isStateSnapshot(read, fields.state, 64);
2764
+ }
2765
+ /**
2766
+ * Reports whether `value` is a well-formed app-owned Pay window → hub frame message ({@link AppWindowStateMessage}),
2767
+ * and rejects every other shape: `app-window-state` with payload keys exactly `appId` (matching `APP_ID_PATTERN`),
2768
+ * `appOrigin` (1 to `MAX_APP_ORIGIN_LENGTH` characters that `URL` reads as an `http:` or `https:` origin, spelled as
2769
+ * that origin), `sequence` (a safe integer from 1) and `state` (as for {@link isWindowElementMessage}'s
2770
+ * `relay-state`). The same envelope, plain-object, exact-key and `undefined`-as-absent rules apply. It checks shape
2771
+ * only: the hub frame checks the sender's document and relationship, the app connection and the order. Never throws.
2772
+ */
2773
+ function isAppWindowHubMessage(value) {
2774
+ return decodeAppWindowHubMessage(value) !== void 0;
2775
+ }
2776
+ function decodeAppWindowHubMessage(value) {
2777
+ return decodeMessage(value, isAppWindowHubPayload);
2778
+ }
2779
+ /**
2780
+ * A control, format, line-separator or paragraph-separator character: none may appear in an account-email report's
2781
+ * identity or email, so the text the hub shows reads as it was typed and holds no hidden or reordering mark.
2782
+ */
2783
+ const UNSAFE_TEXT_PATTERN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
2784
+ /**
2785
+ * Reports whether `value` is a string of 1 to `maxLength` characters with no control or format character. Its length
2786
+ * is checked first, so a huge string never reaches the pattern.
2787
+ */
2788
+ function isSafeText(value, maxLength) {
2789
+ return isStringOfLength(value, 1, maxLength) && !UNSAFE_TEXT_PATTERN.test(value);
2790
+ }
2791
+ /**
2792
+ * Checks an account-email report's `account`: `null`, or exactly `identityId` (safe text of at most
2793
+ * `MAX_ACCOUNT_IDENTITY_LENGTH` characters), `evmAddress` (matching `EVM_ADDRESS_PATTERN`), `email` (`null`, or safe
2794
+ * text of at most `MAX_ACCOUNT_EMAIL_LENGTH` characters) and `validUntil` (a safe integer from 1).
2795
+ */
2796
+ function isAccountEmailAccount(read, value) {
2797
+ if (value === null) return true;
2798
+ const fields = read(value, ACCOUNT_EMAIL_ACCOUNT_KEYS);
2799
+ return fields !== void 0 && isSafeText(fields.identityId, 256) && isEvmAddress(fields.evmAddress) && (fields.email === null || isSafeText(fields.email, 320)) && isRevision(fields.validUntil);
2800
+ }
2801
+ /**
2802
+ * Checks a `relay-account-email` payload: exactly `relayId`, `requestId` (ids), `sequence`, `stateSequence` (safe
2803
+ * integers from 1) and `account`.
2804
+ */
2805
+ function isRelayAccountEmailPayload(read, type, payload) {
2806
+ if (type !== SUA_ACCOUNT_EMAIL_MESSAGE_TYPES.relay) return false;
2807
+ const fields = read(payload, RELAY_ACCOUNT_EMAIL_KEYS);
2808
+ return fields !== void 0 && isMessageId(fields.relayId) && isMessageId(fields.requestId) && isRevision(fields.sequence) && isRevision(fields.stateSequence) && isAccountEmailAccount(read, fields.account);
2809
+ }
2810
+ /**
2811
+ * Checks a `window-account-email` payload: exactly `operationId`, `windowId`, `requestId`, `relayId` (ids),
2812
+ * `sequence`, `stateSequence` (safe integers from 1) and `account`.
2813
+ */
2814
+ function isWindowAccountEmailPayload(read, type, payload) {
2815
+ if (type !== SUA_ACCOUNT_EMAIL_MESSAGE_TYPES.window) return false;
2816
+ const fields = read(payload, WINDOW_ACCOUNT_EMAIL_KEYS);
2817
+ return fields !== void 0 && isMessageId(fields.operationId) && isMessageId(fields.windowId) && isMessageId(fields.requestId) && isMessageId(fields.relayId) && isRevision(fields.sequence) && isRevision(fields.stateSequence) && isAccountEmailAccount(read, fields.account);
2818
+ }
2819
+ /**
2820
+ * Checks an `app-window-account-email` payload: exactly `appId`, `appOrigin` (as for `app-window-state`), `sequence`,
2821
+ * `stateSequence` (safe integers from 1) and `account`.
2822
+ */
2823
+ function isAppWindowAccountEmailPayload(read, type, payload) {
2824
+ if (type !== SUA_ACCOUNT_EMAIL_MESSAGE_TYPES.appWindow) return false;
2825
+ const fields = read(payload, APP_WINDOW_ACCOUNT_EMAIL_KEYS);
2826
+ return fields !== void 0 && isAppId(fields.appId) && isAppOrigin(fields.appOrigin) && isRevision(fields.sequence) && isRevision(fields.stateSequence) && isAccountEmailAccount(read, fields.account);
2827
+ }
2828
+ /**
2829
+ * Checks an `app-window-account-email-refresh` payload: exactly `appId`, `appOrigin` (as for `app-window-state`),
2830
+ * `refreshId` (an id) and `stateSequence` (a safe integer from 1).
2831
+ */
2832
+ function isAppWindowAccountEmailRefreshPayload(read, type, payload) {
2833
+ if (type !== SUA_ACCOUNT_EMAIL_MESSAGE_TYPES.appWindowRefresh) return false;
2834
+ const fields = read(payload, APP_WINDOW_ACCOUNT_EMAIL_REFRESH_KEYS);
2835
+ return fields !== void 0 && isAppId(fields.appId) && isAppOrigin(fields.appOrigin) && isMessageId(fields.refreshId) && isRevision(fields.stateSequence);
2836
+ }
2837
+ /**
2838
+ * Checks an `app-window-account-email-refresh-reply` payload: exactly `appId`, `appOrigin`, `refreshId` and
2839
+ * `stateSequence` (as for the request), `checkedAt` (a safe integer from 1) and `account`.
2840
+ */
2841
+ function isAppWindowAccountEmailRefreshReplyPayload(read, type, payload) {
2842
+ if (type !== SUA_ACCOUNT_EMAIL_MESSAGE_TYPES.appWindowRefreshReply) return false;
2843
+ const fields = read(payload, APP_WINDOW_ACCOUNT_EMAIL_REFRESH_REPLY_KEYS);
2844
+ return fields !== void 0 && isAppId(fields.appId) && isAppOrigin(fields.appOrigin) && isMessageId(fields.refreshId) && isRevision(fields.stateSequence) && isRevision(fields.checkedAt) && isAccountEmailAccount(read, fields.account);
2845
+ }
2846
+ /**
2847
+ * Decodes a Pay window → opener `relay-account-email` ({@link RelayAccountEmailMessage}) into a frozen snapshot, or
2848
+ * `undefined` for every other shape: payload keys exactly `relayId` and `requestId` (ids), `sequence` and
2849
+ * `stateSequence` (safe integers from 1), and `account`. `account` is `null`, or exactly `identityId` (1 to
2850
+ * `MAX_ACCOUNT_IDENTITY_LENGTH` characters), `evmAddress` (matching `EVM_ADDRESS_PATTERN`), `email` (`null`, or 1 to
2851
+ * `MAX_ACCOUNT_EMAIL_LENGTH` characters) and `validUntil` (a safe integer from 1); the identity and the email hold no
2852
+ * control, format, line-separator or paragraph-separator character. The same envelope, plain-object, exact-key and
2853
+ * `undefined`-as-absent rules as every other guard apply. It checks shape only: the receiver checks the sender's
2854
+ * document, the operation, the state it refers to and the lease. No other guard accepts it. Never throws, and never
2855
+ * reports what it rejected.
2856
+ */
2857
+ function decodeRelayAccountEmailMessage(value) {
2858
+ return decodeMessage(value, isRelayAccountEmailPayload);
2859
+ }
2860
+ /**
2861
+ * Decodes a Pay element → hub frame `window-account-email` ({@link WindowAccountEmailMessage}) into a frozen snapshot,
2862
+ * or `undefined` for every other shape: payload keys exactly `operationId`, `windowId`, `requestId`, `relayId` (ids),
2863
+ * `sequence`, `stateSequence` and `account`, each as for {@link decodeRelayAccountEmailMessage}. It checks shape only,
2864
+ * and only the ordinary envelope id. No other guard accepts it. Never throws.
2865
+ */
2866
+ function decodeWindowAccountEmailMessage(value) {
2867
+ return decodeMessage(value, isWindowAccountEmailPayload);
2868
+ }
2869
+ /**
2870
+ * Decodes an app-owned Pay window → hub frame `app-window-account-email` ({@link AppWindowAccountEmailMessage}) into a
2871
+ * frozen snapshot, or `undefined` for every other shape: payload keys exactly `appId` and `appOrigin` (as for
2872
+ * {@link isAppWindowHubMessage}), `sequence`, `stateSequence` and `account` (as for
2873
+ * {@link decodeRelayAccountEmailMessage}). It checks shape only. No other guard accepts it. Never throws.
2874
+ */
2875
+ function decodeAppWindowAccountEmailMessage(value) {
2876
+ return decodeMessage(value, isAppWindowAccountEmailPayload);
2877
+ }
2878
+ /**
2879
+ * Decodes a hub frame → app-owned Pay window `app-window-account-email-refresh`
2880
+ * ({@link AppWindowAccountEmailRefreshMessage}) into a frozen snapshot, or `undefined` for every other shape: payload
2881
+ * keys exactly `appId` and `appOrigin` (as for {@link isAppWindowHubMessage}), `refreshId` (an id) and `stateSequence`
2882
+ * (a safe integer from 1). The same envelope, plain-object, exact-key and `undefined`-as-absent rules as every other
2883
+ * guard apply. It checks shape only: the Pay window checks that the sender is a hub frame of its app page and that the
2884
+ * state is its current one. No other guard accepts it. Never throws, and never reports what it rejected.
2885
+ */
2886
+ function decodeAppWindowAccountEmailRefreshMessage(value) {
2887
+ return decodeMessage(value, isAppWindowAccountEmailRefreshPayload);
2888
+ }
2889
+ /**
2890
+ * Decodes an app-owned Pay window → hub frame `app-window-account-email-refresh-reply`
2891
+ * ({@link AppWindowAccountEmailRefreshReplyMessage}) into a frozen snapshot, or `undefined` for every other shape:
2892
+ * payload keys exactly `appId`, `appOrigin`, `refreshId` and `stateSequence` (as for
2893
+ * {@link decodeAppWindowAccountEmailRefreshMessage}), `checkedAt` (a safe integer from 1) and `account` (as for
2894
+ * {@link decodeRelayAccountEmailMessage}). It checks shape only: the frame checks the sender's document, its open
2895
+ * request, the state, the check time and the lease. No other guard accepts it. Never throws.
2896
+ */
2897
+ function decodeAppWindowAccountEmailRefreshReplyMessage(value) {
2898
+ return decodeMessage(value, isAppWindowAccountEmailRefreshReplyPayload);
2899
+ }
2900
+ function decodeMessage(value, validate) {
2901
+ try {
2902
+ const { read, freeze } = createSnapshotReader();
2903
+ const envelope = readStrictEnvelope(read, value);
2904
+ if (envelope !== void 0 && validate === isHubElementPayload && envelope.type === SUA_LINK_C_MESSAGE_TYPES.paySource) {
2905
+ const source = readPaySource(read, envelope.payload);
2906
+ if (source === void 0) return void 0;
2907
+ envelope.payload = source;
2908
+ return Object.freeze(envelope);
2909
+ }
2910
+ if (envelope !== void 0) {
2911
+ let payload;
2912
+ if (validate === isElementPayload && envelope.type === PAY_MESSAGE_TYPES.checkoutResult) payload = readCheckoutResult(read, envelope.payload);
2913
+ else if (validate === isHubElementPayload && envelope.type === SUA_LINK_C_MESSAGE_TYPES.checkoutResult) payload = readHubCheckoutResult(read, envelope.payload);
2914
+ else if (validate === isHubElementPayload && envelope.type === SUA_LINK_C_MESSAGE_TYPES.paySourceFunds) payload = readPaySourceFunds(read, envelope.payload);
2915
+ else if (validate === isWindowElementPayload && envelope.type === SUA_RELAY_CONTROL_MESSAGE_TYPES.checkoutResult) {
2916
+ payload = readRelayCheckoutResult(read, envelope.payload, isMessageId, isRevision);
2917
+ if (payload === void 0) return void 0;
2918
+ }
2919
+ if (payload !== void 0) {
2920
+ envelope.payload = payload;
2921
+ return Object.freeze(envelope);
2922
+ }
2923
+ }
2924
+ if (envelope === void 0 || !validate(read, envelope.type, envelope.payload)) return void 0;
2925
+ return freeze(envelope);
2926
+ } catch {
2927
+ return;
2928
+ }
2929
+ }
2930
+ function isAppearance(value) {
2931
+ try {
2932
+ return hasAppearanceTheme(createSnapshotReader().read(value, APPEARANCE_KEYS));
2933
+ } catch {
2934
+ return false;
2935
+ }
2936
+ }
2937
+ //#endregion
2938
+ Object.defineProperty(exports, "APP_ID_PATTERN", {
2939
+ enumerable: true,
2940
+ get: function() {
2941
+ return APP_ID_PATTERN;
2942
+ }
2943
+ });
2944
+ Object.defineProperty(exports, "EVM_ADDRESS_PATTERN", {
2945
+ enumerable: true,
2946
+ get: function() {
2947
+ return EVM_ADDRESS_PATTERN;
2948
+ }
2949
+ });
2950
+ Object.defineProperty(exports, "GUEST_COOKIE_ACCESS_HEADER", {
2951
+ enumerable: true,
2952
+ get: function() {
2953
+ return GUEST_COOKIE_ACCESS_HEADER;
2954
+ }
2955
+ });
2956
+ Object.defineProperty(exports, "HUB_BUILD_ID_PATTERN", {
2957
+ enumerable: true,
2958
+ get: function() {
2959
+ return HUB_BUILD_ID_PATTERN;
2960
+ }
2961
+ });
2962
+ Object.defineProperty(exports, "HUB_CSRF_COOKIE_NAME", {
2963
+ enumerable: true,
2964
+ get: function() {
2965
+ return HUB_CSRF_COOKIE_NAME;
2966
+ }
2967
+ });
2968
+ Object.defineProperty(exports, "HUB_FRAME_NAME_PATTERN", {
2969
+ enumerable: true,
2970
+ get: function() {
2971
+ return HUB_FRAME_NAME_PATTERN;
2972
+ }
2973
+ });
2974
+ Object.defineProperty(exports, "HUB_GUEST_COOKIE_NAME", {
2975
+ enumerable: true,
2976
+ get: function() {
2977
+ return HUB_GUEST_COOKIE_NAME;
2978
+ }
2979
+ });
2980
+ Object.defineProperty(exports, "HUB_NEEDS_POPUP_MESSAGE", {
2981
+ enumerable: true,
2982
+ get: function() {
2983
+ return HUB_NEEDS_POPUP_MESSAGE;
2984
+ }
2985
+ });
2986
+ Object.defineProperty(exports, "HUB_PARTITIONED_GUEST_COOKIE_NAME", {
2987
+ enumerable: true,
2988
+ get: function() {
2989
+ return HUB_PARTITIONED_GUEST_COOKIE_NAME;
2990
+ }
2991
+ });
2992
+ Object.defineProperty(exports, "HUB_SURFACE_ELEMENT", {
2993
+ enumerable: true,
2994
+ get: function() {
2995
+ return HUB_SURFACE_ELEMENT;
2996
+ }
2997
+ });
2998
+ Object.defineProperty(exports, "HUB_SURFACE_POPUP", {
2999
+ enumerable: true,
3000
+ get: function() {
3001
+ return HUB_SURFACE_POPUP;
3002
+ }
3003
+ });
3004
+ Object.defineProperty(exports, "HUB_URL_PARAMS", {
3005
+ enumerable: true,
3006
+ get: function() {
3007
+ return HUB_URL_PARAMS;
3008
+ }
3009
+ });
3010
+ Object.defineProperty(exports, "MAX_ACCOUNT_EMAIL_LEASE_MS", {
3011
+ enumerable: true,
3012
+ get: function() {
3013
+ return MAX_ACCOUNT_EMAIL_LEASE_MS;
3014
+ }
3015
+ });
3016
+ Object.defineProperty(exports, "MAX_ACCOUNT_EMAIL_LENGTH", {
3017
+ enumerable: true,
3018
+ get: function() {
3019
+ return MAX_ACCOUNT_EMAIL_LENGTH;
3020
+ }
3021
+ });
3022
+ Object.defineProperty(exports, "MAX_ACCOUNT_IDENTITY_LENGTH", {
3023
+ enumerable: true,
3024
+ get: function() {
3025
+ return MAX_ACCOUNT_IDENTITY_LENGTH;
3026
+ }
3027
+ });
3028
+ Object.defineProperty(exports, "MAX_APP_ORIGIN_LENGTH", {
3029
+ enumerable: true,
3030
+ get: function() {
3031
+ return MAX_APP_ORIGIN_LENGTH;
3032
+ }
3033
+ });
3034
+ Object.defineProperty(exports, "MAX_ELEMENT_BLOCK_SIZE", {
3035
+ enumerable: true,
3036
+ get: function() {
3037
+ return MAX_ELEMENT_BLOCK_SIZE;
3038
+ }
3039
+ });
3040
+ Object.defineProperty(exports, "MAX_ELEMENT_LABEL_LENGTH", {
3041
+ enumerable: true,
3042
+ get: function() {
3043
+ return MAX_ELEMENT_LABEL_LENGTH;
3044
+ }
3045
+ });
3046
+ Object.defineProperty(exports, "MAX_ELEMENT_RESIZE_DURATION_MS", {
3047
+ enumerable: true,
3048
+ get: function() {
3049
+ return MAX_ELEMENT_RESIZE_DURATION_MS;
3050
+ }
3051
+ });
3052
+ Object.defineProperty(exports, "MAX_ERROR_MESSAGE_LENGTH", {
3053
+ enumerable: true,
3054
+ get: function() {
3055
+ return MAX_ERROR_MESSAGE_LENGTH;
3056
+ }
3057
+ });
3058
+ Object.defineProperty(exports, "MAX_HUB_BALANCE_AMOUNT_LENGTH", {
3059
+ enumerable: true,
3060
+ get: function() {
3061
+ return MAX_HUB_BALANCE_AMOUNT_LENGTH;
3062
+ }
3063
+ });
3064
+ Object.defineProperty(exports, "MAX_HUB_BUILD_ID_LENGTH", {
3065
+ enumerable: true,
3066
+ get: function() {
3067
+ return MAX_HUB_BUILD_ID_LENGTH;
3068
+ }
3069
+ });
3070
+ Object.defineProperty(exports, "MAX_MENU_RECT_VALUE", {
3071
+ enumerable: true,
3072
+ get: function() {
3073
+ return MAX_MENU_RECT_VALUE;
3074
+ }
3075
+ });
3076
+ Object.defineProperty(exports, "MAX_MESSAGE_ID_LENGTH", {
3077
+ enumerable: true,
3078
+ get: function() {
3079
+ return MAX_MESSAGE_ID_LENGTH;
3080
+ }
3081
+ });
3082
+ Object.defineProperty(exports, "MAX_PAGE_URL_LENGTH", {
3083
+ enumerable: true,
3084
+ get: function() {
3085
+ return MAX_PAGE_URL_LENGTH;
3086
+ }
3087
+ });
3088
+ Object.defineProperty(exports, "MAX_PAY_AMOUNT", {
3089
+ enumerable: true,
3090
+ get: function() {
3091
+ return MAX_PAY_AMOUNT;
3092
+ }
3093
+ });
3094
+ Object.defineProperty(exports, "MAX_PAY_ITEM_LENGTH", {
3095
+ enumerable: true,
3096
+ get: function() {
3097
+ return MAX_PAY_ITEM_LENGTH;
3098
+ }
3099
+ });
3100
+ Object.defineProperty(exports, "MAX_PAY_PAYOUT_ADDRESS_LENGTH", {
3101
+ enumerable: true,
3102
+ get: function() {
3103
+ return MAX_PAY_PAYOUT_ADDRESS_LENGTH;
3104
+ }
3105
+ });
3106
+ Object.defineProperty(exports, "MAX_PAY_SOURCE_FUNDS_WALLETS", {
3107
+ enumerable: true,
3108
+ get: function() {
3109
+ return MAX_PAY_SOURCE_FUNDS_WALLETS;
3110
+ }
3111
+ });
3112
+ Object.defineProperty(exports, "MAX_RELAY_STATE_EXPIRY_LENGTH", {
3113
+ enumerable: true,
3114
+ get: function() {
3115
+ return MAX_RELAY_STATE_EXPIRY_LENGTH;
3116
+ }
3117
+ });
3118
+ Object.defineProperty(exports, "MAX_SIGN_MESSAGE_BYTES", {
3119
+ enumerable: true,
3120
+ get: function() {
3121
+ return MAX_SIGN_MESSAGE_BYTES;
3122
+ }
3123
+ });
3124
+ Object.defineProperty(exports, "PAY_AMOUNT_PATTERN", {
3125
+ enumerable: true,
3126
+ get: function() {
3127
+ return PAY_AMOUNT_PATTERN;
3128
+ }
3129
+ });
3130
+ Object.defineProperty(exports, "PAY_CURRENCIES", {
3131
+ enumerable: true,
3132
+ get: function() {
3133
+ return PAY_CURRENCIES;
3134
+ }
3135
+ });
3136
+ Object.defineProperty(exports, "PAY_DESTINATION_ASSET_PATTERN", {
3137
+ enumerable: true,
3138
+ get: function() {
3139
+ return PAY_DESTINATION_ASSET_PATTERN;
3140
+ }
3141
+ });
3142
+ Object.defineProperty(exports, "PAY_DESTINATION_RULE_PATTERN", {
3143
+ enumerable: true,
3144
+ get: function() {
3145
+ return PAY_DESTINATION_RULE_PATTERN;
3146
+ }
3147
+ });
3148
+ Object.defineProperty(exports, "PAY_ELEMENT_FAILURE_CODES", {
3149
+ enumerable: true,
3150
+ get: function() {
3151
+ return PAY_ELEMENT_FAILURE_CODES;
3152
+ }
3153
+ });
3154
+ Object.defineProperty(exports, "PAY_ELEMENT_LIFETIME_MESSAGE_TYPES", {
3155
+ enumerable: true,
3156
+ get: function() {
3157
+ return PAY_ELEMENT_LIFETIME_MESSAGE_TYPES;
3158
+ }
3159
+ });
3160
+ Object.defineProperty(exports, "PAY_ELEMENT_LOAD_FAILURE_REASONS", {
3161
+ enumerable: true,
3162
+ get: function() {
3163
+ return PAY_ELEMENT_LOAD_FAILURE_REASONS;
3164
+ }
3165
+ });
3166
+ Object.defineProperty(exports, "PAY_ELEMENT_MESSAGE_TYPES", {
3167
+ enumerable: true,
3168
+ get: function() {
3169
+ return PAY_ELEMENT_MESSAGE_TYPES;
3170
+ }
3171
+ });
3172
+ Object.defineProperty(exports, "PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES", {
3173
+ enumerable: true,
3174
+ get: function() {
3175
+ return PAY_ELEMENT_NOTIFICATION_MESSAGE_TYPES;
3176
+ }
3177
+ });
3178
+ Object.defineProperty(exports, "PAY_ELEMENT_PATH", {
3179
+ enumerable: true,
3180
+ get: function() {
3181
+ return PAY_ELEMENT_PATH;
3182
+ }
3183
+ });
3184
+ Object.defineProperty(exports, "PAY_FIRST_STEPS", {
3185
+ enumerable: true,
3186
+ get: function() {
3187
+ return PAY_FIRST_STEPS;
3188
+ }
3189
+ });
3190
+ Object.defineProperty(exports, "PAY_FUND_MESSAGE_TYPES", {
3191
+ enumerable: true,
3192
+ get: function() {
3193
+ return PAY_FUND_MESSAGE_TYPES;
3194
+ }
3195
+ });
3196
+ Object.defineProperty(exports, "PAY_FUND_REQUEST_TYPE", {
3197
+ enumerable: true,
3198
+ get: function() {
3199
+ return PAY_FUND_REQUEST_TYPE;
3200
+ }
3201
+ });
3202
+ Object.defineProperty(exports, "PAY_FUND_START_SCREENS", {
3203
+ enumerable: true,
3204
+ get: function() {
3205
+ return PAY_FUND_START_SCREENS;
3206
+ }
3207
+ });
3208
+ Object.defineProperty(exports, "PAY_HUB_FRAME_MESSAGE_TYPES", {
3209
+ enumerable: true,
3210
+ get: function() {
3211
+ return PAY_HUB_FRAME_MESSAGE_TYPES;
3212
+ }
3213
+ });
3214
+ Object.defineProperty(exports, "PAY_JOBS", {
3215
+ enumerable: true,
3216
+ get: function() {
3217
+ return PAY_JOBS;
3218
+ }
3219
+ });
3220
+ Object.defineProperty(exports, "PAY_MESSAGE_TYPES", {
3221
+ enumerable: true,
3222
+ get: function() {
3223
+ return PAY_MESSAGE_TYPES;
3224
+ }
3225
+ });
3226
+ Object.defineProperty(exports, "PAY_PROTOCOL", {
3227
+ enumerable: true,
3228
+ get: function() {
3229
+ return PAY_PROTOCOL;
3230
+ }
3231
+ });
3232
+ Object.defineProperty(exports, "SESSION_HEADER", {
3233
+ enumerable: true,
3234
+ get: function() {
3235
+ return SESSION_HEADER;
3236
+ }
3237
+ });
3238
+ Object.defineProperty(exports, "SESSION_HEADER_OMIT", {
3239
+ enumerable: true,
3240
+ get: function() {
3241
+ return SESSION_HEADER_OMIT;
3242
+ }
3243
+ });
3244
+ Object.defineProperty(exports, "SUA_ACCOUNT_EMAIL_MESSAGE_TYPES", {
3245
+ enumerable: true,
3246
+ get: function() {
3247
+ return SUA_ACCOUNT_EMAIL_MESSAGE_TYPES;
3248
+ }
3249
+ });
3250
+ Object.defineProperty(exports, "SUA_APP_WINDOW_MESSAGE_TYPES", {
3251
+ enumerable: true,
3252
+ get: function() {
3253
+ return SUA_APP_WINDOW_MESSAGE_TYPES;
3254
+ }
3255
+ });
3256
+ Object.defineProperty(exports, "SUA_ELEMENT_GEOMETRY_EASINGS", {
3257
+ enumerable: true,
3258
+ get: function() {
3259
+ return SUA_ELEMENT_GEOMETRY_EASINGS;
3260
+ }
3261
+ });
3262
+ Object.defineProperty(exports, "SUA_ELEMENT_RELOAD_REASONS", {
3263
+ enumerable: true,
3264
+ get: function() {
3265
+ return SUA_ELEMENT_RELOAD_REASONS;
3266
+ }
3267
+ });
3268
+ Object.defineProperty(exports, "SUA_FUND_WINDOW_MESSAGE_TYPE", {
3269
+ enumerable: true,
3270
+ get: function() {
3271
+ return SUA_FUND_WINDOW_MESSAGE_TYPE;
3272
+ }
3273
+ });
3274
+ Object.defineProperty(exports, "SUA_GUEST_HANDOFF_MESSAGE_TYPE", {
3275
+ enumerable: true,
3276
+ get: function() {
3277
+ return SUA_GUEST_HANDOFF_MESSAGE_TYPE;
3278
+ }
3279
+ });
3280
+ Object.defineProperty(exports, "SUA_LINK_C_ID_SEPARATOR", {
3281
+ enumerable: true,
3282
+ get: function() {
3283
+ return SUA_LINK_C_ID_SEPARATOR;
3284
+ }
3285
+ });
3286
+ Object.defineProperty(exports, "SUA_LINK_C_MESSAGE_TYPES", {
3287
+ enumerable: true,
3288
+ get: function() {
3289
+ return SUA_LINK_C_MESSAGE_TYPES;
3290
+ }
3291
+ });
3292
+ Object.defineProperty(exports, "SUA_LINK_C_STREAM_PREFIXES", {
3293
+ enumerable: true,
3294
+ get: function() {
3295
+ return SUA_LINK_C_STREAM_PREFIXES;
3296
+ }
3297
+ });
3298
+ Object.defineProperty(exports, "SUA_PAY_REQUEST_TYPE", {
3299
+ enumerable: true,
3300
+ get: function() {
3301
+ return SUA_PAY_REQUEST_TYPE;
3302
+ }
3303
+ });
3304
+ Object.defineProperty(exports, "SUA_PROTOCOL_VERSION", {
3305
+ enumerable: true,
3306
+ get: function() {
3307
+ return SUA_PROTOCOL_VERSION;
3308
+ }
3309
+ });
3310
+ Object.defineProperty(exports, "SUA_RELAY_CONTROL_MESSAGE_TYPES", {
3311
+ enumerable: true,
3312
+ get: function() {
3313
+ return SUA_RELAY_CONTROL_MESSAGE_TYPES;
3314
+ }
3315
+ });
3316
+ Object.defineProperty(exports, "SUA_RELAY_MESSAGE_TYPES", {
3317
+ enumerable: true,
3318
+ get: function() {
3319
+ return SUA_RELAY_MESSAGE_TYPES;
3320
+ }
3321
+ });
3322
+ Object.defineProperty(exports, "SUA_WINDOW_CANCEL_CAUSES", {
3323
+ enumerable: true,
3324
+ get: function() {
3325
+ return SUA_WINDOW_CANCEL_CAUSES;
3326
+ }
3327
+ });
3328
+ Object.defineProperty(exports, "SUA_WINDOW_END_CAUSES", {
3329
+ enumerable: true,
3330
+ get: function() {
3331
+ return SUA_WINDOW_END_CAUSES;
3332
+ }
3333
+ });
3334
+ Object.defineProperty(exports, "answersPayAmount", {
3335
+ enumerable: true,
3336
+ get: function() {
3337
+ return answersPayAmount;
3338
+ }
3339
+ });
3340
+ Object.defineProperty(exports, "bytesToUtf8", {
3341
+ enumerable: true,
3342
+ get: function() {
3343
+ return bytesToUtf8;
3344
+ }
3345
+ });
3346
+ Object.defineProperty(exports, "comparePayAmounts", {
3347
+ enumerable: true,
3348
+ get: function() {
3349
+ return comparePayAmounts;
3350
+ }
3351
+ });
3352
+ Object.defineProperty(exports, "createHubSuaEnvelope", {
3353
+ enumerable: true,
3354
+ get: function() {
3355
+ return createHubSuaEnvelope;
3356
+ }
3357
+ });
3358
+ Object.defineProperty(exports, "createPayEnvelope", {
3359
+ enumerable: true,
3360
+ get: function() {
3361
+ return createPayEnvelope;
3362
+ }
3363
+ });
3364
+ Object.defineProperty(exports, "decodeAppElementMessage", {
3365
+ enumerable: true,
3366
+ get: function() {
3367
+ return decodeAppElementMessage;
3368
+ }
3369
+ });
3370
+ Object.defineProperty(exports, "decodeAppHubFrameMessage", {
3371
+ enumerable: true,
3372
+ get: function() {
3373
+ return decodeAppHubFrameMessage;
3374
+ }
3375
+ });
3376
+ Object.defineProperty(exports, "decodeAppMessage", {
3377
+ enumerable: true,
3378
+ get: function() {
3379
+ return decodeAppMessage;
3380
+ }
3381
+ });
3382
+ Object.defineProperty(exports, "decodeAppWindowAccountEmailMessage", {
3383
+ enumerable: true,
3384
+ get: function() {
3385
+ return decodeAppWindowAccountEmailMessage;
3386
+ }
3387
+ });
3388
+ Object.defineProperty(exports, "decodeAppWindowAccountEmailRefreshMessage", {
3389
+ enumerable: true,
3390
+ get: function() {
3391
+ return decodeAppWindowAccountEmailRefreshMessage;
3392
+ }
3393
+ });
3394
+ Object.defineProperty(exports, "decodeAppWindowAccountEmailRefreshReplyMessage", {
3395
+ enumerable: true,
3396
+ get: function() {
3397
+ return decodeAppWindowAccountEmailRefreshReplyMessage;
3398
+ }
3399
+ });
3400
+ Object.defineProperty(exports, "decodeAppWindowHubMessage", {
3401
+ enumerable: true,
3402
+ get: function() {
3403
+ return decodeAppWindowHubMessage;
3404
+ }
3405
+ });
3406
+ Object.defineProperty(exports, "decodeElementHubMessage", {
3407
+ enumerable: true,
3408
+ get: function() {
3409
+ return decodeElementHubMessage;
3410
+ }
3411
+ });
3412
+ Object.defineProperty(exports, "decodeElementMessage", {
3413
+ enumerable: true,
3414
+ get: function() {
3415
+ return decodeElementMessage;
3416
+ }
3417
+ });
3418
+ Object.defineProperty(exports, "decodeElementWindowMessage", {
3419
+ enumerable: true,
3420
+ get: function() {
3421
+ return decodeElementWindowMessage;
3422
+ }
3423
+ });
3424
+ Object.defineProperty(exports, "decodeHubElementMessage", {
3425
+ enumerable: true,
3426
+ get: function() {
3427
+ return decodeHubElementMessage;
3428
+ }
3429
+ });
3430
+ Object.defineProperty(exports, "decodeHubFrameAppMessage", {
3431
+ enumerable: true,
3432
+ get: function() {
3433
+ return decodeHubFrameAppMessage;
3434
+ }
3435
+ });
3436
+ Object.defineProperty(exports, "decodeHubMessage", {
3437
+ enumerable: true,
3438
+ get: function() {
3439
+ return decodeHubMessage;
3440
+ }
3441
+ });
3442
+ Object.defineProperty(exports, "decodeRelayAccountEmailMessage", {
3443
+ enumerable: true,
3444
+ get: function() {
3445
+ return decodeRelayAccountEmailMessage;
3446
+ }
3447
+ });
3448
+ Object.defineProperty(exports, "decodeWindowAccountEmailMessage", {
3449
+ enumerable: true,
3450
+ get: function() {
3451
+ return decodeWindowAccountEmailMessage;
3452
+ }
3453
+ });
3454
+ Object.defineProperty(exports, "decodeWindowElementMessage", {
3455
+ enumerable: true,
3456
+ get: function() {
3457
+ return decodeWindowElementMessage;
3458
+ }
3459
+ });
3460
+ Object.defineProperty(exports, "isAppElementMessage", {
3461
+ enumerable: true,
3462
+ get: function() {
3463
+ return isAppElementMessage;
3464
+ }
3465
+ });
3466
+ Object.defineProperty(exports, "isAppHubFrameMessage", {
3467
+ enumerable: true,
3468
+ get: function() {
3469
+ return isAppHubFrameMessage;
3470
+ }
3471
+ });
3472
+ Object.defineProperty(exports, "isAppMessage", {
3473
+ enumerable: true,
3474
+ get: function() {
3475
+ return isAppMessage;
3476
+ }
3477
+ });
3478
+ Object.defineProperty(exports, "isAppWindowHubMessage", {
3479
+ enumerable: true,
3480
+ get: function() {
3481
+ return isAppWindowHubMessage;
3482
+ }
3483
+ });
3484
+ Object.defineProperty(exports, "isAppearance", {
3485
+ enumerable: true,
3486
+ get: function() {
3487
+ return isAppearance;
3488
+ }
3489
+ });
3490
+ Object.defineProperty(exports, "isElementCheckoutResultPayload", {
3491
+ enumerable: true,
3492
+ get: function() {
3493
+ return isElementCheckoutResultPayload;
3494
+ }
3495
+ });
3496
+ Object.defineProperty(exports, "isElementDepositRequestPayload", {
3497
+ enumerable: true,
3498
+ get: function() {
3499
+ return isElementDepositRequestPayload;
3500
+ }
3501
+ });
3502
+ Object.defineProperty(exports, "isElementHubMessage", {
3503
+ enumerable: true,
3504
+ get: function() {
3505
+ return isElementHubMessage;
3506
+ }
3507
+ });
3508
+ Object.defineProperty(exports, "isElementMessage", {
3509
+ enumerable: true,
3510
+ get: function() {
3511
+ return isElementMessage;
3512
+ }
3513
+ });
3514
+ Object.defineProperty(exports, "isElementPaidPayload", {
3515
+ enumerable: true,
3516
+ get: function() {
3517
+ return isElementPaidPayload;
3518
+ }
3519
+ });
3520
+ Object.defineProperty(exports, "isElementPayRequestAckPayload", {
3521
+ enumerable: true,
3522
+ get: function() {
3523
+ return isElementPayRequestAckPayload;
3524
+ }
3525
+ });
3526
+ Object.defineProperty(exports, "isElementPayRequestPayload", {
3527
+ enumerable: true,
3528
+ get: function() {
3529
+ return isElementPayRequestPayload;
3530
+ }
3531
+ });
3532
+ Object.defineProperty(exports, "isElementWindowMessage", {
3533
+ enumerable: true,
3534
+ get: function() {
3535
+ return isElementWindowMessage;
3536
+ }
3537
+ });
3538
+ Object.defineProperty(exports, "isHubBuildId", {
3539
+ enumerable: true,
3540
+ get: function() {
3541
+ return isHubBuildId;
3542
+ }
3543
+ });
3544
+ Object.defineProperty(exports, "isHubElementMessage", {
3545
+ enumerable: true,
3546
+ get: function() {
3547
+ return isHubElementMessage;
3548
+ }
3549
+ });
3550
+ Object.defineProperty(exports, "isHubFrameAppMessage", {
3551
+ enumerable: true,
3552
+ get: function() {
3553
+ return isHubFrameAppMessage;
3554
+ }
3555
+ });
3556
+ Object.defineProperty(exports, "isHubFrameName", {
3557
+ enumerable: true,
3558
+ get: function() {
3559
+ return isHubFrameName;
3560
+ }
3561
+ });
3562
+ Object.defineProperty(exports, "isHubMessage", {
3563
+ enumerable: true,
3564
+ get: function() {
3565
+ return isHubMessage;
3566
+ }
3567
+ });
3568
+ Object.defineProperty(exports, "isSignText", {
3569
+ enumerable: true,
3570
+ get: function() {
3571
+ return isSignText;
3572
+ }
3573
+ });
3574
+ Object.defineProperty(exports, "isSuaEnvelope", {
3575
+ enumerable: true,
3576
+ get: function() {
3577
+ return isSuaEnvelope;
3578
+ }
3579
+ });
3580
+ Object.defineProperty(exports, "isWindowElementMessage", {
3581
+ enumerable: true,
3582
+ get: function() {
3583
+ return isWindowElementMessage;
3584
+ }
3585
+ });
3586
+ Object.defineProperty(exports, "payJobOf", {
3587
+ enumerable: true,
3588
+ get: function() {
3589
+ return payJobOf;
3590
+ }
3591
+ });
3592
+ Object.defineProperty(exports, "sameLegacyPayDestinationAsk", {
3593
+ enumerable: true,
3594
+ get: function() {
3595
+ return sameLegacyPayDestinationAsk;
3596
+ }
3597
+ });
3598
+ Object.defineProperty(exports, "samePayDestinationAsk", {
3599
+ enumerable: true,
3600
+ get: function() {
3601
+ return samePayDestinationAsk;
3602
+ }
3603
+ });
3604
+ Object.defineProperty(exports, "samePayTerms", {
3605
+ enumerable: true,
3606
+ get: function() {
3607
+ return samePayTerms;
3608
+ }
3609
+ });
3610
+ Object.defineProperty(exports, "utf8ToBytes", {
3611
+ enumerable: true,
3612
+ get: function() {
3613
+ return utf8ToBytes;
3614
+ }
3615
+ });
3616
+
3617
+ //# sourceMappingURL=guards-r1nnLHLD.cjs.map