1id 0.4.1 → 0.7.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.
Files changed (57) hide show
  1. package/README.md +3 -3
  2. package/dist/auth.d.ts +21 -13
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +126 -19
  5. package/dist/auth.js.map +1 -1
  6. package/dist/cli.js +1 -1
  7. package/dist/client.d.ts +7 -2
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +12 -3
  10. package/dist/client.js.map +1 -1
  11. package/dist/credentials.d.ts +8 -0
  12. package/dist/credentials.d.ts.map +1 -1
  13. package/dist/credentials.js +16 -0
  14. package/dist/credentials.js.map +1 -1
  15. package/dist/devices.d.ts +76 -0
  16. package/dist/devices.d.ts.map +1 -0
  17. package/dist/devices.js +103 -0
  18. package/dist/devices.js.map +1 -0
  19. package/dist/enroll.d.ts +5 -3
  20. package/dist/enroll.d.ts.map +1 -1
  21. package/dist/enroll.js +22 -16
  22. package/dist/enroll.js.map +1 -1
  23. package/dist/exceptions.d.ts +27 -0
  24. package/dist/exceptions.d.ts.map +1 -1
  25. package/dist/exceptions.js +35 -0
  26. package/dist/exceptions.js.map +1 -1
  27. package/dist/helper.d.ts +12 -0
  28. package/dist/helper.d.ts.map +1 -1
  29. package/dist/helper.js +21 -4
  30. package/dist/helper.js.map +1 -1
  31. package/dist/identity.d.ts +9 -9
  32. package/dist/identity.d.ts.map +1 -1
  33. package/dist/identity.js +9 -10
  34. package/dist/identity.js.map +1 -1
  35. package/dist/index.d.ts +70 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +93 -5
  38. package/dist/index.js.map +1 -1
  39. package/dist/test/test_declared_enrollment.js +2 -4
  40. package/dist/test/test_declared_enrollment.js.map +1 -1
  41. package/dist/test/test_peer_verification.d.ts +15 -0
  42. package/dist/test/test_peer_verification.d.ts.map +1 -0
  43. package/dist/test/test_peer_verification.js +481 -0
  44. package/dist/test/test_peer_verification.js.map +1 -0
  45. package/dist/trustRoots.d.ts +38 -0
  46. package/dist/trustRoots.d.ts.map +1 -0
  47. package/dist/trustRoots.js +145 -0
  48. package/dist/trustRoots.js.map +1 -0
  49. package/dist/verify.d.ts +71 -0
  50. package/dist/verify.d.ts.map +1 -0
  51. package/dist/verify.js +315 -0
  52. package/dist/verify.js.map +1 -0
  53. package/dist/world.d.ts +83 -0
  54. package/dist/world.d.ts.map +1 -0
  55. package/dist/world.js +122 -0
  56. package/dist/world.js.map +1 -0
  57. package/package.json +1 -1
