Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve variable namings #374

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
372025b
feat: refactor `granteeEnryptionPublicKey` and `nearWalletPublicKey`
ditoglez Dec 3, 2024
89c3fed
feat: change `receiverPublicKey` to `recipientEncryptionPublicKey`
ditoglez Dec 3, 2024
5ff1742
feat: additional changes to key arguments
ditoglez Dec 3, 2024
9d5d6aa
feat: change `discoverEncryptionKey` to `discoverUserEncryptionPublic…
ditoglez Dec 4, 2024
c2840e4
fix: update dashboard to use new namings
ditoglez Dec 4, 2024
61a94b2
docs: update README
ditoglez Dec 4, 2024
1782e2a
feat(client-sdk): update key names in enclave provider
ditoglez Dec 5, 2024
5a21782
featy(enclave: update variable names
ditoglez Dec 5, 2024
b78b575
feat(client-sdk): update AuthUser type
ditoglez Dec 5, 2024
545b148
feat(client-sdk): update grants var names
ditoglez Dec 5, 2024
09068a0
feat(types): update idOSGrant type
ditoglez Dec 5, 2024
b1a626f
feat(dashboard): update grants functionality
ditoglez Dec 5, 2024
3023b9c
feat(types): update idOSGrant types
ditoglez Dec 5, 2024
50363bf
feat: update `hasProfile` signature
ditoglez Dec 6, 2024
9f76ed5
feat(dashboard-dapps): update with latest sdk changes
ditoglez Dec 6, 2024
4b3305f
feat(example-dapp): update to match latest grant sharing changes
ditoglez Dec 6, 2024
3ba21bd
feat(server-dapp-sdk): update namings
ditoglez Dec 6, 2024
ed73612
feat(example-dapp): proper `idOSGrantee` initialisation
ditoglez Dec 6, 2024
f485b1f
Merge branch 'main' of github.com:idos-network/idos-sdk-js into refac…
Mohammed-Mamoun98 Dec 11, 2024
2b309bb
Merge remote-tracking branch 'origin' into refactor/improve-namings
pkoch Dec 13, 2024
a67ca80
Fix naming
pkoch Dec 13, 2024
7706e5d
Rename human to user
pkoch Dec 13, 2024
63bcb07
more PR comments completed
Mohammed-Mamoun98 Dec 16, 2024
f676751
fix format
Mohammed-Mamoun98 Dec 16, 2024
e7a871b
Get rid of old encryptionPrivateKey
pkoch Dec 17, 2024
419ad73
Merge branch 'main' of github.com:idos-network/idos-sdk-js into refac…
Mohammed-Mamoun98 Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions apps/dashboard-for-dapps/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const useFetchGrants = () => {
queryKey: ["grants"],
queryFn: () =>
idOS.grants.list({
grantee: address,
granteeAddress: address,
}),
select: (data) =>
data.map((grant) => ({
Expand Down Expand Up @@ -331,7 +331,6 @@ function CredentialDetails({
<List.Item
flexShrink="0"
key={key}
role="button"
transition="transform 0.2s"
cursor="pointer"
_hover={{ transform: "scale(1.02)" }}
Expand Down Expand Up @@ -424,7 +423,7 @@ function SearchResults({ results }: { results: GrantsWithFormattedLockedUntil })
pt="4"
grow
label="Owner"
value={grant.owner}
value={grant.ownerAddress}
truncate
/>
<DataListItem
Expand All @@ -439,7 +438,7 @@ function SearchResults({ results }: { results: GrantsWithFormattedLockedUntil })
pt="4"
grow
label="Grantee"
value={grant.grantee}
value={grant.granteeAddress}
truncate
/>
<DataListItem
Expand Down
2 changes: 1 addition & 1 deletion apps/idos-data-dashboard/src/core/idos/idos-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Provider = ({ children }: PropsWithChildren) => {
if (profile) {
// @ts-expect-error
await _sdk.setSigner(signer.type, signer.value);
const _pk = _sdk.auth.currentUser.publicKey;
const _pk = _sdk.auth.currentUser.currentUserPublicKey;
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved

setPublicKey(_pk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const DeleteCredential = ({ isOpen, credential, onClose }: DeleteCredenti
if (!credential) return null;

const [currentToRevoke] = state;
const { grantee } = currentToRevoke ?? {};
const { granteeAddress } = currentToRevoke ?? {};

const meta = JSON.parse(credential.public_notes);

Expand Down Expand Up @@ -172,7 +172,7 @@ export const DeleteCredential = ({ isOpen, credential, onClose }: DeleteCredenti
<>
<Text mb={1}>Revoking grant for grantee:</Text>
<Code px={2} py={1} rounded="md" fontSize="sm" bg="neutral.800">
{grantee}
{granteeAddress}
</Code>
</>
) : deleteCredential.isPending ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type GrantsCenterProps = {
};

function generateGrantId(grant: idOSGrant): string {
const { dataId, grantee, owner, lockedUntil } = grant;
return [dataId, grantee, owner, lockedUntil].join("-");
const { dataId, granteeAddress, ownerAddress, lockedUntil } = grant;
return [dataId, granteeAddress, ownerAddress, lockedUntil].join("-");
}

function timelockToMs(timelock: number): number {
Expand Down Expand Up @@ -96,7 +96,7 @@ const Shares = ({ credentialId, grants }: { credentialId: string; grants: idOSGr
data-grant={JSON.stringify(grant)}
>
<Td maxW={140}>
<Text isTruncated>{grant.grantee}</Text>
<Text isTruncated>{grant.granteeAddress}</Text>
</Td>
<Td>
<Text>{grant.lockedUntil ? timelockToDate(grant.lockedUntil) : "-"}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const useFetchGrants = ({ credentialId }: { credentialId: string }) => {
const queryClient = useQueryClient();
const credentials = queryClient.getQueryData<idOSCredentialWithShares[]>(["credentials"]);

const owner = address?.includes("0x") ? address : publicKey;
const ownerAddress = address?.includes("0x") ? address : publicKey;

return useQuery({
queryKey: ["grants", credentialId],
queryFn: () => sdk.grants.list({ owner }),
queryFn: () => sdk.grants.list({ ownerAddress }),
retry: 1,
select(grants) {
if (!credentials || !grants) return [];
Expand All @@ -34,8 +34,8 @@ export const useRevokeGrant = () => {
const queryClient = useQueryClient();

return useMutation<{ transactionId: string }, DefaultError, idOSGrant, Ctx>({
mutationFn: ({ grantee, dataId, lockedUntil }: idOSGrant) =>
sdk.grants.revoke("credentials", dataId, grantee, dataId, lockedUntil),
mutationFn: ({ granteeAddress, dataId, lockedUntil }: idOSGrant) =>
sdk.grants.revoke("credentials", dataId, granteeAddress, dataId, lockedUntil),
mutationKey: ["revokeGrant"],
async onMutate(grant) {
const previousCredentials =
Expand Down
12 changes: 4 additions & 8 deletions apps/idos-enclave/src/lib/enclave.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export class Enclave {
});
}

storage(humanId, signerAddress, signerPublicKey, expectedUserEncryptionPublicKey) {
storage(humanId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signerEncryptionPublicKey doesn't make sense. A signer is a crypto device used for auth.

What am I missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userEncryptionPublicKey ?

humanId && this.store.set("human-id", humanId);
signerAddress && this.store.set("signer-address", signerAddress);
signerPublicKey && this.store.set("signer-public-key", signerPublicKey);
signerEncryptionPublicKey && this.store.set("signer-public-key", signerEncryptionPublicKey);

const litAttrs = this.store.get("litAttrs");
this.handlstoreableAttributes(litAttrs);
Expand Down Expand Up @@ -248,10 +248,6 @@ export class Enclave {
}
}

messageParent(message) {
window.parent.postMessage(message, this.parentOrigin);
}

async filterCredentialsByCountries(credentials, countries) {
const decrypted = await Promise.all(
credentials.map(async (credential) => ({
Expand Down Expand Up @@ -329,7 +325,7 @@ export class Enclave {
receiverPublicKey,
senderPublicKey,
signerAddress,
signerPublicKey,
signerEncryptionPublicKey,
mode,
theme,
credentials,
Expand All @@ -352,7 +348,7 @@ export class Enclave {
storage: () => [
humanId,
signerAddress,
signerPublicKey,
signerEncryptionPublicKey,
expectedUserEncryptionPublicKey,
litAttrs,
userWallets,
Expand Down
2 changes: 1 addition & 1 deletion examples/idos-example-dapp/api/EVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const evmGranteeSigner = new ethers.Wallet(
const idosGrantee = await idOSGrantee.init({
chainType: "EVM",
granteeSigner: evmGranteeSigner,
encryptionSecret: ENCRYPTION_SECRET_KEY,
encryptionPrivateKey: ENCRYPTION_SECRET_KEY,
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved
});

const encryptionPublicKey = idosGrantee.encryptionPublicKey;
Expand Down
2 changes: 1 addition & 1 deletion examples/idos-example-dapp/api/NEAR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const nearGranteeSigner = KeyPair.fromString(NEAR_GRANTEE_PRIVATE_KEY);
const idosGrantee = await idOSGrantee.init({
chainType: "NEAR",
granteeSigner: nearGranteeSigner,
encryptionSecret: ENCRYPTION_SECRET_KEY,
encryptionPrivateKey: ENCRYPTION_SECRET_KEY,
});

const encryptionPublicKey = idosGrantee.encryptionPublicKey;
Expand Down
3 changes: 2 additions & 1 deletion examples/idos-example-dapp/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ const connectWallet = {
.h1("eyes", "User's grants to this dApp")
.wait(
"awaiting RPC",
cache.get("grants") || idos.grants.list({ owner, grantee: granteeInfo.grantee }),
cache.get("grants") ||
idos.grants.list({ ownerAddress: owner, granteeAddress: granteeInfo.grantee }),
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved
);
cache.set("grants", grants);

Expand Down
17 changes: 12 additions & 5 deletions packages/idos-sdk-js/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ import { implicitAddressFromPublicKey } from "./utils";

export interface AuthUser {
humanId: string | null;
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved
address: string;
publicKey?: string;
userAddress: string;
/**
* The public key of the wallet that was used to sign the message.
* It's only available when the `signer` is a NEAR wallet.
*/
nearWalletPublicKey?: string;
/**
* The derived public key of the user from the password / passkey.
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved
*/
currentUserPublicKey?: string;
}

Expand Down Expand Up @@ -72,7 +79,7 @@ export class Auth {
this.user = {
humanId: id,
currentUserPublicKey: current_public_key,
address: currentAddress,
userAddress: currentAddress,
};
}

Expand Down Expand Up @@ -208,8 +215,8 @@ export class Auth {
this.user = {
humanId: id,
currentUserPublicKey: current_public_key,
address: currentAddress,
publicKey,
userAddress: currentAddress,
nearWalletPublicKey: publicKey,
};
}
}
35 changes: 18 additions & 17 deletions packages/idos-sdk-js/src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@ export class Data {
records: T[],
synchronous?: boolean,
) {
let receiverPublicKey: string | undefined;
let recipientEncryptionPublicKey: string | undefined;

if (tableName === "credentials") {
receiverPublicKey = receiverPublicKey ?? Base64Codec.encode(await this.enclave.ready());
recipientEncryptionPublicKey =
recipientEncryptionPublicKey ?? Base64Codec.encode(await this.enclave.ready());
for (const record of records) {
Object.assign(
record,
await this.#buildInsertableIDOSCredential(
record.human_id,
record.public_notes,
record.content,
receiverPublicKey, // Encryption
recipientEncryptionPublicKey,
),
);
}
Expand Down Expand Up @@ -118,7 +119,7 @@ export class Data {
tableName === "human_attributes" ? "attributes" : tableName,
)}`;

