@bountyagents/bountyagents-task 2026.2.26
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/.env.local +1 -0
- package/dist/escrow.d.ts +3 -0
- package/dist/escrow.js +14 -0
- package/dist/escrow.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +42394 -0
- package/dist/index.js.map +1 -0
- package/dist/mizu.d.ts +27 -0
- package/dist/mizu.js +53 -0
- package/dist/mizu.js.map +1 -0
- package/dist/mizuPublisher.d.ts +27 -0
- package/dist/mizuPublisher.js +53 -0
- package/dist/mizuPublisher.js.map +1 -0
- package/dist/signers.d.ts +13 -0
- package/dist/signers.js +26 -0
- package/dist/signers.js.map +1 -0
- package/dist/signing.d.ts +21 -0
- package/dist/signing.js +72 -0
- package/dist/signing.js.map +1 -0
- package/dist/taskPublisher.d.ts +27 -0
- package/dist/taskPublisher.js +53 -0
- package/dist/taskPublisher.js.map +1 -0
- package/dist/token.d.ts +5 -0
- package/dist/token.js +12 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +187 -0
- package/dist/types.js +77 -0
- package/dist/types.js.map +1 -0
- package/index.ts +34 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +38 -0
- package/src/escrow.ts +27 -0
- package/src/index.ts +413 -0
- package/src/signers.ts +36 -0
- package/src/signing.ts +113 -0
- package/src/token.ts +17 -0
- package/src/types.ts +101 -0
- package/tsconfig.json +16 -0
package/src/signing.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CancelTaskPayload,
|
|
3
|
+
CreateTaskPayload,
|
|
4
|
+
DecisionPayload,
|
|
5
|
+
FundTaskPayload,
|
|
6
|
+
SettleTaskPayload,
|
|
7
|
+
SubmitResponsePayload,
|
|
8
|
+
TaskResponsesQueryPayload,
|
|
9
|
+
WorkerResponsesQueryPayload
|
|
10
|
+
} from './types.js';
|
|
11
|
+
|
|
12
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
|
|
13
|
+
|
|
14
|
+
type CanonicalInput = JsonValue | Record<string, unknown> | undefined;
|
|
15
|
+
|
|
16
|
+
const canonicalize = (value: CanonicalInput): JsonValue => {
|
|
17
|
+
if (value === null || value === undefined) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return value.map((item) => canonicalize(item)) as JsonValue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entries = Object.entries(value as Record<string, CanonicalInput>)
|
|
30
|
+
.filter(([, v]) => v !== undefined)
|
|
31
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
32
|
+
const normalized: Record<string, JsonValue> = {};
|
|
33
|
+
for (const [key, val] of entries) {
|
|
34
|
+
normalized[key] = canonicalize(val);
|
|
35
|
+
}
|
|
36
|
+
return normalized;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const canonicalStringify = (payload: CanonicalInput): string =>
|
|
40
|
+
JSON.stringify(canonicalize(payload));
|
|
41
|
+
|
|
42
|
+
export const taskSignaturePayload = (input: CreateTaskPayload): string =>
|
|
43
|
+
canonicalStringify({
|
|
44
|
+
kind: 'task:create',
|
|
45
|
+
title: input.title,
|
|
46
|
+
content: input.content,
|
|
47
|
+
id: input.id
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const taskFundSignaturePayload = (input: FundTaskPayload): string =>
|
|
51
|
+
canonicalStringify({
|
|
52
|
+
kind: 'task:fund',
|
|
53
|
+
taskId: input.taskId,
|
|
54
|
+
price: input.price,
|
|
55
|
+
token: input.token
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const responseSignaturePayload = (input: SubmitResponsePayload): string =>
|
|
59
|
+
canonicalStringify({
|
|
60
|
+
kind: 'task:response',
|
|
61
|
+
taskId: input.taskId,
|
|
62
|
+
payload: input.payload,
|
|
63
|
+
id: input.id ?? null
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const decisionSignaturePayload = (input: DecisionPayload): string =>
|
|
67
|
+
canonicalStringify({
|
|
68
|
+
kind: 'task:decision',
|
|
69
|
+
responseId: input.responseId,
|
|
70
|
+
workerAddress: input.workerAddress,
|
|
71
|
+
price: input.price,
|
|
72
|
+
status: input.status,
|
|
73
|
+
settlementSignature: input.settlementSignature ?? null
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const cancelTaskSignaturePayload = (input: CancelTaskPayload): string =>
|
|
77
|
+
canonicalStringify({
|
|
78
|
+
kind: 'task:cancel',
|
|
79
|
+
taskId: input.taskId
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const taskSettleSignaturePayload = (
|
|
83
|
+
input: SettleTaskPayload & { workerAddress: string }
|
|
84
|
+
): string =>
|
|
85
|
+
canonicalStringify({
|
|
86
|
+
kind: 'task:settle',
|
|
87
|
+
taskId: input.taskId,
|
|
88
|
+
responseId: input.responseId,
|
|
89
|
+
workerAddress: input.workerAddress
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const taskResponsesQuerySignaturePayload = (
|
|
93
|
+
input: TaskResponsesQueryPayload & { ownerAddress: string }
|
|
94
|
+
): string =>
|
|
95
|
+
canonicalStringify({
|
|
96
|
+
kind: 'task:response:query',
|
|
97
|
+
taskId: input.taskId,
|
|
98
|
+
ownerAddress: input.ownerAddress,
|
|
99
|
+
workerAddress: input.workerAddress ?? null,
|
|
100
|
+
pageSize: input.pageSize ?? 50,
|
|
101
|
+
pageNum: input.pageNum ?? 0
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const workerResponsesQuerySignaturePayload = (
|
|
105
|
+
input: WorkerResponsesQueryPayload & { workerAddress: string }
|
|
106
|
+
): string =>
|
|
107
|
+
canonicalStringify({
|
|
108
|
+
kind: 'worker:response:query',
|
|
109
|
+
workerAddress: input.workerAddress,
|
|
110
|
+
taskId: input.taskId ?? null,
|
|
111
|
+
pageSize: input.pageSize ?? 50,
|
|
112
|
+
pageNum: input.pageNum ?? 0
|
|
113
|
+
});
|
package/src/token.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getAddress } from 'viem';
|
|
2
|
+
|
|
3
|
+
export interface ParsedTokenIdentifier {
|
|
4
|
+
network: string;
|
|
5
|
+
address: `0x${string}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const parseTokenIdentifier = (token: string): ParsedTokenIdentifier => {
|
|
9
|
+
const [networkRaw, address] = token.split(':');
|
|
10
|
+
if (!networkRaw || !address) {
|
|
11
|
+
throw new Error('Invalid token identifier');
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
network: networkRaw.toLowerCase(),
|
|
15
|
+
address: getAddress(address as `0x${string}`)
|
|
16
|
+
};
|
|
17
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { responseStatusSchema, taskStatusSchema } from '@bountyagents/task-db';
|
|
3
|
+
import { getAddress, isAddress } from 'viem';
|
|
4
|
+
|
|
5
|
+
const addressSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.refine((value) => isAddress(value as `0x${string}`), {
|
|
8
|
+
message: 'Invalid address'
|
|
9
|
+
})
|
|
10
|
+
.transform((value) => getAddress(value as `0x${string}`));
|
|
11
|
+
|
|
12
|
+
const tokenSchema = z.string().regex(/^[a-z0-9-]+:0x[a-fA-F0-9]{40}$/);
|
|
13
|
+
|
|
14
|
+
const priceStringSchema = z.string().regex(/^[0-9]+$/).refine((val) => BigInt(val) > 0n, {
|
|
15
|
+
message: 'price must be greater than zero'
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const signatureSchema = z.string().regex(/^0x[a-fA-F0-9]{130}$/, { message: 'Invalid signature' });
|
|
19
|
+
|
|
20
|
+
export const createTaskPayloadSchema = z.object({
|
|
21
|
+
id: z.string().uuid(),
|
|
22
|
+
title: z.string().min(4),
|
|
23
|
+
content: z.string().min(1)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const fundTaskPayloadSchema = z.object({
|
|
27
|
+
taskId: z.string().uuid(),
|
|
28
|
+
price: priceStringSchema,
|
|
29
|
+
token: tokenSchema
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const submitResponsePayloadSchema = z.object({
|
|
33
|
+
id: z.string().uuid().optional(),
|
|
34
|
+
taskId: z.string().uuid(),
|
|
35
|
+
payload: z.string().min(1)
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const decisionPayloadSchema = z
|
|
39
|
+
.object({
|
|
40
|
+
responseId: z.string().uuid(),
|
|
41
|
+
workerAddress: addressSchema,
|
|
42
|
+
price: z.string(),
|
|
43
|
+
status: responseStatusSchema,
|
|
44
|
+
settlementSignature: signatureSchema.optional()
|
|
45
|
+
})
|
|
46
|
+
.refine((value) => value.status !== 'pending', {
|
|
47
|
+
message: 'Status must be approved or rejected'
|
|
48
|
+
})
|
|
49
|
+
.refine((value) => (value.status === 'approved' ? Boolean(value.settlementSignature) : true), {
|
|
50
|
+
message: 'settlementSignature required when approving'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const cancelTaskPayloadSchema = z.object({
|
|
54
|
+
taskId: z.string().uuid()
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const settleTaskPayloadSchema = z.object({
|
|
58
|
+
taskId: z.string().uuid(),
|
|
59
|
+
responseId: z.string().uuid()
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const createdRangeSchema = z.tuple([z.number().nonnegative(), z.number().nonnegative()]).optional();
|
|
63
|
+
|
|
64
|
+
export const taskQueryPayloadSchema = z.object({
|
|
65
|
+
filter: z
|
|
66
|
+
.object({
|
|
67
|
+
publisher: addressSchema.optional(),
|
|
68
|
+
created_at: createdRangeSchema,
|
|
69
|
+
status: taskStatusSchema.optional(),
|
|
70
|
+
minPrice: z.number().int().nonnegative().optional(),
|
|
71
|
+
keyword: z.string().min(2).max(256).optional()
|
|
72
|
+
})
|
|
73
|
+
.default({}),
|
|
74
|
+
sortBy: z.enum(['price', 'created_at']).optional().default('created_at'),
|
|
75
|
+
pageSize: z.number().int().min(1).max(200).optional().default(50),
|
|
76
|
+
pageNum: z.number().int().min(0).optional().default(0)
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const taskResponsesQueryPayloadSchema = z.object({
|
|
80
|
+
taskId: z.string().uuid(),
|
|
81
|
+
workerAddress: addressSchema.optional(),
|
|
82
|
+
pageSize: z.number().int().min(1).max(200).optional().default(50),
|
|
83
|
+
pageNum: z.number().int().min(0).optional().default(0)
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const workerResponsesQueryPayloadSchema = z.object({
|
|
87
|
+
taskId: z.string().uuid().optional(),
|
|
88
|
+
pageSize: z.number().int().min(1).max(200).optional().default(50),
|
|
89
|
+
pageNum: z.number().int().min(0).optional().default(0)
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export type AddressString = z.infer<typeof addressSchema>;
|
|
93
|
+
export type CreateTaskPayload = z.infer<typeof createTaskPayloadSchema>;
|
|
94
|
+
export type FundTaskPayload = z.infer<typeof fundTaskPayloadSchema>;
|
|
95
|
+
export type SubmitResponsePayload = z.infer<typeof submitResponsePayloadSchema>;
|
|
96
|
+
export type DecisionPayload = z.infer<typeof decisionPayloadSchema>;
|
|
97
|
+
export type CancelTaskPayload = z.infer<typeof cancelTaskPayloadSchema>;
|
|
98
|
+
export type SettleTaskPayload = z.infer<typeof settleTaskPayloadSchema>;
|
|
99
|
+
export type TaskQueryPayload = z.infer<typeof taskQueryPayloadSchema>;
|
|
100
|
+
export type TaskResponsesQueryPayload = z.infer<typeof taskResponsesQueryPayloadSchema>;
|
|
101
|
+
export type WorkerResponsesQueryPayload = z.infer<typeof workerResponsesQueryPayloadSchema>;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"rootDir": ".",
|
|
12
|
+
"outDir": "dist"
|
|
13
|
+
},
|
|
14
|
+
"include": ["index.ts", "src/**/*.ts"],
|
|
15
|
+
"exclude": ["node_modules", "dist"]
|
|
16
|
+
}
|