@capxul/sdk 0.2.0-alpha.3 → 0.2.0-alpha.5

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.
Files changed (45) hide show
  1. package/README.md +4 -266
  2. package/dist/InMemoryAuthCacheAdapter-BK-B_ERB.mjs +113 -0
  3. package/dist/InMemoryAuthCacheAdapter-BK-B_ERB.mjs.map +1 -0
  4. package/dist/index.d.mts +1263 -0
  5. package/dist/index.d.mts.map +1 -0
  6. package/dist/index.mjs +4740 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/node/index.d.mts +55 -0
  9. package/dist/node/index.d.mts.map +1 -0
  10. package/dist/node/index.mjs +159 -0
  11. package/dist/node/index.mjs.map +1 -0
  12. package/dist/ports/safe-deployment.d.mts +2 -0
  13. package/dist/ports/safe-deployment.mjs +38 -0
  14. package/dist/ports/safe-deployment.mjs.map +1 -0
  15. package/dist/safe-deployment-Vni46k3t.d.mts +137 -0
  16. package/dist/safe-deployment-Vni46k3t.d.mts.map +1 -0
  17. package/dist/signer-oaYGfjDe.d.mts +142 -0
  18. package/dist/signer-oaYGfjDe.d.mts.map +1 -0
  19. package/package.json +37 -71
  20. package/CHANGELOG.md +0 -256
  21. package/LICENSE +0 -44
  22. package/dist/client-B_Z3ThFO.d.cts +0 -1484
  23. package/dist/client-pMBRFcsz.d.ts +0 -1484
  24. package/dist/client.cjs +0 -4324
  25. package/dist/client.d.cts +0 -6
  26. package/dist/client.d.ts +0 -6
  27. package/dist/client.js +0 -4322
  28. package/dist/errors-CwhCWGxm.d.ts +0 -70
  29. package/dist/errors-rqxuUhQP.d.cts +0 -70
  30. package/dist/errors.cjs +0 -35
  31. package/dist/errors.d.cts +0 -2
  32. package/dist/errors.d.ts +0 -2
  33. package/dist/errors.js +0 -31
  34. package/dist/index.cjs +0 -4626
  35. package/dist/index.d.cts +0 -571
  36. package/dist/index.d.ts +0 -571
  37. package/dist/index.js +0 -4585
  38. package/dist/next-action-CTGl8wpy.d.cts +0 -177
  39. package/dist/next-action-CTGl8wpy.d.ts +0 -177
  40. package/dist/types-Brucpq0Z.d.cts +0 -1191
  41. package/dist/types-V_D7qjxY.d.ts +0 -1191
  42. package/dist/webhooks.cjs +0 -118
  43. package/dist/webhooks.d.cts +0 -33
  44. package/dist/webhooks.d.ts +0 -33
  45. package/dist/webhooks.js +0 -116
