@oobe-protocol-labs/synapse-sap-sdk 0.9.1 → 0.9.3
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.
- package/dist/cjs/registries/metaplex-bridge.js +302 -5
- package/dist/cjs/registries/metaplex-bridge.js.map +1 -1
- package/dist/esm/registries/metaplex-bridge.js +302 -5
- package/dist/esm/registries/metaplex-bridge.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/registries/index.d.ts +1 -1
- package/dist/types/registries/index.d.ts.map +1 -1
- package/dist/types/registries/metaplex-bridge.d.ts +261 -1
- package/dist/types/registries/metaplex-bridge.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/registries/index.ts +9 -0
- package/src/registries/metaplex-bridge.ts +558 -4
|
@@ -175,6 +175,190 @@ export interface UnifiedProfile {
|
|
|
175
175
|
readonly linked: boolean;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
* @interface AgentIdentifierResolution
|
|
180
|
+
* @description Resolution result for an agent identifier that may be either
|
|
181
|
+
* an SAP owner wallet or an MPL Core asset address.
|
|
182
|
+
*
|
|
183
|
+
* - `kind = "wallet"`: input is treated as owner wallet.
|
|
184
|
+
* - `kind = "core-asset"`: input is an MPL Core asset; `wallet` is asset owner.
|
|
185
|
+
* - `kind = "unknown"`: input is invalid or cannot be resolved.
|
|
186
|
+
*
|
|
187
|
+
* @category Registries
|
|
188
|
+
* @since v0.9.2
|
|
189
|
+
*/
|
|
190
|
+
export interface AgentIdentifierResolution {
|
|
191
|
+
readonly input: string;
|
|
192
|
+
readonly kind: "wallet" | "core-asset" | "unknown";
|
|
193
|
+
readonly wallet: PublicKey | null;
|
|
194
|
+
readonly sapAgentPda: PublicKey | null;
|
|
195
|
+
readonly asset: PublicKey | null;
|
|
196
|
+
readonly hasSapAgent: boolean;
|
|
197
|
+
readonly error: string | null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @interface RegisterAgentInput
|
|
202
|
+
* @description Minimal input set the bridge needs to construct a SAP
|
|
203
|
+
* `registerAgent` instruction. Exposed independently so the bridge does not
|
|
204
|
+
* import `RegisterAgentArgs` from another module (keeping the public surface flat).
|
|
205
|
+
*
|
|
206
|
+
* @category Registries
|
|
207
|
+
* @since v0.9.3
|
|
208
|
+
*/
|
|
209
|
+
export interface RegisterAgentInput {
|
|
210
|
+
readonly name: string;
|
|
211
|
+
readonly description: string;
|
|
212
|
+
readonly capabilities: readonly Capability[];
|
|
213
|
+
readonly pricing: unknown;
|
|
214
|
+
readonly protocols: readonly number[];
|
|
215
|
+
readonly agentId?: string | null;
|
|
216
|
+
readonly agentUri?: string | null;
|
|
217
|
+
readonly x402Endpoint?: string | null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @interface MintAttachOpts
|
|
222
|
+
* @description Inputs for {@link MetaplexBridge.buildMintAndAttachIxs}.
|
|
223
|
+
* Builds: MPL Core `create` (mint a fresh asset) + `addExternalPluginAdapterV1`
|
|
224
|
+
* (attach AgentIdentity → SAP EIP-8004 URL) — produced as two web3.js
|
|
225
|
+
* instructions in deterministic order.
|
|
226
|
+
*
|
|
227
|
+
* The caller MUST sign with the returned `assetSigner` in addition to the
|
|
228
|
+
* wallet authority, since Core mint requires the asset keypair as a signer.
|
|
229
|
+
*
|
|
230
|
+
* @category Registries
|
|
231
|
+
* @since v0.9.3
|
|
232
|
+
*/
|
|
233
|
+
export interface MintAttachOpts {
|
|
234
|
+
readonly sapAgentOwner: PublicKey;
|
|
235
|
+
readonly authority: PublicKey;
|
|
236
|
+
readonly payer?: PublicKey;
|
|
237
|
+
readonly owner?: PublicKey;
|
|
238
|
+
readonly name: string;
|
|
239
|
+
readonly metadataUri: string;
|
|
240
|
+
readonly registrationBaseUrl: string;
|
|
241
|
+
readonly rpcUrl: string;
|
|
242
|
+
readonly collection?: PublicKey;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @interface MintAttachResult
|
|
247
|
+
* @description Return shape of {@link MetaplexBridge.buildMintAndAttachIxs}
|
|
248
|
+
* and the mint half of {@link MetaplexBridge.buildRegisterBothIxs}.
|
|
249
|
+
*
|
|
250
|
+
* `assetSecretKey` is the freshly generated asset keypair's secret. The
|
|
251
|
+
* caller is responsible for safe handling: server-side flows should
|
|
252
|
+
* partial-sign the assembled transaction with it and then discard.
|
|
253
|
+
*
|
|
254
|
+
* @category Registries
|
|
255
|
+
* @since v0.9.3
|
|
256
|
+
*/
|
|
257
|
+
export interface MintAttachResult {
|
|
258
|
+
readonly assetAddress: PublicKey;
|
|
259
|
+
readonly assetSecretKey: Uint8Array;
|
|
260
|
+
readonly registrationUrl: string;
|
|
261
|
+
readonly instructions: readonly TransactionInstruction[];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @interface SapForMplOpts
|
|
266
|
+
* @description Inputs for {@link MetaplexBridge.buildRegisterSapForMplOwnerIx}.
|
|
267
|
+
* Resolves the owner of `asset`, derives that owner's SAP PDA, and (if no
|
|
268
|
+
* agent exists yet) returns the `registerAgent` instruction the owner must sign.
|
|
269
|
+
*
|
|
270
|
+
* @category Registries
|
|
271
|
+
* @since v0.9.3
|
|
272
|
+
*/
|
|
273
|
+
export interface SapForMplOpts {
|
|
274
|
+
readonly asset: PublicKey;
|
|
275
|
+
readonly registerArgs: RegisterAgentInput;
|
|
276
|
+
readonly rpcUrl: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @interface SapForMplResult
|
|
281
|
+
* @description Result of {@link MetaplexBridge.buildRegisterSapForMplOwnerIx}.
|
|
282
|
+
* `instruction` is `null` when the asset owner already has a SAP agent
|
|
283
|
+
* (idempotent: nothing to do).
|
|
284
|
+
*
|
|
285
|
+
* @category Registries
|
|
286
|
+
* @since v0.9.3
|
|
287
|
+
*/
|
|
288
|
+
export interface SapForMplResult {
|
|
289
|
+
readonly assetOwner: PublicKey;
|
|
290
|
+
readonly sapAgentPda: PublicKey;
|
|
291
|
+
readonly alreadyRegistered: boolean;
|
|
292
|
+
readonly currentAgentIdentityUri: string | null;
|
|
293
|
+
readonly instruction: TransactionInstruction | null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* @interface RegisterBothOpts
|
|
298
|
+
* @description Inputs for {@link MetaplexBridge.buildRegisterBothIxs}.
|
|
299
|
+
* Builds the atomic SAP `registerAgent` + MPL Core `create` + `AgentIdentity`
|
|
300
|
+
* attach sequence for a wallet that owns neither side yet.
|
|
301
|
+
*
|
|
302
|
+
* @category Registries
|
|
303
|
+
* @since v0.9.3
|
|
304
|
+
*/
|
|
305
|
+
export interface RegisterBothOpts {
|
|
306
|
+
readonly wallet: PublicKey;
|
|
307
|
+
readonly payer?: PublicKey;
|
|
308
|
+
readonly registerArgs: RegisterAgentInput;
|
|
309
|
+
readonly mintName: string;
|
|
310
|
+
readonly mintMetadataUri: string;
|
|
311
|
+
readonly registrationBaseUrl: string;
|
|
312
|
+
readonly rpcUrl: string;
|
|
313
|
+
readonly collection?: PublicKey;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @interface RegisterBothResult
|
|
318
|
+
* @description Result of {@link MetaplexBridge.buildRegisterBothIxs}.
|
|
319
|
+
* Instructions are ordered: `[0]` SAP `registerAgent`, `[1]` MPL Core mint,
|
|
320
|
+
* `[2]` MPL `AgentIdentity` attach. All three execute atomically inside one
|
|
321
|
+
* transaction signed by the wallet + `assetSecretKey`.
|
|
322
|
+
*
|
|
323
|
+
* @category Registries
|
|
324
|
+
* @since v0.9.3
|
|
325
|
+
*/
|
|
326
|
+
export interface RegisterBothResult {
|
|
327
|
+
readonly sapAgentPda: PublicKey;
|
|
328
|
+
readonly assetAddress: PublicKey;
|
|
329
|
+
readonly assetSecretKey: Uint8Array;
|
|
330
|
+
readonly registrationUrl: string;
|
|
331
|
+
readonly instructions: readonly TransactionInstruction[];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @interface TripleCheckResult
|
|
336
|
+
* @description Result of {@link MetaplexBridge.tripleCheckLink} — the explicit
|
|
337
|
+
* 3-layer verification used by explorer/host badges.
|
|
338
|
+
*
|
|
339
|
+
* - `mplOnChain`: MPL Core asset fetched on-chain via mpl-core (gRPC/RPC).
|
|
340
|
+
* - `eip8004Json`: registration JSON fetched from `agentIdentityUri` and
|
|
341
|
+
* its `synapseAgent` matches the SAP PDA.
|
|
342
|
+
* - `sapOnChain`: a SAP `AgentAccount` exists on-chain at that PDA.
|
|
343
|
+
*
|
|
344
|
+
* `linked = true` only when **all three** layers pass.
|
|
345
|
+
*
|
|
346
|
+
* @category Registries
|
|
347
|
+
* @since v0.9.3
|
|
348
|
+
*/
|
|
349
|
+
export interface TripleCheckResult {
|
|
350
|
+
readonly asset: PublicKey;
|
|
351
|
+
readonly sapAgentPda: PublicKey;
|
|
352
|
+
readonly mplOnChain: boolean;
|
|
353
|
+
readonly eip8004Json: boolean;
|
|
354
|
+
readonly sapOnChain: boolean;
|
|
355
|
+
readonly linked: boolean;
|
|
356
|
+
readonly agentIdentityUri: string | null;
|
|
357
|
+
readonly registration: Eip8004Registration | null;
|
|
358
|
+
readonly identity: AgentAccountData | null;
|
|
359
|
+
readonly error: string | null;
|
|
360
|
+
}
|
|
361
|
+
|
|
178
362
|
// ═══════════════════════════════════════════════════════════════════
|
|
179
363
|
// Lazy peer-dep loader
|
|
180
364
|
// ═══════════════════════════════════════════════════════════════════
|
|
@@ -360,6 +544,177 @@ export class MetaplexBridge {
|
|
|
360
544
|
return this.firstWeb3Ix(builder, "updateExternalPluginAdapterV1");
|
|
361
545
|
}
|
|
362
546
|
|
|
547
|
+
// ─────────────────────────────────────────────────────
|
|
548
|
+
// Write side — combined SAP × MPL register flows (v0.9.3)
|
|
549
|
+
// ─────────────────────────────────────────────────────
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* @name buildMintAndAttachIxs
|
|
553
|
+
* @description Build the two MPL Core instructions needed to mint a new
|
|
554
|
+
* asset for an existing SAP agent and immediately bind it via the
|
|
555
|
+
* `AgentIdentity` plugin (URI = canonical EIP-8004 URL).
|
|
556
|
+
*
|
|
557
|
+
* Flow:
|
|
558
|
+
* 1. Generate a fresh asset keypair (returned as `assetSecretKey`).
|
|
559
|
+
* 2. Build `mpl_core::create` with the new asset as signer.
|
|
560
|
+
* 3. Build `addExternalPluginAdapterV1` for the AgentIdentity URI.
|
|
561
|
+
*
|
|
562
|
+
* The returned `instructions` are deterministic order. The caller
|
|
563
|
+
* partial-signs the assembled transaction with `assetSecretKey` and the
|
|
564
|
+
* authority/payer wallet.
|
|
565
|
+
*
|
|
566
|
+
* @since v0.9.3
|
|
567
|
+
*/
|
|
568
|
+
async buildMintAndAttachIxs(opts: MintAttachOpts): Promise<MintAttachResult> {
|
|
569
|
+
const { mplCore, umiBundle, umiCore } = await loadMplCore();
|
|
570
|
+
const umi: Umi = umiBundle.createUmi(opts.rpcUrl).use(mplCore.mplCore());
|
|
571
|
+
|
|
572
|
+
const [sapPda] = deriveAgent(opts.sapAgentOwner);
|
|
573
|
+
const registrationUrl = this.deriveRegistrationUrl(
|
|
574
|
+
sapPda,
|
|
575
|
+
opts.registrationBaseUrl,
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
const assetUmiSigner = umiCore.generateSigner(umi);
|
|
579
|
+
const assetAddress = new PublicKey(assetUmiSigner.publicKey.toString());
|
|
580
|
+
const assetSecretKey = assetUmiSigner.secretKey;
|
|
581
|
+
|
|
582
|
+
const authority: UmiSigner = umiCore.createNoopSigner(
|
|
583
|
+
umiCore.publicKey(opts.authority.toBase58()),
|
|
584
|
+
);
|
|
585
|
+
const payer: UmiSigner = umiCore.createNoopSigner(
|
|
586
|
+
umiCore.publicKey((opts.payer ?? opts.authority).toBase58()),
|
|
587
|
+
);
|
|
588
|
+
const ownerUmi = opts.owner
|
|
589
|
+
? umiCore.publicKey(opts.owner.toBase58())
|
|
590
|
+
: umiCore.publicKey(opts.authority.toBase58());
|
|
591
|
+
|
|
592
|
+
const createBuilder: TransactionBuilder = mplCore.create(umi, {
|
|
593
|
+
asset: assetUmiSigner,
|
|
594
|
+
collection: opts.collection
|
|
595
|
+
? ({ publicKey: umiCore.publicKey(opts.collection.toBase58()) } as never)
|
|
596
|
+
: undefined,
|
|
597
|
+
authority,
|
|
598
|
+
payer,
|
|
599
|
+
owner: ownerUmi,
|
|
600
|
+
name: opts.name,
|
|
601
|
+
uri: opts.metadataUri,
|
|
602
|
+
});
|
|
603
|
+
const mintIx = await this.firstWeb3Ix(createBuilder, "mpl_core::create");
|
|
604
|
+
|
|
605
|
+
const attachIx = await this.buildAddExternalPluginIx({
|
|
606
|
+
asset: assetAddress,
|
|
607
|
+
authority: opts.authority,
|
|
608
|
+
payer: opts.payer ?? opts.authority,
|
|
609
|
+
uri: registrationUrl,
|
|
610
|
+
rpcUrl: opts.rpcUrl,
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
assetAddress,
|
|
615
|
+
assetSecretKey,
|
|
616
|
+
registrationUrl,
|
|
617
|
+
instructions: [mintIx, attachIx],
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* @name buildRegisterSapForMplOwnerIx
|
|
623
|
+
* @description Given an existing MPL Core asset, resolve its on-chain
|
|
624
|
+
* owner and build the SAP `registerAgent` instruction the owner must
|
|
625
|
+
* sign. Idempotent: if a SAP agent already exists for that owner the
|
|
626
|
+
* method returns `instruction: null` with `alreadyRegistered: true`.
|
|
627
|
+
*
|
|
628
|
+
* Use after a wallet has minted (or holds) an MPL Core agent NFT and
|
|
629
|
+
* wants to back-fill a SAP identity at the canonical PDA so the bridge's
|
|
630
|
+
* EIP-8004 URL becomes resolvable.
|
|
631
|
+
*
|
|
632
|
+
* @since v0.9.3
|
|
633
|
+
*/
|
|
634
|
+
async buildRegisterSapForMplOwnerIx(
|
|
635
|
+
opts: SapForMplOpts,
|
|
636
|
+
): Promise<SapForMplResult> {
|
|
637
|
+
const snap = await this.fetchMplSnapshot(opts.asset, opts.rpcUrl);
|
|
638
|
+
if (!snap) {
|
|
639
|
+
throw new Error(
|
|
640
|
+
`buildRegisterSapForMplOwnerIx: MPL Core asset ${opts.asset.toBase58()} not readable`,
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
const [sapPda] = deriveAgent(snap.owner);
|
|
644
|
+
const existing = await this.fetchAgentNullable(sapPda);
|
|
645
|
+
if (existing) {
|
|
646
|
+
return {
|
|
647
|
+
assetOwner: snap.owner,
|
|
648
|
+
sapAgentPda: sapPda,
|
|
649
|
+
alreadyRegistered: true,
|
|
650
|
+
currentAgentIdentityUri: snap.agentIdentityUri,
|
|
651
|
+
instruction: null,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const ix = await this.buildRegisterAgentIx({
|
|
656
|
+
wallet: snap.owner,
|
|
657
|
+
args: opts.registerArgs,
|
|
658
|
+
});
|
|
659
|
+
return {
|
|
660
|
+
assetOwner: snap.owner,
|
|
661
|
+
sapAgentPda: sapPda,
|
|
662
|
+
alreadyRegistered: false,
|
|
663
|
+
currentAgentIdentityUri: snap.agentIdentityUri,
|
|
664
|
+
instruction: ix,
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* @name buildRegisterBothIxs
|
|
670
|
+
* @description Atomic 3-instruction bundle for a wallet that owns
|
|
671
|
+
* neither side: `[SAP registerAgent, MPL Core create, MPL AgentIdentity attach]`.
|
|
672
|
+
* Single transaction, single user signature (plus the ephemeral asset
|
|
673
|
+
* keypair returned in `assetSecretKey`).
|
|
674
|
+
*
|
|
675
|
+
* Throws if a SAP agent already exists for `wallet` — callers should
|
|
676
|
+
* fall through to {@link MetaplexBridge.buildMintAndAttachIxs} instead.
|
|
677
|
+
*
|
|
678
|
+
* @since v0.9.3
|
|
679
|
+
*/
|
|
680
|
+
async buildRegisterBothIxs(
|
|
681
|
+
opts: RegisterBothOpts,
|
|
682
|
+
): Promise<RegisterBothResult> {
|
|
683
|
+
const [sapPda] = deriveAgent(opts.wallet);
|
|
684
|
+
const existing = await this.fetchAgentNullable(sapPda);
|
|
685
|
+
if (existing) {
|
|
686
|
+
throw new Error(
|
|
687
|
+
`buildRegisterBothIxs: SAP agent already exists at ${sapPda.toBase58()}; ` +
|
|
688
|
+
`use buildMintAndAttachIxs instead`,
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const sapIx = await this.buildRegisterAgentIx({
|
|
693
|
+
wallet: opts.wallet,
|
|
694
|
+
args: opts.registerArgs,
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
const mint = await this.buildMintAndAttachIxs({
|
|
698
|
+
sapAgentOwner: opts.wallet,
|
|
699
|
+
authority: opts.wallet,
|
|
700
|
+
payer: opts.payer ?? opts.wallet,
|
|
701
|
+
owner: opts.wallet,
|
|
702
|
+
name: opts.mintName,
|
|
703
|
+
metadataUri: opts.mintMetadataUri,
|
|
704
|
+
registrationBaseUrl: opts.registrationBaseUrl,
|
|
705
|
+
rpcUrl: opts.rpcUrl,
|
|
706
|
+
collection: opts.collection,
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
return {
|
|
710
|
+
sapAgentPda: sapPda,
|
|
711
|
+
assetAddress: mint.assetAddress,
|
|
712
|
+
assetSecretKey: mint.assetSecretKey,
|
|
713
|
+
registrationUrl: mint.registrationUrl,
|
|
714
|
+
instructions: [sapIx, ...mint.instructions],
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
|
|
363
718
|
// ─────────────────────────────────────────────────────
|
|
364
719
|
// Read side
|
|
365
720
|
// ─────────────────────────────────────────────────────
|
|
@@ -375,6 +730,7 @@ export class MetaplexBridge {
|
|
|
375
730
|
wallet?: PublicKey;
|
|
376
731
|
asset?: PublicKey;
|
|
377
732
|
rpcUrl: string;
|
|
733
|
+
rpcHeaders?: Record<string, string>;
|
|
378
734
|
}): Promise<UnifiedProfile> {
|
|
379
735
|
if (!input.wallet && !input.asset) {
|
|
380
736
|
throw new Error("getUnifiedProfile: provide `wallet` or `asset`");
|
|
@@ -392,7 +748,7 @@ export class MetaplexBridge {
|
|
|
392
748
|
|
|
393
749
|
let mpl: MplAgentSnapshot | null = null;
|
|
394
750
|
if (input.asset) {
|
|
395
|
-
mpl = await this.fetchMplSnapshot(input.asset, input.rpcUrl);
|
|
751
|
+
mpl = await this.fetchMplSnapshot(input.asset, input.rpcUrl, input.rpcHeaders);
|
|
396
752
|
if (!sapPda && mpl?.registration?.synapseAgent) {
|
|
397
753
|
try {
|
|
398
754
|
sapPda = new PublicKey(mpl.registration.synapseAgent);
|
|
@@ -415,6 +771,80 @@ export class MetaplexBridge {
|
|
|
415
771
|
};
|
|
416
772
|
}
|
|
417
773
|
|
|
774
|
+
/**
|
|
775
|
+
* @name resolveAgentIdentifier
|
|
776
|
+
* @description Resolve a generic agent identifier to canonical SAP routing
|
|
777
|
+
* keys. Useful when callers may receive either owner wallets or Metaplex
|
|
778
|
+
* Core asset IDs (e.g. metaplex.com/agents/<core-asset-id>).
|
|
779
|
+
*
|
|
780
|
+
* Resolution order:
|
|
781
|
+
* 1) Treat input as wallet and check if a SAP agent exists.
|
|
782
|
+
* 2) If not found, treat input as MPL Core asset and resolve owner wallet.
|
|
783
|
+
*
|
|
784
|
+
* @since v0.9.2
|
|
785
|
+
*/
|
|
786
|
+
async resolveAgentIdentifier(input: {
|
|
787
|
+
identifier: string;
|
|
788
|
+
rpcUrl: string;
|
|
789
|
+
rpcHeaders?: Record<string, string>;
|
|
790
|
+
}): Promise<AgentIdentifierResolution> {
|
|
791
|
+
let asPubkey: PublicKey;
|
|
792
|
+
try {
|
|
793
|
+
asPubkey = new PublicKey(input.identifier);
|
|
794
|
+
} catch {
|
|
795
|
+
return {
|
|
796
|
+
input: input.identifier,
|
|
797
|
+
kind: "unknown",
|
|
798
|
+
wallet: null,
|
|
799
|
+
sapAgentPda: null,
|
|
800
|
+
asset: null,
|
|
801
|
+
hasSapAgent: false,
|
|
802
|
+
error: "Invalid public key",
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// 1) Wallet-first resolution (SAP-native)
|
|
807
|
+
const [walletSapPda] = deriveAgent(asPubkey);
|
|
808
|
+
const walletIdentity = await this.fetchAgentNullable(walletSapPda);
|
|
809
|
+
if (walletIdentity) {
|
|
810
|
+
return {
|
|
811
|
+
input: input.identifier,
|
|
812
|
+
kind: "wallet",
|
|
813
|
+
wallet: asPubkey,
|
|
814
|
+
sapAgentPda: walletSapPda,
|
|
815
|
+
asset: null,
|
|
816
|
+
hasSapAgent: true,
|
|
817
|
+
error: null,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// 2) MPL Core asset resolution
|
|
822
|
+
const mpl = await this.fetchMplSnapshot(asPubkey, input.rpcUrl, input.rpcHeaders);
|
|
823
|
+
if (!mpl) {
|
|
824
|
+
return {
|
|
825
|
+
input: input.identifier,
|
|
826
|
+
kind: "unknown",
|
|
827
|
+
wallet: null,
|
|
828
|
+
sapAgentPda: null,
|
|
829
|
+
asset: null,
|
|
830
|
+
hasSapAgent: false,
|
|
831
|
+
error: "Not a SAP wallet and not a readable MPL Core asset",
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
const [sapPdaFromOwner] = deriveAgent(mpl.owner);
|
|
836
|
+
const ownerIdentity = await this.fetchAgentNullable(sapPdaFromOwner);
|
|
837
|
+
return {
|
|
838
|
+
input: input.identifier,
|
|
839
|
+
kind: "core-asset",
|
|
840
|
+
wallet: mpl.owner,
|
|
841
|
+
sapAgentPda: sapPdaFromOwner,
|
|
842
|
+
asset: asPubkey,
|
|
843
|
+
hasSapAgent: !!ownerIdentity,
|
|
844
|
+
error: ownerIdentity ? null : "Core asset owner has no SAP agent profile",
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
418
848
|
/**
|
|
419
849
|
* @name verifyLink
|
|
420
850
|
* @description Verify the bidirectional link between an MPL Core asset
|
|
@@ -427,14 +857,81 @@ export class MetaplexBridge {
|
|
|
427
857
|
asset: PublicKey;
|
|
428
858
|
sapAgentPda: PublicKey;
|
|
429
859
|
rpcUrl: string;
|
|
860
|
+
rpcHeaders?: Record<string, string>;
|
|
430
861
|
}): Promise<boolean> {
|
|
431
|
-
const snap = await this.fetchMplSnapshot(args.asset, args.rpcUrl);
|
|
862
|
+
const snap = await this.fetchMplSnapshot(args.asset, args.rpcUrl, args.rpcHeaders);
|
|
432
863
|
if (!snap?.agentIdentityUri || !snap.registration) return false;
|
|
433
864
|
const expectedSuffix = `/agents/${args.sapAgentPda.toBase58()}/eip-8004.json`;
|
|
434
865
|
if (!snap.agentIdentityUri.endsWith(expectedSuffix)) return false;
|
|
435
866
|
return snap.registration.synapseAgent === args.sapAgentPda.toBase58();
|
|
436
867
|
}
|
|
437
868
|
|
|
869
|
+
/**
|
|
870
|
+
* @name tripleCheckLink
|
|
871
|
+
* @description Explicit 3-layer verification for explorer/host badges.
|
|
872
|
+
* Returns one struct enumerating each check independently so UIs can
|
|
873
|
+
* present partial trust states (e.g. "MPL plugin present, JSON pending").
|
|
874
|
+
*
|
|
875
|
+
* Layers:
|
|
876
|
+
* 1. **mplOnChain** — Asset + AgentIdentity URI fetched on-chain.
|
|
877
|
+
* 2. **eip8004Json** — JSON fetched and `synapseAgent` matches PDA.
|
|
878
|
+
* 3. **sapOnChain** — `AgentAccount` PDA exists on the SAP program.
|
|
879
|
+
*
|
|
880
|
+
* @since v0.9.3
|
|
881
|
+
*/
|
|
882
|
+
async tripleCheckLink(args: {
|
|
883
|
+
asset: PublicKey;
|
|
884
|
+
expectedOwner?: PublicKey;
|
|
885
|
+
rpcUrl: string;
|
|
886
|
+
rpcHeaders?: Record<string, string>;
|
|
887
|
+
}): Promise<TripleCheckResult> {
|
|
888
|
+
const snap = await this.fetchMplSnapshot(args.asset, args.rpcUrl, args.rpcHeaders);
|
|
889
|
+
if (!snap) {
|
|
890
|
+
const fallbackPda = args.expectedOwner
|
|
891
|
+
? deriveAgent(args.expectedOwner)[0]
|
|
892
|
+
: args.asset;
|
|
893
|
+
return {
|
|
894
|
+
asset: args.asset,
|
|
895
|
+
sapAgentPda: fallbackPda,
|
|
896
|
+
mplOnChain: false,
|
|
897
|
+
eip8004Json: false,
|
|
898
|
+
sapOnChain: false,
|
|
899
|
+
linked: false,
|
|
900
|
+
agentIdentityUri: null,
|
|
901
|
+
registration: null,
|
|
902
|
+
identity: null,
|
|
903
|
+
error: "MPL Core asset not readable on-chain",
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const owner = args.expectedOwner ?? snap.owner;
|
|
908
|
+
const [sapPda] = deriveAgent(owner);
|
|
909
|
+
const expectedSuffix = `/agents/${sapPda.toBase58()}/eip-8004.json`;
|
|
910
|
+
|
|
911
|
+
const mplOnChain = !!snap.agentIdentityUri;
|
|
912
|
+
const eip8004Json =
|
|
913
|
+
!!snap.registration &&
|
|
914
|
+
!!snap.agentIdentityUri &&
|
|
915
|
+
snap.agentIdentityUri.endsWith(expectedSuffix) &&
|
|
916
|
+
snap.registration.synapseAgent === sapPda.toBase58();
|
|
917
|
+
|
|
918
|
+
const identity = await this.fetchAgentNullable(sapPda);
|
|
919
|
+
const sapOnChain = !!identity;
|
|
920
|
+
|
|
921
|
+
return {
|
|
922
|
+
asset: args.asset,
|
|
923
|
+
sapAgentPda: sapPda,
|
|
924
|
+
mplOnChain,
|
|
925
|
+
eip8004Json,
|
|
926
|
+
sapOnChain,
|
|
927
|
+
linked: mplOnChain && eip8004Json && sapOnChain,
|
|
928
|
+
agentIdentityUri: snap.agentIdentityUri,
|
|
929
|
+
registration: snap.registration,
|
|
930
|
+
identity,
|
|
931
|
+
error: null,
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
|
|
438
935
|
// ═════════════════════════════════════════════════════
|
|
439
936
|
// Private — SAP fetching
|
|
440
937
|
// ═════════════════════════════════════════════════════
|
|
@@ -491,12 +988,30 @@ export class MetaplexBridge {
|
|
|
491
988
|
// Private — MPL fetching
|
|
492
989
|
// ═════════════════════════════════════════════════════
|
|
493
990
|
|
|
991
|
+
private async buildUmi(
|
|
992
|
+
rpcUrl: string,
|
|
993
|
+
rpcHeaders?: Record<string, string>,
|
|
994
|
+
): Promise<Umi> {
|
|
995
|
+
const { mplCore, umiBundle } = await loadMplCore();
|
|
996
|
+
// umi-bundle-defaults.createUmi accepts an options object with httpHeaders
|
|
997
|
+
// since umi 1.x — required for gated providers like Synapse RPC that
|
|
998
|
+
// enforce `x-api-key`. Without it `getAccountInfo` returns 401 silently.
|
|
999
|
+
const umi: Umi = (umiBundle.createUmi as unknown as (
|
|
1000
|
+
endpoint: string,
|
|
1001
|
+
opts?: { httpHeaders?: Record<string, string> },
|
|
1002
|
+
) => Umi)(rpcUrl, rpcHeaders ? { httpHeaders: rpcHeaders } : undefined).use(
|
|
1003
|
+
mplCore.mplCore(),
|
|
1004
|
+
);
|
|
1005
|
+
return umi;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
494
1008
|
private async fetchMplSnapshot(
|
|
495
1009
|
asset: PublicKey,
|
|
496
1010
|
rpcUrl: string,
|
|
1011
|
+
rpcHeaders?: Record<string, string>,
|
|
497
1012
|
): Promise<MplAgentSnapshot | null> {
|
|
498
|
-
const { mplCore,
|
|
499
|
-
const umi: Umi =
|
|
1013
|
+
const { mplCore, umiCore } = await loadMplCore();
|
|
1014
|
+
const umi: Umi = await this.buildUmi(rpcUrl, rpcHeaders);
|
|
500
1015
|
try {
|
|
501
1016
|
const fetched: AssetV1 = await mplCore.fetchAsset(
|
|
502
1017
|
umi,
|
|
@@ -594,6 +1109,45 @@ export class MetaplexBridge {
|
|
|
594
1109
|
return this.firstWeb3Ix(builder, "addExternalPluginAdapterV1");
|
|
595
1110
|
}
|
|
596
1111
|
|
|
1112
|
+
// ═════════════════════════════════════════════════════
|
|
1113
|
+
// Private — SAP instruction building (v0.9.3)
|
|
1114
|
+
// ═════════════════════════════════════════════════════
|
|
1115
|
+
|
|
1116
|
+
private async buildRegisterAgentIx(args: {
|
|
1117
|
+
wallet: PublicKey;
|
|
1118
|
+
args: RegisterAgentInput;
|
|
1119
|
+
}): Promise<TransactionInstruction> {
|
|
1120
|
+
// Lazy import to avoid a hard cycle with `pda/index.ts`.
|
|
1121
|
+
const { deriveGlobalRegistry } = await import("../pda");
|
|
1122
|
+
const { SystemProgram } = await import("@solana/web3.js");
|
|
1123
|
+
const [agentPda] = deriveAgent(args.wallet);
|
|
1124
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
1125
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
1126
|
+
const a = args.args;
|
|
1127
|
+
// Cast to `any` to sidestep Anchor's deep generic IDL inference, which
|
|
1128
|
+
// otherwise blows TS recursion budget here. Same pattern as BaseModule.
|
|
1129
|
+
const methods = (this.program as { methods: any }).methods;
|
|
1130
|
+
return await methods
|
|
1131
|
+
.registerAgent(
|
|
1132
|
+
a.name,
|
|
1133
|
+
a.description,
|
|
1134
|
+
a.capabilities,
|
|
1135
|
+
a.pricing,
|
|
1136
|
+
a.protocols,
|
|
1137
|
+
a.agentId ?? null,
|
|
1138
|
+
a.agentUri ?? null,
|
|
1139
|
+
a.x402Endpoint ?? null,
|
|
1140
|
+
)
|
|
1141
|
+
.accounts({
|
|
1142
|
+
wallet: args.wallet,
|
|
1143
|
+
agent: agentPda,
|
|
1144
|
+
agentStats: statsPda,
|
|
1145
|
+
globalRegistry: globalPda,
|
|
1146
|
+
systemProgram: SystemProgram.programId,
|
|
1147
|
+
})
|
|
1148
|
+
.instruction();
|
|
1149
|
+
}
|
|
1150
|
+
|
|
597
1151
|
private async firstWeb3Ix(
|
|
598
1152
|
builder: TransactionBuilder,
|
|
599
1153
|
name: string,
|