@hypermid/sdk 1.2.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/README.md +71 -0
- package/dist/chain-registry.d.ts +104 -0
- package/dist/chain-registry.d.ts.map +1 -0
- package/dist/chain-registry.js +507 -0
- package/dist/chain-registry.js.map +1 -0
- package/dist/chains.d.ts +85 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +97 -0
- package/dist/chains.js.map +1 -0
- package/dist/client.d.ts +257 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +477 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +56 -0
- package/dist/errors.js.map +1 -0
- package/dist/execution.d.ts +193 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +348 -0
- package/dist/execution.js.map +1 -0
- package/dist/helpers.d.ts +71 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +97 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +487 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook-verify.d.ts +40 -0
- package/dist/webhook-verify.d.ts.map +1 -0
- package/dist/webhook-verify.js +76 -0
- package/dist/webhook-verify.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook signature verification utility.
|
|
3
|
+
*
|
|
4
|
+
* When HyperMid sends a webhook, it includes:
|
|
5
|
+
* - `X-Hypermid-Signature`: HMAC-SHA256 hex digest of the raw body
|
|
6
|
+
* - `X-Hypermid-Event`: event type (e.g. "swap.completed")
|
|
7
|
+
*
|
|
8
|
+
* Use `verifyWebhookSignature()` to validate incoming webhooks.
|
|
9
|
+
*
|
|
10
|
+
* @example Express / Node.js
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { verifyWebhookSignature } from "@hypermid/sdk";
|
|
13
|
+
*
|
|
14
|
+
* app.post("/webhooks/hypermid", express.raw({ type: "application/json" }), (req, res) => {
|
|
15
|
+
* const signature = req.headers["x-hypermid-signature"] as string;
|
|
16
|
+
* const isValid = verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET);
|
|
17
|
+
*
|
|
18
|
+
* if (!isValid) {
|
|
19
|
+
* return res.status(401).send("Invalid signature");
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const event = req.headers["x-hypermid-event"];
|
|
23
|
+
* const payload = JSON.parse(req.body.toString());
|
|
24
|
+
* // Handle event...
|
|
25
|
+
* res.sendStatus(200);
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Verify a webhook signature using HMAC-SHA256.
|
|
31
|
+
*
|
|
32
|
+
* Works in both Node.js (using `crypto`) and edge runtimes (using `SubtleCrypto`).
|
|
33
|
+
*
|
|
34
|
+
* @param body - The raw request body (string or Buffer/Uint8Array)
|
|
35
|
+
* @param signature - The `X-Hypermid-Signature` header value
|
|
36
|
+
* @param secret - Your webhook signing secret (from webhook creation)
|
|
37
|
+
* @returns `true` if the signature is valid
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyWebhookSignature(body: string | Uint8Array, signature: string, secret: string): Promise<boolean>;
|
|
40
|
+
//# sourceMappingURL=webhook-verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-verify.d.ts","sourceRoot":"","sources":["../src/webhook-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAgClB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook signature verification utility.
|
|
3
|
+
*
|
|
4
|
+
* When HyperMid sends a webhook, it includes:
|
|
5
|
+
* - `X-Hypermid-Signature`: HMAC-SHA256 hex digest of the raw body
|
|
6
|
+
* - `X-Hypermid-Event`: event type (e.g. "swap.completed")
|
|
7
|
+
*
|
|
8
|
+
* Use `verifyWebhookSignature()` to validate incoming webhooks.
|
|
9
|
+
*
|
|
10
|
+
* @example Express / Node.js
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { verifyWebhookSignature } from "@hypermid/sdk";
|
|
13
|
+
*
|
|
14
|
+
* app.post("/webhooks/hypermid", express.raw({ type: "application/json" }), (req, res) => {
|
|
15
|
+
* const signature = req.headers["x-hypermid-signature"] as string;
|
|
16
|
+
* const isValid = verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET);
|
|
17
|
+
*
|
|
18
|
+
* if (!isValid) {
|
|
19
|
+
* return res.status(401).send("Invalid signature");
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const event = req.headers["x-hypermid-event"];
|
|
23
|
+
* const payload = JSON.parse(req.body.toString());
|
|
24
|
+
* // Handle event...
|
|
25
|
+
* res.sendStatus(200);
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Verify a webhook signature using HMAC-SHA256.
|
|
31
|
+
*
|
|
32
|
+
* Works in both Node.js (using `crypto`) and edge runtimes (using `SubtleCrypto`).
|
|
33
|
+
*
|
|
34
|
+
* @param body - The raw request body (string or Buffer/Uint8Array)
|
|
35
|
+
* @param signature - The `X-Hypermid-Signature` header value
|
|
36
|
+
* @param secret - Your webhook signing secret (from webhook creation)
|
|
37
|
+
* @returns `true` if the signature is valid
|
|
38
|
+
*/
|
|
39
|
+
export async function verifyWebhookSignature(body, signature, secret) {
|
|
40
|
+
const bodyStr = typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
41
|
+
// Try Node.js crypto first (synchronous, faster)
|
|
42
|
+
try {
|
|
43
|
+
const crypto = await import("node:crypto");
|
|
44
|
+
const expected = crypto
|
|
45
|
+
.createHmac("sha256", secret)
|
|
46
|
+
.update(bodyStr)
|
|
47
|
+
.digest("hex");
|
|
48
|
+
return timingSafeEqual(expected, signature);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Not in Node.js — use SubtleCrypto (edge runtimes, Deno, Bun)
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const encoder = new TextEncoder();
|
|
55
|
+
const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
56
|
+
const sig = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(bodyStr));
|
|
57
|
+
const expected = Array.from(new Uint8Array(sig))
|
|
58
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
59
|
+
.join("");
|
|
60
|
+
return timingSafeEqual(expected, signature);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Constant-time string comparison to prevent timing attacks */
|
|
67
|
+
function timingSafeEqual(a, b) {
|
|
68
|
+
if (a.length !== b.length)
|
|
69
|
+
return false;
|
|
70
|
+
let result = 0;
|
|
71
|
+
for (let i = 0; i < a.length; i++) {
|
|
72
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
73
|
+
}
|
|
74
|
+
return result === 0;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=webhook-verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-verify.js","sourceRoot":"","sources":["../src/webhook-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH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GAAG,CAAC,CAAC;aAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hypermid/sdk",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "TypeScript SDK for the HyperMid Partner API — swap, bridge & on-ramp across 90+ chains",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"hypermid",
|
|
27
|
+
"swap",
|
|
28
|
+
"bridge",
|
|
29
|
+
"cross-chain",
|
|
30
|
+
"defi",
|
|
31
|
+
"lifi",
|
|
32
|
+
"near-intents",
|
|
33
|
+
"onramp",
|
|
34
|
+
"web3"
|
|
35
|
+
],
|
|
36
|
+
"author": "HyperMid",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^25.5.0",
|
|
40
|
+
"typescript": "^5.5.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|