@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/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
|
}
|
|
@@ -9394,7 +9409,8 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
9394
9409
|
try {
|
|
9395
9410
|
const peerInfo = await this.deps.transport.resolve?.(request.recipient) ?? null;
|
|
9396
9411
|
const recipientPubkey = this.resolveTransportPubkey(request.recipient, peerInfo);
|
|
9397
|
-
const
|
|
9412
|
+
const willUseEngine = !!(this.deps?.tokenEngine && peerInfo?.chainPubkey);
|
|
9413
|
+
const recipientAddress = willUseEngine ? null : await this.resolveRecipientAddress(request.recipient, request.addressMode, peerInfo);
|
|
9398
9414
|
const signingService = await this.createSigningService();
|
|
9399
9415
|
const stClient = this.deps.oracle.getStateTransitionClient?.();
|
|
9400
9416
|
if (!stClient) {
|
|
@@ -9518,6 +9534,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
9518
9534
|
splitPlan.remainderAmount,
|
|
9519
9535
|
splitPlan.coinId,
|
|
9520
9536
|
recipientAddress,
|
|
9537
|
+
// v1 path only — non-null (would have thrown in resolve otherwise)
|
|
9521
9538
|
onChainMessage
|
|
9522
9539
|
);
|
|
9523
9540
|
committedOnChainTokenIds.add(splitPlan.tokenToSplit.uiToken.id);
|
|
@@ -9598,6 +9615,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
9598
9615
|
splitPlan.remainderAmount,
|
|
9599
9616
|
splitPlan.coinId,
|
|
9600
9617
|
recipientAddress,
|
|
9618
|
+
// v1 path only — non-null (would have thrown in resolve otherwise)
|
|
9601
9619
|
{
|
|
9602
9620
|
memo: request.memo,
|
|
9603
9621
|
message: onChainMessage,
|
|
@@ -12594,7 +12612,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
12594
12612
|
const nametag = recipient.startsWith("@") ? recipient.slice(1) : info.nametag || recipient;
|
|
12595
12613
|
if (!info.directAddress) {
|
|
12596
12614
|
throw new SphereError(
|
|
12597
|
-
`"${nametag}" has no
|
|
12615
|
+
`"${nametag}" has no published identity \u2014 the recipient must register a Unicity ID (publish a key-based identity binding) before they can receive payments.`,
|
|
12598
12616
|
"INVALID_RECIPIENT"
|
|
12599
12617
|
);
|
|
12600
12618
|
}
|
|
@@ -27981,6 +27999,8 @@ var Sphere = class _Sphere {
|
|
|
27981
27999
|
const walletExists = await _Sphere.exists(options.storage);
|
|
27982
28000
|
if (walletExists) {
|
|
27983
28001
|
const sphere2 = await _Sphere.load({
|
|
28002
|
+
network: options.network,
|
|
28003
|
+
// forward network so load's configureTokenRegistry uses it (not the testnet default)
|
|
27984
28004
|
storage: options.storage,
|
|
27985
28005
|
transport: options.transport,
|
|
27986
28006
|
oracle: options.oracle,
|
|
@@ -28015,6 +28035,8 @@ var Sphere = class _Sphere {
|
|
|
28015
28035
|
}
|
|
28016
28036
|
const sphere = await _Sphere.create({
|
|
28017
28037
|
mnemonic,
|
|
28038
|
+
network: options.network,
|
|
28039
|
+
// forward network so create's configureTokenRegistry uses it (not the testnet default)
|
|
28018
28040
|
storage: options.storage,
|
|
28019
28041
|
transport: options.transport,
|
|
28020
28042
|
oracle: options.oracle,
|
|
@@ -28102,6 +28124,12 @@ var Sphere = class _Sphere {
|
|
|
28102
28124
|
* This method ensures the main bundle's TokenRegistry is properly configured.
|
|
28103
28125
|
*/
|
|
28104
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
|
+
}
|
|
28105
28133
|
const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
|
|
28106
28134
|
TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
|
|
28107
28135
|
}
|
|
@@ -28253,7 +28281,8 @@ var Sphere = class _Sphere {
|
|
|
28253
28281
|
await options.storage.connect();
|
|
28254
28282
|
logger.debug("Sphere", "Storage reconnected");
|
|
28255
28283
|
}
|
|
28256
|
-
|
|
28284
|
+
_Sphere.configureTokenRegistry(options.storage, options.network);
|
|
28285
|
+
const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
|
|
28257
28286
|
const marketConfig = _Sphere.resolveMarketConfig(options.market);
|
|
28258
28287
|
const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
|
|
28259
28288
|
const swapConfig = _Sphere.resolveSwapConfig(options.swap);
|