@inversealtruism/cairnx-core 0.1.11 → 0.1.13

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.cjs CHANGED
@@ -29,7 +29,7 @@ __export(index_exports, {
29
29
  CONF_TOKEN_FILL: () => CONF_TOKEN_FILL,
30
30
  DEPLOY_FEE: () => DEPLOY_FEE,
31
31
  DOMAIN: () => DOMAIN,
32
- EPOCH_LEN: () => EPOCH_LEN,
32
+ EPOCH_LEN: () => import_csd_codec.EPOCH_LEN,
33
33
  FEE_BPS: () => FEE_BPS,
34
34
  FEE_BPS_V16: () => FEE_BPS_V16,
35
35
  HASH_RE: () => HASH_RE,
@@ -43,9 +43,13 @@ __export(index_exports, {
43
43
  NAME_PREMIUM_START: () => NAME_PREMIUM_START,
44
44
  NAME_RE: () => NAME_RE,
45
45
  NAME_TERM_EPOCHS: () => NAME_TERM_EPOCHS,
46
+ PKEY: () => PKEY,
47
+ PROFILE_MAX_KEYS: () => PROFILE_MAX_KEYS,
48
+ PROFILE_MAX_VALUE_BYTES: () => PROFILE_MAX_VALUE_BYTES,
46
49
  REBATE_BPS: () => REBATE_BPS,
47
50
  REBATE_FLAT: () => REBATE_FLAT,
48
51
  RESERVED_NAMES: () => RESERVED_NAMES,
52
+ SALT_RE: () => SALT_RE,
49
53
  SCORE_CANCEL: () => SCORE_CANCEL,
50
54
  SCORE_CLAIM: () => SCORE_CLAIM,
51
55
  SCORE_FILL: () => SCORE_FILL,
@@ -59,6 +63,7 @@ __export(index_exports, {
59
63
  V16_HEIGHT: () => V16_HEIGHT,
60
64
  V17_HEIGHT: () => V17_HEIGHT,
61
65
  V18_HEIGHT: () => V18_HEIGHT,
66
+ V19_HEIGHT: () => V19_HEIGHT,
62
67
  bid: () => bid,
63
68
  buildRecord: () => buildRecord,
64
69
  canonicalState: () => canonicalState,
@@ -73,6 +78,7 @@ __export(index_exports, {
73
78
  nameClaim: () => nameClaim,
74
79
  nameCommit: () => nameCommit,
75
80
  nameCommitRecord: () => nameCommitRecord,
81
+ nameProfile: () => nameProfile,
76
82
  nameRegFee: () => nameRegFee,
77
83
  nameRenew: () => nameRenew,
78
84
  nameSet: () => nameSet,
@@ -89,6 +95,7 @@ __export(index_exports, {
89
95
  module.exports = __toCommonJS(index_exports);
90
96
 
91
97
  // src/types.ts
98
+ var import_csd_codec = require("@inversealtruism/csd-codec");
92
99
  var DOMAIN = "cairnx:v1";
93
100
  var ACTIVATION_HEIGHT = 29860;
94
101
  var V11_HEIGHT = 29960;
@@ -98,7 +105,6 @@ var V14_HEIGHT = 31400;
98
105
  var V15_HEIGHT = 32e3;
99
106
  var V16_HEIGHT = 33600;
100
107
  var V17_HEIGHT = 34e3;
101
- var EPOCH_LEN = 30;
102
108
  var NAME_TERM_EPOCHS = 8760;
103
109
  var NAME_GRACE_EPOCHS = 720;
104
110
  var NAME_PREMIUM_START = 20n;
@@ -128,6 +134,10 @@ var DEPLOY_FEE = 1e8;
128
134
  var V18_HEIGHT = 4e4;
129
135
  var NAME_FEE_SHORT_V18 = 670000000n;
130
136
  var NAME_FEE_V18 = 300000000n;
137
+ var V19_HEIGHT = 36700;
138
+ var PKEY = /^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$/;
139
+ var PROFILE_MAX_KEYS = 16;
140
+ var PROFILE_MAX_VALUE_BYTES = 256;
131
141
  function nameRegFee(name, height) {
132
142
  if (height >= V18_HEIGHT) return name.length <= 4 ? NAME_FEE_SHORT_V18 : NAME_FEE_V18;
133
143
  const n = name.length;
@@ -144,14 +154,15 @@ var ADDR_RE = /^0x[0-9a-f]{40}$/;
144
154
  var AMOUNT_RE = /^(0|[1-9][0-9]*)$/;
145
155
  var NAME_RE = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
146
156
  var HASH_RE = /^0x[0-9a-f]{64}$/;
157
+ var SALT_RE = /^[0-9a-fA-F]{16,128}$/;
147
158
  var RESERVED_NAMES = /* @__PURE__ */ new Set(["csd", "treasury", "admin", "official", "root", "www", "support"]);
148
- var COMMIT_MAX_BLOCKS = 8 * EPOCH_LEN;
149
- var epochOf = (height) => Math.floor(height / EPOCH_LEN);
159
+ var COMMIT_MAX_BLOCKS = 8 * import_csd_codec.EPOCH_LEN;
160
+ var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
150
161
  var isNameGive = (g) => typeof g.name === "string";
151
162
  var isTokenWant = (w) => typeof w.ticker === "string";
152
163
 
153
164
  // src/records.ts
154
- var import_csd_codec = require("@inversealtruism/csd-codec");
165
+ var import_csd_codec2 = require("@inversealtruism/csd-codec");
155
166
  function parseAmount(s, opts = {}) {
156
167
  if (typeof s !== "string" || !AMOUNT_RE.test(s)) return null;
157
168
  const v = BigInt(s);
@@ -164,7 +175,7 @@ var isTicker = (t) => typeof t === "string" && TICKER_RE.test(t);
164
175
  var isHash = (h) => typeof h === "string" && HASH_RE.test(h);
165
176
  var isName = (n) => typeof n === "string" && NAME_RE.test(n) && !RESERVED_NAMES.has(n);
166
177
  function nameCommit(name, salt, owner) {
167
- return (0, import_csd_codec.payloadHash)({ t: "cairnx:name:commit:v1", name, salt, owner: owner.toLowerCase() });
178
+ return (0, import_csd_codec2.payloadHash)({ t: "cairnx:name:commit:v1", name, salt, owner: owner.toLowerCase() });
168
179
  }
169
180
  function strWellFormed(s) {
170
181
  const wf = String.prototype.isWellFormed;
@@ -199,6 +210,7 @@ var TRANSFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "ticker", "to", "amount",
199
210
  var OFFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "give", "want", "min", "bid", "taker", "memo", "ts"]);
200
211
  var BID_KEYS = /* @__PURE__ */ new Set(["v", "t", "want", "give", "memo", "ts"]);
201
212
  var NAME_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
213
+ var NPROFILE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "p"]);
202
214
  function parseRecord(uri, payloadHashHex) {
203
215
  if (new TextEncoder().encode(uri).length > MAX_RECORD_BYTES) return null;
204
216
  let obj;
@@ -209,8 +221,8 @@ function parseRecord(uri, payloadHashHex) {
209
221
  }
210
222
  if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return null;
211
223
  try {
212
- if ((0, import_csd_codec.canonicalJson)(obj) !== uri) return null;
213
- if ((0, import_csd_codec.payloadHash)(obj).toLowerCase() !== payloadHashHex.toLowerCase()) return null;
224
+ if ((0, import_csd_codec2.canonicalJson)(obj) !== uri) return null;
225
+ if ((0, import_csd_codec2.payloadHash)(obj).toLowerCase() !== payloadHashHex.toLowerCase()) return null;
214
226
  } catch {
215
227
  return null;
216
228
  }
@@ -306,7 +318,7 @@ function parseRecord(uri, payloadHashHex) {
306
318
  case "name": {
307
319
  if (!onlyKeys(r, NAME_KEYS)) return null;
308
320
  if (!isName(r.name)) return null;
309
- if (r.salt !== void 0 && (typeof r.salt !== "string" || !/^[0-9a-fA-F]{16,128}$/.test(r.salt))) return null;
321
+ if (r.salt !== void 0 && (typeof r.salt !== "string" || !SALT_RE.test(r.salt))) return null;
310
322
  return r;
311
323
  }
312
324
  case "nxfer": {
@@ -325,9 +337,24 @@ function parseRecord(uri, payloadHashHex) {
325
337
  if (Object.keys(r).length !== 3) return null;
326
338
  return r;
327
339
  }
340
+ case "nprofile": {
341
+ if (!onlyKeys(r, NPROFILE_KEYS)) return null;
342
+ if (!isName(r.name)) return null;
343
+ const p = r.p;
344
+ if (!p || typeof p !== "object" || Array.isArray(p)) return null;
345
+ const keys = Object.keys(p);
346
+ if (keys.length > PROFILE_MAX_KEYS) return null;
347
+ for (const k of keys) {
348
+ if (!PKEY.test(k)) return null;
349
+ const val = p[k];
350
+ if (typeof val !== "string") return null;
351
+ if (new TextEncoder().encode(val).length > PROFILE_MAX_VALUE_BYTES) return null;
352
+ }
353
+ return r;
354
+ }
328
355
  case "tmeta": {
329
356
  if (!isTicker(r.ticker)) return null;
330
- if (typeof r.hash !== "string" || !/^0x[0-9a-f]{64}$/.test(r.hash)) return null;
357
+ if (typeof r.hash !== "string" || !HASH_RE.test(r.hash)) return null;
331
358
  if (Object.keys(r).length !== 4) return null;
332
359
  return r;
333
360
  }
@@ -336,8 +363,8 @@ function parseRecord(uri, payloadHashHex) {
336
363
  }
337
364
  }
338
365
  function buildRecord(record) {
339
- const uri = (0, import_csd_codec.canonicalJson)(record);
340
- const ph = (0, import_csd_codec.payloadHash)(record);
366
+ const uri = (0, import_csd_codec2.canonicalJson)(record);
367
+ const ph = (0, import_csd_codec2.payloadHash)(record);
341
368
  const back = parseRecord(uri, ph);
342
369
  if (back === null) throw new Error("record does not validate against CONVENTION.md");
343
370
  return { record, uri, payloadHash: ph };
@@ -354,6 +381,7 @@ var nameXfer = (r) => buildRecord({ v: 1, t: "nxfer", ...r });
354
381
  var nameSet = (r) => buildRecord({ v: 1, t: "nset", ...r });
355
382
  var nameRenew = (r) => buildRecord({ v: 1, t: "nrenew", ...r });
356
383
  var tokenMeta = (r) => buildRecord({ v: 1, t: "tmeta", ...r });
384
+ var nameProfile = (r) => buildRecord({ v: 1, t: "nprofile", ...r });
357
385
 
358
386
  // src/resolve.ts
359
387
  var ord = (a, b) => a < b ? -1 : a > b ? 1 : 0;
@@ -437,6 +465,7 @@ function resolve(events, tipHeight) {
437
465
  const v12 = ev.height >= V12_HEIGHT;
438
466
  const v15 = ev.height >= V15_HEIGHT;
439
467
  const v16 = ev.height >= V16_HEIGHT;
468
+ const v19 = ev.height >= V19_HEIGHT;
440
469
  const feeToTreasury = ev.kind === "propose" ? BigInt((ev.paidTo ?? {})[TREASURY_ADDR] ?? "0") : 0n;
441
470
  if (ev.kind === "propose") {
442
471
  const rec = parseRecord(ev.uri, ev.payloadHash);
@@ -592,6 +621,7 @@ function resolve(events, tipHeight) {
592
621
  }
593
622
  n.owner = rec.to.toLowerCase();
594
623
  n.addr = void 0;
624
+ n.profile = void 0;
595
625
  note(ev, ev.id, "nxfer", true);
596
626
  } else if (rec.t === "nset") {
597
627
  const n = names.get(rec.name);
@@ -605,6 +635,22 @@ function resolve(events, tipHeight) {
605
635
  }
606
636
  n.addr = rec.addr.toLowerCase();
607
637
  note(ev, ev.id, "nset", true);
638
+ } else if (rec.t === "nprofile") {
639
+ if (!v19) {
640
+ note(ev, ev.id, "nprofile", false, "before v1.9 activation");
641
+ continue;
642
+ }
643
+ const n = names.get(rec.name);
644
+ if (!n || n.owner !== who) {
645
+ note(ev, ev.id, "nprofile", false, "not the name owner");
646
+ continue;
647
+ }
648
+ if (v15 && lapsed(n, epochOf(ev.height))) {
649
+ note(ev, ev.id, "nprofile", false, "lease lapsed \u2014 claim it instead");
650
+ continue;
651
+ }
652
+ n.profile = Object.keys(rec.p).length ? { ...rec.p } : void 0;
653
+ note(ev, ev.id, "nprofile", true);
608
654
  } else if (rec.t === "offer") {
609
655
  const wantIsToken = isTokenWant(rec.want);
610
656
  if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
@@ -858,6 +904,7 @@ function resolve(events, tipHeight) {
858
904
  giveName.owner = who;
859
905
  giveName.locked = false;
860
906
  giveName.addr = void 0;
907
+ giveName.profile = void 0;
861
908
  if (ev.height >= V13_HEIGHT) {
862
909
  giveName.effHeight = ev.height;
863
910
  giveName.pos = ev.pos;
@@ -987,6 +1034,7 @@ function resolve(events, tipHeight) {
987
1034
  n.owner = who;
988
1035
  n.locked = false;
989
1036
  n.addr = void 0;
1037
+ n.profile = void 0;
990
1038
  if (ev.height >= V13_HEIGHT) {
991
1039
  n.effHeight = ev.height;
992
1040
  n.pos = ev.pos;
@@ -1057,6 +1105,7 @@ function resolve(events, tipHeight) {
1057
1105
  }
1058
1106
  const namesOut = {};
1059
1107
  const tipV15 = tipHeight >= V15_HEIGHT;
1108
+ const tipV19 = tipHeight >= V19_HEIGHT;
1060
1109
  const tipEpoch = epochOf(tipHeight);
1061
1110
  for (const [nm, n] of [...names.entries()].sort(([a], [b]) => ord(a, b))) {
1062
1111
  namesOut[nm] = {
@@ -1068,6 +1117,9 @@ function resolve(events, tipHeight) {
1068
1117
  locked: n.locked,
1069
1118
  ...n.addr ? { addr: n.addr } : {},
1070
1119
  ...n.viaFill ? { viaFill: true } : {},
1120
+ // v1.9 profile materialized at v1.9+ tips ONLY (the apply is also gated) → every pre-v1.9 canonical
1121
+ // hash stays byte-identical; absent when empty/unset.
1122
+ ...tipV19 && n.profile ? { profile: n.profile } : {},
1071
1123
  // lease fields exist only at v1.5+ tips so every pre-v1.5 canonical hash stays pinned
1072
1124
  ...tipV15 ? { paidThroughEpoch: paidThrough(n), ...lapsed(n, tipEpoch) ? { expired: true } : {} } : {}
1073
1125
  };
@@ -1114,9 +1166,13 @@ function canonicalState(s) {
1114
1166
  NAME_PREMIUM_START,
1115
1167
  NAME_RE,
1116
1168
  NAME_TERM_EPOCHS,
1169
+ PKEY,
1170
+ PROFILE_MAX_KEYS,
1171
+ PROFILE_MAX_VALUE_BYTES,
1117
1172
  REBATE_BPS,
1118
1173
  REBATE_FLAT,
1119
1174
  RESERVED_NAMES,
1175
+ SALT_RE,
1120
1176
  SCORE_CANCEL,
1121
1177
  SCORE_CLAIM,
1122
1178
  SCORE_FILL,
@@ -1130,6 +1186,7 @@ function canonicalState(s) {
1130
1186
  V16_HEIGHT,
1131
1187
  V17_HEIGHT,
1132
1188
  V18_HEIGHT,
1189
+ V19_HEIGHT,
1133
1190
  bid,
1134
1191
  buildRecord,
1135
1192
  canonicalState,
@@ -1144,6 +1201,7 @@ function canonicalState(s) {
1144
1201
  nameClaim,
1145
1202
  nameCommit,
1146
1203
  nameCommitRecord,
1204
+ nameProfile,
1147
1205
  nameRegFee,
1148
1206
  nameRenew,
1149
1207
  nameSet,
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ export { EPOCH_LEN } from '@inversealtruism/csd-codec';
2
+
1
3
  declare const DOMAIN = "cairnx:v1";
2
4
  declare const ACTIVATION_HEIGHT = 29860;
3
5
  declare const V11_HEIGHT = 29960;
@@ -7,7 +9,7 @@ declare const V14_HEIGHT = 31400;
7
9
  declare const V15_HEIGHT = 32000;
8
10
  declare const V16_HEIGHT = 33600;
9
11
  declare const V17_HEIGHT = 34000;
10
- declare const EPOCH_LEN = 30;
12
+
11
13
  declare const NAME_TERM_EPOCHS = 8760;
12
14
  declare const NAME_GRACE_EPOCHS = 720;
13
15
  declare const NAME_PREMIUM_START = 20n;
@@ -33,6 +35,10 @@ declare const DEPLOY_FEE = 100000000;
33
35
  declare const V18_HEIGHT = 40000;
34
36
  declare const NAME_FEE_SHORT_V18 = 670000000n;
35
37
  declare const NAME_FEE_V18 = 300000000n;
38
+ declare const V19_HEIGHT = 36700;
39
+ declare const PKEY: RegExp;
40
+ declare const PROFILE_MAX_KEYS = 16;
41
+ declare const PROFILE_MAX_VALUE_BYTES = 256;
36
42
  declare function nameRegFee(name: string, height: number): bigint;
37
43
  declare const tradeFee: (want: bigint, bps?: number) => bigint;
38
44
  declare const makerRebate: (value: bigint) => bigint;
@@ -41,6 +47,7 @@ declare const ADDR_RE: RegExp;
41
47
  declare const AMOUNT_RE: RegExp;
42
48
  declare const NAME_RE: RegExp;
43
49
  declare const HASH_RE: RegExp;
50
+ declare const SALT_RE: RegExp;
44
51
  declare const RESERVED_NAMES: Set<string>;
45
52
  declare const COMMIT_MAX_BLOCKS: number;
46
53
  declare const epochOf: (height: number) => number;
@@ -151,7 +158,13 @@ interface TokenMetaRecord {
151
158
  ticker: string;
152
159
  hash: string;
153
160
  }
154
- type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord;
161
+ interface NameProfileRecord {
162
+ v: 1;
163
+ t: "nprofile";
164
+ name: string;
165
+ p: Record<string, string>;
166
+ }
167
+ type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
155
168
  interface ProposeEvent {
156
169
  kind: "propose";
157
170
  id: string;
@@ -207,6 +220,10 @@ interface NameState {
207
220
  paidThroughEpoch?: number;
208
221
  /** v1.5: true once the lease + grace lapsed (record kept for history; name is claimable) */
209
222
  expired?: true;
223
+ /** v1.9: ENS-class identity — a charset-locked string→string map (doc 36). INERT cosmetic metadata
224
+ * (NOT a send target; the verified address is `addr`). Materialized at v1.9+ tips only, cleared on
225
+ * every ownership change, absent when empty. */
226
+ profile?: Record<string, string>;
210
227
  }
211
228
  type OfferStatus = "open" | "filled" | "cancelled" | "expired";
212
229
  interface FillEntry {
@@ -328,6 +345,7 @@ declare const nameXfer: (r: Omit<NameXferRecord, "v" | "t">) => BuiltRecord;
328
345
  declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
329
346
  declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
330
347
  declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
348
+ declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
331
349
 
332
350
  declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
333
351
  /** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
@@ -339,4 +357,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
339
357
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
340
358
  declare function canonicalState(s: CairnXState): string;
341
359
 
342
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
360
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, 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, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { EPOCH_LEN } from '@inversealtruism/csd-codec';
2
+
1
3
  declare const DOMAIN = "cairnx:v1";
2
4
  declare const ACTIVATION_HEIGHT = 29860;
3
5
  declare const V11_HEIGHT = 29960;
@@ -7,7 +9,7 @@ declare const V14_HEIGHT = 31400;
7
9
  declare const V15_HEIGHT = 32000;
8
10
  declare const V16_HEIGHT = 33600;
9
11
  declare const V17_HEIGHT = 34000;
10
- declare const EPOCH_LEN = 30;
12
+
11
13
  declare const NAME_TERM_EPOCHS = 8760;
12
14
  declare const NAME_GRACE_EPOCHS = 720;
13
15
  declare const NAME_PREMIUM_START = 20n;
@@ -33,6 +35,10 @@ declare const DEPLOY_FEE = 100000000;
33
35
  declare const V18_HEIGHT = 40000;
34
36
  declare const NAME_FEE_SHORT_V18 = 670000000n;
35
37
  declare const NAME_FEE_V18 = 300000000n;
38
+ declare const V19_HEIGHT = 36700;
39
+ declare const PKEY: RegExp;
40
+ declare const PROFILE_MAX_KEYS = 16;
41
+ declare const PROFILE_MAX_VALUE_BYTES = 256;
36
42
  declare function nameRegFee(name: string, height: number): bigint;
37
43
  declare const tradeFee: (want: bigint, bps?: number) => bigint;
38
44
  declare const makerRebate: (value: bigint) => bigint;
@@ -41,6 +47,7 @@ declare const ADDR_RE: RegExp;
41
47
  declare const AMOUNT_RE: RegExp;
42
48
  declare const NAME_RE: RegExp;
43
49
  declare const HASH_RE: RegExp;
50
+ declare const SALT_RE: RegExp;
44
51
  declare const RESERVED_NAMES: Set<string>;
45
52
  declare const COMMIT_MAX_BLOCKS: number;
46
53
  declare const epochOf: (height: number) => number;
@@ -151,7 +158,13 @@ interface TokenMetaRecord {
151
158
  ticker: string;
152
159
  hash: string;
153
160
  }
154
- type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord;
161
+ interface NameProfileRecord {
162
+ v: 1;
163
+ t: "nprofile";
164
+ name: string;
165
+ p: Record<string, string>;
166
+ }
167
+ type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
155
168
  interface ProposeEvent {
156
169
  kind: "propose";
157
170
  id: string;
@@ -207,6 +220,10 @@ interface NameState {
207
220
  paidThroughEpoch?: number;
208
221
  /** v1.5: true once the lease + grace lapsed (record kept for history; name is claimable) */
209
222
  expired?: true;
223
+ /** v1.9: ENS-class identity — a charset-locked string→string map (doc 36). INERT cosmetic metadata
224
+ * (NOT a send target; the verified address is `addr`). Materialized at v1.9+ tips only, cleared on
225
+ * every ownership change, absent when empty. */
226
+ profile?: Record<string, string>;
210
227
  }
211
228
  type OfferStatus = "open" | "filled" | "cancelled" | "expired";
212
229
  interface FillEntry {
@@ -328,6 +345,7 @@ declare const nameXfer: (r: Omit<NameXferRecord, "v" | "t">) => BuiltRecord;
328
345
  declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
329
346
  declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
330
347
  declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
348
+ declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
331
349
 
332
350
  declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
333
351
  /** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
@@ -339,4 +357,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
339
357
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
340
358
  declare function canonicalState(s: CairnXState): string;
341
359
 
342
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
360
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, 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, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/types.ts
2
+ import { EPOCH_LEN } from "@inversealtruism/csd-codec";
2
3
  var DOMAIN = "cairnx:v1";
3
4
  var ACTIVATION_HEIGHT = 29860;
4
5
  var V11_HEIGHT = 29960;
@@ -8,7 +9,6 @@ var V14_HEIGHT = 31400;
8
9
  var V15_HEIGHT = 32e3;
9
10
  var V16_HEIGHT = 33600;
10
11
  var V17_HEIGHT = 34e3;
11
- var EPOCH_LEN = 30;
12
12
  var NAME_TERM_EPOCHS = 8760;
13
13
  var NAME_GRACE_EPOCHS = 720;
14
14
  var NAME_PREMIUM_START = 20n;
@@ -38,6 +38,10 @@ var DEPLOY_FEE = 1e8;
38
38
  var V18_HEIGHT = 4e4;
39
39
  var NAME_FEE_SHORT_V18 = 670000000n;
40
40
  var NAME_FEE_V18 = 300000000n;
41
+ var V19_HEIGHT = 36700;
42
+ var PKEY = /^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$/;
43
+ var PROFILE_MAX_KEYS = 16;
44
+ var PROFILE_MAX_VALUE_BYTES = 256;
41
45
  function nameRegFee(name, height) {
42
46
  if (height >= V18_HEIGHT) return name.length <= 4 ? NAME_FEE_SHORT_V18 : NAME_FEE_V18;
43
47
  const n = name.length;
@@ -54,6 +58,7 @@ var ADDR_RE = /^0x[0-9a-f]{40}$/;
54
58
  var AMOUNT_RE = /^(0|[1-9][0-9]*)$/;
55
59
  var NAME_RE = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
56
60
  var HASH_RE = /^0x[0-9a-f]{64}$/;
61
+ var SALT_RE = /^[0-9a-fA-F]{16,128}$/;
57
62
  var RESERVED_NAMES = /* @__PURE__ */ new Set(["csd", "treasury", "admin", "official", "root", "www", "support"]);
58
63
  var COMMIT_MAX_BLOCKS = 8 * EPOCH_LEN;
59
64
  var epochOf = (height) => Math.floor(height / EPOCH_LEN);
@@ -109,6 +114,7 @@ var TRANSFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "ticker", "to", "amount",
109
114
  var OFFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "give", "want", "min", "bid", "taker", "memo", "ts"]);
110
115
  var BID_KEYS = /* @__PURE__ */ new Set(["v", "t", "want", "give", "memo", "ts"]);
111
116
  var NAME_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
117
+ var NPROFILE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "p"]);
112
118
  function parseRecord(uri, payloadHashHex) {
113
119
  if (new TextEncoder().encode(uri).length > MAX_RECORD_BYTES) return null;
114
120
  let obj;
@@ -216,7 +222,7 @@ function parseRecord(uri, payloadHashHex) {
216
222
  case "name": {
217
223
  if (!onlyKeys(r, NAME_KEYS)) return null;
218
224
  if (!isName(r.name)) return null;
219
- if (r.salt !== void 0 && (typeof r.salt !== "string" || !/^[0-9a-fA-F]{16,128}$/.test(r.salt))) return null;
225
+ if (r.salt !== void 0 && (typeof r.salt !== "string" || !SALT_RE.test(r.salt))) return null;
220
226
  return r;
221
227
  }
222
228
  case "nxfer": {
@@ -235,9 +241,24 @@ function parseRecord(uri, payloadHashHex) {
235
241
  if (Object.keys(r).length !== 3) return null;
236
242
  return r;
237
243
  }
244
+ case "nprofile": {
245
+ if (!onlyKeys(r, NPROFILE_KEYS)) return null;
246
+ if (!isName(r.name)) return null;
247
+ const p = r.p;
248
+ if (!p || typeof p !== "object" || Array.isArray(p)) return null;
249
+ const keys = Object.keys(p);
250
+ if (keys.length > PROFILE_MAX_KEYS) return null;
251
+ for (const k of keys) {
252
+ if (!PKEY.test(k)) return null;
253
+ const val = p[k];
254
+ if (typeof val !== "string") return null;
255
+ if (new TextEncoder().encode(val).length > PROFILE_MAX_VALUE_BYTES) return null;
256
+ }
257
+ return r;
258
+ }
238
259
  case "tmeta": {
239
260
  if (!isTicker(r.ticker)) return null;
240
- if (typeof r.hash !== "string" || !/^0x[0-9a-f]{64}$/.test(r.hash)) return null;
261
+ if (typeof r.hash !== "string" || !HASH_RE.test(r.hash)) return null;
241
262
  if (Object.keys(r).length !== 4) return null;
242
263
  return r;
243
264
  }
@@ -264,6 +285,7 @@ var nameXfer = (r) => buildRecord({ v: 1, t: "nxfer", ...r });
264
285
  var nameSet = (r) => buildRecord({ v: 1, t: "nset", ...r });
265
286
  var nameRenew = (r) => buildRecord({ v: 1, t: "nrenew", ...r });
266
287
  var tokenMeta = (r) => buildRecord({ v: 1, t: "tmeta", ...r });
288
+ var nameProfile = (r) => buildRecord({ v: 1, t: "nprofile", ...r });
267
289
 
268
290
  // src/resolve.ts
269
291
  var ord = (a, b) => a < b ? -1 : a > b ? 1 : 0;
@@ -347,6 +369,7 @@ function resolve(events, tipHeight) {
347
369
  const v12 = ev.height >= V12_HEIGHT;
348
370
  const v15 = ev.height >= V15_HEIGHT;
349
371
  const v16 = ev.height >= V16_HEIGHT;
372
+ const v19 = ev.height >= V19_HEIGHT;
350
373
  const feeToTreasury = ev.kind === "propose" ? BigInt((ev.paidTo ?? {})[TREASURY_ADDR] ?? "0") : 0n;
351
374
  if (ev.kind === "propose") {
352
375
  const rec = parseRecord(ev.uri, ev.payloadHash);
@@ -502,6 +525,7 @@ function resolve(events, tipHeight) {
502
525
  }
503
526
  n.owner = rec.to.toLowerCase();
504
527
  n.addr = void 0;
528
+ n.profile = void 0;
505
529
  note(ev, ev.id, "nxfer", true);
506
530
  } else if (rec.t === "nset") {
507
531
  const n = names.get(rec.name);
@@ -515,6 +539,22 @@ function resolve(events, tipHeight) {
515
539
  }
516
540
  n.addr = rec.addr.toLowerCase();
517
541
  note(ev, ev.id, "nset", true);
542
+ } else if (rec.t === "nprofile") {
543
+ if (!v19) {
544
+ note(ev, ev.id, "nprofile", false, "before v1.9 activation");
545
+ continue;
546
+ }
547
+ const n = names.get(rec.name);
548
+ if (!n || n.owner !== who) {
549
+ note(ev, ev.id, "nprofile", false, "not the name owner");
550
+ continue;
551
+ }
552
+ if (v15 && lapsed(n, epochOf(ev.height))) {
553
+ note(ev, ev.id, "nprofile", false, "lease lapsed \u2014 claim it instead");
554
+ continue;
555
+ }
556
+ n.profile = Object.keys(rec.p).length ? { ...rec.p } : void 0;
557
+ note(ev, ev.id, "nprofile", true);
518
558
  } else if (rec.t === "offer") {
519
559
  const wantIsToken = isTokenWant(rec.want);
520
560
  if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
@@ -768,6 +808,7 @@ function resolve(events, tipHeight) {
768
808
  giveName.owner = who;
769
809
  giveName.locked = false;
770
810
  giveName.addr = void 0;
811
+ giveName.profile = void 0;
771
812
  if (ev.height >= V13_HEIGHT) {
772
813
  giveName.effHeight = ev.height;
773
814
  giveName.pos = ev.pos;
@@ -897,6 +938,7 @@ function resolve(events, tipHeight) {
897
938
  n.owner = who;
898
939
  n.locked = false;
899
940
  n.addr = void 0;
941
+ n.profile = void 0;
900
942
  if (ev.height >= V13_HEIGHT) {
901
943
  n.effHeight = ev.height;
902
944
  n.pos = ev.pos;
@@ -967,6 +1009,7 @@ function resolve(events, tipHeight) {
967
1009
  }
968
1010
  const namesOut = {};
969
1011
  const tipV15 = tipHeight >= V15_HEIGHT;
1012
+ const tipV19 = tipHeight >= V19_HEIGHT;
970
1013
  const tipEpoch = epochOf(tipHeight);
971
1014
  for (const [nm, n] of [...names.entries()].sort(([a], [b]) => ord(a, b))) {
972
1015
  namesOut[nm] = {
@@ -978,6 +1021,9 @@ function resolve(events, tipHeight) {
978
1021
  locked: n.locked,
979
1022
  ...n.addr ? { addr: n.addr } : {},
980
1023
  ...n.viaFill ? { viaFill: true } : {},
1024
+ // v1.9 profile materialized at v1.9+ tips ONLY (the apply is also gated) → every pre-v1.9 canonical
1025
+ // hash stays byte-identical; absent when empty/unset.
1026
+ ...tipV19 && n.profile ? { profile: n.profile } : {},
981
1027
  // lease fields exist only at v1.5+ tips so every pre-v1.5 canonical hash stays pinned
982
1028
  ...tipV15 ? { paidThroughEpoch: paidThrough(n), ...lapsed(n, tipEpoch) ? { expired: true } : {} } : {}
983
1029
  };
@@ -1023,9 +1069,13 @@ export {
1023
1069
  NAME_PREMIUM_START,
1024
1070
  NAME_RE,
1025
1071
  NAME_TERM_EPOCHS,
1072
+ PKEY,
1073
+ PROFILE_MAX_KEYS,
1074
+ PROFILE_MAX_VALUE_BYTES,
1026
1075
  REBATE_BPS,
1027
1076
  REBATE_FLAT,
1028
1077
  RESERVED_NAMES,
1078
+ SALT_RE,
1029
1079
  SCORE_CANCEL,
1030
1080
  SCORE_CLAIM,
1031
1081
  SCORE_FILL,
@@ -1039,6 +1089,7 @@ export {
1039
1089
  V16_HEIGHT,
1040
1090
  V17_HEIGHT,
1041
1091
  V18_HEIGHT,
1092
+ V19_HEIGHT,
1042
1093
  bid,
1043
1094
  buildRecord,
1044
1095
  canonicalState,
@@ -1053,6 +1104,7 @@ export {
1053
1104
  nameClaim,
1054
1105
  nameCommit,
1055
1106
  nameCommitRecord,
1107
+ nameProfile,
1056
1108
  nameRegFee,
1057
1109
  nameRenew,
1058
1110
  nameSet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "CairnX — tokens, atomic DvP trades and leased .csd names on Compute Substrate, as a pure deterministic convention library (Ordinals/Runes class). Ships the normative CONVENTION.md and the conformance vectors.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "test/vectors"
23
23
  ],
24
24
  "dependencies": {
25
- "@inversealtruism/csd-codec": "0.1.11"
25
+ "@inversealtruism/csd-codec": "0.1.13"
26
26
  },
27
27
  "license": "MIT",
28
28
  "sideEffects": false,