Skip to content

Commit

Permalink
Merge branch 'main' of github.com:idos-network/idos-sdk-js into refac…
Browse files Browse the repository at this point in the history
…tor/improve-namings
  • Loading branch information
Mohammed-Mamoun98 committed Dec 11, 2024
2 parents ed73612 + bbff067 commit f485b1f
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
run: pnpm install

- name: Build
run: pnpm build --filter=@idos-network/issuer-sdk-js --filter=@idos-network/idos-sdk
run: pnpm build --filter=@idos-network/issuer-sdk-js --filter=@idos-network/idos-sdk --filter=@idos-network/idos-sdk-server-dapp

- name: Release
run: pnpx pkg-pr-new publish --pnpm './packages/issuer-sdk-js' './packages/idos-sdk-js'
run: pnpx pkg-pr-new publish --pnpm './packages/issuer-sdk-js' './packages/idos-sdk-js' './packages/idos-sdk-server-dapp'

2 changes: 1 addition & 1 deletion apps/idos-data-dashboard/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<ChakraBaseProvider theme={theme}>
<WalletSelectorContextProvider>
{/* @ts-expect-error: TODO: fix wagmi types */}
{/* @ts-ignore: TODO: fix wagmi types */}
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<IDOSProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,7 @@ const useFetchCredentials = () => {
.map((c) => c.id),
})) as idOSCredentialWithShares[]; // @todo: remove once we have more type safety in the SDK.
},
select: (credentials) =>
credentials
.filter((credential) => !credential.original_id)

.map((credential) => {
const { credential_level, credential_status, credential_type, issuer } =
// biome-ignore lint/suspicious/noExplicitAny: // @todo: remove once we have successfully migrated to Credentials 2.0.
credential as any;
const fields = credential.public_notes ? JSON.parse(credential.public_notes) : {};

const public_notes = {
id: fields.id ?? credential.id,
level: fields.level ?? credential_level,
status: fields.status ?? credential_status,
type: fields.type ?? credential_type,
issuer: fields.issuer ?? issuer,
};

return {
...credential,
public_notes: JSON.stringify(public_notes),
};
}),
select: (credentials) => credentials.filter((credential) => !credential.original_id),
});
};

Expand Down
25 changes: 1 addition & 24 deletions examples/idos-example-dapp/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,7 @@ const connectWallet = {
let credentials = await terminal
.h1("eyes", "User's credentials")
.wait("awaiting signature", cache.get("credentials") || idos.data.list("credentials"));
credentials = credentials
.filter((c) => c.original_id === null)
// @todo: remove once we have successfully migrated to Credentials 2.0.
.map((credential) => {
const { credential_level, credential_status, credential_type, issuer } = credential;
const _fields = credential.public_notes
? typeof credential.public_notes === "string"
? JSON.parse(credential.public_notes)
: credential.public_notes
: {};
const { id, ...public_notes } = {
id: _fields.id ?? credential.id,
level: _fields.level ?? credential_level,
status: _fields.status ?? credential_status,
type: _fields.type ?? credential_type,
issuer: _fields.issuer ?? issuer,
};

return {
...credential,
...public_notes,
public_notes,
};
});
credentials = credentials.filter((c) => c.original_id === null);

cache.set("credentials", credentials);

Expand Down
21 changes: 1 addition & 20 deletions examples/issuer-sdk-demo/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,7 @@ export default function Home() {
// @ts-expect-error: types in the SDK are a bit messy.
await _instance.setSigner("EVM", signer);
const _credentials = await _instance.data.list<idOSCredential>("credentials");
setCredentials(
_credentials.map((credential) => {
const { credential_level, credential_status, credential_type, issuer } =
// biome-ignore lint/suspicious/noExplicitAny: // @todo: remove once we have successfully migrated to Credentials 2.0.
credential as any;
const fields = credential.public_notes ? JSON.parse(credential.public_notes) : {};

const public_notes = {
id: fields.id ?? credential.id,
level: fields.level ?? credential_level,
status: fields.status ?? credential_status,
type: fields.type ?? credential_type,
issuer: fields.issuer ?? issuer,
};
return {
...credential,
public_notes: JSON.stringify(public_notes),
};
}),
);
setCredentials(_credentials);
}

setHasProfile(_hasProfile);
Expand Down
2 changes: 1 addition & 1 deletion packages/idos-sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@idos-network/idos-sdk",
"description": "idOS JavaScript SDK",
"version": "0.3.4",
"version": "0.3.5-0",
"homepage": "https://idos.network",
"repository": "https://github.com/idos-network/idos-sdk-js",
"license": "MIT",
Expand Down
33 changes: 23 additions & 10 deletions packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ export class IframeEnclave implements EnclaveProvider {
}) as Promise<idOSCredential[]>;
}

