@arkade-os/swap 0.0.5 → 0.0.7
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 +79 -10
- package/dist/chunk-WGRU2DBF.js +38 -0
- package/dist/{chunk-Q4FAYBXS.js → chunk-ZDTRQZE2.js} +49 -15
- package/dist/index.cjs +103 -14
- package/dist/index.d.cts +46 -231
- package/dist/index.d.ts +46 -231
- package/dist/index.js +62 -35
- package/dist/nostr.cjs +15 -9
- package/dist/nostr.d.cts +4 -3
- package/dist/nostr.d.ts +4 -3
- package/dist/nostr.js +4 -11
- package/dist/repositories/realm/index.cjs +138 -0
- package/dist/repositories/realm/index.d.cts +103 -0
- package/dist/repositories/realm/index.d.ts +103 -0
- package/dist/repositories/realm/index.js +108 -0
- package/dist/repositories/sqlite/index.cjs +163 -0
- package/dist/repositories/sqlite/index.d.cts +63 -0
- package/dist/repositories/sqlite/index.d.ts +63 -0
- package/dist/repositories/sqlite/index.js +138 -0
- package/dist/repository-BwnZ8N62.d.cts +236 -0
- package/dist/repository-BwnZ8N62.d.ts +236 -0
- package/dist/{rfq-BH2yvo3O.d.cts → rfq-DfT9dAss.d.cts} +24 -11
- package/dist/{rfq-BH2yvo3O.d.ts → rfq-DfT9dAss.d.ts} +24 -11
- package/package.json +24 -4
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { DiscoveredMarket } from '@arkade-os/solver-discovery';
|
|
2
|
+
import { IWallet, ProvisionedKey, ProvisionedClaimSecret } from '@arkade-os/sdk';
|
|
3
|
+
|
|
4
|
+
type AssetSwapStatus = "pending" | "cancelling" | "fulfilled" | "cancelled" | "recoverable" | "awaiting_fill" | "claimable" | "claimed" | "refunded_l1";
|
|
5
|
+
/** The sentinel asset id for BTC itself, as opposed to a 68-hex asset id.
|
|
6
|
+
* Lives here with the {@link AssetSwap} fields it describes so the market and
|
|
7
|
+
* restore layers share one spelling instead of re-typing the literal. */
|
|
8
|
+
declare const BTC_ASSET_ID = "btc";
|
|
9
|
+
/**
|
|
10
|
+
* The record fields a wallet-provisioned secret becomes — what
|
|
11
|
+
* {@link swapSecretsToRecord} emits, and what every record type carrying swap
|
|
12
|
+
* secrets embeds.
|
|
13
|
+
*
|
|
14
|
+
* A named type rather than four fields restated per record: the mapper and the
|
|
15
|
+
* records it feeds must agree exactly, and a record that silently omits one of
|
|
16
|
+
* these round-trips a swap whose preimage cannot be re-derived. Embedding makes
|
|
17
|
+
* the omission a compile error instead.
|
|
18
|
+
*
|
|
19
|
+
* **Only `preimageHex` is secret.** `signingDescriptor` and `preimageSaltHex`
|
|
20
|
+
* are public derivation inputs — they must survive a field-mapped backend, but
|
|
21
|
+
* they leak nothing without the seed.
|
|
22
|
+
*/
|
|
23
|
+
interface SwapSecretsProjection {
|
|
24
|
+
/**
|
|
25
|
+
* The wallet descriptor this swap's sender key comes from — a fresh HD
|
|
26
|
+
* child, or a static wallet's `tr(pubkey)`. Public — the signer
|
|
27
|
+
* re-derives from the wallet, so the record carries no key material.
|
|
28
|
+
*/
|
|
29
|
+
signingDescriptor?: string;
|
|
30
|
+
/** P, hex, when it cannot be re-derived from the seed at all: the user
|
|
31
|
+
* supplied it, or the signer cannot sign deterministically. The swap's only
|
|
32
|
+
* claim secret when present. */
|
|
33
|
+
preimageHex?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The salt P derives from, hex, on the salted arm — what a static wallet
|
|
36
|
+
* gets instead of storing P. **Public**, and unlike every other field here
|
|
37
|
+
* it is minted per swap: it is what stops one repeating key from handing
|
|
38
|
+
* every swap the same preimage.
|
|
39
|
+
*/
|
|
40
|
+
preimageSaltHex?: string;
|
|
41
|
+
}
|
|
42
|
+
interface AssetSwap extends SwapSecretsProjection {
|
|
43
|
+
/** Funding txid — the swap's identity. */
|
|
44
|
+
id: string;
|
|
45
|
+
/** 'btc' or a 68-hex asset id. */
|
|
46
|
+
fromAsset: string;
|
|
47
|
+
toAsset: string;
|
|
48
|
+
/** Atomic amounts as strings (bigint is not JSON-safe). */
|
|
49
|
+
fromAmount: string;
|
|
50
|
+
/** The covenant wantAmount — a floor, the fill pays >= this. */
|
|
51
|
+
toAmount: string;
|
|
52
|
+
swapAddress: string;
|
|
53
|
+
/** Hex pkScript of the swap contract — the indexer monitoring key. */
|
|
54
|
+
swapPkScript: string;
|
|
55
|
+
/** TLV offer — needed to rebuild the contract for cancel. */
|
|
56
|
+
offerHex: string;
|
|
57
|
+
fundingTxid: string;
|
|
58
|
+
spentTxid?: string;
|
|
59
|
+
status: AssetSwapStatus;
|
|
60
|
+
createdAt: number;
|
|
61
|
+
completedAt?: number;
|
|
62
|
+
/** RFQ pair string, e.g. `arkade:BTC->onchain:BTC`. */
|
|
63
|
+
pair?: string;
|
|
64
|
+
/** `sha256(P)`, hex. Public, and how a restore confirms a candidate
|
|
65
|
+
* derivation is the right one. */
|
|
66
|
+
paymentHash?: string;
|
|
67
|
+
/** The L1 HTLC's pkScript, hex — the chain-watch key. */
|
|
68
|
+
htlcPkScriptHex?: string;
|
|
69
|
+
htlcLocktime?: number;
|
|
70
|
+
/** The L1 funding txid, once observed. */
|
|
71
|
+
l1Txid?: string;
|
|
72
|
+
}
|
|
73
|
+
/** All swaps, newest-first. Insertion order is not chronological — the restore
|
|
74
|
+
* scan rebuilds records in tx-scan order — so sort at read to keep
|
|
75
|
+
* newest-first canonical for every consumer. */
|
|
76
|
+
declare const getAssetSwapsOrThrow: (repository: AssetSwapRepository) => Promise<AssetSwap[]>;
|
|
77
|
+
/** The consumer read: a broken backend reads as no swaps rather than crashing
|
|
78
|
+
* a history view. Mutations must use {@link getAssetSwapsOrThrow} instead —
|
|
79
|
+
* swallowing the read there would let "the backend is gone" masquerade as "no
|
|
80
|
+
* such swap" and skip the write silently. */
|
|
81
|
+
declare const getAssetSwaps: (repository: AssetSwapRepository) => Promise<AssetSwap[]>;
|
|
82
|
+
/** Add a swap; no-op if the id is already stored. Returns the updated list.
|
|
83
|
+
* THROWS on a failed write — nothing irreversible may happen until this record
|
|
84
|
+
* is durable, so the caller must not fund on a failure. */
|
|
85
|
+
declare const addAssetSwap: (repository: AssetSwapRepository, swap: AssetSwap) => Promise<AssetSwap[]>;
|
|
86
|
+
/** Merge changes into a swap by id. Returns the updated list.
|
|
87
|
+
* THROWS on a failed read or write, like {@link addAssetSwap} — use this for a
|
|
88
|
+
* write that gates something irreversible. Transitions written *after* the
|
|
89
|
+
* irreversible act belong on {@link updateAssetSwapBestEffort}. */
|
|
90
|
+
declare const updateAssetSwap: (repository: AssetSwapRepository, id: string, changes: Partial<Omit<AssetSwap, "id">>) => Promise<AssetSwap[]>;
|
|
91
|
+
/**
|
|
92
|
+
* {@link updateAssetSwap} for transitions that follow an irreversible action (a
|
|
93
|
+
* broadcast claim, a spent lockup): failing the caller there would report as
|
|
94
|
+
* failed a swap whose funds already moved, and a stale status is recoverable —
|
|
95
|
+
* crash recovery re-derives the true state from the chain
|
|
96
|
+
* (`classifyOnchainHtlc`).
|
|
97
|
+
*
|
|
98
|
+
* `persisted` is the part that must not be hidden: a caller that notifies on a
|
|
99
|
+
* change, or treats one as terminal, has to know the store did not agree.
|
|
100
|
+
*/
|
|
101
|
+
declare const updateAssetSwapBestEffort: (repository: AssetSwapRepository, id: string, changes: Partial<Omit<AssetSwap, "id">>) => Promise<{
|
|
102
|
+
swaps: AssetSwap[];
|
|
103
|
+
persisted: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* The record fields a wallet-provisioned secret becomes.
|
|
107
|
+
*
|
|
108
|
+
* `signingDescriptor` is public and always stored — it is what recovers the
|
|
109
|
+
* signer. Then at most one of: `preimageHex`, when the wallet says it cannot
|
|
110
|
+
* re-derive P and it becomes the swap's only claim secret; or
|
|
111
|
+
* `preimageSaltHex`, the public input a derivable-but-repeating key needs.
|
|
112
|
+
*/
|
|
113
|
+
declare const swapSecretsToRecord: (secrets: ProvisionedKey | ProvisionedClaimSecret) => SwapSecretsProjection & {
|
|
114
|
+
signingDescriptor: string;
|
|
115
|
+
};
|
|
116
|
+
/** Why a wallet cannot produce a swap's preimage. */
|
|
117
|
+
type PreimageBlockedReason =
|
|
118
|
+
/** The record carries no `signingDescriptor`. */
|
|
119
|
+
"no-secrets"
|
|
120
|
+
/** `preimageHex` or `preimageSaltHex` is present but not 32 bytes of hex. */
|
|
121
|
+
| "malformed-record"
|
|
122
|
+
/**
|
|
123
|
+
* Nothing to derive from: a descriptor that repeats across swaps, with
|
|
124
|
+
* neither a stored preimage nor a salt — or one this wallet holds no key
|
|
125
|
+
* for. Merged deliberately: `contractSigner` reports a key it does not
|
|
126
|
+
* hold as a plain `Error` for static wallets and a `ForeignDescriptorError`
|
|
127
|
+
* for HD ones, so splitting the two here would mean matching on message
|
|
128
|
+
* text, which is the thing this type exists to avoid. The `cause` carries
|
|
129
|
+
* whichever it was.
|
|
130
|
+
*/
|
|
131
|
+
| "not-derivable"
|
|
132
|
+
/** Derived, but it does not hash to the record's `paymentHash`. */
|
|
133
|
+
| "hash-mismatch";
|
|
134
|
+
/**
|
|
135
|
+
* The wallet cannot produce this swap's preimage, and which of the four ways
|
|
136
|
+
* is `reason`.
|
|
137
|
+
*
|
|
138
|
+
* Deliberately **not** {@link RefundNotLocallyPossibleError}: that one means
|
|
139
|
+
* "no local refund is possible", and `RfqSwapManager` acts on it by reporting
|
|
140
|
+
* `needs_counterparty`. A claim-path read failure is a different verdict, and
|
|
141
|
+
* borrowing the refund error would have the manager announce one for the
|
|
142
|
+
* other.
|
|
143
|
+
*/
|
|
144
|
+
declare class PreimageNotRecoverableError extends Error {
|
|
145
|
+
readonly reason: PreimageBlockedReason;
|
|
146
|
+
readonly name = "PreimageNotRecoverableError";
|
|
147
|
+
constructor(reason: PreimageBlockedReason, message: string, options?: {
|
|
148
|
+
cause?: unknown;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The preimage a swap record claims with — stored, or re-derived from the
|
|
153
|
+
* wallet.
|
|
154
|
+
*
|
|
155
|
+
* The record-shaped inverse of {@link swapSecretsToRecord}, and the one place
|
|
156
|
+
* that knows which of a record's fields `contractPreimage` needs. Wire claim
|
|
157
|
+
* paths here rather than composing it by hand: a caller that forgets to pass
|
|
158
|
+
* `preimageSaltHex` gets a *wrong* preimage from a wallet that can derive,
|
|
159
|
+
* not an error.
|
|
160
|
+
*
|
|
161
|
+
* Verifies the result against `paymentHash` when the record carries one. The
|
|
162
|
+
* salted arm has two inputs that can be wrong — the key and the salt — where
|
|
163
|
+
* the HD arm had one, and a wrong P otherwise surfaces as an opaque script
|
|
164
|
+
* failure at claim time, long after the mistake.
|
|
165
|
+
*
|
|
166
|
+
* Every refusal is a {@link PreimageNotRecoverableError} carrying a `reason`,
|
|
167
|
+
* so a caller can tell "this record predates the descriptor" from "the salt is
|
|
168
|
+
* corrupt" without reading message text.
|
|
169
|
+
*/
|
|
170
|
+
declare const preimageForSwapRecord: (wallet: IWallet, record: SwapSecretsProjection & {
|
|
171
|
+
paymentHash?: string;
|
|
172
|
+
}) => Promise<Uint8Array>;
|
|
173
|
+
|
|
174
|
+
/** A registry discovery result held for reuse. Refetchable — unlike a swap
|
|
175
|
+
* record, losing it costs one network round trip — but it must survive a cold
|
|
176
|
+
* boot: serving it stale is what keeps quoting alive while a registry is down. */
|
|
177
|
+
interface MarketsCacheEntry {
|
|
178
|
+
markets: DiscoveredMarket[];
|
|
179
|
+
fetchedAt: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Everything the package persists, following the monorepo repository
|
|
183
|
+
* convention (versioned interface, AsyncDisposable, one backend per
|
|
184
|
+
* platform — see the Boltz plugin's SwapRepository). Consumers construct
|
|
185
|
+
* exactly one of these; there is no second storage seam.
|
|
186
|
+
*
|
|
187
|
+
* Durable records (swaps) and rebuildable state (the restore scan's txid
|
|
188
|
+
* cursor, the markets cache) live side by side because they share a
|
|
189
|
+
* lifetime: all three belong to one wallet on one device, and a consumer
|
|
190
|
+
* that wipes one wants all three gone.
|
|
191
|
+
*
|
|
192
|
+
* ponytail: no query filters — every consumer reads all swaps and filters
|
|
193
|
+
* in memory; mirror the Boltz plugin's GetSwapsFilter when a consumer needs
|
|
194
|
+
* subset queries.
|
|
195
|
+
*/
|
|
196
|
+
interface AssetSwapRepository extends AsyncDisposable {
|
|
197
|
+
readonly version: 2;
|
|
198
|
+
/** Insert or replace a swap by id. Store the record whole: `preimageHex`
|
|
199
|
+
* and `preimageSaltHex` both leave the swap unclaimable if a field-mapped
|
|
200
|
+
* backend drops them — the first is the only claim secret of a swap whose
|
|
201
|
+
* signer cannot derive, the second the public input every other static
|
|
202
|
+
* wallet's preimage derives from.
|
|
203
|
+
*
|
|
204
|
+
* Records must be **JSON-safe**: the SQLite and Realm backends serialize
|
|
205
|
+
* the record to JSON, so a `Date` in a consumer-added field comes back a
|
|
206
|
+
* string, a `Set`/`Map` comes back empty, and a `bigint` throws here —
|
|
207
|
+
* none of which happens on IndexedDB's structured clone. `AssetSwap` as
|
|
208
|
+
* declared is JSON-safe; keep added fields that way. */
|
|
209
|
+
saveSwap(swap: AssetSwap): Promise<void>;
|
|
210
|
+
/** All stored swaps, in no particular order — `getAssetSwaps` is the
|
|
211
|
+
* canonical newest-first read. */
|
|
212
|
+
getAllSwaps(): Promise<AssetSwap[]>;
|
|
213
|
+
/** Sent txids already checked for offer packets (see restore.ts). */
|
|
214
|
+
getScannedTxids(): Promise<Set<string>>;
|
|
215
|
+
markTxidsScanned(txids: Iterable<string>): Promise<void>;
|
|
216
|
+
/** Cached registry markets, or undefined on a miss. */
|
|
217
|
+
getCachedMarkets(network: string, registry: string): Promise<MarketsCacheEntry | undefined>;
|
|
218
|
+
saveCachedMarkets(network: string, registry: string, entry: MarketsCacheEntry): Promise<void>;
|
|
219
|
+
clear(): Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
declare class InMemoryAssetSwapRepository implements AssetSwapRepository {
|
|
222
|
+
readonly version: 2;
|
|
223
|
+
private readonly swaps;
|
|
224
|
+
private readonly scanned;
|
|
225
|
+
private readonly markets;
|
|
226
|
+
saveSwap(swap: AssetSwap): Promise<void>;
|
|
227
|
+
getAllSwaps(): Promise<AssetSwap[]>;
|
|
228
|
+
getScannedTxids(): Promise<Set<string>>;
|
|
229
|
+
markTxidsScanned(txids: Iterable<string>): Promise<void>;
|
|
230
|
+
getCachedMarkets(network: string, registry: string): Promise<MarketsCacheEntry | undefined>;
|
|
231
|
+
saveCachedMarkets(network: string, registry: string, entry: MarketsCacheEntry): Promise<void>;
|
|
232
|
+
clear(): Promise<void>;
|
|
233
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { type AssetSwapRepository as A, BTC_ASSET_ID as B, InMemoryAssetSwapRepository as I, type MarketsCacheEntry as M, type PreimageBlockedReason as P, type SwapSecretsProjection as S, type AssetSwap as a, type AssetSwapStatus as b, PreimageNotRecoverableError as c, addAssetSwap as d, getAssetSwapsOrThrow as e, updateAssetSwapBestEffort as f, getAssetSwaps as g, preimageForSwapRecord as p, swapSecretsToRecord as s, updateAssetSwap as u };
|
|
@@ -210,13 +210,25 @@ declare function classifyOnchainHtlc(chain: ChainSource, input: {
|
|
|
210
210
|
};
|
|
211
211
|
}): Promise<OnchainHtlcPhase>;
|
|
212
212
|
|
|
213
|
-
/** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`.
|
|
214
|
-
* asset legs stay coarse (`arkade:ASSET`) — the exact asset ids ride the
|
|
215
|
-
* request profile, mirroring how the offer TLV identifies assets. */
|
|
213
|
+
/** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`. */
|
|
216
214
|
declare const ARKADE_BTC = "arkade:BTC";
|
|
217
|
-
declare const ARKADE_ASSET = "arkade:ASSET";
|
|
218
215
|
declare const LIGHTNING_BTC = "lightning:BTC";
|
|
219
216
|
declare const ONCHAIN_BTC = "onchain:BTC";
|
|
217
|
+
/** The arkade leg for an asset: the asset id itself, 68 lowercase hex. The id
|
|
218
|
+
* lives in the pair rather than the profile because the pair is the field both
|
|
219
|
+
* sides route and subscribe on, and a coarse leg cannot say which asset a
|
|
220
|
+
* market key is for.
|
|
221
|
+
*
|
|
222
|
+
* Taking an `AssetId` rather than a string is what enforces the case rule:
|
|
223
|
+
* `hex.decode` accepts uppercase while `hex.encode` only emits lowercase, so a
|
|
224
|
+
* value that reached us as `A1B2…` leaves here as `a1b2…`. Solvers compare pair
|
|
225
|
+
* strings byte for byte — a sender that normalised only in its key derivation
|
|
226
|
+
* would reach the right subscription and then be skipped as an unserved pair. */
|
|
227
|
+
declare const arkadeAssetLeg: (id: asset.AssetId) => string;
|
|
228
|
+
/** @deprecated The coarse asset leg. No solver serves it: `ASSET` is neither a
|
|
229
|
+
* registered ticker nor a 68-hex asset id, so a solver's market-key derivation
|
|
230
|
+
* throws on it. Use {@link arkadeAssetLeg}. Removed next major. */
|
|
231
|
+
declare const ARKADE_ASSET = "arkade:ASSET";
|
|
220
232
|
declare const rfqPair: (from: string, to: string) => string;
|
|
221
233
|
/** The implemented pair: pay a BOLT11 invoice out of an Arkade balance. */
|
|
222
234
|
declare const LIGHTNING_SEND_PAIR: string;
|
|
@@ -276,9 +288,10 @@ interface RfqStatus {
|
|
|
276
288
|
* `senderPubkey` is the trader's own key for the VHTLC's sender-side leaves
|
|
277
289
|
* (see {@link lightningSendVtxoScript}) — required, never sent anywhere else,
|
|
278
290
|
* never trusted by the solver as anything but a pubkey to bind into the
|
|
279
|
-
* script. On the wire it's `client_refund_pubkey` (
|
|
280
|
-
* the solver's schema
|
|
281
|
-
*
|
|
291
|
+
* script. On the wire it's `client_refund_pubkey` (the payload schemas are
|
|
292
|
+
* public at https://docs.arkadeos.com/intents/reference/rfq — the solver's schema
|
|
293
|
+
* is `.strict()`, so both the wrong name AND the missing required field would
|
|
294
|
+
* refuse every request). */
|
|
282
295
|
declare const lightningSendRequest: (input: {
|
|
283
296
|
rfqId: string;
|
|
284
297
|
invoice: string;
|
|
@@ -286,9 +299,9 @@ declare const lightningSendRequest: (input: {
|
|
|
286
299
|
senderPubkey: Uint8Array;
|
|
287
300
|
}) => Record<string, unknown>;
|
|
288
301
|
/** The rfq_request for an arkade↔arkade swap. Exactly one side may name an
|
|
289
|
-
* asset id per direction (BTC has none)
|
|
290
|
-
*
|
|
291
|
-
*
|
|
302
|
+
* asset id per direction (BTC has none), and the id is the leg itself — see
|
|
303
|
+
* {@link arkadeAssetLeg}. Forward-looking: the wire shape is specified, the
|
|
304
|
+
* reference solver does not serve it yet. */
|
|
292
305
|
declare const arkadeSwapRequest: (input: {
|
|
293
306
|
rfqId: string;
|
|
294
307
|
/** Asset the trader deposits; omit when depositing BTC. */
|
|
@@ -919,4 +932,4 @@ declare function requestOnchainReceive(wallet: IWallet, arkServerUrl: string, tr
|
|
|
919
932
|
secrets: ProvisionedClaimSecret;
|
|
920
933
|
}>;
|
|
921
934
|
|
|
922
|
-
export {
|
|
935
|
+
export { onchainReceiveRequest as $, ARKADE_ASSET as A, assertReceivable as B, type ChainSource as C, awaitOnchainFill as D, buildHtlcClaim as E, buildHtlcRefund as F, claimOnchainFill as G, type HtlcUtxo as H, type InvoiceFacts as I, classifyOnchainHtlc as J, deriveLightningReceive as K, LIGHTNING_BTC as L, MAX_MIN_CONFIRMATIONS as M, deriveOnchainReceive as N, type OnchainHtlc as O, deriveOnchainSend as P, extractPreimage as Q, type RfqStatus as R, SOLO_REFUND_HEADROOM_SECONDS as S, httpTransport as T, lightningReceiveRequest as U, lightningSendRequest as V, lightningSendVtxoScript as W, newPreimage as X, newRfqId as Y, offerTermsFromQuote as Z, onchainHtlcScript as _, type RfqTransport as a, onchainSendRequest as a0, paymentHashOf as a1, receiveVtxoScript as a2, relayTransport as a3, requestLightningReceive as a4, requestLightningSend as a5, requestOnchainReceive as a6, requestOnchainSend as a7, rfqPair as a8, unilateralClaimDelay as a9, unilateralRefundDelay as aa, unilateralRefundWithoutReceiverDelay as ab, verifyLockupAddress as ac, verifyReceiveInvoice as ad, type ChainUtxo as b, type OnchainHtlcPhase as c, ARKADE_BTC as d, AddressMismatch as e, LIGHTNING_RECEIVE_PAIR as f, LIGHTNING_SEND_PAIR as g, MIN_CLAIM_WINDOW_SECONDS as h, MIN_HEADROOM_SECONDS as i, ONCHAIN_BTC as j, ONCHAIN_CLAIM_MARGIN_SECONDS as k, ONCHAIN_DUST_SATS as l, ONCHAIN_ORDER_MARGIN_SECONDS as m, ONCHAIN_RECEIVE_PAIR as n, ONCHAIN_SECONDS_PER_BLOCK as o, ONCHAIN_SEND_PAIR as p, type OnchainHtlcParams as q, type OnchainNetwork as r, RFQ_TERMINAL_STATES as s, type RelaySocket as t, type RfqQuote as u, type RfqRefusalReason as v, SwapRefusal as w, arkadeAssetLeg as x, arkadeSwapRequest as y, assertFundable as z };
|
|
@@ -210,13 +210,25 @@ declare function classifyOnchainHtlc(chain: ChainSource, input: {
|
|
|
210
210
|
};
|
|
211
211
|
}): Promise<OnchainHtlcPhase>;
|
|
212
212
|
|
|
213
|
-
/** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`.
|
|
214
|
-
* asset legs stay coarse (`arkade:ASSET`) — the exact asset ids ride the
|
|
215
|
-
* request profile, mirroring how the offer TLV identifies assets. */
|
|
213
|
+
/** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`. */
|
|
216
214
|
declare const ARKADE_BTC = "arkade:BTC";
|
|
217
|
-
declare const ARKADE_ASSET = "arkade:ASSET";
|
|
218
215
|
declare const LIGHTNING_BTC = "lightning:BTC";
|
|
219
216
|
declare const ONCHAIN_BTC = "onchain:BTC";
|
|
217
|
+
/** The arkade leg for an asset: the asset id itself, 68 lowercase hex. The id
|
|
218
|
+
* lives in the pair rather than the profile because the pair is the field both
|
|
219
|
+
* sides route and subscribe on, and a coarse leg cannot say which asset a
|
|
220
|
+
* market key is for.
|
|
221
|
+
*
|
|
222
|
+
* Taking an `AssetId` rather than a string is what enforces the case rule:
|
|
223
|
+
* `hex.decode` accepts uppercase while `hex.encode` only emits lowercase, so a
|
|
224
|
+
* value that reached us as `A1B2…` leaves here as `a1b2…`. Solvers compare pair
|
|
225
|
+
* strings byte for byte — a sender that normalised only in its key derivation
|
|
226
|
+
* would reach the right subscription and then be skipped as an unserved pair. */
|
|
227
|
+
declare const arkadeAssetLeg: (id: asset.AssetId) => string;
|
|
228
|
+
/** @deprecated The coarse asset leg. No solver serves it: `ASSET` is neither a
|
|
229
|
+
* registered ticker nor a 68-hex asset id, so a solver's market-key derivation
|
|
230
|
+
* throws on it. Use {@link arkadeAssetLeg}. Removed next major. */
|
|
231
|
+
declare const ARKADE_ASSET = "arkade:ASSET";
|
|
220
232
|
declare const rfqPair: (from: string, to: string) => string;
|
|
221
233
|
/** The implemented pair: pay a BOLT11 invoice out of an Arkade balance. */
|
|
222
234
|
declare const LIGHTNING_SEND_PAIR: string;
|
|
@@ -276,9 +288,10 @@ interface RfqStatus {
|
|
|
276
288
|
* `senderPubkey` is the trader's own key for the VHTLC's sender-side leaves
|
|
277
289
|
* (see {@link lightningSendVtxoScript}) — required, never sent anywhere else,
|
|
278
290
|
* never trusted by the solver as anything but a pubkey to bind into the
|
|
279
|
-
* script. On the wire it's `client_refund_pubkey` (
|
|
280
|
-
* the solver's schema
|
|
281
|
-
*
|
|
291
|
+
* script. On the wire it's `client_refund_pubkey` (the payload schemas are
|
|
292
|
+
* public at https://docs.arkadeos.com/intents/reference/rfq — the solver's schema
|
|
293
|
+
* is `.strict()`, so both the wrong name AND the missing required field would
|
|
294
|
+
* refuse every request). */
|
|
282
295
|
declare const lightningSendRequest: (input: {
|
|
283
296
|
rfqId: string;
|
|
284
297
|
invoice: string;
|
|
@@ -286,9 +299,9 @@ declare const lightningSendRequest: (input: {
|
|
|
286
299
|
senderPubkey: Uint8Array;
|
|
287
300
|
}) => Record<string, unknown>;
|
|
288
301
|
/** The rfq_request for an arkade↔arkade swap. Exactly one side may name an
|
|
289
|
-
* asset id per direction (BTC has none)
|
|
290
|
-
*
|
|
291
|
-
*
|
|
302
|
+
* asset id per direction (BTC has none), and the id is the leg itself — see
|
|
303
|
+
* {@link arkadeAssetLeg}. Forward-looking: the wire shape is specified, the
|
|
304
|
+
* reference solver does not serve it yet. */
|
|
292
305
|
declare const arkadeSwapRequest: (input: {
|
|
293
306
|
rfqId: string;
|
|
294
307
|
/** Asset the trader deposits; omit when depositing BTC. */
|
|
@@ -919,4 +932,4 @@ declare function requestOnchainReceive(wallet: IWallet, arkServerUrl: string, tr
|
|
|
919
932
|
secrets: ProvisionedClaimSecret;
|
|
920
933
|
}>;
|
|
921
934
|
|
|
922
|
-
export {
|
|
935
|
+
export { onchainReceiveRequest as $, ARKADE_ASSET as A, assertReceivable as B, type ChainSource as C, awaitOnchainFill as D, buildHtlcClaim as E, buildHtlcRefund as F, claimOnchainFill as G, type HtlcUtxo as H, type InvoiceFacts as I, classifyOnchainHtlc as J, deriveLightningReceive as K, LIGHTNING_BTC as L, MAX_MIN_CONFIRMATIONS as M, deriveOnchainReceive as N, type OnchainHtlc as O, deriveOnchainSend as P, extractPreimage as Q, type RfqStatus as R, SOLO_REFUND_HEADROOM_SECONDS as S, httpTransport as T, lightningReceiveRequest as U, lightningSendRequest as V, lightningSendVtxoScript as W, newPreimage as X, newRfqId as Y, offerTermsFromQuote as Z, onchainHtlcScript as _, type RfqTransport as a, onchainSendRequest as a0, paymentHashOf as a1, receiveVtxoScript as a2, relayTransport as a3, requestLightningReceive as a4, requestLightningSend as a5, requestOnchainReceive as a6, requestOnchainSend as a7, rfqPair as a8, unilateralClaimDelay as a9, unilateralRefundDelay as aa, unilateralRefundWithoutReceiverDelay as ab, verifyLockupAddress as ac, verifyReceiveInvoice as ad, type ChainUtxo as b, type OnchainHtlcPhase as c, ARKADE_BTC as d, AddressMismatch as e, LIGHTNING_RECEIVE_PAIR as f, LIGHTNING_SEND_PAIR as g, MIN_CLAIM_WINDOW_SECONDS as h, MIN_HEADROOM_SECONDS as i, ONCHAIN_BTC as j, ONCHAIN_CLAIM_MARGIN_SECONDS as k, ONCHAIN_DUST_SATS as l, ONCHAIN_ORDER_MARGIN_SECONDS as m, ONCHAIN_RECEIVE_PAIR as n, ONCHAIN_SECONDS_PER_BLOCK as o, ONCHAIN_SEND_PAIR as p, type OnchainHtlcParams as q, type OnchainNetwork as r, RFQ_TERMINAL_STATES as s, type RelaySocket as t, type RfqQuote as u, type RfqRefusalReason as v, SwapRefusal as w, arkadeAssetLeg as x, arkadeSwapRequest as y, assertFundable as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkade-os/swap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Client-side Arkade Intents asset swaps: discover markets, quote, create/track/cancel offers, restore from chain.",
|
|
6
6
|
"repository": {
|
|
@@ -30,6 +30,26 @@
|
|
|
30
30
|
"types": "./dist/nostr.d.ts",
|
|
31
31
|
"default": "./dist/nostr.cjs"
|
|
32
32
|
}
|
|
33
|
+
},
|
|
34
|
+
"./repositories/sqlite": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/repositories/sqlite/index.d.ts",
|
|
37
|
+
"default": "./dist/repositories/sqlite/index.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/repositories/sqlite/index.d.ts",
|
|
41
|
+
"default": "./dist/repositories/sqlite/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./repositories/realm": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/repositories/realm/index.d.ts",
|
|
47
|
+
"default": "./dist/repositories/realm/index.js"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/repositories/realm/index.d.ts",
|
|
51
|
+
"default": "./dist/repositories/realm/index.cjs"
|
|
52
|
+
}
|
|
33
53
|
}
|
|
34
54
|
},
|
|
35
55
|
"files": [
|
|
@@ -44,12 +64,12 @@
|
|
|
44
64
|
"author": "Arkade-OS",
|
|
45
65
|
"license": "MIT",
|
|
46
66
|
"dependencies": {
|
|
47
|
-
"@arkade-os/solver-discovery": "0.2.
|
|
67
|
+
"@arkade-os/solver-discovery": "0.2.3",
|
|
48
68
|
"@noble/curves": "2.0.1",
|
|
49
69
|
"@noble/hashes": "2.0.1",
|
|
50
70
|
"@scure/base": "2.0.0",
|
|
51
71
|
"@scure/btc-signer": "2.0.1",
|
|
52
|
-
"@arkade-os/sdk": "0.4.
|
|
72
|
+
"@arkade-os/sdk": "0.4.64"
|
|
53
73
|
},
|
|
54
74
|
"peerDependencies": {
|
|
55
75
|
"nostr-tools": "^2.12.0"
|
|
@@ -68,7 +88,7 @@
|
|
|
68
88
|
"nostr-tools": "^2.12.0"
|
|
69
89
|
},
|
|
70
90
|
"scripts": {
|
|
71
|
-
"build": "tsup src/index.ts src/nostr.ts --format esm,cjs --dts --clean",
|
|
91
|
+
"build": "tsup src/index.ts src/nostr.ts src/repositories/sqlite/index.ts src/repositories/realm/index.ts --format esm,cjs --dts --clean",
|
|
72
92
|
"typecheck": "tsc --noEmit",
|
|
73
93
|
"format": "prettier --write src test",
|
|
74
94
|
"lint": "prettier --check src test",
|