@agent-shield/sdk 0.4.1 → 0.5.2
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/LICENSE +191 -0
- package/README.md +10 -19
- package/dist/idl-json.d.ts +3 -3
- package/dist/idl-json.js +3 -3
- package/dist/idl-json.js.map +1 -1
- package/dist/idl.d.ts +3 -3
- package/dist/idl.d.ts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/wrapper/engine.d.ts +17 -0
- package/dist/wrapper/engine.d.ts.map +1 -0
- package/dist/wrapper/engine.js +45 -0
- package/dist/wrapper/engine.js.map +1 -0
- package/dist/wrapper/errors.d.ts +10 -0
- package/dist/wrapper/errors.d.ts.map +1 -0
- package/dist/wrapper/errors.js +20 -0
- package/dist/wrapper/errors.js.map +1 -0
- package/dist/wrapper/harden.d.ts +119 -0
- package/dist/wrapper/harden.d.ts.map +1 -0
- package/dist/wrapper/harden.js +399 -0
- package/dist/wrapper/harden.js.map +1 -0
- package/dist/wrapper/index.d.ts +17 -0
- package/dist/wrapper/index.d.ts.map +1 -0
- package/dist/wrapper/index.js +60 -0
- package/dist/wrapper/index.js.map +1 -0
- package/dist/wrapper/inspector.d.ts +22 -0
- package/dist/wrapper/inspector.d.ts.map +1 -0
- package/dist/wrapper/inspector.js +175 -0
- package/dist/wrapper/inspector.js.map +1 -0
- package/dist/wrapper/policies.d.ts +78 -0
- package/dist/wrapper/policies.d.ts.map +1 -0
- package/dist/wrapper/policies.js +108 -0
- package/dist/wrapper/policies.js.map +1 -0
- package/dist/wrapper/registry.d.ts +24 -0
- package/dist/wrapper/registry.d.ts.map +1 -0
- package/dist/wrapper/registry.js +43 -0
- package/dist/wrapper/registry.js.map +1 -0
- package/dist/wrapper/shield.d.ts +86 -0
- package/dist/wrapper/shield.d.ts.map +1 -0
- package/dist/wrapper/shield.js +236 -0
- package/dist/wrapper/shield.js.map +1 -0
- package/dist/wrapper/state.d.ts +3 -0
- package/dist/wrapper/state.d.ts.map +1 -0
- package/dist/wrapper/state.js +6 -0
- package/dist/wrapper/state.js.map +1 -0
- package/dist/wrapper/x402.d.ts +153 -0
- package/dist/wrapper/x402.d.ts.map +1 -0
- package/dist/wrapper/x402.js +342 -0
- package/dist/wrapper/x402.js.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PublicKey, Connection, Keypair } from "@solana/web3.js";
|
|
2
|
+
import { ShieldedWallet, WalletLike } from "./shield";
|
|
3
|
+
import { ResolvedPolicies } from "./policies";
|
|
4
|
+
import type { ShieldPolicies } from "./policies";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for hardening a shielded wallet to on-chain enforcement.
|
|
7
|
+
*/
|
|
8
|
+
export interface HardenOptions {
|
|
9
|
+
/** Solana RPC connection */
|
|
10
|
+
connection: Connection;
|
|
11
|
+
/** Owner wallet — vault administrator. Auto-generates a Keypair if omitted. */
|
|
12
|
+
ownerWallet?: WalletLike;
|
|
13
|
+
/** Vault ID (auto-incremented if not provided) */
|
|
14
|
+
vaultId?: number;
|
|
15
|
+
/** Fee destination for the vault */
|
|
16
|
+
feeDestination?: PublicKey;
|
|
17
|
+
/** Developer fee rate (0-500, maps to on-chain rate). Default: 0 */
|
|
18
|
+
developerFeeRate?: number;
|
|
19
|
+
/** Override program ID (for devnet/testing) */
|
|
20
|
+
programId?: PublicKey;
|
|
21
|
+
/** Maximum leverage in basis points. Default: 0 */
|
|
22
|
+
maxLeverageBps?: number;
|
|
23
|
+
/** Maximum concurrent positions. Default: 5 */
|
|
24
|
+
maxConcurrentPositions?: number;
|
|
25
|
+
/** Skip TEE wallet requirement — devnet testing only. Default: false */
|
|
26
|
+
unsafeSkipTeeCheck?: boolean;
|
|
27
|
+
/** Auto-provision a TEE wallet from a custody provider */
|
|
28
|
+
teeProvider?: "crossmint" | "turnkey" | "privy";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of hardening a shielded wallet.
|
|
32
|
+
*/
|
|
33
|
+
export interface HardenResult {
|
|
34
|
+
/** Hardened wallet with dual enforcement (client-side + on-chain) */
|
|
35
|
+
wallet: ShieldedWallet;
|
|
36
|
+
/** The owner keypair, only set if ownerWallet was NOT provided */
|
|
37
|
+
ownerKeypair?: Keypair;
|
|
38
|
+
/** The vault PDA address */
|
|
39
|
+
vaultAddress: PublicKey;
|
|
40
|
+
/** The vault ID used */
|
|
41
|
+
vaultId: number;
|
|
42
|
+
/** The policy PDA address */
|
|
43
|
+
policyAddress: PublicKey;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Map resolved client-side policies to on-chain InitializeVaultParams.
|
|
47
|
+
*
|
|
48
|
+
* Multiple per-token SpendLimits collapse to the largest value as the
|
|
49
|
+
* on-chain dailySpendingCap (conservative ceiling). Per-token granularity
|
|
50
|
+
* is enforced client-side. Fields with no on-chain equivalent
|
|
51
|
+
* (blockUnknownPrograms, rateLimit, customCheck) stay client-side only.
|
|
52
|
+
*/
|
|
53
|
+
export declare function mapPoliciesToVaultParams(resolved: ResolvedPolicies, vaultId: number, feeDestination: PublicKey, opts?: {
|
|
54
|
+
developerFeeRate?: number;
|
|
55
|
+
maxLeverageBps?: number;
|
|
56
|
+
maxConcurrentPositions?: number;
|
|
57
|
+
}): {
|
|
58
|
+
vaultId: any;
|
|
59
|
+
dailySpendingCap: bigint;
|
|
60
|
+
maxTransactionSize: bigint;
|
|
61
|
+
allowedTokens: PublicKey[];
|
|
62
|
+
allowedProtocols: PublicKey[];
|
|
63
|
+
maxLeverageBps: number;
|
|
64
|
+
maxConcurrentPositions: number;
|
|
65
|
+
feeDestination: PublicKey;
|
|
66
|
+
developerFeeRate: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Probe vault PDAs starting from 0 to find the next available vault ID.
|
|
70
|
+
* Returns 0 for a new owner, or the first unused ID.
|
|
71
|
+
*/
|
|
72
|
+
export declare function findNextVaultId(connection: Connection, ownerPubkey: PublicKey, programId?: PublicKey): Promise<number>;
|
|
73
|
+
/**
|
|
74
|
+
* Harden a shielded wallet with on-chain vault enforcement.
|
|
75
|
+
*
|
|
76
|
+
* Creates an on-chain AgentShield vault, registers the wallet as an agent,
|
|
77
|
+
* and configures policies matching the wrapper config. Requires a TEE-backed
|
|
78
|
+
* wallet unless unsafeSkipTeeCheck is set (devnet only).
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { withVault } from '@agent-shield/sdk';
|
|
83
|
+
*
|
|
84
|
+
* const result = await withVault(teeWallet, { maxSpend: '500 USDC/day' }, {
|
|
85
|
+
* connection,
|
|
86
|
+
* });
|
|
87
|
+
* // result.wallet is ready with full on-chain enforcement
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function harden(shieldedWallet: ShieldedWallet, options: HardenOptions): Promise<HardenResult>;
|
|
91
|
+
/**
|
|
92
|
+
* The primary developer-facing function. Wraps a wallet with client-side policy
|
|
93
|
+
* enforcement and hardens it to on-chain vault enforcement in one call.
|
|
94
|
+
*
|
|
95
|
+
* One call = full protection: client-side fast deny + on-chain vault enforcement.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { withVault } from '@agent-shield/sdk';
|
|
100
|
+
*
|
|
101
|
+
* // Simplest path: bring your TEE wallet
|
|
102
|
+
* const result = await withVault(teeWallet, { maxSpend: '500 USDC/day' }, {
|
|
103
|
+
* connection,
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Devnet testing (no TEE required)
|
|
107
|
+
* const result = await withVault(wallet, { maxSpend: '500 USDC/day' }, {
|
|
108
|
+
* connection,
|
|
109
|
+
* unsafeSkipTeeCheck: true,
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function withVault(wallet: WalletLike, policies: ShieldPolicies | undefined, options: HardenOptions): Promise<HardenResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Public API for client-side-only shielding (no on-chain vault).
|
|
116
|
+
* For most users, prefer withVault() for full enforcement.
|
|
117
|
+
*/
|
|
118
|
+
export declare function shieldWallet(wallet: WalletLike, policies?: ShieldPolicies, options?: import("./shield").ShieldOptions): ShieldedWallet;
|
|
119
|
+
//# sourceMappingURL=harden.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harden.d.ts","sourceRoot":"","sources":["../../src/wrapper/harden.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,OAAO,EAMR,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAuB,MAAM,YAAY,CAAC;AAWnE,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,YAAY,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0DAA0D;IAC1D,WAAW,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,wBAAsB,SAAS,CAC7B,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAGvB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAClB,QAAQ,CAAC,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,OAAO,UAAU,EAAE,aAAa,GACzC,cAAc,CAEhB"}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapPoliciesToVaultParams = mapPoliciesToVaultParams;
|
|
4
|
+
exports.findNextVaultId = findNextVaultId;
|
|
5
|
+
exports.harden = harden;
|
|
6
|
+
exports.withVault = withVault;
|
|
7
|
+
exports.shieldWallet = shieldWallet;
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
10
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
11
|
+
const shield_1 = require("./shield");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
const inspector_1 = require("./inspector");
|
|
14
|
+
const engine_1 = require("./engine");
|
|
15
|
+
const shield_2 = require("./shield");
|
|
16
|
+
const registry_1 = require("./registry");
|
|
17
|
+
const client_1 = require("../client");
|
|
18
|
+
const accounts_1 = require("../accounts");
|
|
19
|
+
const composer_1 = require("../composer");
|
|
20
|
+
const idl_json_1 = require("../idl-json");
|
|
21
|
+
/**
|
|
22
|
+
* Map resolved client-side policies to on-chain InitializeVaultParams.
|
|
23
|
+
*
|
|
24
|
+
* Multiple per-token SpendLimits collapse to the largest value as the
|
|
25
|
+
* on-chain dailySpendingCap (conservative ceiling). Per-token granularity
|
|
26
|
+
* is enforced client-side. Fields with no on-chain equivalent
|
|
27
|
+
* (blockUnknownPrograms, rateLimit, customCheck) stay client-side only.
|
|
28
|
+
*/
|
|
29
|
+
function mapPoliciesToVaultParams(resolved, vaultId, feeDestination, opts) {
|
|
30
|
+
// Collapse multiple spend limits to the largest (ceiling cap)
|
|
31
|
+
let maxCap = BigInt(0);
|
|
32
|
+
const tokenMintSet = new Set();
|
|
33
|
+
for (const limit of resolved.spendLimits) {
|
|
34
|
+
if (limit.amount > maxCap) {
|
|
35
|
+
maxCap = limit.amount;
|
|
36
|
+
}
|
|
37
|
+
// Collect token mints from spend limits
|
|
38
|
+
tokenMintSet.add(limit.mint);
|
|
39
|
+
}
|
|
40
|
+
// Merge explicitly allowed tokens (deduped) — allowedTokens is Set<string>|undefined
|
|
41
|
+
if (resolved.allowedTokens) {
|
|
42
|
+
for (const t of resolved.allowedTokens) {
|
|
43
|
+
tokenMintSet.add(t);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Cap at 10 tokens (on-chain limit)
|
|
47
|
+
const allowedTokens = Array.from(tokenMintSet)
|
|
48
|
+
.slice(0, 10)
|
|
49
|
+
.map((s) => new web3_js_1.PublicKey(s));
|
|
50
|
+
// Allowed protocols (Set<string>|undefined), cap at 10
|
|
51
|
+
const protocolArr = resolved.allowedProtocols
|
|
52
|
+
? Array.from(resolved.allowedProtocols)
|
|
53
|
+
: [];
|
|
54
|
+
const allowedProtocols = protocolArr
|
|
55
|
+
.slice(0, 10)
|
|
56
|
+
.map((s) => new web3_js_1.PublicKey(s));
|
|
57
|
+
// maxTransactionSize: use resolved value, fall back to dailySpendingCap
|
|
58
|
+
const maxTransactionSize = resolved.maxTransactionSize ?? maxCap;
|
|
59
|
+
return {
|
|
60
|
+
vaultId,
|
|
61
|
+
dailySpendingCap: maxCap,
|
|
62
|
+
maxTransactionSize,
|
|
63
|
+
allowedTokens,
|
|
64
|
+
allowedProtocols,
|
|
65
|
+
maxLeverageBps: opts?.maxLeverageBps ?? 0,
|
|
66
|
+
maxConcurrentPositions: opts?.maxConcurrentPositions ?? 5,
|
|
67
|
+
feeDestination,
|
|
68
|
+
developerFeeRate: opts?.developerFeeRate ?? 0,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Probe vault PDAs starting from 0 to find the next available vault ID.
|
|
73
|
+
* Returns 0 for a new owner, or the first unused ID.
|
|
74
|
+
*/
|
|
75
|
+
async function findNextVaultId(connection, ownerPubkey, programId) {
|
|
76
|
+
for (let id = 0; id <= 255; id++) {
|
|
77
|
+
const [vaultPda] = (0, accounts_1.getVaultPDA)(ownerPubkey, new anchor_1.BN(id), programId);
|
|
78
|
+
const account = await connection.getAccountInfo(vaultPda);
|
|
79
|
+
if (!account) {
|
|
80
|
+
return id;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new Error("All 256 vault slots are in use for this owner.");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Infer the token mint from a transaction analysis.
|
|
87
|
+
* Uses the first outgoing transfer's mint, falls back to SOL mint.
|
|
88
|
+
*/
|
|
89
|
+
function inferTokenMint(analysis) {
|
|
90
|
+
const SOL_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
|
|
91
|
+
const outgoing = analysis.transfers.find((t) => t.direction === "outgoing");
|
|
92
|
+
if (outgoing && !outgoing.mint.equals(web3_js_1.PublicKey.default)) {
|
|
93
|
+
return outgoing.mint;
|
|
94
|
+
}
|
|
95
|
+
return SOL_MINT;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Infer the total outgoing amount from a transaction analysis.
|
|
99
|
+
*/
|
|
100
|
+
function inferAmount(analysis) {
|
|
101
|
+
return analysis.transfers
|
|
102
|
+
.filter((t) => t.direction === "outgoing")
|
|
103
|
+
.reduce((sum, t) => sum + t.amount, BigInt(0));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Infer the target protocol from a transaction analysis.
|
|
107
|
+
* Returns the first non-system program ID, or SystemProgram.
|
|
108
|
+
*/
|
|
109
|
+
function inferTargetProtocol(analysis) {
|
|
110
|
+
const SYSTEM_PROGRAM = new web3_js_1.PublicKey("11111111111111111111111111111111");
|
|
111
|
+
for (const pid of analysis.programIds) {
|
|
112
|
+
if (!pid.equals(SYSTEM_PROGRAM)) {
|
|
113
|
+
return pid;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return SYSTEM_PROGRAM;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Infer the ActionType from a transaction analysis.
|
|
120
|
+
*
|
|
121
|
+
* Pure SPL token transfer transactions → Transfer.
|
|
122
|
+
* Everything else (Jupiter, Flash Trade, etc.) → Swap.
|
|
123
|
+
*/
|
|
124
|
+
function inferActionType(instructions) {
|
|
125
|
+
const TOKEN_2022_PROGRAM = new web3_js_1.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
126
|
+
const nonSystemIxs = instructions.filter((ix) => !(0, registry_1.isSystemProgram)(ix.programId) &&
|
|
127
|
+
!ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
|
|
128
|
+
const allAreTokenTransfers = nonSystemIxs.length > 0 &&
|
|
129
|
+
nonSystemIxs.every((ix) => ix.programId.equals(spl_token_1.TOKEN_PROGRAM_ID) ||
|
|
130
|
+
ix.programId.equals(TOKEN_2022_PROGRAM));
|
|
131
|
+
return allAreTokenTransfers ? { transfer: {} } : { swap: {} };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a hardened wallet that enforces policies both client-side and on-chain.
|
|
135
|
+
*
|
|
136
|
+
* Dual enforcement flow:
|
|
137
|
+
* 1. Client-side policy check (fast deny)
|
|
138
|
+
* 2. If approved, compose transaction with validate+authorize + original ixs + finalize
|
|
139
|
+
* 3. Sign composed transaction with agent's inner wallet
|
|
140
|
+
*/
|
|
141
|
+
function createHardenedWallet(original, vaultAddress, ownerPubkey, vaultId, connection, programId) {
|
|
142
|
+
const innerWallet = original.innerWallet;
|
|
143
|
+
const state = original.shieldState;
|
|
144
|
+
// We need the resolved policies and the pause state from the original
|
|
145
|
+
// shield for client-side enforcement. We'll delegate to the original
|
|
146
|
+
// for policy evaluation, but override signTransaction.
|
|
147
|
+
const hardened = {
|
|
148
|
+
publicKey: original.publicKey,
|
|
149
|
+
innerWallet,
|
|
150
|
+
shieldState: state,
|
|
151
|
+
isHardened: true,
|
|
152
|
+
get resolvedPolicies() {
|
|
153
|
+
return original.resolvedPolicies;
|
|
154
|
+
},
|
|
155
|
+
get isPaused() {
|
|
156
|
+
return original.isPaused;
|
|
157
|
+
},
|
|
158
|
+
async signTransaction(tx) {
|
|
159
|
+
// If paused, pass through without enforcement
|
|
160
|
+
if (original.isPaused) {
|
|
161
|
+
return innerWallet.signTransaction(tx);
|
|
162
|
+
}
|
|
163
|
+
// Step 1: Client-side policy check (fast deny)
|
|
164
|
+
let lookupTableAccounts;
|
|
165
|
+
if (tx instanceof web3_js_1.VersionedTransaction &&
|
|
166
|
+
tx.message.addressTableLookups.length > 0) {
|
|
167
|
+
lookupTableAccounts = await (0, inspector_1.resolveTransactionAddressLookupTables)(tx, connection);
|
|
168
|
+
}
|
|
169
|
+
const analysis = (0, inspector_1.analyzeTransaction)(tx, innerWallet.publicKey, lookupTableAccounts);
|
|
170
|
+
const violations = (0, engine_1.evaluatePolicy)(analysis, original.resolvedPolicies, state);
|
|
171
|
+
if (violations.length > 0) {
|
|
172
|
+
throw new errors_1.ShieldDeniedError(violations);
|
|
173
|
+
}
|
|
174
|
+
// Step 2: Extract original instructions and compose with vault enforcement
|
|
175
|
+
const originalIxs = (0, inspector_1.extractInstructions)(tx, lookupTableAccounts);
|
|
176
|
+
const tokenMint = inferTokenMint(analysis);
|
|
177
|
+
const amount = inferAmount(analysis);
|
|
178
|
+
const targetProtocol = inferTargetProtocol(analysis);
|
|
179
|
+
const vaultTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, vaultAddress, true);
|
|
180
|
+
const program = createProgram(connection, innerWallet, programId);
|
|
181
|
+
const composedTx = await (0, composer_1.composePermittedTransaction)(program, connection, {
|
|
182
|
+
vault: vaultAddress,
|
|
183
|
+
owner: ownerPubkey,
|
|
184
|
+
vaultId: new anchor_1.BN(vaultId),
|
|
185
|
+
agent: innerWallet.publicKey,
|
|
186
|
+
actionType: inferActionType(originalIxs),
|
|
187
|
+
tokenMint,
|
|
188
|
+
amount: new anchor_1.BN(amount.toString()),
|
|
189
|
+
targetProtocol,
|
|
190
|
+
defiInstructions: originalIxs,
|
|
191
|
+
vaultTokenAccount,
|
|
192
|
+
});
|
|
193
|
+
// Step 3: Sign the composed transaction with the inner wallet
|
|
194
|
+
const signed = await innerWallet.signTransaction(composedTx);
|
|
195
|
+
// Step 4: Record in client-side state
|
|
196
|
+
(0, engine_1.recordTransaction)(analysis, state);
|
|
197
|
+
return signed;
|
|
198
|
+
},
|
|
199
|
+
async signAllTransactions(txs) {
|
|
200
|
+
const results = [];
|
|
201
|
+
for (const tx of txs) {
|
|
202
|
+
results.push(await hardened.signTransaction(tx));
|
|
203
|
+
}
|
|
204
|
+
return results;
|
|
205
|
+
},
|
|
206
|
+
updatePolicies(policies) {
|
|
207
|
+
original.updatePolicies(policies);
|
|
208
|
+
},
|
|
209
|
+
resetState() {
|
|
210
|
+
original.resetState();
|
|
211
|
+
},
|
|
212
|
+
pause() {
|
|
213
|
+
original.pause();
|
|
214
|
+
},
|
|
215
|
+
resume() {
|
|
216
|
+
original.resume();
|
|
217
|
+
},
|
|
218
|
+
getSpendingSummary() {
|
|
219
|
+
return original.getSpendingSummary();
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
// Expose vault metadata for x402 hardened path
|
|
223
|
+
hardened._vaultAddress = vaultAddress;
|
|
224
|
+
hardened._vaultId = vaultId;
|
|
225
|
+
hardened._programId = programId;
|
|
226
|
+
hardened._ownerPubkey = ownerPubkey;
|
|
227
|
+
hardened._connection = connection;
|
|
228
|
+
return hardened;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create a Program instance for vault operations.
|
|
232
|
+
* Uses the inner wallet as the signer.
|
|
233
|
+
*/
|
|
234
|
+
function createProgram(connection, wallet, programId) {
|
|
235
|
+
const provider = new anchor_1.AnchorProvider(connection, wallet, {
|
|
236
|
+
commitment: "confirmed",
|
|
237
|
+
});
|
|
238
|
+
const idl = { ...idl_json_1.IDL };
|
|
239
|
+
if (programId) {
|
|
240
|
+
idl.address = programId.toBase58();
|
|
241
|
+
}
|
|
242
|
+
return new anchor_1.Program(idl, provider);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create an Anchor Wallet from a WalletLike.
|
|
246
|
+
* If the wallet has a `payer` property (Keypair-based), use it directly.
|
|
247
|
+
* Otherwise create a wrapper that delegates to signTransaction.
|
|
248
|
+
*/
|
|
249
|
+
function toAnchorWallet(wallet) {
|
|
250
|
+
return {
|
|
251
|
+
publicKey: wallet.publicKey,
|
|
252
|
+
signTransaction: wallet.signTransaction.bind(wallet),
|
|
253
|
+
signAllTransactions: wallet.signAllTransactions?.bind(wallet) ??
|
|
254
|
+
((txs) => Promise.all(txs.map((tx) => wallet.signTransaction(tx)))),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Harden a shielded wallet with on-chain vault enforcement.
|
|
259
|
+
*
|
|
260
|
+
* Creates an on-chain AgentShield vault, registers the wallet as an agent,
|
|
261
|
+
* and configures policies matching the wrapper config. Requires a TEE-backed
|
|
262
|
+
* wallet unless unsafeSkipTeeCheck is set (devnet only).
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* import { withVault } from '@agent-shield/sdk';
|
|
267
|
+
*
|
|
268
|
+
* const result = await withVault(teeWallet, { maxSpend: '500 USDC/day' }, {
|
|
269
|
+
* connection,
|
|
270
|
+
* });
|
|
271
|
+
* // result.wallet is ready with full on-chain enforcement
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
async function harden(shieldedWallet, options) {
|
|
275
|
+
// Resolve owner: use provided wallet or auto-generate a keypair
|
|
276
|
+
let ownerKeypair;
|
|
277
|
+
let ownerWallet;
|
|
278
|
+
if (options.ownerWallet) {
|
|
279
|
+
ownerWallet = options.ownerWallet;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
ownerKeypair = web3_js_1.Keypair.generate();
|
|
283
|
+
ownerWallet = {
|
|
284
|
+
publicKey: ownerKeypair.publicKey,
|
|
285
|
+
async signTransaction(tx) {
|
|
286
|
+
if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
287
|
+
tx.sign([ownerKeypair]);
|
|
288
|
+
return tx;
|
|
289
|
+
}
|
|
290
|
+
tx.partialSign(ownerKeypair);
|
|
291
|
+
return tx;
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const agentPubkey = shieldedWallet.innerWallet.publicKey;
|
|
296
|
+
const ownerPubkey = ownerWallet.publicKey;
|
|
297
|
+
// Validate owner != agent
|
|
298
|
+
if (ownerPubkey.equals(agentPubkey)) {
|
|
299
|
+
throw new Error("Owner and agent must be different keys. The wallet passed to shield() is the agent key. " +
|
|
300
|
+
"Provide a different ownerWallet in HardenOptions, or omit it to auto-generate one.");
|
|
301
|
+
}
|
|
302
|
+
// Enforce TEE requirement — production agents must use TEE custody
|
|
303
|
+
if (!options.unsafeSkipTeeCheck && !(0, shield_1.isTeeWallet)(shieldedWallet.innerWallet)) {
|
|
304
|
+
throw new errors_1.TeeRequiredError();
|
|
305
|
+
}
|
|
306
|
+
// Create client with owner wallet (owner signs vault creation + agent registration)
|
|
307
|
+
const client = new client_1.AgentShieldClient(options.connection, toAnchorWallet(ownerWallet), options.programId);
|
|
308
|
+
// Find next vault ID if not provided
|
|
309
|
+
const vaultId = options.vaultId ??
|
|
310
|
+
(await findNextVaultId(options.connection, ownerPubkey, options.programId));
|
|
311
|
+
// Map policies to vault params
|
|
312
|
+
const feeDestination = options.feeDestination ?? ownerPubkey;
|
|
313
|
+
const mapped = mapPoliciesToVaultParams(shieldedWallet.resolvedPolicies, vaultId, feeDestination, {
|
|
314
|
+
developerFeeRate: options.developerFeeRate,
|
|
315
|
+
maxLeverageBps: options.maxLeverageBps,
|
|
316
|
+
maxConcurrentPositions: options.maxConcurrentPositions,
|
|
317
|
+
});
|
|
318
|
+
// Convert bigints to BN and wrap tokens as AllowedToken for the SDK
|
|
319
|
+
const vaultParams = {
|
|
320
|
+
vaultId: new anchor_1.BN(mapped.vaultId),
|
|
321
|
+
dailySpendingCapUsd: new anchor_1.BN(mapped.dailySpendingCap.toString()),
|
|
322
|
+
maxTransactionSizeUsd: new anchor_1.BN(mapped.maxTransactionSize.toString()),
|
|
323
|
+
allowedTokens: mapped.allowedTokens.map((mint) => ({
|
|
324
|
+
mint,
|
|
325
|
+
oracleFeed: web3_js_1.PublicKey.default, // stablecoin (1:1 USD) by default
|
|
326
|
+
decimals: 6,
|
|
327
|
+
dailyCapBase: new anchor_1.BN(0),
|
|
328
|
+
maxTxBase: new anchor_1.BN(0),
|
|
329
|
+
})),
|
|
330
|
+
allowedProtocols: mapped.allowedProtocols,
|
|
331
|
+
maxLeverageBps: mapped.maxLeverageBps,
|
|
332
|
+
maxConcurrentPositions: mapped.maxConcurrentPositions,
|
|
333
|
+
feeDestination: mapped.feeDestination,
|
|
334
|
+
developerFeeRate: mapped.developerFeeRate,
|
|
335
|
+
};
|
|
336
|
+
// Create vault (signed by owner)
|
|
337
|
+
try {
|
|
338
|
+
await client.createVault(vaultParams);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
throw new Error(`Failed to create on-chain vault: ${err.message ?? err}. ` +
|
|
342
|
+
"Ensure the owner wallet has enough SOL for rent.");
|
|
343
|
+
}
|
|
344
|
+
// Derive vault PDA address
|
|
345
|
+
const [vaultAddress] = client.getVaultPDA(ownerPubkey, new anchor_1.BN(vaultId));
|
|
346
|
+
const [policyAddress] = client.getPolicyPDA(vaultAddress);
|
|
347
|
+
// Register agent (signed by owner)
|
|
348
|
+
try {
|
|
349
|
+
await client.registerAgent(vaultAddress, agentPubkey);
|
|
350
|
+
}
|
|
351
|
+
catch (err) {
|
|
352
|
+
throw new Error(`Vault created at ${vaultAddress.toBase58()} but agent registration failed: ${err.message ?? err}. ` +
|
|
353
|
+
"You can manually register the agent using the vault SDK: " +
|
|
354
|
+
`client.registerAgent(new PublicKey("${vaultAddress.toBase58()}"), agentPubkey)`);
|
|
355
|
+
}
|
|
356
|
+
// Build hardened wallet with dual enforcement
|
|
357
|
+
const wallet = createHardenedWallet(shieldedWallet, vaultAddress, ownerPubkey, vaultId, options.connection, options.programId);
|
|
358
|
+
return {
|
|
359
|
+
wallet,
|
|
360
|
+
ownerKeypair,
|
|
361
|
+
vaultAddress,
|
|
362
|
+
vaultId,
|
|
363
|
+
policyAddress,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The primary developer-facing function. Wraps a wallet with client-side policy
|
|
368
|
+
* enforcement and hardens it to on-chain vault enforcement in one call.
|
|
369
|
+
*
|
|
370
|
+
* One call = full protection: client-side fast deny + on-chain vault enforcement.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* import { withVault } from '@agent-shield/sdk';
|
|
375
|
+
*
|
|
376
|
+
* // Simplest path: bring your TEE wallet
|
|
377
|
+
* const result = await withVault(teeWallet, { maxSpend: '500 USDC/day' }, {
|
|
378
|
+
* connection,
|
|
379
|
+
* });
|
|
380
|
+
*
|
|
381
|
+
* // Devnet testing (no TEE required)
|
|
382
|
+
* const result = await withVault(wallet, { maxSpend: '500 USDC/day' }, {
|
|
383
|
+
* connection,
|
|
384
|
+
* unsafeSkipTeeCheck: true,
|
|
385
|
+
* });
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
async function withVault(wallet, policies, options) {
|
|
389
|
+
const shielded = (0, shield_2.shield)(wallet, policies);
|
|
390
|
+
return harden(shielded, options);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Public API for client-side-only shielding (no on-chain vault).
|
|
394
|
+
* For most users, prefer withVault() for full enforcement.
|
|
395
|
+
*/
|
|
396
|
+
function shieldWallet(wallet, policies, options) {
|
|
397
|
+
return (0, shield_2.shield)(wallet, policies, options);
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=harden.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harden.js","sourceRoot":"","sources":["../../src/wrapper/harden.ts"],"names":[],"mappings":";;AAmFA,4DAkEC;AAMD,0CAaC;AA8QD,wBAiIC;AAwBD,8BAOC;AAMD,oCAMC;AAlmBD,6CASyB;AACzB,iDAG2B;AAC3B,8CAAgE;AAChE,qCAAmE;AAEnE,qCAA+D;AAC/D,2CAIqB;AACrB,qCAA6D;AAE7D,qCAAkC;AAClC,yCAA6C;AAE7C,sCAA8C;AAC9C,0CAAwD;AACxD,0CAA0D;AAC1D,0CAAkC;AA4ClC;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CACtC,QAA0B,EAC1B,OAAe,EACf,cAAyB,EACzB,IAIC;IAYD,8DAA8D;IAC9D,IAAI,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IAEvC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YAC1B,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QACxB,CAAC;QACD,wCAAwC;QACxC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,qFAAqF;IACrF,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YACvC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC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@
|
|
|
1
|
+
export { harden, withVault, shieldWallet, mapPoliciesToVaultParams, findNextVaultId, } from "./harden";
|
|
2
|
+
export type { HardenOptions, HardenResult } from "./harden";
|
|
3
|
+
export type { ShieldedWallet, WalletLike, ShieldOptions } from "./shield";
|
|
4
|
+
export { isTeeWallet } from "./shield";
|
|
5
|
+
export type { TeeWallet } from "./shield";
|
|
6
|
+
export type { ShieldPolicies, SpendLimit, SpendingSummary, RateLimitConfig, PolicyCheckResult, TransactionAnalysis, TokenTransfer, ResolvedPolicies, } from "./policies";
|
|
7
|
+
export { parseSpendLimit, resolvePolicies, DEFAULT_POLICIES } from "./policies";
|
|
8
|
+
export { ShieldDeniedError, ShieldConfigError, TeeRequiredError, } from "./errors";
|
|
9
|
+
export type { PolicyViolation } from "./errors";
|
|
10
|
+
export { analyzeTransaction, getNonSystemProgramIds, resolveTransactionAddressLookupTables, extractInstructions, } from "./inspector";
|
|
11
|
+
export { KNOWN_PROTOCOLS, KNOWN_TOKENS, SYSTEM_PROGRAMS, getTokenInfo, getProtocolName, isSystemProgram, isKnownProtocol, } from "./registry";
|
|
12
|
+
export { ShieldState } from "./state";
|
|
13
|
+
export type { ShieldStorage, SpendEntry as ClientSpendEntry, TxEntry, } from "./state";
|
|
14
|
+
export { evaluatePolicy, enforcePolicy, recordTransaction } from "./engine";
|
|
15
|
+
export { shieldedFetch, createShieldedFetchForWallet, selectPaymentOption, evaluateX402Payment, buildX402TransferInstruction, encodeX402Payload, decodePaymentRequiredHeader, encodePaymentSignatureHeader, decodePaymentResponseHeader, X402ParseError, X402PaymentError, X402UnsupportedError, } from "./x402";
|
|
16
|
+
export type { ShieldedFetchOptions, ShieldedFetchResponse, X402PaymentResult, PaymentRequired, PaymentRequirements, PaymentPayload, ResourceInfo, SettleResponse, } from "./x402";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wrapper/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5B,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,QAAQ,CAAC;AAChB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Wrapper — client-side policy enforcement + on-chain hardening
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.X402UnsupportedError = exports.X402PaymentError = exports.X402ParseError = exports.decodePaymentResponseHeader = exports.encodePaymentSignatureHeader = exports.decodePaymentRequiredHeader = exports.encodeX402Payload = exports.buildX402TransferInstruction = exports.evaluateX402Payment = exports.selectPaymentOption = exports.createShieldedFetchForWallet = exports.shieldedFetch = exports.recordTransaction = exports.enforcePolicy = exports.evaluatePolicy = exports.ShieldState = exports.isKnownProtocol = exports.isSystemProgram = exports.getProtocolName = exports.getTokenInfo = exports.SYSTEM_PROGRAMS = exports.KNOWN_TOKENS = exports.KNOWN_PROTOCOLS = exports.extractInstructions = exports.resolveTransactionAddressLookupTables = exports.getNonSystemProgramIds = exports.analyzeTransaction = exports.TeeRequiredError = exports.ShieldConfigError = exports.ShieldDeniedError = exports.DEFAULT_POLICIES = exports.resolvePolicies = exports.parseSpendLimit = exports.isTeeWallet = exports.findNextVaultId = exports.mapPoliciesToVaultParams = exports.shieldWallet = exports.withVault = exports.harden = void 0;
|
|
5
|
+
// Main API — harden() and withVault() are the primary entry points
|
|
6
|
+
var harden_1 = require("./harden");
|
|
7
|
+
Object.defineProperty(exports, "harden", { enumerable: true, get: function () { return harden_1.harden; } });
|
|
8
|
+
Object.defineProperty(exports, "withVault", { enumerable: true, get: function () { return harden_1.withVault; } });
|
|
9
|
+
Object.defineProperty(exports, "shieldWallet", { enumerable: true, get: function () { return harden_1.shieldWallet; } });
|
|
10
|
+
Object.defineProperty(exports, "mapPoliciesToVaultParams", { enumerable: true, get: function () { return harden_1.mapPoliciesToVaultParams; } });
|
|
11
|
+
Object.defineProperty(exports, "findNextVaultId", { enumerable: true, get: function () { return harden_1.findNextVaultId; } });
|
|
12
|
+
var shield_1 = require("./shield");
|
|
13
|
+
Object.defineProperty(exports, "isTeeWallet", { enumerable: true, get: function () { return shield_1.isTeeWallet; } });
|
|
14
|
+
var policies_1 = require("./policies");
|
|
15
|
+
Object.defineProperty(exports, "parseSpendLimit", { enumerable: true, get: function () { return policies_1.parseSpendLimit; } });
|
|
16
|
+
Object.defineProperty(exports, "resolvePolicies", { enumerable: true, get: function () { return policies_1.resolvePolicies; } });
|
|
17
|
+
Object.defineProperty(exports, "DEFAULT_POLICIES", { enumerable: true, get: function () { return policies_1.DEFAULT_POLICIES; } });
|
|
18
|
+
// Errors (re-exported from @agent-shield/core + TeeRequiredError)
|
|
19
|
+
var errors_1 = require("./errors");
|
|
20
|
+
Object.defineProperty(exports, "ShieldDeniedError", { enumerable: true, get: function () { return errors_1.ShieldDeniedError; } });
|
|
21
|
+
Object.defineProperty(exports, "ShieldConfigError", { enumerable: true, get: function () { return errors_1.ShieldConfigError; } });
|
|
22
|
+
Object.defineProperty(exports, "TeeRequiredError", { enumerable: true, get: function () { return errors_1.TeeRequiredError; } });
|
|
23
|
+
// Transaction inspection (Solana-specific)
|
|
24
|
+
var inspector_1 = require("./inspector");
|
|
25
|
+
Object.defineProperty(exports, "analyzeTransaction", { enumerable: true, get: function () { return inspector_1.analyzeTransaction; } });
|
|
26
|
+
Object.defineProperty(exports, "getNonSystemProgramIds", { enumerable: true, get: function () { return inspector_1.getNonSystemProgramIds; } });
|
|
27
|
+
Object.defineProperty(exports, "resolveTransactionAddressLookupTables", { enumerable: true, get: function () { return inspector_1.resolveTransactionAddressLookupTables; } });
|
|
28
|
+
Object.defineProperty(exports, "extractInstructions", { enumerable: true, get: function () { return inspector_1.extractInstructions; } });
|
|
29
|
+
// Protocol & token registry (wrapper versions — accept PublicKey | string)
|
|
30
|
+
var registry_1 = require("./registry");
|
|
31
|
+
Object.defineProperty(exports, "KNOWN_PROTOCOLS", { enumerable: true, get: function () { return registry_1.KNOWN_PROTOCOLS; } });
|
|
32
|
+
Object.defineProperty(exports, "KNOWN_TOKENS", { enumerable: true, get: function () { return registry_1.KNOWN_TOKENS; } });
|
|
33
|
+
Object.defineProperty(exports, "SYSTEM_PROGRAMS", { enumerable: true, get: function () { return registry_1.SYSTEM_PROGRAMS; } });
|
|
34
|
+
Object.defineProperty(exports, "getTokenInfo", { enumerable: true, get: function () { return registry_1.getTokenInfo; } });
|
|
35
|
+
Object.defineProperty(exports, "getProtocolName", { enumerable: true, get: function () { return registry_1.getProtocolName; } });
|
|
36
|
+
Object.defineProperty(exports, "isSystemProgram", { enumerable: true, get: function () { return registry_1.isSystemProgram; } });
|
|
37
|
+
Object.defineProperty(exports, "isKnownProtocol", { enumerable: true, get: function () { return registry_1.isKnownProtocol; } });
|
|
38
|
+
// Client-side state (re-exported from @agent-shield/core)
|
|
39
|
+
var state_1 = require("./state");
|
|
40
|
+
Object.defineProperty(exports, "ShieldState", { enumerable: true, get: function () { return state_1.ShieldState; } });
|
|
41
|
+
// Policy engine (wrapper versions — accept PublicKey-based TransactionAnalysis)
|
|
42
|
+
var engine_1 = require("./engine");
|
|
43
|
+
Object.defineProperty(exports, "evaluatePolicy", { enumerable: true, get: function () { return engine_1.evaluatePolicy; } });
|
|
44
|
+
Object.defineProperty(exports, "enforcePolicy", { enumerable: true, get: function () { return engine_1.enforcePolicy; } });
|
|
45
|
+
Object.defineProperty(exports, "recordTransaction", { enumerable: true, get: function () { return engine_1.recordTransaction; } });
|
|
46
|
+
// x402 — HTTP 402 payment support
|
|
47
|
+
var x402_1 = require("./x402");
|
|
48
|
+
Object.defineProperty(exports, "shieldedFetch", { enumerable: true, get: function () { return x402_1.shieldedFetch; } });
|
|
49
|
+
Object.defineProperty(exports, "createShieldedFetchForWallet", { enumerable: true, get: function () { return x402_1.createShieldedFetchForWallet; } });
|
|
50
|
+
Object.defineProperty(exports, "selectPaymentOption", { enumerable: true, get: function () { return x402_1.selectPaymentOption; } });
|
|
51
|
+
Object.defineProperty(exports, "evaluateX402Payment", { enumerable: true, get: function () { return x402_1.evaluateX402Payment; } });
|
|
52
|
+
Object.defineProperty(exports, "buildX402TransferInstruction", { enumerable: true, get: function () { return x402_1.buildX402TransferInstruction; } });
|
|
53
|
+
Object.defineProperty(exports, "encodeX402Payload", { enumerable: true, get: function () { return x402_1.encodeX402Payload; } });
|
|
54
|
+
Object.defineProperty(exports, "decodePaymentRequiredHeader", { enumerable: true, get: function () { return x402_1.decodePaymentRequiredHeader; } });
|
|
55
|
+
Object.defineProperty(exports, "encodePaymentSignatureHeader", { enumerable: true, get: function () { return x402_1.encodePaymentSignatureHeader; } });
|
|
56
|
+
Object.defineProperty(exports, "decodePaymentResponseHeader", { enumerable: true, get: function () { return x402_1.decodePaymentResponseHeader; } });
|
|
57
|
+
Object.defineProperty(exports, "X402ParseError", { enumerable: true, get: function () { return x402_1.X402ParseError; } });
|
|
58
|
+
Object.defineProperty(exports, "X402PaymentError", { enumerable: true, get: function () { return x402_1.X402PaymentError; } });
|
|
59
|
+
Object.defineProperty(exports, "X402UnsupportedError", { enumerable: true, get: function () { return x402_1.X402UnsupportedError; } });
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":";AAAA,gEAAgE;;;AAEhE,mEAAmE;AACnE,mCAMkB;AALhB,gGAAA,MAAM,OAAA;AACN,mGAAA,SAAS,OAAA;AACT,sGAAA,YAAY,OAAA;AACZ,kHAAA,wBAAwB,OAAA;AACxB,yGAAA,eAAe,OAAA;AAMjB,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AAcpB,uCAAgF;AAAvE,2GAAA,eAAe,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,4GAAA,gBAAgB,OAAA;AAE3D,kEAAkE;AAClE,mCAIkB;AAHhB,2GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAA;AACjB,0GAAA,gBAAgB,OAAA;AAIlB,2CAA2C;AAC3C,yCAKqB;AAJnB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,kIAAA,qCAAqC,OAAA;AACrC,gHAAA,mBAAmB,OAAA;AAGrB,2EAA2E;AAC3E,uCAQoB;AAPlB,2GAAA,eAAe,OAAA;AACf,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AAGjB,0DAA0D;AAC1D,iCAAsC;AAA7B,oGAAA,WAAW,OAAA;AAOpB,gFAAgF;AAChF,mCAA4E;AAAnE,wGAAA,cAAc,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAEzD,kCAAkC;AAClC,+BAagB;AAZd,qGAAA,aAAa,OAAA;AACb,oHAAA,4BAA4B,OAAA;AAC5B,2GAAA,mBAAmB,OAAA;AACnB,2GAAA,mBAAmB,OAAA;AACnB,oHAAA,4BAA4B,OAAA;AAC5B,yGAAA,iBAAiB,OAAA;AACjB,mHAAA,2BAA2B,OAAA;AAC3B,oHAAA,4BAA4B,OAAA;AAC5B,mHAAA,2BAA2B,OAAA;AAC3B,sGAAA,cAAc,OAAA;AACd,wGAAA,gBAAgB,OAAA;AAChB,4GAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AddressLookupTableAccount, Connection, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { TransactionAnalysis } from "./policies";
|
|
3
|
+
/**
|
|
4
|
+
* Analyze a transaction to extract program IDs, token transfers, and estimated value.
|
|
5
|
+
* Works with both legacy Transaction and VersionedTransaction.
|
|
6
|
+
*/
|
|
7
|
+
export declare function analyzeTransaction(tx: Transaction | VersionedTransaction, signerPubkey: PublicKey, addressLookupTableAccounts?: AddressLookupTableAccount[]): TransactionAnalysis;
|
|
8
|
+
/**
|
|
9
|
+
* Extract instructions from either Transaction or VersionedTransaction.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractInstructions(tx: Transaction | VersionedTransaction, addressLookupTableAccounts?: AddressLookupTableAccount[]): TransactionInstruction[];
|
|
12
|
+
/**
|
|
13
|
+
* Resolve Address Lookup Table accounts for a VersionedTransaction.
|
|
14
|
+
* Returns empty array if the transaction has no ALT references.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveTransactionAddressLookupTables(tx: VersionedTransaction, connection: Connection): Promise<AddressLookupTableAccount[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Get all non-system program IDs from a transaction analysis.
|
|
19
|
+
* Useful for checking if a transaction interacts with unknown programs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getNonSystemProgramIds(analysis: TransactionAnalysis): PublicKey[];
|
|
22
|
+
//# sourceMappingURL=inspector.d.ts.map
|