async #loadEnclave() {
const hasIframe = document.getElementById(this.iframe.id);
if (hasIframe) {
console.warn("An iframe already exists in the container");
return Promise.resolve();
}
async #loadEnclave(): Promise<void> {
const container =
document.querySelector(this.container) ||
throwNew(Error, `Can't find container with selector ${this.container}`);

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#directives
const permissionsPolicies = ["publickey-credentials-get", "storage-access"];
Expand Down Expand Up @@ -149,12 +147,23 @@ export class IframeEnclave implements EnclaveProvider {
this.iframe.style.setProperty(k, v);
}

const container = document.querySelector(this.container);
if (!container) throw new Error(`Can't find container with selector ${this.container}`);

let el: HTMLElement | null;
// biome-ignore lint/suspicious/noAssignInExpressions: it's on purpose
while ((el = document.getElementById(this.iframe.id))) {
console.log("reinstalling idOS iframe...");
container.removeChild(el);
}
container.appendChild(this.iframe);

return new Promise((resolve) => this.iframe.addEventListener("load", resolve));
return new Promise((resolve) =>
this.iframe.addEventListener(
"load",
() => {
resolve();
},
{ once: true },
),
);
}

#showEnclave() {
Expand Down Expand Up @@ -240,3 +249,7 @@ export class IframeEnclave implements EnclaveProvider {
};
}
}

function throwNew(ErrorClass: ErrorConstructor, ...args: Parameters<ErrorConstructor>): never {
throw new ErrorClass(...args);
}
6 changes: 3 additions & 3 deletions packages/idos-sdk-server-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
}
},
"scripts": {
"dev": "dotenvx run --convention=nextjs -- tsup --watch",
"build": "export NODE_ENV=production && dotenvx run --convention=nextjs -- tsup",
"dev": "dotenvx run --convention=nextjs -- tsup --watch --config tsup.config.ts",
"build": "export NODE_ENV=production && dotenvx run --convention=nextjs -- tsup --config tsup.config.ts",
"lint": "biome check --apply ./src",
"format": "biome format --write .",
"test": "vitest run",
Expand All @@ -33,6 +33,7 @@
},
"devDependencies": {
"@dotenvx/dotenvx": "^1.6.4",
"@idos-network/kwil-nep413-signer": "workspace:*",
"@near-js/types": "^0.2.1",
"@near-wallet-selector/core": "^8.7.5",
"@release-it/keep-a-changelog": "^5.0.0",
Expand All @@ -47,7 +48,6 @@
"@digitalbazaar/ed25519-signature-2020": "^5.2.0",
"@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
"@digitalbazaar/vc": "^6.0.2",
"@idos-network/kwil-nep413-signer": "workspace:*",
"@kwilteam/kwil-js": "0.7.1",
"@stablelib/base64": "^1.0.1",
"@stablelib/binary": "^1.0.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/idos-sdk-server-dapp/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export default defineConfig({
env: config().parsed,
format: ["esm"],
outDir: "./dist",
bundle: true,
noExternal: ["@idos-network/kwil-nep413-signer", "@idos-network/idos-sdk-types"],
});
2 changes: 1 addition & 1 deletion packages/issuer-sdk-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To create a human profile in idOS, you need:
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
<img src="./assets/add-user.drawio.svg" alt="Human Creation Process" width="100%">
<img src="https://raw.githubusercontent.com/idos-network/idos-sdk-js/main/packages/issuer-sdk-js/assets/add-user.drawio.svg" alt="Human Creation Process" width="100%">


#### Step 1: Decide on a human id
Expand Down
3 changes: 3 additions & 0 deletions packages/issuer-sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@idos-network/issuer-sdk-js",
"description": "idOS Issuer JavaScript SDK",
"version": "0.0.1",
"publishConfig": {
"access": "public"
},
"homepage": "https://idos.network",
"type": "module",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f485b1f

Please sign in to comment.