@inversealtruism/cairn-sdk 0.4.6 → 0.6.0
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 +13 -21
- package/dist/{chunk-ZFVE6MU7.js → chunk-2A4AJBO5.js} +1 -1
- package/dist/{chunk-2HP3ZXBO.js → chunk-67QBDZPW.js} +36 -5
- package/dist/{chunk-FWTPXLGV.js → chunk-BMH2MACB.js} +2 -2
- package/dist/{chunk-J5J4JEJ6.js → chunk-K5MGEYEU.js} +13 -3
- package/dist/{chunk-OB33SSGA.js → chunk-MLNW2RQB.js} +6 -3
- package/dist/{chunk-E4YQRWZZ.js → chunk-QEYBWBXC.js} +19 -8
- package/dist/connect.cjs +2 -2
- package/dist/connect.d.cts +2 -2
- package/dist/connect.d.ts +2 -2
- package/dist/connect.js +2 -2
- package/dist/content.cjs +18 -8
- package/dist/content.d.cts +8 -5
- package/dist/content.d.ts +8 -5
- package/dist/content.js +2 -2
- package/dist/controller.cjs +7 -4
- package/dist/controller.js +3 -3
- package/dist/index.cjs +214 -227
- package/dist/index.d.cts +54 -23
- package/dist/index.d.ts +54 -23
- package/dist/index.js +144 -53
- package/dist/indexer.cjs +13 -3
- package/dist/indexer.d.cts +3 -0
- package/dist/indexer.d.ts +3 -0
- package/dist/indexer.js +1 -1
- package/dist/react.cjs +12 -5
- package/dist/react.js +8 -4
- package/dist/registry.cjs +34 -5
- package/dist/registry.js +2 -2
- package/package.json +11 -17
- package/dist/board.cjs +0 -231
- package/dist/board.d.cts +0 -151
- package/dist/board.d.ts +0 -151
- package/dist/board.js +0 -7
- package/dist/chunk-E2MA75S3.js +0 -163
package/dist/chunk-E2MA75S3.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CairnError
|
|
3
|
-
} from "./chunk-ZFVE6MU7.js";
|
|
4
|
-
|
|
5
|
-
// src/board.ts
|
|
6
|
-
import { payloadHash } from "@inversealtruism/csd-codec";
|
|
7
|
-
import { MIN_FEE_PROPOSE, MIN_FEE_ATTEST, EPOCH_LEN } from "@inversealtruism/csd-codec";
|
|
8
|
-
var BoardClient = class {
|
|
9
|
-
http;
|
|
10
|
-
wallet;
|
|
11
|
-
constructor(http, wallet) {
|
|
12
|
-
this.http = http;
|
|
13
|
-
this.wallet = wallet;
|
|
14
|
-
}
|
|
15
|
-
requireWallet() {
|
|
16
|
-
if (!this.wallet) {
|
|
17
|
-
throw new CairnError("This action needs a connected wallet. Construct Cairn with a wallet, or call cairn.connect() first.");
|
|
18
|
-
}
|
|
19
|
-
return this.wallet;
|
|
20
|
-
}
|
|
21
|
-
// ---- reads (public) ----------------------------------------------------
|
|
22
|
-
/** Ranked board for a domain + time window. */
|
|
23
|
-
board(opts = {}) {
|
|
24
|
-
return this.http.getJson("/api/board", { domain: opts.domain ?? "all", window: opts.window ?? "all" });
|
|
25
|
-
}
|
|
26
|
-
/** Alias for `board()` — the top items. */
|
|
27
|
-
top(opts = {}) {
|
|
28
|
-
return this.board(opts);
|
|
29
|
-
}
|
|
30
|
-
/** A single item with its supports + pledges + integrity flag. */
|
|
31
|
-
item(id) {
|
|
32
|
-
return this.http.getJson(`/api/item/${encodeURIComponent(id)}`);
|
|
33
|
-
}
|
|
34
|
-
/** Known + discovered domains. */
|
|
35
|
-
domains() {
|
|
36
|
-
return this.http.getJson("/api/domains");
|
|
37
|
-
}
|
|
38
|
-
/** All quests (work-graph items). */
|
|
39
|
-
quests() {
|
|
40
|
-
return this.http.getJson("/api/quests");
|
|
41
|
-
}
|
|
42
|
-
/** A single quest with claims/submissions/payouts. */
|
|
43
|
-
quest(id) {
|
|
44
|
-
return this.http.getJson(`/api/quest/${encodeURIComponent(id)}`);
|
|
45
|
-
}
|
|
46
|
-
/** An address's on-chain-derived profile + identity + reputation. */
|
|
47
|
-
profile(addr, opts = {}) {
|
|
48
|
-
return this.http.getJson(`/api/profile/${encodeURIComponent(addr)}`, opts.live ? { live: 1 } : void 0);
|
|
49
|
-
}
|
|
50
|
-
/** Reputation leaderboard (top 50). */
|
|
51
|
-
leaderboard() {
|
|
52
|
-
return this.http.getJson("/api/leaderboard");
|
|
53
|
-
}
|
|
54
|
-
/** Network dashboard snapshot. */
|
|
55
|
-
network() {
|
|
56
|
-
return this.http.getJson("/api/network");
|
|
57
|
-
}
|
|
58
|
-
/** Network time-series for charts. */
|
|
59
|
-
networkSeries(range = "24h") {
|
|
60
|
-
return this.http.getJson("/api/network/series", { range });
|
|
61
|
-
}
|
|
62
|
-
/** Recent blocks with miner/reward. */
|
|
63
|
-
networkBlocks(limit = 15) {
|
|
64
|
-
return this.http.getJson("/api/network/blocks", { limit });
|
|
65
|
-
}
|
|
66
|
-
/** Per-miner hashrate estimate. */
|
|
67
|
-
miner(addr) {
|
|
68
|
-
return this.http.getJson(`/api/miner/${encodeURIComponent(addr)}`);
|
|
69
|
-
}
|
|
70
|
-
/** Recent activity feed. */
|
|
71
|
-
activity() {
|
|
72
|
-
return this.http.getJson("/api/activity");
|
|
73
|
-
}
|
|
74
|
-
/** The gamified cairn wall. */
|
|
75
|
-
wall() {
|
|
76
|
-
return this.http.getJson("/api/wall");
|
|
77
|
-
}
|
|
78
|
-
/** Server health + chain reachability. */
|
|
79
|
-
health() {
|
|
80
|
-
return this.http.getJson("/api/health");
|
|
81
|
-
}
|
|
82
|
-
// ---- writes (wallet-signed) -------------------------------------------
|
|
83
|
-
/**
|
|
84
|
-
* Publish a board item: compute the canonical payload hash, have the WALLET
|
|
85
|
-
* build/sign/submit the Propose (clear-signed approval), then register the
|
|
86
|
-
* off-chain content. The payload hash is byte-identical to what the cairn
|
|
87
|
-
* server verifies (csd-codec.payloadHash over { v:1, domain, title, body, links }).
|
|
88
|
-
*/
|
|
89
|
-
async propose(input) {
|
|
90
|
-
const wallet = this.requireWallet();
|
|
91
|
-
const content = {
|
|
92
|
-
v: 1,
|
|
93
|
-
domain: input.domain,
|
|
94
|
-
title: input.title,
|
|
95
|
-
body: input.body ?? "",
|
|
96
|
-
links: input.links ?? []
|
|
97
|
-
};
|
|
98
|
-
const ph = payloadHash(content);
|
|
99
|
-
const uri = `cairn:v1:${ph.slice(2, 14)}`;
|
|
100
|
-
const lifetime = input.lifetimeEpochs ?? 720;
|
|
101
|
-
const height = await this.tipHeight();
|
|
102
|
-
const expiresEpoch = Math.floor(height / EPOCH_LEN) + lifetime;
|
|
103
|
-
const fee = input.fee ?? MIN_FEE_PROPOSE;
|
|
104
|
-
const r = await wallet.propose({ domain: content.domain, payloadHash: ph, uri, expiresEpoch, fee });
|
|
105
|
-
const txid = String(r.txid ?? "");
|
|
106
|
-
if (!txid) throw new CairnError("Propose submitted but no txid was returned by the wallet.");
|
|
107
|
-
const reg = await this.tryRegister(content, txid);
|
|
108
|
-
return { txid, payloadHash: ph, content, registered: reg.ok, registerError: reg.error };
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Register off-chain content for an already-submitted proposal txid. Idempotent.
|
|
112
|
-
* Returns { ok } — the cairn server verifies sha256(canonical) == on-chain payload_hash.
|
|
113
|
-
*/
|
|
114
|
-
async registerContent(content, txid) {
|
|
115
|
-
try {
|
|
116
|
-
const res = await this.http.postJson("/api/content", {
|
|
117
|
-
domain: content.domain,
|
|
118
|
-
title: content.title,
|
|
119
|
-
body: content.body,
|
|
120
|
-
links: content.links,
|
|
121
|
-
txid
|
|
122
|
-
});
|
|
123
|
-
return { ok: !!res.ok, error: res.ok ? void 0 : res.error };
|
|
124
|
-
} catch (e) {
|
|
125
|
-
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** Support/attest a proposal (wallet-signed; always clear-signed). */
|
|
129
|
-
async support(proposalId, opts = {}) {
|
|
130
|
-
const wallet = this.requireWallet();
|
|
131
|
-
return wallet.attest({
|
|
132
|
-
proposalId,
|
|
133
|
-
score: opts.score ?? 80,
|
|
134
|
-
confidence: opts.confidence ?? 70,
|
|
135
|
-
fee: opts.fee ?? MIN_FEE_ATTEST
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
// ---- internal ----------------------------------------------------------
|
|
139
|
-
async tipHeight() {
|
|
140
|
-
const tip = await this.http.getJson("/api/rpc/tip");
|
|
141
|
-
const h = Number(tip?.height);
|
|
142
|
-
if (!Number.isFinite(h)) throw new CairnError("Could not read chain tip height for expiry computation.");
|
|
143
|
-
return h;
|
|
144
|
-
}
|
|
145
|
-
async tryRegister(content, txid) {
|
|
146
|
-
const delays = [0, 1500, 3e3, 5e3];
|
|
147
|
-
let last = { ok: false, error: "not attempted" };
|
|
148
|
-
for (const d of delays) {
|
|
149
|
-
if (d) await sleep(d);
|
|
150
|
-
last = await this.registerContent(content, txid);
|
|
151
|
-
if (last.ok) return last;
|
|
152
|
-
if (!/not found yet|not found/i.test(last.error ?? "")) return last;
|
|
153
|
-
}
|
|
154
|
-
return last;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
function sleep(ms) {
|
|
158
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
BoardClient
|
|
163
|
-
};
|