const tweetnacl=require('tweetnacl') import {CurveTypeStr} from './type' export class PublicKey{ CurveType:string=CurveTypeStr.Ed25519 PublicKey:string constructor(publicKey:string){ console.log('publicKey.length',publicKey.length) if (publicKey.length !== 64) throw new Error('bad publicKey key size'); this.PublicKey=publicKey } setCurveType(curveType){ this.CurveType=curveType } verify(msg:Buffer,signData:Uint8Array){ switch (this.CurveType){ case CurveTypeStr.Ed25519: let msgArray=Uint8Array.from(msg) return tweetnacl.sign.detached.verify(msgArray, signData, Buffer.from(this.PublicKey,'hex')) case CurveTypeStr.Secp256k1: throw new Error('CurveType Secp256k1 is not implemented') default: throw new Error('invalid curve type') } } }