@agent-shield/platform 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +94 -0
- package/dist/index.js +130 -0
- package/package.json +36 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agent-shield/platform
|
|
3
|
+
*
|
|
4
|
+
* Lightweight client for agents to request TEE wallet provisioning
|
|
5
|
+
* via the AgentShield platform's Solana Actions endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const platform = new AgentShieldPlatform("https://app.agentshield.dev");
|
|
10
|
+
*
|
|
11
|
+
* // 1. Generate Action URL for user to sign
|
|
12
|
+
* const actionUrl = platform.getProvisionActionUrl({ dailyCap: 500 });
|
|
13
|
+
*
|
|
14
|
+
* // 2. Or get a blink URL (for in-chat rendering)
|
|
15
|
+
* const blinkUrl = platform.getBlinkUrl({ dailyCap: 500 });
|
|
16
|
+
*
|
|
17
|
+
* // 3. Poll for result after user signs
|
|
18
|
+
* const result = await platform.waitForProvision(txSignature);
|
|
19
|
+
* // → { vaultAddress, agentPubkey, agentLocator }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ProvisionOptions {
|
|
23
|
+
/** Daily spending cap in USDC (e.g. 500 = 500 USDC/day) */
|
|
24
|
+
dailyCap?: number;
|
|
25
|
+
/** Policy template: "conservative" | "moderate" | "aggressive" */
|
|
26
|
+
template?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ActionMetadata {
|
|
29
|
+
type: string;
|
|
30
|
+
icon: string;
|
|
31
|
+
title: string;
|
|
32
|
+
description: string;
|
|
33
|
+
label: string;
|
|
34
|
+
links: {
|
|
35
|
+
actions: Array<{
|
|
36
|
+
label: string;
|
|
37
|
+
href: string;
|
|
38
|
+
parameters?: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
label: string;
|
|
41
|
+
required?: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface ProvisionResult {
|
|
47
|
+
status: "pending" | "confirmed" | "not_found";
|
|
48
|
+
vaultAddress?: string;
|
|
49
|
+
agentPubkey?: string;
|
|
50
|
+
agentLocator?: string;
|
|
51
|
+
template?: string;
|
|
52
|
+
error?: string;
|
|
53
|
+
}
|
|
54
|
+
export declare class AgentShieldPlatform {
|
|
55
|
+
private readonly baseUrl;
|
|
56
|
+
constructor(baseUrl: string);
|
|
57
|
+
/**
|
|
58
|
+
* Get the Solana Action URL for vault provisioning.
|
|
59
|
+
* This URL can be presented to users in chat, blink renderers, or dashboards.
|
|
60
|
+
*/
|
|
61
|
+
getProvisionActionUrl(options?: ProvisionOptions): string;
|
|
62
|
+
/**
|
|
63
|
+
* Get a Dialect blink URL that renders the Action in-chat.
|
|
64
|
+
*/
|
|
65
|
+
getBlinkUrl(options?: ProvisionOptions): string;
|
|
66
|
+
/**
|
|
67
|
+
* Fetch the Action metadata (GET endpoint).
|
|
68
|
+
*/
|
|
69
|
+
getActionMetadata(): Promise<ActionMetadata>;
|
|
70
|
+
/**
|
|
71
|
+
* Request a provision transaction for a specific account.
|
|
72
|
+
* Returns the base64-encoded unsigned VersionedTransaction.
|
|
73
|
+
*/
|
|
74
|
+
requestProvision(account: string, options?: ProvisionOptions): Promise<{
|
|
75
|
+
transaction: string;
|
|
76
|
+
message?: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Poll the status endpoint for a provision result.
|
|
80
|
+
*/
|
|
81
|
+
checkStatus(txSignature: string): Promise<ProvisionResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Poll until the provision is confirmed or times out.
|
|
84
|
+
*
|
|
85
|
+
* @param txSignature - The transaction signature from user's wallet
|
|
86
|
+
* @param timeoutMs - Max time to wait (default: 60s)
|
|
87
|
+
* @param intervalMs - Poll interval (default: 2s)
|
|
88
|
+
*/
|
|
89
|
+
waitForProvision(txSignature: string, timeoutMs?: number, intervalMs?: number): Promise<ProvisionResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Generate a human-readable message with the Action URL for the user.
|
|
92
|
+
*/
|
|
93
|
+
formatProvisionMessage(options?: ProvisionOptions): string;
|
|
94
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @agent-shield/platform
|
|
4
|
+
*
|
|
5
|
+
* Lightweight client for agents to request TEE wallet provisioning
|
|
6
|
+
* via the AgentShield platform's Solana Actions endpoints.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const platform = new AgentShieldPlatform("https://app.agentshield.dev");
|
|
11
|
+
*
|
|
12
|
+
* // 1. Generate Action URL for user to sign
|
|
13
|
+
* const actionUrl = platform.getProvisionActionUrl({ dailyCap: 500 });
|
|
14
|
+
*
|
|
15
|
+
* // 2. Or get a blink URL (for in-chat rendering)
|
|
16
|
+
* const blinkUrl = platform.getBlinkUrl({ dailyCap: 500 });
|
|
17
|
+
*
|
|
18
|
+
* // 3. Poll for result after user signs
|
|
19
|
+
* const result = await platform.waitForProvision(txSignature);
|
|
20
|
+
* // → { vaultAddress, agentPubkey, agentLocator }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.AgentShieldPlatform = void 0;
|
|
25
|
+
class AgentShieldPlatform {
|
|
26
|
+
constructor(baseUrl) {
|
|
27
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the Solana Action URL for vault provisioning.
|
|
31
|
+
* This URL can be presented to users in chat, blink renderers, or dashboards.
|
|
32
|
+
*/
|
|
33
|
+
getProvisionActionUrl(options = {}) {
|
|
34
|
+
const params = new URLSearchParams();
|
|
35
|
+
if (options.template) {
|
|
36
|
+
params.set("template", options.template);
|
|
37
|
+
}
|
|
38
|
+
if (options.dailyCap) {
|
|
39
|
+
params.set("dailyCap", options.dailyCap.toString());
|
|
40
|
+
}
|
|
41
|
+
const query = params.toString();
|
|
42
|
+
return `${this.baseUrl}/api/actions/provision${query ? `?${query}` : ""}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get a Dialect blink URL that renders the Action in-chat.
|
|
46
|
+
*/
|
|
47
|
+
getBlinkUrl(options = {}) {
|
|
48
|
+
const actionUrl = this.getProvisionActionUrl(options);
|
|
49
|
+
return `https://dial.to/?action=solana-action:${encodeURIComponent(actionUrl)}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch the Action metadata (GET endpoint).
|
|
53
|
+
*/
|
|
54
|
+
async getActionMetadata() {
|
|
55
|
+
const res = await fetch(`${this.baseUrl}/api/actions/provision`, {
|
|
56
|
+
method: "GET",
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
throw new Error(`Failed to fetch action metadata: ${res.status}`);
|
|
60
|
+
}
|
|
61
|
+
return res.json();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Request a provision transaction for a specific account.
|
|
65
|
+
* Returns the base64-encoded unsigned VersionedTransaction.
|
|
66
|
+
*/
|
|
67
|
+
async requestProvision(account, options = {}) {
|
|
68
|
+
const actionUrl = this.getProvisionActionUrl(options);
|
|
69
|
+
const res = await fetch(actionUrl, {
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
body: JSON.stringify({ account }),
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const error = await res.json().catch(() => ({ error: res.statusText }));
|
|
76
|
+
throw new Error(error.error || `Provision request failed: ${res.status}`);
|
|
77
|
+
}
|
|
78
|
+
return res.json();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Poll the status endpoint for a provision result.
|
|
82
|
+
*/
|
|
83
|
+
async checkStatus(txSignature) {
|
|
84
|
+
const res = await fetch(`${this.baseUrl}/api/actions/status/${txSignature}`, { method: "GET" });
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
throw new Error(`Status check failed: ${res.status}`);
|
|
87
|
+
}
|
|
88
|
+
return res.json();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Poll until the provision is confirmed or times out.
|
|
92
|
+
*
|
|
93
|
+
* @param txSignature - The transaction signature from user's wallet
|
|
94
|
+
* @param timeoutMs - Max time to wait (default: 60s)
|
|
95
|
+
* @param intervalMs - Poll interval (default: 2s)
|
|
96
|
+
*/
|
|
97
|
+
async waitForProvision(txSignature, timeoutMs = 60000, intervalMs = 2000) {
|
|
98
|
+
const deadline = Date.now() + timeoutMs;
|
|
99
|
+
while (Date.now() < deadline) {
|
|
100
|
+
const result = await this.checkStatus(txSignature);
|
|
101
|
+
if (result.status === "confirmed") {
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
if (result.status === "not_found" && result.error) {
|
|
105
|
+
throw new Error(`Provision failed: ${result.error}`);
|
|
106
|
+
}
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Provision timed out after ${timeoutMs}ms. TX: ${txSignature}`);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Generate a human-readable message with the Action URL for the user.
|
|
113
|
+
*/
|
|
114
|
+
formatProvisionMessage(options = {}) {
|
|
115
|
+
const actionUrl = this.getProvisionActionUrl(options);
|
|
116
|
+
const blinkUrl = this.getBlinkUrl(options);
|
|
117
|
+
const dailyCap = options.dailyCap || 500;
|
|
118
|
+
const template = options.template || "conservative";
|
|
119
|
+
return [
|
|
120
|
+
`I need a protected wallet to trade. Please approve the vault creation:`,
|
|
121
|
+
``,
|
|
122
|
+
`**Policy:** ${template} (${dailyCap} USDC/day cap)`,
|
|
123
|
+
`**Action URL:** ${actionUrl}`,
|
|
124
|
+
`**Blink:** ${blinkUrl}`,
|
|
125
|
+
``,
|
|
126
|
+
`Click the link above or paste the Action URL in any Solana blink-compatible app.`,
|
|
127
|
+
].join("\n");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.AgentShieldPlatform = AgentShieldPlatform;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agent-shield/platform",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Platform client for AgentShield — request TEE wallet provisioning via Solana Actions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"clean": "rm -rf dist",
|
|
10
|
+
"test": "mocha --require ts-node/register tests/**/*.test.ts --timeout 30000",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/chai": "^4.3.11",
|
|
22
|
+
"@types/mocha": "^10.0.6",
|
|
23
|
+
"@types/sinon": "^17.0.3",
|
|
24
|
+
"chai": "^4.4.1",
|
|
25
|
+
"mocha": "^10.3.0",
|
|
26
|
+
"sinon": "^17.0.1",
|
|
27
|
+
"ts-node": "^10.9.2",
|
|
28
|
+
"typescript": "^5.3.3"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/agent-shield/agent-shield",
|
|
34
|
+
"directory": "sdk/platform"
|
|
35
|
+
}
|
|
36
|
+
}
|