@gvnrdao/dh-sdk 0.0.279 → 0.0.281

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.mjs CHANGED
@@ -3964,9 +3964,9 @@ var init_deployment_addresses = __esm({
3964
3964
  };
3965
3965
  LOCALHOST_DEPLOYMENT = {
3966
3966
  network: "localhost",
3967
- chainId: 31337,
3968
- timestamp: "2026-03-23T15:33:34.068Z",
3969
- deployer: "",
3967
+ chainId: 1337,
3968
+ timestamp: "2026-06-15T13:32:40.927Z",
3969
+ deployer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
3970
3970
  contracts: {
3971
3971
  MessageHashBuilder: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
3972
3972
  UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
@@ -3975,15 +3975,13 @@ var init_deployment_addresses = __esm({
3975
3975
  PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
3976
3976
  TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
3977
3977
  LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
3978
- BTCSpendAuthorizer: "0x59b670e9fA9D0A427751Af201D676719a970857b",
3979
- CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
3980
- LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
3978
+ BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
3979
+ CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
3980
+ LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
3981
3981
  CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
3982
- AdminModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
3982
+ AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
3983
3983
  PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
3984
- PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
3985
- OperationAuthorizationRegistry: "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0",
3986
- PKPValidation: "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc"
3984
+ PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB"
3987
3985
  },
3988
3986
  latestEnv: {
3989
3987
  UCD_TOKEN: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
@@ -4016,15 +4014,13 @@ var init_deployment_addresses = __esm({
4016
4014
  PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
4017
4015
  TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
4018
4016
  LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
4019
- BTCSpendAuthorizer: "0x59b670e9fA9D0A427751Af201D676719a970857b",
4020
- CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
4021
- LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
4017
+ BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
4018
+ CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
4019
+ LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
4022
4020
  CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
4023
- AdminModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
4021
+ AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
4024
4022
  PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
4025
- PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
4026
- OperationAuthorizationRegistry: "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0",
4027
- PKPValidation: "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc"
4023
+ PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB"
4028
4024
  };
4029
4025
  ALL_DEPLOYMENTS = {
4030
4026
  sepolia: SEPOLIA_DEPLOYMENT,
@@ -31388,103 +31384,103 @@ var require_pkg_src = __commonJS({
31388
31384
  }
31389
31385
  },
31390
31386
  btcTransactionSigner: {
31391
- cid: "QmTrtAnUFpAi6tpw74UPCiULqe9Z4SBE4b4neekY8evK5Y",
31387
+ cid: "QmZs56sVTCJv7mgvyRYfpYHFvFLcSeXa4H44qUYT7z14QP",
31392
31388
  authorizedCidHex: cidToHex(
31393
- "QmTrtAnUFpAi6tpw74UPCiULqe9Z4SBE4b4neekY8evK5Y"
31389
+ "QmZs56sVTCJv7mgvyRYfpYHFvFLcSeXa4H44qUYT7z14QP"
31394
31390
  ),
31395
31391
  name: "Btc Transaction Signer",
31396
31392
  description: "Production Btc Transaction Signer",
31397
31393
  version: "1.0.0",
31398
31394
  deployed: true,
31399
- deployedAt: 1780976122896,
31400
- size: 41048,
31401
- hash: "93725b2020e1914e93f1e21bdcc75d9cb28bc0b6bc4ea9b470f112e1f068998f"
31395
+ deployedAt: 1781542204806,
31396
+ size: 42376,
31397
+ hash: "f4aed3d88f6fbff6623ed2047436cecd4f561a74883171ea6f4ebe0a1129973c"
31402
31398
  },
31403
31399
  ucdMintValidator: {
31404
- cid: "QmTWKgfSHfYWTosPJBzu2s4sM2U6qhvmA9pXbkUzDxdQTJ",
31400
+ cid: "QmPir8F8jmJ4ssQpEC3xFxkEnZxMHcgS6VxBQE1jkTLj5K",
31405
31401
  authorizedCidHex: cidToHex(
31406
- "QmTWKgfSHfYWTosPJBzu2s4sM2U6qhvmA9pXbkUzDxdQTJ"
31402
+ "QmPir8F8jmJ4ssQpEC3xFxkEnZxMHcgS6VxBQE1jkTLj5K"
31407
31403
  ),
31408
31404
  name: "Ucd Mint Validator",
31409
31405
  description: "Production Ucd Mint Validator",
31410
31406
  version: "1.0.0",
31411
31407
  deployed: true,
31412
- deployedAt: 1781116591564,
31413
- size: 68521,
31414
- hash: "5a955863b32c003314ab29c37b157e06d00a2f93c2d9085a02ca73b71838a72f",
31415
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31408
+ deployedAt: 1781542207366,
31409
+ size: 72074,
31410
+ hash: "567a51d3beaedbda4f0af2636835ca8a2af89c2264e91f8dc31f522c1a424b7b",
31411
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31416
31412
  pkp: {
31417
31413
  publicKey: "0x041ab17cd91fc5c0b761eea6092d032807561b621b82c488826776e04a9158d61ba64d809a4729f0501289d980732cb06d8dfd06999dd9c8efd2f495dad78b31bb",
31418
31414
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
31419
31415
  }
31420
31416
  },
31421
31417
  processPaymentValidator: {
31422
- cid: "QmVJ9UaUz8vfvHCEwVY584e9RTEcqy3f3T89UNtzzFSdcz",
31418
+ cid: "QmVq19NXJEpMMvaWQdsU5czLoqh28WGWoGgKMSYFaCmfa9",
31423
31419
  authorizedCidHex: cidToHex(
31424
- "QmVJ9UaUz8vfvHCEwVY584e9RTEcqy3f3T89UNtzzFSdcz"
31420
+ "QmVq19NXJEpMMvaWQdsU5czLoqh28WGWoGgKMSYFaCmfa9"
31425
31421
  ),
31426
31422
  name: "Process Payment Validator",
31427
31423
  description: "Production Process Payment Validator",
31428
31424
  version: "1.0.0",
31429
31425
  deployed: true,
31430
- deployedAt: 1780976120346,
31431
- size: 64473,
31432
- hash: "8cf2ea8e2bf39ab02c6ac1706d8bec2aa16aa1f04f4789b11fa8215e04ac2d7e",
31433
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31426
+ deployedAt: 1781542209526,
31427
+ size: 68239,
31428
+ hash: "ada27fea57aa3f3b861c49e75ed1f80b72500fdccc1d6e88ee1a3c1396b81867",
31429
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31434
31430
  pkp: {
31435
31431
  publicKey: "0x04cfccb9b6c7addc79469c0e9fafebef4c70801302c62cdb26b610723a9b8527d23f98a40158c7340d83fd0e62d02b5ec74c12f7a86d98e8c6973b4811110f19ad",
31436
31432
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
31437
31433
  }
31438
31434
  },
31439
31435
  extendPositionValidator: {
31440
- cid: "QmW2zjWbsVzm8q4oMEHZ1SCeijygZFMvvi9zHqUQWm3jut",
31436
+ cid: "QmP2u3bgKLtfqsFMp6Li72zMY8ZZH3ttAqp9W2wwonUmcb",
31441
31437
  authorizedCidHex: cidToHex(
31442
- "QmW2zjWbsVzm8q4oMEHZ1SCeijygZFMvvi9zHqUQWm3jut"
31438
+ "QmP2u3bgKLtfqsFMp6Li72zMY8ZZH3ttAqp9W2wwonUmcb"
31443
31439
  ),
31444
31440
  name: "Extend Position Validator",
31445
31441
  description: "Production Extend Position Validator",
31446
31442
  version: "1.0.1",
31447
31443
  deployed: true,
31448
- deployedAt: 1781116610064,
31449
- size: 63508,
31450
- hash: "187c71046858bde0753fe479634bd2901e3d7f3689b5f39a82b3c5fa3a47b53d",
31451
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31444
+ deployedAt: 1781542211640,
31445
+ size: 66543,
31446
+ hash: "0db666fa2888e9acea13d8e4d79edd4ca252f5a4bb06d97e53aa14a9a34b7143",
31447
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31452
31448
  pkp: {
31453
31449
  publicKey: "0x04e52338f6a0c3362800f1a94c4c8f08be5030dde0fa217388c53d1c1a4790f4443c9f2886b2d2d8f4b75a9a156e9b028011b1a1cf7648da0e556aa980ec692836",
31454
31450
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
31455
31451
  }
31456
31452
  },
31457
31453
  btcWithdrawal: {
31458
- cid: "QmcxHLCcXpx5Jstd1hQmwjU2KPDzP2KYEdMgbZVn84nY6n",
31454
+ cid: "QmXtmLdGuEqMKKAtV7d8sHpUV32Kt74na4dRQdpWLasbHJ",
31459
31455
  authorizedCidHex: cidToHex(
31460
- "QmcxHLCcXpx5Jstd1hQmwjU2KPDzP2KYEdMgbZVn84nY6n"
31456
+ "QmXtmLdGuEqMKKAtV7d8sHpUV32Kt74na4dRQdpWLasbHJ"
31461
31457
  ),
31462
31458
  name: "Btc Withdrawal",
31463
31459
  description: "Production Btc Withdrawal",
31464
31460
  version: "1.0.0",
31465
31461
  deployed: true,
31466
- deployedAt: 1781116627244,
31467
- size: 76218,
31468
- hash: "1e686e517ab1b8163904a27d3e1962cecb2f49b3cc7ecdc8f2ff5e5847fe3762",
31469
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31462
+ deployedAt: 1781542212709,
31463
+ size: 79782,
31464
+ hash: "e824eb473df8eba3a025ac3adc46730dbf89f90884d7c05a78cc07b90d6bc4df",
31465
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31470
31466
  pkp: {
31471
31467
  publicKey: "0x043616787c5432415c24378c4ef48de2bcd6bb7b575b837e3cff09171802662da7105d79586c7659677a0ecbaddac4cce06cb2a11f69a16fa0c4d7002ac7d51a4d",
31472
31468
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
31473
31469
  }
31474
31470
  },
31475
31471
  liquidationValidator: {
31476
- cid: "QmZv8cRhvQqEGscWufU4rYPrKNt3ruAhQWK2ei3ohJBiZA",
31472
+ cid: "QmVicBXuZVY8t4DXLPjvXjzLqnBtnogAh5HT7BaL9VeDwF",
31477
31473
  authorizedCidHex: cidToHex(
31478
- "QmZv8cRhvQqEGscWufU4rYPrKNt3ruAhQWK2ei3ohJBiZA"
31474
+ "QmVicBXuZVY8t4DXLPjvXjzLqnBtnogAh5HT7BaL9VeDwF"
31479
31475
  ),
31480
31476
  name: "Liquidation Validator",
31481
31477
  description: "Production Liquidation Validator",
31482
31478
  version: "1.0.0",
31483
31479
  deployed: true,
31484
- deployedAt: 1781116646357,
31485
- size: 54901,
31486
- hash: "017ec04899089b98991a5aab6eeae5e3214c2cc9de7ef9b3fc0cd5ad85c3556c",
31487
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31480
+ deployedAt: 1781542213421,
31481
+ size: 58444,
31482
+ hash: "0f42e9f8984433fef95875d35eb3c8d985e7ce15ad309e6aa1093d6fd1ba0bb5",
31483
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31488
31484
  pkp: {
31489
31485
  publicKey: "0x041a241de58976c13e3d7ca5a18e494f7330151e3818706135d50176e78ffb673e58b11f0b67a87c73fade6c6b27d6e7a7377ea9f4c10bf31880f1d725f18cc6f8",
31490
31486
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
@@ -31509,18 +31505,18 @@ var require_pkg_src = __commonJS({
31509
31505
  }
31510
31506
  },
31511
31507
  loanVaultBtcBalance: {
31512
- cid: "Qmd7ZAWQzxjbFXjk39HuyRCN18FDG1LDifXceaikNFYRbm",
31508
+ cid: "QmUmqL4LcjDSpw2TtuWMcw8xYk8hPxgagY2qHDU8Mx1PLG",
31513
31509
  authorizedCidHex: cidToHex(
31514
- "Qmd7ZAWQzxjbFXjk39HuyRCN18FDG1LDifXceaikNFYRbm"
31510
+ "QmUmqL4LcjDSpw2TtuWMcw8xYk8hPxgagY2qHDU8Mx1PLG"
31515
31511
  ),
31516
31512
  name: "Loan Vault Btc Balance",
31517
31513
  description: "Production Loan Vault Btc Balance",
31518
31514
  version: "1.0.0",
31519
31515
  deployed: true,
31520
- deployedAt: 1780976125009,
31521
- size: 44634,
31522
- hash: "f7ba0f8778a15f349122237c44391800bb082d2090a87cc1631f0a764439d029",
31523
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31516
+ deployedAt: 1781542215432,
31517
+ size: 48397,
31518
+ hash: "da3750a70e532b87f3590a3e2d8c2d51e700589f6e111bb291384ab01304af35",
31519
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31524
31520
  pkp: {
31525
31521
  publicKey: "0x043616787c5432415c24378c4ef48de2bcd6bb7b575b837e3cff09171802662da7105d79586c7659677a0ecbaddac4cce06cb2a11f69a16fa0c4d7002ac7d51a4d",
31526
31522
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
@@ -31533,18 +31529,18 @@ var require_pkg_src = __commonJS({
31533
31529
  // Requires BitcoinProviderRegistry.addAllowedCid(chainId, keccak256(utf8(cid)))
31534
31530
  // on each target chain (the action decrypts registry slots). No OAR entry.
31535
31531
  btcAddressBalance: {
31536
- cid: "QmVmF9CHFDhhV51bNX87tVyd95oQS56u78ThFYKzMwEbFS",
31532
+ cid: "QmWRDAg7ZCBFFhGfdXR7aUtQsG5qqBb1yVdLCxh8dPD7G5",
31537
31533
  authorizedCidHex: cidToHex(
31538
- "QmVmF9CHFDhhV51bNX87tVyd95oQS56u78ThFYKzMwEbFS"
31534
+ "QmWRDAg7ZCBFFhGfdXR7aUtQsG5qqBb1yVdLCxh8dPD7G5"
31539
31535
  ),
31540
31536
  name: "Btc Address Balance",
31541
31537
  description: "Address-only signed total BTC balance via registry consensus (no positionId, no price)",
31542
31538
  version: "0.1.0",
31543
31539
  deployed: true,
31544
- deployedAt: 1781116681558,
31545
- size: 21957,
31546
- hash: "b17977304be6b117bcb29feafc3bb654113d72d5147ceeba92e91b4d7f5c0327",
31547
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31540
+ deployedAt: 1781542217452,
31541
+ size: 25519,
31542
+ hash: "000e2f8bdbccdc95b0db0fb3f12412e2e76eea16a8456d37914d324437ae291c",
31543
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31548
31544
  pkp: {
31549
31545
  publicKey: "0x0498cbb31facfa26e3ec83ccdabfe4fe341ca0282e0c3cb81da7113723b9726e1e49efa92165cc3faa66ced4454cea56dbab12267852d6525a55d7c4f128b912cd",
31550
31546
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
@@ -31577,18 +31573,18 @@ var require_pkg_src = __commonJS({
31577
31573
  hash: "03ee5be239c91c735d2c95db89a0d1b77e602cfc18af8eb64b3281fddcd90a72"
31578
31574
  },
31579
31575
  staleSpendRecoveryValidator: {
31580
- cid: "QmRZuRrxzsbp3WejuMfJJgws1iteRk87p1nGna82Cgun2k",
31576
+ cid: "QmWqJZqoKUqMaGTXe9WUSwdDyeBwXJ9dnR3ioFnVK4RkN5",
31581
31577
  authorizedCidHex: cidToHex(
31582
- "QmRZuRrxzsbp3WejuMfJJgws1iteRk87p1nGna82Cgun2k"
31578
+ "QmWqJZqoKUqMaGTXe9WUSwdDyeBwXJ9dnR3ioFnVK4RkN5"
31583
31579
  ),
31584
31580
  name: "Stale Spend Recovery Validator",
31585
31581
  description: "Production Stale Spend Recovery Validator",
31586
31582
  version: "1.0.0",
31587
31583
  deployed: true,
31588
- deployedAt: 1781116700324,
31589
- size: 31148,
31590
- hash: "c93591c7c7f51b519243499d78bd5ac0df1e368caa76c08d6a5d7aea9e3a49cc",
31591
- validatorWalletAddress: "0x82db9f515957aa380b596c6ea2bd30cef181f236",
31584
+ deployedAt: 1781542219438,
31585
+ size: 34413,
31586
+ hash: "26b11730cf5d9eb4af0b1fe65192d26ccee50369c0472211a0ea11e26ef51cc5",
31587
+ validatorWalletAddress: "0x82DB9F515957aA380B596C6eA2Bd30CEF181f236",
31592
31588
  pkp: {
31593
31589
  publicKey: "0x046da0ad6da7dd4a0063cbeac6f2bdb6a9889c2178b23470833356a8ee5630f7f0eee0db348d9d9aaaadd23eccf0063c8f68ee5e446abe30b882bf1de4c932bc21",
31594
31590
  ethAddress: "0xc7e1588Db94Bbe92Ab209B833235144Fc5b97607"
@@ -33335,12 +33331,83 @@ ${errorReport}`);
33335
33331
  function isAbortError(error2) {
33336
33332
  return error2 instanceof Error && error2.name === "AbortError";
33337
33333
  }
33334
+ var BLOCKSTREAM_TOKEN_URL = "https://login.blockstream.com/realms/blockstream-public/protocol/openid-connect/token";
33335
+ var oauthTokenCache = /* @__PURE__ */ new Map();
33336
+ var OAUTH_TOKEN_TIMEOUT_MS = 1e4;
33337
+ async function getBlockstreamBearerToken(auth, timeoutMs) {
33338
+ const tokenUrl = auth.tokenUrl || BLOCKSTREAM_TOKEN_URL;
33339
+ const key = `${tokenUrl}
33340
+ ${auth.clientId}`;
33341
+ const cached = oauthTokenCache.get(key);
33342
+ if (cached)
33343
+ return cached;
33344
+ const promise = (async () => {
33345
+ const body = `grant_type=client_credentials&client_id=${encodeURIComponent(auth.clientId)}&client_secret=${encodeURIComponent(auth.clientSecret)}&scope=openid`;
33346
+ const controller = new AbortController();
33347
+ const timeoutId = setTimeout(
33348
+ () => controller.abort(),
33349
+ timeoutMs && timeoutMs > 0 ? timeoutMs : OAUTH_TOKEN_TIMEOUT_MS
33350
+ );
33351
+ let resp;
33352
+ try {
33353
+ resp = await fetch(tokenUrl, {
33354
+ method: "POST",
33355
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
33356
+ body,
33357
+ signal: controller.signal
33358
+ });
33359
+ } finally {
33360
+ clearTimeout(timeoutId);
33361
+ }
33362
+ if (!resp.ok) {
33363
+ throw new Error(
33364
+ `Blockstream OAuth token exchange failed: ${resp.status} ${resp.statusText}`
33365
+ );
33366
+ }
33367
+ const json = await resp.json();
33368
+ const token = json?.access_token;
33369
+ if (typeof token !== "string" || token.length === 0) {
33370
+ throw new Error(
33371
+ "Blockstream OAuth token exchange returned no access_token"
33372
+ );
33373
+ }
33374
+ return token;
33375
+ })();
33376
+ promise.catch(() => oauthTokenCache.delete(key));
33377
+ oauthTokenCache.set(key, promise);
33378
+ return promise;
33379
+ }
33380
+ async function authHeaders(auth, timeoutMs) {
33381
+ if (!auth)
33382
+ return {};
33383
+ switch (auth.provider) {
33384
+ case "esplora":
33385
+ return {};
33386
+ case "maestro":
33387
+ return { "api-key": auth.apiKey };
33388
+ case "blockstream-enterprise": {
33389
+ const token = await getBlockstreamBearerToken(auth, timeoutMs);
33390
+ return { Authorization: `Bearer ${token}` };
33391
+ }
33392
+ default:
33393
+ return {};
33394
+ }
33395
+ }
33338
33396
  var BitcoinDataProvider = class {
33339
33397
  constructor(config) {
33340
33398
  this.config = config;
33341
33399
  this.timeout = config.timeout || 15e3;
33342
33400
  this.logger = LitActionLogger.create("BitcoinDataProvider");
33343
33401
  }
33402
+ /**
33403
+ * Merge per-provider auth headers into a base header set. No-op for public
33404
+ * Esplora / regtest faucet (no `auth`); attaches the `api-key` header for
33405
+ * Maestro and performs a (memoized) OAuth exchange → `Bearer` for Blockstream
33406
+ * Enterprise. Awaited at every fetch site so a single run shares one token.
33407
+ */
33408
+ async withAuth(base22 = {}) {
33409
+ return { ...base22, ...await authHeaders(this.config.auth, this.timeout) };
33410
+ }
33344
33411
  /**
33345
33412
  * Get current Bitcoin block height from provider
33346
33413
  */
@@ -33359,11 +33426,11 @@ ${errorReport}`);
33359
33426
  `${this.config.providerUrl}/blocks/tip/height`,
33360
33427
  {
33361
33428
  signal: controller.signal,
33362
- headers: {
33429
+ headers: await this.withAuth({
33363
33430
  Accept: "text/plain",
33364
33431
  "User-Agent": "Mozilla/5.0 (compatible; DiamondHandsValidator/1.0)",
33365
33432
  "ngrok-skip-browser-warning": "true"
33366
- }
33433
+ })
33367
33434
  }
33368
33435
  );
33369
33436
  clearTimeout(timeoutId);
@@ -33533,12 +33600,12 @@ ${errorReport}`);
33533
33600
  * Internal method to fetch UTXOs from a specific provider
33534
33601
  *
33535
33602
  * Supports standard Esplora API format:
33536
- * - Standard format: {providerUrl}/address/{address}/utxos
33603
+ * - Standard format: {providerUrl}/address/{address}/utxo
33537
33604
  * - providerUrl must include full base path (e.g., "http://localhost:3002/api/esplora")
33538
33605
  */
33539
33606
  async fetchUTXOsFromProvider(providerUrl, address) {
33540
33607
  this.logger.stepStart("1", "fetchUTXOsFromProvider");
33541
- const endpoint = `${providerUrl}/address/${address}/utxos`;
33608
+ const endpoint = `${providerUrl}/address/${address}/utxo`;
33542
33609
  this.logger.log("1", `Fetching UTXOs from ${endpoint}`);
33543
33610
  const controller = new AbortController();
33544
33611
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
@@ -33548,18 +33615,18 @@ ${errorReport}`);
33548
33615
  this.getCurrentBlockHeight(),
33549
33616
  fetch(endpoint, {
33550
33617
  signal: controller.signal,
33551
- headers: {
33618
+ headers: await this.withAuth({
33552
33619
  Accept: "application/json",
33553
33620
  "Content-Type": "application/json",
33554
33621
  "User-Agent": "Mozilla/5.0 (compatible; DiamondHandsValidator/1.0)",
33555
33622
  "ngrok-skip-browser-warning": "true"
33556
33623
  // Skip ngrok browser warning page
33557
- }
33624
+ })
33558
33625
  })
33559
33626
  ]);
33560
33627
  clearTimeout(timeoutId);
33561
33628
  litDebugLog(
33562
- `[BitcoinDataProvider] parallel(tipHeight + GET utxos) wall ${Date.now() - tParallel}ms endpoint tail .../${address.slice(0, 12)}.../utxos (timeout budget ${this.timeout}ms)`
33629
+ `[BitcoinDataProvider] parallel(tipHeight + GET utxo) wall ${Date.now() - tParallel}ms endpoint tail .../${address.slice(0, 12)}.../utxo (timeout budget ${this.timeout}ms)`
33563
33630
  );
33564
33631
  this.logger.log("1", `Current block height: ${currentBlockHeight}`);
33565
33632
  if (!response.ok) {
@@ -33671,12 +33738,12 @@ ${errorReport}`);
33671
33738
  const t0 = Date.now();
33672
33739
  const response = await fetch(endpoint, {
33673
33740
  signal: controller.signal,
33674
- headers: {
33741
+ headers: await this.withAuth({
33675
33742
  Accept: "application/json",
33676
33743
  "Content-Type": "application/json",
33677
33744
  "User-Agent": "Mozilla/5.0 (compatible; DiamondHandsValidator/1.0)",
33678
33745
  "ngrok-skip-browser-warning": "true"
33679
- }
33746
+ })
33680
33747
  });
33681
33748
  clearTimeout(timeoutId);
33682
33749
  litDebugLog(
@@ -33750,7 +33817,8 @@ ${errorReport}`);
33750
33817
  try {
33751
33818
  const t0 = Date.now();
33752
33819
  const response = await fetch(`${this.config.providerUrl}/tx/${txid}`, {
33753
- signal: controller.signal
33820
+ signal: controller.signal,
33821
+ headers: await this.withAuth()
33754
33822
  });
33755
33823
  clearTimeout(timeoutId);
33756
33824
  litDebugLog(
@@ -33772,7 +33840,7 @@ ${errorReport}`);
33772
33840
  try {
33773
33841
  const tipResp = await fetch(
33774
33842
  `${this.config.providerUrl}/blocks/tip/height`,
33775
- { signal: controller.signal }
33843
+ { signal: controller.signal, headers: await this.withAuth() }
33776
33844
  );
33777
33845
  if (!tipResp.ok) {
33778
33846
  return { txid: data.txid ?? txid, confirmations: 1 };
@@ -33823,7 +33891,8 @@ ${errorReport}`);
33823
33891
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
33824
33892
  try {
33825
33893
  const response = await fetch(`${this.config.providerUrl}/tx/${txid}`, {
33826
- signal: controller.signal
33894
+ signal: controller.signal,
33895
+ headers: await this.withAuth()
33827
33896
  });
33828
33897
  clearTimeout(timeoutId);
33829
33898
  if (!response.ok) {
@@ -122336,29 +122405,46 @@ Error data: ${errorData || "none"}`
122336
122405
  "Content-Type": "application/json",
122337
122406
  ...await this.getAuthHeader()
122338
122407
  };
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
- })
122408
+ const PHASE2_CLIENT_TIMEOUT_MS = 6e4;
122409
+ const abort = new AbortController();
122410
+ const abortTimer = setTimeout(() => abort.abort(), PHASE2_CLIENT_TIMEOUT_MS);
122411
+ let resp;
122412
+ try {
122413
+ resp = await fetch(
122414
+ `${this.config.serviceEndpoint}/api/lit/pending-withdrawals/execute`,
122415
+ {
122416
+ method: "POST",
122417
+ headers,
122418
+ signal: abort.signal,
122419
+ body: JSON.stringify({
122420
+ positionId: envelope.positionId,
122421
+ txid: envelope.txid,
122422
+ vout: envelope.vout,
122423
+ satoshis: envelope.satoshis,
122424
+ targetAddress: envelope.targetAddress,
122425
+ // CRIT-1: send the user-signed targetAmount so the Lit Action can
122426
+ // bind it into its hash recomputation AND cross-check against the
122427
+ // on-chain authorizer record.
122428
+ targetAmount: envelope.targetAmount,
122429
+ networkFee: envelope.networkFee,
122430
+ userSignature: envelope.userSignature,
122431
+ borrowerAddress: envelope.borrowerAddress,
122432
+ chainId: envelope.chainId,
122433
+ timestamp: envelope.timestamp
122434
+ })
122435
+ }
122436
+ );
122437
+ } catch (fetchErr) {
122438
+ if (abort.signal.aborted) {
122439
+ return {
122440
+ success: false,
122441
+ error: "Withdrawal signing timed out. Your withdrawal is still authorized on-chain \u2014 retry Execute from Pending Withdrawals to complete it."
122442
+ };
122360
122443
  }
122361
- );
122444
+ throw fetchErr;
122445
+ } finally {
122446
+ clearTimeout(abortTimer);
122447
+ }
122362
122448
  const json = await resp.json();
122363
122449
  if (!json.success || !json.data?.success) {
122364
122450
  const errMsg = json.data?.error ?? json.error ?? "BTC broadcast failed";
@@ -122632,38 +122718,68 @@ Error data: ${errorData || "none"}`
122632
122718
  error: "chainId required for recoverStaleSpend (set DiamondHandsSDKConfig.chainId)"
122633
122719
  };
122634
122720
  }
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"
122721
+ let attRes;
122722
+ if (this.config.mode === "service" && this.config.serviceEndpoint) {
122723
+ const headers = {
122724
+ "Content-Type": "application/json",
122725
+ ...await this.getAuthHeader()
122641
122726
  };
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
122727
+ const resp = await fetch(
122728
+ `${this.config.serviceEndpoint}/api/lit/stale-spend/recover`,
122729
+ {
122730
+ method: "POST",
122731
+ headers,
122732
+ body: JSON.stringify({
122733
+ positionId: this.toBytes32(params.positionId),
122734
+ utxoTxid: params.utxoTxid,
122735
+ utxoVout: params.utxoVout,
122736
+ invalidatorTxid: params.invalidatorTxid,
122737
+ chainId,
122738
+ ...params.minConfirmations !== void 0 && {
122739
+ minConfirmations: params.minConfirmations
122740
+ }
122741
+ })
122655
122742
  }
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
122743
+ );
122744
+ const json = await resp.json();
122745
+ attRes = json.data ?? {
122746
+ success: false,
122747
+ error: json.error ?? "stale-spend recovery request failed"
122748
+ };
122749
+ } else {
122750
+ const rpcUrl = params.rpcUrl ?? this.config.ethRpcUrl;
122751
+ if (!rpcUrl) {
122752
+ return {
122753
+ success: false,
122754
+ failedStep: "config",
122755
+ error: "ethRpcUrl required for recoverStaleSpend \u2014 set DiamondHandsSDKConfig.ethRpcUrl or pass rpcUrl"
122756
+ };
122665
122757
  }
122666
- });
122758
+ const sdkBitcoinProviderUrl = this.config.bitcoinProviders?.[0]?.url;
122759
+ attRes = await this.litOps.requestStaleSpendRecoveryAttestation({
122760
+ chainId,
122761
+ positionId: this.toBytes32(params.positionId),
122762
+ utxoTxid: params.utxoTxid,
122763
+ utxoVout: params.utxoVout,
122764
+ invalidatorTxid: params.invalidatorTxid,
122765
+ contractAddresses: {
122766
+ PositionManager: contractAddresses.positionManager,
122767
+ BTCSpendAuthorizer: btcSpendAuthorizerAddress,
122768
+ ...contractAddresses.bitcoinProviderRegistry && {
122769
+ BitcoinProviderRegistry: contractAddresses.bitcoinProviderRegistry
122770
+ }
122771
+ },
122772
+ rpcUrl,
122773
+ ...sdkBitcoinProviderUrl && { bitcoinProviderUrl: sdkBitcoinProviderUrl },
122774
+ // Hardhat (chainId 1337/31337) has no on-chain BitcoinProviderRegistry —
122775
+ // Lit Actions read `devBitcoinProviderUrl` from globalThis. Always pass;
122776
+ // non-hardhat chains ignore it. (Single source of truth: bitcoinProviderUrl.)
122777
+ ...sdkBitcoinProviderUrl && { devBitcoinProviderUrl: sdkBitcoinProviderUrl },
122778
+ ...params.minConfirmations !== void 0 && {
122779
+ minConfirmations: params.minConfirmations
122780
+ }
122781
+ });
122782
+ }
122667
122783
  if (!attRes.success || !attRes.signature || !attRes.attestation) {
122668
122784
  return {
122669
122785
  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.281",
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",
@@ -81,8 +81,8 @@
81
81
  },
82
82
  "sideEffects": false,
83
83
  "dependencies": {
84
- "@gvnrdao/dh-lit-actions": "^0.0.309",
85
- "@gvnrdao/dh-lit-ops": "^0.0.297",
84
+ "@gvnrdao/dh-lit-actions": "^0.0.310",
85
+ "@gvnrdao/dh-lit-ops": "^0.0.298",
86
86
  "@noble/hashes": "^1.5.0",
87
87
  "axios": "^1.17.0",
88
88
  "bech32": "^2.0.0",