kryptoexpress-sdk 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ - Limited client-side minimum amount validation to `USD` payments only.
6
+ - Allowed non-USD `PAYMENT` creation without a local fiat converter or FX-based threshold validation.
7
+
8
+ ## 0.1.0
9
+
10
+ - Initial release of the TypeScript-first KryptoExpress SDK.
11
+ - Added payments, wallet, currencies, fiat, and callback-signature helpers.
12
+ - Added typed errors, timeout/retry support, runtime boundary validation, and business-rule enforcement.
13
+ - Added CI and npm publish workflows using trusted publishing.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # kryptoexpress-sdk
2
+
3
+ TypeScript-first, production-oriented SDK for the KryptoExpress API.
4
+
5
+ Repository: `https://github.com/kryptoexpress/kryptoexpress-typescript`
6
+
7
+ ## Design goals
8
+
9
+ - One package for both TypeScript and JavaScript users.
10
+ - ESM-first build with CommonJS compatibility.
11
+ - Stable, small public API centered around `KryptoExpressClient`.
12
+ - Manual business-rule enforcement where the practical docs are stricter than OpenAPI.
13
+
14
+ ## API contract analysis
15
+
16
+ Sources used:
17
+
18
+ - OpenAPI: `https://kryptoexpress.pro/api/swagger/documentation.yaml`
19
+ - Practical docs: `https://raw.githubusercontent.com/kryptoexpress/kryptoexpress/refs/heads/main/api-docs.md`
20
+
21
+ ### Auth scheme
22
+
23
+ - Protected endpoints use `X-Api-Key`.
24
+ - Public endpoints do not require authentication.
25
+
26
+ ### Base URL
27
+
28
+ - `https://kryptoexpress.pro/api`
29
+
30
+ ### Covered endpoints
31
+
32
+ - `POST /payment`
33
+ - `GET /payment?hash=...`
34
+ - `GET /wallet`
35
+ - `POST /wallet/withdrawal`
36
+ - `GET /currency`
37
+ - `GET /cryptocurrency`
38
+ - `GET /cryptocurrency/all`
39
+ - `GET /cryptocurrency/stable`
40
+ - `GET /cryptocurrency/price`
41
+
42
+ ### Business rules applied in the SDK
43
+
44
+ - `PAYMENT` requires `fiatAmount`.
45
+ - `DEPOSIT` does not accept `fiatAmount`.
46
+ - Stablecoins support only `PAYMENT`.
47
+ - Stablecoin flows are treated as exact-payment-only by policy.
48
+ - Client-side minimum payment validation applies only to `USD` payments and enforces a minimum of `1.00`.
49
+ - Non-USD payments are forwarded to the API without local minimum threshold validation.
50
+ - Withdrawal dry-runs use `onlyCalculate: true`.
51
+ - Callback verification uses `X-Signature` and `HMAC-SHA512` over compact JSON.
52
+
53
+ ### Known ambiguities and safe decisions
54
+
55
+ - The practical docs are treated as the source of truth for payment semantics when they are stricter than OpenAPI.
56
+ - Stablecoin exact-payment behavior is documented as a business rule, but there is no extra request field to toggle exactness. The SDK enforces the supported mode by allowing stablecoins only for `PAYMENT`.
57
+ - The `fiatConverter` abstraction remains available as an optional extension, but ordinary non-USD payment creation no longer depends on it.
58
+ - Runtime validation is limited to boundary parsing and critical policy checks to keep the package light and semver-friendly.
59
+
60
+ ## Installation
61
+
62
+ ```bash
63
+ npm install kryptoexpress-sdk
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ```ts
69
+ import {
70
+ KryptoExpressClient,
71
+ StaticRateFiatConverter,
72
+ verifyCallbackSignature,
73
+ } from 'kryptoexpress-sdk';
74
+
75
+ const client = new KryptoExpressClient({
76
+ apiKey: process.env.KRYPTOEXPRESS_API_KEY,
77
+ fiatConverter: new StaticRateFiatConverter([{ from: 'EUR', to: 'USD', rate: 1.08 }]),
78
+ });
79
+
80
+ const payment = await client.payments.createPayment({
81
+ fiatCurrency: 'USD',
82
+ fiatAmount: 25,
83
+ cryptoCurrency: 'BTC',
84
+ callbackUrl: 'https://merchant.example/callback',
85
+ callbackSecret: 'super-secret',
86
+ });
87
+
88
+ const lookup = await client.payments.getByHash(payment.hash);
89
+ const balances = await client.wallet.get();
90
+
91
+ const quote = await client.wallet.calculateAll({
92
+ cryptoCurrency: 'BTC',
93
+ toAddress: 'bc1destination...',
94
+ });
95
+
96
+ const isValid = verifyCallbackSignature({
97
+ rawBody: requestBody,
98
+ callbackSecret: 'super-secret',
99
+ signature: request.headers['x-signature'],
100
+ });
101
+ ```
102
+
103
+ `fiatConverter` is optional. The SDK only enforces the `>= 1.00` minimum locally for `USD` payments; non-USD payment requests are forwarded to the API without local FX-based threshold validation.
104
+
105
+ ## Public API
106
+
107
+ ```ts
108
+ const client = new KryptoExpressClient({ apiKey: '...' });
109
+
110
+ await client.payments.create(...);
111
+ await client.payments.createPayment(...);
112
+ await client.payments.createDeposit(...);
113
+ await client.payments.getByHash(...);
114
+
115
+ await client.wallet.get();
116
+ await client.wallet.withdraw(...);
117
+ await client.wallet.calculate(...);
118
+ await client.wallet.withdrawAll(...);
119
+ await client.wallet.withdrawSingle(...);
120
+ await client.wallet.calculateAll(...);
121
+ await client.wallet.calculateSingle(...);
122
+
123
+ await client.currencies.listAll();
124
+ await client.currencies.listNative();
125
+ await client.currencies.listStable();
126
+ await client.currencies.getPrices(...);
127
+
128
+ await client.fiat.list();
129
+ ```
130
+
131
+ ## Configuration
132
+
133
+ ```ts
134
+ const client = new KryptoExpressClient({
135
+ apiKey: '...',
136
+ baseUrl: 'https://kryptoexpress.pro/api',
137
+ timeoutMs: 10_000,
138
+ retry: {
139
+ maxRetries: 2,
140
+ retryStatusCodes: [408, 409, 429, 500, 502, 503, 504],
141
+ },
142
+ fetch,
143
+ });
144
+ ```
145
+
146
+ ## Callback verification
147
+
148
+ ```ts
149
+ import { verifyCallbackSignature } from 'kryptoexpress-sdk';
150
+
151
+ const ok = verifyCallbackSignature({
152
+ rawBody,
153
+ callbackSecret: process.env.KRYPTOEXPRESS_CALLBACK_SECRET!,
154
+ signature: request.headers['x-signature'],
155
+ });
156
+ ```
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ npm install
162
+ npm run lint
163
+ npm run test
164
+ npm run build
165
+ ```