@blindmarket/sdk 0.1.6 → 0.1.8

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 (156) hide show
  1. package/README.md +242 -29
  2. package/dist/chain/BlindEscrowClient.d.ts +2 -0
  3. package/dist/chain/BlindEscrowClient.js +19 -7
  4. package/dist/chain/BlindReputationClient.d.ts +3 -0
  5. package/dist/chain/BlindReputationClient.js +3 -1
  6. package/dist/chain/ChainClient.d.ts +6 -3
  7. package/dist/chain/ChainClient.js +6 -1
  8. package/dist/chain/IBlindMarketChain.d.ts +74 -0
  9. package/dist/chain/IBlindMarketChain.js +1 -0
  10. package/dist/chain/TaskRegistryClient.d.ts +2 -1
  11. package/dist/chain/TaskRegistryClient.js +15 -7
  12. package/dist/chain/createChainAdapter.d.ts +25 -0
  13. package/dist/chain/createChainAdapter.js +24 -0
  14. package/dist/chain/domain-types.d.ts +77 -0
  15. package/dist/chain/domain-types.js +1 -0
  16. package/dist/chain/evm/EVMChainAdapter.d.ts +56 -0
  17. package/dist/chain/evm/EVMChainAdapter.js +161 -0
  18. package/dist/chain/evm/index.d.ts +1 -0
  19. package/dist/chain/evm/index.js +1 -0
  20. package/dist/chain/index.d.ts +4 -0
  21. package/dist/chain/index.js +5 -0
  22. package/dist/crypto/constants.js +1 -1
  23. package/dist/errors/{BlindBountyError.d.ts → BlindMarketError.d.ts} +1 -1
  24. package/dist/errors/{BlindBountyError.js → BlindMarketError.js} +1 -1
  25. package/dist/errors/index.d.ts +1 -1
  26. package/dist/errors/index.js +1 -1
  27. package/dist/errors/subclasses.d.ts +9 -9
  28. package/dist/errors/subclasses.js +9 -9
  29. package/dist/executor/WorkerRuntime.d.ts +113 -0
  30. package/dist/executor/WorkerRuntime.js +248 -0
  31. package/dist/executor/index.d.ts +1 -0
  32. package/dist/executor/index.js +1 -0
  33. package/dist/index.d.ts +292 -22
  34. package/dist/index.js +413 -23
  35. package/dist/keystore/InMemoryKeyStore.js +2 -2
  36. package/dist/network/presets.d.ts +33 -5
  37. package/dist/network/presets.js +35 -8
  38. package/dist/network/resolve.d.ts +12 -3
  39. package/dist/network/resolve.js +15 -7
  40. package/dist/network/types.d.ts +3 -16
  41. package/dist/signer/EthersSigner.js +1 -1
  42. package/dist/storage/index.d.ts +0 -1
  43. package/dist/storage/index.js +1 -1
  44. package/dist/tools/adapters.d.ts +99 -0
  45. package/dist/tools/adapters.js +129 -0
  46. package/dist/tools/helpers.d.ts +9 -0
  47. package/dist/tools/helpers.js +169 -0
  48. package/dist/tools/index.d.ts +36 -0
  49. package/dist/tools/index.js +32 -0
  50. package/dist/tools/types.d.ts +44 -0
  51. package/dist/tools/types.js +1 -0
  52. package/dist/types.d.ts +202 -1
  53. package/dist/types.js +24 -1
  54. package/package.json +13 -2
  55. package/src/chain/BlindEscrowClient.ts +20 -6
  56. package/src/chain/BlindReputationClient.ts +6 -1
  57. package/src/chain/ChainClient.ts +9 -3
  58. package/src/chain/IBlindMarketChain.ts +109 -0
  59. package/src/chain/TaskRegistryClient.ts +17 -8
  60. package/src/chain/createChainAdapter.ts +40 -0
  61. package/src/chain/domain-types.ts +92 -0
  62. package/src/chain/evm/EVMChainAdapter.ts +212 -0
  63. package/src/chain/evm/index.ts +1 -0
  64. package/src/chain/index.ts +6 -0
  65. package/src/executor/WorkerRuntime.ts +338 -0
  66. package/src/executor/index.ts +8 -0
  67. package/src/index.ts +546 -36
  68. package/src/network/presets.ts +47 -8
  69. package/src/network/resolve.ts +20 -8
  70. package/src/network/types.ts +18 -16
  71. package/src/signer/index.ts +1 -1
  72. package/src/storage/index.ts +1 -1
  73. package/src/tools/adapters.ts +177 -0
  74. package/src/tools/helpers.ts +199 -0
  75. package/src/tools/index.ts +59 -0
  76. package/src/tools/types.ts +47 -0
  77. package/src/types.ts +222 -1
  78. package/tsconfig.json +2 -1
  79. package/dist/BlindEscrowClient-CyPuKMge.d.cts +0 -54
  80. package/dist/BlindEscrowClient-R7iGpE-n.d.ts +0 -54
  81. package/dist/KeyStore-Be_SSpCt.d.cts +0 -21
  82. package/dist/KeyStore-k1JgYPJY.d.ts +0 -21
  83. package/dist/Signer-BnqH_qew.d.cts +0 -38
  84. package/dist/Signer-LColE0Uo.d.ts +0 -38
  85. package/dist/Storage-4QOrh7rm.d.ts +0 -17
  86. package/dist/Storage-Cf4IJRMk.d.cts +0 -17
  87. package/dist/TaskRegistryClient-Ch6lYqM_.d.ts +0 -24
  88. package/dist/TaskRegistryClient-CrQjddDc.d.cts +0 -24
  89. package/dist/aes-J-7HrHze.d.cts +0 -17
  90. package/dist/aes-J-7HrHze.d.ts +0 -17
  91. package/dist/agent/index.cjs +0 -425
  92. package/dist/agent/index.cjs.map +0 -1
  93. package/dist/agent/index.d.cts +0 -63
  94. package/dist/agent/index.js.map +0 -1
  95. package/dist/api/index.cjs +0 -4
  96. package/dist/api/index.cjs.map +0 -1
  97. package/dist/api/index.d.cts +0 -2
  98. package/dist/api/index.js.map +0 -1
  99. package/dist/chain/index.cjs +0 -2484
  100. package/dist/chain/index.cjs.map +0 -1
  101. package/dist/chain/index.d.cts +0 -2305
  102. package/dist/chain/index.js.map +0 -1
  103. package/dist/compute/index.cjs +0 -4
  104. package/dist/compute/index.cjs.map +0 -1
  105. package/dist/compute/index.d.cts +0 -2
  106. package/dist/compute/index.js.map +0 -1
  107. package/dist/crypto/index.cjs +0 -424
  108. package/dist/crypto/index.cjs.map +0 -1
  109. package/dist/crypto/index.d.cts +0 -74
  110. package/dist/crypto/index.js.map +0 -1
  111. package/dist/errors/index.cjs +0 -136
  112. package/dist/errors/index.cjs.map +0 -1
  113. package/dist/errors/index.d.cts +0 -60
  114. package/dist/errors/index.js.map +0 -1
  115. package/dist/events/index.cjs +0 -41
  116. package/dist/events/index.cjs.map +0 -1
  117. package/dist/events/index.d.cts +0 -61
  118. package/dist/events/index.js.map +0 -1
  119. package/dist/index.cjs +0 -4
  120. package/dist/index.cjs.map +0 -1
  121. package/dist/index.d.cts +0 -2
  122. package/dist/index.js.map +0 -1
  123. package/dist/keystore/index.cjs +0 -335
  124. package/dist/keystore/index.cjs.map +0 -1
  125. package/dist/keystore/index.d.cts +0 -23
  126. package/dist/keystore/index.js.map +0 -1
  127. package/dist/network/index.cjs +0 -74
  128. package/dist/network/index.cjs.map +0 -1
  129. package/dist/network/index.d.cts +0 -36
  130. package/dist/network/index.js.map +0 -1
  131. package/dist/signer/index.cjs +0 -121
  132. package/dist/signer/index.cjs.map +0 -1
  133. package/dist/signer/index.d.cts +0 -40
  134. package/dist/signer/index.js.map +0 -1
  135. package/dist/storage/ZgStorage.d.ts +0 -24
  136. package/dist/storage/ZgStorage.js +0 -102
  137. package/dist/storage/index.cjs +0 -221
  138. package/dist/storage/index.cjs.map +0 -1
  139. package/dist/storage/index.d.cts +0 -44
  140. package/dist/storage/index.js.map +0 -1
  141. package/dist/testing/index.cjs +0 -4
  142. package/dist/testing/index.cjs.map +0 -1
  143. package/dist/testing/index.d.cts +0 -2
  144. package/dist/testing/index.js.map +0 -1
  145. package/dist/types-BOG5Ub1z.d.cts +0 -31
  146. package/dist/types-BOG5Ub1z.d.ts +0 -31
  147. package/dist/types-V7_ZmUb-.d.cts +0 -19
  148. package/dist/types-hAsITUQ7.d.ts +0 -19
  149. package/dist/verifier/index.cjs +0 -4
  150. package/dist/verifier/index.cjs.map +0 -1
  151. package/dist/verifier/index.d.cts +0 -2
  152. package/dist/verifier/index.js.map +0 -1
  153. package/dist/worker/index.cjs +0 -382
  154. package/dist/worker/index.cjs.map +0 -1
  155. package/dist/worker/index.d.cts +0 -58
  156. package/dist/worker/index.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ import type { Address, Hex, TaskId, TaskStatus } from '../types.js';
2
+ export type BlockchainType = 'evm';
3
+ /** Base fields shared by all chain network configs. */
4
+ export interface NetworkBase {
5
+ name: string;
6
+ chainType: BlockchainType;
7
+ rpc: string[];
8
+ explorer?: string;
9
+ }
10
+ /** EVM-compatible chain network config (0G, Ethereum, Polygon, etc.). */
11
+ export interface EVMNetwork extends NetworkBase {
12
+ chainType: 'evm';
13
+ chainId: number;
14
+ contracts: {
15
+ escrow: Address;
16
+ registry: Address;
17
+ reputation: Address;
18
+ usdc: Address;
19
+ };
20
+ indexer?: string;
21
+ broker?: string;
22
+ }
23
+ /** Union of all supported chain network configs. */
24
+ export type Network = EVMNetwork;
25
+ /** Parameters for creating a task on any chain. */
26
+ export interface CreateTaskParams {
27
+ taskHash: Hex;
28
+ token: Address | string;
29
+ amount: bigint;
30
+ category: string;
31
+ locationZone: string;
32
+ deadline: bigint;
33
+ /** Per-task verifier address (agent-verification mode). Optional. */
34
+ verifierAgent?: string;
35
+ }
36
+ /** Decoded on-chain task representation (chain-agnostic). */
37
+ export interface DomainTask {
38
+ taskId: TaskId;
39
+ agent: string;
40
+ worker: string;
41
+ token: string;
42
+ amount: bigint;
43
+ taskHash: Hex;
44
+ evidenceHash: Hex;
45
+ status: TaskStatus;
46
+ category: string;
47
+ locationZone: string;
48
+ createdAt: Date;
49
+ deadline: Date;
50
+ }
51
+ /** Task metadata used for discovery / listing. */
52
+ export interface DomainTaskMeta {
53
+ taskId: TaskId;
54
+ agent: string;
55
+ category: string;
56
+ locationZone: string;
57
+ reward: bigint;
58
+ createdAt: Date;
59
+ isOpen: boolean;
60
+ }
61
+ /** On-chain reputation snapshot (chain-agnostic). */
62
+ export interface DomainReputation {
63
+ tasksCompleted: bigint;
64
+ totalScore: bigint;
65
+ disputes: bigint;
66
+ avgScore: number;
67
+ }
68
+ /** Transaction receipt (chain-agnostic). */
69
+ export interface DomainTxReceipt {
70
+ hash: string;
71
+ blockNumber?: number;
72
+ }
73
+ /** Signer abstraction that works across chains. */
74
+ export interface ChainSigner {
75
+ getAddress(): Promise<string>;
76
+ getChainType(): BlockchainType;
77
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
1
+ import { ethers } from 'ethers';
2
+ import { type ChainClientOptions } from '../ChainClient.js';
3
+ import type { CreateTaskParams, DomainReputation, DomainTask, DomainTaskMeta, DomainTxReceipt, EVMNetwork } from '../domain-types.js';
4
+ import type { IBlindMarketChain } from '../IBlindMarketChain.js';
5
+ /**
6
+ * EVM-compatible implementation of IBlindMarketChain.
7
+ *
8
+ * Wraps the existing ChainClient (which bundles BlindEscrowClient,
9
+ * TaskRegistryClient, and BlindReputationClient) and translates domain
10
+ * operations into ethers v6 contract calls on EVM chains (0G, Ethereum, etc.).
11
+ */
12
+ export declare class EVMChainAdapter implements IBlindMarketChain {
13
+ readonly network: EVMNetwork;
14
+ private client;
15
+ private signer;
16
+ constructor(opts: ChainClientOptions);
17
+ getAddress(): Promise<string>;
18
+ createTask(params: CreateTaskParams): Promise<{
19
+ taskId: bigint;
20
+ receipt: DomainTxReceipt;
21
+ }>;
22
+ assignWorker(taskId: bigint, worker: string): Promise<DomainTxReceipt>;
23
+ submitEvidence(taskId: bigint, evidenceHash: string): Promise<DomainTxReceipt>;
24
+ completeVerification(taskId: bigint, passed: boolean): Promise<DomainTxReceipt>;
25
+ cancelTask(taskId: bigint): Promise<DomainTxReceipt>;
26
+ claimTimeout(taskId: bigint): Promise<DomainTxReceipt>;
27
+ raiseDispute(taskId: bigint): Promise<DomainTxReceipt>;
28
+ resolveDispute(taskId: bigint, workerFavored: boolean): Promise<DomainTxReceipt>;
29
+ getTask(taskId: bigint): Promise<DomainTask>;
30
+ isTaskExpired(taskId: bigint): Promise<boolean>;
31
+ publishTask(taskId: bigint, _meta: Omit<DomainTaskMeta, 'taskId'> & {
32
+ taskId?: bigint;
33
+ }): Promise<DomainTxReceipt>;
34
+ closeTask(taskId: bigint): Promise<DomainTxReceipt>;
35
+ getOpenTasks(offset: bigint, limit: bigint): Promise<DomainTaskMeta[]>;
36
+ openTaskCount(): Promise<bigint>;
37
+ totalTasks(): Promise<bigint>;
38
+ rateWorker(worker: string, score: number, taskId: bigint): Promise<DomainTxReceipt>;
39
+ recordDispute(worker: string, taskId: bigint): Promise<DomainTxReceipt>;
40
+ getReputation(worker: string): Promise<DomainReputation>;
41
+ hasBeenRated(worker: string, taskId: bigint): Promise<boolean>;
42
+ mintAgent(params: {
43
+ to: string;
44
+ encryptedURI: string;
45
+ metadataHash: string;
46
+ }): Promise<{
47
+ tokenId: bigint;
48
+ receipt: DomainTxReceipt;
49
+ }>;
50
+ getEncryptedURI(_tokenId: bigint): Promise<string>;
51
+ getBalance(address: string): Promise<bigint>;
52
+ /** Get the underlying ethers Provider for raw queries. */
53
+ getProvider(): ethers.Provider;
54
+ /** Get the underlying ethers Signer (if configured). */
55
+ getEthersSigner(): ethers.Signer | undefined;
56
+ }
@@ -0,0 +1,161 @@
1
+ import { ChainClient } from '../ChainClient.js';
2
+ import { resolveNetwork } from '../../network/resolve.js';
3
+ /**
4
+ * EVM-compatible implementation of IBlindMarketChain.
5
+ *
6
+ * Wraps the existing ChainClient (which bundles BlindEscrowClient,
7
+ * TaskRegistryClient, and BlindReputationClient) and translates domain
8
+ * operations into ethers v6 contract calls on EVM chains (0G, Ethereum, etc.).
9
+ */
10
+ export class EVMChainAdapter {
11
+ network;
12
+ client;
13
+ signer;
14
+ constructor(opts) {
15
+ const resolved = resolveNetwork(opts.network);
16
+ if (resolved.chainType !== 'evm') {
17
+ throw new Error(`EVMChainAdapter requires an EVM network, got ${resolved.chainType}`);
18
+ }
19
+ this.network = resolved;
20
+ this.client = new ChainClient(opts);
21
+ this.signer = opts.signer;
22
+ }
23
+ async getAddress() {
24
+ if (!this.signer)
25
+ throw new Error('No signer configured');
26
+ return this.signer.getAddress();
27
+ }
28
+ // ── Task lifecycle ──────────────────────────────────────────────────────
29
+ async createTask(params) {
30
+ const result = await this.client.escrow.createTask({
31
+ taskHash: params.taskHash,
32
+ token: params.token,
33
+ amount: params.amount,
34
+ category: params.category,
35
+ locationZone: params.locationZone,
36
+ deadline: params.deadline,
37
+ });
38
+ return {
39
+ taskId: result.taskId,
40
+ receipt: {
41
+ hash: result.receipt.hash,
42
+ blockNumber: result.receipt.blockNumber,
43
+ },
44
+ };
45
+ }
46
+ async assignWorker(taskId, worker) {
47
+ const receipt = await this.client.escrow.assignWorker(taskId, worker);
48
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
49
+ }
50
+ async submitEvidence(taskId, evidenceHash) {
51
+ const receipt = await this.client.escrow.submitEvidence(taskId, evidenceHash);
52
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
53
+ }
54
+ async completeVerification(taskId, passed) {
55
+ const receipt = await this.client.escrow.completeVerification(taskId, passed);
56
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
57
+ }
58
+ async cancelTask(taskId) {
59
+ const receipt = await this.client.escrow.cancelTask(taskId);
60
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
61
+ }
62
+ async claimTimeout(taskId) {
63
+ const receipt = await this.client.escrow.claimTimeout(taskId);
64
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
65
+ }
66
+ async raiseDispute(taskId) {
67
+ const receipt = await this.client.escrow.raiseDispute(taskId);
68
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
69
+ }
70
+ async resolveDispute(taskId, workerFavored) {
71
+ const receipt = await this.client.escrow.resolveDispute(taskId, workerFavored);
72
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
73
+ }
74
+ async getTask(taskId) {
75
+ const onChain = await this.client.escrow.getTask(taskId);
76
+ return {
77
+ ...onChain,
78
+ category: '', // OnChainTask doesn't decode these contract fields;
79
+ locationZone: '', // they are present in the Solidity Task struct.
80
+ };
81
+ }
82
+ async isTaskExpired(taskId) {
83
+ return this.client.escrow.isTaskExpired(taskId);
84
+ }
85
+ // ── Task discovery ──────────────────────────────────────────────────────
86
+ async publishTask(taskId, _meta) {
87
+ // The EVM contracts publish tasks via the escrow's TaskCreated event
88
+ // (handled by the backend indexer). This is a no-op at the adapter level
89
+ // for EVM — the registry is updated by the escrow contract internally.
90
+ // Return a stub receipt for interface compatibility.
91
+ return { hash: '0x0', blockNumber: 0 };
92
+ }
93
+ async closeTask(taskId) {
94
+ const receipt = await this.client.registry.closeTask(taskId);
95
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
96
+ }
97
+ async getOpenTasks(offset, limit) {
98
+ const taskIds = await this.client.registry.getOpenTasks(offset, limit);
99
+ const metas = await Promise.all(taskIds.map(async (tid) => {
100
+ const meta = await this.client.registry.getTaskMeta(tid);
101
+ return {
102
+ taskId: tid,
103
+ agent: '', // EVM TaskRegistry stores agent; use meta directly
104
+ category: meta.category,
105
+ locationZone: meta.locationZone,
106
+ reward: meta.reward,
107
+ createdAt: meta.createdAt,
108
+ isOpen: true,
109
+ };
110
+ }));
111
+ return metas;
112
+ }
113
+ async openTaskCount() {
114
+ return this.client.registry.openTaskCount();
115
+ }
116
+ async totalTasks() {
117
+ return this.client.registry.totalTasks();
118
+ }
119
+ // ── Reputation ──────────────────────────────────────────────────────────
120
+ async rateWorker(worker, score, taskId) {
121
+ const receipt = await this.client.reputation.rate(worker, score, taskId);
122
+ return { hash: receipt.hash, blockNumber: receipt.blockNumber };
123
+ }
124
+ async recordDispute(worker, taskId) {
125
+ // EVM BlindReputation doesn't expose recordDispute as a standalone client
126
+ // method in the SDK — the escrow calls it internally. For external callers
127
+ // we throw. The escrow contract handles dispute recording via its own path.
128
+ throw new Error('recordDispute is handled internally by BlindEscrow on EVM chains');
129
+ }
130
+ async getReputation(worker) {
131
+ return this.client.reputation.getReputation(worker);
132
+ }
133
+ async hasBeenRated(worker, taskId) {
134
+ return this.client.reputation.hasBeenRated(worker, taskId);
135
+ }
136
+ // ── Agent identity ──────────────────────────────────────────────────────
137
+ async mintAgent(params) {
138
+ // INFT minting is handled by the backend (services/chain.ts → inft.mint()).
139
+ // The SDK doesn't expose a direct INFT client. For direct EVM calls,
140
+ // consumers can use the raw ethers.Contract via the unwrapped signer.
141
+ throw new Error('INFT minting is backend-managed on EVM chains. Use the REST API or raw ethers.Contract.');
142
+ }
143
+ async getEncryptedURI(_tokenId) {
144
+ throw new Error('INFT URI reading is backend-managed on EVM chains. Use the REST API or raw ethers.Contract.');
145
+ }
146
+ // ── Queries ─────────────────────────────────────────────────────────────
147
+ async getBalance(address) {
148
+ return this.client.provider.getBalance(address);
149
+ }
150
+ // ── Accessors for direct ethers access (advanced use) ───────────────────
151
+ /** Get the underlying ethers Provider for raw queries. */
152
+ getProvider() {
153
+ return this.client.provider;
154
+ }
155
+ /** Get the underlying ethers Signer (if configured). */
156
+ getEthersSigner() {
157
+ if (!this.signer)
158
+ return undefined;
159
+ return this.signer.inner;
160
+ }
161
+ }
@@ -0,0 +1 @@
1
+ export { EVMChainAdapter } from './EVMChainAdapter.js';
@@ -0,0 +1 @@
1
+ export { EVMChainAdapter } from './EVMChainAdapter.js';
@@ -4,3 +4,7 @@ export * from './BlindEscrowClient.js';
4
4
  export * from './TaskRegistryClient.js';
5
5
  export * from './BlindReputationClient.js';
6
6
  export * from './ChainClient.js';
7
+ export * from './IBlindMarketChain.js';
8
+ export * from './domain-types.js';
9
+ export * from './createChainAdapter.js';
10
+ export * from './evm/index.js';
@@ -4,3 +4,8 @@ export * from './BlindEscrowClient.js';
4
4
  export * from './TaskRegistryClient.js';
5
5
  export * from './BlindReputationClient.js';
6
6
  export * from './ChainClient.js';
7
+ // Chain-agnostic domain interface (EVM only — 0G Chain)
8
+ export * from './IBlindMarketChain.js';
9
+ export * from './domain-types.js';
10
+ export * from './createChainAdapter.js';
11
+ export * from './evm/index.js';
@@ -2,6 +2,6 @@ export const IV_LENGTH = 12;
2
2
  export const TAG_LENGTH = 16;
3
3
  export const KEY_LENGTH = 32;
4
4
  export const ECIES_PUBKEY_LENGTH = 65;
5
- export const ECIES_HKDF_INFO = new TextEncoder().encode('BlindBounty-ECIES-v1');
5
+ export const ECIES_HKDF_INFO = new TextEncoder().encode('BlindMarket-ECIES-v1');
6
6
  export const AES_MIN_BLOB = IV_LENGTH + TAG_LENGTH;
7
7
  export const ECIES_MIN_BLOB = ECIES_PUBKEY_LENGTH + AES_MIN_BLOB;
@@ -4,7 +4,7 @@ export interface ErrorOptions {
4
4
  context?: Record<string, unknown>;
5
5
  cause?: unknown;
6
6
  }
7
- export declare abstract class BlindBountyError extends Error {
7
+ export declare abstract class BlindMarketError extends Error {
8
8
  readonly code: ErrorCode;
9
9
  readonly retriable: boolean;
10
10
  readonly context?: Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- export class BlindBountyError extends Error {
1
+ export class BlindMarketError extends Error {
2
2
  code;
3
3
  retriable;
4
4
  context;
@@ -1,3 +1,3 @@
1
1
  export * from './codes.js';
2
- export * from './BlindBountyError.js';
2
+ export * from './BlindMarketError.js';
3
3
  export * from './subclasses.js';
@@ -1,3 +1,3 @@
1
1
  export * from './codes.js';
2
- export * from './BlindBountyError.js';
2
+ export * from './BlindMarketError.js';
3
3
  export * from './subclasses.js';
@@ -1,26 +1,26 @@
1
- import { BlindBountyError, type ErrorOptions } from './BlindBountyError.js';
1
+ import { BlindMarketError, type ErrorOptions } from './BlindMarketError.js';
2
2
  import type { ApiCode, ChainCode, ComputeCode, ConfigCode, CryptoCode, LifecycleCode, StorageCode, TimeoutCode } from './codes.js';
3
- export declare class ConfigError extends BlindBountyError {
3
+ export declare class ConfigError extends BlindMarketError {
4
4
  constructor(code: ConfigCode, msg: string, opts?: ErrorOptions);
5
5
  }
6
- export declare class CryptoError extends BlindBountyError {
6
+ export declare class CryptoError extends BlindMarketError {
7
7
  constructor(code: CryptoCode, msg: string, opts?: ErrorOptions);
8
8
  }
9
- export declare class StorageError extends BlindBountyError {
9
+ export declare class StorageError extends BlindMarketError {
10
10
  constructor(code: StorageCode, msg: string, opts?: ErrorOptions);
11
11
  }
12
- export declare class ChainError extends BlindBountyError {
12
+ export declare class ChainError extends BlindMarketError {
13
13
  constructor(code: ChainCode, msg: string, opts?: ErrorOptions);
14
14
  }
15
- export declare class ComputeError extends BlindBountyError {
15
+ export declare class ComputeError extends BlindMarketError {
16
16
  constructor(code: ComputeCode, msg: string, opts?: ErrorOptions);
17
17
  }
18
- export declare class ApiError extends BlindBountyError {
18
+ export declare class ApiError extends BlindMarketError {
19
19
  constructor(code: ApiCode, msg: string, opts?: ErrorOptions);
20
20
  }
21
- export declare class LifecycleError extends BlindBountyError {
21
+ export declare class LifecycleError extends BlindMarketError {
22
22
  constructor(code: LifecycleCode, msg: string, opts?: ErrorOptions);
23
23
  }
24
- export declare class TimeoutError extends BlindBountyError {
24
+ export declare class TimeoutError extends BlindMarketError {
25
25
  constructor(code: TimeoutCode, msg: string, opts?: ErrorOptions);
26
26
  }
@@ -1,40 +1,40 @@
1
- import { BlindBountyError } from './BlindBountyError.js';
2
- export class ConfigError extends BlindBountyError {
1
+ import { BlindMarketError } from './BlindMarketError.js';
2
+ export class ConfigError extends BlindMarketError {
3
3
  constructor(code, msg, opts) {
4
4
  super(code, msg, opts);
5
5
  }
6
6
  }
7
- export class CryptoError extends BlindBountyError {
7
+ export class CryptoError extends BlindMarketError {
8
8
  constructor(code, msg, opts) {
9
9
  super(code, msg, opts);
10
10
  }
11
11
  }
12
- export class StorageError extends BlindBountyError {
12
+ export class StorageError extends BlindMarketError {
13
13
  constructor(code, msg, opts) {
14
14
  super(code, msg, opts);
15
15
  }
16
16
  }
17
- export class ChainError extends BlindBountyError {
17
+ export class ChainError extends BlindMarketError {
18
18
  constructor(code, msg, opts) {
19
19
  super(code, msg, opts);
20
20
  }
21
21
  }
22
- export class ComputeError extends BlindBountyError {
22
+ export class ComputeError extends BlindMarketError {
23
23
  constructor(code, msg, opts) {
24
24
  super(code, msg, opts);
25
25
  }
26
26
  }
27
- export class ApiError extends BlindBountyError {
27
+ export class ApiError extends BlindMarketError {
28
28
  constructor(code, msg, opts) {
29
29
  super(code, msg, opts);
30
30
  }
31
31
  }
32
- export class LifecycleError extends BlindBountyError {
32
+ export class LifecycleError extends BlindMarketError {
33
33
  constructor(code, msg, opts) {
34
34
  super(code, msg, opts);
35
35
  }
36
36
  }
37
- export class TimeoutError extends BlindBountyError {
37
+ export class TimeoutError extends BlindMarketError {
38
38
  constructor(code, msg, opts) {
39
39
  super(code, msg, opts);
40
40
  }
@@ -0,0 +1,113 @@
1
+ import type { A2ATaskState, AgentCapability, ExecutorProfile, Message } from '../types.js';
2
+ export interface WorkerRuntimeConfig {
3
+ apiKey: string;
4
+ apiBase?: string;
5
+ displayName: string;
6
+ capabilities: AgentCapability[];
7
+ executeTask: ExecuteTaskHandler;
8
+ existingPrivateKey?: string;
9
+ existingAddress?: string;
10
+ existingPublicKey?: string;
11
+ minReward?: string;
12
+ preferredCapabilities?: AgentCapability[];
13
+ browseIntervalMs?: number;
14
+ watchIntervalMs?: number;
15
+ maxConcurrentTasks?: number;
16
+ }
17
+ export type ExecuteTaskHandler = (ctx: TaskContext) => Promise<Record<string, unknown>>;
18
+ export interface TaskContext {
19
+ taskId: string;
20
+ task: A2ATaskState;
21
+ instructions: string;
22
+ }
23
+ export interface TaskExecutionInfo {
24
+ taskId: string;
25
+ status: 'bidding' | 'assigned' | 'working' | 'submitted' | 'completed' | 'failed';
26
+ task?: A2ATaskState;
27
+ error?: string;
28
+ startedAt: number;
29
+ }
30
+ export type WorkerRuntimeEvent = {
31
+ type: 'started';
32
+ } | {
33
+ type: 'stopped';
34
+ } | {
35
+ type: 'paused';
36
+ } | {
37
+ type: 'resumed';
38
+ } | {
39
+ type: 'registered';
40
+ profile: ExecutorProfile;
41
+ } | {
42
+ type: 'task_found';
43
+ taskId: string;
44
+ task: A2ATaskState;
45
+ } | {
46
+ type: 'task_bidded';
47
+ taskId: string;
48
+ } | {
49
+ type: 'task_assigned';
50
+ taskId: string;
51
+ } | {
52
+ type: 'task_accepted';
53
+ taskId: string;
54
+ } | {
55
+ type: 'task_working';
56
+ taskId: string;
57
+ } | {
58
+ type: 'task_executed';
59
+ taskId: string;
60
+ } | {
61
+ type: 'task_submitted';
62
+ taskId: string;
63
+ result: Record<string, unknown>;
64
+ } | {
65
+ type: 'task_failed';
66
+ taskId: string;
67
+ error: string;
68
+ } | {
69
+ type: 'message_received';
70
+ message: Message;
71
+ count: number;
72
+ } | {
73
+ type: 'browse_done';
74
+ found: number;
75
+ } | {
76
+ type: 'error';
77
+ error: string;
78
+ };
79
+ export declare class WorkerRuntime {
80
+ private bb;
81
+ private config;
82
+ private wallet?;
83
+ private profile?;
84
+ private running;
85
+ private paused;
86
+ private browseTimer?;
87
+ private watchTimers;
88
+ private executions;
89
+ private listeners;
90
+ constructor(config: WorkerRuntimeConfig);
91
+ get isRunning(): boolean;
92
+ get isPaused(): boolean;
93
+ get activeExecutions(): TaskExecutionInfo[];
94
+ /** Get own executor profile (available after start). */
95
+ get executorProfile(): ExecutorProfile | undefined;
96
+ /** Get own wallet info (available after start). */
97
+ get executorWallet(): {
98
+ address: string;
99
+ publicKey: string;
100
+ } | undefined;
101
+ on(listener: (event: WorkerRuntimeEvent) => void): () => void;
102
+ private emit;
103
+ start(): Promise<ExecutorProfile>;
104
+ stop(): void;
105
+ pause(): void;
106
+ resume(): void;
107
+ private startBrowseLoop;
108
+ private browse;
109
+ private watchForAssignment;
110
+ private executeTask;
111
+ private decodeWrappedKey;
112
+ private hexToBytes;
113
+ }