Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions stellar-payment-platform/src/routes/v1/webhookRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@ const { verifyMultiSignerThreshold } = require('../../multisigner-verifier');
const { logger } = require('../../logger');
const { Keypair, StrKey } = require('@stellar/stellar-sdk');
const { asyncHandler } = require('../../middleware/asyncHandler');
const { shouldFallbackToLocalRegistry } = require('../../utils');

const router = express.Router();

const DEFAULT_FEDERATION_DOMAIN = 'localhost';

const shouldFallbackToLocalRegistry = (error) => {
const code = typeof error?.code === 'string' ? error.code : '';
const message = typeof error?.message === 'string' ? error.message : '';

return (
code.startsWith('P10') ||
['P2021', 'P2023', 'P2028', 'P2001'].includes(code) ||
/DATABASE_URL|connect|relation|table|timeout/i.test(message)
);
};

const verifyFreighterSignedMessage = ({
message,
signature,
Expand Down Expand Up @@ -86,7 +76,7 @@ const authenticateWebhookCall = async (req) => {

const normalizedUsername = normalizeNameTag(rawUsername).toLowerCase();

let userRecord = null;
let userRecord;
try {
userRecord = await prisma.user.findUnique({
where: { username: normalizedUsername },
Expand Down
11 changes: 1 addition & 10 deletions stellar-payment-platform/src/webhookWorker.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
const crypto = require('crypto');
const cron = require('node-cron');
const { logger } = require('./logger');
const { shouldFallbackToLocalRegistry } = require('./utils');

const WEBHOOK_TIMEOUT_MS = 10_000;
const MAX_RETRY_BACKLOG_DAYS = 3;
const RETRY_JOB_CRON = '*/5 * * * *'; // every 5 minutes

const shouldFallbackToLocalRegistry = (error) => {
const code = typeof error?.code === 'string' ? error.code : '';
const message = typeof error?.message === 'string' ? error.message : '';
return (
code.startsWith('P10') ||
['P2021', 'P2023', 'P2028', 'P2001'].includes(code) ||
/DATABASE_URL|connect|relation|table|timeout/i.test(message)
);
};

const computeSignature = (secret, rawBody) => {
return crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
};
Expand Down
Loading