diff --git a/bin/multisig.wasm b/bin/multisig.wasm new file mode 100755 index 00000000..c904c5b7 Binary files /dev/null and b/bin/multisig.wasm differ diff --git a/index.js b/index.js index 90652ef5..46b8b88a 100644 --- a/index.js +++ b/index.js @@ -180,7 +180,6 @@ exports.viewAccount = async function (options) { }; exports.deleteAccount = async function (options) { - console.log( `Deleting account. Account id: ${options.accountId}, node: ${options.nodeUrl}, helper: ${options.helperUrl}, beneficiary: ${options.beneficiaryId}`); const near = await connect(options); diff --git a/utils/2fa.js b/utils/2fa.js new file mode 100644 index 00000000..0cbfe07b --- /dev/null +++ b/utils/2fa.js @@ -0,0 +1,24 @@ + +// const prompts = require('prompts'); +const readline = require('readline'); +const chalk = require('chalk'); + +const getCode = async(method) => { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + const securityCode = await new Promise((res) => { + rl.question(chalk`{bold Enter security code sent to ${ method.kind.split('2fa-')[1] }: }`, (accountId) => res(accountId)); + }); + rl.close(); + return securityCode; +}; + +const onResult = async(result) => { + console.log('Request confirmed with result:', result); +}; + +module.exports = { + options2fa: { getCode, onResult } +}; diff --git a/utils/connect.js b/utils/connect.js index 10523331..4a5747a1 100644 --- a/utils/connect.js +++ b/utils/connect.js @@ -1,6 +1,13 @@ -const { connect: nearConnect } = require('near-api-js'); +const { + connect: nearConnect, + multisig: { + modIfMultisig, + } +} = require('near-api-js'); +const { options2fa } = require('./2fa'); module.exports = async function connect({ keyStore, ...options }) { - // TODO: Avoid need to wrap in deps - return await nearConnect({ ...options, deps: { keyStore }}); + const near = await nearConnect({ ...options, deps: { keyStore }}); + modIfMultisig(near, options2fa); + return near; };