From 7a2f231b676f41284dc87ec65faaea518b6ecf55 Mon Sep 17 00:00:00 2001 From: Maharshi Mishra Date: Sun, 20 Oct 2024 21:31:20 +0530 Subject: [PATCH] removed top level await --- .../sfa-web-ton-telegram-example/src/App.tsx | 2 +- .../src/tonRpc.ts | 26 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/single-factor-auth-web/sfa-web-ton-telegram-example/src/App.tsx b/single-factor-auth-web/sfa-web-ton-telegram-example/src/App.tsx index 1cb120e1..34489116 100644 --- a/single-factor-auth-web/sfa-web-ton-telegram-example/src/App.tsx +++ b/single-factor-auth-web/sfa-web-ton-telegram-example/src/App.tsx @@ -5,7 +5,7 @@ import { CommonPrivateKeyProvider } from "@web3auth/base-provider"; import { getHttpEndpoint } from "@orbs-network/ton-access"; import { useLaunchParams, isTMA } from "@telegram-apps/sdk-react"; import { mockTelegramEnvironment } from "./hooks/useMockTelegramInitData"; -import TonRPC from "./tonRpc"; +// import TonRPC from "./tonRpc"; import Loading from "./Loading"; import "./App.css"; diff --git a/single-factor-auth-web/sfa-web-ton-telegram-example/src/tonRpc.ts b/single-factor-auth-web/sfa-web-ton-telegram-example/src/tonRpc.ts index b0debae5..b616ef64 100644 --- a/single-factor-auth-web/sfa-web-ton-telegram-example/src/tonRpc.ts +++ b/single-factor-auth-web/sfa-web-ton-telegram-example/src/tonRpc.ts @@ -2,17 +2,21 @@ import type { IProvider } from "@web3auth/base"; import { getHttpEndpoint } from "@orbs-network/ton-access"; import TonWeb from "tonweb"; -const rpc = await getHttpEndpoint({ - network: "testnet", - protocol: "json-rpc", -}); - export default class TonRPC { private provider: IProvider; private tonweb: TonWeb; constructor(provider: IProvider) { this.provider = provider; + // Initialize tonweb in the constructor + this.initTonWeb(); + } + + private async initTonWeb() { + const rpc = await getHttpEndpoint({ + network: "testnet", + protocol: "json-rpc", + }); this.tonweb = new TonWeb(new TonWeb.HttpProvider(rpc)); } @@ -32,7 +36,7 @@ export default class TonRPC { } } - getChainId(): string { + getChainId(): string { return "testnet"; } @@ -77,7 +81,6 @@ export default class TonRPC { const result = await transfer.send(); console.log(result); - // Return the full result for display in uiConsole return result; } catch (error) { console.error("Error sending transaction:", error); @@ -101,23 +104,19 @@ export default class TonRPC { } } - public getKeyPairFromPrivateKey(privateKey: string): { publicKey: Uint8Array; secretKey: Uint8Array } { - // Convert the hex string to a Uint8Array + private getKeyPairFromPrivateKey(privateKey: string): { publicKey: Uint8Array; secretKey: Uint8Array } { const privateKeyBytes = new Uint8Array(privateKey.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16))); - // Ensure the private key is 32 bytes (256 bits) if (privateKeyBytes.length !== 32) { - // If it's shorter, pad it. If it's longer, truncate it. const adjustedPrivateKey = new Uint8Array(32); adjustedPrivateKey.set(privateKeyBytes.slice(0, 32)); return TonWeb.utils.nacl.sign.keyPair.fromSeed(adjustedPrivateKey); } - // If it's already 32 bytes, use it directly return TonWeb.utils.nacl.sign.keyPair.fromSeed(privateKeyBytes); } - async getPrivateKey(): Promise { + private async getPrivateKey(): Promise { try { return await this.provider.request({ method: "private_key", @@ -127,5 +126,4 @@ export default class TonRPC { throw error; } } - } \ No newline at end of file