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 async Task SignAndVerifyDocument() { var aliceKey = new Ed25519VerificationKey2018(Mock.Alice_Keys.VerificationMethod.First() as JObject); var signedDocument = await LdSignatures.SignAsync( Mock.ExampleDoc, new ProofOptions { Suite = new JcsEd25519Signature2020 { Signer = aliceKey, VerificationMethod = aliceKey.Id }, Purpose = new AssertionMethodPurpose(), DocumentLoader = Mock.DocumentLoader }); var verified = await LdSignatures.VerifyAsync( document: signedDocument, options: new ProofOptions { Suite = new JcsEd25519Signature2020 { Signer = aliceKey, VerificationMethod = aliceKey.Id }, Purpose = new AssertionMethodPurpose(), DocumentLoader = Mock.DocumentLoader }); Assert.NotNull(verified); }
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); }
public async Task SignDocument() { var aliceKey = new Ed25519VerificationKey2018(Mock.Alice_Keys.VerificationMethod.First() as JObject); var signedDocument = await LdSignatures.SignAsync( Mock.ExampleDoc, new ProofOptions { Suite = new JcsEd25519Signature2020 { Signer = aliceKey, VerificationMethod = aliceKey.Id }, Purpose = new AssertionMethodPurpose(), DocumentLoader = Mock.DocumentLoader }); Assert.NotNull(signedDocument); Assert.NotNull(signedDocument["proof"]); Assert.Equal("assertionMethod", signedDocument["proof"]?["proofPurpose"]); Assert.NotNull(signedDocument["proof"]?["signatureValue"]); Assert.Equal(aliceKey.Id, signedDocument["proof"]?["verificationMethod"]); }
public async Task VerifyProofRandomKey() { var signer = new Ed25519VerificationKey2018(Mock.Diana_Keys.VerificationMethod.First() as JObject); var document = new DidDocument { Id = signer.Controller }; var signedDocument = await LdSignatures.SignAsync( document, new ProofOptions { Suite = new Ed25519Signature2018 { Signer = signer, VerificationMethod = signer.Id }, Purpose = new AssertionMethodPurpose(), DocumentLoader = Mock.DocumentLoader }); signedDocument["@context"] = new JArray(new[] { Constants.DID_V1_URL, Constants.SECURITY_CONTEXT_V2_URL }); var result = await LdSignatures.VerifyAsync(signedDocument, new ProofOptions { Suite = new Ed25519Signature2018(), Purpose = new AssertionMethodPurpose(), DocumentLoader = Mock.DocumentLoader }); Assert.NotNull(result); }