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

@0xsequence/account

Package Overview
Dependencies
Maintainers
5
Versions
301
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xsequence/account - npm Package Compare versions

Comparing version 0.0.0-20230621214515 to 0.0.0-20230621215727

11

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

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

var migration = require('@0xsequence/migration');
var network = require('@0xsequence/network');
var relayer = require('@0xsequence/relayer');

@@ -99,4 +100,4 @@ var utils = require('@0xsequence/utils');

if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`);
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(found.rpcUrl, {
name: "",
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(network.getDefaultConnectionInfo(found.rpcUrl), {
name: '',
chainId: ethers.ethers.BigNumber.from(chainId).toNumber()

@@ -349,8 +350,8 @@ });

* for that wallet to start working with the given version.
*
*
* This usually involves: (a) deploying the wallet, (b) executing migrations
*
*
* Notice: It should NOT explicitly include chained signatures. Unless internally used
* by any of the migrations.
*
*
*/

@@ -357,0 +358,0 @@ buildBootstrapTransactions(status, chainId) {

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

var migration = require('@0xsequence/migration');
var network = require('@0xsequence/network');
var relayer = require('@0xsequence/relayer');

@@ -99,4 +100,4 @@ var utils = require('@0xsequence/utils');

if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`);
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(found.rpcUrl, {
name: "",
return found.provider || new ethers.ethers.providers.StaticJsonRpcProvider(network.getDefaultConnectionInfo(found.rpcUrl), {
name: '',
chainId: ethers.ethers.BigNumber.from(chainId).toNumber()

@@ -349,8 +350,8 @@ });

* for that wallet to start working with the given version.
*
*
* This usually involves: (a) deploying the wallet, (b) executing migrations
*
*
* Notice: It should NOT explicitly include chained signatures. Unless internally used
* by any of the migrations.
*
*
*/

@@ -357,0 +358,0 @@ buildBootstrapTransactions(status, chainId) {

import { commons, universal } from '@0xsequence/core';
import { defaults, migrator, version } from '@0xsequence/migration';
import { getDefaultConnectionInfo } from '@0xsequence/network';
import { isRelayer, RpcRelayer } from '@0xsequence/relayer';

@@ -94,4 +95,4 @@ import { encodeTypedDataDigest } from '@0xsequence/utils';

if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`);
return found.provider || new ethers.providers.StaticJsonRpcProvider(found.rpcUrl, {
name: "",
return found.provider || new ethers.providers.StaticJsonRpcProvider(getDefaultConnectionInfo(found.rpcUrl), {
name: '',
chainId: ethers.BigNumber.from(chainId).toNumber()

@@ -344,8 +345,8 @@ });

* for that wallet to start working with the given version.
*
*
* This usually involves: (a) deploying the wallet, (b) executing migrations
*
*
* Notice: It should NOT explicitly include chained signatures. Unless internally used
* by any of the migrations.
*
*
*/

@@ -352,0 +353,0 @@ buildBootstrapTransactions(status, chainId) {

{
"name": "@0xsequence/account",
"version": "0.0.0-20230621214515",
"version": "0.0.0-20230621215727",
"description": "tools for migrating sequence wallets to new versions",

@@ -13,9 +13,9 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/account",

"ethers": "^5.5.2",
"@0xsequence/core": "0.0.0-20230621214515",
"@0xsequence/migration": "0.0.0-20230621214515",
"@0xsequence/network": "0.0.0-20230621214515",
"@0xsequence/relayer": "0.0.0-20230621214515",
"@0xsequence/sessions": "0.0.0-20230621214515",
"@0xsequence/wallet": "0.0.0-20230621214515",
"@0xsequence/utils": "0.0.0-20230621214515"
"@0xsequence/core": "0.0.0-20230621215727",
"@0xsequence/migration": "0.0.0-20230621215727",
"@0xsequence/network": "0.0.0-20230621215727",
"@0xsequence/relayer": "0.0.0-20230621215727",
"@0xsequence/sessions": "0.0.0-20230621215727",
"@0xsequence/utils": "0.0.0-20230621215727",
"@0xsequence/wallet": "0.0.0-20230621215727"
},

@@ -25,4 +25,4 @@ "devDependencies": {

"nyc": "^15.1.0",
"@0xsequence/signhub": "0.0.0-20230621214515",
"@0xsequence/tests": "0.0.0-20230621214515"
"@0xsequence/signhub": "0.0.0-20230621215727",
"@0xsequence/tests": "0.0.0-20230621215727"
},

@@ -29,0 +29,0 @@ "files": [

import { commons, universal } from '@0xsequence/core'
import { migrator, defaults, version } from '@0xsequence/migration'
import { NetworkConfig } from '@0xsequence/network'
import { NetworkConfig, getDefaultConnectionInfo } from '@0xsequence/network'
import { FeeOption, FeeQuote, isRelayer, Relayer, RpcRelayer } from '@0xsequence/relayer'

@@ -13,20 +13,20 @@ import { tracker } from '@0xsequence/sessions'

original: {
version: number,
imageHash: string,
version: number
imageHash: string
context: commons.context.WalletContext
}
onChain: {
imageHash: string,
config: commons.config.Config,
version: number,
imageHash: string
config: commons.config.Config
version: number
deployed: boolean
},
fullyMigrated: boolean,
signedMigrations: migrator.SignedMigration[],
version: number,
presignedConfigurations: tracker.PresignedConfigLink[],
imageHash: string,
config: commons.config.Config,
checkpoint: ethers.BigNumberish,
canOnchainValidate: boolean,
}
fullyMigrated: boolean
signedMigrations: migrator.SignedMigration[]
version: number
presignedConfigurations: tracker.PresignedConfigLink[]
imageHash: string
config: commons.config.Config
checkpoint: ethers.BigNumberish
canOnchainValidate: boolean
}

@@ -36,3 +36,3 @@

// The only unique identifier for a wallet is the address
address: string,
address: string

@@ -42,3 +42,3 @@ // The config tracker keeps track of chained configs,

// it must implement both the ConfigTracker and MigrationTracker
tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker,
tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker

@@ -106,14 +106,10 @@ // Versioned contexts contains the context information for each Sequence version

static async new(options: {
config: commons.config.SimpleConfig,
tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker,
contexts: commons.context.VersionedContext,
orchestrator: Orchestrator,
networks: NetworkConfig[],
config: commons.config.SimpleConfig
tracker: tracker.ConfigTracker & migrator.PresignedMigrationTracker
contexts: commons.context.VersionedContext
orchestrator: Orchestrator
networks: NetworkConfig[]
migrations?: migrator.Migrations
}): Promise<Account> {
const mig = new migrator.Migrator(
options.tracker,
options.migrations ?? defaults.DefaultMigrations,
options.contexts
)
const mig = new migrator.Migrator(options.tracker, options.migrations ?? defaults.DefaultMigrations, options.contexts)

@@ -149,4 +145,4 @@ const lastMigration = mig.lastMigration()

get coders(): {
signature: commons.signature.SignatureCoder,
config: commons.config.ConfigCoder,
signature: commons.signature.SignatureCoder
config: commons.config.ConfigCoder
} {

@@ -163,3 +159,3 @@ const lastMigration = this.migrator.lastMigration()

const tcid = ethers.BigNumber.from(chainId)
const found = this.networks.find((n) => tcid.eq(n.chainId))
const found = this.networks.find(n => tcid.eq(n.chainId))
if (!found) throw new Error(`Network not found for chainId ${chainId}`)

@@ -172,3 +168,9 @@ return found

if (!found.provider && !found.rpcUrl) throw new Error(`Provider not found for chainId ${chainId}`)
return found.provider || new ethers.providers.StaticJsonRpcProvider(found.rpcUrl, { name: "", chainId: ethers.BigNumber.from(chainId).toNumber() })
return (
found.provider ||
new ethers.providers.StaticJsonRpcProvider(getDefaultConnectionInfo(found.rpcUrl), {
name: '',
chainId: ethers.BigNumber.from(chainId).toNumber()
})
)
}

@@ -201,13 +203,5 @@

walletForStatus(
chainId: ethers.BigNumberish,
status: Pick<AccountStatus, 'version'> & Pick<AccountStatus, 'config'>
): Wallet {
walletForStatus(chainId: ethers.BigNumberish, status: Pick<AccountStatus, 'version'> & Pick<AccountStatus, 'config'>): Wallet {
const coder = universal.coderFor(status.version)
return this.walletFor(
chainId,
this.contextFor(status.version),
status.config,
coder,
)
return this.walletFor(chainId, this.contextFor(status.version), status.config, coder)
}

@@ -230,3 +224,3 @@

orchestrator: this.orchestrator,
reader: this.reader(chainId),
reader: this.reader(chainId)
})

@@ -243,16 +237,14 @@ }

const isDeployedPromise = this.reader(chainId).isDeployed(this.address)
const counterfactualImageHashPromise = this.tracker.imageHashOfCounterfactualWallet({
wallet: this.address
}).then((r) => {
if (!r) throw new Error(`Counterfactual imageHash not found for wallet ${this.address}`)
return r
})
const counterFactualVersionPromise = counterfactualImageHashPromise.then((r) => {
return version.counterfactualVersion(
this.address,
r.imageHash,
Object.values(this.contexts),
)
const counterfactualImageHashPromise = this.tracker
.imageHashOfCounterfactualWallet({
wallet: this.address
})
.then(r => {
if (!r) throw new Error(`Counterfactual imageHash not found for wallet ${this.address}`)
return r
})
const counterFactualVersionPromise = counterfactualImageHashPromise.then(r => {
return version.counterfactualVersion(this.address, r.imageHash, Object.values(this.contexts))
})

@@ -351,6 +343,3 @@

checkpoint,
canOnchainValidate: (
onChainVersion === this.version &&
isDeployed
)
canOnchainValidate: onChainVersion === this.version && isDeployed
}

@@ -368,3 +357,3 @@ }

status: AccountStatus,
chainId: ethers.BigNumberish,
chainId: ethers.BigNumberish
): Promise<commons.transaction.Transactionish> {

@@ -377,3 +366,3 @@ // if onchain wallet config is not up to date

const updateConfig = await wallet.buildUpdateConfigurationTransaction(status.config)
return [(Array.isArray(txs) ? txs : [txs]), updateConfig.transactions].flat()
return [Array.isArray(txs) ? txs : [txs], updateConfig.transactions].flat()
}

@@ -386,3 +375,3 @@

bundle: commons.transaction.IntendedTransactionBundle,
status: AccountStatus,
status: AccountStatus
): commons.transaction.IntendedTransactionBundle {

@@ -400,3 +389,3 @@ const bootstrapBundle = this.buildBootstrapTransactions(status, bundle.chainId)

...bootstrapBundle.transactions,
{
{
to: bundle.entrypoint,

@@ -415,3 +404,3 @@ data: commons.transaction.encodeBundleExecData(bundle),

signature: T,
status: Partial<Pick<AccountStatus, 'presignedConfigurations'>>,
status: Partial<Pick<AccountStatus, 'presignedConfigurations'>>
): T | string {

@@ -424,3 +413,3 @@ if (!status.presignedConfigurations || status.presignedConfigurations.length === 0) {

const chain = status.presignedConfigurations.map((c) => c.signature)
const chain = status.presignedConfigurations.map(c => c.signature)
const chainedSignature = coder.chainSignatures(signature, chain)

@@ -438,7 +427,3 @@ return coder.encode(chainedSignature)

async signDigest(
digest: ethers.BytesLike,
chainId: ethers.BigNumberish,
decorate: boolean = true
): Promise<string> {
async signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate: boolean = true): Promise<string> {
// If we are signing a digest for chainId zero then we can never be fully migrated

@@ -462,10 +447,8 @@ // because Sequence v1 doesn't allow for signing a message on "all chains"

async editConfig(
changes: {
add?: commons.config.SimpleSigner[];
remove?: string[];
threshold?: ethers.BigNumberish;
}
): Promise<void> {
const currentConfig = await this.status(0).then((s) => s.config)
async editConfig(changes: {
add?: commons.config.SimpleSigner[]
remove?: string[]
threshold?: ethers.BigNumberish
}): Promise<void> {
const currentConfig = await this.status(0).then(s => s.config)
const newConfig = this.coders.config.editConfig(currentConfig, {

@@ -479,5 +462,3 @@ ...changes,

async updateConfig(
config: commons.config.Config
): Promise<void> {
async updateConfig(config: commons.config.Config): Promise<void> {
// config should be for the current version of the wallet

@@ -508,13 +489,10 @@ if (!this.coders.config.isWalletConfig(config)) {

* for that wallet to start working with the given version.
*
*
* This usually involves: (a) deploying the wallet, (b) executing migrations
*
*
* Notice: It should NOT explicitly include chained signatures. Unless internally used
* by any of the migrations.
*
*
*/
buildBootstrapTransactions(
status: AccountStatus,
chainId: ethers.BigNumberish
): commons.transaction.IntendedTransactionBundle {
buildBootstrapTransactions(status: AccountStatus, chainId: ethers.BigNumberish): commons.transaction.IntendedTransactionBundle {
const transactions: commons.transaction.Transaction[] = []

@@ -526,6 +504,3 @@

// so we need to use the context to get the correct deployment
const deployTransaction = Wallet.buildDeployTransaction(
status.original.context,
status.original.imageHash
)
const deployTransaction = Wallet.buildDeployTransaction(status.original.context, status.original.imageHash)

@@ -536,10 +511,12 @@ transactions.push(...deployTransaction.transactions)

// Get pending migrations
transactions.push(...status.signedMigrations.map((m) => ({
to: m.tx.entrypoint,
data: commons.transaction.encodeBundleExecData(m.tx),
value: 0,
gasLimit: 0,
revertOnError: true,
delegateCall: false
})))
transactions.push(
...status.signedMigrations.map(m => ({
to: m.tx.entrypoint,
data: commons.transaction.encodeBundleExecData(m.tx),
value: 0,
gasLimit: 0,
revertOnError: true,
delegateCall: false
}))
)

@@ -550,5 +527,6 @@ // Build the transaction intent, if the transaction has migrations

// ... but this may fail if the relayer uses a different GuestModule
const id = status.signedMigrations.length > 0
? status.signedMigrations[0].tx.intent.id
: commons.transaction.subdigestOfGuestModuleTransactions(this.contexts[this.version].guestModule, chainId, transactions)
const id =
status.signedMigrations.length > 0
? status.signedMigrations[0].tx.intent.id
: commons.transaction.subdigestOfGuestModuleTransactions(this.contexts[this.version].guestModule, chainId, transactions)

@@ -565,11 +543,7 @@ // Everything is encoded as a bundle

): Promise<Omit<commons.transaction.IntendedTransactionBundle, 'chainId'>> {
const status = prestatus || await this.status(chainId)
const status = prestatus || (await this.status(chainId))
return this.buildBootstrapTransactions(status, chainId)
}
async doBootstrap(
chainId: ethers.BigNumberish,
feeQuote?: FeeQuote,
prestatus?: AccountStatus
) {
async doBootstrap(chainId: ethers.BigNumberish, feeQuote?: FeeQuote, prestatus?: AccountStatus) {
const bootstrapTxs = await this.bootstrapTransactions(chainId, prestatus)

@@ -588,3 +562,3 @@ return this.relayer(chainId).relay({ ...bootstrapTxs, chainId }, feeQuote)

): Promise<commons.transaction.SignedTransactionBundle> {
const status = pstatus || await this.status(chainId)
const status = pstatus || (await this.status(chainId))
this.mustBeFullyMigrated(status)

@@ -601,3 +575,6 @@

async signMigrations(chainId: ethers.BigNumberish, editConfig: (prevConfig: commons.config.Config) => commons.config.Config): Promise<boolean> {
async signMigrations(
chainId: ethers.BigNumberish,
editConfig: (prevConfig: commons.config.Config) => commons.config.Config
): Promise<boolean> {
const status = await this.status(chainId)

@@ -616,6 +593,6 @@ if (status.fullyMigrated) return false

editConfig: (prevConfig: commons.config.Config) => commons.config.Config
): Promise<{ signedMigrations: Array<any>, failedChains: number[] }> {
): Promise<{ signedMigrations: Array<any>; failedChains: number[] }> {
const failedChains: number[] = []
const signedMigrations = await Promise.all(
this.networks.map(async (n) => {
this.networks.map(async n => {
try {

@@ -632,15 +609,15 @@ // Signing migrations for each chain

}
}),
})
)
// Filter out null values to get only the successful signed migrations
const successfulSignedMigrations = signedMigrations.filter((migration) => migration !== null)
const successfulSignedMigrations = signedMigrations.filter(migration => migration !== null)
return { signedMigrations: successfulSignedMigrations, failedChains }
}
async isMigratedAllChains(): Promise<{ migratedAllChains: boolean, failedChains: number[] }> {
async isMigratedAllChains(): Promise<{ migratedAllChains: boolean; failedChains: number[] }> {
const failedChains: number[] = []
const statuses = await Promise.all(
this.networks.map(async (n) => {
this.networks.map(async n => {
try {

@@ -656,6 +633,6 @@ return await this.status(n.chainId)

}
}),
})
)
const migratedAllChains = statuses.every((s) => s.fullyMigrated)
const migratedAllChains = statuses.every(s => s.fullyMigrated)
return { migratedAllChains, failedChains }

@@ -670,3 +647,3 @@ }

): Promise<ethers.providers.TransactionResponse> {
const status = pstatus || await this.status(signedBundle.chainId)
const status = pstatus || (await this.status(signedBundle.chainId))
this.mustBeFullyMigrated(status)

@@ -684,3 +661,3 @@

): Promise<commons.transaction.SimulatedTransaction[]> {
const wallet = this.walletForStatus(chainId, status || await this.status(chainId))
const wallet = this.walletForStatus(chainId, status || (await this.status(chainId)))
return wallet.fillGasLimits(txs)

@@ -695,8 +672,7 @@ }

): Promise<{
options: FeeOption[];
quote?: FeeQuote,
options: FeeOption[]
quote?: FeeQuote
decorated: commons.transaction.IntendedTransactionBundle
}> {
const wstatus = status || await this.status(chainId)
const wstatus = status || (await this.status(chainId))
const wallet = this.walletForStatus(chainId, wstatus)

@@ -718,3 +694,3 @@

id: intentId,
wallet: this.address,
wallet: this.address
},

@@ -734,9 +710,9 @@ signature: stubSignature,

async prepareTransactions(args: {
txs: commons.transaction.Transactionish,
chainId: ethers.BigNumberish,
txs: commons.transaction.Transactionish
chainId: ethers.BigNumberish
stubSignatureOverrides: Map<string, string>
}): Promise<{
transactions: commons.transaction.SimulatedTransaction[],
flatDecorated: commons.transaction.Transaction[],
options: FeeOption[],
transactions: commons.transaction.SimulatedTransaction[]
flatDecorated: commons.transaction.Transaction[]
options: FeeOption[]
quote?: FeeQuote

@@ -782,12 +758,14 @@ }> {

async getAllSigners(): Promise<{
address: string,
weight: number,
network: number,
flaggedForRemoval: boolean
}[]> {
async getAllSigners(): Promise<
{
address: string
weight: number
network: number
flaggedForRemoval: boolean
}[]
> {
const allSigners: {
address: string,
weight: number,
network: number,
address: string
weight: number
network: number
flaggedForRemoval: boolean

@@ -797,51 +775,52 @@ }[] = []

// We need to get the signers for each status
await Promise.all(this.networks.map(async network => {
const chainId = network.chainId
await Promise.all(
this.networks.map(async network => {
const chainId = network.chainId
// Getting the status with `longestPath` set to true will give us all the possible configurations
// between the current onChain config and the latest config, including the ones "flagged for removal"
const status = await this.status(chainId, true)
// Getting the status with `longestPath` set to true will give us all the possible configurations
// between the current onChain config and the latest config, including the ones "flagged for removal"
const status = await this.status(chainId, true)
const fullChain = [
status.onChain.imageHash,
...(
status.onChain.version !== status.version ? status.signedMigrations.map((m) => universal.coderFor(m.toVersion).config.imageHashOf(m.toConfig as any)) : []
),
...status.presignedConfigurations.map((update) => update.nextImageHash)
]
const fullChain = [
status.onChain.imageHash,
...(status.onChain.version !== status.version
? status.signedMigrations.map(m => universal.coderFor(m.toVersion).config.imageHashOf(m.toConfig as any))
: []),
...status.presignedConfigurations.map(update => update.nextImageHash)
]
return Promise.all(fullChain.map(async (nextImageHash, iconf) => {
const isLast = iconf === fullChain.length - 1
const config = await this.tracker.configOfImageHash({ imageHash: nextImageHash })
return Promise.all(
fullChain.map(async (nextImageHash, iconf) => {
const isLast = iconf === fullChain.length - 1
const config = await this.tracker.configOfImageHash({ imageHash: nextImageHash })
if (!config) {
console.warn(`AllSigners may be incomplete, config not found for imageHash ${nextImageHash}`)
return
}
if (!config) {
console.warn(`AllSigners may be incomplete, config not found for imageHash ${nextImageHash}`)
return
}
const coder = universal.genericCoderFor(config.version)
const signers = coder.config.signersOf(config)
const coder = universal.genericCoderFor(config.version)
const signers = coder.config.signersOf(config)
signers.forEach((signer) => {
const exists = allSigners.find((s) => (
s.address === signer.address &&
s.network === chainId
))
signers.forEach(signer => {
const exists = allSigners.find(s => s.address === signer.address && s.network === chainId)
if (exists && isLast && exists.flaggedForRemoval) {
exists.flaggedForRemoval = false
return
}
if (exists && isLast && exists.flaggedForRemoval) {
exists.flaggedForRemoval = false
return
}
if (exists) return
if (exists) return
allSigners.push({
address: signer.address,
weight: signer.weight,
network: chainId,
flaggedForRemoval: !isLast
allSigners.push({
address: signer.address,
weight: signer.weight,
network: chainId,
flaggedForRemoval: !isLast
})
})
})
})
}))
}))
)
})
)

@@ -848,0 +827,0 @@ return allSigners

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