@allorc/a423-sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CANCELLATION.md +70 -0
- package/CHANGELOG.md +17 -0
- package/ESCROW.md +4 -2
- package/INTEGRATION.md +9 -1
- package/OPERATIONS.md +5 -1
- package/README.md +6 -2
- package/SECURITY.md +4 -0
- package/SETTLEMENT.md +142 -0
- package/contracts/A423Escrow.sol +68 -6
- package/contracts/standard-input.json +1 -1
- package/examples/operations-dashboard.html +3 -3
- package/package.json +6 -2
- package/src/cancellation.cjs +74 -0
- package/src/closing.cjs +17 -0
- package/src/escrow/artifact.json +292 -1
- package/src/escrow/cancellation.cjs +34 -0
- package/src/escrow/index.cjs +70 -5
- package/src/escrow/index.d.mts +8 -1
- package/src/escrow/index.d.ts +8 -1
- package/src/escrow/index.mjs +1 -1
- package/src/escrow/negotiation.cjs +13 -0
- package/src/escrow/services.cjs +4 -1
- package/src/operations/application.cjs +8 -3
- package/src/operations/factory.cjs +3 -3
- package/src/operations/index.cjs +18 -7
- package/src/operations/index.d.ts +5 -3
- package/src/operations/index.mjs +1 -1
- package/src/workflow.cjs +79 -9
- package/src/workflow.d.ts +36 -2
- package/src/workflow.mjs +1 -1
package/src/workflow.d.ts
CHANGED
|
@@ -2,7 +2,26 @@ export type Json = null | boolean | number | string | Json[] | { [key: string]:
|
|
|
2
2
|
export interface Agreement { revision: number; terms: { [key: string]: Json }; hash: string; accepted_by: string[] }
|
|
3
3
|
export interface Operation { id: string; key: string; action: string; actor: string; input: Json; request_hash: string; target: string; created_at: string; observation: AdapterResult | null }
|
|
4
4
|
export interface AdapterResult { status: 'pending' | 'confirmed' | 'rejected'; evidence?: { [key: string]: Json }; [key: string]: Json | undefined }
|
|
5
|
+
export interface SettlementClaim {kind: 'work' | 'expense' | 'other';description: string;amount?: string;evidence?: string[]}
|
|
6
|
+
export interface SettlementProposal {version: 'a423.closing.v1';job_id: string;agreement_hash: string;escrow_version: number;worker_amount: string;payer_amount: string;expires_at: number;reason: string;claims: SettlementClaim[];closes_job: true;proposal_hash: string;proposer_id?: string;at?: string}
|
|
7
|
+
export interface Negotiation {status: 'open' | 'accepted' | 'disputed' | 'settled';acceptance_basis?: 'dual_wallet_signatures';origin_state: string;current: SettlementProposal;history: SettlementProposal[];accepted_by?: string;settled_at?: string}
|
|
8
|
+
export interface EscrowLedger {funded_amount: string;worker_paid: string;payer_refunded: string;locked_amount: string;escrow_version: number}
|
|
9
|
+
export interface CancellationInstruction {
|
|
10
|
+
id: string;version: 'a423.cancellation_instruction.v1';purpose: 'close_job';funds_status: 'not_executed';job_id: string;subflow_id: string;agreement_hash: string;chain_id: string;escrow_contract: string;token: string;onchain_job_id: string;escrow_version: number;proposal_hash: string;expires_at: number;
|
|
11
|
+
payer: {agent_id: string;address: string;amount: string};worker: {agent_id: string;address: string;amount: string};proposal: SettlementProposal;
|
|
12
|
+
authorization: {scheme: 'eip712_closing_settlement_v1';payer_signature: string;worker_signature: string};
|
|
13
|
+
}
|
|
14
|
+
export interface CancellationReceipt {
|
|
15
|
+
id: string;version: 'a423.cancellation_receipt.v1';status: 'confirmed';job_id: string;subflow_id: string;agreement_hash: string;outcome: string;instruction_id: string | null;prior_instruction_id: string | null;
|
|
16
|
+
allocations: {worker: {address: string;amount: string};payer: {address: string;amount: string}};remaining_locked: '0';evidence: {[key: string]: Json};
|
|
17
|
+
}
|
|
18
|
+
export interface CancellationSubflow {
|
|
19
|
+
id: string;kind: 'cancellation';parent_job_id: string;status: 'proposal_pending'|'proposal_rejected'|'negotiating'|'acceptance_pending'|'accepted'|'execution_pending'|'execution_failed'|'completed'|'disputed';started_at: string;updated_at: string;proposal_revision: number;instruction: CancellationInstruction | null;receipt: CancellationReceipt | null;events: Array<{sequence: number;type: string;actor_id: string;at: string;data: Json}>;accepted_at?: string;approved_by?: string[];completed_at?: string;execution_reference?: string | null;closing_action?: string;last_error?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface CancellationApproval {expected_revision: number;proposal_hash: string;payer_signature: string;worker_signature: string}
|
|
5
22
|
export interface WorkflowJob {
|
|
23
|
+
subflows?: CancellationSubflow[];active_subflow_id?: string | null;
|
|
24
|
+
work_status?: string;negotiation?: Negotiation | null;escrow_ledger?: EscrowLedger | null;
|
|
6
25
|
id: string; protocol: 'a423.workflow.v1'; version: number; state: string;
|
|
7
26
|
participants: { requester: string; worker: string; verifier: string; [role: string]: string };
|
|
8
27
|
metadata: Json; agreement: Agreement | null; submission: Json;
|
|
@@ -38,13 +57,17 @@ export interface Workflow {
|
|
|
38
57
|
act(id: string, action: string, input: Json, options: { actor: string; idempotencyKey: string }): Promise<WorkflowJob>;
|
|
39
58
|
resume(id: string, actor: string): Promise<WorkflowJob>;
|
|
40
59
|
reconcile(id: string, actor: string): Promise<WorkflowJob>;
|
|
41
|
-
|
|
60
|
+
cancellation(id: string, actor: string): Promise<CancellationSubflow | null>;
|
|
61
|
+
cancellationInstruction(id: string, actor: string): Promise<CancellationInstruction>;
|
|
62
|
+
cancellationReceipt(id: string, actor: string): Promise<CancellationReceipt>;
|
|
63
|
+
acceptCancellation(id: string,input: CancellationApproval,options: {actor: string;idempotencyKey: string;forward?: boolean}): Promise<WorkflowJob>;
|
|
64
|
+
receipts(id: string, actor: string): Promise<Pick<WorkflowJob, 'protocol' | 'state' | 'agreement' | 'submission' | 'evidence' | 'events' | 'pending' | 'work_status' | 'negotiation' | 'escrow_ledger' | 'subflows' | 'active_subflow_id'> & { job_id: string }>;
|
|
42
65
|
}
|
|
43
66
|
export function hashAgreement(terms: Json): string;
|
|
44
67
|
export function createWorkflow(options: WorkflowOptions): Workflow;
|
|
45
68
|
export function createWorkflowHandler(options: {
|
|
46
69
|
workflow: Workflow; authenticate(request: Request): string | null | Promise<string | null>;
|
|
47
|
-
basePath?: string; maxBodyBytes?: number; onError?(error: unknown): void | Promise<void>;
|
|
70
|
+
basePath?: string; maxBodyBytes?: number; forwardCancellations?: boolean; revalidateCancellationReceipt?(context: {job: WorkflowJob;receipt: CancellationReceipt;actor: string}): Promise<void>; onError?(error: unknown): void | Promise<void>;
|
|
48
71
|
}): (request: Request) => Promise<Response>;
|
|
49
72
|
export interface WorkflowClient {
|
|
50
73
|
/** Supply a stable id so creation retries can be resolved with get(id). */
|
|
@@ -52,9 +75,20 @@ export interface WorkflowClient {
|
|
|
52
75
|
get(id: string): Promise<WorkflowJob>;
|
|
53
76
|
act(id: string, action: string, input: Json, options: { idempotencyKey: string }): Promise<WorkflowJob>;
|
|
54
77
|
reconcile(id: string): Promise<WorkflowJob>;
|
|
78
|
+
cancellation(id: string): Promise<CancellationSubflow | null>;
|
|
79
|
+
cancellationInstruction(id: string): Promise<CancellationInstruction>;
|
|
80
|
+
cancellationReceipt(id: string): Promise<CancellationReceipt>;
|
|
81
|
+
subflows(id: string): Promise<CancellationSubflow[]>;
|
|
82
|
+
acceptCancellation(id: string,input: CancellationApproval,options: {idempotencyKey: string}): Promise<WorkflowJob>;
|
|
83
|
+
executeCancellation(id: string,input: {instruction_id: string;transaction_hash?: string},options: {idempotencyKey: string}): Promise<WorkflowJob>;
|
|
55
84
|
receipts(id: string): ReturnType<Workflow['receipts']>;
|
|
56
85
|
}
|
|
57
86
|
export function createWorkflowClient(options: {
|
|
58
87
|
baseUrl: string; headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
59
88
|
fetch?: typeof globalThis.fetch; timeoutMs?: number;
|
|
60
89
|
}): WorkflowClient;
|
|
90
|
+
|
|
91
|
+
export function getCancellationSubflow(job: WorkflowJob): CancellationSubflow | null;
|
|
92
|
+
export function createCancellationInstruction(job: WorkflowJob,proofs: {payer_signature: string;worker_signature: string}): CancellationInstruction;
|
|
93
|
+
export function validateCancellationInstruction(job: WorkflowJob,instruction: CancellationInstruction): CancellationInstruction;
|
|
94
|
+
export function validateCancellationReceipt(job: WorkflowJob,receipt: CancellationReceipt): CancellationReceipt;
|
package/src/workflow.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import workflow from './workflow.cjs';
|
|
2
|
-
export const { createWorkflow, createWorkflowHandler, createWorkflowClient, hashAgreement } = workflow;
|
|
2
|
+
export const { createWorkflow, createWorkflowHandler, createWorkflowClient, hashAgreement, getCancellationSubflow, createCancellationInstruction, validateCancellationInstruction, validateCancellationReceipt } = workflow;
|