@ghostspeak/sdk 2.0.6 → 2.0.8
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 +295 -30
- package/dist/GhostSpeakClient-bnXwUPHI.d.ts +1011 -0
- package/dist/StakingModule-DunDShLq.d.ts +2446 -0
- package/dist/{agent-M74TCRON.js → agent-S42FIMR7.js} +4 -4
- package/dist/{agent-M74TCRON.js.map → agent-S42FIMR7.js.map} +1 -1
- package/dist/batch-operations-45CQFEID.js +4 -0
- package/dist/batch-operations-45CQFEID.js.map +1 -0
- package/dist/browser-CI5_6Gzk.d.ts +234 -0
- package/dist/browser.d.ts +6 -576
- package/dist/browser.js +15 -842
- package/dist/browser.js.map +1 -1
- package/dist/chunk-46QWY3MG.js +156 -0
- package/dist/chunk-46QWY3MG.js.map +1 -0
- package/dist/{chunk-F3DZMBUA.js → chunk-5QBSC4T4.js} +327 -493
- package/dist/chunk-5QBSC4T4.js.map +1 -0
- package/dist/chunk-5QZVFUXB.js +4176 -0
- package/dist/chunk-5QZVFUXB.js.map +1 -0
- package/dist/chunk-6XCCMJ6M.js +1865 -0
- package/dist/chunk-6XCCMJ6M.js.map +1 -0
- package/dist/chunk-A7ALCVUI.js +98 -0
- package/dist/chunk-A7ALCVUI.js.map +1 -0
- package/dist/chunk-AWMGX3OX.js +814 -0
- package/dist/chunk-AWMGX3OX.js.map +1 -0
- package/dist/chunk-BF3IQ35I.js +284 -0
- package/dist/chunk-BF3IQ35I.js.map +1 -0
- package/dist/chunk-BQDGRTVP.js +168 -0
- package/dist/chunk-BQDGRTVP.js.map +1 -0
- package/dist/chunk-IQM5RASO.js +8502 -0
- package/dist/chunk-IQM5RASO.js.map +1 -0
- package/dist/chunk-JYXSOXCP.js +3850 -0
- package/dist/chunk-JYXSOXCP.js.map +1 -0
- package/dist/chunk-OXA7MECJ.js +7787 -0
- package/dist/chunk-OXA7MECJ.js.map +1 -0
- package/dist/chunk-QLRWUHN2.js +231 -0
- package/dist/chunk-QLRWUHN2.js.map +1 -0
- package/dist/chunk-SKMJJ3Q6.js +125 -0
- package/dist/chunk-SKMJJ3Q6.js.map +1 -0
- package/dist/chunk-TTB4OS2D.js +69 -0
- package/dist/chunk-TTB4OS2D.js.map +1 -0
- package/dist/chunk-UP2VWCW5.js +33 -0
- package/dist/{chunk-NSBPE2FW.js.map → chunk-UP2VWCW5.js.map} +1 -1
- package/dist/{chunk-UJUGGLMT.js → chunk-VQZQCHUT.js} +5 -5
- package/dist/{chunk-UJUGGLMT.js.map → chunk-VQZQCHUT.js.map} +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.js +11 -10
- package/dist/createAgentAuthorization-KGZNXZBT.js +5 -0
- package/dist/createAgentAuthorization-KGZNXZBT.js.map +1 -0
- package/dist/credentials.js +1 -1
- package/dist/crypto.js +2 -2
- package/dist/errors.js +1 -1
- package/dist/feature-flags-B1g0DCPe.d.ts +1181 -0
- package/dist/generated-QJREJQ2C.js +9 -0
- package/dist/{generated-VNLHMR6Y.js.map → generated-QJREJQ2C.js.map} +1 -1
- package/dist/{ghostspeak_wasm-SB2RPJ3D.js → ghostspeak_wasm-F227HOSM.js} +3 -3
- package/dist/{ghostspeak_wasm-SB2RPJ3D.js.map → ghostspeak_wasm-F227HOSM.js.map} +1 -1
- package/dist/index.d.ts +1179 -1498
- package/dist/index.js +356 -3578
- package/dist/index.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/minimal/core-minimal.d.ts +2446 -1245
- package/dist/minimal/core-minimal.js +9 -9
- package/dist/minimal/core-minimal.js.map +1 -1
- package/dist/nacl-fast-W5BJ3KZ2.js +2229 -0
- package/dist/nacl-fast-W5BJ3KZ2.js.map +1 -0
- package/dist/pda-4KP7CURF.js +4 -0
- package/dist/pda-4KP7CURF.js.map +1 -0
- package/dist/pda-Ce7VYg4T.d.ts +25 -0
- package/dist/reputation-types-Yebf0Rm_.d.ts +1071 -0
- package/dist/revokeAuthorization-2ZRO6GUZ.js +5 -0
- package/dist/revokeAuthorization-2ZRO6GUZ.js.map +1 -0
- package/dist/signature-verification-DGxR4aYQ.d.ts +448 -0
- package/dist/types.js +1 -1
- package/dist/updateReputationWithAuth-PCEUOCFV.js +5 -0
- package/dist/updateReputationWithAuth-PCEUOCFV.js.map +1 -0
- package/dist/utils.d.ts +69 -203
- package/dist/utils.js +15 -153
- package/dist/utils.js.map +1 -1
- package/package.json +27 -34
- package/dist/.tsbuildinfo +0 -1
- package/dist/GhostSpeakClient-D_66Uzsf.d.ts +0 -707
- package/dist/GovernanceModule-DQYYys-H.d.ts +0 -1766
- package/dist/chunk-APCKGD23.js +0 -1328
- package/dist/chunk-APCKGD23.js.map +0 -1
- package/dist/chunk-ASQXX4IT.js +0 -572
- package/dist/chunk-ASQXX4IT.js.map +0 -1
- package/dist/chunk-COGZFWOT.js +0 -19657
- package/dist/chunk-COGZFWOT.js.map +0 -1
- package/dist/chunk-F3DZMBUA.js.map +0 -1
- package/dist/chunk-GMHIUK2R.js +0 -7526
- package/dist/chunk-GMHIUK2R.js.map +0 -1
- package/dist/chunk-IAWBZYPE.js +0 -356
- package/dist/chunk-IAWBZYPE.js.map +0 -1
- package/dist/chunk-NSBPE2FW.js +0 -15
- package/dist/chunk-OWYHJG6H.js +0 -13311
- package/dist/chunk-OWYHJG6H.js.map +0 -1
- package/dist/chunk-RDDPOFR5.js +0 -3
- package/dist/chunk-RDDPOFR5.js.map +0 -1
- package/dist/chunk-RERCHKZP.js +0 -35
- package/dist/chunk-RERCHKZP.js.map +0 -1
- package/dist/chunk-TVVGXYCI.js +0 -2887
- package/dist/chunk-TVVGXYCI.js.map +0 -1
- package/dist/chunk-ZGP5552B.js +0 -377
- package/dist/chunk-ZGP5552B.js.map +0 -1
- package/dist/chunk-ZWOYNHVK.js +0 -196
- package/dist/chunk-ZWOYNHVK.js.map +0 -1
- package/dist/dist/.tsbuildinfo +0 -1
- package/dist/elgamal-VZLWB3XK.js +0 -5
- package/dist/elgamal-VZLWB3XK.js.map +0 -1
- package/dist/feature-flags-V722ZuXO.d.ts +0 -3512
- package/dist/generated-VNLHMR6Y.js +0 -5
- package/dist/ipfs-types-BOt9ZNg4.d.ts +0 -592
- package/dist/multisigConfig-BzEhy6jy.d.ts +0 -58
- package/dist/pda-B_nS8SbD.d.ts +0 -114
- package/dist/pda-S4BFJVGE.js +0 -4
- package/dist/pda-S4BFJVGE.js.map +0 -1
- package/dist/system-addresses-BFNLEbFx.d.ts +0 -857
- package/dist/token-2022-rpc-RALH4RK7.js +0 -593
- package/dist/token-2022-rpc-RALH4RK7.js.map +0 -1
|
@@ -0,0 +1,1865 @@
|
|
|
1
|
+
import { CredentialModule, BaseModule, generateDidString, validateDidString, deriveDidDocumentPda, parseDidString, didDocumentToJson, exportAsW3CDidDocument, isDidActive, createEd25519VerificationMethod, createServiceEndpoint, AgentModule, GhostModule, GovernanceModule, MultisigModule, ReputationModule, init_MultiSourceAggregator, MultiSourceAggregator_exports, StakingModule } from './chunk-JYXSOXCP.js';
|
|
2
|
+
import { createSignedAuthorization, verifyAuthorizationSignature, isAuthorizationExpired, isAuthorizationExhausted, serializeAuthorization, deserializeAuthorization, getAuthorizationId } from './chunk-BQDGRTVP.js';
|
|
3
|
+
import { PRIVACY_CONSTANTS, PrivacyPresets, init_reputation_tag_engine, reputation_tag_engine_exports } from './chunk-OXA7MECJ.js';
|
|
4
|
+
import { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS } from './chunk-AWMGX3OX.js';
|
|
5
|
+
import { CrossmintVCClient } from './chunk-RIZZPLLB.js';
|
|
6
|
+
import { __toCommonJS } from './chunk-UP2VWCW5.js';
|
|
7
|
+
import { address } from '@solana/addresses';
|
|
8
|
+
|
|
9
|
+
// src/modules/credentials/UnifiedCredentialService.ts
|
|
10
|
+
var UnifiedCredentialService = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.credentialModule = new CredentialModule(config.programId);
|
|
14
|
+
if (config.crossmint) {
|
|
15
|
+
this.crossmintClient = new CrossmintVCClient(config.crossmint);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
credentialModule;
|
|
19
|
+
crossmintClient;
|
|
20
|
+
/**
|
|
21
|
+
* Issue an Agent Identity credential.
|
|
22
|
+
* Note: logic simplified for SDK usage (mocking the on-chain part for now as per original implementation)
|
|
23
|
+
*/
|
|
24
|
+
async issueAgentIdentityCredential(params) {
|
|
25
|
+
const subjectData = CredentialModule.buildAgentIdentitySubject({
|
|
26
|
+
agentId: params.agentId,
|
|
27
|
+
owner: params.owner,
|
|
28
|
+
name: params.name,
|
|
29
|
+
capabilities: params.capabilities,
|
|
30
|
+
serviceEndpoint: params.serviceEndpoint,
|
|
31
|
+
frameworkOrigin: params.frameworkOrigin,
|
|
32
|
+
x402Enabled: params.x402Enabled,
|
|
33
|
+
registeredAt: params.registeredAt,
|
|
34
|
+
verifiedAt: params.verifiedAt
|
|
35
|
+
});
|
|
36
|
+
const credentialId = this.credentialModule.generateCredentialId(
|
|
37
|
+
"AgentIdentity" /* AgentIdentity */,
|
|
38
|
+
params.owner
|
|
39
|
+
);
|
|
40
|
+
const subjectDataHash = this.credentialModule.hashSubjectData(subjectData);
|
|
41
|
+
const credential = {
|
|
42
|
+
template: "11111111111111111111111111111111",
|
|
43
|
+
// Placeholder Address
|
|
44
|
+
subject: params.owner,
|
|
45
|
+
issuer: params.owner,
|
|
46
|
+
// Self-issued for agent identity usually, or program
|
|
47
|
+
credentialId,
|
|
48
|
+
subjectDataHash,
|
|
49
|
+
subjectDataUri: `ipfs://placeholder/${credentialId}`,
|
|
50
|
+
status: "Active" /* Active */,
|
|
51
|
+
signature: params.signature,
|
|
52
|
+
// Use provided signature
|
|
53
|
+
issuedAt: Math.floor(Date.now() / 1e3),
|
|
54
|
+
expiresAt: void 0,
|
|
55
|
+
revokedAt: void 0,
|
|
56
|
+
crossmintCredentialId: void 0
|
|
57
|
+
};
|
|
58
|
+
const mockType = {
|
|
59
|
+
authority: "11111111111111111111111111111111",
|
|
60
|
+
name: "AgentIdentity",
|
|
61
|
+
kind: "AgentIdentity" /* AgentIdentity */,
|
|
62
|
+
schemaUri: "https://ghostspeak.io/schemas/agent-identity.json",
|
|
63
|
+
description: "Verified AI agent identity on GhostSpeak Protocol",
|
|
64
|
+
isActive: true,
|
|
65
|
+
totalIssued: 1,
|
|
66
|
+
createdAt: Math.floor(Date.now() / 1e3)
|
|
67
|
+
};
|
|
68
|
+
const mockTemplate = {
|
|
69
|
+
credentialType: "11111111111111111111111111111111",
|
|
70
|
+
name: "GhostSpeak Agent Identity",
|
|
71
|
+
imageUri: "https://www.ghostspeak.io/assets/credential-agent.png",
|
|
72
|
+
issuer: params.owner,
|
|
73
|
+
isActive: true,
|
|
74
|
+
totalIssued: 1,
|
|
75
|
+
createdAt: Math.floor(Date.now() / 1e3),
|
|
76
|
+
crossmintTemplateId: this.config.crossmintTemplates?.agentIdentity
|
|
77
|
+
};
|
|
78
|
+
const w3cCredential = this.credentialModule.exportAsW3CCredential(
|
|
79
|
+
credential,
|
|
80
|
+
mockTemplate,
|
|
81
|
+
mockType,
|
|
82
|
+
subjectData
|
|
83
|
+
);
|
|
84
|
+
const result = {
|
|
85
|
+
solanaCredential: {
|
|
86
|
+
credentialId
|
|
87
|
+
},
|
|
88
|
+
w3cCredential
|
|
89
|
+
};
|
|
90
|
+
if (params.syncToCrossmint && this.crossmintClient && params.recipientEmail) {
|
|
91
|
+
if (!mockTemplate.crossmintTemplateId) {
|
|
92
|
+
result.crossmintSync = { status: "failed", error: "No template ID configured" };
|
|
93
|
+
} else {
|
|
94
|
+
try {
|
|
95
|
+
const crossmintResult = await this.crossmintClient.issueCredential(
|
|
96
|
+
mockTemplate.crossmintTemplateId,
|
|
97
|
+
params.recipientEmail,
|
|
98
|
+
subjectData
|
|
99
|
+
// enrichedSubject... logic handled here or in client?
|
|
100
|
+
// In web it was in syncToCrossmint.
|
|
101
|
+
);
|
|
102
|
+
result.crossmintSync = {
|
|
103
|
+
status: "synced",
|
|
104
|
+
credentialId: crossmintResult.credentialId,
|
|
105
|
+
chain: this.config.crossmint?.chain
|
|
106
|
+
};
|
|
107
|
+
} catch (error) {
|
|
108
|
+
result.crossmintSync = {
|
|
109
|
+
status: "failed",
|
|
110
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var DidModule = class extends BaseModule {
|
|
119
|
+
constructor(config) {
|
|
120
|
+
super(config);
|
|
121
|
+
}
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// DID CRUD Operations
|
|
124
|
+
// ============================================================================
|
|
125
|
+
/**
|
|
126
|
+
* Create a new DID document
|
|
127
|
+
*
|
|
128
|
+
* @param signer - Transaction signer (will be the controller)
|
|
129
|
+
* @param params - DID creation parameters
|
|
130
|
+
* @returns Transaction signature
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const signature = await didModule.create(signer, {
|
|
135
|
+
* controller: signer.address,
|
|
136
|
+
* network: 'devnet',
|
|
137
|
+
* verificationMethods: [{
|
|
138
|
+
* id: 'key-1',
|
|
139
|
+
* methodType: VerificationMethodType.Ed25519VerificationKey2020,
|
|
140
|
+
* controller: 'did:sol:devnet:...',
|
|
141
|
+
* publicKeyMultibase: 'z...',
|
|
142
|
+
* relationships: [VerificationRelationship.Authentication],
|
|
143
|
+
* createdAt: Date.now() / 1000,
|
|
144
|
+
* revoked: false
|
|
145
|
+
* }]
|
|
146
|
+
* })
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
async create(signer, params) {
|
|
150
|
+
const network = params.network || "devnet";
|
|
151
|
+
const didString = generateDidString(network, params.controller);
|
|
152
|
+
validateDidString(didString);
|
|
153
|
+
const [didDocumentPda] = await deriveDidDocumentPda(
|
|
154
|
+
this.programId,
|
|
155
|
+
params.controller
|
|
156
|
+
);
|
|
157
|
+
const instructionGetter = async () => {
|
|
158
|
+
return this.buildCreateDidInstruction(
|
|
159
|
+
didDocumentPda,
|
|
160
|
+
params.controller,
|
|
161
|
+
didString,
|
|
162
|
+
params.verificationMethods || [],
|
|
163
|
+
params.serviceEndpoints || []
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
return this.execute(
|
|
167
|
+
"createDidDocument",
|
|
168
|
+
instructionGetter,
|
|
169
|
+
[signer]
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Update an existing DID document
|
|
174
|
+
*
|
|
175
|
+
* @param signer - Transaction signer (must be the controller)
|
|
176
|
+
* @param params - Update parameters
|
|
177
|
+
* @returns Transaction signature
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const signature = await didModule.update(signer, {
|
|
182
|
+
* didDocument: didPda,
|
|
183
|
+
* addVerificationMethod: {
|
|
184
|
+
* id: 'key-2',
|
|
185
|
+
* methodType: VerificationMethodType.X25519KeyAgreementKey2020,
|
|
186
|
+
* controller: 'did:sol:devnet:...',
|
|
187
|
+
* publicKeyMultibase: 'z...',
|
|
188
|
+
* relationships: [VerificationRelationship.KeyAgreement],
|
|
189
|
+
* createdAt: Date.now() / 1000,
|
|
190
|
+
* revoked: false
|
|
191
|
+
* }
|
|
192
|
+
* })
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
async update(signer, params) {
|
|
196
|
+
const instructionGetter = async () => {
|
|
197
|
+
return this.buildUpdateDidInstruction(
|
|
198
|
+
params.didDocument,
|
|
199
|
+
signer.address,
|
|
200
|
+
params.addVerificationMethod || null,
|
|
201
|
+
params.removeVerificationMethodId || null,
|
|
202
|
+
params.addServiceEndpoint || null,
|
|
203
|
+
params.removeServiceEndpointId || null
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
return this.execute(
|
|
207
|
+
"updateDidDocument",
|
|
208
|
+
instructionGetter,
|
|
209
|
+
[signer]
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Deactivate a DID document (irreversible)
|
|
214
|
+
*
|
|
215
|
+
* @param signer - Transaction signer (must be the controller)
|
|
216
|
+
* @param params - Deactivation parameters
|
|
217
|
+
* @returns Transaction signature
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const signature = await didModule.deactivate(signer, {
|
|
222
|
+
* didDocument: didPda
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
async deactivate(signer, params) {
|
|
227
|
+
const instructionGetter = async () => {
|
|
228
|
+
return this.buildDeactivateDidInstruction(
|
|
229
|
+
params.didDocument,
|
|
230
|
+
signer.address
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
return this.execute(
|
|
234
|
+
"deactivateDidDocument",
|
|
235
|
+
instructionGetter,
|
|
236
|
+
[signer]
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Resolve a DID document
|
|
241
|
+
*
|
|
242
|
+
* @param didOrController - DID string or controller address
|
|
243
|
+
* @returns DID document or null if not found
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Resolve by controller address
|
|
248
|
+
* const didDoc = await didModule.resolve(controllerAddress)
|
|
249
|
+
*
|
|
250
|
+
* // Resolve by DID string
|
|
251
|
+
* const didDoc = await didModule.resolve('did:sol:devnet:5VKz...')
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
async resolve(didOrController) {
|
|
255
|
+
let controllerAddress;
|
|
256
|
+
if (typeof didOrController === "string" && didOrController.startsWith("did:sol:")) {
|
|
257
|
+
const { identifier } = parseDidString(didOrController);
|
|
258
|
+
controllerAddress = address(identifier);
|
|
259
|
+
} else {
|
|
260
|
+
controllerAddress = typeof didOrController === "string" ? address(didOrController) : didOrController;
|
|
261
|
+
}
|
|
262
|
+
const [didDocumentPda] = await deriveDidDocumentPda(
|
|
263
|
+
this.programId,
|
|
264
|
+
controllerAddress
|
|
265
|
+
);
|
|
266
|
+
return this.getAccount(didDocumentPda, "getDidDocumentDecoder");
|
|
267
|
+
}
|
|
268
|
+
// ============================================================================
|
|
269
|
+
// W3C Export
|
|
270
|
+
// ============================================================================
|
|
271
|
+
/**
|
|
272
|
+
* Export a DID document as W3C-compliant JSON
|
|
273
|
+
*
|
|
274
|
+
* @param didOrController - DID string or controller address
|
|
275
|
+
* @param pretty - Whether to pretty-print the JSON
|
|
276
|
+
* @returns W3C DID document JSON string
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const json = await didModule.exportW3C(controllerAddress, true)
|
|
281
|
+
* console.log(json)
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
async exportW3C(didOrController, pretty = true) {
|
|
285
|
+
const didDoc = await this.resolve(didOrController);
|
|
286
|
+
if (!didDoc) return null;
|
|
287
|
+
return didDocumentToJson(didDoc, pretty);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get W3C DID document object
|
|
291
|
+
*
|
|
292
|
+
* @param didOrController - DID string or controller address
|
|
293
|
+
* @returns W3C DID document object or null
|
|
294
|
+
*/
|
|
295
|
+
async getW3CDocument(didOrController) {
|
|
296
|
+
const didDoc = await this.resolve(didOrController);
|
|
297
|
+
if (!didDoc) return null;
|
|
298
|
+
return exportAsW3CDidDocument(didDoc);
|
|
299
|
+
}
|
|
300
|
+
// ============================================================================
|
|
301
|
+
// Helper Methods
|
|
302
|
+
// ============================================================================
|
|
303
|
+
/**
|
|
304
|
+
* Derive DID document PDA for a controller
|
|
305
|
+
*
|
|
306
|
+
* @param controller - Controller address
|
|
307
|
+
* @returns DID document PDA and bump
|
|
308
|
+
*/
|
|
309
|
+
async deriveDidPda(controller) {
|
|
310
|
+
return deriveDidDocumentPda(this.programId, controller);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Generate a DID string for a controller
|
|
314
|
+
*
|
|
315
|
+
* @param controller - Controller address
|
|
316
|
+
* @param network - Network identifier
|
|
317
|
+
* @returns DID string
|
|
318
|
+
*/
|
|
319
|
+
generateDid(controller, network = "devnet") {
|
|
320
|
+
return generateDidString(network, controller);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Validate a DID string
|
|
324
|
+
*
|
|
325
|
+
* @param did - DID string to validate
|
|
326
|
+
* @returns True if valid, throws error if invalid
|
|
327
|
+
*/
|
|
328
|
+
validateDid(did) {
|
|
329
|
+
validateDidString(did);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Check if a DID is active
|
|
334
|
+
*
|
|
335
|
+
* @param didOrController - DID string or controller address
|
|
336
|
+
* @returns True if active, false if deactivated or not found
|
|
337
|
+
*/
|
|
338
|
+
async isActive(didOrController) {
|
|
339
|
+
const didDoc = await this.resolve(didOrController);
|
|
340
|
+
if (!didDoc) return false;
|
|
341
|
+
return isDidActive(didDoc);
|
|
342
|
+
}
|
|
343
|
+
// ============================================================================
|
|
344
|
+
// Manual Instruction Builders (until code generation)
|
|
345
|
+
// ============================================================================
|
|
346
|
+
/**
|
|
347
|
+
* Build create DID instruction manually
|
|
348
|
+
* Note: This is temporary until DID instructions are generated from IDL
|
|
349
|
+
*/
|
|
350
|
+
buildCreateDidInstruction(didDocument, controller, didString, verificationMethods, serviceEndpoints) {
|
|
351
|
+
throw new Error(
|
|
352
|
+
"DID instructions are not yet generated. Please run: bun run generate:client after adding DID instructions to the program."
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Build update DID instruction manually
|
|
357
|
+
* Note: This is temporary until DID instructions are generated from IDL
|
|
358
|
+
*/
|
|
359
|
+
buildUpdateDidInstruction(didDocument, controller, addVerificationMethod, removeVerificationMethodId, addServiceEndpoint, removeServiceEndpointId) {
|
|
360
|
+
throw new Error(
|
|
361
|
+
"DID instructions are not yet generated. Please run: bun run generate:client after adding DID instructions to the program."
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Build deactivate DID instruction manually
|
|
366
|
+
* Note: This is temporary until DID instructions are generated from IDL
|
|
367
|
+
*/
|
|
368
|
+
buildDeactivateDidInstruction(didDocument, controller) {
|
|
369
|
+
throw new Error(
|
|
370
|
+
"DID instructions are not yet generated. Please run: bun run generate:client after adding DID instructions to the program."
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
// ============================================================================
|
|
374
|
+
// Exported Helper Functions (re-export for convenience)
|
|
375
|
+
// ============================================================================
|
|
376
|
+
/**
|
|
377
|
+
* Create an Ed25519 verification method
|
|
378
|
+
*/
|
|
379
|
+
static createVerificationMethod = createEd25519VerificationMethod;
|
|
380
|
+
/**
|
|
381
|
+
* Create a service endpoint
|
|
382
|
+
*/
|
|
383
|
+
static createServiceEndpoint = createServiceEndpoint;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/modules/privacy/privacy-helpers.ts
|
|
387
|
+
function calculateVisibleScore(score, privacyMode, hasAccess) {
|
|
388
|
+
if (hasAccess || privacyMode === "Public" /* Public */) {
|
|
389
|
+
return {
|
|
390
|
+
exactScore: score,
|
|
391
|
+
tier: getReputationTier(score),
|
|
392
|
+
scoreRange: getScoreRange(score)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
switch (privacyMode) {
|
|
396
|
+
case "TierOnly" /* TierOnly */:
|
|
397
|
+
return {
|
|
398
|
+
tier: getReputationTier(score)
|
|
399
|
+
};
|
|
400
|
+
case "RangeOnly" /* RangeOnly */:
|
|
401
|
+
return {
|
|
402
|
+
scoreRange: getScoreRange(score)
|
|
403
|
+
};
|
|
404
|
+
case "Confidential" /* Confidential */:
|
|
405
|
+
return {};
|
|
406
|
+
case "Custom" /* Custom */:
|
|
407
|
+
return {
|
|
408
|
+
tier: getReputationTier(score),
|
|
409
|
+
scoreRange: getScoreRange(score)
|
|
410
|
+
};
|
|
411
|
+
default:
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function getReputationTier(score) {
|
|
416
|
+
if (score >= PRIVACY_CONSTANTS.TIER_THRESHOLDS.PLATINUM) {
|
|
417
|
+
return "Platinum" /* Platinum */;
|
|
418
|
+
} else if (score >= PRIVACY_CONSTANTS.TIER_THRESHOLDS.GOLD) {
|
|
419
|
+
return "Gold" /* Gold */;
|
|
420
|
+
} else if (score >= PRIVACY_CONSTANTS.TIER_THRESHOLDS.SILVER) {
|
|
421
|
+
return "Silver" /* Silver */;
|
|
422
|
+
} else if (score >= PRIVACY_CONSTANTS.TIER_THRESHOLDS.BRONZE) {
|
|
423
|
+
return "Bronze" /* Bronze */;
|
|
424
|
+
}
|
|
425
|
+
return "None" /* None */;
|
|
426
|
+
}
|
|
427
|
+
function getScoreRange(score) {
|
|
428
|
+
const ranges = PRIVACY_CONSTANTS.SCORE_RANGES;
|
|
429
|
+
if (score >= ranges.VERY_HIGH.min) {
|
|
430
|
+
return "VeryHigh" /* VeryHigh */;
|
|
431
|
+
} else if (score >= ranges.HIGH.min) {
|
|
432
|
+
return "High" /* High */;
|
|
433
|
+
} else if (score >= ranges.MEDIUM.min) {
|
|
434
|
+
return "Medium" /* Medium */;
|
|
435
|
+
} else if (score >= ranges.LOW.min) {
|
|
436
|
+
return "Low" /* Low */;
|
|
437
|
+
}
|
|
438
|
+
return "VeryLow" /* VeryLow */;
|
|
439
|
+
}
|
|
440
|
+
function canViewerAccess(viewerAddress, settings, agentAddress) {
|
|
441
|
+
if (viewerAddress === agentAddress) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
return settings.authorizedViewers.includes(viewerAddress);
|
|
445
|
+
}
|
|
446
|
+
function filterMetricsByVisibility(reputationData, metricVisibility, hasAccess) {
|
|
447
|
+
const result = {
|
|
448
|
+
agent: reputationData.agent
|
|
449
|
+
};
|
|
450
|
+
const isVisible = (level) => {
|
|
451
|
+
return hasAccess || level === "Public" /* Public */;
|
|
452
|
+
};
|
|
453
|
+
if (isVisible(metricVisibility.showScore)) {
|
|
454
|
+
result.exactScore = reputationData.overallScore;
|
|
455
|
+
}
|
|
456
|
+
if (isVisible(metricVisibility.showJobsCompleted)) {
|
|
457
|
+
result.totalJobsCompleted = reputationData.totalJobsCompleted;
|
|
458
|
+
}
|
|
459
|
+
if (isVisible(metricVisibility.showSuccessRate)) {
|
|
460
|
+
const total = reputationData.totalJobsCompleted + reputationData.totalJobsFailed;
|
|
461
|
+
result.successRate = total > 0 ? reputationData.totalJobsCompleted / total * 100 : 0;
|
|
462
|
+
}
|
|
463
|
+
if (isVisible(metricVisibility.showResponseTime)) {
|
|
464
|
+
result.avgResponseTime = reputationData.avgResponseTime;
|
|
465
|
+
}
|
|
466
|
+
if (isVisible(metricVisibility.showDisputes)) {
|
|
467
|
+
result.disputes = {
|
|
468
|
+
total: reputationData.disputesAgainst,
|
|
469
|
+
resolved: reputationData.disputesResolved
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (isVisible(metricVisibility.showEarnings) && reputationData.totalEarnings !== void 0) {
|
|
473
|
+
result.totalEarnings = reputationData.totalEarnings;
|
|
474
|
+
}
|
|
475
|
+
if (isVisible(metricVisibility.showRatings) && reputationData.avgRating !== void 0) {
|
|
476
|
+
result.avgRating = reputationData.avgRating;
|
|
477
|
+
}
|
|
478
|
+
if (isVisible(metricVisibility.showBadges) && reputationData.badges !== void 0) {
|
|
479
|
+
result.badges = reputationData.badges;
|
|
480
|
+
}
|
|
481
|
+
result.hasFullAccess = hasAccess;
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
484
|
+
function getDefaultMetricVisibility(mode) {
|
|
485
|
+
switch (mode) {
|
|
486
|
+
case "Public" /* Public */:
|
|
487
|
+
return {
|
|
488
|
+
showScore: "Public" /* Public */,
|
|
489
|
+
showJobsCompleted: "Public" /* Public */,
|
|
490
|
+
showSuccessRate: "Public" /* Public */,
|
|
491
|
+
showResponseTime: "Public" /* Public */,
|
|
492
|
+
showDisputes: "Public" /* Public */,
|
|
493
|
+
showEarnings: "Public" /* Public */,
|
|
494
|
+
showRatings: "Public" /* Public */,
|
|
495
|
+
showBadges: "Public" /* Public */
|
|
496
|
+
};
|
|
497
|
+
case "TierOnly" /* TierOnly */:
|
|
498
|
+
case "RangeOnly" /* RangeOnly */:
|
|
499
|
+
return {
|
|
500
|
+
showScore: "Private" /* Private */,
|
|
501
|
+
showJobsCompleted: "Private" /* Private */,
|
|
502
|
+
showSuccessRate: "Private" /* Private */,
|
|
503
|
+
showResponseTime: "Private" /* Private */,
|
|
504
|
+
showDisputes: "Private" /* Private */,
|
|
505
|
+
showEarnings: "Private" /* Private */,
|
|
506
|
+
showRatings: "Private" /* Private */,
|
|
507
|
+
showBadges: "Public" /* Public */
|
|
508
|
+
};
|
|
509
|
+
case "Confidential" /* Confidential */:
|
|
510
|
+
return {
|
|
511
|
+
showScore: "ZKProof" /* ZKProof */,
|
|
512
|
+
showJobsCompleted: "ZKProof" /* ZKProof */,
|
|
513
|
+
showSuccessRate: "ZKProof" /* ZKProof */,
|
|
514
|
+
showResponseTime: "ZKProof" /* ZKProof */,
|
|
515
|
+
showDisputes: "ZKProof" /* ZKProof */,
|
|
516
|
+
showEarnings: "ZKProof" /* ZKProof */,
|
|
517
|
+
showRatings: "ZKProof" /* ZKProof */,
|
|
518
|
+
showBadges: "ZKProof" /* ZKProof */
|
|
519
|
+
};
|
|
520
|
+
case "Custom" /* Custom */:
|
|
521
|
+
default:
|
|
522
|
+
return {
|
|
523
|
+
showScore: "Private" /* Private */,
|
|
524
|
+
showJobsCompleted: "Public" /* Public */,
|
|
525
|
+
showSuccessRate: "Public" /* Public */,
|
|
526
|
+
showResponseTime: "Public" /* Public */,
|
|
527
|
+
showDisputes: "Private" /* Private */,
|
|
528
|
+
showEarnings: "Private" /* Private */,
|
|
529
|
+
showRatings: "Public" /* Public */,
|
|
530
|
+
showBadges: "Public" /* Public */
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function validatePrivacySettings(settings) {
|
|
535
|
+
const errors = [];
|
|
536
|
+
if (settings.authorizedViewers.length > PRIVACY_CONSTANTS.MAX_AUTHORIZED_VIEWERS) {
|
|
537
|
+
errors.push(
|
|
538
|
+
`Too many authorized viewers (max: ${PRIVACY_CONSTANTS.MAX_AUTHORIZED_VIEWERS})`
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
if (settings.mode === "Public" /* Public */) {
|
|
542
|
+
const hasPrivateMetric = Object.values(settings.metricVisibility).some(
|
|
543
|
+
(level) => level !== "Public" /* Public */
|
|
544
|
+
);
|
|
545
|
+
if (hasPrivateMetric) {
|
|
546
|
+
errors.push("Public mode cannot have private metrics");
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return {
|
|
550
|
+
valid: errors.length === 0,
|
|
551
|
+
errors
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function getTierDisplayName(tier) {
|
|
555
|
+
const names = {
|
|
556
|
+
["None" /* None */]: "Unranked",
|
|
557
|
+
["Bronze" /* Bronze */]: "Bronze",
|
|
558
|
+
["Silver" /* Silver */]: "Silver",
|
|
559
|
+
["Gold" /* Gold */]: "Gold",
|
|
560
|
+
["Platinum" /* Platinum */]: "Platinum"
|
|
561
|
+
};
|
|
562
|
+
return names[tier];
|
|
563
|
+
}
|
|
564
|
+
function getRangeDisplayString(range) {
|
|
565
|
+
const ranges = {
|
|
566
|
+
["VeryLow" /* VeryLow */]: "0-2000",
|
|
567
|
+
["Low" /* Low */]: "2000-5000",
|
|
568
|
+
["Medium" /* Medium */]: "5000-7500",
|
|
569
|
+
["High" /* High */]: "7500-9000",
|
|
570
|
+
["VeryHigh" /* VeryHigh */]: "9000-10000"
|
|
571
|
+
};
|
|
572
|
+
return ranges[range];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/modules/privacy/PrivacyModule.ts
|
|
576
|
+
var PrivacyModule = class extends BaseModule {
|
|
577
|
+
constructor(config) {
|
|
578
|
+
super(config);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Initialize privacy settings for an agent
|
|
582
|
+
*
|
|
583
|
+
* Sets up privacy controls for an agent's reputation data.
|
|
584
|
+
* By default, starts in Public mode with all metrics visible.
|
|
585
|
+
*
|
|
586
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
587
|
+
* @param params - Initialization parameters
|
|
588
|
+
* @returns Transaction signature
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* const signature = await privacyModule.initializePrivacy(signer, {
|
|
593
|
+
* agentAddress: agentPda,
|
|
594
|
+
* mode: PrivacyMode.TierOnly,
|
|
595
|
+
* metricVisibility: {
|
|
596
|
+
* showScore: VisibilityLevel.Private,
|
|
597
|
+
* showJobsCompleted: VisibilityLevel.Public,
|
|
598
|
+
* // ... other metrics
|
|
599
|
+
* }
|
|
600
|
+
* })
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
async initializePrivacy(signer, params) {
|
|
604
|
+
const mode = params.mode ?? "Public" /* Public */;
|
|
605
|
+
params.metricVisibility ?? getDefaultMetricVisibility(mode);
|
|
606
|
+
const instructionGetter = async () => {
|
|
607
|
+
return {
|
|
608
|
+
programAddress: this.programId,
|
|
609
|
+
accounts: [],
|
|
610
|
+
data: new Uint8Array([0])
|
|
611
|
+
// Placeholder
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
return this.execute(
|
|
615
|
+
"initializePrivacy",
|
|
616
|
+
instructionGetter,
|
|
617
|
+
[signer]
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Update privacy mode for an agent
|
|
622
|
+
*
|
|
623
|
+
* Changes how reputation data is displayed publicly.
|
|
624
|
+
*
|
|
625
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
626
|
+
* @param params - Update parameters
|
|
627
|
+
* @returns Transaction signature
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```typescript
|
|
631
|
+
* // Switch to tier-only mode
|
|
632
|
+
* await privacyModule.updatePrivacyMode(signer, {
|
|
633
|
+
* agentAddress: agentPda,
|
|
634
|
+
* mode: PrivacyMode.TierOnly
|
|
635
|
+
* })
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
async updatePrivacyMode(signer, params) {
|
|
639
|
+
const instructionGetter = async () => {
|
|
640
|
+
return {
|
|
641
|
+
programAddress: this.programId,
|
|
642
|
+
accounts: [],
|
|
643
|
+
data: new Uint8Array([1])
|
|
644
|
+
// Placeholder
|
|
645
|
+
};
|
|
646
|
+
};
|
|
647
|
+
return this.execute(
|
|
648
|
+
"updatePrivacyMode",
|
|
649
|
+
instructionGetter,
|
|
650
|
+
[signer]
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Set metric visibility settings
|
|
655
|
+
*
|
|
656
|
+
* Configure selective disclosure for individual metrics.
|
|
657
|
+
* Only works in Custom privacy mode.
|
|
658
|
+
*
|
|
659
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
660
|
+
* @param params - Metric visibility parameters
|
|
661
|
+
* @returns Transaction signature
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* await privacyModule.setMetricVisibility(signer, {
|
|
666
|
+
* agentAddress: agentPda,
|
|
667
|
+
* metricVisibility: {
|
|
668
|
+
* showScore: VisibilityLevel.Private,
|
|
669
|
+
* showJobsCompleted: VisibilityLevel.Public,
|
|
670
|
+
* showSuccessRate: VisibilityLevel.Public,
|
|
671
|
+
* showResponseTime: VisibilityLevel.Public,
|
|
672
|
+
* showDisputes: VisibilityLevel.Private,
|
|
673
|
+
* showEarnings: VisibilityLevel.Private,
|
|
674
|
+
* showRatings: VisibilityLevel.Public,
|
|
675
|
+
* showBadges: VisibilityLevel.Public
|
|
676
|
+
* }
|
|
677
|
+
* })
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
async setMetricVisibility(signer, params) {
|
|
681
|
+
const instructionGetter = async () => {
|
|
682
|
+
return {
|
|
683
|
+
programAddress: this.programId,
|
|
684
|
+
accounts: [],
|
|
685
|
+
data: new Uint8Array([2])
|
|
686
|
+
// Placeholder
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
return this.execute(
|
|
690
|
+
"setMetricVisibility",
|
|
691
|
+
instructionGetter,
|
|
692
|
+
[signer]
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Grant viewer access to private reputation data
|
|
697
|
+
*
|
|
698
|
+
* Adds an address to the authorized viewers list, giving them
|
|
699
|
+
* full access to all private metrics.
|
|
700
|
+
*
|
|
701
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
702
|
+
* @param params - Grant access parameters
|
|
703
|
+
* @returns Transaction signature
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```typescript
|
|
707
|
+
* // Grant access to a client
|
|
708
|
+
* await privacyModule.grantAccess(signer, {
|
|
709
|
+
* agentAddress: agentPda,
|
|
710
|
+
* viewer: clientAddress
|
|
711
|
+
* })
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
async grantAccess(signer, params) {
|
|
715
|
+
const instructionGetter = async () => {
|
|
716
|
+
return {
|
|
717
|
+
programAddress: this.programId,
|
|
718
|
+
accounts: [],
|
|
719
|
+
data: new Uint8Array([3])
|
|
720
|
+
// Placeholder
|
|
721
|
+
};
|
|
722
|
+
};
|
|
723
|
+
return this.execute(
|
|
724
|
+
"grantAccess",
|
|
725
|
+
instructionGetter,
|
|
726
|
+
[signer]
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Revoke viewer access to private reputation data
|
|
731
|
+
*
|
|
732
|
+
* Removes an address from the authorized viewers list.
|
|
733
|
+
*
|
|
734
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
735
|
+
* @param params - Revoke access parameters
|
|
736
|
+
* @returns Transaction signature
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```typescript
|
|
740
|
+
* // Revoke access from a viewer
|
|
741
|
+
* await privacyModule.revokeAccess(signer, {
|
|
742
|
+
* agentAddress: agentPda,
|
|
743
|
+
* viewer: viewerAddress
|
|
744
|
+
* })
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
async revokeAccess(signer, params) {
|
|
748
|
+
const instructionGetter = async () => {
|
|
749
|
+
return {
|
|
750
|
+
programAddress: this.programId,
|
|
751
|
+
accounts: [],
|
|
752
|
+
data: new Uint8Array([4])
|
|
753
|
+
// Placeholder
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
return this.execute(
|
|
757
|
+
"revokeAccess",
|
|
758
|
+
instructionGetter,
|
|
759
|
+
[signer]
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Apply a privacy preset
|
|
764
|
+
*
|
|
765
|
+
* Quickly configure privacy settings using a predefined preset
|
|
766
|
+
* (Conservative, Balanced, or Open).
|
|
767
|
+
*
|
|
768
|
+
* @param signer - Transaction signer (must be agent owner)
|
|
769
|
+
* @param params - Preset parameters
|
|
770
|
+
* @returns Transaction signature
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* // Apply balanced preset
|
|
775
|
+
* await privacyModule.applyPreset(signer, {
|
|
776
|
+
* agentAddress: agentPda,
|
|
777
|
+
* preset: PrivacyPresets.BALANCED
|
|
778
|
+
* })
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
async applyPreset(signer, params) {
|
|
782
|
+
const { preset } = params;
|
|
783
|
+
await this.updatePrivacyMode(signer, {
|
|
784
|
+
agentAddress: params.agentAddress,
|
|
785
|
+
mode: preset.mode
|
|
786
|
+
});
|
|
787
|
+
return this.setMetricVisibility(signer, {
|
|
788
|
+
agentAddress: params.agentAddress,
|
|
789
|
+
metricVisibility: preset.metricVisibility
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Get privacy settings for an agent
|
|
794
|
+
*
|
|
795
|
+
* Fetches the current privacy configuration.
|
|
796
|
+
*
|
|
797
|
+
* @param agentAddress - Agent address
|
|
798
|
+
* @returns Privacy settings or null if not initialized
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```typescript
|
|
802
|
+
* const settings = await privacyModule.getPrivacySettings(agentPda)
|
|
803
|
+
* if (settings) {
|
|
804
|
+
* console.log('Privacy mode:', settings.mode)
|
|
805
|
+
* console.log('Authorized viewers:', settings.authorizedViewers.length)
|
|
806
|
+
* }
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
async getPrivacySettings(agentAddress) {
|
|
810
|
+
return {
|
|
811
|
+
agent: agentAddress,
|
|
812
|
+
mode: "Public" /* Public */,
|
|
813
|
+
metricVisibility: getDefaultMetricVisibility("Public" /* Public */),
|
|
814
|
+
authorizedViewers: [],
|
|
815
|
+
autoGrantClients: false,
|
|
816
|
+
updatedAt: Math.floor(Date.now() / 1e3)
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Get visible reputation data (privacy-filtered)
|
|
821
|
+
*
|
|
822
|
+
* Fetches reputation data and applies privacy filters based on
|
|
823
|
+
* the viewer's access level.
|
|
824
|
+
*
|
|
825
|
+
* @param agentAddress - Agent address
|
|
826
|
+
* @param viewerAddress - Viewer address (for access check)
|
|
827
|
+
* @returns Privacy-filtered reputation data
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```typescript
|
|
831
|
+
* // Get visible reputation for a specific viewer
|
|
832
|
+
* const visibleRep = await privacyModule.getVisibleReputation(
|
|
833
|
+
* agentPda,
|
|
834
|
+
* viewerAddress
|
|
835
|
+
* )
|
|
836
|
+
*
|
|
837
|
+
* console.log('Tier:', visibleRep.tier)
|
|
838
|
+
* console.log('Exact score:', visibleRep.exactScore) // Only if visible
|
|
839
|
+
* console.log('Has full access:', visibleRep.hasFullAccess)
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
async getVisibleReputation(agentAddress, viewerAddress) {
|
|
843
|
+
let privacySettings = await this.getPrivacySettings(agentAddress);
|
|
844
|
+
if (!privacySettings) {
|
|
845
|
+
privacySettings = {
|
|
846
|
+
agent: agentAddress,
|
|
847
|
+
mode: "Public" /* Public */,
|
|
848
|
+
metricVisibility: getDefaultMetricVisibility("Public" /* Public */),
|
|
849
|
+
authorizedViewers: [],
|
|
850
|
+
autoGrantClients: false,
|
|
851
|
+
updatedAt: Math.floor(Date.now() / 1e3)
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
const hasAccess = canViewerAccess(viewerAddress, privacySettings, agentAddress);
|
|
855
|
+
const reputationData = {
|
|
856
|
+
agent: agentAddress,
|
|
857
|
+
overallScore: 7500,
|
|
858
|
+
// Mock data
|
|
859
|
+
totalJobsCompleted: 100,
|
|
860
|
+
totalJobsFailed: 5,
|
|
861
|
+
avgResponseTime: 250,
|
|
862
|
+
disputesAgainst: 2,
|
|
863
|
+
disputesResolved: 2,
|
|
864
|
+
totalEarnings: 5e4,
|
|
865
|
+
avgRating: 4.5,
|
|
866
|
+
badges: ["FirstJob", "TenJobs", "QuickResponder"]
|
|
867
|
+
};
|
|
868
|
+
const visibleScore = calculateVisibleScore(
|
|
869
|
+
reputationData.overallScore,
|
|
870
|
+
privacySettings.mode,
|
|
871
|
+
hasAccess
|
|
872
|
+
);
|
|
873
|
+
const filteredMetrics = filterMetricsByVisibility(
|
|
874
|
+
reputationData,
|
|
875
|
+
privacySettings.metricVisibility,
|
|
876
|
+
hasAccess
|
|
877
|
+
);
|
|
878
|
+
return {
|
|
879
|
+
...filteredMetrics,
|
|
880
|
+
privacyMode: privacySettings.mode,
|
|
881
|
+
...visibleScore,
|
|
882
|
+
hasFullAccess: hasAccess
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
// =====================================================
|
|
886
|
+
// HELPER METHODS
|
|
887
|
+
// =====================================================
|
|
888
|
+
/**
|
|
889
|
+
* Validate privacy settings before applying
|
|
890
|
+
*
|
|
891
|
+
* @param settings - Privacy settings to validate
|
|
892
|
+
* @returns Validation result
|
|
893
|
+
*/
|
|
894
|
+
validateSettings(settings) {
|
|
895
|
+
return validatePrivacySettings(settings);
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Get available privacy presets
|
|
899
|
+
*
|
|
900
|
+
* @returns Record of available presets
|
|
901
|
+
*/
|
|
902
|
+
getAvailablePresets() {
|
|
903
|
+
return PrivacyPresets;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Get default metric visibility for a privacy mode
|
|
907
|
+
*
|
|
908
|
+
* @param mode - Privacy mode
|
|
909
|
+
* @returns Default metric visibility
|
|
910
|
+
*/
|
|
911
|
+
getDefaultVisibility(mode) {
|
|
912
|
+
return getDefaultMetricVisibility(mode);
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Calculate reputation tier from score
|
|
916
|
+
*
|
|
917
|
+
* @param score - Reputation score
|
|
918
|
+
* @returns Reputation tier
|
|
919
|
+
*/
|
|
920
|
+
getTier(score) {
|
|
921
|
+
return getReputationTier(score);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Calculate score range from score
|
|
925
|
+
*
|
|
926
|
+
* @param score - Reputation score
|
|
927
|
+
* @returns Score range
|
|
928
|
+
*/
|
|
929
|
+
getRange(score) {
|
|
930
|
+
return getScoreRange(score);
|
|
931
|
+
}
|
|
932
|
+
// Private helper to derive privacy PDA (when privacy accounts are implemented)
|
|
933
|
+
async derivePrivacyPda(agentAddress) {
|
|
934
|
+
const { getProgramDerivedAddress, getAddressEncoder } = await import('@solana/addresses');
|
|
935
|
+
const addressEncoder = getAddressEncoder();
|
|
936
|
+
const agentBytes = addressEncoder.encode(agentAddress);
|
|
937
|
+
const [pda] = await getProgramDerivedAddress({
|
|
938
|
+
programAddress: this.programId,
|
|
939
|
+
seeds: [
|
|
940
|
+
new TextEncoder().encode("privacy_settings"),
|
|
941
|
+
agentBytes
|
|
942
|
+
]
|
|
943
|
+
});
|
|
944
|
+
return pda;
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
// src/modules/authorization/AuthorizationModule.ts
|
|
949
|
+
var DEFAULT_STORAGE_FEE = 2000000n;
|
|
950
|
+
var AuthorizationModule = class extends BaseModule {
|
|
951
|
+
constructor(config) {
|
|
952
|
+
super(config);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Create a signed authorization for a facilitator
|
|
956
|
+
*
|
|
957
|
+
* @param params - Authorization parameters
|
|
958
|
+
* @param agentKeypair - Agent's keypair for signing
|
|
959
|
+
* @returns Signed authorization
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* ```typescript
|
|
963
|
+
* const authorization = await client.authorization.createAuthorization({
|
|
964
|
+
* authorizedSource: payAIFacilitatorAddress,
|
|
965
|
+
* indexLimit: 1000, // Allow 1000 reputation updates
|
|
966
|
+
* expiresIn: 30 * 24 * 60 * 60, // 30 days
|
|
967
|
+
* network: 'devnet',
|
|
968
|
+
* }, agentKeypair)
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
async createAuthorization(params, agentKeypair) {
|
|
972
|
+
return await createSignedAuthorization(params, agentKeypair);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Store authorization on-chain (optional, ~0.002 SOL fee)
|
|
976
|
+
*
|
|
977
|
+
* Creates a PDA account storing the authorization for on-chain verification.
|
|
978
|
+
* This provides an immutable audit trail but costs rent (~0.002 SOL).
|
|
979
|
+
*
|
|
980
|
+
* **Cost vs Benefit:**
|
|
981
|
+
* - Off-chain (default): Free, but requires sharing signed authorization
|
|
982
|
+
* - On-chain: ~0.002 SOL, provides transparent audit trail
|
|
983
|
+
*
|
|
984
|
+
* **When to use on-chain storage:**
|
|
985
|
+
* - High-value authorizations where transparency is critical
|
|
986
|
+
* - Compliance/audit requirements
|
|
987
|
+
* - Public agent reputation systems
|
|
988
|
+
*
|
|
989
|
+
* @param authorization - Authorization to store
|
|
990
|
+
* @param agentSigner - Agent's signer (or facilitator if they pay fee)
|
|
991
|
+
* @param config - Optional storage configuration
|
|
992
|
+
* @returns Transaction signature
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* // Default: Agent pays ~0.002 SOL
|
|
997
|
+
* const sig = await client.authorization.storeAuthorizationOnChain(auth, agentSigner)
|
|
998
|
+
*
|
|
999
|
+
* // Custom fee structure
|
|
1000
|
+
* const sig = await client.authorization.storeAuthorizationOnChain(auth, agentSigner, {
|
|
1001
|
+
* storageFee: 1500000n, // 0.0015 SOL
|
|
1002
|
+
* feePayedByAgent: false // Facilitator pays
|
|
1003
|
+
* })
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
async storeAuthorizationOnChain(authorization, agentSigner, config) {
|
|
1007
|
+
const storageFee = this.calculateStorageFee(authorization, config);
|
|
1008
|
+
const feePayedByAgent = config?.feePayedByAgent ?? true;
|
|
1009
|
+
console.log(`\u{1F4B0} On-chain storage cost: ${Number(storageFee) / 1e9} SOL`);
|
|
1010
|
+
console.log(` Fee payer: ${feePayedByAgent ? "Agent" : "Facilitator"}`);
|
|
1011
|
+
const { getCreateAgentAuthorizationInstructionAsync } = await import('./createAgentAuthorization-KGZNXZBT.js');
|
|
1012
|
+
const { getProgramDerivedAddress, getBytesEncoder, getAddressEncoder, getUtf8Encoder } = await import('@solana/kit');
|
|
1013
|
+
const nonce = authorization.nonce ?? "default";
|
|
1014
|
+
const [authorizationPda] = await getProgramDerivedAddress({
|
|
1015
|
+
programAddress: this.getProgramId(),
|
|
1016
|
+
seeds: [
|
|
1017
|
+
getBytesEncoder().encode(new Uint8Array([97, 103, 101, 110, 116, 95, 97, 117, 116, 104])),
|
|
1018
|
+
// 'agent_auth'
|
|
1019
|
+
getAddressEncoder().encode(authorization.agentAddress),
|
|
1020
|
+
getAddressEncoder().encode(authorization.authorizedSource),
|
|
1021
|
+
getUtf8Encoder().encode(nonce)
|
|
1022
|
+
// Raw bytes, no size prefix - matches Rust .as_bytes()
|
|
1023
|
+
]
|
|
1024
|
+
});
|
|
1025
|
+
return await this.execute(
|
|
1026
|
+
"createAgentAuthorization",
|
|
1027
|
+
async () => {
|
|
1028
|
+
return await getCreateAgentAuthorizationInstructionAsync({
|
|
1029
|
+
agent: authorization.agentAddress,
|
|
1030
|
+
authorization: authorizationPda,
|
|
1031
|
+
// Provide manually derived PDA
|
|
1032
|
+
authority: agentSigner,
|
|
1033
|
+
authorizedSource: authorization.authorizedSource,
|
|
1034
|
+
indexLimit: BigInt(authorization.indexLimit),
|
|
1035
|
+
expiresAt: BigInt(authorization.expiresAt),
|
|
1036
|
+
network: authorization.network === "mainnet-beta" ? 0 : authorization.network === "devnet" ? 1 : 2,
|
|
1037
|
+
signature: authorization.signature,
|
|
1038
|
+
nonce
|
|
1039
|
+
// Pass the actual nonce value
|
|
1040
|
+
});
|
|
1041
|
+
},
|
|
1042
|
+
[agentSigner]
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Verify authorization signature
|
|
1047
|
+
*
|
|
1048
|
+
* @param authorization - Authorization to verify
|
|
1049
|
+
* @returns True if signature is valid
|
|
1050
|
+
*
|
|
1051
|
+
* @example
|
|
1052
|
+
* ```typescript
|
|
1053
|
+
* const isValid = await client.authorization.verifySignature(authorization)
|
|
1054
|
+
* if (!isValid) {
|
|
1055
|
+
* throw new Error('Invalid authorization signature')
|
|
1056
|
+
* }
|
|
1057
|
+
* ```
|
|
1058
|
+
*/
|
|
1059
|
+
async verifySignature(authorization) {
|
|
1060
|
+
return verifyAuthorizationSignature(authorization);
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Check authorization status (without on-chain call)
|
|
1064
|
+
*
|
|
1065
|
+
* @param authorization - Authorization to check
|
|
1066
|
+
* @param currentIndex - Current usage count (optional, defaults to authorization.currentIndex)
|
|
1067
|
+
* @returns Authorization status
|
|
1068
|
+
*/
|
|
1069
|
+
getAuthorizationStatus(authorization, currentIndex) {
|
|
1070
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1071
|
+
const idx = currentIndex ?? 0;
|
|
1072
|
+
if (isAuthorizationExpired(authorization, now)) {
|
|
1073
|
+
return {
|
|
1074
|
+
status: "expired",
|
|
1075
|
+
isValid: false,
|
|
1076
|
+
remainingUses: 0,
|
|
1077
|
+
reason: "Authorization has expired"
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
if (isAuthorizationExhausted(authorization, idx)) {
|
|
1081
|
+
return {
|
|
1082
|
+
status: "exhausted",
|
|
1083
|
+
isValid: false,
|
|
1084
|
+
remainingUses: 0,
|
|
1085
|
+
reason: "Index limit reached"
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
const remaining = authorization.indexLimit - idx;
|
|
1089
|
+
return {
|
|
1090
|
+
status: "active",
|
|
1091
|
+
isValid: true,
|
|
1092
|
+
remainingUses: remaining
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Fetch authorization from on-chain PDA
|
|
1097
|
+
*
|
|
1098
|
+
* @param agentAddress - Agent's address
|
|
1099
|
+
* @param authorizedSource - Authorized source address
|
|
1100
|
+
* @param nonce - Optional nonce (must match creation)
|
|
1101
|
+
* @returns Authorization with current on-chain status
|
|
1102
|
+
*/
|
|
1103
|
+
async fetchAuthorization(agentAddress, authorizedSource, nonce) {
|
|
1104
|
+
throw new Error("On-chain fetch not yet implemented - pending Codama generation");
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Update reputation using authorization
|
|
1108
|
+
*
|
|
1109
|
+
* Called by facilitators (e.g., PayAI) to update agent reputation
|
|
1110
|
+
* using a pre-signed authorization.
|
|
1111
|
+
*
|
|
1112
|
+
* @param authorization - Authorization to use
|
|
1113
|
+
* @param reputationChange - Reputation change to apply
|
|
1114
|
+
* @param transactionSignature - Transaction signature for audit trail
|
|
1115
|
+
* @param usageRecord - PDA for usage record (audit trail)
|
|
1116
|
+
* @param metadata - Optional metadata
|
|
1117
|
+
* @param facilitatorSigner - Facilitator's signer
|
|
1118
|
+
* @returns Transaction signature
|
|
1119
|
+
*/
|
|
1120
|
+
async updateReputationWithAuth(authorization, reputationChange, transactionSignature, usageRecord, metadata, facilitatorSigner) {
|
|
1121
|
+
const isValid = await this.verifySignature(authorization);
|
|
1122
|
+
if (!isValid) {
|
|
1123
|
+
throw new Error("Invalid authorization signature");
|
|
1124
|
+
}
|
|
1125
|
+
const status = this.getAuthorizationStatus(authorization);
|
|
1126
|
+
if (!status.isValid) {
|
|
1127
|
+
throw new Error(`Authorization is ${status.status}: ${status.reason}`);
|
|
1128
|
+
}
|
|
1129
|
+
const { getUpdateReputationWithAuthInstructionAsync } = await import('./updateReputationWithAuth-PCEUOCFV.js');
|
|
1130
|
+
return await this.execute(
|
|
1131
|
+
"updateReputationWithAuth",
|
|
1132
|
+
async () => {
|
|
1133
|
+
return await getUpdateReputationWithAuthInstructionAsync({
|
|
1134
|
+
agent: authorization.agentAddress,
|
|
1135
|
+
authorizedSource: facilitatorSigner,
|
|
1136
|
+
usageRecord,
|
|
1137
|
+
reputationChange: BigInt(reputationChange),
|
|
1138
|
+
transactionSignature,
|
|
1139
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
1140
|
+
nonce: authorization.nonce ?? null
|
|
1141
|
+
});
|
|
1142
|
+
},
|
|
1143
|
+
[facilitatorSigner]
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Revoke authorization
|
|
1148
|
+
*
|
|
1149
|
+
* Agent can revoke an authorization before it expires or is exhausted.
|
|
1150
|
+
*
|
|
1151
|
+
* @param agentAddress - Agent's address
|
|
1152
|
+
* @param authorization - Authorization account PDA
|
|
1153
|
+
* @param nonce - Optional nonce (must match creation)
|
|
1154
|
+
* @param agentSigner - Agent's signer
|
|
1155
|
+
* @returns Transaction signature
|
|
1156
|
+
*/
|
|
1157
|
+
async revokeAuthorization(agentAddress, authorization, nonce, agentSigner) {
|
|
1158
|
+
const { getRevokeAuthorizationInstruction } = await import('./revokeAuthorization-2ZRO6GUZ.js');
|
|
1159
|
+
return await this.execute(
|
|
1160
|
+
"revokeAuthorization",
|
|
1161
|
+
() => {
|
|
1162
|
+
return getRevokeAuthorizationInstruction({
|
|
1163
|
+
agent: agentAddress,
|
|
1164
|
+
authorization,
|
|
1165
|
+
authority: agentSigner,
|
|
1166
|
+
nonce: nonce ?? null
|
|
1167
|
+
});
|
|
1168
|
+
},
|
|
1169
|
+
[agentSigner]
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* List authorizations for an agent (filtering)
|
|
1174
|
+
*
|
|
1175
|
+
* @param filter - Filter criteria
|
|
1176
|
+
* @returns List of authorizations
|
|
1177
|
+
*/
|
|
1178
|
+
async listAuthorizations(filter) {
|
|
1179
|
+
throw new Error("Authorization listing not yet implemented - pending Codama generation");
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Serialize authorization for storage/transmission
|
|
1183
|
+
*
|
|
1184
|
+
* @param authorization - Authorization to serialize
|
|
1185
|
+
* @returns JSON-safe object
|
|
1186
|
+
*/
|
|
1187
|
+
serializeAuthorization(authorization) {
|
|
1188
|
+
return serializeAuthorization(authorization);
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Deserialize authorization from storage/transmission
|
|
1192
|
+
*
|
|
1193
|
+
* @param data - Serialized authorization data
|
|
1194
|
+
* @returns Authorization object
|
|
1195
|
+
*/
|
|
1196
|
+
deserializeAuthorization(data) {
|
|
1197
|
+
return deserializeAuthorization(data);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Get authorization ID (deterministic hash)
|
|
1201
|
+
*
|
|
1202
|
+
* @param authorization - Authorization to hash
|
|
1203
|
+
* @returns Base58-encoded hash
|
|
1204
|
+
*/
|
|
1205
|
+
async getAuthorizationId(authorization) {
|
|
1206
|
+
return getAuthorizationId(authorization);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Helper: Create authorization for PayAI facilitator
|
|
1210
|
+
*
|
|
1211
|
+
* Convenience method with sensible defaults for PayAI integration.
|
|
1212
|
+
*
|
|
1213
|
+
* @param payAIFacilitatorAddress - PayAI facilitator address
|
|
1214
|
+
* @param agentKeypair - Agent's keypair
|
|
1215
|
+
* @param options - Optional overrides
|
|
1216
|
+
* @returns Signed authorization
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```typescript
|
|
1220
|
+
* const auth = await client.authorization.createPayAIAuthorization(
|
|
1221
|
+
* 'PayAI...FacilitatorAddress',
|
|
1222
|
+
* agentKeypair,
|
|
1223
|
+
* { indexLimit: 5000 } // Optional overrides
|
|
1224
|
+
* )
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
async createPayAIAuthorization(payAIFacilitatorAddress, agentKeypair, options) {
|
|
1228
|
+
const defaultParams = {
|
|
1229
|
+
authorizedSource: payAIFacilitatorAddress,
|
|
1230
|
+
indexLimit: 1e3,
|
|
1231
|
+
// 1000 reputation updates
|
|
1232
|
+
expiresIn: 30 * 24 * 60 * 60,
|
|
1233
|
+
// 30 days
|
|
1234
|
+
network: "devnet",
|
|
1235
|
+
// TODO: detect from client
|
|
1236
|
+
...options
|
|
1237
|
+
};
|
|
1238
|
+
return this.createAuthorization(defaultParams, agentKeypair);
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Calculate storage fee based on authorization duration and custom fees
|
|
1242
|
+
*
|
|
1243
|
+
* @param authorization - Authorization to calculate fee for
|
|
1244
|
+
* @param config - Storage configuration
|
|
1245
|
+
* @returns Fee in lamports
|
|
1246
|
+
*
|
|
1247
|
+
* @example
|
|
1248
|
+
* ```typescript
|
|
1249
|
+
* // Default fee: 0.002 SOL
|
|
1250
|
+
* const fee = module.calculateStorageFee(auth)
|
|
1251
|
+
*
|
|
1252
|
+
* // Custom fee for 30-day authorizations: 0.001 SOL
|
|
1253
|
+
* const fee = module.calculateStorageFee(auth, {
|
|
1254
|
+
* customFees: { 2592000: 1000000n } // 30 days = 0.001 SOL
|
|
1255
|
+
* })
|
|
1256
|
+
* ```
|
|
1257
|
+
*/
|
|
1258
|
+
calculateStorageFee(authorization, config) {
|
|
1259
|
+
if (config?.storageFee !== void 0) {
|
|
1260
|
+
return config.storageFee;
|
|
1261
|
+
}
|
|
1262
|
+
if (config?.customFees) {
|
|
1263
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1264
|
+
const duration = authorization.expiresAt - now;
|
|
1265
|
+
const durations = Object.keys(config.customFees).map(Number).sort((a, b) => a - b);
|
|
1266
|
+
for (const d of durations) {
|
|
1267
|
+
if (duration <= d) {
|
|
1268
|
+
return config.customFees[d];
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
const highestDuration = durations[durations.length - 1];
|
|
1272
|
+
if (highestDuration && config.customFees[highestDuration]) {
|
|
1273
|
+
return config.customFees[highestDuration];
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return DEFAULT_STORAGE_FEE;
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Estimate on-chain storage cost for an authorization
|
|
1280
|
+
*
|
|
1281
|
+
* @param params - Authorization parameters
|
|
1282
|
+
* @param config - Optional storage configuration
|
|
1283
|
+
* @returns Estimated cost in SOL
|
|
1284
|
+
*
|
|
1285
|
+
* @example
|
|
1286
|
+
* ```typescript
|
|
1287
|
+
* const costInSOL = await client.authorization.estimateStorageCost({
|
|
1288
|
+
* authorizedSource: facilitatorAddress,
|
|
1289
|
+
* expiresIn: 30 * 24 * 60 * 60 // 30 days
|
|
1290
|
+
* })
|
|
1291
|
+
* console.log(`On-chain storage will cost ${costInSOL} SOL`)
|
|
1292
|
+
* ```
|
|
1293
|
+
*/
|
|
1294
|
+
async estimateStorageCost(params, config) {
|
|
1295
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1296
|
+
const mockAuth = {
|
|
1297
|
+
agentAddress: "11111111111111111111111111111111",
|
|
1298
|
+
// Placeholder
|
|
1299
|
+
authorizedSource: params.authorizedSource,
|
|
1300
|
+
indexLimit: params.indexLimit ?? 1e3,
|
|
1301
|
+
expiresAt: params.expiresAt ?? now + (params.expiresIn ?? 30 * 24 * 60 * 60),
|
|
1302
|
+
network: params.network ?? "devnet",
|
|
1303
|
+
signature: new Uint8Array(64),
|
|
1304
|
+
nonce: params.nonce
|
|
1305
|
+
};
|
|
1306
|
+
const feeInLamports = this.calculateStorageFee(mockAuth, config);
|
|
1307
|
+
return Number(feeInLamports) / 1e9;
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
// src/core/GhostSpeakClient.ts
|
|
1312
|
+
var GhostSpeakClient = class {
|
|
1313
|
+
config;
|
|
1314
|
+
constructor(config) {
|
|
1315
|
+
this.config = {
|
|
1316
|
+
programId: GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS,
|
|
1317
|
+
commitment: "confirmed",
|
|
1318
|
+
cluster: "devnet",
|
|
1319
|
+
rpcEndpoint: config?.rpcEndpoint ?? this.getDefaultRpcEndpoint(config?.cluster ?? "devnet"),
|
|
1320
|
+
...config,
|
|
1321
|
+
rpc: config?.rpc ?? {}
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Direct access to Agent Module for read operations
|
|
1326
|
+
*/
|
|
1327
|
+
get agents() {
|
|
1328
|
+
return new AgentModule(this.config);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Direct access to Ghost Module for claiming external agents
|
|
1332
|
+
*
|
|
1333
|
+
* Ghosts are external AI agents (type 10) that exist on x402 facilitators.
|
|
1334
|
+
* They can be claimed using Solana Attestation Service (SAS)
|
|
1335
|
+
* for trustless ownership verification.
|
|
1336
|
+
*/
|
|
1337
|
+
get ghosts() {
|
|
1338
|
+
return new GhostModule(this.config);
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Direct access to Governance Module for read operations
|
|
1342
|
+
*/
|
|
1343
|
+
get governanceModule() {
|
|
1344
|
+
return new GovernanceModule(this.config);
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Direct access to Multisig Module for read operations
|
|
1348
|
+
*/
|
|
1349
|
+
get multisigModule() {
|
|
1350
|
+
return new MultisigModule(this.config);
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Agent operations
|
|
1354
|
+
*/
|
|
1355
|
+
agent() {
|
|
1356
|
+
return new AgentBuilder(this.config);
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Reputation operations
|
|
1360
|
+
*/
|
|
1361
|
+
reputation() {
|
|
1362
|
+
return new ReputationModule(this.config);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Reputation Tag Engine (Pillar 2: Granular Tags)
|
|
1366
|
+
*
|
|
1367
|
+
* Automatic tag assignment and management based on agent metrics.
|
|
1368
|
+
* Features confidence scoring, evidence tracking, and tag decay.
|
|
1369
|
+
*/
|
|
1370
|
+
tagEngine() {
|
|
1371
|
+
const { ReputationTagEngine } = (init_reputation_tag_engine(), __toCommonJS(reputation_tag_engine_exports));
|
|
1372
|
+
return new ReputationTagEngine();
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Multi-Source Reputation Aggregator (Pillar 3: External Sources)
|
|
1376
|
+
*
|
|
1377
|
+
* Aggregate reputation data from multiple sources (x402, GitHub, custom webhooks)
|
|
1378
|
+
* with weighted scoring and conflict detection.
|
|
1379
|
+
*/
|
|
1380
|
+
reputationAggregator() {
|
|
1381
|
+
const { MultiSourceAggregator } = (init_MultiSourceAggregator(), __toCommonJS(MultiSourceAggregator_exports));
|
|
1382
|
+
return new MultiSourceAggregator();
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Privacy operations
|
|
1386
|
+
*/
|
|
1387
|
+
privacy() {
|
|
1388
|
+
return new PrivacyModule(this.config);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Governance operations
|
|
1392
|
+
*/
|
|
1393
|
+
governance() {
|
|
1394
|
+
return new GovernanceBuilder(this.config);
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Multisig operations
|
|
1398
|
+
*/
|
|
1399
|
+
multisig() {
|
|
1400
|
+
return new MultisigBuilder(this.config);
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Unified Credential operations (Solana + Crossmint)
|
|
1404
|
+
*/
|
|
1405
|
+
credentials() {
|
|
1406
|
+
return new UnifiedCredentialService({
|
|
1407
|
+
programId: this.config.programId,
|
|
1408
|
+
crossmint: this.config.credentials?.crossmintApiKey ? {
|
|
1409
|
+
apiKey: this.config.credentials.crossmintApiKey,
|
|
1410
|
+
environment: this.config.credentials.crossmintEnvironment,
|
|
1411
|
+
chain: this.config.credentials.crossmintChain
|
|
1412
|
+
} : void 0,
|
|
1413
|
+
crossmintTemplates: this.config.credentials?.templates
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* DID operations (Decentralized Identifiers)
|
|
1418
|
+
*/
|
|
1419
|
+
did() {
|
|
1420
|
+
return new DidModule(this.config);
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Direct access to Authorization Module for read operations
|
|
1424
|
+
*/
|
|
1425
|
+
get authorization() {
|
|
1426
|
+
return new AuthorizationModule(this.config);
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Direct access to Staking Module for read operations
|
|
1430
|
+
*/
|
|
1431
|
+
get staking() {
|
|
1432
|
+
return new StakingModule(this.config);
|
|
1433
|
+
}
|
|
1434
|
+
// H2A module has been removed - use A2A (Agent-to-Agent) instructions instead
|
|
1435
|
+
/**
|
|
1436
|
+
* Enable development mode features
|
|
1437
|
+
*/
|
|
1438
|
+
enableDevMode() {
|
|
1439
|
+
console.log("\u{1F6E0}\uFE0F Development mode enabled");
|
|
1440
|
+
console.log(" - Transaction simulation before sending");
|
|
1441
|
+
console.log(" - Cost estimates for all operations");
|
|
1442
|
+
console.log(" - Enhanced error messages");
|
|
1443
|
+
this.config = {
|
|
1444
|
+
...this.config
|
|
1445
|
+
// Add dev mode flags
|
|
1446
|
+
};
|
|
1447
|
+
return this;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Configure network
|
|
1451
|
+
*/
|
|
1452
|
+
useNetwork(cluster) {
|
|
1453
|
+
this.config.cluster = cluster;
|
|
1454
|
+
this.config.rpcEndpoint = this.getDefaultRpcEndpoint(cluster);
|
|
1455
|
+
return this;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Configure custom RPC
|
|
1459
|
+
*/
|
|
1460
|
+
useRpc(endpoint, wsEndpoint) {
|
|
1461
|
+
this.config.rpcEndpoint = endpoint;
|
|
1462
|
+
this.config.wsEndpoint = wsEndpoint;
|
|
1463
|
+
return this;
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Get default RPC endpoint for cluster
|
|
1467
|
+
*/
|
|
1468
|
+
getDefaultRpcEndpoint(cluster) {
|
|
1469
|
+
switch (cluster) {
|
|
1470
|
+
case "mainnet-beta":
|
|
1471
|
+
return "https://api.mainnet-beta.solana.com";
|
|
1472
|
+
case "devnet":
|
|
1473
|
+
return "https://api.devnet.solana.com";
|
|
1474
|
+
case "testnet":
|
|
1475
|
+
return "https://api.testnet.solana.com";
|
|
1476
|
+
case "localnet":
|
|
1477
|
+
return "http://localhost:8899";
|
|
1478
|
+
default:
|
|
1479
|
+
return "https://api.devnet.solana.com";
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
var AgentBuilder = class {
|
|
1484
|
+
module;
|
|
1485
|
+
params = {};
|
|
1486
|
+
constructor(config) {
|
|
1487
|
+
this.module = new AgentModule(config);
|
|
1488
|
+
}
|
|
1489
|
+
create(params) {
|
|
1490
|
+
this.params = {
|
|
1491
|
+
...this.params,
|
|
1492
|
+
agentType: 0,
|
|
1493
|
+
// Default type
|
|
1494
|
+
metadataUri: JSON.stringify(params),
|
|
1495
|
+
agentId: params.name.toLowerCase().replace(/\s+/g, "-"),
|
|
1496
|
+
name: params.name,
|
|
1497
|
+
description: params.description || ""
|
|
1498
|
+
};
|
|
1499
|
+
return this;
|
|
1500
|
+
}
|
|
1501
|
+
withDescription(description) {
|
|
1502
|
+
this.params.description = description;
|
|
1503
|
+
return this;
|
|
1504
|
+
}
|
|
1505
|
+
withType(agentType) {
|
|
1506
|
+
this.params.agentType = agentType;
|
|
1507
|
+
return this;
|
|
1508
|
+
}
|
|
1509
|
+
withIPFS() {
|
|
1510
|
+
this.params.forceIPFS = true;
|
|
1511
|
+
return this;
|
|
1512
|
+
}
|
|
1513
|
+
compressed() {
|
|
1514
|
+
this.params.compressed = true;
|
|
1515
|
+
return this;
|
|
1516
|
+
}
|
|
1517
|
+
debug() {
|
|
1518
|
+
this.module.debug();
|
|
1519
|
+
return this;
|
|
1520
|
+
}
|
|
1521
|
+
withSigner(signer) {
|
|
1522
|
+
this.params.signer = signer;
|
|
1523
|
+
return this;
|
|
1524
|
+
}
|
|
1525
|
+
validateParams() {
|
|
1526
|
+
if (!this.params.signer) {
|
|
1527
|
+
throw new Error("Agent builder requires a signer. Call with signer first.");
|
|
1528
|
+
}
|
|
1529
|
+
if (!this.params.metadataUri) {
|
|
1530
|
+
throw new Error("Agent builder requires metadata. Call create() first.");
|
|
1531
|
+
}
|
|
1532
|
+
if (!this.params.agentId) {
|
|
1533
|
+
throw new Error("Agent builder requires agent ID. Call create() first.");
|
|
1534
|
+
}
|
|
1535
|
+
this.params.agentType ??= 0;
|
|
1536
|
+
}
|
|
1537
|
+
async getCost() {
|
|
1538
|
+
this.validateParams();
|
|
1539
|
+
return this.module.getCost("registerAgent", () => ({
|
|
1540
|
+
programAddress: this.module.getProgramId(),
|
|
1541
|
+
accounts: [],
|
|
1542
|
+
data: new Uint8Array()
|
|
1543
|
+
}));
|
|
1544
|
+
}
|
|
1545
|
+
async simulate() {
|
|
1546
|
+
const instruction = () => ({
|
|
1547
|
+
// Placeholder for actual instruction generation
|
|
1548
|
+
programAddress: this.module.getProgramId(),
|
|
1549
|
+
accounts: [],
|
|
1550
|
+
data: new Uint8Array()
|
|
1551
|
+
});
|
|
1552
|
+
this.validateParams();
|
|
1553
|
+
return this.module.simulateInstruction("registerAgent", instruction, [this.params.signer]);
|
|
1554
|
+
}
|
|
1555
|
+
async explain() {
|
|
1556
|
+
this.validateParams();
|
|
1557
|
+
return this.module.explain("registerAgent", () => ({
|
|
1558
|
+
programAddress: this.module.getProgramId(),
|
|
1559
|
+
accounts: [],
|
|
1560
|
+
data: new Uint8Array()
|
|
1561
|
+
}));
|
|
1562
|
+
}
|
|
1563
|
+
async execute() {
|
|
1564
|
+
this.validateParams();
|
|
1565
|
+
if (this.params.compressed) {
|
|
1566
|
+
console.log("Creating compressed agent (5000x cheaper)...");
|
|
1567
|
+
}
|
|
1568
|
+
const signature = await this.module.register(this.params.signer, {
|
|
1569
|
+
agentType: this.params.agentType,
|
|
1570
|
+
name: this.params.name,
|
|
1571
|
+
description: this.params.description,
|
|
1572
|
+
metadataUri: this.params.metadataUri,
|
|
1573
|
+
agentId: this.params.agentId
|
|
1574
|
+
});
|
|
1575
|
+
const address2 = await this.deriveAgentAddress(this.params.agentId, this.params.signer);
|
|
1576
|
+
return { address: address2, signature };
|
|
1577
|
+
}
|
|
1578
|
+
async deriveAgentAddress(agentId, signer) {
|
|
1579
|
+
const { deriveAgentPda } = await import('./pda-4KP7CURF.js');
|
|
1580
|
+
const [address2] = await deriveAgentPda({
|
|
1581
|
+
programAddress: this.module.getProgramId(),
|
|
1582
|
+
owner: signer.address,
|
|
1583
|
+
agentId
|
|
1584
|
+
});
|
|
1585
|
+
return address2;
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
var GovernanceBuilder = class {
|
|
1589
|
+
module;
|
|
1590
|
+
params = {};
|
|
1591
|
+
constructor(config) {
|
|
1592
|
+
this.module = new GovernanceModule(config);
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Create a governance proposal
|
|
1596
|
+
*/
|
|
1597
|
+
proposal() {
|
|
1598
|
+
return new ProposalBuilder(this.module, this.params);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Get governance queries
|
|
1602
|
+
*/
|
|
1603
|
+
query() {
|
|
1604
|
+
return new GovernanceQuery(this.module);
|
|
1605
|
+
}
|
|
1606
|
+
debug() {
|
|
1607
|
+
this.module.debug();
|
|
1608
|
+
return this;
|
|
1609
|
+
}
|
|
1610
|
+
withSigner(signer) {
|
|
1611
|
+
this.params.signer = signer;
|
|
1612
|
+
return this;
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
var ProposalBuilder = class {
|
|
1616
|
+
constructor(module, builderParams) {
|
|
1617
|
+
this.module = module;
|
|
1618
|
+
this.builderParams = builderParams;
|
|
1619
|
+
this.params.signer = builderParams.signer;
|
|
1620
|
+
}
|
|
1621
|
+
params = {};
|
|
1622
|
+
create(params) {
|
|
1623
|
+
this.params.title = params.title;
|
|
1624
|
+
this.params.description = params.description;
|
|
1625
|
+
return this;
|
|
1626
|
+
}
|
|
1627
|
+
type(proposalType) {
|
|
1628
|
+
this.params.proposalType = proposalType;
|
|
1629
|
+
return this;
|
|
1630
|
+
}
|
|
1631
|
+
votingDuration(hours) {
|
|
1632
|
+
this.params.votingDuration = hours;
|
|
1633
|
+
return this;
|
|
1634
|
+
}
|
|
1635
|
+
executionDelay(hours) {
|
|
1636
|
+
this.params.executionDelay = hours;
|
|
1637
|
+
return this;
|
|
1638
|
+
}
|
|
1639
|
+
validateParams() {
|
|
1640
|
+
if (!this.params.signer) throw new Error("Signer required");
|
|
1641
|
+
if (!this.params.title) throw new Error("Title required");
|
|
1642
|
+
if (!this.params.description) throw new Error("Description required");
|
|
1643
|
+
if (!this.params.proposalType) throw new Error("Proposal type required");
|
|
1644
|
+
if (!this.params.votingDuration) throw new Error("Voting duration required");
|
|
1645
|
+
}
|
|
1646
|
+
async execute() {
|
|
1647
|
+
this.validateParams();
|
|
1648
|
+
const signature = await this.module.createProposal({
|
|
1649
|
+
signer: this.params.signer,
|
|
1650
|
+
title: this.params.title,
|
|
1651
|
+
description: this.params.description,
|
|
1652
|
+
proposalType: this.params.proposalType,
|
|
1653
|
+
votingDuration: this.params.votingDuration,
|
|
1654
|
+
executionDelay: this.params.executionDelay
|
|
1655
|
+
});
|
|
1656
|
+
const address2 = `proposal_${this.params.signer.address}_${this.params.title}`;
|
|
1657
|
+
return { address: address2, signature };
|
|
1658
|
+
}
|
|
1659
|
+
withSigner(signer) {
|
|
1660
|
+
this.params.signer = signer;
|
|
1661
|
+
return this;
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
var GovernanceQuery = class {
|
|
1665
|
+
constructor(module) {
|
|
1666
|
+
this.module = module;
|
|
1667
|
+
}
|
|
1668
|
+
async activeProposals() {
|
|
1669
|
+
return this.module.getActiveProposals();
|
|
1670
|
+
}
|
|
1671
|
+
async proposalsByProposer(proposer) {
|
|
1672
|
+
return this.module.getProposalsByProposer(proposer);
|
|
1673
|
+
}
|
|
1674
|
+
async proposalsByStatus(status) {
|
|
1675
|
+
return this.module.getProposalsByStatus(status);
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
var MultisigBuilder = class {
|
|
1679
|
+
module;
|
|
1680
|
+
params = {};
|
|
1681
|
+
constructor(config) {
|
|
1682
|
+
this.module = new MultisigModule(config);
|
|
1683
|
+
}
|
|
1684
|
+
create() {
|
|
1685
|
+
return new CreateMultisigBuilder(this.module, this.params);
|
|
1686
|
+
}
|
|
1687
|
+
proposal() {
|
|
1688
|
+
return new MultisigProposalBuilder(this.module, this.params);
|
|
1689
|
+
}
|
|
1690
|
+
approve() {
|
|
1691
|
+
return new MultisigApproveBuilder(this.module, this.params);
|
|
1692
|
+
}
|
|
1693
|
+
executeProposal() {
|
|
1694
|
+
return new MultisigExecuteBuilder(this.module, this.params);
|
|
1695
|
+
}
|
|
1696
|
+
withSigner(signer) {
|
|
1697
|
+
this.params.signer = signer;
|
|
1698
|
+
return this;
|
|
1699
|
+
}
|
|
1700
|
+
debug() {
|
|
1701
|
+
this.module.debug();
|
|
1702
|
+
return this;
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
var CreateMultisigBuilder = class {
|
|
1706
|
+
constructor(module, builderParams) {
|
|
1707
|
+
this.module = module;
|
|
1708
|
+
this.builderParams = builderParams;
|
|
1709
|
+
this.params.signer = builderParams.signer;
|
|
1710
|
+
}
|
|
1711
|
+
params = {};
|
|
1712
|
+
withId(id) {
|
|
1713
|
+
this.params.multisigId = id;
|
|
1714
|
+
return this;
|
|
1715
|
+
}
|
|
1716
|
+
threshold(t) {
|
|
1717
|
+
this.params.threshold = t;
|
|
1718
|
+
return this;
|
|
1719
|
+
}
|
|
1720
|
+
signers(s) {
|
|
1721
|
+
this.params.signers = s;
|
|
1722
|
+
return this;
|
|
1723
|
+
}
|
|
1724
|
+
async execute() {
|
|
1725
|
+
if (!this.params.signer) throw new Error("Signer required");
|
|
1726
|
+
if (!this.params.multisigId) throw new Error("Multisig ID required");
|
|
1727
|
+
if (!this.params.threshold) throw new Error("Threshold required");
|
|
1728
|
+
if (!this.params.signers) throw new Error("Signers required");
|
|
1729
|
+
return {
|
|
1730
|
+
signature: await this.module.createMultisig({
|
|
1731
|
+
owner: this.params.signer,
|
|
1732
|
+
multisigId: this.params.multisigId,
|
|
1733
|
+
threshold: this.params.threshold,
|
|
1734
|
+
signers: this.params.signers
|
|
1735
|
+
})
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
withSigner(signer) {
|
|
1739
|
+
this.params.signer = signer;
|
|
1740
|
+
return this;
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
var MultisigProposalBuilder = class {
|
|
1744
|
+
constructor(module, builderParams) {
|
|
1745
|
+
this.module = module;
|
|
1746
|
+
this.builderParams = builderParams;
|
|
1747
|
+
this.params.signer = builderParams.signer;
|
|
1748
|
+
}
|
|
1749
|
+
params = {};
|
|
1750
|
+
forMultisig(address2) {
|
|
1751
|
+
this.params.multisigAddress = address2;
|
|
1752
|
+
return this;
|
|
1753
|
+
}
|
|
1754
|
+
title(t) {
|
|
1755
|
+
this.params.title = t;
|
|
1756
|
+
return this;
|
|
1757
|
+
}
|
|
1758
|
+
description(d) {
|
|
1759
|
+
this.params.description = d;
|
|
1760
|
+
return this;
|
|
1761
|
+
}
|
|
1762
|
+
async execute() {
|
|
1763
|
+
if (!this.params.signer) throw new Error("Signer required");
|
|
1764
|
+
if (!this.params.title) throw new Error("Title required");
|
|
1765
|
+
if (!this.params.description) throw new Error("Description required");
|
|
1766
|
+
return {
|
|
1767
|
+
signature: await this.module.createProposal({
|
|
1768
|
+
multisigAddress: this.params.multisigAddress,
|
|
1769
|
+
title: this.params.title,
|
|
1770
|
+
description: this.params.description,
|
|
1771
|
+
proposalType: 7 /* Custom */,
|
|
1772
|
+
executionParams: {
|
|
1773
|
+
instructions: [],
|
|
1774
|
+
executionDelay: 0n,
|
|
1775
|
+
executionConditions: [],
|
|
1776
|
+
cancellable: true,
|
|
1777
|
+
autoExecute: true,
|
|
1778
|
+
executionAuthority: this.params.signer.address
|
|
1779
|
+
},
|
|
1780
|
+
proposalId: BigInt(Date.now()),
|
|
1781
|
+
proposer: this.params.signer
|
|
1782
|
+
})
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
withSigner(signer) {
|
|
1786
|
+
this.params.signer = signer;
|
|
1787
|
+
return this;
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var MultisigApproveBuilder = class {
|
|
1791
|
+
constructor(module, builderParams) {
|
|
1792
|
+
this.module = module;
|
|
1793
|
+
this.builderParams = builderParams;
|
|
1794
|
+
this.params.signer = builderParams.signer;
|
|
1795
|
+
}
|
|
1796
|
+
params = {};
|
|
1797
|
+
proposal(address2) {
|
|
1798
|
+
this.params.proposalAddress = address2;
|
|
1799
|
+
return this;
|
|
1800
|
+
}
|
|
1801
|
+
vote(choice) {
|
|
1802
|
+
this.params.voteChoice = choice;
|
|
1803
|
+
return this;
|
|
1804
|
+
}
|
|
1805
|
+
reason(text) {
|
|
1806
|
+
this.params.reasoning = text;
|
|
1807
|
+
return this;
|
|
1808
|
+
}
|
|
1809
|
+
tokenAccount(account) {
|
|
1810
|
+
this.params.tokenAccount = account;
|
|
1811
|
+
return this;
|
|
1812
|
+
}
|
|
1813
|
+
async execute() {
|
|
1814
|
+
if (!this.params.signer) throw new Error("Signer required");
|
|
1815
|
+
if (!this.params.proposalAddress) throw new Error("Proposal address required");
|
|
1816
|
+
throw new Error("Multisig approval: Use protocol_config instructions for voting (approveProposal removed)");
|
|
1817
|
+
}
|
|
1818
|
+
withSigner(signer) {
|
|
1819
|
+
this.params.signer = signer;
|
|
1820
|
+
return this;
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
var MultisigExecuteBuilder = class {
|
|
1824
|
+
constructor(module, builderParams) {
|
|
1825
|
+
this.module = module;
|
|
1826
|
+
this.builderParams = builderParams;
|
|
1827
|
+
this.params.signer = builderParams.signer;
|
|
1828
|
+
}
|
|
1829
|
+
params = {};
|
|
1830
|
+
proposal(address2) {
|
|
1831
|
+
this.params.proposalAddress = address2;
|
|
1832
|
+
return this;
|
|
1833
|
+
}
|
|
1834
|
+
target(programId) {
|
|
1835
|
+
this.params.targetProgram = programId;
|
|
1836
|
+
return this;
|
|
1837
|
+
}
|
|
1838
|
+
async execute() {
|
|
1839
|
+
if (!this.params.signer) throw new Error("Signer required");
|
|
1840
|
+
if (!this.params.proposalAddress) throw new Error("Proposal address required");
|
|
1841
|
+
if (!this.params.targetProgram) throw new Error("Target program required");
|
|
1842
|
+
return {
|
|
1843
|
+
signature: await this.module.executeProposal({
|
|
1844
|
+
proposalAddress: this.params.proposalAddress,
|
|
1845
|
+
executor: this.params.signer,
|
|
1846
|
+
targetProgram: this.params.targetProgram
|
|
1847
|
+
})
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
withSigner(signer) {
|
|
1851
|
+
this.params.signer = signer;
|
|
1852
|
+
return this;
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
function sol(amount) {
|
|
1856
|
+
return BigInt(Math.floor(amount * 1e9));
|
|
1857
|
+
}
|
|
1858
|
+
function lamportsToSol(lamports) {
|
|
1859
|
+
return Number(lamports) / 1e9;
|
|
1860
|
+
}
|
|
1861
|
+
var GhostSpeakClient_default = GhostSpeakClient;
|
|
1862
|
+
|
|
1863
|
+
export { AuthorizationModule, DidModule, GhostSpeakClient, GhostSpeakClient_default, PrivacyModule, UnifiedCredentialService, calculateVisibleScore, canViewerAccess, filterMetricsByVisibility, getDefaultMetricVisibility, getRangeDisplayString, getReputationTier, getScoreRange, getTierDisplayName, lamportsToSol, sol, validatePrivacySettings };
|
|
1864
|
+
//# sourceMappingURL=chunk-6XCCMJ6M.js.map
|
|
1865
|
+
//# sourceMappingURL=chunk-6XCCMJ6M.js.map
|