Exemplo n.º 1
0
        public async Task Deposit(IEnumerable <Token> tokens, CancellationToken cancellationToken)
        {
            using (var iterator = tokens.GetEnumerator())
            {
                if (!iterator.MoveNext())
                {
                    return;
                }

                var token         = iterator.Current;
                var mintRequestId = TokenIdentifier.Parse(token.Id).MintRequestId;
                var list          = new List <Token>()
                {
                    token
                };

                await repository.Save(token, ExpectedVersion.Initial, cancellationToken);

                while (iterator.MoveNext())
                {
                    token = iterator.Current;
                    await repository.Save(token, ExpectedVersion.Initial, cancellationToken);

                    list.Add(token);
                }

                deposited.Add(mintRequestId, list);
            }
        }
Exemplo n.º 2
0
        T DecryptFiveByFive(T item)
        {
            var properties = ToDictionary(new ProjectionProxy(item));
            var tokenId    = properties["id"];
            var code       = properties["code"];
            var hash       = properties["hash"];
            var salt       = TokenIdentifier.Parse(tokenId.Value).MintRequestId.ToByteArray();

            using (var tokenCode = tokenSecurity.DecryptFromBase64(code.Value, hash.Value, salt))
            {
                var fiveByFive = SecureStringToGlobalAllocAnsi(tokenCode);

                try
                {
                    code.Value = PtrToStringAnsi(fiveByFive);
                }
                finally
                {
                    if (fiveByFive != IntPtr.Zero)
                    {
                        ZeroFreeGlobalAllocAnsi(fiveByFive);
                    }
                }
            }

            return(item);
        }
Exemplo n.º 3
0
        public Task RemoveFromCirculation(Guid mintRequestId, string correlationId, CancellationToken cancellationToken)
        {
            foreach (var circulated in vault.Select(p => p.Value))
            {
                var tokenIds = circulated.ToArray();

                foreach (var tokenId in tokenIds)
                {
                    var id = TokenIdentifier.Parse(tokenId);

                    if (id.MintRequestId == mintRequestId)
                    {
                        circulated.Remove(tokenId);
                    }
                }
            }

            return(CompletedTask);
        }
Exemplo n.º 4
0
        Token DecryptFiveByFive(Token token)
        {
            var salt = TokenIdentifier.Parse(token.Id).MintRequestId.ToByteArray();

            using (var tokenCode = tokenSecurity.DecryptFromBase64(token.Code, token.Hash, salt))
            {
                var fiveByFive = SecureStringToGlobalAllocAnsi(tokenCode);

                try
                {
                    token.Code = PtrToStringAnsi(fiveByFive);
                }
                finally
                {
                    if (fiveByFive != IntPtr.Zero)
                    {
                        ZeroFreeGlobalAllocAnsi(fiveByFive);
                    }
                }
            }

            return(token);
        }