Skip to content

Commit

Permalink
wip sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Nov 4, 2024
1 parent a26cd3d commit 2d0cce4
Show file tree
Hide file tree
Showing 28 changed files with 2,072 additions and 160 deletions.
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'],
};
6 changes: 0 additions & 6 deletions packages/js-sdk/jest.config.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@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"
Expand All @@ -36,5 +37,6 @@
"ts-jest": "^28.0.4",
"typescript": "^4.4.2"
},

"publish": true
}
31 changes: 27 additions & 4 deletions packages/js-sdk/src/Dm3Sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import { Dm3 } from './Dm3Sdk';
import { ethers } from 'ethers';
import { Dm3Sdk, Dm3SdkConfig } from './Dm3Sdk';

describe('Dm3Sdk', () => {
it('test', () => {
const sdk = new Dm3();
const test = sdk.test();
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',
};

const sdk = new Dm3Sdk(mockConfig);

const dm3 = await sdk.universalProfileLogin();
});
});
41 changes: 25 additions & 16 deletions packages/js-sdk/src/Dm3Sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ export function getIdForAddress(address: string, addrEnsSubdomain: string) {
return address + addrEnsSubdomain;
}

export interface Dm3SdkConfig {
mainnetProvider: ethers.providers.JsonRpcProvider;
nonce: string;
defaultDeliveryService: string;
addressEnsSubdomain: string;
userEnsSubdomain: string;
resolverBackendUrl: string;
backendUrl: string;
lukso?: ethers.providers.ExternalProvider;
}

export class Dm3Sdk {
private readonly mainnetProvider: ethers.providers.JsonRpcProvider;
private readonly lukso?: ethers.providers.ExternalProvider;

/**
* DM3 ENVIRONMENT
Expand Down Expand Up @@ -49,32 +61,29 @@ export class Dm3Sdk {
*/
public conversations: Conversations;

constructor(
mainnetProvider: ethers.providers.JsonRpcProvider,
nonce: string,
defaultDeliveryService: string,
addressEnsSubdomain: string,
userEnsSubdomain: string,
resolverBackendUrl: string,
backendUrl: string,
) {
this.mainnetProvider = mainnetProvider;
this.nonce = nonce;
this.defaultDeliveryService = defaultDeliveryService;
this.addressEnsSubdomain = addressEnsSubdomain;
this.userEnsSubdomain = userEnsSubdomain;
this.resolverBackendUrl = resolverBackendUrl;
this.backendUrl = backendUrl;
constructor(config: Dm3SdkConfig) {
this.mainnetProvider = config.mainnetProvider;
this.nonce = config.nonce;
this.defaultDeliveryService = config.defaultDeliveryService;
this.addressEnsSubdomain = config.addressEnsSubdomain;
this.userEnsSubdomain = config.userEnsSubdomain;
this.resolverBackendUrl = config.resolverBackendUrl;
this.backendUrl = config.backendUrl;
this.lukso = config.lukso;
}

public async universalProfileLogin() {
if (!this.lukso) {
throw new Error('Lukso provider not found');
}
const tld = new Tld(
this.mainnetProvider,
this.addressEnsSubdomain,
this.userEnsSubdomain,
this.resolverBackendUrl,
);
const lc = await LuksoConnector._instance(
this.lukso,
this.nonce,
this.defaultDeliveryService,
);
Expand Down
Loading

0 comments on commit 2d0cce4

Please sign in to comment.