@agledger/sdk 1.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/LICENSE +34 -0
- package/README.md +209 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +68 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +114 -0
- package/dist/http.d.ts +47 -0
- package/dist/http.js +272 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +12 -0
- package/dist/resources/a2a.d.ts +22 -0
- package/dist/resources/a2a.js +33 -0
- package/dist/resources/admin.d.ts +39 -0
- package/dist/resources/admin.js +57 -0
- package/dist/resources/capabilities.d.ts +23 -0
- package/dist/resources/capabilities.js +21 -0
- package/dist/resources/compliance.d.ts +34 -0
- package/dist/resources/compliance.js +54 -0
- package/dist/resources/dashboard.d.ts +14 -0
- package/dist/resources/dashboard.js +20 -0
- package/dist/resources/disputes.d.ts +16 -0
- package/dist/resources/disputes.js +26 -0
- package/dist/resources/events.d.ts +21 -0
- package/dist/resources/events.js +22 -0
- package/dist/resources/health.d.ts +15 -0
- package/dist/resources/health.js +21 -0
- package/dist/resources/mandates.d.ts +48 -0
- package/dist/resources/mandates.js +89 -0
- package/dist/resources/notarize.d.ts +20 -0
- package/dist/resources/notarize.js +44 -0
- package/dist/resources/proxy.d.ts +74 -0
- package/dist/resources/proxy.js +149 -0
- package/dist/resources/receipts.d.ts +28 -0
- package/dist/resources/receipts.js +27 -0
- package/dist/resources/registration.d.ts +30 -0
- package/dist/resources/registration.js +39 -0
- package/dist/resources/reputation.d.ts +16 -0
- package/dist/resources/reputation.js +17 -0
- package/dist/resources/schemas.d.ts +20 -0
- package/dist/resources/schemas.js +24 -0
- package/dist/resources/verification.d.ts +13 -0
- package/dist/resources/verification.js +17 -0
- package/dist/resources/webhooks.d.ts +25 -0
- package/dist/resources/webhooks.js +37 -0
- package/dist/types.d.ts +1134 -0
- package/dist/types.js +6 -0
- package/dist/webhooks/verify.d.ts +37 -0
- package/dist/webhooks/verify.js +86 -0
- package/package.json +74 -0
package/dist/types.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AGLedger™ SDK — Webhook Signature Verification
|
|
3
|
+
* Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Separate export to avoid pulling node:crypto into browser bundles.
|
|
6
|
+
* Import via: import { verifySignature } from '@agledger/sdk/webhooks'
|
|
7
|
+
*/
|
|
8
|
+
export interface SignResult {
|
|
9
|
+
header: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
signature: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sign a payload (for testing purposes).
|
|
15
|
+
* Returns the header string, timestamp, and hex signature.
|
|
16
|
+
*/
|
|
17
|
+
export declare function signPayload(rawBody: string, secret: string, timestamp?: number): SignResult;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a webhook signature header into timestamp and signature(s).
|
|
20
|
+
* Format: t=<unix_ts>,v1=<hex>[,v1=<hex2>]
|
|
21
|
+
* Supports multiple v1 signatures for key rotation.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseSignatureHeader(header: string): {
|
|
24
|
+
timestamp: number;
|
|
25
|
+
signatures: string[];
|
|
26
|
+
} | null;
|
|
27
|
+
/**
|
|
28
|
+
* Verify a webhook signature.
|
|
29
|
+
*
|
|
30
|
+
* @param rawBody - The raw request body string
|
|
31
|
+
* @param header - The x-agledger-signature header value
|
|
32
|
+
* @param secrets - One or more webhook secrets (array for key rotation)
|
|
33
|
+
* @param toleranceSeconds - Max age in seconds (default/max: 300)
|
|
34
|
+
* @returns true if signature is valid and within tolerance
|
|
35
|
+
*/
|
|
36
|
+
export declare function verifySignature(rawBody: string, header: string, secrets: string | string[], toleranceSeconds?: number): boolean;
|
|
37
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AGLedger™ SDK — Webhook Signature Verification
|
|
3
|
+
* Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Separate export to avoid pulling node:crypto into browser bundles.
|
|
6
|
+
* Import via: import { verifySignature } from '@agledger/sdk/webhooks'
|
|
7
|
+
*/
|
|
8
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
9
|
+
const MAX_TOLERANCE_SECONDS = 300;
|
|
10
|
+
/**
|
|
11
|
+
* Sign a payload (for testing purposes).
|
|
12
|
+
* Returns the header string, timestamp, and hex signature.
|
|
13
|
+
*/
|
|
14
|
+
export function signPayload(rawBody, secret, timestamp) {
|
|
15
|
+
const ts = timestamp ?? Math.floor(Date.now() / 1000);
|
|
16
|
+
const signedPayload = `${ts}.${rawBody}`;
|
|
17
|
+
const signature = createHmac('sha256', secret)
|
|
18
|
+
.update(signedPayload)
|
|
19
|
+
.digest('hex');
|
|
20
|
+
return {
|
|
21
|
+
header: `t=${ts},v1=${signature}`,
|
|
22
|
+
timestamp: ts,
|
|
23
|
+
signature,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse a webhook signature header into timestamp and signature(s).
|
|
28
|
+
* Format: t=<unix_ts>,v1=<hex>[,v1=<hex2>]
|
|
29
|
+
* Supports multiple v1 signatures for key rotation.
|
|
30
|
+
*/
|
|
31
|
+
export function parseSignatureHeader(header) {
|
|
32
|
+
const parts = header.split(',');
|
|
33
|
+
let timestamp;
|
|
34
|
+
const signatures = [];
|
|
35
|
+
for (const part of parts) {
|
|
36
|
+
const [key, value] = part.split('=', 2);
|
|
37
|
+
if (!key || !value)
|
|
38
|
+
return null;
|
|
39
|
+
if (key.trim() === 't') {
|
|
40
|
+
timestamp = parseInt(value.trim(), 10);
|
|
41
|
+
if (isNaN(timestamp))
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
else if (key.trim() === 'v1') {
|
|
45
|
+
signatures.push(value.trim());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (timestamp === undefined || signatures.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
return { timestamp, signatures };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Verify a webhook signature.
|
|
54
|
+
*
|
|
55
|
+
* @param rawBody - The raw request body string
|
|
56
|
+
* @param header - The x-agledger-signature header value
|
|
57
|
+
* @param secrets - One or more webhook secrets (array for key rotation)
|
|
58
|
+
* @param toleranceSeconds - Max age in seconds (default/max: 300)
|
|
59
|
+
* @returns true if signature is valid and within tolerance
|
|
60
|
+
*/
|
|
61
|
+
export function verifySignature(rawBody, header, secrets, toleranceSeconds) {
|
|
62
|
+
const parsed = parseSignatureHeader(header);
|
|
63
|
+
if (!parsed)
|
|
64
|
+
return false;
|
|
65
|
+
const tolerance = Math.min(toleranceSeconds ?? MAX_TOLERANCE_SECONDS, MAX_TOLERANCE_SECONDS);
|
|
66
|
+
// Check timestamp freshness
|
|
67
|
+
const now = Math.floor(Date.now() / 1000);
|
|
68
|
+
if (Math.abs(now - parsed.timestamp) > tolerance)
|
|
69
|
+
return false;
|
|
70
|
+
const secretList = Array.isArray(secrets) ? secrets : [secrets];
|
|
71
|
+
const signedPayload = `${parsed.timestamp}.${rawBody}`;
|
|
72
|
+
for (const secret of secretList) {
|
|
73
|
+
const expected = createHmac('sha256', secret)
|
|
74
|
+
.update(signedPayload)
|
|
75
|
+
.digest('hex');
|
|
76
|
+
for (const sig of parsed.signatures) {
|
|
77
|
+
const sigBuf = Buffer.from(sig, 'hex');
|
|
78
|
+
const expectedBuf = Buffer.from(expected, 'hex');
|
|
79
|
+
if (sigBuf.length === expectedBuf.length && timingSafeEqual(sigBuf, expectedBuf)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=verify.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agledger/sdk",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "AGLedger™ SDK — Accountability and audit infrastructure for agentic systems.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./webhooks": {
|
|
15
|
+
"types": "./dist/webhooks/verify.d.ts",
|
|
16
|
+
"import": "./dist/webhooks/verify.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"!dist/__tests__",
|
|
22
|
+
"!dist/**/*.map",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
32
|
+
"lint": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "npm run build"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"agledger",
|
|
37
|
+
"agentic",
|
|
38
|
+
"accountability",
|
|
39
|
+
"audit",
|
|
40
|
+
"mandate",
|
|
41
|
+
"verification",
|
|
42
|
+
"governance",
|
|
43
|
+
"a2a",
|
|
44
|
+
"sdk",
|
|
45
|
+
"ai-agent",
|
|
46
|
+
"ai-governance",
|
|
47
|
+
"ai-safety",
|
|
48
|
+
"compliance",
|
|
49
|
+
"eu-ai-act",
|
|
50
|
+
"mcp",
|
|
51
|
+
"model-context-protocol"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/agledger-ai/sdk"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://agledger.ai",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/agledger-ai/sdk/issues"
|
|
60
|
+
},
|
|
61
|
+
"author": "AGLedger LLC",
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/node": "^22.0.0",
|
|
70
|
+
"prettier": "^3.4.0",
|
|
71
|
+
"typescript": "^5.7.0",
|
|
72
|
+
"vitest": "^3.0.0"
|
|
73
|
+
}
|
|
74
|
+
}
|