Skip to content

Match @bsv/sdk 4.1.1 UHRP, registry, identity and KVStore tokens - #17

Merged
rohenaz merged 4 commits into
mainfrom
storage-registry-identity-tokens
Nov 16, 2026
Merged

rohenaz merged 4 commits into
mainfrom
storage-registry-identity-tokens

Conversation

@rohenaz

@rohenaz rohenaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Before: Swift's UHRP advertisements, registry entries, identity reveals and KVStore tokens used layouts that the TS topic managers reject, so files, registry definitions and identities published from Swift did not show up for TS clients and the reverse.

After: all four token types use the @bsv/sdk 4.1.1 layouts, and Swift decodes six token scripts generated by TS 4.1.1 (and writes byte-identical basket, protocol and KVStore tokens).

How: new signed codecs that follow the TS validators, wallet-signed encoders, and frozen TS vectors in the tests.

Behaviour changes

  • UHRP: new BSVStorage.UHRPAdvertisement with the TS six-field signed layout (host key, hash, HTTPS URL, expiry, size, signature; locking key linked to the host under 2-uhrp advertisement-1). UHRPDownloader checks hash and expiry and sends {"uhrpUrl","limit","offset"}. UHRPURL accepts uhrp:<id>.
  • Registry: basket/protocol/certificate tokens are 7/7/8 fields at protocol level 1 with the operator's signature; decode checks the linked key and signature; encode is async, signs with the wallet and refuses a non-operator wallet or empty fields. TS size bounds (16 KiB per field, 64 KiB total) are enforced. Certificate field JSON is accepted in any key order. High-S signatures are accepted as in TS.
  • Identity: IdentityClientOptions defaults to [1,"identity"]; public reveals always prove to the anyone key (verifier: parameter removed); badge links match TS.
  • KVStore: tokens are [value, signature] under [2, context], one-field tokens are rejected, values are capped at 2 MiB; new async wallet write and owner-checked decode.
  • The Go one-field registry token is no longer read or written (COMP-056 superseded).

API breaks

  • BSVNetwork: noAvailableHosts → noAvailableHosts(rejected:), allHostsFailed → allHostsFailed(_:). New UHRPAdvertisementRejection, UHRPHostFailure, UHRPAdvertisementLookup, advertisements(for:).
  • BSVRegistry: pushDropFailure carries its PushDropError; new roundTripMismatch, emptyField(name:), textTooLong, aggregateTooLarge, maximumTokenFieldByteCount, maximumTokenPayloadByteCount, fieldNames(for:); encoders are async.
  • BSVKVStore: new invalidWalletLocator.
  • BSVIdentity: publiclyRevealAttributes(Simple) lose the verifier: parameter.

All new and changed errors have plain-word errorDescriptions in the style of PR 15, with full detail kept for logs.

Testing

swift test in swift:6.1 (Linux) after merging main: 876 tests passed, XCTest 154 passed, 0 failures; only live and opt-in tests skipped. check-public-api.sh clean.

Live overlay hosts run the TypeScript topic managers, so the token shapes
now follow @bsv/sdk 4.1.1.

- UHRP: new UHRPAdvertisement decodes the six-field signed advertisement
  (host key, hash, URL, expiry, size, signature) and checks the BRC-42 link
  to the host under [2, "uhrp advertisement"]. The downloader uses it and
  sends limit and offset in the ls_uhrp query. uhrp:<id> now parses.
- Registry: tokens carry the operator signature (7/7/8 fields) under
  [1, "basketmap"|"protomap"|"certmap"], key ID "1", counterparty anyone.
  Decoding checks key linkage and signature; encoding signs with the
  wallet. Certificate field JSON is read in any key order.
- Identity: default protocol is [1, "identity"] and public reveal always
  proves to the anyone key. Badge links match TypeScript.
- KVStore: tokens are [value, signature] under [2, context], key, self,
  with a 2 MiB value limit. One-field tokens are rejected.
…tail

- Registry decode and encode apply the TypeScript token bounds (16 KiB per
  field, 64 KiB total, signature included) whatever RegistryLimits says.
- A registry data field written as OP_0 is rejected, as TypeScript reads it
  as "\0" and refuses it. Empty-field errors name the field.
- UHRP, registry and KVStore verification accept high-S signatures, as
  TypeScript does. DER stays strict.
- UHRPDownloader keeps why each advertisement was skipped and why each host
  failed. advertisements(for:) returns both lists; noAvailableHosts and
  allHostsFailed carry them, with a short description and the full list in
  debugDescription.
- RegistryError.pushDropFailure carries its PushDropError, and a failed
  round-trip throws roundTripMismatch instead of invalidSignature.
- KVStore locator wallet conversions throw invalidWalletLocator, and the
  unowned decode overload says plainly that it proves no ownership.
- Superseded one-field KVStore text in COMP-056, GoSDK-v1.3.3.md and
  Roadmap.md is marked or updated.
Frozen scripts produced by @bsv/sdk 4.1.1 (ts-stack 3b1abc569) under bun
with PrivateKey(42), each checked by the TypeScript validator: a UHRP
advertisement, basket, protocol and certificate registry tokens (with
certificate field JSON out of byte order), a LocalKVStore token, and the
[1, "identity"] reveal locking key. The generating TypeScript is in each
test's doc comment.

Swift decodes every script, and its wallet path derives the same locking
key. The basket, protocol and KVStore scripts Swift writes are byte for
byte the TypeScript ones.
Brings in plain-word error descriptions with full logs (PR 15) and the
merkle path and ASM compatibility work (PR 16).

UHRPDownloader keeps both sides: each failed host and each skipped
advertisement is logged through NetworkLog and also kept in the
noAvailableHosts(rejected:) and allHostsFailed(_:) payloads.

Following PR 15, UHRPDownloadError, UHRPAdvertisementError, RegistryError
and KVStoreError now give a short plain sentence as errorDescription, while
String(reflecting:) keeps the full detail for logs.
@rohenaz
rohenaz merged commit 122768f into main Nov 16, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant