@blindmarket/sdk 0.1.4

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 (244) hide show
  1. package/README.md +72 -0
  2. package/biome.json +19 -0
  3. package/dist/BlindEscrowClient-CyPuKMge.d.cts +54 -0
  4. package/dist/BlindEscrowClient-R7iGpE-n.d.ts +54 -0
  5. package/dist/KeyStore-Be_SSpCt.d.cts +21 -0
  6. package/dist/KeyStore-k1JgYPJY.d.ts +21 -0
  7. package/dist/Signer-BnqH_qew.d.cts +38 -0
  8. package/dist/Signer-LColE0Uo.d.ts +38 -0
  9. package/dist/Storage-4QOrh7rm.d.ts +17 -0
  10. package/dist/Storage-Cf4IJRMk.d.cts +17 -0
  11. package/dist/TaskRegistryClient-Ch6lYqM_.d.ts +24 -0
  12. package/dist/TaskRegistryClient-CrQjddDc.d.cts +24 -0
  13. package/dist/aes-J-7HrHze.d.cts +17 -0
  14. package/dist/aes-J-7HrHze.d.ts +17 -0
  15. package/dist/agent/Agent.d.ts +59 -0
  16. package/dist/agent/Agent.js +73 -0
  17. package/dist/agent/index.cjs +425 -0
  18. package/dist/agent/index.cjs.map +1 -0
  19. package/dist/agent/index.d.cts +63 -0
  20. package/dist/agent/index.d.ts +1 -0
  21. package/dist/agent/index.js +1 -0
  22. package/dist/agent/index.js.map +1 -0
  23. package/dist/api/index.cjs +4 -0
  24. package/dist/api/index.cjs.map +1 -0
  25. package/dist/api/index.d.cts +2 -0
  26. package/dist/api/index.d.ts +1 -0
  27. package/dist/api/index.js +1 -0
  28. package/dist/api/index.js.map +1 -0
  29. package/dist/chain/BlindEscrowClient.d.ts +51 -0
  30. package/dist/chain/BlindEscrowClient.js +142 -0
  31. package/dist/chain/BlindReputationClient.d.ts +16 -0
  32. package/dist/chain/BlindReputationClient.js +45 -0
  33. package/dist/chain/ChainClient.d.ts +26 -0
  34. package/dist/chain/ChainClient.js +46 -0
  35. package/dist/chain/TaskRegistryClient.d.ts +21 -0
  36. package/dist/chain/TaskRegistryClient.js +70 -0
  37. package/dist/chain/abi/BlindEscrow.json +1113 -0
  38. package/dist/chain/abi/BlindReputation.json +447 -0
  39. package/dist/chain/abi/TaskRegistry.json +586 -0
  40. package/dist/chain/abi/index.d.ts +4 -0
  41. package/dist/chain/abi/index.js +4 -0
  42. package/dist/chain/errors.d.ts +8 -0
  43. package/dist/chain/errors.js +32 -0
  44. package/dist/chain/index.cjs +2484 -0
  45. package/dist/chain/index.cjs.map +1 -0
  46. package/dist/chain/index.d.cts +2305 -0
  47. package/dist/chain/index.d.ts +6 -0
  48. package/dist/chain/index.js +6 -0
  49. package/dist/chain/index.js.map +1 -0
  50. package/dist/compute/index.cjs +4 -0
  51. package/dist/compute/index.cjs.map +1 -0
  52. package/dist/compute/index.d.cts +2 -0
  53. package/dist/compute/index.d.ts +1 -0
  54. package/dist/compute/index.js +1 -0
  55. package/dist/compute/index.js.map +1 -0
  56. package/dist/crypto/aes.d.ts +15 -0
  57. package/dist/crypto/aes.js +81 -0
  58. package/dist/crypto/constants.d.ts +7 -0
  59. package/dist/crypto/constants.js +7 -0
  60. package/dist/crypto/ecies.d.ts +8 -0
  61. package/dist/crypto/ecies.js +51 -0
  62. package/dist/crypto/envelope.d.ts +35 -0
  63. package/dist/crypto/envelope.js +103 -0
  64. package/dist/crypto/hkdf.d.ts +5 -0
  65. package/dist/crypto/hkdf.js +34 -0
  66. package/dist/crypto/index.cjs +424 -0
  67. package/dist/crypto/index.cjs.map +1 -0
  68. package/dist/crypto/index.d.cts +74 -0
  69. package/dist/crypto/index.d.ts +6 -0
  70. package/dist/crypto/index.js +6 -0
  71. package/dist/crypto/index.js.map +1 -0
  72. package/dist/crypto/keys.d.ts +12 -0
  73. package/dist/crypto/keys.js +42 -0
  74. package/dist/errors/BlindBountyError.d.ts +14 -0
  75. package/dist/errors/BlindBountyError.js +30 -0
  76. package/dist/errors/codes.d.ts +19 -0
  77. package/dist/errors/codes.js +48 -0
  78. package/dist/errors/index.cjs +136 -0
  79. package/dist/errors/index.cjs.map +1 -0
  80. package/dist/errors/index.d.cts +60 -0
  81. package/dist/errors/index.d.ts +3 -0
  82. package/dist/errors/index.js +3 -0
  83. package/dist/errors/index.js.map +1 -0
  84. package/dist/errors/subclasses.d.ts +26 -0
  85. package/dist/errors/subclasses.js +41 -0
  86. package/dist/events/EventBus.d.ts +13 -0
  87. package/dist/events/EventBus.js +41 -0
  88. package/dist/events/index.cjs +41 -0
  89. package/dist/events/index.cjs.map +1 -0
  90. package/dist/events/index.d.cts +61 -0
  91. package/dist/events/index.d.ts +2 -0
  92. package/dist/events/index.js +2 -0
  93. package/dist/events/index.js.map +1 -0
  94. package/dist/events/types.d.ts +45 -0
  95. package/dist/events/types.js +1 -0
  96. package/dist/index.cjs +4 -0
  97. package/dist/index.cjs.map +1 -0
  98. package/dist/index.d.cts +2 -0
  99. package/dist/index.d.ts +129 -0
  100. package/dist/index.js +154 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/keystore/InMemoryKeyStore.d.ts +21 -0
  103. package/dist/keystore/InMemoryKeyStore.js +111 -0
  104. package/dist/keystore/KeyStore.d.ts +18 -0
  105. package/dist/keystore/KeyStore.js +1 -0
  106. package/dist/keystore/index.cjs +335 -0
  107. package/dist/keystore/index.cjs.map +1 -0
  108. package/dist/keystore/index.d.cts +23 -0
  109. package/dist/keystore/index.d.ts +2 -0
  110. package/dist/keystore/index.js +2 -0
  111. package/dist/keystore/index.js.map +1 -0
  112. package/dist/network/index.cjs +74 -0
  113. package/dist/network/index.cjs.map +1 -0
  114. package/dist/network/index.d.cts +36 -0
  115. package/dist/network/index.d.ts +3 -0
  116. package/dist/network/index.js +3 -0
  117. package/dist/network/index.js.map +1 -0
  118. package/dist/network/presets.d.ts +24 -0
  119. package/dist/network/presets.js +23 -0
  120. package/dist/network/resolve.d.ts +7 -0
  121. package/dist/network/resolve.js +17 -0
  122. package/dist/network/types.d.ts +16 -0
  123. package/dist/network/types.js +1 -0
  124. package/dist/signer/EthersSigner.d.ts +24 -0
  125. package/dist/signer/EthersSigner.js +68 -0
  126. package/dist/signer/PrivateKeySigner.d.ts +14 -0
  127. package/dist/signer/PrivateKeySigner.js +18 -0
  128. package/dist/signer/Signer.d.ts +35 -0
  129. package/dist/signer/Signer.js +1 -0
  130. package/dist/signer/index.cjs +121 -0
  131. package/dist/signer/index.cjs.map +1 -0
  132. package/dist/signer/index.d.cts +40 -0
  133. package/dist/signer/index.d.ts +3 -0
  134. package/dist/signer/index.js +3 -0
  135. package/dist/signer/index.js.map +1 -0
  136. package/dist/storage/MemoryStorage.d.ts +18 -0
  137. package/dist/storage/MemoryStorage.js +40 -0
  138. package/dist/storage/Storage.d.ts +14 -0
  139. package/dist/storage/Storage.js +1 -0
  140. package/dist/storage/ZgStorage.d.ts +24 -0
  141. package/dist/storage/ZgStorage.js +102 -0
  142. package/dist/storage/index.cjs +221 -0
  143. package/dist/storage/index.cjs.map +1 -0
  144. package/dist/storage/index.d.cts +44 -0
  145. package/dist/storage/index.d.ts +3 -0
  146. package/dist/storage/index.js +3 -0
  147. package/dist/storage/index.js.map +1 -0
  148. package/dist/testing/index.cjs +4 -0
  149. package/dist/testing/index.cjs.map +1 -0
  150. package/dist/testing/index.d.cts +2 -0
  151. package/dist/testing/index.d.ts +1 -0
  152. package/dist/testing/index.js +1 -0
  153. package/dist/testing/index.js.map +1 -0
  154. package/dist/types-BOG5Ub1z.d.cts +31 -0
  155. package/dist/types-BOG5Ub1z.d.ts +31 -0
  156. package/dist/types-V7_ZmUb-.d.cts +19 -0
  157. package/dist/types-hAsITUQ7.d.ts +19 -0
  158. package/dist/types.d.ts +58 -0
  159. package/dist/types.js +1 -0
  160. package/dist/verifier/index.cjs +4 -0
  161. package/dist/verifier/index.cjs.map +1 -0
  162. package/dist/verifier/index.d.cts +2 -0
  163. package/dist/verifier/index.d.ts +1 -0
  164. package/dist/verifier/index.js +1 -0
  165. package/dist/verifier/index.js.map +1 -0
  166. package/dist/worker/Worker.d.ts +53 -0
  167. package/dist/worker/Worker.js +53 -0
  168. package/dist/worker/index.cjs +382 -0
  169. package/dist/worker/index.cjs.map +1 -0
  170. package/dist/worker/index.d.cts +58 -0
  171. package/dist/worker/index.d.ts +1 -0
  172. package/dist/worker/index.js +1 -0
  173. package/dist/worker/index.js.map +1 -0
  174. package/examples/agent-demo.ts +121 -0
  175. package/package.json +46 -0
  176. package/scripts/gen-crypto-fixtures.mjs +72 -0
  177. package/src/agent/Agent.ts +122 -0
  178. package/src/agent/index.ts +1 -0
  179. package/src/api/index.ts +1 -0
  180. package/src/chain/BlindEscrowClient.ts +182 -0
  181. package/src/chain/BlindReputationClient.ts +55 -0
  182. package/src/chain/ChainClient.ts +59 -0
  183. package/src/chain/TaskRegistryClient.ts +82 -0
  184. package/src/chain/abi/BlindEscrow.json +1113 -0
  185. package/src/chain/abi/BlindReputation.json +447 -0
  186. package/src/chain/abi/TaskRegistry.json +586 -0
  187. package/src/chain/abi/index.ts +5 -0
  188. package/src/chain/errors.ts +43 -0
  189. package/src/chain/index.ts +6 -0
  190. package/src/compute/index.ts +1 -0
  191. package/src/crypto/aes.ts +104 -0
  192. package/src/crypto/constants.ts +7 -0
  193. package/src/crypto/ecies.ts +60 -0
  194. package/src/crypto/envelope.ts +131 -0
  195. package/src/crypto/hkdf.ts +45 -0
  196. package/src/crypto/index.ts +6 -0
  197. package/src/crypto/keys.ts +56 -0
  198. package/src/errors/BlindMarketError.ts +38 -0
  199. package/src/errors/codes.ts +67 -0
  200. package/src/errors/index.ts +3 -0
  201. package/src/errors/subclasses.ts +59 -0
  202. package/src/events/EventBus.ts +45 -0
  203. package/src/events/index.ts +2 -0
  204. package/src/events/types.ts +13 -0
  205. package/src/index.ts +222 -0
  206. package/src/keystore/InMemoryKeyStore.ts +146 -0
  207. package/src/keystore/KeyStore.ts +19 -0
  208. package/src/keystore/index.ts +2 -0
  209. package/src/network/index.ts +3 -0
  210. package/src/network/presets.ts +27 -0
  211. package/src/network/resolve.ts +19 -0
  212. package/src/network/types.ts +18 -0
  213. package/src/signer/EthersSigner.ts +82 -0
  214. package/src/signer/PrivateKeySigner.ts +19 -0
  215. package/src/signer/Signer.ts +40 -0
  216. package/src/signer/index.ts +3 -0
  217. package/src/storage/MemoryStorage.ts +49 -0
  218. package/src/storage/Storage.ts +15 -0
  219. package/src/storage/ZgStorage.ts +124 -0
  220. package/src/storage/index.ts +3 -0
  221. package/src/testing/index.ts +1 -0
  222. package/src/types.ts +76 -0
  223. package/src/verifier/index.ts +1 -0
  224. package/src/worker/Worker.ts +98 -0
  225. package/src/worker/index.ts +1 -0
  226. package/test/agent.test.ts +193 -0
  227. package/test/chain.test.ts +145 -0
  228. package/test/crypto.aes.test.ts +81 -0
  229. package/test/crypto.compat.test.ts +33 -0
  230. package/test/crypto.ecies.test.ts +64 -0
  231. package/test/envelope.test.ts +82 -0
  232. package/test/errors.test.ts +64 -0
  233. package/test/events.test.ts +59 -0
  234. package/test/fixtures/crypto.json +16 -0
  235. package/test/keystore.test.ts +103 -0
  236. package/test/network.test.ts +53 -0
  237. package/test/signer.test.ts +66 -0
  238. package/test/smoke.test.ts +7 -0
  239. package/test/storage.test.ts +55 -0
  240. package/test/worker.test.ts +181 -0
  241. package/tsconfig.build.json +1 -0
  242. package/tsconfig.json +13 -0
  243. package/tsup.config.ts +32 -0
  244. package/vitest.config.ts +17 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/crypto/constants.ts","../../src/errors/codes.ts","../../src/errors/BlindBountyError.ts","../../src/errors/subclasses.ts","../../src/errors/index.ts","../../src/crypto/aes.ts","../../src/crypto/hkdf.ts","../../src/crypto/keys.ts","../../src/crypto/ecies.ts","../../src/crypto/envelope.ts","../../src/agent/Agent.ts"],"names":["toArrayBuffer","ethers","eciesDecrypt"],"mappings":";;;;;;;;;;;;;AAAA,IAAa,SAAA,EACA,UAAA,EACA,UAAA,EACA,mBAAA,EACA,iBACA,YAAA,EACA,cAAA;AANb,IAAA,cAAA,GAAA,KAAA,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,MAAA,EAAQ,KAAK,gBAAA,EAAkB,EAAE,QAAQ,MAAA,EAAQ,OAAA,CAAQ,MAAM,CAAA;AAC/D,IAAA,OAAO,OAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,uBAAA,CAAwB,YAAA,EAAmB,YAAA,EAA2C;AAC1F,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,SAAS,YAAY,CAAA;AAC9D,IAAA,OAAO,mBAAA,CAAoB,UAAU,YAAY,CAAA;AAAA,EACnD;AACF;AAEA,SAAS,QAAQ,CAAA,EAAoC;AACnD,EAAA,OAAO,OAAO,MAAM,QAAA,GAAW,IAAI,aAAY,CAAE,MAAA,CAAO,CAAC,CAAA,GAAI,CAAA;AAC/D","file":"index.js","sourcesContent":["export const IV_LENGTH = 12;\nexport const TAG_LENGTH = 16;\nexport const KEY_LENGTH = 32;\nexport const ECIES_PUBKEY_LENGTH = 65;\nexport const ECIES_HKDF_INFO = new TextEncoder().encode('BlindBounty-ECIES-v1');\nexport const AES_MIN_BLOB = IV_LENGTH + TAG_LENGTH;\nexport const ECIES_MIN_BLOB = ECIES_PUBKEY_LENGTH + AES_MIN_BLOB;\n","export const ErrorCodes = {\n Config: ['CONFIG/INVALID_NETWORK', 'CONFIG/MISSING_SIGNER', 'CONFIG/BAD_CONFIG'] as const,\n Crypto: [\n 'CRYPTO/INVALID_KEY',\n 'CRYPTO/DECRYPT_FAILED',\n 'CRYPTO/INTEGRITY_CHECK',\n 'CRYPTO/UNSUPPORTED_CIPHER',\n ] as const,\n Storage: [\n 'STORAGE/UPLOAD_FAILED',\n 'STORAGE/DOWNLOAD_FAILED',\n 'STORAGE/MERKLE_MISMATCH',\n 'STORAGE/NOT_FOUND',\n 'STORAGE/INDEXER_UNREACHABLE',\n ] as const,\n Chain: [\n 'CHAIN/TX_REVERTED',\n 'CHAIN/TX_TIMED_OUT',\n 'CHAIN/NONCE_CONFLICT',\n 'CHAIN/INSUFFICIENT_BALANCE',\n 'CHAIN/NETWORK_MISMATCH',\n 'CHAIN/CONTRACT_NOT_DEPLOYED',\n ] as const,\n Compute: [\n 'COMPUTE/BROKER_UNREACHABLE',\n 'COMPUTE/NO_PROVIDERS',\n 'COMPUTE/LEDGER_INSUFFICIENT',\n 'COMPUTE/TEE_ATTESTATION_INVALID',\n 'COMPUTE/VERIFICATION_TIMEOUT',\n ] as const,\n Api: [\n 'API/AUTH_REQUIRED',\n 'API/AUTH_EXPIRED',\n 'API/FORBIDDEN',\n 'API/RATE_LIMITED',\n 'API/VALIDATION',\n 'API/SERVER',\n 'API/NOT_FOUND',\n ] as const,\n Lifecycle: [\n 'LIFECYCLE/ILLEGAL_TRANSITION',\n 'LIFECYCLE/TASK_NOT_FOUND',\n 'LIFECYCLE/NOT_ASSIGNED',\n 'LIFECYCLE/ALREADY_SUBMITTED',\n 'LIFECYCLE/CLAIM_NOT_READY',\n ] as const,\n Timeout: ['TIMEOUT'] as const,\n} as const;\n\nexport type ConfigCode = (typeof ErrorCodes.Config)[number];\nexport type CryptoCode = (typeof ErrorCodes.Crypto)[number];\nexport type StorageCode = (typeof ErrorCodes.Storage)[number];\nexport type ChainCode = (typeof ErrorCodes.Chain)[number];\nexport type ComputeCode = (typeof ErrorCodes.Compute)[number];\nexport type ApiCode = (typeof ErrorCodes.Api)[number];\nexport type LifecycleCode = (typeof ErrorCodes.Lifecycle)[number];\nexport type TimeoutCode = (typeof ErrorCodes.Timeout)[number];\n\nexport type ErrorCode =\n | ConfigCode\n | CryptoCode\n | StorageCode\n | ChainCode\n | ComputeCode\n | ApiCode\n | LifecycleCode\n | TimeoutCode;\n","import type { ErrorCode } from './codes.js';\n\nexport interface ErrorOptions {\n retriable?: boolean;\n context?: Record<string, unknown>;\n cause?: unknown;\n}\n\nexport abstract class BlindBountyError extends Error {\n readonly code: ErrorCode;\n readonly retriable: boolean;\n readonly context?: Record<string, unknown>;\n override readonly cause?: unknown;\n\n constructor(code: ErrorCode, message: string, opts: ErrorOptions = {}) {\n super(message);\n this.code = code;\n this.retriable = opts.retriable ?? false;\n if (opts.context !== undefined) this.context = opts.context;\n if (opts.cause !== undefined) this.cause = opts.cause;\n Object.defineProperty(this, 'name', {\n value: this.constructor.name,\n enumerable: false,\n configurable: true,\n writable: true,\n });\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n retriable: this.retriable,\n ...(this.context ? { context: this.context } : {}),\n };\n }\n}\n","import { BlindBountyError, type ErrorOptions } from './BlindBountyError.js';\nimport type {\n ApiCode,\n ChainCode,\n ComputeCode,\n ConfigCode,\n CryptoCode,\n LifecycleCode,\n StorageCode,\n TimeoutCode,\n} from './codes.js';\n\nexport class ConfigError extends BlindBountyError {\n constructor(code: ConfigCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class CryptoError extends BlindBountyError {\n constructor(code: CryptoCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class StorageError extends BlindBountyError {\n constructor(code: StorageCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ChainError extends BlindBountyError {\n constructor(code: ChainCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ComputeError extends BlindBountyError {\n constructor(code: ComputeCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class ApiError extends BlindBountyError {\n constructor(code: ApiCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class LifecycleError extends BlindBountyError {\n constructor(code: LifecycleCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n\nexport class TimeoutError extends BlindBountyError {\n constructor(code: TimeoutCode, msg: string, opts?: ErrorOptions) {\n super(code, msg, opts);\n }\n}\n","export * from './codes.js';\nexport * from './BlindBountyError.js';\nexport * from './subclasses.js';\n","import { CryptoError } from '../errors/index.js';\nimport { AES_MIN_BLOB, IV_LENGTH, KEY_LENGTH, TAG_LENGTH } from './constants.js';\n\nfunction getCrypto(): Crypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/** Generate a fresh 32-byte AES-256 key. */\nexport async function generateAesKey(): Promise<Uint8Array> {\n const key = new Uint8Array(KEY_LENGTH);\n getCrypto().getRandomValues(key);\n return key;\n}\n\n/**\n * AES-256-GCM encrypt. Output format: [12 IV][16 tag][ciphertext].\n * This ordering matches backend/src/services/crypto.ts and frontend/src/lib/crypto.ts\n * byte-for-byte, so SDK blobs decrypt anywhere in the stack.\n */\nexport async function aesEncrypt(plaintext: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n const c = getCrypto();\n const iv = new Uint8Array(IV_LENGTH);\n c.getRandomValues(iv);\n try {\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['encrypt']);\n const wcOut = new Uint8Array(\n await c.subtle.encrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(plaintext),\n ),\n );\n // WebCrypto returns [ciphertext || tag]. Rewrite to [IV || tag || ciphertext].\n const ctLen = wcOut.length - TAG_LENGTH;\n const ct = wcOut.subarray(0, ctLen);\n const tag = wcOut.subarray(ctLen);\n const blob = new Uint8Array(IV_LENGTH + TAG_LENGTH + ctLen);\n blob.set(iv, 0);\n blob.set(tag, IV_LENGTH);\n blob.set(ct, IV_LENGTH + TAG_LENGTH);\n return blob;\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM encryption failed', { cause });\n }\n}\n\n/**\n * AES-256-GCM decrypt. Input format: [12 IV][16 tag][ciphertext].\n * Throws CRYPTO/INTEGRITY_CHECK on truncation or tag mismatch.\n */\nexport async function aesDecrypt(blob: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n if (key.byteLength !== KEY_LENGTH) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `AES key must be ${KEY_LENGTH} bytes, got ${key.byteLength}`,\n );\n }\n if (blob.byteLength < AES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `AES blob too short: need ≥${AES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const iv = blob.subarray(0, IV_LENGTH);\n const tag = blob.subarray(IV_LENGTH, IV_LENGTH + TAG_LENGTH);\n const ct = blob.subarray(IV_LENGTH + TAG_LENGTH);\n const combined = new Uint8Array(ct.length + TAG_LENGTH);\n combined.set(ct, 0);\n combined.set(tag, ct.length);\n try {\n const c = getCrypto();\n const ck = await c.subtle.importKey('raw', toArrayBuffer(key), 'AES-GCM', false, ['decrypt']);\n const pt = await c.subtle.decrypt(\n { name: 'AES-GCM', iv: toArrayBuffer(iv), tagLength: TAG_LENGTH * 8 },\n ck,\n toArrayBuffer(combined),\n );\n return new Uint8Array(pt);\n } catch (cause) {\n throw new CryptoError('CRYPTO/DECRYPT_FAILED', 'AES-GCM decryption failed (wrong key or tampered data)', { cause });\n }\n}\n\n/** SHA-256 of arbitrary bytes. Returns 32-byte digest. */\nexport async function sha256(data: Uint8Array): Promise<Uint8Array> {\n const digest = await getCrypto().subtle.digest('SHA-256', toArrayBuffer(data));\n return new Uint8Array(digest);\n}\n","import { CryptoError } from '../errors/index.js';\nimport { ECIES_HKDF_INFO } from './constants.js';\n\nfunction getSubtle(): SubtleCrypto {\n const c = (globalThis as { crypto?: Crypto }).crypto;\n if (!c?.subtle) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', 'Web Crypto (crypto.subtle) is not available');\n }\n return c.subtle;\n}\n\nfunction toArrayBuffer(u: Uint8Array): ArrayBuffer {\n const ab = new ArrayBuffer(u.byteLength);\n new Uint8Array(ab).set(u);\n return ab;\n}\n\n/**\n * HKDF-SHA256. Defaults match backend: empty salt, the ECIES domain separation info,\n * 32-byte output length. Pass custom values for other uses.\n */\nexport async function hkdfSha256(\n ikm: Uint8Array,\n length = 32,\n info: Uint8Array = ECIES_HKDF_INFO,\n salt: Uint8Array = new Uint8Array(0),\n): Promise<Uint8Array> {\n try {\n const subtle = getSubtle();\n const baseKey = await subtle.importKey('raw', toArrayBuffer(ikm), 'HKDF', false, ['deriveBits']);\n const derived = await subtle.deriveBits(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n info: toArrayBuffer(info),\n salt: toArrayBuffer(salt),\n },\n baseKey,\n length * 8,\n );\n return new Uint8Array(derived);\n } catch (cause) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'HKDF derivation failed', { cause });\n }\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\n\nexport interface KeyPair {\n privateKey: string;\n publicKey: string;\n}\n\n/** Fresh secp256k1 keypair. Hex strings returned un-prefixed (no 0x). */\nexport function generateKeyPair(): KeyPair {\n const w = ethers.Wallet.createRandom();\n return {\n privateKey: w.privateKey.slice(2),\n publicKey: w.signingKey.publicKey.slice(2),\n };\n}\n\n/** Recover the uncompressed public key (un-prefixed hex) from a private key. */\nexport function derivePublicKey(privateKey: string): string {\n const sk = new ethers.SigningKey(`0x${strip(privateKey)}`);\n return sk.publicKey.slice(2);\n}\n\nexport function strip(hex: string): string {\n return hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;\n}\n\nexport function assertUncompressedPubKey(pub: string): void {\n const s = strip(pub);\n if (s.length !== 130 || !/^04/i.test(s)) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n 'expected uncompressed secp256k1 pubkey (65 bytes hex, starts with 04)',\n );\n }\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n const s = strip(hex);\n if (s.length % 2 !== 0) {\n throw new CryptoError('CRYPTO/INVALID_KEY', 'hex string has odd length');\n }\n const out = new Uint8Array(s.length / 2);\n for (let i = 0; i < out.length; i++) {\n const byte = Number.parseInt(s.substring(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(byte)) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `invalid hex byte at position ${i * 2}`);\n }\n out[i] = byte;\n }\n return out;\n}\n\nexport function bytesToHex(u: Uint8Array): string {\n return Array.from(u, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n","import { ethers } from 'ethers';\nimport { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt } from './aes.js';\nimport { ECIES_MIN_BLOB, ECIES_PUBKEY_LENGTH, KEY_LENGTH } from './constants.js';\nimport { hkdfSha256 } from './hkdf.js';\nimport { assertUncompressedPubKey, bytesToHex, hexToBytes, strip } from './keys.js';\n\n/**\n * ECIES-secp256k1 encrypt to a recipient's uncompressed public key.\n * Wire format: [65 ephemeral pubkey][12 IV][16 tag][ciphertext].\n * Byte-compatible with backend/src/services/crypto.ts.\n */\nexport async function eciesEncrypt(plaintext: Uint8Array, recipientPubKey: string): Promise<Uint8Array> {\n assertUncompressedPubKey(recipientPubKey);\n const ephemeral = ethers.Wallet.createRandom();\n const shared = deriveSharedSecretX(ephemeral.privateKey, `0x${strip(recipientPubKey)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n const aesBlob = await aesEncrypt(plaintext, aesKey);\n const ephPub = hexToBytes(strip(ephemeral.signingKey.publicKey));\n if (ephPub.byteLength !== ECIES_PUBKEY_LENGTH) {\n throw new CryptoError('CRYPTO/INVALID_KEY', `ephemeral pubkey length ${ephPub.byteLength}`);\n }\n const blob = new Uint8Array(ECIES_PUBKEY_LENGTH + aesBlob.byteLength);\n blob.set(ephPub, 0);\n blob.set(aesBlob, ECIES_PUBKEY_LENGTH);\n return blob;\n}\n\n/** ECIES-secp256k1 decrypt with the recipient's private key. */\nexport async function eciesDecrypt(blob: Uint8Array, recipientPrivKey: string): Promise<Uint8Array> {\n if (blob.byteLength < ECIES_MIN_BLOB) {\n throw new CryptoError(\n 'CRYPTO/INTEGRITY_CHECK',\n `ECIES blob too short: need ≥${ECIES_MIN_BLOB} bytes, got ${blob.byteLength}`,\n );\n }\n const ephPub = blob.subarray(0, ECIES_PUBKEY_LENGTH);\n const aesBlob = blob.subarray(ECIES_PUBKEY_LENGTH);\n const shared = deriveSharedSecretX(`0x${strip(recipientPrivKey)}`, `0x${bytesToHex(ephPub)}`);\n const aesKey = await hkdfSha256(shared, KEY_LENGTH);\n return aesDecrypt(aesBlob, aesKey);\n}\n\n/**\n * Compute the ECDH shared secret X coordinate (32 bytes) between a private key\n * and a peer's public key. Matches Node createECDH.computeSecret() output used by\n * the backend — ethers v6 returns 0x04||X||Y, so we slice X.\n */\nfunction deriveSharedSecretX(privHex: string, pubHex: string): Uint8Array {\n const sk = new ethers.SigningKey(privHex);\n const shared = sk.computeSharedSecret(pubHex);\n const bytes = hexToBytes(strip(shared));\n if (bytes.byteLength !== 65 || bytes[0] !== 0x04) {\n throw new CryptoError(\n 'CRYPTO/INVALID_KEY',\n `unexpected shared secret shape (len=${bytes.byteLength}, prefix=${bytes[0]?.toString(16) ?? 'none'})`,\n );\n }\n return bytes.subarray(1, 33);\n}\n","import { CryptoError } from '../errors/index.js';\nimport { aesDecrypt, aesEncrypt, generateAesKey } from './aes.js';\nimport { eciesEncrypt } from './ecies.js';\n\n/**\n * Evidence envelope — the single blob a worker uploads to Storage containing:\n * 1. The AES key wrapped to the agent's pubkey (so agent can decrypt later)\n * 2. The AES key wrapped to the TEE enclave's pubkey (so Sealed Inference can decrypt)\n * 3. The evidence ciphertext under that AES key\n *\n * Wire format (big-endian):\n * bytes 0..1 magic = 0x42 0x42 (\"BB\")\n * byte 2 version = 0x01\n * bytes 3..6 wrappedAgentLen (uint32)\n * bytes 7.. wrappedAgent (ECIES blob)\n * 4-byte uint32 wrappedEnclaveLen\n * bytes wrappedEnclave (ECIES blob)\n * bytes aesCiphertext (rest of the blob — AES blob [IV||tag||ct])\n *\n * The layout is versioned so we can rev it without breaking old blobs.\n */\n\nconst MAGIC_0 = 0x42;\nconst MAGIC_1 = 0x42;\nconst VERSION = 0x01;\nconst HEADER_LEN = 3;\n\nexport interface EvidenceEnvelope {\n wrappedForAgent: Uint8Array;\n wrappedForEnclave: Uint8Array;\n aesCiphertext: Uint8Array;\n}\n\nexport interface SealEvidenceInput {\n evidence: Uint8Array;\n agentPubKey: string;\n enclavePubKey: string;\n}\n\nexport interface SealEvidenceOutput {\n envelope: Uint8Array;\n aesKey: Uint8Array;\n}\n\n/**\n * Seal evidence for the agent + TEE enclave. Generates a fresh AES key,\n * encrypts the evidence, ECIES-wraps the key twice, and concatenates the\n * result as an EvidenceEnvelope. Returns both the on-wire envelope and\n * the raw AES key (for audit / diagnostic use — do NOT persist beyond\n * the submission).\n */\nexport async function sealEvidence(input: SealEvidenceInput): Promise<SealEvidenceOutput> {\n const aesKey = await generateAesKey();\n const aesCiphertext = await aesEncrypt(input.evidence, aesKey);\n const wrappedForAgent = await eciesEncrypt(aesKey, input.agentPubKey);\n const wrappedForEnclave = await eciesEncrypt(aesKey, input.enclavePubKey);\n const envelope = pack({ wrappedForAgent, wrappedForEnclave, aesCiphertext });\n return { envelope, aesKey };\n}\n\n/**\n * Open an evidence envelope as the agent — extracts the AES key wrapped\n * to the agent's pubkey, decrypts the ciphertext, and returns the plaintext\n * evidence. The enclave-wrapped key is ignored by agents (TEE-only).\n */\nexport async function openEvidenceAsAgent(\n envelope: Uint8Array,\n agentPrivKey: string,\n): Promise<Uint8Array> {\n const parsed = parse(envelope);\n const { eciesDecrypt } = await import('./ecies.js');\n const aesKey = await eciesDecrypt(parsed.wrappedForAgent, agentPrivKey);\n return aesDecrypt(parsed.aesCiphertext, aesKey);\n}\n\nfunction pack(parts: EvidenceEnvelope): Uint8Array {\n const { wrappedForAgent, wrappedForEnclave, aesCiphertext } = parts;\n const total =\n HEADER_LEN +\n 4 + wrappedForAgent.byteLength +\n 4 + wrappedForEnclave.byteLength +\n aesCiphertext.byteLength;\n const out = new Uint8Array(total);\n const view = new DataView(out.buffer);\n let off = 0;\n out[off++] = MAGIC_0;\n out[off++] = MAGIC_1;\n out[off++] = VERSION;\n view.setUint32(off, wrappedForAgent.byteLength, false);\n off += 4;\n out.set(wrappedForAgent, off);\n off += wrappedForAgent.byteLength;\n view.setUint32(off, wrappedForEnclave.byteLength, false);\n off += 4;\n out.set(wrappedForEnclave, off);\n off += wrappedForEnclave.byteLength;\n out.set(aesCiphertext, off);\n return out;\n}\n\nfunction parse(blob: Uint8Array): EvidenceEnvelope {\n if (blob.byteLength < HEADER_LEN + 4 + 4) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', `envelope too short: ${blob.byteLength}`);\n }\n if (blob[0] !== MAGIC_0 || blob[1] !== MAGIC_1) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'bad envelope magic');\n }\n if (blob[2] !== VERSION) {\n throw new CryptoError('CRYPTO/UNSUPPORTED_CIPHER', `unknown envelope version ${blob[2]}`);\n }\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);\n let off = HEADER_LEN;\n const agentLen = view.getUint32(off, false);\n off += 4;\n if (off + agentLen + 4 > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (agent)');\n }\n const wrappedForAgent = blob.slice(off, off + agentLen);\n off += agentLen;\n const enclaveLen = view.getUint32(off, false);\n off += 4;\n if (off + enclaveLen > blob.byteLength) {\n throw new CryptoError('CRYPTO/INTEGRITY_CHECK', 'envelope truncated (enclave)');\n }\n const wrappedForEnclave = blob.slice(off, off + enclaveLen);\n off += enclaveLen;\n const aesCiphertext = blob.slice(off);\n return { wrappedForAgent, wrappedForEnclave, aesCiphertext };\n}\n\nexport const __internals = { pack, parse };\n","import type { BlindEscrowClient } from '../chain/index.js';\nimport {\n aesEncrypt,\n eciesEncrypt,\n generateAesKey,\n openEvidenceAsAgent,\n} from '../crypto/index.js';\nimport { LifecycleError } from '../errors/index.js';\nimport type { EventBus, SdkEvents } from '../events/index.js';\nimport type { KeyStore } from '../keystore/index.js';\nimport type { Signer } from '../signer/index.js';\nimport type { Storage } from '../storage/index.js';\nimport type { Address, Hex, Reward, TaskId, TaskKey, TxReceiptLike } from '../types.js';\n\nexport interface AgentDeps {\n escrow: BlindEscrowClient;\n storage: Storage;\n keystore: KeyStore;\n signer: Signer;\n events?: EventBus<SdkEvents>;\n}\n\nexport interface CreateTaskInput {\n instructions: string | Uint8Array;\n category: string;\n locationZone: string;\n reward: Reward & { token: Address };\n deadline: Date | bigint;\n}\n\nexport interface CreateTaskResult {\n taskId: TaskId;\n taskKey: TaskKey;\n rootHash: Hex;\n txHash: Hex;\n receipt: TxReceiptLike;\n}\n\nexport interface AssignWorkerResult {\n wrappedKey: Uint8Array;\n receipt: TxReceiptLike;\n}\n\n/**\n * End-to-end agent flows. Composes storage + crypto + chain + keystore so a\n * caller can post an encrypted bounty in one call. Key exchange with the\n * worker is intentionally out-of-band: assignWorker() returns the wrapped\n * AES key as bytes, and the caller is responsible for delivering it (backend\n * API, DM, whatever). This keeps the SDK pluggable across different\n * message-passing substrates.\n */\nexport class Agent {\n constructor(private readonly deps: AgentDeps) {}\n\n async createTask(input: CreateTaskInput): Promise<CreateTaskResult> {\n const { storage, escrow, keystore, events } = this.deps;\n\n const aesKey = await generateAesKey();\n const plaintext = toBytes(input.instructions);\n const ciphertext = await aesEncrypt(plaintext, aesKey);\n\n const uploaded = await storage.upload(ciphertext);\n const rootHash = uploaded.rootHash;\n\n const deadline = typeof input.deadline === 'bigint' ? input.deadline : BigInt(Math.floor(input.deadline.getTime() / 1000));\n\n const { taskId, receipt } = await escrow.createTask({\n taskHash: rootHash,\n token: input.reward.token as Address,\n amount: input.reward.amount,\n category: input.category,\n locationZone: input.locationZone,\n deadline,\n });\n\n const taskKey: TaskKey = { aesKey, createdAt: new Date() };\n await keystore.putTaskKey(taskId, taskKey);\n\n events?.emit('task.created', { taskId, txHash: receipt.hash, rootHash });\n return { taskId, taskKey, rootHash, txHash: receipt.hash, receipt };\n }\n\n /**\n * Wrap the stored AES key for the chosen worker and record the assignment\n * on-chain. The caller must deliver `wrappedKey` to the worker separately\n * (backend API, DM, etc.). Returns the wrapped bytes and the tx receipt.\n */\n async assignWorker(taskId: TaskId, worker: Address, workerPubKey: string): Promise<AssignWorkerResult> {\n const { keystore, escrow, events } = this.deps;\n const stored = await keystore.getTaskKey(taskId);\n if (!stored) {\n throw new LifecycleError('LIFECYCLE/TASK_NOT_FOUND', `no task key in keystore for task ${taskId}`);\n }\n const wrappedKey = await eciesEncrypt(stored.aesKey, workerPubKey);\n const receipt = await escrow.assignWorker(taskId, worker);\n events?.emit('task.assigned', { taskId, worker, txHash: receipt.hash });\n return { wrappedKey, receipt };\n }\n\n async cancelTask(taskId: TaskId): Promise<TxReceiptLike> {\n const { escrow, keystore, events } = this.deps;\n const receipt = await this.deps.escrow.cancelTask(taskId);\n void escrow;\n await keystore.delete(taskId);\n events?.emit('task.cancelled', { taskId, txHash: receipt.hash });\n return receipt;\n }\n\n /**\n * Fetch evidence by root hash, unwrap the AES key with the agent's private\n * key (signer's key material is not accessible, so a raw private key is\n * required), and return the decrypted evidence plaintext.\n */\n async fetchAndDecryptEvidence(evidenceHash: Hex, agentPrivKey: string): Promise<Uint8Array> {\n const envelope = await this.deps.storage.download(evidenceHash);\n return openEvidenceAsAgent(envelope, agentPrivKey);\n }\n}\n\nfunction toBytes(x: string | Uint8Array): Uint8Array {\n return typeof x === 'string' ? new TextEncoder().encode(x) : x;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=index.cjs.map
4
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,51 @@
1
+ import { ethers } from 'ethers';
2
+ import type { Address, Hex, TaskId, TaskStatus, TxReceiptLike } from '../types.js';
3
+ export interface CreateTaskArgs {
4
+ taskHash: Hex;
5
+ token: Address;
6
+ amount: bigint;
7
+ category: string;
8
+ locationZone: string;
9
+ deadline: bigint;
10
+ }
11
+ export interface OnChainTask {
12
+ taskId: TaskId;
13
+ agent: Address;
14
+ worker: Address;
15
+ token: Address;
16
+ amount: bigint;
17
+ taskHash: Hex;
18
+ evidenceHash: Hex;
19
+ status: TaskStatus;
20
+ createdAt: Date;
21
+ deadline: Date;
22
+ }
23
+ /**
24
+ * Typed ethers v6 wrapper for the BlindEscrow contract. Every state-changing
25
+ * method awaits one confirmation and returns a TxReceiptLike; every read
26
+ * returns decoded values. Ethers errors are mapped to ChainError via
27
+ * wrapChainError().
28
+ */
29
+ export declare class BlindEscrowClient {
30
+ readonly contract: ethers.Contract;
31
+ readonly address: Address;
32
+ constructor(address: Address, runner: ethers.ContractRunner);
33
+ /** Create a task and return its id + receipt. Reads the TaskCreated event for the id. */
34
+ createTask(args: CreateTaskArgs): Promise<{
35
+ taskId: TaskId;
36
+ receipt: TxReceiptLike;
37
+ }>;
38
+ assignWorker(taskId: TaskId, worker: Address): Promise<TxReceiptLike>;
39
+ submitEvidence(taskId: TaskId, evidenceHash: Hex): Promise<TxReceiptLike>;
40
+ completeVerification(taskId: TaskId, passed: boolean): Promise<TxReceiptLike>;
41
+ cancelTask(taskId: TaskId): Promise<TxReceiptLike>;
42
+ raiseDispute(taskId: TaskId): Promise<TxReceiptLike>;
43
+ resolveDispute(taskId: TaskId, workerFavored: boolean): Promise<TxReceiptLike>;
44
+ claimTimeout(taskId: TaskId): Promise<TxReceiptLike>;
45
+ getTask(taskId: TaskId): Promise<OnChainTask>;
46
+ isTaskExpired(taskId: TaskId): Promise<boolean>;
47
+ nextTaskId(): Promise<TaskId>;
48
+ feeBps(): Promise<bigint>;
49
+ private sendTx;
50
+ private extractTaskIdFromReceipt;
51
+ }
@@ -0,0 +1,142 @@
1
+ import { ethers } from 'ethers';
2
+ import { BlindEscrowAbi } from './abi/index.js';
3
+ import { wrapChainError } from './errors.js';
4
+ const STATUS_BY_INDEX = ['funded', 'assigned', 'submitted', 'verified', 'completed', 'cancelled'];
5
+ /**
6
+ * Typed ethers v6 wrapper for the BlindEscrow contract. Every state-changing
7
+ * method awaits one confirmation and returns a TxReceiptLike; every read
8
+ * returns decoded values. Ethers errors are mapped to ChainError via
9
+ * wrapChainError().
10
+ */
11
+ export class BlindEscrowClient {
12
+ contract;
13
+ address;
14
+ constructor(address, runner) {
15
+ this.address = address;
16
+ this.contract = new ethers.Contract(address, BlindEscrowAbi, runner);
17
+ }
18
+ /** Create a task and return its id + receipt. Reads the TaskCreated event for the id. */
19
+ async createTask(args) {
20
+ try {
21
+ const tx = await this.contract.createTask(args.taskHash, args.token, args.amount, args.category, args.locationZone, args.deadline);
22
+ const rec = await tx.wait(1);
23
+ const taskId = this.extractTaskIdFromReceipt(rec);
24
+ return { taskId, receipt: toReceipt(rec) };
25
+ }
26
+ catch (err) {
27
+ throw wrapChainError(err, 'createTask');
28
+ }
29
+ }
30
+ async assignWorker(taskId, worker) {
31
+ return this.sendTx('assignWorker', [taskId, worker]);
32
+ }
33
+ async submitEvidence(taskId, evidenceHash) {
34
+ return this.sendTx('submitEvidence', [taskId, evidenceHash]);
35
+ }
36
+ async completeVerification(taskId, passed) {
37
+ return this.sendTx('completeVerification', [taskId, passed]);
38
+ }
39
+ async cancelTask(taskId) {
40
+ return this.sendTx('cancelTask', [taskId]);
41
+ }
42
+ async raiseDispute(taskId) {
43
+ return this.sendTx('raiseDispute', [taskId]);
44
+ }
45
+ async resolveDispute(taskId, workerFavored) {
46
+ return this.sendTx('resolveDispute', [taskId, workerFavored]);
47
+ }
48
+ async claimTimeout(taskId) {
49
+ return this.sendTx('claimTimeout', [taskId]);
50
+ }
51
+ async getTask(taskId) {
52
+ try {
53
+ const raw = await this.contract.getTask(taskId);
54
+ return decodeTask(taskId, raw);
55
+ }
56
+ catch (err) {
57
+ throw wrapChainError(err, 'getTask');
58
+ }
59
+ }
60
+ async isTaskExpired(taskId) {
61
+ try {
62
+ return Boolean(await this.contract.isTaskExpired(taskId));
63
+ }
64
+ catch (err) {
65
+ throw wrapChainError(err, 'isTaskExpired');
66
+ }
67
+ }
68
+ async nextTaskId() {
69
+ try {
70
+ return BigInt(await this.contract.nextTaskId());
71
+ }
72
+ catch (err) {
73
+ throw wrapChainError(err, 'nextTaskId');
74
+ }
75
+ }
76
+ async feeBps() {
77
+ try {
78
+ return BigInt(await this.contract.feeBps());
79
+ }
80
+ catch (err) {
81
+ throw wrapChainError(err, 'feeBps');
82
+ }
83
+ }
84
+ async sendTx(method, args) {
85
+ try {
86
+ const fn = this.contract[method];
87
+ if (typeof fn !== 'function') {
88
+ throw new Error(`unknown contract method: ${method}`);
89
+ }
90
+ const tx = await fn(...args);
91
+ const rec = await tx.wait(1);
92
+ return toReceipt(rec);
93
+ }
94
+ catch (err) {
95
+ throw wrapChainError(err, method);
96
+ }
97
+ }
98
+ extractTaskIdFromReceipt(receipt) {
99
+ if (!receipt)
100
+ throw new Error('no receipt');
101
+ const iface = this.contract.interface;
102
+ for (const log of receipt.logs) {
103
+ try {
104
+ const parsed = iface.parseLog({ topics: log.topics, data: log.data });
105
+ if (parsed?.name === 'TaskCreated') {
106
+ return BigInt(parsed.args.getValue('taskId'));
107
+ }
108
+ }
109
+ catch {
110
+ // not our event, skip
111
+ }
112
+ }
113
+ throw new Error('TaskCreated event not found in receipt logs');
114
+ }
115
+ }
116
+ function toReceipt(rec) {
117
+ if (!rec)
118
+ throw new Error('no receipt');
119
+ return {
120
+ hash: rec.hash,
121
+ blockNumber: rec.blockNumber,
122
+ gasUsed: rec.gasUsed,
123
+ };
124
+ }
125
+ function decodeTask(taskId, raw) {
126
+ // Tuple order from BlindEscrow.getTask(): (agent, worker, token, amount, taskHash,
127
+ // evidenceHash, status, createdAt, deadline) — verify against contracts/BlindEscrow.sol.
128
+ const arr = raw;
129
+ const statusIndex = Number(arr[6]);
130
+ return {
131
+ taskId,
132
+ agent: arr[0],
133
+ worker: arr[1],
134
+ token: arr[2],
135
+ amount: BigInt(arr[3]),
136
+ taskHash: arr[4],
137
+ evidenceHash: arr[5],
138
+ status: STATUS_BY_INDEX[statusIndex] ?? 'funded',
139
+ createdAt: new Date(Number(arr[7]) * 1000),
140
+ deadline: new Date(Number(arr[8]) * 1000),
141
+ };
142
+ }
@@ -0,0 +1,16 @@
1
+ import { ethers } from 'ethers';
2
+ import type { Address, TaskId, TxReceiptLike } from '../types.js';
3
+ export interface ReputationSnapshot {
4
+ tasksCompleted: bigint;
5
+ totalScore: bigint;
6
+ disputes: bigint;
7
+ avgScore: number;
8
+ }
9
+ export declare class BlindReputationClient {
10
+ readonly contract: ethers.Contract;
11
+ readonly address: Address;
12
+ constructor(address: Address, runner: ethers.ContractRunner);
13
+ getReputation(worker: Address): Promise<ReputationSnapshot>;
14
+ rate(worker: Address, score: number, taskId: TaskId): Promise<TxReceiptLike>;
15
+ hasBeenRated(worker: Address, taskId: TaskId): Promise<boolean>;
16
+ }
@@ -0,0 +1,45 @@
1
+ import { ethers } from 'ethers';
2
+ import { BlindReputationAbi } from './abi/index.js';
3
+ import { wrapChainError } from './errors.js';
4
+ export class BlindReputationClient {
5
+ contract;
6
+ address;
7
+ constructor(address, runner) {
8
+ this.address = address;
9
+ this.contract = new ethers.Contract(address, BlindReputationAbi, runner);
10
+ }
11
+ async getReputation(worker) {
12
+ try {
13
+ const raw = (await this.contract.getReputation(worker));
14
+ const tasksCompleted = BigInt(raw[0]);
15
+ const totalScore = BigInt(raw[1]);
16
+ const disputes = BigInt(raw[2]);
17
+ const avgScore = tasksCompleted === 0n ? 0 : Number(totalScore) / Number(tasksCompleted);
18
+ return { tasksCompleted, totalScore, disputes, avgScore };
19
+ }
20
+ catch (err) {
21
+ throw wrapChainError(err, 'getReputation');
22
+ }
23
+ }
24
+ async rate(worker, score, taskId) {
25
+ if (!Number.isInteger(score) || score < 1 || score > 5) {
26
+ throw wrapChainError(new Error(`score must be integer 1..5, got ${score}`), 'rate');
27
+ }
28
+ try {
29
+ const tx = await this.contract.rate(worker, score, taskId);
30
+ const rec = await tx.wait(1);
31
+ return { hash: rec.hash, blockNumber: rec.blockNumber, gasUsed: rec.gasUsed };
32
+ }
33
+ catch (err) {
34
+ throw wrapChainError(err, 'rate');
35
+ }
36
+ }
37
+ async hasBeenRated(worker, taskId) {
38
+ try {
39
+ return Boolean(await this.contract.hasBeenRated(worker, taskId));
40
+ }
41
+ catch (err) {
42
+ throw wrapChainError(err, 'hasBeenRated');
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,26 @@
1
+ import { ethers } from 'ethers';
2
+ import type { Signer as SdkSigner } from '../signer/index.js';
3
+ import type { Network } from '../network/index.js';
4
+ import { BlindEscrowClient } from './BlindEscrowClient.js';
5
+ import { BlindReputationClient } from './BlindReputationClient.js';
6
+ import { TaskRegistryClient } from './TaskRegistryClient.js';
7
+ export interface ChainClientOptions {
8
+ network: Network;
9
+ signer?: SdkSigner;
10
+ /** If provided, used for reads even when signer is absent. Useful for public queries. */
11
+ provider?: ethers.Provider;
12
+ }
13
+ /**
14
+ * Bundles typed clients for all three BlindBounty contracts plus the underlying
15
+ * ethers runner. Reads use provider (or signer's provider); writes require a
16
+ * signer. To keep the SDK's Signer abstraction decoupled from ethers at the
17
+ * call sites, we unwrap an EthersSigner's inner ethers.Signer lazily here.
18
+ */
19
+ export declare class ChainClient {
20
+ readonly escrow: BlindEscrowClient;
21
+ readonly registry: TaskRegistryClient;
22
+ readonly reputation: BlindReputationClient;
23
+ readonly provider: ethers.Provider;
24
+ readonly network: Network;
25
+ constructor(opts: ChainClientOptions);
26
+ }
@@ -0,0 +1,46 @@
1
+ import { ethers } from 'ethers';
2
+ import { BlindEscrowClient } from './BlindEscrowClient.js';
3
+ import { BlindReputationClient } from './BlindReputationClient.js';
4
+ import { TaskRegistryClient } from './TaskRegistryClient.js';
5
+ /**
6
+ * Bundles typed clients for all three BlindBounty contracts plus the underlying
7
+ * ethers runner. Reads use provider (or signer's provider); writes require a
8
+ * signer. To keep the SDK's Signer abstraction decoupled from ethers at the
9
+ * call sites, we unwrap an EthersSigner's inner ethers.Signer lazily here.
10
+ */
11
+ export class ChainClient {
12
+ escrow;
13
+ registry;
14
+ reputation;
15
+ provider;
16
+ network;
17
+ constructor(opts) {
18
+ this.network = opts.network;
19
+ const provider = opts.provider ??
20
+ (opts.signer && unwrapEthersSigner(opts.signer)?.provider) ??
21
+ defaultProvider(opts.network);
22
+ this.provider = provider;
23
+ const runner = unwrapEthersSigner(opts.signer) ?? provider;
24
+ this.escrow = new BlindEscrowClient(opts.network.contracts.escrow, runner);
25
+ this.registry = new TaskRegistryClient(opts.network.contracts.registry, runner);
26
+ this.reputation = new BlindReputationClient(opts.network.contracts.reputation, runner);
27
+ }
28
+ }
29
+ /**
30
+ * If the SDK Signer is an EthersSigner, pull out the inner ethers.Signer
31
+ * (so ethers.Contract treats it as the transaction runner). Otherwise
32
+ * returns undefined — writes will fail at the contract layer with a clear
33
+ * signer-required error, as intended.
34
+ */
35
+ function unwrapEthersSigner(signer) {
36
+ if (!signer)
37
+ return undefined;
38
+ const maybe = signer;
39
+ return maybe.inner;
40
+ }
41
+ function defaultProvider(network) {
42
+ const url = network.rpc[0];
43
+ if (!url)
44
+ throw new Error(`network ${network.name} has no RPC endpoint configured`);
45
+ return new ethers.JsonRpcProvider(url, { chainId: Number(network.chainId), name: network.name });
46
+ }
@@ -0,0 +1,21 @@
1
+ import { ethers } from 'ethers';
2
+ import type { Address, TaskId, TxReceiptLike } from '../types.js';
3
+ export interface OpenTaskMeta {
4
+ taskId: TaskId;
5
+ token: Address;
6
+ category: string;
7
+ locationZone: string;
8
+ reward: bigint;
9
+ createdAt: Date;
10
+ }
11
+ export declare class TaskRegistryClient {
12
+ readonly contract: ethers.Contract;
13
+ readonly address: Address;
14
+ constructor(address: Address, runner: ethers.ContractRunner);
15
+ getTaskMeta(taskId: TaskId): Promise<OpenTaskMeta>;
16
+ getOpenTasks(offset: bigint, limit: bigint): Promise<TaskId[]>;
17
+ totalTasks(): Promise<bigint>;
18
+ openTaskCount(): Promise<bigint>;
19
+ taskExists(taskId: TaskId): Promise<boolean>;
20
+ closeTask(taskId: TaskId): Promise<TxReceiptLike>;
21
+ }
@@ -0,0 +1,70 @@
1
+ import { ethers } from 'ethers';
2
+ import { TaskRegistryAbi } from './abi/index.js';
3
+ import { wrapChainError } from './errors.js';
4
+ export class TaskRegistryClient {
5
+ contract;
6
+ address;
7
+ constructor(address, runner) {
8
+ this.address = address;
9
+ this.contract = new ethers.Contract(address, TaskRegistryAbi, runner);
10
+ }
11
+ async getTaskMeta(taskId) {
12
+ try {
13
+ const raw = (await this.contract.getTaskMeta(taskId));
14
+ return {
15
+ taskId,
16
+ token: raw[0],
17
+ category: raw[1],
18
+ locationZone: raw[2],
19
+ reward: BigInt(raw[3]),
20
+ createdAt: new Date(Number(raw[4]) * 1000),
21
+ };
22
+ }
23
+ catch (err) {
24
+ throw wrapChainError(err, 'getTaskMeta');
25
+ }
26
+ }
27
+ async getOpenTasks(offset, limit) {
28
+ try {
29
+ const ids = (await this.contract.getOpenTasks(offset, limit));
30
+ return ids.map((x) => BigInt(x));
31
+ }
32
+ catch (err) {
33
+ throw wrapChainError(err, 'getOpenTasks');
34
+ }
35
+ }
36
+ async totalTasks() {
37
+ try {
38
+ return BigInt(await this.contract.totalTasks());
39
+ }
40
+ catch (err) {
41
+ throw wrapChainError(err, 'totalTasks');
42
+ }
43
+ }
44
+ async openTaskCount() {
45
+ try {
46
+ return BigInt(await this.contract.openTaskCount());
47
+ }
48
+ catch (err) {
49
+ throw wrapChainError(err, 'openTaskCount');
50
+ }
51
+ }
52
+ async taskExists(taskId) {
53
+ try {
54
+ return Boolean(await this.contract.taskExists(taskId));
55
+ }
56
+ catch (err) {
57
+ throw wrapChainError(err, 'taskExists');
58
+ }
59
+ }
60
+ async closeTask(taskId) {
61
+ try {
62
+ const tx = await this.contract.closeTask(taskId);
63
+ const rec = await tx.wait(1);
64
+ return { hash: rec.hash, blockNumber: rec.blockNumber, gasUsed: rec.gasUsed };
65
+ }
66
+ catch (err) {
67
+ throw wrapChainError(err, 'closeTask');
68
+ }
69
+ }
70
+ }