Skip to content

Commit

Permalink
Merge pull request #1157 from dm3-org/lukso-poc
Browse files Browse the repository at this point in the history
Lukso poc
  • Loading branch information
karladler authored Nov 18, 2024
2 parents 5da0caf + 7b445cb commit 6baf2b2
Show file tree
Hide file tree
Showing 95 changed files with 7,827 additions and 181 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
echo "ENCRYPTION_PUBLIC_KEY=${{ secrets.ENCRYPTION_PUBLIC_KEY }}" >> ./.env
echo "ENCRYPTION_PRIVATE_KEY=${{ secrets.ENCRYPTION_PRIVATE_KEY }}" >> ./.env
echo "RPC=${{ secrets.RPC }}" >> ./.env
echo "LUKSO_RPC=${{ secrets.LUKSO_RPC }}" >> ./.env
echo "URL=${{ vars.HOST_DOMAIN }}" >> ./.env
echo "CERT_MAIL=${{ vars.CERT_MAIL }}" >> ./.env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> ./.env
Expand Down
2 changes: 1 addition & 1 deletion docker/DockerfileBuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM --platform=linux/amd64 node:22-alpine3.18 as build
WORKDIR /build
COPY . .
# we need coreutils for proper ls command
RUN apk add --update coreutils python3 make g++ curl bash gawk jq\
RUN apk add --update coreutils python3 make g++ curl bash gawk jq git\
&& rm -rf /var/cache/apk/*

## Build libraries
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PRIVATE_KEY}
DISABLE_SESSION_CHECK: ${DISABLE_SESSION_CHECK}
RPC: ${RPC}
LUKSO_RPC: ${LUKSO_RPC}
PORT: 8081
LOG_LEVEL: 'debug'
DATABASE_URL: ${DATABASE_URL}
Expand Down Expand Up @@ -58,6 +59,7 @@ services:
ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY}
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PRIVATE_KEY}
RPC: ${RPC}
LUKSO_RPC: ${LUKSO_RPC}
PORT: 8083
LOG_LEVEL: 'debug'
volumes:
Expand Down Expand Up @@ -88,6 +90,7 @@ services:
DATABASE_URL: postgresql://postgres:example@offchain-resolver-db:5432
PORT: 8082
RPC: ${RPC}
LUKSO_RPC: ${LUKSO_RPC}
RESOLVER_SUPPORTED_ADDR_ENS_SUBDOMAINS: ${RESOLVER_SUPPORTED_ADDR_ENS_SUBDOMAINS}
RESOLVER_SUPPORTED_NAME_ENS_SUBDOMAINS: ${RESOLVER_SUPPORTED_NAME_ENS_SUBDOMAINS}
LOG_LEVEL: 'debug'
Expand Down
1 change: 1 addition & 0 deletions docker/resolutions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@dm3-org/dm3-lib-shared": "file:/library_archives/lib-shared.tgz",
"@dm3-org/dm3-lib-storage": "file:/library_archives/lib-storage.tgz",
"@dm3-org/dm3-lib-test-helper": "file:/library_archives/lib-test-helper.tgz",
"@dm3-org/dm3-lib-smart-account": "file:/library_archives/lib-smart-account.tgz",
"@dm3-org/dm3-messenger-widget": "file:/library_archives/messenger-widget.tgz"
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"packages/lib/storage",
"packages/lib/delivery-api",
"packages/lib/test-helper",
"packages/lib/smart-account",
"packages/lib/offchain-resolver-api",
"packages/backend",
"packages/integration-tests",
"packages/offchain-resolver",
"packages/messenger-widget",
"packages/js-sdk",
"packages/messenger-demo",
"packages/next-messenger-demo",
"packages/messenger-web",
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getServerSecret,
logError,
logRequest,
getLuksoProvider,
} from '@dm3-org/dm3-lib-server-side';
import { logInfo } from '@dm3-org/dm3-lib-shared';
import bodyParser from 'body-parser';
Expand All @@ -30,14 +31,15 @@ app.use(bodyParser.json());
(async () => {
const db = await getDatabase();
const web3Provider = await getCachedWebProvider(process.env);
const luksoProvider = await getLuksoProvider(process.env);
const serverSecret = getServerSecret(process.env);

app.use(logRequest);

app.get('/hello', (req, res) => {
return res.status(200).send('Hello DM3');
});
app.use('/profile', Profile(db, web3Provider, serverSecret));
app.use('/profile', Profile(db, web3Provider, luksoProvider, serverSecret));
app.use('/storage', Storage(db, web3Provider, serverSecret));
app.use('/auth', Authenticate(db, serverSecret, web3Provider));
app.use(logError);
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/profile/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ const setUpApp = async (
db: IBackendDatabase,
web3Provider: ethers.providers.JsonRpcProvider,
serverSecret: string = 'my-secret',
luksoProvider: ethers.providers.JsonRpcProvider = {} as ethers.providers.JsonRpcProvider,
) => {
app.use(bodyParser.json());
const server = http.createServer(app);
app.use(profile(db, web3Provider, serverSecret));
app.use(profile(db, web3Provider, luksoProvider, serverSecret));
};

const createDbMock = async () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/backend/src/profile/profile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { generateAuthJWT } from '@dm3-org/dm3-lib-server-side';
import { getUserProfile } from '@dm3-org/dm3-lib-profile';
import {
getUserProfile,
ProfileValidator,
SignedUserProfile,
} from '@dm3-org/dm3-lib-profile';

import {
checkUserProfile,
Expand All @@ -14,6 +18,7 @@ import { IBackendDatabase } from '../persistence/getDatabase';
export default (
db: IBackendDatabase,
web3Provider: ethers.providers.JsonRpcProvider,
luksoProvider: ethers.providers.JsonRpcProvider,
serverSecret: string,
) => {
const router = express.Router();
Expand Down Expand Up @@ -60,6 +65,7 @@ export default (
if (
!(await checkUserProfile(
web3Provider,
luksoProvider,
req.body, // as SignedUserProfile,
normalizeEnsName(ensName),
))
Expand Down
36 changes: 0 additions & 36 deletions packages/backend/src/profile/submitUserProfile.ts

This file was deleted.

8 changes: 5 additions & 3 deletions packages/delivery-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Authenticate,
errorHandler,
getCachedWebProvider,
getLuksoProvider,
getServerSecret,
logError,
logRequest,
Expand All @@ -22,13 +23,13 @@ import { startCleanUpPendingMessagesJob } from './cleanup/cleanUpPendingMessages
import { getDeliveryServiceProperties } from './config/getDeliveryServiceProperties';
import Delivery from './delivery';
import { onConnection } from './messaging';
import Metrics from './metrics';
import Notifications from './notifications';
import { IDatabase, getDatabase } from './persistence/getDatabase';
import { Profile } from './profile/profile';
import RpcProxy from './rpc/rpc-proxy';
import { WebSocketManager } from './ws/WebSocketManager';
import { socketAuth } from './socketAuth';
import Metrics from './metrics';
import { WebSocketManager } from './ws/WebSocketManager';

const app = express();
app.use(express.json({ limit: '50mb' }));
Expand Down Expand Up @@ -96,6 +97,7 @@ app.use(bodyParser.json());
// load environment
const deliveryServiceProperties = getDeliveryServiceProperties();
const web3Provider = await getCachedWebProvider(process.env);
const luksoProvider = await getLuksoProvider(process.env);

const db = getDbWithAddressResolvedGetAccount(
await getDatabase(),
Expand Down Expand Up @@ -142,7 +144,7 @@ app.use(bodyParser.json());

app.use('/metrics', Metrics(db, deliveryServiceProperties));
app.use('/auth', Authenticate(db, serverSecret, web3Provider));
app.use('/profile', Profile(db, web3Provider, serverSecret));
app.use('/profile', Profile(db, web3Provider, luksoProvider, serverSecret));
app.use('/delivery', Delivery(web3Provider, db, serverSecret));
app.use(
'/notifications',
Expand Down
3 changes: 2 additions & 1 deletion packages/delivery-service/src/profile/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const setUpApp = async (
db: IDatabase,
web3Provider: ethers.providers.JsonRpcProvider,
serverSecret: string = 'my-secret',
luksoProvider: ethers.providers.JsonRpcProvider = {} as ethers.providers.JsonRpcProvider,
) => {
app.use(bodyParser.json());
app.use(profile(db, web3Provider, serverSecret));
app.use(profile(db, web3Provider, luksoProvider, serverSecret));
};

const createDbMock = async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/delivery-service/src/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IDatabase } from '../persistence/getDatabase';
export const Profile = (
db: IDatabase,
web3Provider: ethers.providers.JsonRpcProvider,
luksoProvider: ethers.providers.JsonRpcProvider,
serverSecret: string,
) => {
const router = express.Router();
Expand Down Expand Up @@ -69,6 +70,7 @@ export const Profile = (
);

const data = await submitUserProfile(
luksoProvider,
db.getAccount,
db.setAccount,
//use normalized address
Expand Down
1 change: 1 addition & 0 deletions packages/js-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/**
6 changes: 6 additions & 0 deletions packages/js-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
modulePathIgnorePatterns: ['./dist'],
};
41 changes: 41 additions & 0 deletions packages/js-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@dm3-org/dm3-js-sdk",
"license": "BSD-2-Clause",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@dm3-org/dm3-lib-crypto": "workspace:^",
"@dm3-org/dm3-lib-delivery": "workspace:^",
"@dm3-org/dm3-lib-messaging": "workspace:^",
"@dm3-org/dm3-lib-profile": "workspace:^",
"@dm3-org/dm3-lib-server-side": "workspace:^",
"@dm3-org/dm3-lib-shared": "workspace:^",
"@dm3-org/dm3-lib-storage": "workspace:^",
"@dm3-org/dm3-lib-test-helper": "workspace:^",
"@web3-name-sdk/core": "^0.2.0",
"axios": "^0.27.2",
"dotenv": "^16.0.1",
"ethers": "5.7.2"
},
"scripts": {
"test": "jest --coverage --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'",
"build": "yarn tsc --declaration --declarationMap"
},
"devDependencies": {
"@babel/core": "^7.19.6",
"@babel/preset-env": "^7.19.4",
"@babel/preset-typescript": "^7.18.6",
"@types/supertest": "^2.0.12",
"babel-cli": "^6.26.0",
"babel-jest": "^29.2.2",
"babel-preset-env": "^1.7.0",
"jest": "^29.2.2",
"jest-mock-extended": "2.0.4",
"prettier": "^2.6.2",
"superagent": "^8.0.3",
"ts-jest": "^28.0.4",
"typescript": "^4.4.2"
},
"publish": true
}
12 changes: 12 additions & 0 deletions packages/js-sdk/src/Dm3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Conversations } from './conversation/Conversations';
import { Tld } from './tld/Tld';

export class Dm3 {
public readonly conversations: Conversations;
public readonly tld: Tld;

constructor(conversations: Conversations, tld: Tld) {
this.conversations = conversations;
this.tld = tld;
}
}
34 changes: 34 additions & 0 deletions packages/js-sdk/src/Dm3Sdk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ethers } from 'ethers';
import { Dm3Sdk, Dm3SdkConfig } from './Dm3Sdk';
import { StorageAPI } from '@dm3-org/dm3-lib-storage';

describe('Dm3Sdk', () => {
let upController: ethers.Signer;

beforeEach(async () => {
upController = ethers.Wallet.createRandom();
});

it('test', async () => {
const luksoProvider = () => ({
send: () => Promise.resolve([]),
getSigner: () => Promise.resolve(upController),
});
const mockConfig: Dm3SdkConfig = {
mainnetProvider: {} as ethers.providers.JsonRpcProvider,
lukso: luksoProvider as any,
nonce: '1',
defaultDeliveryService: 'test.io',
addressEnsSubdomain: 'addr.test',
userEnsSubdomain: 'user.test',
resolverBackendUrl: 'resolver.io',
backendUrl: 'backend.io',
storageApi: {} as StorageAPI,
};

// const dm3 = await new Dm3Sdk().universalProfileLogin();
// await dm3.conversations.addConversation('karl.eth');
// const c = dm3.conversations.list;
// const karl = c[0];
});
});
Loading

0 comments on commit 6baf2b2

Please sign in to comment.