@unicitylabs/sphere-sdk 0.15.0-dev.1 → 0.16.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +15 -5
  2. package/dist/connect/index.cjs +23 -25
  3. package/dist/connect/index.cjs.map +1 -1
  4. package/dist/connect/index.d.cts +4 -0
  5. package/dist/connect/index.d.ts +4 -0
  6. package/dist/connect/index.js +23 -25
  7. package/dist/connect/index.js.map +1 -1
  8. package/dist/core/index.cjs +726 -225
  9. package/dist/core/index.cjs.map +1 -1
  10. package/dist/core/index.d.cts +172 -21
  11. package/dist/core/index.d.ts +172 -21
  12. package/dist/core/index.js +726 -224
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/impl/browser/connect/index.cjs +23 -25
  15. package/dist/impl/browser/connect/index.cjs.map +1 -1
  16. package/dist/impl/browser/connect/index.js +23 -25
  17. package/dist/impl/browser/connect/index.js.map +1 -1
  18. package/dist/impl/browser/index.cjs +331 -504
  19. package/dist/impl/browser/index.cjs.map +1 -1
  20. package/dist/impl/browser/index.js +331 -504
  21. package/dist/impl/browser/index.js.map +1 -1
  22. package/dist/impl/nodejs/connect/index.cjs +22 -24
  23. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  24. package/dist/impl/nodejs/connect/index.js +22 -24
  25. package/dist/impl/nodejs/connect/index.js.map +1 -1
  26. package/dist/impl/nodejs/index.cjs +298 -569
  27. package/dist/impl/nodejs/index.cjs.map +1 -1
  28. package/dist/impl/nodejs/index.d.cts +90 -13
  29. package/dist/impl/nodejs/index.d.ts +90 -13
  30. package/dist/impl/nodejs/index.js +298 -569
  31. package/dist/impl/nodejs/index.js.map +1 -1
  32. package/dist/impl/shared/wallet-api/index.d.cts +54 -2
  33. package/dist/impl/shared/wallet-api/index.d.ts +54 -2
  34. package/dist/index.cjs +728 -225
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +227 -108
  37. package/dist/index.d.ts +227 -108
  38. package/dist/index.js +728 -224
  39. package/dist/index.js.map +1 -1
  40. package/dist/modules/payments-v2/index.cjs +11 -7
  41. package/dist/modules/payments-v2/index.cjs.map +1 -1
  42. package/dist/modules/payments-v2/index.d.cts +56 -3
  43. package/dist/modules/payments-v2/index.d.ts +56 -3
  44. package/dist/modules/payments-v2/index.js +11 -7
  45. package/dist/modules/payments-v2/index.js.map +1 -1
  46. package/dist/token-engine/index.cjs +46 -0
  47. package/dist/token-engine/index.cjs.map +1 -1
  48. package/dist/token-engine/index.js +46 -0
  49. package/dist/token-engine/index.js.map +1 -1
  50. package/package.json +2 -1
package/README.md CHANGED
@@ -172,10 +172,9 @@ The SDK ships network presets that configure all services automatically. `networ
172
172
  |---------|----------------------|-------------|
173
173
  | `testnet` | gateway.testnet2.unicity.network (v2) | nostr-relay.testnet.unicity.network |
174
174
  | `testnet2` | alias of `testnet` (same configuration) | nostr-relay.testnet.unicity.network |
175
- | `mainnet` | aggregator.unicity.network (v1-era) | relay.unicity.network (+ public relays) |
176
- | `dev` | dev-aggregator.dyndns.org (v1-era) | nostr-relay.testnet.unicity.network |
175
+ | `mainnet` | gateway.mainnet.unicity.network (v3) | nostr-relay.testnet.unicity.network (shared until mainnet has its own) |
177
176
 
178
- > **v1 → v2 cutover:** `testnet` now points at **testnet2**, the v2 state-transition gateway network (network id 4, taken from the trust base; own testnet2 token registry). The old `goggregator-test` testnet spoke the removed v1 protocol and is gone. `mainnet` and `dev` still point at v1-era aggregators — wallet operations that move money (`send`, `mint`) **fail loudly** (`AGGREGATOR_ERROR`) on those networks until their gateways are cut over. The transfer wire payload is the finished token blob — the base SDK's own `Token.toCBOR()` bytes, with no sphere envelope around them — deposited into the recipient's wallet-api mailbox.
177
+ > **Live networks are testnet2 and mainnet.** `testnet` is an alias of **testnet2** (network id 4, taken from the trust base; own testnet2 token registry); `mainnet` is network id 1. The v1 network is discontinued — the old `goggregator-test` testnet spoke the removed v1 protocol, and the `dev` network that aliased its trust base has been removed along with every other v1 pointer. Mainnet has no wallet-api deployment yet, so its money path is not reachable even though the chain and gateway are live. The transfer wire payload is the finished token blob — the base SDK's own `Token.toCBOR()` bytes, with no sphere envelope around them — deposited into the recipient's wallet-api mailbox.
179
178
  >
180
179
  > The **network** name (testnet2) and the **base-SDK major** (3.x since 0.15.0) are separate axes: testnet2 is still testnet2 after the 3.0.1 bump. What the bump changes is the bytes on that network — a gateway serving the v3 protocol accepts nothing a 2.x client writes, and vice versa.
181
180
 
@@ -217,7 +216,7 @@ The `testnet` preset wires most of these automatically — you only pass `networ
217
216
  | **Group-chat relay** (NIP-29) | `wss://sphere-relay.unicity.network` |
