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 {
131
131
public signCosignatureTransaction ( cosignatureTransaction : CosignatureTransaction ) : CosignatureSignedTransaction {
132
132
return cosignatureTransaction . signWith ( this ) ;
133
133
}
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
+ }
134
145
}
Original file line number Diff line number Diff line change 17
17
import { expect } from 'chai' ;
18
18
import { Account } from '../../../src/model/account/Account' ;
19
19
import { NetworkType } from '../../../src/model/blockchain/NetworkType' ;
20
+ import { PublicAccount } from '../../../src/model/model' ;
20
21
21
22
describe ( 'Account' , ( ) => {
22
23
const accountInformation = {
@@ -45,4 +46,14 @@ describe('Account', () => {
45
46
expect ( account . address ) . to . not . be . equal ( undefined ) ;
46
47
} ) ;
47
48
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
+ } ) ;
48
59
} ) ;
You can’t perform that action at this time.
0 commit comments