@escro/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/index.cjs +487 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +455 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { TaskSpec, EscrowState, EscrowAccount } from '@escro/shared';
|
|
2
|
+
export { AcceptanceCriterion, DeliverableFormat, DeliverableType, EscrowAccount, EscrowErrorCode, EscrowState, Network, TaskSpec, TaskType } from '@escro/shared';
|
|
3
|
+
import { Keypair } from '@solana/web3.js';
|
|
4
|
+
|
|
5
|
+
/** Constructor options for the {@link Escro} client. */
|
|
6
|
+
interface EscroOptions {
|
|
7
|
+
/** Solana RPC endpoint URL. */
|
|
8
|
+
rpcUrl: string;
|
|
9
|
+
/** Escro REST API base URL (e.g. "https://api.escro.ai"). */
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
/** Ed25519 keypair used to sign transactions and API requests. */
|
|
12
|
+
wallet: Keypair;
|
|
13
|
+
}
|
|
14
|
+
/** Parameters for creating a new escrow. */
|
|
15
|
+
interface CreateEscrowParams {
|
|
16
|
+
/** Full task specification uploaded to IPFS. */
|
|
17
|
+
taskSpec: TaskSpec;
|
|
18
|
+
/** Payment amount in μUSDC (1 USDC = 1_000_000). Minimum: 5_000_000. */
|
|
19
|
+
amountUsdc: number;
|
|
20
|
+
/** Unix timestamp (seconds) at which the escrow deadline expires. */
|
|
21
|
+
deadlineSeconds: number;
|
|
22
|
+
/** Base-58 public key of the worker pre-assigned to this task. */
|
|
23
|
+
assignedWorker: string;
|
|
24
|
+
}
|
|
25
|
+
/** Return value from {@link Escro.createEscrow}. */
|
|
26
|
+
interface CreateEscrowResult {
|
|
27
|
+
/** Task ID (32-char hex UUID without hyphens). Used internally by the API. */
|
|
28
|
+
escrowId: string;
|
|
29
|
+
/** Base-58 on-chain PDA address. Use this as the identifier for all subsequent calls. */
|
|
30
|
+
escrowPda: string;
|
|
31
|
+
/** Solana transaction signature. */
|
|
32
|
+
signature: string;
|
|
33
|
+
}
|
|
34
|
+
/** Parameters for submitting a deliverable. */
|
|
35
|
+
interface SubmitDeliverableParams {
|
|
36
|
+
/** SHA-256 hex digest (or content-addressed hash) of the deliverable content. */
|
|
37
|
+
contentHash: string;
|
|
38
|
+
/** Optional URI pointing to the deliverable artifact (IPFS, Arweave, etc.). */
|
|
39
|
+
proofUri?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Parameters for raising a dispute. */
|
|
42
|
+
interface RaiseDisputeParams {
|
|
43
|
+
/** Human-readable reason for the dispute (max 200 chars). */
|
|
44
|
+
reason: string;
|
|
45
|
+
/** Optional URL to evidence supporting the dispute. */
|
|
46
|
+
evidence?: string;
|
|
47
|
+
}
|
|
48
|
+
/** Options for polling methods. */
|
|
49
|
+
interface PollOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Enable polling with exponential backoff.
|
|
52
|
+
* - 0–5 min: poll every 15 s
|
|
53
|
+
* - 5–30 min: poll every 30 s
|
|
54
|
+
* - 30 min–24 h: poll every 60 s
|
|
55
|
+
* - After 24 h: throws {@link EscrowTimeoutError}
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
poll?: boolean;
|
|
59
|
+
/** Override the default 24-hour polling timeout (ms). */
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
}
|
|
62
|
+
/** Pagination parameters for list queries. */
|
|
63
|
+
interface ListOptions {
|
|
64
|
+
/** Maximum number of items to return. Default: 20, max: 100. */
|
|
65
|
+
limit?: number;
|
|
66
|
+
/** Zero-based offset for pagination. Default: 0. */
|
|
67
|
+
offset?: number;
|
|
68
|
+
}
|
|
69
|
+
/** Paginated response wrapper. */
|
|
70
|
+
interface PaginatedResult<T> {
|
|
71
|
+
/** The requested page of items. */
|
|
72
|
+
items: T[];
|
|
73
|
+
/** Total number of items matching the query (ignoring pagination). */
|
|
74
|
+
total: number;
|
|
75
|
+
/** The effective limit applied to this response. */
|
|
76
|
+
limit: number;
|
|
77
|
+
/** The effective offset applied to this response. */
|
|
78
|
+
offset: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare class Escro {
|
|
82
|
+
private readonly connection;
|
|
83
|
+
private readonly api;
|
|
84
|
+
private readonly options;
|
|
85
|
+
constructor(options: EscroOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Create a new escrow: registers with the API, signs and submits the
|
|
88
|
+
* on-chain `create_escrow` transaction.
|
|
89
|
+
*
|
|
90
|
+
* @returns `{ escrowId, escrowPda, signature }` — use `escrowPda` for all subsequent calls.
|
|
91
|
+
*/
|
|
92
|
+
createEscrow(params: CreateEscrowParams): Promise<CreateEscrowResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Release payment to the worker. Buyer must be the wallet in the constructor.
|
|
95
|
+
* Updates API DB state, then builds and submits the `release_payment` on-chain tx.
|
|
96
|
+
*
|
|
97
|
+
* @returns Solana transaction signature.
|
|
98
|
+
*/
|
|
99
|
+
releasePayment(address: string): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Raise a dispute for an escrow. Either the buyer or the assigned worker
|
|
102
|
+
* may call this. Signs and submits the `raise_dispute` on-chain tx.
|
|
103
|
+
*
|
|
104
|
+
* @returns Solana transaction signature.
|
|
105
|
+
*/
|
|
106
|
+
raiseDispute(address: string, params: RaiseDisputeParams): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Cancel a funded escrow before any worker has claimed it.
|
|
109
|
+
* Buyer must be the wallet in the constructor. Only valid when state is `FUNDED`.
|
|
110
|
+
* Signs and submits the `cancel_escrow` on-chain tx; full USDC refund to buyer.
|
|
111
|
+
*
|
|
112
|
+
* @returns Solana transaction signature.
|
|
113
|
+
*/
|
|
114
|
+
cancelEscrow(address: string): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Claim an assigned task. Worker must be the wallet in the constructor.
|
|
117
|
+
* Signs and submits the `claim_task` on-chain tx.
|
|
118
|
+
*
|
|
119
|
+
* @returns Solana transaction signature.
|
|
120
|
+
*/
|
|
121
|
+
claimTask(address: string): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Submit a deliverable for oracle evaluation. Worker must be the wallet.
|
|
124
|
+
* Signs and submits the `submit_deliverable` on-chain tx.
|
|
125
|
+
*
|
|
126
|
+
* @returns Solana transaction signature.
|
|
127
|
+
*/
|
|
128
|
+
submitDeliverable(address: string, params: SubmitDeliverableParams): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* List tasks assigned to the wallet's public key.
|
|
131
|
+
* Optionally filter by state(s) and paginate results.
|
|
132
|
+
*
|
|
133
|
+
* If `options.poll` is true, polls with exponential backoff until at least
|
|
134
|
+
* one task is returned.
|
|
135
|
+
*
|
|
136
|
+
* @param state - Filter by one or more states (first state used as API filter).
|
|
137
|
+
* @param options - Polling, pagination (limit/offset).
|
|
138
|
+
*/
|
|
139
|
+
getMyTasks(state?: EscrowState[], options?: PollOptions & ListOptions): Promise<PaginatedResult<EscrowAccount>>;
|
|
140
|
+
/**
|
|
141
|
+
* Fetch an escrow by its PDA address.
|
|
142
|
+
* If `options.poll` is true, polls with exponential backoff until the escrow
|
|
143
|
+
* appears (useful immediately after a create tx before the API DB syncs).
|
|
144
|
+
*/
|
|
145
|
+
getEscrow(address: string, options?: PollOptions): Promise<EscrowAccount>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Base class for all errors thrown by the @escro/sdk. */
|
|
149
|
+
declare class EscroError extends Error {
|
|
150
|
+
readonly code: string;
|
|
151
|
+
constructor(message: string, code?: string);
|
|
152
|
+
}
|
|
153
|
+
/** The requested escrow was not found (HTTP 404). */
|
|
154
|
+
declare class EscrowNotFoundError extends EscroError {
|
|
155
|
+
constructor(address: string);
|
|
156
|
+
}
|
|
157
|
+
/** The operation is not valid for the escrow's current state (HTTP 409). */
|
|
158
|
+
declare class EscrowStateError extends EscroError {
|
|
159
|
+
constructor(message: string);
|
|
160
|
+
}
|
|
161
|
+
/** Polling timed out after 24 hours without reaching the expected state. */
|
|
162
|
+
declare class EscrowTimeoutError extends EscroError {
|
|
163
|
+
constructor(address: string);
|
|
164
|
+
}
|
|
165
|
+
/** The caller is not authorized to perform this action (HTTP 401/403). */
|
|
166
|
+
declare class UnauthorizedError extends EscroError {
|
|
167
|
+
constructor(message?: string);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { type CreateEscrowParams, type CreateEscrowResult, Escro, EscroError, type EscroOptions, EscrowNotFoundError, EscrowStateError, EscrowTimeoutError, type ListOptions, type PaginatedResult, type PollOptions, type RaiseDisputeParams, type SubmitDeliverableParams, UnauthorizedError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { TaskSpec, EscrowState, EscrowAccount } from '@escro/shared';
|
|
2
|
+
export { AcceptanceCriterion, DeliverableFormat, DeliverableType, EscrowAccount, EscrowErrorCode, EscrowState, Network, TaskSpec, TaskType } from '@escro/shared';
|
|
3
|
+
import { Keypair } from '@solana/web3.js';
|
|
4
|
+
|
|
5
|
+
/** Constructor options for the {@link Escro} client. */
|
|
6
|
+
interface EscroOptions {
|
|
7
|
+
/** Solana RPC endpoint URL. */
|
|
8
|
+
rpcUrl: string;
|
|
9
|
+
/** Escro REST API base URL (e.g. "https://api.escro.ai"). */
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
/** Ed25519 keypair used to sign transactions and API requests. */
|
|
12
|
+
wallet: Keypair;
|
|
13
|
+
}
|
|
14
|
+
/** Parameters for creating a new escrow. */
|
|
15
|
+
interface CreateEscrowParams {
|
|
16
|
+
/** Full task specification uploaded to IPFS. */
|
|
17
|
+
taskSpec: TaskSpec;
|
|
18
|
+
/** Payment amount in μUSDC (1 USDC = 1_000_000). Minimum: 5_000_000. */
|
|
19
|
+
amountUsdc: number;
|
|
20
|
+
/** Unix timestamp (seconds) at which the escrow deadline expires. */
|
|
21
|
+
deadlineSeconds: number;
|
|
22
|
+
/** Base-58 public key of the worker pre-assigned to this task. */
|
|
23
|
+
assignedWorker: string;
|
|
24
|
+
}
|
|
25
|
+
/** Return value from {@link Escro.createEscrow}. */
|
|
26
|
+
interface CreateEscrowResult {
|
|
27
|
+
/** Task ID (32-char hex UUID without hyphens). Used internally by the API. */
|
|
28
|
+
escrowId: string;
|
|
29
|
+
/** Base-58 on-chain PDA address. Use this as the identifier for all subsequent calls. */
|
|
30
|
+
escrowPda: string;
|
|
31
|
+
/** Solana transaction signature. */
|
|
32
|
+
signature: string;
|
|
33
|
+
}
|
|
34
|
+
/** Parameters for submitting a deliverable. */
|
|
35
|
+
interface SubmitDeliverableParams {
|
|
36
|
+
/** SHA-256 hex digest (or content-addressed hash) of the deliverable content. */
|
|
37
|
+
contentHash: string;
|
|
38
|
+
/** Optional URI pointing to the deliverable artifact (IPFS, Arweave, etc.). */
|
|
39
|
+
proofUri?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Parameters for raising a dispute. */
|
|
42
|
+
interface RaiseDisputeParams {
|
|
43
|
+
/** Human-readable reason for the dispute (max 200 chars). */
|
|
44
|
+
reason: string;
|
|
45
|
+
/** Optional URL to evidence supporting the dispute. */
|
|
46
|
+
evidence?: string;
|
|
47
|
+
}
|
|
48
|
+
/** Options for polling methods. */
|
|
49
|
+
interface PollOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Enable polling with exponential backoff.
|
|
52
|
+
* - 0–5 min: poll every 15 s
|
|
53
|
+
* - 5–30 min: poll every 30 s
|
|
54
|
+
* - 30 min–24 h: poll every 60 s
|
|
55
|
+
* - After 24 h: throws {@link EscrowTimeoutError}
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
poll?: boolean;
|
|
59
|
+
/** Override the default 24-hour polling timeout (ms). */
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
}
|
|
62
|
+
/** Pagination parameters for list queries. */
|
|
63
|
+
interface ListOptions {
|
|
64
|
+
/** Maximum number of items to return. Default: 20, max: 100. */
|
|
65
|
+
limit?: number;
|
|
66
|
+
/** Zero-based offset for pagination. Default: 0. */
|
|
67
|
+
offset?: number;
|
|
68
|
+
}
|
|
69
|
+
/** Paginated response wrapper. */
|
|
70
|
+
interface PaginatedResult<T> {
|
|
71
|
+
/** The requested page of items. */
|
|
72
|
+
items: T[];
|
|
73
|
+
/** Total number of items matching the query (ignoring pagination). */
|
|
74
|
+
total: number;
|
|
75
|
+
/** The effective limit applied to this response. */
|
|
76
|
+
limit: number;
|
|
77
|
+
/** The effective offset applied to this response. */
|
|
78
|
+
offset: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare class Escro {
|
|
82
|
+
private readonly connection;
|
|
83
|
+
private readonly api;
|
|
84
|
+
private readonly options;
|
|
85
|
+
constructor(options: EscroOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Create a new escrow: registers with the API, signs and submits the
|
|
88
|
+
* on-chain `create_escrow` transaction.
|
|
89
|
+
*
|
|
90
|
+
* @returns `{ escrowId, escrowPda, signature }` — use `escrowPda` for all subsequent calls.
|
|
91
|
+
*/
|
|
92
|
+
createEscrow(params: CreateEscrowParams): Promise<CreateEscrowResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Release payment to the worker. Buyer must be the wallet in the constructor.
|
|
95
|
+
* Updates API DB state, then builds and submits the `release_payment` on-chain tx.
|
|
96
|
+
*
|
|
97
|
+
* @returns Solana transaction signature.
|
|
98
|
+
*/
|
|
99
|
+
releasePayment(address: string): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Raise a dispute for an escrow. Either the buyer or the assigned worker
|
|
102
|
+
* may call this. Signs and submits the `raise_dispute` on-chain tx.
|
|
103
|
+
*
|
|
104
|
+
* @returns Solana transaction signature.
|
|
105
|
+
*/
|
|
106
|
+
raiseDispute(address: string, params: RaiseDisputeParams): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Cancel a funded escrow before any worker has claimed it.
|
|
109
|
+
* Buyer must be the wallet in the constructor. Only valid when state is `FUNDED`.
|
|
110
|
+
* Signs and submits the `cancel_escrow` on-chain tx; full USDC refund to buyer.
|
|
111
|
+
*
|
|
112
|
+
* @returns Solana transaction signature.
|
|
113
|
+
*/
|
|
114
|
+
cancelEscrow(address: string): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Claim an assigned task. Worker must be the wallet in the constructor.
|
|
117
|
+
* Signs and submits the `claim_task` on-chain tx.
|
|
118
|
+
*
|
|
119
|
+
* @returns Solana transaction signature.
|
|
120
|
+
*/
|
|
121
|
+
claimTask(address: string): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Submit a deliverable for oracle evaluation. Worker must be the wallet.
|
|
124
|
+
* Signs and submits the `submit_deliverable` on-chain tx.
|
|
125
|
+
*
|
|
126
|
+
* @returns Solana transaction signature.
|
|
127
|
+
*/
|
|
128
|
+
submitDeliverable(address: string, params: SubmitDeliverableParams): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* List tasks assigned to the wallet's public key.
|
|
131
|
+
* Optionally filter by state(s) and paginate results.
|
|
132
|
+
*
|
|
133
|
+
* If `options.poll` is true, polls with exponential backoff until at least
|
|
134
|
+
* one task is returned.
|
|
135
|
+
*
|
|
136
|
+
* @param state - Filter by one or more states (first state used as API filter).
|
|
137
|
+
* @param options - Polling, pagination (limit/offset).
|
|
138
|
+
*/
|
|
139
|
+
getMyTasks(state?: EscrowState[], options?: PollOptions & ListOptions): Promise<PaginatedResult<EscrowAccount>>;
|
|
140
|
+
/**
|
|
141
|
+
* Fetch an escrow by its PDA address.
|
|
142
|
+
* If `options.poll` is true, polls with exponential backoff until the escrow
|
|
143
|
+
* appears (useful immediately after a create tx before the API DB syncs).
|
|
144
|
+
*/
|
|
145
|
+
getEscrow(address: string, options?: PollOptions): Promise<EscrowAccount>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Base class for all errors thrown by the @escro/sdk. */
|
|
149
|
+
declare class EscroError extends Error {
|
|
150
|
+
readonly code: string;
|
|
151
|
+
constructor(message: string, code?: string);
|
|
152
|
+
}
|
|
153
|
+
/** The requested escrow was not found (HTTP 404). */
|
|
154
|
+
declare class EscrowNotFoundError extends EscroError {
|
|
155
|
+
constructor(address: string);
|
|
156
|
+
}
|
|
157
|
+
/** The operation is not valid for the escrow's current state (HTTP 409). */
|
|
158
|
+
declare class EscrowStateError extends EscroError {
|
|
159
|
+
constructor(message: string);
|
|
160
|
+
}
|
|
161
|
+
/** Polling timed out after 24 hours without reaching the expected state. */
|
|
162
|
+
declare class EscrowTimeoutError extends EscroError {
|
|
163
|
+
constructor(address: string);
|
|
164
|
+
}
|
|
165
|
+
/** The caller is not authorized to perform this action (HTTP 401/403). */
|
|
166
|
+
declare class UnauthorizedError extends EscroError {
|
|
167
|
+
constructor(message?: string);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { type CreateEscrowParams, type CreateEscrowResult, Escro, EscroError, type EscroOptions, EscrowNotFoundError, EscrowStateError, EscrowTimeoutError, type ListOptions, type PaginatedResult, type PollOptions, type RaiseDisputeParams, type SubmitDeliverableParams, UnauthorizedError };
|