Skip to content

Commit 48a301c

Browse files
Merge pull request #27 from iExecBlockchainComputing/release/sdk-v0.0.3-alpha
Release/sdk v0.0.3 alpha
2 parents 2b3cbdc + 465d051 commit 48a301c

18 files changed

+207
-197
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.0.3-alpha] - 2025-04-04
6+
7+
### Changed
8+
9+
- Migrated the iApp codebase to ES Modules (ESM).
10+
- Migrated Bellecour subgraph URL to `https://thegraph.iex.ec`.
11+
512
## [0.0.2-alpha] - 2025-03-11
613

714
### Changed

dapp/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"root": true,
33
"plugins": ["import", "sonarjs"],
44
"parserOptions": {
5-
"ecmaVersion": 2020
5+
"ecmaVersion": 2022
66
},
77
"extends": ["airbnb-base", "prettier", "plugin:sonarjs/recommended"],
88
"rules": {

dapp/jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
transform: {},
3+
moduleNameMapper: {
4+
'^(\\.{1,2}/.*)\\.js$': '$1',
5+
},
6+
};

dapp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.2-alpha",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"engines": {
78
"node": ">=14.0.0 <15.0.0",
89
"npm": ">=6.0.0 <7.0.0"
@@ -38,4 +39,4 @@
3839
"jest": "^29.7.0",
3940
"prettier": "^2.8.8"
4041
}
41-
}
42+
}

dapp/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const start = require('./executeTask');
1+
import start from './executeTask';
22

33
start().catch((error) => {
44
console.error(`Error: ${error.message}`);

dapp/src/decryptContent.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { Buffer } = require('buffer');
2-
const forge = require('node-forge');
3-
const fetch = require('node-fetch');
1+
import { Buffer } from 'buffer';
2+
import fetch from 'node-fetch';
3+
import forge from 'node-forge';
44

55
const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec';
66

7-
const downloadEncryptedContent = async (
7+
export const downloadEncryptedContent = async (
88
multiaddr,
99
{ ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}
1010
) => {
@@ -22,7 +22,7 @@ const downloadEncryptedContent = async (
2222
}
2323
};
2424

25-
const decryptContent = (encryptedContent, encryptionKey) => {
25+
export const decryptContent = (encryptedContent, encryptionKey) => {
2626
const ivBytes = encryptedContent.slice(0, 16);
2727
let ciphertextBytes = encryptedContent.slice(16);
2828
const key = forge.util.createBuffer(Buffer.from(encryptionKey, 'base64'));
@@ -53,5 +53,3 @@ const decryptContent = (encryptedContent, encryptionKey) => {
5353

5454
return decryptedBuffer.toString();
5555
};
56-
57-
module.exports = { downloadEncryptedContent, decryptContent };

dapp/src/executeTask.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
const { promises: fs } = require('fs');
2-
const {
3-
IExecDataProtectorDeserializer,
4-
} = require('@iexec/dataprotector-deserializer');
5-
const sendTelegram = require('./telegramService');
6-
const {
7-
validateWorkerEnv,
1+
import { IExecDataProtectorDeserializer } from '@iexec/dataprotector-deserializer';
2+
import { promises as fs } from 'fs';
3+
import { decryptContent, downloadEncryptedContent } from './decryptContent';
4+
import sendTelegram from './telegramService';
5+
import {
86
validateAppSecret,
9-
validateRequesterSecret,
107
validateProtectedData,
11-
} = require('./validation');
12-
const {
13-
downloadEncryptedContent,
14-
decryptContent,
15-
} = require('./decryptContent');
8+
validateRequesterSecret,
9+
validateWorkerEnv,
10+
} from './validation';
1611

1712
async function writeTaskOutput(path, message) {
1813
try {
@@ -30,7 +25,6 @@ async function start() {
3025

3126
// Check worker env
3227
const workerEnv = validateWorkerEnv({ IEXEC_OUT });
33-
3428
// Parse the app developer secret environment variable
3529
let appDeveloperSecret;
3630
try {
@@ -51,7 +45,7 @@ async function start() {
5145
}
5246
requesterSecret = validateRequesterSecret(requesterSecret);
5347

54-
// parse the protected data and get the requester secret (chatId)
48+
// Parse the protected data and get the requester secret (chatId)
5549
let protectedData;
5650
try {
5751
const deserializer = new IExecDataProtectorDeserializer();
@@ -61,7 +55,7 @@ async function start() {
6155
} catch (e) {
6256
throw Error(`Failed to parse ProtectedData: ${e.message}`);
6357
}
64-
// validate the protected data (chatId)
58+
// Validate the protected data (chatId)
6559
validateProtectedData(protectedData);
6660

6761
const encryptedTelegramContent = await downloadEncryptedContent(
@@ -79,7 +73,6 @@ async function start() {
7973
botToken: appDeveloperSecret.TELEGRAM_BOT_TOKEN,
8074
senderName: requesterSecret.senderName,
8175
});
82-
8376
await writeTaskOutput(
8477
`${workerEnv.IEXEC_OUT}/result.txt`,
8578
JSON.stringify(response, null, 2)
@@ -92,4 +85,4 @@ async function start() {
9285
);
9386
}
9487

95-
module.exports = start;
88+
export default start;

dapp/src/telegramService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const TelegramBot = require('node-telegram-bot-api');
1+
import TelegramBot from 'node-telegram-bot-api';
22

33
async function sendTelegram({
44
chatId,
@@ -35,4 +35,4 @@ async function sendTelegram({
3535
};
3636
}
3737

38-
module.exports = sendTelegram;
38+
export default sendTelegram;

dapp/src/validation.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const Joi = require('joi');
1+
import Joi from 'joi';
22

33
const workerEnvSchema = Joi.object({
44
IEXEC_OUT: Joi.string().required(),
55
});
66

7-
function validateWorkerEnv(envVars) {
7+
export function validateWorkerEnv(envVars) {
88
const { error, value } = workerEnvSchema.validate(envVars, {
99
abortEarly: false,
1010
});
@@ -19,7 +19,7 @@ const appSecretSchema = Joi.object({
1919
TELEGRAM_BOT_TOKEN: Joi.string().required(),
2020
});
2121

22-
function validateAppSecret(obj) {
22+
export function validateAppSecret(obj) {
2323
const { error, value } = appSecretSchema.validate(obj, {
2424
abortEarly: false,
2525
});
@@ -42,7 +42,7 @@ const protectedDataChatIdSchema = Joi.object({
4242
.required(),
4343
});
4444

45-
function validateProtectedData(obj) {
45+
export function validateProtectedData(obj) {
4646
const { error, value } = protectedDataChatIdSchema.validate(obj, {
4747
abortEarly: false,
4848
});
@@ -62,7 +62,7 @@ const requesterSecretSchema = Joi.object({
6262
senderName: Joi.string().min(3).max(20),
6363
});
6464

65-
function validateRequesterSecret(obj) {
65+
export function validateRequesterSecret(obj) {
6666
const { error, value } = requesterSecretSchema.validate(obj, {
6767
abortEarly: false,
6868
});
@@ -72,10 +72,3 @@ function validateRequesterSecret(obj) {
7272
}
7373
return value;
7474
}
75-
76-
module.exports = {
77-
validateWorkerEnv,
78-
validateAppSecret,
79-
validateRequesterSecret,
80-
validateProtectedData,
81-
};

dapp/tests/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)