Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0xsequence/wallet

Package Overview
Dependencies
Maintainers
2
Versions
498
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xsequence/wallet - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

20

CHANGELOG.md
# @0xsequence/wallet
## 0.8.3
### Patch Changes
- - refinements
- normalize signer address in config
- provider: getWalletState() method to WalletProvider
- Updated dependencies [undefined]
- @0xsequence/abi@0.8.3
- @0xsequence/api@0.8.3
- @0xsequence/config@0.8.3
- @0xsequence/guard@0.8.3
- @0xsequence/network@0.8.3
- @0xsequence/relayer@0.8.3
- @0xsequence/transactions@0.8.3
- @0xsequence/utils@0.8.3
## 0.8.2

@@ -4,0 +24,0 @@

144

dist/0xsequence-wallet.cjs.dev.js

@@ -12,2 +12,3 @@ 'use strict';

var transactions = require('@0xsequence/transactions');
var utils = require('@0xsequence/utils');
var fetchPonyfill = require('fetch-ponyfill');

@@ -80,3 +81,3 @@ var guard = require('@0xsequence/guard');

weight: s.weight,
address: recoverSigner(digest, s)
address: recoverSigner(digest, s).toLowerCase()
};

@@ -86,3 +87,3 @@ } else {

weight: s.weight,
address: s.address
address: s.address.toLowerCase()
};

@@ -344,3 +345,3 @@ }

this.config = config.sortConfig(config$1);
this.config = config.sortConfig(config$1, true);
this._signers = signers.map(s => ethers.Signer.isSigner(s) ? s : new ethers.ethers.Wallet(s));

@@ -436,5 +437,10 @@ } // useConfig creates a new Wallet instance with the provided config, and uses the current provider

imageHash: this.imageHash,
currentImageHash: isDeployed ? await fetchImageHash(this) : undefined
}; // TODO: check if its published
publishedImageHash: isDeployed ? await fetchImageHash(this) : undefined,
publishedLatest: false
};
if (state.publishedImageHash && state.publishedImageHash.length > 0 && state.imageHash === state.publishedImageHash) {
state.publishedLatest = true;
}
return [state];

@@ -473,3 +479,3 @@ } // connected reports if json-rpc provider has been connected

return Promise.all(this._signers.map(s => s.getAddress()));
return Promise.all(this._signers.map(s => s.getAddress().then(s => s.toLowerCase())));
} // chainId returns the network connected to this wallet instance

@@ -610,9 +616,9 @@

throw new Error(`signTypedData: domain.chainId (${domain.chainId}) is expected to be ${signChainId}`);
} // remove EIP712Domain key from types as ethers will auto-gen it
}
delete types['EIP712Domain'];
const hash = ethers.ethers.utils._TypedDataEncoder.hash(domain, types, message);
const hash = utils.encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(ethers.ethers.utils.arrayify(hash), signChainId, allSigners);

@@ -633,3 +639,3 @@ }

