Sign data

Sign hashes or any data with wallet's private key.

Signs data with a wallet private key. The card receives a transaction hash and signs it. The resulting signature is relayed to the blockchain along with the transaction. It proves that the user is authorized to dispose of assets stored on the address associated with the walet’s public key.

For the simplicity we created two methods if you want to sign one or several hashes. Method for one hash will return response with one signature, for many – many.

Request parameters

hash[es] <Sring> or array of <String> One or several hashes of the data to be signed by the card.

walletPublicKey <Data> The wallet's public key. Since a Tangem card can contain more than one wallet, you need to specify the wallet's public key that you want to use to sign the data.

cardId <String> CID, Unique Tangem card ID number.

hdPath <DerivationPath> [optional] Derivation path of the wallet. COS v. 4.28 and higher.

initialMessage <Message> [optional] This message will be shown in the NFC session dialog. Default: "Tap the card to your phone exactly as it shown above".

Response

This command will return the SignHashResponse or SignHashesResponse (click to see more) object in response.

Example (sign one hash)

let hash = Data(repeating: 0x1, count: 32) // Test data
let walletPublicKey = card.wallets[0].publicKey //Sign with the first wallet
let cardId = card.cardId

tangemSdk.sign(hash: hash,
               walletPublicKey: walletPublicKey,
               cardId: cardId) { result in
    switch result {
    case .success(let response):
        let signature = response.signature
        print(signature)
    case .failure(let error):
        print(error)
    }
}

Example (sign many hashes at once)

let hash1 = Data(repeating: 0x0, count: 32)
let hash2 = Data(repeating: 0x1, count: 32)
let walletPublicKey = card.wallets[0].publicKey //Sign with the first wallet
let cardId = card.cardId

tangemSdk.sign(hashes: [hash1, hash2],
               walletPublicKey: walletPublicKey,
               cardId: cardId) { result in
    switch result {
    case .success(let response):
        let signature1 = response.signatures[0]
        let signature2 = response.signatures[1]
        print(signature1)
        print(signature2)
    case .failure(let error):
        print(error)
    }
}

Last updated