mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-05 00:24:50 +08:00
Add extracted source directory and README navigation
This commit is contained in:
100
extracted-source/node_modules/@azure/msal-node/dist/crypto/CryptoProvider.mjs
generated
vendored
Normal file
100
extracted-source/node_modules/@azure/msal-node/dist/crypto/CryptoProvider.mjs
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*! @azure/msal-node v3.8.1 2025-10-29 */
|
||||
'use strict';
|
||||
import { EncodingTypes } from '@azure/msal-common/node';
|
||||
import { GuidGenerator } from './GuidGenerator.mjs';
|
||||
import { EncodingUtils } from '../utils/EncodingUtils.mjs';
|
||||
import { PkceGenerator } from './PkceGenerator.mjs';
|
||||
import { HashUtils } from './HashUtils.mjs';
|
||||
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
/**
|
||||
* This class implements MSAL node's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
|
||||
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
||||
* @public
|
||||
*/
|
||||
class CryptoProvider {
|
||||
constructor() {
|
||||
// Browser crypto needs to be validated first before any other classes can be set.
|
||||
this.pkceGenerator = new PkceGenerator();
|
||||
this.guidGenerator = new GuidGenerator();
|
||||
this.hashUtils = new HashUtils();
|
||||
}
|
||||
/**
|
||||
* base64 URL safe encoded string
|
||||
*/
|
||||
base64UrlEncode() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Stringifies and base64Url encodes input public key
|
||||
* @param inputKid - public key id
|
||||
* @returns Base64Url encoded public key
|
||||
*/
|
||||
encodeKid() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Creates a new random GUID - used to populate state and nonce.
|
||||
* @returns string (GUID)
|
||||
*/
|
||||
createNewGuid() {
|
||||
return this.guidGenerator.generateGuid();
|
||||
}
|
||||
/**
|
||||
* Encodes input string to base64.
|
||||
* @param input - string to be encoded
|
||||
*/
|
||||
base64Encode(input) {
|
||||
return EncodingUtils.base64Encode(input);
|
||||
}
|
||||
/**
|
||||
* Decodes input string from base64.
|
||||
* @param input - string to be decoded
|
||||
*/
|
||||
base64Decode(input) {
|
||||
return EncodingUtils.base64Decode(input);
|
||||
}
|
||||
/**
|
||||
* Generates PKCE codes used in Authorization Code Flow.
|
||||
*/
|
||||
generatePkceCodes() {
|
||||
return this.pkceGenerator.generatePkceCodes();
|
||||
}
|
||||
/**
|
||||
* Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
|
||||
*/
|
||||
getPublicKeyThumbprint() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Removes cryptographic keypair from key store matching the keyId passed in
|
||||
* @param kid - public key id
|
||||
*/
|
||||
removeTokenBindingKey() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Removes all cryptographic keys from Keystore
|
||||
*/
|
||||
clearKeystore() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
|
||||
*/
|
||||
signJwt() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Returns the SHA-256 hash of an input string
|
||||
*/
|
||||
async hashString(plainText) {
|
||||
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString(EncodingTypes.BASE64), EncodingTypes.BASE64);
|
||||
}
|
||||
}
|
||||
|
||||
export { CryptoProvider };
|
||||
//# sourceMappingURL=CryptoProvider.mjs.map
|
||||
29
extracted-source/node_modules/@azure/msal-node/dist/crypto/GuidGenerator.mjs
generated
vendored
Normal file
29
extracted-source/node_modules/@azure/msal-node/dist/crypto/GuidGenerator.mjs
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/*! @azure/msal-node v3.8.1 2025-10-29 */
|
||||
'use strict';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
class GuidGenerator {
|
||||
/**
|
||||
*
|
||||
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
|
||||
* uuidv4 generates guids from cryprtographically-string random
|
||||
*/
|
||||
generateGuid() {
|
||||
return v4();
|
||||
}
|
||||
/**
|
||||
* verifies if a string is GUID
|
||||
* @param guid
|
||||
*/
|
||||
isGuid(guid) {
|
||||
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return regexGuid.test(guid);
|
||||
}
|
||||
}
|
||||
|
||||
export { GuidGenerator };
|
||||
//# sourceMappingURL=GuidGenerator.mjs.map
|
||||
21
extracted-source/node_modules/@azure/msal-node/dist/crypto/HashUtils.mjs
generated
vendored
Normal file
21
extracted-source/node_modules/@azure/msal-node/dist/crypto/HashUtils.mjs
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/*! @azure/msal-node v3.8.1 2025-10-29 */
|
||||
'use strict';
|
||||
import { Hash } from '../utils/Constants.mjs';
|
||||
import crypto from 'crypto';
|
||||
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
class HashUtils {
|
||||
/**
|
||||
* generate 'SHA256' hash
|
||||
* @param buffer
|
||||
*/
|
||||
sha256(buffer) {
|
||||
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
||||
}
|
||||
}
|
||||
|
||||
export { HashUtils };
|
||||
//# sourceMappingURL=HashUtils.mjs.map
|
||||
60
extracted-source/node_modules/@azure/msal-node/dist/crypto/PkceGenerator.mjs
generated
vendored
Normal file
60
extracted-source/node_modules/@azure/msal-node/dist/crypto/PkceGenerator.mjs
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*! @azure/msal-node v3.8.1 2025-10-29 */
|
||||
'use strict';
|
||||
import { EncodingTypes, Constants } from '@azure/msal-common/node';
|
||||
import { RANDOM_OCTET_SIZE, CharSet } from '../utils/Constants.mjs';
|
||||
import { EncodingUtils } from '../utils/EncodingUtils.mjs';
|
||||
import { HashUtils } from './HashUtils.mjs';
|
||||
import crypto from 'crypto';
|
||||
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc7636#page-8
|
||||
*/
|
||||
class PkceGenerator {
|
||||
constructor() {
|
||||
this.hashUtils = new HashUtils();
|
||||
}
|
||||
/**
|
||||
* generates the codeVerfier and the challenge from the codeVerfier
|
||||
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
||||
*/
|
||||
async generatePkceCodes() {
|
||||
const verifier = this.generateCodeVerifier();
|
||||
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
||||
return { verifier, challenge };
|
||||
}
|
||||
/**
|
||||
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
||||
*/
|
||||
generateCodeVerifier() {
|
||||
const charArr = [];
|
||||
const maxNumber = 256 - (256 % CharSet.CV_CHARSET.length);
|
||||
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
||||
const byte = crypto.randomBytes(1)[0];
|
||||
if (byte >= maxNumber) {
|
||||
/*
|
||||
* Ignore this number to maintain randomness.
|
||||
* Including it would result in an unequal distribution of characters after doing the modulo
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
const index = byte % CharSet.CV_CHARSET.length;
|
||||
charArr.push(CharSet.CV_CHARSET[index]);
|
||||
}
|
||||
const verifier = charArr.join(Constants.EMPTY_STRING);
|
||||
return EncodingUtils.base64EncodeUrl(verifier);
|
||||
}
|
||||
/**
|
||||
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
||||
* @param codeVerifier
|
||||
*/
|
||||
generateCodeChallengeFromVerifier(codeVerifier) {
|
||||
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString(EncodingTypes.BASE64), EncodingTypes.BASE64);
|
||||
}
|
||||
}
|
||||
|
||||
export { PkceGenerator };
|
||||
//# sourceMappingURL=PkceGenerator.mjs.map
|
||||
Reference in New Issue
Block a user