@vess-id/ai-identity 0.2.0 → 0.3.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/dist/index.d.mts CHANGED
@@ -3009,6 +3009,70 @@ declare function isValidDidJwk(did: string): boolean;
3009
3009
  */
3010
3010
  declare function getKeyIdFromDid(did: string): string;
3011
3011
 
3012
+ interface DeviceEnrollStartParams {
3013
+ rootDid: string;
3014
+ publicKeyJwk: {
3015
+ kty: string;
3016
+ crv: string;
3017
+ x: string;
3018
+ y?: string;
3019
+ use?: string;
3020
+ alg?: string;
3021
+ };
3022
+ clientInfo?: {
3023
+ deviceName?: string;
3024
+ os?: string;
3025
+ appVersion?: string;
3026
+ hostname?: string;
3027
+ [key: string]: any;
3028
+ };
3029
+ purpose?: string;
3030
+ }
3031
+
3032
+ interface DeviceEnrollServerSideParams {
3033
+ clientInfo?: {
3034
+ deviceName?: string;
3035
+ os?: string;
3036
+ appVersion?: string;
3037
+ hostname?: string;
3038
+ [key: string]: any;
3039
+ };
3040
+ purpose?: string;
3041
+ }
3042
+
3043
+ interface DeviceEnrollStartResult {
3044
+ requestId: string;
3045
+ userCode: string;
3046
+ verificationUrl: string;
3047
+ expiresAt: string;
3048
+ }
3049
+
3050
+ interface DeviceEnrollPollResult {
3051
+ status: 'pending' | 'approved' | 'expired' | 'denied';
3052
+ deviceSessionToken?: string;
3053
+ expiresAt?: string;
3054
+ rootDid?: string;
3055
+ }
3056
+
3057
+ declare class DeviceEnrollManager {
3058
+ constructor(baseUrl: string);
3059
+ startDeviceEnrollment(params: DeviceEnrollStartParams): Promise<DeviceEnrollStartResult>;
3060
+ startServerSideEnrollment(params: DeviceEnrollServerSideParams): Promise<DeviceEnrollStartResult>;
3061
+ pollDeviceEnrollment(requestId: string): Promise<DeviceEnrollPollResult>;
3062
+ enrollAndWait(
3063
+ params: DeviceEnrollStartParams,
3064
+ onUserCode: (info: DeviceEnrollStartResult) => void,
3065
+ pollIntervalMs?: number,
3066
+ maxPolls?: number
3067
+ ): Promise<DeviceEnrollPollResult>;
3068
+ enrollServerSideAndWait(
3069
+ params: DeviceEnrollServerSideParams,
3070
+ onUserCode: (info: DeviceEnrollStartResult) => void,
3071
+ pollIntervalMs?: number,
3072
+ maxPolls?: number
3073
+ ): Promise<DeviceEnrollPollResult>;
3074
+ }
3075
+
3012
3076
  declare const version = "0.0.1";
3013
3077
 
