@oobe-protocol-labs/synapse-sap-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.
Files changed (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +882 -0
  3. package/dist/cjs/constants/index.js +43 -0
  4. package/dist/cjs/constants/index.js.map +1 -0
  5. package/dist/cjs/constants/limits.js +161 -0
  6. package/dist/cjs/constants/limits.js.map +1 -0
  7. package/dist/cjs/constants/programs.js +78 -0
  8. package/dist/cjs/constants/programs.js.map +1 -0
  9. package/dist/cjs/constants/seeds.js +57 -0
  10. package/dist/cjs/constants/seeds.js.map +1 -0
  11. package/dist/cjs/core/client.js +391 -0
  12. package/dist/cjs/core/client.js.map +1 -0
  13. package/dist/cjs/core/connection.js +319 -0
  14. package/dist/cjs/core/connection.js.map +1 -0
  15. package/dist/cjs/core/index.js +24 -0
  16. package/dist/cjs/core/index.js.map +1 -0
  17. package/dist/cjs/errors/index.js +334 -0
  18. package/dist/cjs/errors/index.js.map +1 -0
  19. package/dist/cjs/events/index.js +136 -0
  20. package/dist/cjs/events/index.js.map +1 -0
  21. package/dist/cjs/idl/index.js +63 -0
  22. package/dist/cjs/idl/index.js.map +1 -0
  23. package/dist/cjs/idl/synapse_agent_sap.json +9710 -0
  24. package/dist/cjs/index.js +147 -0
  25. package/dist/cjs/index.js.map +1 -0
  26. package/dist/cjs/modules/agent.js +272 -0
  27. package/dist/cjs/modules/agent.js.map +1 -0
  28. package/dist/cjs/modules/attestation.js +147 -0
  29. package/dist/cjs/modules/attestation.js.map +1 -0
  30. package/dist/cjs/modules/base.js +128 -0
  31. package/dist/cjs/modules/base.js.map +1 -0
  32. package/dist/cjs/modules/escrow.js +246 -0
  33. package/dist/cjs/modules/escrow.js.map +1 -0
  34. package/dist/cjs/modules/feedback.js +166 -0
  35. package/dist/cjs/modules/feedback.js.map +1 -0
  36. package/dist/cjs/modules/index.js +35 -0
  37. package/dist/cjs/modules/index.js.map +1 -0
  38. package/dist/cjs/modules/indexing.js +375 -0
  39. package/dist/cjs/modules/indexing.js.map +1 -0
  40. package/dist/cjs/modules/ledger.js +234 -0
  41. package/dist/cjs/modules/ledger.js.map +1 -0
  42. package/dist/cjs/modules/tools.js +319 -0
  43. package/dist/cjs/modules/tools.js.map +1 -0
  44. package/dist/cjs/modules/vault.js +410 -0
  45. package/dist/cjs/modules/vault.js.map +1 -0
  46. package/dist/cjs/pda/index.js +377 -0
  47. package/dist/cjs/pda/index.js.map +1 -0
  48. package/dist/cjs/plugin/index.js +934 -0
  49. package/dist/cjs/plugin/index.js.map +1 -0
  50. package/dist/cjs/plugin/protocols.js +282 -0
  51. package/dist/cjs/plugin/protocols.js.map +1 -0
  52. package/dist/cjs/plugin/schemas.js +831 -0
  53. package/dist/cjs/plugin/schemas.js.map +1 -0
  54. package/dist/cjs/postgres/adapter.js +715 -0
  55. package/dist/cjs/postgres/adapter.js.map +1 -0
  56. package/dist/cjs/postgres/index.js +50 -0
  57. package/dist/cjs/postgres/index.js.map +1 -0
  58. package/dist/cjs/postgres/serializers.js +381 -0
  59. package/dist/cjs/postgres/serializers.js.map +1 -0
  60. package/dist/cjs/postgres/sync.js +221 -0
  61. package/dist/cjs/postgres/sync.js.map +1 -0
  62. package/dist/cjs/postgres/types.js +44 -0
  63. package/dist/cjs/postgres/types.js.map +1 -0
  64. package/dist/cjs/registries/builder.js +414 -0
  65. package/dist/cjs/registries/builder.js.map +1 -0
  66. package/dist/cjs/registries/discovery.js +362 -0
  67. package/dist/cjs/registries/discovery.js.map +1 -0
  68. package/dist/cjs/registries/index.js +51 -0
  69. package/dist/cjs/registries/index.js.map +1 -0
  70. package/dist/cjs/registries/session.js +433 -0
  71. package/dist/cjs/registries/session.js.map +1 -0
  72. package/dist/cjs/registries/x402.js +577 -0
  73. package/dist/cjs/registries/x402.js.map +1 -0
  74. package/dist/cjs/types/accounts.js +13 -0
  75. package/dist/cjs/types/accounts.js.map +1 -0
  76. package/dist/cjs/types/common.js +13 -0
  77. package/dist/cjs/types/common.js.map +1 -0
  78. package/dist/cjs/types/enums.js +174 -0
  79. package/dist/cjs/types/enums.js.map +1 -0
  80. package/dist/cjs/types/index.js +36 -0
  81. package/dist/cjs/types/index.js.map +1 -0
  82. package/dist/cjs/types/instructions.js +92 -0
  83. package/dist/cjs/types/instructions.js.map +1 -0
  84. package/dist/cjs/utils/hash.js +58 -0
  85. package/dist/cjs/utils/hash.js.map +1 -0
  86. package/dist/cjs/utils/index.js +27 -0
  87. package/dist/cjs/utils/index.js.map +1 -0
  88. package/dist/cjs/utils/serialization.js +105 -0
  89. package/dist/cjs/utils/serialization.js.map +1 -0
  90. package/dist/cjs/utils/validation.js +36 -0
  91. package/dist/cjs/utils/validation.js.map +1 -0
  92. package/dist/esm/constants/index.js +29 -0
  93. package/dist/esm/constants/index.js.map +1 -0
  94. package/dist/esm/constants/limits.js +158 -0
  95. package/dist/esm/constants/limits.js.map +1 -0
  96. package/dist/esm/constants/programs.js +75 -0
  97. package/dist/esm/constants/programs.js.map +1 -0
  98. package/dist/esm/constants/seeds.js +54 -0
  99. package/dist/esm/constants/seeds.js.map +1 -0
  100. package/dist/esm/core/client.js +384 -0
  101. package/dist/esm/core/client.js.map +1 -0
  102. package/dist/esm/core/connection.js +315 -0
  103. package/dist/esm/core/connection.js.map +1 -0
  104. package/dist/esm/core/index.js +19 -0
  105. package/dist/esm/core/index.js.map +1 -0
  106. package/dist/esm/errors/index.js +325 -0
  107. package/dist/esm/errors/index.js.map +1 -0
  108. package/dist/esm/events/index.js +132 -0
  109. package/dist/esm/events/index.js.map +1 -0
  110. package/dist/esm/idl/index.js +57 -0
  111. package/dist/esm/idl/index.js.map +1 -0
  112. package/dist/esm/idl/synapse_agent_sap.json +9710 -0
  113. package/dist/esm/index.js +70 -0
  114. package/dist/esm/index.js.map +1 -0
  115. package/dist/esm/modules/agent.js +268 -0
  116. package/dist/esm/modules/agent.js.map +1 -0
  117. package/dist/esm/modules/attestation.js +143 -0
  118. package/dist/esm/modules/attestation.js.map +1 -0
  119. package/dist/esm/modules/base.js +124 -0
  120. package/dist/esm/modules/base.js.map +1 -0
  121. package/dist/esm/modules/escrow.js +242 -0
  122. package/dist/esm/modules/escrow.js.map +1 -0
  123. package/dist/esm/modules/feedback.js +162 -0
  124. package/dist/esm/modules/feedback.js.map +1 -0
  125. package/dist/esm/modules/index.js +23 -0
  126. package/dist/esm/modules/index.js.map +1 -0
  127. package/dist/esm/modules/indexing.js +371 -0
  128. package/dist/esm/modules/indexing.js.map +1 -0
  129. package/dist/esm/modules/ledger.js +230 -0
  130. package/dist/esm/modules/ledger.js.map +1 -0
  131. package/dist/esm/modules/tools.js +315 -0
  132. package/dist/esm/modules/tools.js.map +1 -0
  133. package/dist/esm/modules/vault.js +406 -0
  134. package/dist/esm/modules/vault.js.map +1 -0
  135. package/dist/esm/pda/index.js +357 -0
  136. package/dist/esm/pda/index.js.map +1 -0
  137. package/dist/esm/plugin/index.js +927 -0
  138. package/dist/esm/plugin/index.js.map +1 -0
  139. package/dist/esm/plugin/protocols.js +279 -0
  140. package/dist/esm/plugin/protocols.js.map +1 -0
  141. package/dist/esm/plugin/schemas.js +828 -0
  142. package/dist/esm/plugin/schemas.js.map +1 -0
  143. package/dist/esm/postgres/adapter.js +678 -0
  144. package/dist/esm/postgres/adapter.js.map +1 -0
  145. package/dist/esm/postgres/index.js +27 -0
  146. package/dist/esm/postgres/index.js.map +1 -0
  147. package/dist/esm/postgres/serializers.js +362 -0
  148. package/dist/esm/postgres/serializers.js.map +1 -0
  149. package/dist/esm/postgres/sync.js +217 -0
  150. package/dist/esm/postgres/sync.js.map +1 -0
  151. package/dist/esm/postgres/types.js +41 -0
  152. package/dist/esm/postgres/types.js.map +1 -0
  153. package/dist/esm/registries/builder.js +410 -0
  154. package/dist/esm/registries/builder.js.map +1 -0
  155. package/dist/esm/registries/discovery.js +358 -0
  156. package/dist/esm/registries/discovery.js.map +1 -0
  157. package/dist/esm/registries/index.js +44 -0
  158. package/dist/esm/registries/index.js.map +1 -0
  159. package/dist/esm/registries/session.js +429 -0
  160. package/dist/esm/registries/session.js.map +1 -0
  161. package/dist/esm/registries/x402.js +573 -0
  162. package/dist/esm/registries/x402.js.map +1 -0
  163. package/dist/esm/types/accounts.js +12 -0
  164. package/dist/esm/types/accounts.js.map +1 -0
  165. package/dist/esm/types/common.js +12 -0
  166. package/dist/esm/types/common.js.map +1 -0
  167. package/dist/esm/types/enums.js +171 -0
  168. package/dist/esm/types/enums.js.map +1 -0
  169. package/dist/esm/types/index.js +25 -0
  170. package/dist/esm/types/index.js.map +1 -0
  171. package/dist/esm/types/instructions.js +89 -0
  172. package/dist/esm/types/instructions.js.map +1 -0
  173. package/dist/esm/utils/hash.js +53 -0
  174. package/dist/esm/utils/hash.js.map +1 -0
  175. package/dist/esm/utils/index.js +19 -0
  176. package/dist/esm/utils/index.js.map +1 -0
  177. package/dist/esm/utils/serialization.js +98 -0
  178. package/dist/esm/utils/serialization.js.map +1 -0
  179. package/dist/esm/utils/validation.js +33 -0
  180. package/dist/esm/utils/validation.js.map +1 -0
  181. package/dist/types/constants/index.d.ts +27 -0
  182. package/dist/types/constants/index.d.ts.map +1 -0
  183. package/dist/types/constants/limits.d.ts +149 -0
  184. package/dist/types/constants/limits.d.ts.map +1 -0
  185. package/dist/types/constants/programs.d.ts +69 -0
  186. package/dist/types/constants/programs.d.ts.map +1 -0
  187. package/dist/types/constants/seeds.d.ts +61 -0
  188. package/dist/types/constants/seeds.d.ts.map +1 -0
  189. package/dist/types/core/client.d.ts +323 -0
  190. package/dist/types/core/client.d.ts.map +1 -0
  191. package/dist/types/core/connection.d.ts +279 -0
  192. package/dist/types/core/connection.d.ts.map +1 -0
  193. package/dist/types/core/index.d.ts +20 -0
  194. package/dist/types/core/index.d.ts.map +1 -0
  195. package/dist/types/errors/index.d.ts +276 -0
  196. package/dist/types/errors/index.d.ts.map +1 -0
  197. package/dist/types/events/index.d.ts +248 -0
  198. package/dist/types/events/index.d.ts.map +1 -0
  199. package/dist/types/idl/index.d.ts +70 -0
  200. package/dist/types/idl/index.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +68 -0
  202. package/dist/types/index.d.ts.map +1 -0
  203. package/dist/types/modules/agent.d.ts +166 -0
  204. package/dist/types/modules/agent.d.ts.map +1 -0
  205. package/dist/types/modules/attestation.d.ts +96 -0
  206. package/dist/types/modules/attestation.d.ts.map +1 -0
  207. package/dist/types/modules/base.d.ts +126 -0
  208. package/dist/types/modules/base.d.ts.map +1 -0
  209. package/dist/types/modules/escrow.d.ts +151 -0
  210. package/dist/types/modules/escrow.d.ts.map +1 -0
  211. package/dist/types/modules/feedback.d.ts +105 -0
  212. package/dist/types/modules/feedback.d.ts.map +1 -0
  213. package/dist/types/modules/index.d.ts +24 -0
  214. package/dist/types/modules/index.d.ts.map +1 -0
  215. package/dist/types/modules/indexing.d.ts +200 -0
  216. package/dist/types/modules/indexing.d.ts.map +1 -0
  217. package/dist/types/modules/ledger.d.ts +150 -0
  218. package/dist/types/modules/ledger.d.ts.map +1 -0
  219. package/dist/types/modules/tools.d.ts +182 -0
  220. package/dist/types/modules/tools.d.ts.map +1 -0
  221. package/dist/types/modules/vault.d.ts +240 -0
  222. package/dist/types/modules/vault.d.ts.map +1 -0
  223. package/dist/types/pda/index.d.ts +296 -0
  224. package/dist/types/pda/index.d.ts.map +1 -0
  225. package/dist/types/plugin/index.d.ts +171 -0
  226. package/dist/types/plugin/index.d.ts.map +1 -0
  227. package/dist/types/plugin/protocols.d.ts +152 -0
  228. package/dist/types/plugin/protocols.d.ts.map +1 -0
  229. package/dist/types/plugin/schemas.d.ts +823 -0
  230. package/dist/types/plugin/schemas.d.ts.map +1 -0
  231. package/dist/types/postgres/adapter.d.ts +355 -0
  232. package/dist/types/postgres/adapter.d.ts.map +1 -0
  233. package/dist/types/postgres/index.d.ts +24 -0
  234. package/dist/types/postgres/index.d.ts.map +1 -0
  235. package/dist/types/postgres/serializers.d.ts +30 -0
  236. package/dist/types/postgres/serializers.d.ts.map +1 -0
  237. package/dist/types/postgres/sync.d.ts +132 -0
  238. package/dist/types/postgres/sync.d.ts.map +1 -0
  239. package/dist/types/postgres/types.d.ts +167 -0
  240. package/dist/types/postgres/types.d.ts.map +1 -0
  241. package/dist/types/registries/builder.d.ts +340 -0
  242. package/dist/types/registries/builder.d.ts.map +1 -0
  243. package/dist/types/registries/discovery.d.ts +333 -0
  244. package/dist/types/registries/discovery.d.ts.map +1 -0
  245. package/dist/types/registries/index.d.ts +48 -0
  246. package/dist/types/registries/index.d.ts.map +1 -0
  247. package/dist/types/registries/session.d.ts +323 -0
  248. package/dist/types/registries/session.d.ts.map +1 -0
  249. package/dist/types/registries/x402.d.ts +463 -0
  250. package/dist/types/registries/x402.d.ts.map +1 -0
  251. package/dist/types/types/accounts.d.ts +565 -0
  252. package/dist/types/types/accounts.d.ts.map +1 -0
  253. package/dist/types/types/common.d.ts +166 -0
  254. package/dist/types/types/common.d.ts.map +1 -0
  255. package/dist/types/types/enums.d.ts +238 -0
  256. package/dist/types/types/enums.d.ts.map +1 -0
  257. package/dist/types/types/index.d.ts +28 -0
  258. package/dist/types/types/index.d.ts.map +1 -0
  259. package/dist/types/types/instructions.d.ts +366 -0
  260. package/dist/types/types/instructions.d.ts.map +1 -0
  261. package/dist/types/utils/hash.d.ts +48 -0
  262. package/dist/types/utils/hash.d.ts.map +1 -0
  263. package/dist/types/utils/index.d.ts +19 -0
  264. package/dist/types/utils/index.d.ts.map +1 -0
  265. package/dist/types/utils/serialization.d.ts +69 -0
  266. package/dist/types/utils/serialization.d.ts.map +1 -0
  267. package/dist/types/utils/validation.d.ts +29 -0
  268. package/dist/types/utils/validation.d.ts.map +1 -0
  269. package/package.json +178 -0
  270. package/src/constants/index.ts +44 -0
  271. package/src/constants/limits.ts +165 -0
  272. package/src/constants/programs.ts +83 -0
  273. package/src/constants/seeds.ts +66 -0
  274. package/src/core/client.ts +416 -0
  275. package/src/core/connection.ts +409 -0
  276. package/src/core/index.ts +20 -0
  277. package/src/errors/index.ts +346 -0
  278. package/src/events/index.ts +335 -0
  279. package/src/idl/index.ts +76 -0
  280. package/src/idl/synapse_agent_sap.json +9710 -0
  281. package/src/index.ts +253 -0
  282. package/src/modules/agent.ts +319 -0
  283. package/src/modules/attestation.ts +168 -0
  284. package/src/modules/base.ts +158 -0
  285. package/src/modules/escrow.ts +308 -0
  286. package/src/modules/feedback.ts +186 -0
  287. package/src/modules/index.ts +24 -0
  288. package/src/modules/indexing.ts +444 -0
  289. package/src/modules/ledger.ts +262 -0
  290. package/src/modules/tools.ts +411 -0
  291. package/src/modules/vault.ts +533 -0
  292. package/src/pda/index.ts +512 -0
  293. package/src/plugin/index.ts +1202 -0
  294. package/src/plugin/protocols.ts +404 -0
  295. package/src/plugin/schemas.ts +909 -0
  296. package/src/postgres/adapter.ts +904 -0
  297. package/src/postgres/index.ts +59 -0
  298. package/src/postgres/schema.sql +683 -0
  299. package/src/postgres/serializers.ts +485 -0
  300. package/src/postgres/sync.ts +254 -0
  301. package/src/postgres/types.ts +245 -0
  302. package/src/registries/builder.ts +607 -0
  303. package/src/registries/discovery.ts +572 -0
  304. package/src/registries/index.ts +77 -0
  305. package/src/registries/session.ts +613 -0
  306. package/src/registries/x402.ts +906 -0
  307. package/src/types/accounts.ts +618 -0
  308. package/src/types/common.ts +187 -0
  309. package/src/types/enums.ts +214 -0
  310. package/src/types/index.ts +92 -0
  311. package/src/types/instructions.ts +413 -0
  312. package/src/utils/hash.ts +57 -0
  313. package/src/utils/index.ts +19 -0
  314. package/src/utils/serialization.ts +98 -0
  315. package/src/utils/validation.ts +36 -0
@@ -0,0 +1,413 @@
1
+ /**
2
+ * @module types/instructions
3
+ * @description Instruction argument DTOs and helper enumerations.
4
+ *
5
+ * These interfaces map 1:1 to the Anchor instruction argument structs.
6
+ * Use them when calling SDK module methods.
7
+ *
8
+ * @category Types
9
+ * @since v0.1.0
10
+ */
11
+
12
+ import type { PublicKey } from "@solana/web3.js";
13
+ import type BN from "bn.js";
14
+ import type { Capability, PricingTier, VolumeCurveBreakpoint } from "./common";
15
+
16
+ // ═══════════════════════════════════════════════════════════════════
17
+ // Agent Instructions
18
+ // ═══════════════════════════════════════════════════════════════════
19
+
20
+ /**
21
+ * @interface RegisterAgentArgs
22
+ * @description Arguments for the `registerAgent` instruction.
23
+ *
24
+ * Creates a new on-chain agent identity with the given profile,
25
+ * capabilities, pricing tiers, and protocol support.
26
+ *
27
+ * @category Types
28
+ * @since v0.1.0
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { TokenType } from "@synapse-sap/sdk";
33
+ *
34
+ * const args: RegisterAgentArgs = {
35
+ * name: "My Agent",
36
+ * description: "A helpful Solana agent",
37
+ * capabilities: [{ id: "jupiter:swap", description: null, protocolId: "jupiter", version: "1.0" }],
38
+ * pricing: [],
39
+ * protocols: ["solana-agent-protocol"],
40
+ * };
41
+ * ```
42
+ */
43
+ export interface RegisterAgentArgs {
44
+ /** Agent display name. */
45
+ readonly name: string;
46
+ /** Agent description. */
47
+ readonly description: string;
48
+ /** Capabilities the agent exposes. */
49
+ readonly capabilities: Capability[];
50
+ /** Pricing tiers for the agent's services. */
51
+ readonly pricing: PricingTier[];
52
+ /** Supported protocol identifiers. */
53
+ readonly protocols: string[];
54
+ /** Optional off-chain agent identifier. */
55
+ readonly agentId?: string | null;
56
+ /** Optional URI to extended metadata. */
57
+ readonly agentUri?: string | null;
58
+ /** Optional x402 payment endpoint. */
59
+ readonly x402Endpoint?: string | null;
60
+ }
61
+
62
+ /**
63
+ * @interface UpdateAgentArgs
64
+ * @description Arguments for the `updateAgent` instruction.
65
+ *
66
+ * All fields are optional — pass only the fields you want to change.
67
+ * `null` values are ignored on-chain.
68
+ *
69
+ * @category Types
70
+ * @since v0.1.0
71
+ */
72
+ export interface UpdateAgentArgs {
73
+ readonly name?: string | null;
74
+ readonly description?: string | null;
75
+ readonly capabilities?: Capability[] | null;
76
+ readonly pricing?: PricingTier[] | null;
77
+ readonly protocols?: string[] | null;
78
+ readonly agentId?: string | null;
79
+ readonly agentUri?: string | null;
80
+ readonly x402Endpoint?: string | null;
81
+ }
82
+
83
+ // ═══════════════════════════════════════════════════════════════════
84
+ // Feedback Instructions
85
+ // ═══════════════════════════════════════════════════════════════════
86
+
87
+ /**
88
+ * @interface GiveFeedbackArgs
89
+ * @description Arguments for the `giveFeedback` instruction.
90
+ *
91
+ * Submits a reputation score and tag for the target agent.
92
+ * Each reviewer can only submit one feedback per agent.
93
+ *
94
+ * @category Types
95
+ * @since v0.1.0
96
+ */
97
+ export interface GiveFeedbackArgs {
98
+ /** Reputation score (1–100). */
99
+ readonly score: number;
100
+ /** Freeform tag / category for the feedback. */
101
+ readonly tag: string;
102
+ /** Optional SHA-256 hash of an off-chain comment. */
103
+ readonly commentHash?: number[] | null; // [u8; 32]
104
+ }
105
+
106
+ /**
107
+ * @interface UpdateFeedbackArgs
108
+ * @description Arguments for the `updateFeedback` instruction.
109
+ *
110
+ * Allows the original reviewer to revise their score and/or tag.
111
+ *
112
+ * @category Types
113
+ * @since v0.1.0
114
+ */
115
+ export interface UpdateFeedbackArgs {
116
+ /** Updated reputation score (1–100). */
117
+ readonly newScore: number;
118
+ /** Updated tag (optional). */
119
+ readonly newTag?: string | null;
120
+ /** Updated off-chain comment hash (optional). */
121
+ readonly commentHash?: number[] | null; // [u8; 32]
122
+ }
123
+
124
+ // ═══════════════════════════════════════════════════════════════════
125
+ // Tool Instructions
126
+ // ═══════════════════════════════════════════════════════════════════
127
+
128
+ /**
129
+ * @interface PublishToolArgs
130
+ * @description Arguments for the `publishTool` instruction.
131
+ *
132
+ * Registers a new tool descriptor on-chain with hashed metadata.
133
+ * Hash fields are SHA-256 digests of the corresponding off-chain content.
134
+ *
135
+ * @category Types
136
+ * @since v0.1.0
137
+ */
138
+ export interface PublishToolArgs {
139
+ /** Human-readable tool name. */
140
+ readonly toolName: string;
141
+ /** SHA-256 hash of the tool name (PDA seed). */
142
+ readonly toolNameHash: number[]; // [u8; 32]
143
+ /** SHA-256 hash of the protocol identifier. */
144
+ readonly protocolHash: number[]; // [u8; 32]
145
+ /** SHA-256 hash of the tool description. */
146
+ readonly descriptionHash: number[]; // [u8; 32]
147
+ /** SHA-256 hash of the input JSON schema. */
148
+ readonly inputSchemaHash: number[]; // [u8; 32]
149
+ /** SHA-256 hash of the output JSON schema. */
150
+ readonly outputSchemaHash: number[];// [u8; 32]
151
+ /** HTTP method discriminant index. */
152
+ readonly httpMethod: number;
153
+ /** Tool category discriminant index. */
154
+ readonly category: number;
155
+ /** Total number of parameters. */
156
+ readonly paramsCount: number;
157
+ /** Number of required parameters. */
158
+ readonly requiredParams: number;
159
+ /** Whether the tool is a compound (multi-step) operation. */
160
+ readonly isCompound: boolean;
161
+ }
162
+
163
+ /**
164
+ * @interface UpdateToolArgs
165
+ * @description Arguments for the `updateTool` instruction.
166
+ *
167
+ * All fields are optional — only pass the fields to update.
168
+ *
169
+ * @category Types
170
+ * @since v0.1.0
171
+ */
172
+ export interface UpdateToolArgs {
173
+ readonly descriptionHash?: number[] | null;
174
+ readonly inputSchemaHash?: number[] | null;
175
+ readonly outputSchemaHash?: number[] | null;
176
+ readonly httpMethod?: number | null;
177
+ readonly category?: number | null;
178
+ readonly paramsCount?: number | null;
179
+ readonly requiredParams?: number | null;
180
+ }
181
+
182
+ /**
183
+ * @interface InscribeToolSchemaArgs
184
+ * @description Arguments for the `inscribeToolSchema` instruction.
185
+ *
186
+ * Writes a tool’s JSON schema (input, output, or description) on-chain
187
+ * as an inscription, with optional compression.
188
+ *
189
+ * @category Types
190
+ * @since v0.1.0
191
+ * @see {@link SchemaType} for schema type discriminants.
192
+ * @see {@link CompressionType} for compression discriminants.
193
+ */
194
+ export interface InscribeToolSchemaArgs {
195
+ /** Schema type discriminant (input / output / description). */
196
+ readonly schemaType: number;
197
+ /** Raw (optionally compressed) schema bytes. */
198
+ readonly schemaData: Buffer;
199
+ /** SHA-256 hash of the uncompressed schema. */
200
+ readonly schemaHash: number[]; // [u8; 32]
201
+ /** Compression algorithm discriminant. */
202
+ readonly compression: number;
203
+ }
204
+
205
+ // ═══════════════════════════════════════════════════════════════════
206
+ // Memory Vault Instructions
207
+ // ═══════════════════════════════════════════════════════════════════
208
+
209
+ /**
210
+ * @interface InscribeMemoryArgs
211
+ * @description Arguments for the `inscribeMemory` instruction.
212
+ *
213
+ * Writes an encrypted memory fragment into a vault session.
214
+ * Supports multi-fragment inscriptions and epoch-based partitioning.
215
+ *
216
+ * @category Types
217
+ * @since v0.1.0
218
+ */
219
+ export interface InscribeMemoryArgs {
220
+ /** Sequence number within the session. */
221
+ readonly sequence: number;
222
+ /** NaCl-encrypted payload. */
223
+ readonly encryptedData: Buffer;
224
+ /** Encryption nonce (12 bytes). */
225
+ readonly nonce: number[]; // [u8; 12]
226
+ /** SHA-256 hash of the plaintext content. */
227
+ readonly contentHash: number[];// [u8; 32]
228
+ /** Total fragments in this inscription. */
229
+ readonly totalFragments: number;
230
+ /** Zero-based index of this fragment. */
231
+ readonly fragmentIndex: number;
232
+ /** Compression algorithm discriminant. */
233
+ readonly compression: number;
234
+ /** Target epoch index. */
235
+ readonly epochIndex: number;
236
+ }
237
+
238
+ /**
239
+ * @interface CompactInscribeArgs
240
+ * @description Arguments for the `compactInscribe` instruction.
241
+ *
242
+ * A simplified inscription variant that omits fragmentation and epoch
243
+ * fields — ideal for small, single-fragment payloads.
244
+ *
245
+ * @category Types
246
+ * @since v0.1.0
247
+ */
248
+ export interface CompactInscribeArgs {
249
+ /** Sequence number within the session. */
250
+ readonly sequence: number;
251
+ /** NaCl-encrypted payload. */
252
+ readonly encryptedData: Buffer;
253
+ /** Encryption nonce (12 bytes). */
254
+ readonly nonce: number[]; // [u8; 12]
255
+ /** SHA-256 hash of the plaintext content. */
256
+ readonly contentHash: number[]; // [u8; 32]
257
+ }
258
+
259
+ // ═══════════════════════════════════════════════════════════════════
260
+ // Escrow Instructions
261
+ // ═══════════════════════════════════════════════════════════════════
262
+
263
+ /**
264
+ * @interface CreateEscrowArgs
265
+ * @description Arguments for the `createEscrow` instruction.
266
+ *
267
+ * Creates a pre-funded escrow account for micropayments to an agent,
268
+ * optionally with volume-based discount breakpoints.
269
+ *
270
+ * @category Types
271
+ * @since v0.1.0
272
+ * @see {@link VolumeCurveBreakpoint} for discount curve details.
273
+ */
274
+ export interface CreateEscrowArgs {
275
+ /** Base price per call in token base units. */
276
+ readonly pricePerCall: BN;
277
+ /** Maximum number of calls the escrow should fund. */
278
+ readonly maxCalls: BN;
279
+ /** Initial deposit amount. */
280
+ readonly initialDeposit: BN;
281
+ /** Unix timestamp when the escrow expires. */
282
+ readonly expiresAt: BN;
283
+ /** Volume discount breakpoints (pass `[]` for none). */
284
+ readonly volumeCurve: VolumeCurveBreakpoint[];
285
+ /** SPL token mint (pass `null` for native SOL). */
286
+ readonly tokenMint: PublicKey | null;
287
+ /** Decimal places for the token. */
288
+ readonly tokenDecimals: number;
289
+ }
290
+
291
+ // ═══════════════════════════════════════════════════════════════════
292
+ // Attestation Instructions
293
+ // ═══════════════════════════════════════════════════════════════════
294
+
295
+ /**
296
+ * @interface CreateAttestationArgs
297
+ * @description Arguments for the `createAttestation` instruction.
298
+ *
299
+ * Issues a web-of-trust attestation for a target agent.
300
+ *
301
+ * @category Types
302
+ * @since v0.1.0
303
+ */
304
+ export interface CreateAttestationArgs {
305
+ /** Freeform attestation type (e.g. `"kyc"`, `"audit"`). */
306
+ readonly attestationType: string;
307
+ /** SHA-256 hash of off-chain attestation metadata. */
308
+ readonly metadataHash: number[]; // [u8; 32]
309
+ /** Unix timestamp when the attestation expires. */
310
+ readonly expiresAt: BN;
311
+ }
312
+
313
+ // ═══════════════════════════════════════════════════════════════════
314
+ // Permission & Schema Helpers
315
+ // ═══════════════════════════════════════════════════════════════════
316
+
317
+ /**
318
+ * @name DelegatePermission
319
+ * @description Bitmask constants for vault delegate permissions.
320
+ *
321
+ * Combine with bitwise OR to grant multiple permissions.
322
+ *
323
+ * | Bit | Value | Permission |
324
+ * | --- | ----- | ------------------- |
325
+ * | 0 | 1 | Inscribe memories |
326
+ * | 1 | 2 | Close sessions |
327
+ * | 2 | 4 | Open sessions |
328
+ * | — | 7 | All permissions |
329
+ *
330
+ * @category Types
331
+ * @since v0.1.0
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * import { DelegatePermission } from "@synapse-sap/sdk";
336
+ *
337
+ * // Grant inscribe + open session
338
+ * const perms = DelegatePermission.Inscribe | DelegatePermission.OpenSession;
339
+ * ```
340
+ */
341
+ export const DelegatePermission = {
342
+ Inscribe: 1,
343
+ CloseSession: 2,
344
+ OpenSession: 4,
345
+ All: 7,
346
+ } as const;
347
+
348
+ /**
349
+ * @name DelegatePermissionBit
350
+ * @description Union of valid {@link DelegatePermission} bit values.
351
+ */
352
+ export type DelegatePermissionBit =
353
+ (typeof DelegatePermission)[keyof typeof DelegatePermission];
354
+
355
+ /**
356
+ * @name SchemaType
357
+ * @description Numeric discriminants for tool schema types.
358
+ *
359
+ * Used in the `inscribeToolSchema` instruction to specify which schema
360
+ * is being written on-chain.
361
+ *
362
+ * @category Types
363
+ * @since v0.1.0
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * import { SchemaType } from "@synapse-sap/sdk";
368
+ *
369
+ * const args = { schemaType: SchemaType.Input, ... };
370
+ * ```
371
+ */
372
+ export const SchemaType = {
373
+ Input: 0,
374
+ Output: 1,
375
+ Description: 2,
376
+ } as const;
377
+
378
+ /**
379
+ * @name SchemaTypeValue
380
+ * @description Union of valid {@link SchemaType} discriminant values.
381
+ */
382
+ export type SchemaTypeValue = (typeof SchemaType)[keyof typeof SchemaType];
383
+
384
+ /**
385
+ * @name CompressionType
386
+ * @description Numeric discriminants for compression algorithms.
387
+ *
388
+ * Used in inscription instructions to declare the compression format
389
+ * of the payload so consumers can decompress correctly.
390
+ *
391
+ * @category Types
392
+ * @since v0.1.0
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { CompressionType } from "@synapse-sap/sdk";
397
+ *
398
+ * const args = { compression: CompressionType.Gzip, ... };
399
+ * ```
400
+ */
401
+ export const CompressionType = {
402
+ None: 0,
403
+ Deflate: 1,
404
+ Gzip: 2,
405
+ Brotli: 3,
406
+ } as const;
407
+
408
+ /**
409
+ * @name CompressionTypeValue
410
+ * @description Union of valid {@link CompressionType} discriminant values.
411
+ */
412
+ export type CompressionTypeValue =
413
+ (typeof CompressionType)[keyof typeof CompressionType];
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @module utils/hash
3
+ * @description Cryptographic hashing utilities.
4
+ *
5
+ * @category Utils
6
+ * @since v0.1.0
7
+ */
8
+
9
+ import { createHash } from "crypto";
10
+
11
+ /**
12
+ * Compute the SHA-256 hash of a UTF-8 string or byte buffer.
13
+ *
14
+ * Returns a 32-byte `Uint8Array` suitable for PDA seeds
15
+ * and Anchor instruction arguments.
16
+ *
17
+ * @name sha256
18
+ * @description Hashes the input using Node’s `crypto.createHash("sha256")`.
19
+ * @param input - A UTF-8 string, `Buffer`, or `Uint8Array` to hash.
20
+ * @returns {Uint8Array} 32-byte SHA-256 digest.
21
+ * @category Utils
22
+ * @since v0.1.0
23
+ * @example
24
+ * ```ts
25
+ * import { sha256 } from "@synapse-sap/sdk/utils";
26
+ *
27
+ * const hash = sha256("jupiter:swap"); // Uint8Array (32 bytes)
28
+ * ```
29
+ */
30
+ export const sha256 = (input: string | Buffer | Uint8Array): Uint8Array => {
31
+ const hash = createHash("sha256");
32
+ hash.update(
33
+ typeof input === "string" ? Buffer.from(input, "utf-8") : input,
34
+ );
35
+ return new Uint8Array(hash.digest());
36
+ };
37
+
38
+ /**
39
+ * Convert a `Uint8Array` hash to a plain `number[]`.
40
+ *
41
+ * Anchor instruction argument types expect `number[]` for hash fields
42
+ * rather than typed arrays.
43
+ *
44
+ * @name hashToArray
45
+ * @description Converts a byte array (typically 32 bytes) to a plain JavaScript `number[]`.
46
+ * @param hash - The byte array to convert.
47
+ * @returns {number[]} Shallow copy as a plain array of numbers.
48
+ * @category Utils
49
+ * @since v0.1.0
50
+ * @example
51
+ * ```ts
52
+ * import { sha256, hashToArray } from "@synapse-sap/sdk/utils";
53
+ *
54
+ * const arr = hashToArray(sha256("jupiter:swap")); // number[]
55
+ * ```
56
+ */
57
+ export const hashToArray = (hash: Uint8Array): number[] => Array.from(hash);
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module utils
3
+ * @description Shared utilities used across SDK modules.
4
+ *
5
+ * @category Utils
6
+ * @since v0.1.0
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { sha256, hashToArray, assert } from "@synapse-sap/sdk/utils";
11
+ *
12
+ * const hash = sha256("jupiter:swap");
13
+ * const arr = hashToArray(hash); // number[] for Anchor args
14
+ * ```
15
+ */
16
+
17
+ export { sha256, hashToArray } from "./hash";
18
+ export { assert } from "./validation";
19
+ export { serializeAccount, serializeValue } from "./serialization";
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @module utils/serialization
3
+ * @description JSON-safe serialization helpers for on-chain account data.
4
+ *
5
+ * On-chain Anchor account objects contain `PublicKey` and `BN` instances
6
+ * that are not JSON-serializable. These helpers convert them to plain
7
+ * strings (`base58` and decimal `string`) recursively.
8
+ *
9
+ * @category Utils
10
+ * @since v0.1.0
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { serializeAccount } from "@synapse-sap/sdk/utils";
15
+ *
16
+ * const raw = await program.account.agent.fetch(pda);
17
+ * const json = serializeAccount(raw);
18
+ * // { authority: "GBL...", totalCalls: "42", ... }
19
+ * ```
20
+ */
21
+
22
+ import { PublicKey } from "@solana/web3.js";
23
+ import BN from "bn.js";
24
+
25
+ /**
26
+ * Recursively convert a single value for JSON serialization.
27
+ *
28
+ * - `PublicKey` → base58 string
29
+ * - `BN` → decimal string
30
+ * - `Uint8Array` / `Buffer` → hex string
31
+ * - `Array` → recursed
32
+ * - plain `object` → recursed via {@link serializeAccount}
33
+ * - primitives → identity
34
+ *
35
+ * @name serializeValue
36
+ * @description Transforms a single Anchor-typed value into its JSON-safe equivalent.
37
+ * @param value - The value to serialize.
38
+ * @returns The JSON-safe representation of `value`.
39
+ * @category Utils
40
+ * @since v0.1.0
41
+ * @example
42
+ * ```ts
43
+ * import { serializeValue } from "@synapse-sap/sdk/utils";
44
+ *
45
+ * serializeValue(new PublicKey("11111111111111111111111111111111")); // "1111..."
46
+ * serializeValue(new BN(42)); // "42"
47
+ * ```
48
+ */
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ export function serializeValue(value: unknown): any {
51
+ if (value === null || value === undefined) return null;
52
+ if (value instanceof PublicKey) return value.toBase58();
53
+ if (BN.isBN(value)) return value.toString();
54
+ if (value instanceof Uint8Array || Buffer.isBuffer(value))
55
+ return Buffer.from(value).toString("hex");
56
+ if (Array.isArray(value)) return value.map(serializeValue);
57
+ if (typeof value === "object") {
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ return serializeAccount(value as Record<string, any>);
60
+ }
61
+ return value;
62
+ }
63
+
64
+ /**
65
+ * Serialize an entire on-chain account object to a JSON-safe shape.
66
+ *
67
+ * Iterates over each key and delegates to {@link serializeValue}.
68
+ * Handles `PublicKey` → base58, `BN` → string, and nested
69
+ * objects / arrays recursively.
70
+ *
71
+ * @name serializeAccount
72
+ * @description Converts all non-primitive fields in an Anchor account record to JSON-safe strings.
73
+ * @param obj - The raw account object returned by `program.account.<name>.fetch()`.
74
+ * @returns A new plain object with all values converted.
75
+ * @category Utils
76
+ * @since v0.1.0
77
+ * @example
78
+ * ```ts
79
+ * import { serializeAccount } from "@synapse-sap/sdk/utils";
80
+ *
81
+ * const raw = await program.account.agent.fetch(pda);
82
+ * const safe = serializeAccount(raw);
83
+ * console.log(JSON.stringify(safe));
84
+ * ```
85
+ */
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ export function serializeAccount(
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ obj: Record<string, any>,
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ ): Record<string, any> {
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ const result: Record<string, any> = {};
94
+ for (const [key, value] of Object.entries(obj)) {
95
+ result[key] = serializeValue(value);
96
+ }
97
+ return result;
98
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @module utils/validation
3
+ * @description Runtime assertion helpers.
4
+ *
5
+ * @category Utils
6
+ * @since v0.1.0
7
+ */
8
+
9
+ /**
10
+ * Assert that a condition holds, throwing a descriptive error otherwise.
11
+ *
12
+ * Uses TypeScript’s `asserts condition` return type so the compiler
13
+ * narrows the guarded value after the call.
14
+ *
15
+ * @name assert
16
+ * @description Runtime guard — throws `RangeError` with a `[SAP SDK]` prefix when the condition is falsy.
17
+ * @param condition - The boolean expression to verify.
18
+ * @param message - Human-readable message included in the thrown error.
19
+ * @throws {RangeError} When `condition` is `false`.
20
+ * @category Utils
21
+ * @since v0.1.0
22
+ * @example
23
+ * ```ts
24
+ * import { assert } from "@synapse-sap/sdk/utils";
25
+ *
26
+ * assert(name.length <= 64, "Agent name exceeds MAX_NAME_LEN");
27
+ * ```
28
+ */
29
+ export function assert(
30
+ condition: boolean,
31
+ message: string,
32
+ ): asserts condition {
33
+ if (!condition) {
34
+ throw new RangeError(`[SAP SDK] ${message}`);
35
+ }
36
+ }