@smartledger/bsv 9.11.2 → 9.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bsv.d.ts CHANGED
@@ -983,21 +983,46 @@ declare module '@smartledger/bsv' {
983
983
  // -------- SPV (trustless Merkle inclusion proofs) -------------------
984
984
 
985
985
  export namespace SPV {
986
+ /**
987
+ * The easiest target a header may declare and still be believed: difficulty 1,
988
+ * 0x1d00ffff, the proof-of-work limit of mainnet and testnet. Regtest declares
989
+ * 0x207fffff, so regtest headers need `powLimit` set explicitly.
990
+ *
991
+ * This rules out a FREE forgery, not a cheap one: a header at difficulty 1 costs
992
+ * about 4.3e9 double-SHA256 attempts, against about 1e20 for a real mainnet header.
993
+ * Use `minWork`, or check the header against your own chain source.
994
+ */
995
+ const POW_LIMIT_BITS: number;
986
996
  /** A Merkle branch proof. All hashes are DISPLAY-order hex; a node of '*' means "duplicate the working hash". */
987
997
  interface MerkleProof { txid: string; index: number; nodes: string[]; merkleRoot: string; }
988
998
  interface InclusionParams {
989
999
  txid: string;
990
1000
  index: number;
991
1001
  nodes: string[];
992
- /** a bsv.BlockHeader, an 80-byte Buffer, or 80-byte hex. */
1002
+ /** a bsv.BlockHeader, an 80-byte Buffer, or 80-byte hex. Nothing else is a header. */
993
1003
  header: any;
994
- /** default true — require the header to meet its proof-of-work target. */
1004
+ /** default true — require the header's proof of work, its declared target and `minWork`. */
995
1005
  requirePow?: boolean;
1006
+ /**
1007
+ * The easiest target a header may declare, as compact bits (number or hex string)
1008
+ * or a BN target. Defaults to POW_LIMIT_BITS; regtest needs 0x207fffff. A header
1009
+ * declares its own target, so without this a forged header costs nothing to make.
1010
+ */
1011
+ powLimit?: number | string | object;
1012
+ /** Minimum work the header must represent: 2^256 / (target + 1). Difficulty 1 is about 4.295e9. */
1013
+ minWork?: number | string | object;
996
1014
  }
997
1015
  interface InclusionResult {
998
1016
  valid: boolean;
999
1017
  rootMatches: boolean;
1018
+ /** The header meets the target it declares for itself. */
1000
1019
  powValid: boolean;
1020
+ /** That declared target is no easier than `powLimit`. True when not checked. */
1021
+ targetAllowed: boolean;
1022
+ /** The work it represents is at least `minWork`. True when not checked. */
1023
+ workSufficient: boolean;
1024
+ /** Work the header represents, as a decimal string. */
1025
+ work: string;
1001
1026
  merkleRoot: string;
1002
1027
  blockHash: string;
1003
1028
  }
@@ -1699,6 +1724,27 @@ declare module '@smartledger/bsv' {
1699
1724
  * it to have it checked against `spv.blockHeight`.
1700
1725
  */
1701
1726
  height?: number;
1727
+ /**
1728
+ * The block hash the caller's own chain source has at that height. No amount of
1729
+ * proof of work detects an orphan: a block that lost a race carries real work.
1730
+ *
1731
+ * Supplying this or `minWork` will be REQUIRED in 10.0.0: the proof-of-work limit
1732
+ * rules out a free forgery, not a cheap one — a header at difficulty 1 costs about
1733
+ * 4.3e9 hashes, while a real mainnet header carries about 1e20. Verifying with a
1734
+ * header alone warns since 9.13.0.
1735
+ */
1736
+ blockHashAtHeight?: string;
1737
+ /**
1738
+ * The easiest target the header may declare, as compact bits. Defaults to
1739
+ * SPV.POW_LIMIT_BITS (difficulty 1); regtest headers need 0x207fffff.
1740
+ */
1741
+ powLimit?: number | string;
1742
+ /**
1743
+ * Minimum work the header must represent. Difficulty 1 is about 4.295e9, and a
1744
+ * real mainnet header carries about 1e20. Either this or `blockHashAtHeight` will
1745
+ * be required in 10.0.0.
1746
+ */
1747
+ minWork?: number | string;
1702
1748
  /** Pass false only for test fixtures. Defaults to true. */
1703
1749
  requirePow?: boolean;
1704
1750
  }