@oobe-protocol-labs/synapse-sap-sdk 0.6.3 → 0.8.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 (132) hide show
  1. package/dist/cjs/constants/seeds.js +9 -0
  2. package/dist/cjs/constants/seeds.js.map +1 -1
  3. package/dist/cjs/core/client.js +55 -0
  4. package/dist/cjs/core/client.js.map +1 -1
  5. package/dist/cjs/idl/synapse_agent_sap.json +8571 -4106
  6. package/dist/cjs/index.js +29 -3
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/modules/escrow-v2.js +220 -0
  9. package/dist/cjs/modules/escrow-v2.js.map +1 -0
  10. package/dist/cjs/modules/escrow.js +4 -0
  11. package/dist/cjs/modules/escrow.js.map +1 -1
  12. package/dist/cjs/modules/index.js +9 -1
  13. package/dist/cjs/modules/index.js.map +1 -1
  14. package/dist/cjs/modules/receipt.js +144 -0
  15. package/dist/cjs/modules/receipt.js.map +1 -0
  16. package/dist/cjs/modules/staking.js +94 -0
  17. package/dist/cjs/modules/staking.js.map +1 -0
  18. package/dist/cjs/modules/subscription.js +96 -0
  19. package/dist/cjs/modules/subscription.js.map +1 -0
  20. package/dist/cjs/pda/index.js +166 -1
  21. package/dist/cjs/pda/index.js.map +1 -1
  22. package/dist/cjs/registries/x402.js +88 -51
  23. package/dist/cjs/registries/x402.js.map +1 -1
  24. package/dist/cjs/types/enums.js +96 -1
  25. package/dist/cjs/types/enums.js.map +1 -1
  26. package/dist/cjs/types/index.js +6 -1
  27. package/dist/cjs/types/index.js.map +1 -1
  28. package/dist/cjs/types/instructions.js.map +1 -1
  29. package/dist/cjs/utils/escrow-validation.js +219 -0
  30. package/dist/cjs/utils/escrow-validation.js.map +1 -0
  31. package/dist/cjs/utils/index.js +12 -1
  32. package/dist/cjs/utils/index.js.map +1 -1
  33. package/dist/cjs/utils/merchant-validator.js +246 -0
  34. package/dist/cjs/utils/merchant-validator.js.map +1 -0
  35. package/dist/cjs/utils/x402-direct.js +231 -0
  36. package/dist/cjs/utils/x402-direct.js.map +1 -0
  37. package/dist/esm/constants/seeds.js +9 -0
  38. package/dist/esm/constants/seeds.js.map +1 -1
  39. package/dist/esm/core/client.js +55 -0
  40. package/dist/esm/core/client.js.map +1 -1
  41. package/dist/esm/idl/synapse_agent_sap.json +8571 -4106
  42. package/dist/esm/index.js +5 -3
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/modules/escrow-v2.js +216 -0
  45. package/dist/esm/modules/escrow-v2.js.map +1 -0
  46. package/dist/esm/modules/escrow.js +4 -0
  47. package/dist/esm/modules/escrow.js.map +1 -1
  48. package/dist/esm/modules/index.js +4 -0
  49. package/dist/esm/modules/index.js.map +1 -1
  50. package/dist/esm/modules/receipt.js +140 -0
  51. package/dist/esm/modules/receipt.js.map +1 -0
  52. package/dist/esm/modules/staking.js +90 -0
  53. package/dist/esm/modules/staking.js.map +1 -0
  54. package/dist/esm/modules/subscription.js +92 -0
  55. package/dist/esm/modules/subscription.js.map +1 -0
  56. package/dist/esm/pda/index.js +157 -0
  57. package/dist/esm/pda/index.js.map +1 -1
  58. package/dist/esm/registries/x402.js +89 -52
  59. package/dist/esm/registries/x402.js.map +1 -1
  60. package/dist/esm/types/enums.js +95 -0
  61. package/dist/esm/types/enums.js.map +1 -1
  62. package/dist/esm/types/index.js +1 -1
  63. package/dist/esm/types/index.js.map +1 -1
  64. package/dist/esm/types/instructions.js.map +1 -1
  65. package/dist/esm/utils/escrow-validation.js +212 -0
  66. package/dist/esm/utils/escrow-validation.js.map +1 -0
  67. package/dist/esm/utils/index.js +4 -0
  68. package/dist/esm/utils/index.js.map +1 -1
  69. package/dist/esm/utils/merchant-validator.js +241 -0
  70. package/dist/esm/utils/merchant-validator.js.map +1 -0
  71. package/dist/esm/utils/x402-direct.js +228 -0
  72. package/dist/esm/utils/x402-direct.js.map +1 -0
  73. package/dist/types/constants/seeds.d.ts +9 -0
  74. package/dist/types/constants/seeds.d.ts.map +1 -1
  75. package/dist/types/core/client.d.ts +43 -0
  76. package/dist/types/core/client.d.ts.map +1 -1
  77. package/dist/types/index.d.ts +6 -4
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/types/modules/escrow-v2.d.ts +58 -0
  80. package/dist/types/modules/escrow-v2.d.ts.map +1 -0
  81. package/dist/types/modules/escrow.d.ts +4 -0
  82. package/dist/types/modules/escrow.d.ts.map +1 -1
  83. package/dist/types/modules/index.d.ts +4 -0
  84. package/dist/types/modules/index.d.ts.map +1 -1
  85. package/dist/types/modules/receipt.d.ts +77 -0
  86. package/dist/types/modules/receipt.d.ts.map +1 -0
  87. package/dist/types/modules/staking.d.ts +32 -0
  88. package/dist/types/modules/staking.d.ts.map +1 -0
  89. package/dist/types/modules/subscription.d.ts +33 -0
  90. package/dist/types/modules/subscription.d.ts.map +1 -0
  91. package/dist/types/pda/index.d.ts +114 -0
  92. package/dist/types/pda/index.d.ts.map +1 -1
  93. package/dist/types/plugin/schemas.d.ts +2 -2
  94. package/dist/types/registries/x402.d.ts +14 -12
  95. package/dist/types/registries/x402.d.ts.map +1 -1
  96. package/dist/types/types/accounts.d.ts +201 -1
  97. package/dist/types/types/accounts.d.ts.map +1 -1
  98. package/dist/types/types/enums.d.ts +115 -0
  99. package/dist/types/types/enums.d.ts.map +1 -1
  100. package/dist/types/types/index.d.ts +4 -4
  101. package/dist/types/types/index.d.ts.map +1 -1
  102. package/dist/types/types/instructions.d.ts +34 -0
  103. package/dist/types/types/instructions.d.ts.map +1 -1
  104. package/dist/types/utils/escrow-validation.d.ts +145 -0
  105. package/dist/types/utils/escrow-validation.d.ts.map +1 -0
  106. package/dist/types/utils/index.d.ts +6 -0
  107. package/dist/types/utils/index.d.ts.map +1 -1
  108. package/dist/types/utils/merchant-validator.d.ts +176 -0
  109. package/dist/types/utils/merchant-validator.d.ts.map +1 -0
  110. package/dist/types/utils/x402-direct.d.ts +114 -0
  111. package/dist/types/utils/x402-direct.d.ts.map +1 -0
  112. package/package.json +2 -2
  113. package/src/constants/seeds.ts +9 -0
  114. package/src/core/client.ts +59 -0
  115. package/src/idl/synapse_agent_sap.json +8571 -4106
  116. package/src/index.ts +54 -0
  117. package/src/modules/escrow-v2.ts +375 -0
  118. package/src/modules/escrow.ts +4 -0
  119. package/src/modules/index.ts +4 -0
  120. package/src/modules/receipt.ts +207 -0
  121. package/src/modules/staking.ts +122 -0
  122. package/src/modules/subscription.ts +147 -0
  123. package/src/pda/index.ts +228 -0
  124. package/src/registries/x402.ts +108 -69
  125. package/src/types/accounts.ts +241 -1
  126. package/src/types/enums.ts +119 -0
  127. package/src/types/index.ts +20 -0
  128. package/src/types/instructions.ts +40 -0
  129. package/src/utils/escrow-validation.ts +301 -0
  130. package/src/utils/index.ts +28 -0
  131. package/src/utils/merchant-validator.ts +359 -0
  132. package/src/utils/x402-direct.ts +370 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @module utils/x402-direct
