@inversealtruism/cairnx-core 0.2.3 → 0.2.7

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/dist/index.d.cts CHANGED
@@ -1,5 +1,138 @@
1
+ import { App, TxOutput } from '@inversealtruism/csd-codec';
1
2
  export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PROPOSE, blockReward, canonicalJson, epochOf, payloadHash } from '@inversealtruism/csd-codec';
2
3
 
4
+ declare const TABLE: {
5
+ readonly TOKEN_DEPLOYED: "applied";
6
+ readonly TOKEN_MINTED: "applied";
7
+ readonly TOKEN_TRANSFERRED: "applied";
8
+ readonly TOKEN_META_SET: "applied";
9
+ readonly NAME_COMMITTED: "applied";
10
+ readonly NAME_REGISTERED: "applied";
11
+ readonly NAME_REGISTERED_DISPLACED: "applied";
12
+ readonly NAME_RESERVED: "applied";
13
+ readonly NAME_RESERVED_DISPLACED: "applied";
14
+ readonly NAME_RECAPTURE_RESERVED: "applied";
15
+ readonly NAME_RECAPTURE_RESERVED_DISPLACED: "applied";
16
+ readonly NAME_RECLAIMED: "applied";
17
+ readonly NAME_FINALIZED: "applied";
18
+ readonly NAME_RECAPTURE_FINALIZED: "applied";
19
+ readonly NAME_TRANSFERRED: "applied";
20
+ readonly NAME_ADDR_SET: "applied";
21
+ readonly NAME_PROFILE_SET: "applied";
22
+ readonly NAME_RENEWED: "applied";
23
+ readonly OFFER_CREATED: "applied";
24
+ readonly OFFER_BULK_CANCELLED: "applied";
25
+ readonly OFFER_CANCELLED: "applied";
26
+ readonly BID_CREATED: "applied";
27
+ readonly BID_CANCELLED: "applied";
28
+ readonly FILL_APPLIED: "applied";
29
+ readonly FILL_PARTIAL: "applied";
30
+ readonly CLAIM_GRANTED: "applied";
31
+ readonly GATE_NOT_ACTIVE: "refused";
32
+ readonly CLAIM_LEGACY_SUNSET: "refused";
33
+ readonly TOKEN_TICKER_TAKEN: "refused";
34
+ readonly TOKEN_UNKNOWN: "refused";
35
+ readonly TOKEN_NOT_ISSUER: "refused";
36
+ readonly TOKEN_SUPPLY_EXHAUSTED: "refused";
37
+ readonly TOKEN_MINT_AMOUNT_REQUIRED: "refused";
38
+ readonly TOKEN_BALANCE_LOW: "refused";
39
+ readonly TREASURY_FEE_UNPAID: "refused";
40
+ readonly NAME_NO_COMMIT: "refused";
41
+ readonly NAME_SALT_REQUIRED: "refused";
42
+ readonly NAME_TAKEN_EARLIER: "refused";
43
+ readonly NAME_TAKEN_PURCHASED: "refused";
44
+ readonly NAME_SALT_MISMATCH: "refused";
45
+ readonly NAME_FINALIZE_TOO_EARLY: "refused";
46
+ readonly NAME_RESERVATION_EXPIRED: "refused";
47
+ readonly NAME_NOT_LAPSED: "refused";
48
+ readonly NAME_NO_RESERVATION: "refused";
49
+ readonly NAME_NOT_OWNER: "refused";
50
+ readonly NAME_PENDING: "refused";
51
+ readonly NAME_LAPSED: "refused";
52
+ readonly NAME_NO_LIVE_LEASE: "refused";
53
+ readonly NAME_GRACE_OWNER_ONLY: "refused";
54
+ readonly NAME_LOCKED: "refused";
55
+ readonly NAME_TOO_YOUNG: "refused";
56
+ readonly OFFER_LEASE_TOO_SHORT: "refused";
57
+ readonly OFFER_TAKER_REQUIRED: "refused";
58
+ readonly OFFER_PAYTO_TREASURY: "refused";
59
+ readonly OFFER_UNKNOWN: "refused";
60
+ readonly OFFER_NOT_OPEN: "refused";
61
+ readonly OFFER_NOT_SELLER: "refused";
62
+ readonly OFFER_FIRM_QUOTE: "refused";
63
+ readonly OFFER_CANCEL_HOLD_LIVE: "refused";
64
+ readonly OFFER_CLOSED_BEFORE_CANCEL: "refused";
65
+ readonly BID_NOT_BIDDER: "refused";
66
+ readonly BID_NOT_OPEN: "refused";
67
+ readonly EXPIRY_UNSAFE: "refused";
68
+ readonly EXPIRY_PAST: "refused";
69
+ readonly EXPIRY_TOO_LONG: "refused";
70
+ readonly FILL_FCLAIM_NOT_CURRENT: "refused";
71
+ readonly FILL_NOT_TAKER: "refused";
72
+ readonly FILL_NO_TOKEN_MARKER: "refused";
73
+ readonly FILL_OPEN_LANE_CLOSED: "refused";
74
+ readonly FILL_WRONG_TARGET: "refused";
75
+ readonly FILL_NO_LIVE_CLAIM: "refused";
76
+ readonly FILL_BELOW_MIN: "refused";
77
+ readonly FILL_ZERO_DELIVERY: "refused";
78
+ readonly FILL_UNDERPAID: "refused";
79
+ readonly FILL_REBATE_UNPAID: "refused";
80
+ readonly CLAIM_TAKER_BOUND: "refused";
81
+ readonly CLAIM_TOKEN_PRICED: "refused";
82
+ readonly CLAIM_HOLD_LIVE: "refused";
83
+ readonly CLAIM_COOLDOWN: "refused";
84
+ readonly CLAIM_OUTLIVES_OFFER: "refused";
85
+ readonly CLAIM_TOO_FAR_AHEAD: "refused";
86
+ readonly CAP_PENDING_RESERVATIONS: "refused";
87
+ readonly CAP_PENDING_RECAPTURES: "refused";
88
+ readonly CAP_LIVE_HOLDS: "refused";
89
+ readonly INVARIANT_BROKEN: "refused";
90
+ readonly RECORD_TOO_LARGE: "refused";
91
+ readonly RECORD_NOT_OBJECT: "refused";
92
+ readonly RECORD_NOT_CANONICAL: "refused";
93
+ readonly RECORD_HASH_MISMATCH: "refused";
94
+ readonly RECORD_LONE_SURROGATE: "refused";
95
+ readonly RECORD_NOT_V1: "refused";
96
+ readonly RECORD_UNKNOWN_TYPE: "refused";
97
+ readonly RECORD_EXTRA_KEY: "refused";
98
+ readonly RECORD_BAD_SHAPE: "refused";
99
+ readonly RECORD_SAME_TOKEN: "refused";
100
+ readonly RECORD_BAD_TICKER: "refused";
101
+ readonly RECORD_BAD_NAME: "refused";
102
+ readonly RECORD_NAME_RESERVED: "refused";
103
+ readonly RECORD_BAD_ADDRESS: "refused";
104
+ readonly RECORD_BAD_AMOUNT: "refused";
105
+ readonly RECORD_AMOUNT_TOO_LARGE: "refused";
106
+ readonly RECORD_AMOUNT_ZERO: "refused";
107
+ readonly RECORD_MIN_ABOVE_WANT: "refused";
108
+ readonly RECORD_BAD_HASH: "refused";
109
+ readonly RECORD_BAD_SALT: "refused";
110
+ readonly RECORD_BAD_DECIMALS: "refused";
111
+ readonly RECORD_BAD_MINT_MODE: "refused";
112
+ readonly RECORD_BAD_TEXT: "refused";
113
+ readonly RECORD_BAD_TS: "refused";
114
+ readonly RECORD_PROFILE_TOO_MANY_KEYS: "refused";
115
+ readonly RECORD_PROFILE_BAD_KEY: "refused";
116
+ readonly RECORD_PROFILE_BAD_VALUE: "refused";
117
+ readonly RECORD_PROFILE_VALUE_TOO_LONG: "refused";
118
+ };
119
+ /** A reason code of the applied log or of record validation. */
120
+ type ReasonCode = keyof typeof TABLE;
121
+ /** The codes of an applied record (`ok: true`). */
122
+ type AppliedCode = {
123
+ [K in ReasonCode]: (typeof TABLE)[K] extends "applied" ? K : never;
124
+ }[ReasonCode];
125
+ /** The codes of a refused record (`ok: false`). */
126
+ type RefusalCode = Exclude<ReasonCode, AppliedCode>;
127
+ /** The codes of a record that does not parse (explainRecord, RecordError, the log's `invalid` entries). */
128
+ type RecordCode = Extract<ReasonCode, `RECORD_${string}`>;
129
+ /** Every code, in table order. */
130
+ declare const REASON_CODES: readonly ReasonCode[];
131
+ /** Each code's outcome. A reader meets codes added after its release, so it classifies an unknown code by the entry's `ok`. */
132
+ declare const REASON_CODE_OUTCOME: Readonly<Record<ReasonCode, "applied" | "refused">>;
133
+ /** The refusals CONVENTION §40 calls caps: per-address rules that count the proposer's other names or offers. */
134
+ declare const CAP_CODES: readonly ["CAP_PENDING_RESERVATIONS", "CAP_PENDING_RECAPTURES", "CAP_LIVE_HOLDS"];
135
+
3
136
  declare const DOMAIN = "cairnx:v1";
