From 9e3693af768015958c440bef31bf8977a801ec66 Mon Sep 17 00:00:00 2001 From: Christophe Le Bars Date: Tue, 18 Apr 2023 20:12:50 +0200 Subject: [PATCH] ethers6 lib migration --- lib/rouge.mjs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/rouge.mjs b/lib/rouge.mjs index 95d99eb..1ed7d77 100644 --- a/lib/rouge.mjs +++ b/lib/rouge.mjs @@ -20,36 +20,35 @@ export const setLogger = logger => { void({ fatal, error, warn, info, debug, trace } = logger) } - // TODO lookup for contracts... export const NFT_LIMIT = 281474976710655 export const ALL_CHANNELS = 65535 export const tokens = { - 'ETH': ethers.AddressZero, - 'USDC': ethers.AddressZero, + 'ETH': ethers.ZeroAddress, + 'USDC': ethers.ZeroAddress, } export const abiEncodeChannel = ({ supply = NFT_LIMIT, amount = '0', // uint256 - token = ethers.AddressZero, + token = ethers.ZeroAddress, free } = {}) => { if (free) { amount = '0' - token = ethers.AddressZero + token = ethers.ZeroAddress } if (amount instanceof TokenAmount) { - token = amount.token.address || ethers.AddressZero + token = amount.token.address || ethers.ZeroAddress amount = amount.valueOf() } else if (typeof token === 'object') { // old format to remove ... - token = token.address || ethers.AddressZero + token = token.address || ethers.ZeroAddress } return [ supply, 0, 0, token, amount ] @@ -60,7 +59,7 @@ export const abiEncodeChannel = ({ // { scope: 'acquire', hasRole: [ /*addresses_lists*/ ] } export const abiEncodeAuth = ({ iface, - address = ethers.AddressZero, + address = ethers.ZeroAddress, scope, channels = [ ALL_CHANNELS ], grant = true @@ -68,14 +67,14 @@ export const abiEncodeAuth = ({ return [ address, - /^0x/.test(scope) ? scope : iface.getSighash(scope), + /^0x/.test(scope) ? scope : iface.getFunction(scope).selector, channels, grant ] } -export const getStamp = proof => ethers.keccak256(ethers.solidityPack(['bytes32'],[proof])).slice(0,34) +export const getStamp = proof => ethers.keccak256(ethers.solidityPacked(['bytes32'],[proof])).slice(0,34) // Make Class with asXXX as Qr stamp etc handler @@ -99,7 +98,7 @@ export const calculateStampProof = async ({ contract, signer, secret, tokenId, c export const encodeAnnotatedProof = ({ contract, bearer, tokenId, proof }) => { trace('[encodeAnnotatedProofShort]', { contract, bearer, tokenId, proof }) // length is 6 + 20 + 20 + 32 = 78 bytes - const packed = ethers.solidityPack( + const packed = ethers.solidityPacked( [ 'uint48', 'address', 'address', 'bytes32' ], [ tokenId, contract, bearer, proof ] ).slice(2).replace(/^(00)+/,'') const b64 = Buffer.from(packed, 'hex').toString('base64') @@ -115,10 +114,10 @@ export const decodeAnnotatedProof = data => { } export const encodeAnnotatedCertificate = ({ contract, bearer, tokenId, signature, selector = '0x0', expire = 0}) => { - const { r, s, v } = ethers.splitSignature(signature) + const { r, s, v } = ethers.Signature.from(signature) trace('[encodeAnnotatedCertificate]', { contract, bearer, tokenId, signature, selector, expire }) // length is 6 + 20 + 20 + 4 + 4 + 1 + 32 + 32 = 119 bytes - const packed = ethers.solidityPack( + const packed = ethers.solidityPacked( [ 'uint48', 'address', 'address', 'uint32', 'bytes4', 'uint8', 'bytes32', 'bytes32' ], [ tokenId, contract, bearer, expire, selector, v, r, s ] ).slice(2).replace(/^(00)+/,'') const b64 = Buffer.from(packed, 'hex').toString('base64') @@ -221,14 +220,14 @@ export const generateCertificate = async ({ } export const abiEncodeCertificate = ({ from, tokenId, selector, expire, signature, r, s, v } = {}) => { - if (!signature && !r) return [ ethers.AddressZero, 0, [ '0x00000000', 0 ], ethers.HashZero, ethers.HashZero, 27 ] - if (signature && !r) void({ r, s, v } = ethers.splitSignature(signature)) + if (!signature && !r) return [ ethers.ZeroAddress, 0, [ '0x00000000', 0 ], ethers.ZeroHash, ethers.ZeroHash, 27 ] + if (signature && !r) void({ r, s, v } = ethers.Signature.from(signature)) return [ from, tokenId, [ selector, expire ], r, s, v ] } export const decodeRoles = async (contract, selectors, account, channels) => { const raw = await contract.getRoles( - selectors.map(s => contract.interface.getSighash(s)), + selectors.map(s => contract.interface.getFunction(s).selector, account ) return raw.map(c => {