mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-07 20:53:54 -05:00
Signed-off-by: KiruthikaJeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com>
24 lines
648 B
TypeScript
24 lines
648 B
TypeScript
import asn1 from 'asn1.js';
|
|
import {Buffer} from 'buffer';
|
|
|
|
const convertDerToRsFormat = derSignature => {
|
|
const ASN1Integer = asn1.define('ASN1Integer', function () {
|
|
this.int();
|
|
});
|
|
|
|
const ASN1Sequence = asn1.define('ASN1Sequence', function () {
|
|
this.seq().obj(this.key('r').int(), this.key('s').int());
|
|
});
|
|
|
|
const derBuffer = Buffer.from(derSignature);
|
|
const seq = ASN1Sequence.decode(derBuffer, 'der');
|
|
const r = seq.r.toArrayLike(Buffer, 'be', 32);
|
|
const s = seq.s.toArrayLike(Buffer, 'be', 32);
|
|
|
|
const rsBuffer = Buffer.concat([r, s]);
|
|
|
|
return rsBuffer.toString('base64');
|
|
};
|
|
|
|
export default convertDerToRsFormat;
|