@lendasat/lendaswap-sdk-pure 0.2.41 → 0.2.43
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/_esm-6K2AP5GG.js +3663 -0
- package/dist/_esm-6K2AP5GG.js.map +1 -0
- package/dist/_esm-UGRDSVEV.cjs +3662 -0
- package/dist/_esm-UGRDSVEV.cjs.map +1 -0
- package/dist/api/client.d.ts +0 -4
- package/dist/api/client.d.ts.map +1 -1
- package/dist/base-2KYNAFR3.cjs +109 -0
- package/dist/base-2KYNAFR3.cjs.map +1 -0
- package/dist/base-HMHH3XPM.js +9 -0
- package/dist/base-HMHH3XPM.js.map +1 -0
- package/dist/ccip-EBXWV2U3.js +8 -0
- package/dist/ccip-EBXWV2U3.js.map +1 -0
- package/dist/ccip-PD37NJHA.cjs +26 -0
- package/dist/ccip-PD37NJHA.cjs.map +1 -0
- package/dist/cctp-bridge/index.cjs +67 -0
- package/dist/cctp-bridge/index.cjs.map +1 -0
- package/dist/cctp-bridge/index.js +53 -15
- package/dist/cctp-bridge/index.js.map +1 -1
- package/dist/cctp-inbound/client.d.ts +21 -19
- package/dist/cctp-inbound/client.d.ts.map +1 -1
- package/dist/cctp-inbound/smartAccount.d.ts +21 -19
- package/dist/cctp-inbound/smartAccount.d.ts.map +1 -1
- package/dist/chunk-4JXN4UPB.js +554 -0
- package/dist/chunk-4JXN4UPB.js.map +1 -0
- package/dist/chunk-A4GKKURK.cjs +430 -0
- package/dist/chunk-A4GKKURK.cjs.map +1 -0
- package/dist/chunk-BZU3R5DJ.cjs +554 -0
- package/dist/chunk-BZU3R5DJ.cjs.map +1 -0
- package/dist/chunk-DBBCKPZ5.js +421 -0
- package/dist/chunk-DBBCKPZ5.js.map +1 -0
- package/dist/chunk-DNSJDKTP.cjs +96 -0
- package/dist/chunk-DNSJDKTP.cjs.map +1 -0
- package/dist/chunk-EIK6BZWG.js +90 -0
- package/dist/chunk-EIK6BZWG.js.map +1 -0
- package/dist/chunk-GVAPVS4Z.js +6144 -0
- package/dist/chunk-GVAPVS4Z.js.map +1 -0
- package/dist/chunk-I7TGLGN6.js +46 -0
- package/dist/chunk-I7TGLGN6.js.map +1 -0
- package/dist/chunk-JBVKWKD4.cjs +50 -0
- package/dist/chunk-JBVKWKD4.cjs.map +1 -0
- package/dist/chunk-LA3YX2HD.js +47096 -0
- package/dist/chunk-LA3YX2HD.js.map +1 -0
- package/dist/chunk-PKDJZJMV.cjs +2214 -0
- package/dist/chunk-PKDJZJMV.cjs.map +1 -0
- package/dist/chunk-PRN5VZOM.js +370 -0
- package/dist/chunk-PRN5VZOM.js.map +1 -0
- package/dist/chunk-RIOT5VOJ.cjs +47240 -0
- package/dist/chunk-RIOT5VOJ.cjs.map +1 -0
- package/dist/chunk-WVZSHRV7.cjs +431 -0
- package/dist/chunk-WVZSHRV7.cjs.map +1 -0
- package/dist/chunk-YLWPBHMV.cjs +6311 -0
- package/dist/chunk-YLWPBHMV.cjs.map +1 -0
- package/dist/chunk-Z2FCTNRC.js +2210 -0
- package/dist/chunk-Z2FCTNRC.js.map +1 -0
- package/dist/client.d.ts +68 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/compose-quote.d.ts +77 -0
- package/dist/compose-quote.d.ts.map +1 -0
- package/dist/delegate.cjs +23 -0
- package/dist/delegate.cjs.map +1 -0
- package/dist/delegate.js +8 -269
- package/dist/delegate.js.map +1 -1
- package/dist/dist-PWXNFVDF.js +8 -0
- package/dist/dist-PWXNFVDF.js.map +1 -0
- package/dist/dist-VEHYC67F.cjs +550 -0
- package/dist/dist-VEHYC67F.cjs.map +1 -0
- package/dist/esplora.d.ts +14 -0
- package/dist/esplora.d.ts.map +1 -1
- package/dist/generated/api.d.ts +235 -38
- package/dist/generated/api.d.ts.map +1 -1
- package/dist/index.cjs +35461 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35312 -32
- package/dist/index.js.map +1 -1
- package/dist/mine.wasm-LUTPOAD2.js +12 -0
- package/dist/mine.wasm-LUTPOAD2.js.map +1 -0
- package/dist/mine.wasm-Z3ORSBKN.cjs +12 -0
- package/dist/mine.wasm-Z3ORSBKN.cjs.map +1 -0
- package/dist/node.cjs +166 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.js +159 -18
- package/dist/node.js.map +1 -1
- package/dist/secp256k1-B6OW5ZCM.js +8 -0
- package/dist/secp256k1-B6OW5ZCM.js.map +1 -0
- package/dist/secp256k1-PJCSE4N6.cjs +30 -0
- package/dist/secp256k1-PJCSE4N6.cjs.map +1 -0
- package/dist/tokens.d.ts +2 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/types/chain-config.d.ts +50 -0
- package/dist/types/chain-config.d.ts.map +1 -0
- package/dist/types/chain.d.ts +11 -0
- package/dist/types/chain.d.ts.map +1 -0
- package/dist/types/dex-quote.d.ts +85 -0
- package/dist/types/dex-quote.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/network-fees.d.ts +43 -0
- package/dist/types/network-fees.d.ts.map +1 -0
- package/dist/types/quote.d.ts +87 -0
- package/dist/types/quote.d.ts.map +1 -0
- package/dist/types/swap-pairs.d.ts +37 -0
- package/dist/types/swap-pairs.d.ts.map +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/wallet-4YGTKWNZ.js +7 -0
- package/dist/wallet-4YGTKWNZ.js.map +1 -0
- package/dist/wallet-SZJDXAY7.cjs +45 -0
- package/dist/wallet-SZJDXAY7.cjs.map +1 -0
- package/package.json +23 -10
- package/dist/api/client.js +0 -13
- package/dist/api/client.js.map +0 -1
- package/dist/arkade-network.js +0 -40
- package/dist/arkade-network.js.map +0 -1
- package/dist/arkade.js +0 -61
- package/dist/arkade.js.map +0 -1
- package/dist/cctp/attestation.js +0 -149
- package/dist/cctp/attestation.js.map +0 -1
- package/dist/cctp/constants.js +0 -92
- package/dist/cctp/constants.js.map +0 -1
- package/dist/cctp/fee.js +0 -70
- package/dist/cctp/fee.js.map +0 -1
- package/dist/cctp/index.js +0 -13
- package/dist/cctp/index.js.map +0 -1
- package/dist/cctp/types.js +0 -5
- package/dist/cctp/types.js.map +0 -1
- package/dist/cctp/utils.js +0 -91
- package/dist/cctp/utils.js.map +0 -1
- package/dist/cctp-bridge/bridge.js +0 -74
- package/dist/cctp-bridge/bridge.js.map +0 -1
- package/dist/cctp-inbound/approveAndBurn.js +0 -95
- package/dist/cctp-inbound/approveAndBurn.js.map +0 -1
- package/dist/cctp-inbound/burn.js +0 -66
- package/dist/cctp-inbound/burn.js.map +0 -1
- package/dist/cctp-inbound/chainMap.js +0 -128
- package/dist/cctp-inbound/chainMap.js.map +0 -1
- package/dist/cctp-inbound/client.js +0 -125
- package/dist/cctp-inbound/client.js.map +0 -1
- package/dist/cctp-inbound/eip2612.js +0 -95
- package/dist/cctp-inbound/eip2612.js.map +0 -1
- package/dist/cctp-inbound/evmSignerAdapter.js +0 -82
- package/dist/cctp-inbound/evmSignerAdapter.js.map +0 -1
- package/dist/cctp-inbound/fundSwap.js +0 -95
- package/dist/cctp-inbound/fundSwap.js.map +0 -1
- package/dist/cctp-inbound/index.js +0 -34
- package/dist/cctp-inbound/index.js.map +0 -1
- package/dist/cctp-inbound/permit2.js +0 -32
- package/dist/cctp-inbound/permit2.js.map +0 -1
- package/dist/cctp-inbound/preflight.js +0 -84
- package/dist/cctp-inbound/preflight.js.map +0 -1
- package/dist/cctp-inbound/recover.js +0 -177
- package/dist/cctp-inbound/recover.js.map +0 -1
- package/dist/cctp-inbound/smartAccount.js +0 -117
- package/dist/cctp-inbound/smartAccount.js.map +0 -1
- package/dist/cctp-inbound/submit.js +0 -136
- package/dist/cctp-inbound/submit.js.map +0 -1
- package/dist/cctp-inbound/types.js +0 -5
- package/dist/cctp-inbound/types.js.map +0 -1
- package/dist/cctp-inbound/userOp.js +0 -151
- package/dist/cctp-inbound/userOp.js.map +0 -1
- package/dist/client.js +0 -4126
- package/dist/client.js.map +0 -1
- package/dist/create/arkade-to-lightning.js +0 -76
- package/dist/create/arkade-to-lightning.js.map +0 -1
- package/dist/create/arkade.js +0 -86
- package/dist/create/arkade.js.map +0 -1
- package/dist/create/bitcoin-to-arkade.js +0 -76
- package/dist/create/bitcoin-to-arkade.js.map +0 -1
- package/dist/create/bitcoin.js +0 -77
- package/dist/create/bitcoin.js.map +0 -1
- package/dist/create/evm-to-arkade.js +0 -80
- package/dist/create/evm-to-arkade.js.map +0 -1
- package/dist/create/evm-to-bitcoin.js +0 -82
- package/dist/create/evm-to-bitcoin.js.map +0 -1
- package/dist/create/evm-to-lightning.js +0 -89
- package/dist/create/evm-to-lightning.js.map +0 -1
- package/dist/create/index.js +0 -21
- package/dist/create/index.js.map +0 -1
- package/dist/create/lightning-to-arkade.js +0 -69
- package/dist/create/lightning-to-arkade.js.map +0 -1
- package/dist/create/lightning.js +0 -61
- package/dist/create/lightning.js.map +0 -1
- package/dist/create/retry.js +0 -71
- package/dist/create/retry.js.map +0 -1
- package/dist/create/types.js +0 -5
- package/dist/create/types.js.map +0 -1
- package/dist/escrow/index.js +0 -115
- package/dist/escrow/index.js.map +0 -1
- package/dist/esplora.js +0 -47
- package/dist/esplora.js.map +0 -1
- package/dist/evm/coordinator.js +0 -714
- package/dist/evm/coordinator.js.map +0 -1
- package/dist/evm/htlc.js +0 -278
- package/dist/evm/htlc.js.map +0 -1
- package/dist/evm/index.js +0 -10
- package/dist/evm/index.js.map +0 -1
- package/dist/evm/signing.js +0 -70
- package/dist/evm/signing.js.map +0 -1
- package/dist/evm/wallet.js +0 -133
- package/dist/evm/wallet.js.map +0 -1
- package/dist/generated/api.js +0 -6
- package/dist/generated/api.js.map +0 -1
- package/dist/logging.js +0 -130
- package/dist/logging.js.map +0 -1
- package/dist/price-calculations.js +0 -135
- package/dist/price-calculations.js.map +0 -1
- package/dist/redeem/arkade.js +0 -416
- package/dist/redeem/arkade.js.map +0 -1
- package/dist/redeem/ethereum.js +0 -206
- package/dist/redeem/ethereum.js.map +0 -1
- package/dist/redeem/gasless.js +0 -73
- package/dist/redeem/gasless.js.map +0 -1
- package/dist/redeem/index.js +0 -189
- package/dist/redeem/index.js.map +0 -1
- package/dist/redeem/types.js +0 -36
- package/dist/redeem/types.js.map +0 -1
- package/dist/refund/arkade.js +0 -200
- package/dist/refund/arkade.js.map +0 -1
- package/dist/refund/collab-arkade-evm.js +0 -307
- package/dist/refund/collab-arkade-evm.js.map +0 -1
- package/dist/refund/collab-arkade-lightning.js +0 -245
- package/dist/refund/collab-arkade-lightning.js.map +0 -1
- package/dist/refund/index.js +0 -12
- package/dist/refund/index.js.map +0 -1
- package/dist/refund/onchain.js +0 -366
- package/dist/refund/onchain.js.map +0 -1
- package/dist/signer/index.js +0 -249
- package/dist/signer/index.js.map +0 -1
- package/dist/storage/idb.js +0 -236
- package/dist/storage/idb.js.map +0 -1
- package/dist/storage/index.js +0 -98
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/sqlite.js +0 -206
- package/dist/storage/sqlite.js.map +0 -1
- package/dist/storage/types.js +0 -9
- package/dist/storage/types.js.map +0 -1
- package/dist/tokens.js +0 -322
- package/dist/tokens.js.map +0 -1
- package/dist/usd-price.js +0 -96
- package/dist/usd-price.js.map +0 -1
- package/dist/usdt0-bridge/constants.js +0 -71
- package/dist/usdt0-bridge/constants.js.map +0 -1
- package/dist/usdt0-bridge/index.js +0 -11
- package/dist/usdt0-bridge/index.js.map +0 -1
- package/dist/usdt0-bridge/tracking.js +0 -123
- package/dist/usdt0-bridge/tracking.js.map +0 -1
- package/dist/usdt0-bridge/utils.js +0 -51
- package/dist/usdt0-bridge/utils.js.map +0 -1
- package/dist/version.js +0 -6
- package/dist/version.js.map +0 -1
- package/dist/ws.js +0 -145
- package/dist/ws.js.map +0 -1
package/dist/redeem/arkade.js
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Arkade (off-chain) VHTLC claim implementation.
|
|
3
|
-
*
|
|
4
|
-
* This module provides VHTLC claim functionality for Arkade swaps.
|
|
5
|
-
* When a swap is funded by the server (EVM-to-Arkade direction),
|
|
6
|
-
* the user can claim their BTC by revealing the preimage.
|
|
7
|
-
*
|
|
8
|
-
* The VHTLC uses a Taproot output with multiple spending paths. For claims,
|
|
9
|
-
* we use the `claim` script path which requires revealing the preimage.
|
|
10
|
-
*/
|
|
11
|
-
import { buildOffchainTx, ConditionWitness, CSVMultisigTapscript, Intent, RestArkProvider, RestIndexerProvider, SingleKey, setArkPsbtField, Transaction, VHTLC, VtxoTaprootTree, } from "@arkade-os/sdk";
|
|
12
|
-
import { ripemd160 } from "@noble/hashes/legacy.js";
|
|
13
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
14
|
-
import { base64, hex } from "@scure/base";
|
|
15
|
-
import { SigHash } from "@scure/btc-signer";
|
|
16
|
-
import { getNetworkHrp, getNetworkName, resolveArkadeServerUrlByName, } from "../arkade-network.js";
|
|
17
|
-
import { createSdkLogger } from "../logging.js";
|
|
18
|
-
/**
|
|
19
|
-
* Convert seconds to RelativeTimelock format.
|
|
20
|
-
*/
|
|
21
|
-
function secondsToTimelock(seconds) {
|
|
22
|
-
return {
|
|
23
|
-
type: "seconds",
|
|
24
|
-
value: BigInt(seconds),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Parse public key, handling both compressed (33-byte) and x-only (32-byte) formats.
|
|
29
|
-
* Returns x-only (32-byte) format.
|
|
30
|
-
*/
|
|
31
|
-
function parseXOnlyPubKey(pubKeyHex) {
|
|
32
|
-
const bytes = hex.decode(pubKeyHex);
|
|
33
|
-
if (bytes.length === 33) {
|
|
34
|
-
// Compressed pubkey, strip the prefix byte
|
|
35
|
-
return bytes.slice(1);
|
|
36
|
-
}
|
|
37
|
-
if (bytes.length === 32) {
|
|
38
|
-
// Already x-only
|
|
39
|
-
return bytes;
|
|
40
|
-
}
|
|
41
|
-
throw new Error(`Invalid public key length: expected 32 or 33, got ${bytes.length}`);
|
|
42
|
-
}
|
|
43
|
-
function isNoPendingClaimError(error) {
|
|
44
|
-
return (error instanceof Error &&
|
|
45
|
-
error.message.startsWith("No pending transactions found at the VHTLC address"));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Claim a VHTLC swap by revealing the preimage.
|
|
49
|
-
*
|
|
50
|
-
* This function:
|
|
51
|
-
* 1. Constructs the VHTLC with the same parameters as the original swap
|
|
52
|
-
* 2. Connects to the Arkade server
|
|
53
|
-
* 3. Fetches spendable VTXOs at the VHTLC address
|
|
54
|
-
* 4. Builds an offchain transaction using the claim script path
|
|
55
|
-
* 5. Signs and submits the transaction (with preimage in witness)
|
|
56
|
-
* 6. Finalizes the transaction
|
|
57
|
-
*
|
|
58
|
-
* @param params - The claim parameters
|
|
59
|
-
* @returns The claim result with transaction ID and amount
|
|
60
|
-
* @throws Error if the claim fails
|
|
61
|
-
*/
|
|
62
|
-
export async function buildArkadeClaim(params) {
|
|
63
|
-
const { userSecretKey, userPubKey, lendaswapPubKey, arkadeServerPubKey, preimage, preimageHash, vhtlcAddress, refundLocktime, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, destinationAddress, network, arkadeServerUrl, } = params;
|
|
64
|
-
const logger = createSdkLogger(params).child({
|
|
65
|
-
module: "redeem/arkade",
|
|
66
|
-
operation: "arkade.claim",
|
|
67
|
-
data: { vhtlcAddress, network, destinationAddress },
|
|
68
|
-
});
|
|
69
|
-
logger.info({
|
|
70
|
-
event: "arkade.claim.start",
|
|
71
|
-
message: "Starting Arkade claim",
|
|
72
|
-
});
|
|
73
|
-
// Arkade offchain spends are submit/finalize. If a previous attempt submitted
|
|
74
|
-
// but failed before finalization, submitting again with the same VTXOs will
|
|
75
|
-
// fail. First ask the server for an existing pending tx and finalize that.
|
|
76
|
-
try {
|
|
77
|
-
return await continueArkadeClaim(params);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (!isNoPendingClaimError(error)) {
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
console.log("No pending Arkade claim found; submitting a new claim");
|
|
84
|
-
}
|
|
85
|
-
// Parse keys
|
|
86
|
-
// For claim: user is RECEIVER, lendaswap is SENDER
|
|
87
|
-
const userPkBytes = parseXOnlyPubKey(userPubKey);
|
|
88
|
-
const lendaswapPkBytes = parseXOnlyPubKey(lendaswapPubKey);
|
|
89
|
-
const serverPkBytes = parseXOnlyPubKey(arkadeServerPubKey);
|
|
90
|
-
// Parse preimage and compute hash
|
|
91
|
-
const preimageBytes = hex.decode(preimage);
|
|
92
|
-
if (preimageBytes.length !== 32) {
|
|
93
|
-
throw new Error(`Invalid preimage length: expected 32, got ${preimageBytes.length}`);
|
|
94
|
-
}
|
|
95
|
-
// Compute preimage hash: SHA256 -> RIPEMD160 (HASH160)
|
|
96
|
-
const sha256Hash = sha256(preimageBytes);
|
|
97
|
-
const preimageHashBytes = ripemd160(sha256Hash);
|
|
98
|
-
const preimageHashBytesString = hex.encode(preimageHashBytes);
|
|
99
|
-
if (preimageHashBytesString !== hex.encode(ripemd160(hex.decode(preimageHash)))) {
|
|
100
|
-
throw new Error(`Preimage hash are not equal. '${hex.encode(ripemd160(hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`);
|
|
101
|
-
}
|
|
102
|
-
// Determine Arkade server URL
|
|
103
|
-
const networkName = getNetworkName(network);
|
|
104
|
-
const serverUrl = resolveArkadeServerUrlByName(networkName, arkadeServerUrl);
|
|
105
|
-
// Create Arkade providers
|
|
106
|
-
const arkProvider = new RestArkProvider(serverUrl);
|
|
107
|
-
const indexerProvider = new RestIndexerProvider(serverUrl);
|
|
108
|
-
// Get server info
|
|
109
|
-
const serverInfo = await arkProvider.getInfo();
|
|
110
|
-
// Construct VHTLC with the same parameters as the original swap
|
|
111
|
-
// For claim: lendaswap is the SENDER, user is the RECEIVER
|
|
112
|
-
const vhtlc = new VHTLC.Script({
|
|
113
|
-
sender: lendaswapPkBytes,
|
|
114
|
-
receiver: userPkBytes,
|
|
115
|
-
server: serverPkBytes,
|
|
116
|
-
preimageHash: preimageHashBytes,
|
|
117
|
-
refundLocktime: BigInt(refundLocktime),
|
|
118
|
-
unilateralClaimDelay: secondsToTimelock(unilateralClaimDelay),
|
|
119
|
-
unilateralRefundDelay: secondsToTimelock(unilateralRefundDelay),
|
|
120
|
-
unilateralRefundWithoutReceiverDelay: secondsToTimelock(unilateralRefundWithoutReceiverDelay),
|
|
121
|
-
});
|
|
122
|
-
// Get network HRP and verify computed VHTLC address
|
|
123
|
-
const hrp = getNetworkHrp(networkName);
|
|
124
|
-
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
125
|
-
const computedAddressStr = computedAddress.encode();
|
|
126
|
-
// Verify address matches expected
|
|
127
|
-
if (computedAddressStr !== vhtlcAddress) {
|
|
128
|
-
throw new Error(`Computed VHTLC address (${computedAddressStr}) does not match expected (${vhtlcAddress})`);
|
|
129
|
-
}
|
|
130
|
-
// Fetch VTXOs at the VHTLC address
|
|
131
|
-
const vhtlcPkScript = hex.encode(vhtlc.pkScript);
|
|
132
|
-
const { vtxos } = await indexerProvider.getVtxos({
|
|
133
|
-
scripts: [vhtlcPkScript],
|
|
134
|
-
spendableOnly: true,
|
|
135
|
-
});
|
|
136
|
-
if (vtxos.length === 0) {
|
|
137
|
-
const { vtxos: allVtxos } = await indexerProvider.getVtxos({
|
|
138
|
-
scripts: [vhtlcPkScript],
|
|
139
|
-
});
|
|
140
|
-
logger.debug({
|
|
141
|
-
event: "arkade.claim.no_spendable_vtxos",
|
|
142
|
-
message: "No spendable VTXOs found at VHTLC address",
|
|
143
|
-
data: { vtxos: allVtxos },
|
|
144
|
-
});
|
|
145
|
-
throw new Error("No spendable VTXOs found at the VHTLC address");
|
|
146
|
-
}
|
|
147
|
-
// Calculate total amount
|
|
148
|
-
const totalAmount = vtxos.reduce((acc, v) => acc + BigInt(v.value), 0n);
|
|
149
|
-
if (totalAmount === 0n) {
|
|
150
|
-
throw new Error("Total VTXO amount is zero");
|
|
151
|
-
}
|
|
152
|
-
// Get the claim TapLeafScript (this is the key difference from refund)
|
|
153
|
-
const claimLeafScript = vhtlc.claim();
|
|
154
|
-
// Encode the VHTLC tap tree
|
|
155
|
-
const tapTree = vhtlc.encode();
|
|
156
|
-
// Decode the server's checkpoint tapscript
|
|
157
|
-
const checkpointTapscript = CSVMultisigTapscript.decode(hex.decode(serverInfo.checkpointTapscript));
|
|
158
|
-
// Build inputs for offchain transaction
|
|
159
|
-
// Include the preimage in the witness data
|
|
160
|
-
const inputs = vtxos.map((v) => ({
|
|
161
|
-
txid: v.txid,
|
|
162
|
-
vout: v.vout,
|
|
163
|
-
value: v.value,
|
|
164
|
-
tapTree: tapTree,
|
|
165
|
-
tapLeafScript: claimLeafScript,
|
|
166
|
-
// The preimage will be added to the witness during signing
|
|
167
|
-
witnessData: preimageBytes,
|
|
168
|
-
}));
|
|
169
|
-
// Parse destination address
|
|
170
|
-
const { ArkAddress } = await import("@arkade-os/sdk");
|
|
171
|
-
const destAddr = ArkAddress.decode(destinationAddress);
|
|
172
|
-
const destPkScript = destAddr.pkScript;
|
|
173
|
-
// Build outputs
|
|
174
|
-
const outputs = [
|
|
175
|
-
{
|
|
176
|
-
script: destPkScript,
|
|
177
|
-
amount: totalAmount,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
logger.info({
|
|
181
|
-
event: "arkade.claim.vtxos_found",
|
|
182
|
-
message: "Found spendable VTXOs for Arkade claim",
|
|
183
|
-
data: { totalAmount, vtxoCount: vtxos.length },
|
|
184
|
-
});
|
|
185
|
-
// Build the offchain transaction
|
|
186
|
-
const { arkTx, checkpoints } = buildOffchainTx(inputs, outputs, checkpointTapscript);
|
|
187
|
-
// Create signer from user's secret key
|
|
188
|
-
const signer = SingleKey.fromHex(userSecretKey);
|
|
189
|
-
const computedPk = await signer.xOnlyPublicKey();
|
|
190
|
-
if (hex.encode(userPkBytes) !== hex.encode(computedPk)) {
|
|
191
|
-
throw new Error(`Signing with wrong key? ${hex.encode(userPkBytes)} vs ${hex.encode(computedPk)}`);
|
|
192
|
-
}
|
|
193
|
-
// Sign the ark transaction
|
|
194
|
-
setArkPsbtField(arkTx, 0, ConditionWitness, [preimageBytes]);
|
|
195
|
-
const signedArkTx = await signer.sign(arkTx);
|
|
196
|
-
// Submit the transaction to the Arkade server
|
|
197
|
-
const signedArkTxBase64 = base64.encode(signedArkTx.toPSBT());
|
|
198
|
-
const { arkTxid, signedCheckpointTxs } = await arkProvider.submitTx(signedArkTxBase64, checkpoints.map((cp) => base64.encode(cp.toPSBT())));
|
|
199
|
-
// Sign and finalize checkpoint transactions
|
|
200
|
-
const finalCheckpoints = await Promise.all(signedCheckpointTxs.map(async (c) => {
|
|
201
|
-
const tx = Transaction.fromPSBT(base64.decode(c));
|
|
202
|
-
setArkPsbtField(tx, 0, ConditionWitness, [preimageBytes]);
|
|
203
|
-
const signedCheckpoint = await signer.sign(tx, [0]);
|
|
204
|
-
return base64.encode(signedCheckpoint.toPSBT());
|
|
205
|
-
}));
|
|
206
|
-
logger.debug({
|
|
207
|
-
event: "arkade.claim.checkpoints_signed",
|
|
208
|
-
message: "Checkpoint transactions signed",
|
|
209
|
-
});
|
|
210
|
-
// Finalize the transaction
|
|
211
|
-
try {
|
|
212
|
-
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
logger.error({
|
|
216
|
-
event: "arkade.claim.finalize_failed",
|
|
217
|
-
message: "Failed to finalize Arkade claim",
|
|
218
|
-
error,
|
|
219
|
-
});
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
logger.info({
|
|
223
|
-
event: "arkade.claim.finalized",
|
|
224
|
-
message: "Arkade claim finalized",
|
|
225
|
-
data: { arkTxid },
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
txId: arkTxid,
|
|
229
|
-
claimAmount: totalAmount,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
export async function continueArkadeClaim(params) {
|
|
233
|
-
const { userSecretKey, userPubKey, lendaswapPubKey, arkadeServerPubKey, preimage, preimageHash, vhtlcAddress, refundLocktime, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay,
|
|
234
|
-
// destinationAddress not needed — we continue an existing pending tx
|
|
235
|
-
network, arkadeServerUrl, } = params;
|
|
236
|
-
const logger = createSdkLogger(params).child({
|
|
237
|
-
module: "redeem/arkade",
|
|
238
|
-
operation: "arkade.claim.continue",
|
|
239
|
-
data: { vhtlcAddress, network },
|
|
240
|
-
});
|
|
241
|
-
logger.info({
|
|
242
|
-
event: "arkade.claim.continue_start",
|
|
243
|
-
message: "Continuing Arkade claim",
|
|
244
|
-
});
|
|
245
|
-
// Parse keys
|
|
246
|
-
// For claim: user is RECEIVER, lendaswap is SENDER
|
|
247
|
-
const userPkBytes = parseXOnlyPubKey(userPubKey);
|
|
248
|
-
const lendaswapPkBytes = parseXOnlyPubKey(lendaswapPubKey);
|
|
249
|
-
const serverPkBytes = parseXOnlyPubKey(arkadeServerPubKey);
|
|
250
|
-
// Parse preimage and compute hash
|
|
251
|
-
const preimageBytes = hex.decode(preimage);
|
|
252
|
-
if (preimageBytes.length !== 32) {
|
|
253
|
-
throw new Error(`Invalid preimage length: expected 32, got ${preimageBytes.length}`);
|
|
254
|
-
}
|
|
255
|
-
// Compute preimage hash: SHA256 -> RIPEMD160 (HASH160)
|
|
256
|
-
const sha256Hash = sha256(preimageBytes);
|
|
257
|
-
const preimageHashBytes = ripemd160(sha256Hash);
|
|
258
|
-
const preimageHashBytesString = hex.encode(preimageHashBytes);
|
|
259
|
-
if (preimageHashBytesString !== hex.encode(ripemd160(hex.decode(preimageHash)))) {
|
|
260
|
-
throw new Error(`Preimage hash are not equal. '${hex.encode(ripemd160(hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`);
|
|
261
|
-
}
|
|
262
|
-
// Determine Arkade server URL
|
|
263
|
-
const networkName = getNetworkName(network);
|
|
264
|
-
const serverUrl = resolveArkadeServerUrlByName(networkName, arkadeServerUrl);
|
|
265
|
-
// Create Arkade providers
|
|
266
|
-
const arkProvider = new RestArkProvider(serverUrl);
|
|
267
|
-
const indexerProvider = new RestIndexerProvider(serverUrl);
|
|
268
|
-
// Construct VHTLC with the same parameters as the original swap
|
|
269
|
-
// For claim: lendaswap is the SENDER, user is the RECEIVER
|
|
270
|
-
const vhtlc = new VHTLC.Script({
|
|
271
|
-
sender: lendaswapPkBytes,
|
|
272
|
-
receiver: userPkBytes,
|
|
273
|
-
server: serverPkBytes,
|
|
274
|
-
preimageHash: preimageHashBytes,
|
|
275
|
-
refundLocktime: BigInt(refundLocktime),
|
|
276
|
-
unilateralClaimDelay: secondsToTimelock(unilateralClaimDelay),
|
|
277
|
-
unilateralRefundDelay: secondsToTimelock(unilateralRefundDelay),
|
|
278
|
-
unilateralRefundWithoutReceiverDelay: secondsToTimelock(unilateralRefundWithoutReceiverDelay),
|
|
279
|
-
});
|
|
280
|
-
// Get network HRP and verify computed VHTLC address
|
|
281
|
-
const hrp = getNetworkHrp(networkName);
|
|
282
|
-
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
283
|
-
const computedAddressStr = computedAddress.encode();
|
|
284
|
-
// Verify address matches expected
|
|
285
|
-
if (computedAddressStr !== vhtlcAddress) {
|
|
286
|
-
throw new Error(`Computed VHTLC address (${computedAddressStr}) does not match expected (${vhtlcAddress})`);
|
|
287
|
-
}
|
|
288
|
-
// Fetch VTXOs at the VHTLC address
|
|
289
|
-
const vhtlcPkScript = hex.encode(vhtlc.pkScript);
|
|
290
|
-
const { vtxos } = await indexerProvider.getVtxos({
|
|
291
|
-
scripts: [vhtlcPkScript],
|
|
292
|
-
});
|
|
293
|
-
if (vtxos.length === 0) {
|
|
294
|
-
const { vtxos: allVtxos } = await indexerProvider.getVtxos({
|
|
295
|
-
scripts: [vhtlcPkScript],
|
|
296
|
-
});
|
|
297
|
-
logger.debug({
|
|
298
|
-
event: "arkade.claim.no_spendable_vtxos",
|
|
299
|
-
message: "No spendable VTXOs found at VHTLC address",
|
|
300
|
-
data: { vtxos: allVtxos },
|
|
301
|
-
});
|
|
302
|
-
throw new Error("No spendable VTXOs found at the VHTLC address");
|
|
303
|
-
}
|
|
304
|
-
// Calculate total amount
|
|
305
|
-
const totalAmount = vtxos.reduce((acc, v) => acc + BigInt(v.value), 0n);
|
|
306
|
-
if (totalAmount === 0n) {
|
|
307
|
-
throw new Error("Total VTXO amount is zero");
|
|
308
|
-
}
|
|
309
|
-
// Get the claim TapLeafScript (needed for the GetPendingTx intent)
|
|
310
|
-
const claimLeafScript = vhtlc.claim();
|
|
311
|
-
const claimScriptByte = claimLeafScript[1];
|
|
312
|
-
// Encode the VHTLC tap tree
|
|
313
|
-
const tapTree = vhtlc.encode();
|
|
314
|
-
logger.info({
|
|
315
|
-
event: "arkade.claim.continue_vtxos_found",
|
|
316
|
-
message: "Found VTXOs for pending Arkade claim",
|
|
317
|
-
data: { totalAmount, vtxoCount: vtxos.length },
|
|
318
|
-
});
|
|
319
|
-
// Build a GetPendingTx intent to ask Arkade for pending transactions
|
|
320
|
-
const now = Math.floor(Date.now() / 1000);
|
|
321
|
-
const intentMessage = {
|
|
322
|
-
type: "get-pending-tx",
|
|
323
|
-
expire_at: now + 120,
|
|
324
|
-
};
|
|
325
|
-
// Build intent inputs from VTXOs
|
|
326
|
-
const pkScriptBytes = hex.decode(vhtlcPkScript);
|
|
327
|
-
const intentInputs = vtxos.map((v) => ({
|
|
328
|
-
txid: hex.decode(v.txid),
|
|
329
|
-
index: v.vout,
|
|
330
|
-
witnessUtxo: {
|
|
331
|
-
script: pkScriptBytes,
|
|
332
|
-
amount: BigInt(v.value),
|
|
333
|
-
},
|
|
334
|
-
tapLeafScript: [claimLeafScript],
|
|
335
|
-
sighashType: SigHash.ALL,
|
|
336
|
-
}));
|
|
337
|
-
// Create the intent proof PSBT
|
|
338
|
-
const intentProof = Intent.create(intentMessage, intentInputs);
|
|
339
|
-
// Set VtxoTaprootTree on each real input (skip input 0 which is the toSpend ref)
|
|
340
|
-
for (let i = 0; i < vtxos.length; i++) {
|
|
341
|
-
setArkPsbtField(intentProof, i + 1, VtxoTaprootTree, tapTree);
|
|
342
|
-
}
|
|
343
|
-
// Set condition witness (preimage) on each real input
|
|
344
|
-
for (let i = 0; i < vtxos.length; i++) {
|
|
345
|
-
setArkPsbtField(intentProof, i + 1, ConditionWitness, [preimageBytes]);
|
|
346
|
-
}
|
|
347
|
-
// Create signer from user's secret key
|
|
348
|
-
const signer = SingleKey.fromHex(userSecretKey);
|
|
349
|
-
const computedPk = await signer.xOnlyPublicKey();
|
|
350
|
-
if (hex.encode(userPkBytes) !== hex.encode(computedPk)) {
|
|
351
|
-
throw new Error(`Signing with wrong key? ${hex.encode(userPkBytes)} vs ${hex.encode(computedPk)}`);
|
|
352
|
-
}
|
|
353
|
-
// Sign the intent proof
|
|
354
|
-
const signedIntentProof = await signer.sign(intentProof);
|
|
355
|
-
const signedIntent = {
|
|
356
|
-
proof: base64.encode(signedIntentProof.toPSBT()),
|
|
357
|
-
message: intentMessage,
|
|
358
|
-
};
|
|
359
|
-
// Fetch pending transactions from Arkade
|
|
360
|
-
const pendingTxs = await arkProvider.getPendingTxs(signedIntent);
|
|
361
|
-
if (pendingTxs.length === 0) {
|
|
362
|
-
throw new Error("No pending transactions found at the VHTLC address. The claim may have already been finalized or was never submitted.");
|
|
363
|
-
}
|
|
364
|
-
logger.info({
|
|
365
|
-
event: "arkade.claim.pending_txs_found",
|
|
366
|
-
message: "Found pending Arkade claim transactions",
|
|
367
|
-
data: { pendingTxCount: pendingTxs.length },
|
|
368
|
-
});
|
|
369
|
-
// Finalize each pending transaction
|
|
370
|
-
let lastResult;
|
|
371
|
-
for (const pendingTx of pendingTxs) {
|
|
372
|
-
const { arkTxid, signedCheckpointTxs } = pendingTx;
|
|
373
|
-
// Sign and finalize checkpoint transactions
|
|
374
|
-
const finalCheckpoints = await Promise.all(signedCheckpointTxs.map(async (c) => {
|
|
375
|
-
const checkpointTx = Transaction.fromPSBT(base64.decode(c));
|
|
376
|
-
// Restore missing witness scripts from the ark tx
|
|
377
|
-
checkpointTx.updateInput(0, {
|
|
378
|
-
witnessScript: claimScriptByte,
|
|
379
|
-
});
|
|
380
|
-
// Inject preimage into all checkpoint inputs
|
|
381
|
-
for (let i = 0; i < checkpointTx.inputsLength; i++) {
|
|
382
|
-
setArkPsbtField(checkpointTx, i, ConditionWitness, [preimageBytes]);
|
|
383
|
-
}
|
|
384
|
-
// Sign input 0 (the checkpoint input)
|
|
385
|
-
const signedCheckpoint = await signer.sign(checkpointTx, [0]);
|
|
386
|
-
return base64.encode(signedCheckpoint.toPSBT());
|
|
387
|
-
}));
|
|
388
|
-
// Finalize the transaction
|
|
389
|
-
try {
|
|
390
|
-
await arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
391
|
-
}
|
|
392
|
-
catch (error) {
|
|
393
|
-
logger.error({
|
|
394
|
-
event: "arkade.claim.continue_finalize_failed",
|
|
395
|
-
message: "Failed to finalize pending Arkade claim",
|
|
396
|
-
error,
|
|
397
|
-
});
|
|
398
|
-
throw error;
|
|
399
|
-
}
|
|
400
|
-
logger.info({
|
|
401
|
-
event: "arkade.claim.finalized",
|
|
402
|
-
message: "Arkade claim finalized",
|
|
403
|
-
data: { arkTxid },
|
|
404
|
-
});
|
|
405
|
-
lastResult = {
|
|
406
|
-
txId: arkTxid,
|
|
407
|
-
claimAmount: totalAmount,
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
if (!lastResult) {
|
|
411
|
-
throw Error("Failed continuing claim");
|
|
412
|
-
}
|
|
413
|
-
// We know lastResult is defined because we checked pendingTxs.length > 0
|
|
414
|
-
return lastResult;
|
|
415
|
-
}
|
|
416
|
-
//# sourceMappingURL=arkade.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ark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
|
3
|
-
*
|
|
4
|
-
* EVM claims use the HTLCErc20 contract's redeem() function which requires
|
|
5
|
-
* all original swap parameters for verification.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Builds the claim data for an EVM swap (Ethereum, Polygon, or Arbitrum).
|
|
9
|
-
*
|
|
10
|
-
* The HTLCErc20 contract requires all original swap parameters for verification:
|
|
11
|
-
* - preimage: The secret whose SHA-256 hash matches the preimageHash
|
|
12
|
-
* - amount: Token amount that was locked
|
|
13
|
-
* - token: ERC20 token address that was locked
|
|
14
|
-
* - sender: Address that created the swap (server)
|
|
15
|
-
* - timelock: Unix timestamp after which sender can refund
|
|
16
|
-
*
|
|
17
|
-
* @param id - The UUID of the swap (not used in contract call, kept for reference).
|
|
18
|
-
* @param secret - The preimage/secret (32-byte hex string, with or without 0x prefix).
|
|
19
|
-
* @param swap - The swap response from the API.
|
|
20
|
-
* @param chain - The target chain for the claim.
|
|
21
|
-
* @returns A ClaimResult with the EVM claim data.
|
|
22
|
-
*/
|
|
23
|
-
export function buildEthereumClaimData(id, secret, swap, chain) {
|
|
24
|
-
const contractAddress = getEvmHtlcAddress(swap);
|
|
25
|
-
if (!contractAddress) {
|
|
26
|
-
return {
|
|
27
|
-
success: false,
|
|
28
|
-
message: "Could not find HTLC contract address in swap response.",
|
|
29
|
-
chain,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// Extract swap parameters needed for redeem()
|
|
33
|
-
const params = getRedeemParams(swap);
|
|
34
|
-
if (!params) {
|
|
35
|
-
return {
|
|
36
|
-
success: false,
|
|
37
|
-
message: "Could not extract redeem parameters from swap response. Missing amount, token, sender, or timelock.",
|
|
38
|
-
chain,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// Normalize the secret - strip any double 0x prefix first
|
|
42
|
-
let normalizedSecret = secret;
|
|
43
|
-
while (normalizedSecret.startsWith("0x0x")) {
|
|
44
|
-
normalizedSecret = normalizedSecret.slice(2);
|
|
45
|
-
}
|
|
46
|
-
normalizedSecret = normalizedSecret.startsWith("0x")
|
|
47
|
-
? normalizedSecret
|
|
48
|
-
: `0x${normalizedSecret}`;
|
|
49
|
-
// Encode the call data for redeem(bytes32,uint256,address,address,uint256)
|
|
50
|
-
const callData = encodeRedeemCallData(normalizedSecret, params.amount, params.token, params.sender, params.timelock);
|
|
51
|
-
return {
|
|
52
|
-
success: true,
|
|
53
|
-
message: `${chain.charAt(0).toUpperCase() + chain.slice(1)} claims require manual execution. Use the provided call data to submit the transaction.`,
|
|
54
|
-
chain,
|
|
55
|
-
ethereumClaimData: {
|
|
56
|
-
contractAddress,
|
|
57
|
-
callData,
|
|
58
|
-
swapId: id, // Keep for reference (not used in contract)
|
|
59
|
-
secret: normalizedSecret,
|
|
60
|
-
functionSignature: "redeem(bytes32 preimage, uint256 amount, address token, address sender, uint256 timelock)",
|
|
61
|
-
// Additional params for manual construction
|
|
62
|
-
amount: params.amount,
|
|
63
|
-
token: params.token,
|
|
64
|
-
sender: params.sender,
|
|
65
|
-
timelock: params.timelock,
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Extracts redeem parameters from a swap response.
|
|
71
|
-
*
|
|
72
|
-
* Note: Lightning-to-EVM and Arkade-to-EVM swaps use the gasless claim path
|
|
73
|
-
* and don't go through this function.
|
|
74
|
-
*/
|
|
75
|
-
function getRedeemParams(swap) {
|
|
76
|
-
// BTC-to-EVM swaps (BtcToEvmSwapResponse) - legacy type
|
|
77
|
-
if ("htlc_address_evm" in swap) {
|
|
78
|
-
// These swaps use different field names - not supported for manual redeem
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
// EVM swaps with the newer field structure
|
|
82
|
-
// Check for the fields we need
|
|
83
|
-
const evmSwap = swap;
|
|
84
|
-
if (evmSwap.evm_expected_sats !== undefined &&
|
|
85
|
-
evmSwap.wbtc_address &&
|
|
86
|
-
evmSwap.server_evm_address &&
|
|
87
|
-
evmSwap.evm_refund_locktime !== undefined) {
|
|
88
|
-
return {
|
|
89
|
-
amount: BigInt(evmSwap.evm_expected_sats),
|
|
90
|
-
token: evmSwap.wbtc_address,
|
|
91
|
-
sender: evmSwap.server_evm_address,
|
|
92
|
-
timelock: BigInt(evmSwap.evm_refund_locktime),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Encodes call data for the redeem(bytes32,uint256,address,address,uint256) function.
|
|
99
|
-
*
|
|
100
|
-
* Function selector: keccak256("redeem(bytes32,uint256,address,address,uint256)")[0:4]
|
|
101
|
-
*
|
|
102
|
-
* @param preimage - The preimage/secret as a bytes32 hex string
|
|
103
|
-
* @param amount - The token amount
|
|
104
|
-
* @param token - The ERC20 token address
|
|
105
|
-
* @param sender - The swap sender (server) address
|
|
106
|
-
* @param timelock - The refund timelock
|
|
107
|
-
* @returns The encoded call data as a hex string with 0x prefix
|
|
108
|
-
*/
|
|
109
|
-
export function encodeRedeemCallData(preimage, amount, token, sender, timelock) {
|
|
110
|
-
// Function selector for redeem(bytes32,uint256,address,address,uint256)
|
|
111
|
-
// keccak256("redeem(bytes32,uint256,address,address,uint256)") = 0xb31597ad
|
|
112
|
-
const selector = "0xb31597ad";
|
|
113
|
-
// Normalize preimage to 32 bytes (64 hex chars)
|
|
114
|
-
const normalizedPreimage = normalizeBytes32(preimage);
|
|
115
|
-
// Encode amount as uint256 (32 bytes, left-padded)
|
|
116
|
-
const encodedAmount = amount.toString(16).padStart(64, "0");
|
|
117
|
-
// Encode addresses as 32 bytes (left-padded with zeros)
|
|
118
|
-
const encodedToken = normalizeAddress(token);
|
|
119
|
-
const encodedSender = normalizeAddress(sender);
|
|
120
|
-
// Encode timelock as uint256 (32 bytes, left-padded)
|
|
121
|
-
const encodedTimelock = timelock.toString(16).padStart(64, "0");
|
|
122
|
-
return `${selector}${normalizedPreimage}${encodedAmount}${encodedToken}${encodedSender}${encodedTimelock}`;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Encodes call data for the legacy claimSwap(bytes32,bytes32) function.
|
|
126
|
-
* @deprecated Use encodeRedeemCallData instead for HTLCErc20 v2 contracts.
|
|
127
|
-
*/
|
|
128
|
-
export function encodeClaimSwapCallData(swapId, secret) {
|
|
129
|
-
// Function selector for claimSwap(bytes32,bytes32)
|
|
130
|
-
// keccak256("claimSwap(bytes32,bytes32)") = 0x84cc315b...
|
|
131
|
-
const selector = "0x84cc315b";
|
|
132
|
-
// Normalize inputs - remove 0x prefix if present and ensure 64 chars (32 bytes)
|
|
133
|
-
const normalizedSwapId = normalizeBytes32(swapId);
|
|
134
|
-
const normalizedSecret = normalizeBytes32(secret);
|
|
135
|
-
return `${selector}${normalizedSwapId}${normalizedSecret}`;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Normalizes a hex string to a 32-byte (64 character) representation.
|
|
139
|
-
* Left-pads with zeros (for secrets/hashes).
|
|
140
|
-
*
|
|
141
|
-
* @param input - Hex string
|
|
142
|
-
* @returns 64-character hex string (without 0x prefix)
|
|
143
|
-
*/
|
|
144
|
-
function normalizeBytes32(input) {
|
|
145
|
-
// Remove 0x prefix if present
|
|
146
|
-
let hex = input.startsWith("0x") ? input.slice(2) : input;
|
|
147
|
-
// Pad to 64 characters (32 bytes) if needed - left pad for hashes
|
|
148
|
-
if (hex.length < 64) {
|
|
149
|
-
hex = hex.padStart(64, "0");
|
|
150
|
-
}
|
|
151
|
-
// Truncate if longer (shouldn't happen for valid inputs)
|
|
152
|
-
if (hex.length > 64) {
|
|
153
|
-
hex = hex.slice(0, 64);
|
|
154
|
-
}
|
|
155
|
-
return hex.toLowerCase();
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Normalizes an Ethereum address to a 32-byte (64 character) representation.
|
|
159
|
-
* Left-pads with zeros (addresses are 20 bytes, need 12 bytes of padding).
|
|
160
|
-
*
|
|
161
|
-
* @param address - Ethereum address (with or without 0x prefix)
|
|
162
|
-
* @returns 64-character hex string (without 0x prefix)
|
|
163
|
-
*/
|
|
164
|
-
function normalizeAddress(address) {
|
|
165
|
-
// Remove 0x prefix if present
|
|
166
|
-
const hex = address.startsWith("0x") ? address.slice(2) : address;
|
|
167
|
-
// Addresses are 20 bytes (40 hex chars), pad to 32 bytes (64 hex chars)
|
|
168
|
-
return hex.padStart(64, "0").toLowerCase();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Converts a UUID to a bytes32 hex string.
|
|
172
|
-
* Removes dashes and right-pads with zeros to make 32 bytes.
|
|
173
|
-
*
|
|
174
|
-
* @param uuid - UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
|
|
175
|
-
* @returns 64-character hex string (without 0x prefix)
|
|
176
|
-
*/
|
|
177
|
-
export function uuidToBytes32(uuid) {
|
|
178
|
-
// Remove dashes and 0x prefix if present
|
|
179
|
-
let hex = uuid.replace(/-/g, "");
|
|
180
|
-
if (hex.startsWith("0x")) {
|
|
181
|
-
hex = hex.slice(2);
|
|
182
|
-
}
|
|
183
|
-
// Right-pad to 64 characters (32 bytes)
|
|
184
|
-
if (hex.length < 64) {
|
|
185
|
-
hex = hex.padEnd(64, "0");
|
|
186
|
-
}
|
|
187
|
-
// Truncate if longer (shouldn't happen for valid UUIDs)
|
|
188
|
-
if (hex.length > 64) {
|
|
189
|
-
hex = hex.slice(0, 64);
|
|
190
|
-
}
|
|
191
|
-
return hex.toLowerCase();
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Gets the EVM HTLC contract address from a swap response.
|
|
195
|
-
*
|
|
196
|
-
* @param swap - The swap response
|
|
197
|
-
* @returns The HTLC contract address or undefined if not found
|
|
198
|
-
*/
|
|
199
|
-
function getEvmHtlcAddress(swap) {
|
|
200
|
-
// Other EVM swap types use evm_htlc_address
|
|
201
|
-
if ("evm_htlc_address" in swap) {
|
|
202
|
-
return swap.evm_htlc_address;
|
|
203
|
-
}
|
|
204
|
-
return undefined;
|
|
205
|
-
}
|
|
206
|
-
//# sourceMappingURL=ethereum.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.js","sourceRoot":"","sources":["../../src/redeem/ethereum.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACpC,EAAU,EACV,MAAc,EACd,IAAqB,EACrB,KAA0C;IAE1C,MAAM,eAAe,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,wDAAwD;YACjE,KAAK;SACN,CAAC;IACJ,CAAC;IAED,8CAA8C;IAC9C,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EACL,qGAAqG;YACvG,KAAK;SACN,CAAC;IACJ,CAAC;IAED,0DAA0D;IAC1D,IAAI,gBAAgB,GAAG,MAAM,CAAC;IAC9B,OAAO,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,gBAAgB,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,gBAAgB,GAAG,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC;QAClD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,KAAK,gBAAgB,EAAE,CAAC;IAE5B,2EAA2E;IAC3E,MAAM,QAAQ,GAAG,oBAAoB,CACnC,gBAAgB,EAChB,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,CAChB,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG,KAA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