tusdt-sdk 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/dist/chunk-5HS7VSOA.js +1844 -0
  4. package/dist/chunk-5HS7VSOA.js.map +1 -0
  5. package/dist/client.d.ts +2 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +3 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/contract/events.d.ts +39 -0
  10. package/dist/contract/events.d.ts.map +1 -0
  11. package/dist/contract/finalized-events.d.ts +32 -0
  12. package/dist/contract/finalized-events.d.ts.map +1 -0
  13. package/dist/contract/helpers.d.ts +19 -0
  14. package/dist/contract/helpers.d.ts.map +1 -0
  15. package/dist/contract/payment-listener.d.ts +88 -0
  16. package/dist/contract/payment-listener.d.ts.map +1 -0
  17. package/dist/contract/queries.d.ts +23 -0
  18. package/dist/contract/queries.d.ts.map +1 -0
  19. package/dist/contract/transactions.d.ts +36 -0
  20. package/dist/contract/transactions.d.ts.map +1 -0
  21. package/dist/contract/tusdt-contract.d.ts +186 -0
  22. package/dist/contract/tusdt-contract.d.ts.map +1 -0
  23. package/dist/core/constants.d.ts +10 -0
  24. package/dist/core/constants.d.ts.map +1 -0
  25. package/dist/core/errors.d.ts +85 -0
  26. package/dist/core/errors.d.ts.map +1 -0
  27. package/dist/core/types.d.ts +97 -0
  28. package/dist/core/types.d.ts.map +1 -0
  29. package/dist/core/validation.d.ts +30 -0
  30. package/dist/core/validation.d.ts.map +1 -0
  31. package/dist/index.d.ts +13 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +3 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/server.d.ts +19 -0
  36. package/dist/server.d.ts.map +1 -0
  37. package/dist/server.js +204 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/signer/types.d.ts +2 -0
  40. package/dist/signer/types.d.ts.map +1 -0
  41. package/metadata/tusdt_erc20.json +1133 -0
  42. package/package.json +83 -0
