Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Commit e36f146

Browse files
committed
use toBytes methods of query payloads
1 parent 06b5cd7 commit e36f146

File tree

3 files changed

+18
-35
lines changed

3 files changed

+18
-35
lines changed

src/examples/typescript/dapp/main.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Timestamp,
1212
LedgerId,
1313
PublicKey,
14+
AccountInfo,
1415
} from '@hashgraph/sdk'
1516
import { proto } from '@hashgraph/proto'
1617
import {
@@ -167,7 +168,14 @@ async function hedera_signAndExecuteQuery(_: Event) {
167168
query: queryToBase64String(query),
168169
}
169170

170-
return await dAppConnector!.signAndExecuteQuery(params)
171+
/*
172+
* We expect the response to be the bytes of the AccountInfo protobuf
173+
*/
174+
const { response } = await dAppConnector!.signAndExecuteQuery(params)
175+
const bytes = Buffer.from(response, 'base64')
176+
const accountInfo = AccountInfo.fromBytes(bytes)
177+
console.log(accountInfo)
178+
return accountInfo
171179
}
172180

173181
document.getElementById('hedera_signAndExecuteQuery')!.onsubmit = (e: SubmitEvent) =>

src/lib/wallet/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,22 @@ export default class Wallet extends Web3Wallet implements HederaNativeWallet {
324324
body: Query<any>,
325325
signer: HederaWallet,
326326
): Promise<void> {
327-
const queryResult = await body.executeWithSigner(signer)
327+
/*
328+
* Can be used with return values the have a toBytes method implemented
329+
* For example:
330+
* https://github.com/hashgraph/hedera-sdk-js/blob/c4438cbaa38074d8bfc934dba84e3b430344ed89/src/account/AccountInfo.js#L402
331+
*/
332+
const queryResult = (await body.executeWithSigner(signer)) as { toBytes: () => Uint8Array }
328333
const queryResponse = Uint8ArrayToBase64String(queryResult.toBytes())
329334

330335
const response: SignAndExecuteQueryResponse = {
331336
topic,
332337
response: {
333338
jsonrpc: '2.0',
334339
id,
335-
result: { response: queryResponse },
340+
result: {
341+
response: queryResponse,
342+
},
336343
},
337344
}
338345

test/utils.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,6 @@ describe(base64StringToTransaction.name, () => {
9797
})
9898
})
9999

100-
// TODO: remake it after fixes
101-
// describe('SignatureMap helpers', () => {
102-
// let base64SignatureMap: string
103-
104-
// describe(signatureMapToBase64.name, () => {
105-
// it('should encode SignatureMap to base64 string', async() => {
106-
// const txn = prepareTestTransaction(new TopicCreateTransaction(), {freeze: true})
107-
// const wallet = await Wallet.create(projectId, walletMetadata)
108-
// const hederaWallet = wallet!.getHederaWallet(
109-
// HederaChainId.Testnet,
110-
// testUserAccountId,
111-
// testPrivateKeyECDSA,
112-
// )
113-
114-
// const signedTxn = await hederaWallet.signTransaction(txn)
115-
// const signatureMap = signedTxn.getSignatures()
116-
// base64SignatureMap = signatureMapToBase64(signatureMap)
117-
118-
// expect(typeof base64SignatureMap).toBe('string')
119-
// expect(base64SignatureMap).toBe('eyIwLjAuMyI6eyIzMDJkMzAwNzA2MDUyYjgxMDQwMDBhMDMyMjAwMDI3ODI3OWRmMjFhZTNjZDMwNjEwNjI3YjFlNDIzZWJiNzQwNWM1NGI4MDM5YWY1NTJjNGI0NThmYjYzYWE4ZDMzIjp7IjAiOjE0MywiMSI6MjUxLCIyIjoyNCwiMyI6MTQwLCI0IjoyNTEsIjUiOjEwNywiNiI6MTQsIjciOjY3LCI4Ijo5MiwiOSI6MTI0LCIxMCI6MTM1LCIxMSI6NjMsIjEyIjoxMDksIjEzIjoyNCwiMTQiOjEsIjE1IjowLCIxNiI6MTgsIjE3IjoyMjQsIjE4IjoyMiwiMTkiOjI4LCIyMCI6MzcsIjIxIjo4MywiMjIiOjI5LCIyMyI6MTkxLCIyNCI6MjEzLCIyNSI6MTc2LCIyNiI6MjA4LCIyNyI6MTcwLCIyOCI6MTIsIjI5IjoxMzMsIjMwIjoyMjcsIjMxIjo3NiwiMzIiOjE3NywiMzMiOjEzNSwiMzQiOjIwLCIzNSI6NzksIjM2IjoxODYsIjM3IjoxNTAsIjM4IjoxLCIzOSI6MjEzLCI0MCI6ODQsIjQxIjoxMTMsIjQyIjoyNTMsIjQzIjo1OCwiNDQiOjI0OSwiNDUiOjE4MCwiNDYiOjIxNSwiNDciOjg1LCI0OCI6MTg4LCI0OSI6MTU3LCI1MCI6MTk5LCI1MSI6MjIwLCI1MiI6MTM1LCI1MyI6MjMxLCI1NCI6MjEzLCI1NSI6MTA4LCI1NiI6MTg0LCI1NyI6MjM5LCI1OCI6MTUyLCI1OSI6MjM2LCI2MCI6MTI1LCI2MSI6MjI2LCI2MiI6MjQ2LCI2MyI6MjUyfX19')
120-
// })
121-
// })
122-
123-
// describe(base64StringToSignatureMap.name, () => {
124-
// it('should decode base64 string to SignatureMap', async() => {
125-
// const signatureMap = base64StringToSignatureMap(base64SignatureMap)
126-
// console.log(JSON.stringify(signatureMap, null, 2))
127-
// expect(signatureMap).toBe(???)
128-
// })
129-
// })
130-
// })
131-
132100
describe(`Uint8Array helpers`, () => {
133101
let uInt8Array: Uint8Array
134102

0 commit comments

Comments
 (0)