# @atomicfinance/types

## 5.0.0

### Major Changes

- 5211f4a: Release 5.0.0: run on the ddk v2 engine and fund single-funded contracts the
  way ddk v2 builds them. Every `@atomicfinance` package moves to 5.0.0 together.

  **The engine is now the generated ddk binding**, `@bennyblader/ddk` (formerly
  `@bennyblader/ddk-ts`) or `@bennyblader/ddk-rn`, 1.0.0-rc7 or later.
  `DdkInterface` mirrors it:
  - Bytes are `Uint8Array`. A `Buffer` still passes as an argument; results are
    wrapped in `Buffer.from()` before BAL calls `Buffer`-only methods.
  - Functions that operate on one record are methods on that record's namespace:
    `ddk.Transaction.signCet(tx, ...)`, `ddk.Transaction.cetSighash(...)`,
    `ddk.Transaction.cetAdaptorSignatureInputs(...)`, `ddk.TxOutput.isDust(...)`,
    `ddk.AdaptorSignature.verifyFromOracleInfo(...)`,
    `ddk.PartyParams.changeOutputAndFees(...)`, and so on.
  - `DdkDlcTransactions.fundingScriptPubkey` is `fundingWitnessScript`; the bytes
    are the same 2-of-2 witness script.
  - `contractFlags` and the mnemonic passphrase are required arguments.

  An earlier engine (`@bennyblader/ddk-ts` 0.3.x through 1.0.0-rc5) no longer
  satisfies `DdkInterface`. The `BitcoinDdkProvider` constructor throws when the
  engine lacks `FeeRule`, `createDlcTransactionsWithFeeRule` or
  `createSplicedDlcTransactionsWithFeeRule`, or when its `dlcInputMaxWitnessLen()`
  differs from `DLC_INPUT_MAX_WITNESS_LEN`, so an unsupported engine fails at
  startup instead of on a live contract.

  **The engine is ESM-only.** From CommonJS, load it with a real dynamic
  `import()`, which TypeScript's CommonJS output rewrites to `require()`; the
  integration tests do this in `tests/integration/utils/load-ddk.mjs`.

  **Single-funded offers reserve the ddk v2 fees.** From `ddk-dlc` 2.0.0-rc.4, the
  party that funds the whole contract pays the full funding and CET base weights
  and the CET fee for the other party's payout output. `createDlcOffer` now selects
  coins for, and checks its inputs against, that rule, reserving for a 34-byte
  acceptor payout script because the real one is not known yet.
  `calculateMaxCollateral` uses the same rule for a single contract. Dual-funded
  contracts do not change.

  **A counterparty still on `ddk-dlc` 1.x can still sign.** It builds a
  single-funded contract under the old fee rule, so its signatures do not verify
  against the current rule's transactions. `signDlcAccept` then rebuilds under the
  old rule and signs those transactions if the acceptor's signatures verify
  against them. The contract is created under the old rule, and `createDlcTxs`
  with its `dlcSign` rebuilds it the same way. The reverse is not covered: an
  offerer on `ddk-dlc` 1.x cannot verify an accept made with this release.

  **Existing contracts still close.** `createDlcTxs` takes an optional `dlcSign`
  (also on `client.dlc.createDlcTxs`). Pass it whenever the contract already
  exists, for example to restore or splice it: a single-funded contract created
  before `ddk-dlc` 2.0.0-rc.4 is rebuilt under the fee rule whose funding
  transaction reproduces the sign message's contract id, and the call throws if
  neither rule does, with each rule's failure in the error. The
  legacy rule is also tried when the current rule cannot build because the old
  inputs do not cover the new fee. `execute`, `refund` and `createDlcClose` use
  the transactions they are given and are unaffected.

### Minor Changes

- 5211f4a: Expose the CET adaptor signature debug helpers that `ddk-ts` has always
  shipped but `DdkInterface` never mirrored.

  `DdkInterface` gains `cetAdaptorSignatureInputs` and `cetSighash`, along with
  the `CetAdaptorSignatureDebugInfo` type.

  `BitcoinDdkProvider` gains two methods that resolve the funding script, oracle
  info and outcome messages for a CET and hand them to ddk:
  - `getCetAdaptorSignatureDetails(dlcOffer, dlcAccept, dlcTxs, cetIndex)` —
    returns the sighash, adaptor point, funding script, fund output value and raw
    CET used for that CET's adaptor signature.
  - `getCetSighash(dlcOffer, dlcAccept, dlcTxs, cetIndex)` — returns just the
    32-byte sighash, hex encoded.

  These are for diffing against a remote signer (e.g. Fordefi) when an adaptor
  signature is rejected, isolating whether the mismatch is in the sighash, the
  adaptor point, or the CET itself. They complement the existing
  `getFundingTransactionSighashDetails`.

- 5211f4a: Track the `@bennyblader/ddk-ts@1.0.0-rc1` API rename.

  `DdkInterface` members renamed to match the new NAPI surface:

  | Before                                    | After                               |
  | ----------------------------------------- | ----------------------------------- |
  | `addSignatureToTransaction`               | `addSignature`                      |
  | `createCetAdaptorSignatureFromOracleInfo` | `cetAdaptorSignatureFromOracleInfo` |
  | `getChangeOutputAndFees`                  | `changeOutputAndFees`               |
  | `getRawFundingTransactionInputSignature`  | `rawFundingInputSignature`          |
  | `isDustOutput`                            | `isDust`                            |
  | `signFundTransactionInput`                | `signFundInput`                     |
  | `verifyCetAdaptorSigFromOracleInfo`       | `verifyFromOracleInfo`              |
  | `verifyFundTxSignature`                   | `verifyFundSignature`               |

  No runtime behaviour changes — every `DdkInterface` method that BAL actually
  calls kept its name and signature in `1.0.0-rc1`.

  The unused legacy `declare function` block mirroring the same surface has been
  removed from `@atomicfinance/types`; import `DdkInterface` instead.

  The generated engine in `ddk-v2-engine` then moves every renamed member that
  operates on one record onto that record's namespace (for example
  `ddk.Transaction.addSignature`); see that changeset.

- 5211f4a: Replace the hardcoded DLC input witness length with a shared constant.

  `220` was written out at five call sites across three packages. It is now
  `DLC_INPUT_MAX_WITNESS_LEN`, exported from `@atomicfinance/types`.

  The constant is duplicated from ddk rather than read from it because
  `@atomicfinance/types` and the CFD-based `BitcoinDlcProvider` have no ddk
  instance to call. To stop the copy drifting, `DdkInterface` now declares
  `dlcInputMaxWitnessLen()` and `BitcoinDdkProvider.DdkLoaded()` throws if ddk's
  value and the constant disagree.

## 4.3.6

## 4.3.5

## 4.3.4

## 4.3.3

### Patch Changes

- 4ed94d2: Bump @node-dlc to 1.2.1, which estimates taproot witness length in fee calculations

## 4.3.2

### Patch Changes

- dd55924: Bump @node-dlc to 1.2.0, which preserves raw DLC change scripts (taproot change output support)

## 4.3.1

### Patch Changes

- 3df9ca2: Bump @node-dlc 1.1.9 and ddk-ts 0.3.41 to fix backward compatibility dlc protocol issues contract flags

## 4.3.0

### Minor Changes

- d041351: Add contractFlags parameter to DLC offer and transaction creation

## 4.2.8

### Patch Changes

- 82c2f2b: Lazy load ECC

## 4.2.7

### Patch Changes

- 8e9f8f0: Bump @node-dlc to 1.1.7

## 4.2.6

### Patch Changes

- 4f7eaa7: Bump @node-dlc to 1.1.15

## 4.2.5

### Patch Changes

- 295d995: Ensure contractId is not null for dlcFundingInput

## 4.2.4

### Patch Changes

- 735d7b9: Bump @node-dlc to 1.1.4

## 4.2.3

### Patch Changes

- f6e1e50: Bump @node-dlc to 1.1.3

## 4.2.2

### Patch Changes

- e0cda38: Fix fundingInputToInput derivationPath dlcInput

## 4.2.1

### Patch Changes

- 8d13721: Fix lexographic ordering dlc input pubkeys

## 4.2.0

### Minor Changes

- ec43a60: Implement DDK DLC splicing support + util refactor

### Patch Changes

- b718514: Refactor funding input sorting

## 4.1.13

### Patch Changes

- 9674167: Ensure consistent sequence numbers in funding sig verification

## 4.1.12

### Patch Changes

