NUI contract ​
The contract between the Lua client, the web UI (web/index.html), the np_phone app (web/phone.html), the
web components and the server RPCs behind them. The wire types are mirrored in
web/src/lib/types.ts and web/src/phone/types.ts. You only need this page to change the UI or write your own front
end; resources that use locks call the exports.
The NUI never decides anything. It sends what the player entered, or the id of a saved entry. The server checks the session, distance, lockout and code, and answers with the result. Plain secrets only travel to the client for the phone app's reveal / copy, a new guest code, the warrant sheet and shoulder surfing.
Messages ​
Every message is { action, data }. Messages are queued until the web posts ready (at most 128).
Lua → web ​
| Action | Data |
|---|---|
boot |
{ locale, material: 'frosted' | 'liquid', brand?, strength?, keys: { autofill, submit, cancel, shuffle } } |
theme |
{ material, brand, strength } when np_admin's server theme changes (Config.Material wins when set) |
prompt.open |
PromptSession (below) |
prompt.result |
{ sid, ok, unlocked, triesLeft, lockedUntil?, error? } |
prompt.close |
{ sid } |
create.open |
{ sid, label, sub?, icon, types, type, length?, rules: { min?, max?, digit?, symbol?, upper?, words?, noReuse? } } |
create.result |
{ sid, ok, strength?, error? } |
crack.open |
{ sid, label, sub, duration, length, strength } (duration in seconds, strength = level) |
crack.close |
{ sid, ok } |
surf.digits |
{ label, digits: (string | false)[] } (false = hidden), shown 6 s |
toast |
{ id, title, message, icon, tint?, actions?: { id, label, key, style? }[], duration? } (fallback without np_hud) |
warrant.open |
{ name, entries: { label, username?, secret, category }[] } |
close |
{} |
PromptSession = {
sid: string, type: 'pin' | 'password' | 'login' | 'phrase' | 'pattern' | 'otp',
label: string, sub?: string, icon: string, tint?: Tint, length?: number, words?: number,
triesLeft: number, maxTries: number, lockedUntil?: number /* ms epoch */,
autofill?: { entryId, label, sub }, // "Use saved code"
logins?: { entryId, username, label, shared }[], // login dropdown
username?: string,
otp?: { app, label, remaining },
}
entryId is '12' for keychain row 12, 'v34' for vault item 34 and 'otp:<app>' for a Codes entry.
Web → Lua ​
NUI callbacks (fetch('https://np_passwords/<name>')) answer { ok = true, … } or { ok = false, code, error }.
| Callback | Body | Lua |
|---|---|---|
ready |
{} |
Sends boot, flushes the queue (on a reload: re-sends what is open) |
prompt.submit |
{ sid, secret?, username?, entryId? } |
RPC prompt.attempt, answers the result and pushes prompt.result |
prompt.cancel |
{ sid } |
RPC prompt.cancel, the waiting Prompt export returns cancelled |
create.submit |
{ sid, secret, type } |
RPC create.submit, pushes create.result |
create.cancel |
{ sid } |
RPC create.cancel |
crack.cancel |
{ sid } |
RPC crack.cancel |
toast.action |
{ id, action } |
RPC offer.answer (action = 'accept' saves) |
close |
{} |
Closes the warrant sheet or whatever is open |
Web components ​
Web components in other resources' pages call these callbacks directly. The client routes them to the same RPCs as the prompt and keeps one component session at a time.
| Callback | Body | Answer |
|---|---|---|
component.autofill |
{ lockId? | verify? | app? } |
{ ok, autofill?, logins?, otp? } (opens the session) |
component.prompt |
{ lockId? | verify?, secret?, username?, entryId? } |
{ ok, unlocked, triesLeft, lockedUntil? } |
component.create |
{ lockId?, type, secret, rules } |
{ ok, strength: { level, seconds } }. With lockId: RPC create.set. Without: validated only, nothing stored |
component.otp |
{ app, code? } |
{ ok, unlocked, triesLeft }. Without code: autofill from the Codes entry |
Server RPCs ​
Client → server: TriggerServerEvent('np_passwords:rpc', id, name, payload), answered with
TriggerClientEvent('np_passwords:rpc', src, id, result) (10 s timeout on the client). Every RPC passes the global
token bucket (Config.RateLimit), a payload check (depth, keys, size), a schema, its own rate window and one call in
flight per name.
| RPC | Payload | Result |
|---|---|---|
prompt.open |
{ lockId?, opts? } |
{ ok, session } |
prompt.attempt |
{ sid, secret?, username?, entryId? } |
{ ok, unlocked, triesLeft, lockedUntil?, error? } |
prompt.cancel |
{ sid } |
{ ok } |
create.open |
{ lockId, opts? } |
{ ok, session } (owners / managers) |
create.submit |
{ sid, secret, type? } |
{ ok, strength } |
create.set |
{ lockId, secret, type?, rules? } |
{ ok, strength } (<np-password-new lock>, owners / managers) |
create.cancel |
{ sid } |
{ ok } |
crack.start |
{ lockId } |
{ ok, sid, label, sub, duration, length, strength } |
crack.finish / crack.cancel |
{ sid } |
{ ok, unlocked? } |
surf.watch |
{ target } |
{ ok } |
offer.answer |
{ offerId, accept } |
{ ok } |
warrant.read |
{ target } |
{ ok, name, entries } |
door.lock |
{ lockId } |
{ ok } (players who know the code or manage the lock, in range) |
Error codes: invalid, unknown_rpc, rate_limited, busy, no_character, not_ready, no_permission,
not_found, no_session, no_code, too_far, too_early, locked, expired, invalid_code, invalid_length,
invalid_type, rule_<min|max|digit|symbol|upper|words|length|reuse>, no_item, no_target, not_typing,
not_crackable, disabled, off_duty, no_document, inventory, limit, internal. error is the localised
text.
Pushes ​
Server → client: TriggerClientEvent('np_passwords:push', src, { action, data }). Some are handled by Lua, the others
are relayed to the web.
| Push | Data | Handled |
|---|---|---|
locks.sync |
{ locks } (public lock list: id, label, icon, type, length, coords, radius, hasCode, hasDoor, locked, door) |
Lua: proximity prompts |
locks.update / locks.remove |
{ lock } / { id } |
Lua |
known |
{ ids } (locks the player has an entry for) |
Lua: Knows, E Unlock |
typing |
{ source, on } |
Lua: watch prompt, np_menu option |
door |
{ id, locked } |
Lua: proximity prompts (the door itself is an np_prophandler door) |
prompt.open |
{ session } (server-initiated Prompt / RequireCode) |
Lua + web |
prompt.close |
{ sid } |
Lua + web |
crack.open / crack.close |
crack.start result / { sid, ok } |
Lua + web |
surf.digits, toast |
as above | web |
Phone app ​
web/phone.html runs inside np_phone. It calls phone.rpc(name, params); np_passwords registers each name with
np_phone's registerAppRpc('passwords', name, fn). The server pushes sendAppMessage(src, 'passwords', 'changed', { scope }) (coalesced 250 ms) and sets the badge with setBadge. Times are ms epoch.
| RPC | Params | Returns |
|---|---|---|
overview |
– | { total, counts: { doors, logins, codes, shared, wifi, other }, security: { score, leaked, weak, reused }, deleted } |
list |
{ category = 'all' | 'doors' | 'logins' | 'wifi' | 'other' | 'shared', sort = 'nearby' | 'az' | 'recent', query? } |
{ items: Entry[] } |
entry |
{ id } |
EntryDetail |
reveal |
{ id } |
{ secret } (rate limited, logged) |
save |
{ id?, kind, category, label, username?, secret?, autofill? } |
{ id } (new manual entry, or a partial update) |
delete / restore / purge |
{ id } |
{} |
deleted |
– | { items: Entry[] } |
nearbyPlayers |
– | { players: { source, name }[] } |
share |
{ id, target } |
{} (the target gets a save offer) |
note |
{ id } |
{} (a paper_note with the code) |
changeCode |
{ lockId, secret } |
{ strength: { level, seconds } } |
guest |
{ lockId, uses, ttl, label? } |
{ code, expiresAt } |
codes |
– | { period, items: { app, label, icon, tint, code, remaining }[] } |
security |
– | { score, leaked: Entry[], weak: Entry[], reused: Entry[] } |
vaults |
– | { items: { id, kind, label, role, rank, members, count, flagged }[] } |
vault |
{ id } |
{ id, kind, label, role, rank, canManage, canEdit, members, items: Entry[], activity, flagged } |
vault.add |
{ vaultId, entryId, minRank? } |
{} |
vault.remove |
{ vaultId, itemId } |
{} |
vault.rotate |
{ vaultId } |
{ rotated } |
vault.create |
{ label } |
{ id } |
vault.invite / vault.kick |
{ vaultId, target, role? } / { vaultId, target } |
{} (target: server id, or a member's cid for kick) |
Entry = {
id: string /* '12' keychain, 'v34' vault item */, lockId?: string, kind: 'lock' | 'login' | 'wifi' | 'custom',
category: 'doors' | 'logins' | 'wifi' | 'other', label: string, icon: string, sub: string, username?: string,
tint?: Tint, distance?: number /* m, locks with coords */, status?: 'leaked' | 'weak' | 'stale',
shared?: { vaultId: string, label: string }, locked?: boolean /* above the player's rank */, flagged?: boolean,
usedAt?: number,
}
EntryDetail = Entry & {
strength: { level: 'weak' | 'fair' | 'good' | 'strong', seconds: number }, length?: number, type?: string,
coords?: { x: number, y: number }, autofill: boolean, uses: number, createdAt: number, rules?: Rules,
history: { at: number, method: string, ok: boolean, name?: string }[],
canEdit: boolean, canManageLock: boolean, canShare: boolean, canNote: boolean,
}
Vault members are { name, role }; managers also get cid and the online source to remove members.