Complete Email Sortierer implementation with Appwrite and Stripe integration
This commit is contained in:
40
server/node_modules/stripe/esm/crypto/CryptoProvider.js
generated
vendored
Normal file
40
server/node_modules/stripe/esm/crypto/CryptoProvider.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Interface encapsulating the various crypto computations used by the library,
|
||||
* allowing pluggable underlying crypto implementations.
|
||||
*/
|
||||
export class CryptoProvider {
|
||||
/**
|
||||
* Computes a SHA-256 HMAC given a secret and a payload (encoded in UTF-8).
|
||||
* The output HMAC should be encoded in hexadecimal.
|
||||
*
|
||||
* Sample values for implementations:
|
||||
* - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd'
|
||||
* - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43
|
||||
*/
|
||||
computeHMACSignature(payload, secret) {
|
||||
throw new Error('computeHMACSignature not implemented.');
|
||||
}
|
||||
/**
|
||||
* Asynchronous version of `computeHMACSignature`. Some implementations may
|
||||
* only allow support async signature computation.
|
||||
*
|
||||
* Computes a SHA-256 HMAC given a secret and a payload (encoded in UTF-8).
|
||||
* The output HMAC should be encoded in hexadecimal.
|
||||
*
|
||||
* Sample values for implementations:
|
||||
* - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd'
|
||||
* - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43
|
||||
*/
|
||||
computeHMACSignatureAsync(payload, secret) {
|
||||
throw new Error('computeHMACSignatureAsync not implemented.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* If the crypto provider only supports asynchronous operations,
|
||||
* throw CryptoProviderOnlySupportsAsyncError instead of
|
||||
* a generic error so that the caller can choose to provide
|
||||
* a more helpful error message to direct the user to use
|
||||
* an asynchronous pathway.
|
||||
*/
|
||||
export class CryptoProviderOnlySupportsAsyncError extends Error {
|
||||
}
|
||||
19
server/node_modules/stripe/esm/crypto/NodeCryptoProvider.js
generated
vendored
Normal file
19
server/node_modules/stripe/esm/crypto/NodeCryptoProvider.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { CryptoProvider } from './CryptoProvider.js';
|
||||
/**
|
||||
* `CryptoProvider which uses the Node `crypto` package for its computations.
|
||||
*/
|
||||
export class NodeCryptoProvider extends CryptoProvider {
|
||||
/** @override */
|
||||
computeHMACSignature(payload, secret) {
|
||||
return crypto
|
||||
.createHmac('sha256', secret)
|
||||
.update(payload, 'utf8')
|
||||
.digest('hex');
|
||||
}
|
||||
/** @override */
|
||||
async computeHMACSignatureAsync(payload, secret) {
|
||||
const signature = await this.computeHMACSignature(payload, secret);
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
43
server/node_modules/stripe/esm/crypto/SubtleCryptoProvider.js
generated
vendored
Normal file
43
server/node_modules/stripe/esm/crypto/SubtleCryptoProvider.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import { CryptoProvider, CryptoProviderOnlySupportsAsyncError, } from './CryptoProvider.js';
|
||||
/**
|
||||
* `CryptoProvider which uses the SubtleCrypto interface of the Web Crypto API.
|
||||
*
|
||||
* This only supports asynchronous operations.
|
||||
*/
|
||||
export class SubtleCryptoProvider extends CryptoProvider {
|
||||
constructor(subtleCrypto) {
|
||||
super();
|
||||
// If no subtle crypto is interface, default to the global namespace. This
|
||||
// is to allow custom interfaces (eg. using the Node webcrypto interface in
|
||||
// tests).
|
||||
this.subtleCrypto = subtleCrypto || crypto.subtle;
|
||||
}
|
||||
/** @override */
|
||||
computeHMACSignature(payload, secret) {
|
||||
throw new CryptoProviderOnlySupportsAsyncError('SubtleCryptoProvider cannot be used in a synchronous context.');
|
||||
}
|
||||
/** @override */
|
||||
async computeHMACSignatureAsync(payload, secret) {
|
||||
const encoder = new TextEncoder();
|
||||
const key = await this.subtleCrypto.importKey('raw', encoder.encode(secret), {
|
||||
name: 'HMAC',
|
||||
hash: { name: 'SHA-256' },
|
||||
}, false, ['sign']);
|
||||
const signatureBuffer = await this.subtleCrypto.sign('hmac', key, encoder.encode(payload));
|
||||
// crypto.subtle returns the signature in base64 format. This must be
|
||||
// encoded in hex to match the CryptoProvider contract. We map each byte in
|
||||
// the buffer to its corresponding hex octet and then combine into a string.
|
||||
const signatureBytes = new Uint8Array(signatureBuffer);
|
||||
const signatureHexCodes = new Array(signatureBytes.length);
|
||||
for (let i = 0; i < signatureBytes.length; i++) {
|
||||
signatureHexCodes[i] = byteHexMapping[signatureBytes[i]];
|
||||
}
|
||||
return signatureHexCodes.join('');
|
||||
}
|
||||
}
|
||||
// Cached mapping of byte to hex representation. We do this once to avoid re-
|
||||
// computing every time we need to convert the result of a signature to hex.
|
||||
const byteHexMapping = new Array(256);
|
||||
for (let i = 0; i < byteHexMapping.length; i++) {
|
||||
byteHexMapping[i] = i.toString(16).padStart(2, '0');
|
||||
}
|
||||
Reference in New Issue
Block a user