@nextera.one/axis-server-sdk 1.2.1 → 1.4.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 +25 -0
- package/dist/bin/generate-keys.d.mts +2 -0
- package/dist/bin/generate-keys.d.ts +2 -0
- package/dist/bin/generate-keys.js +159 -0
- package/dist/bin/generate-keys.js.map +1 -0
- package/dist/bin/generate-keys.mjs +169 -0
- package/dist/bin/generate-keys.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -25
- package/dist/core/index.d.ts +2 -25
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +12 -0
- package/dist/core/index.mjs.map +1 -1
- package/dist/index-B5xzROld.d.mts +122 -0
- package/dist/index-B5xzROld.d.ts +122 -0
- package/dist/index.d.mts +1476 -10
- package/dist/index.d.ts +1476 -10
- package/dist/index.js +3086 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3064 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -13,8 +13,27 @@ npm install @nextera.one/axis-server-sdk
|
|
|
13
13
|
Peer dependencies:
|
|
14
14
|
|
|
15
15
|
- `@nestjs/common`
|
|
16
|
+
- `@nestjs/config`
|
|
16
17
|
- `reflect-metadata`
|
|
17
18
|
|
|
19
|
+
## Release Surface
|
|
20
|
+
|
|
21
|
+
The `1.3.0` release folds the backend server runtime namespaces that previously lived in temporary internal package shells into this published package.
|
|
22
|
+
|
|
23
|
+
Added grouped runtime namespaces:
|
|
24
|
+
|
|
25
|
+
- `core`
|
|
26
|
+
- `crypto`
|
|
27
|
+
- `decorators`
|
|
28
|
+
- `engine`
|
|
29
|
+
- `loom`
|
|
30
|
+
- `schemas`
|
|
31
|
+
- `security`
|
|
32
|
+
- `sensors`
|
|
33
|
+
- `utils`
|
|
34
|
+
|
|
35
|
+
It also exposes the `axis-generate-keys` CLI through the package `bin` entry for local key generation workflows.
|
|
36
|
+
|
|
18
37
|
## What It Exposes
|
|
19
38
|
|
|
20
39
|
Root exports are split into two groups:
|
|
@@ -22,6 +41,12 @@ Root exports are split into two groups:
|
|
|
22
41
|
- Server runtime helpers: `@Handler`, `@Intent`, `IntentRouter`, handler interfaces, sensor interfaces.
|
|
23
42
|
- Shared protocol primitives: binary frame codecs, TLV/varint/constants, binary signature helpers, codec utilities, packet types.
|
|
24
43
|
|
|
44
|
+
You can also import the grouped namespaces directly from the package root:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { core, crypto, engine, sensors } from '@nextera.one/axis-server-sdk';
|
|
48
|
+
```
|
|
49
|
+
|
|
25
50
|
## Shared Core API
|
|
26
51
|
|
|
27
52
|
The canonical cross-SDK protocol layer is the `./core` subpath:
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// src/bin/generate-keys.ts
|
|
2
|
+
var import_crypto = require("crypto");
|
|
3
|
+
var import_crypto2 = require("crypto");
|
|
4
|
+
function calculateFingerprint(publicKeyPem) {
|
|
5
|
+
const der = (0, import_crypto.createPublicKey)(publicKeyPem).export({
|
|
6
|
+
type: "spki",
|
|
7
|
+
format: "der"
|
|
8
|
+
});
|
|
9
|
+
return (0, import_crypto.createHash)("sha256").update(der).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
function generateUuid() {
|
|
12
|
+
const bytes = (0, import_crypto2.randomBytes)(16);
|
|
13
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
14
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
15
|
+
return bytes.toString("hex");
|
|
16
|
+
}
|
|
17
|
+
function generateIssuerKey() {
|
|
18
|
+
const { publicKey, privateKey } = (0, import_crypto.generateKeyPairSync)("ed25519");
|
|
19
|
+
const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
20
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
|
21
|
+
const fingerprint = calculateFingerprint(publicKeyPem);
|
|
22
|
+
const kid = `axis_issuer_${fingerprint.slice(0, 16)}`;
|
|
23
|
+
const uuid = generateUuid();
|
|
24
|
+
const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
25
|
+
const sql = `
|
|
26
|
+
-- AXIS Issuer Key
|
|
27
|
+
INSERT INTO axis_issuer_keys (
|
|
28
|
+
id, kid, issuer_id, alg, public_key_pem, status,
|
|
29
|
+
fingerprint, created_at, updated_at
|
|
30
|
+
) VALUES (
|
|
31
|
+
UNHEX('${uuid}'),
|
|
32
|
+
'${kid}',
|
|
33
|
+
'axis-capsule-service',
|
|
34
|
+
'EdDSA',
|
|
35
|
+
'${publicKeyPem.replace(/\n/g, "\\n")}',
|
|
36
|
+
'ACTIVE',
|
|
37
|
+
'${fingerprint}',
|
|
38
|
+
'${now}',
|
|
39
|
+
'${now}'
|
|
40
|
+
);`;
|
|
41
|
+
return {
|
|
42
|
+
kid,
|
|
43
|
+
publicKeyPem,
|
|
44
|
+
privateKeyPem,
|
|
45
|
+
fingerprint,
|
|
46
|
+
sql
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function generateActorKey(actorId) {
|
|
50
|
+
const { publicKey, privateKey } = (0, import_crypto.generateKeyPairSync)("ed25519");
|
|
51
|
+
const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
52
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
|
53
|
+
const der = publicKey.export({ type: "spki", format: "der" });
|
|
54
|
+
const publicKeyBytes = der.slice(-32);
|
|
55
|
+
const fingerprint = calculateFingerprint(publicKeyPem);
|
|
56
|
+
const kid = `${actorId}_${fingerprint.slice(0, 12)}`;
|
|
57
|
+
const uuid = generateUuid();
|
|
58
|
+
const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
59
|
+
const sql = `
|
|
60
|
+
-- AXIS Actor Key for ${actorId}
|
|
61
|
+
INSERT INTO axis_actor_keys (
|
|
62
|
+
id, actor_id, key_id, algorithm, public_key, purpose, status,
|
|
63
|
+
is_primary, created_at, updated_at
|
|
64
|
+
) VALUES (
|
|
65
|
+
UNHEX('${uuid}'),
|
|
66
|
+
'${actorId}',
|
|
67
|
+
'${kid}',
|
|
68
|
+
'ED25519',
|
|
69
|
+
UNHEX('${publicKeyBytes.toString("hex")}'),
|
|
70
|
+
'SIGN',
|
|
71
|
+
'ACTIVE',
|
|
72
|
+
1,
|
|
73
|
+
'${now}',
|
|
74
|
+
'${now}'
|
|
75
|
+
);`;
|
|
76
|
+
return {
|
|
77
|
+
kid,
|
|
78
|
+
publicKeyPem,
|
|
79
|
+
privateKeyPem,
|
|
80
|
+
fingerprint,
|
|
81
|
+
sql
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function main() {
|
|
85
|
+
const args = process.argv.slice(2);
|
|
86
|
+
const typeIndex = args.indexOf("--type");
|
|
87
|
+
const actorIdIndex = args.indexOf("--actor-id");
|
|
88
|
+
const type = typeIndex >= 0 ? args[typeIndex + 1] : "issuer";
|
|
89
|
+
const actorId = actorIdIndex >= 0 ? args[actorIdIndex + 1] : `actor_${Date.now()}`;
|
|
90
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
91
|
+
console.log(" AXIS Key Generator (Ed25519)");
|
|
92
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
93
|
+
console.log("");
|
|
94
|
+
let result;
|
|
95
|
+
if (type === "issuer") {
|
|
96
|
+
console.log("Generating ISSUER keypair...");
|
|
97
|
+
console.log("");
|
|
98
|
+
result = generateIssuerKey();
|
|
99
|
+
} else if (type === "actor") {
|
|
100
|
+
console.log(`Generating ACTOR keypair for: ${actorId}`);
|
|
101
|
+
console.log("");
|
|
102
|
+
result = generateActorKey(actorId);
|
|
103
|
+
} else {
|
|
104
|
+
console.error("Invalid type. Use --type issuer or --type actor");
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
console.log("\u2713 Keypair generated successfully");
|
|
108
|
+
console.log("");
|
|
109
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
110
|
+
console.log("KID (Key Identifier):");
|
|
111
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
112
|
+
console.log(result.kid);
|
|
113
|
+
console.log("");
|
|
114
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
115
|
+
console.log("Fingerprint (SHA-256):");
|
|
116
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
117
|
+
console.log(result.fingerprint);
|
|
118
|
+
console.log("");
|
|
119
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
120
|
+
console.log("PUBLIC KEY (PEM):");
|
|
121
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
122
|
+
console.log(result.publicKeyPem);
|
|
123
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
124
|
+
console.log("PRIVATE KEY (PEM):");
|
|
125
|
+
console.log("\u26A0\uFE0F KEEP SECRET - Do not commit to version control");
|
|
126
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
127
|
+
console.log(result.privateKeyPem);
|
|
128
|
+
if (type === "issuer") {
|
|
129
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
130
|
+
console.log("Environment Variables (add to .env):");
|
|
131
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
132
|
+
console.log(`AXIS_ISSUER_KID=${result.kid}`);
|
|
133
|
+
console.log(`AXIS_ISSUER_ALG=EdDSA`);
|
|
134
|
+
console.log(
|
|
135
|
+
`AXIS_ISSUER_PRIVATE_KEY_PEM="${result.privateKeyPem.replace(/\n/g, "\\n")}"`
|
|
136
|
+
);
|
|
137
|
+
console.log("");
|
|
138
|
+
}
|
|
139
|
+
if (result.sql) {
|
|
140
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
141
|
+
console.log("SQL INSERT Statement:");
|
|
142
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
143
|
+
console.log(result.sql);
|
|
144
|
+
}
|
|
145
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
146
|
+
console.log("");
|
|
147
|
+
console.log("Next steps:");
|
|
148
|
+
if (type === "issuer") {
|
|
149
|
+
console.log("1. Add environment variables to .env");
|
|
150
|
+
console.log("2. Run SQL statement to insert public key into database");
|
|
151
|
+
console.log("3. Store private key securely (Vault/KMS in production)");
|
|
152
|
+
} else {
|
|
153
|
+
console.log("1. Run SQL statement to insert actor key into database");
|
|
154
|
+
console.log("2. Distribute private key securely to actor/device");
|
|
155
|
+
}
|
|
156
|
+
console.log("");
|
|
157
|
+
}
|
|
158
|
+
main();
|
|
159
|
+
//# sourceMappingURL=generate-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/generate-keys.ts"],"sourcesContent":["/**\n * AXIS Key Generator\n *\n * Generates Ed25519 keypairs for AXIS issuer and actors\n * For development and testing only - use proper KMS/Vault in production\n *\n * Usage:\n * npm run generate-keys -- --type issuer\n * npm run generate-keys -- --type actor --actor-id user_123\n */\nimport { createHash, createPublicKey, generateKeyPairSync } from 'crypto';\nimport { randomBytes } from 'crypto';\n\ninterface KeyPairResult {\n kid: string;\n publicKeyPem: string;\n privateKeyPem: string;\n fingerprint: string;\n sql?: string;\n}\n\n/**\n * Calculate SHA-256 fingerprint of public key\n */\nfunction calculateFingerprint(publicKeyPem: string): string {\n const der = createPublicKey(publicKeyPem).export({\n type: 'spki',\n format: 'der',\n }) as Buffer;\n return createHash('sha256').update(der).digest('hex');\n}\n\n/**\n * Generate UUID v4 as binary hex for MySQL\n */\nfunction generateUuid(): string {\n const bytes = randomBytes(16);\n bytes[6] = (bytes[6] & 0x0f) | 0x40; // Version 4\n bytes[8] = (bytes[8] & 0x3f) | 0x80; // Variant\n return bytes.toString('hex');\n}\n\n/**\n * Generate Ed25519 keypair for AXIS issuer\n */\nfunction generateIssuerKey(): KeyPairResult {\n const { publicKey, privateKey } = generateKeyPairSync('ed25519');\n\n const publicKeyPem = publicKey\n .export({ type: 'spki', format: 'pem' })\n .toString();\n const privateKeyPem = privateKey\n .export({ type: 'pkcs8', format: 'pem' })\n .toString();\n\n const fingerprint = calculateFingerprint(publicKeyPem);\n const kid = `axis_issuer_${fingerprint.slice(0, 16)}`;\n\n const uuid = generateUuid();\n const now = new Date().toISOString().slice(0, 19).replace('T', ' ');\n\n const sql = `\n-- AXIS Issuer Key\nINSERT INTO axis_issuer_keys (\n id, kid, issuer_id, alg, public_key_pem, status, \n fingerprint, created_at, updated_at\n) VALUES (\n UNHEX('${uuid}'),\n '${kid}',\n 'axis-capsule-service',\n 'EdDSA',\n '${publicKeyPem.replace(/\\n/g, '\\\\n')}',\n 'ACTIVE',\n '${fingerprint}',\n '${now}',\n '${now}'\n);`;\n\n return {\n kid,\n publicKeyPem,\n privateKeyPem,\n fingerprint,\n sql,\n };\n}\n\n/**\n * Generate Ed25519 keypair for AXIS actor\n */\nfunction generateActorKey(actorId: string): KeyPairResult {\n const { publicKey, privateKey } = generateKeyPairSync('ed25519');\n\n const publicKeyPem = publicKey\n .export({ type: 'spki', format: 'pem' })\n .toString();\n const privateKeyPem = privateKey\n .export({ type: 'pkcs8', format: 'pem' })\n .toString();\n\n // Extract raw public key bytes (32 bytes for Ed25519)\n const der = publicKey.export({ type: 'spki', format: 'der' }) as Buffer;\n const publicKeyBytes = der.slice(-32); // Last 32 bytes are the raw key\n\n const fingerprint = calculateFingerprint(publicKeyPem);\n const kid = `${actorId}_${fingerprint.slice(0, 12)}`;\n\n const uuid = generateUuid();\n const now = new Date().toISOString().slice(0, 19).replace('T', ' ');\n\n const sql = `\n-- AXIS Actor Key for ${actorId}\nINSERT INTO axis_actor_keys (\n id, actor_id, key_id, algorithm, public_key, purpose, status,\n is_primary, created_at, updated_at\n) VALUES (\n UNHEX('${uuid}'),\n '${actorId}',\n '${kid}',\n 'ED25519',\n UNHEX('${publicKeyBytes.toString('hex')}'),\n 'SIGN',\n 'ACTIVE',\n 1,\n '${now}',\n '${now}'\n);`;\n\n return {\n kid,\n publicKeyPem,\n privateKeyPem,\n fingerprint,\n sql,\n };\n}\n\n/**\n * Main function\n */\nfunction main() {\n const args = process.argv.slice(2);\n const typeIndex = args.indexOf('--type');\n const actorIdIndex = args.indexOf('--actor-id');\n\n const type = typeIndex >= 0 ? args[typeIndex + 1] : 'issuer';\n const actorId =\n actorIdIndex >= 0 ? args[actorIdIndex + 1] : `actor_${Date.now()}`;\n\n console.log('═══════════════════════════════════════════════════════════');\n console.log(' AXIS Key Generator (Ed25519)');\n console.log('═══════════════════════════════════════════════════════════');\n console.log('');\n\n let result: KeyPairResult;\n\n if (type === 'issuer') {\n console.log('Generating ISSUER keypair...');\n console.log('');\n result = generateIssuerKey();\n } else if (type === 'actor') {\n console.log(`Generating ACTOR keypair for: ${actorId}`);\n console.log('');\n result = generateActorKey(actorId);\n } else {\n console.error('Invalid type. Use --type issuer or --type actor');\n process.exit(1);\n }\n\n console.log('✓ Keypair generated successfully');\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('KID (Key Identifier):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.kid);\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('Fingerprint (SHA-256):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.fingerprint);\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('PUBLIC KEY (PEM):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.publicKeyPem);\n console.log('───────────────────────────────────────────────────────────');\n console.log('PRIVATE KEY (PEM):');\n console.log('⚠️ KEEP SECRET - Do not commit to version control');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.privateKeyPem);\n\n if (type === 'issuer') {\n console.log('───────────────────────────────────────────────────────────');\n console.log('Environment Variables (add to .env):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(`AXIS_ISSUER_KID=${result.kid}`);\n console.log(`AXIS_ISSUER_ALG=EdDSA`);\n console.log(\n `AXIS_ISSUER_PRIVATE_KEY_PEM=\"${result.privateKeyPem.replace(/\\n/g, '\\\\n')}\"`,\n );\n console.log('');\n }\n\n if (result.sql) {\n console.log('───────────────────────────────────────────────────────────');\n console.log('SQL INSERT Statement:');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.sql);\n }\n\n console.log('═══════════════════════════════════════════════════════════');\n console.log('');\n console.log('Next steps:');\n if (type === 'issuer') {\n console.log('1. Add environment variables to .env');\n console.log('2. Run SQL statement to insert public key into database');\n console.log('3. Store private key securely (Vault/KMS in production)');\n } else {\n console.log('1. Run SQL statement to insert actor key into database');\n console.log('2. Distribute private key securely to actor/device');\n }\n console.log('');\n}\n\nmain();\n"],"mappings":";AAUA,oBAAiE;AACjE,IAAAA,iBAA4B;AAa5B,SAAS,qBAAqB,cAA8B;AAC1D,QAAM,UAAM,+BAAgB,YAAY,EAAE,OAAO;AAAA,IAC/C,MAAM;AAAA,IACN,QAAQ;AAAA,EACV,CAAC;AACD,aAAO,0BAAW,QAAQ,EAAE,OAAO,GAAG,EAAE,OAAO,KAAK;AACtD;AAKA,SAAS,eAAuB;AAC9B,QAAM,YAAQ,4BAAY,EAAE;AAC5B,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,QAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,SAAO,MAAM,SAAS,KAAK;AAC7B;AAKA,SAAS,oBAAmC;AAC1C,QAAM,EAAE,WAAW,WAAW,QAAI,mCAAoB,SAAS;AAE/D,QAAM,eAAe,UAClB,OAAO,EAAE,MAAM,QAAQ,QAAQ,MAA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AC9B,UAAQ,IAAI,EAAE;AACd,UAAQ,IAAI,oWAA6D;AACzE,UAAQ,IAAI,mBAAmB;AAC/B,UAAQ,IAAI,oWAA6D;AACzE,UAAQ,IAAI,OAAO,YAAY;AAC/B,UAAQ,IAAI,oWAA6D;AACzE,UAAQ,IAAI,oBAAoB;AAChC,UAAQ,IAAI,8DAAoD;AAChE,UAAQ,IAAI,oWAA6D;AACzE,UAAQ,IAAI,OAAO,aAAa;AAEhC,MAAI,SAAS,UAAU;AACrB,YAAQ,IAAI,oWAA6D;AACzE,YAAQ,IAAI,sCAAsC;AAClD,YAAQ,IAAI,oWAA6D;AACzE,YAAQ,IAAI,mBAAmB,OAAO,GAAG,EAAE;AAC3C,YAAQ,IAAI,uBAAuB;AACnC,YAAQ;AAAA,MACN,gCAAgC,OAAO,cAAc,QAAQ,OAAO,KAAK,CAAC;AAAA,IAC5E;AACA,YAAQ,IAAI,EAAE;AAAA,EAChB;AAEA,MAAI,OAAO,KAAK;AACd,YAAQ,IAAI,oWAA6D;AACzE,YAAQ,IAAI,uBAAuB;AACnC,YAAQ,IAAI,oWAA6D;AACzE,YAAQ,IAAI,OAAO,GAAG;AAAA,EACxB;AAEA,UAAQ,IAAI,oWAA6D;AACzE,UAAQ,IAAI,EAAE;AACd,UAAQ,IAAI,aAAa;AACzB,MAAI,SAAS,UAAU;AACrB,YAAQ,IAAI,sCAAsC;AAClD,YAAQ,IAAI,yDAAyD;AACrE,YAAQ,IAAI,yDAAyD;AAAA,EACvE,OAAO;AACL,YAAQ,IAAI,wDAAwD;AACpE,YAAQ,IAAI,oDAAoD;AAAA,EAClE;AACA,UAAQ,IAAI,EAAE;AAChB;AAEA,KAAK;","names":["import_crypto"]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// src/bin/generate-keys.ts
|
|
7
|
+
import { createHash, createPublicKey, generateKeyPairSync } from "crypto";
|
|
8
|
+
import { randomBytes } from "crypto";
|
|
9
|
+
var require_generate_keys = __commonJS({
|
|
10
|
+
"src/bin/generate-keys.ts"() {
|
|
11
|
+
function calculateFingerprint(publicKeyPem) {
|
|
12
|
+
const der = createPublicKey(publicKeyPem).export({
|
|
13
|
+
type: "spki",
|
|
14
|
+
format: "der"
|
|
15
|
+
});
|
|
16
|
+
return createHash("sha256").update(der).digest("hex");
|
|
17
|
+
}
|
|
18
|
+
function generateUuid() {
|
|
19
|
+
const bytes = randomBytes(16);
|
|
20
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
21
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
22
|
+
return bytes.toString("hex");
|
|
23
|
+
}
|
|
24
|
+
function generateIssuerKey() {
|
|
25
|
+
const { publicKey, privateKey } = generateKeyPairSync("ed25519");
|
|
26
|
+
const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
27
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
|
28
|
+
const fingerprint = calculateFingerprint(publicKeyPem);
|
|
29
|
+
const kid = `axis_issuer_${fingerprint.slice(0, 16)}`;
|
|
30
|
+
const uuid = generateUuid();
|
|
31
|
+
const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
32
|
+
const sql = `
|
|
33
|
+
-- AXIS Issuer Key
|
|
34
|
+
INSERT INTO axis_issuer_keys (
|
|
35
|
+
id, kid, issuer_id, alg, public_key_pem, status,
|
|
36
|
+
fingerprint, created_at, updated_at
|
|
37
|
+
) VALUES (
|
|
38
|
+
UNHEX('${uuid}'),
|
|
39
|
+
'${kid}',
|
|
40
|
+
'axis-capsule-service',
|
|
41
|
+
'EdDSA',
|
|
42
|
+
'${publicKeyPem.replace(/\n/g, "\\n")}',
|
|
43
|
+
'ACTIVE',
|
|
44
|
+
'${fingerprint}',
|
|
45
|
+
'${now}',
|
|
46
|
+
'${now}'
|
|
47
|
+
);`;
|
|
48
|
+
return {
|
|
49
|
+
kid,
|
|
50
|
+
publicKeyPem,
|
|
51
|
+
privateKeyPem,
|
|
52
|
+
fingerprint,
|
|
53
|
+
sql
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function generateActorKey(actorId) {
|
|
57
|
+
const { publicKey, privateKey } = generateKeyPairSync("ed25519");
|
|
58
|
+
const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
59
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
|
60
|
+
const der = publicKey.export({ type: "spki", format: "der" });
|
|
61
|
+
const publicKeyBytes = der.slice(-32);
|
|
62
|
+
const fingerprint = calculateFingerprint(publicKeyPem);
|
|
63
|
+
const kid = `${actorId}_${fingerprint.slice(0, 12)}`;
|
|
64
|
+
const uuid = generateUuid();
|
|
65
|
+
const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
66
|
+
const sql = `
|
|
67
|
+
-- AXIS Actor Key for ${actorId}
|
|
68
|
+
INSERT INTO axis_actor_keys (
|
|
69
|
+
id, actor_id, key_id, algorithm, public_key, purpose, status,
|
|
70
|
+
is_primary, created_at, updated_at
|
|
71
|
+
) VALUES (
|
|
72
|
+
UNHEX('${uuid}'),
|
|
73
|
+
'${actorId}',
|
|
74
|
+
'${kid}',
|
|
75
|
+
'ED25519',
|
|
76
|
+
UNHEX('${publicKeyBytes.toString("hex")}'),
|
|
77
|
+
'SIGN',
|
|
78
|
+
'ACTIVE',
|
|
79
|
+
1,
|
|
80
|
+
'${now}',
|
|
81
|
+
'${now}'
|
|
82
|
+
);`;
|
|
83
|
+
return {
|
|
84
|
+
kid,
|
|
85
|
+
publicKeyPem,
|
|
86
|
+
privateKeyPem,
|
|
87
|
+
fingerprint,
|
|
88
|
+
sql
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function main() {
|
|
92
|
+
const args = process.argv.slice(2);
|
|
93
|
+
const typeIndex = args.indexOf("--type");
|
|
94
|
+
const actorIdIndex = args.indexOf("--actor-id");
|
|
95
|
+
const type = typeIndex >= 0 ? args[typeIndex + 1] : "issuer";
|
|
96
|
+
const actorId = actorIdIndex >= 0 ? args[actorIdIndex + 1] : `actor_${Date.now()}`;
|
|
97
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
98
|
+
console.log(" AXIS Key Generator (Ed25519)");
|
|
99
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
100
|
+
console.log("");
|
|
101
|
+
let result;
|
|
102
|
+
if (type === "issuer") {
|
|
103
|
+
console.log("Generating ISSUER keypair...");
|
|
104
|
+
console.log("");
|
|
105
|
+
result = generateIssuerKey();
|
|
106
|
+
} else if (type === "actor") {
|
|
107
|
+
console.log(`Generating ACTOR keypair for: ${actorId}`);
|
|
108
|
+
console.log("");
|
|
109
|
+
result = generateActorKey(actorId);
|
|
110
|
+
} else {
|
|
111
|
+
console.error("Invalid type. Use --type issuer or --type actor");
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
console.log("\u2713 Keypair generated successfully");
|
|
115
|
+
console.log("");
|
|
116
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
117
|
+
console.log("KID (Key Identifier):");
|
|
118
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
119
|
+
console.log(result.kid);
|
|
120
|
+
console.log("");
|
|
121
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
122
|
+
console.log("Fingerprint (SHA-256):");
|
|
123
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
124
|
+
console.log(result.fingerprint);
|
|
125
|
+
console.log("");
|
|
126
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
127
|
+
console.log("PUBLIC KEY (PEM):");
|
|
128
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
129
|
+
console.log(result.publicKeyPem);
|
|
130
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
131
|
+
console.log("PRIVATE KEY (PEM):");
|
|
132
|
+
console.log("\u26A0\uFE0F KEEP SECRET - Do not commit to version control");
|
|
133
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
134
|
+
console.log(result.privateKeyPem);
|
|
135
|
+
if (type === "issuer") {
|
|
136
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
137
|
+
console.log("Environment Variables (add to .env):");
|
|
138
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
139
|
+
console.log(`AXIS_ISSUER_KID=${result.kid}`);
|
|
140
|
+
console.log(`AXIS_ISSUER_ALG=EdDSA`);
|
|
141
|
+
console.log(
|
|
142
|
+
`AXIS_ISSUER_PRIVATE_KEY_PEM="${result.privateKeyPem.replace(/\n/g, "\\n")}"`
|
|
143
|
+
);
|
|
144
|
+
console.log("");
|
|
145
|
+
}
|
|
146
|
+
if (result.sql) {
|
|
147
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
148
|
+
console.log("SQL INSERT Statement:");
|
|
149
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
150
|
+
console.log(result.sql);
|
|
151
|
+
}
|
|
152
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
153
|
+
console.log("");
|
|
154
|
+
console.log("Next steps:");
|
|
155
|
+
if (type === "issuer") {
|
|
156
|
+
console.log("1. Add environment variables to .env");
|
|
157
|
+
console.log("2. Run SQL statement to insert public key into database");
|
|
158
|
+
console.log("3. Store private key securely (Vault/KMS in production)");
|
|
159
|
+
} else {
|
|
160
|
+
console.log("1. Run SQL statement to insert actor key into database");
|
|
161
|
+
console.log("2. Distribute private key securely to actor/device");
|
|
162
|
+
}
|
|
163
|
+
console.log("");
|
|
164
|
+
}
|
|
165
|
+
main();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
export default require_generate_keys();
|
|
169
|
+
//# sourceMappingURL=generate-keys.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/generate-keys.ts"],"sourcesContent":["/**\n * AXIS Key Generator\n *\n * Generates Ed25519 keypairs for AXIS issuer and actors\n * For development and testing only - use proper KMS/Vault in production\n *\n * Usage:\n * npm run generate-keys -- --type issuer\n * npm run generate-keys -- --type actor --actor-id user_123\n */\nimport { createHash, createPublicKey, generateKeyPairSync } from 'crypto';\nimport { randomBytes } from 'crypto';\n\ninterface KeyPairResult {\n kid: string;\n publicKeyPem: string;\n privateKeyPem: string;\n fingerprint: string;\n sql?: string;\n}\n\n/**\n * Calculate SHA-256 fingerprint of public key\n */\nfunction calculateFingerprint(publicKeyPem: string): string {\n const der = createPublicKey(publicKeyPem).export({\n type: 'spki',\n format: 'der',\n }) as Buffer;\n return createHash('sha256').update(der).digest('hex');\n}\n\n/**\n * Generate UUID v4 as binary hex for MySQL\n */\nfunction generateUuid(): string {\n const bytes = randomBytes(16);\n bytes[6] = (bytes[6] & 0x0f) | 0x40; // Version 4\n bytes[8] = (bytes[8] & 0x3f) | 0x80; // Variant\n return bytes.toString('hex');\n}\n\n/**\n * Generate Ed25519 keypair for AXIS issuer\n */\nfunction generateIssuerKey(): KeyPairResult {\n const { publicKey, privateKey } = generateKeyPairSync('ed25519');\n\n const publicKeyPem = publicKey\n .export({ type: 'spki', format: 'pem' })\n .toString();\n const privateKeyPem = privateKey\n .export({ type: 'pkcs8', format: 'pem' })\n .toString();\n\n const fingerprint = calculateFingerprint(publicKeyPem);\n const kid = `axis_issuer_${fingerprint.slice(0, 16)}`;\n\n const uuid = generateUuid();\n const now = new Date().toISOString().slice(0, 19).replace('T', ' ');\n\n const sql = `\n-- AXIS Issuer Key\nINSERT INTO axis_issuer_keys (\n id, kid, issuer_id, alg, public_key_pem, status, \n fingerprint, created_at, updated_at\n) VALUES (\n UNHEX('${uuid}'),\n '${kid}',\n 'axis-capsule-service',\n 'EdDSA',\n '${publicKeyPem.replace(/\\n/g, '\\\\n')}',\n 'ACTIVE',\n '${fingerprint}',\n '${now}',\n '${now}'\n);`;\n\n return {\n kid,\n publicKeyPem,\n privateKeyPem,\n fingerprint,\n sql,\n };\n}\n\n/**\n * Generate Ed25519 keypair for AXIS actor\n */\nfunction generateActorKey(actorId: string): KeyPairResult {\n const { publicKey, privateKey } = generateKeyPairSync('ed25519');\n\n const publicKeyPem = publicKey\n .export({ type: 'spki', format: 'pem' })\n .toString();\n const privateKeyPem = privateKey\n .export({ type: 'pkcs8', format: 'pem' })\n .toString();\n\n // Extract raw public key bytes (32 bytes for Ed25519)\n const der = publicKey.export({ type: 'spki', format: 'der' }) as Buffer;\n const publicKeyBytes = der.slice(-32); // Last 32 bytes are the raw key\n\n const fingerprint = calculateFingerprint(publicKeyPem);\n const kid = `${actorId}_${fingerprint.slice(0, 12)}`;\n\n const uuid = generateUuid();\n const now = new Date().toISOString().slice(0, 19).replace('T', ' ');\n\n const sql = `\n-- AXIS Actor Key for ${actorId}\nINSERT INTO axis_actor_keys (\n id, actor_id, key_id, algorithm, public_key, purpose, status,\n is_primary, created_at, updated_at\n) VALUES (\n UNHEX('${uuid}'),\n '${actorId}',\n '${kid}',\n 'ED25519',\n UNHEX('${publicKeyBytes.toString('hex')}'),\n 'SIGN',\n 'ACTIVE',\n 1,\n '${now}',\n '${now}'\n);`;\n\n return {\n kid,\n publicKeyPem,\n privateKeyPem,\n fingerprint,\n sql,\n };\n}\n\n/**\n * Main function\n */\nfunction main() {\n const args = process.argv.slice(2);\n const typeIndex = args.indexOf('--type');\n const actorIdIndex = args.indexOf('--actor-id');\n\n const type = typeIndex >= 0 ? args[typeIndex + 1] : 'issuer';\n const actorId =\n actorIdIndex >= 0 ? args[actorIdIndex + 1] : `actor_${Date.now()}`;\n\n console.log('═══════════════════════════════════════════════════════════');\n console.log(' AXIS Key Generator (Ed25519)');\n console.log('═══════════════════════════════════════════════════════════');\n console.log('');\n\n let result: KeyPairResult;\n\n if (type === 'issuer') {\n console.log('Generating ISSUER keypair...');\n console.log('');\n result = generateIssuerKey();\n } else if (type === 'actor') {\n console.log(`Generating ACTOR keypair for: ${actorId}`);\n console.log('');\n result = generateActorKey(actorId);\n } else {\n console.error('Invalid type. Use --type issuer or --type actor');\n process.exit(1);\n }\n\n console.log('✓ Keypair generated successfully');\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('KID (Key Identifier):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.kid);\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('Fingerprint (SHA-256):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.fingerprint);\n console.log('');\n console.log('───────────────────────────────────────────────────────────');\n console.log('PUBLIC KEY (PEM):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.publicKeyPem);\n console.log('───────────────────────────────────────────────────────────');\n console.log('PRIVATE KEY (PEM):');\n console.log('⚠️ KEEP SECRET - Do not commit to version control');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.privateKeyPem);\n\n if (type === 'issuer') {\n console.log('───────────────────────────────────────────────────────────');\n console.log('Environment Variables (add to .env):');\n console.log('───────────────────────────────────────────────────────────');\n console.log(`AXIS_ISSUER_KID=${result.kid}`);\n console.log(`AXIS_ISSUER_ALG=EdDSA`);\n console.log(\n `AXIS_ISSUER_PRIVATE_KEY_PEM=\"${result.privateKeyPem.replace(/\\n/g, '\\\\n')}\"`,\n );\n console.log('');\n }\n\n if (result.sql) {\n console.log('───────────────────────────────────────────────────────────');\n console.log('SQL INSERT Statement:');\n console.log('───────────────────────────────────────────────────────────');\n console.log(result.sql);\n }\n\n console.log('═══════════════════════════════════════════════════════════');\n console.log('');\n console.log('Next steps:');\n if (type === 'issuer') {\n console.log('1. Add environment variables to .env');\n console.log('2. Run SQL statement to insert public key into database');\n console.log('3. Store private key securely (Vault/KMS in production)');\n } else {\n console.log('1. Run SQL statement to insert actor key into database');\n console.log('2. Distribute private key securely to actor/device');\n }\n console.log('');\n}\n\nmain();\n"],"mappings":";;;;;;AAUA,SAAS,YAAY,iBAAiB,2BAA2B;AACjE,SAAS,mBAAmB;AAX5B;AAAA;AAwBA,aAAS,qBAAqB,cAA8B;AAC1D,YAAM,MAAM,gBAAgB,YAAY,EAAE,OAAO;AAAA,QAC/C,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AACD,aAAO,WAAW,QAAQ,EAAE,OAAO,GAAG,EAAE,OAAO,KAAK;AAAA,IACtD;AAKA,aAAS,eAAuB;AAC9B,YAAM,QAAQ,YAAY,EAAE;AAC5B,YAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,YAAM,CAAC,IAAK,MAAM,CAAC,IAAI,KAAQ;AAC/B,aAAO,MAAM,SAAS,KAAK;AAAA,IAC7B;AAKA,aAAS,oBAAmC;AAC1C,YAAM,EAAE,WAAW,WAAW,IAAI,oBAAoB,SAAS;AAE/D,YAAM,eAAe,UAClB,OAAO,EAAE,MAAM,QAAQ,QAAQ,MAAM,CAAC,EACtC,SAAS;AACZ,YAAM,gBAAgB,WACnB,OAAO,EAAE,MAAM,SAAS,QAAQ,MAAM,CAAC,EACvC,SAAS;AAEZ,YAAM,cAAc,qBAAqB,YAAY;AACrD,YAAM,MAAM,eAAe,YAAY,MAAM,GAAG,EAAE,CAAC;AAEnD,YAAM,OAAO,aAAa;AAC1B,YAAM,OAAM,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,KAAK,GAAG;AAElE,YAAM,MAAM;AAAA;AAAA;AAAA;AAAA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oWAA6D;AACzE,gBAAQ,IAAI,sCAAsC;AAClD,gBAAQ,IAAI,oWAA6D;AACzE,gBAAQ,IAAI,mBAAmB,OAAO,GAAG,EAAE;AAC3C,gBAAQ,IAAI,uBAAuB;AACnC,gBAAQ;AAAA,UACN,gCAAgC,OAAO,cAAc,QAAQ,OAAO,KAAK,CAAC;AAAA,QAC5E;AACA,gBAAQ,IAAI,EAAE;AAAA,MAChB;AAEA,UAAI,OAAO,KAAK;AACd,gBAAQ,IAAI,oWAA6D;AACzE,gBAAQ,IAAI,uBAAuB;AACnC,gBAAQ,IAAI,oWAA6D;AACzE,gBAAQ,IAAI,OAAO,GAAG;AAAA,MACxB;AAEA,cAAQ,IAAI,oWAA6D;AACzE,cAAQ,IAAI,EAAE;AACd,cAAQ,IAAI,aAAa;AACzB,UAAI,SAAS,UAAU;AACrB,gBAAQ,IAAI,sCAAsC;AAClD,gBAAQ,IAAI,yDAAyD;AACrE,gBAAQ,IAAI,yDAAyD;AAAA,MACvE,OAAO;AACL,gBAAQ,IAAI,wDAAwD;AACpE,gBAAQ,IAAI,oDAAoD;AAAA,MAClE;AACA,cAAQ,IAAI,EAAE;AAAA,IAChB;AAEA,SAAK;AAAA;AAAA;","names":[]}
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
1
|
export { AXIS_MAGIC, AXIS_VERSION, BodyProfile, ERR_BAD_SIGNATURE, ERR_CONTRACT_VIOLATION, ERR_INVALID_PACKET, ERR_REPLAY_DETECTED, FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS, MAX_BODY_LEN, MAX_FRAME_LEN, MAX_HDR_LEN, MAX_SIG_LEN, NCERT_ALG, NCERT_EXP, NCERT_ISSUER_KID, NCERT_KID, NCERT_NBF, NCERT_NODE_ID, NCERT_PAYLOAD, NCERT_PUB, NCERT_SCOPE, NCERT_SIG, PROOF_CAPSULE, PROOF_JWT, PROOF_LOOM, PROOF_MTLS, PROOF_NONE, PROOF_WITNESS, ProofType, TLV, TLV_ACTOR_ID, TLV_AUD, TLV_BODY_ARR, TLV_BODY_OBJ, TLV_CAPSULE, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG, TLV_INDEX, TLV_INTENT, TLV_KID, TLV_LOOM_PRESENCE_ID, TLV_LOOM_THREAD_HASH, TLV_LOOM_WRIT, TLV_NODE, TLV_NODE_CERT_HASH, TLV_NODE_KID, TLV_NONCE, TLV_OFFSET, TLV_OK, TLV_PID, TLV_PREV_HASH, TLV_PROOF_REF, TLV_PROOF_TYPE, TLV_REALM, TLV_RECEIPT_HASH, TLV_RID, TLV_SHA256_CHUNK, TLV_TRACE_ID, TLV_TS, TLV_UPLOAD_ID, decodeArray, decodeObject, decodeTLVs, decodeTLVsList, decodeVarint, encodeTLVs, encodeVarint, varintLength } from '@nextera.one/axis-protocol';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const AxisFrameZ: z.ZodObject<{
|
|
5
|
-
flags: z.ZodNumber;
|
|
6
|
-
headers: z.ZodMap<z.ZodNumber, z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
|
|
7
|
-
body: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
8
|
-
sig: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
9
|
-
}, z.core.$strip>;
|
|
10
|
-
type AxisFrame = z.infer<typeof AxisFrameZ>;
|
|
11
|
-
type AxisBinaryFrame = AxisFrame;
|
|
12
|
-
declare function encodeFrame(frame: AxisFrame): Uint8Array;
|
|
13
|
-
declare function decodeFrame(buf: Uint8Array): AxisFrame;
|
|
14
|
-
declare function getSignTarget(frame: AxisFrame): Uint8Array;
|
|
15
|
-
|
|
16
|
-
declare function computeSignaturePayload(frame: AxisFrame): Buffer;
|
|
17
|
-
declare function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer;
|
|
18
|
-
declare function verifyFrameSignature(frame: AxisFrame, publicKey: Buffer): boolean;
|
|
19
|
-
declare function generateEd25519KeyPair(): {
|
|
20
|
-
privateKey: Buffer;
|
|
21
|
-
publicKey: Buffer;
|
|
22
|
-
};
|
|
23
|
-
declare function sha256(data: Buffer | Uint8Array): Buffer;
|
|
24
|
-
declare function computeReceiptHash(receiptBytes: Buffer | Uint8Array, prevHash?: Buffer | Uint8Array): Buffer;
|
|
25
|
-
|
|
26
|
-
export { type AxisBinaryFrame, type AxisFrame, AxisFrameZ, computeReceiptHash, computeSignaturePayload, decodeFrame, encodeFrame, generateEd25519KeyPair, getSignTarget, sha256, signFrame, verifyFrameSignature };
|
|
2
|
+
export { a as AxisBinaryFrame, k as AxisError, A as AxisFrame, b as AxisFrameZ, c as computeReceiptHash, d as computeSignaturePayload, e as decodeFrame, f as encodeFrame, g as generateEd25519KeyPair, h as getSignTarget, s as sha256, j as signFrame, v as verifyFrameSignature } from '../index-B5xzROld.mjs';
|
|
3
|
+
import 'zod';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
1
|
export { AXIS_MAGIC, AXIS_VERSION, BodyProfile, ERR_BAD_SIGNATURE, ERR_CONTRACT_VIOLATION, ERR_INVALID_PACKET, ERR_REPLAY_DETECTED, FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS, MAX_BODY_LEN, MAX_FRAME_LEN, MAX_HDR_LEN, MAX_SIG_LEN, NCERT_ALG, NCERT_EXP, NCERT_ISSUER_KID, NCERT_KID, NCERT_NBF, NCERT_NODE_ID, NCERT_PAYLOAD, NCERT_PUB, NCERT_SCOPE, NCERT_SIG, PROOF_CAPSULE, PROOF_JWT, PROOF_LOOM, PROOF_MTLS, PROOF_NONE, PROOF_WITNESS, ProofType, TLV, TLV_ACTOR_ID, TLV_AUD, TLV_BODY_ARR, TLV_BODY_OBJ, TLV_CAPSULE, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG, TLV_INDEX, TLV_INTENT, TLV_KID, TLV_LOOM_PRESENCE_ID, TLV_LOOM_THREAD_HASH, TLV_LOOM_WRIT, TLV_NODE, TLV_NODE_CERT_HASH, TLV_NODE_KID, TLV_NONCE, TLV_OFFSET, TLV_OK, TLV_PID, TLV_PREV_HASH, TLV_PROOF_REF, TLV_PROOF_TYPE, TLV_REALM, TLV_RECEIPT_HASH, TLV_RID, TLV_SHA256_CHUNK, TLV_TRACE_ID, TLV_TS, TLV_UPLOAD_ID, decodeArray, decodeObject, decodeTLVs, decodeTLVsList, decodeVarint, encodeTLVs, encodeVarint, varintLength } from '@nextera.one/axis-protocol';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const AxisFrameZ: z.ZodObject<{
|
|
5
|
-
flags: z.ZodNumber;
|
|
6
|
-
headers: z.ZodMap<z.ZodNumber, z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
|
|
7
|
-
body: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
8
|
-
sig: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
9
|
-
}, z.core.$strip>;
|
|
10
|
-
type AxisFrame = z.infer<typeof AxisFrameZ>;
|
|
11
|
-
type AxisBinaryFrame = AxisFrame;
|
|
12
|
-
declare function encodeFrame(frame: AxisFrame): Uint8Array;
|
|
13
|
-
declare function decodeFrame(buf: Uint8Array): AxisFrame;
|
|
14
|
-
declare function getSignTarget(frame: AxisFrame): Uint8Array;
|
|
15
|
-
|
|
16
|
-
declare function computeSignaturePayload(frame: AxisFrame): Buffer;
|
|
17
|
-
declare function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer;
|
|
18
|
-
declare function verifyFrameSignature(frame: AxisFrame, publicKey: Buffer): boolean;
|
|
19
|
-
declare function generateEd25519KeyPair(): {
|
|
20
|
-
privateKey: Buffer;
|
|
21
|
-
publicKey: Buffer;
|
|
22
|
-
};
|
|
23
|
-
declare function sha256(data: Buffer | Uint8Array): Buffer;
|
|
24
|
-
declare function computeReceiptHash(receiptBytes: Buffer | Uint8Array, prevHash?: Buffer | Uint8Array): Buffer;
|
|
25
|
-
|
|
26
|
-
export { type AxisBinaryFrame, type AxisFrame, AxisFrameZ, computeReceiptHash, computeSignaturePayload, decodeFrame, encodeFrame, generateEd25519KeyPair, getSignTarget, sha256, signFrame, verifyFrameSignature };
|
|
2
|
+
export { a as AxisBinaryFrame, k as AxisError, A as AxisFrame, b as AxisFrameZ, c as computeReceiptHash, d as computeSignaturePayload, e as decodeFrame, f as encodeFrame, g as generateEd25519KeyPair, h as getSignTarget, s as sha256, j as signFrame, v as verifyFrameSignature } from '../index-B5xzROld.js';
|
|
3
|
+
import 'zod';
|
package/dist/core/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var core_exports = {};
|
|
|
31
31
|
__export(core_exports, {
|
|
32
32
|
AXIS_MAGIC: () => import_axis_protocol.AXIS_MAGIC,
|
|
33
33
|
AXIS_VERSION: () => import_axis_protocol.AXIS_VERSION,
|
|
34
|
+
AxisError: () => AxisError,
|
|
34
35
|
AxisFrameZ: () => AxisFrameZ,
|
|
35
36
|
BodyProfile: () => import_axis_protocol.BodyProfile,
|
|
36
37
|
ERR_BAD_SIGNATURE: () => import_axis_protocol.ERR_BAD_SIGNATURE,
|
|
@@ -336,10 +337,22 @@ function computeReceiptHash(receiptBytes, prevHash) {
|
|
|
336
337
|
}
|
|
337
338
|
return hasher.digest();
|
|
338
339
|
}
|
|
340
|
+
|
|
341
|
+
// src/core/axis-error.ts
|
|
342
|
+
var AxisError = class extends Error {
|
|
343
|
+
constructor(code, message, httpStatus = 400, details) {
|
|
344
|
+
super(message);
|
|
345
|
+
this.code = code;
|
|
346
|
+
this.httpStatus = httpStatus;
|
|
347
|
+
this.details = details;
|
|
348
|
+
this.name = "AxisError";
|
|
349
|
+
}
|
|
350
|
+
};
|
|
339
351
|
// Annotate the CommonJS export names for ESM import in node:
|
|
340
352
|
0 && (module.exports = {
|
|
341
353
|
AXIS_MAGIC,
|
|
342
354
|
AXIS_VERSION,
|
|
355
|
+
AxisError,
|
|
343
356
|
AxisFrameZ,
|
|
344
357
|
BodyProfile,
|
|
345
358
|
ERR_BAD_SIGNATURE,
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts","../../src/core/constants.ts","../../src/core/varint.ts","../../src/core/tlv.ts","../../src/core/axis-bin.ts","../../src/core/signature.ts"],"sourcesContent":["export * from './constants';\nexport * from './varint';\nexport * from './tlv';\nexport * from './axis-bin';\nexport * from './signature';\n","export {\n AXIS_MAGIC, AXIS_VERSION,\n MAX_HDR_LEN, MAX_BODY_LEN, MAX_SIG_LEN, MAX_FRAME_LEN,\n FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS,\n TLV_PID, TLV_TS, TLV_INTENT, TLV_ACTOR_ID, TLV_PROOF_TYPE,\n TLV_PROOF_REF, TLV_NONCE, TLV_AUD, TLV_REALM, TLV_NODE,\n TLV_TRACE_ID, TLV_KID,\n TLV_RID, TLV_OK, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG,\n TLV_PREV_HASH, TLV_RECEIPT_HASH, TLV_NODE_KID, TLV_NODE_CERT_HASH,\n TLV_LOOM_PRESENCE_ID, TLV_LOOM_WRIT, TLV_LOOM_THREAD_HASH,\n TLV_UPLOAD_ID, TLV_INDEX, TLV_OFFSET, TLV_SHA256_CHUNK, TLV_CAPSULE,\n TLV_BODY_OBJ, TLV_BODY_ARR,\n NCERT_NODE_ID, NCERT_KID, NCERT_ALG, NCERT_PUB, NCERT_NBF,\n NCERT_EXP, NCERT_SCOPE, NCERT_ISSUER_KID, NCERT_PAYLOAD, NCERT_SIG,\n PROOF_NONE, PROOF_CAPSULE, PROOF_JWT, PROOF_MTLS, PROOF_LOOM, PROOF_WITNESS,\n ProofType, BodyProfile,\n ERR_INVALID_PACKET, ERR_BAD_SIGNATURE, ERR_REPLAY_DETECTED, ERR_CONTRACT_VIOLATION,\n} from '@nextera.one/axis-protocol';\n","export { encodeVarint, decodeVarint, varintLength } from '@nextera.one/axis-protocol';\n","export {\n TLV, encodeTLVs, decodeTLVs, decodeTLVsList, decodeObject, decodeArray,\n} from '@nextera.one/axis-protocol';\n","import * as z from 'zod';\n\n/**\n * AxisFrame Schema\n *\n * Defines the logical structure of an AXIS frame using Zod for runtime validation.\n * This is used for internal processing after the low-level binary parsing is complete.\n */\nexport const AxisFrameZ = z.object({\n /** Flag bits for protocol control (e.g., encryption, compression) */\n flags: z.number().int().nonnegative(),\n /** A map of TLV headers where key=Tag and value=BinaryData */\n headers: z.map(\n z.number(),\n z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n ),\n /** The main payload of the frame */\n body: z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n /** The cryptographic signature covering the frame (except the signature itself) */\n sig: z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n});\n\n/**\n * Represents a structured AXIS frame.\n * @typedef {Object} AxisFrame\n */\nexport type AxisFrame = z.infer<typeof AxisFrameZ>;\nexport type AxisBinaryFrame = AxisFrame;\nimport {\n AXIS_MAGIC,\n AXIS_VERSION,\n MAX_BODY_LEN,\n MAX_FRAME_LEN,\n MAX_HDR_LEN,\n MAX_SIG_LEN,\n} from './constants';\nimport { decodeTLVs, encodeTLVs } from './tlv';\nimport { decodeVarint, encodeVarint } from './varint';\n\n/**\n * Encodes a structured AxisFrame into its binary wire representation.\n *\n * **Encoding Steps:**\n * 1. Encodes header TLV map into a single buffer.\n * 2. Validates lengths against MAX_* constants.\n * 3. Encodes lengths (HDR, BODY, SIG) as varints.\n * 4. Assembles the final byte array with magic, version, and flags.\n *\n * @param {AxisFrame} frame - The structured frame to encode\n * @returns {Uint8Array} The full binary frame\n * @throws {Error} If any section exceeds protocol limits\n */\nexport function encodeFrame(frame: AxisFrame): Uint8Array {\n const hdrBytes = encodeTLVs(\n Array.from(frame.headers.entries()).map(([t, v]) => ({\n type: t,\n value: v,\n })),\n );\n\n if (hdrBytes.length > MAX_HDR_LEN) throw new Error('Header too large');\n if (frame.body.length > MAX_BODY_LEN) throw new Error('Body too large');\n if (frame.sig.length > MAX_SIG_LEN) throw new Error('Signature too large');\n\n // Header Len, Body Len, Sig Len\n const hdrLenBytes = encodeVarint(hdrBytes.length);\n const bodyLenBytes = encodeVarint(frame.body.length);\n const sigLenBytes = encodeVarint(frame.sig.length);\n\n const totalLen =\n 5 + // Magic (AXIS1)\n 1 + // Version\n 1 + // Flags\n hdrLenBytes.length +\n bodyLenBytes.length +\n sigLenBytes.length +\n hdrBytes.length +\n frame.body.length +\n frame.sig.length;\n\n if (totalLen > MAX_FRAME_LEN) throw new Error('Total frame too large');\n\n const buf = new Uint8Array(totalLen);\n let offset = 0;\n\n // Magic (AXIS1 - 5 bytes)\n buf.set(AXIS_MAGIC, offset);\n offset += 5;\n\n // Version\n buf[offset++] = AXIS_VERSION;\n\n // Flags\n buf[offset++] = frame.flags;\n\n // Lengths\n buf.set(hdrLenBytes, offset);\n offset += hdrLenBytes.length;\n\n buf.set(bodyLenBytes, offset);\n offset += bodyLenBytes.length;\n\n buf.set(sigLenBytes, offset);\n offset += sigLenBytes.length;\n\n // Payloads\n buf.set(hdrBytes, offset);\n offset += hdrBytes.length;\n\n buf.set(frame.body, offset);\n offset += frame.body.length;\n\n buf.set(frame.sig, offset);\n offset += frame.sig.length;\n\n return buf;\n}\n\n/**\n * Decodes a binary buffer into a structured AxisFrame with strict validation.\n *\n * @param {Uint8Array} buf - Raw bytes from the wire\n * @returns {AxisFrame} The parsed and validated frame\n * @throws {Error} If magic, version, or lengths are invalid\n */\nexport function decodeFrame(buf: Uint8Array): AxisFrame {\n let offset = 0;\n\n // 1. Magic (AXIS1 - 5 bytes)\n if (offset + 5 > buf.length) throw new Error('Packet too short');\n for (let i = 0; i < 5; i++) {\n if (buf[offset + i] !== AXIS_MAGIC[i]) throw new Error('Invalid Magic');\n }\n offset += 5;\n\n // 2. Version\n const ver = buf[offset++];\n if (ver !== AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);\n\n // 3. Flags\n const flags = buf[offset++];\n\n // 4. Lengths\n const { value: hdrLen, length: hlLen } = decodeVarint(buf, offset);\n offset += hlLen;\n if (hdrLen > MAX_HDR_LEN) throw new Error('Header limit exceeded');\n\n const { value: bodyLen, length: blLen } = decodeVarint(buf, offset);\n offset += blLen;\n if (bodyLen > MAX_BODY_LEN) throw new Error('Body limit exceeded');\n\n const { value: sigLen, length: slLen } = decodeVarint(buf, offset);\n offset += slLen;\n if (sigLen > MAX_SIG_LEN) throw new Error('Signature limit exceeded');\n\n // 5. Extract Bytes\n if (offset + hdrLen + bodyLen + sigLen > buf.length) {\n throw new Error('Frame truncated');\n }\n\n const hdrBytes = buf.slice(offset, offset + hdrLen);\n offset += hdrLen;\n\n const bodyBytes = buf.slice(offset, offset + bodyLen);\n offset += bodyLen;\n\n const sigBytes = buf.slice(offset, offset + sigLen);\n offset += sigLen;\n\n // 6. Decode Header TLVs\n const headers = decodeTLVs(hdrBytes);\n\n return {\n flags,\n headers,\n body: bodyBytes,\n sig: sigBytes,\n };\n}\n\n/**\n * Helper to get canonical bytes for signing.\n * SigTarget = All bytes up to SigLen, with SigLen=0, and no SigBytes.\n */\nexport function getSignTarget(frame: AxisFrame): Uint8Array {\n // Re-encode frame but with empty signature\n // Note: This is efficient enough for v1 (tens of KB).\n return encodeFrame({\n ...frame,\n sig: new Uint8Array(0),\n });\n}\n","import * as crypto from 'crypto';\n\nimport { AxisFrame, encodeFrame } from './axis-bin';\n\n/**\n * Signature utilities for AXIS binary frames\n * Supports Ed25519 signature generation and verification\n */\n\n/**\n * Computes the canonical payload for signing an AXIS frame.\n * The signature covers all bytes of the encoded frame EXCEPT the signature field itself.\n *\n * @param {AxisFrame} frame - The frame to prepare for signing\n * @returns {Buffer} The serialized canonical bytes for the signature algorithm\n */\nexport function computeSignaturePayload(frame: AxisFrame): Buffer {\n // Re-encode frame with empty signature\n const frameWithoutSig: AxisFrame = {\n ...frame,\n sig: new Uint8Array(0),\n };\n\n const encoded = encodeFrame(frameWithoutSig);\n return Buffer.from(encoded);\n}\n\n/**\n * Signs an AXIS frame using the Ed25519 algorithm.\n * Automatically handles both raw 32-byte seeds and pkcs8 DER-encoded private keys.\n *\n * @param {AxisFrame} frame - The frame to sign\n * @param {Buffer} privateKey - Ed25519 private key (32-byte raw OR pkcs8 DER)\n * @returns {Buffer} The 64-byte Ed25519 signature\n * @throws {Error} If key format is invalid or signing fail\n */\nexport function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer {\n const payload = computeSignaturePayload(frame);\n\n let keyObject: crypto.KeyObject;\n\n // Check if key is raw 32-byte seed or DER-encoded\n if (privateKey.length === 32) {\n // Raw seed - wrap in pkcs8 DER format\n // pkcs8 prefix for Ed25519: 0x302e020100300506032b657004220420\n const pkcs8Prefix = Buffer.from([\n 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,\n 0x04, 0x22, 0x04, 0x20,\n ]);\n const pkcs8Key = Buffer.concat([pkcs8Prefix, privateKey]);\n\n keyObject = crypto.createPrivateKey({\n key: pkcs8Key,\n format: 'der',\n type: 'pkcs8',\n });\n } else {\n // Assume already DER-encoded pkcs8\n keyObject = crypto.createPrivateKey({\n key: privateKey,\n format: 'der',\n type: 'pkcs8',\n });\n }\n\n const signature = crypto.sign(null, payload, keyObject);\n\n if (signature.length !== 64) {\n throw new Error('Ed25519 signature must be 64 bytes');\n }\n\n return signature;\n}\n\n/**\n * Verifies an Ed25519 signature on an AXIS frame.\n * Automatically handles both raw 32-byte public keys and spki DER-encoded public keys.\n *\n * @param {AxisFrame} frame - The frame containing the signature to verify\n * @param {Buffer} publicKey - Ed25519 public key (32-byte raw OR spki DER)\n * @returns {boolean} True if the signature is cryptographically valid\n * @throws {Error} If signature length is invalid\n */\nexport function verifyFrameSignature(\n frame: AxisFrame,\n publicKey: Buffer,\n): boolean {\n if (frame.sig.length === 0) {\n return false; // No signature\n }\n\n if (frame.sig.length !== 64) {\n throw new Error('Ed25519 signature must be 64 bytes');\n }\n\n const payload = computeSignaturePayload(frame);\n\n try {\n let keyObject: crypto.KeyObject;\n\n // Check if key is raw 32-byte or DER-encoded\n if (publicKey.length === 32) {\n // Raw key - wrap in spki DER format\n // spki prefix for Ed25519: 0x302a300506032b6570032100\n const spkiPrefix = Buffer.from([\n 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00,\n ]);\n const spkiKey = Buffer.concat([spkiPrefix, publicKey]);\n\n keyObject = crypto.createPublicKey({\n key: spkiKey,\n format: 'der',\n type: 'spki',\n });\n } else {\n // Assume already DER-encoded spki\n keyObject = crypto.createPublicKey({\n key: publicKey,\n format: 'der',\n type: 'spki',\n });\n }\n\n const valid = crypto.verify(\n null,\n payload,\n keyObject,\n Buffer.from(frame.sig),\n );\n return valid;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Generates a new Ed25519 key pair for use with the AXIS protocol.\n * Returns keys in canonical DER format (pkcs8 for private, spki for public).\n *\n * @returns {Object} An object containing the privateKey and publicKey as Buffers\n */\nexport function generateEd25519KeyPair(): {\n privateKey: Buffer;\n publicKey: Buffer;\n} {\n const { privateKey, publicKey } = crypto.generateKeyPairSync('ed25519');\n\n return {\n privateKey: privateKey.export({ type: 'pkcs8', format: 'der' }) as Buffer,\n publicKey: publicKey.export({ type: 'spki', format: 'der' }) as Buffer,\n };\n}\n\n/**\n * Computes a standard SHA-256 hash of the provided data.\n *\n * @param {Buffer | Uint8Array} data - The input data to hash\n * @returns {Buffer} The 32-byte SHA-256 digest\n */\nexport function sha256(data: Buffer | Uint8Array): Buffer {\n return crypto.createHash('sha256').update(data).digest();\n}\n\n/**\n * Computes a hash for an AXIS receipt, optionally chaining it to a previous hash.\n * This is used for generating an immutable transaction chain.\n *\n * @param {Buffer | Uint8Array} receiptBytes - The canonical binary representation of the receipt\n * @param {Buffer | Uint8Array} [prevHash] - The hash of the previous receipt in the chain\n * @returns {Buffer} The 32-byte SHA-256 hash of the receipt (and link)\n */\nexport function computeReceiptHash(\n receiptBytes: Buffer | Uint8Array,\n prevHash?: Buffer | Uint8Array,\n): Buffer {\n const hasher = crypto.createHash('sha256');\n hasher.update(receiptBytes);\n\n if (prevHash && prevHash.length > 0) {\n hasher.update(prevHash);\n }\n\n return hasher.digest();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAiBO;;;ACjBP,IAAAA,wBAAyD;;;ACAzD,IAAAC,wBAEO;;;ACFP,QAAmB;AAQZ,IAAM,aAAe,SAAO;AAAA;AAAA,EAEjC,OAAS,SAAO,EAAE,IAAI,EAAE,YAAY;AAAA;AAAA,EAEpC,SAAW;AAAA,IACP,SAAO;AAAA,IACP,SAAmB,CAAC,MAAM,aAAa,UAAU;AAAA,EACrD;AAAA;AAAA,EAEA,MAAQ,SAAmB,CAAC,MAAM,aAAa,UAAU;AAAA;AAAA,EAEzD,KAAO,SAAmB,CAAC,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/core/index.ts","../../src/core/constants.ts","../../src/core/varint.ts","../../src/core/tlv.ts","../../src/core/axis-bin.ts","../../src/core/signature.ts","../../src/core/axis-error.ts"],"sourcesContent":["export * from './constants';\nexport * from './varint';\nexport * from './tlv';\nexport * from './axis-bin';\nexport * from './signature';\nexport * from './axis-error';\n","export {\n AXIS_MAGIC, AXIS_VERSION,\n MAX_HDR_LEN, MAX_BODY_LEN, MAX_SIG_LEN, MAX_FRAME_LEN,\n FLAG_BODY_TLV, FLAG_CHAIN_REQ, FLAG_HAS_WITNESS,\n TLV_PID, TLV_TS, TLV_INTENT, TLV_ACTOR_ID, TLV_PROOF_TYPE,\n TLV_PROOF_REF, TLV_NONCE, TLV_AUD, TLV_REALM, TLV_NODE,\n TLV_TRACE_ID, TLV_KID,\n TLV_RID, TLV_OK, TLV_EFFECT, TLV_ERROR_CODE, TLV_ERROR_MSG,\n TLV_PREV_HASH, TLV_RECEIPT_HASH, TLV_NODE_KID, TLV_NODE_CERT_HASH,\n TLV_LOOM_PRESENCE_ID, TLV_LOOM_WRIT, TLV_LOOM_THREAD_HASH,\n TLV_UPLOAD_ID, TLV_INDEX, TLV_OFFSET, TLV_SHA256_CHUNK, TLV_CAPSULE,\n TLV_BODY_OBJ, TLV_BODY_ARR,\n NCERT_NODE_ID, NCERT_KID, NCERT_ALG, NCERT_PUB, NCERT_NBF,\n NCERT_EXP, NCERT_SCOPE, NCERT_ISSUER_KID, NCERT_PAYLOAD, NCERT_SIG,\n PROOF_NONE, PROOF_CAPSULE, PROOF_JWT, PROOF_MTLS, PROOF_LOOM, PROOF_WITNESS,\n ProofType, BodyProfile,\n ERR_INVALID_PACKET, ERR_BAD_SIGNATURE, ERR_REPLAY_DETECTED, ERR_CONTRACT_VIOLATION,\n} from '@nextera.one/axis-protocol';\n","export { encodeVarint, decodeVarint, varintLength } from '@nextera.one/axis-protocol';\n","export {\n TLV, encodeTLVs, decodeTLVs, decodeTLVsList, decodeObject, decodeArray,\n} from '@nextera.one/axis-protocol';\n","import * as z from 'zod';\n\n/**\n * AxisFrame Schema\n *\n * Defines the logical structure of an AXIS frame using Zod for runtime validation.\n * This is used for internal processing after the low-level binary parsing is complete.\n */\nexport const AxisFrameZ = z.object({\n /** Flag bits for protocol control (e.g., encryption, compression) */\n flags: z.number().int().nonnegative(),\n /** A map of TLV headers where key=Tag and value=BinaryData */\n headers: z.map(\n z.number(),\n z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n ),\n /** The main payload of the frame */\n body: z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n /** The cryptographic signature covering the frame (except the signature itself) */\n sig: z.custom<Uint8Array>((v) => v instanceof Uint8Array),\n});\n\n/**\n * Represents a structured AXIS frame.\n * @typedef {Object} AxisFrame\n */\nexport type AxisFrame = z.infer<typeof AxisFrameZ>;\nexport type AxisBinaryFrame = AxisFrame;\nimport {\n AXIS_MAGIC,\n AXIS_VERSION,\n MAX_BODY_LEN,\n MAX_FRAME_LEN,\n MAX_HDR_LEN,\n MAX_SIG_LEN,\n} from './constants';\nimport { decodeTLVs, encodeTLVs } from './tlv';\nimport { decodeVarint, encodeVarint } from './varint';\n\n/**\n * Encodes a structured AxisFrame into its binary wire representation.\n *\n * **Encoding Steps:**\n * 1. Encodes header TLV map into a single buffer.\n * 2. Validates lengths against MAX_* constants.\n * 3. Encodes lengths (HDR, BODY, SIG) as varints.\n * 4. Assembles the final byte array with magic, version, and flags.\n *\n * @param {AxisFrame} frame - The structured frame to encode\n * @returns {Uint8Array} The full binary frame\n * @throws {Error} If any section exceeds protocol limits\n */\nexport function encodeFrame(frame: AxisFrame): Uint8Array {\n const hdrBytes = encodeTLVs(\n Array.from(frame.headers.entries()).map(([t, v]) => ({\n type: t,\n value: v,\n })),\n );\n\n if (hdrBytes.length > MAX_HDR_LEN) throw new Error('Header too large');\n if (frame.body.length > MAX_BODY_LEN) throw new Error('Body too large');\n if (frame.sig.length > MAX_SIG_LEN) throw new Error('Signature too large');\n\n // Header Len, Body Len, Sig Len\n const hdrLenBytes = encodeVarint(hdrBytes.length);\n const bodyLenBytes = encodeVarint(frame.body.length);\n const sigLenBytes = encodeVarint(frame.sig.length);\n\n const totalLen =\n 5 + // Magic (AXIS1)\n 1 + // Version\n 1 + // Flags\n hdrLenBytes.length +\n bodyLenBytes.length +\n sigLenBytes.length +\n hdrBytes.length +\n frame.body.length +\n frame.sig.length;\n\n if (totalLen > MAX_FRAME_LEN) throw new Error('Total frame too large');\n\n const buf = new Uint8Array(totalLen);\n let offset = 0;\n\n // Magic (AXIS1 - 5 bytes)\n buf.set(AXIS_MAGIC, offset);\n offset += 5;\n\n // Version\n buf[offset++] = AXIS_VERSION;\n\n // Flags\n buf[offset++] = frame.flags;\n\n // Lengths\n buf.set(hdrLenBytes, offset);\n offset += hdrLenBytes.length;\n\n buf.set(bodyLenBytes, offset);\n offset += bodyLenBytes.length;\n\n buf.set(sigLenBytes, offset);\n offset += sigLenBytes.length;\n\n // Payloads\n buf.set(hdrBytes, offset);\n offset += hdrBytes.length;\n\n buf.set(frame.body, offset);\n offset += frame.body.length;\n\n buf.set(frame.sig, offset);\n offset += frame.sig.length;\n\n return buf;\n}\n\n/**\n * Decodes a binary buffer into a structured AxisFrame with strict validation.\n *\n * @param {Uint8Array} buf - Raw bytes from the wire\n * @returns {AxisFrame} The parsed and validated frame\n * @throws {Error} If magic, version, or lengths are invalid\n */\nexport function decodeFrame(buf: Uint8Array): AxisFrame {\n let offset = 0;\n\n // 1. Magic (AXIS1 - 5 bytes)\n if (offset + 5 > buf.length) throw new Error('Packet too short');\n for (let i = 0; i < 5; i++) {\n if (buf[offset + i] !== AXIS_MAGIC[i]) throw new Error('Invalid Magic');\n }\n offset += 5;\n\n // 2. Version\n const ver = buf[offset++];\n if (ver !== AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);\n\n // 3. Flags\n const flags = buf[offset++];\n\n // 4. Lengths\n const { value: hdrLen, length: hlLen } = decodeVarint(buf, offset);\n offset += hlLen;\n if (hdrLen > MAX_HDR_LEN) throw new Error('Header limit exceeded');\n\n const { value: bodyLen, length: blLen } = decodeVarint(buf, offset);\n offset += blLen;\n if (bodyLen > MAX_BODY_LEN) throw new Error('Body limit exceeded');\n\n const { value: sigLen, length: slLen } = decodeVarint(buf, offset);\n offset += slLen;\n if (sigLen > MAX_SIG_LEN) throw new Error('Signature limit exceeded');\n\n // 5. Extract Bytes\n if (offset + hdrLen + bodyLen + sigLen > buf.length) {\n throw new Error('Frame truncated');\n }\n\n const hdrBytes = buf.slice(offset, offset + hdrLen);\n offset += hdrLen;\n\n const bodyBytes = buf.slice(offset, offset + bodyLen);\n offset += bodyLen;\n\n const sigBytes = buf.slice(offset, offset + sigLen);\n offset += sigLen;\n\n // 6. Decode Header TLVs\n const headers = decodeTLVs(hdrBytes);\n\n return {\n flags,\n headers,\n body: bodyBytes,\n sig: sigBytes,\n };\n}\n\n/**\n * Helper to get canonical bytes for signing.\n * SigTarget = All bytes up to SigLen, with SigLen=0, and no SigBytes.\n */\nexport function getSignTarget(frame: AxisFrame): Uint8Array {\n // Re-encode frame but with empty signature\n // Note: This is efficient enough for v1 (tens of KB).\n return encodeFrame({\n ...frame,\n sig: new Uint8Array(0),\n });\n}\n","import * as crypto from 'crypto';\n\nimport { AxisFrame, encodeFrame } from './axis-bin';\n\n/**\n * Signature utilities for AXIS binary frames\n * Supports Ed25519 signature generation and verification\n */\n\n/**\n * Computes the canonical payload for signing an AXIS frame.\n * The signature covers all bytes of the encoded frame EXCEPT the signature field itself.\n *\n * @param {AxisFrame} frame - The frame to prepare for signing\n * @returns {Buffer} The serialized canonical bytes for the signature algorithm\n */\nexport function computeSignaturePayload(frame: AxisFrame): Buffer {\n // Re-encode frame with empty signature\n const frameWithoutSig: AxisFrame = {\n ...frame,\n sig: new Uint8Array(0),\n };\n\n const encoded = encodeFrame(frameWithoutSig);\n return Buffer.from(encoded);\n}\n\n/**\n * Signs an AXIS frame using the Ed25519 algorithm.\n * Automatically handles both raw 32-byte seeds and pkcs8 DER-encoded private keys.\n *\n * @param {AxisFrame} frame - The frame to sign\n * @param {Buffer} privateKey - Ed25519 private key (32-byte raw OR pkcs8 DER)\n * @returns {Buffer} The 64-byte Ed25519 signature\n * @throws {Error} If key format is invalid or signing fail\n */\nexport function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer {\n const payload = computeSignaturePayload(frame);\n\n let keyObject: crypto.KeyObject;\n\n // Check if key is raw 32-byte seed or DER-encoded\n if (privateKey.length === 32) {\n // Raw seed - wrap in pkcs8 DER format\n // pkcs8 prefix for Ed25519: 0x302e020100300506032b657004220420\n const pkcs8Prefix = Buffer.from([\n 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,\n 0x04, 0x22, 0x04, 0x20,\n ]);\n const pkcs8Key = Buffer.concat([pkcs8Prefix, privateKey]);\n\n keyObject = crypto.createPrivateKey({\n key: pkcs8Key,\n format: 'der',\n type: 'pkcs8',\n });\n } else {\n // Assume already DER-encoded pkcs8\n keyObject = crypto.createPrivateKey({\n key: privateKey,\n format: 'der',\n type: 'pkcs8',\n });\n }\n\n const signature = crypto.sign(null, payload, keyObject);\n\n if (signature.length !== 64) {\n throw new Error('Ed25519 signature must be 64 bytes');\n }\n\n return signature;\n}\n\n/**\n * Verifies an Ed25519 signature on an AXIS frame.\n * Automatically handles both raw 32-byte public keys and spki DER-encoded public keys.\n *\n * @param {AxisFrame} frame - The frame containing the signature to verify\n * @param {Buffer} publicKey - Ed25519 public key (32-byte raw OR spki DER)\n * @returns {boolean} True if the signature is cryptographically valid\n * @throws {Error} If signature length is invalid\n */\nexport function verifyFrameSignature(\n frame: AxisFrame,\n publicKey: Buffer,\n): boolean {\n if (frame.sig.length === 0) {\n return false; // No signature\n }\n\n if (frame.sig.length !== 64) {\n throw new Error('Ed25519 signature must be 64 bytes');\n }\n\n const payload = computeSignaturePayload(frame);\n\n try {\n let keyObject: crypto.KeyObject;\n\n // Check if key is raw 32-byte or DER-encoded\n if (publicKey.length === 32) {\n // Raw key - wrap in spki DER format\n // spki prefix for Ed25519: 0x302a300506032b6570032100\n const spkiPrefix = Buffer.from([\n 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00,\n ]);\n const spkiKey = Buffer.concat([spkiPrefix, publicKey]);\n\n keyObject = crypto.createPublicKey({\n key: spkiKey,\n format: 'der',\n type: 'spki',\n });\n } else {\n // Assume already DER-encoded spki\n keyObject = crypto.createPublicKey({\n key: publicKey,\n format: 'der',\n type: 'spki',\n });\n }\n\n const valid = crypto.verify(\n null,\n payload,\n keyObject,\n Buffer.from(frame.sig),\n );\n return valid;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Generates a new Ed25519 key pair for use with the AXIS protocol.\n * Returns keys in canonical DER format (pkcs8 for private, spki for public).\n *\n * @returns {Object} An object containing the privateKey and publicKey as Buffers\n */\nexport function generateEd25519KeyPair(): {\n privateKey: Buffer;\n publicKey: Buffer;\n} {\n const { privateKey, publicKey } = crypto.generateKeyPairSync('ed25519');\n\n return {\n privateKey: privateKey.export({ type: 'pkcs8', format: 'der' }) as Buffer,\n publicKey: publicKey.export({ type: 'spki', format: 'der' }) as Buffer,\n };\n}\n\n/**\n * Computes a standard SHA-256 hash of the provided data.\n *\n * @param {Buffer | Uint8Array} data - The input data to hash\n * @returns {Buffer} The 32-byte SHA-256 digest\n */\nexport function sha256(data: Buffer | Uint8Array): Buffer {\n return crypto.createHash('sha256').update(data).digest();\n}\n\n/**\n * Computes a hash for an AXIS receipt, optionally chaining it to a previous hash.\n * This is used for generating an immutable transaction chain.\n *\n * @param {Buffer | Uint8Array} receiptBytes - The canonical binary representation of the receipt\n * @param {Buffer | Uint8Array} [prevHash] - The hash of the previous receipt in the chain\n * @returns {Buffer} The 32-byte SHA-256 hash of the receipt (and link)\n */\nexport function computeReceiptHash(\n receiptBytes: Buffer | Uint8Array,\n prevHash?: Buffer | Uint8Array,\n): Buffer {\n const hasher = crypto.createHash('sha256');\n hasher.update(receiptBytes);\n\n if (prevHash && prevHash.length > 0) {\n hasher.update(prevHash);\n }\n\n return hasher.digest();\n}\n","export class AxisError extends Error {\n constructor(\n public code: string,\n message: string,\n public httpStatus: number = 400,\n public details?: Record<string, any>,\n ) {\n super(message);\n this.name = 'AxisError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAiBO;;;ACjBP,IAAAA,wBAAyD;;;ACAzD,IAAAC,wBAEO;;;ACFP,QAAmB;AAQZ,IAAM,aAAe,SAAO;AAAA;AAAA,EAEjC,OAAS,SAAO,EAAE,IAAI,EAAE,YAAY;AAAA;AAAA,EAEpC,SAAW;AAAA,IACP,SAAO;AAAA,IACP,SAAmB,CAAC,MAAM,aAAa,UAAU;AAAA,EACrD;AAAA;AAAA,EAEA,MAAQ,SAAmB,CAAC,MAAM,aAAa,UAAU;AAAA;AAAA,EAEzD,KAAO,SAAmB,CAAC,MAAM,aAAa,UAAU;AAC1D,CAAC;AAgCM,SAAS,YAAY,OAA8B;AACxD,QAAM,eAAW;AAAA,IACf,MAAM,KAAK,MAAM,QAA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