-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
🦙 MegaLinter status: ✅ SUCCESS
See errors details in artifact MegaLinter reports on CI Job page |
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 | ||
) | ||
} |
There was a problem hiding this comment.
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.
PrismAgent/Sources/PrismAgent.swift
Outdated
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 } | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
4bfb8cd
to
fad2f0b
Compare
3cea694
to
10c59c8
Compare
fad2f0b
to
c9cbad4
Compare
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c112c8b
to
c8a25b5
Compare
c9cbad4
to
ec05665
Compare
ec05665
to
f2c2142
Compare
Fixes ATL-2497