Ejemplo n.º 1
0
        public bool SendAssetTransition(byte[] assetId, byte[] transactionKey, byte[] assetCommitment, byte[] prevDestinationKey, ulong tagId, Account target)
        {
            UtxoConfidentialBase block         = (UtxoConfidentialBase)CreateNonQuantitativeTransitionAssetTransferBlock(target, assetId, transactionKey, assetCommitment, prevDestinationKey, 3, tagId, out byte[] otsk, out int pos);
            BlockBase            registerBlock = CreateUtxoRegisterBlock(block, otsk, pos);

            return(_networkAdapter.SendTransaction(block, registerBlock));
        }
Ejemplo n.º 2
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int readBytes = 0;

                ReadCommitment(ref spanBody, ref readBytes, out byte[] assetCommitment);
                ReadEcdhTupleProofs(ref spanBody, ref readBytes, out EcdhTupleProofs ecdhTuple);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof ownershipProofs);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof eligibilityProofs);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof authenticationProofs);

                block = new TransitionAuthenticationProofs
                {
                    AssetCommitment     = assetCommitment,
                    EncodedPayload      = ecdhTuple,
                    OwnershipProof      = ownershipProofs,
                    EligibilityProof    = eligibilityProofs,
                    AuthenticationProof = authenticationProofs
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Ejemplo n.º 3
0
 private void UpdateUtxoConfidentialTransaction(UtxoConfidentialBase utxoConfidentialBase, ulong registryCombinedBlockHeight)
 {
     switch (utxoConfidentialBase.BlockType)
     {
     case BlockTypes.UtxoConfidential_NonQuantitativeTransitionAssetTransfer:
         ProcessNonQuantitativeTransitionAssetTransfer(utxoConfidentialBase as NonQuantitativeTransitionAssetTransferBlock, registryCombinedBlockHeight);
         break;
     }
 }
Ejemplo n.º 4
0
        protected override Memory <byte> FillBlockBaseHeader(BlockBase blockBase, Memory <byte> spanHeader)
        {
            UtxoConfidentialBase utxoConfidentialBase = (UtxoConfidentialBase)blockBase;

            spanHeader = base.FillBlockBaseHeader(blockBase, spanHeader);

            utxoConfidentialBase.SyncBlockHeight = BinaryPrimitives.ReadUInt64LittleEndian(spanHeader.Span);
            utxoConfidentialBase.Nonce           = BinaryPrimitives.ReadUInt32LittleEndian(spanHeader.Slice(Globals.SYNC_BLOCK_HEIGHT_LENGTH).Span);
            utxoConfidentialBase.PowHash         = spanHeader.Slice(Globals.SYNC_BLOCK_HEIGHT_LENGTH + Globals.NONCE_LENGTH, Globals.POW_HASH_SIZE).ToArray();

            return(spanHeader.Slice(Globals.SYNC_BLOCK_HEIGHT_LENGTH + Globals.NONCE_LENGTH + Globals.POW_HASH_SIZE));
        }
Ejemplo n.º 5
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int readBytes = 0;

                ReadCommitmentAndProof(ref spanBody, ref readBytes, out byte[] assetCommitment, out SurjectionProof surjectionProof);
                ReadCommitmentAndProof(ref spanBody, ref readBytes, out byte[] affiliationAssetCommitment, out SurjectionProof affiliationSurjectionProof);

                ushort affiliationKeysCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                byte[][] affiliationKeys = new byte[affiliationKeysCount][];
                for (int i = 0; i < affiliationKeysCount; i++)
                {
                    affiliationKeys[i] = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray();
                    readBytes         += Globals.NODE_PUBLIC_KEY_SIZE;
                }

                ReadBorromeanRingSignature(ref spanBody, ref readBytes, out BorromeanRingSignature borromeanRingSignature);

                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof surjectionEvidenceProof);

                ReadEcdhTupleCA(ref spanBody, ref readBytes, out EcdhTupleCA ecdhTuple);

                block = new TransitionAffiliatedAssetTransfer
                {
                    AssetCommitment                    = assetCommitment,
                    SurjectionProof                    = surjectionProof,
                    AffiliationCommitment              = affiliationAssetCommitment,
                    AffiliationSurjectionProof         = affiliationSurjectionProof,
                    AffiliationKeys                    = affiliationKeys,
                    AffiliationBorromeanSignature      = borromeanRingSignature,
                    AffiliationEvidenceSurjectionProof = surjectionEvidenceProof,
                    EcdhTuple = ecdhTuple
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Ejemplo n.º 6
0
        public BlockBase CreateUtxoRegisterBlock(UtxoConfidentialBase confidentialBase, byte[] otsk, int actualAssetPos)
        {
            byte[] msg = ConfidentialAssetsHelper.FastHash256(confidentialBase.RawData.ToArray());

            RegistryRegisterUtxoConfidentialBlock registryRegisterUtxoConfidentialBlock = new RegistryRegisterUtxoConfidentialBlock
            {
                SyncBlockHeight      = confidentialBase.SyncBlockHeight,
                Nonce                = confidentialBase.Nonce,
                PowHash              = confidentialBase.PowHash,
                ReferencedPacketType = confidentialBase.PacketType,
                ReferencedBlockType  = confidentialBase.BlockType,
                DestinationKey       = confidentialBase.DestinationKey,
                KeyImage             = confidentialBase.KeyImage,
                ReferencedBodyHash   = _hashCalculation.CalculateHash(confidentialBase.RawData),
                TransactionPublicKey = confidentialBase.TransactionPublicKey,
                TagId                = confidentialBase.TagId,
                PublicKeys           = confidentialBase.PublicKeys,
                Signatures           = ConfidentialAssetsHelper.GenerateRingSignature(msg, confidentialBase.KeyImage.Value.ToArray(), confidentialBase.PublicKeys.Select(p => p.Value.ToArray()).ToArray(), otsk, actualAssetPos)
            };

            return(registryRegisterUtxoConfidentialBlock);
        }
Ejemplo n.º 7
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            if (version == 1)
            {
                int readBytes = 0;

                PacketType referencedPacketType = (PacketType)BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span);
                readBytes += 2;

                ushort referencedBlockType = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += 2;

                byte[] referencedBlockHash = spanBody.Slice(readBytes, Globals.DEFAULT_HASH_SIZE).ToArray();
                readBytes += Globals.DEFAULT_HASH_SIZE;

                RegistryRegisterUtxoConfidential registryRegisterUtxoConfidentialBlock = new RegistryRegisterUtxoConfidential
                {
                    ReferencedPacketType = referencedPacketType,
                    ReferencedBlockType  = referencedBlockType,
                    ReferencedBodyHash   = referencedBlockHash,
                };

                utxoConfidentialBase = registryRegisterUtxoConfidentialBlock;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Ejemplo n.º 8
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int    readBytes       = 0;
                byte[] assetCommitment = spanBody.Slice(readBytes, 32).ToArray();
                readBytes += 32;

                ushort assetCommitmentsCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Slice(readBytes).Span);
                readBytes += 2;

                byte[][] assetCommitments = new byte[assetCommitmentsCount][];
                for (int i = 0; i < assetCommitmentsCount; i++)
                {
                    assetCommitments[i] = spanBody.Slice(readBytes, 32).ToArray();
                    readBytes          += 32;
                }

                byte[] e = spanBody.Slice(readBytes, 32).ToArray();
                readBytes += 32;

                byte[][] s = new byte[assetCommitmentsCount][];
                for (int i = 0; i < assetCommitmentsCount; i++)
                {
                    s[i]       = spanBody.Slice(readBytes, 32).ToArray();
                    readBytes += 32;
                }

                byte[] mask = spanBody.Slice(readBytes, 32).ToArray();
                readBytes += 32;

                byte[] assetId = spanBody.Slice(readBytes, 32).ToArray();
                readBytes += 32;

                SurjectionProof surjectionProof = new SurjectionProof
                {
                    AssetCommitments = assetCommitments,
                    Rs = new BorromeanRingSignature
                    {
                        E = e,
                        S = s
                    }
                };

                block = new AssetTransfer
                {
                    AssetCommitment = assetCommitment,
                    SurjectionProof = surjectionProof,
                    EcdhTuple       = new EcdhTupleCA
                    {
                        Mask    = mask,
                        AssetId = assetId
                    }
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Ejemplo n.º 9
0
 protected abstract Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase);
