@oobe-protocol-labs/synapse-sap-sdk 0.8.0 → 0.9.1

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.
@@ -0,0 +1,228 @@
1
+ /**
2
+ * @module registries/metaplex-bridge
3
+ * @description Bridge between Synapse Agent Protocol (SAP) and Metaplex
4
+ * Core's `AgentIdentity` external plugin adapter (mpl-core ≥ 1.9.0).
5
+ *
6
+ * ## Why this design (verified against mpl-core PR #258, v1.9.0)
7
+ *
8
+ * The MPL Core `AgentIdentity` plugin has exactly one field:
9
+ *
10
+ * ```ts
11
+ * type AgentIdentity = { uri: string };
12
+ * ```
13
+ *
14
+ * The URI must point to an **EIP-8004** agent registration JSON. There is
15
+ * no on-chain executive list, no `addExecutive` / `delegateExecutionV1`
16
+ * instruction. Capabilities, services, executives, and reputation live
17
+ * off-chain in that JSON. The plugin only hooks the `Execute` lifecycle
18
+ * event, allowing the URI's authority to gate execution.
19
+ *
20
+ * The most efficient SAP × MPL integration therefore is:
21
+ *
22
+ * 1. SAP serves a **live EIP-8004 JSON** at a deterministic URL derived
23
+ * from the SAP `AgentAccount` PDA (e.g.
24
+ * `https://explorer.oobeprotocol.ai/agents/<sapAgentPda>/eip-8004.json`).
25
+ * 2. The MPL Core asset attaches an `AgentIdentity` adapter whose `uri`
26
+ * points to that URL.
27
+ * 3. Every SAP write (capability change, vault delegate add/revoke, x402
28
+ * tier update) is reflected in the JSON automatically — **no second
29
+ * transaction required, on either chain or for any wallet.**
30
+ *
31
+ * One SAP transaction = both protocols updated. That is the efficiency
32
+ * win that motivated the Phase 1 redesign on 2026-04-22.
33
+ *
34
+ * @category Registries
35
+ * @since v0.9.0
36
+ * @see https://github.com/metaplex-foundation/mpl-core/pull/258
37
+ * @see https://eips.ethereum.org/EIPS/eip-8004
38
+ */
39
+ import { PublicKey, type TransactionInstruction } from "@solana/web3.js";
40
+ import type { SapProgram } from "../modules/base";
41
+ import type { AgentAccountData, AgentStatsData } from "../types";
42
+ /**
43
+ * @interface Eip8004Service
44
+ * @description One service entry in an EIP-8004 registration document.
45
+ * @category Registries
46
+ * @since v0.9.0
47
+ */
48
+ export interface Eip8004Service {
49
+ readonly id: string;
50
+ readonly type: string;
51
+ readonly url: string;
52
+ readonly priceLamports?: string;
53
+ }
54
+ /**
55
+ * @interface Eip8004Registration
56
+ * @description Subset of an EIP-8004 registration document used by the
57
+ * bridge. Hosts may include additional fields; they are passed through
58
+ * via `extra`.
59
+ * @category Registries
60
+ * @since v0.9.0
61
+ */
62
+ export interface Eip8004Registration {
63
+ readonly version: string;
64
+ readonly name: string;
65
+ readonly description?: string;
66
+ readonly synapseAgent: string;
67
+ readonly authority: string;
68
+ readonly capabilities: readonly string[];
69
+ readonly services: readonly Eip8004Service[];
70
+ readonly executives: readonly {
71
+ wallet: string;
72
+ expiresAt: string | null;
73
+ }[];
74
+ readonly updatedAt: string;
75
+ readonly extra?: Record<string, unknown>;
76
+ }
77
+ /**
78
+ * @interface AttachAgentIdentityOpts
79
+ * @description Parameters for {@link MetaplexBridge.buildAttachAgentIdentityIx}.
80
+ * @category Registries
81
+ * @since v0.9.0
82
+ */
83
+ export interface AttachAgentIdentityOpts {
84
+ readonly asset: PublicKey;
85
+ readonly authority: PublicKey;
86
+ readonly payer?: PublicKey;
87
+ readonly sapAgentOwner: PublicKey;
88
+ readonly registrationBaseUrl: string;
89
+ readonly rpcUrl: string;
90
+ }
91
+ /**
92
+ * @interface UpdateAgentIdentityUriOpts
93
+ * @description Parameters for {@link MetaplexBridge.buildUpdateAgentIdentityUriIx}.
94
+ * @category Registries
95
+ * @since v0.9.0
96
+ */
97
+ export interface UpdateAgentIdentityUriOpts {
98
+ readonly asset: PublicKey;
99
+ readonly authority: PublicKey;
100
+ readonly payer?: PublicKey;
101
+ readonly newUri: string;
102
+ readonly rpcUrl: string;
103
+ }
104
+ /**
105
+ * @interface MplAgentSnapshot
106
+ * @description Subset of an MPL Core Asset relevant to the bridge.
107
+ * @category Registries
108
+ * @since v0.9.0
109
+ */
110
+ export interface MplAgentSnapshot {
111
+ readonly asset: PublicKey;
112
+ readonly owner: PublicKey;
113
+ readonly name: string | null;
114
+ readonly agentIdentityUri: string | null;
115
+ readonly registration: Eip8004Registration | null;
116
+ }
117
+ /**
118
+ * @interface UnifiedProfile
119
+ * @description Merged read-only profile combining SAP identity and an
120
+ * (optional) MPL Core asset side. The `linked` flag is `true` when the
121
+ * MPL asset's `AgentIdentity.uri` references the SAP agent PDA both in
122
+ * the URL path and in the `synapseAgent` JSON field.
123
+ * @category Registries
124
+ * @since v0.9.0
125
+ */
126
+ export interface UnifiedProfile {
127
+ readonly sap: {
128
+ readonly pda: PublicKey;
129
+ readonly identity: AgentAccountData | null;
130
+ readonly stats: AgentStatsData | null;
131
+ };
132
+ readonly mpl: MplAgentSnapshot | null;
133
+ readonly linked: boolean;
134
+ }
135
+ /**
136
+ * @name MetaplexBridge
137
+ * @description Read-side merger and write-side instruction composer for
138
+ * SAP × Metaplex Core `AgentIdentity` integration.
139
+ *
140
+ * Linking is **single-transaction**: the MPL `addExternalPluginAdapterV1`
141
+ * instruction sets a URI that points at SAP's live registration host.
142
+ * Subsequent SAP state changes propagate automatically — no extra MPL
143
+ * transaction required.
144
+ *
145
+ * @category Registries
146
+ * @since v0.9.0
147
+ */
148
+ export declare class MetaplexBridge {
149
+ private readonly program;
150
+ constructor(program: SapProgram);
151
+ /**
152
+ * @name deriveRegistrationUrl
153
+ * @description Compute the deterministic EIP-8004 registration URL for
154
+ * a SAP agent. Hosts MUST serve the JSON at exactly this path so that
155
+ * {@link MetaplexBridge.verifyLink} validates without external config.
156
+ *
157
+ * @since v0.9.0
158
+ */
159
+ deriveRegistrationUrl(sapAgentPda: PublicKey, baseUrl: string): string;
160
+ /**
161
+ * @name buildEip8004Registration
162
+ * @description Build a canonical EIP-8004 JSON document for a SAP agent.
163
+ * Designed to be called server-side by a registry host.
164
+ *
165
+ * @since v0.9.0
166
+ */
167
+ buildEip8004Registration(args: {
168
+ sapAgentOwner: PublicKey;
169
+ services?: readonly Eip8004Service[];
170
+ extra?: Record<string, unknown>;
171
+ }): Promise<Eip8004Registration>;
172
+ /**
173
+ * @name buildAttachAgentIdentityIx
174
+ * @description Build the MPL Core `addExternalPluginAdapterV1`
175
+ * `TransactionInstruction` that attaches an `AgentIdentity` plugin
176
+ * pointing at SAP's live EIP-8004 registration URL.
177
+ *
178
+ * @since v0.9.0
179
+ */
180
+ buildAttachAgentIdentityIx(opts: AttachAgentIdentityOpts): Promise<TransactionInstruction>;
181
+ /**
182
+ * @name buildUpdateAgentIdentityUriIx
183
+ * @description Build the MPL Core `updateExternalPluginAdapterV1`
184
+ * instruction that re-points an existing `AgentIdentity` plugin.
185
+ *
186
+ * @since v0.9.0
187
+ */
188
+ buildUpdateAgentIdentityUriIx(opts: UpdateAgentIdentityUriOpts): Promise<TransactionInstruction>;
189
+ /**
190
+ * @name getUnifiedProfile
191
+ * @description Fetch a merged view of an agent across SAP and Metaplex.
192
+ * Provide `wallet` (SAP-first) or `asset` (MPL-first), or both.
193
+ *
194
+ * @since v0.9.0
195
+ */
196
+ getUnifiedProfile(input: {
197
+ wallet?: PublicKey;
198
+ asset?: PublicKey;
199
+ rpcUrl: string;
200
+ }): Promise<UnifiedProfile>;
201
+ /**
202
+ * @name verifyLink
203
+ * @description Verify the bidirectional link between an MPL Core asset
204
+ * and a SAP agent. Returns `true` only when both URL and JSON sides
205
+ * reference the SAP agent PDA.
206
+ *
207
+ * @since v0.9.0
208
+ */
209
+ verifyLink(args: {
210
+ asset: PublicKey;
211
+ sapAgentPda: PublicKey;
212
+ rpcUrl: string;
213
+ }): Promise<boolean>;
214
+ private get accounts();
215
+ private fetchAgentNullable;
216
+ private fetchStatsNullable;
217
+ private fetchActiveVaultDelegates;
218
+ private fetchMplSnapshot;
219
+ private extractAgentIdentityUri;
220
+ private fetchEip8004Safe;
221
+ private buildAddExternalPluginIx;
222
+ private firstWeb3Ix;
223
+ private umiIxToWeb3;
224
+ private detectLink;
225
+ private readString;
226
+ private readCapabilities;
227
+ }
228
+ //# sourceMappingURL=metaplex-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaplex-bridge.d.ts","sourceRoot":"","sources":["../../../src/registries/metaplex-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AAYzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EAGf,MAAM,UAAU,CAAC;AAoBlB;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE,SAAS;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,EAAE,CAAC;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,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;YAkChB,wBAAwB;YAmCxB,WAAW;IAYzB,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,gBAAgB;CAIzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oobe-protocol-labs/synapse-sap-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
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",
@@ -97,6 +97,11 @@
97
97
  "require": "./dist/cjs/registries/builder.js",
