@unicitylabs/sphere-sdk 0.8.0-dev.2 → 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 +36 -7
- 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 +36 -7
- 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 +36 -7
- 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 +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7562,6 +7562,19 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7562
7562
|
// ===========================================================================
|
|
7563
7563
|
// Cache (StorageProvider)
|
|
7564
7564
|
// ===========================================================================
|
|
7565
|
+
/**
|
|
7566
|
+
* Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
|
|
7567
|
+
* testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
|
|
7568
|
+
* global key let a stale testnet snapshot be served for a testnet2 request —
|
|
7569
|
+
* wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
|
|
7570
|
+
* by remoteUrl isolates the snapshots so a network can never read another's.
|
|
7571
|
+
*/
|
|
7572
|
+
cacheKeys() {
|
|
7573
|
+
const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
|
|
7574
|
+
const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
|
|
7575
|
+
if (!this.remoteUrl) return { data: base, ts: baseTs };
|
|
7576
|
+
return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
|
|
7577
|
+
}
|
|
7565
7578
|
/**
|
|
7566
7579
|
* Load definitions from StorageProvider cache.
|
|
7567
7580
|
* Only applies if cache exists and is fresh (within refreshIntervalMs).
|
|
@@ -7569,9 +7582,10 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7569
7582
|
async loadFromCache() {
|
|
7570
7583
|
if (!this.storage) return false;
|
|
7571
7584
|
try {
|
|
7585
|
+
const { data: dataKey, ts: tsKey } = this.cacheKeys();
|
|
7572
7586
|
const [cached, cachedTs] = await Promise.all([
|
|
7573
|
-
this.storage.get(
|
|
7574
|
-
this.storage.get(
|
|
7587
|
+
this.storage.get(dataKey),
|
|
7588
|
+
this.storage.get(tsKey)
|
|
7575
7589
|
]);
|
|
7576
7590
|
if (!cached || !cachedTs) return false;
|
|
7577
7591
|
const ts = parseInt(cachedTs, 10);
|
|
@@ -7594,9 +7608,10 @@ var TokenRegistry = class _TokenRegistry {
|
|
|
7594
7608
|
async saveToCache(definitions) {
|
|
7595
7609
|
if (!this.storage) return;
|
|
7596
7610
|
try {
|
|
7611
|
+
const { data: dataKey, ts: tsKey } = this.cacheKeys();
|
|
7597
7612
|
await Promise.all([
|
|
7598
|
-
this.storage.set(
|
|
7599
|
-
this.storage.set(
|
|
7613
|
+
this.storage.set(dataKey, JSON.stringify(definitions)),
|
|
7614
|
+
this.storage.set(tsKey, String(Date.now()))
|
|
7600
7615
|
]);
|
|
7601
7616
|
} catch {
|
|
7602
7617
|
}
|
|
@@ -9839,7 +9854,8 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
9839
9854
|
try {
|
|
9840
9855
|
const peerInfo = await this.deps.transport.resolve?.(request.recipient) ?? null;
|
|
9841
9856
|
const recipientPubkey = this.resolveTransportPubkey(request.recipient, peerInfo);
|
|
9842
|
-
const
|
|
9857
|
+
const willUseEngine = !!(this.deps?.tokenEngine && peerInfo?.chainPubkey);
|
|
9858
|
+
const recipientAddress = willUseEngine ? null : await this.resolveRecipientAddress(request.recipient, request.addressMode, peerInfo);
|
|
9843
9859
|
const signingService = await this.createSigningService();
|
|
9844
9860
|
const stClient = this.deps.oracle.getStateTransitionClient?.();
|
|
9845
9861
|
if (!stClient) {
|
|
@@ -9963,6 +9979,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
9963
9979
|
splitPlan.remainderAmount,
|
|
9964
9980
|
splitPlan.coinId,
|
|
9965
9981
|
recipientAddress,
|
|
9982
|
+
// v1 path only — non-null (would have thrown in resolve otherwise)
|
|
9966
9983
|
onChainMessage
|
|
9967
9984
|
);
|
|
9968
9985
|
committedOnChainTokenIds.add(splitPlan.tokenToSplit.uiToken.id);
|
|
@@ -10043,6 +10060,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
10043
10060
|
splitPlan.remainderAmount,
|
|
10044
10061
|
splitPlan.coinId,
|
|
10045
10062
|
recipientAddress,
|
|
10063
|
+
// v1 path only — non-null (would have thrown in resolve otherwise)
|
|
10046
10064
|
{
|
|
10047
10065
|
memo: request.memo,
|
|
10048
10066
|
message: onChainMessage,
|
|
@@ -13039,7 +13057,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
13039
13057
|
const nametag = recipient.startsWith("@") ? recipient.slice(1) : info.nametag || recipient;
|
|
13040
13058
|
if (!info.directAddress) {
|
|
13041
13059
|
throw new SphereError(
|
|
13042
|
-
`"${nametag}" has no
|
|
13060
|
+
`"${nametag}" has no published identity \u2014 the recipient must register a Unicity ID (publish a key-based identity binding) before they can receive payments.`,
|
|
13043
13061
|
"INVALID_RECIPIENT"
|
|
13044
13062
|
);
|
|
13045
13063
|
}
|
|
@@ -28417,6 +28435,8 @@ var Sphere = class _Sphere {
|
|
|
28417
28435
|
const walletExists = await _Sphere.exists(options.storage);
|
|
28418
28436
|
if (walletExists) {
|
|
28419
28437
|
const sphere2 = await _Sphere.load({
|
|
28438
|
+
network: options.network,
|
|
28439
|
+
// forward network so load's configureTokenRegistry uses it (not the testnet default)
|
|
28420
28440
|
storage: options.storage,
|
|
28421
28441
|
transport: options.transport,
|
|
28422
28442
|
oracle: options.oracle,
|
|
@@ -28451,6 +28471,8 @@ var Sphere = class _Sphere {
|
|
|
28451
28471
|
}
|
|
28452
28472
|
const sphere = await _Sphere.create({
|
|
28453
28473
|
mnemonic,
|
|
28474
|
+
network: options.network,
|
|
28475
|
+
// forward network so create's configureTokenRegistry uses it (not the testnet default)
|
|
28454
28476
|
storage: options.storage,
|
|
28455
28477
|
transport: options.transport,
|
|
28456
28478
|
oracle: options.oracle,
|
|
@@ -28538,6 +28560,12 @@ var Sphere = class _Sphere {
|
|
|
28538
28560
|
* This method ensures the main bundle's TokenRegistry is properly configured.
|
|
28539
28561
|
*/
|
|
28540
28562
|
static configureTokenRegistry(storage, network) {
|
|
28563
|
+
if (!network) {
|
|
28564
|
+
logger.warn(
|
|
28565
|
+
"Sphere",
|
|
28566
|
+
"configureTokenRegistry: no network provided \u2014 defaulting to testnet. Pass options.network to avoid loading the wrong-network registry."
|
|
28567
|
+
);
|
|
28568
|
+
}
|
|
28541
28569
|
const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
|
|
28542
28570
|
TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
|
|
28543
28571
|
}
|
|
@@ -28689,7 +28717,8 @@ var Sphere = class _Sphere {
|
|
|
28689
28717
|
await options.storage.connect();
|
|
28690
28718
|
logger.debug("Sphere", "Storage reconnected");
|
|
28691
28719
|
}
|
|
28692
|
-
|
|
28720
|
+
_Sphere.configureTokenRegistry(options.storage, options.network);
|
|
28721
|
+
const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
|
|
28693
28722
|
const marketConfig = _Sphere.resolveMarketConfig(options.market);
|
|
28694
28723
|
const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
|
|
28695
28724
|
const swapConfig = _Sphere.resolveSwapConfig(options.swap);
|