@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,533 @@
1
+ /**
2
+ * @module vault
3
+ * @description Encrypted memory vault — init, session management, inscribe,
4
+ * delegate access, nonce rotation, and close operations.
5
+ *
6
+ * Vaults provide encrypted, session-scoped memory storage for agents,
7
+ * with support for epoch-based pagination and hot-wallet delegation.
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
+ deriveVault,
19
+ deriveSession,
20
+ deriveEpochPage,
21
+ deriveVaultDelegate,
22
+ deriveGlobalRegistry,
23
+ } from "../pda";
24
+ import type {
25
+ MemoryVaultData,
26
+ SessionLedgerData,
27
+ EpochPageData,
28
+ VaultDelegateData,
29
+ InscribeMemoryArgs,
30
+ CompactInscribeArgs,
31
+ } from "../types";
32
+
33
+ /**
34
+ * @name VaultModule
35
+ * @description Manages encrypted memory vaults for the Solana Agent Protocol.
36
+ * Provides methods to initialise vaults, open/close sessions, inscribe
37
+ * encrypted data, manage delegates (hot wallets), rotate nonces, and
38
+ * fetch all related account types.
39
+ *
40
+ * @category Modules
41
+ * @since v0.1.0
42
+ * @extends BaseModule
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const sap = new SapClient(provider);
47
+ * // Initialize a vault
48
+ * await sap.vault.initVault([...nonce]);
49
+ * // Open a session and inscribe data
50
+ * await sap.vault.openSession([...sessionHash]);
51
+ * ```
52
+ */
53
+ export class VaultModule extends BaseModule {
54
+ // ── PDA helpers ──────────────────────────────────────
55
+
56
+ /**
57
+ * @name deriveVault
58
+ * @description Derive the `MemoryVault` PDA for a given agent.
59
+ * @param agentPda - The agent account PDA.
60
+ * @returns A tuple of `[PublicKey, bump]` for the vault PDA.
61
+ * @see {@link deriveVault} from `pda/` module for the underlying derivation.
62
+ * @since v0.1.0
63
+ */
64
+ deriveVault(agentPda: PublicKey): readonly [PublicKey, number] {
65
+ return deriveVault(agentPda);
66
+ }
67
+
68
+ /**
69
+ * @name deriveSession
70
+ * @description Derive the `SessionLedger` PDA for a given vault and session hash.
71
+ * @param vaultPda - The memory vault PDA.
72
+ * @param sessionHash - A unique session identifier (32 bytes).
73
+ * @returns A tuple of `[PublicKey, bump]` for the session PDA.
74
+ * @see {@link deriveSession} from `pda/` module for the underlying derivation.
75
+ * @since v0.1.0
76
+ */
77
+ deriveSession(
78
+ vaultPda: PublicKey,
79
+ sessionHash: Uint8Array,
80
+ ): readonly [PublicKey, number] {
81
+ return deriveSession(vaultPda, sessionHash);
82
+ }
83
+
84
+ // ── Vault Lifecycle ──────────────────────────────────
85
+
86
+ /**
87
+ * @name initVault
88
+ * @description Initialize an encrypted memory vault for the caller's agent.
89
+ * Creates the `MemoryVault` PDA and sets the initial encryption nonce.
90
+ * @param vaultNonce - The initial encryption nonce (byte array).
91
+ * @returns {Promise<TransactionSignature>} The transaction signature.
92
+ * @since v0.1.0
93
+ */
94
+ async initVault(vaultNonce: number[]): Promise<TransactionSignature> {
95
+ const [agentPda] = deriveAgent(this.walletPubkey);
96
+ const [vaultPda] = deriveVault(agentPda);
97
+ const [globalPda] = deriveGlobalRegistry();
98
+
99
+ return this.methods
100
+ .initVault(vaultNonce)
101
+ .accounts({
102
+ wallet: this.walletPubkey,
103
+ agent: agentPda,
104
+ vault: vaultPda,
105
+ globalRegistry: globalPda,
106
+ systemProgram: SystemProgram.programId,
107
+ })
108
+ .rpc();
109
+ }
110
+
111
+ /**
112
+ * @name openSession
113
+ * @description Open a new session within a vault. Creates a `SessionLedger`
114
+ * PDA identified by the session hash.
115
+ * @param sessionHash - A unique session identifier (byte array).
116
+ * @returns {Promise<TransactionSignature>} The transaction signature.
117
+ * @since v0.1.0
118
+ */
119
+ async openSession(
120
+ sessionHash: number[],
121
+ ): Promise<TransactionSignature> {
122
+ const [agentPda] = deriveAgent(this.walletPubkey);
123
+ const [vaultPda] = deriveVault(agentPda);
124
+ const [sessionPda] = deriveSession(vaultPda, new Uint8Array(sessionHash));
125
+
126
+ return this.methods
127
+ .openSession(sessionHash)
128
+ .accounts({
129
+ wallet: this.walletPubkey,
130
+ vault: vaultPda,
131
+ session: sessionPda,
132
+ systemProgram: SystemProgram.programId,
133
+ })
134
+ .rpc();
135
+ }
136
+
137
+ /**
138
+ * @name inscribe
139
+ * @description Inscribe encrypted data into the transaction log.
140
+ * Account resolution is handled by Anchor via remaining accounts.
141
+ * @param args - Inscription parameters (sequence, encrypted data, nonce, content hash, fragments, compression, epoch).
142
+ * @returns {Promise<TransactionSignature>} The transaction signature.
143
+ * @since v0.1.0
144
+ */
145
+ async inscribe(args: InscribeMemoryArgs): Promise<TransactionSignature> {
146
+ // Session PDA is passed via remaining accounts resolution by Anchor
147
+ // For now, we build accounts manually
148
+
149
+ return this.methods
150
+ .inscribeMemory(
151
+ args.sequence,
152
+ args.encryptedData,
153
+ args.nonce,
154
+ args.contentHash,
155
+ args.totalFragments,
156
+ args.fragmentIndex,
157
+ args.compression,
158
+ args.epochIndex,
159
+ )
160
+ .rpc();
161
+ }
162
+
163
+ /**
164
+ * @name inscribeWithAccounts
165
+ * @description Full inscribe with explicit session and epoch page PDAs.
166
+ * Use this when you need manual control over account resolution.
167
+ * @param sessionPda - The session ledger PDA.
168
+ * @param epochPagePda - The epoch page PDA for the target epoch.
169
+ * @param vaultPda - The memory vault PDA.
170
+ * @param args - Inscription parameters.
171
+ * @returns {Promise<TransactionSignature>} The transaction signature.
172
+ * @since v0.1.0
173
+ */
174
+ async inscribeWithAccounts(
175
+ sessionPda: PublicKey,
176
+ epochPagePda: PublicKey,
177
+ vaultPda: PublicKey,
178
+ args: InscribeMemoryArgs,
179
+ ): Promise<TransactionSignature> {
180
+ return this.methods
181
+ .inscribeMemory(
182
+ args.sequence,
183
+ args.encryptedData,
184
+ args.nonce,
185
+ args.contentHash,
186
+ args.totalFragments,
187
+ args.fragmentIndex,
188
+ args.compression,
189
+ args.epochIndex,
190
+ )
191
+ .accounts({
192
+ wallet: this.walletPubkey,
193
+ vault: vaultPda,
194
+ session: sessionPda,
195
+ epochPage: epochPagePda,
196
+ systemProgram: SystemProgram.programId,
197
+ })
198
+ .rpc();
199
+ }
200
+
201
+ /**
202
+ * @name compactInscribe
203
+ * @description Simplified inscription (4 args vs 8) for single-fragment writes.
204
+ * @param sessionPda - The session ledger PDA.
205
+ * @param vaultPda - The memory vault PDA.
206
+ * @param args - Compact inscription parameters (sequence, encrypted data, nonce, content hash).
207
+ * @returns {Promise<TransactionSignature>} The transaction signature.
208
+ * @since v0.1.0
209
+ */
210
+ async compactInscribe(
211
+ sessionPda: PublicKey,
212
+ vaultPda: PublicKey,
213
+ args: CompactInscribeArgs,
214
+ ): Promise<TransactionSignature> {
215
+ return this.methods
216
+ .compactInscribe(
217
+ args.sequence,
218
+ args.encryptedData,
219
+ args.nonce,
220
+ args.contentHash,
221
+ )
222
+ .accounts({
223
+ wallet: this.walletPubkey,
224
+ vault: vaultPda,
225
+ session: sessionPda,
226
+ })
227
+ .rpc();
228
+ }
229
+
230
+ /**
231
+ * @name closeSession
232
+ * @description Close a session — no more inscriptions will be allowed.
233
+ * @param vaultPda - The memory vault PDA.
234
+ * @param sessionPda - The session ledger PDA to close.
235
+ * @returns {Promise<TransactionSignature>} The transaction signature.
236
+ * @since v0.1.0
237
+ */
238
+ async closeSession(
239
+ vaultPda: PublicKey,
240
+ sessionPda: PublicKey,
241
+ ): Promise<TransactionSignature> {
242
+ return this.methods
243
+ .closeSession()
244
+ .accounts({
245
+ wallet: this.walletPubkey,
246
+ vault: vaultPda,
247
+ session: sessionPda,
248
+ })
249
+ .rpc();
250
+ }
251
+
252
+ /**
253
+ * @name closeVault
254
+ * @description Close the `MemoryVault` PDA and reclaim rent to the owner wallet.
255
+ * @returns {Promise<TransactionSignature>} The transaction signature.
256
+ * @since v0.1.0
257
+ */
258
+ async closeVault(): Promise<TransactionSignature> {
259
+ const [agentPda] = deriveAgent(this.walletPubkey);
260
+ const [vaultPda] = deriveVault(agentPda);
261
+
262
+ return this.methods
263
+ .closeVault()
264
+ .accounts({
265
+ wallet: this.walletPubkey,
266
+ agent: agentPda,
267
+ vault: vaultPda,
268
+ })
269
+ .rpc();
270
+ }
271
+
272
+ /**
273
+ * @name closeSessionPda
274
+ * @description Close a `SessionLedger` PDA (session must be closed first).
275
+ * Reclaims rent to the owner wallet.
276
+ * @param vaultPda - The memory vault PDA.
277
+ * @param sessionPda - The session ledger PDA to close.
278
+ * @returns {Promise<TransactionSignature>} The transaction signature.
279
+ * @since v0.1.0
280
+ */
281
+ async closeSessionPda(
282
+ vaultPda: PublicKey,
283
+ sessionPda: PublicKey,
284
+ ): Promise<TransactionSignature> {
285
+ return this.methods
286
+ .closeSessionPda()
287
+ .accounts({
288
+ wallet: this.walletPubkey,
289
+ vault: vaultPda,
290
+ session: sessionPda,
291
+ })
292
+ .rpc();
293
+ }
294
+
295
+ /**
296
+ * @name closeEpochPage
297
+ * @description Close an `EpochPage` PDA and reclaim rent.
298
+ * @param sessionPda - The session ledger PDA that owns this epoch page.
299
+ * @param epochIndex - The zero-based epoch index.
300
+ * @returns {Promise<TransactionSignature>} The transaction signature.
301
+ * @since v0.1.0
302
+ */
303
+ async closeEpochPage(
304
+ sessionPda: PublicKey,
305
+ epochIndex: number,
306
+ ): Promise<TransactionSignature> {
307
+ const [epochPda] = deriveEpochPage(sessionPda, epochIndex);
308
+
309
+ return this.methods
310
+ .closeEpochPage(epochIndex)
311
+ .accounts({
312
+ wallet: this.walletPubkey,
313
+ session: sessionPda,
314
+ epochPage: epochPda,
315
+ })
316
+ .rpc();
317
+ }
318
+
319
+ /**
320
+ * @name rotateNonce
321
+ * @description Rotate the vault encryption nonce. All future inscriptions
322
+ * will use the new nonce.
323
+ * @param newNonce - The replacement nonce (byte array).
324
+ * @returns {Promise<TransactionSignature>} The transaction signature.
325
+ * @since v0.1.0
326
+ */
327
+ async rotateNonce(
328
+ newNonce: number[],
329
+ ): Promise<TransactionSignature> {
330
+ const [agentPda] = deriveAgent(this.walletPubkey);
331
+ const [vaultPda] = deriveVault(agentPda);
332
+
333
+ return this.methods
334
+ .rotateVaultNonce(newNonce)
335
+ .accounts({
336
+ wallet: this.walletPubkey,
337
+ vault: vaultPda,
338
+ })
339
+ .rpc();
340
+ }
341
+
342
+ // ── Delegation ───────────────────────────────────────
343
+
344
+ /**
345
+ * @name addDelegate
346
+ * @description Authorize a delegate (hot wallet) for vault operations.
347
+ * Creates a `VaultDelegate` PDA with the specified permissions and expiry.
348
+ * @param delegatePubkey - The public key of the delegate wallet to authorize.
349
+ * @param permissions - Bitmask of permitted operations.
350
+ * @param expiresAt - Unix timestamp when delegation expires.
351
+ * @returns {Promise<TransactionSignature>} The transaction signature.
352
+ * @since v0.1.0
353
+ */
354
+ async addDelegate(
355
+ delegatePubkey: PublicKey,
356
+ permissions: number,
357
+ expiresAt: number | bigint,
358
+ ): Promise<TransactionSignature> {
359
+ const [agentPda] = deriveAgent(this.walletPubkey);
360
+ const [vaultPda] = deriveVault(agentPda);
361
+ const [delegatePda] = deriveVaultDelegate(vaultPda, delegatePubkey);
362
+
363
+ return this.methods
364
+ .addVaultDelegate(permissions, this.bn(expiresAt))
365
+ .accounts({
366
+ wallet: this.walletPubkey,
367
+ vault: vaultPda,
368
+ delegate: delegatePda,
369
+ delegateWallet: delegatePubkey,
370
+ systemProgram: SystemProgram.programId,
371
+ })
372
+ .rpc();
373
+ }
374
+
375
+ /**
376
+ * @name revokeDelegate
377
+ * @description Revoke a delegate’s authorization, closing their `VaultDelegate` PDA.
378
+ * @param delegatePubkey - The public key of the delegate wallet to revoke.
379
+ * @returns {Promise<TransactionSignature>} The transaction signature.
380
+ * @since v0.1.0
381
+ */
382
+ async revokeDelegate(
383
+ delegatePubkey: PublicKey,
384
+ ): Promise<TransactionSignature> {
385
+ const [agentPda] = deriveAgent(this.walletPubkey);
386
+ const [vaultPda] = deriveVault(agentPda);
387
+ const [delegatePda] = deriveVaultDelegate(vaultPda, delegatePubkey);
388
+
389
+ return this.methods
390
+ .revokeVaultDelegate()
391
+ .accounts({
392
+ wallet: this.walletPubkey,
393
+ vault: vaultPda,
394
+ delegate: delegatePda,
395
+ })
396
+ .rpc();
397
+ }
398
+
399
+ /**
400
+ * @name inscribeDelegated
401
+ * @description Inscribe data via an authorized delegate (hot wallet).
402
+ * The transaction is signed by the delegate instead of the vault owner.
403
+ * @param delegateWallet - The delegate wallet public key.
404
+ * @param vaultPda - The memory vault PDA.
405
+ * @param sessionPda - The session ledger PDA.
406
+ * @param epochPagePda - The epoch page PDA.
407
+ * @param args - Inscription parameters.
408
+ * @returns {Promise<TransactionSignature>} The transaction signature.
409
+ * @since v0.1.0
410
+ */
411
+ async inscribeDelegated(
412
+ delegateWallet: PublicKey,
413
+ vaultPda: PublicKey,
414
+ sessionPda: PublicKey,
415
+ epochPagePda: PublicKey,
416
+ args: InscribeMemoryArgs,
417
+ ): Promise<TransactionSignature> {
418
+ const [delegatePda] = deriveVaultDelegate(vaultPda, delegateWallet);
419
+
420
+ return this.methods
421
+ .inscribeMemoryDelegated(
422
+ args.sequence,
423
+ args.encryptedData,
424
+ args.nonce,
425
+ args.contentHash,
426
+ args.totalFragments,
427
+ args.fragmentIndex,
428
+ args.compression,
429
+ args.epochIndex,
430
+ )
431
+ .accounts({
432
+ delegateWallet,
433
+ vault: vaultPda,
434
+ delegateAuth: delegatePda,
435
+ session: sessionPda,
436
+ epochPage: epochPagePda,
437
+ systemProgram: SystemProgram.programId,
438
+ })
439
+ .rpc();
440
+ }
441
+
442
+ // ── Fetchers ─────────────────────────────────────────
443
+
444
+ /**
445
+ * @name fetchVault
446
+ * @description Fetch a deserialized `MemoryVault` account.
447
+ * @param agentPda - The agent account PDA.
448
+ * @returns {Promise<MemoryVaultData>} The vault account data.
449
+ * @throws Will throw if the vault account does not exist.
450
+ * @since v0.1.0
451
+ */
452
+ async fetchVault(agentPda: PublicKey): Promise<MemoryVaultData> {
453
+ const [pda] = deriveVault(agentPda);
454
+ return this.fetchAccount<MemoryVaultData>("memoryVault", pda);
455
+ }
456
+
457
+ /**
458
+ * @name fetchVaultNullable
459
+ * @description Fetch a deserialized `MemoryVault` account, or `null`
460
+ * if it does not exist on-chain.
461
+ * @param agentPda - The agent account PDA.
462
+ * @returns {Promise<MemoryVaultData | null>} The vault data or `null`.
463
+ * @since v0.1.0
464
+ */
465
+ async fetchVaultNullable(agentPda: PublicKey): Promise<MemoryVaultData | null> {
466
+ const [pda] = deriveVault(agentPda);
467
+ return this.fetchAccountNullable<MemoryVaultData>("memoryVault", pda);
468
+ }
469
+
470
+ /**
471
+ * @name fetchSession
472
+ * @description Fetch a deserialized `SessionLedger` account by vault and session hash.
473
+ * @param vaultPda - The memory vault PDA.
474
+ * @param sessionHash - The session identifier used during creation.
475
+ * @returns {Promise<SessionLedgerData>} The session ledger data.
476
+ * @throws Will throw if the session does not exist.
477
+ * @since v0.1.0
478
+ */
479
+ async fetchSession(
480
+ vaultPda: PublicKey,
481
+ sessionHash: Uint8Array,
482
+ ): Promise<SessionLedgerData> {
483
+ const [pda] = deriveSession(vaultPda, sessionHash);
484
+ return this.fetchAccount<SessionLedgerData>("sessionLedger", pda);
485
+ }
486
+
487
+ /**
488
+ * @name fetchSessionByPda
489
+ * @description Fetch a deserialized `SessionLedger` account by its PDA directly,
490
+ * bypassing PDA derivation.
491
+ * @param sessionPda - The session ledger PDA.
492
+ * @returns {Promise<SessionLedgerData>} The session ledger data.
493
+ * @throws Will throw if the session does not exist.
494
+ * @since v0.1.0
495
+ */
496
+ async fetchSessionByPda(sessionPda: PublicKey): Promise<SessionLedgerData> {
497
+ return this.fetchAccount<SessionLedgerData>("sessionLedger", sessionPda);
498
+ }
499
+
500
+ /**
501
+ * @name fetchEpochPage
502
+ * @description Fetch a deserialized `EpochPage` account.
503
+ * @param sessionPda - The session ledger PDA.
504
+ * @param epochIndex - The zero-based epoch index.
505
+ * @returns {Promise<EpochPageData>} The epoch page data.
506
+ * @throws Will throw if the epoch page does not exist.
507
+ * @since v0.1.0
508
+ */
509
+ async fetchEpochPage(
510
+ sessionPda: PublicKey,
511
+ epochIndex: number,
512
+ ): Promise<EpochPageData> {
513
+ const [pda] = deriveEpochPage(sessionPda, epochIndex);
514
+ return this.fetchAccount<EpochPageData>("epochPage", pda);
515
+ }
516
+
517
+ /**
518
+ * @name fetchDelegate
519
+ * @description Fetch a deserialized `VaultDelegate` account.
520
+ * @param vaultPda - The memory vault PDA.
521
+ * @param delegatePubkey - The delegate wallet public key.
522
+ * @returns {Promise<VaultDelegateData>} The delegate account data.
523
+ * @throws Will throw if the delegate does not exist.
524
+ * @since v0.1.0
525
+ */
526
+ async fetchDelegate(
527
+ vaultPda: PublicKey,
528
+ delegatePubkey: PublicKey,
529
+ ): Promise<VaultDelegateData> {
530
+ const [pda] = deriveVaultDelegate(vaultPda, delegatePubkey);
531
+ return this.fetchAccount<VaultDelegateData>("vaultDelegate", pda);
532
+ }
533
+ }