Skip to content

Commit e792f23

Browse files
authored
fix: Update signature documentation. (#68)
1 parent 022a8f4 commit e792f23

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ match result {
440440

441441
*Note that this only verifies the hash. If you also want to verify the signature, you can skip this step and call `verify_signature` directly, which performs a hash verification internally.*
442442

443+
### Verifying an Event's Signature
444+
445+
To verify the authenticity of an event, call the `verify_signature` function on the event instance. This requires the public key that matches the private key used for signing on the server.
446+
447+
The function first verifies the event's hash, and then checks the signature. If any verification step fails, it returns an error:
448+
449+
```rust
450+
use ed25519_dalek::VerifyingKey;
451+
452+
// ...
453+
454+
let verification_key = // public key as VerifyingKey
455+
456+
let result = event.verify_signature(&verification_key);
457+
match result {
458+
Ok(()) => // ...
459+
Err(err) => // ...
460+
}
461+
```
462+
443463
### Using Testcontainers
444464

445465
Call the `Container::start_default()` function, get a client, and run your test code:
@@ -470,6 +490,24 @@ let container = Container::builder()
470490
.await.unwrap()
471491
```
472492

493+
If you want to sign events, call the `with_signing_key` function. This generates a new signing and verification key pair inside the container:
494+
495+
```rust
496+
let container = Container::builder()
497+
.with_signing_key()
498+
.build()
499+
.await.unwrap()
500+
```
501+
502+
You can retrieve the private key (for signing) and the public key (for verifying signatures) once the container has been started:
503+
504+
```rust
505+
let signing_key = container.get_signing_key().await?;
506+
let verification_key = container.get_verification_key().await?;
507+
```
508+
509+
The `signing_key` can be used when configuring the container to sign outgoing events. The `verification_key` can be passed to `verify_signature` when verifying events read from the database.
510+
473511
#### Configuring the Client Manually
474512

475513
In case you need to set up the client yourself, use the following functions to get details on the container:

0 commit comments

Comments
 (0)