1id 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +151 -0
- package/dist/auth.d.ts +55 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +188 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +57 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +224 -0
- package/dist/client.js.map +1 -0
- package/dist/credentials.d.ts +84 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +155 -0
- package/dist/credentials.js.map +1 -0
- package/dist/enroll.d.ts +44 -0
- package/dist/enroll.d.ts.map +1 -0
- package/dist/enroll.js +226 -0
- package/dist/enroll.js.map +1 -0
- package/dist/exceptions.d.ts +109 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +168 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/helper.d.ts +57 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/helper.js +387 -0
- package/dist/helper.js.map +1 -0
- package/dist/identity.d.ts +106 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +76 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +56 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +105 -0
- package/dist/keys.js.map +1 -0
- package/dist/test/test_declared_enrollment.d.ts +11 -0
- package/dist/test/test_declared_enrollment.d.ts.map +1 -0
- package/dist/test/test_declared_enrollment.js +256 -0
- package/dist/test/test_declared_enrollment.js.map +1 -0
- package/package.json +53 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the 1id.com Enrollment API.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node.js built-in `https`/`http` modules -- zero external dependencies.
|
|
5
|
+
*
|
|
6
|
+
* Handles all HTTP communication with the 1id.com server, including:
|
|
7
|
+
* - Enrollment requests (declared and sovereign tiers)
|
|
8
|
+
* - Identity lookups
|
|
9
|
+
* - Handle management
|
|
10
|
+
* - Error response mapping to SDK exceptions
|
|
11
|
+
*
|
|
12
|
+
* All responses follow the 1id.com API envelope:
|
|
13
|
+
* {"ok": true, "data": {...}, "error": null}
|
|
14
|
+
* {"ok": false, "data": null, "error": {"code": "...", "message": "..."}}
|
|
15
|
+
*/
|
|
16
|
+
import * as https from "node:https";
|
|
17
|
+
import * as http from "node:http";
|
|
18
|
+
import { DEFAULT_API_BASE_URL } from "./credentials.js";
|
|
19
|
+
import { EnrollmentError, NetworkError, raise_from_server_error_response, } from "./exceptions.js";
|
|
20
|
+
// -- HTTP client configuration --
|
|
21
|
+
const DEFAULT_HTTP_TIMEOUT_MILLISECONDS = 30_000;
|
|
22
|
+
const USER_AGENT = "oneid-sdk-node/0.1.0";
|
|
23
|
+
/**
|
|
24
|
+
* Make a raw HTTP(S) request and return the parsed JSON body.
|
|
25
|
+
* Uses only Node.js built-in modules.
|
|
26
|
+
*/
|
|
27
|
+
function make_http_request(base_url, options, timeout_milliseconds) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const url = new URL(options.path, base_url);
|
|
30
|
+
const is_https = url.protocol === "https:";
|
|
31
|
+
const transport = is_https ? https : http;
|
|
32
|
+
const request_headers = {
|
|
33
|
+
"User-Agent": USER_AGENT,
|
|
34
|
+
"Accept": "application/json",
|
|
35
|
+
...options.headers,
|
|
36
|
+
};
|
|
37
|
+
let request_body_string;
|
|
38
|
+
if (options.json_body != null) {
|
|
39
|
+
request_body_string = JSON.stringify(options.json_body);
|
|
40
|
+
request_headers["Content-Type"] = "application/json";
|
|
41
|
+
request_headers["Content-Length"] = Buffer.byteLength(request_body_string).toString();
|
|
42
|
+
}
|
|
43
|
+
const req = transport.request({
|
|
44
|
+
hostname: url.hostname,
|
|
45
|
+
port: url.port || (is_https ? 443 : 80),
|
|
46
|
+
path: url.pathname + url.search,
|
|
47
|
+
method: options.method,
|
|
48
|
+
headers: request_headers,
|
|
49
|
+
timeout: timeout_milliseconds,
|
|
50
|
+
}, (res) => {
|
|
51
|
+
const chunks = [];
|
|
52
|
+
res.on("data", (chunk) => { chunks.push(chunk); });
|
|
53
|
+
res.on("end", () => {
|
|
54
|
+
const raw_body = Buffer.concat(chunks).toString("utf-8");
|
|
55
|
+
try {
|
|
56
|
+
const parsed_body = JSON.parse(raw_body);
|
|
57
|
+
resolve({ status_code: res.statusCode ?? 0, body: parsed_body });
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
reject(new NetworkError(`Invalid JSON response from ${url.href} (HTTP ${res.statusCode}): ${raw_body.slice(0, 200)}`));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
req.on("error", (error) => {
|
|
65
|
+
reject(new NetworkError(`Could not connect to ${base_url}: ${error.message}`));
|
|
66
|
+
});
|
|
67
|
+
req.on("timeout", () => {
|
|
68
|
+
req.destroy();
|
|
69
|
+
reject(new NetworkError(`Request to ${url.href} timed out after ${timeout_milliseconds}ms`));
|
|
70
|
+
});
|
|
71
|
+
if (request_body_string != null) {
|
|
72
|
+
req.write(request_body_string);
|
|
73
|
+
}
|
|
74
|
+
req.end();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* HTTP client for the 1id.com enrollment and identity API.
|
|
79
|
+
*
|
|
80
|
+
* Wraps Node.js http/https with 1id-specific error handling. All methods
|
|
81
|
+
* throw SDK exceptions on failure, never raw HTTP errors.
|
|
82
|
+
*/
|
|
83
|
+
export class OneIDAPIClient {
|
|
84
|
+
api_base_url;
|
|
85
|
+
timeout_milliseconds;
|
|
86
|
+
constructor(api_base_url = DEFAULT_API_BASE_URL, timeout_milliseconds = DEFAULT_HTTP_TIMEOUT_MILLISECONDS) {
|
|
87
|
+
this.api_base_url = api_base_url.replace(/\/+$/, "");
|
|
88
|
+
this.timeout_milliseconds = timeout_milliseconds;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Make an HTTP request to the 1id.com API and parse the envelope response.
|
|
92
|
+
*/
|
|
93
|
+
async _make_request(method, api_path, json_body, headers) {
|
|
94
|
+
const response = await make_http_request(this.api_base_url, { method, path: api_path, json_body, headers }, this.timeout_milliseconds);
|
|
95
|
+
const response_body = response.body;
|
|
96
|
+
// Check for the standard 1id error envelope
|
|
97
|
+
if (!response_body?.ok) {
|
|
98
|
+
const error_info = (response_body?.error ?? {});
|
|
99
|
+
const error_code = error_info.code ?? "UNKNOWN_ERROR";
|
|
100
|
+
const error_message = error_info.message ?? `Server returned HTTP ${response.status_code}`;
|
|
101
|
+
raise_from_server_error_response(error_code, error_message);
|
|
102
|
+
}
|
|
103
|
+
return (response_body.data ?? {});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Enroll a new identity at the declared trust tier (no HSM required).
|
|
107
|
+
*/
|
|
108
|
+
async enroll_declared(software_key_pem, key_algorithm, operator_email, requested_handle) {
|
|
109
|
+
const request_body = {
|
|
110
|
+
software_key_pem,
|
|
111
|
+
key_algorithm,
|
|
112
|
+
};
|
|
113
|
+
if (operator_email != null) {
|
|
114
|
+
request_body["operator_email"] = operator_email;
|
|
115
|
+
}
|
|
116
|
+
if (requested_handle != null) {
|
|
117
|
+
request_body["requested_handle"] = requested_handle;
|
|
118
|
+
}
|
|
119
|
+
return this._make_request("POST", "/api/v1/enroll/declared", request_body);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Begin TPM/HSM-based enrollment (sovereign/sovereign-portable tiers).
|
|
123
|
+
*/
|
|
124
|
+
async enroll_begin(ek_certificate_pem, ak_public_key_pem, ak_tpmt_public_b64 = "", ek_public_key_pem = "", ek_certificate_chain_pem, hsm_type = "tpm", operator_email, requested_handle) {
|
|
125
|
+
const request_body = {
|
|
126
|
+
ek_certificate_pem,
|
|
127
|
+
ek_public_key_pem,
|
|
128
|
+
ak_public_key_pem,
|
|
129
|
+
ak_tpmt_public_b64,
|
|
130
|
+
hsm_type,
|
|
131
|
+
};
|
|
132
|
+
if (ek_certificate_chain_pem) {
|
|
133
|
+
request_body["ek_certificate_chain_pem"] = ek_certificate_chain_pem;
|
|
134
|
+
}
|
|
135
|
+
if (operator_email != null) {
|
|
136
|
+
request_body["operator_email"] = operator_email;
|
|
137
|
+
}
|
|
138
|
+
if (requested_handle != null) {
|
|
139
|
+
request_body["requested_handle"] = requested_handle;
|
|
140
|
+
}
|
|
141
|
+
return this._make_request("POST", "/api/v1/enroll/begin", request_body);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Complete TPM/HSM-based enrollment by proving HSM possession.
|
|
145
|
+
*/
|
|
146
|
+
async enroll_activate(enrollment_session_id, decrypted_credential) {
|
|
147
|
+
return this._make_request("POST", "/api/v1/enroll/activate", {
|
|
148
|
+
enrollment_session_id,
|
|
149
|
+
decrypted_credential,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Look up public identity information for an agent.
|
|
154
|
+
*/
|
|
155
|
+
async get_identity(agent_id) {
|
|
156
|
+
return this._make_request("GET", `/api/v1/identity/${agent_id}`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get an OAuth2 access token using the client_credentials grant.
|
|
160
|
+
*
|
|
161
|
+
* NOTE: Keycloak token endpoint expects form-urlencoded, not JSON.
|
|
162
|
+
*/
|
|
163
|
+
async get_token_with_client_credentials(client_id, client_secret) {
|
|
164
|
+
const token_path = "/realms/agents/protocol/openid-connect/token";
|
|
165
|
+
const form_body = new URLSearchParams({
|
|
166
|
+
grant_type: "client_credentials",
|
|
167
|
+
client_id,
|
|
168
|
+
client_secret,
|
|
169
|
+
}).toString();
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
const url = new URL(token_path, this.api_base_url);
|
|
172
|
+
const is_https = url.protocol === "https:";
|
|
173
|
+
const transport = is_https ? https : http;
|
|
174
|
+
const req = transport.request({
|
|
175
|
+
hostname: url.hostname,
|
|
176
|
+
port: url.port || (is_https ? 443 : 80),
|
|
177
|
+
path: url.pathname,
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers: {
|
|
180
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
181
|
+
"Content-Length": Buffer.byteLength(form_body).toString(),
|
|
182
|
+
"User-Agent": USER_AGENT,
|
|
183
|
+
},
|
|
184
|
+
timeout: this.timeout_milliseconds,
|
|
185
|
+
}, (res) => {
|
|
186
|
+
const chunks = [];
|
|
187
|
+
res.on("data", (chunk) => { chunks.push(chunk); });
|
|
188
|
+
res.on("end", () => {
|
|
189
|
+
const raw_body = Buffer.concat(chunks).toString("utf-8");
|
|
190
|
+
try {
|
|
191
|
+
const parsed = JSON.parse(raw_body);
|
|
192
|
+
if (res.statusCode !== 200) {
|
|
193
|
+
const error_description = parsed.error_description ??
|
|
194
|
+
parsed.error ??
|
|
195
|
+
`HTTP ${res.statusCode}`;
|
|
196
|
+
reject(new EnrollmentError(`Token request failed (HTTP ${res.statusCode}): ${error_description}`));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
resolve(parsed);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
reject(new NetworkError(`Invalid JSON from token endpoint (HTTP ${res.statusCode}): ${raw_body.slice(0, 200)}`));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
req.on("error", (error) => {
|
|
207
|
+
reject(new NetworkError(`Could not connect to token endpoint ${url.href}: ${error.message}`));
|
|
208
|
+
});
|
|
209
|
+
req.on("timeout", () => {
|
|
210
|
+
req.destroy();
|
|
211
|
+
reject(new NetworkError(`Token request to ${url.href} timed out after ${this.timeout_milliseconds}ms`));
|
|
212
|
+
});
|
|
213
|
+
req.write(form_body);
|
|
214
|
+
req.end();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Check whether a vanity handle is available.
|
|
219
|
+
*/
|
|
220
|
+
async check_handle_availability(handle_name) {
|
|
221
|
+
return this._make_request("GET", `/api/v1/handle/${handle_name}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gCAAgC,GACjC,MAAM,iBAAiB,CAAC;AAEzB,kCAAkC;AAClC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACjD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAS1C;;;GAGG;AACH,SAAS,iBAAiB,CACxB,QAAgB,EAChB,OAAuB,EACvB,oBAA4B;IAE5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAC3C,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1C,MAAM,eAAe,GAA2B;YAC9C,YAAY,EAAE,UAAU;YACxB,QAAQ,EAAE,kBAAkB;YAC5B,GAAG,OAAO,CAAC,OAAO;SACnB,CAAC;QAEF,IAAI,mBAAuC,CAAC;QAC5C,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC9B,mBAAmB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AiB,EAAE,CACtE,CAAC,CAAC;4BACH,OAAO;wBACT,CAAC;wBACD,OAAO,CAAC,MAAM,CAAC,CAAC;oBAClB,CAAC;oBAAC,MAAM,CAAC;wBACP,MAAM,CAAC,IAAI,YAAY,CACrB,0CAA0C,GAAG,CAAC,UAAU,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CACvF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CACF,CAAC;YAEF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;gBAC/B,MAAM,CAAC,IAAI,YAAY,CACrB,uCAAuC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CACpE,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;gBACrB,GAAG,CAAC,OAAO,EAAE,CAAC;gBACd,MAAM,CAAC,IAAI,YAAY,CACrB,oBAAoB,GAAG,CAAC,IAAI,oBAAoB,IAAI,CAAC,oBAAoB,IAAI,CAC9E,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YACrB,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,yBAAyB,CAAC,WAAmB;QACjD,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAC;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential storage for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* Manages the local credentials file that stores OAuth2 client credentials
|
|
5
|
+
* and the agent's signing key (for declared-tier software keys or references
|
|
6
|
+
* to TPM/YubiKey keys for hardware-backed tiers).
|
|
7
|
+
*
|
|
8
|
+
* Storage locations:
|
|
9
|
+
* Windows: %APPDATA%\oneid\credentials.json
|
|
10
|
+
* Linux: ~/.config/oneid/credentials.json
|
|
11
|
+
* macOS: ~/.config/oneid/credentials.json
|
|
12
|
+
*
|
|
13
|
+
* Security:
|
|
14
|
+
* - File permissions set to owner-only (0600 on Unix)
|
|
15
|
+
* - Private keys are stored PEM-encoded in the credentials file
|
|
16
|
+
* - Credentials are NEVER logged or printed
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_API_BASE_URL = "https://1id.com";
|
|
19
|
+
export declare const DEFAULT_TOKEN_ENDPOINT = "https://1id.com/realms/agents/protocol/openid-connect/token";
|
|
20
|
+
/**
|
|
21
|
+
* Credentials stored locally after enrollment.
|
|
22
|
+
*
|
|
23
|
+
* Contains everything needed to authenticate and sign challenges
|
|
24
|
+
* without re-enrolling.
|
|
25
|
+
*/
|
|
26
|
+
export interface StoredCredentials {
|
|
27
|
+
/** The 1id internal ID (e.g., '1id_a7b3c9d2'), used as OAuth2 client_id. */
|
|
28
|
+
client_id: string;
|
|
29
|
+
/** OAuth2 client secret issued by Keycloak. */
|
|
30
|
+
client_secret: string;
|
|
31
|
+
/** Full URL of the Keycloak token endpoint. */
|
|
32
|
+
token_endpoint: string;
|
|
33
|
+
/** Base URL for the 1id.com enrollment API. */
|
|
34
|
+
api_base_url: string;
|
|
35
|
+
/** The trust tier assigned at enrollment. */
|
|
36
|
+
trust_tier: string;
|
|
37
|
+
/** The key algorithm used for the signing key. */
|
|
38
|
+
key_algorithm: string;
|
|
39
|
+
/** PEM-encoded private key (declared tier). Null for TPM tiers. */
|
|
40
|
+
private_key_pem?: string | null;
|
|
41
|
+
/** Reference to the HSM-stored key (e.g., TPM AK handle). Null for declared tier. */
|
|
42
|
+
hsm_key_reference?: string | null;
|
|
43
|
+
/** ISO 8601 timestamp of enrollment. */
|
|
44
|
+
enrolled_at?: string | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Return the platform-appropriate directory for storing credentials.
|
|
48
|
+
*
|
|
49
|
+
* Windows: %APPDATA%\oneid\
|
|
50
|
+
* Linux: ~/.config/oneid/
|
|
51
|
+
* macOS: ~/.config/oneid/
|
|
52
|
+
*/
|
|
53
|
+
export declare function get_credentials_directory(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Return the full path to the credentials JSON file.
|
|
56
|
+
*/
|
|
57
|
+
export declare function get_credentials_file_path(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Save enrollment credentials to the local credentials file.
|
|
60
|
+
*
|
|
61
|
+
* Creates the directory if it doesn't exist. Sets file permissions
|
|
62
|
+
* to owner-only for security.
|
|
63
|
+
*
|
|
64
|
+
* @returns Path to the saved credentials file.
|
|
65
|
+
*/
|
|
66
|
+
export declare function save_credentials(credentials: StoredCredentials): string;
|
|
67
|
+
/**
|
|
68
|
+
* Load enrollment credentials from the local credentials file.
|
|
69
|
+
*
|
|
70
|
+
* @throws NotEnrolledError if no credentials file exists.
|
|
71
|
+
* @throws OneIDError if the credentials file is corrupted.
|
|
72
|
+
*/
|
|
73
|
+
export declare function load_credentials(): StoredCredentials;
|
|
74
|
+
/**
|
|
75
|
+
* Check whether a credentials file exists (agent has enrolled).
|
|
76
|
+
*/
|
|
77
|
+
export declare function credentials_exist(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Delete the local credentials file (for re-enrollment or cleanup).
|
|
80
|
+
*
|
|
81
|
+
* @returns true if the file was deleted, false if it didn't exist.
|
|
82
|
+
*/
|
|
83
|
+
export declare function delete_credentials(): boolean;
|
|
84
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,sBAAsB,gEAAgE,CAAC;AAKpG;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAelD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAgBD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,CA4BvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,iBAAiB,CAkCpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAO5C"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential storage for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* Manages the local credentials file that stores OAuth2 client credentials
|
|
5
|
+
* and the agent's signing key (for declared-tier software keys or references
|
|
6
|
+
* to TPM/YubiKey keys for hardware-backed tiers).
|
|
7
|
+
*
|
|
8
|
+
* Storage locations:
|
|
9
|
+
* Windows: %APPDATA%\oneid\credentials.json
|
|
10
|
+
* Linux: ~/.config/oneid/credentials.json
|
|
11
|
+
* macOS: ~/.config/oneid/credentials.json
|
|
12
|
+
*
|
|
13
|
+
* Security:
|
|
14
|
+
* - File permissions set to owner-only (0600 on Unix)
|
|
15
|
+
* - Private keys are stored PEM-encoded in the credentials file
|
|
16
|
+
* - Credentials are NEVER logged or printed
|
|
17
|
+
*/
|
|
18
|
+
import * as fs from "node:fs";
|
|
19
|
+
import * as os from "node:os";
|
|
20
|
+
import * as path from "node:path";
|
|
21
|
+
import { NotEnrolledError, OneIDError } from "./exceptions.js";
|
|
22
|
+
// -- Default server endpoints --
|
|
23
|
+
export const DEFAULT_API_BASE_URL = "https://1id.com";
|
|
24
|
+
export const DEFAULT_TOKEN_ENDPOINT = "https://1id.com/realms/agents/protocol/openid-connect/token";
|
|
25
|
+
// -- Credential file name --
|
|
26
|
+
const CREDENTIALS_FILENAME = "credentials.json";
|
|
27
|
+
/**
|
|
28
|
+
* Return the platform-appropriate directory for storing credentials.
|
|
29
|
+
*
|
|
30
|
+
* Windows: %APPDATA%\oneid\
|
|
31
|
+
* Linux: ~/.config/oneid/
|
|
32
|
+
* macOS: ~/.config/oneid/
|
|
33
|
+
*/
|
|
34
|
+
export function get_credentials_directory() {
|
|
35
|
+
const system_platform = os.platform();
|
|
36
|
+
if (system_platform === "win32") {
|
|
37
|
+
const appdata = process.env["APPDATA"];
|
|
38
|
+
if (appdata) {
|
|
39
|
+
return path.join(appdata, "oneid");
|
|
40
|
+
}
|
|
41
|
+
return path.join(os.homedir(), "AppData", "Roaming", "oneid");
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const xdg_config_home = process.env["XDG_CONFIG_HOME"];
|
|
45
|
+
if (xdg_config_home) {
|
|
46
|
+
return path.join(xdg_config_home, "oneid");
|
|
47
|
+
}
|
|
48
|
+
return path.join(os.homedir(), ".config", "oneid");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Return the full path to the credentials JSON file.
|
|
53
|
+
*/
|
|
54
|
+
export function get_credentials_file_path() {
|
|
55
|
+
return path.join(get_credentials_directory(), CREDENTIALS_FILENAME);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set file permissions to owner-only (0600 on Unix).
|
|
59
|
+
* On Windows, %APPDATA% is already user-private by default.
|
|
60
|
+
*/
|
|
61
|
+
function set_owner_only_permissions(file_path) {
|
|
62
|
+
if (os.platform() !== "win32") {
|
|
63
|
+
try {
|
|
64
|
+
fs.chmodSync(file_path, 0o600);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Best effort -- may fail in some environments
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Save enrollment credentials to the local credentials file.
|
|
73
|
+
*
|
|
74
|
+
* Creates the directory if it doesn't exist. Sets file permissions
|
|
75
|
+
* to owner-only for security.
|
|
76
|
+
*
|
|
77
|
+
* @returns Path to the saved credentials file.
|
|
78
|
+
*/
|
|
79
|
+
export function save_credentials(credentials) {
|
|
80
|
+
const credentials_directory = get_credentials_directory();
|
|
81
|
+
fs.mkdirSync(credentials_directory, { recursive: true });
|
|
82
|
+
const credentials_file_path = path.join(credentials_directory, CREDENTIALS_FILENAME);
|
|
83
|
+
// Serialize to JSON -- only include key fields that are present
|
|
84
|
+
const credentials_dict = {
|
|
85
|
+
client_id: credentials.client_id,
|
|
86
|
+
client_secret: credentials.client_secret,
|
|
87
|
+
token_endpoint: credentials.token_endpoint,
|
|
88
|
+
api_base_url: credentials.api_base_url,
|
|
89
|
+
trust_tier: credentials.trust_tier,
|
|
90
|
+
key_algorithm: credentials.key_algorithm,
|
|
91
|
+
enrolled_at: credentials.enrolled_at ?? null,
|
|
92
|
+
};
|
|
93
|
+
if (credentials.private_key_pem != null) {
|
|
94
|
+
credentials_dict["private_key_pem"] = credentials.private_key_pem;
|
|
95
|
+
}
|
|
96
|
+
if (credentials.hsm_key_reference != null) {
|
|
97
|
+
credentials_dict["hsm_key_reference"] = credentials.hsm_key_reference;
|
|
98
|
+
}
|
|
99
|
+
fs.writeFileSync(credentials_file_path, JSON.stringify(credentials_dict, null, 2) + "\n", "utf-8");
|
|
100
|
+
set_owner_only_permissions(credentials_file_path);
|
|
101
|
+
return credentials_file_path;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Load enrollment credentials from the local credentials file.
|
|
105
|
+
*
|
|
106
|
+
* @throws NotEnrolledError if no credentials file exists.
|
|
107
|
+
* @throws OneIDError if the credentials file is corrupted.
|
|
108
|
+
*/
|
|
109
|
+
export function load_credentials() {
|
|
110
|
+
const credentials_file_path = get_credentials_file_path();
|
|
111
|
+
if (!fs.existsSync(credentials_file_path)) {
|
|
112
|
+
throw new NotEnrolledError(`No credentials file found at ${credentials_file_path}. ` +
|
|
113
|
+
"Call oneid.enroll() to create an identity first.");
|
|
114
|
+
}
|
|
115
|
+
let raw_json_text;
|
|
116
|
+
let credentials_dict;
|
|
117
|
+
try {
|
|
118
|
+
raw_json_text = fs.readFileSync(credentials_file_path, "utf-8");
|
|
119
|
+
credentials_dict = JSON.parse(raw_json_text);
|
|
120
|
+
}
|
|
121
|
+
catch (read_error) {
|
|
122
|
+
throw new OneIDError(`Credentials file at ${credentials_file_path} is corrupted or unreadable: ${read_error}`, "CREDENTIALS_CORRUPTED");
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
client_id: credentials_dict["client_id"],
|
|
126
|
+
client_secret: credentials_dict["client_secret"],
|
|
127
|
+
token_endpoint: credentials_dict["token_endpoint"],
|
|
128
|
+
api_base_url: credentials_dict["api_base_url"],
|
|
129
|
+
trust_tier: credentials_dict["trust_tier"] ?? "declared",
|
|
130
|
+
key_algorithm: credentials_dict["key_algorithm"] ?? "ed25519",
|
|
131
|
+
private_key_pem: credentials_dict["private_key_pem"] ?? null,
|
|
132
|
+
hsm_key_reference: credentials_dict["hsm_key_reference"] ?? null,
|
|
133
|
+
enrolled_at: credentials_dict["enrolled_at"] ?? null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check whether a credentials file exists (agent has enrolled).
|
|
138
|
+
*/
|
|
139
|
+
export function credentials_exist() {
|
|
140
|
+
return fs.existsSync(get_credentials_file_path());
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Delete the local credentials file (for re-enrollment or cleanup).
|
|
144
|
+
*
|
|
145
|
+
* @returns true if the file was deleted, false if it didn't exist.
|
|
146
|
+
*/
|
|
147
|
+
export function delete_credentials() {
|
|
148
|
+
const credentials_file_path = get_credentials_file_path();
|
|
149
|
+
if (fs.existsSync(credentials_file_path)) {
|
|
150
|
+
fs.unlinkSync(credentials_file_path);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE/D,iCAAiC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,6DAA6D,CAAC;AAEpG,6BAA6B;AAC7B,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AA6BhD;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,eAAe,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IACtC,IAAI,eAAe,KAAK,OAAO,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACvC,IAA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IAC/C,CAAC;IAAC,OAAO,UAAU,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,CAClB,uBAAuB,qBAAqB,gCAAgC,UAAU,EAAE,EACxF,uBAAuB,CACxB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAW;QAClD,aAAa,EAAE,gBAAgB,CAAC,eAAe,CAAW;QAC1D,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAW;QAC5D,YAAY,EAAE,gBAAgB,CAAC,cAAc,CAAW;QACxD,UAAU,EAAG,gBAAgB,CAAC,YAAY,CAAY,IAAI,UAAU;QACpE,aAAa,EAAG,gBAAgB,CAAC,eAAe,CAAY,IAAI,SAAS;QACzE,eAAe,EAAG,gBAAgB,CAAC,iBAAiB,CAAY,IAAI,IAAI;QACxE,iBAAiB,EAAG,gBAAgB,CAAC,mBAAmB,CAAY,IAAI,IAAI;QAC5E,WAAW,EAAG,gBAAgB,CAAC,aAAa,CAAY,IAAI,IAAI;KACjE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,EAAE,CAAC,UAAU,CAAC,yBAAyB,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,qBAAqB,GAAG,yBAAyB,EAAE,CAAC;IAC1D,IAAI,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACzC,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/enroll.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enrollment logic for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates the enrollment flow for all trust tiers:
|
|
5
|
+
* - Declared: Pure software, generates a keypair, sends public key to server.
|
|
6
|
+
* - Sovereign: Spawns Go binary for TPM operations, two-phase enrollment.
|
|
7
|
+
* - Sovereign-portable: Spawns Go binary for YubiKey/PIV operations.
|
|
8
|
+
*
|
|
9
|
+
* CRITICAL DESIGN RULE: requestTier is a REQUIREMENT, not a preference.
|
|
10
|
+
* The agent gets exactly the tier it requests, or an exception.
|
|
11
|
+
* There are NO automatic fallbacks. The caller's logic decides what to do.
|
|
12
|
+
*/
|
|
13
|
+
import { type Identity, KeyAlgorithm } from "./identity.js";
|
|
14
|
+
/**
|
|
15
|
+
* Options for the enroll() function.
|
|
16
|
+
*/
|
|
17
|
+
export interface EnrollOptions {
|
|
18
|
+
/** REQUIRED. The trust tier to request. */
|
|
19
|
+
request_tier: string;
|
|
20
|
+
/** Optional. Human contact email for this agent. */
|
|
21
|
+
operator_email?: string | null;
|
|
22
|
+
/** Optional. Vanity handle to claim (without '@' prefix). */
|
|
23
|
+
requested_handle?: string | null;
|
|
24
|
+
/** Optional. Key algorithm for declared-tier enrollment. Default: 'ed25519'. */
|
|
25
|
+
key_algorithm?: string | KeyAlgorithm | null;
|
|
26
|
+
/** Optional. Override the API base URL (for testing/staging). */
|
|
27
|
+
api_base_url?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Enroll this agent with 1id.com to receive a unique, verifiable identity.
|
|
31
|
+
*
|
|
32
|
+
* This is the primary entry point for enrollment. The agent specifies
|
|
33
|
+
* which trust tier it requires, and gets exactly that tier or an exception.
|
|
34
|
+
*
|
|
35
|
+
* THERE ARE NO AUTOMATIC FALLBACKS.
|
|
36
|
+
*
|
|
37
|
+
* @param options Enrollment options including the required request_tier.
|
|
38
|
+
* @returns The enrolled Identity.
|
|
39
|
+
* @throws NoHSMError if requested tier requires an HSM but none was found.
|
|
40
|
+
* @throws EnrollmentError for any enrollment failure.
|
|
41
|
+
* @throws NetworkError if the server cannot be reached.
|
|
42
|
+
*/
|
|
43
|
+
export declare function enroll(options: EnrollOptions): Promise<Identity>;
|
|
44
|
+
//# sourceMappingURL=enroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enroll.d.ts","sourceRoot":"","sources":["../src/enroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,OAAO,EAGL,KAAK,QAAQ,EACb,YAAY,EAEb,MAAM,eAAe,CAAC;AAqBvB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;IAC7C,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8CtE"}
|