crypto-js#algo TypeScript Examples
The following examples show how to use
crypto-js#algo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: paypay-rest-sdk.ts From paypayopa-sdk-node with Apache License 2.0 | 6 votes |
private createAuthHeader = (method: string, resourceUrl: string, body: unknown) => {
const epoch = Math.floor(Date.now() / 1000);
const nonce = uuidv4();
const jsonified = JSON.stringify(body);
const isempty = [undefined, null, "", "undefined", "null"];
let contentType;
let payloadDigest;
if (isempty.includes(jsonified)) {
contentType = "empty";
payloadDigest = "empty";
} else {
contentType = "application/json";
payloadDigest = algo.MD5.create()
.update(contentType)
.update(jsonified)
.finalize()
.toString(enc.Base64);
}
const signatureRawList = [resourceUrl, method, nonce, epoch, contentType, payloadDigest];
const signatureRawData = signatureRawList.join("\n");
const hashed = HmacSHA256(signatureRawData, this.auth.clientSecret);
const hashed64 = enc.Base64.stringify(hashed);
const headList = [this.auth.clientId, hashed64, nonce, epoch, payloadDigest];
const header = headList.join(":");
return `hmac OPA-Auth:${header}`;
}