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 #36 from jzaki/bw-35-update-signer-for-tx-sets
Update signer for tx sets
- Loading branch information
Showing
10 changed files
with
101 additions
and
98 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,21 +1,13 @@ | ||
import * as hubbleBls from "../deps/hubble-bls"; | ||
|
||
import { AggregateTransactionData, TransactionData } from "./types"; | ||
import { Transaction } from "./types"; | ||
|
||
export default (txs: TransactionData[]): AggregateTransactionData => { | ||
export default (txs: Transaction[]): Transaction => { | ||
const sigsG1 = txs.map(tx => hubbleBls.mcl.loadG1(tx.signature)); | ||
const aggSigG1 = hubbleBls.signer.aggregate(sigsG1); | ||
|
||
const aggregateSignature = hubbleBls.mcl.dumpG1(aggSigG1); | ||
|
||
return { | ||
transactions: txs.map(tx => ({ | ||
publicKey: tx.publicKey, | ||
nonce: tx.nonce, | ||
ethValue: tx.ethValue, | ||
contractAddress: tx.contractAddress, | ||
encodedFunction: tx.encodedFunction, | ||
})), | ||
signature: aggregateSignature, | ||
subTransactions: txs.map(txSet => txSet.subTransactions).flat(), | ||
signature: hubbleBls.mcl.dumpG1(aggSigG1), | ||
}; | ||
} |
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 { RawTransactionData } from "./types"; | ||
import { TransactionTemplate } from "./types"; | ||
|
||
export default ( | ||
chainId: number, | ||
) => ( | ||
rawTxData: RawTransactionData, | ||
txTemplate: TransactionTemplate, | ||
): string => { | ||
return solidityPack( | ||
["uint256", "uint256", "uint256", "address", "bytes32"], | ||
[ | ||
chainId, | ||
rawTxData.nonce, | ||
rawTxData.ethValue, | ||
rawTxData.contractAddress, | ||
keccak256(rawTxData.encodedFunction), | ||
txTemplate.nonce, | ||
txTemplate.ethValue, | ||
txTemplate.contractAddress, | ||
keccak256(txTemplate.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,24 +1,15 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
|
||
export type RawTransactionData = { | ||
export type TransactionTemplate = { | ||
nonce: BigNumber; | ||
ethValue: BigNumber; | ||
contractAddress: string; | ||
encodedFunction: string; | ||
}; | ||
|
||
export type TransactionData = RawTransactionData & { | ||
publicKey: string; | ||
signature: string; | ||
}; | ||
export type SubTransaction = TransactionTemplate & { publicKey: string }; | ||
|
||
export type AggregateTransactionData = { | ||
transactions: { | ||
publicKey: string; | ||
nonce: BigNumber; | ||
ethValue: BigNumber; | ||
contractAddress: string; | ||
encodedFunction: string; | ||
}[], | ||
signature: string, | ||
export type Transaction = { | ||
subTransactions: SubTransaction[]; | ||
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,19 +1,21 @@ | ||
import * as hubbleBls from "../deps/hubble-bls"; | ||
|
||
import encodeMessageForSigning from "./encodeMessageForSigning"; | ||
import { TransactionData } from "./types"; | ||
import { Transaction } from "./types"; | ||
|
||
export default ( | ||
domain: Uint8Array, | ||
chainId: number, | ||
) => ( | ||
txData: TransactionData, | ||
): boolean => { | ||
) => (tx: Transaction): boolean => { | ||
const verifier = new hubbleBls.signer.BlsVerifier(domain); | ||
|
||
return verifier.verify( | ||
hubbleBls.mcl.loadG1(txData.signature), | ||
hubbleBls.mcl.loadG2(txData.publicKey), | ||
encodeMessageForSigning(chainId)(txData), | ||
return verifier.verifyMultiple( | ||
hubbleBls.mcl.loadG1(tx.signature), | ||
tx.subTransactions.map( | ||
subTx => hubbleBls.mcl.loadG2(subTx.publicKey), | ||
), | ||
tx.subTransactions.map( | ||
subTx => encodeMessageForSigning(chainId)(subTx), | ||
), | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default function Range(limit: number): number[] { | ||
const result: number[] = []; | ||
|
||
for (let i = 0; i < limit; i += 1) { | ||
result.push(i); | ||
} | ||
|
||
return result; | ||
} |
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