3
+ * @description Recognize x402 direct SPL token payments on an agent's ATA
4
+ * by scanning transaction history and filtering for x402 patterns.
5
+ *
6
+ * @category Utils
7
+ * @since v0.6.4
8
+ */
9
+ import { type Connection, PublicKey } from "@solana/web3.js";
10
+ /**
11
+ * @interface SettlementPayload
12
+ * @description Settlement metadata from the merchant's PAYMENT-RESPONSE.
13
+ * @category Utils
14
+ * @since v0.6.4
15
+ */
16
+ export interface SettlementPayload {
17
+ /** SHA-256 service hash. */
18
+ readonly serviceHash: string;
19
+ /** Resource identifier. */
20
+ readonly resource: string;
21
+ /** Agent wallet (base58). */
22
+ readonly agentWallet: string;
23
+ /** Depositor wallet (base58). */
24
+ readonly depositorWallet: string;
25
+ /** Amount in smallest unit. */
26
+ readonly amount: string;
27
+ /** Service timestamp. */
28
+ readonly timestamp: number;
29
+ }
30
+ /**
31
+ * @interface X402DirectPayment
32
+ * @description A recognized x402 direct SPL transfer on an agent's ATA.
33
+ * @category Utils
34
+ * @since v0.6.4
35
+ */
36
+ export interface X402DirectPayment {
37
+ /** Transaction signature. */
38
+ readonly signature: string;
39
+ /** Transfer amount (in smallest token unit). */
40
+ readonly amount: bigint;
41
+ /** Source ATA (payer). */
42
+ readonly payerAta: PublicKey;
43
+ /** Destination ATA (payTo / agent). */
44
+ readonly payeeAta: PublicKey;
45
+ /** Token mint used for transfer. */
46
+ readonly mint: PublicKey;
47
+ /** Memo data (if a Memo instruction was included). */
48
+ readonly memo: string | null;
49
+ /** Matched settlement payload (if server-side verification is available). */
50
+ readonly settlement: SettlementPayload | null;
51
+ /** Block time (unix seconds). */
52
+ readonly blockTime: number | null;
53
+ /** Slot number. */
54
+ readonly slot: number;
55
+ }
56
+ /**
57
+ * @interface GetX402DirectOptions
58
+ * @description Options for {@link getX402DirectPayments}.
59
+ * @category Utils
60
+ * @since v0.6.4
61
+ */
62
+ export interface GetX402DirectOptions {
63
+ /** Max signatures to scan (default: 100). */
64
+ readonly limit?: number;
65
+ /** Only return transfers from this specific payer. */
66
+ readonly filterPayer?: PublicKey;
67
+ /** Known settlements from server-side PAYMENT-RESPONSE logs.
68
+ * Used for deterministic hash matching. */
69
+ readonly knownSettlements?: SettlementPayload[];
70
+ /** Only include payments that match x402 memo prefix. Default: false. */
71
+ readonly requireMemo?: boolean;
72
+ /** Scan before this TX signature (pagination). */
73
+ readonly before?: string;
74
+ /** Scan after this TX signature (pagination). */
75
+ readonly until?: string;
76
+ }
77
+ /**
78
+ * @name getX402DirectPayments
79
+ * @description Scan an agent's ATA for x402 direct payments.
80
+ *
81
+ * Fetches recent transaction signatures for the given `payTo` ATA,
82
+ * inspects each transaction for SPL token transfers, and filters
83
+ * for x402 payment patterns (memo prefix, settlement hash match, etc.).
84
+ *
85
+ * @param connection - Solana RPC connection.
86
+ * @param payToAta - The agent's receiving ATA (e.g. USDC ATA of Syra).
87
+ * @param opts - Filter and pagination options.
88
+ * @returns Array of recognized x402 direct payments, newest first.
89
+ *
90
+ * @category Utils
91
+ * @since v0.6.4
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { getX402DirectPayments, findATA } from "@oobe-protocol-labs/synapse-sap-sdk";
96
+ *
97
+ * const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
98
+ * const payToAta = findATA(agentWallet, USDC_MINT);
99
+ *
100
+ * const payments = await getX402DirectPayments(connection, payToAta, {
101
+ * limit: 50,
102
+ * knownSettlements: savedSettlements, // from your API PAYMENT-RESPONSE logs
103
+ * });
104
+ *
105
+ * for (const p of payments) {
106
+ * console.log(`${p.signature}: ${p.amount} from ${p.payerAta.toBase58()}`);
107
+ * if (p.settlement) {
108
+ * console.log(` Matched settlement: ${p.settlement.serviceHash}`);
109
+ * }
110
+ * }
111
+ * ```
112
+ */
113
+ export declare function getX402DirectPayments(connection: Connection, payToAta: PublicKey, opts?: GetX402DirectOptions): Promise<X402DirectPayment[]>;
114
+ //# sourceMappingURL=x402-direct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-direct.d.ts","sourceRoot":"","sources":["../../../src/utils/x402-direct.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,KAAK,UAAU,EACf,SAAS,EAGV,MAAM,iBAAiB,CAAC;AAOzB;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6BAA6B;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,iCAAiC;IACjC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yBAAyB;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,QAAQ,CAAC,SAA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2
2
  "name": "@oobe-protocol-labs/synapse-sap-sdk",
