@otoplo/wallet-common 0.6.0 → 0.7.0
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/index.d.ts +53 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -48
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/services/rostrum.ts +322 -274
- package/src/services/wallet.ts +762 -683
- package/src/types/rostrum.types.ts +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -325,6 +325,19 @@ interface RostrumParams {
|
|
|
325
325
|
port: number;
|
|
326
326
|
label: string;
|
|
327
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Whether the wallet can use a server, from `RostrumService.checkInstance()`:
|
|
330
|
+
* - `online`: reachable and usable, with the round-trip time of a request in milliseconds.
|
|
331
|
+
* - `offline`: couldn't connect, or it didn't answer.
|
|
332
|
+
* - `wrong_network`: it serves another network (e.g. testnet while the wallet is on mainnet).
|
|
333
|
+
* - `unsupported`: it doesn't index scripts (`script_index`), which the wallet needs.
|
|
334
|
+
*/
|
|
335
|
+
type RostrumInstanceCheck = {
|
|
336
|
+
status: 'online';
|
|
337
|
+
latency: number;
|
|
338
|
+
} | {
|
|
339
|
+
status: 'offline' | 'wrong_network' | 'unsupported';
|
|
340
|
+
};
|
|
328
341
|
interface ServerFeatures {
|
|
329
342
|
genesis_hash: string;
|
|
330
343
|
server_version: string;
|
|
@@ -458,6 +471,8 @@ export type RostrumUpdateCallback = (event: RostrumEvent) => void;
|
|
|
458
471
|
export declare class RostrumService {
|
|
459
472
|
private readonly walletDb;
|
|
460
473
|
private client?;
|
|
474
|
+
/** The server `client` connects to. */
|
|
475
|
+
private params?;
|
|
461
476
|
private updateCallback?;
|
|
462
477
|
constructor(walletDb: WalletDB);
|
|
463
478
|
onUpdate(callback: RostrumUpdateCallback): void;
|
|
@@ -481,6 +496,15 @@ export declare class RostrumService {
|
|
|
481
496
|
getLatency(): Promise<number>;
|
|
482
497
|
connect(params?: RostrumParams): Promise<void>;
|
|
483
498
|
disconnect(): Promise<void>;
|
|
499
|
+
/**
|
|
500
|
+
* Checks whether the wallet can use a server (e.g. before switching to it): that it's reachable, on the wallet's
|
|
501
|
+
* network and indexes scripts. Never throws.
|
|
502
|
+
*
|
|
503
|
+
* The server this service is connected to answers on its connection; any other one is checked on a temporary
|
|
504
|
+
* connection, closed after.
|
|
505
|
+
*/
|
|
506
|
+
checkInstance(params: RostrumParams): Promise<RostrumInstanceCheck>;
|
|
507
|
+
private check;
|
|
484
508
|
/**
|
|
485
509
|
* Walk a cursor-paginated rostrum query: start with "start" and follow the returned cursor until it is null.
|
|
486
510
|
* If the cursor expires mid-walk (e.g. reorg / mempool change), the walk is restarted from the beginning.
|
|
@@ -491,6 +515,8 @@ export declare class RostrumService {
|
|
|
491
515
|
setCurrentInstance(params: RostrumParams): Promise<void>;
|
|
492
516
|
resetCurrentInstance(): Promise<void>;
|
|
493
517
|
getCurrentInstance(): Promise<RostrumParams>;
|
|
518
|
+
/** Whether both point to the same server (the label aside). */
|
|
519
|
+
static isSameInstance(a: RostrumParams, b: RostrumParams): boolean;
|
|
494
520
|
static getPredefinedInstances(): RostrumParams[];
|
|
495
521
|
}
|
|
496
522
|
export declare class KeyManager {
|
|
@@ -687,6 +713,10 @@ export declare class WalletManager {
|
|
|
687
713
|
private readonly transactionService;
|
|
688
714
|
private readonly sessionManager;
|
|
689
715
|
private static readonly DEBOUNCE_MS;
|
|
716
|
+
/** Delay before the first `connect` retry, in milliseconds. Doubles after each failed attempt. */
|
|
717
|
+
private static readonly RETRY_DELAY_MS;
|
|
718
|
+
/** Upper bound for the delay between `connect` retries, in milliseconds. */
|
|
719
|
+
private static readonly MAX_RETRY_DELAY_MS;
|
|
690
720
|
accounts: Map<number, AccountDTO>;
|
|
691
721
|
accountsAddressToId: Map<string, number>;
|
|
692
722
|
receiveAddresses: AddressDTO[];
|
|
@@ -698,6 +728,9 @@ export declare class WalletManager {
|
|
|
698
728
|
private updateCallback?;
|
|
699
729
|
private isConnected;
|
|
700
730
|
private isSubscribed;
|
|
731
|
+
private connectionId;
|
|
732
|
+
private connecting?;
|
|
733
|
+
private retryNow?;
|
|
701
734
|
private readonly discoveryService;
|
|
702
735
|
constructor(keyManager: KeyManager, walletDb: WalletDB, rostrumService: RostrumService, assetService: AssetService, transactionService: TransactionService, sessionManager: SessionManager);
|
|
703
736
|
clear(): void;
|
|
@@ -708,8 +741,27 @@ export declare class WalletManager {
|
|
|
708
741
|
getReceiveAddress(accountId?: number): string;
|
|
709
742
|
getChangeAddress(accountId?: number): string;
|
|
710
743
|
getUsedAddressKeys(accountId?: number): AddressKey[];
|
|
744
|
+
/**
|
|
745
|
+
* Switches to another server (or reconnects to the current one without `params`): saves it, disconnects, then
|
|
746
|
+
* connects with `connect()`, retrying until it does. Check the server first with `RostrumService.checkInstance()`.
|
|
747
|
+
*
|
|
748
|
+
* @returns resolves like `connect()`: once connected and synced, or when stopped by `disconnectRostrum()`.
|
|
749
|
+
*/
|
|
711
750
|
reloadRostrum(params?: RostrumParams): Promise<void>;
|
|
712
751
|
initRostrum(): Promise<void>;
|
|
752
|
+
/**
|
|
753
|
+
* Connects and syncs the loaded wallet, retrying with exponential backoff until it succeeds or
|
|
754
|
+
* `disconnectRostrum()` is called. Never throws.
|
|
755
|
+
*
|
|
756
|
+
* Each attempt skips what's already done (connected, subscribed), so a retry continues where the last one failed.
|
|
757
|
+
* Calling it while waiting to retry makes the next attempt immediately (e.g. when the app returns to the foreground).
|
|
758
|
+
*
|
|
759
|
+
* For flows where the user is waiting on the result (e.g. discovery), use `initRostrum()`, which makes a single attempt.
|
|
760
|
+
*
|
|
761
|
+
* @returns resolves once connected and synced, or when stopped by `disconnectRostrum()`.
|
|
762
|
+
*/
|
|
763
|
+
connect(): Promise<void>;
|
|
764
|
+
private connectLoop;
|
|
713
765
|
disconnectRostrum(): Promise<void>;
|
|
714
766
|
discoverWallet(): Promise<void>;
|
|
715
767
|
loadWallet(): Promise<void>;
|
|
@@ -865,5 +917,5 @@ export declare function generateVaultAddress(pubKey: PublicKey, args: number[]):
|
|
|
865
917
|
export declare function estimateDateByFutureBlock(current: number, future: number): string;
|
|
866
918
|
export declare function keyPathToString(account: AccountType, type: KeySpace, index: number): string;
|
|
867
919
|
export declare function stringToKeyPath(path: string): KeyPath;
|
|
868
|
-
export type { Account, AccountDTO, AccountEntity, AddressDTO, AddressEntity, AddressKey, AppNotification, AssetBase, AssetEntity, AssetInfo, AssetMovement, AssetTransactionEntity, AssetType, Balance, BlockTip, DappRpcRequest, IFirstUse, IListUnspentRecord, IScriptPubKey, IScriptSig, ISpent, ITXHistory, ITXInput, ITXOutput, ITemplateScript, ITokenUtxo, ITokensBalance, ITransaction, IUtxo, KeyPath, MarketData, MovementDetails, NFTAsset, NftEntity, NotificationAction, RostrumParams, ServerFeatures, SessionEntity, SessionInfo, SettingEntity, TokenAsset, TokenEntity, TransactionDTO, TransactionDetails, TransactionEntity, TransactionType, VaultDTO, VaultEntity, VaultInfo };
|
|
920
|
+
export type { Account, AccountDTO, AccountEntity, AddressDTO, AddressEntity, AddressKey, AppNotification, AssetBase, AssetEntity, AssetInfo, AssetMovement, AssetTransactionEntity, AssetType, Balance, BlockTip, DappRpcRequest, IFirstUse, IListUnspentRecord, IScriptPubKey, IScriptSig, ISpent, ITXHistory, ITXInput, ITXOutput, ITemplateScript, ITokenUtxo, ITokensBalance, ITransaction, IUtxo, KeyPath, MarketData, MovementDetails, NFTAsset, NftEntity, NotificationAction, RostrumInstanceCheck, RostrumParams, ServerFeatures, SessionEntity, SessionInfo, SettingEntity, TokenAsset, TokenEntity, TransactionDTO, TransactionDetails, TransactionEntity, TransactionType, VaultDTO, VaultEntity, VaultInfo };
|
|
869
921
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils/enums.ts","../src/types/wallet.types.ts","../src/types/db.types.ts","../src/persistence/repository.ts","../src/persistence/wallet-db.ts","../src/services/cache.ts","../src/types/rostrum.types.ts","../src/services/rostrum.ts","../src/services/key.ts","../src/services/asset.ts","../src/services/transaction.ts","../src/types/dapp.types.ts","../src/types/notification.types.ts","../src/services/session.ts","../src/services/tx-transformer.ts","../src/services/wallet.ts","../src/utils/common.ts","../src/services/market.ts","../src/utils/asset.ts","../src/utils/seed.ts","../src/utils/vault.ts","../src/utils/keypath.ts"],"mappings":";;;oBAAY;EACV;EACA;EACA;;oBAGU;EACV;EACA;;oBAGU;EACV;EACA;EACA;EACA;;UCZe;EACf,SAAS;EACT,MAAM;EACN;;UAGe;EACf;EACA;EACA,SAAS;EACT,eAAe,eAAe;;UAGf;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,SAAS;EACT,eAAe,eAAe;EAC9B,UAAU,eAAe;;UAGV;EACf;EACA,SAAS;EACT;EACA;;UAGe;EACf,SAAS;EACT,SAAS;;UAGM;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;KAEA,aACP;EAAc;EAAe,MAAM;MACnC;EAAc;EAAa,MAAM;;UAErB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UClFe;EACf;EACA;EACA;EACA;;KAGU;UAEK;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA,eAAe;EACf,WAAW;EACX,UAAU;;UAGK;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,MAAM;EACN;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,SAAS;EACT,eAA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EAIZ,UAAU;;UChDF;EACf,QAAQ;EACR;EACA;EACA;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils/enums.ts","../src/types/wallet.types.ts","../src/types/db.types.ts","../src/persistence/repository.ts","../src/persistence/wallet-db.ts","../src/services/cache.ts","../src/types/rostrum.types.ts","../src/services/rostrum.ts","../src/services/key.ts","../src/services/asset.ts","../src/services/transaction.ts","../src/types/dapp.types.ts","../src/types/notification.types.ts","../src/services/session.ts","../src/services/tx-transformer.ts","../src/services/wallet.ts","../src/utils/common.ts","../src/services/market.ts","../src/utils/asset.ts","../src/utils/seed.ts","../src/utils/vault.ts","../src/utils/keypath.ts"],"mappings":";;;oBAAY;EACV;EACA;EACA;;oBAGU;EACV;EACA;;oBAGU;EACV;EACA;EACA;EACA;;UCZe;EACf,SAAS;EACT,MAAM;EACN;;UAGe;EACf;EACA;EACA,SAAS;EACT,eAAe,eAAe;;UAGf;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,SAAS;EACT,eAAe,eAAe;EAC9B,UAAU,eAAe;;UAGV;EACf;EACA,SAAS;EACT;EACA;;UAGe;EACf,SAAS;EACT,SAAS;;UAGM;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;KAEA,aACP;EAAc;EAAe,MAAM;MACnC;EAAc;EAAa,MAAM;;UAErB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UClFe;EACf;EACA;EACA;EACA;;KAGU;UAEK;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA,eAAe;EACf,WAAW;EACX,UAAU;;UAGK;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,MAAM;EACN;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf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,aAAa;wBAOb,eAAe;wBAOf,yBAAyB;wBAUzB,WAAW,UAAU,YAAY;wBASjC,iBAAiB,UAAU,eAAe,aAAa,eAAe;wBA0CtE,iBAAiB;wBAQjB,gBAAgB;wBAQhB,MAAM,aAAa;wBAInB,eAAe;wBAIf,mBAAmB,yBAAyB,eAAe,UAAU,cAAc;YCzJvF;EACN;EAA6B,UAAU;EAAc,MAAM,eAAe;;EAC1E;EAA0B,UAAU;;YAE9B,wBAAwB,OAAO;qBAE9B;0BAEa;0BACA;0BACA;mBAIP;UAET;UACA;UACA;UAEA;EAEW,YAAA,UAAU;EAItB,SAAS,UAAU;UAIlB;EAIK,QAAQ;EAWd;EAMA,eAAe;EAIT,YAAY,UAAU,eAAe;UAYpC;UAeN;UAQM;;wBC/GA,sBAAsB,cAAc;wBAcpC,kBAAkB;wBAiBlB,oBAAoB;wBAIpB,gBAAgB,eAAc;wBCjC9B,oBAAoB;wBAIpB,gBAAgB;wBA8BV,gBAAgB,gBAAgB,mBAAmB;wBA0CnD,2BAA2B,iBAAiB,mBAAmB;qBC7ExE;wBAEG,oBAAoB;wBAOpB,wBAAwB;wBAKxB,wBAAwB,QAAQ,YAAY;wBAI5C,uBAAuB,QAAQ,YAAY;wBAK3C,yBAAyB,iBAAiB;wBAI1C,qBAAqB,QAAQ,WAAW;wBAYxC,0BAA0B,iBAAiB;wBCvC3C,gBAAgB,SAAS,aAAa,MAAM,UAAU;wBAItD,gBAAgB,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -54,42 +54,42 @@ const ue = -1, de = 9223372036854775807n, S = {
|
|
|
54
54
|
function w() {
|
|
55
55
|
return s.defaultNetwork == s.testnet;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function T(e) {
|
|
58
58
|
return w() ? e == "508c843a4b98fb25f57cf9ebafb245a5c16468f06519cdd467059a91e7b79d52" : e == "edc7144fe1ba4edd0edf35d7eea90f6cb1dba42314aa85da8207e97c5339c801";
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function E(n, r = t.PayToScriptTemplate) {
|
|
61
61
|
return e.isValid(n, s.defaultNetwork, r);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function fe() {
|
|
64
64
|
return `https://${w() ? "testnet-" : ""}explorer.nexa.org`;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function D() {
|
|
67
67
|
return Math.floor(Date.now() / 1e3);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function O(e) {
|
|
70
70
|
return !e || e.length === 0;
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function pe(e, t = 0) {
|
|
73
73
|
if (!e || e.length <= t) return e || "";
|
|
74
74
|
let n = Math.floor((t - 3) / 2), r = e.slice(0, n), i = e.slice(e.length - n);
|
|
75
75
|
return r + "..." + i;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function me(e) {
|
|
78
78
|
return e.length === 0 ? "" : e.charAt(0).toUpperCase() + e.substring(1);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function k(t) {
|
|
81
81
|
return i.isHexa(t) ? n.hexToBuffer(t) : e.fromString(t).data;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return i.isHexa(e) ? e : n.bufferToHex(
|
|
83
|
+
function A(e) {
|
|
84
|
+
return i.isHexa(e) ? e : n.bufferToHex(k(e));
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return i.isHexa(n) ? new e(
|
|
86
|
+
function he(n) {
|
|
87
|
+
return i.isHexa(n) ? new e(k(n), s.defaultNetwork, t.GroupIdAddress).toString() : n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function j(e) {
|
|
90
90
|
return e == null || e === "" ? "" : BigInt(e) <= 0n ? "0" : e.toString();
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function M(e) {
|
|
93
93
|
let t = BigInt(0), n = BigInt(0);
|
|
94
94
|
return e.forEach((e) => {
|
|
95
95
|
t += BigInt(e.confirmed), n += BigInt(e.unconfirmed);
|
|
@@ -98,7 +98,7 @@ function j(e) {
|
|
|
98
98
|
unconfirmed: n.toString()
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function N(e) {
|
|
102
102
|
let t = {};
|
|
103
103
|
return e.forEach((e) => {
|
|
104
104
|
for (let n in e) t[n] ? (t[n].confirmed = (BigInt(t[n].confirmed) + BigInt(e[n].confirmed)).toString(), t[n].unconfirmed = (BigInt(t[n].unconfirmed) + BigInt(e[n].unconfirmed)).toString()) : t[n] = {
|
|
@@ -107,7 +107,7 @@ function M(e) {
|
|
|
107
107
|
};
|
|
108
108
|
}), t;
|
|
109
109
|
}
|
|
110
|
-
const
|
|
110
|
+
const P = {
|
|
111
111
|
".gif": {
|
|
112
112
|
media: "image",
|
|
113
113
|
mime: "image/gif"
|
|
@@ -177,17 +177,17 @@ const N = {
|
|
|
177
177
|
mime: "audio/mp4"
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
-
function
|
|
180
|
+
function ge(e) {
|
|
181
181
|
let t = e.lastIndexOf(".");
|
|
182
182
|
if (t === -1) return "unknown";
|
|
183
183
|
let n = e.slice(t).toLowerCase();
|
|
184
|
-
return
|
|
184
|
+
return P[n]?.media ?? "unknown";
|
|
185
185
|
}
|
|
186
186
|
function F(e) {
|
|
187
187
|
let t = e.lastIndexOf(".");
|
|
188
188
|
if (t === -1) return "application/octet-stream";
|
|
189
189
|
let n = e.slice(t).toLowerCase();
|
|
190
|
-
return
|
|
190
|
+
return P[n]?.mime ?? "application/octet-stream";
|
|
191
191
|
}
|
|
192
192
|
function I(e) {
|
|
193
193
|
return new Promise((t) => setTimeout(t, e));
|
|
@@ -252,7 +252,7 @@ var ve = class {
|
|
|
252
252
|
accountId: e,
|
|
253
253
|
tokenIdHex: t.tokenIdHex,
|
|
254
254
|
type: "token",
|
|
255
|
-
addedTime:
|
|
255
|
+
addedTime: D()
|
|
256
256
|
};
|
|
257
257
|
await this.repository.upsertToken(t), await this.saveAsset(n);
|
|
258
258
|
}
|
|
@@ -400,20 +400,20 @@ var ve = class {
|
|
|
400
400
|
this.tokens.clear(), this.nfts.clear();
|
|
401
401
|
}
|
|
402
402
|
async getToken(e) {
|
|
403
|
-
if (e =
|
|
403
|
+
if (e = A(e), this.tokens.has(e)) return this.tokens.get(e);
|
|
404
404
|
let t = await this.walletDb.getToken(e);
|
|
405
405
|
return t && this.tokens.set(e, t), t;
|
|
406
406
|
}
|
|
407
407
|
async getNft(e) {
|
|
408
|
-
if (e =
|
|
408
|
+
if (e = A(e), this.nfts.has(e)) return this.nfts.get(e);
|
|
409
409
|
let t = await this.walletDb.getNft(e);
|
|
410
410
|
return t && this.nfts.set(e, t), t;
|
|
411
411
|
}
|
|
412
412
|
removeToken(e) {
|
|
413
|
-
this.tokens.delete(
|
|
413
|
+
this.tokens.delete(A(e));
|
|
414
414
|
}
|
|
415
415
|
removeNft(e) {
|
|
416
|
-
this.nfts.delete(
|
|
416
|
+
this.nfts.delete(A(e));
|
|
417
417
|
}
|
|
418
418
|
}, be = class e {
|
|
419
419
|
constructor(e) {
|
|
@@ -521,7 +521,7 @@ var ve = class {
|
|
|
521
521
|
}
|
|
522
522
|
async connect(e) {
|
|
523
523
|
try {
|
|
524
|
-
await this.disconnect(), e ||= await this.getCurrentInstance(), this.client = new ne({
|
|
524
|
+
await this.disconnect(), e ||= await this.getCurrentInstance(), this.params = e, this.client = new ne({
|
|
525
525
|
application: "com.otoplo.wallet",
|
|
526
526
|
version: "1.4.3",
|
|
527
527
|
host: e.host,
|
|
@@ -536,6 +536,38 @@ var ve = class {
|
|
|
536
536
|
await this.client?.disconnect();
|
|
537
537
|
}
|
|
538
538
|
/**
|
|
539
|
+
* Checks whether the wallet can use a server (e.g. before switching to it): that it's reachable, on the wallet's
|
|
540
|
+
* network and indexes scripts. Never throws.
|
|
541
|
+
*
|
|
542
|
+
* The server this service is connected to answers on its connection; any other one is checked on a temporary
|
|
543
|
+
* connection, closed after.
|
|
544
|
+
*/
|
|
545
|
+
async checkInstance(t) {
|
|
546
|
+
if (this.isConnected() && this.params && e.isSameInstance(this.params, t)) return this.check();
|
|
547
|
+
let n = new e(this.walletDb);
|
|
548
|
+
try {
|
|
549
|
+
return await n.connect(t), await n.check();
|
|
550
|
+
} catch {
|
|
551
|
+
return { status: "offline" };
|
|
552
|
+
} finally {
|
|
553
|
+
await n.disconnect();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
async check() {
|
|
557
|
+
try {
|
|
558
|
+
let e = await this.getFeatures();
|
|
559
|
+
if (!T(e.genesis_hash)) return { status: "wrong_network" };
|
|
560
|
+
if (!e.script_index) return { status: "unsupported" };
|
|
561
|
+
let t = await this.getLatency();
|
|
562
|
+
return t ? {
|
|
563
|
+
status: "online",
|
|
564
|
+
latency: t
|
|
565
|
+
} : { status: "offline" };
|
|
566
|
+
} catch {
|
|
567
|
+
return { status: "offline" };
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
539
571
|
* Walk a cursor-paginated rostrum query: start with "start" and follow the returned cursor until it is null.
|
|
540
572
|
* If the cursor expires mid-walk (e.g. reorg / mempool change), the walk is restarted from the beginning.
|
|
541
573
|
*/
|
|
@@ -576,6 +608,10 @@ var ve = class {
|
|
|
576
608
|
let t = await this.walletDb.getSetting("rostrum-params");
|
|
577
609
|
return t ? JSON.parse(t) : e.getPredefinedInstances()[0];
|
|
578
610
|
}
|
|
611
|
+
/** Whether both point to the same server (the label aside). */
|
|
612
|
+
static isSameInstance(e, t) {
|
|
613
|
+
return e.scheme === t.scheme && e.host.toLowerCase() === t.host.toLowerCase() && e.port === t.port;
|
|
614
|
+
}
|
|
579
615
|
static getPredefinedInstances() {
|
|
580
616
|
return w() ? [{
|
|
581
617
|
scheme: b.WSS,
|
|
@@ -740,8 +776,8 @@ var we = class {
|
|
|
740
776
|
let n = Object.keys(t), r = await this.walletDb.getAssets(e, "nft"), i = r?.filter((e) => !n.includes(e.tokenIdHex)) ?? [];
|
|
741
777
|
for (let t of i) await this.deleteNft(e, t.tokenIdHex);
|
|
742
778
|
for (let [n, i] of Object.entries(t)) {
|
|
743
|
-
let t =
|
|
744
|
-
!a && !o || a && o || (!a && o ? await this.deleteNft(e, t) : await this.handleNftReceive(e, t,
|
|
779
|
+
let t = A(n), a = i && BigInt(i.confirmed) + BigInt(i.unconfirmed) > 0n, o = r?.some((e) => e.tokenIdHex == t);
|
|
780
|
+
!a && !o || a && o || (!a && o ? await this.deleteNft(e, t) : await this.handleNftReceive(e, t, D()));
|
|
745
781
|
}
|
|
746
782
|
}
|
|
747
783
|
async saveToken(e, t) {
|
|
@@ -848,17 +884,17 @@ var Ee = class {
|
|
|
848
884
|
address: e.addresses[0],
|
|
849
885
|
nexaAmount: e.value_satoshi.toString(),
|
|
850
886
|
assetId: e.token_id_hex ?? "",
|
|
851
|
-
assetAmount:
|
|
887
|
+
assetAmount: j(e.groupQuantity)
|
|
852
888
|
};
|
|
853
889
|
t.includes(n.address) ? r.push(n) : i.push(n);
|
|
854
890
|
}
|
|
855
891
|
for (let e of n.vout) {
|
|
856
|
-
if (
|
|
892
|
+
if (O(e.scriptPubKey.addresses)) continue;
|
|
857
893
|
let n = {
|
|
858
894
|
address: e.scriptPubKey.addresses[0],
|
|
859
895
|
nexaAmount: e.value_satoshi.toString(),
|
|
860
896
|
assetId: e.scriptPubKey.token_id_hex ?? "",
|
|
861
|
-
assetAmount:
|
|
897
|
+
assetAmount: j(e.scriptPubKey.groupQuantity)
|
|
862
898
|
};
|
|
863
899
|
t.includes(n.address) ? a.push(n) : o.push(n);
|
|
864
900
|
}
|
|
@@ -869,7 +905,7 @@ var Ee = class {
|
|
|
869
905
|
accountId: 0,
|
|
870
906
|
txId: n.txid,
|
|
871
907
|
txIdem: n.txidem,
|
|
872
|
-
time: c ? n.time :
|
|
908
|
+
time: c ? n.time : D(),
|
|
873
909
|
height: c ? n.height : 0,
|
|
874
910
|
type: s,
|
|
875
911
|
fee: n.fee_satoshi.toString(),
|
|
@@ -894,12 +930,12 @@ var Ee = class {
|
|
|
894
930
|
return this.finalizeTransaction(i, Array.from(a.values()));
|
|
895
931
|
}
|
|
896
932
|
prepareTransaction(n, r, i, a) {
|
|
897
|
-
if (!
|
|
933
|
+
if (!E(n) && !E(n, t.PayToPublicKeyHash)) throw Error("Invalid Address.");
|
|
898
934
|
if (i && BigInt(r) < 1n || !i && parseInt(r) < h.DUST_AMOUNT) throw Error("The amount is too low.");
|
|
899
935
|
if (i && BigInt(r) > 9223372036854775807n || !i && parseInt(r) > h.MAX_MONEY) throw Error("The amount is too high.");
|
|
900
936
|
let o = new g();
|
|
901
937
|
if (a && o.addData(a), i) {
|
|
902
|
-
if (!
|
|
938
|
+
if (!E(i, t.GroupIdAddress)) throw Error("Invalid Token ID");
|
|
903
939
|
if (e.getOutputType(n) === 0) throw Error("Token must be sent to script template address");
|
|
904
940
|
o.to(n, h.DUST_AMOUNT, i, BigInt(r));
|
|
905
941
|
} else o.to(n, r);
|
|
@@ -907,7 +943,7 @@ var Ee = class {
|
|
|
907
943
|
}
|
|
908
944
|
async populateNexaInputsAndChange(e, t, n, r) {
|
|
909
945
|
let i = t.filter((e) => BigInt(e.balance.confirmed) + BigInt(e.balance.unconfirmed) > 0n);
|
|
910
|
-
if (
|
|
946
|
+
if (O(i)) throw Error("Not enough Nexa balance.");
|
|
911
947
|
let a = /* @__PURE__ */ new Map(), o = r.isConsolidate ? 0 : Number(e.transaction.outputs.find((e) => e.value > 0n).value);
|
|
912
948
|
for (let t of i) {
|
|
913
949
|
let i = await this.rostrumService.getNexaUtxos(t.address);
|
|
@@ -954,8 +990,8 @@ var Ee = class {
|
|
|
954
990
|
throw Error(JSON.stringify(s));
|
|
955
991
|
}
|
|
956
992
|
async populateTokenInputsAndChange(e, t, n, r, i) {
|
|
957
|
-
let a =
|
|
958
|
-
if (
|
|
993
|
+
let a = A(r), o = t.filter((e) => Object.keys(e.tokensBalance).includes(a));
|
|
994
|
+
if (O(o)) throw Error("Not enough token balance.");
|
|
959
995
|
let s = /* @__PURE__ */ new Map(), c = 0n;
|
|
960
996
|
for (let t of o) {
|
|
961
997
|
let a = await this.rostrumService.getTokenUtxos(t.address, r);
|
|
@@ -1232,7 +1268,7 @@ var je = class {
|
|
|
1232
1268
|
address: e.address,
|
|
1233
1269
|
nexaAmount: i.amount.toString(),
|
|
1234
1270
|
assetId: n,
|
|
1235
|
-
assetAmount:
|
|
1271
|
+
assetAmount: j(i.group_quantity) || i.amount.toString()
|
|
1236
1272
|
}), e.involvedAssets.add(n), r.scriptSig.isEmpty() && e.inputsToSign.add(t);
|
|
1237
1273
|
}
|
|
1238
1274
|
r.scriptSig.findPlaceholder() > 0 && e.inputsToSign.add(t);
|
|
@@ -1241,11 +1277,11 @@ var je = class {
|
|
|
1241
1277
|
for (let t = 0; t < e.txDetails.tx.outputs.length; t++) {
|
|
1242
1278
|
let n = e.txDetails.tx.outputs[t].toObject();
|
|
1243
1279
|
if (n.address !== e.address) continue;
|
|
1244
|
-
let r = n.groupId ?
|
|
1280
|
+
let r = n.groupId ? A(n.groupId) : "NEXA", i = {
|
|
1245
1281
|
address: n.address,
|
|
1246
1282
|
nexaAmount: n.value.toString(),
|
|
1247
1283
|
assetId: r,
|
|
1248
|
-
assetAmount:
|
|
1284
|
+
assetAmount: j(n.groupAmount) || n.value.toString()
|
|
1249
1285
|
};
|
|
1250
1286
|
e.involvedAssets.add(r), e.myOutputs.set(t, i);
|
|
1251
1287
|
}
|
|
@@ -1376,8 +1412,14 @@ var je = class {
|
|
|
1376
1412
|
static {
|
|
1377
1413
|
this.DEBOUNCE_MS = 1e3;
|
|
1378
1414
|
}
|
|
1415
|
+
static {
|
|
1416
|
+
this.RETRY_DELAY_MS = 1e3;
|
|
1417
|
+
}
|
|
1418
|
+
static {
|
|
1419
|
+
this.MAX_RETRY_DELAY_MS = 1e4;
|
|
1420
|
+
}
|
|
1379
1421
|
constructor(e, t, n, r, i, a) {
|
|
1380
|
-
this.keyManager = e, this.walletDb = t, this.rostrumService = n, this.assetService = r, this.transactionService = i, this.sessionManager = a, this.updatesStarted = !1, this.isConnected = !1, this.isSubscribed = !1, this.onSubscribeEvent = (e, t) => {
|
|
1422
|
+
this.keyManager = e, this.walletDb = t, this.rostrumService = n, this.assetService = r, this.transactionService = i, this.sessionManager = a, this.updatesStarted = !1, this.isConnected = !1, this.isSubscribed = !1, this.connectionId = 0, this.onSubscribeEvent = (e, t) => {
|
|
1381
1423
|
if (typeof t != "string") return;
|
|
1382
1424
|
let n = this.getAllAddresses().find((t) => t.address === e);
|
|
1383
1425
|
n && n.statusHash !== t && this.registerUpdate({
|
|
@@ -1429,8 +1471,14 @@ var je = class {
|
|
|
1429
1471
|
tokensBalance: e.tokensBalance
|
|
1430
1472
|
}));
|
|
1431
1473
|
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Switches to another server (or reconnects to the current one without `params`): saves it, disconnects, then
|
|
1476
|
+
* connects with `connect()`, retrying until it does. Check the server first with `RostrumService.checkInstance()`.
|
|
1477
|
+
*
|
|
1478
|
+
* @returns resolves like `connect()`: once connected and synced, or when stopped by `disconnectRostrum()`.
|
|
1479
|
+
*/
|
|
1432
1480
|
async reloadRostrum(e) {
|
|
1433
|
-
e && await this.rostrumService.setCurrentInstance(e), await this.disconnectRostrum(),
|
|
1481
|
+
return e && await this.rostrumService.setCurrentInstance(e), await this.disconnectRostrum(), this.connect();
|
|
1434
1482
|
}
|
|
1435
1483
|
async initRostrum() {
|
|
1436
1484
|
this.isConnected ||= (await this.rostrumService.connect(), await this.rostrumService.subscribeHeaders((e) => this.notify({
|
|
@@ -1438,8 +1486,47 @@ var je = class {
|
|
|
1438
1486
|
tip: e
|
|
1439
1487
|
})), !0);
|
|
1440
1488
|
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Connects and syncs the loaded wallet, retrying with exponential backoff until it succeeds or
|
|
1491
|
+
* `disconnectRostrum()` is called. Never throws.
|
|
1492
|
+
*
|
|
1493
|
+
* Each attempt skips what's already done (connected, subscribed), so a retry continues where the last one failed.
|
|
1494
|
+
* Calling it while waiting to retry makes the next attempt immediately (e.g. when the app returns to the foreground).
|
|
1495
|
+
*
|
|
1496
|
+
* For flows where the user is waiting on the result (e.g. discovery), use `initRostrum()`, which makes a single attempt.
|
|
1497
|
+
*
|
|
1498
|
+
* @returns resolves once connected and synced, or when stopped by `disconnectRostrum()`.
|
|
1499
|
+
*/
|
|
1500
|
+
connect() {
|
|
1501
|
+
if (this.connecting?.id === this.connectionId) return this.retryNow?.(), this.connecting.promise;
|
|
1502
|
+
let e = {
|
|
1503
|
+
id: this.connectionId,
|
|
1504
|
+
promise: this.connectLoop(this.connectionId)
|
|
1505
|
+
};
|
|
1506
|
+
return this.connecting = e, e.promise.finally(() => {
|
|
1507
|
+
this.connecting === e && (this.connecting = void 0);
|
|
1508
|
+
}), e.promise;
|
|
1509
|
+
}
|
|
1510
|
+
async connectLoop(t) {
|
|
1511
|
+
let n = e.RETRY_DELAY_MS;
|
|
1512
|
+
for (; t === this.connectionId;) {
|
|
1513
|
+
try {
|
|
1514
|
+
await this.initRostrum(), await this.reconnectSync();
|
|
1515
|
+
return;
|
|
1516
|
+
} catch (e) {
|
|
1517
|
+
console.info(`Connection failed, retrying in ${n}ms:`, e instanceof Error ? e.message : e);
|
|
1518
|
+
}
|
|
1519
|
+
if (t !== this.connectionId) return;
|
|
1520
|
+
await new Promise((e) => {
|
|
1521
|
+
let t = setTimeout(() => this.retryNow?.(), n);
|
|
1522
|
+
this.retryNow = () => {
|
|
1523
|
+
clearTimeout(t), this.retryNow = void 0, e();
|
|
1524
|
+
};
|
|
1525
|
+
}), n = Math.min(n * 2, e.MAX_RETRY_DELAY_MS);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1441
1528
|
async disconnectRostrum() {
|
|
1442
|
-
await this.rostrumService.disconnect(), this.isConnected = !1, this.isSubscribed = !1, this.stopUpdates();
|
|
1529
|
+
this.connectionId++, this.retryNow?.(), await this.rostrumService.disconnect(), this.isConnected = !1, this.isSubscribed = !1, this.stopUpdates();
|
|
1443
1530
|
}
|
|
1444
1531
|
async discoverWallet() {
|
|
1445
1532
|
let e = this.discoveryService.discoverWalletIndex(0, 0), t = this.discoveryService.discoverWalletIndex(0, 1), n = this.discoveryService.discoverWalletIndex(2, 0), r = this.discoveryService.discoverVaults(), [i, a, o, s] = await Promise.all([
|
|
@@ -1468,7 +1555,14 @@ var je = class {
|
|
|
1468
1555
|
return this.startUpdates(), Promise.all([this.sessionManager.reload(this.accounts), this.subscribeAllAddresses()]);
|
|
1469
1556
|
}
|
|
1470
1557
|
async subscribeAllAddresses() {
|
|
1471
|
-
|
|
1558
|
+
if (!this.isSubscribed) {
|
|
1559
|
+
this.isSubscribed = !0;
|
|
1560
|
+
try {
|
|
1561
|
+
await this.subscribeAddresses(this.getAllAddresses());
|
|
1562
|
+
} catch (e) {
|
|
1563
|
+
throw this.isSubscribed = !1, e;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1472
1566
|
}
|
|
1473
1567
|
initState() {
|
|
1474
1568
|
let e = this.getMainAddresses();
|
|
@@ -1478,8 +1572,8 @@ var je = class {
|
|
|
1478
1572
|
id: -1,
|
|
1479
1573
|
name: "HD Wallet",
|
|
1480
1574
|
address: this.getReceiveAddress(),
|
|
1481
|
-
balance:
|
|
1482
|
-
tokensBalance:
|
|
1575
|
+
balance: M(e.map((e) => e.balance)),
|
|
1576
|
+
tokensBalance: N(e.map((e) => e.tokensBalance)),
|
|
1483
1577
|
sessions: {}
|
|
1484
1578
|
}
|
|
1485
1579
|
});
|
|
@@ -1614,7 +1708,7 @@ var je = class {
|
|
|
1614
1708
|
for (let { txs: n } of e) for (let e of n) t.set(e.tx_hash, e);
|
|
1615
1709
|
let n = Array.from(t.values());
|
|
1616
1710
|
await this.checkGapLimit(0), await this.checkGapLimit(1);
|
|
1617
|
-
let r = this.getMainAddresses(), i =
|
|
1711
|
+
let r = this.getMainAddresses(), i = M(r.map((e) => e.balance)), a = N(r.map((e) => e.tokensBalance));
|
|
1618
1712
|
this.notify({
|
|
1619
1713
|
type: "account_balance_updated",
|
|
1620
1714
|
accountId: -1,
|
|
@@ -1775,7 +1869,7 @@ var je = class {
|
|
|
1775
1869
|
}
|
|
1776
1870
|
async recoverTokens() {
|
|
1777
1871
|
let e = [];
|
|
1778
|
-
e.push(this.assetService.syncTokens(-1,
|
|
1872
|
+
e.push(this.assetService.syncTokens(-1, N(this.getMainAddresses().map((e) => e.tokensBalance))));
|
|
1779
1873
|
for (let t of this.accounts.values()) e.push(this.assetService.syncTokens(t.id, t.tokensBalance));
|
|
1780
1874
|
await Promise.all(e);
|
|
1781
1875
|
}
|
|
@@ -1869,6 +1963,6 @@ var je = class {
|
|
|
1869
1963
|
}), a;
|
|
1870
1964
|
}
|
|
1871
1965
|
};
|
|
1872
|
-
export { se as AccountType, we as AssetService, S as CURRENCIES, ue as HD_WALLET_ID, B as KeyManager, ce as KeySpace, de as MAX_INT64, Pe as MarketService, be as RostrumService, je as SessionManager, le as SessionRequestType, Ee as TransactionService, Me as TransactionTransformer, W as VAULT_FIRST_BLOCK, ye as WalletCache, ve as WalletDB, Ne as WalletManager, _e as calculateFiatValue,
|
|
1966
|
+
export { se as AccountType, we as AssetService, S as CURRENCIES, ue as HD_WALLET_ID, B as KeyManager, ce as KeySpace, de as MAX_INT64, Pe as MarketService, be as RostrumService, je as SessionManager, le as SessionRequestType, Ee as TransactionService, Me as TransactionTransformer, W as VAULT_FIRST_BLOCK, ye as WalletCache, ve as WalletDB, Ne as WalletManager, _e as calculateFiatValue, me as capitalizeFirstLetter, C as currencyCodes, D as currentTimestamp, Oe as encryptMnemonic, Te as estimateDateByFutureBlock, De as generateNewMnemonic, X as generateVaultAddress, q as generateVaultConstraint, Y as generateVaultVisibleArgs, k as getAddressBuffer, H as getAssetFileUrl, V as getAssetMetadataUrl, fe as getExplorerUrl, ge as getFileMediaType, F as getFileMimeType, J as getVaultConstraintHash, G as getVaultTemplate, K as getVaultTemplateHash, T as isGenesisHashValid, Z as isMnemonicValid, O as isNullOrEmpty, w as isTestnet, E as isValidNexaAddress, R as keyPathToString, Se as parseTokenDataUrl, L as prettifyAmount, I as sleep, z as stringToKeyPath, M as sumBalance, N as sumTokensBalance, j as tokenAmountToAssetAmount, he as tokenHexToAddr, A as tokenIdToHex, xe as transformTokenIconUrl, pe as truncateStringMiddle, Ae as validateAndDecryptMnemonic };
|
|
1873
1967
|
|
|
1874
1968
|
//# sourceMappingURL=index.js.map
|