Skip to content

Add public sign() method to Sphere for message signing #30

@jvsteiner

Description

@jvsteiner

Problem

There is no public API to sign arbitrary data using the wallet's identity key. The sphere.identity getter deliberately strips privateKey from the returned object, and the underlying _identity field is TypeScript-private.

Applications that need to prove identity (e.g. authenticating HTTP requests to a service) are forced to bypass access control:

const fullIdentity = (sphere as any)._identity;
const privateKey = fullIdentity.privateKey;

They must then bring in @noble/curves/secp256k1 and @noble/hashes as separate dependencies and reimplement signing from scratch — even though the SDK already depends on these libraries internally.

Context

We built two marketplace applications on top of sphere-sdk (a prediction market and a P2P marketplace). Both needed to authenticate HTTP requests using the wallet's secp256k1 keypair. Both independently implemented identical signing code (~30 lines each) that:

  1. Accesses (sphere as any)._identity.privateKey
  2. Hashes a payload with SHA256 (from @noble/hashes)
  3. Signs with secp256k1 (from @noble/curves)
  4. Returns the signature + compressed public key

The SDK has SigningService internally for on-chain state transitions, but it's not exposed for general-purpose signing. The SDK also already exposes deriveAddress() which returns private keys, and exportToJSON() which dumps the master key — so there's no philosophical objection to key access, just a missing convenience method.

Proposed Solution

Add a public method to Sphere:

sphere.sign(message: Uint8Array): { signature: Uint8Array, publicKey: Uint8Array }

Or with hex convenience:

sphere.signMessage(payload: string): { signature: string, publicKey: string }

This would:

  • Eliminate the (sphere as any)._identity hack in every consumer
  • Remove the need for consumers to directly depend on @noble/curves and @noble/hashes
  • Provide a safe, supported way to prove wallet ownership without exposing raw private keys

Alternatives

  • Expose sphere.getPrivateKey(): string — simpler but less safe, pushes signing responsibility to consumers
  • Document the _identity access pattern — legitimizes the hack but doesn't solve the dependency duplication

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions