Skip to content

Commit

Permalink
pr: fix verify linked account endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Graney-Ward committed May 15, 2024
1 parent 9b0d8b8 commit 6088ef8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/repositories/hive/hive.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ export class HiveRepository {
return await this.#hive.database.call('get_active_votes', [author, permlink]);
}

async decodeMessageAndGetPublicKeys(memo: string) {
decodeMessage(memo: string) {
const decoded: string = this.#hiveJs.memo.decode(process.env.DELEGATED_ACCOUNT_POSTING, memo);
const message: string = JSON.parse(decoded.substr(1));
const message: unknown = JSON.parse(decoded.substr(1));

return message;
}
Expand Down
58 changes: 30 additions & 28 deletions src/services/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,42 +208,44 @@ export class ApiController {
const { memo } = data;
console.log(memo);

// TODO: this function does not get the message, it gets the public keys
const message = await this.hiveRepository.getPublicKeys(memo);
throw new Error('Not implemented');
// const pubKeys = await this.hiveRepository.getPublicKeys(memo);
const message = this.hiveRepository.decodeMessage(memo) as {
account: string;
authority: string;
message: string;
};
const pubKeys = await this.hiveRepository.getPublicKeys(memo);

// const [account] = await HiveClient.database.getAccounts([message.account]);
const account = await this.hiveRepository.getAccount(message.account);

// if (!account) {
// throw new HttpException({ reason: 'Account not found' }, HttpStatus.BAD_REQUEST);
// }
// console.log(account[message.authority], pubKeys);
if (!account) {
throw new HttpException({ reason: 'Account not found' }, HttpStatus.BAD_REQUEST);
}
console.log(account[message.authority], pubKeys);

// // Check if the signature is not valid
// const signatureValid = account[message.authority].key_auths.some(
// (key_auth) => key_auth[0] === pubKeys[0],
// );
// if (!signatureValid) {
// throw new HttpException({ reason: 'Incorrect signature' }, HttpStatus.BAD_REQUEST);
// }
// Check if the signature is not valid
const signatureValid = account[message.authority].key_auths.some(
(key_auth) => key_auth[0] === pubKeys[0],
);
if (!signatureValid) {
throw new HttpException({ reason: 'Incorrect signature' }, HttpStatus.BAD_REQUEST);
}

// const identityChallenge = await this.linkedAccountsRepository.findOneByChallenge({
// challenge: message.message,
// });
const identityChallenge = await this.linkedAccountsRepository.findOneByChallenge({
challenge: message.message,
});

// if (!identityChallenge) {
// throw new HttpException({ reason: 'Challenge not found' }, HttpStatus.BAD_REQUEST);
// }
if (!identityChallenge) {
throw new HttpException({ reason: 'Challenge not found' }, HttpStatus.BAD_REQUEST);
}

// console.log(signatureValid, account, message.message, identityChallenge);
console.log(signatureValid, account, message.message, identityChallenge);

// if (identityChallenge.account !== account.name) {
// throw new HttpException({ reason: 'Incorrect signing account' }, HttpStatus.BAD_REQUEST);
// }
if (identityChallenge.account !== account.name) {
throw new HttpException({ reason: 'Incorrect signing account' }, HttpStatus.BAD_REQUEST);
}

// await this.linkedAccountsRepository.verify(identityChallenge._id);
// return { ok: true };
await this.linkedAccountsRepository.verify(identityChallenge._id);
return { ok: true };
}

@ApiOperation({
Expand Down

0 comments on commit 6088ef8

Please sign in to comment.