@0xsequence/account
Advanced tools
Comparing version 0.0.0-20240820154443 to 0.0.0-20240820173337
@@ -28,16 +28,5 @@ 'use strict'; | ||
function isPromise(value) { | ||
return !!value && typeof value.then === 'function'; | ||
} | ||
function isDeferrable(value) { | ||
// The value is deferrable if any of the properties is a Promises | ||
if (typeof value === 'object') { | ||
return Object.keys(value).some(key => isPromise(value[key])); | ||
} | ||
return false; | ||
} | ||
function encodeGasRefundTransaction(option) { | ||
if (!option) return []; | ||
const value = ethers.ethers.BigNumber.from(option.value); | ||
const value = BigInt(option.value); | ||
switch (option.token.type) { | ||
@@ -50,4 +39,4 @@ case relayer.proto.FeeTokenType.UNKNOWN: | ||
to: option.to, | ||
value: value.toHexString(), | ||
data: [] | ||
value: utils.toHexString(value), | ||
data: '0x' | ||
}]; | ||
@@ -64,3 +53,3 @@ case relayer.proto.FeeTokenType.ERC20_TOKEN: | ||
value: 0, | ||
data: new ethers.ethers.utils.Interface([{ | ||
data: new ethers.ethers.Interface([{ | ||
constant: false, | ||
@@ -75,3 +64,3 @@ inputs: [{ | ||
type: 'function' | ||
}]).encodeFunctionData('transfer', [option.to, value.toHexString()]) | ||
}]).encodeFunctionData('transfer', [option.to, utils.toHexString(value)]) | ||
}]; | ||
@@ -87,3 +76,2 @@ default: | ||
this.options = options; | ||
this._isSigner = true; | ||
} | ||
@@ -100,2 +88,6 @@ get provider() { | ||
} | ||
signTypedData(domain, types, value) { | ||
var _this$options$cantVal2, _this$options2; | ||
return this.account.signTypedData(domain, types, value, this.chainId, (_this$options$cantVal2 = (_this$options2 = this.options) == null ? void 0 : _this$options2.cantValidateBehavior) != null ? _this$options$cantVal2 : 'throw'); | ||
} | ||
async defaultSelectFee(_txs, options) { | ||
@@ -122,3 +114,3 @@ // If no options, return undefined | ||
const balance = await this.getBalance(); | ||
if (balance.gte(ethers.ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -130,3 +122,3 @@ } | ||
const balance = await token.balanceOf(this.account.address); | ||
if (balance.gte(ethers.ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -138,15 +130,14 @@ } | ||
} | ||
async sendTransaction(txsPromise, options) { | ||
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4; | ||
const txs = isDeferrable(txsPromise) ? await ethers.ethers.utils.resolveProperties(txsPromise) : txsPromise; | ||
async sendTransaction(txs, options) { | ||
var _this$options$stubSig, _this$options3, _this$options$selectF, _this$options4, _this$options5; | ||
const prepare = await this.account.prepareTransactions({ | ||
txs, | ||
chainId: this.chainId, | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options2 = this.options) == null ? void 0 : _this$options2.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options3 = this.options) == null ? void 0 : _this$options3.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
simulateForFeeOptions: options == null ? void 0 : options.simulateForFeeOptions | ||
}); | ||
const selectMethod = (_this$options$selectF = (_this$options3 = this.options) == null ? void 0 : _this$options3.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const selectMethod = (_this$options$selectF = (_this$options4 = this.options) == null ? void 0 : _this$options4.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const feeOption = await selectMethod(txs, prepare.feeOptions); | ||
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)]; | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options4 = this.options) == null ? void 0 : _this$options4.nonceSpace) !== undefined ? { | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options5 = this.options) == null ? void 0 : _this$options5.nonceSpace) !== undefined ? { | ||
nonceSpace: this.options.nonceSpace | ||
@@ -159,3 +150,5 @@ } : undefined); // Will always have a transaction response | ||
call(transaction, blockTag) { | ||
return this.provider.call(transaction, blockTag); | ||
return this.provider.call(_extends({}, transaction, { | ||
blockTag | ||
})); | ||
} | ||
@@ -180,3 +173,3 @@ async resolveName(name) { | ||
getChainId() { | ||
return Promise.resolve(ethers.ethers.BigNumber.from(this.chainId).toNumber()); | ||
return Promise.resolve(Number(this.chainId)); | ||
} | ||
@@ -189,6 +182,12 @@ getGasPrice() { | ||
} | ||
getNonce(blockTag) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateCall(tx) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
checkTransaction(transaction) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateTransaction(transaction) { | ||
async populateTransaction(tx) { | ||
throw new Error('Method not implemented.'); | ||
@@ -212,3 +211,3 @@ } | ||
async nonce(_wallet, _space) { | ||
return ethers.ethers.constants.Zero; | ||
return 0n; | ||
} | ||
@@ -230,3 +229,3 @@ async isValidSignature(_wallet, _digest, _signature) { | ||
this.projectAccessKey = void 0; | ||
this.address = ethers.ethers.utils.getAddress(options.address); | ||
this.address = ethers.ethers.getAddress(options.address); | ||
this.contexts = options.contexts; | ||
@@ -281,4 +280,4 @@ this.tracker = options.tracker; | ||
network(chainId) { | ||
const tcid = ethers.ethers.BigNumber.from(chainId); | ||
const found = this.networks.find(n => tcid.eq(n.chainId)); | ||
const tcid = BigInt(chainId); | ||
const found = this.networks.find(n => tcid === BigInt(n.chainId)); | ||
if (!found) throw new Error(`Network not found for chainId ${chainId}`); | ||
@@ -289,10 +288,14 @@ return found; | ||
const found = this.network(chainId); | ||
if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`); | ||
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(utils.getEthersConnectionInfo(found.rpcUrl, this.projectAccessKey, this.jwt), { | ||
name: '', | ||
chainId: ethers.ethers.BigNumber.from(chainId).toNumber() | ||
if (!found.provider && !found.rpcUrl) { | ||
throw new Error(`Provider not found for chainId ${chainId}`); | ||
} | ||
const network = new ethers.ethers.Network(found.name, found.chainId); | ||
return found.provider || new ethers.ethers.JsonRpcProvider(utils.getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, { | ||
staticNetwork: network | ||
}); | ||
} | ||
reader(chainId) { | ||
if (ethers.ethers.constants.Zero.eq(chainId)) return new Chain0Reader(); | ||
if (BigInt(chainId) === 0n) { | ||
return new Chain0Reader(); | ||
} | ||
@@ -329,3 +332,3 @@ // TODO: Networks should be able to provide a reader directly | ||
walletFor(chainId, context, config, coders) { | ||
const isNetworkZero = ethers.ethers.constants.Zero.eq(chainId); | ||
const isNetworkZero = BigInt(chainId) === 0n; | ||
return new wallet.Wallet({ | ||
@@ -532,3 +535,3 @@ config, | ||
async publishWitness() { | ||
const digest = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(`This is a Sequence account woo! ${Date.now()}`)); | ||
const digest = ethers.ethers.id(`This is a Sequence account woo! ${Date.now()}`); | ||
const signature = await this.signDigest(digest, 0, false); | ||
@@ -551,3 +554,3 @@ const decoded = this.coders.signature.decode(signature); | ||
// the behaviour of being migrated on all chains | ||
const chainRef = ethers.ethers.constants.Zero.eq(chainId) ? this.networks[0].chainId : chainId; | ||
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId; | ||
const status = await this.status(chainRef); | ||
@@ -583,7 +586,7 @@ this.mustBeFullyMigrated(status); | ||
const subdigest = core.commons.signature.subdigestOf({ | ||
digest: ethers.ethers.utils.hexlify(digest), | ||
digest: ethers.ethers.hexlify(digest), | ||
chainId: 0, | ||
address: this.address | ||
}); | ||
const hexSubdigest = ethers.ethers.utils.hexlify(subdigest); | ||
const hexSubdigest = ethers.ethers.hexlify(subdigest); | ||
const config = this.coders.config.fromSimple({ | ||
@@ -597,3 +600,3 @@ // Threshold *only* needs to be > 0, this is not a magic number | ||
}); | ||
const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi); | ||
const walletInterface = new ethers.ethers.Interface(abi.walletContracts.mainModule.abi); | ||
const bundle = { | ||
@@ -633,4 +636,4 @@ entrypoint: this.address, | ||
} | ||
const encoded = ethers.ethers.utils.defaultAbiCoder.encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.ethers.utils.solidityPack(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]); | ||
const encoded = ethers.ethers.AbiCoder.defaultAbiCoder().encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.ethers.solidityPacked(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]); | ||
} | ||
@@ -640,3 +643,3 @@ async editConfig(changes) { | ||
const newConfig = this.coders.config.editConfig(currentConfig, _extends({}, changes, { | ||
checkpoint: this.coders.config.checkpointOf(currentConfig).add(1) | ||
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n | ||
})); | ||
@@ -701,3 +704,2 @@ return this.updateConfig(newConfig); | ||
} | ||
transactions.length; | ||
@@ -746,3 +748,3 @@ // Get pending migrations | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -873,3 +875,3 @@ async signTransactions(txs, chainId, pstatus, options) { | ||
// Now we can decorate the transactions as always, but we need to manually build the signed bundle | ||
const intentId = ethers.ethers.utils.hexlify(ethers.ethers.utils.randomBytes(32)); | ||
const intentId = ethers.ethers.hexlify(ethers.ethers.randomBytes(32)); | ||
const signedBundle = { | ||
@@ -876,0 +878,0 @@ chainId, |
@@ -28,16 +28,5 @@ 'use strict'; | ||
function isPromise(value) { | ||
return !!value && typeof value.then === 'function'; | ||
} | ||
function isDeferrable(value) { | ||
// The value is deferrable if any of the properties is a Promises | ||
if (typeof value === 'object') { | ||
return Object.keys(value).some(key => isPromise(value[key])); | ||
} | ||
return false; | ||
} | ||
function encodeGasRefundTransaction(option) { | ||
if (!option) return []; | ||
const value = ethers.ethers.BigNumber.from(option.value); | ||
const value = BigInt(option.value); | ||
switch (option.token.type) { | ||
@@ -50,4 +39,4 @@ case relayer.proto.FeeTokenType.UNKNOWN: | ||
to: option.to, | ||
value: value.toHexString(), | ||
data: [] | ||
value: utils.toHexString(value), | ||
data: '0x' | ||
}]; | ||
@@ -64,3 +53,3 @@ case relayer.proto.FeeTokenType.ERC20_TOKEN: | ||
value: 0, | ||
data: new ethers.ethers.utils.Interface([{ | ||
data: new ethers.ethers.Interface([{ | ||
constant: false, | ||
@@ -75,3 +64,3 @@ inputs: [{ | ||
type: 'function' | ||
}]).encodeFunctionData('transfer', [option.to, value.toHexString()]) | ||
}]).encodeFunctionData('transfer', [option.to, utils.toHexString(value)]) | ||
}]; | ||
@@ -87,3 +76,2 @@ default: | ||
this.options = options; | ||
this._isSigner = true; | ||
} | ||
@@ -100,2 +88,6 @@ get provider() { | ||
} | ||
signTypedData(domain, types, value) { | ||
var _this$options$cantVal2, _this$options2; | ||
return this.account.signTypedData(domain, types, value, this.chainId, (_this$options$cantVal2 = (_this$options2 = this.options) == null ? void 0 : _this$options2.cantValidateBehavior) != null ? _this$options$cantVal2 : 'throw'); | ||
} | ||
async defaultSelectFee(_txs, options) { | ||
@@ -122,3 +114,3 @@ // If no options, return undefined | ||
const balance = await this.getBalance(); | ||
if (balance.gte(ethers.ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -130,3 +122,3 @@ } | ||
const balance = await token.balanceOf(this.account.address); | ||
if (balance.gte(ethers.ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -138,15 +130,14 @@ } | ||
} | ||
async sendTransaction(txsPromise, options) { | ||
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4; | ||
const txs = isDeferrable(txsPromise) ? await ethers.ethers.utils.resolveProperties(txsPromise) : txsPromise; | ||
async sendTransaction(txs, options) { | ||
var _this$options$stubSig, _this$options3, _this$options$selectF, _this$options4, _this$options5; | ||
const prepare = await this.account.prepareTransactions({ | ||
txs, | ||
chainId: this.chainId, | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options2 = this.options) == null ? void 0 : _this$options2.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options3 = this.options) == null ? void 0 : _this$options3.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
simulateForFeeOptions: options == null ? void 0 : options.simulateForFeeOptions | ||
}); | ||
const selectMethod = (_this$options$selectF = (_this$options3 = this.options) == null ? void 0 : _this$options3.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const selectMethod = (_this$options$selectF = (_this$options4 = this.options) == null ? void 0 : _this$options4.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const feeOption = await selectMethod(txs, prepare.feeOptions); | ||
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)]; | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options4 = this.options) == null ? void 0 : _this$options4.nonceSpace) !== undefined ? { | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options5 = this.options) == null ? void 0 : _this$options5.nonceSpace) !== undefined ? { | ||
nonceSpace: this.options.nonceSpace | ||
@@ -159,3 +150,5 @@ } : undefined); // Will always have a transaction response | ||
call(transaction, blockTag) { | ||
return this.provider.call(transaction, blockTag); | ||
return this.provider.call(_extends({}, transaction, { | ||
blockTag | ||
})); | ||
} | ||
@@ -180,3 +173,3 @@ async resolveName(name) { | ||
getChainId() { | ||
return Promise.resolve(ethers.ethers.BigNumber.from(this.chainId).toNumber()); | ||
return Promise.resolve(Number(this.chainId)); | ||
} | ||
@@ -189,6 +182,12 @@ getGasPrice() { | ||
} | ||
getNonce(blockTag) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateCall(tx) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
checkTransaction(transaction) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateTransaction(transaction) { | ||
async populateTransaction(tx) { | ||
throw new Error('Method not implemented.'); | ||
@@ -212,3 +211,3 @@ } | ||
async nonce(_wallet, _space) { | ||
return ethers.ethers.constants.Zero; | ||
return 0n; | ||
} | ||
@@ -230,3 +229,3 @@ async isValidSignature(_wallet, _digest, _signature) { | ||
this.projectAccessKey = void 0; | ||
this.address = ethers.ethers.utils.getAddress(options.address); | ||
this.address = ethers.ethers.getAddress(options.address); | ||
this.contexts = options.contexts; | ||
@@ -281,4 +280,4 @@ this.tracker = options.tracker; | ||
network(chainId) { | ||
const tcid = ethers.ethers.BigNumber.from(chainId); | ||
const found = this.networks.find(n => tcid.eq(n.chainId)); | ||
const tcid = BigInt(chainId); | ||
const found = this.networks.find(n => tcid === BigInt(n.chainId)); | ||
if (!found) throw new Error(`Network not found for chainId ${chainId}`); | ||
@@ -289,10 +288,14 @@ return found; | ||
const found = this.network(chainId); | ||
if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`); | ||
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(utils.getEthersConnectionInfo(found.rpcUrl, this.projectAccessKey, this.jwt), { | ||
name: '', | ||
chainId: ethers.ethers.BigNumber.from(chainId).toNumber() | ||
if (!found.provider && !found.rpcUrl) { | ||
throw new Error(`Provider not found for chainId ${chainId}`); | ||
} | ||
const network = new ethers.ethers.Network(found.name, found.chainId); | ||
return found.provider || new ethers.ethers.JsonRpcProvider(utils.getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, { | ||
staticNetwork: network | ||
}); | ||
} | ||
reader(chainId) { | ||
if (ethers.ethers.constants.Zero.eq(chainId)) return new Chain0Reader(); | ||
if (BigInt(chainId) === 0n) { | ||
return new Chain0Reader(); | ||
} | ||
@@ -329,3 +332,3 @@ // TODO: Networks should be able to provide a reader directly | ||
walletFor(chainId, context, config, coders) { | ||
const isNetworkZero = ethers.ethers.constants.Zero.eq(chainId); | ||
const isNetworkZero = BigInt(chainId) === 0n; | ||
return new wallet.Wallet({ | ||
@@ -532,3 +535,3 @@ config, | ||
async publishWitness() { | ||
const digest = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(`This is a Sequence account woo! ${Date.now()}`)); | ||
const digest = ethers.ethers.id(`This is a Sequence account woo! ${Date.now()}`); | ||
const signature = await this.signDigest(digest, 0, false); | ||
@@ -551,3 +554,3 @@ const decoded = this.coders.signature.decode(signature); | ||
// the behaviour of being migrated on all chains | ||
const chainRef = ethers.ethers.constants.Zero.eq(chainId) ? this.networks[0].chainId : chainId; | ||
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId; | ||
const status = await this.status(chainRef); | ||
@@ -583,7 +586,7 @@ this.mustBeFullyMigrated(status); | ||
const subdigest = core.commons.signature.subdigestOf({ | ||
digest: ethers.ethers.utils.hexlify(digest), | ||
digest: ethers.ethers.hexlify(digest), | ||
chainId: 0, | ||
address: this.address | ||
}); | ||
const hexSubdigest = ethers.ethers.utils.hexlify(subdigest); | ||
const hexSubdigest = ethers.ethers.hexlify(subdigest); | ||
const config = this.coders.config.fromSimple({ | ||
@@ -597,3 +600,3 @@ // Threshold *only* needs to be > 0, this is not a magic number | ||
}); | ||
const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi); | ||
const walletInterface = new ethers.ethers.Interface(abi.walletContracts.mainModule.abi); | ||
const bundle = { | ||
@@ -633,4 +636,4 @@ entrypoint: this.address, | ||
} | ||
const encoded = ethers.ethers.utils.defaultAbiCoder.encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.ethers.utils.solidityPack(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]); | ||
const encoded = ethers.ethers.AbiCoder.defaultAbiCoder().encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.ethers.solidityPacked(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]); | ||
} | ||
@@ -640,3 +643,3 @@ async editConfig(changes) { | ||
const newConfig = this.coders.config.editConfig(currentConfig, _extends({}, changes, { | ||
checkpoint: this.coders.config.checkpointOf(currentConfig).add(1) | ||
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n | ||
})); | ||
@@ -701,3 +704,2 @@ return this.updateConfig(newConfig); | ||
} | ||
transactions.length; | ||
@@ -746,3 +748,3 @@ // Get pending migrations | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -873,3 +875,3 @@ async signTransactions(txs, chainId, pstatus, options) { | ||
// Now we can decorate the transactions as always, but we need to manually build the signed bundle | ||
const intentId = ethers.ethers.utils.hexlify(ethers.ethers.utils.randomBytes(32)); | ||
const intentId = ethers.ethers.hexlify(ethers.ethers.randomBytes(32)); | ||
const signedBundle = { | ||
@@ -876,0 +878,0 @@ chainId, |
@@ -5,3 +5,3 @@ import { walletContracts } from '@0xsequence/abi'; | ||
import { proto, isRelayer, RpcRelayer } from '@0xsequence/relayer'; | ||
import { getEthersConnectionInfo, encodeTypedDataDigest } from '@0xsequence/utils'; | ||
import { toHexString, getFetchRequest, encodeTypedDataDigest } from '@0xsequence/utils'; | ||
import { Wallet } from '@0xsequence/wallet'; | ||
@@ -25,16 +25,5 @@ import { ethers } from 'ethers'; | ||
function isPromise(value) { | ||
return !!value && typeof value.then === 'function'; | ||
} | ||
function isDeferrable(value) { | ||
// The value is deferrable if any of the properties is a Promises | ||
if (typeof value === 'object') { | ||
return Object.keys(value).some(key => isPromise(value[key])); | ||
} | ||
return false; | ||
} | ||
function encodeGasRefundTransaction(option) { | ||
if (!option) return []; | ||
const value = ethers.BigNumber.from(option.value); | ||
const value = BigInt(option.value); | ||
switch (option.token.type) { | ||
@@ -47,4 +36,4 @@ case proto.FeeTokenType.UNKNOWN: | ||
to: option.to, | ||
value: value.toHexString(), | ||
data: [] | ||
value: toHexString(value), | ||
data: '0x' | ||
}]; | ||
@@ -61,3 +50,3 @@ case proto.FeeTokenType.ERC20_TOKEN: | ||
value: 0, | ||
data: new ethers.utils.Interface([{ | ||
data: new ethers.Interface([{ | ||
constant: false, | ||
@@ -72,3 +61,3 @@ inputs: [{ | ||
type: 'function' | ||
}]).encodeFunctionData('transfer', [option.to, value.toHexString()]) | ||
}]).encodeFunctionData('transfer', [option.to, toHexString(value)]) | ||
}]; | ||
@@ -84,3 +73,2 @@ default: | ||
this.options = options; | ||
this._isSigner = true; | ||
} | ||
@@ -97,2 +85,6 @@ get provider() { | ||
} | ||
signTypedData(domain, types, value) { | ||
var _this$options$cantVal2, _this$options2; | ||
return this.account.signTypedData(domain, types, value, this.chainId, (_this$options$cantVal2 = (_this$options2 = this.options) == null ? void 0 : _this$options2.cantValidateBehavior) != null ? _this$options$cantVal2 : 'throw'); | ||
} | ||
async defaultSelectFee(_txs, options) { | ||
@@ -119,3 +111,3 @@ // If no options, return undefined | ||
const balance = await this.getBalance(); | ||
if (balance.gte(ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -127,3 +119,3 @@ } | ||
const balance = await token.balanceOf(this.account.address); | ||
if (balance.gte(ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option; | ||
@@ -135,15 +127,14 @@ } | ||
} | ||
async sendTransaction(txsPromise, options) { | ||
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4; | ||
const txs = isDeferrable(txsPromise) ? await ethers.utils.resolveProperties(txsPromise) : txsPromise; | ||
async sendTransaction(txs, options) { | ||
var _this$options$stubSig, _this$options3, _this$options$selectF, _this$options4, _this$options5; | ||
const prepare = await this.account.prepareTransactions({ | ||
txs, | ||
chainId: this.chainId, | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options2 = this.options) == null ? void 0 : _this$options2.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
stubSignatureOverrides: (_this$options$stubSig = (_this$options3 = this.options) == null ? void 0 : _this$options3.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(), | ||
simulateForFeeOptions: options == null ? void 0 : options.simulateForFeeOptions | ||
}); | ||
const selectMethod = (_this$options$selectF = (_this$options3 = this.options) == null ? void 0 : _this$options3.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const selectMethod = (_this$options$selectF = (_this$options4 = this.options) == null ? void 0 : _this$options4.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this); | ||
const feeOption = await selectMethod(txs, prepare.feeOptions); | ||
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)]; | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options4 = this.options) == null ? void 0 : _this$options4.nonceSpace) !== undefined ? { | ||
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options5 = this.options) == null ? void 0 : _this$options5.nonceSpace) !== undefined ? { | ||
nonceSpace: this.options.nonceSpace | ||
@@ -156,3 +147,5 @@ } : undefined); // Will always have a transaction response | ||
call(transaction, blockTag) { | ||
return this.provider.call(transaction, blockTag); | ||
return this.provider.call(_extends({}, transaction, { | ||
blockTag | ||
})); | ||
} | ||
@@ -177,3 +170,3 @@ async resolveName(name) { | ||
getChainId() { | ||
return Promise.resolve(ethers.BigNumber.from(this.chainId).toNumber()); | ||
return Promise.resolve(Number(this.chainId)); | ||
} | ||
@@ -186,6 +179,12 @@ getGasPrice() { | ||
} | ||
getNonce(blockTag) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateCall(tx) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
checkTransaction(transaction) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
populateTransaction(transaction) { | ||
async populateTransaction(tx) { | ||
throw new Error('Method not implemented.'); | ||
@@ -209,3 +208,3 @@ } | ||
async nonce(_wallet, _space) { | ||
return ethers.constants.Zero; | ||
return 0n; | ||
} | ||
@@ -227,3 +226,3 @@ async isValidSignature(_wallet, _digest, _signature) { | ||
this.projectAccessKey = void 0; | ||
this.address = ethers.utils.getAddress(options.address); | ||
this.address = ethers.getAddress(options.address); | ||
this.contexts = options.contexts; | ||
@@ -278,4 +277,4 @@ this.tracker = options.tracker; | ||
network(chainId) { | ||
const tcid = ethers.BigNumber.from(chainId); | ||
const found = this.networks.find(n => tcid.eq(n.chainId)); | ||
const tcid = BigInt(chainId); | ||
const found = this.networks.find(n => tcid === BigInt(n.chainId)); | ||
if (!found) throw new Error(`Network not found for chainId ${chainId}`); | ||
@@ -286,10 +285,14 @@ return found; | ||
const found = this.network(chainId); | ||
if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`); | ||
return found.provider || new ethers.providers.StaticJsonRpcProvider(getEthersConnectionInfo(found.rpcUrl, this.projectAccessKey, this.jwt), { | ||
name: '', | ||
chainId: ethers.BigNumber.from(chainId).toNumber() | ||
if (!found.provider && !found.rpcUrl) { | ||
throw new Error(`Provider not found for chainId ${chainId}`); | ||
} | ||
const network = new ethers.Network(found.name, found.chainId); | ||
return found.provider || new ethers.JsonRpcProvider(getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, { | ||
staticNetwork: network | ||
}); | ||
} | ||
reader(chainId) { | ||
if (ethers.constants.Zero.eq(chainId)) return new Chain0Reader(); | ||
if (BigInt(chainId) === 0n) { | ||
return new Chain0Reader(); | ||
} | ||
@@ -326,3 +329,3 @@ // TODO: Networks should be able to provide a reader directly | ||
walletFor(chainId, context, config, coders) { | ||
const isNetworkZero = ethers.constants.Zero.eq(chainId); | ||
const isNetworkZero = BigInt(chainId) === 0n; | ||
return new Wallet({ | ||
@@ -529,3 +532,3 @@ config, | ||
async publishWitness() { | ||
const digest = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`This is a Sequence account woo! ${Date.now()}`)); | ||
const digest = ethers.id(`This is a Sequence account woo! ${Date.now()}`); | ||
const signature = await this.signDigest(digest, 0, false); | ||
@@ -548,3 +551,3 @@ const decoded = this.coders.signature.decode(signature); | ||
// the behaviour of being migrated on all chains | ||
const chainRef = ethers.constants.Zero.eq(chainId) ? this.networks[0].chainId : chainId; | ||
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId; | ||
const status = await this.status(chainRef); | ||
@@ -580,7 +583,7 @@ this.mustBeFullyMigrated(status); | ||
const subdigest = commons.signature.subdigestOf({ | ||
digest: ethers.utils.hexlify(digest), | ||
digest: ethers.hexlify(digest), | ||
chainId: 0, | ||
address: this.address | ||
}); | ||
const hexSubdigest = ethers.utils.hexlify(subdigest); | ||
const hexSubdigest = ethers.hexlify(subdigest); | ||
const config = this.coders.config.fromSimple({ | ||
@@ -594,3 +597,3 @@ // Threshold *only* needs to be > 0, this is not a magic number | ||
}); | ||
const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi); | ||
const walletInterface = new ethers.Interface(walletContracts.mainModule.abi); | ||
const bundle = { | ||
@@ -630,4 +633,4 @@ entrypoint: this.address, | ||
} | ||
const encoded = ethers.utils.defaultAbiCoder.encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.utils.solidityPack(['bytes', 'bytes32'], [encoded, commons.EIP6492.EIP_6492_SUFFIX]); | ||
const encoded = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, commons.transaction.encodeBundleExecData(bootstrapBundle), signature]); | ||
return ethers.solidityPacked(['bytes', 'bytes32'], [encoded, commons.EIP6492.EIP_6492_SUFFIX]); | ||
} | ||
@@ -637,3 +640,3 @@ async editConfig(changes) { | ||
const newConfig = this.coders.config.editConfig(currentConfig, _extends({}, changes, { | ||
checkpoint: this.coders.config.checkpointOf(currentConfig).add(1) | ||
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n | ||
})); | ||
@@ -698,3 +701,2 @@ return this.updateConfig(newConfig); | ||
} | ||
transactions.length; | ||
@@ -743,3 +745,3 @@ // Get pending migrations | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
return this.signDigest(ethers.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -870,3 +872,3 @@ async signTransactions(txs, chainId, pstatus, options) { | ||
// Now we can decorate the transactions as always, but we need to manually build the signed bundle | ||
const intentId = ethers.utils.hexlify(ethers.utils.randomBytes(32)); | ||
const intentId = ethers.hexlify(ethers.randomBytes(32)); | ||
const signedBundle = { | ||
@@ -873,0 +875,0 @@ chainId, |
@@ -8,3 +8,3 @@ import { commons } from '@0xsequence/core'; | ||
import { Wallet } from '@0xsequence/wallet'; | ||
import { ethers, TypedDataDomain, TypedDataField } from 'ethers'; | ||
import { ethers } from 'ethers'; | ||
import { AccountSigner, AccountSignerOptions } from "./signer.js"; | ||
@@ -76,3 +76,3 @@ export type AccountStatus = { | ||
network(chainId: ethers.BigNumberish): NetworkConfig; | ||
providerFor(chainId: ethers.BigNumberish): ethers.providers.Provider; | ||
providerFor(chainId: ethers.BigNumberish): ethers.Provider; | ||
reader(chainId: ethers.BigNumberish): commons.reader.Reader; | ||
@@ -132,3 +132,3 @@ relayer(chainId: ethers.BigNumberish): Relayer; | ||
}>; | ||
sendSignedTransactions(signedBundle: commons.transaction.IntendedTransactionBundle | commons.transaction.IntendedTransactionBundle[], chainId: ethers.BigNumberish, quote?: FeeQuote, pstatus?: AccountStatus, callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void): Promise<ethers.providers.TransactionResponse>; | ||
sendSignedTransactions(signedBundle: commons.transaction.IntendedTransactionBundle | commons.transaction.IntendedTransactionBundle[], chainId: ethers.BigNumberish, quote?: FeeQuote, pstatus?: AccountStatus, callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void): Promise<ethers.TransactionResponse>; | ||
fillGasLimits(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, status?: AccountStatus): Promise<commons.transaction.SimulatedTransaction[]>; | ||
@@ -151,4 +151,4 @@ gasRefundQuotes(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, stubSignatureOverrides: Map<string, string>, status?: AccountStatus, options?: { | ||
serial?: boolean; | ||
}): Promise<ethers.providers.TransactionResponse | undefined>; | ||
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>; | ||
}): Promise<ethers.TransactionResponse | undefined>; | ||
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>; | ||
getSigners(): Promise<Array<{ | ||
@@ -155,0 +155,0 @@ address: string; |
@@ -10,30 +10,32 @@ import { ChainId } from '@0xsequence/network'; | ||
stubSignatureOverrides?: Map<string, string>; | ||
selectFee?: (txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish, options: FeeOption[]) => Promise<FeeOption | undefined>; | ||
selectFee?: (txs: ethers.TransactionRequest | commons.transaction.Transactionish, options: FeeOption[]) => Promise<FeeOption | undefined>; | ||
}; | ||
export declare class AccountSigner implements ethers.Signer { | ||
export declare class AccountSigner implements ethers.AbstractSigner<ethers.Provider> { | ||
account: Account; | ||
chainId: ChainId; | ||
readonly options?: AccountSignerOptions | undefined; | ||
readonly _isSigner = true; | ||
constructor(account: Account, chainId: ChainId, options?: AccountSignerOptions | undefined); | ||
get provider(): ethers.providers.Provider; | ||
get provider(): ethers.Provider; | ||
getAddress(): Promise<string>; | ||
signMessage(message: string | ethers.utils.Bytes): Promise<string>; | ||
signMessage(message: string | ethers.BytesLike): Promise<string>; | ||
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, value: Record<string, any>): Promise<string>; | ||
private defaultSelectFee; | ||
sendTransaction(txsPromise: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish, options?: { | ||
sendTransaction(txs: commons.transaction.Transactionish, options?: { | ||
simulateForFeeOptions?: boolean; | ||
}): Promise<ethers.providers.TransactionResponse>; | ||
getBalance(blockTag?: ethers.providers.BlockTag | undefined): Promise<ethers.BigNumber>; | ||
call(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, blockTag?: ethers.providers.BlockTag | undefined): Promise<string>; | ||
}): Promise<ethers.TransactionResponse>; | ||
getBalance(blockTag?: ethers.BlockTag | undefined): Promise<bigint>; | ||
call(transaction: ethers.TransactionRequest, blockTag?: ethers.BlockTag): Promise<string>; | ||
resolveName(name: string): Promise<string>; | ||
connect(_provider: ethers.providers.Provider): ethers.Signer; | ||
signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>; | ||
getTransactionCount(blockTag?: ethers.providers.BlockTag | undefined): Promise<number>; | ||
estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.BigNumber>; | ||
connect(_provider: ethers.Provider): ethers.Signer; | ||
signTransaction(transaction: ethers.TransactionRequest): Promise<string>; | ||
getTransactionCount(blockTag?: ethers.BlockTag | undefined): Promise<number>; | ||
estimateGas(transaction: ethers.TransactionRequest): Promise<bigint>; | ||
getChainId(): Promise<number>; | ||
getGasPrice(): Promise<ethers.BigNumber>; | ||
getFeeData(): Promise<ethers.providers.FeeData>; | ||
checkTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): ethers.utils.Deferrable<ethers.providers.TransactionRequest>; | ||
populateTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.providers.TransactionRequest>; | ||
getGasPrice(): Promise<bigint>; | ||
getFeeData(): Promise<ethers.FeeData>; | ||
getNonce(blockTag?: ethers.BlockTag): Promise<number>; | ||
populateCall(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>>; | ||
checkTransaction(transaction: ethers.TransactionRequest): ethers.TransactionRequest; | ||
populateTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>>; | ||
_checkProvider(operation?: string | undefined): void; | ||
} |
{ | ||
"name": "@0xsequence/account", | ||
"version": "0.0.0-20240820154443", | ||
"version": "0.0.0-20240820173337", | ||
"description": "tools for migrating sequence wallets to new versions", | ||
@@ -12,17 +12,20 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/account", | ||
"dependencies": { | ||
"ethers": "^5.5.2", | ||
"@0xsequence/abi": "0.0.0-20240820154443", | ||
"@0xsequence/core": "0.0.0-20240820154443", | ||
"@0xsequence/migration": "0.0.0-20240820154443", | ||
"@0xsequence/network": "0.0.0-20240820154443", | ||
"@0xsequence/relayer": "0.0.0-20240820154443", | ||
"@0xsequence/sessions": "0.0.0-20240820154443", | ||
"@0xsequence/utils": "0.0.0-20240820154443", | ||
"@0xsequence/wallet": "0.0.0-20240820154443" | ||
"@0xsequence/abi": "0.0.0-20240820173337", | ||
"@0xsequence/core": "0.0.0-20240820173337", | ||
"@0xsequence/migration": "0.0.0-20240820173337", | ||
"@0xsequence/relayer": "0.0.0-20240820173337", | ||
"@0xsequence/network": "0.0.0-20240820173337", | ||
"@0xsequence/sessions": "0.0.0-20240820173337", | ||
"@0xsequence/utils": "0.0.0-20240820173337", | ||
"@0xsequence/wallet": "0.0.0-20240820173337" | ||
}, | ||
"peerDependencies": { | ||
"ethers": ">=6" | ||
}, | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"ethers": "^6.13.0", | ||
"nyc": "^15.1.0", | ||
"@0xsequence/signhub": "0.0.0-20240820154443", | ||
"@0xsequence/tests": "0.0.0-20240820154443" | ||
"@0xsequence/signhub": "0.0.0-20240820173337", | ||
"@0xsequence/tests": "0.0.0-20240820173337" | ||
}, | ||
@@ -29,0 +32,0 @@ "files": [ |
import { walletContracts } from '@0xsequence/abi' | ||
import { commons, universal } from '@0xsequence/core' | ||
import { WalletSignRequestMetadata } from '@0xsequence/core/src/commons' | ||
import { migrator, defaults, version } from '@0xsequence/migration' | ||
@@ -9,5 +8,5 @@ import { ChainId, NetworkConfig } from '@0xsequence/network' | ||
import { SignatureOrchestrator } from '@0xsequence/signhub' | ||
import { encodeTypedDataDigest, getEthersConnectionInfo } from '@0xsequence/utils' | ||
import { encodeTypedDataDigest, getFetchRequest } from '@0xsequence/utils' | ||
import { Wallet } from '@0xsequence/wallet' | ||
import { ethers, TypedDataDomain, TypedDataField } from 'ethers' | ||
import { ethers } from 'ethers' | ||
import { AccountSigner, AccountSignerOptions } from './signer' | ||
@@ -86,7 +85,7 @@ | ||
async nonce(_wallet: string, _space: ethers.BigNumberish): Promise<ethers.BigNumberish> { | ||
return ethers.constants.Zero | ||
async nonce(_wallet: string, _space: ethers.BigNumberish): Promise<bigint> { | ||
return 0n | ||
} | ||
async isValidSignature(_wallet: string, _digest: ethers.utils.BytesLike, _signature: ethers.utils.BytesLike): Promise<boolean> { | ||
async isValidSignature(_wallet: string, _digest: ethers.BytesLike, _signature: ethers.BytesLike): Promise<boolean> { | ||
throw new Error('Method not supported.') | ||
@@ -113,3 +112,3 @@ } | ||
constructor(options: AccountOptions) { | ||
this.address = ethers.utils.getAddress(options.address) | ||
this.address = ethers.getAddress(options.address) | ||
@@ -184,4 +183,4 @@ this.contexts = options.contexts | ||
network(chainId: ethers.BigNumberish): NetworkConfig { | ||
const tcid = ethers.BigNumber.from(chainId) | ||
const found = this.networks.find(n => tcid.eq(n.chainId)) | ||
const tcid = BigInt(chainId) | ||
const found = this.networks.find(n => tcid === BigInt(n.chainId)) | ||
if (!found) throw new Error(`Network not found for chainId ${chainId}`) | ||
@@ -191,10 +190,14 @@ return found | ||
providerFor(chainId: ethers.BigNumberish): ethers.providers.Provider { | ||
providerFor(chainId: ethers.BigNumberish): ethers.Provider { | ||
const found = this.network(chainId) | ||
if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`) | ||
if (!found.provider && !found.rpcUrl) { | ||
throw new Error(`Provider not found for chainId ${chainId}`) | ||
} | ||
const network = new ethers.Network(found.name, found.chainId) | ||
return ( | ||
found.provider || | ||
new ethers.providers.StaticJsonRpcProvider(getEthersConnectionInfo(found.rpcUrl, this.projectAccessKey, this.jwt), { | ||
name: '', | ||
chainId: ethers.BigNumber.from(chainId).toNumber() | ||
new ethers.JsonRpcProvider(getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, { | ||
staticNetwork: network | ||
}) | ||
@@ -205,3 +208,5 @@ ) | ||
reader(chainId: ethers.BigNumberish): commons.reader.Reader { | ||
if (ethers.constants.Zero.eq(chainId)) return new Chain0Reader() | ||
if (BigInt(chainId) === 0n) { | ||
return new Chain0Reader() | ||
} | ||
@@ -250,3 +255,3 @@ // TODO: Networks should be able to provide a reader directly | ||
): Wallet { | ||
const isNetworkZero = ethers.constants.Zero.eq(chainId) | ||
const isNetworkZero = BigInt(chainId) === 0n | ||
return new Wallet({ | ||
@@ -496,3 +501,3 @@ config, | ||
async publishWitness(): Promise<void> { | ||
const digest = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`This is a Sequence account woo! ${Date.now()}`)) | ||
const digest = ethers.id(`This is a Sequence account woo! ${Date.now()}`) | ||
const signature = await this.signDigest(digest, 0, false) | ||
@@ -517,3 +522,3 @@ const decoded = this.coders.signature.decode(signature) | ||
// the behaviour of being migrated on all chains | ||
const chainRef = ethers.constants.Zero.eq(chainId) ? this.networks[0].chainId : chainId | ||
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId | ||
const status = await this.status(chainRef) | ||
@@ -553,4 +558,8 @@ this.mustBeFullyMigrated(status) | ||
buildOnChainSignature(digest: ethers.BytesLike): { bundle: commons.transaction.TransactionBundle; signature: string } { | ||
const subdigest = commons.signature.subdigestOf({ digest: ethers.utils.hexlify(digest), chainId: 0, address: this.address }) | ||
const hexSubdigest = ethers.utils.hexlify(subdigest) | ||
const subdigest = commons.signature.subdigestOf({ | ||
digest: ethers.hexlify(digest), | ||
chainId: 0, | ||
address: this.address | ||
}) | ||
const hexSubdigest = ethers.hexlify(subdigest) | ||
const config = this.coders.config.fromSimple({ | ||
@@ -565,3 +574,3 @@ // Threshold *only* needs to be > 0, this is not a magic number | ||
const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi) | ||
const walletInterface = new ethers.Interface(walletContracts.mainModule.abi) | ||
const bundle: commons.transaction.TransactionBundle = { | ||
@@ -604,3 +613,3 @@ entrypoint: this.address, | ||
const encoded = ethers.utils.defaultAbiCoder.encode( | ||
const encoded = ethers.AbiCoder.defaultAbiCoder().encode( | ||
['address', 'bytes', 'bytes'], | ||
@@ -610,3 +619,3 @@ [bootstrapBundle.entrypoint, commons.transaction.encodeBundleExecData(bootstrapBundle), signature] | ||
return ethers.utils.solidityPack(['bytes', 'bytes32'], [encoded, commons.EIP6492.EIP_6492_SUFFIX]) | ||
return ethers.solidityPacked(['bytes', 'bytes32'], [encoded, commons.EIP6492.EIP_6492_SUFFIX]) | ||
} | ||
@@ -622,3 +631,3 @@ | ||
...changes, | ||
checkpoint: this.coders.config.checkpointOf(currentConfig).add(1) | ||
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n | ||
}) | ||
@@ -688,3 +697,2 @@ | ||
} | ||
const len = transactions.length | ||
@@ -736,3 +744,3 @@ // Get pending migrations | ||
): Promise<string> { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId, true, cantValidateBehavior) | ||
return this.signDigest(ethers.keccak256(message), chainId, true, cantValidateBehavior) | ||
} | ||
@@ -754,3 +762,3 @@ | ||
const metadata: WalletSignRequestMetadata = { | ||
const metadata: commons.WalletSignRequestMetadata = { | ||
address: this.address, | ||
@@ -860,3 +868,3 @@ digest: '', // Set in wallet.signTransactions | ||
callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void | ||
): Promise<ethers.providers.TransactionResponse> { | ||
): Promise<ethers.TransactionResponse> { | ||
if (!Array.isArray(signedBundle)) { | ||
@@ -908,3 +916,3 @@ return this.sendSignedTransactions([signedBundle], chainId, quote, pstatus, callback) | ||
// Now we can decorate the transactions as always, but we need to manually build the signed bundle | ||
const intentId = ethers.utils.hexlify(ethers.utils.randomBytes(32)) | ||
const intentId = ethers.hexlify(ethers.randomBytes(32)) | ||
const signedBundle: commons.transaction.SignedTransactionBundle = { | ||
@@ -960,3 +968,3 @@ chainId, | ||
} | ||
): Promise<ethers.providers.TransactionResponse | undefined> { | ||
): Promise<ethers.TransactionResponse | undefined> { | ||
const status = await this.status(chainId) | ||
@@ -980,4 +988,4 @@ | ||
async signTypedData( | ||
domain: TypedDataDomain, | ||
types: Record<string, Array<TypedDataField>>, | ||
domain: ethers.TypedDataDomain, | ||
types: Record<string, Array<ethers.TypedDataField>>, | ||
message: Record<string, any>, | ||
@@ -984,0 +992,0 @@ chainId: ethers.BigNumberish, |
@@ -18,6 +18,6 @@ import { commons } from '@0xsequence/core' | ||
getChainIdFromMetadata(metadata: object): ethers.BigNumber { | ||
getChainIdFromMetadata(metadata: object): bigint { | ||
try { | ||
const { chainId } = metadata as MetadataWithChainId | ||
return ethers.BigNumber.from(chainId) | ||
return BigInt(chainId) | ||
} catch (err) { | ||
@@ -50,3 +50,3 @@ // Invalid metadata object | ||
sign(message: ethers.utils.BytesLike, metadata: object): Promise<ethers.utils.BytesLike> { | ||
sign(message: ethers.BytesLike, metadata: object): Promise<ethers.BytesLike> { | ||
if (!commons.isWalletSignRequestMetadata(metadata)) { | ||
@@ -68,5 +68,5 @@ throw new Error('AccountOrchestratorWrapper only supports wallet metadata requests') | ||
suffix(): ethers.utils.BytesLike { | ||
return [3] | ||
suffix(): ethers.BytesLike { | ||
return new Uint8Array([3]) | ||
} | ||
} |
@@ -6,3 +6,3 @@ import { ChainId } from '@0xsequence/network' | ||
import { FeeOption, proto } from '@0xsequence/relayer' | ||
import { isDeferrable } from './utils' | ||
import { toHexString } from '@0xsequence/utils' | ||
@@ -14,3 +14,3 @@ export type AccountSignerOptions = { | ||
selectFee?: ( | ||
txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish, | ||
txs: ethers.TransactionRequest | commons.transaction.Transactionish, | ||
options: FeeOption[] | ||
@@ -23,3 +23,3 @@ ) => Promise<FeeOption | undefined> | ||
const value = ethers.BigNumber.from(option.value) | ||
const value = BigInt(option.value) | ||
@@ -34,4 +34,4 @@ switch (option.token.type) { | ||
to: option.to, | ||
value: value.toHexString(), | ||
data: [] | ||
value: toHexString(value), | ||
data: '0x' | ||
} | ||
@@ -52,3 +52,3 @@ ] | ||
value: 0, | ||
data: new ethers.utils.Interface([ | ||
data: new ethers.Interface([ | ||
{ | ||
@@ -61,3 +61,3 @@ constant: false, | ||
} | ||
]).encodeFunctionData('transfer', [option.to, value.toHexString()]) | ||
]).encodeFunctionData('transfer', [option.to, toHexString(value)]) | ||
} | ||
@@ -71,5 +71,3 @@ ] | ||
export class AccountSigner implements ethers.Signer { | ||
public readonly _isSigner = true | ||
export class AccountSigner implements ethers.AbstractSigner<ethers.Provider> { | ||
constructor( | ||
@@ -89,10 +87,15 @@ public account: Account, | ||
signMessage(message: string | ethers.utils.Bytes): Promise<string> { | ||
signMessage(message: string | ethers.BytesLike): Promise<string> { | ||
return this.account.signMessage(message, this.chainId, this.options?.cantValidateBehavior ?? 'throw') | ||
} | ||
private async defaultSelectFee( | ||
_txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish, | ||
options: FeeOption[] | ||
): Promise<FeeOption | undefined> { | ||
signTypedData( | ||
domain: ethers.TypedDataDomain, | ||
types: Record<string, Array<ethers.TypedDataField>>, | ||
value: Record<string, any> | ||
): Promise<string> { | ||
return this.account.signTypedData(domain, types, value, this.chainId, this.options?.cantValidateBehavior ?? 'throw') | ||
} | ||
private async defaultSelectFee(_txs: commons.transaction.Transactionish, options: FeeOption[]): Promise<FeeOption | undefined> { | ||
// If no options, return undefined | ||
@@ -117,3 +120,3 @@ if (options.length === 0) return undefined | ||
const balance = await this.getBalance() | ||
if (balance.gte(ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option | ||
@@ -125,3 +128,3 @@ } | ||
const balance = await token.balanceOf(this.account.address) | ||
if (balance.gte(ethers.BigNumber.from(option.value))) { | ||
if (balance >= BigInt(option.value)) { | ||
return option | ||
@@ -138,11 +141,7 @@ } | ||
async sendTransaction( | ||
txsPromise: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish, | ||
txs: commons.transaction.Transactionish, | ||
options?: { | ||
simulateForFeeOptions?: boolean | ||
} | ||
): Promise<ethers.providers.TransactionResponse> { | ||
const txs = isDeferrable(txsPromise) | ||
? await ethers.utils.resolveProperties(txsPromise as ethers.utils.Deferrable<ethers.providers.TransactionRequest>) | ||
: txsPromise | ||
): Promise<ethers.TransactionResponse> { | ||
const prepare = await this.account.prepareTransactions({ | ||
@@ -171,14 +170,11 @@ txs, | ||
: undefined | ||
) as Promise<ethers.providers.TransactionResponse> // Will always have a transaction response | ||
) as Promise<ethers.TransactionResponse> // Will always have a transaction response | ||
} | ||
getBalance(blockTag?: ethers.providers.BlockTag | undefined): Promise<ethers.BigNumber> { | ||
getBalance(blockTag?: ethers.BlockTag | undefined): Promise<bigint> { | ||
return this.provider.getBalance(this.account.address, blockTag) | ||
} | ||
call( | ||
transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, | ||
blockTag?: ethers.providers.BlockTag | undefined | ||
): Promise<string> { | ||
return this.provider.call(transaction, blockTag) | ||
call(transaction: ethers.TransactionRequest, blockTag?: ethers.BlockTag): Promise<string> { | ||
return this.provider.call({ ...transaction, blockTag }) | ||
} | ||
@@ -192,15 +188,15 @@ | ||
connect(_provider: ethers.providers.Provider): ethers.Signer { | ||
connect(_provider: ethers.Provider): ethers.Signer { | ||
throw new Error('Method not implemented.') | ||
} | ||
signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string> { | ||
signTransaction(transaction: ethers.TransactionRequest): Promise<string> { | ||
throw new Error('Method not implemented.') | ||
} | ||
getTransactionCount(blockTag?: ethers.providers.BlockTag | undefined): Promise<number> { | ||
getTransactionCount(blockTag?: ethers.BlockTag | undefined): Promise<number> { | ||
throw new Error('Method not implemented.') | ||
} | ||
estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.BigNumber> { | ||
estimateGas(transaction: ethers.TransactionRequest): Promise<bigint> { | ||
throw new Error('Method not implemented.') | ||
@@ -210,25 +206,29 @@ } | ||
getChainId(): Promise<number> { | ||
return Promise.resolve(ethers.BigNumber.from(this.chainId).toNumber()) | ||
return Promise.resolve(Number(this.chainId)) | ||
} | ||
getGasPrice(): Promise<ethers.BigNumber> { | ||
getGasPrice(): Promise<bigint> { | ||
throw new Error('Method not implemented.') | ||
} | ||
getFeeData(): Promise<ethers.providers.FeeData> { | ||
getFeeData(): Promise<ethers.FeeData> { | ||
throw new Error('Method not implemented.') | ||
} | ||
checkTransaction( | ||
transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | ||
): ethers.utils.Deferrable<ethers.providers.TransactionRequest> { | ||
getNonce(blockTag?: ethers.BlockTag): Promise<number> { | ||
throw new Error('Method not implemented.') | ||
} | ||
populateTransaction( | ||
transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | ||
): Promise<ethers.providers.TransactionRequest> { | ||
populateCall(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>> { | ||
throw new Error('Method not implemented.') | ||
} | ||
checkTransaction(transaction: ethers.TransactionRequest): ethers.TransactionRequest { | ||
throw new Error('Method not implemented.') | ||
} | ||
async populateTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>> { | ||
throw new Error('Method not implemented.') | ||
} | ||
_checkProvider(operation?: string | undefined): void { | ||
@@ -235,0 +235,0 @@ throw new Error('Method not implemented.') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4266
192299
5
14
+ Added@0xsequence/abi@0.0.0-20240820173337(transitive)
+ Added@0xsequence/core@0.0.0-20240820173337(transitive)
+ Added@0xsequence/indexer@0.0.0-20240820173337(transitive)
+ Added@0xsequence/migration@0.0.0-20240820173337(transitive)
+ Added@0xsequence/network@0.0.0-20240820173337(transitive)
+ Added@0xsequence/relayer@0.0.0-20240820173337(transitive)
+ Added@0xsequence/replacer@0.0.0-20240820173337(transitive)
+ Added@0xsequence/sessions@0.0.0-20240820173337(transitive)
+ Added@0xsequence/signhub@0.0.0-20240820173337(transitive)
+ Added@0xsequence/utils@0.0.0-20240820173337(transitive)
+ Added@0xsequence/wallet@0.0.0-20240820173337(transitive)
+ Added@adraffy/ens-normalize@1.10.1(transitive)
+ Added@noble/curves@1.2.0(transitive)
+ Added@noble/hashes@1.3.2(transitive)
+ Added@types/node@22.7.5(transitive)
+ Addedaes-js@4.0.0-beta.5(transitive)
+ Addedethers@6.13.4(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedws@8.17.1(transitive)
- Removedethers@^5.5.2
- Removed@0xsequence/abi@0.0.0-20240820154443(transitive)
- Removed@0xsequence/core@0.0.0-20240820154443(transitive)
- Removed@0xsequence/indexer@0.0.0-20240820154443(transitive)
- Removed@0xsequence/migration@0.0.0-20240820154443(transitive)
- Removed@0xsequence/network@0.0.0-20240820154443(transitive)
- Removed@0xsequence/relayer@0.0.0-20240820154443(transitive)
- Removed@0xsequence/replacer@0.0.0-20240820154443(transitive)
- Removed@0xsequence/sessions@0.0.0-20240820154443(transitive)
- Removed@0xsequence/signhub@0.0.0-20240820154443(transitive)
- Removed@0xsequence/utils@0.0.0-20240820154443(transitive)
- Removed@0xsequence/wallet@0.0.0-20240820154443(transitive)
- Removed@ethersproject/abi@5.7.0(transitive)
- Removed@ethersproject/abstract-provider@5.7.0(transitive)
- Removed@ethersproject/abstract-signer@5.7.0(transitive)
- Removed@ethersproject/address@5.7.0(transitive)
- Removed@ethersproject/base64@5.7.0(transitive)
- Removed@ethersproject/basex@5.7.0(transitive)
- Removed@ethersproject/bignumber@5.7.0(transitive)
- Removed@ethersproject/bytes@5.7.0(transitive)
- Removed@ethersproject/constants@5.7.0(transitive)
- Removed@ethersproject/contracts@5.7.0(transitive)
- Removed@ethersproject/hash@5.7.0(transitive)
- Removed@ethersproject/hdnode@5.7.0(transitive)
- Removed@ethersproject/json-wallets@5.7.0(transitive)
- Removed@ethersproject/keccak256@5.7.0(transitive)
- Removed@ethersproject/logger@5.7.0(transitive)
- Removed@ethersproject/networks@5.7.1(transitive)
- Removed@ethersproject/pbkdf2@5.7.0(transitive)
- Removed@ethersproject/properties@5.7.0(transitive)
- Removed@ethersproject/providers@5.7.2(transitive)
- Removed@ethersproject/random@5.7.0(transitive)
- Removed@ethersproject/rlp@5.7.0(transitive)
- Removed@ethersproject/sha2@5.7.0(transitive)
- Removed@ethersproject/signing-key@5.7.0(transitive)
- Removed@ethersproject/solidity@5.7.0(transitive)
- Removed@ethersproject/strings@5.7.0(transitive)
- Removed@ethersproject/transactions@5.7.0(transitive)
- Removed@ethersproject/units@5.7.0(transitive)
- Removed@ethersproject/wallet@5.7.0(transitive)
- Removed@ethersproject/web@5.7.1(transitive)
- Removed@ethersproject/wordlists@5.7.0(transitive)
- Removedaes-js@3.0.0(transitive)
- Removedbech32@1.1.4(transitive)
- Removedbn.js@4.12.15.2.1(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethers@5.7.2(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-sha3@0.8.0(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@3.0.1(transitive)
- Removedws@7.4.6(transitive)