viem 2.56.0 → 2.56.2
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.
- package/CHANGELOG.md +16 -0
- package/_cjs/actions/wallet/sendTransaction.js +9 -1
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +9 -1
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Abis.js +11 -23
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Account.js +66 -61
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Client.js +10 -2
- package/_cjs/tempo/Client.js.map +1 -1
- package/_cjs/tempo/Decorator.js +2 -1
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/Formatters.js +29 -9
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Multisig.js +990 -0
- package/_cjs/tempo/Multisig.js.map +1 -0
- package/_cjs/tempo/Selectors.js +2 -3
- package/_cjs/tempo/Selectors.js.map +1 -1
- package/_cjs/tempo/{Storage.js → Store.js} +34 -9
- package/_cjs/tempo/Store.js.map +1 -0
- package/_cjs/tempo/Transaction.js +15 -30
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/Transport.js +51 -5
- package/_cjs/tempo/Transport.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +102 -8
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/amm.js +6 -0
- package/_cjs/tempo/actions/amm.js.map +1 -1
- package/_cjs/tempo/actions/channel.js +12 -0
- package/_cjs/tempo/actions/channel.js.map +1 -1
- package/_cjs/tempo/actions/dex.js +10 -0
- package/_cjs/tempo/actions/dex.js.map +1 -1
- package/_cjs/tempo/actions/earn/deployment.js +13 -1
- package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +17 -0
- package/_cjs/tempo/actions/earn.js.map +1 -1
- package/_cjs/tempo/actions/fee.js +4 -0
- package/_cjs/tempo/actions/fee.js.map +1 -1
- package/_cjs/tempo/actions/multisig.js +86 -28
- package/_cjs/tempo/actions/multisig.js.map +1 -1
- package/_cjs/tempo/actions/policy.js +8 -0
- package/_cjs/tempo/actions/policy.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +6 -0
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
- package/_cjs/tempo/actions/reward.js +4 -0
- package/_cjs/tempo/actions/reward.js.map +1 -1
- package/_cjs/tempo/actions/token.js +32 -0
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/actions/virtualAddress.js +2 -0
- package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +7 -5
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +180 -69
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +5 -2
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/utils.js +2 -1
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_cjs/tempo/multisig/Config.js +80 -0
- package/_cjs/tempo/multisig/Config.js.map +1 -0
- package/_cjs/tempo/multisig/Operation.js +163 -0
- package/_cjs/tempo/multisig/Operation.js.map +1 -0
- package/_cjs/utils/encoding/fromHex.js +1 -1
- package/_cjs/utils/encoding/fromHex.js.map +1 -1
- package/_cjs/utils/hash/isHash.js +1 -2
- package/_cjs/utils/hash/isHash.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +9 -1
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +9 -1
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Abis.js +11 -23
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Account.js +66 -61
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Client.js +22 -3
- package/_esm/tempo/Client.js.map +1 -1
- package/_esm/tempo/Decorator.js +2 -1
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/Formatters.js +32 -11
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Multisig.js +1020 -0
- package/_esm/tempo/Multisig.js.map +1 -0
- package/_esm/tempo/Selectors.js +2 -3
- package/_esm/tempo/Selectors.js.map +1 -1
- package/_esm/tempo/{Storage.js → Store.js} +37 -26
- package/_esm/tempo/Store.js.map +1 -0
- package/_esm/tempo/Transaction.js +16 -31
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/Transport.js +71 -6
- package/_esm/tempo/Transport.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +104 -20
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/amm.js +6 -0
- package/_esm/tempo/actions/amm.js.map +1 -1
- package/_esm/tempo/actions/channel.js +12 -0
- package/_esm/tempo/actions/channel.js.map +1 -1
- package/_esm/tempo/actions/dex.js +10 -0
- package/_esm/tempo/actions/dex.js.map +1 -1
- package/_esm/tempo/actions/earn/deployment.js +13 -1
- package/_esm/tempo/actions/earn/deployment.js.map +1 -1
- package/_esm/tempo/actions/earn.js +17 -0
- package/_esm/tempo/actions/earn.js.map +1 -1
- package/_esm/tempo/actions/fee.js +4 -0
- package/_esm/tempo/actions/fee.js.map +1 -1
- package/_esm/tempo/actions/multisig.js +129 -63
- package/_esm/tempo/actions/multisig.js.map +1 -1
- package/_esm/tempo/actions/policy.js +8 -0
- package/_esm/tempo/actions/policy.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +6 -0
- package/_esm/tempo/actions/receivePolicy.js.map +1 -1
- package/_esm/tempo/actions/reward.js +4 -0
- package/_esm/tempo/actions/reward.js.map +1 -1
- package/_esm/tempo/actions/token.js +32 -0
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/actions/virtualAddress.js +2 -0
- package/_esm/tempo/actions/virtualAddress.js.map +1 -1
- package/_esm/tempo/actions/zone.js +8 -6
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/chainConfig.js +188 -86
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +5 -3
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/utils.js +2 -1
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_esm/tempo/multisig/Config.js +84 -0
- package/_esm/tempo/multisig/Config.js.map +1 -0
- package/_esm/tempo/multisig/Operation.js +170 -0
- package/_esm/tempo/multisig/Operation.js.map +1 -0
- package/_esm/utils/encoding/fromHex.js +1 -1
- package/_esm/utils/encoding/fromHex.js.map +1 -1
- package/_esm/utils/hash/isHash.js +1 -2
- package/_esm/utils/hash/isHash.js.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/tempo.d.ts +72 -92
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +72 -92
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +72 -92
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +72 -92
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Abis.d.ts +54 -108
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +47 -20
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Client.d.ts +23 -1
- package/_types/tempo/Client.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +30 -5
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/Multisig.d.ts +32 -0
- package/_types/tempo/Multisig.d.ts.map +1 -0
- package/_types/tempo/Selectors.d.ts +2 -3
- package/_types/tempo/Selectors.d.ts.map +1 -1
- package/_types/tempo/Store.d.ts +62 -0
- package/_types/tempo/Store.d.ts.map +1 -0
- package/_types/tempo/Transaction.d.ts +12 -31
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/Transport.d.ts +37 -5
- package/_types/tempo/Transport.d.ts.map +1 -1
- package/_types/tempo/Zone.d.ts +468 -598
- package/_types/tempo/Zone.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +38 -8
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/amm.d.ts.map +1 -1
- package/_types/tempo/actions/channel.d.ts.map +1 -1
- package/_types/tempo/actions/dex.d.ts.map +1 -1
- package/_types/tempo/actions/earn/deployment.d.ts +3 -3
- package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
- package/_types/tempo/actions/earn.d.ts.map +1 -1
- package/_types/tempo/actions/fee.d.ts.map +1 -1
- package/_types/tempo/actions/multisig.d.ts +139 -136
- package/_types/tempo/actions/multisig.d.ts.map +1 -1
- package/_types/tempo/actions/policy.d.ts.map +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
- package/_types/tempo/actions/reward.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +4 -4
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts +38 -48
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +8 -3
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/types.d.ts +1 -1
- package/_types/tempo/internal/types.d.ts.map +1 -1
- package/_types/tempo/internal/utils.d.ts +1 -0
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/_types/tempo/multisig/Config.d.ts +42 -0
- package/_types/tempo/multisig/Config.d.ts.map +1 -0
- package/_types/tempo/multisig/Operation.d.ts +32 -0
- package/_types/tempo/multisig/Operation.d.ts.map +1 -0
- package/_types/types/chain.d.ts +10 -0
- package/_types/types/chain.d.ts.map +1 -1
- package/_types/utils/hash/isHash.d.ts +1 -2
- package/_types/utils/hash/isHash.d.ts.map +1 -1
- package/actions/wallet/sendTransaction.ts +9 -1
- package/actions/wallet/sendTransactionSync.ts +9 -1
- package/errors/version.ts +1 -1
- package/package.json +2 -2
- package/tempo/Abis.ts +11 -23
- package/tempo/Account.ts +136 -105
- package/tempo/Client.ts +46 -3
- package/tempo/Decorator.ts +40 -8
- package/tempo/Formatters.ts +39 -21
- package/tempo/Multisig.ts +1349 -0
- package/tempo/Selectors.ts +2 -3
- package/tempo/Store.ts +170 -0
- package/tempo/Transaction.ts +39 -64
- package/tempo/Transport.ts +125 -10
- package/tempo/actions/accessKey.ts +210 -23
- package/tempo/actions/amm.ts +7 -0
- package/tempo/actions/channel.ts +12 -0
- package/tempo/actions/dex.ts +10 -0
- package/tempo/actions/earn/deployment.ts +16 -3
- package/tempo/actions/earn.ts +19 -0
- package/tempo/actions/fee.ts +4 -0
- package/tempo/actions/multisig.ts +192 -94
- package/tempo/actions/policy.ts +8 -0
- package/tempo/actions/receivePolicy.ts +6 -0
- package/tempo/actions/reward.ts +5 -0
- package/tempo/actions/token.ts +33 -0
- package/tempo/actions/virtualAddress.ts +2 -0
- package/tempo/actions/zone.ts +10 -8
- package/tempo/chainConfig.ts +259 -100
- package/tempo/index.ts +9 -1
- package/tempo/internal/types.ts +3 -2
- package/tempo/internal/utils.ts +2 -0
- package/tempo/multisig/Config.ts +131 -0
- package/tempo/multisig/Operation.ts +211 -0
- package/types/chain.ts +14 -0
- package/utils/encoding/fromHex.ts +1 -1
- package/utils/hash/isHash.ts +2 -3
- package/_cjs/tempo/Storage.js.map +0 -1
- package/_cjs/tempo/internal/multisig.js +0 -56
- package/_cjs/tempo/internal/multisig.js.map +0 -1
- package/_esm/tempo/Storage.js.map +0 -1
- package/_esm/tempo/internal/multisig.js +0 -56
- package/_esm/tempo/internal/multisig.js.map +0 -1
- package/_types/tempo/Storage.d.ts +0 -42
- package/_types/tempo/Storage.d.ts.map +0 -1
- package/_types/tempo/internal/multisig.d.ts +0 -13
- package/_types/tempo/internal/multisig.d.ts.map +0 -1
- package/tempo/Storage.ts +0 -115
- package/tempo/internal/multisig.ts +0 -72
|
@@ -0,0 +1,1020 @@
|
|
|
1
|
+
import * as Address_ from 'ox/Address';
|
|
2
|
+
import * as Hash from 'ox/Hash';
|
|
3
|
+
import * as Hex from 'ox/Hex';
|
|
4
|
+
import * as RpcResponse from 'ox/RpcResponse';
|
|
5
|
+
import { KeyAuthorization, MultisigConfig, MultisigOperation, Transaction as ox_Transaction, SignatureEnvelope, TxEnvelopeTempo, } from 'ox/tempo';
|
|
6
|
+
import { getBlockNumber } from '../actions/public/getBlockNumber.js';
|
|
7
|
+
import { createClient } from '../clients/createClient.js';
|
|
8
|
+
import { custom } from '../clients/transports/custom.js';
|
|
9
|
+
import { decodeFunctionData } from '../utils/abi/decodeFunctionData.js';
|
|
10
|
+
import { isAddressEqual } from '../utils/address/isAddressEqual.js';
|
|
11
|
+
import * as Abis from './Abis.js';
|
|
12
|
+
import * as Addresses from './Addresses.js';
|
|
13
|
+
import { getConfigCommitment } from './actions/multisig.js';
|
|
14
|
+
import * as ConfigStore from './multisig/Config.js';
|
|
15
|
+
import * as OperationStore from './multisig/Operation.js';
|
|
16
|
+
import * as Transaction from './Transaction.js';
|
|
17
|
+
const submissionTtl = 30_000;
|
|
18
|
+
const pollingInterval = 100;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an RPC request handler that coordinates native multisig approvals.
|
|
21
|
+
*
|
|
22
|
+
* @param next - Downstream RPC request handler.
|
|
23
|
+
* @param parameters - Handler parameters.
|
|
24
|
+
* @returns The multisig-aware RPC request handler.
|
|
25
|
+
*/
|
|
26
|
+
export function handleRequest(next, parameters) {
|
|
27
|
+
if (!parameters.store.compareAndSet)
|
|
28
|
+
throw new RpcResponse.InvalidParamsError({
|
|
29
|
+
message: 'Multisig coordination requires a store with atomic `compareAndSet`.',
|
|
30
|
+
});
|
|
31
|
+
const client = createClient({
|
|
32
|
+
transport: custom({
|
|
33
|
+
request: ({ method, params }, options) => next({ method, params }, options),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
return async (request, requestOptions) => {
|
|
37
|
+
if (request.method === 'multisig_getConfig') {
|
|
38
|
+
const value = request.params?.[0];
|
|
39
|
+
const address = value && typeof value === 'object' && 'address' in value
|
|
40
|
+
? value.address
|
|
41
|
+
: undefined;
|
|
42
|
+
if (typeof address !== 'string' ||
|
|
43
|
+
!Address_.validate(address) ||
|
|
44
|
+
Hex.toBigInt(address) === 0n)
|
|
45
|
+
throw new RpcResponse.InvalidParamsError({
|
|
46
|
+
message: 'Expected a multisig account address.',
|
|
47
|
+
});
|
|
48
|
+
const blockNumber = await getBlockNumber(client, { cacheTime: 0 });
|
|
49
|
+
const commitment = await getConfigCommitment(client, {
|
|
50
|
+
account: address,
|
|
51
|
+
blockNumber,
|
|
52
|
+
});
|
|
53
|
+
const config = await ConfigStore.read(parameters.store, {
|
|
54
|
+
address,
|
|
55
|
+
commitment,
|
|
56
|
+
});
|
|
57
|
+
if (!config)
|
|
58
|
+
return null;
|
|
59
|
+
return MultisigConfig.toRpc(config);
|
|
60
|
+
}
|
|
61
|
+
if (request.method === 'multisig_getOperation') {
|
|
62
|
+
const hash = request.params?.[0];
|
|
63
|
+
if (typeof hash !== 'string' || !Hash.validate(hash))
|
|
64
|
+
throw new RpcResponse.InvalidParamsError({
|
|
65
|
+
message: 'Expected a multisig operation hash.',
|
|
66
|
+
});
|
|
67
|
+
const operation = await OperationStore.read(parameters.store, hash);
|
|
68
|
+
return operation ? MultisigOperation.toRpc(operation) : null;
|
|
69
|
+
}
|
|
70
|
+
if (request.method === 'multisig_approveKeyAuthorization')
|
|
71
|
+
return await approveKeyAuthorization({
|
|
72
|
+
client,
|
|
73
|
+
request,
|
|
74
|
+
store: parameters.store,
|
|
75
|
+
});
|
|
76
|
+
if (request.method === 'eth_getTransactionByHash' ||
|
|
77
|
+
request.method === 'eth_getTransactionReceipt') {
|
|
78
|
+
const hash = request.params?.[0];
|
|
79
|
+
if (typeof hash !== 'string' || !Hash.validate(hash))
|
|
80
|
+
return await next(request, requestOptions);
|
|
81
|
+
const operation = await OperationStore.read(parameters.store, hash);
|
|
82
|
+
if (!operation || operation.type !== 'transaction')
|
|
83
|
+
return await next(request, requestOptions);
|
|
84
|
+
if (request.method === 'eth_getTransactionReceipt') {
|
|
85
|
+
if (operation.status === 'pending')
|
|
86
|
+
return null;
|
|
87
|
+
const transactionHash = await getSubmittedTransactionHash(parameters.store, operation);
|
|
88
|
+
if (!transactionHash)
|
|
89
|
+
return null;
|
|
90
|
+
const receipt = await next({
|
|
91
|
+
...request,
|
|
92
|
+
params: [transactionHash],
|
|
93
|
+
}, requestOptions);
|
|
94
|
+
if (!receipt || typeof receipt !== 'object')
|
|
95
|
+
return receipt;
|
|
96
|
+
const success = operation.status === 'submitting'
|
|
97
|
+
? await completeSubmission(parameters.store, operation, transactionHash)
|
|
98
|
+
: operation;
|
|
99
|
+
return {
|
|
100
|
+
...receipt,
|
|
101
|
+
multisig: MultisigOperation.toRpc(success),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (operation.status === 'pending')
|
|
105
|
+
return await toTransaction(client, operation, parameters.store);
|
|
106
|
+
const transactionHash = await getSubmittedTransactionHash(parameters.store, operation);
|
|
107
|
+
if (!transactionHash)
|
|
108
|
+
return await toTransaction(client, operation, parameters.store);
|
|
109
|
+
const transaction = await next({
|
|
110
|
+
...request,
|
|
111
|
+
params: [transactionHash],
|
|
112
|
+
}, requestOptions);
|
|
113
|
+
if (!transaction || typeof transaction !== 'object')
|
|
114
|
+
return await toTransaction(client, operation, parameters.store);
|
|
115
|
+
const success = operation.status === 'submitting'
|
|
116
|
+
? await completeSubmission(parameters.store, operation, transactionHash)
|
|
117
|
+
: operation;
|
|
118
|
+
return {
|
|
119
|
+
...transaction,
|
|
120
|
+
multisig: MultisigOperation.toRpc(success),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (request.method !== 'eth_sendRawTransaction' &&
|
|
124
|
+
request.method !== 'eth_sendRawTransactionSync' &&
|
|
125
|
+
request.method !== 'multisig_approveRawTransaction' &&
|
|
126
|
+
request.method !== 'multisig_approveRawTransactionSync')
|
|
127
|
+
return await next(request, requestOptions);
|
|
128
|
+
const standard = request.method === 'eth_sendRawTransaction' ||
|
|
129
|
+
request.method === 'eth_sendRawTransactionSync';
|
|
130
|
+
const serialized = request.params?.[0];
|
|
131
|
+
if (!isSerializedTempoTransaction(serialized)) {
|
|
132
|
+
if (standard)
|
|
133
|
+
return await next(request, requestOptions);
|
|
134
|
+
throw new RpcResponse.InvalidParamsError({
|
|
135
|
+
message: 'Expected a serialized Tempo multisig transaction.',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return await submit({
|
|
139
|
+
client,
|
|
140
|
+
method: request.method,
|
|
141
|
+
next,
|
|
142
|
+
request,
|
|
143
|
+
requestOptions,
|
|
144
|
+
serialized,
|
|
145
|
+
store: parameters.store,
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** Collects approvals and submits a transaction after quorum. @internal */
|
|
150
|
+
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
151
|
+
async function submit(options) {
|
|
152
|
+
const transaction = (() => {
|
|
153
|
+
try {
|
|
154
|
+
return deserialize(options.serialized);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (options.method !== 'eth_sendRawTransaction' &&
|
|
158
|
+
options.method !== 'eth_sendRawTransactionSync')
|
|
159
|
+
throw error;
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
})();
|
|
163
|
+
const signature = transaction?.signature;
|
|
164
|
+
if (!transaction || signature?.type !== 'multisig') {
|
|
165
|
+
if (options.method === 'eth_sendRawTransaction' ||
|
|
166
|
+
options.method === 'eth_sendRawTransactionSync')
|
|
167
|
+
return await options.next(options.request, options.requestOptions);
|
|
168
|
+
throw new RpcResponse.InvalidParamsError({
|
|
169
|
+
message: 'Expected a multisig transaction signature.',
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const { signature: _, ...unsigned } = transaction;
|
|
173
|
+
const envelope = TxEnvelopeTempo.from(unsigned);
|
|
174
|
+
const serializedUnsigned = serializeUnsigned(envelope, options.serialized.startsWith(TxEnvelopeTempo.feePayerMagic));
|
|
175
|
+
const blockNumber = await getBlockNumber(options.client, { cacheTime: 0 });
|
|
176
|
+
const config = MultisigConfig.from(signature.config);
|
|
177
|
+
const configCommitment = await validateConfig({
|
|
178
|
+
account: signature.account,
|
|
179
|
+
blockNumber,
|
|
180
|
+
client: options.client,
|
|
181
|
+
config,
|
|
182
|
+
});
|
|
183
|
+
const operationHash = MultisigOperation.getHash({
|
|
184
|
+
account: signature.account,
|
|
185
|
+
config,
|
|
186
|
+
transaction: serializedUnsigned,
|
|
187
|
+
type: 'transaction',
|
|
188
|
+
});
|
|
189
|
+
const incoming = signature.signatures.map((signature) => SignatureEnvelope.serialize(signature));
|
|
190
|
+
if (incoming.length === 0)
|
|
191
|
+
throw new RpcResponse.InvalidParamsError({
|
|
192
|
+
message: 'A multisig approval envelope must include a signature.',
|
|
193
|
+
});
|
|
194
|
+
const now = Date.now();
|
|
195
|
+
const expiredSubmissionIds = new Set();
|
|
196
|
+
const operation = await OperationStore.update(options.store, operationHash, async (existing) => {
|
|
197
|
+
if (existing && existing.type !== 'transaction')
|
|
198
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
199
|
+
if (existing?.status === 'success')
|
|
200
|
+
return existing;
|
|
201
|
+
if (existing?.status === 'submitting' && existing.expiresAt > now)
|
|
202
|
+
return existing;
|
|
203
|
+
if (existing?.status === 'submitting')
|
|
204
|
+
expiredSubmissionIds.add(existing.submissionId);
|
|
205
|
+
const existingApprovals = existing
|
|
206
|
+
? await selectApprovals({
|
|
207
|
+
account: signature.account,
|
|
208
|
+
client: options.client,
|
|
209
|
+
config,
|
|
210
|
+
discardInvalidNested: true,
|
|
211
|
+
hash: operationHash,
|
|
212
|
+
approvals: existing.approvals,
|
|
213
|
+
blockNumber,
|
|
214
|
+
store: options.store,
|
|
215
|
+
})
|
|
216
|
+
: undefined;
|
|
217
|
+
const approvals = await selectApprovals({
|
|
218
|
+
account: signature.account,
|
|
219
|
+
client: options.client,
|
|
220
|
+
config,
|
|
221
|
+
hash: operationHash,
|
|
222
|
+
approvals: [...(existingApprovals?.approvals ?? []), ...incoming],
|
|
223
|
+
blockNumber,
|
|
224
|
+
store: options.store,
|
|
225
|
+
});
|
|
226
|
+
return MultisigOperation.from({
|
|
227
|
+
account: signature.account,
|
|
228
|
+
approvals: approvals.approvals,
|
|
229
|
+
config,
|
|
230
|
+
createdAt: existing?.createdAt ?? now,
|
|
231
|
+
hash: operationHash,
|
|
232
|
+
signatureCount: approvals.signatureCount,
|
|
233
|
+
status: 'pending',
|
|
234
|
+
threshold: approvals.threshold,
|
|
235
|
+
transaction: mergeTransaction(existing?.transaction, serializedUnsigned),
|
|
236
|
+
type: 'transaction',
|
|
237
|
+
updatedAt: now,
|
|
238
|
+
weight: approvals.weight,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
for (const submissionId of expiredSubmissionIds) {
|
|
242
|
+
if (operation.status === 'submitting' &&
|
|
243
|
+
operation.submissionId?.toLowerCase() === submissionId.toLowerCase())
|
|
244
|
+
continue;
|
|
245
|
+
await removeSettledSubmission(options.store, operationHash, submissionId);
|
|
246
|
+
}
|
|
247
|
+
await ConfigStore.write(options.store, {
|
|
248
|
+
address: signature.account,
|
|
249
|
+
commitment: configCommitment,
|
|
250
|
+
config,
|
|
251
|
+
});
|
|
252
|
+
await cacheNextConfigs({
|
|
253
|
+
account: signature.account,
|
|
254
|
+
config,
|
|
255
|
+
store: options.store,
|
|
256
|
+
transaction,
|
|
257
|
+
});
|
|
258
|
+
if (operation.type !== 'transaction')
|
|
259
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
260
|
+
if (operation.status === 'success')
|
|
261
|
+
return await submittedResult(options, operation);
|
|
262
|
+
if (operation.status === 'submitting' && operation.expiresAt > Date.now())
|
|
263
|
+
return await submittingResult(options, operation);
|
|
264
|
+
if (operation.weight < operation.threshold)
|
|
265
|
+
return pendingResult(options.method, operation);
|
|
266
|
+
const submissionId = Hex.random(32);
|
|
267
|
+
const timeout = options.request.params?.[1];
|
|
268
|
+
const synchronous = options.method === 'eth_sendRawTransactionSync' ||
|
|
269
|
+
options.method === 'multisig_approveRawTransactionSync';
|
|
270
|
+
const leaseTtl = synchronous &&
|
|
271
|
+
typeof timeout === 'number' &&
|
|
272
|
+
Number.isSafeInteger(timeout) &&
|
|
273
|
+
timeout >= 0
|
|
274
|
+
? timeout + submissionTtl
|
|
275
|
+
: submissionTtl;
|
|
276
|
+
const claim = await OperationStore.update(options.store, operationHash, (current) => {
|
|
277
|
+
if (!current || current.type !== 'transaction')
|
|
278
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
279
|
+
if (current.status === 'success')
|
|
280
|
+
return current;
|
|
281
|
+
if (current.status === 'submitting' && current.expiresAt > Date.now())
|
|
282
|
+
return current;
|
|
283
|
+
if (current.weight < current.threshold)
|
|
284
|
+
return current;
|
|
285
|
+
const now = Date.now();
|
|
286
|
+
return MultisigOperation.from({
|
|
287
|
+
...current,
|
|
288
|
+
expiresAt: Math.min(now + leaseTtl, Number.MAX_SAFE_INTEGER),
|
|
289
|
+
status: 'submitting',
|
|
290
|
+
submissionId,
|
|
291
|
+
updatedAt: now,
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
if (claim.type !== 'transaction')
|
|
295
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
296
|
+
if (claim.status === 'success')
|
|
297
|
+
return await submittedResult(options, claim);
|
|
298
|
+
if (claim.status === 'pending')
|
|
299
|
+
return pendingResult(options.method, claim);
|
|
300
|
+
if (claim.submissionId !== submissionId)
|
|
301
|
+
return await submittingResult(options, claim);
|
|
302
|
+
const { final, transactionHash: initialTransactionHash } = await (async () => {
|
|
303
|
+
try {
|
|
304
|
+
const blockNumber = await getBlockNumber(options.client, {
|
|
305
|
+
cacheTime: 0,
|
|
306
|
+
});
|
|
307
|
+
await validateConfig({
|
|
308
|
+
account: claim.account,
|
|
309
|
+
blockNumber,
|
|
310
|
+
client: options.client,
|
|
311
|
+
config: claim.config,
|
|
312
|
+
});
|
|
313
|
+
const finalApprovals = await selectApprovals({
|
|
314
|
+
account: claim.account,
|
|
315
|
+
blockNumber,
|
|
316
|
+
client: options.client,
|
|
317
|
+
config: claim.config,
|
|
318
|
+
hash: claim.hash,
|
|
319
|
+
approvals: claim.approvals,
|
|
320
|
+
store: options.store,
|
|
321
|
+
});
|
|
322
|
+
const final = MultisigOperation.serializeTransaction(claim, {
|
|
323
|
+
approvals: finalApprovals.selectedApprovals,
|
|
324
|
+
});
|
|
325
|
+
const transactionHash = TxEnvelopeTempo.hash(TxEnvelopeTempo.deserialize(final));
|
|
326
|
+
await OperationStore.writeSubmission(options.store, operationHash, submissionId, final);
|
|
327
|
+
return { final, transactionHash };
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
await releaseSubmission(options.store, operationHash, submissionId);
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
})();
|
|
334
|
+
let transactionHash = initialTransactionHash;
|
|
335
|
+
let result;
|
|
336
|
+
const stopLease = maintainSubmissionLease(options.store, operationHash, submissionId, leaseTtl);
|
|
337
|
+
let leaseStopped = false;
|
|
338
|
+
const stopLeaseOnce = async () => {
|
|
339
|
+
if (leaseStopped)
|
|
340
|
+
return;
|
|
341
|
+
leaseStopped = true;
|
|
342
|
+
await stopLease();
|
|
343
|
+
};
|
|
344
|
+
try {
|
|
345
|
+
try {
|
|
346
|
+
result = await options.next({
|
|
347
|
+
method: options.method === 'eth_sendRawTransaction' ||
|
|
348
|
+
options.method === 'multisig_approveRawTransaction'
|
|
349
|
+
? 'eth_sendRawTransaction'
|
|
350
|
+
: 'eth_sendRawTransactionSync',
|
|
351
|
+
params: [final, ...(options.request.params?.slice(1) ?? [])],
|
|
352
|
+
}, options.requestOptions);
|
|
353
|
+
const returnedHash = getTransactionHash(result);
|
|
354
|
+
if (returnedHash.toLowerCase() !== transactionHash.toLowerCase())
|
|
355
|
+
transactionHash = returnedHash;
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
const submittedHash = await OperationStore.readSubmission(options.store, claim, submissionId);
|
|
359
|
+
const transaction = await (async () => {
|
|
360
|
+
if (!submittedHash)
|
|
361
|
+
return null;
|
|
362
|
+
try {
|
|
363
|
+
return await options.next({
|
|
364
|
+
method: 'eth_getTransactionByHash',
|
|
365
|
+
params: [submittedHash],
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
})();
|
|
372
|
+
await stopLeaseOnce();
|
|
373
|
+
if (!submittedHash || !transaction) {
|
|
374
|
+
await releaseSubmission(options.store, operationHash, submissionId);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
transactionHash = submittedHash;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
await stopLeaseOnce();
|
|
382
|
+
}
|
|
383
|
+
const success = await OperationStore.update(options.store, operationHash, (current) => {
|
|
384
|
+
if (!current || current.type !== 'transaction')
|
|
385
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
386
|
+
if (current.status === 'success') {
|
|
387
|
+
if (current.transactionHash?.toLowerCase() !==
|
|
388
|
+
transactionHash.toLowerCase())
|
|
389
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
390
|
+
return current;
|
|
391
|
+
}
|
|
392
|
+
if (current.status !== 'submitting' ||
|
|
393
|
+
current.submissionId !== submissionId)
|
|
394
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
395
|
+
const { expiresAt: _, submissionId: __, ...operation } = current;
|
|
396
|
+
return MultisigOperation.from({
|
|
397
|
+
...operation,
|
|
398
|
+
status: 'success',
|
|
399
|
+
transactionHash,
|
|
400
|
+
updatedAt: Date.now(),
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
if (success.type !== 'transaction' || success.status !== 'success')
|
|
404
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
405
|
+
await removeSettledSubmission(options.store, operationHash, submissionId);
|
|
406
|
+
if (options.method === 'eth_sendRawTransactionSync' &&
|
|
407
|
+
result &&
|
|
408
|
+
typeof result === 'object')
|
|
409
|
+
return { ...result, multisig: MultisigOperation.toRpc(success) };
|
|
410
|
+
return await submittedResult(options, success);
|
|
411
|
+
}
|
|
412
|
+
/** Collects approvals for a multisig key authorization. @internal */
|
|
413
|
+
// biome-ignore lint/correctness/noUnusedVariables: declaration merge
|
|
414
|
+
async function approveKeyAuthorization(options) {
|
|
415
|
+
const value = options.request.params?.[0];
|
|
416
|
+
if (!value || typeof value !== 'object')
|
|
417
|
+
throw new RpcResponse.InvalidParamsError({
|
|
418
|
+
message: 'Expected a multisig key authorization approval.',
|
|
419
|
+
});
|
|
420
|
+
const approval = await (async () => {
|
|
421
|
+
if ('keyAuthorization' in value) {
|
|
422
|
+
const authorization = (() => {
|
|
423
|
+
try {
|
|
424
|
+
return KeyAuthorization.fromRpc(value.keyAuthorization);
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
throw new RpcResponse.InvalidParamsError({
|
|
428
|
+
message: 'Invalid multisig key authorization.',
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
})();
|
|
432
|
+
const signature = authorization.signature;
|
|
433
|
+
if (signature?.type !== 'multisig')
|
|
434
|
+
throw new RpcResponse.InvalidParamsError({
|
|
435
|
+
message: 'Expected a multisig key authorization signature.',
|
|
436
|
+
});
|
|
437
|
+
if (!authorization.account ||
|
|
438
|
+
!isAddressEqual(authorization.account, signature.account))
|
|
439
|
+
throw new RpcResponse.InvalidParamsError({
|
|
440
|
+
message: 'Multisig key authorization account does not match its signature.',
|
|
441
|
+
});
|
|
442
|
+
const { signature: _, ...unsigned } = authorization;
|
|
443
|
+
const keyAuthorization = KeyAuthorization.serialize(KeyAuthorization.from(unsigned));
|
|
444
|
+
const config = MultisigConfig.from(signature.config);
|
|
445
|
+
const hash = MultisigOperation.getHash({
|
|
446
|
+
account: signature.account,
|
|
447
|
+
config,
|
|
448
|
+
keyAuthorization,
|
|
449
|
+
type: 'keyAuthorization',
|
|
450
|
+
});
|
|
451
|
+
return {
|
|
452
|
+
account: signature.account,
|
|
453
|
+
approvals: signature.signatures.map((signature) => SignatureEnvelope.serialize(signature)),
|
|
454
|
+
config,
|
|
455
|
+
hash,
|
|
456
|
+
keyAuthorization,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if ('hash' in value && 'signature' in value) {
|
|
460
|
+
if (typeof value.hash !== 'string' || !Hash.validate(value.hash))
|
|
461
|
+
throw new RpcResponse.InvalidParamsError({
|
|
462
|
+
message: 'Expected a multisig operation hash.',
|
|
463
|
+
});
|
|
464
|
+
const operation = await OperationStore.read(options.store, value.hash);
|
|
465
|
+
if (!operation || operation.type !== 'keyAuthorization')
|
|
466
|
+
throw new RpcResponse.InvalidParamsError({
|
|
467
|
+
message: 'Multisig key authorization operation was not found.',
|
|
468
|
+
});
|
|
469
|
+
if (operation.status === 'success')
|
|
470
|
+
return { operation };
|
|
471
|
+
const signature = (() => {
|
|
472
|
+
try {
|
|
473
|
+
return SignatureEnvelope.serialize(SignatureEnvelope.from(value.signature));
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
throw new RpcResponse.InvalidParamsError({
|
|
477
|
+
message: 'Invalid multisig owner signature.',
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
})();
|
|
481
|
+
return {
|
|
482
|
+
account: operation.account,
|
|
483
|
+
approvals: [signature],
|
|
484
|
+
config: operation.config,
|
|
485
|
+
hash: operation.hash,
|
|
486
|
+
keyAuthorization: operation.keyAuthorization,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
throw new RpcResponse.InvalidParamsError({
|
|
490
|
+
message: 'Expected a multisig key authorization approval.',
|
|
491
|
+
});
|
|
492
|
+
})();
|
|
493
|
+
if ('operation' in approval)
|
|
494
|
+
return MultisigOperation.toRpc(approval.operation);
|
|
495
|
+
if (approval.approvals.length === 0)
|
|
496
|
+
throw new RpcResponse.InvalidParamsError({
|
|
497
|
+
message: 'A multisig approval envelope must include a signature.',
|
|
498
|
+
});
|
|
499
|
+
const blockNumber = await getBlockNumber(options.client, { cacheTime: 0 });
|
|
500
|
+
const commitment = await validateConfig({
|
|
501
|
+
account: approval.account,
|
|
502
|
+
blockNumber,
|
|
503
|
+
client: options.client,
|
|
504
|
+
config: approval.config,
|
|
505
|
+
});
|
|
506
|
+
const now = Date.now();
|
|
507
|
+
const operation = await OperationStore.update(options.store, approval.hash, async (existing) => {
|
|
508
|
+
if (existing && existing.type !== 'keyAuthorization')
|
|
509
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
510
|
+
if (existing?.status === 'success')
|
|
511
|
+
return existing;
|
|
512
|
+
if (existing &&
|
|
513
|
+
(existing.account.toLowerCase() !== approval.account.toLowerCase() ||
|
|
514
|
+
MultisigConfig.getCommitment(existing.config).toLowerCase() !==
|
|
515
|
+
MultisigConfig.getCommitment(approval.config).toLowerCase() ||
|
|
516
|
+
existing.keyAuthorization.toLowerCase() !==
|
|
517
|
+
approval.keyAuthorization.toLowerCase()))
|
|
518
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
519
|
+
const existingApprovals = existing
|
|
520
|
+
? await selectApprovals({
|
|
521
|
+
account: approval.account,
|
|
522
|
+
approvals: existing.approvals,
|
|
523
|
+
blockNumber,
|
|
524
|
+
client: options.client,
|
|
525
|
+
config: approval.config,
|
|
526
|
+
discardInvalidNested: true,
|
|
527
|
+
hash: approval.hash,
|
|
528
|
+
store: options.store,
|
|
529
|
+
})
|
|
530
|
+
: undefined;
|
|
531
|
+
const approvals = await selectApprovals({
|
|
532
|
+
account: approval.account,
|
|
533
|
+
approvals: [
|
|
534
|
+
...(existingApprovals?.approvals ?? []),
|
|
535
|
+
...approval.approvals,
|
|
536
|
+
],
|
|
537
|
+
blockNumber,
|
|
538
|
+
client: options.client,
|
|
539
|
+
config: approval.config,
|
|
540
|
+
hash: approval.hash,
|
|
541
|
+
store: options.store,
|
|
542
|
+
});
|
|
543
|
+
if (existing &&
|
|
544
|
+
approvals.approvals.length === existing.approvals.length &&
|
|
545
|
+
approvals.approvals.every((approval, index) => approval === existing.approvals[index]))
|
|
546
|
+
return existing;
|
|
547
|
+
const pending = {
|
|
548
|
+
account: approval.account,
|
|
549
|
+
approvals: approvals.approvals,
|
|
550
|
+
config: approval.config,
|
|
551
|
+
createdAt: existing?.createdAt ?? now,
|
|
552
|
+
hash: approval.hash,
|
|
553
|
+
keyAuthorization: approval.keyAuthorization,
|
|
554
|
+
signatureCount: approvals.signatureCount,
|
|
555
|
+
threshold: approvals.threshold,
|
|
556
|
+
type: 'keyAuthorization',
|
|
557
|
+
updatedAt: now,
|
|
558
|
+
weight: approvals.weight,
|
|
559
|
+
};
|
|
560
|
+
if (approvals.weight < approvals.threshold)
|
|
561
|
+
return MultisigOperation.from({ ...pending, status: 'pending' });
|
|
562
|
+
return MultisigOperation.from({
|
|
563
|
+
...pending,
|
|
564
|
+
keyAuthorization: MultisigOperation.serializeKeyAuthorization(approval.keyAuthorization, {
|
|
565
|
+
account: approval.account,
|
|
566
|
+
approvals: approvals.selectedApprovals,
|
|
567
|
+
config: approval.config,
|
|
568
|
+
}),
|
|
569
|
+
status: 'success',
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
await ConfigStore.write(options.store, {
|
|
573
|
+
address: approval.account,
|
|
574
|
+
commitment,
|
|
575
|
+
config: approval.config,
|
|
576
|
+
});
|
|
577
|
+
if (operation.type !== 'keyAuthorization')
|
|
578
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
579
|
+
return MultisigOperation.toRpc(operation);
|
|
580
|
+
}
|
|
581
|
+
/** Deserializes a Tempo transaction or throws an RPC parameter error. */
|
|
582
|
+
function deserialize(serialized) {
|
|
583
|
+
try {
|
|
584
|
+
return Transaction.deserialize(serialized);
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
throw new RpcResponse.InvalidParamsError({
|
|
588
|
+
message: 'Invalid serialized Tempo transaction.',
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
/** Validates a config against an observed chain commitment. */
|
|
593
|
+
function assertConfig(options) {
|
|
594
|
+
const { account, commitment, config } = options;
|
|
595
|
+
if (config.version === 0n &&
|
|
596
|
+
MultisigConfig.getAddress(config).toLowerCase() !== account.toLowerCase())
|
|
597
|
+
throw new RpcResponse.InvalidParamsError({
|
|
598
|
+
message: 'Initial multisig config does not match the multisig account.',
|
|
599
|
+
});
|
|
600
|
+
const expected = (() => {
|
|
601
|
+
if (config.version === 0n)
|
|
602
|
+
return Hex.fromNumber(0, { size: 32 });
|
|
603
|
+
return MultisigConfig.getCommitment(config);
|
|
604
|
+
})();
|
|
605
|
+
if (commitment.toLowerCase() !== expected.toLowerCase())
|
|
606
|
+
throw new RpcResponse.InvalidParamsError({
|
|
607
|
+
message: `Multisig config does not match account ${account}.`,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
/** Reads and validates a config commitment at one block. */
|
|
611
|
+
async function validateConfig(options) {
|
|
612
|
+
const { account, blockNumber, client, config } = options;
|
|
613
|
+
const commitment = await getConfigCommitment(client, {
|
|
614
|
+
account,
|
|
615
|
+
blockNumber,
|
|
616
|
+
});
|
|
617
|
+
assertConfig({ account, commitment, config });
|
|
618
|
+
return commitment;
|
|
619
|
+
}
|
|
620
|
+
/** Caches candidate configs from valid native update calls. */
|
|
621
|
+
// biome-ignore lint/correctness/noUnusedVariables: declaration merge
|
|
622
|
+
async function cacheNextConfigs(options) {
|
|
623
|
+
let currentConfig = options.config;
|
|
624
|
+
for (const call of options.transaction.calls) {
|
|
625
|
+
if (!call.to ||
|
|
626
|
+
!isAddressEqual(call.to, Addresses.nativeMultisig) ||
|
|
627
|
+
!call.data)
|
|
628
|
+
continue;
|
|
629
|
+
const decoded = (() => {
|
|
630
|
+
try {
|
|
631
|
+
return decodeFunctionData({ abi: Abis.nativeMultisig, data: call.data });
|
|
632
|
+
}
|
|
633
|
+
catch {
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
})();
|
|
637
|
+
if (decoded?.functionName !== 'updateConfig')
|
|
638
|
+
continue;
|
|
639
|
+
const [current, threshold, owners] = decoded.args;
|
|
640
|
+
const suppliedConfig = (() => {
|
|
641
|
+
try {
|
|
642
|
+
return MultisigConfig.from(current);
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
})();
|
|
648
|
+
if (!suppliedConfig ||
|
|
649
|
+
MultisigConfig.getCommitment(suppliedConfig).toLowerCase() !==
|
|
650
|
+
MultisigConfig.getCommitment(currentConfig).toLowerCase())
|
|
651
|
+
continue;
|
|
652
|
+
const config = (() => {
|
|
653
|
+
try {
|
|
654
|
+
return MultisigConfig.from({
|
|
655
|
+
owners,
|
|
656
|
+
salt: suppliedConfig.salt,
|
|
657
|
+
threshold,
|
|
658
|
+
version: suppliedConfig.version + 1n,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
})();
|
|
665
|
+
if (!config)
|
|
666
|
+
continue;
|
|
667
|
+
await ConfigStore.write(options.store, {
|
|
668
|
+
address: options.account,
|
|
669
|
+
commitment: MultisigConfig.getCommitment(config),
|
|
670
|
+
config,
|
|
671
|
+
});
|
|
672
|
+
currentConfig = config;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/** Selects approvals after validating every nested config. */
|
|
676
|
+
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
677
|
+
async function selectApprovals(options) {
|
|
678
|
+
const validation = new Map();
|
|
679
|
+
let validationCount = 0;
|
|
680
|
+
const select = async (approvals) => {
|
|
681
|
+
const result = await MultisigOperation.selectApprovals({
|
|
682
|
+
account: options.account,
|
|
683
|
+
approvals,
|
|
684
|
+
config: options.config,
|
|
685
|
+
hash: options.hash,
|
|
686
|
+
});
|
|
687
|
+
const configs = new Map();
|
|
688
|
+
const visit = (signature) => {
|
|
689
|
+
if (signature.type !== 'multisig')
|
|
690
|
+
return;
|
|
691
|
+
const config = MultisigConfig.from(signature.config);
|
|
692
|
+
const key = signature.account.toLowerCase();
|
|
693
|
+
configs.set(key, { account: signature.account, config });
|
|
694
|
+
for (const approval of signature.signatures)
|
|
695
|
+
visit(approval);
|
|
696
|
+
};
|
|
697
|
+
for (const approval of result.approvals)
|
|
698
|
+
visit(SignatureEnvelope.from(approval));
|
|
699
|
+
for (const { account, config } of configs.values()) {
|
|
700
|
+
const key = `${account.toLowerCase()}:${MultisigConfig.getCommitment(config)}`;
|
|
701
|
+
const pending = (() => {
|
|
702
|
+
const existing = validation.get(key);
|
|
703
|
+
if (existing)
|
|
704
|
+
return existing;
|
|
705
|
+
validationCount++;
|
|
706
|
+
if (validationCount > MultisigConfig.maxOwners)
|
|
707
|
+
throw new RpcResponse.InvalidParamsError({
|
|
708
|
+
message: 'Multisig approval validation exceeds the owner limit.',
|
|
709
|
+
});
|
|
710
|
+
const pending = validateConfig({
|
|
711
|
+
account,
|
|
712
|
+
blockNumber: options.blockNumber,
|
|
713
|
+
client: options.client,
|
|
714
|
+
config,
|
|
715
|
+
});
|
|
716
|
+
validation.set(key, pending);
|
|
717
|
+
return pending;
|
|
718
|
+
})();
|
|
719
|
+
const commitment = await pending;
|
|
720
|
+
await ConfigStore.write(options.store, {
|
|
721
|
+
address: account,
|
|
722
|
+
commitment,
|
|
723
|
+
config,
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
return result;
|
|
727
|
+
};
|
|
728
|
+
try {
|
|
729
|
+
if (!options.discardInvalidNested)
|
|
730
|
+
return await select(options.approvals);
|
|
731
|
+
const approvals = [];
|
|
732
|
+
for (const approval of options.approvals) {
|
|
733
|
+
if (SignatureEnvelope.from(approval).type !== 'multisig') {
|
|
734
|
+
approvals.push(approval);
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
try {
|
|
738
|
+
const retained = (await select([approval])).approvals[0];
|
|
739
|
+
if (retained)
|
|
740
|
+
approvals.push(retained);
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
if (error instanceof MultisigOperation.InvalidApprovalError ||
|
|
744
|
+
error instanceof RpcResponse.InvalidParamsError)
|
|
745
|
+
continue;
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return await select(approvals);
|
|
750
|
+
}
|
|
751
|
+
catch (error) {
|
|
752
|
+
if (error instanceof MultisigOperation.InvalidApprovalError)
|
|
753
|
+
throw new RpcResponse.InvalidParamsError({ message: error.shortMessage });
|
|
754
|
+
throw error;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
/** Returns an existing successful operation through the requested send method. */
|
|
758
|
+
async function submittedResult(options, operation) {
|
|
759
|
+
if (options.method === 'eth_sendRawTransaction' ||
|
|
760
|
+
options.method === 'multisig_approveRawTransaction')
|
|
761
|
+
return operation.hash;
|
|
762
|
+
if (options.method === 'multisig_approveRawTransactionSync')
|
|
763
|
+
return MultisigOperation.toRpc(operation);
|
|
764
|
+
const timeout = options.request.params?.[1];
|
|
765
|
+
const deadline = Date.now() +
|
|
766
|
+
(typeof timeout === 'number' && timeout >= 0 ? timeout : submissionTtl);
|
|
767
|
+
while (true) {
|
|
768
|
+
const receipt = await options.next({
|
|
769
|
+
method: 'eth_getTransactionReceipt',
|
|
770
|
+
params: [operation.transactionHash],
|
|
771
|
+
}, options.requestOptions);
|
|
772
|
+
if (receipt && typeof receipt === 'object')
|
|
773
|
+
return { ...receipt, multisig: MultisigOperation.toRpc(operation) };
|
|
774
|
+
if (Date.now() >= deadline)
|
|
775
|
+
throw new Error('Timed out while waiting for the multisig transaction.');
|
|
776
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
/** Waits for the relay that owns a live submission lease. */
|
|
780
|
+
async function submittingResult(options, operation) {
|
|
781
|
+
if (options.method === 'eth_sendRawTransaction' ||
|
|
782
|
+
options.method === 'multisig_approveRawTransaction')
|
|
783
|
+
return operation.hash;
|
|
784
|
+
const timeout = options.request.params?.[1];
|
|
785
|
+
const deadline = Date.now() +
|
|
786
|
+
(typeof timeout === 'number' && timeout >= 0 ? timeout : submissionTtl);
|
|
787
|
+
while (true) {
|
|
788
|
+
const current = await OperationStore.read(options.store, operation.hash);
|
|
789
|
+
if (!current || current.type !== 'transaction')
|
|
790
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
791
|
+
if (current.status === 'success')
|
|
792
|
+
return await submittedResult(options, current);
|
|
793
|
+
if (current.status === 'pending' || current.expiresAt <= Date.now())
|
|
794
|
+
return await submit(options);
|
|
795
|
+
if (Date.now() >= deadline)
|
|
796
|
+
return pendingResult(options.method, current);
|
|
797
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/** Returns a pending result for an operation that has not reached quorum. */
|
|
801
|
+
function pendingResult(method, operation) {
|
|
802
|
+
if (method === 'eth_sendRawTransaction' ||
|
|
803
|
+
method === 'multisig_approveRawTransaction')
|
|
804
|
+
return operation.hash;
|
|
805
|
+
if (method === 'multisig_approveRawTransactionSync')
|
|
806
|
+
return MultisigOperation.toRpc(operation);
|
|
807
|
+
return {
|
|
808
|
+
blockHash: null,
|
|
809
|
+
blockNumber: null,
|
|
810
|
+
contractAddress: null,
|
|
811
|
+
cumulativeGasUsed: null,
|
|
812
|
+
effectiveGasPrice: null,
|
|
813
|
+
from: operation.account,
|
|
814
|
+
gasUsed: null,
|
|
815
|
+
logs: [],
|
|
816
|
+
logsBloom: null,
|
|
817
|
+
multisig: MultisigOperation.toRpc(operation),
|
|
818
|
+
status: 'pending',
|
|
819
|
+
to: null,
|
|
820
|
+
transactionHash: operation.hash,
|
|
821
|
+
transactionIndex: null,
|
|
822
|
+
type: '0x76',
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
/** Marks a transaction as successful after a lookup proves that it was submitted. */
|
|
826
|
+
async function completeSubmission(store, operation, transactionHash) {
|
|
827
|
+
if (operation.status !== 'submitting' || !operation.submissionId)
|
|
828
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
829
|
+
const success = await OperationStore.update(store, operation.hash, (current) => {
|
|
830
|
+
if (!current || current.type !== 'transaction')
|
|
831
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
832
|
+
if (current.status === 'success') {
|
|
833
|
+
if (current.transactionHash?.toLowerCase() !==
|
|
834
|
+
transactionHash.toLowerCase())
|
|
835
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
836
|
+
return current;
|
|
837
|
+
}
|
|
838
|
+
if (current.status !== 'submitting' ||
|
|
839
|
+
current.submissionId !== operation.submissionId)
|
|
840
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
841
|
+
const { expiresAt: _, submissionId: __, transactionHash: ___, ...value } = current;
|
|
842
|
+
return MultisigOperation.from({
|
|
843
|
+
...value,
|
|
844
|
+
status: 'success',
|
|
845
|
+
transactionHash,
|
|
846
|
+
updatedAt: Date.now(),
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
await removeSettledSubmission(store, operation.hash, operation.submissionId);
|
|
850
|
+
return success;
|
|
851
|
+
}
|
|
852
|
+
/** Releases a failed submission lease without discarding collected approvals. */
|
|
853
|
+
async function releaseSubmission(store, hash, submissionId) {
|
|
854
|
+
await OperationStore.update(store, hash, (current) => {
|
|
855
|
+
if (!current || current.type !== 'transaction')
|
|
856
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
857
|
+
if (current.status !== 'submitting' ||
|
|
858
|
+
current.submissionId !== submissionId)
|
|
859
|
+
return current;
|
|
860
|
+
const { expiresAt: _, submissionId: __, ...operation } = current;
|
|
861
|
+
return MultisigOperation.from({
|
|
862
|
+
...operation,
|
|
863
|
+
status: 'pending',
|
|
864
|
+
updatedAt: Date.now(),
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
await OperationStore.removeSubmission(store, hash, submissionId);
|
|
868
|
+
}
|
|
869
|
+
/** Removes settled submission data without replacing a successful result with a cleanup error. */
|
|
870
|
+
async function removeSettledSubmission(store, hash, submissionId) {
|
|
871
|
+
try {
|
|
872
|
+
await OperationStore.removeSubmission(store, hash, submissionId);
|
|
873
|
+
}
|
|
874
|
+
catch { }
|
|
875
|
+
}
|
|
876
|
+
/** Preserves or upgrades a fee-payer envelope without removing an existing signature. */
|
|
877
|
+
function mergeTransaction(existing, incoming) {
|
|
878
|
+
if (!existing)
|
|
879
|
+
return incoming;
|
|
880
|
+
const existingTransaction = TxEnvelopeTempo.deserialize(existing);
|
|
881
|
+
const incomingTransaction = TxEnvelopeTempo.deserialize(incoming);
|
|
882
|
+
if (!('feePayerSignature' in incomingTransaction))
|
|
883
|
+
return existing;
|
|
884
|
+
if (incomingTransaction.feePayerSignature !== null)
|
|
885
|
+
return incoming;
|
|
886
|
+
if (!('feePayerSignature' in existingTransaction))
|
|
887
|
+
return incoming;
|
|
888
|
+
return existing;
|
|
889
|
+
}
|
|
890
|
+
/** Returns a synthetic transaction while the downstream transaction is unavailable. */
|
|
891
|
+
async function toTransaction(client, operation, store) {
|
|
892
|
+
const approvals = await (async () => {
|
|
893
|
+
if (operation.status !== 'pending')
|
|
894
|
+
return await MultisigOperation.selectApprovals({
|
|
895
|
+
account: operation.account,
|
|
896
|
+
approvals: operation.approvals,
|
|
897
|
+
config: operation.config,
|
|
898
|
+
hash: operation.hash,
|
|
899
|
+
});
|
|
900
|
+
const blockNumber = await getBlockNumber(client, { cacheTime: 0 });
|
|
901
|
+
await validateConfig({
|
|
902
|
+
account: operation.account,
|
|
903
|
+
blockNumber,
|
|
904
|
+
client,
|
|
905
|
+
config: operation.config,
|
|
906
|
+
});
|
|
907
|
+
return await selectApprovals({
|
|
908
|
+
account: operation.account,
|
|
909
|
+
approvals: operation.approvals,
|
|
910
|
+
blockNumber,
|
|
911
|
+
client,
|
|
912
|
+
config: operation.config,
|
|
913
|
+
discardInvalidNested: true,
|
|
914
|
+
hash: operation.hash,
|
|
915
|
+
store,
|
|
916
|
+
});
|
|
917
|
+
})();
|
|
918
|
+
const current = operation.status === 'pending'
|
|
919
|
+
? MultisigOperation.from({
|
|
920
|
+
...operation,
|
|
921
|
+
approvals: approvals.approvals,
|
|
922
|
+
signatureCount: approvals.signatureCount,
|
|
923
|
+
threshold: approvals.threshold,
|
|
924
|
+
weight: approvals.weight,
|
|
925
|
+
})
|
|
926
|
+
: operation;
|
|
927
|
+
const serialized = MultisigOperation.serializeTransaction(approvals.approvals.length > 0 ? current : operation, {
|
|
928
|
+
// Keep one stored approval in the synthetic envelope when every nested
|
|
929
|
+
// approval became stale. The next submission replaces it before broadcast.
|
|
930
|
+
approvals: approvals.selectedApprovals.length > 0
|
|
931
|
+
? approvals.selectedApprovals
|
|
932
|
+
: operation.approvals.slice(0, 1),
|
|
933
|
+
});
|
|
934
|
+
const transaction = deserialize(serialized);
|
|
935
|
+
return {
|
|
936
|
+
...ox_Transaction.toRpc({
|
|
937
|
+
...transaction,
|
|
938
|
+
blockHash: null,
|
|
939
|
+
blockNumber: null,
|
|
940
|
+
from: operation.account,
|
|
941
|
+
hash: operation.hash,
|
|
942
|
+
transactionIndex: null,
|
|
943
|
+
}, { pending: true }),
|
|
944
|
+
multisig: MultisigOperation.toRpc(current),
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
/** Returns the persisted transaction hash for a submitting or successful operation. */
|
|
948
|
+
async function getSubmittedTransactionHash(store, operation) {
|
|
949
|
+
if (operation.status === 'success')
|
|
950
|
+
return operation.transactionHash;
|
|
951
|
+
if (operation.status !== 'submitting' || !operation.submissionId)
|
|
952
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
953
|
+
return await OperationStore.readSubmission(store, operation, operation.submissionId);
|
|
954
|
+
}
|
|
955
|
+
/** Renews a submission lease until the returned cleanup function runs. */
|
|
956
|
+
function maintainSubmissionLease(store, hash, submissionId, leaseTtl) {
|
|
957
|
+
let active = true;
|
|
958
|
+
let error;
|
|
959
|
+
let renewal = Promise.resolve();
|
|
960
|
+
const timer = setInterval(() => {
|
|
961
|
+
renewal = renewal.then(async () => {
|
|
962
|
+
if (!active || error)
|
|
963
|
+
return;
|
|
964
|
+
try {
|
|
965
|
+
const operation = await OperationStore.update(store, hash, (current) => {
|
|
966
|
+
if (!current || current.type !== 'transaction')
|
|
967
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
968
|
+
if (current.status !== 'submitting' ||
|
|
969
|
+
current.submissionId !== submissionId)
|
|
970
|
+
return current;
|
|
971
|
+
return MultisigOperation.from({
|
|
972
|
+
...current,
|
|
973
|
+
expiresAt: Math.min(Date.now() + leaseTtl, Number.MAX_SAFE_INTEGER),
|
|
974
|
+
updatedAt: Date.now(),
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
if (operation.type !== 'transaction' ||
|
|
978
|
+
operation.status !== 'submitting' ||
|
|
979
|
+
operation.submissionId !== submissionId)
|
|
980
|
+
throw new OperationStore.InvalidStoreValueError();
|
|
981
|
+
}
|
|
982
|
+
catch (cause) {
|
|
983
|
+
error = cause;
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}, submissionTtl / 2);
|
|
987
|
+
return async () => {
|
|
988
|
+
active = false;
|
|
989
|
+
clearInterval(timer);
|
|
990
|
+
await renewal;
|
|
991
|
+
if (error)
|
|
992
|
+
throw error;
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
/** Canonically serializes an unsigned Tempo transaction. */
|
|
996
|
+
function serializeUnsigned(envelope, feePayer) {
|
|
997
|
+
return TxEnvelopeTempo.serialize(envelope, feePayer
|
|
998
|
+
? envelope.from
|
|
999
|
+
? { format: 'feePayer', sender: envelope.from }
|
|
1000
|
+
: { format: 'feePayer' }
|
|
1001
|
+
: {});
|
|
1002
|
+
}
|
|
1003
|
+
/** Extracts a transaction hash from an RPC submission result. */
|
|
1004
|
+
function getTransactionHash(result) {
|
|
1005
|
+
if (typeof result === 'string' && Hash.validate(result))
|
|
1006
|
+
return result;
|
|
1007
|
+
if (result &&
|
|
1008
|
+
typeof result === 'object' &&
|
|
1009
|
+
'transactionHash' in result &&
|
|
1010
|
+
typeof result.transactionHash === 'string' &&
|
|
1011
|
+
Hash.validate(result.transactionHash))
|
|
1012
|
+
return result.transactionHash;
|
|
1013
|
+
throw new Error('Expected transaction hash in multisig broadcast result.');
|
|
1014
|
+
}
|
|
1015
|
+
/** Checks whether a value is a serialized Tempo transaction. */
|
|
1016
|
+
function isSerializedTempoTransaction(value) {
|
|
1017
|
+
return (typeof value === 'string' &&
|
|
1018
|
+
(value.startsWith('0x76') || value.startsWith('0x78')));
|
|
1019
|
+
}
|
|
1020
|
+
//# sourceMappingURL=Multisig.js.map
|