@socket.tech/dl-common 1.0.1

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.js +20 -0
  5. package/dist/models/attestSignature.d.ts +34 -0
  6. package/dist/models/attestSignature.js +32 -0
  7. package/dist/models/attestations.d.ts +69 -0
  8. package/dist/models/attestations.js +59 -0
  9. package/dist/models/index.d.ts +3 -0
  10. package/dist/models/index.js +19 -0
  11. package/dist/models/message.d.ts +165 -0
  12. package/dist/models/message.js +135 -0
  13. package/dist/models/packet.d.ts +220 -0
  14. package/dist/models/packet.js +195 -0
  15. package/dist/models/proposal.d.ts +126 -0
  16. package/dist/models/proposal.js +114 -0
  17. package/dist/services/cacheService.d.ts +14 -0
  18. package/dist/services/cacheService.js +89 -0
  19. package/dist/services/index.d.ts +2 -0
  20. package/dist/services/index.js +19 -0
  21. package/dist/services/queueService.d.ts +10 -0
  22. package/dist/services/queueService.js +57 -0
  23. package/dist/types/codes.d.ts +22 -0
  24. package/dist/types/codes.js +28 -0
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/index.js +18 -0
  27. package/dist/types/types.d.ts +86 -0
  28. package/dist/types/types.js +41 -0
  29. package/dist/utils/address.d.ts +2 -0
  30. package/dist/utils/address.js +8 -0
  31. package/dist/utils/axios.d.ts +2 -0
  32. package/dist/utils/axios.js +47 -0
  33. package/dist/utils/dataStructHelper.d.ts +2 -0
  34. package/dist/utils/dataStructHelper.js +10 -0
  35. package/dist/utils/discord.d.ts +1 -0
  36. package/dist/utils/discord.js +17 -0
  37. package/dist/utils/extraUtils.d.ts +22 -0
  38. package/dist/utils/extraUtils.js +85 -0
  39. package/dist/utils/idUtils.d.ts +13 -0
  40. package/dist/utils/idUtils.js +41 -0
  41. package/dist/utils/index.d.ts +7 -0
  42. package/dist/utils/index.js +23 -0
  43. package/dist/utils/relaySigner.d.ts +21 -0
  44. package/dist/utils/relaySigner.js +69 -0
  45. package/package.json +80 -0
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ const redis = require("async-redis");
5
+ let deploymentStage;
6
+ const initCache = (host, port, password, stage) => {
7
+ exports.client = redis.createClient({
8
+ port,
9
+ host,
10
+ password,
11
+ });
12
+ deploymentStage = stage;
13
+ };
14
+ exports.initCache = initCache;
15
+ const formatKey = (key) => {
16
+ return deploymentStage + "_" + key;
17
+ };
18
+ exports.formatKey = formatKey;
19
+ const getKey = async (key) => {
20
+ return await exports.client.get((0, exports.formatKey)(key));
21
+ };
22
+ exports.getKey = getKey;
23
+ 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;
30
+ };
31
+ exports.lock = lock;
32
+ 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));
36
+ };
37
+ exports.deleteKey = deleteKey;
38
+ const unlock = async (key) => {
39
+ let result = await exports.client.del((0, exports.formatKey)(key));
40
+ if (result)
41
+ console.log("unlocked");
42
+ };
43
+ exports.unlock = unlock;
44
+ const setKey = async (key, value, expire = 0, setIfNotExist = false) => {
45
+ let params = [(0, exports.formatKey)(key), value];
46
+ if (expire > 0)
47
+ params.push("EX", expire);
48
+ if (setIfNotExist)
49
+ params.push("NX");
50
+ console.log("command : SET ", params);
51
+ let response = await exports.client.sendCommand("SET", params);
52
+ if (response) {
53
+ console.log((0, exports.formatKey)(key) + " set to => " + value);
54
+ return true;
55
+ }
56
+ else
57
+ return false;
58
+ };
59
+ exports.setKey = setKey;
60
+ const rpush = async (key, values) => {
61
+ return await exports.client.rpush((0, exports.formatKey)(key), values);
62
+ };
63
+ exports.rpush = rpush;
64
+ const lpop = async (key) => {
65
+ return await exports.client.lpop((0, exports.formatKey)(key));
66
+ };
67
+ exports.lpop = lpop;
68
+ const getListLength = async (key) => {
69
+ return await exports.client.llen((0, exports.formatKey)(key));
70
+ };
71
+ exports.getListLength = getListLength;
72
+ const increment = async (key) => {
73
+ let value = await exports.client.incr((0, exports.formatKey)(key));
74
+ console.log("incremented key : ", (0, exports.formatKey)(key), " value : ", value);
75
+ return value;
76
+ };
77
+ exports.increment = increment;
78
+ 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;
82
+ };
83
+ exports.decrement = decrement;
84
+ const sendCommand = async (command, params) => {
85
+ params[0] = (0, exports.formatKey)(params[0]);
86
+ let result = await exports.client.sendCommand(command, params);
87
+ return result;
88
+ };
89
+ exports.sendCommand = sendCommand;
@@ -0,0 +1,2 @@
1
+ export * from "./queueService";
2
+ export * from "./cacheService";
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./queueService"), exports);
18
+ __exportStar(require("./cacheService"), exports);
19
+ // export * from "./apiService";
@@ -0,0 +1,10 @@
1
+ export declare const initQueue: (region: string) => void;
2
+ export declare const sendStandardSqsMessage: (queueUrl: string, data: any, DelaySeconds?: number) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
3
+ export declare const sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<import("@aws-sdk/client-sqs").SendMessageBatchCommandOutput>;
4
+ export declare const sendFifoSqsMessage: (queueUrl: string, data: any, MessageGroupId: string) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
5
+ declare const _default: {
6
+ sendStandardSqsMessage: (queueUrl: string, data: any, DelaySeconds?: number) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
7
+ sendFifoSqsMessage: (queueUrl: string, data: any, MessageGroupId: string) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
8
+ sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<import("@aws-sdk/client-sqs").SendMessageBatchCommandOutput>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendFifoSqsMessage = exports.sendStandardBatchMessages = exports.sendStandardSqsMessage = exports.initQueue = void 0;
4
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
5
+ let client;
6
+ const initQueue = (region) => {
7
+ client = new client_sqs_1.SQSClient({ region });
8
+ };
9
+ exports.initQueue = initQueue;
10
+ const sendStandardSqsMessage = async (queueUrl, data, DelaySeconds = 0) => {
11
+ let sqsOrderData = {
12
+ MessageBody: JSON.stringify(data),
13
+ QueueUrl: queueUrl,
14
+ DelaySeconds,
15
+ };
16
+ // Send the order data to the SQS queue
17
+ const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
18
+ let result = await client.send(command);
19
+ return result;
20
+ };
21
+ exports.sendStandardSqsMessage = sendStandardSqsMessage;
22
+ const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray = []) => {
23
+ let Entries = [];
24
+ for (let i = 0; i < dataArray.length; i++) {
25
+ Entries.push({
26
+ MessageBody: JSON.stringify(dataArray[i]),
27
+ Id: i,
28
+ DelaySeconds: DelaySecondsArray[i] ? DelaySecondsArray[i] : 0,
29
+ });
30
+ }
31
+ let sqsOrderData = {
32
+ Entries,
33
+ QueueUrl,
34
+ };
35
+ // Send the order data to the SQS queue
36
+ const command = new client_sqs_1.SendMessageBatchCommand(sqsOrderData);
37
+ let result = await client.send(command);
38
+ return result;
39
+ };
40
+ exports.sendStandardBatchMessages = sendStandardBatchMessages;
41
+ const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
42
+ let sqsOrderData = {
43
+ MessageBody: JSON.stringify(data),
44
+ QueueUrl: queueUrl,
45
+ MessageGroupId,
46
+ };
47
+ // Send the order data to the SQS queue
48
+ const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
49
+ let result = await client.send(command);
50
+ return result;
51
+ };
52
+ exports.sendFifoSqsMessage = sendFifoSqsMessage;
53
+ exports.default = {
54
+ sendStandardSqsMessage: exports.sendStandardSqsMessage,
55
+ sendFifoSqsMessage: exports.sendFifoSqsMessage,
56
+ sendStandardBatchMessages: exports.sendStandardBatchMessages,
57
+ };
@@ -0,0 +1,22 @@
1
+ export declare enum MessageStatuses {
2
+ RECEIVED = "RECEIVED",
3
+ SEALED = "SEALED",
4
+ PROPOSED = "PROPOSED",
5
+ CONFIRMED = "CONFIRMED",
6
+ EXECUTION_SUCCESS = "EXECUTION_SUCCESS",
7
+ EXECUTION_FAILURE = "EXECUTION_FAILURE"
8
+ }
9
+ export declare enum MessageStatusStep {
10
+ RECEIVED = 0,
11
+ SEALED = 1,
12
+ PROPOSED = 2,
13
+ CONFIRMED = 3,
14
+ EXECUTION_SUCCESS = 4,
15
+ EXECUTION_FAILURE = 5
16
+ }
17
+ export declare enum StatusCodes {
18
+ SUCCESS = "SUCCESS",
19
+ NOT_FOUND = "NOT_FOUND",
20
+ BAD_REQUEST = "BAD_REQUEST",
21
+ INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
22
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatusCodes = exports.MessageStatusStep = exports.MessageStatuses = void 0;
4
+ var MessageStatuses;
5
+ (function (MessageStatuses) {
6
+ MessageStatuses["RECEIVED"] = "RECEIVED";
7
+ MessageStatuses["SEALED"] = "SEALED";
8
+ MessageStatuses["PROPOSED"] = "PROPOSED";
9
+ MessageStatuses["CONFIRMED"] = "CONFIRMED";
10
+ MessageStatuses["EXECUTION_SUCCESS"] = "EXECUTION_SUCCESS";
11
+ MessageStatuses["EXECUTION_FAILURE"] = "EXECUTION_FAILURE";
12
+ })(MessageStatuses || (exports.MessageStatuses = MessageStatuses = {}));
13
+ var MessageStatusStep;
14
+ (function (MessageStatusStep) {
15
+ MessageStatusStep[MessageStatusStep["RECEIVED"] = 0] = "RECEIVED";
16
+ MessageStatusStep[MessageStatusStep["SEALED"] = 1] = "SEALED";
17
+ MessageStatusStep[MessageStatusStep["PROPOSED"] = 2] = "PROPOSED";
18
+ MessageStatusStep[MessageStatusStep["CONFIRMED"] = 3] = "CONFIRMED";
19
+ MessageStatusStep[MessageStatusStep["EXECUTION_SUCCESS"] = 4] = "EXECUTION_SUCCESS";
20
+ MessageStatusStep[MessageStatusStep["EXECUTION_FAILURE"] = 5] = "EXECUTION_FAILURE";
21
+ })(MessageStatusStep || (exports.MessageStatusStep = MessageStatusStep = {}));
22
+ var StatusCodes;
23
+ (function (StatusCodes) {
24
+ StatusCodes["SUCCESS"] = "SUCCESS";
25
+ StatusCodes["NOT_FOUND"] = "NOT_FOUND";
26
+ StatusCodes["BAD_REQUEST"] = "BAD_REQUEST";
27
+ StatusCodes["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
28
+ })(StatusCodes || (exports.StatusCodes = StatusCodes = {}));
@@ -0,0 +1,2 @@
1
+ export * from "./codes";
2
+ export * from "./types";
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./codes"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,86 @@
1
+ import { StatusCodes } from "./codes";
2
+ export type Speed = "safeLow" | "average" | "fast" | "fastest";
3
+ export declare enum InboundStatus {
4
+ NOT_TRIED = "NOT_TRIED",
5
+ REVERTING = "REVERTING",
6
+ EXECUTING = "EXECUTING",
7
+ SUCCESS = "SUCCESS"
8
+ }
9
+ export interface FeeEstimate {
10
+ transmissionFees: string;
11
+ verificationFees: string;
12
+ executionFees: string;
13
+ totalFees: string;
14
+ }
15
+ export declare enum RelayerAPIStatus {
16
+ FAILED = "FAILED",
17
+ SIMULATION_FAILED = "SIMULATION_FAILED",
18
+ COMPLETED = "COMPLETED"
19
+ }
20
+ export declare class ServerError {
21
+ code: Omit<StatusCodes, StatusCodes.SUCCESS>;
22
+ message?: string;
23
+ constructor(code: Omit<StatusCodes, StatusCodes.SUCCESS>, message?: string);
24
+ toString(): string;
25
+ }
26
+ export declare class BadRequestError {
27
+ code: Omit<StatusCodes, StatusCodes.SUCCESS>;
28
+ message?: string;
29
+ constructor(message?: string);
30
+ toString(): string;
31
+ }
32
+ export interface EthersError {
33
+ reason?: string;
34
+ code?: string;
35
+ argument?: string;
36
+ value?: string;
37
+ }
38
+ export type SealParams = {
39
+ srcChainSlug: number;
40
+ dstChainSlug: number;
41
+ dstSwitchboard: string;
42
+ message: {
43
+ messageId: string;
44
+ srcPlug: string;
45
+ destPlug: string;
46
+ minMsgGasLimit: string;
47
+ executionParams: string;
48
+ transmissionParams: string;
49
+ executionFee: string;
50
+ transmissionFees: string;
51
+ switchboardFees: string;
52
+ fees: string;
53
+ decapacitorProof: string;
54
+ payload: string;
55
+ packedMessage: string;
56
+ outboundTxHash: string;
57
+ outboundTime: number;
58
+ capacitorMsgCount: string;
59
+ };
60
+ packet: {
61
+ capacitorPacketCount: string;
62
+ rootHash: string;
63
+ packetId: string;
64
+ srcCapacitor: string;
65
+ root: string;
66
+ sealSignature: string;
67
+ };
68
+ };
69
+ export type SealIndexedParams = {
70
+ srcChainSlug: number;
71
+ sealer: string;
72
+ sealTime: number;
73
+ sealTxHash: string;
74
+ rootSealed: string;
75
+ dstSwitchboard: string;
76
+ sealSignature: string;
77
+ packetId: string;
78
+ };
79
+ export interface ExecuteSigResponse {
80
+ messageId: string;
81
+ retry: boolean;
82
+ inboundSuccess: boolean;
83
+ inboundRevertString: string;
84
+ executeSignature: string;
85
+ executeMsgGasLimit: string;
86
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BadRequestError = exports.ServerError = exports.RelayerAPIStatus = exports.InboundStatus = void 0;
4
+ const codes_1 = require("./codes");
5
+ var InboundStatus;
6
+ (function (InboundStatus) {
7
+ InboundStatus["NOT_TRIED"] = "NOT_TRIED";
8
+ InboundStatus["REVERTING"] = "REVERTING";
9
+ InboundStatus["EXECUTING"] = "EXECUTING";
10
+ InboundStatus["SUCCESS"] = "SUCCESS";
11
+ })(InboundStatus || (exports.InboundStatus = InboundStatus = {}));
12
+ var RelayerAPIStatus;
13
+ (function (RelayerAPIStatus) {
14
+ RelayerAPIStatus["FAILED"] = "FAILED";
15
+ RelayerAPIStatus["SIMULATION_FAILED"] = "SIMULATION_FAILED";
16
+ RelayerAPIStatus["COMPLETED"] = "COMPLETED";
17
+ })(RelayerAPIStatus || (exports.RelayerAPIStatus = RelayerAPIStatus = {}));
18
+ class ServerError {
19
+ constructor(code, message) {
20
+ this.code = code;
21
+ if (message) {
22
+ this.message = message;
23
+ }
24
+ }
25
+ toString() {
26
+ return `code: ${this.code}, message: ${this.message}`;
27
+ }
28
+ }
29
+ exports.ServerError = ServerError;
30
+ class BadRequestError {
31
+ constructor(message) {
32
+ this.code = codes_1.StatusCodes.BAD_REQUEST;
33
+ if (message) {
34
+ this.message = message;
35
+ }
36
+ }
37
+ toString() {
38
+ return `code: ${this.code}, message: ${this.message}`;
39
+ }
40
+ }
41
+ exports.BadRequestError = BadRequestError;
@@ -0,0 +1,2 @@
1
+ export declare const checksum: (address: string) => string;
2
+ export declare const toLowerCase: (address: string) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toLowerCase = exports.checksum = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const checksum = (address) => ethers_1.utils.getAddress(address);
6
+ exports.checksum = checksum;
7
+ const toLowerCase = (address) => address.toLowerCase();
8
+ exports.toLowerCase = toLowerCase;
@@ -0,0 +1,2 @@
1
+ export declare const axiosGet: (url: string, config?: {}, errorLogging?: boolean) => Promise<any>;
2
+ export declare const axiosPost: (url: string, data: object, config?: {}, errorLogging?: boolean) => Promise<any>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.axiosPost = exports.axiosGet = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const axiosGet = async (url, config = {}, errorLogging = false) => {
9
+ var _a, _b, _c, _d;
10
+ try {
11
+ const response = await axios_1.default.get(url, config);
12
+ return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
13
+ }
14
+ catch (error) {
15
+ if (errorLogging) {
16
+ console.log("status : ", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status);
17
+ console.log("error occurred, url : ", url, "\n error : ", error === null || error === void 0 ? void 0 : error.message, (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data);
18
+ }
19
+ return {
20
+ success: false,
21
+ status: (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.status,
22
+ message: error === null || error === void 0 ? void 0 : error.message,
23
+ ...(_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data,
24
+ };
25
+ }
26
+ };
27
+ exports.axiosGet = axiosGet;
28
+ const axiosPost = async (url, data, config = {}, errorLogging = false) => {
29
+ var _a, _b, _c, _d;
30
+ try {
31
+ const response = await axios_1.default.post(url, data, config);
32
+ return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
33
+ }
34
+ catch (error) {
35
+ if (errorLogging) {
36
+ console.log("status : ", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status);
37
+ console.log("error occurred, url : ", url, "data : ", data, "\n error : ", error === null || error === void 0 ? void 0 : error.message, (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data);
38
+ }
39
+ return {
40
+ success: false,
41
+ message: error === null || error === void 0 ? void 0 : error.message,
42
+ status: (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.status,
43
+ ...(_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data,
44
+ };
45
+ }
46
+ };
47
+ exports.axiosPost = axiosPost;
@@ -0,0 +1,2 @@
1
+ export declare const MAX_PAYLOAD_SIZE: number;
2
+ export declare function chunks<T>(arr: T[], n: number): Generator<T[], void>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chunks = exports.MAX_PAYLOAD_SIZE = void 0;
4
+ exports.MAX_PAYLOAD_SIZE = 10 * 1024; // max is 24.5 kb, left some buffer for function and batch encoding
5
+ function* chunks(arr, n) {
6
+ for (let i = 0; i < arr.length; i += n) {
7
+ yield arr.slice(i, i + n);
8
+ }
9
+ }
10
+ exports.chunks = chunks;
@@ -0,0 +1 @@
1
+ export declare const sendToDiscordWebhook: (data: any) => Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendToDiscordWebhook = void 0;
4
+ const axios_1 = require("./axios");
5
+ const sendToDiscordWebhook = async (data) => {
6
+ try {
7
+ const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL;
8
+ if (!discordWebhookUrl) {
9
+ throw new Error("DISCORD_WEBHOOK_URL not provided");
10
+ }
11
+ await (0, axios_1.axiosPost)(discordWebhookUrl, { content: JSON.stringify(data) });
12
+ }
13
+ catch (error) {
14
+ throw error;
15
+ }
16
+ };
17
+ exports.sendToDiscordWebhook = sendToDiscordWebhook;
@@ -0,0 +1,22 @@
1
+ export declare const removeFields: (obj: any, fieldsToRemove: string[]) => any;
2
+ export declare const filterFields: (obj: any, fieldsAllowed: string[]) => any;
3
+ /**
4
+ * util function to return body response.
5
+ * params: statusCode, message, data.
6
+ // */
7
+ export declare const responseBody: (statusCode?: number, message?: null | string, data?: any, success?: boolean, error_code?: number | null) => {
8
+ statusCode: number;
9
+ headers: {
10
+ "Access-Control-Allow-Origin": string;
11
+ "Access-Control-Allow-Credentials": boolean;
12
+ };
13
+ body: string;
14
+ };
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;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.responseBody = exports.filterFields = exports.removeFields = void 0;
4
+ /**
5
+ * defining functions.
6
+ */
7
+ const isEmpty = (data) => {
8
+ if (data === undefined || data === null || data === "") {
9
+ return true;
10
+ }
11
+ else {
12
+ return false;
13
+ }
14
+ }; // end of isEmpty.
15
+ const checkMissingFields = (fields) => {
16
+ for (const field in fields) {
17
+ if (isEmpty(fields[field])) {
18
+ throw { message: `missing field : ${field}`, code: 1 };
19
+ }
20
+ }
21
+ };
22
+ const checkMissingFieldsAndType = (fields, types = {}) => {
23
+ for (const field in fields) {
24
+ if (isEmpty(fields[field])) {
25
+ throw { message: `missing field : ${field}`, code: 1 };
26
+ }
27
+ 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
+ };
32
+ }
33
+ }
34
+ };
35
+ const removeFields = (obj, fieldsToRemove) => {
36
+ for (const field in obj) {
37
+ if (fieldsToRemove.includes(field)) {
38
+ delete obj[field];
39
+ }
40
+ }
41
+ return obj;
42
+ };
43
+ exports.removeFields = removeFields;
44
+ const filterFields = (obj, fieldsAllowed) => {
45
+ const finalObj = {};
46
+ for (const field in obj) {
47
+ if (fieldsAllowed.includes(field)) {
48
+ finalObj[field] = obj[field];
49
+ }
50
+ }
51
+ return finalObj;
52
+ };
53
+ exports.filterFields = filterFields;
54
+ /**
55
+ * util function to return body response.
56
+ * params: statusCode, message, data.
57
+ // */
58
+ const responseBody = (statusCode = 400, message = null, data = null, success = true, error_code = null) => {
59
+ // If no proper message present, or error code is not 1 => system generated error, return standard error message.
60
+ if (statusCode == 400 && (!message || error_code !== 1)) {
61
+ message = "BAD_REQUEST";
62
+ }
63
+ error_code = null;
64
+ return {
65
+ statusCode,
66
+ headers: {
67
+ "Access-Control-Allow-Origin": "*",
68
+ "Access-Control-Allow-Credentials": true,
69
+ },
70
+ body: JSON.stringify({
71
+ success,
72
+ error_code,
73
+ message,
74
+ data,
75
+ }),
76
+ };
77
+ }; // end responseBody function.
78
+ exports.responseBody = responseBody;
79
+ exports.default = {
80
+ isEmpty,
81
+ checkMissingFields,
82
+ checkMissingFieldsAndType,
83
+ removeFields: exports.removeFields,
84
+ filterFields: exports.filterFields,
85
+ };
@@ -0,0 +1,13 @@
1
+ export interface PacketDetails {
2
+ chainSlug: number;
3
+ capacitorAddr: string;
4
+ packetNonce: string;
5
+ }
6
+ export interface MessageDetails {
7
+ chainSlug: number;
8
+ siblingPlug: string;
9
+ globalMessageCount: string;
10
+ }
11
+ export declare const unpackPacketId: (packetId: string) => PacketDetails;
12
+ export declare const unpackMessageId: (messageId: string) => MessageDetails;
13
+ export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetNonce: string) => string;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const address_1 = require("./address");
6
+ const utils_1 = require("ethers/lib/utils");
7
+ const unpackPacketId = (packetId) => {
8
+ // 2(0x) + 1-8(chain slug) + 40(address) + 16(nonce)
9
+ const slugLength = packetId.length - 58;
10
+ const chainSlug = parseInt(ethers_1.BigNumber.from(`0x${packetId.substring(2, 2 + slugLength)}`).toString());
11
+ const capacitorAddr = (0, address_1.toLowerCase)(`0x${packetId.substring(2 + slugLength, 40 + 2 + slugLength)}`);
12
+ const packetNonce = ethers_1.BigNumber.from(`0x${packetId.substring(40 + 2 + slugLength)}`).toString();
13
+ return {
14
+ chainSlug,
15
+ capacitorAddr,
16
+ packetNonce,
17
+ };
18
+ };
19
+ exports.unpackPacketId = unpackPacketId;
20
+ const unpackMessageId = (messageId) => {
21
+ // 2(0x) + 1-8(chain slug) + 40(address) + 16(nonce)
22
+ const slugLength = messageId.length - 58;
23
+ const chainSlug = parseInt(ethers_1.BigNumber.from(`0x${messageId.substring(2, 2 + slugLength)}`).toString());
24
+ const siblingPlug = (0, address_1.toLowerCase)(`0x${messageId.substring(2 + slugLength, 40 + 2 + slugLength)}`);
25
+ const globalMessageCount = ethers_1.BigNumber.from(`0x${messageId.substring(40 + 2 + slugLength)}`).toString();
26
+ return {
27
+ chainSlug,
28
+ siblingPlug,
29
+ globalMessageCount,
30
+ };
31
+ };
32
+ exports.unpackMessageId = unpackMessageId;
33
+ const packPacketId = (chainSlug, capacitorAddr, packetNonce) => {
34
+ const nonce = ethers_1.BigNumber.from(packetNonce).toHexString();
35
+ const nonceHex = nonce.length <= 16 ? (0, utils_1.hexZeroPad)(nonce, 8).substring(2) : nonce.substring(2);
36
+ const slug = ethers_1.BigNumber.from(chainSlug).toHexString();
37
+ const slugHex = slug.length <= 10 ? (0, utils_1.hexZeroPad)(slug, 4) : slug;
38
+ const id = slugHex + capacitorAddr.substring(2) + nonceHex;
39
+ return id.toLowerCase();
40
+ };
41
+ exports.packPacketId = packPacketId;
@@ -0,0 +1,7 @@
1
+ export * from "./axios";
2
+ export * from "./discord";
3
+ export * from "./relaySigner";
4
+ export * from "./idUtils";
5
+ export * from "./address";
6
+ export * from "./dataStructHelper";
7
+ export * from "./extraUtils";