public static VaspClient Create(
            VaspInformation vaspInfo,
            VaspContractInfo vaspContractInfo,
            string handshakePrivateKeyHex,
            string signaturePrivateKeyHex,
            IEthereumRpc nodeClientEthereumRpc,
            IWhisperRpc nodeClientWhisperRpc,
            IEnsProvider ensProvider,
            ISignService signService,
            ITransportClient transportClient)
        {
            var handshakeKey = ECDH_Key.ImportKey(handshakePrivateKeyHex);

            var vaspClient = new VaspClient(
                handshakeKey,
                signaturePrivateKeyHex,
                vaspContractInfo,
                vaspInfo,
                nodeClientEthereumRpc,
                nodeClientWhisperRpc,
                ensProvider,
                transportClient,
                signService);

            return(vaspClient);
        }
Exemple #2
0
 public SessionRequestMessage(Message message, HandShakeRequest handshake, VaspInformation vasp)
 {
     MessageType = MessageType.SessionRequest;
     Message     = message;
     HandShake   = handshake;
     VASP        = vasp;
 }
Exemple #3
0
 public TransactionsManager(VaspClient vaspClient, VaspInformation vaspInformation)
 {
     _vaspInformation      = vaspInformation;
     _outgoingTransactions = new List <Core.Models.Transaction>();
     _incomingTransactions = new List <Core.Models.Transaction>();
     _vaspSessionsManager  = new VaspSessionsManager(vaspClient, this);
 }
 public SessionReplyMessage(Message message, HandShakeResponse handshake, VaspInformation vasp)
 {
     MessageType = MessageType.SessionReply;
     Message     = message;
     HandShake   = handshake;
     VASP        = vasp;
 }
Exemple #5
0
        public static ProtoVaspInfo MapVaspInformationToProto(VaspInformation vaspInfo)
        {
            var proto = new ProtoVaspInfo()
            {
                Name          = vaspInfo.Name,
                PlaceOfBirth  = MapPlaceOfBirthToProto(vaspInfo.PlaceOfBirth),
                PostalAddress = MapPostalAddressToProto(vaspInfo.PostalAddress),
                VaspIdentity  = vaspInfo.VaspIdentity,
                VaspPubkey    = vaspInfo.VaspPublickKey,
                Bic           = vaspInfo.BIC ?? ""
            };

            var juridicalPeronsIds = vaspInfo
                                     .JuridicalPersonIds?.Select <JuridicalPersonId, ProtoJuridicalPersonId>(x =>
                                                                                                             MapJuridicalPersonIdToProto(x));

            var naturalPersonsIds =
                vaspInfo.NaturalPersonIds?.Select <NaturalPersonId, ProtoNaturalPersonId>(x =>
                                                                                          MapNaturalPersonIdToProto(x));

            if (juridicalPeronsIds != null)
            {
                proto.JuridicalPersonId.Add(juridicalPeronsIds);
            }

            if (naturalPersonsIds != null)
            {
                proto.NaturalPersonId.Add(naturalPersonsIds);
            }

            return(proto);
        }
Exemple #6
0
 public SessionRequestMessage(string sessionId, HandShakeRequest handshake, VaspInformation vasp)
 {
     MessageType = MessageType.SessionRequest;
     Message     = new Message(Guid.NewGuid().ToString(), sessionId, "1");
     HandShake   = handshake;
     VASP        = vasp;
 }
Exemple #7
0
 public TerminationMessage(string sessionId, TerminationMessageCode messageCode, VaspInformation vasp)
 {
     MessageType = MessageType.Termination;
     Message     = new Message(
         Guid.NewGuid().ToString(),
         sessionId,
         GetMessageCode(messageCode));
     VASP = vasp;
 }
Exemple #8
0
 public TransferRequestMessage(
     string sessionId,
     Originator originator,
     Beneficiary beneficiary,
     TransferRequest transfer,
     VaspInformation vasp)
 {
     MessageType = MessageType.TransferRequest;
     Message     = new Message(Guid.NewGuid().ToString(), sessionId, "1");
     Originator  = originator;
     Beneficiary = beneficiary;
     Transfer    = transfer;
     VASP        = vasp;
 }
