From 8fd5d93e875f8f520567adeba3cc0a8b5d35642d Mon Sep 17 00:00:00 2001 From: joepegler Date: Wed, 18 Sep 2024 10:46:30 +0100 Subject: [PATCH 1/4] feat: nextjs logs (#581) --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/account/utils/Helpers.ts | 17 +---------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8f95d7a8..07fa28376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @biconomy/account +## 4.6.3 + +### Patch Changes + +- fix nextjs logs + ## 4.6.2 ### Patch Changes diff --git a/package.json b/package.json index 3f618bbdf..00b5d3725 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "sideEffects": false, "name": "@biconomy/account", "author": "Biconomy", - "version": "4.6.2", + "version": "4.6.3", "description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.", "keywords": [ "erc-7579", diff --git a/src/account/utils/Helpers.ts b/src/account/utils/Helpers.ts index 38dc3e01d..49824ed16 100644 --- a/src/account/utils/Helpers.ts +++ b/src/account/utils/Helpers.ts @@ -1,16 +1 @@ -const VARS_T0_CHECK = [ - "BICONOMY_SDK_DEBUG", - "REACT_APP_BICONOMY_SDK_DEBUG", - "NEXT_PUBLIC_BICONOMY_SDK_DEBUG" -] - -export const isDebugging = (): boolean => { - try { - // @ts-ignore - return VARS_T0_CHECK.some( - (key) => process?.env?.[key]?.toString() === "true" - ) - } catch (e) { - return false - } -} +export const isDebugging = () => !!process.env.NEXT_PUBLIC_BICONOMY_SDK_DEBUG || !!process.env.REACT_APP_BICONOMY_SDK_DEBUG || !!process.env.BICONOMY_SDK_DEBUG From 67ec3687112797041b69caaa703d9d7f61422fdc Mon Sep 17 00:00:00 2001 From: Vasile Gabriel Marian <56271768+VGabriel45@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:51:16 +0300 Subject: [PATCH 2/4] feat: generalized url chain id regex check (#586) Co-authored-by: VGabriel45 --- src/bundler/utils/Utils.ts | 63 +++++++++++++++++++++++++++----------- tests/bundler/read.test.ts | 37 ++++++++++++++++++---- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/src/bundler/utils/Utils.ts b/src/bundler/utils/Utils.ts index 700a2bb59..7587b3749 100644 --- a/src/bundler/utils/Utils.ts +++ b/src/bundler/utils/Utils.ts @@ -1,23 +1,50 @@ -export const extractChainIdFromBundlerUrl = (url: string): number => { +/** + * Extracts the chain ID from a given URL. + * + * @param url - The URL to extract the chain ID from. + * @returns The extracted chain ID as a number. + * @throws {Error} If the chain ID is not found in the URL or is invalid. + * + * @example + * // Returns 80001 + * extractChainIdFromUrl("https://example.com/api/v2/80001/rpc") + */ +export const extractChainIdFromUrl = (url: string): number => { try { - const regex = /\/api\/v2\/(\d+)\/[a-zA-Z0-9.-]+$/ - // biome-ignore lint/style/noNonNullAssertion: - const match = regex.exec(url)! - return Number.parseInt(match[1]) - } catch (error) { - throw new Error("Invalid chain id") - } -} - -export const extractChainIdFromPaymasterUrl = (url: string): number => { - try { - const regex = /\/api\/v\d+\/(\d+)\// - const match = regex.exec(url) + const regex = /\/(\d+)\//; + const match = regex.exec(new URL(url).pathname); if (!match) { - throw new Error("Invalid URL format") + throw new Error("Chain ID not found in URL"); } - return Number.parseInt(match[1]) + const chainId = Number.parseInt(match[1], 10); + if (Number.isNaN(chainId)) { + throw new Error("Invalid chain ID"); + } + return chainId; } catch (error) { - throw new Error("Invalid chain id") + if (error instanceof Error) { + throw new Error(`Invalid chain id: ${error.message}`); + } + throw new Error("Invalid chain id"); } -} +}; + +/** + * Extracts the chain ID from a bundler URL. + * + * @param url - The bundler URL to extract the chain ID from. + * @returns The extracted chain ID as a number. + * @throws {Error} If the chain ID is not found in the URL or is invalid. + */ +export const extractChainIdFromBundlerUrl = (url: string): number => + extractChainIdFromUrl(url); + +/** + * Extracts the chain ID from a paymaster URL. + * + * @param url - The paymaster URL to extract the chain ID from. + * @returns The extracted chain ID as a number. + * @throws {Error} If the chain ID is not found in the URL or is invalid. + */ +export const extractChainIdFromPaymasterUrl = (url: string): number => + extractChainIdFromUrl(url); \ No newline at end of file diff --git a/tests/bundler/read.test.ts b/tests/bundler/read.test.ts index 2b8c27b4b..2dcbca7a5 100644 --- a/tests/bundler/read.test.ts +++ b/tests/bundler/read.test.ts @@ -6,9 +6,8 @@ import { type BiconomySmartAccountV2Config, compareChainIds, createSmartAccountClient, - getCustomChain } from "../../src/account" -import { createBundler } from "../../src/bundler" +import { createBundler, extractChainIdFromUrl } from "../../src/bundler" import { getBundlerUrl, getConfig } from "../utils" describe("Bundler:Read", () => { @@ -51,11 +50,11 @@ describe("Bundler:Read", () => { }) ) ) - ;[smartAccountAddress, smartAccountAddressTwo] = await Promise.all( - [smartAccount, smartAccountTwo].map((account) => - account.getAccountAddress() + ;[smartAccountAddress, smartAccountAddressTwo] = await Promise.all( + [smartAccount, smartAccountTwo].map((account) => + account.getAccountAddress() + ) ) - ) }) test.concurrent( @@ -200,4 +199,30 @@ describe("Bundler:Read", () => { await expect(createAccount).rejects.toThrow() } ) + + test.concurrent('extracts chain ID from various URL structures', () => { + const testCases = [ + { url: "https://example.com/api/v2/1234/endpoint", expected: 1234 }, + { url: "https://api.example.com/v1/5678/resource", expected: 5678 }, + { url: "http://localhost:3000/api/9876/action", expected: 9876 }, + { url: "https://example.com/1234/api/v2/endpoint", expected: 1234 }, + { url: "https://example.com/network/5678/resource/action", expected: 5678 }, + { url: "https://api.example.com/prefix/9876/suffix", expected: 9876 }, + { url: "https://example.com/api/v2/1234/5678/endpoint", expected: 1234 }, + { url: "https://example.com/api/v2/endpoint/1234/", expected: 1234 }, + { url: "https://example.com/api/v2/1234/endpoint?param=value", expected: 1234 }, + { url: "https://example.com/api/v2/1234/endpoint#section", expected: 1234 }, + { url: "https://subdomain.example.com/api/1234/endpoint", expected: 1234 }, + { url: "http://192.168.1.1/api/1234/endpoint", expected: 1234 }, + { url: "https://user:pass@example.com/api/1234/endpoint", expected: 1234 }, + { url: "https://example.com/1234/", expected: 1234 }, + { url: "https://api.example.com/v1/chain/5678/details", expected: 5678 }, + { url: "https://paymaster.biconomy.io/api/v1/80001/-RObQRX9ei.fc6918eb-c582-4417-9d5a-0507b17cfe71", expected: 80001 }, + { url: "https://bundler.biconomy.io/api/v2/80002/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44", expected: 80002 }, + ]; + + for (const { url, expected } of testCases) { + expect(extractChainIdFromUrl(url)).toBe(expected); + } + }) }) From 71d39255ca3b79a44a6efce4dc3eb7eeb7673b52 Mon Sep 17 00:00:00 2001 From: joepegler Date: Fri, 11 Oct 2024 15:08:28 +0100 Subject: [PATCH 3/4] chore: reduce default wait interval (#550) --- CHANGELOG.md | 8 ++++++-- package.json | 2 +- src/bundler/Bundler.ts | 15 ++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fa28376..5a34ebdc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @biconomy/account +## 4.6.4 + +### Patch Changes + +- shorten default pollInterval + ## 4.6.3 ### Patch Changes @@ -16,8 +22,6 @@ ### Patch Changes -- Taiko testnet fix - ## 4.5.5 ### Patch Changes diff --git a/package.json b/package.json index 00b5d3725..4fc3508fb 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "sideEffects": false, "name": "@biconomy/account", "author": "Biconomy", - "version": "4.6.3", + "version": "4.5.6", "description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.", "keywords": [ "erc-7579", diff --git a/src/bundler/Bundler.ts b/src/bundler/Bundler.ts index b9ced0b4b..6c489115d 100644 --- a/src/bundler/Bundler.ts +++ b/src/bundler/Bundler.ts @@ -32,6 +32,7 @@ import type { } from "./utils/Types.js" import { extractChainIdFromBundlerUrl } from "./utils/Utils.js" +const POLL_INTERVAL = 2000; /** * This class implements IBundler interface. * Implementation sends UserOperation to a bundler URL as per ERC4337 standard. @@ -182,7 +183,7 @@ export class Bundler implements IBundler { let totalDuration = 0 return new Promise((resolve, reject) => { - const intervalValue = this.UserOpReceiptIntervals[chainId] || 5000 // default 5 seconds + const intervalValue = this.UserOpReceiptIntervals[chainId] || POLL_INTERVAL const intervalId = setInterval(async () => { try { const userOpResponse = await this.getUserOpReceipt( @@ -215,10 +216,8 @@ export class Bundler implements IBundler { clearInterval(intervalId) reject( new Error( - `Exceeded maximum duration (${ - maxDuration / 1000 - } sec) waiting to get receipt for userOpHash ${ - sendUserOperationResponse.result + `Exceeded maximum duration (${maxDuration / 1000 + } sec) waiting to get receipt for userOpHash ${sendUserOperationResponse.result }. Try getting the receipt manually using eth_getUserOperationReceipt rpc method on bundler` ) ) @@ -255,10 +254,8 @@ export class Bundler implements IBundler { clearInterval(intervalId) reject( new Error( - `Exceeded maximum duration (${ - maxDuration / 1000 - } sec) waiting to get receipt for userOpHash ${ - sendUserOperationResponse.result + `Exceeded maximum duration (${maxDuration / 1000 + } sec) waiting to get receipt for userOpHash ${sendUserOperationResponse.result }. Try getting the receipt manually using eth_getUserOperationReceipt rpc method on bundler` ) ) From bbbb3d9378c3c640d7a415e31ca537ede54c825c Mon Sep 17 00:00:00 2001 From: Joe Pegler Date: Fri, 11 Oct 2024 15:12:17 +0100 Subject: [PATCH 4/4] chore: bundler url fix --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a34ebdc0..ef49d6bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @biconomy/account +## 4.5.7 + +### Patch Changes + +- bundlerUrl fix + ## 4.6.4 ### Patch Changes diff --git a/package.json b/package.json index 4fc3508fb..8019f1605 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "sideEffects": false, "name": "@biconomy/account", "author": "Biconomy", - "version": "4.5.6", + "version": "4.5.7", "description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.", "keywords": [ "erc-7579",