UNPKG

@kanalabs/mirai

Version:

Mirai - Account Abstraction SDK (EVM + non-EVM)

125 lines (124 loc) 4.93 kB
"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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Paymaster = void 0; const constant_1 = require("./constant"); const cross_fetch_1 = __importDefault(require("cross-fetch")); class Paymaster { constructor(apiKey) { this.apiKey = apiKey; this.baseUrl = constant_1.MIRAI_PAYMASTER_URL; this.apikey = ""; if (!apiKey) throw new Error('Invalid Api Key'); this.apiKey = apiKey; } addWhitelist(accountAddress, chainId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this.baseUrl}/whitelist`; const requestBody = { addresses: accountAddress, chainId: chainId, apiKey: this.apiKey }; const response = yield (0, cross_fetch_1.default)(url, { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); return yield response.json(); }); } checkWhitelist(accountAddress, sponsorAddress, chainId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this.baseUrl}/checkWhitelist`; const requestBody = { accountAddress: accountAddress, sponsorAddress: sponsorAddress, chainId: chainId, apiKey: this.apiKey }; const response = yield (0, cross_fetch_1.default)(url, { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); return yield response.json(); }); } removeWhitelist(accountAddress, chainId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this.baseUrl}/removeWhitelist`; const requestBody = { addresses: accountAddress, chainId: chainId, apiKey: this.apiKey }; const response = yield (0, cross_fetch_1.default)(url, { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); return yield response.json(); }); } deposit(amount, chainId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this.baseUrl}/deposit`; const requestBody = { amount: amount, chainId: chainId, apiKey: this.apiKey }; const response = yield (0, cross_fetch_1.default)(url, { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify(requestBody), }); return yield response.json(); }); } getSponsorBalance(sponsorAddress, chainId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this.baseUrl}/getSponsorBalance`; const query = { sponsorAddress: sponsorAddress, chainId: chainId.toString() }; const params = new URLSearchParams(query).toString(); const fullUrl = `${url}?${params}`; const response = yield (0, cross_fetch_1.default)(fullUrl, { method: "GET", headers: { Accept: "application/json", "Content-Type": "application/json", }, }); return yield response.json(); }); } } exports.Paymaster = Paymaster;