Coder Social home page Coder Social logo

ethers-aws-kms-signer's People

Contributors

rjchow avatar semantic-release-bot avatar shioju avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ethers-aws-kms-signer's Issues

List compatible ethers versions

I believe this is not compatible with the v6 of ethers? Or maybe its just my specific version 6.7? I would love a list of compatible major versions or latest version etc

Send Legacy and EIP-155 Transactions error due to transaction:from field

Hi, When I try to use this library to send a Legacy transaction with gasPrice filed. I got the following error

Error: invalid object key - from (argument="transaction:from", value={"to":"0xxxxxxxxx","value":{"type":"BigNumber","hex":"0x016345785d8a0000"},"gasLimit":22000,"gasPrice":{"type":"BigNumber","hex":"0x59682f08"},"type":0,"from":"0x2cxxxxxx","nonce":5,"chainId":5}, code=INVALID_ARGUMENT, version=properties/5.6.0)
    at Logger.makeError (/home/ubuntu/kms-demo/node_modules/@ethersproject/logger/lib/index.js:233:21)
    at Logger.throwError (/home/ubuntu/kms-demo/node_modules/@ethersproject/logger/lib/index.js:242:20)
    at Logger.throwArgumentError (/home/ubuntu/kms-demo/node_modules/@ethersproject/logger/lib/index.js:245:21)
    at /home/ubuntu/kms-demo/node_modules/@ethersproject/properties/lib/index.js:93:20
    at Array.forEach (<anonymous>)
    at checkProperties (/home/ubuntu/kms-demo/node_modules/@ethersproject/properties/lib/index.js:91:25)
    at _serialize (/home/ubuntu/kms-demo/node_modules/@ethersproject/transactions/lib/index.js:173:38)
    at Object.serialize (/home/ubuntu/kms-demo/node_modules/@ethersproject/transactions/lib/index.js:246:16)
    at /home/ubuntu/kms-demo/node_modules/ethers-aws-kms-signer/dist/index.js:77:49
    at Generator.next (<anonymous>) {
  reason: 'invalid object key - from',
  code: 'INVALID_ARGUMENT',
  argument: 'transaction:from',
  value: {
    to: '0xxxxxxxxx',
    value: BigNumber { _hex: '0x016345785d8a0000', _isBigNumber: true },
    gasLimit: 22000,
    gasPrice: BigNumber { _hex: '0x59682f08', _isBigNumber: true },
    type: 0,
    from: '0x2cxxxxxx',
    nonce: 5,
    chainId: 5
  }
}

My demo code:

let signer = new AwsKmsSigner(kmsCredentials);
const provider = ethers.providers.getDefaultProvider("xxxxxxx");
signer = signer.connect(provider);

const tx = await signer.sendTransaction({
        // from: from,
        to: "0x00000",
        value: value,
        gasLimit: gasLimit,
        gasPrice: gp,
        // maxFeePerGas: maxFeePerGas,
        // maxPriorityFeePerGas: maxPriorityFeePerGas
        type: 0
    });

I have checked the source code:

signer.sendTransaction would call populateTransaction of ethers's abstract-signer:

// Populates all fields in a transaction, signs it and sends it to the network
async sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> {
        this._checkProvider("sendTransaction");
        
        const tx = await this.populateTransaction(transaction);
        
        const signedTx = await this.signTransaction(tx);
        
        return await this.provider.sendTransaction(signedTx);
    }

it would add from:0xxxxx field to tx.

Then in your lib's signTransaction, you call _ethers.ethers.utils.serializeTransaction(unsignedTx):

signTransaction(transaction) {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      
      const unsignedTx = yield _ethers.ethers.utils.resolveProperties(transaction);
      
      const serializedTx = _ethers.ethers.utils.serializeTransaction(unsignedTx);
      
      const transactionSignature = yield _this4._signDigest(_ethers.ethers.utils.keccak256(serializedTx));
      
      return _ethers.ethers.utils.serializeTransaction(unsignedTx, transactionSignature);
    })();
  }

then it would call _serialize function of ethers, which would call checkProperties:

// Legacy Transactions and EIP-155
function _serialize(transaction: UnsignedTransaction, signature?: SignatureLike): string {
    checkProperties(transaction, allowedTransactionKeys);
    ......

And the checkProperties fails due to the from key:

export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void {
    if (!object || typeof(object) !== "object") {
        logger.throwArgumentError("invalid object", "object", object);
    }

    Object.keys(object).forEach((key) => {
        if (!properties[key]) {
            logger.throwArgumentError("invalid object key - " + key, "transaction:" + key, object);
        }
    });
}


const allowedTransactionKeys: { [ key: string ]: boolean } = {
    chainId: true, data: true, gasLimit: true, gasPrice:true, nonce: true, to: true, type: true, value: true
}

It would not cause error of an EIP1559 transaction, because _serializeEip1559 pack fields only needed.

I haven't figure out good method to escape this error besides that delete tx.from before serilization:

signTransaction(transaction) {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      
      const unsignedTx = yield _ethers.ethers.utils.resolveProperties(transaction);
      
      delete unsignedTx.from; // modify here!
      
      const serializedTx = _ethers.ethers.utils.serializeTransaction(unsignedTx);
      
      const transactionSignature = yield _this4._signDigest(_ethers.ethers.utils.keccak256(serializedTx));
      
      return _ethers.ethers.utils.serializeTransaction(unsignedTx, transactionSignature);
    })();
  }

Do you have any suggestions? Thank you!

getAddress() returns old key

While implementing key rotation it was found that getAddress() does not return us the latest value but the signer still signs using the latest one. This mismatch in addresses is causing the signed docs to be invalid.

if (this.ethereumAddress === undefined) {

Can we add an optional param to skip the if statement above?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.