Skip to content

Commit

Permalink
feat: Implement sd+jwt for issuance and verification flows with cloud…
Browse files Browse the repository at this point in the history
… agent (#228)

Signed-off-by: Javier Ribó <[email protected]>

BREAKING CHANGE:

Pollux instance now requires to have Apollo first constructor parameter (used internally)
Deprecated internal function processJWTCredential, processAnoncredsCredential and extractCredentialFormatFromMessage. Internally, in order to process any type of credential offer just call pollux.processCredentialOffer instead. In order to extract the credentialFormat from a DIDComm message if available, use message.credentialFormat (will return known CredentialType or unknown) In order to extract the payload of whatever DIDComm message, use message.payload which will decode it into the right object instance
JWT class now needs apollo and castor in constructor as they now instantiate from JWTCore (used internally)
Derivable Private key is not deriving using the derivationPath as a string not the DerivationPath class (used internally)
  • Loading branch information
elribonazo committed Jul 19, 2024
1 parent bf15325 commit a8c0b21
Show file tree
Hide file tree
Showing 81 changed files with 3,453 additions and 1,652 deletions.
17 changes: 13 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
"plugins": [
"@typescript-eslint",
"react"
"react",
"unused-imports"
],
"extends": [
"eslint:recommended",
Expand All @@ -34,10 +35,18 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn"
]
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": "off"
},
"settings": {
"react": {
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx eslint . --fix
2 changes: 1 addition & 1 deletion demos/next/src/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export function Message({ message }) {
if (SDK.isPresentationDefinitionRequestType(requestPresentation, SDK.Domain.CredentialType.AnonCreds)) {
const credentials = app.credentials;
const fields =
Object.keys(requestPresentation.requested_attributes).reduce(
Object.keys(requestPresentation.requested_attributes || []).reduce(
(_, key) => ([
..._,
{
Expand Down
45 changes: 16 additions & 29 deletions demos/next/src/pages/credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,25 @@ function Credential(props) {
const [claims, setClaims] = useState(protect(credential));

function revealAttributes(credential: SDK.Domain.Credential, claimIndex: number, field: string) {
if (credential.credentialType === SDK.Domain.CredentialType.JWT) {
const revealed = claims.map((claim, index) => {
if (claimIndex === index) {
return {
...claim,
[field]: credential.claims[index][field]
}
}
return claim
})
setClaims(revealed)
} else {
app.agent.instance?.pluto.getLinkSecret()
.then((linkSecret) => {
app.agent.instance?.revealCredentialFields(
credential,
[field],
linkSecret!.secret
).then((revealedFields) => {
const revealed = claims.map((claim, index) => {
if (claimIndex === index) {
return {
...claim,
[field]: revealedFields[field]
}
app.agent.instance?.pluto.getLinkSecret()
.then((linkSecret) => {
app.agent.instance?.revealCredentialFields(
credential,
[field],
linkSecret!.secret
).then((revealedFields) => {
const revealed = claims.map((claim, index) => {
if (claimIndex === index) {
return {
...claim,
[field]: revealedFields[field]
}
return claim
})
setClaims(revealed)
}
return claim
})
setClaims(revealed)
})
}
})
}

return <div className="w-full mt-5 p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
Expand Down
6 changes: 4 additions & 2 deletions demos/next/src/reducers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
import { DBPreload, Message, Credential } from "@/actions/types";
import { acceptCredentialOffer, acceptPresentationRequest, connectDatabase, initAgent, rejectCredentialOffer, sendMessage, startAgent, stopAgent } from "../actions";

const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHBzOi8vc2l0LXByaXNtLW1lZGlhdG9yLmF0YWxhcHJpc20uaW8iLCJhIjpbImRpZGNvbW0vdjIiXX19.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzczovL3NpdC1wcmlzbS1tZWRpYXRvci5hdGFsYXByaXNtLmlvL3dzIiwiYSI6WyJkaWRjb21tL3YyIl19fQ";
const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjEuNDQ6ODA4MCIsImEiOlsiZGlkY29tbS92MiJdfX0.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzOi8vMTkyLjE2OC4xLjQ0OjgwODAvd3MiLCJhIjpbImRpZGNvbW0vdjIiXX19";

class TraceableError extends Error {

Expand Down Expand Up @@ -137,7 +137,9 @@ const appSlice = createSlice({
...action.meta.arg.message,
isAnswering: true,
hasAnswered: false,
error: null
error: null,
safeBody: action.meta.arg.message.safeBody,
credentialFormat: action.meta.arg.message.credentialFormat
})
})

Expand Down
Loading

0 comments on commit a8c0b21

Please sign in to comment.