EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

Authorization problems when using multiSig Contract #318

Closed co1ingue closed 6 years ago

co1ingue commented 6 years ago

I fellow the example creating a multiSig account

function createAccount(){
    userProvidedKey = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 //EOSIO private key' 
    eos.transaction(tr => {
        tr.newaccount({
            creator: 'eosio',
            name: 'jack23',
            owner: { threshold: 2,
                accounts: [ { permission: {actor:'bob',permission:'active'}, weight: 1 },{ permission: {actor:'alice',permission:'active'}, weight: 1 } ],
                waits: []},
            active: { threshold: 2,
                accounts: [ { permission: {actor:'bob',permission:'active'}, weight: 1 },{ permission: {actor:'alice',permission:'active'}, weight: 1 } ],
                waits: []},  
        })

        tr.buyrambytes({
            payer: 'eosio',
            receiver: 'jack23',
            bytes: 8192
        })

        tr.delegatebw({
            from: 'eosio',
            receiver: 'jack23',
            stake_net_quantity: '10.0000 SYS',
            stake_cpu_quantity: '10.0000 SYS',
            transfer: 0
        })
    })
}

then I want to transfer some EOS to bob

(async function() {

    //bob put a propose
    userProvidedKey = '5JFsGvwD63dc8G2bzV7xmspHeRH1VbJpn2mmzUhd3UUi6RHNYVM'
    const transfer = await eos.transfer('jack23', 'bob', '1.0000 EOS', '', {broadcast: false, sign: false})
    transfer.transaction.transaction.max_net_usage_words = 0 // 
    //console.log(transfer.transaction.transaction)

    msig = await eos.contract('eosio.msig')  
    const randomName = String(Math.round(Math.random() * 100000)).replace(/[0,6-9]/g, '')
    const propose = await msig.propose('bob', 'jack2.' + randomName, [{actor: 'alice', permission: 'active'},{actor: 'bob', permission: 'active'}], transfer.transaction.transaction)
    //console.info(propose)

    //bob confirm the propose
    userProvidedKey = '5JFsGvwD63dc8G2bzV7xmspHeRH1VbJpn2mmzUhd3UUi6RHNYVM'
    const confirm1 = await msig.approve('bob','jack2.' + randomName,{actor: 'bob', permission: 'active'})

    //alice confirm the propose
    userProvidedKey = '5JvJVQwFSYRbVncoKi3HwbN85vW3x3dmm9TkVpXALJgJCUXLFia'
    eos = Eos({httpEndpoint,chainid,keyProvider: '5JvJVQwFSYRbVncoKi3HwbN85vW3x3dmm9TkVpXALJgJCUXLFia' })
    msig = await eos.contract('eosio.msig')
    const confirm2 = await msig.approve('bob','jack2.' + randomName,{actor: 'alice', permission: 'active'})

    //bob exec the propose
    userProvidedKey = '5JFsGvwD63dc8G2bzV7xmspHeRH1VbJpn2mmzUhd3UUi6RHNYVM'
    msig = await eos.contract('eosio.msig')
    const exec = await msig.exec('bob','jack2.' + randomName,'bob')

    })()

but I got this when Alice confirm the propose


2018-08-24T12:29:22.341 thread-0   http_plugin.cpp:475           handle_exception     ] FC Exception encountered while processing chain.push_transaction
2018-08-24T12:29:22.341 thread-0   http_plugin.cpp:476           handle_exception     ] Exception Details: 3090003 unsatisfied_authorization: Provided keys, permissions, and delays do not satisfy declared authorizations
transaction declares authority '{"actor":"bob","permission":"active"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], and provided keys ["EOS6pRHvA2AsnV6YFuSKiqYM1opbT6pNWzQYrQRuRxF2e8xqwLxg6"]
    {"auth":{"actor":"bob","permission":"active"},"provided_delay":0,"provided_permissions":[],"provided_keys":["EOS6pRHvA2AsnV6YFuSKiqYM1opbT6pNWzQYrQRuRxF2e8xqwLxg6"],"delay_max_limit_ms":3888000000}
    thread-0  authorization_manager.cpp:411 check_authorization

Do alice need bob's key to confirm , or there is some kind of cacahe in the Contract ? I find that command line works cleos multisig approve bob jack2.42 '{"actor":"alice","permission":"active"}' -p alice@active

Please help me..

jcalfee commented 6 years ago

Try two permission levels (the first is for the smart contract, the last one is for eosjs). Eosjs tries the first account name as the permission level but in this case it is not correct, bob is not the permission you need so just override it.

    const confirm2 = await msig.approve('bob','jack2.' + randomName,{actor: 'alice', permission: 'active'}, {actor: 'alice', permission: 'active'})
co1ingue commented 6 years ago

@jcalfee Thanks very much ,you solved my problem. const confirm2 = await msig.approve('bob','jack2.' + randomName,{actor: 'alice', permission: 'active'}, {authorization: 'alice@active'})