import { BeaconMessageType, BeaconMessageWrapper, DisconnectMessage } from '@tezos-x/octez.connect-types'; interface WrappedPayload { type: unknown; } export declare const MESSAGE_WRAPPED_FROM_VERSION = 3; export declare const MULTI_NETWORK_FROM_VERSION = "4"; export declare const parseStrictDecimalInteger: (value: unknown) => number | null; /** * Compare two `peer.version` strings as strict decimal integers. * * Returns < 0 if `a < b`, 0 if equal, > 0 if `a > b` — same convention as * `Array.prototype.sort` comparators. * * Throws `InvalidBeaconVersionError` if either operand is not a decimal- * integer string in `[0, Number.MAX_SAFE_INTEGER]`. Leading signs, leading * zeros, decimal points, exponent notation, hex, whitespace, `'NaN'` and * `'Infinity'` all reject. * * @category Utility */ export declare const compareBeaconVersion: (a: unknown, b: unknown) => number; /** * Whether `version` is a valid peer.version at or above `threshold`. * * Single source of truth for the "is this peer at least version X" decision. * Returns `false` for an absent version and for any value that fails the * strict decimal-integer contract of `compareBeaconVersion` — i.e. malformed * or untrusted input is always treated as below the threshold, so a hostile * peer cannot trip a higher-version code path. * * @category Utility */ export declare const isAtLeastVersion: (version: string | undefined, threshold: string) => boolean; /** * Whether `version` is at or above the multi-network (v4) threshold. * * @category Utility */ export declare const isMultiNetworkVersion: (version: string | undefined) => boolean; export declare const usesWrappedMessages: (version?: string) => boolean; /** The flat legacy wire dialect served to peers below the wrapped baseline. */ export declare const LEGACY_ENVELOPE_VERSION = "2"; /** * The envelope version to stamp on an outgoing message for a peer that * declared `peerVersion` at pairing: `min(peerVersion, BEACON_VERSION)` with * a floor at the flat legacy dialect ('2'). * * This is the backward-compatibility pivot: a peer that declared '2' — or * never declared a version at all (legacy pairings, WalletConnect peers, * malformed values) — is served the flat v2 dialect it has always spoken; a * v3 peer receives '3' wrapped envelopes and never sees v4 payload fields; * a v4 peer gets the full wrapped v4 wire. Callers pick the message SHAPE * with `usesWrappedMessages(negotiated)` and gate v4 fields (`networks`/ * `accounts`) on `isMultiNetworkVersion(negotiated)`. * * @category Utility */ export declare const negotiateEnvelopeVersion: (peerVersion: string | undefined) => string; /** * The peer's version as safe to feed into capability negotiation * ({@link negotiateEnvelopeVersion}, multi-network gating, minimum-version * enforcement). * * `peer.version` alone CANNOT be trusted: legacy wallets (octez.connect * 4.8.x and upstream beacon-sdk forks) build their pairing response with the * version field of the dApp's pairing REQUEST — they echo the dApp's own * version back instead of declaring theirs. A v5 dApp reading that echo sees * '4', serves a wrapped v4 envelope, and the legacy wallet silently drops it * after pairing ("Pairing complete! Waiting for permission request…"). * * The reliable capability marker is `protocolVersion`: v5+ pairing responses * attach it on every transport that can carry it (P2P, PostMessage), legacy * responses never do, and it cannot be echoed (legacy constructors don't * know the field). A peer that DECLARES a version without a valid marker * (a positive protocol version, matching the protocol's minimum of 1) is * therefore treated as a legacy flat-v2 speaker regardless of its echoed * `version` — exactly the wire a 4.8.x dApp would have served it. * * A peer that declares NO version at all keeps the long-standing "unknown" * semantics and maps to `undefined` (WalletConnect pairings, where beacon * versions are never fabricated and capability is negotiated via session * namespaces): version gates treat unknown as allowed-through and response * handling falls back to the response envelope's version. The echo problem * by definition only exists for peers that DO carry a version. * * @category Utility */ export declare const effectivePeerVersion: (peer: { version?: string; protocolVersion?: unknown; } | undefined) => string | undefined; /** * Build a wrapped beacon envelope. Single source of truth for the * `{ id, version, senderId, message }` wire shape so senders cannot drift. * * @category Utility */ export declare const wrapBeaconMessage: (envelope: { id: string; version: string; senderId: string; }, message: T) => BeaconMessageWrapper; /** * Extract the inner payload of a wrapped beacon envelope, or `undefined` * when the candidate's version does not follow the wrapped (v3+) contract. * Callers must treat `undefined` as "not a wrapped message" and drop or * tombstone it — never fall back to reading flat fields. * * @category Utility */ export declare const unwrapBeaconMessage: (candidate: { version?: string; message?: T; }) => T | undefined; /** * Build a disconnect message in the peer's negotiated dialect: a wrapped * envelope for v3+ peers, the flat legacy shape for v2 peers. A legacy peer * routes on the top-level `type` and would silently ignore a wrapped * envelope — the goodbye must be spoken in the dialect the peer parses. * * @category Utility */ export declare const buildDisconnectMessage: (envelope: { id: string; senderId: string; }, peerVersion: string | undefined) => DisconnectMessage | BeaconMessageWrapper<{ type: BeaconMessageType.Disconnect; }>; export {};