hashgraph / hedera-sdk-js

Hedera™ Hashgraph SDK for JavaScript/TypeScript
https://docs.hedera.com/guides/docs/sdks
Apache License 2.0
276 stars 145 forks source link

Expo Version (expo@51.0.14) #2361

Open rubixvi opened 5 months ago

rubixvi commented 5 months ago

Description

The current Expo Version in the SDK is ^49.0.16 within the script. However, the latest Expo Version is expo@51.0.14

Can we get this updated?

Currently, by passing it with npm install --save @hashgraph/sdk --legacy-peer-deps

Steps to reproduce

  1. Visual Code
  2. Run npx expo install
  3. Run npm install --save @hashgraph/sdk

Additional context

PS F:\XRL Wallet\dev> npm install --save @hashgraph/sdk npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @hashgraph/cryptography@1.4.8-beta.5 npm WARN Found: expo@51.0.14 npm WARN node_modules/expo npm WARN peer expo@"" from expo-application@5.9.1 npm WARN node_modules/expo-application npm WARN expo-application@"~5.9.0" from expo-auth-session@5.5.2 npm WARN node_modules/expo-auth-session npm WARN 15 more (expo-asset, expo-camera, expo-constants, expo-contacts, ...) npm WARN npm WARN Could not resolve dependency: npm WARN peerOptional expo@"^49.0.16" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm WARN npm WARN Conflicting peer dependency: expo@49.0.23 npm WARN node_modules/expo npm WARN peerOptional expo@"^49.0.16" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @hashgraph/cryptography@1.4.8-beta.5 npm WARN Found: expo-crypto@13.0.2 npm WARN node_modules/expo-crypto npm WARN expo-crypto@"~13.0.0" from expo-auth-session@5.5.2 npm WARN node_modules/expo-auth-session npm WARN expo-auth-session@"~5.5.2" from the root project npm WARN 1 more (the root project) npm WARN npm WARN Could not resolve dependency: npm WARN peerOptional expo-crypto@"^10.1.2" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm WARN npm WARN Conflicting peer dependency: expo-crypto@10.2.0 npm WARN node_modules/expo-crypto npm WARN peerOptional expo-crypto@"^10.1.2" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @hashgraph/cryptography@1.4.8-beta.5 npm WARN Found: expo-random@14.0.1 npm WARN node_modules/expo-random npm WARN expo-random@"~14.0.1" from the root project npm WARN npm WARN Could not resolve dependency: npm WARN peerOptional expo-random@"^12.1.2" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm WARN npm WARN Conflicting peer dependency: expo-random@12.3.0 npm WARN node_modules/expo-random npm WARN peerOptional expo-random@"^12.1.2" from @hashgraph/cryptography@1.4.8-beta.5 npm WARN node_modules/@hashgraph/cryptography npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/sdk@2.47.0 npm WARN node_modules/@hashgraph/sdk npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @hashgraph/sdk@2.47.0 npm ERR! Found: expo@51.0.14 npm ERR! node_modules/expo npm ERR! peer expo@"" from expo-application@5.9.1 npm ERR! node_modules/expo-application npm ERR! expo-application@"~5.9.0" from expo-auth-session@5.5.2 npm ERR! node_modules/expo-auth-session npm ERR! expo-auth-session@"~5.5.2" from the root project npm ERR! peer expo@"*" from expo-asset@10.0.9 npm ERR! node_modules/expo-asset npm ERR! expo-asset@"~10.0.9" from expo@51.0.14 npm ERR! 14 more (expo-camera, expo-constants, expo-contacts, expo-crypto, ...) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional expo@"^49.0.16" from @hashgraph/sdk@2.47.0 npm ERR! node_modules/@hashgraph/sdk npm ERR! @hashgraph/sdk@"^2.47.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: expo@49.0.23 npm ERR! node_modules/expo npm ERR! peerOptional expo@"^49.0.16" from @hashgraph/sdk@2.47.0 npm ERR! node_modules/@hashgraph/sdk npm ERR! @hashgraph/sdk@"^2.47.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Hedera network

other

Version

v2.47.0

Operating system

Windows

ivaylonikolov7 commented 4 months ago

After some discussion with @rubixvi , we found out that bumping the expo version might not solve their issue. The following text and code is a followup from them.

Code snippets

import { AccountId, Client, TransferTransaction, Hbar } from '@hashgraph/sdk';

const client = Client.forTestnet().setOperator(
process.env.EXPO_PUBLIC_ACCOUNT_ID ?? '',
process.env.EXPO_PUBLIC_PRIVATE_KEY ?? ''
);

