Skip to content

Commit

Permalink
strips BTCDepositAddressDeriver
Browse files Browse the repository at this point in the history
  • Loading branch information
dpiatkivskyi committed Jun 25, 2024
1 parent 03e2c65 commit e1e5e20
Showing 1 changed file with 0 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/BTCDepositAddressDeriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

pragma solidity ^0.8.24;

import {Deriver} from "./Deriver.sol";
import {Bech32m} from "./Bech32m.sol";
import {console} from "forge-std/console.sol";

error SeedWasNotSetYet();
error UnsupportedBtcAddress(string btcAddress);
error CannotParseBtcAddress(
string btcAddress,
string hrp,
Bech32m.DecodeError err
);

// Types of Bitcoin Network

contract BTCDepositAddressDeriver {

event SeedChanged(string btcAddr1, string btcAddr2, string hrp);
Expand Down Expand Up @@ -49,9 +35,6 @@ contract BTCDepositAddressDeriver {

networkHrp = _hrp;

(p1x, p1y) = parseBTCTaprootAddress(_hrp, _btcAddr1);
(p2x, p2y) = parseBTCTaprootAddress(_hrp, _btcAddr2);

btcAddr1 = _btcAddr1;
btcAddr2 = _btcAddr2;

Expand All @@ -78,51 +61,4 @@ contract BTCDepositAddressDeriver {

return _hrp;
}

// Derive pubkey's (x,y) coordinates from taproot address
function parseBTCTaprootAddress(
string memory _hrp,
string calldata _bitcoinAddress
) public pure returns (uint256, uint256) {

(uint8 witVer, bytes memory witProg, Bech32m.DecodeError err) = Bech32m
.decodeSegwitAddress(bytes(_hrp), bytes(_bitcoinAddress));

if (err != Bech32m.DecodeError.NoError) {
revert CannotParseBtcAddress(_bitcoinAddress, _hrp, err);
}
if (witVer != 1 || witProg.length != 32) {
revert UnsupportedBtcAddress(_bitcoinAddress);
}

uint256 x = uint256(bytes32(witProg));

if (x == 0 || x >= Deriver.PP) {
revert UnsupportedBtcAddress(_bitcoinAddress);
}

uint256 y = Deriver.liftX(x);

return (x, y);
}

// Get users' Bitcoin deposit address from user's Ethereum address
function getBTCDepositAddress(
address ethAddr
) public view returns (string memory) {

if (!wasSeedSet) {
revert SeedWasNotSetYet();
}

return
Deriver.getBtcAddressFromEth(
p1x,
p1y,
p2x,
p2y,
bytes(networkHrp),
ethAddr
);
}
}

0 comments on commit e1e5e20

Please sign in to comment.