示例#1
0
        public async Task SignSampleDocument()
        {
            // an example document to sign
            var document = JObject.Parse(@"{
                'id': 'Alice'
            }");

            // signer key
            var key = Ed25519VerificationKey2018.Generate();

            // create proof
            var signedDocument = await LdSignatures.SignAsync(
                document,
                new ProofOptions
            {
                Suite = new Ed25519Signature2018
                {
                    Signer             = key,
                    VerificationMethod = key.Id
                },
                Purpose = new AssertionMethodPurpose()
            });

            Console.WriteLine(signedDocument.ToString(Formatting.Indented));
        }
        public void GenerateRandomKey()
        {
            var method = Ed25519VerificationKey2018.Generate();

            Assert.NotNull(method);
            Assert.NotNull(method.PublicKeyBase58);
            Assert.NotNull(method.PrivateKeyBase58);
            Assert.Equal(Ed25519VerificationKey2018.Name, method.TypeName);
        }
        public void VerifyPayload()
        {
            var method    = Ed25519VerificationKey2018.Generate();
            var payload   = (ByteArray)Encoding.UTF8.GetBytes("my message");
            var signature = method.Sign(payload);

            var verified = method.Verify(signature, payload);

            Assert.True(verified);
        }
        public void SignPayload()
        {
            var method  = Ed25519VerificationKey2018.Generate();
            var payload = Encoding.UTF8.GetBytes("my message");

            var signature = method.Sign((ByteArray)payload);

            Assert.NotNull(signature);
            Assert.Equal(Chaos.NaCl.Ed25519.SignatureSizeInBytes, signature.Length);
        }