Comment on page
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.
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.
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".
This command will return the
SignHashResponse
or SignHashesResponse
(click to see more) object in response.Swift
Kotlin
Java
JS (React Native)
JS (Cordova)
Dart
JSON-RPC
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)
}
}
val hash = Random.nextBytes(ByteArray(32)) // Random data
val walletPublicKey = card.wallets.first().publicKey //Sign with the first wallet
val cardId = card.cardId
tangemSdk.sign(
hash: hash,
walletPublicKey = walletPublicKey,
cardId = cardId
) { result ->
when (result) {
is CompletionResult.Success -> {
runOnUiThread {
Log.d(TAG, result.signature)
}
}
is CompletionResult.Failure -> {
runOnUiThread {
Log.d(TAG, result.error)
}
}
}
}
byte[] hash = new byte[32];
new Random().nextBytes(hash);
byte[] walletPublicKey = card.getWallets().get(0).getPublicKey();
String cardId = card.getCardId();
tangemSdk.sign(hash, walletPublicKey, cardId, null, null, result -> {
if (result instanceof CompletionResult.Success) {
SignHashResponse response = ((CompletionResult.Success<SignHashResponse>) result).getData();
Log.d(TAG, Arrays.toString(response.getSignature()));
} else if (result instanceof CompletionResult.Failure) {
TangemError error = ((CompletionResult.Failure<SignHashResponse>) result).getError();
Log.d(TAG, error.getCustomMessage());
}
return Unit.INSTANCE;
});
// Request
{
"jsonrpc":"2.0",
"method":"sign_hash",
"params":{
"walletPublicKey":"5130869115a2ff91959774c99d4dc2873f0c41af3e0bb23d027ab16d39de1348",
"hash":"f1642bb080e1f320924dde7238c1c5f8"
},
"id":1
}
// Response
{
"jsonrpc":"2.0",
"result":{
"cardId":"c000111122223333",
"signature":"eb7411c2b7d871c06dad51e58e44746583ad134f4e214e4899f2fc84802232a1",
"totalSignedHashes":2
},
"id":1
}
Swift
Kotlin
Java
JS (React Native)
JS (Cordova)
Dart
JSON-RPC
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)
}
}
val hash1 = Random.nextBytes(ByteArray(32))
val hash2 = Random.nextBytes(ByteArray(32))
val hashes = arrayOf(hash1, hash2)
val walletPublicKey = card.wallets.first().publicKey //Sign with the first wallet
val cardId = card.cardId
tangemSdk.sign(
hashes: hashes,
walletPublicKey = walletPublicKey,
cardId = cardId
) { result ->
when (result) {
is CompletionResult.Success -> {
runOnUiThread {
Log.d(TAG, result.signature)
}
}
is CompletionResult.Failure -> {
runOnUiThread {
Log.d(TAG, result.error)
}
}
}
}
byte[] hash1 = new byte[32];
byte[] hash2 = new byte[32];
new Random().nextBytes(hash1);
new Random().nextBytes(hash2);
byte[][] hashes = new byte[2][32];
hashes[0] = hash1;
hashes[1] = hash2;
byte[] walletPublicKey = card.getWallets().get(0).getPublicKey();
String cardId = card.getCardId();
tangemSdk.sign(hashes, walletPublicKey, cardId, null, null, result -> {
if (result instanceof CompletionResult.Success) {
SignResponse response = ((CompletionResult.Success<SignResponse>) result).getData();
Log.d(TAG, Arrays.toString(response.getSignatures().get(0)));
Log.d(TAG, Arrays.toString(response.getSignatures().get(1)));
} else if (result instanceof CompletionResult.Failure) {
TangemError error = ((CompletionResult.Failure<SignResponse>) result).getError();
Log.d(TAG, error.getCustomMessage());
}
return Unit.INSTANCE;
});
const hashes = [
'44617461207573656420666f722068617368696e67',
'4461746120666f7220757365642068617368696e67',
];
const walletPublicKey = card.wallets[0].publicKey;
const hdPath = undefined
const cardId = card.id;
TangemSdk.sign(hashes, walletPublicKey, hdPath, cardId)
.then((result) => console.log(result))
.catch((err) => console.log(err));
var hashes = [
'44617461207573656420666f722068617368696e67',
'4461746120666f7220757365642068617368696e67',
];
var hdPath = undefined;
var cardId = card.cardId;
var initialMessage = {"body": "body", "header": "header"};
var callback = function (response, error) {
if (error) {
alert({ "error": error });
} else {
alert({"response": response});
}
};
TangemSdk.sign(hashes, walletPublicKey, hdPath, cardId, initialMessage, callback);
// Request
{
"jsonrpc":"2.0",
"result":{
"cardId":"c000111122223333",
"signature":"eb7411c2b7d871c06dad51e58e44746583ad134f4e214e4899f2fc84802232a1",
"totalSignedHashes":2
},
"id":1
}
// Response
{
"jsonrpc":"2.0",
"result":{
"cardId":"c000111122223333",
"signatures":[
"eb7411c2b7d871c06dad51e58e44746583ad134f4e214e4899f2fc84802232a1",
"33443bd93f350b62a90a0c23d30c6d4e9bb164606e809ccace60cf0e2591e58c"
],
"totalSignedHashes":2
},
"id":1
}
Last modified 2yr ago