@anywalletkit/wallet-ton 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +126 -2
- package/dist/chunk-BLWBC6L2.js +480 -0
- package/dist/chunk-BLWBC6L2.js.map +1 -0
- package/dist/history.cjs +499 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +163 -0
- package/dist/history.d.ts +163 -0
- package/dist/history.js +25 -0
- package/dist/history.js.map +1 -0
- package/dist/index.cjs +1649 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +704 -0
- package/dist/index.d.ts +704 -0
- package/dist/index.js +1185 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ChainTx, HistoryPage, HistorySource, HistoryQuery, ChainTransfer, ChainCall } from '@anywalletkit/core';
|
|
2
|
+
|
|
3
|
+
type HistoryFetch = (input: string, init?: {
|
|
4
|
+
method?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
json(): Promise<unknown>;
|
|
11
|
+
}>;
|
|
12
|
+
/** Which indexer answered: tonapi events or toncenter v3 transactions. */
|
|
13
|
+
type TonHistoryBackend = 'tonapi' | 'toncenter';
|
|
14
|
+
/** Options for `createTonHistory`: tonapi first, toncenter v3 as the fallback. */
|
|
15
|
+
interface TonHistoryOptions {
|
|
16
|
+
/** tonapi root. Default `https://tonapi.io` (`https://testnet.tonapi.io` on testnet). `null` disables tonapi. */
|
|
17
|
+
tonapiUrl?: string | null;
|
|
18
|
+
/** tonapi Bearer key. Keyless tonapi allows ~1 request/s. */
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/** toncenter root for the v3 fallback. Default `https://toncenter.com` (`https://testnet.toncenter.com`). `null` disables it. */
|
|
21
|
+
toncenterUrl?: string | null;
|
|
22
|
+
/** toncenter `X-API-Key`. */
|
|
23
|
+
toncenterApiKey?: string;
|
|
24
|
+
network?: 'mainnet' | 'testnet';
|
|
25
|
+
fetch?: HistoryFetch;
|
|
26
|
+
/** tonapi requests per second. Default 1 without a key, 10 with one. */
|
|
27
|
+
rateLimit?: number;
|
|
28
|
+
/** Per request, ms. Default 15 000. */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
interface TonHistoryRaw {
|
|
32
|
+
backend: TonHistoryBackend;
|
|
33
|
+
/** The tonapi account event, or the toncenter v3 transaction row. */
|
|
34
|
+
event: unknown;
|
|
35
|
+
/** tonapi flagged the event as scam. */
|
|
36
|
+
scam?: boolean;
|
|
37
|
+
/** tonapi `value_flow` for the account when it had to be fetched to recover jetton movements. */
|
|
38
|
+
valueFlow?: unknown;
|
|
39
|
+
}
|
|
40
|
+
interface TonChainTx extends ChainTx {
|
|
41
|
+
/** Mirrors `raw.scam`; the app hides these by default. */
|
|
42
|
+
scam?: boolean;
|
|
43
|
+
raw: TonHistoryRaw;
|
|
44
|
+
}
|
|
45
|
+
interface TonHistoryPage extends HistoryPage {
|
|
46
|
+
items: TonChainTx[];
|
|
47
|
+
backend?: TonHistoryBackend;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* TON history from tonapi events with a toncenter v3 fallback. Build it with `createTonHistory`.
|
|
51
|
+
*/
|
|
52
|
+
interface TonHistorySource extends HistorySource {
|
|
53
|
+
listActivity(address: string, query?: HistoryQuery): Promise<TonHistoryPage>;
|
|
54
|
+
getTransaction(hash: string, address: string): Promise<TonChainTx | undefined>;
|
|
55
|
+
}
|
|
56
|
+
/** Every configured history backend failed (or none was configured). */
|
|
57
|
+
declare class HistoryUnavailableError extends Error {
|
|
58
|
+
readonly chain: string;
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
readonly attempts: readonly string[];
|
|
61
|
+
constructor(chain: string, reason: string, attempts?: readonly string[]);
|
|
62
|
+
}
|
|
63
|
+
interface TonHistoryCursor {
|
|
64
|
+
v: 1;
|
|
65
|
+
b: TonHistoryBackend;
|
|
66
|
+
/** Next page = events / transactions with `lt < this` (decimal string). */
|
|
67
|
+
lt: string;
|
|
68
|
+
}
|
|
69
|
+
declare function encodeCursor(c: TonHistoryCursor): string;
|
|
70
|
+
declare function decodeCursor(s: string): TonHistoryCursor;
|
|
71
|
+
/** Any spelling → raw lowercase `wc:hex`; unparsable input is returned as-is. */
|
|
72
|
+
declare function rawTonAddress(a: string): string;
|
|
73
|
+
interface TonapiAccount {
|
|
74
|
+
address: string;
|
|
75
|
+
is_wallet?: boolean;
|
|
76
|
+
is_scam?: boolean;
|
|
77
|
+
name?: string;
|
|
78
|
+
}
|
|
79
|
+
interface TonapiJetton {
|
|
80
|
+
address: string;
|
|
81
|
+
symbol?: string;
|
|
82
|
+
decimals?: number;
|
|
83
|
+
name?: string;
|
|
84
|
+
}
|
|
85
|
+
interface TonapiAction {
|
|
86
|
+
type: string;
|
|
87
|
+
status: 'ok' | 'failed' | string;
|
|
88
|
+
[body: string]: unknown;
|
|
89
|
+
}
|
|
90
|
+
interface TonapiEvent {
|
|
91
|
+
event_id: string;
|
|
92
|
+
account?: TonapiAccount;
|
|
93
|
+
timestamp: number;
|
|
94
|
+
lt: number | string;
|
|
95
|
+
in_progress: boolean;
|
|
96
|
+
is_scam: boolean;
|
|
97
|
+
actions: TonapiAction[];
|
|
98
|
+
/** Account-scoped events only: TON the account lost beyond its actions (negative = fees). */
|
|
99
|
+
extra?: number;
|
|
100
|
+
value_flow?: Array<{
|
|
101
|
+
account: TonapiAccount;
|
|
102
|
+
ton: number;
|
|
103
|
+
jettons?: Array<{
|
|
104
|
+
jetton: TonapiJetton;
|
|
105
|
+
quantity: number | string;
|
|
106
|
+
}>;
|
|
107
|
+
}>;
|
|
108
|
+
}
|
|
109
|
+
interface MappedActions {
|
|
110
|
+
transfers: ChainTransfer[];
|
|
111
|
+
call?: ChainCall;
|
|
112
|
+
/** Who initiated the event as far as the first action tells. */
|
|
113
|
+
initiator?: string;
|
|
114
|
+
/** The event needs `value_flow` to recover a jetton movement tonapi did not spell out (unstake requests). */
|
|
115
|
+
needsValueFlow?: {
|
|
116
|
+
counterparty: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** tonapi actions → transfers + the contract call. Only `ok` actions move value. */
|
|
120
|
+
declare function mapActions(actions: TonapiAction[]): MappedActions;
|
|
121
|
+
/** The account's jetton deltas from `value_flow` as transfers against `counterparty`. */
|
|
122
|
+
declare function valueFlowTransfers(event: TonapiEvent, own: string, counterparty: string): ChainTransfer[];
|
|
123
|
+
declare function mapTonapiEvent(chain: string, address: string, own: string, event: TonapiEvent, valueFlow?: TonapiEvent): TonChainTx;
|
|
124
|
+
interface V3Message {
|
|
125
|
+
source?: string | null;
|
|
126
|
+
destination?: string | null;
|
|
127
|
+
value?: string | null;
|
|
128
|
+
opcode?: string | null;
|
|
129
|
+
decoded_opcode?: string | null;
|
|
130
|
+
}
|
|
131
|
+
interface V3Transaction {
|
|
132
|
+
account: string;
|
|
133
|
+
/** base64. */
|
|
134
|
+
hash: string;
|
|
135
|
+
lt: string;
|
|
136
|
+
now: number;
|
|
137
|
+
total_fees: string;
|
|
138
|
+
description?: {
|
|
139
|
+
aborted?: boolean;
|
|
140
|
+
compute_ph?: {
|
|
141
|
+
success?: boolean;
|
|
142
|
+
exit_code?: number;
|
|
143
|
+
skipped?: boolean;
|
|
144
|
+
};
|
|
145
|
+
action?: {
|
|
146
|
+
success?: boolean;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
in_msg?: V3Message | null;
|
|
150
|
+
out_msgs?: V3Message[];
|
|
151
|
+
}
|
|
152
|
+
/** Reduced mapping: TON in / out and op codes of the account's own transaction; jettons are not visible here. */
|
|
153
|
+
declare function mapToncenterTransaction(chain: string, address: string, row: V3Transaction): TonChainTx;
|
|
154
|
+
/** Tonviewer link for a transaction. */
|
|
155
|
+
declare function tonExplorerTxUrl(hash: string, network?: 'mainnet' | 'testnet'): string;
|
|
156
|
+
/**
|
|
157
|
+
* A `HistorySource` for TON: tonapi account events first, toncenter v3 when
|
|
158
|
+
* tonapi is down or disabled. Both page by `lt`, so a cursor from one backend
|
|
159
|
+
* resumes on the other.
|
|
160
|
+
*/
|
|
161
|
+
declare function createTonHistory(options?: TonHistoryOptions): TonHistorySource;
|
|
162
|
+
|
|
163
|
+
export { type HistoryFetch, HistoryUnavailableError, type TonChainTx, type TonHistoryBackend, type TonHistoryCursor, type TonHistoryOptions, type TonHistoryPage, type TonHistoryRaw, type TonHistorySource, type TonapiAction, type TonapiEvent, type V3Transaction, createTonHistory, decodeCursor, encodeCursor, mapActions, mapTonapiEvent, mapToncenterTransaction, rawTonAddress, tonExplorerTxUrl, valueFlowTransfers };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ChainTx, HistoryPage, HistorySource, HistoryQuery, ChainTransfer, ChainCall } from '@anywalletkit/core';
|
|
2
|
+
|
|
3
|
+
type HistoryFetch = (input: string, init?: {
|
|
4
|
+
method?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
json(): Promise<unknown>;
|
|
11
|
+
}>;
|
|
12
|
+
/** Which indexer answered: tonapi events or toncenter v3 transactions. */
|
|
13
|
+
type TonHistoryBackend = 'tonapi' | 'toncenter';
|
|
14
|
+
/** Options for `createTonHistory`: tonapi first, toncenter v3 as the fallback. */
|
|
15
|
+
interface TonHistoryOptions {
|
|
16
|
+
/** tonapi root. Default `https://tonapi.io` (`https://testnet.tonapi.io` on testnet). `null` disables tonapi. */
|
|
17
|
+
tonapiUrl?: string | null;
|
|
18
|
+
/** tonapi Bearer key. Keyless tonapi allows ~1 request/s. */
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/** toncenter root for the v3 fallback. Default `https://toncenter.com` (`https://testnet.toncenter.com`). `null` disables it. */
|
|
21
|
+
toncenterUrl?: string | null;
|
|
22
|
+
/** toncenter `X-API-Key`. */
|
|
23
|
+
toncenterApiKey?: string;
|
|
24
|
+
network?: 'mainnet' | 'testnet';
|
|
25
|
+
fetch?: HistoryFetch;
|
|
26
|
+
/** tonapi requests per second. Default 1 without a key, 10 with one. */
|
|
27
|
+
rateLimit?: number;
|
|
28
|
+
/** Per request, ms. Default 15 000. */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
interface TonHistoryRaw {
|
|
32
|
+
backend: TonHistoryBackend;
|
|
33
|
+
/** The tonapi account event, or the toncenter v3 transaction row. */
|
|
34
|
+
event: unknown;
|
|
35
|
+
/** tonapi flagged the event as scam. */
|
|
36
|
+
scam?: boolean;
|
|
37
|
+
/** tonapi `value_flow` for the account when it had to be fetched to recover jetton movements. */
|
|
38
|
+
valueFlow?: unknown;
|
|
39
|
+
}
|
|
40
|
+
interface TonChainTx extends ChainTx {
|
|
41
|
+
/** Mirrors `raw.scam`; the app hides these by default. */
|
|
42
|
+
scam?: boolean;
|
|
43
|
+
raw: TonHistoryRaw;
|
|
44
|
+
}
|
|
45
|
+
interface TonHistoryPage extends HistoryPage {
|
|
46
|
+
items: TonChainTx[];
|
|
47
|
+
backend?: TonHistoryBackend;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* TON history from tonapi events with a toncenter v3 fallback. Build it with `createTonHistory`.
|
|
51
|
+
*/
|
|
52
|
+
interface TonHistorySource extends HistorySource {
|
|
53
|
+
listActivity(address: string, query?: HistoryQuery): Promise<TonHistoryPage>;
|
|
54
|
+
getTransaction(hash: string, address: string): Promise<TonChainTx | undefined>;
|
|
55
|
+
}
|
|
56
|
+
/** Every configured history backend failed (or none was configured). */
|
|
57
|
+
declare class HistoryUnavailableError extends Error {
|
|
58
|
+
readonly chain: string;
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
readonly attempts: readonly string[];
|
|
61
|
+
constructor(chain: string, reason: string, attempts?: readonly string[]);
|
|
62
|
+
}
|
|
63
|
+
interface TonHistoryCursor {
|
|
64
|
+
v: 1;
|
|
65
|
+
b: TonHistoryBackend;
|
|
66
|
+
/** Next page = events / transactions with `lt < this` (decimal string). */
|
|
67
|
+
lt: string;
|
|
68
|
+
}
|
|
69
|
+
declare function encodeCursor(c: TonHistoryCursor): string;
|
|
70
|
+
declare function decodeCursor(s: string): TonHistoryCursor;
|
|
71
|
+
/** Any spelling → raw lowercase `wc:hex`; unparsable input is returned as-is. */
|
|
72
|
+
declare function rawTonAddress(a: string): string;
|
|
73
|
+
interface TonapiAccount {
|
|
74
|
+
address: string;
|
|
75
|
+
is_wallet?: boolean;
|
|
76
|
+
is_scam?: boolean;
|
|
77
|
+
name?: string;
|
|
78
|
+
}
|
|
79
|
+
interface TonapiJetton {
|
|
80
|
+
address: string;
|
|
81
|
+
symbol?: string;
|
|
82
|
+
decimals?: number;
|
|
83
|
+
name?: string;
|
|
84
|
+
}
|
|
85
|
+
interface TonapiAction {
|
|
86
|
+
type: string;
|
|
87
|
+
status: 'ok' | 'failed' | string;
|
|
88
|
+
[body: string]: unknown;
|
|
89
|
+
}
|
|
90
|
+
interface TonapiEvent {
|
|
91
|
+
event_id: string;
|
|
92
|
+
account?: TonapiAccount;
|
|
93
|
+
timestamp: number;
|
|
94
|
+
lt: number | string;
|
|
95
|
+
in_progress: boolean;
|
|
96
|
+
is_scam: boolean;
|
|
97
|
+
actions: TonapiAction[];
|
|
98
|
+
/** Account-scoped events only: TON the account lost beyond its actions (negative = fees). */
|
|
99
|
+
extra?: number;
|
|
100
|
+
value_flow?: Array<{
|
|
101
|
+
account: TonapiAccount;
|
|
102
|
+
ton: number;
|
|
103
|
+
jettons?: Array<{
|
|
104
|
+
jetton: TonapiJetton;
|
|
105
|
+
quantity: number | string;
|
|
106
|
+
}>;
|
|
107
|
+
}>;
|
|
108
|
+
}
|
|
109
|
+
interface MappedActions {
|
|
110
|
+
transfers: ChainTransfer[];
|
|
111
|
+
call?: ChainCall;
|
|
112
|
+
/** Who initiated the event as far as the first action tells. */
|
|
113
|
+
initiator?: string;
|
|
114
|
+
/** The event needs `value_flow` to recover a jetton movement tonapi did not spell out (unstake requests). */
|
|
115
|
+
needsValueFlow?: {
|
|
116
|
+
counterparty: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** tonapi actions → transfers + the contract call. Only `ok` actions move value. */
|
|
120
|
+
declare function mapActions(actions: TonapiAction[]): MappedActions;
|
|
121
|
+
/** The account's jetton deltas from `value_flow` as transfers against `counterparty`. */
|
|
122
|
+
declare function valueFlowTransfers(event: TonapiEvent, own: string, counterparty: string): ChainTransfer[];
|
|
123
|
+
declare function mapTonapiEvent(chain: string, address: string, own: string, event: TonapiEvent, valueFlow?: TonapiEvent): TonChainTx;
|
|
124
|
+
interface V3Message {
|
|
125
|
+
source?: string | null;
|
|
126
|
+
destination?: string | null;
|
|
127
|
+
value?: string | null;
|
|
128
|
+
opcode?: string | null;
|
|
129
|
+
decoded_opcode?: string | null;
|
|
130
|
+
}
|
|
131
|
+
interface V3Transaction {
|
|
132
|
+
account: string;
|
|
133
|
+
/** base64. */
|
|
134
|
+
hash: string;
|
|
135
|
+
lt: string;
|
|
136
|
+
now: number;
|
|
137
|
+
total_fees: string;
|
|
138
|
+
description?: {
|
|
139
|
+
aborted?: boolean;
|
|
140
|
+
compute_ph?: {
|
|
141
|
+
success?: boolean;
|
|
142
|
+
exit_code?: number;
|
|
143
|
+
skipped?: boolean;
|
|
144
|
+
};
|
|
145
|
+
action?: {
|
|
146
|
+
success?: boolean;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
in_msg?: V3Message | null;
|
|
150
|
+
out_msgs?: V3Message[];
|
|
151
|
+
}
|
|
152
|
+
/** Reduced mapping: TON in / out and op codes of the account's own transaction; jettons are not visible here. */
|
|
153
|
+
declare function mapToncenterTransaction(chain: string, address: string, row: V3Transaction): TonChainTx;
|
|
154
|
+
/** Tonviewer link for a transaction. */
|
|
155
|
+
declare function tonExplorerTxUrl(hash: string, network?: 'mainnet' | 'testnet'): string;
|
|
156
|
+
/**
|
|
157
|
+
* A `HistorySource` for TON: tonapi account events first, toncenter v3 when
|
|
158
|
+
* tonapi is down or disabled. Both page by `lt`, so a cursor from one backend
|
|
159
|
+
* resumes on the other.
|
|
160
|
+
*/
|
|
161
|
+
declare function createTonHistory(options?: TonHistoryOptions): TonHistorySource;
|
|
162
|
+
|
|
163
|
+
export { type HistoryFetch, HistoryUnavailableError, type TonChainTx, type TonHistoryBackend, type TonHistoryCursor, type TonHistoryOptions, type TonHistoryPage, type TonHistoryRaw, type TonHistorySource, type TonapiAction, type TonapiEvent, type V3Transaction, createTonHistory, decodeCursor, encodeCursor, mapActions, mapTonapiEvent, mapToncenterTransaction, rawTonAddress, tonExplorerTxUrl, valueFlowTransfers };
|
package/dist/history.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HistoryUnavailableError,
|
|
3
|
+
createTonHistory,
|
|
4
|
+
decodeCursor,
|
|
5
|
+
encodeCursor,
|
|
6
|
+
mapActions,
|
|
7
|
+
mapTonapiEvent,
|
|
8
|
+
mapToncenterTransaction,
|
|
9
|
+
rawTonAddress,
|
|
10
|
+
tonExplorerTxUrl,
|
|
11
|
+
valueFlowTransfers
|
|
12
|
+
} from "./chunk-BLWBC6L2.js";
|
|
13
|
+
export {
|
|
14
|
+
HistoryUnavailableError,
|
|
15
|
+
createTonHistory,
|
|
16
|
+
decodeCursor,
|
|
17
|
+
encodeCursor,
|
|
18
|
+
mapActions,
|
|
19
|
+
mapTonapiEvent,
|
|
20
|
+
mapToncenterTransaction,
|
|
21
|
+
rawTonAddress,
|
|
22
|
+
tonExplorerTxUrl,
|
|
23
|
+
valueFlowTransfers
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|