feat(phone-psi): bind blinded E.164 phone tokens to DIDs and resolve phone contacts in POST /v1/contacts/psi

Open
#12 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
api, backend

Research direction

Start with handle_psi_json in src/psi_service.rs, then the identity and contacts routes in src/http_server.rs, to see how NodeState stores DIDs and how evaluate_psi_batch is called. Run tests/milestone10_node_test.rs to see the current contract. Done means a registered phone token resolves to its DID through /v1/contacts/psi and the by-phone lookup, and the existing evaluated_tokens field still returns. The issue names both matched_dids and matches for the response, so settle that with a maintainer first.

Written by the indexing model from the issue text.

Description

area::node effort::m impact::critical priority::critical source::auto status::review type::feature

Description

In sonaraim-node/src/psi_service.rs:77-90 and src/http_server.rs:199-235, POST /v1/identity registers a did and key_commitment, while POST /v1/contacts/psi evaluates blinded_tokens, but sonaraim-node does not store a mapping from phone_token (blinded E.164 phone number, e.g. +51999888777) to the user's did:sonaraim:.... Because of this, users and businesses cannot resolve an E.164 phone number to an active Sonaraim DID mailbox like WhatsApp does.

Affected Files

  • src/psi_service.rs:29-90
  • src/http_server.rs:198-235

Evidence (Current Code Snippet)

// src/psi_service.rs:78-89
pub fn handle_psi_json(body: &str, secret: &[u8]) -> (u16, &'static str, String) {
    let tokens = extract_json_str_array(body, "blinded_tokens");
    let quoted: Vec<String> = evaluate_psi_batch(&tokens, secret)
        .into_iter()
        .map(|t| format!(""{t}""))
        .collect();
    (
        200,
        "OK",
        format!("{{"evaluated_tokens":[{}]}}", quoted.join(",")),
    )
}

Impact & Historical Context

  • Impact: For Sonaraim to work like WhatsApp connected to a phone number, registering a phone number (phone_e164 or phone_token) alongside POST /v1/identity must index the blind-evaluated phone token so POST /v1/contacts/psi returns both evaluated_tokens and matched_dids: [{"token": "...", "did": "did:sonaraim:..."}].
  • Historical Context: Parent Meta-Issue alfonsodg/sonaraim#15. Extends alfonsodg/sonaraim-node#5.

Proposed Solution

  1. Allow POST /v1/identity to accept an optional "phone_token" (or "phone_e164"), computing its blind PSI evaluation and indexing evaluated_token -> did in NodeState.
  2. In POST /v1/contacts/psi, return "evaluated_tokens": [...] AND "matches": [{"blinded_token": "...", "evaluated_token": "...", "did": "did:sonaraim:..."}] for all registered phone numbers.
  3. Also allow GET /v1/identity/by-phone/<phone_token> so sonaraim-b2b and sonaraim-app can check whether an E.164 phone number is onboarded on Sonaraim and route directly to its did:sonaraim:... mailbox.

Acceptance Criteria

  • Functional: Registering an identity with a phone number binds its PSI token to the DID; POST /v1/contacts/psi and GET /v1/identity/by-phone/<token> resolve the phone token to the registered did:sonaraim:....
  • Code Quality: All files in src/ strictly < 300 lines; cargo fmt --check and cargo clippy -- -D warnings pass.
  • Tests: TDD tests in tests/milestone10_node_test.rs verify phone registration and contact book discovery returning the matched did:sonaraim:....
  • Regression: Existing evaluated_tokens response field is preserved for backward compatibility.
Dominant language
Rust
Stars
0
Forks
0
Avg merge
4m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from alfonsodg/sonaraim-node

All issues in alfonsodg/sonaraim-node

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.