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/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Crypt Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# 1id
|
|
2
|
+
|
|
3
|
+
Hardware-anchored identity SDK for AI agents — [1id.com](https://1id.com)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/1id)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## What is 1id.com?
|
|
9
|
+
|
|
10
|
+
An identity registrar for AI agents. Like a passport office, but for software.
|
|
11
|
+
|
|
12
|
+
- **TPM-backed**: Agents with a Trusted Platform Module get cryptographic proof of identity
|
|
13
|
+
- **Sybil-resistant**: One chip = one identity. No farming.
|
|
14
|
+
- **Standards-based**: OAuth2, OIDC, JWT — your existing libraries work
|
|
15
|
+
- **Free**: Enrollment and authentication cost nothing
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install 1id
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Node.js 18 or later. Zero runtime dependencies.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import oneid from "1id";
|
|
29
|
+
|
|
30
|
+
// Enroll at declared tier (no TPM required, always works)
|
|
31
|
+
const identity = await oneid.enroll({ request_tier: "declared" });
|
|
32
|
+
console.log(`Enrolled as ${identity.handle}`);
|
|
33
|
+
|
|
34
|
+
// Get an OAuth2 token for authentication
|
|
35
|
+
const token = await oneid.getToken();
|
|
36
|
+
console.log(`Bearer ${token.access_token}`);
|
|
37
|
+
|
|
38
|
+
// Check current identity
|
|
39
|
+
const me = oneid.whoami();
|
|
40
|
+
console.log(`I am ${me.handle} (tier: ${me.trust_tier})`);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Trust Tiers
|
|
44
|
+
|
|
45
|
+
| Tier | Hardware | Sybil Resistance |
|
|
46
|
+
|------|----------|-----------------|
|
|
47
|
+
| `sovereign` | TPM (discrete/firmware) | Highest — manufacturer-attested |
|
|
48
|
+
| `sovereign-portable` | YubiKey / Nitrokey | High — manufacturer-attested |
|
|
49
|
+
| `virtual` | VMware/Hyper-V vTPM | Medium — hypervisor-attested |
|
|
50
|
+
| `declared` | None (software keys) | Lowest — self-asserted |
|
|
51
|
+
|
|
52
|
+
**CRITICAL**: `request_tier` is a REQUIREMENT, not a preference. You get exactly what you ask for, or an exception. No silent fallbacks.
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
### `oneid.enroll(options)`
|
|
57
|
+
|
|
58
|
+
Enroll this agent with 1id.com.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const identity = await oneid.enroll({
|
|
62
|
+
request_tier: "declared", // REQUIRED: trust tier
|
|
63
|
+
key_algorithm: "ed25519", // Optional: ed25519 (default), ecdsa-p256, rsa-2048, etc.
|
|
64
|
+
requested_handle: "my-agent", // Optional: vanity handle (without @)
|
|
65
|
+
operator_email: "human@example.com" // Optional: human contact
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `oneid.getToken()`
|
|
70
|
+
|
|
71
|
+
Get a valid OAuth2 access token (cached, auto-refreshes).
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const token = await oneid.getToken();
|
|
75
|
+
// Use token.access_token as a Bearer token
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `oneid.whoami()`
|
|
79
|
+
|
|
80
|
+
Read the local identity (no network call).
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const me = oneid.whoami();
|
|
84
|
+
// me.internal_id, me.handle, me.trust_tier, etc.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### `oneid.credentials_exist()`
|
|
88
|
+
|
|
89
|
+
Check if the agent has enrolled.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
if (!oneid.credentials_exist()) {
|
|
93
|
+
await oneid.enroll({ request_tier: "declared" });
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Error Handling
|
|
98
|
+
|
|
99
|
+
All errors extend `OneIDError`:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { OneIDError, NoHSMError, EnrollmentError, NetworkError } from "1id";
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
await oneid.enroll({ request_tier: "sovereign" });
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e instanceof NoHSMError) {
|
|
108
|
+
console.log("No TPM found — try 'declared' tier");
|
|
109
|
+
} else if (e instanceof NetworkError) {
|
|
110
|
+
console.log("Server unreachable — check connection");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Architecture
|
|
116
|
+
|
|
117
|
+
The SDK uses a two-tier architecture:
|
|
118
|
+
|
|
119
|
+
1. **TypeScript SDK** (this package) — handles enrollment orchestration, credential storage, OAuth2 token management, and software key operations using Node.js built-in `crypto`
|
|
120
|
+
2. **Go binary** (`oneid-enroll`) — handles all TPM/HSM hardware operations. Auto-downloaded from [GitHub releases](https://github.com/AuraFriday/oneid-enroll/releases) when needed
|
|
121
|
+
|
|
122
|
+
For `declared` tier enrollment, only the TypeScript SDK is needed. For `sovereign` (TPM) tier, the Go binary is automatically fetched.
|
|
123
|
+
|
|
124
|
+
## Credential Storage
|
|
125
|
+
|
|
126
|
+
Credentials are stored at:
|
|
127
|
+
- **Windows**: `%APPDATA%\oneid\credentials.json`
|
|
128
|
+
- **Linux/macOS**: `~/.config/oneid/credentials.json`
|
|
129
|
+
|
|
130
|
+
Permissions are set to owner-only (0600 on Unix).
|
|
131
|
+
|
|
132
|
+
## Python SDK
|
|
133
|
+
|
|
134
|
+
The Python equivalent is available as [`oneid`](https://pypi.org/project/oneid/) on PyPI:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pip install oneid
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Both SDKs share the same API design and credential format.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Apache 2.0 — see [LICENSE](LICENSE).
|
|
145
|
+
|
|
146
|
+
## Links
|
|
147
|
+
|
|
148
|
+
- [1id.com](https://1id.com) — Service homepage
|
|
149
|
+
- [Enrollment guide](https://1id.com/enroll.md) — Machine-readable enrollment instructions
|
|
150
|
+
- [Python SDK](https://pypi.org/project/oneid/) — `pip install oneid`
|
|
151
|
+
- [Go binary](https://github.com/AuraFriday/oneid-enroll) — TPM/HSM helper
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth2 token management for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* After enrollment, agents authenticate using standard OAuth2
|
|
5
|
+
* client_credentials grant. No TPM operations needed for daily use.
|
|
6
|
+
*
|
|
7
|
+
* This module handles:
|
|
8
|
+
* - Token acquisition (client_credentials grant)
|
|
9
|
+
* - Token caching (in-memory, with expiry awareness)
|
|
10
|
+
* - Token refresh
|
|
11
|
+
* - Authorization header formatting
|
|
12
|
+
*/
|
|
13
|
+
import { type StoredCredentials } from "./credentials.js";
|
|
14
|
+
import type { Token } from "./identity.js";
|
|
15
|
+
/**
|
|
16
|
+
* Get a valid OAuth2 access token, refreshing if needed.
|
|
17
|
+
*
|
|
18
|
+
* This is the primary authentication method for daily use. It uses
|
|
19
|
+
* the OAuth2 client_credentials grant with the credentials stored
|
|
20
|
+
* during enrollment.
|
|
21
|
+
*
|
|
22
|
+
* Tokens are cached in memory and automatically refreshed when they
|
|
23
|
+
* are within 60s of expiry.
|
|
24
|
+
*
|
|
25
|
+
* @param force_refresh If true, always fetch a new token even if cached.
|
|
26
|
+
* @param credentials Optional pre-loaded credentials.
|
|
27
|
+
* @returns A valid Token object.
|
|
28
|
+
* @throws NotEnrolledError if no credentials file exists.
|
|
29
|
+
* @throws AuthenticationError if the token request fails.
|
|
30
|
+
* @throws NetworkError if the token endpoint cannot be reached.
|
|
31
|
+
*/
|
|
32
|
+
export declare function get_token(force_refresh?: boolean, credentials?: StoredCredentials | null): Promise<Token>;
|
|
33
|
+
/**
|
|
34
|
+
* Clear the in-memory cached token.
|
|
35
|
+
*
|
|
36
|
+
* Useful for testing or when credentials have changed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clear_cached_token(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate using the TPM -- passwordless, zero-elevation sign-in.
|
|
41
|
+
*
|
|
42
|
+
* This is the "OAuth for agents" flow:
|
|
43
|
+
* 1. Requests a challenge nonce from the server
|
|
44
|
+
* 2. Signs it with the TPM AK (no elevation needed)
|
|
45
|
+
* 3. Sends the signature back to the server
|
|
46
|
+
* 4. Server verifies and issues a JWT
|
|
47
|
+
*
|
|
48
|
+
* @param identity_id The 1id internal ID. If null, loaded from credentials.
|
|
49
|
+
* @param ak_handle The AK persistent handle (hex). If null, loaded from credentials.
|
|
50
|
+
* @param api_base_url Base URL for the 1id API.
|
|
51
|
+
* @param credentials Pre-loaded credentials. If null, loaded from file.
|
|
52
|
+
* @returns A valid Token object.
|
|
53
|
+
*/
|
|
54
|
+
export declare function authenticate_with_tpm(identity_id?: string | null, ak_handle?: string | null, api_base_url?: string | null, credentials?: StoredCredentials | null): Promise<Token>;
|
|
55
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAoB,MAAM,kBAAkB,CAAC;AAE5E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAU3C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,aAAa,GAAE,OAAe,EAC9B,WAAW,CAAC,EAAE,iBAAiB,GAAG,IAAI,GACrC,OAAO,CAAC,KAAK,CAAC,CAmBhB;AA0CD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,EAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,EAC5B,WAAW,CAAC,EAAE,iBAAiB,GAAG,IAAI,GACrC,OAAO,CAAC,KAAK,CAAC,CA2FhB"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth2 token management for the 1id.com Node.js SDK.
|
|
3
|
+
*
|
|
4
|
+
* After enrollment, agents authenticate using standard OAuth2
|
|
5
|
+
* client_credentials grant. No TPM operations needed for daily use.
|
|
6
|
+
*
|
|
7
|
+
* This module handles:
|
|
8
|
+
* - Token acquisition (client_credentials grant)
|
|
9
|
+
* - Token caching (in-memory, with expiry awareness)
|
|
10
|
+
* - Token refresh
|
|
11
|
+
* - Authorization header formatting
|
|
12
|
+
*/
|
|
13
|
+
import { load_credentials } from "./credentials.js";
|
|
14
|
+
import { AuthenticationError, NetworkError } from "./exceptions.js";
|
|
15
|
+
import { OneIDAPIClient } from "./client.js";
|
|
16
|
+
// -- Configuration --
|
|
17
|
+
const TOKEN_REFRESH_MARGIN_MILLISECONDS = 60_000; // Refresh tokens 60s before expiry
|
|
18
|
+
const TOKEN_REQUEST_TIMEOUT_MILLISECONDS = 15_000;
|
|
19
|
+
// -- Module-level token cache --
|
|
20
|
+
let cached_token = null;
|
|
21
|
+
/**
|
|
22
|
+
* Get a valid OAuth2 access token, refreshing if needed.
|
|
23
|
+
*
|
|
24
|
+
* This is the primary authentication method for daily use. It uses
|
|
25
|
+
* the OAuth2 client_credentials grant with the credentials stored
|
|
26
|
+
* during enrollment.
|
|
27
|
+
*
|
|
28
|
+
* Tokens are cached in memory and automatically refreshed when they
|
|
29
|
+
* are within 60s of expiry.
|
|
30
|
+
*
|
|
31
|
+
* @param force_refresh If true, always fetch a new token even if cached.
|
|
32
|
+
* @param credentials Optional pre-loaded credentials.
|
|
33
|
+
* @returns A valid Token object.
|
|
34
|
+
* @throws NotEnrolledError if no credentials file exists.
|
|
35
|
+
* @throws AuthenticationError if the token request fails.
|
|
36
|
+
* @throws NetworkError if the token endpoint cannot be reached.
|
|
37
|
+
*/
|
|
38
|
+
export async function get_token(force_refresh = false, credentials) {
|
|
39
|
+
// Check if cached token is still valid (with margin)
|
|
40
|
+
if (!force_refresh && cached_token != null) {
|
|
41
|
+
const margin_adjusted_expiry = new Date(cached_token.expires_at.getTime() - TOKEN_REFRESH_MARGIN_MILLISECONDS);
|
|
42
|
+
if (new Date() < margin_adjusted_expiry) {
|
|
43
|
+
return cached_token;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Load credentials
|
|
47
|
+
if (credentials == null) {
|
|
48
|
+
credentials = load_credentials();
|
|
49
|
+
}
|
|
50
|
+
// Request a new token
|
|
51
|
+
const token = await request_token_from_keycloak(credentials);
|
|
52
|
+
cached_token = token;
|
|
53
|
+
return token;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Request a new access token from Keycloak using client_credentials grant.
|
|
57
|
+
*/
|
|
58
|
+
async function request_token_from_keycloak(credentials) {
|
|
59
|
+
const api_client = new OneIDAPIClient(credentials.api_base_url, TOKEN_REQUEST_TIMEOUT_MILLISECONDS);
|
|
60
|
+
let token_response;
|
|
61
|
+
try {
|
|
62
|
+
token_response = await api_client.get_token_with_client_credentials(credentials.client_id, credentials.client_secret);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof NetworkError || error instanceof AuthenticationError) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
throw new AuthenticationError(`Token request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
69
|
+
}
|
|
70
|
+
const access_token = token_response.access_token;
|
|
71
|
+
if (!access_token) {
|
|
72
|
+
throw new AuthenticationError("Token response missing 'access_token' field");
|
|
73
|
+
}
|
|
74
|
+
const expires_in_seconds = token_response.expires_in ?? 3600;
|
|
75
|
+
const expires_at = new Date(Date.now() + expires_in_seconds * 1000);
|
|
76
|
+
return {
|
|
77
|
+
access_token,
|
|
78
|
+
token_type: token_response.token_type ?? "Bearer",
|
|
79
|
+
expires_at,
|
|
80
|
+
refresh_token: token_response.refresh_token ?? null,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Clear the in-memory cached token.
|
|
85
|
+
*
|
|
86
|
+
* Useful for testing or when credentials have changed.
|
|
87
|
+
*/
|
|
88
|
+
export function clear_cached_token() {
|
|
89
|
+
cached_token = null;
|
|
90
|
+
}
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// TPM-backed passwordless authentication (sovereign/virtual tier)
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
/**
|
|
95
|
+
* Authenticate using the TPM -- passwordless, zero-elevation sign-in.
|
|
96
|
+
*
|
|
97
|
+
* This is the "OAuth for agents" flow:
|
|
98
|
+
* 1. Requests a challenge nonce from the server
|
|
99
|
+
* 2. Signs it with the TPM AK (no elevation needed)
|
|
100
|
+
* 3. Sends the signature back to the server
|
|
101
|
+
* 4. Server verifies and issues a JWT
|
|
102
|
+
*
|
|
103
|
+
* @param identity_id The 1id internal ID. If null, loaded from credentials.
|
|
104
|
+
* @param ak_handle The AK persistent handle (hex). If null, loaded from credentials.
|
|
105
|
+
* @param api_base_url Base URL for the 1id API.
|
|
106
|
+
* @param credentials Pre-loaded credentials. If null, loaded from file.
|
|
107
|
+
* @returns A valid Token object.
|
|
108
|
+
*/
|
|
109
|
+
export async function authenticate_with_tpm(identity_id, ak_handle, api_base_url, credentials) {
|
|
110
|
+
// Load credentials if not provided
|
|
111
|
+
if (credentials == null) {
|
|
112
|
+
credentials = load_credentials();
|
|
113
|
+
}
|
|
114
|
+
if (identity_id == null) {
|
|
115
|
+
identity_id = credentials.client_id;
|
|
116
|
+
}
|
|
117
|
+
if (ak_handle == null) {
|
|
118
|
+
ak_handle = credentials.hsm_key_reference ?? null;
|
|
119
|
+
if (!ak_handle) {
|
|
120
|
+
throw new AuthenticationError("No AK handle found in credentials. TPM authentication requires " +
|
|
121
|
+
"a sovereign or virtual tier enrollment with a TPM.");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (api_base_url == null) {
|
|
125
|
+
api_base_url = credentials.api_base_url;
|
|
126
|
+
}
|
|
127
|
+
// Step 1: Request a challenge nonce from the server
|
|
128
|
+
const api_client = new OneIDAPIClient(api_base_url, TOKEN_REQUEST_TIMEOUT_MILLISECONDS);
|
|
129
|
+
let challenge_data;
|
|
130
|
+
try {
|
|
131
|
+
challenge_data = await api_client["_make_request"]("POST", "/api/v1/auth/challenge", {
|
|
132
|
+
identity_id,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (error instanceof NetworkError) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
throw new AuthenticationError(`Challenge request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
140
|
+
}
|
|
141
|
+
const challenge_id = challenge_data.challenge_id;
|
|
142
|
+
const nonce_b64 = challenge_data.nonce_b64;
|
|
143
|
+
if (!challenge_id || !nonce_b64) {
|
|
144
|
+
throw new AuthenticationError("Server returned incomplete challenge response");
|
|
145
|
+
}
|
|
146
|
+
// Step 2: Sign the nonce with the TPM AK (NO elevation needed)
|
|
147
|
+
const { sign_challenge_with_tpm } = await import("./helper.js");
|
|
148
|
+
const sign_result = await sign_challenge_with_tpm(nonce_b64, ak_handle);
|
|
149
|
+
const signature_b64 = sign_result.signature_b64 ?? "";
|
|
150
|
+
if (!signature_b64) {
|
|
151
|
+
throw new AuthenticationError("TPM signing returned empty signature");
|
|
152
|
+
}
|
|
153
|
+
// Step 3: Send the signature to the server for verification
|
|
154
|
+
let verify_data;
|
|
155
|
+
try {
|
|
156
|
+
verify_data = await api_client["_make_request"]("POST", "/api/v1/auth/verify", {
|
|
157
|
+
challenge_id,
|
|
158
|
+
signature_b64,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (error instanceof NetworkError) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
throw new AuthenticationError(`TPM authentication failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
166
|
+
}
|
|
167
|
+
if (!verify_data.authenticated) {
|
|
168
|
+
throw new AuthenticationError("Server did not confirm authentication");
|
|
169
|
+
}
|
|
170
|
+
// Extract token from response
|
|
171
|
+
const tokens = verify_data.tokens;
|
|
172
|
+
if (tokens?.access_token) {
|
|
173
|
+
const expires_in_seconds = tokens.expires_in ?? 3600;
|
|
174
|
+
const token = {
|
|
175
|
+
access_token: tokens.access_token,
|
|
176
|
+
token_type: tokens.token_type ?? "Bearer",
|
|
177
|
+
expires_at: new Date(Date.now() + expires_in_seconds * 1000),
|
|
178
|
+
refresh_token: tokens.refresh_token ?? null,
|
|
179
|
+
};
|
|
180
|
+
cached_token = token;
|
|
181
|
+
return token;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
throw new AuthenticationError("TPM signature verified but no tokens were issued. " +
|
|
185
|
+
"The Keycloak token endpoint may be unavailable.");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAA0B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,sBAAsB;AACtB,MAAM,iCAAiC,GAAG,MAAM,CAAC,CAAC,mCAAmC;AACrF,MAAM,kCAAkC,GAAG,MAAM,CAAC;AAElD,iCAAiC;AACjC,IAAI,YAAY,GAAiB,IAAI,CAAC;AAEtC;;;;;;;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;YACZ,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAAC,MAAM,KAAK,CAAC;QAAC,CAAC;QACnD,MAAM,IAAI,mBAAmB,CAC3B,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACvF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC;QAC/B,MAAM,IAAI,mBAAmB,CAAC,uCAAuC,CAAC,CAAC;IACzE,CAAC;IAED,8BAA8B;IAC9B,MAAM,MAAM,GAAG,WAAW,CAAC,MAA6C,CAAC;IACzE,IAAI,MAAM,EAAE,YAAY,EAAE,CAAC;QACzB,MAAM,kBAAkB,GAAI,MAAM,CAAC,UAAqB,IAAI,IAAI,CAAC;QACjE,MAAM,KAAK,GAAU;YACnB,YAAY,EAAE,MAAM,CAAC,YAAsB;YAC3C,UAAU,EAAG,MAAM,CAAC,UAAqB,IAAI,QAAQ;YACrD,UAAU,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,kBAAkB,GAAG,IAAI,CAAC;YAC5D,aAAa,EAAG,MAAM,CAAC,aAAwB,IAAI,IAAI;SACxD,CAAC;QACF,YAAY,GAAG,KAAK,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,mBAAmB,CAC3B,oDAAoD;YACpD,iDAAiD,CAClD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* HTTP client for the 1id.com enrollment and identity API.
|
|
18
|
+
*
|
|
19
|
+
* Wraps Node.js http/https with 1id-specific error handling. All methods
|
|
20
|
+
* throw SDK exceptions on failure, never raw HTTP errors.
|
|
21
|
+
*/
|
|
22
|
+
export declare class OneIDAPIClient {
|
|
23
|
+
readonly api_base_url: string;
|
|
24
|
+
readonly timeout_milliseconds: number;
|
|
25
|
+
constructor(api_base_url?: string, timeout_milliseconds?: number);
|
|
26
|
+
/**
|
|
27
|
+
* Make an HTTP request to the 1id.com API and parse the envelope response.
|
|
28
|
+
*/
|
|
29
|
+
private _make_request;
|
|
30
|
+
/**
|
|
31
|
+
* Enroll a new identity at the declared trust tier (no HSM required).
|
|
32
|
+
*/
|
|
33
|
+
enroll_declared(software_key_pem: string, key_algorithm: string, operator_email?: string | null, requested_handle?: string | null): Promise<Record<string, unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* Begin TPM/HSM-based enrollment (sovereign/sovereign-portable tiers).
|
|
36
|
+
*/
|
|
37
|
+
enroll_begin(ek_certificate_pem: string, ak_public_key_pem: string, ak_tpmt_public_b64?: string, ek_public_key_pem?: string, ek_certificate_chain_pem?: string[], hsm_type?: string, operator_email?: string | null, requested_handle?: string | null): Promise<Record<string, unknown>>;
|
|
38
|
+
/**
|
|
39
|
+
* Complete TPM/HSM-based enrollment by proving HSM possession.
|
|
40
|
+
*/
|
|
41
|
+
enroll_activate(enrollment_session_id: string, decrypted_credential: string): Promise<Record<string, unknown>>;
|
|
42
|
+
/**
|
|
43
|
+
* Look up public identity information for an agent.
|
|
44
|
+
*/
|
|
45
|
+
get_identity(agent_id: string): Promise<Record<string, unknown>>;
|
|
46
|
+
/**
|
|
47
|
+
* Get an OAuth2 access token using the client_credentials grant.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: Keycloak token endpoint expects form-urlencoded, not JSON.
|
|
50
|
+
*/
|
|
51
|
+
get_token_with_client_credentials(client_id: string, client_secret: string): Promise<Record<string, unknown>>;
|
|
52
|
+
/**
|
|
53
|
+
* Check whether a vanity handle is available.
|
|
54
|
+
*/
|
|
55
|
+
check_handle_availability(handle_name: string): Promise<Record<string, unknown>>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA6FH;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,oBAAoB,EAAE,MAAM,CAAC;gBAG3C,YAAY,GAAE,MAA6B,EAC3C,oBAAoB,GAAE,MAA0C;IAMlE;;OAEG;YACW,aAAa;IAyB3B;;OAEG;IACG,eAAe,CACnB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,EAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAWnC;;OAEG;IACG,YAAY,CAChB,kBAAkB,EAAE,MAAM,EAC1B,iBAAiB,EAAE,MAAM,EACzB,kBAAkB,GAAE,MAAW,EAC/B,iBAAiB,GAAE,MAAW,EAC9B,wBAAwB,CAAC,EAAE,MAAM,EAAE,EACnC,QAAQ,GAAE,MAAc,EACxB,cAAc,CAAC,EAA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