@socket.tech/dl-common 1.0.3-test.4 → 1.0.3-test.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/constants/confirmations.d.ts +5 -0
  2. package/dist/constants/confirmations.js +17 -0
  3. package/dist/constants/enums.d.ts +12 -2
  4. package/dist/constants/enums.js +12 -1
  5. package/dist/constants/types.d.ts +25 -3
  6. package/dist/constants/types.js +9 -1
  7. package/dist/constants/waitTime.d.ts +1 -0
  8. package/dist/constants/waitTime.js +7 -9
  9. package/dist/models/attestation.d.ts +2 -2
  10. package/dist/models/attestation.js +2 -2
  11. package/dist/models/index.d.ts +1 -0
  12. package/dist/models/index.js +1 -0
  13. package/dist/models/lastBlock.d.ts +28 -0
  14. package/dist/models/lastBlock.js +27 -0
  15. package/dist/models/message.d.ts +2 -2
  16. package/dist/models/message.js +2 -2
  17. package/dist/models/packet.d.ts +10 -2
  18. package/dist/models/packet.js +11 -2
  19. package/dist/models/proposal.d.ts +2 -2
  20. package/dist/models/proposal.js +2 -2
  21. package/dist/models/switchboard.d.ts +69 -0
  22. package/dist/models/switchboard.js +92 -0
  23. package/dist/models/transaction.d.ts +0 -0
  24. package/dist/models/transaction.js +280 -0
  25. package/dist/services/eventBridgeService.d.ts +8 -0
  26. package/dist/services/eventBridgeService.js +39 -0
  27. package/dist/services/index.d.ts +1 -0
  28. package/dist/services/index.js +1 -0
  29. package/dist/services/queueService.d.ts +2 -2
  30. package/dist/services/queueService.js +22 -14
  31. package/dist/utils/ethersAwsKmsSigner.d.ts +2 -2
  32. package/dist/utils/ethersAwsKmsSigner.js +6 -3
  33. package/dist/utils/extraUtils.d.ts +1 -0
  34. package/dist/utils/extraUtils.js +15 -7
  35. package/dist/utils/index.d.ts +2 -0
  36. package/dist/utils/index.js +2 -0
  37. package/dist/utils/relaySigner.d.ts +2 -4
  38. package/dist/utils/relaySigner.js +7 -10
  39. package/dist/utils/s3Service.d.ts +5 -0
  40. package/dist/utils/s3Service.js +45 -0
  41. package/dist/utils/signer/adapter.d.ts +18 -0
  42. package/dist/utils/signer/adapter.js +71 -0
  43. package/dist/utils/signer/address.d.ts +10 -0
  44. package/dist/utils/signer/address.js +42 -0
  45. package/dist/utils/signer/asn1-parser.d.ts +11 -0
  46. package/dist/utils/signer/asn1-parser.js +80 -0
  47. package/dist/utils/signer/crypto.d.ts +6 -0
  48. package/dist/utils/signer/crypto.js +34 -0
  49. package/dist/utils/signer/index.d.ts +4 -0
  50. package/dist/{types → utils/signer}/index.js +4 -2
  51. package/dist/utils/signer/kms-ethers-signer.d.ts +19 -0
  52. package/dist/utils/signer/kms-ethers-signer.js +32 -0
  53. package/dist/utils/signer/kms-signer.d.ts +14 -0
  54. package/dist/utils/signer/kms-signer.js +46 -0
  55. package/dist/utils/signer/signature.d.ts +17 -0
  56. package/dist/utils/signer/signature.js +65 -0
  57. package/dist/utils/signer/signer.d.ts +7 -0
  58. package/dist/utils/signer/signer.js +2 -0
  59. package/dist/utils/time.d.ts +1 -0
  60. package/dist/utils/time.js +3 -1
  61. package/package.json +52 -16
  62. package/dist/models/attestations.d.ts +0 -69
  63. package/dist/models/attestations.js +0 -59
  64. package/dist/types/codes.d.ts +0 -22
  65. package/dist/types/codes.js +0 -28
  66. package/dist/types/index.d.ts +0 -2
  67. package/dist/types/types.d.ts +0 -86
  68. package/dist/types/types.js +0 -41
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ // import { IntegrationTypes } from "@socket.tech/dl-core";
3
+ // import { DataTypes, Model } from "sequelize";
4
+ // import { toLowerCase } from "../utils";
5
+ // import {Project} from "@socket.tech/socket-plugs";
6
+ // export enum SealRelayStatus {
7
+ // SEALED = "SEALED",
8
+ // SEALING = "SEALING",
9
+ // NO = "NO",
10
+ // SEAL_FAILED = "SEAL_FAILED",
11
+ // }
12
+ // export enum PacketTripRelayStatus {
13
+ // IS_TRIPPING = "IS_TRIPPING",
14
+ // NO = "NO",
15
+ // TRIPPING_FAILED = "TRIPPING_FAILED",
16
+ // TRIPPED = "TRIPPED",
17
+ // }
18
+ // export enum ProposeRelayStatus {
19
+ // PROPOSED = "PROPOSED",
20
+ // PROPOSING = "PROPOSING",
21
+ // CONFIRMING = "CONFIRMING",
22
+ // NO = "NO",
23
+ // PROPOSE_FAILED = "PROPOSE_FAILED",
24
+ // CONFIRM_FAILED = "CONFIRM_FAILED",
25
+ // }
26
+ // export enum TxType {
27
+ // SUPERBRIDGE = "SUPERBRIDGE",
28
+ // SUPERTOKEN = "SUPERTOKEN"
29
+ // }
30
+ // export class Transaction extends Model {
31
+ // declare id: number;
32
+ // srcChainSlug: number;
33
+ // dstChainSlug: number;
34
+ // from: string;
35
+ // to:string;
36
+ // amount:number;
37
+ // token: string;
38
+ // tokenAddress: string;
39
+ // srcPlug: string;
40
+ // dstPlug: string;
41
+ // usdAmount: number;
42
+ // type: TxType;
43
+ // project: Project;
44
+ // srcTxHash: string;
45
+ // txTime: string;
46
+ // root: string;
47
+ // rootSealed: string;
48
+ // sealer: string;
49
+ // sealTxHash: string;
50
+ // sealTxId: string;
51
+ // sealSignature: string;
52
+ // sealTime: number;
53
+ // sealRelayStatus: SealRelayStatus;
54
+ // packetTripTime: number;
55
+ // packetTripTxnHash: string;
56
+ // packetTripErrorMessage: string;
57
+ // isPacketTripped: boolean;
58
+ // packetTripRelayStatus: PacketTripRelayStatus;
59
+ // // proposeTxId, proposeTxHash refers to the proposal sent by us. For details of other proposals, see Proposal table.
60
+ // proposeTxId: string;
61
+ // proposeTxHash: string;
62
+ // proposeRelayStatus: ProposeRelayStatus;
63
+ // selectedProposalCount: number;
64
+ // // attestTxId, attestTxHash refers to the attestation sent by us. For details of other attestations, see Attestation table.
65
+ // attestTxId: string;
66
+ // attestTxHash: string;
67
+ // attestRelayStatus: AttestRelayStatus;
68
+ // outboundTxHash: string;
69
+ // outboundTime: number;
70
+ // sealIndexTime: number;
71
+ // proposeTime: number;
72
+ // attestTime: number;
73
+ // packetTripTxHash: string;
74
+ // isFilled: boolean;
75
+ // isSealed: boolean;
76
+ // isProposed: boolean;
77
+ // isAttested: boolean;
78
+ // isVerified: boolean;
79
+ // isFullyExecuted: boolean;
80
+ // tripreason: TripReason;
81
+ // executionWaitTime: number;
82
+ // }
83
+ // export const PacketModel = {
84
+ // id: {
85
+ // type: DataTypes.INTEGER,
86
+ // autoIncrement: true,
87
+ // },
88
+ // srcChainSlug: {
89
+ // type: DataTypes.BIGINT,
90
+ // },
91
+ // dstChainSlug: {
92
+ // type: DataTypes.BIGINT,
93
+ // },
94
+ // srcCapacitor: {
95
+ // type: DataTypes.STRING,
96
+ // },
97
+ // dstSwitchboard: {
98
+ // type: DataTypes.STRING,
99
+ // },
100
+ // switchboardId: {
101
+ // type: DataTypes.STRING,
102
+ // },
103
+ // integrationType: {
104
+ // type: DataTypes.ENUM,
105
+ // values: [...Object.values(IntegrationTypes)],
106
+ // defaultValue: IntegrationTypes.unknown,
107
+ // },
108
+ // packetId: {
109
+ // type: DataTypes.STRING,
110
+ // primaryKey: true,
111
+ // },
112
+ // capacitorPacketCount: {
113
+ // type: DataTypes.STRING,
114
+ // },
115
+ // root: {
116
+ // type: DataTypes.STRING,
117
+ // },
118
+ // rootSealed: {
119
+ // type: DataTypes.STRING,
120
+ // },
121
+ // isFilled: {
122
+ // type: DataTypes.BOOLEAN,
123
+ // },
124
+ // isSealed: {
125
+ // type: DataTypes.BOOLEAN,
126
+ // defaultValue: false,
127
+ // },
128
+ // isProposed: {
129
+ // type: DataTypes.BOOLEAN,
130
+ // defaultValue: false,
131
+ // },
132
+ // isAttested: {
133
+ // type: DataTypes.BOOLEAN,
134
+ // defaultValue: false,
135
+ // },
136
+ // isVerified: {
137
+ // type: DataTypes.BOOLEAN,
138
+ // defaultValue: false,
139
+ // },
140
+ // isFullyExecuted: {
141
+ // type: DataTypes.BOOLEAN,
142
+ // defaultValue: false,
143
+ // },
144
+ // sealer: {
145
+ // type: DataTypes.STRING,
146
+ // },
147
+ // sealRelayStatus: {
148
+ // type: DataTypes.ENUM,
149
+ // values: [...Object.values(SealRelayStatus)],
150
+ // defaultValue: SealRelayStatus.NO,
151
+ // },
152
+ // sealTxId: {
153
+ // type: DataTypes.STRING,
154
+ // defaultValue: "",
155
+ // },
156
+ // sealTxHash: {
157
+ // type: DataTypes.STRING,
158
+ // defaultValue: "",
159
+ // },
160
+ // outboundTxHash: {
161
+ // type: DataTypes.STRING,
162
+ // defaultValue: "",
163
+ // },
164
+ // outboundTime: {
165
+ // type: DataTypes.INTEGER,
166
+ // },
167
+ // proposeTime: {
168
+ // type: DataTypes.INTEGER,
169
+ // },
170
+ // attestTime: {
171
+ // type: DataTypes.INTEGER,
172
+ // },
173
+ // sealTime: {
174
+ // type: DataTypes.INTEGER,
175
+ // },
176
+ // sealIndexTime: {
177
+ // type: DataTypes.INTEGER,
178
+ // },
179
+ // sealSignature: {
180
+ // type: DataTypes.STRING,
181
+ // },
182
+ // packetTripRelayStatus: {
183
+ // type: DataTypes.ENUM,
184
+ // values: [...Object.values(PacketTripRelayStatus)],
185
+ // defaultValue: PacketTripRelayStatus.NO,
186
+ // },
187
+ // packetTripTxId: {
188
+ // type: DataTypes.STRING,
189
+ // defaultValue: "",
190
+ // },
191
+ // packetTripTxHash: {
192
+ // type: DataTypes.STRING,
193
+ // defaultValue: "",
194
+ // },
195
+ // packetTripErrorMessage: {
196
+ // type: DataTypes.STRING,
197
+ // defaultValue: "",
198
+ // },
199
+ // packetTripTime: {
200
+ // type: DataTypes.INTEGER,
201
+ // },
202
+ // isPacketTripped: {
203
+ // type: DataTypes.BOOLEAN,
204
+ // defaultValue: false,
205
+ // },
206
+ // proposeTxId: {
207
+ // type: DataTypes.STRING,
208
+ // defaultValue: "",
209
+ // },
210
+ // proposeTxHash: {
211
+ // type: DataTypes.STRING,
212
+ // defaultValue: "",
213
+ // },
214
+ // proposeRelayStatus: {
215
+ // type: DataTypes.ENUM,
216
+ // values: [...Object.values(ProposeRelayStatus)],
217
+ // defaultValue: ProposeRelayStatus.NO,
218
+ // },
219
+ // selectedProposalCount: {
220
+ // type: DataTypes.INTEGER,
221
+ // },
222
+ // executionWaitTime: {
223
+ // type: DataTypes.INTEGER,
224
+ // },
225
+ // attestTxId: {
226
+ // type: DataTypes.STRING,
227
+ // defaultValue: "",
228
+ // },
229
+ // attestTxHash: {
230
+ // type: DataTypes.STRING,
231
+ // defaultValue: "",
232
+ // },
233
+ // tripReason: {
234
+ // type: DataTypes.ENUM,
235
+ // values: [...Object.values(TripReason)],
236
+ // defaultValue: TripReason.NO,
237
+ // },
238
+ // // packetTripTxHash: {
239
+ // // type: DataTypes.STRING,
240
+ // // defaultValue: "",
241
+ // // },
242
+ // attestRelayStatus: {
243
+ // type: DataTypes.ENUM,
244
+ // values: [...Object.values(AttestRelayStatus)],
245
+ // defaultValue: AttestRelayStatus.NO,
246
+ // },
247
+ // };
248
+ // function processStrings(packet: Packet): Packet {
249
+ // if (packet.packetId) packet.packetId = toLowerCase(packet.packetId);
250
+ // if (packet.root) packet.root = toLowerCase(packet.root);
251
+ // if (packet.rootSealed) packet.rootSealed = toLowerCase(packet.rootSealed);
252
+ // if (packet.sealer) packet.sealer = toLowerCase(packet.sealer);
253
+ // if (packet.outboundTxHash) {
254
+ // packet.outboundTxHash = toLowerCase(packet.outboundTxHash);
255
+ // }
256
+ // if (packet.sealTxHash) packet.sealTxHash = toLowerCase(packet.sealTxHash);
257
+ // if (packet.sealSignature) {
258
+ // packet.sealSignature = toLowerCase(packet.sealSignature);
259
+ // }
260
+ // if (packet.dstSwitchboard) {
261
+ // packet.dstSwitchboard = toLowerCase(packet.dstSwitchboard);
262
+ // }
263
+ // if (packet.switchboardId) {
264
+ // packet.switchboardId = toLowerCase(packet.switchboardId);
265
+ // }
266
+ // if (packet.packetTripTxHash) {
267
+ // packet.packetTripTxHash = toLowerCase(packet.packetTripTxHash);
268
+ // }
269
+ // return packet;
270
+ // }
271
+ // export const addPacketHooks = () => {
272
+ // Packet.beforeBulkCreate((packet, options) => {
273
+ // for (let index = 0; index < packet.length; index++) {
274
+ // packet[index] = processStrings(packet[index]);
275
+ // }
276
+ // });
277
+ // Packet.beforeSave((packet, options) => {
278
+ // packet = processStrings(packet);
279
+ // });
280
+ // };
@@ -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;
@@ -1,2 +1,3 @@
1
1
  export * from "./queueService";
