@inversealtruism/cairnx-core 0.2.4 → 0.2.8

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/README.md CHANGED
@@ -81,8 +81,9 @@ CNS is an **ENS-class** namespace native to Compute Substrate. A name like `alic
81
81
  address, **leased** (not sold forever), points to an address, and carries an optional profile, all as
82
82
  plain on-chain records, all resolvable by replay.
83
83
 
84
- - **Names are lowercase-ASCII only** (`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`, 1–32 chars). This kills
85
- the homograph/confusable phishing class outright, there is no unicode look-alike attack surface.
84
+ - **Names are lowercase-ASCII only** (`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`, 1–32 chars). This removes
85
+ the mixed-script homograph class: there is no Unicode look-alike surface. Look-alikes within ASCII remain
86
+ (`paypa1` and `paypal` are distinct, valid names), so an interface that shows a name should still warn on them.
86
87
  - **The `.csd` suffix is presentation, not consensus.** The on-chain record stores the *bare* name
87
88
  (`alice`); the UI renders `alice.csd`. The CNS rebrand and any display-suffix change are **UI-only**, they do not touch the resolver or chain history.
88
89
  - **Reserved names** (`csd`, `treasury`, `admin`, `official`, `root`, `www`, `support`) can never be
@@ -100,7 +101,7 @@ stateDiagram-v2
100
101
  Active --> Grace: lease term ends (~1 year)
101
102
  Grace --> Active: nrenew · OWNER ONLY, ~30-day window
102
103
  Grace --> Lapsed: grace ends un-renewed
103
- Lapsed --> Active: recapture · anyone re-claims at a DECAYING premium (20x to 1x over ~30 days), fresh lease
104
+ Lapsed --> Active: recapture · anyone re-claims at a DECAYING premium (19x stepping down to 1x over about 28 days), fresh lease
104
105
  Active --> [*]
105
106
  ```
106
107
 
@@ -114,7 +115,7 @@ stateDiagram-v2
114
115
  (`nprofile`), transfer it (`nxfer`), renew it (`nrenew`), or list it for sale.
115
116
  3. **Grace (~30 days).** When the term ends, **only the current owner** may renew during a grace window, your name is never sniped out from under you while you still hold it.
116
117
  4. **Lapsed → decaying-premium recapture.** If grace passes un-renewed, anyone may re-claim, but at a
117
- **premium that decays 20× → 1×** over ~30 days (a Dutch auction back to the floor price). This prices
118
+ **premium of 19× stepping down to 1×** over about 28 days (CONVENTION section 17; a Dutch auction back to the floor price). This prices
118
119
  in genuine demand without a permanent squatting tax, and a recaptured name gets a fresh ownership basis
119
120
  so a stale pre-lapse commit can't steal it.
120
121
 
@@ -136,7 +137,7 @@ stateDiagram-v2
136
137
  |---|---|---|
137
138
  | Lease term | ~1 year (`NAME_TERM_EPOCHS = 8760`) | 1 epoch ≈ 1 h (30 blocks) |
138
139
  | Grace window | ~30 days (`NAME_GRACE_EPOCHS = 720`) | owner-only renewal |
139
- | Recapture premium | **20× → 1×** over ~30 days | decaying Dutch auction on lapsed names |
140
+ | Recapture premium | **19× stepping down to 1×** over about 28 days (CONVENTION section 17) | decaying Dutch auction on lapsed names |
140
141
  | Reveal window | ~16 min (`REG_COMMIT_MAX_BLOCKS = 8`, v2.5+; was 240 blocks below v2.5) | commit-reveal deadline; doubles as the displacement freeze |
141
142
  | Registration fee | **15 / 10 / 5 / 3 CSD** by length (≤3 / 4 / 5-9 / ≥10 chars, v2.4) | length-graded (was flat 6.7 / 3 CSD under v1.8); paid to the treasury at finalize (v2.5+) |
142
143
 
@@ -174,15 +175,21 @@ sequenceDiagram
174
175
  a name that does not resolve or whose lease lapsed, and at signing it re-checks and refuses an address change
175
176
  or a drop from verified to not verified. The wallet's `SECURITY.md` ("What happens when the sources
