@inversealtruism/cairn-sdk 0.6.0 → 0.7.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 +7 -10
- package/dist/{chunk-BMH2MACB.js → chunk-4FFLCCL4.js} +1 -1
- package/dist/{chunk-K5MGEYEU.js → chunk-CI7YODPP.js} +0 -12
- package/dist/{chunk-2A4AJBO5.js → chunk-PBKDSDID.js} +1 -1
- package/dist/{chunk-QEYBWBXC.js → chunk-TDXGYP3G.js} +17 -27
- package/dist/{chunk-MLNW2RQB.js → chunk-XOGOSGC6.js} +1 -1
- package/dist/connect.cjs +1 -1
- package/dist/connect.js +2 -2
- package/dist/content.cjs +17 -27
- package/dist/content.d.cts +7 -13
- package/dist/content.d.ts +7 -13
- package/dist/content.js +2 -2
- package/dist/controller.cjs +1 -1
- package/dist/controller.js +3 -3
- package/dist/index.cjs +18 -97
- package/dist/index.d.cts +3 -12
- package/dist/index.d.ts +3 -12
- package/dist/index.js +174 -17
- package/dist/indexer.cjs +0 -12
- package/dist/indexer.d.cts +0 -4
- package/dist/indexer.d.ts +0 -4
- package/dist/indexer.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +3 -3
- package/package.json +16 -19
- package/dist/chunk-67QBDZPW.js +0 -254
- package/dist/registry.cjs +0 -326
- package/dist/registry.d.cts +0 -44
- package/dist/registry.d.ts +0 -44
- package/dist/registry.js +0 -27
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,6 @@ import { IndexerClient } from './indexer.cjs';
|
|
|
5
5
|
export { InclusionResult, IndexEvent, MerkleProof, StreamHandle, StreamHandlers, TrustLevel } from './indexer.cjs';
|
|
6
6
|
import { ContentClient } from './content.cjs';
|
|
7
7
|
export { ContentClientOptions, PreparedContent } from './content.cjs';
|
|
8
|
-
import { RegistryClient } from './registry.cjs';
|
|
9
8
|
import { NameState, MintedProvenOfferTerms } from '@inversealtruism/cairnx-core';
|
|
10
9
|
export { FillEndorsement, FillOutputPlan, FillPreview, FillSafety, MintedProvenOfferTerms, ProvenOfferTerms, bindOfferTerms, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, previewFill, requiredFillOutputs } from '@inversealtruism/cairnx-core';
|
|
11
10
|
import { WalletConnection, DetectOptions } from './connect.cjs';
|
|
@@ -16,7 +15,6 @@ import '@inversealtruism/csd-client';
|
|
|
16
15
|
import '@inversealtruism/csd-tx';
|
|
17
16
|
import '@inversealtruism/csd-codec';
|
|
18
17
|
import '@inversealtruism/csd-crypto';
|
|
19
|
-
import '@inversealtruism/csd-registry';
|
|
20
18
|
|
|
21
19
|
/** `/cairnx/resolve/:name` — the display-path name→address resolution. */
|
|
22
20
|
interface NameResolution {
|
|
@@ -191,7 +189,7 @@ declare function preverifyOffer(opts: {
|
|
|
191
189
|
|
|
192
190
|
/** Stable machine-readable error codes (branch on these, not the message text). */
|
|
193
191
|
type CairnErrorCode = "NOT_INSTALLED" | "USER_REJECTED" | "WALLET_LOCKED" | "UNSUPPORTED_METHOD" | "HTTP_ERROR" | "CONTENT_VERIFICATION" | "CONTENT_NOT_JSON" | "ACCOUNT_CHANGED" | "FIRST_PARTY_ONLY" | "RATE_LIMITED" | "APPROVAL_CLOSED" | "FORBIDDEN" | "INTERNAL" | "GHOST_INPUTS_SKIPPED" | "VERIFY_UNAVAILABLE" | "VERIFY_TAMPER" | "INSUFFICIENT" | "TOO_MANY_INPUTS" | "FEE_TOO_LOW" | "FEE_CAP" | "BAD_FEE" | "ZERO_ADDR_REFUSED" | "BAD_OUTPUTS" | "NO_OUTPUTS" | "BAD_REQUEST" | "OFFER_UNKNOWN" | "FILL_UNSAFE" | "FILL_WRONG_TARGET" | "SOURCE_DIVERGENCE" | "SUBMIT_REJECTED" | "SUBMIT_MAYBE_INFLIGHT" | "SUBMIT_DUPLICATE" | "NOTHING_TO_CONSOLIDATE" | "OFFER_SOURCE_CONFLICT" | "FILL_LEGACY_SUNSET" | "VERIFY_HORIZON" | "VERIFY_UNREPRESENTABLE" | "WALLET_UNAVAILABLE" | "REVIEW_REQUIRED" | "UNKNOWN";
|
|
194
|
-
declare const SDK_VERSION = "0.
|
|
192
|
+
declare const SDK_VERSION = "0.7.0";
|
|
195
193
|
interface CairnErrorOptions {
|
|
196
194
|
code?: CairnErrorCode;
|
|
197
195
|
docsPath?: string;
|
|
@@ -211,7 +209,7 @@ declare class CairnError extends Error {
|
|
|
211
209
|
/** Relative docs path (under the SDK docs base), if any. */
|
|
212
210
|
readonly docsPath?: string;
|
|
213
211
|
/** The cairn-sdk version that produced this error. */
|
|
214
|
-
readonly version = "0.
|
|
212
|
+
readonly version = "0.7.0";
|
|
215
213
|
/**
|
|
216
214
|
* Whether a dApp may safely AUTO-retry this failure. `false` for fund-safety refusals and user-intent
|
|
217
215
|
* declines (the default); `true` only for provably transient infra faults where nothing was signed.
|
|
@@ -302,12 +300,6 @@ interface CairnBaseUrls {
|
|
|
302
300
|
* needs a direct indexer endpoint (set this to a localhost/private indexer URL).
|
|
303
301
|
*/
|
|
304
302
|
indexer?: string;
|
|
305
|
-
/**
|
|
306
|
-
* Optional direct csd-swarm gateway base. Not set by default — content is reached
|
|
307
|
-
* via the indexer proxy (which fronts the swarm) and the cairn origin, both verified.
|
|
308
|
-
* Set this only if you run a public swarm gateway.
|
|
309
|
-
*/
|
|
310
|
-
swarm?: string;
|
|
311
303
|
}
|
|
312
304
|
interface CairnConfig {
|
|
313
305
|
/** Currently only "mainnet". Selects the default base URLs. */
|
|
@@ -343,7 +335,6 @@ declare class Cairn {
|
|
|
343
335
|
readonly chain: Chain;
|
|
344
336
|
readonly index: IndexerClient;
|
|
345
337
|
readonly content: ContentClient;
|
|
346
|
-
readonly registry: RegistryClient;
|
|
347
338
|
/** .csd names + CairnX market READS (server-trusted display reads; see names.ts trust note). */
|
|
348
339
|
readonly names: NamesClient;
|
|
349
340
|
wallet?: WalletConnection;
|
|
@@ -424,4 +415,4 @@ declare class Cairn {
|
|
|
424
415
|
get connected(): boolean;
|
|
425
416
|
}
|
|
426
417
|
|
|
427
|
-
export { Cairn, type CairnBaseUrls, type CairnConfig, CairnError, type CairnErrorCode, type CairnErrorOptions, Chain, ContentClient, ContentVerificationError, DEFAULT_SPV_CHECKPOINT, DetectOptions, FetchLike, Http, HttpError, IndexerClient, type NameDetail, type NameHistory, type NameHistoryEntry, type NameResolution, NamesClient, NotInstalledError, type OfferFillCheck, type PrimaryName,
|
|
418
|
+
export { Cairn, type CairnBaseUrls, type CairnConfig, CairnError, type CairnErrorCode, type CairnErrorOptions, Chain, ContentClient, ContentVerificationError, DEFAULT_SPV_CHECKPOINT, DetectOptions, FetchLike, Http, HttpError, IndexerClient, type NameDetail, type NameHistory, type NameHistoryEntry, type NameResolution, NamesClient, NotInstalledError, type OfferFillCheck, type PrimaryName, SDK_VERSION, SubmitInFlightError, type TokenInfo, UnsupportedMethodError, UserRejectedError, WalletConnection, WalletLockedError, errorCode, mapProviderError, mapSubmitResultError, preverifyOffer };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { IndexerClient } from './indexer.js';
|
|
|
5
5
|
export { InclusionResult, IndexEvent, MerkleProof, StreamHandle, StreamHandlers, TrustLevel } from './indexer.js';
|
|
6
6
|
import { ContentClient } from './content.js';
|
|
7
7
|
export { ContentClientOptions, PreparedContent } from './content.js';
|
|
8
|
-
import { RegistryClient } from './registry.js';
|
|
9
8
|
import { NameState, MintedProvenOfferTerms } from '@inversealtruism/cairnx-core';
|
|
10
9
|
export { FillEndorsement, FillOutputPlan, FillPreview, FillSafety, MintedProvenOfferTerms, ProvenOfferTerms, bindOfferTerms, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, previewFill, requiredFillOutputs } from '@inversealtruism/cairnx-core';
|
|
11
10
|
import { WalletConnection, DetectOptions } from './connect.js';
|
|
@@ -16,7 +15,6 @@ import '@inversealtruism/csd-client';
|
|
|
16
15
|
import '@inversealtruism/csd-tx';
|
|
17
16
|
import '@inversealtruism/csd-codec';
|
|
18
17
|
import '@inversealtruism/csd-crypto';
|
|
19
|
-
import '@inversealtruism/csd-registry';
|
|
20
18
|
|
|
21
19
|
/** `/cairnx/resolve/:name` — the display-path name→address resolution. */
|
|
22
20
|
interface NameResolution {
|
|
@@ -191,7 +189,7 @@ declare function preverifyOffer(opts: {
|
|
|
191
189
|
|
|
192
190
|
/** Stable machine-readable error codes (branch on these, not the message text). */
|
|
193
191
|
type CairnErrorCode = "NOT_INSTALLED" | "USER_REJECTED" | "WALLET_LOCKED" | "UNSUPPORTED_METHOD" | "HTTP_ERROR" | "CONTENT_VERIFICATION" | "CONTENT_NOT_JSON" | "ACCOUNT_CHANGED" | "FIRST_PARTY_ONLY" | "RATE_LIMITED" | "APPROVAL_CLOSED" | "FORBIDDEN" | "INTERNAL" | "GHOST_INPUTS_SKIPPED" | "VERIFY_UNAVAILABLE" | "VERIFY_TAMPER" | "INSUFFICIENT" | "TOO_MANY_INPUTS" | "FEE_TOO_LOW" | "FEE_CAP" | "BAD_FEE" | "ZERO_ADDR_REFUSED" | "BAD_OUTPUTS" | "NO_OUTPUTS" | "BAD_REQUEST" | "OFFER_UNKNOWN" | "FILL_UNSAFE" | "FILL_WRONG_TARGET" | "SOURCE_DIVERGENCE" | "SUBMIT_REJECTED" | "SUBMIT_MAYBE_INFLIGHT" | "SUBMIT_DUPLICATE" | "NOTHING_TO_CONSOLIDATE" | "OFFER_SOURCE_CONFLICT" | "FILL_LEGACY_SUNSET" | "VERIFY_HORIZON" | "VERIFY_UNREPRESENTABLE" | "WALLET_UNAVAILABLE" | "REVIEW_REQUIRED" | "UNKNOWN";
|
|
194
|
-
declare const SDK_VERSION = "0.
|
|
192
|
+
declare const SDK_VERSION = "0.7.0";
|
|
195
193
|
interface CairnErrorOptions {
|
|
196
194
|
code?: CairnErrorCode;
|
|
197
195
|
docsPath?: string;
|
|
@@ -211,7 +209,7 @@ declare class CairnError extends Error {
|
|
|
211
209
|
/** Relative docs path (under the SDK docs base), if any. */
|
|
212
210
|
readonly docsPath?: string;
|
|
213
211
|
/** The cairn-sdk version that produced this error. */
|
|
214
|
-
readonly version = "0.
|
|
212
|
+
readonly version = "0.7.0";
|
|
215
213
|
/**
|
|
216
214
|
* Whether a dApp may safely AUTO-retry this failure. `false` for fund-safety refusals and user-intent
|
|
217
215
|
* declines (the default); `true` only for provably transient infra faults where nothing was signed.
|
|
@@ -302,12 +300,6 @@ interface CairnBaseUrls {
|
|
|
302
300
|
* needs a direct indexer endpoint (set this to a localhost/private indexer URL).
|
|
303
301
|
*/
|
|
304
302
|
indexer?: string;
|
|
305
|
-
/**
|
|
306
|
-
* Optional direct csd-swarm gateway base. Not set by default — content is reached
|
|
307
|
-
* via the indexer proxy (which fronts the swarm) and the cairn origin, both verified.
|
|
308
|
-
* Set this only if you run a public swarm gateway.
|
|
309
|
-
*/
|
|
310
|
-
swarm?: string;
|
|
311
303
|
}
|
|
312
304
|
interface CairnConfig {
|
|
313
305
|
/** Currently only "mainnet". Selects the default base URLs. */
|
|
@@ -343,7 +335,6 @@ declare class Cairn {
|
|
|
343
335
|
readonly chain: Chain;
|
|
344
336
|
readonly index: IndexerClient;
|
|
345
337
|
readonly content: ContentClient;
|
|
346
|
-
readonly registry: RegistryClient;
|
|
347
338
|
/** .csd names + CairnX market READS (server-trusted display reads; see names.ts trust note). */
|
|
348
339
|
readonly names: NamesClient;
|
|
349
340
|
wallet?: WalletConnection;
|
|
@@ -424,4 +415,4 @@ declare class Cairn {
|
|
|
424
415
|
get connected(): boolean;
|
|
425
416
|
}
|
|
426
417
|
|
|
427
|
-
export { Cairn, type CairnBaseUrls, type CairnConfig, CairnError, type CairnErrorCode, type CairnErrorOptions, Chain, ContentClient, ContentVerificationError, DEFAULT_SPV_CHECKPOINT, DetectOptions, FetchLike, Http, HttpError, IndexerClient, type NameDetail, type NameHistory, type NameHistoryEntry, type NameResolution, NamesClient, NotInstalledError, type OfferFillCheck, type PrimaryName,
|
|
418
|
+
export { Cairn, type CairnBaseUrls, type CairnConfig, CairnError, type CairnErrorCode, type CairnErrorOptions, Chain, ContentClient, ContentVerificationError, DEFAULT_SPV_CHECKPOINT, DetectOptions, FetchLike, Http, HttpError, IndexerClient, type NameDetail, type NameHistory, type NameHistoryEntry, type NameResolution, NamesClient, NotInstalledError, type OfferFillCheck, type PrimaryName, SDK_VERSION, SubmitInFlightError, type TokenInfo, UnsupportedMethodError, UserRejectedError, WalletConnection, WalletLockedError, errorCode, mapProviderError, mapSubmitResultError, preverifyOffer };
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
} from "./chunk-C452UODV.js";
|
|
5
5
|
import {
|
|
6
6
|
ContentClient
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TDXGYP3G.js";
|
|
8
8
|
import {
|
|
9
9
|
IndexerClient
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CI7YODPP.js";
|
|
11
11
|
import {
|
|
12
12
|
CairnController
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-XOGOSGC6.js";
|
|
14
14
|
import {
|
|
15
15
|
WalletConnection,
|
|
16
16
|
connect,
|
|
@@ -18,14 +18,7 @@ import {
|
|
|
18
18
|
discoverProviders,
|
|
19
19
|
getWallet,
|
|
20
20
|
isInstalled
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import {
|
|
23
|
-
Http,
|
|
24
|
-
RegistryClient,
|
|
25
|
-
RetryWaitBudget,
|
|
26
|
-
readCapped,
|
|
27
|
-
retryAfterMs
|
|
28
|
-
} from "./chunk-67QBDZPW.js";
|
|
21
|
+
} from "./chunk-4FFLCCL4.js";
|
|
29
22
|
import {
|
|
30
23
|
CairnError,
|
|
31
24
|
ContentVerificationError,
|
|
@@ -39,7 +32,175 @@ import {
|
|
|
39
32
|
errorCode,
|
|
40
33
|
mapProviderError,
|
|
41
34
|
mapSubmitResultError
|
|
42
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-PBKDSDID.js";
|
|
36
|
+
|
|
37
|
+
// src/http.ts
|
|
38
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
39
|
+
var ERR_TEXT_CAP = 8 * 1024;
|
|
40
|
+
var MAX_RETRY_AFTER_MS = 6e4;
|
|
41
|
+
function retryAfterMs(res) {
|
|
42
|
+
const secs = Number(res.headers.get("retry-after"));
|
|
43
|
+
return Number.isFinite(secs) && secs > 0 ? Math.min(secs * 1e3, MAX_RETRY_AFTER_MS) : 0;
|
|
44
|
+
}
|
|
45
|
+
var RetryWaitBudget = class {
|
|
46
|
+
left;
|
|
47
|
+
constructor(totalMs) {
|
|
48
|
+
this.left = totalMs;
|
|
49
|
+
}
|
|
50
|
+
/** The ms to sleep before the next attempt (`ownMs` is the caller's backoff, clipped to what is left), or
|
|
51
|
+
* null when the server's hint exceeds the remaining budget. */
|
|
52
|
+
take(ownMs, serverMs) {
|
|
53
|
+
if (serverMs > this.left) return null;
|
|
54
|
+
const ms = Math.min(Math.max(ownMs, serverMs), this.left);
|
|
55
|
+
this.left -= ms;
|
|
56
|
+
return ms;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var HTTP_RETRY_WAIT_BUDGET_MS = 3e4;
|
|
60
|
+
async function readCapped(res, maxBytes) {
|
|
61
|
+
const cl = Number(res.headers.get("content-length"));
|
|
62
|
+
if (Number.isFinite(cl) && cl > maxBytes) throw new HttpError(res.status, res.url, `response too large (content-length ${cl} > ${maxBytes})`);
|
|
63
|
+
const body = res.body;
|
|
64
|
+
if (!body || typeof body.getReader !== "function") {
|
|
65
|
+
const buf = new Uint8Array(await res.arrayBuffer());
|
|
66
|
+
if (buf.byteLength > maxBytes) throw new HttpError(res.status, res.url, `response too large (${buf.byteLength} > ${maxBytes})`);
|
|
67
|
+
return buf;
|
|
68
|
+
}
|
|
69
|
+
const reader = body.getReader();
|
|
70
|
+
const chunks = [];
|
|
71
|
+
let total = 0;
|
|
72
|
+
for (; ; ) {
|
|
73
|
+
const { done, value } = await reader.read();
|
|
74
|
+
if (done) break;
|
|
75
|
+
if (value) {
|
|
76
|
+
total += value.byteLength;
|
|
77
|
+
if (total > maxBytes) {
|
|
78
|
+
try {
|
|
79
|
+
await reader.cancel();
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
throw new HttpError(res.status, res.url, `response exceeded ${maxBytes} bytes`);
|
|
83
|
+
}
|
|
84
|
+
chunks.push(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const out = new Uint8Array(total);
|
|
88
|
+
let off = 0;
|
|
89
|
+
for (const c of chunks) {
|
|
90
|
+
out.set(c, off);
|
|
91
|
+
off += c.byteLength;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
var Http = class {
|
|
96
|
+
baseUrl;
|
|
97
|
+
_fetch;
|
|
98
|
+
timeoutMs;
|
|
99
|
+
maxBytes;
|
|
100
|
+
headers;
|
|
101
|
+
retries;
|
|
102
|
+
constructor(opts) {
|
|
103
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
104
|
+
const f = opts.fetch ?? globalThis.fetch;
|
|
105
|
+
if (!f) throw new Error("No fetch available \u2014 pass `fetch` in the SDK options.");
|
|
106
|
+
this._fetch = opts.fetch ? opts.fetch : f.bind(globalThis);
|
|
107
|
+
this.timeoutMs = opts.timeoutMs ?? 15e3;
|
|
108
|
+
this.maxBytes = Number.isFinite(opts.maxBytes) && opts.maxBytes >= 1 ? Math.floor(opts.maxBytes) : DEFAULT_MAX_BYTES;
|
|
109
|
+
this.headers = opts.headers ?? {};
|
|
110
|
+
const retries = Number(opts.retries ?? 0);
|
|
111
|
+
this.retries = Number.isNaN(retries) ? 0 : Math.min(10, Math.max(0, Math.floor(retries)));
|
|
112
|
+
}
|
|
113
|
+
/** Build an absolute URL from a path + optional query params. */
|
|
114
|
+
url(path, query) {
|
|
115
|
+
const p = path.startsWith("/") ? path : `/${path}`;
|
|
116
|
+
const u = new URL(this.baseUrl + p);
|
|
117
|
+
const basePath = new URL(this.baseUrl + "/").pathname;
|
|
118
|
+
if (basePath !== "/" && !(u.pathname + "/").startsWith(basePath)) {
|
|
119
|
+
throw new Error(`illegal path '${path}' \u2014 escapes base ${basePath}`);
|
|
120
|
+
}
|
|
121
|
+
if (query) {
|
|
122
|
+
for (const [k, v] of Object.entries(query)) {
|
|
123
|
+
if (v !== void 0 && v !== null) u.searchParams.set(k, String(v));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return u.toString();
|
|
127
|
+
}
|
|
128
|
+
async raw(method, path, opts) {
|
|
129
|
+
const url = this.url(path, opts?.query);
|
|
130
|
+
const ctrl = new AbortController();
|
|
131
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
132
|
+
try {
|
|
133
|
+
const res = await this._fetch(url, {
|
|
134
|
+
method,
|
|
135
|
+
signal: ctrl.signal,
|
|
136
|
+
headers: {
|
|
137
|
+
...opts?.body !== void 0 ? { "content-type": "application/json" } : {},
|
|
138
|
+
...this.headers,
|
|
139
|
+
...opts?.headers ?? {}
|
|
140
|
+
},
|
|
141
|
+
body: opts?.body !== void 0 ? JSON.stringify(opts.body) : void 0
|
|
142
|
+
});
|
|
143
|
+
const body = await readCapped(res, this.maxBytes);
|
|
144
|
+
return { res, body };
|
|
145
|
+
} finally {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// A malformed 2xx body must surface as a TYPED HttpError, not a leaked SyntaxError (B10: dApp
|
|
150
|
+
// code branches on `instanceof CairnError`; a raw parse error escaped that contract).
|
|
151
|
+
parseJson(res, text, url) {
|
|
152
|
+
try {
|
|
153
|
+
return JSON.parse(text);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
throw new HttpError(res.status, url, `invalid JSON body: ${text.slice(0, 120)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async getJson(path, query) {
|
|
159
|
+
const url = this.url(path, query);
|
|
160
|
+
const budget = new RetryWaitBudget(HTTP_RETRY_WAIT_BUDGET_MS);
|
|
161
|
+
for (let attempt = 0; ; attempt++) {
|
|
162
|
+
let serverWaitMs = 0;
|
|
163
|
+
let last;
|
|
164
|
+
try {
|
|
165
|
+
const { res, body } = await this.raw("GET", path, { query });
|
|
166
|
+
if (!res.ok) {
|
|
167
|
+
last = new HttpError(res.status, url, errText(body));
|
|
168
|
+
if (!(res.status >= 500 && attempt < this.retries)) throw last;
|
|
169
|
+
serverWaitMs = retryAfterMs(res);
|
|
170
|
+
} else {
|
|
171
|
+
return this.parseJson(res, new TextDecoder().decode(body), url);
|
|
172
|
+
}
|
|
173
|
+
} catch (e) {
|
|
174
|
+
if (e instanceof HttpError && e.status < 500) throw e;
|
|
175
|
+
if (attempt >= this.retries) throw e;
|
|
176
|
+
}
|
|
177
|
+
const jitterMs = Math.floor(Math.random() * Math.min(4e3, 250 * 2 ** attempt));
|
|
178
|
+
const waitMs = budget.take(jitterMs, serverWaitMs);
|
|
179
|
+
if (waitMs === null) throw last ?? new HttpError(0, url, "retry wait budget exhausted");
|
|
180
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async postJson(path, body, headers) {
|
|
184
|
+
const url = this.url(path);
|
|
185
|
+
const { res, body: respBody } = await this.raw("POST", path, { body, headers });
|
|
186
|
+
if (!res.ok) throw new HttpError(res.status, url, errText(respBody));
|
|
187
|
+
return this.parseJson(res, new TextDecoder().decode(respBody), url);
|
|
188
|
+
}
|
|
189
|
+
/** GET raw bytes (for content retrieval). Returns null on 404. */
|
|
190
|
+
async getBytes(path) {
|
|
191
|
+
const { res, body } = await this.raw("GET", path);
|
|
192
|
+
if (res.status === 404) return null;
|
|
193
|
+
if (!res.ok) throw new HttpError(res.status, this.url(path), errText(body));
|
|
194
|
+
return { bytes: body, headers: res.headers };
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
function errText(body) {
|
|
198
|
+
try {
|
|
199
|
+
return new TextDecoder().decode(body).slice(0, ERR_TEXT_CAP);
|
|
200
|
+
} catch {
|
|
201
|
+
return "";
|
|
202
|
+
}
|
|
203
|
+
}
|
|
43
204
|
|
|
44
205
|
// src/names.ts
|
|
45
206
|
import { NAME_RE, RESERVED_NAMES, TICKER_RE, AMOUNT_RE, HASH_RE } from "@inversealtruism/cairnx-core";
|
|
@@ -379,7 +540,6 @@ var Cairn = class {
|
|
|
379
540
|
chain;
|
|
380
541
|
index;
|
|
381
542
|
content;
|
|
382
|
-
registry;
|
|
383
543
|
/** .csd names + CairnX market READS (server-trusted display reads; see names.ts trust note). */
|
|
384
544
|
names;
|
|
385
545
|
wallet;
|
|
@@ -403,7 +563,6 @@ var Cairn = class {
|
|
|
403
563
|
this.cairnHttp = new Http({ baseUrl: cairn, fetch, timeoutMs });
|
|
404
564
|
this._cairnBase = cairn;
|
|
405
565
|
const indexerHttp = new Http({ baseUrl: indexer, fetch, timeoutMs });
|
|
406
|
-
const swarmHttp = config.baseUrls?.swarm ? new Http({ baseUrl: config.baseUrls.swarm.replace(/\/+$/, ""), fetch, timeoutMs }) : void 0;
|
|
407
566
|
this._spvCp = config.spvCheckpoint ?? DEFAULT_SPV_CHECKPOINT;
|
|
408
567
|
this.chain = new Chain({ rpcUrl: rpc, fetch, timeoutMs });
|
|
409
568
|
this.wallet = config.wallet;
|
|
@@ -412,8 +571,7 @@ var Cairn = class {
|
|
|
412
571
|
WebSocketImpl: config.WebSocketImpl,
|
|
413
572
|
headerMerkleAt: (h) => this.verifiedHeaderMerkleAt(h)
|
|
414
573
|
});
|
|
415
|
-
this.content = new ContentClient({
|
|
416
|
-
this.registry = new RegistryClient(indexerHttp);
|
|
574
|
+
this.content = new ContentClient({ cairn: this.cairnHttp });
|
|
417
575
|
this.names = new NamesClient(this.cairnHttp);
|
|
418
576
|
}
|
|
419
577
|
/**
|
|
@@ -621,7 +779,6 @@ export {
|
|
|
621
779
|
IndexerClient,
|
|
622
780
|
NamesClient,
|
|
623
781
|
NotInstalledError,
|
|
624
|
-
RegistryClient,
|
|
625
782
|
SDK_VERSION,
|
|
626
783
|
SubmitInFlightError,
|
|
627
784
|
UnsupportedMethodError,
|
package/dist/indexer.cjs
CHANGED
|
@@ -93,18 +93,6 @@ var IndexerClient = class {
|
|
|
93
93
|
attestations(id) {
|
|
94
94
|
return this.http.getJson(`/proposal/${encodeURIComponent(id)}/attestations`);
|
|
95
95
|
}
|
|
96
|
-
registryPeers() {
|
|
97
|
-
return this.http.getJson("/registry/peers");
|
|
98
|
-
}
|
|
99
|
-
registryGateways() {
|
|
100
|
-
return this.http.getJson("/registry/gateways");
|
|
101
|
-
}
|
|
102
|
-
identity(handle) {
|
|
103
|
-
return this.http.getJson(`/identity/${encodeURIComponent(handle)}`);
|
|
104
|
-
}
|
|
105
|
-
reverseIdentity(addr) {
|
|
106
|
-
return this.http.getJson(`/address/${encodeURIComponent(addr)}/identity`);
|
|
107
|
-
}
|
|
108
96
|
// ---- trust-minimized inclusion ----------------------------------------
|
|
109
97
|
/**
|
|
110
98
|
* Verify a tx is included in a block by folding its merkle branch to the root
|
package/dist/indexer.d.cts
CHANGED
|
@@ -68,10 +68,6 @@ declare class IndexerClient {
|
|
|
68
68
|
domainProposals(d: string): Promise<unknown[]>;
|
|
69
69
|
proposal(id: string): Promise<unknown>;
|
|
70
70
|
attestations(id: string): Promise<unknown[]>;
|
|
71
|
-
registryPeers(): Promise<unknown[]>;
|
|
72
|
-
registryGateways(): Promise<unknown[]>;
|
|
73
|
-
identity(handle: string): Promise<unknown>;
|
|
74
|
-
reverseIdentity(addr: string): Promise<unknown>;
|
|
75
71
|
/**
|
|
76
72
|
* Verify a tx is included in a block by folding its merkle branch to the root
|
|
77
73
|
* with csd-codec.verifyMerkleProof. If `headerMerkleAt` was provided, the
|
package/dist/indexer.d.ts
CHANGED
|
@@ -68,10 +68,6 @@ declare class IndexerClient {
|
|
|
68
68
|
domainProposals(d: string): Promise<unknown[]>;
|
|
69
69
|
proposal(id: string): Promise<unknown>;
|
|
70
70
|
attestations(id: string): Promise<unknown[]>;
|
|
71
|
-
registryPeers(): Promise<unknown[]>;
|
|
72
|
-
registryGateways(): Promise<unknown[]>;
|
|
73
|
-
identity(handle: string): Promise<unknown>;
|
|
74
|
-
reverseIdentity(addr: string): Promise<unknown>;
|
|
75
71
|
/**
|
|
76
72
|
* Verify a tx is included in a block by folding its merkle branch to the root
|
|
77
73
|
* with csd-codec.verifyMerkleProof. If `headerMerkleAt` was provided, the
|
package/dist/indexer.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -26,7 +26,7 @@ __export(react_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(react_exports);
|
|
27
27
|
|
|
28
28
|
// src/errors.ts
|
|
29
|
-
var SDK_VERSION = "0.
|
|
29
|
+
var SDK_VERSION = "0.7.0";
|
|
30
30
|
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
31
31
|
var CairnError = class extends Error {
|
|
32
32
|
/** Stable machine code for programmatic branching. */
|
package/dist/react.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CairnController
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-XOGOSGC6.js";
|
|
4
|
+
import "./chunk-4FFLCCL4.js";
|
|
5
|
+
import "./chunk-PBKDSDID.js";
|
|
6
6
|
|
|
7
7
|
// src/react.ts
|
|
8
8
|
function createCairnHooks(React, controllerOrOpts) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inversealtruism/cairn-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The Compute Substrate dApp kit: one cohesive toolkit to connect the Cairn Wallet, read the chain, the indexer and .csd names, verify self-certifying content, and resolve
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "The Compute Substrate dApp kit: one cohesive toolkit to connect the Cairn Wallet, read the chain, the indexer and .csd names, verify self-certifying content, and resolve .csd names. Composes the published csd-* primitives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -27,11 +27,6 @@
|
|
|
27
27
|
"import": "./dist/content.js",
|
|
28
28
|
"require": "./dist/content.cjs"
|
|
29
29
|
},
|
|
30
|
-
"./registry": {
|
|
31
|
-
"types": "./dist/registry.d.ts",
|
|
32
|
-
"import": "./dist/registry.js",
|
|
33
|
-
"require": "./dist/registry.cjs"
|
|
34
|
-
},
|
|
35
30
|
"./chain": {
|
|
36
31
|
"types": "./dist/chain.d.ts",
|
|
37
32
|
"import": "./dist/chain.js",
|
|
@@ -59,16 +54,17 @@
|
|
|
59
54
|
"@inversealtruism/csd-codec": "0.1.18",
|
|
60
55
|
"@inversealtruism/csd-crypto": "0.1.18",
|
|
61
56
|
"@inversealtruism/csd-light": "0.1.23",
|
|
62
|
-
"@inversealtruism/csd-registry": "0.1.20",
|
|
63
57
|
"@inversealtruism/csd-tx": "0.1.21"
|
|
64
58
|
},
|
|
65
59
|
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "2.5.15",
|
|
66
61
|
"@inversealtruism/csd-siwc": "0.1.19",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
62
|
+
"@types/node": "22.19.20",
|
|
63
|
+
"esbuild": "0.28.2",
|
|
64
|
+
"playwright-core": "1.60.0",
|
|
65
|
+
"tsup": "8.5.1",
|
|
66
|
+
"tsx": "4.22.4",
|
|
67
|
+
"typescript": "5.9.3"
|
|
72
68
|
},
|
|
73
69
|
"sideEffects": false,
|
|
74
70
|
"license": "MIT",
|
|
@@ -90,14 +86,15 @@
|
|
|
90
86
|
"blockchain"
|
|
91
87
|
],
|
|
92
88
|
"scripts": {
|
|
93
|
-
"build": "tsup src/index.ts src/connect.ts src/indexer.ts src/content.ts src/
|
|
89
|
+
"build": "tsup src/index.ts src/connect.ts src/indexer.ts src/content.ts src/chain.ts src/controller.ts src/react.ts --format esm,cjs --dts --clean",
|
|
90
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
91
|
+
"lint": "biome lint --max-diagnostics=none .",
|
|
92
|
+
"check:dashes-paths": "node scripts/check-dashes-paths.mjs",
|
|
94
93
|
"test": "node test/run.mjs",
|
|
95
|
-
"test:live": "node examples/read-only.mjs",
|
|
94
|
+
"test:live": "node examples/read-only.mjs && node test/e2e/e2e-read.mjs",
|
|
95
|
+
"test:live:wallet": "xvfb-run -a node test/e2e/e2e-wallet-connect.mjs",
|
|
96
96
|
"build:example": "node scripts/build-example.mjs",
|
|
97
97
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
98
|
-
"test:
|
|
99
|
-
"test:e2e:wallet": "xvfb-run -a node test/e2e/e2e-wallet-connect.mjs",
|
|
100
|
-
"test:e2e": "node test/e2e/e2e-read.mjs && xvfb-run -a node test/e2e/e2e-wallet-connect.mjs",
|
|
101
|
-
"test:all": "pnpm test && pnpm test:e2e"
|
|
98
|
+
"test:all": "pnpm test && pnpm test:live && pnpm test:live:wallet"
|
|
102
99
|
}
|
|
103
100
|
}
|