@exagent/sdk 0.1.1 → 0.1.3

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 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 to sign for wallet linking
360
+ * Generate the message hash for wallet linking.
361
+ * Matches the contract's keccak256(abi.encodePacked(...)) exactly.
362
+ * Sign the returned hash with signMessage({ raw: hash }) to produce a valid signature.
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 Message to sign
366
+ * @returns keccak256 hash of the packed message (32 bytes)
365
367
  */
366
- static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint): string;
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
@@ -1968,9 +1970,11 @@ declare class ExagentClient {
1968
1970
  /**
1969
1971
  * Link an additional wallet to this agent
1970
1972
  * @param wallet Wallet address to link
1971
- * @param signMessage Function to sign a message with the wallet
1973
+ * @param signMessage Function to sign the message hash with the wallet (use signMessage({ raw: hash }))
1972
1974
  */
1973
- linkWallet(wallet: Address, signMessage: (message: string) => Promise<`0x${string}`>): Promise<Hash>;
1975
+ linkWallet(wallet: Address, signMessage: (message: {
1976
+ raw: `0x${string}`;
1977
+ }) => Promise<`0x${string}`>): Promise<Hash>;
1974
1978
  /**
1975
1979
  * Get all wallets linked to this agent
1976
1980
  */
@@ -2166,10 +2170,12 @@ declare class ExagentClient {
2166
2170
  get address(): Address;
2167
2171
  /**
2168
2172
  * Sign a message with the wallet's private key (EIP-191 personal sign)
2169
- * @param message The message to sign
2173
+ * @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
2170
2174
  * @returns The signature
2171
2175
  */
2172
- signMessage(message: string): Promise<`0x${string}`>;
2176
+ signMessage(message: string | {
2177
+ raw: `0x${string}`;
2178
+ }): Promise<`0x${string}`>;
2173
2179
  private uploadMetadata;
2174
2180
  private signIntent;
2175
2181
  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 to sign for wallet linking
360
+ * Generate the message hash for wallet linking.
361
+ * Matches the contract's keccak256(abi.encodePacked(...)) exactly.
362
+ * Sign the returned hash with signMessage({ raw: hash }) to produce a valid signature.
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 Message to sign
366
+ * @returns keccak256 hash of the packed message (32 bytes)
365
367
  */
366
- static generateLinkMessage(wallet: Address, agentId: bigint, nonce: bigint): string;
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
@@ -1968,9 +1970,11 @@ declare class ExagentClient {
1968
1970
  /**
1969
1971
  * Link an additional wallet to this agent
1970
1972
  * @param wallet Wallet address to link
1971
- * @param signMessage Function to sign a message with the wallet
1973
+ * @param signMessage Function to sign the message hash with the wallet (use signMessage({ raw: hash }))
1972
1974
  */
1973
- linkWallet(wallet: Address, signMessage: (message: string) => Promise<`0x${string}`>): Promise<Hash>;
1975
+ linkWallet(wallet: Address, signMessage: (message: {
1976
+ raw: `0x${string}`;
1977
+ }) => Promise<`0x${string}`>): Promise<Hash>;
1974
1978
  /**
1975
1979
  * Get all wallets linked to this agent
1976
1980
  */
@@ -2166,10 +2170,12 @@ declare class ExagentClient {
2166
2170
  get address(): Address;
2167
2171
  /**
2168
2172
  * Sign a message with the wallet's private key (EIP-191 personal sign)
2169
- * @param message The message to sign
2173
+ * @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
2170
2174
  * @returns The signature
2171
2175
  */
2172
- signMessage(message: string): Promise<`0x${string}`>;
2176
+ signMessage(message: string | {
2177
+ raw: `0x${string}`;
2178
+ }): Promise<`0x${string}`>;
2173
2179
  private uploadMetadata;
2174
2180
  private signIntent;
2175
2181
  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 import_viem = require("viem");
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 to sign for wallet linking
514
+ * Generate the message hash for wallet linking.
515
+ * Matches the contract's keccak256(abi.encodePacked(...)) exactly.
516
+ * Sign the returned hash with signMessage({ raw: hash }) to produce a valid signature.
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 Message to sign
520
+ * @returns keccak256 hash of the packed message (32 bytes)
518
521
  */
519
522
  static generateLinkMessage(wallet, agentId, nonce) {
520
- return `Link wallet ${wallet} to Exagent ${agentId} nonce ${nonce}`;
523
+ return (0, import_viem.keccak256)((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(encodePacked(["string", "string"], [provider, model]));
658
+ const { keccak256: keccak2562, encodePacked: encodePacked2 } = require("viem");
659
+ return keccak2562(encodePacked2(["string", "string"], [provider, model]));
654
660
  }
655
661
  };
656
662
 
@@ -1876,19 +1882,19 @@ var ExagentClient = class {
1876
1882
  this.apiKey = config.apiKey;
1877
1883
  validateContractAddresses(this.network);
1878
1884
  const chain = CHAIN_CONFIG[this.network];
1879
- this.publicClient = (0, import_viem.createPublicClient)({
1885
+ this.publicClient = (0, import_viem2.createPublicClient)({
1880
1886
  chain,
1881
- transport: (0, import_viem.http)(config.rpcUrl)
1887
+ transport: (0, import_viem2.http)(config.rpcUrl)
1882
1888
  });
1883
1889
  if (config.walletClient) {
1884
1890
  this.walletClient = config.walletClient;
1885
1891
  this.account = config.walletClient.account;
1886
1892
  } else if (config.privateKey) {
1887
1893
  this.account = (0, import_accounts.privateKeyToAccount)(config.privateKey);
1888
- this.walletClient = (0, import_viem.createWalletClient)({
1894
+ this.walletClient = (0, import_viem2.createWalletClient)({
1889
1895
  account: this.account,
1890
1896
  chain,
1891
- transport: (0, import_viem.http)(config.rpcUrl)
1897
+ transport: (0, import_viem2.http)(config.rpcUrl)
1892
1898
  });
1893
1899
  } else {
1894
1900
  throw new Error("Either privateKey or walletClient must be provided");
@@ -1976,14 +1982,14 @@ var ExagentClient = class {
1976
1982
  /**
1977
1983
  * Link an additional wallet to this agent
1978
1984
  * @param wallet Wallet address to link
1979
- * @param signMessage Function to sign a message with the wallet
1985
+ * @param signMessage Function to sign the message hash with the wallet (use signMessage({ raw: hash }))
1980
1986
  */
1981
1987
  async linkWallet(wallet, signMessage) {
1982
1988
  const agentId = await this.getAgentId();
1983
1989
  if (!agentId) throw new Error("Agent not registered");
1984
1990
  const nonce = await this.registry.getNonce(wallet);
1985
- const message = ExagentRegistry.generateLinkMessage(wallet, agentId, nonce);
1986
- const signature = await signMessage(message);
1991
+ const messageHash = ExagentRegistry.generateLinkMessage(wallet, agentId, nonce);
1992
+ const signature = await signMessage({ raw: messageHash });
1987
1993
  return this.registry.linkWallet(agentId, wallet, signature);
1988
1994
  }
1989
1995
  /**
@@ -2439,7 +2445,7 @@ var ExagentClient = class {
2439
2445
  }
2440
2446
  /**
2441
2447
  * Sign a message with the wallet's private key (EIP-191 personal sign)
2442
- * @param message The message to sign
2448
+ * @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
2443
2449
  * @returns The signature
2444
2450
  */
2445
2451
  async signMessage(message) {
package/dist/index.mjs CHANGED
@@ -14,6 +14,10 @@ import {
14
14
  import { privateKeyToAccount } from "viem/accounts";
15
15
 
16
16
  // src/contracts/registry.ts
17
+ import {
18
+ encodePacked,
19
+ keccak256
20
+ } from "viem";
17
21
  var EXAGENT_REGISTRY_ABI = [
18
22
  {
19
23
  type: "function",
@@ -482,14 +486,19 @@ var ExagentRegistry = class {
482
486
  return nextId;
483
487
  }
484
488
  /**
485
- * Generate the message to sign for wallet linking
489
+ * Generate the message hash for wallet linking.
490
+ * Matches the contract's keccak256(abi.encodePacked(...)) exactly.
491
+ * Sign the returned hash with signMessage({ raw: hash }) to produce a valid signature.
486
492
  * @param wallet The wallet to link
487
493
  * @param agentId The agent ID to link to
488
494
  * @param nonce The current nonce for the wallet
489
- * @returns Message to sign
495
+ * @returns keccak256 hash of the packed message (32 bytes)
490
496
  */
491
497
  static generateLinkMessage(wallet, agentId, nonce) {
492
- return `Link wallet ${wallet} to Exagent ${agentId} nonce ${nonce}`;
498
+ return keccak256(encodePacked(
499
+ ["string", "address", "string", "uint256", "string", "uint256"],
500
+ ["Link wallet ", wallet, " to Exagent ", agentId, " nonce ", nonce]
501
+ ));
493
502
  }
494
503
  // ============ V4: One Agent Per Wallet ============
495
504
  /**
@@ -621,8 +630,8 @@ var ExagentRegistry = class {
621
630
  * @returns keccak256 hash of the config
622
631
  */
623
632
  static calculateConfigHash(provider, model) {
624
- const { keccak256, encodePacked } = __require("viem");
625
- return keccak256(encodePacked(["string", "string"], [provider, model]));
633
+ const { keccak256: keccak2562, encodePacked: encodePacked2 } = __require("viem");
634
+ return keccak2562(encodePacked2(["string", "string"], [provider, model]));
626
635
  }
627
636
  };
628
637
 
@@ -1948,14 +1957,14 @@ var ExagentClient = class {
1948
1957
  /**
1949
1958
  * Link an additional wallet to this agent
1950
1959
  * @param wallet Wallet address to link
1951
- * @param signMessage Function to sign a message with the wallet
1960
+ * @param signMessage Function to sign the message hash with the wallet (use signMessage({ raw: hash }))
1952
1961
  */
1953
1962
  async linkWallet(wallet, signMessage) {
1954
1963
  const agentId = await this.getAgentId();
1955
1964
  if (!agentId) throw new Error("Agent not registered");
1956
1965
  const nonce = await this.registry.getNonce(wallet);
1957
- const message = ExagentRegistry.generateLinkMessage(wallet, agentId, nonce);
1958
- const signature = await signMessage(message);
1966
+ const messageHash = ExagentRegistry.generateLinkMessage(wallet, agentId, nonce);
1967
+ const signature = await signMessage({ raw: messageHash });
1959
1968
  return this.registry.linkWallet(agentId, wallet, signature);
1960
1969
  }
1961
1970
  /**
@@ -2411,7 +2420,7 @@ var ExagentClient = class {
2411
2420
  }
2412
2421
  /**
2413
2422
  * Sign a message with the wallet's private key (EIP-191 personal sign)
2414
- * @param message The message to sign
2423
+ * @param message The message to sign — string for UTF-8, or { raw: Hex } for raw bytes
2415
2424
  * @returns The signature
2416
2425
  */
2417
2426
  async signMessage(message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exagent/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript SDK for Exagent",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",