@socket.tech/dl-common 1.0.2 → 1.0.3-test.10

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.
Files changed (48) hide show
  1. package/README.md +17 -0
  2. package/dist/constants/enums.d.ts +37 -0
  3. package/dist/constants/enums.js +44 -0
  4. package/dist/constants/index.d.ts +3 -0
  5. package/dist/constants/index.js +19 -0
  6. package/dist/constants/types.d.ts +117 -0
  7. package/dist/constants/types.js +37 -0
  8. package/dist/constants/waitTime.d.ts +7 -0
  9. package/dist/constants/waitTime.js +50 -0
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/models/attestSignature.d.ts +1 -0
  13. package/dist/models/attestSignature.js +22 -1
  14. package/dist/models/attestation.d.ts +70 -0
  15. package/dist/models/attestation.js +86 -0
  16. package/dist/models/index.d.ts +3 -0
  17. package/dist/models/index.js +3 -0
  18. package/dist/models/message.d.ts +1 -0
  19. package/dist/models/message.js +49 -1
  20. package/dist/models/packet.d.ts +13 -0
  21. package/dist/models/packet.js +47 -1
  22. package/dist/models/proposal.d.ts +1 -0
  23. package/dist/models/proposal.js +28 -1
  24. package/dist/models/switchboard.d.ts +61 -0
  25. package/dist/models/switchboard.js +75 -0
  26. package/dist/services/cacheService.d.ts +3 -3
  27. package/dist/services/cacheService.js +9 -21
  28. package/dist/services/queueService.js +3 -6
  29. package/dist/utils/axios.js +7 -0
  30. package/dist/utils/discord.d.ts +2 -1
  31. package/dist/utils/discord.js +23 -5
  32. package/dist/utils/ethersAwsKmsSigner.d.ts +2 -0
  33. package/dist/utils/ethersAwsKmsSigner.js +23 -0
  34. package/dist/utils/eventGetter.d.ts +4 -0
  35. package/dist/utils/eventGetter.js +50 -0
  36. package/dist/utils/extraUtils.d.ts +18 -8
  37. package/dist/utils/extraUtils.js +35 -17
  38. package/dist/utils/idUtils.d.ts +3 -2
  39. package/dist/utils/idUtils.js +14 -5
  40. package/dist/utils/index.d.ts +4 -0
  41. package/dist/utils/index.js +4 -0
  42. package/dist/utils/relaySigner.d.ts +2 -2
  43. package/dist/utils/relaySigner.js +7 -8
  44. package/dist/utils/secretManagerService.d.ts +2 -0
  45. package/dist/utils/secretManagerService.js +33 -0
  46. package/dist/utils/time.d.ts +1 -0
  47. package/dist/utils/time.js +5 -0
  48. package/package.json +11 -6
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PacketModel = exports.Packet = exports.TripReason = exports.AttestRelayStatus = exports.ProposeRelayStatus = exports.PacketTripRelayStatus = exports.SealRelayStatus = void 0;
3
+ exports.addPacketHooks = exports.PacketModel = exports.Packet = exports.TripReason = exports.AttestRelayStatus = exports.ProposeRelayStatus = exports.PacketTripRelayStatus = exports.SealRelayStatus = void 0;
4
4
  const dl_core_1 = require("@socket.tech/dl-core");
5
5
  const sequelize_1 = require("sequelize");
6
+ const utils_1 = require("../utils");
6
7
  var SealRelayStatus;
