11<template >
22 <div >
3- <Dropdown nobalance =" true" mode =' accounts' :externalAddress =" address"
4- @selected =" handleAccountSelectionFrom" />
5- <br >
3+ <AccountSelect label =" sign with following account" v-model =" account" :asKeyring =" true" />
64 <b-field label =" sign the following data" >
7- <b-input v-model =" input" @input =" isHexData()" ></b-input >
8- </b-field >
9- <b-field label =" password 🤫 magic spell" class =" password-wrapper" >
10- <b-input v-model =" password" type =" password" password-reveal >
11- </b-input >
5+ <b-input v-model =" input" />
126 </b-field >
7+ <PasswordInput v-model =" password" />
138
14- <b-button icon-left =" key" @click =" signData() "
9+ <b-button icon-left =" key" @click =" signData"
1510 :disabled =" !accountFrom" >Sign Message</b-button >
1611 <br >
1712 <br >
18- <DisabledInput label =" hex input data" :value =" inputDataCheck " />
13+ <DisabledInput label =" hex input data" :value =" isHexData " />
1914 <b-field label =" signature" >
2015 <b-input :value =" signature" expanded disabled />
2116 <b-button
@@ -33,12 +28,15 @@ import { KeyringPair } from '@polkadot/keyring/types';
3328import keyring from ' @polkadot/ui-keyring' ;
3429import { isHex , u8aToHex , hexToU8a , stringToU8a , u8aToString } from ' @polkadot/util' ;
3530import DisabledInput from ' @/components/shared/DisabledInput.vue' ;
36- import Dropdown from ' @/components/shared/Dropdown.vue' ;
31+ import AccountSelect from ' @/components/shared/AccountSelect.vue'
32+ import PasswordInput from ' @/components/shared/PasswordInput.vue' ;
33+ import { emptyObject } from ' @/utils/empty' ;
3734
3835@Component ({
3936 components: {
4037 DisabledInput ,
41- Dropdown ,
38+ AccountSelect ,
39+ PasswordInput
4240 }
4341})
4442export default class SignMessage extends Vue {
@@ -47,31 +45,31 @@ export default class SignMessage extends Vue {
4745 private input: string = ' ' ;
4846 private signature: any = ' ' ;
4947 private inputDataCheck: string = ' No' ;
50- private accountFrom : any = null ;
48+ private account : KeyringPair = emptyObject < KeyringPair >() ;
5149 private currentPair: any = null ;
5250
53- private isHexData(): void {
54- this .inputDataCheck = isHex (this .input )
55- ? ' Yes'
56- : ' No' ;
51+ get isHexData(): string {
52+ return String (isHex (this .input ))
53+ }
54+
55+ get accountFrom(): boolean {
56+ return !! this .account .address
5757 }
5858
5959 private signData(): void {
60- this .isHexData ();
61- this .accountFrom .decodePkcs8 (this .password )
60+ if (this .password ) {
61+ this .account .decodePkcs8 (this .password )
62+ }
63+
6264 this .signature = u8aToHex (
63- this .accountFrom .sign (
65+ this .account .sign (
6466 isHex (this .input )
6567 ? hexToU8a (this .input )
6668 : stringToU8a (this .input )
6769 )
6870 )
6971 }
7072
71- private handleAccountSelectionFrom(account : KeyringPair ) {
72- this .accountFrom = account ;
73- }
74-
7573 private toast(message : string ): void {
7674 this .$buefy .toast .open (message );
7775 }
0 commit comments