@depthhq/maker-sdk 0.1.17 → 0.1.18

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.
@@ -5,4 +5,7 @@ export type EthereumProvider = {
5
5
  params?: unknown[];
6
6
  }): Promise<unknown>;
7
7
  };
8
- export declare function connect_hyperliquid(provider: EthereumProvider): Promise<AbstractViemJsonRpcAccount>;
8
+ export declare function connect_hyperliquid(provider: EthereumProvider, options?: {
9
+ timeoutMs?: number;
10
+ signal?: AbortSignal;
11
+ }): Promise<AbstractViemJsonRpcAccount>;
package/dist/index.js CHANGED
@@ -28422,13 +28422,40 @@ async function createDepthMaker(options) {
28422
28422
  return MakerClient.create(options);
28423
28423
  }
28424
28424
  // src/hedge/wallet.ts
28425
- async function connect_hyperliquid(provider) {
28426
- const accounts2 = await provider.request({ method: "eth_requestAccounts" });
28425
+ async function connect_hyperliquid(provider, options = {}) {
28426
+ const timeoutMs = options.timeoutMs ?? 60000;
28427
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 300000)
28428
+ throw new RangeError("Wallet timeout must be 1 to 300000 milliseconds");
28429
+ const request = (input) => new Promise((resolve, reject) => {
28430
+ const signal = options.signal;
28431
+ if (signal?.aborted) {
28432
+ reject(new Error("Wallet connection cancelled"));
28433
+ return;
28434
+ }
28435
+ let settled = false;
28436
+ const finish = (action) => {
28437
+ if (settled)
28438
+ return;
28439
+ settled = true;
28440
+ clearTimeout(timer);
28441
+ signal?.removeEventListener("abort", abort);
28442
+ action();
28443
+ };
28444
+ const abort = () => finish(() => reject(new Error("Wallet connection cancelled")));
28445
+ const timer = setTimeout(() => finish(() => reject(new Error("Wallet did not respond. Open the extension and resolve its pending request."))), timeoutMs);
28446
+ signal?.addEventListener("abort", abort, { once: true });
28447
+ try {
28448
+ provider.request(input).then((value) => finish(() => resolve(value)), (cause) => finish(() => reject(cause)));
28449
+ } catch (cause) {
28450
+ finish(() => reject(cause));
28451
+ }
28452
+ });
28453
+ const accounts2 = await request({ method: "eth_requestAccounts" });
28427
28454
  if (!Array.isArray(accounts2) || typeof accounts2[0] !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(accounts2[0]))
28428
28455
  throw new Error("The Ethereum wallet did not provide an account");
28429
28456
  const address3 = accounts2[0];
28430
28457
  const check = async () => {
28431
- const current = await provider.request({ method: "eth_accounts" });
28458
+ const current = await request({ method: "eth_accounts" });
28432
28459
  if (!Array.isArray(current) || typeof current[0] !== "string" || current[0].toLowerCase() !== address3.toLowerCase())
28433
28460
  throw new Error("The Ethereum wallet account changed; connect it again");
28434
28461
  };
@@ -28438,14 +28465,14 @@ async function connect_hyperliquid(provider) {
28438
28465
  return [address3];
28439
28466
  },
28440
28467
  async getChainId() {
28441
- const chain = await provider.request({ method: "eth_chainId" });
28468
+ const chain = await request({ method: "eth_chainId" });
28442
28469
  if (typeof chain !== "string" || !/^0x[0-9a-fA-F]+$/.test(chain) || !Number.isSafeInteger(Number(chain)))
28443
28470
  throw new Error("Ethereum wallet chain is invalid");
28444
28471
  return Number(chain);
28445
28472
  },
28446
28473
  async signTypedData(params) {
28447
28474
  await check();
28448
- const signature = await provider.request({
28475
+ const signature = await request({
28449
28476
  method: "eth_signTypedData_v4",
28450
28477
  params: [
28451
28478
  address3,
@@ -26944,13 +26944,40 @@ async function createDepthMaker(options) {
26944
26944
  return MakerClient.create(options);
26945
26945
  }
26946
26946
  // src/hedge/wallet.ts
26947
- async function connect_hyperliquid(provider) {
26948
- const accounts2 = await provider.request({ method: "eth_requestAccounts" });
26947
+ async function connect_hyperliquid(provider, options = {}) {
26948
+ const timeoutMs = options.timeoutMs ?? 60000;
26949
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 300000)
26950
+ throw new RangeError("Wallet timeout must be 1 to 300000 milliseconds");
26951
+ const request = (input) => new Promise((resolve, reject) => {
26952
+ const signal = options.signal;
26953
+ if (signal?.aborted) {
26954
+ reject(new Error("Wallet connection cancelled"));
26955
+ return;
26956
+ }
26957
+ let settled = false;
26958
+ const finish = (action) => {
26959
+ if (settled)
26960
+ return;
26961
+ settled = true;
26962
+ clearTimeout(timer);
26963
+ signal?.removeEventListener("abort", abort);
26964
+ action();
26965
+ };
26966
+ const abort = () => finish(() => reject(new Error("Wallet connection cancelled")));
26967
+ const timer = setTimeout(() => finish(() => reject(new Error("Wallet did not respond. Open the extension and resolve its pending request."))), timeoutMs);
26968
+ signal?.addEventListener("abort", abort, { once: true });
26969
+ try {
26970
+ provider.request(input).then((value) => finish(() => resolve(value)), (cause) => finish(() => reject(cause)));
26971
+ } catch (cause) {
26972
+ finish(() => reject(cause));
26973
+ }
26974
+ });
26975
+ const accounts2 = await request({ method: "eth_requestAccounts" });
26949
26976
  if (!Array.isArray(accounts2) || typeof accounts2[0] !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(accounts2[0]))
26950
26977
  throw new Error("The Ethereum wallet did not provide an account");
26951
26978
  const address3 = accounts2[0];
26952
26979
  const check = async () => {
26953
- const current = await provider.request({ method: "eth_accounts" });
26980
+ const current = await request({ method: "eth_accounts" });
26954
26981
  if (!Array.isArray(current) || typeof current[0] !== "string" || current[0].toLowerCase() !== address3.toLowerCase())
26955
26982
  throw new Error("The Ethereum wallet account changed; connect it again");
26956
26983
  };
@@ -26960,14 +26987,14 @@ async function connect_hyperliquid(provider) {
26960
26987
  return [address3];
26961
26988
  },
26962
26989
  async getChainId() {
26963
- const chain = await provider.request({ method: "eth_chainId" });
26990
+ const chain = await request({ method: "eth_chainId" });
26964
26991
  if (typeof chain !== "string" || !/^0x[0-9a-fA-F]+$/.test(chain) || !Number.isSafeInteger(Number(chain)))
26965
26992
  throw new Error("Ethereum wallet chain is invalid");
26966
26993
  return Number(chain);
26967
26994
  },
26968
26995
  async signTypedData(params) {
26969
26996
  await check();
26970
- const signature = await provider.request({
26997
+ const signature = await request({
26971
26998
  method: "eth_signTypedData_v4",
26972
26999
  params: [
26973
27000
  address3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depthhq/maker-sdk",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },