Add yaw2 invite interoperability
Protocol: - invite.go: include full 64-char `net` hash in waste: invite blob (matches yaw2's `net` field — any client parsing the base64 JSON can join without knowing the plaintext name). Expose NetHash() helper. - netmgr: add JoinByHash() — join via full 64-char hex hash alone, storing the short ID as display name. Enables joining yaw2 networks from a URL that only carries the hash. - anchor: expose RunByHash() so netmgr can pass a pre-computed hash directly without a name→hash roundtrip. - ipc/proto: add network_hash field to join_network — routes to JoinByHash when present and network_name is absent. Web UI: - Parse ?net=<64hex> (yaw2 URL param) and ?a=<anchor> in addition to existing ?n= / ?invite= params. Hash-only joins send network_hash. - Sidebar shows yaw: contact card (yaw:<masterID>?n=<alias>) using the master identity — compatible with yaw2 contact card format. Click to copy to clipboard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,30 +7,42 @@ interface Props {
|
||||
|
||||
// Parse URL search params for pre-filling the join form.
|
||||
// Supports:
|
||||
// ?invite=waste:<b64> waste: invite string (anchor + network name)
|
||||
// ?invite=waste:<b64> waste: invite string (anchor + network name + net hash)
|
||||
// ?n=<name> network name shorthand
|
||||
// ?network=<name> network name
|
||||
// ?net=<64hex> yaw2-style full network hash (joined without plaintext name)
|
||||
// ?a=<url> anchor URL hint (informational — daemon controls its anchor)
|
||||
function parseInviteParams(): { network: string; anchor: string; inviteString: string } {
|
||||
function parseInviteParams(): { network: string; netHash: string; anchor: string; inviteString: string } {
|
||||
const p = new URLSearchParams(window.location.search)
|
||||
const inviteString = p.get('invite') ?? ''
|
||||
let network = p.get('n') ?? p.get('network') ?? ''
|
||||
let netHash = p.get('net') ?? ''
|
||||
let anchor = p.get('a') ?? p.get('anchor') ?? ''
|
||||
|
||||
if (inviteString.startsWith('waste:')) {
|
||||
try {
|
||||
// URL-safe base64 → standard base64
|
||||
const json = JSON.parse(atob(inviteString.slice(6).replace(/-/g, '+').replace(/_/g, '/')))
|
||||
network = network || json.network || ''
|
||||
netHash = netHash || json.net || ''
|
||||
anchor = anchor || json.anchor || ''
|
||||
} catch { /* ignore bad invite */ }
|
||||
}
|
||||
|
||||
return { network, anchor, inviteString }
|
||||
// URL path: /<16hex>/ — short network ID from anchor-served URL
|
||||
const pathMatch = window.location.pathname.match(/\/([0-9a-f]{16})\/?$/i)
|
||||
if (pathMatch && !netHash && !network) {
|
||||
// Only the short ID — can't join by short ID alone (need full hash for HKDF).
|
||||
// Store it as a hint; the user must supply the network name OR a full 64-char hash.
|
||||
}
|
||||
|
||||
return { network, netHash, anchor, inviteString }
|
||||
}
|
||||
|
||||
export function Onboarding({ status }: Props) {
|
||||
const { send, masterAlias, masterId, exportedBackup } = useWaste()
|
||||
const [network, setNetwork] = useState('')
|
||||
const [netHash, setNetHash] = useState('')
|
||||
const [inviteString, setInviteString] = useState('')
|
||||
const [anchorHint, setAnchorHint] = useState('')
|
||||
const [exportPass, setExportPass] = useState('')
|
||||
@@ -40,8 +52,9 @@ export function Onboarding({ status }: Props) {
|
||||
const [showBackup, setShowBackup] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const { network: n, anchor: a, inviteString: inv } = parseInviteParams()
|
||||
const { network: n, netHash: nh, anchor: a, inviteString: inv } = parseInviteParams()
|
||||
if (n) setNetwork(n)
|
||||
if (nh) setNetHash(nh)
|
||||
if (a) setAnchorHint(a)
|
||||
if (inv) setInviteString(inv)
|
||||
}, [])
|
||||
@@ -49,8 +62,14 @@ export function Onboarding({ status }: Props) {
|
||||
function joinNetwork(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
const name = network.trim()
|
||||
if (!name) return
|
||||
send({ type: 'join_network', network_name: name })
|
||||
const hash = netHash.trim()
|
||||
if (!name && !hash) return
|
||||
if (hash.length === 64 && !name) {
|
||||
// yaw2-style: join by full network hash without plaintext name
|
||||
send({ type: 'join_network', network_hash: hash })
|
||||
} else {
|
||||
send({ type: 'join_network', network_name: name })
|
||||
}
|
||||
}
|
||||
|
||||
function exportIdentity(e: React.FormEvent) {
|
||||
@@ -110,23 +129,31 @@ export function Onboarding({ status }: Props) {
|
||||
{anchorHint && (
|
||||
<p className="onboarding-hint muted">via {anchorHint}</p>
|
||||
)}
|
||||
<input
|
||||
value={network}
|
||||
onChange={e => setNetwork(e.target.value)}
|
||||
placeholder="network name"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
/>
|
||||
{inviteString && (
|
||||
{netHash && !network ? (
|
||||
<input
|
||||
value={inviteString}
|
||||
readOnly
|
||||
className="muted mono"
|
||||
value={netHash}
|
||||
onChange={e => setNetHash(e.target.value)}
|
||||
placeholder="network hash (64 hex)"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
className="mono"
|
||||
style={{ fontSize: '0.72rem' }}
|
||||
title="invite string"
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
value={network}
|
||||
onChange={e => setNetwork(e.target.value)}
|
||||
placeholder="network name"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
/>
|
||||
)}
|
||||
<button type="submit" className="primary" disabled={!network.trim()}>
|
||||
{inviteString && (
|
||||
<p className="onboarding-hint muted mono" style={{ fontSize: '0.68rem', wordBreak: 'break-all' }}>
|
||||
{inviteString.slice(0, 48)}…
|
||||
</p>
|
||||
)}
|
||||
<button type="submit" className="primary" disabled={!network.trim() && netHash.length !== 64}>
|
||||
Join
|
||||
</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user