Multi-signature

1 Multi-signature operation steps

Step 1: Set up multi-signature.

Step 2: Disable the private key of a multi-signature account.

Step 3: Signers sign separately, then merge transaction signatures.

2 Code examples

1. Set up multi-signature, N users sign, the minimum number of BVC holdings, need to increase 5* (2 + N).
const API = require('bvcadt-crypto-core');

const address = "bPWAAXW73xt7n3b9L3JbN5a8ex3B7ucAhV";       // Multi-signature account
const secret = "sp**************************7";             // The private key of multi-sign account 

const user1Address = "b9iFbbNkMHruLB8gnzBfYLUUSc1zgMSnbf";  // Account of Signer 1
const user1Secret = "sh**************************T";        // Private key of signer 1
const user2Address = "bMGhReHMKoLP3VxoruRU9x3vVFqnddDRj4";  // Account of Signer 2
const user2Secret = "sn**************************V";        // Private key of signer 2
const signerListSetTxJson = {
    "Flags": 0,
    "TransactionType": "SignerListSet",
    "Account": address,
    "Fee": "10000",
    "Sequence": 1,
    "SignerQuorum": 2,              // Effective weight of multi-signature submission
    "SignerEntries": [
        {
            "SignerEntry": {
                "Account": user1Address,
                "SignerWeight": 1   // Weight of signer 1
            }
        },
        {
            "SignerEntry": {
                "Account": user2Address,
                "SignerWeight": 1   // Weight of signer 2
            }
        }
    ]
};
const setMSigned = API.sign(signerListSetTxJson, secret);
console.log("hash  : " + setMSigned.hash);
console.log("txBlob: " + setMSigned.signedTransaction + "\n");

// Submit through "submit" method of JSON-RPC API.
/*
{
    "method": "submit",
    "params": [
        {
            "tx_blob": txBlob
        }
    ]
}
 */
2. Disable the private key of a multi-signature account. If not, the account can be transferred either by multi-signing or by private key.
const accountSetTxJson = {
    "TransactionType": "AccountSet",
    "SetFlag": 4,           // Set Flag to 4 to disable the private key of an account
    "Account": address,
    "Sequence": 2,
    "Fee": "10000",
    "Flags": 2147483648
};

const accountSetSigned = API.sign(accountSetTxJson, secret);
console.log("hash  : " + accountSetSigned.hash);
console.log("txBlob: " + accountSetSigned.signedTransaction + "\n");

// Submit through "submit" method of JSON-RPC API.
/*
{
    "method": "submit",
    "params": [
        {
            "tx_blob": txBlob
        }
    ]
}
 */
3. Multi-Sign Transfer.
const mPaymentTxJson = {
    "TransactionType": "Payment",
    "Account": address,
    "Amount": "1000000",
    "Destination": "bwU3SrCq66oVQi2a2twnMdhJipiS1LXGAQ",
    "Sequence": 3,
    "Flags": 2147483648,
    "Fee": "" + (10000 * (1 + 2))     // The cost of multi-signature transaction is: basic cost * (1 + number of signers).
};

// Signer 1 sign
const signedFor1 = API.signFor(mPaymentTxJson, user1Secret, user1Address);
//console.log(JSON.stringify(signedFor1));

// Signer 2 sign
const signedFor2 = API.signFor(mPaymentTxJson, user2Secret, user2Address);
//console.log(JSON.stringify(signedFor2));

// Merger transaction signature.
mPaymentTxJson.SigningPubKey = '';
mPaymentTxJson.Signers = [];
mPaymentTxJson.Signers = mPaymentTxJson.Signers.concat(signedFor1.Signers);
mPaymentTxJson.Signers = mPaymentTxJson.Signers.concat(signedFor2.Signers);
//console.log(JSON.stringify(mTxJson));

// Submit merged transactions through "submit_multisigned" method of JSON-RPC API.
/*
{
    "method": "submit_multisigned",
    "params": [{
        "offline": false,
        "tx_json": mTxJson
    }]
}
*/

// It can also be serialized and submitted through "submit" method of JSON-RPC API.
const serialized = API.serialize(mPaymentTxJson);
console.log("hash  : " + serialized.hash);
console.log("txBlob: " + serialized.txBlob + "\n");
/*
{
    "method": "submit",
    "params": [
        {
            "tx_blob": txBlob
        }
    ]
}
 */

results matching ""

    No results matching ""