@inversealtruism/cairnx-core 0.1.11 → 0.1.12
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 +55 -0
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +50 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,9 @@ __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,
|
|
@@ -59,6 +62,7 @@ __export(index_exports, {
|
|
|
59
62
|
V16_HEIGHT: () => V16_HEIGHT,
|
|
60
63
|
V17_HEIGHT: () => V17_HEIGHT,
|
|
61
64
|
V18_HEIGHT: () => V18_HEIGHT,
|
|
65
|
+
V19_HEIGHT: () => V19_HEIGHT,
|
|
62
66
|
bid: () => bid,
|
|
63
67
|
buildRecord: () => buildRecord,
|
|
64
68
|
canonicalState: () => canonicalState,
|
|
@@ -73,6 +77,7 @@ __export(index_exports, {
|
|
|
73
77
|
nameClaim: () => nameClaim,
|
|
74
78
|
nameCommit: () => nameCommit,
|
|
75
79
|
nameCommitRecord: () => nameCommitRecord,
|
|
80
|
+
nameProfile: () => nameProfile,
|
|
76
81
|
nameRegFee: () => nameRegFee,
|
|
77
82
|
nameRenew: () => nameRenew,
|
|
78
83
|
nameSet: () => nameSet,
|
|
@@ -128,6 +133,10 @@ var DEPLOY_FEE = 1e8;
|
|
|
128
133
|
var V18_HEIGHT = 4e4;
|
|
129
134
|
var NAME_FEE_SHORT_V18 = 670000000n;
|
|
130
135
|
var NAME_FEE_V18 = 300000000n;
|
|
136
|
+
var V19_HEIGHT = 36700;
|
|
137
|
+
var PKEY = /^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$/;
|
|
138
|
+
var PROFILE_MAX_KEYS = 16;
|
|
139
|
+
var PROFILE_MAX_VALUE_BYTES = 256;
|
|
131
140
|
function nameRegFee(name, height) {
|
|
132
141
|
if (height >= V18_HEIGHT) return name.length <= 4 ? NAME_FEE_SHORT_V18 : NAME_FEE_V18;
|
|
133
142
|
const n = name.length;
|
|
@@ -199,6 +208,7 @@ var TRANSFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "ticker", "to", "amount",
|
|
|
199
208
|
var OFFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "give", "want", "min", "bid", "taker", "memo", "ts"]);
|
|
200
209
|
var BID_KEYS = /* @__PURE__ */ new Set(["v", "t", "want", "give", "memo", "ts"]);
|
|
201
210
|
var NAME_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
|
|
211
|
+
var NPROFILE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "p"]);
|
|
202
212
|
function parseRecord(uri, payloadHashHex) {
|
|
203
213
|
if (new TextEncoder().encode(uri).length > MAX_RECORD_BYTES) return null;
|
|
204
214
|
let obj;
|
|
@@ -325,6 +335,21 @@ function parseRecord(uri, payloadHashHex) {
|
|
|
325
335
|
if (Object.keys(r).length !== 3) return null;
|
|
326
336
|
return r;
|
|
327
337
|
}
|
|
338
|
+
case "nprofile": {
|
|
339
|
+
if (!onlyKeys(r, NPROFILE_KEYS)) return null;
|
|
340
|
+
if (!isName(r.name)) return null;
|
|
341
|
+
const p = r.p;
|
|
342
|
+
if (!p || typeof p !== "object" || Array.isArray(p)) return null;
|
|
343
|
+
const keys = Object.keys(p);
|
|
344
|
+
if (keys.length > PROFILE_MAX_KEYS) return null;
|
|
345
|
+
for (const k of keys) {
|
|
346
|
+
if (!PKEY.test(k)) return null;
|
|
347
|
+
const val = p[k];
|
|
348
|
+
if (typeof val !== "string") return null;
|
|
349
|
+
if (new TextEncoder().encode(val).length > PROFILE_MAX_VALUE_BYTES) return null;
|
|
350
|
+
}
|
|
351
|
+
return r;
|
|
352
|
+
}
|
|
328
353
|
case "tmeta": {
|
|
329
354
|
if (!isTicker(r.ticker)) return null;
|
|
330
355
|
if (typeof r.hash !== "string" || !/^0x[0-9a-f]{64}$/.test(r.hash)) return null;
|
|
@@ -354,6 +379,7 @@ var nameXfer = (r) => buildRecord({ v: 1, t: "nxfer", ...r });
|
|
|
354
379
|
var nameSet = (r) => buildRecord({ v: 1, t: "nset", ...r });
|
|
355
380
|
var nameRenew = (r) => buildRecord({ v: 1, t: "nrenew", ...r });
|
|
356
381
|
var tokenMeta = (r) => buildRecord({ v: 1, t: "tmeta", ...r });
|
|
382
|
+
var nameProfile = (r) => buildRecord({ v: 1, t: "nprofile", ...r });
|
|
357
383
|
|
|
358
384
|
// src/resolve.ts
|
|
359
385
|
var ord = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -437,6 +463,7 @@ function resolve(events, tipHeight) {
|
|
|
437
463
|
const v12 = ev.height >= V12_HEIGHT;
|
|
438
464
|
const v15 = ev.height >= V15_HEIGHT;
|
|
439
465
|
const v16 = ev.height >= V16_HEIGHT;
|
|
466
|
+
const v19 = ev.height >= V19_HEIGHT;
|
|
440
467
|
const feeToTreasury = ev.kind === "propose" ? BigInt((ev.paidTo ?? {})[TREASURY_ADDR] ?? "0") : 0n;
|
|
441
468
|
if (ev.kind === "propose") {
|
|
442
469
|
const rec = parseRecord(ev.uri, ev.payloadHash);
|
|
@@ -592,6 +619,7 @@ function resolve(events, tipHeight) {
|
|
|
592
619
|
}
|
|
593
620
|
n.owner = rec.to.toLowerCase();
|
|
594
621
|
n.addr = void 0;
|
|
622
|
+
n.profile = void 0;
|
|
595
623
|
note(ev, ev.id, "nxfer", true);
|
|
596
624
|
} else if (rec.t === "nset") {
|
|
597
625
|
const n = names.get(rec.name);
|
|
@@ -605,6 +633,22 @@ function resolve(events, tipHeight) {
|
|
|
605
633
|
}
|
|
606
634
|
n.addr = rec.addr.toLowerCase();
|
|
607
635
|
note(ev, ev.id, "nset", true);
|
|
636
|
+
} else if (rec.t === "nprofile") {
|
|
637
|
+
if (!v19) {
|
|
638
|
+
note(ev, ev.id, "nprofile", false, "before v1.9 activation");
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
const n = names.get(rec.name);
|
|
642
|
+
if (!n || n.owner !== who) {
|
|
643
|
+
note(ev, ev.id, "nprofile", false, "not the name owner");
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
if (v15 && lapsed(n, epochOf(ev.height))) {
|
|
647
|
+
note(ev, ev.id, "nprofile", false, "lease lapsed \u2014 claim it instead");
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
n.profile = Object.keys(rec.p).length ? { ...rec.p } : void 0;
|
|
651
|
+
note(ev, ev.id, "nprofile", true);
|
|
608
652
|
} else if (rec.t === "offer") {
|
|
609
653
|
const wantIsToken = isTokenWant(rec.want);
|
|
610
654
|
if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
|
|
@@ -858,6 +902,7 @@ function resolve(events, tipHeight) {
|
|
|
858
902
|
giveName.owner = who;
|
|
859
903
|
giveName.locked = false;
|
|
860
904
|
giveName.addr = void 0;
|
|
905
|
+
giveName.profile = void 0;
|
|
861
906
|
if (ev.height >= V13_HEIGHT) {
|
|
862
907
|
giveName.effHeight = ev.height;
|
|
863
908
|
giveName.pos = ev.pos;
|
|
@@ -987,6 +1032,7 @@ function resolve(events, tipHeight) {
|
|
|
987
1032
|
n.owner = who;
|
|
988
1033
|
n.locked = false;
|
|
989
1034
|
n.addr = void 0;
|
|
1035
|
+
n.profile = void 0;
|
|
990
1036
|
if (ev.height >= V13_HEIGHT) {
|
|
991
1037
|
n.effHeight = ev.height;
|
|
992
1038
|
n.pos = ev.pos;
|
|
@@ -1057,6 +1103,7 @@ function resolve(events, tipHeight) {
|
|
|
1057
1103
|
}
|
|
1058
1104
|
const namesOut = {};
|
|
1059
1105
|
const tipV15 = tipHeight >= V15_HEIGHT;
|
|
1106
|
+
const tipV19 = tipHeight >= V19_HEIGHT;
|
|
1060
1107
|
const tipEpoch = epochOf(tipHeight);
|
|
1061
1108
|
for (const [nm, n] of [...names.entries()].sort(([a], [b]) => ord(a, b))) {
|
|
1062
1109
|
namesOut[nm] = {
|
|
@@ -1068,6 +1115,9 @@ function resolve(events, tipHeight) {
|
|
|
1068
1115
|
locked: n.locked,
|
|
1069
1116
|
...n.addr ? { addr: n.addr } : {},
|
|
1070
1117
|
...n.viaFill ? { viaFill: true } : {},
|
|
1118
|
+
// v1.9 profile materialized at v1.9+ tips ONLY (the apply is also gated) → every pre-v1.9 canonical
|
|
1119
|
+
// hash stays byte-identical; absent when empty/unset.
|
|
1120
|
+
...tipV19 && n.profile ? { profile: n.profile } : {},
|
|
1071
1121
|
// lease fields exist only at v1.5+ tips so every pre-v1.5 canonical hash stays pinned
|
|
1072
1122
|
...tipV15 ? { paidThroughEpoch: paidThrough(n), ...lapsed(n, tipEpoch) ? { expired: true } : {} } : {}
|
|
1073
1123
|
};
|
|
@@ -1114,6 +1164,9 @@ function canonicalState(s) {
|
|
|
1114
1164
|
NAME_PREMIUM_START,
|
|
1115
1165
|
NAME_RE,
|
|
1116
1166
|
NAME_TERM_EPOCHS,
|
|
1167
|
+
PKEY,
|
|
1168
|
+
PROFILE_MAX_KEYS,
|
|
1169
|
+
PROFILE_MAX_VALUE_BYTES,
|
|
1117
1170
|
REBATE_BPS,
|
|
1118
1171
|
REBATE_FLAT,
|
|
1119
1172
|
RESERVED_NAMES,
|
|
@@ -1130,6 +1183,7 @@ function canonicalState(s) {
|
|
|
1130
1183
|
V16_HEIGHT,
|
|
1131
1184
|
V17_HEIGHT,
|
|
1132
1185
|
V18_HEIGHT,
|
|
1186
|
+
V19_HEIGHT,
|
|
1133
1187
|
bid,
|
|
1134
1188
|
buildRecord,
|
|
1135
1189
|
canonicalState,
|
|
@@ -1144,6 +1198,7 @@ function canonicalState(s) {
|
|
|
1144
1198
|
nameClaim,
|
|
1145
1199
|
nameCommit,
|
|
1146
1200
|
nameCommitRecord,
|
|
1201
|
+
nameProfile,
|
|
1147
1202
|
nameRegFee,
|
|
1148
1203
|
nameRenew,
|
|
1149
1204
|
nameSet,
|
package/dist/index.d.cts
CHANGED
|
@@ -33,6 +33,10 @@ declare const DEPLOY_FEE = 100000000;
|
|
|
33
33
|
declare const V18_HEIGHT = 40000;
|
|
34
34
|
declare const NAME_FEE_SHORT_V18 = 670000000n;
|
|
35
35
|
declare const NAME_FEE_V18 = 300000000n;
|
|
36
|
+
declare const V19_HEIGHT = 36700;
|
|
37
|
+
declare const PKEY: RegExp;
|
|
38
|
+
declare const PROFILE_MAX_KEYS = 16;
|
|
39
|
+
declare const PROFILE_MAX_VALUE_BYTES = 256;
|
|
36
40
|
declare function nameRegFee(name: string, height: number): bigint;
|
|
37
41
|
declare const tradeFee: (want: bigint, bps?: number) => bigint;
|
|
38
42
|
declare const makerRebate: (value: bigint) => bigint;
|
|
@@ -151,7 +155,13 @@ interface TokenMetaRecord {
|
|
|
151
155
|
ticker: string;
|
|
152
156
|
hash: string;
|
|
153
157
|
}
|
|
154
|
-
|
|
158
|
+
interface NameProfileRecord {
|
|
159
|
+
v: 1;
|
|
160
|
+
t: "nprofile";
|
|
161
|
+
name: string;
|
|
162
|
+
p: Record<string, string>;
|
|
163
|
+
}
|
|
164
|
+
type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
|
|
155
165
|
interface ProposeEvent {
|
|
156
166
|
kind: "propose";
|
|
157
167
|
id: string;
|
|
@@ -207,6 +217,10 @@ interface NameState {
|
|
|
207
217
|
paidThroughEpoch?: number;
|
|
208
218
|
/** v1.5: true once the lease + grace lapsed (record kept for history; name is claimable) */
|
|
209
219
|
expired?: true;
|
|
220
|
+
/** v1.9: ENS-class identity — a charset-locked string→string map (doc 36). INERT cosmetic metadata
|
|
221
|
+
* (NOT a send target; the verified address is `addr`). Materialized at v1.9+ tips only, cleared on
|
|
222
|
+
* every ownership change, absent when empty. */
|
|
223
|
+
profile?: Record<string, string>;
|
|
210
224
|
}
|
|
211
225
|
type OfferStatus = "open" | "filled" | "cancelled" | "expired";
|
|
212
226
|
interface FillEntry {
|
|
@@ -328,6 +342,7 @@ declare const nameXfer: (r: Omit<NameXferRecord, "v" | "t">) => BuiltRecord;
|
|
|
328
342
|
declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
|
|
329
343
|
declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
|
|
330
344
|
declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
|
|
345
|
+
declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
|
|
331
346
|
|
|
332
347
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
333
348
|
/** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
|
|
@@ -339,4 +354,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
|
339
354
|
* history.) Keys sort in ordinal (code-unit) order at every depth. */
|
|
340
355
|
declare function canonicalState(s: CairnXState): string;
|
|
341
356
|
|
|
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 };
|
|
357
|
+
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 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, 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
|
@@ -33,6 +33,10 @@ declare const DEPLOY_FEE = 100000000;
|
|
|
33
33
|
declare const V18_HEIGHT = 40000;
|
|
34
34
|
declare const NAME_FEE_SHORT_V18 = 670000000n;
|
|
35
35
|
declare const NAME_FEE_V18 = 300000000n;
|
|
36
|
+
declare const V19_HEIGHT = 36700;
|
|
37
|
+
declare const PKEY: RegExp;
|
|
38
|
+
declare const PROFILE_MAX_KEYS = 16;
|
|
39
|
+
declare const PROFILE_MAX_VALUE_BYTES = 256;
|
|
36
40
|
declare function nameRegFee(name: string, height: number): bigint;
|
|
37
41
|
declare const tradeFee: (want: bigint, bps?: number) => bigint;
|
|
38
42
|
declare const makerRebate: (value: bigint) => bigint;
|
|
@@ -151,7 +155,13 @@ interface TokenMetaRecord {
|
|
|
151
155
|
ticker: string;
|
|
152
156
|
hash: string;
|
|
153
157
|
}
|
|
154
|
-
|
|
158
|
+
interface NameProfileRecord {
|
|
159
|
+
v: 1;
|
|
160
|
+
t: "nprofile";
|
|
161
|
+
name: string;
|
|
162
|
+
p: Record<string, string>;
|
|
163
|
+
}
|
|
164
|
+
type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
|
|
155
165
|
interface ProposeEvent {
|
|
156
166
|
kind: "propose";
|
|
157
167
|
id: string;
|
|
@@ -207,6 +217,10 @@ interface NameState {
|
|
|
207
217
|
paidThroughEpoch?: number;
|
|
208
218
|
/** v1.5: true once the lease + grace lapsed (record kept for history; name is claimable) */
|
|
209
219
|
expired?: true;
|
|
220
|
+
/** v1.9: ENS-class identity — a charset-locked string→string map (doc 36). INERT cosmetic metadata
|
|
221
|
+
* (NOT a send target; the verified address is `addr`). Materialized at v1.9+ tips only, cleared on
|
|
222
|
+
* every ownership change, absent when empty. */
|
|
223
|
+
profile?: Record<string, string>;
|
|
210
224
|
}
|
|
211
225
|
type OfferStatus = "open" | "filled" | "cancelled" | "expired";
|
|
212
226
|
interface FillEntry {
|
|
@@ -328,6 +342,7 @@ declare const nameXfer: (r: Omit<NameXferRecord, "v" | "t">) => BuiltRecord;
|
|
|
328
342
|
declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
|
|
329
343
|
declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
|
|
330
344
|
declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
|
|
345
|
+
declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
|
|
331
346
|
|
|
332
347
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
333
348
|
/** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
|
|
@@ -339,4 +354,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
|
339
354
|
* history.) Keys sort in ordinal (code-unit) order at every depth. */
|
|
340
355
|
declare function canonicalState(s: CairnXState): string;
|
|
341
356
|
|
|
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 };
|
|
357
|
+
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 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, 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
|
@@ -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;
|
|
@@ -109,6 +113,7 @@ var TRANSFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "ticker", "to", "amount",
|
|
|
109
113
|
var OFFER_KEYS = /* @__PURE__ */ new Set(["v", "t", "give", "want", "min", "bid", "taker", "memo", "ts"]);
|
|
110
114
|
var BID_KEYS = /* @__PURE__ */ new Set(["v", "t", "want", "give", "memo", "ts"]);
|
|
111
115
|
var NAME_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
|
|
116
|
+
var NPROFILE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "p"]);
|
|
112
117
|
function parseRecord(uri, payloadHashHex) {
|
|
113
118
|
if (new TextEncoder().encode(uri).length > MAX_RECORD_BYTES) return null;
|
|
114
119
|
let obj;
|
|
@@ -235,6 +240,21 @@ function parseRecord(uri, payloadHashHex) {
|
|
|
235
240
|
if (Object.keys(r).length !== 3) return null;
|
|
236
241
|
return r;
|
|
237
242
|
}
|
|
243
|
+
case "nprofile": {
|
|
244
|
+
if (!onlyKeys(r, NPROFILE_KEYS)) return null;
|
|
245
|
+
if (!isName(r.name)) return null;
|
|
246
|
+
const p = r.p;
|
|
247
|
+
if (!p || typeof p !== "object" || Array.isArray(p)) return null;
|
|
248
|
+
const keys = Object.keys(p);
|
|
249
|
+
if (keys.length > PROFILE_MAX_KEYS) return null;
|
|
250
|
+
for (const k of keys) {
|
|
251
|
+
if (!PKEY.test(k)) return null;
|
|
252
|
+
const val = p[k];
|
|
253
|
+
if (typeof val !== "string") return null;
|
|
254
|
+
if (new TextEncoder().encode(val).length > PROFILE_MAX_VALUE_BYTES) return null;
|
|
255
|
+
}
|
|
256
|
+
return r;
|
|
257
|
+
}
|
|
238
258
|
case "tmeta": {
|
|
239
259
|
if (!isTicker(r.ticker)) return null;
|
|
240
260
|
if (typeof r.hash !== "string" || !/^0x[0-9a-f]{64}$/.test(r.hash)) return null;
|
|
@@ -264,6 +284,7 @@ var nameXfer = (r) => buildRecord({ v: 1, t: "nxfer", ...r });
|
|
|
264
284
|
var nameSet = (r) => buildRecord({ v: 1, t: "nset", ...r });
|
|
265
285
|
var nameRenew = (r) => buildRecord({ v: 1, t: "nrenew", ...r });
|
|
266
286
|
var tokenMeta = (r) => buildRecord({ v: 1, t: "tmeta", ...r });
|
|
287
|
+
var nameProfile = (r) => buildRecord({ v: 1, t: "nprofile", ...r });
|
|
267
288
|
|
|
268
289
|
// src/resolve.ts
|
|
269
290
|
var ord = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -347,6 +368,7 @@ function resolve(events, tipHeight) {
|
|
|
347
368
|
const v12 = ev.height >= V12_HEIGHT;
|
|
348
369
|
const v15 = ev.height >= V15_HEIGHT;
|
|
349
370
|
const v16 = ev.height >= V16_HEIGHT;
|
|
371
|
+
const v19 = ev.height >= V19_HEIGHT;
|
|
350
372
|
const feeToTreasury = ev.kind === "propose" ? BigInt((ev.paidTo ?? {})[TREASURY_ADDR] ?? "0") : 0n;
|
|
351
373
|
if (ev.kind === "propose") {
|
|
352
374
|
const rec = parseRecord(ev.uri, ev.payloadHash);
|
|
@@ -502,6 +524,7 @@ function resolve(events, tipHeight) {
|
|
|
502
524
|
}
|
|
503
525
|
n.owner = rec.to.toLowerCase();
|
|
504
526
|
n.addr = void 0;
|
|
527
|
+
n.profile = void 0;
|
|
505
528
|
note(ev, ev.id, "nxfer", true);
|
|
506
529
|
} else if (rec.t === "nset") {
|
|
507
530
|
const n = names.get(rec.name);
|
|
@@ -515,6 +538,22 @@ function resolve(events, tipHeight) {
|
|
|
515
538
|
}
|
|
516
539
|
n.addr = rec.addr.toLowerCase();
|
|
517
540
|
note(ev, ev.id, "nset", true);
|
|
541
|
+
} else if (rec.t === "nprofile") {
|
|
542
|
+
if (!v19) {
|
|
543
|
+
note(ev, ev.id, "nprofile", false, "before v1.9 activation");
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
const n = names.get(rec.name);
|
|
547
|
+
if (!n || n.owner !== who) {
|
|
548
|
+
note(ev, ev.id, "nprofile", false, "not the name owner");
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (v15 && lapsed(n, epochOf(ev.height))) {
|
|
552
|
+
note(ev, ev.id, "nprofile", false, "lease lapsed \u2014 claim it instead");
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
n.profile = Object.keys(rec.p).length ? { ...rec.p } : void 0;
|
|
556
|
+
note(ev, ev.id, "nprofile", true);
|
|
518
557
|
} else if (rec.t === "offer") {
|
|
519
558
|
const wantIsToken = isTokenWant(rec.want);
|
|
520
559
|
if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
|
|
@@ -768,6 +807,7 @@ function resolve(events, tipHeight) {
|
|
|
768
807
|
giveName.owner = who;
|
|
769
808
|
giveName.locked = false;
|
|
770
809
|
giveName.addr = void 0;
|
|
810
|
+
giveName.profile = void 0;
|
|
771
811
|
if (ev.height >= V13_HEIGHT) {
|
|
772
812
|
giveName.effHeight = ev.height;
|
|
773
813
|
giveName.pos = ev.pos;
|
|
@@ -897,6 +937,7 @@ function resolve(events, tipHeight) {
|
|
|
897
937
|
n.owner = who;
|
|
898
938
|
n.locked = false;
|
|
899
939
|
n.addr = void 0;
|
|
940
|
+
n.profile = void 0;
|
|
900
941
|
if (ev.height >= V13_HEIGHT) {
|
|
901
942
|
n.effHeight = ev.height;
|
|
902
943
|
n.pos = ev.pos;
|
|
@@ -967,6 +1008,7 @@ function resolve(events, tipHeight) {
|
|
|
967
1008
|
}
|
|
968
1009
|
const namesOut = {};
|
|
969
1010
|
const tipV15 = tipHeight >= V15_HEIGHT;
|
|
1011
|
+
const tipV19 = tipHeight >= V19_HEIGHT;
|
|
970
1012
|
const tipEpoch = epochOf(tipHeight);
|
|
971
1013
|
for (const [nm, n] of [...names.entries()].sort(([a], [b]) => ord(a, b))) {
|
|
972
1014
|
namesOut[nm] = {
|
|
@@ -978,6 +1020,9 @@ function resolve(events, tipHeight) {
|
|
|
978
1020
|
locked: n.locked,
|
|
979
1021
|
...n.addr ? { addr: n.addr } : {},
|
|
980
1022
|
...n.viaFill ? { viaFill: true } : {},
|
|
1023
|
+
// v1.9 profile materialized at v1.9+ tips ONLY (the apply is also gated) → every pre-v1.9 canonical
|
|
1024
|
+
// hash stays byte-identical; absent when empty/unset.
|
|
1025
|
+
...tipV19 && n.profile ? { profile: n.profile } : {},
|
|
981
1026
|
// lease fields exist only at v1.5+ tips so every pre-v1.5 canonical hash stays pinned
|
|
982
1027
|
...tipV15 ? { paidThroughEpoch: paidThrough(n), ...lapsed(n, tipEpoch) ? { expired: true } : {} } : {}
|
|
983
1028
|
};
|
|
@@ -1023,6 +1068,9 @@ export {
|
|
|
1023
1068
|
NAME_PREMIUM_START,
|
|
1024
1069
|
NAME_RE,
|
|
1025
1070
|
NAME_TERM_EPOCHS,
|
|
1071
|
+
PKEY,
|
|
1072
|
+
PROFILE_MAX_KEYS,
|
|
1073
|
+
PROFILE_MAX_VALUE_BYTES,
|
|
1026
1074
|
REBATE_BPS,
|
|
1027
1075
|
REBATE_FLAT,
|
|
1028
1076
|
RESERVED_NAMES,
|
|
@@ -1039,6 +1087,7 @@ export {
|
|
|
1039
1087
|
V16_HEIGHT,
|
|
1040
1088
|
V17_HEIGHT,
|
|
1041
1089
|
V18_HEIGHT,
|
|
1090
|
+
V19_HEIGHT,
|
|
1042
1091
|
bid,
|
|
1043
1092
|
buildRecord,
|
|
1044
1093
|
canonicalState,
|
|
@@ -1053,6 +1102,7 @@ export {
|
|
|
1053
1102
|
nameClaim,
|
|
1054
1103
|
nameCommit,
|
|
1055
1104
|
nameCommitRecord,
|
|
1105
|
+
nameProfile,
|
|
1056
1106
|
nameRegFee,
|
|
1057
1107
|
nameRenew,
|
|
1058
1108
|
nameSet,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inversealtruism/cairnx-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
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.
|
|
25
|
+
"@inversealtruism/csd-codec": "0.1.12"
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"sideEffects": false,
|