-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modify proof of reserve calculation (#15)
* feat: modify por calculation, add tests * feat: add unit tests for bitcoin functions related to por calculations
- Loading branch information
1 parent
04bdc9d
commit a20b638
Showing
13 changed files
with
592 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/functions/proof-of-reserve/proof-of-reserve-functions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Network } from 'bitcoinjs-lib'; | ||
import { RawVault } from 'src/models/ethereum-models.js'; | ||
|
||
import { | ||
createTaprootMultisigPayment, | ||
deriveUnhardenedPublicKey, | ||
getScriptMatchingOutputFromTransaction, | ||
getUnspendableKeyCommittedToUUID, | ||
} from '../bitcoin/bitcoin-functions.js'; | ||
import { | ||
checkBitcoinTransactionConfirmations, | ||
fetchBitcoinTransaction, | ||
} from '../bitcoin/bitcoin-request-functions.js'; | ||
|
||
export async function verifyVaultDeposit( | ||
vault: RawVault, | ||
attestorGroupPublicKey: Buffer, | ||
bitcoinBlockchainBlockHeight: number, | ||
bitcoinBlockchainAPI: string, | ||
bitcoinNetwork: Network | ||
): Promise<boolean> { | ||
try { | ||
const fundingTransaction = await fetchBitcoinTransaction( | ||
vault.fundingTxId, | ||
bitcoinBlockchainAPI | ||
); | ||
|
||
const isFundingTransactionConfirmed = await checkBitcoinTransactionConfirmations( | ||
fundingTransaction, | ||
bitcoinBlockchainBlockHeight | ||
); | ||
|
||
if (!isFundingTransactionConfirmed) { | ||
return false; | ||
} | ||
|
||
const unspendableKeyCommittedToUUID = deriveUnhardenedPublicKey( | ||
getUnspendableKeyCommittedToUUID(vault.uuid, bitcoinNetwork), | ||
bitcoinNetwork | ||
); | ||
|
||
const taprootMultisigPayment = createTaprootMultisigPayment( | ||
unspendableKeyCommittedToUUID, | ||
attestorGroupPublicKey, | ||
Buffer.from(vault.taprootPubKey, 'hex'), | ||
bitcoinNetwork | ||
); | ||
|
||
const vaultTransactionOutput = getScriptMatchingOutputFromTransaction( | ||
fundingTransaction, | ||
taprootMultisigPayment.script | ||
); | ||
|
||
if (!vaultTransactionOutput) { | ||
return false; | ||
} | ||
|
||
if (vaultTransactionOutput.value !== vault.valueLocked.toNumber()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
console.log(`Error verifying Vault Deposit: ${error}`); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const TEST_REGTEST_BITCOIN_BLOCKCHAIN_API = 'https://devnet.dlc.link/electrs'; | ||
export const TEST_TESTNET_BITCOIN_BLOCKCHAIN_API = 'https://testnet.dlc.link/electrs'; | ||
|
||
export const TEST_BITCOIN_BLOCKCHAIN_FEE_RECOMMENDATION_API = | ||
'https://devnet.dlc.link/electrs/fee-estimates'; | ||
|
||
export const TEST_REGTEST_ATTESTOR_APIS = [ | ||
'https://devnet.dlc.link/attestor-1', | ||
'https://devnet.dlc.link/attestor-2', | ||
'https://devnet.dlc.link/attestor-3', | ||
]; | ||
|
||
export const TEST_ETHEREUM_NODE_API = 'https://sepolia-rollup.arbitrum.io/rpc'; | ||
export const TEST_ETHEREUM_READ_ONLY_NODE_API = 'https://sepolia-rollup.arbitrum.io/rpc'; | ||
|
||
export const TEST_ETHEREUM_GITHUB_DEPLOYMENT_PLAN_ROOT_URL = | ||
'https://raw.githubusercontent.com/DLC-link/dlc-solidity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const TEST_REGTEST_ATTESTOR_EXTENDED_GROUP_PUBLIC_KEY_1 = | ||
'tpubDDqN2CmTDKaGeqXMayfCZEvjZqntifi4r1ztmRWsGuE1VE4bosR3mBKQwVaCxZcmg8R1nHDMDzDmzjoccBMgwZV1hhz51tAXVnhjABCQcwA'; | ||
|
||
export const TEST_TESTNET_ATTESTOR_EXTENDED_GROUP_PUBLIC_KEY_1 = | ||
'tpubDDRekL64eJJav32TLhNhG59qra7wAMaei8YMGXNiJE8ksdYrKgvaFM1XG6JrSt31W97XryScrX37RUEujjZT4qScNf8Zu1JxWj4VYkwz4rU'; | ||
|
||
export const TEST_TESTNET_ATTESTOR_UNHARDENED_DERIVED_PUBLIC_KEY_1 = | ||
'027eda4d625f781dcc98bf68901360fdaaacce8ed466096c1dfe4865209b28c058'; |
Oops, something went wrong.