From 3dc8376bab8320320e4f34ebf297aec04ac79969 Mon Sep 17 00:00:00 2001 From: Zouheir Layine <58786497+zlayine@users.noreply.github.com> Date: Tue, 5 Sep 2023 12:47:45 +0300 Subject: [PATCH] add error for signing transaction with different address (#31) --- resources/js/shims-vue.d.ts | 3 ++- resources/js/store/index.ts | 11 ++++++++--- resources/js/store/transaction.ts | 24 ++++++++++++++++++++---- resources/js/types/types.interface.ts | 1 + resources/views/app.blade.php | 2 +- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/resources/js/shims-vue.d.ts b/resources/js/shims-vue.d.ts index 3916f47..f64a56d 100644 --- a/resources/js/shims-vue.d.ts +++ b/resources/js/shims-vue.d.ts @@ -7,6 +7,7 @@ declare module '*.vue' { interface Window { bootstrap: { - hostname: string; + url: string; + daemon: string; }; } diff --git a/resources/js/store/index.ts b/resources/js/store/index.ts index 0d28691..e8873ed 100644 --- a/resources/js/store/index.ts +++ b/resources/js/store/index.ts @@ -29,6 +29,7 @@ export const useAppStore = defineStore('app', { tenant: false, webSocket: '', channel: '', + daemon: '', }, navigations: [ { name: 'Collections', to: { name: 'platform.collections' }, pos: 1 }, @@ -77,7 +78,7 @@ export const useAppStore = defineStore('app', { if (this.hasMarketplacePackage) this.addMarketplaceNavigation(); this.loggedIn = true; - if (this.isMultiTenant && this.loggedIn) await this.getUser(); + if (this.loggedIn) await this.getUser(); return await this.fetchCollectionIds(); } catch (error: any) { @@ -101,8 +102,8 @@ export const useAppStore = defineStore('app', { if (appConfig?.url) { this.config.url = parseConfigURL(appConfig.url); - } else if (window?.bootstrap?.hostname) { - this.config.url = parseConfigURL(window.location.origin); + } else if (window?.bootstrap?.url) { + this.config.url = parseConfigURL(window?.bootstrap?.url); } else { this.config.url = this.url; } @@ -119,6 +120,10 @@ export const useAppStore = defineStore('app', { if (appConfig.channel.length) { this.config.channel = appConfig.channel; } + + if (window.bootstrap.daemon) { + this.config.daemon = window.bootstrap.daemon; + } }, async checkURL(url: URL) { try { diff --git a/resources/js/store/transaction.ts b/resources/js/store/transaction.ts index 5c891ae..f8cbf43 100644 --- a/resources/js/store/transaction.ts +++ b/resources/js/store/transaction.ts @@ -8,6 +8,7 @@ import snackbar from '~/util/snackbar'; import { SignerPayloadJSON } from '@polkadot/types/types'; import { markRaw } from 'vue'; import { AccountInfoWithTripleRefCount } from '@polkadot/types/interfaces'; +import { publicKeyToAddress } from '~/util/address'; const RPC_URLS = { canary: 'wss://rpc.matrix.canary.enjin.io', @@ -79,22 +80,37 @@ export const useTransactionStore = defineStore('transaction', { return paymentInfo.partialFee.toHuman(); }, async signTransaction(transaction: any) { + const appStore = useAppStore(); + if (appStore.user?.account || appStore.config.daemon) { + if ( + publicKeyToAddress(appStore.account.address) !== + publicKeyToAddress(appStore.user?.account ?? appStore.config.daemon) + ) { + snackbar.error({ + title: 'Sign Transaction', + text: 'Signing account must be the same as wallet daemon account', + }); + + return; + } + } + const { extrinsic, payloadToSign, currentBlock } = await this.getExtrinsicData( transaction, - useAppStore().account.address, + appStore.account.address, this.api ); - const { signature } = await useAppStore().account.signer.signPayload(payloadToSign); + const { signature } = await appStore.account.signer.signPayload(payloadToSign); - extrinsic.addSignature(useAppStore().account.address, signature, payloadToSign); + extrinsic.addSignature(appStore.account.address, signature, payloadToSign); const transactionHash = await this.api.rpc.author.submitExtrinsic(extrinsic.toHex()); return await this.updateTransaction({ id: transaction.id, transactionHash: transactionHash.toHex(), - signingAccount: useAppStore().account.address, + signingAccount: appStore.account.address, signedAtBlock: currentBlock.block.header.number.toNumber(), }); }, diff --git a/resources/js/types/types.interface.ts b/resources/js/types/types.interface.ts index 38ea4a8..b200f95 100644 --- a/resources/js/types/types.interface.ts +++ b/resources/js/types/types.interface.ts @@ -13,6 +13,7 @@ export interface AppState { tenant: boolean; webSocket: string; channel: string; + daemon: string; }; navigations: any[]; collections: string[]; diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php index 27a3cdd..7da682a 100644 --- a/resources/views/app.blade.php +++ b/resources/views/app.blade.php @@ -14,7 +14,7 @@ @vite('resources/js/app.ts', 'vendor/platform-ui/build')