diff --git a/package.json b/package.json index f46079374..93af07c66 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "axios": "^0.21.1", "browserify-zlib": "~0.1.4", "buffer": "^6.0.3", + "bytebuffer": "^5.0.1", "console-browserify": "^1.1.0", "constants-browserify": "^1.0.0", "core-js": "3.6.4", diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index 35da1e7b3..3e9414c3d 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -2,8 +2,10 @@ // import '../../../shim'; // import * as bitcoin from 'bitcoinjs-lib'; -import { Client, cryptoUtils, utils } from '@hiveio/dhive'; +import { Client, cryptoUtils, utils, Types, Transaction } from '@hiveio/dhive'; import { PrivateKey } from '@esteemapp/dhive'; +import bytebuffer from 'bytebuffer'; +import { createHash } from 'react-native-crypto'; import { Client as hsClient } from 'hivesigner'; import Config from 'react-native-config'; @@ -55,6 +57,22 @@ export const checkClient = async () => { checkClient(); +const sha256 = (input: Buffer | string): Buffer => { + return createHash('sha256').update(input).digest(); +}; + +export const generateTrxId = (transaction) => { + const buffer = new bytebuffer(bytebuffer.DEFAULT_CAPACITY, bytebuffer.LITTLE_ENDIAN); + try { + Types.Transaction(buffer, transaction); + } catch (cause) { + console.warn('SerializationError', cause); + } + buffer.flip(); + const transactionData = Buffer.from(buffer.toBuffer()); + return sha256(transactionData).toString('hex').slice(0, 40); //CryptoJS.enc.Hex +}; + export const getDigitPinCode = (pin) => decryptKey(pin, Config.PIN_KEY); export const getDynamicGlobalProperties = () => client.database.getDynamicGlobalProperties(); @@ -665,7 +683,7 @@ export const vote = async (account, pin, author, permlink, weight) => { console.log('Returning vote response'); return resp; } catch (err) { - console.warn('Failed to complete vote'); + console.warn('Failed to complete vote', err); } }; @@ -712,7 +730,14 @@ const _vote = (currentAccount, pin, author, permlink, weight) => { client.broadcast .sendOperations(args, privateKey) .then((result) => { - Alert.alert('dhive transaction id: ' + JSON.stringify(result)); + console.log(result); + console.log(generateTrxId(result.tx)); + Alert.alert( + 'dhive transaction id: ' + + JSON.stringify(result) + + 'localGen:' + + generateTrxId(result.tx), + ); resolve(result); }) .catch((err) => { diff --git a/yarn.lock b/yarn.lock index b6e3a9332..e4cb6a6e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1173,7 +1173,7 @@ "@hiveio/dhive@ecency/dhive-test": version "1.0.1" - resolved "https://codeload.github.com/ecency/dhive-test/tar.gz/8ecafed50308c562a40300cc081c96fa59c4e38a" + resolved "https://codeload.github.com/ecency/dhive-test/tar.gz/7bcf3d51ed889d47e2a0ed747debc37099c03c6b" dependencies: bs58 "^4.0.1" bytebuffer "^5.0.1"