4
137
  declare const ACTIVATION_HEIGHT = 29860;
5
138
  /** True below ACTIVATION_HEIGHT, where resolve() skips every event without a note. */
@@ -85,6 +218,7 @@ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => nu
85
218
  declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
86
219
  declare const fclaimHoldEnd: (expiresEpoch: number) => number;
87
220
  declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
221
+ declare const offerFillTooLate: (expiresAt: number, tip: number) => boolean;
88
222
  interface DeployRecord {
89
223
  v: 1;
90
224
  t: "deploy";
@@ -345,6 +479,9 @@ interface AppliedEvent {
345
479
  id: string;
346
480
  kind: string;
347
481
  ok: boolean;
482
+ /** The rule that decided the record (CONVENTION §40); every entry resolve() writes carries one. Optional in the type:
483
+ * a log built by hand or by a core before 0.2.6 has none. */
484
+ code?: ReasonCode;
348
485
  note?: string;
349
486
  }
350
487
  interface CairnXState {
@@ -409,10 +546,24 @@ declare const FCLAIM_KEYS: Set<string>;
409
546
  * Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
410
547
  * per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
411
548
  * Requirements enforced here: uri is canonical JSON of the record, ≤512 bytes,
412
- * payload_hash commits to it, schema rules of §4.
549
+ * payload_hash commits to it, schema rules of §4. explainRecord says which rule refused it.
413
550
  */
414
551
  declare function parseRecord(uri: string, payloadHashHex: string): CairnXRecord | null;
415
- /** Build (and self-validate) a record → {record, uri, payloadHash} ready to anchor. */
552
+ /** parseRecord with its reason: the record, or the code of the first rule it breaks in parseRecord's order (CONVENTION
553
+ * §40). parseRecord answers null exactly when this answers ok: false: both read one implementation. */
554
+ declare function explainRecord(uri: string, payloadHashHex: string): {
555
+ ok: true;
556
+ record: CairnXRecord;
557
+ } | {
558
+ ok: false;
559
+ code: RecordCode;
560
+ };
561
+ /** A record builder's refusal: the record does not validate, and `code` names the first rule it breaks (CONVENTION §40). */
562
+ declare class RecordError extends Error {
563
+ readonly code: RecordCode;
564
+ constructor(code: RecordCode);
565
+ }
566
+ /** Build (and self-validate) a record → {record, uri, payloadHash} ready to anchor; a RecordError names the rule it breaks. */
416
567
  declare function buildRecord(record: CairnXRecord): BuiltRecord;
417
568
  declare const deploy: (r: Omit<DeployRecord, "v" | "t">) => BuiltRecord;
418
569
  declare const mint: (r: Omit<MintRecord, "v" | "t">) => BuiltRecord;
@@ -432,6 +583,14 @@ declare const fclaim: (r: Omit<FclaimRecord, "v" | "t">) => BuiltRecord;
432
583
 
433
584
  declare function ptAmt(v: unknown): bigint;
434
585
 
586
+ /** An event's id (CONVENTION §33.4): a Propose's id, an Attest's transaction id. */
587
+ declare function eventId(e: ChainEvent): string;
588
+ /** The apply order of CONVENTION §3 and §33.3, the comparator resolve() sorts its events with: height, a block's
589
+ * Proposes before its Attests, position, then the ordinal order of the id. Negative when `a` applies before `b`, zero
590
+ * when all four keys are equal (the same event, or a repeated one, which a stable sort keeps in input order).
591
+ * Defined for events the rule of §33 builds: a kind of "propose" or "attest", integer height and position, a string id.
592
+ * Outside that domain the result is unspecified: a NaN key compares as equal. */
593
+ declare function applyOrder(a: ChainEvent, b: ChainEvent): number;
435
594
  declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
436
595
  /** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
437
596
  * The canonical surface is the DATA ONLY: {tipHeight, tokens, balances, names, offers, bids,
@@ -447,15 +606,21 @@ declare const CLAIM_MIN_DEPTH = 3;
447
606
  declare const COMMIT_REVEAL_MIN_DEPTH = 3;
448
607
  /**
449
608
  * Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
450
- * (anchored at `height`) is reorg-safe. Returns `{ depth, reversalPct, capped }`; `capped=true` ⇒ the value
451
- * exceeds what one claim window can safely settle (the buyer should split the trade).
609
+ * (anchored at `height`), so that a minority miner undoing the claim is unlikely. Returns
610
+ * `{ depth, reversalPct, capped }`; `reversalPct` is that miner's chance of reversing `depth` blocks, positive at every depth;
611
+ * `capped=true` ⇒ the value exceeds what one claim window can settle (the buyer should split the trade).
452
612
  *
453
- * A MINORITY attacker (the dominant pool is trusted; a majority means the chain is already lost) only profits
454
- * if `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
613
+ * The model is a miner with `CLAIM_ATTACKER_Q` of the hashrate. It only profits if
614
+ * `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
455
615
  * Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
456
616
  * in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
457
617
  * capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
458
618
  * absurd > total-supply values ever reach the cap).
619
+ *
620
+ * The pool that produces most blocks is outside this model. It is an external party, not run by Cairn; no depth
621
+ * bounds a producer with more than half the hashrate (the reversal chance is 1 at q ≥ 0.5), and reordering recent
622
+ * blocks costs it almost nothing, since it re-mines them and keeps their rewards. The wait guards against smaller
623
+ * miners only.
459
624
  */
460
625
  declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
461
626
  depth: number;
@@ -653,6 +818,7 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
653
818
  /** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
654
819
  declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
655
820
 
821
+ declare const FCLAIM_MAX_HOLD_SPAN: number;
656
822
  declare const GAP_NEEDED: number;
657
823
  declare const SCAN_MARGIN = 30;
658
824
  declare const MAX_SCAN: number;
@@ -685,9 +851,13 @@ interface FillVerdict {
685
851
  * MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
686
852
  * `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
687
853
  * fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
688
- * Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
689
- * refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
690
- * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
854
+ * Over a window that holds the offer's history it refuses the doomed/forged cases (a denied fclaim a lying
855
+ * resolver calls "granted", a cancelled/lapsed or not-mine hold, a below-depth signing, a zero-delivery fill, a
856
+ * stranded past-deadline broadcast) and one honest case on purpose: the cap count. `opts.myLiveHoldsAtGrant`, as
857
+ * countOtherHoldsAtGrant computes it, counts the buyer's earlier fclaims on other offers whether or not the chain
858
+ * granted them (a denial is not visible to it), so a buyer whose three such fclaims were all denied is refused a
859
+ * later fill the chain granted. Over-counting refuses; under-counting would let a cap-denied fill burn. Over a
860
+ * window that lacks part of the history, see "Known limits" below.
691
861
  *
692
862
  * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
693
863
  * THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
@@ -699,13 +869,38 @@ interface FillVerdict {
699
869
  * without it there is nothing to bind. A caller that omits it keeps the overpay exposure described next.
700
870
  * `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
701
871
  * caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
702
- * the merkle-proven, replayed offer (so `paid`/`delivered` are the chain's, not a served lie) and the caller's
703
- * map must match it EXACTLY, address for address. This closes the W3 overpay: a resolver serving `paid:"0"`
704
- * for a 90%-filled partial made callers size the FULL want while the chain credits only the remainder - the
705
- * difference was permanently overpaid. Pass the SAME per-address sums you will build (the wallet's need-map
872
+ * the merkle-proven, replayed offer and the caller's map must match it EXACTLY, address for address. The
873
+ * replayed `paid`/`delivered` are the chain's only inside the window the seam read: a fill whose fclaim lies
874
+ * below it is not replayed. Inside the window this closes the W3 overpay: a resolver serving `paid:"0"` for a
875
+ * 90%-filled partial made callers size the FULL want while the chain credits only the remainder. Pass the SAME
876
+ * per-address sums you will build (the wallet's need-map
706
877
  * shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
707
878
  * DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
708
879
  * wallet's per-address sum includes the maker rebate when payto === seller; the site passes no pay at all).
880
+ *
881
+ * Known limits: the replay sees only the window the seam read, and reading the history below it is not
882
+ * implemented. verifyFillSpv takes no served offer and decides from the proven window alone, so each limit says
883
+ * first what holds for a caller that uses only verifyFillSpv (with an honest resolver unless stated), then what
884
+ * the checks of the site and the wallet add. A third-party caller has only the first unless it adds such checks.
885
+ * - The grant replay (step 5): an fclaim the window does not decide (the GAP_NEEDED note) can replay as
886
+ * granted. A hold chain that starts below the window can make verifyFillSpv grant the caller's own fclaim
887
+ * that the chain denied, and the whole fill burns, with an honest resolver. A caller closes it by signing only
888
+ * while the served offer names its own fclaim as the current hold: the site fills only when the served claim
889
+ * state is the buyer's, so for the site it needs a resolver that serves the false hold; the wallet refuses when
890
+ * its second-source offer read reports another reservation holding the offer through the buyer's hold. A third
891
+ * party's fclaim the cap denied can also replay as granted with its fill credited, raising the replayed
892
+ * `paid`: against sums sized from an honest served offer that only refuses, and it pays wrong only when the
893
+ * served `paid` matches the raised one.
894
+ * - Delivery (step 6), aged fills: a fill whose fclaim lies below the window is not replayed, so the replayed
895
+ * `paid` is too low, with an honest resolver. A tail below the offer's `min` replays as below-min and an honest
896
+ * buy is refused. For a coarse give (a payment worth less than one unit, `give * pay < want`) the delivery
897
+ * check can disagree with the chain's in either direction: it can refuse an honest buy, or accept a payment the
898
+ * chain refuses after it moved. A caller refuses a payment its served offer computes as undeliverable
899
+ * (previewFill) instead of relying on this check for it.
900
+ * - The sums bind (step 6b): it passes a payment sized from a served offer that omits such a fill and serves the
901
+ * matching lower `paid`, and the payment overpays. That needs the resolver the caller sizes from to omit the
902
+ * fill; for the site and the wallet that is the project's own resolver (host-only), and the wallet's
903
+ * second-source offer read bounds it.
709
904
  */
710
905
  declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
711
906
  myLiveHoldsAtGrant: number;
@@ -794,6 +989,72 @@ declare function burnedPayment(paidTo: Readonly<Record<string, unknown>> | undef
794
989
  counterparty: bigint;
795
990
  };
796
991
 
992
+ /** The domain and the activation height the rule selects for. */
993
+ interface EventRule {
994
+ readonly domain: string;
995
+ readonly activationHeight: number;
996
+ }
997
+ /** CairnX: `cairnx:v1` from height 29,860. */
998
+ declare const CAIRNX_EVENT_RULE: EventRule;
999
+ /** One mined transaction: its position in the block (the coinbase is 0), its txid, and its body decoded with u64
1000
+ * values exact (a bigint, or a number up to 2^53). csd-light's BoundTx is one. */
1001
+ interface EventRuleTx {
1002
+ readonly pos: number;
1003
+ readonly txid: string;
1004
+ readonly tx: {
1005
+ readonly app: App;
1006
+ readonly outputs: readonly TxOutput[];
1007
+ };
1008
+ }
1009
+ /** The caller's record of the events below the block it reads, rolled back with them on a reorganisation: every event
1010
+ * id (a Propose's id, an Attest's txid, `0x` and lowercase hex) and the Propose ids among them. */
1011
+ interface EventsSoFar {
1012
+ readonly eventIds: {
1013
+ has(id: string): boolean;
1014
+ };
1015
+ readonly proposeIds: {
1016
+ has(id: string): boolean;
1017
+ };
1018
+ }
1019
+ /** A transaction of a block that is an event, so its author must be bound. */
1020
+ interface EventMember<T extends EventRuleTx> {
1021
+ readonly kind: "propose" | "attest";
1022
+ readonly item: T;
1023
+ }
1024
+ /** The event of one transaction at `height`, or null when it carries no app payload, lies below the activation height
1025
+ * or is a Propose in another domain. Attest membership needs the block and is not decided here: an Attest maps to an
1026
+ * event whatever its proposal, and a per-transaction caller decides membership itself (resolve() ignores an Attest on
1027
+ * a proposal it does not hold). Throws on a field out of its consensus type, a payload at position 0, or an event's
1028
+ * author that is not an address. */
1029
+ declare function eventOfTx(t: EventRuleTx, height: number, author: string, rule?: EventRule): ChainEvent | null;
1030
+ /** The members of one block in position order: the transactions whose authors the caller binds. `txs` lists, in
1031
+ * strictly increasing position order, every transaction of the block that carries an app payload (a complete block
1032
+ * is one such list). Throws on a list that is no block of the chain: positions out of order, a txid repeated, a
1033
+ * payload at position 0. Nothing of a block below the activation height is read. */
1034
+ declare function blockMembers<T extends EventRuleTx>(height: number, txs: readonly T[], sofar: EventsSoFar, rule?: EventRule): EventMember<T>[];
1035
+ /** The block's events in apply order (Proposes by position, then Attests by position), `authors[i]` being the author
1036
+ * of `blockMembers(...)[i]`. The members are selected again here, so an author list that does not match them throws:
1037
+ * a member whose author cannot be bound leaves the block without events, never without that event. */
1038
+ declare function blockEvents(height: number, txs: readonly EventRuleTx[], sofar: EventsSoFar, authors: readonly string[], rule?: EventRule): ChainEvent[];
1039
+
1040
+ /** The fields of an event the events hash reads; a ChainEvent is one. */
1041
+ type HashedEvent = Pick<ProposeEvent, "kind" | "id" | "proposer" | "height" | "pos"> | Pick<AttestEvent, "kind" | "txid" | "attester" | "height" | "pos">;
1042
+ /** The events hash before the first block that holds an event: 32 zero bytes. */
1043
+ declare const EVENTS_HASH_START: string;
1044
+ /** How far below its tip a replica holds an epoch boundary before it publishes or compares the tuple there (§38). It
1045
+ * is the depth replicas compare at, not a bound on how deep a reorganisation can reach. */
1046
+ declare const FINAL_DEPTH = 12;
1047
+ /** sha256 of the UTF-8 bytes of canonicalState(state), `0x` and lowercase hex (§34.1). */
1048
+ declare function stateHash(state: CairnXState): string;
1049
+ /** The events hash after one block (§34.2) from the value `prev`: `events` are that block's, in any order, hashed in
1050
+ * ascending position. A block without events leaves `prev`. The previous block's height is not an input, so a caller
1051
+ * that steps block by block keeps the blocks in ascending height itself. */
1052
+ declare function eventsHashStep(prev: string, height: number, events: readonly HashedEvent[]): string;
1053
+ /** The events hash over a list from the start value (§34.2): the list is in the order of §33.3, or in one that differs
1054
+ * from it only within a block, so each height forms one run. A height below the run before it is refused, never
1055
+ * sorted: resolve() sorts its input, this function does not. */
1056
+ declare function eventsHash(events: readonly HashedEvent[]): string;
1057
+
797
1058
  /**
798
1059
  * True only when `fill` proves `me`'s own fill CLOSED the offer behind `fclaim` before `grantHeight`, so a
799
1060
  * resolver at a grant height >= V29_HEIGHT no longer counts that hold. `fill` and `offerEv` must be
@@ -857,4 +1118,4 @@ interface ProvenOfferTx {
857
1118
  * rules; the resolver writes no note below activation), or null when it passes. */
858
1119
  declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
859
1120
 
860
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BindTermsOpts, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FCLAIM_WINDOW_MIN, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEndorsement, type FillEntry, type FillOutputPlan, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, MINT_KEYS, type MintRecord, type MintedProvenOfferTerms, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, type ProvenAttest, type ProvenEvent, type ProvenOfferTerms, type ProvenOfferTx, type ProvenPropose, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCAN_MARGIN, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, V27_HEIGHT, V28_HEIGHT, V29_HEIGHT, type Want, ZERO_ADDR, beforeActivation, bid, bindOfferTerms, bindProvenOffer, buildFeeHeight, buildRecord, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
1121
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedCode, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BindTermsOpts, type BuiltRecord, CAIRNX_EVENT_RULE, CAP_CODES, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, EVENTS_HASH_START, type EventMember, type EventRule, type EventRuleTx, type EventsSoFar, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FCLAIM_MAX_HOLD_SPAN, FCLAIM_WINDOW_MIN, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, FINAL_DEPTH, type FclaimRecord, type FillEndorsement, type FillEntry, type FillOutputPlan, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HashedEvent, type HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, MINT_KEYS, type MintRecord, type MintedProvenOfferTerms, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, type ProvenAttest, type ProvenEvent, type ProvenOfferTerms, type ProvenOfferTx, type ProvenPropose, REASON_CODES, REASON_CODE_OUTCOME, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, type ReasonCode, type RecordCode, RecordError, type RefusalCode, SALT_RE, SCAN_MARGIN, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, V27_HEIGHT, V28_HEIGHT, V29_HEIGHT, type Want, ZERO_ADDR, applyOrder, beforeActivation, bid, bindOfferTerms, bindProvenOffer, blockEvents, blockMembers, buildFeeHeight, buildRecord, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, eventId, eventOfTx, eventsHash, eventsHashStep, expiredClaimFee, explainRecord, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, offerFillTooLate, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, stateHash, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };