@socket.tech/dl-common 1.0.2 → 1.0.3-test.2
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/README.md +17 -0
- package/dist/constants/enums.d.ts +33 -0
- package/dist/constants/enums.js +40 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +19 -0
- package/dist/constants/types.d.ts +104 -0
- package/dist/constants/types.js +37 -0
- package/dist/constants/waitTime.d.ts +7 -0
- package/dist/constants/waitTime.js +51 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models/attestSignature.d.ts +1 -0
- package/dist/models/attestSignature.js +22 -1
- package/dist/models/attestation.d.ts +70 -0
- package/dist/models/attestation.js +86 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +2 -0
- package/dist/models/message.d.ts +1 -0
- package/dist/models/message.js +49 -1
- package/dist/models/packet.d.ts +13 -0
- package/dist/models/packet.js +47 -1
- package/dist/models/proposal.d.ts +1 -0
- package/dist/models/proposal.js +28 -1
- package/dist/services/cacheService.d.ts +3 -3
- package/dist/services/cacheService.js +9 -21
- package/dist/services/queueService.js +3 -6
- package/dist/utils/axios.js +7 -0
- package/dist/utils/discord.d.ts +2 -1
- package/dist/utils/discord.js +23 -5
- package/dist/utils/ethersAwsKmsSigner.d.ts +2 -0
- package/dist/utils/ethersAwsKmsSigner.js +23 -0
- package/dist/utils/eventGetter.d.ts +4 -0
- package/dist/utils/eventGetter.js +50 -0
- package/dist/utils/extraUtils.d.ts +17 -8
- package/dist/utils/extraUtils.js +27 -17
- package/dist/utils/idUtils.d.ts +1 -0
- package/dist/utils/idUtils.js +10 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/relaySigner.d.ts +3 -1
- package/dist/utils/relaySigner.js +7 -5
- package/dist/utils/secretManagerService.d.ts +2 -0
- package/dist/utils/secretManagerService.js +33 -0
- package/dist/utils/time.d.ts +1 -0
- package/dist/utils/time.js +5 -0
- package/package.json +10 -5
package/dist/models/packet.js
CHANGED
|
@@ -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;
|
package/dist/models/proposal.js
CHANGED
|
@@ -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;
|
|
@@ -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<
|
|
7
|
-
export declare const unlock: (key: string) => Promise<
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
return result;
|
|
47
|
+
return await client.send(command);
|
|
51
48
|
};
|
|
52
49
|
exports.sendFifoSqsMessage = sendFifoSqsMessage;
|
|
53
50
|
exports.default = {
|
package/dist/utils/axios.js
CHANGED
|
@@ -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 };
|
package/dist/utils/discord.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const initDiscord: (webhookUrl_: string, serviceName_: string) => void;
|
|
2
|
+
export declare const sendToDiscordWebhook: (title: string, data: object, optionalConfig?: object) => Promise<void>;
|
package/dist/utils/discord.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
16
|
+
throw (0, __1.InternalServerError)("DISCORD_WEBHOOK_URL not provided");
|
|
10
17
|
}
|
|
11
|
-
|
|
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,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,20 @@
|
|
|
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 checkMissingFieldsAndType: (fields: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}, types?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
export declare const checkObjectFieldsAndType: (data: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}, types?: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}, prefix?: string) => void;
|
|
1
18
|
export declare const removeFields: (obj: any, fieldsToRemove: string[]) => any;
|
|
2
19
|
export declare const filterFields: (obj: any, fieldsAllowed: string[]) => any;
|
|
3
20
|
/**
|
|
@@ -12,11 +29,3 @@ export declare const responseBody: (statusCode?: number, message?: null | string
|
|
|
12
29
|
};
|
|
13
30
|
body: string;
|
|
14
31
|
};
|
|
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;
|
package/dist/utils/extraUtils.js
CHANGED
|
@@ -1,37 +1,54 @@
|
|
|
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.checkMissingFields = exports.isEmpty = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
4
5
|
/**
|
|
5
6
|
* defining functions.
|
|
6
7
|
*/
|
|
7
8
|
const isEmpty = (data) => {
|
|
8
|
-
if (data === undefined || data === null
|
|
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
|
-
|
|
18
|
-
|
|
19
|
+
let value = fields[field];
|
|
20
|
+
if (!value) {
|
|
21
|
+
throw (0, __1.BadRequestError)(`missing field : ${field}`);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
};
|
|
25
|
+
exports.checkMissingFields = checkMissingFields;
|
|
22
26
|
const checkMissingFieldsAndType = (fields, types = {}) => {
|
|
23
27
|
for (const field in fields) {
|
|
24
|
-
if (isEmpty(fields[field])) {
|
|
25
|
-
throw
|
|
28
|
+
if ((0, exports.isEmpty)(fields[field])) {
|
|
29
|
+
throw (0, __1.BadRequestError)(`missing field : ${field}`);
|
|
26
30
|
}
|
|
27
31
|
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
|
+
throw (0, __1.BadRequestError)(`Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
};
|
|
36
|
+
exports.checkMissingFieldsAndType = checkMissingFieldsAndType;
|
|
37
|
+
const checkObjectFieldsAndType = (data, types = {}, prefix = "") => {
|
|
38
|
+
let keys = Object.keys(types);
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
if ((0, exports.isEmpty)(data[key])) {
|
|
41
|
+
throw (0, __1.BadRequestError)(`missing field : ${prefix}.${key}`);
|
|
42
|
+
}
|
|
43
|
+
if (typeof data[key] === "object") {
|
|
44
|
+
(0, exports.checkObjectFieldsAndType)(data[key], types[key], `${prefix}.${key}`);
|
|
45
|
+
}
|
|
46
|
+
else if (typeof data[key] !== types[key]) {
|
|
47
|
+
throw (0, __1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.checkObjectFieldsAndType = checkObjectFieldsAndType;
|
|
35
52
|
const removeFields = (obj, fieldsToRemove) => {
|
|
36
53
|
for (const field in obj) {
|
|
37
54
|
if (fieldsToRemove.includes(field)) {
|
|
@@ -76,10 +93,3 @@ const responseBody = (statusCode = 400, message = null, data = null, success = t
|
|
|
76
93
|
};
|
|
77
94
|
}; // end responseBody function.
|
|
78
95
|
exports.responseBody = responseBody;
|
|
79
|
-
exports.default = {
|
|
80
|
-
isEmpty,
|
|
81
|
-
checkMissingFields,
|
|
82
|
-
checkMissingFieldsAndType,
|
|
83
|
-
removeFields: exports.removeFields,
|
|
84
|
-
filterFields: exports.filterFields,
|
|
85
|
-
};
|
package/dist/utils/idUtils.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export interface MessageDetails {
|
|
|
11
11
|
export declare const unpackPacketId: (packetId: string) => PacketDetails;
|
|
12
12
|
export declare const unpackMessageId: (messageId: string) => MessageDetails;
|
|
13
13
|
export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetNonce: string) => string;
|
|
14
|
+
export declare function encodePacketId(chainSlug: number, capacitorAddress: string, packetCount: number): string;
|
package/dist/utils/idUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
|
|
3
|
+
exports.encodePacketId = exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const address_1 = require("./address");
|
|
6
6
|
const utils_1 = require("ethers/lib/utils");
|
|
@@ -39,3 +39,12 @@ const packPacketId = (chainSlug, capacitorAddr, packetNonce) => {
|
|
|
39
39
|
return id.toLowerCase();
|
|
40
40
|
};
|
|
41
41
|
exports.packPacketId = packPacketId;
|
|
42
|
+
function encodePacketId(chainSlug, capacitorAddress, packetCount) {
|
|
43
|
+
const encodedValue = (BigInt(chainSlug) << BigInt(224)) |
|
|
44
|
+
(BigInt(capacitorAddress) << BigInt(64)) |
|
|
45
|
+
BigInt(packetCount);
|
|
46
|
+
// Ensure the result is a 32-byte hex string (bytes32 in Solidity)
|
|
47
|
+
const resultHex = encodedValue.toString(16).padStart(64, "0");
|
|
48
|
+
return "0x" + resultHex;
|
|
49
|
+
}
|
|
50
|
+
exports.encodePacketId = encodePacketId;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -21,3 +21,5 @@ __exportStar(require("./idUtils"), exports);
|
|
|
21
21
|
__exportStar(require("./address"), exports);
|
|
22
22
|
__exportStar(require("./dataStructHelper"), exports);
|
|
23
23
|
__exportStar(require("./extraUtils"), exports);
|
|
24
|
+
__exportStar(require("./time"), exports);
|
|
25
|
+
__exportStar(require("./ethersAwsKmsSigner"), exports);
|
|
@@ -2,15 +2,17 @@ import { Provider, TransactionRequest, TransactionResponse } from "@ethersprojec
|
|
|
2
2
|
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
3
|
import { Bytes } from "@ethersproject/bytes";
|
|
4
4
|
import { Deferrable } from "@ethersproject/properties";
|
|
5
|
+
import { ChainSlug } from "@socket.tech/dl-core";
|
|
5
6
|
export declare class SocketRelaySigner extends Signer {
|
|
6
7
|
readonly provider: Provider;
|
|
8
|
+
readonly chainSlug: ChainSlug;
|
|
7
9
|
readonly relayUrl: string;
|
|
8
10
|
readonly relayerAPIKey: string;
|
|
9
11
|
readonly sequential: boolean;
|
|
10
12
|
readonly isCritical: boolean;
|
|
11
13
|
readonly metadata: object;
|
|
12
14
|
readonly source: string;
|
|
13
|
-
constructor(provider: Provider, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object, source?: string);
|
|
15
|
+
constructor(provider: Provider, chainSlug: ChainSlug, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object, source?: string);
|
|
14
16
|
getAddress(): Promise<string>;
|
|
15
17
|
signMessage(message: string | Bytes): Promise<string>;
|
|
16
18
|
connect(provider: Provider): SocketRelaySigner;
|
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SocketRelaySigner = void 0;
|
|
4
4
|
const abstract_signer_1 = require("@ethersproject/abstract-signer");
|
|
5
5
|
const axios_1 = require("./axios");
|
|
6
|
+
const dl_core_1 = require("@socket.tech/dl-core");
|
|
6
7
|
class SocketRelaySigner extends abstract_signer_1.Signer {
|
|
7
|
-
constructor(provider, relayUrl, relayerAPIKey, sequential = false,
|
|
8
|
+
constructor(provider, chainSlug, relayUrl, relayerAPIKey, sequential = false,
|
|
8
9
|
// if isCritical is set to true, will try multiple relayers
|
|
9
10
|
// to get the transaction included
|
|
10
11
|
isCritical = false, metadata = {}, source = "Attester") {
|
|
11
12
|
super();
|
|
12
13
|
this.provider = provider;
|
|
14
|
+
this.chainSlug = chainSlug;
|
|
13
15
|
this.relayUrl = relayUrl;
|
|
14
16
|
this.relayerAPIKey = relayerAPIKey;
|
|
15
17
|
this.sequential = sequential;
|
|
@@ -25,13 +27,13 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
|
|
|
25
27
|
throw new Error(" signMessage not Implemented");
|
|
26
28
|
}
|
|
27
29
|
connect(provider) {
|
|
28
|
-
return new SocketRelaySigner(provider, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
|
|
30
|
+
return new SocketRelaySigner(provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
|
|
29
31
|
}
|
|
30
32
|
setCritical(isCritical) {
|
|
31
|
-
return new SocketRelaySigner(this.provider, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
|
|
33
|
+
return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
|
|
32
34
|
}
|
|
33
35
|
addMetadata(metadata) {
|
|
34
|
-
return new SocketRelaySigner(this.provider, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
|
|
36
|
+
return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
|
|
35
37
|
}
|
|
36
38
|
async signTransaction(transaction) {
|
|
37
39
|
throw new Error(" signTransaction not Implemented");
|
|
@@ -43,7 +45,7 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
|
|
|
43
45
|
if (!this.relayUrl)
|
|
44
46
|
throw new Error("relayUrl not provided");
|
|
45
47
|
let payload = {
|
|
46
|
-
chainId:
|
|
48
|
+
chainId: dl_core_1.ChainSlugToId[this.chainSlug],
|
|
47
49
|
sequential: this.sequential,
|
|
48
50
|
isCritical: this.isCritical,
|
|
49
51
|
source: this.source,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSecret = exports.getAllSecrets = void 0;
|
|
4
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
5
|
+
const defaultRegion = "us-east-1";
|
|
6
|
+
const getAllSecrets = async (secretName, region = defaultRegion) => {
|
|
7
|
+
try {
|
|
8
|
+
const client = new client_secrets_manager_1.SecretsManagerClient({
|
|
9
|
+
region,
|
|
10
|
+
});
|
|
11
|
+
let response = await client.send(new client_secrets_manager_1.GetSecretValueCommand({
|
|
12
|
+
SecretId: secretName,
|
|
13
|
+
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
|
|
14
|
+
}));
|
|
15
|
+
if (!(response === null || response === void 0 ? void 0 : response.SecretString))
|
|
16
|
+
throw new Error("No secret found");
|
|
17
|
+
return JSON.parse(response.SecretString);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.getAllSecrets = getAllSecrets;
|
|
24
|
+
const getSecret = async (secretName, secretKey, region = defaultRegion) => {
|
|
25
|
+
try {
|
|
26
|
+
let secrets = await (0, exports.getAllSecrets)(secretName, region);
|
|
27
|
+
return secrets === null || secrets === void 0 ? void 0 : secrets[secretKey];
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.getSecret = getSecret;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const currentTimestampInSeconds: () => number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentTimestampInSeconds = void 0;
|
|
4
|
+
const currentTimestampInSeconds = () => Math.floor(new Date().getTime() / 1000);
|
|
5
|
+
exports.currentTimestampInSeconds = currentTimestampInSeconds;
|