import asn1 from 'asn1.js' ; import BN from 'bn.js' ; const EcdsaDerSignature = asn1 . define ( 'ECPrivateKey' , function ( ) { return this . seq ( ) . obj ( this . key ( 'r' ) . int ( ) , this . key ( 's' ) . int ( ) ) ; } ) ; param buffer export function nodeSignatureToWebSignature ( buffer ) { const rsSig = EcdsaDerSignature . decode ( buffer , 'der' ) ; return Buffer . concat ( [ rsSig . r . toArrayLike ( Buffer , 'be' , 32 ) , rsSig . s . toArrayLike ( Buffer , 'be' , 32 ) , ] ) ; } param buffer export function webSignatureToNodeSignature ( buffer ) { const r = new BN ( buffer . slice ( 0 , 32 ) . toString ( 'hex' ) , 16 , 'be' ) ; const s = new BN ( buffer . slice ( 32 ) . toString ( 'hex' ) , 16 , 'be' ) ; return EcdsaDerSignature . encode ( { r , s } , 'der' ) ; }