@unicitylabs/sphere-sdk 0.1.7 → 0.1.9
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 +69 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +39 -3
- package/dist/core/index.d.ts +39 -3
- package/dist/core/index.js +69 -7
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +9 -6
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +9 -6
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +23 -6
- 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 +23 -6
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +69 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -11
- package/dist/index.d.ts +109 -11
- package/dist/index.js +69 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.cts
CHANGED
|
@@ -324,6 +324,15 @@ interface TokenBalance {
|
|
|
324
324
|
readonly tokenCount: number;
|
|
325
325
|
readonly decimals: number;
|
|
326
326
|
}
|
|
327
|
+
interface Asset {
|
|
328
|
+
readonly coinId: string;
|
|
329
|
+
readonly symbol: string;
|
|
330
|
+
readonly name: string;
|
|
331
|
+
readonly decimals: number;
|
|
332
|
+
readonly iconUrl?: string;
|
|
333
|
+
readonly totalAmount: string;
|
|
334
|
+
readonly tokenCount: number;
|
|
335
|
+
}
|
|
327
336
|
type TransferStatus = 'pending' | 'submitted' | 'confirmed' | 'delivered' | 'completed' | 'failed';
|
|
328
337
|
interface TransferRequest {
|
|
329
338
|
readonly coinId: string;
|
|
@@ -1468,6 +1477,11 @@ declare class PaymentsModule {
|
|
|
1468
1477
|
* Get balance for coin type
|
|
1469
1478
|
*/
|
|
1470
1479
|
getBalance(coinId?: string): TokenBalance[];
|
|
1480
|
+
/**
|
|
1481
|
+
* Get aggregated assets (tokens grouped by coinId)
|
|
1482
|
+
* Only includes confirmed tokens
|
|
1483
|
+
*/
|
|
1484
|
+
getAssets(coinId?: string): Asset[];
|
|
1471
1485
|
/**
|
|
1472
1486
|
* Get all tokens
|
|
1473
1487
|
*/
|
|
@@ -1924,6 +1938,8 @@ declare class Sphere {
|
|
|
1924
1938
|
private _currentAddressIndex;
|
|
1925
1939
|
/** Map of addressId -> (nametagIndex -> nametag). Supports multiple nametags per address (e.g., from Nostr recovery) */
|
|
1926
1940
|
private _addressNametags;
|
|
1941
|
+
/** Cached PROXY address (computed once when nametag is set) */
|
|
1942
|
+
private _cachedProxyAddress;
|
|
1927
1943
|
private _storage;
|
|
1928
1944
|
private _tokenStorageProviders;
|
|
1929
1945
|
private _transport;
|
|
@@ -1975,10 +1991,28 @@ declare class Sphere {
|
|
|
1975
1991
|
*/
|
|
1976
1992
|
static import(options: SphereImportOptions): Promise<Sphere>;
|
|
1977
1993
|
/**
|
|
1978
|
-
* Clear wallet data from storage
|
|
1979
|
-
*
|
|
1994
|
+
* Clear all SDK-owned wallet data from storage.
|
|
1995
|
+
*
|
|
1996
|
+
* Removes wallet keys, per-address data, and optionally token storage.
|
|
1997
|
+
* Does NOT affect application-level data stored outside the SDK.
|
|
1998
|
+
*
|
|
1999
|
+
* @param storageOrOptions - StorageProvider (backward compatible) or options object
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* // New usage (recommended) - clears wallet keys AND token data
|
|
2003
|
+
* await Sphere.clear({
|
|
2004
|
+
* storage: providers.storage,
|
|
2005
|
+
* tokenStorage: providers.tokenStorage,
|
|
2006
|
+
* });
|
|
2007
|
+
*
|
|
2008
|
+
* @example
|
|
2009
|
+
* // Legacy usage - clears only wallet keys
|
|
2010
|
+
* await Sphere.clear(storage);
|
|
1980
2011
|
*/
|
|
1981
|
-
static clear(
|
|
2012
|
+
static clear(storageOrOptions: StorageProvider | {
|
|
2013
|
+
storage: StorageProvider;
|
|
2014
|
+
tokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
|
|
2015
|
+
}): Promise<void>;
|
|
1982
2016
|
/**
|
|
1983
2017
|
* Get current instance
|
|
1984
2018
|
*/
|
|
@@ -2322,6 +2356,8 @@ declare class Sphere {
|
|
|
2322
2356
|
* @returns PROXY address string or undefined if no nametag
|
|
2323
2357
|
*/
|
|
2324
2358
|
getProxyAddress(): string | undefined;
|
|
2359
|
+
/** Compute and cache the PROXY address from the current nametag */
|
|
2360
|
+
private _updateCachedProxyAddress;
|
|
2325
2361
|
/**
|
|
2326
2362
|
* Register a nametag for the current active address
|
|
2327
2363
|
* Each address can have its own independent nametag
|
package/dist/core/index.d.ts
CHANGED
|
@@ -324,6 +324,15 @@ interface TokenBalance {
|
|
|
324
324
|
readonly tokenCount: number;
|
|
325
325
|
readonly decimals: number;
|
|
326
326
|
}
|
|
327
|
+
interface Asset {
|
|
328
|
+
readonly coinId: string;
|
|
329
|
+
readonly symbol: string;
|
|
330
|
+
readonly name: string;
|
|
331
|
+
readonly decimals: number;
|
|
332
|
+
readonly iconUrl?: string;
|
|
333
|
+
readonly totalAmount: string;
|
|
334
|
+
readonly tokenCount: number;
|
|
335
|
+
}
|
|
327
336
|
type TransferStatus = 'pending' | 'submitted' | 'confirmed' | 'delivered' | 'completed' | 'failed';
|
|
328
337
|
interface TransferRequest {
|
|
329
338
|
readonly coinId: string;
|
|
@@ -1468,6 +1477,11 @@ declare class PaymentsModule {
|
|
|
1468
1477
|
* Get balance for coin type
|
|
1469
1478
|
*/
|
|
1470
1479
|
getBalance(coinId?: string): TokenBalance[];
|
|
1480
|
+
/**
|
|
1481
|
+
* Get aggregated assets (tokens grouped by coinId)
|
|
1482
|
+
* Only includes confirmed tokens
|
|
1483
|
+
*/
|
|
1484
|
+
getAssets(coinId?: string): Asset[];
|
|
1471
1485
|
/**
|
|
1472
1486
|
* Get all tokens
|
|
1473
1487
|
*/
|
|
@@ -1924,6 +1938,8 @@ declare class Sphere {
|
|
|
1924
1938
|
private _currentAddressIndex;
|
|
1925
1939
|
/** Map of addressId -> (nametagIndex -> nametag). Supports multiple nametags per address (e.g., from Nostr recovery) */
|
|
1926
1940
|
private _addressNametags;
|
|
1941
|
+
/** Cached PROXY address (computed once when nametag is set) */
|
|
1942
|
+
private _cachedProxyAddress;
|
|
1927
1943
|
private _storage;
|
|
1928
1944
|
private _tokenStorageProviders;
|
|
1929
1945
|
private _transport;
|
|
@@ -1975,10 +1991,28 @@ declare class Sphere {
|
|
|
1975
1991
|
*/
|
|
1976
1992
|
static import(options: SphereImportOptions): Promise<Sphere>;
|
|
1977
1993
|
/**
|
|
1978
|
-
* Clear wallet data from storage
|
|
1979
|
-
*
|
|
1994
|
+
* Clear all SDK-owned wallet data from storage.
|
|
1995
|
+
*
|
|
1996
|
+
* Removes wallet keys, per-address data, and optionally token storage.
|
|
1997
|
+
* Does NOT affect application-level data stored outside the SDK.
|
|
1998
|
+
*
|
|
1999
|
+
* @param storageOrOptions - StorageProvider (backward compatible) or options object
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* // New usage (recommended) - clears wallet keys AND token data
|
|
2003
|
+
* await Sphere.clear({
|
|
2004
|
+
* storage: providers.storage,
|
|
2005
|
+
* tokenStorage: providers.tokenStorage,
|
|
2006
|
+
* });
|
|
2007
|
+
*
|
|
2008
|
+
* @example
|
|
2009
|
+
* // Legacy usage - clears only wallet keys
|
|
2010
|
+
* await Sphere.clear(storage);
|
|
1980
2011
|
*/
|
|
1981
|
-
static clear(
|
|
2012
|
+
static clear(storageOrOptions: StorageProvider | {
|
|
2013
|
+
storage: StorageProvider;
|
|
2014
|
+
tokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
|
|
2015
|
+
}): Promise<void>;
|
|
1982
2016
|
/**
|
|
1983
2017
|
* Get current instance
|
|
1984
2018
|
*/
|
|
@@ -2322,6 +2356,8 @@ declare class Sphere {
|
|
|
2322
2356
|
* @returns PROXY address string or undefined if no nametag
|
|
2323
2357
|
*/
|
|
2324
2358
|
getProxyAddress(): string | undefined;
|
|
2359
|
+
/** Compute and cache the PROXY address from the current nametag */
|
|
2360
|
+
private _updateCachedProxyAddress;
|
|
2325
2361
|
/**
|
|
2326
2362
|
* Register a nametag for the current active address
|
|
2327
2363
|
* Each address can have its own independent nametag
|
package/dist/core/index.js
CHANGED
|
@@ -3718,6 +3718,34 @@ var PaymentsModule = class {
|
|
|
3718
3718
|
}
|
|
3719
3719
|
return Array.from(balances.values());
|
|
3720
3720
|
}
|
|
3721
|
+
/**
|
|
3722
|
+
* Get aggregated assets (tokens grouped by coinId)
|
|
3723
|
+
* Only includes confirmed tokens
|
|
3724
|
+
*/
|
|
3725
|
+
getAssets(coinId) {
|
|
3726
|
+
const assets = /* @__PURE__ */ new Map();
|
|
3727
|
+
for (const token of this.tokens.values()) {
|
|
3728
|
+
if (token.status !== "confirmed") continue;
|
|
3729
|
+
if (coinId && token.coinId !== coinId) continue;
|
|
3730
|
+
const key = token.coinId;
|
|
3731
|
+
const existing = assets.get(key);
|
|
3732
|
+
if (existing) {
|
|
3733
|
+
existing.totalAmount = (BigInt(existing.totalAmount) + BigInt(token.amount)).toString();
|
|
3734
|
+
existing.tokenCount++;
|
|
3735
|
+
} else {
|
|
3736
|
+
assets.set(key, {
|
|
3737
|
+
coinId: token.coinId,
|
|
3738
|
+
symbol: token.symbol,
|
|
3739
|
+
name: token.name,
|
|
3740
|
+
decimals: token.decimals,
|
|
3741
|
+
iconUrl: token.iconUrl,
|
|
3742
|
+
totalAmount: token.amount,
|
|
3743
|
+
tokenCount: 1
|
|
3744
|
+
});
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
return Array.from(assets.values());
|
|
3748
|
+
}
|
|
3721
3749
|
/**
|
|
3722
3750
|
* Get all tokens
|
|
3723
3751
|
*/
|
|
@@ -5819,7 +5847,6 @@ import { SigningService as SigningService2 } from "@unicitylabs/state-transition
|
|
|
5819
5847
|
import { TokenType as TokenType2 } from "@unicitylabs/state-transition-sdk/lib/token/TokenType";
|
|
5820
5848
|
import { HashAlgorithm as HashAlgorithm4 } from "@unicitylabs/state-transition-sdk/lib/hash/HashAlgorithm";
|
|
5821
5849
|
import { UnmaskedPredicateReference as UnmaskedPredicateReference2 } from "@unicitylabs/state-transition-sdk/lib/predicate/embedded/UnmaskedPredicateReference";
|
|
5822
|
-
import { hashNametag } from "@unicitylabs/nostr-js-sdk";
|
|
5823
5850
|
var UNICITY_TOKEN_TYPE_HEX2 = "f8aa13834268d29355ff12183066f0cb902003629bbc5eb9ef0efbe397867509";
|
|
5824
5851
|
async function deriveL3PredicateAddress(privateKey) {
|
|
5825
5852
|
const secret = Buffer.from(privateKey, "hex");
|
|
@@ -5848,6 +5875,8 @@ var Sphere = class _Sphere {
|
|
|
5848
5875
|
_currentAddressIndex = 0;
|
|
5849
5876
|
/** Map of addressId -> (nametagIndex -> nametag). Supports multiple nametags per address (e.g., from Nostr recovery) */
|
|
5850
5877
|
_addressNametags = /* @__PURE__ */ new Map();
|
|
5878
|
+
/** Cached PROXY address (computed once when nametag is set) */
|
|
5879
|
+
_cachedProxyAddress = void 0;
|
|
5851
5880
|
// Providers
|
|
5852
5881
|
_storage;
|
|
5853
5882
|
_tokenStorageProviders = /* @__PURE__ */ new Map();
|
|
@@ -6012,7 +6041,7 @@ var Sphere = class _Sphere {
|
|
|
6012
6041
|
if (!options.mnemonic && !options.masterKey) {
|
|
6013
6042
|
throw new Error("Either mnemonic or masterKey is required");
|
|
6014
6043
|
}
|
|
6015
|
-
await _Sphere.clear(options.storage);
|
|
6044
|
+
await _Sphere.clear({ storage: options.storage, tokenStorage: options.tokenStorage });
|
|
6016
6045
|
const sphere = new _Sphere(
|
|
6017
6046
|
options.storage,
|
|
6018
6047
|
options.transport,
|
|
@@ -6054,10 +6083,27 @@ var Sphere = class _Sphere {
|
|
|
6054
6083
|
return sphere;
|
|
6055
6084
|
}
|
|
6056
6085
|
/**
|
|
6057
|
-
* Clear wallet data from storage
|
|
6058
|
-
*
|
|
6086
|
+
* Clear all SDK-owned wallet data from storage.
|
|
6087
|
+
*
|
|
6088
|
+
* Removes wallet keys, per-address data, and optionally token storage.
|
|
6089
|
+
* Does NOT affect application-level data stored outside the SDK.
|
|
6090
|
+
*
|
|
6091
|
+
* @param storageOrOptions - StorageProvider (backward compatible) or options object
|
|
6092
|
+
*
|
|
6093
|
+
* @example
|
|
6094
|
+
* // New usage (recommended) - clears wallet keys AND token data
|
|
6095
|
+
* await Sphere.clear({
|
|
6096
|
+
* storage: providers.storage,
|
|
6097
|
+
* tokenStorage: providers.tokenStorage,
|
|
6098
|
+
* });
|
|
6099
|
+
*
|
|
6100
|
+
* @example
|
|
6101
|
+
* // Legacy usage - clears only wallet keys
|
|
6102
|
+
* await Sphere.clear(storage);
|
|
6059
6103
|
*/
|
|
6060
|
-
static async clear(
|
|
6104
|
+
static async clear(storageOrOptions) {
|
|
6105
|
+
const storage = "get" in storageOrOptions ? storageOrOptions : storageOrOptions.storage;
|
|
6106
|
+
const tokenStorage = "get" in storageOrOptions ? void 0 : storageOrOptions.tokenStorage;
|
|
6061
6107
|
await storage.remove(STORAGE_KEYS_GLOBAL.MNEMONIC);
|
|
6062
6108
|
await storage.remove(STORAGE_KEYS_GLOBAL.MASTER_KEY);
|
|
6063
6109
|
await storage.remove(STORAGE_KEYS_GLOBAL.CHAIN_CODE);
|
|
@@ -6069,6 +6115,9 @@ var Sphere = class _Sphere {
|
|
|
6069
6115
|
await storage.remove(STORAGE_KEYS_GLOBAL.ADDRESS_NAMETAGS);
|
|
6070
6116
|
await storage.remove(STORAGE_KEYS_ADDRESS.PENDING_TRANSFERS);
|
|
6071
6117
|
await storage.remove(STORAGE_KEYS_ADDRESS.OUTBOX);
|
|
6118
|
+
if (tokenStorage?.clear) {
|
|
6119
|
+
await tokenStorage.clear();
|
|
6120
|
+
}
|
|
6072
6121
|
if (_Sphere.instance) {
|
|
6073
6122
|
await _Sphere.instance.destroy();
|
|
6074
6123
|
}
|
|
@@ -6752,6 +6801,7 @@ var Sphere = class _Sphere {
|
|
|
6752
6801
|
nametag
|
|
6753
6802
|
};
|
|
6754
6803
|
this._currentAddressIndex = index;
|
|
6804
|
+
await this._updateCachedProxyAddress();
|
|
6755
6805
|
await this._storage.set(STORAGE_KEYS_GLOBAL.CURRENT_ADDRESS_INDEX, index.toString());
|
|
6756
6806
|
this._storage.setIdentity(this._identity);
|
|
6757
6807
|
this._transport.setIdentity(this._identity);
|
|
@@ -6949,9 +6999,18 @@ var Sphere = class _Sphere {
|
|
|
6949
6999
|
* @returns PROXY address string or undefined if no nametag
|
|
6950
7000
|
*/
|
|
6951
7001
|
getProxyAddress() {
|
|
7002
|
+
return this._cachedProxyAddress;
|
|
7003
|
+
}
|
|
7004
|
+
/** Compute and cache the PROXY address from the current nametag */
|
|
7005
|
+
async _updateCachedProxyAddress() {
|
|
6952
7006
|
const nametag = this._identity?.nametag;
|
|
6953
|
-
if (!nametag)
|
|
6954
|
-
|
|
7007
|
+
if (!nametag) {
|
|
7008
|
+
this._cachedProxyAddress = void 0;
|
|
7009
|
+
return;
|
|
7010
|
+
}
|
|
7011
|
+
const { ProxyAddress } = await import("@unicitylabs/state-transition-sdk/lib/address/ProxyAddress");
|
|
7012
|
+
const proxyAddr = await ProxyAddress.fromNameTag(nametag);
|
|
7013
|
+
this._cachedProxyAddress = proxyAddr.toString();
|
|
6955
7014
|
}
|
|
6956
7015
|
/**
|
|
6957
7016
|
* Register a nametag for the current active address
|
|
@@ -6991,6 +7050,7 @@ var Sphere = class _Sphere {
|
|
|
6991
7050
|
}
|
|
6992
7051
|
}
|
|
6993
7052
|
this._identity.nametag = cleanNametag;
|
|
7053
|
+
await this._updateCachedProxyAddress();
|
|
6994
7054
|
const addressId = this.getCurrentAddressId();
|
|
6995
7055
|
if (addressId) {
|
|
6996
7056
|
let nametagsMap = this._addressNametags.get(addressId);
|
|
@@ -7131,6 +7191,7 @@ var Sphere = class _Sphere {
|
|
|
7131
7191
|
if (recoveredNametag) {
|
|
7132
7192
|
if (this._identity) {
|
|
7133
7193
|
this._identity.nametag = recoveredNametag;
|
|
7194
|
+
await this._updateCachedProxyAddress();
|
|
7134
7195
|
}
|
|
7135
7196
|
const addressId = this.getCurrentAddressId();
|
|
7136
7197
|
if (addressId) {
|
|
@@ -7298,6 +7359,7 @@ var Sphere = class _Sphere {
|
|
|
7298
7359
|
this._identity.nametag = nametag;
|
|
7299
7360
|
}
|
|
7300
7361
|
}
|
|
7362
|
+
await this._updateCachedProxyAddress();
|
|
7301
7363
|
}
|
|
7302
7364
|
async initializeIdentityFromMnemonic(mnemonic, derivationPath) {
|
|
7303
7365
|
const basePath = derivationPath ?? DEFAULT_BASE_PATH;
|