"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};

// src/index.ts
var index_exports = {};
__export(index_exports, {
  BlindPay: () => BlindPay,
  createApiKeysResource: () => createApiKeysResource,
  createAvailableResource: () => createAvailableResource,
  createBankAccountsResource: () => createBankAccountsResource,
  createBlockchainWalletsResource: () => createBlockchainWalletsResource,
  createInstancesResource: () => createInstancesResource,
  createOfframpWalletsResource: () => createOfframpWalletsResource,
  createPartnerFeesResource: () => createPartnerFeesResource,
  createPayinQuotesResource: () => createPayinQuotesResource,
  createPayinsResource: () => createPayinsResource,
  createPayoutsResource: () => createPayoutsResource,
  createQuotesResource: () => createQuotesResource,
  createReceiversResource: () => createReceiversResource,
  createVirtualAccountsResource: () => createVirtualAccountsResource,
  createWebhookEndpointsResource: () => createWebhookEndpointsResource
});
module.exports = __toCommonJS(index_exports);

// src/client.ts
var import_node_crypto = require("crypto");

// package.json
var version = "1.1.0";

// src/internal/blindpay-error.ts
var BlindPayError = class extends Error {
  constructor(message) {
    super(message);
    this.name = "BlindpayError";
  }
};

// src/resources/api-keys/index.ts
function createApiKeysResource(instanceId, client) {
  return {
    list() {
      return client.get(`/instances/${instanceId}/api-keys`);
    },
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/api-keys`, data);
    },
    get(id) {
      return client.get(`/instances/${instanceId}/api-keys/${id}`);
    },
    delete(id) {
      return client.delete(`/instances/${instanceId}/api-keys/${id}`);
    }
  };
}

// src/resources/available/index.ts
function createAvailableResource(client) {
  return {
    getBankDetails(rail) {
      return client.get(`/available/bank-details?rail=${rail}`);
    },
    getRails() {
      return client.get("/available/rails");
    }
  };
}

// src/resources/bank-accounts/index.ts
function createBankAccountsResource(instanceId, client) {
  return {
    list(receiver_id) {
      return client.get(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`);
    },
    get({
      receiver_id,
      id
    }) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/bank-accounts/${id}`
      );
    },
    delete({ receiver_id, id }) {
      return client.delete(
        `/instances/${instanceId}/receivers/${receiver_id}/bank-accounts/${id}`
      );
    },
    createPix(_a) {
      var _b = _a, {
        receiver_id
      } = _b, data = __objRest(_b, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "pix"
      }, data));
    },
    createArgentinaTransfers(_c) {
      var _d = _c, {
        receiver_id
      } = _d, data = __objRest(_d, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "transfers_bitso"
      }, data));
    },
    createSpei(_e) {
      var _f = _e, {
        receiver_id
      } = _f, data = __objRest(_f, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "spei_bitso"
      }, data));
    },
    createColombiaAch(_g) {
      var _h = _g, {
        receiver_id
      } = _h, data = __objRest(_h, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "ach_cop_bitso"
      }, data));
    },
    createAch(_i) {
      var _j = _i, {
        receiver_id
      } = _j, data = __objRest(_j, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "ach"
      }, data));
    },
    createWire(_k) {
      var _l = _k, {
        receiver_id
      } = _l, data = __objRest(_l, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "wire"
      }, data));
    },
    createInternationalSwift(_m) {
      var _n = _m, {
        receiver_id
      } = _n, data = __objRest(_n, [
        "receiver_id"
      ]);
      return client.post(`/instances/${instanceId}/receivers/${receiver_id}/bank-accounts`, __spreadValues({
        type: "international_swift"
      }, data));
    }
  };
}

// src/resources/instances/index.ts
function createInstancesResource(instanceId, client) {
  return {
    getMembers() {
      return client.get(`/instances/${instanceId}/members`);
    },
    update(_a) {
      var data = __objRest(_a, []);
      return client.put(`/instances/${instanceId}`, data);
    },
    delete() {
      return client.delete(`/instances/${instanceId}`);
    },
    deleteMember(memberId) {
      return client.delete(`/instances/${instanceId}/members/${memberId}`);
    },
    updateMemberRole({
      memberId,
      role
    }) {
      return client.put(`/instances/${instanceId}/members/${memberId}`, { role });
    }
  };
}

// src/resources/partner-fees/index.ts
function createPartnerFeesResource(instanceId, client) {
  return {
    list() {
      return client.get(`/instances/${instanceId}/partner-fees`);
    },
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/partner-fees`, data);
    },
    get(id) {
      return client.get(`/instances/${instanceId}/partner-fees/${id}`);
    },
    delete(id) {
      return client.delete(`/instances/${instanceId}/partner-fees/${id}`);
    }
  };
}