3014
- export { type ABACPolicyEngine, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, APIVCManager, type AbacDecision, type AbacInput, type ActionMeta, type ActionRegistry, AgentDIDManager, AgentManager, AllowAllAbac, type CapabilityMeta, type CheckPermissionInput, type CheckPermissionResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type CredentialDisclosureConfig, type CredentialRef, type CredentialStatusInfo, type CredentialStore, type DecisionTrace, DisclosureConfigManager, DummyCreds, DummyVpVerifier, FilesystemKeyStorage, type JsonSchema, KeyManager, type KeyPairGenerationResult, type KeyRotationConfig, type KeyRotationInfo, KeyRotationManager, type KeyStorageConfig, type KeyStorageProvider, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, MetricsManager, type OperationMetric, type OrganizationDisclosureConfig, type PlanDelegationInput, type PlanDelegationResult, type Provider, type ReBACChecker, type Relation, type ResourceRef, type ResourceScope, type ResourceType, type RevocationList, type RevocationListEntry, RevocationManager, type SDJWTMetrics, SDJwtClient, SimpleRebac, type ToolDefinition, ToolManager, UserIdentityManager, UserKeyPairManager, VCManager, VPManager, type VerifiedVcClaims, type VpVerifier, checkPermissionWithVP, configure, createAjv, createDidJwk, defaultConstraintEvaluator, evaluateConstraints, extractPublicKey, extractPublicKeyFromDid, generateKeyPair, generateNonce, getClient, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, indexActions, indexCapabilities, isValidDidJwk, loadActionRegistryFromFile, loadActionRegistryFromObject, planDelegationForVC, resolveActionsFromSelection, signJWT, validateRegistryObject, verifyJWT, version };
3078
+ export { type ABACPolicyEngine, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, APIVCManager, type AbacDecision, type AbacInput, type ActionMeta, type ActionRegistry, AgentDIDManager, AgentManager, AllowAllAbac, type CapabilityMeta, type CheckPermissionInput, type CheckPermissionResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type CredentialDisclosureConfig, type CredentialRef, type CredentialStatusInfo, type CredentialStore, type DecisionTrace, DeviceEnrollManager, type DeviceEnrollPollResult, type DeviceEnrollServerSideParams, type DeviceEnrollStartParams, type DeviceEnrollStartResult, DisclosureConfigManager, DummyCreds, DummyVpVerifier, FilesystemKeyStorage, type JsonSchema, KeyManager, type KeyPairGenerationResult, type KeyRotationConfig, type KeyRotationInfo, KeyRotationManager, type KeyStorageConfig, type KeyStorageProvider, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, MetricsManager, type OperationMetric, type OrganizationDisclosureConfig, type PlanDelegationInput, type PlanDelegationResult, type Provider, type ReBACChecker, type Relation, type ResourceRef, type ResourceScope, type ResourceType, type RevocationList, type RevocationListEntry, RevocationManager, type SDJWTMetrics, SDJwtClient, SimpleRebac, type ToolDefinition, ToolManager, UserIdentityManager, UserKeyPairManager, VCManager, VPManager, type VerifiedVcClaims, type VpVerifier, checkPermissionWithVP, configure, createAjv, createDidJwk, defaultConstraintEvaluator, evaluateConstraints, extractPublicKey, extractPublicKeyFromDid, generateKeyPair, generateNonce, getClient, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, indexActions, indexCapabilities, isValidDidJwk, loadActionRegistryFromFile, loadActionRegistryFromObject, planDelegationForVC, resolveActionsFromSelection, signJWT, validateRegistryObject, verifyJWT, version };
package/dist/index.d.ts CHANGED
@@ -3009,6 +3009,70 @@ declare function isValidDidJwk(did: string): boolean;
3009
3009
  */
3010
3010
  declare function getKeyIdFromDid(did: string): string;
3011
3011
 
