@arkade-os/sdk 0.4.28 → 0.4.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -16
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +4 -4
- package/dist/adapters/expo.d.ts +4 -4
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-TZ1gXAXU.d.cts → ark-ChhTwpLf.d.cts} +73 -61
- package/dist/{ark-TZ1gXAXU.d.ts → ark-ChhTwpLf.d.ts} +73 -61
- package/dist/{asyncStorageTaskQueue-EFqSmYTg.d.cts → asyncStorageTaskQueue-DW1-BpI7.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-Cb1F_Z9s.d.ts → asyncStorageTaskQueue-DZ0nUuEJ.d.ts} +2 -2
- package/dist/{chunk-ADV27S4N.cjs → chunk-6FLL2Q36.cjs} +8 -8
- package/dist/chunk-6FLL2Q36.cjs.map +1 -0
- package/dist/{chunk-ZBUDLTBO.js → chunk-6NWNOLL3.js} +5 -5
- package/dist/chunk-6NWNOLL3.js.map +1 -0
- package/dist/{chunk-CFZMTDWI.js → chunk-ABWRLTX5.js} +6 -5
- package/dist/chunk-ABWRLTX5.js.map +1 -0
- package/dist/{chunk-BQLHADL7.js → chunk-BVP2U66Q.js} +316 -178
- package/dist/chunk-BVP2U66Q.js.map +1 -0
- package/dist/{chunk-ZLO6NETT.cjs → chunk-GDCTOSMV.cjs} +480 -332
- package/dist/chunk-GDCTOSMV.cjs.map +1 -0
- package/dist/{chunk-FG5ACJJW.cjs → chunk-GIGILVVP.cjs} +11 -10
- package/dist/chunk-GIGILVVP.cjs.map +1 -0
- package/dist/{chunk-I3DGUUCT.cjs → chunk-IEO3XDKI.cjs} +28 -28
- package/dist/{chunk-I3DGUUCT.cjs.map → chunk-IEO3XDKI.cjs.map} +1 -1
- package/dist/{chunk-IPX2R7FR.cjs → chunk-PJUFOJ2L.cjs} +7 -7
- package/dist/{chunk-IPX2R7FR.cjs.map → chunk-PJUFOJ2L.cjs.map} +1 -1
- package/dist/{chunk-A3EMF7RN.js → chunk-TH6T23XG.js} +3 -3
- package/dist/{chunk-A3EMF7RN.js.map → chunk-TH6T23XG.js.map} +1 -1
- package/dist/{chunk-HW3JJ323.js → chunk-TU3LVAPX.js} +32 -31
- package/dist/chunk-TU3LVAPX.js.map +1 -0
- package/dist/{chunk-5PG7DV7A.cjs → chunk-WMIPYZSB.cjs} +34 -36
- package/dist/chunk-WMIPYZSB.cjs.map +1 -0
- package/dist/{chunk-T64LAI7L.js → chunk-YA4G7RFB.js} +3 -3
- package/dist/{chunk-T64LAI7L.js.map → chunk-YA4G7RFB.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +6 -6
- 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-aaVGfWsV.d.ts → delegate-4JBUkUhR.d.cts} +2 -2
- package/dist/{delegate-BFZs69hp.d.cts → delegate-DN7RELL1.d.ts} +2 -2
- package/dist/{index-NDla_UoJ.d.ts → index-Cn82bBUu.d.ts} +2 -2
- package/dist/{index-B22cA64m.d.cts → index-DfT5xzgY.d.cts} +2 -2
- package/dist/index.cjs +161 -137
- package/dist/index.d.cts +143 -17
- package/dist/index.d.ts +143 -17
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +13 -13
- package/dist/repositories/realm/index.d.cts +1 -1
- package/dist/repositories/realm/index.d.ts +1 -1
- package/dist/repositories/realm/index.js +4 -4
- package/dist/repositories/sqlite/index.cjs +13 -13
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.js +4 -4
- package/dist/{taskRunner-C6Ff4OaU.d.cts → taskRunner-B-aPfHhK.d.cts} +2 -2
- package/dist/{taskRunner-yvPN8Z0K.d.ts → taskRunner-B-vG08pX.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 +19 -15
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +9 -7
- package/dist/wallet/expo/index.d.ts +9 -7
- package/dist/wallet/expo/index.js +11 -7
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-D9NBRqvC.d.ts → wallet-CCtqT2Wb.d.ts} +19 -15
- package/dist/{wallet-AF-p-OWj.d.cts → wallet-DjgFb_4T.d.cts} +19 -15
- 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-5PG7DV7A.cjs.map +0 -1
- package/dist/chunk-ADV27S4N.cjs.map +0 -1
- package/dist/chunk-BQLHADL7.js.map +0 -1
- package/dist/chunk-CFZMTDWI.js.map +0 -1
- package/dist/chunk-FG5ACJJW.cjs.map +0 -1
- package/dist/chunk-HW3JJ323.js.map +0 -1
- package/dist/chunk-ZBUDLTBO.js.map +0 -1
- package/dist/chunk-ZLO6NETT.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { craftToSpendTx, Transaction, OP_RETURN_EMPTY_PKSCRIPT, Intent, getArkPsbtFields, CosignerPublicKey, setArkPsbtField, VtxoTaprootTree, maybeArkError,
|
|
2
|
-
import { isMainnetDescriptor, descriptorIsOurs, contractHandlers, DelegateVtxo, DefaultVtxo, WALLET_RECEIVE_SOURCE, deriveDescriptorLeafPubKey } from './chunk-
|
|
3
|
-
import { VtxoScript, timelockToSequence,
|
|
4
|
-
import {
|
|
1
|
+
import { craftToSpendTx, Transaction, OP_RETURN_EMPTY_PKSCRIPT, Intent, getArkPsbtFields, CosignerPublicKey, setArkPsbtField, VtxoTaprootTree, maybeArkError, AssetRef, AssetId, AssetOutput, AssetGroup, AssetInput, Packet, Metadata, isEventSourceError, RestArkProvider, RestIndexerProvider, ArkError, BufferReader } from './chunk-6NWNOLL3.js';
|
|
2
|
+
import { isMainnetDescriptor, descriptorIsOurs, contractHandlers, DelegateVtxo, DefaultVtxo, WALLET_RECEIVE_SOURCE, deriveDescriptorLeafPubKey } from './chunk-YA4G7RFB.js';
|
|
3
|
+
import { VtxoScript, timelockToSequence, DEFAULT_NETWORK, DEFAULT_NETWORK_NAME, decodeTapscript, scriptFromTapLeafScript, CLTVMultisigTapscript, ArkAddress, getSequence, CSVMultisigTapscript, getNetwork, MultisigTapscript, networks as networks$1, DEFAULT_ARKADE_SERVER_URL } from './chunk-TU3LVAPX.js';
|
|
4
|
+
import { sha256, hash160, sha256x2, concatBytes, randomPrivateKeyBytes, pubECDSA, pubSchnorr, equalBytes as equalBytes$1 } from '@scure/btc-signer/utils.js';
|
|
5
5
|
import { SigHash, Script, p2tr, RawWitness, Address, OutScript, p2wpkh, TaprootControlBlock, DEFAULT_SEQUENCE, Transaction as Transaction$2 } from '@scure/btc-signer';
|
|
6
6
|
import { hex, base58, base64 } from '@scure/base';
|
|
7
7
|
import * as musig2 from '@scure/btc-signer/musig2.js';
|
|
@@ -938,12 +938,12 @@ async function getActiveServiceWorker(path) {
|
|
|
938
938
|
return serviceWorker;
|
|
939
939
|
}
|
|
940
940
|
|
|
941
|
-
// src/providers/
|
|
942
|
-
var
|
|
941
|
+
// src/providers/delegate.ts
|
|
942
|
+
var RestDelegateProvider = class {
|
|
943
943
|
/**
|
|
944
|
-
* Create a REST
|
|
944
|
+
* Create a REST delegate provider targeting the given base URL.
|
|
945
945
|
*
|
|
946
|
-
* @param url - Base URL of the delegation service
|
|
946
|
+
* @param url - Base URL of the remote delegation service.
|
|
947
947
|
*/
|
|
948
948
|
constructor(url) {
|
|
949
949
|
this.url = url;
|
|
@@ -994,35 +994,13 @@ var RestDelegatorProvider = class {
|
|
|
994
994
|
if (!isDelegateInfo(data)) {
|
|
995
995
|
throw new Error("Invalid delegate info");
|
|
996
996
|
}
|
|
997
|
-
|
|
997
|
+
const delegateAddress = typeof data.delegateAddress === "string" && data.delegateAddress !== "" ? data.delegateAddress : typeof data.delegatorAddress === "string" && data.delegatorAddress !== "" ? data.delegatorAddress : "";
|
|
998
|
+
return { ...data, delegateAddress };
|
|
998
999
|
}
|
|
999
1000
|
};
|
|
1001
|
+
var RestDelegatorProvider = RestDelegateProvider;
|
|
1000
1002
|
function isDelegateInfo(data) {
|
|
1001
|
-
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && "
|
|
1002
|
-
}
|
|
1003
|
-
var getNetwork = (network) => {
|
|
1004
|
-
return networks2[network];
|
|
1005
|
-
};
|
|
1006
|
-
var networks2 = {
|
|
1007
|
-
bitcoin: withArkPrefix(NETWORK, "ark"),
|
|
1008
|
-
testnet: withArkPrefix(TEST_NETWORK, "tark"),
|
|
1009
|
-
signet: withArkPrefix(TEST_NETWORK, "tark"),
|
|
1010
|
-
mutinynet: withArkPrefix(TEST_NETWORK, "tark"),
|
|
1011
|
-
regtest: withArkPrefix(
|
|
1012
|
-
{
|
|
1013
|
-
...TEST_NETWORK,
|
|
1014
|
-
bech32: "bcrt",
|
|
1015
|
-
pubKeyHash: 111,
|
|
1016
|
-
scriptHash: 196
|
|
1017
|
-
},
|
|
1018
|
-
"tark"
|
|
1019
|
-
)
|
|
1020
|
-
};
|
|
1021
|
-
function withArkPrefix(network, prefix) {
|
|
1022
|
-
return {
|
|
1023
|
-
...network,
|
|
1024
|
-
hrp: prefix
|
|
1025
|
-
};
|
|
1003
|
+
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && typeof data.pubkey === "string" && typeof data.fee === "string" && data.pubkey !== "" && data.fee !== "" && (typeof data.delegateAddress === "string" && data.delegateAddress !== "" || typeof data.delegatorAddress === "string" && data.delegatorAddress !== "");
|
|
1026
1004
|
}
|
|
1027
1005
|
|
|
1028
1006
|
// src/providers/onchain.ts
|
|
@@ -1034,7 +1012,7 @@ var ESPLORA_URL = {
|
|
|
1034
1012
|
regtest: "http://localhost:3000"
|
|
1035
1013
|
};
|
|
1036
1014
|
var EsploraProvider = class {
|
|
1037
|
-
constructor(baseUrl, opts) {
|
|
1015
|
+
constructor(baseUrl = ESPLORA_URL[DEFAULT_NETWORK_NAME], opts) {
|
|
1038
1016
|
this.baseUrl = baseUrl;
|
|
1039
1017
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1040
1018
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1695,6 +1673,30 @@ function validateAssetGroupOutput(packet, outputIndex, assetId, expectedAmount)
|
|
|
1695
1673
|
}
|
|
1696
1674
|
}
|
|
1697
1675
|
|
|
1676
|
+
// src/wallet/index.ts
|
|
1677
|
+
var TxType = /* @__PURE__ */ ((TxType2) => {
|
|
1678
|
+
TxType2["TxSent"] = "SENT";
|
|
1679
|
+
TxType2["TxReceived"] = "RECEIVED";
|
|
1680
|
+
return TxType2;
|
|
1681
|
+
})(TxType || {});
|
|
1682
|
+
function isSpendable(vtxo) {
|
|
1683
|
+
return !vtxo.isSpent;
|
|
1684
|
+
}
|
|
1685
|
+
function isRecoverable(vtxo) {
|
|
1686
|
+
return vtxo.virtualStatus.state === "swept" && isSpendable(vtxo);
|
|
1687
|
+
}
|
|
1688
|
+
function isExpired(vtxo) {
|
|
1689
|
+
if (vtxo.virtualStatus.state === "swept") return true;
|
|
1690
|
+
const expiry = vtxo.virtualStatus.batchExpiry;
|
|
1691
|
+
if (!expiry) return false;
|
|
1692
|
+
const expireAt = new Date(expiry);
|
|
1693
|
+
if (expireAt.getFullYear() < 2025) return false;
|
|
1694
|
+
return expiry <= Date.now();
|
|
1695
|
+
}
|
|
1696
|
+
function isSubdust(vtxo, dust) {
|
|
1697
|
+
return vtxo.value < dust;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1698
1700
|
// src/wallet/asset.ts
|
|
1699
1701
|
function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
1700
1702
|
const inputsByAssetId = /* @__PURE__ */ new Map();
|
|
@@ -2241,6 +2243,77 @@ function parseProgram(text, env) {
|
|
|
2241
2243
|
}
|
|
2242
2244
|
return { program, text };
|
|
2243
2245
|
}
|
|
2246
|
+
var DUST_AMOUNT = 546;
|
|
2247
|
+
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
2248
|
+
function getDustAmount(wallet) {
|
|
2249
|
+
return "dustAmount" in wallet ? wallet.dustAmount : FALLBACK_WALLET_DUST_AMOUNT;
|
|
2250
|
+
}
|
|
2251
|
+
function extendCoin(wallet, utxo) {
|
|
2252
|
+
return {
|
|
2253
|
+
...utxo,
|
|
2254
|
+
forfeitTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
2255
|
+
intentTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
2256
|
+
tapTree: wallet.boardingTapscript.encode()
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
function extendVtxoFromContract(vtxo, contract) {
|
|
2260
|
+
const handler = contractHandlers.get(contract.type);
|
|
2261
|
+
if (!handler) {
|
|
2262
|
+
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2263
|
+
}
|
|
2264
|
+
const script = handler.createScript(contract.params);
|
|
2265
|
+
return {
|
|
2266
|
+
...vtxo,
|
|
2267
|
+
forfeitTapLeafScript: script.forfeit(),
|
|
2268
|
+
intentTapLeafScript: script.forfeit(),
|
|
2269
|
+
tapTree: script.encode()
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2272
|
+
function extendVirtualCoinForContract(vtxo, contractOrMap) {
|
|
2273
|
+
const contract = resolveContract(vtxo, contractOrMap);
|
|
2274
|
+
if (!contract) {
|
|
2275
|
+
throw new Error(
|
|
2276
|
+
"extendVirtualCoinForContract: no contract matched vtxo.script \u2014 callers must resolve the owning contract before annotating"
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
return extendVtxoFromContract(vtxo, contract);
|
|
2280
|
+
}
|
|
2281
|
+
function isContractMap(value) {
|
|
2282
|
+
return typeof value.get === "function";
|
|
2283
|
+
}
|
|
2284
|
+
function resolveContract(vtxo, contractOrMap) {
|
|
2285
|
+
if (!contractOrMap) return void 0;
|
|
2286
|
+
if (isContractMap(contractOrMap)) {
|
|
2287
|
+
return contractOrMap.get(vtxo.script);
|
|
2288
|
+
}
|
|
2289
|
+
return contractOrMap;
|
|
2290
|
+
}
|
|
2291
|
+
function getRandomId() {
|
|
2292
|
+
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
2293
|
+
return hex.encode(randomValue);
|
|
2294
|
+
}
|
|
2295
|
+
function validateRecipients(recipients, dustAmount) {
|
|
2296
|
+
const validatedRecipients = [];
|
|
2297
|
+
for (const recipient of recipients) {
|
|
2298
|
+
let address;
|
|
2299
|
+
try {
|
|
2300
|
+
address = ArkAddress.decode(recipient.address);
|
|
2301
|
+
} catch (e) {
|
|
2302
|
+
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2303
|
+
}
|
|
2304
|
+
const amount = recipient.amount || dustAmount;
|
|
2305
|
+
if (amount <= 0) {
|
|
2306
|
+
throw new Error("Amount must be positive");
|
|
2307
|
+
}
|
|
2308
|
+
validatedRecipients.push({
|
|
2309
|
+
address: recipient.address,
|
|
2310
|
+
assets: recipient.assets ?? [],
|
|
2311
|
+
amount,
|
|
2312
|
+
script: amount < dustAmount ? address.subdustPkScript : address.pkScript
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
return validatedRecipients;
|
|
2316
|
+
}
|
|
2244
2317
|
|
|
2245
2318
|
// src/wallet/vtxo-manager.ts
|
|
2246
2319
|
function isSweepCapable(wallet) {
|
|
@@ -2265,7 +2338,7 @@ async function runWithCrossInstanceLock(name, fn) {
|
|
|
2265
2338
|
await fn();
|
|
2266
2339
|
});
|
|
2267
2340
|
}
|
|
2268
|
-
var DEFAULT_THRESHOLD_SECONDS =
|
|
2341
|
+
var DEFAULT_THRESHOLD_SECONDS = 259200;
|
|
2269
2342
|
var DEFAULT_THRESHOLD_MS = DEFAULT_THRESHOLD_SECONDS * 1e3;
|
|
2270
2343
|
var DEFAULT_RENEWAL_CONFIG = {
|
|
2271
2344
|
thresholdMs: DEFAULT_THRESHOLD_MS
|
|
@@ -2276,9 +2349,6 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
2276
2349
|
boardingUtxoSweep: true,
|
|
2277
2350
|
pollIntervalMs: 6e4
|
|
2278
2351
|
};
|
|
2279
|
-
function getDustAmount(wallet) {
|
|
2280
|
-
return "dustAmount" in wallet ? wallet.dustAmount : 330n;
|
|
2281
|
-
}
|
|
2282
2352
|
function getRecoverableVtxos(vtxos, dustAmount) {
|
|
2283
2353
|
return vtxos.filter((vtxo) => {
|
|
2284
2354
|
if (isRecoverable(vtxo)) {
|
|
@@ -2494,7 +2564,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2494
2564
|
* ```typescript
|
|
2495
2565
|
* const wallet = await Wallet.create({
|
|
2496
2566
|
* identity,
|
|
2497
|
-
*
|
|
2567
|
+
* arkProvider: new RestArkProvider(),
|
|
2498
2568
|
* settlementConfig: {
|
|
2499
2569
|
* vtxoThreshold: 86_400 // 24 hours
|
|
2500
2570
|
* },
|
|
@@ -2638,7 +2708,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2638
2708
|
* ```typescript
|
|
2639
2709
|
* const wallet = await Wallet.create({
|
|
2640
2710
|
* identity,
|
|
2641
|
-
*
|
|
2711
|
+
* arkProvider: new RestArkProvider(),
|
|
2642
2712
|
* settlementConfig: {
|
|
2643
2713
|
* boardingUtxoSweep: true,
|
|
2644
2714
|
* },
|
|
@@ -2757,8 +2827,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
2757
2827
|
this.startBoardingUtxoPoll();
|
|
2758
2828
|
}, 1e3);
|
|
2759
2829
|
try {
|
|
2760
|
-
const [
|
|
2761
|
-
this.wallet.
|
|
2830
|
+
const [delegateManager, contractManager, destination] = await Promise.all([
|
|
2831
|
+
this.wallet.getDelegateManager(),
|
|
2762
2832
|
this.wallet.getContractManager(),
|
|
2763
2833
|
this.wallet.getAddress()
|
|
2764
2834
|
]);
|
|
@@ -2788,8 +2858,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
2788
2858
|
console.error("Error renewing VTXOs:", e);
|
|
2789
2859
|
});
|
|
2790
2860
|
}
|
|
2791
|
-
if (
|
|
2792
|
-
|
|
2861
|
+
if (delegateManager) {
|
|
2862
|
+
delegateManager.delegate(event.vtxos, destination).catch((e) => {
|
|
2793
2863
|
console.error("Error delegating VTXOs:", e);
|
|
2794
2864
|
});
|
|
2795
2865
|
}
|
|
@@ -3230,73 +3300,6 @@ function readUInt32BE(array, offset) {
|
|
|
3230
3300
|
function noteTapscript(preimageHash) {
|
|
3231
3301
|
return Script.encode(["SHA256", preimageHash, "EQUAL"]);
|
|
3232
3302
|
}
|
|
3233
|
-
var DUST_AMOUNT = 546;
|
|
3234
|
-
function extendCoin(wallet, utxo) {
|
|
3235
|
-
return {
|
|
3236
|
-
...utxo,
|
|
3237
|
-
forfeitTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
3238
|
-
intentTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
3239
|
-
tapTree: wallet.boardingTapscript.encode()
|
|
3240
|
-
};
|
|
3241
|
-
}
|
|
3242
|
-
function extendVtxoFromContract(vtxo, contract) {
|
|
3243
|
-
const handler = contractHandlers.get(contract.type);
|
|
3244
|
-
if (!handler) {
|
|
3245
|
-
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3246
|
-
}
|
|
3247
|
-
const script = handler.createScript(contract.params);
|
|
3248
|
-
return {
|
|
3249
|
-
...vtxo,
|
|
3250
|
-
forfeitTapLeafScript: script.forfeit(),
|
|
3251
|
-
intentTapLeafScript: script.forfeit(),
|
|
3252
|
-
tapTree: script.encode()
|
|
3253
|
-
};
|
|
3254
|
-
}
|
|
3255
|
-
function extendVirtualCoinForContract(vtxo, contractOrMap) {
|
|
3256
|
-
const contract = resolveContract(vtxo, contractOrMap);
|
|
3257
|
-
if (!contract) {
|
|
3258
|
-
throw new Error(
|
|
3259
|
-
"extendVirtualCoinForContract: no contract matched vtxo.script \u2014 callers must resolve the owning contract before annotating"
|
|
3260
|
-
);
|
|
3261
|
-
}
|
|
3262
|
-
return extendVtxoFromContract(vtxo, contract);
|
|
3263
|
-
}
|
|
3264
|
-
function isContractMap(value) {
|
|
3265
|
-
return typeof value.get === "function";
|
|
3266
|
-
}
|
|
3267
|
-
function resolveContract(vtxo, contractOrMap) {
|
|
3268
|
-
if (!contractOrMap) return void 0;
|
|
3269
|
-
if (isContractMap(contractOrMap)) {
|
|
3270
|
-
return contractOrMap.get(vtxo.script);
|
|
3271
|
-
}
|
|
3272
|
-
return contractOrMap;
|
|
3273
|
-
}
|
|
3274
|
-
function getRandomId() {
|
|
3275
|
-
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
3276
|
-
return hex.encode(randomValue);
|
|
3277
|
-
}
|
|
3278
|
-
function validateRecipients(recipients, dustAmount) {
|
|
3279
|
-
const validatedRecipients = [];
|
|
3280
|
-
for (const recipient of recipients) {
|
|
3281
|
-
let address;
|
|
3282
|
-
try {
|
|
3283
|
-
address = ArkAddress.decode(recipient.address);
|
|
3284
|
-
} catch (e) {
|
|
3285
|
-
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
3286
|
-
}
|
|
3287
|
-
const amount = recipient.amount || dustAmount;
|
|
3288
|
-
if (amount <= 0) {
|
|
3289
|
-
throw new Error("Amount must be positive");
|
|
3290
|
-
}
|
|
3291
|
-
validatedRecipients.push({
|
|
3292
|
-
address: recipient.address,
|
|
3293
|
-
assets: recipient.assets ?? [],
|
|
3294
|
-
amount,
|
|
3295
|
-
script: amount < dustAmount ? address.subdustPkScript : address.pkScript
|
|
3296
|
-
});
|
|
3297
|
-
}
|
|
3298
|
-
return validatedRecipients;
|
|
3299
|
-
}
|
|
3300
3303
|
var TxTree = class {
|
|
3301
3304
|
constructor(root, children = /* @__PURE__ */ new Map()) {
|
|
3302
3305
|
this.root = root;
|
|
@@ -4070,15 +4073,15 @@ function castMetadata(metadata) {
|
|
|
4070
4073
|
}
|
|
4071
4074
|
return md;
|
|
4072
4075
|
}
|
|
4073
|
-
var
|
|
4074
|
-
/** Create a
|
|
4075
|
-
constructor(
|
|
4076
|
-
this.
|
|
4076
|
+
var DelegateManagerImpl = class {
|
|
4077
|
+
/** Create a delegate manager from the configured provider, Arkade info source, and wallet identity. */
|
|
4078
|
+
constructor(delegateProvider, arkInfoProvider, identity) {
|
|
4079
|
+
this.delegateProvider = delegateProvider;
|
|
4077
4080
|
this.arkInfoProvider = arkInfoProvider;
|
|
4078
4081
|
this.identity = identity;
|
|
4079
4082
|
}
|
|
4080
4083
|
async getDelegateInfo() {
|
|
4081
|
-
return this.
|
|
4084
|
+
return this.delegateProvider.getDelegateInfo();
|
|
4082
4085
|
}
|
|
4083
4086
|
async delegate(vtxos, destination, delegateAt) {
|
|
4084
4087
|
if (vtxos.length === 0) {
|
|
@@ -4086,7 +4089,7 @@ var DelegatorManagerImpl = class {
|
|
|
4086
4089
|
}
|
|
4087
4090
|
const destinationScript = ArkAddress.decode(destination).pkScript;
|
|
4088
4091
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
4089
|
-
const delegateInfo = await this.
|
|
4092
|
+
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
4090
4093
|
const eligible = vtxos.filter(
|
|
4091
4094
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
4092
4095
|
);
|
|
@@ -4097,7 +4100,7 @@ var DelegatorManagerImpl = class {
|
|
|
4097
4100
|
try {
|
|
4098
4101
|
await delegate(
|
|
4099
4102
|
this.identity,
|
|
4100
|
-
this.
|
|
4103
|
+
this.delegateProvider,
|
|
4101
4104
|
arkInfo,
|
|
4102
4105
|
delegateInfo,
|
|
4103
4106
|
eligible,
|
|
@@ -4128,7 +4131,7 @@ var DelegatorManagerImpl = class {
|
|
|
4128
4131
|
try {
|
|
4129
4132
|
await delegate(
|
|
4130
4133
|
this.identity,
|
|
4131
|
-
this.
|
|
4134
|
+
this.delegateProvider,
|
|
4132
4135
|
arkInfo,
|
|
4133
4136
|
delegateInfo,
|
|
4134
4137
|
recoverableVtxos,
|
|
@@ -4153,7 +4156,7 @@ var DelegatorManagerImpl = class {
|
|
|
4153
4156
|
groupsList.map(
|
|
4154
4157
|
async ([, vtxosGroup]) => delegate(
|
|
4155
4158
|
this.identity,
|
|
4156
|
-
this.
|
|
4159
|
+
this.delegateProvider,
|
|
4157
4160
|
arkInfo,
|
|
4158
4161
|
delegateInfo,
|
|
4159
4162
|
vtxosGroup,
|
|
@@ -4174,12 +4177,13 @@ var DelegatorManagerImpl = class {
|
|
|
4174
4177
|
return { delegated, failed };
|
|
4175
4178
|
}
|
|
4176
4179
|
};
|
|
4177
|
-
|
|
4180
|
+
var DelegatorManagerImpl = DelegateManagerImpl;
|
|
4181
|
+
async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos, destinationScript, delegateAt) {
|
|
4178
4182
|
if (vtxos.length === 0) {
|
|
4179
4183
|
throw new Error("unable to delegate: no vtxos provided");
|
|
4180
4184
|
}
|
|
4181
|
-
if (!
|
|
4182
|
-
throw new Error("unable to delegate:
|
|
4185
|
+
if (!delegateProvider) {
|
|
4186
|
+
throw new Error("unable to delegate: delegate provider not configured");
|
|
4183
4187
|
}
|
|
4184
4188
|
if (!delegateAt) {
|
|
4185
4189
|
const expiryTimestamp = vtxos.filter((coin) => !isRecoverable(coin) && coin.virtualStatus.batchExpiry).reduce(
|
|
@@ -4225,13 +4229,14 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4225
4229
|
}
|
|
4226
4230
|
amount += BigInt(coin.value) - BigInt(inputFee.value);
|
|
4227
4231
|
}
|
|
4228
|
-
const {
|
|
4232
|
+
const { pubkey, fee } = delegateInfo;
|
|
4233
|
+
const delegateAddress = delegateInfo.delegateAddress;
|
|
4229
4234
|
const outputs = [];
|
|
4230
|
-
const
|
|
4231
|
-
if (
|
|
4235
|
+
const delegateFee = BigInt(Number(fee));
|
|
4236
|
+
if (delegateFee > 0n) {
|
|
4232
4237
|
outputs.push({
|
|
4233
|
-
script: ArkAddress.decode(
|
|
4234
|
-
amount:
|
|
4238
|
+
script: ArkAddress.decode(delegateAddress).pkScript,
|
|
4239
|
+
amount: delegateFee
|
|
4235
4240
|
});
|
|
4236
4241
|
}
|
|
4237
4242
|
const outputFee = outputs.reduce((fee2, output) => {
|
|
@@ -4245,7 +4250,7 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4245
4250
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
4246
4251
|
}
|
|
4247
4252
|
amount -= BigInt(outputFee);
|
|
4248
|
-
amount -=
|
|
4253
|
+
amount -= delegateFee;
|
|
4249
4254
|
if (amount <= dust) {
|
|
4250
4255
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
4251
4256
|
}
|
|
@@ -4277,7 +4282,7 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4277
4282
|
return base64.encode(forfeit.toPSBT());
|
|
4278
4283
|
})
|
|
4279
4284
|
);
|
|
4280
|
-
await
|
|
4285
|
+
await delegateProvider.delegate(registerIntent, forfeits);
|
|
4281
4286
|
}
|
|
4282
4287
|
async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, forfeitOutputScript, identity) {
|
|
4283
4288
|
const delegateTapLeaf = findDelegateTapLeaf(input, delegatePubkey);
|
|
@@ -7722,7 +7727,7 @@ function hasToReadonly(identity) {
|
|
|
7722
7727
|
return typeof identity === "object" && identity !== null && "toReadonly" in identity && typeof identity.toReadonly === "function";
|
|
7723
7728
|
}
|
|
7724
7729
|
var ReadonlyWallet = class _ReadonlyWallet {
|
|
7725
|
-
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository,
|
|
7730
|
+
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, walletContractTimelocks) {
|
|
7726
7731
|
this.identity = identity;
|
|
7727
7732
|
this.network = network;
|
|
7728
7733
|
this.onchainProvider = onchainProvider;
|
|
@@ -7732,7 +7737,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7732
7737
|
this.dustAmount = dustAmount;
|
|
7733
7738
|
this.walletRepository = walletRepository;
|
|
7734
7739
|
this.contractRepository = contractRepository;
|
|
7735
|
-
this.
|
|
7740
|
+
this.delegateProvider = delegateProvider;
|
|
7736
7741
|
if ("descriptor" in identity) {
|
|
7737
7742
|
const descriptor = identity.descriptor;
|
|
7738
7743
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -7786,7 +7791,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7786
7791
|
*/
|
|
7787
7792
|
static async setupWalletConfig(config, pubKey) {
|
|
7788
7793
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
7789
|
-
const arkProvider = config.arkProvider
|
|
7794
|
+
const arkProvider = config.arkProvider || new RestArkProvider(arkadeServerUrl);
|
|
7790
7795
|
let indexerProvider = config.indexerProvider;
|
|
7791
7796
|
if (!indexerProvider) {
|
|
7792
7797
|
let indexerUrl = config.indexerUrl;
|
|
@@ -7847,7 +7852,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7847
7852
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
7848
7853
|
};
|
|
7849
7854
|
const serverPubKey = hex.decode(info.signerPubkey).slice(1);
|
|
7850
|
-
const delegatePubKey = config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => hex.decode(info2.pubkey).slice(1)) : void 0;
|
|
7855
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => hex.decode(info2.pubkey).slice(1)) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => hex.decode(info2.pubkey).slice(1)) : void 0;
|
|
7851
7856
|
const offchainOptions = {
|
|
7852
7857
|
pubKey,
|
|
7853
7858
|
serverPubKey,
|
|
@@ -7873,7 +7878,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7873
7878
|
walletRepository,
|
|
7874
7879
|
contractRepository,
|
|
7875
7880
|
info,
|
|
7876
|
-
|
|
7881
|
+
delegateProvider: config.delegateProvider || config.delegatorProvider,
|
|
7882
|
+
/** @deprecated alias for `delegateProvider` */
|
|
7883
|
+
delegatorProvider: config.delegateProvider || config.delegatorProvider,
|
|
7877
7884
|
walletContractTimelocks
|
|
7878
7885
|
};
|
|
7879
7886
|
}
|
|
@@ -7900,7 +7907,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7900
7907
|
setup.dustAmount,
|
|
7901
7908
|
setup.walletRepository,
|
|
7902
7909
|
setup.contractRepository,
|
|
7903
|
-
setup.delegatorProvider,
|
|
7910
|
+
setup.delegateProvider || setup.delegatorProvider,
|
|
7904
7911
|
config.watcherConfig,
|
|
7905
7912
|
setup.walletContractTimelocks
|
|
7906
7913
|
);
|
|
@@ -8315,7 +8322,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8315
8322
|
}
|
|
8316
8323
|
};
|
|
8317
8324
|
var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
8318
|
-
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig,
|
|
8325
|
+
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig, delegateProvider, watcherConfig, settlementConfig, walletContractTimelocks, receiveRotator, descriptorProvider) {
|
|
8319
8326
|
super(
|
|
8320
8327
|
identity,
|
|
8321
8328
|
network,
|
|
@@ -8327,7 +8334,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8327
8334
|
dustAmount,
|
|
8328
8335
|
walletRepository,
|
|
8329
8336
|
contractRepository,
|
|
8330
|
-
|
|
8337
|
+
delegateProvider,
|
|
8331
8338
|
watcherConfig,
|
|
8332
8339
|
walletContractTimelocks
|
|
8333
8340
|
);
|
|
@@ -8352,7 +8359,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8352
8359
|
} else {
|
|
8353
8360
|
this.settlementConfig = { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
8354
8361
|
}
|
|
8355
|
-
this.
|
|
8362
|
+
this._delegateManager = delegateProvider ? new DelegateManagerImpl(delegateProvider, arkProvider, identity) : void 0;
|
|
8356
8363
|
this._receiveRotator = receiveRotator;
|
|
8357
8364
|
this._descriptorProvider = descriptorProvider;
|
|
8358
8365
|
this._signerRouter = new InputSignerRouter({
|
|
@@ -8365,7 +8372,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8365
8372
|
static MIN_FEE_RATE = 1;
|
|
8366
8373
|
// sats/vbyte
|
|
8367
8374
|
identity;
|
|
8368
|
-
|
|
8375
|
+
_delegateManager;
|
|
8369
8376
|
_vtxoManager;
|
|
8370
8377
|
_vtxoManagerInitializing;
|
|
8371
8378
|
_walletAssetManager;
|
|
@@ -8574,7 +8581,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8574
8581
|
* ```typescript
|
|
8575
8582
|
* const wallet = await Wallet.create({
|
|
8576
8583
|
* identity,
|
|
8577
|
-
*
|
|
8584
|
+
* arkProvider: new RestArkProvider(),
|
|
8578
8585
|
* });
|
|
8579
8586
|
* ```
|
|
8580
8587
|
*/
|
|
@@ -8611,7 +8618,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8611
8618
|
setup.walletRepository,
|
|
8612
8619
|
setup.contractRepository,
|
|
8613
8620
|
config.renewalConfig,
|
|
8614
|
-
config.delegatorProvider,
|
|
8621
|
+
config.delegateProvider || config.delegatorProvider,
|
|
8615
8622
|
config.watcherConfig,
|
|
8616
8623
|
config.settlementConfig,
|
|
8617
8624
|
setup.walletContractTimelocks,
|
|
@@ -8651,14 +8658,18 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8651
8658
|
this.dustAmount,
|
|
8652
8659
|
this.walletRepository,
|
|
8653
8660
|
this.contractRepository,
|
|
8654
|
-
this.
|
|
8661
|
+
this.delegateProvider,
|
|
8655
8662
|
this.watcherConfig,
|
|
8656
8663
|
this.walletContractTimelocks
|
|
8657
8664
|
);
|
|
8658
8665
|
}
|
|
8659
|
-
/** Returns the
|
|
8666
|
+
/** Returns the delegate manager when delegation support is configured. */
|
|
8667
|
+
async getDelegateManager() {
|
|
8668
|
+
return this._delegateManager;
|
|
8669
|
+
}
|
|
8670
|
+
/** @deprecated alias for @see Wallet.getDelegateManager */
|
|
8660
8671
|
async getDelegatorManager() {
|
|
8661
|
-
return this.
|
|
8672
|
+
return this.getDelegateManager();
|
|
8662
8673
|
}
|
|
8663
8674
|
/**
|
|
8664
8675
|
* Send bitcoin to an Arkade address.
|
|
@@ -9914,7 +9925,7 @@ var MessageBus = class {
|
|
|
9914
9925
|
walletRepository: this.walletRepository,
|
|
9915
9926
|
contractRepository: this.contractRepository
|
|
9916
9927
|
};
|
|
9917
|
-
const
|
|
9928
|
+
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : config.delegatorUrl ? new RestDelegateProvider(config.delegatorUrl) : void 0;
|
|
9918
9929
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
9919
9930
|
if (isSigningSerialized(serialized)) {
|
|
9920
9931
|
const identity2 = hydrateIdentity(serialized);
|
|
@@ -9925,7 +9936,7 @@ var MessageBus = class {
|
|
|
9925
9936
|
indexerUrl: config.indexerUrl,
|
|
9926
9937
|
esploraUrl: config.esploraUrl,
|
|
9927
9938
|
storage,
|
|
9928
|
-
|
|
9939
|
+
delegateProvider,
|
|
9929
9940
|
settlementConfig: config.settlementConfig,
|
|
9930
9941
|
walletMode: config.walletMode,
|
|
9931
9942
|
watcherConfig: config.watcherConfig
|
|
@@ -9940,7 +9951,7 @@ var MessageBus = class {
|
|
|
9940
9951
|
indexerUrl: config.indexerUrl,
|
|
9941
9952
|
esploraUrl: config.esploraUrl,
|
|
9942
9953
|
storage,
|
|
9943
|
-
|
|
9954
|
+
delegateProvider,
|
|
9944
9955
|
watcherConfig: config.watcherConfig
|
|
9945
9956
|
});
|
|
9946
9957
|
return { readonlyWallet, arkProvider };
|
|
@@ -10219,6 +10230,18 @@ var MessageBus = class {
|
|
|
10219
10230
|
function toError(value) {
|
|
10220
10231
|
return value instanceof Error ? value : new Error(String(value));
|
|
10221
10232
|
}
|
|
10233
|
+
var DustChangeError = class extends Error {
|
|
10234
|
+
change;
|
|
10235
|
+
dustAmount;
|
|
10236
|
+
constructor(change, dustAmount) {
|
|
10237
|
+
super(
|
|
10238
|
+
`change ${change} sats is below dust threshold ${dustAmount}; consider exiting the full balance`
|
|
10239
|
+
);
|
|
10240
|
+
this.name = "DustChangeError";
|
|
10241
|
+
this.change = change;
|
|
10242
|
+
this.dustAmount = dustAmount;
|
|
10243
|
+
}
|
|
10244
|
+
};
|
|
10222
10245
|
var Ramps = class {
|
|
10223
10246
|
/**
|
|
10224
10247
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -10356,6 +10379,10 @@ var Ramps = class {
|
|
|
10356
10379
|
}
|
|
10357
10380
|
change = totalAmount - amount;
|
|
10358
10381
|
}
|
|
10382
|
+
const dustAmount = getDustAmount(this.wallet);
|
|
10383
|
+
if (change > 0n && change < dustAmount) {
|
|
10384
|
+
throw new DustChangeError(change, dustAmount);
|
|
10385
|
+
}
|
|
10359
10386
|
amount = amount ?? totalAmount;
|
|
10360
10387
|
const networkNames = [
|
|
10361
10388
|
"bitcoin",
|
|
@@ -10367,7 +10394,7 @@ var Ramps = class {
|
|
|
10367
10394
|
let destinationScript;
|
|
10368
10395
|
for (const networkName of networkNames) {
|
|
10369
10396
|
try {
|
|
10370
|
-
const network =
|
|
10397
|
+
const network = networks$1[networkName];
|
|
10371
10398
|
const addr = Address(network).decode(destinationAddress);
|
|
10372
10399
|
destinationScript = OutScript.encode(addr);
|
|
10373
10400
|
break;
|
|
@@ -10418,18 +10445,47 @@ var WalletNotInitializedError = class extends Error {
|
|
|
10418
10445
|
this.name = "WalletNotInitializedError";
|
|
10419
10446
|
}
|
|
10420
10447
|
};
|
|
10448
|
+
function isSerializedAggregateError(value) {
|
|
10449
|
+
if (!value || typeof value !== "object") return false;
|
|
10450
|
+
const v = value;
|
|
10451
|
+
return v.name === "AggregateError" && typeof v.message === "string" && Array.isArray(v.errors) && v.errors.every((e) => e && typeof e.name === "string" && typeof e.message === "string");
|
|
10452
|
+
}
|
|
10453
|
+
function serializeAggregateError(error) {
|
|
10454
|
+
const errors = [];
|
|
10455
|
+
for (const child of error.errors ?? []) {
|
|
10456
|
+
if (child instanceof Error) {
|
|
10457
|
+
errors.push({ name: child.name, message: child.message });
|
|
10458
|
+
} else {
|
|
10459
|
+
errors.push({ name: "Error", message: String(child) });
|
|
10460
|
+
}
|
|
10461
|
+
}
|
|
10462
|
+
return {
|
|
10463
|
+
name: "AggregateError",
|
|
10464
|
+
message: error.message,
|
|
10465
|
+
errors
|
|
10466
|
+
};
|
|
10467
|
+
}
|
|
10468
|
+
function deserializeAggregateError(payload) {
|
|
10469
|
+
const errs = payload.errors.map((e) => {
|
|
10470
|
+
const err = new Error(e.message);
|
|
10471
|
+
err.name = e.name;
|
|
10472
|
+
return err;
|
|
10473
|
+
});
|
|
10474
|
+
return new AggregateError(errs, payload.message);
|
|
10475
|
+
}
|
|
10421
10476
|
var ReadonlyWalletError = class extends Error {
|
|
10422
10477
|
constructor() {
|
|
10423
10478
|
super("Read-only wallet: operation requires signing");
|
|
10424
10479
|
this.name = "ReadonlyWalletError";
|
|
10425
10480
|
}
|
|
10426
10481
|
};
|
|
10427
|
-
var
|
|
10482
|
+
var DelegateNotConfiguredError = class extends Error {
|
|
10428
10483
|
constructor() {
|
|
10429
|
-
super("
|
|
10430
|
-
this.name = "
|
|
10484
|
+
super("Delegate not configured");
|
|
10485
|
+
this.name = "DelegateNotConfiguredError";
|
|
10431
10486
|
}
|
|
10432
10487
|
};
|
|
10488
|
+
var DelegatorNotConfiguredError = DelegateNotConfiguredError;
|
|
10433
10489
|
var DEFAULT_MESSAGE_TAG = "WALLET_UPDATER";
|
|
10434
10490
|
var WalletMessageHandler = class {
|
|
10435
10491
|
messageTag;
|
|
@@ -10512,7 +10568,10 @@ var WalletMessageHandler = class {
|
|
|
10512
10568
|
// page-side PING / MESSAGE_BUS_NOT_INITIALIZED path triggered by concurrent
|
|
10513
10569
|
// short requests (GET_STATUS, GET_BALANCE, ...).
|
|
10514
10570
|
isLongRunning(message) {
|
|
10515
|
-
return message.type === "SETTLE" || message.type === "RECOVER_VTXOS" || message.type === "RENEW_VTXOS"
|
|
10571
|
+
return message.type === "SETTLE" || message.type === "RECOVER_VTXOS" || message.type === "RENEW_VTXOS" || // HD restore walks the index range with one indexer round-trip per
|
|
10572
|
+
// step until it hits gapLimit consecutive unused indices. The bus
|
|
10573
|
+
// deadline must not race the scan; liveness stays covered by PING.
|
|
10574
|
+
message.type === "RESTORE_WALLET";
|
|
10516
10575
|
}
|
|
10517
10576
|
async handleMessage(message) {
|
|
10518
10577
|
const id = message.id;
|
|
@@ -10781,11 +10840,11 @@ var WalletMessageHandler = class {
|
|
|
10781
10840
|
}
|
|
10782
10841
|
case "GET_DELEGATE_INFO": {
|
|
10783
10842
|
const wallet = this.requireWallet();
|
|
10784
|
-
const
|
|
10785
|
-
if (!
|
|
10786
|
-
throw new
|
|
10843
|
+
const delegateManager = await wallet.getDelegateManager();
|
|
10844
|
+
if (!delegateManager) {
|
|
10845
|
+
throw new DelegateNotConfiguredError();
|
|
10787
10846
|
}
|
|
10788
|
-
const info = await
|
|
10847
|
+
const info = await delegateManager.getDelegateInfo();
|
|
10789
10848
|
return this.tagged({
|
|
10790
10849
|
id,
|
|
10791
10850
|
type: "DELEGATE_INFO",
|
|
@@ -10875,6 +10934,24 @@ var WalletMessageHandler = class {
|
|
|
10875
10934
|
payload: { txid }
|
|
10876
10935
|
});
|
|
10877
10936
|
}
|
|
10937
|
+
case "RESTORE_WALLET": {
|
|
10938
|
+
const wallet = this.requireWallet();
|
|
10939
|
+
try {
|
|
10940
|
+
await wallet.restore(message.payload);
|
|
10941
|
+
} catch (error) {
|
|
10942
|
+
if (error instanceof AggregateError) {
|
|
10943
|
+
return this.tagged({
|
|
10944
|
+
id,
|
|
10945
|
+
error: serializeAggregateError(error)
|
|
10946
|
+
});
|
|
10947
|
+
}
|
|
10948
|
+
throw error;
|
|
10949
|
+
}
|
|
10950
|
+
return this.tagged({
|
|
10951
|
+
id,
|
|
10952
|
+
type: "RESTORE_WALLET_SUCCESS"
|
|
10953
|
+
});
|
|
10954
|
+
}
|
|
10878
10955
|
default:
|
|
10879
10956
|
console.error("Unknown message type", message);
|
|
10880
10957
|
throw new Error("Unknown message");
|
|
@@ -11129,15 +11206,15 @@ var WalletMessageHandler = class {
|
|
|
11129
11206
|
}
|
|
11130
11207
|
async handleDelegate(message) {
|
|
11131
11208
|
const wallet = this.requireWallet();
|
|
11132
|
-
const
|
|
11133
|
-
if (!
|
|
11134
|
-
throw new
|
|
11209
|
+
const delegateManager = await wallet.getDelegateManager();
|
|
11210
|
+
if (!delegateManager) {
|
|
11211
|
+
throw new DelegateNotConfiguredError();
|
|
11135
11212
|
}
|
|
11136
11213
|
const { vtxoOutpoints, destination, delegateAt } = message.payload;
|
|
11137
11214
|
const allVtxos = await wallet.getVtxos();
|
|
11138
11215
|
const outpointSet = new Set(vtxoOutpoints.map((o) => `${o.txid}:${o.vout}`));
|
|
11139
11216
|
const filtered = allVtxos.filter((v) => outpointSet.has(`${v.txid}:${v.vout}`)).map((v) => ({ ...v, contractScript: v.script }));
|
|
11140
|
-
const result = await
|
|
11217
|
+
const result = await delegateManager.delegate(
|
|
11141
11218
|
filtered,
|
|
11142
11219
|
destination,
|
|
11143
11220
|
delegateAt !== void 0 ? new Date(delegateAt) : void 0
|
|
@@ -11344,6 +11421,10 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
11344
11421
|
RECOVER_VTXOS: 5e4,
|
|
11345
11422
|
RENEW_VTXOS: 5e4,
|
|
11346
11423
|
SWEEP_EXPIRED_BOARDING_UTXOS: 5e4,
|
|
11424
|
+
// RESTORE_WALLET is a streaming/long-running path (sendMessageWithEvents)
|
|
11425
|
+
// like SETTLE; the value here is kept for type completeness and is never
|
|
11426
|
+
// enforced as an inactivity deadline.
|
|
11427
|
+
RESTORE_WALLET: 5e4,
|
|
11347
11428
|
// Misc writes
|
|
11348
11429
|
INIT_WALLET: 3e4,
|
|
11349
11430
|
CLEAR: 1e4,
|
|
@@ -11485,6 +11566,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11485
11566
|
// these immediately after construction.
|
|
11486
11567
|
arkServerUrl;
|
|
11487
11568
|
arkServerPublicKey;
|
|
11569
|
+
delegateUrl;
|
|
11570
|
+
/** @deprecated alias for @see ServiceWorkerReadonlyWallet.delegateUrl */
|
|
11488
11571
|
delegatorUrl;
|
|
11489
11572
|
indexerUrl;
|
|
11490
11573
|
esploraUrl;
|
|
@@ -11523,7 +11606,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11523
11606
|
key: { publicKey },
|
|
11524
11607
|
arkServerUrl: getArkadeServerUrl(options),
|
|
11525
11608
|
arkServerPublicKey: options.arkServerPublicKey,
|
|
11526
|
-
|
|
11609
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
11610
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11611
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11612
|
+
// a newer version.
|
|
11613
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
11527
11614
|
};
|
|
11528
11615
|
const messageTimeouts = options.messageTimeouts ? {
|
|
11529
11616
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -11535,7 +11622,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11535
11622
|
url: getArkadeServerUrl(options),
|
|
11536
11623
|
publicKey: options.arkServerPublicKey
|
|
11537
11624
|
},
|
|
11538
|
-
|
|
11625
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
11626
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11627
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11628
|
+
// a newer version.
|
|
11629
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
11539
11630
|
indexerUrl: options.indexerUrl,
|
|
11540
11631
|
esploraUrl: options.esploraUrl,
|
|
11541
11632
|
watcherConfig: options.watcherConfig,
|
|
@@ -11757,7 +11848,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11757
11848
|
url: this.arkServerUrl,
|
|
11758
11849
|
publicKey: this.arkServerPublicKey
|
|
11759
11850
|
},
|
|
11760
|
-
|
|
11851
|
+
delegateUrl: this.delegateUrl || this.delegatorUrl,
|
|
11852
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11853
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11854
|
+
// a newer version.
|
|
11855
|
+
delegatorUrl: this.delegateUrl || this.delegatorUrl,
|
|
11761
11856
|
indexerUrl: this.indexerUrl,
|
|
11762
11857
|
esploraUrl: this.esploraUrl,
|
|
11763
11858
|
watcherConfig: this.watcherConfig,
|
|
@@ -12126,7 +12221,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
12126
12221
|
}
|
|
12127
12222
|
};
|
|
12128
12223
|
var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
|
|
12129
|
-
constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag,
|
|
12224
|
+
constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag, hasDelegate) {
|
|
12130
12225
|
super(serviceWorker, identity, walletRepository, contractRepository, messageTag);
|
|
12131
12226
|
this.serviceWorker = serviceWorker;
|
|
12132
12227
|
this.identity = identity;
|
|
@@ -12136,13 +12231,13 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12136
12231
|
(msg) => this.sendMessage(msg),
|
|
12137
12232
|
messageTag
|
|
12138
12233
|
);
|
|
12139
|
-
this.
|
|
12234
|
+
this.hasDelegate = hasDelegate;
|
|
12140
12235
|
}
|
|
12141
12236
|
walletRepository;
|
|
12142
12237
|
contractRepository;
|
|
12143
12238
|
identity;
|
|
12144
12239
|
_assetManager;
|
|
12145
|
-
|
|
12240
|
+
hasDelegate;
|
|
12146
12241
|
get assetManager() {
|
|
12147
12242
|
return this._assetManager;
|
|
12148
12243
|
}
|
|
@@ -12166,14 +12261,18 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12166
12261
|
walletRepository,
|
|
12167
12262
|
contractRepository,
|
|
12168
12263
|
messageTag,
|
|
12169
|
-
!!options.delegatorUrl
|
|
12264
|
+
!!(options.delegateUrl || options.delegatorUrl)
|
|
12170
12265
|
);
|
|
12171
12266
|
const legacyPrivateKey = serializedWallet.type === "single-key" ? serializedWallet.privateKey : null;
|
|
12172
12267
|
const initWalletPayload = {
|
|
12173
12268
|
key: legacyPrivateKey ? { privateKey: legacyPrivateKey } : {},
|
|
12174
12269
|
arkServerUrl: getArkadeServerUrl(options),
|
|
12175
12270
|
arkServerPublicKey: options.arkServerPublicKey,
|
|
12176
|
-
|
|
12271
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
12272
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
12273
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
12274
|
+
// a newer version.
|
|
12275
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
12177
12276
|
};
|
|
12178
12277
|
const messageTimeouts = options.messageTimeouts ? {
|
|
12179
12278
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -12185,7 +12284,11 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12185
12284
|
url: getArkadeServerUrl(options),
|
|
12186
12285
|
publicKey: options.arkServerPublicKey
|
|
12187
12286
|
},
|
|
12188
|
-
|
|
12287
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
12288
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
12289
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
12290
|
+
// a newer version.
|
|
12291
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
12189
12292
|
indexerUrl: options.indexerUrl,
|
|
12190
12293
|
esploraUrl: options.esploraUrl,
|
|
12191
12294
|
settlementConfig: options.settlementConfig,
|
|
@@ -12266,6 +12369,38 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12266
12369
|
throw new Error(`Settlement failed: ${error}`);
|
|
12267
12370
|
}
|
|
12268
12371
|
}
|
|
12372
|
+
/**
|
|
12373
|
+
* Explicitly recover this wallet's contracts and balance on a fresh repo.
|
|
12374
|
+
* Mirrors {@link Wallet.restore} but drives the scan inside the service
|
|
12375
|
+
* worker — the materialize() callback used by `scanContracts` cannot
|
|
12376
|
+
* cross the postMessage boundary, so the entire flow runs worker-side
|
|
12377
|
+
* and only the gapLimit / outcome cross the wire.
|
|
12378
|
+
*
|
|
12379
|
+
* Uses the streaming send path so the bus deadline does not race a
|
|
12380
|
+
* long indexer-bound scan. AggregateError thrown by the worker is
|
|
12381
|
+
* reconstructed here so callers can inspect `.errors`.
|
|
12382
|
+
*/
|
|
12383
|
+
async restore(opts) {
|
|
12384
|
+
const message = {
|
|
12385
|
+
id: getRandomId(),
|
|
12386
|
+
tag: this.messageTag,
|
|
12387
|
+
type: "RESTORE_WALLET",
|
|
12388
|
+
payload: opts ?? {}
|
|
12389
|
+
};
|
|
12390
|
+
try {
|
|
12391
|
+
await this.sendMessageWithEvents(
|
|
12392
|
+
message,
|
|
12393
|
+
() => {
|
|
12394
|
+
},
|
|
12395
|
+
(resp) => resp.type === "RESTORE_WALLET_SUCCESS"
|
|
12396
|
+
);
|
|
12397
|
+
} catch (error) {
|
|
12398
|
+
if (isSerializedAggregateError(error)) {
|
|
12399
|
+
throw deserializeAggregateError(error);
|
|
12400
|
+
}
|
|
12401
|
+
throw error;
|
|
12402
|
+
}
|
|
12403
|
+
}
|
|
12269
12404
|
async send(...recipients) {
|
|
12270
12405
|
const message = {
|
|
12271
12406
|
tag: this.messageTag,
|
|
@@ -12280,8 +12415,8 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12280
12415
|
throw new Error(`Send failed: ${error}`);
|
|
12281
12416
|
}
|
|
12282
12417
|
}
|
|
12283
|
-
async
|
|
12284
|
-
if (!this.
|
|
12418
|
+
async getDelegateManager() {
|
|
12419
|
+
if (!this.hasDelegate) {
|
|
12285
12420
|
return void 0;
|
|
12286
12421
|
}
|
|
12287
12422
|
const wallet = this;
|
|
@@ -12331,6 +12466,10 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12331
12466
|
};
|
|
12332
12467
|
return manager;
|
|
12333
12468
|
}
|
|
12469
|
+
/** @deprecated alias for @see ServiceWorkerWallet.getDelegateManager */
|
|
12470
|
+
async getDelegatorManager() {
|
|
12471
|
+
return await this.getDelegateManager();
|
|
12472
|
+
}
|
|
12334
12473
|
async getVtxoManager() {
|
|
12335
12474
|
const wallet = this;
|
|
12336
12475
|
const messageTag = this.messageTag;
|
|
@@ -12454,7 +12593,6 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
12454
12593
|
* @param networkName - Bitcoin network name, @see NetworkName
|
|
12455
12594
|
* @param provider - Optional onchain provider override, @see OnchainProvider
|
|
12456
12595
|
* @returns Configured onchain wallet
|
|
12457
|
-
* @defaultValue `provider = new EsploraProvider('https://mempool.space/api')`
|
|
12458
12596
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
12459
12597
|
*/
|
|
12460
12598
|
static async create(identity, networkName = DEFAULT_NETWORK_NAME, provider) {
|
|
@@ -13780,7 +13918,7 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
13780
13918
|
metadata: options.metadata
|
|
13781
13919
|
};
|
|
13782
13920
|
}
|
|
13783
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
13921
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = DEFAULT_NETWORK.hrp, options = {}) {
|
|
13784
13922
|
const parsed = decodeArkContract(encoded);
|
|
13785
13923
|
const handler = contractHandlers.getOrThrow(parsed.type);
|
|
13786
13924
|
const params = parsed.data;
|
|
@@ -13800,6 +13938,6 @@ function isArkContract(str) {
|
|
|
13800
13938
|
return str.startsWith(ARKCONTRACT_PREFIX + "=");
|
|
13801
13939
|
}
|
|
13802
13940
|
|
|
13803
|
-
export { ArkNote, BIP322, Batch, ContractManager, ContractRepositoryImpl, ContractWatcher, DB_VERSION, DEFAULT_MESSAGE_TIMEOUTS, DelegatorManagerImpl, DelegatorNotConfiguredError, DescriptorSigningProviderMissingError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EsploraProvider, Estimator, HDDescriptorProvider, InMemoryContractRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBWalletRepository, MESSAGE_BUS_NOT_INITIALIZED, MIGRATION_KEY, MessageBus, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, P2A, Ramps, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegatorProvider, SeedIdentity, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, TxTree, TxWeightEstimator, Unroll, VtxoManager, Wallet2 as Wallet, WalletMessageHandler, WalletNotInitializedError, WalletRepositoryImpl, WsElectrumChainSource, buildForfeitTx, buildOffchainTx, closeDatabase, combineTapscriptSigs, contractFromArkContract, contractFromArkContractWithAddress, decodeArkContract, deserializeAssets, deserializeUtxo, deserializeVtxo, encodeArkContract, extendVirtualCoinForContract, getMigrationStatus, getRandomId, hasBoardingTxExpired, isArkContract, isBatchSignable, isDiscoverable, isValidArkAddress, isVtxoExpiringSoon, isVtxoForScript, migrateWalletRepository,
|
|
13804
|
-
//# sourceMappingURL=chunk-
|
|
13805
|
-
//# sourceMappingURL=chunk-
|
|
13941
|
+
export { ArkNote, AssetManager, BIP322, Batch, ContractManager, ContractRepositoryImpl, ContractWatcher, DB_VERSION, DEFAULT_MESSAGE_TIMEOUTS, DelegateManagerImpl, DelegateNotConfiguredError, DelegatorManagerImpl, DelegatorNotConfiguredError, DescriptorSigningProviderMissingError, DustChangeError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EsploraProvider, Estimator, HDDescriptorProvider, InMemoryContractRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBWalletRepository, MESSAGE_BUS_NOT_INITIALIZED, MIGRATION_KEY, MessageBus, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, P2A, Ramps, ReadonlyAssetManager, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegateProvider, RestDelegatorProvider, SeedIdentity, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, TxTree, TxType, TxWeightEstimator, Unroll, VtxoManager, Wallet2 as Wallet, WalletMessageHandler, WalletNotInitializedError, WalletRepositoryImpl, WsElectrumChainSource, buildForfeitTx, buildOffchainTx, closeDatabase, combineTapscriptSigs, contractFromArkContract, contractFromArkContractWithAddress, decodeArkContract, deserializeAssets, deserializeUtxo, deserializeVtxo, encodeArkContract, extendVirtualCoinForContract, getMigrationStatus, getRandomId, hasBoardingTxExpired, isArkContract, isBatchSignable, isDiscoverable, isExpired, isRecoverable, isSpendable, isSubdust, isValidArkAddress, isVtxoExpiringSoon, isVtxoForScript, migrateWalletRepository, openDatabase, requiresMigration, rollbackMigration, saveVtxosForContract, scriptFromArkAddress, serializeAssets, serializeUtxo, serializeVtxo, setupServiceWorker, validateConnectorsTxGraph, validateVtxoTxGraph, verifyTapscriptSignatures, waitForIncomingFunds, warnAndFilterVtxosForScript };
|
|
13942
|
+
//# sourceMappingURL=chunk-BVP2U66Q.js.map
|
|
13943
|
+
//# sourceMappingURL=chunk-BVP2U66Q.js.map
|