@socket.tech/dl-common 1.0.3-test.3 → 1.0.3-test.31
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 +6 -1
- package/dist/constants/enums.js +5 -0
- package/dist/constants/types.d.ts +27 -1
- package/dist/constants/waitTime.d.ts +1 -0
- package/dist/constants/waitTime.js +15 -4
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/packet.d.ts +8 -0
- package/dist/models/packet.js +9 -0
- package/dist/models/{attestations.d.ts → switchboard.d.ts} +37 -37
- package/dist/models/switchboard.js +92 -0
- package/dist/services/eventBridgeService.d.ts +8 -0
- package/dist/services/eventBridgeService.js +39 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/utils/ethersAwsKmsSigner.d.ts +2 -2
- package/dist/utils/ethersAwsKmsSigner.js +6 -3
- package/dist/utils/extraUtils.d.ts +1 -0
- package/dist/utils/extraUtils.js +15 -7
- package/dist/utils/idUtils.d.ts +2 -2
- package/dist/utils/idUtils.js +4 -4
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/relaySigner.d.ts +2 -4
- package/dist/utils/relaySigner.js +7 -10
- package/dist/utils/s3Service.d.ts +4 -0
- package/dist/utils/s3Service.js +41 -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 +10 -0
- package/dist/utils/signer/address.js +42 -0
- package/dist/utils/signer/asn1-parser.d.ts +11 -0
- package/dist/utils/signer/asn1-parser.js +80 -0
- package/dist/utils/signer/crypto.d.ts +6 -0
- package/dist/utils/signer/crypto.js +34 -0
- package/dist/utils/signer/index.d.ts +4 -0
- package/dist/{types → utils/signer}/index.js +4 -2
- 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 +14 -0
- package/dist/utils/signer/kms-signer.js +46 -0
- package/dist/utils/signer/signature.d.ts +17 -0
- package/dist/utils/signer/signature.js +65 -0
- package/dist/utils/signer/signer.d.ts +7 -0
- package/dist/utils/signer/signer.js +2 -0
- package/package.json +32 -8
- package/dist/models/attestations.js +0 -59
- package/dist/types/codes.d.ts +0 -22
- package/dist/types/codes.js +0 -28
- package/dist/types/index.d.ts +0 -2
- package/dist/types/types.d.ts +0 -86
- package/dist/types/types.js +0 -41
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Confirmations = exports.getConfirmations = void 0;
|
|
4
|
+
const dl_core_1 = require("@socket.tech/dl-core");
|
|
5
|
+
const getConfirmations = (chainSlug) => {
|
|
6
|
+
if (dl_core_1.TestnetIds.includes(chainSlug)) {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
return exports.Confirmations[chainSlug];
|
|
10
|
+
};
|
|
11
|
+
exports.getConfirmations = getConfirmations;
|
|
12
|
+
exports.Confirmations = {
|
|
13
|
+
[dl_core_1.ChainSlug.MAINNET]: 12,
|
|
14
|
+
[dl_core_1.ChainSlug.ARBITRUM]: 1,
|
|
15
|
+
[dl_core_1.ChainSlug.OPTIMISM]: 18,
|
|
16
|
+
[dl_core_1.ChainSlug.AEVO]: 18,
|
|
17
|
+
};
|
|
@@ -15,7 +15,11 @@ export declare enum MessageStatuses {
|
|
|
15
15
|
PROPOSED = "PROPOSED",
|
|
16
16
|
CONFIRMED = "CONFIRMED",
|
|
17
17
|
EXECUTION_SUCCESS = "EXECUTION_SUCCESS",
|
|
18
|
-
EXECUTION_FAILURE = "EXECUTION_FAILURE"
|
|
18
|
+
EXECUTION_FAILURE = "EXECUTION_FAILURE",
|
|
19
|
+
VERIFIED = "VERIFIED",
|
|
20
|
+
ATTESTED = "ATTESTED",
|
|
21
|
+
EXECUTING = "EXECUTING",
|
|
22
|
+
INBOUND_REVERTING = "INBOUND_REVERTING"
|
|
19
23
|
}
|
|
20
24
|
export declare enum MessageStatusStep {
|
|
21
25
|
RECEIVED = 0,
|
|
@@ -29,5 +33,6 @@ export declare enum StatusCodes {
|
|
|
29
33
|
SUCCESS = "SUCCESS",
|
|
30
34
|
NOT_FOUND = "NOT_FOUND",
|
|
31
35
|
BAD_REQUEST = "BAD_REQUEST",
|
|
36
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
32
37
|
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
|
|
33
38
|
}
|
package/dist/constants/enums.js
CHANGED
|
@@ -21,6 +21,10 @@ var MessageStatuses;
|
|
|
21
21
|
MessageStatuses["CONFIRMED"] = "CONFIRMED";
|
|
22
22
|
MessageStatuses["EXECUTION_SUCCESS"] = "EXECUTION_SUCCESS";
|
|
23
23
|
MessageStatuses["EXECUTION_FAILURE"] = "EXECUTION_FAILURE";
|
|
24
|
+
MessageStatuses["VERIFIED"] = "VERIFIED";
|
|
25
|
+
MessageStatuses["ATTESTED"] = "ATTESTED";
|
|
26
|
+
MessageStatuses["EXECUTING"] = "EXECUTING";
|
|
27
|
+
MessageStatuses["INBOUND_REVERTING"] = "INBOUND_REVERTING";
|
|
24
28
|
})(MessageStatuses || (exports.MessageStatuses = MessageStatuses = {}));
|
|
25
29
|
var MessageStatusStep;
|
|
26
30
|
(function (MessageStatusStep) {
|
|
@@ -36,5 +40,6 @@ var StatusCodes;
|
|
|
36
40
|
StatusCodes["SUCCESS"] = "SUCCESS";
|
|
37
41
|
StatusCodes["NOT_FOUND"] = "NOT_FOUND";
|
|
38
42
|
StatusCodes["BAD_REQUEST"] = "BAD_REQUEST";
|
|
43
|
+
StatusCodes["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
39
44
|
StatusCodes["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
40
45
|
})(StatusCodes || (exports.StatusCodes = StatusCodes = {}));
|
|
@@ -37,6 +37,7 @@ export type SealParams = {
|
|
|
37
37
|
srcChainSlug: number;
|
|
38
38
|
dstChainSlug: number;
|
|
39
39
|
dstSwitchboard: string;
|
|
40
|
+
srcSwitchboard: string;
|
|
40
41
|
integrationType: IntegrationTypes;
|
|
41
42
|
message: {
|
|
42
43
|
messageId: string;
|
|
@@ -84,7 +85,7 @@ export interface ExecuteSigResponse {
|
|
|
84
85
|
}
|
|
85
86
|
export interface AttestRequest {
|
|
86
87
|
switchboardAddress: string;
|
|
87
|
-
dstChainSlug:
|
|
88
|
+
dstChainSlug: number;
|
|
88
89
|
packetId: string;
|
|
89
90
|
root: string;
|
|
90
91
|
proposalCount: number;
|
|
@@ -94,6 +95,8 @@ export interface AttestSuccess {
|
|
|
94
95
|
packetId: string;
|
|
95
96
|
proposalCount: number;
|
|
96
97
|
signature: string;
|
|
98
|
+
digest: string;
|
|
99
|
+
signerAddress: string;
|
|
97
100
|
}
|
|
98
101
|
export interface AttestFailure {
|
|
99
102
|
proposalValid: false;
|
|
@@ -102,3 +105,26 @@ export interface AttestFailure {
|
|
|
102
105
|
reason: TripReason;
|
|
103
106
|
}
|
|
104
107
|
export type AttestResponse = AttestSuccess | AttestFailure;
|
|
108
|
+
export type MessageData = {
|
|
109
|
+
messageId: string;
|
|
110
|
+
destPlug: string;
|
|
111
|
+
srcPlug: string;
|
|
112
|
+
dstChainSlug: number;
|
|
113
|
+
srcChainSlug: number;
|
|
114
|
+
payload: string;
|
|
115
|
+
minMsgGasLimit: string;
|
|
116
|
+
executionParams: string;
|
|
117
|
+
packedMessage: string;
|
|
118
|
+
};
|
|
119
|
+
export type S3Config = {
|
|
120
|
+
chains: {
|
|
121
|
+
[chainSlug in ChainSlug]?: {
|
|
122
|
+
rpc: string;
|
|
123
|
+
blockNumber: number;
|
|
124
|
+
confirmations: number;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
batcherSupportedChainSlugs: ChainSlug[];
|
|
128
|
+
watcherSupportedChainSlugs: ChainSlug[];
|
|
129
|
+
transmitterSupportedChainSlugs: ChainSlug[];
|
|
130
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChainSlug, IntegrationTypes } from "@socket.tech/dl-core";
|
|
2
2
|
export declare const getWaitTime: (integrationType: IntegrationTypes, srcChainSlug: ChainSlug, dstChainSlug: ChainSlug) => number;
|
|
3
|
+
export declare const getNativeWaitTime: (srcChainSlug: ChainSlug, dstChainSlug: ChainSlug) => number;
|
|
3
4
|
export declare const NativeWaitTime: {
|
|
4
5
|
[srcChain in ChainSlug]?: {
|
|
5
6
|
[dstChain in ChainSlug]?: number;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NativeWaitTime = exports.getWaitTime = void 0;
|
|
3
|
+
exports.NativeWaitTime = exports.getNativeWaitTime = exports.getWaitTime = void 0;
|
|
4
4
|
const dl_core_1 = require("@socket.tech/dl-core");
|
|
5
5
|
const getWaitTime = (integrationType, srcChainSlug, dstChainSlug) => {
|
|
6
|
-
var _a, _b;
|
|
7
6
|
switch (integrationType) {
|
|
8
7
|
case dl_core_1.IntegrationTypes.fast:
|
|
9
8
|
return 0;
|
|
@@ -12,13 +11,24 @@ const getWaitTime = (integrationType, srcChainSlug, dstChainSlug) => {
|
|
|
12
11
|
case dl_core_1.IntegrationTypes.optimistic:
|
|
13
12
|
return 2 * 3600;
|
|
14
13
|
case dl_core_1.IntegrationTypes.native:
|
|
15
|
-
return (
|
|
14
|
+
return (0, exports.getNativeWaitTime)(srcChainSlug, dstChainSlug);
|
|
16
15
|
default:
|
|
17
16
|
return 0;
|
|
18
|
-
break;
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
exports.getWaitTime = getWaitTime;
|
|
20
|
+
const getNativeWaitTime = (srcChainSlug, dstChainSlug) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
let defaultWaitTime;
|
|
23
|
+
if (dl_core_1.TestnetIds.includes(srcChainSlug))
|
|
24
|
+
defaultWaitTime = 5 * 60;
|
|
25
|
+
else if (srcChainSlug === dl_core_1.ChainSlug.MAINNET)
|
|
26
|
+
defaultWaitTime = 10 * 60;
|
|
27
|
+
else
|
|
28
|
+
defaultWaitTime = 2 * 3600;
|
|
29
|
+
return (_b = (_a = exports.NativeWaitTime[srcChainSlug]) === null || _a === void 0 ? void 0 : _a[dstChainSlug]) !== null && _b !== void 0 ? _b : defaultWaitTime;
|
|
30
|
+
};
|
|
31
|
+
exports.getNativeWaitTime = getNativeWaitTime;
|
|
22
32
|
exports.NativeWaitTime = {
|
|
23
33
|
[dl_core_1.ChainSlug.OPTIMISM_GOERLI]: {
|
|
24
34
|
[dl_core_1.ChainSlug.GOERLI]: 5 * 60,
|
|
@@ -47,5 +57,6 @@ exports.NativeWaitTime = {
|
|
|
47
57
|
[dl_core_1.ChainSlug.ARBITRUM]: 10 * 60,
|
|
48
58
|
[dl_core_1.ChainSlug.OPTIMISM]: 10 * 60,
|
|
49
59
|
[dl_core_1.ChainSlug.POLYGON_MAINNET]: 10 * 60,
|
|
60
|
+
[dl_core_1.ChainSlug.LYRA]: 10 * 60,
|
|
50
61
|
},
|
|
51
62
|
};
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/index.js
CHANGED
package/dist/models/packet.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare enum TripReason {
|
|
|
34
34
|
}
|
|
35
35
|
export declare class Packet extends Model {
|
|
36
36
|
id: number;
|
|
37
|
+
switchboardId: string;
|
|
37
38
|
packetId: string;
|
|
38
39
|
srcChainSlug: number;
|
|
39
40
|
dstChainSlug: number;
|
|
@@ -63,6 +64,7 @@ export declare class Packet extends Model {
|
|
|
63
64
|
attestRelayStatus: AttestRelayStatus;
|
|
64
65
|
outboundTxHash: string;
|
|
65
66
|
outboundTime: number;
|
|
67
|
+
sealIndexTime: number;
|
|
66
68
|
proposeTime: number;
|
|
67
69
|
attestTime: number;
|
|
68
70
|
packetTripTxHash: string;
|
|
@@ -92,6 +94,9 @@ export declare const PacketModel: {
|
|
|
92
94
|
dstSwitchboard: {
|
|
93
95
|
type: DataTypes.StringDataTypeConstructor;
|
|
94
96
|
};
|
|
97
|
+
switchboardId: {
|
|
98
|
+
type: DataTypes.StringDataTypeConstructor;
|
|
99
|
+
};
|
|
95
100
|
integrationType: {
|
|
96
101
|
type: DataTypes.EnumDataTypeConstructor;
|
|
97
102
|
values: IntegrationTypes[];
|
|
@@ -165,6 +170,9 @@ export declare const PacketModel: {
|
|
|
165
170
|
sealTime: {
|
|
166
171
|
type: DataTypes.IntegerDataTypeConstructor;
|
|
167
172
|
};
|
|
173
|
+
sealIndexTime: {
|
|
174
|
+
type: DataTypes.IntegerDataTypeConstructor;
|
|
175
|
+
};
|
|
168
176
|
sealSignature: {
|
|
169
177
|
type: DataTypes.StringDataTypeConstructor;
|
|
170
178
|
};
|
package/dist/models/packet.js
CHANGED
|
@@ -61,6 +61,9 @@ exports.PacketModel = {
|
|
|
61
61
|
dstSwitchboard: {
|
|
62
62
|
type: sequelize_1.DataTypes.STRING,
|
|
63
63
|
},
|
|
64
|
+
switchboardId: {
|
|
65
|
+
type: sequelize_1.DataTypes.STRING,
|
|
66
|
+
},
|
|
64
67
|
integrationType: {
|
|
65
68
|
type: sequelize_1.DataTypes.ENUM,
|
|
66
69
|
values: [...Object.values(dl_core_1.IntegrationTypes)],
|
|
@@ -134,6 +137,9 @@ exports.PacketModel = {
|
|
|
134
137
|
sealTime: {
|
|
135
138
|
type: sequelize_1.DataTypes.INTEGER,
|
|
136
139
|
},
|
|
140
|
+
sealIndexTime: {
|
|
141
|
+
type: sequelize_1.DataTypes.INTEGER,
|
|
142
|
+
},
|
|
137
143
|
sealSignature: {
|
|
138
144
|
type: sequelize_1.DataTypes.STRING,
|
|
139
145
|
},
|
|
@@ -223,6 +229,9 @@ function processStrings(packet) {
|
|
|
223
229
|
if (packet.dstSwitchboard) {
|
|
224
230
|
packet.dstSwitchboard = (0, utils_1.toLowerCase)(packet.dstSwitchboard);
|
|
225
231
|
}
|
|
232
|
+
if (packet.switchboardId) {
|
|
233
|
+
packet.switchboardId = (0, utils_1.toLowerCase)(packet.switchboardId);
|
|
234
|
+
}
|
|
226
235
|
if (packet.packetTripTxHash) {
|
|
227
236
|
packet.packetTripTxHash = (0, utils_1.toLowerCase)(packet.packetTripTxHash);
|
|
228
237
|
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
import { IntegrationTypes } from "@socket.tech/dl-core";
|
|
2
2
|
import { DataTypes, Model } from "sequelize";
|
|
3
|
-
export declare
|
|
3
|
+
export declare enum CapacitorType {
|
|
4
|
+
singleCapacitor = "1",
|
|
5
|
+
hashChainCapacitor = "2"
|
|
6
|
+
}
|
|
7
|
+
export declare class Switchboard extends Model {
|
|
4
8
|
id: number;
|
|
5
|
-
|
|
6
|
-
proposalCount: number;
|
|
7
|
-
root: string;
|
|
8
|
-
switchboard: string;
|
|
9
|
-
integrationType: IntegrationTypes;
|
|
9
|
+
switchboardId: string;
|
|
10
10
|
srcChainSlug: number;
|
|
11
11
|
dstChainSlug: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
maxPacketLength: number;
|
|
13
|
+
srcSwitchboard: string;
|
|
14
|
+
dstSwitchboard: string;
|
|
15
|
+
srcCapacitor: string;
|
|
16
|
+
srcDecapacitor: string;
|
|
17
|
+
capacitorType: CapacitorType;
|
|
18
|
+
isEnabled: boolean;
|
|
19
|
+
integrationType: IntegrationTypes;
|
|
17
20
|
}
|
|
18
|
-
export declare const
|
|
21
|
+
export declare const SwitchboardModel: {
|
|
19
22
|
id: {
|
|
20
23
|
type: DataTypes.IntegerDataTypeConstructor;
|
|
21
24
|
autoIncrement: boolean;
|
|
22
25
|
primaryKey: boolean;
|
|
23
26
|
};
|
|
24
|
-
|
|
25
|
-
type: DataTypes.StringDataTypeConstructor;
|
|
26
|
-
unique: string;
|
|
27
|
-
};
|
|
28
|
-
proposalCount: {
|
|
29
|
-
type: DataTypes.IntegerDataTypeConstructor;
|
|
30
|
-
unique: string;
|
|
31
|
-
};
|
|
32
|
-
switchboard: {
|
|
27
|
+
switchboardId: {
|
|
33
28
|
type: DataTypes.StringDataTypeConstructor;
|
|
34
29
|
};
|
|
35
30
|
srcChainSlug: {
|
|
36
31
|
type: DataTypes.IntegerDataTypeConstructor;
|
|
32
|
+
unique: string;
|
|
37
33
|
};
|
|
38
34
|
dstChainSlug: {
|
|
39
35
|
type: DataTypes.IntegerDataTypeConstructor;
|
|
36
|
+
unique: string;
|
|
40
37
|
};
|
|
41
|
-
|
|
42
|
-
type: DataTypes.
|
|
38
|
+
maxPacketLength: {
|
|
39
|
+
type: DataTypes.IntegerDataTypeConstructor;
|
|
43
40
|
};
|
|
44
|
-
|
|
41
|
+
srcSwitchboard: {
|
|
45
42
|
type: DataTypes.StringDataTypeConstructor;
|
|
46
43
|
unique: string;
|
|
47
44
|
};
|
|
48
|
-
|
|
45
|
+
dstSwitchboard: {
|
|
49
46
|
type: DataTypes.StringDataTypeConstructor;
|
|
50
|
-
defaultValue: string;
|
|
51
|
-
unique: string;
|
|
52
47
|
};
|
|
53
|
-
|
|
48
|
+
srcCapacitor: {
|
|
54
49
|
type: DataTypes.StringDataTypeConstructor;
|
|
55
|
-
defaultValue: string;
|
|
56
50
|
};
|
|
57
|
-
|
|
51
|
+
srcDecapacitor: {
|
|
58
52
|
type: DataTypes.StringDataTypeConstructor;
|
|
59
|
-
defaultValue: string;
|
|
60
53
|
};
|
|
61
|
-
|
|
62
|
-
type: DataTypes.
|
|
63
|
-
|
|
54
|
+
capacitorType: {
|
|
55
|
+
type: DataTypes.EnumDataTypeConstructor;
|
|
56
|
+
values: CapacitorType[];
|
|
57
|
+
defaultValue: CapacitorType;
|
|
64
58
|
};
|
|
65
|
-
|
|
66
|
-
type: DataTypes.
|
|
67
|
-
defaultValue:
|
|
59
|
+
isEnabled: {
|
|
60
|
+
type: DataTypes.AbstractDataTypeConstructor;
|
|
61
|
+
defaultValue: boolean;
|
|
62
|
+
};
|
|
63
|
+
integrationType: {
|
|
64
|
+
type: DataTypes.EnumDataTypeConstructor;
|
|
65
|
+
values: IntegrationTypes[];
|
|
66
|
+
defaultValue: IntegrationTypes;
|
|
68
67
|
};
|
|
69
68
|
};
|
|
69
|
+
export declare const addSwitchboardHooks: () => Promise<void>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSwitchboardHooks = exports.SwitchboardModel = exports.Switchboard = exports.CapacitorType = void 0;
|
|
4
|
+
const dl_core_1 = require("@socket.tech/dl-core");
|
|
5
|
+
const sequelize_1 = require("sequelize");
|
|
6
|
+
const __1 = require("..");
|
|
7
|
+
var CapacitorType;
|
|
8
|
+
(function (CapacitorType) {
|
|
9
|
+
CapacitorType["singleCapacitor"] = "1";
|
|
10
|
+
CapacitorType["hashChainCapacitor"] = "2";
|
|
11
|
+
})(CapacitorType || (exports.CapacitorType = CapacitorType = {}));
|
|
12
|
+
class Switchboard extends sequelize_1.Model {
|
|
13
|
+
}
|
|
14
|
+
exports.Switchboard = Switchboard;
|
|
15
|
+
exports.SwitchboardModel = {
|
|
16
|
+
id: {
|
|
17
|
+
type: sequelize_1.DataTypes.INTEGER,
|
|
18
|
+
autoIncrement: true,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
},
|
|
21
|
+
switchboardId: {
|
|
22
|
+
type: sequelize_1.DataTypes.STRING,
|
|
23
|
+
},
|
|
24
|
+
srcChainSlug: {
|
|
25
|
+
type: sequelize_1.DataTypes.INTEGER,
|
|
26
|
+
unique: "uniqueSwitchboardPointer",
|
|
27
|
+
},
|
|
28
|
+
dstChainSlug: {
|
|
29
|
+
type: sequelize_1.DataTypes.INTEGER,
|
|
30
|
+
unique: "uniqueSwitchboardPointer",
|
|
31
|
+
},
|
|
32
|
+
maxPacketLength: {
|
|
33
|
+
type: sequelize_1.DataTypes.INTEGER,
|
|
34
|
+
},
|
|
35
|
+
srcSwitchboard: {
|
|
36
|
+
type: sequelize_1.DataTypes.STRING,
|
|
37
|
+
unique: "uniqueSwitchboardPointer",
|
|
38
|
+
},
|
|
39
|
+
dstSwitchboard: {
|
|
40
|
+
type: sequelize_1.DataTypes.STRING,
|
|
41
|
+
},
|
|
42
|
+
srcCapacitor: {
|
|
43
|
+
type: sequelize_1.DataTypes.STRING,
|
|
44
|
+
},
|
|
45
|
+
srcDecapacitor: {
|
|
46
|
+
type: sequelize_1.DataTypes.STRING,
|
|
47
|
+
},
|
|
48
|
+
capacitorType: {
|
|
49
|
+
type: sequelize_1.DataTypes.ENUM,
|
|
50
|
+
values: [...Object.values(CapacitorType)],
|
|
51
|
+
defaultValue: CapacitorType.singleCapacitor,
|
|
52
|
+
},
|
|
53
|
+
isEnabled: {
|
|
54
|
+
type: sequelize_1.DataTypes.BOOLEAN,
|
|
55
|
+
defaultValue: false,
|
|
56
|
+
},
|
|
57
|
+
integrationType: {
|
|
58
|
+
type: sequelize_1.DataTypes.ENUM,
|
|
59
|
+
values: [...Object.values(dl_core_1.IntegrationTypes)],
|
|
60
|
+
defaultValue: dl_core_1.IntegrationTypes.unknown,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const addSwitchboardHooks = async () => {
|
|
64
|
+
Switchboard.beforeBulkCreate((switchboards, options) => {
|
|
65
|
+
for (let index = 0; index < switchboards.length; index++) {
|
|
66
|
+
switchboards[index] = processStrings(switchboards[index]);
|
|
67
|
+
switchboards[index] = createSwitchboardId(switchboards[index]);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Switchboard.beforeSave((switchboard, options) => {
|
|
71
|
+
switchboard = processStrings(switchboard);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
exports.addSwitchboardHooks = addSwitchboardHooks;
|
|
75
|
+
function processStrings(switchboard) {
|
|
76
|
+
if (switchboard.srcSwitchboard)
|
|
77
|
+
switchboard.srcSwitchboard = (0, __1.toLowerCase)(switchboard.srcSwitchboard);
|
|
78
|
+
if (switchboard.dstSwitchboard)
|
|
79
|
+
switchboard.dstSwitchboard = (0, __1.toLowerCase)(switchboard.dstSwitchboard);
|
|
80
|
+
if (switchboard.srcCapacitor)
|
|
81
|
+
switchboard.srcCapacitor = (0, __1.toLowerCase)(switchboard.srcCapacitor);
|
|
82
|
+
if (switchboard.srcDecapacitor)
|
|
83
|
+
switchboard.srcDecapacitor = (0, __1.toLowerCase)(switchboard.srcDecapacitor);
|
|
84
|
+
return switchboard;
|
|
85
|
+
}
|
|
86
|
+
function createSwitchboardId(switchboard) {
|
|
87
|
+
if (switchboard.srcSwitchboard &&
|
|
88
|
+
switchboard.srcChainSlug &&
|
|
89
|
+
switchboard.dstChainSlug)
|
|
90
|
+
switchboard.switchboardId = `${switchboard.srcChainSlug}-${switchboard.dstChainSlug}-${switchboard.srcSwitchboard.toLowerCase()}`;
|
|
91
|
+
return switchboard;
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type EventBridgeEntry = {
|
|
2
|
+
eventBus: string;
|
|
3
|
+
source: string;
|
|
4
|
+
detailType: string;
|
|
5
|
+
data: Object;
|
|
6
|
+
};
|
|
7
|
+
export declare const initEventBridgeClient: (region?: string) => void;
|
|
8
|
+
export declare const sendEvents: (events: EventBridgeEntry[]) => Promise<import("@aws-sdk/client-eventbridge").PutEventsCommandOutput>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendEvents = exports.initEventBridgeClient = void 0;
|
|
4
|
+
const client_eventbridge_1 = require("@aws-sdk/client-eventbridge");
|
|
5
|
+
let client;
|
|
6
|
+
const initEventBridgeClient = (region = "us-east-1") => {
|
|
7
|
+
client = new client_eventbridge_1.EventBridgeClient({ region });
|
|
8
|
+
};
|
|
9
|
+
exports.initEventBridgeClient = initEventBridgeClient;
|
|
10
|
+
const sendEvents = async (events) => {
|
|
11
|
+
// async/await.
|
|
12
|
+
try {
|
|
13
|
+
if (!client) {
|
|
14
|
+
throw new Error("EventBridge client is not initialized. Call initEventBridgeClient first.");
|
|
15
|
+
}
|
|
16
|
+
let entries = events.map((event) => {
|
|
17
|
+
let { eventBus, source, detailType, data } = event;
|
|
18
|
+
return {
|
|
19
|
+
Source: source,
|
|
20
|
+
DetailType: detailType,
|
|
21
|
+
Detail: JSON.stringify(data),
|
|
22
|
+
EventBusName: eventBus,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const params = {
|
|
26
|
+
Entries: entries,
|
|
27
|
+
};
|
|
28
|
+
const command = new client_eventbridge_1.PutEventsCommand(params);
|
|
29
|
+
return await client.send(command);
|
|
30
|
+
// process data.
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
// finally.
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.sendEvents = sendEvents;
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./queueService"), exports);
|
|
18
18
|
__exportStar(require("./cacheService"), exports);
|
|
19
|
+
__exportStar(require("./eventBridgeService"), exports);
|
|
19
20
|
// export * from "./apiService";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getAwsKmsSigner: (keyId: string, region?: string) => Promise<
|
|
1
|
+
import { KmsEthersSigner } from "./signer/kms-ethers-signer";
|
|
2
|
+
export declare const getAwsKmsSigner: (keyId: string, region?: string) => Promise<KmsEthersSigner>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAwsKmsSigner = void 0;
|
|
4
|
-
const
|
|
4
|
+
const kms_ethers_signer_1 = require("./signer/kms-ethers-signer");
|
|
5
5
|
const getAwsKmsSigner = async (keyId, region = "us-east-1") => {
|
|
6
6
|
try {
|
|
7
7
|
const kmsCredentials = {
|
|
8
|
-
|
|
8
|
+
kmsClientConfig: {
|
|
9
|
+
signingRegion: region,
|
|
10
|
+
region,
|
|
11
|
+
},
|
|
9
12
|
keyId,
|
|
10
13
|
};
|
|
11
|
-
let signer = new
|
|
14
|
+
let signer = new kms_ethers_signer_1.KmsEthersSigner(kmsCredentials);
|
|
12
15
|
let signerAddress = await signer.getAddress();
|
|
13
16
|
// logger.info(` keyid ${keyId} ${signerAddress}`);
|
|
14
17
|
if (!signerAddress) {
|
|
@@ -5,6 +5,7 @@ export declare const isEmpty: (data: any) => boolean;
|
|
|
5
5
|
export declare const checkMissingFields: (fields: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}) => void;
|
|
8
|
+
export declare const checkEnvValue: (key: string) => string;
|
|
8
9
|
export declare const checkMissingFieldsAndType: (fields: {
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
}, types?: {
|
package/dist/utils/extraUtils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.responseBody = exports.filterFields = exports.removeFields = exports.checkObjectFieldsAndType = exports.checkMissingFieldsAndType = exports.checkMissingFields = exports.isEmpty = void 0;
|
|
4
|
-
const
|
|
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
5
|
/**
|
|
6
6
|
* defining functions.
|
|
7
7
|
*/
|
|
@@ -18,18 +18,26 @@ const checkMissingFields = (fields) => {
|
|
|
18
18
|
for (const field in fields) {
|
|
19
19
|
let value = fields[field];
|
|
20
20
|
if (!value) {
|
|
21
|
-
throw (0,
|
|
21
|
+
throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
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;
|
|
26
34
|
const checkMissingFieldsAndType = (fields, types = {}) => {
|
|
27
35
|
for (const field in fields) {
|
|
28
36
|
if ((0, exports.isEmpty)(fields[field])) {
|
|
29
|
-
throw (0,
|
|
37
|
+
throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
|
|
30
38
|
}
|
|
31
39
|
if (types[field] && typeof fields[field] !== types[field]) {
|
|
32
|
-
throw (0,
|
|
40
|
+
throw (0, constants_1.BadRequestError)(`Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
};
|
|
@@ -38,13 +46,13 @@ const checkObjectFieldsAndType = (data, types = {}, prefix = "") => {
|
|
|
38
46
|
let keys = Object.keys(types);
|
|
39
47
|
for (const key of keys) {
|
|
40
48
|
if ((0, exports.isEmpty)(data[key])) {
|
|
41
|
-
throw (0,
|
|
49
|
+
throw (0, constants_1.BadRequestError)(`missing field : ${prefix}.${key}`);
|
|
42
50
|
}
|
|
43
51
|
if (typeof data[key] === "object") {
|
|
44
52
|
(0, exports.checkObjectFieldsAndType)(data[key], types[key], `${prefix}.${key}`);
|
|
45
53
|
}
|
|
46
54
|
else if (typeof data[key] !== types[key]) {
|
|
47
|
-
throw (0,
|
|
55
|
+
throw (0, constants_1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
};
|
package/dist/utils/idUtils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface PacketDetails {
|
|
2
2
|
chainSlug: number;
|
|
3
3
|
capacitorAddr: string;
|
|
4
|
-
|
|
4
|
+
packetCount: string;
|
|
5
5
|
}
|
|
6
6
|
export interface MessageDetails {
|
|
7
7
|
chainSlug: number;
|
|
@@ -10,5 +10,5 @@ export interface MessageDetails {
|
|
|
10
10
|
}
|
|
11
11
|
export declare const unpackPacketId: (packetId: string) => PacketDetails;
|
|
12
12
|
export declare const unpackMessageId: (messageId: string) => MessageDetails;
|
|
13
|
-
export declare const packPacketId: (chainSlug: number, capacitorAddr: string,
|
|
13
|
+
export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetCount: string) => string;
|
|
14
14
|
export declare function encodePacketId(chainSlug: number, capacitorAddress: string, packetCount: number): string;
|
package/dist/utils/idUtils.js
CHANGED
|
@@ -9,11 +9,11 @@ const unpackPacketId = (packetId) => {
|
|
|
9
9
|
const slugLength = packetId.length - 58;
|
|
10
10
|
const chainSlug = parseInt(ethers_1.BigNumber.from(`0x${packetId.substring(2, 2 + slugLength)}`).toString());
|
|
11
11
|
const capacitorAddr = (0, address_1.toLowerCase)(`0x${packetId.substring(2 + slugLength, 40 + 2 + slugLength)}`);
|
|
12
|
-
const
|
|
12
|
+
const packetCount = ethers_1.BigNumber.from(`0x${packetId.substring(40 + 2 + slugLength)}`).toString();
|
|
13
13
|
return {
|
|
14
14
|
chainSlug,
|
|
15
15
|
capacitorAddr,
|
|
16
|
-
|
|
16
|
+
packetCount,
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
exports.unpackPacketId = unpackPacketId;
|
|
@@ -30,8 +30,8 @@ const unpackMessageId = (messageId) => {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
exports.unpackMessageId = unpackMessageId;
|
|
33
|
-
const packPacketId = (chainSlug, capacitorAddr,
|
|
34
|
-
const nonce = ethers_1.BigNumber.from(
|
|
33
|
+
const packPacketId = (chainSlug, capacitorAddr, packetCount) => {
|
|
34
|
+
const nonce = ethers_1.BigNumber.from(packetCount).toHexString();
|
|
35
35
|
const nonceHex = nonce.length <= 16 ? (0, utils_1.hexZeroPad)(nonce, 8).substring(2) : nonce.substring(2);
|
|
36
36
|
const slug = ethers_1.BigNumber.from(chainSlug).toHexString();
|
|
37
37
|
const slugHex = slug.length <= 10 ? (0, utils_1.hexZeroPad)(slug, 4) : slug;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./address";
|
|
|
6
6
|
export * from "./dataStructHelper";
|
|
7
7
|
export * from "./extraUtils";
|
|
8
8
|
export * from "./time";
|
|
9
|
+
export * from "./signer";
|
|
9
10
|
export * from "./ethersAwsKmsSigner";
|
|
10
11
|
export * from "./secretManagerService";
|
|
11
12
|
export * from "./eventGetter";
|
|
13
|
+
export * from "./s3Service";
|
package/dist/utils/index.js
CHANGED
|
@@ -22,6 +22,8 @@ __exportStar(require("./address"), exports);
|
|
|
22
22
|
__exportStar(require("./dataStructHelper"), exports);
|
|
23
23
|
__exportStar(require("./extraUtils"), exports);
|
|
24
24
|
__exportStar(require("./time"), exports);
|
|
25
|
+
__exportStar(require("./signer"), exports);
|
|
25
26
|
__exportStar(require("./ethersAwsKmsSigner"), exports);
|
|
26
27
|
__exportStar(require("./secretManagerService"), exports);
|
|
27
28
|
__exportStar(require("./eventGetter"), exports);
|
|
29
|
+
__exportStar(require("./s3Service"), exports);
|