@0xsequence/account 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var abi = require('@0xsequence/abi');
|
|
5
6
|
var core = require('@0xsequence/core');
|
|
6
7
|
var migration = require('@0xsequence/migration');
|
|
7
8
|
var relayer = require('@0xsequence/relayer');
|
|
@@ -76,10 +77,10 @@ function encodeGasRefundTransaction(option) {
|
|
|
76
77
|
}
|
|
77
78
|
class AccountSigner {
|
|
78
79
|
constructor(account, chainId, options) {
|
|
79
|
-
this._isSigner = true;
|
|
80
80
|
this.account = account;
|
|
81
81
|
this.chainId = chainId;
|
|
82
82
|
this.options = options;
|
|
83
|
+
this._isSigner = true;
|
|
83
84
|
}
|
|
84
85
|
get provider() {
|
|
85
86
|
return this.account.providerFor(this.chainId);
|
|
@@ -142,7 +143,6 @@ class AccountSigner {
|
|
|
142
143
|
nonceSpace: this.options.nonceSpace
|
|
143
144
|
} : undefined); // Will always have a transaction response
|
|
144
145
|
}
|
|
145
|
-
|
|
146
146
|
getBalance(blockTag) {
|
|
147
147
|
return this.provider.getBalance(this.account.address, blockTag);
|
|
148
148
|
}
|
|
@@ -205,6 +205,14 @@ class Chain0Reader {
|
|
|
205
205
|
}
|
|
206
206
|
class Account {
|
|
207
207
|
constructor(options) {
|
|
208
|
+
this.address = void 0;
|
|
209
|
+
this.networks = void 0;
|
|
210
|
+
this.tracker = void 0;
|
|
211
|
+
this.contexts = void 0;
|
|
212
|
+
this.migrator = void 0;
|
|
213
|
+
this.migrations = void 0;
|
|
214
|
+
this.orchestrator = void 0;
|
|
215
|
+
this.jwt = void 0;
|
|
208
216
|
this.address = ethers.ethers.utils.getAddress(options.address);
|
|
209
217
|
this.contexts = options.contexts;
|
|
210
218
|
this.tracker = options.tracker;
|
|
@@ -546,6 +554,51 @@ class Account {
|
|
|
546
554
|
}
|
|
547
555
|
return decorated;
|
|
548
556
|
}
|
|
557
|
+
buildOnChainSignature(digest) {
|
|
558
|
+
const subdigest = core.commons.signature.subdigestOf({
|
|
559
|
+
digest: ethers.ethers.utils.hexlify(digest),
|
|
560
|
+
chainId: 0,
|
|
561
|
+
address: this.address
|
|
562
|
+
});
|
|
563
|
+
const hexSubdigest = ethers.ethers.utils.hexlify(subdigest);
|
|
564
|
+
const config = this.coders.config.fromSimple({
|
|
565
|
+
// Threshold *only* needs to be > 0, this is not a magic number
|
|
566
|
+
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
567
|
+
threshold: 32768,
|
|
568
|
+
checkpoint: 0,
|
|
569
|
+
signers: [],
|
|
570
|
+
subdigests: [hexSubdigest]
|
|
571
|
+
});
|
|
572
|
+
const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
|
|
573
|
+
const bundle = {
|
|
574
|
+
entrypoint: this.address,
|
|
575
|
+
transactions: [{
|
|
576
|
+
to: this.address,
|
|
577
|
+
data: walletInterface.encodeFunctionData(
|
|
578
|
+
// *NEVER* use updateImageHash here, as it would effectively destroy the wallet
|
|
579
|
+
// setExtraImageHash sets an additional imageHash, without changing the current one
|
|
580
|
+
'setExtraImageHash', [this.coders.config.imageHashOf(config),
|
|
581
|
+
// 2 ** 255 instead of max uint256, to have more zeros in the calldata
|
|
582
|
+
'57896044618658097711785492504343953926634992332820282019728792003956564819968']),
|
|
583
|
+
// Conservative gas limit, used because the current relayer
|
|
584
|
+
// has trouble estimating gas for this transaction
|
|
585
|
+
gasLimit: 250000
|
|
586
|
+
}]
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// Fire and forget request to save the config
|
|
590
|
+
this.tracker.saveWalletConfig({
|
|
591
|
+
config
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// Encode a signature proof for the given subdigest
|
|
595
|
+
// use `chainId = 0` to make it simpler, as this signature is only a proof
|
|
596
|
+
const signature = this.coders.signature.encodeSigners(config, new Map(), [hexSubdigest], 0).encoded;
|
|
597
|
+
return {
|
|
598
|
+
bundle,
|
|
599
|
+
signature
|
|
600
|
+
};
|
|
601
|
+
}
|
|
549
602
|
async buildEIP6492Signature(signature, status, chainId) {
|
|
550
603
|
const bootstrapBundle = await this.buildBootstrapTransactions(status, chainId);
|
|
551
604
|
if (bootstrapBundle.transactions.length === 0) {
|
|
@@ -678,9 +731,11 @@ class Account {
|
|
|
678
731
|
decorate: true,
|
|
679
732
|
cantValidateBehavior: 'ignore'
|
|
680
733
|
};
|
|
681
|
-
const
|
|
682
|
-
space: options == null ? void 0 : options.nonceSpace
|
|
683
|
-
|
|
734
|
+
const nonceOptions = (options == null ? void 0 : options.nonceSpace) && {
|
|
735
|
+
space: options == null ? void 0 : options.nonceSpace,
|
|
736
|
+
serial: options == null ? void 0 : options.serial
|
|
737
|
+
};
|
|
738
|
+
const signed = await wallet.signTransactions(txs, nonceOptions, metadata);
|
|
684
739
|
return _extends({}, signed, {
|
|
685
740
|
signature: await this.decorateSignature(signed.signature, status)
|
|
686
741
|
});
|
|
@@ -765,7 +820,7 @@ class Account {
|
|
|
765
820
|
const status = pstatus || (await this.status(chainId));
|
|
766
821
|
this.mustBeFullyMigrated(status);
|
|
767
822
|
const decoratedBundle = await this.decorateTransactions(signedBundle, status, chainId);
|
|
768
|
-
callback == null
|
|
823
|
+
callback == null || callback(decoratedBundle);
|
|
769
824
|
return this.relayer(chainId).relay(decoratedBundle, quote);
|
|
770
825
|
}
|
|
771
826
|
async fillGasLimits(txs, chainId, status) {
|
|
@@ -796,7 +851,6 @@ class Account {
|
|
|
796
851
|
entrypoint: this.address,
|
|
797
852
|
nonce: 0 // The relayer also ignored the nonce
|
|
798
853
|
};
|
|
799
|
-
|
|
800
854
|
const decoratedBundle = await this.decorateTransactions(signedBundle, wstatus);
|
|
801
855
|
const data = core.commons.transaction.encodeBundleExecData(decoratedBundle);
|
|
802
856
|
const res = await this.relayer(chainId).getFeeOptionsRaw(decoratedBundle.entrypoint, data, options);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var abi = require('@0xsequence/abi');
|
|
5
6
|
var core = require('@0xsequence/core');
|
|
6
7
|
var migration = require('@0xsequence/migration');
|
|
7
8
|
var relayer = require('@0xsequence/relayer');
|
|
@@ -76,10 +77,10 @@ function encodeGasRefundTransaction(option) {
|
|
|
76
77
|
}
|
|
77
78
|
class AccountSigner {
|
|
78
79
|
constructor(account, chainId, options) {
|
|
79
|
-
this._isSigner = true;
|
|
80
80
|
this.account = account;
|
|
81
81
|
this.chainId = chainId;
|
|
82
82
|
this.options = options;
|
|
83
|
+
this._isSigner = true;
|
|
83
84
|
}
|
|
84
85
|
get provider() {
|
|
85
86
|
return this.account.providerFor(this.chainId);
|
|
@@ -142,7 +143,6 @@ class AccountSigner {
|
|
|
142
143
|
nonceSpace: this.options.nonceSpace
|
|
143
144
|
} : undefined); // Will always have a transaction response
|
|
144
145
|
}
|
|
145
|
-
|
|
146
146
|
getBalance(blockTag) {
|
|
147
147
|
return this.provider.getBalance(this.account.address, blockTag);
|
|
148
148
|
}
|
|
@@ -205,6 +205,14 @@ class Chain0Reader {
|
|
|
205
205
|
}
|
|
206
206
|
class Account {
|
|
207
207
|
constructor(options) {
|
|
208
|
+
this.address = void 0;
|
|
209
|
+
this.networks = void 0;
|
|
210
|
+
this.tracker = void 0;
|
|
211
|
+
this.contexts = void 0;
|
|
212
|
+
this.migrator = void 0;
|
|
213
|
+
this.migrations = void 0;
|
|
214
|
+
this.orchestrator = void 0;
|
|
215
|
+
this.jwt = void 0;
|
|
208
216
|
this.address = ethers.ethers.utils.getAddress(options.address);
|
|
209
217
|
this.contexts = options.contexts;
|
|
210
218
|
this.tracker = options.tracker;
|
|
@@ -546,6 +554,51 @@ class Account {
|
|
|
546
554
|
}
|
|
547
555
|
return decorated;
|
|
548
556
|
}
|
|
557
|
+
buildOnChainSignature(digest) {
|
|
558
|
+
const subdigest = core.commons.signature.subdigestOf({
|
|
559
|
+
digest: ethers.ethers.utils.hexlify(digest),
|
|
560
|
+
chainId: 0,
|
|
561
|
+
address: this.address
|
|
562
|
+
});
|
|
563
|
+
const hexSubdigest = ethers.ethers.utils.hexlify(subdigest);
|
|
564
|
+
const config = this.coders.config.fromSimple({
|
|
565
|
+
// Threshold *only* needs to be > 0, this is not a magic number
|
|
566
|
+
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
567
|
+
threshold: 32768,
|
|
568
|
+
checkpoint: 0,
|
|
569
|
+
signers: [],
|
|
570
|
+
subdigests: [hexSubdigest]
|
|
571
|
+
});
|
|
572
|
+
const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
|
|
573
|
+
const bundle = {
|
|
574
|
+
entrypoint: this.address,
|
|
575
|
+
transactions: [{
|
|
576
|
+
to: this.address,
|
|
577
|
+
data: walletInterface.encodeFunctionData(
|
|
578
|
+
// *NEVER* use updateImageHash here, as it would effectively destroy the wallet
|
|
579
|
+
// setExtraImageHash sets an additional imageHash, without changing the current one
|
|
580
|
+
'setExtraImageHash', [this.coders.config.imageHashOf(config),
|
|
581
|
+
// 2 ** 255 instead of max uint256, to have more zeros in the calldata
|
|
582
|
+
'57896044618658097711785492504343953926634992332820282019728792003956564819968']),
|
|
583
|
+
// Conservative gas limit, used because the current relayer
|
|
584
|
+
// has trouble estimating gas for this transaction
|
|
585
|
+
gasLimit: 250000
|
|
586
|
+
}]
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// Fire and forget request to save the config
|
|
590
|
+
this.tracker.saveWalletConfig({
|
|
591
|
+
config
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// Encode a signature proof for the given subdigest
|
|
595
|
+
// use `chainId = 0` to make it simpler, as this signature is only a proof
|
|
596
|
+
const signature = this.coders.signature.encodeSigners(config, new Map(), [hexSubdigest], 0).encoded;
|
|
597
|
+
return {
|
|
598
|
+
bundle,
|
|
599
|
+
signature
|
|
600
|
+
};
|
|
601
|
+
}
|
|
549
602
|
async buildEIP6492Signature(signature, status, chainId) {
|
|
550
603
|
const bootstrapBundle = await this.buildBootstrapTransactions(status, chainId);
|
|
551
604
|
if (bootstrapBundle.transactions.length === 0) {
|
|
@@ -678,9 +731,11 @@ class Account {
|
|
|
678
731
|
decorate: true,
|
|
679
732
|
cantValidateBehavior: 'ignore'
|
|
680
733
|
};
|
|
681
|
-
const
|
|
682
|
-
space: options == null ? void 0 : options.nonceSpace
|
|
683
|
-
|
|
734
|
+
const nonceOptions = (options == null ? void 0 : options.nonceSpace) && {
|
|
735
|
+
space: options == null ? void 0 : options.nonceSpace,
|
|
736
|
+
serial: options == null ? void 0 : options.serial
|
|
737
|
+
};
|
|
738
|
+
const signed = await wallet.signTransactions(txs, nonceOptions, metadata);
|
|
684
739
|
return _extends({}, signed, {
|
|
685
740
|
signature: await this.decorateSignature(signed.signature, status)
|
|
686
741
|
});
|
|
@@ -765,7 +820,7 @@ class Account {
|
|
|
765
820
|
const status = pstatus || (await this.status(chainId));
|
|
766
821
|
this.mustBeFullyMigrated(status);
|
|
767
822
|
const decoratedBundle = await this.decorateTransactions(signedBundle, status, chainId);
|
|
768
|
-
callback == null
|
|
823
|
+
callback == null || callback(decoratedBundle);
|
|
769
824
|
return this.relayer(chainId).relay(decoratedBundle, quote);
|
|
770
825
|
}
|
|
771
826
|
async fillGasLimits(txs, chainId, status) {
|
|
@@ -796,7 +851,6 @@ class Account {
|
|
|
796
851
|
entrypoint: this.address,
|
|
797
852
|
nonce: 0 // The relayer also ignored the nonce
|
|
798
853
|
};
|
|
799
|
-
|
|
800
854
|
const decoratedBundle = await this.decorateTransactions(signedBundle, wstatus);
|
|
801
855
|
const data = core.commons.transaction.encodeBundleExecData(decoratedBundle);
|
|
802
856
|
const res = await this.relayer(chainId).getFeeOptionsRaw(decoratedBundle.entrypoint, data, options);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { walletContracts } from '@0xsequence/abi';
|
|
1
2
|
import { commons, universal } from '@0xsequence/core';
|
|
2
3
|
import { defaults, migrator, version } from '@0xsequence/migration';
|
|
3
4
|
import { proto, isRelayer, RpcRelayer } from '@0xsequence/relayer';
|
|
@@ -72,10 +73,10 @@ function encodeGasRefundTransaction(option) {
|
|
|
72
73
|
}
|
|
73
74
|
class AccountSigner {
|
|
74
75
|
constructor(account, chainId, options) {
|
|
75
|
-
this._isSigner = true;
|
|
76
76
|
this.account = account;
|
|
77
77
|
this.chainId = chainId;
|
|
78
78
|
this.options = options;
|
|
79
|
+
this._isSigner = true;
|
|
79
80
|
}
|
|
80
81
|
get provider() {
|
|
81
82
|
return this.account.providerFor(this.chainId);
|
|
@@ -138,7 +139,6 @@ class AccountSigner {
|
|
|
138
139
|
nonceSpace: this.options.nonceSpace
|
|
139
140
|
} : undefined); // Will always have a transaction response
|
|
140
141
|
}
|
|
141
|
-
|
|
142
142
|
getBalance(blockTag) {
|
|
143
143
|
return this.provider.getBalance(this.account.address, blockTag);
|
|
144
144
|
}
|
|
@@ -201,6 +201,14 @@ class Chain0Reader {
|
|
|
201
201
|
}
|
|
202
202
|
class Account {
|
|
203
203
|
constructor(options) {
|
|
204
|
+
this.address = void 0;
|
|
205
|
+
this.networks = void 0;
|
|
206
|
+
this.tracker = void 0;
|
|
207
|
+
this.contexts = void 0;
|
|
208
|
+
this.migrator = void 0;
|
|
209
|
+
this.migrations = void 0;
|
|
210
|
+
this.orchestrator = void 0;
|
|
211
|
+
this.jwt = void 0;
|
|
204
212
|
this.address = ethers.utils.getAddress(options.address);
|
|
205
213
|
this.contexts = options.contexts;
|
|
206
214
|
this.tracker = options.tracker;
|
|
@@ -542,6 +550,51 @@ class Account {
|
|
|
542
550
|
}
|
|
543
551
|
return decorated;
|
|
544
552
|
}
|
|
553
|
+
buildOnChainSignature(digest) {
|
|
554
|
+
const subdigest = commons.signature.subdigestOf({
|
|
555
|
+
digest: ethers.utils.hexlify(digest),
|
|
556
|
+
chainId: 0,
|
|
557
|
+
address: this.address
|
|
558
|
+
});
|
|
559
|
+
const hexSubdigest = ethers.utils.hexlify(subdigest);
|
|
560
|
+
const config = this.coders.config.fromSimple({
|
|
561
|
+
// Threshold *only* needs to be > 0, this is not a magic number
|
|
562
|
+
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
563
|
+
threshold: 32768,
|
|
564
|
+
checkpoint: 0,
|
|
565
|
+
signers: [],
|
|
566
|
+
subdigests: [hexSubdigest]
|
|
567
|
+
});
|
|
568
|
+
const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi);
|
|
569
|
+
const bundle = {
|
|
570
|
+
entrypoint: this.address,
|
|
571
|
+
transactions: [{
|
|
572
|
+
to: this.address,
|
|
573
|
+
data: walletInterface.encodeFunctionData(
|
|
574
|
+
// *NEVER* use updateImageHash here, as it would effectively destroy the wallet
|
|
575
|
+
// setExtraImageHash sets an additional imageHash, without changing the current one
|
|
576
|
+
'setExtraImageHash', [this.coders.config.imageHashOf(config),
|
|
577
|
+
// 2 ** 255 instead of max uint256, to have more zeros in the calldata
|
|
578
|
+
'57896044618658097711785492504343953926634992332820282019728792003956564819968']),
|
|
579
|
+
// Conservative gas limit, used because the current relayer
|
|
580
|
+
// has trouble estimating gas for this transaction
|
|
581
|
+
gasLimit: 250000
|
|
582
|
+
}]
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// Fire and forget request to save the config
|
|
586
|
+
this.tracker.saveWalletConfig({
|
|
587
|
+
config
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// Encode a signature proof for the given subdigest
|
|
591
|
+
// use `chainId = 0` to make it simpler, as this signature is only a proof
|
|
592
|
+
const signature = this.coders.signature.encodeSigners(config, new Map(), [hexSubdigest], 0).encoded;
|
|
593
|
+
return {
|
|
594
|
+
bundle,
|
|
595
|
+
signature
|
|
596
|
+
};
|
|
597
|
+
}
|
|
545
598
|
async buildEIP6492Signature(signature, status, chainId) {
|
|
546
599
|
const bootstrapBundle = await this.buildBootstrapTransactions(status, chainId);
|
|
547
600
|
if (bootstrapBundle.transactions.length === 0) {
|
|
@@ -674,9 +727,11 @@ class Account {
|
|
|
674
727
|
decorate: true,
|
|
675
728
|
cantValidateBehavior: 'ignore'
|
|
676
729
|
};
|
|
677
|
-
const
|
|
678
|
-
space: options == null ? void 0 : options.nonceSpace
|
|
679
|
-
|
|
730
|
+
const nonceOptions = (options == null ? void 0 : options.nonceSpace) && {
|
|
731
|
+
space: options == null ? void 0 : options.nonceSpace,
|
|
732
|
+
serial: options == null ? void 0 : options.serial
|
|
733
|
+
};
|
|
734
|
+
const signed = await wallet.signTransactions(txs, nonceOptions, metadata);
|
|
680
735
|
return _extends({}, signed, {
|
|
681
736
|
signature: await this.decorateSignature(signed.signature, status)
|
|
682
737
|
});
|
|
@@ -761,7 +816,7 @@ class Account {
|
|
|
761
816
|
const status = pstatus || (await this.status(chainId));
|
|
762
817
|
this.mustBeFullyMigrated(status);
|
|
763
818
|
const decoratedBundle = await this.decorateTransactions(signedBundle, status, chainId);
|
|
764
|
-
callback == null
|
|
819
|
+
callback == null || callback(decoratedBundle);
|
|
765
820
|
return this.relayer(chainId).relay(decoratedBundle, quote);
|
|
766
821
|
}
|
|
767
822
|
async fillGasLimits(txs, chainId, status) {
|
|
@@ -792,7 +847,6 @@ class Account {
|
|
|
792
847
|
entrypoint: this.address,
|
|
793
848
|
nonce: 0 // The relayer also ignored the nonce
|
|
794
849
|
};
|
|
795
|
-
|
|
796
850
|
const decoratedBundle = await this.decorateTransactions(signedBundle, wstatus);
|
|
797
851
|
const data = commons.transaction.encodeBundleExecData(decoratedBundle);
|
|
798
852
|
const res = await this.relayer(chainId).getFeeOptionsRaw(decoratedBundle.entrypoint, data, options);
|
|
@@ -85,6 +85,10 @@ export declare class Account {
|
|
|
85
85
|
decorateSignature<T extends ethers.BytesLike>(signature: T, status: Partial<Pick<AccountStatus, 'presignedConfigurations'>>): Promise<T | string>;
|
|
86
86
|
publishWitness(): Promise<void>;
|
|
87
87
|
signDigest(digest: ethers.BytesLike, chainId: ethers.BigNumberish, decorate?: boolean, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw', metadata?: object): Promise<string>;
|
|
88
|
+
buildOnChainSignature(digest: ethers.BytesLike): {
|
|
89
|
+
bundle: commons.transaction.TransactionBundle;
|
|
90
|
+
signature: string;
|
|
91
|
+
};
|
|
88
92
|
private buildEIP6492Signature;
|
|
89
93
|
editConfig(changes: {
|
|
90
94
|
add?: commons.config.SimpleSigner[];
|
|
@@ -109,6 +113,7 @@ export declare class Account {
|
|
|
109
113
|
signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>;
|
|
110
114
|
signTransactions(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, pstatus?: AccountStatus, options?: {
|
|
111
115
|
nonceSpace?: ethers.BigNumberish;
|
|
116
|
+
serial?: boolean;
|
|
112
117
|
}): Promise<commons.transaction.SignedTransactionBundle>;
|
|
113
118
|
signMigrations(chainId: ethers.BigNumberish, editConfig: (prevConfig: commons.config.Config) => commons.config.Config): Promise<boolean>;
|
|
114
119
|
signAllMigrations(editConfig: (prevConfig: commons.config.Config) => commons.config.Config): Promise<{
|
|
@@ -136,6 +141,7 @@ export declare class Account {
|
|
|
136
141
|
}): Promise<PreparedTransactions>;
|
|
137
142
|
sendTransaction(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, quote?: FeeQuote, skipPreDecorate?: boolean, callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void, options?: {
|
|
138
143
|
nonceSpace?: ethers.BigNumberish;
|
|
144
|
+
serial?: boolean;
|
|
139
145
|
}): Promise<ethers.providers.TransactionResponse | undefined>;
|
|
140
146
|
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>;
|
|
141
147
|
getSigners(): Promise<Array<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/account",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "tools for migrating sequence wallets to new versions",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/account",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -10,19 +10,20 @@
|
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^5.5.2",
|
|
13
|
-
"@0xsequence/
|
|
14
|
-
"@0xsequence/
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/
|
|
13
|
+
"@0xsequence/abi": "1.6.1",
|
|
14
|
+
"@0xsequence/core": "1.6.1",
|
|
15
|
+
"@0xsequence/migration": "1.6.1",
|
|
16
|
+
"@0xsequence/network": "1.6.1",
|
|
17
|
+
"@0xsequence/relayer": "1.6.1",
|
|
18
|
+
"@0xsequence/sessions": "1.6.1",
|
|
19
|
+
"@0xsequence/utils": "1.6.1",
|
|
20
|
+
"@0xsequence/wallet": "1.6.1"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
23
24
|
"nyc": "^15.1.0",
|
|
24
|
-
"@0xsequence/signhub": "1.
|
|
25
|
-
"@0xsequence/tests": "1.
|
|
25
|
+
"@0xsequence/signhub": "1.6.1",
|
|
26
|
+
"@0xsequence/tests": "1.6.1"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"src",
|
package/src/account.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { walletContracts } from '@0xsequence/abi'
|
|
1
2
|
import { commons, universal } from '@0xsequence/core'
|
|
2
3
|
import { WalletSignRequestMetadata } from '@0xsequence/core/src/commons'
|
|
3
4
|
import { migrator, defaults, version } from '@0xsequence/migration'
|
|
@@ -526,6 +527,50 @@ export class Account {
|
|
|
526
527
|
return decorated
|
|
527
528
|
}
|
|
528
529
|
|
|
530
|
+
buildOnChainSignature(digest: ethers.BytesLike): { bundle: commons.transaction.TransactionBundle; signature: string } {
|
|
531
|
+
const subdigest = commons.signature.subdigestOf({ digest: ethers.utils.hexlify(digest), chainId: 0, address: this.address })
|
|
532
|
+
const hexSubdigest = ethers.utils.hexlify(subdigest)
|
|
533
|
+
const config = this.coders.config.fromSimple({
|
|
534
|
+
// Threshold *only* needs to be > 0, this is not a magic number
|
|
535
|
+
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
536
|
+
threshold: 32768,
|
|
537
|
+
checkpoint: 0,
|
|
538
|
+
signers: [],
|
|
539
|
+
subdigests: [hexSubdigest]
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi)
|
|
543
|
+
const bundle: commons.transaction.TransactionBundle = {
|
|
544
|
+
entrypoint: this.address,
|
|
545
|
+
transactions: [
|
|
546
|
+
{
|
|
547
|
+
to: this.address,
|
|
548
|
+
data: walletInterface.encodeFunctionData(
|
|
549
|
+
// *NEVER* use updateImageHash here, as it would effectively destroy the wallet
|
|
550
|
+
// setExtraImageHash sets an additional imageHash, without changing the current one
|
|
551
|
+
'setExtraImageHash',
|
|
552
|
+
[
|
|
553
|
+
this.coders.config.imageHashOf(config),
|
|
554
|
+
// 2 ** 255 instead of max uint256, to have more zeros in the calldata
|
|
555
|
+
'57896044618658097711785492504343953926634992332820282019728792003956564819968'
|
|
556
|
+
]
|
|
557
|
+
),
|
|
558
|
+
// Conservative gas limit, used because the current relayer
|
|
559
|
+
// has trouble estimating gas for this transaction
|
|
560
|
+
gasLimit: 250000
|
|
561
|
+
}
|
|
562
|
+
]
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Fire and forget request to save the config
|
|
566
|
+
this.tracker.saveWalletConfig({ config })
|
|
567
|
+
|
|
568
|
+
// Encode a signature proof for the given subdigest
|
|
569
|
+
// use `chainId = 0` to make it simpler, as this signature is only a proof
|
|
570
|
+
const signature = this.coders.signature.encodeSigners(config, new Map(), [hexSubdigest], 0).encoded
|
|
571
|
+
return { bundle, signature }
|
|
572
|
+
}
|
|
573
|
+
|
|
529
574
|
private async buildEIP6492Signature(signature: string, status: AccountStatus, chainId: ethers.BigNumberish): Promise<string> {
|
|
530
575
|
const bootstrapBundle = await this.buildBootstrapTransactions(status, chainId)
|
|
531
576
|
if (bootstrapBundle.transactions.length === 0) {
|
|
@@ -669,6 +714,7 @@ export class Account {
|
|
|
669
714
|
pstatus?: AccountStatus,
|
|
670
715
|
options?: {
|
|
671
716
|
nonceSpace?: ethers.BigNumberish
|
|
717
|
+
serial?: boolean
|
|
672
718
|
}
|
|
673
719
|
): Promise<commons.transaction.SignedTransactionBundle> {
|
|
674
720
|
const status = pstatus || (await this.status(chainId))
|
|
@@ -685,7 +731,8 @@ export class Account {
|
|
|
685
731
|
cantValidateBehavior: 'ignore'
|
|
686
732
|
}
|
|
687
733
|
|
|
688
|
-
const
|
|
734
|
+
const nonceOptions = options?.nonceSpace && { space: options?.nonceSpace, serial: options?.serial }
|
|
735
|
+
const signed = await wallet.signTransactions(txs, nonceOptions, metadata)
|
|
689
736
|
|
|
690
737
|
return {
|
|
691
738
|
...signed,
|
|
@@ -871,6 +918,7 @@ export class Account {
|
|
|
871
918
|
callback?: (bundle: commons.transaction.IntendedTransactionBundle) => void,
|
|
872
919
|
options?: {
|
|
873
920
|
nonceSpace?: ethers.BigNumberish
|
|
921
|
+
serial?: boolean
|
|
874
922
|
}
|
|
875
923
|
): Promise<ethers.providers.TransactionResponse | undefined> {
|
|
876
924
|
const status = await this.status(chainId)
|