@@ -0,0 +1,186 @@
1
+ import { Contract } from 'dedot/contracts';
2
+ import type { AccountId, Balance, TusdtSigner, TxOptions, TxResult, TransferEvent, ApprovalEvent, FinalizedTransferEvent, Unsubscribe, EventSubscriptionOptions } from '../core/types.js';
3
+ import type { WatchFinalizedOptions } from './finalized-events.js';
4
+ export interface TusdtContractOptions {
5
+ /**
6
+ * Default caller address for read-only queries.
7
+ * If not provided, a zero address is used.
8
+ * This only affects the context of dry-run queries, not authorization.
9
+ */
10
+ defaultCaller?: AccountId;
11
+ }
12
+ /**
13
+ * Minimal client interface that both DedotClient and LegacyClient satisfy.
14
+ * This allows the SDK to work with any Dedot-compatible client regardless
15
+ * of whether it uses the new JSON-RPC v2 spec or the legacy spec.
16
+ *
17
+ * For nodes that only support legacy JSON-RPC (e.g., most Substrate nodes),
18
+ * create the client with: `await DedotClient.legacy(provider)`
19
+ * or `await LegacyClient.new(provider)`.
20
+ */
21
+ export interface SubstrateClient {
22
+ rpc: any;
23
+ query: any;
24
+ disconnect(): Promise<void>;
25
+ }
26
+ /**
27
+ * Primary SDK class for interacting with the TUSDT ERC20 ink! smart contract.
28
+ *
29
+ * The SDK does NOT create or manage RPC connections. The user must provide
30
+ * a pre-connected Dedot client instance (DedotClient or LegacyClient).
31
+ *
32
+ * Usage with legacy RPC nodes (most Substrate nodes):
33
+ * ```ts
34
+ * import { DedotClient, WsProvider } from 'dedot';
35
+ * import { TusdtContract } from 'tusdt-sdk';
36
+ *
37
+ * // Use DedotClient.legacy() for nodes that don't support JSON-RPC v2
38
+ * const client = await DedotClient.legacy(new WsProvider('wss://...'));
39
+ * const tusdt = new TusdtContract(client, '5GGq...');
40
+ *
41
+ * const balance = await tusdt.balanceOf('5HhJ...');
42
+ * ```
43
+ *
44
+ * Usage with JSON-RPC v2 nodes:
45
+ * ```ts
46
+ * const client = await DedotClient.new(new WsProvider('wss://...'));
47
+ * const tusdt = new TusdtContract(client, '5GGq...');
48
+ * ```
49
+ */
50
+ export declare class TusdtContract {
51
+ /** The underlying Dedot typed contract instance */
52
+ readonly contract: Contract<any>;
53
+ /** The Dedot client (stored for event subscriptions) */
54
+ private readonly client;
55
+ /**
56
+ * Create a TusdtContract attached to a deployed TUSDT ERC20 contract.
57
+ *
58
+ * @param client - A connected Dedot client instance (DedotClient or LegacyClient).
59
+ * For nodes using legacy JSON-RPC, create with `DedotClient.legacy(provider)`.
60
+ * The user is responsible for creating and managing the client lifecycle.
61
+ * @param contractAddress - The SS58 address of the deployed contract.
62
+ * @param options - Optional configuration.
63
+ */
64
+ constructor(client: SubstrateClient, contractAddress: AccountId, options?: TusdtContractOptions);
65
+ /**
66
+ * Factory: create from user-provided metadata JSON.
67
+ *
68
+ * Use this when the metadata JSON is loaded externally (e.g., in browser builds
69
+ * where JSON import paths may differ, or when using a custom contract build).
70
+ */
71
+ static fromMetadata(client: SubstrateClient, contractAddress: AccountId, metadata: Record<string, unknown>, options?: TusdtContractOptions): TusdtContract;
72
+ /**
73
+ * Returns the controller account address.
74
+ * The controller is authorized to mint/burn tokens.
75
+ */
76
+ controller(): Promise<AccountId>;
77
+ /**
78
+ * Returns the total supply of tokens in circulation.
79
+ * Returns bigint (u64).
80
+ */
81
+ totalSupply(): Promise<Balance>;
82
+ /**
83
+ * Returns the token balance of the specified account.
84
+ * Returns 0n if the account has no balance.
85
+ */
86
+ balanceOf(owner: AccountId): Promise<Balance>;
87
+ /**
88
+ * Returns the remaining allowance that spender can withdraw from owner.
89
+ * Returns 0n if no allowance has been set.
90
+ */
91
+ allowance(owner: AccountId, spender: AccountId): Promise<Balance>;
92
+ /**
93
+ * Transfer tokens from the signer's account to a recipient.
94
+ *
95
+ * Performs a dry-run first to check for errors and estimate gas.
96
+ * Self-transfers and zero-value transfers are allowed.
97
+ *
98
+ * @throws InsufficientBalanceError if signer has insufficient balance
99
+ * @throws ValidationError if inputs are invalid or would cause overflow
100
+ */
101
+ transfer(signer: TusdtSigner, to: AccountId, value: Balance, options?: TxOptions): Promise<TxResult>;
102
+ /**
103
+ * Approve a spender to withdraw up to `value` tokens from the signer's account.
104
+ *
105
+ * WARNING: Uses set-overwrite pattern (standard ERC20). Subject to front-running attack.
106
+ * Use `safeApprove()` for safer approval changes.
107
+ *
108
+ * @throws ValidationError if inputs are invalid
109
+ */
110
+ approve(signer: TusdtSigner, spender: AccountId, value: Balance, options?: TxOptions): Promise<TxResult>;
111
+ /**
112
+ * Transfer tokens from one account to another using the signer's allowance.
113
+ *
114
+ * The signer must have been granted sufficient allowance by the `from` account.
115
+ * On success, the allowance is decreased by `value`.
116
+ * On failure (insufficient balance), the allowance is NOT decreased.
117
+ *
118
+ * @throws InsufficientAllowanceError if signer has insufficient allowance
119
+ * @throws InsufficientBalanceError if `from` has insufficient balance
120
+ * @throws ValidationError if inputs are invalid or would cause overflow
121
+ */
122
+ transferFrom(signer: TusdtSigner, from: AccountId, to: AccountId, value: Balance, options?: TxOptions): Promise<TxResult>;
123
+ /**
124
+ * Safe approval that mitigates the ERC20 approve front-running attack.
125
+ *
126
+ * If the current allowance > 0 and newValue > 0, this first sets the
127
+ * allowance to 0, then sets it to the desired value.
128
+ *
129
+ * @throws ValidationError if inputs are invalid
130
+ */
131
+ safeApprove(signer: TusdtSigner, spender: AccountId, newValue: Balance, options?: TxOptions): Promise<TxResult>;
132
+ /**
133
+ * Subscribe to all Transfer events emitted by this contract.
134
+ * Includes mints (from=null), burns (to=null), and regular transfers.
135
+ *
136
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
137
+ * @returns A function to unsubscribe from the event stream.
138
+ */
139
+ onTransfer(callback: (event: TransferEvent) => void, options?: EventSubscriptionOptions): Promise<Unsubscribe>;
140
+ /**
141
+ * Subscribe to all Approval events emitted by this contract.
142
+ *
143
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
144
+ * @returns A function to unsubscribe from the event stream.
145
+ */
146
+ onApproval(callback: (event: ApprovalEvent) => void, options?: EventSubscriptionOptions): Promise<Unsubscribe>;
147
+ /**
148
+ * Subscribe to Transfer events where a specific account is the sender.
149
+ *
150
+ * @param account - SS58 address of the sender to filter for
151
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
152
+ * @returns A function to unsubscribe from the event stream.
153
+ */
154
+ onTransferFrom(account: AccountId, callback: (event: TransferEvent) => void, options?: EventSubscriptionOptions): Promise<Unsubscribe>;
155
+ /**
156
+ * Subscribe to Transfer events where a specific account is the recipient.
157
+ *
158
+ * @param account - SS58 address of the recipient to filter for
159
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
160
+ * @returns A function to unsubscribe from the event stream.
161
+ */
162
+ onTransferTo(account: AccountId, callback: (event: TransferEvent) => void, options?: EventSubscriptionOptions): Promise<Unsubscribe>;
163
+ /**
164
+ * Subscribe to all Transfer events on finalized blocks.
165
+ *
166
+ * Finalized blocks are immutable (no reorg risk), making this suitable for
167
+ * payment detection and reconciliation. Events include block number and
168
+ * event index within the block.
169
+ *
170
+ * For a full production payment listener with reconnection, deduplication,
171
+ * and address filtering, use `TusdtPaymentListener` from `tusdt-sdk/server`.
172
+ *
173
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
174
+ * @returns A function to unsubscribe from the event stream.
175
+ */
176
+ onFinalizedTransfer(callback: (event: FinalizedTransferEvent) => void, options?: WatchFinalizedOptions): Promise<Unsubscribe>;
177
+ /**
178
+ * Subscribe to Transfer events to a specific account on finalized blocks.
179
+ *
180
+ * @param account - SS58 address of the recipient to filter for
181
+ * @param options - Optional. Pass `onError` to receive errors instead of silent skipping.
182
+ * @returns A function to unsubscribe from the event stream.
183
+ */
184
+ onFinalizedTransferTo(account: AccountId, callback: (event: FinalizedTransferEvent) => void, options?: WatchFinalizedOptions): Promise<Unsubscribe>;
185
+ }
186
+ //# sourceMappingURL=tusdt-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tusdt-contract.d.ts","sourceRoot":"","sources":["../../src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AC,WAAW,CAAC;IAIvB;;;;;;OAMG;IACH,YAAY,CACV,OAAO,EAAE,SAAS,EAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACxC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,WAAW,CAAC;IAMvB;;;;;;;;;;;;OAYG;IACH,mBAAmB,CACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAIvB;;;;;;OAMG;IACH,qBAAqB,CACnB,OAAO,EAAE,SAAS,EAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,WAAW,CAAC;CAGxB"}
@@ -0,0 +1,10 @@
1
+ /** u64 maximum value: 2^64 - 1 */
2
+ export declare const U64_MAX: bigint;
3
+ /** Zero balance constant */
4
+ export declare const ZERO_BALANCE: bigint;
5
+ /**
6
+ * 32 zero bytes as hex string.
7
+ * Used as defaultCaller for read-only contract queries when no specific caller is needed.
8
+ */
9
+ export declare const ZERO_ADDRESS: string;
10
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,eAAO,MAAM,OAAO,EAAE,MAAoC,CAAC;AAE3D,4BAA4B;AAC5B,eAAO,MAAM,YAAY,EAAE,MAAW,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,MAA+B,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Base error class for all TUSDT SDK errors.
3
+ */
4
+ export declare class TusdtSdkError extends Error {
5
+ constructor(message: string, options?: ErrorOptions);
6
+ }
7
+ /**
8
+ * Client-side input validation failure.
9
+ * Thrown before any RPC call when inputs are invalid.
10
+ */
11
+ export declare class ValidationError extends TusdtSdkError {
12
+ constructor(message: string);
13
+ }
14
+ /**
15
+ * Base error for contract-returned errors.
16
+ * The contract rejected the call with a typed error variant.
17
+ */
18
+ export declare class ContractError extends TusdtSdkError {
19
+ readonly contractErrorType: string;
20
+ constructor(message: string, contractErrorType: string);
21
+ }
22
+ /**
23
+ * Contract returned InsufficientBalance (error index 0).
24
+ * The sender does not have enough tokens for the transfer.
25
+ */
26
+ export declare class InsufficientBalanceError extends ContractError {
27
+ constructor(message?: string);
28
+ }
29
+ /**
30
+ * Contract returned InsufficientAllowance (error index 1).
31
+ * The spender does not have enough allowance for the transferFrom.
32
+ */
33
+ export declare class InsufficientAllowanceError extends ContractError {
34
+ constructor(message?: string);
35
+ }
36
+ /**
37
+ * Contract returned NotController (error index 2).
38
+ * Only the controller can perform mint/burn operations.
39
+ */
40
+ export declare class NotControllerError extends ContractError {
41
+ constructor(message?: string);
42
+ }
43
+ /**
44
+ * Pallet-level dispatch failure during dry-run.
45
+ * The transaction would fail at the runtime level (e.g., OutOfGas, contract trap).
46
+ */
47
+ export declare class DryRunError extends TusdtSdkError {
48
+ readonly dispatchError: unknown;
49
+ constructor(message: string, dispatchError?: unknown);
50
+ }
51
+ /**
52
+ * On-chain extrinsic failure after submission.
53
+ * The transaction was included in a block but failed during execution.
54
+ */
55
+ export declare class DispatchError extends TusdtSdkError {
56
+ readonly dispatchError: unknown;
57
+ constructor(message: string, dispatchError?: unknown);
58
+ }
59
+ /**
60
+ * WebSocket/RPC connection failure.
61
+ */
62
+ export declare class ConnectionError extends TusdtSdkError {
63
+ constructor(message: string);
64
+ }
65
+ /**
66
+ * Transaction was not included within the expected time.
67
+ */
68
+ export declare class TimeoutError extends TusdtSdkError {
69
+ constructor(message: string);
70
+ }
71
+ /**
72
+ * Maps a Dedot contract error variant to the corresponding typed SDK error.
73
+ *
74
+ * The TUSDT ERC20 contract defines three error variants:
75
+ * - InsufficientBalance (index 0)
76
+ * - InsufficientAllowance (index 1)
77
+ * - NotController (index 2)
78
+ *
79
+ * Dedot's generated types produce these as a string union:
80
+ * `TusdtErc20TusdtError = 'InsufficientBalance' | 'InsufficientAllowance' | 'NotController'`
81
+ *
82
+ * The error may also arrive as an object with a `type` property in some contexts.
83
+ */
84
+ export declare function mapContractError(error: unknown): ContractError;
85
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAC9C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;CAKvD;AAED;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,OAAO,CAAC,EAAE,MAAM;CAO7B;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,aAAa;gBAC/C,OAAO,CAAC,EAAE,MAAM;CAO7B;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;gBACvC,OAAO,CAAC,EAAE,MAAM;CAO7B;AAED;;;GAGG;AACH,qBAAa,WAAY,SAAQ,aAAa;IAC5C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO;CAKrD;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAC9C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO;CAKrD;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAoC9D"}
@@ -0,0 +1,97 @@
1
+ /** u64 token balance, always represented as bigint */
2
+ export type Balance = bigint;
3
+ /** SS58-encoded Substrate account address */
4
+ export type AccountId = string;
5
+ /** Finality level for transaction waiting */
6
+ export type WaitFor = 'bestChainBlockIncluded' | 'finalized';
7
+ /** Options for state-changing transactions */
8
+ export interface TxOptions {
9
+ /** Finality level to wait for. Default: 'bestChainBlockIncluded' */
10
+ waitFor?: WaitFor;
11
+ }
12
+ /** Decoded Transfer event from the TUSDT ERC20 contract */
13
+ export interface TransferEvent {
14
+ /** Sender address, or null for mint events */
15
+ from: AccountId | null;
16
+ /** Recipient address, or null for burn events */
17
+ to: AccountId | null;
18
+ /** Amount transferred (bigint, u64) */
19
+ value: Balance;
20
+ /** Block hash where the event occurred */
21
+ blockHash: string;
22
+ }
23
+ /**
24
+ * Transfer event from a finalized block.
25
+ * Extends TransferEvent with block number and event position.
26
+ * Used by finalized-block watchers and TusdtPaymentListener.
27
+ */
28
+ export interface FinalizedTransferEvent extends TransferEvent {
29
+ /** Block number where the event occurred (finalized) */
30
+ blockNumber: number;
31
+ /** Index among Transfer events from this contract in the block */
32
+ txIndex?: number;
33
+ }
34
+ /** Decoded Approval event from the TUSDT ERC20 contract */
35
+ export interface ApprovalEvent {
36
+ /** Token owner who granted the allowance */
37
+ owner: AccountId;
38
+ /** Spender who received the allowance */
39
+ spender: AccountId;
40
+ /** Approved amount (bigint, u64) */
41
+ value: Balance;
42
+ /** Block hash where the event occurred */
43
+ blockHash: string;
44
+ }
45
+ /** Gas estimation from dry-run */
46
+ export interface QueryGasEstimate {
47
+ refTime: bigint;
48
+ proofSize: bigint;
49
+ }
50
+ /** Result of a successful state-changing transaction */
51
+ export interface TxResult {
52
+ /** Block hash where the tx was included */
53
+ blockHash: string;
54
+ /** Transaction hash */
55
+ txHash: string;
56
+ /** Gas consumed estimate from dry-run */
57
+ gasEstimate: QueryGasEstimate;
58
+ /** Decoded Transfer events from this tx */
59
+ transfers: TransferEvent[];
60
+ /** Decoded Approval events from this tx */
61
+ approvals: ApprovalEvent[];
62
+ }
63
+ /** Unsubscribe function returned by event subscriptions */
64
+ export type Unsubscribe = () => void;
65
+ /** Options for event subscription functions */
66
+ export interface EventSubscriptionOptions {
67
+ /** Called when an error occurs during block event processing */
68
+ onError?: (error: Error) => void;
69
+ }
70
+ /**
71
+ * Signer type accepted by the SDK.
72
+ *
73
+ * Supports two patterns that Dedot natively accepts:
74
+ * 1. IKeyringPair from @polkadot/keyring (backend/testing) - has `address` and `sign` method
75
+ * 2. Injected wallet signer (browser) - has `address` and nested `signer` object
76
+ *
77
+ * Dedot's contract.tx.signAndSend() dispatches based on the shape:
78
+ * - signAndSend(keyringPair) for IKeyringPair
79
+ * - signAndSend(address, { signer }) for injected signers
80
+ */
81
+ export type TusdtSigner = KeyringPairSigner | InjectedWalletSigner;
82
+ /** Backend signer using a keyring pair (has `sign` method directly on the object) */
83
+ export interface KeyringPairSigner {
84
+ readonly address: string;
85
+ sign(data: Uint8Array): Uint8Array;
86
+ /** Keyring pairs have additional properties; this is the minimal interface */
87
+ [key: string]: unknown;
88
+ }
89
+ /** Browser-injected wallet signer */
90
+ export interface InjectedWalletSigner {
91
+ readonly address: string;
92
+ readonly signer: {
93
+ signPayload: (payload: unknown) => Promise<unknown>;
94
+ signRaw?: (raw: unknown) => Promise<unknown>;
95
+ };
96
+ }
97
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,MAAM,OAA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C3C,SAAS,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED,2DAA2D;AAC3D,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,+CAA+C;AAC/C,MAAM,WAAW,wBAAwB;IACvC,gEAAgE;IAChE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,oBAAoB,CAAC;AAEzB,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IACnC,8EAA8E;IAC9E,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qCAAqC;AACrC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE;QACf,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAC9C,CAAC;CACH"}
@@ -0,0 +1,30 @@
1
+ import type { TusdtSigner } from './types.js';
2
+ /**
3
+ * Validates that a value is a valid u64 balance.
4
+ * Throws ValidationError if not bigint, negative, or exceeds u64 max.
5
+ */
6
+ export declare function validateBalance(value: bigint): void;
7
+ /**
8
+ * Validates that an address string is well-formed.
9
+ * Performs lightweight format checks. Full SS58 validation happens
10
+ * at the Dedot/runtime level when encoding parameters.
11
+ */
12
+ export declare function validateAddress(address: string): void;
13
+ /**
14
+ * Validates that adding transferAmount to recipientBalance does not overflow u64.
15
+ * This is a critical pre-flight check because the contract panics on overflow
16
+ * (consuming all gas with an opaque error).
17
+ */
18
+ export declare function validateOverflowSafe(recipientBalance: bigint, transferAmount: bigint): void;
19
+ /**
20
+ * Type guard: checks whether a signer is a KeyringPair (has a `sign` method).
21
+ * This distinguishes backend KeyringPair signers from injected wallet signers.
22
+ */
23
+ export declare function isKeyringPair(signer: TusdtSigner): signer is TusdtSigner & {
24
+ sign: (data: Uint8Array) => Uint8Array;
25
+ };
26
+ /**
27
+ * Extracts the SS58 address from either signer type.
28
+ */
29
+ export declare function getSignerAddress(signer: TusdtSigner): string;
30
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAcnD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAYrD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,GACrB,IAAI,CAMN;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,GAClB,MAAM,IAAI,WAAW,GAAG;IAAE,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAA;CAAE,CAQpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAE5D"}
@@ -0,0 +1,13 @@
1
+ export { TusdtContract } from './contract/tusdt-contract.js';
2
+ export type { TusdtContractOptions, SubstrateClient } from './contract/tusdt-contract.js';
3
+ export type { AccountId, Balance, TusdtSigner, KeyringPairSigner, InjectedWalletSigner, TxOptions, TxResult, TransferEvent, ApprovalEvent, FinalizedTransferEvent, QueryGasEstimate, Unsubscribe, WaitFor, EventSubscriptionOptions, } from './core/types.js';
4
+ export { TusdtSdkError, ValidationError, ContractError, InsufficientBalanceError, InsufficientAllowanceError, NotControllerError, DryRunError, DispatchError, ConnectionError, TimeoutError, mapContractError, } from './core/errors.js';
5
+ export { U64_MAX, ZERO_BALANCE } from './core/constants.js';
6
+ export { queryController, queryTotalSupply, queryBalanceOf, queryAllowance, } from './contract/queries.js';
7
+ export { executeTransfer, executeApprove, executeTransferFrom, } from './contract/transactions.js';
8
+ export { safeApprove } from './contract/helpers.js';
9
+ export { watchFinalizedTransfers, watchFinalizedTransfersTo } from './contract/finalized-events.js';
10
+ export type { WatchFinalizedOptions } from './contract/finalized-events.js';
11
+ export { subscribeTransfer, subscribeApproval, subscribeTransferFrom, subscribeTransferTo, } from './contract/events.js';
12
+ export { validateBalance, validateAddress, validateOverflowSafe, isKeyringPair, getSignerAddress, } from './core/validation.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG1F,YAAY,EACV,SAAS,EACT,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,OAAO,EACP,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AACpG,YAAY,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAG5E,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { ConnectionError, ContractError, DispatchError, DryRunError, InsufficientAllowanceError, InsufficientBalanceError, NotControllerError, TimeoutError, TusdtContract, TusdtSdkError, U64_MAX, ValidationError, ZERO_BALANCE, executeApprove, executeTransfer, executeTransferFrom, getSignerAddress, isKeyringPair, mapContractError, queryAllowance, queryBalanceOf, queryController, queryTotalSupply, safeApprove, subscribeApproval, subscribeTransfer, subscribeTransferFrom, subscribeTransferTo, validateAddress, validateBalance, validateOverflowSafe, watchFinalizedTransfers, watchFinalizedTransfersTo } from './chunk-5HS7VSOA.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,19 @@
1
+ export * from './index.js';
2
+ export { TusdtPaymentListener } from './contract/payment-listener.js';
3
+ export type { PaymentListenerConfig, ReconnectConfig } from './contract/payment-listener.js';
4
+ /**
5
+ * Create an IKeyringPair signer from a secret URI (e.g., "//Alice", "//Bob").
6
+ *
7
+ * This is a convenience helper for backend and testing environments.
8
+ * Uses dynamic imports to avoid hard errors when @polkadot/keyring is not installed.
9
+ *
10
+ * Requires peer dependencies:
11
+ * - @polkadot/keyring
12
+ * - @polkadot/util-crypto
13
+ *
14
+ * @param suri - Secret URI (e.g., "//Alice", "//Bob", or a mnemonic)
15
+ * @param type - Key type. Default: 'sr25519'
16
+ * @returns An IKeyringPair that can be passed as a TusdtSigner
17
+ */
18
+ export declare function createSigner(suri: string, type?: 'sr25519' | 'ed25519'): Promise<import('./core/types.js').KeyringPairSigner>;
19
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAE7F;;;;;;;;;;;;;GAaG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,SAAS,GAAG,SAAqB,GACtC,OAAO,CAAC,OAAO,iBAAiB,EAAE,iBAAiB,CAAC,CAMtD"}