Exemple #9
0
        public static VaspInformation MapVaspInformationFromProto(ProtoVaspInfo vaspInfo)
        {
            var proto = new VaspInformation(
                vaspInfo.Name,
                vaspInfo.VaspIdentity,
                vaspInfo.VaspPubkey,
                MapPostalAddressFromProto(vaspInfo.PostalAddress),
                MapPlaceOfBirthFromProto(vaspInfo.PlaceOfBirth),
                vaspInfo.NaturalPersonId?.Select <ProtoNaturalPersonId, NaturalPersonId>(x => MapNaturalPersonIdFromProto(x)).ToArray(),
                vaspInfo.JuridicalPersonId?.Select <ProtoJuridicalPersonId, JuridicalPersonId>(x => MapJuridicalPersonIdFromProto(x)).ToArray(),
                string.IsNullOrEmpty(vaspInfo.Bic) ? null : vaspInfo.Bic);

            return(proto);
        }
Exemple #10
0
 public TransferRequestMessage(
     Message message,
     Originator originator,
     Beneficiary beneficiary,
     TransferRequest transfer,
     VaspInformation vasp)
 {
     MessageType = MessageType.TransferRequest;
     Message     = message;
     Originator  = originator;
     Beneficiary = beneficiary;
     Transfer    = transfer;
     VASP        = vasp;
 }
Exemple #11
0
        private static SessionRequestMessage GetSessionRequestMessage()
        {
            //Should be a contract
            var vaspKey = EthECKey.GenerateKey();

            //4Bytes
            var topic = "0x12345678"; //"0x" + "My Topic".GetHashCode().ToString("x");

            string ecdhPubKey = "12";

            var message = new Message(
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                "1");
            var handshake     = new HandShakeRequest(topic, ecdhPubKey);
            var postalAddress = new PostalAddress(
                "TestingStreet",
                61,
                "Test Address Line",
                "410000",
                "TownN",
                Country.List["DE"]
                );
            var placeOfBirth    = new PlaceOfBirth(DateTime.UtcNow, "TownN", Country.List["DE"]);
            var vaspInformation = new VaspInformation(
                "Test test",
                vaspKey.GetPublicAddress(),
                vaspKey.GetPubKey().ToHex(prefix: false),
                postalAddress,
                placeOfBirth,
                new NaturalPersonId[]
            {
                new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber,
                                    Country.List["DE"]),
            },
                new JuridicalPersonId[]
            {
                new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification,
                                      Country.List["DE"]),
            },
                "DEUTDEFF");

            var request = new SessionRequestMessage(message, handshake, vaspInformation)
            {
                Comment = "This is test message",
            };

            return(request);
        }
Exemple #12
0
 public TransferReplyMessage(
     string sessionId,
     TransferReplyMessageCode transferReplyMessageCode,
     Originator originator,
     Beneficiary beneficiary,
     TransferReply transfer,
     VaspInformation vasp)
 {
     MessageType = MessageType.TransferReply;
     Message     = new Message(Guid.NewGuid().ToString(), sessionId, GetMessageCode(transferReplyMessageCode));
     Originator  = originator;
     Beneficiary = beneficiary;
     Transfer    = transfer;
     VASP        = vasp;
 }
 public TransferDispatchMessage(
     string sessionId,
     Originator originator,
     Beneficiary beneficiary,
     TransferReply transfer,
     Transaction transaction,
     VaspInformation vasp)
 {
     MessageType = MessageType.TransferDispatch;
     Message     = new Message(Guid.NewGuid().ToString(), sessionId, "1");
     Originator  = originator;
     Beneficiary = beneficiary;
     Transfer    = transfer;
     Transaction = transaction;
     VASP        = vasp;
 }
 public TransferDispatchMessage(
     Message message,
     Originator originator,
     Beneficiary beneficiary,
     TransferReply transfer,
     Transaction transaction,
     VaspInformation vasp)
 {
     MessageType = MessageType.TransferDispatch;
     Message     = message;
     Originator  = originator;
     Beneficiary = beneficiary;
     Transfer    = transfer;
     Transaction = transaction;
     VASP        = vasp;
 }
