@mocyuto/aws-srp-client 1.4.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/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # AWS SRP Client
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm install @mocyuto/aws-srp-client
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ import { AwsSrpClient } from '@mocyuto/aws-srp-client';
13
+
14
+ const client = new AwsSrpClient('region', 'poolId', 'clientId');
15
+ const result = await client.AuthenticateUser('username', 'password');
16
+ if (result.Success) {
17
+ const tokens = result.AuthenticationResult;
18
+ //
19
+ } else {
20
+ //
21
+ }
22
+ ```
@@ -0,0 +1,52 @@
1
+ import { type PasswordVerifierChallengeParams, type PasswordVerifierResult, type PasswordVerifierChallengeResponse } from './Types.js';
2
+ import { type BigInteger } from 'big-integer';
3
+ export declare class AwsSrpClient {
4
+ private static N_HEX;
5
+ private static G_HEX;
6
+ Region: string;
7
+ PoolId: string;
8
+ ClientId: string;
9
+ BigN: BigInteger;
10
+ G: BigInteger;
11
+ K: BigInteger;
12
+ SmallAValue: BigInteger;
13
+ LargeAValue: BigInteger;
14
+ constructor(region: string, poolId: string, clientId: string);
15
+ Initialize(): void;
16
+ private GenerateRandomSmallA;
17
+ private CalculateA;
18
+ /**
19
+ *
20
+ * @returns The generated SRP_A value for an InitiateAuth request.
21
+ */
22
+ GetSrpA(): string;
23
+ private GetPasswordAuthenticationKey;
24
+ /**
25
+ * Generate a response for an AuthChallenge.
26
+ * @param password The user password
27
+ * @param challengeParams The response from an InitiateAuth request
28
+ * @returns A Password Verifier challenge response
29
+ */
30
+ ProcessChallenge(password: string, challengeParams: PasswordVerifierChallengeParams): PasswordVerifierChallengeResponse;
31
+ /**
32
+ * Authenticate a user via their password.
33
+ *
34
+ * This method also re-initializes the SmallA and LargeA values.
35
+ *
36
+ * @param username Cognito Username
37
+ * @param password Cognito Password
38
+ * @returns An object with Id-/Access-/Refresh tokens on success, an error object on failure
39
+ */
40
+ AuthenticateUser(username: string, password: string): Promise<PasswordVerifierResult | undefined>;
41
+ /**
42
+ * Authenticate a user via a refresh token.
43
+ *
44
+ * This method generates new Id-/Access-Token.
45
+ *
46
+ * @param refreshToken A valid refresh token
47
+ * @returns An object with Id-/Access-/Refresh tokens on success, an error object on failure
48
+ */
49
+ AuthenticateUserWithRefreshToken(refreshToken: string): Promise<PasswordVerifierResult | undefined>;
50
+ SetNewPassword(session: string, username: string, newPassword: string): Promise<PasswordVerifierResult | undefined>;
51
+ }
52
+ //# sourceMappingURL=AwsSrpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AwsSrpClient.d.ts","sourceRoot":"","sources":["../../src/client/AwsSrpClient.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,+BAA+B,EAGpC,KAAK,sBAAsB,EAE3B,KAAK,iCAAiC,EAIvC,MAAM,YAAY,CAAC;AAEpB,OAAe,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAItD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAgBiC;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAO;IAE3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,CAAC,EAAE,UAAU,CAAC;IACd,CAAC,EAAE,UAAU,CAAC;IACd,WAAW,EAAE,UAAU,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAWrD,UAAU;IAKjB,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,UAAU;IAMlB;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB,OAAO,CAAC,4BAA4B;IAiBpC;;;;;OAKG;IACI,gBAAgB,CACrB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,+BAA+B,GAC/C,iCAAiC;IAyBpC;;;;;;;;OAQG;IACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAqF9G;;;;;;;OAOG;IACU,gCAAgC,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAmDnG,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;CAuC/C"}
@@ -0,0 +1,261 @@
1
+ import { HashUtils } from '../utils/HashUtils.js';
2
+ import { AmzTarget, AuthFlow, } from './Types.js';
3
+ import CryptoJS from 'crypto-js';
4
+ import bigInt from 'big-integer';
5
+ import moment from 'moment';
6
+ import axios from 'axios';
7
+ export class AwsSrpClient {
8
+ constructor(region, poolId, clientId) {
9
+ this.Region = region;
10
+ this.PoolId = poolId;
11
+ this.ClientId = clientId;
12
+ this.BigN = HashUtils.HexToLong(AwsSrpClient.N_HEX);
13
+ this.G = HashUtils.HexToLong(AwsSrpClient.G_HEX);
14
+ this.K = HashUtils.HexToLong(HashUtils.HexHash(`00${AwsSrpClient.N_HEX}0${AwsSrpClient.G_HEX}`));
15
+ this.SmallAValue = bigInt(0);
16
+ this.LargeAValue = bigInt(0);
17
+ }
18
+ Initialize() {
19
+ this.SmallAValue = this.GenerateRandomSmallA();
20
+ this.LargeAValue = this.CalculateA();
21
+ }
22
+ GenerateRandomSmallA() {
23
+ const random = HashUtils.GetRandom(128);
24
+ return random.mod(this.BigN);
25
+ }
26
+ CalculateA() {
27
+ const bigA = this.G.modPow(this.SmallAValue, this.BigN);
28
+ if (bigA === this.BigN)
29
+ throw new Error('Safety check for A failed.');
30
+ return bigA;
31
+ }
32
+ /**
33
+ *
34
+ * @returns The generated SRP_A value for an InitiateAuth request.
35
+ */
36
+ GetSrpA() {
37
+ return HashUtils.LongToHex(this.LargeAValue);
38
+ }
39
+ GetPasswordAuthenticationKey(username, password, serverBValue, salt) {
40
+ const uValue = HashUtils.CalculateU(this.LargeAValue, serverBValue);
41
+ if (uValue === bigInt())
42
+ throw new Error('U cannot be zero.');
43
+ const usernamePassword = `${this.PoolId.split('_')[1]}${username}:${password}`;
44
+ const usernamePasswordHash = HashUtils.HashSha256(CryptoJS.enc.Utf8.parse(usernamePassword));
45
+ const xValue = HashUtils.HexToLong(HashUtils.HexHash(HashUtils.PadHex(salt) + usernamePasswordHash));
46
+ const gModPowXn = this.G.modPow(xValue, this.BigN);
47
+ const intValue2 = serverBValue.minus(this.K.times(gModPowXn));
48
+ let sValue = intValue2.modPow(this.SmallAValue.plus(uValue.times(xValue)), this.BigN);
49
+ if (sValue < bigInt())
50
+ sValue = sValue.plus(this.BigN);
51
+ return HashUtils.ComputeHdkf(CryptoJS.enc.Hex.parse(HashUtils.PadHex(sValue)), CryptoJS.enc.Hex.parse(HashUtils.PadHex(HashUtils.LongToHex(uValue))));
52
+ }
53
+ /**
54
+ * Generate a response for an AuthChallenge.
55
+ * @param password The user password
56
+ * @param challengeParams The response from an InitiateAuth request
57
+ * @returns A Password Verifier challenge response
58
+ */
59
+ ProcessChallenge(password, challengeParams) {
60
+ const timestamp = moment.utc().format('ddd MMM D HH:mm:ss UTC yyyy');
61
+ const hkdf = this.GetPasswordAuthenticationKey(challengeParams.USER_ID_FOR_SRP, password, HashUtils.HexToLong(challengeParams.SRP_B), challengeParams.SALT);
62
+ const secretBlockBytes = CryptoJS.enc.Base64.parse(challengeParams.SECRET_BLOCK);
63
+ const poolIdBytes = CryptoJS.enc.Utf8.parse(this.PoolId.split('_')[1]);
64
+ const userIdBytes = CryptoJS.enc.Utf8.parse(challengeParams.USER_ID_FOR_SRP);
65
+ const timestampBytes = CryptoJS.enc.Utf8.parse(timestamp);
66
+ const msg = poolIdBytes.concat(userIdBytes).concat(secretBlockBytes).concat(timestampBytes);
67
+ const hmac = CryptoJS.HmacSHA256(msg, hkdf);
68
+ const signature = CryptoJS.enc.Base64.stringify(hmac);
69
+ return {
70
+ USERNAME: challengeParams.USER_ID_FOR_SRP,
71
+ TIMESTAMP: timestamp,
72
+ PASSWORD_CLAIM_SECRET_BLOCK: challengeParams.SECRET_BLOCK,
73
+ PASSWORD_CLAIM_SIGNATURE: signature,
74
+ };
75
+ }
76
+ /**
77
+ * Authenticate a user via their password.
78
+ *
79
+ * This method also re-initializes the SmallA and LargeA values.
80
+ *
81
+ * @param username Cognito Username
82
+ * @param password Cognito Password
83
+ * @returns An object with Id-/Access-/Refresh tokens on success, an error object on failure
84
+ */
85
+ async AuthenticateUser(username, password) {
86
+ try {
87
+ this.Initialize();
88
+ const cognitoUrl = `https://cognito-idp.${this.Region}.amazonaws.com`;
89
+ const authParams = {
90
+ USERNAME: username,
91
+ SRP_A: this.GetSrpA(),
92
+ };
93
+ const authRequest = {
94
+ AuthFlow: AuthFlow.UserSrpAuth,
95
+ ClientId: this.ClientId,
96
+ AuthParameters: authParams,
97
+ };
98
+ const initAuthResponse = await axios.request({
99
+ url: cognitoUrl,
100
+ method: 'POST',
101
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.InitiateAuth },
102
+ data: JSON.stringify(authRequest),
103
+ });
104
+ if (initAuthResponse) {
105
+ const initAuthBody = initAuthResponse.data;
106
+ if ((initAuthBody === null || initAuthBody === void 0 ? void 0 : initAuthBody.ChallengeName) && initAuthBody.ChallengeName === 'PASSWORD_VERIFIER') {
107
+ const challengeResponse = this.ProcessChallenge(password, initAuthBody.ChallengeParameters);
108
+ const challengeRequest = {
109
+ ChallengeName: initAuthBody.ChallengeName,
110
+ ChallengeResponses: challengeResponse,
111
+ ClientId: this.ClientId,
112
+ };
113
+ const authChallengeResponse = await axios.request({
114
+ url: cognitoUrl,
115
+ method: 'POST',
116
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.AuthChallenge },
117
+ data: JSON.stringify(challengeRequest),
118
+ });
119
+ if (authChallengeResponse) {
120
+ const verifierResult = {
121
+ Success: false,
122
+ NewPasswordRequired: false,
123
+ };
124
+ if (authChallengeResponse.data.AuthenticationResult) {
125
+ verifierResult.Success = true;
126
+ verifierResult.AuthenticationResult = authChallengeResponse.data.AuthenticationResult;
127
+ verifierResult.ChallengeParameters = authChallengeResponse.data.ChallengeParameters;
128
+ }
129
+ else if (authChallengeResponse.data.ChallengeName &&
130
+ authChallengeResponse.data.ChallengeName === 'NEW_PASSWORD_REQUIRED') {
131
+ verifierResult.Success = true;
132
+ verifierResult.NewPasswordRequired = true;
133
+ verifierResult.Session = authChallengeResponse.data.Session;
134
+ }
135
+ else if (authChallengeResponse.data.ChallengeName &&
136
+ authChallengeResponse.data.ChallengeName === 'MFA_SETUP') {
137
+ verifierResult.Success = true;
138
+ verifierResult.MfaSetup = true;
139
+ verifierResult.Session = authChallengeResponse.data.Session;
140
+ verifierResult.ChallengeParameters = authChallengeResponse.data.ChallengeParameters;
141
+ }
142
+ return verifierResult;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ catch (err) {
148
+ return {
149
+ Success: false,
150
+ NewPasswordRequired: false,
151
+ Error: err,
152
+ };
153
+ }
154
+ }
155
+ /**
156
+ * Authenticate a user via a refresh token.
157
+ *
158
+ * This method generates new Id-/Access-Token.
159
+ *
160
+ * @param refreshToken A valid refresh token
161
+ * @returns An object with Id-/Access-/Refresh tokens on success, an error object on failure
162
+ */
163
+ async AuthenticateUserWithRefreshToken(refreshToken) {
164
+ try {
165
+ const cognitoUrl = `https://cognito-idp.${this.Region}.amazonaws.com`;
166
+ const authParams = {
167
+ REFRESH_TOKEN: refreshToken,
168
+ };
169
+ const authRequest = {
170
+ AuthFlow: AuthFlow.RefreshTokenAuth,
171
+ ClientId: this.ClientId,
172
+ AuthParameters: authParams,
173
+ };
174
+ const initAuthResponse = await axios.request({
175
+ url: cognitoUrl,
176
+ method: 'POST',
177
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.InitiateAuth },
178
+ data: JSON.stringify(authRequest),
179
+ });
180
+ if (initAuthResponse) {
181
+ const verifierResult = {
182
+ Success: false,
183
+ NewPasswordRequired: false,
184
+ };
185
+ if (initAuthResponse.data.AuthenticationResult) {
186
+ verifierResult.Success = true;
187
+ verifierResult.AuthenticationResult = initAuthResponse.data.AuthenticationResult;
188
+ verifierResult.ChallengeParameters = initAuthResponse.data.ChallengeParameters;
189
+ }
190
+ else if (initAuthResponse.data.ChallengeName &&
191
+ initAuthResponse.data.ChallengeName === 'NEW_PASSWORD_REQUIRED') {
192
+ verifierResult.Success = true;
193
+ verifierResult.NewPasswordRequired = true;
194
+ verifierResult.Session = initAuthResponse.data.Session;
195
+ }
196
+ return verifierResult;
197
+ }
198
+ }
199
+ catch (err) {
200
+ return {
201
+ Success: false,
202
+ NewPasswordRequired: false,
203
+ Error: err,
204
+ };
205
+ }
206
+ }
207
+ async SetNewPassword(session, username, newPassword) {
208
+ const cognitoUrl = `https://cognito-idp.${this.Region}.amazonaws.com`;
209
+ const newPasswordChallengeResponse = {
210
+ USERNAME: username,
211
+ NEW_PASSWORD: newPassword,
212
+ };
213
+ const newPasswordChallengeRequest = {
214
+ ChallengeName: 'NEW_PASSWORD_REQUIRED',
215
+ ClientId: this.ClientId,
216
+ Session: session,
217
+ ChallengeResponses: newPasswordChallengeResponse,
218
+ };
219
+ try {
220
+ const newPasswordResponse = await axios.request({
221
+ url: cognitoUrl,
222
+ method: 'POST',
223
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.AuthChallenge },
224
+ data: JSON.stringify(newPasswordChallengeRequest),
225
+ });
226
+ if (newPasswordResponse) {
227
+ return {
228
+ Success: true,
229
+ NewPasswordRequired: false,
230
+ AuthenticationResult: newPasswordResponse.data.AuthenticationResult,
231
+ ChallengeParameters: newPasswordResponse.data.ChallengeParameters,
232
+ };
233
+ }
234
+ }
235
+ catch (err) {
236
+ return {
237
+ Success: false,
238
+ NewPasswordRequired: false,
239
+ Error: err,
240
+ };
241
+ }
242
+ }
243
+ }
244
+ AwsSrpClient.N_HEX = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1' +
245
+ '29024E088A67CC74020BBEA63B139B22514A08798E3404DD' +
246
+ 'EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245' +
247
+ 'E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' +
248
+ 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D' +
249
+ 'C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F' +
250
+ '83655D23DCA3AD961C62F356208552BB9ED529077096966D' +
251
+ '670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' +
252
+ 'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9' +
253
+ 'DE2BCBF6955817183995497CEA956AE515D2261898FA0510' +
254
+ '15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64' +
255
+ 'ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' +
256
+ 'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B' +
257
+ 'F12FFA06D98A0864D87602733EC86A64521F2B18177B200C' +
258
+ 'BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31' +
259
+ '43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF';
260
+ AwsSrpClient.G_HEX = '2';
261
+ //# sourceMappingURL=AwsSrpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AwsSrpClient.js","sourceRoot":"","sources":["../../src/client/AwsSrpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACL,SAAS,EAUT,QAAQ,GACT,M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,EAAE,UAAU;gBACf,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,4BAA4B,EAAE,cAAc,EAAE,SAAS,CAAC,aAAa,EAAE;gBAClG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,2BAA2B,CAAC;aAClD,CAAC,CAAC;YAEH,IAAI,mBAAmB,EAAE;gBACvB,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,mBAAmB,EAAE,KAAK;oBAC1B,oBAAoB,EAAE,mBAAmB,CAAC,IAAI,CAAC,oBAAoB;oBACnE,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,mBAAmB;iBAClE,CAAC;aACH;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,mBAAmB,EAAE,KAAK;gBAC1B,KAAK,EAAE,GAAG;aACX,CAAC;SACH;IACH,CAAC;;AArTc,kBAAK,GAClB,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD;IAClD,kDAAkD,CAAC;AACtC,kBAAK,GAAG,GAAG,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type ChangePasswordResponse, type ConfirmForgotPasswordResponse, type ForgotPasswordResponse } from './Types.js';
2
+ export declare class CognitoClient {
3
+ Region: string;
4
+ ClientId: string;
5
+ CognitoUrl: string;
6
+ constructor(region: string, clientId: string);
7
+ /**
8
+ * Change a users password.
9
+ * @param accessToken Valid access token for the user whos password you want to change
10
+ * @param previousPassword Current password
11
+ * @param newPassword New password
12
+ * @returns Object with StatusCode 200 if it worked, StatusCode != 200 and Error message otherwise
13
+ */
14
+ ChangePassword(accessToken: string, previousPassword: string, newPassword: string): Promise<ChangePasswordResponse>;
15
+ ForgotPassword(username: string, metadata: Record<string, string>): Promise<ForgotPasswordResponse>;
16
+ ConfirmForgotPassword(username: string, code: string, newPassword: string): Promise<ConfirmForgotPasswordResponse>;
17
+ /**
18
+ * Build a Cognito Auth Domain with your chosen prefix and region.
19
+ * @deprecated Not needed anymore, will be removed in the next version.
20
+ * @param prefix Chosen URL prefix
21
+ * @returns Your Cognito Auth Domain
22
+ */
23
+ CognitoDomain(prefix: string): string;
24
+ }
25
+ //# sourceMappingURL=CognitoClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitoClient.d.ts","sourceRoot":"","sources":["../../src/client/CognitoClient.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,sBAAsB,EAE3B,KAAK,6BAA6B,EAElC,KAAK,sBAAsB,EAE5B,MAAM,YAAY,CAAC;AAEpB,qBAAa,aAAa;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAM5C;;;;;;OAMG;IACG,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,sBAAsB,CAAC;IAoB5B,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAoBnG,qBAAqB,CACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,6BAA6B,CAAC;IAqBzC;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM;CAG7B"}
@@ -0,0 +1,78 @@
1
+ import axios from 'axios';
2
+ import { AmzTarget, } from './Types.js';
3
+ export class CognitoClient {
4
+ constructor(region, clientId) {
5
+ this.Region = region;
6
+ this.ClientId = clientId;
7
+ this.CognitoUrl = `https://cognito-idp.${this.Region}.amazonaws.com`;
8
+ }
9
+ /**
10
+ * Change a users password.
11
+ * @param accessToken Valid access token for the user whos password you want to change
12
+ * @param previousPassword Current password
13
+ * @param newPassword New password
14
+ * @returns Object with StatusCode 200 if it worked, StatusCode != 200 and Error message otherwise
15
+ */
16
+ async ChangePassword(accessToken, previousPassword, newPassword) {
17
+ const params = {
18
+ AccessToken: accessToken,
19
+ PreviousPassword: previousPassword,
20
+ ProposedPassword: newPassword,
21
+ };
22
+ const response = await axios.request({
23
+ url: this.CognitoUrl,
24
+ method: 'POST',
25
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.ChangePassword },
26
+ data: JSON.stringify(params),
27
+ });
28
+ return {
29
+ StatusCode: response.status,
30
+ Error: JSON.stringify(response.data),
31
+ };
32
+ }
33
+ async ForgotPassword(username, metadata) {
34
+ const params = {
35
+ ClientId: this.ClientId,
36
+ Username: username,
37
+ ClientMetadata: metadata,
38
+ };
39
+ const response = await axios.request({
40
+ url: this.CognitoUrl,
41
+ method: 'POST',
42
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.ForgotPassword },
43
+ data: JSON.stringify(params),
44
+ });
45
+ return {
46
+ CodeDeliveryDetails: response.data.CodeDeliveryDetails ? response.data.CodeDeliveryDetails : {},
47
+ Error: !response.data.CodeDeliveryDetails ? response.data : {},
48
+ };
49
+ }
50
+ async ConfirmForgotPassword(username, code, newPassword) {
51
+ const params = {
52
+ ClientId: this.ClientId,
53
+ ConfirmationCode: code,
54
+ Username: username,
55
+ Password: newPassword,
56
+ };
57
+ const response = await axios.request({
58
+ url: this.CognitoUrl,
59
+ method: 'POST',
60
+ headers: { 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': AmzTarget.ConfirmForgotPassword },
61
+ data: JSON.stringify(params),
62
+ });
63
+ return {
64
+ Success: response.status === 200,
65
+ Error: JSON.stringify(response.data),
66
+ };
67
+ }
68
+ /**
69
+ * Build a Cognito Auth Domain with your chosen prefix and region.
70
+ * @deprecated Not needed anymore, will be removed in the next version.
71
+ * @param prefix Chosen URL prefix
72
+ * @returns Your Cognito Auth Domain
73
+ */
74
+ CognitoDomain(prefix) {
75
+ return `https://${prefix}.auth.${this.Region}.amazoncognito.com`;
76
+ }
77
+ }
78
+ //# sourceMappingURL=CognitoClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CognitoClient.js","sourceRoot":"","sources":["../../src/client/CognitoClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,SAAS,GAQV,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,aAAa;IAKxB,YAAY,MAAc,EAAE,QAAgB;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,uBAAuB,IAAI,CAAC,MAAM,gBAAgB,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAClB,WAAmB,EACnB,gBAAwB,EACxB,WAAmB;QAEnB,MAAM,MAAM,GAAyB;YACnC,WAAW,EAAE,WAAW;YACxB,gBAAgB,EAAE,gBAAgB;YAClC,gBAAgB,EAAE,WAAW;SAC9B,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;YACnC,GAAG,EAAE,IAAI,CAAC,UAAU;YACpB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,4BAA4B,EAAE,cAAc,EAAE,SAAS,CAAC,cAAc,EAAE;YACnG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC,CAAC;QAEH,OAAO;YACL,UAAU,EAAE,QAAQ,CAAC,MAAM;YAC3B,KAAK,E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,EAAE;YAC1G,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,QAAQ,CAAC,MAAM,KAAK,GAAG;YAChC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;SACrC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,MAAc;QAC1B,OAAO,WAAW,MAAM,SAAS,IAAI,CAAC,MAAM,oBAAoB,CAAC;IACnE,CAAC;CACF"}
@@ -0,0 +1,107 @@
1
+ declare enum AmzTarget {
2
+ InitiateAuth = "AWSCognitoIdentityProviderService.InitiateAuth",
3
+ AuthChallenge = "AWSCognitoIdentityProviderService.RespondToAuthChallenge",
4
+ ChangePassword = "AWSCognitoIdentityProviderService.ChangePassword",
5
+ ForgotPassword = "AWSCognitoIdentityProviderService.ForgotPassword",
6
+ ConfirmForgotPassword = "AWSCognitoIdentityProviderService.ConfirmForgotPassword"
7
+ }
8
+ declare enum AuthFlow {
9
+ UserSrpAuth = "USER_SRP_AUTH",
10
+ RefreshTokenAuth = "REFRESH_TOKEN"
11
+ }
12
+ interface InitiateAuthParams {
13
+ USERNAME: string;
14
+ SRP_A: string;
15
+ }
16
+ interface RefreshTokenParams {
17
+ REFRESH_TOKEN: string;
18
+ SECRET_HASH?: string;
19
+ }
20
+ interface InitiateAuthRequest {
21
+ AuthParameters: InitiateAuthParams | RefreshTokenParams;
22
+ AuthFlow: AuthFlow;
23
+ ClientId: string;
24
+ }
25
+ interface PasswordVerifierChallengeParams {
26
+ SALT: string;
27
+ SECRET_BLOCK: string;
28
+ USER_ID_FOR_SRP: string;
29
+ USERNAME: string;
30
+ SRP_B: string;
31
+ }
32
+ interface InitiateAuthResponse {
33
+ ChallengeName: string;
34
+ ChallengeParameters: PasswordVerifierChallengeParams;
35
+ }
36
+ interface ChallengeResponse {
37
+ USERNAME: string;
38
+ }
39
+ interface PasswordVerifierChallengeResponse extends ChallengeResponse {
40
+ TIMESTAMP?: string;
41
+ PASSWORD_CLAIM_SECRET_BLOCK?: string;
42
+ PASSWORD_CLAIM_SIGNATURE?: string;
43
+ }
44
+ interface NewPasswordChallengeReponse extends ChallengeResponse {
45
+ NEW_PASSWORD: string;
46
+ SECRET_HASH?: string;
47
+ }
48
+ interface RespondToAuthChallengeRequest {
49
+ ClientId: string;
50
+ ChallengeName: string;
51
+ ChallengeResponses: ChallengeResponse;
52
+ Session?: string;
53
+ }
54
+ interface PasswordVerifierResult {
55
+ Success: boolean;
56
+ NewPasswordRequired: boolean;
57
+ Session?: string;
58
+ AuthenticationResult?: {
59
+ AccessToken: string;
60
+ IdToken: string;
61
+ RefreshToken: string;
62
+ ExpiresIn: number;
63
+ TokenType: string;
64
+ };
65
+ MfaSetup?: boolean;
66
+ ChallengeParameters?: any;
67
+ Error?: any;
68
+ }
69
+ interface ChangePasswordParams {
70
+ AccessToken: string;
71
+ PreviousPassword: string;
72
+ ProposedPassword: string;
73
+ }
74
+ interface ChangePasswordResponse {
75
+ StatusCode: number;
76
+ Error?: string;
77
+ }
78
+ interface ForgotPasswordParams {
79
+ ClientId: string;
80
+ SecretHash?: string;
81
+ Username: string;
82
+ ClientMetadata?: Record<string, string>;
83
+ }
84
+ interface ForgotPasswordResponse {
85
+ CodeDeliveryDetails?: {
86
+ AttributeName: string;
87
+ DeliveryMedium: string;
88
+ Destination: string;
89
+ };
90
+ Error?: {
91
+ __type: string;
92
+ message: string;
93
+ };
94
+ }
95
+ interface ConfirmForgotPasswordParams {
96
+ ClientId: string;
97
+ SecretHash?: string;
98
+ Username: string;
99
+ ConfirmationCode: string;
100
+ Password: string;
101
+ }
102
+ interface ConfirmForgotPasswordResponse {
103
+ Success: boolean;
104
+ Error?: any;
105
+ }
106
+ export { AmzTarget, AuthFlow, type InitiateAuthParams, type RefreshTokenParams, type InitiateAuthRequest, type PasswordVerifierChallengeParams, type InitiateAuthResponse, type RespondToAuthChallengeRequest, type ChallengeResponse, type PasswordVerifierResult, type PasswordVerifierChallengeResponse, type NewPasswordChallengeReponse, type ChangePasswordParams, type ChangePasswordResponse, type ForgotPasswordParams, type ForgotPasswordResponse, type ConfirmForgotPasswordParams, type ConfirmForgotPasswordResponse, };
107
+ //# sourceMappingURL=Types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/client/Types.ts"],"names":[],"mappings":"AAAA,aAAK,SAAS;IACZ,YAAY,mDAAmD;IAC/D,aAAa,6DAA6D;IAC1E,cAAc,qDAAqD;IACnE,cAAc,qDAAqD;IACnE,qBAAqB,4DAA4D;CAClF;AAED,aAAK,QAAQ;IACX,WAAW,kBAAkB;IAC7B,gBAAgB,kBAAkB;CACnC;AAED,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,kBAAkB;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,mBAAmB;IAC3B,cAAc,EAAE,kBAAkB,GAAG,kBAAkB,CAAC;IACxD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,+BAA+B;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,oBAAoB;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,+BAA+B,CAAC;CACtD;AAED,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,iCAAkC,SAAQ,iBAAiB;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B,CAAC,EAAE,MAAM,CAAC;I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AAE,MAAM,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,UAAU,2BAA2B;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,6BAA6B;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,OAAO,EACL,SAAS,EACT,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,EACpC,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,GACnC,CAAC"}
@@ -0,0 +1,15 @@
1
+ var AmzTarget;
2
+ (function (AmzTarget) {
3
+ AmzTarget["InitiateAuth"] = "AWSCognitoIdentityProviderService.InitiateAuth";
4
+ AmzTarget["AuthChallenge"] = "AWSCognitoIdentityProviderService.RespondToAuthChallenge";
5
+ AmzTarget["ChangePassword"] = "AWSCognitoIdentityProviderService.ChangePassword";
6
+ AmzTarget["ForgotPassword"] = "AWSCognitoIdentityProviderService.ForgotPassword";
7
+ AmzTarget["ConfirmForgotPassword"] = "AWSCognitoIdentityProviderService.ConfirmForgotPassword";
8
+ })(AmzTarget || (AmzTarget = {}));
9
+ var AuthFlow;
10
+ (function (AuthFlow) {
11
+ AuthFlow["UserSrpAuth"] = "USER_SRP_AUTH";
12
+ AuthFlow["RefreshTokenAuth"] = "REFRESH_TOKEN";
13
+ })(AuthFlow || (AuthFlow = {}));
14
+ export { AmzTarget, AuthFlow, };
15
+ //# sourceMappingURL=Types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.js","sourceRoot":"","sources":["../../src/client/Types.ts"],"names":[],"mappings":"AAAA,IAAK,SAMJ;AAND,WAAK,SAAS;IACZ,4EAA+D,CAAA;IAC/D,uFAA0E,CAAA;IAC1E,gFAAmE,CAAA;IACnE,gFAAmE,CAAA;IACnE,8FAAiF,CAAA;AACnF,CAAC,EANI,SAAS,KAAT,SAAS,QAMb;AAED,IAAK,QAGJ;AAHD,WAAK,QAAQ;IACX,yCAA6B,CAAA;IAC7B,8CAAkC,CAAA;AACpC,CAAC,EAHI,QAAQ,KAAR,QAAQ,QAGZ;AAgHD,OAAO,EACL,SAAS,EACT,QAAQ,GAiBT,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { AwsSrpClient } from './client/AwsSrpClient.js';
2
+ import { CognitoClient } from './client/CognitoClient.js';
3
+ import { HashUtils } from './utils/HashUtils.js';
4
+ import { AmzTarget, AuthFlow, ChangePasswordParams, ChangePasswordResponse, InitiateAuthParams, RefreshTokenParams, InitiateAuthRequest, InitiateAuthResponse, RespondToAuthChallengeRequest, ChallengeResponse, PasswordVerifierChallengeParams, PasswordVerifierResult, NewPasswordChallengeReponse, PasswordVerifierChallengeResponse } from './client/Types.js';
5
+ export { AwsSrpClient, CognitoClient, HashUtils, AmzTarget, AuthFlow, ChangePasswordParams, ChangePasswordResponse, InitiateAuthParams, RefreshTokenParams, InitiateAuthRequest, InitiateAuthResponse, RespondToAuthChallengeRequest, ChallengeResponse, PasswordVerifierChallengeParams, PasswordVerifierResult, NewPasswordChallengeReponse, PasswordVerifierChallengeResponse, };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,iCAAiC,EAClC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,iBAAiB,EACjB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,iCAAiC,GAClC,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { AwsSrpClient } from './client/AwsSrpClient.js';
2
+ import { CognitoClient } from './client/CognitoClient.js';
3
+ import { HashUtils } from './utils/HashUtils.js';
4
+ import { AmzTarget, AuthFlow, } from './client/Types.js';
5
+ export { AwsSrpClient, CognitoClient, HashUtils, AmzTarget, AuthFlow, };
6
+ // const client = new AwsSrpClient('region', 'pool-id', 'client-id');
7
+ // client.AuthenticateUser('user', 'password');
8
+ // const response: AuthResponse = {
9
+ // ChallengeName: "PASSWORD_VERIFIER",
10
+ // ChallengeParameters: {
11
+ // SALT: "aqsfyf326546sdgsdfasda65s1d6a",
12
+ // SECRET_BLOCK: "jdhgsjsdghkjklyvda65sf1w64h615l651c6a5sd41fg65g4j1651c651hb651d6516kj16l414vca32c32x2g6r4n61yc651hnj84rz9k451acy1g984w6v21y1b9641h16dxb4rj9n61C1Y65G4X9684B1JM94B65s21v4ds6fhg==",
13
+ // USER_ID_FOR_SRP: "user",
14
+ // USERNAME: "user",
15
+ // SRP_B: "laskdjfglsdjgietu099sd8h49dsgd4s9dgf4s9dg4s5g4sdg4s94af4aFHd9318u6ßsdfoi120hfv28094ghß2jfldxmg20894ujtßmmhß9j2gimcgklkgüpdskt902fölksdöfk390utßskdfl,k1ß3ujsdjkf"
16
+ // }
17
+ // };
18
+ // client.Initialize();
19
+ // const challengeParams = client.ProcessChallenge("password", response.ChallengeParameters);
20
+ // console.log(JSON.stringify(challengeParams));
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,QAAQ,GAaT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,EACT,QAAQ,GAaT,CAAC;AAEF,qEAAqE;AACrE,+CAA+C;AAE/C,mCAAmC;AACnC,0CAA0C;AAC1C,6BAA6B;AAC7B,iDAAiD;AACjD,4MAA4M;AAC5M,mCAAmC;AACnC,4BAA4B;AAC5B,oLAAoL;AACpL,QAAQ;AACR,KAAK;AAEL,uBAAuB;AACvB,6FAA6F;AAE7F,gDAAgD"}
@@ -0,0 +1,39 @@
1
+ import CryptoJS from 'crypto-js';
2
+ import bigInt, { BigInteger } from 'big-integer';
3
+ declare class HashUtils {
4
+ private static INFO_BITS;
5
+ /**
6
+ * Creates a SHA256 hash out of a WordArray.
7
+ * @param buf CryptoJS WordArray to hash
8
+ * @returns SHA256-encrypted hash, padded to a length of 64
9
+ */
10
+ static HashSha256(buf: CryptoJS.lib.WordArray): string;
11
+ static HexHash(hexString: string): string;
12
+ static HexToLong(hexString: string): BigInteger;
13
+ static LongToHex(longValue: BigInteger): string;
14
+ /**
15
+ * Creates a random BigInteger of a given size.
16
+ * @param size Number of random bytes
17
+ * @returns Random BigInteger
18
+ */
19
+ static GetRandom(size: number): BigInteger;
20
+ /**
21
+ * Add padding to ensure a valid hex string.
22
+ * @param hex Either a hex string or a BigInteger that get converted to a hex string
23
+ * @returns A padded hex string
24
+ */
25
+ static PadHex(hex: string | BigInteger): string;
26
+ /**
27
+ * Creates a 16 byte HMAC derived key.
28
+ * @param ikm Input key material
29
+ * @param salt Salt from the server challenge response
30
+ * @returns 16 byte HMAC derived key
31
+ */
32
+ static ComputeHdkf(ikm: CryptoJS.lib.WordArray, salt: CryptoJS.lib.WordArray): CryptoJS.lib.WordArray;
33
+ static CalculateU(bigA: BigInteger, bigB: BigInteger): bigInt.BigInteger;
34
+ private static ByteArrayToWordArray;
35
+ private static WordToByteArray;
36
+ private static WordArrayToByteArray;
37
+ }
38
+ export { HashUtils };
39
+ //# sourceMappingURL=HashUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashUtils.d.ts","sourceRoot":"","sources":["../../src/utils/HashUtils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjD,cAAM,SAAS;IACb,OAAO,CAAC,MAAM,CAAC,SAAS,CAA0E;IAElG;;;;OAIG;WACW,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,GAAG,MAAM;WAK/C,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;WAIlC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU;WAIxC,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM;IAItD;;;;OAIG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAMjD;;;;OAIG;WACW,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;IAYtD;;;;;OAKG;WACW,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS;WAe9F,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU;IAK3D,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAanC,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAiBpC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,111 @@
1
+ import CryptoJS from 'crypto-js';
2
+ import bigInt from 'big-integer';
3
+ class HashUtils {
4
+ /**
5
+ * Creates a SHA256 hash out of a WordArray.
6
+ * @param buf CryptoJS WordArray to hash
7
+ * @returns SHA256-encrypted hash, padded to a length of 64
8
+ */
9
+ static HashSha256(buf) {
10
+ const a = CryptoJS.SHA256(buf).toString(CryptoJS.enc.Hex);
11
+ return a.padStart(64, '0');
12
+ }
13
+ static HexHash(hexString) {
14
+ return this.HashSha256(CryptoJS.enc.Hex.parse(hexString));
15
+ }
16
+ static HexToLong(hexString) {
17
+ return bigInt(hexString, 16);
18
+ }
19
+ static LongToHex(longValue) {
20
+ return longValue.toString(16);
21
+ }
22
+ /**
23
+ * Creates a random BigInteger of a given size.
24
+ * @param size Number of random bytes
25
+ * @returns Random BigInteger
26
+ */
27
+ static GetRandom(size) {
28
+ const randomBytes = CryptoJS.lib.WordArray.random(size);
29
+ const randomHex = CryptoJS.enc.Hex.stringify(randomBytes);
30
+ return this.HexToLong(randomHex);
31
+ }
32
+ /**
33
+ * Add padding to ensure a valid hex string.
34
+ * @param hex Either a hex string or a BigInteger that get converted to a hex string
35
+ * @returns A padded hex string
36
+ */
37
+ static PadHex(hex) {
38
+ let hashStr = '';
39
+ if (hex instanceof bigInt)
40
+ hashStr = this.LongToHex(hex);
41
+ else if (typeof hex === 'string')
42
+ hashStr = hex;
43
+ if (hashStr.length % 2 === 1)
44
+ hashStr = `0${hashStr}`;
45
+ else if ('89ABCDEFabcdef'.includes(hashStr[0]))
46
+ hashStr = `00${hashStr}`;
47
+ return hashStr;
48
+ }
49
+ /**
50
+ * Creates a 16 byte HMAC derived key.
51
+ * @param ikm Input key material
52
+ * @param salt Salt from the server challenge response
53
+ * @returns 16 byte HMAC derived key
54
+ */
55
+ static ComputeHdkf(ikm, salt) {
56
+ const prk = CryptoJS.HmacSHA256(ikm, salt);
57
+ const updateByteArray = [1];
58
+ const updateWordArray = this.ByteArrayToWordArray(updateByteArray);
59
+ const infoBits = this.INFO_BITS.clone();
60
+ const infoBitsUpdate = infoBits.concat(updateWordArray);
61
+ const hash = CryptoJS.HmacSHA256(infoBitsUpdate, prk);
62
+ hash.sigBytes = 16;
63
+ hash.clamp();
64
+ return hash;
65
+ }
66
+ static CalculateU(bigA, bigB) {
67
+ const uHexHash = this.HexHash(this.PadHex(bigA) + this.PadHex(bigB));
68
+ return this.HexToLong(uHexHash);
69
+ }
70
+ static ByteArrayToWordArray(ba) {
71
+ const wa = [];
72
+ let i;
73
+ for (i = 0; i < ba.length; i++) {
74
+ wa[(i / 4) | 0] |= ba[i] << (24 - 8 * i);
75
+ }
76
+ return CryptoJS.lib.WordArray.create(wa, ba.length);
77
+ }
78
+ // Following function where only used for debugging to check if the generated WordArray is equal to the byte array used in other implementations
79
+ static WordToByteArray(word, length) {
80
+ const ba = [];
81
+ const xFF = 0xff;
82
+ if (length > 0)
83
+ ba.push(word >>> 24);
84
+ if (length > 1)
85
+ ba.push((word >>> 16) & xFF);
86
+ if (length > 2)
87
+ ba.push((word >>> 8) & xFF);
88
+ if (length > 3)
89
+ ba.push(word & xFF);
90
+ return ba;
91
+ }
92
+ static WordArrayToByteArray(wordArray, length) {
93
+ if (wordArray.hasOwnProperty('sigBytes') && wordArray.hasOwnProperty('words')) {
94
+ length = wordArray.sigBytes;
95
+ wordArray = wordArray.words;
96
+ }
97
+ const result = [];
98
+ let bytes = [];
99
+ let i = 0;
100
+ while (length > 0) {
101
+ bytes = this.WordToByteArray(wordArray[i], Math.min(4, length));
102
+ length -= bytes.length;
103
+ result.push(bytes);
104
+ i++;
105
+ }
106
+ return [].concat.apply([], result);
107
+ }
108
+ }
109
+ HashUtils.INFO_BITS = CryptoJS.enc.Utf8.parse('Caldera Derived Key');
110
+ export { HashUtils };
111
+ //# sourceMappingURL=HashUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashUtils.js","sourceRoot":"","sources":["../../src/utils/HashUtils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAsB,MAAM,aAAa,CAAC;AAEjD,MAAM,SAAS;IAGb;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,GAA2B;QAClD,MAAM,CAAC,GAAW,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClE,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,SAAiB;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,SAAiB;QACvC,OAAO,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,SAAqB;QAC3C,OAAO,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;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AAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC5C,IAAI,MAAM,GAAG,CAAC;YAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;QAEpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,SAAc,EAAE,MAAW;QAC7D,IAAI,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;YAC7E,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC;YAC5B,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;SAC7B;QAED,MAAM,MAAM,GAAU,EAAE,CAAC;QACzB,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,IAAI,CAAC,GAAW,CAAC,CAAC;QAClB,OAAO,MAAM,GAAG,CAAC,EAAE;YACjB,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC,EAAE,CAAC;SACL;QACD,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;;AAvHc,mBAAS,GAA2B,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AA0HpG,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@mocyuto/aws-srp-client",
3
+ "version": "1.4.0",
4
+ "description": "Authenticate users with AWS Cognito via SRP",
5
+ "exports": "./lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "test": "jest --config jestconfig.json",
10
+ "build": "tsc",
11
+ "format": "prettier --write \"src/**/*.ts\"",
12
+ "lint": "tslint -p tsconfig.json",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm run lint",
15
+ "preversion": "npm run lint",
16
+ "version": "npm run format && git add -A src",
17
+ "postversion": "git push && git push --tags"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/mocyuto/aws-srp-client.git"
22
+ },
23
+ "keywords": [
24
+ "AWS",
25
+ "SRP"
26
+ ],
27
+ "author": "Yuto Suzuki",
28
+ "license": "ISC",
29
+ "devDependencies": {
30
+ "@types/crypto-js": "^4.1.1",
31
+ "@types/jest": "^29.5.2",
32
+ "@types/node": "^20.3.1",
33
+ "jest": "^29.5.0",
34
+ "prettier": "^2.8.8",
35
+ "ts-jest": "^29.1.0",
36
+ "tslint": "^6.1.3",
37
+ "tslint-config-prettier": "^1.18.0",
38
+ "typescript": "^5.1.3"
39
+ },
40
+ "files": [
41
+ "lib/**/*"
42
+ ],
43
+ "dependencies": {
44
+ "axios": "^1.4.0",
45
+ "big-integer": "^1.6.51",
46
+ "crypto-js": "^4.1.1",
47
+ "moment": "^2.29.4"
48
+ }
49
+ }