3012
+ interface DeviceEnrollStartParams {
3013
+ rootDid: string;
3014
+ publicKeyJwk: {
3015
+ kty: string;
3016
+ crv: string;
3017
+ x: string;
3018
+ y?: string;
3019
+ use?: string;
3020
+ alg?: string;
3021
+ };
3022
+ clientInfo?: {
3023
+ deviceName?: string;
3024
+ os?: string;
3025
+ appVersion?: string;
3026
+ hostname?: string;
3027
+ [key: string]: any;
3028
+ };
3029
+ purpose?: string;
3030
+ }
3031
+
3032
+ interface DeviceEnrollServerSideParams {
3033
+ clientInfo?: {
3034
+ deviceName?: string;
3035
+ os?: string;
3036
+ appVersion?: string;
3037
+ hostname?: string;
3038
+ [key: string]: any;
3039
+ };
3040
+ purpose?: string;
3041
+ }
3042
+
3043
+ interface DeviceEnrollStartResult {
3044
+ requestId: string;
3045
+ userCode: string;
3046
+ verificationUrl: string;
3047
+ expiresAt: string;
3048
+ }
3049
+
3050
+ interface DeviceEnrollPollResult {
3051
+ status: 'pending' | 'approved' | 'expired' | 'denied';
3052
+ deviceSessionToken?: string;
3053
+ expiresAt?: string;
3054
+ rootDid?: string;
3055
+ }
3056
+
3057
+ declare class DeviceEnrollManager {
3058
+ constructor(baseUrl: string);
3059
+ startDeviceEnrollment(params: DeviceEnrollStartParams): Promise<DeviceEnrollStartResult>;
3060
+ startServerSideEnrollment(params: DeviceEnrollServerSideParams): Promise<DeviceEnrollStartResult>;
3061
+ pollDeviceEnrollment(requestId: string): Promise<DeviceEnrollPollResult>;
3062
+ enrollAndWait(
3063
+ params: DeviceEnrollStartParams,
3064
+ onUserCode: (info: DeviceEnrollStartResult) => void,
3065
+ pollIntervalMs?: number,
3066
+ maxPolls?: number
3067
+ ): Promise<DeviceEnrollPollResult>;
3068
+ enrollServerSideAndWait(
3069
+ params: DeviceEnrollServerSideParams,
3070
+ onUserCode: (info: DeviceEnrollStartResult) => void,
3071
+ pollIntervalMs?: number,
3072
+ maxPolls?: number
3073
+ ): Promise<DeviceEnrollPollResult>;
3074
+ }
3075
+
3012
3076
  declare const version = "0.0.1";
3013
3077
 
3014
- export { type ABACPolicyEngine, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, APIVCManager, type AbacDecision, type AbacInput, type ActionMeta, type ActionRegistry, AgentDIDManager, AgentManager, AllowAllAbac, type CapabilityMeta, type CheckPermissionInput, type CheckPermissionResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type CredentialDisclosureConfig, type CredentialRef, type CredentialStatusInfo, type CredentialStore, type DecisionTrace, DisclosureConfigManager, DummyCreds, DummyVpVerifier, FilesystemKeyStorage, type JsonSchema, KeyManager, type KeyPairGenerationResult, type KeyRotationConfig, type KeyRotationInfo, KeyRotationManager, type KeyStorageConfig, type KeyStorageProvider, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, MetricsManager, type OperationMetric, type OrganizationDisclosureConfig, type PlanDelegationInput, type PlanDelegationResult, type Provider, type ReBACChecker, type Relation, type ResourceRef, type ResourceScope, type ResourceType, type RevocationList, type RevocationListEntry, RevocationManager, type SDJWTMetrics, SDJwtClient, SimpleRebac, type ToolDefinition, ToolManager, UserIdentityManager, UserKeyPairManager, VCManager, VPManager, type VerifiedVcClaims, type VpVerifier, checkPermissionWithVP, configure, createAjv, createDidJwk, defaultConstraintEvaluator, evaluateConstraints, extractPublicKey, extractPublicKeyFromDid, generateKeyPair, generateNonce, getClient, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, indexActions, indexCapabilities, isValidDidJwk, loadActionRegistryFromFile, loadActionRegistryFromObject, planDelegationForVC, resolveActionsFromSelection, signJWT, validateRegistryObject, verifyJWT, version };
3078
+ export { type ABACPolicyEngine, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, APIVCManager, type AbacDecision, type AbacInput, type ActionMeta, type ActionRegistry, AgentDIDManager, AgentManager, AllowAllAbac, type CapabilityMeta, type CheckPermissionInput, type CheckPermissionResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type CredentialDisclosureConfig, type CredentialRef, type CredentialStatusInfo, type CredentialStore, type DecisionTrace, DeviceEnrollManager, type DeviceEnrollPollResult, type DeviceEnrollServerSideParams, type DeviceEnrollStartParams, type DeviceEnrollStartResult, DisclosureConfigManager, DummyCreds, DummyVpVerifier, FilesystemKeyStorage, type JsonSchema, KeyManager, type KeyPairGenerationResult, type KeyRotationConfig, type KeyRotationInfo, KeyRotationManager, type KeyStorageConfig, type KeyStorageProvider, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, MetricsManager, type OperationMetric, type OrganizationDisclosureConfig, type PlanDelegationInput, type PlanDelegationResult, type Provider, type ReBACChecker, type Relation, type ResourceRef, type ResourceScope, type ResourceType, type RevocationList, type RevocationListEntry, RevocationManager, type SDJWTMetrics, SDJwtClient, SimpleRebac, type ToolDefinition, ToolManager, UserIdentityManager, UserKeyPairManager, VCManager, VPManager, type VerifiedVcClaims, type VpVerifier, checkPermissionWithVP, configure, createAjv, createDidJwk, defaultConstraintEvaluator, evaluateConstraints, extractPublicKey, extractPublicKeyFromDid, generateKeyPair, generateNonce, getClient, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, indexActions, indexCapabilities, isValidDidJwk, loadActionRegistryFromFile, loadActionRegistryFromObject, planDelegationForVC, resolveActionsFromSelection, signJWT, validateRegistryObject, verifyJWT, version };
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  AgentManager: () => AgentManager,
39
39
  AllowAllAbac: () => AllowAllAbac,