- 054a95e: Add Buffer.from() wrapper for React Native compatibility
- ebe6af2: Bump @node-dlc to 1.1.2 to fix react native buffer compatibility issues

## 4.1.11

### Patch Changes

- 4372f72: Wrap fromOutputScript in buffer for cross platform support

## 4.1.10

### Patch Changes

- 99f0550: Bump @node-dlc to 1.1.1 and ensure consistent oraclePublicKey

## 4.1.9

### Patch Changes

- 58031b0: React native compatibility

## 4.1.8

### Patch Changes

- e1d4e0d: Fix fund tx to use DER encoding for witness sig

## 4.1.7

### Patch Changes

- 1203f06: Ensure refund tx includes sequence from original refund tx ddk provider

## 4.1.6

### Patch Changes

- 5b7d9ea: Fix refund sig generation bitcoin ddk provider

## 4.1.5

### Patch Changes

- f1806a6: Implement rust-dlc/ddk compatible Contract ID computation

## 4.1.4

### Patch Changes

- 77dd82f: Ensure compact signatures for refund signatures in BitcoinDdkProvider

## 4.1.3

### Patch Changes

- bd75cc3: Ensure DER signature

## 4.1.2

### Patch Changes

- 5536d01: Add ensure buffer to BitcoinDdkProvider

## 4.1.1

### Patch Changes

- ece1dc1: Add DDK address derivation provider
- 0d882fc: Update changeset for ddk

## 4.1.0

### Minor Changes

- 0224065: Switch from yarn to pnpm and update eslint config

### Patch Changes

- b2394fa: Add alpha ddk support in BitcoinDdkProvider

## 4.0.3

### Patch Changes

- c7e9691: Update import modules organize imports

## 4.0.2

### Patch Changes

- 79a403b: Fix typescript strict mode compilation errors

## 4.0.1

### Patch Changes

- 03c6974: Add DLC input splicing support

  This release introduces DLC (Discreet Log Contract) input splicing functionality, enabling more flexible contract funding and management.

  ## Key Features
  - **Core Types**: Added new types and interfaces for DLC input splicing operations
  - **Provider Integration**: Implemented splicing support in BitcoinDlcProvider with proper input handling
  - **Comprehensive Testing**: Added integration tests to validate splicing functionality
  - **Dependency Updates**: Upgraded @node-dlc to v1.1.0 for enhanced splicing capabilities

  ## What's New
  - DLC contracts can now be funded using spliced inputs
  - Enhanced input selection and handling for splicing operations
  - Improved test coverage for edge cases in DLC splicing scenarios

  This feature enables more efficient Bitcoin transaction management when working with DLC contracts by allowing existing UTXOs to be split and used as contract inputs.

- d94fbbf: Fix TypeScript ESLint compatibility and improve type safety
  - Upgrade @typescript-eslint dependencies to v6.21.0 for TypeScript 4.9.5 support

- b83e3a8: Add single-funded DLC support and update to node-dlc v1.0.1
  - Add comprehensive single-funded DLC support to BitcoinDlcProvider
  - Update @node-dlc dependencies to v1.0.1 with single-funded support
  - Update cfd-dlc-js to v0.0.52
  - Implement single-funded DLC detection and validation logic
  - Handle acceptDlcOffer with 0 collateral scenarios (no funding)
  - Fix fundTxVout calculation for parties with collateral only
  - Add getFundOutputValueSats helper with proper error handling
  - Add markAsSingleFunded() calls for proper DLC type identification
  - Skip funding validation when accept collateral is 0
  - Generate addresses/keys without requiring funding inputs

  Enables single-funded DLCs where one party provides all collateral
  while the other party participates without funding inputs.

## 4.0.0

### Major Changes

