Skip to content

Commit

Permalink
feat: add rollup bundler, remove submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Jun 21, 2024
1 parent 53f1445 commit 24f0a31
Show file tree
Hide file tree
Showing 21 changed files with 366 additions and 86 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
"dist"
],
"exports": {
".": "./dist/index.js",
"./utilities": "./dist/utilities/index.js",
"./constants": "./dist/constants/index.js",
"./models": "./dist/models/index.js",
"./bitcoin-functions": "./dist/functions/bitcoin/index.js",
"./ethereum-functions": "./dist/functions/ethereum/index.js"
".": "./dist/index.js"
},
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "rm -rf dist && tsc",
"build": "rm -rf dist && rollup -c rollup.config.js",
"test": "jest",
"lint": "concurrently -g 'yarn lint:eslint' 'yarn lint:prettier' 'yarn run lint:typecheck'",
"lint:eslint": "eslint \"src/**/*.{js,ts}\"",
Expand All @@ -38,6 +33,9 @@
"author": "DLC.Link",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/jest": "^29.5.12",
"@types/prompts": "^2.4.9",
Expand All @@ -50,19 +48,22 @@
"ls-lint": "^0.1.2",
"prettier": "^3.2.5",
"prettier-eslint": "^16.3.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typecheck": "^0.1.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.0"
},
"dependencies": {
"@bitcoinerlab/secp256k1": "bitcoinerlab/secp256k1",
"@ledgerhq/hw-app-btc": "^10.2.4",
"@noble/hashes": "^1.4.0",
"@scure/base": "^1.1.6",
"@scure/btc-signer": "^1.3.1",
"bip32": "^4.0.0",
"bitcoinjs-lib": "^6.1.5",
"buffer": "^6.0.3",
"chalk": "^5.3.0",
"decimal.js": "^10.4.3",
"ethers": "5.7.2",
Expand Down
17 changes: 17 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'esm',
name: 'dlc-btc-lib',
sourcemap: true,
},
],
plugins: [resolve(), typescript({ tsconfig: './tsconfig.json' }), commonjs(), nodePolyfills()],
};
2 changes: 1 addition & 1 deletion src/attestor-handlers/attestor-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AttestorError } from '../models/errors.js';
import { AttestorError } from '../models/error-models.js';

export class AttestorHandler {
private attestorRootURLs: string[];
Expand Down
3 changes: 0 additions & 3 deletions src/constants/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/dlc-handlers/ledger-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Transaction } from '@scure/btc-signer';
import { P2Ret, P2TROut, p2wpkh } from '@scure/btc-signer/payment';
import { Network, Psbt } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';
import { Buffer } from 'buffer';
import { AppClient, DefaultWalletPolicy, WalletPolicy } from 'ledger-bitcoin';

import {
Expand All @@ -25,7 +26,7 @@ import {
} from '../functions/bitcoin/psbt-functions.js';
import { ExtendedPaymentInformation } from '../models/bitcoin-models.js';
import { RawVault } from '../models/ethereum-models.js';
import { truncateAddress } from '../utilities/index.js';
import { truncateAddress } from '../utilities/utilities.js';

interface LedgerPolicyInformation {
nativeSegwitWalletPolicy: DefaultWalletPolicy;
Expand Down
1 change: 1 addition & 0 deletions src/dlc-handlers/software-wallet-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Transaction, p2wpkh } from '@scure/btc-signer';
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Network } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';
import { Buffer } from 'buffer';

