"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEmitterAddressAlgorand = exports.getEmitterAddressTerra = exports.getEmitterAddressSolana = exports.getEmitterAddressEth = void 0;
const web3_js_1 = require("@solana/web3.js");
const algosdk_1 = require("algosdk");
const bech32_1 = require("bech32");
const utils_1 = require("ethers/lib/utils");
const wasm_1 = require("../solana/wasm");
const utils_2 = require("../utils");
function getEmitterAddressEth(contractAddress) {
    return Buffer.from(utils_1.zeroPad(utils_1.arrayify(contractAddress), 32)).toString("hex");
}
exports.getEmitterAddressEth = getEmitterAddressEth;
function getEmitterAddressSolana(programAddress) {
    return __awaiter(this, void 0, void 0, function* () {
        const { emitter_address } = yield wasm_1.importTokenWasm();
        return Buffer.from(utils_1.zeroPad(new web3_js_1.PublicKey(emitter_address(programAddress)).toBytes(), 32)).toString("hex");
    });
}
exports.getEmitterAddressSolana = getEmitterAddressSolana;
function getEmitterAddressTerra(programAddress) {
    return __awaiter(this, void 0, void 0, function* () {
        return Buffer.from(utils_1.zeroPad(bech32_1.bech32.fromWords(bech32_1.bech32.decode(programAddress).words), 32)).toString("hex");
    });
}
exports.getEmitterAddressTerra = getEmitterAddressTerra;
function getEmitterAddressAlgorand(appId) {
    const appAddr = algosdk_1.getApplicationAddress(appId);
    const decAppAddr = algosdk_1.decodeAddress(appAddr).publicKey;
    const aa = utils_2.uint8ArrayToHex(decAppAddr);
    return aa;
}
exports.getEmitterAddressAlgorand = getEmitterAddressAlgorand;
