UNPKG

@cityofzion/neon-ledger

Version:

Neon Ledger integration for Node.js

33 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DerToHexSignature = DerToHexSignature; const neon_core_1 = require("@cityofzion/neon-core"); /** * Converts a signature in DER format to HEX format. * @param response - signature in DER format * @returns Signature in HEX format (64 bytes) */ function DerToHexSignature(response) { const ss = new neon_core_1.u.StringStream(response); // The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET) // The second byte represents the total length of the DER module. ss.read(2); // Now we read each field off // Each field is encoded with a type byte, length byte followed by the data itself ss.read(1); // Read and drop the type const r = ss.readVarBytes(); ss.read(1); const s = ss.readVarBytes(); // We will need to ensure both integers are 32 bytes long const integers = [r, s].map((i) => { if (i.length < 64) { i = "0".repeat(i.length - 64) + i; } if (i.length > 64) { i = i.substr(-64); } return i; }); return integers.join(""); } //# sourceMappingURL=utils.js.map