@@ -0,0 +1,1263 @@
1
+ import { a as AccountProviderSource, c as eip1193AccountProvider, d as CapxulResult, f as Profile, g as AuthCachePort, i as AccountProvider, l as localPrivateKeyAccountProvider, m as SmartAccount, n as Eip1193RequestProvider, o as AccountRequirement, p as Session, r as injectedWalletSigner, s as Eip1193Provider, t as CapxulSigner, u as openfortEmbeddedAccountProvider, v as CachedJwt } from "./signer-oaYGfjDe.mjs";
2
+ import { a as SafeDeploymentEvidence, n as SafeDeploymentConfig } from "./safe-deployment-Vni46k3t.mjs";
3
+ import { Context, Effect, Layer, Request } from "effect";
4
+ import { Machine } from "@effect/experimental";
5
+ import { CapxulError, CapxulErrorCode, CapxulErrorDetails } from "@capxul/config";
6
+ import { Account, Account as Account$1, AccountId, Address, Address as Address$1, AllowedOrigin, AnonymousDistinctId, AppId, AuthSession, AuthSession as AuthSession$1, AuthUserId, AuthUserId as AuthUserId$1, ChainId, CountryCode, DeveloperApplication, DurationMs, Email, EpochMs, Money, Money as Money$1, OrgId, OrgId as OrgId$1, Profile as Profile$1, PublishableKey, PublishableKeyId, PublishableKeyRecord, RoleKey, RoleKey as RoleKey$1, RunId, SessionToken, SmartAccount as SmartAccount$1, SubAccount, SubAccount as SubAccount$1, SubAccountId, SubAccountId as SubAccountId$1 } from "@capxul/types";
7
+ import { TelemetryEvent, TelemetryGroupInput, TelemetryIdentifyInput } from "@capxul/observability";
8
+ import { Hex } from "viem";
9
+ import { Schema } from "@effect/schema";
10
+ import { FunctionReference } from "convex/server";
11
+
12
+ //#region src/ports/auth-client.d.ts
13
+ type AuthClientOperationOptions = {
14
+ readonly signal?: AbortSignal;
15
+ };
16
+ type SendOtpInput = {
17
+ readonly email: Email;
18
+ };
19
+ type CanSendOtpInput = {
20
+ readonly email: Email;
21
+ };
22
+ type CanSendOtpStatus = {
23
+ readonly allowed: boolean;
24
+ readonly cooldownMs: DurationMs;
25
+ };
26
+ type VerifyOtpInput = {
27
+ readonly email: Email;
28
+ readonly otp: string;
29
+ };
30
+ type GetConvexJwtOptions = AuthClientOperationOptions & {
31
+ readonly forceRefresh?: boolean;
32
+ };
33
+ declare const AuthClientError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
34
+ readonly _tag: "AuthClientError";
35
+ } & Readonly<A>;
36
+ declare class AuthClientError extends AuthClientError_base<{
37
+ readonly operation: string;
38
+ readonly kind: string;
39
+ readonly cause: unknown;
40
+ }> {}
41
+ interface AuthClientPort {
42
+ canSendOtp(input: CanSendOtpInput, options?: AuthClientOperationOptions): Effect.Effect<CanSendOtpStatus, AuthClientError>;
43
+ sendOtp(input: SendOtpInput, options?: AuthClientOperationOptions): Effect.Effect<void, AuthClientError>;
44
+ verifyOtp(input: VerifyOtpInput, options?: AuthClientOperationOptions): Effect.Effect<AuthSession$1, AuthClientError>;
45
+ getSession(options?: AuthClientOperationOptions): Effect.Effect<AuthSession$1 | null, AuthClientError>;
46
+ signOut(options?: AuthClientOperationOptions): Effect.Effect<void, AuthClientError>;
47
+ /**
48
+ * Fetches a Convex-aud JWT from `/api/auth/convex/token` (W7). Server mints
49
+ * a fresh JWT on every call per Probe A's 2026-05-19 finding (RS256, 900 s
50
+ * lifetime, `iss = <site-url>`, `aud = convex`). The caller (the SDK's
51
+ * `tokenProvider` wired into ConvexCallPort) is responsible for the
52
+ * `exp - 30s` proactive cache + `forceRefresh` callback handshake.
53
+ */
54
+ getConvexJwt(options?: GetConvexJwtOptions): Effect.Effect<CachedJwt, AuthClientError>;
55
+ }
56
+ //#endregion
57
+ //#region src/ports/clock.d.ts
58
+ interface ClockPort {
59
+ readonly now: Effect.Effect<EpochMs, ClockError>;
60
+ readonly sleep: (duration: DurationMs) => Effect.Effect<void, ClockError>;
61
+ }
62
+ declare const ClockError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
63
+ readonly _tag: "ClockError";
64
+ } & Readonly<A>;
65
+ declare class ClockError extends ClockError_base<{
66
+ readonly operation: "now" | "sleep" | "initialize";
67
+ readonly cause: unknown;
68
+ }> {}
69
+ //#endregion
70
+ //#region src/ports/telemetry.d.ts
71
+ interface TelemetryPort {
72
+ readonly emit: (event: TelemetryEvent) => Effect.Effect<void, never>;
73
+ readonly identify: (input: TelemetryIdentifyInput) => Effect.Effect<void, never>;
74
+ readonly group: (input: TelemetryGroupInput) => Effect.Effect<void, never>;
75
+ readonly reset: () => Effect.Effect<void, never>;
76
+ }
77
+ //#endregion
78
+ //#region src/flows/auth.d.ts
79
+ interface AuthFlowInput {
80
+ readonly otpTtlMs?: number;
81
+ }
82
+ type AuthFlowState = "idle" | "sending_otp" | "otp_requested" | "verifying" | "authenticated" | "signing_out" | "error";
83
+ interface AuthFlowContext {
84
+ readonly state: AuthFlowState;
85
+ readonly email: Email | null;
86
+ readonly session: AuthSession$1 | null;
87
+ readonly otpRequestedAt: EpochMs | null;
88
+ readonly anonDistinctId?: AnonymousDistinctId;
89
+ readonly error: CapxulError | null;
90
+ }
91
+ interface AuthFlowObserver {
92
+ readonly input: AuthFlowInput;
93
+ readonly getSnapshot: () => {
94
+ readonly value: AuthFlowState;
95
+ readonly context: AuthFlowContext;
96
+ readonly status: "active" | "stopped";
97
+ };
98
+ readonly stop: () => void;
99
+ }
100
+ //#endregion
101
+ //#region src/env/_internal.d.ts
102
+ declare const envShapeSchema: Schema.Struct<{
103
+ [k: string]: Schema.Schema<string, string, never> | Schema.optional<Schema.Schema<string, string, never>>;
104
+ }>;
105
+ type EnvShape = Schema.Schema.Type<typeof envShapeSchema>;
106
+ type EnvKey = keyof EnvShape & string;
107
+ //#endregion
108
+ //#region src/env/index.d.ts
109
+ type RequiredEnvKey = EnvKey;
110
+ type OptionalEnvKey = EnvKey;
111
+ //#endregion
112
+ //#region src/ports/env.d.ts
113
+ declare const EnvError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
114
+ readonly _tag: "EnvError";
115
+ } & Readonly<A>;
116
+ declare class EnvError extends EnvError_base<{
117
+ readonly publicError: CapxulError;
118
+ readonly publicCode?: CapxulErrorCode;
119
+ readonly key?: string;
120
+ readonly details?: CapxulErrorDetails;
121
+ readonly cause?: unknown;
122
+ }> {}
123
+ interface EnvPort {
124
+ readonly require: <K extends RequiredEnvKey>(key: K) => Effect.Effect<EnvShape[K], EnvError, never>;
125
+ readonly optional: <K extends OptionalEnvKey>(key: K) => Effect.Effect<EnvShape[K] | undefined, EnvError, never>;
126
+ readonly has: (key: EnvKey) => Effect.Effect<boolean, EnvError, never>;
127
+ }
128
+ //#endregion
129
+ //#region src/ports/evm-signer.d.ts
130
+ type HexString = `0x${string}`;
131
+ type UserOperationRequest = {
132
+ readonly sender: Address$1;
133
+ readonly chainId: ChainId;
134
+ readonly callData: HexString;
135
+ readonly nonce?: HexString;
136
+ readonly maxFeePerGas?: HexString;
137
+ readonly maxPriorityFeePerGas?: HexString;
138
+ readonly callGasLimit?: HexString;
139
+ readonly verificationGasLimit?: HexString;
140
+ readonly preVerificationGas?: HexString;
141
+ readonly paymasterAndData?: HexString;
142
+ };
143
+ type SignedUserOperation = UserOperationRequest & {
144
+ readonly sender: Address$1;
145
+ readonly signature: HexString;
146
+ readonly userOpHash: HexString;
147
+ };
148
+ declare const EvmSignerError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
149
+ readonly _tag: "EvmSignerError";
150
+ } & Readonly<A>;
151
+ declare class EvmSignerError extends EvmSignerError_base<{
152
+ readonly publicError: CapxulError;
153
+ readonly publicCode?: CapxulErrorCode;
154
+ readonly operation?: string;
155
+ readonly details?: CapxulErrorDetails;
156
+ readonly cause?: unknown;
157
+ }> {}
158
+ interface EvmSignerPort {
159
+ readonly getAddress: Effect.Effect<Address$1, EvmSignerError, never>;
160
+ readonly signMessage: (message: string | Uint8Array) => Effect.Effect<HexString, EvmSignerError, never>;
161
+ readonly signUserOp: (userOperation: UserOperationRequest) => Effect.Effect<SignedUserOperation, EvmSignerError, never>;
162
+ }
163
+ //#endregion
164
+ //#region src/ports/transport.d.ts
165
+ type TransportOperationKind = "query" | "mutation" | "action";
166
+ type TransportRequest<TArgs = unknown> = {
167
+ readonly name: string;
168
+ readonly args: TArgs;
169
+ readonly correlationId?: string;
170
+ };
171
+ declare const TransportError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
172
+ readonly _tag: "TransportError";
173
+ } & Readonly<A>;
174
+ declare class TransportError extends TransportError_base<{
175
+ readonly operation: TransportOperationKind;
176
+ readonly name: string;
177
+ readonly publicCode: CapxulErrorCode;
178
+ readonly publicError: CapxulError;
179
+ readonly cause: unknown;
180
+ readonly correlationId?: string;
181
+ readonly details?: CapxulErrorDetails;
182
+ }> {}
183
+ interface TransportPort {
184
+ readonly runQuery: <TOutput = unknown, TArgs = unknown>(request: TransportRequest<TArgs>) => Effect.Effect<TOutput, TransportError>;
185
+ readonly runMutation: <TOutput = unknown, TArgs = unknown>(request: TransportRequest<TArgs>) => Effect.Effect<TOutput, TransportError>;
186
+ readonly runAction: <TOutput = unknown, TArgs = unknown>(request: TransportRequest<TArgs>) => Effect.Effect<TOutput, TransportError>;
187
+ }
188
+ //#endregion
189
+ //#region src/ports/bootstrap.d.ts
190
+ type BootstrapInput = {
191
+ readonly publishableKey: PublishableKey;
192
+ /**
193
+ * Browser callers send the App origin so bootstrap can enforce the
194
+ * publishable-key allowlist. Node/server callers may omit it; the backend
195
+ * only applies the origin allowlist when an origin is present.
196
+ */
197
+ readonly origin?: AllowedOrigin;
198
+ };
199
+ type BootstrapResolution = {
200
+ readonly applicationId: AppId;
201
+ readonly chainId: ChainId;
202
+ /**
203
+ * SDK-handshake session token — distinct from the user-auth `AuthSession`
204
+ * token issued by `AuthClientPort`. Both use the `SessionToken` brand for
205
+ * opaque-string discipline; the issuance source distinguishes them.
206
+ */
207
+ readonly sessionToken: SessionToken;
208
+ readonly issuedAt: EpochMs;
209
+ readonly expiresIn: DurationMs;
210
+ readonly authBaseUrl: string;
211
+ readonly convexUrl: string;
212
+ };
213
+ type BootstrapErrorKind = "notAuthenticated" | "network" | "provider" | "malformedBody" | "invalidInput" | "rateLimited";
214
+ declare const BootstrapError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
215
+ readonly _tag: "BootstrapError";
216
+ } & Readonly<A>;
217
+ declare class BootstrapError extends BootstrapError_base<{
218
+ readonly operation: "resolve";
219
+ readonly kind: BootstrapErrorKind;
220
+ readonly publicCode: CapxulErrorCode;
221
+ readonly cause: unknown;
222
+ readonly details?: CapxulErrorDetails;
223
+ }> {}
224
+ interface BootstrapPort {
225
+ readonly resolve: (input: BootstrapInput) => Effect.Effect<BootstrapResolution, BootstrapError>;
226
+ }
227
+ //#endregion
228
+ //#region src/ports/subscription.d.ts
229
+ /**
230
+ * Canonical teardown handle for substrate-level reactive callbacks.
231
+ *
232
+ * Calling it stops the subscription; no further snapshots will be delivered
233
+ * to the callback after the first invocation. Calling more than once is a
234
+ * no-op (idempotent).
235
+ *
236
+ * @internal-use
237
+ */
238
+ type Unsubscribe = () => void;
239
+ /**
240
+ * Snapshot is the substrate discriminated union for reactive callbacks over
241
+ * `ConvexCallPort.subscribe`. The public SDK surface is imperative
242
+ * (`Promise<CapxulResult>`). This type is reachable for internal XState
243
+ * `fromCallback` actor wiring,
244
+ * property-based `crossAdapterSubscriptionProperty` harness consumers, and
245
+ * genuinely non-React advanced consumers.
246
+ *
247
+ * - `loading` · initial state before any value arrives from the substrate
248
+ * - `ok` · a successful snapshot carrying `value`
249
+ * - `error` · a failed snapshot carrying a typed error (defaults to
250
+ * `CapxulError`)
251
+ *
252
+ * Generic over the value type `T`. The error type `E` is parameterised but
253
+ * defaults to `CapxulError` — every shipped port today uses the default. A
254
+ * narrower or wider `E` is reserved for future ports that need a different
255
+ * error vocabulary.
256
+ *
257
+ * The substrate guarantees the first snapshot is `loading` (CC8 in the
258
+ * `ConvexCallPort` contract); subsequent snapshots carry `ok` or `error`
259
+ * per the underlying transport.
260
+ *
261
+ * Per ARCH-LOCK-1 (`docs/decisions/stage-4-reactivity-pivot.html`), domain
262
+ * ports do not expose reactive callback methods.
263
+ *
264
+ * @internal-use
265
+ */
266
+ type Snapshot<T, E = CapxulError> = {
267
+ readonly status: "loading";
268
+ } | {
269
+ readonly status: "ok";
270
+ readonly value: T;
271
+ } | {
272
+ readonly status: "error";
273
+ readonly error: E;
274
+ };
275
+ //#endregion
276
+ //#region src/ports/convex-call.d.ts
277
+ declare const ConvexCallError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
278
+ readonly _tag: "ConvexCallError";
279
+ } & Readonly<A>;
280
+ declare class ConvexCallError extends ConvexCallError_base<{
281
+ readonly operation: string;
282
+ readonly publicCode: CapxulErrorCode;
283
+ readonly publicError: CapxulError;
284
+ readonly cause: unknown;
285
+ readonly details?: CapxulErrorDetails;
286
+ }> {}
287
+ interface ConvexCallPort {
288
+ query<TArgs extends Record<string, unknown>, TOutput>(fn: FunctionReference<"query", "public", TArgs, TOutput>, args: TArgs): Effect.Effect<TOutput, ConvexCallError>;
289
+ mutation<TArgs extends Record<string, unknown>, TOutput>(fn: FunctionReference<"mutation", "public", TArgs, TOutput>, args: TArgs): Effect.Effect<TOutput, ConvexCallError>;
290
+ action<TArgs extends Record<string, unknown>, TOutput>(fn: FunctionReference<"action", "public", TArgs, TOutput>, args: TArgs): Effect.Effect<TOutput, ConvexCallError>;
291
+ /**
292
+ * Substrate-level reactive transport over Convex's `onUpdate`.
293
+ *
294
+ * @internal-use — substrate only; see `ports/subscription.ts`. Domain
295
+ * ports do not expose reactive callback methods to consumers (ARCH-LOCK-1).
296
+ */
297
+ subscribe<TArgs extends Record<string, unknown>, TOutput>(fn: FunctionReference<"query", "public", TArgs, TOutput>, args: TArgs, callback: (snapshot: Snapshot<TOutput>) => void): Effect.Effect<Unsubscribe, ConvexCallError>;
298
+ }
299
+ //#endregion
300
+ //#region src/ports/credentials.d.ts
301
+ type CreateApplicationInput = {
302
+ readonly authUserId: AuthUserId$1;
303
+ readonly name: string;
304
+ readonly allowedOrigins: readonly AllowedOrigin[];
305
+ };
306
+ type MintKeyInput = {
307
+ readonly applicationId: AppId;
308
+ readonly authUserId: AuthUserId$1;
309
+ };
310
+ type RotateKeyInput = {
311
+ readonly keyId: PublishableKeyId;
312
+ readonly authUserId: AuthUserId$1;
313
+ readonly graceMs: DurationMs;
314
+ };
315
+ type RevokeKeyInput = {
316
+ readonly keyId: PublishableKeyId;
317
+ readonly authUserId: AuthUserId$1;
318
+ };
319
+ type RotateKeyResult = {
320
+ readonly active: PublishableKeyRecord;
321
+ readonly retired: PublishableKeyRecord;
322
+ };
323
+ declare const CredentialsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
324
+ readonly _tag: "CredentialsError";
325
+ } & Readonly<A>;
326
+ declare class CredentialsError extends CredentialsError_base<{
327
+ readonly operation: string;
328
+ readonly publicCode: CapxulErrorCode;
329
+ readonly publicError: CapxulError;
330
+ readonly cause: unknown;
331
+ readonly details?: CapxulErrorDetails;
332
+ }> {}
333
+ interface CredentialsPort {
334
+ listApplications(authUserId: AuthUserId$1): Effect.Effect<readonly DeveloperApplication[], CredentialsError>;
335
+ createApplication(input: CreateApplicationInput): Effect.Effect<DeveloperApplication, CredentialsError>;
336
+ mintPublishableKey(input: MintKeyInput): Effect.Effect<PublishableKeyRecord, CredentialsError>;
337
+ rotatePublishableKey(input: RotateKeyInput): Effect.Effect<RotateKeyResult, CredentialsError>;
338
+ revokePublishableKey(input: RevokeKeyInput): Effect.Effect<void, CredentialsError>;
339
+ }
340
+ //#endregion
341
+ //#region src/ports/identity.d.ts
342
+ type CreateIdentityInput = {
343
+ readonly authUserId: AuthUserId$1;
344
+ readonly email: Email;
345
+ readonly displayName?: string;
346
+ readonly country?: CountryCode;
347
+ };
348
+ type UpdateIdentityInput = {
349
+ readonly authUserId: AuthUserId$1;
350
+ readonly displayName?: string;
351
+ readonly country?: CountryCode;
352
+ };
353
+ declare const IdentityError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
354
+ readonly _tag: "IdentityError";
355
+ } & Readonly<A>;
356
+ declare class IdentityError extends IdentityError_base<{
357
+ readonly operation: string;
358
+ readonly publicCode: CapxulErrorCode;
359
+ readonly publicError: CapxulError;
360
+ readonly cause: unknown;
361
+ readonly details?: CapxulErrorDetails;
362
+ }> {}
363
+ interface IdentityPort {
364
+ loadByAuthUserId(authUserId: AuthUserId$1): Effect.Effect<Profile$1 | null, IdentityError, never>;
365
+ create(input: CreateIdentityInput): Effect.Effect<Profile$1, IdentityError, never>;
366
+ update(input: UpdateIdentityInput): Effect.Effect<Profile$1, IdentityError, never>;
367
+ }
368
+ //#endregion
369
+ //#region src/ports/smart-account.d.ts
370
+ type ProvisionInput = {
371
+ readonly authUserId: AuthUserId$1;
372
+ readonly signerAddress: Address$1;
373
+ readonly chainId: ChainId;
374
+ };
375
+ /**
376
+ * Input to `SmartAccountPort.confirmDeployment` (#161 · γ-B).
377
+ *
378
+ * The SDK provides evidence pointers; the backend is the oracle for
379
+ * `deployedAt`. `evidence.deployedAt` does NOT exist by schema (see
380
+ * `SafeDeploymentEvidence`) — the backend derives `deployedAt` from
381
+ * the on-chain receipt block via `eth_getBlockByNumber`.
382
+ *
383
+ * Precheck path: `evidence.userOpHash` omitted; backend scans
384
+ * `SafeProxyFactory.ProxyCreation(safeAddress, _)` via `eth_getLogs`.
385
+ *
386
+ * Real-userOp path: `evidence.userOpHash` populated; backend calls
387
+ * `eth_getUserOperationReceipt(userOpHash)` to re-verify and derive.
388
+ */
389
+ type ConfirmDeploymentInput = {
390
+ readonly authUserId: AuthUserId$1;
391
+ readonly chainId: ChainId;
392
+ readonly safeAddress: Address$1;
393
+ readonly evidence: SafeDeploymentEvidence;
394
+ /**
395
+ * Optional live-E2E correlation id. This does not prove deployment; the
396
+ * backend still re-verifies chain evidence and only mirrors this branded
397
+ * id onto telemetry for PostHog run joins.
398
+ */
399
+ readonly telemetryRunId?: RunId;
400
+ };
401
+ /** Opaque wire form of the backend-built deployment UserOperation (hex strings). */
402
+ type DeploymentUserOpFields = {
403
+ readonly sender: string;
404
+ readonly nonce: string;
405
+ readonly factory: string;
406
+ readonly factoryData: string;
407
+ readonly callData: string;
408
+ readonly callGasLimit: string;
409
+ readonly verificationGasLimit: string;
410
+ readonly preVerificationGas: string;
411
+ readonly maxFeePerGas: string;
412
+ readonly maxPriorityFeePerGas: string;
413
+ readonly paymaster: string;
414
+ readonly paymasterVerificationGasLimit: string;
415
+ readonly paymasterPostOpGasLimit: string;
416
+ readonly paymasterData: string;
417
+ };
418
+ /** Input to `SmartAccountPort.deployPrepare` (backend-orchestrated-deploy.md · #289). */
419
+ type DeployPrepareInput = {
420
+ readonly authUserId: AuthUserId$1;
421
+ readonly chainId: ChainId;
422
+ readonly telemetryRunId?: RunId;
423
+ };
424
+ /** Backend-built deployment UserOp + the EIP-712 SafeOp digest the CapxulSigner signs. */
425
+ type DeployPrepareResult = {
426
+ readonly digest: Hex;
427
+ readonly safeAddress: Address$1;
428
+ readonly userOp: DeploymentUserOpFields;
429
+ };
430
+ /** Input to `SmartAccountPort.deploySubmit` — the consumer-signed deployment UserOp. */
431
+ type DeploySubmitInput = {
432
+ readonly authUserId: AuthUserId$1;
433
+ readonly chainId: ChainId;
434
+ readonly userOp: DeploymentUserOpFields;
435
+ readonly signature: Hex;
436
+ readonly telemetryRunId?: RunId;
437
+ };
438
+ declare const SmartAccountError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
439
+ readonly _tag: "SmartAccountError";
440
+ } & Readonly<A>;
441
+ declare class SmartAccountError extends SmartAccountError_base<{
442
+ readonly operation: string;
443
+ readonly publicCode: CapxulErrorCode;
444
+ readonly publicError: CapxulError;
445
+ readonly cause: unknown;
446
+ readonly details?: CapxulErrorDetails;
447
+ }> {}
448
+ interface SmartAccountPort {
449
+ loadByAuthUserId(authUserId: AuthUserId$1): Effect.Effect<SmartAccount$1 | null, SmartAccountError, never>;
450
+ loadBySmartAccountAddress(address: Address$1): Effect.Effect<SmartAccount$1 | null, SmartAccountError, never>;
451
+ provision(input: ProvisionInput): Effect.Effect<SmartAccount$1, SmartAccountError, never>;
452
+ /**
453
+ * Persist on-chain Safe-deployment evidence. The backend re-verifies
454
+ * the evidence against chain state and derives `deployedAt` from the
455
+ * receipt block's timestamp. Returns the updated `SmartAccount` row.
456
+ *
457
+ * γ-B trust model: the SDK supplies evidence pointers only. The
458
+ * backend is the SOLE oracle for `deployedAt` — see
459
+ * `docs/canon/ports/smart-account.md`.
460
+ */
461
+ confirmDeployment(input: ConfirmDeploymentInput): Effect.Effect<SmartAccount$1, SmartAccountError, never>;
462
+ /**
463
+ * Build + gas-fill + paymaster-sponsor the deployment UserOperation
464
+ * server-side and return the EIP-712 `SafeOp` digest for the consumer's
465
+ * `CapxulSigner` to sign. The client never holds RPC, a gas policy, or a
466
+ * bundler — see `docs/canon/decisions/backend-orchestrated-deploy.md`.
467
+ */
468
+ deployPrepare(input: DeployPrepareInput): Effect.Effect<DeployPrepareResult, SmartAccountError, never>;
469
+ /**
470
+ * Submit the signed deployment UserOperation through the bundler and confirm
471
+ * `deployedAt` on-chain (absorbing the `confirmDeployment` verify path).
472
+ * Returns the updated `SmartAccount` row.
473
+ */
474
+ deploySubmit(input: DeploySubmitInput): Effect.Effect<SmartAccount$1, SmartAccountError, never>;
475
+ }
476
+ //#endregion
477
+ //#region src/ports/account-read.d.ts
478
+ type ReadAccountBalanceInput = {
479
+ readonly chainId: ChainId;
480
+ };
481
+ type FundFromFaucetInput = {
482
+ readonly chainId: ChainId;
483
+ readonly amount: Money$1;
484
+ };
485
+ type FundFromFaucetResult = {
486
+ readonly txHash: string;
487
+ };
488
+ declare const AccountReadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
489
+ readonly _tag: "AccountReadError";
490
+ } & Readonly<A>;
491
+ declare class AccountReadError extends AccountReadError_base<{
492
+ readonly operation: string;
493
+ readonly publicCode: CapxulErrorCode;
494
+ readonly publicError: CapxulError;
495
+ readonly cause: unknown;
496
+ readonly details?: CapxulErrorDetails;
497
+ }> {}
498
+ /**
499
+ * Logical Account money read (M2 Slice S1a). Joins the `accounts` row with a
500
+ * live RPC `balanceOf` pull; the adapter lifts wire integers to `Money`.
501
+ */
502
+ interface AccountReadPort {
503
+ readBalance(input: ReadAccountBalanceInput): Effect.Effect<Account$1, AccountReadError, never>;
504
+ fundFromFaucet(input: FundFromFaucetInput): Effect.Effect<FundFromFaucetResult, AccountReadError, never>;
505
+ }
506
+ //#endregion
507
+ //#region src/ports/sub-account.d.ts
508
+ declare const SubAccountError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
509
+ readonly _tag: "SubAccountError";
510
+ } & Readonly<A>;
511
+ declare class SubAccountError extends SubAccountError_base<{
512
+ readonly operation: string;
513
+ readonly publicCode: CapxulErrorCode;
514
+ readonly publicError: CapxulError;
515
+ readonly cause: unknown;
516
+ readonly details?: CapxulErrorDetails;
517
+ }> {}
518
+ type CreateSubAccountInput = {
519
+ readonly accountId: AccountId;
520
+ readonly name: string;
521
+ };
522
+ type SubAccountIdInput = {
523
+ readonly subAccountId: SubAccountId$1;
524
+ };
525
+ type RenameSubAccountInput = {
526
+ readonly subAccountId: SubAccountId$1;
527
+ readonly name: string;
528
+ };
529
+ /**
530
+ * A `transfer` endpoint is either the Account's MAIN balance (the remainder
531
+ * left over after every sub-account is funded — never a stored row) or a
532
+ * specific sub-account, addressed by its `SubAccountId` (canon
533
+ * `account-balance-model.md` §5, §12).
534
+ */
535
+ type TransferEndpoint = "main" | SubAccountId$1;
536
+ /**
537
+ * Move money between two of the SAME Account's balances (canon §12). The
538
+ * backend resolves the Account from auth (v1 = one Account per user), so the
539
+ * input carries no `accountId` — only the from/to endpoints and the `Money`
540
+ * amount. One verb covers money in (`main → sub`), money out (`sub → main`),
541
+ * and `sub → sub`.
542
+ */
543
+ type TransferInput = {
544
+ readonly from: TransferEndpoint;
545
+ readonly to: TransferEndpoint;
546
+ readonly amount: Money$1;
547
+ };
548
+ /**
549
+ * Result of a `transfer`: the recomputed `available` (`balanceOf − Σ`), plus
550
+ * the updated source/destination sub-account rows. An endpoint that is `"main"`
551
+ * has no stored row, so its slot is `null`.
552
+ */
553
+ type TransferResult = {
554
+ readonly available: Money$1;
555
+ readonly from: SubAccount$1 | null;
556
+ readonly to: SubAccount$1 | null;
557
+ };
558
+ interface SubAccountPort {
559
+ create(input: CreateSubAccountInput): Effect.Effect<SubAccount$1, SubAccountError, never>;
560
+ get(input: SubAccountIdInput): Effect.Effect<SubAccount$1 | null, SubAccountError, never>;
561
+ list(input: {
562
+ readonly accountId: AccountId;
563
+ }): Effect.Effect<readonly SubAccount$1[], SubAccountError, never>;
564
+ rename(input: RenameSubAccountInput): Effect.Effect<SubAccount$1, SubAccountError, never>;
565
+ delete(input: SubAccountIdInput): Effect.Effect<void, SubAccountError, never>;
566
+ transfer(input: TransferInput): Effect.Effect<TransferResult, SubAccountError, never>;
567
+ }
568
+ //#endregion
569
+ //#region src/flows/types.d.ts
570
+ /**
571
+ * The full 14-port bundle that `assembleCapxulClient` (slice 5) consumes.
572
+ *
573
+ * Each per-flow factory in slices 2-4 takes a narrowed subset, e.g.
574
+ * `AuthFlowPorts = Pick<FlowPorts, "authClient" | "authCache" | "clock" | "telemetry">`.
575
+ * Slice 1 ships only the union; per Q6 each per-flow slice declares its
576
+ * own narrowed `Pick<FlowPorts, ...>` inside its flow file.
577
+ */
578
+ interface FlowPorts {
579
+ readonly authClient: AuthClientPort;
580
+ readonly authCache: AuthCachePort;
581
+ readonly identity: IdentityPort;
582
+ readonly smartAccount: SmartAccountPort;
583
+ readonly accountRead: AccountReadPort;
584
+ readonly subAccount: SubAccountPort;
585
+ readonly credentials: CredentialsPort;
586
+ readonly bootstrap: BootstrapPort;
587
+ readonly evmSigner: EvmSignerPort;
588
+ readonly clock: ClockPort;
589
+ readonly env: EnvPort;
590
+ readonly telemetry: TelemetryPort;
591
+ readonly transport: TransportPort;
592
+ readonly convexCall: ConvexCallPort;
593
+ }
594
+ /**
595
+ * Pre-resolved external signer + signed proof. The UI obtains this
596
+ * BEFORE prompting the user to verify (MetaMask popup, hardware-wallet
597
+ * confirm, etc.), then the consumer sends it to AuthFlow via the
598
+ * `SET_SIGNER` event between `idle` and `verifying`. AuthFlow assigns
599
+ * to `context.externalSigner` on the SET_SIGNER self-loop in either
600
+ * `idle` or `otp_requested`, then flows the value through to the
601
+ * invoked ProvisioningFlow child via `invoke.input.externalSigner`.
602
+ * The child's `branching` state inspects `context.signerAddress`
603
+ * (derived from `input.externalSigner?.address`) to route through
604
+ * `register_external` instead of `mint_openfort` when present.
605
+ *
606
+ * The signer's lifetime is the authenticated session — `clearAuthContext`
607
+ * (on SIGN_OUT → idle) and `clearErrorAndContext` (on error → RESET →
608
+ * idle) both wipe `context.externalSigner`. A subsequent sign-in cycle
609
+ * begins fresh; the consumer re-sends SET_SIGNER (or omits it for the
610
+ * Openfort fallback path). Reference:
611
+ * `docs/decisions/stage-3-external-signer-lifecycle.html` (Option C,
612
+ * locked 2026-05-17, supersedes the earlier factory-input shape).
613
+ *
614
+ * `signedProof` is an EIP-191 signed message proving the user controls
615
+ * the address. ProvisioningFlow does not verify the proof itself —
616
+ * verification is delegated to the indexer registration in Stage 4 when
617
+ * `IndexerPort.registerSafe` lands. For Stage 3 the field is recorded
618
+ * verbatim for trace fidelity.
619
+ *
620
+ * The type lives in this flows/types module (not in `@capxul/types`)
621
+ * because it is a flow-shape composite — `Address` + a freeform proof
622
+ * string — not a primitive brand. Per the Stage 3 plan's vocabulary
623
+ * convention, flow-shape composites stay co-located with their flow.
624
+ */
625
+ interface ExternalSigner {
626
+ readonly address: Address$1;
627
+ readonly signedProof: string;
628
+ }
629
+ //#endregion
630
+ //#region src/client/auth.d.ts
631
+ interface SignInOptions {
632
+ readonly signal?: AbortSignal;
633
+ }
634
+ type AuthMethodOptions = SignInOptions;
635
+ interface AuthMethods {
636
+ canSendOtp(input: {
637
+ readonly email: string;
638
+ }, options?: AuthMethodOptions): Promise<CapxulResult<CanSendOtpStatus>>;
639
+ signIn(input: {
640
+ readonly email: string;
641
+ }, options?: SignInOptions): Promise<CapxulResult<{
642
+ readonly sessionId: string;
643
+ readonly expiresAt: number;
644
+ }>>;
645
+ verifyOtp(input: {
646
+ readonly email: string;
647
+ readonly code: string;
648
+ readonly signer?: ExternalSigner;
649
+ }, options?: AuthMethodOptions): Promise<CapxulResult<Session>>;
650
+ signOut(options?: AuthMethodOptions): Promise<CapxulResult<void>>;
651
+ getSession(options?: AuthMethodOptions): Promise<CapxulResult<Session | null>>;
652
+ }
653
+ //#endregion
654
+ //#region src/client/smart-account.d.ts
655
+ interface SmartAccountMethods {
656
+ loadCurrent(options?: {
657
+ readonly signal?: AbortSignal;
658
+ }): Promise<CapxulResult<SmartAccount | null>>;
659
+ provision(input?: {
660
+ readonly externalSigner?: ExternalSigner;
661
+ }): Promise<CapxulResult<SmartAccount>>;
662
+ }
663
+ //#endregion
664
+ //#region src/client/identity.d.ts
665
+ interface IdentityMethods {
666
+ loadCurrent(options?: {
667
+ readonly signal?: AbortSignal;
668
+ }): Promise<CapxulResult<Profile | null>>;
669
+ }
670
+ //#endregion
671
+ //#region src/client/account.d.ts
672
+ type AccountStatus = {
673
+ readonly status: "notAuthenticated";
674
+ } | {
675
+ readonly status: "accountRequired";
676
+ readonly requirement: AccountRequirement;
677
+ readonly chainId: number;
678
+ } | {
679
+ readonly status: "accountProviderReady";
680
+ readonly requirement: AccountRequirement;
681
+ readonly chainId: number;
682
+ readonly source: AccountProviderSource;
683
+ readonly signerAddress: Address$1;
684
+ } | {
685
+ readonly status: "accountPrepared";
686
+ readonly requirement: AccountRequirement;
687
+ readonly account: SmartAccount$1;
688
+ readonly deployment: {
689
+ readonly status: "counterfactual";
690
+ };
691
+ } | {
692
+ readonly status: "accountReady";
693
+ readonly requirement: AccountRequirement;
694
+ readonly account: SmartAccount$1 | null;
695
+ readonly deployment: {
696
+ readonly status: "counterfactual";
697
+ } | {
698
+ readonly status: "deployed";
699
+ readonly deployedAt: SmartAccount$1["deployedAt"];
700
+ };
701
+ };
702
+ /**
703
+ * Public consumer-facing surface (issue #159 · AC1+AC3). Exactly two
704
+ * methods. `provision` and `deploySafe` are intentionally NOT here —
705
+ * they are advanced/testing-only and will live on
706
+ * `client._internal.account` when sibling issue #161 lands. Per
707
+ * `docs/canon/rules/public-surface.md`, the narrowing is enforced at
708
+ * both the type level (the `keyof AccountMethods` extract is exactly
709
+ * `"getStatus" | "ensureReady"`) and at runtime (the bundle returned
710
+ * here has those two own-keys and nothing else).
711
+ *
712
+ * Per `docs/canon/conventions/flow-internal-substrate.md`, the
713
+ * `AccountStatus` discriminant — including the variants this slice can
714
+ * only reach via `getStatus` (e.g. `accountPrepared`) — is the durable
715
+ * shape consumers depend on. Sibling #161 will extend `ensureReady` to
716
+ * advance the ladder past `accountProviderReady` and from
717
+ * `accountPrepared` to `accountReady(deployed)`; until then, the type
718
+ * surface is stable and the runtime fixed-point is documented.
719
+ */
720
+ interface AccountMethods {
721
+ /**
722
+ * Read-only status inspection. Safe to call anytime.
723
+ */
724
+ getStatus(): Promise<CapxulResult<AccountStatus>>;
725
+ /**
726
+ * Normal app entry point. Idempotent.
727
+ *
728
+ * Per #161, `ensureReady` now advances the ladder upward:
729
+ * - `accountProviderReady → accountReady` via `_internal.account.provision`
730
+ * - `accountPrepared → accountReady(deployed)` via
731
+ * `_internal.account.deploySafe` (when `requirement === "deployed"`
732
+ * and deploy deps are configured).
733
+ */
734
+ ensureReady(): Promise<CapxulResult<AccountStatus>>;
735
+ /**
736
+ * Internal advanced surface (#161 · AC1). Reserved for the rebuild's
737
+ * own `ensureReady` upward transitions and for testing harnesses;
738
+ * consumers MUST NOT depend on this in production. Tagged
739
+ * `@internal-use` per `.claude/rules/flow-internal-substrate.md`.
740
+ *
741
+ * @internal-use
742
+ */
743
+ readonly _internal: AccountInternalSurface;
744
+ }
745
+ /**
746
+ * Internal `provision` + `deploySafe` arms exposed at
747
+ * `client._internal.account` (#161). Each returns `Promise<CapxulResult<T>>`
748
+ * with the same error catalog the public methods use.
749
+ *
750
+ * @internal-use
751
+ */
752
+ interface AccountInternalSurface {
753
+ provision(): Promise<CapxulResult<SmartAccount$1>>;
754
+ deploySafe(): Promise<CapxulResult<SmartAccount$1>>;
755
+ }
756
+ //#endregion
757
+ //#region src/client/accounts.d.ts
758
+ interface AccountsMethods {
759
+ read(options?: {
760
+ readonly signal?: AbortSignal;
761
+ }): Promise<CapxulResult<Account$1>>;
762
+ }
763
+ /**
764
+ * Faucet surface (dev-only). Deliberately OFF the public `AccountsMethods`;
765
+ * reachable only via `client._internal.accounts` (production-surface-policy.md).
766
+ * The reference CLI uses it behind a test-env gate — consumers never see `fund`.
767
+ */
768
+ interface AccountsFaucetMethods {
769
+ fund(amount: Money$1, options?: {
770
+ readonly signal?: AbortSignal;
771
+ }): Promise<CapxulResult<{
772
+ readonly txHash: string;
773
+ }>>;
774
+ }
775
+ //#endregion
776
+ //#region src/client/sub-accounts.d.ts
777
+ interface SubAccountsMethods {
778
+ create(accountId: AccountId, input: {
779
+ readonly name: string;
780
+ }, options?: {
781
+ readonly signal?: AbortSignal;
782
+ }): Promise<CapxulResult<SubAccount$1>>;
783
+ get(subAccountId: SubAccountId$1, options?: {
784
+ readonly signal?: AbortSignal;
785
+ }): Promise<CapxulResult<SubAccount$1 | null>>;
786
+ list(accountId: AccountId, options?: {
787
+ readonly signal?: AbortSignal;
788
+ }): Promise<CapxulResult<readonly SubAccount$1[]>>;
789
+ rename(subAccountId: SubAccountId$1, name: string, options?: {
790
+ readonly signal?: AbortSignal;
791
+ }): Promise<CapxulResult<SubAccount$1>>;
792
+ delete(subAccountId: SubAccountId$1, options?: {
793
+ readonly signal?: AbortSignal;
794
+ }): Promise<CapxulResult<void>>;
795
+ transfer(input: TransferInput, options?: {
796
+ readonly signal?: AbortSignal;
797
+ }): Promise<CapxulResult<TransferResult>>;
798
+ }
799
+ //#endregion
800
+ //#region src/client/org-spend-gate.d.ts
801
+ type SpendGateRecipients = "anyone" | readonly Address$1[];
802
+ type SpendGateSubAccountScope = {
803
+ readonly scope: "all";
804
+ } | {
805
+ readonly scope: "only";
806
+ readonly subAccountIds: readonly SubAccountId$1[];
807
+ };
808
+ //#endregion
809
+ //#region src/ports/org.d.ts
810
+ type CreateOrgPortInput = {
811
+ readonly input: CreateOrgInput;
812
+ };
813
+ type ReadOrgTreasuryInput = {
814
+ readonly orgId: OrgId$1;
815
+ };
816
+ type ListOrgsInput = Record<never, never>;
817
+ type ListOrgRolesInput = {
818
+ readonly orgId: OrgId$1;
819
+ };
820
+ type ListOrgMembersInput = {
821
+ readonly orgId: OrgId$1;
822
+ };
823
+ type InviteOrgMemberInput = {
824
+ readonly orgId: OrgId$1;
825
+ readonly input: InviteMemberInput;
826
+ };
827
+ type DetectPendingOrgInvitationsInput = Record<never, never>;
828
+ type DetectPendingOrgInvitationsResult$1 = {
829
+ readonly matched: readonly OrgId$1[];
830
+ };
831
+ type DeployOrgRolesInput = {
832
+ readonly orgId: OrgId$1;
833
+ };
834
+ type OrgRolesDeploymentResult = {
835
+ readonly orgId: OrgId$1;
836
+ readonly roles: readonly RoleView[];
837
+ };
838
+ type GrantOrgRoleInput = {
839
+ readonly orgId: OrgId$1;
840
+ readonly input: AssignRoleInput;
841
+ };
842
+ type RevokeOrgRoleInput = {
843
+ readonly orgId: OrgId$1;
844
+ readonly input: RemoveMemberInput;
845
+ };
846
+ type OrgSpendAuthority = {
847
+ readonly activeMember: boolean;
848
+ readonly subAccountBalanceRaw: string;
849
+ readonly recipients: SpendGateRecipients;
850
+ readonly subAccounts: SpendGateSubAccountScope;
851
+ readonly perTxCapRaw?: string | null;
852
+ readonly perDayCapRaw?: string | null;
853
+ readonly spentTodayRaw?: string | null;
854
+ readonly role?: string;
855
+ };
856
+ type ReadOrgSpendAuthorityInput = {
857
+ readonly orgId: OrgId$1;
858
+ readonly input: OrgSpendInput;
859
+ readonly amountRaw: string;
860
+ };
861
+ type SubmitOrgSpendInput = {
862
+ readonly orgId: OrgId$1;
863
+ readonly input: OrgSpendInput;
864
+ readonly amountRaw: string;
865
+ readonly authority: OrgSpendAuthority;
866
+ };
867
+ declare const OrgError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
868
+ readonly _tag: "OrgError";
869
+ } & Readonly<A>;
870
+ declare class OrgError extends OrgError_base<{
871
+ readonly operation: string;
872
+ readonly publicCode: CapxulErrorCode;
873
+ readonly publicError: CapxulError;
874
+ readonly cause: unknown;
875
+ readonly details?: CapxulErrorDetails;
876
+ }> {}
877
+ /**
878
+ * Live org seam. `createOrg` runs the SDK-orchestrated deploy (D10) and returns
879
+ * the created `OrgView` (its treasury is the real M2 `Account` over the Org
880
+ * Safe — $0 at creation, D3). `readTreasury` pulls the org's Account via RPC
881
+ * `balanceOf` (D3). `listOrgs` lists the orgs the authenticated user belongs to.
882
+ */
883
+ interface OrgPort {
884
+ createOrg(input: CreateOrgPortInput): Effect.Effect<OrgView, OrgError, never>;
885
+ readTreasury(input: ReadOrgTreasuryInput): Effect.Effect<Account$1, OrgError, never>;
886
+ listOrgs(input: ListOrgsInput): Effect.Effect<readonly OrgView[], OrgError, never>;
887
+ listRoles(input: ListOrgRolesInput): Effect.Effect<readonly RoleView[], OrgError, never>;
888
+ listMembers(input: ListOrgMembersInput): Effect.Effect<readonly MemberView[], OrgError, never>;
889
+ inviteMember(input: InviteOrgMemberInput): Effect.Effect<MemberView, OrgError, never>;
890
+ detectAndAcceptPendingInvitations(input: DetectPendingOrgInvitationsInput): Effect.Effect<DetectPendingOrgInvitationsResult$1, OrgError, never>;
891
+ }
892
+ interface OrgRolesDeploymentPort {
893
+ deployRoles(input: DeployOrgRolesInput): Effect.Effect<OrgRolesDeploymentResult, OrgError, never>;
894
+ grantRole(input: GrantOrgRoleInput): Effect.Effect<MemberView, OrgError, never>;
895
+ revokeRole(input: RevokeOrgRoleInput): Effect.Effect<void, OrgError, never>;
896
+ }
897
+ interface OrgSpendPort {
898
+ readSpendAuthority(input: ReadOrgSpendAuthorityInput): Effect.Effect<OrgSpendAuthority, OrgError, never>;
899
+ submitSpend(input: SubmitOrgSpendInput): Effect.Effect<OrgSpendResult, OrgError, never>;
900
+ }
901
+ //#endregion
902
+ //#region src/client/org.d.ts
903
+ /**
904
+ * A member's lifecycle status (D9 — unified `Member` with status
905
+ * `pending | active | revoked | expired`). `pending` = invited (incl. a
906
+ * non-user emailed into existence) but not yet a provisioned member with an
907
+ * on-chain grant; `active` = on-chain role granted; `revoked` = offboarded
908
+ * (on-chain REVOKE fired); `expired` = pending invitation timed out.
909
+ */
910
+ type MemberStatus = "pending" | "pending_safe" | "pending_grant" | "active" | "revoked" | "expired";
911
+ /**
912
+ * One Org you belong to (canon §C1 "Org list" — name, role, balance).
913
+ * `role` is the member's role label within THIS org. `treasury` is the M2
914
+ * `Account` over the Org Safe (D3). `handle` is the globally-unique,
915
+ * normalized org handle (D10a). Pure record of brand-typed fields — not a
916
+ * brand.
917
+ */
918
+ type OrgView = {
919
+ readonly id: OrgId$1;
920
+ readonly name: string;
921
+ readonly handle: string;
922
+ readonly safeAddress: Address$1; /** The viewing member's own role label within this org. */
923
+ readonly role: string; /** The Org treasury — the real M2 Account over the Org Safe (D3). */
924
+ readonly treasury: Account$1;
925
+ };
926
+ /**
927
+ * One member of an Org (canon §C1 "Members" — name/email, role, status; D7/D8).
928
+ * `personalSafeAddress` is the member-identity key (D7 — Safe-as-identity); it
929
+ * is `null` while the member is still `pending` (emailed into existence but not
930
+ * yet provisioned a personal Safe). `email` is the universal entry point (D8).
931
+ */
932
+ type MemberView = {
933
+ readonly orgId: OrgId$1;
934
+ readonly email: Email;
935
+ readonly name: string | null; /** Member-identity key (D7). `null` until the invitee provisions a Safe. */
936
+ readonly personalSafeAddress: Address$1 | null; /** The member's role label (maps deterministically to the on-chain `roleKey`, D9). */
937
+ readonly role: string;
938
+ readonly roleKey: RoleKey$1 | null;
939
+ readonly status: MemberStatus;
940
+ readonly grantTxHash: string | null;
941
+ readonly revokeTxHash: string | null;
942
+ };
943
+ /**
944
+ * A role's on-chain Level-1 spend cap (D4/D5 — physically enforced via Zodiac
945
+ * Roles + Allowance). `perTx` / `perDay` are `Money`; `toRecipients` scopes the
946
+ * allowed recipient set. Omitting a field means "unbounded on that axis"
947
+ * (the Owner role).
948
+ */
949
+ type RoleSpendCap = {
950
+ readonly perTx?: Money$1;
951
+ readonly perDay?: Money$1;
952
+ readonly toRecipients?: "anyone" | readonly Address$1[];
953
+ };
954
+ /**
955
+ * The Capxul-owned Role DSL definition (D4). `label` becomes the sticky
956
+ * bytes32 `roleKey` on-chain. `spend` compiles to Level-1 on-chain Zodiac
957
+ * conditions; `subAccounts` + `canManage*` compile to Level-2 off-chain Convex
958
+ * guards (D5).
959
+ */
960
+ type RoleDefinition = {
961
+ readonly label: string;
962
+ readonly spend?: RoleSpendCap;
963
+ readonly subAccounts?: {
964
+ readonly scope: "all" | readonly SubAccountId$1[];
965
+ };
966
+ readonly canManageMembers?: boolean;
967
+ readonly canManageRoles?: boolean;
968
+ };
969
+ /**
970
+ * One role seeded on an Org (canon §C1 "Roles" — label + caps; D4/D6).
971
+ * `roleKey` is the on-chain bytes32 role key derived from the label. `definition`
972
+ * is the full Role DSL entry.
973
+ */
974
+ type RoleView = {
975
+ readonly orgId: OrgId$1;
976
+ readonly label: string;
977
+ readonly roleKey: RoleKey$1;
978
+ readonly definition: RoleDefinition;
979
+ };
980
+ /** Built-in role templates that seed a new Org at creation (D6). */
981
+ type OrgTemplate = "Solo" | "Startup" | "Custom";
982
+ /**
983
+ * Input to `capxul.createOrg` (S1, D10a, D14). `name` is the display name;
984
+ * `handle` is the globally-unique normalized handle (`^[a-z0-9-]{3,32}$`, D10a);
985
+ * `template` seeds the initial role set (D6); `country` is stored unvalidated
986
+ * (D14 — KYB deferred). For `template: "Custom"`, `roles` carries the authored
987
+ * `RoleDefinition[]`.
988
+ */
989
+ type CreateOrgInput = {
990
+ readonly name: string;
991
+ readonly handle: string;
992
+ readonly template: OrgTemplate;
993
+ readonly country?: string;
994
+ readonly roles?: readonly RoleDefinition[];
995
+ };
996
+ /**
997
+ * Input to `org(orgId).invite` (S3, D8). Email is the universal entry point —
998
+ * inviting an address that is not yet a Capxul user auto-creates a `pending`
999
+ * membership that resolves on sign-in (the virality loop). `role` names the
1000
+ * role label the invitee is granted on accept.
1001
+ */
1002
+ type InviteMemberInput = {
1003
+ readonly email: string;
1004
+ readonly role: string;
1005
+ };
1006
+ /**
1007
+ * Input to `org(orgId).removeMember` (S3, D8). Keyed on the member's personal
1008
+ * Safe address (D7 — Safe-as-identity). Drives the on-chain REVOKE + Convex
1009
+ * mirror.
1010
+ */
1011
+ type RemoveMemberInput = {
1012
+ readonly memberSafeAddress: Address$1;
1013
+ };
1014
+ /**
1015
+ * Input to `org(orgId).assignRole` (S3, D7/D9). Keyed on the member's personal
1016
+ * Safe address (D7). Drives the on-chain GRANT + Convex mirror; the `role`
1017
+ * label maps deterministically to the on-chain `roleKey`.
1018
+ */
1019
+ type AssignRoleInput = {
1020
+ readonly memberSafeAddress: Address$1;
1021
+ readonly role: string;
1022
+ };
1023
+ /**
1024
+ * Input to `org(orgId).spend` (S4, capstone, D5). A member spends `amount` from
1025
+ * a scoped sub-account `from` to `to`, gated Level 1 (Zodiac cap) + Level 2
1026
+ * (envelope scope/balance). One UserOp: signer → personal Safe → Org Roles
1027
+ * modifier → `CapxulPayments.send`.
1028
+ */
1029
+ type OrgSpendInput = {
1030
+ /** The sub-account (envelope) the spend draws from (Level-2 scope, D5). */readonly from: SubAccountId$1;
1031
+ readonly to: Address$1;
1032
+ readonly amount: Money$1;
1033
+ };
1034
+ /** Result of a settled Org spend — the settling transaction hash (S4). */
1035
+ type OrgSpendResult = {
1036
+ readonly txHash: string;
1037
+ };
1038
+ type DetectPendingOrgInvitationsResult = {
1039
+ readonly matched: readonly OrgId$1[];
1040
+ };
1041
+ /**
1042
+ * Entity-scoped Org method bundle, returned by `capxul.org(orgId)`. Every
1043
+ * method names the entity implicitly via the closed-over `orgId` (D13 — no
1044
+ * stateful active context). `treasury()` returns the real M2 `Account` over
1045
+ * the Org Safe (D3).
1046
+ */
1047
+ interface OrgScopedMethods {
1048
+ /** The Org treasury — the real M2 Account over the Org Safe (D3). */
1049
+ treasury(options?: {
1050
+ readonly signal?: AbortSignal;
1051
+ }): Promise<CapxulResult<Account$1>>;
1052
+ members(options?: {
1053
+ readonly signal?: AbortSignal;
1054
+ }): Promise<CapxulResult<readonly MemberView[]>>;
1055
+ roles(options?: {
1056
+ readonly signal?: AbortSignal;
1057
+ }): Promise<CapxulResult<readonly RoleView[]>>;
1058
+ deployRoles(options?: {
1059
+ readonly signal?: AbortSignal;
1060
+ }): Promise<CapxulResult<readonly RoleView[]>>;
1061
+ invite(input: InviteMemberInput, options?: {
1062
+ readonly signal?: AbortSignal;
1063
+ }): Promise<CapxulResult<MemberView>>;
1064
+ removeMember(input: RemoveMemberInput, options?: {
1065
+ readonly signal?: AbortSignal;
1066
+ }): Promise<CapxulResult<void>>;
1067
+ assignRole(input: AssignRoleInput, options?: {
1068
+ readonly signal?: AbortSignal;
1069
+ }): Promise<CapxulResult<MemberView>>;
1070
+ spend(input: OrgSpendInput, options?: {
1071
+ readonly signal?: AbortSignal;
1072
+ }): Promise<CapxulResult<OrgSpendResult>>;
1073
+ }
1074
+ type OrgsMethod = {
1075
+ (options?: {
1076
+ readonly signal?: AbortSignal;
1077
+ }): Promise<CapxulResult<readonly OrgView[]>>;
1078
+ detectAndAcceptPendingInvitations(options?: {
1079
+ readonly signal?: AbortSignal;
1080
+ }): Promise<CapxulResult<DetectPendingOrgInvitationsResult>>;
1081
+ };
1082
+ /**
1083
+ * Top-level Org method bundle, exposed at `client.org` / `client.orgs` /
1084
+ * `client.createOrg`. `org(orgId)` resolves the entity-scoped bundle (D13).
1085
+ */
1086
+ interface OrgMethods {
1087
+ createOrg(input: CreateOrgInput, options?: {
1088
+ readonly signal?: AbortSignal;
1089
+ }): Promise<CapxulResult<OrgView>>;
1090
+ readonly orgs: OrgsMethod;
1091
+ /** Resolve the entity-scoped bundle for a specific Org (D13). */
1092
+ org(orgId: OrgId$1): OrgScopedMethods;
1093
+ }
1094
+ //#endregion
1095
+ //#region src/client/create-capxul-client.d.ts
1096
+ interface CapxulClient {
1097
+ readonly auth: AuthMethods;
1098
+ readonly smartAccount: SmartAccountMethods;
1099
+ readonly identity: IdentityMethods;
1100
+ /**
1101
+ * Consumer-facing account readiness surface (issue #159 · AC1+AC3).
1102
+ * Exactly `getStatus` + `ensureReady`; the `_internal.account`
1103
+ * namespace with `provision` + `deploySafe` lands in sibling #161.
1104
+ */
1105
+ readonly account: AccountMethods;
1106
+ /**
1107
+ * Consumer-facing logical Account money read (M2 Slice S1a · #265).
1108
+ * Returns `{ balance, available }` as `Money` — never wei or token units.
1109
+ */
1110
+ readonly accounts: AccountsMethods;
1111
+ /** Sub-account lifecycle (M2 Slice S2a · #267). Transfer lands in S2b. */
1112
+ readonly subAccounts: SubAccountsMethods;
1113
+ /**
1114
+ * Organization domain surface (canon `org-domain-model.md` §C2/§C3, D13).
1115
+ * `createOrg(input)` creates an Org; `orgs()` lists the Orgs you belong to;
1116
+ * `org(orgId)` resolves the entity-scoped bundle (treasury / members / roles
1117
+ * / invite / removeMember / assignRole / spend). Explicit entity scoping —
1118
+ * NO stateful active context (D13). RED until the S1→S4 slices fill it.
1119
+ */
1120
+ readonly createOrg: OrgMethods["createOrg"];
1121
+ readonly orgs: OrgMethods["orgs"];
1122
+ readonly org: OrgMethods["org"];
1123
+ /** Resolved bootstrap for this client instance (chain, auth URLs, etc.). */
1124
+ readonly bootstrap: BootstrapResolution;
1125
+ /**
1126
+ * Internal observation namespace. Consumers MUST NOT drive the actor
1127
+ * directly — use the method bundles instead.
1128
+ *
1129
+ * @internal-use
1130
+ */
1131
+ readonly _internal: {
1132
+ readonly authActor: AuthFlowObserver;
1133
+ /**
1134
+ * Dev-only faucet bundle (production-surface-policy.md). `fund` lives here,
1135
+ * NOT on the public `client.accounts` surface.
1136
+ */
1137
+ readonly accounts: AccountsFaucetMethods;
1138
+ readonly close?: () => Promise<void>;
1139
+ };
1140
+ }
1141
+ interface CreateCapxulClientInput {
1142
+ /**
1143
+ * The 12-port `FlowPorts` bundle. The factory narrows this to the
1144
+ * 3-port AuthFlow subset (`authClient`, `clock`, `telemetry`) for
1145
+ * the flow internally, and uses additional ports (`identity`,
1146
+ * `smartAccount`) for the method bundles.
1147
+ */
1148
+ readonly ports: FlowPorts;
1149
+ /**
1150
+ * Bootstrap resolution for this client instance. The factory closes over
1151
+ * `bootstrap.chainId` internally; consumers do not pass a standalone
1152
+ * chainId and no method boundary accepts one.
1153
+ */
1154
+ readonly bootstrap: BootstrapResolution;
1155
+ /**
1156
+ * Optional AuthCachePort. When omitted, `detectAuthCacheAdapter()` selects
1157
+ * the appropriate per-environment adapter (Browser/FileSystem/InMemory).
1158
+ */
1159
+ readonly authCache?: AuthCachePort;
1160
+ /**
1161
+ * Optional AbortSignal reserved for callers that coordinate client lifetime.
1162
+ */
1163
+ readonly signal?: AbortSignal;
1164
+ /**
1165
+ * OTP TTL window in ms. Default 300_000 (5 min).
1166
+ */
1167
+ readonly otpTtlMs?: number;
1168
+ /**
1169
+ * Optional per-call timeout for invoked auth requests.
1170
+ */
1171
+ readonly invokeTimeoutMs?: number;
1172
+ /**
1173
+ * Init-time account readiness target (issue #159 · AC4). The factory
1174
+ * closes over this so `client.account.{getStatus,ensureReady}` don't
1175
+ * need to take a per-call requirement arg. REQUIRED — there is no
1176
+ * hidden default. Consumers building flows that never need a smart
1177
+ * account pass `"none"`; flows that want a counterfactual deposit
1178
+ * address pass `"counterfactual"`; flows that need an on-chain Safe
1179
+ * pass `"deployed"` (deploy path lands in sibling #161).
1180
+ */
1181
+ readonly requirement: AccountRequirement;
1182
+ /**
1183
+ * Consumer-held signer (backend-orchestrated-deploy.md). Required for
1184
+ * `requirement: "deployed"` flows: `provision` reads `getAddress()` and the
1185
+ * deploy path signs the backend's SafeOp digest via `signUserOpHash()`. The
1186
+ * backend orchestrates build + gas + paymaster + submit — the client never
1187
+ * holds an RPC URL, a gas-sponsorship policy, or a bundler.
1188
+ */
1189
+ readonly signer?: CapxulSigner;
1190
+ /**
1191
+ * Optional live Org-deploy lane (canon D10 SDK-orchestrated Org Safe deploy +
1192
+ * D3 RPC treasury). When supplied, `client.createOrg` / `org(id).treasury`
1193
+ * run the live path (real deploy + on-chain balance); when omitted, the
1194
+ * hermetic `$0` path runs (a fresh Org has no on-chain funds). The adapter
1195
+ * that CONSTRUCTS this port (deployer key + RPC + authenticated Convex seam)
1196
+ * is wired by the CLI deploy-stack; the factory only threads it through.
1197
+ */
1198
+ readonly orgDeploymentPort?: OrgPort;
1199
+ /** Locked D6 data-port name. Prefer over `orgDeploymentPort` in new code. */
1200
+ readonly orgPort?: OrgPort;
1201
+ /** S2 deploy/grant/revoke port. S2 uses deploy; S3 adds grant/revoke. */
1202
+ readonly orgRolesDeploymentPort?: OrgRolesDeploymentPort;
1203
+ /** S4 treasury-spend authority + submit port. */
1204
+ readonly orgSpendPort?: OrgSpendPort;
1205
+ readonly orgDeploymentConfig?: SafeDeploymentConfig;
1206
+ }
1207
+ declare function assembleCapxulClient(input: CreateCapxulClientInput): CapxulClient;
1208
+ //#endregion
1209
+ //#region src/production.d.ts
1210
+ type ProductionRuntime = "browser" | "node";
1211
+ type ProductionAdapterClose = () => Promise<void>;
1212
+ interface ProductionAdapterInput {
1213
+ readonly publishableKey: string;
1214
+ readonly origin?: string;
1215
+ readonly bootstrapBaseUrl?: string;
1216
+ readonly runtime?: ProductionRuntime;
1217
+ readonly authCache?: AuthCachePort;
1218
+ readonly telemetry?: TelemetryPort;
1219
+ readonly evmSigner?: EvmSignerPort;
1220
+ readonly fetch?: typeof fetch;
1221
+ readonly signal?: AbortSignal;
1222
+ readonly otpTtlMs?: number;
1223
+ readonly invokeTimeoutMs?: number;
1224
+ /**
1225
+ * Init-time account readiness target (issue #159 · AC4). Threaded into
1226
+ * `assembleCapxulClient` so `client.account.{getStatus,ensureReady}` reflect
1227
+ * the consumer's chosen requirement. Optional — defaults to `"none"` (SDK
1228
+ * publish readiness · I3) so `createCapxulClient({ publishableKey })` works
1229
+ * with no account lane.
1230
+ */
1231
+ readonly requirement?: AccountRequirement;
1232
+ /**
1233
+ * Consumer-held signer (backend-orchestrated-deploy.md). Required for
1234
+ * `requirement: "deployed"` flows: `provision` reads `getAddress()` and the
1235
+ * deploy path signs the backend's SafeOp digest via `signUserOpHash()`. The
1236
+ * backend orchestrates build + gas + paymaster + submit — the client never
1237
+ * holds an RPC URL, a gas-sponsorship policy, or a bundler.
1238
+ */
1239
+ readonly signer?: CapxulSigner;
1240
+ /**
1241
+ * Optional live Org-deploy lane (canon D10 SDK-orchestrated Org Safe deploy +
1242
+ * D3 RPC treasury). Supplied as a FACTORY rather than a pre-built port because
1243
+ * the live `OrgPort` (`LiveOrgDeploymentAdapter`) talks to the backend
1244
+ * `org.createOrg` mutation through the SAME authenticated Convex seam the rest
1245
+ * of the client uses (`tokenProvider → getConvexJwt → ConvexCallAdapter`),
1246
+ * which only exists AFTER `createProductionAdapters` resolves bootstrap. The
1247
+ * factory receives that resolved `ConvexCallPort` and returns the port; the
1248
+ * CLI deploy-stack builds the factory from the deployer key + RPC (the same
1249
+ * env/signer as `safeDeploymentPort`). When omitted, the hermetic `$0` path
1250
+ * runs (a fresh Org has no on-chain funds).
1251
+ */
1252
+ readonly orgDeploymentPortFactory?: (convex: ConvexCallPort) => OrgPort & OrgRolesDeploymentPort & OrgSpendPort;
1253
+ readonly orgDeploymentConfig?: SafeDeploymentConfig;
1254
+ }
1255
+ interface ProductionAdapters {
1256
+ readonly ports: FlowPorts;
1257
+ readonly bootstrap: BootstrapResolution;
1258
+ readonly close: ProductionAdapterClose;
1259
+ }
1260
+ declare function createCapxulClient(input: ProductionAdapterInput): Promise<CapxulResult<CapxulClient>>;
1261
+ //#endregion
1262
+ export { type Account, type AccountMethods, type AccountProvider, type AccountProviderSource, type AccountRequirement, type AccountStatus, type AccountsMethods, type Address, type AssignRoleInput, type AuthMethods, type AuthSession, type AuthUserId, type CapxulClient, type CapxulResult, type CapxulSigner, type CreateCapxulClientInput, type CreateOrgInput, type DetectPendingOrgInvitationsResult, type Eip1193Provider, type Eip1193RequestProvider, type IdentityMethods, type InviteMemberInput, type MemberStatus, type MemberView, type Money, type OrgId, type OrgMethods, type OrgScopedMethods, type OrgSpendInput, type OrgSpendResult, type OrgTemplate, type OrgView, type ProductionAdapterClose, type ProductionAdapterInput, type ProductionAdapters, type ProductionRuntime, type Profile, type RemoveMemberInput, type RoleDefinition, type RoleKey, type RoleSpendCap, type RoleView, type Session, type SmartAccount, type SmartAccountMethods, type SubAccount, type SubAccountId, type SubAccountsMethods, type TransferEndpoint, type TransferInput, type TransferResult, assembleCapxulClient, createCapxulClient, eip1193AccountProvider, injectedWalletSigner, localPrivateKeyAccountProvider, openfortEmbeddedAccountProvider };
1263
+ //# sourceMappingURL=index.d.mts.map