const signWith = async function signWith(signers, auxData) {
const signersAddr = Promise.all(signers.map(s => s.getAddress()));
const signersAddr = Promise.all(signers.map(s => s.getAddress().then(s => s.toLowerCase())));
const accountBytes = await Promise.all(_this.config.signers.map(async function (a) {

@@ -760,3 +766,3 @@ const signerIndex = (await signersAddr).indexOf(a.address);

nonce: nonce,
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config$1.threshold, config.sortConfig(config$1).signers.map(s => ({
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config$1.threshold, config.sortConfig(config$1, true).signers.map(s => ({
weight: s.weight,

@@ -809,3 +815,3 @@ signer: s.address

weight: 1,
address: await signer.getAddress()
address: (await signer.getAddress()).toLowerCase()
}]

@@ -880,5 +886,6 @@ };

const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat();
const idx = states.findIndex(s => s.chainId === this.authChainId());
const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat(); // fetch the current config for the AuthChain, as it will be available
const idx = states.findIndex(s => s.chainId === this.getAuthChainId());
if (idx >= 0) {

@@ -908,5 +915,5 @@ states[idx].config = await this.currentConfig(wallets[idx].wallet);

getProvider(chainId) {
var _this$_wallets$find;
var _this$mainWallet, _this$_wallets$find;
if (!chainId) return this.mainWallet().getProvider();
if (!chainId) return (_this$mainWallet = this.mainWallet()) == null ? void 0 : _this$mainWallet.wallet.getProvider();
return (_this$_wallets$find = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find.wallet.getProvider();

@@ -916,5 +923,5 @@ }

getRelayer(chainId) {
var _this$_wallets$find2;
var _this$mainWallet2, _this$_wallets$find2;
if (!chainId) return this.mainWallet().getRelayer();
if (!chainId) return (_this$mainWallet2 = this.mainWallet()) == null ? void 0 : _this$mainWallet2.wallet.getRelayer();
return (_this$_wallets$find2 = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find2.wallet.getRelayer();

@@ -927,27 +934,45 @@ }

async signAuthMessage(message, allSigners = true) {
return this.signMessage(message, this.authWallet(), allSigners);
}
getAuthChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
} // TODO: maybe rename allSigners to partialSign
async signMessage(message, target, allSigners = true) {
let wallet = (() => {
if (!target) return this.mainWallet();
var _this = this;
let {
wallet,
network
} = await async function () {
// eslint-disable-line
if (!target) {
return _this.mainWallet();
}
if (target.address) {
return target;
const chainId = await target.getChainId();
return _this._wallets.find(w => w.wallet.chainId === chainId);
}
return this.getWalletByNetwork(target).wallet;
})(); // Fetch the latest config of the wallet
// TODO: Skip this step if wallet is authWallet
return _this.getWalletByNetwork(target);
}(); // Fetch the latest config of the wallet.
//
// We skip this step if wallet is authWallet
// TODO: instead, memoize the currentConfig, as below will break
// if we skip
// if (!network.isAuthChain) {
let thisConfig = await this.currentConfig(wallet);
thisConfig = thisConfig ? thisConfig : this._wallets[0].wallet.config;
wallet = wallet.useConfig(thisConfig); // See if wallet has enough signer power
wallet = wallet.useConfig(thisConfig); // }
// See if wallet has enough signer power
const weight = await wallet.signWeight();
if (weight.lt(thisConfig.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${thisConfig.threshold.toString()}`);
if (weight.lt(wallet.config.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${wallet.config.threshold.toString()}`);
}

@@ -958,5 +983,16 @@

async signAuthMessage(message, allSigners = true) {
var _this$authWallet;
return this.signMessage(message, (_this$authWallet = this.authWallet()) == null ? void 0 : _this$authWallet.wallet, allSigners);
}
async signTypedData(domain, types, message, chainId, allSigners = true) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
return wallet.signTypedData(domain, types, message, chainId, allSigners);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
const hash = utils.encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(hash, wallet, allSigners);
}

@@ -970,3 +1006,3 @@

const transaction = await resolveArrayProperties(dtransactionish);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet(); // TODO: Skip this step if wallet is authWallet
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet; // TODO: Skip this step if wallet is authWallet

@@ -999,3 +1035,3 @@ const [thisConfig, lastConfig] = await Promise.all([this.currentConfig(wallet), this.currentConfig()]); // See if wallet has enough signer power

signTransactions(txs, chainId, allSigners) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.signTransactions(txs, chainId, allSigners);

@@ -1005,3 +1041,3 @@ }

async sendSignedTransactions(signedTxs, chainId) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.sendSignedTransactions(signedTxs);

@@ -1013,3 +1049,3 @@ } // updateConfig will build an updated config transaction, update the imageHahs on-chain and also publish

async updateConfig(newConfig) {
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;

@@ -1048,3 +1084,3 @@ if (!newConfig) {

publishConfig() {
return this.authWallet().publishConfig();
return this.authWallet().wallet.publishConfig();
}

@@ -1054,3 +1090,3 @@

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1071,3 +1107,3 @@ if (target.address) {

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1088,3 +1124,3 @@ if (target.address) {

const currentImplementation = ethers.ethers.utils.defaultAbiCoder.decode(['address'], ethers.ethers.utils.hexZeroPad(await wallet.provider.getStorageAt(address, address).catch(() => ethers.ethers.constants.AddressZero), 32))[0];
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;
const authContract = new ethers.Contract(authWallet.context.sequenceUtils, abi.walletContracts.sequenceUtils.abi, authWallet.provider);

@@ -1152,6 +1188,7 @@ let event;

return this._wallets.find(w => w.network.chainId === networkId);
}
} // mainWallet is the DefaultChain wallet
mainWallet() {
const found = this._wallets.find(w => w.network.isDefaultChain).wallet;
const found = this._wallets.find(w => w.network.isDefaultChain);

@@ -1162,7 +1199,8 @@ if (!found) {

return found; // return found ? found : this._wallets[0].wallet
}
return found;
} // authWallet is the AuthChain wallet
authWallet() {
const found = this._wallets.find(w => w.network.isAuthChain).wallet;
const found = this._wallets.find(w => w.network.isAuthChain);

@@ -1176,10 +1214,2 @@ if (!found) {

authChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
}
setNetworks(mainnetNetworks, testnetNetworks = [], defaultChainId) {

@@ -1186,0 +1216,0 @@ let networks = []; // find chain between mainnet and testnet network groups, and set that network group.

@@ -12,2 +12,3 @@ 'use strict';

var transactions = require('@0xsequence/transactions');
var utils = require('@0xsequence/utils');
var fetchPonyfill = require('fetch-ponyfill');

@@ -80,3 +81,3 @@ var guard = require('@0xsequence/guard');

weight: s.weight,
address: recoverSigner(digest, s)
address: recoverSigner(digest, s).toLowerCase()
};

@@ -86,3 +87,3 @@ } else {

weight: s.weight,
address: s.address
address: s.address.toLowerCase()
};

@@ -344,3 +345,3 @@ }

this.config = config.sortConfig(config$1);
this.config = config.sortConfig(config$1, true);
this._signers = signers.map(s => ethers.Signer.isSigner(s) ? s : new ethers.ethers.Wallet(s));

@@ -436,5 +437,10 @@ } // useConfig creates a new Wallet instance with the provided config, and uses the current provider

imageHash: this.imageHash,
currentImageHash: isDeployed ? await fetchImageHash(this) : undefined
}; // TODO: check if its published
publishedImageHash: isDeployed ? await fetchImageHash(this) : undefined,
publishedLatest: false
};
if (state.publishedImageHash && state.publishedImageHash.length > 0 && state.imageHash === state.publishedImageHash) {
state.publishedLatest = true;
}
return [state];

@@ -473,3 +479,3 @@ } // connected reports if json-rpc provider has been connected

return Promise.all(this._signers.map(s => s.getAddress()));
return Promise.all(this._signers.map(s => s.getAddress().then(s => s.toLowerCase())));
} // chainId returns the network connected to this wallet instance

@@ -610,9 +616,9 @@

throw new Error(`signTypedData: domain.chainId (${domain.chainId}) is expected to be ${signChainId}`);
} // remove EIP712Domain key from types as ethers will auto-gen it
}
delete types['EIP712Domain'];
const hash = ethers.ethers.utils._TypedDataEncoder.hash(domain, types, message);
const hash = utils.encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(ethers.ethers.utils.arrayify(hash), signChainId, allSigners);

@@ -633,3 +639,3 @@ }

