Files
wownerogue/html/js/smirkChatSign.js
jwinterm ed24d43b56 chore: prepare the repository for public release
Removes operator-private material from the shipped tree, corrects documentation
that had drifted from the code, deletes dead code, and applies a consistent
prose style.

Private material moved out of the public tree (docs/private/, git-ignored):
  - the wallet keyfile recovery runbook and its helper scripts, which together
    published the mainnet wallet file path, the service account, backup snapshot
    filenames, and the wallet RPC listener state. The helper duplicated the same
    constants, so relocating the document alone would not have removed them.
  - the stagenet parallel-candidate runbook and its fixtures.
  - the dated production-state record, the internal remediation plan, and the
    TODO list. None are reference documentation for an outside reader.

Redacted or genericised:
  - operator home-directory paths in shipped scripts and units. The asset build
    script now takes KENNEY_ASSETS_DIR instead of a hard-coded path.
  - private LAN addresses in tests, env examples and deploy docs, replaced with
    RFC 5737 documentation addresses.
  - the default alert sender and the notification hub example.
  - the Monero wallet unit now matches the Wownero one: a dedicated service
    account and a config file, instead of the operator's login account with the
    wallet password in argv where any local user can read it from /proc.

Ignore rules now cover every .env variant rather than the bare name, plus local
agent state. The deployment docs instruct operators to create .env.mainnet and
.env.stagenet, which the exact-name rule would have allowed to be committed.

Documentation corrected against the code: per-chain dungeon level counts, the
premium unlock rule, Tavern chat scope, backup retention, the chain-profile
fallback, the environment template location, and several sections describing
shipped work as pending.

Dead code removed: configPersistence, rpccalls, a duplicate vendored ROT.js
bundle, the unused tile-picker overlay, the unreachable legacy game-size path
and its vestigial parameter, spectator stubs that shadowed the real
SpectatorManager, and commented-out debugging. nip98 now imports the shared
nostr loader rather than duplicating it.

Prose style: em-dashes removed throughout in favour of colons, semicolons and
commas; comments restated as present-tense descriptions of the code rather than
narration of past changes.

127 suites / 1015 tests pass.
2026-07-27 06:40:38 -04:00

47 lines
2.5 KiB
JavaScript

(function (root) {
'use strict';
// Per-player nostr identity (Phase 2). Sign a global-chat message with the player's OWN Smirk
// npub (window.smirk.signNostrEvent) and emit it as `chat_signed`; the server verifies it's
// signed by this session's authenticated npub, then relays it to nostr under that npub.
//
// Returns a Promise<boolean>: true if it signed + emitted, false if Smirk signing is
// unavailable or declined, in which case the caller falls back to the normal unsigned send.
// Feature-detected end to end, so it's a no-op (always false) until the page has a connected
// Smirk wallet; wiring it into a send site is therefore always safe.
// Sign an event, granting the Nostr scope on demand. Signing FIRST means a returning user
// (scope already granted for this origin, e.g. from the game's NIP-98 login) gets a single
// approval; only a first-time origin hits NOT_AUTHORIZED and needs the one-time scope grant.
// Same pattern as SmirkAuth (html/js/network/smirkAuth.js).
function signWithScope(smirk, tmpl) {
return Promise.resolve()
.then(function () { return smirk.signNostrEvent(tmpl); })
.catch(function (err) {
var needsScope = (err && err.code === 'NOT_AUTHORIZED')
|| /nostr scope|getNostrPublicKey/i.test((err && err.message) || '');
if (!needsScope || typeof smirk.getNostrPublicKey !== 'function') throw err;
return smirk.getNostrPublicKey().then(function () { return smirk.signNostrEvent(tmpl); });
});
}
function smirkChatSign(socket, text, tag) {
try {
var smirk = root.smirk;
if (!socket || !smirk || typeof smirk.signNostrEvent !== 'function') return Promise.resolve(false);
var tmpl = {
kind: 1,
created_at: Math.floor(Date.now() / 1000),
tags: [['t', tag || 'wowngeon-global']],
content: String(text)
};
return signWithScope(smirk, tmpl).then(function (signed) {
if (!signed || !signed.id || !signed.sig || !signed.pubkey) return false;
socket.emit('chat_signed', { event: signed });
return true;
}).catch(function () { return false; });
} catch (e) {
return Promise.resolve(false);
}
}
root.smirkChatSign = smirkChatSign;
})(typeof window !== 'undefined' ? window : this);