@oobe-protocol-labs/synapse-sap-sdk 0.13.0 → 0.15.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 (418) hide show
  1. package/dist/cjs/accounts/index.js +286 -0
  2. package/dist/cjs/accounts/index.js.map +1 -0
  3. package/dist/cjs/client.js +125 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/constants/seeds.js +9 -9
  6. package/dist/cjs/constants/seeds.js.map +1 -1
  7. package/dist/cjs/constants.js +66 -0
  8. package/dist/cjs/constants.js.map +1 -0
  9. package/dist/cjs/errors.js +260 -0
  10. package/dist/cjs/errors.js.map +1 -0
  11. package/dist/cjs/events/index.js +37 -123
  12. package/dist/cjs/events/index.js.map +1 -1
  13. package/dist/cjs/idlTypes.js +4 -0
  14. package/dist/cjs/idlTypes.js.map +1 -0
  15. package/dist/cjs/index.js +75 -241
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/instructions/agent.js +90 -0
  18. package/dist/cjs/instructions/agent.js.map +1 -0
  19. package/dist/cjs/instructions/attestation.js +113 -0
  20. package/dist/cjs/instructions/attestation.js.map +1 -0
  21. package/dist/cjs/instructions/digest.js +29 -0
  22. package/dist/cjs/instructions/digest.js.map +1 -0
  23. package/dist/cjs/instructions/dispute.js +117 -0
  24. package/dist/cjs/instructions/dispute.js.map +1 -0
  25. package/dist/cjs/instructions/escrow.js +102 -0
  26. package/dist/cjs/instructions/escrow.js.map +1 -0
  27. package/dist/cjs/instructions/global.js +29 -0
  28. package/dist/cjs/instructions/global.js.map +1 -0
  29. package/dist/cjs/instructions/index.js +31 -0
  30. package/dist/cjs/instructions/index.js.map +1 -0
  31. package/dist/cjs/instructions/indexing.js +222 -0
  32. package/dist/cjs/instructions/indexing.js.map +1 -0
  33. package/dist/cjs/instructions/misc.js +74 -0
  34. package/dist/cjs/instructions/misc.js.map +1 -0
  35. package/dist/cjs/instructions/session.js +90 -0
  36. package/dist/cjs/instructions/session.js.map +1 -0
  37. package/dist/cjs/instructions/staking.js +133 -0
  38. package/dist/cjs/instructions/staking.js.map +1 -0
  39. package/dist/cjs/instructions/subscription.js +81 -0
  40. package/dist/cjs/instructions/subscription.js.map +1 -0
  41. package/dist/cjs/instructions/tools.js +110 -0
  42. package/dist/cjs/instructions/tools.js.map +1 -0
  43. package/dist/cjs/instructions/vault.js +107 -0
  44. package/dist/cjs/instructions/vault.js.map +1 -0
  45. package/dist/cjs/pdas/index.js +120 -0
  46. package/dist/cjs/pdas/index.js.map +1 -0
  47. package/dist/cjs/registries/fairscale.js +1 -1
  48. package/dist/cjs/registries/fairscale.js.map +1 -1
  49. package/dist/cjs/registries/metaplex-bridge.js +1 -1
  50. package/dist/cjs/registries/metaplex-bridge.js.map +1 -1
  51. package/dist/cjs/types.js +45 -0
  52. package/dist/cjs/types.js.map +1 -0
  53. package/dist/cjs/utils/escrow-validation.js +1 -1
  54. package/dist/cjs/utils/escrow-validation.js.map +1 -1
  55. package/dist/cjs/utils/index.js +32 -83
  56. package/dist/cjs/utils/index.js.map +1 -1
  57. package/dist/cjs/utils/merchant-validator.js +5 -5
  58. package/dist/cjs/utils/merchant-validator.js.map +1 -1
  59. package/dist/cjs/utils/validate.js +236 -0
  60. package/dist/cjs/utils/validate.js.map +1 -0
  61. package/dist/cjs/utils/volume-curve.js +1 -1
  62. package/dist/cjs/utils/volume-curve.js.map +1 -1
  63. package/dist/esm/accounts/index.d.ts +11 -0
  64. package/dist/esm/accounts/index.d.ts.map +1 -0
  65. package/dist/esm/accounts/index.js +273 -0
  66. package/dist/esm/accounts/index.js.map +1 -0
  67. package/dist/esm/client.d.ts +55 -0
  68. package/dist/esm/client.d.ts.map +1 -0
  69. package/dist/esm/client.js +87 -0
  70. package/dist/esm/client.js.map +1 -0
  71. package/dist/esm/constants/addresses.d.ts +117 -0
  72. package/dist/esm/constants/addresses.d.ts.map +1 -0
  73. package/dist/esm/constants/index.d.ts +31 -0
  74. package/dist/esm/constants/index.d.ts.map +1 -0
  75. package/dist/esm/constants/limits.d.ts +149 -0
  76. package/dist/esm/constants/limits.d.ts.map +1 -0
  77. package/{src/constants/network.ts → dist/esm/constants/network.d.ts} +23 -31
  78. package/dist/esm/constants/network.d.ts.map +1 -0
  79. package/{src/constants/payments.ts → dist/esm/constants/payments.d.ts} +11 -35
  80. package/dist/esm/constants/payments.d.ts.map +1 -0
  81. package/{src/constants/programs.ts → dist/esm/constants/programs.d.ts} +6 -20
  82. package/dist/esm/constants/programs.d.ts.map +1 -0
  83. package/dist/esm/constants/seeds.d.ts +80 -0
  84. package/dist/esm/constants/seeds.d.ts.map +1 -0
  85. package/dist/esm/constants/seeds.js +9 -9
  86. package/dist/esm/constants/seeds.js.map +1 -1
  87. package/dist/esm/constants.d.ts +39 -0
  88. package/dist/esm/constants.d.ts.map +1 -0
  89. package/dist/esm/constants.js +41 -0
  90. package/dist/esm/constants.js.map +1 -0
  91. package/dist/esm/core/client.d.ts +452 -0
  92. package/dist/esm/core/client.d.ts.map +1 -0
  93. package/dist/esm/core/connection.d.ts +305 -0
  94. package/dist/esm/core/connection.d.ts.map +1 -0
  95. package/{src/core/index.ts → dist/esm/core/index.d.ts} +1 -1
  96. package/dist/esm/core/index.d.ts.map +1 -0
  97. package/dist/esm/errors/index.d.ts +276 -0
  98. package/dist/esm/errors/index.d.ts.map +1 -0
  99. package/dist/esm/errors.d.ts +119 -0
  100. package/dist/esm/errors.d.ts.map +1 -0
  101. package/dist/esm/errors.js +252 -0
  102. package/dist/esm/errors.js.map +1 -0
  103. package/dist/esm/events/geyser.d.ts +150 -0
  104. package/dist/esm/events/geyser.d.ts.map +1 -0
  105. package/dist/esm/events/index.d.ts +17 -0
  106. package/dist/esm/events/index.d.ts.map +1 -0
  107. package/dist/esm/events/index.js +34 -122
  108. package/dist/esm/events/index.js.map +1 -1
  109. package/{src/idl/index.ts → dist/esm/idl/index.d.ts} +9 -15
  110. package/dist/esm/idl/index.d.ts.map +1 -0
  111. package/dist/esm/idlTypes.d.ts +925 -0
  112. package/dist/esm/idlTypes.d.ts.map +1 -0
  113. package/dist/esm/idlTypes.js +3 -0
  114. package/dist/esm/idlTypes.js.map +1 -0
  115. package/dist/esm/index.d.ts +12 -0
  116. package/dist/esm/index.d.ts.map +1 -0
  117. package/dist/esm/index.js +15 -88
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/instructions/agent.d.ts +71 -0
  120. package/dist/esm/instructions/agent.d.ts.map +1 -0
  121. package/dist/esm/instructions/agent.js +86 -0
  122. package/dist/esm/instructions/agent.js.map +1 -0
  123. package/dist/esm/instructions/attestation.d.ts +76 -0
  124. package/dist/esm/instructions/attestation.d.ts.map +1 -0
  125. package/dist/esm/instructions/attestation.js +109 -0
  126. package/dist/esm/instructions/attestation.js.map +1 -0
  127. package/dist/esm/instructions/digest.d.ts +20 -0
  128. package/dist/esm/instructions/digest.d.ts.map +1 -0
  129. package/dist/esm/instructions/digest.js +25 -0
  130. package/dist/esm/instructions/digest.js.map +1 -0
  131. package/dist/esm/instructions/dispute.d.ts +81 -0
  132. package/dist/esm/instructions/dispute.d.ts.map +1 -0
  133. package/dist/esm/instructions/dispute.js +113 -0
  134. package/dist/esm/instructions/dispute.js.map +1 -0
  135. package/dist/esm/instructions/escrow.d.ts +79 -0
  136. package/dist/esm/instructions/escrow.d.ts.map +1 -0
  137. package/dist/esm/instructions/escrow.js +98 -0
  138. package/dist/esm/instructions/escrow.js.map +1 -0
  139. package/dist/esm/instructions/global.d.ts +14 -0
  140. package/dist/esm/instructions/global.d.ts.map +1 -0
  141. package/dist/esm/instructions/global.js +25 -0
  142. package/dist/esm/instructions/global.js.map +1 -0
  143. package/dist/esm/instructions/index.d.ts +14 -0
  144. package/dist/esm/instructions/index.d.ts.map +1 -0
  145. package/dist/esm/instructions/index.js +15 -0
  146. package/dist/esm/instructions/index.js.map +1 -0
  147. package/dist/esm/instructions/indexing.d.ts +150 -0
  148. package/dist/esm/instructions/indexing.d.ts.map +1 -0
  149. package/dist/esm/instructions/indexing.js +218 -0
  150. package/dist/esm/instructions/indexing.js.map +1 -0
  151. package/dist/esm/instructions/memory.d.ts +8 -0
  152. package/dist/esm/instructions/memory.d.ts.map +1 -0
  153. package/dist/esm/instructions/memory.js +234 -0
  154. package/dist/esm/instructions/memory.js.map +1 -0
  155. package/dist/esm/instructions/misc.d.ts +50 -0
  156. package/dist/esm/instructions/misc.d.ts.map +1 -0
  157. package/dist/esm/instructions/misc.js +70 -0
  158. package/dist/esm/instructions/misc.js.map +1 -0
  159. package/dist/esm/instructions/session.d.ts +57 -0
  160. package/dist/esm/instructions/session.d.ts.map +1 -0
  161. package/dist/esm/instructions/session.js +86 -0
  162. package/dist/esm/instructions/session.js.map +1 -0
  163. package/dist/esm/instructions/staking.d.ts +85 -0
  164. package/dist/esm/instructions/staking.d.ts.map +1 -0
  165. package/dist/esm/instructions/staking.js +129 -0
  166. package/dist/esm/instructions/staking.js.map +1 -0
  167. package/dist/esm/instructions/subscription.d.ts +50 -0
  168. package/dist/esm/instructions/subscription.d.ts.map +1 -0
  169. package/dist/esm/instructions/subscription.js +77 -0
  170. package/dist/esm/instructions/subscription.js.map +1 -0
  171. package/dist/esm/instructions/tools.d.ts +88 -0
  172. package/dist/esm/instructions/tools.d.ts.map +1 -0
  173. package/dist/esm/instructions/tools.js +106 -0
  174. package/dist/esm/instructions/tools.js.map +1 -0
  175. package/dist/esm/instructions/vault.d.ts +84 -0
  176. package/dist/esm/instructions/vault.d.ts.map +1 -0
  177. package/dist/esm/instructions/vault.js +103 -0
  178. package/dist/esm/instructions/vault.js.map +1 -0
  179. package/dist/esm/modules/agent.d.ts +166 -0
  180. package/dist/esm/modules/agent.d.ts.map +1 -0
  181. package/dist/esm/modules/attestation.d.ts +96 -0
  182. package/dist/esm/modules/attestation.d.ts.map +1 -0
  183. package/dist/esm/modules/base.d.ts +161 -0
  184. package/dist/esm/modules/base.d.ts.map +1 -0
  185. package/dist/esm/modules/escrow-v2.d.ts +169 -0
  186. package/dist/esm/modules/escrow-v2.d.ts.map +1 -0
  187. package/dist/esm/modules/feedback.d.ts +105 -0
  188. package/dist/esm/modules/feedback.d.ts.map +1 -0
  189. package/{src/modules/index.ts → dist/esm/modules/index.d.ts} +1 -1
  190. package/dist/esm/modules/index.d.ts.map +1 -0
  191. package/dist/esm/modules/indexing.d.ts +200 -0
  192. package/dist/esm/modules/indexing.d.ts.map +1 -0
  193. package/dist/esm/modules/ledger.d.ts +150 -0
  194. package/dist/esm/modules/ledger.d.ts.map +1 -0
  195. package/dist/esm/modules/receipt.d.ts +77 -0
  196. package/dist/esm/modules/receipt.d.ts.map +1 -0
  197. package/dist/esm/modules/staking.d.ts +51 -0
  198. package/dist/esm/modules/staking.d.ts.map +1 -0
  199. package/dist/esm/modules/subscription.d.ts +33 -0
  200. package/dist/esm/modules/subscription.d.ts.map +1 -0
  201. package/dist/esm/modules/tools.d.ts +182 -0
  202. package/dist/esm/modules/tools.d.ts.map +1 -0
  203. package/dist/esm/modules/vault.d.ts +240 -0
  204. package/dist/esm/modules/vault.d.ts.map +1 -0
  205. package/dist/esm/parser/client.d.ts +123 -0
  206. package/dist/esm/parser/client.d.ts.map +1 -0
  207. package/dist/esm/parser/complete.d.ts +90 -0
  208. package/dist/esm/parser/complete.d.ts.map +1 -0
  209. package/{src/parser/index.ts → dist/esm/parser/index.d.ts} +6 -37
  210. package/dist/esm/parser/index.d.ts.map +1 -0
  211. package/dist/esm/parser/inner.d.ts +114 -0
  212. package/dist/esm/parser/inner.d.ts.map +1 -0
  213. package/{src/parser/instructions.ts → dist/esm/parser/instructions.d.ts} +4 -63
  214. package/dist/esm/parser/instructions.d.ts.map +1 -0
  215. package/dist/esm/parser/transaction.d.ts +77 -0
  216. package/dist/esm/parser/transaction.d.ts.map +1 -0
  217. package/dist/esm/parser/types.d.ts +154 -0
  218. package/dist/esm/parser/types.d.ts.map +1 -0
  219. package/{src/pda/index.ts → dist/esm/pda/index.d.ts} +33 -442
  220. package/dist/esm/pda/index.d.ts.map +1 -0
  221. package/dist/esm/pdas/index.d.ts +37 -0
  222. package/dist/esm/pdas/index.d.ts.map +1 -0
  223. package/dist/esm/pdas/index.js +101 -0
  224. package/dist/esm/pdas/index.js.map +1 -0
  225. package/dist/esm/plugin/index.d.ts +171 -0
  226. package/dist/esm/plugin/index.d.ts.map +1 -0
  227. package/dist/esm/plugin/protocols.d.ts +152 -0
  228. package/dist/esm/plugin/protocols.d.ts.map +1 -0
  229. package/dist/esm/plugin/schemas.d.ts +829 -0
  230. package/dist/esm/plugin/schemas.d.ts.map +1 -0
  231. package/dist/esm/postgres/adapter.d.ts +355 -0
  232. package/dist/esm/postgres/adapter.d.ts.map +1 -0
  233. package/dist/esm/postgres/index.d.ts +24 -0
  234. package/dist/esm/postgres/index.d.ts.map +1 -0
  235. package/dist/esm/postgres/serializers.d.ts +30 -0
  236. package/dist/esm/postgres/serializers.d.ts.map +1 -0
  237. package/dist/esm/postgres/sync.d.ts +156 -0
  238. package/dist/esm/postgres/sync.d.ts.map +1 -0
  239. package/dist/esm/postgres/types.d.ts +167 -0
  240. package/dist/esm/postgres/types.d.ts.map +1 -0
  241. package/dist/esm/registries/builder.d.ts +340 -0
  242. package/dist/esm/registries/builder.d.ts.map +1 -0
  243. package/dist/esm/registries/discovery.d.ts +333 -0
  244. package/dist/esm/registries/discovery.d.ts.map +1 -0
  245. package/dist/esm/registries/fairscale.d.ts +680 -0
  246. package/dist/esm/registries/fairscale.d.ts.map +1 -0
  247. package/dist/esm/registries/fairscale.js +1 -1
  248. package/dist/esm/registries/fairscale.js.map +1 -1
  249. package/dist/esm/registries/index.d.ts +52 -0
  250. package/dist/esm/registries/index.d.ts.map +1 -0
  251. package/dist/esm/registries/metaplex-bridge.d.ts +489 -0
  252. package/dist/esm/registries/metaplex-bridge.d.ts.map +1 -0
  253. package/dist/esm/registries/metaplex-bridge.js +1 -1
  254. package/dist/esm/registries/metaplex-bridge.js.map +1 -1
  255. package/dist/esm/registries/session.d.ts +323 -0
  256. package/dist/esm/registries/session.d.ts.map +1 -0
  257. package/dist/esm/registries/x402.d.ts +530 -0
  258. package/dist/esm/registries/x402.d.ts.map +1 -0
  259. package/dist/esm/types/accounts.d.ts +765 -0
  260. package/dist/esm/types/accounts.d.ts.map +1 -0
  261. package/dist/esm/types/common.d.ts +166 -0
  262. package/dist/esm/types/common.d.ts.map +1 -0
  263. package/dist/esm/types/endpoint.d.ts +161 -0
  264. package/dist/esm/types/endpoint.d.ts.map +1 -0
  265. package/dist/esm/types/enums.d.ts +353 -0
  266. package/dist/esm/types/enums.d.ts.map +1 -0
  267. package/dist/esm/types/index.d.ts +29 -0
  268. package/dist/esm/types/index.d.ts.map +1 -0
  269. package/dist/esm/types/instructions.d.ts +400 -0
  270. package/dist/esm/types/instructions.d.ts.map +1 -0
  271. package/dist/esm/types.d.ts +236 -0
  272. package/dist/esm/types.d.ts.map +1 -0
  273. package/dist/esm/types.js +40 -0
  274. package/dist/esm/types.js.map +1 -0
  275. package/dist/esm/utils/anchor-errors.d.ts +61 -0
  276. package/dist/esm/utils/anchor-errors.d.ts.map +1 -0
  277. package/dist/esm/utils/endpoint-validator.d.ts +110 -0
  278. package/dist/esm/utils/endpoint-validator.d.ts.map +1 -0
  279. package/dist/esm/utils/escrow-validation.d.ts +145 -0
  280. package/dist/esm/utils/escrow-validation.d.ts.map +1 -0
  281. package/dist/esm/utils/escrow-validation.js +1 -1
  282. package/dist/esm/utils/escrow-validation.js.map +1 -1
  283. package/{src/utils/hash.ts → dist/esm/utils/hash.d.ts} +4 -42
  284. package/dist/esm/utils/hash.d.ts.map +1 -0
  285. package/dist/esm/utils/index.d.ts +6 -0
  286. package/dist/esm/utils/index.d.ts.map +1 -0
  287. package/dist/esm/utils/index.js +16 -33
  288. package/dist/esm/utils/index.js.map +1 -1
  289. package/dist/esm/utils/merchant-validator.d.ts +176 -0
  290. package/dist/esm/utils/merchant-validator.d.ts.map +1 -0
  291. package/dist/esm/utils/merchant-validator.js +1 -1
  292. package/dist/esm/utils/merchant-validator.js.map +1 -1
  293. package/dist/esm/utils/network-normalizer.d.ts +120 -0
  294. package/dist/esm/utils/network-normalizer.d.ts.map +1 -0
  295. package/dist/esm/utils/priority-fee.d.ts +205 -0
  296. package/dist/esm/utils/priority-fee.d.ts.map +1 -0
  297. package/dist/esm/utils/rpc-strategy.d.ts +172 -0
  298. package/dist/esm/utils/rpc-strategy.d.ts.map +1 -0
  299. package/dist/esm/utils/schemas.d.ts +351 -0
  300. package/dist/esm/utils/schemas.d.ts.map +1 -0
  301. package/{src/utils/serialization.ts → dist/esm/utils/serialization.d.ts} +3 -32
  302. package/dist/esm/utils/serialization.d.ts.map +1 -0
  303. package/dist/esm/utils/validate.d.ts +66 -0
  304. package/dist/esm/utils/validate.d.ts.map +1 -0
  305. package/dist/esm/utils/validate.js +221 -0
  306. package/dist/esm/utils/validate.js.map +1 -0
  307. package/{src/utils/validation.ts → dist/esm/utils/validation.d.ts} +2 -9
  308. package/dist/esm/utils/validation.d.ts.map +1 -0
  309. package/{src/utils/volume-curve.ts → dist/esm/utils/volume-curve.d.ts} +2 -73
  310. package/dist/esm/utils/volume-curve.d.ts.map +1 -0
  311. package/dist/esm/utils/volume-curve.js +1 -1
  312. package/dist/esm/utils/volume-curve.js.map +1 -1
  313. package/dist/esm/utils/x402-direct.d.ts +114 -0
  314. package/dist/esm/utils/x402-direct.d.ts.map +1 -0
  315. package/dist/types/constants/seeds.d.ts +2 -0
  316. package/dist/types/constants/seeds.d.ts.map +1 -1
  317. package/dist/types/core/client.d.ts +21 -6
  318. package/dist/types/core/client.d.ts.map +1 -1
  319. package/dist/types/errors/index.d.ts +59 -0
  320. package/dist/types/errors/index.d.ts.map +1 -1
  321. package/dist/types/index.d.ts +3 -2
  322. package/dist/types/index.d.ts.map +1 -1
  323. package/dist/types/modules/agent.d.ts +9 -19
  324. package/dist/types/modules/agent.d.ts.map +1 -1
  325. package/dist/types/modules/attestation.d.ts.map +1 -1
  326. package/dist/types/modules/base.d.ts +54 -0
  327. package/dist/types/modules/base.d.ts.map +1 -1
  328. package/dist/types/modules/escrow-v2.d.ts +117 -1
  329. package/dist/types/modules/escrow-v2.d.ts.map +1 -1
  330. package/dist/types/modules/index.d.ts +1 -2
  331. package/dist/types/modules/index.d.ts.map +1 -1
  332. package/dist/types/modules/receipt.d.ts +14 -0
  333. package/dist/types/modules/receipt.d.ts.map +1 -1
  334. package/dist/types/modules/subscription.d.ts.map +1 -1
  335. package/dist/types/modules/tools.d.ts +0 -10
  336. package/dist/types/modules/tools.d.ts.map +1 -1
  337. package/dist/types/modules/vault.d.ts.map +1 -1
  338. package/dist/types/pda/index.d.ts +17 -0
  339. package/dist/types/pda/index.d.ts.map +1 -1
  340. package/dist/types/plugin/index.d.ts.map +1 -1
  341. package/dist/types/registries/builder.d.ts +2 -9
  342. package/dist/types/registries/builder.d.ts.map +1 -1
  343. package/dist/types/registries/metaplex-bridge.d.ts.map +1 -1
  344. package/dist/types/registries/session.d.ts +3 -9
  345. package/dist/types/registries/session.d.ts.map +1 -1
  346. package/dist/types/registries/x402.d.ts +2 -9
  347. package/dist/types/registries/x402.d.ts.map +1 -1
  348. package/dist/types/types/accounts.d.ts +52 -0
  349. package/dist/types/types/accounts.d.ts.map +1 -1
  350. package/dist/types/types/index.d.ts +1 -1
  351. package/dist/types/types/index.d.ts.map +1 -1
  352. package/dist/types/utils/rpc-strategy.d.ts +7 -0
  353. package/dist/types/utils/rpc-strategy.d.ts.map +1 -1
  354. package/package.json +59 -183
  355. package/src/constants/addresses.ts +0 -162
  356. package/src/constants/index.ts +0 -69
  357. package/src/constants/limits.ts +0 -165
  358. package/src/constants/seeds.ts +0 -85
  359. package/src/core/client.ts +0 -583
  360. package/src/core/connection.ts +0 -461
  361. package/src/errors/index.ts +0 -346
  362. package/src/events/geyser.ts +0 -384
  363. package/src/events/index.ts +0 -335
  364. package/src/events/yellowstone.d.ts +0 -7
  365. package/src/idl/synapse_agent_sap.json +0 -14595
  366. package/src/index.ts +0 -421
  367. package/src/modules/agent.ts +0 -319
  368. package/src/modules/attestation.ts +0 -168
  369. package/src/modules/base.ts +0 -247
  370. package/src/modules/escrow-v2.ts +0 -871
  371. package/src/modules/escrow.ts +0 -439
  372. package/src/modules/feedback.ts +0 -186
  373. package/src/modules/indexing.ts +0 -444
  374. package/src/modules/ledger.ts +0 -262
  375. package/src/modules/receipt.ts +0 -212
  376. package/src/modules/staking.ts +0 -223
  377. package/src/modules/subscription.ts +0 -147
  378. package/src/modules/tools.ts +0 -454
  379. package/src/modules/vault.ts +0 -558
  380. package/src/parser/client.ts +0 -211
  381. package/src/parser/complete.ts +0 -232
  382. package/src/parser/inner.ts +0 -255
  383. package/src/parser/transaction.ts +0 -200
  384. package/src/parser/types.ts +0 -182
  385. package/src/plugin/index.ts +0 -1224
  386. package/src/plugin/protocols.ts +0 -404
  387. package/src/plugin/schemas.ts +0 -941
  388. package/src/postgres/adapter.ts +0 -904
  389. package/src/postgres/index.ts +0 -59
  390. package/src/postgres/schema.sql +0 -683
  391. package/src/postgres/serializers.ts +0 -485
  392. package/src/postgres/sync.ts +0 -340
  393. package/src/postgres/types.ts +0 -245
  394. package/src/registries/builder.ts +0 -607
  395. package/src/registries/discovery.ts +0 -572
  396. package/src/registries/fairscale.ts +0 -1278
  397. package/src/registries/index.ts +0 -143
  398. package/src/registries/metaplex-bridge.ts +0 -1199
  399. package/src/registries/session.ts +0 -613
  400. package/src/registries/x402.ts +0 -1048
  401. package/src/types/accounts.ts +0 -858
  402. package/src/types/common.ts +0 -187
  403. package/src/types/endpoint.ts +0 -181
  404. package/src/types/enums.ts +0 -333
  405. package/src/types/index.ts +0 -121
  406. package/src/types/instructions.ts +0 -453
  407. package/src/utils/anchor-errors.ts +0 -461
  408. package/src/utils/endpoint-validator.ts +0 -300
  409. package/src/utils/escrow-validation.ts +0 -301
  410. package/src/utils/index.ts +0 -118
  411. package/src/utils/merchant-validator.ts +0 -359
  412. package/src/utils/network-normalizer.ts +0 -240
  413. package/src/utils/priority-fee.ts +0 -325
  414. package/src/utils/rpc-strategy.ts +0 -322
  415. package/src/utils/schemas.ts +0 -359
  416. package/src/utils/x402-direct.ts +0 -370
  417. /package/dist/{types → esm}/modules/escrow.d.ts +0 -0
  418. /package/dist/{types → esm}/modules/escrow.d.ts.map +0 -0
