"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.0.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(client) {
  return {
    list({ instanceId }) {
      return client.get(`/instances/${instanceId}/api-keys`);
    },
    create(_a) {
      var _b = _a, {
        instanceId
      } = _b, data = __objRest(_b, [
        "instanceId"
      ]);
      return client.post(`/instances/${instanceId}/api-keys`, data);
    },
    get({ instanceId, id }) {
      return client.get(`/instances/${instanceId}/api_keys/${id}`);
    },
    delete({ instanceId, 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(client) {
  return {
    list({
      instanceId,
      receiverId
    }) {
      return client.get(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`);
    },
    createPix({
      instanceId,
      receiverId,
      name,
      pix_key
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "pix",
        name,
        pix_key
      });
    },
    createArgentinaTransfers({
      instanceId,
      receiverId,
      beneficiary_name,
      name,
      transfers_account,
      transfers_type
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "transfers_bitso",
        beneficiary_name,
        name,
        transfers_account,
        transfers_type
      });
    },
    createSpei({
      instanceId,
      receiverId,
      beneficiary_name,
      name,
      spei_clabe,
      spei_institution_code,
      spei_protocol
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "spei_bitso",
        beneficiary_name,
        name,
        spei_clabe,
        spei_institution_code,
        spei_protocol
      });
    },
    createColombiaAch({
      instanceId,
      receiverId,
      name,
      account_type,
      ach_cop_beneficiary_first_name,
      ach_cop_beneficiary_last_name,
      ach_cop_document_id,
      ach_cop_document_type,
      ach_cop_email,
      ach_cop_bank_code,
      ach_cop_bank_account
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "ach_cop_bitso",
        name,
        account_type,
        ach_cop_beneficiary_first_name,
        ach_cop_beneficiary_last_name,
        ach_cop_document_id,
        ach_cop_document_type,
        ach_cop_email,
        ach_cop_bank_code,
        ach_cop_bank_account
      });
    },
    createAch({
      instanceId,
      receiverId,
      name,
      account_class,
      account_number,
      account_type,
      beneficiary_name,
      routing_number
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "ach",
        name,
        account_class,
        account_number,
        account_type,
        beneficiary_name,
        routing_number
      });
    },
    createWire({
      instanceId,
      receiverId,
      name,
      account_number,
      beneficiary_name,
      routing_number,
      address_line_1,
      address_line_2,
      city,
      state_province_region,
      country,
      postal_code
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "wire",
        name,
        account_number,
        beneficiary_name,
        routing_number,
        address_line_1,
        address_line_2,
        city,
        state_province_region,
        country,
        postal_code
      });
    },
    createInternationalSwift({
      instanceId,
      receiverId,
      name,
      swift_account_holder_name,
      swift_account_number_iban,
      swift_bank_address_line_1,
      swift_bank_address_line_2,
      swift_bank_city,
      swift_bank_country,
      swift_bank_name,
      swift_bank_postal_code,
      swift_bank_state_province_region,
      swift_beneficiary_address_line_1,
      swift_beneficiary_address_line_2,
      swift_beneficiary_city,
      swift_beneficiary_country,
      swift_beneficiary_postal_code,
      swift_beneficiary_state_province_region,
      swift_code_bic,
      swift_intermediary_bank_account_number_iban,
      swift_intermediary_bank_country,
      swift_intermediary_bank_name,
      swift_intermediary_bank_swift_code_bic
    }) {
      return client.post(`/instances/${instanceId}/receivers/${receiverId}/bank-accounts`, {
        type: "international_swift",
        name,
        swift_account_holder_name,
        swift_account_number_iban,
        swift_bank_address_line_1,
        swift_bank_address_line_2,
        swift_bank_city,
        swift_bank_country,
        swift_bank_name,
        swift_bank_postal_code,
        swift_bank_state_province_region,
        swift_beneficiary_address_line_1,
        swift_beneficiary_address_line_2,
        swift_beneficiary_city,
        swift_beneficiary_country,
        swift_beneficiary_postal_code,
        swift_beneficiary_state_province_region,
        swift_code_bic,
        swift_intermediary_bank_account_number_iban,
        swift_intermediary_bank_country,
        swift_intermediary_bank_name,
        swift_intermediary_bank_swift_code_bic
      });
    },
    get({
      instanceId,
      receiverId,
      id
    }) {
      return client.get(
        `/instances/${instanceId}/receivers/${receiverId}/bank-accounts/${id}`
      );
    },
    delete({
      instanceId,
      receiverId,
      id
    }) {
      return client.delete(
        `/instances/${instanceId}/receivers/${receiverId}/bank-accounts/${id}`
      );
    }
  };
}

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

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

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

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

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

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

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

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

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

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

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

// src/client.ts
var Blindpay = class {
  constructor(apiKey) {
    // Options
    this.baseUrl = "https://api.blindpay.com/v1";
    if (!apiKey) {
      throw new BlindpayError("Api key not provided, get your api key on blindpay dashboard");
    }
    this.apiKey = apiKey;
    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.api)), {
      apiKeys: createApiKeysResource(this.api),
      webhookEndpoints: createWebhookEndpointsResource(this.api)
    });
    this.partnerFees = createPartnerFeesResource(this.api);
    this.payins = __spreadProps(__spreadValues({}, createPayinsResource(this.api)), {
      quotes: createPayinQuotesResource(this.api)
    });
    this.quotes = createQuotesResource(this.api);
    this.payouts = createPayoutsResource(this.api);
    this.receivers = __spreadProps(__spreadValues({}, createReceiversResource(this.api)), {
      bankAccounts: createBankAccountsResource(this.api)
    });
    this.virtualAccounts = createVirtualAccountsResource(this.api);
    this.wallets = {
      blockchain: createBlockchainWalletsResource(this.api),
      offramp: createOfframpWalletsResource(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
});
