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