@socket.tech/dl-common 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/confirmations.d.ts +5 -0
- package/dist/constants/confirmations.js +17 -0
- package/dist/constants/enums.d.ts +44 -0
- package/dist/constants/enums.js +52 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +19 -0
- package/dist/constants/types.d.ts +136 -0
- package/dist/constants/types.js +53 -0
- package/dist/constants/waitTime.d.ts +8 -0
- package/dist/constants/waitTime.js +45 -0
- package/dist/dl-common/constants/index.d.ts +1 -0
- package/dist/dl-common/constants/index.js +1 -0
- package/dist/dl-common/constants/index.js.map +1 -1
- package/dist/dl-common/constants/relay-types.d.ts +78 -0
- package/dist/dl-common/constants/relay-types.js +24 -0
- package/dist/dl-common/constants/relay-types.js.map +1 -0
- package/dist/dl-common/constants/types.d.ts +0 -6
- package/dist/dl-common/constants/types.js +1 -8
- package/dist/dl-common/constants/types.js.map +1 -1
- package/dist/dl-common/utils/index.d.ts +1 -0
- package/dist/dl-common/utils/index.js +1 -0
- package/dist/dl-common/utils/index.js.map +1 -1
- package/dist/dl-common/utils/relaySigner.d.ts +6 -2
- package/dist/dl-common/utils/relaySigner.js +23 -5
- package/dist/dl-common/utils/relaySigner.js.map +1 -1
- package/dist/dl-common/utils/relayUtils.d.ts +2 -0
- package/dist/dl-common/utils/relayUtils.js +21 -0
- package/dist/dl-common/utils/relayUtils.js.map +1 -0
- package/dist/dl-common/utils/signer/adapter.js.map +1 -1
- package/dist/dl-common/utils/signer/kms-ethers-signer.js.map +1 -1
- package/dist/dl-common/utils/signer/kms-signer.js +1 -1
- package/dist/dl-common/utils/signer/socketSigner.js +1 -1
- package/dist/dl-common/utils/signer/socketSigner.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +36 -0
- package/dist/models/attestSignature.d.ts +35 -0
- package/dist/models/attestSignature.js +53 -0
- package/dist/models/attestation.d.ts +70 -0
- package/dist/models/attestation.js +86 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.js +23 -0
- package/dist/models/lastBlock.d.ts +28 -0
- package/dist/models/lastBlock.js +27 -0
- package/dist/models/message.d.ts +171 -0
- package/dist/models/message.js +193 -0
- package/dist/models/packet.d.ts +240 -0
- package/dist/models/packet.js +249 -0
- package/dist/models/proposal.d.ts +127 -0
- package/dist/models/proposal.js +141 -0
- package/dist/models/switchboard.d.ts +69 -0
- package/dist/models/switchboard.js +92 -0
- package/dist/models/transaction.d.ts +0 -0
- package/dist/models/transaction.js +280 -0
- package/dist/services/cacheService.d.ts +14 -0
- package/dist/services/cacheService.js +77 -0
- package/dist/services/eventBridgeService.d.ts +8 -0
- package/dist/services/eventBridgeService.js +40 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +20 -0
- package/dist/services/queueService.d.ts +10 -0
- package/dist/services/queueService.js +62 -0
- package/dist/src/constants/gasEstimation.d.ts +8 -0
- package/dist/src/constants/gasEstimation.js +61 -0
- package/dist/src/constants/relayer.d.ts +0 -3
- package/dist/src/constants/relayer.js +4 -9
- package/dist/src/constants/relayer.js.map +1 -1
- package/dist/src/constants/types.d.ts +3 -3
- package/dist/src/handlers/statusHandler.js +1 -1
- package/dist/src/handlers/statusHandler.js.map +1 -1
- package/dist/src/relayers/common.js +3 -3
- package/dist/src/relayers/common.js.map +1 -1
- package/dist/src/relayers/propose/main.js +4 -8
- package/dist/src/relayers/propose/main.js.map +1 -1
- package/dist/src/relayers/proposeRelayer.d.ts +7 -0
- package/dist/src/relayers/proposeRelayer.js +587 -0
- package/dist/src/relayers/sealRelayer.js +4 -6
- package/dist/src/relayers/sealRelayer.js.map +1 -1
- package/dist/src/services/batcherService.d.ts +9 -0
- package/dist/src/services/batcherService.js +197 -0
- package/dist/src/services/executeService.d.ts +16 -0
- package/dist/src/services/executeService.js +209 -0
- package/dist/src/statusTrackers/message.js +6 -5
- package/dist/src/statusTrackers/message.js.map +1 -1
- package/dist/src/statusTrackers/packet.d.ts +2 -2
- package/dist/src/statusTrackers/packet.js +6 -5
- package/dist/src/statusTrackers/packet.js.map +1 -1
- package/dist/utils/address.d.ts +2 -0
- package/dist/utils/address.js +8 -0
- package/dist/utils/axios.d.ts +2 -0
- package/dist/utils/axios.js +54 -0
- package/dist/utils/dataStructHelper.d.ts +2 -0
- package/dist/utils/dataStructHelper.js +10 -0
- package/dist/utils/discord.d.ts +2 -0
- package/dist/utils/discord.js +43 -0
- package/dist/utils/ethersAwsKmsSigner.d.ts +2 -0
- package/dist/utils/ethersAwsKmsSigner.js +26 -0
- package/dist/utils/eventGetter.d.ts +4 -0
- package/dist/utils/eventGetter.js +50 -0
- package/dist/utils/extraUtils.d.ts +32 -0
- package/dist/utils/extraUtils.js +103 -0
- package/dist/utils/idUtils.d.ts +14 -0
- package/dist/utils/idUtils.js +50 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +29 -0
- package/dist/utils/relaySigner.d.ts +21 -0
- package/dist/utils/relaySigner.js +68 -0
- package/dist/utils/s3Service.d.ts +11 -0
- package/dist/utils/s3Service.js +70 -0
- package/dist/utils/secretManagerService.d.ts +2 -0
- package/dist/utils/secretManagerService.js +33 -0
- package/dist/utils/signer/adapter.d.ts +18 -0
- package/dist/utils/signer/adapter.js +71 -0
- package/dist/utils/signer/address.d.ts +9 -0
- package/dist/utils/signer/address.js +42 -0
- package/dist/utils/signer/asn1-parser.d.ts +10 -0
- package/dist/utils/signer/asn1-parser.js +79 -0
- package/dist/utils/signer/crypto.d.ts +5 -0
- package/dist/utils/signer/crypto.js +33 -0
- package/dist/utils/signer/index.d.ts +5 -0
- package/dist/utils/signer/index.js +21 -0
- package/dist/utils/signer/kms-ethers-signer.d.ts +19 -0
- package/dist/utils/signer/kms-ethers-signer.js +32 -0
- package/dist/utils/signer/kms-signer.d.ts +13 -0
- package/dist/utils/signer/kms-signer.js +46 -0
- package/dist/utils/signer/signature.d.ts +16 -0
- package/dist/utils/signer/signature.js +65 -0
- package/dist/utils/signer/signer.d.ts +6 -0
- package/dist/utils/signer/signer.js +2 -0
- package/dist/utils/signer/socketSigner.d.ts +39 -0
- package/dist/utils/signer/socketSigner.js +153 -0
- package/dist/utils/time.d.ts +2 -0
- package/dist/utils/time.js +7 -0
- package/package.json +4 -4
|
@@ -0,0 +1,54 @@
|
|
|
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 __1 = require("..");
|
|
9
|
+
const axiosGet = async (url, config = {}, errorLogging = false) => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
11
|
+
if (!url)
|
|
12
|
+
throw (0, __1.InternalServerError)("GET request url not provided");
|
|
13
|
+
try {
|
|
14
|
+
const response = await axios_1.default.get(url, config);
|
|
15
|
+
return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (errorLogging) {
|
|
19
|
+
console.log("status : ", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status);
|
|
20
|
+
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);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
status: (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.status,
|
|
25
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
26
|
+
...(_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.axiosGet = axiosGet;
|
|
31
|
+
const axiosPost = async (url, data, config = {}, errorLogging = false) => {
|
|
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");
|
|
37
|
+
try {
|
|
38
|
+
const response = await axios_1.default.post(url, data, config);
|
|
39
|
+
return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (errorLogging) {
|
|
43
|
+
console.log("status : ", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status);
|
|
44
|
+
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);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
49
|
+
status: (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.status,
|
|
50
|
+
...(_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.axiosPost = axiosPost;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_PAYLOAD_SIZE = void 0;
|
|
4
|
+
exports.chunks = chunks;
|
|
5
|
+
exports.MAX_PAYLOAD_SIZE = 10 * 1024; // max is 24.5 kb, left some buffer for function and batch encoding
|
|
6
|
+
function* chunks(arr, n) {
|
|
7
|
+
for (let i = 0; i < arr.length; i += n) {
|
|
8
|
+
yield arr.slice(i, i + n);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendToDiscordWebhook = exports.initDiscord = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const axios_1 = require("./axios");
|
|
6
|
+
let discordWebhookUrl;
|
|
7
|
+
let discordDebugWebhookUrl;
|
|
8
|
+
let serviceName;
|
|
9
|
+
const initDiscord = (webhookUrl_, serviceName_, discordDebugWebhookUrl_ = undefined) => {
|
|
10
|
+
discordWebhookUrl = webhookUrl_;
|
|
11
|
+
discordDebugWebhookUrl = discordDebugWebhookUrl_;
|
|
12
|
+
serviceName = serviceName_;
|
|
13
|
+
};
|
|
14
|
+
exports.initDiscord = initDiscord;
|
|
15
|
+
const sendToDiscordWebhook = async (title, data, optionalConfig = {}, isDebug = false) => {
|
|
16
|
+
try {
|
|
17
|
+
if (!discordWebhookUrl) {
|
|
18
|
+
throw (0, __1.InternalServerError)("DISCORD_WEBHOOK_URL not provided");
|
|
19
|
+
}
|
|
20
|
+
if (isDebug && !discordDebugWebhookUrl) {
|
|
21
|
+
console.log("Debug mode enabled but no debug webhook provided");
|
|
22
|
+
}
|
|
23
|
+
let content = formatMsg(title, data);
|
|
24
|
+
const urlToUse = isDebug && discordDebugWebhookUrl
|
|
25
|
+
? discordDebugWebhookUrl
|
|
26
|
+
: discordWebhookUrl;
|
|
27
|
+
await (0, axios_1.axiosPost)(urlToUse, { content, ...optionalConfig });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.sendToDiscordWebhook = sendToDiscordWebhook;
|
|
34
|
+
const formatMsg = (title, data) => {
|
|
35
|
+
let message = `**${title}**\n`;
|
|
36
|
+
// Iterate through the object's key-value pairs
|
|
37
|
+
for (const key in data) {
|
|
38
|
+
if (data.hasOwnProperty(key)) {
|
|
39
|
+
message += `${key}: ${data[key]}\n`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return message;
|
|
43
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAwsKmsSigner = void 0;
|
|
4
|
+
const kms_ethers_signer_1 = require("./signer/kms-ethers-signer");
|
|
5
|
+
const getAwsKmsSigner = async (keyId, region = "us-east-1") => {
|
|
6
|
+
try {
|
|
7
|
+
const kmsCredentials = {
|
|
8
|
+
kmsClientConfig: {
|
|
9
|
+
signingRegion: region,
|
|
10
|
+
region,
|
|
11
|
+
},
|
|
12
|
+
keyId,
|
|
13
|
+
};
|
|
14
|
+
let signer = new kms_ethers_signer_1.KmsEthersSigner(kmsCredentials);
|
|
15
|
+
let signerAddress = await signer.getAddress();
|
|
16
|
+
// logger.info(` keyid ${keyId} ${signerAddress}`);
|
|
17
|
+
if (!signerAddress) {
|
|
18
|
+
throw new Error(`Invalid kms signer, keyId:${keyId}`);
|
|
19
|
+
}
|
|
20
|
+
return signer;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
19
|
+
export declare const removeFields: (obj: any, fieldsToRemove: string[]) => any;
|
|
20
|
+
export declare const filterFields: (obj: any, fieldsAllowed: string[]) => any;
|
|
21
|
+
/**
|
|
22
|
+
* util function to return body response.
|
|
23
|
+
* params: statusCode, message, data.
|
|
24
|
+
// */
|
|
25
|
+
export declare const responseBody: (statusCode?: number, message?: null | string, data?: any, success?: boolean, error_code?: number | null) => {
|
|
26
|
+
statusCode: number;
|
|
27
|
+
headers: {
|
|
28
|
+
"Access-Control-Allow-Origin": string;
|
|
29
|
+
"Access-Control-Allow-Credentials": boolean;
|
|
30
|
+
};
|
|
31
|
+
body: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
5
|
+
/**
|
|
6
|
+
* defining functions.
|
|
7
|
+
*/
|
|
8
|
+
const isEmpty = (data) => {
|
|
9
|
+
if (data === undefined || data === null) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}; // end of isEmpty.
|
|
16
|
+
exports.isEmpty = isEmpty;
|
|
17
|
+
const checkMissingFields = (fields) => {
|
|
18
|
+
for (const field in fields) {
|
|
19
|
+
let value = fields[field];
|
|
20
|
+
if (!value) {
|
|
21
|
+
throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
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;
|
|
34
|
+
const checkMissingFieldsAndType = (fields, types = {}) => {
|
|
35
|
+
for (const field in fields) {
|
|
36
|
+
if ((0, exports.isEmpty)(fields[field])) {
|
|
37
|
+
throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
|
|
38
|
+
}
|
|
39
|
+
if (types[field] && typeof fields[field] !== types[field]) {
|
|
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]}"`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.checkObjectFieldsAndType = checkObjectFieldsAndType;
|
|
60
|
+
const removeFields = (obj, fieldsToRemove) => {
|
|
61
|
+
for (const field in obj) {
|
|
62
|
+
if (fieldsToRemove.includes(field)) {
|
|
63
|
+
delete obj[field];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return obj;
|
|
67
|
+
};
|
|
68
|
+
exports.removeFields = removeFields;
|
|
69
|
+
const filterFields = (obj, fieldsAllowed) => {
|
|
70
|
+
const finalObj = {};
|
|
71
|
+
for (const field in obj) {
|
|
72
|
+
if (fieldsAllowed.includes(field)) {
|
|
73
|
+
finalObj[field] = obj[field];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return finalObj;
|
|
77
|
+
};
|
|
78
|
+
exports.filterFields = filterFields;
|
|
79
|
+
/**
|
|
80
|
+
* util function to return body response.
|
|
81
|
+
* params: statusCode, message, data.
|
|
82
|
+
// */
|
|
83
|
+
const responseBody = (statusCode = 400, message = null, data = null, success = true, error_code = null) => {
|
|
84
|
+
// If no proper message present, or error code is not 1 => system generated error, return standard error message.
|
|
85
|
+
if (statusCode == 400 && (!message || error_code !== 1)) {
|
|
86
|
+
message = "BAD_REQUEST";
|
|
87
|
+
}
|
|
88
|
+
error_code = null;
|
|
89
|
+
return {
|
|
90
|
+
statusCode,
|
|
91
|
+
headers: {
|
|
92
|
+
"Access-Control-Allow-Origin": "*",
|
|
93
|
+
"Access-Control-Allow-Credentials": true,
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify({
|
|
96
|
+
success,
|
|
97
|
+
error_code,
|
|
98
|
+
message,
|
|
99
|
+
data,
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
}; // end responseBody function.
|
|
103
|
+
exports.responseBody = responseBody;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PacketDetails {
|
|
2
|
+
chainSlug: number;
|
|
3
|
+
capacitorAddr: string;
|
|
4
|
+
packetCount: 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, packetCount: string) => string;
|
|
14
|
+
export declare function encodePacketId(chainSlug: number, capacitorAddress: string, packetCount: number): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
|
|
4
|
+
exports.encodePacketId = encodePacketId;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const address_1 = require("./address");
|
|
7
|
+
const utils_1 = require("ethers/lib/utils");
|
|
8
|
+
const unpackPacketId = (packetId) => {
|
|
9
|
+
// 2(0x) + 1-8(chain slug) + 40(address) + 16(nonce)
|
|
10
|
+
const slugLength = packetId.length - 58;
|
|
11
|
+
const chainSlug = parseInt(ethers_1.BigNumber.from(`0x${packetId.substring(2, 2 + slugLength)}`).toString());
|
|
12
|
+
const capacitorAddr = (0, address_1.toLowerCase)(`0x${packetId.substring(2 + slugLength, 40 + 2 + slugLength)}`);
|
|
13
|
+
const packetCount = ethers_1.BigNumber.from(`0x${packetId.substring(40 + 2 + slugLength)}`).toString();
|
|
14
|
+
return {
|
|
15
|
+
chainSlug,
|
|
16
|
+
capacitorAddr,
|
|
17
|
+
packetCount,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.unpackPacketId = unpackPacketId;
|
|
21
|
+
const unpackMessageId = (messageId) => {
|
|
22
|
+
// 2(0x) + 1-8(chain slug) + 40(address) + 16(nonce)
|
|
23
|
+
const slugLength = messageId.length - 58;
|
|
24
|
+
const chainSlug = parseInt(ethers_1.BigNumber.from(`0x${messageId.substring(2, 2 + slugLength)}`).toString());
|
|
25
|
+
const siblingPlug = (0, address_1.toLowerCase)(`0x${messageId.substring(2 + slugLength, 40 + 2 + slugLength)}`);
|
|
26
|
+
const globalMessageCount = ethers_1.BigNumber.from(`0x${messageId.substring(40 + 2 + slugLength)}`).toString();
|
|
27
|
+
return {
|
|
28
|
+
chainSlug,
|
|
29
|
+
siblingPlug,
|
|
30
|
+
globalMessageCount,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.unpackMessageId = unpackMessageId;
|
|
34
|
+
const packPacketId = (chainSlug, capacitorAddr, packetCount) => {
|
|
35
|
+
const nonce = ethers_1.BigNumber.from(packetCount).toHexString();
|
|
36
|
+
const nonceHex = nonce.length <= 16 ? (0, utils_1.hexZeroPad)(nonce, 8).substring(2) : nonce.substring(2);
|
|
37
|
+
const slug = ethers_1.BigNumber.from(chainSlug).toHexString();
|
|
38
|
+
const slugHex = slug.length <= 10 ? (0, utils_1.hexZeroPad)(slug, 4) : slug;
|
|
39
|
+
const id = slugHex + capacitorAddr.substring(2) + nonceHex;
|
|
40
|
+
return id.toLowerCase();
|
|
41
|
+
};
|
|
42
|
+
exports.packPacketId = packPacketId;
|
|
43
|
+
function encodePacketId(chainSlug, capacitorAddress, packetCount) {
|
|
44
|
+
const encodedValue = (BigInt(chainSlug) << BigInt(224)) |
|
|
45
|
+
(BigInt(capacitorAddress) << BigInt(64)) |
|
|
46
|
+
BigInt(packetCount);
|
|
47
|
+
// Ensure the result is a 32-byte hex string (bytes32 in Solidity)
|
|
48
|
+
const resultHex = encodedValue.toString(16).padStart(64, "0");
|
|
49
|
+
return "0x" + resultHex;
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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";
|
|
8
|
+
export * from "./time";
|
|
9
|
+
export * from "./signer";
|
|
10
|
+
export * from "./ethersAwsKmsSigner";
|
|
11
|
+
export * from "./secretManagerService";
|
|
12
|
+
export * from "./eventGetter";
|
|
13
|
+
export * from "./s3Service";
|
|
@@ -0,0 +1,29 @@
|
|
|
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("./axios"), exports);
|
|
18
|
+
__exportStar(require("./discord"), exports);
|
|
19
|
+
__exportStar(require("./relaySigner"), exports);
|
|
20
|
+
__exportStar(require("./idUtils"), exports);
|
|
21
|
+
__exportStar(require("./address"), exports);
|
|
22
|
+
__exportStar(require("./dataStructHelper"), exports);
|
|
23
|
+
__exportStar(require("./extraUtils"), exports);
|
|
24
|
+
__exportStar(require("./time"), exports);
|
|
25
|
+
__exportStar(require("./signer"), exports);
|
|
26
|
+
__exportStar(require("./ethersAwsKmsSigner"), exports);
|
|
27
|
+
__exportStar(require("./secretManagerService"), exports);
|
|
28
|
+
__exportStar(require("./eventGetter"), exports);
|
|
29
|
+
__exportStar(require("./s3Service"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
|
|
2
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { Bytes } from "@ethersproject/bytes";
|
|
4
|
+
import { Deferrable } from "@ethersproject/properties";
|
|
5
|
+
export declare class SocketRelaySigner extends Signer {
|
|
6
|
+
readonly provider: Provider;
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly relayUrl: string;
|
|
9
|
+
readonly relayerAPIKey: string;
|
|
10
|
+
readonly sequential: boolean;
|
|
11
|
+
readonly isCritical: boolean;
|
|
12
|
+
readonly metadata: object;
|
|
13
|
+
constructor(provider: Provider, chainId: number, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object);
|
|
14
|
+
getAddress(): Promise<string>;
|
|
15
|
+
signMessage(message: string | Bytes): Promise<string>;
|
|
16
|
+
connect(provider: Provider): SocketRelaySigner;
|
|
17
|
+
setCritical(isCritical: boolean): SocketRelaySigner;
|
|
18
|
+
addMetadata(metadata: object): SocketRelaySigner;
|
|
19
|
+
signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
20
|
+
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SocketRelaySigner = void 0;
|
|
4
|
+
const abstract_signer_1 = require("@ethersproject/abstract-signer");
|
|
5
|
+
const axios_1 = require("./axios");
|
|
6
|
+
class SocketRelaySigner extends abstract_signer_1.Signer {
|
|
7
|
+
constructor(provider, chainId, relayUrl, relayerAPIKey, sequential = false,
|
|
8
|
+
// if isCritical is set to true, will try multiple relayers
|
|
9
|
+
// to get the transaction included
|
|
10
|
+
isCritical = false, metadata = {}) {
|
|
11
|
+
super();
|
|
12
|
+
this.provider = provider;
|
|
13
|
+
this.chainId = chainId;
|
|
14
|
+
this.relayUrl = relayUrl;
|
|
15
|
+
this.relayerAPIKey = relayerAPIKey;
|
|
16
|
+
this.sequential = sequential;
|
|
17
|
+
this.isCritical = isCritical;
|
|
18
|
+
this.metadata = metadata;
|
|
19
|
+
}
|
|
20
|
+
async getAddress() {
|
|
21
|
+
// some random address
|
|
22
|
+
return "0x5367Efc17020Aa1CF0943bA7eD17f1D3e4c7d7EE";
|
|
23
|
+
}
|
|
24
|
+
async signMessage(message) {
|
|
25
|
+
throw new Error(" signMessage not Implemented");
|
|
26
|
+
}
|
|
27
|
+
connect(provider) {
|
|
28
|
+
return new SocketRelaySigner(provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
|
|
29
|
+
}
|
|
30
|
+
setCritical(isCritical) {
|
|
31
|
+
return new SocketRelaySigner(this.provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
|
|
32
|
+
}
|
|
33
|
+
addMetadata(metadata) {
|
|
34
|
+
return new SocketRelaySigner(this.provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
|
|
35
|
+
}
|
|
36
|
+
async signTransaction(transaction) {
|
|
37
|
+
throw new Error(" signTransaction not Implemented");
|
|
38
|
+
}
|
|
39
|
+
async sendTransaction(transaction) {
|
|
40
|
+
try {
|
|
41
|
+
if (!this.relayerAPIKey)
|
|
42
|
+
throw new Error("relayerAPIKey not provided");
|
|
43
|
+
if (!this.relayUrl)
|
|
44
|
+
throw new Error("relayUrl not provided");
|
|
45
|
+
let payload = {
|
|
46
|
+
chainId: this.chainId,
|
|
47
|
+
sequential: this.sequential,
|
|
48
|
+
isCritical: this.isCritical,
|
|
49
|
+
metadata: this.metadata,
|
|
50
|
+
...transaction,
|
|
51
|
+
};
|
|
52
|
+
const config = {
|
|
53
|
+
headers: {
|
|
54
|
+
"x-api-key": this.relayerAPIKey,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
let result = await (0, axios_1.axiosPost)(this.relayUrl, payload, config);
|
|
58
|
+
if (!result.success)
|
|
59
|
+
throw result;
|
|
60
|
+
let tx = result === null || result === void 0 ? void 0 : result.data;
|
|
61
|
+
return this.provider._wrapTransaction(tx);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.SocketRelaySigner = SocketRelaySigner;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DeploymentMode } from "@socket.tech/dl-core";
|
|
2
|
+
import { Accounts } from "..";
|
|
3
|
+
export declare const initS3Client: (region: string) => void;
|
|
4
|
+
export declare const getFileFromS3: (bucket: string, filePath: string) => Promise<any>;
|
|
5
|
+
export declare const uploadFileToS3: (bucket: string, filePath: string, jsonData: object) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
6
|
+
export declare const getBucketAndFileName: (deploymentMode: DeploymentMode, account?: Accounts.dl | Accounts.ll) => {
|
|
7
|
+
S3_BUCKET_NAME: string;
|
|
8
|
+
S3_RPC_CONFIG_FILE_PATH: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const getS3Config: (deploymentMode: DeploymentMode, region?: string, account?: Accounts.dl | Accounts.ll) => Promise<any>;
|
|
11
|
+
export declare const setS3Config: (jsonData: object, deploymentMode: DeploymentMode, region?: string, account?: Accounts.dl | Accounts.ll) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setS3Config = exports.getS3Config = exports.getBucketAndFileName = exports.uploadFileToS3 = exports.getFileFromS3 = exports.initS3Client = void 0;
|
|
4
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
+
const dl_core_1 = require("@socket.tech/dl-core");
|
|
6
|
+
const __1 = require("..");
|
|
7
|
+
// Set your AWS credentials and region
|
|
8
|
+
let s3Client;
|
|
9
|
+
const initS3Client = (region) => {
|
|
10
|
+
s3Client = new client_s3_1.S3Client({
|
|
11
|
+
region,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.initS3Client = initS3Client;
|
|
15
|
+
const getFileFromS3 = async (bucket, filePath) => {
|
|
16
|
+
var _a;
|
|
17
|
+
try {
|
|
18
|
+
const s3Response = await s3Client.send(new client_s3_1.GetObjectCommand({
|
|
19
|
+
Bucket: bucket,
|
|
20
|
+
Key: filePath,
|
|
21
|
+
}));
|
|
22
|
+
const jsonStr = await ((_a = s3Response.Body) === null || _a === void 0 ? void 0 : _a.transformToString());
|
|
23
|
+
let response;
|
|
24
|
+
if (jsonStr)
|
|
25
|
+
response = JSON.parse(jsonStr);
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error("Error downloading file from S3:", error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.getFileFromS3 = getFileFromS3;
|
|
34
|
+
const uploadFileToS3 = async (bucket, filePath, jsonData) => {
|
|
35
|
+
try {
|
|
36
|
+
const response = await s3Client.send(new client_s3_1.PutObjectCommand({
|
|
37
|
+
Bucket: bucket,
|
|
38
|
+
Key: filePath,
|
|
39
|
+
Body: JSON.stringify(jsonData),
|
|
40
|
+
ContentType: "application/json",
|
|
41
|
+
}));
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error("Error uploading file to S3:", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.uploadFileToS3 = uploadFileToS3;
|
|
50
|
+
const getBucketAndFileName = (deploymentMode, account = __1.Accounts.dl) => {
|
|
51
|
+
const S3_BUCKET_NAME = deploymentMode === dl_core_1.DeploymentMode.SURGE ||
|
|
52
|
+
deploymentMode == dl_core_1.DeploymentMode.PROD
|
|
53
|
+
? `socket-${account}-${deploymentMode}`
|
|
54
|
+
: `socket-ll-${deploymentMode}`;
|
|
55
|
+
const S3_RPC_CONFIG_FILE_PATH = deploymentMode + "RpcConfig.json";
|
|
56
|
+
return { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH };
|
|
57
|
+
};
|
|
58
|
+
exports.getBucketAndFileName = getBucketAndFileName;
|
|
59
|
+
const getS3Config = async (deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
|
|
60
|
+
const { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH } = (0, exports.getBucketAndFileName)(deploymentMode, account);
|
|
61
|
+
(0, exports.initS3Client)(region);
|
|
62
|
+
return await (0, exports.getFileFromS3)(S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH);
|
|
63
|
+
};
|
|
64
|
+
exports.getS3Config = getS3Config;
|
|
65
|
+
const setS3Config = async (jsonData, deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
|
|
66
|
+
const { S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH } = (0, exports.getBucketAndFileName)(deploymentMode, account);
|
|
67
|
+
(0, exports.initS3Client)(region);
|
|
68
|
+
return await (0, exports.uploadFileToS3)(S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH, jsonData);
|
|
69
|
+
};
|
|
70
|
+
exports.setS3Config = setS3Config;
|