@unicitylabs/sphere-sdk 0.8.0-dev.3 → 0.8.0-dev.5
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 +37 -11
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +8 -3
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +37 -11
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +51 -11
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +51 -11
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +49 -12
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +8 -2
- package/dist/impl/nodejs/index.d.ts +8 -2
- package/dist/impl/nodejs/index.js +49 -12
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +37 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +37 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.cts
CHANGED
|
@@ -6728,13 +6728,14 @@ type DecryptionProgressCallback = (iteration: number, total: number) => Promise<
|
|
|
6728
6728
|
*
|
|
6729
6729
|
* const storage = createLocalStorageProvider();
|
|
6730
6730
|
* const transport = createNostrTransportProvider();
|
|
6731
|
-
* const oracle = createUnicityAggregatorProvider({ url: '/rpc' });
|
|
6731
|
+
* const oracle = createUnicityAggregatorProvider({ url: '/rpc', network: 'testnet2' });
|
|
6732
6732
|
*
|
|
6733
6733
|
* // Option 1: Unified init (recommended)
|
|
6734
6734
|
* const { sphere, created, generatedMnemonic } = await Sphere.init({
|
|
6735
6735
|
* storage,
|
|
6736
6736
|
* transport,
|
|
6737
6737
|
* oracle,
|
|
6738
|
+
* network: 'testnet2', // required: selects registry/trustbase/aggregator
|
|
6738
6739
|
* mnemonic: 'your twelve words...', // optional - will load if wallet exists
|
|
6739
6740
|
* autoGenerate: true, // generate new mnemonic if needed
|
|
6740
6741
|
* });
|
|
@@ -6745,9 +6746,9 @@ type DecryptionProgressCallback = (iteration: number, total: number) => Promise<
|
|
|
6745
6746
|
*
|
|
6746
6747
|
* // Option 2: Manual create/load
|
|
6747
6748
|
* if (await Sphere.exists(storage)) {
|
|
6748
|
-
* const sphere = await Sphere.load({ storage, transport, oracle });
|
|
6749
|
+
* const sphere = await Sphere.load({ storage, transport, oracle, network: 'testnet2' });
|
|
6749
6750
|
* } else {
|
|
6750
|
-
* const sphere = await Sphere.create({ mnemonic, storage, transport, oracle });
|
|
6751
|
+
* const sphere = await Sphere.create({ mnemonic, storage, transport, oracle, network: 'testnet2' });
|
|
6751
6752
|
* }
|
|
6752
6753
|
*
|
|
6753
6754
|
* // Use the wallet
|
|
@@ -6878,6 +6879,10 @@ interface SphereImportOptions {
|
|
|
6878
6879
|
derivationMode?: DerivationMode;
|
|
6879
6880
|
/** Optional nametag to register for this wallet (e.g., 'alice' for @alice). Token is auto-minted. */
|
|
6880
6881
|
nametag?: string;
|
|
6882
|
+
/** Network this wallet runs on — drives TokenRegistry config. Without it, import
|
|
6883
|
+
* falls back to NETWORKS.testnet and a non-testnet wallet loads the wrong registry
|
|
6884
|
+
* (symbols resolve via baked values but icons/metadata don't) until a reload. */
|
|
6885
|
+
network?: NetworkType;
|
|
6881
6886
|
/** Storage provider instance */
|
|
6882
6887
|
storage: StorageProvider;
|
|
6883
6888
|
/** Optional token storage provider */
|
package/dist/core/index.d.ts
CHANGED
|
@@ -6728,13 +6728,14 @@ type DecryptionProgressCallback = (iteration: number, total: number) => Promise<
|
|
|
6728
6728
|
*
|
|
6729
6729
|
* const storage = createLocalStorageProvider();
|
|
6730
6730
|
* const transport = createNostrTransportProvider();
|
|
6731
|
-
* const oracle = createUnicityAggregatorProvider({ url: '/rpc' });
|
|
6731
|
+
* const oracle = createUnicityAggregatorProvider({ url: '/rpc', network: 'testnet2' });
|
|
6732
6732
|
*
|
|
6733
6733
|
* // Option 1: Unified init (recommended)
|
|
6734
6734
|
* const { sphere, created, generatedMnemonic } = await Sphere.init({
|
|
6735
6735
|
* storage,
|
|
6736
6736
|
* transport,
|
|
6737
6737
|
* oracle,
|
|
6738
|
+
* network: 'testnet2', // required: selects registry/trustbase/aggregator
|
|
6738
6739
|
* mnemonic: 'your twelve words...', // optional - will load if wallet exists
|
|
6739
6740
|
* autoGenerate: true, // generate new mnemonic if needed
|
|
6740
6741
|
* });
|
|
@@ -6745,9 +6746,9 @@ type DecryptionProgressCallback = (iteration: number, total: number) => Promise<
|
|
|
6745
6746
|
*
|
|
6746
6747
|
* // Option 2: Manual create/load
|
|
6747
6748
|
* if (await Sphere.exists(storage)) {
|
|
6748
|
-
* const sphere = await Sphere.load({ storage, transport, oracle });
|
|
6749
|
+
* const sphere = await Sphere.load({ storage, transport, oracle, network: 'testnet2' });
|
|
6749
6750
|
* } else {
|
|
6750
|
-
* const sphere = await Sphere.create({ mnemonic, storage, transport, oracle });
|
|
6751
|
+
* const sphere = await Sphere.create({ mnemonic, storage, transport, oracle, network: 'testnet2' });
|
|
6751
6752
|
* }
|
|
6752
6753
|
*
|
|
6753
6754
|
* // Use the wallet
|
|
@@ -6878,6 +6879,10 @@ interface SphereImportOptions {
|
|
|
6878
6879
|
derivationMode?: DerivationMode;
|
|
6879
6880
|
/** Optional nametag to register for this wallet (e.g., 'alice' for @alice). Token is auto-minted. */
|
|
6880
6881
|
nametag?: string;
|
|
6882
|
+
/** Network this wallet runs on — drives TokenRegistry config. Without it, import
|
|
6883
|
+
* falls back to NETWORKS.testnet and a non-testnet wallet loads the wrong registry
|
|
6884
|
+
* (symbols resolve via baked values but icons/metadata don't) until a reload. */
|
|
6885
|
+
network?: NetworkType;
|
|
6881
6886
|
/** Storage provider instance */
|
|
6882
6887
|
storage: StorageProvider;
|
|
6883
6888
|
/** 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,
|
|
@@ -28052,13 +28071,14 @@ var Sphere = class _Sphere {
|
|
|
28052
28071
|
*/
|
|
28053
28072
|
static resolveGroupChatConfig(config, network) {
|
|
28054
28073
|
if (!config) return void 0;
|
|
28074
|
+
if (!network) {
|
|
28075
|
+
throw new SphereError("network is required to resolve group chat relays.", "INVALID_CONFIG");
|
|
28076
|
+
}
|
|
28055
28077
|
if (config === true) {
|
|
28056
|
-
|
|
28057
|
-
return { relays: [...netConfig.groupRelays] };
|
|
28078
|
+
return { relays: [...NETWORKS[network].groupRelays] };
|
|
28058
28079
|
}
|
|
28059
28080
|
if (!config.relays || config.relays.length === 0) {
|
|
28060
|
-
|
|
28061
|
-
return { ...config, relays: [...netConfig.groupRelays] };
|
|
28081
|
+
return { ...config, relays: [...NETWORKS[network].groupRelays] };
|
|
28062
28082
|
}
|
|
28063
28083
|
return config;
|
|
28064
28084
|
}
|
|
@@ -28105,8 +28125,13 @@ var Sphere = class _Sphere {
|
|
|
28105
28125
|
* This method ensures the main bundle's TokenRegistry is properly configured.
|
|
28106
28126
|
*/
|
|
28107
28127
|
static configureTokenRegistry(storage, network) {
|
|
28108
|
-
|
|
28109
|
-
|
|
28128
|
+
if (!network) {
|
|
28129
|
+
throw new SphereError(
|
|
28130
|
+
"network is required to configure the TokenRegistry. Every Sphere entry point must forward options.network.",
|
|
28131
|
+
"INVALID_CONFIG"
|
|
28132
|
+
);
|
|
28133
|
+
}
|
|
28134
|
+
TokenRegistry.configure({ remoteUrl: NETWORKS[network].tokenRegistryUrl, storage });
|
|
28110
28135
|
}
|
|
28111
28136
|
/**
|
|
28112
28137
|
* Create new wallet with mnemonic
|
|
@@ -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);
|