Skip to content

Commit 7b445cb

Browse files
committed
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 11 additions & 8 deletions
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

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 11 additions & 15 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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
}
Lines changed: 2 additions & 0 deletions
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';
Lines changed: 4 additions & 0 deletions
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+
};
Lines changed: 8 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)