@creator.co/wapi 1.1.5 → 1.1.6
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/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +8 -0
- package/dist/src/Crypto/Crypto.js +84 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/Crypto/Crypto.ts +35 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Utils from "./src/API/Utils";
|
|
|
3
3
|
import EventProcessor from "./src/BaseEvent/EventProcessor";
|
|
4
4
|
import Process from "./src/BaseEvent/Process";
|
|
5
5
|
import Transaction from "./src/BaseEvent/Transaction";
|
|
6
|
+
import Crypto from "./src/Crypto/Crypto";
|
|
6
7
|
import Mailer from "./src/Mailer/Mailer";
|
|
7
8
|
import Publisher from "./src/Publisher/Publisher";
|
|
8
|
-
export { Transaction, Process, EventProcessor, Publisher, Mailer, Response, Utils, };
|
|
9
|
+
export { Transaction, Process, EventProcessor, Publisher, Mailer, Crypto, Response, Utils, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.Response = exports.Mailer = exports.Publisher = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
3
|
+
exports.Utils = exports.Response = exports.Crypto = exports.Mailer = exports.Publisher = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
4
4
|
var Response_1 = require("./src/API/Response");
|
|
5
5
|
exports.Response = Response_1.default;
|
|
6
6
|
var Utils_1 = require("./src/API/Utils");
|
|
@@ -11,6 +11,8 @@ var Process_1 = require("./src/BaseEvent/Process");
|
|
|
11
11
|
exports.Process = Process_1.default;
|
|
12
12
|
var Transaction_1 = require("./src/BaseEvent/Transaction");
|
|
13
13
|
exports.Transaction = Transaction_1.default;
|
|
14
|
+
var Crypto_1 = require("./src/Crypto/Crypto");
|
|
15
|
+
exports.Crypto = Crypto_1.default;
|
|
14
16
|
var Mailer_1 = require("./src/Mailer/Mailer");
|
|
15
17
|
exports.Mailer = Mailer_1.default;
|
|
16
18
|
var Publisher_1 = require("./src/Publisher/Publisher");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAmBvC,mBAnBK,kBAAQ,CAmBL;AAlBV,yCAAmC;AAoBjC,gBApBK,eAAK,CAoBL;AAnBP,iEAA2D;AAWzD,yBAXK,wBAAc,CAWL;AAVhB,mDAA6C;AAS3C,kBATK,iBAAO,CASL;AART,2DAAqD;AAOnD,sBAPK,qBAAW,CAOL;AANb,8CAAwC;AAYtC,iBAZK,gBAAM,CAYL;AAXR,8CAAwC;AAUtC,iBAVK,gBAAM,CAUL;AATR,uDAAiD;AAQ/C,oBARK,mBAAS,CAQL"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var client_kms_1 = require("@aws-sdk/client-kms");
|
|
40
|
+
var Crypto = /** @class */ (function () {
|
|
41
|
+
function Crypto(region, keyId) {
|
|
42
|
+
this.region = region;
|
|
43
|
+
this.keyId = keyId;
|
|
44
|
+
this.client = new client_kms_1.KMSClient({ region: this.region });
|
|
45
|
+
}
|
|
46
|
+
//
|
|
47
|
+
Crypto.prototype.encryptData = function (data) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var resp;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, this.client.send(new client_kms_1.EncryptCommand({
|
|
53
|
+
KeyId: this.keyId,
|
|
54
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
55
|
+
Plaintext: new TextEncoder().encode(typeof data === "string" ? data : JSON.stringify(data)),
|
|
56
|
+
}))];
|
|
57
|
+
case 1:
|
|
58
|
+
resp = _a.sent();
|
|
59
|
+
return [2 /*return*/, Buffer.from(String(resp.CiphertextBlob), "utf8").toString("hex")];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
Crypto.prototype.decryptData = function (data) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var resp;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, this.client.send(new client_kms_1.DecryptCommand({
|
|
70
|
+
KeyId: this.keyId,
|
|
71
|
+
CiphertextBlob: Buffer.from(data, "hex"),
|
|
72
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
73
|
+
}))];
|
|
74
|
+
case 1:
|
|
75
|
+
resp = _a.sent();
|
|
76
|
+
return [2 /*return*/, new TextDecoder().decode(resp.Plaintext)];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
return Crypto;
|
|
82
|
+
}());
|
|
83
|
+
exports.default = Crypto;
|
|
84
|
+
//# sourceMappingURL=Crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA+E;AAE/E;IAIE,gBAAY,MAAc,EAAE,KAAa;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,EAAE;IACI,4BAAW,GAAjB,UAAkB,IAAkB;;;;;4BACrB,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,2BAAc,CAAC;4BACjB,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,mBAAmB,EAAE,oBAAoB;4BACzC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CACjC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACvD;yBACF,CAAC,CACH,EAAA;;wBARK,IAAI,GAAG,SAQZ;wBACD,sBAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAA;;;;KACxE;IACK,4BAAW,GAAjB,UAAkB,IAAY;;;;;4BACf,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,2BAAc,CAAC;4BACjB,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;4BACxC,mBAAmB,EAAE,oBAAoB;yBAC1C,CAAC,CACH,EAAA;;wBANK,IAAI,GAAG,SAMZ;wBACD,sBAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAA;;;;KAChD;IACH,aAAC;AAAD,CAAC,AAhCD,IAgCC"}
|
package/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Utils from "./src/API/Utils"
|
|
|
3
3
|
import EventProcessor from "./src/BaseEvent/EventProcessor"
|
|
4
4
|
import Process from "./src/BaseEvent/Process"
|
|
5
5
|
import Transaction from "./src/BaseEvent/Transaction"
|
|
6
|
+
import Crypto from "./src/Crypto/Crypto"
|
|
6
7
|
import Mailer from "./src/Mailer/Mailer"
|
|
7
8
|
import Publisher from "./src/Publisher/Publisher"
|
|
8
9
|
|
|
@@ -14,6 +15,7 @@ export {
|
|
|
14
15
|
//Client
|
|
15
16
|
Publisher,
|
|
16
17
|
Mailer,
|
|
18
|
+
Crypto,
|
|
17
19
|
//Responses
|
|
18
20
|
Response,
|
|
19
21
|
//Helpers
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { KMSClient, EncryptCommand, DecryptCommand } from "@aws-sdk/client-kms"
|
|
2
|
+
|
|
3
|
+
export default class Crypto {
|
|
4
|
+
private readonly client: KMSClient
|
|
5
|
+
private readonly region: string
|
|
6
|
+
private readonly keyId: string
|
|
7
|
+
constructor(region: string, keyId: string) {
|
|
8
|
+
this.region = region
|
|
9
|
+
this.keyId = keyId
|
|
10
|
+
this.client = new KMSClient({ region: this.region })
|
|
11
|
+
}
|
|
12
|
+
//
|
|
13
|
+
async encryptData(data: string | any): Promise<string> {
|
|
14
|
+
const resp = await this.client.send(
|
|
15
|
+
new EncryptCommand({
|
|
16
|
+
KeyId: this.keyId,
|
|
17
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
18
|
+
Plaintext: new TextEncoder().encode(
|
|
19
|
+
typeof data === "string" ? data : JSON.stringify(data),
|
|
20
|
+
),
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
return Buffer.from(String(resp.CiphertextBlob), "utf8").toString("hex")
|
|
24
|
+
}
|
|
25
|
+
async decryptData(data: string): Promise<string> {
|
|
26
|
+
const resp = await this.client.send(
|
|
27
|
+
new DecryptCommand({
|
|
28
|
+
KeyId: this.keyId,
|
|
29
|
+
CiphertextBlob: Buffer.from(data, "hex"),
|
|
30
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
return new TextDecoder().decode(resp.Plaintext)
|
|
34
|
+
}
|
|
35
|
+
}
|