@unicitylabs/sphere-sdk 0.15.0 → 0.16.0-dev.2
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.
- package/README.md +15 -5
- package/dist/connect/index.cjs +26 -25
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.d.cts +4 -0
- package/dist/connect/index.d.ts +4 -0
- package/dist/connect/index.js +26 -25
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +728 -227
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +174 -23
- package/dist/core/index.d.ts +174 -23
- package/dist/core/index.js +728 -226
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +16 -25
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +16 -25
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +333 -506
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +333 -506
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +15 -24
- package/dist/impl/nodejs/connect/index.cjs.map +1 -1
- package/dist/impl/nodejs/connect/index.js +15 -24
- package/dist/impl/nodejs/connect/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +300 -571
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +92 -15
- package/dist/impl/nodejs/index.d.ts +92 -15
- package/dist/impl/nodejs/index.js +300 -571
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/impl/shared/wallet-api/index.d.cts +54 -2
- package/dist/impl/shared/wallet-api/index.d.ts +54 -2
- package/dist/index.cjs +730 -227
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +229 -110
- package/dist/index.d.ts +229 -110
- package/dist/index.js +730 -226
- package/dist/index.js.map +1 -1
- package/dist/modules/payments-v2/index.cjs +11 -7
- package/dist/modules/payments-v2/index.cjs.map +1 -1
- package/dist/modules/payments-v2/index.d.cts +56 -3
- package/dist/modules/payments-v2/index.d.ts +56 -3
- package/dist/modules/payments-v2/index.js +11 -7
- package/dist/modules/payments-v2/index.js.map +1 -1
- package/dist/token-engine/index.cjs +46 -0
- package/dist/token-engine/index.cjs.map +1 -1
- package/dist/token-engine/index.js +46 -0
- package/dist/token-engine/index.js.map +1 -1
- package/package.json +1 -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` |
|
|
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
|
-
> **
|
|
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
|
|
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/
|
|
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
|
|
package/dist/connect/index.cjs
CHANGED
|
@@ -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,16 +241,25 @@ var DEFAULT_GROUP_RELAYS = [
|
|
|
250
241
|
var NETWORKS = {
|
|
251
242
|
mainnet: {
|
|
252
243
|
name: "Mainnet",
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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
|
|
260
260
|
// run against it. 'testnet2' stays as an alias of the same configuration.
|
|
261
261
|
testnet: {
|
|
262
|
-
name: "
|
|
262
|
+
name: "Testnet",
|
|
263
263
|
networkId: 4,
|
|
264
264
|
// v2 state-transition gateway (networkId 4 comes from the trust base). apiKey is env-injected.
|
|
265
265
|
aggregatorUrl: "https://gateway.testnet2.unicity.network",
|
|
@@ -269,7 +269,7 @@ var NETWORKS = {
|
|
|
269
269
|
tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet2.json"
|
|
270
270
|
},
|
|
271
271
|
testnet2: {
|
|
272
|
-
name: "
|
|
272
|
+
name: "Testnet",
|
|
273
273
|
networkId: 4,
|
|
274
274
|
// v2 state-transition gateway (networkId 4 comes from the trust base). apiKey is env-injected.
|
|
275
275
|
aggregatorUrl: "https://gateway.testnet2.unicity.network",
|
|
@@ -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.
|
|
449
|
+
var SDK_VERSION = "0.16.0-dev.2";
|
|
459
450
|
|
|
460
451
|
// connect/permissions.ts
|
|
461
452
|
var PERMISSION_SCOPES = {
|
|
@@ -906,6 +897,16 @@ var ConnectHost = class {
|
|
|
906
897
|
return;
|
|
907
898
|
}
|
|
908
899
|
if (this._walletState === "live") {
|
|
900
|
+
if (this.session?.active && (this.snapshot.networkId ?? null) !== (next.networkId ?? null)) {
|
|
901
|
+
logger.warn(
|
|
902
|
+
"ConnectHost",
|
|
903
|
+
`Network changed under a live session \u2014 revoking instead of rebinding (origin=${this.config.origin ?? "unverified"})`
|
|
904
|
+
);
|
|
905
|
+
this.sphere = next;
|
|
906
|
+
this.snapshot = buildWalletSnapshot(next);
|
|
907
|
+
this.revokeSession();
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
909
910
|
this.sphere = next;
|
|
910
911
|
this.snapshot = buildWalletSnapshot(next);
|
|
911
912
|
const existing = this.eventSubscriptions.get(WALLET_EVENTS.IDENTITY_CHANGED);
|