How to use the eth-crypto.sign function in eth-crypto

To help you get started, we’ve selected a few eth-crypto 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 cryptoeconomics-study / code / ch2 / nodeAgent.js View on Github external
// amount of transaction
      amount,
      // which address the transaction is from
      from: this.wallet.address,
      // which address the transaction is going to
      to,
      // the nonce of the sender's address at the time of creating this transaction
      nonce: this.state[this.wallet.address].nonce,
    };
    // create a transaction object
    const tx = {
      // unsigned transaction
      contents: unsignedTx,
      // signature of the unsigned transaction
      // (hash the unsigned transaction object and then sign it with this node's private key)
      sig: EthCrypto.sign(this.wallet.privateKey, getTxHash(unsignedTx)),
    };
    // return the transaction object
    return tx;
  }
github liquality / chainabstractionlayer / packages / ethereum-rpc-wallet-provider / lib / EthereumRPCWalletProvider.js View on Github external
async signMessage (message) {
    const hex = Buffer.from(message).toString('hex')
    const messageHash = EthCrypto.hash.keccak256(message);

    const signature = EthCrypto.sign(
      ensure0x(this.wallet.getPrivateKey().toString('hex')), // private key
      messageHash // hash of message
    );

    return remove0x(signature)
  }
github cryptoeconomics-study / code / c1_CentralPaymentOperator / 1.4 - Account Model vs. UTXOs / solution / Client.js View on Github external
sign(message) {
        const messageHash = this.toHash(message)
        return EthCrypto.sign(
            this.wallet.privateKey,
            messageHash
        )
    }
github decentraland / explorer / kernel / packages / shared / crypto / Authenticator.ts View on Github external
static doCreateSignature(privateKey: string, message: string) {
    return sign(privateKey, Authenticator.createEthereumMessageHash(message))
  }
github cryptoeconomics-study / code / ch1 / 1.3 / Client.js View on Github external
sign(message) {
    const messageHash = this.hash(message);
    return EthCrypto.sign(this.wallet.privateKey, messageHash);
  }
github cryptoeconomics-study / code / ch3 / nodeAgent.js View on Github external
generateTx (to, amount) {
    const unsignedTx = {
      type: 'send',
      amount: amount,
      from: this.wallet.address,
      to: to,
      nonce: this.nonce
    }
    const tx = {
      contents: unsignedTx,
      sig: EthCrypto.sign(this.wallet.privateKey, getTxHash(unsignedTx))
    }
    this.nonce++ //added so a node can send multiple txs before applying them (before they are included in a block)
    return tx
  }
github cryptoeconomics-study / code / ch2 / 2.3 / FaultTolerant.js View on Github external
if(this.network.time >= this.timeout(tx.contents.timestamp, sigs.size)) return
    //seen tx
    this.seen.push(tx.contents)
    //TODO Check that each signee is actually a peer in the network
      //-possible attack: byzantine node signs a message 100 times with random Private Key
    const finalTimeout = this.timeout(tx.contents.timestamp, this.network.agents.length)
    if (!this.pendingTxs[finalTimeout]) this.pendingTxs[finalTimeout] = []
    //add to pending ( we'll apply this transaction once we hit finalTimeout)
    this.pendingTxs[finalTimeout].push(tx)
    //Choice rule: if have two transactions with same sender, nonce, and timestamp apply the one with lower sig first
    this.pendingTxs[finalTimeout].sort((a, b)=>{
      return a.sigs[0] - b.sigs[0]
    })

    //add signature
    tx.sigs.push(EthCrypto.sign(this.wallet.privateKey, getTxHash(tx)))
    this.network.broadcast(this.pid, tx)
  }
github cryptoeconomics-study / code / ch1 / 1.2 / solution / Client.js View on Github external
sign(message) {
        const messageHash = this.toHash(message)
        return EthCrypto.sign(
            this.wallet.privateKey,
            messageHash
        )
    }
github cryptoeconomics-study / code / ch2 / 2.4 / PoAClient.js View on Github external
generateTx(to, amount) {
    const unsignedTx = {
      type: 'send',
      amount,
      from: this.wallet.address,
      to,
      nonce: this.state[this.wallet.address].nonce,
    };
    const tx = {
      contents: unsignedTx,
      sigs: [],
    };
    tx.sigs.push(EthCrypto.sign(this.wallet.privateKey, getTxHash(tx)));
    return tx;
  }