"use strict";
/*
 *
 * Copyright 2018-present NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountService = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const derivation_service_1 = require("./derivation.service");
/**
 * Account service
 */
class AccountService {
    /**
     * Gets the address given a raw address.
     * @param {string} rawRecipient -  Address or namespace name. If starts with "@", it is a namespace name.
     * @returns {UnresolvedAddress}
     */
    static getUnresolvedAddress(rawRecipient) {
        let recipient;
        if (rawRecipient.charAt(0) === AccountService.ALIAS_TAG) {
            recipient = new symbol_sdk_1.NamespaceId(rawRecipient.substring(1));
        }
        else {
            recipient = symbol_sdk_1.Address.createFromRawAddress(rawRecipient);
        }
        return recipient;
    }
    /**
     * Generates the accounts from given mnemonic
     * @param {string} mnemonic
     * @param {NetworkType} networkType
     * @param {Network} curve
     * @param numOfAccounts
     */
    static generateAccountsFromMnemonic(mnemonic, networkType, curve, numOfAccounts = 10) {
        return [...Array(numOfAccounts).keys()].map((i) => {
            const privateKey = derivation_service_1.DerivationService.getPrivateKeyFromMnemonicWithCurve(mnemonic, i, networkType, curve);
            return symbol_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
        });
    }
}
exports.AccountService = AccountService;
AccountService.ALIAS_TAG = '@';
