@0xgasless/agentos 0.0.0-stage → 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/README.md +32 -2
- package/dist/config/env.d.ts +12 -0
- package/dist/config/env.js +63 -0
- package/dist/core/AgentOSClient.d.ts +48 -0
- package/dist/core/AgentOSClient.js +115 -0
- package/dist/core/IntentBuilder.d.ts +76 -0
- package/dist/core/IntentBuilder.js +47 -0
- package/dist/cre/CREWorkflowClient.d.ts +22 -0
- package/dist/cre/CREWorkflowClient.js +148 -0
- package/dist/cre/creTypes.d.ts +58 -0
- package/dist/cre/creTypes.js +1 -0
- package/dist/http/fetchWithRetry.d.ts +12 -0
- package/dist/http/fetchWithRetry.js +49 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/protocols/erc8004/IdentityManager.d.ts +52 -0
- package/dist/protocols/erc8004/IdentityManager.js +120 -0
- package/dist/protocols/erc8004/erc8004Types.d.ts +15 -0
- package/dist/protocols/erc8004/erc8004Types.js +1 -0
- package/dist/protocols/x402/FacilitatorClient.d.ts +9 -0
- package/dist/protocols/x402/FacilitatorClient.js +106 -0
- package/dist/protocols/x402/X402PaymentHandler.d.ts +25 -0
- package/dist/protocols/x402/X402PaymentHandler.js +139 -0
- package/dist/protocols/x402/x402Types.d.ts +52 -0
- package/dist/protocols/x402/x402Types.js +1 -0
- package/dist/security/ValidationGate.d.ts +12 -0
- package/dist/security/ValidationGate.js +14 -0
- package/dist/sxt/SXTQueryProvider.d.ts +30 -0
- package/dist/sxt/SXTQueryProvider.js +220 -0
- package/dist/sxt/sxtTypes.d.ts +48 -0
- package/dist/sxt/sxtTypes.js +1 -0
- package/dist/telemetry/DashboardLogger.d.ts +35 -0
- package/dist/telemetry/DashboardLogger.js +66 -0
- package/dist/wallet/GaslessWalletProvider.d.ts +55 -0
- package/dist/wallet/GaslessWalletProvider.js +99 -0
- package/package.json +47 -4
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { fetchWithRetry } from "../http/fetchWithRetry.js";
|
|
2
|
+
const DEFAULT_TIMEOUT_MS = 45_000;
|
|
3
|
+
const DEFAULT_RETRIES = 3;
|
|
4
|
+
const DEFAULT_RETRY_DELAY_MS = 400;
|
|
5
|
+
function assertEvmAddress(addr) {
|
|
6
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(addr)) {
|
|
7
|
+
throw new Error(`SXTQueryProvider: invalid EVM address for query binding: ${addr}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Minimal SQL literal hardening for interpolated identifiers (prefer `buildReputationSql` for untrusted input). */
|
|
11
|
+
function sqlLiteralString(s) {
|
|
12
|
+
if (!/^[a-zA-Z0-9._\-:+/]+$/u.test(s)) {
|
|
13
|
+
throw new Error("SXTQueryProvider: agentId contains characters not allowed in SQL literal");
|
|
14
|
+
}
|
|
15
|
+
return s.replace(/'/g, "''");
|
|
16
|
+
}
|
|
17
|
+
function extractZkProof(payload) {
|
|
18
|
+
if (payload === null || payload === undefined)
|
|
19
|
+
return "";
|
|
20
|
+
if (typeof payload === "string")
|
|
21
|
+
return payload;
|
|
22
|
+
if (typeof payload !== "object")
|
|
23
|
+
return "";
|
|
24
|
+
const o = payload;
|
|
25
|
+
const direct = o.proof ||
|
|
26
|
+
o.zkProof ||
|
|
27
|
+
o.proofOfSql ||
|
|
28
|
+
o.zk_proof ||
|
|
29
|
+
o.sxtProof;
|
|
30
|
+
if (typeof direct === "string" && direct.length > 0)
|
|
31
|
+
return direct;
|
|
32
|
+
const data = o.data;
|
|
33
|
+
if (data && typeof data === "object") {
|
|
34
|
+
const nested = extractZkProof(data);
|
|
35
|
+
if (nested)
|
|
36
|
+
return nested;
|
|
37
|
+
}
|
|
38
|
+
const result = o.result;
|
|
39
|
+
if (result && typeof result === "object") {
|
|
40
|
+
const nested = extractZkProof(result);
|
|
41
|
+
if (nested)
|
|
42
|
+
return nested;
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
function firstRow(payload) {
|
|
47
|
+
if (payload === null || payload === undefined || typeof payload !== "object")
|
|
48
|
+
return undefined;
|
|
49
|
+
const o = payload;
|
|
50
|
+
const rows = o.rows ?? o.data ?? o.records;
|
|
51
|
+
if (Array.isArray(rows) && rows.length > 0 && rows[0] && typeof rows[0] === "object") {
|
|
52
|
+
return rows[0];
|
|
53
|
+
}
|
|
54
|
+
if (o.total_spent !== undefined || o.TOTAL_SPENT !== undefined)
|
|
55
|
+
return o;
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function pickDecimal(row, keys) {
|
|
59
|
+
for (const k of keys) {
|
|
60
|
+
const v = row[k] ?? row[k.toUpperCase()] ?? row[k.toLowerCase()];
|
|
61
|
+
if (v === undefined || v === null)
|
|
62
|
+
continue;
|
|
63
|
+
if (typeof v === "bigint")
|
|
64
|
+
return v;
|
|
65
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
66
|
+
return BigInt(Math.trunc(v));
|
|
67
|
+
if (typeof v === "string" && /^\d+$/.test(v))
|
|
68
|
+
return BigInt(v);
|
|
69
|
+
if (typeof v === "string" && /^\d+\.\d+$/.test(v)) {
|
|
70
|
+
const [a, b] = v.split(".");
|
|
71
|
+
return BigInt(a + b.slice(0, 18).padEnd(18, "0").slice(0, 18));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return 0n;
|
|
75
|
+
}
|
|
76
|
+
function pickNumber(row, keys) {
|
|
77
|
+
for (const k of keys) {
|
|
78
|
+
const v = row[k] ?? row[k.toUpperCase()] ?? row[k.toLowerCase()];
|
|
79
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
80
|
+
return v;
|
|
81
|
+
if (typeof v === "string" && /^\d+(\.\d+)?$/.test(v))
|
|
82
|
+
return Number(v);
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Integrates Space and Time (SXT) Proof of SQL via DQL over indexed ERC-20 transfer data.
|
|
88
|
+
* Uses REST `POST /v1/sql/dql` with bearer auth, matching the platform’s SQL API surface.
|
|
89
|
+
*
|
|
90
|
+
* @see https://docs.spaceandtime.io/docs/javascript-sdk
|
|
91
|
+
*/
|
|
92
|
+
export class SXTQueryProvider {
|
|
93
|
+
cfg;
|
|
94
|
+
constructor(cfg) {
|
|
95
|
+
this.cfg = cfg;
|
|
96
|
+
}
|
|
97
|
+
/** Exposes effective config for enterprise guardrails. */
|
|
98
|
+
get config() {
|
|
99
|
+
return this.cfg;
|
|
100
|
+
}
|
|
101
|
+
async postDql(sqlText) {
|
|
102
|
+
const timeoutMs = this.cfg.requestTimeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
103
|
+
const maxRetries = this.cfg.maxRetries ?? DEFAULT_RETRIES;
|
|
104
|
+
const baseDelayMs = this.cfg.retryBaseDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
105
|
+
const url = `${this.cfg.baseUrl.replace(/\/$/, "")}/v1/sql/dql`;
|
|
106
|
+
const controller = new AbortController();
|
|
107
|
+
const t = setTimeout(() => controller.abort(), timeoutMs);
|
|
108
|
+
const signal = controller.signal;
|
|
109
|
+
try {
|
|
110
|
+
const body = {
|
|
111
|
+
sqlText,
|
|
112
|
+
biscuits: this.cfg.biscuits,
|
|
113
|
+
resources: this.cfg.resources,
|
|
114
|
+
};
|
|
115
|
+
const res = await fetchWithRetry(url, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
signal,
|
|
118
|
+
headers: {
|
|
119
|
+
accept: "application/json",
|
|
120
|
+
"content-type": "application/json",
|
|
121
|
+
authorization: `Bearer ${this.cfg.accessToken}`,
|
|
122
|
+
},
|
|
123
|
+
body: JSON.stringify(body),
|
|
124
|
+
}, {
|
|
125
|
+
maxRetries,
|
|
126
|
+
baseDelayMs,
|
|
127
|
+
signal,
|
|
128
|
+
retryOnRateLimit: true,
|
|
129
|
+
});
|
|
130
|
+
const text = await res.text();
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
parsed = text ? JSON.parse(text) : {};
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw new Error(`SXT DQL: non-JSON response (${res.status}): ${text.slice(0, 200)}`);
|
|
137
|
+
}
|
|
138
|
+
if (!res.ok) {
|
|
139
|
+
const errMsg = typeof parsed === "object" && parsed && "message" in parsed
|
|
140
|
+
? String(parsed.message)
|
|
141
|
+
: text.slice(0, 300);
|
|
142
|
+
throw new Error(`SXT DQL failed: HTTP ${res.status} — ${errMsg}`);
|
|
143
|
+
}
|
|
144
|
+
return parsed;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
clearTimeout(t);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
defaultSpendingSql(agentAddress, timeframeHours) {
|
|
151
|
+
const table = this.cfg.erc20TransfersTableFqn;
|
|
152
|
+
const toCol = this.cfg.toAddressColumn ?? "TO_WALLET";
|
|
153
|
+
const valCol = this.cfg.valueColumn ?? "VALUE";
|
|
154
|
+
const tsCol = this.cfg.blockTimestampColumn ?? "BLOCK_TIMESTAMP";
|
|
155
|
+
assertEvmAddress(agentAddress);
|
|
156
|
+
return `
|
|
157
|
+
SELECT COALESCE(SUM(CAST(${valCol} AS DECIMAL(38,0))), 0) AS total_spent
|
|
158
|
+
FROM ${table}
|
|
159
|
+
WHERE LOWER(${toCol}) = LOWER('${agentAddress}')
|
|
160
|
+
AND ${tsCol} >= TIMESTAMPADD(HOUR, -${timeframeHours}, CURRENT_TIMESTAMP)
|
|
161
|
+
`.trim();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Proof-of-SQL bounded spending from indexed ERC-20 transfers (recipient = agent wallet).
|
|
165
|
+
*/
|
|
166
|
+
async getAgentSpendingHistory(agentId, timeframeHours) {
|
|
167
|
+
if (this.cfg.mockMode) {
|
|
168
|
+
return {
|
|
169
|
+
total: 150n,
|
|
170
|
+
proof: "0xmock_sxt_proof_" + "a".repeat(64),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const sql = this.cfg.buildSpendingHistorySql?.({ agentAddress: agentId, timeframeHours }) ??
|
|
174
|
+
this.defaultSpendingSql(agentId, timeframeHours);
|
|
175
|
+
const raw = await this.postDql(sql);
|
|
176
|
+
const proof = extractZkProof(raw) || "0x";
|
|
177
|
+
const row = firstRow(raw);
|
|
178
|
+
const total = row ? pickDecimal(row, ["total_spent", "TOTAL_SPENT"]) : 0n;
|
|
179
|
+
return { total, proof };
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Application-specific reputation aggregate; requires `reputationTableFqn` or `buildReputationSql`.
|
|
183
|
+
*/
|
|
184
|
+
async getAgentReputation(agentId) {
|
|
185
|
+
if (this.cfg.mockMode) {
|
|
186
|
+
return { score: 98, count: 124, proof: "0xmock_reputation_proof" };
|
|
187
|
+
}
|
|
188
|
+
if (this.cfg.buildReputationSql) {
|
|
189
|
+
const raw = await this.postDql(this.cfg.buildReputationSql({ agentId }));
|
|
190
|
+
const proof = extractZkProof(raw) || "0x";
|
|
191
|
+
const row = firstRow(raw);
|
|
192
|
+
if (!row)
|
|
193
|
+
return { score: 0, count: 0, proof };
|
|
194
|
+
return {
|
|
195
|
+
score: pickNumber(row, ["score", "avg_score", "AVG_SCORE"]),
|
|
196
|
+
count: Math.trunc(pickNumber(row, ["count", "cnt", "feedback_count"])),
|
|
197
|
+
proof,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!this.cfg.reputationTableFqn) {
|
|
201
|
+
throw new Error("SXTQueryProvider.getAgentReputation: set `reputationTableFqn` + matching columns or `buildReputationSql` in SXTQueryConfig");
|
|
202
|
+
}
|
|
203
|
+
const table = this.cfg.reputationTableFqn;
|
|
204
|
+
const sql = `
|
|
205
|
+
SELECT AVG(CAST(feedback_score AS DECIMAL)) AS score, COUNT(*) AS count
|
|
206
|
+
FROM ${table}
|
|
207
|
+
WHERE agent_id = '${sqlLiteralString(agentId)}'
|
|
208
|
+
`.trim();
|
|
209
|
+
const raw = await this.postDql(sql);
|
|
210
|
+
const proof = extractZkProof(raw) || "0x";
|
|
211
|
+
const row = firstRow(raw);
|
|
212
|
+
if (!row)
|
|
213
|
+
return { score: 0, count: 0, proof };
|
|
214
|
+
return {
|
|
215
|
+
score: pickNumber(row, ["score", "avg_score"]),
|
|
216
|
+
count: Math.trunc(pickNumber(row, ["count", "cnt"])),
|
|
217
|
+
proof,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Space and Time (SXT) connectivity for Proof-of-SQL DQL against indexed chain data.
|
|
3
|
+
* Configure table FQNs and column names to match your SXT workspace / indexed Ethereum schema.
|
|
4
|
+
*
|
|
5
|
+
* @see https://docs.spaceandtime.io/docs/indexed-ethereum-data-zk-proven
|
|
6
|
+
*/
|
|
7
|
+
export interface SXTQueryConfig {
|
|
8
|
+
/** Base API URL including protocol, no trailing slash (e.g. from `BASEURL_GENERAL` in SXT docs). */
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/** OAuth-style bearer token from SXT authentication (`authorization: Bearer …`). */
|
|
11
|
+
accessToken: string;
|
|
12
|
+
/**
|
|
13
|
+
* Fully-qualified ERC-20 transfer table for indexed Ethereum data, e.g. `ETH.TOKEN_ERC20_TRANSFERS`.
|
|
14
|
+
* Must match tables available in your SXT deployment.
|
|
15
|
+
*/
|
|
16
|
+
erc20TransfersTableFqn: string;
|
|
17
|
+
/** Column holding the recipient address on transfers. */
|
|
18
|
+
toAddressColumn?: string;
|
|
19
|
+
/** Numeric transfer amount column (wei-style integer). */
|
|
20
|
+
valueColumn?: string;
|
|
21
|
+
/** Block or row timestamp column for time-bounded queries. */
|
|
22
|
+
blockTimestampColumn?: string;
|
|
23
|
+
/** Optional biscuit tokens for permissioned resources. */
|
|
24
|
+
biscuits?: string[];
|
|
25
|
+
resources?: string[];
|
|
26
|
+
requestTimeoutMs?: number;
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
retryBaseDelayMs?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Override default SUM(...) SQL for spending history (advanced).
|
|
31
|
+
* Use when your schema differs from the default ERC-20 indexed layout.
|
|
32
|
+
*/
|
|
33
|
+
buildSpendingHistorySql?: (ctx: {
|
|
34
|
+
agentAddress: string;
|
|
35
|
+
timeframeHours: number;
|
|
36
|
+
}) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional table for ERC-8004-style reputation aggregates (application-specific).
|
|
39
|
+
*/
|
|
40
|
+
reputationTableFqn?: string;
|
|
41
|
+
buildReputationSql?: (ctx: {
|
|
42
|
+
agentId: string;
|
|
43
|
+
}) => string;
|
|
44
|
+
/**
|
|
45
|
+
* When true, skips HTTP and returns deterministic stub data (local dev only; do not use in production).
|
|
46
|
+
*/
|
|
47
|
+
mockMode?: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type LogLevel = "INFO" | "WARN" | "ERROR" | "DEBUG";
|
|
2
|
+
export interface LogEntry {
|
|
3
|
+
timestamp: string;
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
agentId: string;
|
|
6
|
+
step: string;
|
|
7
|
+
message: string;
|
|
8
|
+
metadata?: Record<string, any>;
|
|
9
|
+
error?: string;
|
|
10
|
+
txHash?: string;
|
|
11
|
+
}
|
|
12
|
+
export type LogListener = (entry: LogEntry) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Enterprise Telemetry Logger for @0xgasless/agentOS.
|
|
15
|
+
* Provides AWS CloudWatch-style observability for user dashboards to ingest.
|
|
16
|
+
* Intercepts intent creation, SXT proofs, CRE consensus, and Execution stages.
|
|
17
|
+
*/
|
|
18
|
+
export declare class DashboardLogger {
|
|
19
|
+
private readonly defaultAgentId;
|
|
20
|
+
private listeners;
|
|
21
|
+
constructor(defaultAgentId?: string);
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe a frontend dashboard or webhook to the telemetry stream.
|
|
24
|
+
*/
|
|
25
|
+
subscribe(listener: LogListener): void;
|
|
26
|
+
/**
|
|
27
|
+
* Unsubscribe a listener from the telemetry stream.
|
|
28
|
+
*/
|
|
29
|
+
unsubscribe(listener: LogListener): void;
|
|
30
|
+
private emit;
|
|
31
|
+
info(step: string, message: string, metadata?: Record<string, any>, txHash?: string): void;
|
|
32
|
+
warn(step: string, message: string, metadata?: Record<string, any>): void;
|
|
33
|
+
error(step: string, message: string, errorObj?: any, metadata?: Record<string, any>): void;
|
|
34
|
+
debug(step: string, message: string, metadata?: Record<string, any>): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enterprise Telemetry Logger for @0xgasless/agentOS.
|
|
3
|
+
* Provides AWS CloudWatch-style observability for user dashboards to ingest.
|
|
4
|
+
* Intercepts intent creation, SXT proofs, CRE consensus, and Execution stages.
|
|
5
|
+
*/
|
|
6
|
+
export class DashboardLogger {
|
|
7
|
+
defaultAgentId;
|
|
8
|
+
listeners = [];
|
|
9
|
+
constructor(defaultAgentId = "unregistered-agent") {
|
|
10
|
+
this.defaultAgentId = defaultAgentId;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Subscribe a frontend dashboard or webhook to the telemetry stream.
|
|
14
|
+
*/
|
|
15
|
+
subscribe(listener) {
|
|
16
|
+
this.listeners.push(listener);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Unsubscribe a listener from the telemetry stream.
|
|
20
|
+
*/
|
|
21
|
+
unsubscribe(listener) {
|
|
22
|
+
this.listeners = this.listeners.filter(l => l !== listener);
|
|
23
|
+
}
|
|
24
|
+
emit(level, step, message, metadata, error, txHash) {
|
|
25
|
+
const entry = {
|
|
26
|
+
timestamp: new Date().toISOString(),
|
|
27
|
+
level,
|
|
28
|
+
agentId: this.defaultAgentId,
|
|
29
|
+
step,
|
|
30
|
+
message,
|
|
31
|
+
metadata,
|
|
32
|
+
error,
|
|
33
|
+
txHash
|
|
34
|
+
};
|
|
35
|
+
// Broadcast to all hooked dashboard listeners
|
|
36
|
+
this.listeners.forEach(listener => listener(entry));
|
|
37
|
+
}
|
|
38
|
+
info(step, message, metadata, txHash) {
|
|
39
|
+
this.emit("INFO", step, message, metadata, undefined, txHash);
|
|
40
|
+
}
|
|
41
|
+
warn(step, message, metadata) {
|
|
42
|
+
this.emit("WARN", step, message, metadata);
|
|
43
|
+
}
|
|
44
|
+
error(step, message, errorObj, metadata) {
|
|
45
|
+
let actualErrorStr = "";
|
|
46
|
+
let actualMetadata = metadata;
|
|
47
|
+
if (errorObj instanceof Error) {
|
|
48
|
+
actualErrorStr = errorObj.message;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof errorObj === 'string') {
|
|
51
|
+
actualErrorStr = errorObj;
|
|
52
|
+
}
|
|
53
|
+
else if (errorObj !== null && typeof errorObj === 'object' && !metadata) {
|
|
54
|
+
// It was passed as a metadata object instead of an error string
|
|
55
|
+
actualMetadata = errorObj;
|
|
56
|
+
actualErrorStr = errorObj.error ? String(errorObj.error) : "Unknown error";
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
actualErrorStr = String(errorObj);
|
|
60
|
+
}
|
|
61
|
+
this.emit("ERROR", step, message, actualMetadata, actualErrorStr);
|
|
62
|
+
}
|
|
63
|
+
debug(step, message, metadata) {
|
|
64
|
+
this.emit("DEBUG", step, message, metadata);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ZeroXgaslessSmartAccount, type SignTypedDataParams } from "@0xgasless/smart-account";
|
|
2
|
+
import { OxGasClient } from "@0xgasless/core";
|
|
3
|
+
import type { PublicClient } from "viem";
|
|
4
|
+
import { Intent } from "../core/IntentBuilder.js";
|
|
5
|
+
export interface IGaslessWalletProvider {
|
|
6
|
+
getAddress(): Promise<string>;
|
|
7
|
+
getChainId(): Promise<number>;
|
|
8
|
+
signTypedData(params: SignTypedDataParams): Promise<`0x${string}`>;
|
|
9
|
+
getPublicClient(): PublicClient;
|
|
10
|
+
sendTransactionFromIntent(intent: Intent, donSignature: string): Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
txHash?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
}>;
|
|
15
|
+
sendContractCallAuthorized(params: {
|
|
16
|
+
to: `0x${string}`;
|
|
17
|
+
data: `0x${string}`;
|
|
18
|
+
value?: bigint;
|
|
19
|
+
}, donSignature: string): Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
txHash?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A tightly coupled wallet provider wrapper for 0xGasless infrastructure.
|
|
27
|
+
* Enforces usage of `@0xgasless/core` and `@0xgasless/smart-account` as the execution layer.
|
|
28
|
+
*/
|
|
29
|
+
export declare class GaslessWalletProvider implements IGaslessWalletProvider {
|
|
30
|
+
private readonly smartAccount;
|
|
31
|
+
private readonly coreClient;
|
|
32
|
+
constructor(smartAccount: ZeroXgaslessSmartAccount, coreClient: OxGasClient);
|
|
33
|
+
getAddress(): Promise<string>;
|
|
34
|
+
getChainId(): Promise<number>;
|
|
35
|
+
getPublicClient(): PublicClient;
|
|
36
|
+
signTypedData(params: SignTypedDataParams): Promise<`0x${string}`>;
|
|
37
|
+
/**
|
|
38
|
+
* Converts an approved Intent into a UserOperation and broadcasts it via the 0xGasless bundler.
|
|
39
|
+
* The signature from the CRE DON acts as the authorization payload.
|
|
40
|
+
*/
|
|
41
|
+
sendTransactionFromIntent(intent: Intent, donSignature: string): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
txHash?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
}>;
|
|
46
|
+
sendContractCallAuthorized(params: {
|
|
47
|
+
to: `0x${string}`;
|
|
48
|
+
data: `0x${string}`;
|
|
49
|
+
value?: bigint;
|
|
50
|
+
}, donSignature: string): Promise<{
|
|
51
|
+
success: boolean;
|
|
52
|
+
txHash?: string;
|
|
53
|
+
error?: string;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { parseEther } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* A tightly coupled wallet provider wrapper for 0xGasless infrastructure.
|
|
4
|
+
* Enforces usage of `@0xgasless/core` and `@0xgasless/smart-account` as the execution layer.
|
|
5
|
+
*/
|
|
6
|
+
export class GaslessWalletProvider {
|
|
7
|
+
smartAccount;
|
|
8
|
+
coreClient;
|
|
9
|
+
constructor(smartAccount, coreClient) {
|
|
10
|
+
this.smartAccount = smartAccount;
|
|
11
|
+
this.coreClient = coreClient;
|
|
12
|
+
}
|
|
13
|
+
async getAddress() {
|
|
14
|
+
return this.smartAccount.getAddress();
|
|
15
|
+
}
|
|
16
|
+
async getChainId() {
|
|
17
|
+
return this.smartAccount.rpcProvider.getChainId();
|
|
18
|
+
}
|
|
19
|
+
getPublicClient() {
|
|
20
|
+
return this.smartAccount.rpcProvider;
|
|
21
|
+
}
|
|
22
|
+
async signTypedData(params) {
|
|
23
|
+
// viem SignTypedDataParameters requires an account; smart-account signer already knows the account.
|
|
24
|
+
// We satisfy the type by injecting the smart account address.
|
|
25
|
+
const account = (await this.getAddress());
|
|
26
|
+
return this.smartAccount.signTypedData({ ...params, account });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts an approved Intent into a UserOperation and broadcasts it via the 0xGasless bundler.
|
|
30
|
+
* The signature from the CRE DON acts as the authorization payload.
|
|
31
|
+
*/
|
|
32
|
+
async sendTransactionFromIntent(intent, donSignature) {
|
|
33
|
+
try {
|
|
34
|
+
let tx;
|
|
35
|
+
if (intent.actionType === "TRANSFER") {
|
|
36
|
+
// Map generic transfer intent to specific transaction payload
|
|
37
|
+
tx = {
|
|
38
|
+
to: intent.target,
|
|
39
|
+
value: intent.amount ? parseEther(intent.amount) : 0n,
|
|
40
|
+
data: "0x", // For ERC20 this would require ABI encoding (omitted here for brevity)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error(`Unsupported transaction mapping for Intent Type: ${intent.actionType}`);
|
|
45
|
+
}
|
|
46
|
+
// In a real flow, the `donSignature` is appended to the UserOp signature field
|
|
47
|
+
// to satisfy the signature validation required by the EntryPoint contract
|
|
48
|
+
console.log(`[GaslessWallet] Submitting UserOp Authorized by DON Signature: ${donSignature.substring(0, 8)}...`);
|
|
49
|
+
// Enterprise invariant: no local signing bypass. The DON signature is the only allowed signature payload.
|
|
50
|
+
// Build unsigned UserOperation, override signature, then submit.
|
|
51
|
+
const unsignedUserOp = await this.smartAccount.buildUserOp([tx]);
|
|
52
|
+
const signedUserOp = {
|
|
53
|
+
...unsignedUserOp,
|
|
54
|
+
signature: donSignature,
|
|
55
|
+
};
|
|
56
|
+
const response = await this.smartAccount.sendSignedUserOp(signedUserOp, "validation_and_execution");
|
|
57
|
+
if (response.error?.message) {
|
|
58
|
+
return { success: false, error: `Bundler rejected UserOp: ${response.error.message}` };
|
|
59
|
+
}
|
|
60
|
+
// Prefer tx hash when available; otherwise return the userOp hash.
|
|
61
|
+
const status = await response.waitForTxHash();
|
|
62
|
+
const txHash = status.transactionHash ?? response.userOpHash ?? undefined;
|
|
63
|
+
if (!txHash) {
|
|
64
|
+
return { success: false, error: "UserOp submitted but no tx hash was returned by bundler" };
|
|
65
|
+
}
|
|
66
|
+
return { success: true, txHash };
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error(`[GaslessWallet] Execution Failed:`, e.message);
|
|
70
|
+
return { success: false, error: `Gasless Execution Failed: ${e.message}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async sendContractCallAuthorized(params, donSignature) {
|
|
74
|
+
try {
|
|
75
|
+
const tx = {
|
|
76
|
+
to: params.to,
|
|
77
|
+
data: params.data,
|
|
78
|
+
value: params.value ?? 0n,
|
|
79
|
+
};
|
|
80
|
+
const unsignedUserOp = await this.smartAccount.buildUserOp([tx]);
|
|
81
|
+
const signedUserOp = {
|
|
82
|
+
...unsignedUserOp,
|
|
83
|
+
signature: donSignature,
|
|
84
|
+
};
|
|
85
|
+
const response = await this.smartAccount.sendSignedUserOp(signedUserOp, "validation_and_execution");
|
|
86
|
+
if (response.error?.message) {
|
|
87
|
+
return { success: false, error: `Bundler rejected UserOp: ${response.error.message}` };
|
|
88
|
+
}
|
|
89
|
+
const status = await response.waitForTxHash();
|
|
90
|
+
const txHash = status.transactionHash ?? response.userOpHash ?? undefined;
|
|
91
|
+
if (!txHash)
|
|
92
|
+
return { success: false, error: "UserOp submitted but no tx hash was returned by bundler" };
|
|
93
|
+
return { success: true, txHash };
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return { success: false, error: `Gasless contract call failed: ${e.message}` };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xgasless/agentos",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Client-side agent SDK for 0xGasless: gasless smart-account wallets, x402 payments and ERC-8004 identity",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@0xgasless/core": "^1.0.2",
|
|
15
|
+
"@0xgasless/smart-account": "^0.0.13",
|
|
16
|
+
"viem": "^2.21.0",
|
|
17
|
+
"zod": "^3.23.8"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18.18.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.5.4"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"0xgasless",
|
|
43
|
+
"x402",
|
|
44
|
+
"erc-8004",
|
|
45
|
+
"account-abstraction",
|
|
46
|
+
"ai-agents",
|
|
47
|
+
"avalanche"
|
|
48
|
+
]
|
|
49
|
+
}
|