Skip to content

Commit

Permalink
chore(README): add examples and update roadmap
Browse files Browse the repository at this point in the history
  • Loading branch information
RTann committed Oct 9, 2024
1 parent 7cf77d5 commit 2187e0c
Showing 1 changed file with 109 additions and 4 deletions.
113 changes: 109 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,115 @@ APIs similar to the source repository.

Only libsignal-protocol is implemented at this time.

This repository is still under development, so
breaking changes should be expected.
This repository is still under development, so users should expect
breaking changes.

## How to Use

### Protocol

#### Session

```go
package main

import (
"context"
"crypto/rand"

"github.com/RTann/libsignal-go/protocol/address"
"github.com/RTann/libsignal-go/protocol/identity"
"github.com/RTann/libsignal-go/protocol/session"
)

// Alice creates a session with Bob and sends a message.
// Error handing is ignored in this example, but should otherwise not be ignored.
func main() {
aliceIdentityKeyPair, _ := identity.GenerateKeyPair(rand.Reader)
aliceBaseKeyPair, _ := curve.GenerateKeyPair(rand.Reader)

var bobIdentity identity.Key
var bobSignedPreKey curve.PublicKey
var bobEphemeralKey curve.PublicKey

aliceParams := &ratchet.AliceParameters{
OurIdentityKeyPair: aliceIdentityKeyPair,
OurBaseKeyPair: aliceBaseKeyPair,
TheirIdentityKey: bobIdentity,
TheirSignedPreKey: bobSignedPreKey,
TheirOneTimePreKey: nil,
TheirRatchetKey: bobEphemeralKey,
}
aliceRecord, _ := session.InitializeAliceSessionRecord(rand.Reader, aliceParams)

registrationID := uint32(1)
bobAddress := address.Address{
Name: "+15555555555",
DeviceID: 1,
}

// Alice creates a session to talk to Bob.
aliceSession := &session.Session{
RemoteAddress: bobAddress,
SessionStore: session.NewInMemStore(),
IdentityKeyStore: identity.NewInMemStore(aliceIdentityKeyPair, registrationID),
}
_ = aliceSession.SessionStore.Store(context.Background(), bobAddress, aliceRecord)
// Write a nice encrypted message to Bob.
plaintext := []byte("Hello, Bob!")
aliceCiphertext, _ := aliceSession.EncryptMessage(context.Background(), plaintext)

// Alice sends her encrypted message to Bob.
}
```

```go
package main

import (
"context"
"crypto/rand"

"github.com/RTann/libsignal-go/protocol/address"
"github.com/RTann/libsignal-go/protocol/identity"
"github.com/RTann/libsignal-go/protocol/session"
)

// Bob creates a session with Alice and receives a message.
// Error handing is ignored in this example, but should otherwise not be ignored.
func main() {
keyPair, _ := identity.GenerateKeyPair(rand.Reader)
registrationID := uint32(1)
aliceAddress := address.Address{
Name: "+15555555556",
DeviceID: 1,
}

// Bob creates a session to talk to Alice.
bobSession := &session.Session{
RemoteAddress: aliceAddress,
SessionStore: session.NewInMemStore(),
IdentityKeyStore: identity.NewInMemStore(keyPair, registrationID),
}

var ciphertext []byte
// Bob receives Alice's message and stores it in ciphertext.

plaintext, _ := bobSession.DecryptMessage(context.Background(), rand.Reader, ciphertext)

// Alice sends her encrypted message to Bob.
}
```

#### Group Session

```go

```

## Roadmap

* Add and refactor tests
* Implement other APIs available in the source repository.
1. Implement post-quantum cryptography support.
1. Implement sealed sender support.
1. Add and refactor tests.
1. Implement other APIs available in the source repository.

0 comments on commit 2187e0c

Please sign in to comment.