176
177
  disagree") is the full list.
178
+ - **The rule a resolved name follows** is `resolveNameIn(state.names, name)` (CONVENTION §35.4): the `nset` address,
179
+ else the owner; a pending reservation and an absent name resolve to nothing; a lapsed lease resolves with
180
+ `lapsed: true`, which a sender refuses. `nameView` gives what a reader shows: the class (held, pending, lapsed, free,
181
+ reserved), the owner, and a held name's address and profile. The reference service's `/cairnx/resolve/:name` answers
182
+ with the first, and `test/vectors/forward.json` pins both.
177
183
  - **Reverse resolution (`address → primary name`, a display label) is server-trusted.** It is never a send
178
184
  target, an identity badge only, so it is cheaper and clearly bounded as "unverified label."
179
185
  - **Ownership has an unambiguous total order:** lowest `(effectiveHeight, position, ordinal-id)` wins, with
180
186
  a paid market-fill (`viaFill`) immune to displacement. Exactly one owner per name at every height.
181
187
 
182
- > **Note on bought names:** a name you *register* is fully SPV-verifiable today. A name acquired via a
183
- > *market fill* is displacement-immune and correctly resolved, but its forward resolution currently shows
184
- > a caution rather than a green check (the wallet never shows it as verified) pending a resolver change
185
- > that makes name-fills name-local. Registration, the alpha's primary flow, is unaffected.
188
+ > **Note on names whose history reads other state:** a replay of one name's records alone cannot decide a
189
+ > name whose history touches a rule that reads other state (a name bought on the market can be one such
190
+ > case). The reference service's name-history read (`/cairnx/name-history/:name`) serves such a name with
191
+ > `scopedReplaySufficient: false`, and a per-name verifier should show it as unverified. A replay of the
192
+ > whole `cairnx:v1` domain decides every name exactly.
186
193
 
187
194
  ---
188
195
 
