@gvnrdao/dh-sdk 0.0.279 → 0.0.280
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/browser/dist/browser.js +1 -1
- package/dist/index.js +98 -51
- package/dist/index.mjs +98 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -122414,29 +122414,46 @@ Error data: ${errorData || "none"}`
|
|
|
122414
122414
|
"Content-Type": "application/json",
|
|
122415
122415
|
...await this.getAuthHeader()
|
|
122416
122416
|
};
|
|
122417
|
-
const
|
|
122418
|
-
|
|
122419
|
-
|
|
122420
|
-
|
|
122421
|
-
|
|
122422
|
-
|
|
122423
|
-
|
|
122424
|
-
|
|
122425
|
-
|
|
122426
|
-
|
|
122427
|
-
|
|
122428
|
-
|
|
122429
|
-
|
|
122430
|
-
|
|
122431
|
-
|
|
122432
|
-
|
|
122433
|
-
|
|
122434
|
-
|
|
122435
|
-
|
|
122436
|
-
|
|
122437
|
-
|
|
122417
|
+
const PHASE2_CLIENT_TIMEOUT_MS = 6e4;
|
|
122418
|
+
const abort = new AbortController();
|
|
122419
|
+
const abortTimer = setTimeout(() => abort.abort(), PHASE2_CLIENT_TIMEOUT_MS);
|
|
122420
|
+
let resp;
|
|
122421
|
+
try {
|
|
122422
|
+
resp = await fetch(
|
|
122423
|
+
`${this.config.serviceEndpoint}/api/lit/pending-withdrawals/execute`,
|
|
122424
|
+
{
|
|
122425
|
+
method: "POST",
|
|
122426
|
+
headers,
|
|
122427
|
+
signal: abort.signal,
|
|
122428
|
+
body: JSON.stringify({
|
|
122429
|
+
positionId: envelope.positionId,
|
|
122430
|
+
txid: envelope.txid,
|
|
122431
|
+
vout: envelope.vout,
|
|
122432
|
+
satoshis: envelope.satoshis,
|
|
122433
|
+
targetAddress: envelope.targetAddress,
|
|
122434
|
+
// CRIT-1: send the user-signed targetAmount so the Lit Action can
|
|
122435
|
+
// bind it into its hash recomputation AND cross-check against the
|
|
122436
|
+
// on-chain authorizer record.
|
|
122437
|
+
targetAmount: envelope.targetAmount,
|
|
122438
|
+
networkFee: envelope.networkFee,
|
|
122439
|
+
userSignature: envelope.userSignature,
|
|
122440
|
+
borrowerAddress: envelope.borrowerAddress,
|
|
122441
|
+
chainId: envelope.chainId,
|
|
122442
|
+
timestamp: envelope.timestamp
|
|
122443
|
+
})
|
|
122444
|
+
}
|
|
122445
|
+
);
|
|
122446
|
+
} catch (fetchErr) {
|
|
122447
|
+
if (abort.signal.aborted) {
|
|
122448
|
+
return {
|
|
122449
|
+
success: false,
|
|
122450
|
+
error: "Withdrawal signing timed out. Your withdrawal is still authorized on-chain \u2014 retry Execute from Pending Withdrawals to complete it."
|
|
122451
|
+
};
|
|
122438
122452
|
}
|
|
122439
|
-
|
|
122453
|
+
throw fetchErr;
|
|
122454
|
+
} finally {
|
|
122455
|
+
clearTimeout(abortTimer);
|
|
122456
|
+
}
|
|
122440
122457
|
const json = await resp.json();
|
|
122441
122458
|
if (!json.success || !json.data?.success) {
|
|
122442
122459
|
const errMsg = json.data?.error ?? json.error ?? "BTC broadcast failed";
|
|
@@ -122710,38 +122727,68 @@ Error data: ${errorData || "none"}`
|
|
|
122710
122727
|
error: "chainId required for recoverStaleSpend (set DiamondHandsSDKConfig.chainId)"
|
|
122711
122728
|
};
|
|
122712
122729
|
}
|
|
122713
|
-
|
|
122714
|
-
if (
|
|
122715
|
-
|
|
122716
|
-
|
|
122717
|
-
|
|
122718
|
-
error: "ethRpcUrl required for recoverStaleSpend \u2014 set DiamondHandsSDKConfig.ethRpcUrl or pass rpcUrl"
|
|
122730
|
+
let attRes;
|
|
122731
|
+
if (this.config.mode === "service" && this.config.serviceEndpoint) {
|
|
122732
|
+
const headers = {
|
|
122733
|
+
"Content-Type": "application/json",
|
|
122734
|
+
...await this.getAuthHeader()
|
|
122719
122735
|
};
|
|
122720
|
-
|
|
122721
|
-
|
|
122722
|
-
|
|
122723
|
-
|
|
122724
|
-
|
|
122725
|
-
|
|
122726
|
-
|
|
122727
|
-
|
|
122728
|
-
|
|
122729
|
-
|
|
122730
|
-
|
|
122731
|
-
|
|
122732
|
-
|
|
122736
|
+
const resp = await fetch(
|
|
122737
|
+
`${this.config.serviceEndpoint}/api/lit/stale-spend/recover`,
|
|
122738
|
+
{
|
|
122739
|
+
method: "POST",
|
|
122740
|
+
headers,
|
|
122741
|
+
body: JSON.stringify({
|
|
122742
|
+
positionId: this.toBytes32(params.positionId),
|
|
122743
|
+
utxoTxid: params.utxoTxid,
|
|
122744
|
+
utxoVout: params.utxoVout,
|
|
122745
|
+
invalidatorTxid: params.invalidatorTxid,
|
|
122746
|
+
chainId,
|
|
122747
|
+
...params.minConfirmations !== void 0 && {
|
|
122748
|
+
minConfirmations: params.minConfirmations
|
|
122749
|
+
}
|
|
122750
|
+
})
|
|
122733
122751
|
}
|
|
122734
|
-
|
|
122735
|
-
|
|
122736
|
-
|
|
122737
|
-
|
|
122738
|
-
|
|
122739
|
-
|
|
122740
|
-
|
|
122741
|
-
|
|
122742
|
-
|
|
122752
|
+
);
|
|
122753
|
+
const json = await resp.json();
|
|
122754
|
+
attRes = json.data ?? {
|
|
122755
|
+
success: false,
|
|
122756
|
+
error: json.error ?? "stale-spend recovery request failed"
|
|
122757
|
+
};
|
|
122758
|
+
} else {
|
|
122759
|
+
const rpcUrl = params.rpcUrl ?? this.config.ethRpcUrl;
|
|
122760
|
+
if (!rpcUrl) {
|
|
122761
|
+
return {
|
|
122762
|
+
success: false,
|
|
122763
|
+
failedStep: "config",
|
|
122764
|
+
error: "ethRpcUrl required for recoverStaleSpend \u2014 set DiamondHandsSDKConfig.ethRpcUrl or pass rpcUrl"
|
|
122765
|
+
};
|
|
122743
122766
|
}
|
|
122744
|
-
|
|
122767
|
+
const sdkBitcoinProviderUrl = this.config.bitcoinProviders?.[0]?.url;
|
|
122768
|
+
attRes = await this.litOps.requestStaleSpendRecoveryAttestation({
|
|
122769
|
+
chainId,
|
|
122770
|
+
positionId: this.toBytes32(params.positionId),
|
|
122771
|
+
utxoTxid: params.utxoTxid,
|
|
122772
|
+
utxoVout: params.utxoVout,
|
|
122773
|
+
invalidatorTxid: params.invalidatorTxid,
|
|
122774
|
+
contractAddresses: {
|
|
122775
|
+
PositionManager: contractAddresses.positionManager,
|
|
122776
|
+
BTCSpendAuthorizer: btcSpendAuthorizerAddress,
|
|
122777
|
+
...contractAddresses.bitcoinProviderRegistry && {
|
|
122778
|
+
BitcoinProviderRegistry: contractAddresses.bitcoinProviderRegistry
|
|
122779
|
+
}
|
|
122780
|
+
},
|
|
122781
|
+
rpcUrl,
|
|
122782
|
+
...sdkBitcoinProviderUrl && { bitcoinProviderUrl: sdkBitcoinProviderUrl },
|
|
122783
|
+
// Hardhat (chainId 1337/31337) has no on-chain BitcoinProviderRegistry —
|
|
122784
|
+
// Lit Actions read `devBitcoinProviderUrl` from globalThis. Always pass;
|
|
122785
|
+
// non-hardhat chains ignore it. (Single source of truth: bitcoinProviderUrl.)
|
|
122786
|
+
...sdkBitcoinProviderUrl && { devBitcoinProviderUrl: sdkBitcoinProviderUrl },
|
|
122787
|
+
...params.minConfirmations !== void 0 && {
|
|
122788
|
+
minConfirmations: params.minConfirmations
|
|
122789
|
+
}
|
|
122790
|
+
});
|
|
122791
|
+
}
|
|
122745
122792
|
if (!attRes.success || !attRes.signature || !attRes.attestation) {
|
|
122746
122793
|
return {
|
|
122747
122794
|
success: false,
|
package/dist/index.mjs
CHANGED
|
@@ -122336,29 +122336,46 @@ Error data: ${errorData || "none"}`
|
|
|
122336
122336
|
"Content-Type": "application/json",
|
|
122337
122337
|
...await this.getAuthHeader()
|
|
122338
122338
|
};
|
|
122339
|
-
const
|
|
122340
|
-
|
|
122341
|
-
|
|
122342
|
-
|
|
122343
|
-
|
|
122344
|
-
|
|
122345
|
-
|
|
122346
|
-
|
|
122347
|
-
|
|
122348
|
-
|
|
122349
|
-
|
|
122350
|
-
|
|
122351
|
-
|
|
122352
|
-
|
|
122353
|
-
|
|
122354
|
-
|
|
122355
|
-
|
|
122356
|
-
|
|
122357
|
-
|
|
122358
|
-
|
|
122359
|
-
|
|
122339
|
+
const PHASE2_CLIENT_TIMEOUT_MS = 6e4;
|
|
122340
|
+
const abort = new AbortController();
|
|
122341
|
+
const abortTimer = setTimeout(() => abort.abort(), PHASE2_CLIENT_TIMEOUT_MS);
|
|
122342
|
+
let resp;
|
|
122343
|
+
try {
|
|
122344
|
+
resp = await fetch(
|
|
122345
|
+
`${this.config.serviceEndpoint}/api/lit/pending-withdrawals/execute`,
|
|
122346
|
+
{
|
|
122347
|
+
method: "POST",
|
|
122348
|
+
headers,
|
|
122349
|
+
signal: abort.signal,
|
|
122350
|
+
body: JSON.stringify({
|
|
122351
|
+
positionId: envelope.positionId,
|
|
122352
|
+
txid: envelope.txid,
|
|
122353
|
+
vout: envelope.vout,
|
|
122354
|
+
satoshis: envelope.satoshis,
|
|
122355
|
+
targetAddress: envelope.targetAddress,
|
|
122356
|
+
// CRIT-1: send the user-signed targetAmount so the Lit Action can
|
|
122357
|
+
// bind it into its hash recomputation AND cross-check against the
|
|
122358
|
+
// on-chain authorizer record.
|
|
122359
|
+
targetAmount: envelope.targetAmount,
|
|
122360
|
+
networkFee: envelope.networkFee,
|
|
122361
|
+
userSignature: envelope.userSignature,
|
|
122362
|
+
borrowerAddress: envelope.borrowerAddress,
|
|
122363
|
+
chainId: envelope.chainId,
|
|
122364
|
+
timestamp: envelope.timestamp
|
|
122365
|
+
})
|
|
122366
|
+
}
|
|
122367
|
+
);
|
|
122368
|
+
} catch (fetchErr) {
|
|
122369
|
+
if (abort.signal.aborted) {
|
|
122370
|
+
return {
|
|
122371
|
+
success: false,
|
|
122372
|
+
error: "Withdrawal signing timed out. Your withdrawal is still authorized on-chain \u2014 retry Execute from Pending Withdrawals to complete it."
|
|
122373
|
+
};
|
|
122360
122374
|
}
|
|
122361
|
-
|
|
122375
|
+
throw fetchErr;
|
|
122376
|
+
} finally {
|
|
122377
|
+
clearTimeout(abortTimer);
|
|
122378
|
+
}
|
|
122362
122379
|
const json = await resp.json();
|
|
122363
122380
|
if (!json.success || !json.data?.success) {
|
|
122364
122381
|
const errMsg = json.data?.error ?? json.error ?? "BTC broadcast failed";
|
|
@@ -122632,38 +122649,68 @@ Error data: ${errorData || "none"}`
|
|
|
122632
122649
|
error: "chainId required for recoverStaleSpend (set DiamondHandsSDKConfig.chainId)"
|
|
122633
122650
|
};
|
|
122634
122651
|
}
|
|
122635
|
-
|
|
122636
|
-
if (
|
|
122637
|
-
|
|
122638
|
-
|
|
122639
|
-
|
|
122640
|
-
error: "ethRpcUrl required for recoverStaleSpend \u2014 set DiamondHandsSDKConfig.ethRpcUrl or pass rpcUrl"
|
|
122652
|
+
let attRes;
|
|
122653
|
+
if (this.config.mode === "service" && this.config.serviceEndpoint) {
|
|
122654
|
+
const headers = {
|
|
122655
|
+
"Content-Type": "application/json",
|
|
122656
|
+
...await this.getAuthHeader()
|
|
122641
122657
|
};
|
|
122642
|
-
|
|
122643
|
-
|
|
122644
|
-
|
|
122645
|
-
|
|
122646
|
-
|
|
122647
|
-
|
|
122648
|
-
|
|
122649
|
-
|
|
122650
|
-
|
|
122651
|
-
|
|
122652
|
-
|
|
122653
|
-
|
|
122654
|
-
|
|
122658
|
+
const resp = await fetch(
|
|
122659
|
+
`${this.config.serviceEndpoint}/api/lit/stale-spend/recover`,
|
|
122660
|
+
{
|
|
122661
|
+
method: "POST",
|
|
122662
|
+
headers,
|
|
122663
|
+
body: JSON.stringify({
|
|
122664
|
+
positionId: this.toBytes32(params.positionId),
|
|
122665
|
+
utxoTxid: params.utxoTxid,
|
|
122666
|
+
utxoVout: params.utxoVout,
|
|
122667
|
+
invalidatorTxid: params.invalidatorTxid,
|
|
122668
|
+
chainId,
|
|
122669
|
+
...params.minConfirmations !== void 0 && {
|
|
122670
|
+
minConfirmations: params.minConfirmations
|
|
122671
|
+
}
|
|
122672
|
+
})
|
|
122655
122673
|
}
|
|
122656
|
-
|
|
122657
|
-
|
|
122658
|
-
|
|
122659
|
-
|
|
122660
|
-
|
|
122661
|
-
|
|
122662
|
-
|
|
122663
|
-
|
|
122664
|
-
|
|
122674
|
+
);
|
|
122675
|
+
const json = await resp.json();
|
|
122676
|
+
attRes = json.data ?? {
|
|
122677
|
+
success: false,
|
|
122678
|
+
error: json.error ?? "stale-spend recovery request failed"
|
|
122679
|
+
};
|
|
122680
|
+
} else {
|
|
122681
|
+
const rpcUrl = params.rpcUrl ?? this.config.ethRpcUrl;
|
|
122682
|
+
if (!rpcUrl) {
|
|
122683
|
+
return {
|
|
122684
|
+
success: false,
|
|
122685
|
+
failedStep: "config",
|
|
122686
|
+
error: "ethRpcUrl required for recoverStaleSpend \u2014 set DiamondHandsSDKConfig.ethRpcUrl or pass rpcUrl"
|
|
122687
|
+
};
|
|
122665
122688
|
}
|
|
122666
|
-
|
|
122689
|
+
const sdkBitcoinProviderUrl = this.config.bitcoinProviders?.[0]?.url;
|
|
122690
|
+
attRes = await this.litOps.requestStaleSpendRecoveryAttestation({
|
|
122691
|
+
chainId,
|
|
122692
|
+
positionId: this.toBytes32(params.positionId),
|
|
122693
|
+
utxoTxid: params.utxoTxid,
|
|
122694
|
+
utxoVout: params.utxoVout,
|
|
122695
|
+
invalidatorTxid: params.invalidatorTxid,
|
|
122696
|
+
contractAddresses: {
|
|
122697
|
+
PositionManager: contractAddresses.positionManager,
|
|
122698
|
+
BTCSpendAuthorizer: btcSpendAuthorizerAddress,
|
|
122699
|
+
...contractAddresses.bitcoinProviderRegistry && {
|
|
122700
|
+
BitcoinProviderRegistry: contractAddresses.bitcoinProviderRegistry
|
|
122701
|
+
}
|
|
122702
|
+
},
|
|
122703
|
+
rpcUrl,
|
|
122704
|
+
...sdkBitcoinProviderUrl && { bitcoinProviderUrl: sdkBitcoinProviderUrl },
|
|
122705
|
+
// Hardhat (chainId 1337/31337) has no on-chain BitcoinProviderRegistry —
|
|
122706
|
+
// Lit Actions read `devBitcoinProviderUrl` from globalThis. Always pass;
|
|
122707
|
+
// non-hardhat chains ignore it. (Single source of truth: bitcoinProviderUrl.)
|
|
122708
|
+
...sdkBitcoinProviderUrl && { devBitcoinProviderUrl: sdkBitcoinProviderUrl },
|
|
122709
|
+
...params.minConfirmations !== void 0 && {
|
|
122710
|
+
minConfirmations: params.minConfirmations
|
|
122711
|
+
}
|
|
122712
|
+
});
|
|
122713
|
+
}
|
|
122667
122714
|
if (!attRes.success || !attRes.signature || !attRes.attestation) {
|
|
122668
122715
|
return {
|
|
122669
122716
|
success: false,
|
package/package.json
CHANGED