218
217
  | **Token registry** | `https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet2.json` |
219
218
 
220
- The aggregator key above is the **testnet2** key only and is safe in client code; a **mainnet** key is a real secret. `mainnet`/`dev` still point at v1-era aggregators and cannot serve the engine (`AGGREGATOR_ERROR`).
219
+ The aggregator key above is the **testnet2** key only and is safe in client code; a **mainnet** key is a real secret and must never be committed.
221
220
 
222
221
  ## Price Provider (Optional)
223
222
 
@@ -668,6 +667,14 @@ const sphere = await Sphere.import({
668
667
  });
669
668
  ```
670
669
 
670
+ > **`Sphere.import()` wipes first, and that wipe destroys live Spheres.** When a wallet already
671
+ > exists on the given storage — or a Sphere is live on it — import calls `Sphere.clear()` before
672
+ > writing, which calls `destroy()` on every live `Sphere` built on that **backing store**: their
673
+ > payments verticals stop, their providers disconnect, and every `sphere.on()` handler goes with
674
+ > them. The scope is the store, not the provider object: two provider objects reporting the same
675
+ > `backingStoreId` share the teardown, while a Sphere on unrelated storage is left alone. Drop
676
+ > your references to the old instance rather than reusing it.
677
+
671
678
  ## Wallet Export/Import (JSON)
672
679
 
673
680
  ```typescript