import {
createTaprootMultisigPayment,
Expand Down
5 changes: 3 additions & 2 deletions src/functions/bitcoin/bitcoin-functions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as ellipticCurveCryptography from '@bitcoinerlab/secp256k1';
import {
Address,
OutScript,
Expand All @@ -13,8 +14,8 @@ import { TransactionInput } from '@scure/btc-signer/psbt';
import { BIP32Factory, BIP32Interface } from 'bip32';
import { Network } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';
import { Buffer } from 'buffer';
import { Decimal } from 'decimal.js';
import * as ellipticCurveCryptography from 'tiny-secp256k1';

import {
BitcoinInputSigningConfig,
Expand All @@ -24,7 +25,7 @@ import {
PaymentTypes,
UTXO,
} from '../../models/bitcoin-models.js';
import { createRangeFromLength, isDefined, isUndefined } from '../../utilities/index.js';
import { createRangeFromLength, isDefined, isUndefined } from '../../utilities/utilities.js';

const TAPROOT_UNSPENDABLE_KEY_HEX =
'0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0';
Expand Down
16 changes: 0 additions & 16 deletions src/functions/bitcoin/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/functions/bitcoin/psbt-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { hexToBytes } from '@noble/hashes/utils';
import { selectUTXO } from '@scure/btc-signer';
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Network, Psbt } from 'bitcoinjs-lib';
import { Buffer } from 'buffer';
import { PartialSignature } from 'ledger-bitcoin/build/main/lib/appClient.js';

import { BitcoinInputSigningConfig, PaymentTypes } from '../../models/bitcoin-models.js';
import { reverseBytes } from '../../utilities/index.js';
import { reverseBytes } from '../../utilities/utilities.js';
import {
ecdsaPublicKeyToSchnorr,
getFeeAmount,
Expand Down
2 changes: 1 addition & 1 deletion src/functions/ethereum/ethereum-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ethereumArbitrum,
ethereumArbitrumSepolia,
} from '../../constants/ethereum-constants.js';
import { EthereumError } from '../../models/errors.js';
import { EthereumError } from '../../models/error-models.js';
import {
DLCEthereumContracts,
DLCSolidityBranchName,
Expand Down
6 changes: 0 additions & 6 deletions src/functions/ethereum/index.ts

This file was deleted.

45 changes: 29 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import { AttestorHandler } from './attestor-handlers/attestor-handler.js';
import { LedgerDLCHandler } from './dlc-handlers/ledger-dlc-handler.js';
import { PrivateKeyDLCHandler } from './dlc-handlers/private-key-dlc-handler.js';
import { SoftwareWalletDLCHandler } from './dlc-handlers/software-wallet-dlc-handler.js';
import { EthereumHandler } from './network-handlers/ethereum-handler.js';
import { ReadOnlyEthereumHandler } from './network-handlers/read-only-ethereum-handler.js';
import { ProofOfReserveHandler } from './proof-of-reserve-handlers/proof-of-reserve-handler.js';

export { AttestorHandler } from './attestor-handlers/attestor-handler.js';
export { LedgerDLCHandler } from './dlc-handlers/ledger-dlc-handler.js';
export { PrivateKeyDLCHandler } from './dlc-handlers/private-key-dlc-handler.js';
export { SoftwareWalletDLCHandler } from './dlc-handlers/software-wallet-dlc-handler.js';
export { EthereumHandler } from './network-handlers/ethereum-handler.js';
export { ReadOnlyEthereumHandler } from './network-handlers/read-only-ethereum-handler.js';
export { ProofOfReserveHandler } from './proof-of-reserve-handlers/proof-of-reserve-handler.js';
export * from './utilities/utilities.js';
export { Network } from 'bitcoinjs-lib/src/networks.js';
export { Transaction } from '@scure/btc-signer';
export * from './models/bitcoin-models.js';
export * from './models/error-models.js';
export * from './models/ethereum-models.js';
export {
PrivateKeyDLCHandler,
LedgerDLCHandler,
SoftwareWalletDLCHandler,
EthereumHandler,
ReadOnlyEthereumHandler,
AttestorHandler,
ProofOfReserveHandler,
};
broadcastTransaction,
fetchBitcoinBlockchainBlockHeight,
fetchBitcoinTransaction,
getBalance,
} from './functions/bitcoin/bitcoin-request-functions.js';
export {
createClosingTransaction,
createFundingTransaction,
} from './functions/bitcoin/psbt-functions.js';
export {
fetchEthereumDeploymentPlan,
fetchEthereumDeploymentPlansByNetwork,
} from './functions/ethereum/ethereum-functions.js';
export * from './constants/ethereum-constants.js';
export * from './constants/ledger-constants.js';
export { bitcoin, testnet, regtest } from 'bitcoinjs-lib/src/networks.js';
1 change: 1 addition & 0 deletions src/models/bitcoin-models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Buffer } from 'buffer';

export interface UTXO {
txid: string;
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions src/models/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/network-handlers/ethereum-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Event, Wallet, providers } from 'ethers';

import { getEthereumContracts, getProvider } from '../functions/ethereum/ethereum-functions.js';
import { EthereumError } from '../models/errors.js';
import { EthereumError } from '../models/error-models.js';
import {
DLCEthereumContractName,
DLCEthereumContracts,
Expand Down
2 changes: 1 addition & 1 deletion src/network-handlers/read-only-ethereum-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getProvider,
getReadOnlyEthereumContracts,
} from '../functions/ethereum/ethereum-functions.js';
import { EthereumError } from '../models/errors.js';
import { EthereumError } from '../models/error-models.js';
import {
DLCEthereumContractName,
DLCEthereumContracts,
Expand Down
1 change: 1 addition & 0 deletions src/proof-of-reserve-handlers/proof-of-reserve-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { hex } from '@scure/base';
import { Network } from 'bitcoinjs-lib';
import { Buffer } from 'buffer';

import {
createTaprootMultisigPayment,
Expand Down
1 change: 1 addition & 0 deletions src/utilities/index.ts → src/utilities/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'buffer';
import { Decimal } from 'decimal.js';

export function shiftValue(value: number): number {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/sign-transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Transaction, p2wpkh } from '@scure/btc-signer';
import { Buffer } from 'buffer';

import { PrivateKeyDLCHandler } from '../../src/index.js';
import {
Expand Down
Loading

0 comments on commit 24f0a31

Please sign in to comment.