diff --git a/AtalaPrismSDK/Apollo/Sources/ApolloImpl+Public.swift b/AtalaPrismSDK/Apollo/Sources/ApolloImpl+Public.swift index 5ebe361e..bf3a3c35 100644 --- a/AtalaPrismSDK/Apollo/Sources/ApolloImpl+Public.swift +++ b/AtalaPrismSDK/Apollo/Sources/ApolloImpl+Public.swift @@ -1,6 +1,5 @@ import Domain import Foundation -import SwiftJWT extension ApolloImpl: Apollo { /// createRandomMnemonics creates a random set of mnemonic phrases that can be used as a seed for generating a private key. @@ -191,21 +190,8 @@ returns random mnemonics nerver returns invalid mnemonics return jsonString } - public func verifyJWT(jwk: String, publicKey: PublicKey) throws -> String { - switch publicKey.curve { - case "secp256k1": - let verifier = JWTVerifier.es256(publicKey: publicKey.value) - let decoder = JWTDecoder(jwtVerifier: verifier) - return jwk - default: - let verifier = JWTVerifier.none - let decoder = JWTDecoder(jwtVerifier: verifier) - return jwk - } - } - public func keyDataToPEMString(_ keyData: PrivateKey) -> String? { - let keyBase64 = keyData.value.base64EncodedString(options: .lineLength64Characters) + let keyBase64 = keyData.value.base64EncodedString() let pemString = """ -----BEGIN PRIVATE KEY----- \(keyBase64) @@ -215,7 +201,7 @@ returns random mnemonics nerver returns invalid mnemonics } public func keyDataToPEMString(_ keyData: PublicKey) -> String? { - let keyBase64 = keyData.value.base64EncodedString(options: .lineLength64Characters) + let keyBase64 = keyData.value.base64EncodedString() let pemString = """ -----BEGIN PUBLIC KEY----- \(keyBase64) @@ -224,9 +210,3 @@ returns random mnemonics nerver returns invalid mnemonics return pemString } } - -struct MyClaims: Claims { - let iss: String - let sub: String - let exp: Date -} diff --git a/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/HDPrivateKey.swift b/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/HDPrivateKey.swift index dbc0b733..dd31a2c0 100644 --- a/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/HDPrivateKey.swift +++ b/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/HDPrivateKey.swift @@ -65,7 +65,7 @@ struct HDPrivateKey { } func privateKey() -> LockPrivateKey { - return LockPrivateKey(data: raw, isPublicKeyCompressed: true) + return LockPrivateKey(data: raw, isPublicKeyCompressed: false) } func extendedPublicKey() -> HDPublicKey { diff --git a/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/LockPrivateKey.swift b/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/LockPrivateKey.swift index 452f51ad..caea3cdf 100644 --- a/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/LockPrivateKey.swift +++ b/AtalaPrismSDK/Apollo/Sources/BIPs/BIP32_44/LockPrivateKey.swift @@ -76,7 +76,7 @@ struct LockPrivateKey { self.data = key } - init(data: Data, isPublicKeyCompressed: Bool = true) { + init(data: Data, isPublicKeyCompressed: Bool = false) { self.data = data self.isPublicKeyCompressed = isPublicKeyCompressed } diff --git a/AtalaPrismSDK/Apollo/Sources/Crypto/ECVerify.swift b/AtalaPrismSDK/Apollo/Sources/Crypto/ECVerify.swift index 9d386115..868e0e72 100644 --- a/AtalaPrismSDK/Apollo/Sources/Crypto/ECVerify.swift +++ b/AtalaPrismSDK/Apollo/Sources/Crypto/ECVerify.swift @@ -1,62 +1,38 @@ -// -// File.swift -// -// -// Created by Goncalo Frade IOHK on 07/03/2023. -// - +import CryptoKit import Foundation import secp256k1 struct ECVerify { + public enum CryptoError: String, Error { + case signatureParseFailed + case publicKeyParseFailed + } + let signature: Data let message: Data let publicKey: Data - func verifySignature() throws -> Bool { - let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_VERIFY))! - defer { secp256k1_context_destroy(ctx) } - - let signaturePointer = UnsafeMutablePointer.allocate(capacity: 1) - defer { signaturePointer.deallocate() } - guard signature.withUnsafeBytes({ - secp256k1_ecdsa_signature_parse_der( - ctx, - signaturePointer, - $0.bindMemory(to: UInt8.self).baseAddress.unsafelyUnwrapped, - signature.count + let signature = try getSignatureFromData(signature) + return try secp256k1 + .Signing + .PublicKey( + rawRepresentation: publicKey, + format: LockPublicKey(bytes: publicKey).isCompressed ? .compressed : .uncompressed ) - }) == 1 else { - throw CryptoError.signatureParseFailed - } - - let pubkeyPointer = UnsafeMutablePointer.allocate(capacity: 1) - defer { pubkeyPointer.deallocate() } - guard publicKey.withUnsafeBytes({ - secp256k1_ec_pubkey_parse( - ctx, - pubkeyPointer, - $0.bindMemory(to: UInt8.self).baseAddress.unsafelyUnwrapped, - publicKey.count - ) }) == 1 else { - throw CryptoError.publicKeyParseFailed - } - - guard message.withUnsafeBytes ({ - secp256k1_ecdsa_verify( - ctx, - signaturePointer, - $0.bindMemory(to: UInt8.self).baseAddress.unsafelyUnwrapped, - pubkeyPointer) }) == 1 else { - return false - } - - return true + .ecdsa + .isValidSignature(signature, for: SHA256.hash(data: message)) } - public enum CryptoError: Error { - case signatureParseFailed - case publicKeyParseFailed + private func getSignatureFromData(_ data: Data) throws -> secp256k1.Signing.ECDSASignature { + if let derSignature = try? secp256k1.Signing.ECDSASignature(derRepresentation: data) { + return derSignature + } else if let rawSignature = try? secp256k1.Signing.ECDSASignature(rawRepresentation: data) { + return rawSignature + } else if let compactSignature = try? secp256k1.Signing.ECDSASignature(compactRepresentation: data) { + return compactSignature + } else { + throw CryptoError.signatureParseFailed + } } } diff --git a/AtalaPrismSDK/Apollo/Sources/Operations/VerifySignatureOperation.swift b/AtalaPrismSDK/Apollo/Sources/Operations/VerifySignatureOperation.swift index a5803c6a..ecfb0864 100644 --- a/AtalaPrismSDK/Apollo/Sources/Operations/VerifySignatureOperation.swift +++ b/AtalaPrismSDK/Apollo/Sources/Operations/VerifySignatureOperation.swift @@ -24,7 +24,7 @@ struct VerifySignatureOperation { func compute() throws -> Bool { try ECVerify( signature: signature.value, - message: Data(SHA256.hash(data: challenge)), + message: challenge, publicKey: publicKey.value ).verifySignature() } diff --git a/AtalaPrismSDK/Apollo/Tests/BIP32Tests.swift b/AtalaPrismSDK/Apollo/Tests/BIP32Tests.swift index 72be2901..c6a6e224 100644 --- a/AtalaPrismSDK/Apollo/Tests/BIP32Tests.swift +++ b/AtalaPrismSDK/Apollo/Tests/BIP32Tests.swift @@ -2,6 +2,7 @@ import Core import Domain import XCTest +import secp256k1 final class BIP32Tests: XCTestCase { @@ -26,4 +27,14 @@ final class BIP32Tests: XCTestCase { "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg" ) } + + func testBip32KeyPathGenerationPublicKey() throws { + let seed = try CreateSeedOperation(words: mnemonics).compute() + let operation = CreateSec256k1KeyPairOperation(seed: seed, keyPath: .init(index: 3)) + let privateKey = try operation.compute() + XCTAssertEqual( + privateKey.publicKey.value.base64UrlEncodedString(), + "BD-l4lrQ6Go-oN5XtdpY6o5dyf2V2v5EbMAvRjVGJpE1gYVURJfxKMpNPnKlLr4MOLNVaYvBNOoy9L50E8jVx8Q" + ) + } } diff --git a/AtalaPrismSDK/Apollo/Tests/ECSigningTests.swift b/AtalaPrismSDK/Apollo/Tests/ECSigningTests.swift index ddfc32b9..a817e193 100644 --- a/AtalaPrismSDK/Apollo/Tests/ECSigningTests.swift +++ b/AtalaPrismSDK/Apollo/Tests/ECSigningTests.swift @@ -6,10 +6,10 @@ import XCTest final class ECSigningTests: XCTestCase { func testSigning() throws { let privKey = PrivateKey( - curve: .secp256k1(index: 0), - value: Data(fromBase64URL: "xURclKhT6as1Tb9vg4AJRRLPAMWb9dYTTthDvXEKjMc")! + curve: .secp256k1(index: 3), + value: Data(fromBase64URL: "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg")! ) - let testMessage = "test".data(using: .utf8)! + let testMessage = "Test".data(using: .utf8)! let signing = try SignMessageOperation( privateKey: privKey, @@ -18,7 +18,7 @@ final class ECSigningTests: XCTestCase { XCTAssertEqual( signing.value.base64UrlEncodedString(), - "MEUCIQDJroM8wtcJovEyZjl2unJpKZ_kbicRjPCJ2krzQzK31QIgcpe5CwIIXUrP63qOT-WzzmxVplHGhSO8R8h5-1ECKt4" + "MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ" ) } } diff --git a/AtalaPrismSDK/Apollo/Tests/ECVerifyTests.swift b/AtalaPrismSDK/Apollo/Tests/ECVerifyTests.swift index 4d97e2eb..aa0db57b 100644 --- a/AtalaPrismSDK/Apollo/Tests/ECVerifyTests.swift +++ b/AtalaPrismSDK/Apollo/Tests/ECVerifyTests.swift @@ -4,20 +4,19 @@ import Domain import XCTest final class ECVerification: XCTestCase { - func testVerify() throws { let pubKey = PublicKey( curve: KeyCurve.secp256k1().name, - value: Data(fromBase64URL: "BHza5mV6_Iz6XdyMpxpjUMprZUCN_MpMuQCTFYpxSf8rW7N7DD04troywCgLkg0_ABP-IcxZcE1-qKjwCWYTVO8")! + value: Data(fromBase64URL: "BD-l4lrQ6Go-oN5XtdpY6o5dyf2V2v5EbMAvRjVGJpE1gYVURJfxKMpNPnKlLr4MOLNVaYvBNOoy9L50E8jVx8Q")! ) - let testMessage = "test".data(using: .utf8)! + let testMessage = "Test".data(using: .utf8)! + let signature = Data(fromBase64URL: "MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ")! XCTAssertTrue(try VerifySignatureOperation( publicKey: pubKey, challenge: testMessage, signature: Signature( - value: Data( - fromBase64URL: "MEUCIQDJroM8wtcJovEyZjl2unJpKZ_kbicRjPCJ2krzQzK31QIgcpe5CwIIXUrP63qOT-WzzmxVplHGhSO8R8h5-1ECKt4")! + value: signature ) ).compute()) } diff --git a/AtalaPrismSDK/Apollo/Tests/PublicKeyCompressionTests.swift b/AtalaPrismSDK/Apollo/Tests/PublicKeyCompressionTests.swift index 4e348d73..6a21fee1 100644 --- a/AtalaPrismSDK/Apollo/Tests/PublicKeyCompressionTests.swift +++ b/AtalaPrismSDK/Apollo/Tests/PublicKeyCompressionTests.swift @@ -1,5 +1,7 @@ @testable import Apollo +import Domain import XCTest +import secp256k1 final class PublicKeyCompressionTests: XCTestCase { @@ -7,12 +9,12 @@ final class PublicKeyCompressionTests: XCTestCase { let privateKey = LockPrivateKey(data: Data(fromBase64URL: "xURclKhT6as1Tb9vg4AJRRLPAMWb9dYTTthDvXEKjMc")!) let pubKey = privateKey.publicKey() - print("Is key compressed: \(pubKey.isCompressed)") + XCTAssertFalse(pubKey.isCompressed) let compressedPubKey = pubKey.compressedPublicKey() - print("Is key compressed: \(compressedPubKey.isCompressed)") + XCTAssertTrue(compressedPubKey.isCompressed) let uncompressedPubKey = pubKey.uncompressedPublicKey() - print("Is key compressed: \(uncompressedPubKey.isCompressed)") + XCTAssertFalse(uncompressedPubKey.isCompressed) } } diff --git a/AtalaPrismSDK/Builders/Sources/PolluxBuilder.swift b/AtalaPrismSDK/Builders/Sources/PolluxBuilder.swift index 4d82e1b7..452a5e18 100644 --- a/AtalaPrismSDK/Builders/Sources/PolluxBuilder.swift +++ b/AtalaPrismSDK/Builders/Sources/PolluxBuilder.swift @@ -2,13 +2,21 @@ import Domain import Pollux public struct PolluxBuilder { + let apollo: Apollo let castor: Castor - public init(castor: Castor) { + public init( + apollo: Apollo, + castor: Castor + ) { + self.apollo = apollo self.castor = castor } public func build() -> Pollux { - PolluxImpl(castor: castor) + PolluxImpl( + apollo: apollo, + castor: castor + ) } } diff --git a/AtalaPrismSDK/Castor/Sources/DID/PrismDID/PrismDIDPublicKey.swift b/AtalaPrismSDK/Castor/Sources/DID/PrismDID/PrismDIDPublicKey.swift index fb30a46f..fbfa717f 100644 --- a/AtalaPrismSDK/Castor/Sources/DID/PrismDID/PrismDIDPublicKey.swift +++ b/AtalaPrismSDK/Castor/Sources/DID/PrismDID/PrismDIDPublicKey.swift @@ -93,6 +93,7 @@ struct PrismDIDPublicKey { var protoEC = Io_Iohk_Atala_Prism_Protos_ECKeyData() protoEC.x = points.x protoEC.y = points.y + protoEC.curve = "secp256k1" protoKey.keyData = .ecKeyData(protoEC) return protoKey } diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfBaseListener.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfBaseListener.swift index 2fb4970f..d048a239 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfBaseListener.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfBaseListener.swift @@ -1,88 +1,89 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDAbnf.g4 by ANTLR 4.12.0 import Antlr4 + /** * This class provides an empty implementation of {@link DIDAbnfListener}, * which can be extended to create a listener which only needs to handle a subset * of the available methods. */ open class DIDAbnfBaseListener: DIDAbnfListener { - public init() {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterDid(_ ctx: DIDAbnfParser.DidContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitDid(_ ctx: DIDAbnfParser.DidContext) {} + public init() { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterDid(_ ctx: DIDAbnfParser.DidContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitDid(_ ctx: DIDAbnfParser.DidContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterIdchar(_ ctx: DIDAbnfParser.IdcharContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitIdchar(_ ctx: DIDAbnfParser.IdcharContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterIdchar(_ ctx: DIDAbnfParser.IdcharContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitIdchar(_ ctx: DIDAbnfParser.IdcharContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterEveryRule(_ ctx: ParserRuleContext) throws {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitEveryRule(_ ctx: ParserRuleContext) throws {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func visitTerminal(_ node: TerminalNode) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func visitErrorNode(_ node: ErrorNode) {} -} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterEveryRule(_ ctx: ParserRuleContext) throws { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitEveryRule(_ ctx: ParserRuleContext) throws { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func visitTerminal(_ node: TerminalNode) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func visitErrorNode(_ node: ErrorNode) { } +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfLexer.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfLexer.swift index bd9641d2..1169414a 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfLexer.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfLexer.swift @@ -1,99 +1,101 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDAbnf.g4 by ANTLR 4.12.0 import Antlr4 open class DIDAbnfLexer: Lexer { - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = DIDAbnfLexer._ATN.getNumberOfDecisions() - for i in 0 ..< length { - decisionToDFA.append(DFA(DIDAbnfLexer._ATN.getDecisionState(i)!, i)) - } - return decisionToDFA - }() - - internal static let _sharedContextCache = PredictionContextCache() - - public - static let SCHEMA = 1, ALPHA = 2, DIGIT = 3, PCT_ENCODED = 4, PERCENT = 5, DASH = 6, - PERIOD = 7, COLON = 8, UNDERSCORE = 9 - - public - static let channelNames: [String] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ] - - public - static let modeNames: [String] = [ - "DEFAULT_MODE" - ] - - public - static let ruleNames: [String] = [ - "D", "I", "SCHEMA", "LOWERCASE", "UPPERCASE", "ALPHA", "HEX", "DIGIT", - "PCT_ENCODED", "PERCENT", "DASH", "PERIOD", "COLON", "UNDERSCORE" - ] - - private static let _LITERAL_NAMES: [String?] = [ - nil, nil, nil, nil, nil, "'%'", "'-'", "'.'", "':'", "'_'" - ] - private static let _SYMBOLIC_NAMES: [String?] = [ - nil, "SCHEMA", "ALPHA", "DIGIT", "PCT_ENCODED", "PERCENT", "DASH", "PERIOD", - "COLON", "UNDERSCORE" - ] - public - static let VOCABULARY = Vocabulary(_LITERAL_NAMES, _SYMBOLIC_NAMES) - - override open - func getVocabulary() -> Vocabulary { - return DIDAbnfLexer.VOCABULARY - } - - public - required init(_ input: CharStream) { - RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION) - super.init(input) - _interp = LexerATNSimulator(self, DIDAbnfLexer._ATN, DIDAbnfLexer._decisionToDFA, DIDAbnfLexer._sharedContextCache) - } - - override open - func getGrammarFileName() -> String { return "DIDAbnf.g4" } - - override open - func getRuleNames() -> [String] { return DIDAbnfLexer.ruleNames } - - override open - func getSerializedATN() -> [Int] { return DIDAbnfLexer._serializedATN } - - override open - func getChannelNames() -> [String] { return DIDAbnfLexer.channelNames } - - override open - func getModeNames() -> [String] { return DIDAbnfLexer.modeNames } - - override open - func getATN() -> ATN { return DIDAbnfLexer._ATN } - - static let _serializedATN: [Int] = [ - 4, 0, 9, 63, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, - 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 1, 0, 1, - 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 3, 5, 44, 8, 5, 1, 6, 1, 6, 1, - 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, - 0, 0, 14, 1, 0, 3, 0, 5, 1, 7, 0, 9, 0, 11, 2, 13, 0, 15, 3, 17, 4, 19, 5, 21, 6, 23, 7, 25, 8, 27, - 9, 1, 0, 6, 2, 0, 68, 68, 100, 100, 2, 0, 73, 73, 105, 105, 1, 0, 97, 122, 1, 0, 65, 90, 3, 0, 48, - 57, 65, 70, 97, 102, 1, 0, 48, 57, 58, 0, 5, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, - 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, - 0, 1, 29, 1, 0, 0, 0, 3, 31, 1, 0, 0, 0, 5, 33, 1, 0, 0, 0, 7, 37, 1, 0, 0, 0, 9, 39, 1, 0, 0, 0, 11, - 43, 1, 0, 0, 0, 13, 45, 1, 0, 0, 0, 15, 47, 1, 0, 0, 0, 17, 49, 1, 0, 0, 0, 19, 53, 1, 0, 0, 0, 21, - 55, 1, 0, 0, 0, 23, 57, 1, 0, 0, 0, 25, 59, 1, 0, 0, 0, 27, 61, 1, 0, 0, 0, 29, 30, 7, 0, 0, 0, 30, - 2, 1, 0, 0, 0, 31, 32, 7, 1, 0, 0, 32, 4, 1, 0, 0, 0, 33, 34, 3, 1, 0, 0, 34, 35, 3, 3, 1, 0, 35, 36, - 3, 1, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38, 7, 2, 0, 0, 38, 8, 1, 0, 0, 0, 39, 40, 7, 3, 0, 0, 40, 10, 1, - 0, 0, 0, 41, 44, 3, 7, 3, 0, 42, 44, 3, 9, 4, 0, 43, 41, 1, 0, 0, 0, 43, 42, 1, 0, 0, 0, 44, 12, 1, - 0, 0, 0, 45, 46, 7, 4, 0, 0, 46, 14, 1, 0, 0, 0, 47, 48, 7, 5, 0, 0, 48, 16, 1, 0, 0, 0, 49, 50, 3, - 19, 9, 0, 50, 51, 3, 13, 6, 0, 51, 52, 3, 13, 6, 0, 52, 18, 1, 0, 0, 0, 53, 54, 5, 37, 0, 0, 54, 20, - 1, 0, 0, 0, 55, 56, 5, 45, 0, 0, 56, 22, 1, 0, 0, 0, 57, 58, 5, 46, 0, 0, 58, 24, 1, 0, 0, 0, 59, 60, - 5, 58, 0, 0, 60, 26, 1, 0, 0, 0, 61, 62, 5, 95, 0, 0, 62, 28, 1, 0, 0, 0, 2, 0, 43, 0 - ] - - public - static let _ATN: ATN = try! ATNDeserializer().deserialize(_serializedATN) -} + + internal static var _decisionToDFA: [DFA] = { + var decisionToDFA = [DFA]() + let length = DIDAbnfLexer._ATN.getNumberOfDecisions() + for i in 0.. Vocabulary { + return DIDAbnfLexer.VOCABULARY + } + + public + required init(_ input: CharStream) { + RuntimeMetaData.checkVersion("4.12.0", RuntimeMetaData.VERSION) + super.init(input) + _interp = LexerATNSimulator(self, DIDAbnfLexer._ATN, DIDAbnfLexer._decisionToDFA, DIDAbnfLexer._sharedContextCache) + } + + override open + func getGrammarFileName() -> String { return "DIDAbnf.g4" } + + override open + func getRuleNames() -> [String] { return DIDAbnfLexer.ruleNames } + + override open + func getSerializedATN() -> [Int] { return DIDAbnfLexer._serializedATN } + + override open + func getChannelNames() -> [String] { return DIDAbnfLexer.channelNames } + + override open + func getModeNames() -> [String] { return DIDAbnfLexer.modeNames } + + override open + func getATN() -> ATN { return DIDAbnfLexer._ATN } + + static let _serializedATN:[Int] = [ + 4,0,9,63,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6, + 2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,1,0,1, + 0,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,3,5,44,8,5,1,6,1,6,1, + 7,1,7,1,8,1,8,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13, + 0,0,14,1,0,3,0,5,1,7,0,9,0,11,2,13,0,15,3,17,4,19,5,21,6,23,7,25,8,27, + 9,1,0,6,2,0,68,68,100,100,2,0,73,73,105,105,1,0,97,122,1,0,65,90,3,0,48, + 57,65,70,97,102,1,0,48,57,58,0,5,1,0,0,0,0,11,1,0,0,0,0,15,1,0,0,0,0,17, + 1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0, + 0,1,29,1,0,0,0,3,31,1,0,0,0,5,33,1,0,0,0,7,37,1,0,0,0,9,39,1,0,0,0,11, + 43,1,0,0,0,13,45,1,0,0,0,15,47,1,0,0,0,17,49,1,0,0,0,19,53,1,0,0,0,21, + 55,1,0,0,0,23,57,1,0,0,0,25,59,1,0,0,0,27,61,1,0,0,0,29,30,7,0,0,0,30, + 2,1,0,0,0,31,32,7,1,0,0,32,4,1,0,0,0,33,34,3,1,0,0,34,35,3,3,1,0,35,36, + 3,1,0,0,36,6,1,0,0,0,37,38,7,2,0,0,38,8,1,0,0,0,39,40,7,3,0,0,40,10,1, + 0,0,0,41,44,3,7,3,0,42,44,3,9,4,0,43,41,1,0,0,0,43,42,1,0,0,0,44,12,1, + 0,0,0,45,46,7,4,0,0,46,14,1,0,0,0,47,48,7,5,0,0,48,16,1,0,0,0,49,50,3, + 19,9,0,50,51,3,13,6,0,51,52,3,13,6,0,52,18,1,0,0,0,53,54,5,37,0,0,54,20, + 1,0,0,0,55,56,5,45,0,0,56,22,1,0,0,0,57,58,5,46,0,0,58,24,1,0,0,0,59,60, + 5,58,0,0,60,26,1,0,0,0,61,62,5,95,0,0,62,28,1,0,0,0,2,0,43,0 + ] + + public + static let _ATN: ATN = try! ATNDeserializer().deserialize(_serializedATN) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfListener.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfListener.swift index 90c11ea5..785ce3d2 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfListener.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfListener.swift @@ -1,4 +1,4 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDAbnf.g4 by ANTLR 4.12.0 import Antlr4 /** @@ -6,52 +6,52 @@ import Antlr4 * {@link DIDAbnfParser}. */ public protocol DIDAbnfListener: ParseTreeListener { - /** - * Enter a parse tree produced by {@link DIDAbnfParser#did}. - - Parameters: - - ctx: the parse tree - */ - func enterDid(_ ctx: DIDAbnfParser.DidContext) - /** - * Exit a parse tree produced by {@link DIDAbnfParser#did}. - - Parameters: - - ctx: the parse tree - */ - func exitDid(_ ctx: DIDAbnfParser.DidContext) - /** - * Enter a parse tree produced by {@link DIDAbnfParser#method_name}. - - Parameters: - - ctx: the parse tree - */ - func enterMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) - /** - * Exit a parse tree produced by {@link DIDAbnfParser#method_name}. - - Parameters: - - ctx: the parse tree - */ - func exitMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) - /** - * Enter a parse tree produced by {@link DIDAbnfParser#method_specific_id}. - - Parameters: - - ctx: the parse tree - */ - func enterMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) - /** - * Exit a parse tree produced by {@link DIDAbnfParser#method_specific_id}. - - Parameters: - - ctx: the parse tree - */ - func exitMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) - /** - * Enter a parse tree produced by {@link DIDAbnfParser#idchar}. - - Parameters: - - ctx: the parse tree - */ - func enterIdchar(_ ctx: DIDAbnfParser.IdcharContext) - /** - * Exit a parse tree produced by {@link DIDAbnfParser#idchar}. - - Parameters: - - ctx: the parse tree - */ - func exitIdchar(_ ctx: DIDAbnfParser.IdcharContext) -} + /** + * Enter a parse tree produced by {@link DIDAbnfParser#did}. + - Parameters: + - ctx: the parse tree + */ + func enterDid(_ ctx: DIDAbnfParser.DidContext) + /** + * Exit a parse tree produced by {@link DIDAbnfParser#did}. + - Parameters: + - ctx: the parse tree + */ + func exitDid(_ ctx: DIDAbnfParser.DidContext) + /** + * Enter a parse tree produced by {@link DIDAbnfParser#method_name}. + - Parameters: + - ctx: the parse tree + */ + func enterMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) + /** + * Exit a parse tree produced by {@link DIDAbnfParser#method_name}. + - Parameters: + - ctx: the parse tree + */ + func exitMethod_name(_ ctx: DIDAbnfParser.Method_nameContext) + /** + * Enter a parse tree produced by {@link DIDAbnfParser#method_specific_id}. + - Parameters: + - ctx: the parse tree + */ + func enterMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) + /** + * Exit a parse tree produced by {@link DIDAbnfParser#method_specific_id}. + - Parameters: + - ctx: the parse tree + */ + func exitMethod_specific_id(_ ctx: DIDAbnfParser.Method_specific_idContext) + /** + * Enter a parse tree produced by {@link DIDAbnfParser#idchar}. + - Parameters: + - ctx: the parse tree + */ + func enterIdchar(_ ctx: DIDAbnfParser.IdcharContext) + /** + * Exit a parse tree produced by {@link DIDAbnfParser#idchar}. + - Parameters: + - ctx: the parse tree + */ + func exitIdchar(_ ctx: DIDAbnfParser.IdcharContext) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfParser.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfParser.swift index 97cf286e..7c984d84 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfParser.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDAbnfParser.swift @@ -1,417 +1,403 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDAbnf.g4 by ANTLR 4.12.0 import Antlr4 open class DIDAbnfParser: Parser { - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = DIDAbnfParser._ATN.getNumberOfDecisions() - for i in 0 ..< length { + + internal static var _decisionToDFA: [DFA] = { + var decisionToDFA = [DFA]() + let length = DIDAbnfParser._ATN.getNumberOfDecisions() + for i in 0.. String { return "java-escape" } - - override open - func getRuleNames() -> [String] { return DIDAbnfParser.ruleNames } - - override open - func getSerializedATN() -> [Int] { return DIDAbnfParser._serializedATN } - - override open - func getATN() -> ATN { return DIDAbnfParser._ATN } - - override open - func getVocabulary() -> Vocabulary { - return DIDAbnfParser.VOCABULARY - } - - override public - init(_ input: TokenStream) throws { - RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION) - try super.init(input) - _interp = ParserATNSimulator(self, DIDAbnfParser._ATN, DIDAbnfParser._decisionToDFA, DIDAbnfParser._sharedContextCache) - } - - public class DidContext: ParserRuleContext { - open - func SCHEMA() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.SCHEMA.rawValue, 0) - } - - open - func COLON() -> [TerminalNode] { - return getTokens(DIDAbnfParser.Tokens.COLON.rawValue) - } - - open - func COLON(_ i: Int) -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.COLON.rawValue, i) - } - - open - func method_name() -> Method_nameContext? { - return getRuleContext(Method_nameContext.self, 0) - } - - open - func method_specific_id() -> Method_specific_idContext? { - return getRuleContext(Method_specific_idContext.self, 0) - } - - open - func EOF() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.EOF.rawValue, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDAbnfParser.RULE_did - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.enterDid(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.exitDid(self) - } - } - } - - @discardableResult - open func did() throws -> DidContext { - var _localctx: DidContext - _localctx = DidContext(_ctx, getState()) - try enterRule(_localctx, 0, DIDAbnfParser.RULE_did) - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(8) - try match(DIDAbnfParser.Tokens.SCHEMA.rawValue) - setState(9) - try match(DIDAbnfParser.Tokens.COLON.rawValue) - setState(10) - try method_name() - setState(11) - try match(DIDAbnfParser.Tokens.COLON.rawValue) - setState(12) - try method_specific_id() - setState(13) - try match(DIDAbnfParser.Tokens.EOF.rawValue) - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class Method_nameContext: ParserRuleContext { - open - func ALPHA() -> [TerminalNode] { - return getTokens(DIDAbnfParser.Tokens.ALPHA.rawValue) - } - - open - func ALPHA(_ i: Int) -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.ALPHA.rawValue, i) - } - - open - func DIGIT() -> [TerminalNode] { - return getTokens(DIDAbnfParser.Tokens.DIGIT.rawValue) - } - - open - func DIGIT(_ i: Int) -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.DIGIT.rawValue, i) - } - - override open - func getRuleIndex() -> Int { - return DIDAbnfParser.RULE_method_name - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.enterMethod_name(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.exitMethod_name(self) - } - } - } - - @discardableResult - open func method_name() throws -> Method_nameContext { - var _localctx: Method_nameContext - _localctx = Method_nameContext(_ctx, getState()) - try enterRule(_localctx, 2, DIDAbnfParser.RULE_method_name) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(16) - try _errHandler.sync(self) - _la = try _input.LA(1) - repeat { - setState(15) - _la = try _input.LA(1) - if !(_la == DIDAbnfParser.Tokens.ALPHA.rawValue || _la == DIDAbnfParser.Tokens.DIGIT.rawValue) { - try _errHandler.recoverInline(self) - } else { - _errHandler.reportMatch(self) - try consume() - } - - setState(18) - try _errHandler.sync(self) - _la = try _input.LA(1) - } while _la == DIDAbnfParser.Tokens.ALPHA.rawValue || _la == DIDAbnfParser.Tokens.DIGIT.rawValue - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class Method_specific_idContext: ParserRuleContext { - open - func COLON() -> [TerminalNode] { - return getTokens(DIDAbnfParser.Tokens.COLON.rawValue) - } - - open - func COLON(_ i: Int) -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.COLON.rawValue, i) - } - - open - func idchar() -> [IdcharContext] { - return getRuleContexts(IdcharContext.self) - } - - open - func idchar(_ i: Int) -> IdcharContext? { - return getRuleContext(IdcharContext.self, i) - } - - override open - func getRuleIndex() -> Int { - return DIDAbnfParser.RULE_method_specific_id - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.enterMethod_specific_id(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.exitMethod_specific_id(self) - } - } - } - - @discardableResult - open func method_specific_id() throws -> Method_specific_idContext { - var _localctx: Method_specific_idContext - _localctx = Method_specific_idContext(_ctx, getState()) - try enterRule(_localctx, 4, DIDAbnfParser.RULE_method_specific_id) - var _la = 0 - defer { - try! exitRule() - } - do { - var _alt: Int - try enterOuterAlt(_localctx, 1) - setState(29) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 2, _ctx) - while _alt != 2, _alt != ATN.INVALID_ALT_NUMBER { - if _alt == 1 { - setState(21) - try _errHandler.sync(self) - _la = try _input.LA(1) - repeat { - setState(20) - try idchar() - - setState(23) - try _errHandler.sync(self) - _la = try _input.LA(1) - } while (Int64(_la) & ~0x3F) == 0 && ((Int64(1) << _la) & 732) != 0 - setState(25) - try match(DIDAbnfParser.Tokens.COLON.rawValue) - } - setState(31) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 2, _ctx) - } - setState(33) - try _errHandler.sync(self) - _la = try _input.LA(1) - repeat { - setState(32) - try idchar() - - setState(35) - try _errHandler.sync(self) - _la = try _input.LA(1) - } while (Int64(_la) & ~0x3F) == 0 && ((Int64(1) << _la) & 732) != 0 - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class IdcharContext: ParserRuleContext { - open - func ALPHA() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.ALPHA.rawValue, 0) - } - - open - func DIGIT() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.DIGIT.rawValue, 0) - } - - open - func PERIOD() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.PERIOD.rawValue, 0) - } - - open - func DASH() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.DASH.rawValue, 0) - } - - open - func UNDERSCORE() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.UNDERSCORE.rawValue, 0) - } - - open - func PCT_ENCODED() -> TerminalNode? { - return getToken(DIDAbnfParser.Tokens.PCT_ENCODED.rawValue, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDAbnfParser.RULE_idchar - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.enterIdchar(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDAbnfListener { - listener.exitIdchar(self) - } - } - } - - @discardableResult - open func idchar() throws -> IdcharContext { - var _localctx: IdcharContext - _localctx = IdcharContext(_ctx, getState()) - try enterRule(_localctx, 6, DIDAbnfParser.RULE_idchar) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(37) - _la = try _input.LA(1) - if !((Int64(_la) & ~0x3F) == 0 && ((Int64(1) << _la) & 732) != 0) { - try _errHandler.recoverInline(self) - } else { - _errHandler.reportMatch(self) - try consume() - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - static let _serializedATN: [Int] = [ - 4, 1, 9, 40, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - 1, 4, 1, 17, 8, 1, 11, 1, 12, 1, 18, 1, 2, 4, 2, 22, 8, 2, 11, 2, 12, 2, 23, 1, 2, 1, 2, 5, 2, 28, 8, - 2, 10, 2, 12, 2, 31, 9, 2, 1, 2, 4, 2, 34, 8, 2, 11, 2, 12, 2, 35, 1, 3, 1, 3, 1, 3, 0, 0, 4, 0, 2, 4, - 6, 0, 2, 1, 0, 2, 3, 3, 0, 2, 4, 6, 7, 9, 9, 39, 0, 8, 1, 0, 0, 0, 2, 16, 1, 0, 0, 0, 4, 29, 1, 0, 0, 0, - 6, 37, 1, 0, 0, 0, 8, 9, 5, 1, 0, 0, 9, 10, 5, 8, 0, 0, 10, 11, 3, 2, 1, 0, 11, 12, 5, 8, 0, 0, 12, 13, - 3, 4, 2, 0, 13, 14, 5, 0, 0, 1, 14, 1, 1, 0, 0, 0, 15, 17, 7, 0, 0, 0, 16, 15, 1, 0, 0, 0, 17, 18, 1, - 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 3, 1, 0, 0, 0, 20, 22, 3, 6, 3, 0, 21, 20, 1, 0, - 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 5, 8, - 0, 0, 26, 28, 1, 0, 0, 0, 27, 21, 1, 0, 0, 0, 28, 31, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, 29, 30, 1, 0, - 0, 0, 30, 33, 1, 0, 0, 0, 31, 29, 1, 0, 0, 0, 32, 34, 3, 6, 3, 0, 33, 32, 1, 0, 0, 0, 34, 35, 1, 0, - 0, 0, 35, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 5, 1, 0, 0, 0, 37, 38, 7, 1, 0, 0, 38, 7, 1, 0, 0, - 0, 4, 18, 23, 29, 35 - ] - - public - static let _ATN = try! ATNDeserializer().deserialize(_serializedATN) -} + } + return decisionToDFA + }() + + internal static let _sharedContextCache = PredictionContextCache() + + public + enum Tokens: Int { + case EOF = -1, SCHEMA = 1, ALPHA = 2, DIGIT = 3, PCT_ENCODED = 4, PERCENT = 5, + DASH = 6, PERIOD = 7, COLON = 8, UNDERSCORE = 9 + } + + public + static let RULE_did = 0, RULE_method_name = 1, RULE_method_specific_id = 2, + RULE_idchar = 3 + + public + static let ruleNames: [String] = [ + "did", "method_name", "method_specific_id", "idchar" + ] + + private static let _LITERAL_NAMES: [String?] = [ + nil, nil, nil, nil, nil, "'%'", "'-'", "'.'", "':'", "'_'" + ] + private static let _SYMBOLIC_NAMES: [String?] = [ + nil, "SCHEMA", "ALPHA", "DIGIT", "PCT_ENCODED", "PERCENT", "DASH", "PERIOD", + "COLON", "UNDERSCORE" + ] + public + static let VOCABULARY = Vocabulary(_LITERAL_NAMES, _SYMBOLIC_NAMES) + + override open + func getGrammarFileName() -> String { return "DIDAbnf.g4" } + + override open + func getRuleNames() -> [String] { return DIDAbnfParser.ruleNames } + + override open + func getSerializedATN() -> [Int] { return DIDAbnfParser._serializedATN } + + override open + func getATN() -> ATN { return DIDAbnfParser._ATN } + + + override open + func getVocabulary() -> Vocabulary { + return DIDAbnfParser.VOCABULARY + } + + override public + init(_ input:TokenStream) throws { + RuntimeMetaData.checkVersion("4.12.0", RuntimeMetaData.VERSION) + try super.init(input) + _interp = ParserATNSimulator(self,DIDAbnfParser._ATN,DIDAbnfParser._decisionToDFA, DIDAbnfParser._sharedContextCache) + } + + + public class DidContext: ParserRuleContext { + open + func SCHEMA() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.SCHEMA.rawValue, 0) + } + open + func COLON() -> [TerminalNode] { + return getTokens(DIDAbnfParser.Tokens.COLON.rawValue) + } + open + func COLON(_ i:Int) -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.COLON.rawValue, i) + } + open + func method_name() -> Method_nameContext? { + return getRuleContext(Method_nameContext.self, 0) + } + open + func method_specific_id() -> Method_specific_idContext? { + return getRuleContext(Method_specific_idContext.self, 0) + } + open + func EOF() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.EOF.rawValue, 0) + } + override open + func getRuleIndex() -> Int { + return DIDAbnfParser.RULE_did + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.enterDid(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.exitDid(self) + } + } + } + @discardableResult + open func did() throws -> DidContext { + var _localctx: DidContext + _localctx = DidContext(_ctx, getState()) + try enterRule(_localctx, 0, DIDAbnfParser.RULE_did) + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(8) + try match(DIDAbnfParser.Tokens.SCHEMA.rawValue) + setState(9) + try match(DIDAbnfParser.Tokens.COLON.rawValue) + setState(10) + try method_name() + setState(11) + try match(DIDAbnfParser.Tokens.COLON.rawValue) + setState(12) + try method_specific_id() + setState(13) + try match(DIDAbnfParser.Tokens.EOF.rawValue) + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class Method_nameContext: ParserRuleContext { + open + func ALPHA() -> [TerminalNode] { + return getTokens(DIDAbnfParser.Tokens.ALPHA.rawValue) + } + open + func ALPHA(_ i:Int) -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.ALPHA.rawValue, i) + } + open + func DIGIT() -> [TerminalNode] { + return getTokens(DIDAbnfParser.Tokens.DIGIT.rawValue) + } + open + func DIGIT(_ i:Int) -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.DIGIT.rawValue, i) + } + override open + func getRuleIndex() -> Int { + return DIDAbnfParser.RULE_method_name + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.enterMethod_name(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.exitMethod_name(self) + } + } + } + @discardableResult + open func method_name() throws -> Method_nameContext { + var _localctx: Method_nameContext + _localctx = Method_nameContext(_ctx, getState()) + try enterRule(_localctx, 2, DIDAbnfParser.RULE_method_name) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(16) + try _errHandler.sync(self) + _la = try _input.LA(1) + repeat { + setState(15) + _la = try _input.LA(1) + if (!(_la == DIDAbnfParser.Tokens.ALPHA.rawValue || _la == DIDAbnfParser.Tokens.DIGIT.rawValue)) { + try _errHandler.recoverInline(self) + } + else { + _errHandler.reportMatch(self) + try consume() + } + + + setState(18); + try _errHandler.sync(self) + _la = try _input.LA(1) + } while (_la == DIDAbnfParser.Tokens.ALPHA.rawValue || _la == DIDAbnfParser.Tokens.DIGIT.rawValue) + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class Method_specific_idContext: ParserRuleContext { + open + func COLON() -> [TerminalNode] { + return getTokens(DIDAbnfParser.Tokens.COLON.rawValue) + } + open + func COLON(_ i:Int) -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.COLON.rawValue, i) + } + open + func idchar() -> [IdcharContext] { + return getRuleContexts(IdcharContext.self) + } + open + func idchar(_ i: Int) -> IdcharContext? { + return getRuleContext(IdcharContext.self, i) + } + override open + func getRuleIndex() -> Int { + return DIDAbnfParser.RULE_method_specific_id + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.enterMethod_specific_id(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.exitMethod_specific_id(self) + } + } + } + @discardableResult + open func method_specific_id() throws -> Method_specific_idContext { + var _localctx: Method_specific_idContext + _localctx = Method_specific_idContext(_ctx, getState()) + try enterRule(_localctx, 4, DIDAbnfParser.RULE_method_specific_id) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + var _alt:Int + try enterOuterAlt(_localctx, 1) + setState(29) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,2,_ctx) + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if ( _alt==1 ) { + setState(21) + try _errHandler.sync(self) + _la = try _input.LA(1) + repeat { + setState(20) + try idchar() + + + setState(23); + try _errHandler.sync(self) + _la = try _input.LA(1) + } while (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 732) != 0)) + setState(25) + try match(DIDAbnfParser.Tokens.COLON.rawValue) + + + } + setState(31) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,2,_ctx) + } + setState(33) + try _errHandler.sync(self) + _la = try _input.LA(1) + repeat { + setState(32) + try idchar() + + + setState(35); + try _errHandler.sync(self) + _la = try _input.LA(1) + } while (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 732) != 0)) + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class IdcharContext: ParserRuleContext { + open + func ALPHA() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.ALPHA.rawValue, 0) + } + open + func DIGIT() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.DIGIT.rawValue, 0) + } + open + func PERIOD() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.PERIOD.rawValue, 0) + } + open + func DASH() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.DASH.rawValue, 0) + } + open + func UNDERSCORE() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.UNDERSCORE.rawValue, 0) + } + open + func PCT_ENCODED() -> TerminalNode? { + return getToken(DIDAbnfParser.Tokens.PCT_ENCODED.rawValue, 0) + } + override open + func getRuleIndex() -> Int { + return DIDAbnfParser.RULE_idchar + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.enterIdchar(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDAbnfListener { + listener.exitIdchar(self) + } + } + } + @discardableResult + open func idchar() throws -> IdcharContext { + var _localctx: IdcharContext + _localctx = IdcharContext(_ctx, getState()) + try enterRule(_localctx, 6, DIDAbnfParser.RULE_idchar) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(37) + _la = try _input.LA(1) + if (!(((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 732) != 0))) { + try _errHandler.recoverInline(self) + } + else { + _errHandler.reportMatch(self) + try consume() + } + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + static let _serializedATN:[Int] = [ + 4,1,9,40,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, + 1,4,1,17,8,1,11,1,12,1,18,1,2,4,2,22,8,2,11,2,12,2,23,1,2,1,2,5,2,28,8, + 2,10,2,12,2,31,9,2,1,2,4,2,34,8,2,11,2,12,2,35,1,3,1,3,1,3,0,0,4,0,2,4, + 6,0,2,1,0,2,3,3,0,2,4,6,7,9,9,39,0,8,1,0,0,0,2,16,1,0,0,0,4,29,1,0,0,0, + 6,37,1,0,0,0,8,9,5,1,0,0,9,10,5,8,0,0,10,11,3,2,1,0,11,12,5,8,0,0,12,13, + 3,4,2,0,13,14,5,0,0,1,14,1,1,0,0,0,15,17,7,0,0,0,16,15,1,0,0,0,17,18,1, + 0,0,0,18,16,1,0,0,0,18,19,1,0,0,0,19,3,1,0,0,0,20,22,3,6,3,0,21,20,1,0, + 0,0,22,23,1,0,0,0,23,21,1,0,0,0,23,24,1,0,0,0,24,25,1,0,0,0,25,26,5,8, + 0,0,26,28,1,0,0,0,27,21,1,0,0,0,28,31,1,0,0,0,29,27,1,0,0,0,29,30,1,0, + 0,0,30,33,1,0,0,0,31,29,1,0,0,0,32,34,3,6,3,0,33,32,1,0,0,0,34,35,1,0, + 0,0,35,33,1,0,0,0,35,36,1,0,0,0,36,5,1,0,0,0,37,38,7,1,0,0,38,7,1,0,0, + 0,4,18,23,29,35 + ] + + public + static let _ATN = try! ATNDeserializer().deserialize(_serializedATN) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfBaseListener.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfBaseListener.swift index 9977744c..948cee5c 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfBaseListener.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfBaseListener.swift @@ -1,166 +1,167 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDUrlAbnf.g4 by ANTLR 4.12.0 import Antlr4 + /** * This class provides an empty implementation of {@link DIDUrlAbnfListener}, * which can be extended to create a listener which only needs to handle a subset * of the available methods. */ open class DIDUrlAbnfBaseListener: DIDUrlAbnfListener { - public init() {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) {} + public init() { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterDid(_ ctx: DIDUrlAbnfParser.DidContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitDid(_ ctx: DIDUrlAbnfParser.DidContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterDid(_ ctx: DIDUrlAbnfParser.DidContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitDid(_ ctx: DIDUrlAbnfParser.DidContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterPath(_ ctx: DIDUrlAbnfParser.PathContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitPath(_ ctx: DIDUrlAbnfParser.PathContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterPath(_ ctx: DIDUrlAbnfParser.PathContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitPath(_ ctx: DIDUrlAbnfParser.PathContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterQuery(_ ctx: DIDUrlAbnfParser.QueryContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitQuery(_ ctx: DIDUrlAbnfParser.QueryContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterQuery(_ ctx: DIDUrlAbnfParser.QueryContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitQuery(_ ctx: DIDUrlAbnfParser.QueryContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterFrag(_ ctx: DIDUrlAbnfParser.FragContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitFrag(_ ctx: DIDUrlAbnfParser.FragContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterFrag(_ ctx: DIDUrlAbnfParser.FragContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitFrag(_ ctx: DIDUrlAbnfParser.FragContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterSearch(_ ctx: DIDUrlAbnfParser.SearchContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitSearch(_ ctx: DIDUrlAbnfParser.SearchContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterSearch(_ ctx: DIDUrlAbnfParser.SearchContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitSearch(_ ctx: DIDUrlAbnfParser.SearchContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterString(_ ctx: DIDUrlAbnfParser.StringContext) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitString(_ ctx: DIDUrlAbnfParser.StringContext) {} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterString(_ ctx: DIDUrlAbnfParser.StringContext) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitString(_ ctx: DIDUrlAbnfParser.StringContext) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func enterEveryRule(_ ctx: ParserRuleContext) throws {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func exitEveryRule(_ ctx: ParserRuleContext) throws {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func visitTerminal(_ node: TerminalNode) {} - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - open func visitErrorNode(_ node: ErrorNode) {} -} + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func enterEveryRule(_ ctx: ParserRuleContext) throws { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func exitEveryRule(_ ctx: ParserRuleContext) throws { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func visitTerminal(_ node: TerminalNode) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + open func visitErrorNode(_ node: ErrorNode) { } +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfLexer.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfLexer.swift index abe3a3b2..b577aa52 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfLexer.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfLexer.swift @@ -1,116 +1,118 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDUrlAbnf.g4 by ANTLR 4.12.0 import Antlr4 open class DIDUrlAbnfLexer: Lexer { - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = DIDUrlAbnfLexer._ATN.getNumberOfDecisions() - for i in 0 ..< length { - decisionToDFA.append(DFA(DIDUrlAbnfLexer._ATN.getDecisionState(i)!, i)) - } - return decisionToDFA - }() - - internal static let _sharedContextCache = PredictionContextCache() - - public - static let T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, SCHEMA = 6, ALPHA = 7, DIGIT = 8, - PCT_ENCODED = 9, PERCENT = 10, DASH = 11, PERIOD = 12, COLON = 13, UNDERSCORE = 14, - HEX = 15, STRING = 16 - - public - static let channelNames: [String] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ] - - public - static let modeNames: [String] = [ - "DEFAULT_MODE" - ] - - public - static let ruleNames: [String] = [ - "T__0", "T__1", "T__2", "T__3", "T__4", "D", "I", "SCHEMA", "LOWERCASE", - "UPPERCASE", "ALPHA", "DIGIT", "PCT_ENCODED", "PERCENT", "DASH", "PERIOD", - "COLON", "UNDERSCORE", "HEX", "STRING" - ] - - private static let _LITERAL_NAMES: [String?] = [ - nil, "'/'", "'?'", "'#'", "'&'", "'='", nil, nil, nil, nil, "'%'", "'-'", - "'.'", "':'", "'_'" - ] - private static let _SYMBOLIC_NAMES: [String?] = [ - nil, nil, nil, nil, nil, nil, "SCHEMA", "ALPHA", "DIGIT", "PCT_ENCODED", - "PERCENT", "DASH", "PERIOD", "COLON", "UNDERSCORE", "HEX", "STRING" - ] - public - static let VOCABULARY = Vocabulary(_LITERAL_NAMES, _SYMBOLIC_NAMES) - - override open - func getVocabulary() -> Vocabulary { - return DIDUrlAbnfLexer.VOCABULARY - } - - public - required init(_ input: CharStream) { - RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION) - super.init(input) - _interp = LexerATNSimulator(self, DIDUrlAbnfLexer._ATN, DIDUrlAbnfLexer._decisionToDFA, DIDUrlAbnfLexer._sharedContextCache) - } - - override open - func getGrammarFileName() -> String { return "DIDUrlAbnf.g4" } - - override open - func getRuleNames() -> [String] { return DIDUrlAbnfLexer.ruleNames } - - override open - func getSerializedATN() -> [Int] { return DIDUrlAbnfLexer._serializedATN } - - override open - func getChannelNames() -> [String] { return DIDUrlAbnfLexer.channelNames } - - override open - func getModeNames() -> [String] { return DIDUrlAbnfLexer.modeNames } - - override open - func getATN() -> ATN { return DIDUrlAbnfLexer._ATN } - - static let _serializedATN: [Int] = [ - 4, 0, 16, 101, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, - 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, - 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 1, 0, 1, 0, 1, 1, 1, 1, - 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, - 9, 1, 10, 1, 10, 3, 10, 66, 8, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, - 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 4, 18, 87, 8, 18, 11, 18, 12, - 18, 88, 1, 19, 1, 19, 3, 19, 93, 8, 19, 1, 19, 1, 19, 5, 19, 97, 8, 19, 10, 19, 12, 19, 100, 9, - 19, 0, 0, 20, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 0, 13, 0, 15, 6, 17, 0, 19, 0, 21, 7, 23, 8, 25, 9, - 27, 10, 29, 11, 31, 12, 33, 13, 35, 14, 37, 15, 39, 16, 1, 0, 8, 2, 0, 68, 68, 100, 100, 2, 0, - 73, 73, 105, 105, 1, 0, 97, 122, 1, 0, 65, 90, 1, 0, 48, 57, 3, 0, 48, 57, 65, 70, 97, 102, 4, - 0, 48, 57, 65, 90, 97, 122, 126, 126, 5, 0, 43, 43, 45, 46, 48, 57, 65, 90, 97, 122, 101, 0, - 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, - 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, - 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 1, 41, 1, 0, 0, - 0, 3, 43, 1, 0, 0, 0, 5, 45, 1, 0, 0, 0, 7, 47, 1, 0, 0, 0, 9, 49, 1, 0, 0, 0, 11, 51, 1, 0, 0, 0, 13, - 53, 1, 0, 0, 0, 15, 55, 1, 0, 0, 0, 17, 59, 1, 0, 0, 0, 19, 61, 1, 0, 0, 0, 21, 65, 1, 0, 0, 0, 23, - 67, 1, 0, 0, 0, 25, 69, 1, 0, 0, 0, 27, 73, 1, 0, 0, 0, 29, 75, 1, 0, 0, 0, 31, 77, 1, 0, 0, 0, 33, - 79, 1, 0, 0, 0, 35, 81, 1, 0, 0, 0, 37, 86, 1, 0, 0, 0, 39, 92, 1, 0, 0, 0, 41, 42, 5, 47, 0, 0, 42, - 2, 1, 0, 0, 0, 43, 44, 5, 63, 0, 0, 44, 4, 1, 0, 0, 0, 45, 46, 5, 35, 0, 0, 46, 6, 1, 0, 0, 0, 47, 48, - 5, 38, 0, 0, 48, 8, 1, 0, 0, 0, 49, 50, 5, 61, 0, 0, 50, 10, 1, 0, 0, 0, 51, 52, 7, 0, 0, 0, 52, 12, - 1, 0, 0, 0, 53, 54, 7, 1, 0, 0, 54, 14, 1, 0, 0, 0, 55, 56, 3, 11, 5, 0, 56, 57, 3, 13, 6, 0, 57, 58, - 3, 11, 5, 0, 58, 16, 1, 0, 0, 0, 59, 60, 7, 2, 0, 0, 60, 18, 1, 0, 0, 0, 61, 62, 7, 3, 0, 0, 62, 20, - 1, 0, 0, 0, 63, 66, 3, 17, 8, 0, 64, 66, 3, 19, 9, 0, 65, 63, 1, 0, 0, 0, 65, 64, 1, 0, 0, 0, 66, 22, - 1, 0, 0, 0, 67, 68, 7, 4, 0, 0, 68, 24, 1, 0, 0, 0, 69, 70, 3, 27, 13, 0, 70, 71, 3, 37, 18, 0, 71, - 72, 3, 37, 18, 0, 72, 26, 1, 0, 0, 0, 73, 74, 5, 37, 0, 0, 74, 28, 1, 0, 0, 0, 75, 76, 5, 45, 0, 0, - 76, 30, 1, 0, 0, 0, 77, 78, 5, 46, 0, 0, 78, 32, 1, 0, 0, 0, 79, 80, 5, 58, 0, 0, 80, 34, 1, 0, 0, - 0, 81, 82, 5, 95, 0, 0, 82, 36, 1, 0, 0, 0, 83, 84, 5, 37, 0, 0, 84, 85, 7, 5, 0, 0, 85, 87, 7, 5, - 0, 0, 86, 83, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 86, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 38, 1, 0, - 0, 0, 90, 93, 7, 6, 0, 0, 91, 93, 3, 37, 18, 0, 92, 90, 1, 0, 0, 0, 92, 91, 1, 0, 0, 0, 93, 98, 1, - 0, 0, 0, 94, 97, 7, 7, 0, 0, 95, 97, 3, 37, 18, 0, 96, 94, 1, 0, 0, 0, 96, 95, 1, 0, 0, 0, 97, 100, - 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 40, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 6, 0, 65, - 88, 92, 96, 98, 0 - ] - - public - static let _ATN: ATN = try! ATNDeserializer().deserialize(_serializedATN) -} + + internal static var _decisionToDFA: [DFA] = { + var decisionToDFA = [DFA]() + let length = DIDUrlAbnfLexer._ATN.getNumberOfDecisions() + for i in 0.. Vocabulary { + return DIDUrlAbnfLexer.VOCABULARY + } + + public + required init(_ input: CharStream) { + RuntimeMetaData.checkVersion("4.12.0", RuntimeMetaData.VERSION) + super.init(input) + _interp = LexerATNSimulator(self, DIDUrlAbnfLexer._ATN, DIDUrlAbnfLexer._decisionToDFA, DIDUrlAbnfLexer._sharedContextCache) + } + + override open + func getGrammarFileName() -> String { return "DIDUrlAbnf.g4" } + + override open + func getRuleNames() -> [String] { return DIDUrlAbnfLexer.ruleNames } + + override open + func getSerializedATN() -> [Int] { return DIDUrlAbnfLexer._serializedATN } + + override open + func getChannelNames() -> [String] { return DIDUrlAbnfLexer.channelNames } + + override open + func getModeNames() -> [String] { return DIDUrlAbnfLexer.modeNames } + + override open + func getATN() -> ATN { return DIDUrlAbnfLexer._ATN } + + static let _serializedATN:[Int] = [ + 4,0,16,101,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,1,0,1,0,1,1,1,1, + 1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,9,1, + 9,1,10,1,10,3,10,66,8,10,1,11,1,11,1,12,1,12,1,12,1,12,1,13,1,13,1,14, + 1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,18,1,18,1,18,4,18,87,8,18,11,18,12, + 18,88,1,19,1,19,3,19,93,8,19,1,19,1,19,5,19,97,8,19,10,19,12,19,100,9, + 19,0,0,20,1,1,3,2,5,3,7,4,9,5,11,0,13,0,15,6,17,0,19,0,21,7,23,8,25,9, + 27,10,29,11,31,12,33,13,35,14,37,15,39,16,1,0,8,2,0,68,68,100,100,2,0, + 73,73,105,105,1,0,97,122,1,0,65,90,1,0,48,57,3,0,48,57,65,70,97,102,4, + 0,48,57,65,90,97,122,126,126,5,0,43,43,45,46,48,57,65,90,97,122,101,0, + 1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,15,1,0,0,0, + 0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31, + 1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,1,41,1,0,0, + 0,3,43,1,0,0,0,5,45,1,0,0,0,7,47,1,0,0,0,9,49,1,0,0,0,11,51,1,0,0,0,13, + 53,1,0,0,0,15,55,1,0,0,0,17,59,1,0,0,0,19,61,1,0,0,0,21,65,1,0,0,0,23, + 67,1,0,0,0,25,69,1,0,0,0,27,73,1,0,0,0,29,75,1,0,0,0,31,77,1,0,0,0,33, + 79,1,0,0,0,35,81,1,0,0,0,37,86,1,0,0,0,39,92,1,0,0,0,41,42,5,47,0,0,42, + 2,1,0,0,0,43,44,5,63,0,0,44,4,1,0,0,0,45,46,5,35,0,0,46,6,1,0,0,0,47,48, + 5,38,0,0,48,8,1,0,0,0,49,50,5,61,0,0,50,10,1,0,0,0,51,52,7,0,0,0,52,12, + 1,0,0,0,53,54,7,1,0,0,54,14,1,0,0,0,55,56,3,11,5,0,56,57,3,13,6,0,57,58, + 3,11,5,0,58,16,1,0,0,0,59,60,7,2,0,0,60,18,1,0,0,0,61,62,7,3,0,0,62,20, + 1,0,0,0,63,66,3,17,8,0,64,66,3,19,9,0,65,63,1,0,0,0,65,64,1,0,0,0,66,22, + 1,0,0,0,67,68,7,4,0,0,68,24,1,0,0,0,69,70,3,27,13,0,70,71,3,37,18,0,71, + 72,3,37,18,0,72,26,1,0,0,0,73,74,5,37,0,0,74,28,1,0,0,0,75,76,5,45,0,0, + 76,30,1,0,0,0,77,78,5,46,0,0,78,32,1,0,0,0,79,80,5,58,0,0,80,34,1,0,0, + 0,81,82,5,95,0,0,82,36,1,0,0,0,83,84,5,37,0,0,84,85,7,5,0,0,85,87,7,5, + 0,0,86,83,1,0,0,0,87,88,1,0,0,0,88,86,1,0,0,0,88,89,1,0,0,0,89,38,1,0, + 0,0,90,93,7,6,0,0,91,93,3,37,18,0,92,90,1,0,0,0,92,91,1,0,0,0,93,98,1, + 0,0,0,94,97,7,7,0,0,95,97,3,37,18,0,96,94,1,0,0,0,96,95,1,0,0,0,97,100, + 1,0,0,0,98,96,1,0,0,0,98,99,1,0,0,0,99,40,1,0,0,0,100,98,1,0,0,0,6,0,65, + 88,92,96,98,0 + ] + + public + static let _ATN: ATN = try! ATNDeserializer().deserialize(_serializedATN) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfListener.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfListener.swift index ade4b2c0..701543ac 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfListener.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfListener.swift @@ -1,4 +1,4 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDUrlAbnf.g4 by ANTLR 4.12.0 import Antlr4 /** @@ -6,124 +6,124 @@ import Antlr4 * {@link DIDUrlAbnfParser}. */ public protocol DIDUrlAbnfListener: ParseTreeListener { - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#did_url}. - - Parameters: - - ctx: the parse tree - */ - func enterDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#did_url}. - - Parameters: - - ctx: the parse tree - */ - func exitDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#did}. - - Parameters: - - ctx: the parse tree - */ - func enterDid(_ ctx: DIDUrlAbnfParser.DidContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#did}. - - Parameters: - - ctx: the parse tree - */ - func exitDid(_ ctx: DIDUrlAbnfParser.DidContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#method_name}. - - Parameters: - - ctx: the parse tree - */ - func enterMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#method_name}. - - Parameters: - - ctx: the parse tree - */ - func exitMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#method_specific_id}. - - Parameters: - - ctx: the parse tree - */ - func enterMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#method_specific_id}. - - Parameters: - - ctx: the parse tree - */ - func exitMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#path}. - - Parameters: - - ctx: the parse tree - */ - func enterPath(_ ctx: DIDUrlAbnfParser.PathContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#path}. - - Parameters: - - ctx: the parse tree - */ - func exitPath(_ ctx: DIDUrlAbnfParser.PathContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#query}. - - Parameters: - - ctx: the parse tree - */ - func enterQuery(_ ctx: DIDUrlAbnfParser.QueryContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#query}. - - Parameters: - - ctx: the parse tree - */ - func exitQuery(_ ctx: DIDUrlAbnfParser.QueryContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#frag}. - - Parameters: - - ctx: the parse tree - */ - func enterFrag(_ ctx: DIDUrlAbnfParser.FragContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#frag}. - - Parameters: - - ctx: the parse tree - */ - func exitFrag(_ ctx: DIDUrlAbnfParser.FragContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#search}. - - Parameters: - - ctx: the parse tree - */ - func enterSearch(_ ctx: DIDUrlAbnfParser.SearchContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#search}. - - Parameters: - - ctx: the parse tree - */ - func exitSearch(_ ctx: DIDUrlAbnfParser.SearchContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#searchparameter}. - - Parameters: - - ctx: the parse tree - */ - func enterSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#searchparameter}. - - Parameters: - - ctx: the parse tree - */ - func exitSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) - /** - * Enter a parse tree produced by {@link DIDUrlAbnfParser#string}. - - Parameters: - - ctx: the parse tree - */ - func enterString(_ ctx: DIDUrlAbnfParser.StringContext) - /** - * Exit a parse tree produced by {@link DIDUrlAbnfParser#string}. - - Parameters: - - ctx: the parse tree - */ - func exitString(_ ctx: DIDUrlAbnfParser.StringContext) -} + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#did_url}. + - Parameters: + - ctx: the parse tree + */ + func enterDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#did_url}. + - Parameters: + - ctx: the parse tree + */ + func exitDid_url(_ ctx: DIDUrlAbnfParser.Did_urlContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#did}. + - Parameters: + - ctx: the parse tree + */ + func enterDid(_ ctx: DIDUrlAbnfParser.DidContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#did}. + - Parameters: + - ctx: the parse tree + */ + func exitDid(_ ctx: DIDUrlAbnfParser.DidContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#method_name}. + - Parameters: + - ctx: the parse tree + */ + func enterMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#method_name}. + - Parameters: + - ctx: the parse tree + */ + func exitMethod_name(_ ctx: DIDUrlAbnfParser.Method_nameContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#method_specific_id}. + - Parameters: + - ctx: the parse tree + */ + func enterMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#method_specific_id}. + - Parameters: + - ctx: the parse tree + */ + func exitMethod_specific_id(_ ctx: DIDUrlAbnfParser.Method_specific_idContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#path}. + - Parameters: + - ctx: the parse tree + */ + func enterPath(_ ctx: DIDUrlAbnfParser.PathContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#path}. + - Parameters: + - ctx: the parse tree + */ + func exitPath(_ ctx: DIDUrlAbnfParser.PathContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#query}. + - Parameters: + - ctx: the parse tree + */ + func enterQuery(_ ctx: DIDUrlAbnfParser.QueryContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#query}. + - Parameters: + - ctx: the parse tree + */ + func exitQuery(_ ctx: DIDUrlAbnfParser.QueryContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#frag}. + - Parameters: + - ctx: the parse tree + */ + func enterFrag(_ ctx: DIDUrlAbnfParser.FragContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#frag}. + - Parameters: + - ctx: the parse tree + */ + func exitFrag(_ ctx: DIDUrlAbnfParser.FragContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#search}. + - Parameters: + - ctx: the parse tree + */ + func enterSearch(_ ctx: DIDUrlAbnfParser.SearchContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#search}. + - Parameters: + - ctx: the parse tree + */ + func exitSearch(_ ctx: DIDUrlAbnfParser.SearchContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#searchparameter}. + - Parameters: + - ctx: the parse tree + */ + func enterSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#searchparameter}. + - Parameters: + - ctx: the parse tree + */ + func exitSearchparameter(_ ctx: DIDUrlAbnfParser.SearchparameterContext) + /** + * Enter a parse tree produced by {@link DIDUrlAbnfParser#string}. + - Parameters: + - ctx: the parse tree + */ + func enterString(_ ctx: DIDUrlAbnfParser.StringContext) + /** + * Exit a parse tree produced by {@link DIDUrlAbnfParser#string}. + - Parameters: + - ctx: the parse tree + */ + func exitString(_ ctx: DIDUrlAbnfParser.StringContext) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfParser.swift b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfParser.swift index 6288341d..3267a0c2 100644 --- a/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfParser.swift +++ b/AtalaPrismSDK/Castor/Sources/DIDParser/DIDGrammar/DIDUrlAbnfParser.swift @@ -1,799 +1,784 @@ -// Generated from java-escape by ANTLR 4.11.1 +// Generated from DIDUrlAbnf.g4 by ANTLR 4.12.0 import Antlr4 open class DIDUrlAbnfParser: Parser { - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = DIDUrlAbnfParser._ATN.getNumberOfDecisions() - for i in 0 ..< length { + + internal static var _decisionToDFA: [DFA] = { + var decisionToDFA = [DFA]() + let length = DIDUrlAbnfParser._ATN.getNumberOfDecisions() + for i in 0.. String { return "java-escape" } - - override open - func getRuleNames() -> [String] { return DIDUrlAbnfParser.ruleNames } - - override open - func getSerializedATN() -> [Int] { return DIDUrlAbnfParser._serializedATN } - - override open - func getATN() -> ATN { return DIDUrlAbnfParser._ATN } - - override open - func getVocabulary() -> Vocabulary { - return DIDUrlAbnfParser.VOCABULARY - } - - override public - init(_ input: TokenStream) throws { - RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION) - try super.init(input) - _interp = ParserATNSimulator(self, DIDUrlAbnfParser._ATN, DIDUrlAbnfParser._decisionToDFA, DIDUrlAbnfParser._sharedContextCache) - } - - public class Did_urlContext: ParserRuleContext { - open - func did() -> DidContext? { - return getRuleContext(DidContext.self, 0) - } - - open - func EOF() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.EOF.rawValue, 0) - } - - open - func path() -> PathContext? { - return getRuleContext(PathContext.self, 0) - } - - open - func query() -> QueryContext? { - return getRuleContext(QueryContext.self, 0) - } - - open - func frag() -> FragContext? { - return getRuleContext(FragContext.self, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_did_url - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterDid_url(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitDid_url(self) - } - } - } - - @discardableResult - open func did_url() throws -> Did_urlContext { - var _localctx: Did_urlContext - _localctx = Did_urlContext(_ctx, getState()) - try enterRule(_localctx, 0, DIDUrlAbnfParser.RULE_did_url) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(20) - try did() - setState(22) - try _errHandler.sync(self) - switch try getInterpreter().adaptivePredict(_input, 0, _ctx) { - case 1: - setState(21) - try path() - - default: break - } - setState(25) - try _errHandler.sync(self) - _la = try _input.LA(1) - if _la == DIDUrlAbnfParser.Tokens.T__1.rawValue { - setState(24) - try query() - } - - setState(28) - try _errHandler.sync(self) - _la = try _input.LA(1) - if _la == DIDUrlAbnfParser.Tokens.T__2.rawValue { - setState(27) - try frag() - } - - setState(30) - try match(DIDUrlAbnfParser.Tokens.EOF.rawValue) - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class DidContext: ParserRuleContext { - open - func SCHEMA() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.SCHEMA.rawValue, 0) - } - - open - func COLON() -> [TerminalNode] { - return getTokens(DIDUrlAbnfParser.Tokens.COLON.rawValue) - } - - open - func COLON(_ i: Int) -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.COLON.rawValue, i) - } - - open - func method_name() -> Method_nameContext? { - return getRuleContext(Method_nameContext.self, 0) - } - - open - func method_specific_id() -> Method_specific_idContext? { - return getRuleContext(Method_specific_idContext.self, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_did - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterDid(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitDid(self) - } - } - } - - @discardableResult - open func did() throws -> DidContext { - var _localctx: DidContext - _localctx = DidContext(_ctx, getState()) - try enterRule(_localctx, 2, DIDUrlAbnfParser.RULE_did) - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(32) - try match(DIDUrlAbnfParser.Tokens.SCHEMA.rawValue) - setState(33) - try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) - setState(34) - try method_name() - setState(35) - try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) - setState(36) - try method_specific_id() - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class Method_nameContext: ParserRuleContext { - open - func string() -> StringContext? { - return getRuleContext(StringContext.self, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_method_name - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterMethod_name(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitMethod_name(self) - } - } - } - - @discardableResult - open func method_name() throws -> Method_nameContext { - var _localctx: Method_nameContext - _localctx = Method_nameContext(_ctx, getState()) - try enterRule(_localctx, 4, DIDUrlAbnfParser.RULE_method_name) - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(38) - try string() - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class Method_specific_idContext: ParserRuleContext { - open - func string() -> [StringContext] { - return getRuleContexts(StringContext.self) - } - - open - func string(_ i: Int) -> StringContext? { - return getRuleContext(StringContext.self, i) - } - - open - func COLON() -> [TerminalNode] { - return getTokens(DIDUrlAbnfParser.Tokens.COLON.rawValue) - } - - open - func COLON(_ i: Int) -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.COLON.rawValue, i) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_method_specific_id - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterMethod_specific_id(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitMethod_specific_id(self) - } - } - } - - @discardableResult - open func method_specific_id() throws -> Method_specific_idContext { - var _localctx: Method_specific_idContext - _localctx = Method_specific_idContext(_ctx, getState()) - try enterRule(_localctx, 6, DIDUrlAbnfParser.RULE_method_specific_id) - var _la = 0 - defer { - try! exitRule() - } - do { - var _alt: Int - try enterOuterAlt(_localctx, 1) - setState(46) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 4, _ctx) - while _alt != 2, _alt != ATN.INVALID_ALT_NUMBER { - if _alt == 1 { - setState(40) - try string() - setState(42) - try _errHandler.sync(self) - _la = try _input.LA(1) - if _la == DIDUrlAbnfParser.Tokens.COLON.rawValue { - setState(41) - try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) - } - } - setState(48) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 4, _ctx) - } - setState(49) - try string() - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class PathContext: ParserRuleContext { - open - func string() -> [StringContext] { - return getRuleContexts(StringContext.self) - } - - open - func string(_ i: Int) -> StringContext? { - return getRuleContext(StringContext.self, i) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_path - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterPath(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitPath(self) - } - } - } - - @discardableResult - open func path() throws -> PathContext { - var _localctx: PathContext - _localctx = PathContext(_ctx, getState()) - try enterRule(_localctx, 8, DIDUrlAbnfParser.RULE_path) - var _la = 0 - defer { - try! exitRule() - } - do { - var _alt: Int - try enterOuterAlt(_localctx, 1) - setState(55) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 5, _ctx) - while _alt != 2, _alt != ATN.INVALID_ALT_NUMBER { - if _alt == 1 { - setState(51) - try match(DIDUrlAbnfParser.Tokens.T__0.rawValue) - setState(52) - try string() - } - setState(57) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input, 5, _ctx) - } - setState(59) - try _errHandler.sync(self) - _la = try _input.LA(1) - if _la == DIDUrlAbnfParser.Tokens.T__0.rawValue { - setState(58) - try match(DIDUrlAbnfParser.Tokens.T__0.rawValue) - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class QueryContext: ParserRuleContext { - open - func search() -> SearchContext? { - return getRuleContext(SearchContext.self, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_query - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterQuery(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitQuery(self) - } - } - } - - @discardableResult - open func query() throws -> QueryContext { - var _localctx: QueryContext - _localctx = QueryContext(_ctx, getState()) - try enterRule(_localctx, 10, DIDUrlAbnfParser.RULE_query) - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(61) - try match(DIDUrlAbnfParser.Tokens.T__1.rawValue) - setState(62) - try search() - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class FragContext: ParserRuleContext { - open - func string() -> StringContext? { - return getRuleContext(StringContext.self, 0) - } - - open - func DIGIT() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_frag - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterFrag(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitFrag(self) - } - } - } - - @discardableResult - open func frag() throws -> FragContext { - var _localctx: FragContext - _localctx = FragContext(_ctx, getState()) - try enterRule(_localctx, 12, DIDUrlAbnfParser.RULE_frag) - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(64) - try match(DIDUrlAbnfParser.Tokens.T__2.rawValue) - setState(67) - try _errHandler.sync(self) - switch try getInterpreter().adaptivePredict(_input, 7, _ctx) { - case 1: - setState(65) - try string() - - case 2: - setState(66) - try match(DIDUrlAbnfParser.Tokens.DIGIT.rawValue) - - default: break - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class SearchContext: ParserRuleContext { - open - func searchparameter() -> [SearchparameterContext] { - return getRuleContexts(SearchparameterContext.self) - } - - open - func searchparameter(_ i: Int) -> SearchparameterContext? { - return getRuleContext(SearchparameterContext.self, i) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_search - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterSearch(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitSearch(self) - } - } - } - - @discardableResult - open func search() throws -> SearchContext { - var _localctx: SearchContext - _localctx = SearchContext(_ctx, getState()) - try enterRule(_localctx, 14, DIDUrlAbnfParser.RULE_search) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(69) - try searchparameter() - setState(74) - try _errHandler.sync(self) - _la = try _input.LA(1) - while _la == DIDUrlAbnfParser.Tokens.T__3.rawValue { - setState(70) - try match(DIDUrlAbnfParser.Tokens.T__3.rawValue) - setState(71) - try searchparameter() - - setState(76) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class SearchparameterContext: ParserRuleContext { - open - func string() -> [StringContext] { - return getRuleContexts(StringContext.self) - } - - open - func string(_ i: Int) -> StringContext? { - return getRuleContext(StringContext.self, i) - } - - open - func DIGIT() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) - } - - open - func HEX() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.HEX.rawValue, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_searchparameter - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterSearchparameter(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitSearchparameter(self) - } - } - } - - @discardableResult - open func searchparameter() throws -> SearchparameterContext { - var _localctx: SearchparameterContext - _localctx = SearchparameterContext(_ctx, getState()) - try enterRule(_localctx, 16, DIDUrlAbnfParser.RULE_searchparameter) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(77) - try string() - setState(84) - try _errHandler.sync(self) - _la = try _input.LA(1) - if _la == DIDUrlAbnfParser.Tokens.T__4.rawValue { - setState(78) - try match(DIDUrlAbnfParser.Tokens.T__4.rawValue) - setState(82) - try _errHandler.sync(self) - switch try getInterpreter().adaptivePredict(_input, 9, _ctx) { - case 1: - setState(79) - try string() - - case 2: - setState(80) - try match(DIDUrlAbnfParser.Tokens.DIGIT.rawValue) - - case 3: - setState(81) - try match(DIDUrlAbnfParser.Tokens.HEX.rawValue) - - default: break - } - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class StringContext: ParserRuleContext { - open - func STRING() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.STRING.rawValue, 0) - } - - open - func DIGIT() -> TerminalNode? { - return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) - } - - override open - func getRuleIndex() -> Int { - return DIDUrlAbnfParser.RULE_string - } - - override open - func enterRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.enterString(self) - } - } - - override open - func exitRule(_ listener: ParseTreeListener) { - if let listener = listener as? DIDUrlAbnfListener { - listener.exitString(self) - } - } - } - - @discardableResult - open func string() throws -> StringContext { - var _localctx: StringContext - _localctx = StringContext(_ctx, getState()) - try enterRule(_localctx, 18, DIDUrlAbnfParser.RULE_string) - var _la = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(86) - _la = try _input.LA(1) - if !(_la == DIDUrlAbnfParser.Tokens.DIGIT.rawValue || _la == DIDUrlAbnfParser.Tokens.STRING.rawValue) { - try _errHandler.recoverInline(self) - } else { - _errHandler.reportMatch(self) - try consume() - } - } catch let ANTLRException.recognition(re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - static let _serializedATN: [Int] = [ - 4, 1, 16, 89, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, - 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 1, 0, 3, 0, 23, 8, 0, 1, 0, 3, 0, 26, 8, 0, 1, 0, 3, 0, 29, 8, 0, 1, - 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 43, 8, 3, 5, 3, 45, 8, 3, 10, - 3, 12, 3, 48, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 5, 4, 54, 8, 4, 10, 4, 12, 4, 57, 9, 4, 1, 4, 3, 4, 60, 8, - 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 3, 6, 68, 8, 6, 1, 7, 1, 7, 1, 7, 5, 7, 73, 8, 7, 10, 7, 12, 7, - 76, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 83, 8, 8, 3, 8, 85, 8, 8, 1, 9, 1, 9, 1, 9, 0, 0, 10, 0, - 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 1, 2, 0, 8, 8, 16, 16, 90, 0, 20, 1, 0, 0, 0, 2, 32, 1, 0, 0, 0, - 4, 38, 1, 0, 0, 0, 6, 46, 1, 0, 0, 0, 8, 55, 1, 0, 0, 0, 10, 61, 1, 0, 0, 0, 12, 64, 1, 0, 0, 0, 14, - 69, 1, 0, 0, 0, 16, 77, 1, 0, 0, 0, 18, 86, 1, 0, 0, 0, 20, 22, 3, 2, 1, 0, 21, 23, 3, 8, 4, 0, 22, - 21, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 25, 1, 0, 0, 0, 24, 26, 3, 10, 5, 0, 25, 24, 1, 0, 0, 0, 25, - 26, 1, 0, 0, 0, 26, 28, 1, 0, 0, 0, 27, 29, 3, 12, 6, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, - 30, 1, 0, 0, 0, 30, 31, 5, 0, 0, 1, 31, 1, 1, 0, 0, 0, 32, 33, 5, 6, 0, 0, 33, 34, 5, 13, 0, 0, 34, - 35, 3, 4, 2, 0, 35, 36, 5, 13, 0, 0, 36, 37, 3, 6, 3, 0, 37, 3, 1, 0, 0, 0, 38, 39, 3, 18, 9, 0, 39, - 5, 1, 0, 0, 0, 40, 42, 3, 18, 9, 0, 41, 43, 5, 13, 0, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, - 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, - 49, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 50, 3, 18, 9, 0, 50, 7, 1, 0, 0, 0, 51, 52, 5, 1, 0, 0, 52, - 54, 3, 18, 9, 0, 53, 51, 1, 0, 0, 0, 54, 57, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, - 59, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 58, 60, 5, 1, 0, 0, 59, 58, 1, 0, 0, 0, 59, 60, 1, 0, 0, 0, 60, - 9, 1, 0, 0, 0, 61, 62, 5, 2, 0, 0, 62, 63, 3, 14, 7, 0, 63, 11, 1, 0, 0, 0, 64, 67, 5, 3, 0, 0, 65, - 68, 3, 18, 9, 0, 66, 68, 5, 8, 0, 0, 67, 65, 1, 0, 0, 0, 67, 66, 1, 0, 0, 0, 68, 13, 1, 0, 0, 0, 69, - 74, 3, 16, 8, 0, 70, 71, 5, 4, 0, 0, 71, 73, 3, 16, 8, 0, 72, 70, 1, 0, 0, 0, 73, 76, 1, 0, 0, 0, 74, - 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 15, 1, 0, 0, 0, 76, 74, 1, 0, 0, 0, 77, 84, 3, 18, 9, 0, 78, - 82, 5, 5, 0, 0, 79, 83, 3, 18, 9, 0, 80, 83, 5, 8, 0, 0, 81, 83, 5, 15, 0, 0, 82, 79, 1, 0, 0, 0, 82, - 80, 1, 0, 0, 0, 82, 81, 1, 0, 0, 0, 83, 85, 1, 0, 0, 0, 84, 78, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, - 17, 1, 0, 0, 0, 86, 87, 7, 0, 0, 0, 87, 19, 1, 0, 0, 0, 11, 22, 25, 28, 42, 46, 55, 59, 67, 74, 82, - 84 - ] - - public - static let _ATN = try! ATNDeserializer().deserialize(_serializedATN) -} + } + return decisionToDFA + }() + + internal static let _sharedContextCache = PredictionContextCache() + + public + enum Tokens: Int { + case EOF = -1, T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, SCHEMA = 6, + ALPHA = 7, DIGIT = 8, PCT_ENCODED = 9, PERCENT = 10, DASH = 11, + PERIOD = 12, COLON = 13, UNDERSCORE = 14, HEX = 15, STRING = 16 + } + + public + static let RULE_did_url = 0, RULE_did = 1, RULE_method_name = 2, RULE_method_specific_id = 3, + RULE_path = 4, RULE_query = 5, RULE_frag = 6, RULE_search = 7, + RULE_searchparameter = 8, RULE_string = 9 + + public + static let ruleNames: [String] = [ + "did_url", "did", "method_name", "method_specific_id", "path", "query", + "frag", "search", "searchparameter", "string" + ] + + private static let _LITERAL_NAMES: [String?] = [ + nil, "'/'", "'?'", "'#'", "'&'", "'='", nil, nil, nil, nil, "'%'", "'-'", + "'.'", "':'", "'_'" + ] + private static let _SYMBOLIC_NAMES: [String?] = [ + nil, nil, nil, nil, nil, nil, "SCHEMA", "ALPHA", "DIGIT", "PCT_ENCODED", + "PERCENT", "DASH", "PERIOD", "COLON", "UNDERSCORE", "HEX", "STRING" + ] + public + static let VOCABULARY = Vocabulary(_LITERAL_NAMES, _SYMBOLIC_NAMES) + + override open + func getGrammarFileName() -> String { return "DIDUrlAbnf.g4" } + + override open + func getRuleNames() -> [String] { return DIDUrlAbnfParser.ruleNames } + + override open + func getSerializedATN() -> [Int] { return DIDUrlAbnfParser._serializedATN } + + override open + func getATN() -> ATN { return DIDUrlAbnfParser._ATN } + + + override open + func getVocabulary() -> Vocabulary { + return DIDUrlAbnfParser.VOCABULARY + } + + override public + init(_ input:TokenStream) throws { + RuntimeMetaData.checkVersion("4.12.0", RuntimeMetaData.VERSION) + try super.init(input) + _interp = ParserATNSimulator(self,DIDUrlAbnfParser._ATN,DIDUrlAbnfParser._decisionToDFA, DIDUrlAbnfParser._sharedContextCache) + } + + + public class Did_urlContext: ParserRuleContext { + open + func did() -> DidContext? { + return getRuleContext(DidContext.self, 0) + } + open + func EOF() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.EOF.rawValue, 0) + } + open + func path() -> PathContext? { + return getRuleContext(PathContext.self, 0) + } + open + func query() -> QueryContext? { + return getRuleContext(QueryContext.self, 0) + } + open + func frag() -> FragContext? { + return getRuleContext(FragContext.self, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_did_url + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterDid_url(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitDid_url(self) + } + } + } + @discardableResult + open func did_url() throws -> Did_urlContext { + var _localctx: Did_urlContext + _localctx = Did_urlContext(_ctx, getState()) + try enterRule(_localctx, 0, DIDUrlAbnfParser.RULE_did_url) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(20) + try did() + setState(22) + try _errHandler.sync(self) + switch (try getInterpreter().adaptivePredict(_input,0,_ctx)) { + case 1: + setState(21) + try path() + + break + default: break + } + setState(25) + try _errHandler.sync(self) + _la = try _input.LA(1) + if (_la == DIDUrlAbnfParser.Tokens.T__1.rawValue) { + setState(24) + try query() + + } + + setState(28) + try _errHandler.sync(self) + _la = try _input.LA(1) + if (_la == DIDUrlAbnfParser.Tokens.T__2.rawValue) { + setState(27) + try frag() + + } + + setState(30) + try match(DIDUrlAbnfParser.Tokens.EOF.rawValue) + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class DidContext: ParserRuleContext { + open + func SCHEMA() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.SCHEMA.rawValue, 0) + } + open + func COLON() -> [TerminalNode] { + return getTokens(DIDUrlAbnfParser.Tokens.COLON.rawValue) + } + open + func COLON(_ i:Int) -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.COLON.rawValue, i) + } + open + func method_name() -> Method_nameContext? { + return getRuleContext(Method_nameContext.self, 0) + } + open + func method_specific_id() -> Method_specific_idContext? { + return getRuleContext(Method_specific_idContext.self, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_did + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterDid(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitDid(self) + } + } + } + @discardableResult + open func did() throws -> DidContext { + var _localctx: DidContext + _localctx = DidContext(_ctx, getState()) + try enterRule(_localctx, 2, DIDUrlAbnfParser.RULE_did) + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(32) + try match(DIDUrlAbnfParser.Tokens.SCHEMA.rawValue) + setState(33) + try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) + setState(34) + try method_name() + setState(35) + try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) + setState(36) + try method_specific_id() + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class Method_nameContext: ParserRuleContext { + open + func string() -> StringContext? { + return getRuleContext(StringContext.self, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_method_name + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterMethod_name(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitMethod_name(self) + } + } + } + @discardableResult + open func method_name() throws -> Method_nameContext { + var _localctx: Method_nameContext + _localctx = Method_nameContext(_ctx, getState()) + try enterRule(_localctx, 4, DIDUrlAbnfParser.RULE_method_name) + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(38) + try string() + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class Method_specific_idContext: ParserRuleContext { + open + func string() -> [StringContext] { + return getRuleContexts(StringContext.self) + } + open + func string(_ i: Int) -> StringContext? { + return getRuleContext(StringContext.self, i) + } + open + func COLON() -> [TerminalNode] { + return getTokens(DIDUrlAbnfParser.Tokens.COLON.rawValue) + } + open + func COLON(_ i:Int) -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.COLON.rawValue, i) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_method_specific_id + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterMethod_specific_id(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitMethod_specific_id(self) + } + } + } + @discardableResult + open func method_specific_id() throws -> Method_specific_idContext { + var _localctx: Method_specific_idContext + _localctx = Method_specific_idContext(_ctx, getState()) + try enterRule(_localctx, 6, DIDUrlAbnfParser.RULE_method_specific_id) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + var _alt:Int + try enterOuterAlt(_localctx, 1) + setState(46) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,4,_ctx) + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if ( _alt==1 ) { + setState(40) + try string() + setState(42) + try _errHandler.sync(self) + _la = try _input.LA(1) + if (_la == DIDUrlAbnfParser.Tokens.COLON.rawValue) { + setState(41) + try match(DIDUrlAbnfParser.Tokens.COLON.rawValue) + + } + + + + } + setState(48) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,4,_ctx) + } + setState(49) + try string() + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class PathContext: ParserRuleContext { + open + func string() -> [StringContext] { + return getRuleContexts(StringContext.self) + } + open + func string(_ i: Int) -> StringContext? { + return getRuleContext(StringContext.self, i) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_path + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterPath(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitPath(self) + } + } + } + @discardableResult + open func path() throws -> PathContext { + var _localctx: PathContext + _localctx = PathContext(_ctx, getState()) + try enterRule(_localctx, 8, DIDUrlAbnfParser.RULE_path) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + var _alt:Int + try enterOuterAlt(_localctx, 1) + setState(55) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,5,_ctx) + while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { + if ( _alt==1 ) { + setState(51) + try match(DIDUrlAbnfParser.Tokens.T__0.rawValue) + setState(52) + try string() + + + } + setState(57) + try _errHandler.sync(self) + _alt = try getInterpreter().adaptivePredict(_input,5,_ctx) + } + setState(59) + try _errHandler.sync(self) + _la = try _input.LA(1) + if (_la == DIDUrlAbnfParser.Tokens.T__0.rawValue) { + setState(58) + try match(DIDUrlAbnfParser.Tokens.T__0.rawValue) + + } + + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class QueryContext: ParserRuleContext { + open + func search() -> SearchContext? { + return getRuleContext(SearchContext.self, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_query + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterQuery(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitQuery(self) + } + } + } + @discardableResult + open func query() throws -> QueryContext { + var _localctx: QueryContext + _localctx = QueryContext(_ctx, getState()) + try enterRule(_localctx, 10, DIDUrlAbnfParser.RULE_query) + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(61) + try match(DIDUrlAbnfParser.Tokens.T__1.rawValue) + setState(62) + try search() + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class FragContext: ParserRuleContext { + open + func string() -> StringContext? { + return getRuleContext(StringContext.self, 0) + } + open + func DIGIT() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_frag + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterFrag(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitFrag(self) + } + } + } + @discardableResult + open func frag() throws -> FragContext { + var _localctx: FragContext + _localctx = FragContext(_ctx, getState()) + try enterRule(_localctx, 12, DIDUrlAbnfParser.RULE_frag) + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(64) + try match(DIDUrlAbnfParser.Tokens.T__2.rawValue) + setState(67) + try _errHandler.sync(self) + switch(try getInterpreter().adaptivePredict(_input,7, _ctx)) { + case 1: + setState(65) + try string() + + break + case 2: + setState(66) + try match(DIDUrlAbnfParser.Tokens.DIGIT.rawValue) + + break + default: break + } + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class SearchContext: ParserRuleContext { + open + func searchparameter() -> [SearchparameterContext] { + return getRuleContexts(SearchparameterContext.self) + } + open + func searchparameter(_ i: Int) -> SearchparameterContext? { + return getRuleContext(SearchparameterContext.self, i) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_search + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterSearch(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitSearch(self) + } + } + } + @discardableResult + open func search() throws -> SearchContext { + var _localctx: SearchContext + _localctx = SearchContext(_ctx, getState()) + try enterRule(_localctx, 14, DIDUrlAbnfParser.RULE_search) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(69) + try searchparameter() + setState(74) + try _errHandler.sync(self) + _la = try _input.LA(1) + while (_la == DIDUrlAbnfParser.Tokens.T__3.rawValue) { + setState(70) + try match(DIDUrlAbnfParser.Tokens.T__3.rawValue) + setState(71) + try searchparameter() + + + setState(76) + try _errHandler.sync(self) + _la = try _input.LA(1) + } + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class SearchparameterContext: ParserRuleContext { + open + func string() -> [StringContext] { + return getRuleContexts(StringContext.self) + } + open + func string(_ i: Int) -> StringContext? { + return getRuleContext(StringContext.self, i) + } + open + func DIGIT() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) + } + open + func HEX() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.HEX.rawValue, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_searchparameter + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterSearchparameter(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitSearchparameter(self) + } + } + } + @discardableResult + open func searchparameter() throws -> SearchparameterContext { + var _localctx: SearchparameterContext + _localctx = SearchparameterContext(_ctx, getState()) + try enterRule(_localctx, 16, DIDUrlAbnfParser.RULE_searchparameter) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(77) + try string() + setState(84) + try _errHandler.sync(self) + _la = try _input.LA(1) + if (_la == DIDUrlAbnfParser.Tokens.T__4.rawValue) { + setState(78) + try match(DIDUrlAbnfParser.Tokens.T__4.rawValue) + setState(82) + try _errHandler.sync(self) + switch(try getInterpreter().adaptivePredict(_input,9, _ctx)) { + case 1: + setState(79) + try string() + + break + case 2: + setState(80) + try match(DIDUrlAbnfParser.Tokens.DIGIT.rawValue) + + break + case 3: + setState(81) + try match(DIDUrlAbnfParser.Tokens.HEX.rawValue) + + break + default: break + } + + } + + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + public class StringContext: ParserRuleContext { + open + func STRING() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.STRING.rawValue, 0) + } + open + func DIGIT() -> TerminalNode? { + return getToken(DIDUrlAbnfParser.Tokens.DIGIT.rawValue, 0) + } + override open + func getRuleIndex() -> Int { + return DIDUrlAbnfParser.RULE_string + } + override open + func enterRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.enterString(self) + } + } + override open + func exitRule(_ listener: ParseTreeListener) { + if let listener = listener as? DIDUrlAbnfListener { + listener.exitString(self) + } + } + } + @discardableResult + open func string() throws -> StringContext { + var _localctx: StringContext + _localctx = StringContext(_ctx, getState()) + try enterRule(_localctx, 18, DIDUrlAbnfParser.RULE_string) + var _la: Int = 0 + defer { + try! exitRule() + } + do { + try enterOuterAlt(_localctx, 1) + setState(86) + _la = try _input.LA(1) + if (!(_la == DIDUrlAbnfParser.Tokens.DIGIT.rawValue || _la == DIDUrlAbnfParser.Tokens.STRING.rawValue)) { + try _errHandler.recoverInline(self) + } + else { + _errHandler.reportMatch(self) + try consume() + } + + } + catch ANTLRException.recognition(let re) { + _localctx.exception = re + _errHandler.reportError(self, re) + try _errHandler.recover(self, re) + } + + return _localctx + } + + static let _serializedATN:[Int] = [ + 4,1,16,89,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7, + 7,7,2,8,7,8,2,9,7,9,1,0,1,0,3,0,23,8,0,1,0,3,0,26,8,0,1,0,3,0,29,8,0,1, + 0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,3,1,3,3,3,43,8,3,5,3,45,8,3,10, + 3,12,3,48,9,3,1,3,1,3,1,4,1,4,5,4,54,8,4,10,4,12,4,57,9,4,1,4,3,4,60,8, + 4,1,5,1,5,1,5,1,6,1,6,1,6,3,6,68,8,6,1,7,1,7,1,7,5,7,73,8,7,10,7,12,7, + 76,9,7,1,8,1,8,1,8,1,8,1,8,3,8,83,8,8,3,8,85,8,8,1,9,1,9,1,9,0,0,10,0, + 2,4,6,8,10,12,14,16,18,0,1,2,0,8,8,16,16,90,0,20,1,0,0,0,2,32,1,0,0,0, + 4,38,1,0,0,0,6,46,1,0,0,0,8,55,1,0,0,0,10,61,1,0,0,0,12,64,1,0,0,0,14, + 69,1,0,0,0,16,77,1,0,0,0,18,86,1,0,0,0,20,22,3,2,1,0,21,23,3,8,4,0,22, + 21,1,0,0,0,22,23,1,0,0,0,23,25,1,0,0,0,24,26,3,10,5,0,25,24,1,0,0,0,25, + 26,1,0,0,0,26,28,1,0,0,0,27,29,3,12,6,0,28,27,1,0,0,0,28,29,1,0,0,0,29, + 30,1,0,0,0,30,31,5,0,0,1,31,1,1,0,0,0,32,33,5,6,0,0,33,34,5,13,0,0,34, + 35,3,4,2,0,35,36,5,13,0,0,36,37,3,6,3,0,37,3,1,0,0,0,38,39,3,18,9,0,39, + 5,1,0,0,0,40,42,3,18,9,0,41,43,5,13,0,0,42,41,1,0,0,0,42,43,1,0,0,0,43, + 45,1,0,0,0,44,40,1,0,0,0,45,48,1,0,0,0,46,44,1,0,0,0,46,47,1,0,0,0,47, + 49,1,0,0,0,48,46,1,0,0,0,49,50,3,18,9,0,50,7,1,0,0,0,51,52,5,1,0,0,52, + 54,3,18,9,0,53,51,1,0,0,0,54,57,1,0,0,0,55,53,1,0,0,0,55,56,1,0,0,0,56, + 59,1,0,0,0,57,55,1,0,0,0,58,60,5,1,0,0,59,58,1,0,0,0,59,60,1,0,0,0,60, + 9,1,0,0,0,61,62,5,2,0,0,62,63,3,14,7,0,63,11,1,0,0,0,64,67,5,3,0,0,65, + 68,3,18,9,0,66,68,5,8,0,0,67,65,1,0,0,0,67,66,1,0,0,0,68,13,1,0,0,0,69, + 74,3,16,8,0,70,71,5,4,0,0,71,73,3,16,8,0,72,70,1,0,0,0,73,76,1,0,0,0,74, + 72,1,0,0,0,74,75,1,0,0,0,75,15,1,0,0,0,76,74,1,0,0,0,77,84,3,18,9,0,78, + 82,5,5,0,0,79,83,3,18,9,0,80,83,5,8,0,0,81,83,5,15,0,0,82,79,1,0,0,0,82, + 80,1,0,0,0,82,81,1,0,0,0,83,85,1,0,0,0,84,78,1,0,0,0,84,85,1,0,0,0,85, + 17,1,0,0,0,86,87,7,0,0,0,87,19,1,0,0,0,11,22,25,28,42,46,55,59,67,74,82, + 84 + ] + + public + static let _ATN = try! ATNDeserializer().deserialize(_serializedATN) +} \ No newline at end of file diff --git a/AtalaPrismSDK/Castor/Sources/Operations/CreatePrismDIDOperation.swift b/AtalaPrismSDK/Castor/Sources/Operations/CreatePrismDIDOperation.swift index 8ea20f88..92592480 100644 --- a/AtalaPrismSDK/Castor/Sources/Operations/CreatePrismDIDOperation.swift +++ b/AtalaPrismSDK/Castor/Sources/Operations/CreatePrismDIDOperation.swift @@ -12,6 +12,12 @@ struct CreatePrismDIDOperation { var operation = Io_Iohk_Atala_Prism_Protos_AtalaOperation() operation.createDid = try createDIDAtalaOperation( publicKeys: [PrismDIDPublicKey( + apollo: apollo, + id: PrismDIDPublicKey.Usage.authenticationKey.defaultId, + usage: .authenticationKey, + keyData: masterPublicKey + ), + PrismDIDPublicKey( apollo: apollo, id: PrismDIDPublicKey.Usage.masterKey.defaultId, usage: .masterKey, diff --git a/AtalaPrismSDK/Domain/Sources/Models/Errors.swift b/AtalaPrismSDK/Domain/Sources/Models/Errors.swift index 440416f3..61311292 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/Errors.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/Errors.swift @@ -33,6 +33,12 @@ public protocol KnownPrismError: LocalizedError { var message: String { get } } +extension KnownPrismError { + public var errorDescription: String? { + message + } +} + /** An enum representing an unknown error in a Prism API response. @@ -141,8 +147,8 @@ public enum CommonError: KnownPrismError { switch self { case .invalidURLError(let url): return "Invalid url while trying to send message: \(url)" - case let .httpError(_, message): - return message + case let .httpError(code, message): + return "HTTP Request Error \(code): \(message)" } } @@ -548,6 +554,8 @@ public enum PolluxError: KnownPrismError { /// An error case representing an invalid JWT string. case invalidJWTString + case invalidPrismDID + case invalidJWTCredential /// The error code returned by the server. public var code: Int { @@ -556,6 +564,10 @@ public enum PolluxError: KnownPrismError { return 51 case .invalidJWTString: return 52 + case .invalidPrismDID: + return 53 + case .invalidJWTCredential: + return 54 } } @@ -572,6 +584,10 @@ public enum PolluxError: KnownPrismError { return "Invalid credential, could not decode" case .invalidJWTString: return "Invalid JWT while decoding credential" + case .invalidPrismDID: + return "To create a JWT presentation a Prism DID is required" + case .invalidJWTCredential: + return "To create a JWT presentation please provide a valid JWTCredential" } } } diff --git a/AtalaPrismSDK/Domain/Sources/Models/JWTVerifiableCredential.swift b/AtalaPrismSDK/Domain/Sources/Models/JWTVerifiableCredential.swift index f9533d21..6b3fa4c3 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/JWTVerifiableCredential.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/JWTVerifiableCredential.swift @@ -63,6 +63,7 @@ public struct JWTCredentialPayload { public let exp: Date? public let jti: String public let aud: Set + public let originalJWTString: String? /** Initializes a new instance of `JWTCredentialPayload`. @@ -83,7 +84,8 @@ public struct JWTCredentialPayload { nbf: Date, exp: Date? = nil, jti: String, - aud: Set = Set() + aud: Set = Set(), + originalJWTString: String? = nil ) { self.iss = iss self.sub = sub @@ -92,6 +94,7 @@ public struct JWTCredentialPayload { self.exp = exp self.jti = jti self.aud = aud + self.originalJWTString = originalJWTString } } @@ -101,6 +104,7 @@ extension JWTCredentialPayload: VerifiableCredential { public var type: Set { verifiableCredential.type } public var id: String { jti } public var issuer: DID { iss } + public var subject: DID? { sub.flatMap { try? DID(string: $0) } } public var issuanceDate: Date { nbf } public var expirationDate: Date? { exp } public var credentialSchema: VerifiableCredentialTypeContainer? { verifiableCredential.credentialSchema } diff --git a/AtalaPrismSDK/Domain/Sources/Models/Message.swift b/AtalaPrismSDK/Domain/Sources/Models/Message.swift index 8e1c4586..d0c0c0cc 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/Message.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/Message.swift @@ -1,7 +1,7 @@ import Foundation /// The `Message` struct represents a DIDComm message, which is used for secure, decentralized communication in the Atala PRISM architecture. A `Message` object includes information about the sender, recipient, message body, and other metadata. `Message` objects are typically exchanged between DID controllers using the `Mercury` building block. -public struct Message { +public struct Message: Identifiable, Hashable { /// The direction of the message (sent or received). public enum Direction: String { case sent @@ -97,4 +97,18 @@ public struct Message { self.ack = ack self.direction = direction } + + public func hash(into hasher: inout Hasher) { + hasher.combine(id) + hasher.combine(body) + hasher.combine(piuri) + } + + public static func == (lhs: Message, rhs: Message) -> Bool { + return lhs.id == rhs.id + && lhs.to == rhs.to + && lhs.from == rhs.from + && lhs.piuri == rhs.piuri + && lhs.body == rhs.body + } } diff --git a/AtalaPrismSDK/Domain/Sources/Models/VerifiableCredential.swift b/AtalaPrismSDK/Domain/Sources/Models/VerifiableCredential.swift index 0283fac4..a028a804 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/VerifiableCredential.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/VerifiableCredential.swift @@ -77,6 +77,8 @@ public protocol VerifiableCredential { var type: Set { get } /// The issuer of this credential. var issuer: DID { get } + /// The subject of this credential. + var subject: DID? { get } /// The date of issuance of this credential. var issuanceDate: Date { get } /// The expiration date of this credential, if any. diff --git a/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential+Codable.swift b/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential+Codable.swift index 36c5b27a..bd678f4f 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential+Codable.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential+Codable.swift @@ -6,6 +6,7 @@ extension W3CVerifiableCredential: Codable { case type = "@type" case id case issuer + case subject case issuanceDate case expirationDate case validFrom @@ -30,6 +31,9 @@ extension W3CVerifiableCredential: Codable { } try container.encode(self.id, forKey: .id) try container.encode(self.issuer.string, forKey: .issuer) + if let subject = self.subject?.string { + try container.encode(subject, forKey: .subject) + } try container.encode(self.issuanceDate, forKey: .issuanceDate) try container.encode(self.expirationDate, forKey: .expirationDate) try container.encode(self.validFrom, forKey: .validFrom) @@ -63,6 +67,11 @@ extension W3CVerifiableCredential: Codable { let proof = try? container.decode(String.self, forKey: .proof) let aud = (try? container.decode(Set.self, forKey: .proof)) ?? Set() let credentialSubject = try container.decode([String: String].self, forKey: .credentialSubject) + let subjectString = try? container.decode( + String.self, + forKey: .subject + ) + let subject = subjectString.flatMap { try? DID(string: $0) } let credentialStatus = try? container.decode( VerifiableCredentialTypeContainer.self, forKey: .credentialStatus @@ -89,6 +98,7 @@ extension W3CVerifiableCredential: Codable { type: type, id: id, issuer: issuer, + subject: subject, issuanceDate: issuanceDate, expirationDate: expirationDate, credentialSchema: credentialSchema, diff --git a/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential.swift b/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential.swift index 75a722b8..4f7e43ec 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/W3CVerifiableCredential.swift @@ -27,6 +27,9 @@ public struct W3CVerifiableCredential: VerifiableCredential { // The DID of the entity that issued the credential public let issuer: DID + // The DID of the entity that is subject of the credential + public let subject: DID? + // The date on which the credential was issued public let issuanceDate: Date @@ -90,6 +93,7 @@ public struct W3CVerifiableCredential: VerifiableCredential { type: Set = Set(), id: String, issuer: DID, + subject: DID?, issuanceDate: Date, expirationDate: Date? = nil, credentialSchema: VerifiableCredentialTypeContainer? = nil, @@ -107,6 +111,7 @@ public struct W3CVerifiableCredential: VerifiableCredential { self.type = type self.id = id self.issuer = issuer + self.subject = subject self.issuanceDate = issuanceDate self.expirationDate = expirationDate self.credentialSchema = credentialSchema diff --git a/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift b/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift index 09238eca..7cbfa86d 100644 --- a/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift +++ b/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift @@ -83,7 +83,8 @@ extension MercuryImpl { guard let msgData = try await sendMessage(msg), let msgStr = String(data: msgData, encoding: .utf8), - msgStr != "null" + msgStr != "null", + !msgStr.isEmpty else { return nil } return try? await self.unpackMessage(msg: msgStr) } diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialProvider.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialProvider.swift index 7c5c597e..e5df2baa 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialProvider.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialProvider.swift @@ -28,8 +28,18 @@ extension CDVerifiableCredential { func toDomain() throws -> VerifiableCredential { switch self.credentialType { case "jwt": - return try JSONDecoder() + let credential = try JSONDecoder() .decode(JWTCredentialPayload.self, from: self.verifiableCredetialJson) + return JWTCredentialPayload( + iss: credential.iss, + sub: credential.sub, + verifiableCredential: credential.verifiableCredential, + nbf: credential.nbf, + exp: credential.exp, + jti: credential.jti, + aud: credential.aud, + originalJWTString: self.originalJWT + ) case "w3c": return try JSONDecoder() .decode(W3CVerifiableCredential.self, from: self.verifiableCredetialJson) diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialStore.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialStore.swift index e38c843e..da547cf5 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialStore.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDVerifiableCredentialDAO+VerifiableCredentialStore.swift @@ -65,6 +65,7 @@ extension CDVerifiableCredential { case let jwt as JWTCredentialPayload: self.verifiableCredetialJson = try JSONEncoder().encode(jwt) self.credentialType = "jwt" + self.originalJWT = jwt.originalJWTString case let w3c as W3CVerifiableCredential: self.verifiableCredetialJson = try JSONEncoder().encode(w3c) self.credentialType = "w3c" diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/Models/CDVerifiableCredential+CoreDataProperties.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/Models/CDVerifiableCredential+CoreDataProperties.swift index c7727740..cd6bc89e 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/Models/CDVerifiableCredential+CoreDataProperties.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/Models/CDVerifiableCredential+CoreDataProperties.swift @@ -15,6 +15,7 @@ extension CDVerifiableCredential { @NSManaged var issuer: CDDID @NSManaged var context: Set @NSManaged var type: Set + @NSManaged var originalJWT: String? } extension CDVerifiableCredential { diff --git a/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/PrismPluto.xcdatamodel/contents b/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/PrismPluto.xcdatamodel/contents index 7b1e1576..7f2eb722 100644 --- a/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/PrismPluto.xcdatamodel/contents +++ b/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/PrismPluto.xcdatamodel/contents @@ -61,6 +61,7 @@ + diff --git a/AtalaPrismSDK/Pollux/Sources/JWTCredential.swift b/AtalaPrismSDK/Pollux/Sources/Models/JWTCredential.swift similarity index 90% rename from AtalaPrismSDK/Pollux/Sources/JWTCredential.swift rename to AtalaPrismSDK/Pollux/Sources/Models/JWTCredential.swift index e563ffe6..3e456f9d 100644 --- a/AtalaPrismSDK/Pollux/Sources/JWTCredential.swift +++ b/AtalaPrismSDK/Pollux/Sources/Models/JWTCredential.swift @@ -18,7 +18,8 @@ struct JWTCredential { nbf: jwtVerifiableCredential.nbf, exp: jwtVerifiableCredential.exp, jti: id, - aud: jwtVerifiableCredential.aud + aud: jwtVerifiableCredential.aud, + originalJWTString: id ) } } diff --git a/AtalaPrismSDK/Pollux/Sources/Models/JWTPresentation.swift b/AtalaPrismSDK/Pollux/Sources/Models/JWTPresentation.swift new file mode 100644 index 00000000..ea7f58fc --- /dev/null +++ b/AtalaPrismSDK/Pollux/Sources/Models/JWTPresentation.swift @@ -0,0 +1,23 @@ +import Domain +import Foundation +import SwiftJWT + +struct VerifiablePresentationPayload: Claims { + + struct VerifiablePresentation: Codable { + enum CodingKeys: String, CodingKey { + case context = "@context" + case type = "@type" + case verifiableCredential + } + + let context: Set + let type: Set + let verifiableCredential: [String] + } + + let iss: String + let aud: String + let nonce: String + let vp: [VerifiablePresentation] +} diff --git a/AtalaPrismSDK/Pollux/Sources/Operation/VerifyJWTCredential.swift b/AtalaPrismSDK/Pollux/Sources/Operation/VerifyJWTCredential.swift new file mode 100644 index 00000000..a3c845f1 --- /dev/null +++ b/AtalaPrismSDK/Pollux/Sources/Operation/VerifyJWTCredential.swift @@ -0,0 +1,88 @@ +import CryptoKit +import Domain +import Foundation +import SwiftJWT + +struct VerifyJWTCredential { + let apollo: Apollo + let castor: Castor + let jwtString: String + private let separatedJWTComponents: [String] + private var headersComponent: String { separatedJWTComponents[0] } + private var credentialComponent: String { separatedJWTComponents[1] } + private var signatureComponent: String { separatedJWTComponents[2] } + + init(apollo: Apollo, castor: Castor, jwtString: String) throws { + self.apollo = apollo + self.castor = castor + self.jwtString = jwtString + self.separatedJWTComponents = jwtString.components(separatedBy: ".") + guard + self.separatedJWTComponents.count == 3 + else { throw PolluxError.invalidJWTString } + } + + func compute() async throws -> Bool { + let document = try await getDIDDocument() + let pemKeys = try getAuthenticationPublicKeyPem(document: document) + var result = false + try pemKeys.forEach { + guard + !result, + let pemData = $0.data(using: .utf8) + else { return } + let verifier = JWTVerifier.es256k(publicKey: pemData) + let decoder = JWTDecoder(jwtVerifier: verifier) + do { + _ = try decoder.decode(JWT.self, fromString: jwtString) + result = true + } catch let error as JWTError { + switch error { + case .invalidUTF8Data, .invalidJWTString, .invalidPrivateKey, .missingPEMHeaders: + throw error + default: + break + } + } + } + return result + } + + private func getDIDDocument() async throws -> DIDDocument { + let did = try getJWTCredential().makeVerifiableCredential().issuer + let document = try await castor.resolveDID(did: did) + return document + } + + private func getJWTCredential() throws -> JWTCredential { + guard + let base64Data = Data(fromBase64URL: credentialComponent), + let jsonString = String(data: base64Data, encoding: .utf8) + else { throw PolluxError.invalidJWTString } + + guard + let dataValue = jsonString.data(using: .utf8) + else { throw PolluxError.invalidCredentialError } + return try JWTCredential( + id: jwtString, + fromJson: dataValue, + decoder: JSONDecoder() + ) + } + + private func getAuthenticationPublicKeyPem(document: DIDDocument) throws -> [String] { + return document.authenticate + .map { $0.publicKey.flatMap { keyDataToPEMString($0) } } + .compactMap { $0 } + } +} + +public func keyDataToPEMString(_ keyData: PublicKey) -> String? { + let keyBase64 = keyData.value.base64EncodedString() + let pemString = """ + -----BEGIN PUBLIC KEY----- + \(keyBase64) + -----END PUBLIC KEY----- + """ + return pemString +} diff --git a/AtalaPrismSDK/Pollux/Sources/PolluxImpl+Public.swift b/AtalaPrismSDK/Pollux/Sources/PolluxImpl+Public.swift index 7ab2fdf7..2a97cd71 100644 --- a/AtalaPrismSDK/Pollux/Sources/PolluxImpl+Public.swift +++ b/AtalaPrismSDK/Pollux/Sources/PolluxImpl+Public.swift @@ -1,6 +1,7 @@ import Core import Domain import Foundation +import SwiftJWT extension PolluxImpl: Pollux { public func parseVerifiableCredential(jwtString: String) throws -> VerifiableCredential { @@ -28,4 +29,36 @@ extension PolluxImpl: Pollux { throw PolluxError.invalidCredentialError } } + + public func createVerifiablePresentationJWT( + did: DID, + privateKey: PrivateKey, + credential: VerifiableCredential, + challenge: String, + domain: String + ) throws -> String { + let pemKey = apollo.keyDataToPEMString(privateKey) + guard + did.method == "prism", + let keyPemData = pemKey?.data(using: .utf8) + else { throw PolluxError.invalidCredentialError } + guard + let credentialJWT = (credential as? JWTCredentialPayload)?.originalJWTString + else { throw PolluxError.invalidJWTCredential } + let presentation = VerifiablePresentationPayload( + iss: did.string, + aud: domain, + nonce: challenge, + vp: [ + .init( + context: Set(["https://www.w3.org/2018/presentations/v1"]), + type: Set(["VerifiablePresentation"]), + verifiableCredential: [credentialJWT] + ) + ] + ) + let jwt = JWT(header: .init(), claims: presentation) + let signer = JWTSigner.es256k(privateKey: keyPemData) + return try JWTEncoder(jwtSigner: signer).encodeToString(jwt) + } } diff --git a/AtalaPrismSDK/Pollux/Sources/PolluxImpl.swift b/AtalaPrismSDK/Pollux/Sources/PolluxImpl.swift index 2efbcfd0..100d8b5d 100644 --- a/AtalaPrismSDK/Pollux/Sources/PolluxImpl.swift +++ b/AtalaPrismSDK/Pollux/Sources/PolluxImpl.swift @@ -1,9 +1,11 @@ import Domain public struct PolluxImpl { + let apollo: Apollo let castor: Castor - public init(castor: Castor) { + public init(apollo: Apollo, castor: Castor) { + self.apollo = apollo self.castor = castor } } diff --git a/AtalaPrismSDK/Pollux/Tests/JWTTests.swift b/AtalaPrismSDK/Pollux/Tests/JWTTests.swift new file mode 100644 index 00000000..52590c1c --- /dev/null +++ b/AtalaPrismSDK/Pollux/Tests/JWTTests.swift @@ -0,0 +1,55 @@ +import Apollo +import Castor +import Domain +import CryptoKit +@testable import Pollux +import XCTest +import secp256k1 + +final class JWTTests: XCTestCase { + + lazy var apollo = ApolloImpl() + lazy var castor = CastorImpl(apollo: apollo) + + func testJWTPresentationSignature() throws { + let privKey = PrivateKey( + curve: .secp256k1(index: 3), + value: Data(fromBase64URL: "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg")! + ) + let pubKey = PublicKey( + curve: KeyCurve.secp256k1().name, + value: Data(fromBase64URL: "BD-l4lrQ6Go-oN5XtdpY6o5dyf2V2v5EbMAvRjVGJpE1gYVURJfxKMpNPnKlLr4MOLNVaYvBNOoy9L50E8jVx8Q")! + ) + let issuerPrismDID = try castor.createPrismDID(masterPublicKey: pubKey, services: []) + let jwtCredential = JWTCredentialPayload( + iss: issuerPrismDID, + sub: nil, + verifiableCredential: .init(credentialSubject: ["test":"test"]), + nbf: Date(), + exp: nil, + jti: "", + aud: Set([""]), + originalJWTString: "Test.JWT.String" + ) + let ownerPrismDID = try castor.createPrismDID(masterPublicKey: pubKey, services: []) + let apollo = ApolloImpl() + let castor = CastorImpl(apollo: apollo) + let pollux = PolluxImpl(apollo: apollo, castor: castor) + + + let jwt = try pollux.createVerifiablePresentationJWT( + did: ownerPrismDID, + privateKey: privKey, + credential: jwtCredential, + challenge: "testChallenge", + domain: "testDomain" + ) + + let components = jwt.components(separatedBy: ".") + XCTAssertEqual(components.count, 3) + let claims = String(data: Data(fromBase64URL: components[1])!, encoding: .utf8)! + XCTAssertTrue(claims.contains("\"nonce\":\"testChallenge\"")) + XCTAssertTrue(claims.contains("\"Test.JWT.String\"")) + XCTAssertTrue(claims.contains("\"aud\":\"testDomain\"")) + } +} diff --git a/AtalaPrismSDK/Pollux/Tests/PolluxTest.swift b/AtalaPrismSDK/Pollux/Tests/PolluxTest.swift deleted file mode 100644 index 1a0a45df..00000000 --- a/AtalaPrismSDK/Pollux/Tests/PolluxTest.swift +++ /dev/null @@ -1 +0,0 @@ -// This file is just here as a foolproof/template since for Swift Packages a module source always have to have at least one Swift file diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift index 34917d28..94124c30 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift @@ -1,6 +1,8 @@ +import Core import Combine import Domain import Foundation +import SwiftJWT // MARK: Verifiable credentials functionalities public extension PrismAgent { @@ -9,7 +11,150 @@ public extension PrismAgent { /// - Returns: A publisher that emits an array of `VerifiableCredential` and completes when all the /// credentials are emitted or terminates with an error if any occurs func verifiableCredentials() -> AnyPublisher<[VerifiableCredential], Error> { - pluto - .getAllCredentials() + pluto.getAllCredentials() } + + /// This function parses an issued credential message, stores and returns the verifiable credential. + /// + /// - Parameters: + /// - message: Issue credential Message. + /// - Returns: The parsed verifiable credential. + /// - Throws: PrismAgentError, if there is a problem parsing the credential. + func processIssuedCredentialMessage(message: IssueCredential) async throws -> VerifiableCredential { + guard + let attachment = message.attachments.first?.data as? AttachmentBase64, + let jwtData = Data(fromBase64URL: attachment.base64), + let jwtString = String(data: jwtData, encoding: .utf8) + else { + throw UnknownError.somethingWentWrongError( + customMessage: "Cannot find attachment base64 in message", + underlyingErrors: nil + ) + } + + let credential = try pollux.parseVerifiableCredential(jwtString: jwtString) + print(credential) + try await pluto + .storeCredential(credential: credential) + .first() + .await() + return credential + } + + /// This function prepares a request credential from an offer given the subject DID. + /// + /// - Parameters: + /// - did: Subject DID. + /// - did: Received offer credential. + /// - Returns: Created request credential + /// - Throws: PrismAgentError, if there is a problem creating the request credential. + func prepareRequestCredentialWithIssuer(did: DID, offer: OfferCredential) async throws -> RequestCredential? { + guard did.method == "prism" else { throw PolluxError.invalidPrismDID } + let apollo = self.apollo + let seed = self.seed + let keyPair = try await pluto + .getPrismDIDInfo(did: did) + .tryMap { + guard let info = $0 else { throw PrismAgentError.cannotFindDIDKeyPairIndex } + return try apollo.createKeyPair(seed: seed, curve: .secp256k1(index: info.keyPairIndex)) + } + .first() + .await() + + print(did.string) + guard + let pem = apollo.keyDataToPEMString(keyPair.privateKey)?.data(using: .utf8) + else { throw PrismAgentError.cannotFindDIDKeyPairIndex } + + guard let offerData = offer + .attachments + .map({ + switch $0.data { + case let json as AttachmentJsonData: + return json.data + default: + return nil + } + }) + .compactMap({ $0 }) + .first + else { throw PrismAgentError.offerDoesntProvideEnoughInformation } + let jsonObject = try JSONSerialization.jsonObject(with: offerData) + guard + let domain = findValue(forKey: "domain", in: jsonObject), + let challenge = findValue(forKey: "challenge", in: jsonObject) + else { throw PrismAgentError.offerDoesntProvideEnoughInformation } + + let jwt = JWT(claims: ClaimsRequestSignatureJWT( + iss: did.string, + aud: domain, + nonce: challenge, + vp: .init(context: .init([ + "https://www.w3.org/2018/presentations/v1" + ]), type: .init([ + "VerifiablePresentation" + ])) + )) + let jwtString = try JWTEncoder(jwtSigner: .es256k(privateKey: pem)).encodeToString(jwt) + + guard let base64String = jwtString.data(using: .utf8)?.base64EncodedString() else { + throw UnknownError.somethingWentWrongError() + } + let requestCredential = RequestCredential( + body: .init( + goalCode: offer.body.goalCode, + comment: offer.body.comment, + formats: offer.body.formats + ), + attachments: [.init( + mediaType: "prism/jwt", + data: AttachmentBase64(base64: base64String) + )], + thid: offer.thid, + from: offer.to, + to: offer.from + ) + print(requestCredential) + return requestCredential + } + + +} + +// TODO: This function is not the most appropriate but will do the job now to change later. +private func findValue(forKey key: String, in json: Any) -> String? { + if let dict = json as? [String: Any] { + if let value = dict[key] { + return value as? String + } + for (_, subJson) in dict { + if let foundValue = findValue(forKey: key, in: subJson) { + return foundValue + } + } + } else if let array = json as? [Any] { + for subJson in array { + if let foundValue = findValue(forKey: key, in: subJson) { + return foundValue + } + } + } + return nil +} + +private struct ClaimsRequestSignatureJWT: Claims { + struct VerifiablePresentation: Codable { + enum CodingKeys: String, CodingKey { + case context = "@context" + case type = "type" + } + + let context: Set + let type: Set + } + + let iss: String + let aud: String + let nonce: String + let vp: VerifiablePresentation } diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift index 24304483..27e99131 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift @@ -199,7 +199,7 @@ Could not find key in storage please use Castor instead and provide the private .maskedMetadataByLevel(key: "DID", value: did.string, level: .debug) ]) - try await mediationHandler.updateKeyListWithDIDs(dids: [did]) + try await mediationHandler?.updateKeyListWithDIDs(dids: [did]) } /// This function gets the DID information (alias) for a given DID diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Invitations.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Invitations.swift index 1dea2f22..78522145 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Invitations.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Invitations.swift @@ -85,18 +85,12 @@ public extension PrismAgent { /// - Parameter invitation: The Out-of-Band invitation to accept /// - Throws: `PrismAgentError` if there is no mediator available or other errors occur during the acceptance process func acceptDIDCommInvitation(invitation: OutOfBandInvitation) async throws { - guard let mediatorRoutingDID else { throw PrismAgentError.noMediatorAvailableError } + guard + let connectionManager, + let mediatorRoutingDID + else { throw PrismAgentError.noMediatorAvailableError } logger.info(message: "Start accept DIDComm invitation") - let ownDID = try await createNewPeerDID( - services: [.init( - id: "#didcomm-1", - type: ["DIDCommMessaging"], - serviceEndpoint: [.init( - uri: mediatorRoutingDID.string - )] - )], - updateMediator: true - ) + let ownDID = try await createNewPeerDID(updateMediator: true) logger.info(message: "Sending DIDComm Connection message") diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift index 7f153e36..44adc1a6 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift @@ -7,7 +7,10 @@ public extension PrismAgent { /// Start fetching the messages from the mediator func startFetchingMessages(timeBetweenRequests: Int = 5) { let timeInterval = max(timeBetweenRequests, 5) - guard messagesStreamTask == nil else { return } + guard + let connectionManager, + messagesStreamTask == nil + else { return } logger.info(message: "Start streaming new unread messages") let manager = connectionManager @@ -48,7 +51,7 @@ public extension PrismAgent { /// - Returns: The sent message if successful, otherwise `nil`. /// - Throws: An error if the sending fails. func sendMessage(message: Message) async throws -> Message? { - return try await connectionManager.sendMessage(message) + return try await connectionManager?.sendMessage(message) } /// Handles the received messages events and return a publisher of the messages diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift new file mode 100644 index 00000000..88a5c204 --- /dev/null +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift @@ -0,0 +1,128 @@ +import Core +import Combine +import Domain +import Foundation +import SwiftJWT + +// MARK: Credentials proof functionalities +public extension PrismAgent { + + /// This function creates a Presentation from a request verfication. + /// + /// - Parameters: + /// - request: Request message received. + /// - credential: Verifiable Credential to present. + /// - Returns: Presentation message prepared to send. + /// - Throws: PrismAgentError, if there is a problem creating the presentation. + func createPresentationForRequestProof( + request: RequestPresentation, + credential: VerifiableCredential + ) async throws -> Presentation { + guard let requestData = request + .attachments + .map({ + switch $0.data { + case let json as AttachmentJsonData: + return json.data + default: + return nil + } + }) + .compactMap({ $0 }) + .first + else { throw PrismAgentError.offerDoesntProvideEnoughInformation } + let jsonObject = try JSONSerialization.jsonObject(with: requestData) + guard + let domain = findValue(forKey: "domain", in: jsonObject), + let challenge = findValue(forKey: "challenge", in: jsonObject) + else { throw PrismAgentError.offerDoesntProvideEnoughInformation } + + guard + let subjectDID = credential.subject + else { + throw UnknownError.somethingWentWrongError() + } + + let apollo = apollo + let seed = seed + let pemPrivateKey = try await pluto.getPrismDIDInfo(did: subjectDID) + .tryMap { + guard let info = $0 else { throw PrismAgentError.cannotFindDIDKeyPairIndex } + let keyPair = try apollo.createKeyPair(seed: seed, curve: .secp256k1(index: info.keyPairIndex)) + return apollo.keyDataToPEMString(keyPair.privateKey)?.data(using: .utf8) + } + .first() + .await() + + guard let pemPrivateKey else { throw UnknownError.somethingWentWrongError() } + + let jwt = JWT(claims: ClaimsProofPresentationJWT( + iss: subjectDID.string, + aud: domain, + nonce: challenge, + vp: .init( + context: .init(["https://www.w3.org/2018/presentations/v1"]), + type: .init(["VerifiablePresentation"]), + verifiableCredential: [credential.id] + ) + )) + let jwtString = try JWTEncoder(jwtSigner: .es256k(privateKey: pemPrivateKey)).encodeToString(jwt) + guard let base64String = jwtString.data(using: .utf8)?.base64EncodedString() else { + throw UnknownError.somethingWentWrongError() + } + return Presentation( + body: .init( + goalCode: request.body.goalCode, + comment: request.body.comment + ), + attachments: [.init( + mediaType: "prism/jwt", + data: AttachmentBase64(base64: base64String) + )], + thid: request.thid, + from: request.to, + to: request.from + ) + } +} + +// TODO: This function is not the most appropriate but will do the job now to change later. +private func findValue(forKey key: String, in json: Any) -> String? { + if let dict = json as? [String: Any] { + if let value = dict[key] { + return value as? String + } + for (_, subJson) in dict { + if let foundValue = findValue(forKey: key, in: subJson) { + return foundValue + } + } + } else if let array = json as? [Any] { + for subJson in array { + if let foundValue = findValue(forKey: key, in: subJson) { + return foundValue + } + } + } + return nil +} + +private struct ClaimsProofPresentationJWT: Claims { + struct VerifiablePresentation: Codable { + enum CodingKeys: String, CodingKey { + case context = "@context" + case type = "type" + case verifiableCredential + } + + let context: Set + let type: Set + let verifiableCredential: [String] + } + + let iss: String + let aud: String + let nonce: String + let vp: VerifiablePresentation +} + diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift index 44ba582a..c02732ec 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift @@ -28,7 +28,7 @@ public class PrismAgent { /// The mediator routing DID if one is currently registered. public var mediatorRoutingDID: DID? { - connectionManager.mediationHandler.mediator?.routingDID + connectionManager?.mediationHandler.mediator?.routingDID } let logger = PrismLogger(category: .prismAgent) @@ -37,9 +37,9 @@ public class PrismAgent { let pluto: Pluto let pollux: Pollux let mercury: Mercury - let mediationHandler: MediatorHandler + var mediationHandler: MediatorHandler? - var connectionManager: ConnectionsManagerImpl + var connectionManager: ConnectionsManagerImpl? var cancellables = [AnyCancellable]() // Not a "stream" var messagesStreamTask: Task? @@ -64,7 +64,7 @@ public class PrismAgent { pluto: Pluto, pollux: Pollux, mercury: Mercury, - mediationHandler: MediatorHandler, + mediationHandler: MediatorHandler? = nil, seed: Seed? = nil ) { self.apollo = apollo @@ -74,13 +74,15 @@ public class PrismAgent { self.mercury = mercury self.seed = seed ?? apollo.createRandomSeed().seed self.mediationHandler = mediationHandler - self.connectionManager = ConnectionsManagerImpl( - castor: castor, - mercury: mercury, - pluto: pluto, - mediationHandler: mediationHandler, - pairings: [] - ) + mediationHandler.map { + self.connectionManager = ConnectionsManagerImpl( + castor: castor, + mercury: mercury, + pluto: pluto, + mediationHandler: $0, + pairings: [] + ) + } } /** @@ -97,7 +99,7 @@ public class PrismAgent { let apollo = ApolloBuilder().build() let castor = CastorBuilder(apollo: apollo).build() let pluto = PlutoBuilder().build() - let pollux = PolluxBuilder(castor: castor).build() + let pollux = PolluxBuilder(apollo: apollo, castor: castor).build() let mercury = MercuryBuilder( apollo: apollo, castor: castor, @@ -119,6 +121,27 @@ public class PrismAgent { ) } + public func setupMediatorHandler(mediationHandler: MediatorHandler) async throws { + try await stop() + self.mediationHandler = mediationHandler + self.connectionManager = ConnectionsManagerImpl( + castor: castor, + mercury: mercury, + pluto: pluto, + mediationHandler: mediationHandler, + pairings: [] + ) + } + + public func setupMediatorDID(did: DID) async throws { + let mediatorHandler = BasicMediatorHandler( + mediatorDID: did, + mercury: mercury, + store: BasicMediatorHandler.PlutoMediatorStoreImpl(pluto: pluto) + ) + try await setupMediatorHandler(mediationHandler: mediatorHandler) + } + /** Start the PrismAgent and Mediator services @@ -126,7 +149,10 @@ public class PrismAgent { as well as any error thrown by `createNewPeerDID` and `connectionManager.registerMediator` */ public func start() async throws { - guard state == .stoped else { return } + guard + let connectionManager, + state == .stoped + else { return } logger.info(message: "Starting agent") state = .starting do { @@ -155,7 +181,7 @@ public class PrismAgent { logger.info(message: "Stoping agent") state = .stoping cancellables.forEach { $0.cancel() } - connectionManager.stopAllEvents() + connectionManager?.stopAllEvents() state = .stoped logger.info(message: "Agent not running") } diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgentErrors.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgentErrors.swift index 6cca33dc..64ac5a2b 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgentErrors.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgentErrors.swift @@ -27,6 +27,9 @@ public enum PrismAgentError: KnownPrismError { /// An error case representing that a mediation request has failed. case mediationRequestFailedError(underlyingErrors: [Error]?) + /// An error case + case offerDoesntProvideEnoughInformation + /// The error code returned by the server. public var code: Int { switch self { @@ -42,6 +45,8 @@ public enum PrismAgentError: KnownPrismError { return 115 case .mediationRequestFailedError: return 116 + case .offerDoesntProvideEnoughInformation: + return 117 } } @@ -76,6 +81,9 @@ You need to provide a mediation handler and start the prism agent before doing s .joined(separator: ", ") let message = errorsMessages.map { "Errors: " + $0 } ?? "" return "Something failed while trying to achieve mediation. \(message)" + + case .offerDoesntProvideEnoughInformation: + return "Offer provided doesnt have challenge and domain in the attachments" } } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionAccept.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionAccept.swift index 6a1cddf3..0e618c16 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionAccept.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionAccept.swift @@ -140,7 +140,8 @@ public struct ConnectionAccept { from: from, to: to, body: try JSONEncoder.didComm().encode(self.body), - thid: thid + thid: thid, + direction: .sent ) } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionRequest.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionRequest.swift index b8c74fed..b1ed6d9d 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionRequest.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/ConnectionRequest.swift @@ -167,7 +167,8 @@ public struct ConnectionRequest { from: from, to: to, body: try JSONEncoder.didComm().encode(self.body), - thid: thid + thid: thid, + direction: .sent ) } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DIDCommConnectionRunner.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DIDCommConnectionRunner.swift index dad7eaf2..71c73bf8 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DIDCommConnectionRunner.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DIDCommConnectionRunner.swift @@ -24,16 +24,16 @@ class DIDCommConnectionRunner { func run() async throws -> DIDPair { let request = try ConnectionRequest(inviteMessage: invitationMessage, from: ownDID) try await connection.sendMessage(request.makeMessage()) -// let message = try await pluto.getAllMessagesReceived() -// .flatMap { $0.publisher } -// .first { $0.thid == request.id } -// .await() -// -// guard -// message.piuri == ProtocolTypes.didcommconnectionResponse.rawValue -// else { -// throw PrismAgentError.noHandshakeResponseError -// } + let message = try await pluto.getAllMessagesReceived() + .flatMap { $0.publisher } + .first { $0.thid == request.id } + .await() + + guard + message.piuri == ProtocolTypes.didcommconnectionResponse.rawValue + else { + throw PrismAgentError.invitationIsInvalidError + } return DIDPair(holder: ownDID, other: request.to, name: nil) } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/IssueCredential.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/IssueCredential.swift index 55a87485..6d7ca7b0 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/IssueCredential.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/IssueCredential.swift @@ -80,7 +80,8 @@ public struct IssueCredential { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/OfferCredential.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/OfferCredential.swift index aa51f46c..6656060e 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/OfferCredential.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/OfferCredential.swift @@ -83,7 +83,8 @@ public struct OfferCredential { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/ProposeCredential.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/ProposeCredential.swift index 3199e4e2..ec14937a 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/ProposeCredential.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/ProposeCredential.swift @@ -76,7 +76,8 @@ public struct ProposeCredential { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/RequestCredential.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/RequestCredential.swift index ca2ce78b..e595d874 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/RequestCredential.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/IssueCredential/RequestCredential.swift @@ -5,12 +5,12 @@ import Foundation // ALL parameters are DIDCOMMV2 format and naming conventions and follows the protocol // https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2 public struct RequestCredential { - struct Body: Codable, Equatable { - let goalCode: String? - let comment: String? - let formats: [CredentialFormat] + public struct Body: Codable, Equatable { + public let goalCode: String? + public let comment: String? + public let formats: [CredentialFormat] - init( + public init( goalCode: String? = nil, comment: String? = nil, formats: [CredentialFormat] @@ -23,8 +23,8 @@ public struct RequestCredential { public let id: String public let type = ProtocolTypes.didcommRequestCredential.rawValue - let body: Body - let attachments: [AttachmentDescriptor] + public let body: Body + public let attachments: [AttachmentDescriptor] public let thid: String? public let from: DID public let to: DID @@ -74,7 +74,8 @@ public struct RequestCredential { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift index 131e51ba..c7a39686 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift @@ -55,7 +55,8 @@ public struct BasicMessage { from: from, to: to, body: try JSONEncoder.didComm().encode(body), - createdTime: date + createdTime: date, + direction: .sent ) } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/Presentation.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/Presentation.swift index 467f8a2d..82553c1c 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/Presentation.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/Presentation.swift @@ -74,7 +74,8 @@ public struct Presentation { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/ProposePresentation.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/ProposePresentation.swift index 07c8bdd3..5b6377c1 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/ProposePresentation.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/ProposePresentation.swift @@ -71,7 +71,8 @@ public struct ProposePresentation { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/RequestPresentation.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/RequestPresentation.swift index 9c3dd374..8df551b5 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/RequestPresentation.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProofPresentation/RequestPresentation.swift @@ -74,7 +74,8 @@ public struct RequestPresentation { to: to, body: try JSONEncoder.didComm().encode(body), attachments: attachments, - thid: thid + thid: thid, + direction: .sent ) } diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift index 3a338a04..95695bb2 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift @@ -1,6 +1,6 @@ import Foundation -enum ProtocolTypes: String { +public enum ProtocolTypes: String { case didcommBasicMessage = "https://didcomm.org/basicmessage/2.0/message" case didcommMediationRequest = "https://didcomm.org/coordinate-mediation/2.0/mediate-request" case didcommMediationGrant = "https://didcomm.org/coordinate-mediation/2.0/mediate-grant" diff --git a/Package.swift b/Package.swift index cf170d04..8312efa8 100644 --- a/Package.swift +++ b/Package.swift @@ -63,11 +63,11 @@ let package = Package( from: "1.4.4" ), .package(url: "git@github.com:apple/swift-protobuf.git", from: "1.7.0"), - .package(url: "git@github.com:antlr/antlr4.git", branch: "master"), + .package(url: "git@github.com:antlr/antlr4.git", exact: "4.12.0"), .package(url: "git@github.com:input-output-hk/atala-prism-didcomm-swift.git", from: "0.3.6"), .package(url: "git@github.com:swift-libp2p/swift-multibase.git", branch: "main"), - .package(url: "git@github.com:Kitura/Swift-JWT.git", from: "4.0.0"), - .package(url: "git@github.com:GigaBitcoin/secp256k1.swift.git", from: "0.5.0") + .package(url: "git@github.com:GigaBitcoin/secp256k1.swift.git", from: "0.10.0"), + .package(url: "git@github.com:goncalo-frade-iohk/Swift-JWT.git", from: "4.1.2") ], targets: [ .target( @@ -97,8 +97,7 @@ let package = Package( dependencies: [ "Domain", "Core", - .product(name: "secp256k1", package: "secp256k1.swift"), - .product(name: "SwiftJWT", package: "Swift-JWT") + .product(name: "secp256k1", package: "secp256k1.swift") ], path: "AtalaPrismSDK/Apollo/Sources" ), @@ -127,13 +126,14 @@ let package = Package( name: "Pollux", dependencies: [ "Domain", - "Core" + "Core", + .product(name: "SwiftJWT", package: "Swift-JWT") ], path: "AtalaPrismSDK/Pollux/Sources" ), .testTarget( name: "PolluxTests", - dependencies: ["Pollux"], + dependencies: ["Pollux", "Apollo", "Castor"], path: "AtalaPrismSDK/Pollux/Tests" ), .target( @@ -168,7 +168,12 @@ let package = Package( ), .target( name: "PrismAgent", - dependencies: ["Domain", "Builders", "Core"], + dependencies: [ + "Domain", + "Builders", + "Core", + .product(name: "SwiftJWT", package: "Swift-JWT") + ], path: "AtalaPrismSDK/PrismAgent/Sources" ), .testTarget( diff --git a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift index 1dea13fe..322c4cda 100644 --- a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift +++ b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift @@ -3,11 +3,10 @@ import Builders import Combine import Domain import Foundation -import SwiftJWT final class SetupPrismAgentViewModelImpl: ObservableObject, SetupPrismAgentViewModel { - @Published var oobUrl: String = "https://domain.com/path?_oob=eyJpZCI6IjlmMDBkMTg1LWEwZGQtNDcyNy1iY2I1LWQwMTc0NmIwYWNkNCIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNmdVhkcDRybmNwQnZxanlXYVE1Z1IxWHB3dFVHbzZVYmpmQ3lINldKYzhCbi5WejZNa29ZUWRoVm1rSEthVGhZU1ZSOFRvYzVkZWp1ZW0yTENzWDRlU280WHRYQ1ZDLlNleUowSWpvaVpHMGlMQ0p6SWpvaWFIUjBjRG92TDJodmMzUXVaRzlqYTJWeUxtbHVkR1Z5Ym1Gc09qZ3dPREF2Wkdsa1kyOXRiU0lzSW5JaU9sdGRMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDAiLCJib2R5Ijp7ImdvYWxfY29kZSI6ImNvbm5lY3QiLCJnb2FsIjoiRXN0YWJsaXNoIGEgdHJ1c3QgY29ubmVjdGlvbiBiZXR3ZWVuIHR3byBwZWVycyIsImFjY2VwdCI6W119fQ==" + @Published var oobUrl: String = "https://domain.com/path?_oob=eyJpZCI6ImNjZmM0MjYyLTczZjItNGFkMy1iYWVhLTgwNmQ0MjNkZjQ5NyIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNmTTlGYVp1a0JDR3hVVlpLVkN4RlRrb1BZcW00dkxCbm9XN202R1E1dlBUOC5WejZNa3FUOWV2NmU3Wm5xVlM2OUZ5d3ZUQkVpdG41SGNQeFRkVzVTYmFkdzZtTWY3LlNleUowSWpvaVpHMGlMQ0p6SWpvaWFIUjBjRG92TDJ4dlkyRnNhRzl6ZERvNU1ERXdMMlJwWkdOdmJXMGlMQ0p5SWpwYlhTd2lZU0k2V3lKa2FXUmpiMjF0TDNZeUlsMTkiLCJib2R5Ijp7ImdvYWxfY29kZSI6ImlvLmF0YWxhcHJpc20uY29ubmVjdCIsImdvYWwiOiJFc3RhYmxpc2ggYSB0cnVzdCBjb25uZWN0aW9uIGJldHdlZW4gdHdvIHBlZXJzIHVzaW5nIHRoZSBwcm90b2NvbCAnaHR0cHM6Ly9hdGFsYXByaXNtLmlvL21lcmN1cnkvY29ubmVjdGlvbnMvMS4wL3JlcXVlc3QnIiwiYWNjZXB0IjpbXX19" @Published var status: String = "" @Published var error: String? @@ -83,7 +82,7 @@ final class SetupPrismAgentViewModelImpl: ObservableObject, SetupPrismAgentViewM let str = String(data: b64, encoding: .utf8)! let apollo = ApolloBuilder().build() let castor = CastorBuilder(apollo: apollo).build() - let pollux = PolluxBuilder(castor: castor).build() + let pollux = PolluxBuilder(apollo: apollo, castor: castor).build() let credential = try pollux.parseVerifiableCredential(jwtString: str) print(credential) default: