Addresses, display names and links (01): the SV local-part profile, domains, canonicalize, canonical-address checks, display names, sloppyv URIs and HTTPS share links. Entry point @sloppyvoice/sdk/address.

import { … } from '@sloppyvoice/sdk/address'

Functions

addressError function

function addressError(code: "address.non_canonical" | "address.invalid" | "address.invalid_local_part" | "address.invalid_domain" | "address.invalid_link" | "address.display_name_mismatch" | "address.not_allowed" | "address.not_found" | "address.taken" | "address.too_similar" | "address.reserved" | "address.quarantined" | "address.deleted", data?: Record<string, unknown>, detail?: string): SloppyVoiceError

Build (not throw) a SloppyVoiceError for an address.* code with the status, userAction and retryable of 01 §12.1 and the given data.

code: "address.non_canonical" | "address.invalid" | "address.invalid_local_part" | "address.invalid_domain" | "address.invalid_link" | "address.display_name_mismatch" | "address.not_allowed" | "address.not_found" | "address.taken" | "address.too_similar" | "address.reserved" | "address.quarantined" | "address.deleted"
data?: Record<string, unknown>
detail?: string

Source: address/errors.ts:17

aLabelToULabel function

function aLabelToULabel(label: string): string | null

Decode an xn-- A-label to its U-label, or return null if it isn't valid Punycode (RFC 5891 §5.4, 01 §4.3 condition 1).

label: string

Source: address/domain.ts:106

assertCanonical function

function assertCanonical(addr: unknown, options?: CanonicalCheckOptions & { field?: string }): asserts addr is string

Throw address.non_canonical (01 §12.1) unless addr passes checkCanonical. field names the member (a JSON Pointer or claim name) for data.field.

addr: unknown
options: CanonicalCheckOptions & { field?: string }

Default: {}

Source: address/canonical.ts:87

canonicalInviteForLink function

function canonicalInviteForLink(invite: string): string

An invite code in 09's canonical form (12 Crockford base32 characters, no display hyphens), as generated links carry it (01 §10.3 step 4, §11.2; 09 §8.2). Accepts any form 09's normalization accepts; throws sdk.invalid_argument for a code that 09 would treat as unknown.

invite: string

Source: address/uri.ts:215

canonicalize function

function canonicalize(input: string, options: CanonicalizeOptions): Promise<CanonicalizeResult>

canonicalize(input, defaultDomain) (01 §7.2). Every client MUST use it for every address that comes from a person or a link. Steps: lenient parse (01 §8), prepareLocal, prepareDomain, discovery, canonical-domain check, and, for a local part that this SDK's Unicode data rejects, the confirmation lookup at the owning server (AD-14).

Throws address.* errors (01 §7.3), the discovery.* errors of 02, or the lookup's errors. A client that is offline MUST NOT fall back to the typed domain (01 §7.3). The typed domain is never returned (01 §7.8).

input: string

Source: address/canonicalize.ts:123

checkCanonical function

function checkCanonical(addr: unknown, options?: CanonicalCheckOptions): CanonicalCheck

isCanonical(addr, expectedDomain?) as a detailed check (01 §7.5): the syntactic checks 1 to 5 always, check 6 when canonicalDomain or expectedDomain is given. It never runs the full profile of 01 §3 (AD-8): an address isn't rejected because it would fail the profile under this SDK's Unicode version.

Reasons: malformed (not one @, empty parts, invalid UTF-16/UTF-8), local_not_prepared (checks 1 to 4 on the local part), domain_not_alabel (check 5), alias_domain (check 6).

addr: unknown
options: CanonicalCheckOptions

Default: {}

Source: address/canonical.ts:45

checkDisplayName function

function checkDisplayName(name: string | null | undefined, address: string): DisplayNameCheck

checkDisplayName(name, address), the receiver check (01 §6.4). Every client MUST run it on every display name it renders, whatever the source. On success it returns the normalized string S to show (never the unnormalized name). On failure the caller shows the prepared local part instead and shows no warning (01 §6.5).

It needs no confusable data, collision table or network, and leaves out the version-dependent steps 10 to 13 of prepareLocal (AD-8).

name: string | null | undefined
address: string

Source: address/display.ts:57

ckey function

function ckey(x: string): string

ckey(X), the case-insensitive collision key (01 §5.3): the skeleton, then up to three rounds of skeleton(toCasefold(k)) until it settles.

x: string

Source: address/skeleton.ts:51

compareAddresses function

function compareAddresses(a: string, b: string): number

Protocol order of two canonical addresses (01 §7.10): their UTF-8 octets compared as unsigned bytes, a proper prefix first; equal to code-point order and not locale-aware. Returns a negative number, zero or a positive number.

a: string
b: string

Source: address/canonical.ts:130

displayDomain function

function displayDomain(domain: string): string

How a domain may be shown (01 §4.3): the U-label form only if every label passes all four conditions, otherwise the A-label form for the whole domain.

  1. each xn-- label decodes to a valid IDNA2008 U-label;
  2. the U-label meets the Highly Restrictive rule (01 §3.5.1) and one digit system (01 §3.5.2);
  3. it isn't a whole-script confusable of an ASCII label (its skeleton isn't all ASCII letters, digits and -);
  4. every code point's Identifier_Type is Recommended, Inclusion or Limited_Use.