98
98
  "types": "./dist/types/registries/builder.d.ts"
99
99
  },
100
+ "./registries/metaplex-bridge": {
101
+ "import": "./dist/esm/registries/metaplex-bridge.js",
102
+ "require": "./dist/cjs/registries/metaplex-bridge.js",
103
+ "types": "./dist/types/registries/metaplex-bridge.d.ts"
104
+ },
100
105
  "./idl": {
101
106
  "import": "./dist/esm/idl/index.js",
102
107
  "require": "./dist/cjs/idl/index.js",
@@ -156,19 +161,25 @@
156
161
  "typecheck": "tsc --noEmit"
157
162
  },
158
163
  "dependencies": {
159
- "@coral-xyz/anchor": "^0.32.1",
160
- "@solana/web3.js": "^1.98.0"
164
+ "@coral-xyz/anchor": ">=0.30.0",
165
+ "@solana/web3.js": ">=1.90.0"
161
166
  },
162
167
  "devDependencies": {
168
+ "@metaplex-foundation/mpl-core": "^1.10.0",
169
+ "@metaplex-foundation/umi": "^1.5.0",
170
+ "@metaplex-foundation/umi-bundle-defaults": "^1.5.1",
163
171
  "typescript": "^5.7.3",
164
172
  "zod": "^4.3.6"
165
173
  },
