@@ -23,6 +23,7 @@ import { HiveChainModule } from '../../repositories/hive-chain/hive-chain.module
23
23
import { EmailModule } from '../email/email.module' ;
24
24
import * as crypto from 'crypto' ;
25
25
import { HiveModule } from '../hive/hive.module' ;
26
+ import { PrivateKey } from '@hiveio/dhive' ;
26
27
27
28
describe ( 'ApiController' , ( ) => {
28
29
let app : INestApplication ;
@@ -138,7 +139,16 @@ describe('ApiController', () => {
138
139
describe ( '/POST /v1/hive/linkaccount' , ( ) => {
139
140
it ( 'should link a Hive account' , async ( ) => {
140
141
const jwtToken = 'test_jwt_token' ;
141
- const body = { username : 'test-account' } ;
142
+
143
+ const privateKey = PrivateKey . fromSeed ( crypto . randomBytes ( 32 ) . toString ( "hex" ) ) ;
144
+ const publicKey = privateKey . createPublic ( ) ;
145
+ const publicKeyString = publicKey . toString ( ) ;
146
+ const message = "singleton/bob/did is the owner of @starkerz" ;
147
+ const signature = privateKey . sign ( crypto . createHash ( 'sha256' ) . update ( message ) . digest ( ) ) ;
148
+
149
+ const body = { username : 'starkerz' , proof : signature . toString ( ) } ;
150
+
151
+ process . env . TEST_PUBLIC_KEY = publicKeyString ;
142
152
143
153
return request ( app . getHttpServer ( ) )
144
154
. post ( '/v1/hive/linkaccount' )
@@ -147,7 +157,12 @@ describe('ApiController', () => {
147
157
. expect ( 201 )
148
158
. then ( response => {
149
159
expect ( response . body ) . toEqual ( {
150
- challenge : expect . any ( String ) ,
160
+ __v : 0 ,
161
+ _id : expect . any ( String ) ,
162
+ account : "starkerz" ,
163
+ network : "HIVE" ,
164
+ status : "verified" ,
165
+ user_id : "singleton/bob/did" ,
151
166
} ) ;
152
167
} ) ;
153
168
} ) ;
@@ -165,8 +180,9 @@ describe('ApiController', () => {
165
180
expect ( response . body ) . toEqual ( {
166
181
id : "test_user_id" ,
167
182
network : "did" ,
168
- sub : "test_user_id" ,
169
- username : "test" ,
183
+ sub : "singleton/bob/did" ,
184
+ type : "singleton" ,
185
+ username : "test_user_id" ,
170
186
} ) ;
171
187
} ) ;
172
188
} ) ;
@@ -177,7 +193,7 @@ describe('ApiController', () => {
177
193
const jwtToken = 'test_jwt_token' ;
178
194
179
195
// Mock linking and verifying an account
180
- const link = await linkedAccountsRepository . linkHiveAccount ( 'singleton/bob/did' , 'test-account' , 'challenge' ) ;
196
+ const link = await linkedAccountsRepository . linkHiveAccount ( 'singleton/bob/did' , 'test-account' ) ;
181
197
await linkedAccountsRepository . verify ( link . _id ) ;
182
198
183
199
return request ( app . getHttpServer ( ) )
0 commit comments