Skip to main content

Messages and intents

Beyond transaction witnesses, the bindings expose two signature flavors with distinct verification rules: spending signatures (verified against a public key) and challenge signatures (verified against an address). Transaction intents build on challenge signatures.

Spending signatures​

signMessageForSpending(privateKey, message) signs an arbitrary message with a plain private key; verifySignatureForSpending(publicKey, signature, message) checks it against the matching public key. This is the flavor used by transaction witnesses.

import MintlayerWalletBindings

let message = Data("withdraw:123".utf8)
let signature = try signMessageForSpending(privateKey: key, message: message)
let ok = try verifySignatureForSpending(
publicKey: publicKeyFromPrivateKey(privateKey: key),
signature: signature,
message: message)

Challenges​

signChallenge(privateKey, message) produces a signature that verifyChallenge checks against a bech32 address rather than a raw public key — useful when the verifier only knows the address (for example, proving control of a wallet address to a backend).

Transaction intents​

A transaction intent is an on-chain record that the signers of specific inputs approve of a given message. The flow:

  1. Build the message to sign: makeTransactionIntentMessageToSign(intent, transactionId) — intent is an arbitrary string, transactionId the hex id of the transaction that carries the intent.
  2. Sign that message once per input destination with signChallenge.
  3. Assemble: encodeSignedTransactionIntent(signedMessage, signatures) — one challenge signature per input, in input order.
  4. Verify: verifyTransactionIntent(expectedSignedMessage, encodedSignedIntent, inputDestinations, network).
import org.mintlayer.wallet.bindings.makeTransactionIntentMessageToSign
import org.mintlayer.wallet.bindings.signChallenge
import org.mintlayer.wallet.bindings.encodeSignedTransactionIntent

val message = makeTransactionIntentMessageToSign(intent, txIdHex)
val signatures = listOf(signChallenge(inputKey0, message)) // one per input destination
val signedIntent = encodeSignedTransactionIntent(message, signatures)

Signing a transaction intent in one call​

signTransactionIntent(intent, signedTransaction, privateKeys, inputDestinations, network) collapses the flow above into a single call. It computes the transaction id from the signed transaction, builds the same message makeTransactionIntentMessageToSign produces, signs it once per private key — one challenge signature per input, in input order — encodes the signed intent, and verifies it against inputDestinations before returning. A failed verification raises an error; there is no boolean variant of the flow.

The returned bytes are exactly what the M2E bridge API accepts as deposit_transactions[].intent, byte-identical to the WASM reference for the same inputs — the convenience composes the intent steps the WASM differential suite pins, and the composition itself is covered by round-trip, tamper and count-mismatch unit tests in the bindings crate. Lower-level flows can still run message, sign + encode and verify separately; the outputs are interchangeable.

privateKeys and inputDestinations line up with the transaction inputs: privateKeys[i] is the plain private-key blob that signs input i (what makeReceivingAddress/makeChangeAddress return), and inputDestinations[i] is that input's bech32 destination. A different number of keys than destinations raises IntentKeyDestinationCountMismatch (carrying both counts); a non-UTF-8 intent raises IntentMessageNotUtf8.

The typical M2E bridge deposit: build and sign the transaction, derive one receiving key per input, call the convenience, and attach the returned bytes to the deposit request.

import org.mintlayer.wallet.bindings.Network
import org.mintlayer.wallet.bindings.makeReceivingAddress
import org.mintlayer.wallet.bindings.publicKeyFromPrivateKey
import org.mintlayer.wallet.bindings.pubkeyToPubkeyhashAddress
import org.mintlayer.wallet.bindings.signTransactionIntent

// one signing key and one destination per transaction input, in input order
val key0 = makeReceivingAddress(account, 0u)
val key1 = makeReceivingAddress(account, 1u)
val destination0 = pubkeyToPubkeyhashAddress(publicKeyFromPrivateKey(key0), Network.TESTNET)
val destination1 = pubkeyToPubkeyhashAddress(publicKeyFromPrivateKey(key1), Network.TESTNET)

val encodedIntent = signTransactionIntent(
"m2e deposit #42", // free-text intent
signedTransaction, // the signed transaction blob
listOf(key0, key1),
listOf(destination0, destination1),
Network.TESTNET,
)
// attach encodedIntent to deposit_transactions[].intent of the bridge deposit request
import MintlayerWalletBindings

// one signing key and one destination per transaction input, in input order
let key0 = try makeReceivingAddress(accountPrivkey: account, keyIndex: 0)
let key1 = try makeReceivingAddress(accountPrivkey: account, keyIndex: 1)
let destination0 = try pubkeyToPubkeyhashAddress(
publicKey: publicKeyFromPrivateKey(privateKey: key0), network: .testnet)
let destination1 = try pubkeyToPubkeyhashAddress(
publicKey: publicKeyFromPrivateKey(privateKey: key1), network: .testnet)

let encodedIntent = try signTransactionIntent(
intent: "m2e deposit #42", // free-text intent
signedTransaction: signedTransaction, // the signed transaction blob
privateKeys: [key0, key1],
inputDestinations: [destination0, destination1],
network: .testnet)
// attach encodedIntent to deposit_transactions[].intent of the bridge deposit request

Multisig destinations​

encodeDestination(address, network) turns a bech32 address into a destination blob; encodeMultisigChallenge and multisigChallengeToAddress build and inspect multisig challenges (a signature-count threshold plus public keys). These are the building blocks for multisig destinations in outputs and witnesses.