forked from hyperledger-identus/sdk-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agent): Implementing DIDComm V2 Protocols + Demo showcasing (hyp…
…erledger-identus#36) Co-authored-by: Curtish <[email protected]>
- Loading branch information
1 parent
3a011cb
commit 515d835
Showing
56 changed files
with
3,264 additions
and
1,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2021, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"ignorePatterns": ["castor/parser", "castor/protos", "webpack", "scripts"], | ||
"plugins": ["@typescript-eslint", "react"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react/recommended" | ||
], | ||
"rules": { | ||
"comma-dangle": 0, | ||
"no-unexpected-multiline": "warn", | ||
"prefer-const": "warn", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["warn"] | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"jasmine": true, | ||
"jest": true, | ||
"es2021": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { curve } from "elliptic"; | ||
import { KeyPair } from "../../domain"; | ||
|
||
interface PublicJson { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as didJWT from "did-jwt"; | ||
|
||
import Castor from "../../../domain/buildingBlocks/Castor"; | ||
import { DIDResolutionResult } from "did-resolver"; | ||
import { | ||
AlsoKnownAs, | ||
Controller, | ||
Services, | ||
VerificationMethods, | ||
DID, | ||
} from "../../../domain"; | ||
|
||
export class JWT { | ||
private castor: Castor; | ||
|
||
constructor(castor: Castor) { | ||
this.castor = castor; | ||
} | ||
|
||
private async resolve(did: string): Promise<DIDResolutionResult> { | ||
const resolved = await this.castor.resolveDID(did); | ||
const alsoKnownAs = resolved.coreProperties.find( | ||
(prop): prop is AlsoKnownAs => prop instanceof AlsoKnownAs | ||
); | ||
const controller = resolved.coreProperties.find( | ||
(prop): prop is Controller => prop instanceof Controller | ||
); | ||
const verificationMethods = resolved.coreProperties.find( | ||
(prop): prop is VerificationMethods => prop instanceof VerificationMethods | ||
); | ||
const service = resolved.coreProperties.find( | ||
(prop): prop is Services => prop instanceof Services | ||
); | ||
|
||
return { | ||
didResolutionMetadata: { contentType: "application/did+ld+json" }, | ||
didDocumentMetadata: {}, | ||
didDocument: { | ||
id: resolved.id.toString(), | ||
alsoKnownAs: alsoKnownAs && alsoKnownAs.values, | ||
controller: | ||
controller && controller.values | ||
? controller.values.map((v) => v.toString()) | ||
: [], | ||
verificationMethod: | ||
verificationMethods && verificationMethods.values | ||
? verificationMethods.values.map((vm) => { | ||
if (vm.publicKeyMultibase) { | ||
return { | ||
id: vm.id, | ||
type: "EcdsaSecp256k1VerificationKey2019", | ||
controller: vm.controller, | ||
publicKeyMultibase: vm.publicKeyMultibase, | ||
}; | ||
} | ||
if (vm.publicKeyJwk) { | ||
return { | ||
id: vm.id, | ||
type: "JsonWebKey2020", | ||
controller: vm.controller, | ||
publicKeyJwk: vm.publicKeyJwk, | ||
}; | ||
} | ||
throw new Error("Invalid KeyType"); | ||
}) | ||
: [], | ||
service: | ||
service && service.values | ||
? service.values.map((service) => { | ||
return { | ||
id: service.id, | ||
type: service.type[0], | ||
serviceEndpoint: service.serviceEndpoint, | ||
}; | ||
}) | ||
: [], | ||
}, | ||
}; | ||
} | ||
|
||
async sign( | ||
issuer: DID, | ||
privateKey: Uint8Array, | ||
payload: Partial<didJWT.JWTPayload> | ||
): Promise<string> { | ||
//TODO: Better check if this method is called with PrismDID and not PeerDID or other | ||
const signer = didJWT.ES256KSigner(privateKey); | ||
const jwt = await didJWT.createJWT( | ||
payload, | ||
{ issuer: issuer.toString(), signer }, | ||
{ alg: "ES256K" } | ||
); | ||
return jwt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.