コード例 #1
0
        public void VerifyTrust(TrustModel trust)
        {
            var schema = new TrustSchema(trust);

            if (!schema.Validate())
            {
                var msg = string.Join(". ", schema.Errors.ToArray());
                throw new ApplicationException(msg);
            }

            var signature = new TrustECDSASignature(trust);
            var errors    = signature.VerifyTrustSignatureMessage();

            if (errors.Count > 0)
            {
                throw new ApplicationException(string.Join(". ", errors.ToArray()));
            }
        }
コード例 #2
0
ファイル: TrustBuilder.cs プロジェクト: keutmann/Trustgraph
        public static TrustModel CreateTrust(string issuerName, string subjectName, JObject claim)
        {
            var issuerKey  = new Key(Hashes.SHA256(Encoding.UTF8.GetBytes(issuerName)));
            var subjectKey = new Key(Hashes.SHA256(Encoding.UTF8.GetBytes(subjectName)));
            var serverKey  = new Key(Hashes.SHA256(Encoding.UTF8.GetBytes("server")));

            var trust = new TrustModel();

            trust.Head = new HeadModel
            {
                Version = "standard 0.1.0",
                Script  = "btc-pkh"
            };
            trust.Server    = new ServerModel();
            trust.Server.Id = serverKey.PubKey.GetAddress(App.BitcoinNetwork).Hash.ToBytes();
            trust.Issuer    = new IssuerModel();
            trust.Issuer.Id = issuerKey.PubKey.GetAddress(App.BitcoinNetwork).Hash.ToBytes();
            var subjects = new List <SubjectModel>();

            subjects.Add(new SubjectModel
            {
                Id     = subjectKey.PubKey.GetAddress(App.BitcoinNetwork).Hash.ToBytes(),
                IdType = "person",
                Claim  = (claim != null) ? claim : new JObject(
                    new JProperty("trust", "true")
                    ),
                Scope = "global"
            });
            trust.Issuer.Subjects = subjects.ToArray();

            var binary = new TrustBinary(trust);

            trust.TrustId = TrustECDSASignature.GetHashOfBinary(binary.GetIssuerBinary());
            var trustHash = new uint256(trust.TrustId);

            trust.Issuer.Signature = issuerKey.SignCompact(trustHash);

            return(trust);
        }
コード例 #3
0
 public static byte[] GetTrustId(TrustModel trust)
 {
     return(TrustECDSASignature.GetHashOfBinary(GetTrustBinary(trust)));
 }