3
- "version": "0.6.3",
4
- "description": "TypeScript SDK for the Synapse Agent Protocol (SAP v2) on Solana",
3
+ "version": "0.8.0",
4
+ "description": "TypeScript SDK for the Synapse Agent Protocol (SAP v2) on Solana Mainnet/Devnet",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",
@@ -47,6 +47,7 @@ export const SEEDS = {
47
47
  TOOL: "sap_tool",
48
48
  CHECKPOINT: "sap_checkpoint",
49
49
  ESCROW: "sap_escrow",
50
+ ESCROW_V2: "sap_escrow_v2",
50
51
  STATS: "sap_stats",
51
52
  TOOL_CATEGORY: "sap_tool_cat",
52
53
  ATTESTATION: "sap_attest",
@@ -54,6 +55,14 @@ export const SEEDS = {
54
55
  LEDGER_PAGE: "sap_page",
55
56
  BUFFER: "sap_buffer",
56
57
  DIGEST: "sap_digest",
58
+ PENDING: "sap_pending",
59
+ DISPUTE: "sap_dispute",
60
+ STAKE: "sap_stake",
61
+ SUBSCRIPTION: "sap_sub",
62
+ SHARD: "sap_shard",
63
+ INDEX_PAGE: "sap_idx_page",
64
+ /** @since v0.7.0 — Receipt batch merkle root PDA */
65
+ RECEIPT: "sap_receipt",
57
66
  } as const;
58
67
 
59
68
  /**
@@ -33,6 +33,10 @@ import { IndexingModule } from "../modules/indexing";
33
33
  import { ToolsModule } from "../modules/tools";
34
34
  import { VaultModule } from "../modules/vault";
35
35
  import { EscrowModule } from "../modules/escrow";
36
+ import { EscrowV2Module } from "../modules/escrow-v2";
37
+ import { ReceiptModule } from "../modules/receipt";
38
+ import { StakingModule } from "../modules/staking";
39
+ import { SubscriptionModule } from "../modules/subscription";
36
40
  import { AttestationModule } from "../modules/attestation";
37
41
  import { LedgerModule } from "../modules/ledger";
38
42
  import { EventParser } from "../events";
@@ -113,6 +117,10 @@ export class SapClient {
113
117
  #tools?: ToolsModule;
114
118
  #vault?: VaultModule;
115
119
  #escrow?: EscrowModule;
120
+ #escrowV2?: EscrowV2Module;
121
+ #receipt?: ReceiptModule;
122
+ #staking?: StakingModule;
123
+ #subscription?: SubscriptionModule;
116
124
  #attestation?: AttestationModule;
117
125
  #ledger?: LedgerModule;
118
126
  #events?: EventParser;
@@ -284,6 +292,57 @@ export class SapClient {
284
292
  return (this.#escrow ??= new EscrowModule(this.program));
285
293
  }
286
294
 
295
+ /**
296
+ * @name escrowV2
297
+ * @description V2 escrow settlement with dispute windows, co-signing,
298
+ * pending settlements, and migration from V1.
299
+ * @returns {EscrowV2Module} The lazily-instantiated `EscrowV2Module` singleton.
300
+ * @category Modules
301
+ * @since v0.7.0
302
+ * @see {@link EscrowV2Module}
303
+ */
304
+ get escrowV2(): EscrowV2Module {
305
+ return (this.#escrowV2 ??= new EscrowV2Module(this.program));
306
+ }
307
+
308
+ /**
309
+ * @name receipt
310
+ * @description Receipt batch inscriptions and automatic dispute resolution (v0.7).
311
+ * @returns {ReceiptModule} The lazily-instantiated `ReceiptModule` singleton.
312
+ * @category Modules
313
+ * @since v0.7.0
314
+ * @see {@link ReceiptModule}
315
+ */
316
+ get receipt(): ReceiptModule {
317
+ return (this.#receipt ??= new ReceiptModule(this.program));
318
+ }
319
+
320
+ /**
321
+ * @name staking
322
+ * @description Agent staking: init stake, deposit, request unstake,
323
+ * and complete unstake.
324
+ * @returns {StakingModule} The lazily-instantiated `StakingModule` singleton.
325
+ * @category Modules
326
+ * @since v0.7.0
327
+ * @see {@link StakingModule}
328
+ */
329
+ get staking(): StakingModule {
330
+ return (this.#staking ??= new StakingModule(this.program));
331
+ }
332
+
333
+ /**
334
+ * @name subscription
335
+ * @description Recurring subscriptions: create, fund, cancel, and close
336
+ * subscriber-agent subscription accounts.
337
+ * @returns {SubscriptionModule} The lazily-instantiated `SubscriptionModule` singleton.
338
+ * @category Modules
339
+ * @since v0.7.0
340
+ * @see {@link SubscriptionModule}
341
+ */
342
+ get subscription(): SubscriptionModule {
343
+ return (this.#subscription ??= new SubscriptionModule(this.program));
344
+ }
345
+
287
346
  /**
288
347
  * @name attestation
289
348
  * @description Web of trust: create, revoke, and close on-chain