@inversealtruism/cairn-sdk 0.1.2 → 0.1.4
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/board.cjs +33 -2
- package/dist/board.d.cts +1 -1
- package/dist/board.d.ts +1 -1
- package/dist/board.js +2 -2
- package/dist/chain.cjs +29 -0
- package/dist/chain.d.cts +24 -3
- package/dist/chain.d.ts +24 -3
- package/dist/chain.js +5 -1
- package/dist/{chunk-G7FABIF4.js → chunk-BGJZF7S2.js} +11 -2
- package/dist/{chunk-6VWLWF7R.js → chunk-C452UODV.js} +31 -2
- package/dist/{chunk-OGP2W7DL.js → chunk-FSQZVNEM.js} +1 -1
- package/dist/chunk-K7SJOW3O.js +213 -0
- package/dist/chunk-MBSPHWZG.js +96 -0
- package/dist/{chunk-BZVJVL4Q.js → chunk-MVX7VQT4.js} +4 -3
- package/dist/{chunk-FNBE2FPE.js → chunk-OG4KA3LS.js} +49 -17
- package/dist/chunk-RELP23CH.js +99 -0
- package/dist/connect.cjs +145 -18
- package/dist/connect.d.cts +140 -2
- package/dist/connect.d.ts +140 -2
- package/dist/connect.js +4 -2
- package/dist/content.cjs +37 -5
- package/dist/content.d.cts +1 -1
- package/dist/content.d.ts +1 -1
- package/dist/content.js +2 -2
- package/dist/controller.cjs +355 -0
- package/dist/controller.d.cts +37 -0
- package/dist/controller.d.ts +37 -0
- package/dist/controller.js +8 -0
- package/dist/{http-D2CzfOsm.d.cts → http-CQsNL8w9.d.cts} +5 -0
- package/dist/{http-D2CzfOsm.d.ts → http-CQsNL8w9.d.ts} +5 -0
- package/dist/index.cjs +386 -48
- package/dist/index.d.cts +39 -6
- package/dist/index.d.ts +39 -6
- package/dist/index.js +75 -20
- package/dist/indexer.cjs +49 -17
- package/dist/indexer.d.cts +15 -4
- package/dist/indexer.d.ts +15 -4
- package/dist/indexer.js +1 -1
- package/dist/react.cjs +371 -0
- package/dist/react.d.cts +30 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.js +23 -0
- package/dist/registry.cjs +11 -2
- package/dist/registry.d.cts +12 -3
- package/dist/registry.d.ts +12 -3
- package/dist/registry.js +1 -1
- package/package.json +21 -10
- package/dist/chunk-PHMU3CG5.js +0 -63
- package/dist/chunk-SMAPCKVG.js +0 -118
package/dist/connect.d.cts
CHANGED
|
@@ -49,18 +49,94 @@ interface SealClaimParams {
|
|
|
49
49
|
claim: string;
|
|
50
50
|
fee?: number;
|
|
51
51
|
}
|
|
52
|
+
/** Atomic fill (CairnX delivery-vs-payment): an Attest + payment outputs in ONE tx. */
|
|
53
|
+
interface FillParams {
|
|
54
|
+
proposalId: string;
|
|
55
|
+
outputs: {
|
|
56
|
+
to: string;
|
|
57
|
+
value: number;
|
|
58
|
+
}[];
|
|
59
|
+
score?: number;
|
|
60
|
+
confidence?: number;
|
|
61
|
+
fee?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Audience-bound "Sign in with CSD" (SIWC) params — the secure third-party login. The wallet binds
|
|
65
|
+
* the REAL requesting origin as the message `domain` (from the unforgeable sender.origin, NEVER this
|
|
66
|
+
* field) plus your server `nonce`, chain id, and a validity window, and returns only the signed
|
|
67
|
+
* artifact. The relying party MUST verify it server-side (see below).
|
|
68
|
+
*/
|
|
69
|
+
interface SiwcParams {
|
|
70
|
+
/** Server-issued, single-use, >=8 alphanumeric (use `generateNonce()` from @inversealtruism/csd-siwc). */
|
|
71
|
+
nonce: string;
|
|
72
|
+
/** Optional one-line human statement shown in the wallet (no newline). */
|
|
73
|
+
statement?: string;
|
|
74
|
+
/** Subject URI; defaults to the origin root. If given, MUST be on the requesting site. */
|
|
75
|
+
uri?: string;
|
|
76
|
+
/** Validity window in seconds (wallet clamps 60..3600, default 600). */
|
|
77
|
+
expirationSecs?: number;
|
|
78
|
+
notBeforeSecs?: number;
|
|
79
|
+
requestId?: string;
|
|
80
|
+
resources?: string[];
|
|
81
|
+
/** Optional cross-check only — if set it MUST equal the requesting origin's host, else refused. */
|
|
82
|
+
domain?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* SIWC result — the signed artifact. VERIFY SERVER-SIDE with `verifySiwc` from
|
|
86
|
+
* `@inversealtruism/csd-siwc` (check domain==your-origin, nonce==your-issued-single-use-nonce,
|
|
87
|
+
* chainId, time window, signature, hash160(pub33)==account), THEN issue your OWN session. The
|
|
88
|
+
* signature is proof-of-control, NEVER a bearer token.
|
|
89
|
+
*/
|
|
90
|
+
interface SiwcResult {
|
|
91
|
+
account: string;
|
|
92
|
+
pub33: string;
|
|
93
|
+
sig64: string;
|
|
94
|
+
/** The exact canonical SIWC message that was signed (verify the signature over this). */
|
|
95
|
+
message: string;
|
|
96
|
+
/** CAIP-2 chain id the sign-in is bound to. */
|
|
97
|
+
chainId: string;
|
|
98
|
+
}
|
|
99
|
+
/** Wallet feature/capability descriptor (feature-detection; older wallets may not expose it). */
|
|
100
|
+
interface WalletCapabilities {
|
|
101
|
+
version: string;
|
|
102
|
+
/** SIWC byte-contract version, e.g. "1", when audience-bound sign-in is supported. */
|
|
103
|
+
siwc?: string;
|
|
104
|
+
methods?: string[];
|
|
105
|
+
[k: string]: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** An EIP-2255-style per-origin permission grant. */
|
|
108
|
+
interface WalletPermission {
|
|
109
|
+
invoker: string;
|
|
110
|
+
accounts: string[];
|
|
111
|
+
grantedAt: number;
|
|
112
|
+
}
|
|
52
113
|
/** The raw provider object the extension injects at `window.cairn`. */
|
|
53
114
|
interface CairnProvider {
|
|
54
115
|
isCairn: true;
|
|
55
116
|
version: string;
|
|
56
117
|
connect(): Promise<ProviderReply<ConnectResult>>;
|
|
57
118
|
getAddress(): Promise<ProviderReply<ConnectResult>>;
|
|
119
|
+
/** @deprecated First-party-only legacy login. Third parties MUST use `signInWithCsd`. */
|
|
58
120
|
signIn(): Promise<ProviderReply<SignInResult>>;
|
|
121
|
+
/** Audience-bound "Sign in with CSD" — the secure third-party login. */
|
|
122
|
+
signInWithCsd(p: SiwcParams): Promise<ProviderReply<SiwcResult>>;
|
|
59
123
|
propose(p: ProposeParams): Promise<ProviderReply<TxResult>>;
|
|
60
124
|
attest(p: AttestParams): Promise<ProviderReply<TxResult>>;
|
|
61
125
|
send(p: SendParams): Promise<ProviderReply<TxResult>>;
|
|
126
|
+
fillOffer(p: FillParams): Promise<ProviderReply<TxResult>>;
|
|
62
127
|
sealClaim(p: SealClaimParams): Promise<ProviderReply<TxResult>>;
|
|
63
128
|
revealClaim(txid: string): Promise<ProviderReply<TxResult>>;
|
|
129
|
+
/** Feature/capability detection (optional; absent on older wallets). */
|
|
130
|
+
getCapabilities?(): Promise<WalletCapabilities>;
|
|
131
|
+
/** EIP-2255-style per-origin permissions (optional; absent on older wallets). */
|
|
132
|
+
getPermissions?(): Promise<ProviderReply<WalletPermission[]>>;
|
|
133
|
+
requestPermissions?(): Promise<ProviderReply<WalletPermission[]>>;
|
|
134
|
+
revokePermissions?(): Promise<ProviderReply<{
|
|
135
|
+
revoked: boolean;
|
|
136
|
+
}>>;
|
|
137
|
+
/** Event subscription (accountsChanged / disconnect) (optional; absent on older wallets). */
|
|
138
|
+
on?(event: string, handler: (data: unknown) => void): void;
|
|
139
|
+
removeListener?(event: string, handler: (data: unknown) => void): void;
|
|
64
140
|
}
|
|
65
141
|
/** Every provider call resolves to this discriminated reply (never rejects). */
|
|
66
142
|
type ProviderReply<T> = {
|
|
@@ -84,12 +160,40 @@ interface DetectOptions {
|
|
|
84
160
|
* content script hasn't injected yet. Throws `NotInstalledError` on timeout or
|
|
85
161
|
* outside a browser.
|
|
86
162
|
*/
|
|
163
|
+
/** EIP-6963-style announced wallet info (Cairn's own `csd:` discovery namespace). */
|
|
164
|
+
interface ProviderInfo {
|
|
165
|
+
uuid: string;
|
|
166
|
+
name: string;
|
|
167
|
+
icon: string;
|
|
168
|
+
rdns: string;
|
|
169
|
+
}
|
|
170
|
+
/** A discovered provider + its display info. */
|
|
171
|
+
interface ProviderDetail {
|
|
172
|
+
info: ProviderInfo;
|
|
173
|
+
provider: CairnProvider;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Enumerate all wallets that announce via the `csd:` discovery handshake (EIP-6963 analog) — for a
|
|
177
|
+
* multi-wallet picker. Resolves with everything announced within `timeoutMs` (default 1000ms).
|
|
178
|
+
*/
|
|
179
|
+
declare function discoverProviders(opts?: DetectOptions): Promise<ProviderDetail[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Resolve `window.cairn`, via three paths that race: an immediate global, the legacy
|
|
182
|
+
* `cairn#initialized` event, or the `csd:announceProvider` discovery handshake (we dispatch
|
|
183
|
+
* `csd:requestProvider`). Throws `NotInstalledError` on timeout or outside a browser.
|
|
184
|
+
*/
|
|
87
185
|
declare function detectProvider(opts?: DetectOptions): Promise<CairnProvider>;
|
|
88
186
|
/** True if the Cairn Wallet is already present (no waiting). */
|
|
89
187
|
declare function isInstalled(): boolean;
|
|
90
188
|
/**
|
|
91
189
|
* High-level, typed wallet handle. Construct via `connect()` or `new WalletConnection(provider)`.
|
|
92
190
|
* Methods throw `UserRejectedError` / `WalletLockedError` / `UnsupportedMethodError` on failure.
|
|
191
|
+
*
|
|
192
|
+
* Note (typed-error contract): the genuine Cairn Wallet always RESOLVES a `{ok,result|error}` reply, so a
|
|
193
|
+
* failure is mapped to a typed `CairnError` via `unwrap`. A non-conformant or SPOOFED provider that instead
|
|
194
|
+
* REJECTS its promise will surface that raw rejection un-mapped (it bypasses `unwrap`), so a dApp's
|
|
195
|
+
* `catch (e) { errorCode(e) }` may see `UNKNOWN` from such a provider. The real auth boundary is server-side
|
|
196
|
+
* SIWC verification, never a client-side error code.
|
|
93
197
|
*/
|
|
94
198
|
declare class WalletConnection {
|
|
95
199
|
readonly provider: CairnProvider;
|
|
@@ -103,8 +207,42 @@ declare class WalletConnection {
|
|
|
103
207
|
connect(): Promise<string>;
|
|
104
208
|
/** Get the connected address (does not force a new connection prompt if already consented). */
|
|
105
209
|
getAddress(): Promise<string>;
|
|
106
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated First-party-only legacy login (it authenticates against the wallet's own configured
|
|
212
|
+
* server and is rejected from third-party origins). Use {@link signInWithCsd} for any site.
|
|
213
|
+
* Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx).
|
|
214
|
+
*/
|
|
107
215
|
signIn(): Promise<SignInResult>;
|
|
216
|
+
/**
|
|
217
|
+
* Audience-bound "Sign in with CSD" (SIWC) — the secure, replay-resistant third-party login.
|
|
218
|
+
* The wallet binds the REAL requesting origin + your single-use server `nonce` into the signed
|
|
219
|
+
* message and returns the artifact; it never mints a session. VERIFY the result SERVER-SIDE with
|
|
220
|
+
* `verifySiwc` from `@inversealtruism/csd-siwc` (domain/nonce/chain/time/signature/account), then
|
|
221
|
+
* issue your OWN session. The signature is proof-of-control, NOT a bearer token. Always prompts.
|
|
222
|
+
*/
|
|
223
|
+
signInWithCsd(params: SiwcParams): Promise<SiwcResult>;
|
|
224
|
+
/** True if this wallet supports audience-bound SIWC (safe to call `signInWithCsd`). */
|
|
225
|
+
get supportsSiwc(): boolean;
|
|
226
|
+
/** Feature/capability detection. Returns null if the wallet predates `getCapabilities`. */
|
|
227
|
+
getCapabilities(): Promise<WalletCapabilities | null>;
|
|
228
|
+
/** Atomic fill (CairnX DvP): pay + attest in ONE tx. Always prompts with clear-signing. */
|
|
229
|
+
fillOffer(params: FillParams): Promise<TxResult>;
|
|
230
|
+
/** This origin's current permission grant (EIP-2255-style). Silent; [] if none / unsupported. */
|
|
231
|
+
getPermissions(): Promise<WalletPermission[]>;
|
|
232
|
+
/** Explicitly request permission to see the address (prompts, like connect). */
|
|
233
|
+
requestPermissions(): Promise<WalletPermission[]>;
|
|
234
|
+
/** Revoke THIS origin's own access (silent). Returns { revoked }. Safe no-op on older wallets. */
|
|
235
|
+
revokePermissions(): Promise<{
|
|
236
|
+
revoked: boolean;
|
|
237
|
+
}>;
|
|
238
|
+
/**
|
|
239
|
+
* Subscribe to provider events. `accountsChanged` fires with `[]` when this site loses access
|
|
240
|
+
* (wallet lock / account switch / revoke) — re-call connect() to (re)share; `disconnect` likewise.
|
|
241
|
+
* No-op if the wallet predates events. Use the SAME handler reference with off() to unsubscribe.
|
|
242
|
+
*/
|
|
243
|
+
on(event: "accountsChanged" | "disconnect" | (string & {}), handler: (data: any) => void): void;
|
|
244
|
+
/** Remove a previously-added event handler (must be the same reference passed to on()). */
|
|
245
|
+
off(event: string, handler: (data: any) => void): void;
|
|
108
246
|
/** Send CSD (always prompts with clear-signing; wallet picks inputs + returns change to itself). */
|
|
109
247
|
send(params: SendParams): Promise<TxResult>;
|
|
110
248
|
/** Low-level Propose (always prompts). Prefer `cairn.board.propose()` which computes the hash/uri/expiry. */
|
|
@@ -124,4 +262,4 @@ declare function connect(opts?: DetectOptions): Promise<{
|
|
|
124
262
|
address: string;
|
|
125
263
|
}>;
|
|
126
264
|
|
|
127
|
-
export { type AttestParams, type CairnProvider, type ConnectResult, type DetectOptions, type ProposeParams, type ProviderReply, type SealClaimParams, type SendParams, type SignInResult, type TxResult, WalletConnection, connect, detectProvider, getWallet, isInstalled };
|
|
265
|
+
export { type AttestParams, type CairnProvider, type ConnectResult, type DetectOptions, type FillParams, type ProposeParams, type ProviderDetail, type ProviderInfo, type ProviderReply, type SealClaimParams, type SendParams, type SignInResult, type SiwcParams, type SiwcResult, type TxResult, type WalletCapabilities, WalletConnection, type WalletPermission, connect, detectProvider, discoverProviders, getWallet, isInstalled };
|
package/dist/connect.d.ts
CHANGED
|
@@ -49,18 +49,94 @@ interface SealClaimParams {
|
|
|
49
49
|
claim: string;
|
|
50
50
|
fee?: number;
|
|
51
51
|
}
|
|
52
|
+
/** Atomic fill (CairnX delivery-vs-payment): an Attest + payment outputs in ONE tx. */
|
|
53
|
+
interface FillParams {
|
|
54
|
+
proposalId: string;
|
|
55
|
+
outputs: {
|
|
56
|
+
to: string;
|
|
57
|
+
value: number;
|
|
58
|
+
}[];
|
|
59
|
+
score?: number;
|
|
60
|
+
confidence?: number;
|
|
61
|
+
fee?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Audience-bound "Sign in with CSD" (SIWC) params — the secure third-party login. The wallet binds
|
|
65
|
+
* the REAL requesting origin as the message `domain` (from the unforgeable sender.origin, NEVER this
|
|
66
|
+
* field) plus your server `nonce`, chain id, and a validity window, and returns only the signed
|
|
67
|
+
* artifact. The relying party MUST verify it server-side (see below).
|
|
68
|
+
*/
|
|
69
|
+
interface SiwcParams {
|
|
70
|
+
/** Server-issued, single-use, >=8 alphanumeric (use `generateNonce()` from @inversealtruism/csd-siwc). */
|
|
71
|
+
nonce: string;
|
|
72
|
+
/** Optional one-line human statement shown in the wallet (no newline). */
|
|
73
|
+
statement?: string;
|
|
74
|
+
/** Subject URI; defaults to the origin root. If given, MUST be on the requesting site. */
|
|
75
|
+
uri?: string;
|
|
76
|
+
/** Validity window in seconds (wallet clamps 60..3600, default 600). */
|
|
77
|
+
expirationSecs?: number;
|
|
78
|
+
notBeforeSecs?: number;
|
|
79
|
+
requestId?: string;
|
|
80
|
+
resources?: string[];
|
|
81
|
+
/** Optional cross-check only — if set it MUST equal the requesting origin's host, else refused. */
|
|
82
|
+
domain?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* SIWC result — the signed artifact. VERIFY SERVER-SIDE with `verifySiwc` from
|
|
86
|
+
* `@inversealtruism/csd-siwc` (check domain==your-origin, nonce==your-issued-single-use-nonce,
|
|
87
|
+
* chainId, time window, signature, hash160(pub33)==account), THEN issue your OWN session. The
|
|
88
|
+
* signature is proof-of-control, NEVER a bearer token.
|
|
89
|
+
*/
|
|
90
|
+
interface SiwcResult {
|
|
91
|
+
account: string;
|
|
92
|
+
pub33: string;
|
|
93
|
+
sig64: string;
|
|
94
|
+
/** The exact canonical SIWC message that was signed (verify the signature over this). */
|
|
95
|
+
message: string;
|
|
96
|
+
/** CAIP-2 chain id the sign-in is bound to. */
|
|
97
|
+
chainId: string;
|
|
98
|
+
}
|
|
99
|
+
/** Wallet feature/capability descriptor (feature-detection; older wallets may not expose it). */
|
|
100
|
+
interface WalletCapabilities {
|
|
101
|
+
version: string;
|
|
102
|
+
/** SIWC byte-contract version, e.g. "1", when audience-bound sign-in is supported. */
|
|
103
|
+
siwc?: string;
|
|
104
|
+
methods?: string[];
|
|
105
|
+
[k: string]: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** An EIP-2255-style per-origin permission grant. */
|
|
108
|
+
interface WalletPermission {
|
|
109
|
+
invoker: string;
|
|
110
|
+
accounts: string[];
|
|
111
|
+
grantedAt: number;
|
|
112
|
+
}
|
|
52
113
|
/** The raw provider object the extension injects at `window.cairn`. */
|
|
53
114
|
interface CairnProvider {
|
|
54
115
|
isCairn: true;
|
|
55
116
|
version: string;
|
|
56
117
|
connect(): Promise<ProviderReply<ConnectResult>>;
|
|
57
118
|
getAddress(): Promise<ProviderReply<ConnectResult>>;
|
|
119
|
+
/** @deprecated First-party-only legacy login. Third parties MUST use `signInWithCsd`. */
|
|
58
120
|
signIn(): Promise<ProviderReply<SignInResult>>;
|
|
121
|
+
/** Audience-bound "Sign in with CSD" — the secure third-party login. */
|
|
122
|
+
signInWithCsd(p: SiwcParams): Promise<ProviderReply<SiwcResult>>;
|
|
59
123
|
propose(p: ProposeParams): Promise<ProviderReply<TxResult>>;
|
|
60
124
|
attest(p: AttestParams): Promise<ProviderReply<TxResult>>;
|
|
61
125
|
send(p: SendParams): Promise<ProviderReply<TxResult>>;
|
|
126
|
+
fillOffer(p: FillParams): Promise<ProviderReply<TxResult>>;
|
|
62
127
|
sealClaim(p: SealClaimParams): Promise<ProviderReply<TxResult>>;
|
|
63
128
|
revealClaim(txid: string): Promise<ProviderReply<TxResult>>;
|
|
129
|
+
/** Feature/capability detection (optional; absent on older wallets). */
|
|
130
|
+
getCapabilities?(): Promise<WalletCapabilities>;
|
|
131
|
+
/** EIP-2255-style per-origin permissions (optional; absent on older wallets). */
|
|
132
|
+
getPermissions?(): Promise<ProviderReply<WalletPermission[]>>;
|
|
133
|
+
requestPermissions?(): Promise<ProviderReply<WalletPermission[]>>;
|
|
134
|
+
revokePermissions?(): Promise<ProviderReply<{
|
|
135
|
+
revoked: boolean;
|
|
136
|
+
}>>;
|
|
137
|
+
/** Event subscription (accountsChanged / disconnect) (optional; absent on older wallets). */
|
|
138
|
+
on?(event: string, handler: (data: unknown) => void): void;
|
|
139
|
+
removeListener?(event: string, handler: (data: unknown) => void): void;
|
|
64
140
|
}
|
|
65
141
|
/** Every provider call resolves to this discriminated reply (never rejects). */
|
|
66
142
|
type ProviderReply<T> = {
|
|
@@ -84,12 +160,40 @@ interface DetectOptions {
|
|
|
84
160
|
* content script hasn't injected yet. Throws `NotInstalledError` on timeout or
|
|
85
161
|
* outside a browser.
|
|
86
162
|
*/
|
|
163
|
+
/** EIP-6963-style announced wallet info (Cairn's own `csd:` discovery namespace). */
|
|
164
|
+
interface ProviderInfo {
|
|
165
|
+
uuid: string;
|
|
166
|
+
name: string;
|
|
167
|
+
icon: string;
|
|
168
|
+
rdns: string;
|
|
169
|
+
}
|
|
170
|
+
/** A discovered provider + its display info. */
|
|
171
|
+
interface ProviderDetail {
|
|
172
|
+
info: ProviderInfo;
|
|
173
|
+
provider: CairnProvider;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Enumerate all wallets that announce via the `csd:` discovery handshake (EIP-6963 analog) — for a
|
|
177
|
+
* multi-wallet picker. Resolves with everything announced within `timeoutMs` (default 1000ms).
|
|
178
|
+
*/
|
|
179
|
+
declare function discoverProviders(opts?: DetectOptions): Promise<ProviderDetail[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Resolve `window.cairn`, via three paths that race: an immediate global, the legacy
|
|
182
|
+
* `cairn#initialized` event, or the `csd:announceProvider` discovery handshake (we dispatch
|
|
183
|
+
* `csd:requestProvider`). Throws `NotInstalledError` on timeout or outside a browser.
|
|
184
|
+
*/
|
|
87
185
|
declare function detectProvider(opts?: DetectOptions): Promise<CairnProvider>;
|
|
88
186
|
/** True if the Cairn Wallet is already present (no waiting). */
|
|
89
187
|
declare function isInstalled(): boolean;
|
|
90
188
|
/**
|
|
91
189
|
* High-level, typed wallet handle. Construct via `connect()` or `new WalletConnection(provider)`.
|
|
92
190
|
* Methods throw `UserRejectedError` / `WalletLockedError` / `UnsupportedMethodError` on failure.
|
|
191
|
+
*
|
|
192
|
+
* Note (typed-error contract): the genuine Cairn Wallet always RESOLVES a `{ok,result|error}` reply, so a
|
|
193
|
+
* failure is mapped to a typed `CairnError` via `unwrap`. A non-conformant or SPOOFED provider that instead
|
|
194
|
+
* REJECTS its promise will surface that raw rejection un-mapped (it bypasses `unwrap`), so a dApp's
|
|
195
|
+
* `catch (e) { errorCode(e) }` may see `UNKNOWN` from such a provider. The real auth boundary is server-side
|
|
196
|
+
* SIWC verification, never a client-side error code.
|
|
93
197
|
*/
|
|
94
198
|
declare class WalletConnection {
|
|
95
199
|
readonly provider: CairnProvider;
|
|
@@ -103,8 +207,42 @@ declare class WalletConnection {
|
|
|
103
207
|
connect(): Promise<string>;
|
|
104
208
|
/** Get the connected address (does not force a new connection prompt if already consented). */
|
|
105
209
|
getAddress(): Promise<string>;
|
|
106
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated First-party-only legacy login (it authenticates against the wallet's own configured
|
|
212
|
+
* server and is rejected from third-party origins). Use {@link signInWithCsd} for any site.
|
|
213
|
+
* Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx).
|
|
214
|
+
*/
|
|
107
215
|
signIn(): Promise<SignInResult>;
|
|
216
|
+
/**
|
|
217
|
+
* Audience-bound "Sign in with CSD" (SIWC) — the secure, replay-resistant third-party login.
|
|
218
|
+
* The wallet binds the REAL requesting origin + your single-use server `nonce` into the signed
|
|
219
|
+
* message and returns the artifact; it never mints a session. VERIFY the result SERVER-SIDE with
|
|
220
|
+
* `verifySiwc` from `@inversealtruism/csd-siwc` (domain/nonce/chain/time/signature/account), then
|
|
221
|
+
* issue your OWN session. The signature is proof-of-control, NOT a bearer token. Always prompts.
|
|
222
|
+
*/
|
|
223
|
+
signInWithCsd(params: SiwcParams): Promise<SiwcResult>;
|
|
224
|
+
/** True if this wallet supports audience-bound SIWC (safe to call `signInWithCsd`). */
|
|
225
|
+
get supportsSiwc(): boolean;
|
|
226
|
+
/** Feature/capability detection. Returns null if the wallet predates `getCapabilities`. */
|
|
227
|
+
getCapabilities(): Promise<WalletCapabilities | null>;
|
|
228
|
+
/** Atomic fill (CairnX DvP): pay + attest in ONE tx. Always prompts with clear-signing. */
|
|
229
|
+
fillOffer(params: FillParams): Promise<TxResult>;
|
|
230
|
+
/** This origin's current permission grant (EIP-2255-style). Silent; [] if none / unsupported. */
|
|
231
|
+
getPermissions(): Promise<WalletPermission[]>;
|
|
232
|
+
/** Explicitly request permission to see the address (prompts, like connect). */
|
|
233
|
+
requestPermissions(): Promise<WalletPermission[]>;
|
|
234
|
+
/** Revoke THIS origin's own access (silent). Returns { revoked }. Safe no-op on older wallets. */
|
|
235
|
+
revokePermissions(): Promise<{
|
|
236
|
+
revoked: boolean;
|
|
237
|
+
}>;
|
|
238
|
+
/**
|
|
239
|
+
* Subscribe to provider events. `accountsChanged` fires with `[]` when this site loses access
|
|
240
|
+
* (wallet lock / account switch / revoke) — re-call connect() to (re)share; `disconnect` likewise.
|
|
241
|
+
* No-op if the wallet predates events. Use the SAME handler reference with off() to unsubscribe.
|
|
242
|
+
*/
|
|
243
|
+
on(event: "accountsChanged" | "disconnect" | (string & {}), handler: (data: any) => void): void;
|
|
244
|
+
/** Remove a previously-added event handler (must be the same reference passed to on()). */
|
|
245
|
+
off(event: string, handler: (data: any) => void): void;
|
|
108
246
|
/** Send CSD (always prompts with clear-signing; wallet picks inputs + returns change to itself). */
|
|
109
247
|
send(params: SendParams): Promise<TxResult>;
|
|
110
248
|
/** Low-level Propose (always prompts). Prefer `cairn.board.propose()` which computes the hash/uri/expiry. */
|
|
@@ -124,4 +262,4 @@ declare function connect(opts?: DetectOptions): Promise<{
|
|
|
124
262
|
address: string;
|
|
125
263
|
}>;
|
|
126
264
|
|
|
127
|
-
export { type AttestParams, type CairnProvider, type ConnectResult, type DetectOptions, type ProposeParams, type ProviderReply, type SealClaimParams, type SendParams, type SignInResult, type TxResult, WalletConnection, connect, detectProvider, getWallet, isInstalled };
|
|
265
|
+
export { type AttestParams, type CairnProvider, type ConnectResult, type DetectOptions, type FillParams, type ProposeParams, type ProviderDetail, type ProviderInfo, type ProviderReply, type SealClaimParams, type SendParams, type SignInResult, type SiwcParams, type SiwcResult, type TxResult, type WalletCapabilities, WalletConnection, type WalletPermission, connect, detectProvider, discoverProviders, getWallet, isInstalled };
|
package/dist/connect.js
CHANGED
|
@@ -2,14 +2,16 @@ import {
|
|
|
2
2
|
WalletConnection,
|
|
3
3
|
connect,
|
|
4
4
|
detectProvider,
|
|
5
|
+
discoverProviders,
|
|
5
6
|
getWallet,
|
|
6
7
|
isInstalled
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-K7SJOW3O.js";
|
|
9
|
+
import "./chunk-RELP23CH.js";
|
|
9
10
|
export {
|
|
10
11
|
WalletConnection,
|
|
11
12
|
connect,
|
|
12
13
|
detectProvider,
|
|
14
|
+
discoverProviders,
|
|
13
15
|
getWallet,
|
|
14
16
|
isInstalled
|
|
15
17
|
};
|
package/dist/content.cjs
CHANGED
|
@@ -26,16 +26,47 @@ 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.1.4";
|
|
30
|
+
var DOCS_BASE = "https://cairn-substrate.com/docs/sdk";
|
|
29
31
|
var CairnError = class extends Error {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
/** Stable machine code for programmatic branching. */
|
|
33
|
+
code;
|
|
34
|
+
/** The human message without the appended docs/version footer. */
|
|
35
|
+
shortMessage;
|
|
36
|
+
/** Relative docs path (under the SDK docs base), if any. */
|
|
37
|
+
docsPath;
|
|
38
|
+
/** The cairn-sdk version that produced this error. */
|
|
39
|
+
version = SDK_VERSION;
|
|
40
|
+
constructor(shortMessage, opts = {}) {
|
|
41
|
+
const docs = opts.docsPath;
|
|
42
|
+
super(
|
|
43
|
+
[shortMessage, docs ? `Docs: ${DOCS_BASE}${docs}` : "", `Version: cairn-sdk@${SDK_VERSION}`].filter(Boolean).join("\n"),
|
|
44
|
+
{ cause: opts.cause }
|
|
45
|
+
);
|
|
32
46
|
this.name = new.target.name;
|
|
47
|
+
this.code = opts.code ?? "UNKNOWN";
|
|
48
|
+
this.shortMessage = shortMessage;
|
|
49
|
+
this.docsPath = docs;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Walk the `cause` chain. With a predicate, returns the FIRST matching error (or null). Without one,
|
|
53
|
+
* returns the DEEPEST cause (the root). Mirrors viem's `BaseError.walk()`.
|
|
54
|
+
*/
|
|
55
|
+
walk(fn) {
|
|
56
|
+
let current = this;
|
|
57
|
+
let last = this;
|
|
58
|
+
while (current != null) {
|
|
59
|
+
if (fn && fn(current)) return current;
|
|
60
|
+
last = current;
|
|
61
|
+
current = current?.cause;
|
|
62
|
+
}
|
|
63
|
+
return fn ? null : last;
|
|
33
64
|
}
|
|
34
65
|
};
|
|
35
66
|
var ContentVerificationError = class extends CairnError {
|
|
36
67
|
expected;
|
|
37
68
|
constructor(expected) {
|
|
38
|
-
super(`Content does not match its payload hash ${expected} \u2014 bytes were tampered with in transit
|
|
69
|
+
super(`Content does not match its payload hash ${expected} \u2014 bytes were tampered with in transit.`, { code: "CONTENT_VERIFICATION", docsPath: "/content#verification" });
|
|
39
70
|
this.expected = expected;
|
|
40
71
|
}
|
|
41
72
|
};
|
|
@@ -104,8 +135,9 @@ var ContentClient = class {
|
|
|
104
135
|
}
|
|
105
136
|
};
|
|
106
137
|
function normalizeHash(hash) {
|
|
107
|
-
const h = hash.startsWith("0x") || hash.startsWith("0X") ? hash : `0x${hash}
|
|
108
|
-
|
|
138
|
+
const h = (hash.startsWith("0x") || hash.startsWith("0X") ? hash : `0x${hash}`).toLowerCase();
|
|
139
|
+
if (!/^0x[0-9a-f]{64}$/.test(h)) throw new Error(`invalid content hash: ${hash}`);
|
|
140
|
+
return h;
|
|
109
141
|
}
|
|
110
142
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
143
|
0 && (module.exports = {
|
package/dist/content.d.cts
CHANGED
package/dist/content.d.ts
CHANGED