- 8989c75: Upgrade to @node-dlc v1.0.0

  ## Breaking Changes

  This release upgrades to @node-dlc v1.0.0 with significant breaking changes:

  ### Dependencies
  - Upgraded @node-dlc packages from 0.24.0 to ^1.0.0
  - Minimum Node.js version now 18.18.2
  - Added decimal.js dependency for F64 type support

  ### API Changes
  - **Message Types**: Removed versioned suffixes (DlcOfferV0 → DlcOffer)
  - **Property Names**:
    - `fundingPubKey` → `fundingPubkey`
    - `payoutSPK` → `payoutSpk`
    - `changeSPK` → `changeSpk`
    - `cetSignatures` → `cetAdaptorSignatures`
    - `tempContractId` → `temporaryContractId`

  ### Type System
  - **Contract Descriptors**: V0/V1 types replaced with Enumerated/Numerical descriptors
  - **Oracle Types**: OracleInfoV0 → SingleOracleInfo/MultiOracleInfo
  - **Message Validation**: Switched from type-based to property-based checking
  - **Enum Outcomes**: Migrated from Buffer to string format

  ### New Features
  - Enhanced oracle event descriptor handling
  - Improved decimal precision with F64 types
  - Fallback outcome index search algorithm
  - Auto-generation of temporary contract IDs

  ## Migration Guide

  ### Code Updates Required

  ```javascript
  // Before
  const dlcOffer = new DlcOfferV0();
  dlcOffer.fundingPubKey = pubkey;
  dlcOffer.payoutSPK = spk;

  // After
  const dlcOffer = new DlcOffer();
  dlcOffer.fundingPubkey = pubkey;
  dlcOffer.payoutSpk = spk;
  ```

  ### Environment
  - Update Node.js to 18.18.2+
  - Run `yarn install` to update dependencies
  - Review custom DLC implementations for compatibility

  This is a **major breaking change** requiring code updates in consuming applications.

## 3.6.1

### Patch Changes

- 3c85279: Upgrade bitcoinjs-lib v6 with ECPair migration

## 3.6.0

### Minor Changes

- cbf35c5: - **BREAKING CHANGE**: Migrated from `@node-lightning` packages to `@node-dlc` packages
  - Updated all imports from `@node-lightning/*` to `@node-dlc/*`
  - Update @node-dlc 0.24.0 and Node 18+
  - Upgraded Node.js requirement to v18+
  - Updated cfd-dlc-js to v0.0.51 and cfd-js to v0.3.13
  - Removed unused dependencies: lerna, mocha-webpack

## 3.5.3

### Patch Changes

- 87ff085: Fix enum hashed outcomes

## 3.5.2

### Patch Changes

- 3e8815c: Add support for Enum DLCs

## 3.5.1

### Patch Changes

- 9aa93d3: Fix types for bitcoin-rpc-provider

## 3.5.0

### Minor Changes

- fb279b7: Update dependencies for Node LTS and fix payout index edge cases

## 3.4.7

### Patch Changes

- 0ba01ef: Bump @node-dlc to 0.23.6

## 3.4.6

### Patch Changes

- b765b9c: Bump nodep-dlc to 0.23.5

## 3.4.5

### Patch Changes

- 74b7a4f: Bump node-dlc to 0.23.4

## 3.4.4

### Patch Changes

- cc8f06a: Bump node-dlc to 0.23.3

## 3.4.3

### Patch Changes

- db49017: Bump node-dlc to 0.23.2 for all packages

## 3.4.2

### Patch Changes

- e701ba6: Bump node-dlc- to 0.23.1 and add node-dlc batch tx builder validation tests

## 3.4.1

### Patch Changes

- 9781efe: Add getInputsForDualFunding functionality and bump @node-dlc

## 3.4.0

### Minor Changes

- 314d7d7: Add batch dlc funding transactions

## 3.3.1

### Patch Changes

- 7f6f4a8: Fix rounding error with find payout

## 3.3.0

### Minor Changes

- 4a512ee: Fix find outcome index for hyperbola payout curve edge case

## 3.2.5

### Patch Changes

- a72c7b9: Bump node-dlc to 0.22.4 for all packages

## 3.2.4

### Patch Changes

- 177b76a: Upgrade node-dlc to 0.22.4

## 3.2.3

## 3.2.2

## 3.2.1

### Patch Changes

- f69141e: Bump @node-dlc to 0.21.2 to improve env compatibility

## 3.2.0

### Minor Changes

- dc9ac8a: Bump node-dlc to 0.21.0 for fee shifting and rounding intervals for cso

## 3.1.1

## 3.1.0

### Minor Changes

- c60033b: Fix DLC Input Ordering

## 3.0.1

## 3.0.0

### Major Changes

- a06082e: Create unified standalone `bitcoin-abstraction-layer` package

## 2.5.1

### Patch Changes

- Upgrade various package dependencies