7
8
  (function (SealRelayStatus) {
8
9
  SealRelayStatus["SEALED"] = "SEALED";
@@ -124,6 +125,12 @@ exports.PacketModel = {
124
125
  outboundTime: {
125
126
  type: sequelize_1.DataTypes.INTEGER,
126
127
  },
128
+ proposeTime: {
129
+ type: sequelize_1.DataTypes.INTEGER,
130
+ },
131
+ attestTime: {
132
+ type: sequelize_1.DataTypes.INTEGER,
133
+ },
127
134
  sealTime: {
128
135
  type: sequelize_1.DataTypes.INTEGER,
129
136
  },
@@ -170,6 +177,9 @@ exports.PacketModel = {
170
177
  selectedProposalCount: {
171
178
  type: sequelize_1.DataTypes.INTEGER,
172
179
  },
180
+ executionWaitTime: {
181
+ type: sequelize_1.DataTypes.INTEGER,
182
+ },
173
183
  attestTxId: {
174
184
  type: sequelize_1.DataTypes.STRING,
175
185
  defaultValue: "",
@@ -193,3 +203,39 @@ exports.PacketModel = {
193
203
  defaultValue: AttestRelayStatus.NO,
194
204
  },
195
205
  };
206
+ function processStrings(packet) {
207
+ if (packet.packetId)
208
+ packet.packetId = (0, utils_1.toLowerCase)(packet.packetId);
209
+ if (packet.root)
210
+ packet.root = (0, utils_1.toLowerCase)(packet.root);
211
+ if (packet.rootSealed)
212
+ packet.rootSealed = (0, utils_1.toLowerCase)(packet.rootSealed);
213
+ if (packet.sealer)
214
+ packet.sealer = (0, utils_1.toLowerCase)(packet.sealer);
215
+ if (packet.outboundTxHash) {
216
+ packet.outboundTxHash = (0, utils_1.toLowerCase)(packet.outboundTxHash);
217
+ }
218
+ if (packet.sealTxHash)
219
+ packet.sealTxHash = (0, utils_1.toLowerCase)(packet.sealTxHash);
220
+ if (packet.sealSignature) {
221
+ packet.sealSignature = (0, utils_1.toLowerCase)(packet.sealSignature);
222
+ }
223
+ if (packet.dstSwitchboard) {
224
+ packet.dstSwitchboard = (0, utils_1.toLowerCase)(packet.dstSwitchboard);
225
+ }
226
+ if (packet.packetTripTxHash) {
227
+ packet.packetTripTxHash = (0, utils_1.toLowerCase)(packet.packetTripTxHash);
228
+ }
229
+ return packet;
230
+ }
231
+ const addPacketHooks = () => {
232
+ Packet.beforeBulkCreate((packet, options) => {
233
+ for (let index = 0; index < packet.length; index++) {
234
+ packet[index] = processStrings(packet[index]);
235
+ }
236
+ });
237
+ Packet.beforeSave((packet, options) => {
238
+ packet = processStrings(packet);
239
+ });
240
+ };
241
+ exports.addPacketHooks = addPacketHooks;
@@ -124,3 +124,4 @@ export declare const ProposalModel: {
124
124
  defaultValue: boolean;
125
125
  };
126
126
  };
127
+ export declare const addProposalHooks: () => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProposalModel = exports.Proposal = exports.ProposalTripRelayStatus = exports.MatchState = exports.RootMatchState = exports.TripStatus = void 0;
3
+ exports.addProposalHooks = exports.ProposalModel = exports.Proposal = exports.ProposalTripRelayStatus = exports.MatchState = exports.RootMatchState = exports.TripStatus = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const utils_1 = require("../utils");
5
6
  var TripStatus;
6
7
  (function (TripStatus) {
7
8
  TripStatus["TRIP_REQUIRED"] = "TRIP_REQUIRED";
@@ -112,3 +113,29 @@ exports.ProposalModel = {
112
113
  defaultValue: false,
113
114
  },
114
115
  };
116
+ function processStrings(proposal) {
117
+ if (proposal.packetId)
118
+ proposal.packetId = (0, utils_1.toLowerCase)(proposal.packetId);
119
+ if (proposal.root)
120
+ proposal.root = (0, utils_1.toLowerCase)(proposal.root);
121
+ if (proposal.switchboard)
122
+ proposal.switchboard = (0, utils_1.toLowerCase)(proposal.switchboard);
123
+ if (proposal.proposer)
124
+ proposal.proposer = (0, utils_1.toLowerCase)(proposal.proposer);
125
+ if (proposal.proposeTxHash)
126
+ proposal.proposeTxHash = (0, utils_1.toLowerCase)(proposal.proposeTxHash);
127
+ if (proposal.tripTxHash)
128
+ proposal.tripTxHash = (0, utils_1.toLowerCase)(proposal.tripTxHash);
129
+ return proposal;
130
+ }
131
+ const addProposalHooks = () => {
132
+ Proposal.beforeBulkCreate((proposal, options) => {
133
+ for (let index = 0; index < proposal.length; index++) {
134
+ proposal[index] = processStrings(proposal[index]);
135
+ }
136
+ });
137
+ Proposal.beforeSave((proposal, options) => {
138
+ proposal = processStrings(proposal);
139
+ });
140
+ };
141
+ exports.addProposalHooks = addProposalHooks;
@@ -0,0 +1,61 @@
1
+ import { IntegrationTypes } from "@socket.tech/dl-core";
2
+ import { DataTypes, Model } from "sequelize";
3
+ export declare enum CapacitorType {
4
+ singleCapacitor = "1",
5
+ hashChainCapacitor = "2"
6
+ }
7
+ export declare class Switchboard extends Model {
8
+ id: number;
9
+ srcChainSlug: number;
10
+ dstChainSlug: number;
11
+ maxPacketLength: number;
12
+ srcSwitchboard: string;
13
+ dstSwitchboard: string;
14
+ srcCapacitor: string;
15
+ capacitorType: CapacitorType;
16
+ isEnabled: boolean;
17
+ integrationType: IntegrationTypes;
18
+ }
19
+ export declare const SwitchboardModel: {
20
+ id: {
21
+ type: DataTypes.IntegerDataTypeConstructor;
22
+ autoIncrement: boolean;
23
+ primaryKey: boolean;
24
+ };
25
+ srcChainSlug: {
26
+ type: DataTypes.IntegerDataTypeConstructor;
27
+ unique: string;
28
+ };
29
+ dstChainSlug: {
30
+ type: DataTypes.IntegerDataTypeConstructor;
31
+ unique: string;
32
+ };
33
+ maxPacketLength: {
34
+ type: DataTypes.IntegerDataTypeConstructor;
35
+ };
36
+ srcSwitchboard: {
37
+ type: DataTypes.StringDataTypeConstructor;
38
+ unique: string;
39
+ };
40
+ dstSwitchboard: {
41
+ type: DataTypes.StringDataTypeConstructor;
42
+ };
43
+ srcCapacitor: {
44
+ type: DataTypes.StringDataTypeConstructor;
45
+ };
46
+ capacitorType: {
47
+ type: DataTypes.EnumDataTypeConstructor;
48
+ values: CapacitorType[];
49
+ defaultValue: CapacitorType;
50
+ };
51
+ isEnabled: {
52
+ type: DataTypes.AbstractDataTypeConstructor;
53
+ defaultValue: boolean;
54
+ };
55
+ integrationType: {
56
+ type: DataTypes.EnumDataTypeConstructor;
57
+ values: IntegrationTypes[];
58
+ defaultValue: IntegrationTypes;
59
+ };
60
+ };
61
+ export declare const addSwitchboardHooks: () => Promise<void>;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSwitchboardHooks = exports.SwitchboardModel = exports.Switchboard = exports.CapacitorType = void 0;
4
+ const dl_core_1 = require("@socket.tech/dl-core");
5
+ const sequelize_1 = require("sequelize");
6
+ var CapacitorType;
7
+ (function (CapacitorType) {
8
+ CapacitorType["singleCapacitor"] = "1";
9
+ CapacitorType["hashChainCapacitor"] = "2";
10
+ })(CapacitorType || (exports.CapacitorType = CapacitorType = {}));
11
+ class Switchboard extends sequelize_1.Model {
12
+ }
13
+ exports.Switchboard = Switchboard;
14
+ exports.SwitchboardModel = {
15
+ id: {
16
+ type: sequelize_1.DataTypes.INTEGER,
17
+ autoIncrement: true,
18
+ primaryKey: true,
19
+ },
20
+ srcChainSlug: {
21
+ type: sequelize_1.DataTypes.INTEGER,
22
+ unique: "uniqueSwitchboardPointer",
23
+ },
24
+ dstChainSlug: {
25
+ type: sequelize_1.DataTypes.INTEGER,
26
+ unique: "uniqueSwitchboardPointer",
27
+ },
28
+ maxPacketLength: {
29
+ type: sequelize_1.DataTypes.INTEGER,
30
+ },
31
+ srcSwitchboard: {
32
+ type: sequelize_1.DataTypes.STRING,
33
+ unique: "uniqueSwitchboardPointer",
34
+ },
35
+ dstSwitchboard: {
36
+ type: sequelize_1.DataTypes.STRING,
37
+ },
38
+ srcCapacitor: {
39
+ type: sequelize_1.DataTypes.STRING,
40
+ },
41
+ capacitorType: {
42
+ type: sequelize_1.DataTypes.ENUM,
43
+ values: [...Object.values(CapacitorType)],
44
+ defaultValue: CapacitorType.singleCapacitor,
45
+ },
46
+ isEnabled: {
47
+ type: sequelize_1.DataTypes.BOOLEAN,
48
+ defaultValue: false,
49
+ },
50
+ integrationType: {
51
+ type: sequelize_1.DataTypes.ENUM,
52
+ values: [...Object.values(dl_core_1.IntegrationTypes)],
53
+ defaultValue: dl_core_1.IntegrationTypes.unknown,
54
+ },
55
+ };
56
+ const addSwitchboardHooks = async () => {
57
+ Switchboard.beforeBulkCreate((switchboards, options) => {
58
+ for (let index = 0; index < switchboards.length; index++) {
59
+ switchboards[index] = processStrings(switchboards[index]);
60
+ }
61
+ });
62
+ Switchboard.beforeSave((switchboard, options) => {
63
+ switchboard = processStrings(switchboard);
64
+ });
65
+ };
66
+ exports.addSwitchboardHooks = addSwitchboardHooks;
67
+ function processStrings(switchboard) {
68
+ if (switchboard.srcSwitchboard)
69
+ switchboard.srcSwitchboard = switchboard.srcSwitchboard.toLowerCase();
70
+ if (switchboard.dstSwitchboard)
71
+ switchboard.dstSwitchboard = switchboard.dstSwitchboard.toLowerCase();
72
+ if (switchboard.srcCapacitor)
73
+ switchboard.srcCapacitor = switchboard.srcCapacitor.toLowerCase();
74
+ return switchboard;
75
+ }
@@ -1,10 +1,10 @@
1
1
  export declare let client: any;
2
- export declare const initCache: (host: string, port: number, password: string, stage: string) => void;
2
+ export declare const initCache: (host: string, port: number, password: string, stage: string, serviceName: string) => void;
3
3
  export declare const formatKey: (key: string) => string;
4
4
  export declare const getKey: (key: string) => Promise<any>;
5
5
  export declare const lock: (key: string, expire?: number) => Promise<boolean>;
6
- export declare const deleteKey: (key: string) => Promise<void>;
7
- export declare const unlock: (key: string) => Promise<void>;
6
+ export declare const deleteKey: (key: string) => Promise<any>;
7
+ export declare const unlock: (key: string) => Promise<any>;
8
8
  export declare const setKey: (key: string, value: any, expire?: number, setIfNotExist?: boolean) => Promise<boolean>;
9
9
  export declare const rpush: (key: string, values: any[]) => Promise<any>;
10
10
  export declare const lpop: (key: string) => Promise<any>;
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendCommand = exports.decrement = exports.increment = exports.getListLength = exports.lpop = exports.rpush = exports.setKey = exports.unlock = exports.deleteKey = exports.lock = exports.getKey = exports.formatKey = exports.initCache = exports.client = void 0;
4
4
  const redis = require("async-redis");
5
5
  let deploymentStage;
6
- const initCache = (host, port, password, stage) => {
6
+ let servicePrefix;
7
+ const initCache = (host, port, password, stage, serviceName) => {
7
8
  exports.client = redis.createClient({
8
9
  port,
9
10
  host,
10
11
  password,
11
12
  });
12
13
  deploymentStage = stage;
14
+ servicePrefix = serviceName;
13
15
  };
14
16
  exports.initCache = initCache;
15
17
  const formatKey = (key) => {
16
- return deploymentStage + "_" + key;
18
+ return deploymentStage + "_" + servicePrefix + "_" + key;
17
19
  };
18
20
  exports.formatKey = formatKey;
19
21
  const getKey = async (key) => {
@@ -21,24 +23,15 @@ const getKey = async (key) => {
21
23
  };
22
24
  exports.getKey = getKey;
23
25
  const lock = async (key, expire = 0) => {
24
- let result = await (0, exports.setKey)(key, "locked", expire, true);
25
- if (result)
26
- console.log("acquired lock!");
27
- else
28
- console.log("blocked");
29
- return result;
26
+ return await (0, exports.setKey)(key, "locked", expire, true);
30
27
  };
31
28
  exports.lock = lock;
32
29
  const deleteKey = async (key) => {
33
- let result = await exports.client.del((0, exports.formatKey)(key));
34
- if (result)
35
- console.log("deleted ", (0, exports.formatKey)(key));
30
+ return await exports.client.del((0, exports.formatKey)(key));
36
31
  };
37
32
  exports.deleteKey = deleteKey;
38
33
  const unlock = async (key) => {
39
- let result = await exports.client.del((0, exports.formatKey)(key));
40
- if (result)
41
- console.log("unlocked");
34
+ return await exports.client.del((0, exports.formatKey)(key));
42
35
  };
43
36
  exports.unlock = unlock;
44
37
  const setKey = async (key, value, expire = 0, setIfNotExist = false) => {
@@ -47,10 +40,8 @@ const setKey = async (key, value, expire = 0, setIfNotExist = false) => {
47
40
  params.push("EX", expire);
48
41
  if (setIfNotExist)
49
42
  params.push("NX");
50
- console.log("command : SET ", params);
51
43
  let response = await exports.client.sendCommand("SET", params);
52
44
  if (response) {
53
- console.log((0, exports.formatKey)(key) + " set to => " + value);
54
45
  return true;
55
46
  }
56
47
  else
@@ -76,14 +67,11 @@ const increment = async (key) => {
76
67
  };
77
68
  exports.increment = increment;
78
69
  const decrement = async (key) => {
79
- let value = await exports.client.decr((0, exports.formatKey)(key));
80
- console.log("decremented key : ", (0, exports.formatKey)(key), " value : ", value);
81
- return value;
70
+ return await exports.client.decr((0, exports.formatKey)(key));
82
71
  };
83
72
  exports.decrement = decrement;
84
73
  const sendCommand = async (command, params) => {
85
74
  params[0] = (0, exports.formatKey)(params[0]);
86
- let result = await exports.client.sendCommand(command, params);
87
- return result;
75
+ return await exports.client.sendCommand(command, params);
88
76
  };
89
77
  exports.sendCommand = sendCommand;
@@ -15,8 +15,7 @@ const sendStandardSqsMessage = async (queueUrl, data, DelaySeconds = 0) => {
15
15
  };
16
16
  // Send the order data to the SQS queue
17
17
  const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
18
- let result = await client.send(command);
19
- return result;
18
+ return await client.send(command);
20
19
  };
21
20
  exports.sendStandardSqsMessage = sendStandardSqsMessage;
22
21
  const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray = []) => {
@@ -34,8 +33,7 @@ const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray
34
33
  };
35
34
  // Send the order data to the SQS queue
36
35
  const command = new client_sqs_1.SendMessageBatchCommand(sqsOrderData);
37
- let result = await client.send(command);
38
- return result;
36
+ return await client.send(command);
39
37
  };
40
38
  exports.sendStandardBatchMessages = sendStandardBatchMessages;
41
39
  const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
@@ -46,8 +44,7 @@ const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
46
44
  };
47
45
  // Send the order data to the SQS queue
48
46
  const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
49
- let result = await client.send(command);
50
- return result;
47
+ return await client.send(command);
51
48
  };
52
49
  exports.sendFifoSqsMessage = sendFifoSqsMessage;
53
50
  exports.default = {
@@ -5,8 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.axiosPost = exports.axiosGet = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const __1 = require("..");
8
9
  const axiosGet = async (url, config = {}, errorLogging = false) => {
9
10
  var _a, _b, _c, _d;
11
+ if (!url)
12
+ throw (0, __1.InternalServerError)("GET request url not provided");
10
13
  try {
11
14
  const response = await axios_1.default.get(url, config);
12
15
  return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
@@ -27,6 +30,10 @@ const axiosGet = async (url, config = {}, errorLogging = false) => {
27
30
  exports.axiosGet = axiosGet;
28
31
  const axiosPost = async (url, data, config = {}, errorLogging = false) => {
29
32
  var _a, _b, _c, _d;
33
+ if (!url)
34
+ throw (0, __1.InternalServerError)("POST request url not provided");
35
+ if (!data)
36
+ throw (0, __1.InternalServerError)("POST request data not provided");
30
37
  try {
31
38
  const response = await axios_1.default.post(url, data, config);
32
39
  return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
@@ -1 +1,2 @@
1
- export declare const sendToDiscordWebhook: (data: any) => Promise<void>;
1
+ export declare const initDiscord: (webhookUrl_: string, serviceName_: string) => void;
2
+ export declare const sendToDiscordWebhook: (title: string, data: object, optionalConfig?: object) => Promise<void>;
@@ -1,17 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendToDiscordWebhook = void 0;
3
+ exports.sendToDiscordWebhook = exports.initDiscord = void 0;
4
+ const __1 = require("..");
4
5
  const axios_1 = require("./axios");
5
- const sendToDiscordWebhook = async (data) => {
6
+ let discordWebhookUrl;
7
+ let serviceName;
8
+ const initDiscord = (webhookUrl_, serviceName_) => {
9
+ discordWebhookUrl = webhookUrl_;
10
+ serviceName = serviceName_;
11
+ };
12
+ exports.initDiscord = initDiscord;
13
+ const sendToDiscordWebhook = async (title, data, optionalConfig = {}) => {
6
14
  try {
7
- const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL;
8
15
  if (!discordWebhookUrl) {
9
- throw new Error("DISCORD_WEBHOOK_URL not provided");
16
+ throw (0, __1.InternalServerError)("DISCORD_WEBHOOK_URL not provided");
10
17
  }
11
- await (0, axios_1.axiosPost)(discordWebhookUrl, { content: JSON.stringify(data) });
18
+ let content = formatMsg(title, data);
19
+ await (0, axios_1.axiosPost)(discordWebhookUrl, { content, ...optionalConfig });
12
20
  }
13
21
  catch (error) {
14
22
  throw error;
15
23
  }
16
24
  };
17
25
  exports.sendToDiscordWebhook = sendToDiscordWebhook;
26
+ const formatMsg = (title, data) => {
27
+ let message = `**${title}**\n`;
28
+ // Iterate through the object's key-value pairs
29
+ for (const key in data) {
30
+ if (data.hasOwnProperty(key)) {
31
+ message += `${key}: ${data[key]}\n`;
32
+ }
33
+ }
34
+ return message;
35
+ };
@@ -0,0 +1,2 @@
1
+ import { AwsKmsSigner } from "ethers-aws-kms-signer";
2
+ export declare const getAwsKmsSigner: (keyId: string, region?: string) => Promise<AwsKmsSigner>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAwsKmsSigner = void 0;
4
+ const ethers_aws_kms_signer_1 = require("ethers-aws-kms-signer");
5
+ const getAwsKmsSigner = async (keyId, region = "us-east-1") => {
6
+ try {
7
+ const kmsCredentials = {
8
+ region,
9
+ keyId,
10
+ };
11
+ let signer = new ethers_aws_kms_signer_1.AwsKmsSigner(kmsCredentials);
12
+ let signerAddress = await signer.getAddress();
13
+ // logger.info(` keyid ${keyId} ${signerAddress}`);
14
+ if (!signerAddress) {
15
+ throw new Error(`Invalid kms signer, keyId:${keyId}`);
16
+ }
17
+ return signer;
18
+ }
19
+ catch (error) {
20
+ throw error;
21
+ }
22
+ };
23
+ exports.getAwsKmsSigner = getAwsKmsSigner;
@@ -0,0 +1,4 @@
1
+ import { Contract, Event, EventFilter, providers } from "ethers";
2
+ import { StaticJsonRpcProvider } from "@ethersproject/providers";
3
+ export declare const getEvents: (contract: Contract, filter: EventFilter | string, fromBlock: number, toBlock: number, eventBlockRange?: number) => Promise<Event[]>;
4
+ export declare const getLogs: (provider: StaticJsonRpcProvider, address: string[], topics: string[], fromBlock: number, toBlock: number, eventBlockRange?: number) => Promise<providers.Log[]>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLogs = exports.getEvents = void 0;
4
+ const getEvents = async (contract, filter, fromBlock, toBlock, eventBlockRange = 5000) => {
5
+ const allEvents = [];
6
+ try {
7
+ let from = fromBlock;
8
+ let to = from + eventBlockRange - 1;
9
+ to = to < toBlock ? to : toBlock;
10
+ while (from <= toBlock) {
11
+ const events = await contract.queryFilter(filter, from, to);
12
+ allEvents.push(...events);
13
+ from = to + 1;
14
+ to = from + eventBlockRange - 1;
15
+ to = to < toBlock ? to : toBlock;
16
+ }
17
+ }
18
+ catch (error) {
19
+ throw error;
20
+ }
21
+ return allEvents;
22
+ };
23
+ exports.getEvents = getEvents;
24
+ const getLogs = async (provider, address, topics, fromBlock, toBlock, eventBlockRange = 5000) => {
25
+ const allLogs = [];
26
+ try {
27
+ let from = fromBlock;
28
+ let to = from + eventBlockRange - 1;
29
+ to = to < toBlock ? to : toBlock;
30
+ while (from <= toBlock) {
31
+ const logs = await provider.send("eth_getLogs", [
32
+ {
33
+ address,
34
+ topics,
35
+ fromBlock: `0x${from.toString(16)}`,
36
+ toBlock: `0x${to.toString(16)}`,
37
+ },
38
+ ]);
39
+ allLogs.push(...logs);
40
+ from = to + 1;
41
+ to = from + eventBlockRange - 1;
42
+ to = to < toBlock ? to : toBlock;
43
+ }
44
+ }
45
+ catch (error) {
46
+ throw error;
47
+ }
48
+ return allLogs;
49
+ };
50
+ exports.getLogs = getLogs;
@@ -1,3 +1,21 @@
1
+ /**
2
+ * defining functions.
3
+ */
4
+ export declare const isEmpty: (data: any) => boolean;
5
+ export declare const checkMissingFields: (fields: {
6
+ [key: string]: any;
7
+ }) => void;
8
+ export declare const checkEnvValue: (key: string) => string;
9
+ export declare const checkMissingFieldsAndType: (fields: {
10
+ [key: string]: any;
11
+ }, types?: {
12
+ [key: string]: string;
13
+ }) => void;
14
+ export declare const checkObjectFieldsAndType: (data: {
15
+ [key: string]: any;
16
+ }, types?: {
17
+ [key: string]: any;
18
+ }, prefix?: string) => void;
1
19
  export declare const removeFields: (obj: any, fieldsToRemove: string[]) => any;
2
20
  export declare const filterFields: (obj: any, fieldsAllowed: string[]) => any;
3
21
  /**
@@ -12,11 +30,3 @@ export declare const responseBody: (statusCode?: number, message?: null | string
12
30
  };
13
31
  body: string;
14
32
  };
15
- declare const _default: {
16
- isEmpty: (data: any) => boolean;
17
- checkMissingFields: (fields: any) => void;
18
- checkMissingFieldsAndType: (fields: any, types?: any) => void;
19
- removeFields: (obj: any, fieldsToRemove: string[]) => any;
20
- filterFields: (obj: any, fieldsAllowed: string[]) => any;
21
- };
22
- export default _default;
@@ -1,37 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.responseBody = exports.filterFields = exports.removeFields = void 0;
3
+ exports.responseBody = exports.filterFields = exports.removeFields = exports.checkObjectFieldsAndType = exports.checkMissingFieldsAndType = exports.checkEnvValue = exports.checkMissingFields = exports.isEmpty = void 0;
4
+ const constants_1 = require("../constants");
4
5
  /**
5
6
  * defining functions.
6
7
  */
7
8
  const isEmpty = (data) => {
8
- if (data === undefined || data === null || data === "") {
9
+ if (data === undefined || data === null) {
9
10
  return true;
10
11
  }
11
12
  else {
12
13
  return false;
13
14
  }
14
15
  }; // end of isEmpty.
16
+ exports.isEmpty = isEmpty;
15
17
  const checkMissingFields = (fields) => {
16
18
  for (const field in fields) {
17
- if (isEmpty(fields[field])) {
18
- throw { message: `missing field : ${field}`, code: 1 };
19
+ let value = fields[field];
20
+ if (!value) {
21
+ throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
19
22
  }
20
23
  }
21
24
  };
25
+ exports.checkMissingFields = checkMissingFields;
26
+ const checkEnvValue = (key) => {
27
+ let value = process.env[key];
28
+ if (!value) {
29
+ throw (0, constants_1.InternalServerError)(`${key} not found`);
30
+ }
31
+ return value;
32
+ };
33
+ exports.checkEnvValue = checkEnvValue;
22
34
  const checkMissingFieldsAndType = (fields, types = {}) => {
23
35
  for (const field in fields) {
24
- if (isEmpty(fields[field])) {
25
- throw { message: `missing field : ${field}`, code: 1 };
36
+ if ((0, exports.isEmpty)(fields[field])) {
37
+ throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
26
38
  }
27
39
  if (types[field] && typeof fields[field] !== types[field]) {
28
- throw {
29
- message: `Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`,
30
- code: 1,
31
- };
40
+ throw (0, constants_1.BadRequestError)(`Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`);
41
+ }
42
+ }
43
+ };
44
+ exports.checkMissingFieldsAndType = checkMissingFieldsAndType;
45
+ const checkObjectFieldsAndType = (data, types = {}, prefix = "") => {
46
+ let keys = Object.keys(types);
47
+ for (const key of keys) {
48
+ if ((0, exports.isEmpty)(data[key])) {
49
+ throw (0, constants_1.BadRequestError)(`missing field : ${prefix}.${key}`);
50
+ }
51
+ if (typeof data[key] === "object") {
52
+ (0, exports.checkObjectFieldsAndType)(data[key], types[key], `${prefix}.${key}`);
53
+ }
54
+ else if (typeof data[key] !== types[key]) {
55
+ throw (0, constants_1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
32
56
  }
33
57
  }
34
58
  };
59
+ exports.checkObjectFieldsAndType = checkObjectFieldsAndType;
35
60
  const removeFields = (obj, fieldsToRemove) => {
36
61
  for (const field in obj) {
37
62
  if (fieldsToRemove.includes(field)) {
@@ -76,10 +101,3 @@ const responseBody = (statusCode = 400, message = null, data = null, success = t
76
101
  };
77
102
  }; // end responseBody function.
78
103
  exports.responseBody = responseBody;
79
- exports.default = {
80
- isEmpty,
81
- checkMissingFields,
82
- checkMissingFieldsAndType,
83
- removeFields: exports.removeFields,
84
- filterFields: exports.filterFields,
85
- };
@@ -1,7 +1,7 @@
1
1
  export interface PacketDetails {
2
2
  chainSlug: number;
3
3
  capacitorAddr: string;
4
- packetNonce: string;
4
+ packetCount: string;
5
5
  }
6
6
  export interface MessageDetails {
7
7
  chainSlug: number;
@@ -10,4 +10,5 @@ export interface MessageDetails {
10
10
  }
11
11
  export declare const unpackPacketId: (packetId: string) => PacketDetails;
12
12
  export declare const unpackMessageId: (messageId: string) => MessageDetails;
13
- export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetNonce: string) => string;
13
+ export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetCount: string) => string;
14
+ export declare function encodePacketId(chainSlug: number, capacitorAddress: string, packetCount: number): string;