UNPKG

@airgap/aeternity

Version:

The @airgap/aeternity is an Aeternity implementation of the ICoinProtocol interface from @airgap/coinlib-core.

33 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertPublicKey = exports.aePublicKey = void 0; var coinlib_core_1 = require("@airgap/coinlib-core"); var errors_1 = require("@airgap/coinlib-core/errors"); var hex_1 = require("@airgap/coinlib-core/utils/hex"); var module_kit_1 = require("@airgap/module-kit"); var convert_1 = require("./convert"); var PK_PREFIX = 'ak_'; function aePublicKey(publicKey) { var format = (0, hex_1.isHex)(publicKey) ? 'hex' : publicKey.startsWith(PK_PREFIX) ? 'encoded' : undefined; if (format === undefined) { throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Invalid public key.'); } return (0, module_kit_1.newPublicKey)(publicKey, format); } exports.aePublicKey = aePublicKey; function convertPublicKey(publicKey, targetFormat) { if (publicKey.format === targetFormat) { return publicKey; } switch (publicKey.format) { case 'encoded': return (0, module_kit_1.newPublicKey)((0, convert_1.convertEncodedBytesString)(PK_PREFIX, publicKey.value, targetFormat), targetFormat); case 'hex': return (0, module_kit_1.newPublicKey)((0, convert_1.convertHexBytesString)(PK_PREFIX, publicKey.value, targetFormat), targetFormat); default: (0, coinlib_core_1.assertNever)(publicKey.format); throw new errors_1.UnsupportedError(coinlib_core_1.Domain.AETERNITY, 'Unsupported public key format.'); } } exports.convertPublicKey = convertPublicKey; //# sourceMappingURL=key.js.map