UNPKG

@qiushaoxi/hw-app-ont

Version:

Ledger Javascript API for ONT and NEO.

53 lines (52 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ontology_ts_sdk_1 = require("ontology-ts-sdk"); function splitPath(path) { var result = []; var components = path.split('/'); components.forEach(function (element) { var number = parseInt(element, 10); if (isNaN(number)) { throw Error("Path " + path + " is invalid."); } if (element.length > 1 && element[element.length - 1] === "'") { number += 0x80000000; } result.push(number); }); return result; } exports.splitPath = splitPath; function convertPathToBuffer(path) { var paths = splitPath(path); var buffer = Buffer.alloc(paths.length * 4); paths.forEach(function (element, index) { buffer.writeUInt32BE(element, 4 * index); }); return buffer; } exports.convertPathToBuffer = convertPathToBuffer; function convertDerToHex(response) { var ss = new ontology_ts_sdk_1.utils.StringReader(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 var r = ss.readNextBytes(); ss.read(1); var s = ss.readNextBytes(); // We will need to ensure both integers are 32 bytes long var integers = [r, s].map(function (i) { if (i.length < 64) { i = i.padStart(64, '0'); } if (i.length > 64) { i = i.substr(-64); } return i; }); return integers.join(''); } exports.convertDerToHex = convertDerToHex;