@swapkit/toolboxes 6.3.0 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @swapkit/toolboxes
2
2
 
3
+ ## 6.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#373](https://github.com/swapkit/sdk/pull/373) [`218e46d`](https://github.com/swapkit/sdk/commit/218e46d12d423e0420143ec410f0a4c8d102ab8d) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Add a standalone Lightning toolbox backed by Lightspark at `@swapkit/toolboxes/lightspark`, re-exported from `@swapkit/server`. It ships with no `Chain` enum member and no core or wallet wiring.
8
+ - [#449](https://github.com/swapkit/sdk/pull/449) [`e105e04`](https://github.com/swapkit/sdk/commit/e105e0417e77c486406706ecf1c0ed12c77c4375) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - The Starknet toolbox uses a wallet-provided account only to sign and send. Network reads and fee estimates go through the configured Starknet RPC, so wallets that bundle an older starknet.js (such as OKX Wallet) no longer fail with `getClassHashAt` of undefined or an "Invalid block id" error.
9
+ - [#373](https://github.com/swapkit/sdk/pull/373) [`218e46d`](https://github.com/swapkit/sdk/commit/218e46d12d423e0420143ec410f0a4c8d102ab8d) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Add the `toolbox_lightspark_*` block (91301 to 91313) to `SwapKitError.ErrorCode` for the new Lightning toolbox: `toolbox_lightspark_missing_credentials`, `toolbox_lightspark_invalid_invoice`, `toolbox_lightspark_invoice_amount_mismatch`, `toolbox_lightspark_invoice_destination_mismatch`, `toolbox_lightspark_invoice_expired`, `toolbox_lightspark_invoice_already_settled`, `toolbox_lightspark_fee_limit_exceeded`, `toolbox_lightspark_invalid_params`, `toolbox_lightspark_api_error`, `toolbox_lightspark_invalid_amount`, `toolbox_lightspark_invalid_destination`, `toolbox_lightspark_network_mismatch` and `toolbox_lightspark_signing_key_unavailable`. An unloadable node signing key is reported as `toolbox_lightspark_signing_key_unavailable`, distinct from `toolbox_lightspark_missing_credentials`, so an integrator branching on the code can tell an unloaded key from an absent credential. (via @swapkit/helpers@6.2.0)
10
+ - [#447](https://github.com/swapkit/sdk/pull/447) [`b827853`](https://github.com/swapkit/sdk/commit/b827853cd1bfa68a9bd733843b3740f10ecab359) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@6.2.0)
11
+
3
12
  ## 6.3.0
4
13
 
5
14
  ### Minor Changes
@@ -0,0 +1 @@
1
+ import{ja as Kt}from"../../chunk-exyqap7m.js";import{SwapKitError as y}from"@swapkit/helpers";import{SwapKitError as D}from"@swapkit/helpers";var T=1000n,x=100000000n*T,Tt=BigInt(Number.MAX_SAFE_INTEGER),bt=10000n,vt=16n,ot=5n*T,Et=/^\d+$/,At=/^0[23][0-9a-fA-F]{64}$/,Mt=/^[0-9a-fA-F]{64}$/,xt=new Map([["BITCOIN",x],["MILLIBITCOIN",x/1000n],["MICROBITCOIN",x/1000000n],["NANOBITCOIN",x/1000000000n],["MILLISATOSHI",1n],["SATOSHI",T]]),Ct=(t,e)=>(t+e-1n)/e;function I(t,e){if(typeof t!=="string"||!Et.test(t))throw new D({errorKey:"toolbox_lightspark_invalid_amount",info:{context:e,value:t}});return BigInt(t)}function S(t,e){if(t<0n||t>Tt)throw new D({errorKey:"toolbox_lightspark_invalid_amount",info:{context:e,msats:t.toString()}});return Number(t)}function L(t){if(!t)return;let{originalUnit:e,originalValue:d}=t,p=xt.get(e);if(p===void 0||!Number.isSafeInteger(d)||d<0)return;return BigInt(d)*p}function b(t){let e=L(t);if(e===void 0)throw new D({errorKey:"toolbox_lightspark_api_error",info:{originalUnit:t?.originalUnit,originalValue:t?.originalValue,reason:t?"unsupported currency amount":"missing currency amount"}});return e}function at(t){let e=Ct(t*vt,bt*T)*T;if(e<ot)return ot;return e}function B(t){return t==="SUCCESS"||t==="FAILED"?t:"PENDING"}function v(t){return B(t)!=="PENDING"}function C(t){return typeof t==="string"&&At.test(t)}function H(t){return typeof t==="string"&&Mt.test(t)}function U(t){return new Promise((e)=>setTimeout(e,t))}function V(t){return typeof t==="object"&&t!==null&&"code"in t&&typeof t.code==="string"?t.code:void 0}function q(t){return t instanceof Error?t.message:void 0}var K=60000,X=600000,Ht=new Set(["MAINNET","REGTEST","SIGNET","TESTNET"]);function rt({decoded:t,expectedDestinationPublicKey:e,expectedNetwork:d,nowMs:p,skewToleranceMs:f}){if(!Number.isFinite(f)||f<0||f>X)throw new y({errorKey:"toolbox_lightspark_invalid_params",info:{expirySkewToleranceMs:f,maxExpirySkewToleranceMs:X,operation:"payInvoice"}});if(!H(t.paymentHash)||t.paymentHash!==t.paymentHash.toLowerCase())throw new y({errorKey:"toolbox_lightspark_invalid_invoice",info:{paymentHash:t.paymentHash,reason:"missing or malformed payment hash"}});if(!Ht.has(t.network)||t.network!==d)throw new y({errorKey:"toolbox_lightspark_network_mismatch",info:{expectedNetwork:d,invoiceNetwork:t.network,paymentHash:t.paymentHash}});if(e!==void 0){if(!C(e))throw new y({errorKey:"toolbox_lightspark_invalid_destination",info:{destinationPublicKey:e,paymentHash:t.paymentHash}});if(t.destinationPublicKey?.toLowerCase()!==e.toLowerCase())throw new y({errorKey:"toolbox_lightspark_invoice_destination_mismatch",info:{expectedDestinationPublicKey:e,invoiceDestinationPublicKey:t.destinationPublicKey,paymentHash:t.paymentHash}})}let _=Date.parse(t.expiresAt);if(Number.isNaN(_))throw new y({errorKey:"toolbox_lightspark_invalid_invoice",info:{expiresAt:t.expiresAt,paymentHash:t.paymentHash,reason:"unparseable expiry"}});if(p>_+f)throw new y({errorKey:"toolbox_lightspark_invoice_expired",info:{expiresAt:t.expiresAt,expirySkewToleranceMs:f,nowMs:p,paymentHash:t.paymentHash}})}function st({amountMsats:t,invoiceAmountMsats:e,paymentHash:d}){let p=t===void 0?void 0:I(t,"payInvoice amountMsats");if(e>0n){if(p!==void 0&&p!==e)throw new y({errorKey:"toolbox_lightspark_invoice_amount_mismatch",info:{invoiceAmountMsats:e.toString(),paymentHash:d,requestedAmountMsats:t}});return{payAmountMsats:e,zeroAmountInvoice:!1}}if(p===void 0)throw new y({errorKey:"toolbox_lightspark_invoice_amount_mismatch",info:{invoiceAmountMsats:"0",paymentHash:d,reason:"zero-amount invoice requires an explicit amountMsats"}});if(p===0n)throw new y({errorKey:"toolbox_lightspark_invalid_amount",info:{context:"payInvoice amountMsats",paymentHash:d,reason:"amountMsats must be positive"}});return{payAmountMsats:p,zeroAmountInvoice:!0}}import{SwapKitError as c}from"@swapkit/helpers";var ct=60,ut=10,W=3000,Rt=K;function R(t){let e=L(t.amount),d=L(t.fees);return{...e===void 0?{}:{amountMsats:e.toString()},...d===void 0?{}:{feePaidMsats:d.toString()},failureReason:t.failureReason??void 0,paymentHash:t.transactionHash??void 0,preimage:t.paymentPreimage??void 0,status:B(t.status),transactionId:t.id}}function Y(t){return t.find((e)=>e.status==="SUCCESS")??t.find((e)=>!v(e.status))}function Ot(t){if(t.status==="CLOSED")return!0;let e=t.amountPaid?.originalValue;if(e===void 0||e===null)return!1;return typeof e==="number"?e>0:!0}function Ft({paymentHash:t,prior:e,requestedAmountMsats:d}){let p=L(e.amount);if(p===d)return;throw new c({errorKey:"toolbox_lightspark_invoice_amount_mismatch",info:{operation:"payInvoice",paymentHash:t,...p===void 0?{}:{priorAmountMsats:p.toString()},priorTransactionId:e.id,reason:p===void 0?"a prior payment for this zero-amount invoice is denominated in a unit this toolbox cannot read, so it cannot be shown to match":"a prior payment for this zero-amount invoice used a different amount",requestedAmountMsats:d.toString()}})}async function dt({context:t,estimate:e,info:d,maximumFeesMsats:p,payAmountMsats:f}){let _=p!==void 0?I(p,t):at(f),P;try{P=L(await e())}catch{}if(P!==void 0&&P>_)throw new c({errorKey:"toolbox_lightspark_fee_limit_exceeded",info:{...d,estimatedFeeMsats:P.toString(),maximumFeesMsats:_.toString()}});return _}function Gt(t){let{nodeId:e}=t;if(!e||!(t.client||t.clientId&&t.clientSecret))throw new c({errorKey:"toolbox_lightspark_missing_credentials",info:{hasClient:!!t.client,hasClientId:!!t.clientId,hasClientSecret:!!t.clientSecret,hasNodeId:!!e}});let d,p,f;async function _(n){try{return await import("@lightsparkdev/lightspark-sdk")}catch(i){throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:n,reason:"@lightsparkdev/lightspark-sdk could not be loaded; install the optional peer dependency or inject a client"}},i)}}async function P(){if(t.client)return t.client;let{clientId:n,clientSecret:i}=t;if(!n||!i)throw new c({errorKey:"toolbox_lightspark_missing_credentials",info:{hasClientId:!!n,hasClientSecret:!!i,hasNodeId:!!e}});let{AccountTokenAuthProvider:o,LightsparkClient:s}=await _("createClient");return new s(new o(n,i),t.apiUrl||void 0)}function k(){return d??=P().catch((n)=>{throw d=void 0,n}),d}function z(n,i){let o=V(n);return new c({errorKey:"toolbox_lightspark_signing_key_unavailable",info:{nodeId:e,operation:i,reason:"the node signing key could not be loaded",...o===void 0?{}:{vendorErrorCode:o}}})}function Q(n){let{signingKey:i}=t;if(!i)return Promise.resolve();return f??=n.loadNodeKey(e,{key:i}).catch((o)=>{throw f=void 0,z(o,"loadNodeKey")}),f}function j(n){if(t.signingKey||t.client)return;throw new c({errorKey:"toolbox_lightspark_missing_credentials",info:{operation:n,reason:"signingKey is required to send payments"}})}async function J(n){let i;if(n.getNodeById)i=await n.getNodeById(e);else if(n.executeRawQuery){let{getLightsparkNodeQuery:o}=await _("getNode");i=await n.executeRawQuery(o(e))}else throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"getNode",reason:"the injected client implements neither getNodeById nor executeRawQuery"}});if(!i)throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"getNode",reason:"node not found"}});return p=i,i}async function Z(n){return p??await J(n)}async function tt({client:n,attempts:i,intervalMs:o,initial:s}){let a=s;if(v(a.status))return a;for(let r=0;r<i;r++){await U(o);try{let u=await n.getTransaction(s.id);if(u){if(a=u,v(u.status))return u}}catch{}}return a}async function pt(n,i){try{let o=await n.outgoingPaymentsForPaymentHash(i),s=Y(o);if(s)return{attemptSeq:0,existing:s};let a=await n.invoiceForPaymentHash(i);if(a&&Ot(a))throw new c({errorKey:"toolbox_lightspark_invoice_already_settled",info:{invoiceStatus:a.status,paymentHash:i}});return{attemptSeq:o.filter((r)=>r.status==="FAILED").length,existing:void 0}}catch(o){if(o instanceof c)throw o;throw new c({errorKey:"toolbox_lightspark_api_error",info:{operation:"payInvoice preflight",paymentHash:i}},o)}}async function mt(n,i){try{return Y(await n.outgoingPaymentsForPaymentHash(i,["SUCCESS","PENDING"]))}catch{return}}async function ht(n,{paymentHash:i,transactionId:o}){if(o){let a=await n.getTransaction(o)??void 0;if(a)return{found:a,hashVerified:!1}}if(!i)return{found:void 0,hashVerified:!1};let s=await n.outgoingPaymentsForPaymentHash(i);return{found:Y(s)??s[s.length-1],hashVerified:!0}}async function lt(n,i,o,s){let a=!1,r,u=!1;for(let h=0;h<o;h++){if(h>0)await U(s);try{let m=await ht(n,i);if(u=!0,m.found){if(r=m.found,a=m.hashVerified,v(m.found.status))break}}catch{u=!1}}return{hashVerified:a,last:r,lookupSucceeded:u}}function O(n,i){let{timeoutSecs:o,attempts:s,intervalMs:a}=i;if(o!==void 0&&!(Number.isInteger(o)&&o>0)||s!==void 0&&!(Number.isInteger(s)&&s>=0)||a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new c({errorKey:"toolbox_lightspark_invalid_params",info:{operation:n,...i}})}function et(n,i){if(n instanceof c)throw n;let o=V(n);if(o==="SigningException")throw z(n,i);return o==="PaymentError"?"FAILED":"UNKNOWN"}async function ft(){let n=await k(),i=await J(n),o=i.balances?.availableToSendBalance??i.localBalance;if(!o)throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"getBalance",reason:"node reports no spendable balance"}});return{spendableMsats:b(o).toString(),...i.remoteBalance?{inboundCapacityMsats:b(i.remoteBalance).toString()}:{}}}async function nt(n){if(!n||typeof n!=="string")throw new c({errorKey:"toolbox_lightspark_invalid_invoice",info:{reason:"empty invoice"}});let i=await k(),o;try{o=await i.decodeInvoice(n)}catch(s){throw new c({errorKey:"toolbox_lightspark_api_error",info:{operation:"decodeInvoice"}},s)}if(!o?.paymentHash)throw new c({errorKey:"toolbox_lightspark_invalid_invoice",info:{operation:"decodeInvoice",reason:"decoded invoice has no payment hash"}});return{amountMsats:b(o.amount).toString(),createdAt:o.createdAt,destinationPublicKey:o.destination?.publicKey??void 0,expiresAt:o.expiresAt,memo:o.memo??void 0,network:o.bitcoinNetwork,paymentHash:o.paymentHash}}async function gt({amountMsats:n,memo:i,expirySecs:o}){let s=I(n,"createInvoice"),r=await(await k()).createInvoiceWithDetails(e,S(s,"createInvoice"),i??"",void 0,o);if(!(r?.data?.encodedPaymentRequest&&r.data.paymentHash))throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"createInvoice",reason:"invoice creation returned no invoice"}});return{amountMsats:b(r.data.amount).toString(),createdAt:r.data.createdAt,encodedInvoice:r.data.encodedPaymentRequest,expiresAt:r.data.expiresAt,paymentHash:r.data.paymentHash}}async function yt({amountMsats:n,memo:i}){let o=I(n,"createTestModeInvoice"),s=S(o,"createTestModeInvoice"),a=await k(),r;try{r=await a.createTestModeInvoice(e,s,i)}catch(u){throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"createTestModeInvoice"}},u)}if(!r)throw new c({errorKey:"toolbox_lightspark_api_error",info:{nodeId:e,operation:"createTestModeInvoice",reason:"test mode invoices require regtest credentials"}});return{encodedInvoice:r}}async function _t({invoice:n,amountMsats:i,maximumFeesMsats:o,destinationPublicKey:s,timeoutSecs:a=ct,attempts:r=ut,intervalMs:u=W,expirySkewToleranceMs:h=K}){j("payInvoice"),O("payInvoice",{attempts:r,intervalMs:u,timeoutSecs:a});let m=await k(),l=await nt(n),F=await Z(m);rt({decoded:l,expectedDestinationPublicKey:s,expectedNetwork:F.bitcoinNetwork,nowMs:Date.now(),skewToleranceMs:h});let{payAmountMsats:g,zeroAmountInvoice:w}=st({amountMsats:i,invoiceAmountMsats:I(l.amountMsats,"payInvoice"),paymentHash:l.paymentHash}),E=w?S(g,"payInvoice"):void 0,{attemptSeq:A,existing:G}=await pt(m,l.paymentHash);if(G){if(w)Ft({paymentHash:l.paymentHash,prior:G,requestedAmountMsats:g});return{...R(G),paymentHash:l.paymentHash,replayedPriorPayment:!0}}let St=await dt({context:"payInvoice maximumFeesMsats",estimate:()=>m.getLightningFeeEstimateForInvoice(e,n,E),info:{paymentHash:l.paymentHash},maximumFeesMsats:o,payAmountMsats:g});await Q(m);let Lt=S(St,"payInvoice maximumFeesMsats"),Pt=`${l.paymentHash}:${A}`,M;try{M=await m.payInvoice(e,n,Lt,a,E,Pt)}catch(it){if(et(it,"payInvoice")==="FAILED")return{failureReason:q(it),paymentHash:l.paymentHash,status:"FAILED"};M=await mt(m,l.paymentHash)}if(!M)return{paymentHash:l.paymentHash,status:"PENDING"};let Nt=await tt({attempts:r,client:m,initial:M,intervalMs:u}),N={...R(Nt),paymentHash:l.paymentHash};if(w&&N.status!=="FAILED"&&N.amountMsats!==g.toString())return{...N,reconciliationRequired:{reason:N.amountMsats===void 0?"AMOUNT_UNVERIFIABLE":"AMOUNT_MISMATCH",requestedAmountMsats:g.toString()},status:"PENDING"};return N}async function kt({destinationPublicKey:n,amountMsats:i,maximumFeesMsats:o,timeoutSecs:s=ct,attempts:a=ut,intervalMs:r=W}){if(j("sendPayment"),O("sendPayment",{attempts:a,intervalMs:r,timeoutSecs:s}),!C(n))throw new c({errorKey:"toolbox_lightspark_invalid_destination",info:{destinationPublicKey:n}});let u=I(i,"sendPayment");if(u===0n)throw new c({errorKey:"toolbox_lightspark_invalid_amount",info:{context:"sendPayment",reason:"amountMsats must be positive"}});let h=S(u,"sendPayment"),m=await k(),l=await dt({context:"sendPayment maximumFeesMsats",estimate:()=>m.getLightningFeeEstimateForNode(e,n,h),info:{destinationPublicKey:n},maximumFeesMsats:o,payAmountMsats:u}),F=S(l,"sendPayment maximumFeesMsats");await Q(m);let g={amountMsats:u.toString(),destinationPublicKey:n,sentAfter:new Date(Date.now()-Rt).toISOString()},w;try{w=await m.sendPayment(e,n,s,h,F)}catch(A){if(et(A,"sendPayment")==="FAILED")return{...g,failureReason:q(A),status:"FAILED"};return{...g,status:"PENDING"}}if(!w)return{...g,status:"PENDING"};let E=await tt({attempts:a,client:m,initial:w,intervalMs:r});return{...g,...R(E)}}async function It({transactionId:n,paymentHash:i,attempts:o=1,intervalMs:s=W}){if(!n&&!i)throw new c({errorKey:"toolbox_lightspark_invalid_params",info:{operation:"getTransactionStatus",reason:"transactionId or paymentHash is required"}});O("getTransactionStatus",{attempts:o,intervalMs:s});let a=i?.toLowerCase();if(a!==void 0&&!H(a))throw new c({errorKey:"toolbox_lightspark_invalid_params",info:{operation:"getTransactionStatus",paymentHash:i,reason:"malformed payment hash"}});let r=await k(),{hashVerified:u,last:h,lookupSucceeded:m}=await lt(r,{paymentHash:a,transactionId:n},o,s);if(!h)return{paymentHash:a,status:m?"NOT_FOUND":"UNKNOWN",transactionId:n};if(a&&!u&&h.transactionHash!==a)throw new c({errorKey:"toolbox_lightspark_invalid_params",info:{operation:"getTransactionStatus",paymentHash:a,reason:h.transactionHash?"paymentHash does not match the transaction":"transaction carries no payment hash to verify against",transactionHash:h.transactionHash??void 0,transactionId:h.id}});return{...R(h),paymentHash:a??h.transactionHash??void 0}}async function wt({numTransactions:n,afterDate:i}={}){let o=await k(),s=await Z(o);return(await o.getRecentTransactions(e,n,s.bitcoinNetwork,i)).map((r)=>{let u=L(r.amount);return{...u===void 0?{}:{amountMsats:u.toString()},createdAt:r.createdAt,destinationId:r.destinationId??void 0,id:r.id,resolvedAt:r.resolvedAt??void 0,status:r.status,transactionHash:r.transactionHash??void 0,typename:r.typename}})}return{createInvoice:gt,createTestModeInvoice:yt,decodeInvoice:nt,getBalance:ft,getTransactionStatus:It,listTransactions:wt,payInvoice:_t,sendPayment:kt}}export{X as LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MAX_MS,K as LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MS,Gt as getLightsparkToolbox};
@@ -1 +1 @@
1
- import{ia as I}from"../../chunk-xdkdc1f0.js";import{ja as u}from"../../chunk-exyqap7m.js";import{AssetValue as T,Chain as D,DerivationPath as W,derivationPathToString as tt,getChainConfig as M,getRPCUrl as U,NetworkDerivationPath as et,SwapKitError as s,updateDerivationPath as at}from"@swapkit/helpers";import{match as j,P}from"ts-pattern";var K="0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",z="0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",H="0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";function R(i){if(!i)return!1;return/^0x[0-9a-fA-F]{1,64}$/.test(i)}async function E({phrase:i,derivationPath:d=W.STRK}){let{HDKey:h}=await import("@scure/bip32"),{mnemonicToSeedSync:_}=await import("@scure/bip39"),{ec:l,hash:w,encode:f,CallData:p}=await import("starknet"),v=_(i),S=h.fromMasterSeed(v).derive(d);if(!S.privateKey)throw new s("toolbox_starknet_no_signer");let m=f.addHexPrefix(Buffer.from(S.privateKey).toString("hex")),k=l.starkCurve.grindKey(m),g=f.addHexPrefix(k),b=l.starkCurve.getStarkKey(g),C=p.compile([b,0]);return{address:w.calculateContractAddressFromHash(b,H,C,0),privateKey:g,publicKey:b}}async function Z({phrase:i,derivationPath:d=W.STRK}){let{Account:h,RpcProvider:_}=await import("starknet"),{privateKey:l,address:w}=await E({derivationPath:d,phrase:i}),f=await U(D.Starknet),p=new _({nodeUrl:f});return new h({address:w,provider:p,signer:l})}function rt(i){let d=D.Starknet,h=i&&"index"in i?i.index||0:0,_=tt(i&&"derivationPath"in i&&i.derivationPath?i.derivationPath:at(et[d],{index:h})),l,w,f;async function p(){if(w)return w;if(l)return w=l.provider,w;let{RpcProvider:e}=await import("starknet"),t=await U(d);return w=new e({nodeUrl:t}),w}async function v(e){let t=await p(),a=e||await k();if(!a)return!1;try{return await t.getClassHashAt(a),!0}catch(r){if(r instanceof Error&&r.message.includes("Contract not found"))return!1;let n=r;if(n?.code===20||n?.code===19)return!1;throw r}}async function F(){let{CallData:e,hash:t}=await import("starknet"),a=await p(),r=await m();if(!r)throw new s("toolbox_starknet_no_signer");if(!f)throw new s({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Cannot deploy account: public key not available. Use phrase-based wallet initialization."}});if(await v())return r.address;let o=e.compile([f,0]);if(t.calculateContractAddressFromHash(f,H,o,0).toLowerCase()!==r.address.toLowerCase())throw new s({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Address mismatch during deployment verification"}});let y={addressSalt:f,classHash:H,constructorCalldata:o},{transaction_hash:x}=await r.deployAccount(y);return await a.waitForTransaction(x),x}async function S(){if(!await v()){if(!f)throw new s({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Starknet account is not deployed and cannot be auto-deployed without public key. Use phrase-based wallet initialization."}});await F()}}async function m(){if(l)return l;return l=await j(i).with({phrase:P.string},async({phrase:e})=>{let{Account:t,RpcProvider:a}=await import("starknet"),{privateKey:r,address:n,publicKey:o}=await E({derivationPath:_,phrase:e});f=o;let c=await U(D.Starknet),y=new a({nodeUrl:c});return new t({address:n,provider:y,signer:r})}).with({address:P.string,privateKey:P.string},async({privateKey:e,address:t})=>{let{Account:a}=await import("starknet"),r=await p();return new a({address:t,provider:r,signer:e})}).with({signer:P.instanceOf(Object)},({signer:e})=>e).otherwise(()=>{return}),l}async function k(){return(await m())?.address??""}async function g(e,t){let a=await p(),{uint256:r,CallData:n}=await import("starknet"),[o="0",c="0"]=await a.callContract({calldata:n.compile({account:e}),contractAddress:t,entrypoint:"balanceOf"});return r.uint256ToBN({high:c,low:o})}async function b(e){let{baseDecimal:t}=M(d),a=[],r=[K,z];for(let n of r)try{let o=await g(e,n);j(n).with(K,()=>{a.push(T.from({chain:d,fromBaseDecimal:t,value:o}))}).with(z,()=>{if(o>0n)a.push(T.from({asset:`${d}.ETH-${n}`,fromBaseDecimal:t,value:o}))}).otherwise(()=>{})}catch{}return a}async function C(e){let t=await m();if(t&&(!e||t.address.toLowerCase()===e.toLowerCase()))return t;if(e){let{Account:a}=await import("starknet"),r=await p();return new a({address:e,provider:r,signer:"0x0"})}throw new s({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Estimating fee needs a valid sender address or signer"}})}async function O(e,t){try{let a=await C(t),{overall_fee:r}=await a.estimateInvokeFee(e);if(r<=0n)throw new s({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Sweep fee estimation returned a non-positive fee",sender:t}});return r}catch(a){throw new s({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Unable to estimate the sweep fee. Verify RPC availability and that the sender account is deployed.",sender:t}},a)}}async function G(e,t){let a=await N(e),r=t.isGasAsset?a.find(({isGasAsset:n})=>n):a.find(({address:n})=>n?.toLowerCase()===t.address?.toLowerCase());if(r)return r.getBaseValue("bigint");if(t.isGasAsset)return g(e,K);if(t.address)return g(e,t.address);return 0n}async function B({recipient:e,assetValue:t,sender:a,sweep:r}){let{CallData:n,uint256:o}=await import("starknet");if(!R(e))throw new s("core_transaction_invalid_recipient_address",{address:e});let c=t.isGasAsset?K:t.address;if(!c)throw new s("toolbox_starknet_invalid_address",{address:c,assetValue:t});let y=t.getBaseValue("bigint");if(r){let A=a??await k();if(!R(A))throw new s("core_transaction_invalid_sender_address",{address:A});if(t.isGasAsset){let Y=[{calldata:n.compile([e,o.bnToUint256(1n)]),contractAddress:c,entrypoint:"transfer"}],V=await O(Y,A);y=await G(A,t)-V}else y=await G(A,t);if(y<=0n)throw new s({errorKey:"toolbox_sweep_amount_too_low",info:{amount:y.toString(),asset:t.toString()}})}let x=o.bnToUint256(y);return[{calldata:n.compile([e,x]),contractAddress:c,entrypoint:"transfer"}]}async function q({recipient:e,assetValue:t,sender:a}){let{baseDecimal:r}=M(D.Starknet);try{let n=await B({assetValue:t,recipient:e}),c=await(await C(a)).estimateInvokeFee(n);if(c?.overall_fee)return T.from({chain:d,fromBaseDecimal:r,value:c.overall_fee})}catch(n){throw new s("toolbox_starknet_fee_estimation_failed",n)}return T.from({chain:d,value:"0.00001"})}async function J({recipient:e,assetValue:t,memo:a,sweep:r}){let n=await m();if(!n)throw new s("toolbox_starknet_no_signer");await S();let o=await B({assetValue:t,memo:a,recipient:e,sender:n.address,sweep:r});return(await n.execute(o)).transaction_hash}async function Q(e){let t=await m();if(!t)throw new s("toolbox_starknet_no_signer");let a=await t.signMessage(e);return Array.isArray(a)?a:[a.r.toString(),a.s.toString()]}async function L(e){let t=await m();if(!t)throw new s("toolbox_starknet_no_signer");return await S(),(await t.execute(e)).transaction_hash}function X(e){return L(e)}async function N(e,t=!0){try{return await I(d)(e,t)}catch{return b(e)}}return{broadcastTransaction:L,createKeysForPath:Z,createTransaction:B,deployAccount:F,estimateTransactionFee:q,getAddress:k,getBalance:N,getProvider:p,isAccountDeployed:v,signAndBroadcastTransaction:X,signMessage:Q,transfer:J,validateAddress:R}}export{E as deriveStarknetKeys,rt as getStarknetToolbox,Z as starknetCreateKeysForPath,R as validateStarknetAddress};
1
+ import{ia as z}from"../../chunk-xdkdc1f0.js";import{ja as f}from"../../chunk-exyqap7m.js";import{AssetValue as x,Chain as H,DerivationPath as I,derivationPathToString as et,getChainConfig as N,getRPCUrl as W,NetworkDerivationPath as at,SwapKitError as i,updateDerivationPath as nt}from"@swapkit/helpers";import{match as M,P}from"ts-pattern";var D="0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",j="0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",U="0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";function K(o){if(!o)return!1;return/^0x[0-9a-fA-F]{1,64}$/.test(o)}async function E({phrase:o,derivationPath:c=I.STRK}){let{HDKey:_}=await import("@scure/bip32"),{mnemonicToSeedSync:v}=await import("@scure/bip39"),{ec:u,hash:p,encode:d,CallData:k}=await import("starknet"),w=v(o),S=_.fromMasterSeed(w).derive(c);if(!S.privateKey)throw new i("toolbox_starknet_no_signer");let C=d.addHexPrefix(Buffer.from(S.privateKey).toString("hex")),y=u.starkCurve.grindKey(C),g=d.addHexPrefix(y),m=u.starkCurve.getStarkKey(g),F=k.compile([m,0]);return{address:p.calculateContractAddressFromHash(m,U,F,0),privateKey:g,publicKey:m}}async function Z({phrase:o,derivationPath:c=I.STRK}){let{Account:_,RpcProvider:v}=await import("starknet"),{privateKey:u,address:p}=await E({derivationPath:c,phrase:o}),d=await W(H.Starknet),k=new v({nodeUrl:d});return new _({address:p,provider:k,signer:u})}function rt(o){let c=H.Starknet,_=o&&"index"in o?o.index||0:0,v=et(o&&"derivationPath"in o&&o.derivationPath?o.derivationPath:nt(at[c],{index:_})),u,p,d,k=Boolean(o&&"walletDeploysAccount"in o&&o.walletDeploysAccount);async function w(){if(p)return p;let{RpcProvider:e}=await import("starknet"),t=await W(c);return p=new e({nodeUrl:t}),p}async function A(e){let t=await w(),a=e||await g();if(!a)return!1;try{return await t.getClassHashAt(a),!0}catch(n){if(n instanceof Error&&n.message.includes("Contract not found"))return!1;let r=n;if(r?.code===20||r?.code===19)return!1;throw n}}async function S(){let{CallData:e,hash:t}=await import("starknet"),a=await w(),n=await y();if(!n)throw new i("toolbox_starknet_no_signer");if(!d)throw new i({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Cannot deploy account: public key not available. Use phrase-based wallet initialization."}});if(await A())return n.address;let s=e.compile([d,0]);if(t.calculateContractAddressFromHash(d,U,s,0).toLowerCase()!==n.address.toLowerCase())throw new i({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Address mismatch during deployment verification"}});let h={addressSalt:d,classHash:U,constructorCalldata:s},{transaction_hash:T}=await n.deployAccount(h);return await a.waitForTransaction(T),T}async function C(){if(k)return;if(!await A()){if(!d)throw new i({errorKey:"toolbox_starknet_account_not_deployed",info:{message:"Starknet account is not deployed and cannot be auto-deployed without public key. Use phrase-based wallet initialization."}});await S()}}async function y(){if(u)return u;return u=await M(o).with({phrase:P.string},async({phrase:e})=>{let{Account:t}=await import("starknet"),{privateKey:a,address:n,publicKey:r}=await E({derivationPath:v,phrase:e});d=r;let s=await w();return new t({address:n,provider:s,signer:a})}).with({address:P.string,privateKey:P.string},async({privateKey:e,address:t})=>{let{Account:a}=await import("starknet"),n=await w();return new a({address:t,provider:n,signer:e})}).with({signer:P.instanceOf(Object)},({signer:e})=>e).otherwise(()=>{return}),u}async function g(){return(await y())?.address??""}async function m(e,t){let a=await w(),{uint256:n,CallData:r}=await import("starknet"),[s="0",l="0"]=await a.callContract({calldata:r.compile({account:e}),contractAddress:t,entrypoint:"balanceOf"});return n.uint256ToBN({high:l,low:s})}async function F(e){let{baseDecimal:t}=N(c),a=[],n=[D,j];for(let r of n)try{let s=await m(e,r);M(r).with(D,()=>{a.push(x.from({chain:c,fromBaseDecimal:t,value:s}))}).with(j,()=>{if(s>0n)a.push(x.from({asset:`${c}.ETH-${r}`,fromBaseDecimal:t,value:s}))}).otherwise(()=>{})}catch{}return a}async function R(e){let t=e||await g();if(t){let{Account:a}=await import("starknet"),n=await w();return new a({address:t,provider:n,signer:"0x0"})}throw new i({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Estimating fee needs a valid sender address or signer"}})}async function q(e,t){try{let a=await R(t),{overall_fee:n}=await a.estimateInvokeFee(e,{skipValidate:!0});if(n<=0n)throw new i({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Sweep fee estimation returned a non-positive fee",sender:t}});return n}catch(a){throw new i({errorKey:"toolbox_starknet_fee_estimation_failed",info:{message:"Unable to estimate the sweep fee. Verify RPC availability and that the sender account is deployed.",sender:t}},a)}}async function O(e,t){let a=await L(e),n=t.isGasAsset?a.find(({isGasAsset:r})=>r):a.find(({address:r})=>r?.toLowerCase()===t.address?.toLowerCase());if(n)return n.getBaseValue("bigint");if(t.isGasAsset)return m(e,D);if(t.address)return m(e,t.address);return 0n}async function B({recipient:e,assetValue:t,sender:a,sweep:n}){let{CallData:r,uint256:s}=await import("starknet");if(!K(e))throw new i("core_transaction_invalid_recipient_address",{address:e});let l=t.isGasAsset?D:t.address;if(!l)throw new i("toolbox_starknet_invalid_address",{address:l,assetValue:t});let h=t.getBaseValue("bigint");if(n){let b=a??await g();if(!K(b))throw new i("core_transaction_invalid_sender_address",{address:b});if(t.isGasAsset){let V=[{calldata:r.compile([e,s.bnToUint256(1n)]),contractAddress:l,entrypoint:"transfer"}],tt=await q(V,b);h=await O(b,t)-tt}else h=await O(b,t);if(h<=0n)throw new i({errorKey:"toolbox_sweep_amount_too_low",info:{amount:h.toString(),asset:t.toString()}})}let T=s.bnToUint256(h);return[{calldata:r.compile([e,T]),contractAddress:l,entrypoint:"transfer"}]}async function J({recipient:e,assetValue:t,sender:a}){let{baseDecimal:n}=N(H.Starknet);try{let r=await B({assetValue:t,recipient:e}),l=await(await R(a)).estimateInvokeFee(r,{skipValidate:!0});if(l?.overall_fee)return x.from({chain:c,fromBaseDecimal:n,value:l.overall_fee})}catch(r){throw new i("toolbox_starknet_fee_estimation_failed",r)}return x.from({chain:c,value:"0.00001"})}async function Q({recipient:e,assetValue:t,memo:a,sweep:n}){let r=await y();if(!r)throw new i("toolbox_starknet_no_signer");await C();let s=await B({assetValue:t,memo:a,recipient:e,sender:r.address,sweep:n});return(await r.execute(s)).transaction_hash}async function X(e){let t=await y();if(!t)throw new i("toolbox_starknet_no_signer");let a=await t.signMessage(e);return Array.isArray(a)?a:[a.r.toString(),a.s.toString()]}async function G(e){let t=await y();if(!t)throw new i("toolbox_starknet_no_signer");return await C(),(await t.execute(e)).transaction_hash}function Y(e){return G(e)}async function L(e,t=!0){try{return await z(c)(e,t)}catch{return F(e)}}return{broadcastTransaction:G,createKeysForPath:Z,createTransaction:B,deployAccount:S,estimateTransactionFee:J,getAddress:g,getBalance:L,getProvider:w,isAccountDeployed:A,signAndBroadcastTransaction:Y,signMessage:X,transfer:Q,validateAddress:K}}export{E as deriveStarknetKeys,rt as getStarknetToolbox,Z as starknetCreateKeysForPath,K as validateStarknetAddress};
@@ -0,0 +1,13 @@
1
+ import type { LightsparkCurrencyAmount, LightsparkPaymentStatus } from "./types";
2
+ export declare function parseMsats(value: string, context: string): bigint;
3
+ export declare function msatsToSdkNumber(msats: bigint, context: string): number;
4
+ export declare function tryCurrencyAmountToMsats(amount: LightsparkCurrencyAmount | null | undefined): bigint | undefined;
5
+ export declare function currencyAmountToMsats(amount: LightsparkCurrencyAmount | null | undefined): bigint;
6
+ export declare function defaultMaximumFeesMsats(amountMsats: bigint): bigint;
7
+ export declare function mapPaymentStatus(status: string): LightsparkPaymentStatus;
8
+ export declare function isTerminalPaymentStatus(status: string): boolean;
9
+ export declare function isCompressedNodePublicKey(value: string): boolean;
10
+ export declare function isPaymentHash(value: string): boolean;
11
+ export declare function sleep(ms: number): Promise<void>;
12
+ export declare function sdkErrorCode(error: unknown): string | undefined;
13
+ export declare function sdkErrorMessage(error: unknown): string | undefined;
@@ -0,0 +1,3 @@
1
+ export { LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MAX_MS, LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MS, } from "./invoiceAssert";
2
+ export { getLightsparkToolbox } from "./toolbox";
3
+ export type * from "./types";
@@ -0,0 +1,18 @@
1
+ import type { LightsparkDecodedInvoice } from "./types";
2
+ export declare const LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MS = 60000;
3
+ export declare const LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MAX_MS = 600000;
4
+ export declare function assertPayableLightningInvoice({ decoded, expectedDestinationPublicKey, expectedNetwork, nowMs, skewToleranceMs, }: {
5
+ decoded: LightsparkDecodedInvoice;
6
+ expectedDestinationPublicKey?: string;
7
+ expectedNetwork: string;
8
+ nowMs: number;
9
+ skewToleranceMs: number;
10
+ }): void;
11
+ export declare function resolveLightningPaymentAmountMsats({ amountMsats, invoiceAmountMsats, paymentHash, }: {
12
+ amountMsats?: string;
13
+ invoiceAmountMsats: bigint;
14
+ paymentHash: string;
15
+ }): {
16
+ payAmountMsats: bigint;
17
+ zeroAmountInvoice: boolean;
18
+ };
@@ -0,0 +1,13 @@
1
+ import type { LightsparkBalance, LightsparkCreateInvoiceParams, LightsparkCreateInvoiceResult, LightsparkCreateTestModeInvoiceParams, LightsparkDecodedInvoice, LightsparkListTransactionsParams, LightsparkPayInvoiceParams, LightsparkPayInvoiceResult, LightsparkSendPaymentParams, LightsparkSendPaymentResult, LightsparkToolboxParams, LightsparkTrackingOutcome, LightsparkTransactionStatusParams, LightsparkTransactionSummary } from "./types";
2
+ export declare function getLightsparkToolbox(params: LightsparkToolboxParams): {
3
+ createInvoice: ({ amountMsats, memo, expirySecs, }: LightsparkCreateInvoiceParams) => Promise<LightsparkCreateInvoiceResult>;
4
+ createTestModeInvoice: ({ amountMsats, memo, }: LightsparkCreateTestModeInvoiceParams) => Promise<{
5
+ encodedInvoice: string;
6
+ }>;
7
+ decodeInvoice: (invoice: string) => Promise<LightsparkDecodedInvoice>;
8
+ getBalance: () => Promise<LightsparkBalance>;
9
+ getTransactionStatus: ({ transactionId, paymentHash: rawPaymentHash, attempts, intervalMs, }: LightsparkTransactionStatusParams) => Promise<LightsparkTrackingOutcome>;
10
+ listTransactions: ({ numTransactions, afterDate, }?: LightsparkListTransactionsParams) => Promise<LightsparkTransactionSummary[]>;
11
+ payInvoice: ({ invoice, amountMsats, maximumFeesMsats, destinationPublicKey, timeoutSecs, attempts, intervalMs, expirySkewToleranceMs, }: LightsparkPayInvoiceParams) => Promise<LightsparkPayInvoiceResult>;
12
+ sendPayment: ({ destinationPublicKey, amountMsats, maximumFeesMsats, timeoutSecs, attempts, intervalMs, }: LightsparkSendPaymentParams) => Promise<LightsparkSendPaymentResult>;
13
+ };
@@ -0,0 +1,196 @@
1
+ export type LightsparkCurrencyAmount = {
2
+ originalValue: number;
3
+ originalUnit: string;
4
+ };
5
+ export type LightsparkSdkInvoiceData = {
6
+ encodedPaymentRequest: string;
7
+ bitcoinNetwork: string;
8
+ paymentHash: string;
9
+ amount: LightsparkCurrencyAmount;
10
+ createdAt: string;
11
+ expiresAt: string;
12
+ destination: {
13
+ publicKey?: string | null;
14
+ };
15
+ memo?: string | null;
16
+ };
17
+ export type LightsparkSdkInvoice = {
18
+ id: string;
19
+ status: string;
20
+ data: LightsparkSdkInvoiceData;
21
+ amountPaid?: LightsparkCurrencyAmount | null;
22
+ };
23
+ export type LightsparkSdkTransaction = {
24
+ id: string;
25
+ createdAt: string;
26
+ status: string;
27
+ amount: LightsparkCurrencyAmount;
28
+ typename: string;
29
+ resolvedAt?: string | null;
30
+ transactionHash?: string | null;
31
+ fees?: LightsparkCurrencyAmount | null;
32
+ paymentPreimage?: string | null;
33
+ failureReason?: string | null;
34
+ destinationId?: string | null;
35
+ };
36
+ export type LightsparkSdkNode = {
37
+ id: string;
38
+ bitcoinNetwork: string;
39
+ balances?: {
40
+ availableToSendBalance: LightsparkCurrencyAmount;
41
+ };
42
+ localBalance?: LightsparkCurrencyAmount;
43
+ remoteBalance?: LightsparkCurrencyAmount;
44
+ };
45
+ type LightsparkGraphClientMethods = {
46
+ decodeInvoice(encodedInvoice: string): Promise<LightsparkSdkInvoiceData>;
47
+ payInvoice(payerNodeId: string, encodedInvoice: string, maximumFeesMsats: number, timeoutSecs?: number, amountMsats?: number, idempotencyKey?: string): Promise<LightsparkSdkTransaction | undefined>;
48
+ sendPayment(payerNodeId: string, destinationPublicKey: string, timeoutSecs: number | undefined, amountMsats: number, maximumFeesMsats: number): Promise<LightsparkSdkTransaction | undefined>;
49
+ createInvoiceWithDetails(nodeId: string, amountMsats: number, memo: string, type?: undefined, expirySecs?: number): Promise<LightsparkSdkInvoice | undefined>;
50
+ createTestModeInvoice(localNodeId: string, amountMsats: number, memo?: string): Promise<string | null>;
51
+ getRecentTransactions(nodeId: string, numTransactions?: number, bitcoinNetwork?: string, afterDate?: string): Promise<LightsparkSdkTransaction[]>;
52
+ getTransaction(transactionId: string): Promise<LightsparkSdkTransaction | null | undefined>;
53
+ outgoingPaymentsForPaymentHash(paymentHash: string, statuses?: string[]): Promise<LightsparkSdkTransaction[]>;
54
+ invoiceForPaymentHash(paymentHash: string): Promise<LightsparkSdkInvoice | null>;
55
+ getLightningFeeEstimateForInvoice(nodeId: string, encodedPaymentRequest: string, amountMsats?: number): Promise<LightsparkCurrencyAmount>;
56
+ getLightningFeeEstimateForNode(nodeId: string, destinationNodePublicKey: string, amountMsats: number): Promise<LightsparkCurrencyAmount>;
57
+ loadNodeKey(nodeId: string, signingPrivateKeyOrAlias: {
58
+ key: string;
59
+ }): Promise<void>;
60
+ };
61
+ /** Implement getNodeById to avoid the optional vendor SDK; executeRawQuery uses its query builder. */
62
+ export type LightsparkGraphClient = LightsparkGraphClientMethods & ({
63
+ getNodeById(nodeId: string): Promise<LightsparkSdkNode | null>;
64
+ executeRawQuery?(query: unknown): Promise<unknown>;
65
+ } | {
66
+ getNodeById?(nodeId: string): Promise<LightsparkSdkNode | null>;
67
+ executeRawQuery(query: unknown): Promise<unknown>;
68
+ });
69
+ export type LightsparkToolboxParams = {
70
+ nodeId: string;
71
+ signingKey?: string;
72
+ apiUrl?: string;
73
+ } & ({
74
+ clientId: string;
75
+ clientSecret: string;
76
+ client?: LightsparkGraphClient;
77
+ } | {
78
+ clientId?: string;
79
+ clientSecret?: string;
80
+ client: LightsparkGraphClient;
81
+ });
82
+ export type LightsparkPaymentStatus = "PENDING" | "SUCCESS" | "FAILED";
83
+ export type LightsparkTrackingStatus = LightsparkPaymentStatus | "NOT_FOUND" | "UNKNOWN";
84
+ export type LightsparkPaymentOutcome = {
85
+ status: LightsparkPaymentStatus;
86
+ paymentHash?: string;
87
+ transactionId?: string;
88
+ amountMsats?: string;
89
+ feePaidMsats?: string;
90
+ preimage?: string;
91
+ failureReason?: string;
92
+ };
93
+ export type LightsparkPayInvoiceResult = LightsparkPaymentOutcome & {
94
+ paymentHash: string;
95
+ /**
96
+ * PENDING because an amountless payment cannot be matched to this request. Reconcile its actual
97
+ * amount against requestedAmountMsats before resending, even if tracking later reports SUCCESS.
98
+ */
99
+ reconciliationRequired?: {
100
+ reason: "AMOUNT_MISMATCH" | "AMOUNT_UNVERIFIABLE";
101
+ requestedAmountMsats: string;
102
+ };
103
+ /** The result belongs to an earlier payment; this call sent nothing. */
104
+ replayedPriorPayment?: true;
105
+ };
106
+ export type LightsparkSendPaymentResult = LightsparkPaymentOutcome & {
107
+ amountMsats: string;
108
+ destinationPublicKey: string;
109
+ /**
110
+ * ISO-8601 send time minus LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MS. Pass as afterDate to
111
+ * listTransactions and match createdAt, amountMsats and typename before retrying an unknown send.
112
+ * destinationId is an entity id, so it cannot be compared with destinationPublicKey.
113
+ */
114
+ sentAfter: string;
115
+ };
116
+ export type LightsparkTrackingOutcome = Omit<LightsparkPaymentOutcome, "status"> & {
117
+ status: LightsparkTrackingStatus;
118
+ };
119
+ export type LightsparkPayInvoiceParams = {
120
+ invoice: string;
121
+ amountMsats?: string;
122
+ maximumFeesMsats?: string;
123
+ destinationPublicKey?: string;
124
+ timeoutSecs?: number;
125
+ attempts?: number;
126
+ intervalMs?: number;
127
+ /**
128
+ * Expiry allowance in milliseconds, from 0 to LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MAX_MS.
129
+ * Defaults to LIGHTNING_INVOICE_EXPIRY_SKEW_TOLERANCE_MS.
130
+ */
131
+ expirySkewToleranceMs?: number;
132
+ };
133
+ export type LightsparkSendPaymentParams = {
134
+ destinationPublicKey: string;
135
+ amountMsats: string;
136
+ maximumFeesMsats?: string;
137
+ timeoutSecs?: number;
138
+ attempts?: number;
139
+ intervalMs?: number;
140
+ };
141
+ export type LightsparkCreateInvoiceParams = {
142
+ amountMsats: string;
143
+ memo?: string;
144
+ expirySecs?: number;
145
+ };
146
+ export type LightsparkCreateInvoiceResult = {
147
+ encodedInvoice: string;
148
+ paymentHash: string;
149
+ amountMsats: string;
150
+ createdAt: string;
151
+ expiresAt: string;
152
+ };
153
+ export type LightsparkCreateTestModeInvoiceParams = {
154
+ amountMsats: string;
155
+ memo?: string;
156
+ };
157
+ export type LightsparkDecodedInvoice = {
158
+ paymentHash: string;
159
+ amountMsats: string;
160
+ network: string;
161
+ createdAt: string;
162
+ expiresAt: string;
163
+ destinationPublicKey?: string;
164
+ memo?: string;
165
+ };
166
+ export type LightsparkBalance = {
167
+ spendableMsats: string;
168
+ inboundCapacityMsats?: string;
169
+ };
170
+ export type LightsparkTransactionStatusParams = {
171
+ transactionId?: string;
172
+ paymentHash?: string;
173
+ attempts?: number;
174
+ intervalMs?: number;
175
+ };
176
+ export type LightsparkListTransactionsParams = {
177
+ numTransactions?: number;
178
+ /** ISO-8601 timestamp; pass `sentAfter` from a `sendPayment` result to bound a reconciliation scan. */
179
+ afterDate?: string;
180
+ };
181
+ /** A listTransactions row. Vendor enum values remain strings to support future SDK versions. */
182
+ export type LightsparkTransactionSummary = {
183
+ id: string;
184
+ /** GraphQL type, e.g. "OutgoingPayment", "IncomingPayment" or "RoutingTransaction". */
185
+ typename: string;
186
+ /** Raw vendor status, including FUTURE_VALUE for an unrecognised status. */
187
+ status: string;
188
+ createdAt: string;
189
+ amountMsats?: string;
190
+ resolvedAt?: string;
191
+ /** BOLT11 payment hash for an OutgoingPayment, matching payInvoice results. */
192
+ transactionHash?: string;
193
+ /** Counterparty entity id (e.g. "GraphNode:0188..."); not a Lightning public key. */
194
+ destinationId?: string;
195
+ };
196
+ export {};
@@ -2,6 +2,7 @@ import type { DerivationPathArray, GenericTransferParams } from "@swapkit/helper
2
2
  import type { Account } from "starknet";
