|
|
|
const { web3 } = require('@openzeppelin/test-environment');
|
|
|
|
|
|
|
|
function toEthSignedMessageHash (messageHex) {
|
|
|
|
const messageBuffer = Buffer.from(messageHex.substring(2), 'hex');
|
|
|
|
const prefix = Buffer.from(`\u0019Ethereum Signed Message:\n${messageBuffer.length}`);
|
|
|
|
return web3.utils.sha3(Buffer.concat([prefix, messageBuffer]));
|
|
|
|
}
|
|
|
|
|
Signature Malleability: (#1622)
* Transaction Malleability:
If you allow for both values 0/1 and 27/28, you allow two different
signatures both resulting in a same valid recovery. (r,s,0/1) and
(r,s,27/28) would both be valid, recover the same public key and sign
the same data. Furthermore, given (r,s,0/1), (r,s,27/28) can be
constructed by anyone.
* Transaction Malleability:
EIP-2 still allows signature malleabality for ecrecover(), remove this
possibility and force the signature to be unique.
* Added a reference to appendix F to the yellow paper and improved
comment.
* better test description for testing the version 0, which returns
a zero address
* Check that the conversion from 0/1 to 27/28 only happens if its 0/1
* improved formatting
* Refactor ECDSA code a bit.
* Refactor ECDSA tests a bit.
* Add changelog entry.
* Add high-s check test.
6 years ago
|
|
|
function fixSignature (signature) {
|
|
|
|
// in geth its always 27/28, in ganache its 0/1. Change to 27/28 to prevent
|
|
|
|
// signature malleability if version is 0/1
|
|
|
|
// see https://github.com/ethereum/go-ethereum/blob/v1.8.23/internal/ethapi/api.go#L465
|
|
|
|
let v = parseInt(signature.slice(130, 132), 16);
|
|
|
|
if (v < 27) {
|
|
|
|
v += 27;
|
|
|
|
}
|
|
|
|
const vHex = v.toString(16);
|
|
|
|
return signature.slice(0, 130) + vHex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// signs message in node (ganache auto-applies "Ethereum Signed Message" prefix)
|
Signature Malleability: (#1622)
* Transaction Malleability:
If you allow for both values 0/1 and 27/28, you allow two different
signatures both resulting in a same valid recovery. (r,s,0/1) and
(r,s,27/28) would both be valid, recover the same public key and sign
the same data. Furthermore, given (r,s,0/1), (r,s,27/28) can be
constructed by anyone.
* Transaction Malleability:
EIP-2 still allows signature malleabality for ecrecover(), remove this
possibility and force the signature to be unique.
* Added a reference to appendix F to the yellow paper and improved
comment.
* better test description for testing the version 0, which returns
a zero address
* Check that the conversion from 0/1 to 27/28 only happens if its 0/1
* improved formatting
* Refactor ECDSA code a bit.
* Refactor ECDSA tests a bit.
* Add changelog entry.
* Add high-s check test.
6 years ago
|
|
|
async function signMessage (signer, messageHex = '0x') {
|
|
|
|
return fixSignature(await web3.eth.sign(messageHex, signer));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a signer between a contract and a signer for a voucher of method, args, and redeemer
|
|
|
|
* Note that `method` is the web3 method, not the truffle-contract method
|
|
|
|
* @param contract TruffleContract
|
|
|
|
* @param signer address
|
|
|
|
* @param redeemer address
|
|
|
|
* @param methodName string
|
|
|
|
* @param methodArgs any[]
|
|
|
|
*/
|
RBAC and Ownable migration towards Roles (#1291)
* Role tests (#1228)
* Moved RBAC tests to access.
* Added Roles.addMany and tests.
* Fixed linter error.
* Now using uint256 indexes.
* Removed RBAC tokens (#1229)
* Deleted RBACCappedTokenMock.
* Removed RBACMintableToken.
* Removed RBACMintableToken from the MintedCrowdsale tests.
* Roles can now be transfered. (#1235)
* Roles can now be transfered.
* Now explicitly checking support for the null address.
* Now rejecting transfer to a role-haver.
* Added renounce, roles can no longer be transfered to 0.
* Fixed linter errors.
* Fixed a Roles test.
* True Ownership (#1247)
* Added barebones Secondary.
* Added transferPrimary
* Escrow is now Secondary instead of Ownable.
* Now reverting on transfers to 0.
* The Secondary's primary is now private.
* MintableToken using Roles (#1236)
* Minor test style improvements (#1219)
* Changed .eq to .equal
* Changed equal(bool) to .to.be.bool
* Changed be.bool to equal(bool), disallowed unused expressions.
* Add ERC165Query library (#1086)
* Add ERC165Query library
* Address PR Comments
* Add tests and mocks from #1024 and refactor code slightly
* Fix javascript and solidity linting errors
* Split supportsInterface into three methods as discussed in #1086
* Change InterfaceId_ERC165 comment to match style in the rest of the repo
* Fix max-len lint issue on ERC165Checker.sol
* Conditionally ignore the asserts during solidity-coverage test
* Switch to abi.encodeWithSelector and add test for account addresses
* Switch to supportsInterfaces API as suggested by @frangio
* Adding ERC165InterfacesSupported.sol
* Fix style issues
* Add test for supportsInterfaces returning false
* Add ERC165Checker.sol newline
* feat: fix coverage implementation
* fix: solidity linting error
* fix: revert to using boolean tests instead of require statements
* fix: make supportsERC165Interface private again
* rename SupportsInterfaceWithLookupMock to avoid name clashing
* Added mint and burn tests for zero amounts. (#1230)
* Changed .eq to .equal. (#1231)
* ERC721 pausable token (#1154)
* ERC721 pausable token
* Reuse of ERC721 Basic behavior for Pausable, split view checks in paused state & style fixes
* [~] paused token behavior
* Add some detail to releasing steps (#1190)
* add note about pulling upstream changes to release branch
* add comment about upstream changes in merging section
* Increase test coverage (#1237)
* Fixed a SplitPayment test
* Deleted unnecessary function.
* Improved PostDeliveryCrowdsale tests.
* Improved RefundableCrowdsale tests.
* Improved MintedCrowdsale tests.
* Improved IncreasingPriceCrowdsale tests.
* Fixed a CappedCrowdsale test.
* Improved TimedCrowdsale tests.
* Improved descriptions of added tests.
* ci: trigger docs update on tag (#1186)
* MintableToken now uses Roles.
* Fixed FinalizableCrowdsale test.
* Roles can now be transfered.
* Fixed tests related to MintableToken.
* Removed Roles.check.
* Renamed transferMintPermission.
* Moved MinterRole
* Fixed RBAC.
* Adressed review comments.
* Addressed review comments
* Fixed linter errors.
* Added Events tests of Pausable contract (#1207)
* Fixed roles tests.
* Rename events to past-tense (#1181)
* fix: refactor sign.js and related tests (#1243)
* fix: refactor sign.js and related tests
* fix: remove unused dep
* fix: update package.json correctly
* Added "_" sufix to internal variables (#1171)
* Added PublicRole test.
* Fixed crowdsale tests.
* Rename ERC interfaces to I prefix (#1252)
* rename ERC20 to IERC20
* move ERC20.sol to IERC20.sol
* rename StandardToken to ERC20
* rename StandardTokenMock to ERC20Mock
* move StandardToken.sol to ERC20.sol, likewise test and mock files
* rename MintableToken to ERC20Mintable
* move MintableToken.sol to ERC20Mintable.sol, likewise test and mock files
* rename BurnableToken to ERC20Burnable
* move BurnableToken.sol to ERC20Burnable.sol, likewise for related files
* rename CappedToken to ERC20Capped
* move CappedToken.sol to ERC20Capped.sol, likewise for related files
* rename PausableToken to ERC20Pausable
* move PausableToken.sol to ERC20Pausable.sol, likewise for related files
* rename DetailedERC20 to ERC20Detailed
* move DetailedERC20.sol to ERC20Detailed.sol, likewise for related files
* rename ERC721 to IERC721, and likewise for other related interfaces
* move ERC721.sol to IERC721.sol, likewise for other 721 interfaces
* rename ERC721Token to ERC721
* move ERC721Token.sol to ERC721.sol, likewise for related files
* rename ERC721BasicToken to ERC721Basic
* move ERC721BasicToken.sol to ERC721Basic.sol, likewise for related files
* rename ERC721PausableToken to ERC721Pausable
* move ERC721PausableToken.sol to ERC721Pausable.sol
* rename ERC165 to IERC165
* move ERC165.sol to IERC165.sol
* amend comment that ERC20 is based on FirstBlood
* fix comments mentioning IERC721Receiver
* added explicit visibility (#1261)
* Remove underscores from event parameters. (#1258)
* Remove underscores from event parameters.
Fixes #1175
* Add comment about ERC
* Move contracts to subdirectories (#1253)
* Move contracts to subdirectories
Fixes #1177.
This Change also removes the LimitBalance contract.
* fix import
* move MerkleProof to cryptography
* Fix import
* Remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner (#1254)
* remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner
* remove unused ERC223TokenMock
* remove Contactable
* remove TokenDestructible
* remove DeprecatedERC721
* inline Destructible#destroy in Bounty
* remove Destructible
* Functions in interfaces changed to "external" (#1263)
* Add a leading underscore to internal and private functions. (#1257)
* Add a leading underscore to internal and private functions.
Fixes #1176
* Remove super
* update the ERC721 changes
* add missing underscore after merge
* Fix mock
* Improve encapsulation on SignatureBouncer, Whitelist and RBAC example (#1265)
* Improve encapsulation on Whitelist
* remove only
* update whitelisted crowdsale test
* Improve encapsulation on SignatureBouncer
* fix missing test
* Improve encapsulation on RBAC example
* Improve encapsulation on RBAC example
* Remove extra visibility
* Improve encapsulation on ERC20 Mintable
* Improve encapsulation on Superuser
* fix lint
* add missing constant
* Addressed review comments.
* Fixed build error.
* Improved Roles API. (#1280)
* Improved Roles API.
* fix linter error
* Added PauserRole. (#1283)
* Remove Claimable, DelayedClaimable, Heritable (#1274)
* remove Claimable, DelayedClaimable, Heritable
* remove SimpleSavingsWallet example which used Heritable
(cherry picked from commit 0dc711732a297e70af63f23a9b52e4b3712eac40)
* Role behavior tests (#1285)
* Added role tests.
* Added PauserRole tests to contracts that have that role.
* Added MinterRole tests to contracts that have that role.
* Fixed linter errors.
* Migrate Ownable to Roles (#1287)
* Added CapperRole.
* RefundEscrow is now Secondary.
* FinalizableCrowdsale is no longer Ownable.
* Removed Whitelist and WhitelistedCrowdsale, redesign needed.
* Fixed linter errors, disabled lbrace due to it being buggy.
* Remove RBAC, SignatureBouncer refactor (#1289)
* Added CapperRole.
* RefundEscrow is now Secondary.
* FinalizableCrowdsale is no longer Ownable.
* Removed Whitelist and WhitelistedCrowdsale, redesign needed.
* Fixed linter errors, disabled lbrace due to it being buggy.
* Moved SignatureBouncer tests.
* Deleted RBAC and Superuser.
* Deleted rbac directory.
* Updated readme.
* SignatureBouncer now uses SignerRole, renamed bouncer to signer.
* feat: implement ERC721Mintable and ERC721Burnable (#1276)
* feat: implement ERC721Mintable and ERC721Burnable
* fix: linting errors
* fix: remove unused mintable mock for ERC721BasicMock
* fix: add finishMinting tests
* fix: catch MintFinished typo
* inline ERC721Full behavior
* undo pretty formatting
* fix lint errors
* rename canMint to onlyBeforeMintingFinished for consistency with ERC20Mintable
* Fix the merge with the privatization branch
* remove duplicate CapperRole test
6 years ago
|
|
|
const getSignFor = (contract, signer) => (redeemer, methodName, methodArgs = []) => {
|
|
|
|
const parts = [
|
|
|
|
contract.address,
|
|
|
|
redeemer,
|
|
|
|
];
|
|
|
|
|
|
|
|
const REAL_SIGNATURE_SIZE = 2 * 65; // 65 bytes in hexadecimal string length
|
|
|
|
const PADDED_SIGNATURE_SIZE = 2 * 96; // 96 bytes in hexadecimal string length
|
|
|
|
const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
|
|
|
|
|
|
|
|
// if we have a method, add it to the parts that we're signing
|
|
|
|
if (methodName) {
|
|
|
|
if (methodArgs.length > 0) {
|
|
|
|
parts.push(
|
|
|
|
contract.contract.methods[methodName](...methodArgs.concat([DUMMY_SIGNATURE])).encodeABI()
|
|
|
|
.slice(0, -1 * PADDED_SIGNATURE_SIZE)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
const abi = contract.abi.find(abi => abi.name === methodName);
|
|
|
|
parts.push(abi.signature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the signature of the "Ethereum Signed Message" hash of the hash of `parts`
|
|
|
|
const messageHex = web3.utils.soliditySha3(...parts);
|
|
|
|
return signMessage(signer, messageHex);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
signMessage,
|
|
|
|
toEthSignedMessageHash,
|
Signature Malleability: (#1622)
* Transaction Malleability:
If you allow for both values 0/1 and 27/28, you allow two different
signatures both resulting in a same valid recovery. (r,s,0/1) and
(r,s,27/28) would both be valid, recover the same public key and sign
the same data. Furthermore, given (r,s,0/1), (r,s,27/28) can be
constructed by anyone.
* Transaction Malleability:
EIP-2 still allows signature malleabality for ecrecover(), remove this
possibility and force the signature to be unique.
* Added a reference to appendix F to the yellow paper and improved
comment.
* better test description for testing the version 0, which returns
a zero address
* Check that the conversion from 0/1 to 27/28 only happens if its 0/1
* improved formatting
* Refactor ECDSA code a bit.
* Refactor ECDSA tests a bit.
* Add changelog entry.
* Add high-s check test.
6 years ago
|
|
|
fixSignature,
|
RBAC and Ownable migration towards Roles (#1291)
* Role tests (#1228)
* Moved RBAC tests to access.
* Added Roles.addMany and tests.
* Fixed linter error.
* Now using uint256 indexes.
* Removed RBAC tokens (#1229)
* Deleted RBACCappedTokenMock.
* Removed RBACMintableToken.
* Removed RBACMintableToken from the MintedCrowdsale tests.
* Roles can now be transfered. (#1235)
* Roles can now be transfered.
* Now explicitly checking support for the null address.
* Now rejecting transfer to a role-haver.
* Added renounce, roles can no longer be transfered to 0.
* Fixed linter errors.
* Fixed a Roles test.
* True Ownership (#1247)
* Added barebones Secondary.
* Added transferPrimary
* Escrow is now Secondary instead of Ownable.
* Now reverting on transfers to 0.
* The Secondary's primary is now private.
* MintableToken using Roles (#1236)
* Minor test style improvements (#1219)
* Changed .eq to .equal
* Changed equal(bool) to .to.be.bool
* Changed be.bool to equal(bool), disallowed unused expressions.
* Add ERC165Query library (#1086)
* Add ERC165Query library
* Address PR Comments
* Add tests and mocks from #1024 and refactor code slightly
* Fix javascript and solidity linting errors
* Split supportsInterface into three methods as discussed in #1086
* Change InterfaceId_ERC165 comment to match style in the rest of the repo
* Fix max-len lint issue on ERC165Checker.sol
* Conditionally ignore the asserts during solidity-coverage test
* Switch to abi.encodeWithSelector and add test for account addresses
* Switch to supportsInterfaces API as suggested by @frangio
* Adding ERC165InterfacesSupported.sol
* Fix style issues
* Add test for supportsInterfaces returning false
* Add ERC165Checker.sol newline
* feat: fix coverage implementation
* fix: solidity linting error
* fix: revert to using boolean tests instead of require statements
* fix: make supportsERC165Interface private again
* rename SupportsInterfaceWithLookupMock to avoid name clashing
* Added mint and burn tests for zero amounts. (#1230)
* Changed .eq to .equal. (#1231)
* ERC721 pausable token (#1154)
* ERC721 pausable token
* Reuse of ERC721 Basic behavior for Pausable, split view checks in paused state & style fixes
* [~] paused token behavior
* Add some detail to releasing steps (#1190)
* add note about pulling upstream changes to release branch
* add comment about upstream changes in merging section
* Increase test coverage (#1237)
* Fixed a SplitPayment test
* Deleted unnecessary function.
* Improved PostDeliveryCrowdsale tests.
* Improved RefundableCrowdsale tests.
* Improved MintedCrowdsale tests.
* Improved IncreasingPriceCrowdsale tests.
* Fixed a CappedCrowdsale test.
* Improved TimedCrowdsale tests.
* Improved descriptions of added tests.
* ci: trigger docs update on tag (#1186)
* MintableToken now uses Roles.
* Fixed FinalizableCrowdsale test.
* Roles can now be transfered.
* Fixed tests related to MintableToken.
* Removed Roles.check.
* Renamed transferMintPermission.
* Moved MinterRole
* Fixed RBAC.
* Adressed review comments.
* Addressed review comments
* Fixed linter errors.
* Added Events tests of Pausable contract (#1207)
* Fixed roles tests.
* Rename events to past-tense (#1181)
* fix: refactor sign.js and related tests (#1243)
* fix: refactor sign.js and related tests
* fix: remove unused dep
* fix: update package.json correctly
* Added "_" sufix to internal variables (#1171)
* Added PublicRole test.
* Fixed crowdsale tests.
* Rename ERC interfaces to I prefix (#1252)
* rename ERC20 to IERC20
* move ERC20.sol to IERC20.sol
* rename StandardToken to ERC20
* rename StandardTokenMock to ERC20Mock
* move StandardToken.sol to ERC20.sol, likewise test and mock files
* rename MintableToken to ERC20Mintable
* move MintableToken.sol to ERC20Mintable.sol, likewise test and mock files
* rename BurnableToken to ERC20Burnable
* move BurnableToken.sol to ERC20Burnable.sol, likewise for related files
* rename CappedToken to ERC20Capped
* move CappedToken.sol to ERC20Capped.sol, likewise for related files
* rename PausableToken to ERC20Pausable
* move PausableToken.sol to ERC20Pausable.sol, likewise for related files
* rename DetailedERC20 to ERC20Detailed
* move DetailedERC20.sol to ERC20Detailed.sol, likewise for related files
* rename ERC721 to IERC721, and likewise for other related interfaces
* move ERC721.sol to IERC721.sol, likewise for other 721 interfaces
* rename ERC721Token to ERC721
* move ERC721Token.sol to ERC721.sol, likewise for related files
* rename ERC721BasicToken to ERC721Basic
* move ERC721BasicToken.sol to ERC721Basic.sol, likewise for related files
* rename ERC721PausableToken to ERC721Pausable
* move ERC721PausableToken.sol to ERC721Pausable.sol
* rename ERC165 to IERC165
* move ERC165.sol to IERC165.sol
* amend comment that ERC20 is based on FirstBlood
* fix comments mentioning IERC721Receiver
* added explicit visibility (#1261)
* Remove underscores from event parameters. (#1258)
* Remove underscores from event parameters.
Fixes #1175
* Add comment about ERC
* Move contracts to subdirectories (#1253)
* Move contracts to subdirectories
Fixes #1177.
This Change also removes the LimitBalance contract.
* fix import
* move MerkleProof to cryptography
* Fix import
* Remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner (#1254)
* remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner
* remove unused ERC223TokenMock
* remove Contactable
* remove TokenDestructible
* remove DeprecatedERC721
* inline Destructible#destroy in Bounty
* remove Destructible
* Functions in interfaces changed to "external" (#1263)
* Add a leading underscore to internal and private functions. (#1257)
* Add a leading underscore to internal and private functions.
Fixes #1176
* Remove super
* update the ERC721 changes
* add missing underscore after merge
* Fix mock
* Improve encapsulation on SignatureBouncer, Whitelist and RBAC example (#1265)
* Improve encapsulation on Whitelist
* remove only
* update whitelisted crowdsale test
* Improve encapsulation on SignatureBouncer
* fix missing test
* Improve encapsulation on RBAC example
* Improve encapsulation on RBAC example
* Remove extra visibility
* Improve encapsulation on ERC20 Mintable
* Improve encapsulation on Superuser
* fix lint
* add missing constant
* Addressed review comments.
* Fixed build error.
* Improved Roles API. (#1280)
* Improved Roles API.
* fix linter error
* Added PauserRole. (#1283)
* Remove Claimable, DelayedClaimable, Heritable (#1274)
* remove Claimable, DelayedClaimable, Heritable
* remove SimpleSavingsWallet example which used Heritable
(cherry picked from commit 0dc711732a297e70af63f23a9b52e4b3712eac40)
* Role behavior tests (#1285)
* Added role tests.
* Added PauserRole tests to contracts that have that role.
* Added MinterRole tests to contracts that have that role.
* Fixed linter errors.
* Migrate Ownable to Roles (#1287)
* Added CapperRole.
* RefundEscrow is now Secondary.
* FinalizableCrowdsale is no longer Ownable.
* Removed Whitelist and WhitelistedCrowdsale, redesign needed.
* Fixed linter errors, disabled lbrace due to it being buggy.
* Remove RBAC, SignatureBouncer refactor (#1289)
* Added CapperRole.
* RefundEscrow is now Secondary.
* FinalizableCrowdsale is no longer Ownable.
* Removed Whitelist and WhitelistedCrowdsale, redesign needed.
* Fixed linter errors, disabled lbrace due to it being buggy.
* Moved SignatureBouncer tests.
* Deleted RBAC and Superuser.
* Deleted rbac directory.
* Updated readme.
* SignatureBouncer now uses SignerRole, renamed bouncer to signer.
* feat: implement ERC721Mintable and ERC721Burnable (#1276)
* feat: implement ERC721Mintable and ERC721Burnable
* fix: linting errors
* fix: remove unused mintable mock for ERC721BasicMock
* fix: add finishMinting tests
* fix: catch MintFinished typo
* inline ERC721Full behavior
* undo pretty formatting
* fix lint errors
* rename canMint to onlyBeforeMintingFinished for consistency with ERC20Mintable
* Fix the merge with the privatization branch
* remove duplicate CapperRole test
6 years ago
|
|
|
getSignFor,
|
|
|
|
};
|