Skip to content

Commit 7b445cb

Browse files
committedNov 18, 2024·
address pr comments
1 parent e103fd3 commit 7b445cb

File tree

15 files changed

+55
-96
lines changed

15 files changed

+55
-96
lines changed
 

‎packages/js-sdk/src/connectors/SmartAccountConnector.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class SmartAccountConnector {
111111
);
112112
//For each device in the keyStore, encrypt the profileKeys of the controller
113113
//That only applies for controllers that have a publicKey but not encryptedProfileKeys yet
114-
const newKeyStore: KeyStore.Dm3KeyStore = {};
114+
const newKeyStore: KeyStore.IDm3KeyStore = {};
115115

116116
for (const key of Object.keys(keyStore)) {
117117
const controller = keyStore[key];
@@ -350,7 +350,7 @@ export class SmartAccountConnector {
350350
// They are not.
351351
// Device2 starts the key transfer process, by:
352352
// Storing Device2 public key on an appropriate service
353-
private async addNewSigner(keyStore: KeyStore.Dm3KeyStore) {
353+
private async addNewSigner(keyStore: KeyStore.IDm3KeyStore) {
354354
const { encryptionKeyPair, signature } =
355355
await this.createEncryptionKeys();
356356

@@ -398,7 +398,7 @@ export class SmartAccountConnector {
398398
);
399399
const encryptedProfileKeys = btoa(stringify(encryptedPayload));
400400

401-
const dm3KeyStore: KeyStore.Dm3KeyStore = {
401+
const dm3KeyStore: KeyStore.IDm3KeyStore = {
402402
[upContollerAddress]: {
403403
encryptedProfileKeys,
404404
signerPublicKey: profileKeys.encryptionKeyPair.publicKey,

‎packages/js-sdk/src/tld/nameService/UniversalProfile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class UniversalProfile implements ITLDResolver {
3939
): Promise<string> {
4040
const [address] = ensName.split('.');
4141
const aliasName = await this.luksoIndexer.resolveAddress(address);
42-
return aliasName! + '.up';
42+
return `${aliasName}.up`;
4343
}
4444

4545
//e.g. alexcv#d7ab.up => 0x1234.addr.dm3.eth
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import { SignedUserProfile } from '@dm3-org/dm3-lib-profile';
22

33
//Struct that represents a Dm3 key store
4-
export interface Dm3KeyStore {
4+
export interface IDm3KeyStore {
55
[signerAddress: string]: {
66
signerPublicKey: string;
77
encryptedProfileKeys?: string;
88
};
99
}
1010

1111
export interface IKeyStoreService {
12-
//Method to publish the Dm3 user profile. Ideally this should be ENS or any other place that can be access using a resolver
12+
/*
13+
* Method to publish the Dm3 user profile. Ideally this should be ENS or any other place that can be access using a resolver
14+
*/
1315
writeDm3Profile(userProfile: SignedUserProfile): Promise<void>;
14-
//Method to publish the Dm3 key store. Ideally this should be ENS or any other place that can be access using a resolver
15-
writeDm3KeyStore(keyStore: Dm3KeyStore): Promise<void>;
16+
/* Method to publish the Dm3 key store. Ideally this should be ENS or any other place that can be access using a resolver */
1617

17-
//Convenience method to support batch calls
18+
writeDm3KeyStore(keyStore: IDm3KeyStore): Promise<void>;
19+
20+
/* Convenience method to support batch calls */
1821
writeDm3KeyStoreAndUserProfile(
19-
keyStore: Dm3KeyStore,
22+
keyStore: IDm3KeyStore,
2023
userProfile: SignedUserProfile,
2124
): Promise<void>;
2225

2326
readDm3Profile(): Promise<SignedUserProfile | undefined>;
24-
readDm3KeyStore(): Promise<Dm3KeyStore>;
27+
readDm3KeyStore(): Promise<IDm3KeyStore>;
2528

26-
//Returns the address of the Smart Account the KeyStore is associated with
29+
/* Returns the address of the Smart Account the KeyStore is associated with */
2730
getAccountAddress(): string;
2831
}

‎packages/lib/smart-account/src/lukso/ERC725JsonCoder.test.ts

-26
This file was deleted.

‎packages/lib/smart-account/src/lukso/ERC725JsonCoder.ts

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ERC725, { ERC725JSONSchema } from '@erc725/erc725.js';
2-
import { Dm3KeyStore } from '../KeyStore/IKeyStore';
2+
import { IDm3KeyStore } from '../KeyStore/IKeyStore';
33
import { EncodeDataReturn } from '@erc725/erc725.js/build/main/src/types';
44
import { ethers } from 'ethers';
55
import {
@@ -8,6 +8,7 @@ import {
88
} from '@erc725/erc725.js/build/main/src/types/decodeData';
99
import LSP6Schema from '@erc725/erc725.js/schemas/LSP6KeyManager.json';
1010
import { SignedUserProfile } from '@dm3-org/dm3-lib-profile';
11+
import { isStringArray } from './utils/isStringArray';
1112

1213
export class ERC725JsonCoder {
1314
public static readonly schemas: ERC725JSONSchema[] = [
@@ -96,7 +97,7 @@ export class ERC725JsonCoder {
9697
keyName: 'DM3UserProfile:<address>',
9798
dynamicKeyParts: upAddress,
9899
});
99-
if (encodedUserProfile.value === null) {
100+
if (!isStringArray(encodedUserProfile.value)) {
100101
return undefined;
101102
}
102103

@@ -105,25 +106,22 @@ export class ERC725JsonCoder {
105106
publicEncryptionKey,
106107
deliveryServices,
107108
signature,
108-
] = encodedUserProfile.value as Data[];
109+
] = encodedUserProfile.value;
109110

110111
return {
111112
profile: {
112-
publicSigningKey: ethers.utils.toUtf8String(
113-
publicSigningKey as string,
114-
),
115-
publicEncryptionKey: ethers.utils.toUtf8String(
116-
publicEncryptionKey as string,
117-
),
113+
publicSigningKey: ethers.utils.toUtf8String(publicSigningKey),
114+
publicEncryptionKey:
115+
ethers.utils.toUtf8String(publicEncryptionKey),
118116
deliveryServices: JSON.parse(
119-
ethers.utils.toUtf8String(deliveryServices as string),
117+
ethers.utils.toUtf8String(deliveryServices),
120118
),
121119
},
122-
signature: ethers.utils.toUtf8String(signature as string),
120+
signature: ethers.utils.toUtf8String(signature),
123121
};
124122
}
125123

126-
public async decodeDm3KeyStore(): Promise<Dm3KeyStore> {
124+
public async decodeDm3KeyStore(): Promise<IDm3KeyStore> {
127125
const controllerAddresses = await this.erc725.getData(
128126
'AddressPermissions[]',
129127
);
@@ -150,10 +148,8 @@ export class ERC725JsonCoder {
150148
),
151149
};
152150
return acc;
153-
}, {} as Dm3KeyStore);
151+
}, {} as IDm3KeyStore);
154152

155153
return ks;
156154
}
157155
}
158-
//"0x89197c814f5df4249c180000c73abaa79d9d562d07f09d8135b72b047908bbe6"
159-
//"0x89197c814f5df4249c1800007870c5b8bc9572a8001c3f96f7ff59961b23500d"

‎packages/lib/smart-account/src/lukso/LuksoIndexer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LuksoIndexer {
2121

2222
public async resolveAddress(address: string): Promise<string | undefined> {
2323
const query = gql`
24-
query MyQuery {
24+
query resolveAddress {
2525
Profile(where: { id: { _ilike: "${address}" } }) {
2626
fullName
2727
}
@@ -39,7 +39,7 @@ export class LuksoIndexer {
3939
lsp3FullName: string,
4040
): Promise<string | undefined> {
4141
const query = gql`
42-
query MyQuery {
42+
query resolveName {
4343
search_profiles(args: { search: "${lsp3FullName}" }) {
4444
id
4545
}

‎packages/lib/smart-account/src/lukso/LuksoKeyStore.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SignedUserProfile } from '@dm3-org/dm3-lib-profile';
22
import { stringify } from '@dm3-org/dm3-lib-shared';
33
import { ethers } from 'ethers';
44
import {
5-
Dm3KeyStore,
5+
IDm3KeyStore,
66
IKeyStoreService as IKeyStore,
77
} from '../KeyStore/IKeyStore';
88
import { ERC725, ERC725JSONSchema } from '@erc725/erc725.js';
@@ -44,7 +44,7 @@ export class LuksoKeyStore implements IKeyStore {
4444
const { keys, values } = encoded;
4545
await this.upContract.setDataBatch([...keys], [...values]);
4646
}
47-
async writeDm3KeyStore(keyStore: Dm3KeyStore): Promise<void> {
47+
async writeDm3KeyStore(keyStore: IDm3KeyStore): Promise<void> {
4848
//Create a key for each address in the keyStore
4949
const encodeDataReturn = Object.keys(keyStore).map((a) => {
5050
return this.erc725JsonCoder.encodeDm3KeyStoreEntry(
@@ -60,7 +60,7 @@ export class LuksoKeyStore implements IKeyStore {
6060
await this.upContract.setDataBatch(keys, values);
6161
}
6262
async writeDm3KeyStoreAndUserProfile(
63-
keyStore: Dm3KeyStore,
63+
keyStore: IDm3KeyStore,
6464
userProfile: SignedUserProfile,
6565
): Promise<void> {
6666
//encode keyStore
@@ -91,7 +91,7 @@ export class LuksoKeyStore implements IKeyStore {
9191
this.upContract.address,
9292
);
9393
}
94-
async readDm3KeyStore(): Promise<Dm3KeyStore> {
94+
async readDm3KeyStore(): Promise<IDm3KeyStore> {
9595
return await this.erc725JsonCoder.decodeDm3KeyStore();
9696
}
9797
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { LuksoKeyStore } from './LuksoKeyStore';
22
export { LuksoIndexer } from './LuksoIndexer';
3+
4+
export { isLuksoName } from './utils/isLuksoName';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const isLuksoName = (input: string): boolean => {
2+
const regex = /^[a-zA-Z0-9]+#[a-zA-Z0-9]{4}\.up$/;
3+
return regex.test(input);
4+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Checks if the value is an array of strings
3+
*/
4+
export function isStringArray(value: unknown): value is string[] {
5+
return (
6+
Array.isArray(value) && value.every((item) => typeof item === 'string')
7+
);
8+
}

‎packages/messenger-widget/src/components/AddConversation/AddConversation.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { closeLoader, startLoader } from '../Loader/Loader';
1515
import './AddConversation.css';
1616
import { normalizeEnsName } from '@dm3-org/dm3-lib-profile';
17+
import { Lukso } from '@dm3-org/dm3-lib-smart-account';
1718

1819
// class for input field
1920
export const INPUT_FIELD_CLASS =
@@ -98,21 +99,14 @@ export default function AddConversation() {
9899
setTldName(e.target.value);
99100

100101
if (
101-
!(
102-
ethers.utils.isValidName(e.target.value) ||
103-
isLuksoName(e.target.value)
104-
)
102+
!ethers.utils.isValidName(e.target.value) &&
103+
!Lukso.isLuksoName(e.target.value)
105104
) {
106105
setErrorMsg('Invalid address or ENS name');
107106
setShowError(true);
108107
}
109108
};
110109

111-
const isLuksoName = (input: string): boolean => {
112-
const regex = /^[a-zA-Z0-9]+#[a-zA-Z0-9]{4}\.up$/;
113-
return regex.test(input);
114-
};
115-
116110
return (
117111
<div>
118112
<div

‎packages/messenger-widget/src/hooks/auth/AccountConnector.ts

-16
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ export const AccountConnector = (
6666
if (!onChainProfile) {
6767
return await connectOffchainAccount(address);
6868
}
69-
/**
70-
* We've to check wether the profile published on chain belongs to the address we're trying to connect
71-
* For EOA that would simply work by checking if the profile sig matches the address linked to the profile
72-
* For Smart contracts we've to implement an ERC-1271 check first
73-
* See https://github.com/dm3-org/dm3/issues/1160
74-
*/
75-
//First occurance users logs in with onchain profile
76-
// const isProfileValid = await checkUserProfile(
77-
// mainnetProvider,
78-
// onChainProfile,
79-
// address,
80-
// );
81-
82-
// if (!isProfileValid) {
83-
// throw Error('Profile signature is invalid');
84-
// }
8569

8670
return {
8771
userProfile: onChainProfile,

‎packages/messenger-widget/src/hooks/auth/lukso/SmartAccountConnector.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Success,
1010
} from './SmartAccountConnector';
1111

12-
describe('SmartAccountConnector', () => {
12+
describe.skip('SmartAccountConnector', () => {
1313
describe('SignUp', () => {
1414
let universalProfile: ethers.Contract;
1515
let upController1: ethers.Signer;

‎packages/messenger-widget/src/hooks/auth/lukso/SmartAccountConnector.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class SmartAccountConnector {
111111
);
112112
//For each device in the keyStore, encrypt the profileKeys of the controller
113113
//That only applies for controllers that have a publicKey but not encryptedProfileKeys yet
114-
const newKeyStore: KeyStore.Dm3KeyStore = {};
114+
const newKeyStore: KeyStore.IDm3KeyStore = {};
115115

116116
for (const key of Object.keys(keyStore)) {
117117
const controller = keyStore[key];
@@ -350,7 +350,7 @@ export class SmartAccountConnector {
350350
// They are not.
351351
// Device2 starts the key transfer process, by:
352352
// Storing Device2 public key on an appropriate service
353-
private async addNewSigner(keyStore: KeyStore.Dm3KeyStore) {
353+
private async addNewSigner(keyStore: KeyStore.IDm3KeyStore) {
354354
const { encryptionKeyPair, signature } =
355355
await this.createEncryptionKeys();
356356

@@ -398,7 +398,7 @@ export class SmartAccountConnector {
398398
);
399399
const encryptedProfileKeys = btoa(stringify(encryptedPayload));
400400

401-
const dm3KeyStore: KeyStore.Dm3KeyStore = {
401+
const dm3KeyStore: KeyStore.IDm3KeyStore = {
402402
[upContollerAddress]: {
403403
encryptedProfileKeys,
404404
signerPublicKey: profileKeys.encryptionKeyPair.publicKey,

‎packages/messenger-widget/src/hooks/messages/useMessage.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { checkIfEnvelopAreInSizeLimit } from './sizeLimit/checkIfEnvelopIsInSize
2525
import { handleMessagesFromDeliveryService } from './sources/handleMessagesFromDeliveryService';
2626
import { handleMessagesFromStorage } from './sources/handleMessagesFromStorage';
2727
import { handleMessagesFromWebSocket } from './sources/handleMessagesFromWebSocket';
28+
import { Lukso } from '@dm3-org/dm3-lib-smart-account';
2829

2930
const DEFAULT_MESSAGE_PAGESIZE = 100;
3031

@@ -345,13 +346,6 @@ export const useMessage = () => {
345346
return { isSuccess: true };
346347
};
347348

348-
//Just for testing purposes
349-
//TODO cleanup and find better solution
350-
const isLuksoName = (input: string): boolean => {
351-
const regex = /^[a-zA-Z0-9]+#[a-zA-Z0-9]{4}\.up$/;
352-
return regex.test(input);
353-
};
354-
355349
const _dispatchMessage = async (
356350
contact: string,
357351
recipient: ContactPreview,
@@ -371,7 +365,7 @@ export const useMessage = () => {
371365
to: {
372366
...recipient!.contactDetails.account,
373367
//Cover edge case of lukso names. TODO discuss with the team and decide how to dela with non ENS names
374-
ensName: isLuksoName(recipient.name)
368+
ensName: Lukso.isLuksoName(recipient.name)
375369
? recipient.contactDetails.account.ensName
376370
: recipient.name,
377371
},

0 commit comments

Comments
 (0)
Please sign in to comment.