2
2
  export * from "./cacheService";
3
+ export * from "./eventBridgeService";
@@ -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,10 +1,10 @@
1
1
  export declare const initQueue: (region: string) => void;
2
2
  export declare const sendStandardSqsMessage: (queueUrl: string, data: any, DelaySeconds?: number) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
3
- export declare const sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<import("@aws-sdk/client-sqs").SendMessageBatchCommandOutput>;
3
+ export declare const sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<void>;
4
4
  export declare const sendFifoSqsMessage: (queueUrl: string, data: any, MessageGroupId: string) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
5
5
  declare const _default: {
6
6
  sendStandardSqsMessage: (queueUrl: string, data: any, DelaySeconds?: number) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
7
7
  sendFifoSqsMessage: (queueUrl: string, data: any, MessageGroupId: string) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
8
- sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<import("@aws-sdk/client-sqs").SendMessageBatchCommandOutput>;
8
+ sendStandardBatchMessages: (QueueUrl: string, dataArray: any[], DelaySecondsArray?: number[]) => Promise<void>;
9
9
  };
10
10
  export default _default;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendFifoSqsMessage = exports.sendStandardBatchMessages = exports.sendStandardSqsMessage = exports.initQueue = void 0;
4
4
  const client_sqs_1 = require("@aws-sdk/client-sqs");
