Перейти к содержанию

SignerClient

SignerClient

class SignerClient(val url: String, val auth: AuthorizationSession, crypto: Crypto, timeout: UInt?, val transport: SSETransportDriver = SSETransportDriver( url, auth )) : SpatiumProtocol

Pre-configured Protocol intended for communication with Spatium Signer Service

  • For transport it uses HTTP(S) + SSE bidirectional transport.
  • For cache it uses an in-memory storage
  • For crypto driver it uses any provided Crypto

As it uses SSETransportDriver internally, one should also keep in mind that client starts listening as soon as connect(timeout =) is called and does not stop untill disconnect() is called.

  • SeeAlso = SpatiumSDKSwift/ProtocolKotlin

Parameters

androidJvm

url = signer service endpoint (HTTP(S))
auth = authorization AuthorizationSession session to use
crypto = any valid Crypto to hadle data and computations
timeout = UInt? per-message request timeout, after which a procedure is dropped

Note requests are attributed to accountId of an authorization session, thus storing data independently for each authorized user

Example

 // Assuming an already initialised Crypto
val auth = AuthorizationSession(
    url = "https://api-cloud-dev.spatium.io/authorization/v1",
    tokenId = UUID.randomUUID().toString(),
    permissions = listOf("read", "secret")
)

val clientCache = MemoryStorageDriver()
val clientStorage = MemoryStorageDriver()

val clientCrypto = SpatiumCrypto(cache = clientCache, storage = clientStorage)

val clientProtocol = SignerClient(
    url = "https://api-cloud-dev.spatium.io/signer/v1",
    auth = auth,
    crypto = clientCrypto,
    timeout = (60 * 1000).toUInt()
)

// Connect to signer service (with 10 sec timeout) 
clientProtocol.connect((60 * 1000).toUInt())

// Generate random secret ID for a new secret (should be done exactly once and kept) 
val secretId = UUID.randomUUID().toString()

// Generate both secerts (first on a connected server, and then locally) (should be done once per secret ID) 
clientProtocol.generateDistributedSecret(secretId = secretId)

// Generate random session ID for a new synchronisation session 
val syncSessionId = UUID.randomUUID().toString()

// Perform a ECDSA-over-secp256k1 synchronisation procedure for a key with path m/44'/0'/0'/0'/0'`
val publicKey = syncDistributedEcdsaKey(
    driver = clientProtocol,
    secretId = secretId,
    syncSessionId = syncSessionId,
    curve = EcdsaCurve.secp256k1,
    derivationCoin = 0U,
    derivationAccount = 0U
)

// At this point synchronisation data is saved to the storage so one may access it to get a compound public key 
val _publicKey = getEcdsaPublicKey(
    driver = clientProtocol,
    secretId = secretId,
    syncSessionId = syncSessionId
)

// Which is obviously the same key that was returned from the synchronisation procedure itself 
assertEquals(publicKey, _publicKey)

// Generate random session ID for a new signing session 
val signSessionId = UUID.randomUUID().toString()

// Message to be signed 
val message = "7hJ9yN2OdIQo2kJu0arZgw2EKnMX5FGtQ6jlCWuLXCM="

// Generate a ECDSA signature 
val signature = signEcdsaMessage(
    driver = clientProtocol,
    secretId = secretId,
    syncSessionId = syncSessionId,
    signSessionId = signSessionId,
    message = message
)

// Verify the resulting signature against a compound public key 
print(
    mapOf(
        "curve" to EddsaCurve.ed25519,
        "publicKey" to publicKey,
        "message" to message,
        "signature" to mapOf("R" to signature.r, "s" to signature.s) as Map<String, Any>
    ) as Map<String, Any>
)

Constructors

SignerClient [androidJvm]
constructor(url: String, auth: AuthorizationSession, crypto: Crypto, timeout: UInt?, transport: SSETransportDriver = SSETransportDriver( url, auth ))

Properties

Name Summary
auth [androidJvm]
val auth: AuthorizationSession
crypto [androidJvm]
val crypto: Crypto
timeout [androidJvm]
val timeout: UInt?
transport [androidJvm]
open override val transport: SSETransportDriver
url [androidJvm]
val url: String

Functions

Name Summary
connect [androidJvm]
suspend fun connect(timeout: UInt?)
Connect and start listening to events
disconnect [androidJvm]
fun disconnect()
Stop listening for messages and disconnect
generateDistributedSecret [androidJvm]
suspend fun generateDistributedSecret(secretId: String)
Simltaneous genteration of a distributed secret with the same secret ID