domain: string

Source: address/display.ts:102

displayForm function

function displayForm(address: string, name?: string | null, options?: DisplayFormOptions): string

The display form of an address (01 §6.6): display-local form, @, and the displayed domain. For people only: never store it or send it in a JSON member as an address (01 §2.3).

address: string
name?: string | null
options: DisplayFormOptions

Default: {}

Source: address/display.ts:133

displayLocal function

function displayLocal(address: string, name?: string | null): string

The display-local form of an address (01 §6.6): the display name with all White_Space removed if it passes the receiver check, otherwise the prepared local part. It always prepares back to the local part.

address: string
name?: string | null

Source: address/display.ts:88

displayNameKeyInput function

function displayNameKeyInput(displayName: string): string

The form of a display name D that 01 §5.3 keys: all White_Space removed, width-mapped and NFC-normalized.

displayName: string

Source: address/skeleton.ts:65

domainOf function

function domainOf(address: string): string

The domain of an address: everything after the last @ (01 §2.2).

address: string

Source: address/display.ts:26

domainToUnicode function

function domainToUnicode(domain: string): string | null

The U-label form of an A-label domain (01 §4.3): every xn-- label decoded, other labels unchanged. Returns null if a label doesn't decode to a valid IDNA2008 U-label. Whether the result may be shown is decided by displayDomain (01 §4.3).

domain: string

Source: address/domain.ts:233

effectiveAddressReason function

function effectiveAddressReason(code: string, reason: unknown): string | undefined

The reason a receiver acts on for an address.* problem (01 §12.1): an unknown data.reason is read as the most general reason listed for that code. For address.not_found, 01 §9.4 names taken.

code: string
reason: unknown

Source: address/errors.ts:37

entryCollisionKeys function

function entryCollisionKeys(local: string, displayName?: string | null): { local: string; name: string | null }

Collision keys of a user, bot or channel entry (01 §5.3): ckey(local) and, when a display name is set, ckey(D) of the display name.

local: string
displayName?: string | null

Source: address/skeleton.ts:73

expandShareLink function

function expandShareLink(template: string, vars: { local?: string; domain: string; invite?: string }): string | null

Expand a share link from a valid template (01 §11.2): local is the display-local form (undefined for a community), domain the canonical domain as an A-label, invite the invite code in 09's canonical form. Returns null if the template is invalid (01 §11.2: treat as absent). The caller must also have checked the host with isJoinTemplateHostBound.

template: string
vars: { local?: string; domain: string; invite?: string }

Source: address/share-link.ts:251

expandUriTemplate function

function expandUriTemplate(template: string | TemplatePart[], vars: Readonly<Record<string, string | undefined>>): string

Expand a URI Template of level 3 or below (RFC 6570 §3.2). Variables that are undefined are undefined in the RFC 6570 sense (skipped); values are strings. Throws sdk.invalid_argument for a malformed template.

template: string | TemplatePart[]
vars: Readonly<Record<string, string | undefined>>

Source: address/share-link.ts:116

fetchShareLinkTarget function

function fetchShareLinkTarget(url: string, options?: FetchShareLinkOptions): Promise<LinkTarget>

Fetch a pasted share link to read its alternate sloppyv URI (01 §11.4 step 3), under every limit of that step: HTTPS only (http: is tried as https:), at most 3 redirects, all HTTPS, no credentials or cookies, 5 s, at most 64 KiB of body, HEAD first and GET only if HEAD gives no usable Link header. Returns the parsed target (01 §10.4).

Call it only after the person explicitly pasted or opened this URL; a client MUST NOT fetch links merely because they appear in a message. Throws address.invalid_link with fetch_failed on a network error or an unreadable response, and not_a_share_link when nothing usable is found.

url: string
options: FetchShareLinkOptions

Default: {}

Source: address/share-link.ts:520

firstSloppyvAlternate function

function firstSloppyvAlternate(candidates: readonly string[]): string | null

The first alternate link whose target has the scheme sloppyv or web+sloppyv (01 §11.4 step 4).

candidates: readonly string[]

Source: address/share-link.ts:470

formatSloppyvUri function

function formatSloppyvUri(target: ShareTarget, options?: FormatUriOptions): string

Generate a sloppyv URI (01 §10.3): sloppyv://, the display-local form percent-encoded (every octet outside ALPHA / DIGIT, uppercase hex) and @ for an address target, the canonical domain as an A-label, and ?invite= with the code in 09's canonical form if there is one. Nothing else. Throws sdk.invalid_argument for a target that isn't in wire form (canonicalize it first) or an invite code that 09 §8.2 rejects.

A client that re-shares a target generates a fresh URI with this function rather than copying the one it received (01 §10.4).

target: ShareTarget
options: FormatUriOptions

Default: {}

Source: address/uri.ts:176

hasOneDigitSystem function

function hasOneDigitSystem(cps: readonly number[]): boolean

Whether all Nd code points come from one decimal digit system (01 §3.5.2).

cps: readonly number[]

Source: address/precis.ts:294

hasSloppyvScheme function

function hasSloppyvScheme(s: string): boolean

Whether a string starts with a sloppyv: or web+sloppyv: scheme, ASCII case-insensitively (01 §8.2 step 3).

s: string

Source: address/uri.ts:48

htmlAlternateLinks function

function htmlAlternateLinks(html: string): string[]

Find <link rel="alternate" href="…"> elements in an HTML document's <head>, in order (01 §11.3 item 2, §11.4 step 3).

html: string

Source: address/share-link.ts:453

inviteFromQuery function

function inviteFromQuery(query: string): string | undefined

Take the invite parameter from a query string without its ? (01 §10.4 step 9): parameter names are case-sensitive, other parameters are ignored, more than one invite throws duplicate_param, a bad value throws bad_invite.

query: string

Source: address/uri.ts:69

isCanonical function

function isCanonical(addr: unknown, options?: CanonicalCheckOptions): addr is string

Whether addr passes checkCanonical (01 §7.5).

addr: unknown
options: CanonicalCheckOptions

Default: {}

Source: address/canonical.ts:78

isCanonicalDomain function

function isCanonicalDomain(domain: unknown, checkALabels?: boolean): domain is string

Whether a string is a canonical domain on its own (01 §7.5 check 5, as used for iss and similar members).

domain: unknown
checkALabels: boolean

Default: true

Source: address/canonical.ts:97

isDisplayNameSyntax function

function isDisplayNameSyntax(name: string): boolean

Whether a stored display name meets the syntax of 01 §6.2 rules 2 to 4 (linkage, rule 1, needs the local part: see checkDisplayName).

name: string

Source: address/display.ts:199

isHighlyRestrictive function

function isHighlyRestrictive(cps: readonly number[]): boolean

Whether a string meets the script condition of UTS #39 Highly Restrictive as 01 §3.5.1 computes it.

cps: readonly number[]

Source: address/precis.ts:281

isJoinTemplateHostBound function

function isJoinTemplateHostBound(hostname: string, server: Pick<ResolvedServer, "baseUrl">, resolver: DomainResolver, options?: { signal?: AbortSignal }): Promise<boolean>

Whether a template's host belongs to the server by discovery (01 §11.2, §11.4 step 1): it is the host of the server's base URL, or it resolves through 02 to the same base URL. Never by the server's own domains list or a same-site test.

hostname: string
server: Pick<ResolvedServer, "baseUrl">
resolver: DomainResolver
options: { signal?: AbortSignal }

Default: {}

Source: address/share-link.ts:229

isolateAddress function

function isolateAddress(displayFormText: string): string

Wrap a display form for rendering in plain text (01 §6.8 rule 1): the whole address in a left-to-right isolate, the display-local form inside it in a first-strong isolate. Presentation only; never put the result on the clipboard (rule 3).

displayFormText: string

Source: address/display.ts:160

isolateName function

function isolateName(name: string): string

Wrap a display name in a first-strong isolate (01 §6.8 rule 2). Presentation only.

name: string

Source: address/display.ts:167

isValidALabel function

function isValidALabel(label: string): boolean

Whether label is an A-label (xn-- plus Punycode, lowercase) that decodes to a valid IDNA2008 U-label and re-encodes to itself (01 §4.1 step 5, §7.5 check 5).

label: string

Source: address/domain.ts:116

isValidULabel function

function isValidULabel(label: string): boolean

Whether a Unicode label is a valid IDNA2008 U-label (RFC 5891 §5.4, §4.2, RFC 5892): NFC, non-empty, at least one non-ASCII code point, no leading combining mark, no hyphen at the start, the end or in positions 3 and 4, and every code point PVALID, or CONTEXTJ or CONTEXTO with its rule satisfied (RFC 5892 Appendix A). The Bidi Rule is a whole-domain check: see satisfiesDomainBidi.

label: string

Source: address/domain.ts:87

isWellFormedDomain function

function isWellFormedDomain(domain: string, checkALabels?: boolean): boolean

Whether a domain meets the syntactic rules for a canonical domain (01 §7.5 check 5, §2.2): at most 253 octets, at least two labels of 1 to 63 octets, only [0-9a-z.-], no trailing dot, last label not all digits, LDH labels without -- in positions 3 and 4 unless an A-label. With checkALabels (the SHOULD of check 5), every xn-- label must also decode to a valid U-label.

domain: string
checkALabels: boolean

Default: true

Source: address/domain.ts:212

linkPrepare function

function linkPrepare(s: string): PrepareResult

linkPrepare(s) (01 §3.2): steps 2 to 9 of prepareLocal, without the Sloppy Voice restrictions whose data changes between Unicode versions. A display name N is linked to a local part L exactly when linkPrepare(N) gives L (01 §6.1).

s: string

Source: address/precis.ts:384

localPartOf function

function localPartOf(address: string): string

The local part of an address: everything before the last @, unchanged (01 §6.4 step 1).

address: string

Source: address/display.ts:20

matchShareLink function

function matchShareLink(url: string, template: string): ShareLinkMatch | "unsupported" | null

Match a URL against a links.join template, left to right (01 §11.4 step 2). Works only on templates whose expressions are among {local}, {/local}, {domain}, {/domain} and {?invite}; returns 'unsupported' for others and null when the URL doesn't match. Scheme and host compare ASCII case-insensitively, the rest case-sensitively; the fragment is ignored; matched values are percent-decoded once as UTF-8.

Throws address.invalid_link with duplicate_param, bad_invite or invalid_utf8. Only call it for a template that step 1 allows for the URL's host.

url: string
template: string

Source: address/share-link.ts:325

minimalPrepare function

function minimalPrepare(s: string): PrepareResult

minimalPrepare(s) (01 §3.2): remove white space, width-map, map U+0130 to U+0049, case-fold and NFC-normalize. Fails only with empty. It uses only version-stable mappings, so it checks canonical addresses (01 §7.5) and finds grandfathered names (01 §7.2, §9.2).

s: string

Source: address/precis.ts:371

mustShowDomain function

function mustShowDomain(address: string, contextDomain: string): boolean

Whether the domain must be shown with an address (01 §4.4 rule 1): when the address's canonical domain differs from the context domain, octet for octet. Where it is equal the client MAY show the display name alone; 01 §4.4 rule 3 lists screens that always show the full display form.

address: string
contextDomain: string

Source: address/display.ts:145

parseInput function

function parseInput(input: string): ParsedInput

parseInput(T) (01 §8.2). It never changes letters, case or accents (that is prepareLocal's job) and never guesses. Throws address.invalid (too_long, empty, invalid_utf8, multiple_at), address.invalid_local_part (empty) or the address.invalid_link errors of parseSloppyvUri.

input: string

Source: address/parse.ts:62

parseLinkHeader function

function parseLinkHeader(value: string | null | undefined): WebLink[]

Parse an RFC 8288 Link header value into links with their rel types.

value: string | null | undefined

Source: address/share-link.ts:410

parseSloppyvUri function

function parseSloppyvUri(uri: string): LinkTarget

parseSloppyvUri(U) (01 §10.4): parse a sloppyv or web+sloppyv URI or IRI into a target and an optional invite code. Paths, fragments and unknown parameters are ignored. Throws address.invalid_link with scheme, userinfo_password, port, ip_literal, invalid_utf8, duplicate_param or bad_invite.

The caller passes the result to canonicalize, which prepares the local part and the domain. The invite code is checked only by 09 when redeemed.

uri: string

Source: address/uri.ts:94

parseUriTemplate function

function parseUriTemplate(template: string): TemplatePart[] | null

Parse an RFC 6570 URI Template of level 3 or below (no prefix or explode modifiers). Returns null for a malformed template or one that uses level 4 features or reserved operators.

template: string

Source: address/share-link.ts:53

passesStableLocalChecks function

function passesStableLocalChecks(local: string): boolean

01 §7.5 checks 2 to 4 applied to a local part (and the canonical-local grammar of check 1, which no server-confirmed local part can break).

local: string

Source: address/canonicalize.ts:85

percentDecodeUtf8 function

function percentDecodeUtf8(s: string): string | null

Percent-decode a string exactly once and interpret the octets as UTF-8 (01 §8.2 step 4, §9.2 step 1, §10.4 steps 7 to 9). Characters that aren't part of a %XX triplet are kept as they are (their own UTF-8 octets), so IRIs with Unicode text decode too. A % not followed by two hex digits is kept literally. Returns null if the octets aren't valid UTF-8.

s: string

Source: address/percent.ts:18

precisIdentifierClass function

function precisIdentifierClass(cp: number): PrecisPropertyValue

The IdentifierClass derived property value of a code point under Unicode 16.0.0 (RFC 8264 §8). ID_DIS and FREE_PVAL are reported as DISALLOWED, which is what they mean in the IdentifierClass.

cp: number

Source: address/precis.ts:105

prepareDisplayName function

function prepareDisplayName(proposed: string, local: string): DisplayNameResult

Process a proposed display name P for an entry with prepared local part local (01 §6.3 steps 1 to 3), as every endpoint that sets a display name MUST. Server side; clients can use it to preview what the server will store. Collision checks (step 4) are the server's (ckey).

An empty or white-space-only proposal clears the display name: the result is the prepared local part itself (01 §6.3).

proposed: string
local: string

Source: address/display.ts:188

prepareDomain function

function prepareDomain(d: string): DomainResult

prepareDomain(d) (01 §4.1): turn the domain part of an input into a lowercase A-label domain (the typed domain, used only as discovery input), or fail with a 01 §4.2 reason.

d: string

Source: address/domain.ts:158

prepareLocal function

function prepareLocal(s: string): PrepareResult

prepareLocal(s) (01 §3.2): turn a local part in any input form (case, width and spacing variants, a display name) into the prepared local part, or report why it fails, with a reason of 01 §3.9 and, where 01 §3.9 defines one, the index of the code point to blame.

Uses Unicode 16.0.0 data (01 §1.4). It never transliterates, strips accents, maps lookalikes or truncates.

s: string

Source: address/precis.ts:357

provisionalForm function

function provisionalForm(input: string): { address?: string; local?: string; domain: string; unresolved: true }

The provisional prepared form of a moderation or policy target whose discovery failed (01 §7.7): the prepared local part and the typed domain as a lowercase A-label, flagged unresolved. Such values may be stored only where the owning document allows, re-resolved at least every 24 h, and never put into signed objects, S2S events or identity bindings.

input: string

Source: address/canonicalize.ts:239

punycodeDecode function

function punycodeDecode(input: string): string | null

Decode Punycode (RFC 3492 §6.2), without the xn-- prefix. Returns null for invalid input (bad digits, overflow, non-ASCII input, or a result containing surrogates).

input: string

Source: address/punycode.ts:94

punycodeEncode function

function punycodeEncode(input: string): string

Encode a Unicode label as Punycode (RFC 3492 §6.3), without the xn-- prefix. Throws sdk.invalid_argument on overflow or a lone surrogate.

input: string

Source: address/punycode.ts:46

readAddressInfo function

function readAddressInfo(info: AddressInfo, canonicalDomain?: string): AddressInfoView | null

Read an AddressInfo (01 §9.3). If canonicalDomain (the server's, from 02) is given, address must be canonical at that domain; otherwise only the syntactic checks run. Returns null for a response whose address isn't canonical, which the caller treats as a failed lookup.

canonicalDomain?: string

Source: address/info.ts:42

reservedClass function

function reservedClass(preparedLocal: string): ReservedClass | null

The class of a local part in the initial reserved registry (01 §5.4), or null. Matches the prepared local part only.

preparedLocal: string

Source: address/skeleton.ts:110

reservedCollisionKeys function

function reservedCollisionKeys(r: string): string[]

Collision keys of a reserved name r (01 §5.3): ckey(r), ckey(Titlecase(r)) and ckey(Uppercase(r)), without duplicates.

r: string

Source: address/skeleton.ts:105

reservedKeyIndex function

function reservedKeyIndex(extra?: Readonly<Record<string, ReservedClass>>): Map<string, string[]>

A map from collision key to the reserved local parts (registry of 01 §5.4, plus any server-local reservations) that hold it. Servers use it to refuse confusable spellings of reserved names (01 §5.4: "Matching is by prepared local part and by collision key").

extra: Readonly<Record<string, ReservedClass>>

Default: {}

Source: address/skeleton.ts:120

resolveCanonicalDomain function

function resolveCanonicalDomain(typedDomain: string, resolver: DomainResolver, options?: { signal?: AbortSignal }): Promise<ResolvedServer>

Resolve a typed domain and check its canonical domain (01 §7.2 steps 4 and 5, 02 §5.2 step 8, §5.3, §7.4 step 3): D must be in the metadata's domains when the resolver reports them (discovery.domain_not_served), C must be a well-formed lowercase A-label domain listed in domains (discovery.metadata_invalid), and C must resolve back to the same base URL (discovery.canonical_mismatch). Errors of resolving C propagate unchanged (02 §5.3).

typedDomain: string
resolver: DomainResolver
options: { signal?: AbortSignal }

Default: {}

Source: address/resolve.ts:56

resolveShareLink function

function resolveShareLink(url: string, options: ResolveShareLinkOptions): Promise<LinkTarget>

Turn a pasted HTTPS URL into a sloppyv target (01 §11.4): match it against the links.join template of a server its host belongs to by discovery (never any other server's template), and otherwise, if allowed, fetch it and read its alternate link. Throws address.invalid_link (not_a_share_link, fetch_failed, duplicate_param, bad_invite, invalid_utf8); the client then treats the URL as an ordinary web link.

url: string

Source: address/share-link.ts:622

rewriteOwnAlias function

function rewriteOwnAlias(addr: string, own: OwnDomains): string

Process an {addr} path parameter that names an address on another server (01 §7.7): an address whose domain is one of this server's own alias domains is rewritten to the canonical domain; any other non-canonical address throws address.non_canonical (400). Returns the canonical address.

addr: string

Source: address/canonical.ts:115

runtimeUnicodeOk function

function runtimeUnicodeOk(recheck?: boolean): boolean

Whether the runtime's Unicode data is 16.0.0 or later in every place the SDK relies on it (01 §1.4): NFKC (HasCompat), the Changes_When_NFKC_Casefolded regular-expression property, NFC composition and UTS #46 mapping in the URL parser. Checked once and cached; recheck runs it again (for tests).

recheck: boolean

Default: false

Source: address/unicode.ts:49

sameAddress function

function sameAddress(a: string, b: string): boolean

Whether two addresses are the same address: their canonical forms are identical octet for octet (01 §3.7, §7.10).

a: string
b: string

Source: address/canonical.ts:149

sameBaseUrl function

function sameBaseUrl(a: string, b: string): boolean

Whether two base URLs name the same server: equal after 02 §3.3 normalization (https://Chat.example.com:443/server/ and https://chat.example.com/server are the same server). A value that isn't a valid base URL is compared as given, minus trailing slashes.

a: string
b: string

Source: address/resolve.ts:41

satisfiesBidiRule function

function satisfiesBidiRule(cps: readonly number[]): boolean

Whether a label satisfies all six conditions of the Bidi Rule (RFC 5893 §2).

cps: readonly number[]

Source: address/precis.ts:182

shareLinkFor function

function shareLinkFor(target: ShareTarget, server: ResolvedServer, resolver: DomainResolver, options?: { invite?: string; signal?: AbortSignal }): Promise<string | null>

Generate the HTTPS share link for a target (01 §11.2 generation rules): built from the template of the target's server (the server canonicalize resolved), with the canonical domain and the display-local form. Returns null when that server publishes no valid template, or its host isn't bound to the server by discovery; the client then offers the sloppyv URI alone. Throws sdk.invalid_argument for a target that isn't in wire form or an invite code 09 §8.2 rejects.

target: ShareTarget
resolver: DomainResolver
options: { invite?: string; signal?: AbortSignal }

Default: {}

Source: address/share-link.ts:276

shareTargetDomain function

function shareTargetDomain(target: ShareTarget): string

The canonical domain of a link target, after checking that the target is in wire form: generated links use only the canonical address or canonical domain (01 §10.3 steps 2 and 3, §11.2 rule 2, §7.6). Throws sdk.invalid_argument for an input form, which must go through canonicalize first.

target: ShareTarget

Source: address/uri.ts:196

shownName function

function shownName(address: string, name?: string | null): string

What to show as the name of an address (01 §6.4, §6.5): the checked display name, or the prepared local part when the name is absent, null or fails the check.

address: string
name?: string | null

Source: address/display.ts:73

shownNameOf function

function shownNameOf(ref: AddressRef): string

shownName for an AddressRef (01 §6.7).

Source: address/display.ts:79

skeleton function

function skeleton(x: string): string

skeleton(X), the UTS #39 §4 confusable skeleton (01 §5.3): NFD, remove Default_Ignorable_Code_Point, replace each code point by its prototype, NFD again. Used only for collision checks, never displayed or sent.

x: string

Source: address/skeleton.ts:37

sortAddresses function

function sortAddresses(addresses: readonly string[]): string[]

Sort canonical addresses into protocol order (01 §7.10), returning a new array.

addresses: readonly string[]

Source: address/canonical.ts:144

stripIsolates function

function stripIsolates(s: string): string

Remove the isolation characters of 01 §6.8 (U+2066 to U+2069), for text put on the clipboard (rule 3).

s: string

Source: address/display.ts:172

validateJoinTemplate function

function validateJoinTemplate(template: unknown): JoinTemplateCheck

Check the syntax rules of a links.join template (01 §11.2, 02 §7.3.4): RFC 6570 level 3 or below, at most 512 octets, only the variables local, domain and invite, referencing local and invite, scheme https and authority as literal text, and every expansion an absolute https URI. A template that fails is treated as absent.

The host rule (the host belongs to the server by discovery) needs resolution: see isJoinTemplateHostBound.

template: unknown

Source: address/share-link.ts:168

verifyCanonical function

function verifyCanonical(addr: string, options: { resolver: DomainResolver; expectedDomain?: string; field?: string; signal?: AbortSignal }): Promise<{ local: string; domain: string; server: ResolvedServer }>

The semantic canonical-address check (01 §7.5 checks 1 to 6): the syntactic checks, then the address's domain resolved through 02 and compared with that server's canonicalDomain (and expectedDomain if given). Throws address.non_canonical with its reason, or the discovery.* error of 02 when the domain can't be resolved (the address may be canonical, but nothing can be said yet).

Don't call it in the no-contact flows of 01 §7.5 (02 §5.8), where a verifier must not resolve the server's domain itself.

addr: string
options: { resolver: DomainResolver; expectedDomain?: string; field?: string; signal?: AbortSignal }

Source: address/canonicalize.ts:212

Interfaces

AddressInfoView interface

A summary of an AddressInfo with every 01 §9.3 unknown-value rule applied.

interface AddressInfoView

kind

kind: "user" | "channel" | "unknown"

user, channel, or unknown for a kind this client can't open (show the address only).

address

address: string

The canonical address.

name

name: string

The display name after the receiver check (01 §6.4), or the local part (01 §6.5).

bot

bot: boolean

Whether the account is a bot (users only).

ctx?

ctx?: string

The channel's ctx (channels only).

channelKind?

channelKind?: "text" | "voice"

text or voice; unknown values read as text (channels only).

security?

security?: "insecure" | "secure"

insecure or secure; unknown values read as secure for what is shown before joining (channels only). Never create or change a secure-state pin from this value when the wire value was unknown (securityKnown).

securityKnown?

securityKnown?: boolean

Whether security was a known wire value.

Source: address/info.ts:13

CanonicalCheckOptions interface

Options for checkCanonical (01 §7.5).

interface CanonicalCheckOptions

canonicalDomain?

canonicalDomain?: string

The canonical domain of the address's server (from 02), for check 6. When absent, only the syntactic checks 1 to 5 run.

expectedDomain?

expectedDomain?: string

A domain the address must be at, for example the iss of an IdentityState (01 §7.5 check 6).

checkALabels?

checkALabels?: boolean

Also check that xn-- labels decode to valid U-labels (the SHOULD of check 5). Default true.

Source: address/canonical.ts:20

CanonicalizeOptions interface

Options for canonicalize (01 §7.2).

interface CanonicalizeOptions

resolver

resolver: DomainResolver

Discovery (02). It MUST run 02's resolution with its domain and canonical-domain checks.

defaultDomain?

defaultDomain?: string

The canonical domain to use when the input has no domain (01 §7.2), for example the viewer's home server in a "New message" box.

lookup?

lookup?: AddressLookup

Address lookup for confirmation (01 §7.2 step 6). Default: an anonymous GET {base}/v1/addresses/{local} with fetch.

fetch?

fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>

fetch for the default lookup and for share-link fetches.

MDN Reference

signal?

signal?: AbortSignal

Cancels discovery, lookups and fetches.

servers?

servers?: readonly ResolvedServer[]

Servers whose metadata the client has cached, for share-link template matching (01 §11.4 step 2).

prepareLocal?

prepareLocal?: (s: string) => PrepareResult

Override prepareLocal (for tests that simulate other Unicode data, 01 §13.6 C13).

Source: address/canonicalize.ts:33

CanonicalizeResult interface

The result of canonicalize (01 §7.2 step 7).

interface CanonicalizeResult

kind

kind: "community" | "address"

address for an address target, community for a community target.

address?

address?: string

L "@" C; absent for a community target.

local?

local?: string

L; absent for a community target.

domain

domain: string

C, the canonical domain.

baseUrl

baseUrl: string

The server's base URL.

viaAlias

viaAlias: boolean

true if the typed domain differs from C. For diagnostics only; MUST NOT be shown (01 §7.8).

evidence?

evidence?: string

The delegation evidence of discovery (02 §9).

invite?

invite?: string

The invite code from a link, if any (01 §10), unchanged.

Source: address/canonicalize.ts:59

DisplayFormOptions interface

Options for displayForm (01 §6.6).

interface DisplayFormOptions

unicodeDomain?

unicodeDomain?: boolean

Show the domain as a U-label where 01 §4.3 allows it (default true).

Source: address/display.ts:123

DomainResolver interface

Resolves a domain through 02 (resolve() or webResolve(), 02 §5), with 02's cache and checks; used by 01 §7.2 steps 4 and 5 and §11.4 steps 1 and 2.

interface DomainResolver

resolve

resolve(domain: string, options?: { signal?: AbortSignal }): Promise<ResolvedServer>

Resolve a domain to its server; rejects with the discovery.* error of 02 on failure.

domain: string
options?: { signal?: AbortSignal }

Source: address/resolve.ts:30

FetchShareLinkOptions interface

Options for fetchShareLinkTarget (01 §11.4 step 3).

interface FetchShareLinkOptions

fetch?

fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>

fetch implementation. Default: globalThis.fetch.

MDN Reference

signal?

signal?: AbortSignal

Cancels the fetch.

timers?

timers?: { setTimeout(fn: () => void, ms: number): unknown; clearTimeout(handle: unknown): void }

Timer functions for the 5 s limit (01 §11.4 step 3), injectable for tests. Default: the global timers.

Source: address/share-link.ts:475

FormatUriOptions interface

Options for formatSloppyvUri (01 §10.3, §10.6).

interface FormatUriOptions

invite?

invite?: string

The invite code in 09's canonical form.

form?

form?: "uri" | "iri"

'uri' (default): the ASCII URI form for hrefs, QR codes and headers. 'iri': the IRI form for text people read or copy, with the local part in Unicode and the domain as a U-label where 01 §4.3 allows (01 §10.6).

Source: address/uri.ts:154

OwnDomains interface

A server's own domains, as its ServerMetadata lists them (02 §7, 01 §7.7).

interface OwnDomains

canonicalDomain

canonicalDomain: string

The server's canonicalDomain.

domains

domains: readonly string[]

The server's domains (the canonical domain and every alias).

Source: address/canonical.ts:102

ResolvedServer interface

The part of a discovery result (02 §5.1, DiscoveryResult) that the address module needs.

interface ResolvedServer

baseUrl

baseUrl: string

The server's base URL (02 §3.3).

canonicalDomain

canonicalDomain: string

The server's canonicalDomain, verified per 02 §5.3.

evidence?

evidence?: string

Delegation evidence (02 §9).

metadata?

metadata?: { links?: { join?: string | null } | null; domains?: readonly string[] | null } | null

The server's ServerMetadata, at least its links and domains members (02 §7).

Source: address/resolve.ts:18

ResolveShareLinkOptions interface

Options for resolveShareLink (01 §11.4).

interface ResolveShareLinkOptions

resolver

resolver: DomainResolver

Resolves hosts and domains through 02.

servers?

servers?: readonly ResolvedServer[]

Servers whose metadata the client has cached; their templates are tried first (01 §11.4 step 2).

allowFetch?

allowFetch?: boolean

Fetch the URL when no template matches (01 §11.4 step 3). Only when the person explicitly pasted or opened this URL. Default false.

fetch?

fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>

fetch for step 3.

MDN Reference

signal?

signal?: AbortSignal

Cancels resolution and fetches.

Source: address/share-link.ts:597

ShareLinkMatch interface

A template match: the raw (decoded) values of the variables it bound (01 §11.4 step 2).

interface ShareLinkMatch

local?

local?: string

Display-local form from the URL, or undefined for a community.

domain?

domain?: string

Domain from the URL, when the template has {domain}; it must canonicalize to the template's server.

invite?

invite?: string

Invite code, decoded but otherwise unchanged.

Source: address/share-link.ts:298

TemplateExpression interface

One expression of a URI Template (RFC 6570 §2.2).

interface TemplateExpression

operator

operator: "" | "+" | "#" | "." | "/" | ";" | "?" | "&"

The operator: '', +, #, ., /, ;, ? or & (level 3 and below).

variables

variables: string[]

Variable names, in order.

Source: address/share-link.ts:36

WebLink interface

One link of an RFC 8288 Link header.

interface WebLink

href

href: string

The target URI, as written between < and >.

rel

rel: string[]

The relation types, lowercased.

Source: address/share-link.ts:402

Types

AddressLookup type

Looks up a local part at a base URL (01 §9), anonymously. Used for the confirmation of 01 §7.2 step 6.

type AddressLookup = (baseUrl: string, local: string, options: { signal?: AbortSignal }) => Promise<AddressInfo>

Source: address/canonicalize.ts:30

CanonicalCheck type

The result of a canonical-address check: ok, or the address.non_canonical reason (01 §7.5).

type CanonicalCheck = { ok: true; local: string; domain: string } | { ok: false; reason: NonCanonicalReason }

Source: address/canonical.ts:17

DisplayNameCheck type

The result of the receiver check (01 §6.4).

type DisplayNameCheck = { ok: true; shown: string } | { ok: false }

Source: address/display.ts:17

DisplayNameResult type

The result of prepareDisplayName (01 §6.3).

type DisplayNameResult = { ok: true; value: string } | { ok: false; reason: DisplayNameMismatchReason }

Source: address/display.ts:177

DomainResult type

The result of prepareDomain: the typed domain as lowercase A-labels, or a 01 §4.2 failure reason.

type DomainResult = { ok: true; value: string } | { ok: false; reason: DomainFailureReason }

Source: address/domain.ts:21

JoinTemplateCheck type

The result of validateJoinTemplate (01 §11.2).

type JoinTemplateCheck = { ok: true; parts: TemplatePart[]; host: string; hostname: string } | { ok: false; problem: string }

Source: address/share-link.ts:144

LinkTarget type

A link or input target before preparation: an address (raw local part and raw domain) or a community (raw domain only), with an optional invite code (01 §7.2 step 1, §10.4 step 10).

type LinkTarget = { kind: "address"; local: string; domain: string | null; invite?: string } | { kind: "community"; domain: string; invite?: string }

Source: address/uri.ts:23

ParsedInput type

The result of parseInput (01 §8.2, §7.2 step 1): an address or community target (from text or a sloppyv URI), or an HTTPS link that may be a share link and must be resolved first (01 §11.4).

type ParsedInput = LinkTarget & { source: "text" | "uri" } | { kind: "link"; url: string; source: "link" }

Source: address/parse.ts:21

PrecisPropertyValue type

The PRECIS derived property value of a code point in the IdentifierClass (RFC 8264 §8, §9).

type PrecisPropertyValue = "PVALID" | "CONTEXTJ" | "CONTEXTO" | "DISALLOWED" | "UNASSIGNED"

Source: address/precis.ts:55

PrepareFailure type

A failure of a profile function, with a 01 §3.9 reason.

type PrepareFailure = Extract<PrepareResult, { ok: false }>

Source: address/precis.ts:44

PrepareResult type

The result of a profile function: the prepared string, or a failure with a 01 §3.9 reason.

type PrepareResult = { ok: true; value: string } | { ok: false; reason: LocalPartFailureReason; index?: number }

Source: address/precis.ts:34

ShareTarget type

A target to generate a link for (01 §10.3, §11.2).

type ShareTarget = { address: string; name?: string | null } | { domain: string }

Source: address/uri.ts:141

TemplatePart type

A parsed URI Template: literal strings and expressions in order (RFC 6570 §2).

type TemplatePart = { literal: string } | { expression: TemplateExpression }

Source: address/share-link.ts:44

Constants

FULL_STOPS const

The full stops of 01 §4.1 step 2: U+002E, U+3002, U+FF0E and U+FF61.

const FULL_STOPS: readonly string[]

Source: address/domain.ts:24

PROFILE_UNICODE_VERSION const

The Unicode version of the profile data this SDK uses (01 §1.4: 16.0.0).

const PROFILE_UNICODE_VERSION: string = UNICODE_DATA_VERSION

Source: address/unicode.ts:73