@vess-id/ai-identity 0.1.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 +76 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { VerifiablePresentation, VPRequest, Agent, DIDDocument, VCTemplate, ConnectorResponse, ToolPermissionRequest, OrganizationConfig, Grant, CreateGrantRequest, GrantStatus, CheckGrantPermissionRequest, CheckGrantPermissionResult, UpdateGrantRequest, CredentialType, IssueSDJWTVCRequest, IssueSDJWTVCResult, VerifySDJWTVCResult, GrantConstraints, EvaluationContext, ConstraintEvaluationResult, ConstraintViolation, ConstraintWarning, TimeWindowConstraint, RiskLevel } from '@vess-id/ai-identity-types';
|
|
2
2
|
export * from '@vess-id/ai-identity-types';
|
|
3
|
-
import Ajv from 'ajv';
|
|
4
3
|
import * as jose from 'jose';
|
|
5
4
|
import { JWK } from 'jose';
|
|
5
|
+
import Ajv from 'ajv';
|
|
6
6
|
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
7
7
|
import { DisclosureFrame } from '@sd-jwt/types';
|
|
8
8
|
|
|
@@ -730,6 +730,16 @@ declare class AgentDIDManager {
|
|
|
730
730
|
private deleteAgentDIDMapping;
|
|
731
731
|
}
|
|
732
732
|
|
|
733
|
+
interface KeyPairGenerationResult {
|
|
734
|
+
did: string;
|
|
735
|
+
publicKey: JWK;
|
|
736
|
+
privateKey: JWK;
|
|
737
|
+
}
|
|
738
|
+
declare class UserKeyPairManager {
|
|
739
|
+
generateKeyPair(): Promise<KeyPairGenerationResult>;
|
|
740
|
+
extractPublicKeyInfo(did: string): JWK;
|
|
741
|
+
}
|
|
742
|
+
|
|
733
743
|
interface OrganizationDisclosureConfig {
|
|
734
744
|
organizationDid: string;
|
|
735
745
|
defaultFields: string[];
|
|
@@ -2999,6 +3009,70 @@ declare function isValidDidJwk(did: string): boolean;
|
|
|
2999
3009
|
*/
|
|
3000
3010
|
declare function getKeyIdFromDid(did: string): string;
|
|
3001
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
|
+
|
|
3002
3076
|
declare const version = "0.0.1";
|
|
3003
3077
|
|
|
3004
|
-
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 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, 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { VerifiablePresentation, VPRequest, Agent, DIDDocument, VCTemplate, ConnectorResponse, ToolPermissionRequest, OrganizationConfig, Grant, CreateGrantRequest, GrantStatus, CheckGrantPermissionRequest, CheckGrantPermissionResult, UpdateGrantRequest, CredentialType, IssueSDJWTVCRequest, IssueSDJWTVCResult, VerifySDJWTVCResult, GrantConstraints, EvaluationContext, ConstraintEvaluationResult, ConstraintViolation, ConstraintWarning, TimeWindowConstraint, RiskLevel } from '@vess-id/ai-identity-types';
|
|
2
2
|
export * from '@vess-id/ai-identity-types';
|
|
3
|
-
import Ajv from 'ajv';
|
|
4
3
|
import * as jose from 'jose';
|
|
5
4
|
import { JWK } from 'jose';
|
|
5
|
+
import Ajv from 'ajv';
|
|
6
6
|
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
7
7
|
import { DisclosureFrame } from '@sd-jwt/types';
|
|
8
8
|
|
|
@@ -730,6 +730,16 @@ declare class AgentDIDManager {
|
|
|
730
730
|
private deleteAgentDIDMapping;
|
|
731
731
|
}
|
|
732
732
|
|
|
733
|
+
interface KeyPairGenerationResult {
|
|
734
|
+
did: string;
|
|
735
|
+
publicKey: JWK;
|
|
736
|
+
privateKey: JWK;
|
|
737
|
+
}
|
|
738
|
+
declare class UserKeyPairManager {
|
|
739
|
+
generateKeyPair(): Promise<KeyPairGenerationResult>;
|
|
740
|
+
extractPublicKeyInfo(did: string): JWK;
|
|
741
|
+
}
|
|
742
|
+
|
|
733
743
|
interface OrganizationDisclosureConfig {
|
|
734
744
|
organizationDid: string;
|
|
735
745
|
defaultFields: string[];
|
|
@@ -2999,6 +3009,70 @@ declare function isValidDidJwk(did: string): boolean;
|
|
|
2999
3009
|
*/
|
|
3000
3010
|
declare function getKeyIdFromDid(did: string): string;
|
|
3001
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
|
+
|
|
3002
3076
|
declare const version = "0.0.1";
|
|
3003
3077
|
|
|
3004
|
-
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 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, 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,
|
|
@@ -52,6 +53,7 @@ __export(index_exports, {
|
|
|
52
53
|
SimpleRebac: () => SimpleRebac,
|
|
53
54
|
ToolManager: () => ToolManager,
|
|
54
55
|
UserIdentityManager: () => UserIdentityManager,
|
|
56
|
+
UserKeyPairManager: () => UserKeyPairManager,
|
|
55
57
|
VCManager: () => VCManager,
|
|
56
58
|
VPManager: () => VPManager,
|
|
57
59
|
checkPermissionWithVP: () => checkPermissionWithVP,
|
|
@@ -2811,6 +2813,163 @@ function getClient(config, password) {
|
|
|
2811
2813
|
return defaultClient;
|
|
2812
2814
|
}
|
|
2813
2815
|
|
|
2816
|
+
// src/identity/user-key-pair-manager.ts
|
|
2817
|
+
var UserKeyPairManager = class {
|
|
2818
|
+
/**
|
|
2819
|
+
* Generate a new key pair and create a did:jwk DID
|
|
2820
|
+
*/
|
|
2821
|
+
async generateKeyPair() {
|
|
2822
|
+
const keyPair = await SDJwtClient.generateKeyPair();
|
|
2823
|
+
const did = createDidJwk(keyPair.publicKey);
|
|
2824
|
+
return {
|
|
2825
|
+
did,
|
|
2826
|
+
publicKey: keyPair.publicKey,
|
|
2827
|
+
privateKey: keyPair.privateKey
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* Extract public key info from a did:jwk DID
|
|
2832
|
+
* @throws Error if the DID is not in did:jwk format
|
|
2833
|
+
*/
|
|
2834
|
+
extractPublicKeyInfo(did) {
|
|
2835
|
+
if (!did.startsWith("did:jwk:")) {
|
|
2836
|
+
throw new Error("Only did:jwk format is supported");
|
|
2837
|
+
}
|
|
2838
|
+
return extractPublicKeyFromDid(did);
|
|
2839
|
+
}
|
|
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
|
+
|
|
2814
2973
|
// src/vc/api-vc-manager.ts
|
|
2815
2974
|
var import_ai_identity_types2 = require("@vess-id/ai-identity-types");
|
|
2816
2975
|
|
|
@@ -4739,6 +4898,7 @@ var version = "0.0.1";
|
|
|
4739
4898
|
AgentManager,
|
|
4740
4899
|
AllowAllAbac,
|
|
4741
4900
|
ConstraintEvaluator,
|
|
4901
|
+
DeviceEnrollManager,
|
|
4742
4902
|
DisclosureConfigManager,
|
|
4743
4903
|
DummyCreds,
|
|
4744
4904
|
DummyVpVerifier,
|
|
@@ -4753,6 +4913,7 @@ var version = "0.0.1";
|
|
|
4753
4913
|
SimpleRebac,
|
|
4754
4914
|
ToolManager,
|
|
4755
4915
|
UserIdentityManager,
|
|
4916
|
+
UserKeyPairManager,
|
|
4756
4917
|
VCManager,
|
|
4757
4918
|
VPManager,
|
|
4758
4919
|
checkPermissionWithVP,
|