### Deployment Script Usage (Bash) Source: https://context7.com/mystenlabs/multisig-move/llms.txt This shows how to execute the 'publish.sh' script to deploy multisig contracts to different Sui networks (localnet, devnet, testnet, mainnet). ```bash # Usage: # ./publish.sh # Deploy to localnet # ./publish.sh devnet # Deploy to devnet # ./publish.sh testnet # Deploy to testnet # ./publish.sh mainnet # Deploy to mainnet ``` -------------------------------- ### TypeScript SDK: Create Multisig Addresses On-Chain Source: https://context7.com/mystenlabs/multisig-move/llms.txt Demonstrates how to use the Sui TypeScript SDK to interact with the deployed multisig contract and create multisig addresses on-chain. It involves preparing a transaction block, defining public keys, and executing the transaction. ```typescript import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; import { SuiClient } from "@mysten/sui.js/client"; import * as dotenv from "dotenv"; // Initialize environment and client dotenv.config({ path: "../.env" }); const phrase = process.env.ADMIN_PHRASE; const keypair = Ed25519Keypair.deriveKeypair(phrase!); const client = new SuiClient({ url: process.env.FULLNODE!, }); const packageId = process.env.PACKAGE_ID; const moduleName = "multisig"; // Prepare transaction block let transactionBlock = new TransactionBlock(); // Define three public keys (Ed25519, Secp256k1, Secp256r1) const key1 = [ 0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117, ]; const key2 = [ 1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43, ]; const key3 = [ 2, 3, 71, 251, 175, 35, 240, 56, 171, 196, 195, 8, 162, 113, 17, 122, 42, 76, 255, 174, 221, 188, 95, 248, 28, 117, 23, 188, 108, 116, 167, 237, 180, 48, ]; // Call the multisig contract to create/derive a multisig address transactionBlock.moveCall({ target: `${packageId}::${moduleName}::create_multisig_address`, arguments: [ transactionBlock.pure([key1, key2, key3], "vector>"), transactionBlock.pure([1, 1, 1], "vector"), transactionBlock.pure(2), // 2-of-3 threshold ], }); // Execute transaction try { const result = await client.signAndExecuteTransactionBlock({ transactionBlock: transactionBlock, signer: keypair, }); // Result includes transaction effects and emitted events // MultisigAddressEvent contains the derived address and configuration console.log("Transaction succeeded:", result.digest); } catch (e) { console.error("Transaction failed:", e); } ``` -------------------------------- ### Bash Script: Deploy Multisig Smart Contract to Sui Source: https://context7.com/mystenlabs/multisig-move/llms.txt A bash script to deploy the multisig smart contract to Sui networks (localnet, devnet, testnet, mainnet). It handles dependency checks, network configuration, key import, and publishing the Move package. ```bash #!/bin/bash # Validate dependencies for i in jq curl sui; do if ! command -V ${i} 2>/dev/null; then echo "${i} is not installed" exit 1 fi done # Configure network (default: localnet) NETWORK=http://localhost:9000 if [ $# -ne 0 ]; then case $1 in devnet) NETWORK="https://fullnode.devnet.sui.io:443";; testnet) NETWORK="https://fullnode.testnet.sui.io:443";; mainnet) NETWORK="https://fullnode.mainnet.sui.io:443";; esac fi echo "- Admin Address is: ${ADMIN_ADDRESS}" # Import admin keypair and switch to it import_address=$(sui keytool import "$ADMIN_PHRASE" ed25519) switch_res=$(sui client switch --address ${ADMIN_ADDRESS}) ACTIVE_ADMIN_ADDRESS=$(sui client active-address) echo "Admin address used for publishing: ${ACTIVE_ADMIN_ADDRESS}" ACTIVE_NETWORK=$(sui client active-env) echo "Environment used is: ${ACTIVE_NETWORK}" # Publish the Move package publish_res=$(sui client publish --gas-budget 2000000000 --json ../move/) echo ${publish_res} >.publish.res.json # Check for errors if [[ "$publish_res" =~ "error" ]]; then echo "Error during move contract publishing. Details: $publish_res" exit 1 fi ``` -------------------------------- ### Verify Multisig Address Equality (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Verifies if a given address matches the multisig address derived from public keys, weights, and a threshold. Useful for validating address creation with specific multisig parameters. Requires the 'multisig' module. ```move use multisig::multisig::{Self as ms}; let pks: vector> = vector[ vector[0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117], vector[1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43] ]; let weights: vector = vector[1, 2]; let threshold: u16 = 2; let expected: address = @0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef; // Check if the derived address matches the expected address let is_match: bool = ms::check_multisig_address_eq(pks, weights, threshold, expected); // Returns: true if derived address matches expected, false otherwise // Use case: Verify an address was created with specific multisig configuration ``` -------------------------------- ### Generate .env File for TypeScript Client (Bash) Source: https://context7.com/mystenlabs/multisig-move/llms.txt This script generates a '.env' file for the TypeScript client by concatenating environment variables. It's used after deploying multisig contracts to configure the client with network details and contract addresses. ```bash cat >../multisig/.env<<-ENV FULLNODE=$NETWORK ADMIN_PHRASE=$ADMIN_PHRASE PACKAGE_ID=$PACKAGE_ID UPGRADE_CAP_ID=$UPGRADE_CAP_ID ADMIN_ADDRESS=$ACTIVE_ADMIN_ADDRESS ACTIVE_NETWORK=$ACTIVE_NETWORK ENV ``` -------------------------------- ### Derive Multisig Addresses with Different Key Types in Move Source: https://github.com/mystenlabs/multisig-move/blob/main/README.md This snippet demonstrates how to derive multisig addresses using the multisig module. It showcases the conversion of public keys for ED25519, Secp256k1, and Secp256r1 into addresses. It then derives a multisig address based on a set of public keys, weights, and a threshold. ```move #[test_only] module multisig::multisig_unit_tests { use multisig::multisig::{Self as ms}; #[test] fun test_derive_multisig_address() { // ED25519 let address_ED25519: address = @0x73a6b3c33e2d63383de5c6786cbaca231ff789f4c853af6d54cb883d8780adc0; let key_ED25519: vector = vector[0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117]; assert!(ms::ed25519_key_to_address(&key_ED25519) == address_ED25519, 0); // Secp256k1 let address_Secp256k1: address = @0xd9607cd03428c904949572b51471e7a9f60019aeb9a3d7ee5e72921cab8e8be7; let key_Secp256k1: vector = vector[1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43]; assert!(ms::secp256k1_key_to_address(&key_Secp256k1) == address_Secp256k1, 0); // Secp256r1 let address_Secp256r1: address = @0x600b1081644fe46f76da3bdc19f8743b9f04458516364374c7d82959e790c19e; let key_Secp256r1: vector = vector[2, 3, 71, 251, 175, 35, 240, 56, 171, 196, 195, 8, 162, 113, 17, 122, 42, 76, 255, 174, 221, 188, 95, 248, 28, 117, 23, 188, 108, 116, 167, 237, 180, 48]; assert!(ms::secp256r1_key_to_address(&key_Secp256r1) == address_Secp256r1, 0); let pks: vector> = vector[key_ED25519, key_Secp256k1, key_Secp256r1]; let weights: vector = vector[1, 1, 1]; let threshold: u16 = 2; let expected_multisig_address: address = @0x1c4dac7fb4c01a0c608db993711c451ad655a38b7f0a9571ff099f70090263a8; let derived_multisig_address: address = ms::derive_multisig_address(pks, weights, threshold); assert!(derived_multisig_address == expected_multisig_address, 0); } } ``` -------------------------------- ### Convert Secp256k1 Public Key to Address (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Converts a 34-byte Secp256k1 public key (with a 0x01 flag prefix) to its corresponding Sui address. Secp256k1 is commonly used in Bitcoin and Ethereum. Requires the 'multisig' module. ```move use multisig::multisig::{Self as ms}; // Secp256k1 public key (34 bytes: flag 0x01 + 33-byte compressed public key) let secp256k1_pk: vector = vector[ 1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43 ]; // Convert to address let addr: address = ms::secp256k1_key_to_address(&secp256k1_pk); // Expected: 0xd9607cd03428c904949572b51471e7a9f60019aeb9a3d7ee5e72921cab8e8be7 assert!(addr == @0xd9607cd03428c904949572b51471e7a9f60019aeb9a3d7ee5e72921cab8e8be7, 0); // Error cases: // - EPublicKeyLength (2): pk.length != 34 // - EPublicKeyFlag (3): pk[0] != 0x01 ``` -------------------------------- ### Test Multi-Sig Address Derivation Source: https://github.com/mystenlabs/multisig-move/blob/main/README.md A test function designed to validate the functionality of the multi-sig address derivation within a transaction context. This helps ensure the module operates correctly. ```move multisig::multisig::test_address(); ``` -------------------------------- ### Derive Multisig Address with Event Emission (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Derives a multisig address on Sui by combining public keys, weights, and a threshold. This function emits a MultisigAddressEvent for on-chain tracking. It requires the 'multisig' module and supports multiple signature schemes. Input parameters include vectors of public keys, weights, and a threshold value. The output is the derived multisig address. ```move use multisig::multisig::{Self as ms}; // Define the public keys for three different signature schemes let key_ED25519: vector = vector[ 0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117 ]; let key_Secp256k1: vector = vector[ 1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43 ]; let key_Secp256r1: vector = vector[ 2, 3, 71, 251, 175, 35, 240, 56, 171, 196, 195, 8, 162, 113, 17, 122, 42, 76, 255, 174, 221, 188, 95, 248, 28, 117, 23, 188, 108, 116, 167, 237, 180, 48 ]; // Combine keys into a vector, assign equal weights, and set threshold to 2 let pks: vector> = vector[key_ED25519, key_Secp256k1, key_Secp256r1]; let weights: vector = vector[1, 1, 1]; let threshold: u16 = 2; // Derive the multisig address (emits MultisigAddressEvent) let multisig_address: address = ms::derive_multisig_address(pks, weights, threshold); // Expected result: 0x1c4dac7fb4c01a0c608db993711c451ad655a38b7f0a9571ff099f70090263a8 assert!(multisig_address == @0x1c4dac7fb4c01a0c608db993711c451ad655a38b7f0a9571ff099f70090263a8, 0); ``` -------------------------------- ### Extract Package and Object IDs from Publish Results (Bash) Source: https://context7.com/mystenlabs/multisig-move/llms.txt This script extracts the package ID, publisher ID, and upgrade capability ID from the output of a Move contract publish operation using 'jq'. It assumes the publish result is stored in the 'publish_res' variable. ```bash PACKAGE_ID=$(echo "${publish_res}" | jq -r '.effects.created[] | select(.owner == "Immutable").reference.objectId') newObjs=$(echo "$publish_res" | jq -r '.objectChanges[] | select(.type == "created")') PUBLISHER_ID=$(echo "$newObjs" | jq -r 'select (.objectType | contains("package::Publisher")).objectId') UPGRADE_CAP_ID=$(echo "$newObjs" | jq -r 'select (.objectType | contains("package::UpgradeCap")).objectId') ``` -------------------------------- ### Derive Multi-Sig Sui Address Source: https://github.com/mystenlabs/multisig-move/blob/main/README.md Generates a Sui blockchain address from a set of public keys, their corresponding weights, and a threshold. This function is essential for creating multi-signature accounts on the Sui network. ```move let public_keys: vector> = ...; let weights: vector = ...; let threshold: u8 = ...; let multisig_address = multisig::multisig::derive_multisig_address(public_keys, weights, threshold); ``` -------------------------------- ### Create Sui Address from Public Key (Various Types) Source: https://github.com/mystenlabs/multisig-move/blob/main/README.md Functions to create a Sui blockchain address from different types of public keys, including Ed25519, Secp256k1, and Secp256r1. These are utility functions used in conjunction with multi-signature address derivation. ```move let ed25519_address = multisig::multisig::ed25519_key_to_address(public_key: vector); let secp256k1_address = multisig::multisig::secp256k1_key_to_address(public_key: vector); let secp256r1_address = multisig::multisig::secp256r1_key_to_address(public_key: vector); ``` -------------------------------- ### Derive Multisig Address Silently (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Derives a multisig address on Sui without generating on-chain events, suitable for verification. This function validates that public keys and weights have matching lengths and that the threshold is valid. It relies on the 'multisig' module and accepts vectors of public keys, weights, and a threshold. The output is the computed multisig address. ```move use multisig::multisig::{Self as ms}; // Create a 2-of-2 multisig with two keys let pk1: vector = vector[ 0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117 ]; let pk2: vector = vector[ 1, 2, 14, 23, 205, 89, 57, 228, 107, 25, 102, 65, 150, 140, 215, 89, 145, 11, 162, 87, 126, 39, 250, 115, 253, 227, 135, 109, 185, 190, 197, 188, 235, 43 ]; let pks: vector> = vector[pk1, pk2]; let weights: vector = vector[1, 1]; let threshold: u16 = 2; // Derive address without emitting events let ms_address: address = ms::derive_multisig_address_quiet(pks, weights, threshold); // Returns: Multisig address computed from BLAKE2b hash of serialized parameters // Error cases: // - ELengthsOfPksAndWeightsAreNotEqual (0): pks.length != weights.length // - EThresholdIsPositiveAndNotGreaterThanTheSumOfWeights (1): threshold == 0 or threshold > sum(weights) ``` -------------------------------- ### Convert Ed25519 Public Key to Address (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Converts a 33-byte Ed25519 public key (with a 0x00 flag prefix) to its corresponding Sui address. Ed25519 is a secure and efficient signature scheme. Requires the 'multisig' module. ```move use multisig::multisig::{Self as ms}; // Ed25519 public key (33 bytes: flag 0x00 + 32-byte public key) let ed25519_pk: vector = vector[ 0, 13, 125, 171, 53, 140, 141, 173, 170, 78, 250, 0, 73, 167, 91, 7, 67, 101, 85, 177, 10, 54, 130, 25, 187, 104, 15, 112, 87, 19, 73, 215, 117 ]; // Convert to address let addr: address = ms::ed25519_key_to_address(&ed25519_pk); // Expected: 0x73a6b3c33e2d63383de5c6786cbaca231ff789f4c853af6d54cb883d8780adc0 assert!(addr == @0x73a6b3c33e2d63383de5c6786cbaca231ff789f4c853af6d54cb883d8780adc0, 0); // Error cases: // - EPublicKeyLength (2): pk.length != 33 // - EPublicKeyFlag (3): pk[0] != 0x00 ``` -------------------------------- ### Move: Convert Secp256r1 Public Key to Sui Address Source: https://context7.com/mystenlabs/multisig-move/llms.txt Converts a 34-byte Secp256r1 public key (with 0x02 flag) to its corresponding Sui address using the multisig module. This function is essential for deriving on-chain addresses from Secp256r1 keys. ```move use multisig::multisig::{Self as ms}; // Secp256r1 public key (34 bytes: flag 0x02 + 33-byte compressed public key) let secp256r1_pk: vector = vector[ 2, 3, 71, 251, 175, 35, 240, 56, 171, 196, 195, 8, 162, 113, 17, 122, 42, 76, 255, 174, 221, 188, 95, 248, 28, 117, 23, 188, 108, 116, 167, 237, 180, 48 ]; // Convert to address let addr: address = ms::secp256r1_key_to_address(&secp256r1_pk); // Expected: 0x600b1081644fe46f76da3bdc19f8743b9f04458516364374c7d82959e790c19e assert!(addr == @0x600b1081644fe46f76da3bdc19f8743b9f04458516364374c7d82959e790c19e, 0); // Error cases: // - EPublicKeyLength (2): pk.length != 34 // - EPublicKeyFlag (3): pk[0] != 0x02 ``` -------------------------------- ### Check if Sender is Multisig Address (Move) Source: https://context7.com/mystenlabs/multisig-move/llms.txt Validates if the transaction sender is a multisig address conforming to the provided configuration (public keys, weights, threshold). Enables access control and threshold-based logic in smart contracts. Requires the 'multisig' module and TxContext. ```move use multisig::multisig::{Self as ms}; public entry fun restricted_function( pks: vector>, weights: vector, threshold: u16, ctx: &mut TxContext ) { // Verify the sender is a 2-of-3 multisig address let is_multisig = ms::check_if_sender_is_multisig_address(pks, weights, threshold, ctx); assert!(is_multisig, 100); // Error if sender is not the expected multisig // Implement threshold-based logic if (threshold >= 3) { // High security: allow transfer of up to 1000 coins // ... transfer logic ... } else if (threshold >= 2) { // Medium security: allow transfer of up to 500 coins // ... transfer logic ... }; // Returns: true if tx.sender matches derived multisig address, false otherwise ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.