src/kas/wallet/wallet.js
/**
     * Migrates Klaytn accounts to KAS Wallet API. <br>
     * This function needs Node API. Therefore, it is essential to have initialized to use Node API. <br>
     * Node API initialization is possible through [caver.initKASAPI]{@link CaverExtKAS#initKASAPI} or [caver.initNodeAPI]{@link CaverExtKAS#initNodeAPI}. <br>
     *
     * @example
     * const accounts = [
     *    {
     *        address: '0xc756f6809bc34c2458fcb82fb16d5add3dbad9e3',
     *        key: '0x{private key1}',
     *    },
     *    {
     *        address: '0x5bae5e458ad1a9b210bf0a10434c39be1a5b7983',
     *        key: [
     *            '0x{private key2}',
     *            '0x{private key3}',
     *        ],
     *    },
     *    {
     *        address: '0x5bae5e458ad1a9b210bf0a10434c39be1a5b7983',
     *        key: [
     *            [
     *                '0x{private key4}',
     *                '0x{private key5}',
     *            ],
     *            [
     *                '0x{private key6}',
     *            ],
     *            [
     *                '0x{private key7}',
     *                '0x{private key8}',
     *            ],
     *        ],
     *    }
     * ]
     * const ret = await caver.kas.wallet.migarateAccounts(accounts)
     *
     * @param {Array.<MigrationAccount>} accounts An array of account objects migrated into KAS.
     * @return {RegistrationStatusResponse}
     */
Migrates Klaytn accounts to KAS Wallet API. 
This function needs Node API. Therefore, it is essential to have initialized to use Node API.



@param {Array.} accounts An array of account objects migrated into KAS.
Migrates Klaytn accounts to KAS Wallet API . This function needs Node API . Therefore it is essential to have initialized to use Node API . @param { Array . } accounts An array of account objects migrated into KAS .
async migrateAccounts(accounts) {
        if (!this.accessOptions || !this.accountApi) throw new Error(NOT_INIT_API_ERR_MSG)
        if (!Array.isArray(accounts)) throw new Error(INCORRECT_MIGRATE_ACCOUNTS)
        const keys = await this.createKeys(accounts.length)
        const req = []
        for (const account of accounts) {
            const key = keys.items.pop()
            const keyring = this.keyring.create(account.address, account.key)
            const updateTx = new this.accountsMigration.feeDelegatedAccountUpdate({
                from: account.address,
                account: this.accountsMigration.createWithAccountKeyPublic(account.address, key.publicKey),
                gas: 1000000,
                chainId: this.chainId,
            })
            if (account.nonce !== undefined) updateTx.nonce = account.nonce
            await updateTx.sign(keyring)
            req.push({
                keyId: key.keyId,
                address: account.address,
                rlp: updateTx.getRLPEncoding(),
            })
        }
        return new Promise((resolve, reject) => {
            this.registrationApi.registerAccount(this.chainId, { body: req }, (err, data, response) => {
                if (err) {
                    reject(err)
                }
                resolve(data)
            })
        })
    }
async migrateAccounts ( accounts ) { if ( ! this . accessOptions || ! this . accountApi ) throw new Error ( NOT_INIT_API_ERR_MSG ) if ( ! Array . isArray ( accounts ) ) throw new Error ( INCORRECT_MIGRATE_ACCOUNTS ) const keys = await this . createKeys ( accounts . length ) const req = [ ] for ( const account of accounts ) { const key = keys . items . pop ( ) const keyring = this . keyring . create ( account . address , account . key ) const updateTx = new this . accountsMigration . feeDelegatedAccountUpdate ( { from : account . address , account : this . accountsMigration . createWithAccountKeyPublic ( account . address , key . publicKey ) , gas : 1000000 , chainId : this . chainId , } ) if ( account . nonce !== undefined ) updateTx . nonce = account . nonce await updateTx . sign ( keyring ) req . push ( { keyId : key . keyId , address : account . address , rlp : updateTx . getRLPEncoding ( ) , } ) } return new Promise ( ( resolve , reject ) => { this . registrationApi . registerAccount ( this . chainId , { body : req } , ( err , data , response ) => { if ( err ) { reject ( err ) } resolve ( data ) } ) } ) }
Migrates Klaytn accounts to KAS Wallet API.
Migrates Klaytn accounts to KAS Wallet API .
// Request a set of public keys generated by KAS wallet service. // Define an empty request for account migration. // Create a keyring instance. // Compose a transaction for fee delegated account update with a public key generated by KAS. // Sign the transaction with keyring instance. // Append an item for updating the account into the request. // Call an account registration API with the request containing a set of transaction RLP for updating account. // This API will invoke transactions for RLPs if they are included. // Otherwise, you can update your Klaytn's account with your own Klaytn node in advance.