2021-06-23 11:28:00 +03:00
|
|
|
import { b64uEnc } from "./b64";
|
2021-06-29 11:54:51 +03:00
|
|
|
import { cryptoUtils, PrivateKey } from '@hiveio/dhive';
|
2021-06-23 11:28:00 +03:00
|
|
|
|
|
|
|
export interface HiveSignerMessage {
|
|
|
|
signed_message: {
|
|
|
|
type: string;
|
|
|
|
app: string;
|
|
|
|
},
|
|
|
|
authors: string[];
|
|
|
|
timestamp: number;
|
|
|
|
signatures?: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-29 11:54:51 +03:00
|
|
|
export const makeHsCode = async (account: string, privateKey:PrivateKey): Promise<string> => {
|
2021-06-23 11:28:00 +03:00
|
|
|
const timestamp = new Date().getTime() / 1000;
|
|
|
|
const messageObj: HiveSignerMessage = {signed_message: {type: 'code', app: "ecency.app"}, authors: [account], timestamp};
|
|
|
|
const message = JSON.stringify(messageObj);
|
2021-06-29 11:54:51 +03:00
|
|
|
const signature = signer(message, privateKey);
|
2021-06-23 11:28:00 +03:00
|
|
|
messageObj.signatures = [signature];
|
|
|
|
return b64uEnc(JSON.stringify(messageObj));
|
|
|
|
}
|
2021-06-29 11:54:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2021-06-29 15:24:20 +03:00
|
|
|
}
|