meshmonitor icon indicating copy to clipboard operation
meshmonitor copied to clipboard

[FEAT] MeshCore: import/export MeshCore One contact-share tokens <pubkey:type:name>

Open Yeraze opened this issue 3 weeks ago • 1 comments

Summary

Support the MeshCore One contact-share token <publicKeyHex:type:name> for import and export in MeshMonitor.

Requested by matt in Discord (#feature-requests › MeshCore Contact Import).

Token format (verified against MeshCore One source)

Source: Avi0n/MeshCoreOne → MC1Services/Sources/MC1Services/Utilities/ContactShareUtilities.swift

  • Shape: <64-hex-pubkey:type:name>
  • Regex: <[0-9a-fA-F]{64}:\d+:[^>]+>
  • Public key: 32 bytes as 64 hex characters. Uppercase on emit, case-insensitive on parse.
  • Type: firmware ADV_TYPE_* value. 1 = Companion (chat), 2 = Repeater, 3 = Room. (Not 0 for Repeater. 0 is ADV_TYPE_NONE, 4 is ADV_TYPE_SENSOR — see MeshCore/src/helpers/AdvertDataHelpers.h.) MC1 rejects unknown type values.
  • Name: split the interior on : with max 2 splits, so the name may contain :. Strip > from the name on emit. Reject an empty name.
  • A message can hold more than one token (MC1 extractShares).

MC1 also has the matching UI: MC1/Views/Chats/Components/ChatShareMenu.swift and MC1/Views/Chats/Sheets/ShareContactPickerSheet.swift.

Import

  1. Detect tokens in MeshCore channel messages and DMs. Render a clickable 🪪 next to each token.
  2. Click opens a modal with name, type, and public key, plus Import and Cancel.
  3. Add the token format to the Import dialog on the MeshCore Map/Nodes page. Today handleImport in src/components/MeshCore/MeshCoreNodesView.tsx only accepts a hex signed advert blob (optionally meshcore://-prefixed).

Backend note

The token carries no signature or advert, so the existing POST .../contacts/import (signed advert bytes) path does not fit. The existing .../contacts/:publicKey/add-to-device path needs the node to already exist in the DB. Import needs a new path that builds a contact from pubkey + type + name (empty/flood out-path) and writes it with CMD_ADD_UPDATE_CONTACT (addOrUpdateContact, already used in src/server/meshcoreNativeBackend.ts). It should reuse the existing contact-table-full / favourites-protection handling from add-to-device.

Import is Companion-only because only a Companion source holds a device contact table. Token detection and the 🪪 display should work on every MeshCore source type.

Export

  1. Add a + button between the "Type a message…" field and the Send button, in both MeshCore channel and DM composers.
  2. The + opens a small menu. The only option for now is Share contact (keep it extensible).
  3. Share contact opens a picker with all known contacts (Companions, Repeaters, Rooms) and a search box that filters the list.
  4. Clicking a contact closes the picker and inserts <PUBKEYHEX:type:name> into the message box.

Acceptance

  • Round-trip: a token emitted by MeshMonitor parses in MC1, and the reverse.
  • Name with : parses correctly. Name with > is stripped on emit.
  • Malformed tokens (wrong key length, unknown type, empty name) do not render a 🪪.
  • Token length fits within the MeshCore message size limit when inserted (warn if the name pushes it over).

Authored by NodeZero 0️⃣

Yeraze avatar Nov 12 '26 16:11 Yeraze

Scope addition: "Share my contact info"

Requested by matt in Discord. Add a second option to the composer + menu: Share my contact info.

  • Clicking it inserts a token for the source's own Companion node into the message box: <SELF_PUBKEY_HEX:1:self node name>. No picker.
  • Type is always 1 (Companion / chat), because only a Companion source can send channel messages and DMs.
  • Disable the option when the source has no valid 32-byte public key or the node name is empty.

MeshCore One does the same thing: MC1/Views/Chats/Components/ChatShareMenu.swift → shareMyInfo() builds the token from the connected device's public key and name with type: .chat. canShareMyInfo() gates it on key length = 32 and a non-empty trimmed name.

Updated + menu:

  1. Share contact (picker, as above)
  2. Share my contact info (self token, direct insert)

Authored by NodeZero 0️⃣

Yeraze avatar Nov 12 '26 18:11 Yeraze