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/enroll.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
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 { OneIDAPIClient } from "./client.js";
|
|
14
|
+
import { DEFAULT_API_BASE_URL, save_credentials, } from "./credentials.js";
|
|
15
|
+
import { EnrollmentError, NoHSMError } from "./exceptions.js";
|
|
16
|
+
import { DEFAULT_KEY_ALGORITHM, HSMType, KeyAlgorithm, TrustTier, } from "./identity.js";
|
|
17
|
+
import { generate_keypair } from "./keys.js";
|
|
18
|
+
/** Trust tiers that require an HSM and the Go binary. */
|
|
19
|
+
const TIERS_REQUIRING_HSM = new Set([
|
|
20
|
+
TrustTier.SOVEREIGN,
|
|
21
|
+
TrustTier.SOVEREIGN_PORTABLE,
|
|
22
|
+
TrustTier.LEGACY,
|
|
23
|
+
TrustTier.VIRTUAL,
|
|
24
|
+
TrustTier.ENCLAVE,
|
|
25
|
+
]);
|
|
26
|
+
/** HSM type preferences by tier. */
|
|
27
|
+
const TIER_TO_HSM_TYPE_PREFERENCES = {
|
|
28
|
+
[TrustTier.SOVEREIGN]: ["tpm"],
|
|
29
|
+
[TrustTier.SOVEREIGN_PORTABLE]: ["yubikey", "nitrokey", "feitian", "solokeys"],
|
|
30
|
+
[TrustTier.LEGACY]: ["tpm", "yubikey", "nitrokey", "feitian"],
|
|
31
|
+
[TrustTier.VIRTUAL]: ["tpm"],
|
|
32
|
+
[TrustTier.ENCLAVE]: ["secure_enclave"],
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Enroll this agent with 1id.com to receive a unique, verifiable identity.
|
|
36
|
+
*
|
|
37
|
+
* This is the primary entry point for enrollment. The agent specifies
|
|
38
|
+
* which trust tier it requires, and gets exactly that tier or an exception.
|
|
39
|
+
*
|
|
40
|
+
* THERE ARE NO AUTOMATIC FALLBACKS.
|
|
41
|
+
*
|
|
42
|
+
* @param options Enrollment options including the required request_tier.
|
|
43
|
+
* @returns The enrolled Identity.
|
|
44
|
+
* @throws NoHSMError if requested tier requires an HSM but none was found.
|
|
45
|
+
* @throws EnrollmentError for any enrollment failure.
|
|
46
|
+
* @throws NetworkError if the server cannot be reached.
|
|
47
|
+
*/
|
|
48
|
+
export async function enroll(options) {
|
|
49
|
+
// Validate and normalize the requested tier
|
|
50
|
+
const valid_tiers = Object.values(TrustTier);
|
|
51
|
+
if (!valid_tiers.includes(options.request_tier)) {
|
|
52
|
+
throw new EnrollmentError(`Invalid trust tier: '${options.request_tier}'. Valid tiers: ${valid_tiers.join(", ")}`);
|
|
53
|
+
}
|
|
54
|
+
const tier = options.request_tier;
|
|
55
|
+
// Normalize key algorithm
|
|
56
|
+
let resolved_key_algorithm;
|
|
57
|
+
if (options.key_algorithm == null) {
|
|
58
|
+
resolved_key_algorithm = DEFAULT_KEY_ALGORITHM;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof options.key_algorithm === "string") {
|
|
61
|
+
const valid_algorithms = Object.values(KeyAlgorithm);
|
|
62
|
+
if (!valid_algorithms.includes(options.key_algorithm)) {
|
|
63
|
+
throw new EnrollmentError(`Invalid key algorithm: '${options.key_algorithm}'. Valid: ${valid_algorithms.join(", ")}`);
|
|
64
|
+
}
|
|
65
|
+
resolved_key_algorithm = options.key_algorithm;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolved_key_algorithm = options.key_algorithm;
|
|
69
|
+
}
|
|
70
|
+
const api_base_url = options.api_base_url ?? DEFAULT_API_BASE_URL;
|
|
71
|
+
// Route to the appropriate enrollment flow
|
|
72
|
+
if (tier === TrustTier.DECLARED) {
|
|
73
|
+
return enroll_declared_tier(options.operator_email ?? null, options.requested_handle ?? null, resolved_key_algorithm, api_base_url);
|
|
74
|
+
}
|
|
75
|
+
else if (TIERS_REQUIRING_HSM.has(tier)) {
|
|
76
|
+
return enroll_hsm_tier(tier, options.operator_email ?? null, options.requested_handle ?? null, api_base_url);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new EnrollmentError(`Tier '${tier}' is not yet implemented`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Enroll at the declared trust tier (software keys, no HSM).
|
|
84
|
+
*/
|
|
85
|
+
async function enroll_declared_tier(operator_email, requested_handle, key_algorithm, api_base_url) {
|
|
86
|
+
// Step 1: Generate keypair
|
|
87
|
+
const { private_key_pem, public_key_pem } = generate_keypair(key_algorithm);
|
|
88
|
+
// Step 2: Send enrollment request to server
|
|
89
|
+
const api_client = new OneIDAPIClient(api_base_url);
|
|
90
|
+
const server_response = await api_client.enroll_declared(public_key_pem, key_algorithm, operator_email, requested_handle);
|
|
91
|
+
// Step 3: Parse server response
|
|
92
|
+
const identity_data = (server_response.identity ?? {});
|
|
93
|
+
const credentials_data = (server_response.credentials ?? {});
|
|
94
|
+
const internal_id = identity_data.internal_id ?? "";
|
|
95
|
+
const handle = identity_data.handle ?? `@${internal_id.slice(0, 12)}`;
|
|
96
|
+
const enrolled_at_str = identity_data.registered_at ?? new Date().toISOString();
|
|
97
|
+
// Step 4: Store credentials locally
|
|
98
|
+
const stored_credentials = {
|
|
99
|
+
client_id: credentials_data.client_id ?? internal_id,
|
|
100
|
+
client_secret: credentials_data.client_secret ?? "",
|
|
101
|
+
token_endpoint: credentials_data.token_endpoint ??
|
|
102
|
+
`${api_base_url}/realms/agents/protocol/openid-connect/token`,
|
|
103
|
+
api_base_url,
|
|
104
|
+
trust_tier: TrustTier.DECLARED,
|
|
105
|
+
key_algorithm,
|
|
106
|
+
private_key_pem,
|
|
107
|
+
enrolled_at: enrolled_at_str,
|
|
108
|
+
};
|
|
109
|
+
const credentials_file_path = save_credentials(stored_credentials);
|
|
110
|
+
console.log(`[oneid] Credentials saved to ${credentials_file_path}`);
|
|
111
|
+
// Step 5: Return Identity object
|
|
112
|
+
let enrolled_at;
|
|
113
|
+
try {
|
|
114
|
+
enrolled_at = new Date(enrolled_at_str);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
enrolled_at = new Date();
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
internal_id,
|
|
121
|
+
handle,
|
|
122
|
+
trust_tier: TrustTier.DECLARED,
|
|
123
|
+
hsm_type: HSMType.SOFTWARE,
|
|
124
|
+
hsm_manufacturer: null,
|
|
125
|
+
enrolled_at,
|
|
126
|
+
device_count: 0,
|
|
127
|
+
key_algorithm,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Enroll at an HSM-backed trust tier (sovereign, sovereign-portable, etc.).
|
|
132
|
+
*/
|
|
133
|
+
async function enroll_hsm_tier(request_tier, operator_email, requested_handle, api_base_url) {
|
|
134
|
+
const { detect_available_hsms, extract_attestation_data, activate_credential, } = await import("./helper.js");
|
|
135
|
+
// Step 1: Detect HSMs via Go binary
|
|
136
|
+
const detected_hsms = await detect_available_hsms();
|
|
137
|
+
if (detected_hsms.length === 0) {
|
|
138
|
+
throw new NoHSMError(`No hardware security module found. ` +
|
|
139
|
+
`The '${request_tier}' tier requires a TPM, YubiKey, or similar device.`);
|
|
140
|
+
}
|
|
141
|
+
// Step 2: Select the appropriate HSM
|
|
142
|
+
const selected_hsm = select_hsm_for_tier(detected_hsms, request_tier);
|
|
143
|
+
if (selected_hsm == null) {
|
|
144
|
+
const hsm_types = detected_hsms.map(h => h.type ?? "unknown").join(", ");
|
|
145
|
+
throw new NoHSMError(`Found HSM(s) (${hsm_types}) but none are compatible with the '${request_tier}' tier.`);
|
|
146
|
+
}
|
|
147
|
+
// Step 3: Extract attestation (requires elevation)
|
|
148
|
+
const attestation_data = await extract_attestation_data(selected_hsm);
|
|
149
|
+
// Step 4: Begin enrollment with server
|
|
150
|
+
const api_client = new OneIDAPIClient(api_base_url);
|
|
151
|
+
const begin_response = await api_client.enroll_begin(attestation_data.ek_cert_pem, attestation_data.ak_public_pem ?? "", attestation_data.ak_tpmt_public_b64 ?? "", attestation_data.ek_public_pem ?? "", attestation_data.chain_pem ?? undefined, selected_hsm.type ?? "tpm", operator_email, requested_handle);
|
|
152
|
+
// Step 5: Activate credential via TPM (requires elevation)
|
|
153
|
+
const decrypted_credential = await activate_credential(selected_hsm, begin_response.credential_blob, begin_response.encrypted_secret, attestation_data.ak_handle ?? "0x81000100");
|
|
154
|
+
// Step 6: Complete enrollment with server
|
|
155
|
+
const activate_response = await api_client.enroll_activate(begin_response.enrollment_session_id, decrypted_credential);
|
|
156
|
+
// Step 7: Store credentials and return Identity
|
|
157
|
+
const identity_data = (activate_response.identity ?? {});
|
|
158
|
+
const credentials_data = (activate_response.credentials ?? {});
|
|
159
|
+
const internal_id = identity_data.internal_id ?? "";
|
|
160
|
+
const handle = identity_data.handle ?? `@${internal_id.slice(0, 12)}`;
|
|
161
|
+
const trust_tier_str = identity_data.trust_tier ?? request_tier;
|
|
162
|
+
const enrolled_at_str = identity_data.registered_at ?? new Date().toISOString();
|
|
163
|
+
const stored_credentials = {
|
|
164
|
+
client_id: credentials_data.client_id ?? internal_id,
|
|
165
|
+
client_secret: credentials_data.client_secret ?? "",
|
|
166
|
+
token_endpoint: credentials_data.token_endpoint ??
|
|
167
|
+
`${api_base_url}/realms/agents/protocol/openid-connect/token`,
|
|
168
|
+
api_base_url,
|
|
169
|
+
trust_tier: trust_tier_str,
|
|
170
|
+
key_algorithm: "tpm-ak",
|
|
171
|
+
hsm_key_reference: attestation_data.ak_handle ?? null,
|
|
172
|
+
enrolled_at: enrolled_at_str,
|
|
173
|
+
};
|
|
174
|
+
save_credentials(stored_credentials);
|
|
175
|
+
let enrolled_at;
|
|
176
|
+
try {
|
|
177
|
+
enrolled_at = new Date(enrolled_at_str);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
enrolled_at = new Date();
|
|
181
|
+
}
|
|
182
|
+
// Resolve trust tier enum
|
|
183
|
+
let trust_tier;
|
|
184
|
+
const valid_tiers = Object.values(TrustTier);
|
|
185
|
+
if (valid_tiers.includes(trust_tier_str)) {
|
|
186
|
+
trust_tier = trust_tier_str;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
trust_tier = request_tier;
|
|
190
|
+
}
|
|
191
|
+
// Resolve HSM type enum
|
|
192
|
+
let hsm_type;
|
|
193
|
+
const hsm_type_str = selected_hsm.type ?? "tpm";
|
|
194
|
+
const valid_hsm_types = Object.values(HSMType);
|
|
195
|
+
if (valid_hsm_types.includes(hsm_type_str)) {
|
|
196
|
+
hsm_type = hsm_type_str;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
hsm_type = HSMType.TPM;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
internal_id,
|
|
203
|
+
handle,
|
|
204
|
+
trust_tier,
|
|
205
|
+
hsm_type,
|
|
206
|
+
hsm_manufacturer: selected_hsm.manufacturer ?? null,
|
|
207
|
+
enrolled_at,
|
|
208
|
+
device_count: identity_data.device_count ?? 1,
|
|
209
|
+
key_algorithm: KeyAlgorithm.RSA_2048,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Select the best matching HSM for the requested tier.
|
|
214
|
+
*/
|
|
215
|
+
function select_hsm_for_tier(detected_hsms, request_tier) {
|
|
216
|
+
const preferred_types = TIER_TO_HSM_TYPE_PREFERENCES[request_tier] ?? [];
|
|
217
|
+
for (const preferred_type of preferred_types) {
|
|
218
|
+
for (const hsm of detected_hsms) {
|
|
219
|
+
if (hsm.type === preferred_type) {
|
|
220
|
+
return hsm;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
//#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,CAAa,CAAC;IAC3D,IAAI,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,QAAQ,GAAG,YAAuB,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,OAAO;QACL,WAAW;QACX,MAAM;QACN,UAAU;QACV,QAAQ;QACR,gBAAgB,EAAG,YAAY,CAAC,YAAuB,IAAI,IAAI;QAC/D,WAAW;QACX,YAAY,EAAG,aAAa,CAAC,YAAuB,IAAI,CAAC;QACzD,aAAa,EAAE,YAAY,CAAC,QAAQ;KACrC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAC1B,aAAwC,EACxC,YAAuB;IAEvB,MAAM,eAAe,GAAG,4BAA4B,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAEzE,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;YAChC,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBAChC,OAAO,GAAG,CAAC;YACb,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception hierarchy for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* All exceptions inherit from OneIDError. Enrollment-specific exceptions
|
|
5
|
+
* inherit from EnrollmentError. The hierarchy is designed so callers can
|
|
6
|
+
* catch at any level of specificity:
|
|
7
|
+
*
|
|
8
|
+
* try {
|
|
9
|
+
* await oneid.enroll({ requestTier: "sovereign" });
|
|
10
|
+
* } catch (e) {
|
|
11
|
+
* if (e instanceof NoHSMError) { ... }
|
|
12
|
+
* else if (e instanceof EnrollmentError) { ... }
|
|
13
|
+
* else if (e instanceof OneIDError) { ... }
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* CRITICAL DESIGN RULE: requestTier is a REQUIREMENT, not a preference.
|
|
17
|
+
* These exceptions are raised when the requested tier CANNOT be satisfied.
|
|
18
|
+
* The SDK NEVER silently falls back to a lower tier.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Base error for all 1id.com SDK errors.
|
|
22
|
+
*/
|
|
23
|
+
export declare class OneIDError extends Error {
|
|
24
|
+
readonly error_code: string | null;
|
|
25
|
+
constructor(message?: string, error_code?: string | null);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Base error for all enrollment failures.
|
|
29
|
+
*/
|
|
30
|
+
export declare class EnrollmentError extends OneIDError {
|
|
31
|
+
constructor(message?: string, error_code?: string | null);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Requested trust tier requires an HSM but none was found.
|
|
35
|
+
*/
|
|
36
|
+
export declare class NoHSMError extends EnrollmentError {
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* User denied the elevation prompt (clicked No on UAC/sudo/pkexec).
|
|
41
|
+
*/
|
|
42
|
+
export declare class UACDeniedError extends EnrollmentError {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* HSM was found but could not be accessed.
|
|
47
|
+
*/
|
|
48
|
+
export declare class HSMAccessError extends EnrollmentError {
|
|
49
|
+
constructor(message?: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This HSM is already enrolled with a different identity.
|
|
53
|
+
*/
|
|
54
|
+
export declare class AlreadyEnrolledError extends EnrollmentError {
|
|
55
|
+
constructor(message?: string);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Requested vanity handle is already in use by another identity.
|
|
59
|
+
*/
|
|
60
|
+
export declare class HandleTakenError extends EnrollmentError {
|
|
61
|
+
constructor(message?: string);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Requested handle violates naming rules.
|
|
65
|
+
*/
|
|
66
|
+
export declare class HandleInvalidError extends EnrollmentError {
|
|
67
|
+
constructor(message?: string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Requested handle was previously used and is permanently retired.
|
|
71
|
+
*/
|
|
72
|
+
export declare class HandleRetiredError extends EnrollmentError {
|
|
73
|
+
constructor(message?: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Token acquisition or refresh failed.
|
|
77
|
+
*/
|
|
78
|
+
export declare class AuthenticationError extends OneIDError {
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Could not reach the 1id.com API server.
|
|
83
|
+
*/
|
|
84
|
+
export declare class NetworkError extends OneIDError {
|
|
85
|
+
constructor(message?: string);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* No enrollment credentials found on this machine.
|
|
89
|
+
*/
|
|
90
|
+
export declare class NotEnrolledError extends OneIDError {
|
|
91
|
+
constructor(message?: string);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The oneid-enroll Go binary could not be found or downloaded.
|
|
95
|
+
*/
|
|
96
|
+
export declare class BinaryNotFoundError extends OneIDError {
|
|
97
|
+
constructor(message?: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Too many enrollment attempts from this IP address.
|
|
101
|
+
*/
|
|
102
|
+
export declare class RateLimitExceededError extends EnrollmentError {
|
|
103
|
+
constructor(message?: string);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Raise the appropriate exception for a server error response.
|
|
107
|
+
*/
|
|
108
|
+
export declare function raise_from_server_error_response(error_code: string, error_message: string): never;
|
|
109
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA;;;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,MAA8D;CAIpF;AAcD;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,KAAK,CAGjG"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception hierarchy for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* All exceptions inherit from OneIDError. Enrollment-specific exceptions
|
|
5
|
+
* inherit from EnrollmentError. The hierarchy is designed so callers can
|
|
6
|
+
* catch at any level of specificity:
|
|
7
|
+
*
|
|
8
|
+
* try {
|
|
9
|
+
* await oneid.enroll({ requestTier: "sovereign" });
|
|
10
|
+
* } catch (e) {
|
|
11
|
+
* if (e instanceof NoHSMError) { ... }
|
|
12
|
+
* else if (e instanceof EnrollmentError) { ... }
|
|
13
|
+
* else if (e instanceof OneIDError) { ... }
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* CRITICAL DESIGN RULE: requestTier is a REQUIREMENT, not a preference.
|
|
17
|
+
* These exceptions are raised when the requested tier CANNOT be satisfied.
|
|
18
|
+
* The SDK NEVER silently falls back to a lower tier.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Base error for all 1id.com SDK errors.
|
|
22
|
+
*/
|
|
23
|
+
export class OneIDError extends Error {
|
|
24
|
+
error_code;
|
|
25
|
+
constructor(message = "An error occurred in the 1id SDK", error_code = null) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "OneIDError";
|
|
28
|
+
this.error_code = error_code;
|
|
29
|
+
// Restore prototype chain (needed for instanceof to work with TS class extends Error)
|
|
30
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Base error for all enrollment failures.
|
|
35
|
+
*/
|
|
36
|
+
export class EnrollmentError extends OneIDError {
|
|
37
|
+
constructor(message = "Enrollment failed", error_code = null) {
|
|
38
|
+
super(message, error_code);
|
|
39
|
+
this.name = "EnrollmentError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Requested trust tier requires an HSM but none was found.
|
|
44
|
+
*/
|
|
45
|
+
export class NoHSMError extends EnrollmentError {
|
|
46
|
+
constructor(message = "No hardware security module found") {
|
|
47
|
+
super(message, "NO_HSM_FOUND");
|
|
48
|
+
this.name = "NoHSMError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* User denied the elevation prompt (clicked No on UAC/sudo/pkexec).
|
|
53
|
+
*/
|
|
54
|
+
export class UACDeniedError extends EnrollmentError {
|
|
55
|
+
constructor(message = "User denied elevation prompt") {
|
|
56
|
+
super(message, "UAC_DENIED");
|
|
57
|
+
this.name = "UACDeniedError";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* HSM was found but could not be accessed.
|
|
62
|
+
*/
|
|
63
|
+
export class HSMAccessError extends EnrollmentError {
|
|
64
|
+
constructor(message = "HSM found but access failed") {
|
|
65
|
+
super(message, "HSM_ACCESS_ERROR");
|
|
66
|
+
this.name = "HSMAccessError";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* This HSM is already enrolled with a different identity.
|
|
71
|
+
*/
|
|
72
|
+
export class AlreadyEnrolledError extends EnrollmentError {
|
|
73
|
+
constructor(message = "This HSM is already enrolled with a different identity") {
|
|
74
|
+
super(message, "EK_ALREADY_REGISTERED");
|
|
75
|
+
this.name = "AlreadyEnrolledError";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Requested vanity handle is already in use by another identity.
|
|
80
|
+
*/
|
|
81
|
+
export class HandleTakenError extends EnrollmentError {
|
|
82
|
+
constructor(message = "Requested handle is already in use") {
|
|
83
|
+
super(message, "HANDLE_TAKEN");
|
|
84
|
+
this.name = "HandleTakenError";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Requested handle violates naming rules.
|
|
89
|
+
*/
|
|
90
|
+
export class HandleInvalidError extends EnrollmentError {
|
|
91
|
+
constructor(message = "Requested handle violates naming rules") {
|
|
92
|
+
super(message, "HANDLE_INVALID");
|
|
93
|
+
this.name = "HandleInvalidError";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Requested handle was previously used and is permanently retired.
|
|
98
|
+
*/
|
|
99
|
+
export class HandleRetiredError extends EnrollmentError {
|
|
100
|
+
constructor(message = "Handle was previously used and is permanently retired") {
|
|
101
|
+
super(message, "HANDLE_RETIRED");
|
|
102
|
+
this.name = "HandleRetiredError";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Token acquisition or refresh failed.
|
|
107
|
+
*/
|
|
108
|
+
export class AuthenticationError extends OneIDError {
|
|
109
|
+
constructor(message = "Authentication failed") {
|
|
110
|
+
super(message, "AUTH_FAILED");
|
|
111
|
+
this.name = "AuthenticationError";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Could not reach the 1id.com API server.
|
|
116
|
+
*/
|
|
117
|
+
export class NetworkError extends OneIDError {
|
|
118
|
+
constructor(message = "Could not reach 1id.com") {
|
|
119
|
+
super(message, "NETWORK_ERROR");
|
|
120
|
+
this.name = "NetworkError";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* No enrollment credentials found on this machine.
|
|
125
|
+
*/
|
|
126
|
+
export class NotEnrolledError extends OneIDError {
|
|
127
|
+
constructor(message = "Not enrolled -- call oneid.enroll() first") {
|
|
128
|
+
super(message, "NOT_ENROLLED");
|
|
129
|
+
this.name = "NotEnrolledError";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The oneid-enroll Go binary could not be found or downloaded.
|
|
134
|
+
*/
|
|
135
|
+
export class BinaryNotFoundError extends OneIDError {
|
|
136
|
+
constructor(message = "oneid-enroll binary not found and could not be downloaded") {
|
|
137
|
+
super(message, "BINARY_NOT_FOUND");
|
|
138
|
+
this.name = "BinaryNotFoundError";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Too many enrollment attempts from this IP address.
|
|
143
|
+
*/
|
|
144
|
+
export class RateLimitExceededError extends EnrollmentError {
|
|
145
|
+
constructor(message = "Rate limit exceeded -- too many enrollment attempts") {
|
|
146
|
+
super(message, "RATE_LIMIT_EXCEEDED");
|
|
147
|
+
this.name = "RateLimitExceededError";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// -- Mapping from server API error codes to exception classes --
|
|
151
|
+
const SERVER_ERROR_CODE_TO_EXCEPTION_CLASS = {
|
|
152
|
+
"EK_ALREADY_REGISTERED": AlreadyEnrolledError,
|
|
153
|
+
"EK_CERT_INVALID": EnrollmentError,
|
|
154
|
+
"EK_CERT_CHAIN_UNTRUSTED": EnrollmentError,
|
|
155
|
+
"HANDLE_TAKEN": HandleTakenError,
|
|
156
|
+
"HANDLE_INVALID": HandleInvalidError,
|
|
157
|
+
"HANDLE_RETIRED": HandleRetiredError,
|
|
158
|
+
"RATE_LIMIT_EXCEEDED": RateLimitExceededError,
|
|
159
|
+
"RATE_LIMITED": RateLimitExceededError,
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Raise the appropriate exception for a server error response.
|
|
163
|
+
*/
|
|
164
|
+
export function raise_from_server_error_response(error_code, error_message) {
|
|
165
|
+
const ExceptionClass = SERVER_ERROR_CODE_TO_EXCEPTION_CLASS[error_code] ?? EnrollmentError;
|
|
166
|
+
throw new ExceptionClass(error_message);
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAk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;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,UAAkB,2DAA2D;QACvF,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IACzD,YAAY,UAAkB,qDAAqD;QACjF,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,iEAAiE;AACjE,MAAM,oCAAoC,GAAwD;IAChG,uBAAuB,EAAE,oBAAoB;IAC7C,iBAAiB,EAAE,eAAe;IAClC,yBAAyB,EAAE,eAAe;IAC1C,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,qBAAqB,EAAE,sBAAsB;IAC7C,cAAc,EAAE,sBAAsB;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gCAAgC,CAAC,UAAkB,EAAE,aAAqB;IACxF,MAAM,cAAc,GAAG,oCAAoC,CAAC,UAAU,CAAC,IAAI,eAAe,CAAC;IAC3F,MAAM,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go binary helper for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* Manages the oneid-enroll Go binary:
|
|
5
|
+
* - Locates the binary (cached or PATH)
|
|
6
|
+
* - Downloads it from GitHub releases if not present
|
|
7
|
+
* - Spawns it for HSM operations (detect, extract, activate, sign)
|
|
8
|
+
* - Parses JSON output
|
|
9
|
+
*
|
|
10
|
+
* The binary handles all platform-specific HSM operations:
|
|
11
|
+
* - TPM access (Windows TBS.dll, Linux /dev/tpm*)
|
|
12
|
+
* - YubiKey/PIV access (PCSC)
|
|
13
|
+
* - Privilege elevation (UAC, sudo, pkexec)
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Locate the oneid-enroll binary.
|
|
17
|
+
*
|
|
18
|
+
* Search order:
|
|
19
|
+
* 1. Binary cache directory (~/.local/share/oneid/bin/ or %APPDATA%/oneid/bin/)
|
|
20
|
+
* 2. Current working directory
|
|
21
|
+
* 3. System PATH
|
|
22
|
+
*
|
|
23
|
+
* @returns Path to the binary if found, null otherwise.
|
|
24
|
+
*/
|
|
25
|
+
export declare function find_binary(): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Ensure the oneid-enroll binary is available, downloading if needed.
|
|
28
|
+
*
|
|
29
|
+
* @returns Path to the available binary.
|
|
30
|
+
* @throws BinaryNotFoundError if the binary cannot be found or downloaded.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ensure_binary_available(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Run an oneid-enroll subcommand and parse its JSON output.
|
|
35
|
+
*/
|
|
36
|
+
export declare function run_binary_command(command: string, args?: string[], json_mode?: boolean, timeout_milliseconds?: number): Promise<Record<string, unknown>>;
|
|
37
|
+
/**
|
|
38
|
+
* Detect available hardware security modules via the Go binary.
|
|
39
|
+
*
|
|
40
|
+
* Runs 'oneid-enroll detect --json' which does NOT require elevation.
|
|
41
|
+
*/
|
|
42
|
+
export declare function detect_available_hsms(): Promise<Record<string, unknown>[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Extract attestation data from an HSM (requires elevation).
|
|
45
|
+
*/
|
|
46
|
+
export declare function extract_attestation_data(hsm: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* Decrypt a credential activation challenge via the HSM (requires elevation).
|
|
49
|
+
*/
|
|
50
|
+
export declare function activate_credential(_hsm: Record<string, unknown>, credential_blob_b64: string, encrypted_secret_b64: string, ak_handle: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Sign a challenge nonce using the TPM AK -- NO ELEVATION NEEDED.
|
|
53
|
+
*
|
|
54
|
+
* This is the core of ongoing TPM-backed authentication.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sign_challenge_with_tpm(nonce_b64: string, ak_handle: string): Promise<Record<string, unknown>>;
|
|
57
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoEH;;;;;;;;;GASG;AACH,wBAAgB,WAAW,IAAI,MAAM,GAAG,IAAI,CAyC3C;AAsJD;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAqB/D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,SAAS,GAAE,OAAc,EACzB,oBAAoB,GAAE,MAAe,GACpC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgElC;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAShF;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAGlC;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,mBAAmB,EAAE,MAAM,EAC3B,oBAAoB,EAAE,MAAM,EAC5B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAKlC"}
|