How to use the @cityofzion/neon-js.wallet.Account function in @cityofzion/neon-js

To help you get started, we’ve selected a few @cityofzion/neon-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CityOfZion / neon-wallet / app / modules / transactions.js View on Github external
if (isHardwareSend && !isWatchOnly) {
      dispatch(
        showInfoNotification({
          message: 'Please sign the transaction on your hardware device',
          autoDismiss: 0,
        }),
      )
    }

    const config = {
      net,
      tokensBalanceMap,
      address: fromAddress,
      publicKey,
      privateKey: new wallet.Account(wif).privateKey,
      signingFunction: isHardwareSend ? signingFunction : null,
      fees,
      url,
      balance: undefined,
      tx: undefined,
      intents: undefined,
      script: undefined,
      gas: undefined,
    }
    const balanceResults = await api
      .getBalanceFrom({ net, address: fromAddress }, api.neoscan)
      .catch(e => {
        // indicates that neo scan is down and that api.sendAsset and api.doInvoke
        // will fail unless balances are supplied
        console.error(e)
        config.balance = generateBalanceInfo(tokensBalanceMap, fromAddress, net)
github PacktPublishing / Foundations-of-Blockchain / Chapter07 / NEO / proof_of_ownership_app / interface / src / App.js View on Github external
registerAsset(assetID)
    {

        try {
            let account = new wallet.Account('KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr');

            let intents = [{

                assetId: Neon.CONST.ASSET_ID.GAS,

                value: new Neon.u.Fixed8(1),  // I gueesed this :)

                scriptHash: '60a7ed582c6885addf1f9bec7e413d01abe54f1a'

            }];

            // the interesting part: what do we want to do :)

            let invoke = {

                scriptHash: '60a7ed582c6885addf1f9bec7e413d01abe54f1a',
github CityOfZion / neon-js / examples / basic / multi.js View on Github external
const neoscan = new api.neoscan.instance(
  "https://neoscan-testnet.io/api/main_net"
);
const rpcNodeUrl = "http://seed2.neo.org:20332";

/**
Our multi-sig account in this example is made up of 3 keys with a signing threshold of 2.
Do note that the order of keys in the array matters. A different order will generate a totally different address.
 */
const keyA = new wallet.Account(
  "7d128a6d096f0c14c3a25a2b0c41cf79661bfcb4a8cc95aaaea28bde4d732344"
);
const keyB = new wallet.Account(
  "9ab7e154840daca3a2efadaf0df93cd3a5b51768c632f5433f86909d9b994a69"
);
const keyC = new wallet.Account(
  "3edee7036b8fd9cef91de47386b191dd76db2888a553e7736bb02808932a915b"
);

const multisigAcct = wallet.Account.createMultiSig(2, [
  keyA.publicKey,
  keyB.publicKey,
  keyC.publicKey
]);

console.log("\n\n--- Multi-sig ---");
console.log(`My multi-sig address is ${multisigAcct.address}`);
console.log(`My multi-sig verificationScript is ${multisigAcct.contract.script}`);

/**
## Construct Transaction
Similar to how we setup a transaction for a normal account transfer, we also do the same for our transfer from a multi-sig account.
github CityOfZion / neon-js / examples / basic / sendasset.js View on Github external
We need to decide which provider shall we use. In this example, I shall be using `TestNet` with neoscan. As `TestNet` is built into the `neon-js` networks, we can retrieve it using its name `TestNet` instead of stating a url. For other networks such as your own private network, you will input the url of your private neoscan (for example, https://localhost:4000/api/main_net)
*/

const apiProvider = new api.neoscan.instance(network);

console.log("\n\n--- API Provider ---");
console.log(apiProvider);

/**
## Creating the Account
We create an `Account` object to store our credentials. In this example, we are using a private key to create the account because we are also signing with the same private key. However, if you wish to use an external signing function (such as a ledger), you can create the account with an address and provide the signing function instead.

This account will be the account where the assets will come from.
*/

const account = new wallet.Account(sendingKey);

console.log("\n\n--- Sending Address ---");
console.log(account);

/**
## Execute
We assemble the config object and sendAsset will do the following:

1. Retrieve the balance of sendingKey from apiProvider.
2. Retrieve a good rpc url from apiProvider.
3. Assemble the transaction using the balance and intents.
4. Sign the transaction using the sendingKey
5. Submit the transaction to the network using the `sendrawtransaction` RPC call to the rpc url.
*/

const config = {
github CityOfZion / neon-wallet / app / modules / transactions.js View on Github external
const buildTransferScript = (
  net: NetworkType,
  sendEntries: Array,
  fromAddress: string,
  tokensBalanceMap: {
    [key: string]: TokenBalanceType,
  },
) => {
  const tokenEntries = extractTokens(sendEntries)
  const fromAcct = new wallet.Account(fromAddress)
  const scriptBuilder = new sc.ScriptBuilder()

  tokenEntries.forEach(({ address, amount, symbol }) => {
    const toAcct = new wallet.Account(address)
    const { scriptHash, decimals } = tokensBalanceMap[symbol]
    const args = [
      u.reverseHex(fromAcct.scriptHash),
      u.reverseHex(toAcct.scriptHash),
      sc.ContractParam.byteArray(toNumber(amount), 'fixed8', decimals),
    ]

    scriptBuilder.emitAppCall(scriptHash, 'transfer', args)
  })

  return scriptBuilder.str
}
github nos / client / src / renderer / browser / util / encrypt.js View on Github external
export default function encrypt({ recipientPublicKey, wif, data, ivProvider }) {
  const ecdh = ECDH('prime256v1');
  const senderAccount = new wallet.Account(wif);
  const senderPrivateKey = senderAccount.privateKey;

  ecdh.setPrivateKey(senderPrivateKey, 'hex');

  const senderPublicKey = Buffer.from(senderAccount.publicKey, 'hex');
  const sharedKey = ecdh.computeSecret(recipientPublicKey, 'hex');
  const hash = createHash('sha512')
    .update(sharedKey)
    .digest();
  const iv = ivProvider();
  const encryptionKey = hash.slice(0, 32);
  const macKey = hash.slice(32);
  const encrypted = aes256CbcEncrypt(iv, encryptionKey, data);
  const dataToMac = Buffer.concat([iv, senderPublicKey, encrypted]);
  const mac = createHmac('sha256', macKey)
    .update(dataToMac)
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
public importWIF(wif: string, key: string, name: string = null): Observable {
        const account = new wallet.Account(wallet.getPrivateKeyFromWIF(wif));
        const w = Neon.create.wallet({ name: name || 'NEOLineUser' } as any);
        w.addAccount(account);
        w.encrypt(0, key);
        return from(w.accounts[0].encrypt(key)).pipe(map(() => {
            (w.accounts[0] as any).wif = wif;
            return w;
        }));
    }
    /**
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
return Observable.create((observer: Observer) => {
            const w = Neon.create.wallet({ name: name || 'NEOLineUser' } as any);
            w.addAccount(new wallet.Account(encKey));
            wallet.decrypt(encKey, key).then((wif) => {
                const account = new wallet.Account(wallet.getPrivateKeyFromWIF(wif));
                const returnRes = Neon.create.wallet({ name: name || 'NEOLineUser' } as any);
                returnRes.addAccount(account);
                returnRes.encrypt(0, key);
                returnRes.accounts[0].encrypt(key).then(res => {
                    (returnRes.accounts[0] as any).wif = wif;
                    observer.next(returnRes);

                });
            }).catch((err) => {
                observer.error('import failed');
            });
        });
    }
github nos / client / src / util / accountToNEP6.js View on Github external
export default function accountToNEP6({ address, key, label = address, isDefault = true }) {
  const newAccount = new wallet.Account({ address, key, label, isDefault });
  const newWallet = new wallet.Wallet({ accounts: [newAccount] });

  return newWallet.export();
}
github CityOfZion / neon-wallet / app / actions / authActions.js View on Github external
({ passphrase, encryptedWIF }: Nep2LoginProps) => async (): Promise<
    AccountType,
  > => {
    if (!validatePassphraseLength(passphrase)) {
      throw new Error('Passphrase too short')
    }

    if (!wallet.isNEP2(encryptedWIF)) {
      throw new Error('Invalid encrypted key entered')
    }

    const wif = await wallet.decryptAsync(encryptedWIF, passphrase)
    const account = new wallet.Account(wif)

    await upgradeNEP6AddAddresses(encryptedWIF, wif)

    const hasInternetConnectivity = await checkForInternetConnectivity()

    return {
      wif: account.WIF,
      publicKey: account.publicKey,
      address: account.address,
      isHardwareLogin: false,
      hasInternetConnectivity,
    }
  },
)