@lendasat/lendaswap-sdk-pure 0.2.21-1 → 0.2.21
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/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +4 -1
- package/dist/api/client.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +4 -1
- package/dist/price-feed.d.ts +0 -124
- package/dist/price-feed.d.ts.map +0 -1
- package/dist/price-feed.js +0 -178
- package/dist/price-feed.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -31
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -12
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/arkade.d.ts +0 -36
- package/dist/src/arkade.d.ts.map +0 -1
- package/dist/src/arkade.js +0 -68
- package/dist/src/arkade.js.map +0 -1
- package/dist/src/client.d.ts +0 -760
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/client.js +0 -2169
- package/dist/src/client.js.map +0 -1
- package/dist/src/create/arkade.d.ts +0 -34
- package/dist/src/create/arkade.d.ts.map +0 -1
- package/dist/src/create/arkade.js +0 -76
- package/dist/src/create/arkade.js.map +0 -1
- package/dist/src/create/bitcoin-to-arkade.d.ts +0 -36
- package/dist/src/create/bitcoin-to-arkade.d.ts.map +0 -1
- package/dist/src/create/bitcoin-to-arkade.js +0 -69
- package/dist/src/create/bitcoin-to-arkade.js.map +0 -1
- package/dist/src/create/bitcoin.d.ts +0 -31
- package/dist/src/create/bitcoin.d.ts.map +0 -1
- package/dist/src/create/bitcoin.js +0 -67
- package/dist/src/create/bitcoin.js.map +0 -1
- package/dist/src/create/evm-to-arkade.d.ts +0 -34
- package/dist/src/create/evm-to-arkade.d.ts.map +0 -1
- package/dist/src/create/evm-to-arkade.js +0 -69
- package/dist/src/create/evm-to-arkade.js.map +0 -1
- package/dist/src/create/evm-to-bitcoin.d.ts +0 -35
- package/dist/src/create/evm-to-bitcoin.d.ts.map +0 -1
- package/dist/src/create/evm-to-bitcoin.js +0 -71
- package/dist/src/create/evm-to-bitcoin.js.map +0 -1
- package/dist/src/create/evm-to-lightning.d.ts +0 -34
- package/dist/src/create/evm-to-lightning.d.ts.map +0 -1
- package/dist/src/create/evm-to-lightning.js +0 -66
- package/dist/src/create/evm-to-lightning.js.map +0 -1
- package/dist/src/create/index.d.ts +0 -19
- package/dist/src/create/index.d.ts.map +0 -1
- package/dist/src/create/index.js +0 -18
- package/dist/src/create/index.js.map +0 -1
- package/dist/src/create/lightning.d.ts +0 -31
- package/dist/src/create/lightning.d.ts.map +0 -1
- package/dist/src/create/lightning.js +0 -72
- package/dist/src/create/lightning.js.map +0 -1
- package/dist/src/create/types.d.ts +0 -247
- package/dist/src/create/types.d.ts.map +0 -1
- package/dist/src/create/types.js +0 -5
- package/dist/src/create/types.js.map +0 -1
- package/dist/src/delegate.d.ts +0 -62
- package/dist/src/delegate.d.ts.map +0 -1
- package/dist/src/delegate.js +0 -284
- package/dist/src/delegate.js.map +0 -1
- package/dist/src/esplora.d.ts +0 -41
- package/dist/src/esplora.d.ts.map +0 -1
- package/dist/src/esplora.js +0 -47
- package/dist/src/esplora.js.map +0 -1
- package/dist/src/evm/coordinator.d.ts +0 -247
- package/dist/src/evm/coordinator.d.ts.map +0 -1
- package/dist/src/evm/coordinator.js +0 -414
- package/dist/src/evm/coordinator.js.map +0 -1
- package/dist/src/evm/htlc.d.ts +0 -238
- package/dist/src/evm/htlc.d.ts.map +0 -1
- package/dist/src/evm/htlc.js +0 -278
- package/dist/src/evm/htlc.js.map +0 -1
- package/dist/src/evm/index.d.ts +0 -9
- package/dist/src/evm/index.d.ts.map +0 -1
- package/dist/src/evm/index.js +0 -9
- package/dist/src/evm/index.js.map +0 -1
- package/dist/src/evm/signing.d.ts +0 -30
- package/dist/src/evm/signing.d.ts.map +0 -1
- package/dist/src/evm/signing.js +0 -91
- package/dist/src/evm/signing.js.map +0 -1
- package/dist/src/generated/api.d.ts +0 -2736
- package/dist/src/generated/api.d.ts.map +0 -1
- package/dist/src/generated/api.js +0 -6
- package/dist/src/generated/api.js.map +0 -1
- package/dist/src/index.d.ts +0 -18
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/node.d.ts +0 -19
- package/dist/src/node.d.ts.map +0 -1
- package/dist/src/node.js +0 -19
- package/dist/src/node.js.map +0 -1
- package/dist/src/price-calculations.d.ts +0 -109
- package/dist/src/price-calculations.d.ts.map +0 -1
- package/dist/src/price-calculations.js +0 -135
- package/dist/src/price-calculations.js.map +0 -1
- package/dist/src/redeem/arkade.d.ts +0 -65
- package/dist/src/redeem/arkade.d.ts.map +0 -1
- package/dist/src/redeem/arkade.js +0 -217
- package/dist/src/redeem/arkade.js.map +0 -1
- package/dist/src/redeem/ethereum.d.ts +0 -52
- package/dist/src/redeem/ethereum.d.ts.map +0 -1
- package/dist/src/redeem/ethereum.js +0 -206
- package/dist/src/redeem/ethereum.js.map +0 -1
- package/dist/src/redeem/gasless.d.ts +0 -41
- package/dist/src/redeem/gasless.d.ts.map +0 -1
- package/dist/src/redeem/gasless.js +0 -71
- package/dist/src/redeem/gasless.js.map +0 -1
- package/dist/src/redeem/index.d.ts +0 -49
- package/dist/src/redeem/index.d.ts.map +0 -1
- package/dist/src/redeem/index.js +0 -189
- package/dist/src/redeem/index.js.map +0 -1
- package/dist/src/redeem/types.d.ts +0 -126
- package/dist/src/redeem/types.d.ts.map +0 -1
- package/dist/src/redeem/types.js +0 -36
- package/dist/src/redeem/types.js.map +0 -1
- package/dist/src/refund/arkade.d.ts +0 -62
- package/dist/src/refund/arkade.d.ts.map +0 -1
- package/dist/src/refund/arkade.js +0 -212
- package/dist/src/refund/arkade.js.map +0 -1
- package/dist/src/refund/index.d.ts +0 -10
- package/dist/src/refund/index.d.ts.map +0 -1
- package/dist/src/refund/index.js +0 -10
- package/dist/src/refund/index.js.map +0 -1
- package/dist/src/refund/onchain.d.ts +0 -137
- package/dist/src/refund/onchain.d.ts.map +0 -1
- package/dist/src/refund/onchain.js +0 -366
- package/dist/src/refund/onchain.js.map +0 -1
- package/dist/src/signer/index.d.ts +0 -106
- package/dist/src/signer/index.d.ts.map +0 -1
- package/dist/src/signer/index.js +0 -179
- package/dist/src/signer/index.js.map +0 -1
- package/dist/src/storage/idb.d.ts +0 -70
- package/dist/src/storage/idb.d.ts.map +0 -1
- package/dist/src/storage/idb.js +0 -236
- package/dist/src/storage/idb.js.map +0 -1
- package/dist/src/storage/index.d.ts +0 -152
- package/dist/src/storage/index.d.ts.map +0 -1
- package/dist/src/storage/index.js +0 -98
- package/dist/src/storage/index.js.map +0 -1
- package/dist/src/storage/sqlite.d.ts +0 -95
- package/dist/src/storage/sqlite.d.ts.map +0 -1
- package/dist/src/storage/sqlite.js +0 -206
- package/dist/src/storage/sqlite.js.map +0 -1
- package/dist/src/storage/types.d.ts +0 -57
- package/dist/src/storage/types.d.ts.map +0 -1
- package/dist/src/storage/types.js +0 -9
- package/dist/src/storage/types.js.map +0 -1
- package/dist/src/tokens.d.ts +0 -29
- package/dist/src/tokens.d.ts.map +0 -1
- package/dist/src/tokens.js +0 -89
- package/dist/src/tokens.js.map +0 -1
- package/dist/src/usd-price.d.ts +0 -34
- package/dist/src/usd-price.d.ts.map +0 -1
- package/dist/src/usd-price.js +0 -83
- package/dist/src/usd-price.js.map +0 -1
- package/dist/tests/api-client.test.d.ts +0 -2
- package/dist/tests/api-client.test.d.ts.map +0 -1
- package/dist/tests/api-client.test.js +0 -86
- package/dist/tests/api-client.test.js.map +0 -1
- package/dist/tests/client.test.d.ts +0 -2
- package/dist/tests/client.test.d.ts.map +0 -1
- package/dist/tests/client.test.js +0 -150
- package/dist/tests/client.test.js.map +0 -1
- package/dist/tests/index.test.d.ts +0 -2
- package/dist/tests/index.test.d.ts.map +0 -1
- package/dist/tests/index.test.js +0 -8
- package/dist/tests/index.test.js.map +0 -1
- package/dist/tests/onchain-refund.test.d.ts +0 -2
- package/dist/tests/onchain-refund.test.d.ts.map +0 -1
- package/dist/tests/onchain-refund.test.js +0 -279
- package/dist/tests/onchain-refund.test.js.map +0 -1
- package/dist/tests/signer.test.d.ts +0 -2
- package/dist/tests/signer.test.d.ts.map +0 -1
- package/dist/tests/signer.test.js +0 -92
- package/dist/tests/signer.test.js.map +0 -1
- package/dist/tests/sqlite-storage.test.d.ts +0 -2
- package/dist/tests/sqlite-storage.test.d.ts.map +0 -1
- package/dist/tests/sqlite-storage.test.js +0 -160
- package/dist/tests/sqlite-storage.test.js.map +0 -1
- package/dist/tests/storage.test.d.ts +0 -2
- package/dist/tests/storage.test.d.ts.map +0 -1
- package/dist/tests/storage.test.js +0 -184
- package/dist/tests/storage.test.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/usdt0-bridge/bridge.d.ts +0 -82
- package/dist/usdt0-bridge/bridge.d.ts.map +0 -1
- package/dist/usdt0-bridge/bridge.js +0 -56
- package/dist/usdt0-bridge/bridge.js.map +0 -1
- package/dist/usdt0-bridge/chains.d.ts +0 -41
- package/dist/usdt0-bridge/chains.d.ts.map +0 -1
- package/dist/usdt0-bridge/chains.js +0 -117
- package/dist/usdt0-bridge/chains.js.map +0 -1
- package/dist/usdt0-bridge/layerzero-tracker.d.ts +0 -34
- package/dist/usdt0-bridge/layerzero-tracker.d.ts.map +0 -1
- package/dist/usdt0-bridge/layerzero-tracker.js +0 -86
- package/dist/usdt0-bridge/layerzero-tracker.js.map +0 -1
- package/dist/usdt0-bridge/oft-abi.d.ts +0 -145
- package/dist/usdt0-bridge/oft-abi.d.ts.map +0 -1
- package/dist/usdt0-bridge/oft-abi.js +0 -117
- package/dist/usdt0-bridge/oft-abi.js.map +0 -1
package/dist/src/delegate.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegate settlement for VHTLC VTXOs.
|
|
3
|
-
*
|
|
4
|
-
* Allows the client to prepare and sign delegate PSBTs (intent + forfeits),
|
|
5
|
-
* then POST them to the lendaswap backend which runs the Ark batch ceremony.
|
|
6
|
-
*
|
|
7
|
-
* This works for spendable, recoverable, AND expired VTXOs — unlike the
|
|
8
|
-
* offchain submitTx/finalizeTx path which only handles spendable VTXOs.
|
|
9
|
-
*/
|
|
10
|
-
export interface DelegateClaimParams {
|
|
11
|
-
userSecretKey: string;
|
|
12
|
-
userPubKey: string;
|
|
13
|
-
lendaswapPubKey: string;
|
|
14
|
-
arkadeServerPubKey: string;
|
|
15
|
-
preimage: string;
|
|
16
|
-
preimageHash: string;
|
|
17
|
-
vhtlcAddress: string;
|
|
18
|
-
refundLocktime: number;
|
|
19
|
-
unilateralClaimDelay: number;
|
|
20
|
-
unilateralRefundDelay: number;
|
|
21
|
-
unilateralRefundWithoutReceiverDelay: number;
|
|
22
|
-
/** Destination Arkade address */
|
|
23
|
-
destinationAddress: string;
|
|
24
|
-
network: string;
|
|
25
|
-
/** Lendaswap API base URL (e.g. http://localhost:3333) */
|
|
26
|
-
lendaswapApiUrl: string;
|
|
27
|
-
arkadeServerUrl?: string;
|
|
28
|
-
/** Optional swap ID — enables the backend to mark swap as ClientRedeemed. */
|
|
29
|
-
swapId?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface DelegateRefundParams {
|
|
32
|
-
userSecretKey: string;
|
|
33
|
-
userPubKey: string;
|
|
34
|
-
lendaswapPubKey: string;
|
|
35
|
-
arkadeServerPubKey: string;
|
|
36
|
-
hashLock: string;
|
|
37
|
-
vhtlcAddress: string;
|
|
38
|
-
refundLocktime: number;
|
|
39
|
-
unilateralClaimDelay: number;
|
|
40
|
-
unilateralRefundDelay: number;
|
|
41
|
-
unilateralRefundWithoutReceiverDelay: number;
|
|
42
|
-
destinationAddress: string;
|
|
43
|
-
network: string;
|
|
44
|
-
lendaswapApiUrl: string;
|
|
45
|
-
arkadeServerUrl?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface DelegateSettleResult {
|
|
48
|
-
commitmentTxid: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Fetch the backend's static delegate cosigner public key.
|
|
52
|
-
*/
|
|
53
|
-
export declare function fetchCosignerPk(lendaswapApiUrl: string): Promise<string>;
|
|
54
|
-
/**
|
|
55
|
-
* Settle a VHTLC via delegate claim (reveal preimage).
|
|
56
|
-
*/
|
|
57
|
-
export declare function delegateClaim(params: DelegateClaimParams): Promise<DelegateSettleResult>;
|
|
58
|
-
/**
|
|
59
|
-
* Settle a VHTLC via delegate refund (after locktime expiry).
|
|
60
|
-
*/
|
|
61
|
-
export declare function delegateRefund(params: DelegateRefundParams): Promise<DelegateSettleResult>;
|
|
62
|
-
//# sourceMappingURL=delegate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../src/delegate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4EH,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oCAAoC,EAAE,MAAM,CAAC;IAC7C,iCAAiC;IACjC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oCAAoC,EAAE,MAAM,CAAC;IAC7C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,oBAAoB,CAAC,CAoD/B;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CA4C/B"}
|
package/dist/src/delegate.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegate settlement for VHTLC VTXOs.
|
|
3
|
-
*
|
|
4
|
-
* Allows the client to prepare and sign delegate PSBTs (intent + forfeits),
|
|
5
|
-
* then POST them to the lendaswap backend which runs the Ark batch ceremony.
|
|
6
|
-
*
|
|
7
|
-
* This works for spendable, recoverable, AND expired VTXOs — unlike the
|
|
8
|
-
* offchain submitTx/finalizeTx path which only handles spendable VTXOs.
|
|
9
|
-
*/
|
|
10
|
-
import { ArkAddress, ConditionWitness, Intent, networks, RestArkProvider, RestIndexerProvider, SingleKey, setArkPsbtField, Transaction, VHTLC, VtxoTaprootTree, } from "@arkade-os/sdk";
|
|
11
|
-
import { Address, OutScript, SigHash } from "@scure/btc-signer";
|
|
12
|
-
// P2A is the zero-value anchor output (OP_1 0x4e73)
|
|
13
|
-
const P2A_SCRIPT = new Uint8Array([0x51, 0x02, 0x4e, 0x73]);
|
|
14
|
-
const P2A = { script: P2A_SCRIPT, amount: 0n };
|
|
15
|
-
import { ripemd160 } from "@noble/hashes/legacy";
|
|
16
|
-
import { sha256 } from "@noble/hashes/sha2";
|
|
17
|
-
import { base64, hex } from "@scure/base";
|
|
18
|
-
/** Default Arkade server URL by network */
|
|
19
|
-
const DEFAULT_ARKADE_URLS = {
|
|
20
|
-
bitcoin: "https://arkade.computer",
|
|
21
|
-
mainnet: "https://arkade.computer",
|
|
22
|
-
signet: "https://mutinynet.arkade.sh",
|
|
23
|
-
mutinynet: "https://mutinynet.arkade.sh",
|
|
24
|
-
};
|
|
25
|
-
function getNetworkName(network) {
|
|
26
|
-
switch (network.toLowerCase()) {
|
|
27
|
-
case "mainnet":
|
|
28
|
-
case "bitcoin":
|
|
29
|
-
return "bitcoin";
|
|
30
|
-
case "testnet":
|
|
31
|
-
return "testnet";
|
|
32
|
-
case "signet":
|
|
33
|
-
return "signet";
|
|
34
|
-
case "mutinynet":
|
|
35
|
-
return "mutinynet";
|
|
36
|
-
case "regtest":
|
|
37
|
-
return "regtest";
|
|
38
|
-
default:
|
|
39
|
-
throw new Error(`Unknown network: ${network}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function getNetworkHrp(networkName) {
|
|
43
|
-
return networks[networkName].hrp;
|
|
44
|
-
}
|
|
45
|
-
function secondsToTimelock(seconds) {
|
|
46
|
-
return { type: "seconds", value: BigInt(seconds) };
|
|
47
|
-
}
|
|
48
|
-
function parseXOnlyPubKey(pubKeyHex) {
|
|
49
|
-
const bytes = hex.decode(pubKeyHex);
|
|
50
|
-
if (bytes.length === 33)
|
|
51
|
-
return bytes.slice(1);
|
|
52
|
-
if (bytes.length === 32)
|
|
53
|
-
return bytes;
|
|
54
|
-
throw new Error(`Invalid public key length: ${bytes.length}`);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Fetch the backend's static delegate cosigner public key.
|
|
58
|
-
*/
|
|
59
|
-
export async function fetchCosignerPk(lendaswapApiUrl) {
|
|
60
|
-
const url = `${lendaswapApiUrl.replace(/\/$/, "")}/api/delegate/cosigner-pk`;
|
|
61
|
-
const res = await fetch(url);
|
|
62
|
-
if (!res.ok) {
|
|
63
|
-
throw new Error(`Failed to fetch cosigner pk: ${res.status} ${await res.text()}`);
|
|
64
|
-
}
|
|
65
|
-
const body = (await res.json());
|
|
66
|
-
return body.cosigner_pk;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Settle a VHTLC via delegate claim (reveal preimage).
|
|
70
|
-
*/
|
|
71
|
-
export async function delegateClaim(params) {
|
|
72
|
-
const userPkBytes = parseXOnlyPubKey(params.userPubKey);
|
|
73
|
-
const lendaswapPkBytes = parseXOnlyPubKey(params.lendaswapPubKey);
|
|
74
|
-
const serverPkBytes = parseXOnlyPubKey(params.arkadeServerPubKey);
|
|
75
|
-
const preimageBytes = hex.decode(params.preimage);
|
|
76
|
-
const preimageHashBytes = ripemd160(sha256(preimageBytes));
|
|
77
|
-
if (hex.encode(preimageHashBytes) !==
|
|
78
|
-
hex.encode(ripemd160(hex.decode(params.preimageHash)))) {
|
|
79
|
-
throw new Error("Preimage hash mismatch");
|
|
80
|
-
}
|
|
81
|
-
// Build VHTLC — for claim: lendaswap=sender, user=receiver
|
|
82
|
-
const networkName = getNetworkName(params.network);
|
|
83
|
-
const vhtlc = new VHTLC.Script({
|
|
84
|
-
sender: lendaswapPkBytes,
|
|
85
|
-
receiver: userPkBytes,
|
|
86
|
-
server: serverPkBytes,
|
|
87
|
-
preimageHash: preimageHashBytes,
|
|
88
|
-
refundLocktime: BigInt(params.refundLocktime),
|
|
89
|
-
unilateralClaimDelay: secondsToTimelock(params.unilateralClaimDelay),
|
|
90
|
-
unilateralRefundDelay: secondsToTimelock(params.unilateralRefundDelay),
|
|
91
|
-
unilateralRefundWithoutReceiverDelay: secondsToTimelock(params.unilateralRefundWithoutReceiverDelay),
|
|
92
|
-
});
|
|
93
|
-
const hrp = getNetworkHrp(networkName);
|
|
94
|
-
const computedAddr = vhtlc.address(hrp, serverPkBytes).encode();
|
|
95
|
-
if (computedAddr !== params.vhtlcAddress) {
|
|
96
|
-
throw new Error(`VHTLC address mismatch: computed ${computedAddr}, expected ${params.vhtlcAddress}`);
|
|
97
|
-
}
|
|
98
|
-
return settleDelegate({
|
|
99
|
-
userSecretKey: params.userSecretKey,
|
|
100
|
-
tapLeafScript: vhtlc.claim(),
|
|
101
|
-
tapTree: vhtlc.encode(),
|
|
102
|
-
vhtlcPkScript: hex.encode(vhtlc.pkScript),
|
|
103
|
-
witnessData: preimageBytes,
|
|
104
|
-
destinationAddress: params.destinationAddress,
|
|
105
|
-
networkName,
|
|
106
|
-
lendaswapApiUrl: params.lendaswapApiUrl,
|
|
107
|
-
arkadeServerUrl: params.arkadeServerUrl,
|
|
108
|
-
locktime: undefined,
|
|
109
|
-
swapId: params.swapId,
|
|
110
|
-
preimage: params.preimage,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Settle a VHTLC via delegate refund (after locktime expiry).
|
|
115
|
-
*/
|
|
116
|
-
export async function delegateRefund(params) {
|
|
117
|
-
const userPkBytes = parseXOnlyPubKey(params.userPubKey);
|
|
118
|
-
const lendaswapPkBytes = parseXOnlyPubKey(params.lendaswapPubKey);
|
|
119
|
-
const serverPkBytes = parseXOnlyPubKey(params.arkadeServerPubKey);
|
|
120
|
-
const hashLockBytes = hex.decode(params.hashLock);
|
|
121
|
-
const preimageHashBytes = hashLockBytes.length === 32 ? ripemd160(hashLockBytes) : hashLockBytes;
|
|
122
|
-
// Build VHTLC — for refund: user=sender, lendaswap=receiver
|
|
123
|
-
const networkName = getNetworkName(params.network);
|
|
124
|
-
const vhtlc = new VHTLC.Script({
|
|
125
|
-
sender: userPkBytes,
|
|
126
|
-
receiver: lendaswapPkBytes,
|
|
127
|
-
server: serverPkBytes,
|
|
128
|
-
preimageHash: preimageHashBytes,
|
|
129
|
-
refundLocktime: BigInt(params.refundLocktime),
|
|
130
|
-
unilateralClaimDelay: secondsToTimelock(params.unilateralClaimDelay),
|
|
131
|
-
unilateralRefundDelay: secondsToTimelock(params.unilateralRefundDelay),
|
|
132
|
-
unilateralRefundWithoutReceiverDelay: secondsToTimelock(params.unilateralRefundWithoutReceiverDelay),
|
|
133
|
-
});
|
|
134
|
-
const hrp = getNetworkHrp(networkName);
|
|
135
|
-
const computedAddr = vhtlc.address(hrp, serverPkBytes).encode();
|
|
136
|
-
if (computedAddr !== params.vhtlcAddress) {
|
|
137
|
-
throw new Error(`VHTLC address mismatch: computed ${computedAddr}, expected ${params.vhtlcAddress}`);
|
|
138
|
-
}
|
|
139
|
-
return settleDelegate({
|
|
140
|
-
userSecretKey: params.userSecretKey,
|
|
141
|
-
tapLeafScript: vhtlc.refundWithoutReceiver(),
|
|
142
|
-
tapTree: vhtlc.encode(),
|
|
143
|
-
vhtlcPkScript: hex.encode(vhtlc.pkScript),
|
|
144
|
-
witnessData: undefined,
|
|
145
|
-
destinationAddress: params.destinationAddress,
|
|
146
|
-
networkName,
|
|
147
|
-
lendaswapApiUrl: params.lendaswapApiUrl,
|
|
148
|
-
arkadeServerUrl: params.arkadeServerUrl,
|
|
149
|
-
locktime: params.refundLocktime,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
async function settleDelegate(opts) {
|
|
153
|
-
const { userSecretKey, tapLeafScript, tapTree, vhtlcPkScript, witnessData, destinationAddress, networkName, lendaswapApiUrl, arkadeServerUrl, } = opts;
|
|
154
|
-
const serverUrl = arkadeServerUrl ?? DEFAULT_ARKADE_URLS[networkName];
|
|
155
|
-
if (!serverUrl) {
|
|
156
|
-
throw new Error(`No Arkade server URL for network: ${networkName}`);
|
|
157
|
-
}
|
|
158
|
-
const arkProvider = new RestArkProvider(serverUrl);
|
|
159
|
-
const indexerProvider = new RestIndexerProvider(serverUrl);
|
|
160
|
-
const serverInfo = await arkProvider.getInfo();
|
|
161
|
-
// Fetch cosigner pk from lendaswap backend
|
|
162
|
-
const cosignerPkHex = await fetchCosignerPk(lendaswapApiUrl);
|
|
163
|
-
// Decode forfeit address (bech32) to pkScript
|
|
164
|
-
const btcNetwork = networks[networkName];
|
|
165
|
-
const forfeitDecoded = Address(btcNetwork).decode(serverInfo.forfeitAddress);
|
|
166
|
-
const forfeitPkScript = OutScript.encode(forfeitDecoded);
|
|
167
|
-
// Fetch VTXOs — include all (not just spendable)
|
|
168
|
-
const { vtxos: allVtxos } = await indexerProvider.getVtxos({
|
|
169
|
-
scripts: [vhtlcPkScript],
|
|
170
|
-
});
|
|
171
|
-
// Filter to unspent VTXOs
|
|
172
|
-
const vtxos = allVtxos.filter((v) => !v.isSpent);
|
|
173
|
-
if (vtxos.length === 0) {
|
|
174
|
-
throw new Error("No settleable VTXOs found at the VHTLC address");
|
|
175
|
-
}
|
|
176
|
-
const totalAmount = vtxos.reduce((acc, v) => acc + BigInt(v.value), 0n);
|
|
177
|
-
if (totalAmount === 0n) {
|
|
178
|
-
throw new Error("Total VTXO amount is zero");
|
|
179
|
-
}
|
|
180
|
-
console.log(`Found ${vtxos.length} VTXO(s) totalling ${totalAmount} sats`);
|
|
181
|
-
// Parse destination (Ark address → taproot pkScript)
|
|
182
|
-
const destAddr = ArkAddress.decode(destinationAddress);
|
|
183
|
-
const destPkScript = destAddr.pkScript;
|
|
184
|
-
// Build intent message
|
|
185
|
-
const now = Math.floor(Date.now() / 1000);
|
|
186
|
-
const intentMessage = {
|
|
187
|
-
type: "register",
|
|
188
|
-
onchain_output_indexes: [],
|
|
189
|
-
valid_at: now,
|
|
190
|
-
expire_at: now + 120,
|
|
191
|
-
cosigners_public_keys: [cosignerPkHex],
|
|
192
|
-
};
|
|
193
|
-
// Build intent inputs from VTXOs
|
|
194
|
-
const pkScriptBytes = hex.decode(vhtlcPkScript);
|
|
195
|
-
const intentInputs = vtxos.map((v) => ({
|
|
196
|
-
txid: hex.decode(v.txid),
|
|
197
|
-
index: v.vout,
|
|
198
|
-
witnessUtxo: {
|
|
199
|
-
script: pkScriptBytes,
|
|
200
|
-
amount: BigInt(v.value),
|
|
201
|
-
},
|
|
202
|
-
tapLeafScript: [tapLeafScript],
|
|
203
|
-
sequence: opts.locktime ? 0xfffffffe : undefined,
|
|
204
|
-
sighashType: SigHash.ALL,
|
|
205
|
-
}));
|
|
206
|
-
// Build intent proof PSBT
|
|
207
|
-
const intentProof = Intent.create(intentMessage, intentInputs, [
|
|
208
|
-
{ script: destPkScript, amount: totalAmount },
|
|
209
|
-
]);
|
|
210
|
-
// Set VtxoTaprootTree on each real input (skip input 0 which is the toSpend ref)
|
|
211
|
-
for (let i = 0; i < vtxos.length; i++) {
|
|
212
|
-
setArkPsbtField(intentProof, i + 1, VtxoTaprootTree, tapTree);
|
|
213
|
-
}
|
|
214
|
-
// Sign intent proof
|
|
215
|
-
const signer = SingleKey.fromHex(userSecretKey);
|
|
216
|
-
// Set condition witness (preimage) if claiming
|
|
217
|
-
if (witnessData) {
|
|
218
|
-
for (let i = 0; i < vtxos.length; i++) {
|
|
219
|
-
setArkPsbtField(intentProof, i + 1, ConditionWitness, [witnessData]);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const signedIntentProof = await signer.sign(intentProof);
|
|
223
|
-
// Build and sign delegate forfeit PSBTs.
|
|
224
|
-
// Delegate forfeits have 1 input (the VTXO) with SIGHASH_ALL|ANYONECANPAY.
|
|
225
|
-
// The connector input is added later by the cosigner during batch finalization.
|
|
226
|
-
// Output amount = vtxo_amount + connector_dust (anticipating the connector).
|
|
227
|
-
const dust = serverInfo.dust;
|
|
228
|
-
const signedForfeitPsbts = [];
|
|
229
|
-
for (const v of vtxos) {
|
|
230
|
-
const vtxoAmount = BigInt(v.value);
|
|
231
|
-
const forfeitTx = new Transaction({
|
|
232
|
-
version: 3,
|
|
233
|
-
lockTime: 0,
|
|
234
|
-
});
|
|
235
|
-
forfeitTx.addInput({
|
|
236
|
-
txid: hex.decode(v.txid),
|
|
237
|
-
index: v.vout,
|
|
238
|
-
witnessUtxo: {
|
|
239
|
-
script: pkScriptBytes,
|
|
240
|
-
amount: vtxoAmount,
|
|
241
|
-
},
|
|
242
|
-
tapLeafScript: [tapLeafScript],
|
|
243
|
-
sighashType: SigHash.ALL_ANYONECANPAY,
|
|
244
|
-
});
|
|
245
|
-
// Main output: VTXO amount + connector dust → forfeit address
|
|
246
|
-
forfeitTx.addOutput({
|
|
247
|
-
script: forfeitPkScript,
|
|
248
|
-
amount: vtxoAmount + dust,
|
|
249
|
-
});
|
|
250
|
-
// Anchor output (P2A)
|
|
251
|
-
forfeitTx.addOutput(P2A);
|
|
252
|
-
// Set taproot tree
|
|
253
|
-
setArkPsbtField(forfeitTx, 0, VtxoTaprootTree, tapTree);
|
|
254
|
-
if (witnessData) {
|
|
255
|
-
setArkPsbtField(forfeitTx, 0, ConditionWitness, [witnessData]);
|
|
256
|
-
}
|
|
257
|
-
const signedForfeit = await signer.sign(forfeitTx);
|
|
258
|
-
signedForfeitPsbts.push(base64.encode(signedForfeit.toPSBT()));
|
|
259
|
-
}
|
|
260
|
-
// Serialize intent proof
|
|
261
|
-
const intentProofBase64 = base64.encode(signedIntentProof.toPSBT());
|
|
262
|
-
const intentMessageJson = Intent.encodeMessage(intentMessage);
|
|
263
|
-
// POST to backend
|
|
264
|
-
const settleUrl = `${lendaswapApiUrl.replace(/\/$/, "")}/api/delegate/settle`;
|
|
265
|
-
const settleRes = await fetch(settleUrl, {
|
|
266
|
-
method: "POST",
|
|
267
|
-
headers: { "Content-Type": "application/json" },
|
|
268
|
-
body: JSON.stringify({
|
|
269
|
-
intent_proof: intentProofBase64,
|
|
270
|
-
intent_message: intentMessageJson,
|
|
271
|
-
forfeit_psbts: signedForfeitPsbts,
|
|
272
|
-
cosigner_pk: cosignerPkHex,
|
|
273
|
-
swap_id: opts.swapId,
|
|
274
|
-
preimage: opts.preimage,
|
|
275
|
-
}),
|
|
276
|
-
});
|
|
277
|
-
if (!settleRes.ok) {
|
|
278
|
-
const errBody = await settleRes.text();
|
|
279
|
-
throw new Error(`Delegate settle failed: ${settleRes.status} ${errBody}`);
|
|
280
|
-
}
|
|
281
|
-
const result = (await settleRes.json());
|
|
282
|
-
return { commitmentTxid: result.commitment_txid };
|
|
283
|
-
}
|
|
284
|
-
//# sourceMappingURL=delegate.js.map
|
package/dist/src/delegate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../src/delegate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,UAAU,EAEV,gBAAgB,EAEhB,MAAM,EAEN,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,eAAe,EAEf,WAAW,EACX,KAAK,EACL,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,oDAAoD;AACpD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC5D,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAE1C,2CAA2C;AAC3C,MAAM,mB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4
|
-
/** Esplora UTXO response */
|
|
5
|
-
export interface EsploraUtxo {
|
|
6
|
-
txid: string;
|
|
7
|
-
vout: number;
|
|
8
|
-
status: {
|
|
9
|
-
confirmed: boolean;
|
|
10
|
-
block_height?: number;
|
|
11
|
-
block_hash?: string;
|
|
12
|
-
block_time?: number;
|
|
13
|
-
};
|
|
14
|
-
value: number;
|
|
15
|
-
}
|
|
16
|
-
/** Result of finding an HTLC output */
|
|
17
|
-
export interface HtlcOutputResult {
|
|
18
|
-
txid: string;
|
|
19
|
-
vout: number;
|
|
20
|
-
amount: bigint;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Finds a UTXO at the given address.
|
|
24
|
-
*
|
|
25
|
-
* Queries the Esplora `/address/:address/utxo` endpoint to find
|
|
26
|
-
* unspent outputs. Returns the first UTXO found.
|
|
27
|
-
*
|
|
28
|
-
* @param esploraUrl - The Esplora API base URL
|
|
29
|
-
* @param address - The address to look up UTXOs for
|
|
30
|
-
* @returns The txid, vout, and amount of the first UTXO, or null if none found
|
|
31
|
-
*/
|
|
32
|
-
export declare function findOutputByAddress(esploraUrl: string, address: string): Promise<HtlcOutputResult | null>;
|
|
33
|
-
/**
|
|
34
|
-
* Broadcasts a raw transaction to the Bitcoin network via Esplora API.
|
|
35
|
-
*
|
|
36
|
-
* @param esploraUrl - The Esplora API base URL
|
|
37
|
-
* @param txHex - The raw transaction hex to broadcast
|
|
38
|
-
* @returns The transaction ID on success
|
|
39
|
-
*/
|
|
40
|
-
export declare function broadcastTransaction(esploraUrl: string, txHex: string): Promise<string>;
|
|
41
|
-
//# sourceMappingURL=esplora.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esplora.d.ts","sourceRoot":"","sources":["../../src/esplora.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,4BAA4B;AAC5B,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QACN,SAAS,EAAE,OAAO,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAgBlC;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
package/dist/src/esplora.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Esplora API utilities for Bitcoin transaction lookups.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Finds a UTXO at the given address.
|
|
6
|
-
*
|
|
7
|
-
* Queries the Esplora `/address/:address/utxo` endpoint to find
|
|
8
|
-
* unspent outputs. Returns the first UTXO found.
|
|
9
|
-
*
|
|
10
|
-
* @param esploraUrl - The Esplora API base URL
|
|
11
|
-
* @param address - The address to look up UTXOs for
|
|
12
|
-
* @returns The txid, vout, and amount of the first UTXO, or null if none found
|
|
13
|
-
*/
|
|
14
|
-
export async function findOutputByAddress(esploraUrl, address) {
|
|
15
|
-
const response = await fetch(`${esploraUrl}/address/${address}/utxo`);
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
throw new Error(`Failed to fetch UTXOs for address ${address}: ${response.status}`);
|
|
18
|
-
}
|
|
19
|
-
const utxos = (await response.json());
|
|
20
|
-
if (utxos.length === 0) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const utxo = utxos[0];
|
|
24
|
-
return { txid: utxo.txid, vout: utxo.vout, amount: BigInt(utxo.value) };
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Broadcasts a raw transaction to the Bitcoin network via Esplora API.
|
|
28
|
-
*
|
|
29
|
-
* @param esploraUrl - The Esplora API base URL
|
|
30
|
-
* @param txHex - The raw transaction hex to broadcast
|
|
31
|
-
* @returns The transaction ID on success
|
|
32
|
-
*/
|
|
33
|
-
export async function broadcastTransaction(esploraUrl, txHex) {
|
|
34
|
-
const response = await fetch(`${esploraUrl}/tx`, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "text/plain",
|
|
38
|
-
},
|
|
39
|
-
body: txHex,
|
|
40
|
-
});
|
|
41
|
-
if (!response.ok) {
|
|
42
|
-
const errorText = await response.text();
|
|
43
|
-
throw new Error(`Broadcast failed: ${response.status} - ${errorText}`);
|
|
44
|
-
}
|
|
45
|
-
return response.text();
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=esplora.js.map
|
package/dist/src/esplora.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esplora.js","sourceRoot":"","sources":["../../src/esplora.ts"],"names":[],"mappings":"AAAA;;GAEG;AAsBH;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,UAAkB,EAClB,OAAe;IAEf,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,YAAY,OAAO,OAAO,CAAC,CAAC;IACtE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,qCAAqC,OAAO,KAAK,QAAQ,CAAC,MAAM,EAAE,CACnE,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAk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