Skip to content

Commit

Permalink
feat: add aliases, modify example constants and file, export addition…
Browse files Browse the repository at this point in the history
…al functions
  • Loading branch information
Polybius93 committed May 30, 2024
1 parent 18c9233 commit 9762084
Show file tree
Hide file tree
Showing 30 changed files with 696 additions and 556 deletions.
4 changes: 1 addition & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/** @format */
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, {
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
},
});
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{
"type": "module",
"name": "dlc-btc-app",
"version": "1.0.3",
"version": "1.0.5",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"files": [
"dist"
],
"exports": {
".": "./dist/index.js",
"./utilities": "./dist/utilities/index.js",
"./constants": "./dist/constants/index.js",
"./models": "./dist/models/index.js"
"./models": "./dist/models/index.js",
"./bitcoin-functions": "./dist/functions/bitcoin-functions/index.js",
"./ethereum-functions": "./dist/functions/ethereum-functions/index.js"
},
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "tsc",
"start": "node dist/test.js",
"start": "node dist/example.js",
"test": "ts-node index.ts",
"lint": "concurrently -g 'yarn lint:eslint' 'yarn lint:prettier' 'yarn run lint:typecheck'",
"lint:eslint": "eslint \"src/**/*.{js,ts}\"",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @format */
import { AttestorError } from '../models/errors.js';
import { AttestorError } from '@models/errors.js';

export class AttestorHandler {
private attestorRootURLs: string[];
Expand Down
3 changes: 1 addition & 2 deletions src/constants/ethereum-constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @format */
import { EthereumNetwork, EthereumNetworkID } from '../models/ethereum-models.js';
import { EthereumNetwork, EthereumNetworkID } from '@models/ethereum-models.js';

export const ethereumArbitrumSepolia: EthereumNetwork = {
name: 'ArbSepolia',
Expand Down
38 changes: 38 additions & 0 deletions src/constants/example-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { regtest } from 'bitcoinjs-lib/src/networks.js';

// Bitcoin
export const EXAMPLE_BITCOIN_NETWORK = regtest;
export const EXAMPLE_BITCOIN_EXTENDED_PRIVATE_KEY = '';
export const EXAMPLE_BITCOIN_WALLET_ACCOUNT_INDEX = 0;
export const EXAMPLE_REGTEST_BITCOIN_BLOCKCHAIN_API = 'https://devnet.dlc.link/electrs';
export const EXAMPLE_TESTNET_BITCOIN_BLOCKCHAIN_API = 'https://testnet.dlc.link/electrs';
export const EXAMPLE_BITCOIN_BLOCKCHAIN_FEE_RECOMMENDATION_API =
'https://devnet.dlc.link/electrs/fee-estimates';
export const EXAMPLE_BITCOIN_AMOUNT = 0.01;

// Ethereum
export const EXAMPLE_ETHEREUM_PRIVATE_KEY =
'e84775987ab35c5016195c6bb006847f35a6470dea671e3f06853987f6d5c59b';
export const EXAMPLE_ETHEREUM_NODE_API = 'https://sepolia-rollup.arbitrum.io/rpc';
export const EXAMPLE_ETHEREUM_READ_ONLY_NODE_API = 'https://sepolia-rollup.arbitrum.io/rpc';
export const EXAMPLE_ETHEREUM_GITHUB_DEPLOYMENT_PLAN_ROOT_URL =
'https://raw.githubusercontent.com/DLC-link/dlc-solidity';
export const EXAMPLE_ETHEREUM_DEVNET_GITHUB_DEPLOYMENT_PLAN_BRANCH = 'dev';
export const EXAMPLE_ETHEREUM_TESTNET_GITHUB_DEPLOYMENT_PLAN_BRANCH = 'testnet-rolling';
export const EXAMPLE_ETHEREUM_ATTESTOR_CHAIN_ID = 'evm-arbsepolia';

// Attestor
export const EXAMPLE_REGTEST_ATTESTOR_APIS = [
'https://devnet.dlc.link/attestor-1',
'https://devnet.dlc.link/attestor-2',
'https://devnet.dlc.link/attestor-3',
];

export const EXAMPLE_TESTNET_ATTESTOR_APIS = [
'https://testnet.dlc.link/attestor-1',
'https://testnet.dlc.link/attestor-2',
'https://testnet.dlc.link/attestor-3',
];

export const EXAMPLE_TESTNET_ATTESTOR_GROUP_PUBLIC_KEY_V1 =
'0c0bf55fa1ab72462467b973b13e556b07d2fdd8d7a30cdfc10f337e23c7ac00';
2 changes: 0 additions & 2 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** @format */

export * from './ethereum-constants.js';
export * from './ledger-constants.js';
export { bitcoin, testnet, regtest } from 'bitcoinjs-lib/src/networks.js';
2 changes: 0 additions & 2 deletions src/constants/ledger-constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** @format */

export const LEDGER_APPS_MAP = {
BITCOIN_MAINNET: 'Bitcoin',
BITCOIN_TESTNET: 'Bitcoin Test',
Expand Down
7 changes: 3 additions & 4 deletions src/dlc-handlers/ledger-dlc-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
import { Transaction } from '@scure/btc-signer';
import { P2Ret, P2TROut, p2wpkh } from '@scure/btc-signer/payment';
import { truncateAddress } from '@utilities/index.js';
import { Network, Psbt } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';
import { AppClient, DefaultWalletPolicy, WalletPolicy } from 'ledger-bitcoin';
Expand All @@ -13,7 +13,7 @@ import {
getFeeRate,
getInputByPaymentTypeArray,
getUnspendableKeyCommittedToUUID,
} from '../functions/bitcoin-functions.js';
} from '../functions/bitcoin/bitcoin-functions.js';
import {
addNativeSegwitSignaturesToPSBT,
addTaprootInputSignaturesToPSBT,
Expand All @@ -23,10 +23,9 @@ import {
getTaprootInputsToSign,
updateNativeSegwitInputs,
updateTaprootInputs,
} from '../functions/psbt-functions.js';
} from '../functions/bitcoin/psbt-functions.js';
import { PaymentInformation } from '../models/bitcoin-models.js';
import { RawVault } from '../models/ethereum-models.js';
import { truncateAddress } from '../utilities/index.js';

interface LedgerPolicyInformation {
nativeSegwitWalletPolicy: DefaultWalletPolicy;
Expand Down
13 changes: 8 additions & 5 deletions src/dlc-handlers/private-key-dlc-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** @format */
import { Transaction, p2wpkh } from '@scure/btc-signer';
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Signer } from '@scure/btc-signer/transaction';
Expand All @@ -13,8 +12,11 @@ import {
getBalance,
getFeeRate,
getUnspendableKeyCommittedToUUID,
} from '../functions/bitcoin-functions.js';
import { createClosingTransaction, createFundingTransaction } from '../functions/psbt-functions.js';
} from '../functions/bitcoin/bitcoin-functions.js';
import {
createClosingTransaction,
createFundingTransaction,
} from '../functions/bitcoin/psbt-functions.js';
import { RequiredPayment } from '../models/bitcoin-models.js';
import { RawVault } from '../models/ethereum-models.js';

Expand Down Expand Up @@ -129,7 +131,8 @@ export class PrivateKeyDLCHandler {

return privateKey;
}
private handlePayment(vaultUUID: string, attestorGroupPublicKey: string): RequiredPayment {

handlePayment(vaultUUID: string, attestorGroupPublicKey: string): RequiredPayment {
try {
const unspendablePublicKey = getUnspendableKeyCommittedToUUID(vaultUUID, this.bitcoinNetwork);
const unspendableDerivedPublicKey = deriveUnhardenedPublicKey(
Expand All @@ -146,7 +149,7 @@ export class PrivateKeyDLCHandler {
this.derivedKeyPair.nativeSegwitDerivedKeyPair.publicKey,
this.bitcoinNetwork
);
console.log(nativeSegwitPayment.address);

const taprootMultisigPayment = createTaprootMultisigPayment(
unspendableDerivedPublicKey,
attestorDerivedPublicKey,
Expand Down
8 changes: 5 additions & 3 deletions src/dlc-handlers/software-wallet-dlc-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** @format */
import { Transaction, p2wpkh } from '@scure/btc-signer';
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Network } from 'bitcoinjs-lib';
Expand All @@ -10,8 +9,11 @@ import {
getBalance,
getFeeRate,
getUnspendableKeyCommittedToUUID,
} from '../functions/bitcoin-functions.js';
import { createClosingTransaction, createFundingTransaction } from '../functions/psbt-functions.js';
} from '../functions/bitcoin/bitcoin-functions.js';
import {
createClosingTransaction,
createFundingTransaction,
} from '../functions/bitcoin/psbt-functions.js';
import { RequiredPayment } from '../models/bitcoin-models.js';
import { RawVault } from '../models/ethereum-models.js';

Expand Down
Loading

0 comments on commit 9762084

Please sign in to comment.