@interchained/usdx 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.
- package/LICENSE +352 -0
- package/README.md +379 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +174 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +39 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
Preamble
|
|
9
|
+
|
|
10
|
+
The GNU General Public License is a free, copyleft license for
|
|
11
|
+
software and other kinds of works.
|
|
12
|
+
|
|
13
|
+
The licenses for most software and other practical works are designed
|
|
14
|
+
to take away your freedom to share and change the works. By contrast,
|
|
15
|
+
the GNU General Public License is intended to guarantee your freedom to
|
|
16
|
+
share and change all versions of a program--to make sure it remains free
|
|
17
|
+
software for all its users. We, the Free Software Foundation, use the
|
|
18
|
+
GNU General Public License for most of our software; it applies also to
|
|
19
|
+
any other work released this way by its authors. You can apply it to
|
|
20
|
+
your programs, too.
|
|
21
|
+
|
|
22
|
+
When we speak of free software, we are talking about freedom, not
|
|
23
|
+
price. Our General Public Licenses are designed to make sure that you
|
|
24
|
+
have the freedom to distribute copies of free software (and charge for
|
|
25
|
+
them if you wish), that you receive source code or can get it if you
|
|
26
|
+
want it, that you can change the software or use pieces of it in new
|
|
27
|
+
free programs, and that you know you can do these things.
|
|
28
|
+
|
|
29
|
+
To protect your rights, we need to prevent others from denying you
|
|
30
|
+
these rights or asking you to surrender the rights. Therefore, you have
|
|
31
|
+
certain responsibilities if you distribute copies of the software, or if
|
|
32
|
+
you modify it: responsibilities to respect the freedom of others.
|
|
33
|
+
|
|
34
|
+
For example, if you distribute copies of such a program, whether
|
|
35
|
+
gratis or for a fee, you must pass on to the recipients the same
|
|
36
|
+
freedoms that you received. You must make sure that they, too, receive
|
|
37
|
+
or can get the source code. And you must show them these terms so they
|
|
38
|
+
know their rights.
|
|
39
|
+
|
|
40
|
+
Developers that use the GNU GPL protect your rights with two steps:
|
|
41
|
+
(1) assert copyright on the software, and (2) offer you this License
|
|
42
|
+
giving you legal permission to copy, distribute and/or modify it.
|
|
43
|
+
|
|
44
|
+
For the developers' and authors' protection, the GPL clearly explains
|
|
45
|
+
that there is no warranty for this free software. For both users' and
|
|
46
|
+
authors' sake, the GPL requires that modified versions be marked as
|
|
47
|
+
changed, so that their problems will not be attributed erroneously to
|
|
48
|
+
authors of previous versions.
|
|
49
|
+
|
|
50
|
+
Some devices are designed to deny users access to install or run
|
|
51
|
+
modified versions of the software inside them, although the manufacturer
|
|
52
|
+
can do so. This is fundamentally incompatible with the aim of
|
|
53
|
+
protecting users' freedom to change the software. The systematic
|
|
54
|
+
pattern of such abuse occurs in the area of products for individuals to
|
|
55
|
+
use, which is precisely where it is most unacceptable. Therefore, we
|
|
56
|
+
have designed this version of the GPL to prohibit the practice for those
|
|
57
|
+
products. If such problems arise substantially in other domains, we
|
|
58
|
+
stand ready to extend this provision to those domains in future versions
|
|
59
|
+
of the GPL, as needed to protect the freedom of users.
|
|
60
|
+
|
|
61
|
+
Finally, every program is threatened constantly by software patents.
|
|
62
|
+
States should not allow patents to restrict development and use of
|
|
63
|
+
software on general-purpose computers, but in those that do, we wish to
|
|
64
|
+
avoid the special danger that patents applied to a free program could
|
|
65
|
+
make it effectively proprietary. To prevent this, the GPL assures that
|
|
66
|
+
patents cannot be used to render the program non-free.
|
|
67
|
+
|
|
68
|
+
The precise terms and conditions for copying, distribution and
|
|
69
|
+
modification follow.
|
|
70
|
+
|
|
71
|
+
TERMS AND CONDITIONS
|
|
72
|
+
|
|
73
|
+
0. Definitions.
|
|
74
|
+
|
|
75
|
+
"This License" refers to version 3 of the GNU General Public License.
|
|
76
|
+
|
|
77
|
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
78
|
+
works, such as semiconductor masks.
|
|
79
|
+
|
|
80
|
+
"The Program" refers to any copyrightable work licensed under this
|
|
81
|
+
License. Each licensee is addressed as "you". "Licensees" and
|
|
82
|
+
"recipients" may be individuals or organizations.
|
|
83
|
+
|
|
84
|
+
To "modify" a work means to copy from or adapt all or part of the work
|
|
85
|
+
in a fashion requiring copyright permission, other than the making of an
|
|
86
|
+
exact copy. The resulting work is called a "modified version" of the
|
|
87
|
+
earlier work or a work "based on" the earlier work.
|
|
88
|
+
|
|
89
|
+
A "covered work" means either the unmodified Program or a work based
|
|
90
|
+
on the Program.
|
|
91
|
+
|
|
92
|
+
To "propagate" a work means to do anything with it that, without
|
|
93
|
+
permission, would make you directly or secondarily liable for
|
|
94
|
+
infringement under applicable copyright law, except executing it on a
|
|
95
|
+
computer or modifying a private copy. Propagation includes copying,
|
|
96
|
+
distribution (with or without modification), making available to the
|
|
97
|
+
public, and in some countries other activities as well.
|
|
98
|
+
|
|
99
|
+
To "convey" a work means any kind of propagation that enables other
|
|
100
|
+
parties to make or receive copies. Mere interaction with a user through
|
|
101
|
+
a computer network, with no transfer of a copy, is not conveying.
|
|
102
|
+
|
|
103
|
+
An interactive user interface displays "Appropriate Legal Notices"
|
|
104
|
+
to the extent that it includes a convenient and prominently visible
|
|
105
|
+
feature that (1) displays an appropriate copyright notice, and (2)
|
|
106
|
+
tells the user that there is no warranty for the work (except to the
|
|
107
|
+
extent that warranties are provided), that licensees may convey the
|
|
108
|
+
work under this License, and how to view a copy of this License. If
|
|
109
|
+
the interface presents a list of user commands or other options, such
|
|
110
|
+
as a menu, a program that is not interactive in that case does not need
|
|
111
|
+
to display this notice.
|
|
112
|
+
|
|
113
|
+
1. Source Code.
|
|
114
|
+
|
|
115
|
+
The "source code" for a work means the preferred form of the work
|
|
116
|
+
for making modifications to it. "Object code" means any non-source
|
|
117
|
+
form of a work.
|
|
118
|
+
|
|
119
|
+
A "Standard Interface" means an interface that either is an official
|
|
120
|
+
standard defined by a recognized standards body, or, in the case of
|
|
121
|
+
interfaces specified for a particular programming language, one that is
|
|
122
|
+
widely used among developers working in that language.
|
|
123
|
+
|
|
124
|
+
The "System Libraries" of an executable work include anything, other
|
|
125
|
+
than the work as a whole, that (a) is included in the normal form of
|
|
126
|
+
packaging a Major Component, but which is not part of that Major
|
|
127
|
+
Component, and (b) serves only to enable use of the work with that
|
|
128
|
+
Major Component, or to implement a Standard Interface for which an
|
|
129
|
+
implementation is available to the public in source code form. A
|
|
130
|
+
"Major Component", in this context, means a major essential component
|
|
131
|
+
(kernel, window system, and so on) of the specific operating system
|
|
132
|
+
(if any) on which the executable work runs, or a compiler used to
|
|
133
|
+
produce the work, or an object code interpreter used to run it.
|
|
134
|
+
|
|
135
|
+
The "Corresponding Source" for a work in object code form means all
|
|
136
|
+
the source code needed to generate, install, and (for an executable
|
|
137
|
+
work) run the object code and to modify the work, including scripts to
|
|
138
|
+
control those activities. However, it does not include the work's
|
|
139
|
+
System Libraries, or general-purpose tools or generally applicable free
|
|
140
|
+
software which is unspecified components of the work. For example, Corresponding Source
|
|
141
|
+
includes interface definition files associated with source files for
|
|
142
|
+
the work, and the source code for shared libraries and dynamically
|
|
143
|
+
linked subprograms that the work is specifically designed to require,
|
|
144
|
+
such as by intimate data communication or control flow between those
|
|
145
|
+
subprograms and other parts of the work.
|
|
146
|
+
|
|
147
|
+
The Corresponding Source need not include anything that users
|
|
148
|
+
can regenerate automatically from other parts of the Corresponding
|
|
149
|
+
Source.
|
|
150
|
+
|
|
151
|
+
The Corresponding Source for a work in source code form is that
|
|
152
|
+
same work.
|
|
153
|
+
|
|
154
|
+
2. Basic Permissions.
|
|
155
|
+
|
|
156
|
+
All rights granted under this License are granted for the term of
|
|
157
|
+
copyright on the Program, and are irrevocable provided the stated
|
|
158
|
+
conditions are met. This License explicitly affirms your unlimited
|
|
159
|
+
permission to run the unmodified Program. The output from running a
|
|
160
|
+
covered work is covered by this License only if the output, given its
|
|
161
|
+
content, constitutes a covered work. This License acknowledges your
|
|
162
|
+
rights of fair use or other equivalent, as provided by copyright law.
|
|
163
|
+
|
|
164
|
+
You may make, run and propagate covered works that you do not
|
|
165
|
+
convey, without conditions so long as your license otherwise remains
|
|
166
|
+
in force. You may convey covered works to others for the sole purpose
|
|
167
|
+
of having them make modifications exclusively for you, or provide you
|
|
168
|
+
with facilities for running those works, provided that you comply with
|
|
169
|
+
the terms of this License in conveying all material for which you do
|
|
170
|
+
not control copyright. Those thus making or running the covered works
|
|
171
|
+
for you must do so exclusively on your behalf, under your direction
|
|
172
|
+
and control, on terms that prohibit them from making any copies of
|
|
173
|
+
your copyrighted material outside their relationship with you.
|
|
174
|
+
|
|
175
|
+
Conveying under any other circumstances is permitted solely under
|
|
176
|
+
the conditions stated below. Sublicensing is not allowed; section 10
|
|
177
|
+
makes it unnecessary.
|
|
178
|
+
|
|
179
|
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
180
|
+
|
|
181
|
+
No covered work shall be deemed part of an effective technological
|
|
182
|
+
measure under any applicable law fulfilling obligations under article
|
|
183
|
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
184
|
+
similar laws prohibiting or restricting circumvention of such
|
|
185
|
+
measures.
|
|
186
|
+
|
|
187
|
+
When you convey a covered work, you waive any legal power to forbid
|
|
188
|
+
circumvention of technological measures to the extent such circumvention
|
|
189
|
+
is effected by exercising rights under this License with respect to
|
|
190
|
+
the covered work, and you disclaim any intention to limit operation or
|
|
191
|
+
modification of the work as a means of enforcing, against the work's
|
|
192
|
+
users, your legal rights or third parties' legal rights to forbid
|
|
193
|
+
circumvention of technological measures.
|
|
194
|
+
|
|
195
|
+
4. Conveying Verbatim Copies.
|
|
196
|
+
|
|
197
|
+
You may convey verbatim copies of the Program's source code as you
|
|
198
|
+
receive it, in any medium, provided that you conspicuously and
|
|
199
|
+
appropriately publish on each copy an appropriate copyright notice and
|
|
200
|
+
disclaimer of warranty; keep intact all notices stating that this
|
|
201
|
+
License and any non-warranty terms added in accord with section 7
|
|
202
|
+
apply to the code; keep intact all notices of the absence of any
|
|
203
|
+
warranty; and give all recipients a copy of this License along with
|
|
204
|
+
the Program.
|
|
205
|
+
|
|
206
|
+
You may charge any price or no price for each copy that you convey,
|
|
207
|
+
and you may offer support or warranty protection for a fee.
|
|
208
|
+
|
|
209
|
+
5. Conveying Modified Source Versions.
|
|
210
|
+
|
|
211
|
+
You may convey a work based on the Program, or the modifications to
|
|
212
|
+
produce it from the Program, in the form of source code under the
|
|
213
|
+
terms of section 4, provided that you also meet all of these conditions:
|
|
214
|
+
|
|
215
|
+
a) The work must carry prominent notices stating that you modified
|
|
216
|
+
it, and giving a relevant date.
|
|
217
|
+
|
|
218
|
+
b) The work must carry prominent notices stating that it is
|
|
219
|
+
released under this License and any conditions added under section
|
|
220
|
+
7. This requirement modifies the requirement in section 4 to
|
|
221
|
+
"keep intact all notices".
|
|
222
|
+
|
|
223
|
+
c) You must license the entire work, as a whole, under this
|
|
224
|
+
License to anyone who comes into possession of a copy. This
|
|
225
|
+
License will therefore apply, along with any applicable section 7
|
|
226
|
+
additional terms, to the whole of the work, and all its parts,
|
|
227
|
+
regardless of how they are packaged. This License gives no
|
|
228
|
+
permission to license the work in any other way, but it does not
|
|
229
|
+
invalidate such permission if you have separately received it.
|
|
230
|
+
|
|
231
|
+
d) If the work has interactive user interfaces, each must display
|
|
232
|
+
Appropriate Legal Notices; however, if the Program has interactive
|
|
233
|
+
interfaces that do not display Appropriate Legal Notices, your
|
|
234
|
+
work need not make them do so.
|
|
235
|
+
|
|
236
|
+
6. Conveying Non-Source Forms.
|
|
237
|
+
|
|
238
|
+
You may convey a covered work in object code form under the terms
|
|
239
|
+
of sections 4 and 5, provided that you also convey the
|
|
240
|
+
machine-readable Corresponding Source under the terms of this License,
|
|
241
|
+
in one of these ways:
|
|
242
|
+
|
|
243
|
+
a) Convey the object code in, or embodied in, a physical product
|
|
244
|
+
(including a physical distribution medium), accompanied by the
|
|
245
|
+
Corresponding Source fixed on a durable physical medium
|
|
246
|
+
customarily used for software interchange.
|
|
247
|
+
|
|
248
|
+
b) Convey the object code in, or embodied in, a physical product
|
|
249
|
+
(including a physical distribution medium), accompanied by a
|
|
250
|
+
written offer, valid for at least three years and valid for
|
|
251
|
+
anyone who comes into possession of a copy of the covered work
|
|
252
|
+
(for binary distributions under subsection 6b), or who received
|
|
253
|
+
the covered work for a price (for source distributions).
|
|
254
|
+
|
|
255
|
+
c) Convey individual copies of the object code with a copy of the
|
|
256
|
+
written offer to provide the Corresponding Source. This
|
|
257
|
+
alternative is allowed only occasionally and noncommercially, and
|
|
258
|
+
only if you received the object code with such an offer, in accord
|
|
259
|
+
with subsection 6b.
|
|
260
|
+
|
|
261
|
+
d) Convey the object code by offering access from a designated
|
|
262
|
+
place (gratis or for a charge), and offer equivalent access to the
|
|
263
|
+
Corresponding Source in the same way through the same place at no
|
|
264
|
+
further charge.
|
|
265
|
+
|
|
266
|
+
e) Convey the object code using peer-to-peer transmission, provided
|
|
267
|
+
you inform other peers where the object code and Corresponding
|
|
268
|
+
Source of the work are being offered to the public at no charge
|
|
269
|
+
under subsection 6d.
|
|
270
|
+
|
|
271
|
+
7. Additional Terms.
|
|
272
|
+
|
|
273
|
+
"Additional permissions" are terms that supplement the terms of this
|
|
274
|
+
License by making exceptions from one or more of its conditions.
|
|
275
|
+
|
|
276
|
+
8. Termination.
|
|
277
|
+
|
|
278
|
+
You may not propagate or modify a covered work except as expressly
|
|
279
|
+
provided under this License.
|
|
280
|
+
|
|
281
|
+
9. Acceptance Not Required for Having Copies.
|
|
282
|
+
|
|
283
|
+
You are not required to accept this License in order to receive or
|
|
284
|
+
run a copy of the Program.
|
|
285
|
+
|
|
286
|
+
10. Automatic Licensing of Downstream Recipients.
|
|
287
|
+
|
|
288
|
+
Each time you convey a covered work, the recipient automatically
|
|
289
|
+
receives a license from the original licensors, to run, modify and
|
|
290
|
+
propagate that work, subject to this License.
|
|
291
|
+
|
|
292
|
+
11. Patents.
|
|
293
|
+
|
|
294
|
+
A "contributor" is a copyright holder who authorizes use under this
|
|
295
|
+
License of the Program or a work on which the Program is based.
|
|
296
|
+
|
|
297
|
+
12. No Surrender of Others' Freedom.
|
|
298
|
+
|
|
299
|
+
If conditions are imposed on you (whether by court order, agreement or
|
|
300
|
+
otherwise) that contradict the conditions of this License, they do not
|
|
301
|
+
excuse you from the conditions of this License.
|
|
302
|
+
|
|
303
|
+
13. Use with the GNU Affero General Public License.
|
|
304
|
+
|
|
305
|
+
Notwithstanding any other provision of this License, you have
|
|
306
|
+
permission to link or combine any covered work with a work licensed
|
|
307
|
+
under version 3 of the GNU Affero General Public License into a single
|
|
308
|
+
combined work, and to convey the resulting work.
|
|
309
|
+
|
|
310
|
+
14. Revised Versions of this License.
|
|
311
|
+
|
|
312
|
+
The Free Software Foundation may publish revised and/or new versions of
|
|
313
|
+
the GNU General Public License from time to time.
|
|
314
|
+
|
|
315
|
+
15. Disclaimer of Warranty.
|
|
316
|
+
|
|
317
|
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
318
|
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
319
|
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
320
|
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
321
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
322
|
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
323
|
+
IS WITH YOU.
|
|
324
|
+
|
|
325
|
+
16. Limitation of Liability.
|
|
326
|
+
|
|
327
|
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
328
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
329
|
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
330
|
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
331
|
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
332
|
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
333
|
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
334
|
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
335
|
+
SUCH DAMAGES.
|
|
336
|
+
|
|
337
|
+
END OF TERMS AND CONDITIONS
|
|
338
|
+
|
|
339
|
+
Copyright (C) Interchained Contributors
|
|
340
|
+
|
|
341
|
+
This program is free software: you can redistribute it and/or modify
|
|
342
|
+
it under the terms of the GNU General Public License as published by
|
|
343
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
344
|
+
(at your option) any later version.
|
|
345
|
+
|
|
346
|
+
This program is distributed in the hope that it will be useful,
|
|
347
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
348
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
349
|
+
GNU General Public License for more details.
|
|
350
|
+
|
|
351
|
+
You should have received a copy of the GNU General Public License
|
|
352
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
package/README.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<img src="https://img.shields.io/badge/%40interchained%2Fusdx-TypeScript%20SDK-3178C6?style=for-the-badge&logo=typescript&logoColor=white" alt="@interchained/usdx"/>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<h1 align="center">💠 @interchained/usdx</h1>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<strong>Typed TypeScript HTTP client for the USDx wallet API.</strong><br/>
|
|
10
|
+
Zero production dependencies. Runs everywhere. Strict by default.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/@interchained/usdx"><img src="https://img.shields.io/npm/v/@interchained/usdx?color=CB3837&style=flat-square&logo=npm&logoColor=white" alt="npm version"/></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-18%2B-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node 18+"/>
|
|
16
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript strict"/>
|
|
17
|
+
<img src="https://img.shields.io/badge/deps-zero-brightgreen?style=flat-square" alt="Zero deps"/>
|
|
18
|
+
<img src="https://img.shields.io/badge/runtime-Node%20%7C%20Browser%20%7C%20Deno%20%7C%20Bun-black?style=flat-square" alt="Universal runtime"/>
|
|
19
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-GPLv3-blue?style=flat-square" alt="License: GPLv3"/></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## ⚡ The Lore
|
|
25
|
+
|
|
26
|
+
> *USDx is the stable settlement currency of the Interchained network — the financial bloodstream that connects creators, node operators, traders, and builders.*
|
|
27
|
+
>
|
|
28
|
+
> *On the server, [`interchained-usdx`](https://github.com/interchained/usdx-py) guards every balance with atomic Lua scripts running inside Redis. No locks. No races. No double-spends.*
|
|
29
|
+
>
|
|
30
|
+
> *This package is the client side of that contract — a zero-dependency TypeScript SDK that speaks fluent HTTP to any server built on the Python package. Fully typed. Strict. Runs in every JavaScript runtime that ships native `fetch`.*
|
|
31
|
+
>
|
|
32
|
+
> *Whether you're building a Next.js dashboard, a React Native wallet, or a serverless Cloudflare Worker — this is how you talk to USDx.*
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📦 Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# npm
|
|
40
|
+
npm install @interchained/usdx
|
|
41
|
+
|
|
42
|
+
# pnpm
|
|
43
|
+
pnpm add @interchained/usdx
|
|
44
|
+
|
|
45
|
+
# yarn
|
|
46
|
+
yarn add @interchained/usdx
|
|
47
|
+
|
|
48
|
+
# bun
|
|
49
|
+
bun add @interchained/usdx
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🏗️ How it fits together
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
58
|
+
│ Your TypeScript / Next.js / React Native / Cloudflare app │
|
|
59
|
+
│ │
|
|
60
|
+
│ import { USDxClient } from "@interchained/usdx" │
|
|
61
|
+
│ │
|
|
62
|
+
│ ✓ zero production deps ✓ native fetch │
|
|
63
|
+
│ ✓ strict TypeScript ✓ Node • Browser • Deno • Bun │
|
|
64
|
+
└──────────────────────┬───────────────────────────────────────┘
|
|
65
|
+
│ HTTP / REST
|
|
66
|
+
│ (JSON, standard HTTP status codes)
|
|
67
|
+
┌──────────────────────▼───────────────────────────────────────┐
|
|
68
|
+
│ FastAPI wallet server (interchained-usdx Python package) │
|
|
69
|
+
│ │
|
|
70
|
+
│ from usdx import USDxWallet, NowPaymentsService, … │
|
|
71
|
+
│ │
|
|
72
|
+
│ ✓ Lua atomic scripts ✓ NowPayments IPN handler │
|
|
73
|
+
│ ✓ PSBT payout builder ✓ OTC rate engine │
|
|
74
|
+
└──────────────────────┬───────────────────────────────────────┘
|
|
75
|
+
│
|
|
76
|
+
┌───────▼────────┐
|
|
77
|
+
│ Redis 6+ │
|
|
78
|
+
│ (the source │
|
|
79
|
+
│ of truth) │
|
|
80
|
+
└────────────────┘
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🚀 Quick start
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { USDxClient } from "@interchained/usdx";
|
|
89
|
+
|
|
90
|
+
const client = new USDxClient({
|
|
91
|
+
baseUrl: "https://api.yourapp.com",
|
|
92
|
+
apiKey: "your-api-key", // optional — sent as X-Api-Key
|
|
93
|
+
timeoutMs: 10_000,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ── Balance ───────────────────────────────────────────────────
|
|
97
|
+
const { balance } = await client.getBalance("alice");
|
|
98
|
+
console.log(balance); // 20.74
|
|
99
|
+
|
|
100
|
+
const info = await client.getInfo("alice");
|
|
101
|
+
console.log(info.is_frozen); // false
|
|
102
|
+
console.log(info.total_credited); // 50.00
|
|
103
|
+
|
|
104
|
+
const history = await client.getHistory("alice", { limit: 10 });
|
|
105
|
+
// → Transaction[]
|
|
106
|
+
|
|
107
|
+
// ── Credit / Debit ────────────────────────────────────────────
|
|
108
|
+
const tx = await client.credit({
|
|
109
|
+
userId: "alice",
|
|
110
|
+
amount: 10.00,
|
|
111
|
+
description: "Article view earnings",
|
|
112
|
+
txType: "view_reward",
|
|
113
|
+
multiplier: 1.5, // 1.5× for premium — applied atomically server-side
|
|
114
|
+
});
|
|
115
|
+
console.log(tx.amount); // 15.0
|
|
116
|
+
console.log(tx.balance_after); // 35.74
|
|
117
|
+
|
|
118
|
+
// Both InsufficientBalance and AccountFrozen are first-class error types
|
|
119
|
+
try {
|
|
120
|
+
await client.debit({ userId: "alice", amount: 3.99, description: "Subscription" });
|
|
121
|
+
} catch (e) {
|
|
122
|
+
if (e instanceof InsufficientBalance) console.log("Not enough funds");
|
|
123
|
+
if (e instanceof AccountFrozen) console.log("Account is locked");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ── Transfer ──────────────────────────────────────────────────
|
|
127
|
+
const { debit, credit } = await client.transfer({
|
|
128
|
+
fromUser: "alice",
|
|
129
|
+
toUser: "bob",
|
|
130
|
+
amount: 5.00,
|
|
131
|
+
description: "Tip",
|
|
132
|
+
});
|
|
133
|
+
console.log(debit.balance_after, credit.balance_after);
|
|
134
|
+
|
|
135
|
+
// ── Freeze / Unfreeze (fraud protection) ─────────────────────
|
|
136
|
+
await client.freeze("alice");
|
|
137
|
+
await client.unfreeze("alice");
|
|
138
|
+
|
|
139
|
+
// ── NowPayments crypto deposits ───────────────────────────────
|
|
140
|
+
const invoice = await client.createDeposit({
|
|
141
|
+
userId: "alice",
|
|
142
|
+
amount: 25.00,
|
|
143
|
+
currency: "usdttrc20", // any of 22 supported coins
|
|
144
|
+
});
|
|
145
|
+
console.log(invoice.payment_url); // Redirect user here ↗
|
|
146
|
+
|
|
147
|
+
const status = await client.checkPayment("payment_id_here");
|
|
148
|
+
console.log(status.status); // "waiting" | "confirming" | "finished" | "failed"
|
|
149
|
+
|
|
150
|
+
const result = await client.claimPayment("payment_id_here");
|
|
151
|
+
// result.already_processed === true if already claimed (idempotent)
|
|
152
|
+
|
|
153
|
+
// ── OTC rate engine ───────────────────────────────────────────
|
|
154
|
+
const rate = await client.getOtcRate(); // ITC per 1 USDx (e.g. 10.5)
|
|
155
|
+
const stats = await client.getOtcStats(); // { itc_reserve, usdx_supply, current_rate, … }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 📚 Full API reference
|
|
161
|
+
|
|
162
|
+
### `new USDxClient(options)`
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
new USDxClient({
|
|
166
|
+
baseUrl: string, // required — your wallet server URL
|
|
167
|
+
apiKey?: string, // sent as X-Api-Key header
|
|
168
|
+
headers?: Record<string, string>, // merged into every request
|
|
169
|
+
timeoutMs?: number, // default: 30_000 ms
|
|
170
|
+
fetch?: typeof fetch, // swap in a polyfill or test mock
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### Balance operations
|
|
177
|
+
|
|
178
|
+
| Method | Signature | Returns |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| `getBalance` | `(userId: string)` | `Promise<{ user_id: string; balance: number }>` |
|
|
181
|
+
| `getInfo` | `(userId: string)` | `Promise<BalanceInfo>` |
|
|
182
|
+
| `getHistory` | `(userId: string, opts?: { limit?, offset? })` | `Promise<Transaction[]>` |
|
|
183
|
+
| `credit` | `(opts: CreditOptions)` | `Promise<Transaction>` |
|
|
184
|
+
| `debit` | `(opts: DebitOptions)` | `Promise<Transaction>` |
|
|
185
|
+
| `transfer` | `(opts: TransferOptions)` | `Promise<TransferResult>` |
|
|
186
|
+
| `freeze` | `(userId: string)` | `Promise<void>` |
|
|
187
|
+
| `unfreeze` | `(userId: string)` | `Promise<void>` |
|
|
188
|
+
|
|
189
|
+
### Deposits
|
|
190
|
+
|
|
191
|
+
| Method | Signature | Returns |
|
|
192
|
+
|---|---|---|
|
|
193
|
+
| `createDeposit` | `(opts: DepositOptions)` | `Promise<DepositInvoice>` |
|
|
194
|
+
| `checkPayment` | `(paymentId: string)` | `Promise<PaymentStatus>` |
|
|
195
|
+
| `claimPayment` | `(paymentId: string)` | `Promise<ClaimResult>` |
|
|
196
|
+
|
|
197
|
+
### OTC rate engine
|
|
198
|
+
|
|
199
|
+
| Method | Signature | Returns |
|
|
200
|
+
|---|---|---|
|
|
201
|
+
| `getOtcRate` | `()` | `Promise<number>` |
|
|
202
|
+
| `getOtcStats` | `()` | `Promise<OtcStats>` |
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 🔷 TypeScript types
|
|
207
|
+
|
|
208
|
+
All types are exported from the package root. Import only what you need.
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import type {
|
|
212
|
+
// Core wallet
|
|
213
|
+
Transaction,
|
|
214
|
+
BalanceInfo,
|
|
215
|
+
TransferResult,
|
|
216
|
+
|
|
217
|
+
// Deposits
|
|
218
|
+
DepositInvoice,
|
|
219
|
+
PaymentStatus,
|
|
220
|
+
ClaimResult,
|
|
221
|
+
|
|
222
|
+
// OTC
|
|
223
|
+
OtcStats,
|
|
224
|
+
|
|
225
|
+
// Request option shapes
|
|
226
|
+
CreditOptions,
|
|
227
|
+
DebitOptions,
|
|
228
|
+
TransferOptions,
|
|
229
|
+
DepositOptions,
|
|
230
|
+
} from "@interchained/usdx";
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Key type shapes
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
interface Transaction {
|
|
237
|
+
id: string;
|
|
238
|
+
user_id: string;
|
|
239
|
+
direction: "credit" | "debit";
|
|
240
|
+
tx_type: string;
|
|
241
|
+
amount: number;
|
|
242
|
+
balance_after: number;
|
|
243
|
+
description: string;
|
|
244
|
+
metadata: Record<string, unknown> | null;
|
|
245
|
+
created_at: string; // ISO 8601
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
interface BalanceInfo {
|
|
249
|
+
user_id: string;
|
|
250
|
+
balance: number;
|
|
251
|
+
total_credited: number;
|
|
252
|
+
total_debited: number;
|
|
253
|
+
is_frozen: boolean;
|
|
254
|
+
created_at: string | null;
|
|
255
|
+
last_updated: string | null;
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## 🚨 Error handling
|
|
262
|
+
|
|
263
|
+
All SDK errors extend `USDxError`. Each is a concrete class you can `instanceof` against.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { USDxError, InsufficientBalance, AccountFrozen, HttpError } from "@interchained/usdx";
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
await client.debit({ userId: "alice", amount: 999_999, description: "YOLO" });
|
|
270
|
+
} catch (e) {
|
|
271
|
+
if (e instanceof InsufficientBalance) {
|
|
272
|
+
// HTTP 422 — balance too low
|
|
273
|
+
console.log("Not enough funds:", e.message);
|
|
274
|
+
}
|
|
275
|
+
else if (e instanceof AccountFrozen) {
|
|
276
|
+
// HTTP 403 — account is locked by fraud protection
|
|
277
|
+
console.log("Account locked:", e.message);
|
|
278
|
+
}
|
|
279
|
+
else if (e instanceof HttpError) {
|
|
280
|
+
// Any other non-2xx response
|
|
281
|
+
console.log(`HTTP ${e.statusCode}:`, e.message);
|
|
282
|
+
}
|
|
283
|
+
else if (e instanceof USDxError) {
|
|
284
|
+
// Network timeout, DNS failure, etc.
|
|
285
|
+
console.log("SDK error:", e.message);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 🔬 Bring your own `fetch`
|
|
293
|
+
|
|
294
|
+
The client accepts a custom `fetch` function — useful for testing, polyfilling, or logging every request.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
// ── Test mocking ──────────────────────────────────────────────
|
|
298
|
+
const client = new USDxClient({
|
|
299
|
+
baseUrl: "http://localhost:8000",
|
|
300
|
+
fetch: async (url, init) => {
|
|
301
|
+
// intercept, inspect, or stub any request
|
|
302
|
+
return mockFetch(url, init);
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// ── Node.js < 18 polyfill ────────────────────────────────────
|
|
307
|
+
import nodeFetch from "node-fetch";
|
|
308
|
+
const client = new USDxClient({ baseUrl: "...", fetch: nodeFetch as typeof fetch });
|
|
309
|
+
|
|
310
|
+
// ── Request logging middleware ────────────────────────────────
|
|
311
|
+
const client = new USDxClient({
|
|
312
|
+
baseUrl: "...",
|
|
313
|
+
fetch: async (url, init) => {
|
|
314
|
+
console.log("→", init?.method, url);
|
|
315
|
+
const res = await fetch(url, init);
|
|
316
|
+
console.log("←", res.status);
|
|
317
|
+
return res;
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## 📁 Examples
|
|
325
|
+
|
|
326
|
+
See [`examples/`](examples/) for runnable code:
|
|
327
|
+
|
|
328
|
+
| Example | Description |
|
|
329
|
+
|---|---|
|
|
330
|
+
| [`quickstart.ts`](examples/quickstart.ts) | End-to-end Node.js script covering every `USDxClient` method |
|
|
331
|
+
| [`express-wallet-app/`](examples/express-wallet-app/) | Express skeleton that uses `USDxClient` as a proxy layer — add your auth, validation, and business logic on top |
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## 🔨 Building from source
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
npm install
|
|
339
|
+
npm run build # compiles to dist/ (ESM .js + .d.ts)
|
|
340
|
+
npm run check # tsc --noEmit (strict, zero warnings)
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 🐍 Server-side companion
|
|
346
|
+
|
|
347
|
+
This SDK is the client half of the USDx stack. The server half is built with the Python package:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
pip install interchained-usdx
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
See [`interchained-usdx` on PyPI](https://pypi.org/project/interchained-usdx/) and the
|
|
354
|
+
[`usdx-py` repo](https://github.com/interchained/usdx-py) for the full wallet engine, NowPayments IPN handler, PSBT builder, and OTC rate engine.
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## 🤝 Contributing
|
|
359
|
+
|
|
360
|
+
1. Fork → branch → make your changes
|
|
361
|
+
2. `npm run check` — zero TypeScript errors
|
|
362
|
+
3. `npm run build` — clean build with no new `.js` artifacts committed
|
|
363
|
+
4. Open a PR with a clear description of what changed and why
|
|
364
|
+
|
|
365
|
+
Please report security issues via private message, not public issues.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## 📜 License
|
|
370
|
+
|
|
371
|
+
GNU General Public License v3.0 or later.
|
|
372
|
+
See [LICENSE](LICENSE) for the full text.
|
|
373
|
+
|
|
374
|
+
```
|
|
375
|
+
@interchained/usdx Copyright (C) 2024 Interchained
|
|
376
|
+
This program comes with ABSOLUTELY NO WARRANTY.
|
|
377
|
+
This is free software, and you are welcome to redistribute it
|
|
378
|
+
under the terms of the GPLv3.
|
|
379
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USDxClient — typed HTTP SDK for the USDx wallet API.
|
|
3
|
+
*
|
|
4
|
+
* Works in Node.js 18+, browsers, Deno, and Bun (any runtime with
|
|
5
|
+
* native `fetch`). Pass a custom `fetch` in options to support older
|
|
6
|
+
* environments or for test mocking.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { USDxClient } from "@interchained/usdx";
|
|
10
|
+
* const client = new USDxClient("https://api.yourapp.com");
|
|
11
|
+
* const balance = await client.getBalance("alice");
|
|
12
|
+
*/
|
|
13
|
+
import type { BalanceInfo, ClaimResult, CreditOptions, DebitOptions, DepositInvoice, OtcStats, PaymentStatus, Transaction, TransferOptions, TransferResult, USDxClientOptions } from "./types.js";
|
|
14
|
+
export declare class USDxClient {
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
private readonly defaultHeaders;
|
|
17
|
+
private readonly _fetch;
|
|
18
|
+
constructor(baseUrl: string, options?: USDxClientOptions);
|
|
19
|
+
/** Return the current USDx balance for a user (0 if account is new). */
|
|
20
|
+
getBalance(userId: string): Promise<number>;
|
|
21
|
+
/** Return full account state for a user. */
|
|
22
|
+
getInfo(userId: string): Promise<BalanceInfo>;
|
|
23
|
+
/** Return the most recent transactions for a user, newest first. */
|
|
24
|
+
getHistory(userId: string, limit?: number): Promise<Transaction[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Credit (add) USDx to a user's account.
|
|
27
|
+
*
|
|
28
|
+
* @param multiplier - Pass `1.5` for premium users; server default is `1.0`.
|
|
29
|
+
*/
|
|
30
|
+
credit(userId: string, amount: number, options?: CreditOptions): Promise<Transaction>;
|
|
31
|
+
/**
|
|
32
|
+
* Debit (subtract) USDx from a user's account.
|
|
33
|
+
*
|
|
34
|
+
* @throws {InsufficientBalance} if the balance is too low.
|
|
35
|
+
* @throws {AccountFrozen} if the account has been frozen.
|
|
36
|
+
*/
|
|
37
|
+
debit(userId: string, amount: number, options?: DebitOptions): Promise<Transaction>;
|
|
38
|
+
/**
|
|
39
|
+
* Atomically transfer USDx from one user to another.
|
|
40
|
+
*
|
|
41
|
+
* @throws {InsufficientBalance} if `fromId` doesn't have enough balance.
|
|
42
|
+
* @throws {AccountFrozen} if `fromId`'s account is frozen.
|
|
43
|
+
*/
|
|
44
|
+
transfer(fromId: string, toId: string, amount: number, options?: TransferOptions): Promise<TransferResult>;
|
|
45
|
+
/** Freeze an account — blocks all future debits and transfers out. */
|
|
46
|
+
freeze(userId: string): Promise<void>;
|
|
47
|
+
/** Lift a freeze on an account. */
|
|
48
|
+
unfreeze(userId: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a NowPayments hosted invoice for a crypto deposit.
|
|
51
|
+
*
|
|
52
|
+
* @param currency - NowPayments currency code, e.g. `"usdttrc20"`, `"btc"`, `"eth"`.
|
|
53
|
+
*/
|
|
54
|
+
createDeposit(userId: string, amount: number, currency?: string): Promise<DepositInvoice>;
|
|
55
|
+
/** Check the current status of a NowPayments payment. */
|
|
56
|
+
checkPayment(paymentId: string): Promise<PaymentStatus>;
|
|
57
|
+
/**
|
|
58
|
+
* Claim a completed payment — idempotent, safe to call multiple times.
|
|
59
|
+
* Returns `already_processed: true` if the payment was claimed before.
|
|
60
|
+
*/
|
|
61
|
+
claimPayment(paymentId: string): Promise<ClaimResult>;
|
|
62
|
+
/** Return the current ITC-per-USDx exchange rate. */
|
|
63
|
+
getOtcRate(): Promise<number>;
|
|
64
|
+
/** Return full OTC pool statistics. */
|
|
65
|
+
getOtcStats(): Promise<OtcStats>;
|
|
66
|
+
private _get;
|
|
67
|
+
private _post;
|
|
68
|
+
private _request;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;gBAErC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAe5D,wEAAwE;IAClE,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOjD,4CAA4C;IACtC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAMnD,oEAAoE;IAC9D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAMpE;;;;OAIG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,WAAW,CAAC;IAQvB;;;;;OAKG;IACG,KAAK,CACT,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,WAAW,CAAC;IAQvB;;;;;OAKG;IACG,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC;IAS1B,sEAAsE;IAChE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C,mCAAmC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C;;;;OAIG;IACG,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,SAAc,GACrB,OAAO,CAAC,cAAc,CAAC;IAQ1B,yDAAyD;IACnD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAM7D;;;OAGG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU3D,qDAAqD;IAC/C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAKnC,uCAAuC;IACjC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC;YAQxB,IAAI;YAIJ,KAAK;YAIL,QAAQ;CA8CvB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USDxClient — typed HTTP SDK for the USDx wallet API.
|
|
3
|
+
*
|
|
4
|
+
* Works in Node.js 18+, browsers, Deno, and Bun (any runtime with
|
|
5
|
+
* native `fetch`). Pass a custom `fetch` in options to support older
|
|
6
|
+
* environments or for test mocking.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { USDxClient } from "@interchained/usdx";
|
|
10
|
+
* const client = new USDxClient("https://api.yourapp.com");
|
|
11
|
+
* const balance = await client.getBalance("alice");
|
|
12
|
+
*/
|
|
13
|
+
import { AccountFrozen, HttpError, InsufficientBalance, USDxError, } from "./errors.js";
|
|
14
|
+
export class USDxClient {
|
|
15
|
+
constructor(baseUrl, options = {}) {
|
|
16
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
17
|
+
this._fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
18
|
+
this.defaultHeaders = {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
Accept: "application/json",
|
|
21
|
+
...(options.apiKey ? { "X-Api-Key": options.apiKey } : {}),
|
|
22
|
+
...options.headers,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Balance operations
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/** Return the current USDx balance for a user (0 if account is new). */
|
|
29
|
+
async getBalance(userId) {
|
|
30
|
+
const data = await this._get(`/balance/${encodeURIComponent(userId)}`);
|
|
31
|
+
return data.balance;
|
|
32
|
+
}
|
|
33
|
+
/** Return full account state for a user. */
|
|
34
|
+
async getInfo(userId) {
|
|
35
|
+
return this._get(`/balance/${encodeURIComponent(userId)}/info`);
|
|
36
|
+
}
|
|
37
|
+
/** Return the most recent transactions for a user, newest first. */
|
|
38
|
+
async getHistory(userId, limit = 50) {
|
|
39
|
+
return this._get(`/balance/${encodeURIComponent(userId)}/history?limit=${limit}`);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Credit (add) USDx to a user's account.
|
|
43
|
+
*
|
|
44
|
+
* @param multiplier - Pass `1.5` for premium users; server default is `1.0`.
|
|
45
|
+
*/
|
|
46
|
+
async credit(userId, amount, options = {}) {
|
|
47
|
+
return this._post("/wallet/credit", {
|
|
48
|
+
user_id: userId,
|
|
49
|
+
amount,
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Debit (subtract) USDx from a user's account.
|
|
55
|
+
*
|
|
56
|
+
* @throws {InsufficientBalance} if the balance is too low.
|
|
57
|
+
* @throws {AccountFrozen} if the account has been frozen.
|
|
58
|
+
*/
|
|
59
|
+
async debit(userId, amount, options = {}) {
|
|
60
|
+
return this._post("/wallet/debit", {
|
|
61
|
+
user_id: userId,
|
|
62
|
+
amount,
|
|
63
|
+
...options,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Atomically transfer USDx from one user to another.
|
|
68
|
+
*
|
|
69
|
+
* @throws {InsufficientBalance} if `fromId` doesn't have enough balance.
|
|
70
|
+
* @throws {AccountFrozen} if `fromId`'s account is frozen.
|
|
71
|
+
*/
|
|
72
|
+
async transfer(fromId, toId, amount, options = {}) {
|
|
73
|
+
return this._post("/wallet/transfer", {
|
|
74
|
+
from_id: fromId,
|
|
75
|
+
to_id: toId,
|
|
76
|
+
amount,
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Freeze an account — blocks all future debits and transfers out. */
|
|
81
|
+
async freeze(userId) {
|
|
82
|
+
await this._post("/wallet/freeze", { user_id: userId });
|
|
83
|
+
}
|
|
84
|
+
/** Lift a freeze on an account. */
|
|
85
|
+
async unfreeze(userId) {
|
|
86
|
+
await this._post("/wallet/unfreeze", { user_id: userId });
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// NowPayments deposits
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* Create a NowPayments hosted invoice for a crypto deposit.
|
|
93
|
+
*
|
|
94
|
+
* @param currency - NowPayments currency code, e.g. `"usdttrc20"`, `"btc"`, `"eth"`.
|
|
95
|
+
*/
|
|
96
|
+
async createDeposit(userId, amount, currency = "usdttrc20") {
|
|
97
|
+
return this._post("/deposit/create", {
|
|
98
|
+
user_id: userId,
|
|
99
|
+
amount,
|
|
100
|
+
currency,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Check the current status of a NowPayments payment. */
|
|
104
|
+
async checkPayment(paymentId) {
|
|
105
|
+
return this._get(`/payment/${encodeURIComponent(paymentId)}`);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Claim a completed payment — idempotent, safe to call multiple times.
|
|
109
|
+
* Returns `already_processed: true` if the payment was claimed before.
|
|
110
|
+
*/
|
|
111
|
+
async claimPayment(paymentId) {
|
|
112
|
+
return this._post(`/payment/${encodeURIComponent(paymentId)}/claim`);
|
|
113
|
+
}
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
// OTC rate engine
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
/** Return the current ITC-per-USDx exchange rate. */
|
|
118
|
+
async getOtcRate() {
|
|
119
|
+
const data = await this._get("/otc/rate");
|
|
120
|
+
return data.rate;
|
|
121
|
+
}
|
|
122
|
+
/** Return full OTC pool statistics. */
|
|
123
|
+
async getOtcStats() {
|
|
124
|
+
return this._get("/otc/stats");
|
|
125
|
+
}
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Internal helpers
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
async _get(path) {
|
|
130
|
+
return this._request("GET", path);
|
|
131
|
+
}
|
|
132
|
+
async _post(path, body) {
|
|
133
|
+
return this._request("POST", path, body);
|
|
134
|
+
}
|
|
135
|
+
async _request(method, path, body) {
|
|
136
|
+
const url = `${this.baseUrl}${path}`;
|
|
137
|
+
const init = {
|
|
138
|
+
method,
|
|
139
|
+
headers: this.defaultHeaders,
|
|
140
|
+
};
|
|
141
|
+
if (body !== undefined) {
|
|
142
|
+
init.body = JSON.stringify(body);
|
|
143
|
+
}
|
|
144
|
+
let res;
|
|
145
|
+
try {
|
|
146
|
+
res = await this._fetch(url, init);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
throw new USDxError(`Network error reaching USDx server: ${err.message}`);
|
|
150
|
+
}
|
|
151
|
+
if (!res.ok) {
|
|
152
|
+
const text = await res.text().catch(() => "");
|
|
153
|
+
let message = text;
|
|
154
|
+
try {
|
|
155
|
+
const parsed = JSON.parse(text);
|
|
156
|
+
message =
|
|
157
|
+
String(parsed.detail ?? parsed.message ?? parsed.error ?? text);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// use raw text
|
|
161
|
+
}
|
|
162
|
+
const lower = message.toLowerCase();
|
|
163
|
+
if (lower.includes("insufficient") || lower.includes("balance")) {
|
|
164
|
+
throw new InsufficientBalance(message);
|
|
165
|
+
}
|
|
166
|
+
if (lower.includes("frozen")) {
|
|
167
|
+
throw new AccountFrozen(message);
|
|
168
|
+
}
|
|
169
|
+
throw new HttpError(res.status, message);
|
|
170
|
+
}
|
|
171
|
+
return res.json();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,SAAS,GACV,MAAM,aAAa,CAAC;AAerB,MAAM,OAAO,UAAU;IAKrB,YAAY,OAAe,EAAE,UAA6B,EAAE;QAC1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjE,IAAI,CAAC,cAAc,GAAG;YACpB,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,OAAO,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,OAAO,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;YACpE,CAAC;YAAC,MAAM,CAAC;gBACP,eAAe;YACjB,CAAC;YAED,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAChE,MAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;YACzC,CAAC;YACD,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YACD,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAgB,CAAC;IAClC,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the USDx SDK.
|
|
3
|
+
*
|
|
4
|
+
* All errors thrown by USDxClient are subclasses of USDxError so you can
|
|
5
|
+
* catch the entire family with a single `catch (e) { if (e instanceof USDxError) … }`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class USDxError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/** The account doesn't have enough balance for the requested debit / transfer. */
|
|
11
|
+
export declare class InsufficientBalance extends USDxError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
/** The account is frozen — all outgoing operations are blocked. */
|
|
15
|
+
export declare class AccountFrozen extends USDxError {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
18
|
+
/** The USDx server returned an unexpected HTTP error. */
|
|
19
|
+
export declare class HttpError extends USDxError {
|
|
20
|
+
readonly statusCode: number;
|
|
21
|
+
constructor(statusCode: number, message: string);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAK5B;AAED,kFAAkF;AAClF,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,SAA+B;CAKnD;AAED,mEAAmE;AACnE,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,SAAuB;CAK3C;AAED,yDAAyD;AACzD,qBAAa,SAAU,SAAQ,SAAS;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMhD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the USDx SDK.
|
|
3
|
+
*
|
|
4
|
+
* All errors thrown by USDxClient are subclasses of USDxError so you can
|
|
5
|
+
* catch the entire family with a single `catch (e) { if (e instanceof USDxError) … }`.
|
|
6
|
+
*/
|
|
7
|
+
export class USDxError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "USDxError";
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The account doesn't have enough balance for the requested debit / transfer. */
|
|
15
|
+
export class InsufficientBalance extends USDxError {
|
|
16
|
+
constructor(message = "Insufficient USDx balance.") {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "InsufficientBalance";
|
|
19
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The account is frozen — all outgoing operations are blocked. */
|
|
23
|
+
export class AccountFrozen extends USDxError {
|
|
24
|
+
constructor(message = "Account is frozen.") {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "AccountFrozen";
|
|
27
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The USDx server returned an unexpected HTTP error. */
|
|
31
|
+
export class HttpError extends USDxError {
|
|
32
|
+
constructor(statusCode, message) {
|
|
33
|
+
super(`HTTP ${statusCode}: ${message}`);
|
|
34
|
+
this.name = "HttpError";
|
|
35
|
+
this.statusCode = statusCode;
|
|
36
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChD,YAAY,OAAO,GAAG,4BAA4B;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,YAAY,OAAO,GAAG,oBAAoB;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,yDAAyD;AACzD,MAAM,OAAO,SAAU,SAAQ,SAAS;IAGtC,YAAY,UAAkB,EAAE,OAAe;QAC7C,KAAK,CAAC,QAAQ,UAAU,KAAK,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @interchained/usdx
|
|
3
|
+
*
|
|
4
|
+
* Typed HTTP client SDK for the USDx wallet API.
|
|
5
|
+
* Pairs with the `interchained-usdx` Python server library.
|
|
6
|
+
*/
|
|
7
|
+
export { USDxClient } from "./client.js";
|
|
8
|
+
export { AccountFrozen, HttpError, InsufficientBalance, USDxError, } from "./errors.js";
|
|
9
|
+
export type { BalanceInfo, ClaimResult, CreditOptions, DebitOptions, DepositInvoice, OtcStats, PaymentStatus, Transaction, TransferOptions, TransferResult, USDxClientOptions, } from "./types.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,SAAS,GACV,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @interchained/usdx
|
|
3
|
+
*
|
|
4
|
+
* Typed HTTP client SDK for the USDx wallet API.
|
|
5
|
+
* Pairs with the `interchained-usdx` Python server library.
|
|
6
|
+
*/
|
|
7
|
+
export { USDxClient } from "./client.js";
|
|
8
|
+
export { AccountFrozen, HttpError, InsufficientBalance, USDxError, } from "./errors.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,SAAS,GACV,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core data models — mirrors the Python usdx-py package.
|
|
3
|
+
*/
|
|
4
|
+
export interface Transaction {
|
|
5
|
+
id: string;
|
|
6
|
+
user_id: string;
|
|
7
|
+
/** e.g. "credit", "debit", "transfer_in", "transfer_out", "deposit", "withdrawal" */
|
|
8
|
+
type: string;
|
|
9
|
+
amount: number;
|
|
10
|
+
balance_after: number;
|
|
11
|
+
description: string;
|
|
12
|
+
created_at: string;
|
|
13
|
+
reference_id?: string | null;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface BalanceInfo {
|
|
17
|
+
user_id: string;
|
|
18
|
+
balance: number;
|
|
19
|
+
total_credited: number;
|
|
20
|
+
total_debited: number;
|
|
21
|
+
is_frozen: boolean;
|
|
22
|
+
created_at?: string | null;
|
|
23
|
+
last_updated?: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface TransferResult {
|
|
26
|
+
debit_tx: Transaction;
|
|
27
|
+
credit_tx: Transaction;
|
|
28
|
+
}
|
|
29
|
+
export interface DepositInvoice {
|
|
30
|
+
success: boolean;
|
|
31
|
+
invoice_id: string;
|
|
32
|
+
token_id?: string | null;
|
|
33
|
+
payment_url?: string | null;
|
|
34
|
+
pay_address?: string | null;
|
|
35
|
+
pay_amount?: number | null;
|
|
36
|
+
pay_currency: string;
|
|
37
|
+
order_id: string;
|
|
38
|
+
created_at?: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface PaymentStatus {
|
|
41
|
+
success: boolean;
|
|
42
|
+
status: string;
|
|
43
|
+
pay_amount?: number | null;
|
|
44
|
+
actually_paid?: number | null;
|
|
45
|
+
price_amount?: number | null;
|
|
46
|
+
price_currency?: string | null;
|
|
47
|
+
pay_currency?: string | null;
|
|
48
|
+
order_id?: string | null;
|
|
49
|
+
created_at?: string | null;
|
|
50
|
+
updated_at?: string | null;
|
|
51
|
+
}
|
|
52
|
+
export interface ClaimResult {
|
|
53
|
+
success: boolean;
|
|
54
|
+
username?: string;
|
|
55
|
+
amount?: number;
|
|
56
|
+
currency?: string;
|
|
57
|
+
payment_id?: string;
|
|
58
|
+
error?: string;
|
|
59
|
+
already_processed?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface OtcStats {
|
|
62
|
+
itc_reserve: number;
|
|
63
|
+
usdx_supply: number;
|
|
64
|
+
adjustment_factor: number;
|
|
65
|
+
current_rate: number;
|
|
66
|
+
paused: boolean;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
}
|
|
69
|
+
export interface CreditOptions {
|
|
70
|
+
description?: string;
|
|
71
|
+
tx_type?: string;
|
|
72
|
+
reference_id?: string;
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
/** Premium multiplier, e.g. 1.5 for premium users. Server-side default: 1.0 */
|
|
75
|
+
multiplier?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface DebitOptions {
|
|
78
|
+
description?: string;
|
|
79
|
+
tx_type?: string;
|
|
80
|
+
reference_id?: string;
|
|
81
|
+
metadata?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export interface TransferOptions {
|
|
84
|
+
description?: string;
|
|
85
|
+
reference_id?: string;
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
export interface USDxClientOptions {
|
|
89
|
+
/** API key sent as `X-Api-Key` header. */
|
|
90
|
+
apiKey?: string;
|
|
91
|
+
/** Any additional headers to include in every request. */
|
|
92
|
+
headers?: Record<string, string>;
|
|
93
|
+
/**
|
|
94
|
+
* Custom fetch implementation. Defaults to the global `fetch`.
|
|
95
|
+
* Useful for test mocking or environments without native fetch.
|
|
96
|
+
*/
|
|
97
|
+
fetch?: typeof globalThis.fetch;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;I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js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@interchained/usdx",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed HTTP client SDK for the USDx wallet API — balance engine, NowPayments deposits, ITC PSBT withdrawals, OTC rate",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"usdx",
|
|
7
|
+
"wallet",
|
|
8
|
+
"crypto",
|
|
9
|
+
"interchained",
|
|
10
|
+
"nowpayments",
|
|
11
|
+
"psbt",
|
|
12
|
+
"blockchain",
|
|
13
|
+
"balance",
|
|
14
|
+
"atomic",
|
|
15
|
+
"redis"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/interchained/usdx-js",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/interchained/usdx-js/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/interchained/usdx-js.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "GPL-3.0-or-later",
|
|
26
|
+
"author": "Interchained <dev@interchained.org>",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"dev": "tsc --watch",
|
|
44
|
+
"check": "tsc --noEmit",
|
|
45
|
+
"prepublishOnly": "npm run check && npm run build"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|