@prktsol/prkt 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.devnet.all-protocols.example +5 -0
- package/.env.example +7 -0
- package/CLI.md +24 -0
- package/CLI_QUICKSTART.md +16 -0
- package/README.md +59 -12
- package/dist/agent/AgentManager.d.ts +61 -0
- package/dist/agent/AgentRuntime.d.ts +28 -0
- package/dist/agent/DecisionEngine.d.ts +51 -0
- package/dist/agent/MockPriceFeed.d.ts +10 -0
- package/dist/agent/intents/types.d.ts +35 -0
- package/dist/agent/new-index.d.ts +9 -0
- package/dist/agent/policyFactory.d.ts +2 -0
- package/dist/agent/registry/AgentRegistry.d.ts +11 -0
- package/dist/agent/runner/AgentRunner.d.ts +51 -0
- package/dist/agent/runner/AgentRunner.js +59 -2
- package/dist/agent/strategies/MemoHeartbeatStrategy.d.ts +6 -0
- package/dist/agent/strategies/SimpleScriptedTransferStrategy.d.ts +12 -0
- package/dist/agent/strategies/TokenRebalancerStrategy.d.ts +13 -0
- package/dist/agent/strategies/TreasuryDistributorStrategy.d.ts +12 -0
- package/dist/agent/strategies/UniversalDeFiStrategy.d.ts +22 -0
- package/dist/agent/types/AgentContext.d.ts +28 -0
- package/dist/anchoring/SessionAnchor.d.ts +42 -0
- package/dist/anchoring/SessionAnchor.js +161 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +157 -16
- package/dist/cli/services/activityStore.d.ts +8 -0
- package/dist/cli/services/agentRegistry.d.ts +20 -0
- package/dist/cli/services/agentRuntime.d.ts +6 -0
- package/dist/cli/services/storagePaths.d.ts +8 -0
- package/dist/cli/services/strategyFactory.d.ts +5 -0
- package/dist/cli/services/walletCrypto.d.ts +12 -0
- package/dist/cli/services/walletRegistry.d.ts +26 -0
- package/dist/cli/types.d.ts +68 -0
- package/dist/cli/utils/completion.d.ts +4 -0
- package/dist/cli/utils/output.d.ts +5 -0
- package/dist/cli/utils/output.js +4 -1
- package/dist/compression/AuditLogManager.d.ts +9 -0
- package/dist/compression/AuditLogManager.js +86 -0
- package/dist/compression/PolicyAccountManager.d.ts +11 -0
- package/dist/compression/PolicyAccountManager.js +113 -0
- package/dist/compression/types.d.ts +20 -0
- package/dist/compression/types.js +2 -0
- package/dist/config/PRKTConfig.d.ts +17 -0
- package/dist/config/PRKTConfig.js +19 -0
- package/dist/config/agentPolicies.d.ts +14 -0
- package/dist/config/env.d.ts +39 -0
- package/dist/config/env.js +37 -0
- package/dist/config/policyPresets.d.ts +22 -0
- package/dist/core/balances/BalanceService.d.ts +14 -0
- package/dist/core/funding/DevnetFundingService.d.ts +38 -0
- package/dist/core/funding/DevnetFundingService.js +73 -6
- package/dist/core/idempotency/ExecutionIdempotencyGuard.d.ts +39 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/rpc/RpcClient.d.ts +21 -0
- package/dist/core/rpc/RpcClient.js +35 -0
- package/dist/core/rpc/RpcFailoverClient.d.ts +42 -0
- package/dist/core/tokens/TokenService.d.ts +40 -0
- package/dist/core/transactions/PostTransactionVerifier.d.ts +47 -0
- package/dist/core/transactions/TransactionService.d.ts +46 -0
- package/dist/core/types/services.d.ts +27 -0
- package/dist/core/wallet/WalletManager.d.ts +21 -0
- package/dist/defi/DeFiCoordinator.d.ts +24 -0
- package/dist/defi/DeFiExecutor.d.ts +15 -0
- package/dist/defi/DeFiPolicyGuard.d.ts +7 -0
- package/dist/defi/adapters/JupiterAdapter.d.ts +5 -0
- package/dist/defi/adapters/KaminoAdapter.d.ts +6 -0
- package/dist/defi/adapters/MarinadeAdapter.d.ts +5 -0
- package/dist/defi/adapters/RaydiumAdapter.d.ts +20 -0
- package/dist/defi/kamino/kaminoInstructionCompat.d.ts +3 -0
- package/dist/defi/kamino/kaminoLiveConfig.d.ts +14 -0
- package/dist/defi/kamino/loadKaminoMarketWithFallback.d.ts +11 -0
- package/dist/defi/lp/LpInstructionBuilder.d.ts +15 -0
- package/dist/defi/lp/RaydiumLpInstructionBuilder.d.ts +28 -0
- package/dist/defi/lp/raydiumDevnetConfig.d.ts +11 -0
- package/dist/defi/protocols.d.ts +8 -0
- package/dist/defi/types.d.ts +65 -0
- package/dist/defi/universal/UniversalDeFiOrchestrator.d.ts +24 -0
- package/dist/defi/universal/UniversalDeFiOrchestrator.js +157 -0
- package/dist/defi/universal/adapters.d.ts +25 -0
- package/dist/defi/universal/index.d.ts +2 -0
- package/dist/defi/universal/liveExecutors.d.ts +23 -0
- package/dist/defi/universal/types.d.ts +45 -0
- package/dist/demo/scenarios/multiAgentDevnetScenario.d.ts +5 -0
- package/dist/demo/scripts/runMultiAgentDevnetDemo.d.ts +1 -0
- package/dist/dex/JupiterSwapClient.d.ts +28 -0
- package/dist/dex/SwapExecutor.d.ts +36 -0
- package/dist/errors/PRKTError.d.ts +15 -0
- package/dist/errors/PRKTError.js +38 -0
- package/dist/evm/EvmAdapter.d.ts +45 -0
- package/dist/evm/EvmAdapter.js +2 -0
- package/dist/evm/NeonWalletBridge.d.ts +9 -0
- package/dist/evm/NeonWalletBridge.js +40 -0
- package/dist/evm/adapters/AaveAdapter.d.ts +17 -0
- package/dist/evm/adapters/AaveAdapter.js +100 -0
- package/dist/evm/adapters/UniswapV3Adapter.d.ts +18 -0
- package/dist/evm/adapters/UniswapV3Adapter.js +146 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +35 -20
- package/dist/kora/KoraRpcClient.d.ts +14 -0
- package/dist/kora/KoraSigner.d.ts +22 -0
- package/dist/kora/KoraSigner.js +33 -10
- package/dist/kora/gaslessDemo.d.ts +9 -0
- package/dist/onchain/index.d.ts +2 -0
- package/dist/onchain/index.js +17 -0
- package/dist/onchain/policyGuardProgram.d.ts +86 -0
- package/dist/onchain/policyGuardProgram.js +248 -0
- package/dist/policy/PolicyGuard.d.ts +13 -0
- package/dist/policy/emergencyLock.d.ts +4 -0
- package/dist/policy/engine/PolicyEngine.d.ts +28 -0
- package/dist/policy/engine/PolicyEngine.js +109 -1
- package/dist/policy/errors.d.ts +3 -0
- package/dist/policy/index.d.ts +3 -0
- package/dist/policy/sandbox/SandboxExecutor.d.ts +44 -0
- package/dist/policy/sandbox/SandboxExecutor.js +245 -3
- package/dist/policy/types/policy.d.ts +55 -0
- package/dist/scripts/devnetFunding.d.ts +9 -0
- package/dist/scripts/devnetFunding.js +0 -1
- package/dist/scripts/devnetWalletPreflight.d.ts +8 -0
- package/dist/scripts/localnetCheck.d.ts +1 -0
- package/dist/scripts/managedAgentWallet.d.ts +34 -0
- package/dist/scripts/mode.d.ts +2 -0
- package/dist/scripts/releaseReadiness.d.ts +9 -0
- package/dist/scripts/runAgentUniversalDeFi.d.ts +1 -0
- package/dist/scripts/runAutonomousAgentWalletDevnet.d.ts +1 -0
- package/dist/scripts/runAutonomousAgentWalletDevnet.js +1 -1
- package/dist/scripts/runAutonomousPortfolioDevnet.d.ts +1 -0
- package/dist/scripts/runAutonomousPortfolioDevnet.js +1 -1
- package/dist/scripts/runBorrowStrategy.d.ts +1 -0
- package/dist/scripts/runDeFiSuite.d.ts +1 -0
- package/dist/scripts/runDemoRehearsal.d.ts +1 -0
- package/dist/scripts/runDemoRehearsal.js +39 -10
- package/dist/scripts/runDevnetFeatureMatrix.d.ts +43 -0
- package/dist/scripts/runDevnetFeatureMatrix.js +787 -0
- package/dist/scripts/runDevnetWalletDemo.d.ts +1 -0
- package/dist/scripts/runGaslessMemo.d.ts +1 -0
- package/dist/scripts/runGaslessMemo.js +9 -1
- package/dist/scripts/runGaslessWalletDemo.d.ts +1 -0
- package/dist/scripts/runGaslessWalletDemo.js +9 -1
- package/dist/scripts/runKaminoDevnet.d.ts +1 -0
- package/dist/scripts/runKaminoDevnet.js +82 -42
- package/dist/scripts/runLpStrategy.d.ts +1 -0
- package/dist/scripts/runMarinadeDevnet.d.ts +1 -0
- package/dist/scripts/runOnchainPolicyGuardDevnet.d.ts +1 -0
- package/dist/scripts/runOnchainPolicyGuardDevnet.js +113 -0
- package/dist/scripts/runOrcaLpDevnet.d.ts +1 -0
- package/dist/scripts/runRaydiumLpDevnet.d.ts +1 -0
- package/dist/scripts/runReleaseReadiness.d.ts +1 -0
- package/dist/scripts/runStakeStrategy.d.ts +1 -0
- package/dist/scripts/runStatus.d.ts +1 -0
- package/dist/scripts/runStatus.js +22 -0
- package/dist/scripts/runStressTest.d.ts +1 -0
- package/dist/scripts/runTradeLoop.d.ts +1 -0
- package/dist/scripts/runUniversalDeFiDemo.d.ts +1 -0
- package/dist/scripts/runYieldStrategy.d.ts +1 -0
- package/dist/scripts/runtimeFactory.d.ts +8 -0
- package/dist/scripts/shared.d.ts +3 -0
- package/dist/scripts/shared.js +1 -0
- package/dist/scripts/simulateAttack.d.ts +1 -0
- package/dist/scripts/simulateSwarm.d.ts +1 -0
- package/dist/simulation/attack.d.ts +8 -0
- package/dist/solana/memoLedger.d.ts +33 -0
- package/dist/solana/memoLedger.js +205 -0
- package/dist/solana/programs.d.ts +6 -0
- package/dist/spl/TokenWallet.d.ts +18 -0
- package/dist/types/policy.d.ts +23 -0
- package/dist/wallet/WalletManager.d.ts +1 -0
- package/dist/zk/PolicyCircuit.d.ts +48 -0
- package/dist/zk/PolicyCircuit.js +171 -0
- package/dist/zk/ProofAnchor.d.ts +33 -0
- package/dist/zk/ProofAnchor.js +109 -0
- package/dist/zkCompression/CompressedCommitmentAnchor.d.ts +31 -0
- package/dist/zkCompression/CompressedCommitmentAnchor.js +90 -0
- package/dist/zkCompression/CompressedDataAccount.d.ts +45 -0
- package/dist/zkCompression/CompressedDataAccount.js +349 -0
- package/dist/zkCompression/LocalPayloadRegistry.d.ts +23 -0
- package/dist/zkCompression/LocalPayloadRegistry.js +53 -0
- package/package.json +20 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AgentIntent } from "../intents/types";
|
|
2
|
+
import type { AgentContext, Strategy } from "../types/AgentContext";
|
|
3
|
+
export declare class UniversalDeFiStrategy implements Strategy {
|
|
4
|
+
private readonly requests;
|
|
5
|
+
readonly name = "universal-defi";
|
|
6
|
+
constructor(requests: Array<{
|
|
7
|
+
capability: "trade" | "lp" | "lending" | "borrowing" | "yield" | "staking";
|
|
8
|
+
protocol?: "jupiter" | "raydium" | "kamino" | "marinade";
|
|
9
|
+
snapshot: {
|
|
10
|
+
borrowDemandUsdcAtomic?: number;
|
|
11
|
+
buyThresholdUsd?: number;
|
|
12
|
+
collateralSolLamports?: number;
|
|
13
|
+
healthFactor?: number;
|
|
14
|
+
idleSolLamports?: number;
|
|
15
|
+
idleUsdcAtomic?: number;
|
|
16
|
+
liquidityInRange?: boolean;
|
|
17
|
+
rewardsClaimableAtomic?: number;
|
|
18
|
+
solPriceUsd?: number;
|
|
19
|
+
};
|
|
20
|
+
}>);
|
|
21
|
+
nextIntents(_context: AgentContext): Promise<AgentIntent[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import type { BalanceService } from "../../core/balances/BalanceService";
|
|
3
|
+
import type { RpcClient } from "../../core/rpc/RpcClient";
|
|
4
|
+
import type { TokenService } from "../../core/tokens/TokenService";
|
|
5
|
+
import type { TransactionService } from "../../core/transactions/TransactionService";
|
|
6
|
+
import type { WalletManager } from "../../core/wallet/WalletManager";
|
|
7
|
+
import type { PolicyConfig } from "../../policy";
|
|
8
|
+
import type { AgentIntent } from "../intents/types";
|
|
9
|
+
import type { UniversalDeFiRequest, UniversalExecutionOptions, UniversalExecutionResult } from "../../defi/universal";
|
|
10
|
+
export type AgentLogger = (message: string) => void;
|
|
11
|
+
export type AgentContext = {
|
|
12
|
+
id: string;
|
|
13
|
+
walletManager: WalletManager;
|
|
14
|
+
walletPublicKey: PublicKey;
|
|
15
|
+
rpcClient: RpcClient;
|
|
16
|
+
transactionService: TransactionService;
|
|
17
|
+
tokenService: TokenService;
|
|
18
|
+
balanceService: BalanceService;
|
|
19
|
+
policyConfig: PolicyConfig;
|
|
20
|
+
logger: AgentLogger;
|
|
21
|
+
universalDeFiExecutor?: {
|
|
22
|
+
execute(request: UniversalDeFiRequest, options?: UniversalExecutionOptions): Promise<UniversalExecutionResult>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type Strategy = {
|
|
26
|
+
name: string;
|
|
27
|
+
nextIntents(context: AgentContext): Promise<AgentIntent[]>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AuditEntry } from "../compression/types";
|
|
2
|
+
import { WalletManager } from "../core/wallet/WalletManager";
|
|
3
|
+
export type SessionStartResult = {
|
|
4
|
+
compressedAnchorAddress?: string;
|
|
5
|
+
compressedAnchorSignature?: string;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
slot: number;
|
|
8
|
+
startSignature: string;
|
|
9
|
+
};
|
|
10
|
+
export type SessionCloseResult = {
|
|
11
|
+
closeSignature: string;
|
|
12
|
+
compressedAnchorAddress?: string;
|
|
13
|
+
compressedAnchorSignature?: string;
|
|
14
|
+
commitment: string;
|
|
15
|
+
entryCount: number;
|
|
16
|
+
explorerUrl: string;
|
|
17
|
+
ledgerSlot: number;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
slot: number;
|
|
20
|
+
};
|
|
21
|
+
export type SessionVerifyResult = {
|
|
22
|
+
closeSignature?: string;
|
|
23
|
+
commitment?: string;
|
|
24
|
+
entries: AuditEntry[];
|
|
25
|
+
entryCount: number;
|
|
26
|
+
explorerUrl?: string;
|
|
27
|
+
reason?: string;
|
|
28
|
+
slot?: number;
|
|
29
|
+
valid: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare class SessionAnchor {
|
|
32
|
+
private readonly rpcEndpoint;
|
|
33
|
+
private readonly walletManager?;
|
|
34
|
+
private static readonly sessionRegistry;
|
|
35
|
+
constructor(rpcEndpoint: string, walletManager?: WalletManager | undefined);
|
|
36
|
+
startSession(agentId: string): Promise<SessionStartResult>;
|
|
37
|
+
closeSession(sessionId: string, auditLog: AuditEntry[]): Promise<SessionCloseResult>;
|
|
38
|
+
verifySession(sessionId: string, commitment?: string): Promise<SessionVerifyResult>;
|
|
39
|
+
private buildExplorerUrl;
|
|
40
|
+
private getPayer;
|
|
41
|
+
private getStore;
|
|
42
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionAnchor = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const PRKTError_1 = require("../errors/PRKTError");
|
|
6
|
+
const WalletManager_1 = require("../core/wallet/WalletManager");
|
|
7
|
+
const memoLedger_1 = require("../solana/memoLedger");
|
|
8
|
+
const CompressedDataAccount_1 = require("../zkCompression/CompressedDataAccount");
|
|
9
|
+
const SESSION_START_DISCRIMINATOR = "PRKTSS01";
|
|
10
|
+
const SESSION_CLOSE_DISCRIMINATOR = "PRKTSC01";
|
|
11
|
+
class SessionAnchor {
|
|
12
|
+
rpcEndpoint;
|
|
13
|
+
walletManager;
|
|
14
|
+
static sessionRegistry = new Map();
|
|
15
|
+
constructor(rpcEndpoint, walletManager) {
|
|
16
|
+
this.rpcEndpoint = rpcEndpoint;
|
|
17
|
+
this.walletManager = walletManager;
|
|
18
|
+
}
|
|
19
|
+
async startSession(agentId) {
|
|
20
|
+
try {
|
|
21
|
+
const sessionId = (0, crypto_1.randomUUID)();
|
|
22
|
+
const payload = {
|
|
23
|
+
agentId,
|
|
24
|
+
event: "SESSION_START",
|
|
25
|
+
prkt: 1,
|
|
26
|
+
sessionId,
|
|
27
|
+
ts: Date.now()
|
|
28
|
+
};
|
|
29
|
+
const anchored = await this.getStore().writeAccount({
|
|
30
|
+
discriminator: SESSION_START_DISCRIMINATOR,
|
|
31
|
+
namespace: "prkt-session-start",
|
|
32
|
+
parts: [sessionId],
|
|
33
|
+
payer: this.getPayer(),
|
|
34
|
+
payload
|
|
35
|
+
});
|
|
36
|
+
SessionAnchor.sessionRegistry.set(sessionId, {
|
|
37
|
+
startCompressedAddress: anchored.address,
|
|
38
|
+
startSignature: anchored.signature
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
compressedAnchorAddress: anchored.address,
|
|
42
|
+
compressedAnchorSignature: anchored.signature,
|
|
43
|
+
sessionId,
|
|
44
|
+
slot: anchored.slot ?? 0,
|
|
45
|
+
startSignature: anchored.signature
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new PRKTError_1.AnchorError(`Failed to start session: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async closeSession(sessionId, auditLog) {
|
|
53
|
+
try {
|
|
54
|
+
const serialized = JSON.stringify(auditLog);
|
|
55
|
+
const hash = (0, crypto_1.createHash)("sha256").update(serialized).digest("hex");
|
|
56
|
+
const payload = {
|
|
57
|
+
entryCount: auditLog.length,
|
|
58
|
+
event: "SESSION_CLOSE",
|
|
59
|
+
logHash: hash,
|
|
60
|
+
prkt: 1,
|
|
61
|
+
sessionId,
|
|
62
|
+
ts: Date.now()
|
|
63
|
+
};
|
|
64
|
+
const anchored = await this.getStore().writeAccount({
|
|
65
|
+
discriminator: SESSION_CLOSE_DISCRIMINATOR,
|
|
66
|
+
namespace: "prkt-session-close",
|
|
67
|
+
parts: [sessionId],
|
|
68
|
+
payer: this.getPayer(),
|
|
69
|
+
payload
|
|
70
|
+
});
|
|
71
|
+
SessionAnchor.sessionRegistry.set(sessionId, {
|
|
72
|
+
...SessionAnchor.sessionRegistry.get(sessionId),
|
|
73
|
+
closeCompressedAddress: anchored.address,
|
|
74
|
+
closeSignature: anchored.signature,
|
|
75
|
+
commitment: hash,
|
|
76
|
+
entryCount: auditLog.length
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
closeSignature: anchored.signature,
|
|
80
|
+
compressedAnchorAddress: anchored.address,
|
|
81
|
+
compressedAnchorSignature: anchored.signature,
|
|
82
|
+
commitment: hash,
|
|
83
|
+
entryCount: auditLog.length,
|
|
84
|
+
explorerUrl: this.buildExplorerUrl(anchored.signature),
|
|
85
|
+
ledgerSlot: anchored.slot ?? 0,
|
|
86
|
+
sessionId,
|
|
87
|
+
slot: anchored.slot ?? 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new PRKTError_1.AnchorError(`Failed to close session: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async verifySession(sessionId, commitment) {
|
|
95
|
+
try {
|
|
96
|
+
const record = await this.getStore().readAccount({
|
|
97
|
+
discriminator: SESSION_CLOSE_DISCRIMINATOR,
|
|
98
|
+
namespace: "prkt-session-close",
|
|
99
|
+
parts: [sessionId]
|
|
100
|
+
});
|
|
101
|
+
if (!record.exists || !record.payload) {
|
|
102
|
+
return {
|
|
103
|
+
entries: [],
|
|
104
|
+
entryCount: 0,
|
|
105
|
+
reason: record.reason ?? "SESSION_NOT_FOUND",
|
|
106
|
+
valid: false
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const payload = record.payload;
|
|
110
|
+
if (payload.event !== "SESSION_CLOSE" || payload.sessionId !== sessionId) {
|
|
111
|
+
return {
|
|
112
|
+
closeSignature: record.signature,
|
|
113
|
+
entries: [],
|
|
114
|
+
entryCount: 0,
|
|
115
|
+
reason: "SESSION_RECORD_INVALID",
|
|
116
|
+
valid: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (commitment && payload.logHash !== commitment) {
|
|
120
|
+
return {
|
|
121
|
+
closeSignature: record.signature,
|
|
122
|
+
commitment: payload.logHash,
|
|
123
|
+
entries: [],
|
|
124
|
+
entryCount: payload.entryCount,
|
|
125
|
+
explorerUrl: record.explorerUrl,
|
|
126
|
+
reason: "HASH_MISMATCH",
|
|
127
|
+
slot: record.slot,
|
|
128
|
+
valid: false
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
closeSignature: record.signature,
|
|
133
|
+
commitment: payload.logHash,
|
|
134
|
+
entries: [],
|
|
135
|
+
entryCount: payload.entryCount,
|
|
136
|
+
explorerUrl: record.explorerUrl,
|
|
137
|
+
slot: record.slot,
|
|
138
|
+
valid: true
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new PRKTError_1.AnchorError(`Failed to verify session: ${error}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
buildExplorerUrl(signature) {
|
|
146
|
+
return (0, memoLedger_1.buildExplorerTxUrl)(signature, this.rpcEndpoint);
|
|
147
|
+
}
|
|
148
|
+
getPayer() {
|
|
149
|
+
const wallet = this.walletManager ?? WalletManager_1.WalletManager.loadOrGenerate();
|
|
150
|
+
try {
|
|
151
|
+
return wallet.payer;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw new PRKTError_1.AnchorError(`Compressed session storage requires a local signer: ${error}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
getStore() {
|
|
158
|
+
return new CompressedDataAccount_1.CompressedDataAccount(this.rpcEndpoint);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.SessionAnchor = SessionAnchor;
|
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
const fs_1 = require("fs");
|
|
5
38
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -22,14 +55,84 @@ const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
|
|
|
22
55
|
const multiAgentDevnetScenario_1 = require("../demo/scenarios/multiAgentDevnetScenario");
|
|
23
56
|
const policy_1 = require("../policy");
|
|
24
57
|
const completion_1 = require("./utils/completion");
|
|
58
|
+
const CLI_BANNER = String.raw `██████╗ ██████╗ ██╗ ██╗████████╗
|
|
59
|
+
██╔══██╗██╔══██╗██║ ██╔╝╚══██╔══╝
|
|
60
|
+
██████╔╝██████╔╝█████╔╝ ██║
|
|
61
|
+
██╔═══╝ ██╔══██╗██╔═██╗ ██║
|
|
62
|
+
██║ ██║ ██║██║ ██╗ ██║
|
|
63
|
+
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
|
|
64
|
+
|
|
65
|
+
Policy-Enforced Autonomous Agent Runtime
|
|
66
|
+
Solana Infrastructure Layer`;
|
|
25
67
|
const program = new commander_1.Command();
|
|
26
68
|
const walletRegistry = new walletRegistry_1.WalletRegistry();
|
|
27
69
|
const agentRegistry = new agentRegistry_1.AgentRegistryStore(walletRegistry);
|
|
28
70
|
const activityStore = new activityStore_1.ActivityStore();
|
|
29
71
|
const CUSTODY_MODEL = "local-per-user";
|
|
30
72
|
const POLICY_EXECUTION_MODEL = "user-owned agent wallets with policy-guarded execution";
|
|
73
|
+
function shouldPrintStartupBanner(argv) {
|
|
74
|
+
if (argv.includes("--json")) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return !argv.includes("completion");
|
|
78
|
+
}
|
|
79
|
+
function inspectSignerConfiguration() {
|
|
80
|
+
try {
|
|
81
|
+
const remoteSigner = (0, env_1.getRemoteSignerConfig)();
|
|
82
|
+
if (remoteSigner) {
|
|
83
|
+
return {
|
|
84
|
+
detail: `remote signer ${remoteSigner.publicKey.toBase58()}`,
|
|
85
|
+
status: "ok"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const treasurySecretKey = (0, env_1.getOptionalDevnetTreasurySecretKey)();
|
|
89
|
+
if (treasurySecretKey) {
|
|
90
|
+
return {
|
|
91
|
+
detail: "devnet treasury key present",
|
|
92
|
+
status: "ok"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const localSecretKey = (0, env_1.getOptionalSecretKey)();
|
|
96
|
+
if (localSecretKey) {
|
|
97
|
+
return {
|
|
98
|
+
detail: "local demo key present",
|
|
99
|
+
status: "ok"
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
detail: "missing signer configuration",
|
|
104
|
+
status: "warn"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return {
|
|
109
|
+
detail: error instanceof Error ? error.message : "invalid signer configuration",
|
|
110
|
+
status: "fail"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
31
114
|
function outputOptions(command) {
|
|
32
|
-
|
|
115
|
+
if (command &&
|
|
116
|
+
typeof command === "object" &&
|
|
117
|
+
"optsWithGlobals" in command &&
|
|
118
|
+
typeof command.optsWithGlobals === "function") {
|
|
119
|
+
const options = command.optsWithGlobals();
|
|
120
|
+
return {
|
|
121
|
+
json: Boolean(options.json)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (command &&
|
|
125
|
+
typeof command === "object" &&
|
|
126
|
+
"opts" in command &&
|
|
127
|
+
typeof command.opts === "function") {
|
|
128
|
+
const options = command.opts();
|
|
129
|
+
return {
|
|
130
|
+
json: Boolean(options.json)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const options = command && typeof command === "object" && "json" in command
|
|
134
|
+
? command
|
|
135
|
+
: {};
|
|
33
136
|
return {
|
|
34
137
|
json: Boolean(options.json)
|
|
35
138
|
};
|
|
@@ -162,6 +265,51 @@ program
|
|
|
162
265
|
activity("config", { action: "init" });
|
|
163
266
|
(0, output_1.printResult)(outputOptions(command), payload, "PRKT initialized");
|
|
164
267
|
});
|
|
268
|
+
program
|
|
269
|
+
.command("verify-session <sessionId>")
|
|
270
|
+
.option("--commitment <hash>", "on-chain commitment hash")
|
|
271
|
+
.description("verify an agent session log against the compressed session anchor on Solana devnet")
|
|
272
|
+
.action(async (sessionId, options) => {
|
|
273
|
+
const { SessionAnchor } = await Promise.resolve().then(() => __importStar(require("../anchoring/SessionAnchor")));
|
|
274
|
+
const { defaultPRKTConfig } = await Promise.resolve().then(() => __importStar(require("../config/PRKTConfig")));
|
|
275
|
+
const anchor = new SessionAnchor(defaultPRKTConfig.zkCompression.rpcEndpoint);
|
|
276
|
+
try {
|
|
277
|
+
const result = await anchor.verifySession(sessionId, options.commitment);
|
|
278
|
+
const output = outputOptions(program);
|
|
279
|
+
if (!output.json && result.valid) {
|
|
280
|
+
console.log(`Session valid ✓ | ${result.entryCount} entries | anchored at slot ${result.slot ?? "unknown"}`);
|
|
281
|
+
}
|
|
282
|
+
else if (!output.json) {
|
|
283
|
+
console.log(`Session invalid ✗${result.reason ? ` | ${result.reason}` : ""}`);
|
|
284
|
+
}
|
|
285
|
+
(0, output_1.printResult)(output, result, "Session verification");
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
(0, output_1.failWithMessage)(error);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
program
|
|
292
|
+
.command("verify-tx <txSignature>")
|
|
293
|
+
.description("verify a transaction's compressed policy proof on Solana devnet")
|
|
294
|
+
.action(async (txSignature) => {
|
|
295
|
+
const { ProofAnchor } = await Promise.resolve().then(() => __importStar(require("../zk/ProofAnchor")));
|
|
296
|
+
const { defaultPRKTConfig } = await Promise.resolve().then(() => __importStar(require("../config/PRKTConfig")));
|
|
297
|
+
const anchor = new ProofAnchor(defaultPRKTConfig.zkCompression.rpcEndpoint);
|
|
298
|
+
try {
|
|
299
|
+
const result = await anchor.verifyProof(txSignature);
|
|
300
|
+
const output = outputOptions(program);
|
|
301
|
+
if (!output.json && result.valid) {
|
|
302
|
+
console.log(`Policy attestation valid ✓ | prover ${result.attestation?.prover ?? "unknown"} | slot ${result.slot ?? "unknown"}`);
|
|
303
|
+
}
|
|
304
|
+
else if (!output.json) {
|
|
305
|
+
console.log(`Policy attestation invalid ✗${result.reason ? ` | ${result.reason}` : ""}`);
|
|
306
|
+
}
|
|
307
|
+
(0, output_1.printResult)(output, result, "Transaction proof verification");
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
(0, output_1.failWithMessage)(error);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
165
313
|
const wallet = program.command("wallet").description("wallet management and transfers");
|
|
166
314
|
wallet
|
|
167
315
|
.command("create")
|
|
@@ -1052,8 +1200,8 @@ program
|
|
|
1052
1200
|
status: (0, env_1.detectClusterFromRpcUrl)(rpc) === "devnet" ? "ok" : "warn"
|
|
1053
1201
|
});
|
|
1054
1202
|
try {
|
|
1055
|
-
const
|
|
1056
|
-
await
|
|
1203
|
+
const rpcClient = new RpcClient_1.RpcClient(rpc, "confirmed");
|
|
1204
|
+
await rpcClient.getLatestBlockhash("confirmed");
|
|
1057
1205
|
checks.push({
|
|
1058
1206
|
check: "rpc-connectivity",
|
|
1059
1207
|
details: rpc,
|
|
@@ -1067,21 +1215,11 @@ program
|
|
|
1067
1215
|
status: "fail"
|
|
1068
1216
|
});
|
|
1069
1217
|
}
|
|
1070
|
-
const
|
|
1071
|
-
const treasurySecretKey = (0, env_1.getOptionalDevnetTreasurySecretKey)();
|
|
1072
|
-
const treasuryExists = Boolean(remoteSigner ||
|
|
1073
|
-
treasurySecretKey ||
|
|
1074
|
-
(process.env.AGENT_PRIVATE_KEY && process.env.AGENT_PRIVATE_KEY.length > 0));
|
|
1218
|
+
const signerCheck = inspectSignerConfiguration();
|
|
1075
1219
|
checks.push({
|
|
1076
1220
|
check: "treasury-key",
|
|
1077
|
-
details:
|
|
1078
|
-
|
|
1079
|
-
: treasurySecretKey
|
|
1080
|
-
? "devnet treasury key present"
|
|
1081
|
-
: treasuryExists
|
|
1082
|
-
? "local demo key present"
|
|
1083
|
-
: "missing signer configuration",
|
|
1084
|
-
status: treasuryExists ? "ok" : "warn"
|
|
1221
|
+
details: signerCheck.detail,
|
|
1222
|
+
status: signerCheck.status
|
|
1085
1223
|
});
|
|
1086
1224
|
checks.push({
|
|
1087
1225
|
check: "custody-model",
|
|
@@ -1148,6 +1286,9 @@ program
|
|
|
1148
1286
|
});
|
|
1149
1287
|
async function main() {
|
|
1150
1288
|
try {
|
|
1289
|
+
if (shouldPrintStartupBanner(process.argv.slice(2))) {
|
|
1290
|
+
console.log(`${CLI_BANNER}\n`);
|
|
1291
|
+
}
|
|
1151
1292
|
await program.parseAsync(process.argv);
|
|
1152
1293
|
}
|
|
1153
1294
|
catch (error) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActivityRecord } from "../types";
|
|
2
|
+
export declare class ActivityStore {
|
|
3
|
+
append(record: ActivityRecord): void;
|
|
4
|
+
list(limit?: number): ActivityRecord[];
|
|
5
|
+
listByAgent(agent: string, limit?: number): ActivityRecord[];
|
|
6
|
+
private read;
|
|
7
|
+
private write;
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StoredAgentRecord } from "../types";
|
|
2
|
+
import { WalletRegistry } from "./walletRegistry";
|
|
3
|
+
export declare class AgentRegistryStore {
|
|
4
|
+
private readonly walletRegistry;
|
|
5
|
+
constructor(walletRegistry?: WalletRegistry);
|
|
6
|
+
list(): StoredAgentRecord[];
|
|
7
|
+
find(name: string): StoredAgentRecord | undefined;
|
|
8
|
+
ensureForWallet(walletName: string): StoredAgentRecord;
|
|
9
|
+
createAgent(input: {
|
|
10
|
+
agentId: string;
|
|
11
|
+
ownerId?: string;
|
|
12
|
+
walletName?: string;
|
|
13
|
+
}): StoredAgentRecord;
|
|
14
|
+
upsert(record: StoredAgentRecord): StoredAgentRecord;
|
|
15
|
+
patch(name: string, update: Partial<StoredAgentRecord>): StoredAgentRecord;
|
|
16
|
+
synchronizeWithWallets(): StoredAgentRecord[];
|
|
17
|
+
private read;
|
|
18
|
+
private write;
|
|
19
|
+
private normalize;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function getCliDataDir(): string;
|
|
2
|
+
export declare function resolveCliDataPath(fileName: string): string;
|
|
3
|
+
export declare function getCliHomeEnvName(): string;
|
|
4
|
+
export declare function probeCliDataDir(): {
|
|
5
|
+
details: string;
|
|
6
|
+
path: string;
|
|
7
|
+
writable: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RecoveryPackage, WalletCiphertext } from "../types";
|
|
2
|
+
export declare function encryptSecretKeyForPlatform(secretKey: Uint8Array): WalletCiphertext;
|
|
3
|
+
export declare function decryptSecretKeyForPlatform(payload: WalletCiphertext): Uint8Array;
|
|
4
|
+
export declare function createRecoveryPackage(secretKey: Uint8Array): {
|
|
5
|
+
recoveryKey: string;
|
|
6
|
+
recoveryPackage: RecoveryPackage;
|
|
7
|
+
};
|
|
8
|
+
export declare function decryptSecretKeyWithRecovery(input: {
|
|
9
|
+
recoveryKey: string;
|
|
10
|
+
recoveryPackage: RecoveryPackage;
|
|
11
|
+
}): Uint8Array;
|
|
12
|
+
export declare function getPlatformMasterKeySource(): "env" | "local-file";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StoredWalletRecord } from "../types";
|
|
2
|
+
import { WalletManager } from "../../core/wallet/WalletManager";
|
|
3
|
+
export type WalletProvisionResult = {
|
|
4
|
+
created: boolean;
|
|
5
|
+
record: StoredWalletRecord;
|
|
6
|
+
recoveryKey: string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare class WalletRegistry {
|
|
9
|
+
list(): StoredWalletRecord[];
|
|
10
|
+
find(name: string): StoredWalletRecord | undefined;
|
|
11
|
+
create(name: string): WalletProvisionResult;
|
|
12
|
+
toWalletManager(name: string): WalletManager;
|
|
13
|
+
ensureFromEnv(name: string): WalletProvisionResult;
|
|
14
|
+
exportSecretKeyWithRecovery(input: {
|
|
15
|
+
name: string;
|
|
16
|
+
recoveryKey: string;
|
|
17
|
+
}): Uint8Array;
|
|
18
|
+
private provision;
|
|
19
|
+
private requireRecord;
|
|
20
|
+
private read;
|
|
21
|
+
private write;
|
|
22
|
+
private maybeMigrateLegacyRecord;
|
|
23
|
+
private normalize;
|
|
24
|
+
private resolveSecretKey;
|
|
25
|
+
}
|
|
26
|
+
export declare function generateTemporaryWalletName(): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type StoredWalletRecord = {
|
|
2
|
+
createdAtIso: string;
|
|
3
|
+
encryptedSecretKey?: WalletCiphertext;
|
|
4
|
+
name: string;
|
|
5
|
+
publicKey: string;
|
|
6
|
+
recoveryPackage?: RecoveryPackage;
|
|
7
|
+
secretKey?: number[];
|
|
8
|
+
version?: 1 | 2;
|
|
9
|
+
};
|
|
10
|
+
export type WalletCiphertext = {
|
|
11
|
+
algorithm: "aes-256-gcm";
|
|
12
|
+
ciphertext: string;
|
|
13
|
+
iv: string;
|
|
14
|
+
tag: string;
|
|
15
|
+
};
|
|
16
|
+
export type RecoveryPackage = {
|
|
17
|
+
algorithm: "scrypt-aes-256-gcm";
|
|
18
|
+
ciphertext: string;
|
|
19
|
+
iv: string;
|
|
20
|
+
kdf: "scrypt";
|
|
21
|
+
salt: string;
|
|
22
|
+
tag: string;
|
|
23
|
+
};
|
|
24
|
+
export type ActivityKind = "wallet" | "transfer" | "token" | "policy" | "agent" | "monitor" | "demo" | "doctor" | "config";
|
|
25
|
+
export type ActivityRecord = {
|
|
26
|
+
agent?: string;
|
|
27
|
+
createdAtIso: string;
|
|
28
|
+
details: Record<string, unknown>;
|
|
29
|
+
kind: ActivityKind;
|
|
30
|
+
signature?: string;
|
|
31
|
+
};
|
|
32
|
+
export type StoredAgentRecord = {
|
|
33
|
+
createdAtIso: string;
|
|
34
|
+
lastAction?: string;
|
|
35
|
+
lastError?: string;
|
|
36
|
+
lastRunAtIso?: string;
|
|
37
|
+
lastSignature?: string;
|
|
38
|
+
name: string;
|
|
39
|
+
ownerId?: string;
|
|
40
|
+
policyMode: "sandbox" | "live";
|
|
41
|
+
policyOverrides?: StoredPolicyOverrides;
|
|
42
|
+
policyPreset: PolicyPresetName;
|
|
43
|
+
status: "active" | "stopped";
|
|
44
|
+
strategy: string;
|
|
45
|
+
strategyConfig?: Record<string, unknown>;
|
|
46
|
+
trackedMints?: string[];
|
|
47
|
+
walletName: string;
|
|
48
|
+
};
|
|
49
|
+
export type PolicyPresetName = "observe-only" | "simulate-only" | "auto-devnet-safe" | "guarded-live" | "custom";
|
|
50
|
+
export type StoredPolicyOverrides = {
|
|
51
|
+
allowOpaqueProgramIds?: string[];
|
|
52
|
+
allowedCloseAccountDestinations?: string[];
|
|
53
|
+
allowedMints?: string[];
|
|
54
|
+
allowedTransferDestinations?: string[];
|
|
55
|
+
approvalMode?: "sandbox" | "live";
|
|
56
|
+
denyUnknownInstructionsByDefault?: boolean;
|
|
57
|
+
extraAllowedProgramIds?: string[];
|
|
58
|
+
maxSolPerTxLamports?: number;
|
|
59
|
+
maxSplPerTxRawAmount?: string;
|
|
60
|
+
maxTransactionsPerDay?: number;
|
|
61
|
+
maxTransactionsPerSession?: number;
|
|
62
|
+
rejectSuspiciousBalanceDeltas?: boolean;
|
|
63
|
+
requireSimulationSuccess?: boolean;
|
|
64
|
+
sessionTtlMinutes?: number;
|
|
65
|
+
};
|
|
66
|
+
export type CliOutputOptions = {
|
|
67
|
+
json: boolean;
|
|
68
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CliOutputOptions } from "../types";
|
|
2
|
+
export declare function printResult(output: CliOutputOptions, payload: unknown, title?: string): void;
|
|
3
|
+
export declare function txExplorer(signature: string): string;
|
|
4
|
+
export declare function addressExplorer(address: string): string;
|
|
5
|
+
export declare function failWithMessage(error: unknown): never;
|
package/dist/cli/utils/output.js
CHANGED
|
@@ -8,9 +8,12 @@ exports.txExplorer = txExplorer;
|
|
|
8
8
|
exports.addressExplorer = addressExplorer;
|
|
9
9
|
exports.failWithMessage = failWithMessage;
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
function jsonReplacer(_, value) {
|
|
12
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
13
|
+
}
|
|
11
14
|
function printResult(output, payload, title) {
|
|
12
15
|
if (output.json) {
|
|
13
|
-
console.log(JSON.stringify(payload,
|
|
16
|
+
console.log(JSON.stringify(payload, jsonReplacer, 2));
|
|
14
17
|
return;
|
|
15
18
|
}
|
|
16
19
|
if (title) {
|