5
+ const utils_1 = require("../utils");
5
6
  let client;
6
7
  const initQueue = (region) => {
7
8
  client = new client_sqs_1.SQSClient({ region });
@@ -19,21 +20,28 @@ const sendStandardSqsMessage = async (queueUrl, data, DelaySeconds = 0) => {
19
20
  };
20
21
  exports.sendStandardSqsMessage = sendStandardSqsMessage;
21
22
  const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray = []) => {
22
- let Entries = [];
23
- for (let i = 0; i < dataArray.length; i++) {
24
- Entries.push({
25
- MessageBody: JSON.stringify(dataArray[i]),
26
- Id: i,
27
- DelaySeconds: DelaySecondsArray[i] ? DelaySecondsArray[i] : 0,
28
- });
23
+ var _a;
24
+ const dataChunks = [...(0, utils_1.chunks)(dataArray, 10)];
25
+ const delayChunks = [...(0, utils_1.chunks)(DelaySecondsArray, 10)];
26
+ for (let i = 0; i < dataChunks.length; i++) {
27
+ let Entries = [];
28
+ let currentDataArray = dataChunks[i];
29
+ let currentDelayArray = delayChunks[i];
30
+ for (let j = 0; j < currentDataArray.length; j++) {
31
+ Entries.push({
32
+ MessageBody: JSON.stringify(currentDataArray[j]),
33
+ Id: String(i) + "-" + String(j),
34
+ DelaySeconds: (_a = currentDelayArray[j]) !== null && _a !== void 0 ? _a : 0,
35
+ });
36
+ }
37
+ let sqsOrderData = {
38
+ Entries,
39
+ QueueUrl,
40
+ };
41
+ // Send the order data to the SQS queue
42
+ const command = new client_sqs_1.SendMessageBatchCommand(sqsOrderData);
43
+ await client.send(command);
29
44
  }
30
- let sqsOrderData = {
31
- Entries,
32
- QueueUrl,
33
- };
34
- // Send the order data to the SQS queue
35
- const command = new client_sqs_1.SendMessageBatchCommand(sqsOrderData);
36
- return await client.send(command);
37
45
  };
38
46
  exports.sendStandardBatchMessages = sendStandardBatchMessages;
39
47
  const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
@@ -1,2 +1,2 @@
1
- import { AwsKmsSigner } from "ethers-aws-kms-signer";
2
- export declare const getAwsKmsSigner: (keyId: string, region?: string) => Promise<AwsKmsSigner>;
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 ethers_aws_kms_signer_1 = require("ethers-aws-kms-signer");
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
- region,
8
+ kmsClientConfig: {
9
+ signingRegion: region,
10
+ region,
11
+ },
9
12
  keyId,
10
13
  };
