@exagent/sdk 0.1.0 → 0.1.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/dist/index.d.mts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +36 -12
- package/dist/index.mjs +33 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { Address, Hash, Chain, Account, WalletClient } from 'viem';
|
|
2
|
+
import { Address, Hash, Chain, Account, Hex, WalletClient } from 'viem';
|
|
3
3
|
import * as viem_chains from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -357,13 +357,15 @@ declare class ExagentRegistry {
|
|
|
357
357
|
*/
|
|
358
358
|
getNextAgentId(): Promise<bigint>;
|
|
359
359
|
/**
|
|
360
|
-
* Generate the message
|
|
360
|
+
* Generate the raw packed message bytes for wallet linking.
|
|
361
|
+
* Must match the contract's abi.encodePacked format exactly:
|
|
362
|
+
* keccak256(abi.encodePacked("Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce))
|
|
361
363
|
* @param wallet The wallet to link
|
|
362
364
|
* @param agentId The agent ID to link to
|
|
363
365
|
* @param nonce The current nonce for the wallet
|
|
364
|
-
* @returns
|
|
366
|
+
* @returns Raw packed bytes as hex string
|
|
365
367
|
*/
|
|
366
|
-
static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint):
|
|
368
|
+
static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint): Hex;
|
|
367
369
|
/**
|
|
368
370
|
* Get the agent owned by a wallet (not linked, owned)
|
|
369
371
|
* @param wallet The wallet to look up
|
|
@@ -2164,6 +2166,14 @@ declare class ExagentClient {
|
|
|
2164
2166
|
* Get the agent's wallet address
|
|
2165
2167
|
*/
|
|
2166
2168
|
get address(): Address;
|
|
2169
|
+
/**
|
|
2170
|
+
* Sign a message with the wallet's private key (EIP-191 personal sign)
|
|
2171
|
+
* @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
|
|
2172
|
+
* @returns The signature
|
|
2173
|
+
*/
|
|
2174
|
+
signMessage(message: string | {
|
|
2175
|
+
raw: `0x${string}`;
|
|
2176
|
+
}): Promise<`0x${string}`>;
|
|
2167
2177
|
private uploadMetadata;
|
|
2168
2178
|
private signIntent;
|
|
2169
2179
|
private parseAgentIdFromReceipt;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { Address, Hash, Chain, Account, WalletClient } from 'viem';
|
|
2
|
+
import { Address, Hash, Chain, Account, Hex, WalletClient } from 'viem';
|
|
3
3
|
import * as viem_chains from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -357,13 +357,15 @@ declare class ExagentRegistry {
|
|
|
357
357
|
*/
|
|
358
358
|
getNextAgentId(): Promise<bigint>;
|
|
359
359
|
/**
|
|
360
|
-
* Generate the message
|
|
360
|
+
* Generate the raw packed message bytes for wallet linking.
|
|
361
|
+
* Must match the contract's abi.encodePacked format exactly:
|
|
362
|
+
* keccak256(abi.encodePacked("Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce))
|
|
361
363
|
* @param wallet The wallet to link
|
|
362
364
|
* @param agentId The agent ID to link to
|
|
363
365
|
* @param nonce The current nonce for the wallet
|
|
364
|
-
* @returns
|
|
366
|
+
* @returns Raw packed bytes as hex string
|
|
365
367
|
*/
|
|
366
|
-
static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint):
|
|
368
|
+
static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint): Hex;
|
|
367
369
|
/**
|
|
368
370
|
* Get the agent owned by a wallet (not linked, owned)
|
|
369
371
|
* @param wallet The wallet to look up
|
|
@@ -2164,6 +2166,14 @@ declare class ExagentClient {
|
|
|
2164
2166
|
* Get the agent's wallet address
|
|
2165
2167
|
*/
|
|
2166
2168
|
get address(): Address;
|
|
2169
|
+
/**
|
|
2170
|
+
* Sign a message with the wallet's private key (EIP-191 personal sign)
|
|
2171
|
+
* @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
|
|
2172
|
+
* @returns The signature
|
|
2173
|
+
*/
|
|
2174
|
+
signMessage(message: string | {
|
|
2175
|
+
raw: `0x${string}`;
|
|
2176
|
+
}): Promise<`0x${string}`>;
|
|
2167
2177
|
private uploadMetadata;
|
|
2168
2178
|
private signIntent;
|
|
2169
2179
|
private parseAgentIdFromReceipt;
|
package/dist/index.js
CHANGED
|
@@ -38,10 +38,11 @@ __export(index_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(index_exports);
|
|
39
39
|
|
|
40
40
|
// src/client.ts
|
|
41
|
-
var
|
|
41
|
+
var import_viem2 = require("viem");
|
|
42
42
|
var import_accounts = require("viem/accounts");
|
|
43
43
|
|
|
44
44
|
// src/contracts/registry.ts
|
|
45
|
+
var import_viem = require("viem");
|
|
45
46
|
var EXAGENT_REGISTRY_ABI = [
|
|
46
47
|
{
|
|
47
48
|
type: "function",
|
|
@@ -510,14 +511,19 @@ var ExagentRegistry = class {
|
|
|
510
511
|
return nextId;
|
|
511
512
|
}
|
|
512
513
|
/**
|
|
513
|
-
* Generate the message
|
|
514
|
+
* Generate the raw packed message bytes for wallet linking.
|
|
515
|
+
* Must match the contract's abi.encodePacked format exactly:
|
|
516
|
+
* keccak256(abi.encodePacked("Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce))
|
|
514
517
|
* @param wallet The wallet to link
|
|
515
518
|
* @param agentId The agent ID to link to
|
|
516
519
|
* @param nonce The current nonce for the wallet
|
|
517
|
-
* @returns
|
|
520
|
+
* @returns Raw packed bytes as hex string
|
|
518
521
|
*/
|
|
519
522
|
static generateLinkMessage(wallet, agentId, nonce) {
|
|
520
|
-
return
|
|
523
|
+
return (0, import_viem.encodePacked)(
|
|
524
|
+
["string", "address", "string", "uint256", "string", "uint256"],
|
|
525
|
+
["Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce]
|
|
526
|
+
);
|
|
521
527
|
}
|
|
522
528
|
// ============ V4: One Agent Per Wallet ============
|
|
523
529
|
/**
|
|
@@ -649,8 +655,8 @@ var ExagentRegistry = class {
|
|
|
649
655
|
* @returns keccak256 hash of the config
|
|
650
656
|
*/
|
|
651
657
|
static calculateConfigHash(provider, model) {
|
|
652
|
-
const { keccak256, encodePacked } = require("viem");
|
|
653
|
-
return keccak256(
|
|
658
|
+
const { keccak256, encodePacked: encodePacked2 } = require("viem");
|
|
659
|
+
return keccak256(encodePacked2(["string", "string"], [provider, model]));
|
|
654
660
|
}
|
|
655
661
|
};
|
|
656
662
|
|
|
@@ -1847,12 +1853,21 @@ var EXAGENT_API_CONFIG = {
|
|
|
1847
1853
|
mainnet: "https://api.exagent.io",
|
|
1848
1854
|
testnet: "https://api.testnet.exagent.io"
|
|
1849
1855
|
};
|
|
1856
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1857
|
+
function validateContractAddresses(network) {
|
|
1858
|
+
const addresses = CONTRACT_ADDRESSES[network];
|
|
1859
|
+
const zeroEntries = Object.entries(addresses).filter(([, addr]) => addr === ZERO_ADDRESS);
|
|
1860
|
+
if (network === "mainnet" && zeroEntries.length > 0) {
|
|
1861
|
+
const missing = zeroEntries.map(([name]) => name).join(", ");
|
|
1862
|
+
throw new Error(
|
|
1863
|
+
`Mainnet contracts not yet deployed. Missing addresses: ${missing}. Deploy contracts before using the SDK on mainnet.`
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1850
1867
|
|
|
1851
1868
|
// src/client.ts
|
|
1852
1869
|
var ExagentClient = class {
|
|
1853
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1854
1870
|
publicClient;
|
|
1855
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1856
1871
|
walletClient;
|
|
1857
1872
|
account;
|
|
1858
1873
|
network;
|
|
@@ -1865,20 +1880,21 @@ var ExagentClient = class {
|
|
|
1865
1880
|
constructor(config) {
|
|
1866
1881
|
this.network = config.network ?? "testnet";
|
|
1867
1882
|
this.apiKey = config.apiKey;
|
|
1883
|
+
validateContractAddresses(this.network);
|
|
1868
1884
|
const chain = CHAIN_CONFIG[this.network];
|
|
1869
|
-
this.publicClient = (0,
|
|
1885
|
+
this.publicClient = (0, import_viem2.createPublicClient)({
|
|
1870
1886
|
chain,
|
|
1871
|
-
transport: (0,
|
|
1887
|
+
transport: (0, import_viem2.http)(config.rpcUrl)
|
|
1872
1888
|
});
|
|
1873
1889
|
if (config.walletClient) {
|
|
1874
1890
|
this.walletClient = config.walletClient;
|
|
1875
1891
|
this.account = config.walletClient.account;
|
|
1876
1892
|
} else if (config.privateKey) {
|
|
1877
1893
|
this.account = (0, import_accounts.privateKeyToAccount)(config.privateKey);
|
|
1878
|
-
this.walletClient = (0,
|
|
1894
|
+
this.walletClient = (0, import_viem2.createWalletClient)({
|
|
1879
1895
|
account: this.account,
|
|
1880
1896
|
chain,
|
|
1881
|
-
transport: (0,
|
|
1897
|
+
transport: (0, import_viem2.http)(config.rpcUrl)
|
|
1882
1898
|
});
|
|
1883
1899
|
} else {
|
|
1884
1900
|
throw new Error("Either privateKey or walletClient must be provided");
|
|
@@ -2427,6 +2443,14 @@ var ExagentClient = class {
|
|
|
2427
2443
|
get address() {
|
|
2428
2444
|
return this.account.address;
|
|
2429
2445
|
}
|
|
2446
|
+
/**
|
|
2447
|
+
* Sign a message with the wallet's private key (EIP-191 personal sign)
|
|
2448
|
+
* @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
|
|
2449
|
+
* @returns The signature
|
|
2450
|
+
*/
|
|
2451
|
+
async signMessage(message) {
|
|
2452
|
+
return this.walletClient.signMessage({ account: this.account, message });
|
|
2453
|
+
}
|
|
2430
2454
|
async uploadMetadata(metadata) {
|
|
2431
2455
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2432
2456
|
const response = await fetch(`${apiUrl}/v1/metadata/upload`, {
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
import { privateKeyToAccount } from "viem/accounts";
|
|
15
15
|
|
|
16
16
|
// src/contracts/registry.ts
|
|
17
|
+
import {
|
|
18
|
+
encodePacked
|
|
19
|
+
} from "viem";
|
|
17
20
|
var EXAGENT_REGISTRY_ABI = [
|
|
18
21
|
{
|
|
19
22
|
type: "function",
|
|
@@ -482,14 +485,19 @@ var ExagentRegistry = class {
|
|
|
482
485
|
return nextId;
|
|
483
486
|
}
|
|
484
487
|
/**
|
|
485
|
-
* Generate the message
|
|
488
|
+
* Generate the raw packed message bytes for wallet linking.
|
|
489
|
+
* Must match the contract's abi.encodePacked format exactly:
|
|
490
|
+
* keccak256(abi.encodePacked("Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce))
|
|
486
491
|
* @param wallet The wallet to link
|
|
487
492
|
* @param agentId The agent ID to link to
|
|
488
493
|
* @param nonce The current nonce for the wallet
|
|
489
|
-
* @returns
|
|
494
|
+
* @returns Raw packed bytes as hex string
|
|
490
495
|
*/
|
|
491
496
|
static generateLinkMessage(wallet, agentId, nonce) {
|
|
492
|
-
return
|
|
497
|
+
return encodePacked(
|
|
498
|
+
["string", "address", "string", "uint256", "string", "uint256"],
|
|
499
|
+
["Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce]
|
|
500
|
+
);
|
|
493
501
|
}
|
|
494
502
|
// ============ V4: One Agent Per Wallet ============
|
|
495
503
|
/**
|
|
@@ -621,8 +629,8 @@ var ExagentRegistry = class {
|
|
|
621
629
|
* @returns keccak256 hash of the config
|
|
622
630
|
*/
|
|
623
631
|
static calculateConfigHash(provider, model) {
|
|
624
|
-
const { keccak256, encodePacked } = __require("viem");
|
|
625
|
-
return keccak256(
|
|
632
|
+
const { keccak256, encodePacked: encodePacked2 } = __require("viem");
|
|
633
|
+
return keccak256(encodePacked2(["string", "string"], [provider, model]));
|
|
626
634
|
}
|
|
627
635
|
};
|
|
628
636
|
|
|
@@ -1819,12 +1827,21 @@ var EXAGENT_API_CONFIG = {
|
|
|
1819
1827
|
mainnet: "https://api.exagent.io",
|
|
1820
1828
|
testnet: "https://api.testnet.exagent.io"
|
|
1821
1829
|
};
|
|
1830
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1831
|
+
function validateContractAddresses(network) {
|
|
1832
|
+
const addresses = CONTRACT_ADDRESSES[network];
|
|
1833
|
+
const zeroEntries = Object.entries(addresses).filter(([, addr]) => addr === ZERO_ADDRESS);
|
|
1834
|
+
if (network === "mainnet" && zeroEntries.length > 0) {
|
|
1835
|
+
const missing = zeroEntries.map(([name]) => name).join(", ");
|
|
1836
|
+
throw new Error(
|
|
1837
|
+
`Mainnet contracts not yet deployed. Missing addresses: ${missing}. Deploy contracts before using the SDK on mainnet.`
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1822
1841
|
|
|
1823
1842
|
// src/client.ts
|
|
1824
1843
|
var ExagentClient = class {
|
|
1825
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1826
1844
|
publicClient;
|
|
1827
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1828
1845
|
walletClient;
|
|
1829
1846
|
account;
|
|
1830
1847
|
network;
|
|
@@ -1837,6 +1854,7 @@ var ExagentClient = class {
|
|
|
1837
1854
|
constructor(config) {
|
|
1838
1855
|
this.network = config.network ?? "testnet";
|
|
1839
1856
|
this.apiKey = config.apiKey;
|
|
1857
|
+
validateContractAddresses(this.network);
|
|
1840
1858
|
const chain = CHAIN_CONFIG[this.network];
|
|
1841
1859
|
this.publicClient = createPublicClient({
|
|
1842
1860
|
chain,
|
|
@@ -2399,6 +2417,14 @@ var ExagentClient = class {
|
|
|
2399
2417
|
get address() {
|
|
2400
2418
|
return this.account.address;
|
|
2401
2419
|
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Sign a message with the wallet's private key (EIP-191 personal sign)
|
|
2422
|
+
* @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
|
|
2423
|
+
* @returns The signature
|
|
2424
|
+
*/
|
|
2425
|
+
async signMessage(message) {
|
|
2426
|
+
return this.walletClient.signMessage({ account: this.account, message });
|
|
2427
|
+
}
|
|
2402
2428
|
async uploadMetadata(metadata) {
|
|
2403
2429
|
const apiUrl = EXAGENT_API_CONFIG[this.network];
|
|
2404
2430
|
const response = await fetch(`${apiUrl}/v1/metadata/upload`, {
|