ecency-mobile/src/utils/hive-signer-helper.ts
2021-06-29 17:24:20 +05:00

32 lines
984 B
TypeScript

import { b64uEnc } from "./b64";
import { cryptoUtils, PrivateKey } from '@hiveio/dhive';
export interface HiveSignerMessage {
signed_message: {
type: string;
app: string;
},
authors: string[];
timestamp: number;
signatures?: string[];
}
export const makeHsCode = async (account: string, privateKey:PrivateKey): Promise<string> => {
const timestamp = new Date().getTime() / 1000;
const messageObj: HiveSignerMessage = {signed_message: {type: 'code', app: "ecency.app"}, authors: [account], timestamp};
const message = JSON.stringify(messageObj);
const signature = signer(message, privateKey);
messageObj.signatures = [signature];
return b64uEnc(JSON.stringify(messageObj));
}
export const signer = (message:any, privateKey:PrivateKey) => {
const hash = cryptoUtils.sha256(message);
const key = privateKey;
const signedKey = key.sign(hash);
const signedStr = signedKey.toString();
return signedStr
}