private async Task ObtainRelations(TransferAssetToUtxo packet, byte[] assetId) { _logger.Debug($"[{_accountId}]: {nameof(ObtainRelations)}"); IEnumerable <RegistrationKeyDescriptionStore> groupRelations = await _schemeResolverService.GetGroupRelations(packet.Signer.ToString(), assetId.ToHexString()).ConfigureAwait(false); foreach (var groupRelation in groupRelations) { string groupOwnerName = await _schemeResolverService.ResolveIssuer(groupRelation.Key).ConfigureAwait(false); long groupRelationId = _dataAccessService.AddUserGroupRelation(_accountId, groupOwnerName, groupRelation.Key, groupRelation.Description, groupRelation.AssetId, groupRelation.Issuer); if (groupRelationId > 0) { GroupRelationDto groupRelationDto = new GroupRelationDto { GroupRelationId = groupRelationId, GroupOwnerName = groupOwnerName, GroupOwnerKey = groupRelation.Key, GroupName = groupRelation.Description, Issuer = groupRelation.Issuer, AssetId = groupRelation.AssetId }; await _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushGroupRelation", groupRelationDto).ConfigureAwait(false); } } }
protected override Memory <byte> ParseTransactionalTransitional(ushort version, Memory <byte> spanBody, out TransactionalTransitionalPacketBase transactionalBlockBase) { TransferAssetToUtxo block = null; if (version == 1) { int readBytes = 0; byte[] assetCommitment = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; byte[] assetId = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; byte[] mask = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; ushort assetCommitmentsCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Slice(readBytes).Span); readBytes += sizeof(ushort); byte[][] assetCommitments = new byte[assetCommitmentsCount][]; for (int i = 0; i < assetCommitmentsCount; i++) { assetCommitments[i] = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; } byte[] e = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; byte[][] s = new byte[assetCommitmentsCount][]; for (int i = 0; i < assetCommitmentsCount; i++) { s[i] = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray(); readBytes += Globals.NODE_PUBLIC_KEY_SIZE; } block = new TransferAssetToUtxo { TransferredAsset = new EncryptedAsset { AssetCommitment = assetCommitment, EcdhTuple = new EcdhTupleCA { AssetId = assetId, Mask = mask } }, SurjectionProof = new SurjectionProof { AssetCommitments = assetCommitments, Rs = new BorromeanRingSignature { E = e, S = s } } }; transactionalBlockBase = block; return(spanBody.Slice(readBytes)); } throw new BlockVersionNotSupportedException(version, BlockType); }
public void TransferAssetToUtxoSerializerTest() { ulong syncBlockHeight = 1; uint nonce = 4; byte[] powHash = BinaryHelper.GetPowHash(1234); ushort version = 1; ulong blockHeight = 9; ulong uptodateFunds = 10002; byte[] destinationKey = ConfidentialAssetsHelper.GetRandomSeed(); byte[] transactionKey = ConfidentialAssetsHelper.GetRandomSeed(); byte[] body; byte[] assetCommitment = ConfidentialAssetsHelper.GetRandomSeed(); byte[] mask = ConfidentialAssetsHelper.GetRandomSeed(); byte[] maskedAssetId = ConfidentialAssetsHelper.GetRandomSeed(); ushort assetCommitmentsCount = 10; byte[][] assetCommitments = new byte[assetCommitmentsCount][]; byte[] e = ConfidentialAssetsHelper.GetRandomSeed(); byte[][] s = new byte[assetCommitmentsCount][]; for (int i = 0; i < assetCommitmentsCount; i++) { assetCommitments[i] = ConfidentialAssetsHelper.GetRandomSeed(); s[i] = ConfidentialAssetsHelper.GetRandomSeed(); } using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write(uptodateFunds); bw.Write(destinationKey); bw.Write(transactionKey); bw.Write(assetCommitment); bw.Write(maskedAssetId); bw.Write(mask); bw.Write(assetCommitmentsCount); for (int i = 0; i < assetCommitmentsCount; i++) { bw.Write(assetCommitments[i]); } bw.Write(e); for (int i = 0; i < assetCommitmentsCount; i++) { bw.Write(s[i]); } } body = ms.ToArray(); } byte[] expectedPacket = BinaryHelper.GetSignedPacket(PacketType.Transactional, syncBlockHeight, nonce, powHash, version, BlockTypes.Transaction_TransferAssetToUtxo, blockHeight, null, body, _privateKey, out byte[] expectedSignature); TransferAssetToUtxo packet = new TransferAssetToUtxo { SyncBlockHeight = syncBlockHeight, Nonce = nonce, PowHash = powHash, BlockHeight = blockHeight, UptodateFunds = uptodateFunds, DestinationKey = destinationKey, TransactionPublicKey = transactionKey, TransferredAsset = new EncryptedAsset { AssetCommitment = assetCommitment, EcdhTuple = new EcdhTupleCA { Mask = mask, AssetId = maskedAssetId } }, SurjectionProof = new SurjectionProof { AssetCommitments = assetCommitments, Rs = new BorromeanRingSignature { E = e, S = s } } }; TransferAssetToUtxoSerializer serializer = new TransferAssetToUtxoSerializer(); serializer.Initialize(packet); serializer.SerializeBody(); _signingService.Sign(packet); byte[] actualPacket = serializer.GetBytes(); Assert.Equal(expectedPacket, actualPacket); }
public void TransferAssetToUtxoParserTest() { ulong syncBlockHeight = 1; uint nonce = 4; byte[] powHash = BinaryHelper.GetPowHash(1234); ushort version = 1; ulong blockHeight = 9; ulong uptodateFunds = 10002; byte[] destinationKey = ConfidentialAssetsHelper.GetRandomSeed(); byte[] transactionKey = ConfidentialAssetsHelper.GetRandomSeed(); byte[] body; byte[] assetCommitment = ConfidentialAssetsHelper.GetRandomSeed(); byte[] mask = ConfidentialAssetsHelper.GetRandomSeed(); byte[] maskedAssetId = ConfidentialAssetsHelper.GetRandomSeed(); ushort assetCommitmentsCount = 10; byte[][] assetCommitments = new byte[assetCommitmentsCount][]; byte[] e = ConfidentialAssetsHelper.GetRandomSeed(); byte[][] s = new byte[assetCommitmentsCount][]; for (int i = 0; i < assetCommitmentsCount; i++) { assetCommitments[i] = ConfidentialAssetsHelper.GetRandomSeed(); s[i] = ConfidentialAssetsHelper.GetRandomSeed(); } using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write(uptodateFunds); bw.Write(destinationKey); bw.Write(transactionKey); bw.Write(assetCommitment); bw.Write(maskedAssetId); bw.Write(mask); bw.Write(assetCommitmentsCount); for (int i = 0; i < assetCommitmentsCount; i++) { bw.Write(assetCommitments[i]); } bw.Write(e); for (int i = 0; i < assetCommitmentsCount; i++) { bw.Write(s[i]); } } body = ms.ToArray(); } byte[] packet = BinaryHelper.GetSignedPacket( PacketType.Synchronization, syncBlockHeight, nonce, powHash, version, BlockTypes.Transaction_TransferAssetToUtxo, blockHeight, null, body, _privateKey, out byte[] expectedSignature); TransferAssetToUtxoParser parser = new TransferAssetToUtxoParser(_identityKeyProvidersRegistry); TransferAssetToUtxo block = (TransferAssetToUtxo)parser.Parse(packet); Assert.Equal(syncBlockHeight, block.SyncBlockHeight); Assert.Equal(nonce, block.Nonce); Assert.Equal(powHash, block.PowHash); Assert.Equal(version, block.Version); Assert.Equal(blockHeight, block.BlockHeight); Assert.Equal(destinationKey, block.DestinationKey); Assert.Equal(transactionKey, block.TransactionPublicKey); Assert.Equal(assetCommitment, block.TransferredAsset.AssetCommitment); Assert.Equal(maskedAssetId, block.TransferredAsset.EcdhTuple.AssetId); Assert.Equal(mask, block.TransferredAsset.EcdhTuple.Mask); Assert.Equal(assetCommitmentsCount, block.SurjectionProof.AssetCommitments.Length); Assert.Equal(e, block.SurjectionProof.Rs.E); for (int i = 0; i < assetCommitmentsCount; i++) { Assert.Equal(assetCommitments[i], block.SurjectionProof.AssetCommitments[i]); Assert.Equal(s[i], block.SurjectionProof.Rs.S[i]); } Assert.Equal(expectedSignature, block.Signature.ToArray()); }