Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Mamoun98 committed Dec 17, 2024
2 parents 9a47613 + 2582f15 commit 83dd5e0
Show file tree
Hide file tree
Showing 32 changed files with 298 additions and 270 deletions.
8 changes: 3 additions & 5 deletions apps/dashboard-for-dapps/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function CredentialDetails({

if (!credential.data || !secretKey) return null;

const result = decrypt(credential.data.content, credential.data.encryption_public_key, secretKey);
const result = decrypt(credential.data.content, credential.data.encryptor_public_key, secretKey);
const content = JSON.parse(result);

const subject = Object.entries(content.credentialSubject).filter(
Expand Down Expand Up @@ -328,8 +328,6 @@ function CredentialDetails({
<List.Item
flexShrink="0"
key={key}
// biome-ignore lint/a11y/useSemanticElements: <explanation>
role="button"
transition="transform 0.2s"
cursor="pointer"
_hover={{ transform: "scale(1.02)" }}
Expand Down Expand Up @@ -426,7 +424,7 @@ function SearchResults({
pt="4"
grow
label="Owner"
value={grant.owner}
value={grant.ownerAddress}
truncate
/>
<DataListItem
Expand All @@ -441,7 +439,7 @@ function SearchResults({
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;

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
16 changes: 6 additions & 10 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) {
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 @@ -250,18 +250,14 @@ export class Enclave {
}
}

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

async filterCredentialsByCountries(credentials, countries) {
const decrypted = await Promise.all(
credentials.map(async (credential) => ({
...credential,
content: Utf8Codec.decode(
await this.decrypt(
Base64Codec.decode(credential.content),
Base64Codec.decode(credential.encryption_public_key),
Base64Codec.decode(credential.encryptor_public_key),
),
),
})),
Expand All @@ -287,7 +283,7 @@ export class Enclave {
content: Utf8Codec.decode(
await this.decrypt(
Base64Codec.decode(credential.content),
Base64Codec.decode(credential.encryption_public_key),
Base64Codec.decode(credential.encryptor_public_key),
),
),
})),
Expand Down Expand Up @@ -331,7 +327,7 @@ export class Enclave {
receiverPublicKey,
senderPublicKey,
signerAddress,
signerPublicKey,
signerEncryptionPublicKey,
mode,
theme,
credentials,
Expand All @@ -354,7 +350,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,
});

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 @@ -293,7 +293,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 }),
);
cache.set("grants", grants);

Expand Down
2 changes: 1 addition & 1 deletion examples/issuer-sdk-demo/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function createProfile(
wallet: CreateWalletReqParams,
) {
const issuer = await getIssuerConfig();
await createHuman(issuer, { id: humanId, current_public_key: publicKey }, wallet);
await createHuman(issuer, { id: humanId, recipient_encryption_public_key: publicKey }, wallet);
}

export async function createCredentialByWriteGrant(
Expand Down
6 changes: 3 additions & 3 deletions examples/issuer-sdk-demo/src/components/create-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function CreateProfile({ onSuccess }: { onSuccess: () => void }) {
if (!idOSSDK) throw new Error("No SDK found");
setLoadingMessage("Creating user password...");
const humanId = crypto.randomUUID();
const { encryptionPublicKey } =
await idOSSDK.enclave.provider.discoverUserEncryptionKey(humanId);
const { userEncryptionPublicKey } =
await idOSSDK.enclave.discoverUserEncryptionPublicKey(humanId);

setLoadingMessage("Signing message on your wallet...");

Expand All @@ -31,7 +31,7 @@ export function CreateProfile({ onSuccess }: { onSuccess: () => void }) {

setLoadingMessage("Creating your profile...");

await createProfile(encryptionPublicKey, humanId, {
await createProfile(userEncryptionPublicKey, humanId, {
address: address as string,
signature,
message,
Expand Down
18 changes: 9 additions & 9 deletions packages/grantee-sdk-js/src/idOS-grantee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const buildKwilSignerAndGrantee = (
};

interface idOSGranteeInitParams {
encryptionSecret: string;
encryptionPrivateKey: string;
nodeUrl?: string;
chainId?: string;
dbId?: string;
Expand All @@ -109,7 +109,7 @@ export class idOSGrantee {
grants?: GrantChild;

static async init(_: {
encryptionSecret: string;
encryptionPrivateKey: string;
nodeUrl?: string;
chainId?: string;
dbId?: string;
Expand All @@ -119,7 +119,7 @@ export class idOSGrantee {
}): Promise<idOSGrantee>;

static async init(_: {
encryptionSecret: string;
encryptionPrivateKey: string;
nodeUrl?: string;
chainId?: string;
dbId?: string;
Expand All @@ -129,7 +129,7 @@ export class idOSGrantee {
}): Promise<idOSGrantee>;

static async init({
encryptionSecret,
encryptionPrivateKey,
nodeUrl = KwilWrapper.defaults.kwilProvider,
chainId,
dbId,
Expand Down Expand Up @@ -173,7 +173,7 @@ export class idOSGrantee {
}

return new idOSGrantee(
NoncedBox.fromBase64SecretKey(encryptionSecret),
NoncedBox.fromBase64SecretKey(encryptionPrivateKey),
nodeKwil,
kwilSigner,
dbId,
Expand Down Expand Up @@ -220,12 +220,12 @@ export class idOSGrantee {
async getSharedCredentialContentDecrypted(dataId: string): Promise<string> {
const credentialCopy = await this.fetchSharedCredentialFromIdos<{
content: string;
encryption_public_key: string;
encryptor_public_key: string;
}>(dataId);

return await this.noncedBox.decrypt(
credentialCopy.content,
credentialCopy.encryption_public_key,
credentialCopy.encryptor_public_key,
);
}

Expand All @@ -250,8 +250,8 @@ export class idOSGrantee {
if (!this.grants) throw new Error("NEAR is not implemented yet");

return this.grants.list({
owner: address,
grantee: this.grantee,
ownerAddress: address,
granteeAddress: this.grantee,
});
}

Expand Down
12 changes: 6 additions & 6 deletions packages/grantee-sdk-js/src/idOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ export class idOS {

static async init(
chainType: "EVM" | "NEAR",
privateKey: string,
encryptionSecretKey: string,
authnPrivateKey: string,
encryptionPrivateKey: string,
nodeUrl: string,
) {
let grantee: idOSGrantee;

switch (chainType) {
case "EVM": {
const signer = new ethers.Wallet(privateKey, new JsonRpcProvider(nodeUrl));
const signer = new ethers.Wallet(authnPrivateKey, new JsonRpcProvider(nodeUrl));
grantee = await idOSGrantee.init({
chainType,
granteeSigner: signer,
encryptionSecret: encryptionSecretKey,
encryptionPrivateKey,
});
return new idOS(grantee);
}
case "NEAR": {
const signer = KeyPair.fromString(privateKey);
const signer = KeyPair.fromString(authnPrivateKey);
grantee = await idOSGrantee.init({
chainType,
granteeSigner: signer,
encryptionSecret: privateKey,
encryptionPrivateKey: authnPrivateKey,
});
return new idOS(grantee);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/idos-sdk-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const credential = await idos.data.get(

const content = await idos.enclave.decrypt(
credential.content,
credential.encryption_public_key,
credential.encryptor_public_key,
)
```

Expand Down
7 changes: 3 additions & 4 deletions packages/idos-sdk-js/src/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ describe("auth", () => {
beforeEach(() => {
auth = new Auth(new KwilWrapper(new TestKwilClient()), new Store());

auth.kwilWrapper.getHumanId = vi.fn().mockResolvedValue("human-id");
auth.kwilWrapper.getHumanProfile = vi.fn().mockResolvedValue({
current_public_key: currentUserPublicKey,
recipient_encryption_public_key: currentUserPublicKey,
id: humanId,
});
auth.kwilWrapper.client.auth.logout = vi.fn().mockResolvedValue(void 0);
Expand All @@ -33,14 +32,14 @@ describe("auth", () => {

test("should set a user from an EVM signer", async () => {
const signer = Wallet.createRandom();
const address = await signer.getAddress();
const userAddress = await signer.getAddress();

await auth.setEvmSigner(signer);

expect(auth.currentUser).toEqual({
humanId,
currentUserPublicKey,
address,
userAddress,
});
});

Expand Down
Loading

0 comments on commit 83dd5e0

Please sign in to comment.