Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create assembleChildTx to abstract away signing logic in an attempt to better support browser wallets #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions src/lib/inbox/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,8 @@ export class InboxTools {
}

/**
* Sign a transaction with msg.to, msg.value and msg.data.
* You can use this as a helper to call inboxTools.sendChainSignedMessage
* above.
* Assemble a transaction with msg.to, msg.value and msg.data.
* This is used right below to provide a transaction to signChildTx and sendChildTx.
* @param txRequest A signed transaction which can be sent directly to chain,
* tx.to, tx.data, tx.value must be provided when not contract creation, if
* contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce
Expand All @@ -426,10 +425,10 @@ export class InboxTools {
* @param childSigner ethers Signer type, used to sign Chain transaction
* @returns The parent delayed inbox's transaction signed data.
*/
public async signChildTx(
public async assembleChildTx(
txRequest: RequiredTransactionRequestType,
childSigner: Signer
): Promise<string> {
): Promise<RequiredTransactionRequestType> {
const tx: RequiredTransactionRequestType = { ...txRequest }
const contractCreation = this.isContractCreation(tx)

Expand Down Expand Up @@ -472,6 +471,52 @@ export class InboxTools {
if (contractCreation) {
delete tx.to
}
return tx
}

/**
* Sign a transaction with msg.to, msg.value and msg.data.
* You can use this as a helper to call inboxTools.sendChainSignedMessage
* above.
* @param txRequest A signed transaction which can be sent directly to chain,
* tx.to, tx.data, tx.value must be provided when not contract creation, if
* contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce
* can be overrided. (You can also send contract creation transaction by set tx.to
* to zero address or null)
* @param childSigner ethers Signer type, used to sign Chain transaction
* @returns The parent delayed inbox's transaction signed data.
*/
public async signChildTx(
txRequest: RequiredTransactionRequestType,
childSigner: Signer
): Promise<string> {
const tx: RequiredTransactionRequestType = await this.assembleChildTx(
txRequest,
childSigner
)
return await childSigner.signTransaction(tx)
}

/**
* Sign a transaction with msg.to, msg.value and msg.data.
* A copy of `signChildTx` above but that instead of just signing also sends the transaction.
* This is a workaround wallets in browsers not supporting signing only.
* @param txRequest A signed transaction which can be sent directly to chain,
* tx.to, tx.data, tx.value must be provided when not contract creation, if
* contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce
* can be overrided. (You can also send contract creation transaction by set tx.to
* to zero address or null)
* @param childSigner ethers Signer type, used to sign and send Chain transaction
* @returns The parent delayed inbox's transaction signed data.
*/
public async sendChildTx(
txRequest: RequiredTransactionRequestType,
childSigner: Signer
): Promise<string> {
const tx: RequiredTransactionRequestType = await this.assembleChildTx(
txRequest,
childSigner
)
return (await childSigner.sendTransaction(tx)).hash
}
}