@heliofi/withdraw-core 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -1,11 +1,281 @@
1
1
  # @heliofi/withdraw-core
2
2
 
3
- Core JS/TS SDK for MoonPay Commerce withdrawals — routes, quotes, balance checks, and transaction submission.
3
+ Framework-agnostic TypeScript SDK for **MoonPay Commerce** crypto withdrawals — load a
4
+ withdrawal config, fetch routes and balances, create a priced quote, submit a signed
5
+ transaction, and poll status. No React, no global state, no dependencies beyond a small
6
+ enum package. It uses the global `fetch` (overridable for Node/custom transports).
4
7
 
5
- ## Install guide:
8
+ > **Using React?** Reach for [`@heliofi/withdraw-react`](https://www.npmjs.com/package/@heliofi/withdraw-react)
9
+ > instead — a drop-in `<MoonPayCommerceWithdraw>` component plus headless hooks, both built
10
+ > on this SDK. Use `withdraw-core` directly when you're on another framework, vanilla JS, a
11
+ > backend/Node service, or you want lower-level control.
12
+ >
13
+ > Full guide: **https://docs.hel.io/docs/withdrawals/sdk**
14
+
15
+ ## Installation
6
16
 
7
17
  ```bash
8
18
  npm install @heliofi/withdraw-core
9
- yarn add @heliofi/withdraw-core
10
- pnpm add @heliofi/withdraw-core
19
+ # or: yarn add @heliofi/withdraw-core
20
+ # or: pnpm add @heliofi/withdraw-core
21
+ ```
22
+
23
+ Ships ESM + CJS with bundled type declarations.
24
+
25
+ ## Core concepts
26
+
27
+ | Term | Meaning |
28
+ | --- | --- |
29
+ | **Withdrawal config** | The merchant's server-side configuration (`withdrawalConfigId`). Determines the source chain/token, available routes, and signing strategy. |
30
+ | **Balance** | The user's spendable balance on the *merchant site* (the source of funds). |
31
+ | **Source wallet** (`ownerAddress`) | The merchant's funding/deposit wallet that actually holds and sends the crypto. Provided by your app, not the end user. |
32
+ | **Destination** (`recipient`) | The user's crypto wallet address that receives the funds. |
33
+ | **Quote / withdrawal detail** | A priced withdrawal, created by `createWithdrawalDetail` (prepare). Returns a `withdrawalDetailId`, a `prepared` transaction to sign, a fee `summary`, and a JWT `token` required for submit. |
34
+ | **`handleSign`** | *Your* code. Given the `prepared` transaction, produce the merchant's signature. This is where your wallet integration lives — the SDK never touches private keys. |
35
+ | **Amounts** | All amounts are in **minimal (atomic) units** as strings — e.g. `"1000000"` for 1 USDC (6 decimals). Read `decimals` from the currency to format for display. |
36
+
37
+ **The withdrawal flow:**
38
+
39
+ ```text
40
+ Load config → Get routes → Get balance → Quote (prepare) → Sign → Submit → Poll status
41
+ ```
42
+
43
+ ## Create an instance
44
+
45
+ ```ts
46
+ import { WithdrawalSDK } from '@heliofi/withdraw-core';
47
+
48
+ const sdk = WithdrawalSDK.create();
49
+ ```
50
+
51
+ `create()` accepts optional config — `baseUrl` (defaults to `https://api.hel.io/v1`),
52
+ `headers` (extra request headers), and a custom `fetch` implementation (for instrumentation
53
+ or non-browser runtimes).
54
+
55
+ ## Quickstart — the quote → sign → submit loop
56
+
57
+ ```ts
58
+ import { WithdrawalSDK, TERMINAL_STATES } from '@heliofi/withdraw-core';
59
+
60
+ const sdk = WithdrawalSDK.create();
61
+ const configId = 'wc_...';
62
+
63
+ // 1. Load config → source currency
64
+ const config = await sdk.getWithdrawalConfig(configId);
65
+ const sourceCurrencyId = config.fromCurrencies[0].id;
66
+
67
+ // 2. See where the user can withdraw to
68
+ const { routes } = await sdk.getRoutes(configId);
69
+ const toCurrencyId = routes.find((r) => r.available)!.toCurrency.id;
70
+
71
+ // 3. (Optional) check the source wallet balance
72
+ const { balances } = await sdk.getBalance(configId, ownerAddress);
73
+
74
+ // 4. Quote (prepare)
75
+ const quote = await sdk.createWithdrawalDetail({
76
+ withdrawalConfigId: configId,
77
+ ownerAddress, // merchant's funding wallet
78
+ recipient, // user's destination wallet
79
+ amount: '1000000', // minimal units (string)
80
+ toCurrencyId,
81
+ sourceCurrencyId,
82
+ });
83
+
84
+ // 5. Sign the prepared tx with your wallet — branch on quote.prepared.kind (see Signing)
85
+ const signedTx = await signWithYourWallet(quote.prepared);
86
+
87
+ // 6. Submit
88
+ const result = await sdk.submitWithdrawal({
89
+ withdrawalDetailId: quote.withdrawalDetailId,
90
+ token: quote.token, // JWT from the quote — required for submit
91
+ signedTx,
92
+ });
93
+
94
+ // 7. Poll until terminal
95
+ let status = await sdk.getWithdrawalDetail(quote.withdrawalDetailId);
96
+ while (!TERMINAL_STATES.has(status.state)) {
97
+ await new Promise((r) => setTimeout(r, 3000));
98
+ status = await sdk.getWithdrawalDetail(quote.withdrawalDetailId);
99
+ }
100
+ ```
101
+
102
+ ## Method reference
103
+
104
+ Every method is async, accepts an optional trailing `AbortSignal`, and throws
105
+ [`WithdrawalApiError`](#error-handling) on a non-2xx response.
106
+
107
+ | Method | HTTP endpoint | Returns |
108
+ | --- | --- | --- |
109
+ | `getWithdrawalConfig(configId, signal?)` | `GET /withdrawal-configs/:id/public` | `WithdrawalConfig` — source currencies, exchange rates, enabled features. |
110
+ | `getRoutes(configId, signal?)` | `GET /withdraw/:id/routes` | `RoutesResponse` — `fromCurrencies` + available `routes`. |
111
+ | `getBalance(configId, walletAddress, signal?)` | `GET /withdraw/:id/balances` | `BalanceResponse` — per-currency balances for the wallet. |
112
+ | `createWithdrawalDetail(params, signal?)` | `POST /withdraw/:id/prepare` | `QuoteResponse` — `withdrawalDetailId`, `prepared`, fee `summary`, JWT `token`. |
113
+ | `updateWithdrawalDetail(detailId, params, signal?)` | `PATCH /withdraw-details/:detailId` | `QuoteResponse` — a re-priced quote. |
114
+ | `submitWithdrawal(params, signal?)` | `POST /withdraw/:detailId/submit` | `SubmitResponse` — `txHash`, `state`, `broadcastAck`. |
115
+ | `getWithdrawalDetail(detailId, signal?)` | `GET /withdraw-details/:detailId` | `StatusResponse` — current `state`, `txHash`, `errorReason`. |
116
+ | `isSupported(minSupportedVersions?)` | — (local version check) | `boolean` — whether this SDK version satisfies the config's minimum. |
117
+
118
+ **Params:**
119
+
120
+ - `createWithdrawalDetail` (`CreateWithdrawalDetailParams`): `withdrawalConfigId`, `ownerAddress`,
121
+ `recipient`, `amount` (minimal units, string), `toCurrencyId`, `sourceCurrencyId`, and optional
122
+ `customerId` (string, ≤255 chars — your identifier for the end user, attached to the quote).
123
+ - `updateWithdrawalDetail` (`UpdateWithdrawalDetailParams`): the same, minus `customerId`
124
+ (set once at creation, not accepted on re-quote).
125
+ - `submitWithdrawal` (`SubmitWithdrawalParams`): `withdrawalDetailId`, `token`, `signedTx`.
126
+
127
+ ## Signing
128
+
129
+ Signing is the one piece **you always implement**. A quote's `prepared` object tells you what
130
+ to sign; branch on `prepared.kind` (a `SignedTransactionKind`) and return a signature string.
131
+
132
+ | `prepared.kind` | `data` you sign | What your wallet does | Return |
133
+ | --- | --- | --- | --- |
134
+ | `HYPERCORE` | `prepared.typedData` (EIP-712) | Sign typed data | Signature (hex string) |
135
+ | `RAW` | `prepared.unsignedTx` (string; Solana: base64 `VersionedTransaction`) | Deserialize → sign → re-serialize | Base64 signed tx |
136
+ | `USER_OP` | `{ userOp, entryPoint, chain, authorization? }` | Sign userOpHash + EIP-7702 authorization | JSON string (see below) |
137
+
138
+ ### EVM typed data (the common case)
139
+
140
+ Most EVM integrations (e.g. Hyperliquid) use EIP-712 typed data. Using viem:
141
+
142
+ ```ts
143
+ import { privateKeyToAccount } from 'viem/accounts';
144
+ import { SignedTransactionKind } from '@heliofi/withdraw-core';
145
+
146
+ const account = privateKeyToAccount(privateKey);
147
+
148
+ async function signWithYourWallet(prepared) {
149
+ if (prepared.kind === SignedTransactionKind.HYPERCORE) {
150
+ const { domain, types, primaryType, message } = prepared.typedData;
151
+ // viem derives EIP712Domain itself — strip it from the types.
152
+ const { EIP712Domain: _omit, ...messageTypes } = types;
153
+ return account.signTypedData({ domain, types: messageTypes, primaryType, message });
154
+ }
155
+ throw new Error(`Unsupported signing kind: ${prepared.kind}`);
156
+ }
11
157
  ```
158
+
159
+ ### Solana (`RAW`, base64)
160
+
161
+ `prepared.unsignedTx` is a base64 `VersionedTransaction`. Deserialize, sign, and return the
162
+ **base64 signed tx** — the backend broadcasts it.
163
+
164
+ ```ts
165
+ import { VersionedTransaction } from '@solana/web3.js';
166
+
167
+ const b64ToBytes = (b64: string) => Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
168
+ const bytesToB64 = (b: Uint8Array) => btoa(String.fromCharCode(...b));
169
+
170
+ const tx = VersionedTransaction.deserialize(b64ToBytes(prepared.unsignedTx));
171
+ const signed = await wallet.signTransaction(tx);
172
+ return bytesToB64(signed.serialize());
173
+ ```
174
+
175
+ ### EVM UserOp (`USER_OP`, ERC-4337 + EIP-7702)
176
+
177
+ The account-abstraction path. Recompute the userOp hash with the canonical entryPoint, sign
178
+ it, sign the EIP-7702 authorization, and return **both as a JSON string**.
179
+
180
+ ```ts
181
+ import { getUserOperationHash } from 'viem/account-abstraction';
182
+
183
+ // aa-sdk hexlifies these gas fields; viem's hash needs them as bigints.
184
+ const BIGINT_FIELDS = ['nonce', 'callGasLimit', 'verificationGasLimit', 'preVerificationGas',
185
+ 'maxFeePerGas', 'maxPriorityFeePerGas', 'paymasterVerificationGasLimit', 'paymasterPostOpGasLimit'];
186
+ const toBigints = (op) => {
187
+ const out = { ...op };
188
+ for (const f of BIGINT_FIELDS) if (typeof out[f] === 'string') out[f] = BigInt(out[f]);
189
+ return out;
190
+ };
191
+
192
+ const { userOp, entryPoint, authorization } = prepared;
193
+ const chainId = Number(BigInt(authorization.chainId));
194
+ const nonce = Number(BigInt(authorization.nonce));
195
+
196
+ const userOpHash = getUserOperationHash({
197
+ chainId,
198
+ entryPointAddress: entryPoint,
199
+ entryPointVersion: '0.7',
200
+ userOperation: toBigints(userOp),
201
+ });
202
+
203
+ const signature = await account.signMessage({ message: { raw: userOpHash } });
204
+ const signed = await account.signAuthorization({ address: authorization.address, chainId, nonce });
205
+
206
+ return JSON.stringify({
207
+ signature,
208
+ authorization: { chainId, address: authorization.address, nonce, r: signed.r, s: signed.s, yParity: signed.yParity },
209
+ });
210
+ ```
211
+
212
+ > ⚠️ The userOp hash must match the backend's server-side hash exactly, or `submitWithdrawal`
213
+ > fails with `401`. Keep `entryPointVersion` and the gas-field types aligned with the values above.
214
+
215
+ ## Types & error codes
216
+
217
+ Key exported types:
218
+
219
+ ```ts
220
+ interface QuoteResponse {
221
+ withdrawalDetailId: string;
222
+ token: string; // JWT — required for submit
223
+ prepared: PreparedTransaction; // discriminated union — branch on .kind to sign
224
+ summary: QuoteSummary; // amounts + fee breakdown
225
+ }
226
+
227
+ interface SubmitResponse { withdrawalDetailId: string; txHash: string | null; state: WithdrawalState; broadcastAck: BroadcastAck | null; }
228
+ interface StatusResponse { withdrawalDetailId: string; state: WithdrawalState; txHash: string | null; broadcastAck: BroadcastAck | null; errorReason: string | null; }
229
+ ```
230
+
231
+ `PreparedTransaction` is a discriminated union of `HypercorePreparedTransaction`,
232
+ `RawPreparedTransaction`, and `UserOpPreparedTransaction` (discriminated by
233
+ `kind: SignedTransactionKind`).
234
+
235
+ **`SignedTransactionKind`:** `HYPERCORE` · `RAW` · `USER_OP`.
236
+
237
+ **`WithdrawalState`:** `QUOTED → SUBMITTING → SUBMITTED → BRIDGING → COMPLETED`, plus failure
238
+ states `FAILED`, `FAILED_EXPIRED`, `EXPIRED`, `REFUNDED_BY_PROVIDER`. `TERMINAL_STATES` is a
239
+ `Set` of the terminal ones (`COMPLETED`, `FAILED`, `FAILED_EXPIRED`, `EXPIRED`,
240
+ `REFUNDED_BY_PROVIDER`) — use `TERMINAL_STATES.has(state)` to stop polling.
241
+
242
+ ### Error handling
243
+
244
+ Every method throws `WithdrawalApiError` on a non-2xx response, carrying a
245
+ `WithdrawalErrorCode`:
246
+
247
+ ```ts
248
+ import { WithdrawalApiError, WithdrawalErrorCode } from '@heliofi/withdraw-core';
249
+
250
+ try {
251
+ await sdk.submitWithdrawal({ withdrawalDetailId, token, signedTx });
252
+ } catch (err) {
253
+ if (err instanceof WithdrawalApiError) {
254
+ console.error(err.code, err.message); // e.g. WITHDRAW_TX_INVALID_SIGNATURE
255
+ }
256
+ }
257
+ ```
258
+
259
+ `WithdrawalErrorCode` values: `WITHDRAW_TX_INVALID_SIGNATURE`, `WITHDRAW_TX_BLOCKHASH_EXPIRED`,
260
+ `WITHDRAW_TX_NONCE_TOO_LOW`, `WITHDRAW_TX_USEROP_EXPIRED`, `WITHDRAW_TX_UNDERPRICED`,
261
+ `WITHDRAW_BUNDLER_REJECTED`, `WITHDRAW_TX_BROADCAST_TIMEOUT`, `WITHDRAW_TX_ALREADY_KNOWN`,
262
+ `WITHDRAW_QUOTE_EXPIRED`, `WITHDRAW_SANCTIONS_BLOCKED`, `WITHDRAW_NO_ROUTE`, `WITHDRAW_NOT_FOUND`,
263
+ `WITHDRAW_INSUFFICIENT_BALANCE`, `WITHDRAW_DETAILS_NOT_UPDATABLE`, `INVALID_WALLET_ADDRESS`,
264
+ `BALANCE_FETCH_FAILED`, `UNKNOWN`.
265
+
266
+ ## Helpers
267
+
268
+ ```ts
269
+ import { decodeJwt, isQuoteExpired, isSupported, isBelow, SDK_VERSION } from '@heliofi/withdraw-core';
270
+
271
+ isQuoteExpired(quote.token); // → true once the quote's JWT has expired (with a small buffer)
272
+ decodeJwt(quote.token); // → { exp, iat, withdrawalDetailId, ... }
273
+ SDK_VERSION; // → this package's version string
274
+ ```
275
+
276
+ ## Links
277
+
278
+ - **npm:** [`@heliofi/withdraw-core`](https://www.npmjs.com/package/@heliofi/withdraw-core)
279
+ - **React package:** [`@heliofi/withdraw-react`](https://www.npmjs.com/package/@heliofi/withdraw-react)
280
+ - **Docs:** https://docs.hel.io/docs/withdrawals/sdk
281
+ - **API reference:** https://docs.hel.io/docs/withdrawals
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { toWithdrawalErrorCode, WithdrawalApiError, } from './errors';
2
2
  export type { WithdrawalJwtPayload } from './jwt';
3
3
  export { decodeJwt, isQuoteExpired } from './jwt';
4
4
  export type { ApiClientConfig } from './sdk';
5
- export { WithdrawalSDK } from './sdk';
5
+ export { DEFAULT_BASE_URL, WithdrawalSDK } from './sdk';
6
6
  export type { BalanceResponse, BaseBlockchain, BlockchainEngine, CreateWithdrawalDetailParams, HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PopulatedBlockchain, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, SlimCurrencyWithPopulatedBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, WithdrawalQuoteFee, } from './types';
7
7
  export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './types';
8
8
  export { SDK_VERSION } from './version';
@@ -1,5 +1,8 @@
1
+ /** Default MoonPay Commerce API base URL, used when `baseUrl` is omitted. */
2
+ export declare const DEFAULT_BASE_URL = "https://api.hel.io/v1";
1
3
  export interface ApiClientConfig {
2
- baseUrl: string;
4
+ /** API base URL. Defaults to {@link DEFAULT_BASE_URL} (`https://api.hel.io/v1`). */
5
+ baseUrl?: string;
3
6
  headers?: Record<string, string>;
4
7
  fetch?: typeof globalThis.fetch;
5
8
  consumer?: {
@@ -6,7 +6,7 @@ import { ApiClient, type ApiClientConfig } from './ApiClient';
6
6
  export declare class WithdrawalSDK {
7
7
  private readonly api;
8
8
  constructor(api: ApiClient);
9
- static create(config: ApiClientConfig): WithdrawalSDK;
9
+ static create(config?: ApiClientConfig): WithdrawalSDK;
10
10
  isSupported(minSupportedVersions?: MinSupportedVersions | null): boolean;
11
11
  getWithdrawalConfig(withdrawalConfigId: string, signal?: AbortSignal): Promise<WithdrawalConfig>;
12
12
  getRoutes(withdrawalConfigId: string, signal?: AbortSignal): Promise<RoutesResponse>;
@@ -1,2 +1,3 @@
1
1
  export type { ApiClientConfig } from './ApiClient';
2
+ export { DEFAULT_BASE_URL } from './ApiClient';
2
3
  export { WithdrawalSDK } from './WithdrawalSDK';
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var m=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var D=(e,t,r)=>m(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let U=(function(e){return e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e})({}),C=(function(e){return e.EVM="EVM",e.SOL="SOL",e.BTC="BTC",e.TRON="TRON",e.HYPERCORE="HYPERCORE",e.DOGE="DOGE",e})({}),H=(function(e){return e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e})({}),S=(function(e){return e.IRON="iron",e.MP_SELL="mp_sell",e})({}),T=(function(e){return e.QUOTED="QUOTED",e.SUBMITTING="SUBMITTING",e.SUBMITTED="SUBMITTED",e.BRIDGING="BRIDGING",e.COMPLETED="COMPLETED",e.FAILED="FAILED",e.FAILED_EXPIRED="FAILED_EXPIRED",e.EXPIRED="EXPIRED",e.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",e})({}),P=(function(e){return e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e})({}),d=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const w=new Set([T.COMPLETED,T.FAILED,T.FAILED_EXPIRED,T.EXPIRED,T.REFUNDED_BY_PROVIDER]);var I=(e=>(e.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",e.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",e.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",e.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",e.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",e.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",e.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",e.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",e.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",e.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",e.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",e.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",e.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",e.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",e.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",e.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",e.UNKNOWN="UNKNOWN",e))(I||{});const X=new Set(Object.values(I));class O extends Error{constructor(r,s,n){super(n??s);D(this,"name","WithdrawalApiError");this.status=r,this.code=s,this.detail=n}}const l=e=>e&&X.has(e)?e:I.UNKNOWN,p=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const r=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)},M=(e,t=5e3)=>{const{exp:r}=p(e);return r===void 0?!1:Date.now()>=r*1e3-t},R="1.3.0",A=e=>/^\d+$/.test(e);function N(e){if(typeof e!="string")return null;let t=e.trim();if((t.startsWith("v")||t.startsWith("V"))&&(t=t.slice(1)),t==="")return null;const r=t.indexOf("+");r!==-1&&(t=t.slice(0,r));const s=t.indexOf("-"),n=s===-1?t:t.slice(0,s),i=s===-1?"":t.slice(s+1),E=n.split(".");if(E.length>3)return null;const u=[];for(const _ of E){if(!A(_))return null;u.push(Number(_))}const o=i===""?[]:i.split(".").filter(_=>_!=="");return s!==-1&&o.length===0?null:{major:u[0]??0,minor:u[1]??0,patch:u[2]??0,prerelease:o}}function c(e,t){return e<t?-1:e>t?1:0}function g(e,t){if(e.length===0&&t.length===0)return 0;if(e.length===0)return 1;if(t.length===0)return-1;const r=Math.min(e.length,t.length);for(let s=0;s<r;s++){const n=e[s],i=t[s];if(n===i)continue;const E=A(n),u=A(i);if(E&&u){const o=c(Number(n),Number(i));if(o!==0)return o}else return E?-1:u?1:n<i?-1:1}return c(e.length,t.length)}function B(e,t){const r=N(e)??{major:0,minor:0,patch:0,prerelease:[]},s=N(t)??{major:0,minor:0,patch:0,prerelease:[]},n=c(r.major,s.major)||c(r.minor,s.minor)||c(r.patch,s.patch);return n!==0?n:g(r.prerelease,s.prerelease)}function W(e,t){return B(e,t)<0}const h="@heliofi/withdraw-core";function f(e={}){const{minSupportedVersions:t,consumer:r}=e,s=(t==null?void 0:t.packages)??{},n=e.sdkVersion??R,i={[h]:n};r!=null&&r.name&&r.version!=null&&(i[r.name]=r.version);for(const[E,u]of Object.entries(s)){const o=i[E];if(o!=null&&W(o,u))return!1}return!0}class G{constructor(t){D(this,"baseUrl");D(this,"headers");D(this,"fetch");D(this,"consumer");var r,s;this.consumer=t.consumer,this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json","X-MoonPay-Commerce-SDK-Version":R,...(r=this.consumer)!=null&&r.name?{"X-MoonPay-Commerce-Consumer":this.consumer.name}:{},...(s=this.consumer)!=null&&s.version?{"X-MoonPay-Commerce-Consumer-Version":this.consumer.version}:{},...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,r){return this.request("GET",t,void 0,r)}async post(t,r,s){return this.request("POST",t,r,s)}async patch(t,r,s){return this.request("PATCH",t,r,s)}async request(t,r,s,n){const i=`${this.baseUrl}${r}`,E=await this.fetch(i,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:n});if(!E.ok)throw await this.buildError(E);return await E.json()}async buildError(t){let r,s;try{const n=await t.json();r=n.message??void 0,s=n.errorCode??n.errorType??void 0}catch{r=t.statusText||void 0}return new O(t.status,l(s),r)}}class a{constructor(t){this.api=t}static create(t){return new a(new G(t))}isSupported(t){return f({minSupportedVersions:t,consumer:this.api.consumer})}async getWithdrawalConfig(t,r){return this.api.get(`/withdrawal-configs/${t}/public`,r)}async getRoutes(t,r){return this.api.get(`/withdraw/${t}/routes`,r)}async getBalance(t,r,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(r)}`,s)}async createWithdrawalDetail(t,r){const{withdrawalConfigId:s,...n}=t;return this.api.post(`/withdraw/${s}/prepare`,n,r)}async updateWithdrawalDetail(t,r,s){return this.api.patch(`/withdraw-details/${t}`,r,s)}async submitWithdrawal(t,r){const{withdrawalDetailId:s,...n}=t;return this.api.post(`/withdraw/${s}/submit`,n,r)}async getWithdrawalDetail(t,r){return this.api.get(`/withdraw-details/${t}`,r)}}exports.BlockchainEngineType=C;exports.BlockchainSymbol=U;exports.BroadcastAck=P;exports.Platform=H;exports.SDK_PACKAGE_NAME=h;exports.SDK_VERSION=R;exports.SignedTransactionKind=d;exports.TERMINAL_STATES=w;exports.WithdrawalApiError=O;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=S;exports.WithdrawalSDK=a;exports.WithdrawalState=T;exports.decodeJwt=p;exports.isBelow=W;exports.isQuoteExpired=M;exports.isSupported=f;exports.toWithdrawalErrorCode=l;
1
+ "use strict";var m=Object.defineProperty;var U=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var D=(e,t,r)=>U(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let S=(function(e){return e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e})({}),C=(function(e){return e.EVM="EVM",e.SOL="SOL",e.BTC="BTC",e.TRON="TRON",e.HYPERCORE="HYPERCORE",e.DOGE="DOGE",e})({}),H=(function(e){return e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e})({}),P=(function(e){return e.IRON="iron",e.MP_SELL="mp_sell",e})({}),T=(function(e){return e.QUOTED="QUOTED",e.SUBMITTING="SUBMITTING",e.SUBMITTED="SUBMITTED",e.BRIDGING="BRIDGING",e.COMPLETED="COMPLETED",e.FAILED="FAILED",e.FAILED_EXPIRED="FAILED_EXPIRED",e.EXPIRED="EXPIRED",e.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",e})({}),d=(function(e){return e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e})({}),w=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const X=new Set([T.COMPLETED,T.FAILED,T.FAILED_EXPIRED,T.EXPIRED,T.REFUNDED_BY_PROVIDER]);var I=(e=>(e.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",e.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",e.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",e.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",e.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",e.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",e.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",e.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",e.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",e.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",e.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",e.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",e.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",e.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",e.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",e.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",e.UNKNOWN="UNKNOWN",e))(I||{});const g=new Set(Object.values(I));class O extends Error{constructor(r,s,n){super(n??s);D(this,"name","WithdrawalApiError");this.status=r,this.code=s,this.detail=n}}const l=e=>e&&g.has(e)?e:I.UNKNOWN,p=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const r=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)},B=(e,t=5e3)=>{const{exp:r}=p(e);return r===void 0?!1:Date.now()>=r*1e3-t},R="1.3.2",W="https://api.hel.io/v1";class M{constructor(t){D(this,"baseUrl");D(this,"headers");D(this,"fetch");D(this,"consumer");var s,n;this.consumer=t.consumer;const r=t.baseUrl??W;this.baseUrl=r.endsWith("/")?r.slice(0,-1):r,this.headers={"Content-Type":"application/json","X-MoonPay-Commerce-SDK-Version":R,...(s=this.consumer)!=null&&s.name?{"X-MoonPay-Commerce-Consumer":this.consumer.name}:{},...(n=this.consumer)!=null&&n.version?{"X-MoonPay-Commerce-Consumer-Version":this.consumer.version}:{},...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,r){return this.request("GET",t,void 0,r)}async post(t,r,s){return this.request("POST",t,r,s)}async patch(t,r,s){return this.request("PATCH",t,r,s)}async request(t,r,s,n){const i=`${this.baseUrl}${r}`,E=await this.fetch(i,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:n});if(!E.ok)throw await this.buildError(E);return await E.json()}async buildError(t){let r,s;try{const n=await t.json();r=n.message??void 0,s=n.errorCode??n.errorType??void 0}catch{r=t.statusText||void 0}return new O(t.status,l(s),r)}}const A=e=>/^\d+$/.test(e);function N(e){if(typeof e!="string")return null;let t=e.trim();if((t.startsWith("v")||t.startsWith("V"))&&(t=t.slice(1)),t==="")return null;const r=t.indexOf("+");r!==-1&&(t=t.slice(0,r));const s=t.indexOf("-"),n=s===-1?t:t.slice(0,s),i=s===-1?"":t.slice(s+1),E=n.split(".");if(E.length>3)return null;const o=[];for(const _ of E){if(!A(_))return null;o.push(Number(_))}const u=i===""?[]:i.split(".").filter(_=>_!=="");return s!==-1&&u.length===0?null:{major:o[0]??0,minor:o[1]??0,patch:o[2]??0,prerelease:u}}function c(e,t){return e<t?-1:e>t?1:0}function F(e,t){if(e.length===0&&t.length===0)return 0;if(e.length===0)return 1;if(t.length===0)return-1;const r=Math.min(e.length,t.length);for(let s=0;s<r;s++){const n=e[s],i=t[s];if(n===i)continue;const E=A(n),o=A(i);if(E&&o){const u=c(Number(n),Number(i));if(u!==0)return u}else return E?-1:o?1:n<i?-1:1}return c(e.length,t.length)}function G(e,t){const r=N(e)??{major:0,minor:0,patch:0,prerelease:[]},s=N(t)??{major:0,minor:0,patch:0,prerelease:[]},n=c(r.major,s.major)||c(r.minor,s.minor)||c(r.patch,s.patch);return n!==0?n:F(r.prerelease,s.prerelease)}function h(e,t){return G(e,t)<0}const L="@heliofi/withdraw-core";function f(e={}){const{minSupportedVersions:t,consumer:r}=e,s=(t==null?void 0:t.packages)??{},n=e.sdkVersion??R,i={[L]:n};r!=null&&r.name&&r.version!=null&&(i[r.name]=r.version);for(const[E,o]of Object.entries(s)){const u=i[E];if(u!=null&&h(u,o))return!1}return!0}class a{constructor(t){this.api=t}static create(t={}){return new a(new M(t))}isSupported(t){return f({minSupportedVersions:t,consumer:this.api.consumer})}async getWithdrawalConfig(t,r){return this.api.get(`/withdrawal-configs/${t}/public`,r)}async getRoutes(t,r){return this.api.get(`/withdraw/${t}/routes`,r)}async getBalance(t,r,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(r)}`,s)}async createWithdrawalDetail(t,r){const{withdrawalConfigId:s,...n}=t;return this.api.post(`/withdraw/${s}/prepare`,n,r)}async updateWithdrawalDetail(t,r,s){return this.api.patch(`/withdraw-details/${t}`,r,s)}async submitWithdrawal(t,r){const{withdrawalDetailId:s,...n}=t;return this.api.post(`/withdraw/${s}/submit`,n,r)}async getWithdrawalDetail(t,r){return this.api.get(`/withdraw-details/${t}`,r)}}exports.BlockchainEngineType=C;exports.BlockchainSymbol=S;exports.BroadcastAck=d;exports.DEFAULT_BASE_URL=W;exports.Platform=H;exports.SDK_PACKAGE_NAME=L;exports.SDK_VERSION=R;exports.SignedTransactionKind=w;exports.TERMINAL_STATES=X;exports.WithdrawalApiError=O;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=P;exports.WithdrawalSDK=a;exports.WithdrawalState=T;exports.decodeJwt=p;exports.isBelow=h;exports.isQuoteExpired=B;exports.isSupported=f;exports.toWithdrawalErrorCode=l;
@@ -1,34 +1,34 @@
1
1
  var a = Object.defineProperty;
2
2
  var l = (e, t, s) => t in e ? a(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var T = (e, t, s) => l(e, typeof t != "symbol" ? t + "" : t, s);
4
- let X = /* @__PURE__ */ (function(e) {
3
+ var o = (e, t, s) => l(e, typeof t != "symbol" ? t + "" : t, s);
4
+ let w = /* @__PURE__ */ (function(e) {
5
5
  return e.SOL = "SOL", e.ETH = "ETH", e.POLYGON = "POLYGON", e.BASE = "BASE", e.BITCOIN = "BITCOIN", e.ARBITRUM = "ARBITRUM", e.BSC = "BSC", e.TRON = "TRON", e.DOGE = "DOGE", e;
6
- })({}), w = /* @__PURE__ */ (function(e) {
7
- return e.EVM = "EVM", e.SOL = "SOL", e.BTC = "BTC", e.TRON = "TRON", e.HYPERCORE = "HYPERCORE", e.DOGE = "DOGE", e;
8
6
  })({}), M = /* @__PURE__ */ (function(e) {
9
- return e.HELIO = "HELIO", e.MAGIC_EDEN = "MAGIC_EDEN", e;
7
+ return e.EVM = "EVM", e.SOL = "SOL", e.BTC = "BTC", e.TRON = "TRON", e.HYPERCORE = "HYPERCORE", e.DOGE = "DOGE", e;
10
8
  })({}), d = /* @__PURE__ */ (function(e) {
9
+ return e.HELIO = "HELIO", e.MAGIC_EDEN = "MAGIC_EDEN", e;
10
+ })({}), g = /* @__PURE__ */ (function(e) {
11
11
  return e.IRON = "iron", e.MP_SELL = "mp_sell", e;
12
- })({}), o = /* @__PURE__ */ (function(e) {
12
+ })({}), T = /* @__PURE__ */ (function(e) {
13
13
  return e.QUOTED = "QUOTED", e.SUBMITTING = "SUBMITTING", e.SUBMITTED = "SUBMITTED", e.BRIDGING = "BRIDGING", e.COMPLETED = "COMPLETED", e.FAILED = "FAILED", e.FAILED_EXPIRED = "FAILED_EXPIRED", e.EXPIRED = "EXPIRED", e.REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER", e;
14
- })({}), g = /* @__PURE__ */ (function(e) {
15
- return e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e;
16
14
  })({}), B = /* @__PURE__ */ (function(e) {
15
+ return e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e;
16
+ })({}), G = /* @__PURE__ */ (function(e) {
17
17
  return e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e.HYPERCORE = "hypercore", e;
18
18
  })({});
19
- const G = /* @__PURE__ */ new Set([
20
- o.COMPLETED,
21
- o.FAILED,
22
- o.FAILED_EXPIRED,
23
- o.EXPIRED,
24
- o.REFUNDED_BY_PROVIDER
19
+ const F = /* @__PURE__ */ new Set([
20
+ T.COMPLETED,
21
+ T.FAILED,
22
+ T.FAILED_EXPIRED,
23
+ T.EXPIRED,
24
+ T.REFUNDED_BY_PROVIDER
25
25
  ]);
26
26
  var R = /* @__PURE__ */ ((e) => (e.WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE", e.WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED", e.WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW", e.WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED", e.WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED", e.WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED", e.WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT", e.WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN", e.WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED", e.WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED", e.WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE", e.WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND", e.WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE", e.WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE", e.INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS", e.BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED", e.UNKNOWN = "UNKNOWN", e))(R || {});
27
27
  const p = new Set(Object.values(R));
28
28
  class W extends Error {
29
29
  constructor(s, r, n) {
30
30
  super(n ?? r);
31
- T(this, "name", "WithdrawalApiError");
31
+ o(this, "name", "WithdrawalApiError");
32
32
  this.status = s, this.code = r, this.detail = n;
33
33
  }
34
34
  }
@@ -38,79 +38,24 @@ const f = (e) => e && p.has(e) ? e : R.UNKNOWN, L = (e) => {
38
38
  throw new Error("Invalid JWT: expected 3 parts");
39
39
  const s = atob(t[1].replace(/-/g, "+").replace(/_/g, "/"));
40
40
  return JSON.parse(s);
41
- }, F = (e, t = 5e3) => {
41
+ }, v = (e, t = 5e3) => {
42
42
  const { exp: s } = L(e);
43
43
  return s === void 0 ? !1 : Date.now() >= s * 1e3 - t;
44
- }, O = "1.3.0", c = (e) => /^\d+$/.test(e);
45
- function A(e) {
46
- if (typeof e != "string") return null;
47
- let t = e.trim();
48
- if ((t.startsWith("v") || t.startsWith("V")) && (t = t.slice(1)), t === "") return null;
49
- const s = t.indexOf("+");
50
- s !== -1 && (t = t.slice(0, s));
51
- const r = t.indexOf("-"), n = r === -1 ? t : t.slice(0, r), E = r === -1 ? "" : t.slice(r + 1), u = n.split(".");
52
- if (u.length > 3) return null;
53
- const i = [];
54
- for (const _ of u) {
55
- if (!c(_)) return null;
56
- i.push(Number(_));
57
- }
58
- const D = E === "" ? [] : E.split(".").filter((_) => _ !== "");
59
- return r !== -1 && D.length === 0 ? null : {
60
- major: i[0] ?? 0,
61
- minor: i[1] ?? 0,
62
- patch: i[2] ?? 0,
63
- prerelease: D
64
- };
65
- }
66
- function I(e, t) {
67
- return e < t ? -1 : e > t ? 1 : 0;
68
- }
69
- function h(e, t) {
70
- if (e.length === 0 && t.length === 0) return 0;
71
- if (e.length === 0) return 1;
72
- if (t.length === 0) return -1;
73
- const s = Math.min(e.length, t.length);
74
- for (let r = 0; r < s; r++) {
75
- const n = e[r], E = t[r];
76
- if (n === E) continue;
77
- const u = c(n), i = c(E);
78
- if (u && i) {
79
- const D = I(Number(n), Number(E));
80
- if (D !== 0) return D;
81
- } else return u ? -1 : i ? 1 : n < E ? -1 : 1;
82
- }
83
- return I(e.length, t.length);
84
- }
85
- function m(e, t) {
86
- const s = A(e) ?? { major: 0, minor: 0, patch: 0, prerelease: [] }, r = A(t) ?? { major: 0, minor: 0, patch: 0, prerelease: [] }, n = I(s.major, r.major) || I(s.minor, r.minor) || I(s.patch, r.patch);
87
- return n !== 0 ? n : h(s.prerelease, r.prerelease);
88
- }
89
- function U(e, t) {
90
- return m(e, t) < 0;
91
- }
92
- const H = "@heliofi/withdraw-core";
93
- function C(e = {}) {
94
- const { minSupportedVersions: t, consumer: s } = e, r = (t == null ? void 0 : t.packages) ?? {}, n = e.sdkVersion ?? O, E = { [H]: n };
95
- s != null && s.name && s.version != null && (E[s.name] = s.version);
96
- for (const [u, i] of Object.entries(r)) {
97
- const D = E[u];
98
- if (D != null && U(D, i)) return !1;
99
- }
100
- return !0;
101
- }
102
- class P {
44
+ }, O = "1.3.2", h = "https://api.hel.io/v1";
45
+ class U {
103
46
  constructor(t) {
104
- T(this, "baseUrl");
105
- T(this, "headers");
106
- T(this, "fetch");
107
- T(this, "consumer");
108
- var s, r;
109
- this.consumer = t.consumer, this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.headers = {
47
+ o(this, "baseUrl");
48
+ o(this, "headers");
49
+ o(this, "fetch");
50
+ o(this, "consumer");
51
+ var r, n;
52
+ this.consumer = t.consumer;
53
+ const s = t.baseUrl ?? h;
54
+ this.baseUrl = s.endsWith("/") ? s.slice(0, -1) : s, this.headers = {
110
55
  "Content-Type": "application/json",
111
56
  "X-MoonPay-Commerce-SDK-Version": O,
112
- ...(s = this.consumer) != null && s.name ? { "X-MoonPay-Commerce-Consumer": this.consumer.name } : {},
113
- ...(r = this.consumer) != null && r.version ? { "X-MoonPay-Commerce-Consumer-Version": this.consumer.version } : {},
57
+ ...(r = this.consumer) != null && r.name ? { "X-MoonPay-Commerce-Consumer": this.consumer.name } : {},
58
+ ...(n = this.consumer) != null && n.version ? { "X-MoonPay-Commerce-Consumer-Version": this.consumer.version } : {},
114
59
  ...t.headers
115
60
  }, this.fetch = t.fetch ?? globalThis.fetch.bind(globalThis);
116
61
  }
@@ -124,15 +69,15 @@ class P {
124
69
  return this.request("PATCH", t, s, r);
125
70
  }
126
71
  async request(t, s, r, n) {
127
- const E = `${this.baseUrl}${s}`, u = await this.fetch(E, {
72
+ const E = `${this.baseUrl}${s}`, i = await this.fetch(E, {
128
73
  method: t,
129
74
  headers: this.headers,
130
75
  body: r !== void 0 ? JSON.stringify(r) : void 0,
131
76
  signal: n
132
77
  });
133
- if (!u.ok)
134
- throw await this.buildError(u);
135
- return await u.json();
78
+ if (!i.ok)
79
+ throw await this.buildError(i);
80
+ return await i.json();
136
81
  }
137
82
  async buildError(t) {
138
83
  let s, r;
@@ -149,17 +94,75 @@ class P {
149
94
  );
150
95
  }
151
96
  }
97
+ const c = (e) => /^\d+$/.test(e);
98
+ function A(e) {
99
+ if (typeof e != "string") return null;
100
+ let t = e.trim();
101
+ if ((t.startsWith("v") || t.startsWith("V")) && (t = t.slice(1)), t === "") return null;
102
+ const s = t.indexOf("+");
103
+ s !== -1 && (t = t.slice(0, s));
104
+ const r = t.indexOf("-"), n = r === -1 ? t : t.slice(0, r), E = r === -1 ? "" : t.slice(r + 1), i = n.split(".");
105
+ if (i.length > 3) return null;
106
+ const u = [];
107
+ for (const I of i) {
108
+ if (!c(I)) return null;
109
+ u.push(Number(I));
110
+ }
111
+ const D = E === "" ? [] : E.split(".").filter((I) => I !== "");
112
+ return r !== -1 && D.length === 0 ? null : {
113
+ major: u[0] ?? 0,
114
+ minor: u[1] ?? 0,
115
+ patch: u[2] ?? 0,
116
+ prerelease: D
117
+ };
118
+ }
119
+ function _(e, t) {
120
+ return e < t ? -1 : e > t ? 1 : 0;
121
+ }
122
+ function m(e, t) {
123
+ if (e.length === 0 && t.length === 0) return 0;
124
+ if (e.length === 0) return 1;
125
+ if (t.length === 0) return -1;
126
+ const s = Math.min(e.length, t.length);
127
+ for (let r = 0; r < s; r++) {
128
+ const n = e[r], E = t[r];
129
+ if (n === E) continue;
130
+ const i = c(n), u = c(E);
131
+ if (i && u) {
132
+ const D = _(Number(n), Number(E));
133
+ if (D !== 0) return D;
134
+ } else return i ? -1 : u ? 1 : n < E ? -1 : 1;
135
+ }
136
+ return _(e.length, t.length);
137
+ }
138
+ function H(e, t) {
139
+ const s = A(e) ?? { major: 0, minor: 0, patch: 0, prerelease: [] }, r = A(t) ?? { major: 0, minor: 0, patch: 0, prerelease: [] }, n = _(s.major, r.major) || _(s.minor, r.minor) || _(s.patch, r.patch);
140
+ return n !== 0 ? n : m(s.prerelease, r.prerelease);
141
+ }
142
+ function C(e, t) {
143
+ return H(e, t) < 0;
144
+ }
145
+ const P = "@heliofi/withdraw-core";
146
+ function S(e = {}) {
147
+ const { minSupportedVersions: t, consumer: s } = e, r = (t == null ? void 0 : t.packages) ?? {}, n = e.sdkVersion ?? O, E = { [P]: n };
148
+ s != null && s.name && s.version != null && (E[s.name] = s.version);
149
+ for (const [i, u] of Object.entries(r)) {
150
+ const D = E[i];
151
+ if (D != null && C(D, u)) return !1;
152
+ }
153
+ return !0;
154
+ }
152
155
  class N {
153
156
  // Takes a prebuilt ApiClient (DI). Use `WithdrawalSDK.create()` for the
154
157
  // common case where you just have config.
155
158
  constructor(t) {
156
159
  this.api = t;
157
160
  }
158
- static create(t) {
159
- return new N(new P(t));
161
+ static create(t = {}) {
162
+ return new N(new U(t));
160
163
  }
161
164
  isSupported(t) {
162
- return C({
165
+ return S({
163
166
  minSupportedVersions: t,
164
167
  consumer: this.api.consumer
165
168
  });
@@ -220,22 +223,23 @@ class N {
220
223
  }
221
224
  }
222
225
  export {
223
- w as BlockchainEngineType,
224
- X as BlockchainSymbol,
225
- g as BroadcastAck,
226
- M as Platform,
227
- H as SDK_PACKAGE_NAME,
226
+ M as BlockchainEngineType,
227
+ w as BlockchainSymbol,
228
+ B as BroadcastAck,
229
+ h as DEFAULT_BASE_URL,
230
+ d as Platform,
231
+ P as SDK_PACKAGE_NAME,
228
232
  O as SDK_VERSION,
229
- B as SignedTransactionKind,
230
- G as TERMINAL_STATES,
233
+ G as SignedTransactionKind,
234
+ F as TERMINAL_STATES,
231
235
  W as WithdrawalApiError,
232
236
  R as WithdrawalErrorCode,
233
- d as WithdrawalFeature,
237
+ g as WithdrawalFeature,
234
238
  N as WithdrawalSDK,
235
- o as WithdrawalState,
239
+ T as WithdrawalState,
236
240
  L as decodeJwt,
237
- U as isBelow,
238
- F as isQuoteExpired,
239
- C as isSupported,
241
+ C as isBelow,
242
+ v as isQuoteExpired,
243
+ S as isSupported,
240
244
  f as toWithdrawalErrorCode
241
245
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@heliofi/withdraw-core",
3
3
  "private": false,
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -42,6 +42,6 @@
42
42
  "vitest": "3.2.4"
43
43
  },
44
44
  "dependencies": {
45
- "@heliofi/common-fe": "0.2.278-alpha.1782920922"
45
+ "@heliofi/common-fe": "0.2.286"
46
46
  }
47
47
  }