Exemple #15
0
        public BeneficiarySession(
            VaspContractInfo beneficiaryVaspContractInfo,
            VaspInformation beneficiaryVasp,
            string sessionId,
            string counterpartyTopic,
            string counterPartyPubSigningKey,
            string sharedKey,
            string privateSigningKey,
            IWhisperRpc whisperRpc,
            IVaspMessageHandler vaspMessageHandler,
            ITransportClient transportClient,
            ISignService signService)
            : base(
                beneficiaryVaspContractInfo,
                beneficiaryVasp,
                counterPartyPubSigningKey,
                sharedKey,
                privateSigningKey,
                whisperRpc,
                transportClient,
                signService)
        {
            this.SessionId           = sessionId;
            this.CounterPartyTopic   = counterpartyTopic;
            this._vaspMessageHandler = vaspMessageHandler;

            _messageHandlerResolverBuilder.AddHandler(typeof(TransferRequestMessage), new TransferRequestMessageHandler(
                                                          async(message, cancellationToken) =>
            {
                await _vaspMessageHandler.TransferRequestHandlerAsync(message, this);
            }));

            _messageHandlerResolverBuilder.AddHandler(typeof(TransferDispatchMessage), new TransferDispatchMessageHandler(
                                                          async(message, cancellationToken) =>
            {
                await _vaspMessageHandler.TransferDispatchHandlerAsync(message, this);
            }));

            _messageHandlerResolverBuilder.AddHandler(typeof(TerminationMessage),
                                                      new TerminationMessageHandler(async(message, token) =>
            {
                _hasReceivedTerminationMessage = true;
                await TerminateAsync(message.GetMessageCode());
            }));
        }
Exemple #16
0
        public async Task <(VaspInformation VaspInformation, VaspContractInfo VaspContractInfo)> CreateForBankAsync(
            string vaspSmartContractAddress,
            string settingsBic)
        {
            var vaspContractInfo = await _nodeClientEthereumRpc.GetVaspContractInfoAync(vaspSmartContractAddress);

            var vaspInformation = new VaspInformation(
                vaspContractInfo.Name,
                vaspSmartContractAddress,
                vaspContractInfo.HandshakeKey,//Ensure it is correct
                vaspContractInfo.Address,
                null,
                null,
                null,
                settingsBic);

            return(vaspInformation, vaspContractInfo);
        }
Exemple #17
0
        public async Task <(VaspInformation VaspInformation, VaspContractInfo VaspContractInfo)> CreateForJuridicalPersonAsync(
            string vaspSmartContractAddress,
            JuridicalPersonId[] juridicalIds)
        {
            var vaspContractInfo = await _nodeClientEthereumRpc.GetVaspContractInfoAync(vaspSmartContractAddress);

            var vaspInformation = new VaspInformation(
                vaspContractInfo.Name,
                vaspSmartContractAddress,
                vaspContractInfo.HandshakeKey,//Ensure it is correct
                vaspContractInfo.Address,
                null,
                null,
                juridicalIds,
                null);

            return(vaspInformation, vaspContractInfo);
        }
Exemple #18
0
        private static TerminationMessage GetTerminationMessage()
        {
            //Should be a contract
            var vaspKey = EthECKey.GenerateKey();

            var message = new Message(
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                "1");
            var postalAddress = new PostalAddress(
                "TestingStreet",
                61,
                "Test Address Line",
                "410000",
                "TownN",
                Country.List["DE"]
                );
            var placeOfBirth    = new PlaceOfBirth(DateTime.UtcNow, "TownN", Country.List["DE"]);
            var vaspInformation = new VaspInformation(
                "Test test",
                vaspKey.GetPublicAddress(),
                vaspKey.GetPubKey().ToHex(prefix: false),
                postalAddress,
                placeOfBirth,
                new NaturalPersonId[]
            {
                new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber,
                                    Country.List["DE"]),
            },
                new JuridicalPersonId[]
            {
                new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification,
                                      Country.List["DE"]),
            },
                "DEUTDEFF");

            var request = new TerminationMessage(message, vaspInformation)
            {
                Comment = "This is test message",
            };

            return(request);
        }
