@unicitylabs/sphere-sdk 0.8.0-dev.3 → 0.8.0-dev.4
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/dist/core/index.cjs +31 -5
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +4 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +31 -5
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +19 -4
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +19 -4
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +19 -4
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.js +19 -4
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +31 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.cts
CHANGED
|
@@ -6878,6 +6878,10 @@ interface SphereImportOptions {
|
|
|
6878
6878
|
derivationMode?: DerivationMode;
|
|
6879
6879
|
/** Optional nametag to register for this wallet (e.g., 'alice' for @alice). Token is auto-minted. */
|
|
6880
6880
|
nametag?: string;
|
|
6881
|
+
/** Network this wallet runs on — drives TokenRegistry config. Without it, import
|
|
6882
|
+
* falls back to NETWORKS.testnet and a non-testnet wallet loads the wrong registry
|
|
6883
|
+
* (symbols resolve via baked values but icons/metadata don't) until a reload. */
|
|
6884
|
+
network?: NetworkType;
|
|
6881
6885
|
/** Storage provider instance */
|
|
6882
6886
|
storage: StorageProvider;
|
|
6883
6887
|
/** Optional token storage provider */
|
package/dist/core/index.d.ts
CHANGED
|
@@ -6878,6 +6878,10 @@ interface SphereImportOptions {
|
|
|
6878
6878
|
derivationMode?: DerivationMode;
|
|
6879
6879
|
/** Optional nametag to register for this wallet (e.g., 'alice' for @alice). Token is auto-minted. */
|
|
6880
6880
|
nametag?: string;
|
|
6881
|
+
/** Network this wallet runs on — drives TokenRegistry config. Without it, import
|
|
6882
|
+
* falls back to NETWORKS.testnet and a non-testnet wallet loads the wrong registry
|
|
6883
|
+
* (symbols resolve via baked values but icons/metadata don't) until a reload. */
|
|
6884
|
+
network?: NetworkType;
|
|
6881
6885
|
/** Storage provider instance */
|
|
6882
6886
|
storage: StorageProvider;
|
|
6883
6887
|
/** Optional token storage provider */
|
package/dist/core/index.js
CHANGED
|
@@ -7199,6 +7199,19 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7199
7199
|
// ===========================================================================
|
|
7200
7200
|
// Cache (StorageProvider)
|
|
7201
7201
|
// ===========================================================================
|
|
7202
|
+
/**
|
|
7203
|
+
* Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
|
|
7204
|
+
* testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
|
|
7205
|
+
* global key let a stale testnet snapshot be served for a testnet2 request —
|
|
7206
|
+
* wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
|
|
7207
|
+
* by remoteUrl isolates the snapshots so a network can never read another's.
|
|
7208
|
+
*/
|
|
7209
|
+
cacheKeys() {
|
|
7210
|
+
const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
|
|
7211
|
+
const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
|
|
7212
|
+
if (!this.remoteUrl) return { data: base, ts: baseTs };
|
|
7213
|
+
return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
|
|
7214
|
+
}
|
|
7202
7215
|
/**
|
|
7203
7216
|
* Load definitions from StorageProvider cache.
|
|
7204
7217
|
* Only applies if cache exists and is fresh (within refreshIntervalMs).
|
|
@@ -7206,9 +7219,10 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7206
7219
|
async loadFromCache() {
|
|
7207
7220
|
if (!this.storage) return false;
|
|
7208
7221
|
try {
|
|
7222
|
+
const { data: dataKey, ts: tsKey } = this.cacheKeys();
|
|
7209
7223
|
const [cached, cachedTs] = await Promise.all([
|
|
7210
|
-
this.storage.get(
|
|
7211
|
-
this.storage.get(
|
|
7224
|
+
this.storage.get(dataKey),
|
|
7225
|
+
this.storage.get(tsKey)
|
|
7212
7226
|
]);
|
|
7213
7227
|
if (!cached || !cachedTs) return false;
|
|
7214
7228
|
const ts = parseInt(cachedTs, 10);
|
|
@@ -7231,9 +7245,10 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7231
7245
|
async saveToCache(definitions) {
|
|
7232
7246
|
if (!this.storage) return;
|
|
7233
7247
|
try {
|
|
7248
|
+
const { data: dataKey, ts: tsKey } = this.cacheKeys();
|
|
7234
7249
|
await Promise.all([
|
|
7235
|
-
this.storage.set(
|
|
7236
|
-
this.storage.set(
|
|
7250
|
+
this.storage.set(dataKey, JSON.stringify(definitions)),
|
|
7251
|
+
this.storage.set(tsKey, String(Date.now()))
|
|
7237
7252
|
]);
|
|
7238
7253
|
} catch {
|
|
7239
7254
|
}
|
|
@@ -27984,6 +27999,8 @@ var Sphere = class _Sphere {
|
|
|
27984
27999
|
const walletExists = await _Sphere.exists(options.storage);
|
|
27985
28000
|
if (walletExists) {
|
|
27986
28001
|
const sphere2 = await _Sphere.load({
|
|
28002
|
+
network: options.network,
|
|
28003
|
+
// forward network so load's configureTokenRegistry uses it (not the testnet default)
|
|
27987
28004
|
storage: options.storage,
|
|
27988
28005
|
transport: options.transport,
|
|
27989
28006
|
oracle: options.oracle,
|
|
@@ -28018,6 +28035,8 @@ var Sphere = class _Sphere {
|
|
|
28018
28035
|
}
|
|
28019
28036
|
const sphere = await _Sphere.create({
|
|
28020
28037
|
mnemonic,
|
|
28038
|
+
network: options.network,
|
|
28039
|
+
// forward network so create's configureTokenRegistry uses it (not the testnet default)
|
|
28021
28040
|
storage: options.storage,
|
|
28022
28041
|
transport: options.transport,
|
|
28023
28042
|
oracle: options.oracle,
|
|
@@ -28105,6 +28124,12 @@ var Sphere = class _Sphere {
|
|
|
28105
28124
|
* This method ensures the main bundle's TokenRegistry is properly configured.
|
|
28106
28125
|
*/
|
|
28107
28126
|
static configureTokenRegistry(storage, network) {
|
|
28127
|
+
if (!network) {
|
|
28128
|
+
logger.warn(
|
|
28129
|
+
"Sphere",
|
|
28130
|
+
"configureTokenRegistry: no network provided \u2014 defaulting to testnet. Pass options.network to avoid loading the wrong-network registry."
|
|
28131
|
+
);
|
|
28132
|
+
}
|
|
28108
28133
|
const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
|
|
28109
28134
|
TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
|
|
28110
28135
|
}
|
|
@@ -28256,7 +28281,8 @@ var Sphere = class _Sphere {
|
|
|
28256
28281
|
await options.storage.connect();
|
|
28257
28282
|
logger.debug("Sphere", "Storage reconnected");
|
|
28258
28283
|
}
|
|
28259
|
-
|
|
28284
|
+
_Sphere.configureTokenRegistry(options.storage, options.network);
|
|
28285
|
+
const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
|
|
28260
28286
|
const marketConfig = _Sphere.resolveMarketConfig(options.market);
|
|
28261
28287
|
const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
|
|
28262
28288
|
const swapConfig = _Sphere.resolveSwapConfig(options.swap);
|