Skip to content

Commit

Permalink
Rename human to user
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoch committed Dec 13, 2024
1 parent a67ca80 commit 7706e5d
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 169 deletions.
21 changes: 11 additions & 10 deletions apps/idos-enclave/src/lib/enclave.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -59,19 +59,20 @@ 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: "",
};
}

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"),
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -321,7 +322,7 @@ export class Enclave {
const [requestName, requestData] = Object.entries(event.data).flat();
const {
fullMessage,
humanId,
userId,
message,
receiverPublicKey,
senderPublicKey,
Expand All @@ -347,7 +348,7 @@ export class Enclave {
reset: () => [],
configure: () => [mode, theme],
storage: () => [
humanId,
userId,
signerAddress,
signerEncryptionPublicKey,
expectedUserEncryptionPublicKey,
Expand Down Expand Up @@ -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;
Expand All @@ -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 }));
Expand Down
2 changes: 1 addition & 1 deletion apps/idos-enclave/src/lib/idOSKeyDerivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions apps/idos-enclave/src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export function App({ store, enclave }: AppProps) {
const [origin, setOrigin] = useState<string | null>(null);
const [message, setMessage] = useState<string | null>(null);
const [encryptionPublicKey, setEncryptionUserPublicKey] = useState<string | undefined>();
const [humanId] = useState<string | null>(
new URLSearchParams(window.location.search).get("humanId"),
const [userId] = useState<string | null>(
new URLSearchParams(window.location.search).get("userId"),
);

const isRecoveryMode = useSignal(false);
Expand Down Expand Up @@ -187,11 +187,7 @@ export function App({ store, enclave }: AppProps) {
if (method === "password") {
return (
<Layout onHeaderClick={resetMethod}>
<PasswordForm
{...methodProps}
encryptionPublicKey={encryptionPublicKey}
humanId={humanId}
/>
<PasswordForm {...methodProps} encryptionPublicKey={encryptionPublicKey} userId={userId} />
</Layout>
);
}
Expand Down
7 changes: 4 additions & 3 deletions apps/idos-enclave/src/pages/methods/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions examples/idos-example-dapp/src/creds2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const makePublicNotes = (plaintextW3cVc: ReturnType<typeof makeW3cCredential>):

export const issuer_makeUserCredential = (
idvData: IdvDataResult,
humanId: string,
userId: string,
receiverEncryptionPublicKey: Uint8Array,
issuerAttestationSecretKey: Uint8Array,
) => {
Expand All @@ -74,7 +74,7 @@ export const issuer_makeUserCredential = (
const publicNotes = makePublicNotes(plaintextContent);

return {
humanId,
userId,
publicNotes: JSON.stringify(publicNotes),
plaintextContent: toBytes(plaintextContent),
receiverEncryptionPublicKey,
Expand All @@ -83,7 +83,7 @@ export const issuer_makeUserCredential = (

export const issuer_makeUserCredentialForSharing = (
idvData: IdvDataResult,
humanId: string,
userId: string,
receiverEncryptionPublicKey: Uint8Array,
issuerAttestationSecretKey: Uint8Array,
originalCredentialId: string,
Expand All @@ -93,7 +93,7 @@ export const issuer_makeUserCredentialForSharing = (
const plaintextContent = makeW3cCredential(idvData, issuerAttestationSecretKey);

return {
humanId,
userId,
publicNotes: "",
plaintextContent: toBytes(plaintextContent),
receiverEncryptionPublicKey,
Expand All @@ -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(
Expand Down Expand Up @@ -173,7 +173,7 @@ await (async () => {
const issuerConfig = await issuerConfigBuild();
const credential = issuer_makeUserCredential(
getIdvData(),
humanId,
userId,
userEncryptionPublicKey,
issuerAttestationSecretKey,
);
Expand All @@ -189,7 +189,7 @@ await (async () => {
const issuerConfig = await issuerConfigBuild();
const credential = issuer_makeUserCredential(
getIdvData(),
humanId,
userId,
userEncryptionPublicKey,
issuerAttestationSecretKey,
);
Expand All @@ -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,
Expand All @@ -233,7 +233,7 @@ await (async () => {
const issuerConfig = await issuerConfigBuild();
const credential = issuer_makeUserCredential(
getIdvData(),
humanId,
userId,
userEncryptionPublicKey,
issuerAttestationSecretKey,
);
Expand Down
14 changes: 7 additions & 7 deletions examples/issuer-sdk-demo/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type CreateWalletReqParams,
createCredentialByGrant,
createCredentialPermissioned,
createHuman,
createUser,
editCredential,
} from "@idos-network/issuer-sdk-js";
import * as Base64 from "@stablelib/base64";
Expand Down Expand Up @@ -65,35 +65,35 @@ 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),
});
}

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),
Expand Down
4 changes: 2 additions & 2 deletions examples/issuer-sdk-demo/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<idOSCredential>("credentials");
Expand All @@ -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<idOSCredential>("credentials");
Expand Down
6 changes: 3 additions & 3 deletions examples/issuer-sdk-demo/src/components/create-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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...");

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/idos-sdk-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions packages/idos-sdk-js/src/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<PUBLIC_KEY>";

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);
Expand All @@ -38,7 +38,7 @@ describe("auth", () => {
await auth.setEvmSigner(signer);

expect(auth.currentUser).toEqual({
humanId,
userId,
currentUserPublicKey,
address,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/idos-sdk-js/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 7706e5d

Please sign in to comment.