Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent): enable parsing of enterprise invitation and add prism agent #44

Merged
merged 4 commits into from
Dec 1, 2022

Conversation

goncalo-frade-iohk
Copy link
Contributor

Fixes ATL-2497

@github-actions
Copy link

github-actions bot commented Nov 25, 2022

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ REPOSITORY checkov yes no 10.03s
✅ REPOSITORY dustilock yes no 0.02s
✅ REPOSITORY gitleaks yes no 4.45s
✅ REPOSITORY git_diff yes no 0.16s
✅ REPOSITORY secretlint yes no 2.37s
✅ REPOSITORY syft yes no 0.56s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@goncalo-frade-iohk goncalo-frade-iohk requested review from a team November 25, 2022 12:07
Comment on lines +164 to +185
public func parsePrismInvitation(str: String) async throws -> InvitationType.PrismOnboarding {
let prismOnboarding = try PrismOnboardingInvitation(jsonString: str)
guard
let url = URL(string: prismOnboarding.body.onboardEndpoint)
else { throw PrismAgentError.invalidURLError }

let did = try await self.createNewDID(
type: .peer,
alias: prismOnboarding.body.onboardEndpoint,
services: [.init(
id: "#didcomm-1",
type: ["DIDCommMessaging"],
service: mediatorServiceEnpoint.absoluteString)
]
)

return .init(
from: prismOnboarding.body.from,
endpoint: url,
ownDID: did
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@milosh86 @elribonazo this is the parsing for the invitation request like this:

{
    "@type": "https://atalaprism.io/did-request",
    "onboardEndpoint": "https://demo.atalaprism.io:8085/onboard/uuid-1234-7273-1878",
    "from": "Government Issuer"
  }

And it returns an object prism onboarding object.

Comment on lines 216 to 229
public func acceptPrismInvitation(invitation: InvitationType.PrismOnboarding) async throws {
var request = URLRequest(url: invitation.endpoint.appendingPathComponent(invitation.ownDID.string))
request.httpMethod = "POST"
let response = try await URLSession.shared.data(for: request)
guard
let urlResponse = response.1 as? HTTPURLResponse,
urlResponse.statusCode == 200
else { throw PrismAgentError.failedToOnboardError }
}
Copy link
Contributor Author

@goncalo-frade-iohk goncalo-frade-iohk Nov 25, 2022

Choose a reason for hiding this comment

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

@milosh86 @elribonazo This is a very simple method to just get that parsed object returned previously and send the DID to the endpoint

Choose a reason for hiding this comment

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

@goncalo-frade-iohk . Just to clarify. For DIDComm OOB invitations you use DID Peers. For Prism Invitations, do you use DID Peer or DID Prism?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good question and something I asked and still require clarification. But the initial conclusion is we use DIDPeer as well

guard let index = $0?.keyPairIndex else { throw PrismAgentError.cannotFindDIDKeyPairIndex }
// Re-Create the key pair to sign the message
let keyPair = apollo.createKeyPair(seed: seed, index: index)
return apollo.signMessage(privateKey: keyPair.privateKey, message: message)
Copy link
Member

Choose a reason for hiding this comment

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

just wonder, which default parameters for signing do we use here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case there are no default parameters.

The Agent is always initiated with a valid Seed as requirement, this function signWith(did: DID, message: Data) has DID and the message bytes as parameters.

What the Agent is going to do is check if the DID information ( in this case the KeyPairIndex) was persisted before, return it from the database and create the DID private key with Seed+KeyPairIndex to then sign the message.

@goncalo-frade-iohk goncalo-frade-iohk force-pushed the feature/ATL-2483 branch 2 times, most recently from c112c8b to c8a25b5 Compare December 1, 2022 19:47
Base automatically changed from feature/ATL-2483 to main December 1, 2022 19:48
@goncalo-frade-iohk goncalo-frade-iohk merged commit 0dac025 into main Dec 1, 2022
@goncalo-frade-iohk goncalo-frade-iohk deleted the feature/ATL-2497 branch December 1, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants