@inversealtruism/cairn-sdk 0.1.4 → 0.2.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 +16 -16
- package/dist/board.cjs +1 -1
- package/dist/board.d.cts +1 -1
- package/dist/board.d.ts +1 -1
- package/dist/board.js +2 -2
- package/dist/chain.d.cts +1 -1
- package/dist/chain.d.ts +1 -1
- package/dist/{chunk-OG4KA3LS.js → chunk-J5J4JEJ6.js} +1 -1
- package/dist/{chunk-RELP23CH.js → chunk-JGXD3WIC.js} +7 -2
- package/dist/{chunk-MBSPHWZG.js → chunk-PYREGAB3.js} +1 -1
- package/dist/{chunk-FSQZVNEM.js → chunk-RYZJDZLJ.js} +1 -1
- package/dist/{chunk-MVX7VQT4.js → chunk-SIUUY6FZ.js} +1 -1
- package/dist/{chunk-K7SJOW3O.js → chunk-UIEOBVFI.js} +8 -2
- package/dist/connect.cjs +14 -3
- package/dist/connect.d.cts +1 -0
- package/dist/connect.d.ts +1 -0
- package/dist/connect.js +2 -2
- package/dist/content.cjs +1 -1
- package/dist/content.d.cts +1 -1
- package/dist/content.d.ts +1 -1
- package/dist/content.js +2 -2
- package/dist/controller.cjs +14 -3
- package/dist/controller.js +3 -3
- package/dist/{http-CQsNL8w9.d.cts → http-C9C4L4hz.d.cts} +6 -0
- package/dist/{http-CQsNL8w9.d.ts → http-C9C4L4hz.d.ts} +6 -0
- package/dist/index.cjs +141 -10
- package/dist/index.d.cts +95 -11
- package/dist/index.d.ts +95 -11
- package/dist/index.js +131 -12
- package/dist/indexer.cjs +1 -1
- package/dist/indexer.d.cts +1 -1
- package/dist/indexer.d.ts +1 -1
- package/dist/indexer.js +1 -1
- package/dist/react.cjs +14 -3
- package/dist/react.js +3 -3
- package/dist/registry.d.cts +1 -1
- package/dist/registry.d.ts +1 -1
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @inversealtruism/cairn-sdk
|
|
2
2
|
|
|
3
|
-
The **Compute Substrate dApp kit
|
|
3
|
+
The **Compute Substrate dApp kit:** one cohesive toolkit for building apps on CSD. It composes everything in the Cairn ecosystem behind a single `Cairn` object:
|
|
4
4
|
|
|
5
5
|
| | |
|
|
6
6
|
|---|---|
|
|
@@ -8,7 +8,7 @@ The **Compute Substrate dApp kit** — one cohesive toolkit for building apps on
|
|
|
8
8
|
| `cairn.chain` | Node RPC + transaction builders + a verifying **light client** (re-exports the `csd-*` primitives). |
|
|
9
9
|
| `cairn.board` | The signal **board** + work graph. Reads are public; writes are wallet-signed. |
|
|
10
10
|
| `cairn.index` | The L2 **explorer/indexer**: REST + merkle proofs + live SSE/WS feeds. |
|
|
11
|
-
| `cairn.content` | **Self-certifying content
|
|
11
|
+
| `cairn.content` | **Self-certifying content:** publish via the board, fetch with client-side verification. |
|
|
12
12
|
| `cairn.registry` | L3 **peer / gateway / identity** resolution. |
|
|
13
13
|
|
|
14
14
|
```bash
|
|
@@ -26,7 +26,7 @@ const cairn = new Cairn({ network: "mainnet" }); // defaults to cairn-substrat
|
|
|
26
26
|
const top = await cairn.board.top({ domain: "csd:apps" });
|
|
27
27
|
const tip = await cairn.chain.tip();
|
|
28
28
|
|
|
29
|
-
// connect the user's wallet (browser)
|
|
29
|
+
// connect the user's wallet (browser): prompts once, then "connected"
|
|
30
30
|
await cairn.connect();
|
|
31
31
|
|
|
32
32
|
// publish a board item, signed by the user's wallet (clear-signed approval)
|
|
@@ -42,17 +42,17 @@ cairn.index.streamAll({ onProposal: (e) => console.log("new proposal", e) });
|
|
|
42
42
|
|
|
43
43
|
## How wallet connection works (and why it's safe)
|
|
44
44
|
|
|
45
|
-
The SDK follows the exact model MetaMask uses
|
|
45
|
+
The SDK follows the exact model MetaMask uses, there is **no allowlist you maintain**:
|
|
46
46
|
|
|
47
47
|
- **`connect()` / `getAddress()`** grant *address visibility*. The first time a site connects, the user approves once; after that the wallet answers silently (the site shows up under **Settings → Connected sites**, revocable anytime). This is the only "silent" call.
|
|
48
|
-
- **Every signing / fund-moving call
|
|
48
|
+
- **Every signing / fund-moving call:** `send`, `propose`, `attest`, `signIn`, `sealClaim`, `revealClaim`, **always** opens the wallet's clear-signing approval window, **every time**, no matter what. Being "connected" never pre-approves a signature. A connected site cannot move a satoshi without an explicit, fully-disclosed approval click.
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
import { connect, UserRejectedError, NotInstalledError } from "@inversealtruism/cairn-sdk";
|
|
52
52
|
|
|
53
53
|
try {
|
|
54
54
|
const { wallet, address } = await connect();
|
|
55
|
-
await wallet.send({ to: "0x…", amount: 100_000_000 }); // 1 CSD
|
|
55
|
+
await wallet.send({ to: "0x…", amount: 100_000_000 }); // 1 CSD, still prompts
|
|
56
56
|
} catch (e) {
|
|
57
57
|
if (e instanceof NotInstalledError) { /* tell the user to install the wallet */ }
|
|
58
58
|
if (e instanceof UserRejectedError) { /* they declined */ }
|
|
@@ -61,29 +61,29 @@ try {
|
|
|
61
61
|
|
|
62
62
|
## API by namespace
|
|
63
63
|
|
|
64
|
-
**`cairn.board
|
|
64
|
+
**`cairn.board`:** `top()/board({domain,window})`, `item(id)`, `domains()`, `quests()/quest(id)`, `profile(addr)`, `leaderboard()`, `network()/networkSeries()/miner(addr)`, `activity()`, `wall()`; writes `propose({domain,title,body,links?,fee?})`, `support(id,{score?,confidence?,fee?})`.
|
|
65
65
|
|
|
66
|
-
**`cairn.index
|
|
66
|
+
**`cairn.index`:** `tipHeight()`, `block()/blockTxids()`, `tx()/txStatus()/txMerkleProof()`, `address()/addressTxs()/addressUtxo()`, `proposal()/attestations()`, `reputation()`, `registryPeers()/registryGateways()/identity()`, **`verifyInclusion(txid)`** (trust-minimized), `streamAll()/streamBlocks()/streamDomain()` (SSE), `subscribe()` (WS).
|
|
67
67
|
|
|
68
|
-
**`cairn.content
|
|
68
|
+
**`cairn.content`:** `prepare(obj)`/`put(obj)` → `{ payloadHash, canonical, bytes }`; `get(hash)` / `getBytes(hash)` (fetch **and verify** `sha256(bytes) === hash`, throws `ContentVerificationError` on tamper); `hash(obj)`.
|
|
69
69
|
|
|
70
|
-
**`cairn.chain
|
|
70
|
+
**`cairn.chain`:** `tip()`, `utxos(addr)`, `submit(nodeJsonTx)`, `.client` (full `CsdClient`), `.light()` (verifying light client). The package also re-exports the primitives under the `/chain` subpath: `buildSend/buildPropose/buildAttest`, `signTx`, `keygen`, `payloadHash`, `verifyMerkleProof`, `LightClient`, etc.
|
|
71
71
|
|
|
72
|
-
**`cairn.registry
|
|
72
|
+
**`cairn.registry`:** `gateways()`, `peers()`, `resolveName(handle)`, `reverseName(addr)`, `.fromRecords` (deterministic local resolvers).
|
|
73
73
|
|
|
74
74
|
Subpath imports are available for tree-shaking: `@inversealtruism/cairn-sdk/{connect,board,indexer,content,registry,chain}`.
|
|
75
75
|
|
|
76
76
|
## Examples
|
|
77
77
|
|
|
78
|
-
- **`examples/read-only.mjs
|
|
79
|
-
- **`examples/hello-csd
|
|
78
|
+
- **`examples/read-only.mjs`:** runs today against live mainnet, no wallet, no build: `npm run test:live`. Demonstrates chain/board/indexer/registry reads + verified merkle inclusion + verified content fetch.
|
|
79
|
+
- **`examples/hello-csd/`:** a no-framework browser dApp (connect → read board → publish → live feed). Build the bundle with `npm run build:example`, then serve the folder from **localhost** (the wallet injects there) with the Cairn Wallet installed.
|
|
80
80
|
|
|
81
81
|
## Trust model & honest limits
|
|
82
82
|
|
|
83
|
-
- **Content is always verified client-side.** `cairn.content.get()` rejects bytes that don't hash to the requested `payloadHash
|
|
84
|
-
- **Merkle inclusion is trust-minimized
|
|
83
|
+
- **Content is always verified client-side.** `cairn.content.get()` rejects bytes that don't hash to the requested `payloadHash`, an untrusted gateway can't serve tampered content.
|
|
84
|
+
- **Merkle inclusion is trust-minimized, to the strength of your header source.** `verifyInclusion()` folds the proof and, when a header-merkle source is wired, cross-checks the root against it → `trustLevel: "verified-inclusion"`; otherwise `"proof-consistent"` (indexer trusted). That cross-check only means something against an *independent* header, so the default `Cairn` wiring enables it ONLY when your node RPC is a different origin than the indexer (the default same-origin proxy stays at `"proof-consistent"`, a single compromised server can't be cross-checked against itself). For full trust-minimization against a lying node too, supply a PoW-verifying `headerMerkleAt` (e.g. backed by `cairn.chain.light()`).
|
|
85
85
|
- **Balances are RPC-trusted.** Headers don't commit to the UTXO set; balance reads trust the node/proxy (same as every light client).
|
|
86
|
-
- **Indexer/swarm run behind the cairn proxy.** By default `cairn.index` and content resolution use the cairn server's hardened, read-only, rate-limited `/explorer/api` reverse proxy (no separate public indexer needed). **SSE works through it; `subscribe()` (WebSocket) needs a direct indexer endpoint
|
|
86
|
+
- **Indexer/swarm run behind the cairn proxy.** By default `cairn.index` and content resolution use the cairn server's hardened, read-only, rate-limited `/explorer/api` reverse proxy (no separate public indexer needed). **SSE works through it; `subscribe()` (WebSocket) needs a direct indexer endpoint:** set `baseUrls.indexer` to a private/localhost indexer for WS.
|
|
87
87
|
- **Today the wallet injects only on `cairn-substrate.com` + localhost.** Connecting from an arbitrary third-party origin requires the wallet's "connect anywhere" release (broadened injection), which ships after the per-origin consent layer is proven.
|
|
88
88
|
|
|
89
89
|
## Configuration
|
package/dist/board.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var import_csd_codec = require("@inversealtruism/csd-codec");
|
|
|
27
27
|
var import_csd_codec2 = require("@inversealtruism/csd-codec");
|
|
28
28
|
|
|
29
29
|
// src/errors.ts
|
|
30
|
-
var SDK_VERSION = "0.
|
|
30
|
+
var SDK_VERSION = "0.2.0";
|
|
31
31
|
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
32
32
|
var CairnError = class extends Error {
|
|
33
33
|
/** Stable machine code for programmatic branching. */
|
package/dist/board.d.cts
CHANGED
package/dist/board.d.ts
CHANGED
package/dist/board.js
CHANGED
package/dist/chain.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ export { App, BlockHeader, Tx, TxInput, TxOutput, canonicalJson, deserialize, hb
|
|
|
7
7
|
export { ADDR_RE, addrFromPriv, addrFromPub, hash160, isValidAddr, isValidPriv, keygen, pubFromPriv, randomNonce, signDigest, verifyDigest } from '@inversealtruism/csd-crypto';
|
|
8
8
|
import { LightClient } from '@inversealtruism/csd-light';
|
|
9
9
|
export { InclusionResult, LightClient, ReorgResult, TrustLevel, VerifiedHeader, expectedBits, expectedBitsFromWindow } from '@inversealtruism/csd-light';
|
|
10
|
-
import { F as FetchLike } from './http-
|
|
10
|
+
import { F as FetchLike } from './http-C9C4L4hz.cjs';
|
|
11
11
|
|
|
12
12
|
interface ChainOptions {
|
|
13
13
|
/** Node RPC base URL — defaults to the public Cairn proxy (no local node needed). */
|
package/dist/chain.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { App, BlockHeader, Tx, TxInput, TxOutput, canonicalJson, deserialize, hb
|
|
|
7
7
|
export { ADDR_RE, addrFromPriv, addrFromPub, hash160, isValidAddr, isValidPriv, keygen, pubFromPriv, randomNonce, signDigest, verifyDigest } from '@inversealtruism/csd-crypto';
|
|
8
8
|
import { LightClient } from '@inversealtruism/csd-light';
|
|
9
9
|
export { InclusionResult, LightClient, ReorgResult, TrustLevel, VerifiedHeader, expectedBits, expectedBitsFromWindow } from '@inversealtruism/csd-light';
|
|
10
|
-
import { F as FetchLike } from './http-
|
|
10
|
+
import { F as FetchLike } from './http-C9C4L4hz.js';
|
|
11
11
|
|
|
12
12
|
interface ChainOptions {
|
|
13
13
|
/** Node RPC base URL — defaults to the public Cairn proxy (no local node needed). */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
-
var SDK_VERSION = "0.
|
|
2
|
+
var SDK_VERSION = "0.2.0";
|
|
3
3
|
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
4
4
|
var CairnError = class extends Error {
|
|
5
5
|
/** Stable machine code for programmatic branching. */
|
|
@@ -74,7 +74,12 @@ var ContentVerificationError = class extends CairnError {
|
|
|
74
74
|
this.expected = expected;
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
var NATIVE_CODES = /* @__PURE__ */ new Set(["ACCOUNT_CHANGED", "FIRST_PARTY_ONLY", "RATE_LIMITED", "APPROVAL_CLOSED", "FORBIDDEN", "INTERNAL"]);
|
|
78
|
+
function mapProviderError(error, code) {
|
|
79
|
+
if (code === "USER_REJECTED" || code === "APPROVAL_CLOSED") return new UserRejectedError(error);
|
|
80
|
+
if (code === "WALLET_LOCKED") return new WalletLockedError(error);
|
|
81
|
+
if (code === "UNSUPPORTED_METHOD" || code === "UNKNOWN_KIND") return new UnsupportedMethodError(error);
|
|
82
|
+
if (code && NATIVE_CODES.has(code)) return new CairnError(error || code, { code });
|
|
78
83
|
const e = String(error || "").toLowerCase();
|
|
79
84
|
if (e.includes("rejected by user")) return new UserRejectedError(error);
|
|
80
85
|
if (e.includes("wallet locked")) return new WalletLockedError(error);
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
NotInstalledError,
|
|
3
3
|
UnsupportedMethodError,
|
|
4
4
|
mapProviderError
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-JGXD3WIC.js";
|
|
6
6
|
|
|
7
7
|
// src/connect.ts
|
|
8
8
|
function discoverProviders(opts = {}) {
|
|
@@ -72,7 +72,7 @@ function isInstalled() {
|
|
|
72
72
|
}
|
|
73
73
|
function unwrap(reply) {
|
|
74
74
|
if (reply && reply.ok) return reply.result;
|
|
75
|
-
throw mapProviderError(reply?.error ?? "Unknown wallet error");
|
|
75
|
+
throw mapProviderError(reply?.error ?? "Unknown wallet error", reply?.code);
|
|
76
76
|
}
|
|
77
77
|
var WalletConnection = class {
|
|
78
78
|
provider;
|
|
@@ -106,6 +106,9 @@ var WalletConnection = class {
|
|
|
106
106
|
* Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx).
|
|
107
107
|
*/
|
|
108
108
|
signIn() {
|
|
109
|
+
if (typeof this.provider.signIn !== "function") {
|
|
110
|
+
return Promise.reject(new UnsupportedMethodError("this wallet does not expose signIn()"));
|
|
111
|
+
}
|
|
109
112
|
return Promise.resolve(this.provider.signIn()).then(unwrap);
|
|
110
113
|
}
|
|
111
114
|
/**
|
|
@@ -139,6 +142,9 @@ var WalletConnection = class {
|
|
|
139
142
|
}
|
|
140
143
|
/** Atomic fill (CairnX DvP): pay + attest in ONE tx. Always prompts with clear-signing. */
|
|
141
144
|
fillOffer(params) {
|
|
145
|
+
if (typeof this.provider.fillOffer !== "function") {
|
|
146
|
+
return Promise.reject(new UnsupportedMethodError("this wallet predates fillOffer() \u2014 ask the user to update the Cairn Wallet"));
|
|
147
|
+
}
|
|
142
148
|
return Promise.resolve(this.provider.fillOffer(params)).then(unwrap);
|
|
143
149
|
}
|
|
144
150
|
/** This origin's current permission grant (EIP-2255-style). Silent; [] if none / unsupported. */
|
package/dist/connect.cjs
CHANGED
|
@@ -30,7 +30,7 @@ __export(connect_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(connect_exports);
|
|
31
31
|
|
|
32
32
|
// src/errors.ts
|
|
33
|
-
var SDK_VERSION = "0.
|
|
33
|
+
var SDK_VERSION = "0.2.0";
|
|
34
34
|
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
35
35
|
var CairnError = class extends Error {
|
|
36
36
|
/** Stable machine code for programmatic branching. */
|
|
@@ -87,7 +87,12 @@ var UnsupportedMethodError = class extends CairnError {
|
|
|
87
87
|
super(message, { code: "UNSUPPORTED_METHOD", docsPath: "/errors#unsupported-method" });
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
|
|
90
|
+
var NATIVE_CODES = /* @__PURE__ */ new Set(["ACCOUNT_CHANGED", "FIRST_PARTY_ONLY", "RATE_LIMITED", "APPROVAL_CLOSED", "FORBIDDEN", "INTERNAL"]);
|
|
91
|
+
function mapProviderError(error, code) {
|
|
92
|
+
if (code === "USER_REJECTED" || code === "APPROVAL_CLOSED") return new UserRejectedError(error);
|
|
93
|
+
if (code === "WALLET_LOCKED") return new WalletLockedError(error);
|
|
94
|
+
if (code === "UNSUPPORTED_METHOD" || code === "UNKNOWN_KIND") return new UnsupportedMethodError(error);
|
|
95
|
+
if (code && NATIVE_CODES.has(code)) return new CairnError(error || code, { code });
|
|
91
96
|
const e = String(error || "").toLowerCase();
|
|
92
97
|
if (e.includes("rejected by user")) return new UserRejectedError(error);
|
|
93
98
|
if (e.includes("wallet locked")) return new WalletLockedError(error);
|
|
@@ -163,7 +168,7 @@ function isInstalled() {
|
|
|
163
168
|
}
|
|
164
169
|
function unwrap(reply) {
|
|
165
170
|
if (reply && reply.ok) return reply.result;
|
|
166
|
-
throw mapProviderError(reply?.error ?? "Unknown wallet error");
|
|
171
|
+
throw mapProviderError(reply?.error ?? "Unknown wallet error", reply?.code);
|
|
167
172
|
}
|
|
168
173
|
var WalletConnection = class {
|
|
169
174
|
provider;
|
|
@@ -197,6 +202,9 @@ var WalletConnection = class {
|
|
|
197
202
|
* Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx).
|
|
198
203
|
*/
|
|
199
204
|
signIn() {
|
|
205
|
+
if (typeof this.provider.signIn !== "function") {
|
|
206
|
+
return Promise.reject(new UnsupportedMethodError("this wallet does not expose signIn()"));
|
|
207
|
+
}
|
|
200
208
|
return Promise.resolve(this.provider.signIn()).then(unwrap);
|
|
201
209
|
}
|
|
202
210
|
/**
|
|
@@ -230,6 +238,9 @@ var WalletConnection = class {
|
|
|
230
238
|
}
|
|
231
239
|
/** Atomic fill (CairnX DvP): pay + attest in ONE tx. Always prompts with clear-signing. */
|
|
232
240
|
fillOffer(params) {
|
|
241
|
+
if (typeof this.provider.fillOffer !== "function") {
|
|
242
|
+
return Promise.reject(new UnsupportedMethodError("this wallet predates fillOffer() \u2014 ask the user to update the Cairn Wallet"));
|
|
243
|
+
}
|
|
233
244
|
return Promise.resolve(this.provider.fillOffer(params)).then(unwrap);
|
|
234
245
|
}
|
|
235
246
|
/** This origin's current permission grant (EIP-2255-style). Silent; [] if none / unsupported. */
|
package/dist/connect.d.cts
CHANGED
package/dist/connect.d.ts
CHANGED
package/dist/connect.js
CHANGED
package/dist/content.cjs
CHANGED
|
@@ -26,7 +26,7 @@ module.exports = __toCommonJS(content_exports);
|
|
|
26
26
|
var import_csd_codec = require("@inversealtruism/csd-codec");
|
|
27
27
|
|
|
28
28
|
// src/errors.ts
|
|
29
|
-
var SDK_VERSION = "0.
|
|
29
|
+
var SDK_VERSION = "0.2.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/content.d.cts
CHANGED
package/dist/content.d.ts
CHANGED
package/dist/content.js
CHANGED
package/dist/controller.cjs
CHANGED
|
@@ -25,7 +25,7 @@ __export(controller_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(controller_exports);
|
|
26
26
|
|
|
27
27
|
// src/errors.ts
|
|
28
|
-
var SDK_VERSION = "0.
|
|
28
|
+
var SDK_VERSION = "0.2.0";
|
|
29
29
|
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
30
30
|
var CairnError = class extends Error {
|
|
31
31
|
/** Stable machine code for programmatic branching. */
|
|
@@ -82,7 +82,12 @@ var UnsupportedMethodError = class extends CairnError {
|
|
|
82
82
|
super(message, { code: "UNSUPPORTED_METHOD", docsPath: "/errors#unsupported-method" });
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
var NATIVE_CODES = /* @__PURE__ */ new Set(["ACCOUNT_CHANGED", "FIRST_PARTY_ONLY", "RATE_LIMITED", "APPROVAL_CLOSED", "FORBIDDEN", "INTERNAL"]);
|
|
86
|
+
function mapProviderError(error, code) {
|
|
87
|
+
if (code === "USER_REJECTED" || code === "APPROVAL_CLOSED") return new UserRejectedError(error);
|
|
88
|
+
if (code === "WALLET_LOCKED") return new WalletLockedError(error);
|
|
89
|
+
if (code === "UNSUPPORTED_METHOD" || code === "UNKNOWN_KIND") return new UnsupportedMethodError(error);
|
|
90
|
+
if (code && NATIVE_CODES.has(code)) return new CairnError(error || code, { code });
|
|
86
91
|
const e = String(error || "").toLowerCase();
|
|
87
92
|
if (e.includes("rejected by user")) return new UserRejectedError(error);
|
|
88
93
|
if (e.includes("wallet locked")) return new WalletLockedError(error);
|
|
@@ -135,7 +140,7 @@ function detectProvider(opts = {}) {
|
|
|
135
140
|
}
|
|
136
141
|
function unwrap(reply) {
|
|
137
142
|
if (reply && reply.ok) return reply.result;
|
|
138
|
-
throw mapProviderError(reply?.error ?? "Unknown wallet error");
|
|
143
|
+
throw mapProviderError(reply?.error ?? "Unknown wallet error", reply?.code);
|
|
139
144
|
}
|
|
140
145
|
var WalletConnection = class {
|
|
141
146
|
provider;
|
|
@@ -169,6 +174,9 @@ var WalletConnection = class {
|
|
|
169
174
|
* Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx).
|
|
170
175
|
*/
|
|
171
176
|
signIn() {
|
|
177
|
+
if (typeof this.provider.signIn !== "function") {
|
|
178
|
+
return Promise.reject(new UnsupportedMethodError("this wallet does not expose signIn()"));
|
|
179
|
+
}
|
|
172
180
|
return Promise.resolve(this.provider.signIn()).then(unwrap);
|
|
173
181
|
}
|
|
174
182
|
/**
|
|
@@ -202,6 +210,9 @@ var WalletConnection = class {
|
|
|
202
210
|
}
|
|
203
211
|
/** Atomic fill (CairnX DvP): pay + attest in ONE tx. Always prompts with clear-signing. */
|
|
204
212
|
fillOffer(params) {
|
|
213
|
+
if (typeof this.provider.fillOffer !== "function") {
|
|
214
|
+
return Promise.reject(new UnsupportedMethodError("this wallet predates fillOffer() \u2014 ask the user to update the Cairn Wallet"));
|
|
215
|
+
}
|
|
205
216
|
return Promise.resolve(this.provider.fillOffer(params)).then(unwrap);
|
|
206
217
|
}
|
|
207
218
|
/** This origin's current permission grant (EIP-2255-style). Silent; [] if none / unsupported. */
|
package/dist/controller.js
CHANGED
|
@@ -12,6 +12,10 @@ interface HttpOptions {
|
|
|
12
12
|
maxBytes?: number;
|
|
13
13
|
/** Extra headers sent on every request. */
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
|
+
/** Opt-in retry budget for IDEMPOTENT GETs only (default 0 = today's behavior). Retries fire on
|
|
16
|
+
* network errors/timeouts and 5xx, never on 4xx (mirrors csd-client's posture), with full-jitter
|
|
17
|
+
* backoff. POSTs are never retried (they may not be idempotent). */
|
|
18
|
+
retries?: number;
|
|
15
19
|
}
|
|
16
20
|
declare class Http {
|
|
17
21
|
readonly baseUrl: string;
|
|
@@ -19,10 +23,12 @@ declare class Http {
|
|
|
19
23
|
private readonly timeoutMs;
|
|
20
24
|
private readonly maxBytes;
|
|
21
25
|
private readonly headers;
|
|
26
|
+
private readonly retries;
|
|
22
27
|
constructor(opts: HttpOptions);
|
|
23
28
|
/** Build an absolute URL from a path + optional query params. */
|
|
24
29
|
url(path: string, query?: Record<string, string | number | boolean | undefined>): string;
|
|
25
30
|
private raw;
|
|
31
|
+
private parseJson;
|
|
26
32
|
getJson<T = unknown>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
27
33
|
postJson<T = unknown>(path: string, body: unknown, headers?: Record<string, string>): Promise<T>;
|
|
28
34
|
/** GET raw bytes (for content retrieval). Returns null on 404. */
|
|
@@ -12,6 +12,10 @@ interface HttpOptions {
|
|
|
12
12
|
maxBytes?: number;
|
|
13
13
|
/** Extra headers sent on every request. */
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
|
+
/** Opt-in retry budget for IDEMPOTENT GETs only (default 0 = today's behavior). Retries fire on
|
|
16
|
+
* network errors/timeouts and 5xx, never on 4xx (mirrors csd-client's posture), with full-jitter
|
|
17
|
+
* backoff. POSTs are never retried (they may not be idempotent). */
|
|
18
|
+
retries?: number;
|
|
15
19
|
}
|
|
16
20
|
declare class Http {
|
|
17
21
|
readonly baseUrl: string;
|
|
@@ -19,10 +23,12 @@ declare class Http {
|
|
|
19
23
|
private readonly timeoutMs;
|
|
20
24
|
private readonly maxBytes;
|
|
21
25
|
private readonly headers;
|
|
26
|
+
private readonly retries;
|
|
22
27
|
constructor(opts: HttpOptions);
|
|
23
28
|
/** Build an absolute URL from a path + optional query params. */
|
|
24
29
|
url(path: string, query?: Record<string, string | number | boolean | undefined>): string;
|
|
25
30
|
private raw;
|
|
31
|
+
private parseJson;
|
|
26
32
|
getJson<T = unknown>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
27
33
|
postJson<T = unknown>(path: string, body: unknown, headers?: Record<string, string>): Promise<T>;
|
|
28
34
|
/** GET raw bytes (for content retrieval). Returns null on 404. */
|