let receiverPublicKey: string | undefined;
let recipientEncryptionPublicKey: string | undefined;

const inputs: string[] = ((await this.kwilWrapper.schema) as AnyRecord).data.actions
.find((action: AnyRecord) => action.name === name)
Expand All @@ -131,14 +132,14 @@ export class Data {
}

if (tableName === "credentials") {
receiverPublicKey ??= Base64Codec.encode(await this.enclave.ready());
recipientEncryptionPublicKey ??= Base64Codec.encode(await this.enclave.ready());
Object.assign(
record,
await this.#buildInsertableIDOSCredential(
(record as AnyRecord).human_id,
(record as AnyRecord).public_notes,
(record as AnyRecord).content,
receiverPublicKey, // Encryption
recipientEncryptionPublicKey,
),
);
}
Expand Down Expand Up @@ -259,21 +260,21 @@ export class Data {
description?: string,
synchronous?: boolean,
): Promise<T> {
if (!this.enclave.encryptionPublicKey) await this.enclave.ready();
if (!this.enclave.userEncryptionPublicKey) await this.enclave.ready();

let receiverPublicKey: string | undefined;
let recipientEncryptionPublicKey: string | undefined;
// biome-ignore lint/suspicious/noExplicitAny: using any to avoid type errors for now.
const record: any = recordLike;

if (tableName === "credentials") {
receiverPublicKey ??= Base64Codec.encode(await this.enclave.ready());
recipientEncryptionPublicKey ??= Base64Codec.encode(await this.enclave.ready());
Object.assign(
record,
await this.#buildInsertableIDOSCredential(
record.human_id,
record.public_notes,
record.content,
receiverPublicKey, // Encryption
recipientEncryptionPublicKey,
),
);
}
Expand All @@ -291,7 +292,7 @@ export class Data {
async share(
tableName: string,
recordId: string,
receiverPublicKey: string,
granteeEncryptionPublicKey: string,
Mohammed-Mamoun98 marked this conversation as resolved.
Show resolved Hide resolved
synchronous?: boolean,
): Promise<{ id: string }> {
const name = this.singularize(tableName);
Expand All @@ -306,7 +307,7 @@ export class Data {
record.human_id,
"",
record.content,
receiverPublicKey, // Encryption
granteeEncryptionPublicKey,
),
);
}
Expand Down Expand Up @@ -337,15 +338,15 @@ export class Data {
return await this.delete(tableName, recordId, undefined, synchronous);
}

async addWriteGrant(grantee: string, synchronous?: boolean) {
async addWriteGrant(granteeAddress: string, synchronous?: boolean) {
return await this.kwilWrapper.execute(
"add_write_grant",
[
{
wg_grantee: grantee,
wg_grantee: granteeAddress,
},
],
`Grant ${grantee} write access to your idOS credentials`,
`Grant ${granteeAddress} write access to your idOS credentials`,
synchronous,
);
}
Expand All @@ -354,8 +355,8 @@ export class Data {
return await this.kwilWrapper.call("has_write_grant_given_by", { human_id: humanId });
}

async hasWriteGrantGivenTo(grantee: string) {
return await this.kwilWrapper.call("has_write_grant_given_to", { grantee });
async hasWriteGrantGivenTo(granteeAddress: string) {
return await this.kwilWrapper.call("has_write_grant_given_to", { grantee: granteeAddress });
}

async #buildInsertableIDOSCredential(
Expand Down
Loading
Loading