Skip to content

Commit

Permalink
feat(sdk-verification)!: Implementing DIF Presentation exchange proto…
Browse files Browse the repository at this point in the history
…col 2.0 for SDK to SDK OOB verification (#196)

Signed-off-by: Pete Vielhaber <[email protected]>
Co-authored-by: Pete Vielhaber <[email protected]>
  • Loading branch information
elribonazo and petevielhaber authored Apr 29, 2024
1 parent 23e05ab commit 22fda02
Show file tree
Hide file tree
Showing 339 changed files with 14,066 additions and 4,714 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ npm run build
```

### Running the sample applications
We have enabled sample implementations for browser (react or nextjs) and nodejs.
In order to run each demo, make sure the whole SDK is built from source, then cd into the demo.
We have enabled sample implementations for browsers (React or Next.js) and Node.js.
To run each demo, ensure the whole SDK builds from the source, then cd into the demo.

Nodejs CommonJS
```bash
Expand Down
250 changes: 125 additions & 125 deletions demos/next/package-lock.json

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

64 changes: 63 additions & 1 deletion demos/next/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SDK from "@atala/prism-wallet-sdk";
import { sha512 } from '@noble/hashes/sha512'
import { RootState, reduxActions } from "@/reducers/app";
import IndexDB from '@pluto-encrypted/indexdb'
import { PresentationClaims } from "../../../../src/domain";


const Agent = SDK.Agent;
Expand Down Expand Up @@ -111,7 +112,12 @@ async function handleMessages(
if (issuedCredentials.length) {
for (const issuedCredential of issuedCredentials) {
const issueCredential = IssueCredential.fromMessage(issuedCredential);
await agent.processIssuedCredentialMessage(issueCredential);
const credential = await agent.processIssuedCredentialMessage(issueCredential);
dispatch(
reduxActions.credentialSuccess(
credential
)
)
}
}
dispatch(
Expand Down Expand Up @@ -163,6 +169,12 @@ export const startAgent = createAsyncThunk<

try {
await agent.sendMessage(testMessage);
await agent.pluto.storeMessage(testMessage);
api.dispatch(
reduxActions.messageSuccess(
[testMessage]
)
)
} catch (err) {
console.log("Safe to ignore, mediator returns null on successfully receiving the message, unpack fails.");
}
Expand All @@ -173,6 +185,56 @@ export const startAgent = createAsyncThunk<
}
})

export const sendMessage = createAsyncThunk<
{ message: SDK.Domain.Message },
{
agent: SDK.Agent,
message: SDK.Domain.Message
}
>('sendMessage', async (options, api) => {
try {
const { agent, message } = options;
await agent.sendMessage(message);
await agent.pluto.storeMessage(message);

api.dispatch(
reduxActions.messageSuccess(
[message]
)
)
return api.fulfillWithValue({ message });
} catch (err) {
return api.rejectWithValue(err as Error);
}
})

export const initiatePresentationRequest = createAsyncThunk<
any,
{
agent: SDK.Agent,
toDID: SDK.Domain.DID,
presentationClaims: PresentationClaims
}
>("initiatePresentationRequest", async (options, api) => {
try {
const {
agent,
presentationClaims,
toDID
} = options;

await agent.initiatePresentationRequest(
SDK.Domain.CredentialType.JWT,
toDID,
presentationClaims
);

return api.fulfillWithValue(null)
} catch (err) {
return api.rejectWithValue(err as Error);
}
})

export const initAgent = createAsyncThunk<
{ agent: SDK.Agent },
{
Expand Down
4 changes: 4 additions & 0 deletions demos/next/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export enum DBPreload {
export enum Message {
success = "messageSuccess"
}

export enum Credential {
success = "credentialSuccess"
}
Loading

1 comment on commit 22fda02

@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: 72%
72.77% (2072/2847) 61.53% (947/1539) 79.05% (570/721)

JUnit

Tests Skipped Failures Errors Time
434 6 💤 0 ❌ 0 🔥 1m 5s ⏱️

Please sign in to comment.