public async Task CreateVaspForNaturalPerson_Builder() { var builder = new VaspInformationBuilder(NodeClient.EthereumRpc); (VaspInformation vaspInfo, VaspContractInfo vaspContractInfo) = await builder.CreateForNaturalPersonAsync( Settings.VaspSmartContractAddressPerson, Settings.NaturalPersonIds, Settings.PlaceOfBirth); VaspClient vasp = VaspClient.Create( vaspInfo, vaspContractInfo, Settings.PersonHandshakePrivateKeyHex, Settings.PersonSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); // VASP paramaters must be derived from smart contract Assert.NotNull(vasp.VaspInfo.Name); Assert.NotNull(vasp.VaspInfo.VaspIdentity); Assert.NotNull(vasp.VaspInfo.PostalAddress); // VASP natural person parameters should be same what we pass in constructor Assert.True(vasp.VaspInfo.NaturalPersonIds.SequenceEqual(Settings.NaturalPersonIds)); Assert.Equal(vasp.VaspInfo.PlaceOfBirth, Settings.PlaceOfBirth); Assert.Null(vasp.VaspInfo.JuridicalPersonIds); Assert.Null(vasp.VaspInfo.BIC); }
protected override void Load(ContainerBuilder builder) { _fakeEnsProvider = new FakeEnsProvider(); _signService = new WhisperSignService(); _whisperRpc = new WhisperRpc(new Web3(_appSettings.WhisperRpcUri), new WhisperMessageFormatter()); _ethereumRpc = new EthereumRpc(new Web3(_appSettings.EthereumRpcUri)); _transportClient = new TransportClient(_whisperRpc, _signService, new WhisperMessageFormatter()); var vaspInformationBuilder = new VaspInformationBuilder(_ethereumRpc); var(vaspInfo, vaspContractInfo) = vaspInformationBuilder.Create( _appSettings.VaspSmartContractAddress); var originator = VaspClient.Create( vaspInfo, vaspContractInfo, _appSettings.HandshakePrivateKeyHex, _appSettings.SignaturePrivateKeyHex, _ethereumRpc, _whisperRpc, _fakeEnsProvider, _signService, _transportClient); builder.RegisterInstance(vaspInfo); builder.RegisterInstance(vaspContractInfo); builder.RegisterInstance(originator); builder.RegisterType <TransactionsManager>() .SingleInstance() .AsSelf() .AutoActivate(); base.Load(builder); }
public async Task CreateVaspForBank() { var signature = new EthECKey(Settings.PersonSignaturePrivateKeyHex); var handshake = ECDH_Key.ImportKey(Settings.PersonHandshakePrivateKeyHex); var signPub = signature.GetPubKey().ToHex(prefix: true); var handshakePub = handshake.PublicKey; (VaspInformation vaspInfo, VaspContractInfo vaspContractInfo) = await VaspInformationBuilder.CreateForBankAsync( NodeClient.EthereumRpc, Settings.VaspSmartContractAddressBank, Settings.Bic); VaspClient vasp = VaspClient.Create( vaspInfo, vaspContractInfo, Settings.BankHandshakePrivateKeyHex, Settings.BankSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); // VASP paramaters must be derived from smart contract Assert.NotNull(vasp.VaspInfo.Name); Assert.NotNull(vasp.VaspInfo.VaspIdentity); Assert.NotNull(vasp.VaspInfo.PostalAddress); // VASP natural person parameters should be same what we pass in constructor Assert.Equal(vasp.VaspInfo.BIC, Settings.Bic); Assert.Null(vasp.VaspInfo.NaturalPersonIds); Assert.Null(vasp.VaspInfo.PlaceOfBirth); Assert.Null(vasp.VaspInfo.JuridicalPersonIds); }
public void CreateSessionRequest( string beneficiaryName, string originatorName, PostalAddress originatorPostalAddress, PlaceOfBirth placeOfBirth, VirtualAssetType assetType, decimal transferAmount) { (VaspInformation vaspInfoPerson, VaspContractInfo vaspContractInfoPerson) = VaspInformationBuilder.CreateForNaturalPersonAsync( _ethereumRpc, _vaspSmartContractAddressPerson, _naturalPersonIds, placeOfBirth) .GetAwaiter() .GetResult(); VaspClient originator = VaspClient.Create( vaspInfoPerson, vaspContractInfoPerson, _personHandshakePrivateKeyHex, _personSignaturePrivateKeyHex, _ethereumRpc, _whisperRpc, _fakeEnsProvider, _signService, _transportClient); (VaspInformation vaspInfoJuridical, VaspContractInfo vaspContractInfoJuridical) = VaspInformationBuilder.CreateForJuridicalPersonAsync( _ethereumRpc, _vaspSmartContractAddressJuridical, _juridicalPersonIds) .GetAwaiter() .GetResult(); VaspClient beneficiary = VaspClient.Create( vaspInfoJuridical, vaspContractInfoJuridical, _juridicalHandshakePrivateKeyHex, _juridicalSignaturePrivateKeyHex, _ethereumRpc, _whisperRpc, _fakeEnsProvider, _signService, _transportClient); var originatorVaan = VirtualAssetssAccountNumber.Create(vaspInfoPerson.GetVaspCode(), "524ee3fb082809"); var beneficiaryVaan = VirtualAssetssAccountNumber.Create(vaspInfoJuridical.GetVaspCode(), "524ee3fb082809"); var vaspSession = new VaspSessionWrapper( beneficiaryName, originator, beneficiary); VaspSessions[vaspSession.Id] = vaspSession; var originatorDoc = Originator.CreateOriginatorForNaturalPerson( originatorName, originatorVaan, originatorPostalAddress, placeOfBirth, new NaturalPersonId[] { new NaturalPersonId("Id", NaturalIdentificationType.NationalIdentityNumber, Country.List["DE"]), }); vaspSession.StartSession(originatorDoc, beneficiaryVaan, assetType, transferAmount); }
public async Task CreateSessionBetweenVASPs() { int sessionTerminationCounter = 0; SessionTermination sessionTerminationDelegate = @event => { sessionTerminationCounter++; }; (VaspInformation vaspInfoPerson, VaspContractInfo vaspContractInfoPerson) = await VaspInformationBuilder.CreateForNaturalPersonAsync( NodeClient.EthereumRpc, Settings.VaspSmartContractAddressPerson, Settings.NaturalPersonIds, Settings.PlaceOfBirth); VaspClient originator = VaspClient.Create( vaspInfoPerson, vaspContractInfoPerson, Settings.PersonHandshakePrivateKeyHex, Settings.PersonSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); (VaspInformation vaspInfoJuridical, VaspContractInfo vaspContractInfoJuridical) = await VaspInformationBuilder.CreateForJuridicalPersonAsync( NodeClient.EthereumRpc, Settings.VaspSmartContractAddressJuridical, Settings.JuridicalIds); VaspClient beneficiary = VaspClient.Create( vaspInfoJuridical, vaspContractInfoJuridical, Settings.JuridicalHandshakePrivateKeyHex, Settings.JuridicalSignaturePrivateKeyHex, NodeClient.EthereumRpc, NodeClient.WhisperRpc, _fakeEnsProvider, _signService, NodeClient.TransportClient); var originatorVaan = VirtualAssetssAccountNumber.Create(vaspInfoPerson.GetVaspCode(), "524ee3fb082809"); var beneficiaryVaan = VirtualAssetssAccountNumber.Create(vaspInfoJuridical.GetVaspCode(), "524ee3fb082809"); IVaspMessageHandler messageHandler = new VaspMessageHandlerCallbacks( (vaspInfo) => { return(Task.FromResult(true)); }, (request, currentSession) => { var message = new TransferReplyMessage(currentSession.SessionId, TransferReplyMessage.TransferReplyMessageCode.TransferAccepted, request.Originator, new Beneficiary("Mr. Test", request.Beneficiary.VAAN), new TransferReply( request.Transfer.VirtualAssetType, request.Transfer.TransferType, request.Transfer.Amount, "0x0"), request.VASP); return(Task.FromResult(message)); }, (dispatch, currentSession) => { var message = new TransferConfirmationMessage(currentSession.SessionId, TransferConfirmationMessage.TransferConfirmationMessageCode.TransferConfirmed, dispatch.Originator, dispatch.Beneficiary, dispatch.Transfer, dispatch.Transaction, dispatch.VASP); return(Task.FromResult(message)); }); beneficiary.RunListener(messageHandler); originator.SessionTerminated += sessionTerminationDelegate; beneficiary.SessionTerminated += sessionTerminationDelegate; // change enum to string and add constants //beneficiary.TransferRequest += request => new TransferReply(VirtualAssetType.ETH, TransferType.BlockchainTransfer, "10", "1223"); //beneficiary.TransferDispatch += message => new TransferConfirmationMessage(); var originatorDoc = Originator.CreateOriginatorForNaturalPerson( "Test van der Test", originatorVaan, new PostalAddress( "StreetX", 44, "AddressLineX", "510051", "TownX", Country.List["DE"]), new PlaceOfBirth(DateTime.Today.AddYears(-30), "TownX", Country.List["DE"]), new NaturalPersonId[] { new NaturalPersonId("Id", NaturalIdentificationType.NationalIdentityNumber, Country.List["DE"]), }); var session = await originator.CreateSessionAsync(originatorDoc, beneficiaryVaan); var transferReply = await session.TransferRequestAsync(new TransferInstruction() { VirtualAssetTransfer = new VirtualAssetTransfer() { TransferType = TransferType.BlockchainTransfer, VirtualAssetType = VirtualAssetType.ETH, TransferAmount = "1000000000000000000" } }); var transferConformation = await session.TransferDispatchAsync(transferReply.Transfer, new Transaction("0xtxhash", DateTime.UtcNow, "0x0...a")); Assert.Equal(1, originator.GetActiveSessions().Count); Assert.True(originator.GetActiveSessions().First() is OriginatorSession); Assert.Equal(1, beneficiary.GetActiveSessions().Count); Assert.True(beneficiary.GetActiveSessions().First() is BeneficiarySession); await session.TerminateAsync(TerminationMessage.TerminationMessageCode.SessionClosedTransferOccured); session.Wait(); originator.Dispose(); beneficiary.Dispose(); Assert.Equal(2, sessionTerminationCounter); _testOutputHelper.WriteLine("End of test"); }
protected override void Load(ContainerBuilder builder) { var ethereumRpc = new EthereumRpc(new Web3(_appSettings.EthereumRpcUri)); var vaspInformationBuilder = new VaspInformationBuilder(ethereumRpc); VaspInformation vaspInfo; VaspCode vaspCode; if (_appSettings.VaspBic != null) { (vaspInfo, vaspCode) = vaspInformationBuilder .CreateForBankAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspBic) .GetAwaiter() .GetResult(); } else if (_appSettings.VaspJuridicalIds != null) { (vaspInfo, vaspCode) = vaspInformationBuilder .CreateForJuridicalPersonAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspJuridicalIds) .GetAwaiter() .GetResult(); } else if (_appSettings.VaspNaturalIds != null) { (vaspInfo, vaspCode) = vaspInformationBuilder .CreateForNaturalPersonAsync(_appSettings.VaspSmartContractAddress, _appSettings.VaspNaturalIds, _appSettings.VaspPlaceOfBirth) .GetAwaiter() .GetResult(); } else { throw new ArgumentException("Invalid configuration."); } builder.RegisterInstance(vaspInfo); builder.RegisterInstance(vaspCode); builder.RegisterInstance(ethereumRpc) .As <IEthereumRpc>() .SingleInstance(); builder.RegisterType <WhisperMessageFormatter>() .As <IMessageFormatter>() .SingleInstance(); builder.RegisterType <WhisperRpc>() .As <IWhisperRpc>() .SingleInstance() .WithParameter(TypedParameter.From((IWeb3) new Web3(_appSettings.WhisperRpcUri))); builder.RegisterType <EnsProvider>() .As <IEnsProvider>() .SingleInstance(); builder.RegisterType <WhisperSignService>() .As <ISignService>() .SingleInstance(); builder.RegisterType <WhisperTransportClient>() .As <ITransportClient>() .SingleInstance(); builder.RegisterType <TransactionDataService>() .As <ITransactionDataService>() .SingleInstance(); builder.RegisterType <TransactionsManager>() .SingleInstance() .As <ITransactionsManager>() .AutoActivate() .WithParameter("handshakePrivateKeyHex", _appSettings.HandshakePrivateKeyHex) .WithParameter("signaturePrivateKeyHex", _appSettings.SignaturePrivateKeyHex); builder.RegisterType <VaspCodeManager>() .As <IVaspCodeManager>() .WithParameter(TypedParameter.From((IEnumerable <string>)_appSettings.AutoConfirmedVaspCodes)) .SingleInstance(); builder.RegisterInMemoryRepositories(); base.Load(builder); }