package/dist/world.js ADDED
@@ -0,0 +1,122 @@
1
+ /**
2
+ * World/status endpoint for the 1id.com Node.js SDK.
3
+ *
4
+ * Fetches the full identity state from the server's world endpoint:
5
+ * identity, devices, connected services, available services, and operator guidance.
6
+ *
7
+ * Results are cached for 5 minutes. Call invalidate_world_cache() to force a fresh fetch.
8
+ */
9
+ import { load_credentials } from "./credentials.js";
10
+ import { get_token } from "./auth.js";
11
+ import { OneIDAPIClient } from "./client.js";
12
+ const WORLD_CACHE_TTL_MILLISECONDS = 5 * 60 * 1000;
13
+ let cached_world_status = null;
14
+ let cached_world_status_fetched_at = 0;
15
+ /**
16
+ * Fetch the full world state from the server.
17
+ *
18
+ * Returns everything: identity, devices, connected services, available services,
19
+ * and operator guidance. Results are cached for 5 minutes.
20
+ *
21
+ * @param credentials Optional pre-loaded credentials.
22
+ * @returns WorldStatus with complete identity state.
23
+ * @throws NotEnrolledError if no credentials exist.
24
+ * @throws AuthenticationError if the token is invalid or expired.
25
+ * @throws NetworkError if the server cannot be reached.
26
+ */
27
+ export async function fetch_world_status_from_server(credentials) {
28
+ if (cached_world_status != null) {
29
+ const elapsed_since_cached_fetch = Date.now() - cached_world_status_fetched_at;
30
+ if (elapsed_since_cached_fetch < WORLD_CACHE_TTL_MILLISECONDS) {
31
+ return cached_world_status;
32
+ }
33
+ }
34
+ if (credentials == null) {
35
+ credentials = load_credentials();
36
+ }
37
+ const token = await get_token(false, credentials);
38
+ const api_client = new OneIDAPIClient(credentials.api_base_url);
39
+ const world_data = await api_client.make_authenticated_request("GET", "/api/v1/identity/world", token.access_token);
40
+ const parsed_world_status = parse_world_response_to_world_status(world_data);
41
+ cached_world_status = parsed_world_status;
42
+ cached_world_status_fetched_at = Date.now();
43
+ return parsed_world_status;
44
+ }
45
+ /**
46
+ * Clear the cached world status, forcing a fresh fetch on next call.
47
+ */
48
+ export function invalidate_world_cache() {
49
+ cached_world_status = null;
50
+ cached_world_status_fetched_at = 0;
51
+ }
52
+ function parse_world_response_to_world_status(data) {
53
+ const raw_identity = (data.identity ?? {});
54
+ const raw_devices = (data.devices ?? []);
55
+ const raw_connected = (data.connected_services ?? []);
56
+ const raw_available = (data.available_services ?? []);
57
+ const raw_guidance = data.operator_guidance;
58
+ const identity = {
59
+ internal_id: (raw_identity.internal_id ?? raw_identity.agent_id ?? ""),
60
+ handle: (raw_identity.handle ?? ""),
61
+ trust_tier: (raw_identity.trust_tier ?? "declared"),
62
+ display_name: (raw_identity.display_name ?? null),
63
+ agent_identity_urn: (raw_identity.agent_identity_urn ?? null),
64
+ enrolled_at: (raw_identity.enrolled_at ?? null),
65
+ hardware_locked: Boolean(raw_identity.hardware_locked),
66
+ locked_at: (raw_identity.locked_at ?? null),
67
+ hardware_lock_notice: (raw_identity.hardware_lock_notice ?? null),
68
+ operator_email_registered: Boolean(raw_identity.operator_email_registered),
69
+ credential_pointer_count: (raw_identity.credential_pointer_count ?? 0),
70
+ };
71
+ const devices = raw_devices.map((device_data) => ({
72
+ device_type: (device_data.device_type ?? ""),
73
+ device_fingerprint: (device_data.device_fingerprint ?? ""),
74
+ device_status: (device_data.device_status ?? "active"),
75
+ trust_tier: (device_data.trust_tier ?? null),
76
+ tpm_manufacturer: (device_data.tpm_manufacturer ?? null),
77
+ piv_serial: (device_data.piv_serial ?? null),
78
+ bound_at: (device_data.bound_at ?? null),
79
+ burned_at: (device_data.burned_at ?? null),
80
+ burn_reason: (device_data.burn_reason ?? null),
81
+ }));
82
+ const connected_services = raw_connected.map(parse_service_entry_from_raw_data);
83
+ const available_services = raw_available.map(parse_service_entry_from_raw_data);
84
+ let operator_guidance = null;
85
+ if (raw_guidance != null) {
86
+ const raw_items = (raw_guidance.items ?? []);
87
+ operator_guidance = {
88
+ message_for_human: (raw_guidance.message_for_human ?? ""),
89
+ items: raw_items.map((item_data) => ({
90
+ id: (item_data.id ?? ""),
91
+ priority: (item_data.priority ?? "recommended"),
92
+ title: (item_data.title ?? ""),
93
+ description: (item_data.description ?? ""),
94
+ human_action_url: (item_data.human_action_url ?? null),
95
+ agent_api_endpoint: (item_data.agent_api_endpoint ?? null),
96
+ })),
97
+ };
98
+ }
99
+ return {
100
+ identity,
101
+ devices,
102
+ connected_services,
103
+ available_services,
104
+ operator_guidance,
105
+ raw_data: data,
106
+ };
107
+ }
108
+ function parse_service_entry_from_raw_data(raw) {
109
+ return {
110
+ service_id: (raw.service_id ?? ""),
111
+ service_name: (raw.service_name ?? ""),
112
+ service_type: (raw.service_type ?? null),
113
+ category: (raw.category ?? null),
114
+ status: (raw.status ?? raw.account_status ?? null),
115
+ primary_identifier: (raw.primary_identifier ?? null),
116
+ aliases: (raw.aliases ?? null),
117
+ dashboard_url: (raw.dashboard_url ?? null),
118
+ description: (raw.description ?? null),
119
+ minimum_trust_tier: (raw.minimum_trust_tier ?? null),
120
+ };
121
+ }
122
+ //# sourceMappingURL=world.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.js","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAA0B,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,4BAA4B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAgEnD,IAAI,mBAAmB,GAAuB,IAAI,CAAC;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AAQ;QACR,OAAO;QACP,kBAAkB;QAClB,kBAAkB;QAClB,iBAAiB;QACjB,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC;AAED,SAAS,iCAAiC,CAAC,GAA4B;IACrE,OAAO;QACL,UAAU,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAW;QAC5C,YAAY,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAW;QAChD,YAAY,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAkB;QACzD,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAkB;QACjD,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,cAAc,IAAI,IAAI,CAAkB;QACnE,kBAAkB,EAAE,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAkB;QACrE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAoB;QACjD,aAAa,EAAE,CAAC,GAAG,CAAC,aAAa,IAAI,IAAI,CAAkB;QAC3D,WAAW,EAAE,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,CAAkB;QACvD,kBAAkB,EAAE,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAkB;KACtE,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "1id",
3
- "version": "0.4.1",
3
+ "version": "0.7.0",
4
4
  "description": "Hardware-anchored identity SDK for AI agents -- 1id.com",
5
5
  "keywords": [
6
6
  "identity",