This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from jzaki/revert-36-bw-35-update-signer-for-t…
…x-sets Revert "Update signer for tx sets"
- Loading branch information
Showing
10 changed files
with
98 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import * as hubbleBls from "../deps/hubble-bls"; | ||
|
||
import { Transaction } from "./types"; | ||
import { AggregateTransactionData, TransactionData } from "./types"; | ||
|
||
export default (txs: Transaction[]): Transaction => { | ||
export default (txs: TransactionData[]): AggregateTransactionData => { | ||
const sigsG1 = txs.map(tx => hubbleBls.mcl.loadG1(tx.signature)); | ||
const aggSigG1 = hubbleBls.signer.aggregate(sigsG1); | ||
|
||
const aggregateSignature = hubbleBls.mcl.dumpG1(aggSigG1); | ||
|
||
return { | ||
subTransactions: txs.map(txSet => txSet.subTransactions).flat(), | ||
signature: hubbleBls.mcl.dumpG1(aggSigG1), | ||
transactions: txs.map(tx => ({ | ||
publicKey: tx.publicKey, | ||
nonce: tx.nonce, | ||
ethValue: tx.ethValue, | ||
contractAddress: tx.contractAddress, | ||
encodedFunction: tx.encodedFunction, | ||
})), | ||
signature: aggregateSignature, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { keccak256 } from "@ethersproject/keccak256"; | ||
import { pack as solidityPack } from "@ethersproject/solidity"; | ||
import { TransactionTemplate } from "./types"; | ||
import { RawTransactionData } from "./types"; | ||
|
||
export default ( | ||
chainId: number, | ||
) => ( | ||
txTemplate: TransactionTemplate, | ||
rawTxData: RawTransactionData, | ||
): string => { | ||
return solidityPack( | ||
["uint256", "uint256", "uint256", "address", "bytes32"], | ||
[ | ||
chainId, | ||
txTemplate.nonce, | ||
txTemplate.ethValue, | ||
txTemplate.contractAddress, | ||
keccak256(txTemplate.encodedFunction), | ||
rawTxData.nonce, | ||
rawTxData.ethValue, | ||
rawTxData.contractAddress, | ||
keccak256(rawTxData.encodedFunction), | ||
] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
|
||
export type TransactionTemplate = { | ||
export type RawTransactionData = { | ||
nonce: BigNumber; | ||
ethValue: BigNumber; | ||
contractAddress: string; | ||
encodedFunction: string; | ||
}; | ||
|
||
export type SubTransaction = TransactionTemplate & { publicKey: string }; | ||
|
||
export type Transaction = { | ||
subTransactions: SubTransaction[]; | ||
export type TransactionData = RawTransactionData & { | ||
publicKey: string; | ||
signature: string; | ||
}; | ||
|
||
export type AggregateTransactionData = { | ||
transactions: { | ||
publicKey: string; | ||
nonce: BigNumber; | ||
ethValue: BigNumber; | ||
contractAddress: string; | ||
encodedFunction: string; | ||
}[], | ||
signature: string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import * as hubbleBls from "../deps/hubble-bls"; | ||
|
||
import encodeMessageForSigning from "./encodeMessageForSigning"; | ||
import { Transaction } from "./types"; | ||
import { TransactionData } from "./types"; | ||
|
||
export default ( | ||
domain: Uint8Array, | ||
chainId: number, | ||
) => (tx: Transaction): boolean => { | ||
) => ( | ||
txData: TransactionData, | ||
): boolean => { | ||
const verifier = new hubbleBls.signer.BlsVerifier(domain); | ||
|
||
return verifier.verifyMultiple( | ||
hubbleBls.mcl.loadG1(tx.signature), | ||
tx.subTransactions.map( | ||
subTx => hubbleBls.mcl.loadG2(subTx.publicKey), | ||
), | ||
tx.subTransactions.map( | ||
subTx => encodeMessageForSigning(chainId)(subTx), | ||
), | ||
return verifier.verify( | ||
hubbleBls.mcl.loadG1(txData.signature), | ||
hubbleBls.mcl.loadG2(txData.publicKey), | ||
encodeMessageForSigning(chainId)(txData), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as hubbleBls from "../deps/hubble-bls"; | ||
|
||
import encodeMessageForSigning from "./encodeMessageForSigning"; | ||
import { AggregateTransactionData } from "./types"; | ||
|
||
export default ( | ||
domain: Uint8Array, | ||
chainId: number, | ||
) => ( | ||
aggregateTxData: AggregateTransactionData, | ||
): boolean => { | ||
const verifier = new hubbleBls.signer.BlsVerifier(domain); | ||
|
||
return verifier.verifyMultiple( | ||
hubbleBls.mcl.loadG1(aggregateTxData.signature), | ||
aggregateTxData.transactions.map( | ||
tx => hubbleBls.mcl.loadG2(tx.publicKey), | ||
), | ||
aggregateTxData.transactions.map( | ||
tx => encodeMessageForSigning(chainId)(tx), | ||
), | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters