@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.mjs
CHANGED
|
@@ -2746,6 +2746,163 @@ function getClient(config, password) {
|
|
|
2746
2746
|
return defaultClient;
|
|
2747
2747
|
}
|
|
2748
2748
|
|
|
2749
|
+
// src/identity/user-key-pair-manager.ts
|
|
2750
|
+
var UserKeyPairManager = class {
|
|
2751
|
+
/**
|
|
2752
|
+
* Generate a new key pair and create a did:jwk DID
|
|
2753
|
+
*/
|
|
2754
|
+
async generateKeyPair() {
|
|
2755
|
+
const keyPair = await SDJwtClient.generateKeyPair();
|
|
2756
|
+
const did = createDidJwk(keyPair.publicKey);
|
|
2757
|
+
return {
|
|
2758
|
+
did,
|
|
2759
|
+
publicKey: keyPair.publicKey,
|
|
2760
|
+
privateKey: keyPair.privateKey
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Extract public key info from a did:jwk DID
|
|
2765
|
+
* @throws Error if the DID is not in did:jwk format
|
|
2766
|
+
*/
|
|
2767
|
+
extractPublicKeyInfo(did) {
|
|
2768
|
+
if (!did.startsWith("did:jwk:")) {
|
|
2769
|
+
throw new Error("Only did:jwk format is supported");
|
|
2770
|
+
}
|
|
2771
|
+
return extractPublicKeyFromDid(did);
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
|
|
2775
|
+
// src/identity/device-enroll-manager.ts
|
|
2776
|
+
var DeviceEnrollManager = class {
|
|
2777
|
+
baseUrl;
|
|
2778
|
+
constructor(baseUrl) {
|
|
2779
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* Start the device enrollment flow.
|
|
2783
|
+
* Sends the root DID public key to the Gateway and gets a user code.
|
|
2784
|
+
*
|
|
2785
|
+
* @param params - Root DID public info and client metadata
|
|
2786
|
+
* @returns Request ID, user code, and verification URL
|
|
2787
|
+
*/
|
|
2788
|
+
async startDeviceEnrollment(params) {
|
|
2789
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
|
|
2790
|
+
method: "POST",
|
|
2791
|
+
headers: { "Content-Type": "application/json" },
|
|
2792
|
+
body: JSON.stringify({
|
|
2793
|
+
rootDid: params.rootDid,
|
|
2794
|
+
publicKeyJwk: params.publicKeyJwk,
|
|
2795
|
+
clientInfo: params.clientInfo,
|
|
2796
|
+
purpose: params.purpose || "root_did_enrollment"
|
|
2797
|
+
})
|
|
2798
|
+
});
|
|
2799
|
+
if (!response.ok) {
|
|
2800
|
+
const errorBody = await response.text();
|
|
2801
|
+
throw new Error(
|
|
2802
|
+
`Failed to start device enrollment: ${response.status} - ${errorBody}`
|
|
2803
|
+
);
|
|
2804
|
+
}
|
|
2805
|
+
const body = await response.json();
|
|
2806
|
+
if (!body.success) {
|
|
2807
|
+
throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
|
|
2808
|
+
}
|
|
2809
|
+
return body.data;
|
|
2810
|
+
}
|
|
2811
|
+
/**
|
|
2812
|
+
* Start the device enrollment flow with server-side DID generation.
|
|
2813
|
+
* The server generates the real key pair on approval (not at start time).
|
|
2814
|
+
* Use this for remote/cloud-managed mode.
|
|
2815
|
+
*
|
|
2816
|
+
* @param params - Client metadata (no DID or key needed)
|
|
2817
|
+
* @returns Request ID, user code, and verification URL
|
|
2818
|
+
*/
|
|
2819
|
+
async startServerSideEnrollment(params) {
|
|
2820
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/start`, {
|
|
2821
|
+
method: "POST",
|
|
2822
|
+
headers: { "Content-Type": "application/json" },
|
|
2823
|
+
body: JSON.stringify({
|
|
2824
|
+
generateServerSide: true,
|
|
2825
|
+
clientInfo: params.clientInfo,
|
|
2826
|
+
purpose: params.purpose || "root_did_enrollment"
|
|
2827
|
+
})
|
|
2828
|
+
});
|
|
2829
|
+
if (!response.ok) {
|
|
2830
|
+
const errorBody = await response.text();
|
|
2831
|
+
throw new Error(
|
|
2832
|
+
`Failed to start device enrollment: ${response.status} - ${errorBody}`
|
|
2833
|
+
);
|
|
2834
|
+
}
|
|
2835
|
+
const body = await response.json();
|
|
2836
|
+
if (!body.success) {
|
|
2837
|
+
throw new Error(`Failed to start device enrollment: ${JSON.stringify(body)}`);
|
|
2838
|
+
}
|
|
2839
|
+
return body.data;
|
|
2840
|
+
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Poll for enrollment status.
|
|
2843
|
+
* Call this periodically after startDeviceEnrollment() to check if
|
|
2844
|
+
* the user has approved the enrollment in the web UI.
|
|
2845
|
+
*
|
|
2846
|
+
* @param requestId - The request ID from startDeviceEnrollment()
|
|
2847
|
+
* @returns Current status and token if approved
|
|
2848
|
+
*/
|
|
2849
|
+
async pollDeviceEnrollment(requestId) {
|
|
2850
|
+
const response = await fetch(`${this.baseUrl}/api/v1/device/poll`, {
|
|
2851
|
+
method: "POST",
|
|
2852
|
+
headers: { "Content-Type": "application/json" },
|
|
2853
|
+
body: JSON.stringify({ requestId })
|
|
2854
|
+
});
|
|
2855
|
+
if (!response.ok) {
|
|
2856
|
+
const errorBody = await response.text();
|
|
2857
|
+
throw new Error(
|
|
2858
|
+
`Failed to poll device enrollment: ${response.status} - ${errorBody}`
|
|
2859
|
+
);
|
|
2860
|
+
}
|
|
2861
|
+
const body = await response.json();
|
|
2862
|
+
if (!body.success) {
|
|
2863
|
+
throw new Error(`Failed to poll device enrollment: ${JSON.stringify(body)}`);
|
|
2864
|
+
}
|
|
2865
|
+
return body.data;
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
* Convenience method: Start enrollment and poll until completion.
|
|
2869
|
+
* Returns the final result (approved, expired, or denied).
|
|
2870
|
+
*
|
|
2871
|
+
* @param params - Enrollment parameters (client-generated mode)
|
|
2872
|
+
* @param onUserCode - Callback when user code is available (present to user)
|
|
2873
|
+
* @param pollIntervalMs - Polling interval in ms (default: 3000)
|
|
2874
|
+
* @param maxPolls - Maximum number of poll attempts (default: 120)
|
|
2875
|
+
*/
|
|
2876
|
+
async enrollAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
|
|
2877
|
+
const startResult = await this.startDeviceEnrollment(params);
|
|
2878
|
+
return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Convenience method: Start server-side enrollment and poll until completion.
|
|
2882
|
+
* Returns the final result including the server-generated rootDid on approval.
|
|
2883
|
+
*
|
|
2884
|
+
* @param params - Client metadata (server-generated mode)
|
|
2885
|
+
* @param onUserCode - Callback when user code is available (present to user)
|
|
2886
|
+
* @param pollIntervalMs - Polling interval in ms (default: 3000)
|
|
2887
|
+
* @param maxPolls - Maximum number of poll attempts (default: 120)
|
|
2888
|
+
*/
|
|
2889
|
+
async enrollServerSideAndWait(params, onUserCode, pollIntervalMs = 3e3, maxPolls = 120) {
|
|
2890
|
+
const startResult = await this.startServerSideEnrollment(params);
|
|
2891
|
+
return this.pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls);
|
|
2892
|
+
}
|
|
2893
|
+
async pollUntilComplete(startResult, onUserCode, pollIntervalMs, maxPolls) {
|
|
2894
|
+
onUserCode(startResult);
|
|
2895
|
+
for (let i = 0; i < maxPolls; i++) {
|
|
2896
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
2897
|
+
const pollResult = await this.pollDeviceEnrollment(startResult.requestId);
|
|
2898
|
+
if (pollResult.status !== "pending") {
|
|
2899
|
+
return pollResult;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
return { status: "expired" };
|
|
2903
|
+
}
|
|
2904
|
+
};
|
|
2905
|
+
|
|
2749
2906
|
// src/vc/api-vc-manager.ts
|
|
2750
2907
|
import {
|
|
2751
2908
|
CredentialType as CredentialType2
|
|
@@ -4675,6 +4832,7 @@ export {
|
|
|
4675
4832
|
AgentManager,
|
|
4676
4833
|
AllowAllAbac,
|
|
4677
4834
|
ConstraintEvaluator,
|
|
4835
|
+
DeviceEnrollManager,
|
|
4678
4836
|
DisclosureConfigManager,
|
|
4679
4837
|
DummyCreds,
|
|
4680
4838
|
DummyVpVerifier,
|
|
@@ -4689,6 +4847,7 @@ export {
|
|
|
4689
4847
|
SimpleRebac,
|
|
4690
4848
|
ToolManager,
|
|
4691
4849
|
UserIdentityManager,
|
|
4850
|
+
UserKeyPairManager,
|
|
4692
4851
|
VCManager,
|
|
4693
4852
|
VPManager,
|
|
4694
4853
|
checkPermissionWithVP,
|