UNPKG

ordinalsbot

Version:
135 lines 5.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InscriptionClient = void 0; const axios_1 = __importDefault(require("axios")); const error_1 = require("./inscription/error"); const types_1 = require("./types"); const crypto_1 = require("bitcoinjs-lib/src/crypto"); const l402_1 = require("l402"); const qs = require("qs"); class InscriptionClient { constructor(key = "", environment = types_1.InscriptionEnvNetwork.mainnet, options) { this.api_key = key; this.env = types_1.InscriptionEnvNetwork[environment] ?? types_1.InscriptionEnvNetwork.mainnet; const createInstance = () => { const headers = { "Content-Type": "application/json" }; if (this.api_key) { headers["x-api-key"] = this.api_key; } const baseURL = options?.useL402 ? "https://ordinalsbot.ln.sulu.sh" : types_1.EnvNetworkExplorer[this.env] || types_1.EnvNetworkExplorer.mainnet; const client = axios_1.default.create({ baseURL, headers: headers, }); client.interceptors.response.use(({ data }) => ("data" in data ? data.data : data), (err) => { if (axios_1.default.isAxiosError(err) && err.response?.status !== 402) { throw new error_1.InscriptionError(err.message, err.response?.statusText, err.response?.status); } if (err instanceof Error) throw err; return err; }); if (options?.useL402 && options.l402Config) { (0, l402_1.setupL402Interceptor)(client, options.l402Config.wallet, options.l402Config.tokenStore); } ; return client; }; this.instanceV1 = createInstance(); this.apikeyhash = (0, crypto_1.sha256)(Buffer.from(this.api_key)).toString("hex"); } get axiosInstance() { return this.instanceV1; } async getPrice(priceRequest) { return this.instanceV1.get(`/price`, { params: priceRequest, }); } async createOrder(order) { return this.instanceV1.post(`/order`, order); } async createDirectOrder(order) { return this.instanceV1.post(`/inscribe`, order); } async getOrder(id) { return this.instanceV1.get(`/order`, { params: { id }, }); } async createCollection(collection) { let plainObject = Object.assign({ ...collection }); let files = collection?.files; for (let index in files) { let file = files[index]; let keys = Object.keys(file); for (let key in keys) { let propName = keys[key]; plainObject[`files[${index}][${propName}]`] = file[propName]; } } delete plainObject.files; plainObject.apikeyhash = this.apikeyhash; const data = qs.stringify(plainObject); let config = { method: "post", maxBodyLength: Infinity, url: this.instanceV1.getUri() + "/collectioncreate", headers: { "Content-Type": "application/x-www-form-urlencoded", }, data: data, }; return axios_1.default.request(config); } async updateCollectionPhases(collection) { return this.instanceV1.post(`/updatecollectionphases`, { ...collection }); } async getAllocation(allocation) { return this.instanceV1.post(`/getallocation`, allocation); } async createCollectionOrder(collectionOrder) { return this.instanceV1.post(`/collectionorder`, collectionOrder); } async createTextOrder(order) { return this.instanceV1.post(`/textorder`, order); } async createRunesEtchOrder(order) { return this.instanceV1.post(`/runes/etch`, order); } async createRunesMintOrder(order) { return this.instanceV1.post(`/runes/mint`, order); } async getInventory() { return this.instanceV1.get(`/inventory`); } async setReferralCode(referral) { return this.instanceV1.post(`/referrals`, referral); } async getReferralStatus(referral) { return this.instanceV1.get(`/referrals`, { params: referral, }); } async createSpecialSatsPSBT(createSpecialSatsRequest) { return this.instanceV1.post(`/create-special-sats-psbt`, { ...createSpecialSatsRequest, }); } async createParentChildPsbt(createParentChildPsbtRequest) { return this.instanceV1.post(`/create-parent-child-psbt`, { ...createParentChildPsbtRequest, }); } } exports.InscriptionClient = InscriptionClient; //# sourceMappingURL=client.js.map