UNPKG

@plugnet/keyring

Version:
34 lines (27 loc) 961 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = encode; var _util = require("@plugnet/util"); var _utilCrypto = require("@plugnet/util-crypto"); var _defaults = require("./defaults"); // Copyright 2017-2019 @polkadot/keyring authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. function encode(_ref, passphrase) { let { publicKey, secretKey } = _ref; (0, _util.assert)(secretKey, 'Expected a valid secretKey to be passed to encode'); const encoded = (0, _util.u8aConcat)(_defaults.PKCS8_HEADER, secretKey, _defaults.PKCS8_DIVIDER, publicKey); if (!passphrase) { return encoded; } const { encrypted, nonce } = (0, _utilCrypto.naclEncrypt)(encoded, (0, _util.u8aFixLength)((0, _util.stringToU8a)(passphrase), 256, true)); return (0, _util.u8aConcat)(nonce, encrypted); }