@@ -829,7 +836,7 @@ import type {
829
836
 
830
837
  // Resolver utilities (impl/shared/resolvers.ts)
831
838
  import {
832
- getNetworkConfig, // Get mainnet/testnet/dev config
839
+ getNetworkConfig, // Get mainnet/testnet2 config
833
840
  resolveTransportConfig, // Apply extend/override pattern for relays
834
841
  resolveOracleConfig, // Resolve oracle URL with fallback
835
842
  resolveArrayConfig, // Generic array merge helper
@@ -881,6 +888,9 @@ Design and migration references:
881
888
 
882
889
  - [Payments vertical design](./docs/PAYMENTS-V2-DESIGN.md) — the authoritative money design
883
890
  - [Payments migration guide](./docs/MIGRATION-PAYMENTS-V2.md) — what the P11 flip moved
891
+ - [Token registry migration guide](./docs/MIGRATION-TOKEN-REGISTRY.md) — the per-Sphere token
892
+ registry, the removed `Sphere.getInstance()` / `isInitialized()` lifecycle globals, and
893
+ `Sphere.clear()` / `import()` becoming backing-store-scoped
884
894
 
885
895
  ## Browser Providers
886
896
 
@@ -230,17 +230,8 @@ var NETWORK_SCOPED_ADDRESS_PREFIXES = [
230
230
  "inv_ledger:"
231
231
  // AccountingModule INV_LEDGER_PREFIX
232
232
  ];
233
- var DEFAULT_NOSTR_RELAYS = [
234
- "wss://relay.unicity.network",
235
- "wss://relay.damus.io",
236
- "wss://nos.lol",
237
- "wss://relay.nostr.band"
238
- ];
239
- var DEFAULT_AGGREGATOR_URL = "https://aggregator.unicity.network/rpc";
240
- var DEV_AGGREGATOR_URL = "https://dev-aggregator.dyndns.org/rpc";
241
233
  var DEFAULT_BASE_PATH = "m/44'/0'/0'";
242
234
  var DEFAULT_DERIVATION_PATH = `${DEFAULT_BASE_PATH}/0/0`;
243
- var TOKEN_REGISTRY_URL = "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
244
235
  var TEST_NOSTR_RELAYS = [
245
236
  "wss://nostr-relay.testnet.unicity.network"
246
237
  ];
@@ -250,10 +241,19 @@ var DEFAULT_GROUP_RELAYS = [
250
241
  var NETWORKS = {
251
242
  mainnet: {
252
243
  name: "Mainnet",
253
- aggregatorUrl: DEFAULT_AGGREGATOR_URL,
254
- nostrRelays: DEFAULT_NOSTR_RELAYS,
244
+ networkId: 1,
245
+ // v3 state-transition gateway (networkId 1 comes from the trust base). apiKey is env-injected;
246
+ // unlike testnet2's, a mainnet gateway key is a SECRET — never commit one.
247
+ aggregatorUrl: "https://gateway.mainnet.unicity.network",
248
+ // Mainnet has no relay of its own yet — it shares the testnet relay until one is stood up.
249
+ // Consequence while shared: nametag bindings for both networks live in ONE namespace, and
250
+ // since bindings carry no network the cross-network recipient guard can only signal (#734).
251
+ nostrRelays: TEST_NOSTR_RELAYS,
255
252
  groupRelays: DEFAULT_GROUP_RELAYS,
256
- tokenRegistryUrl: TOKEN_REGISTRY_URL
253
+ // Published, but currently only the non-fungible base token type — no fungible
254
+ // coins yet, so those still miss the registry (decimals 0, symbol falls back to
255
+ // six hex chars). Presentation only: the money path treats coinId as opaque bytes.
256
+ tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.mainnet.json"
257
257
  },
258
258
  // v1 cutover: 'testnet' now POINTS AT TESTNET2 (the v2 gateway network). The
259
259
  // old goggregator testnet spoke the removed v1 protocol — a v2 engine cannot
@@ -277,19 +277,10 @@ var NETWORKS = {
277
277
  // reuse testnet infra (shared relays/ipfs)
278
278
  groupRelays: DEFAULT_GROUP_RELAYS,
279
279
  tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet2.json"
280
- },
281
- // NOTE: mainnet/dev still point at v1-era aggregators. The v2 engine cannot
282
- // operate against them until their gateways are cut over to the v2 protocol —
283
- // wallet operations on these networks fail loudly (AGGREGATOR_ERROR) until then.
284
- dev: {
285
- name: "Development",
286
- aggregatorUrl: DEV_AGGREGATOR_URL,
287
- nostrRelays: TEST_NOSTR_RELAYS,
288
- groupRelays: DEFAULT_GROUP_RELAYS,
289
- tokenRegistryUrl: TOKEN_REGISTRY_URL
290
280
  }
291
281
  };
292
282
  var SPHERE_NETWORKS = {
283
+ mainnet: { id: NETWORKS.mainnet.networkId, name: "mainnet" },
293
284
  testnet2: { id: NETWORKS.testnet2.networkId, name: "testnet2" }
294
285
  };
295
286
  var HOST_READY_TYPE = "sphere-connect:host-ready";
@@ -455,7 +446,7 @@ function checkCompatibility(input) {
455
446
  }
456
447
 
457
448
  // connect/version.ts
458
- var SDK_VERSION = "0.15.0-dev.1";
449
+ var SDK_VERSION = "0.16.0-dev.1";
459
450
 
460
451
  // connect/permissions.ts
461
452
  var PERMISSION_SCOPES = {
@@ -540,8 +531,15 @@ var REALTIME_STATUS = {
540
531
  function toLegacyRequest(view, status) {
541
532
  return { ...view, symbol: view.symbol ?? "", status };
542
533
  }
534
+ function paymentsOrNull(sphere) {
535
+ try {
536
+ return sphere.payments;
537
+ } catch {
538
+ return null;
539
+ }
540
+ }
543
541
  function legacyRequestPayload(sphere, update) {
544
- const view = sphere.payments.requests.list().find((request) => request.id === update.id);
542
+ const view = paymentsOrNull(sphere)?.requests.list().find((request) => request.id === update.id);
545
543
  if (!view) {
546
544
  return {
547
545
  id: update.id,
@@ -620,7 +618,7 @@ var COMPAT_ATTACHERS = /* @__PURE__ */ new Map([
620
618
  forward({ providerId: "wallet-api", error: "wallet-api connection degraded" });
621
619
  })],
622
620
  ["sync:completed", (sphere, forward) => sphere.on("inventory:updated", () => {
623
- forward({ source: "payments", count: sphere.payments.tokens().length });
621
+ forward({ source: "payments", count: paymentsOrNull(sphere)?.tokens().length ?? 0 });
624
622
  })],
625
623
  ["sync:remote-update", remoteUpdateAttacher]
626
624
  ]);