@0xsequence/account
Advanced tools
Comparing version 0.0.0-20230704142612 to 0.0.0-20230706234338
@@ -300,3 +300,3 @@ 'use strict'; | ||
} | ||
async signDigest(digest, chainId, decorate = true) { | ||
async signDigest(digest, chainId, decorate = true, cantValidateBehavior = 'ignore') { | ||
// If we are signing a digest for chainId zero then we can never be fully migrated | ||
@@ -312,6 +312,36 @@ // because Sequence v1 doesn't allow for signing a message on "all chains" | ||
this.mustBeFullyMigrated(status); | ||
// Check if we can validate onchain and what to do if we can't | ||
// revert early, since there is no point in signing a digest now | ||
if (!status.canOnchainValidate && cantValidateBehavior === 'throw') { | ||
throw new Error('Wallet cannot validate onchain'); | ||
} | ||
const wallet = this.walletForStatus(chainId, status); | ||
const signature = await wallet.signDigest(digest); | ||
return decorate ? this.decorateSignature(signature, status) : signature; | ||
const decorated = decorate ? this.decorateSignature(signature, status) : signature; | ||
// If the wallet can't validate onchain then we | ||
// need to prefix the decorated signature with all deployments and migrations | ||
// aka doing a bootstrap using EIP-6492 | ||
if (!status.canOnchainValidate) { | ||
switch (cantValidateBehavior) { | ||
// NOTICE: We covered this case before signing the digest | ||
// case 'throw': | ||
// throw new Error('Wallet cannot validate on-chain') | ||
case 'ignore': | ||
return decorated; | ||
case 'eip6492': | ||
return this.buildEIP6492Signature(await decorated, status, chainId); | ||
} | ||
} | ||
return decorated; | ||
} | ||
buildEIP6492Signature(signature, status, chainId) { | ||
const bootstrapBundle = this.buildBootstrapTransactions(status, chainId); | ||
if (bootstrapBundle.transactions.length === 0) { | ||
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions'); | ||
} | ||
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]); | ||
} | ||
async editConfig(changes) { | ||
@@ -418,4 +448,4 @@ const currentConfig = await this.status(0).then(s => s.config); | ||
} | ||
signMessage(message, chainId) { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId); | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -565,3 +595,3 @@ async signTransactions(txs, chainId, pstatus) { | ||
} | ||
async signTypedData(domain, types, message, chainId) { | ||
async signTypedData(domain, types, message, chainId, cantValidateBehavior = 'ignore') { | ||
const digest = utils.encodeTypedDataDigest({ | ||
@@ -572,3 +602,3 @@ domain, | ||
}); | ||
return this.signDigest(digest, chainId); | ||
return this.signDigest(digest, chainId, true, cantValidateBehavior); | ||
} | ||
@@ -617,3 +647,7 @@ async getAllSigners() { | ||
} | ||
function isAccount(value) { | ||
return value instanceof Account; | ||
} | ||
exports.Account = Account; | ||
exports.isAccount = isAccount; |
@@ -300,3 +300,3 @@ 'use strict'; | ||
} | ||
async signDigest(digest, chainId, decorate = true) { | ||
async signDigest(digest, chainId, decorate = true, cantValidateBehavior = 'ignore') { | ||
// If we are signing a digest for chainId zero then we can never be fully migrated | ||
@@ -312,6 +312,36 @@ // because Sequence v1 doesn't allow for signing a message on "all chains" | ||
this.mustBeFullyMigrated(status); | ||
// Check if we can validate onchain and what to do if we can't | ||
// revert early, since there is no point in signing a digest now | ||
if (!status.canOnchainValidate && cantValidateBehavior === 'throw') { | ||
throw new Error('Wallet cannot validate onchain'); | ||
} | ||
const wallet = this.walletForStatus(chainId, status); | ||
const signature = await wallet.signDigest(digest); | ||
return decorate ? this.decorateSignature(signature, status) : signature; | ||
const decorated = decorate ? this.decorateSignature(signature, status) : signature; | ||
// If the wallet can't validate onchain then we | ||
// need to prefix the decorated signature with all deployments and migrations | ||
// aka doing a bootstrap using EIP-6492 | ||
if (!status.canOnchainValidate) { | ||
switch (cantValidateBehavior) { | ||
// NOTICE: We covered this case before signing the digest | ||
// case 'throw': | ||
// throw new Error('Wallet cannot validate on-chain') | ||
case 'ignore': | ||
return decorated; | ||
case 'eip6492': | ||
return this.buildEIP6492Signature(await decorated, status, chainId); | ||
} | ||
} | ||
return decorated; | ||
} | ||
buildEIP6492Signature(signature, status, chainId) { | ||
const bootstrapBundle = this.buildBootstrapTransactions(status, chainId); | ||
if (bootstrapBundle.transactions.length === 0) { | ||
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions'); | ||
} | ||
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]); | ||
} | ||
async editConfig(changes) { | ||
@@ -418,4 +448,4 @@ const currentConfig = await this.status(0).then(s => s.config); | ||
} | ||
signMessage(message, chainId) { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId); | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -565,3 +595,3 @@ async signTransactions(txs, chainId, pstatus) { | ||
} | ||
async signTypedData(domain, types, message, chainId) { | ||
async signTypedData(domain, types, message, chainId, cantValidateBehavior = 'ignore') { | ||
const digest = utils.encodeTypedDataDigest({ | ||
@@ -572,3 +602,3 @@ domain, | ||
}); | ||
return this.signDigest(digest, chainId); | ||
return this.signDigest(digest, chainId, true, cantValidateBehavior); | ||
} | ||
@@ -617,3 +647,7 @@ async getAllSigners() { | ||
} | ||
function isAccount(value) { | ||
return value instanceof Account; | ||
} | ||
exports.Account = Account; | ||
exports.isAccount = isAccount; |
@@ -296,3 +296,3 @@ import { commons, universal } from '@0xsequence/core'; | ||
} | ||
async signDigest(digest, chainId, decorate = true) { | ||
async signDigest(digest, chainId, decorate = true, cantValidateBehavior = 'ignore') { | ||
// If we are signing a digest for chainId zero then we can never be fully migrated | ||
@@ -308,6 +308,36 @@ // because Sequence v1 doesn't allow for signing a message on "all chains" | ||
this.mustBeFullyMigrated(status); | ||
// Check if we can validate onchain and what to do if we can't | ||
// revert early, since there is no point in signing a digest now | ||
if (!status.canOnchainValidate && cantValidateBehavior === 'throw') { | ||
throw new Error('Wallet cannot validate onchain'); | ||
} | ||
const wallet = this.walletForStatus(chainId, status); | ||
const signature = await wallet.signDigest(digest); | ||
return decorate ? this.decorateSignature(signature, status) : signature; | ||
const decorated = decorate ? this.decorateSignature(signature, status) : signature; | ||
// If the wallet can't validate onchain then we | ||
// need to prefix the decorated signature with all deployments and migrations | ||
// aka doing a bootstrap using EIP-6492 | ||
if (!status.canOnchainValidate) { | ||
switch (cantValidateBehavior) { | ||
// NOTICE: We covered this case before signing the digest | ||
// case 'throw': | ||
// throw new Error('Wallet cannot validate on-chain') | ||
case 'ignore': | ||
return decorated; | ||
case 'eip6492': | ||
return this.buildEIP6492Signature(await decorated, status, chainId); | ||
} | ||
} | ||
return decorated; | ||
} | ||
buildEIP6492Signature(signature, status, chainId) { | ||
const bootstrapBundle = this.buildBootstrapTransactions(status, chainId); | ||
if (bootstrapBundle.transactions.length === 0) { | ||
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions'); | ||
} | ||
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]); | ||
} | ||
async editConfig(changes) { | ||
@@ -414,4 +444,4 @@ const currentConfig = await this.status(0).then(s => s.config); | ||
} | ||
signMessage(message, chainId) { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId); | ||
signMessage(message, chainId, cantValidateBehavior = 'ignore') { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId, true, cantValidateBehavior); | ||
} | ||
@@ -561,3 +591,3 @@ async signTransactions(txs, chainId, pstatus) { | ||
} | ||
async signTypedData(domain, types, message, chainId) { | ||
async signTypedData(domain, types, message, chainId, cantValidateBehavior = 'ignore') { | ||
const digest = encodeTypedDataDigest({ | ||
@@ -568,3 +598,3 @@ domain, | ||
}); | ||
return this.signDigest(digest, chainId); | ||
return this.signDigest(digest, chainId, true, cantValidateBehavior); | ||
} | ||
@@ -613,3 +643,6 @@ async getAllSigners() { | ||
} | ||
function isAccount(value) { | ||
return value instanceof Account; | ||
} | ||
export { Account }; | ||
export { Account, isAccount }; |
@@ -81,3 +81,4 @@ import { commons } from '@0xsequence/core'; | ||
publishWitness(): Promise<void>; | ||
signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate?: boolean): Promise<string>; | ||
signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate?: boolean, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>; | ||
private buildEIP6492Signature; | ||
editConfig(changes: { | ||
@@ -103,3 +104,3 @@ add?: commons.config.SimpleSigner[]; | ||
doBootstrap(chainId: ethers.BigNumberish, feeQuote?: FeeQuote, prestatus?: AccountStatus): Promise<commons.transaction.TransactionResponse<any>>; | ||
signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish): Promise<string>; | ||
signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>; | ||
signTransactions(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, pstatus?: AccountStatus): Promise<commons.transaction.SignedTransactionBundle>; | ||
@@ -128,3 +129,3 @@ signMigrations(chainId: ethers.BigNumberish, editConfig: (prevConfig: commons.config.Config) => commons.config.Config): Promise<boolean>; | ||
sendTransaction(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, quote?: FeeQuote, skipPreDecorate?: boolean, callback?: (signed: commons.transaction.SignedTransactionBundle) => void): Promise<ethers.providers.TransactionResponse>; | ||
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId: ethers.BigNumberish): Promise<string>; | ||
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>; | ||
getAllSigners(): Promise<{ | ||
@@ -137,1 +138,2 @@ address: string; | ||
} | ||
export declare function isAccount(value: any): value is Account; |
{ | ||
"name": "@0xsequence/account", | ||
"version": "0.0.0-20230704142612", | ||
"version": "0.0.0-20230706234338", | ||
"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/migration": "0.0.0-20230704142612", | ||
"@0xsequence/core": "0.0.0-20230704142612", | ||
"@0xsequence/network": "0.0.0-20230704142612", | ||
"@0xsequence/relayer": "0.0.0-20230704142612", | ||
"@0xsequence/sessions": "0.0.0-20230704142612", | ||
"@0xsequence/utils": "0.0.0-20230704142612", | ||
"@0xsequence/wallet": "0.0.0-20230704142612" | ||
"@0xsequence/core": "0.0.0-20230706234338", | ||
"@0xsequence/migration": "0.0.0-20230706234338", | ||
"@0xsequence/network": "0.0.0-20230706234338", | ||
"@0xsequence/relayer": "0.0.0-20230706234338", | ||
"@0xsequence/sessions": "0.0.0-20230706234338", | ||
"@0xsequence/utils": "0.0.0-20230706234338", | ||
"@0xsequence/wallet": "0.0.0-20230706234338" | ||
}, | ||
@@ -25,4 +25,4 @@ "devDependencies": { | ||
"nyc": "^15.1.0", | ||
"@0xsequence/signhub": "0.0.0-20230704142612", | ||
"@0xsequence/tests": "0.0.0-20230704142612" | ||
"@0xsequence/signhub": "0.0.0-20230706234338", | ||
"@0xsequence/tests": "0.0.0-20230706234338" | ||
}, | ||
@@ -29,0 +29,0 @@ "files": [ |
@@ -417,3 +417,8 @@ import { commons, universal } from '@0xsequence/core' | ||
async signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate: boolean = true): Promise<string> { | ||
async signDigest( | ||
digest: ethers.BytesLike, | ||
chainId: ethers.BigNumberish, | ||
decorate: boolean = true, | ||
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore' | ||
): Promise<string> { | ||
// If we are signing a digest for chainId zero then we can never be fully migrated | ||
@@ -431,8 +436,53 @@ // because Sequence v1 doesn't allow for signing a message on "all chains" | ||
// Check if we can validate onchain and what to do if we can't | ||
// revert early, since there is no point in signing a digest now | ||
if (!status.canOnchainValidate && cantValidateBehavior === 'throw') { | ||
throw new Error('Wallet cannot validate onchain') | ||
} | ||
const wallet = this.walletForStatus(chainId, status) | ||
const signature = await wallet.signDigest(digest) | ||
return decorate ? this.decorateSignature(signature, status) : signature | ||
const decorated = decorate ? this.decorateSignature(signature, status) : signature | ||
// If the wallet can't validate onchain then we | ||
// need to prefix the decorated signature with all deployments and migrations | ||
// aka doing a bootstrap using EIP-6492 | ||
if (!status.canOnchainValidate) { | ||
switch (cantValidateBehavior) { | ||
// NOTICE: We covered this case before signing the digest | ||
// case 'throw': | ||
// throw new Error('Wallet cannot validate on-chain') | ||
case 'ignore': | ||
return decorated | ||
case 'eip6492': | ||
return this.buildEIP6492Signature(await decorated, status, chainId) | ||
} | ||
} | ||
return decorated | ||
} | ||
private buildEIP6492Signature( | ||
signature: string, | ||
status: AccountStatus, | ||
chainId: ethers.BigNumberish | ||
): string { | ||
const bootstrapBundle = this.buildBootstrapTransactions(status, chainId) | ||
if (bootstrapBundle.transactions.length === 0) { | ||
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions') | ||
} | ||
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] | ||
) | ||
} | ||
async editConfig(changes: { | ||
@@ -548,4 +598,8 @@ add?: commons.config.SimpleSigner[] | ||
signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish): Promise<string> { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId) | ||
signMessage( | ||
message: ethers.BytesLike, | ||
chainId: ethers.BigNumberish, | ||
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore' | ||
): Promise<string> { | ||
return this.signDigest(ethers.utils.keccak256(message), chainId, true, cantValidateBehavior) | ||
} | ||
@@ -747,6 +801,7 @@ | ||
message: Record<string, any>, | ||
chainId: ethers.BigNumberish | ||
chainId: ethers.BigNumberish, | ||
cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore' | ||
): Promise<string> { | ||
const digest = encodeTypedDataDigest({ domain, types, message }) | ||
return this.signDigest(digest, chainId) | ||
return this.signDigest(digest, chainId, true, cantValidateBehavior) | ||
} | ||
@@ -824,1 +879,5 @@ | ||
} | ||
export function isAccount(value: any): value is Account { | ||
return value instanceof Account | ||
} |
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
132102
2733
+ Added@0xsequence/abi@0.0.0-20230706234338(transitive)
+ Added@0xsequence/core@0.0.0-20230706234338(transitive)
+ Added@0xsequence/guard@0.0.0-20230706234338(transitive)
+ Added@0xsequence/indexer@0.0.0-20230706234338(transitive)
+ Added@0xsequence/migration@0.0.0-20230706234338(transitive)
+ Added@0xsequence/network@0.0.0-20230706234338(transitive)
+ Added@0xsequence/relayer@0.0.0-20230706234338(transitive)
+ Added@0xsequence/replacer@0.0.0-20230706234338(transitive)
+ Added@0xsequence/sessions@0.0.0-20230706234338(transitive)
+ Added@0xsequence/signhub@0.0.0-20230706234338(transitive)
+ Added@0xsequence/utils@0.0.0-20230706234338(transitive)
+ Added@0xsequence/wallet@0.0.0-20230706234338(transitive)
- Removed@0xsequence/abi@0.0.0-20230704142612(transitive)
- Removed@0xsequence/core@0.0.0-20230704142612(transitive)
- Removed@0xsequence/guard@0.0.0-20230704142612(transitive)
- Removed@0xsequence/indexer@0.0.0-20230704142612(transitive)
- Removed@0xsequence/migration@0.0.0-20230704142612(transitive)
- Removed@0xsequence/network@0.0.0-20230704142612(transitive)
- Removed@0xsequence/relayer@0.0.0-20230704142612(transitive)
- Removed@0xsequence/replacer@0.0.0-20230704142612(transitive)
- Removed@0xsequence/sessions@0.0.0-20230704142612(transitive)
- Removed@0xsequence/signhub@0.0.0-20230704142612(transitive)
- Removed@0xsequence/utils@0.0.0-20230704142612(transitive)
- Removed@0xsequence/wallet@0.0.0-20230704142612(transitive)