From 317fa773a0e060b0b521ee049ca5978331a8b016 Mon Sep 17 00:00:00 2001 From: JesseTheRobot Date: Fri, 2 Feb 2024 15:21:52 +0000 Subject: [PATCH] v0.1.6-a2 --- package.json | 4 ++-- src/web/shims/viemv2.ts | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 14df4a49..93b907db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@irys/sdk", - "version": "0.1.6-a1", + "version": "0.1.6-a2", "description": "JS client for Irys", "repository": "https://github.com/Bundlr-Network/js-client.git", "author": "Irys", @@ -119,7 +119,7 @@ "aptos": "=1.8.5", "arbundles": "^0.10.0", "async-retry": "^1.3.3", - "axios": "^1.4.0", + "axios": "^1.6.7", "base64url": "^3.0.1", "bignumber.js": "^9.0.1", "bs58": "5.0.0", diff --git a/src/web/shims/viemv2.ts b/src/web/shims/viemv2.ts index 081a520f..ed53fa71 100644 --- a/src/web/shims/viemv2.ts +++ b/src/web/shims/viemv2.ts @@ -6,9 +6,10 @@ import type { mainnet } from "viem/chains"; import type { Tx } from "src/common/types"; import type EthereumConfig from "../tokens/ethereum"; import type ERC20Config from "../tokens/erc20"; +import { InjectedTypedEthereumSigner } from "arbundles/web"; // TODO: figure out a better way to do this. -export async function augmentViemV2(tokenConfig: EthereumConfig, opts: any): Promise { +export function augmentViemV2(tokenConfig: EthereumConfig, opts: any): void { const walletClient = opts.provider as WalletClient; const publicClient = opts.publicClient as PublicClient, typeof mainnet>; @@ -19,13 +20,23 @@ export async function augmentViemV2(tokenConfig: EthereumConfig, opts: any): Pro }.bind(tokenConfig); tokenConfig.getFee = async (_amount) => new BigNumber(0); - opts.provider.getSigner = () => ({ - getAddress: async () => walletClient.getAddresses().then((r) => r[0]), - _signTypedData: async (domain, types, message): Promise => { - message["Transaction hash"] = "0x" + Buffer.from(message["Transaction hash"]).toString("hex"); - return await walletClient.signTypedData({ account: message.address, domain, types, primaryType: "Bundlr", message }); - }, - }); + + tokenConfig.getSigner = function () { + if (!this.signer) { + this.signer = new InjectedTypedEthereumSigner({ + getSigner: () => ({ + getAddress: async () => walletClient.getAddresses().then((r) => r[0]), + _signTypedData: async (domain, types, message): Promise => { + message["Transaction hash"] = "0x" + Buffer.from(message["Transaction hash"]).toString("hex"); + // @ts-expect-error types + return await walletClient.signTypedData({ account: message.address, domain, types, primaryType: "Bundlr", message }); + }, + }), + }); + } + return this.signer; + }.bind(tokenConfig); + tokenConfig.getCurrentHeight = async () => new BigNumber((await publicClient.getBlockNumber()).toString()); // if this is ERC20