From 372025b912243e8bd6f9999f8c9a6b935feccc17 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Tue, 3 Dec 2024 11:52:29 +0200 Subject: [PATCH 01/23] feat: refactor `granteeEnryptionPublicKey` and `nearWalletPublicKey` --- packages/idos-sdk-js/src/lib/auth.ts | 11 +++++++++-- packages/idos-sdk-js/src/lib/enclave.ts | 7 ++++++- packages/idos-sdk-js/src/lib/grants/grants.ts | 17 +++++++++-------- packages/idos-sdk-js/src/lib/grants/near.ts | 6 +++--- packages/idos-sdk-js/src/lib/idos.ts | 3 +-- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/auth.ts b/packages/idos-sdk-js/src/lib/auth.ts index 8d7fbc5f9..b67d8b168 100644 --- a/packages/idos-sdk-js/src/lib/auth.ts +++ b/packages/idos-sdk-js/src/lib/auth.ts @@ -15,7 +15,14 @@ import { implicitAddressFromPublicKey } from "./utils"; export interface AuthUser { humanId: string | null; address: string; - publicKey?: 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. + */ currentUserPublicKey?: string; } @@ -209,7 +216,7 @@ export class Auth { humanId: id, currentUserPublicKey: current_public_key, address: currentAddress, - publicKey, + nearWalletPublicKey: publicKey, }; } } diff --git a/packages/idos-sdk-js/src/lib/enclave.ts b/packages/idos-sdk-js/src/lib/enclave.ts index 275d4ee41..0eb02b6f8 100644 --- a/packages/idos-sdk-js/src/lib/enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave.ts @@ -18,7 +18,12 @@ export class Enclave { } async ready(): Promise { - const { humanId, address, publicKey, currentUserPublicKey } = this.auth.currentUser; + const { + humanId, + address, + nearWalletPublicKey: publicKey, + currentUserPublicKey, + } = this.auth.currentUser; if (!humanId) throw new Error("Can't operate on a user that has no profile."); diff --git a/packages/idos-sdk-js/src/lib/grants/grants.ts b/packages/idos-sdk-js/src/lib/grants/grants.ts index 7ac4b6693..ba66a5fff 100644 --- a/packages/idos-sdk-js/src/lib/grants/grants.ts +++ b/packages/idos-sdk-js/src/lib/grants/grants.ts @@ -55,24 +55,24 @@ export class Grants { type, signer, accountId, - publicKey, + nearWalletPublicKey, }: { type: "NEAR"; signer: Wallet; accountId: string; - publicKey: string; + nearWalletPublicKey: string; }): Promise; async connect({ type, signer, accountId, - publicKey, + nearWalletPublicKey, }: { type: SignerType; signer: Wallet | Signer; accountId?: string; - publicKey?: string; + nearWalletPublicKey?: string; }): Promise { let child: EvmGrants | NearGrants; @@ -82,12 +82,13 @@ export class Grants { break; case "NEAR": if (accountId === undefined) throw new Error("accountId required for NEAR signers"); - if (publicKey === undefined) throw new Error("publicKey required for NEAR signers"); + if (nearWalletPublicKey === undefined) + throw new Error("publicKey required for NEAR signers"); child = await NearGrants.init({ accountId, signer: signer as Wallet, options: this.nearGrantsOptions, - publicKey, + nearWalletPublicKey, }); break; default: @@ -169,9 +170,9 @@ class ConnectedGrants extends Grants { recordId: string, address: string, lockedUntil: number, - receiverPublicKey: string, + granteeEncryptionPublicKey: string, ): Promise<{ grant: Grant; transactionId: string }> { - const share = await this.data.share(tableName, recordId, receiverPublicKey); + const share = await this.data.share(tableName, recordId, granteeEncryptionPublicKey); return await this.#child.create({ grantee: address, diff --git a/packages/idos-sdk-js/src/lib/grants/near.ts b/packages/idos-sdk-js/src/lib/grants/near.ts index 33426e229..2e2b6eb21 100644 --- a/packages/idos-sdk-js/src/lib/grants/near.ts +++ b/packages/idos-sdk-js/src/lib/grants/near.ts @@ -50,12 +50,12 @@ export class NearGrants implements GrantChild { accountId, signer, options, - publicKey, + nearWalletPublicKey, }: { accountId: string; signer: Wallet; options: NearGrantsOptions; - publicKey: string; + nearWalletPublicKey: string; }): Promise { let near_api: { Contract: typeof Contract; @@ -95,7 +95,7 @@ export class NearGrants implements GrantChild { // biome-ignore lint/suspicious/noExplicitAny: fix `useLocalViewExecution` is not in types. } as any, ), - publicKey, + nearWalletPublicKey, ); } diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index 47b7c5af0..8aae10c1c 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -84,8 +84,7 @@ export class idOS { type, accountId: currentUser.address, signer: signer as Wallet, - // biome-ignore lint/style/noNonNullAssertion: we put it there when we're using NEAR. - publicKey: currentUser.publicKey!, + nearWalletPublicKey: currentUser.nearWalletPublicKey ?? "", }); return currentUser; From 89c3fedcdd5bf4bff6811172d57c12a20fe3afc0 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Tue, 3 Dec 2024 15:07:48 +0200 Subject: [PATCH 02/23] feat: change `receiverPublicKey` to `recipientEncryptionPublicKey` --- packages/idos-sdk-js/src/lib/data.ts | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/data.ts b/packages/idos-sdk-js/src/lib/data.ts index bce1570f3..22c66869d 100644 --- a/packages/idos-sdk-js/src/lib/data.ts +++ b/packages/idos-sdk-js/src/lib/data.ts @@ -78,10 +78,11 @@ 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, @@ -89,7 +90,7 @@ export class Data { record.human_id, record.public_notes, record.content, - receiverPublicKey, // Encryption + recipientEncryptionPublicKey, ), ); } @@ -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) @@ -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, ), ); } @@ -261,19 +262,19 @@ export class Data { ): Promise { if (!this.enclave.encryptionPublicKey) 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, ), ); } @@ -291,7 +292,7 @@ export class Data { async share( tableName: string, recordId: string, - receiverPublicKey: string, + granteeEncryptionPublicKey: string, synchronous?: boolean, ): Promise<{ id: string }> { const name = this.singularize(tableName); @@ -306,7 +307,7 @@ export class Data { record.human_id, "", record.content, - receiverPublicKey, // Encryption + granteeEncryptionPublicKey, ), ); } @@ -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, ); } @@ -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( From 5ff1742eb8c494b99eb33f25e800e25990cfd080 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Tue, 3 Dec 2024 21:28:39 +0200 Subject: [PATCH 03/23] feat: additional changes to key arguments --- packages/idos-sdk-js/src/lib/data.ts | 2 +- .../lib/enclave-providers/iframe-enclave.ts | 8 +++-- .../metamask-snap-enclave.ts | 4 +-- .../src/lib/enclave-providers/types.ts | 6 ++-- packages/idos-sdk-js/src/lib/enclave.ts | 32 +++++++++++-------- packages/idos-sdk-js/src/lib/idos.ts | 2 +- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/data.ts b/packages/idos-sdk-js/src/lib/data.ts index 22c66869d..60e5ec5e9 100644 --- a/packages/idos-sdk-js/src/lib/data.ts +++ b/packages/idos-sdk-js/src/lib/data.ts @@ -260,7 +260,7 @@ export class Data { description?: string, synchronous?: boolean, ): Promise { - if (!this.enclave.encryptionPublicKey) await this.enclave.ready(); + if (!this.enclave.userEncryptionPublicKey) await this.enclave.ready(); let recipientEncryptionPublicKey: string | undefined; // biome-ignore lint/suspicious/noExplicitAny: using any to avoid type errors for now. diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts index ce34de948..11b432231 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts @@ -2,7 +2,7 @@ import type { idOSCredential } from "@idos-network/idos-sdk-types"; import * as Base64Codec from "@stablelib/base64"; import type { BackupPasswordInfo } from "../types"; import type { - DiscoverEncryptionKeyResponse, + DiscoverUserEncryptionPublicKeyResponse, EnclaveOptions, EnclaveProvider, StoredData, @@ -226,9 +226,11 @@ export class IframeEnclave implements EnclaveProvider { } } - async discoverUserEncryptionKey(humanId: string): Promise { + async discoverUserEncryptionPublicKey( + humanId: string, + ): Promise { if (this.options.mode !== "new") - throw new Error("You can only call discoverUserEncryptionKey when mode is 'new'."); + throw new Error("You can only call `discoverUserEncryptionPublicKey` when mode is `new`."); const encryptionPublicKey = await this.ready(humanId); diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts index afbe9c08f..ff24e6dbc 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts @@ -1,5 +1,5 @@ import type { idOSCredential } from "@idos-network/idos-sdk-types"; -import type { DiscoverEncryptionKeyResponse, EnclaveProvider, StoredData } from "./types"; +import type { DiscoverUserEncryptionPublicKeyResponse, EnclaveProvider, StoredData } from "./types"; export class MetaMaskSnapEnclave implements EnclaveProvider { // biome-ignore lint/suspicious/noExplicitAny: Types will be added later @@ -19,7 +19,7 @@ export class MetaMaskSnapEnclave implements EnclaveProvider { throw new Error("Method not implemented."); } - async discoverUserEncryptionKey(): Promise { + async discoverUserEncryptionPublicKey(): Promise { throw new Error("Method not implemented."); } diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts index 8b08f3a59..5826dda4e 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts @@ -8,7 +8,7 @@ export interface StoredData { signerPublicKey?: string; } -export interface DiscoverEncryptionKeyResponse { +export interface DiscoverUserEncryptionPublicKeyResponse { humanId: string; encryptionPublicKey: string; } @@ -36,7 +36,9 @@ export interface EnclaveProvider { updateStore(key: string, value: unknown): Promise; encrypt(message: Uint8Array, receiverPublicKey?: Uint8Array): Promise; decrypt(message: Uint8Array, senderPublicKey?: Uint8Array): Promise; - discoverUserEncryptionKey(humanId: string): Promise; + discoverUserEncryptionPublicKey( + humanId: string, + ): Promise; filterCredentialsByCountries( credentials: Record[], countries: string[], diff --git a/packages/idos-sdk-js/src/lib/enclave.ts b/packages/idos-sdk-js/src/lib/enclave.ts index 0eb02b6f8..113210954 100644 --- a/packages/idos-sdk-js/src/lib/enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave.ts @@ -6,7 +6,7 @@ import type { EnclaveProvider } from "./enclave-providers/types"; import type { BackupPasswordInfo } from "./types"; export class Enclave { - encryptionPublicKey?: Uint8Array; + userEncryptionPublicKey?: Uint8Array; constructor( public readonly auth: Auth, @@ -33,36 +33,40 @@ export class Enclave { await this.provider.updateStore("litAttrs", litAttrs); await this.provider.updateStore("new-user-wallets", userWallets); - if (this.encryptionPublicKey) return this.encryptionPublicKey; + if (this.userEncryptionPublicKey) return this.userEncryptionPublicKey; - this.encryptionPublicKey = await this.provider.ready( + this.userEncryptionPublicKey = await this.provider.ready( humanId, address, publicKey, currentUserPublicKey, ); - return this.encryptionPublicKey; + return this.userEncryptionPublicKey; } - async encrypt(message: string, receiverPublicKey?: string): Promise { - if (!this.encryptionPublicKey) await this.ready(); + async encrypt(message: string, recipientEncryptionPublicKey?: string): Promise { + if (!this.userEncryptionPublicKey) await this.ready(); return Base64Codec.encode( await this.provider.encrypt( Utf8Codec.encode(message), - receiverPublicKey === undefined ? undefined : Base64Codec.decode(receiverPublicKey), + recipientEncryptionPublicKey === undefined + ? undefined + : Base64Codec.decode(recipientEncryptionPublicKey), ), ); } - async decrypt(message: string, senderPublicKey?: string): Promise { - if (!this.encryptionPublicKey) await this.ready(); + async decrypt(message: string, senderEncryptionPublicKey?: string): Promise { + if (!this.userEncryptionPublicKey) await this.ready(); return Utf8Codec.decode( await this.provider.decrypt( Base64Codec.decode(message), - senderPublicKey === undefined ? undefined : Base64Codec.decode(senderPublicKey), + senderEncryptionPublicKey === undefined + ? undefined + : Base64Codec.decode(senderEncryptionPublicKey), ), ); } @@ -80,7 +84,7 @@ export class Enclave { } async filterCredentialsByCountries(credentials: Record[], countries: string[]) { - if (!this.encryptionPublicKey) await this.ready(); + if (!this.userEncryptionPublicKey) await this.ready(); return await this.provider.filterCredentialsByCountries(credentials, countries); } @@ -91,7 +95,7 @@ export class Enclave { omit: Record; }, ): Promise { - if (!this.encryptionPublicKey) await this.ready(); + if (!this.userEncryptionPublicKey) await this.ready(); return await this.provider.filterCredentials(credentials, privateFieldFilters); } @@ -101,7 +105,7 @@ export class Enclave { return this.provider.backupPasswordOrSecret(callbackFn); } - async discoverUserEncryptionKey(humanId: string) { - return this.provider.discoverUserEncryptionKey(humanId); + async discoverUserEncryptionPublicKey(humanId: string) { + return this.provider.discoverUserEncryptionPublicKey(humanId); } } diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index 8aae10c1c..e66f9d2a4 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -234,6 +234,6 @@ export class idOS { } async discoverEncryptionKey(humanId: string) { - return this.enclave.discoverUserEncryptionKey(humanId); + return this.enclave.discoverUserEncryptionPublicKey(humanId); } } From 9d5d6aad509af9259af278bf27b9165652b0f591 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Wed, 4 Dec 2024 10:05:08 +0200 Subject: [PATCH 04/23] feat: change `discoverEncryptionKey` to `discoverUserEncryptionPublicKey` --- .../src/lib/enclave-providers/iframe-enclave.ts | 8 ++++---- packages/idos-sdk-js/src/lib/idos.ts | 2 +- packages/issuer-sdk-js/README.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts index 11b432231..52439e34d 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts @@ -37,7 +37,7 @@ export class IframeEnclave implements EnclaveProvider { signerPublicKey?: string, expectedUserEncryptionPublicKey?: string, ): Promise { - let { encryptionPublicKey } = (await this.#requestToEnclave({ + let { encryptionPublicKey: userEncryptionPublicKey } = (await this.#requestToEnclave({ storage: { humanId, signerAddress, @@ -46,10 +46,10 @@ export class IframeEnclave implements EnclaveProvider { }, })) as StoredData; - while (!encryptionPublicKey) { + while (!userEncryptionPublicKey) { this.#showEnclave(); try { - encryptionPublicKey = (await this.#requestToEnclave({ + userEncryptionPublicKey = (await this.#requestToEnclave({ keys: {}, })) as Uint8Array; } catch (e) { @@ -59,7 +59,7 @@ export class IframeEnclave implements EnclaveProvider { } } - return encryptionPublicKey; + return userEncryptionPublicKey; } async store(key: string, value: string): Promise { diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index e66f9d2a4..b95d24765 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -233,7 +233,7 @@ export class idOS { }); } - async discoverEncryptionKey(humanId: string) { + async discoverUserEncryptionPublicKey(humanId: string) { return this.enclave.discoverUserEncryptionPublicKey(humanId); } } diff --git a/packages/issuer-sdk-js/README.md b/packages/issuer-sdk-js/README.md index 38300a55a..3dda9e55e 100644 --- a/packages/issuer-sdk-js/README.md +++ b/packages/issuer-sdk-js/README.md @@ -79,7 +79,7 @@ const idos = await idOS.init(...); const { humanId } = await yourServer.getIdosInformation(); // Discover user encryption key -const { encryptionPublicKey } = await idos.discoverEncryptionKey(humanId); +const { encryptionPublicKey } = await idos.discoverUserEncryptionPublicKey(humanId); // Report it back to your server await yourServer.reportIdosEncryptionPublicKey(encryptionPublicKey); From c2840e423edee3f84c0bae0386956e2876435785 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Wed, 4 Dec 2024 10:06:20 +0200 Subject: [PATCH 05/23] fix: update dashboard to use new namings --- apps/idos-data-dashboard/src/core/idos/idos-provider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/idos-data-dashboard/src/core/idos/idos-provider.tsx b/apps/idos-data-dashboard/src/core/idos/idos-provider.tsx index a63e800e1..4d043fa4b 100644 --- a/apps/idos-data-dashboard/src/core/idos/idos-provider.tsx +++ b/apps/idos-data-dashboard/src/core/idos/idos-provider.tsx @@ -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); } From 61a94b2d835a91a8e3fb354fe5fb3db895d7d221 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Wed, 4 Dec 2024 13:40:04 +0200 Subject: [PATCH 06/23] docs: update README --- packages/issuer-sdk-js/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/issuer-sdk-js/README.md b/packages/issuer-sdk-js/README.md index 3dda9e55e..bfe12a53c 100644 --- a/packages/issuer-sdk-js/README.md +++ b/packages/issuer-sdk-js/README.md @@ -63,7 +63,7 @@ return { humanId } #### Step 2: Derive the Public Key -Use the `idos.discoverEncryptionKey` function to derive a public key for the human. This key will be used to encrypt and decrypt human's credential content. +Use the `idos.discoverUserEncryptionPublicKey` function to derive a public key for the human. This key will be used to encrypt and decrypt human's credential content. ```javascript // Client side From 1782e2a9beed695b3081cafa737a5302d24d4aa6 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 14:38:31 +0200 Subject: [PATCH 07/23] feat(client-sdk): update key names in enclave provider --- .../src/lib/enclave-providers/iframe-enclave.ts | 12 ++++++------ .../idos-sdk-js/src/lib/enclave-providers/types.ts | 14 +++++++------- packages/idos-sdk-js/src/lib/enclave.ts | 9 ++------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts index 52439e34d..cb86e3dea 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts @@ -34,14 +34,14 @@ export class IframeEnclave implements EnclaveProvider { async ready( humanId?: string, signerAddress?: string, - signerPublicKey?: string, + signerEncryptionPublicKey?: string, expectedUserEncryptionPublicKey?: string, ): Promise { - let { encryptionPublicKey: userEncryptionPublicKey } = (await this.#requestToEnclave({ + let { userEncryptionPublicKey } = (await this.#requestToEnclave({ storage: { humanId, signerAddress, - signerPublicKey, + signerEncryptionPublicKey, expectedUserEncryptionPublicKey, }, })) as StoredData; @@ -113,7 +113,7 @@ export class IframeEnclave implements EnclaveProvider { async #loadEnclave() { const hasIframe = document.getElementById(this.iframe.id); if (hasIframe) { - console.warn("An Iframe already exists in the container"); + console.warn("An iframe already exists in the container"); return Promise.resolve(); } @@ -232,11 +232,11 @@ export class IframeEnclave implements EnclaveProvider { if (this.options.mode !== "new") throw new Error("You can only call `discoverUserEncryptionPublicKey` when mode is `new`."); - const encryptionPublicKey = await this.ready(humanId); + const userEncryptionPublicKey = await this.ready(humanId); return { humanId, - encryptionPublicKey: Base64Codec.encode(encryptionPublicKey), + userEncryptionPublicKey: Base64Codec.encode(userEncryptionPublicKey), }; } } diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts index 5826dda4e..2a2d78d14 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts @@ -2,15 +2,15 @@ import type { idOSCredential } from "@idos-network/idos-sdk-types"; import type { BackupPasswordInfo } from "../types"; export interface StoredData { - encryptionPublicKey?: Uint8Array; + userEncryptionPublicKey?: Uint8Array; humanId?: string; signerAddress?: string; - signerPublicKey?: string; + signerEncryptionPublicKey?: string; } export interface DiscoverUserEncryptionPublicKeyResponse { humanId: string; - encryptionPublicKey: string; + userEncryptionPublicKey: string; } export interface EnclaveOptions { @@ -27,15 +27,15 @@ export interface EnclaveProvider { ready( humanId?: string, signerAddress?: string, - signerPublicKey?: string, - currentUserPublicKey?: string, + signerEncryptionPublicKey?: string, + currentUserEncryptionPublicKey?: string, ): Promise; store(key: string, value: string): Promise; reset(): Promise; confirm(message: string): Promise; updateStore(key: string, value: unknown): Promise; - encrypt(message: Uint8Array, receiverPublicKey?: Uint8Array): Promise; - decrypt(message: Uint8Array, senderPublicKey?: Uint8Array): Promise; + encrypt(message: Uint8Array, recipientEncryptionPublicKey?: Uint8Array): Promise; + decrypt(message: Uint8Array, senderEncryptionPublicKey?: Uint8Array): Promise; discoverUserEncryptionPublicKey( humanId: string, ): Promise; diff --git a/packages/idos-sdk-js/src/lib/enclave.ts b/packages/idos-sdk-js/src/lib/enclave.ts index 113210954..bf3fb32b4 100644 --- a/packages/idos-sdk-js/src/lib/enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave.ts @@ -18,12 +18,7 @@ export class Enclave { } async ready(): Promise { - const { - humanId, - address, - nearWalletPublicKey: publicKey, - currentUserPublicKey, - } = this.auth.currentUser; + const { humanId, address, nearWalletPublicKey, currentUserPublicKey } = this.auth.currentUser; if (!humanId) throw new Error("Can't operate on a user that has no profile."); @@ -38,7 +33,7 @@ export class Enclave { this.userEncryptionPublicKey = await this.provider.ready( humanId, address, - publicKey, + nearWalletPublicKey, currentUserPublicKey, ); From 5a21782372a935d4e36b175d2147964442abbda5 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 14:48:32 +0200 Subject: [PATCH 08/23] featy(enclave: update variable names --- apps/idos-enclave/src/lib/enclave.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/idos-enclave/src/lib/enclave.js b/apps/idos-enclave/src/lib/enclave.js index c435d2d3b..20325023b 100644 --- a/apps/idos-enclave/src/lib/enclave.js +++ b/apps/idos-enclave/src/lib/enclave.js @@ -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); @@ -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) => ({ @@ -329,7 +325,7 @@ export class Enclave { receiverPublicKey, senderPublicKey, signerAddress, - signerPublicKey, + signerEncryptionPublicKey, mode, theme, credentials, @@ -352,7 +348,7 @@ export class Enclave { storage: () => [ humanId, signerAddress, - signerPublicKey, + signerEncryptionPublicKey, expectedUserEncryptionPublicKey, litAttrs, userWallets, From b78b5751159fc9483bd5d59899382976cd4479b4 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 15:07:46 +0200 Subject: [PATCH 09/23] feat(client-sdk): update AuthUser type --- packages/idos-sdk-js/src/lib/auth.ts | 6 +++--- packages/idos-sdk-js/src/lib/enclave.ts | 5 +++-- packages/idos-sdk-js/src/lib/idos.ts | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/auth.ts b/packages/idos-sdk-js/src/lib/auth.ts index b67d8b168..3167bd1b4 100644 --- a/packages/idos-sdk-js/src/lib/auth.ts +++ b/packages/idos-sdk-js/src/lib/auth.ts @@ -14,7 +14,7 @@ import { implicitAddressFromPublicKey } from "./utils"; export interface AuthUser { humanId: string | null; - address: 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. @@ -79,7 +79,7 @@ export class Auth { this.user = { humanId: id, currentUserPublicKey: current_public_key, - address: currentAddress, + userAddress: currentAddress, }; } @@ -215,7 +215,7 @@ export class Auth { this.user = { humanId: id, currentUserPublicKey: current_public_key, - address: currentAddress, + userAddress: currentAddress, nearWalletPublicKey: publicKey, }; } diff --git a/packages/idos-sdk-js/src/lib/enclave.ts b/packages/idos-sdk-js/src/lib/enclave.ts index bf3fb32b4..90d914d25 100644 --- a/packages/idos-sdk-js/src/lib/enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave.ts @@ -18,7 +18,8 @@ export class Enclave { } async ready(): Promise { - const { humanId, address, nearWalletPublicKey, currentUserPublicKey } = this.auth.currentUser; + const { humanId, userAddress, nearWalletPublicKey, currentUserPublicKey } = + this.auth.currentUser; if (!humanId) throw new Error("Can't operate on a user that has no profile."); @@ -32,7 +33,7 @@ export class Enclave { this.userEncryptionPublicKey = await this.provider.ready( humanId, - address, + userAddress, nearWalletPublicKey, currentUserPublicKey, ); diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index b95d24765..9de02c8c2 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -82,7 +82,7 @@ export class idOS { const currentUser = this.auth.currentUser; this.grants = await this.grants.connect({ type, - accountId: currentUser.address, + accountId: currentUser.userAddress, signer: signer as Wallet, nearWalletPublicKey: currentUser.nearWalletPublicKey ?? "", }); From 545b1489be2b98d4aee08ba7e9366b69de886082 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 16:29:25 +0200 Subject: [PATCH 10/23] feat(client-sdk): update grants var names --- packages/idos-sdk-js/src/lib/grants/evm.ts | 80 ++++++++++++------- .../idos-sdk-js/src/lib/grants/grant-child.ts | 4 +- packages/idos-sdk-js/src/lib/grants/grant.ts | 10 +-- packages/idos-sdk-js/src/lib/grants/grants.ts | 38 +++++---- packages/idos-sdk-js/src/lib/grants/near.ts | 62 +++++++------- 5 files changed, 113 insertions(+), 81 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/grants/evm.ts b/packages/idos-sdk-js/src/lib/grants/evm.ts index c3661cd97..03e12e316 100644 --- a/packages/idos-sdk-js/src/lib/grants/evm.ts +++ b/packages/idos-sdk-js/src/lib/grants/evm.ts @@ -403,8 +403,8 @@ export class EvmGrants implements GrantChild { } async list({ - owner = ZERO_ADDRESS, - grantee = ZERO_ADDRESS, + ownerAddress: owner = ZERO_ADDRESS, + granteeAddress: grantee = ZERO_ADDRESS, dataId = ZERO_DATA_ID, }: Partial> = {}): Promise { if (owner === ZERO_ADDRESS && grantee === ZERO_ADDRESS) @@ -414,12 +414,17 @@ export class EvmGrants implements GrantChild { return grants.map( ([owner, grantee, dataId, lockedUntil]: [string, string, string, bigint]) => - new Grant({ owner, grantee, dataId, lockedUntil: Number(lockedUntil) }), + new Grant({ + ownerAddress: owner, + granteeAddress: grantee, + dataId, + lockedUntil: Number(lockedUntil), + }), ); } async create({ - grantee = ZERO_ADDRESS, + granteeAddress = ZERO_ADDRESS, dataId = ZERO_DATA_ID, lockedUntil = ZERO_TIMELOCK, wait = true, @@ -427,17 +432,22 @@ export class EvmGrants implements GrantChild { grant: Grant; transactionId: string; }> { - if (grantee === ZERO_ADDRESS || dataId === ZERO_DATA_ID) { + if (granteeAddress === ZERO_ADDRESS || dataId === ZERO_DATA_ID) { throw new Error("Must provide `grantee` and `dataId`"); } - const owner = await this.signer.getAddress(); - const grant: Grant = { owner, grantee, dataId, lockedUntil }; + const ownerAddress = await this.signer.getAddress(); + const grant: Grant = { + ownerAddress, + granteeAddress, + dataId, + lockedUntil, + }; let transaction: TransactionResponse; try { transaction = (await this.#contract.insertGrant( - grantee, + granteeAddress, dataId, lockedUntil, )) as TransactionResponse; @@ -448,17 +458,22 @@ export class EvmGrants implements GrantChild { } async messageForCreateBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, }: Grant): Promise { - return await this.#contract.insertGrantBySignatureMessage(owner, grantee, dataId, lockedUntil); + return await this.#contract.insertGrantBySignatureMessage( + ownerAddress, + granteeAddress, + dataId, + lockedUntil, + ); } async createBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, @@ -467,13 +482,13 @@ export class EvmGrants implements GrantChild { grant: Grant; transactionId: string; }> { - const grant: Grant = { owner, grantee, dataId, lockedUntil }; + const grant: Grant = { ownerAddress, granteeAddress, dataId, lockedUntil }; let transaction: TransactionResponse; try { transaction = (await this.#contract.insertGrantBySignature( - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, @@ -485,25 +500,25 @@ export class EvmGrants implements GrantChild { } async revoke({ - grantee = ZERO_ADDRESS, + granteeAddress = ZERO_ADDRESS, dataId = ZERO_DATA_ID, lockedUntil = ZERO_TIMELOCK, wait = true, - }: Omit & { wait?: boolean }): Promise<{ + }: Omit & { wait?: boolean }): Promise<{ grant: Grant; transactionId: string; }> { - if (grantee === ZERO_ADDRESS || dataId === ZERO_DATA_ID) { + if (granteeAddress === ZERO_ADDRESS || dataId === ZERO_DATA_ID) { throw new Error("Must provide `grantee` and `dataId`"); } - const owner = await this.signer.getAddress(); - const grant: Grant = { owner, grantee, dataId, lockedUntil }; + const ownerAddress = await this.signer.getAddress(); + const grant: Grant = { ownerAddress, granteeAddress, dataId, lockedUntil }; let transaction: TransactionResponse; try { transaction = (await this.#contract.deleteGrant( - grantee, + granteeAddress, dataId, lockedUntil, )) as TransactionResponse; @@ -515,17 +530,22 @@ export class EvmGrants implements GrantChild { } async messageForRevokeBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, }: Grant): Promise { - return await this.#contract.deleteGrantBySignatureMessage(owner, grantee, dataId, lockedUntil); + return await this.#contract.deleteGrantBySignatureMessage( + ownerAddress, + granteeAddress, + dataId, + lockedUntil, + ); } async revokeBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, @@ -534,13 +554,13 @@ export class EvmGrants implements GrantChild { grant: Grant; transactionId: string; }> { - const grant: Grant = { owner, grantee, dataId, lockedUntil }; + const grant: Grant = { ownerAddress, granteeAddress, dataId, lockedUntil }; let transaction: TransactionResponse; try { transaction = (await this.#contract.deleteGrantBySignature( - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, diff --git a/packages/idos-sdk-js/src/lib/grants/grant-child.ts b/packages/idos-sdk-js/src/lib/grants/grant-child.ts index 16564e2f2..9d9e041b3 100644 --- a/packages/idos-sdk-js/src/lib/grants/grant-child.ts +++ b/packages/idos-sdk-js/src/lib/grants/grant-child.ts @@ -3,7 +3,7 @@ import type Grant from "./grant"; export interface GrantChild { list(_: Partial>): Promise; create( - _: Omit & { wait?: boolean }, + _: Omit & { wait?: boolean }, ): Promise<{ grant: Grant; transactionId: string }>; messageForCreateBySignature(_: Grant): Promise; createBySignature(_: Grant & { signature: Uint8Array; wait?: boolean }): Promise<{ @@ -11,7 +11,7 @@ export interface GrantChild { transactionId: string; }>; revoke( - _: Omit & { wait?: boolean }, + _: Omit & { wait?: boolean }, ): Promise<{ grant: Grant; transactionId: string }>; messageForRevokeBySignature(_: Grant): Promise; revokeBySignature(_: Grant & { signature: Uint8Array; wait?: boolean }): Promise<{ diff --git a/packages/idos-sdk-js/src/lib/grants/grant.ts b/packages/idos-sdk-js/src/lib/grants/grant.ts index 4b4428c19..64d876e91 100644 --- a/packages/idos-sdk-js/src/lib/grants/grant.ts +++ b/packages/idos-sdk-js/src/lib/grants/grant.ts @@ -1,12 +1,12 @@ export default class Grant { - owner: string; - grantee: string; + ownerAddress: string; + granteeAddress: string; dataId: string; lockedUntil: number; - constructor({ owner, grantee, dataId, lockedUntil }: Grant) { - this.owner = owner; - this.grantee = grantee; + constructor({ ownerAddress, granteeAddress, dataId, lockedUntil }: Grant) { + this.ownerAddress = ownerAddress; + this.granteeAddress = granteeAddress; this.dataId = dataId; this.lockedUntil = lockedUntil; } diff --git a/packages/idos-sdk-js/src/lib/grants/grants.ts b/packages/idos-sdk-js/src/lib/grants/grants.ts index ba66a5fff..5a334a866 100644 --- a/packages/idos-sdk-js/src/lib/grants/grants.ts +++ b/packages/idos-sdk-js/src/lib/grants/grants.ts @@ -100,8 +100,8 @@ export class Grants { async list( _args: { - owner?: string; - grantee?: string; + ownerAddress?: string; + granteeAddress?: string; dataId?: string; } = {}, ): Promise { @@ -113,19 +113,19 @@ export class Grants { _recordId: string, _address: string, _lockedUntil: number, - _receiverPublicKey: string, + _receiverEncryptionPublicKey: string, ): Promise<{ grant: Grant; transactionId: string }> { - throw new Error("Call idOS.setSigner first."); + throw new Error("Call `idOS.setSigner` first."); } async revoke( _tableName: string, _recordId: string, - _grantee: string, + _granteeAddress: string, _dataId: string, _lockedUntil: number, ): Promise<{ grant: Grant; transactionId: string }> { - throw new Error("Call idOS.setSigner first."); + throw new Error("Call `idOS.setSigner` first."); } async shareMatchingEntry( @@ -135,11 +135,11 @@ export class Grants { pick: Record; omit: Record; }, - _address: string, + _granteeAddress: string, _lockedUntil: number, - _receiverPublicKey: string, + _receiverEncryptionPublicKey: string, ): Promise<{ grant: Grant; transactionId: string }> { - throw new Error("Call idOS.setSigner first."); + throw new Error("Call `idOS.setSigner` first."); } } @@ -168,14 +168,14 @@ class ConnectedGrants extends Grants { async create( tableName: string, recordId: string, - address: string, + granteeAddress: string, lockedUntil: number, granteeEncryptionPublicKey: string, ): Promise<{ grant: Grant; transactionId: string }> { const share = await this.data.share(tableName, recordId, granteeEncryptionPublicKey); return await this.#child.create({ - grantee: address, + granteeAddress, dataId: share.id, lockedUntil: lockedUntil, }); @@ -188,9 +188,9 @@ class ConnectedGrants extends Grants { pick: Record; omit: Record; }, - address: string, + granteeAddress: string, lockedUntil: number, - receiverPublicKey: string, + receiverEncryptionPublicKey: string, ): Promise<{ grant: Grant; transactionId: string }> { const allEntries = (await this.data.list(tableName)) as unknown as idOSCredential[]; @@ -226,10 +226,14 @@ class ConnectedGrants extends Grants { if (!eligibleEntries.length) throw new Error("No matching credentials"); const selectedEntry = eligibleEntries[0]; - const { id: dataId } = await this.data.share(tableName, selectedEntry.id, receiverPublicKey); + const { id: dataId } = await this.data.share( + tableName, + selectedEntry.id, + receiverEncryptionPublicKey, + ); return await this.#child.create({ - grantee: address, + granteeAddress, dataId, lockedUntil, }); @@ -238,13 +242,13 @@ class ConnectedGrants extends Grants { async revoke( tableName: string, recordId: string, - grantee: string, + granteeAddress: string, dataId: string, lockedUntil: number, ): Promise<{ grant: Grant; transactionId: string }> { await this.data.unshare(tableName, recordId); - return this.#child.revoke({ grantee, dataId, lockedUntil }); + return this.#child.revoke({ granteeAddress, dataId, lockedUntil }); } async messageForCreateBySignature(grant: Grant) { diff --git a/packages/idos-sdk-js/src/lib/grants/near.ts b/packages/idos-sdk-js/src/lib/grants/near.ts index 2e2b6eb21..8405564f0 100644 --- a/packages/idos-sdk-js/src/lib/grants/near.ts +++ b/packages/idos-sdk-js/src/lib/grants/near.ts @@ -107,8 +107,8 @@ export class NearGrants implements GrantChild { return { grant: { - owner: grant.owner, - grantee: grant.grantee, + ownerAddress: grant.owner, + granteeAddress: grant.grantee, lockedUntil: grant.locked_until, dataId: grant.data_id, }, @@ -141,8 +141,8 @@ export class NearGrants implements GrantChild { } async list({ - owner, - grantee, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, }: Partial> = {}): Promise { if (!(owner || grantee)) throw new Error("Must provide `owner` and/or `grantee`"); @@ -159,9 +159,11 @@ export class NearGrants implements GrantChild { ) => Promise; return (await method(grantsFilter)).map( - ({ data_id, locked_until, ...values }) => + ({ data_id, locked_until, owner, grantee, ...values }) => new Grant({ ...values, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, lockedUntil: locked_until / 1e6, }), @@ -173,16 +175,19 @@ export class NearGrants implements GrantChild { /// NOTE: NEAR is problematic for the current implementation. The only way to create an AG in the contract if to /// create an dAG for yourself. async create({ - grantee, + granteeAddress, dataId, lockedUntil, - }: Omit & { wait?: boolean }): Promise<{ grant: Grant; transactionId: string }> { - const owner = this.#publicKey; + }: Omit & { wait?: boolean }): Promise<{ + grant: Grant; + transactionId: string; + }> { + const ownerAddress = this.#publicKey; const recipient = await this.messageRecipient(); const message = await this.messageForCreateBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, }); @@ -190,8 +195,8 @@ export class NearGrants implements GrantChild { const { nonce, signature } = await this.#sign(message, recipient); return this.createBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, @@ -209,8 +214,8 @@ export class NearGrants implements GrantChild { } async messageForCreateBySignature({ - owner, - grantee, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, lockedUntil, }: Grant): Promise { @@ -230,8 +235,8 @@ export class NearGrants implements GrantChild { } async createBySignature({ - owner, - grantee, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, lockedUntil, signature, @@ -282,16 +287,19 @@ export class NearGrants implements GrantChild { /// NOTE: NEAR is problematic for the current implementation. The only way to revoke an AG in the contract if to /// create an dAG for yourself. async revoke({ - grantee, + granteeAddress, dataId, lockedUntil, - }: Omit & { wait?: boolean }): Promise<{ grant: Grant; transactionId: string }> { - const owner = this.#publicKey; + }: Omit & { wait?: boolean }): Promise<{ + grant: Grant; + transactionId: string; + }> { + const ownerAddress = this.#publicKey; const recipient = await this.messageRecipient(); const message = await this.messageForRevokeBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, }); @@ -299,8 +307,8 @@ export class NearGrants implements GrantChild { const { nonce, signature } = await this.#sign(message, recipient); return this.revokeBySignature({ - owner, - grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil, signature, @@ -309,8 +317,8 @@ export class NearGrants implements GrantChild { } async messageForRevokeBySignature({ - owner, - grantee, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, lockedUntil, }: Grant): Promise { @@ -330,8 +338,8 @@ export class NearGrants implements GrantChild { } async revokeBySignature({ - owner, - grantee, + ownerAddress: owner, + granteeAddress: grantee, dataId: data_id, lockedUntil, signature, From 09068a0a987ee7e650572f28343107becf339f78 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 18:43:30 +0200 Subject: [PATCH 11/23] feat(types): update idOSGrant type --- .../dashboard/credentials/components/grants-center.tsx | 6 +++--- .../src/routes/dashboard/credentials/shared/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/grants-center.tsx b/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/grants-center.tsx index c13c4ccb1..42de32d4d 100644 --- a/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/grants-center.tsx +++ b/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/grants-center.tsx @@ -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 { @@ -96,7 +96,7 @@ const Shares = ({ credentialId, grants }: { credentialId: string; grants: idOSGr data-grant={JSON.stringify(grant)} > - {grant.grantee} + {grant.granteeAddress} {grant.lockedUntil ? timelockToDate(grant.lockedUntil) : "-"} diff --git a/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts b/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts index 1b6eb0ac9..7e4786567 100644 --- a/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts +++ b/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts @@ -9,11 +9,11 @@ export const useFetchGrants = ({ credentialId }: { credentialId: string }) => { const queryClient = useQueryClient(); const credentials = queryClient.getQueryData(["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 []; From b1a626f292789a89e3120db180d686ff5ac83e96 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 18:46:59 +0200 Subject: [PATCH 12/23] feat(dashboard): update grants functionality --- .../dashboard/credentials/components/delete-credential.tsx | 4 ++-- .../src/routes/dashboard/credentials/shared/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/delete-credential.tsx b/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/delete-credential.tsx index 15643eff0..28f603964 100644 --- a/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/delete-credential.tsx +++ b/apps/idos-data-dashboard/src/routes/dashboard/credentials/components/delete-credential.tsx @@ -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); @@ -172,7 +172,7 @@ export const DeleteCredential = ({ isOpen, credential, onClose }: DeleteCredenti <> Revoking grant for grantee: - {grantee} + {granteeAddress} ) : deleteCredential.isPending ? ( diff --git a/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts b/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts index 7e4786567..dc64d432c 100644 --- a/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts +++ b/apps/idos-data-dashboard/src/routes/dashboard/credentials/shared/index.ts @@ -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 = From 3023b9cc7f786e6dae31c196ff934ced2a600ed3 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Thu, 5 Dec 2024 18:57:36 +0200 Subject: [PATCH 13/23] feat(types): update idOSGrant types --- packages/types/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/types/index.ts b/packages/types/index.ts index e2be9995e..15b9aa2c4 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -16,8 +16,8 @@ export interface idOSCredential { } export interface idOSGrant { - owner: string; - grantee: string; + ownerAddress: string; + granteeAddress: string; dataId: string; lockedUntil: number; } From 50363bfce068f552ca5b22eeb87d23d6f3f36f7c Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Fri, 6 Dec 2024 11:40:19 +0200 Subject: [PATCH 14/23] feat: update `hasProfile` signature --- packages/idos-sdk-js/src/lib/idos.ts | 4 ++-- packages/idos-sdk-js/src/lib/kwil-wrapper.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index 9de02c8c2..e58ffa6cb 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -101,8 +101,8 @@ export class idOS { return assertNever(type, `Signer type "${type}" not recognized`); } - async hasProfile(address: string): Promise { - return this.kwilWrapper.hasProfile(address); + async hasProfile(user: string): Promise { + return this.kwilWrapper.hasProfile(user); } async reset({ enclave = false } = {}): Promise { diff --git a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts index 0ffbf5bf1..e0a398efa 100644 --- a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts +++ b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts @@ -142,9 +142,9 @@ export class KwilWrapper { return human; } - async hasProfile(address: string): Promise { + async hasProfile(user: string): Promise { // biome-ignore lint/suspicious/noExplicitAny: TBD - const result = (await this.call("has_profile", { address }, undefined, false)) as any; + const result = (await this.call("has_profile", { address: user }, undefined, false)) as any; return !!result[0]?.has_profile; } From 9f76ed5d823bc2317a71c9c065d98152947ba2c1 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Fri, 6 Dec 2024 11:47:44 +0200 Subject: [PATCH 15/23] feat(dashboard-dapps): update with latest sdk changes --- apps/dashboard-for-dapps/src/routes/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/dashboard-for-dapps/src/routes/index.tsx b/apps/dashboard-for-dapps/src/routes/index.tsx index 465463430..9d06d1246 100644 --- a/apps/dashboard-for-dapps/src/routes/index.tsx +++ b/apps/dashboard-for-dapps/src/routes/index.tsx @@ -74,7 +74,7 @@ const useFetchGrants = () => { queryKey: ["grants"], queryFn: () => idOS.grants.list({ - grantee: address, + granteeAddress: address, }), select: (data) => data.map((grant) => ({ @@ -331,7 +331,6 @@ function CredentialDetails({ Date: Fri, 6 Dec 2024 12:00:19 +0200 Subject: [PATCH 16/23] feat(example-dapp): update to match latest grant sharing changes --- examples/idos-example-dapp/src/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/idos-example-dapp/src/main.js b/examples/idos-example-dapp/src/main.js index eeca74685..432f5b164 100644 --- a/examples/idos-example-dapp/src/main.js +++ b/examples/idos-example-dapp/src/main.js @@ -305,7 +305,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); From 3ba21bd8c42318f37ddadea9e39c72beca02eebd Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Fri, 6 Dec 2024 12:25:30 +0200 Subject: [PATCH 17/23] feat(server-dapp-sdk): update namings --- packages/idos-sdk-server-dapp/src/idOS-grantee.ts | 14 +++++++------- packages/idos-sdk-server-dapp/src/idOS.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts index 94b987544..34ec1323d 100644 --- a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts +++ b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts @@ -86,7 +86,7 @@ const buildKwilSignerAndGrantee = ( }; interface idOSGranteeInitParams { - encryptionSecret: string; + encryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -109,7 +109,7 @@ export class idOSGrantee { grants?: GrantChild; static async init(_: { - encryptionSecret: string; + encryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -119,7 +119,7 @@ export class idOSGrantee { }): Promise; static async init(_: { - encryptionSecret: string; + encryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -129,7 +129,7 @@ export class idOSGrantee { }): Promise; static async init({ - encryptionSecret, + encryptionPrivateKey, nodeUrl = KwilWrapper.defaults.kwilProvider, chainId, dbId, @@ -173,7 +173,7 @@ export class idOSGrantee { } return new idOSGrantee( - NoncedBox.fromBase64SecretKey(encryptionSecret), + NoncedBox.fromBase64SecretKey(encryptionPrivateKey), nodeKwil, kwilSigner, dbId, @@ -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, }); } diff --git a/packages/idos-sdk-server-dapp/src/idOS.ts b/packages/idos-sdk-server-dapp/src/idOS.ts index 11439338f..6ad0f8939 100644 --- a/packages/idos-sdk-server-dapp/src/idOS.ts +++ b/packages/idos-sdk-server-dapp/src/idOS.ts @@ -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); } From ed736120ceb6c3828bb73acae3b426b61dded512 Mon Sep 17 00:00:00 2001 From: Fernando Gonzalez Goncharov Date: Fri, 6 Dec 2024 14:05:58 +0200 Subject: [PATCH 18/23] feat(example-dapp): proper `idOSGrantee` initialisation --- examples/idos-example-dapp/api/EVM.ts | 2 +- examples/idos-example-dapp/api/NEAR.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/idos-example-dapp/api/EVM.ts b/examples/idos-example-dapp/api/EVM.ts index 166ae81ac..14b6fc593 100644 --- a/examples/idos-example-dapp/api/EVM.ts +++ b/examples/idos-example-dapp/api/EVM.ts @@ -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; diff --git a/examples/idos-example-dapp/api/NEAR.ts b/examples/idos-example-dapp/api/NEAR.ts index e0cbbfee9..4e0ef185d 100644 --- a/examples/idos-example-dapp/api/NEAR.ts +++ b/examples/idos-example-dapp/api/NEAR.ts @@ -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; From a67ca8077017b413c07aaaec58856698ad316bb2 Mon Sep 17 00:00:00 2001 From: Paulo Koch Date: Fri, 13 Dec 2024 11:20:55 +0000 Subject: [PATCH 19/23] Fix naming --- examples/issuer-sdk-demo/src/components/create-profile.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/issuer-sdk-demo/src/components/create-profile.tsx b/examples/issuer-sdk-demo/src/components/create-profile.tsx index a447e9ed9..223375c70 100644 --- a/examples/issuer-sdk-demo/src/components/create-profile.tsx +++ b/examples/issuer-sdk-demo/src/components/create-profile.tsx @@ -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.provider.discoverUserEncryptionPublicKey(humanId); setLoadingMessage("Signing message on your wallet..."); @@ -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, From 7706e5d4c9a24c82302289fab9978ba30020015b Mon Sep 17 00:00:00 2001 From: Paulo Koch Date: Fri, 13 Dec 2024 11:59:42 +0000 Subject: [PATCH 20/23] Rename human to user --- apps/idos-enclave/src/lib/enclave.js | 21 ++++---- .../idos-enclave/src/lib/idOSKeyDerivation.ts | 2 +- apps/idos-enclave/src/pages/App.tsx | 10 ++-- .../src/pages/methods/Password.tsx | 7 +-- .../src/creds2.integration.test.ts | 20 +++---- examples/issuer-sdk-demo/src/actions/index.ts | 14 ++--- examples/issuer-sdk-demo/src/app/page.tsx | 4 +- .../src/components/create-profile.tsx | 6 +-- packages/idos-sdk-js/README.md | 4 +- .../idos-sdk-js/src/__tests__/auth.test.ts | 10 ++-- packages/idos-sdk-js/src/lib/auth.ts | 10 ++-- packages/idos-sdk-js/src/lib/data.ts | 18 +++---- .../lib/enclave-providers/iframe-enclave.ts | 10 ++-- .../metamask-snap-enclave.ts | 4 +- .../src/lib/enclave-providers/types.ts | 10 ++-- packages/idos-sdk-js/src/lib/enclave.ts | 10 ++-- packages/idos-sdk-js/src/lib/idos.ts | 16 +++--- packages/idos-sdk-js/src/lib/kwil-wrapper.ts | 18 +++---- packages/issuer-sdk-js/README.md | 52 +++++++++---------- .../issuer-sdk-js/assets/add-user.drawio.svg | 30 +++++------ packages/issuer-sdk-js/package.json | 6 +-- packages/issuer-sdk-js/src/credentials.ts | 8 +-- packages/issuer-sdk-js/src/index.ts | 2 +- .../issuer-sdk-js/src/{human.ts => user.ts} | 30 +++++------ packages/issuer-sdk-js/tsup.config.ts | 2 +- packages/types/index.ts | 10 ++-- 26 files changed, 165 insertions(+), 169 deletions(-) rename packages/issuer-sdk-js/src/{human.ts => user.ts} (69%) diff --git a/apps/idos-enclave/src/lib/enclave.js b/apps/idos-enclave/src/lib/enclave.js index 579ba4c26..332a63ad4 100644 --- a/apps/idos-enclave/src/lib/enclave.js +++ b/apps/idos-enclave/src/lib/enclave.js @@ -48,8 +48,8 @@ export class Enclave { }); } - storage(humanId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey) { - humanId && this.store.set("human-id", humanId); + storage(userId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey) { + userId && this.store.set("user-id", userId); signerAddress && this.store.set("signer-address", signerAddress); signerEncryptionPublicKey && this.store.set("signer-public-key", signerEncryptionPublicKey); @@ -59,11 +59,11 @@ export class Enclave { const storeWithCodec = this.store.pipeCodec(Base64Codec); this.expectedUserEncryptionPublicKey = expectedUserEncryptionPublicKey; - this.humanId = humanId; + this.userId = userId; if (!this.isAuthorizedOrigin) { return { - humanId: "", + userId: "", encryptionPublicKey: "", signerAddress: "", signerPublicKey: "", @@ -71,7 +71,8 @@ export class Enclave { } return { - humanId: this.humanId ?? this.store.get("human-id"), + // TODO Remove human-user migration code. + userId: this.userId ?? this.store.get("user-id") ?? this.store.get("human-id"), encryptionPublicKey: storeWithCodec.get("encryption-public-key"), signerAddress: this.store.get("signer-address"), signerPublicKey: this.store.get("signer-public-key"), @@ -156,7 +157,7 @@ export class Enclave { async ensureKeyPair() { const password = this.store.get("password"); - const salt = this.humanId; + const salt = this.userId; const storeWithCodec = this.store.pipeCodec(Base64Codec); @@ -321,7 +322,7 @@ export class Enclave { const [requestName, requestData] = Object.entries(event.data).flat(); const { fullMessage, - humanId, + userId, message, receiverPublicKey, senderPublicKey, @@ -347,7 +348,7 @@ export class Enclave { reset: () => [], configure: () => [mode, theme], storage: () => [ - humanId, + userId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey, @@ -396,7 +397,7 @@ export class Enclave { } async #openDialog(intent, message) { - if (!this.humanId) throw new Error("Can't open dialog without humanId"); + if (!this.userId) throw new Error("Can't open dialog without userId"); const width = 600; const height = this.configuration?.mode === "new" ? 600 : intent === "backupPasswordOrSecret" ? 520 : 400; @@ -412,7 +413,7 @@ export class Enclave { .map((feat) => feat.join("=")) .join(","); - const dialogURL = new URL(`/dialog.html?humanId=${this.humanId}`, window.location.origin); + const dialogURL = new URL(`/dialog.html?userId=${this.userId}`, window.location.origin); this.dialog = window.open(dialogURL, "idos-dialog", popupConfig); await new Promise((resolve) => this.dialog.addEventListener("ready", resolve, { once: true })); diff --git a/apps/idos-enclave/src/lib/idOSKeyDerivation.ts b/apps/idos-enclave/src/lib/idOSKeyDerivation.ts index 0591c8bf2..f43c0e928 100644 --- a/apps/idos-enclave/src/lib/idOSKeyDerivation.ts +++ b/apps/idos-enclave/src/lib/idOSKeyDerivation.ts @@ -6,7 +6,7 @@ import { scrypt } from "scrypt-js"; * Unicode normalization of input strigs * NFKC: compatibility decomposition followed by canonical composition * validateSalt - * UUID v4 format (idOS human IDs) + * UUID v4 format (idOS user IDs) * n, r, p * CPU/RAM cost (higher = costlier) * n: iteration count diff --git a/apps/idos-enclave/src/pages/App.tsx b/apps/idos-enclave/src/pages/App.tsx index 4953c0f82..22d131f6b 100644 --- a/apps/idos-enclave/src/pages/App.tsx +++ b/apps/idos-enclave/src/pages/App.tsx @@ -64,8 +64,8 @@ export function App({ store, enclave }: AppProps) { const [origin, setOrigin] = useState(null); const [message, setMessage] = useState(null); const [encryptionPublicKey, setEncryptionUserPublicKey] = useState(); - const [humanId] = useState( - new URLSearchParams(window.location.search).get("humanId"), + const [userId] = useState( + new URLSearchParams(window.location.search).get("userId"), ); const isRecoveryMode = useSignal(false); @@ -187,11 +187,7 @@ export function App({ store, enclave }: AppProps) { if (method === "password") { return ( - + ); } diff --git a/apps/idos-enclave/src/pages/methods/Password.tsx b/apps/idos-enclave/src/pages/methods/Password.tsx index 9a0624a10..6279d0524 100644 --- a/apps/idos-enclave/src/pages/methods/Password.tsx +++ b/apps/idos-enclave/src/pages/methods/Password.tsx @@ -82,10 +82,10 @@ export function PasswordForm({ onSuccess, store, encryptionPublicKey, - humanId, + userId, }: MethodProps<{ password: string; duration: number }> & { encryptionPublicKey?: string; - humanId: string | null; + userId: string | null; }) { const password = useSignal(""); const duration = useSignal(7); @@ -96,7 +96,8 @@ export function PasswordForm({ const litCipher = store.get("lit-cipher-text"); async function derivePublicKeyFromPassword(password: string) { - const salt = store.get("human-id") || humanId; + // TODO Remove human-user migration code. + const salt = store.get("user-id") || store.get("human-id") || userId; const secretKey = await idOSKeyDerivation({ password, salt }); const keyPair = nacl.box.keyPair.fromSecretKey(secretKey); return encode(keyPair.publicKey); diff --git a/examples/idos-example-dapp/src/creds2.integration.test.ts b/examples/idos-example-dapp/src/creds2.integration.test.ts index 0d97f7571..899f6efe9 100644 --- a/examples/idos-example-dapp/src/creds2.integration.test.ts +++ b/examples/idos-example-dapp/src/creds2.integration.test.ts @@ -63,7 +63,7 @@ const makePublicNotes = (plaintextW3cVc: ReturnType): export const issuer_makeUserCredential = ( idvData: IdvDataResult, - humanId: string, + userId: string, receiverEncryptionPublicKey: Uint8Array, issuerAttestationSecretKey: Uint8Array, ) => { @@ -74,7 +74,7 @@ export const issuer_makeUserCredential = ( const publicNotes = makePublicNotes(plaintextContent); return { - humanId, + userId, publicNotes: JSON.stringify(publicNotes), plaintextContent: toBytes(plaintextContent), receiverEncryptionPublicKey, @@ -83,7 +83,7 @@ export const issuer_makeUserCredential = ( export const issuer_makeUserCredentialForSharing = ( idvData: IdvDataResult, - humanId: string, + userId: string, receiverEncryptionPublicKey: Uint8Array, issuerAttestationSecretKey: Uint8Array, originalCredentialId: string, @@ -93,7 +93,7 @@ export const issuer_makeUserCredentialForSharing = ( const plaintextContent = makeW3cCredential(idvData, issuerAttestationSecretKey); return { - humanId, + userId, publicNotes: "", plaintextContent: toBytes(plaintextContent), receiverEncryptionPublicKey, @@ -115,7 +115,7 @@ import { shareCredentialByGrant, } from "@idos-network/issuer-sdk-js/credentials"; -const humanId = "bf8709ce-9dfc-11ef-a188-047c16570806"; +const userId = "bf8709ce-9dfc-11ef-a188-047c16570806"; const userEncryptionSecretKey = Base64Codec.decode("nIvx0jPbA8d83rL+I7Vs1B/Fp6pndGtXOX4GDmlEkSQ="); const userEncryptionPublicKey = nacl.box.keyPair.fromSecretKey(userEncryptionSecretKey).publicKey; const _thirdPartyEncryptionSecretKey = Base64Codec.decode( @@ -173,7 +173,7 @@ await (async () => { const issuerConfig = await issuerConfigBuild(); const credential = issuer_makeUserCredential( getIdvData(), - humanId, + userId, userEncryptionPublicKey, issuerAttestationSecretKey, ); @@ -189,7 +189,7 @@ await (async () => { const issuerConfig = await issuerConfigBuild(); const credential = issuer_makeUserCredential( getIdvData(), - humanId, + userId, userEncryptionPublicKey, issuerAttestationSecretKey, ); @@ -207,14 +207,14 @@ await (async () => { issuerConfig, issuer_makeUserCredential( getIdvData(), - humanId, + userId, userEncryptionPublicKey, issuerAttestationSecretKey, ), ); const sharedCredential = issuer_makeUserCredentialForSharing( getIdvData(), - humanId, + userId, thirdPartyEncryptionPublicKey, issuerAttestationSecretKey, insertedCredential.id, @@ -233,7 +233,7 @@ await (async () => { const issuerConfig = await issuerConfigBuild(); const credential = issuer_makeUserCredential( getIdvData(), - humanId, + userId, userEncryptionPublicKey, issuerAttestationSecretKey, ); diff --git a/examples/issuer-sdk-demo/src/actions/index.ts b/examples/issuer-sdk-demo/src/actions/index.ts index 4462cabf2..1086de5a7 100644 --- a/examples/issuer-sdk-demo/src/actions/index.ts +++ b/examples/issuer-sdk-demo/src/actions/index.ts @@ -4,7 +4,7 @@ import { type CreateWalletReqParams, createCredentialByGrant, createCredentialPermissioned, - createHuman, + createUser, editCredential, } from "@idos-network/issuer-sdk-js"; import * as Base64 from "@stablelib/base64"; @@ -65,21 +65,21 @@ const publicNotes = { export async function createProfile( publicKey: string, - humanId: string, + userId: string, wallet: CreateWalletReqParams, ) { const issuer = await getIssuerConfig(); - await createHuman(issuer, { id: humanId, current_public_key: publicKey }, wallet); + await createUser(issuer, { id: userId, current_public_key: publicKey }, wallet); } export async function createCredentialByWriteGrant( - humanId: string, + userId: string, userEncryptionPublicKey: string, ) { const issuer = await getIssuerConfig(); await createCredentialByGrant(issuer, { - humanId, + userId, plaintextContent: vcContent, publicNotes: JSON.stringify({ ...publicNotes, id: crypto.randomUUID() }), receiverEncryptionPublicKey: Base64.decode(userEncryptionPublicKey), @@ -87,13 +87,13 @@ export async function createCredentialByWriteGrant( } export async function createCredentialByPermissionedIssuer( - humanId: string, + userId: string, userEncryptionPublicKey: string, ) { const issuer = await getIssuerConfig(); await createCredentialPermissioned(issuer, { - humanId, + userId, plaintextContent: vcContent, publicNotes: JSON.stringify({ ...publicNotes, id: crypto.randomUUID() }), receiverEncryptionPublicKey: Base64.decode(userEncryptionPublicKey), diff --git a/examples/issuer-sdk-demo/src/app/page.tsx b/examples/issuer-sdk-demo/src/app/page.tsx index fd23e4609..730784b53 100644 --- a/examples/issuer-sdk-demo/src/app/page.tsx +++ b/examples/issuer-sdk-demo/src/app/page.tsx @@ -138,7 +138,7 @@ export default function Home() { try { await createCredentialByWriteGrant( - String(clientSDK.auth.currentUser.humanId), + String(clientSDK.auth.currentUser.userId), clientSDK.auth.currentUser.currentUserPublicKey as string, ); const _credentials = await clientSDK.data.list("credentials"); @@ -150,7 +150,7 @@ export default function Home() { const handleCreateCredential = () => { startCredentialRequestTransition(async () => { await createCredentialByPermissionedIssuer( - String(clientSDK.auth.currentUser.humanId), + String(clientSDK.auth.currentUser.userId), clientSDK.auth.currentUser.currentUserPublicKey as string, ); const _credentials = await clientSDK.data.list("credentials"); diff --git a/examples/issuer-sdk-demo/src/components/create-profile.tsx b/examples/issuer-sdk-demo/src/components/create-profile.tsx index 223375c70..6612be9ee 100644 --- a/examples/issuer-sdk-demo/src/components/create-profile.tsx +++ b/examples/issuer-sdk-demo/src/components/create-profile.tsx @@ -18,9 +18,9 @@ export function CreateProfile({ onSuccess }: { onSuccess: () => void }) { try { if (!idOSSDK) throw new Error("No SDK found"); setLoadingMessage("Creating user password..."); - const humanId = crypto.randomUUID(); + const userId = crypto.randomUUID(); const { userEncryptionPublicKey } = - await idOSSDK.enclave.provider.discoverUserEncryptionPublicKey(humanId); + await idOSSDK.enclave.provider.discoverUserEncryptionPublicKey(userId); setLoadingMessage("Signing message on your wallet..."); @@ -31,7 +31,7 @@ export function CreateProfile({ onSuccess }: { onSuccess: () => void }) { setLoadingMessage("Creating your profile..."); - await createProfile(userEncryptionPublicKey, humanId, { + await createProfile(userEncryptionPublicKey, userId, { address: address as string, signature, message, diff --git a/packages/idos-sdk-js/README.md b/packages/idos-sdk-js/README.md index 5f81e2f99..978cc5a3b 100644 --- a/packages/idos-sdk-js/README.md +++ b/packages/idos-sdk-js/README.md @@ -199,7 +199,7 @@ if (!hasProfile) window.location = "https://kyc-provider.example.com/enroll"; ### The `setSigner` flow and supported wallets ```js -const { humanId } = await idos.setSigner("EVM", signer); +const { userId } = await idos.setSigner("EVM", signer); ``` Besides `hasProfile`, all other queries to idOS nodes require a valid signature. These are performed by your user's wallet, whose signer must be passed to the SDK via the `setSigner` method. Your user's wallet might need to be triggered, so you should be mindful of when in your user's journey you call this method. @@ -517,7 +517,7 @@ const address = (await signer.getAccounts())[0].accountId ```js const hasProfile = await idos.hasProfile(address); if (!hasProfile) window.location = "https://kyc-provider.example.com/enroll"; -const { humanId } = await idos.setSigner(CHAIN_TYPE, signer); +const { userId } = await idos.setSigner(CHAIN_TYPE, signer); ``` ### Credentials diff --git a/packages/idos-sdk-js/src/__tests__/auth.test.ts b/packages/idos-sdk-js/src/__tests__/auth.test.ts index 350a57c26..306532be2 100644 --- a/packages/idos-sdk-js/src/__tests__/auth.test.ts +++ b/packages/idos-sdk-js/src/__tests__/auth.test.ts @@ -6,17 +6,17 @@ import { Store } from "../../../idos-store"; import { TestKwilClient } from "./test-kwil-client"; let auth: Auth; -const humanId = "human-id"; +const userId = "user-id"; const currentUserPublicKey = ""; 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({ + auth.kwilWrapper.getuserId = vi.fn().mockResolvedValue("user-id"); + auth.kwilWrapper.getUserProfile = vi.fn().mockResolvedValue({ current_public_key: currentUserPublicKey, - id: humanId, + id: userId, }); auth.kwilWrapper.client.auth.logout = vi.fn().mockResolvedValue(void 0); auth.kwilWrapper.hasProfile = vi.fn().mockResolvedValue(true); @@ -38,7 +38,7 @@ describe("auth", () => { await auth.setEvmSigner(signer); expect(auth.currentUser).toEqual({ - humanId, + userId, currentUserPublicKey, address, }); diff --git a/packages/idos-sdk-js/src/lib/auth.ts b/packages/idos-sdk-js/src/lib/auth.ts index 3167bd1b4..b63e39ad9 100644 --- a/packages/idos-sdk-js/src/lib/auth.ts +++ b/packages/idos-sdk-js/src/lib/auth.ts @@ -13,7 +13,7 @@ import { Nonce } from "./nonce"; import { implicitAddressFromPublicKey } from "./utils"; export interface AuthUser { - humanId: string | null; + userId: string | null; userAddress: string; /** * The public key of the wallet that was used to sign the message. @@ -74,10 +74,10 @@ export class Auth { signatureType: "secp256k1_ep", }); - const { current_public_key, id } = await this.kwilWrapper.getHumanProfile(); + const { current_public_key, id } = await this.kwilWrapper.getUserProfile(); this.user = { - humanId: id, + userId: id, currentUserPublicKey: current_public_key, userAddress: currentAddress, }; @@ -210,10 +210,10 @@ export class Auth { signatureType: "nep413", }); - const { current_public_key, id } = await this.kwilWrapper.getHumanProfile(); + const { current_public_key, id } = await this.kwilWrapper.getUserProfile(); this.user = { - humanId: id, + userId: id, currentUserPublicKey: current_public_key, userAddress: currentAddress, nearWalletPublicKey: publicKey, diff --git a/packages/idos-sdk-js/src/lib/data.ts b/packages/idos-sdk-js/src/lib/data.ts index ee53e1e55..446ecf716 100644 --- a/packages/idos-sdk-js/src/lib/data.ts +++ b/packages/idos-sdk-js/src/lib/data.ts @@ -87,7 +87,7 @@ export class Data { Object.assign( record, await this.#buildInsertableIDOSCredential( - record.human_id, + record.user_id, record.public_notes, record.content, recipientEncryptionPublicKey, @@ -116,7 +116,7 @@ export class Data { synchronous?: boolean, ): Promise & { id: string }> { const name = `add_${this.singularize( - tableName === "human_attributes" ? "attributes" : tableName, + tableName === "user_attributes" ? "attributes" : tableName, )}`; let recipientEncryptionPublicKey: string | undefined; @@ -136,7 +136,7 @@ export class Data { Object.assign( record, await this.#buildInsertableIDOSCredential( - (record as AnyRecord).human_id, + (record as AnyRecord).user_id, (record as AnyRecord).public_notes, (record as AnyRecord).content, recipientEncryptionPublicKey, @@ -271,7 +271,7 @@ export class Data { Object.assign( record, await this.#buildInsertableIDOSCredential( - record.human_id, + record.user_id, record.public_notes, record.content, recipientEncryptionPublicKey, @@ -304,7 +304,7 @@ export class Data { Object.assign( record, await this.#buildInsertableIDOSCredential( - record.human_id, + record.user_id, "", record.content, granteeEncryptionPublicKey, @@ -351,8 +351,8 @@ export class Data { ); } - async hasWriteGrantGivenBy(humanId: string) { - return await this.kwilWrapper.call("has_write_grant_given_by", { human_id: humanId }); + async hasWriteGrantGivenBy(userId: string) { + return await this.kwilWrapper.call("has_write_grant_given_by", { user_id: userId }); } async hasWriteGrantGivenTo(granteeAddress: string) { @@ -360,7 +360,7 @@ export class Data { } async #buildInsertableIDOSCredential( - humanId: string, + userId: string, publicNotes: string, plaintextContent: string, receiverEncryptionPublicKey: string, @@ -377,7 +377,7 @@ export class Data { ); return { - human_id: humanId, + user_id: userId, content, public_notes: publicNotes, diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts index 603454048..ecf75111e 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts @@ -32,14 +32,14 @@ export class IframeEnclave implements EnclaveProvider { } async ready( - humanId?: string, + userId?: string, signerAddress?: string, signerEncryptionPublicKey?: string, expectedUserEncryptionPublicKey?: string, ): Promise { let { userEncryptionPublicKey } = (await this.#requestToEnclave({ storage: { - humanId, + userId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey, @@ -239,15 +239,15 @@ export class IframeEnclave implements EnclaveProvider { } async discoverUserEncryptionPublicKey( - humanId: string, + userId: string, ): Promise { if (this.options.mode !== "new") throw new Error("You can only call `discoverUserEncryptionPublicKey` when mode is `new`."); - const userEncryptionPublicKey = await this.ready(humanId); + const userEncryptionPublicKey = await this.ready(userId); return { - humanId, + userId, userEncryptionPublicKey: Base64Codec.encode(userEncryptionPublicKey), }; } diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts b/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts index f607182af..08c2b252c 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/metamask-snap-enclave.ts @@ -49,12 +49,12 @@ export class MetaMaskSnapEnclave implements EnclaveProvider { } async ready( - humanId?: string, + userId?: string, signerAddress?: string, signerPublicKey?: string, ): Promise { let { encryptionPublicKey } = JSON.parse( - await this.invokeSnap("storage", { humanId, signerAddress, signerPublicKey }), + await this.invokeSnap("storage", { userId, signerAddress, signerPublicKey }), ); encryptionPublicKey ||= await this.invokeSnap("init"); diff --git a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts index a79aa6eba..19a77b040 100644 --- a/packages/idos-sdk-js/src/lib/enclave-providers/types.ts +++ b/packages/idos-sdk-js/src/lib/enclave-providers/types.ts @@ -3,13 +3,13 @@ import type { BackupPasswordInfo } from "../types"; export interface StoredData { userEncryptionPublicKey?: Uint8Array; - humanId?: string; + userId?: string; signerAddress?: string; signerEncryptionPublicKey?: string; } export interface DiscoverUserEncryptionPublicKeyResponse { - humanId: string; + userId: string; userEncryptionPublicKey: string; } @@ -25,7 +25,7 @@ export interface EnclaveProvider { load(): Promise; ready( - humanId?: string, + userId?: string, signerAddress?: string, signerEncryptionPublicKey?: string, currentUserEncryptionPublicKey?: string, @@ -39,9 +39,7 @@ export interface EnclaveProvider { receiverPublicKey?: Uint8Array, ): Promise<{ content: Uint8Array; encryptorPublicKey: Uint8Array }>; decrypt(message: Uint8Array, senderPublicKey?: Uint8Array): Promise; - discoverUserEncryptionPublicKey( - humanId: string, - ): Promise; + discoverUserEncryptionPublicKey(userId: string): Promise; filterCredentialsByCountries( credentials: Record[], countries: string[], diff --git a/packages/idos-sdk-js/src/lib/enclave.ts b/packages/idos-sdk-js/src/lib/enclave.ts index 4cd6f7bf7..146d9b908 100644 --- a/packages/idos-sdk-js/src/lib/enclave.ts +++ b/packages/idos-sdk-js/src/lib/enclave.ts @@ -18,10 +18,10 @@ export class Enclave { } async ready(): Promise { - const { humanId, userAddress, nearWalletPublicKey, currentUserPublicKey } = + const { userId, userAddress, nearWalletPublicKey, currentUserPublicKey } = this.auth.currentUser; - if (!humanId) throw new Error("Can't operate on a user that has no profile."); + if (!userId) throw new Error("Can't operate on a user that has no profile."); const litAttrs = await this.auth.kwilWrapper.getLitAttrs(); const userWallets = await this.auth.kwilWrapper.getEvmUserWallets(); @@ -32,7 +32,7 @@ export class Enclave { if (this.userEncryptionPublicKey) return this.userEncryptionPublicKey; this.userEncryptionPublicKey = await this.provider.ready( - humanId, + userId, userAddress, nearWalletPublicKey, currentUserPublicKey, @@ -107,7 +107,7 @@ export class Enclave { return this.provider.backupPasswordOrSecret(callbackFn); } - async discoverUserEncryptionPublicKey(humanId: string) { - return this.provider.discoverUserEncryptionPublicKey(humanId); + async discoverUserEncryptionPublicKey(userId: string) { + return this.provider.discoverUserEncryptionPublicKey(userId); } } diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index e58ffa6cb..4f3f60efb 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -1,4 +1,4 @@ -import type { idOSHumanAttribute } from "@idos-network/idos-sdk-types"; +import type { idOSUserAttribute } from "@idos-network/idos-sdk-types"; import type { Wallet } from "@near-wallet-selector/core"; import { isEqual } from "es-toolkit"; import type { Signer } from "ethers"; @@ -115,8 +115,8 @@ export class idOS { return this.kwilWrapper.kwilProvider; } - filterLitAttributes(userAttrs: idOSHumanAttribute[], storableAttributes: StorableAttribute[]) { - const hasLitKey = (attr: idOSHumanAttribute | StorableAttribute) => + filterLitAttributes(userAttrs: idOSUserAttribute[], storableAttributes: StorableAttribute[]) { + const hasLitKey = (attr: idOSUserAttribute | StorableAttribute) => "key" in attr ? attr.key.includes("lit-") : attr.attribute_key.includes("lit-"); return { @@ -125,7 +125,7 @@ export class idOS { }; } async updateAttributesIfNeeded( - filteredUserAttributes: idOSHumanAttribute[], // Arrays here are not safe (it's a string) + filteredUserAttributes: idOSUserAttribute[], // Arrays here are not safe (it's a string) litSavableAttributes: StorableAttribute[], // Arrays here are safe (it's a real array) ): Promise { // biome-ignore lint/suspicious/noAsyncPromiseExecutor: @@ -134,7 +134,7 @@ export class idOS { const userAttrMap = new Map( filteredUserAttributes.map((attr) => [attr.attribute_key, attr]), ); - const attributesToCreate: Omit[] = []; + const attributesToCreate: Omit[] = []; // Helper function to safely parse JSON strings const safeParse = (text: string) => { @@ -223,7 +223,7 @@ export class idOS { ); const userAttrs = ((await this.data.list("attributes")) || - []) as unknown as idOSHumanAttribute[]; + []) as unknown as idOSUserAttribute[]; const { filteredUserAttributes, litSavableAttributes } = this.filterLitAttributes( userAttrs, @@ -233,7 +233,7 @@ export class idOS { }); } - async discoverUserEncryptionPublicKey(humanId: string) { - return this.enclave.discoverUserEncryptionPublicKey(humanId); + async discoverUserEncryptionPublicKey(userId: string) { + return this.enclave.discoverUserEncryptionPublicKey(userId); } } diff --git a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts index e0a398efa..4e5d23276 100644 --- a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts +++ b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts @@ -1,4 +1,4 @@ -import type { idOSHuman, idOSHumanAttribute, idOSWallet } from "@idos-network/idos-sdk-types"; +import type { idOSUser, idOSUserAttribute, idOSWallet } from "@idos-network/idos-sdk-types"; import { KwilSigner, Utils as KwilUtils, WebKwil } from "@kwilteam/kwil-js"; import type { ActionBody, ActionInput } from "@kwilteam/kwil-js/dist/core/action"; import type { CustomSigner, EthSigner } from "@kwilteam/kwil-js/dist/core/builders.d"; @@ -128,18 +128,18 @@ export class KwilWrapper { /** * @deprecated * - * Use {@link KwilWrapper.getHumanProfile} instead. + * Use {@link KwilWrapper.getUserProfile} instead. */ - async getHumanId(): Promise { + async getuserId(): Promise { // biome-ignore lint/suspicious/noExplicitAny: TBD - const result = (await this.call("get_wallet_human_id", {}, "See your idOS profile ID")) as any; + const result = (await this.call("get_wallet_user_id", {}, "See your idOS profile ID")) as any; - return result[0]?.human_id || null; + return result[0]?.user_id || null; } - async getHumanProfile(): Promise { - const [human] = (await this.call("get_human", null)) as unknown as [idOSHuman]; - return human; + async getUserProfile(): Promise { + const [user] = (await this.call("get_user", null)) as unknown as [idOSUser]; + return user; } async hasProfile(user: string): Promise { @@ -150,7 +150,7 @@ export class KwilWrapper { } async getLitAttrs() { - const attrs = (await this.call("get_attributes", null)) as unknown as idOSHumanAttribute[]; + const attrs = (await this.call("get_attributes", null)) as unknown as idOSUserAttribute[]; return attrs.filter((attr) => attr.attribute_key.startsWith("lit-")); } diff --git a/packages/issuer-sdk-js/README.md b/packages/issuer-sdk-js/README.md index 3204380f0..994248327 100644 --- a/packages/issuer-sdk-js/README.md +++ b/packages/issuer-sdk-js/README.md @@ -31,37 +31,37 @@ const issuerConfig = await createIssuerConfig({ }); ``` -## Creating a human profile +## Creating a user profile This procedure can only be done by a Permissioned Issuer. Get in touch with us at engineering@idos.network if you're interested in being one. -To create a human profile in idOS, you need: -1. **A wallet address** associated with the human. +To create a user profile in idOS, you need: +1. **A wallet address** associated with the user. 2. **A public encryption key** derived from either a password or a passkey chosen by the user in the idOS enclave app. -### Human Creation Process -Human Creation Process +### User Creation Process +User Creation Process -#### Step 1: Decide on a human id +#### Step 1: Decide on a user id -Deciding on a human id for a user is an issuer decision. You can use whichever you want, as long as it's an [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier). +Deciding on a user id for a user is an issuer decision. You can use whichever you want, as long as it's an [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier). ```js // Server side -const humanId = crypto.randomUUID(); +const userId = crypto.randomUUID(); // Remember it on your database -session.user.update({ humanId }) +session.user.update({ userId }) // Return it to the front-end to be used in the next step -return { humanId } +return { userId } ``` #### Step 2: Derive the Public Key -Use the `idos.discoverUserEncryptionPublicKey` function to derive a public key for the human. This key will be used to encrypt and decrypt human's credential content. +Use the `idos.discoverUserEncryptionPublicKey` function to derive a public key for the user. This key will be used to encrypt and decrypt user's credential content. ```javascript // Client side @@ -73,36 +73,36 @@ import { idOS } from "@idos-network/idos-sdk-js"; const initParams = { ...YOUR_IDOS_INIT_PARAMS, mode: "new" }; const idos = await idOS.init(...); -// Get humanId associated with this user from your server -const { humanId } = await yourServer.getIdosInformation(); +// Get userId associated with this user from your server +const { userId } = await yourServer.getIdosInformation(); // Discover user encryption key -const { encryptionPublicKey } = await idos.discoverUserEncryptionPublicKey(humanId); +const { encryptionPublicKey } = await idos.discoverUserEncryptionPublicKey(userId); // Report it back to your server await yourServer.reportIdosEncryptionPublicKey(encryptionPublicKey); ``` -#### Step 3: Creating a Human Profile -Once the public key is derived, you can create the human profile in idOS by passing it to the `createHuman` function alongside with human id and the wallet the user's going to use to drive their idOS profile. +#### Step 3: Creating a User Profile +Once the public key is derived, you can create the user profile in idOS by passing it to the `createUser` function alongside with user id and the wallet the user's going to use to drive their idOS profile. ```javascript // Server side -import { createHuman } from "@idos-network/issuer-sdk-js"; +import { createUser } from "@idos-network/issuer-sdk-js"; import issuerConfig from "./issuer-config.js"; // Get this from the user's request, and remember it const currentPublicKey = request.params['userEncryptionPublicKey'] session.user.currentPublicKey = currentPublicKey -// Get the stored human id -const humanId = session.user.humanId +// Get the stored user id +const userId = session.user.userId -// Build the human object -const human = { - id: humanId, +// Build the user object +const user = { + id: userId, current_public_key: currentPublicKey, } @@ -121,7 +121,7 @@ const walletPayload = { } // Create the user on idOS nodes, and get some information back. -const [profile, wallet] = await createHuman(issuerConfig, human, walletPayload); +const [profile, wallet] = await createUser(issuerConfig, user, walletPayload); ``` ## Writing credentials @@ -200,8 +200,8 @@ const credentialContent = JSON.stringify({ const credentialPayload = { id: crypto.randomUUID(), - // user id of the human who is creating the credential. - human_id: session.user.humanId, + // user id of the user who is creating the credential. + user_id: session.user.userId, // The verifiable credential content should be passed as it's seen in the example at https://verifiablecredentials.dev/ usually a stringfied JSON object. // credential content is encrypted, using the Issuer's secret encryption key, along with the receiver's public encryption key. @@ -218,7 +218,7 @@ const credentialPayload = { const credential = await createCredentialByGrant(issuerConfig, credentialPayload); ``` -This will create a credential in the idOS for the given human id. +This will create a credential in the idOS for the given user id. > ⚠️ Notice diff --git a/packages/issuer-sdk-js/assets/add-user.drawio.svg b/packages/issuer-sdk-js/assets/add-user.drawio.svg index caed1428a..b59828e84 100644 --- a/packages/issuer-sdk-js/assets/add-user.drawio.svg +++ b/packages/issuer-sdk-js/assets/add-user.drawio.svg @@ -17,13 +17,13 @@
- Ask for the human id + Ask for the user id
- Ask for the human id + Ask for the user id @@ -40,7 +40,7 @@ discoverUserEncryptionKey
- with the human id (step 2) + with the user id (step 2)
@@ -135,7 +135,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
@@ -154,7 +154,7 @@
- Decide on a human id + Decide on a user id
for this user (step 1)
@@ -163,7 +163,7 @@
- Decide on a human id... + Decide on a user id... @@ -175,7 +175,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
@@ -237,13 +237,13 @@
- Get the human id + Get the user id
- Get the human id + Get the user id @@ -291,7 +291,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
@@ -312,7 +312,7 @@
Call - createHuman + createuser
(step 3) @@ -321,7 +321,7 @@
- Call createHuman... + Call createuser... @@ -414,7 +414,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
@@ -435,7 +435,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
@@ -497,7 +497,7 @@
- %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20human%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E + %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DelbowEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3Belbow%3Dvertical%3Bcurved%3D1%3B%22%20edge%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22215%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22590%22%20y%3D%22235%22%20as%3D%22targetPoint%22%2F%3E%3CArray%20as%3D%22points%22%3E%3CmxPoint%20x%3D%22630%22%20y%3D%22225%22%2F%3E%3C%2FArray%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Decide%20on%20a%20user%20id%26lt%3Bdiv%26gt%3Bfor%20this%20user%26lt%3B%2Fdiv%26gt%3B%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22-0.072%22%20y%3D%22-1%22%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%2221%22%20y%3D%22-26%22%20as%3D%22offset%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
diff --git a/packages/issuer-sdk-js/package.json b/packages/issuer-sdk-js/package.json index 92b3ded0a..3967275f5 100644 --- a/packages/issuer-sdk-js/package.json +++ b/packages/issuer-sdk-js/package.json @@ -28,9 +28,9 @@ "types": "./dist/create-issuer-config.d.ts", "import": "./dist/create-issuer-config.js" }, - "./human": { - "types": "./dist/human.d.ts", - "import": "./dist/human.js" + "./user": { + "types": "./dist/user.d.ts", + "import": "./dist/user.js" }, "./credentials": { "types": "./dist/credentials.d.ts", diff --git a/packages/issuer-sdk-js/src/credentials.ts b/packages/issuer-sdk-js/src/credentials.ts index a0be5c301..b32474d33 100644 --- a/packages/issuer-sdk-js/src/credentials.ts +++ b/packages/issuer-sdk-js/src/credentials.ts @@ -33,12 +33,12 @@ type InsertableIDOSCredential = Omit & { const buildInsertableIDOSCredential = ( issuerConfig: IssuerConfig, { - humanId, + userId, publicNotes, plaintextContent, receiverEncryptionPublicKey, }: { - humanId: string; + userId: string; publicNotes: string; plaintextContent: Uint8Array; receiverEncryptionPublicKey: Uint8Array; @@ -54,7 +54,7 @@ const buildInsertableIDOSCredential = ( }); return { - human_id: humanId, + user_id: userId, content: Base64Codec.encode(content), public_notes, @@ -74,7 +74,7 @@ const buildInsertableIDOSCredential = ( type BaseCredentialParams = { id?: string; - humanId: string; + userId: string; publicNotes: string; plaintextContent: Uint8Array; receiverEncryptionPublicKey: Uint8Array; diff --git a/packages/issuer-sdk-js/src/index.ts b/packages/issuer-sdk-js/src/index.ts index 992947fd9..74cd86aff 100644 --- a/packages/issuer-sdk-js/src/index.ts +++ b/packages/issuer-sdk-js/src/index.ts @@ -1,6 +1,6 @@ export * from "./create-issuer-config"; export * from "./credentials"; -export * from "./human"; +export * from "./user"; // export types. export * from "../../types"; diff --git a/packages/issuer-sdk-js/src/human.ts b/packages/issuer-sdk-js/src/user.ts similarity index 69% rename from packages/issuer-sdk-js/src/human.ts rename to packages/issuer-sdk-js/src/user.ts index de1ae589d..ab208a82e 100644 --- a/packages/issuer-sdk-js/src/human.ts +++ b/packages/issuer-sdk-js/src/user.ts @@ -1,19 +1,19 @@ -import type { idOSHuman, idOSWallet } from "./../../types"; +import type { idOSUser, idOSWallet } from "./../../types"; import type { IssuerConfig } from "./create-issuer-config"; import { createActionInput, ensureEntityId } from "./internal"; -export interface CreateProfileReqParams extends Omit { +export interface CreateProfileReqParams extends Omit { id?: string; } -async function createHumanProfile( +async function createUserProfile( { dbid, kwilClient, kwilSigner }: IssuerConfig, params: CreateProfileReqParams, -): Promise { +): Promise { const payload = ensureEntityId(params); await kwilClient.execute( { - name: "add_human_as_inserter", + name: "add_user_as_inserter", dbid, inputs: [createActionInput(payload)], }, @@ -46,31 +46,31 @@ async function upsertWallet( return payload; } -export interface CreateWalletReqParams extends Omit {} +export interface CreateWalletReqParams extends Omit {} -export async function createHuman( +export async function createUser( config: IssuerConfig, - human: CreateProfileReqParams, + user: CreateProfileReqParams, wallet: CreateWalletReqParams, ) { - const human_id = human.id ?? crypto.randomUUID(); + const user_id = user.id ?? crypto.randomUUID(); const wallet_id = wallet.id ?? crypto.randomUUID(); - const humanReqParams = { - ...human, - id: human_id, + const userReqParams = { + ...user, + id: user_id, }; - const humanResponse = await createHumanProfile(config, humanReqParams); + const userResponse = await createUserProfile(config, userReqParams); const walletReqParams = { ...wallet, - human_id, + user_id, id: wallet_id, }; const walletResponse = await upsertWallet(config, walletReqParams); // @todo: I am not sure if this is the best way to return the response. Need to think about it. - return [humanResponse, walletResponse]; + return [userResponse, walletResponse]; } diff --git a/packages/issuer-sdk-js/tsup.config.ts b/packages/issuer-sdk-js/tsup.config.ts index 56459e097..6aaec382a 100644 --- a/packages/issuer-sdk-js/tsup.config.ts +++ b/packages/issuer-sdk-js/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: [ "./src/index.ts", "./src/create-issuer-config.ts", - "./src/human.ts", + "./src/user.ts", "./src/credentials.ts", ], splitting: false, diff --git a/packages/types/index.ts b/packages/types/index.ts index 15b9aa2c4..634d12e1e 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -1,13 +1,13 @@ export type idOSCredentialStatus = "pending" | "contacted" | "approved" | "rejected" | "expired"; -export interface idOSHuman { +export interface idOSUser { id: string; current_public_key: string; } export interface idOSCredential { id: string; - human_id: string; + user_id: string; issuer_auth_public_key: string; original_id?: string; public_notes: string; @@ -24,7 +24,7 @@ export interface idOSGrant { export interface idOSWallet { id: string; - human_id: string; + user_id: string; address: string; wallet_type: string; message: string; @@ -32,9 +32,9 @@ export interface idOSWallet { signature: string; } -export interface idOSHumanAttribute { +export interface idOSUserAttribute { id: string; - human_id: string; + user_id: string; attribute_key: string; value: string; } From 63bcb070093b71d88ee32f162be0f36e2200a865 Mon Sep 17 00:00:00 2001 From: Mohammed-Mamoun98 Date: Mon, 16 Dec 2024 13:54:10 +0200 Subject: [PATCH 21/23] more PR comments completed --- apps/idos-enclave/src/lib/enclave.js | 4 ++-- examples/idos-example-dapp/api/EVM.ts | 2 +- packages/idos-sdk-js/src/lib/data.ts | 4 ++-- packages/idos-sdk-js/src/lib/grants/evm.ts | 14 +++++++------- packages/idos-sdk-js/src/lib/idos.ts | 4 ++-- packages/idos-sdk-js/src/lib/kwil-wrapper.ts | 4 ++-- packages/idos-sdk-server-dapp/src/idOS-grantee.ts | 8 ++++---- packages/idos-sdk-server-dapp/src/idOS.ts | 6 +++--- packages/issuer-sdk-js/README.md | 4 ++-- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/idos-enclave/src/lib/enclave.js b/apps/idos-enclave/src/lib/enclave.js index 332a63ad4..e4f67fd33 100644 --- a/apps/idos-enclave/src/lib/enclave.js +++ b/apps/idos-enclave/src/lib/enclave.js @@ -48,10 +48,10 @@ export class Enclave { }); } - storage(userId, signerAddress, signerEncryptionPublicKey, expectedUserEncryptionPublicKey) { + storage(userId, signerAddress, userEncryptionPublicKey, expectedUserEncryptionPublicKey) { userId && this.store.set("user-id", userId); signerAddress && this.store.set("signer-address", signerAddress); - signerEncryptionPublicKey && this.store.set("signer-public-key", signerEncryptionPublicKey); + userEncryptionPublicKey && this.store.set("signer-public-key", userEncryptionPublicKey); const litAttrs = this.store.get("litAttrs"); this.handlstoreableAttributes(litAttrs); diff --git a/examples/idos-example-dapp/api/EVM.ts b/examples/idos-example-dapp/api/EVM.ts index 14b6fc593..fc417557d 100644 --- a/examples/idos-example-dapp/api/EVM.ts +++ b/examples/idos-example-dapp/api/EVM.ts @@ -19,7 +19,7 @@ const evmGranteeSigner = new ethers.Wallet( const idosGrantee = await idOSGrantee.init({ chainType: "EVM", granteeSigner: evmGranteeSigner, - encryptionPrivateKey: ENCRYPTION_SECRET_KEY, + recipientEncryptionPrivateKey: ENCRYPTION_SECRET_KEY, }); const encryptionPublicKey = idosGrantee.encryptionPublicKey; diff --git a/packages/idos-sdk-js/src/lib/data.ts b/packages/idos-sdk-js/src/lib/data.ts index 446ecf716..4f798f4e2 100644 --- a/packages/idos-sdk-js/src/lib/data.ts +++ b/packages/idos-sdk-js/src/lib/data.ts @@ -292,7 +292,7 @@ export class Data { async share( tableName: string, recordId: string, - granteeEncryptionPublicKey: string, + granteeRecipientEncryptionPublicKey: string, synchronous?: boolean, ): Promise<{ id: string }> { const name = this.singularize(tableName); @@ -307,7 +307,7 @@ export class Data { record.user_id, "", record.content, - granteeEncryptionPublicKey, + granteeRecipientEncryptionPublicKey, ), ); } diff --git a/packages/idos-sdk-js/src/lib/grants/evm.ts b/packages/idos-sdk-js/src/lib/grants/evm.ts index 03e12e316..e79e5bf87 100644 --- a/packages/idos-sdk-js/src/lib/grants/evm.ts +++ b/packages/idos-sdk-js/src/lib/grants/evm.ts @@ -403,20 +403,20 @@ export class EvmGrants implements GrantChild { } async list({ - ownerAddress: owner = ZERO_ADDRESS, - granteeAddress: grantee = ZERO_ADDRESS, + ownerAddress = ZERO_ADDRESS, + granteeAddress = ZERO_ADDRESS, dataId = ZERO_DATA_ID, }: Partial> = {}): Promise { - if (owner === ZERO_ADDRESS && grantee === ZERO_ADDRESS) + if (ownerAddress === ZERO_ADDRESS && granteeAddress === ZERO_ADDRESS) throw new Error("Must provide `owner` and/or `grantee`"); - const grants = await this.#contract.findGrants(owner, grantee, dataId); + const grants = await this.#contract.findGrants(ownerAddress, granteeAddress, dataId); return grants.map( - ([owner, grantee, dataId, lockedUntil]: [string, string, string, bigint]) => + ([ownerAddress, granteeAddress, dataId, lockedUntil]: [string, string, string, bigint]) => new Grant({ - ownerAddress: owner, - granteeAddress: grantee, + ownerAddress, + granteeAddress, dataId, lockedUntil: Number(lockedUntil), }), diff --git a/packages/idos-sdk-js/src/lib/idos.ts b/packages/idos-sdk-js/src/lib/idos.ts index 4f3f60efb..79f4a92a0 100644 --- a/packages/idos-sdk-js/src/lib/idos.ts +++ b/packages/idos-sdk-js/src/lib/idos.ts @@ -101,8 +101,8 @@ export class idOS { return assertNever(type, `Signer type "${type}" not recognized`); } - async hasProfile(user: string): Promise { - return this.kwilWrapper.hasProfile(user); + async hasProfile(userAddress: string): Promise { + return this.kwilWrapper.hasProfile(userAddress); } async reset({ enclave = false } = {}): Promise { diff --git a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts index 4e5d23276..10bbe9b29 100644 --- a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts +++ b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts @@ -142,9 +142,9 @@ export class KwilWrapper { return user; } - async hasProfile(user: string): Promise { + async hasProfile(userAddress: string): Promise { // biome-ignore lint/suspicious/noExplicitAny: TBD - const result = (await this.call("has_profile", { address: user }, undefined, false)) as any; + const result = (await this.call("has_profile", { address: userAddress }, undefined, false)) as any; return !!result[0]?.has_profile; } diff --git a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts index 34ec1323d..5ddf19b27 100644 --- a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts +++ b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts @@ -86,7 +86,7 @@ const buildKwilSignerAndGrantee = ( }; interface idOSGranteeInitParams { - encryptionPrivateKey: string; + recipientEncryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -109,7 +109,7 @@ export class idOSGrantee { grants?: GrantChild; static async init(_: { - encryptionPrivateKey: string; + recipientEncryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -119,7 +119,7 @@ export class idOSGrantee { }): Promise; static async init(_: { - encryptionPrivateKey: string; + recipientEncryptionPrivateKey: string; nodeUrl?: string; chainId?: string; dbId?: string; @@ -129,7 +129,7 @@ export class idOSGrantee { }): Promise; static async init({ - encryptionPrivateKey, + recipientEncryptionPrivateKey: encryptionPrivateKey, nodeUrl = KwilWrapper.defaults.kwilProvider, chainId, dbId, diff --git a/packages/idos-sdk-server-dapp/src/idOS.ts b/packages/idos-sdk-server-dapp/src/idOS.ts index 6ad0f8939..91d4de440 100644 --- a/packages/idos-sdk-server-dapp/src/idOS.ts +++ b/packages/idos-sdk-server-dapp/src/idOS.ts @@ -11,7 +11,7 @@ export class idOS { static async init( chainType: "EVM" | "NEAR", authnPrivateKey: string, - encryptionPrivateKey: string, + recipientEncryptionPrivateKey: string, nodeUrl: string, ) { let grantee: idOSGrantee; @@ -22,7 +22,7 @@ export class idOS { grantee = await idOSGrantee.init({ chainType, granteeSigner: signer, - encryptionPrivateKey, + recipientEncryptionPrivateKey, }); return new idOS(grantee); } @@ -31,7 +31,7 @@ export class idOS { grantee = await idOSGrantee.init({ chainType, granteeSigner: signer, - encryptionPrivateKey: authnPrivateKey, + recipientEncryptionPrivateKey: authnPrivateKey, }); return new idOS(grantee); } diff --git a/packages/issuer-sdk-js/README.md b/packages/issuer-sdk-js/README.md index 994248327..6d14e5f19 100644 --- a/packages/issuer-sdk-js/README.md +++ b/packages/issuer-sdk-js/README.md @@ -77,10 +77,10 @@ const idos = await idOS.init(...); const { userId } = await yourServer.getIdosInformation(); // Discover user encryption key -const { encryptionPublicKey } = await idos.discoverUserEncryptionPublicKey(userId); +const { userEncryptionPublicKey } = await idos.discoverUserEncryptionPublicKey(userId); // Report it back to your server -await yourServer.reportIdosEncryptionPublicKey(encryptionPublicKey); +await yourServer.reportIdosEncryptionPublicKey(userEncryptionPublicKey); ``` From f676751b26b0cc1902aaa50a1b46e4f15055a26c Mon Sep 17 00:00:00 2001 From: Mohammed-Mamoun98 Date: Mon, 16 Dec 2024 13:56:05 +0200 Subject: [PATCH 22/23] fix format --- packages/idos-sdk-js/src/lib/kwil-wrapper.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts index 10bbe9b29..ae256c97f 100644 --- a/packages/idos-sdk-js/src/lib/kwil-wrapper.ts +++ b/packages/idos-sdk-js/src/lib/kwil-wrapper.ts @@ -144,7 +144,12 @@ export class KwilWrapper { async hasProfile(userAddress: string): Promise { // biome-ignore lint/suspicious/noExplicitAny: TBD - const result = (await this.call("has_profile", { address: userAddress }, undefined, false)) as any; + const result = (await this.call( + "has_profile", + { address: userAddress }, + undefined, + false, + )) as any; return !!result[0]?.has_profile; } From e7a871b4955f5a770ebe6e28bc7c3e40ee25d56e Mon Sep 17 00:00:00 2001 From: Paulo Koch Date: Tue, 17 Dec 2024 11:49:03 +0000 Subject: [PATCH 23/23] Get rid of old encryptionPrivateKey --- examples/idos-example-dapp/api/NEAR.ts | 4 ++-- packages/idos-sdk-server-dapp/src/idOS-grantee.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/idos-example-dapp/api/NEAR.ts b/examples/idos-example-dapp/api/NEAR.ts index 4e0ef185d..89813aa23 100644 --- a/examples/idos-example-dapp/api/NEAR.ts +++ b/examples/idos-example-dapp/api/NEAR.ts @@ -15,7 +15,7 @@ const nearGranteeSigner = KeyPair.fromString(NEAR_GRANTEE_PRIVATE_KEY); const idosGrantee = await idOSGrantee.init({ chainType: "NEAR", granteeSigner: nearGranteeSigner, - encryptionPrivateKey: ENCRYPTION_SECRET_KEY, + recipientEncryptionPrivateKey: ENCRYPTION_SECRET_KEY, }); const encryptionPublicKey = idosGrantee.encryptionPublicKey; @@ -38,7 +38,7 @@ export default async function (request: VercelRequest, response: VercelResponse) } const rawBody = request.read(); - let body; + let body: ReturnType; try { body = JSON.parse(rawBody); } catch (e) { diff --git a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts index 5ddf19b27..546874d23 100644 --- a/packages/idos-sdk-server-dapp/src/idOS-grantee.ts +++ b/packages/idos-sdk-server-dapp/src/idOS-grantee.ts @@ -129,7 +129,7 @@ export class idOSGrantee { }): Promise; static async init({ - recipientEncryptionPrivateKey: encryptionPrivateKey, + recipientEncryptionPrivateKey, nodeUrl = KwilWrapper.defaults.kwilProvider, chainId, dbId, @@ -173,7 +173,7 @@ export class idOSGrantee { } return new idOSGrantee( - NoncedBox.fromBase64SecretKey(encryptionPrivateKey), + NoncedBox.fromBase64SecretKey(recipientEncryptionPrivateKey), nodeKwil, kwilSigner, dbId,