@@ -278,14 +285,16 @@ v2.4–v2.7 were re-pinned 2026-07-03 from their originally published heights (4
278
285
 
279
286
  ### Package layout
280
287
 
281
- `src/resolve.ts` + `src/resolve/` (the ledger: the replay loop and its per-record handlers) · `src/records.ts` (the parse/validate gate) · `src/types.ts` (constants +
288
+ `src/resolve.ts` + `src/resolve/` (the ledger: the replay loop and its per-record handlers) · `src/events.ts` (the rule
289
+ from a block to events, CONVENTION §33) · `src/hashes.ts` (the state and events hashes, §34) · `src/records.ts` (the parse/validate gate) · `src/types.ts` (constants +
282
290
  height-gated client selectors) · `src/client.ts` (the claim-burial depth a payer waits for, sized against a minority miner) · `src/preflight.ts`
283
291
  (build-side helpers every host must compute identically: `requiredFillOutputs`, `previewFill`/`fillIsSafe`,
284
292
  `buildFeeHeight` + `NAME_FEE_GATES`, `finalizeWinnerCheck`) · `src/primary.ts` (`pickPrimaryName` /
285
- `primaryRankBefore`, the one primary-name selection every host must agree on) · `src/mm/` (the
293
+ `primaryRankBefore`, the one primary-name selection every host must agree on) · `src/forward.ts` (`resolveNameIn` / `nameView`, forward
294
+ resolution, §35.4) · `src/mm/` (the
286
295
  `@inversealtruism/cairnx-core/mm` subpath: the market maker's bid sizer, fill notional, Sunrise spot curve and
287
296
  order pricing, and the RFQ all-in sum; not consensus and not part of the root export) · `CONVENTION.md`
288
- (normative spec, §1–§32) · `test/vectors/` (portable conformance corpus).
297
+ (normative spec, §1–§39) · `test/vectors/` (portable conformance corpus).
289
298
 
290
299
  ### Use it
291
300
 
@@ -301,18 +310,49 @@ const built = offer({ give: { ticker: "CAIRN", amount: "5000000000" },
301
310
  const tx = buildPropose({ domain: DOMAIN, uri: built.uri, payloadHash: built.payloadHash,
302
311
  expiresEpoch, fee: 25_000_000, utxos, priv });
303
312
 
304
- // RESOLVE the chain (events come from any indexer; see the Scanner reference impl)
313
+ // RESOLVE the chain. CONVENTION §33 turns blocks into events: blockMembers(height, txs, sofar) names the txs
314
+ // that need an author, blockEvents(height, txs, sofar, authors) returns the block's events, and eventOfTx maps
315
+ // one tx. The author is an input: bind it with csd-crypto's authorOf(tx, scriptPubkey) over the coin the first
316
+ // input spends, read from its source tx. csd-light's bindBlockTxs checks a block's txs against a verified header.
305
317
  const state = resolve(events, tipHeight);
306
318
  console.log(state.names, state.tokens.CAIRN, state.balances.CAIRN);
307
319
  ```
308
320
 
321
+ ### What a resolver result proves
322
+
323
+ - Display: an answer read from someone's API. It is worth the trust you place in that API.
324
+ - Record proof: one record is mined under valid proof of work and was written by the owner of the coin
325
+ its first input spends. It does not prove the record is the latest one, and it decides nothing for a name
326
+ whose history touches a cross-name rule.
327
+ - Replica: a replay of every `cairnx:v1` record. It is exact for names and tokens. What it proves depends
328
+ on where the records came from: one's own node, complete blocks checked against headers, or someone's
329
+ record feed, which is complete only on that feed's word.
330
+
331
+ Other applications, the profile-key registry with its byte budget, the three levels with their sources,
332
+ conformance and how the rules change are `CONVENTION.md` §35 to §39.
333
+
334
+ Why a record was applied or refused: each entry of `resolve(...).events` carries a stable `code` (`CONVENTION.md` §40,
335
+ `REASON_CODES`), and `explainRecord(uri, payloadHash)` names the rule a record breaks before it reaches the resolver.
336
+ Match the code, never the `note` text, which may change; a code your release does not know reads by the entry's `ok`.
337
+
338
+ Who received which tokens in which record: an applied entry that moved tokens carries `moves` (`CONVENTION.md` §41,
339
+ `TokenMove`), each `{ leg, ticker, from, to, amount }` with the leg `mint`, `xfer`, `sale`, `fee` or `fill`, written
340
+ where the resolver moves the balance. A deposit credit is a move whose `to` is the receiving address; read the amount
341
+ from the move, not from the record, since a mint is capped and a partial fill delivers by its floor. A server that
342
+ credits a listed token by ticker also pins `tokens[ticker].deployId`, since a replay of another chain can bind the
343
+ ticker to another deploy. Moves are outside canonical state, so they change no hash.
344
+
309
345
  ### Write a conformant resolver in another language
310
346
 
311
- 1. Implement `CONVENTION.md` §1–§32 (apply order, every record type, the `V*_HEIGHT` activations (using
312
- the re-pinned v2.4–v2.7 heights), the canonical-state format, ordinal key ordering, data surface only).
313
- 2. Replay `test/vectors/cases.json`, `cases-v29.json` and `cases-rules.json`: your canonical state must equal
314
- `expectedState` **byte-for-byte**.
315
- 3. Replay the live chain and compare `sha256(canonicalState)` against `test/vectors/replay-hashes.json`.
347
+ 1. Implement `CONVENTION.md` §1–§34 (the events of a block, apply order, every record type, the `V*_HEIGHT`
348
+ activations (using the re-pinned v2.4–v2.7 heights), the canonical-state format, ordinal key ordering, data
349
+ surface only).
350
+ 2. Reproduce `test/vectors/events.json` (§33.7). Replay `test/vectors/cases.json`, `cases-v29.json`,
351
+ `cases-rules.json` and `cases-convention.json`: your canonical state must equal `expectedState` **byte-for-byte**.
352
+ 3. Replay the live chain and compare the state hash (§34.1) against `test/vectors/replay-hashes.json`, and reproduce
353
+ `test/vectors/hashes.json` (§34.4).
354
+ 4. Only if you publish reason codes (§40): reproduce `test/vectors/codes.json`.
355
+ 5. Only if you publish token moves (§41): reproduce `test/vectors/moves.json`.
316
356
 
317
357
  ---
318
358