const signWith = async function signWith(signers, auxData) {
const signersAddr = Promise.all(signers.map(s => s.getAddress()));
const signersAddr = Promise.all(signers.map(s => s.getAddress().then(s => s.toLowerCase())));
const accountBytes = await Promise.all(_this.config.signers.map(async function (a) {

@@ -760,3 +766,3 @@ const signerIndex = (await signersAddr).indexOf(a.address);

nonce: nonce,
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config$1.threshold, config.sortConfig(config$1).signers.map(s => ({
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config$1.threshold, config.sortConfig(config$1, true).signers.map(s => ({
weight: s.weight,

@@ -809,3 +815,3 @@ signer: s.address

weight: 1,
address: await signer.getAddress()
address: (await signer.getAddress()).toLowerCase()
}]

@@ -880,5 +886,6 @@ };

const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat();
const idx = states.findIndex(s => s.chainId === this.authChainId());
const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat(); // fetch the current config for the AuthChain, as it will be available
const idx = states.findIndex(s => s.chainId === this.getAuthChainId());
if (idx >= 0) {

@@ -908,5 +915,5 @@ states[idx].config = await this.currentConfig(wallets[idx].wallet);

getProvider(chainId) {
var _this$_wallets$find;
var _this$mainWallet, _this$_wallets$find;
if (!chainId) return this.mainWallet().getProvider();
if (!chainId) return (_this$mainWallet = this.mainWallet()) == null ? void 0 : _this$mainWallet.wallet.getProvider();
return (_this$_wallets$find = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find.wallet.getProvider();

@@ -916,5 +923,5 @@ }

getRelayer(chainId) {
var _this$_wallets$find2;
var _this$mainWallet2, _this$_wallets$find2;
if (!chainId) return this.mainWallet().getRelayer();
if (!chainId) return (_this$mainWallet2 = this.mainWallet()) == null ? void 0 : _this$mainWallet2.wallet.getRelayer();
return (_this$_wallets$find2 = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find2.wallet.getRelayer();

@@ -927,27 +934,45 @@ }

async signAuthMessage(message, allSigners = true) {
return this.signMessage(message, this.authWallet(), allSigners);
}
getAuthChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
} // TODO: maybe rename allSigners to partialSign
async signMessage(message, target, allSigners = true) {
let wallet = (() => {
if (!target) return this.mainWallet();
var _this = this;
let {
wallet,
network
} = await async function () {
// eslint-disable-line
if (!target) {
return _this.mainWallet();
}
if (target.address) {
return target;
const chainId = await target.getChainId();
return _this._wallets.find(w => w.wallet.chainId === chainId);
}
return this.getWalletByNetwork(target).wallet;
})(); // Fetch the latest config of the wallet
// TODO: Skip this step if wallet is authWallet
return _this.getWalletByNetwork(target);
}(); // Fetch the latest config of the wallet.
//
// We skip this step if wallet is authWallet
// TODO: instead, memoize the currentConfig, as below will break
// if we skip
// if (!network.isAuthChain) {
let thisConfig = await this.currentConfig(wallet);
thisConfig = thisConfig ? thisConfig : this._wallets[0].wallet.config;
wallet = wallet.useConfig(thisConfig); // See if wallet has enough signer power
wallet = wallet.useConfig(thisConfig); // }
// See if wallet has enough signer power
const weight = await wallet.signWeight();
if (weight.lt(thisConfig.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${thisConfig.threshold.toString()}`);
if (weight.lt(wallet.config.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${wallet.config.threshold.toString()}`);
}

@@ -958,5 +983,16 @@

async signAuthMessage(message, allSigners = true) {
var _this$authWallet;
return this.signMessage(message, (_this$authWallet = this.authWallet()) == null ? void 0 : _this$authWallet.wallet, allSigners);
}
async signTypedData(domain, types, message, chainId, allSigners = true) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
return wallet.signTypedData(domain, types, message, chainId, allSigners);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
const hash = utils.encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(hash, wallet, allSigners);
}

@@ -970,3 +1006,3 @@

const transaction = await resolveArrayProperties(dtransactionish);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet(); // TODO: Skip this step if wallet is authWallet
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet; // TODO: Skip this step if wallet is authWallet

@@ -999,3 +1035,3 @@ const [thisConfig, lastConfig] = await Promise.all([this.currentConfig(wallet), this.currentConfig()]); // See if wallet has enough signer power

signTransactions(txs, chainId, allSigners) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.signTransactions(txs, chainId, allSigners);

@@ -1005,3 +1041,3 @@ }

async sendSignedTransactions(signedTxs, chainId) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.sendSignedTransactions(signedTxs);

@@ -1013,3 +1049,3 @@ } // updateConfig will build an updated config transaction, update the imageHahs on-chain and also publish

async updateConfig(newConfig) {
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;

@@ -1048,3 +1084,3 @@ if (!newConfig) {

publishConfig() {
return this.authWallet().publishConfig();
return this.authWallet().wallet.publishConfig();
}

@@ -1054,3 +1090,3 @@

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1071,3 +1107,3 @@ if (target.address) {

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1088,3 +1124,3 @@ if (target.address) {

const currentImplementation = ethers.ethers.utils.defaultAbiCoder.decode(['address'], ethers.ethers.utils.hexZeroPad(await wallet.provider.getStorageAt(address, address).catch(() => ethers.ethers.constants.AddressZero), 32))[0];
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;
const authContract = new ethers.Contract(authWallet.context.sequenceUtils, abi.walletContracts.sequenceUtils.abi, authWallet.provider);

@@ -1152,6 +1188,7 @@ let event;

return this._wallets.find(w => w.network.chainId === networkId);
}
} // mainWallet is the DefaultChain wallet
mainWallet() {
const found = this._wallets.find(w => w.network.isDefaultChain).wallet;
const found = this._wallets.find(w => w.network.isDefaultChain);

@@ -1162,7 +1199,8 @@ if (!found) {

return found; // return found ? found : this._wallets[0].wallet
}
return found;
} // authWallet is the AuthChain wallet
authWallet() {
const found = this._wallets.find(w => w.network.isAuthChain).wallet;
const found = this._wallets.find(w => w.network.isAuthChain);

@@ -1176,10 +1214,2 @@ if (!found) {

authChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
}
setNetworks(mainnetNetworks, testnetNetworks = [], defaultChainId) {

@@ -1186,0 +1216,0 @@ let networks = []; // find chain between mainnet and testnet network groups, and set that network group.

@@ -8,2 +8,3 @@ import { Signer as Signer$1, Contract, ethers, BigNumber } from 'ethers';

import { hasSequenceTransactions, toSequenceTransactions, isSequenceTransaction, makeExpirable, makeAfterNonce, readSequenceNonce, appendNonce, encodeMetaTransactionsData, sequenceTxAbiEncode } from '@0xsequence/transactions';
import { encodeTypedDataHash } from '@0xsequence/utils';
import fetchPonyfill from 'fetch-ponyfill';

@@ -72,3 +73,3 @@ import { GuarddService } from '@0xsequence/guard';

weight: s.weight,
address: recoverSigner(digest, s)
address: recoverSigner(digest, s).toLowerCase()
};

@@ -78,3 +79,3 @@ } else {

weight: s.weight,
address: s.address
address: s.address.toLowerCase()
};

@@ -336,3 +337,3 @@ }

this.config = sortConfig(config);
this.config = sortConfig(config, true);
this._signers = signers.map(s => Signer$1.isSigner(s) ? s : new ethers.Wallet(s));

@@ -428,5 +429,10 @@ } // useConfig creates a new Wallet instance with the provided config, and uses the current provider

imageHash: this.imageHash,
currentImageHash: isDeployed ? await fetchImageHash(this) : undefined
}; // TODO: check if its published
publishedImageHash: isDeployed ? await fetchImageHash(this) : undefined,
publishedLatest: false
};
if (state.publishedImageHash && state.publishedImageHash.length > 0 && state.imageHash === state.publishedImageHash) {
state.publishedLatest = true;
}
return [state];

@@ -465,3 +471,3 @@ } // connected reports if json-rpc provider has been connected

return Promise.all(this._signers.map(s => s.getAddress()));
return Promise.all(this._signers.map(s => s.getAddress().then(s => s.toLowerCase())));
} // chainId returns the network connected to this wallet instance

@@ -602,9 +608,9 @@

throw new Error(`signTypedData: domain.chainId (${domain.chainId}) is expected to be ${signChainId}`);
} // remove EIP712Domain key from types as ethers will auto-gen it
}
delete types['EIP712Domain'];
const hash = ethers.utils._TypedDataEncoder.hash(domain, types, message);
const hash = encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(ethers.utils.arrayify(hash), signChainId, allSigners);

@@ -625,3 +631,3 @@ }

const signWith = async function signWith(signers, auxData) {
const signersAddr = Promise.all(signers.map(s => s.getAddress()));
const signersAddr = Promise.all(signers.map(s => s.getAddress().then(s => s.toLowerCase())));
const accountBytes = await Promise.all(_this.config.signers.map(async function (a) {

@@ -752,3 +758,3 @@ const signerIndex = (await signersAddr).indexOf(a.address);

nonce: nonce,
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config.threshold, sortConfig(config).signers.map(s => ({
data: sequenceUtilsInterface.encodeFunctionData(sequenceUtilsInterface.getFunction('requireConfig'), [this.address, config.threshold, sortConfig(config, true).signers.map(s => ({
weight: s.weight,

@@ -801,3 +807,3 @@ signer: s.address

weight: 1,
address: await signer.getAddress()
address: (await signer.getAddress()).toLowerCase()
}]

@@ -872,5 +878,6 @@ };

const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat();
const idx = states.findIndex(s => s.chainId === this.authChainId());
const states = (await Promise.all(wallets.map(w => w.wallet.getWalletState()))).flat(); // fetch the current config for the AuthChain, as it will be available
const idx = states.findIndex(s => s.chainId === this.getAuthChainId());
if (idx >= 0) {

@@ -900,5 +907,5 @@ states[idx].config = await this.currentConfig(wallets[idx].wallet);

getProvider(chainId) {
var _this$_wallets$find;
var _this$mainWallet, _this$_wallets$find;
if (!chainId) return this.mainWallet().getProvider();
if (!chainId) return (_this$mainWallet = this.mainWallet()) == null ? void 0 : _this$mainWallet.wallet.getProvider();
return (_this$_wallets$find = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find.wallet.getProvider();

@@ -908,5 +915,5 @@ }

getRelayer(chainId) {
var _this$_wallets$find2;
var _this$mainWallet2, _this$_wallets$find2;
if (!chainId) return this.mainWallet().getRelayer();
if (!chainId) return (_this$mainWallet2 = this.mainWallet()) == null ? void 0 : _this$mainWallet2.wallet.getRelayer();
return (_this$_wallets$find2 = this._wallets.find(w => w.network.chainId === chainId)) == null ? void 0 : _this$_wallets$find2.wallet.getRelayer();

@@ -919,27 +926,45 @@ }

async signAuthMessage(message, allSigners = true) {
return this.signMessage(message, this.authWallet(), allSigners);
}
getAuthChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
} // TODO: maybe rename allSigners to partialSign
async signMessage(message, target, allSigners = true) {
let wallet = (() => {
if (!target) return this.mainWallet();
var _this = this;
let {
wallet,
network
} = await async function () {
// eslint-disable-line
if (!target) {
return _this.mainWallet();
}
if (target.address) {
return target;
const chainId = await target.getChainId();
return _this._wallets.find(w => w.wallet.chainId === chainId);
}
return this.getWalletByNetwork(target).wallet;
})(); // Fetch the latest config of the wallet
// TODO: Skip this step if wallet is authWallet
return _this.getWalletByNetwork(target);
}(); // Fetch the latest config of the wallet.
//
// We skip this step if wallet is authWallet
// TODO: instead, memoize the currentConfig, as below will break
// if we skip
// if (!network.isAuthChain) {
let thisConfig = await this.currentConfig(wallet);
thisConfig = thisConfig ? thisConfig : this._wallets[0].wallet.config;
wallet = wallet.useConfig(thisConfig); // See if wallet has enough signer power
wallet = wallet.useConfig(thisConfig); // }
// See if wallet has enough signer power
const weight = await wallet.signWeight();
if (weight.lt(thisConfig.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${thisConfig.threshold.toString()}`);
if (weight.lt(wallet.config.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${wallet.config.threshold.toString()}`);
}

@@ -950,5 +975,16 @@

async signAuthMessage(message, allSigners = true) {
var _this$authWallet;
return this.signMessage(message, (_this$authWallet = this.authWallet()) == null ? void 0 : _this$authWallet.wallet, allSigners);
}
async signTypedData(domain, types, message, chainId, allSigners = true) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
return wallet.signTypedData(domain, types, message, chainId, allSigners);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
const hash = encodeTypedDataHash({
domain,
types,
message
});
return this.signMessage(hash, wallet, allSigners);
}

@@ -962,3 +998,3 @@

const transaction = await resolveArrayProperties(dtransactionish);
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet(); // TODO: Skip this step if wallet is authWallet
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet; // TODO: Skip this step if wallet is authWallet

@@ -991,3 +1027,3 @@ const [thisConfig, lastConfig] = await Promise.all([this.currentConfig(wallet), this.currentConfig()]); // See if wallet has enough signer power

signTransactions(txs, chainId, allSigners) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.signTransactions(txs, chainId, allSigners);

@@ -997,3 +1033,3 @@ }

async sendSignedTransactions(signedTxs, chainId) {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet();
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet;
return wallet.sendSignedTransactions(signedTxs);

@@ -1005,3 +1041,3 @@ } // updateConfig will build an updated config transaction, update the imageHahs on-chain and also publish

async updateConfig(newConfig) {
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;

@@ -1040,3 +1076,3 @@ if (!newConfig) {

publishConfig() {
return this.authWallet().publishConfig();
return this.authWallet().wallet.publishConfig();
}

@@ -1046,3 +1082,3 @@

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1063,3 +1099,3 @@ if (target.address) {

const wallet = (() => {
if (!target) return this.authWallet();
if (!target) return this.authWallet().wallet;

@@ -1080,3 +1116,3 @@ if (target.address) {

const currentImplementation = ethers.utils.defaultAbiCoder.decode(['address'], ethers.utils.hexZeroPad(await wallet.provider.getStorageAt(address, address).catch(() => ethers.constants.AddressZero), 32))[0];
const authWallet = this.authWallet();
const authWallet = this.authWallet().wallet;
const authContract = new Contract(authWallet.context.sequenceUtils, walletContracts.sequenceUtils.abi, authWallet.provider);

@@ -1144,6 +1180,7 @@ let event;

return this._wallets.find(w => w.network.chainId === networkId);
}
} // mainWallet is the DefaultChain wallet
mainWallet() {
const found = this._wallets.find(w => w.network.isDefaultChain).wallet;
const found = this._wallets.find(w => w.network.isDefaultChain);

@@ -1154,7 +1191,8 @@ if (!found) {

return found; // return found ? found : this._wallets[0].wallet
}
return found;
} // authWallet is the AuthChain wallet
authWallet() {
const found = this._wallets.find(w => w.network.isAuthChain).wallet;
const found = this._wallets.find(w => w.network.isAuthChain);

@@ -1168,10 +1206,2 @@ if (!found) {

authChainId() {
let n = this.options.networks[0];
if (n.isAuthChain) return n.chainId;
n = this.options.networks[1];
if (n.isAuthChain) return n.chainId;
throw new Error('expecting authChain to be the first or second in networks list');
}
setNetworks(mainnetNetworks, testnetNetworks = [], defaultChainId) {

@@ -1178,0 +1208,0 @@ let networks = []; // find chain between mainnet and testnet network groups, and set that network group.

@@ -32,4 +32,5 @@ import { TransactionResponse, TransactionRequest, JsonRpcProvider, Provider } from '@ethersproject/providers';

getNetworks(): Promise<NetworkConfig[]>;
getAuthChainId(): number;
signMessage(message: BytesLike, target?: Wallet | ChainId, allSigners?: boolean): Promise<string>;
signAuthMessage(message: BytesLike, allSigners?: boolean): Promise<string>;
signMessage(message: BytesLike, target?: Wallet | ChainId, allSigners?: boolean): Promise<string>;
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainId, allSigners?: boolean): Promise<string>;

@@ -52,5 +53,10 @@ _signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainId, allSigners?: boolean): Promise<string>;

};
mainWallet(): Wallet;
authWallet(): Wallet;
authChainId(): number;
mainWallet(): {
wallet: Wallet;
network: NetworkConfig;
};
authWallet(): {
wallet: Wallet;
network: NetworkConfig;
};
setNetworks(mainnetNetworks: Networks, testnetNetworks?: Networks, defaultChainId?: string | number): void;

@@ -57,0 +63,0 @@ connect(_: Provider): AbstractSigner;

{
"name": "@0xsequence/wallet",
"version": "0.8.2",
"version": "0.8.3",
"description": "wallet sub-package for Sequence",

@@ -17,10 +17,10 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/wallet",

"dependencies": {
"@0xsequence/abi": "^0.8.2",
"@0xsequence/api": "^0.8.2",
"@0xsequence/config": "^0.8.2",
"@0xsequence/guard": "^0.8.2",
"@0xsequence/network": "^0.8.2",
"@0xsequence/relayer": "^0.8.2",
"@0xsequence/transactions": "^0.8.2",
"@0xsequence/utils": "^0.8.2",
"@0xsequence/abi": "^0.8.3",
"@0xsequence/api": "^0.8.3",
"@0xsequence/config": "^0.8.3",
"@0xsequence/guard": "^0.8.3",
"@0xsequence/network": "^0.8.3",
"@0xsequence/relayer": "^0.8.3",
"@0xsequence/transactions": "^0.8.3",
"@0xsequence/utils": "^0.8.3",
"@ethersproject/abi": "^5.0.10",

@@ -27,0 +27,0 @@ "@ethersproject/properties": "^5.0.7",

@@ -13,2 +13,3 @@ import { TransactionResponse, TransactionRequest, JsonRpcProvider, Provider } from '@ethersproject/providers'

import { Relayer, RpcRelayer } from '@0xsequence/relayer'
import { encodeTypedDataHash } from '@0xsequence/utils'

@@ -87,3 +88,4 @@ export interface AccountOptions {

const idx = states.findIndex(s => s.chainId === this.authChainId())
// fetch the current config for the AuthChain, as it will be available
const idx = states.findIndex(s => s.chainId === this.getAuthChainId())
if (idx >= 0) {

@@ -113,3 +115,3 @@ states[idx].config = await this.currentConfig(wallets[idx].wallet)

getProvider(chainId?: number): Promise<JsonRpcProvider | undefined> {
if (!chainId) return this.mainWallet().getProvider()
if (!chainId) return this.mainWallet()?.wallet.getProvider()
return this._wallets.find(w => w.network.chainId === chainId)?.wallet.getProvider()

@@ -119,3 +121,3 @@ }

getRelayer(chainId?: number): Promise<Relayer | undefined> {
if (!chainId) return this.mainWallet().getRelayer()
if (!chainId) return this.mainWallet()?.wallet.getRelayer()
return this._wallets.find(w => w.network.chainId === chainId)?.wallet.getRelayer()

@@ -128,26 +130,38 @@ }

async signAuthMessage(message: BytesLike, allSigners: boolean = true): Promise<string> {
return this.signMessage(message, this.authWallet(), allSigners)
getAuthChainId(): number {
let n = this.options.networks[0]
if (n.isAuthChain) return n.chainId
n = this.options.networks[1]
if (n.isAuthChain) return n.chainId
throw new Error('expecting authChain to be the first or second in networks list')
}
// TODO: maybe rename allSigners to partialSign
async signMessage(message: BytesLike, target?: Wallet | ChainId, allSigners: boolean = true): Promise<string> {
let wallet = (() => {
if (!target) return this.mainWallet()
let { wallet, network } = await (async () => { // eslint-disable-line
if (!target) {
return this.mainWallet()
}
if ((<Wallet>target).address) {
return target as Wallet
const chainId = await ((<Wallet>target).getChainId())
return this._wallets.find(w => w.wallet.chainId === chainId)
}
return this.getWalletByNetwork(target as NetworkConfig).wallet
return this.getWalletByNetwork(target as NetworkConfig)
})()
// Fetch the latest config of the wallet
// TODO: Skip this step if wallet is authWallet
let thisConfig = await this.currentConfig(wallet)
thisConfig = thisConfig ? thisConfig : this._wallets[0].wallet.config
// Fetch the latest config of the wallet.
//
// We skip this step if wallet is authWallet
// TODO: instead, memoize the currentConfig, as below will break
// if we skip
// if (!network.isAuthChain) {
let thisConfig = await this.currentConfig(wallet)
thisConfig = thisConfig ? thisConfig : this._wallets[0].wallet.config
wallet = wallet.useConfig(thisConfig)
// }
wallet = wallet.useConfig(thisConfig)
// See if wallet has enough signer power
const weight = await wallet.signWeight()
if (weight.lt(thisConfig.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${thisConfig.threshold.toString()}`)
if (weight.lt(wallet.config.threshold) && allSigners) {
throw new NotEnoughSigners(`Sign message - wallet combined weight ${weight.toString()} below required ${wallet.config.threshold.toString()}`)
}

@@ -158,5 +172,10 @@

async signAuthMessage(message: BytesLike, allSigners: boolean = true): Promise<string> {
return this.signMessage(message, this.authWallet()?.wallet, allSigners)
}
async signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainId, allSigners: boolean = true): Promise<string> {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet()
return wallet.signTypedData(domain, types, message, chainId, allSigners)
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet
const hash = encodeTypedDataHash({ domain, types, message })
return this.signMessage(hash, wallet, allSigners)
}

@@ -170,3 +189,3 @@

const transaction = await resolveArrayProperties<Transactionish>(dtransactionish)
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet()
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet

@@ -205,3 +224,3 @@ // TODO: Skip this step if wallet is authWallet

signTransactions(txs: Deferrable<Transactionish>, chainId?: ChainId, allSigners?: boolean): Promise<SignedTransactions> {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet()
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet
return wallet.signTransactions(txs, chainId, allSigners)

@@ -211,3 +230,3 @@ }

async sendSignedTransactions(signedTxs: SignedTransactions, chainId?: ChainId): Promise<TransactionResponse> {
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet()
const wallet = chainId ? this.getWalletByNetwork(chainId).wallet : this.mainWallet().wallet
return wallet.sendSignedTransactions(signedTxs)

@@ -219,3 +238,3 @@ }

async updateConfig(newConfig?: WalletConfig): Promise<[WalletConfig, TransactionResponse | undefined]> {
const authWallet = this.authWallet()
const authWallet = this.authWallet().wallet

@@ -256,3 +275,3 @@ if (!newConfig) {

publishConfig(): Promise<TransactionResponse> {
return this.authWallet().publishConfig()
return this.authWallet().wallet.publishConfig()
}

@@ -262,3 +281,3 @@

const wallet = (() => {
if (!target) return this.authWallet()
if (!target) return this.authWallet().wallet
if ((<Wallet>target).address) {

@@ -276,3 +295,3 @@ return target as Wallet

const wallet = (() => {
if (!target) return this.authWallet()
if (!target) return this.authWallet().wallet
if ((<Wallet>target).address) {

@@ -299,3 +318,3 @@ return target as Wallet

const authWallet = this.authWallet()
const authWallet = this.authWallet().wallet
const authContract = new Contract(authWallet.context.sequenceUtils, walletContracts.sequenceUtils.abi, authWallet.provider)

@@ -359,4 +378,5 @@

mainWallet(): Wallet {
const found = this._wallets.find(w => w.network.isDefaultChain).wallet
// mainWallet is the DefaultChain wallet
mainWallet(): { wallet: Wallet, network: NetworkConfig } {
const found = this._wallets.find(w => w.network.isDefaultChain)
if (!found) {

@@ -366,7 +386,7 @@ throw new Error('mainWallet not found')

return found
// return found ? found : this._wallets[0].wallet
}
authWallet(): Wallet {
const found = this._wallets.find(w => w.network.isAuthChain).wallet
// authWallet is the AuthChain wallet
authWallet(): { wallet: Wallet, network: NetworkConfig } {
const found = this._wallets.find(w => w.network.isAuthChain)
if (!found) {

@@ -378,10 +398,2 @@ throw new Error('authChain wallet not found')

authChainId(): number {
let n = this.options.networks[0]
if (n.isAuthChain) return n.chainId
n = this.options.networks[1]
if (n.isAuthChain) return n.chainId
throw new Error('expecting authChain to be the first or second in networks list')
}
setNetworks(mainnetNetworks: Networks, testnetNetworks: Networks = [], defaultChainId?: string | number) {

@@ -388,0 +400,0 @@ let networks: Networks = []

@@ -36,3 +36,3 @@ import { BytesLike, ethers, Contract } from 'ethers'

weight: s.weight,
address: recoverSigner(digest, s as DecodedSigner)
address: recoverSigner(digest, s as DecodedSigner).toLowerCase()
}

@@ -42,3 +42,3 @@ } else {

weight: s.weight,
address: (<DecodedOwner>s).address
address: (<DecodedOwner>s).address.toLowerCase()
}

@@ -45,0 +45,0 @@ }

@@ -44,2 +44,4 @@ import {

import { encodeTypedDataHash } from '@0xsequence/utils'
import { joinSignatures } from './config'

@@ -118,3 +120,3 @@

this.config = sortConfig(config)
this.config = sortConfig(config, true)
this._signers = signers.map(s => (AbstractSigner.isSigner(s) ? s : new ethers.Wallet(s)))

@@ -206,6 +208,9 @@ }

imageHash: this.imageHash,
currentImageHash: isDeployed ? await fetchImageHash(this) : undefined,
publishedImageHash: isDeployed ? await fetchImageHash(this) : undefined,
publishedLatest: false
}
// TODO: check if its published
if (state.publishedImageHash && state.publishedImageHash.length > 0 && state.imageHash === state.publishedImageHash) {
state.publishedLatest = true
}

@@ -244,3 +249,3 @@ return [state]

}
return Promise.all(this._signers.map(s => s.getAddress()))
return Promise.all(this._signers.map(s => s.getAddress().then(s => s.toLowerCase())))
}

@@ -381,6 +386,3 @@

// remove EIP712Domain key from types as ethers will auto-gen it
delete types['EIP712Domain']
const hash = ethers.utils._TypedDataEncoder.hash(domain, types, message)
const hash = encodeTypedDataHash({ domain, types, message })
return this.signMessage(ethers.utils.arrayify(hash), signChainId, allSigners)

@@ -409,3 +411,3 @@ }

const signWith = async (signers: AbstractSigner[], auxData?: string) => {
const signersAddr = Promise.all(signers.map(s => s.getAddress()))
const signersAddr = Promise.all(signers.map(s => s.getAddress().then(s => s.toLowerCase())))

@@ -573,3 +575,3 @@ const accountBytes = await Promise.all(

config.threshold,
sortConfig(config).signers.map((s) => ({
sortConfig(config, true).signers.map((s) => ({
weight: s.weight,

@@ -624,3 +626,3 @@ signer: s.address

weight: 1,
address: await signer.getAddress()
address: (await signer.getAddress()).toLowerCase()
}

@@ -627,0 +629,0 @@ ]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc