@ghostlytools/sdk 1.10.3 → 1.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +2 -2
- package/dist/{fakes-Dbw01Dk9.js → fakes-BNNNkQqY.js} +2 -2
- package/dist/{fakes-Dbw01Dk9.js.map → fakes-BNNNkQqY.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/{keet-identity-key-BT3p-YEj.js → keet-identity-key-DJbA1oSW.js} +2 -2
- package/dist/{keet-identity-key-BT3p-YEj.js.map → keet-identity-key-DJbA1oSW.js.map} +1 -1
- package/dist/{src-CCGK1Q_h.js → src-C2bAufMs.js} +738 -155
- package/dist/src-C2bAufMs.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/browser/src/proofs/contract.d.ts +4 -1
- package/dist/types/core/src/capsRecord.d.ts +19 -6
- package/dist/types/core/src/dhtDelivery.d.ts +47 -0
- package/dist/types/core/src/frames.d.ts +6 -0
- package/dist/types/core/src/ghostlink.d.ts +5 -0
- package/dist/types/core/src/groupCommunity.d.ts +23 -2
- package/dist/types/core/src/groupSession.d.ts +20 -1
- package/dist/types/core/src/http.d.ts +1 -0
- package/dist/types/core/src/identityProofs.d.ts +15 -0
- package/dist/types/core/src/identityTimeline.d.ts +8 -2
- package/dist/types/core/src/link.d.ts +8 -0
- package/dist/types/core/src/relay.d.ts +46 -7
- package/dist/types/core/src/transport.d.ts +29 -0
- package/dist/types/core/src/transportSwitch.d.ts +2 -0
- package/dist/{verify-DXMSqZzR.js → verify-CpIce6Bt.js} +3 -2
- package/dist/verify-CpIce6Bt.js.map +1 -0
- package/package.json +1 -1
- package/dist/src-CCGK1Q_h.js.map +0 -1
- package/dist/verify-DXMSqZzR.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../browser/src/proofs/contract.ts","../../browser/src/plugins/bundled.ts","../../browser/src/plugins/registry.ts"],"sourcesContent":["import type { IdentityDisplay, IdentityStatement, VerifiedIdentity } from \"@ghostly/core\";\n\n/**\n * The identity-proof provider contract. A provider is one way to prove control of an external\n * identity (a Nostr key, a domain, a Bitcoin address, an SSH or PGP key, an OpenID Connect account):\n * how the person produces evidence over the shared statement (`signers`), and how any Ghostly app\n * checks it (`verify`). Everything else — the statement bytes, the proof key, sharing per contact,\n * replay protection, storage, expiry, the UI — is shared. See PROOFS.md.\n */\n\n/**\n * Who vouches for the identity. The UI shows the difference:\n * - self-custodied: the person holds the key (Nostr, SSH, PGP, Bitcoin, a domain they control);\n * only they can have produced the evidence.\n * - provider-attested: a company signs that the person logged in to an account (OpenID Connect);\n * the evidence is only as trustworthy as that company.\n */\nexport type IdentityCategory = \"self-custodied\" | \"provider-attested\";\n/** Where Ghostly runs: the web app, the browser extension (engine in an offscreen document), the Tauri app. */\nexport type IdentityPlatform = \"web\" | \"extension\" | \"desktop\";\nexport const IDENTITY_PLATFORMS: readonly IdentityPlatform[] = [\"web\", \"extension\", \"desktop\"];\n\n/**\n * A bounded HTTPS GET through the engine: time-out, size cap (`maxBytes`, default 64 KiB), no credentials,\n * no referrer, refused offline. `redirect` defaults to \"error\": a record that redirects does not count\n * unless the provider says so. `text` is the body as UTF-8; `bytes` is the same body raw (binary\n * answers such as DNS-over-HTTPS `application/dns-message`).\n */\nexport interface IdentityFetchOptions { headers?: Record<string, string>; maxBytes?: number; signal?: AbortSignal; redirect?: \"follow\" | \"error\" }\nexport interface IdentityFetchResponse { status: number; contentType: string; text: string; bytes: Uint8Array }\nexport type IdentityFetch = (url: string, options?: IdentityFetchOptions) => Promise<IdentityFetchResponse>;\n\n/**\n * How a provider says a line it works out when it runs (a step naming the person's domain, a progress line) in the\n * app's language: `key` names the line within the provider, `english` is the line itself with `{{name}}` for each of\n * `values`. The UI reads a built-in provider's line under `identities.providers.<provider id>.<key>`, with `english`\n * when its language has none; a provider written outside the app (a plugin) always gets its `english` back, filled in.\n * Its fixed words (`label`, `summary`, a signer's `description`…) need no call: the UI reads them by the same rule,\n * under their own path (`subject.help`, `signers.<signer id>.label`, `signers.<signer id>.fields.<name>.help`).\n */\nexport type ProviderSay = (key: string, english: string, values?: Readonly<Record<string, string | number>>) => string;\n\n/** `english` with its `{{name}}`s filled in: what `ProviderSay` returns where no app language is at hand (the CLI, tests). */\nexport const englishSay: ProviderSay = (_key, english, values) =>\n values ? english.replace(/\\{\\{(\\w+)\\}\\}/g, (all, name: string) => (name in values ? String(values[name]) : all)) : english;\n\nexport interface VerifyContext {\n /** Seconds. Use this, never `Date.now()`, so tests and re-checks agree on time. */\n now: number;\n signal: AbortSignal;\n /** The only way `verify` may reach the network. Never call the global `fetch`. */\n fetch: IdentityFetch;\n}\n\nexport interface SubjectSpec {\n /** \"Public key\", \"Domain\", \"Bitcoin address\", \"Account\". */\n label: string;\n placeholder?: string;\n help?: string;\n /** Choices instead of a text field (an OpenID Connect provider's issuer). */\n options?: readonly { value: string; label: string }[];\n /** The canonical subject for what the person typed (or a signer returned). Throw a message they can act on. */\n normalize(input: string): string;\n /** Short form for badges and lists (\"npub1x…4f2\"). Defaults to the subject. */\n short?(subject: string): string;\n /**\n * What the (normalized) subject turns out to be, shown under the field before anything is signed: a DID's\n * method, its keys and its domain. Runs in the UI on the person's input; may reach the network (the\n * person's own identity). Throw a message they can act on.\n */\n preview?(subject: string, options: { signal: AbortSignal; say?: ProviderSay }): Promise<SubjectPreview>;\n}\n\nexport interface SubjectPreview {\n /** Short facts, in order: \"Method\" → \"did:web\", \"Keys\" → \"#key-1 (Ed25519)\". */\n facts: readonly { label: string; value: string }[];\n /** The ids of the signers that apply to this subject; every signer when omitted. */\n signers?: readonly string[];\n}\n\n/** A field an in-app signer needs (a NIP-46 connection link). `secret` values are never stored or logged. */\nexport interface SignerField {\n name: string;\n label: string;\n kind: \"text\" | \"secret\";\n placeholder?: string;\n help?: string;\n optional?: boolean;\n}\n\n/**\n * A request waiting for the person's approval elsewhere, in one of two ways (Pubky: Passport in a browser window, or\n * Ring by scanning a QR code). The UI shows both on one screen; whichever approves first wins. Its values are secrets\n * (the QR carries a relay key): never logged, never stored.\n */\nexport interface ApprovalRequest {\n /** The primary button. `run` is called synchronously from its click, so a popup it opens keeps the user activation. */\n open?: { label: string; description?: string; run(): void };\n /** A QR code for a phone app, with its caption. */\n qr?: { value: string; label: string };\n /** Short lines under the choices. */\n notes?: readonly string[];\n}\n\nexport interface SignerContext {\n values: Record<string, string>;\n signal: AbortSignal;\n /** The signer asks the person to approve on a page (NIP-46 auth_url): the UI shows it as a link, never opens it itself. */\n onAuthUrl(url: string): void;\n onProgress(message: string): void;\n /** The signer waits for an approval elsewhere (`null`: it no longer does). The UI renders it; see `ApprovalRequest`. */\n onApproval?(request: ApprovalRequest | null): void;\n /** Says the signer's progress lines and approval words in the app's language; `englishSay` when absent. */\n say?: ProviderSay;\n}\n\nexport interface SignerSession<E> {\n /** The identity the signer controls, canonical (as `subject.normalize` returns it). */\n subject(): Promise<string>;\n sign(statement: IdentityStatement): Promise<E>;\n}\n\nexport interface InstructionStep {\n text: string;\n /** Shown in a copyable block (a command, a DNS record). */\n copy?: string;\n}\nexport interface SignerInstructions {\n steps: readonly InstructionStep[];\n /** external-tool: the field the output is pasted into. */\n paste?: { label: string; placeholder?: string; multiline?: boolean };\n}\n\ninterface SignerBase {\n /** Unique within the provider: \"nip07\", \"nip46\", \"ssh-keygen\". */\n id: string;\n label: string;\n description?: string;\n /** Defaults to the provider's. */\n platforms?: readonly IdentityPlatform[];\n /** False hides it (no NIP-07 extension in this window). Runs in the UI. */\n available?(): boolean;\n /** The button that starts it (\"Continue on your server\"). Default: \"Sign with <label>\" in-app, \"Continue\" otherwise. */\n action?: string;\n}\n\n/** Signs inside Ghostly through something the person already uses (NIP-07, NIP-46, a wallet API). */\nexport interface InAppSigner<E> extends SignerBase {\n kind: \"in-app\";\n fields?: readonly SignerField[];\n /** Opens the signer, runs `work`, and always cleans up (closes connections, drops keys) before resolving. */\n run<T>(ctx: SignerContext, work: (session: SignerSession<E>) => Promise<T>): Promise<T>;\n}\n\n/** The person runs a tool (ssh-keygen, gpg, a Bitcoin wallet) on the statement and pastes the output back. */\nexport interface ExternalToolSigner<E> extends SignerBase {\n kind: \"external-tool\";\n /** `say`: the steps in the app's language (`englishSay` when absent). */\n instructions(statement: IdentityStatement, say?: ProviderSay): SignerInstructions;\n /** What was pasted, as evidence. Throw a message the person can act on (\"That is not an SSH signature\"). */\n parse(pasted: string, statement: IdentityStatement): E | Promise<E>;\n}\n\n/** A popup to the provider's login page (OpenID Connect); the subject comes out of `verify`. */\nexport interface RedirectSigner<E> extends SignerBase {\n kind: \"redirect\";\n start(statement: IdentityStatement, ctx: SignerContext): Promise<E>;\n}\n\n/** The person publishes something the verifier fetches (a DNS TXT record, a /.well-known file). */\nexport interface PublishSigner<E> extends SignerBase {\n kind: \"publish\";\n /** `say`: the steps in the app's language (`englishSay` when absent). */\n instructions(statement: IdentityStatement, say?: ProviderSay): SignerInstructions;\n /** Usually small or empty: the verifier looks the record up itself. */\n evidence(statement: IdentityStatement): E | Promise<E>;\n}\n\nexport type IdentitySigner<E> = InAppSigner<E> | ExternalToolSigner<E> | RedirectSigner<E> | PublishSigner<E>;\n\n/**\n * A provider module's export. Registering it is adding the module under `proofs/providers/` and ONE\n * line in `proofs/registry.ts`.\n */\nexport interface IdentityProofProvider<E = unknown> {\n /** Stable: it is in the statement, on the wire and in storage. `^[a-z][a-z0-9-]{0,31}$`. */\n id: string;\n label: string;\n category: IdentityCategory;\n /**\n * One short line for the picker card, how you make it: \"Sign once with your Nostr signer\". About 40\n * characters at most; the card shows nothing else beside the name and the category.\n */\n summary: string;\n /** The details view (opened from the card, shown again above the form): what is proven and how, a sentence or two. */\n description: string;\n /**\n * What the proof does NOT show, when a contact could easily assume more (\"Does not prove a balance, a past\n * payment, or that you would pay.\"). Shown with the description, never hidden behind a hover.\n */\n limits?: string;\n platforms: readonly IdentityPlatform[];\n subject: SubjectSpec;\n /** How long one proof may last. The person picks up to `maxDays` (never above 400). */\n validity: { defaultDays: number; maxDays: number };\n /**\n * When a verifier's check can go stale (the DNS record may be removed later): the contact's app offers\n * \"Check again\" after this many seconds and shows the last check time. Omit when the evidence is a\n * signature that stays valid until expiry.\n */\n recheck?: { afterSeconds: number };\n /** One sentence for people: what `verify` contacts and who learns what. \"Nothing: checked on this device.\" */\n privacy: string;\n /** Mark providers whose flows are not proven against real-world tools yet. */\n experimental?: boolean;\n /** Listed under \"Advanced\" in the picker, for people who know what it is (DIDs), so it does not crowd newcomers. */\n advanced?: boolean;\n signers: readonly IdentitySigner<E>[];\n /**\n * Untrusted evidence off the wire → typed evidence. Strict: exact shape, bounded sizes, no extra keys.\n * The serialized evidence is already capped at 16 KiB before this runs.\n */\n parseEvidence(raw: unknown): E;\n /**\n * Checks `evidence` against exactly `statement.bytes` / `statement.text` and returns what it proves.\n * Throws when it does not. Must:\n * - self-custodied: return `subject === statement.binding.subject`;\n * - provider-attested: return the attested subject and set `attester`;\n * - reach the network only through `ctx.fetch`, and use `ctx.now` for time.\n */\n verify(statement: IdentityStatement, evidence: E, ctx: VerifyContext): Promise<VerifiedIdentity>;\n /**\n * Optional public name/picture for a verified subject (Nostr kind-0). Called ONLY when the person asks,\n * never automatically. Sanitize like avatars: plain-text name, bounded raster re-encoded to a data URL.\n */\n lookupDisplay?(subject: string, options: { signal: AbortSignal }): Promise<IdentityDisplay | undefined>;\n /** The button that runs `lookupDisplay`. Default: \"Show public profile\". */\n lookupLabel?: string;\n /**\n * The verified subject as a URI a public DID document may list in `alsoKnownAs` (the profile's\n * did:dht, and only for identities the person chooses to list there). Omit when the identity has no\n * URI of its own. No comma: did:dht separates the list with commas.\n */\n publicUri?(subject: string): string | undefined;\n /**\n * Takes down what a signer published when the person removes the proof (an AT Protocol record, a Pubky proof file). Runs in\n * the UI, called synchronously from the confirming click (it may open a window first). The shared Pkarr\n * revocation is published either way; if this fails, the person may remove the proof without it.\n */\n unpublish?: {\n /** What the removal adds, for the confirmation: \"Also deletes the record on your server.\" */\n description: string;\n /** `evidence` is what `parseEvidence` accepted when the proof was made (Pubky: the proof file's folder). */\n run(proof: { id: string; subject: string; key: string; evidence: E }, ctx: SignerContext): Promise<void>;\n };\n}\n","import type { GhostlyAdapterPlugin } from \"./registry\";\n\n/**\n * The adapter plugins compiled into this build. Empty unless the build lists some: `GHOSTLY_PLUGINS`\n * names their modules (comma-separated paths from the repository root, each default-exporting a\n * `GhostlyAdapterPlugin`), and the Vite plugin in `packages/browser/vite-plugin.ts` swaps this module\n * for one that imports them. Release builds never set it; the e2e build carries the SDK example.\n */\nexport const BUNDLED_PLUGINS: readonly GhostlyAdapterPlugin[] = [];\n","import type { LightningProviderDescriptor } from \"../engine/paymentAdapters/providers/lightning\";\nimport type { OnchainProviderDescriptor } from \"../engine/paymentAdapters/providers/onchain\";\nimport { providerDescriptorProblems, type ProviderDescriptor, type ProviderKind } from \"../engine/paymentAdapters/providers/types\";\nimport type { IdentityProofProvider } from \"../proofs/contract\";\nimport { descriptorProblems } from \"../proofs/verify\";\nimport { BUNDLED_PLUGINS } from \"./bundled\";\n\n/**\n * Adapters written outside the app: wallet sources (Lightning, on-chain) and identity-proof providers\n * that register here instead of being added to the built-in lists. A plugin is a plain object naming\n * its adapters; the registries (`providers/registry.ts`, `proofs/registry.ts`) list what is registered\n * after the built-ins and before the test fakes, and the same platform and mode rules apply to all.\n *\n * Two ways in:\n * - at build time: `GHOSTLY_PLUGINS` lists the modules and `bundled.ts` is swapped for them;\n * - at run time: code already running in the engine's realm calls `registerAdapters` before the\n * pickers are shown (or after: the engine re-reads the lists when something registers).\n *\n * Trust: a plugin runs with the app's privileges, in the app's own JavaScript realm. There is no\n * sandbox, no permission prompt and no store; whoever builds a plugin in, or loads one, trusts its\n * author with everything the app can do, keys and sats included. A manifest with permissions and an\n * isolated runtime are a later phase (docs/wisps/ADAPTER-ROADMAP.md, \"Plugins, apps, catalogs\").\n *\n * The state lives on `globalThis` under a well-known symbol, so a plugin bundled with its own copy of\n * the SDK (a second copy of this module) still registers into the same lists the app reads.\n */\n\n/** The generation of the adapter contracts. A plugin says which one it was written against. */\nexport const SDK_API = 1;\nexport const PLUGIN_ID = /^[a-z][a-z0-9-]{0,63}$/;\n\nexport interface GhostlyAdapterPlugin {\n /** Stable, unique among plugins: `^[a-z][a-z0-9-]{0,63}$`. */\n id: string;\n /** The plugin's own version, for people. */\n version?: string;\n /** The contract generation it was written against: `SDK_API`. Another one is refused. */\n sdk: number;\n lightning?: readonly LightningProviderDescriptor[];\n onchain?: readonly OnchainProviderDescriptor[];\n identities?: readonly IdentityProofProvider[];\n}\n\nexport type AdapterKind = ProviderKind | \"identity\";\n\ninterface Store {\n plugins: Map<string, GhostlyAdapterPlugin>;\n /** Ids the built-in registries own, per kind: a plugin cannot take one. */\n reserved: Record<AdapterKind, Set<string>>;\n listeners: Set<() => void>;\n seeded: boolean;\n}\n\nconst KEY = Symbol.for(\"ghostly.adapters/1\");\nfunction store(): Store {\n const g = globalThis as unknown as Record<symbol, Store | undefined>;\n return (g[KEY] ??= { plugins: new Map(), reserved: { lightning: new Set(), onchain: new Set(), identity: new Set() }, listeners: new Set(), seeded: false });\n}\n\nconst ids = (kind: AdapterKind, plugin: GhostlyAdapterPlugin): string[] => {\n // Not trusted to be well formed: pluginProblems reads it before saying what is wrong with it.\n const list: unknown = kind === \"identity\" ? plugin.identities : kind === \"lightning\" ? plugin.lightning : plugin.onchain;\n return Array.isArray(list) ? list.map((a: { id?: string } | null) => a?.id as string) : [];\n};\nconst KINDS: readonly AdapterKind[] = [\"lightning\", \"onchain\", \"identity\"];\n\n/** Problems with a plugin, empty when it can be registered. Does not look at what is already registered. */\nexport function pluginProblems(plugin: GhostlyAdapterPlugin): string[] {\n const problems: string[] = [];\n if (!plugin || typeof plugin !== \"object\") return [\"not a plugin object\"];\n if (!PLUGIN_ID.test(plugin.id ?? \"\")) problems.push(\"plugin id must match ^[a-z][a-z0-9-]{0,63}$\");\n if (plugin.sdk !== SDK_API) problems.push(`plugin was written for SDK API ${String(plugin.sdk)}; this app speaks ${SDK_API}`);\n if (plugin.version !== undefined && (typeof plugin.version !== \"string\" || plugin.version.length > 64)) problems.push(\"version must be a short string\");\n for (const kind of [\"lightning\", \"onchain\"] as const) {\n const list = plugin[kind];\n if (list === undefined) continue;\n if (!Array.isArray(list)) { problems.push(`${kind} must be a list of descriptors`); continue; }\n for (const d of list as ProviderDescriptor<unknown>[]) {\n if (!d || typeof d !== \"object\") { problems.push(`${kind} ${String(d)}: not a descriptor`); continue; }\n const own = providerDescriptorProblems(d);\n if (d?.kind && d.kind !== kind) own.push(`is listed under ${kind} but says kind ${String(d.kind)}`);\n problems.push(...own.map((p) => `${kind} ${String(d?.id)}: ${p}`));\n }\n }\n if (plugin.identities !== undefined) {\n if (!Array.isArray(plugin.identities)) problems.push(\"identities must be a list of providers\");\n else for (const p of plugin.identities) {\n if (!p || typeof p !== \"object\") problems.push(`identity ${String(p)}: not a provider`);\n else problems.push(...descriptorProblems(p).map((m) => `identity ${String(p.id)}: ${m}`));\n }\n }\n for (const kind of KINDS) {\n const list = ids(kind, plugin);\n if (new Set(list).size !== list.length) problems.push(`${kind} ids are not unique within the plugin`);\n }\n if (!KINDS.some((kind) => ids(kind, plugin).length)) problems.push(\"the plugin brings no adapter\");\n return problems;\n}\n\n/** The built-in registries say which ids are theirs. A plugin using one is refused. */\nexport function reserveAdapterIds(kind: AdapterKind, list: readonly string[]): void {\n const s = store();\n for (const id of list) s.reserved[kind].add(id);\n}\n\n/**\n * Registers a plugin's adapters. Throws, registering nothing, when the plugin is malformed, its id or\n * one of its adapters' ids is taken (by a built-in or by another plugin), or its contract generation\n * is another one. Returns the function that unregisters it.\n */\nexport function registerAdapters(plugin: GhostlyAdapterPlugin): () => void {\n const problems = pluginProblems(plugin);\n const s = store();\n if (!problems.length) {\n if (s.plugins.has(plugin.id)) problems.push(`a plugin with id ${plugin.id} is already registered`);\n for (const kind of KINDS) for (const id of ids(kind, plugin)) {\n if (s.reserved[kind].has(id)) problems.push(`${kind} ${id} is a built-in of this app`);\n for (const other of s.plugins.values()) if (ids(kind, other).includes(id)) problems.push(`${kind} ${id} is already registered by plugin ${other.id}`);\n }\n }\n if (problems.length) throw new Error(`Cannot register plugin ${String(plugin?.id)}: ${problems.join(\"; \")}`);\n s.plugins.set(plugin.id, plugin);\n notify(s);\n return () => { if (s.plugins.get(plugin.id) === plugin) { s.plugins.delete(plugin.id); notify(s); } };\n}\n\nfunction notify(s: Store) { for (const listener of s.listeners) { try { listener(); } catch { /* a listener's problem */ } } }\n\n/** Called when a plugin registers or unregisters: the engine re-reads the lists. */\nexport function onAdaptersChanged(listener: () => void): () => void {\n const s = store();\n s.listeners.add(listener);\n return () => { s.listeners.delete(listener); };\n}\n\n/** Every registered plugin, in registration order (bundled ones first). */\nexport function registeredPlugins(): readonly GhostlyAdapterPlugin[] { seed(); return [...store().plugins.values()]; }\nexport function registeredLightningProviders(): readonly LightningProviderDescriptor[] { return registeredPlugins().flatMap((p) => p.lightning ?? []); }\nexport function registeredOnchainProviders(): readonly OnchainProviderDescriptor[] { return registeredPlugins().flatMap((p) => p.onchain ?? []); }\nexport function registeredIdentityProviders(): readonly IdentityProofProvider[] { return registeredPlugins().flatMap((p) => p.identities ?? []); }\n\n/**\n * The plugins compiled into this build register once, when they are first asked for. A broken one is\n * reported and skipped rather than taking the app down with it; the e2e that expects it fails instead.\n */\nfunction seed() {\n const s = store();\n if (s.seeded) return;\n s.seeded = true;\n for (const plugin of BUNDLED_PLUGINS) {\n try { registerAdapters(plugin); }\n catch (error) { console.error(`[ghostly] a bundled adapter plugin was not loaded: ${error instanceof Error ? error.message : String(error)}`); }\n }\n}\n\n/** Tests only: forget every registration, including the bundled ones. */\nexport function resetAdapterRegistry(): void {\n const s = store();\n s.plugins.clear(); s.seeded = false;\n for (const kind of KINDS) s.reserved[kind].clear();\n notify(s);\n}\n"],"mappings":";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;CAAE,OAAO,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,cAAc,CAAC,CAAC;AAAG;;;;;AAMjJ,SAAS,OAAO;CACd,MAAM,IAAI,MAAM;CAChB,IAAI,EAAE,QAAQ;CACd,EAAE,SAAS;CACX,KAAK,MAAM,UAAU,iBACnB,IAAI;EAAE,iBAAiB,MAAM;CAAG,SACzB,OAAO;EAAE,QAAQ,MAAM,sDAAsD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CAAG;AAEnJ;;AAGA,SAAgB,uBAA6B;CAC3C,MAAM,IAAI,MAAM;CAChB,EAAE,QAAQ,MAAM;CAAG,EAAE,SAAS;CAC9B,KAAK,MAAM,QAAQ,OAAO,EAAE,SAAS,KAAK,CAAC,MAAM;CACjD,OAAO,CAAC;AACV"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../browser/src/proofs/contract.ts","../../browser/src/plugins/bundled.ts","../../browser/src/plugins/registry.ts"],"sourcesContent":["import type { IdentityDisplay, IdentityStatement, VerifiedIdentity } from \"@ghostly/core\";\n\n/**\n * The identity-proof provider contract. A provider is one way to prove control of an external\n * identity (a Nostr key, a domain, a Bitcoin address, an SSH or PGP key, an OpenID Connect account):\n * how the person produces evidence over the shared statement (`signers`), and how any Ghostly app\n * checks it (`verify`). Everything else — the statement bytes, the proof key, sharing per contact,\n * replay protection, storage, expiry, the UI — is shared. See PROOFS.md.\n */\n\n/**\n * Who vouches for the identity. The UI shows the difference:\n * - self-custodied: the person holds the key (Nostr, SSH, PGP, Bitcoin, a domain they control);\n * only they can have produced the evidence.\n * - provider-attested: a company signs that the person logged in to an account (OpenID Connect);\n * the evidence is only as trustworthy as that company.\n */\nexport type IdentityCategory = \"self-custodied\" | \"provider-attested\";\n/** Where Ghostly runs: the web app, the browser extension (engine in an offscreen document), the Tauri app. */\nexport type IdentityPlatform = \"web\" | \"extension\" | \"desktop\";\nexport const IDENTITY_PLATFORMS: readonly IdentityPlatform[] = [\"web\", \"extension\", \"desktop\"];\n\n/**\n * A bounded HTTPS GET through the engine: time-out, size cap (`maxBytes`, default 64 KiB), no credentials,\n * no referrer, refused offline. `redirect` defaults to \"error\": a record that redirects does not count\n * unless the provider says so. `text` is the body as UTF-8; `bytes` is the same body raw (binary\n * answers such as DNS-over-HTTPS `application/dns-message`).\n */\nexport interface IdentityFetchOptions { headers?: Record<string, string>; maxBytes?: number; signal?: AbortSignal; redirect?: \"follow\" | \"error\" }\nexport interface IdentityFetchResponse { status: number; contentType: string; text: string; bytes: Uint8Array }\nexport type IdentityFetch = (url: string, options?: IdentityFetchOptions) => Promise<IdentityFetchResponse>;\n\n/**\n * How a provider says a line it works out when it runs (a step naming the person's domain, a progress line) in the\n * app's language: `key` names the line within the provider, `english` is the line itself with `{{name}}` for each of\n * `values`. The UI reads a built-in provider's line under `identities.providers.<provider id>.<key>`, with `english`\n * when its language has none; a provider written outside the app (a plugin) always gets its `english` back, filled in.\n * Its fixed words (`label`, `summary`, a signer's `description`…) need no call: the UI reads them by the same rule,\n * under their own path (`subject.help`, `signers.<signer id>.label`, `signers.<signer id>.fields.<name>.help`).\n */\nexport type ProviderSay = (key: string, english: string, values?: Readonly<Record<string, string | number>>) => string;\n\n/** `english` with its `{{name}}`s filled in: what `ProviderSay` returns where no app language is at hand (the CLI, tests). */\nexport const englishSay: ProviderSay = (_key, english, values) =>\n values ? english.replace(/\\{\\{(\\w+)\\}\\}/g, (all, name: string) => (name in values ? String(values[name]) : all)) : english;\n\nexport interface VerifyContext {\n /** Seconds. Use this, never `Date.now()`, so tests and re-checks agree on time. */\n now: number;\n signal: AbortSignal;\n /** The only way `verify` may reach the network. Never call the global `fetch`. */\n fetch: IdentityFetch;\n}\n\nexport interface SubjectSpec {\n /** \"Public key\", \"Domain\", \"Bitcoin address\", \"Account\". */\n label: string;\n placeholder?: string;\n help?: string;\n /** Choices instead of a text field (an OpenID Connect provider's issuer). */\n options?: readonly { value: string; label: string }[];\n /** The canonical subject for what the person typed (or a signer returned). Throw a message they can act on. */\n normalize(input: string): string;\n /** Short form for badges and lists (\"npub1x…4f2\"). Defaults to the subject. */\n short?(subject: string): string;\n /**\n * What the (normalized) subject turns out to be, shown under the field before anything is signed: a DID's\n * method, its keys and its domain. Runs in the UI on the person's input; may reach the network (the\n * person's own identity). Throw a message they can act on.\n */\n preview?(subject: string, options: { signal: AbortSignal; say?: ProviderSay }): Promise<SubjectPreview>;\n}\n\nexport interface SubjectPreview {\n /** Short facts, in order: \"Method\" → \"did:web\", \"Keys\" → \"#key-1 (Ed25519)\". */\n facts: readonly { label: string; value: string }[];\n /** The ids of the signers that apply to this subject; every signer when omitted. */\n signers?: readonly string[];\n}\n\n/** A field an in-app signer needs (a NIP-46 connection link). `secret` values are never stored or logged. */\nexport interface SignerField {\n name: string;\n label: string;\n kind: \"text\" | \"secret\";\n placeholder?: string;\n help?: string;\n optional?: boolean;\n}\n\n/**\n * A request waiting for the person's approval elsewhere, in one of two ways (Pubky: Passport in a browser window, or\n * Ring by scanning a QR code). The UI shows both on one screen; whichever approves first wins. Its values are secrets\n * (the QR carries a relay key): never logged, never stored.\n */\nexport interface ApprovalRequest {\n /** The primary button. `run` is called synchronously from its click, so a popup it opens keeps the user activation. */\n open?: { label: string; description?: string; run(): void };\n /** A QR code for a phone app, with its caption. */\n qr?: { value: string; label: string };\n /** Short lines under the choices. */\n notes?: readonly string[];\n}\n\nexport interface SignerContext {\n values: Record<string, string>;\n signal: AbortSignal;\n /** The signer asks the person to approve on a page (NIP-46 auth_url): the UI shows it as a link, never opens it itself. */\n onAuthUrl(url: string): void;\n onProgress(message: string): void;\n /** The signer waits for an approval elsewhere (`null`: it no longer does). The UI renders it; see `ApprovalRequest`. */\n onApproval?(request: ApprovalRequest | null): void;\n /** Says the signer's progress lines and approval words in the app's language; `englishSay` when absent. */\n say?: ProviderSay;\n}\n\nexport interface SignerSession<E> {\n /** The identity the signer controls, canonical (as `subject.normalize` returns it). */\n subject(): Promise<string>;\n sign(statement: IdentityStatement): Promise<E>;\n}\n\nexport interface InstructionStep {\n text: string;\n /** Shown in a copyable block (a command, a DNS record). */\n copy?: string;\n}\nexport interface SignerInstructions {\n steps: readonly InstructionStep[];\n /** external-tool: the field the output is pasted into. */\n paste?: { label: string; placeholder?: string; multiline?: boolean };\n}\n\ninterface SignerBase {\n /** Unique within the provider: \"nip07\", \"nip46\", \"ssh-keygen\". */\n id: string;\n label: string;\n description?: string;\n /** Defaults to the provider's. */\n platforms?: readonly IdentityPlatform[];\n /** False hides it (no NIP-07 extension in this window). Runs in the UI. */\n available?(): boolean;\n /** The button that starts it (\"Continue on your server\"). Default: \"Sign with <label>\" in-app, \"Continue\" otherwise. */\n action?: string;\n}\n\n/** Signs inside Ghostly through something the person already uses (NIP-07, NIP-46, a wallet API). */\nexport interface InAppSigner<E> extends SignerBase {\n kind: \"in-app\";\n fields?: readonly SignerField[];\n /** Opens the signer, runs `work`, and always cleans up (closes connections, drops keys) before resolving. */\n run<T>(ctx: SignerContext, work: (session: SignerSession<E>) => Promise<T>): Promise<T>;\n}\n\n/** The person runs a tool (ssh-keygen, gpg, a Bitcoin wallet) on the statement and pastes the output back. */\nexport interface ExternalToolSigner<E> extends SignerBase {\n kind: \"external-tool\";\n /** `say`: the steps in the app's language (`englishSay` when absent). */\n instructions(statement: IdentityStatement, say?: ProviderSay): SignerInstructions;\n /** What was pasted, as evidence. Throw a message the person can act on (\"That is not an SSH signature\"). */\n parse(pasted: string, statement: IdentityStatement): E | Promise<E>;\n}\n\n/** A popup to the provider's login page (OpenID Connect); the subject comes out of `verify`. */\nexport interface RedirectSigner<E> extends SignerBase {\n kind: \"redirect\";\n start(statement: IdentityStatement, ctx: SignerContext): Promise<E>;\n}\n\n/** The person publishes something the verifier fetches (a DNS TXT record, a /.well-known file). */\nexport interface PublishSigner<E> extends SignerBase {\n kind: \"publish\";\n /** `say`: the steps in the app's language (`englishSay` when absent). */\n instructions(statement: IdentityStatement, say?: ProviderSay): SignerInstructions;\n /** Usually small or empty: the verifier looks the record up itself. */\n evidence(statement: IdentityStatement): E | Promise<E>;\n}\n\nexport type IdentitySigner<E> = InAppSigner<E> | ExternalToolSigner<E> | RedirectSigner<E> | PublishSigner<E>;\n\n/**\n * A provider module's export. Registering it is adding the module under `proofs/providers/` and ONE\n * line in `proofs/registry.ts`.\n */\nexport interface IdentityProofProvider<E = unknown> {\n /** Stable: it is in the statement, on the wire and in storage. `^[a-z][a-z0-9-]{0,31}$`. */\n id: string;\n label: string;\n category: IdentityCategory;\n /**\n * One short line for the picker card, how you make it: \"Sign once with your Nostr signer\". About 40\n * characters at most; the card shows nothing else beside the name and the category.\n */\n summary: string;\n /** The details view (opened from the card, shown again above the form): what is proven and how, a sentence or two. */\n description: string;\n /**\n * What the proof does NOT show, when a contact could easily assume more (\"Does not prove a balance, a past\n * payment, or that you would pay.\"). Shown with the description, never hidden behind a hover.\n */\n limits?: string;\n platforms: readonly IdentityPlatform[];\n subject: SubjectSpec;\n /** How long one proof may last. The person picks up to `maxDays` (never above 400). */\n validity: { defaultDays: number; maxDays: number };\n /**\n * When a verifier's check can go stale (the DNS record may be removed later): the contact's app offers\n * \"Check again\" after this many seconds and shows the last check time. Omit when the evidence is a\n * signature that stays valid until expiry. `perHour`: the most checks the app runs on its own in an hour, for a\n * server that limits lookups per IP (the rest wait for later); well under that limit, so a check a person starts\n * (a new contact's proof, \"Check again\") still gets an answer.\n */\n recheck?: { afterSeconds: number; perHour?: number };\n /** One sentence for people: what `verify` contacts and who learns what. \"Nothing: checked on this device.\" */\n privacy: string;\n /** Mark providers whose flows are not proven against real-world tools yet. */\n experimental?: boolean;\n /** Listed under \"Advanced\" in the picker, for people who know what it is (DIDs), so it does not crowd newcomers. */\n advanced?: boolean;\n signers: readonly IdentitySigner<E>[];\n /**\n * Untrusted evidence off the wire → typed evidence. Strict: exact shape, bounded sizes, no extra keys.\n * The serialized evidence is already capped at 16 KiB before this runs.\n */\n parseEvidence(raw: unknown): E;\n /**\n * Checks `evidence` against exactly `statement.bytes` / `statement.text` and returns what it proves.\n * Throws when it does not. Must:\n * - self-custodied: return `subject === statement.binding.subject`;\n * - provider-attested: return the attested subject and set `attester`;\n * - reach the network only through `ctx.fetch`, and use `ctx.now` for time.\n */\n verify(statement: IdentityStatement, evidence: E, ctx: VerifyContext): Promise<VerifiedIdentity>;\n /**\n * Optional public name/picture for a verified subject (Nostr kind-0). Called ONLY when the person asks,\n * never automatically. Sanitize like avatars: plain-text name, bounded raster re-encoded to a data URL.\n */\n lookupDisplay?(subject: string, options: { signal: AbortSignal }): Promise<IdentityDisplay | undefined>;\n /** The button that runs `lookupDisplay`. Default: \"Show public profile\". */\n lookupLabel?: string;\n /**\n * The verified subject as a URI a public DID document may list in `alsoKnownAs` (the profile's\n * did:dht, and only for identities the person chooses to list there). Omit when the identity has no\n * URI of its own. No comma: did:dht separates the list with commas.\n */\n publicUri?(subject: string): string | undefined;\n /**\n * Takes down what a signer published when the person removes the proof (an AT Protocol record, a Pubky proof file). Runs in\n * the UI, called synchronously from the confirming click (it may open a window first). The shared Pkarr\n * revocation is published either way; if this fails, the person may remove the proof without it.\n */\n unpublish?: {\n /** What the removal adds, for the confirmation: \"Also deletes the record on your server.\" */\n description: string;\n /** `evidence` is what `parseEvidence` accepted when the proof was made (Pubky: the proof file's folder). */\n run(proof: { id: string; subject: string; key: string; evidence: E }, ctx: SignerContext): Promise<void>;\n };\n}\n","import type { GhostlyAdapterPlugin } from \"./registry\";\n\n/**\n * The adapter plugins compiled into this build. Empty unless the build lists some: `GHOSTLY_PLUGINS`\n * names their modules (comma-separated paths from the repository root, each default-exporting a\n * `GhostlyAdapterPlugin`), and the Vite plugin in `packages/browser/vite-plugin.ts` swaps this module\n * for one that imports them. Release builds never set it; the e2e build carries the SDK example.\n */\nexport const BUNDLED_PLUGINS: readonly GhostlyAdapterPlugin[] = [];\n","import type { LightningProviderDescriptor } from \"../engine/paymentAdapters/providers/lightning\";\nimport type { OnchainProviderDescriptor } from \"../engine/paymentAdapters/providers/onchain\";\nimport { providerDescriptorProblems, type ProviderDescriptor, type ProviderKind } from \"../engine/paymentAdapters/providers/types\";\nimport type { IdentityProofProvider } from \"../proofs/contract\";\nimport { descriptorProblems } from \"../proofs/verify\";\nimport { BUNDLED_PLUGINS } from \"./bundled\";\n\n/**\n * Adapters written outside the app: wallet sources (Lightning, on-chain) and identity-proof providers\n * that register here instead of being added to the built-in lists. A plugin is a plain object naming\n * its adapters; the registries (`providers/registry.ts`, `proofs/registry.ts`) list what is registered\n * after the built-ins and before the test fakes, and the same platform and mode rules apply to all.\n *\n * Two ways in:\n * - at build time: `GHOSTLY_PLUGINS` lists the modules and `bundled.ts` is swapped for them;\n * - at run time: code already running in the engine's realm calls `registerAdapters` before the\n * pickers are shown (or after: the engine re-reads the lists when something registers).\n *\n * Trust: a plugin runs with the app's privileges, in the app's own JavaScript realm. There is no\n * sandbox, no permission prompt and no store; whoever builds a plugin in, or loads one, trusts its\n * author with everything the app can do, keys and sats included. A manifest with permissions and an\n * isolated runtime are a later phase (docs/wisps/ADAPTER-ROADMAP.md, \"Plugins, apps, catalogs\").\n *\n * The state lives on `globalThis` under a well-known symbol, so a plugin bundled with its own copy of\n * the SDK (a second copy of this module) still registers into the same lists the app reads.\n */\n\n/** The generation of the adapter contracts. A plugin says which one it was written against. */\nexport const SDK_API = 1;\nexport const PLUGIN_ID = /^[a-z][a-z0-9-]{0,63}$/;\n\nexport interface GhostlyAdapterPlugin {\n /** Stable, unique among plugins: `^[a-z][a-z0-9-]{0,63}$`. */\n id: string;\n /** The plugin's own version, for people. */\n version?: string;\n /** The contract generation it was written against: `SDK_API`. Another one is refused. */\n sdk: number;\n lightning?: readonly LightningProviderDescriptor[];\n onchain?: readonly OnchainProviderDescriptor[];\n identities?: readonly IdentityProofProvider[];\n}\n\nexport type AdapterKind = ProviderKind | \"identity\";\n\ninterface Store {\n plugins: Map<string, GhostlyAdapterPlugin>;\n /** Ids the built-in registries own, per kind: a plugin cannot take one. */\n reserved: Record<AdapterKind, Set<string>>;\n listeners: Set<() => void>;\n seeded: boolean;\n}\n\nconst KEY = Symbol.for(\"ghostly.adapters/1\");\nfunction store(): Store {\n const g = globalThis as unknown as Record<symbol, Store | undefined>;\n return (g[KEY] ??= { plugins: new Map(), reserved: { lightning: new Set(), onchain: new Set(), identity: new Set() }, listeners: new Set(), seeded: false });\n}\n\nconst ids = (kind: AdapterKind, plugin: GhostlyAdapterPlugin): string[] => {\n // Not trusted to be well formed: pluginProblems reads it before saying what is wrong with it.\n const list: unknown = kind === \"identity\" ? plugin.identities : kind === \"lightning\" ? plugin.lightning : plugin.onchain;\n return Array.isArray(list) ? list.map((a: { id?: string } | null) => a?.id as string) : [];\n};\nconst KINDS: readonly AdapterKind[] = [\"lightning\", \"onchain\", \"identity\"];\n\n/** Problems with a plugin, empty when it can be registered. Does not look at what is already registered. */\nexport function pluginProblems(plugin: GhostlyAdapterPlugin): string[] {\n const problems: string[] = [];\n if (!plugin || typeof plugin !== \"object\") return [\"not a plugin object\"];\n if (!PLUGIN_ID.test(plugin.id ?? \"\")) problems.push(\"plugin id must match ^[a-z][a-z0-9-]{0,63}$\");\n if (plugin.sdk !== SDK_API) problems.push(`plugin was written for SDK API ${String(plugin.sdk)}; this app speaks ${SDK_API}`);\n if (plugin.version !== undefined && (typeof plugin.version !== \"string\" || plugin.version.length > 64)) problems.push(\"version must be a short string\");\n for (const kind of [\"lightning\", \"onchain\"] as const) {\n const list = plugin[kind];\n if (list === undefined) continue;\n if (!Array.isArray(list)) { problems.push(`${kind} must be a list of descriptors`); continue; }\n for (const d of list as ProviderDescriptor<unknown>[]) {\n if (!d || typeof d !== \"object\") { problems.push(`${kind} ${String(d)}: not a descriptor`); continue; }\n const own = providerDescriptorProblems(d);\n if (d?.kind && d.kind !== kind) own.push(`is listed under ${kind} but says kind ${String(d.kind)}`);\n problems.push(...own.map((p) => `${kind} ${String(d?.id)}: ${p}`));\n }\n }\n if (plugin.identities !== undefined) {\n if (!Array.isArray(plugin.identities)) problems.push(\"identities must be a list of providers\");\n else for (const p of plugin.identities) {\n if (!p || typeof p !== \"object\") problems.push(`identity ${String(p)}: not a provider`);\n else problems.push(...descriptorProblems(p).map((m) => `identity ${String(p.id)}: ${m}`));\n }\n }\n for (const kind of KINDS) {\n const list = ids(kind, plugin);\n if (new Set(list).size !== list.length) problems.push(`${kind} ids are not unique within the plugin`);\n }\n if (!KINDS.some((kind) => ids(kind, plugin).length)) problems.push(\"the plugin brings no adapter\");\n return problems;\n}\n\n/** The built-in registries say which ids are theirs. A plugin using one is refused. */\nexport function reserveAdapterIds(kind: AdapterKind, list: readonly string[]): void {\n const s = store();\n for (const id of list) s.reserved[kind].add(id);\n}\n\n/**\n * Registers a plugin's adapters. Throws, registering nothing, when the plugin is malformed, its id or\n * one of its adapters' ids is taken (by a built-in or by another plugin), or its contract generation\n * is another one. Returns the function that unregisters it.\n */\nexport function registerAdapters(plugin: GhostlyAdapterPlugin): () => void {\n const problems = pluginProblems(plugin);\n const s = store();\n if (!problems.length) {\n if (s.plugins.has(plugin.id)) problems.push(`a plugin with id ${plugin.id} is already registered`);\n for (const kind of KINDS) for (const id of ids(kind, plugin)) {\n if (s.reserved[kind].has(id)) problems.push(`${kind} ${id} is a built-in of this app`);\n for (const other of s.plugins.values()) if (ids(kind, other).includes(id)) problems.push(`${kind} ${id} is already registered by plugin ${other.id}`);\n }\n }\n if (problems.length) throw new Error(`Cannot register plugin ${String(plugin?.id)}: ${problems.join(\"; \")}`);\n s.plugins.set(plugin.id, plugin);\n notify(s);\n return () => { if (s.plugins.get(plugin.id) === plugin) { s.plugins.delete(plugin.id); notify(s); } };\n}\n\nfunction notify(s: Store) { for (const listener of s.listeners) { try { listener(); } catch { /* a listener's problem */ } } }\n\n/** Called when a plugin registers or unregisters: the engine re-reads the lists. */\nexport function onAdaptersChanged(listener: () => void): () => void {\n const s = store();\n s.listeners.add(listener);\n return () => { s.listeners.delete(listener); };\n}\n\n/** Every registered plugin, in registration order (bundled ones first). */\nexport function registeredPlugins(): readonly GhostlyAdapterPlugin[] { seed(); return [...store().plugins.values()]; }\nexport function registeredLightningProviders(): readonly LightningProviderDescriptor[] { return registeredPlugins().flatMap((p) => p.lightning ?? []); }\nexport function registeredOnchainProviders(): readonly OnchainProviderDescriptor[] { return registeredPlugins().flatMap((p) => p.onchain ?? []); }\nexport function registeredIdentityProviders(): readonly IdentityProofProvider[] { return registeredPlugins().flatMap((p) => p.identities ?? []); }\n\n/**\n * The plugins compiled into this build register once, when they are first asked for. A broken one is\n * reported and skipped rather than taking the app down with it; the e2e that expects it fails instead.\n */\nfunction seed() {\n const s = store();\n if (s.seeded) return;\n s.seeded = true;\n for (const plugin of BUNDLED_PLUGINS) {\n try { registerAdapters(plugin); }\n catch (error) { console.error(`[ghostly] a bundled adapter plugin was not loaded: ${error instanceof Error ? error.message : String(error)}`); }\n }\n}\n\n/** Tests only: forget every registration, including the bundled ones. */\nexport function resetAdapterRegistry(): void {\n const s = store();\n s.plugins.clear(); s.seeded = false;\n for (const kind of KINDS) s.reserved[kind].clear();\n notify(s);\n}\n"],"mappings":";;;;AAoBA,IAAa,qBAAkD;CAAC;CAAO;CAAa;AAAS;;;;;;;;;ACZ7F,IAAa,kBAAmD,CAAC;;;;;;;;;;;;;;;;;;;;;;;ACoBjE,IAAa,UAAU;AACvB,IAAa,YAAY;AAwBzB,IAAM,MAAM,OAAO,IAAI,oBAAoB;AAC3C,SAAS,QAAe;CACtB,MAAM,IAAI;CACV,OAAQ,EAAE,SAAS;EAAE,yBAAS,IAAI,IAAI;EAAG,UAAU;GAAE,2BAAW,IAAI,IAAI;GAAG,yBAAS,IAAI,IAAI;GAAG,0BAAU,IAAI,IAAI;EAAE;EAAG,2BAAW,IAAI,IAAI;EAAG,QAAQ;CAAM;AAC5J;AAEA,IAAM,OAAO,MAAmB,WAA2C;CAEzE,MAAM,OAAgB,SAAS,aAAa,OAAO,aAAa,SAAS,cAAc,OAAO,YAAY,OAAO;CACjH,OAAO,MAAM,QAAQ,IAAI,IA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as __toCommonJS, bT as __exportAll, vT as __commonJSMin, xT as __require, yT as __esmMin } from "./src-C2bAufMs.js";
|
|
2
2
|
//#region ../../node_modules/compact-encoding/endian.js
|
|
3
3
|
var require_endian = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4
4
|
exports.BE = !(exports.LE = new Uint8Array(new Uint16Array([255]).buffer)[0] === 255);
|
|
@@ -76480,4 +76480,4 @@ var require_keet_identity_key = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
76480
76480
|
//#endregion
|
|
76481
76481
|
export default require_keet_identity_key();
|
|
76482
76482
|
|
|
76483
|
-
//# sourceMappingURL=keet-identity-key-
|
|
76483
|
+
//# sourceMappingURL=keet-identity-key-DJbA1oSW.js.map
|