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

syncDistributedEcdsaKey

syncDistributedEcdsaKey(driver:secretId:syncSessionId:curve:derivationCoin:derivationAccount:)

public func syncDistributedEcdsaKey(driver: ProtocolSwift, secretId: String, syncSessionId: String, curve: EcdsaCurve, derivationCoin: UInt32, derivationAccount: UInt32) async throws -> String

Perform distributed key synchronisation procedure

Each secret is independently used to generate distributed key fragments (BIP-44 with path m/44'/(coin)'/(account)'/0'/0'), and then MPC key synchronisation is performed over these fragments in order to get a compound public key for that pair.

Despite each session is bearing a unique set of data, the resulting key is deterministic in regards to further synchronisations, e.g. each set of secrets, coin and account always result in the same compound public key (and ephemeral private keys).

As a result of this operation, a new synchronisation session data is saved to a persistent storage, accessible by the provided session ID. From this point one may freely call getEcdsaPublicKey(driver:secretId:syncSessionId:) or signEcdsaMessage(driver:secretId:syncSessionId:signSessionId:message:) as long as synchronisation data (and secret) is accessible in the storage.

  • SeeAlso: ProtocolSwift/syncDistributedEcdsaKey(secretId:syncSessionId:curve:derivationCoin:derivationAccount:)

Example

 // Assume an already generated secret and established connection

 // Generate random session ID for a new synchronisation session
 let syncSessionId = UUID().uuidString

 // Perform a ECDSA-over-secp256k1 synchronisation procedure for a key with path `m/44'/0'/0'/0'/0'
 let publicKey = await syncDistributedEcdsaKey(secretId: String, syncSessionId: String, curve: EcdsaCurve, derivationCoin: UInt32, derivationAccount: UInt32)

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

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

Parameters

Name Description
driver ProtocolSwift implementation
secretId ID (UUID) of a secret to be used for synchronisation
syncSessionId ID (UUID) of this synchronisation procedure
curve elliptic curve to use (only .secp256k1 is supported at the moment)
derivationCoin “coin” property of HD key derivation (BIP-44)
derivationAccount “account” property of HD key derivation (BIP-44)

Returns

String

compound public key (which may also be accessed via getEcdsaPublicKey(driver:secretId:syncSessionId:) later)