@api-encrypt/sdk
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "@api-encrypt/sdk", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -5,2 +5,3 @@ export interface ISecret { | ||
} | ||
export declare const aesDecrypt: (wordArray: string, secret: ISecret) => string; | ||
export declare const generateAesSecretKey: () => ISecret; | ||
@@ -17,7 +18,7 @@ export declare const getAesSecretValue: (encryptedValue: string, encryptedSecretKey: ISecret, salt: string) => Promise<string>; | ||
onTimeKey: string; | ||
privateKey: string; | ||
encodedSecretKeys: string; | ||
userSecret: string; | ||
}) => Promise<{ | ||
data: any; | ||
decryptedData: string; | ||
decyptedSecret: string; | ||
message: any; | ||
data: string; | ||
}>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadDataFromAPIEncrypt = exports.setDataToAPIEncrypt = exports.creatAesSecretValue = exports.getAesSecretValue = exports.generateAesSecretKey = void 0; | ||
exports.loadDataFromAPIEncrypt = exports.setDataToAPIEncrypt = exports.creatAesSecretValue = exports.getAesSecretValue = exports.generateAesSecretKey = exports.aesDecrypt = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -17,2 +17,3 @@ const crypto_js_1 = require("crypto-js"); | ||
}; | ||
exports.aesDecrypt = aesDecrypt; | ||
const aseEncrypt = (wordArray, secret) => { | ||
@@ -40,3 +41,3 @@ // console.log('encrypWordArray----', wordArray, secret); | ||
// decrypt Secrrets key | ||
const uint8ArrayKey = new Uint8Array(aesDecrypt(encryptedSecretKey.key, { key: salt }).split(',').map(e => Number(e))); | ||
const uint8ArrayKey = new Uint8Array((0, exports.aesDecrypt)(encryptedSecretKey.key, { key: salt }).split(',').map(e => Number(e))); | ||
const enc = new TextDecoder(); | ||
@@ -46,3 +47,3 @@ const key = enc.decode(uint8ArrayKey); | ||
if (encryptedSecretKey.iv) { | ||
const uint8ArrayIv = new Uint8Array(aesDecrypt(encryptedSecretKey.iv, { key: salt }).split(',').map(e => Number(e))); | ||
const uint8ArrayIv = new Uint8Array((0, exports.aesDecrypt)(encryptedSecretKey.iv, { key: salt }).split(',').map(e => Number(e))); | ||
const iv = enc.decode(uint8ArrayIv); | ||
@@ -52,3 +53,3 @@ decriptedSecret.iv = iv; | ||
// decrypt data with decriptedSecret | ||
const decriptedValue = yield aesDecrypt(encryptedValue, decriptedSecret); | ||
const decriptedValue = yield (0, exports.aesDecrypt)(encryptedValue, decriptedSecret); | ||
const uint8ArrayValue = new Uint8Array(decriptedValue.split(',').map(e => Number(e))); | ||
@@ -94,3 +95,3 @@ const decodedValue = enc.decode(uint8ArrayValue); | ||
console.log('loadDataFromAPIEncrypt: ', params); | ||
const { url, clientId, onTimeKey, privateKey } = params; | ||
const { url, clientId, onTimeKey, encodedSecretKeys, userSecret } = params; | ||
const response = yield fetch(url, { | ||
@@ -106,8 +107,12 @@ method: 'GET', | ||
const encryptedSecretKey = response.headers.get('x-api-encrypt-key') || ''; | ||
const { data } = yield response.json(); | ||
// decrypt secret | ||
const decyptedSecret = yield (0, exports.getAesSecretValue)(encryptedSecretKey, { key: onTimeKey }, privateKey); | ||
const decryptedData = yield (0, exports.getAesSecretValue)(data, { key: decyptedSecret }, privateKey); | ||
const { data, message } = yield response.json(); | ||
const secretEncrypted = atob(encodedSecretKeys); | ||
const dataEncryptedFromDb = yield (0, exports.getAesSecretValue)(data, { key: encryptedSecretKey }, onTimeKey); | ||
const dataDecrypted = yield (0, exports.getAesSecretValue)(JSON.parse(dataEncryptedFromDb), JSON.parse(secretEncrypted), userSecret); | ||
console.log('dataEncryptedFromDb >>', JSON.parse(dataEncryptedFromDb)); | ||
console.log('secretEncrypted >>', JSON.parse(secretEncrypted)); | ||
console.log('dataDecrypted >>', dataDecrypted); | ||
return { | ||
data, decryptedData, decyptedSecret | ||
message, | ||
data: dataDecrypted | ||
}; | ||
@@ -114,0 +119,0 @@ }); |
Sorry, the diff of this file is not supported yet
11413
141