3
3
  export type StarknetToolboxParams = {
4
4
  signer?: Account;
5
+ walletDeploysAccount?: boolean;
5
6
  } | {
6
7
  phrase?: string;
7
8
  index?: number;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
- "dependencies": { "@swapkit/helpers": "6.1.2", "@swapkit/utxo-signer": "3.1.1" },
2
+ "dependencies": { "@swapkit/helpers": "6.2.0", "@swapkit/utxo-signer": "3.1.1" },
3
3
  "description": "SwapKit - Toolboxes",
4
4
  "devDependencies": {
5
5
  "@aptos-labs/ts-sdk": "7.0.1",
6
+ "@lightsparkdev/lightspark-sdk": "1.9.19",
6
7
  "@mysten/sui": "2.17.0",
7
8
  "@near-js/accounts": "2.5.1",
8
9
  "@near-js/crypto": "2.5.1",
@@ -60,6 +61,7 @@
60
61
  "./cosmos": { "default": "./dist/src/cosmos/index.js", "types": "./dist/types/cosmos/index.d.ts" },
61
62
  "./evm": { "default": "./dist/src/evm/index.js", "types": "./dist/types/evm/index.d.ts" },
62
63
  "./hypercore": { "default": "./dist/src/hypercore/index.js", "types": "./dist/types/hypercore/index.d.ts" },
64
+ "./lightspark": { "default": "./dist/src/lightspark/index.js", "types": "./dist/types/lightspark/index.d.ts" },
63
65
  "./near": { "default": "./dist/src/near/index.js", "types": "./dist/types/near/index.d.ts" },
64
66
  "./radix": { "default": "./dist/src/radix/index.js", "types": "./dist/types/radix/index.d.ts" },
65
67
  "./ripple": { "default": "./dist/src/ripple/index.js", "types": "./dist/types/ripple/index.d.ts" },
@@ -78,6 +80,7 @@
78
80
  "name": "@swapkit/toolboxes",
79
81
  "peerDependencies": {
80
82
  "@aptos-labs/ts-sdk": "7.0.1",
83
+ "@lightsparkdev/lightspark-sdk": "1.9.19",
81
84
  "@mysten/sui": "2.17.0",
82
85
  "@near-js/accounts": "2.5.1",
83
86
  "@near-js/crypto": "2.5.1",
@@ -121,6 +124,7 @@
121
124
  "ts-pattern": "5.9.0",
122
125
  "xrpl": "4.6.0"
123
126
  },
127
+ "peerDependenciesMeta": { "@lightsparkdev/lightspark-sdk": { "optional": true } },
124
128
  "publishConfig": { "access": "public" },
125
129
  "repository": { "type": "git", "url": "git+https://github.com/swapkit/SwapKit.git" },
126
130
  "scripts": {
@@ -131,5 +135,5 @@
131
135
  "type-check:go": "tsgo"
132
136
  },
133
137
  "type": "module",
134
- "version": "6.3.0"
138
+ "version": "6.4.0"
135
139
  }