@absolutejs/auth 0.38.0 → 0.40.0-beta.1

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.
@@ -1,6 +1,7 @@
1
1
  import type { RouteString } from '../types';
2
2
  import { type SigningKey } from './keys';
3
3
  import type { OnClientRegistration } from './registration';
4
+ import type { VciConfig } from './vci';
4
5
  import type { AuthorizationCodeStore, BackchannelAuthStore, ClientAssertionJtiStore, ClientRegistrationTokenStore, DeviceAuthorizationStore, InitialAccessTokenStore, LogoutDeliveryStore, OAuthClient, OAuthClientStore, OidcRefreshTokenStore, PushedAuthorizationRequestStore } from './types';
5
6
  export declare const DEFAULT_OIDC_ROUTE: RouteString;
6
7
  export type OidcProviderConfig<UserType> = {
@@ -66,6 +67,7 @@ export type OidcProviderConfig<UserType> = {
66
67
  refreshTokenStore: OidcRefreshTokenStore;
67
68
  refreshTokenTtlMs?: number;
68
69
  signingKey: SigningKey;
70
+ vciConfig?: VciConfig;
69
71
  };
70
72
  export type TokenExchangeResult = {
71
73
  error: 'invalid_grant' | 'invalid_scope';
@@ -0,0 +1,3 @@
1
+ import type { CredentialNonceStore, CredentialOfferStore } from './vci';
2
+ export declare const createInMemoryCredentialNonceStore: () => CredentialNonceStore;
3
+ export declare const createInMemoryCredentialOfferStore: () => CredentialOfferStore;
@@ -76,6 +76,7 @@ export declare const oidcProviderRoutes: <UserType>(config: OidcProviderConfig<U
76
76
  client_assertion?: string | undefined;
77
77
  client_assertion_type?: string | undefined;
78
78
  code_verifier?: string | undefined;
79
+ 'pre-authorized_code'?: string | undefined;
79
80
  subject_token?: string | undefined;
80
81
  subject_token_type?: string | undefined;
81
82
  };
@@ -0,0 +1,159 @@
1
+ import type { RouteString } from '../types';
2
+ import { type SigningKey } from './keys';
3
+ export declare const PRE_AUTHORIZED_CODE_GRANT = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
4
+ export type CredentialConfiguration = {
5
+ format: 'vc+sd-jwt';
6
+ id: string;
7
+ display?: Array<{
8
+ locale?: string;
9
+ name: string;
10
+ }>;
11
+ order?: string[];
12
+ claims?: Record<string, {
13
+ display?: Array<{
14
+ locale?: string;
15
+ name: string;
16
+ }>;
17
+ }>;
18
+ vct: string;
19
+ };
20
+ export type CredentialOffer = {
21
+ clientId: string;
22
+ configurationId: string;
23
+ createdAt: number;
24
+ expiresAt: number;
25
+ preAuthorizedCodeHash: string;
26
+ redeemed: boolean;
27
+ userId: string;
28
+ };
29
+ export type CredentialOfferStore = {
30
+ consumeOffer: (preAuthorizedCodeHash: string) => Promise<CredentialOffer | undefined>;
31
+ saveOffer: (offer: CredentialOffer) => Promise<void>;
32
+ };
33
+ export type CredentialNonceRecord = {
34
+ expiresAt: number;
35
+ nonceHash: string;
36
+ };
37
+ export type CredentialNonceStore = {
38
+ consumeNonce: (nonceHash: string) => Promise<CredentialNonceRecord | undefined>;
39
+ saveNonce: (record: CredentialNonceRecord) => Promise<void>;
40
+ };
41
+ export type VciConfig = {
42
+ accessTokenTtlMs?: number;
43
+ credentialConfigurations: CredentialConfiguration[];
44
+ credentialNonceStore?: CredentialNonceStore;
45
+ credentialOfferStore: CredentialOfferStore;
46
+ nonceTtlMs?: number;
47
+ offerTtlMs?: number;
48
+ resolveCredentialClaims: (context: {
49
+ configurationId: string;
50
+ userId: string;
51
+ }) => Promise<Record<string, unknown>> | Record<string, unknown>;
52
+ resolveProtectedClaims?: (context: {
53
+ configurationId: string;
54
+ userId: string;
55
+ }) => Promise<Record<string, unknown>> | Record<string, unknown>;
56
+ signingKey?: SigningKey;
57
+ vciRoute?: RouteString;
58
+ };
59
+ export declare const DEFAULT_VCI_ROUTE: RouteString;
60
+ export declare const createCredentialOffer: ({ clientId, configurationId, now, store, ttlMs, userId }: {
61
+ clientId: string;
62
+ configurationId: string;
63
+ now?: number;
64
+ store: CredentialOfferStore;
65
+ ttlMs?: number;
66
+ userId: string;
67
+ }) => Promise<{
68
+ offer: CredentialOffer;
69
+ preAuthorizedCode: string;
70
+ }>;
71
+ export type PreAuthExchangeResult = {
72
+ error: 'expired_token' | 'invalid_grant';
73
+ ok: false;
74
+ } | {
75
+ access_token: string;
76
+ c_nonce?: string;
77
+ c_nonce_expires_in?: number;
78
+ expires_in: number;
79
+ ok: true;
80
+ token_type: 'Bearer';
81
+ };
82
+ export declare const exchangePreAuthorizedCode: ({ config, issuer, now, preAuthorizedCode, signingKey }: {
83
+ config: VciConfig;
84
+ issuer: string;
85
+ now?: number;
86
+ preAuthorizedCode: string;
87
+ signingKey: SigningKey;
88
+ }) => Promise<{
89
+ error: "expired_token" | "invalid_grant";
90
+ ok: false;
91
+ } | {
92
+ access_token: string;
93
+ c_nonce?: string;
94
+ c_nonce_expires_in?: number;
95
+ expires_in: number;
96
+ ok: true;
97
+ token_type: "Bearer";
98
+ }>;
99
+ export type CredentialIssueInput = {
100
+ accessToken: string;
101
+ proofJwt?: string;
102
+ requestedFormat?: 'vc+sd-jwt';
103
+ };
104
+ export type CredentialIssueResult = {
105
+ credential: string;
106
+ format: 'vc+sd-jwt';
107
+ ok: true;
108
+ } | {
109
+ error: 'invalid_credential_request' | 'invalid_proof' | 'invalid_token' | 'unsupported_credential_format';
110
+ ok: false;
111
+ };
112
+ export declare const buildIssuerMetadata: ({ config, issuer, vciRoute }: {
113
+ config: VciConfig;
114
+ issuer: string;
115
+ vciRoute: RouteString;
116
+ }) => {
117
+ credential_configurations_supported: {
118
+ [k: string]: {
119
+ claims: Record<string, {
120
+ display?: Array<{
121
+ locale?: string;
122
+ name: string;
123
+ }>;
124
+ }> | undefined;
125
+ credential_signing_alg_values_supported: string[];
126
+ cryptographic_binding_methods_supported: string[];
127
+ display: {
128
+ locale?: string;
129
+ name: string;
130
+ }[] | undefined;
131
+ format: "vc+sd-jwt";
132
+ order: string[] | undefined;
133
+ proof_types_supported: {
134
+ jwt: {
135
+ proof_signing_alg_values_supported: string[];
136
+ };
137
+ };
138
+ vct: string;
139
+ };
140
+ };
141
+ credential_endpoint: string;
142
+ credential_issuer: string;
143
+ nonce_endpoint: string | undefined;
144
+ token_endpoint: string;
145
+ };
146
+ export declare const issueCredential: ({ config, input, issuer, now, signingKey }: {
147
+ config: VciConfig;
148
+ input: CredentialIssueInput;
149
+ issuer: string;
150
+ now?: number;
151
+ signingKey: SigningKey;
152
+ }) => Promise<{
153
+ credential: string;
154
+ format: "vc+sd-jwt";
155
+ ok: true;
156
+ } | {
157
+ error: "invalid_credential_request" | "invalid_proof" | "invalid_token" | "unsupported_credential_format";
158
+ ok: false;
159
+ }>;
@@ -0,0 +1,92 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { SigningKey } from './keys';
3
+ import { type VciConfig } from './vci';
4
+ export declare const vciRoutes: ({ issuerUrl, signingKey, vciConfig }: {
5
+ issuerUrl: string;
6
+ signingKey: SigningKey;
7
+ vciConfig: VciConfig;
8
+ }) => Elysia<"", {
9
+ decorator: {};
10
+ store: {};
11
+ derive: {};
12
+ resolve: {};
13
+ }, {
14
+ typebox: {};
15
+ error: {};
16
+ }, {
17
+ schema: {};
18
+ standaloneSchema: {};
19
+ macro: {};
20
+ macroFn: {};
21
+ parser: {};
22
+ response: {};
23
+ }, {
24
+ ".well-known": {
25
+ "openid-credential-issuer": {
26
+ get: {
27
+ body: unknown;
28
+ params: {};
29
+ query: unknown;
30
+ headers: unknown;
31
+ response: {
32
+ 200: Response;
33
+ };
34
+ };
35
+ };
36
+ };
37
+ } & {
38
+ [x: string]: {
39
+ credential: {
40
+ post: {
41
+ body: {
42
+ format?: "vc+sd-jwt" | undefined;
43
+ proof?: {
44
+ jwt: string;
45
+ proof_type: "jwt";
46
+ } | undefined;
47
+ };
48
+ params: {};
49
+ query: unknown;
50
+ headers: unknown;
51
+ response: {
52
+ 200: Response;
53
+ 422: {
54
+ type: "validation";
55
+ on: string;
56
+ summary?: string;
57
+ message?: string;
58
+ found?: unknown;
59
+ property?: string;
60
+ expected?: string;
61
+ };
62
+ };
63
+ };
64
+ };
65
+ };
66
+ } & {
67
+ [x: string]: {
68
+ nonce: {
69
+ post: {
70
+ body: unknown;
71
+ params: {};
72
+ query: unknown;
73
+ headers: unknown;
74
+ response: {
75
+ 200: Response;
76
+ };
77
+ };
78
+ };
79
+ };
80
+ }, {
81
+ derive: {};
82
+ resolve: {};
83
+ schema: {};
84
+ standaloneSchema: {};
85
+ response: {};
86
+ }, {
87
+ derive: {};
88
+ resolve: {};
89
+ schema: {};
90
+ standaloneSchema: {};
91
+ response: {};
92
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { PresentationRequestStore } from './openid4vp';
2
+ export declare const createInMemoryPresentationRequestStore: () => PresentationRequestStore;
@@ -0,0 +1,82 @@
1
+ import { type SigningKey } from '../oidc/keys';
2
+ export type PresentationResponseInput = {
3
+ requestId: string;
4
+ vpToken: string;
5
+ };
6
+ export type PresentationRequest = {
7
+ clientId: string;
8
+ createdAt: number;
9
+ expectedIssuerPublicJwk: JsonWebKey;
10
+ expiresAt: number;
11
+ nonce: string;
12
+ requestedClaims: string[];
13
+ requestId: string;
14
+ responseUri: string;
15
+ state: string | undefined;
16
+ };
17
+ export type PresentationRequestStore = {
18
+ consumeRequest: (requestId: string) => Promise<PresentationRequest | undefined>;
19
+ getRequest: (requestId: string) => Promise<PresentationRequest | undefined>;
20
+ saveRequest: (request: PresentationRequest) => Promise<void>;
21
+ };
22
+ export type Vp4Config = {
23
+ clientSigningKey: SigningKey;
24
+ defaultExpectedIssuerPublicJwk: JsonWebKey;
25
+ getResponseUri: (requestId: string) => string;
26
+ requestStore: PresentationRequestStore;
27
+ requestTtlMs?: number;
28
+ statusListResolver?: (uri: string) => Promise<string | undefined>;
29
+ statusListPublicJwk?: JsonWebKey;
30
+ };
31
+ export type CreatePresentationRequestInput = {
32
+ clientId: string;
33
+ now?: number;
34
+ requestedClaims: string[];
35
+ state?: string;
36
+ };
37
+ export declare const createPresentationRequest: ({ config, getRequestUri, input, issuer }: {
38
+ config: Vp4Config;
39
+ getRequestUri: (requestId: string) => string;
40
+ input: CreatePresentationRequestInput;
41
+ issuer: string;
42
+ }) => Promise<{
43
+ nonce: string;
44
+ request: PresentationRequest;
45
+ requestObject: string;
46
+ requestUri: string;
47
+ }>;
48
+ export type VerifiedPresentation = {
49
+ disclosedClaims: Record<string, unknown>;
50
+ holderJwk: JsonWebKey | undefined;
51
+ missingClaims: string[];
52
+ protectedClaims: Record<string, unknown>;
53
+ requestId: string;
54
+ statusValid: boolean;
55
+ };
56
+ export type PresentationVerifyError = 'expired_request' | 'invalid_holder_binding' | 'invalid_signature' | 'missing_claims' | 'revoked_credential' | 'unknown_request';
57
+ export type PresentationVerifyResult = {
58
+ error: PresentationVerifyError;
59
+ ok: false;
60
+ } | {
61
+ ok: true;
62
+ verified: VerifiedPresentation;
63
+ };
64
+ export declare const verifyPresentationResponse: ({ config, input, now }: {
65
+ config: Vp4Config;
66
+ input: PresentationResponseInput;
67
+ now?: number;
68
+ }) => Promise<{
69
+ error: PresentationVerifyError;
70
+ ok: false;
71
+ } | {
72
+ ok: true;
73
+ verified: VerifiedPresentation;
74
+ }>;
75
+ export declare const buildHolderKeyBindingJwt: ({ audience, holderKey, nonce, now, sdHash }: {
76
+ audience: string;
77
+ holderKey: SigningKey;
78
+ nonce: string;
79
+ now?: number;
80
+ sdHash?: string;
81
+ }) => Promise<string>;
82
+ export declare const parsePresentationToken: (vpToken: string) => import("./sdJwt").ParsedSdJwtVc;
@@ -0,0 +1,37 @@
1
+ import { type SigningKey } from '../oidc/keys';
2
+ declare const toBase64Url: (bytes: ArrayBuffer | Uint8Array) => string;
3
+ declare const fromBase64Url: (value: string) => Uint8Array<ArrayBuffer>;
4
+ export type SdDisclosure = {
5
+ claimName: string;
6
+ claimValue: unknown;
7
+ encoded: string;
8
+ salt: string;
9
+ };
10
+ export type SdJwtVcIssueInput = {
11
+ base: Record<string, unknown>;
12
+ holderJwk?: JsonWebKey;
13
+ selective: Record<string, unknown>;
14
+ signingKey: SigningKey;
15
+ };
16
+ export declare const issueSdJwtVc: (input: SdJwtVcIssueInput) => Promise<string>;
17
+ export type ParsedSdJwtVc = {
18
+ disclosures: string[];
19
+ jwt: string;
20
+ keyBindingJwt: string | undefined;
21
+ };
22
+ export declare const parseSdJwtVc: (token: string) => ParsedSdJwtVc;
23
+ export declare const presentSdJwtVc: (parsed: ParsedSdJwtVc, selectedClaims: string[], keyBindingJwt?: string) => string;
24
+ export type VerifiedSdJwtVc = {
25
+ cnf: {
26
+ jwk: JsonWebKey;
27
+ } | undefined;
28
+ disclosedClaims: Record<string, unknown>;
29
+ keyBindingJwt: string | undefined;
30
+ protectedClaims: Record<string, unknown>;
31
+ };
32
+ export type SdJwtVcVerifyInput = {
33
+ issuerPublicJwk: JsonWebKey;
34
+ token: string;
35
+ };
36
+ export declare const verifySdJwtVc: (input: SdJwtVcVerifyInput) => Promise<VerifiedSdJwtVc | undefined>;
37
+ export { fromBase64Url, toBase64Url };
@@ -0,0 +1,29 @@
1
+ import { type SigningKey } from '../oidc/keys';
2
+ declare const STATUS_LIST_TYP = "statuslist+jwt";
3
+ declare const STATUS_LIST_SUB_TYP = "application/statuslist+jwt";
4
+ export type StatusListBits = Uint8Array;
5
+ export declare const createStatusList: (size?: number) => Uint8Array<ArrayBuffer>;
6
+ export declare const getCredentialStatus: (bits: StatusListBits, idx: number) => 1 | 0 | undefined;
7
+ export declare const setCredentialStatus: (bits: StatusListBits, idx: number, value: 0 | 1) => StatusListBits;
8
+ export declare const buildStatusClaim: (idx: number, uri: string) => {
9
+ status_list: {
10
+ idx: number;
11
+ uri: string;
12
+ };
13
+ };
14
+ export declare const signStatusList: ({ bits, issuer, listUri, now, signingKey, ttlSeconds }: {
15
+ bits: StatusListBits;
16
+ issuer: string;
17
+ listUri: string;
18
+ now?: number;
19
+ signingKey: SigningKey;
20
+ ttlSeconds?: number;
21
+ }) => Promise<string>;
22
+ export declare const verifyStatusListJwt: ({ issuerPublicJwk, token }: {
23
+ issuerPublicJwk: JsonWebKey;
24
+ token: string;
25
+ }) => Promise<{
26
+ bits: Uint8Array<ArrayBuffer>;
27
+ sub: string | undefined;
28
+ } | undefined>;
29
+ export { STATUS_LIST_SUB_TYP, STATUS_LIST_TYP };
@@ -0,0 +1,63 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { SigningKey } from '../oidc/keys';
3
+ import { type StatusListBits } from './statusList';
4
+ export declare const DEFAULT_STATUS_ROUTE = "/vc/status";
5
+ export declare const statusListRoutes: ({ getStatusList, issuerUrl, signingKey, statusRoute, ttlSeconds }: {
6
+ getStatusList: (listId: string) => Promise<StatusListBits | undefined> | StatusListBits | undefined;
7
+ issuerUrl: string;
8
+ signingKey: SigningKey;
9
+ statusRoute?: string;
10
+ ttlSeconds?: number;
11
+ }) => Elysia<"", {
12
+ decorator: {};
13
+ store: {};
14
+ derive: {};
15
+ resolve: {};
16
+ }, {
17
+ typebox: {};
18
+ error: {};
19
+ }, {
20
+ schema: {};
21
+ standaloneSchema: {};
22
+ macro: {};
23
+ macroFn: {};
24
+ parser: {};
25
+ response: {};
26
+ }, {
27
+ [x: string]: {
28
+ ":listId": {
29
+ get: {
30
+ body: unknown;
31
+ params: {
32
+ listId: string;
33
+ };
34
+ query: unknown;
35
+ headers: unknown;
36
+ response: {
37
+ 200: Response;
38
+ 422: {
39
+ type: "validation";
40
+ on: string;
41
+ summary?: string;
42
+ message?: string;
43
+ found?: unknown;
44
+ property?: string;
45
+ expected?: string;
46
+ };
47
+ };
48
+ };
49
+ };
50
+ };
51
+ }, {
52
+ derive: {};
53
+ resolve: {};
54
+ schema: {};
55
+ standaloneSchema: {};
56
+ response: {};
57
+ }, {
58
+ derive: {};
59
+ resolve: {};
60
+ schema: {};
61
+ standaloneSchema: {};
62
+ response: {};
63
+ }>;
@@ -0,0 +1,120 @@
1
+ import { Elysia } from 'elysia';
2
+ import { type VerifiedPresentation, type Vp4Config } from './openid4vp';
3
+ export declare const DEFAULT_VP_ROUTE = "/vp";
4
+ export declare const vpRoutes: ({ defaultClientId, issuerUrl, onVerifiedPresentation, vpConfig, vpRoute }: {
5
+ defaultClientId: string;
6
+ issuerUrl: string;
7
+ onVerifiedPresentation?: (context: {
8
+ verified: VerifiedPresentation;
9
+ }) => Promise<void> | void;
10
+ vpConfig: Vp4Config;
11
+ vpRoute?: string;
12
+ }) => Elysia<"", {
13
+ decorator: {};
14
+ store: {};
15
+ derive: {};
16
+ resolve: {};
17
+ }, {
18
+ typebox: {};
19
+ error: {};
20
+ }, {
21
+ schema: {};
22
+ standaloneSchema: {};
23
+ macro: {};
24
+ macroFn: {};
25
+ parser: {};
26
+ response: {};
27
+ }, {
28
+ [x: string]: {
29
+ authorize: {
30
+ post: {
31
+ body: {
32
+ client_id?: string | undefined;
33
+ state?: string | undefined;
34
+ requested_claims: string[];
35
+ };
36
+ params: {};
37
+ query: unknown;
38
+ headers: unknown;
39
+ response: {
40
+ 200: Response;
41
+ 422: {
42
+ type: "validation";
43
+ on: string;
44
+ summary?: string;
45
+ message?: string;
46
+ found?: unknown;
47
+ property?: string;
48
+ expected?: string;
49
+ };
50
+ };
51
+ };
52
+ };
53
+ };
54
+ } & {
55
+ [x: string]: {
56
+ request: {
57
+ ":id": {
58
+ get: {
59
+ body: unknown;
60
+ params: {
61
+ id: string;
62
+ };
63
+ query: unknown;
64
+ headers: unknown;
65
+ response: {
66
+ 200: Response;
67
+ 422: {
68
+ type: "validation";
69
+ on: string;
70
+ summary?: string;
71
+ message?: string;
72
+ found?: unknown;
73
+ property?: string;
74
+ expected?: string;
75
+ };
76
+ };
77
+ };
78
+ };
79
+ };
80
+ };
81
+ } & {
82
+ [x: string]: {
83
+ response: {
84
+ post: {
85
+ body: {
86
+ state?: string | undefined;
87
+ presentation_submission?: unknown;
88
+ vp_token: string;
89
+ };
90
+ params: {};
91
+ query: unknown;
92
+ headers: unknown;
93
+ response: {
94
+ 200: Response;
95
+ 422: {
96
+ type: "validation";
97
+ on: string;
98
+ summary?: string;
99
+ message?: string;
100
+ found?: unknown;
101
+ property?: string;
102
+ expected?: string;
103
+ };
104
+ };
105
+ };
106
+ };
107
+ };
108
+ }, {
109
+ derive: {};
110
+ resolve: {};
111
+ schema: {};
112
+ standaloneSchema: {};
113
+ response: {};
114
+ }, {
115
+ derive: {};
116
+ resolve: {};
117
+ schema: {};
118
+ standaloneSchema: {};
119
+ response: {};
120
+ }>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.38.0",
2
+ "version": "0.40.0-beta.1",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {