Skip to content

Commit

Permalink
feat!: Implementing Pluto Repositories (#160)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- Domain.Credential now has uuid (string) as an optional attribute in the class
- Change StorePrismDID Function parameters, removing keyPathIndex and privateKeyMetadataId which were not in use
- Small change in the getCredentialMetadata and getLinkSecret to return null when not found
- Change Pluto interface to use CredentialMetadata class VS what it was using before.
- Change Pluto interface, storeMediator now accepts a Mediator class and not 3 attributes, mediator, host and routing
- Rename storePrivateKeys to storePrivateKey
- Change Pluto interface, using Domain.PrismDID instead of Domain.PrismDID which is being removed
- Added new properties to handle Anoncreds credentials properties.
- Re-implemented Pluto which is now available again to all the users.

import SDK from "@atala/prism-wallet-sdk";
import IndexDB from "@pluto-encrypted/indexdb";

const store = new SDK.Store({
name: "test",
storage: IndexDB,
password: Buffer.from("demoapp").toString("hex")
});
const pluto = new SDK.Pluto(store, apollo);

Migrations, schemas, queries and error handling have been moved to the SDK again but user's which were using the existing storages can just pass the indexDB pluto-encrypted storage and it will integrate with the new db schemas, migrations, etc
  • Loading branch information
elribonazo committed Feb 27, 2024
1 parent 6ebf48a commit ce7669f
Show file tree
Hide file tree
Showing 118 changed files with 29,643 additions and 10,362 deletions.
1,076 changes: 45 additions & 1,031 deletions demos/browser/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions demos/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"dependencies": {
"@atala/prism-wallet-sdk": "../..",
"@pluto-encrypted/database": "^1.2.14",
"@pluto-encrypted/inmemory": "^1.3.11",
"@pluto-encrypted/indexdb": "^1.12.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
35 changes: 14 additions & 21 deletions demos/browser/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/**
* WARNING: This is an example using an encrypted inMemory storage.
* WARNING: This is an example using an encrypted indexDB storage.
* Checkout Community maintained NPM package @pluto-encrypted/database for more DB wrappers.
*/
import InMemory from "@pluto-encrypted/inmemory";
import { Database } from "@pluto-encrypted/database";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import "./App.css";
import * as jose from "jose";
import { useAtom } from "jotai";
import SDK from "@atala/prism-wallet-sdk";
import IndexDB from "@pluto-encrypted/indexdb";

import "./App.css";
import { mnemonicsAtom } from "./state";
import { trimString } from "./utils";
import Spacer from "./Spacer";
Expand All @@ -25,7 +25,7 @@ const RequestPresentation = SDK.RequestPresentation;

const apollo = new SDK.Apollo();
const castor = new SDK.Castor(apollo);
const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9iZXRhLW1lZGlhdG9yLmF0YWxhcHJpc20uaW8iLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19";
const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHBzOi8vc2l0LXByaXNtLW1lZGlhdG9yLmF0YWxhcHJpc20uaW8iLCJhIjpbImRpZGNvbW0vdjIiXX19.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzczovL3NpdC1wcmlzbS1tZWRpYXRvci5hdGFsYXByaXNtLmlvL3dzIiwiYSI6WyJkaWRjb21tL3YyIl19fQ";

const useSDK = (mediatorDID: SDK.Domain.DID, pluto: SDK.Domain.Pluto) => {
const agent = SDK.Agent.initialize({ mediatorDID, pluto });
Expand Down Expand Up @@ -362,7 +362,7 @@ const OOB: React.FC<{ agent: SDK.Agent, pluto: SDK.Domain.Pluto; }> = props => {
</>;
};

const Agent: React.FC<{ pluto: SDK.Domain.Pluto }> = props => {
const Agent: React.FC<{ pluto: SDK.Domain.Pluto; }> = props => {
const [mediatorDID, setMediatorDID] = useState<string>(defaultMediatorDID);

const sdk = useMemo(() => useSDK(SDK.Domain.DID.fromString(mediatorDID), props.pluto), [mediatorDID]);
Expand Down Expand Up @@ -390,6 +390,7 @@ const Agent: React.FC<{ pluto: SDK.Domain.Pluto }> = props => {
const lastCredentials = await pluto.getAllCredentials();
const lastCredential = lastCredentials.at(-1);
const requestPresentationMessage = RequestPresentation.fromMessage(requestPresentation);

try {
if (lastCredential === undefined) throw new Error("last credential not found");

Expand Down Expand Up @@ -625,22 +626,14 @@ const Agent: React.FC<{ pluto: SDK.Domain.Pluto }> = props => {
};


function App() {
const [pluto, setPluto] = useState<SDK.Domain.Pluto>()

useEffect(() => {
if (!pluto) {
const defaultPassword = new Uint8Array(32).fill(1);
Database.createEncrypted(
{
name: `my-db`,
encryptionKey: defaultPassword,
storage: InMemory,
}
).then((db) => setPluto(db as any))
}
}, [pluto, setPluto])
const store = new SDK.Store({
name: "test",
storage: IndexDB,
password: Buffer.from("demoapp").toString("hex")
});
const pluto = new SDK.Pluto(store, apollo);

function App() {
return (
<div className="App">
<h1>Atala PRISM Wallet SDK Usage Examples</h1>
Expand Down
4 changes: 2 additions & 2 deletions demos/browser/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom } from "jotai";
import { Domain } from "@atala/prism-wallet-sdk";
import SDK from "@atala/prism-wallet-sdk";

export const mnemonicsAtom = atom<Domain.MnemonicWordList | undefined>(
export const mnemonicsAtom = atom<SDK.Domain.MnemonicWordList | undefined>(
undefined
);
12 changes: 9 additions & 3 deletions demos/browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -17,5 +21,7 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
"include": [
"src"
]
}
Loading

1 comment on commit ce7669f

@github-actions
Copy link

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 67%
67.07% (1691/2521) 53.37% (648/1214) 69.75% (512/734)

JUnit

Tests Skipped Failures Errors Time
383 2 💤 0 ❌ 0 🔥 57.52s ⏱️

Please sign in to comment.