24 Commits

Author SHA1 Message Date
osmaczko
5767997e0e
fix(nim-bindings): bridge Nim/C ABI mismatch via C shim layer
Nim's code generator transforms function signatures involving large structs
in two ways that conflict with the standard C ABI:

  - Return values of large structs (> register size): Nim emits a void
    function with an explicit out-pointer appended as the *last* argument.
    The standard x86-64 SysV ABI passes the hidden return pointer in RDI
    (before the real arguments); ARM64 aapcs64 uses X8. Calling Rust
    directly from Nim therefore puts the pointer in the wrong register /
    stack slot on both architectures, causing crashes.

  - Large struct parameters (> ~24 bytes): Nim passes a pointer rather
    than copying bytes on the stack / into registers as the C ABI expects.

This commit introduces a thin C shim (nim_shims.c) that acts as a
translation layer:

  - Each nim_* wrapper is declared with a Nim-compatible signature, so
    Nim calls it correctly by its own rules.
  - Inside the wrapper the C compiler calls the real Rust-exported
    function using the standard C ABI, inserting the correct hidden-
    pointer placement and stack-copy behaviour for the current platform.

As a result:
  - The Rust API stays standard C ABI (return T by value; destroy takes
    *mut T, which is pointer-sized and matches Nim's large-param transform).
  - Other language bindings (C, Swift, Go, …) call Rust directly without
    any shim — the standard ABI is preserved for them.
  - The fix is correct on both x86-64 and ARM64 without any
    architecture-specific code in Nim or Rust.

Changes:
  - nim-bindings/src/nim_shims.c: C bridge with nim_* wrappers for all
    create/handle/installation_name and destroy functions
  - nim-bindings/src/bindings.nim: {.compile: "nim_shims.c"}, proc
    signatures use natural return-by-value form, importc names point to
    the nim_* shims
  - nim-bindings/src/libchat.nim: call sites use natural let binding form;
    destroy calls pass addr res (ptr T)
  - conversations/src/api.rs: destroy functions take *mut T so Nim's
    large-param-to-pointer transform is satisfied without a stack copy
2026-02-24 12:43:28 +01:00
Jazz Turner-Baggs
960bb195a1
Update crate name (#59) 2026-02-22 08:24:10 +02:00
Jazz Turner-Baggs
eb941387df
Add Installation name (#58)
* Add Identity name

* Update Context to accept a name

* Change constructor in bindings

* Add name retrieval to bindings

* Update constructor string type

* Remove uneeded files

* rename functions for symmetry
2026-02-19 17:25:42 -08:00
osmaczko
a9ca4ffb7d
chore: expose isNewConvo property (#57) 2026-02-18 20:01:47 +01:00
Jazz Turner-Baggs
95ddce9161
Key types (#56)
* Add generic SymmetricKey container

* Rename SecretKey to SymmetricKey32

* Update SymmetricKey usage

* Add PublicKey

* Update PublicKey uses

* Add PrivateKey

* Replace StaticSecret with PrivateKey

* Fix imports

* Remove InstallKey from constructors

* Final integration

* lint fixes

* Fixups
2026-02-18 09:29:33 -08:00
Jazz Turner-Baggs
3b69f946fd
PrivateV1 Convo Ids (#54)
* Add conversation_ids for privateV1

* Skip handling of unknown payloads

* Tag initial ContentData as new

* Add Integration test

* truncate convo_id to size

* Clippy fixes

* cleanup

* Apply suggestion from @osmaczko

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>

* Apply suggestion from @osmaczko

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>

* Linter fixes

---------

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
2026-02-11 14:10:21 -08:00
osmaczko
57fe656728
feat: update introduction bundle encoding (#43)
closes: #27
2026-02-11 19:51:22 +01:00
Patryk Osmaczko
cd737ea058 fix: make ci checks pass 2026-02-10 19:45:00 +01:00
Jazz Turner-Baggs
71f7b8a485
FFI Integration fixes (#48)
* Make conversation store easier to use

* fix: Bug in Inbox id’s

* Clean up warnings

* Add DH decryption for Inbox
2026-02-09 09:55:58 -08:00
Jazz Turner-Baggs
e3e3097947
Safer FFI Migration (#47)
* Use safer_ffi for all functions

* Clean up FFI docs and imports

* Update nim bindings

* Binding Memory Management

* Update tests
2026-02-09 06:37:47 -08:00
Jazz Turner-Baggs
135347cdd0
Update Conversation handles over FFI (#46)
* Remove convo handles

* Remove convo_handle from docs
2026-02-06 08:58:23 -08:00
Jazz Turner-Baggs
1ce196e5ec
Implement handle_payload (#44)
* Implement handle_payload

* Cleanup handler for easier understanding

* Fixups
2026-02-06 08:41:12 -08:00
Jazz Turner-Baggs
97a1cf150a
Update content to use byte slice (#45) 2026-02-06 08:08:06 -08:00
Jazz Turner-Baggs
2a74066cd4
Remove unneeded traits and warnings (#42) 2026-02-06 07:24:13 -08:00
Jazz Turner-Baggs
d5c16f51de
Integrate DR into PrivateV1 (#32)
* Add crate

* Initialize session

* Add encrypt / decrypt
2026-02-03 15:17:45 -08:00
Jazz Turner-Baggs
5a98258ff1
Implement Content::send_content (#31)
* Implement Content::send_content

* rename stamp fn
2026-01-29 08:36:18 -08:00
Jazz Turner-Baggs
1f0354f8e2
Add FFI functions for send_content and handle_payload (#29)
* Add api calls for handle_payload and send_content

* Add handle_payload and send_content to FFI
2026-01-28 10:50:41 -08:00
Jazz Turner-Baggs
1cb1ffc996
Nim FFI Wrapper for LibChat (#25)
* remove unneeded code

* Update comment style

* Update Nim side to support safer_ffi

* Fix Introduction from impl

* Updates
2026-01-28 10:38:08 -08:00
Jazz Turner-Baggs
15bb395475
Rust API - conversation creation (#24)
* Adds final changes for rust side API

* Add Safer_ffi impl

* Simplify api

* Add const handle offset
2026-01-28 09:59:07 -08:00
Jazz Turner-Baggs
4b1069a4a8
Use PayloadData for outbound datatype (#23)
* Add Introductions (#22)

* Move to Payload data

* compute delivery_address
2026-01-27 16:17:04 -08:00
Jazz Turner-Baggs
d40e72be9b
Add Introductions (#22) 2026-01-26 08:53:44 -08:00
Jazz Turner-Baggs
fe23c39321
PrivateV1 Convo Initialization via Inbox (#13)
* Load orginal protofiles

* Change package name

* Add prost generation

* Remove placeholders

* Add generated files + imports

* replace with chat-proto

* Add XK0

* auto formatting

* Initial implementation of PrivateV1 initialization

* Add ConvoFactory trait

* Hook up indentity placeholder

* Remove RemoteInbox until it’s needed

* Simplify Identity ownership

* Clean up x3handshake

* Move inbox encryption

* Simplify inbox encryption

* Cleanup warnings

* Add todos

* Update chat-proto crate

* Publickey Handling

* Reorg Inbox handshake

* Update Inbox convoId

* Remove file structure headers

* Update ConvoID

* Add Domain Separator trait

* Remove Convo trait functions

* Rename Context

* Add SecretKey

* Add workspace dependency

* update KE name

* Update comments for clarity

* Remove Xk0 references

* Bump chat_proto version and relock
2026-01-21 15:39:09 -08:00
kaichao
fc76453f4c
Implement double ratchet (#9) 2026-01-15 08:47:02 +08:00
Jazz Turner-Baggs
04d6f8a84b
Add Project scaffolding (#1) 2025-12-22 09:40:46 -08:00