@zondax/ledger-icp
Version:
Node API for the Internet Computer App (Ledger Nano S/X/S+/Stax/Flex)
71 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processGetAddrResponse = processGetAddrResponse;
exports.processTokenRegistrySizeResponse = processTokenRegistrySizeResponse;
exports.processTokenInfoResponse = processTokenInfoResponse;
const ledger_js_1 = require("@zondax/ledger-js");
const consts_1 = require("./consts");
function processGetAddrResponse(response) {
const errorCodeData = response.subarray(-2);
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
const publicKey = Buffer.from(response.subarray(0, consts_1.PKLEN));
response = response.subarray(consts_1.PKLEN);
const principal = Buffer.from(response.subarray(0, consts_1.PRINCIPAL_LEN));
response = response.subarray(consts_1.PRINCIPAL_LEN);
const address = Buffer.from(response.subarray(0, consts_1.ADDRLEN));
response = response.subarray(consts_1.ADDRLEN);
const principalText = Buffer.from(response.subarray(0, -2))
.toString()
.replace(/(.{5})/g, "$1-");
return {
publicKey,
principal,
address,
principalText,
returnCode,
errorMessage: (0, ledger_js_1.errorCodeToString)(returnCode),
};
}
function processTokenRegistrySizeResponse(response) {
const errorCodeData = response.subarray(-2);
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
let errorMessage = (0, ledger_js_1.errorCodeToString)(returnCode);
let RegistrySize = response[0];
return {
RegistrySize,
returnCode,
errorMessage,
};
}
function processTokenInfoResponse(response) {
const errorCodeData = response.subarray(-2);
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
let offset = 0;
// Read canister ID
const canisterIdLength = response[offset];
offset += 1;
const canisterId = response
.slice(offset, offset + canisterIdLength)
.toString("utf8");
offset += canisterIdLength;
// Read token symbol
const symbolLength = response[offset];
offset += 1;
const tokenSymbol = response
.slice(offset, offset + symbolLength)
.toString("utf8");
offset += symbolLength;
// Read decimals (uint8)
const decimals = response[offset];
let tokenInfo = {
canisterId,
tokenSymbol,
decimals,
};
return {
tokenInfo,
returnCode,
errorMessage: (0, ledger_js_1.errorCodeToString)(returnCode),
};
}
//# sourceMappingURL=helper.js.map