@riocrypto/common-server 1.0.1053 → 1.0.1055

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/build/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export * from "./models/admin-task";
38
38
  export * from "./models/master-order-record";
39
39
  export * from "./models/invoice";
40
40
  export * from "./models/bank-transfer";
41
+ export * from "./models/webhook-registration";
41
42
  export * from "./clients/bitstamp-client";
42
43
  export * from "./clients/ccxt-client";
43
44
  export * from "./clients/kushki-client";
package/build/index.js CHANGED
@@ -54,6 +54,7 @@ __exportStar(require("./models/admin-task"), exports);
54
54
  __exportStar(require("./models/master-order-record"), exports);
55
55
  __exportStar(require("./models/invoice"), exports);
56
56
  __exportStar(require("./models/bank-transfer"), exports);
57
+ __exportStar(require("./models/webhook-registration"), exports);
57
58
  __exportStar(require("./clients/bitstamp-client"), exports);
58
59
  __exportStar(require("./clients/ccxt-client"), exports);
59
60
  __exportStar(require("./clients/kushki-client"), exports);
@@ -3,11 +3,13 @@ interface WebhookRegistrationAttrs {
3
3
  userId: string;
4
4
  type: "user" | "order" | "bank-account";
5
5
  url: string;
6
+ encryptedSharedSecret: String;
6
7
  }
7
8
  interface WebhookRegistrationDoc extends Document {
8
9
  userId: string;
9
10
  type: "user" | "order" | "bank-account";
10
11
  url: string;
12
+ encryptedSharedSecret: String;
11
13
  }
12
14
  interface WebhookRegistrationModel extends Model<WebhookRegistrationDoc> {
13
15
  build(attrs: WebhookRegistrationAttrs): WebhookRegistrationDoc;
@@ -1,6 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.buildWebhookRegistration = void 0;
27
+ const crypto = __importStar(require("crypto"));
4
28
  const buildWebhookRegistration = (mongoose) => {
5
29
  // if model is already defined, return it
6
30
  if (mongoose.models.WebhookRegistration) {
@@ -19,6 +43,10 @@ const buildWebhookRegistration = (mongoose) => {
19
43
  type: String,
20
44
  required: true,
21
45
  },
46
+ encryptedSharedSecret: {
47
+ type: String,
48
+ required: true,
49
+ },
22
50
  }, {
23
51
  toJSON: {
24
52
  transform(doc, ret) {
@@ -31,6 +59,17 @@ const buildWebhookRegistration = (mongoose) => {
31
59
  WebhookRegistrationSchema.statics.build = (attrs) => {
32
60
  return new WebhookRegistration(attrs);
33
61
  };
62
+ WebhookRegistrationSchema.pre("save", function (next) {
63
+ // Encrypt the shared secret before saving
64
+ const algorithm = "aes-256-cbc";
65
+ const iv = crypto.randomBytes(16);
66
+ const sharedSecret = this.get("encryptedSharedSecret");
67
+ const cipher = crypto.createCipheriv(algorithm, Buffer.from(sharedSecret), iv);
68
+ let encryptedSecret = cipher.update(sharedSecret, "utf8", "hex");
69
+ encryptedSecret += cipher.final("hex");
70
+ this.set("encryptedSharedSecret", encryptedSecret);
71
+ next();
72
+ });
34
73
  const WebhookRegistration = mongoose.model("WebhookRegistration", WebhookRegistrationSchema);
35
74
  return WebhookRegistration;
36
75
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1053",
3
+ "version": "1.0.1055",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
25
  "@everapi/currencyapi-js": "^1.0.6",
26
26
  "@google-cloud/storage": "^6.9.5",
27
- "@riocrypto/common": "^1.0.905",
27
+ "@riocrypto/common": "^1.0.906",
28
28
  "@types/express": "^4.17.13",
29
29
  "axios": "^0.27.2",
30
30
  "ccxt": "^3.0.30",