How to use the eth-crypto.encryptWithPublicKey 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 austintgriffith / burner-wallet / src / components / History.js View on Github external
async sendChat(){
    this.setState({sendingChat:true})
    let value = 0
    if(this.state.newChatAmount){
      value = this.state.newChatAmount
    }

    let message
    let targetPublicKey = this.state["publicKey_"+this.props.target]
    let wasEncrypted = false
    if(targetPublicKey){
      //encrypt!
      console.log("ecrypting message with public key",targetPublicKey)
      const encrypted = await EthCrypto.encryptWithPublicKey(
          targetPublicKey.substring(2), // publicKey
          this.state.newChat // message
      );
      console.log("ENCRYPTED:",encrypted)
      const encryptedString = EthCrypto.cipher.stringify(encrypted)
      console.log("encryptedString",encryptedString)
      message = "0x"+encryptedString
      let update = {}
      let key = message.substring(0,32)
      console.log("saving key ",key,"to the state")
      update[key]=this.state.newChat
      this.props.saveKey(update)
      localStorage.setItem(key,this.state.newChat)
      wasEncrypted=true
    }else{
      //rawdog
github ConnextProject / indra / modules / client / src / controllers / ConditionalTransferController.ts View on Github external
invalid32ByteHexString(preImage),
      invalidXpub(recipient),
    );

    const linkedHash = createLinkedHash(amount, assetId, paymentId, preImage);

    // wait for linked transfer
    const ret = await this.handleLinkedTransfers({
      ...params,
      conditionType: "LINKED_TRANSFER",
    });

    // set recipient and encrypted pre-image on linked transfer
    // TODO: use app path instead?
    const recipientPublicKey = fromExtendedKey(recipient).derivePath("0").publicKey;
    const encryptedPreImageCipher = await EthCrypto.encryptWithPublicKey(
      recipientPublicKey.slice(2), // remove 0x
      preImage,
    );
    const encryptedPreImage = EthCrypto.cipher.stringify(encryptedPreImageCipher);
    await this.connext.setRecipientAndEncryptedPreImageForLinkedTransfer(
      recipient,
      encryptedPreImage,
      linkedHash,
    );

    // publish encrypted secret
    // TODO: should we move this to its own file?
    this.connext.messaging.publish(
      `transfer.send-async.${recipient}`,
      stringify({
        amount: amount.toString(),
github RequestNetwork / requestNetwork / packages / utils / src / crypto / ec-utils.ts View on Github external
async function encrypt(publicKey: string, data: string): Promise {
  try {
    // Encrypts the data with the publicKey, returns the encrypted data with encryption parameters (such as IV..)
    const encrypted = await EthCrypto.encryptWithPublicKey(publicKey, data);

    // Transforms the object with the encrypted data into a smaller string-representation.
    return EthCrypto.cipher.stringify(encrypted);
  } catch (e) {
    if (e.message === 'public key length is invalid') {
      throw new Error('The public key must be a string representing 64 bytes');
    }
    throw e;
  }
}
github ShipChain / engine / src / entity / encryption / PrivateKeyDBFieldEncryption.ts View on Github external
async encrypt(private_key: string): Promise {
        const encrypted = await EthCrypto.encryptWithPublicKey(this.masterPublicKey, private_key);
        return EthCrypto.cipher.stringify(encrypted);
    }
github ShipChain / engine / src / entity / Wallet.ts View on Github external
static async encrypt(public_key, message) {
        return await EthCrypto.encryptWithPublicKey(public_key, message);
    }