@lendasat/lendaswap-sdk-native 0.0.67
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 +116 -0
- package/index.d.ts +218 -0
- package/index.js +318 -0
- package/lendaswap-sdk-native.darwin-arm64.node +0 -0
- package/lendaswap-sdk-native.darwin-x64.node +0 -0
- package/lendaswap-sdk-native.linux-arm64-gnu.node +0 -0
- package/lendaswap-sdk-native.linux-x64-gnu.node +0 -0
- package/lendaswap-sdk-native.win32-x64-msvc.node +0 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @lendasat/lendaswap-sdk-native
|
|
2
|
+
|
|
3
|
+
Native Node.js bindings for Lendaswap with SQLite storage.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides native Node.js bindings via [napi-rs](https://napi.rs/) for the Lendaswap client with SQLite storage. It's designed for server-side applications, CLI tools, and backend services.
|
|
8
|
+
|
|
9
|
+
**Recommended:** Use this package through `@lendasat/lendaswap-sdk` with `.withSqliteStorage()` for a unified API across browser and Node.js.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Install both packages
|
|
15
|
+
pnpm add @lendasat/lendaswap-sdk @lendasat/lendaswap-sdk-native
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Platform Support
|
|
19
|
+
|
|
20
|
+
Pre-built binaries are available for:
|
|
21
|
+
|
|
22
|
+
- macOS (x64, ARM64)
|
|
23
|
+
- Linux (x64, ARM64)
|
|
24
|
+
- Windows (x64)
|
|
25
|
+
|
|
26
|
+
## Usage (Recommended)
|
|
27
|
+
|
|
28
|
+
Use the main SDK with SQLite storage:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { Client } from "@lendasat/lendaswap-sdk";
|
|
32
|
+
|
|
33
|
+
const client = await Client.builder()
|
|
34
|
+
.url("https://apilendaswap.lendasat.com")
|
|
35
|
+
.network("bitcoin")
|
|
36
|
+
.arkadeUrl("https://arkade.computer")
|
|
37
|
+
.esploraUrl("https://mempool.space/api")
|
|
38
|
+
.withSqliteStorage("./lendaswap.db")
|
|
39
|
+
.build();
|
|
40
|
+
|
|
41
|
+
await client.init();
|
|
42
|
+
|
|
43
|
+
// Get available trading pairs
|
|
44
|
+
const pairs = await client.getAssetPairs();
|
|
45
|
+
|
|
46
|
+
// Get a quote
|
|
47
|
+
const quote = await client.getQuote("btc_lightning", "usdc_pol", 100000n);
|
|
48
|
+
|
|
49
|
+
// Create a swap
|
|
50
|
+
const swap = await client.createLightningToEvmSwap({
|
|
51
|
+
target_address: "0xYourPolygonAddress",
|
|
52
|
+
source_amount: 100000,
|
|
53
|
+
target_token: "usdc_pol",
|
|
54
|
+
}, "polygon");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Direct Usage (Advanced)
|
|
58
|
+
|
|
59
|
+
For advanced use cases, you can use the native SDK directly:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import {
|
|
63
|
+
SqliteStorageHandle,
|
|
64
|
+
ClientBuilder,
|
|
65
|
+
} from "@lendasat/lendaswap-sdk-native";
|
|
66
|
+
|
|
67
|
+
const storage = SqliteStorageHandle.open("./lendaswap.db");
|
|
68
|
+
const client = new ClientBuilder()
|
|
69
|
+
.storage(storage)
|
|
70
|
+
.url("https://apilendaswap.lendasat.com")
|
|
71
|
+
.network("bitcoin")
|
|
72
|
+
.arkadeUrl("https://arkade.computer")
|
|
73
|
+
.esploraUrl("https://mempool.space/api")
|
|
74
|
+
.build();
|
|
75
|
+
|
|
76
|
+
await client.init();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## CLI Example
|
|
80
|
+
|
|
81
|
+
A full CLI example is available in `examples/nodejs/`:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cd client-sdk/examples/nodejs
|
|
85
|
+
pnpm install
|
|
86
|
+
node index.js help
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Commands:
|
|
90
|
+
|
|
91
|
+
- `pairs` - List available trading pairs
|
|
92
|
+
- `tokens` - List available tokens
|
|
93
|
+
- `quote <from> <to> <amount>` - Get a quote
|
|
94
|
+
- `swap <from> <to> <amount> <address>` - Create and monitor a swap
|
|
95
|
+
- `swaps` - List stored swaps with transaction links
|
|
96
|
+
- `info` - Show wallet and API info
|
|
97
|
+
|
|
98
|
+
## Supported Tokens
|
|
99
|
+
|
|
100
|
+
| Token | Chain | ID |
|
|
101
|
+
| ----- | --------- | --------------- |
|
|
102
|
+
| BTC | Lightning | `btc_lightning` |
|
|
103
|
+
| BTC | Arkade | `btc_arkade` |
|
|
104
|
+
| BTC | On-chain | `btc_onchain` |
|
|
105
|
+
| USDC | Polygon | `usdc_pol` |
|
|
106
|
+
| USDT | Polygon | `usdt0_pol` |
|
|
107
|
+
| USDC | Ethereum | `usdc_eth` |
|
|
108
|
+
| USDT | Ethereum | `usdt_eth` |
|
|
109
|
+
|
|
110
|
+
## Related Packages
|
|
111
|
+
|
|
112
|
+
- `@lendasat/lendaswap-sdk` - Main SDK with unified API for browser (IndexedDB) and Node.js (SQLite)
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
/** Swap status enum with all possible states. */
|
|
7
|
+
export const enum SwapStatus {
|
|
8
|
+
/** Initial state - waiting for client to fund */
|
|
9
|
+
Pending = 'Pending',
|
|
10
|
+
/** Client's funding transaction seen but not confirmed */
|
|
11
|
+
ClientFundingSeen = 'ClientFundingSeen',
|
|
12
|
+
/** Client has funded BTC */
|
|
13
|
+
ClientFunded = 'ClientFunded',
|
|
14
|
+
/** Client refunded before server created HTLC */
|
|
15
|
+
ClientRefunded = 'ClientRefunded',
|
|
16
|
+
/** Server has locked funds in HTLC */
|
|
17
|
+
ServerFunded = 'ServerFunded',
|
|
18
|
+
/** Client is claiming by revealing the secret */
|
|
19
|
+
ClientRedeeming = 'ClientRedeeming',
|
|
20
|
+
/** Client has claimed by revealing the secret */
|
|
21
|
+
ClientRedeemed = 'ClientRedeemed',
|
|
22
|
+
/** Server has redeemed using the revealed secret (swap complete) */
|
|
23
|
+
ServerRedeemed = 'ServerRedeemed',
|
|
24
|
+
/** Client funded, server funded, but HTLC timed out */
|
|
25
|
+
ClientFundedServerRefunded = 'ClientFundedServerRefunded',
|
|
26
|
+
/** Error state: client refunded while server still has funds locked */
|
|
27
|
+
ClientRefundedServerFunded = 'ClientRefundedServerFunded',
|
|
28
|
+
/** Both parties refunded after error state */
|
|
29
|
+
ClientRefundedServerRefunded = 'ClientRefundedServerRefunded',
|
|
30
|
+
/** Swap expired before client funded */
|
|
31
|
+
Expired = 'Expired',
|
|
32
|
+
/** Client funded with wrong parameters */
|
|
33
|
+
ClientInvalidFunded = 'ClientInvalidFunded',
|
|
34
|
+
/** Client funded too late (after timeout) */
|
|
35
|
+
ClientFundedTooLate = 'ClientFundedTooLate',
|
|
36
|
+
/** Critical error: client redeemed and refunded (took all money) */
|
|
37
|
+
ClientRedeemedAndClientRefunded = 'ClientRedeemedAndClientRefunded'
|
|
38
|
+
}
|
|
39
|
+
/** Quote response from the API. */
|
|
40
|
+
export interface QuoteResponse {
|
|
41
|
+
exchangeRate: string
|
|
42
|
+
networkFee: number
|
|
43
|
+
protocolFee: number
|
|
44
|
+
protocolFeeRate: number
|
|
45
|
+
minAmount: number
|
|
46
|
+
maxAmount: number
|
|
47
|
+
}
|
|
48
|
+
/** Token information. */
|
|
49
|
+
export interface TokenInfo {
|
|
50
|
+
tokenId: string
|
|
51
|
+
symbol: string
|
|
52
|
+
chain: string
|
|
53
|
+
name: string
|
|
54
|
+
decimals: number
|
|
55
|
+
}
|
|
56
|
+
/** Asset pair information. */
|
|
57
|
+
export interface AssetPair {
|
|
58
|
+
source: TokenInfo
|
|
59
|
+
target: TokenInfo
|
|
60
|
+
}
|
|
61
|
+
/** BTC to EVM swap response. */
|
|
62
|
+
export interface BtcToEvmSwapResponse {
|
|
63
|
+
id: string
|
|
64
|
+
status: SwapStatus
|
|
65
|
+
hashLock: string
|
|
66
|
+
feeSats: number
|
|
67
|
+
assetAmount: number
|
|
68
|
+
htlcAddressEvm: string
|
|
69
|
+
htlcAddressArkade: string
|
|
70
|
+
userAddressEvm: string
|
|
71
|
+
lnInvoice: string
|
|
72
|
+
satsReceive: number
|
|
73
|
+
sourceToken: string
|
|
74
|
+
targetToken: string
|
|
75
|
+
network: string
|
|
76
|
+
createdAt: string
|
|
77
|
+
/** Bitcoin HTLC claim transaction ID */
|
|
78
|
+
bitcoinHtlcClaimTxid?: string
|
|
79
|
+
/** Bitcoin HTLC fund transaction ID */
|
|
80
|
+
bitcoinHtlcFundTxid?: string
|
|
81
|
+
/** EVM HTLC claim transaction ID */
|
|
82
|
+
evmHtlcClaimTxid?: string
|
|
83
|
+
/** EVM HTLC fund transaction ID */
|
|
84
|
+
evmHtlcFundTxid?: string
|
|
85
|
+
}
|
|
86
|
+
/** EVM to BTC swap response. */
|
|
87
|
+
export interface EvmToBtcSwapResponse {
|
|
88
|
+
id: string
|
|
89
|
+
status: SwapStatus
|
|
90
|
+
hashLock: string
|
|
91
|
+
feeSats: number
|
|
92
|
+
assetAmount: number
|
|
93
|
+
htlcAddressEvm: string
|
|
94
|
+
htlcAddressArkade: string
|
|
95
|
+
userAddressEvm: string
|
|
96
|
+
lnInvoice: string
|
|
97
|
+
satsReceive: number
|
|
98
|
+
sourceToken: string
|
|
99
|
+
targetToken: string
|
|
100
|
+
network: string
|
|
101
|
+
createdAt: string
|
|
102
|
+
sourceTokenAddress: string
|
|
103
|
+
bitcoinHtlcFundTxid?: string
|
|
104
|
+
/** Bitcoin HTLC claim transaction ID */
|
|
105
|
+
bitcoinHtlcClaimTxid?: string
|
|
106
|
+
/** EVM HTLC claim transaction ID */
|
|
107
|
+
evmHtlcClaimTxid?: string
|
|
108
|
+
/** EVM HTLC fund transaction ID */
|
|
109
|
+
evmHtlcFundTxid?: string
|
|
110
|
+
}
|
|
111
|
+
/** BTC to Arkade swap response. */
|
|
112
|
+
export interface BtcToArkadeSwapResponse {
|
|
113
|
+
id: string
|
|
114
|
+
status: SwapStatus
|
|
115
|
+
btcHtlcAddress: string
|
|
116
|
+
assetAmount: number
|
|
117
|
+
satsReceive: number
|
|
118
|
+
feeSats: number
|
|
119
|
+
hashLock: string
|
|
120
|
+
arkadeVhtlcAddress: string
|
|
121
|
+
targetArkadeAddress: string
|
|
122
|
+
network: string
|
|
123
|
+
createdAt: string
|
|
124
|
+
sourceToken: string
|
|
125
|
+
targetToken: string
|
|
126
|
+
btcFundTxid?: string
|
|
127
|
+
/** On-chain BTC claim transaction ID. */
|
|
128
|
+
btcClaimTxid?: string
|
|
129
|
+
/** Arkade VHTLC funding transaction ID. */
|
|
130
|
+
arkadeFundTxid?: string
|
|
131
|
+
/** Arkade VHTLC claim transaction ID. */
|
|
132
|
+
arkadeClaimTxid?: string
|
|
133
|
+
}
|
|
134
|
+
/** Version information. */
|
|
135
|
+
export interface Version {
|
|
136
|
+
tag: string
|
|
137
|
+
commitHash: string
|
|
138
|
+
}
|
|
139
|
+
/** Extended swap storage data. */
|
|
140
|
+
export interface ExtendedSwapStorageData {
|
|
141
|
+
swapType: string
|
|
142
|
+
btcToEvmResponse?: BtcToEvmSwapResponse
|
|
143
|
+
evmToBtcResponse?: EvmToBtcSwapResponse
|
|
144
|
+
btcToArkadeResponse?: BtcToArkadeSwapResponse
|
|
145
|
+
}
|
|
146
|
+
/** SQLite storage handle for Node.js. */
|
|
147
|
+
export declare class SqliteStorageHandle {
|
|
148
|
+
/** Open or create a SQLite database at the given path. */
|
|
149
|
+
static open(path: string): SqliteStorageHandle
|
|
150
|
+
/** Create an in-memory SQLite database (useful for testing). */
|
|
151
|
+
static inMemory(): SqliteStorageHandle
|
|
152
|
+
}
|
|
153
|
+
/** Lendaswap client for Node.js with SQLite storage. */
|
|
154
|
+
export declare class Client {
|
|
155
|
+
/** Create a new client with SQLite storage. */
|
|
156
|
+
constructor(storage: SqliteStorageHandle, url: string, network: string, arkadeUrl: string, esploraUrl: string)
|
|
157
|
+
/** Initialize the client (generates or loads mnemonic). */
|
|
158
|
+
init(mnemonic?: string | undefined | null): Promise<void>
|
|
159
|
+
/** Get the current mnemonic. */
|
|
160
|
+
getMnemonic(): Promise<string>
|
|
161
|
+
/** Get the user ID xpub. */
|
|
162
|
+
getUserIdXpub(): Promise<string>
|
|
163
|
+
/** Get the API version. */
|
|
164
|
+
getVersion(): Promise<Version>
|
|
165
|
+
/** Get asset pairs. */
|
|
166
|
+
getAssetPairs(): Promise<Array<AssetPair>>
|
|
167
|
+
/** Get tokens. */
|
|
168
|
+
getTokens(): Promise<Array<TokenInfo>>
|
|
169
|
+
/** Get a quote. */
|
|
170
|
+
getQuote(from: string, to: string, baseAmount: number): Promise<QuoteResponse>
|
|
171
|
+
/** Create an Arkade to EVM swap. */
|
|
172
|
+
createArkadeToEvmSwap(targetAddress: string, sourceAmount: number | undefined | null, targetAmount: number | undefined | null, targetToken: string, targetChain: string, referralCode?: string | undefined | null): Promise<BtcToEvmSwapResponse>
|
|
173
|
+
/** Create a Lightning to EVM swap. */
|
|
174
|
+
createLightningToEvmSwap(targetAddress: string, sourceAmount: number | undefined | null, targetAmount: number | undefined | null, targetToken: string, targetChain: string, referralCode?: string | undefined | null): Promise<BtcToEvmSwapResponse>
|
|
175
|
+
/** Create an EVM to Arkade swap. */
|
|
176
|
+
createEvmToArkadeSwap(targetAddress: string, userAddress: string, sourceAmount: number, sourceToken: string, sourceChain: string, referralCode?: string | undefined | null): Promise<EvmToBtcSwapResponse>
|
|
177
|
+
/** Create an EVM to Lightning swap. */
|
|
178
|
+
createEvmToLightningSwap(bolt11Invoice: string, userAddress: string, sourceToken: string, sourceChain: string, referralCode?: string | undefined | null): Promise<EvmToBtcSwapResponse>
|
|
179
|
+
/** Create an on-chain Bitcoin to Arkade swap. */
|
|
180
|
+
createBitcoinToArkadeSwap(targetArkadeAddress: string, satsReceive: number, referralCode?: string | undefined | null): Promise<BtcToArkadeSwapResponse>
|
|
181
|
+
/** Get swap by ID. */
|
|
182
|
+
getSwap(id: string): Promise<ExtendedSwapStorageData>
|
|
183
|
+
/** List all swaps. */
|
|
184
|
+
listAll(): Promise<Array<ExtendedSwapStorageData>>
|
|
185
|
+
/** Claim via Gelato relay. */
|
|
186
|
+
claimGelato(swapId: string, secret?: string | undefined | null): Promise<void>
|
|
187
|
+
/** Claim VHTLC. */
|
|
188
|
+
claimVhtlc(swapId: string): Promise<string>
|
|
189
|
+
/** Refund VHTLC. */
|
|
190
|
+
refundVhtlc(swapId: string, refundAddress: string): Promise<string>
|
|
191
|
+
/** Claim BTC to Arkade VHTLC. */
|
|
192
|
+
claimBtcToArkadeVhtlc(swapId: string): Promise<string>
|
|
193
|
+
/** Refund on-chain HTLC. */
|
|
194
|
+
refundOnchainHtlc(swapId: string, refundAddress: string): Promise<string>
|
|
195
|
+
/** Recover swaps. */
|
|
196
|
+
recoverSwaps(): Promise<Array<ExtendedSwapStorageData>>
|
|
197
|
+
/** Clear swap storage. */
|
|
198
|
+
clearSwapStorage(): Promise<void>
|
|
199
|
+
/** Delete a specific swap. */
|
|
200
|
+
deleteSwap(id: string): Promise<void>
|
|
201
|
+
}
|
|
202
|
+
/** Client builder for Node.js. */
|
|
203
|
+
export declare class ClientBuilder {
|
|
204
|
+
/** Create a new client builder. */
|
|
205
|
+
constructor()
|
|
206
|
+
/** Set the SQLite storage. */
|
|
207
|
+
storage(storage: SqliteStorageHandle): this
|
|
208
|
+
/** Set the API URL. */
|
|
209
|
+
url(url: string): this
|
|
210
|
+
/** Set the Bitcoin network. */
|
|
211
|
+
network(network: string): this
|
|
212
|
+
/** Set the Arkade URL. */
|
|
213
|
+
arkadeUrl(url: string): this
|
|
214
|
+
/** Set the Esplora URL. */
|
|
215
|
+
esploraUrl(url: string): this
|
|
216
|
+
/** Build the client. */
|
|
217
|
+
build(): Client
|
|
218
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
|
|
7
|
+
const { existsSync, readFileSync } = require('fs')
|
|
8
|
+
const { join } = require('path')
|
|
9
|
+
|
|
10
|
+
const { platform, arch } = process
|
|
11
|
+
|
|
12
|
+
let nativeBinding = null
|
|
13
|
+
let localFileExisted = false
|
|
14
|
+
let loadError = null
|
|
15
|
+
|
|
16
|
+
function isMusl() {
|
|
17
|
+
// For Node 10
|
|
18
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
+
return !glibcVersionRuntime
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case 'android':
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case 'arm64':
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, 'lendaswap-sdk-native.android-arm64.node'))
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) {
|
|
38
|
+
nativeBinding = require('./lendaswap-sdk-native.android-arm64.node')
|
|
39
|
+
} else {
|
|
40
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-android-arm64')
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
loadError = e
|
|
44
|
+
}
|
|
45
|
+
break
|
|
46
|
+
case 'arm':
|
|
47
|
+
localFileExisted = existsSync(join(__dirname, 'lendaswap-sdk-native.android-arm-eabi.node'))
|
|
48
|
+
try {
|
|
49
|
+
if (localFileExisted) {
|
|
50
|
+
nativeBinding = require('./lendaswap-sdk-native.android-arm-eabi.node')
|
|
51
|
+
} else {
|
|
52
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-android-arm-eabi')
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
loadError = e
|
|
56
|
+
}
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case 'win32':
|
|
63
|
+
switch (arch) {
|
|
64
|
+
case 'x64':
|
|
65
|
+
localFileExisted = existsSync(
|
|
66
|
+
join(__dirname, 'lendaswap-sdk-native.win32-x64-msvc.node')
|
|
67
|
+
)
|
|
68
|
+
try {
|
|
69
|
+
if (localFileExisted) {
|
|
70
|
+
nativeBinding = require('./lendaswap-sdk-native.win32-x64-msvc.node')
|
|
71
|
+
} else {
|
|
72
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-win32-x64-msvc')
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadError = e
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
case 'ia32':
|
|
79
|
+
localFileExisted = existsSync(
|
|
80
|
+
join(__dirname, 'lendaswap-sdk-native.win32-ia32-msvc.node')
|
|
81
|
+
)
|
|
82
|
+
try {
|
|
83
|
+
if (localFileExisted) {
|
|
84
|
+
nativeBinding = require('./lendaswap-sdk-native.win32-ia32-msvc.node')
|
|
85
|
+
} else {
|
|
86
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-win32-ia32-msvc')
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadError = e
|
|
90
|
+
}
|
|
91
|
+
break
|
|
92
|
+
case 'arm64':
|
|
93
|
+
localFileExisted = existsSync(
|
|
94
|
+
join(__dirname, 'lendaswap-sdk-native.win32-arm64-msvc.node')
|
|
95
|
+
)
|
|
96
|
+
try {
|
|
97
|
+
if (localFileExisted) {
|
|
98
|
+
nativeBinding = require('./lendaswap-sdk-native.win32-arm64-msvc.node')
|
|
99
|
+
} else {
|
|
100
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-win32-arm64-msvc')
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
loadError = e
|
|
104
|
+
}
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
+
}
|
|
109
|
+
break
|
|
110
|
+
case 'darwin':
|
|
111
|
+
localFileExisted = existsSync(join(__dirname, 'lendaswap-sdk-native.darwin-universal.node'))
|
|
112
|
+
try {
|
|
113
|
+
if (localFileExisted) {
|
|
114
|
+
nativeBinding = require('./lendaswap-sdk-native.darwin-universal.node')
|
|
115
|
+
} else {
|
|
116
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-darwin-universal')
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
} catch {}
|
|
120
|
+
switch (arch) {
|
|
121
|
+
case 'x64':
|
|
122
|
+
localFileExisted = existsSync(join(__dirname, 'lendaswap-sdk-native.darwin-x64.node'))
|
|
123
|
+
try {
|
|
124
|
+
if (localFileExisted) {
|
|
125
|
+
nativeBinding = require('./lendaswap-sdk-native.darwin-x64.node')
|
|
126
|
+
} else {
|
|
127
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-darwin-x64')
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadError = e
|
|
131
|
+
}
|
|
132
|
+
break
|
|
133
|
+
case 'arm64':
|
|
134
|
+
localFileExisted = existsSync(
|
|
135
|
+
join(__dirname, 'lendaswap-sdk-native.darwin-arm64.node')
|
|
136
|
+
)
|
|
137
|
+
try {
|
|
138
|
+
if (localFileExisted) {
|
|
139
|
+
nativeBinding = require('./lendaswap-sdk-native.darwin-arm64.node')
|
|
140
|
+
} else {
|
|
141
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-darwin-arm64')
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
loadError = e
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
case 'freebsd':
|
|
152
|
+
if (arch !== 'x64') {
|
|
153
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
154
|
+
}
|
|
155
|
+
localFileExisted = existsSync(join(__dirname, 'lendaswap-sdk-native.freebsd-x64.node'))
|
|
156
|
+
try {
|
|
157
|
+
if (localFileExisted) {
|
|
158
|
+
nativeBinding = require('./lendaswap-sdk-native.freebsd-x64.node')
|
|
159
|
+
} else {
|
|
160
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-freebsd-x64')
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
loadError = e
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
case 'linux':
|
|
167
|
+
switch (arch) {
|
|
168
|
+
case 'x64':
|
|
169
|
+
if (isMusl()) {
|
|
170
|
+
localFileExisted = existsSync(
|
|
171
|
+
join(__dirname, 'lendaswap-sdk-native.linux-x64-musl.node')
|
|
172
|
+
)
|
|
173
|
+
try {
|
|
174
|
+
if (localFileExisted) {
|
|
175
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-x64-musl.node')
|
|
176
|
+
} else {
|
|
177
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-x64-musl')
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadError = e
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'lendaswap-sdk-native.linux-x64-gnu.node')
|
|
185
|
+
)
|
|
186
|
+
try {
|
|
187
|
+
if (localFileExisted) {
|
|
188
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-x64-gnu.node')
|
|
189
|
+
} else {
|
|
190
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-x64-gnu')
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadError = e
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break
|
|
197
|
+
case 'arm64':
|
|
198
|
+
if (isMusl()) {
|
|
199
|
+
localFileExisted = existsSync(
|
|
200
|
+
join(__dirname, 'lendaswap-sdk-native.linux-arm64-musl.node')
|
|
201
|
+
)
|
|
202
|
+
try {
|
|
203
|
+
if (localFileExisted) {
|
|
204
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-arm64-musl.node')
|
|
205
|
+
} else {
|
|
206
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-arm64-musl')
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadError = e
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
localFileExisted = existsSync(
|
|
213
|
+
join(__dirname, 'lendaswap-sdk-native.linux-arm64-gnu.node')
|
|
214
|
+
)
|
|
215
|
+
try {
|
|
216
|
+
if (localFileExisted) {
|
|
217
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-arm64-gnu.node')
|
|
218
|
+
} else {
|
|
219
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-arm64-gnu')
|
|
220
|
+
}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadError = e
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
break
|
|
226
|
+
case 'arm':
|
|
227
|
+
if (isMusl()) {
|
|
228
|
+
localFileExisted = existsSync(
|
|
229
|
+
join(__dirname, 'lendaswap-sdk-native.linux-arm-musleabihf.node')
|
|
230
|
+
)
|
|
231
|
+
try {
|
|
232
|
+
if (localFileExisted) {
|
|
233
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-arm-musleabihf.node')
|
|
234
|
+
} else {
|
|
235
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-arm-musleabihf')
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadError = e
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
localFileExisted = existsSync(
|
|
242
|
+
join(__dirname, 'lendaswap-sdk-native.linux-arm-gnueabihf.node')
|
|
243
|
+
)
|
|
244
|
+
try {
|
|
245
|
+
if (localFileExisted) {
|
|
246
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-arm-gnueabihf.node')
|
|
247
|
+
} else {
|
|
248
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-arm-gnueabihf')
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
loadError = e
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
break
|
|
255
|
+
case 'riscv64':
|
|
256
|
+
if (isMusl()) {
|
|
257
|
+
localFileExisted = existsSync(
|
|
258
|
+
join(__dirname, 'lendaswap-sdk-native.linux-riscv64-musl.node')
|
|
259
|
+
)
|
|
260
|
+
try {
|
|
261
|
+
if (localFileExisted) {
|
|
262
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-riscv64-musl.node')
|
|
263
|
+
} else {
|
|
264
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-riscv64-musl')
|
|
265
|
+
}
|
|
266
|
+
} catch (e) {
|
|
267
|
+
loadError = e
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'lendaswap-sdk-native.linux-riscv64-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-riscv64-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-riscv64-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case 's390x':
|
|
285
|
+
localFileExisted = existsSync(
|
|
286
|
+
join(__dirname, 'lendaswap-sdk-native.linux-s390x-gnu.node')
|
|
287
|
+
)
|
|
288
|
+
try {
|
|
289
|
+
if (localFileExisted) {
|
|
290
|
+
nativeBinding = require('./lendaswap-sdk-native.linux-s390x-gnu.node')
|
|
291
|
+
} else {
|
|
292
|
+
nativeBinding = require('@lendasat/lendaswap-sdk-native-linux-s390x-gnu')
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadError = e
|
|
296
|
+
}
|
|
297
|
+
break
|
|
298
|
+
default:
|
|
299
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
300
|
+
}
|
|
301
|
+
break
|
|
302
|
+
default:
|
|
303
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!nativeBinding) {
|
|
307
|
+
if (loadError) {
|
|
308
|
+
throw loadError
|
|
309
|
+
}
|
|
310
|
+
throw new Error(`Failed to load native binding`)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const { SqliteStorageHandle, SwapStatus, Client, ClientBuilder } = nativeBinding
|
|
314
|
+
|
|
315
|
+
module.exports.SqliteStorageHandle = SqliteStorageHandle
|
|
316
|
+
module.exports.SwapStatus = SwapStatus
|
|
317
|
+
module.exports.Client = Client
|
|
318
|
+
module.exports.ClientBuilder = ClientBuilder
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lendasat/lendaswap-sdk-native",
|
|
3
|
+
"version": "0.0.67",
|
|
4
|
+
"description": "Lendaswap Client SDK - Native Node.js bindings with SQLite storage",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">= 18"
|
|
10
|
+
},
|
|
11
|
+
"napi": {
|
|
12
|
+
"name": "lendaswap-sdk-native",
|
|
13
|
+
"triples": {
|
|
14
|
+
"defaults": true,
|
|
15
|
+
"additional": [
|
|
16
|
+
"aarch64-apple-darwin",
|
|
17
|
+
"x86_64-apple-darwin",
|
|
18
|
+
"x86_64-unknown-linux-gnu",
|
|
19
|
+
"aarch64-unknown-linux-gnu",
|
|
20
|
+
"x86_64-pc-windows-msvc"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@napi-rs/cli": "^2.18.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"*.node"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"artifacts": "napi artifacts",
|
|
34
|
+
"build": "napi build --platform --release",
|
|
35
|
+
"build:debug": "napi build --platform",
|
|
36
|
+
"universal": "napi universal",
|
|
37
|
+
"version": "napi version"
|
|
38
|
+
}
|
|
39
|
+
}
|