11
- let signer = new ethers_aws_kms_signer_1.AwsKmsSigner(kmsCredentials);
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?: {
@@ -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 __1 = require("..");
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, __1.BadRequestError)(`missing field : ${field}`);
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, __1.BadRequestError)(`missing field : ${field}`);
37
+ throw (0, constants_1.BadRequestError)(`missing field : ${field}`);
30
38
  }
31
39
  if (types[field] && typeof fields[field] !== types[field]) {
32
- throw (0, __1.BadRequestError)(`Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`);
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, __1.BadRequestError)(`missing field : ${prefix}.${key}`);
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, __1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
55
+ throw (0, constants_1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
48
56
  }
49
57
  }
50
58
  };
@@ -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";
@@ -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);
@@ -2,17 +2,15 @@ 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";
6
5
  export declare class SocketRelaySigner extends Signer {
7
6
  readonly provider: Provider;
8
- readonly chainSlug: ChainSlug;
7
+ readonly chainId: number;
9
8
  readonly relayUrl: string;
10
9
  readonly relayerAPIKey: string;
11
10
  readonly sequential: boolean;
12
11
  readonly isCritical: boolean;
13
12
  readonly metadata: object;
14
- readonly source: string;
15
- constructor(provider: Provider, chainSlug: ChainSlug, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object, source?: string);
13
+ constructor(provider: Provider, chainId: number, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object);
16
14
  getAddress(): Promise<string>;
17
15
  signMessage(message: string | Bytes): Promise<string>;
18
16
  connect(provider: Provider): SocketRelaySigner;
@@ -3,21 +3,19 @@ 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");
7
6
  class SocketRelaySigner extends abstract_signer_1.Signer {
8
- constructor(provider, chainSlug, relayUrl, relayerAPIKey, sequential = false,
7
+ constructor(provider, chainId, relayUrl, relayerAPIKey, sequential = false,
9
8
  // if isCritical is set to true, will try multiple relayers
10
9
  // to get the transaction included
11
- isCritical = false, metadata = {}, source = "Attester") {
10
+ isCritical = false, metadata = {}) {
12
11
  super();
13
12
  this.provider = provider;
14
- this.chainSlug = chainSlug;
13
+ this.chainId = chainId;
15
14
  this.relayUrl = relayUrl;
16
15
  this.relayerAPIKey = relayerAPIKey;
17
16
  this.sequential = sequential;
18
17
  this.isCritical = isCritical;
19
18
  this.metadata = metadata;
20
- this.source = source;
21
19
  }
22
20
  async getAddress() {
23
21
  // some random address
@@ -27,13 +25,13 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
27
25
  throw new Error(" signMessage not Implemented");
28
26
  }
29
27
  connect(provider) {
30
- return new SocketRelaySigner(provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
28
+ return new SocketRelaySigner(provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
31
29
  }
32
30
  setCritical(isCritical) {
33
- return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
31
+ return new SocketRelaySigner(this.provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
34
32
  }
35
33
  addMetadata(metadata) {
36
- return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
34
+ return new SocketRelaySigner(this.provider, this.chainId, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
37
35
  }
38
36
  async signTransaction(transaction) {
39
37
  throw new Error(" signTransaction not Implemented");
@@ -45,10 +43,9 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
45
43
  if (!this.relayUrl)
46
44
  throw new Error("relayUrl not provided");
47
45
  let payload = {
48
- chainId: dl_core_1.ChainSlugToId[this.chainSlug],
46
+ chainId: this.chainId,
49
47
  sequential: this.sequential,
50
48
  isCritical: this.isCritical,
51
- source: this.source,
52
49
  metadata: this.metadata,
53
50
  ...transaction,
54
51
  };
@@ -0,0 +1,5 @@
1
+ import { DeploymentMode } from "@socket.tech/dl-core";
2
+ import { Accounts } from "..";
3
+ export declare const initS3Client: (region: string) => Promise<void>;
4
+ export declare const getFileFromS3: (bucket: string, filePath: string) => Promise<any>;
5
+ export declare const getS3Config: (deploymentMode: DeploymentMode, region?: string, account?: Accounts.dl | Accounts.ll) => Promise<any>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getS3Config = 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 = async (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
+ // Create an S3 GET operation command
19
+ const getObjectCommand = new client_s3_1.GetObjectCommand({
20
+ Bucket: bucket,
21
+ Key: filePath,
22
+ });
23
+ // Execute the command and get the response
24
+ const s3Response = await s3Client.send(getObjectCommand);
25
+ const jsonStr = await ((_a = s3Response.Body) === null || _a === void 0 ? void 0 : _a.transformToString());
26
+ let response;
27
+ if (jsonStr)
28
+ response = JSON.parse(jsonStr);
29
+ return response;
30
+ }
31
+ catch (error) {
32
+ console.error("Error downloading file from S3:", error);
33
+ throw error;
34
+ }
35
+ };
36
+ exports.getFileFromS3 = getFileFromS3;
37
+ const getS3Config = async (deploymentMode, region = "us-east-1", account = __1.Accounts.dl) => {
38
+ const S3_BUCKET_NAME = deploymentMode == dl_core_1.DeploymentMode.PROD
39
+ ? `socket-${account}-` + deploymentMode
40
+ : `socket-ll-` + deploymentMode;
41
+ const S3_RPC_CONFIG_FILE_PATH = deploymentMode + "RpcConfig.json";
42
+ (0, exports.initS3Client)(region);
43
+ return await (0, exports.getFileFromS3)(S3_BUCKET_NAME, S3_RPC_CONFIG_FILE_PATH);
44
+ };
45
+ exports.getS3Config = getS3Config;
@@ -0,0 +1,18 @@
1
+ import type { Signer as ISigner } from "./signer";
2
+ import { Signer } from "@ethersproject/abstract-signer";
3
+ import { Deferrable } from "@ethersproject/properties";
4
+ import { Bytes } from "@ethersproject/bytes";
5
+ import type { Provider, TransactionRequest } from "@ethersproject/abstract-provider";
6
+ export type AdapterConfig = {
7
+ signer: ISigner;
8
+ version: string;
9
+ };
10
+ export declare class Adapter extends Signer {
11
+ private readonly signer;
12
+ private readonly logger;
13
+ constructor(config: AdapterConfig, provider?: Provider);
14
+ getAddress(): Promise<string>;
15
+ signMessage(message: Bytes | string): Promise<string>;
16
+ signTransaction(deferrableTransaction: Deferrable<TransactionRequest>): Promise<string>;
17
+ connect(provider: Provider): Adapter;
18
+ }