import { blake2bFinal , blake2bInit , blake2bUpdate } from 'blakejs' ; import Ed25519 from './ed25519' ; import Convert from './util/convert' ; export default class Signer { ed25519 = new Ed25519 ( ) ; param privateKey param data sign ( privateKey , ... data ) { const signature = this . ed25519 . sign ( this . generateHash ( data ) , Convert . hex2ab ( privateKey ) ) ; return Convert . ab2hex ( signature ) ; } param publicKey param signature param data verify ( publicKey , signature , ... data ) { return this . ed25519 . verify ( this . generateHash ( data ) , Convert . hex2ab ( publicKey ) , Convert . hex2ab ( signature ) ) ; } param data generateHash ( data ) { const ctx = blake2bInit ( 32 , undefined ) ; data . forEach ( str => blake2bUpdate ( ctx , Convert . hex2ab ( str ) ) ) ; return blake2bFinal ( ctx ) ; } }