@inversealtruism/cairnx-core 0.1.35 → 0.1.37
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/CONVENTION.md +153 -22
- package/MAKERS.md +5 -1
- package/README.md +17 -6
- package/dist/index.cjs +266 -30
- package/dist/index.d.cts +105 -10
- package/dist/index.d.ts +105 -10
- package/dist/index.js +245 -22
- package/package.json +2 -2
- package/test/vectors/cases.json +787 -1
package/dist/index.d.cts
CHANGED
|
@@ -27,6 +27,8 @@ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
|
|
|
27
27
|
declare const CLAIM_FILL_GRACE_BLOCKS = 5;
|
|
28
28
|
declare const MAX_ACTIVE_CLAIMS = 3;
|
|
29
29
|
declare const CLAIM_COOLDOWN_BLOCKS = 15;
|
|
30
|
+
declare const FCLAIM_MAX_EPOCH_AHEAD = 2;
|
|
31
|
+
declare const FILL_TIP_MARGIN = 2;
|
|
30
32
|
declare const CONF_TOKEN_FILL = 1000000;
|
|
31
33
|
declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
|
|
32
34
|
declare const FEE_BPS = 100;
|
|
@@ -70,10 +72,13 @@ declare const MAX_PENDING_REG = 3;
|
|
|
70
72
|
declare const FINALIZE_TIP_MARGIN = 2;
|
|
71
73
|
declare const V26_HEIGHT = 46480;
|
|
72
74
|
declare const V27_HEIGHT = 46520;
|
|
75
|
+
declare const V28_HEIGHT = 60000;
|
|
73
76
|
declare const epochOf: (height: number) => number;
|
|
74
77
|
declare const claimWindowAt: (height: number) => number;
|
|
75
78
|
declare const claimWindowOf: (claimUntilHeight: number) => number;
|
|
76
|
-
declare const claimGraceOf: (claimUntilHeight: number) => number;
|
|
79
|
+
declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => number;
|
|
80
|
+
declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
|
|
81
|
+
declare const fclaimHoldEnd: (expiresEpoch: number) => number;
|
|
77
82
|
declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
|
|
78
83
|
interface DeployRecord {
|
|
79
84
|
v: 1;
|
|
@@ -194,7 +199,12 @@ interface NameProfileRecord {
|
|
|
194
199
|
name: string;
|
|
195
200
|
p: Record<string, string>;
|
|
196
201
|
}
|
|
197
|
-
|
|
202
|
+
interface FclaimRecord {
|
|
203
|
+
v: 1;
|
|
204
|
+
t: "fclaim";
|
|
205
|
+
offer: string;
|
|
206
|
+
}
|
|
207
|
+
type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord | FclaimRecord;
|
|
198
208
|
interface ProposeEvent {
|
|
199
209
|
kind: "propose";
|
|
200
210
|
id: string;
|
|
@@ -299,6 +309,10 @@ interface OfferState {
|
|
|
299
309
|
* a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
|
|
300
310
|
claimedBy?: string;
|
|
301
311
|
claimUntilHeight?: number;
|
|
312
|
+
/** v2.8 fclaim (§31, V28+): the txid of the granting fclaim Propose. LAST-WRITE-WINS (re-assigned on every
|
|
313
|
+
* grant, never set-once, never cleared), so fill-routing (claimTxid === fclaimTxid) tracks the CURRENT holder.
|
|
314
|
+
* Present only once granted at V28+; a canonical offer field (§5.1). */
|
|
315
|
+
claimTxid?: string;
|
|
302
316
|
fill?: FillEntry;
|
|
303
317
|
}
|
|
304
318
|
type BidStatus = "open" | "cancelled" | "expired" | "done";
|
|
@@ -343,6 +357,16 @@ interface CairnXState {
|
|
|
343
357
|
effectiveHeight: number;
|
|
344
358
|
finalizeBy: number;
|
|
345
359
|
}>;
|
|
360
|
+
/** v2.8 fclaim (§31): GRANTED fclaims (fclaimTxid → linked offer + proposer + expiry epoch + grant height),
|
|
361
|
+
* for the wallet/UI and the cairnx service D2 alias. DIAGNOSTIC, excluded from canonicalState (like
|
|
362
|
+
* `recaptures`/`events`); resolve() always returns it, and the one initial-state literal (cairnx service)
|
|
363
|
+
* constructs an empty {}. */
|
|
364
|
+
fclaims: Record<string, {
|
|
365
|
+
offer: string;
|
|
366
|
+
proposer: string;
|
|
367
|
+
expiresEpoch: number;
|
|
368
|
+
height: number;
|
|
369
|
+
}>;
|
|
346
370
|
events: AppliedEvent[];
|
|
347
371
|
feesPaid: string;
|
|
348
372
|
}
|
|
@@ -375,6 +399,7 @@ declare const BID_KEYS: Set<string>;
|
|
|
375
399
|
declare const NAME_KEYS: Set<string>;
|
|
376
400
|
declare const NFINALIZE_KEYS: Set<string>;
|
|
377
401
|
declare const NPROFILE_KEYS: Set<string>;
|
|
402
|
+
declare const FCLAIM_KEYS: Set<string>;
|
|
378
403
|
/**
|
|
379
404
|
* Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
|
|
380
405
|
* per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
|
|
@@ -398,6 +423,7 @@ declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
|
|
|
398
423
|
declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
|
|
399
424
|
declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
|
|
400
425
|
declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
|
|
426
|
+
declare const fclaim: (r: Omit<FclaimRecord, "v" | "t">) => BuiltRecord;
|
|
401
427
|
|
|
402
428
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
403
429
|
/** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
|
|
@@ -480,6 +506,12 @@ declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
|
|
|
480
506
|
/** Does `me` currently hold a LIVE claim on `offer` at `tip`? Mirrors resolve.ts claimHeld + the
|
|
481
507
|
* who===claimedBy check (:160-169). For a pre-V17 open offer, open fills are banned entirely. */
|
|
482
508
|
declare function hasLiveClaim(offer: OfferState, me: string, tip: number): boolean;
|
|
509
|
+
/** v2.8 Correction 1 mirror (§31): the proposal txid a fill of `offer` MUST attest at `tip`. During a live
|
|
510
|
+
* fclaim hold (V28+) the payment must target the FCLAIM txid, not the offer id (an offer-txid fill is
|
|
511
|
+
* resolver-rejected while a hold is live, `openFillReject`). Below V28, or with no live fclaim hold, the
|
|
512
|
+
* target is the offer id (legacy). A client builds the fill against this id so it never signs a doomed
|
|
513
|
+
* offer-txid fill during a hold. */
|
|
514
|
+
declare function fillTargetId(offer: OfferState, tip: number): string;
|
|
483
515
|
/** The union verdict a client must clear BEFORE signing a fill of `offer` paying `pay`, as `me`, at `tip`.
|
|
484
516
|
* Closes C2/C3/C4: status open, deliverability >= 1 token, live-claim holdership for the open-CSD lane,
|
|
485
517
|
* and taker match. `safe:true` ⇒ the fill is guaranteed to be accepted by the deterministic gates a
|
|
@@ -492,13 +524,29 @@ interface FillSafety {
|
|
|
492
524
|
}
|
|
493
525
|
declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
|
|
494
526
|
/** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
|
|
495
|
-
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced
|
|
496
|
-
* expired is REJECTED after the fee moved (a burn).
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
|
|
527
|
+
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
|
|
528
|
+
* expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
|
|
529
|
+
*
|
|
530
|
+
* TRUST SCOPE (read before relying on this): this is a STALE-STATE and displacement-race guard under an
|
|
531
|
+
* HONEST resolver, NOT a Byzantine-resolver defense. Its safety rests on `commitHeight` coming from a
|
|
532
|
+
* source INDEPENDENT of `nameState` — then `effectiveHeight !== commitHeight` genuinely detects a
|
|
533
|
+
* displaced/forged reservation. A caller that passes `nameState.effectiveHeight` AS `commitHeight` makes
|
|
534
|
+
* that guard a tautology (`X !== X`), so `eff` becomes resolver-controlled and this helper gives
|
|
535
|
+
* window-SHAPE correctness only, not protection against a resolver that lies about `effectiveHeight`.
|
|
536
|
+
* No field arithmetic here can defeat a resolver that forges the whole record (owner/pending/eff at once);
|
|
537
|
+
* that closure is registration-state SPV (roadmapped), the same posture the fill path documents (a
|
|
538
|
+
* coherently lying resolver is the fill-SPV item, not this guard). Pass the AUTHORITATIVE (freshly
|
|
539
|
+
* re-fetched) name record — never a cached one — as `nameState` (undefined = 404 / unregistered = loss).
|
|
540
|
+
*
|
|
541
|
+
* Pass `tip` to ALSO gate the finalize WINDOW, both sides, mirroring the resolver's authoritative checks
|
|
542
|
+
* (resolve.ts nfinalize rejects unless `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when
|
|
543
|
+
* `ev.height > finalizeBy`) with the client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies:
|
|
544
|
+
* the tx signs at `tip` but mines at tip+1 or later, so the margin keeps a boundary-signed finalize from
|
|
545
|
+
* mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
|
|
546
|
+
* fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
|
|
547
|
+
* `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
|
|
548
|
+
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
|
|
549
|
+
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
502
550
|
safe: boolean;
|
|
503
551
|
reason: string;
|
|
504
552
|
};
|
|
@@ -510,9 +558,56 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
|
510
558
|
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
511
559
|
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
512
560
|
|
|
561
|
+
declare const GAP_NEEDED: number;
|
|
562
|
+
declare const SCAN_MARGIN = 30;
|
|
563
|
+
declare const MAX_SCAN: number;
|
|
564
|
+
type ProvenPropose = ProposeEvent & {
|
|
565
|
+
depth: number;
|
|
566
|
+
};
|
|
567
|
+
type ProvenAttest = AttestEvent & {
|
|
568
|
+
depth: number;
|
|
569
|
+
};
|
|
570
|
+
type ProvenEvent = ProvenPropose | ProvenAttest;
|
|
571
|
+
interface FillSpvIo {
|
|
572
|
+
tip(): Promise<number>;
|
|
573
|
+
offerEventIds(offerId: string, fclaimTxid: string): Promise<string[]>;
|
|
574
|
+
provenEvent(id: string): Promise<ProvenEvent | null>;
|
|
575
|
+
}
|
|
576
|
+
interface HoldReplay {
|
|
577
|
+
state: CairnXState;
|
|
578
|
+
offer?: OfferState;
|
|
579
|
+
granted: boolean;
|
|
580
|
+
routed: boolean;
|
|
581
|
+
heldByMe: boolean;
|
|
582
|
+
}
|
|
583
|
+
declare function replayLiveHold(proven: ProvenEvent[], offerId: string, fclaimTxid: string, me: string, evalHeight: number): HoldReplay;
|
|
584
|
+
interface FillVerdict {
|
|
585
|
+
safe: boolean;
|
|
586
|
+
reason: string;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The union verdict a client MUST clear before signing an open-lane fclaim fill: offer + fclaim
|
|
590
|
+
* MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
|
|
591
|
+
* `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
|
|
592
|
+
* fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
|
|
593
|
+
* Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
|
|
594
|
+
* refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
|
|
595
|
+
* not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
|
|
596
|
+
*
|
|
597
|
+
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
598
|
+
* THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
|
|
599
|
+
* replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
|
|
600
|
+
* across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
|
|
601
|
+
* payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
|
|
602
|
+
*/
|
|
603
|
+
declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
|
|
604
|
+
myLiveHoldsAtGrant: number;
|
|
605
|
+
pay?: bigint | string | number;
|
|
606
|
+
}): Promise<FillVerdict>;
|
|
607
|
+
|
|
513
608
|
declare function paidToFromOutputs(outputs: readonly {
|
|
514
609
|
addr: string;
|
|
515
610
|
value: number;
|
|
516
611
|
}[]): Record<string, string>;
|
|
517
612
|
|
|
518
|
-
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, 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, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
|
|
613
|
+
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEntry, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldReplay, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MINT_KEYS, type MintRecord, 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 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, fillIsSafe, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, verifyFillSpv };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
|
|
|
27
27
|
declare const CLAIM_FILL_GRACE_BLOCKS = 5;
|
|
28
28
|
declare const MAX_ACTIVE_CLAIMS = 3;
|
|
29
29
|
declare const CLAIM_COOLDOWN_BLOCKS = 15;
|
|
30
|
+
declare const FCLAIM_MAX_EPOCH_AHEAD = 2;
|
|
31
|
+
declare const FILL_TIP_MARGIN = 2;
|
|
30
32
|
declare const CONF_TOKEN_FILL = 1000000;
|
|
31
33
|
declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
|
|
32
34
|
declare const FEE_BPS = 100;
|
|
@@ -70,10 +72,13 @@ declare const MAX_PENDING_REG = 3;
|
|
|
70
72
|
declare const FINALIZE_TIP_MARGIN = 2;
|
|
71
73
|
declare const V26_HEIGHT = 46480;
|
|
72
74
|
declare const V27_HEIGHT = 46520;
|
|
75
|
+
declare const V28_HEIGHT = 60000;
|
|
73
76
|
declare const epochOf: (height: number) => number;
|
|
74
77
|
declare const claimWindowAt: (height: number) => number;
|
|
75
78
|
declare const claimWindowOf: (claimUntilHeight: number) => number;
|
|
76
|
-
declare const claimGraceOf: (claimUntilHeight: number) => number;
|
|
79
|
+
declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => number;
|
|
80
|
+
declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
|
|
81
|
+
declare const fclaimHoldEnd: (expiresEpoch: number) => number;
|
|
77
82
|
declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
|
|
78
83
|
interface DeployRecord {
|
|
79
84
|
v: 1;
|
|
@@ -194,7 +199,12 @@ interface NameProfileRecord {
|
|
|
194
199
|
name: string;
|
|
195
200
|
p: Record<string, string>;
|
|
196
201
|
}
|
|
197
|
-
|
|
202
|
+
interface FclaimRecord {
|
|
203
|
+
v: 1;
|
|
204
|
+
t: "fclaim";
|
|
205
|
+
offer: string;
|
|
206
|
+
}
|
|
207
|
+
type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord | FclaimRecord;
|
|
198
208
|
interface ProposeEvent {
|
|
199
209
|
kind: "propose";
|
|
200
210
|
id: string;
|
|
@@ -299,6 +309,10 @@ interface OfferState {
|
|
|
299
309
|
* a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
|
|
300
310
|
claimedBy?: string;
|
|
301
311
|
claimUntilHeight?: number;
|
|
312
|
+
/** v2.8 fclaim (§31, V28+): the txid of the granting fclaim Propose. LAST-WRITE-WINS (re-assigned on every
|
|
313
|
+
* grant, never set-once, never cleared), so fill-routing (claimTxid === fclaimTxid) tracks the CURRENT holder.
|
|
314
|
+
* Present only once granted at V28+; a canonical offer field (§5.1). */
|
|
315
|
+
claimTxid?: string;
|
|
302
316
|
fill?: FillEntry;
|
|
303
317
|
}
|
|
304
318
|
type BidStatus = "open" | "cancelled" | "expired" | "done";
|
|
@@ -343,6 +357,16 @@ interface CairnXState {
|
|
|
343
357
|
effectiveHeight: number;
|
|
344
358
|
finalizeBy: number;
|
|
345
359
|
}>;
|
|
360
|
+
/** v2.8 fclaim (§31): GRANTED fclaims (fclaimTxid → linked offer + proposer + expiry epoch + grant height),
|
|
361
|
+
* for the wallet/UI and the cairnx service D2 alias. DIAGNOSTIC, excluded from canonicalState (like
|
|
362
|
+
* `recaptures`/`events`); resolve() always returns it, and the one initial-state literal (cairnx service)
|
|
363
|
+
* constructs an empty {}. */
|
|
364
|
+
fclaims: Record<string, {
|
|
365
|
+
offer: string;
|
|
366
|
+
proposer: string;
|
|
367
|
+
expiresEpoch: number;
|
|
368
|
+
height: number;
|
|
369
|
+
}>;
|
|
346
370
|
events: AppliedEvent[];
|
|
347
371
|
feesPaid: string;
|
|
348
372
|
}
|
|
@@ -375,6 +399,7 @@ declare const BID_KEYS: Set<string>;
|
|
|
375
399
|
declare const NAME_KEYS: Set<string>;
|
|
376
400
|
declare const NFINALIZE_KEYS: Set<string>;
|
|
377
401
|
declare const NPROFILE_KEYS: Set<string>;
|
|
402
|
+
declare const FCLAIM_KEYS: Set<string>;
|
|
378
403
|
/**
|
|
379
404
|
* Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
|
|
380
405
|
* per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
|
|
@@ -398,6 +423,7 @@ declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
|
|
|
398
423
|
declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
|
|
399
424
|
declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
|
|
400
425
|
declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
|
|
426
|
+
declare const fclaim: (r: Omit<FclaimRecord, "v" | "t">) => BuiltRecord;
|
|
401
427
|
|
|
402
428
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
403
429
|
/** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
|
|
@@ -480,6 +506,12 @@ declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
|
|
|
480
506
|
/** Does `me` currently hold a LIVE claim on `offer` at `tip`? Mirrors resolve.ts claimHeld + the
|
|
481
507
|
* who===claimedBy check (:160-169). For a pre-V17 open offer, open fills are banned entirely. */
|
|
482
508
|
declare function hasLiveClaim(offer: OfferState, me: string, tip: number): boolean;
|
|
509
|
+
/** v2.8 Correction 1 mirror (§31): the proposal txid a fill of `offer` MUST attest at `tip`. During a live
|
|
510
|
+
* fclaim hold (V28+) the payment must target the FCLAIM txid, not the offer id (an offer-txid fill is
|
|
511
|
+
* resolver-rejected while a hold is live, `openFillReject`). Below V28, or with no live fclaim hold, the
|
|
512
|
+
* target is the offer id (legacy). A client builds the fill against this id so it never signs a doomed
|
|
513
|
+
* offer-txid fill during a hold. */
|
|
514
|
+
declare function fillTargetId(offer: OfferState, tip: number): string;
|
|
483
515
|
/** The union verdict a client must clear BEFORE signing a fill of `offer` paying `pay`, as `me`, at `tip`.
|
|
484
516
|
* Closes C2/C3/C4: status open, deliverability >= 1 token, live-claim holdership for the open-CSD lane,
|
|
485
517
|
* and taker match. `safe:true` ⇒ the fill is guaranteed to be accepted by the deterministic gates a
|
|
@@ -492,13 +524,29 @@ interface FillSafety {
|
|
|
492
524
|
}
|
|
493
525
|
declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
|
|
494
526
|
/** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
|
|
495
|
-
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced
|
|
496
|
-
* expired is REJECTED after the fee moved (a burn).
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
|
|
527
|
+
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
|
|
528
|
+
* expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
|
|
529
|
+
*
|
|
530
|
+
* TRUST SCOPE (read before relying on this): this is a STALE-STATE and displacement-race guard under an
|
|
531
|
+
* HONEST resolver, NOT a Byzantine-resolver defense. Its safety rests on `commitHeight` coming from a
|
|
532
|
+
* source INDEPENDENT of `nameState` — then `effectiveHeight !== commitHeight` genuinely detects a
|
|
533
|
+
* displaced/forged reservation. A caller that passes `nameState.effectiveHeight` AS `commitHeight` makes
|
|
534
|
+
* that guard a tautology (`X !== X`), so `eff` becomes resolver-controlled and this helper gives
|
|
535
|
+
* window-SHAPE correctness only, not protection against a resolver that lies about `effectiveHeight`.
|
|
536
|
+
* No field arithmetic here can defeat a resolver that forges the whole record (owner/pending/eff at once);
|
|
537
|
+
* that closure is registration-state SPV (roadmapped), the same posture the fill path documents (a
|
|
538
|
+
* coherently lying resolver is the fill-SPV item, not this guard). Pass the AUTHORITATIVE (freshly
|
|
539
|
+
* re-fetched) name record — never a cached one — as `nameState` (undefined = 404 / unregistered = loss).
|
|
540
|
+
*
|
|
541
|
+
* Pass `tip` to ALSO gate the finalize WINDOW, both sides, mirroring the resolver's authoritative checks
|
|
542
|
+
* (resolve.ts nfinalize rejects unless `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when
|
|
543
|
+
* `ev.height > finalizeBy`) with the client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies:
|
|
544
|
+
* the tx signs at `tip` but mines at tip+1 or later, so the margin keeps a boundary-signed finalize from
|
|
545
|
+
* mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
|
|
546
|
+
* fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
|
|
547
|
+
* `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
|
|
548
|
+
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
|
|
549
|
+
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
502
550
|
safe: boolean;
|
|
503
551
|
reason: string;
|
|
504
552
|
};
|
|
@@ -510,9 +558,56 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
|
510
558
|
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
511
559
|
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
512
560
|
|
|
561
|
+
declare const GAP_NEEDED: number;
|
|
562
|
+
declare const SCAN_MARGIN = 30;
|
|
563
|
+
declare const MAX_SCAN: number;
|
|
564
|
+
type ProvenPropose = ProposeEvent & {
|
|
565
|
+
depth: number;
|
|
566
|
+
};
|
|
567
|
+
type ProvenAttest = AttestEvent & {
|
|
568
|
+
depth: number;
|
|
569
|
+
};
|
|
570
|
+
type ProvenEvent = ProvenPropose | ProvenAttest;
|
|
571
|
+
interface FillSpvIo {
|
|
572
|
+
tip(): Promise<number>;
|
|
573
|
+
offerEventIds(offerId: string, fclaimTxid: string): Promise<string[]>;
|
|
574
|
+
provenEvent(id: string): Promise<ProvenEvent | null>;
|
|
575
|
+
}
|
|
576
|
+
interface HoldReplay {
|
|
577
|
+
state: CairnXState;
|
|
578
|
+
offer?: OfferState;
|
|
579
|
+
granted: boolean;
|
|
580
|
+
routed: boolean;
|
|
581
|
+
heldByMe: boolean;
|
|
582
|
+
}
|
|
583
|
+
declare function replayLiveHold(proven: ProvenEvent[], offerId: string, fclaimTxid: string, me: string, evalHeight: number): HoldReplay;
|
|
584
|
+
interface FillVerdict {
|
|
585
|
+
safe: boolean;
|
|
586
|
+
reason: string;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The union verdict a client MUST clear before signing an open-lane fclaim fill: offer + fclaim
|
|
590
|
+
* MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
|
|
591
|
+
* `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
|
|
592
|
+
* fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
|
|
593
|
+
* Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
|
|
594
|
+
* refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
|
|
595
|
+
* not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
|
|
596
|
+
*
|
|
597
|
+
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
598
|
+
* THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
|
|
599
|
+
* replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
|
|
600
|
+
* across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
|
|
601
|
+
* payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
|
|
602
|
+
*/
|
|
603
|
+
declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
|
|
604
|
+
myLiveHoldsAtGrant: number;
|
|
605
|
+
pay?: bigint | string | number;
|
|
606
|
+
}): Promise<FillVerdict>;
|
|
607
|
+
|
|
513
608
|
declare function paidToFromOutputs(outputs: readonly {
|
|
514
609
|
addr: string;
|
|
515
610
|
value: number;
|
|
516
611
|
}[]): Record<string, string>;
|
|
517
612
|
|
|
518
|
-
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, 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, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
|
|
613
|
+
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEntry, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldReplay, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MINT_KEYS, type MintRecord, 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 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, fillIsSafe, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, verifyFillSpv };
|