Example #1
0
        public async Task <string> CreateSessionAndSendSessionRequestAsync(string counterPartyVaspId)
        {
            var session = new Session
            {
                Id    = Guid.NewGuid().ToString("N"),
                Type  = SessionType.Originator,
                State = SessionState.Created,
                CounterPartyVaspId = counterPartyVaspId,
                CreationDateTime   = DateTime.UtcNow,
                EcdhPrivateKey     = ECDH_Key.GenerateKey().PrivateKey,
            };

            _sessions[session.Id] = session;

            var whisperConnection = await _transportService.CreateConnectionAsync(session.CounterPartyVaspId);

            session.ConnectionId = whisperConnection;

            var messageKey = await _vaspCodesService.GetMessageKeyAsync(session.CounterPartyVaspId.Substring(4));

            session.TempAesMessageKey = ECDH_Key.ImportKey(_privateMessageKey).GenerateSharedSecretHex(messageKey);

            await SendMessageAsync(
                session,
                MessageType.SessionRequest,
                Instruction.Invite,
                ECDH_Key.ImportKey(session.EcdhPrivateKey).PublicKey,
                new SessionRequest());

            return(session.Id);
        }