const confirmTransaction = async () => {
setModalVisible(false);
try {
const sanitizedRecipientId = sanitizeRecipientId(recipientId);
const sanitizedAmount = sanitizeAmount(amount);
const sanitizedMemo = sanitizeMemo(memo);
const hbarAmount = Number(sanitizedAmount);

  if (isNaN(hbarAmount) || hbarAmount <= 0) {
    setAlertType('error');
    setAlertMessage('Invalid amount. Please enter a valid number.');
    return;
  }

  if (sanitizedRecipientId === accountId) {
    setAlertType('error');
    setAlertMessage('Please check the payment address.');
    return;
  }

const transaction = await new TransferTransaction()
  .addHbarTransfer(accountId, Hbar.fromTinybars(-hbarAmount * 100000000))  // Convert HBAR to tinybars
  .addHbarTransfer(sanitizedRecipientId, Hbar.fromTinybars(hbarAmount * 100000000))
  .setTransactionMemo(sanitizedMemo)
  .execute(client);

const receipt = await transaction.getReceipt(client);
const status = receipt.status;

if (status.toString() === 'SUCCESS') {
  setAlertType('success');
  setAlertMessage('Sending Complete');
  setReceiptNumber(transaction.transactionId.toString());
  clearInputs();
} else {
  setAlertType('error');
  setAlertMessage('Sending Failed');
}
} catch (error) {
setAlertType('error');
setAlertMessage('Sending Failed');
console.error('Error during transaction:', error);
}
};

package.json:

"dependencies": {
"@ethersproject/shims": "^5.7.0",
"@expo/vector-icons": "^14.0.2",
"@hashgraph/sdk": "^2.26.0",
"@react-native-async-storage/async-storage": "^1.24.0",
"@react-native-picker/picker": "^2.7.7",
"@react-navigation/native": "^6.0.2",
"axios": "^1.7.2",
"expo": "~51.0.20",
"expo-camera": "^15.0.13",
"expo-clipboard": "~6.0.3",
"expo-crypto": "~13.0.2",
"expo-font": "~12.0.8",
"expo-local-authentication": "~14.0.1",
"expo-optimize": "^0.2.20",
"expo-print": "^13.0.1",
"expo-random": "^14.0.1",
"expo-router": "~3.5.18",
"expo-secure-store": "~13.0.2",
"expo-sharing": "^12.0.1",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"expo-web-browser": "~13.0.3",
"long": "^5.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-native": "^0.74.3",
"react-native-get-random-values": "^1.11.0",
"react-native-modal-datetime-picker": "^17.1.0",
"react-native-svg": "^15.4.0",
"react-native-web": "^0.19.12",
"react-qr-code": "^2.0.15"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "^18.3.3",
"@types/react-native": "^0.73.0",
"@types/react-test-renderer": "^18.0.7",
"eslint": "^9.7.0",
"eslint-config-expo": "^7.0.0",
"metro-minify-terser": "^0.80.9",
"postcss-loader": "^8.1.1",
"react-native-svg-transformer": "^1.4.0",
"react-test-renderer": "^18.3.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
},

Running a buffer:

import { Buffer } from "buffer";

globalThis.Buffer = Buffer;

Layout:

import "react-native-get-random-values"
import "./shims-buffer";
import '@ethersproject/shims';

Error

ERROR Error during transaction: [Error: Not a valid base64 encoded string length]

ivaylonikolov7 commented 4 months ago

Hello @rubixvi,

Can I please have the code for sanitizeRecipientId, sanitizeAmount and sanitizeMemo as the current ongoing theory in the team is that your problem might be because of the stuff that's happening inside sanitizeMemo.

rubixvi commented 4 months ago

const sanitizeRecipientId = (input: string): string => { return input.replace(/[^a-zA-Z0-9.]/g, ''); };

const sanitizeAmount = (input: string): string => { return input.replace(/[^0-9.]/g, ''); };

const sanitizeMemo = (input: string): string => { return input.replace(/[^a-zA-Z0-9\s-.]/g, ''); };

Just a simple script to prevent the wrong inputs.

ivaylonikolov7 commented 4 months ago

Hello, @rubixvi.

We managed to reproduce your issue on Android using Android Studio's emulator by following these steps.

  1. creating an expo project
  2. installing @hashgraph/sdk package
  3. adding the code snippet you provided in a useEffect()
  4. running the app in Android environment

In iOS this was working fine. As you said the web version does not have this problem neither. After some investigation we found out that altho expo shows an error with atob's base64 length but the transaction still passes and the transaction receipt shows status code: 22. Which means the transaction was successful. This can be confirmed from hashscan too - https://hashscan.io/testnet/transaction/1721299020.763775003.

or by running this code:

      const response = await new AccountCreateTransaction()
        .setKey(privateKey)
        .execute(client);

      const receipt = await response.getReceipt(client);
      console.log(receipt);

Thank you for your code snippets for the sanitisation methods you useI asked you for the sanitisation methods because I wanted to be sure that there isn't some base64 encoding that you were doing to the memo. I tested that but this wasn't the issue as I tried running the script without any sanitisation and it was still throwing an error in Android environment.

We also tried to deserialise and serialise it back. For two reasons:

const response = await new AccountCreateTransaction()
        .setKey(privateKey)
        .toBytes();

      Transaction.fromBytes(response).execute(client);

The following code didn't throw an error and correctly deserialised the transaction with expected data.

Our current theory is that there is some issue with expo's newest version so we will be making an issue in their repository.

Thank you for raising this issue. Will keep you updated if there's some response from expo.

Expo related issue that I have created: https://github.com/expo/expo/issues/30503

rubixvi commented 4 months ago

Thanks, glad that's all cleared up, Looks like we'll just to wait for their response.

Atleast it wasn't my coding.