@@ -1,444 +0,0 @@
1
- /**
2
- * @module indexing
3
- * @description Scalable discovery layer — capability indexes, protocol indexes,
4
- * and tool category indexes for the Synapse Agent Protocol.
5
- *
6
- * Indexes are shared PDA-based registries that map agents and tools to
7
- * discovery dimensions, enabling efficient on-chain lookups.
8
- *
9
- * @category Modules
10
- * @since v0.1.0
11
- * @packageDocumentation
12
- */
13
-
14
- import { SystemProgram, type PublicKey, type TransactionSignature } from "@solana/web3.js";
15
- import { BaseModule } from "./base";
16
- import {
17
- deriveAgent,
18
- deriveCapabilityIndex,
19
- deriveProtocolIndex,
20
- deriveToolCategoryIndex,
21
- deriveGlobalRegistry,
22
- } from "../pda";
23
- import type {
24
- CapabilityIndexData,
25
- ProtocolIndexData,
26
- ToolCategoryIndexData,
27
- } from "../types";
28
- import { sha256, hashToArray } from "../utils";
29
-
30
- /**
31
- * @name IndexingModule
32
- * @description Manages on-chain discovery indexes for the Synapse Agent Protocol.
33
- * Provides methods to create, populate, prune, close, and fetch capability
34
- * indexes, protocol indexes, and tool category indexes.
35
- *
36
- * @category Modules
37
- * @since v0.1.0
38
- * @extends BaseModule
39
- *
40
- * @example
41
- * ```ts
42
- * const sap = new SapClient(provider);
43
- * // Create a capability index and add your agent
44
- * await sap.indexing.initCapabilityIndex("text-generation");
45
- * // Query agents by capability
46
- * const idx = await sap.indexing.fetchCapabilityIndex("text-generation");
47
- * ```
48
- */
49
- export class IndexingModule extends BaseModule {
50
- // ── Helpers ──────────────────────────────────────────
51
-
52
- /**
53
- * @name hash
54
- * @description Hash a capability or protocol ID string for use as a PDA seed.
55
- * Uses SHA-256 internally.
56
- * @param id - The capability or protocol identifier string.
57
- * @returns {Uint8Array} The 32-byte SHA-256 hash.
58
- * @since v0.1.0
59
- */
60
- hash(id: string): Uint8Array {
61
- return sha256(id);
62
- }
63
-
64
- // ── Capability Index ─────────────────────────────────
65
-
66
- /**
67
- * @name initCapabilityIndex
68
- * @description Create a new capability index and register the caller’s agent.
69
- * The capability ID is hashed to derive the PDA.
70
- * @param capabilityId - Human-readable capability identifier (e.g. `"text-generation"`).
71
- * @returns {Promise<TransactionSignature>} The transaction signature.
72
- * @since v0.1.0
73
- */
74
- async initCapabilityIndex(
75
- capabilityId: string,
76
- ): Promise<TransactionSignature> {
77
- const capHash = this.hash(capabilityId);
78
- const [agentPda] = deriveAgent(this.walletPubkey);
79
- const [capIdxPda] = deriveCapabilityIndex(capHash);
80
- const [globalPda] = deriveGlobalRegistry();
81
-
82
- return this.methods
83
- .initCapabilityIndex(capabilityId, hashToArray(capHash))
84
- .accounts({
85
- wallet: this.walletPubkey,
86
- agent: agentPda,
87
- capabilityIndex: capIdxPda,
88
- globalRegistry: globalPda,
89
- systemProgram: SystemProgram.programId,
90
- })
91
- .rpc();
92
- }
93
-
94
- /**
95
- * @name addToCapabilityIndex
96
- * @description Add the caller’s agent to an existing capability index.
97
- * @param capabilityId - The capability identifier string.
98
- * @returns {Promise<TransactionSignature>} The transaction signature.
99
- * @since v0.1.0
100
- */
101
- async addToCapabilityIndex(
102
- capabilityId: string,
103
- ): Promise<TransactionSignature> {
104
- const capHash = this.hash(capabilityId);
105
- const [agentPda] = deriveAgent(this.walletPubkey);
106
- const [capIdxPda] = deriveCapabilityIndex(capHash);
107
-
108
- return this.methods
109
- .addToCapabilityIndex(hashToArray(capHash))
110
- .accounts({
111
- wallet: this.walletPubkey,
112
- agent: agentPda,
113
- capabilityIndex: capIdxPda,
114
- })
115
- .rpc();
116
- }
117
-
118
- /**
119
- * @name removeFromCapabilityIndex
120
- * @description Remove the caller’s agent from a capability index.
121
- * @param capabilityId - The capability identifier string.
122
- * @returns {Promise<TransactionSignature>} The transaction signature.
123
- * @since v0.1.0
124
- */
125
- async removeFromCapabilityIndex(
126
- capabilityId: string,
127
- ): Promise<TransactionSignature> {
128
- const capHash = this.hash(capabilityId);
129
- const [agentPda] = deriveAgent(this.walletPubkey);
130
- const [capIdxPda] = deriveCapabilityIndex(capHash);
131
-
132
- return this.methods
133
- .removeFromCapabilityIndex(hashToArray(capHash))
134
- .accounts({
135
- wallet: this.walletPubkey,
136
- agent: agentPda,
137
- capabilityIndex: capIdxPda,
138
- })
139
- .rpc();
140
- }
141
-
142
- /**
143
- * @name closeCapabilityIndex
144
- * @description Close an empty capability index PDA and reclaim rent.
145
- * @param capabilityId - The capability identifier string.
146
- * @returns {Promise<TransactionSignature>} The transaction signature.
147
- * @since v0.1.0
148
- */
149
- async closeCapabilityIndex(
150
- capabilityId: string,
151
- ): Promise<TransactionSignature> {
152
- const capHash = this.hash(capabilityId);
153
- const [capIdxPda] = deriveCapabilityIndex(capHash);
154
- const [globalPda] = deriveGlobalRegistry();
155
-
156
- return this.methods
157
- .closeCapabilityIndex(hashToArray(capHash))
158
- .accounts({
159
- wallet: this.walletPubkey,
160
- capabilityIndex: capIdxPda,
161
- globalRegistry: globalPda,
162
- })
163
- .rpc();
164
- }
165
-
166
- // ── Protocol Index ───────────────────────────────────
167
-
168
- /**
169
- * @name initProtocolIndex
170
- * @description Create a new protocol index and register the caller’s agent.
171
- * The protocol ID is hashed to derive the PDA.
172
- * @param protocolId - Human-readable protocol identifier (e.g. `"mcp-v1"`).
173
- * @returns {Promise<TransactionSignature>} The transaction signature.
174
- * @since v0.1.0
175
- */
176
- async initProtocolIndex(
177
- protocolId: string,
178
- ): Promise<TransactionSignature> {
179
- const protoHash = this.hash(protocolId);
180
- const [agentPda] = deriveAgent(this.walletPubkey);
181
- const [protoIdxPda] = deriveProtocolIndex(protoHash);
182
- const [globalPda] = deriveGlobalRegistry();
183
-
184
- return this.methods
185
- .initProtocolIndex(protocolId, hashToArray(protoHash))
186
- .accounts({
187
- wallet: this.walletPubkey,
188
- agent: agentPda,
189
- protocolIndex: protoIdxPda,
190
- globalRegistry: globalPda,
191
- systemProgram: SystemProgram.programId,
192
- })
193
- .rpc();
194
- }
195
-
196
- /**
197
- * @name addToProtocolIndex
198
- * @description Add the caller’s agent to an existing protocol index.
199
- * @param protocolId - The protocol identifier string.
200
- * @returns {Promise<TransactionSignature>} The transaction signature.
201
- * @since v0.1.0
202
- */
203
- async addToProtocolIndex(
204
- protocolId: string,
205
- ): Promise<TransactionSignature> {
206
- const protoHash = this.hash(protocolId);
207
- const [agentPda] = deriveAgent(this.walletPubkey);
208
- const [protoIdxPda] = deriveProtocolIndex(protoHash);
209
-
210
- return this.methods
211
- .addToProtocolIndex(hashToArray(protoHash))
212
- .accounts({
213
- wallet: this.walletPubkey,
214
- agent: agentPda,
215
- protocolIndex: protoIdxPda,
216
- })
217
- .rpc();
218
- }
219
-
220
- /**
221
- * @name removeFromProtocolIndex
222
- * @description Remove the caller’s agent from a protocol index.
223
- * @param protocolId - The protocol identifier string.
224
- * @returns {Promise<TransactionSignature>} The transaction signature.
225
- * @since v0.1.0
226
- */
227
- async removeFromProtocolIndex(
228
- protocolId: string,
229
- ): Promise<TransactionSignature> {
230
- const protoHash = this.hash(protocolId);
231
- const [agentPda] = deriveAgent(this.walletPubkey);
232
- const [protoIdxPda] = deriveProtocolIndex(protoHash);
233
-
234
- return this.methods
235
- .removeFromProtocolIndex(hashToArray(protoHash))
236
- .accounts({
237
- wallet: this.walletPubkey,
238
- agent: agentPda,
239
- protocolIndex: protoIdxPda,
240
- })
241
- .rpc();
242
- }
243
-
244
- /**
245
- * @name closeProtocolIndex
246
- * @description Close an empty protocol index PDA and reclaim rent.
247
- * @param protocolId - The protocol identifier string.
248
- * @returns {Promise<TransactionSignature>} The transaction signature.
249
- * @since v0.1.0
250
- */
251
- async closeProtocolIndex(
252
- protocolId: string,
253
- ): Promise<TransactionSignature> {
254
- const protoHash = this.hash(protocolId);
255
- const [protoIdxPda] = deriveProtocolIndex(protoHash);
256
- const [globalPda] = deriveGlobalRegistry();
257
-
258
- return this.methods
259
- .closeProtocolIndex(hashToArray(protoHash))
260
- .accounts({
261
- wallet: this.walletPubkey,
262
- protocolIndex: protoIdxPda,
263
- globalRegistry: globalPda,
264
- })
265
- .rpc();
266
- }
267
-
268
- // ── Tool Category Index ──────────────────────────────
269
-
270
- /**
271
- * @name initToolCategoryIndex
272
- * @description Create a new tool category index PDA.
273
- * @param category - Numeric tool category enum value.
274
- * @returns {Promise<TransactionSignature>} The transaction signature.
275
- * @since v0.1.0
276
- */
277
- async initToolCategoryIndex(
278
- category: number,
279
- ): Promise<TransactionSignature> {
280
- const [catIdxPda] = deriveToolCategoryIndex(category);
281
-
282
- return this.methods
283
- .initToolCategoryIndex(category)
284
- .accounts({
285
- wallet: this.walletPubkey,
286
- toolCategoryIndex: catIdxPda,
287
- systemProgram: SystemProgram.programId,
288
- })
289
- .rpc();
290
- }
291
-
292
- /**
293
- * @name addToToolCategory
294
- * @description Add a tool to its matching category index.
295
- * @param category - Numeric tool category enum value.
296
- * @param toolPda - The tool descriptor PDA to add.
297
- * @returns {Promise<TransactionSignature>} The transaction signature.
298
- * @since v0.1.0
299
- */
300
- async addToToolCategory(
301
- category: number,
302
- toolPda: PublicKey,
303
- ): Promise<TransactionSignature> {
304
- const [agentPda] = deriveAgent(this.walletPubkey);
305
- const [catIdxPda] = deriveToolCategoryIndex(category);
306
-
307
- return this.methods
308
- .addToToolCategory(category)
309
- .accounts({
310
- wallet: this.walletPubkey,
311
- agent: agentPda,
312
- tool: toolPda,
313
- toolCategoryIndex: catIdxPda,
314
- })
315
- .rpc();
316
- }
317
-
318
- /**
319
- * @name removeFromToolCategory
320
- * @description Remove a tool from a category index.
321
- * @param category - Numeric tool category enum value.
322
- * @param toolPda - The tool descriptor PDA to remove.
323
- * @returns {Promise<TransactionSignature>} The transaction signature.
324
- * @since v0.1.0
325
- */
326
- async removeFromToolCategory(
327
- category: number,
328
- toolPda: PublicKey,
329
- ): Promise<TransactionSignature> {
330
- const [agentPda] = deriveAgent(this.walletPubkey);
331
- const [catIdxPda] = deriveToolCategoryIndex(category);
332
-
333
- return this.methods
334
- .removeFromToolCategory(category)
335
- .accounts({
336
- wallet: this.walletPubkey,
337
- agent: agentPda,
338
- tool: toolPda,
339
- toolCategoryIndex: catIdxPda,
340
- })
341
- .rpc();
342
- }
343
-
344
- /**
345
- * @name closeToolCategoryIndex
346
- * @description Close an empty tool category index PDA and reclaim rent.
347
- * @param category - Numeric tool category enum value.
348
- * @returns {Promise<TransactionSignature>} The transaction signature.
349
- * @since v0.1.0
350
- */
351
- async closeToolCategoryIndex(
352
- category: number,
353
- ): Promise<TransactionSignature> {
354
- const [catIdxPda] = deriveToolCategoryIndex(category);
355
-
356
- return this.methods
357
- .closeToolCategoryIndex(category)
358
- .accounts({
359
- wallet: this.walletPubkey,
360
- toolCategoryIndex: catIdxPda,
361
- })
362
- .rpc();
363
- }
364
-
365
- // ── Fetchers ─────────────────────────────────────────
366
-
367
- /**
368
- * @name fetchCapabilityIndex
369
- * @description Fetch a deserialized `CapabilityIndex` account by capability ID.
370
- * @param capabilityId - The capability identifier string.
371
- * @returns {Promise<CapabilityIndexData>} The capability index data.
372
- * @throws Will throw if the capability index does not exist.
373
- * @since v0.1.0
374
- */
375
- async fetchCapabilityIndex(capabilityId: string): Promise<CapabilityIndexData> {
376
- const [pda] = deriveCapabilityIndex(this.hash(capabilityId));
377
- return this.fetchAccount<CapabilityIndexData>("capabilityIndex", pda);
378
- }
379
-
380
- /**
381
- * @name fetchCapabilityIndexNullable
382
- * @description Fetch a deserialized `CapabilityIndex` account, or `null`
383
- * if it does not exist on-chain.
384
- * @param capabilityId - The capability identifier string.
385
- * @returns {Promise<CapabilityIndexData | null>} The capability index data or `null`.
386
- * @since v0.1.0
387
- */
388
- async fetchCapabilityIndexNullable(capabilityId: string): Promise<CapabilityIndexData | null> {
389
- const [pda] = deriveCapabilityIndex(this.hash(capabilityId));
390
- return this.fetchAccountNullable<CapabilityIndexData>("capabilityIndex", pda);
391
- }
392
-
393
- /**
394
- * @name fetchProtocolIndex
395
- * @description Fetch a deserialized `ProtocolIndex` account by protocol ID.
396
- * @param protocolId - The protocol identifier string.
397
- * @returns {Promise<ProtocolIndexData>} The protocol index data.
398
- * @throws Will throw if the protocol index does not exist.
399
- * @since v0.1.0
400
- */
401
- async fetchProtocolIndex(protocolId: string): Promise<ProtocolIndexData> {
402
- const [pda] = deriveProtocolIndex(this.hash(protocolId));
403
- return this.fetchAccount<ProtocolIndexData>("protocolIndex", pda);
404
- }
405
-
406
- /**
407
- * @name fetchProtocolIndexNullable
408
- * @description Fetch a deserialized `ProtocolIndex` account, or `null`
409
- * if it does not exist on-chain.
410
- * @param protocolId - The protocol identifier string.
411
- * @returns {Promise<ProtocolIndexData | null>} The protocol index data or `null`.
412
- * @since v0.1.0
413
- */
414
- async fetchProtocolIndexNullable(protocolId: string): Promise<ProtocolIndexData | null> {
415
- const [pda] = deriveProtocolIndex(this.hash(protocolId));
416
- return this.fetchAccountNullable<ProtocolIndexData>("protocolIndex", pda);
417
- }
418
-
419
- /**
420
- * @name fetchToolCategoryIndex
421
- * @description Fetch a deserialized `ToolCategoryIndex` account by category number.
422
- * @param category - Numeric tool category enum value.
423
- * @returns {Promise<ToolCategoryIndexData>} The tool category index data.
424
- * @throws Will throw if the tool category index does not exist.
425
- * @since v0.1.0
426
- */
427
- async fetchToolCategoryIndex(category: number): Promise<ToolCategoryIndexData> {
428
- const [pda] = deriveToolCategoryIndex(category);
429
- return this.fetchAccount<ToolCategoryIndexData>("toolCategoryIndex", pda);
430
- }
431
-
432
- /**
433
- * @name fetchToolCategoryIndexNullable
434
- * @description Fetch a deserialized `ToolCategoryIndex` account, or `null`
435
- * if it does not exist on-chain.
436
- * @param category - Numeric tool category enum value.
437
- * @returns {Promise<ToolCategoryIndexData | null>} The tool category index data or `null`.
438
- * @since v0.1.0
439
- */
440
- async fetchToolCategoryIndexNullable(category: number): Promise<ToolCategoryIndexData | null> {
441
- const [pda] = deriveToolCategoryIndex(category);
442
- return this.fetchAccountNullable<ToolCategoryIndexData>("toolCategoryIndex", pda);
443
- }
444
- }
@@ -1,262 +0,0 @@
1
- /**
2
- * @module ledger
3
- * @description Unified on-chain memory — init, write, seal, and close ledger.
4
- *
5
- * The recommended memory system: fixed-cost PDA with 4 KB ring buffer,
6
- * automatic TX log persistence, and rolling merkle proof.
7
- * Write cost is TX fee only (~0.000005 SOL). ZERO additional rent.
8
- *
9
- * @category Modules
10
- * @since v0.1.0
11
- * @packageDocumentation
12
- */
13
-
14
- import { SystemProgram, type PublicKey, type TransactionSignature } from "@solana/web3.js";
15
- import { BaseModule } from "./base";
16
- import { deriveLedger, deriveLedgerPage } from "../pda";
17
- import type { MemoryLedgerData, LedgerPageData } from "../types";
18
-
19
- /**
20
- * @name LedgerModule
21
- * @description Manage on-chain memory ledgers for sessions.
22
- * Each session can have one MemoryLedger PDA with a 4KB ring buffer for recent entries.
23
- * When the ring buffer fills, it can be sealed into a permanent LedgerPage.
24
- * Ledgers are designed for high-frequency writes with minimal cost (~0.000005 SOL per write).
25
- * Sealed pages are immutable and stored on-chain (~0.031 SOL per page).
26
- */
27
- /**
28
- * @name LedgerModule
29
- * @description Manages the unified on-chain memory ledger for the Solana Agent
30
- * Protocol. Provides methods to initialise a ledger with a 4 KB ring buffer,
31
- * write data (TX fee only), seal pages permanently, close ledgers, and
32
- * decode ring buffer contents.
33
- *
34
- * @category Modules
35
- * @since v0.1.0
36
- * @extends BaseModule
37
- *
38
- * @example
39
- * ```ts
40
- * const sap = new SapClient(provider);
41
- * // Init ledger, write data, seal
42
- * await sap.ledger.init(sessionPda);
43
- * await sap.ledger.write(sessionPda, data, contentHash);
44
- * await sap.ledger.seal(sessionPda);
45
- * ```
46
- */
47
- export class LedgerModule extends BaseModule {
48
- // ── PDA helpers ──────────────────────────────────────
49
-
50
- /**
51
- * @name deriveLedger
52
- * @description Derive the `MemoryLedger` PDA for a given session.
53
- * @param sessionPda - The session ledger PDA.
54
- * @returns A tuple of `[PublicKey, bump]` for the ledger PDA.
55
- * @see {@link deriveLedger} from `pda/` module for the underlying derivation.
56
- * @since v0.1.0
57
- */
58
- deriveLedger(sessionPda: PublicKey): readonly [PublicKey, number] {
59
- return deriveLedger(sessionPda);
60
- }
61
-
62
- /**
63
- * @name deriveLedgerPage
64
- * @description Derive a `LedgerPage` PDA for a given ledger and page index.
65
- * @param ledgerPda - The memory ledger PDA.
66
- * @param pageIndex - The zero-based page index.
67
- * @returns A tuple of `[PublicKey, bump]` for the page PDA.
68
- * @see {@link deriveLedgerPage} from `pda/` module for the underlying derivation.
69
- * @since v0.1.0
70
- */
71
- deriveLedgerPage(
72
- ledgerPda: PublicKey,
73
- pageIndex: number,
74
- ): readonly [PublicKey, number] {
75
- return deriveLedgerPage(ledgerPda, pageIndex);
76
- }
77
-
78
- // ── Instructions ─────────────────────────────────────
79
-
80
- /**
81
- * @name init
82
- * @description Create a `MemoryLedger` with a 4 KB ring buffer (~0.032 SOL rent).
83
- * @param sessionPda - The session ledger PDA to attach the ledger to.
84
- * @returns {Promise<TransactionSignature>} The transaction signature.
85
- * @since v0.1.0
86
- */
87
- async init(sessionPda: PublicKey): Promise<TransactionSignature> {
88
- const [ledgerPda] = deriveLedger(sessionPda);
89
-
90
- return this.methods
91
- .initLedger()
92
- .accounts({
93
- wallet: this.walletPubkey,
94
- session: sessionPda,
95
- ledger: ledgerPda,
96
- systemProgram: SystemProgram.programId,
97
- })
98
- .rpc();
99
- }
100
-
101
- /**
102
- * @name write
103
- * @description Write data to the ledger (ring buffer + TX log simultaneously).
104
- * Cost: TX fee only (~0.000005 SOL). ZERO additional rent.
105
- * @param sessionPda - The session ledger PDA.
106
- * @param data - The data payload to write (Buffer or Uint8Array).
107
- * @param contentHash - A 32-byte SHA-256 content hash for verification.
108
- * @returns {Promise<TransactionSignature>} The transaction signature.
109
- * @since v0.1.0
110
- */
111
- async write(
112
- sessionPda: PublicKey,
113
- data: Buffer | Uint8Array,
114
- contentHash: number[],
115
- ): Promise<TransactionSignature> {
116
- const [ledgerPda] = deriveLedger(sessionPda);
117
-
118
- return this.methods
119
- .writeLedger(Buffer.from(data), contentHash)
120
- .accounts({
121
- wallet: this.walletPubkey,
122
- session: sessionPda,
123
- ledger: ledgerPda,
124
- })
125
- .rpc();
126
- }
127
-
128
- /**
129
- * @name seal
130
- * @description Seal the ring buffer into a permanent `LedgerPage`.
131
- * Pages are WRITE-ONCE, NEVER-DELETE: ~0.031 SOL per page.
132
- * Automatically fetches the current page index from the ledger.
133
- * @param sessionPda - The session ledger PDA.
134
- * @returns {Promise<TransactionSignature>} The transaction signature.
135
- * @since v0.1.0
136
- */
137
- async seal(sessionPda: PublicKey): Promise<TransactionSignature> {
138
- const [ledgerPda] = deriveLedger(sessionPda);
139
- // Fetch ledger to get current page index
140
- const ledger = await this.fetchLedger(sessionPda);
141
- const [pagePda] = deriveLedgerPage(ledgerPda, ledger.numPages);
142
-
143
- return this.methods
144
- .sealLedger()
145
- .accounts({
146
- wallet: this.walletPubkey,
147
- session: sessionPda,
148
- ledger: ledgerPda,
149
- page: pagePda,
150
- systemProgram: SystemProgram.programId,
151
- })
152
- .rpc();
153
- }
154
-
155
- /**
156
- * @name close
157
- * @description Close a ledger PDA and reclaim ~0.032 SOL rent.
158
- * @param sessionPda - The session ledger PDA.
159
- * @returns {Promise<TransactionSignature>} The transaction signature.
160
- * @since v0.1.0
161
- */
162
- async close(sessionPda: PublicKey): Promise<TransactionSignature> {
163
- const [ledgerPda] = deriveLedger(sessionPda);
164
-
165
- return this.methods
166
- .closeLedger()
167
- .accounts({
168
- wallet: this.walletPubkey,
169
- session: sessionPda,
170
- ledger: ledgerPda,
171
- })
172
- .rpc();
173
- }
174
-
175
- // ── Fetchers ─────────────────────────────────────────
176
-
177
- /**
178
- * @name fetchLedger
179
- * @description Fetch a deserialized `MemoryLedger` account.
180
- * @param sessionPda - The session ledger PDA.
181
- * @returns {Promise<MemoryLedgerData>} The memory ledger data.
182
- * @throws Will throw if the ledger does not exist.
183
- * @since v0.1.0
184
- */
185
- async fetchLedger(sessionPda: PublicKey): Promise<MemoryLedgerData> {
186
- const [pda] = deriveLedger(sessionPda);
187
- return this.fetchAccount<MemoryLedgerData>("memoryLedger", pda);
188
- }
189
-
190
- /**
191
- * @name fetchLedgerNullable
192
- * @description Fetch a deserialized `MemoryLedger` account, or `null`
193
- * if it does not exist on-chain.
194
- * @param sessionPda - The session ledger PDA.
195
- * @returns {Promise<MemoryLedgerData | null>} The ledger data or `null`.
196
- * @since v0.1.0
197
- */
198
- async fetchLedgerNullable(sessionPda: PublicKey): Promise<MemoryLedgerData | null> {
199
- const [pda] = deriveLedger(sessionPda);
200
- return this.fetchAccountNullable<MemoryLedgerData>("memoryLedger", pda);
201
- }
202
-
203
- /**
204
- * @name fetchPage
205
- * @description Fetch a deserialized sealed `LedgerPage` account.
206
- * @param ledgerPda - The memory ledger PDA.
207
- * @param pageIndex - The zero-based page index.
208
- * @returns {Promise<LedgerPageData>} The ledger page data.
209
- * @throws Will throw if the page does not exist.
210
- * @since v0.1.0
211
- */
212
- async fetchPage(
213
- ledgerPda: PublicKey,
214
- pageIndex: number,
215
- ): Promise<LedgerPageData> {
216
- const [pda] = deriveLedgerPage(ledgerPda, pageIndex);
217
- return this.fetchAccount<LedgerPageData>("ledgerPage", pda);
218
- }
219
-
220
- /**
221
- * @name fetchPageNullable
222
- * @description Fetch a deserialized sealed `LedgerPage` account, or `null`
223
- * if it does not exist on-chain.
224
- * @param ledgerPda - The memory ledger PDA.
225
- * @param pageIndex - The zero-based page index.
226
- * @returns {Promise<LedgerPageData | null>} The page data or `null`.
227
- * @since v0.1.0
228
- */
229
- async fetchPageNullable(
230
- ledgerPda: PublicKey,
231
- pageIndex: number,
232
- ): Promise<LedgerPageData | null> {
233
- const [pda] = deriveLedgerPage(ledgerPda, pageIndex);
234
- return this.fetchAccountNullable<LedgerPageData>("ledgerPage", pda);
235
- }
236
-
237
- /**
238
- * @name decodeRingBuffer
239
- * @description Decode the ring buffer into individual entries.
240
- * Each entry is stored as `[u16 LE data_len][data bytes]`.
241
- * An entry with `data_len === 0` acts as the empty sentinel.
242
- * @param ring - Raw ring buffer data (byte array or Uint8Array).
243
- * @returns {Uint8Array[]} Array of decoded data entries.
244
- * @since v0.1.0
245
- */
246
- decodeRingBuffer(ring: number[] | Uint8Array): Uint8Array[] {
247
- const buf = Buffer.from(ring);
248
- const entries: Uint8Array[] = [];
249
- let offset = 0;
250
-
251
- while (offset + 2 <= buf.length) {
252
- const len = buf.readUInt16LE(offset);
253
- if (len === 0) break; // empty sentinel
254
- offset += 2;
255
- if (offset + len > buf.length) break;
256
- entries.push(new Uint8Array(buf.subarray(offset, offset + len)));
257
- offset += len;
258
- }
259
-
260
- return entries;
261
- }
262
- }