Ejemplo n.º 10
0
 public UtxoConfidentialSourceKey(UtxoConfidentialBase utxoConfidentialBase)
 {
     _utxoConfidentialBase = utxoConfidentialBase;
 }
Ejemplo n.º 11
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int readBytes = 0;

                ReadCommitment(ref spanBody, ref readBytes, out byte[] assetCommitment);
                ReadEcdhTupleProofs(ref spanBody, ref readBytes, out EcdhTupleProofs ecdhTuple);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof ownershipProofs);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof eligibilityProofs);

                byte associatedProofsCount = spanBody.Slice(readBytes++).Span[0];

                AssociatedProofs[] associatedProofs = new AssociatedProofs[associatedProofsCount];

                for (int i = 0; i < associatedProofsCount; i++)
                {
                    byte associatedProofType = spanBody.Slice(readBytes++).Span[0];

                    AssociatedProofs associatedProof;

                    if (associatedProofType == 1)
                    {
                        ReadCommitment(ref spanBody, ref readBytes, out byte[] associatedAssetCommitment);
                        associatedProof = new AssociatedAssetProofs
                        {
                            AssociatedAssetCommitment = associatedAssetCommitment
                        };
                    }
                    else
                    {
                        associatedProof = new AssociatedProofs();
                    }

                    ReadCommitment(ref spanBody, ref readBytes, out byte[] associatedGroupId);
                    ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof associationProofs);
                    ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof rootProofs);

                    associatedProof.AssociatedAssetGroupId = associatedGroupId;
                    associatedProof.AssociationProofs      = associationProofs;
                    associatedProof.RootProofs             = rootProofs;

                    associatedProofs[i] = associatedProof;
                }

                block = new TransitionOnboardingDisclosingProofs
                {
                    AssetCommitment  = assetCommitment,
                    EcdhTuple        = ecdhTuple,
                    OwnershipProof   = ownershipProofs,
                    EligibilityProof = eligibilityProofs,
                    AssociatedProofs = associatedProofs
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Ejemplo n.º 12
0
 private void FillSyncData(UtxoConfidentialBase block)
 {
     Proto.Model.SyncBlockDescriptor lastSyncBlock = _networkAdapter.GetLastSyncBlock();
     block.SyncBlockHeight = lastSyncBlock.Height;
     block.PowHash         = GetPowHash(lastSyncBlock.Hash.ToByteArray(), 0);
 }
Ejemplo n.º 13
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int readBytes = 0;

                ReadCommitmentAndProof(ref spanBody, ref readBytes, out byte[] assetCommitment, out SurjectionProof surjectionProof);
                ReadCommitmentAndProof(ref spanBody, ref readBytes, out byte[] affiliationAssetCommitment, out SurjectionProof affiliationSurjectionProof);

                ushort affiliationPseudoKeysCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += 2;

                byte[][] affiliationPseudoKeys = new byte[affiliationPseudoKeysCount][];
                for (int i = 0; i < affiliationPseudoKeysCount; i++)
                {
                    affiliationPseudoKeys[i] = spanBody.Slice(readBytes, 32).ToArray();
                    readBytes += 32;
                }

                byte[] e = spanBody.Slice(readBytes, 32).ToArray();
                readBytes += 32;

                ushort sCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += 2;

                byte[][] s = new byte[sCount][];
                for (int i = 0; i < sCount; i++)
                {
                    s[i]       = spanBody.Slice(readBytes, 32).ToArray();
                    readBytes += 32;
                }

                BorromeanRingSignature borromeanRingSignature = new BorromeanRingSignature {
                    E = e, S = s
                };

                SurjectionProof surjectionEvidenceProof = GetSurhectionProof(ref spanBody, ref readBytes);

                ReadEcdhTupleCA(ref spanBody, ref readBytes, out byte[] mask, out byte[] assetId);

                block = new NonQuantitativeTransitionAssetTransferBlock
                {
                    AssetCommitment                    = assetCommitment,
                    SurjectionProof                    = surjectionProof,
                    AffiliationCommitment              = affiliationAssetCommitment,
                    AffiliationSurjectionProof         = affiliationSurjectionProof,
                    AffiliationPseudoKeys              = affiliationPseudoKeys,
                    AffiliationBorromeanSignature      = borromeanRingSignature,
                    AffiliationEvidenceSurjectionProof = surjectionEvidenceProof,
                    EcdhTuple = new EcdhTupleCA
                    {
                        Mask    = mask,
                        AssetId = assetId
                    }
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }