@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/index.d.cts
CHANGED
|
@@ -1671,6 +1671,7 @@ interface TxfStorageDataBase {
|
|
|
1671
1671
|
_outbox?: TxfOutboxEntry[];
|
|
1672
1672
|
_sent?: TxfSentEntry[];
|
|
1673
1673
|
_invalid?: TxfInvalidEntry[];
|
|
1674
|
+
_history?: HistoryRecord[];
|
|
1674
1675
|
[key: `_${string}`]: unknown;
|
|
1675
1676
|
}
|
|
1676
1677
|
interface TxfMeta {
|
|
@@ -3198,6 +3199,13 @@ declare class PaymentsModule {
|
|
|
3198
3199
|
* Also performs one-time migration from legacy KV storage.
|
|
3199
3200
|
*/
|
|
3200
3201
|
loadHistory(): Promise<void>;
|
|
3202
|
+
/**
|
|
3203
|
+
* Import history entries from remote TXF data into local store.
|
|
3204
|
+
* Delegates to the local TokenStorageProvider's importHistoryEntries() for
|
|
3205
|
+
* persistent storage, with in-memory fallback.
|
|
3206
|
+
* Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
|
|
3207
|
+
*/
|
|
3208
|
+
private importRemoteHistoryEntries;
|
|
3201
3209
|
/**
|
|
3202
3210
|
* Get the first local token storage provider (for history operations).
|
|
3203
3211
|
*/
|
|
@@ -5587,6 +5595,7 @@ declare function buildTxfStorageData(tokens: Token[], meta: Omit<TxfMeta$1, 'for
|
|
|
5587
5595
|
outboxEntries?: OutboxEntry[];
|
|
5588
5596
|
mintOutboxEntries?: MintOutboxEntry[];
|
|
5589
5597
|
invalidatedNametags?: InvalidatedNametagEntry[];
|
|
5598
|
+
historyEntries?: HistoryRecord[];
|
|
5590
5599
|
}): Promise<TxfStorageData>;
|
|
5591
5600
|
interface ParsedStorageData {
|
|
5592
5601
|
tokens: Token[];
|
|
@@ -5598,6 +5607,7 @@ interface ParsedStorageData {
|
|
|
5598
5607
|
outboxEntries: OutboxEntry[];
|
|
5599
5608
|
mintOutboxEntries: MintOutboxEntry[];
|
|
5600
5609
|
invalidatedNametags: InvalidatedNametagEntry[];
|
|
5610
|
+
historyEntries: HistoryRecord[];
|
|
5601
5611
|
validationErrors: string[];
|
|
5602
5612
|
}
|
|
5603
5613
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1671,6 +1671,7 @@ interface TxfStorageDataBase {
|
|
|
1671
1671
|
_outbox?: TxfOutboxEntry[];
|
|
1672
1672
|
_sent?: TxfSentEntry[];
|
|
1673
1673
|
_invalid?: TxfInvalidEntry[];
|
|
1674
|
+
_history?: HistoryRecord[];
|
|
1674
1675
|
[key: `_${string}`]: unknown;
|
|
1675
1676
|
}
|
|
1676
1677
|
interface TxfMeta {
|
|
@@ -3198,6 +3199,13 @@ declare class PaymentsModule {
|
|
|
3198
3199
|
* Also performs one-time migration from legacy KV storage.
|
|
3199
3200
|
*/
|
|
3200
3201
|
loadHistory(): Promise<void>;
|
|
3202
|
+
/**
|
|
3203
|
+
* Import history entries from remote TXF data into local store.
|
|
3204
|
+
* Delegates to the local TokenStorageProvider's importHistoryEntries() for
|
|
3205
|
+
* persistent storage, with in-memory fallback.
|
|
3206
|
+
* Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
|
|
3207
|
+
*/
|
|
3208
|
+
private importRemoteHistoryEntries;
|
|
3201
3209
|
/**
|
|
3202
3210
|
* Get the first local token storage provider (for history operations).
|
|
3203
3211
|
*/
|
|
@@ -5587,6 +5595,7 @@ declare function buildTxfStorageData(tokens: Token[], meta: Omit<TxfMeta$1, 'for
|
|
|
5587
5595
|
outboxEntries?: OutboxEntry[];
|
|
5588
5596
|
mintOutboxEntries?: MintOutboxEntry[];
|
|
5589
5597
|
invalidatedNametags?: InvalidatedNametagEntry[];
|
|
5598
|
+
historyEntries?: HistoryRecord[];
|
|
5590
5599
|
}): Promise<TxfStorageData>;
|
|
5591
5600
|
interface ParsedStorageData {
|
|
5592
5601
|
tokens: Token[];
|
|
@@ -5598,6 +5607,7 @@ interface ParsedStorageData {
|
|
|
5598
5607
|
outboxEntries: OutboxEntry[];
|
|
5599
5608
|
mintOutboxEntries: MintOutboxEntry[];
|
|
5600
5609
|
invalidatedNametags: InvalidatedNametagEntry[];
|
|
5610
|
+
historyEntries: HistoryRecord[];
|
|
5601
5611
|
validationErrors: string[];
|
|
5602
5612
|
}
|
|
5603
5613
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2713,7 +2713,7 @@ init_constants();
|
|
|
2713
2713
|
// types/txf.ts
|
|
2714
2714
|
var ARCHIVED_PREFIX = "archived-";
|
|
2715
2715
|
var FORKED_PREFIX = "_forked_";
|
|
2716
|
-
var RESERVED_KEYS = ["_meta", "_nametag", "_nametags", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity"];
|
|
2716
|
+
var RESERVED_KEYS = ["_meta", "_nametag", "_nametags", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity", "_history"];
|
|
2717
2717
|
function isTokenKey(key) {
|
|
2718
2718
|
return key.startsWith("_") && !key.startsWith(ARCHIVED_PREFIX) && !key.startsWith(FORKED_PREFIX) && !RESERVED_KEYS.includes(key);
|
|
2719
2719
|
}
|
|
@@ -3335,6 +3335,9 @@ async function buildTxfStorageData(tokens, meta, options) {
|
|
|
3335
3335
|
if (options?.invalidatedNametags && options.invalidatedNametags.length > 0) {
|
|
3336
3336
|
storageData._invalidatedNametags = options.invalidatedNametags;
|
|
3337
3337
|
}
|
|
3338
|
+
if (options?.historyEntries && options.historyEntries.length > 0) {
|
|
3339
|
+
storageData._history = options.historyEntries;
|
|
3340
|
+
}
|
|
3338
3341
|
for (const token of tokens) {
|
|
3339
3342
|
const txf = tokenToTxf(token);
|
|
3340
3343
|
if (txf) {
|
|
@@ -3368,6 +3371,7 @@ function parseTxfStorageData(data) {
|
|
|
3368
3371
|
outboxEntries: [],
|
|
3369
3372
|
mintOutboxEntries: [],
|
|
3370
3373
|
invalidatedNametags: [],
|
|
3374
|
+
historyEntries: [],
|
|
3371
3375
|
validationErrors: []
|
|
3372
3376
|
};
|
|
3373
3377
|
if (!data || typeof data !== "object") {
|
|
@@ -3421,6 +3425,13 @@ function parseTxfStorageData(data) {
|
|
|
3421
3425
|
}
|
|
3422
3426
|
}
|
|
3423
3427
|
}
|
|
3428
|
+
if (Array.isArray(storageData._history)) {
|
|
3429
|
+
for (const entry of storageData._history) {
|
|
3430
|
+
if (typeof entry === "object" && entry !== null && typeof entry.dedupKey === "string" && typeof entry.type === "string") {
|
|
3431
|
+
result.historyEntries.push(entry);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3424
3435
|
for (const key of Object.keys(storageData)) {
|
|
3425
3436
|
if (isTokenKey(key)) {
|
|
3426
3437
|
const tokenId = tokenIdFromKey(key);
|
|
@@ -4310,6 +4321,7 @@ function computeHistoryDedupKey(type, tokenId, transferId) {
|
|
|
4310
4321
|
if (tokenId) return `${type}_${tokenId}`;
|
|
4311
4322
|
return `${type}_${crypto.randomUUID()}`;
|
|
4312
4323
|
}
|
|
4324
|
+
var MAX_SYNCED_HISTORY_ENTRIES = 5e3;
|
|
4313
4325
|
function enrichWithRegistry(info) {
|
|
4314
4326
|
const registry = TokenRegistry.getInstance();
|
|
4315
4327
|
const def = registry.getDefinition(info.coinId);
|
|
@@ -4734,6 +4746,10 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
4734
4746
|
const result = await provider.load();
|
|
4735
4747
|
if (result.success && result.data) {
|
|
4736
4748
|
this.loadFromStorageData(result.data);
|
|
4749
|
+
const txfData = result.data;
|
|
4750
|
+
if (txfData._history && txfData._history.length > 0) {
|
|
4751
|
+
await this.importRemoteHistoryEntries(txfData._history);
|
|
4752
|
+
}
|
|
4737
4753
|
this.log(`Loaded metadata from provider ${id}`);
|
|
4738
4754
|
break;
|
|
4739
4755
|
}
|
|
@@ -7106,6 +7122,33 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
7106
7122
|
}
|
|
7107
7123
|
}
|
|
7108
7124
|
}
|
|
7125
|
+
/**
|
|
7126
|
+
* Import history entries from remote TXF data into local store.
|
|
7127
|
+
* Delegates to the local TokenStorageProvider's importHistoryEntries() for
|
|
7128
|
+
* persistent storage, with in-memory fallback.
|
|
7129
|
+
* Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
|
|
7130
|
+
*/
|
|
7131
|
+
async importRemoteHistoryEntries(entries) {
|
|
7132
|
+
if (entries.length === 0) return 0;
|
|
7133
|
+
const provider = this.getLocalTokenStorageProvider();
|
|
7134
|
+
if (provider?.importHistoryEntries) {
|
|
7135
|
+
const imported2 = await provider.importHistoryEntries(entries);
|
|
7136
|
+
if (imported2 > 0) {
|
|
7137
|
+
this._historyCache = await provider.getHistoryEntries();
|
|
7138
|
+
}
|
|
7139
|
+
return imported2;
|
|
7140
|
+
}
|
|
7141
|
+
const existingKeys = new Set(this._historyCache.map((e) => e.dedupKey));
|
|
7142
|
+
let imported = 0;
|
|
7143
|
+
for (const entry of entries) {
|
|
7144
|
+
if (!existingKeys.has(entry.dedupKey)) {
|
|
7145
|
+
this._historyCache.push(entry);
|
|
7146
|
+
existingKeys.add(entry.dedupKey);
|
|
7147
|
+
imported++;
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
return imported;
|
|
7151
|
+
}
|
|
7109
7152
|
/**
|
|
7110
7153
|
* Get the first local token storage provider (for history operations).
|
|
7111
7154
|
*/
|
|
@@ -7353,6 +7396,13 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
7353
7396
|
if (this.nametags.length === 0 && savedNametags.length > 0) {
|
|
7354
7397
|
this.nametags = savedNametags;
|
|
7355
7398
|
}
|
|
7399
|
+
const txfData = result.merged;
|
|
7400
|
+
if (txfData._history && txfData._history.length > 0) {
|
|
7401
|
+
const imported = await this.importRemoteHistoryEntries(txfData._history);
|
|
7402
|
+
if (imported > 0) {
|
|
7403
|
+
this.log(`Imported ${imported} history entries from IPFS sync`);
|
|
7404
|
+
}
|
|
7405
|
+
}
|
|
7356
7406
|
totalAdded += result.added;
|
|
7357
7407
|
totalRemoved += result.removed;
|
|
7358
7408
|
}
|
|
@@ -8060,6 +8110,7 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
8060
8110
|
return data ? JSON.parse(data) : [];
|
|
8061
8111
|
}
|
|
8062
8112
|
async createStorageData() {
|
|
8113
|
+
const sorted = [...this._historyCache].sort((a, b) => b.timestamp - a.timestamp);
|
|
8063
8114
|
return await buildTxfStorageData(
|
|
8064
8115
|
Array.from(this.tokens.values()),
|
|
8065
8116
|
{
|
|
@@ -8071,7 +8122,8 @@ var PaymentsModule = class _PaymentsModule {
|
|
|
8071
8122
|
nametags: this.nametags,
|
|
8072
8123
|
tombstones: this.tombstones,
|
|
8073
8124
|
archivedTokens: this.archivedTokens,
|
|
8074
|
-
forkedTokens: this.forkedTokens
|
|
8125
|
+
forkedTokens: this.forkedTokens,
|
|
8126
|
+
historyEntries: sorted.slice(0, MAX_SYNCED_HISTORY_ENTRIES)
|
|
8075
8127
|
}
|
|
8076
8128
|
);
|
|
8077
8129
|
}
|