File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -131,4 +131,15 @@ export class Account {
131131 public signCosignatureTransaction ( cosignatureTransaction : CosignatureTransaction ) : CosignatureSignedTransaction {
132132 return cosignatureTransaction . signWith ( this ) ;
133133 }
134+
135+ /**
136+ * Sign raw data
137+ * @param data - Data to be signed
138+ * @return {string } - Signed data result
139+ */
140+ public signData ( data : string ) : string {
141+ return convert . uint8ToHex ( KeyPair . sign ( this . keyPair ,
142+ convert . hexToUint8 ( convert . utf8ToHex ( data ) ) ,
143+ ) ) ;
144+ }
134145}
Original file line number Diff line number Diff line change 1717import { expect } from 'chai' ;
1818import { Account } from '../../../src/model/account/Account' ;
1919import { NetworkType } from '../../../src/model/blockchain/NetworkType' ;
20+ import { PublicAccount } from '../../../src/model/model' ;
2021
2122describe ( 'Account' , ( ) => {
2223 const accountInformation = {
@@ -45,4 +46,14 @@ describe('Account', () => {
4546 expect ( account . address ) . to . not . be . equal ( undefined ) ;
4647 } ) ;
4748
49+ it ( 'signData' , ( ) => {
50+ const account = Account . createFromPrivateKey (
51+ 'AB860ED1FE7C91C02F79C02225DAC708D7BD13369877C1F59E678CC587658C47' ,
52+ NetworkType . MIJIN_TEST ,
53+ ) ;
54+ const publicAccount = account . publicAccount ;
55+ const signed = account . signData ( 'catapult rocks!' ) ;
56+ expect ( publicAccount . verifySignature ( 'catapult rocks!' , signed ) )
57+ . to . be . equal ( true ) ;
58+ } ) ;
4859} ) ;
You can’t perform that action at this time.
0 commit comments