@arkade-os/sdk 0.4.53 → 0.4.54
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/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-B69ugeJw.d.cts → ark-acFuA57I.d.cts} +2 -1
- package/dist/{ark-B69ugeJw.d.ts → ark-acFuA57I.d.ts} +2 -1
- package/dist/{asyncStorageTaskQueue-B0SUQMXw.d.cts → asyncStorageTaskQueue-BO3cvMpP.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-DWqxuIAs.d.ts → asyncStorageTaskQueue-DACXtP0I.d.ts} +2 -2
- package/dist/chunk-4EIKOJLD.js +2319 -0
- package/dist/chunk-4EIKOJLD.js.map +1 -0
- package/dist/{chunk-IEMPH7J6.cjs → chunk-53XNU2EL.cjs} +40 -40
- package/dist/{chunk-IEMPH7J6.cjs.map → chunk-53XNU2EL.cjs.map} +1 -1
- package/dist/{chunk-B4WZOJAI.js → chunk-7L3P3EP5.js} +4 -4
- package/dist/{chunk-B4WZOJAI.js.map → chunk-7L3P3EP5.js.map} +1 -1
- package/dist/{chunk-UZLQUWYP.js → chunk-A37WVZ5T.js} +3 -3
- package/dist/{chunk-UZLQUWYP.js.map → chunk-A37WVZ5T.js.map} +1 -1
- package/dist/{chunk-4GB73TRR.cjs → chunk-BYJJIITU.cjs} +17 -17
- package/dist/{chunk-4GB73TRR.cjs.map → chunk-BYJJIITU.cjs.map} +1 -1
- package/dist/{chunk-3YC3LQ2E.cjs → chunk-D5LUPJJP.cjs} +829 -431
- package/dist/chunk-D5LUPJJP.cjs.map +1 -0
- package/dist/chunk-GMUVWKOK.cjs +2407 -0
- package/dist/chunk-GMUVWKOK.cjs.map +1 -0
- package/dist/{chunk-3XWDMLOI.js → chunk-QY2YVFZT.js} +4 -4
- package/dist/{chunk-3XWDMLOI.js.map → chunk-QY2YVFZT.js.map} +1 -1
- package/dist/{chunk-RNMLFY2V.cjs → chunk-RNECH3TA.cjs} +19 -1367
- package/dist/chunk-RNECH3TA.cjs.map +1 -0
- package/dist/{chunk-3MMUKLCI.js → chunk-TEHJCEF3.js} +467 -85
- package/dist/chunk-TEHJCEF3.js.map +1 -0
- package/dist/{chunk-CZTQLA55.cjs → chunk-YRLBZJYO.cjs} +9 -9
- package/dist/{chunk-CZTQLA55.cjs.map → chunk-YRLBZJYO.cjs.map} +1 -1
- package/dist/{chunk-LHYNNDY6.js → chunk-ZOY5JSVA.js} +8 -1327
- package/dist/chunk-ZOY5JSVA.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +8 -8
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-C_Y2YrXC.d.cts → delegate-Ca_wXiYE.d.cts} +1 -1
- package/dist/{delegate-BU-Cpyjw.d.ts → delegate-DjwZZi6L.d.ts} +1 -1
- package/dist/{index-tzAInyiX.d.cts → index-DFfefdpc.d.cts} +2 -2
- package/dist/{index-BWF-C9eh.d.ts → index-Ddq0mIKX.d.ts} +2 -2
- package/dist/index.cjs +315 -243
- package/dist/index.d.cts +298 -12
- package/dist/index.d.ts +298 -12
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-B7svzMhT.d.cts → taskRunner-DEwlrgId.d.cts} +2 -2
- package/dist/{taskRunner-nzJFH8qb.d.ts → taskRunner-DbCNRP31.d.ts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +5 -5
- package/dist/{wallet-CuHAI-eW.d.ts → wallet-B9rpddG2.d.ts} +2 -2
- package/dist/{wallet-B6Xiferv.d.cts → wallet-ByjM6L20.d.cts} +2 -2
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-3MMUKLCI.js.map +0 -1
- package/dist/chunk-3YC3LQ2E.cjs.map +0 -1
- package/dist/chunk-E7HB3GKK.cjs +0 -1030
- package/dist/chunk-E7HB3GKK.cjs.map +0 -1
- package/dist/chunk-EFNLTS6Q.js +0 -976
- package/dist/chunk-EFNLTS6Q.js.map +0 -1
- package/dist/chunk-LHYNNDY6.js.map +0 -1
- package/dist/chunk-RNMLFY2V.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { witnessRefToBytes, validateProgram, toASM, stringifyArtifact, serializeArkadeContractParams, resolveAsm, parseArtifact, getOpcodeValue, getOpcodeName, fromASM, deserializeArkadeContractParams, computeArkadeScriptPublicKey, bytesToASM, asmToBytes, arkadeWitnessHash, arkadeScriptHash, SUPPORTED_PROGRAM_VERSION, OPCODE_VALUES, OPCODE_NAMES, bignum_exports, ArkadeScript, ArkadeProgramScript, ARKADE_OPS, ARKADE_OPCODE_VALUES, ARKADE_OPCODE_NAMES, ARKADE_OPCODES, ARKADE_OP, inputName, contractHandlers, isMainnetDescriptor, descriptorIsOurs, DefaultVtxo, speculativeReceiveMetadata, DelegateVtxo, deriveDescriptorLeafPubKey, WALLET_RECEIVE_SOURCE, BoardingContractHandler } from './chunk-
|
|
3
|
-
import { VtxoScript, isRecoverable, CSVMultisigTapscript, DEFAULT_NETWORK, hasTerminalSpend, getNormalizedVtxos, isVirtualCoin, ArkAddress, sequenceToTimelock, decodeTapscript, scriptFromTapLeafScript, CLTVMultisigTapscript, timelockToSequence, DEFAULT_NETWORK_NAME, normalizeVtxo, getSequence, toBatchExpiry, toOffchainInputFeeParams, canRecoverOnchain, getNetwork, MultisigTapscript, getAllNormalizedVtxos, DEFAULT_PAGE_SIZE, canSpendOffchain, toVirtualStatus, resolveTimeHeight, parseLegacyExpiry, networks as networks$1,
|
|
1
|
+
import { AssetId, AssetGroup, AssetInput, AssetOutput, Metadata, Packet, BufferReader, BufferWriter, AssetRef, RestIndexerProvider } from './chunk-ZOY5JSVA.js';
|
|
2
|
+
import { witnessRefToBytes, validateProgram, toASM, stringifyArtifact, serializeArkadeContractParams, resolveAsm, parseArtifact, getOpcodeValue, getOpcodeName, fromASM, deserializeArkadeContractParams, computeArkadeScriptPublicKey, bytesToASM, asmToBytes, arkadeWitnessHash, arkadeScriptHash, SUPPORTED_PROGRAM_VERSION, OPCODE_VALUES, OPCODE_NAMES, bignum_exports, ArkadeScript, ArkadeProgramScript, ARKADE_OPS, ARKADE_OPCODE_VALUES, ARKADE_OPCODE_NAMES, ARKADE_OPCODES, ARKADE_OP, inputName, contractHandlers, isMainnetDescriptor, descriptorIsOurs, DefaultVtxo, speculativeReceiveMetadata, DelegateVtxo, deriveDescriptorLeafPubKey, WALLET_RECEIVE_SOURCE, BoardingContractHandler } from './chunk-A37WVZ5T.js';
|
|
3
|
+
import { VtxoScript, Transaction, isRecoverable, CSVMultisigTapscript, DEFAULT_NETWORK, hasTerminalSpend, getNormalizedVtxos, setArkPsbtField, PrevArkTxField, ConditionWitness, craftToSpendTx, isVirtualCoin, getArkPsbtFields, CosignerPublicKey, ArkAddress, OP_RETURN_EMPTY_PKSCRIPT, sequenceToTimelock, decodeTapscript, scriptFromTapLeafScript, CLTVMultisigTapscript, VtxoTaprootTree, timelockToSequence, baseFetch, Intent, rateGate, DEFAULT_NETWORK_NAME, normalizeVtxo, getSequence, toBatchExpiry, maybeArkError, isArkError, ArkErrorName, toOffchainInputFeeParams, canRecoverOnchain, getNetwork, MultisigTapscript, isEventSourceError, isRetryableProviderError, getAllNormalizedVtxos, DEFAULT_PAGE_SIZE, RestArkProvider, canSpendOffchain, toVirtualStatus, ArkError, resolveTimeHeight, parseLegacyExpiry, isExpired, DEFAULT_ARKADE_SERVER_URL, ProviderUnavailableError, networks as networks$1, isPastExpiry, fetchVtxoCreatedAtByTxid } from './chunk-4EIKOJLD.js';
|
|
4
4
|
import { __export } from './chunk-NSBPE2FW.js';
|
|
5
5
|
import { sha256, equalBytes, hash160, sha256x2, concatBytes, randomPrivateKeyBytes, pubECDSA, pubSchnorr } from '@scure/btc-signer/utils.js';
|
|
6
6
|
import { SigHash, Script, OP, OutScript, Address, RawWitness, p2tr, p2wpkh, TaprootControlBlock, DEFAULT_SEQUENCE, Transaction as Transaction$2 } from '@scure/btc-signer';
|
|
@@ -25,8 +25,8 @@ function aggregateNonces(pubNonces) {
|
|
|
25
25
|
return musig2.nonceAggregate(pubNonces);
|
|
26
26
|
}
|
|
27
27
|
function aggregateKeys(publicKeys, sort, options = {}) {
|
|
28
|
-
{
|
|
29
|
-
publicKeys = musig2.sortKeys(publicKeys);
|
|
28
|
+
if (sort) {
|
|
29
|
+
publicKeys = musig2.sortKeys([...publicKeys]);
|
|
30
30
|
}
|
|
31
31
|
const { aggPublicKey: preTweakedKey } = musig2.keyAggregate(publicKeys);
|
|
32
32
|
if (!options.taprootTweak) {
|
|
@@ -88,24 +88,27 @@ var PartialSig = class _PartialSig {
|
|
|
88
88
|
return new _PartialSig(bytes, R);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
function
|
|
91
|
+
function createSession(combinedNonce, publicKeys, message, options) {
|
|
92
|
+
const keys = musig2.sortKeys([...publicKeys]) ;
|
|
92
93
|
let tweakBytes;
|
|
93
94
|
if (options?.taprootTweak !== void 0) {
|
|
94
|
-
const { preTweakedKey } = aggregateKeys(
|
|
95
|
-
musig2.sortKeys(publicKeys) );
|
|
95
|
+
const { preTweakedKey } = aggregateKeys(keys, false);
|
|
96
96
|
tweakBytes = schnorr.utils.taggedHash(
|
|
97
97
|
"TapTweak",
|
|
98
98
|
preTweakedKey.subarray(1),
|
|
99
99
|
options.taprootTweak
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
return new musig2.Session(
|
|
103
103
|
combinedNonce,
|
|
104
|
-
|
|
104
|
+
keys,
|
|
105
105
|
message,
|
|
106
106
|
tweakBytes ? [tweakBytes] : void 0,
|
|
107
107
|
tweakBytes ? [true] : void 0
|
|
108
108
|
);
|
|
109
|
+
}
|
|
110
|
+
function sign(secNonce, privateKey, combinedNonce, publicKeys, message, options) {
|
|
111
|
+
const session = createSession(combinedNonce, publicKeys, message, options);
|
|
109
112
|
const partialSig = session.sign(secNonce, privateKey);
|
|
110
113
|
return PartialSig.decode(partialSig);
|
|
111
114
|
}
|
|
@@ -2279,7 +2282,7 @@ function hasBoardingTxExpired(coin, boardingTimelock, chainTipHeight) {
|
|
|
2279
2282
|
function formatSighash(type) {
|
|
2280
2283
|
return `0x${type.toString(16).padStart(2, "0")}`;
|
|
2281
2284
|
}
|
|
2282
|
-
function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [SigHash.DEFAULT]) {
|
|
2285
|
+
function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [SigHash.DEFAULT], expectedLeafHash) {
|
|
2283
2286
|
const input = tx.getInput(inputIndex);
|
|
2284
2287
|
const prevoutScripts = [];
|
|
2285
2288
|
const prevoutAmounts = [];
|
|
@@ -2294,12 +2297,21 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
2294
2297
|
if (!input.tapScriptSig || input.tapScriptSig.length === 0) {
|
|
2295
2298
|
throw new Error(`Input ${inputIndex} is missing tapScriptSig`);
|
|
2296
2299
|
}
|
|
2300
|
+
const expectedLeafHashHex = expectedLeafHash ? hex.encode(expectedLeafHash) : void 0;
|
|
2297
2301
|
for (const [tapScriptSigData, signature] of input.tapScriptSig) {
|
|
2298
2302
|
const pubKey = tapScriptSigData.pubKey;
|
|
2299
2303
|
const pubKeyHex = hex.encode(pubKey);
|
|
2300
2304
|
if (excludePubkeys.includes(pubKeyHex)) {
|
|
2301
2305
|
continue;
|
|
2302
2306
|
}
|
|
2307
|
+
if (expectedLeafHashHex !== void 0) {
|
|
2308
|
+
const signedLeafHex = hex.encode(tapScriptSigData.leafHash);
|
|
2309
|
+
if (signedLeafHex !== expectedLeafHashHex) {
|
|
2310
|
+
throw new Error(
|
|
2311
|
+
`Input ${inputIndex}: signature from ${pubKeyHex} commits to leaf ${signedLeafHex}, expected ${expectedLeafHashHex}`
|
|
2312
|
+
);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2303
2315
|
const sighashType = signature.length === 65 ? signature[64] : SigHash.DEFAULT;
|
|
2304
2316
|
const sig = signature.subarray(0, 64);
|
|
2305
2317
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
@@ -2681,6 +2693,14 @@ function getRandomId() {
|
|
|
2681
2693
|
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
2682
2694
|
return hex.encode(randomValue);
|
|
2683
2695
|
}
|
|
2696
|
+
function isValidArkAddress2(address) {
|
|
2697
|
+
try {
|
|
2698
|
+
ArkAddress.decode(address);
|
|
2699
|
+
return true;
|
|
2700
|
+
} catch (e) {
|
|
2701
|
+
return false;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2684
2704
|
function validateRecipients(recipients, dustAmount) {
|
|
2685
2705
|
const validatedRecipients = [];
|
|
2686
2706
|
for (const recipient of recipients) {
|
|
@@ -4900,11 +4920,6 @@ function createExitChainResolver(params) {
|
|
|
4900
4920
|
return new OrderedExitChainResolver(sources, params.repository);
|
|
4901
4921
|
}
|
|
4902
4922
|
|
|
4903
|
-
// src/providers/availability.ts
|
|
4904
|
-
function isRetryableProviderError(error) {
|
|
4905
|
-
return error instanceof ProviderUnavailableError || error instanceof FetchError || isFetchTimeoutError(error);
|
|
4906
|
-
}
|
|
4907
|
-
|
|
4908
4923
|
// src/utils/syncCursors.ts
|
|
4909
4924
|
var SAFETY_LAG_MS = 3e4;
|
|
4910
4925
|
var OVERLAP_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -5527,8 +5542,20 @@ function subtractAssets(spent, change) {
|
|
|
5527
5542
|
if (map.size === 0) return void 0;
|
|
5528
5543
|
return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
|
|
5529
5544
|
}
|
|
5530
|
-
|
|
5545
|
+
function collectArkTxidsNeedingCreatedAt(vtxos) {
|
|
5546
|
+
const ownTxids = new Set(vtxos.map((v) => v.txid));
|
|
5547
|
+
const txids = /* @__PURE__ */ new Set();
|
|
5548
|
+
for (const vtxo of vtxos) {
|
|
5549
|
+
if (vtxo.isSpent && vtxo.arkTxId && !ownTxids.has(vtxo.arkTxId)) {
|
|
5550
|
+
txids.add(vtxo.arkTxId);
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
return [...txids];
|
|
5554
|
+
}
|
|
5555
|
+
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt) {
|
|
5531
5556
|
const fromOldestVtxo = vtxos.map(normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
5557
|
+
const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(fromOldestVtxo) : [];
|
|
5558
|
+
const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
|
|
5532
5559
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
5533
5560
|
const sent = [];
|
|
5534
5561
|
let received = [];
|
|
@@ -5588,7 +5615,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5588
5615
|
txTime = changes[0].createdAt.getTime();
|
|
5589
5616
|
} else {
|
|
5590
5617
|
txAmount = spentAmount;
|
|
5591
|
-
txTime =
|
|
5618
|
+
txTime = resolvedCreatedAt.get(vtxo.arkTxId) ?? vtxo.createdAt.getTime() + 1;
|
|
5592
5619
|
}
|
|
5593
5620
|
const assets = subtractAssets(allSpent, changes);
|
|
5594
5621
|
if (txAmount !== 0 || assets) {
|
|
@@ -11088,11 +11115,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11088
11115
|
const response = await contractManager.getContractsWithVtxos();
|
|
11089
11116
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
11090
11117
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
11091
|
-
const
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11118
|
+
const resolveTxCreatedAt = (txids) => fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
11119
|
+
return buildTransactionHistory(
|
|
11120
|
+
allVtxos,
|
|
11121
|
+
boardingTxs,
|
|
11122
|
+
commitmentsToIgnore,
|
|
11123
|
+
resolveTxCreatedAt
|
|
11124
|
+
);
|
|
11096
11125
|
}
|
|
11097
11126
|
/**
|
|
11098
11127
|
* Wallet history grouped by registered activity resolvers. With no resolver match,
|
|
@@ -14607,6 +14636,25 @@ var DustChangeError = class extends Error {
|
|
|
14607
14636
|
this.dustAmount = dustAmount;
|
|
14608
14637
|
}
|
|
14609
14638
|
};
|
|
14639
|
+
var offboardNetworkNames = [
|
|
14640
|
+
"bitcoin",
|
|
14641
|
+
"regtest",
|
|
14642
|
+
"testnet",
|
|
14643
|
+
"signet",
|
|
14644
|
+
"mutinynet"
|
|
14645
|
+
];
|
|
14646
|
+
function offboardDestinationScript(destinationAddress) {
|
|
14647
|
+
for (const networkName of offboardNetworkNames) {
|
|
14648
|
+
try {
|
|
14649
|
+
const network = networks$1[networkName];
|
|
14650
|
+
const addr = Address(network).decode(destinationAddress);
|
|
14651
|
+
return OutScript.encode(addr);
|
|
14652
|
+
} catch {
|
|
14653
|
+
continue;
|
|
14654
|
+
}
|
|
14655
|
+
}
|
|
14656
|
+
throw new Error(`Failed to decode destination address: ${destinationAddress}`);
|
|
14657
|
+
}
|
|
14610
14658
|
var Ramps = class {
|
|
14611
14659
|
/**
|
|
14612
14660
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -14744,27 +14792,7 @@ var Ramps = class {
|
|
|
14744
14792
|
throw new DustChangeError(change, dustAmount);
|
|
14745
14793
|
}
|
|
14746
14794
|
amount = amount ?? totalAmount;
|
|
14747
|
-
const
|
|
14748
|
-
"bitcoin",
|
|
14749
|
-
"regtest",
|
|
14750
|
-
"testnet",
|
|
14751
|
-
"signet",
|
|
14752
|
-
"mutinynet"
|
|
14753
|
-
];
|
|
14754
|
-
let destinationScript;
|
|
14755
|
-
for (const networkName of networkNames) {
|
|
14756
|
-
try {
|
|
14757
|
-
const network = networks$1[networkName];
|
|
14758
|
-
const addr = Address(network).decode(destinationAddress);
|
|
14759
|
-
destinationScript = OutScript.encode(addr);
|
|
14760
|
-
break;
|
|
14761
|
-
} catch {
|
|
14762
|
-
continue;
|
|
14763
|
-
}
|
|
14764
|
-
}
|
|
14765
|
-
if (!destinationScript) {
|
|
14766
|
-
throw new Error(`Failed to decode destination address: ${destinationAddress}`);
|
|
14767
|
-
}
|
|
14795
|
+
const destinationScript = offboardDestinationScript(destinationAddress);
|
|
14768
14796
|
const outputFee = estimator.evalOnchainOutput({
|
|
14769
14797
|
amount,
|
|
14770
14798
|
script: hex.encode(destinationScript)
|
|
@@ -15796,47 +15824,15 @@ var WalletMessageHandler = class {
|
|
|
15796
15824
|
return allVtxos;
|
|
15797
15825
|
}
|
|
15798
15826
|
/**
|
|
15799
|
-
* Build transaction history from cached virtual outputs
|
|
15800
|
-
*
|
|
15827
|
+
* Build transaction history from cached virtual outputs, hitting the indexer only for
|
|
15828
|
+
* uncached timestamps. Best-effort, like the plain Wallet path.
|
|
15801
15829
|
*/
|
|
15802
15830
|
async buildTransactionHistoryFromCache(vtxos) {
|
|
15803
15831
|
if (!this.readonlyWallet) return null;
|
|
15804
15832
|
const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
|
|
15805
|
-
const
|
|
15806
|
-
|
|
15807
|
-
|
|
15808
|
-
const ts = vtxo.createdAt.getTime();
|
|
15809
|
-
if (existing === void 0 || ts < existing) {
|
|
15810
|
-
vtxoCreatedAt.set(vtxo.txid, ts);
|
|
15811
|
-
}
|
|
15812
|
-
}
|
|
15813
|
-
if (this.indexerProvider) {
|
|
15814
|
-
const uncachedTxids = /* @__PURE__ */ new Set();
|
|
15815
|
-
for (const vtxo of vtxos) {
|
|
15816
|
-
if (vtxo.isSpent && vtxo.arkTxId && !vtxoCreatedAt.has(vtxo.arkTxId) && !vtxos.some((v) => v.txid === vtxo.arkTxId)) {
|
|
15817
|
-
uncachedTxids.add(vtxo.arkTxId);
|
|
15818
|
-
}
|
|
15819
|
-
}
|
|
15820
|
-
if (uncachedTxids.size > 0) {
|
|
15821
|
-
const outpoints = [...uncachedTxids].map((txid) => ({
|
|
15822
|
-
txid,
|
|
15823
|
-
vout: 0
|
|
15824
|
-
}));
|
|
15825
|
-
const BATCH_SIZE = 100;
|
|
15826
|
-
for (let i = 0; i < outpoints.length; i += BATCH_SIZE) {
|
|
15827
|
-
const res = await getNormalizedVtxos(this.indexerProvider, {
|
|
15828
|
-
outpoints: outpoints.slice(i, i + BATCH_SIZE)
|
|
15829
|
-
});
|
|
15830
|
-
for (const v of res.vtxos) {
|
|
15831
|
-
vtxoCreatedAt.set(v.txid, v.createdAt.getTime());
|
|
15832
|
-
}
|
|
15833
|
-
}
|
|
15834
|
-
}
|
|
15835
|
-
}
|
|
15836
|
-
const getTxCreatedAt = async (txid) => {
|
|
15837
|
-
return vtxoCreatedAt.get(txid);
|
|
15838
|
-
};
|
|
15839
|
-
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, getTxCreatedAt);
|
|
15833
|
+
const indexerProvider = this.indexerProvider;
|
|
15834
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
15835
|
+
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, resolveTxCreatedAt);
|
|
15840
15836
|
}
|
|
15841
15837
|
async ensureContractEventBroadcasting() {
|
|
15842
15838
|
if (!this.readonlyWallet) return;
|
|
@@ -19013,19 +19009,48 @@ async function estimate(opts) {
|
|
|
19013
19009
|
}
|
|
19014
19010
|
|
|
19015
19011
|
// src/wallet/exit/executor.ts
|
|
19012
|
+
function abortErrorFor(signal) {
|
|
19013
|
+
if (signal.reason !== void 0) return signal.reason;
|
|
19014
|
+
const e = new Error("The operation was aborted");
|
|
19015
|
+
e.name = "AbortError";
|
|
19016
|
+
return e;
|
|
19017
|
+
}
|
|
19018
|
+
function throwIfAborted(signal) {
|
|
19019
|
+
if (signal?.aborted) throw abortErrorFor(signal);
|
|
19020
|
+
}
|
|
19016
19021
|
var Executor = class {
|
|
19017
19022
|
constructor(pkg, provider, opts) {
|
|
19018
19023
|
this.pkg = pkg;
|
|
19019
19024
|
this.provider = provider;
|
|
19020
19025
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
19021
19026
|
this.feeWallet = opts?.feeWallet;
|
|
19027
|
+
this.signal = opts?.signal;
|
|
19022
19028
|
}
|
|
19023
19029
|
pkg;
|
|
19024
19030
|
provider;
|
|
19025
19031
|
pollIntervalMs;
|
|
19026
19032
|
feeWallet;
|
|
19033
|
+
signal;
|
|
19034
|
+
/**
|
|
19035
|
+
* Poll delay. Nearly all wall-clock time is spent here, so it must be the
|
|
19036
|
+
* thing that reacts to abort — checking only between polls would leave
|
|
19037
|
+
* cancellation up to a full interval late and the timer still pending.
|
|
19038
|
+
*/
|
|
19027
19039
|
sleep() {
|
|
19028
|
-
|
|
19040
|
+
const signal = this.signal;
|
|
19041
|
+
if (!signal) return new Promise((r) => setTimeout(r, this.pollIntervalMs));
|
|
19042
|
+
return new Promise((resolve, reject) => {
|
|
19043
|
+
if (signal.aborted) return reject(abortErrorFor(signal));
|
|
19044
|
+
const onAbort = () => {
|
|
19045
|
+
clearTimeout(timer);
|
|
19046
|
+
reject(abortErrorFor(signal));
|
|
19047
|
+
};
|
|
19048
|
+
const timer = setTimeout(() => {
|
|
19049
|
+
signal.removeEventListener("abort", onAbort);
|
|
19050
|
+
resolve();
|
|
19051
|
+
}, this.pollIntervalMs);
|
|
19052
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19053
|
+
});
|
|
19029
19054
|
}
|
|
19030
19055
|
async status(txid) {
|
|
19031
19056
|
try {
|
|
@@ -19038,10 +19063,12 @@ var Executor = class {
|
|
|
19038
19063
|
for (; ; ) {
|
|
19039
19064
|
const s = await this.status(txid);
|
|
19040
19065
|
if (s?.confirmed) return s;
|
|
19066
|
+
throwIfAborted(this.signal);
|
|
19041
19067
|
await this.sleep();
|
|
19042
19068
|
}
|
|
19043
19069
|
}
|
|
19044
19070
|
async *[Symbol.asyncIterator]() {
|
|
19071
|
+
throwIfAborted(this.signal);
|
|
19045
19072
|
const dead = /* @__PURE__ */ new Set();
|
|
19046
19073
|
if (this.pkg.validUntil && Date.now() / 1e3 > this.pkg.validUntil) {
|
|
19047
19074
|
yield {
|
|
@@ -19153,6 +19180,7 @@ var Executor = class {
|
|
|
19153
19180
|
while (done.size < pending.length) {
|
|
19154
19181
|
for (const { index, step } of pending) {
|
|
19155
19182
|
if (done.has(index)) continue;
|
|
19183
|
+
throwIfAborted(this.signal);
|
|
19156
19184
|
const swept = await this.status(step.txid);
|
|
19157
19185
|
if (swept?.confirmed) {
|
|
19158
19186
|
done.add(index);
|
|
@@ -20112,6 +20140,360 @@ function attachExtension(tx, newPackets) {
|
|
|
20112
20140
|
}
|
|
20113
20141
|
tx.addOutput({ script: newOut.script, amount: newOut.amount });
|
|
20114
20142
|
}
|
|
20143
|
+
|
|
20144
|
+
// src/utils/bip21.ts
|
|
20145
|
+
var BIP21Error = /* @__PURE__ */ ((BIP21Error2) => {
|
|
20146
|
+
BIP21Error2["INVALID_URI"] = "Invalid BIP21 URI";
|
|
20147
|
+
BIP21Error2["INVALID_ADDRESS"] = "Invalid address";
|
|
20148
|
+
return BIP21Error2;
|
|
20149
|
+
})(BIP21Error || {});
|
|
20150
|
+
var BIP21 = class _BIP21 {
|
|
20151
|
+
/**
|
|
20152
|
+
* Create a BIP21 URI from the provided parameters.
|
|
20153
|
+
*
|
|
20154
|
+
* @param params - BIP21 parameters to encode
|
|
20155
|
+
* @returns Encoded BIP21 URI
|
|
20156
|
+
*/
|
|
20157
|
+
static create(params) {
|
|
20158
|
+
const { address, ...options } = params;
|
|
20159
|
+
const queryParams = {};
|
|
20160
|
+
for (const [key, value] of Object.entries(options)) {
|
|
20161
|
+
if (value === void 0) continue;
|
|
20162
|
+
if (key === "amount") {
|
|
20163
|
+
const amount = value;
|
|
20164
|
+
if (!isFinite(amount) || !Number.isSafeInteger(Math.trunc(amount))) {
|
|
20165
|
+
console.warn("Invalid amount");
|
|
20166
|
+
continue;
|
|
20167
|
+
}
|
|
20168
|
+
if (amount < 0) {
|
|
20169
|
+
continue;
|
|
20170
|
+
}
|
|
20171
|
+
queryParams[key] = value;
|
|
20172
|
+
} else if (key === "ark") {
|
|
20173
|
+
if (typeof value === "string" && (value.startsWith("ark") || value.startsWith("tark"))) {
|
|
20174
|
+
queryParams[key] = value;
|
|
20175
|
+
} else {
|
|
20176
|
+
console.warn("Invalid ARK address format");
|
|
20177
|
+
}
|
|
20178
|
+
} else if (key === "sp") {
|
|
20179
|
+
if (typeof value === "string" && value.startsWith("sp")) {
|
|
20180
|
+
queryParams[key] = value;
|
|
20181
|
+
} else {
|
|
20182
|
+
console.warn("Invalid Silent Payment address format");
|
|
20183
|
+
}
|
|
20184
|
+
} else if (typeof value === "string" || typeof value === "number") {
|
|
20185
|
+
queryParams[key] = value;
|
|
20186
|
+
}
|
|
20187
|
+
}
|
|
20188
|
+
const query = Object.keys(queryParams).length > 0 ? "?" + new URLSearchParams(
|
|
20189
|
+
Object.fromEntries(
|
|
20190
|
+
Object.entries(queryParams).map(([k, v]) => [k, String(v)])
|
|
20191
|
+
)
|
|
20192
|
+
).toString() : "";
|
|
20193
|
+
return `bitcoin:${address ? address.toLowerCase() : ""}${query}`;
|
|
20194
|
+
}
|
|
20195
|
+
/**
|
|
20196
|
+
* Integer-sats amount encoded in a BIP21 URI (`amount=` is BTC), or
|
|
20197
|
+
* `undefined` when absent or the URI is unparseable. Shared by the payment
|
|
20198
|
+
* rails, which accept either a bare address or a BIP21 URI.
|
|
20199
|
+
*
|
|
20200
|
+
* @param uri - BIP21 URI (or bare address) to read the amount from
|
|
20201
|
+
* @returns The amount in satoshis, or `undefined`
|
|
20202
|
+
*/
|
|
20203
|
+
static amountSats(uri) {
|
|
20204
|
+
try {
|
|
20205
|
+
const btc = _BIP21.parse(uri).params.amount;
|
|
20206
|
+
return typeof btc === "number" ? Math.round(btc * 1e8) : void 0;
|
|
20207
|
+
} catch {
|
|
20208
|
+
return void 0;
|
|
20209
|
+
}
|
|
20210
|
+
}
|
|
20211
|
+
/**
|
|
20212
|
+
* Parse a BIP21 URI and return its decoded parameters.
|
|
20213
|
+
*
|
|
20214
|
+
* @param uri - BIP21 URI to parse
|
|
20215
|
+
* @returns Parsed BIP21 URI data
|
|
20216
|
+
* @throws Error if the URI does not start with the `bitcoin:` scheme
|
|
20217
|
+
*/
|
|
20218
|
+
static parse(uri) {
|
|
20219
|
+
if (!uri.toLowerCase().startsWith("bitcoin:")) {
|
|
20220
|
+
throw new Error("Invalid BIP21 URI" /* INVALID_URI */);
|
|
20221
|
+
}
|
|
20222
|
+
const withoutPrefix = uri.slice(uri.toLowerCase().indexOf("bitcoin:") + 8);
|
|
20223
|
+
const [address, query] = withoutPrefix.split("?");
|
|
20224
|
+
const params = {};
|
|
20225
|
+
if (address) {
|
|
20226
|
+
params.address = address.toLowerCase();
|
|
20227
|
+
}
|
|
20228
|
+
if (query) {
|
|
20229
|
+
const queryParams = new URLSearchParams(query);
|
|
20230
|
+
for (const [key, value] of queryParams.entries()) {
|
|
20231
|
+
if (!value) continue;
|
|
20232
|
+
if (key === "amount") {
|
|
20233
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(value)) {
|
|
20234
|
+
continue;
|
|
20235
|
+
}
|
|
20236
|
+
const amount = Number(value);
|
|
20237
|
+
if (!isFinite(amount) || !Number.isSafeInteger(Math.trunc(amount))) {
|
|
20238
|
+
continue;
|
|
20239
|
+
}
|
|
20240
|
+
params[key] = amount;
|
|
20241
|
+
} else if (key === "ark") {
|
|
20242
|
+
if (value.startsWith("ark") || value.startsWith("tark")) {
|
|
20243
|
+
params[key] = value;
|
|
20244
|
+
} else {
|
|
20245
|
+
console.warn("Invalid ARK address format");
|
|
20246
|
+
}
|
|
20247
|
+
} else if (key === "sp") {
|
|
20248
|
+
if (value.startsWith("sp")) {
|
|
20249
|
+
params[key] = value;
|
|
20250
|
+
} else {
|
|
20251
|
+
console.warn("Invalid Silent Payment address format");
|
|
20252
|
+
}
|
|
20253
|
+
} else {
|
|
20254
|
+
params[key] = value;
|
|
20255
|
+
}
|
|
20256
|
+
}
|
|
20257
|
+
}
|
|
20258
|
+
return {
|
|
20259
|
+
originalString: uri,
|
|
20260
|
+
params
|
|
20261
|
+
};
|
|
20262
|
+
}
|
|
20263
|
+
};
|
|
20264
|
+
|
|
20265
|
+
// src/payment/predicates.ts
|
|
20266
|
+
var isLightningInvoice = (raw) => /^ln(bcrt|bc|tbs|tb|sb)[0-9a-z]+$/i.test(raw.replace(/^lightning:/i, ""));
|
|
20267
|
+
var isLnurl = (raw) => /^lnurl/i.test(raw) || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(raw);
|
|
20268
|
+
var BECH32_BTC = /^(bc1|tb1|bcrt1)[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,90}$/;
|
|
20269
|
+
var isBech32Btc = (raw) => (raw === raw.toLowerCase() || raw === raw.toUpperCase()) && BECH32_BTC.test(raw.toLowerCase());
|
|
20270
|
+
var isBtcAddress = (raw) => isBech32Btc(raw) || /^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,39}$/.test(raw);
|
|
20271
|
+
|
|
20272
|
+
// src/payment/targets.ts
|
|
20273
|
+
var fromBip21 = (raw, key, accept) => {
|
|
20274
|
+
try {
|
|
20275
|
+
const v = BIP21.parse(raw).params[key];
|
|
20276
|
+
return typeof v === "string" && accept(v) ? v : void 0;
|
|
20277
|
+
} catch {
|
|
20278
|
+
return void 0;
|
|
20279
|
+
}
|
|
20280
|
+
};
|
|
20281
|
+
var arkTarget = (raw) => isValidArkAddress2(raw) ? raw : fromBip21(raw, "ark", isValidArkAddress2);
|
|
20282
|
+
var btcTarget = (raw) => isBtcAddress(raw) ? raw : fromBip21(raw, "address", isBtcAddress);
|
|
20283
|
+
var invoiceTarget = (raw) => {
|
|
20284
|
+
const invoice = isLightningInvoice(raw) ? raw : fromBip21(raw, "lightning", isLightningInvoice);
|
|
20285
|
+
return invoice?.replace(/^lightning:/i, "");
|
|
20286
|
+
};
|
|
20287
|
+
|
|
20288
|
+
// src/payment/amount.ts
|
|
20289
|
+
function assertSendableAmount(railId, amt) {
|
|
20290
|
+
if (!Number.isInteger(amt) || amt <= 0) {
|
|
20291
|
+
throw new Error(`${railId}: invalid amount ${amt} sats (expected a positive integer)`);
|
|
20292
|
+
}
|
|
20293
|
+
}
|
|
20294
|
+
function resolveSendAmount(railId, raw, amount) {
|
|
20295
|
+
const amt = amount ?? BIP21.amountSats(raw);
|
|
20296
|
+
if (amt === void 0) {
|
|
20297
|
+
throw new Error(
|
|
20298
|
+
`${railId}: an amount is required (none provided or encoded in the request)`
|
|
20299
|
+
);
|
|
20300
|
+
}
|
|
20301
|
+
assertSendableAmount(railId, amt);
|
|
20302
|
+
return amt;
|
|
20303
|
+
}
|
|
20304
|
+
function tryResolveSendAmount(raw, amount) {
|
|
20305
|
+
const amt = amount ?? BIP21.amountSats(raw);
|
|
20306
|
+
return amt !== void 0 && Number.isInteger(amt) && amt > 0 ? amt : void 0;
|
|
20307
|
+
}
|
|
20308
|
+
|
|
20309
|
+
// src/payment/handle.ts
|
|
20310
|
+
function makeHandle(id, run) {
|
|
20311
|
+
let status = "pending";
|
|
20312
|
+
let last = { status };
|
|
20313
|
+
const subs = /* @__PURE__ */ new Set();
|
|
20314
|
+
const notify = (f, u) => {
|
|
20315
|
+
try {
|
|
20316
|
+
f(u);
|
|
20317
|
+
} catch {
|
|
20318
|
+
}
|
|
20319
|
+
};
|
|
20320
|
+
const isTerminal = (s) => s === "settled" || s === "failed";
|
|
20321
|
+
const emit = (u) => {
|
|
20322
|
+
status = u.status;
|
|
20323
|
+
last = u;
|
|
20324
|
+
for (const f of subs) notify(f, u);
|
|
20325
|
+
if (isTerminal(u.status)) subs.clear();
|
|
20326
|
+
};
|
|
20327
|
+
const done = run(emit);
|
|
20328
|
+
done.catch((error) => {
|
|
20329
|
+
if (status !== "settled") emit({ status: "failed", error });
|
|
20330
|
+
});
|
|
20331
|
+
return {
|
|
20332
|
+
id,
|
|
20333
|
+
get status() {
|
|
20334
|
+
return status;
|
|
20335
|
+
},
|
|
20336
|
+
subscribe(fn) {
|
|
20337
|
+
notify(fn, last);
|
|
20338
|
+
if (isTerminal(status)) return () => {
|
|
20339
|
+
};
|
|
20340
|
+
subs.add(fn);
|
|
20341
|
+
return () => subs.delete(fn);
|
|
20342
|
+
},
|
|
20343
|
+
settled(opts) {
|
|
20344
|
+
if (!opts?.timeoutMs) return done;
|
|
20345
|
+
let timer;
|
|
20346
|
+
return Promise.race([
|
|
20347
|
+
done,
|
|
20348
|
+
new Promise((_, rej) => {
|
|
20349
|
+
timer = setTimeout(() => rej(new Error("settle timeout")), opts.timeoutMs);
|
|
20350
|
+
})
|
|
20351
|
+
]).finally(() => clearTimeout(timer));
|
|
20352
|
+
}
|
|
20353
|
+
};
|
|
20354
|
+
}
|
|
20355
|
+
|
|
20356
|
+
// src/payment/router.ts
|
|
20357
|
+
var AmbiguousRouteError = class extends Error {
|
|
20358
|
+
constructor(railIds) {
|
|
20359
|
+
super(`ambiguous route: ${railIds.join(", ")}`);
|
|
20360
|
+
this.railIds = railIds;
|
|
20361
|
+
this.name = "AmbiguousRouteError";
|
|
20362
|
+
}
|
|
20363
|
+
railIds;
|
|
20364
|
+
};
|
|
20365
|
+
var PaymentRouter = class {
|
|
20366
|
+
constructor(ctx) {
|
|
20367
|
+
this.ctx = ctx;
|
|
20368
|
+
}
|
|
20369
|
+
ctx;
|
|
20370
|
+
rails = /* @__PURE__ */ new Map();
|
|
20371
|
+
/** Register a rail (or overwrite one with the same id). */
|
|
20372
|
+
use(rail) {
|
|
20373
|
+
this.rails.set(rail.id, rail);
|
|
20374
|
+
return this;
|
|
20375
|
+
}
|
|
20376
|
+
/** Remove a rail by id. */
|
|
20377
|
+
remove(id) {
|
|
20378
|
+
this.rails.delete(id);
|
|
20379
|
+
return this;
|
|
20380
|
+
}
|
|
20381
|
+
/** Rails matching `req`, filtered by `disabled`/`available()`, ranked by
|
|
20382
|
+
* `priority` (unlisted rails keep insertion order, after listed ones). */
|
|
20383
|
+
async options(req, prefs) {
|
|
20384
|
+
const merged = { ...this.ctx.prefs, ...prefs };
|
|
20385
|
+
const ctx = { ...this.ctx, prefs: merged };
|
|
20386
|
+
const matched = [...this.rails.values()].filter(
|
|
20387
|
+
(rail) => !merged.disabled?.includes(rail.id) && rail.match(req, ctx)
|
|
20388
|
+
);
|
|
20389
|
+
const available = (await Promise.all(
|
|
20390
|
+
matched.map(async (rail) => {
|
|
20391
|
+
try {
|
|
20392
|
+
return await rail.available?.(req, ctx) ?? true ? rail : null;
|
|
20393
|
+
} catch (e) {
|
|
20394
|
+
console.warn(`payment rail "${rail.id}": available() threw`, e);
|
|
20395
|
+
return null;
|
|
20396
|
+
}
|
|
20397
|
+
})
|
|
20398
|
+
)).filter((rail) => rail !== null);
|
|
20399
|
+
const rank = (id) => {
|
|
20400
|
+
const i = merged.priority?.indexOf(id) ?? -1;
|
|
20401
|
+
return i < 0 ? Number.MAX_SAFE_INTEGER : i;
|
|
20402
|
+
};
|
|
20403
|
+
available.sort((a, b) => rank(a.id) - rank(b.id));
|
|
20404
|
+
return available.map((rail) => ({
|
|
20405
|
+
railId: rail.id,
|
|
20406
|
+
quote: () => rail.quote(req, ctx)
|
|
20407
|
+
}));
|
|
20408
|
+
}
|
|
20409
|
+
/** Top-ranked option's quote. Throws when nothing routes, or
|
|
20410
|
+
* {@link AmbiguousRouteError} when `tieBreak` is `"require-choice"` and
|
|
20411
|
+
* more than one option survives. */
|
|
20412
|
+
async route(req, prefs) {
|
|
20413
|
+
const options = await this.options(req, prefs);
|
|
20414
|
+
if (options.length === 0) {
|
|
20415
|
+
throw new Error(`no rail for: ${req.raw}`);
|
|
20416
|
+
}
|
|
20417
|
+
const tieBreak = { ...this.ctx.prefs, ...prefs }.tieBreak ?? "first";
|
|
20418
|
+
if (tieBreak === "require-choice" && options.length > 1) {
|
|
20419
|
+
throw new AmbiguousRouteError(options.map((o) => o.railId));
|
|
20420
|
+
}
|
|
20421
|
+
return options[0].quote();
|
|
20422
|
+
}
|
|
20423
|
+
};
|
|
20424
|
+
|
|
20425
|
+
// src/payment/rails/ark.ts
|
|
20426
|
+
function arkRail() {
|
|
20427
|
+
return {
|
|
20428
|
+
id: "ark",
|
|
20429
|
+
match: (req) => arkTarget(req.raw) !== void 0,
|
|
20430
|
+
quote: async (req, ctx) => {
|
|
20431
|
+
const address = arkTarget(req.raw);
|
|
20432
|
+
const amt = resolveSendAmount("ark", req.raw, req.amount);
|
|
20433
|
+
return {
|
|
20434
|
+
railId: "ark",
|
|
20435
|
+
amount: amt,
|
|
20436
|
+
fee: 0,
|
|
20437
|
+
total: amt,
|
|
20438
|
+
send: async () => makeHandle("ark", async (emit) => {
|
|
20439
|
+
const txid = await ctx.wallet.send({ address, amount: amt });
|
|
20440
|
+
const result = { railId: "ark", txid };
|
|
20441
|
+
emit({ status: "settled", result });
|
|
20442
|
+
return result;
|
|
20443
|
+
})
|
|
20444
|
+
};
|
|
20445
|
+
}
|
|
20446
|
+
};
|
|
20447
|
+
}
|
|
20448
|
+
var GROSS_UP_MAX_ROUNDS = 8;
|
|
20449
|
+
function grossUpOffboard(net, feeInfo, script) {
|
|
20450
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
20451
|
+
const feeAt = (amount) => estimator.evalOnchainOutput({ amount: BigInt(amount), script }).satoshis;
|
|
20452
|
+
let gross = net;
|
|
20453
|
+
for (let i = 0; i < GROSS_UP_MAX_ROUNDS; i++) {
|
|
20454
|
+
const next = net + feeAt(gross);
|
|
20455
|
+
if (next === gross) break;
|
|
20456
|
+
gross = next;
|
|
20457
|
+
}
|
|
20458
|
+
return { gross, fee: gross - net };
|
|
20459
|
+
}
|
|
20460
|
+
function onchainRail() {
|
|
20461
|
+
return {
|
|
20462
|
+
id: "onchain",
|
|
20463
|
+
match: (req) => btcTarget(req.raw) !== void 0,
|
|
20464
|
+
quote: async (req, ctx) => {
|
|
20465
|
+
const address = btcTarget(req.raw);
|
|
20466
|
+
const amt = resolveSendAmount("onchain", req.raw, req.amount);
|
|
20467
|
+
const { fees } = await ctx.wallet.arkProvider.getInfo();
|
|
20468
|
+
const script = hex.encode(offboardDestinationScript(address));
|
|
20469
|
+
const { gross, fee } = grossUpOffboard(amt, fees, script);
|
|
20470
|
+
return {
|
|
20471
|
+
railId: "onchain",
|
|
20472
|
+
amount: amt,
|
|
20473
|
+
fee,
|
|
20474
|
+
total: gross,
|
|
20475
|
+
send: async () => makeHandle("onchain", async (emit) => {
|
|
20476
|
+
const txid = await new Ramps(ctx.wallet).offboard(
|
|
20477
|
+
address,
|
|
20478
|
+
fees,
|
|
20479
|
+
BigInt(gross)
|
|
20480
|
+
);
|
|
20481
|
+
const result = { railId: "onchain", txid };
|
|
20482
|
+
emit({ status: "settled", result });
|
|
20483
|
+
return result;
|
|
20484
|
+
})
|
|
20485
|
+
};
|
|
20486
|
+
}
|
|
20487
|
+
};
|
|
20488
|
+
}
|
|
20489
|
+
|
|
20490
|
+
// src/payment/index.ts
|
|
20491
|
+
function createDefaultPaymentRouter(wallet) {
|
|
20492
|
+
return new PaymentRouter({
|
|
20493
|
+
wallet,
|
|
20494
|
+
prefs: { priority: ["ark", "lightning", "onchain"] }
|
|
20495
|
+
}).use(arkRail()).use(onchainRail());
|
|
20496
|
+
}
|
|
20115
20497
|
var ARKCONTRACT_PREFIX = "arkcontract";
|
|
20116
20498
|
function encodeArkContract(contract) {
|
|
20117
20499
|
const params = new URLSearchParams();
|
|
@@ -20171,6 +20553,6 @@ function isArkContract(str) {
|
|
|
20171
20553
|
return str.startsWith(ARKCONTRACT_PREFIX + "=");
|
|
20172
20554
|
}
|
|
20173
20555
|
|
|
20174
|
-
export { ARKADE_MAGIC, ActivityRegistry, ArkNote, ArkadeCash, ArkadeCashCreateError, AssetManager, BIP322, Batch, ChainedTxType, ContractManager, ContractRepositoryImpl, ContractWatcher, DB_VERSION, DEFAULT_MESSAGE_TIMEOUTS, DelegateManagerImpl, DelegateNotConfiguredError, DelegatorManagerImpl, DelegatorNotConfiguredError, DescriptorSigningProviderMissingError, DustChangeError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EmulatorPacket, EsploraProvider, Estimator, Extension, ExtensionNotFoundError, HDDescriptorProvider, INTENT_TERMINAL_STATES, InMemoryContractRepository, InMemoryIntentRepository, InMemoryVirtualTxRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBIntentRepository, IndexedDBVirtualTxRepository, IndexedDBWalletRepository, MESSAGE_BUS_INITIALIZING, MESSAGE_BUS_NOT_INITIALIZED, MIGRATION_KEY, MessageBus, MessageBusInitializingError, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, P2A, Ramps, ReadonlyAssetManager, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegateProvider, RestDelegatorProvider, RestEmulatorProvider, SeedIdentity, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, TxTree, TxType, TxWeightEstimator, UnilateralExit, UnknownPacket, Unroll, VtxoManager, Wallet2 as Wallet, WalletMessageHandler, WalletNotInitializedError, WalletRepositoryImpl, WsElectrumChainSource, arkade_exports, assertIntentIdUnique, boardingResolver, buildForfeitTx, buildOffchainTx, classifyAgainstSignerSet, classifyContractSigner, closeDatabase, combineTapscriptSigs, contractFromArkContract, contractFromArkContractWithAddress, createAssetPacket, createDefaultActivityRegistry, createExitChainResolver, decodeArkContract, deserializeAssets, deserializeExitPackage, deserializeUtxo, deserializeVtxo, encodeArkContract, extendVirtualCoinForContract, getMigrationStatus, getRandomId, hasBoardingTxExpired, hasCandidates, intentMatchesFilter, intentPageBounds, isArkContract, isBatchSignable, isCooperativelyMigratable, isDiscoverable, isMessageBusInitializingError, isMessageBusNotInitializedError,
|
|
20175
|
-
//# sourceMappingURL=chunk-
|
|
20176
|
-
//# sourceMappingURL=chunk-
|
|
20556
|
+
export { ARKADE_MAGIC, ActivityRegistry, AmbiguousRouteError, ArkNote, ArkadeCash, ArkadeCashCreateError, AssetManager, BIP21, BIP21Error, BIP322, Batch, ChainedTxType, ContractManager, ContractRepositoryImpl, ContractWatcher, DB_VERSION, DEFAULT_MESSAGE_TIMEOUTS, DelegateManagerImpl, DelegateNotConfiguredError, DelegatorManagerImpl, DelegatorNotConfiguredError, DescriptorSigningProviderMissingError, DustChangeError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EmulatorPacket, EsploraProvider, Estimator, Extension, ExtensionNotFoundError, HDDescriptorProvider, INTENT_TERMINAL_STATES, InMemoryContractRepository, InMemoryIntentRepository, InMemoryVirtualTxRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBIntentRepository, IndexedDBVirtualTxRepository, IndexedDBWalletRepository, MESSAGE_BUS_INITIALIZING, MESSAGE_BUS_NOT_INITIALIZED, MIGRATION_KEY, MessageBus, MessageBusInitializingError, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, P2A, PaymentRouter, Ramps, ReadonlyAssetManager, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegateProvider, RestDelegatorProvider, RestEmulatorProvider, SeedIdentity, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, TxTree, TxType, TxWeightEstimator, UnilateralExit, UnknownPacket, Unroll, VtxoManager, Wallet2 as Wallet, WalletMessageHandler, WalletNotInitializedError, WalletRepositoryImpl, WsElectrumChainSource, arkRail, arkTarget, arkade_exports, assertIntentIdUnique, assertSendableAmount, boardingResolver, btcTarget, buildForfeitTx, buildOffchainTx, classifyAgainstSignerSet, classifyContractSigner, closeDatabase, combineTapscriptSigs, contractFromArkContract, contractFromArkContractWithAddress, createAssetPacket, createDefaultActivityRegistry, createDefaultPaymentRouter, createExitChainResolver, decodeArkContract, deserializeAssets, deserializeExitPackage, deserializeUtxo, deserializeVtxo, encodeArkContract, extendVirtualCoinForContract, getMigrationStatus, getRandomId, hasBoardingTxExpired, hasCandidates, intentMatchesFilter, intentPageBounds, invoiceTarget, isArkContract, isBatchSignable, isBtcAddress, isCooperativelyMigratable, isDiscoverable, isLightningInvoice, isLnurl, isMessageBusInitializingError, isMessageBusNotInitializedError, isSubdust, isTerminalIntentState, isValidArkAddress, isVtxoExpiringSoon, isVtxoForScript, makeHandle, mergeChainedTxType, migrateWalletRepository, onchainRail, openDatabase, requiresMigration, resolveSendAmount, rollbackMigration, saveVtxosForContract, scriptFromArkAddress, selectCoinsWithAsset, selectVirtualCoins, serializeAssets, serializeExitPackage, serializeUtxo, serializeVtxo, setupServiceWorker, signerSetFromInfo, toXOnlySignerHex, tryResolveSendAmount, validateConnectorsTxGraph, validateVtxoTxGraph, verifyTapscriptSignatures, waitForIncomingFunds, warnAndFilterVtxosForScript };
|
|
20557
|
+
//# sourceMappingURL=chunk-TEHJCEF3.js.map
|
|
20558
|
+
//# sourceMappingURL=chunk-TEHJCEF3.js.map
|