signet-core 1.0.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/LICENSE +21 -0
- package/README.md +84 -0
- package/apis/BlacklistApi.ts +312 -0
- package/apis/CommsApi.ts +99 -0
- package/apis/DeviceApi.ts +322 -0
- package/apis/EnrollmentApi.ts +111 -0
- package/apis/GeoApi.ts +263 -0
- package/apis/IpApi.ts +322 -0
- package/apis/MandateApi.ts +529 -0
- package/apis/PartnerApi.ts +442 -0
- package/apis/ReportingApi.ts +312 -0
- package/apis/index.ts +11 -0
- package/index.ts +6 -0
- package/models/BlacklistControllerBlacklistClientRequest.ts +83 -0
- package/models/BlacklistControllerBlacklistClientRequestReasonsInner.ts +111 -0
- package/models/BlacklistControllerRemoveBlacklistClientRequest.ts +66 -0
- package/models/CommsControllerCheckClientStatusRequest.ts +75 -0
- package/models/DeviceControllerFlagDeviceRequest.ts +92 -0
- package/models/DeviceControllerFlagDeviceRequestReasonsInner.ts +111 -0
- package/models/DeviceControllerUnflagDeviceRequest.ts +75 -0
- package/models/EnrollmentControllerEnrollUser201Response.ts +89 -0
- package/models/EnrollmentControllerEnrollUser201ResponseData.ts +113 -0
- package/models/EnrollmentControllerEnrollUser201ResponseDataMetadata.ts +81 -0
- package/models/EnrollmentControllerEnrollUserRequest.ts +101 -0
- package/models/GeoControllerGeoVerifyRequest.ts +93 -0
- package/models/IpControllerFlagIpRequest.ts +92 -0
- package/models/IpControllerFlagIpRequestReasonsInner.ts +114 -0
- package/models/IpControllerUnflagIpRequest.ts +75 -0
- package/models/ManagementControllerAllClients200Response.ts +89 -0
- package/models/ManagementControllerAllClients200ResponseData.ts +88 -0
- package/models/ManagementControllerAllClients200ResponseDataPagination.ts +89 -0
- package/models/ManagementControllerAllClients400Response.ts +81 -0
- package/models/ManagementControllerAllClients404Response.ts +73 -0
- package/models/ManagementControllerAllClients500Response.ts +81 -0
- package/models/ManagementControllerGetClient200Response.ts +81 -0
- package/models/ManagementControllerGetClient400Response.ts +81 -0
- package/models/ManagementControllerGetClient404Response.ts +73 -0
- package/models/ManagementControllerGetClient500Response.ts +81 -0
- package/models/ManagementControllerRegisterClient201Response.ts +89 -0
- package/models/ManagementControllerRegisterClient201ResponseData.ts +105 -0
- package/models/ManagementControllerRegisterClient400Response.ts +81 -0
- package/models/ManagementControllerRegisterClient409Response.ts +89 -0
- package/models/ManagementControllerRegisterClient409ResponseError.ts +73 -0
- package/models/ManagementControllerRegisterClient500Response.ts +81 -0
- package/models/ManagementControllerRegisterClientRequest.ts +75 -0
- package/models/ManagementControllerRemoveClient200Response.ts +89 -0
- package/models/ManagementControllerRemoveClient200ResponseData.ts +65 -0
- package/models/ManagementControllerRemoveClient400Response.ts +81 -0
- package/models/ManagementControllerRemoveClient500Response.ts +81 -0
- package/models/ManagementControllerRemoveClientRequest.ts +66 -0
- package/models/ManagementControllerUpdateClient200Response.ts +89 -0
- package/models/ManagementControllerUpdateClient200ResponseData.ts +89 -0
- package/models/ManagementControllerUpdateClient400Response.ts +81 -0
- package/models/ManagementControllerUpdateClient500Response.ts +81 -0
- package/models/ManagementControllerUpdateClientRequest.ts +103 -0
- package/models/MandateControllerCreateCartMandate201Response.ts +89 -0
- package/models/MandateControllerCreateCartMandate201ResponseData.ts +137 -0
- package/models/MandateControllerCreateCartMandateRequest.ts +171 -0
- package/models/MandateControllerCreateCartMandateRequestItemsInner.ts +93 -0
- package/models/MandateControllerCreateIntentMandateRequest.ts +144 -0
- package/models/MandateControllerCreatePaymentMandateRequest.ts +189 -0
- package/models/MandateControllerCreateSignedPaymentMandateRequest.ts +137 -0
- package/models/MandateControllerCreateSignedPaymentMandateRequestUserAuthorization.ts +100 -0
- package/models/ReportingControllerRemoveReportRequest.ts +66 -0
- package/models/ReportingControllerReportClientRequest.ts +83 -0
- package/models/ReportingControllerReportClientRequestReasonsInner.ts +110 -0
- package/models/index.ts +55 -0
- package/package.json +65 -0
- package/runtime.ts +432 -0
- package/utils/dpop.ts +174 -0
package/utils/dpop.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DPoP (Distributed Proof of Possession) Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality to generate DPoP tokens for secure API authentication.
|
|
5
|
+
* DPoP binds access tokens to a specific public key, preventing token theft and replay attacks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as crypto from 'crypto';
|
|
9
|
+
import { SignJWT, jwtVerify, type JWK } from 'jose';
|
|
10
|
+
|
|
11
|
+
export interface DPoPKeyPair {
|
|
12
|
+
privateKey: crypto.KeyObject;
|
|
13
|
+
publicKey: crypto.KeyObject;
|
|
14
|
+
jwk: JWK;
|
|
15
|
+
thumbprint: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface DPoPProofOptions {
|
|
19
|
+
method: string;
|
|
20
|
+
url: string;
|
|
21
|
+
accessToken?: string;
|
|
22
|
+
nonce?: string;
|
|
23
|
+
jti?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate a new DPoP key pair
|
|
28
|
+
* @param algorithm - The algorithm to use (default: ES256)
|
|
29
|
+
* @returns A DPoP key pair with private key, public key, JWK, and thumbprint
|
|
30
|
+
*/
|
|
31
|
+
export async function generateDPoPKeyPair(algorithm: string = 'ES256'): Promise<DPoPKeyPair> {
|
|
32
|
+
let keyPair: crypto.KeyPairKeyObjectResult;
|
|
33
|
+
let jwk: JWK;
|
|
34
|
+
|
|
35
|
+
if (algorithm.startsWith('ES')) {
|
|
36
|
+
// ECDSA key pair
|
|
37
|
+
const curve = algorithm === 'ES256' ? 'P-256' : algorithm === 'ES384' ? 'P-384' : 'P-521';
|
|
38
|
+
keyPair = crypto.generateKeyPairSync('ec', {
|
|
39
|
+
namedCurve: curve,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Convert to JWK format
|
|
43
|
+
const publicKeyJwk = keyPair.publicKey.export({ format: 'jwk' });
|
|
44
|
+
jwk = {
|
|
45
|
+
kty: publicKeyJwk.kty!,
|
|
46
|
+
crv: publicKeyJwk.crv!,
|
|
47
|
+
x: publicKeyJwk.x!,
|
|
48
|
+
y: publicKeyJwk.y!,
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(`Unsupported algorithm: ${algorithm}. Only ES256, ES384, ES512 are supported.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Calculate JWK thumbprint (RFC 7638)
|
|
55
|
+
const thumbprint = crypto
|
|
56
|
+
.createHash('sha256')
|
|
57
|
+
.update(JSON.stringify({ ...jwk, alg: algorithm }))
|
|
58
|
+
.digest('base64url');
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
privateKey: keyPair.privateKey,
|
|
62
|
+
publicKey: keyPair.publicKey,
|
|
63
|
+
jwk,
|
|
64
|
+
thumbprint,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Generate a DPoP proof JWT
|
|
70
|
+
* @param keyPair - The DPoP key pair
|
|
71
|
+
* @param options - DPoP proof options (method, url, accessToken, nonce, jti)
|
|
72
|
+
* @param algorithm - The signing algorithm (default: ES256)
|
|
73
|
+
* @returns A signed DPoP proof JWT
|
|
74
|
+
*/
|
|
75
|
+
export async function generateDPoPProof(
|
|
76
|
+
keyPair: DPoPKeyPair,
|
|
77
|
+
options: DPoPProofOptions,
|
|
78
|
+
algorithm: string = 'ES256'
|
|
79
|
+
): Promise<string> {
|
|
80
|
+
const now = Math.floor(Date.now() / 1000);
|
|
81
|
+
const jti = options.jti || crypto.randomBytes(16).toString('hex');
|
|
82
|
+
|
|
83
|
+
const payload: Record<string, unknown> = {
|
|
84
|
+
iat: now,
|
|
85
|
+
jti,
|
|
86
|
+
htu: options.url,
|
|
87
|
+
htm: options.method.toUpperCase(),
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (options.accessToken) {
|
|
91
|
+
payload.ath = crypto
|
|
92
|
+
.createHash('sha256')
|
|
93
|
+
.update(options.accessToken)
|
|
94
|
+
.digest('base64url');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (options.nonce) {
|
|
98
|
+
payload.nonce = options.nonce;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const jwt = new SignJWT(payload)
|
|
102
|
+
.setProtectedHeader({
|
|
103
|
+
typ: 'dpop+jwt',
|
|
104
|
+
alg: algorithm,
|
|
105
|
+
jwk: keyPair.jwk,
|
|
106
|
+
})
|
|
107
|
+
.setIssuedAt(now)
|
|
108
|
+
.setJti(jti);
|
|
109
|
+
|
|
110
|
+
// Sign with the private key
|
|
111
|
+
const privateKeyPem = keyPair.privateKey.export({ format: 'pem', type: 'pkcs8' });
|
|
112
|
+
return await jwt.sign(crypto.createPrivateKey(privateKeyPem));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* DPoP Manager class for managing DPoP keys and generating proofs
|
|
117
|
+
*/
|
|
118
|
+
export class DPoPManager {
|
|
119
|
+
private keyPair: DPoPKeyPair | null = null;
|
|
120
|
+
private algorithm: string;
|
|
121
|
+
|
|
122
|
+
constructor(algorithm: string = 'ES256') {
|
|
123
|
+
this.algorithm = algorithm;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Initialize or get the DPoP key pair
|
|
128
|
+
* @returns The DPoP key pair
|
|
129
|
+
*/
|
|
130
|
+
async getKeyPair(): Promise<DPoPKeyPair> {
|
|
131
|
+
if (!this.keyPair) {
|
|
132
|
+
this.keyPair = await generateDPoPKeyPair(this.algorithm);
|
|
133
|
+
}
|
|
134
|
+
return this.keyPair;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generate a DPoP proof for a request
|
|
139
|
+
* @param method - HTTP method
|
|
140
|
+
* @param url - Request URL
|
|
141
|
+
* @param accessToken - Optional access token to bind the proof to
|
|
142
|
+
* @param nonce - Optional nonce from the server
|
|
143
|
+
* @returns DPoP proof JWT
|
|
144
|
+
*/
|
|
145
|
+
async generateProof(
|
|
146
|
+
method: string,
|
|
147
|
+
url: string,
|
|
148
|
+
accessToken?: string,
|
|
149
|
+
nonce?: string
|
|
150
|
+
): Promise<string> {
|
|
151
|
+
const keyPair = await this.getKeyPair();
|
|
152
|
+
return generateDPoPProof(keyPair, { method, url, accessToken, nonce }, this.algorithm);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the public key JWK for registration/authentication
|
|
157
|
+
* @returns Public key JWK
|
|
158
|
+
*/
|
|
159
|
+
async getPublicKeyJWK(): Promise<JWK> {
|
|
160
|
+
const keyPair = await this.getKeyPair();
|
|
161
|
+
return keyPair.jwk;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get the JWK thumbprint
|
|
166
|
+
* @returns JWK thumbprint
|
|
167
|
+
*/
|
|
168
|
+
async getThumbprint(): Promise<string> {
|
|
169
|
+
const keyPair = await this.getKeyPair();
|
|
170
|
+
return keyPair.thumbprint;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|