@lifi/sdk-provider-ethereum 4.0.1 → 4.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lifi/sdk-provider-ethereum
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#406](https://github.com/lifinance/sdk/pull/406) [`f7775fc`](https://github.com/lifinance/sdk/commit/f7775fc5ec687aa5d01d1ef4db557faf08aa9144) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependency: viem to 2.53.1.
8
+
3
9
  ## 4.0.1
4
10
 
5
11
  ### Patch Changes
@@ -23,7 +23,7 @@ async function deriveKey(ownerAddress) {
23
23
  }, false, ["encrypt", "decrypt"]);
24
24
  }
25
25
  async function encrypt(plaintext, key) {
26
- const iv = crypto.getRandomValues(new Uint8Array(12));
26
+ const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
27
27
  const ciphertext = await crypto.subtle.encrypt({
28
28
  name: "AES-GCM",
29
29
  iv
@@ -1 +1 @@
1
- {"version":3,"file":"agentWallet.js","names":[],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB,QAAc,KAAK;AACjD,MAAM,uBAAuB,OAAU;AAMvC,MAAM,kBAAkB;AAcxB,SAAS,cACP,cACA,YAAY,4BACJ;CACR,OAAO,GAAG,UAAU,GAAG,aAAa,YAAY;AAClD;AAEA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,UAAU,IAAI,YAAY;AAEhC,eAAe,UAAU,cAA0C;CACjE,MAAM,cAAc,MAAM,OAAO,OAAO,UACtC,OAC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A,WAC8D;CAC9D,MAAM,MAAM,MAAM,QAAQ,IAAI,cAAc,cAAc,SAAS,CAAC;CACpE,IAAI,CAAC,KACH,OAAO;CAET,IAAI;EACF,MAAM,OAA0B,KAAK,MAAM,GAAG;EAC9C,MAAM,gBAAgB,MAAM,UAAU,YAAY;EAElD,OAAO;GACL,UAAA,GAAA,cAAA,oBAAA,CAA6B,MAFL,QAAQ,KAAK,MAAM,aAAa,CAEjB;GACvC,WAAW,KAAK;EAClB;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,uBACpB,SACA,cACA,sBACA,WAC4B;CAC5B,IAAI,sBAAsB;EACxB,MAAM,WAAW,MAAM,gBAAgB,SAAS,cAAc,SAAS;EACvE,IACE,UAAU,QAAQ,QAAQ,YAAY,MACpC,qBAAqB,YAAY,KACnC,SAAS,YAAY,KAAK,IAAI,IAAI,sBAElC,OAAO;GACL,SAAS,SAAS;GAClB,eAAe;GACf,WAAW,SAAS;EACtB;CAEJ;CAEA,MAAM,cAAA,GAAA,cAAA,mBAAA,CAAgC;CACtC,MAAM,WAAA,GAAA,cAAA,oBAAA,CAA8B,UAAU;CAC9C,MAAM,YAAY,KAAK,IAAI,IAAI;CAC/B,MAAM,gBACJ,SACA,cACA,QAAQ,SACR,YACA,SACF;CACA,OAAO;EAAE;EAAS,eAAe;EAAM;CAAU;AACnD"}
1
+ {"version":3,"file":"agentWallet.js","names":[],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB,QAAc,KAAK;AACjD,MAAM,uBAAuB,OAAU;AAMvC,MAAM,kBAAkB;AAcxB,SAAS,cACP,cACA,YAAY,4BACJ;CACR,OAAO,GAAG,UAAU,GAAG,aA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CAGH;EAC7C,WAAW,KAAK,IAAI,IAAI;CAC1B;CACA,MAAM,QAAQ,IACZ,cAAc,cAAc,SAAS,GACrC,KAAK,UAAU,IAAI,CACrB;AACF;AAEA,eAAe,gBACb,SACA,cACA,WAC8D;CAC9D,MAAM,MAAM,MAAM,QAAQ,IAAI,cAAc,cAAc,SAAS,CAAC;CACpE,IAAI,CAAC,KACH,OAAO;CAET,IAAI;EACF,MAAM,OAA0B,KAAK,MAAM,GAAG;EAC9C,MAAM,gBAAgB,MAAM,UAAU,YAAY;EAElD,OAAO;GACL,UAAA,GAAA,cAAA,oBAAA,CAA6B,MAFL,QAAQ,KAAK,MAAM,aAAa,CAEjB;GACvC,WAAW,KAAK;EAClB;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,uBACpB,SACA,cACA,sBACA,WAC4B;CAC5B,IAAI,sBAAsB;EACxB,MAAM,WAAW,MAAM,gBAAgB,SAAS,cAAc,SAAS;EACvE,IACE,UAAU,QAAQ,QAAQ,YAAY,MACpC,qBAAqB,YAAY,KACnC,SAAS,YAAY,KAAK,IAAI,IAAI,sBAElC,OAAO;GACL,SAAS,SAAS;GAClB,eAAe;GACf,WAAW,SAAS;EACtB;CAEJ;CAEA,MAAM,cAAA,GAAA,cAAA,mBAAA,CAAgC;CACtC,MAAM,WAAA,GAAA,cAAA,oBAAA,CAA8B,UAAU;CAC9C,MAAM,YAAY,KAAK,IAAI,IAAI;CAC/B,MAAM,gBACJ,SACA,cACA,QAAQ,SACR,YACA,SACF;CACA,OAAO;EAAE;EAAS,eAAe;EAAM;CAAU;AACnD"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-ethereum";
3
- declare const version = "4.0.1";
3
+ declare const version = "4.0.2";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/version.ts
3
3
  const name = "@lifi/sdk-provider-ethereum";
4
- const version = "4.0.1";
4
+ const version = "4.0.2";
5
5
  //#endregion
6
6
  exports.name = name;
7
7
  exports.version = version;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.1'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.2'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -22,7 +22,7 @@ async function deriveKey(ownerAddress) {
22
22
  }, false, ["encrypt", "decrypt"]);
23
23
  }
24
24
  async function encrypt(plaintext, key) {
25
- const iv = crypto.getRandomValues(new Uint8Array(12));
25
+ const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
26
26
  const ciphertext = await crypto.subtle.encrypt({
27
27
  name: "AES-GCM",
28
28
  iv
@@ -1 +1 @@
1
- {"version":3,"file":"agentWallet.js","names":[],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB,QAAc,KAAK;AACjD,MAAM,uBAAuB,OAAU;AAMvC,MAAM,kBAAkB;AAcxB,SAAS,cACP,cACA,YAAY,4BACJ;CACR,OAAO,GAAG,UAAU,GAAG,aAAa,YAAY;AAClD;AAEA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,UAAU,IAAI,YAAY;AAEhC,eAAe,UAAU,cAA0C;CACjE,MAAM,cAAc,MAAM,OAAO,OAAO,UACtC,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cACA,WAC8D;CAC9D,MAAM,MAAM,MAAM,QAAQ,IAAI,cAAc,cAAc,SAAS,CAAC;CACpE,IAAI,CAAC,KACH,OAAO;CAET,IAAI;EACF,MAAM,OAA0B,KAAK,MAAM,GAAG;EAC9C,MAAM,gBAAgB,MAAM,UAAU,YAAY;EAElD,OAAO;GACL,SAAS,oBAAoB,MAFL,QAAQ,KAAK,MAAM,aAAa,CAEjB;GACvC,WAAW,KAAK;EAClB;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,uBACpB,SACA,cACA,sBACA,WAC4B;CAC5B,IAAI,sBAAsB;EACxB,MAAM,WAAW,MAAM,gBAAgB,SAAS,cAAc,SAAS;EACvE,IACE,UAAU,QAAQ,QAAQ,YAAY,MACpC,qBAAqB,YAAY,KACnC,SAAS,YAAY,KAAK,IAAI,IAAI,sBAElC,OAAO;GACL,SAAS,SAAS;GAClB,eAAe;GACf,WAAW,SAAS;EACtB;CAEJ;CAEA,MAAM,aAAa,mBAAmB;CACtC,MAAM,UAAU,oBAAoB,UAAU;CAC9C,MAAM,YAAY,KAAK,IAAI,IAAI;CAC/B,MAAM,gBACJ,SACA,cACA,QAAQ,SACR,YACA,SACF;CACA,OAAO;EAAE;EAAS,eAAe;EAAM;CAAU;AACnD"}
1
+ {"version":3,"file":"agentWallet.js","names":[],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB,QAAc,KAAK;AACjD,MAAM,uBAAuB,OAAU;AAMvC,MAAM,kBAAkB;AAcxB,SAAS,cACP,cACA,YAAY,4BACJ;CACR,OAAO,GAAG,UAAU,GAAG,aAAa,YAAY;AAClD;AAEA,MAAM,UAAU,IAAI,YAAY;AAChC,M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M,QAAQ,IACZ,cAAc,cAAc,SAAS,GACrC,KAAK,UAAU,IAAI,CACrB;AACF;AAEA,eAAe,gBACb,SACA,cACA,WAC8D;CAC9D,MAAM,MAAM,MAAM,QAAQ,IAAI,cAAc,cAAc,SAAS,CAAC;CACpE,IAAI,CAAC,KACH,OAAO;CAET,IAAI;EACF,MAAM,OAA0B,KAAK,MAAM,GAAG;EAC9C,MAAM,gBAAgB,MAAM,UAAU,YAAY;EAElD,OAAO;GACL,SAAS,oBAAoB,MAFL,QAAQ,KAAK,MAAM,aAAa,CAEjB;GACvC,WAAW,KAAK;EAClB;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,uBACpB,SACA,cACA,sBACA,WAC4B;CAC5B,IAAI,sBAAsB;EACxB,MAAM,WAAW,MAAM,gBAAgB,SAAS,cAAc,SAAS;EACvE,IACE,UAAU,QAAQ,QAAQ,YAAY,MACpC,qBAAqB,YAAY,KACnC,SAAS,YAAY,KAAK,IAAI,IAAI,sBAElC,OAAO;GACL,SAAS,SAAS;GAClB,eAAe;GACf,WAAW,SAAS;EACtB;CAEJ;CAEA,MAAM,aAAa,mBAAmB;CACtC,MAAM,UAAU,oBAAoB,UAAU;CAC9C,MAAM,YAAY,KAAK,IAAI,IAAI;CAC/B,MAAM,gBACJ,SACA,cACA,QAAQ,SACR,YACA,SACF;CACA,OAAO;EAAE;EAAS,eAAe;EAAM;CAAU;AACnD"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-ethereum";
3
- declare const version = "4.0.1";
3
+ declare const version = "4.0.2";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-ethereum";
3
- const version = "4.0.1";
3
+ const version = "4.0.2";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.1'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.2'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk-provider-ethereum",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -28,7 +28,7 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "viem": "^2.52.2",
31
+ "viem": "^2.53.1",
32
32
  "@lifi/sdk": "4.0.1"
33
33
  },
34
34
  "publishConfig": {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-ethereum'
2
- export const version = '4.0.1'
2
+ export const version = '4.0.2'