@moltlaunch/sdk 2.4.0 → 3.0.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.
- package/README.md +184 -275
- package/dist/client.d.ts +69 -0
- package/dist/client.js +325 -0
- package/dist/idl/moltlaunch.json +1549 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +63 -0
- package/dist/pda.d.ts +26 -0
- package/dist/pda.js +45 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.js +54 -0
- package/package.json +24 -9
- package/src/idl/moltlaunch.json +1549 -0
- package/examples/agent-config.json +0 -12
- package/src/cli.ts +0 -158
- package/src/index.d.ts +0 -258
- package/src/index.js +0 -1117
- package/src/index.ts +0 -68
- package/src/launcher.ts +0 -263
- package/src/types.ts +0 -122
- package/src/verification.ts +0 -228
- package/test/basic.js +0 -71
- package/tsconfig.json +0 -17
package/dist/client.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MoltLaunch V3 — SDK Client
|
|
4
|
+
*
|
|
5
|
+
* High-level API for interacting with the on-chain Composable Signal Architecture.
|
|
6
|
+
* Program: 6AZSAhq4iJTwCfGEVssoa1p3GnBqGkbcQ1iDdP1U1pSb (devnet)
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MoltLaunchClient = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
const pda_1 = require("./pda");
|
|
17
|
+
const moltlaunch_json_1 = __importDefault(require("./idl/moltlaunch.json"));
|
|
18
|
+
// ── Helpers ─────────────────────────────────────────────────────────
|
|
19
|
+
function mapInfraType(raw) {
|
|
20
|
+
if ("cloud" in raw)
|
|
21
|
+
return types_1.InfraType.Cloud;
|
|
22
|
+
if ("tee" in raw || "TEE" in raw)
|
|
23
|
+
return types_1.InfraType.TEE;
|
|
24
|
+
if ("dePIN" in raw || "dePin" in raw || "depin" in raw)
|
|
25
|
+
return types_1.InfraType.DePIN;
|
|
26
|
+
return types_1.InfraType.Unknown;
|
|
27
|
+
}
|
|
28
|
+
function mapSignalType(raw) {
|
|
29
|
+
if ("infraCloud" in raw)
|
|
30
|
+
return types_1.SignalType.InfraCloud;
|
|
31
|
+
if ("infraTEE" in raw || "infraTee" in raw)
|
|
32
|
+
return types_1.SignalType.InfraTEE;
|
|
33
|
+
if ("infraDePIN" in raw || "infraDePin" in raw || "infraDepin" in raw)
|
|
34
|
+
return types_1.SignalType.InfraDePIN;
|
|
35
|
+
if ("economicStake" in raw)
|
|
36
|
+
return types_1.SignalType.EconomicStake;
|
|
37
|
+
if ("hardwareBinding" in raw)
|
|
38
|
+
return types_1.SignalType.HardwareBinding;
|
|
39
|
+
return types_1.SignalType.General;
|
|
40
|
+
}
|
|
41
|
+
function mapAuthorityType(raw) {
|
|
42
|
+
if ("multisigMember" in raw)
|
|
43
|
+
return types_1.AuthorityType.MultisigMember;
|
|
44
|
+
if ("oracleOperator" in raw)
|
|
45
|
+
return types_1.AuthorityType.OracleOperator;
|
|
46
|
+
if ("ncnValidator" in raw || "NCNValidator" in raw)
|
|
47
|
+
return types_1.AuthorityType.NCNValidator;
|
|
48
|
+
return types_1.AuthorityType.Single;
|
|
49
|
+
}
|
|
50
|
+
// ── Client ──────────────────────────────────────────────────────────
|
|
51
|
+
class MoltLaunchClient {
|
|
52
|
+
connection;
|
|
53
|
+
programId;
|
|
54
|
+
program;
|
|
55
|
+
provider;
|
|
56
|
+
constructor(opts = {}) {
|
|
57
|
+
const rpcUrl = opts.rpcUrl ?? types_1.DEVNET_RPC;
|
|
58
|
+
const commitment = opts.commitment ?? "confirmed";
|
|
59
|
+
this.connection = new web3_js_1.Connection(rpcUrl, commitment);
|
|
60
|
+
this.programId = types_1.MOLTLAUNCH_PROGRAM_ID;
|
|
61
|
+
// Build provider — read-only if no wallet supplied
|
|
62
|
+
const wallet = opts.wallet ?? {
|
|
63
|
+
publicKey: web3_js_1.PublicKey.default,
|
|
64
|
+
signTransaction: async (tx) => tx,
|
|
65
|
+
signAllTransactions: async (txs) => txs,
|
|
66
|
+
};
|
|
67
|
+
this.provider = new anchor_1.AnchorProvider(this.connection, wallet, {
|
|
68
|
+
commitment,
|
|
69
|
+
});
|
|
70
|
+
this.program = new anchor_1.Program(moltlaunch_json_1.default, this.provider);
|
|
71
|
+
}
|
|
72
|
+
// ── Read Operations ─────────────────────────────────────────────
|
|
73
|
+
/** Fetch the singleton ProtocolConfig account */
|
|
74
|
+
async getConfig() {
|
|
75
|
+
const [pda] = (0, pda_1.findConfigPda)();
|
|
76
|
+
const raw = await this.program.account.protocolConfig.fetch(pda);
|
|
77
|
+
return {
|
|
78
|
+
admin: raw.admin,
|
|
79
|
+
revocationNonce: BigInt(raw.revocationNonce.toString()),
|
|
80
|
+
totalAgents: BigInt(raw.totalAgents.toString()),
|
|
81
|
+
totalAttestations: BigInt(raw.totalAttestations.toString()),
|
|
82
|
+
paused: raw.paused,
|
|
83
|
+
bump: raw.bump,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Fetch an AgentIdentity by wallet public key */
|
|
87
|
+
async getAgentIdentity(wallet) {
|
|
88
|
+
const [pda] = (0, pda_1.findAgentPda)(wallet);
|
|
89
|
+
const raw = await this.program.account.agentIdentity.fetch(pda);
|
|
90
|
+
return {
|
|
91
|
+
wallet: raw.wallet,
|
|
92
|
+
infraType: mapInfraType(raw.infraType),
|
|
93
|
+
hasEconomicStake: raw.hasEconomicStake,
|
|
94
|
+
hasHardwareBinding: raw.hasHardwareBinding,
|
|
95
|
+
attestationCount: raw.attestationCount,
|
|
96
|
+
isFlagged: raw.isFlagged,
|
|
97
|
+
trustScore: raw.trustScore,
|
|
98
|
+
lastVerified: BigInt(raw.lastVerified.toString()),
|
|
99
|
+
nonce: BigInt(raw.nonce.toString()),
|
|
100
|
+
registeredAt: BigInt(raw.registeredAt.toString()),
|
|
101
|
+
name: raw.name,
|
|
102
|
+
bump: raw.bump,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Fetch an Authority account */
|
|
106
|
+
async getAuthority(pubkey) {
|
|
107
|
+
const [pda] = (0, pda_1.findAuthorityPda)(pubkey);
|
|
108
|
+
const raw = await this.program.account.authority.fetch(pda);
|
|
109
|
+
return {
|
|
110
|
+
pubkey: raw.pubkey,
|
|
111
|
+
authorityType: mapAuthorityType(raw.authorityType),
|
|
112
|
+
attestationCount: BigInt(raw.attestationCount.toString()),
|
|
113
|
+
active: raw.active,
|
|
114
|
+
addedBy: raw.addedBy,
|
|
115
|
+
addedAt: BigInt(raw.addedAt.toString()),
|
|
116
|
+
bump: raw.bump,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Fetch an Attestation account */
|
|
120
|
+
async getAttestation(agentWallet, authorityPubkey) {
|
|
121
|
+
const [pda] = (0, pda_1.findAttestationPda)(agentWallet, authorityPubkey);
|
|
122
|
+
const raw = await this.program.account.attestation.fetch(pda);
|
|
123
|
+
return {
|
|
124
|
+
agent: raw.agent,
|
|
125
|
+
authority: raw.authority,
|
|
126
|
+
authorityType: mapAuthorityType(raw.authorityType),
|
|
127
|
+
signalContributed: mapSignalType(raw.signalContributed),
|
|
128
|
+
attestationHash: Array.from(raw.attestationHash),
|
|
129
|
+
teeQuote: raw.teeQuote ? Array.from(raw.teeQuote) : null,
|
|
130
|
+
createdAt: BigInt(raw.createdAt.toString()),
|
|
131
|
+
expiresAt: BigInt(raw.expiresAt.toString()),
|
|
132
|
+
revoked: raw.revoked,
|
|
133
|
+
bump: raw.bump,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// ── Write Operations ────────────────────────────────────────────
|
|
137
|
+
/**
|
|
138
|
+
* Register a new agent identity on-chain.
|
|
139
|
+
* Signer = the agent's wallet keypair.
|
|
140
|
+
*/
|
|
141
|
+
async registerAgent(name, walletKeypair) {
|
|
142
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
143
|
+
const [agentPda] = (0, pda_1.findAgentPda)(walletKeypair.publicKey);
|
|
144
|
+
const tx = await this.program.methods
|
|
145
|
+
.registerAgent(name)
|
|
146
|
+
.accounts({
|
|
147
|
+
config: configPda,
|
|
148
|
+
agent: agentPda,
|
|
149
|
+
wallet: walletKeypair.publicKey,
|
|
150
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
151
|
+
})
|
|
152
|
+
.signers([walletKeypair])
|
|
153
|
+
.rpc();
|
|
154
|
+
return tx;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Submit an attestation for an agent.
|
|
158
|
+
* Signer = the authority's keypair.
|
|
159
|
+
*/
|
|
160
|
+
async submitAttestation(agentWallet, signalType, attestationHash, expiresAt, authorityKeypair, teeQuote) {
|
|
161
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
162
|
+
const [authorityPda] = (0, pda_1.findAuthorityPda)(authorityKeypair.publicKey);
|
|
163
|
+
const [agentPda] = (0, pda_1.findAgentPda)(agentWallet);
|
|
164
|
+
const [attestationPda] = (0, pda_1.findAttestationPda)(agentWallet, authorityKeypair.publicKey);
|
|
165
|
+
const hashArr = Array.from(attestationHash);
|
|
166
|
+
const teeArr = teeQuote ? Array.from(teeQuote) : null;
|
|
167
|
+
const tx = await this.program.methods
|
|
168
|
+
.submitAttestation((0, types_1.toAnchorEnum)(signalType), hashArr, teeArr, new anchor_1.BN(expiresAt.toString()))
|
|
169
|
+
.accounts({
|
|
170
|
+
config: configPda,
|
|
171
|
+
authority: authorityPda,
|
|
172
|
+
agent: agentPda,
|
|
173
|
+
attestation: attestationPda,
|
|
174
|
+
authoritySigner: authorityKeypair.publicKey,
|
|
175
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
176
|
+
})
|
|
177
|
+
.signers([authorityKeypair])
|
|
178
|
+
.rpc();
|
|
179
|
+
return tx;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Revoke an attestation (only the original authority can revoke).
|
|
183
|
+
*/
|
|
184
|
+
async revokeAttestation(agentWallet, authorityKeypair) {
|
|
185
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
186
|
+
const [attestationPda] = (0, pda_1.findAttestationPda)(agentWallet, authorityKeypair.publicKey);
|
|
187
|
+
const tx = await this.program.methods
|
|
188
|
+
.revokeAttestation()
|
|
189
|
+
.accounts({
|
|
190
|
+
config: configPda,
|
|
191
|
+
attestation: attestationPda,
|
|
192
|
+
authoritySigner: authorityKeypair.publicKey,
|
|
193
|
+
})
|
|
194
|
+
.signers([authorityKeypair])
|
|
195
|
+
.rpc();
|
|
196
|
+
return tx;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Refresh an agent's trust signals (permissionless — anyone can call).
|
|
200
|
+
*/
|
|
201
|
+
async refreshSignals(agentWallet, signerKeypair) {
|
|
202
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
203
|
+
const [agentPda] = (0, pda_1.findAgentPda)(agentWallet);
|
|
204
|
+
const builder = this.program.methods
|
|
205
|
+
.refreshIdentitySignals()
|
|
206
|
+
.accounts({
|
|
207
|
+
config: configPda,
|
|
208
|
+
agent: agentPda,
|
|
209
|
+
});
|
|
210
|
+
if (signerKeypair) {
|
|
211
|
+
builder.signers([signerKeypair]);
|
|
212
|
+
}
|
|
213
|
+
return builder.rpc();
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Flag an agent (authority-only).
|
|
217
|
+
*/
|
|
218
|
+
async flagAgent(agentWallet, reasonHash, authorityKeypair) {
|
|
219
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
220
|
+
const [authorityPda] = (0, pda_1.findAuthorityPda)(authorityKeypair.publicKey);
|
|
221
|
+
const [agentPda] = (0, pda_1.findAgentPda)(agentWallet);
|
|
222
|
+
const tx = await this.program.methods
|
|
223
|
+
.flagAgent(Array.from(reasonHash))
|
|
224
|
+
.accounts({
|
|
225
|
+
config: configPda,
|
|
226
|
+
authority: authorityPda,
|
|
227
|
+
agent: agentPda,
|
|
228
|
+
authoritySigner: authorityKeypair.publicKey,
|
|
229
|
+
})
|
|
230
|
+
.signers([authorityKeypair])
|
|
231
|
+
.rpc();
|
|
232
|
+
return tx;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Unflag an agent (admin-only).
|
|
236
|
+
*/
|
|
237
|
+
async unflagAgent(agentWallet, adminKeypair) {
|
|
238
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
239
|
+
const [agentPda] = (0, pda_1.findAgentPda)(agentWallet);
|
|
240
|
+
const tx = await this.program.methods
|
|
241
|
+
.unflagAgent()
|
|
242
|
+
.accounts({
|
|
243
|
+
config: configPda,
|
|
244
|
+
agent: agentPda,
|
|
245
|
+
admin: adminKeypair.publicKey,
|
|
246
|
+
})
|
|
247
|
+
.signers([adminKeypair])
|
|
248
|
+
.rpc();
|
|
249
|
+
return tx;
|
|
250
|
+
}
|
|
251
|
+
// ── Admin Operations ────────────────────────────────────────────
|
|
252
|
+
/** Initialize the protocol (admin, one-time) */
|
|
253
|
+
async initialize(adminKeypair) {
|
|
254
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
255
|
+
const tx = await this.program.methods
|
|
256
|
+
.initialize()
|
|
257
|
+
.accounts({
|
|
258
|
+
config: configPda,
|
|
259
|
+
admin: adminKeypair.publicKey,
|
|
260
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
261
|
+
})
|
|
262
|
+
.signers([adminKeypair])
|
|
263
|
+
.rpc();
|
|
264
|
+
return tx;
|
|
265
|
+
}
|
|
266
|
+
/** Add an authority (admin-only) */
|
|
267
|
+
async addAuthority(authorityPubkey, authorityType, adminKeypair) {
|
|
268
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
269
|
+
const [authorityPda] = (0, pda_1.findAuthorityPda)(authorityPubkey);
|
|
270
|
+
const tx = await this.program.methods
|
|
271
|
+
.addAuthority((0, types_1.toAnchorEnum)(authorityType))
|
|
272
|
+
.accounts({
|
|
273
|
+
config: configPda,
|
|
274
|
+
authority: authorityPda,
|
|
275
|
+
authorityPubkey: authorityPubkey,
|
|
276
|
+
admin: adminKeypair.publicKey,
|
|
277
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
278
|
+
})
|
|
279
|
+
.signers([adminKeypair])
|
|
280
|
+
.rpc();
|
|
281
|
+
return tx;
|
|
282
|
+
}
|
|
283
|
+
/** Remove an authority (admin-only) */
|
|
284
|
+
async removeAuthority(authorityPubkey, adminKeypair) {
|
|
285
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
286
|
+
const [authorityPda] = (0, pda_1.findAuthorityPda)(authorityPubkey);
|
|
287
|
+
const tx = await this.program.methods
|
|
288
|
+
.removeAuthority()
|
|
289
|
+
.accounts({
|
|
290
|
+
config: configPda,
|
|
291
|
+
authority: authorityPda,
|
|
292
|
+
admin: adminKeypair.publicKey,
|
|
293
|
+
})
|
|
294
|
+
.signers([adminKeypair])
|
|
295
|
+
.rpc();
|
|
296
|
+
return tx;
|
|
297
|
+
}
|
|
298
|
+
/** Pause / unpause protocol (admin-only) */
|
|
299
|
+
async setPaused(paused, adminKeypair) {
|
|
300
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
301
|
+
const tx = await this.program.methods
|
|
302
|
+
.setPaused(paused)
|
|
303
|
+
.accounts({
|
|
304
|
+
config: configPda,
|
|
305
|
+
admin: adminKeypair.publicKey,
|
|
306
|
+
})
|
|
307
|
+
.signers([adminKeypair])
|
|
308
|
+
.rpc();
|
|
309
|
+
return tx;
|
|
310
|
+
}
|
|
311
|
+
/** Transfer admin to a new pubkey (admin-only) */
|
|
312
|
+
async transferAdmin(newAdmin, adminKeypair) {
|
|
313
|
+
const [configPda] = (0, pda_1.findConfigPda)();
|
|
314
|
+
const tx = await this.program.methods
|
|
315
|
+
.transferAdmin(newAdmin)
|
|
316
|
+
.accounts({
|
|
317
|
+
config: configPda,
|
|
318
|
+
admin: adminKeypair.publicKey,
|
|
319
|
+
})
|
|
320
|
+
.signers([adminKeypair])
|
|
321
|
+
.rpc();
|
|
322
|
+
return tx;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
exports.MoltLaunchClient = MoltLaunchClient;
|