@autlantic/payments 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +92 -0
- package/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/TESTING.md +140 -0
- package/bin/autlantic-payments.mjs +155 -0
- package/dist/client.d.ts +53 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +154 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +2 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/from-env.d.ts +4 -0
- package/dist/from-env.d.ts.map +1 -0
- package/dist/from-env.js +25 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/sandbox.d.ts +5 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +16 -0
- package/dist/test-scenarios.d.ts +48 -0
- package/dist/test-scenarios.d.ts.map +1 -0
- package/dist/test-scenarios.js +235 -0
- package/dist/webhook.d.ts +7 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +47 -0
- package/package.json +65 -0
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signWebhookPayload = signWebhookPayload;
|
|
4
|
+
exports.verifyWebhookSignature = verifyWebhookSignature;
|
|
5
|
+
exports.serializeConfirmedEvent = serializeConfirmedEvent;
|
|
6
|
+
exports.parseConfirmedWebhookEvent = parseConfirmedWebhookEvent;
|
|
7
|
+
exports.parseAndVerifyWebhook = parseAndVerifyWebhook;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
function signWebhookPayload(secret, body) {
|
|
10
|
+
return (0, node_crypto_1.createHmac)("sha256", secret).update(body).digest("hex");
|
|
11
|
+
}
|
|
12
|
+
function verifyWebhookSignature(secret, rawBody, signatureHeader) {
|
|
13
|
+
if (!signatureHeader?.trim())
|
|
14
|
+
return false;
|
|
15
|
+
const expected = signWebhookPayload(secret, rawBody);
|
|
16
|
+
try {
|
|
17
|
+
const a = Buffer.from(expected, "utf8");
|
|
18
|
+
const b = Buffer.from(signatureHeader.trim(), "utf8");
|
|
19
|
+
if (a.length !== b.length)
|
|
20
|
+
return false;
|
|
21
|
+
return (0, node_crypto_1.timingSafeEqual)(a, b);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function serializeConfirmedEvent(event) {
|
|
28
|
+
return JSON.stringify(event);
|
|
29
|
+
}
|
|
30
|
+
function parseConfirmedWebhookEvent(rawBody) {
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(rawBody);
|
|
33
|
+
if (parsed?.type !== "payment.confirmed")
|
|
34
|
+
return null;
|
|
35
|
+
if (!parsed.intentId || !parsed.merchantRef || !parsed.txHash)
|
|
36
|
+
return null;
|
|
37
|
+
return parsed;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function parseAndVerifyWebhook(secret, rawBody, signatureHeader) {
|
|
44
|
+
if (!verifyWebhookSignature(secret, rawBody, signatureHeader))
|
|
45
|
+
return null;
|
|
46
|
+
return parseConfirmedWebhookEvent(rawBody);
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autlantic/payments",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Autlantic Payments SDK — verify USDT on TRON and confirm merchant checkouts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/arslandulsoft/DrProfit.git",
|
|
9
|
+
"directory": "packages/payments"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"tron",
|
|
16
|
+
"usdt",
|
|
17
|
+
"trc20",
|
|
18
|
+
"payments",
|
|
19
|
+
"crypto",
|
|
20
|
+
"verification",
|
|
21
|
+
"autlantic"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"bin",
|
|
29
|
+
"README.md",
|
|
30
|
+
"API.md",
|
|
31
|
+
"TESTING.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"bin": {
|
|
36
|
+
"autlantic-payments": "./bin/autlantic-payments.mjs"
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"import": "./dist/index.js",
|
|
44
|
+
"require": "./dist/index.js",
|
|
45
|
+
"default": "./dist/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@autlantic/chain-tron": "0.1.0",
|
|
50
|
+
"@autlantic/payments-core": "0.1.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.15.29",
|
|
54
|
+
"tsx": "^4.19.4",
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc",
|
|
59
|
+
"dev": "tsc --watch",
|
|
60
|
+
"test": "tsx --test 'src/**/*.test.ts' 'test/**/*.test.ts'",
|
|
61
|
+
"test:live": "TRONGRID_INTEGRATION=1 tsx --test test/**/*.test.ts",
|
|
62
|
+
"example": "tsx examples/sandbox-demo.mts",
|
|
63
|
+
"example:merchant": "tsx examples/merchant-flow.mts"
|
|
64
|
+
}
|
|
65
|
+
}
|