rjchow / ethers-aws-kms-signer Goto Github PK
View Code? Open in Web Editor NEWEthers Signer that connects to AWS KMS
License: MIT License
Ethers Signer that connects to AWS KMS
License: MIT License
Shouldn't a call to sign message with exactly the same message return the
same signature?
Hey, seems like this library is not working on binance smart chain. I am getting error only replay-protected (EIP-155) transactions allowed over RPC
@imnisen
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
Hey @rjchow , thanks for creating this signer.
We have used this project to create the GCP KMS signer, so I will share it here in case anyone wants to use google signer: https://github.com/openlawteam/ethers-gcp-kms-signer
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!
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.
ethers-aws-kms-signer/src/index.ts
Line 23 in 8e3a481
Can we add an optional param to skip the if statement above?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.