Esempio n. 1
0
        public void GenerateCapabilityInvocationProofWithJcs()
        {
            var capability = new JObject
            {
                { "@context", "https://w3id.org/security/v2" },
                { "target", "urn:trinsic:wallets:noop" },
                { "proof", new JObject
                  {
                      { "created", DateTime.UtcNow.ToString("s") }
                  } }
            };

            var key = DIDKey.Generate(new GenerateKeyRequest {
                KeyType = KeyType.Ed25519
            });
            var signingKey = key.Key.First(x => x.Crv == "Ed25519");

            var signedCapability = LDProofs.CreateProof(new CreateProofRequest
            {
                Key      = signingKey,
                Document = capability.ToStruct(),
                Suite    = LdSuite.Jcsed25519Signature2020
            });

            signedCapability.Should().NotBeNull();
            signedCapability.SignedDocument.Should().NotBeNull();
        }
Esempio n. 2
0
 public void TestGenerateKeyThrowsInvalidSeedSize()
 {
     Assert.Throws <DIDCommException>(() =>
                                      _ = DIDKey.Generate(new GenerateKeyRequest
     {
         KeyType = (KeyType)(-1)
     })
                                      );
 }
Esempio n. 3
0
        public void TestGenerateKeyNoSeed()
        {
            var response = DIDKey.Generate(new GenerateKeyRequest {
                KeyType = KeyType.Ed25519
            });

            byte[] x         = System.Convert.FromBase64String(base64toBase64Url(response.Key[0].X));
            byte[] y         = System.Convert.FromBase64String(base64toBase64Url(response.Key[0].Y));
            byte[] publicKey = new byte[x.Length + y.Length];

            System.Buffer.BlockCopy(x, 0, publicKey, 0, x.Length);
            System.Buffer.BlockCopy(y, 0, publicKey, x.Length, y.Length);

            response.Should().NotBeNull();
            response.Key.Should().NotBeNull();
            response.Key[0].Crv.Should().Be("Ed25519");
            publicKey.Should().NotBeNull().And.HaveCount(32);
            System.Convert.FromBase64String(base64toBase64Url(response.Key[0].D)).Should().NotBeNull().And.HaveCount(32);
        }
Esempio n. 4
0
        public void TestGenerateKeyFromSeed(KeyType keyType, string crv, string seed, string publicKey)
        {
            var response = DIDKey.Generate(new GenerateKeyRequest
            {
                KeyType = keyType,
                Seed    = ByteString.CopyFrom(StringToByteArray(seed))
            });;

            byte[] x  = System.Convert.FromBase64String(base64toBase64Url(response.Key[0].X));
            byte[] y  = System.Convert.FromBase64String(base64toBase64Url(response.Key[0].Y));
            byte[] pk = new byte[x.Length + y.Length];

            System.Buffer.BlockCopy(x, 0, pk, 0, x.Length);
            System.Buffer.BlockCopy(y, 0, pk, x.Length, y.Length);

            response.Should().NotBeNull();
            response.Key[0].Should().NotBeNull();
            response.Key[0].Crv.Should().Be(crv);
            pk.Should().NotBeNull().And.HaveCount(32);
            System.Convert.FromBase64String(base64toBase64Url(response.Key[0].D)).Should().NotBeNull().And.HaveCount(32);
            publicKey.Should().Be(Multibase.Base58.Encode(pk));
        }