@stable_sea/sdk 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/README.md +69 -0
- package/dist/client.d.ts +47 -0
- package/dist/client.js +42 -0
- package/dist/gen/schema.d.ts +1861 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/webhooks.d.ts +5 -0
- package/dist/webhooks.js +30 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createStableSeaClient, type StableSeaClient, type StableSeaMutation, type StableSeaMutationOptions, } from "./client.js";
|
|
2
|
+
export type { StableSeaClientOptions } from "./client.js";
|
|
3
|
+
export type { components, operations, paths } from "./gen/schema.js";
|
|
4
|
+
export { verifyWebhookSignature, type VerifyWebhookSignatureOptions, } from "./webhooks.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export interface VerifyWebhookSignatureOptions {
|
|
2
|
+
now?: number;
|
|
3
|
+
toleranceSeconds?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function verifyWebhookSignature(rawBody: string | Uint8Array, signatureHeader: string, signingSecret: string, options?: VerifyWebhookSignatureOptions): boolean;
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export function verifyWebhookSignature(rawBody, signatureHeader, signingSecret, options = {}) {
|
|
3
|
+
const tolerance = options.toleranceSeconds ?? 300;
|
|
4
|
+
if (!Number.isFinite(tolerance) || tolerance < 0) {
|
|
5
|
+
throw new RangeError("toleranceSeconds must be a non-negative number");
|
|
6
|
+
}
|
|
7
|
+
const fields = signatureHeader.split(",").map((field) => field.split("=", 2));
|
|
8
|
+
const timestampText = fields.find(([name]) => name === "t")?.[1];
|
|
9
|
+
const signatures = fields
|
|
10
|
+
.filter(([name, value]) => name === "v1" && /^[0-9a-f]{64}$/i.test(value ?? ""))
|
|
11
|
+
.map(([, value]) => value);
|
|
12
|
+
if (!timestampText || !/^\d+$/.test(timestampText) || signatures.length === 0)
|
|
13
|
+
return false;
|
|
14
|
+
const timestamp = Number(timestampText);
|
|
15
|
+
const now = options.now ?? Date.now() / 1000;
|
|
16
|
+
if (!signingSecret || !Number.isSafeInteger(timestamp) || !Number.isFinite(now))
|
|
17
|
+
return false;
|
|
18
|
+
if (Math.abs(now - timestamp) > tolerance)
|
|
19
|
+
return false;
|
|
20
|
+
const expected = createHmac("sha256", signingSecret)
|
|
21
|
+
.update(`${timestampText}.`)
|
|
22
|
+
.update(rawBody)
|
|
23
|
+
.digest();
|
|
24
|
+
for (const signature of signatures) {
|
|
25
|
+
const candidate = Buffer.from(signature, "hex");
|
|
26
|
+
if (candidate.length === expected.length && timingSafeEqual(candidate, expected))
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stable_sea/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": "git+https://github.com/StableSea/monorepo.git",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && mkdir -p dist/gen && cp -f src/gen/schema.d.ts dist/gen/schema.d.ts",
|
|
25
|
+
"generate": "bash scripts/generate.sh",
|
|
26
|
+
"prepack": "npm run build",
|
|
27
|
+
"test": "npm run build && npm run test:unit && npm run test:consumer",
|
|
28
|
+
"test:consumer": "bash scripts/test-consumer.sh",
|
|
29
|
+
"test:unit": "vitest run --dir test",
|
|
30
|
+
"typecheck": "npm run build && tsc -p tsconfig.json",
|
|
31
|
+
"validate": "npm test && tsc -p tsconfig.json"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"openapi-fetch": "0.17.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "24.10.1",
|
|
38
|
+
"openapi-typescript": "7.13.0",
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
|
+
"vitest": "4.1.11"
|
|
41
|
+
},
|
|
42
|
+
"overrides": {
|
|
43
|
+
"js-yaml": "^5.2.3",
|
|
44
|
+
"nanoid": "^3.3.17"
|
|
45
|
+
}
|
|
46
|
+
}
|