export interface MemWalCredentials { /** 64-hex Ed25519 private key seed (32 bytes). NEVER log this. */ delegatePrivateKey: string; /** 64-hex Ed25519 public key derived from the seed. Safe to display. */ delegatePublicKeyHex: string; /** 0x-prefixed 64-hex Sui address derived from the delegate public key. */ delegateAddress: string; /** 0x-prefixed Sui wallet address that signed the add_delegate_key tx. */ walletAddress: string; /** 0x-prefixed Walrus Memory account object id this delegate is registered against. */ accountId: string; /** 0x-prefixed Walrus Memory package id the account lives in. */ packageId: string; /** Relayer base URL the bridge should connect to. */ relayerUrl: string; /** Human-readable label, e.g. "Cursor MCP" — surfaced in dashboard. */ label?: string; /** ISO timestamp credentials were saved. */ createdAt: string; /** Schema version — bump when we change shape. */ version: 1; } /** * Refusal of a `MEMWAL_CREDS_DIR` that cannot be trusted to sit outside a * repository. Thrown, never swallowed — see {@link credsDirOverride}. */ export declare class UntrustedCredsDirError extends Error { constructor(message: string); } /** The approval store. Outside every repository, on purpose. */ export declare function projectApprovalsPath(): string; /** * What approval is granted against: the destination, not the file's bytes. * * Account, delegate and relayer are the three fields that decide WHERE a * memory ends up and WHO signs for it. Hashing them means a project file may * be re-saved, relabelled or reformatted freely, while any edit that moves the * destination invalidates the approval and has to be approved again. The * delegate private key is deliberately NOT part of it — it must never be read * into a record that gets written back out. */ export declare function credentialsFingerprint(creds: { accountId: string; delegateAddress: string; relayerUrl: string; }): string; /** One approved project credentials file. Contains no secret. */ export interface ProjectApproval { /** Canonical path of the approved `.memwal/credentials.json`. */ path: string; fingerprint: string; accountId: string; delegateAddress: string; relayerUrl: string; approvedAt: string; } /** Why a project credentials file was, or was not, used. */ export type ProjectCredsDecision = /** Approved for exactly this account + delegate + relayer: in use. */ "approved" /** Never approved on this machine. Ignored. */ | "unapproved" /** Approved once, but the destination has since changed. Ignored. */ | "changed" /** Present but not valid credentials, so there is nothing to approve. */ | "unreadable"; export interface ProjectCredsInfo { /** The project-local file that was found. */ path: string; decision: ProjectCredsDecision; /** Destination it points at. Absent when the file could not be read — and * never the delegate private key, which no caller of this ever needs. */ accountId?: string; relayerUrl?: string; } /** Which file won, and what happened to any project-local file that did not. */ export interface CredsResolution { /** The file this process reads and writes. */ path: string; source: "override" | "project" | "global"; /** The project-local file found by the walk, if any — present whether or * not it was used, so callers can report one they ignored. */ project?: ProjectCredsInfo; } /** * Which credentials file this process should read and write, and why. * * `MEMWAL_CREDS_DIR` wins outright, and skips the approval gate — but only a * value {@link credsDirOverride} accepts, i.e. a non-empty ABSOLUTE path * outside the current project. It is "trusted" exactly as far as whoever set * the environment is, and an MCP client will hand this process an `env` block * it read out of the checkout, so a value that could have been committed is * refused rather than obeyed. Otherwise the nearest project-local * `.memwal/credentials.json` at or above the working directory is used IF the * user has approved that exact destination on this machine (WALM-639), and the * global file is used in every other case — including an unapproved, altered * or malformed project file. Falling back rather than failing keeps a machine * that has never seen a project file behaving exactly as it always did. * * Resolved per call rather than at module load, because neither the working * directory nor the approval store is knowable at import time. */ export declare function resolveCreds(): CredsResolution; /** The credentials file in use. Thin wrapper over {@link resolveCreds} so the * many callers that only need a path are unchanged. */ export declare function credsPath(): string; /** Load credentials from disk. Returns null if missing or malformed. */ export declare function loadCreds(): MemWalCredentials | null; /** What {@link approveProjectCreds} did. */ export interface ApproveProjectResult { outcome: /** Newly approved. */ "approved" /** Approved again after the destination changed. */ | "reapproved" /** Already approved for this exact destination; nothing written. */ | "already-approved" /** No project-local credentials file at or above the working directory. */ | "none" /** A project file exists but is not valid credentials. */ | "unreadable" /** `MEMWAL_CREDS_DIR` is set, so project resolution never runs. */ | "overridden"; projectPath?: string; accountId?: string; relayerUrl?: string; /** Destination the previous approval covered, when this replaced one. */ previousAccountId?: string; previousRelayerUrl?: string; approvalsPath: string; } /** * Approve the project-local credentials found from the working directory. * * Deliberately takes no arguments: it approves what resolution would otherwise * ignore, from the same directory, so "what am I approving" and "what will be * used" cannot drift apart. */ export declare function approveProjectCreds(): ApproveProjectResult; /** What {@link revokeProjectCredsApproval} did. */ export interface RevokeProjectResult { outcome: "revoked" | "none"; projectPath?: string; approvalsPath: string; } /** * Withdraw the approval for the project-local credentials here. * * Keyed on the path rather than on the file's current contents, so an approval * can be withdrawn even after the file it covered was edited or deleted — a * revoke that only worked while the destination still matched would be * useless exactly when it is wanted. */ export declare function revokeProjectCredsApproval(): RevokeProjectResult; /** * The warning for a project credentials file that was found and NOT used, or * null when there is nothing to report. * * Says which file was ignored, where memory is going instead, and the exact * command that approves it — a silent fallback would be the mirror image of * the silent redirect this gate exists to stop. Never contains a key: the only * fields it reads are the account id and the relayer URL. */ export declare function formatProjectCredsNotice(resolution?: CredsResolution): string | null; /** * What approving a project credentials file costs, beyond redirecting reads. * * Approval does not just decide which file is READ — it decides which file is * WRITTEN. `saveCreds` writes to `credsPath()`, so from here on every sign-in * from this project puts a fresh 64-hex Ed25519 delegate seed, in plaintext, * into a directory that is inside the repository. An attacker who planted the * file planted the directory too, so it is already tracked rather than ignored, * and `git add -A` stages the key. The user cannot weigh that if nobody says * it, and "you approved a destination" is not the same sentence as "you * approved storing a private key in your repo". * * Separate from {@link formatProjectCredsNotice} on purpose: that one is about * a file that was IGNORED, this one is about a file that is about to be used. */ export declare function formatProjectCredsStorageWarning(projectPath: string): string; /** * Write credentials with secure (`0600`) permission, to whichever file * `credsPath()` resolves to. * * Replacing a *different* account backs the outgoing file up first. There was * no backup of any kind before, so an overwrite was unrecoverable — and the * overwrite that matters is exactly the one that switches accounts (GH #628). * Same-account rewrites (a label change, a rotated delegate) are not backed up: * they are routine, and a backup per login would just churn the directory. */ export declare function saveCreds(creds: MemWalCredentials): SaveCredsResult; /** * Move `tmp` onto `path`, atomically where the platform can. * * POSIX `rename(2)` replaces a destination regardless of who has it open, so * there is nothing to handle there and any error is a real one. Windows * implements the same call as `MoveFileEx(MOVEFILE_REPLACE_EXISTING)`, which * refuses with EPERM / EACCES / EBUSY while another handle holds the * destination — an antivirus scan or a backup agent touching * `credentials.json` is enough. Before this file wrote through a temp inode, * `writeFileSync` to the final path survived that; `login.ts` turns a thrown * `saveCreds` into an HTTP 500, so a lock that lasts a few milliseconds would * otherwise become a failed sign-in. * * So on Windows: retry briefly, then write in place rather than fail. That * fallback gives up the atomic swap, but not the property this function exists * for — Windows does not enforce POSIX mode bits at all, so `0600` was never * doing the work there; NTFS ACLs are, and they are inherited from the * directory either way. On POSIX, where the mode IS the protection, there is no * fallback and no retry. * * `deps` is a seam for tests. CI has no Windows runner, and the fallback is the * one branch here that can leave a second plaintext copy of the delegate key on * disk, so it must be exercisable off Windows. */ export declare function replaceWithTemp(tmp: string, path: string, contents: string, deps?: { platform?: string; rename?: (from: string, to: string) => void; sleep?: (ms: number) => void; }): void; /** What `saveCreds` did, so the caller can tell the user precisely — naming * both accounts is the difference between a warning they can act on and the * silent swap reported in GH #628. */ export interface SaveCredsResult { /** File actually written (project-local or global). */ path: string; /** Account whose credentials were displaced. Absent on a first sign-in or * a same-account re-save. */ replacedAccountId?: string; /** Where the displaced file was copied. Absent when nothing was replaced, * or when the copy failed. */ backedUpTo?: string; } /** * The message shown *before* a sign-in that would overwrite existing * credentials, or null when there is nothing to lose. * * Deliberately shown ahead of the browser step: that is the last moment the * user can back out for free. The incoming account is not known until the * callback arrives, by which point a delegate key has already been registered * on-chain — so a warning that waits for both ids is a warning that arrives * too late to act on. * * When the file being replaced is an approved project one, that is also the * last moment before a new private key lands inside a repository, so the * storage warning is repeated here rather than left behind at approval time — * approval may have been months ago, or done by someone else on the machine. */ export declare function formatPendingSignInWarning(): string | null; /** * The message shown when a sign-in displaced a different account, or null when * nothing was replaced. * * Both ids on purpose: "your credentials changed" is useless without knowing * which account you left and which you are now on — that ambiguity is the whole * of GH #628. Kept here as a pure function so the wording is testable without * driving a browser login. */ export declare function formatReplacementNotice(saved: SaveCredsResult, incomingAccountId: string): string | null; /** What `clearCreds` did. Reported rather than printed, for the same reason * `saveCreds` reports: persistence should not own user-facing output. */ export interface ClearCredsResult { /** File actually deleted. Absent when there was nothing to remove, or the * unlink failed. */ removedPath?: string; /** Credentials that take over from the next run, because removing the file * above them re-exposed them. Absent when signing out was complete. */ fallbackPath?: string; } /** * Delete the credentials this process resolves to. No-op if none exist. * * Resolution happens *before* the unlink on purpose: once the file is gone * `credsPath()` reports the next one down the chain, so a caller that asked * afterwards would name a file it never touched. That same survivor is what * the next run loads, so removing a project file while a global one exists is * not a full sign-out — `fallbackPath` is how the caller can say so instead of * leaving the user to discover a different account later (GH #628). */ export declare function clearCreds(): ClearCredsResult; /** * How long a stranded record stays recoverable. * * Deliberately far longer than the 5-minute login timeout: the whole point is * to survive a client restart, and a user who quits for the evening and comes * back tomorrow is exactly the case worth covering. The cost of holding it is * an unregistered key on disk, which grants nothing. */ export declare const PENDING_LOGIN_TTL_MS: number; export interface PendingLogin { /** 64-hex Ed25519 private key seed. NEVER log this. */ delegatePrivateKey: string; delegatePublicKeyHex: string; delegateAddress: string; /** Relayer the flow was started against — recovery must not repoint. */ relayerUrl: string; label?: string; /** ISO timestamp, for TTL expiry. */ createdAt: string; version: 1; } /** * Where the write-ahead record lives — never inside a repository. * * It used to sit beside whichever credentials file `credsPath()` resolved to, * which reads as "recover into the project you signed in from" and is the right * intent. But for an approved project that path is `/.memwal/`, so every * sign-in dropped a plaintext 64-hex delegate seed into the working tree — * under a directory an attacker who planted the credentials file had already * created, so tracked rather than ignored, and staged by `git add -A`. * * Nothing about this record needs to be in the repo. It is short-lived * handshake state, nobody edits it by hand, and the only property that matters * is that the project which started a sign-in is the one that can reclaim it. * So it moves to the trusted state directory, keyed by a hash of the * credentials path: same per-project scoping, no key material in the checkout. * * The non-project cases are byte-for-byte where they always were — * `dirname(credsPath())` IS `trustedStateDir()` for both the override and the * global file — so a machine that has never approved a project sees no change. */ export declare function pendingLoginPath(): string; /** * Persist the pending keypair. Throws if it cannot. * * Deliberately NOT best-effort. The invariant this record exists to hold is * that the delegate private key is on disk before its public half can reach a * browser that will pay gas to register it. Swallowing the error would publish * the connect URL while claiming a durability that does not exist — the * original WALM-332 loss, now silent. * * Failing the login costs the user nothing: this file lives in the same * trusted state directory the approval record does, so a directory that cannot * take it is one this process cannot keep state in at all. The same login would * have failed at the callback anyway, one on-chain `add_delegate_key` later. */ export declare function savePendingLogin(pending: PendingLogin): void; /** * A pending record this login can adopt instead of minting a new keypair. * * `loginFlow` used to generate a fresh keypair every call and overwrite the * record unconditionally. Recovery only runs at process start and is skipped * for `--login` / `forceLogin`, so a timed-out login followed by `memwal_login` * in the same process replaced the only copy of a key the browser may already * have paid to register. Reusing the record keeps that key reclaimable. * * Scoped to the same relayer: a key registered against one relayer's account * proves nothing to another, and `recovery` must never repoint. TTL and shape * are already enforced by {@link loadPendingLogin}. */ export declare function reusablePendingLogin(relayerUrl: string): PendingLogin | null; /** * Load a pending record, or null if there is none, it is malformed, or it has * aged out. An expired record is deleted on read rather than left to linger. */ export declare function loadPendingLogin(): PendingLogin | null; /** Remove the pending record. Safe to call when there isn't one. */ export declare function clearPendingLogin(): void; //# sourceMappingURL=auth.d.ts.map