Exemple #19
0
        public (VaspInformation VaspInformation, VaspContractInfo VaspContractInfo) Create(
            string vaspSmartContractAddress)
        {
            var vaspContractInfo = _nodeClientEthereumRpc
                                   .GetVaspContractInfoAync(vaspSmartContractAddress)
                                   .GetAwaiter()
                                   .GetResult();

            var vaspInformation = new VaspInformation(
                vaspContractInfo.Name,
                vaspSmartContractAddress,
                vaspContractInfo.HandshakeKey,//Ensure it is correct
                vaspContractInfo.Address,
                null,
                null,
                null,
                null);

            return(vaspInformation, vaspContractInfo);
        }
 //TODO: Get rid of Whisper completely
 private VaspClient(
     ECDH_Key handshakeKey,
     string signatureHexKey,
     VaspContractInfo vaspContractInfo,
     VaspInformation vaspInfo,
     IEthereumRpc nodeClientEthereumRpc,
     IWhisperRpc nodeClientWhisperRpc,
     IEnsProvider ensProvider,
     ITransportClient transportClient,
     ISignService signService)
 {
     this._handshakeKey            = handshakeKey;
     this._signatureKey            = signatureHexKey;
     this._vaspContractInfo        = vaspContractInfo;
     this.VaspInfo                 = vaspInfo;
     this._ethereumRpc             = nodeClientEthereumRpc;
     this._whisperRpc              = nodeClientWhisperRpc;
     this._cancellationTokenSource = new CancellationTokenSource();
     this._ensProvider             = ensProvider;
     this._transportClient         = transportClient;
     this._signService             = signService;
 }
 public VaspSession(
     VaspContractInfo vaspContractInfo,
     VaspInformation vaspInfo,
     string counterPartyPubSigningKey,
     string sharedEncryptionKey,
     string privateSigningKey,
     IWhisperRpc whisperRpc,
     ITransportClient transportClient,
     ISignService signService)
 {
     this._vaspInfo                      = vaspInfo;
     this._vaspContractInfo              = vaspContractInfo;
     this._sessionTopic                  = TopicGenerator.GenerateSessionTopic();
     this._cancellationTokenSource       = new CancellationTokenSource();
     this._whisperRpc                    = whisperRpc;
     this._sharedKey                     = sharedEncryptionKey;
     this._privateSigningKey             = privateSigningKey;
     this._counterPartyPubSigningKey     = counterPartyPubSigningKey;
     this._messageHandlerResolverBuilder = new MessageHandlerResolverBuilder();
     this._transportClient               = transportClient;
     this._signService                   = signService;
 }
Exemple #22
0
        /// <summary>
        /// C-tor
        /// </summary>
        public TransactionsManager(
            VaspCode vaspCode,
            string handshakePrivateKeyHex,
            string signaturePrivateKeyHex,
            IEthereumRpc ethereumRpc,
            ISignService signService,
            IEnsProvider ensProvider,
            ITransportClient transportClient,
            ITransactionDataService transactionDataService,
            ISessionsRepository sessionsRepository,
            ITransactionsRepository transactionsRepository,
            IVaspCodeManager vaspCodeManager,
            VaspInformation vaspInformation,
            ILoggerFactory loggerFactory)
        {
            _vaspClient = VaspClient.Create(
                vaspCode,
                handshakePrivateKeyHex,
                signaturePrivateKeyHex,
                ethereumRpc,
                ensProvider,
                signService,
                transportClient,
                loggerFactory);

            _vaspClient.SessionRequestMessageReceived       += SessionRequestMessageReceivedAsync;
            _vaspClient.SessionReplyMessageReceived         += SessionReplyMessageReceivedAsync;
            _vaspClient.TransferReplyMessageReceived        += TransferReplyMessageReceivedAsync;
            _vaspClient.TransferConfirmationMessageReceived += TransferConfirmationMessageReceivedAsync;
            _vaspClient.TransferRequestMessageReceived      += TransferRequestMessageReceivedAsync;
            _vaspClient.TransferDispatchMessageReceived     += TransferDispatchMessageReceivedAsync;
            _vaspClient.BeneficiarySessionCreated           += BeneficiarySessionCreatedAsync;

            _transactionDataService = transactionDataService;
            _sessionsRepository     = sessionsRepository;
            _transactionsRepository = transactionsRepository;
            _vaspCodeManager        = vaspCodeManager;
            _vaspInformation        = vaspInformation;
        }
Exemple #23
0
 public TerminationMessage(Message message, VaspInformation vasp)
 {
     MessageType = MessageType.Termination;
     Message     = message;
     VASP        = vasp;
 }
Exemple #24
0
        private static TransferConfirmationMessage GetTransferConfirmationMessage()
        {
            //Should be a contract
            var vaspKey = EthECKey.GenerateKey();

            var message = new Message(
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                Guid.NewGuid().ToByteArray().ToHex(prefix: false),
                "1");

            var postalAddress = new PostalAddress(
                "TestingStreet",
                61,
                "Test Address Line",
                "410000",
                "TownN",
                Country.List["DE"]
                );
            var placeOfBirth    = new PlaceOfBirth(DateTime.UtcNow, "TownN", Country.List["DE"]);
            var vaspInformation = new VaspInformation(
                "Test test",
                vaspKey.GetPublicAddress(),
                vaspKey.GetPubKey().ToHex(prefix: false),
                postalAddress,
                placeOfBirth,
                new NaturalPersonId[]
            {
                new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber,
                                    Country.List["DE"]),
            },
                new JuridicalPersonId[]
            {
                new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification,
                                      Country.List["DE"]),
            },
                "DEUTDEFF");

            var originator = new Originator("Originator1", "VaaN", postalAddress, placeOfBirth,
                                            new NaturalPersonId[]
            {
                new NaturalPersonId("SomeId2", NaturalIdentificationType.AlienRegistrationNumber,
                                    Country.List["DE"]),
            },
                                            new JuridicalPersonId[]
            {
                new JuridicalPersonId("SomeId1", JuridicalIdentificationType.BankPartyIdentification,
                                      Country.List["DE"]),
            },
                                            "DEUTDEFF");

            var beneficiary = new Beneficiary("Ben1", "VaaN");

            var transferReply = new TransferReply(VirtualAssetType.ETH, TransferType.BlockchainTransfer, "10000000", "0x0000001");
            var transaction   = new Transaction("txId", DateTime.UtcNow, "0x0000002");

            var request = new TransferConfirmationMessage(message, originator, beneficiary, transferReply, transaction, vaspInformation)
            {
                Comment = "This is test message",
            };

            return(request);
        }
Exemple #25
0
        public OriginatorSession(
            Originator originator,
            VaspContractInfo originatorVaspContractInfo,
            VaspInformation originatorVasp,
            VirtualAssetsAccountNumber beneficiaryVaan,
            string beneficiaryPubSigningKey,
            string beneficiaryPubHandshakeKey,
            string sharedEncryptionKey,
            string pubEncryptionKey,
            string privateSigningKey,
            IWhisperRpc whisperRpc,
            ITransportClient transportClient,
            ISignService signService,
            IOriginatorVaspCallbacks originatorVaspCallbacks)
        //IEnsProvider ensProvider)
            : base(
                originatorVaspContractInfo,
                originatorVasp,
                beneficiaryPubSigningKey,
                sharedEncryptionKey,
                privateSigningKey,
                whisperRpc,
                transportClient,
                signService)
        {
            this._beneficiaryVaan            = beneficiaryVaan;
            this.SessionId                   = Guid.NewGuid().ToString();
            this._beneficiaryPubHandshakeKey = beneficiaryPubHandshakeKey;
            this._pubEncryptionKey           = pubEncryptionKey;
            this._originatorVaspCallbacks    = originatorVaspCallbacks;
            //this._ensProvider = ensProvider;
            this._originator = originator;

            _messageHandlerResolverBuilder.AddHandler(typeof(SessionReplyMessage),
                                                      new SessionReplyMessageHandler((sessionReplyMessage, token) =>
            {
                this.CounterPartyTopic = sessionReplyMessage.HandShake.TopicB;
                return(_originatorVaspCallbacks.SessionReplyMessageHandlerAsync(sessionReplyMessage, this));
            }));

            _messageHandlerResolverBuilder.AddHandler(typeof(TransferReplyMessage),
                                                      new TransferReplyMessageHandler((transferReplyMessage, token) =>
            {
                return(_originatorVaspCallbacks.TransferReplyMessageHandlerAsync(transferReplyMessage, this));
            }));

            _messageHandlerResolverBuilder.AddHandler(typeof(TransferConfirmationMessage),
                                                      new TransferConfirmationMessageHandler((transferDispatchMessage, token) =>
            {
                return(_originatorVaspCallbacks.TransferConfirmationMessageHandlerAsync(transferDispatchMessage,
                                                                                        this));
            }));

            _messageHandlerResolverBuilder.AddHandler(typeof(TerminationMessage),
                                                      new TerminationMessageHandler(async(message, token) =>
            {
                _hasReceivedTerminationMessage = true;

                await TerminateAsync(message.GetMessageCode());
            }));
        }
 Task <bool> IVaspMessageHandler.AuthorizeSessionRequestAsync(VaspInformation request)
 {
     return(_sessionAuthorizeRequest.Invoke(request));
 }