// src/resources/payins/index.ts
function createPayinsResource(instanceId, client) {
  return {
    list(params) {
      const queryParams = params ? `?${new URLSearchParams(params)}` : "";
      return client.get(`/instances/${instanceId}/payins${queryParams}`);
    },
    get(payinId) {
      return client.get(`/instances/${instanceId}/payins/${payinId}`);
    },
    getTrack(payinId) {
      return client.get(`/e/payins/${payinId}`);
    },
    export(_a) {
      var params = __objRest(_a, []);
      const queryParams = params ? `?${new URLSearchParams(params)}` : "";
      return client.get(`/instances/${instanceId}/export/payins${queryParams}`);
    },
    createEvm(payin_quote_id) {
      return client.post(`/instances/${instanceId}/payins/evm`, {
        payin_quote_id
      });
    }
  };
}

// src/resources/payins/quotes.ts
function createPayinQuotesResource(instanceId, client) {
  return {
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/payin-quotes`, data);
    },
    getFxRate(_b) {
      var data = __objRest(_b, []);
      return client.post(`/instances/${instanceId}/payin-quotes/fx`, data);
    }
  };
}

// src/resources/payouts/index.ts
function createPayoutsResource(instanceId, client) {
  return {
    list(params) {
      const queryParams = params ? `?${new URLSearchParams(params)}` : "";
      return client.get(`/instances/${instanceId}/payouts${queryParams}`);
    },
    export(params) {
      const queryParams = params ? `?${new URLSearchParams(params)}` : "";
      return client.get(`/instances/${instanceId}/export/payouts${queryParams}`);
    },
    get(payoutId) {
      return client.get(`/instances/${instanceId}/payouts/${payoutId}`);
    },
    getTrack(payoutId) {
      return client.get(`/e/payouts/${payoutId}`);
    },
    authorizeStellarToken(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/payouts/stellar/authorize`, data);
    },
    createStellar(_b) {
      var data = __objRest(_b, []);
      return client.post(`/instances/${instanceId}/payouts/stellar`, data);
    },
    createEvm(_c) {
      var data = __objRest(_c, []);
      return client.post(`/instances/${instanceId}/payouts/evm`, data);
    }
  };
}

// src/resources/quotes/index.ts
function createQuotesResource(instanceId, client) {
  return {
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/quotes`, data);
    },
    getFxRate(_b) {
      var data = __objRest(_b, []);
      return client.post(`/instances/${instanceId}/quotes/fx`, data);
    }
  };
}

// src/resources/receivers/index.ts
function createReceiversResource(instanceId, client) {
  return {
    list() {
      return client.get(`/instances/${instanceId}/receivers`);
    },
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/receivers`, data);
    },
    get(receiver_id) {
      return client.get(`/instances/${instanceId}/receivers/${receiver_id}`);
    },
    update(_b) {
      var _c = _b, { receiver_id } = _c, data = __objRest(_c, ["receiver_id"]);
      return client.patch(`/instances/${instanceId}/receivers/${receiver_id}`, data);
    },
    delete(receiver_id) {
      return client.delete(`/instances/${instanceId}/receivers/${receiver_id}`);
    },
    getLimits(receiver_id) {
      return client.get(`/instances/${instanceId}/limits/receivers/${receiver_id}`);
    }
  };
}

// src/resources/virtual-accounts/index.ts
function createVirtualAccountsResource(instanceId, client) {
  return {
    update(_a) {
      var _b = _a, {
        receiver_id
      } = _b, data = __objRest(_b, [
        "receiver_id"
      ]);
      return client.put(
        `/instances/${instanceId}/receivers/${receiver_id}/virtual-accounts`,
        data
      );
    },
    create(_c) {
      var _d = _c, {
        receiver_id
      } = _d, data = __objRest(_d, [
        "receiver_id"
      ]);
      return client.post(
        `/instances/${instanceId}/receivers/${receiver_id}/virtual-accounts`,
        data
      );
    },
    get(receiver_id) {
      return client.get(`/instances/${instanceId}/receivers/${receiver_id}/virtual-accounts`);
    }
  };
}

// src/resources/wallets/blockchain.ts
function createBlockchainWalletsResource(instanceId, client) {
  return {
    list(receiver_id) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets`
      );
    },
    createWithAddress(_a) {
      var _b = _a, {
        receiver_id
      } = _b, data = __objRest(_b, [
        "receiver_id"
      ]);
      return client.post(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets`,
        __spreadProps(__spreadValues({}, data), {
          is_account_abstraction: true
        })
      );
    },
    createWithHash(_c) {
      var _d = _c, {
        receiver_id
      } = _d, data = __objRest(_d, [
        "receiver_id"
      ]);
      return client.post(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets`,
        __spreadProps(__spreadValues({}, data), {
          is_account_abstraction: false
        })
      );
    },
    getWalletMessage(receiver_id) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets/sign-message`
      );
    },
    get({
      receiver_id,
      id
    }) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets/${id}`
      );
    },
    delete({
      receiver_id,
      id
    }) {
      return client.delete(
        `/instances/${instanceId}/receivers/${receiver_id}/blockchain-wallets/${id}`
      );
    },
    createAssetTrustline(address) {
      return client.post(`/instances/${instanceId}/create-asset-trustline`, {
        address
      });
    },
    mintUsdbStellar(_e) {
      var data = __objRest(_e, []);
      return client.post(`/instances/${instanceId}/mint-usdb-stellar`, data);
    }
  };
}

// src/resources/wallets/offramp.ts
function createOfframpWalletsResource(instanceId, client) {
  return {
    list({
      bank_account_id,
      receiver_id
    }) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/bank-accounts/${bank_account_id}/offramp-wallets`
      );
    },
    create(_a) {
      var _b = _a, {
        receiver_id,
        bank_account_id
      } = _b, data = __objRest(_b, [
        "receiver_id",
        "bank_account_id"
      ]);
      return client.post(
        `/instances/${instanceId}/receivers/${receiver_id}/bank-accounts/${bank_account_id}/offramp-wallets`,
        data
      );
    },
    get({
      receiver_id,
      bank_account_id,
      id
    }) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiver_id}/bank-accounts/${bank_account_id}/offramp-wallets/${id}`
      );
    }
  };
}

// src/resources/webhooks/index.ts
function createWebhookEndpointsResource(instanceId, client) {
  return {
    list() {
      return client.get(`/instances/${instanceId}/webhook-endpoints`);
    },
    create(_a) {
      var data = __objRest(_a, []);
      return client.post(`/instances/${instanceId}/webhook-endpoints`, data);
    },
    delete(id) {
      return client.delete(`/instances/${instanceId}/webhook-endpoints/${id}`);
    },
    getSecret(id) {
      return client.get(`/instances/${instanceId}/webhook-endpoints/${id}/secret`);
    },
    getPortalAccessUrl() {
      return client.get(`/instances/${instanceId}/webhook-endpoints/portal-access`);
    }
  };
}

// src/client.ts
var BlindPay = class {
  constructor({
    apiKey,
    instanceId
  }) {
    // Options
    this.baseUrl = "https://api.blindpay.com/v1";
    if (!apiKey) {
      throw new BlindPayError("Api key not provided, get your api key on blindpay dashboard");
    }
    if (!instanceId) {
      throw new BlindPayError(
        "Instance id not provided, get your instance id on blindpay dashboard"
      );
    }
    this.apiKey = apiKey;
    this.instanceId = instanceId;
    this.headers = {
      "Content-Type": "application/json",
      Accept: "application/json",
      "User-Agent": `blindpay-node/${version}`,
      Authorization: `Bearer ${this.apiKey}`
    };
    this.api = {
      get: this.get.bind(this),
      post: this.post.bind(this),
      put: this.put.bind(this),
      patch: this.patch.bind(this),
      delete: this.delete.bind(this)
    };
    this.available = createAvailableResource(this.api);
    this.instances = __spreadProps(__spreadValues({}, createInstancesResource(this.instanceId, this.api)), {
      apiKeys: createApiKeysResource(this.instanceId, this.api),
      webhookEndpoints: createWebhookEndpointsResource(this.instanceId, this.api)
    });
    this.partnerFees = createPartnerFeesResource(this.instanceId, this.api);
    this.payins = __spreadProps(__spreadValues({}, createPayinsResource(this.instanceId, this.api)), {
      quotes: createPayinQuotesResource(this.instanceId, this.api)
    });
    this.quotes = createQuotesResource(this.instanceId, this.api);
    this.payouts = createPayoutsResource(this.instanceId, this.api);
    this.receivers = __spreadProps(__spreadValues({}, createReceiversResource(this.instanceId, this.api)), {
      bankAccounts: createBankAccountsResource(this.instanceId, this.api)
    });
    this.virtualAccounts = createVirtualAccountsResource(this.instanceId, this.api);
    this.wallets = {
      blockchain: createBlockchainWalletsResource(this.instanceId, this.api),
      offramp: createOfframpWalletsResource(this.instanceId, this.api)
    };
  }
  request(method, path, body) {
    return __async(this, null, function* () {
      var _a;
      try {
        const response = yield fetch(`${this.baseUrl}${path}`, {
          method,
          headers: this.headers,
          body: body ? JSON.stringify(body) : void 0
        });
        if (!response.ok) {
          const error = yield response.json();
          return {
            data: null,
            error: {
              message: (_a = error == null ? void 0 : error.message) != null ? _a : "Unknown error"
            }
          };
        }
        const data = yield response.json();
        return {
          data,
          error: null
        };
      } catch (error) {
        if (error instanceof Error) {
          return {
            data: null,
            error: {
              message: error.message
            }
          };
        }
        const errorMessage = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "Unknown error";
        return {
          data: null,
          error: {
            message: errorMessage
          }
        };
      }
    });
  }
  get(path) {
    return __async(this, null, function* () {
      return this.request("GET", path);
    });
  }
  post(path, body) {
    return __async(this, null, function* () {
      return this.request("POST", path, body);
    });
  }
  put(path, body) {
    return __async(this, null, function* () {
      return this.request("PUT", path, body);
    });
  }
  patch(path, body) {
    return __async(this, null, function* () {
      return this.request("PATCH", path, body);
    });
  }
  delete(path, body) {
    return __async(this, null, function* () {
      return this.request("DELETE", path, body);
    });
  }
  /**
   * Verifies the BlindPay webhook signature
   *
   * @param params.secret The webhook secret from BlindPay dashboard
   * @param params.id The value of the `svix-id` header
   * @param params.timestamp The value of the `svix-timestamp` header
   * @param params.payload The raw request body
   * @param params.svixSignature The value of the `svix-signature` header
   * @returns {boolean} True if the signature is valid, false otherwise
   */
  verifyWebhookSignature({
    secret,
    id,
    timestamp,
    payload,
    svixSignature
  }) {
    const signedContent = `${id}.${timestamp}.${payload}`;
    const secretBytes = Buffer.from(secret.split("_")[1], "base64");
    const expectedSignature = (0, import_node_crypto.createHmac)("sha256", secretBytes).update(signedContent).digest("base64");
    return svixSignature.length === expectedSignature.length && (0, import_node_crypto.timingSafeEqual)(Buffer.from(svixSignature), Buffer.from(expectedSignature));
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BlindPay,
  createApiKeysResource,
  createAvailableResource,
  createBankAccountsResource,
  createBlockchainWalletsResource,
  createInstancesResource,
  createOfframpWalletsResource,
  createPartnerFeesResource,
  createPayinQuotesResource,
  createPayinsResource,
  createPayoutsResource,
  createQuotesResource,
  createReceiversResource,
  createVirtualAccountsResource,
  createWebhookEndpointsResource
});
