@ixo/editor 3.0.0-beta.10 → 3.0.0-beta.12

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.
@@ -0,0 +1,406 @@
1
+ import { r as FlowNode, F as FlowNodeAuthzExtension, p as FlowNodeRuntimeState, J as IxoEditorType, S as SignedCapability, B as CreateRootDelegationParams, t as StoredDelegation, G as CreateDelegationParams, H as CreateInvocationParams, w as InvocationResult, x as ExecutionWithInvocationResult, s as UcanCapability, y as DelegationChainValidationResult, z as FindProofsResult, M as MigrationReport, U as UcanDelegationStore, l as InvocationStore, E as EvaluationStatus, C as Capability, a as CapabilityValidationResult } from './index-BE746hd_.mjs';
2
+ import { Delegation } from '@ixo/ucan';
3
+ import { Doc, Map } from 'yjs';
4
+
5
+ declare const buildAuthzFromProps: (props: Record<string, any>) => FlowNodeAuthzExtension;
6
+ declare const buildFlowNodeFromBlock: (block: any) => FlowNode;
7
+
8
+ interface FlowRuntimeStateManager {
9
+ get: (nodeId: string) => FlowNodeRuntimeState;
10
+ update: (nodeId: string, updates: Partial<FlowNodeRuntimeState>) => void;
11
+ }
12
+ declare const createRuntimeStateManager: (editor?: IxoEditorType | null) => FlowRuntimeStateManager;
13
+ /**
14
+ * Clears runtime and invocations from a Y.Doc.
15
+ * Used when cloning a flow as a template — the new document should
16
+ * carry only configuration (intent), not execution history.
17
+ */
18
+ declare function clearRuntimeForTemplateClone(yDoc: Doc): void;
19
+
20
+ interface DelegationStore {
21
+ get: (capabilityId: string) => SignedCapability | null;
22
+ set: (capability: SignedCapability) => void;
23
+ remove: (capabilityId: string) => void;
24
+ getRoot: () => SignedCapability | null;
25
+ setRootId: (capabilityId: string) => void;
26
+ getAll: () => SignedCapability[];
27
+ has: (capabilityId: string) => boolean;
28
+ }
29
+ /**
30
+ * Create a delegation store backed by Y.Map
31
+ */
32
+ declare const createDelegationStore: (yMap: Map<any>) => DelegationStore;
33
+ /**
34
+ * Create an in-memory delegation store (for testing or when Y.Map unavailable)
35
+ */
36
+ declare const createMemoryDelegationStore: () => DelegationStore;
37
+
38
+ interface CapabilityGrant {
39
+ raw: string;
40
+ with?: string;
41
+ audience?: string;
42
+ expiresAt?: number;
43
+ action?: string;
44
+ }
45
+ type DerivedCapability = CapabilityGrant;
46
+ interface UCANManager {
47
+ loadParentCapability: (capability: string) => Promise<CapabilityGrant>;
48
+ deriveNodeCapability: (parent: CapabilityGrant, nodeId: string, actorDid: string) => Promise<DerivedCapability>;
49
+ validateDerivedCapability: (derived: DerivedCapability, nodeId: string, actorDid: string) => Promise<void>;
50
+ }
51
+ declare class SimpleUCANManager implements UCANManager {
52
+ loadParentCapability(capability: string): Promise<CapabilityGrant>;
53
+ deriveNodeCapability(parent: CapabilityGrant, nodeId: string, actorDid: string): Promise<DerivedCapability>;
54
+ validateDerivedCapability(derived: DerivedCapability): Promise<void>;
55
+ }
56
+
57
+ /**
58
+ * UCAN Service using @ixo/ucan directly
59
+ *
60
+ * This service provides a high-level API for:
61
+ * - Creating and managing delegations (CAR format)
62
+ * - Creating and validating invocations
63
+ * - Executing actions with invocation-based authorization
64
+ * - Migrating legacy delegations
65
+ *
66
+ * The host app only needs to provide the signer (private key) after PIN decryption.
67
+ * All UCAN operations are performed using @ixo/ucan directly.
68
+ */
69
+
70
+ /**
71
+ * Signer session scope type
72
+ */
73
+ type SignerSessionScope = 'session' | 'operation';
74
+ /**
75
+ * Signer session returned by createSignerSession
76
+ */
77
+ interface SignerSessionInfo {
78
+ sessionId: string;
79
+ did: string;
80
+ publicKey: string;
81
+ keyId: string;
82
+ expiresAt: number;
83
+ scope: SignerSessionScope;
84
+ }
85
+ /**
86
+ * Handler functions for getting signers from the host application
87
+ * The host app handles PIN decryption and key management
88
+ */
89
+ interface UcanServiceHandlers {
90
+ /**
91
+ * Get a signer for the given DID after PIN verification
92
+ * The host app decrypts the private key using the PIN
93
+ *
94
+ * @returns The private key in multibase format (for parseSigner)
95
+ * @deprecated Prefer createSignerSession for better security
96
+ */
97
+ getPrivateKey?: (params: {
98
+ did: string;
99
+ didType: 'entity' | 'user';
100
+ entityRoomId?: string;
101
+ pin: string;
102
+ }) => Promise<string>;
103
+ /**
104
+ * Get a signer from mnemonic (alternative to getPrivateKey)
105
+ * The host app retrieves and decrypts the mnemonic using the PIN
106
+ *
107
+ * @returns The mnemonic phrase
108
+ * @deprecated Prefer createSignerSession for better security
109
+ */
110
+ getMnemonic?: (params: {
111
+ did: string;
112
+ didType: 'entity' | 'user';
113
+ entityRoomId?: string;
114
+ pin: string;
115
+ }) => Promise<string>;
116
+ /**
117
+ * Create a signer session that can be used for multiple sign operations.
118
+ * The host app keeps the key material secure; the editor only receives an opaque handle.
119
+ *
120
+ * @param params.scope - 'session' for multiple operations, 'operation' for one-time use
121
+ * @param params.ttlSeconds - Time-to-live for session scope (default: 300, max: 3600)
122
+ */
123
+ createSignerSession?: (params: {
124
+ did: string;
125
+ didType: 'entity' | 'user';
126
+ entityRoomId?: string;
127
+ pin: string;
128
+ scope: SignerSessionScope;
129
+ ttlSeconds?: number;
130
+ }) => Promise<SignerSessionInfo>;
131
+ /**
132
+ * Sign data using an existing session.
133
+ * For 'operation' scope, the session is automatically invalidated after this call.
134
+ */
135
+ signWithSession?: (params: {
136
+ sessionId: string;
137
+ data: string;
138
+ algorithm?: 'Ed25519';
139
+ }) => Promise<{
140
+ signature: string;
141
+ algorithm: 'Ed25519';
142
+ keyId: string;
143
+ }>;
144
+ /**
145
+ * Release a session before it expires.
146
+ * Safe to call on already-released or expired sessions.
147
+ */
148
+ releaseSignerSession?: (params: {
149
+ sessionId: string;
150
+ }) => Promise<{
151
+ released: boolean;
152
+ reason?: string;
153
+ }>;
154
+ /**
155
+ * Create a delegation directly in the host app.
156
+ * The host handles all signing internally using session-based signing.
157
+ * This is the preferred approach for security.
158
+ */
159
+ createDelegationWithSession?: (params: {
160
+ sessionId: string;
161
+ audience: string;
162
+ capabilities: Array<{
163
+ can: string;
164
+ with: string;
165
+ nb?: Record<string, unknown>;
166
+ }>;
167
+ proofs?: string[];
168
+ expiration?: number;
169
+ }) => Promise<{
170
+ cid: string;
171
+ delegation: string;
172
+ }>;
173
+ /**
174
+ * Create an invocation directly in the host app.
175
+ * The host handles all signing internally using session-based signing.
176
+ * This is the preferred approach for security.
177
+ */
178
+ createInvocationWithSession?: (params: {
179
+ sessionId: string;
180
+ audience: string;
181
+ capability: {
182
+ can: string;
183
+ with: string;
184
+ nb?: Record<string, unknown>;
185
+ };
186
+ proofs: string[];
187
+ }) => Promise<{
188
+ cid: string;
189
+ invocation: string;
190
+ }>;
191
+ }
192
+ /**
193
+ * Configuration for UcanService
194
+ */
195
+ interface UcanServiceConfig {
196
+ delegationStore: UcanDelegationStore;
197
+ invocationStore: InvocationStore;
198
+ handlers: UcanServiceHandlers;
199
+ flowOwnerDid: string;
200
+ flowUri: string;
201
+ }
202
+ /**
203
+ * UCAN Service interface
204
+ */
205
+ interface UcanService {
206
+ createRootDelegation: (params: CreateRootDelegationParams) => Promise<StoredDelegation>;
207
+ createDelegation: (params: CreateDelegationParams) => Promise<StoredDelegation>;
208
+ revokeDelegation: (cid: string) => void;
209
+ getDelegation: (cid: string) => StoredDelegation | null;
210
+ getAllDelegations: () => StoredDelegation[];
211
+ getRootDelegation: () => StoredDelegation | null;
212
+ createAndValidateInvocation: (params: CreateInvocationParams, flowId: string, blockId?: string) => Promise<InvocationResult>;
213
+ executeWithInvocation: <T>(params: CreateInvocationParams, action: () => Promise<T>, flowId: string, blockId?: string) => Promise<ExecutionWithInvocationResult & {
214
+ actionResult?: T;
215
+ }>;
216
+ validateDelegationChain: (audienceDid: string, capability: UcanCapability) => Promise<DelegationChainValidationResult>;
217
+ findValidProofs: (audienceDid: string, capability: UcanCapability) => Promise<FindProofsResult>;
218
+ parseDelegationFromStore: (cid: string) => Promise<Delegation | null>;
219
+ migrateLegacyDelegation: (legacyId: string, pin: string) => Promise<StoredDelegation | null>;
220
+ migrateAllLegacy: (pin: string) => Promise<MigrationReport>;
221
+ getLegacyCount: () => number;
222
+ isConfigured: () => boolean;
223
+ }
224
+ /**
225
+ * Create a UCAN service instance
226
+ */
227
+ declare const createUcanService: (config: UcanServiceConfig) => UcanService;
228
+
229
+ interface NodeActionResult {
230
+ claimId?: string;
231
+ evaluationStatus?: EvaluationStatus;
232
+ submittedByDid?: string;
233
+ payload?: any;
234
+ }
235
+ interface ExecutionContext {
236
+ runtime: FlowRuntimeStateManager;
237
+ /** @deprecated Use delegationStore instead */
238
+ ucanManager?: UCANManager;
239
+ delegationStore?: DelegationStore;
240
+ verifySignature?: (capabilityRaw: string, issuerDid: string) => Promise<{
241
+ valid: boolean;
242
+ error?: string;
243
+ }>;
244
+ rootIssuer?: string;
245
+ flowUri?: string;
246
+ now?: () => number;
247
+ }
248
+ interface ExecutionOutcome {
249
+ success: boolean;
250
+ stage: 'activation' | 'authorization' | 'claim' | 'action' | 'complete';
251
+ error?: string;
252
+ result?: NodeActionResult;
253
+ capabilityId?: string;
254
+ /** Invocation CID (new @ixo/ucan) */
255
+ invocationCid?: string;
256
+ }
257
+ /**
258
+ * V2 Execution context for @ixo/ucan integration
259
+ */
260
+ interface ExecutionContextV2 {
261
+ runtime: FlowRuntimeStateManager;
262
+ /** UCAN service for invocation-based execution */
263
+ ucanService?: UcanService;
264
+ /** Invocation store for audit trail */
265
+ invocationStore?: InvocationStore;
266
+ /** Flow URI */
267
+ flowUri: string;
268
+ /** Flow ID for invocation storage */
269
+ flowId: string;
270
+ /** Flow owner DID */
271
+ flowOwnerDid: string;
272
+ /** Current time function */
273
+ now?: () => number;
274
+ /** @deprecated Use ucanService instead */
275
+ ucanManager?: UCANManager;
276
+ /** @deprecated Use ucanService instead */
277
+ delegationStore?: DelegationStore;
278
+ /** @deprecated Use ucanService instead */
279
+ verifySignature?: (capabilityRaw: string, issuerDid: string) => Promise<{
280
+ valid: boolean;
281
+ error?: string;
282
+ }>;
283
+ /** @deprecated Use flowOwnerDid instead */
284
+ rootIssuer?: string;
285
+ }
286
+ /**
287
+ * V2 Execute node params with PIN for invocation signing
288
+ */
289
+ interface ExecuteNodeParamsV2 {
290
+ node: FlowNode;
291
+ actorDid: string;
292
+ actorType: 'entity' | 'user';
293
+ entityRoomId?: string;
294
+ context: ExecutionContextV2;
295
+ action: () => Promise<NodeActionResult>;
296
+ /** PIN for signing invocation (required for @ixo/ucan) */
297
+ pin: string;
298
+ }
299
+ interface ExecuteNodeParams {
300
+ node: FlowNode;
301
+ actorDid: string;
302
+ context: ExecutionContext;
303
+ action: () => Promise<NodeActionResult>;
304
+ }
305
+ declare const executeNode: ({ node, actorDid, context, action }: ExecuteNodeParams) => Promise<ExecutionOutcome>;
306
+ /**
307
+ * V2 Execute node with invocation-based authorization
308
+ * Creates an invocation before execution and stores it for audit trail
309
+ */
310
+ declare const executeNodeWithInvocation: ({ node, actorDid, actorType, entityRoomId, context, action, pin }: ExecuteNodeParamsV2) => Promise<ExecutionOutcome>;
311
+
312
+ interface AuthorizationResult {
313
+ authorized: boolean;
314
+ reason?: string;
315
+ capabilityId?: string;
316
+ /** Proof chain CIDs for creating invocations (new @ixo/ucan) */
317
+ proofCids?: string[];
318
+ /** @deprecated */
319
+ derived?: DerivedCapability;
320
+ }
321
+ interface AuthorizationContext {
322
+ /** @deprecated Use delegationStore instead */
323
+ ucanManager?: UCANManager;
324
+ delegationStore?: DelegationStore;
325
+ verifySignature?: (capabilityRaw: string, issuerDid: string) => Promise<{
326
+ valid: boolean;
327
+ error?: string;
328
+ }>;
329
+ rootIssuer?: string;
330
+ flowUri?: string;
331
+ }
332
+ /**
333
+ * Authorization context V2 for @ixo/ucan integration
334
+ */
335
+ interface AuthorizationContextV2 {
336
+ /** UCAN service for validation (new @ixo/ucan) */
337
+ ucanService?: UcanService;
338
+ /** Flow URI for resource matching */
339
+ flowUri?: string;
340
+ /** Flow owner DID (root issuer) */
341
+ flowOwnerDid?: string;
342
+ /** @deprecated Use ucanService instead */
343
+ ucanManager?: UCANManager;
344
+ /** @deprecated Use ucanService instead */
345
+ delegationStore?: DelegationStore;
346
+ /** @deprecated Use ucanService instead */
347
+ verifySignature?: (capabilityRaw: string, issuerDid: string) => Promise<{
348
+ valid: boolean;
349
+ error?: string;
350
+ }>;
351
+ /** @deprecated Use flowOwnerDid instead */
352
+ rootIssuer?: string;
353
+ }
354
+ declare const isActorAuthorized: (node: FlowNode, actorDid: string, context?: AuthorizationContext) => Promise<AuthorizationResult>;
355
+ /**
356
+ * V2 Authorization check using @ixo/ucan service
357
+ * Returns proof chain for invocation creation
358
+ */
359
+ declare const isActorAuthorizedV2: (node: FlowNode, actorDid: string, context?: AuthorizationContextV2) => Promise<AuthorizationResult>;
360
+
361
+ interface ActivationResult {
362
+ active: boolean;
363
+ reason?: string;
364
+ }
365
+ declare const isNodeActive: (node: FlowNode, runtime: FlowRuntimeStateManager) => ActivationResult;
366
+
367
+ interface ValidateChainParams {
368
+ /** The capability to validate */
369
+ capability: SignedCapability;
370
+ /** The actor DID trying to use the capability */
371
+ actorDid: string;
372
+ /** Required capability (what the actor wants to do) */
373
+ requiredCapability: Capability;
374
+ /** The delegation store */
375
+ delegationStore: DelegationStore;
376
+ /** Handler to verify signatures */
377
+ verifySignature: (capabilityRaw: string, issuerDid: string) => Promise<{
378
+ valid: boolean;
379
+ error?: string;
380
+ }>;
381
+ /** Expected root issuer (entity DID) */
382
+ rootIssuer: string;
383
+ }
384
+ /**
385
+ * Validate a capability chain back to the root
386
+ */
387
+ declare const validateCapabilityChain: (params: ValidateChainParams) => Promise<CapabilityValidationResult>;
388
+ /**
389
+ * Find a valid capability for an actor to perform an action
390
+ */
391
+ declare const findValidCapability: (params: {
392
+ actorDid: string;
393
+ requiredCapability: Capability;
394
+ delegationStore: DelegationStore;
395
+ verifySignature: (capabilityRaw: string, issuerDid: string) => Promise<{
396
+ valid: boolean;
397
+ error?: string;
398
+ }>;
399
+ rootIssuer: string;
400
+ }) => Promise<{
401
+ found: boolean;
402
+ capabilityId?: string;
403
+ error?: string;
404
+ }>;
405
+
406
+ export { type AuthorizationResult as A, type CapabilityGrant as C, type DelegationStore as D, type ExecuteNodeParams as E, type FlowRuntimeStateManager as F, type NodeActionResult as N, SimpleUCANManager as S, type UcanService as U, isNodeActive as a, createMemoryDelegationStore as b, createDelegationStore as c, createRuntimeStateManager as d, executeNode as e, findValidCapability as f, buildFlowNodeFromBlock as g, buildAuthzFromProps as h, isActorAuthorized as i, type ExecutionOutcome as j, type ExecutionContext as k, type AuthorizationContext as l, type ActivationResult as m, clearRuntimeForTemplateClone as n, executeNodeWithInvocation as o, type ExecuteNodeParamsV2 as p, type ExecutionContextV2 as q, isActorAuthorizedV2 as r, type AuthorizationContextV2 as s, createUcanService as t, type UcanServiceConfig as u, validateCapabilityChain as v, type UcanServiceHandlers as w, type UCANManager as x, type DerivedCapability as y };