Cryptography
Multi-Signature Transactions

Multi-Signature Transactions

The Sui TypeScript SDK provides a MultiSigPublicKey class to support Multi-Signature (opens in a new tab) (MultiSig) transaction and personal message signing.

This class implements the same interface as the PublicKey classes that Keypairs uses and you call the same methods to verify signatures for PersonalMessages and TransactionBlocks.

Creating a MultiSigPublicKey

To create a MultiSigPublicKey, you provide a threshold(u16) value and an array of objects that contain publicKey and weight(u8) values. If the combined weight of valid signatures for a transaction is equal to or greater than the threshold value, then the Sui network considers the transdaction valid.

import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import { MultiSigPublicKey } from '@mysten/sui.js/multisig';
 
const kp1 = new Ed25519Keypair();
const kp2 = new Ed25519Keypair();
const kp3 = new Ed25519Keypair();
 
const multiSigPublicKey = MultiSigPublicKey.fromPublicKeys({
	threshold: 2,
	publicKeys: [
		{
			publicKey: kp1.getPublicKey(),
			weight: 1,
		},
		{
			publicKey: kp2.getPublicKey(),
			weight: 1,
		},
		{
			publicKey: kp3.getPublicKey(),
			weight: 2,
		},
	],
});
 
const multisigAddress = multiSigPublicKey.toSuiAddress();

The multiSigPublicKey in the preceding code enables you to verify that signatures have a combined weight of at least 2. A signature signed with only kp1 or kp2 is not valid, but a signature signed with both kp1 and kp2, or just kp3 is valid.

Combining signatures with a MultiSigPublicKey

To sign a message or transaction for a MultiSig address, you must collect signatures from the individual key pairs, and then combine them into a signature using the MultiSigPublicKey class for the address.

// This example uses the same imports, key pairs, and multiSigPublicKey from the previous example
const message = new TextEncoder().encode('hello world');
 
const signature1 = (await kp1.signPersonalMessage(message)).signature;
const signature2 = (await kp2.signPersonalMessage(message)).signature;
 
const combinedSignature = multiSigPublicKey.combinePartialSignatures([signature1, signature2]);
 
const isValid = await multiSigPublicKey.verifyPersonalMessage(message, combinedSignature);