@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/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 resp = await fetch(
122418
- `${this.config.serviceEndpoint}/api/lit/pending-withdrawals/execute`,
122419
- {
122420
- method: "POST",
122421
- headers,
122422
- body: JSON.stringify({
122423
- positionId: envelope.positionId,
122424
- txid: envelope.txid,
122425
- vout: envelope.vout,
122426
- satoshis: envelope.satoshis,
122427
- targetAddress: envelope.targetAddress,
122428
- // CRIT-1: send the user-signed targetAmount so the Lit Action can
122429
- // bind it into its hash recomputation AND cross-check against the
122430
- // on-chain authorizer record.
122431
- targetAmount: envelope.targetAmount,
122432
- networkFee: envelope.networkFee,
122433
- userSignature: envelope.userSignature,
122434
- borrowerAddress: envelope.borrowerAddress,
122435
- chainId: envelope.chainId,
122436
- timestamp: envelope.timestamp
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
- const rpcUrl = params.rpcUrl ?? this.config.ethRpcUrl;
122714
- if (!rpcUrl) {
122715
- return {
122716
- success: false,
122717
- failedStep: "config",
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
- const sdkBitcoinProviderUrl = this.config.bitcoinProviders?.[0]?.url;
122722
- const attRes = await this.litOps.requestStaleSpendRecoveryAttestation({
122723
- chainId,
122724
- positionId: this.toBytes32(params.positionId),
122725
- utxoTxid: params.utxoTxid,
122726
- utxoVout: params.utxoVout,
122727
- invalidatorTxid: params.invalidatorTxid,
122728
- contractAddresses: {
122729
- PositionManager: contractAddresses.positionManager,
122730
- BTCSpendAuthorizer: btcSpendAuthorizerAddress,
122731
- ...contractAddresses.bitcoinProviderRegistry && {
122732
- BitcoinProviderRegistry: contractAddresses.bitcoinProviderRegistry
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
- rpcUrl,
122736
- ...sdkBitcoinProviderUrl && { bitcoinProviderUrl: sdkBitcoinProviderUrl },
122737
- // Hardhat (chainId 1337/31337) has no on-chain BitcoinProviderRegistry —
122738
- // Lit Actions read `devBitcoinProviderUrl` from globalThis. Always pass;
122739
- // non-hardhat chains ignore it. (Single source of truth: bitcoinProviderUrl.)
122740
- ...sdkBitcoinProviderUrl && { devBitcoinProviderUrl: sdkBitcoinProviderUrl },
122741
- ...params.minConfirmations !== void 0 && {
122742
- minConfirmations: params.minConfirmations
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 resp = await fetch(
122340
- `${this.config.serviceEndpoint}/api/lit/pending-withdrawals/execute`,
122341
- {
122342
- method: "POST",
122343
- headers,
122344
- body: JSON.stringify({
122345
- positionId: envelope.positionId,
122346
- txid: envelope.txid,
122347
- vout: envelope.vout,
122348
- satoshis: envelope.satoshis,
122349
- targetAddress: envelope.targetAddress,
122350
- // CRIT-1: send the user-signed targetAmount so the Lit Action can
122351
- // bind it into its hash recomputation AND cross-check against the
122352
- // on-chain authorizer record.
122353
- targetAmount: envelope.targetAmount,
122354
- networkFee: envelope.networkFee,
122355
- userSignature: envelope.userSignature,
122356
- borrowerAddress: envelope.borrowerAddress,
122357
- chainId: envelope.chainId,
122358
- timestamp: envelope.timestamp
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
- const rpcUrl = params.rpcUrl ?? this.config.ethRpcUrl;
122636
- if (!rpcUrl) {
122637
- return {
122638
- success: false,
122639
- failedStep: "config",
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
- const sdkBitcoinProviderUrl = this.config.bitcoinProviders?.[0]?.url;
122644
- const attRes = await this.litOps.requestStaleSpendRecoveryAttestation({
122645
- chainId,
122646
- positionId: this.toBytes32(params.positionId),
122647
- utxoTxid: params.utxoTxid,
122648
- utxoVout: params.utxoVout,
122649
- invalidatorTxid: params.invalidatorTxid,
122650
- contractAddresses: {
122651
- PositionManager: contractAddresses.positionManager,
122652
- BTCSpendAuthorizer: btcSpendAuthorizerAddress,
122653
- ...contractAddresses.bitcoinProviderRegistry && {
122654
- BitcoinProviderRegistry: contractAddresses.bitcoinProviderRegistry
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
- rpcUrl,
122658
- ...sdkBitcoinProviderUrl && { bitcoinProviderUrl: sdkBitcoinProviderUrl },
122659
- // Hardhat (chainId 1337/31337) has no on-chain BitcoinProviderRegistry —
122660
- // Lit Actions read `devBitcoinProviderUrl` from globalThis. Always pass;
122661
- // non-hardhat chains ignore it. (Single source of truth: bitcoinProviderUrl.)
122662
- ...sdkBitcoinProviderUrl && { devBitcoinProviderUrl: sdkBitcoinProviderUrl },
122663
- ...params.minConfirmations !== void 0 && {
122664
- minConfirmations: params.minConfirmations
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.279",
3
+ "version": "0.0.280",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",