@unicitylabs/sphere-sdk 0.5.2 → 0.5.3
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 +54 -2
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +8 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +54 -2
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +6 -1
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +6 -1
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +6 -1
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +6 -1
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +6 -1
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +1 -0
- package/dist/impl/nodejs/index.d.ts +1 -0
- package/dist/impl/nodejs/index.js +6 -1
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +54 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +54 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -2601,7 +2601,7 @@ init_constants();
|
|
|
2601
2601
|
// types/txf.ts
|
|
2602
2602
|
var ARCHIVED_PREFIX = "archived-";
|
|
2603
2603
|
var FORKED_PREFIX = "_forked_";
|
|
2604
|
-
var RESERVED_KEYS = ["_meta", "_nametag", "_nametags", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity"];
|
|
2604
|
+
var RESERVED_KEYS = ["_meta", "_nametag", "_nametags", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity", "_history"];
|
|
2605
2605
|
function isTokenKey(key) {
|
|
2606
2606
|
return key.startsWith("_") && !key.startsWith(ARCHIVED_PREFIX) && !key.startsWith(FORKED_PREFIX) && !RESERVED_KEYS.includes(key);
|
|
2607
2607
|
}
|
|
@@ -3186,6 +3186,9 @@ async function buildTxfStorageData(tokens, meta, options) {
|
|
|
3186
3186
|
if (options?.invalidatedNametags && options.invalidatedNametags.length > 0) {
|
|
3187
3187
|
storageData._invalidatedNametags = options.invalidatedNametags;
|
|
3188
3188
|
}
|
|
3189
|
+
if (options?.historyEntries && options.historyEntries.length > 0) {
|
|
3190
|
+
storageData._history = options.historyEntries;
|
|
3191
|
+
}
|
|
3189
3192
|
for (const token of tokens) {
|
|
3190
3193
|
const txf = tokenToTxf(token);
|
|
3191
3194
|
if (txf) {
|
|
@@ -3219,6 +3222,7 @@ function parseTxfStorageData(data) {
|
|
|
3219
3222
|
outboxEntries: [],
|
|
3220
3223
|
mintOutboxEntries: [],
|
|
3221
3224
|
invalidatedNametags: [],
|
|
3225
|
+
historyEntries: [],
|
|
3222
3226
|
validationErrors: []
|
|
3223
3227
|
};
|
|
3224
3228
|
if (!data || typeof data !== "object") {
|
|
@@ -3272,6 +3276,13 @@ function parseTxfStorageData(data) {
|
|
|
3272
3276
|
}
|
|
3273
3277
|
}
|
|
3274
3278
|
}
|
|
3279
|
+
if (Array.isArray(storageData._history)) {
|
|
3280
|
+
for (const entry of storageData._history) {
|
|
3281
|
+
if (typeof entry === "object" && entry !== null && typeof entry.dedupKey === "string" && typeof entry.type === "string") {
|
|
3282
|
+
result.historyEntries.push(entry);
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3275
3286
|
for (const key of Object.keys(storageData)) {
|
|
3276
3287
|
if (isTokenKey(key)) {
|
|
3277
3288
|
const tokenId = tokenIdFromKey(key);
|
|
@@ -4110,6 +4121,7 @@ function computeHistoryDedupKey(type, tokenId, transferId) {
|
|
|
4110
4121
|
if (tokenId) return `${type}_${tokenId}`;
|
|
4111
4122
|
return `${type}_${crypto.randomUUID()}`;
|
|
4112
4123
|
}
|
|
4124
|
+
var MAX_SYNCED_HISTORY_ENTRIES = 5e3;
|
|
4113
4125
|
function enrichWithRegistry(info) {
|
|
4114
4126
|
const registry = TokenRegistry.getInstance();
|
|
4115
4127
|
const def = registry.getDefinition(info.coinId);
|
|
@@ -4534,6 +4546,10 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
4534
4546
|
const result = await provider.load();
|
|
4535
4547
|
if (result.success && result.data) {
|
|
4536
4548
|
this.loadFromStorageData(result.data);
|
|
4549
|
+
const txfData = result.data;
|
|
4550
|
+
if (txfData._history && txfData._history.length > 0) {
|
|
4551
|
+
await this.importRemoteHistoryEntries(txfData._history);
|
|
4552
|
+
}
|
|
4537
4553
|
this.log(`Loaded metadata from provider ${id}`);
|
|
4538
4554
|
break;
|
|
4539
4555
|
}
|
|
@@ -6906,6 +6922,33 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
6906
6922
|
}
|
|
6907
6923
|
}
|
|
6908
6924
|
}
|
|
6925
|
+
/**
|
|
6926
|
+
* Import history entries from remote TXF data into local store.
|
|
6927
|
+
* Delegates to the local TokenStorageProvider's importHistoryEntries() for
|
|
6928
|
+
* persistent storage, with in-memory fallback.
|
|
6929
|
+
* Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
|
|
6930
|
+
*/
|
|
6931
|
+
async importRemoteHistoryEntries(entries) {
|
|
6932
|
+
if (entries.length === 0) return 0;
|
|
6933
|
+
const provider = this.getLocalTokenStorageProvider();
|
|
6934
|
+
if (provider?.importHistoryEntries) {
|
|
6935
|
+
const imported2 = await provider.importHistoryEntries(entries);
|
|
6936
|
+
if (imported2 > 0) {
|
|
6937
|
+
this._historyCache = await provider.getHistoryEntries();
|
|
6938
|
+
}
|
|
6939
|
+
return imported2;
|
|
6940
|
+
}
|
|
6941
|
+
const existingKeys = new Set(this._historyCache.map((e) => e.dedupKey));
|
|
6942
|
+
let imported = 0;
|
|
6943
|
+
for (const entry of entries) {
|
|
6944
|
+
if (!existingKeys.has(entry.dedupKey)) {
|
|
6945
|
+
this._historyCache.push(entry);
|
|
6946
|
+
existingKeys.add(entry.dedupKey);
|
|
6947
|
+
imported++;
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
return imported;
|
|
6951
|
+
}
|
|
6909
6952
|
/**
|
|
6910
6953
|
* Get the first local token storage provider (for history operations).
|
|
6911
6954
|
*/
|
|
@@ -7153,6 +7196,13 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
7153
7196
|
if (this.nametags.length === 0 && savedNametags.length > 0) {
|
|
7154
7197
|
this.nametags = savedNametags;
|
|
7155
7198
|
}
|
|
7199
|
+
const txfData = result.merged;
|
|
7200
|
+
if (txfData._history && txfData._history.length > 0) {
|
|
7201
|
+
const imported = await this.importRemoteHistoryEntries(txfData._history);
|
|
7202
|
+
if (imported > 0) {
|
|
7203
|
+
this.log(`Imported ${imported} history entries from IPFS sync`);
|
|
7204
|
+
}
|
|
7205
|
+
}
|
|
7156
7206
|
totalAdded += result.added;
|
|
7157
7207
|
totalRemoved += result.removed;
|
|
7158
7208
|
}
|
|
@@ -7860,6 +7910,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
7860
7910
|
return data ? JSON.parse(data) : [];
|
|
7861
7911
|
}
|
|
7862
7912
|
async createStorageData() {
|
|
7913
|
+
const sorted = [...this._historyCache].sort((a, b) => b.timestamp - a.timestamp);
|
|
7863
7914
|
return await buildTxfStorageData(
|
|
7864
7915
|
Array.from(this.tokens.values()),
|
|
7865
7916
|
{
|
|
@@ -7871,7 +7922,8 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
7871
7922
|
nametags: this.nametags,
|
|
7872
7923
|
tombstones: this.tombstones,
|
|
7873
7924
|
archivedTokens: this.archivedTokens,
|
|
7874
|
-
forkedTokens: this.forkedTokens
|
|
7925
|
+
forkedTokens: this.forkedTokens,
|
|
7926
|
+
historyEntries: sorted.slice(0, MAX_SYNCED_HISTORY_ENTRIES)
|
|
7875
7927
|
}
|
|
7876
7928
|
);
|
|
7877
7929
|
}
|