166
174
  "peerDependencies": {
167
175
  "@coral-xyz/anchor": ">=0.30.0",
176
+ "@metaplex-foundation/mpl-core": ">=1.9.0",
177
+ "@metaplex-foundation/umi": ">=0.9.0",
178
+ "@metaplex-foundation/umi-bundle-defaults": ">=0.9.0",
168
179
  "@solana/web3.js": ">=1.90.0",
169
180
  "@triton-one/yellowstone-grpc": ">=1.0.0",
170
- "zod": ">=3.20.0",
171
- "pg": ">=8.0.0"
181
+ "pg": ">=8.0.0",
182
+ "zod": ">=3.20.0"
172
183
  },
173
184
  "peerDependenciesMeta": {
174
185
  "zod": {
@@ -179,6 +190,15 @@
179
190
  },
180
191
  "@triton-one/yellowstone-grpc": {
181
192
  "optional": true
193
+ },
194
+ "@metaplex-foundation/mpl-core": {
195
+ "optional": true
196
+ },
197
+ "@metaplex-foundation/umi": {
198
+ "optional": true
199
+ },
200
+ "@metaplex-foundation/umi-bundle-defaults": {
201
+ "optional": true
182
202
  }
183
203
  },
184
204
  "engines": {
@@ -45,6 +45,7 @@ import { DiscoveryRegistry } from "../registries/discovery";
45
45
  import { X402Registry } from "../registries/x402";
46
46
  import { SessionManager } from "../registries/session";
47
47
  import { AgentBuilder } from "../registries/builder";
48
+ import { MetaplexBridge } from "../registries/metaplex-bridge";
48
49
 
49
50
  // IDL is embedded inside the SDK — no external workspace dependency
50
51
  import idl from "../idl/synapse_agent_sap.json";
@@ -132,6 +133,7 @@ export class SapClient {
132
133
  #discovery?: DiscoveryRegistry;
133
134
  #x402?: X402Registry;
134
135
  #session?: SessionManager;
136
+ #metaplex?: MetaplexBridge;
135
137
 
136
138
  private constructor(program: SapProgram) {
137
139
  this.program = program;
@@ -497,4 +499,34 @@ export class SapClient {
497
499
  get builder(): AgentBuilder {
498
500
  return new AgentBuilder(this.program);
499
501
  }
502
+
503
+ /**
504
+ * @name metaplex
505
+ * @description Bridge between SAP and the Metaplex Agent Kit
506
+ * (MPL Core Asset + AgentIdentity plugin). Read-side merges SAP
507
+ * `AgentAccount` with MPL Core asset metadata; write-side composes
508
+ * atomic dual-protocol delegation instructions.
509
+ *
510
+ * Requires the optional peer dependencies
511
+ * `@metaplex-foundation/mpl-core` and
512
+ * `@metaplex-foundation/umi-bundle-defaults`. They are imported lazily
513
+ * the first time a method that needs them is called, so consumers that
514
+ * do not use the bridge incur zero overhead.
515
+ *
516
+ * @returns {MetaplexBridge} The lazily-instantiated `MetaplexBridge` singleton.
517
+ * @category Registries
518
+ * @since v0.9.0
519
+ * @see {@link MetaplexBridge}
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const profile = await client.metaplex.getUnifiedProfile({
524
+ * wallet: agentWallet,
525
+ * rpcUrl: "https://api.mainnet-beta.solana.com",
526
+ * });
527
+ * ```
528
+ */
529
+ get metaplex(): MetaplexBridge {
530
+ return (this.#metaplex ??= new MetaplexBridge(this.program));
531
+ }
500
532
  }
package/src/index.ts CHANGED
@@ -373,6 +373,7 @@ export {
373
373
  X402Registry,
374
374
  SessionManager,
375
375
  AgentBuilder,
376
+ MetaplexBridge,
376
377
  } from "./registries/index";
377
378
  export type {
378
379
  DiscoveredAgent,
@@ -398,4 +399,10 @@ export type {
398
399
  ToolInput,
399
400
  RegisterResult,
400
401
  RegisterWithToolsResult,
402
+ UnifiedProfile,
403
+ MplAgentSnapshot,
404
+ Eip8004Registration,
405
+ Eip8004Service,
406
+ AttachAgentIdentityOpts,
407
+ UpdateAgentIdentityUriOpts,
401
408
  } from "./registries/index";
@@ -76,3 +76,13 @@ export type {
76
76
  RegisterResult,
77
77
  RegisterWithToolsResult,
78
78
  } from "./builder";
79
+
80
+ export { MetaplexBridge } from "./metaplex-bridge";
81
+ export type {
82
+ UnifiedProfile,
83
+ MplAgentSnapshot,
84
+ Eip8004Registration,
85
+ Eip8004Service,
86
+ AttachAgentIdentityOpts,
87
+ UpdateAgentIdentityUriOpts,
88
+ } from "./metaplex-bridge";