axiomax-esg-verify 1.0.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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AXIOMAX LLC, Salinas Puerto Rico
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ NOTE: The reference verifier code in this repository is MIT-licensed.
16
+ The AXIOMAX ESG Carbon Shield system architecture, calibration coefficients,
17
+ and brand are proprietary to AXIOMAX LLC and protected by USPTO Patent Pending
18
+ Application 64/081,419 (filed June 3, 2026).
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # axiomax-esg-verify
2
+
3
+ Reference verifier for [AXIOMAX ESG Carbon Shield](https://axiomaxllc.com) cryptographic carbon attestation tokens.
4
+
5
+ > Patent Pending USPTO Application **64/081,419** (filed June 3, 2026).
6
+ > Operated by **AXIOMAX LLC**, Salinas, Puerto Rico.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install axiomax-esg-verify
12
+ ```
13
+
14
+ Works in Node.js (>= 18) and modern browsers (Web Crypto API ed25519).
15
+
16
+ ## Usage
17
+
18
+ ```js
19
+ import { verifyToken } from 'axiomax-esg-verify';
20
+
21
+ const token = JSON.parse(fs.readFileSync('token.json', 'utf-8'));
22
+ const publicKeyPem = fs.readFileSync('client_public.pem', 'utf-8');
23
+
24
+ const result = await verifyToken(token, publicKeyPem);
25
+
26
+ if (result.valid) {
27
+ console.log(`✓ VALID · ${result.n_inferences} inferences certified · ${result.total_wh_saved} Wh saved`);
28
+ } else {
29
+ console.error(`✗ INVALID · ${result.reason}`);
30
+ }
31
+ ```
32
+
33
+ ## How it works
34
+
35
+ Every AXIOMAX ESG attestation token is signed with ed25519 against a per-client public key. This package implements the canonical verification algorithm:
36
+
37
+ 1. Remove the `signature_ed25519` field from the token
38
+ 2. Canonicalize the remaining JSON (sorted keys, minimal separators)
39
+ 3. Verify the ed25519 signature over those bytes using the client's public key
40
+
41
+ If any field in the token has been tampered with, the signature check fails.
42
+
43
+ ## Client public keys
44
+
45
+ Master and per-client public keys are published at https://github.com/axiomaxllc/esg-carbon-shield/tree/main/public_keys
46
+
47
+ ## License
48
+
49
+ MIT License for this package. The AXIOMAX ESG Carbon Shield system architecture, calibration coefficients, and brand are proprietary to AXIOMAX LLC (Patent Pending).
50
+
51
+ ## Links
52
+
53
+ - Main: https://axiomaxllc.com
54
+ - Hosted verifier: https://verify.axiomaxllc.com
55
+ - Browser-side mirror: https://axiomaxllc.github.io/esg-carbon-shield
56
+ - Specification: https://github.com/axiomaxllc/esg-carbon-shield
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "axiomax-esg-verify",
3
+ "version": "1.0.0",
4
+ "description": "Reference verifier for AXIOMAX ESG Carbon Shield cryptographic carbon attestation tokens (ed25519 + SHA-256). Patent Pending USPTO 64/081,419.",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node test/verify.test.js"
12
+ },
13
+ "keywords": [
14
+ "esg",
15
+ "climate-tech",
16
+ "carbon-accounting",
17
+ "cryptography",
18
+ "ed25519",
19
+ "ai",
20
+ "sustainability",
21
+ "csrd",
22
+ "sec-climate",
23
+ "verifier",
24
+ "axiomax"
25
+ ],
26
+ "author": "Charles Santana <charles@axiomaxllc.com> (https://axiomaxllc.com)",
27
+ "license": "MIT",
28
+ "homepage": "https://github.com/axiomaxllc/esg-carbon-shield",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/axiomaxllc/esg-carbon-shield.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/axiomaxllc/esg-carbon-shield/issues"
35
+ },
36
+ "files": [
37
+ "src/",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ }
44
+ }
package/src/index.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * AXIOMAX ESG Carbon Shield — Reference Verifier (Node.js + browser via Web Crypto).
3
+ *
4
+ * Patent Pending USPTO 64/081,419. AXIOMAX LLC, Salinas Puerto Rico.
5
+ * MIT License.
6
+ *
7
+ * Usage:
8
+ * import { verifyToken } from 'axiomax-esg-verify';
9
+ *
10
+ * const result = await verifyToken(tokenObj, publicKeyPem);
11
+ * if (result.valid) {
12
+ * console.log(`✓ ${result.n_inferences} inferences certified`);
13
+ * } else {
14
+ * console.error(`✗ ${result.reason}`);
15
+ * }
16
+ */
17
+
18
+ const isNode = typeof window === 'undefined';
19
+
20
+ function canonicalize(obj) {
21
+ if (obj === null || typeof obj !== 'object') return JSON.stringify(obj);
22
+ if (Array.isArray(obj)) return '[' + obj.map(canonicalize).join(',') + ']';
23
+ const keys = Object.keys(obj).sort();
24
+ return '{' + keys.map(k => JSON.stringify(k) + ':' + canonicalize(obj[k])).join(',') + '}';
25
+ }
26
+
27
+ function hexToBytes(hex) {
28
+ const bytes = new Uint8Array(hex.length / 2);
29
+ for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
30
+ return bytes;
31
+ }
32
+
33
+ function pemToBinary(pem) {
34
+ const b64 = pem.replace(/-----[^-]+-----/g, '').replace(/\s/g, '');
35
+ if (isNode) return Buffer.from(b64, 'base64');
36
+ const raw = atob(b64);
37
+ const bytes = new Uint8Array(raw.length);
38
+ for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
39
+ return bytes;
40
+ }
41
+
42
+ /**
43
+ * Verify an AXIOMAX ESG token against the client's public key.
44
+ *
45
+ * @param {object} token — token JSON object with signature_ed25519 field
46
+ * @param {string} publicKeyPem — client public key in PEM format
47
+ * @returns {Promise<{valid: boolean, reason?: string, client_id?: string, n_inferences?: number, total_wh_saved?: number, total_co2_kg_saved?: number}>}
48
+ */
49
+ export async function verifyToken(token, publicKeyPem) {
50
+ const required = ['v', 'client_id', 'signature_ed25519', 'first_hash', 'last_hash',
51
+ 'n_inferences', 'total_wh_saved', 'seq_first', 'seq_last'];
52
+ for (const k of required) {
53
+ if (!(k in token)) return { valid: false, reason: `missing field: ${k}` };
54
+ }
55
+
56
+ const sigHex = token.signature_ed25519;
57
+ const tokenCopy = { ...token };
58
+ delete tokenCopy.signature_ed25519;
59
+ const canonical = canonicalize(tokenCopy);
60
+ const sigBytes = hexToBytes(sigHex);
61
+ const msgBytes = new TextEncoder().encode(canonical);
62
+ const keyBytes = pemToBinary(publicKeyPem);
63
+
64
+ let ok;
65
+ if (isNode) {
66
+ const { createPublicKey, verify } = await import('node:crypto');
67
+ const key = createPublicKey({ key: Buffer.from(keyBytes), format: 'der', type: 'spki' });
68
+ ok = verify(null, msgBytes, key, sigBytes);
69
+ } else {
70
+ const key = await crypto.subtle.importKey('spki', keyBytes, { name: 'Ed25519' }, false, ['verify']);
71
+ ok = await crypto.subtle.verify('Ed25519', key, sigBytes, msgBytes);
72
+ }
73
+
74
+ if (!ok) return { valid: false, reason: 'signature does not match client public key' };
75
+
76
+ return {
77
+ valid: true,
78
+ client_id: token.client_id,
79
+ n_inferences: token.n_inferences,
80
+ total_tokens: token.total_tokens,
81
+ total_wh_saved: token.total_wh_saved,
82
+ total_liters_water_saved: token.total_liters_water_saved,
83
+ total_co2_kg_saved: token.total_co2_kg_saved,
84
+ ts_issued_utc: token.ts_issued_utc,
85
+ seq_first: token.seq_first,
86
+ seq_last: token.seq_last,
87
+ };
88
+ }
89
+
90
+ export default { verifyToken };