1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.encodePair = void 0;
|
4 | const util_1 = require("@polkadot/util");
|
5 | const util_crypto_1 = require("@polkadot/util-crypto");
|
6 | const defaults_js_1 = require("./defaults.js");
|
7 | function encodePair({ publicKey, secretKey }, passphrase) {
|
8 | if (!secretKey) {
|
9 | throw new Error('Expected a valid secretKey to be passed to encode');
|
10 | }
|
11 | const encoded = (0, util_1.u8aConcat)(defaults_js_1.PKCS8_HEADER, secretKey, defaults_js_1.PKCS8_DIVIDER, publicKey);
|
12 | if (!passphrase) {
|
13 | return encoded;
|
14 | }
|
15 | const { params, password, salt } = (0, util_crypto_1.scryptEncode)(passphrase);
|
16 | const { encrypted, nonce } = (0, util_crypto_1.naclEncrypt)(encoded, password.subarray(0, 32));
|
17 | return (0, util_1.u8aConcat)((0, util_crypto_1.scryptToU8a)(salt, params), nonce, encrypted);
|
18 | }
|
19 | exports.encodePair = encodePair;
|