40
40
  ConstraintEvaluator: () => ConstraintEvaluator,
41
+ DeviceEnrollManager: () => DeviceEnrollManager,
41
42
  DisclosureConfigManager: () => DisclosureConfigManager,
42
43
  DummyCreds: () => DummyCreds,
43
44
  DummyVpVerifier: () => DummyVpVerifier,
@@ -2838,6 +2839,137 @@ var UserKeyPairManager = class {
2838
2839
  }
2839
2840
  };
2840
2841
 
2842
+ // src/identity/device-enroll-manager.ts
2843
+ var DeviceEnrollManager = class {
2844
+ baseUrl;
2845
+ constructor(baseUrl) {
2846
+ this.baseUrl = baseUrl.replace(/\/+$/, "");
2847
+ }
2848
+ /**
2849
+ * Start the device enrollment flow.
2850
+ * Sends the root DID public key to the Gateway and gets a user code.
2851
+ *
2852
+ * @param params - Root DID public info and client metadata
2853
+ * @returns Request ID, user code, and verification URL
2854
+ */
2855
+ async startDeviceEnrollment(params) {
2856
+ const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
2857
+ method: "POST",
2858
+ headers: { "Content-Type": "application/json" },
2859
+ body: JSON.stringify({
2860
+ rootDid: params.rootDid,
2861
+ publicKeyJwk: params.publicKeyJwk,
2862
+ clientInfo: params.clientInfo,
2863
+ purpose: params.purpose || "root_did_enrollment"
2864
+ })
2865
+ });
2866
+ if (!response.ok) {
2867
+ const errorBody = await response.text();
2868
+ throw new Error(
2869
+ `Failed to start device enrollment: ${response.status} - ${errorBody}`
2870
+ );
2871
+ }
2872
+ const body = await response.json();
2873
+ if (!body.success) {
2874
+ throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
2875
+ }
2876
+ return body.data;
2877
+ }
2878
+ /**
2879
+ * Start the device enrollment flow with server-side DID generation.
2880
+ * The server generates the real key pair on approval (not at start time).
2881
+ * Use this for remote/cloud-managed mode.
2882
+ *
2883
+ * @param params - Client metadata (no DID or key needed)
2884
+ * @returns Request ID, user code, and verification URL
2885
+ */
2886
+ async startServerSideEnrollment(params) {
2887
+ const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
2888
+ method: "POST",
2889
+ headers: { "Content-Type": "application/json" },
2890
+ body: JSON.stringify({
2891
+ generateServerSide: true,
2892
+ clientInfo: params.clientInfo,
2893
+ purpose: params.purpose || "root_did_enrollment"
2894
+ })
2895
+ });
2896
+ if (!response.ok) {
2897
+ const errorBody = await response.text();
2898
+ throw new Error(
2899
+ `Failed to start device enrollment: ${response.status} - ${errorBody}`
2900
+ );
2901
+ }
2902
+ const body = await response.json();
2903
+ if (!body.success) {
2904
+ throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
2905
+ }
2906
+ return body.data;
2907
+ }
2908
+ /**
2909
+ * Poll for enrollment status.
2910
+ * Call this periodically after startDeviceEnrollment() to check if
2911
+ * the user has approved the enrollment in the web UI.
2912
+ *
2913
+ * @param requestId - The request ID from startDeviceEnrollment()
2914
+ * @returns Current status and token if approved
2915
+ */
2916
+ async pollDeviceEnrollment(requestId) {
2917
+ const response = await fetch(`${this.baseUrl}/api/v1/device/poll`, {
2918
+ method: "POST",
2919
+ headers: { "Content-Type": "application/json" },
2920
+ body: JSON.stringify({ requestId })
2921
+ });
2922
+ if (!response.ok) {
2923
+ const errorBody = await response.text();
2924
+ throw new Error(
2925
+ `Failed to poll device enrollment: ${response.status} - ${errorBody}`
2926
+ );
2927
+ }
2928
+ const body = await response.json();
2929
+ if (!body.success) {
2930
+ throw new Error(`Failed to poll device enrollment: ${JSON.stringify(body)}`);
2931
+ }
2932
+ return body.data;
2933
+ }
2934
+ /**
2935
+ * Convenience method: Start enrollment and poll until completion.
2936
+ * Returns the final result (approved, expired, or denied).
2937
+ *
2938
+ * @param params - Enrollment parameters (client-generated mode)
2939
+ * @param onUserCode - Callback when user code is available (present to user)
2940
+ * @param pollIntervalMs - Polling interval in ms (default: 3000)
2941
+ * @param maxPolls - Maximum number of poll attempts (default: 120)
2942
+ */
2943
+ async enrollAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
2944
+ const startResult = await this.startDeviceEnrollment(params);
2945
+ return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
2946
+ }
2947
+ /**
2948
+ * Convenience method: Start server-side enrollment and poll until completion.
2949
+ * Returns the final result including the server-generated rootDid on approval.
2950
+ *
2951
+ * @param params - Client metadata (server-generated mode)
2952
+ * @param onUserCode - Callback when user code is available (present to user)
2953
+ * @param pollIntervalMs - Polling interval in ms (default: 3000)
2954
+ * @param maxPolls - Maximum number of poll attempts (default: 120)
2955
+ */
2956
+ async enrollServerSideAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
2957
+ const startResult = await this.startServerSideEnrollment(params);
2958
+ return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
2959
+ }
2960
+ async pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls) {
2961
+ onUserCode(startResult);
2962
+ for (let i = 0; i < maxPolls; i++) {
2963
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
2964
+ const pollResult = await this.pollDeviceEnrollment(startResult.requestId);
2965
+ if (pollResult.status !== "pending") {
2966
+ return pollResult;
2967
+ }
2968
+ }
2969
+ return { status: "expired" };
2970
+ }
2971
+ };
2972
+
2841
2973
  // src/vc/api-vc-manager.ts
2842
2974
  var import_ai_identity_types2 = require("@vess-id/ai-identity-types");
2843
2975
 
@@ -4766,6 +4898,7 @@ var version = "0.0.1";
4766
4898
  AgentManager,
4767
4899
  AllowAllAbac,
4768
4900
  ConstraintEvaluator,
4901
+ DeviceEnrollManager,
4769
4902
  DisclosureConfigManager,
4770
4903
  DummyCreds,
4771
4904
  DummyVpVerifier,