viem 2.57.4 → 2.57.5
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 +26 -0
- package/_cjs/actions/public/waitForTransactionReceipt.js +5 -2
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/actions/wallet/waitForCallsStatus.js +25 -2
- package/_cjs/actions/wallet/waitForCallsStatus.js.map +1 -1
- package/_cjs/chains/definitions/arcTestnet.js +11 -8
- package/_cjs/chains/definitions/arcTestnet.js.map +1 -1
- package/_cjs/chains/definitions/qmsTestnet.js +30 -0
- package/_cjs/chains/definitions/qmsTestnet.js.map +1 -0
- package/_cjs/chains/definitions/tempo.js +1 -1
- package/_cjs/chains/definitions/tempoModerato.js +2 -2
- package/_cjs/chains/index.js +7 -5
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/transports/ipc.js +19 -10
- package/_cjs/clients/transports/ipc.js.map +1 -1
- package/_cjs/clients/transports/webSocket.js +19 -10
- package/_cjs/clients/transports/webSocket.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Account.js +40 -40
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Decorator.js +9 -8
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/ExecutionError.js +1 -1
- package/_cjs/tempo/ExecutionError.js.map +1 -1
- package/_cjs/tempo/Formatters.js +8 -7
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/KeyAuthorizationManager.js +25 -16
- package/_cjs/tempo/KeyAuthorizationManager.js.map +1 -1
- package/_cjs/tempo/Relay.js +9 -4
- package/_cjs/tempo/Relay.js.map +1 -1
- package/_cjs/tempo/Transaction.js +9 -9
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/Transport.js +21 -11
- package/_cjs/tempo/Transport.js.map +1 -1
- package/_cjs/tempo/{multisig → accounts}/Config.js +8 -8
- package/_cjs/tempo/{multisig → accounts}/Config.js.map +1 -1
- package/_cjs/tempo/{multisig → accounts}/Operation.js +10 -10
- package/_cjs/tempo/{multisig → accounts}/Operation.js.map +1 -1
- package/_cjs/tempo/{multisig → accounts}/Signature.js +2 -2
- package/_cjs/tempo/accounts/Signature.js.map +1 -0
- package/_cjs/tempo/actions/accessKey.js +60 -37
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/{multisig.js → accounts.js} +13 -18
- package/_cjs/tempo/actions/accounts.js.map +1 -0
- package/_cjs/tempo/actions/index.js +2 -2
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +37 -37
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +3 -3
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/relay/{multisig.js → accounts.js} +90 -93
- package/_cjs/tempo/internal/relay/accounts.js.map +1 -0
- package/_cjs/tempo/internal/relay/keyAuthorization.js +296 -0
- package/_cjs/tempo/internal/relay/keyAuthorization.js.map +1 -0
- package/_cjs/tempo/internal/relay/plugin.js +17 -7
- package/_cjs/tempo/internal/relay/plugin.js.map +1 -1
- package/_cjs/utils/hash/normalizeSignature.js +1 -1
- package/_cjs/utils/hash/normalizeSignature.js.map +1 -1
- package/_cjs/utils/rpc/http.js +66 -31
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/rpc/socket.js +1 -1
- package/_cjs/utils/rpc/socket.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +5 -2
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/actions/wallet/waitForCallsStatus.js +39 -2
- package/_esm/actions/wallet/waitForCallsStatus.js.map +1 -1
- package/_esm/chains/definitions/arcTestnet.js +11 -8
- package/_esm/chains/definitions/arcTestnet.js.map +1 -1
- package/_esm/chains/definitions/qmsTestnet.js +27 -0
- package/_esm/chains/definitions/qmsTestnet.js.map +1 -0
- package/_esm/chains/definitions/tempo.js +1 -1
- package/_esm/chains/definitions/tempoModerato.js +2 -2
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/transports/ipc.js +21 -10
- package/_esm/clients/transports/ipc.js.map +1 -1
- package/_esm/clients/transports/webSocket.js +21 -10
- package/_esm/clients/transports/webSocket.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Account.js +42 -42
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Client.js +3 -3
- package/_esm/tempo/Decorator.js +9 -8
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/ExecutionError.js +1 -1
- package/_esm/tempo/ExecutionError.js.map +1 -1
- package/_esm/tempo/Formatters.js +11 -10
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/KeyAuthorizationManager.js +58 -16
- package/_esm/tempo/KeyAuthorizationManager.js.map +1 -1
- package/_esm/tempo/Relay.js +49 -8
- package/_esm/tempo/Relay.js.map +1 -1
- package/_esm/tempo/Transaction.js +11 -11
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/Transport.js +22 -12
- package/_esm/tempo/Transport.js.map +1 -1
- package/_esm/tempo/{multisig → accounts}/Config.js +14 -14
- package/_esm/tempo/{multisig → accounts}/Config.js.map +1 -1
- package/_esm/tempo/{multisig → accounts}/Operation.js +17 -17
- package/_esm/tempo/{multisig → accounts}/Operation.js.map +1 -1
- package/_esm/tempo/accounts/Signature.js +9 -0
- package/_esm/tempo/accounts/Signature.js.map +1 -0
- package/_esm/tempo/actions/accessKey.js +93 -38
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/{multisig.js → accounts.js} +31 -36
- package/_esm/tempo/actions/accounts.js.map +1 -0
- package/_esm/tempo/actions/index.js +1 -1
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/chainConfig.js +38 -38
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +2 -1
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/relay/{multisig.js → accounts.js} +93 -98
- package/_esm/tempo/internal/relay/accounts.js.map +1 -0
- package/_esm/tempo/internal/relay/feePayer.js +1 -1
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/tempo/internal/relay/keyAuthorization.js +334 -0
- package/_esm/tempo/internal/relay/keyAuthorization.js.map +1 -0
- package/_esm/tempo/internal/relay/plugin.js +15 -6
- package/_esm/tempo/internal/relay/plugin.js.map +1 -1
- package/_esm/utils/hash/normalizeSignature.js +3 -2
- package/_esm/utils/hash/normalizeSignature.js.map +1 -1
- package/_esm/utils/rpc/http.js +74 -31
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/rpc/socket.js +3 -1
- package/_esm/utils/rpc/socket.js.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/actions/wallet/waitForCallsStatus.d.ts.map +1 -1
- package/_types/chains/definitions/arcTestnet.d.ts +5 -5
- package/_types/chains/definitions/arcTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/qmsTestnet.d.ts +50 -0
- package/_types/chains/definitions/qmsTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +2 -2
- package/_types/chains/definitions/tempoModerato.d.ts +4 -4
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/transports/ipc.d.ts.map +1 -1
- package/_types/clients/transports/webSocket.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Account.d.ts +28 -28
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Client.d.ts +3 -3
- package/_types/tempo/Decorator.d.ts +63 -37
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/KeyAuthorizationManager.d.ts +45 -2
- package/_types/tempo/KeyAuthorizationManager.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +62 -12
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +14 -11
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/Transport.d.ts +20 -7
- package/_types/tempo/Transport.d.ts.map +1 -1
- package/_types/tempo/{multisig → accounts}/Config.d.ts +7 -7
- package/_types/tempo/accounts/Config.d.ts.map +1 -0
- package/_types/tempo/{multisig → accounts}/Operation.d.ts +7 -7
- package/_types/tempo/accounts/Operation.d.ts.map +1 -0
- package/_types/tempo/{multisig → accounts}/Signature.d.ts +1 -1
- package/_types/tempo/accounts/Signature.d.ts.map +1 -0
- package/_types/tempo/actions/accessKey.d.ts +59 -17
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/{multisig.d.ts → accounts.d.ts} +28 -28
- package/_types/tempo/actions/{multisig.d.ts.map → accounts.d.ts.map} +1 -1
- package/_types/tempo/actions/index.d.ts +1 -1
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +3 -2
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/relay/accounts.d.ts +15 -0
- package/_types/tempo/internal/relay/accounts.d.ts.map +1 -0
- package/_types/tempo/internal/relay/keyAuthorization.d.ts +25 -0
- package/_types/tempo/internal/relay/keyAuthorization.d.ts.map +1 -0
- package/_types/tempo/internal/relay/plugin.d.ts +6 -3
- package/_types/tempo/internal/relay/plugin.d.ts.map +1 -1
- package/_types/utils/hash/normalizeSignature.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/rpc/socket.d.ts.map +1 -1
- package/actions/public/waitForTransactionReceipt.ts +8 -2
- package/actions/wallet/waitForCallsStatus.ts +41 -2
- package/chains/definitions/arcTestnet.ts +11 -8
- package/chains/definitions/qmsTestnet.ts +27 -0
- package/chains/definitions/tempo.ts +1 -1
- package/chains/definitions/tempoModerato.ts +2 -2
- package/chains/index.ts +1 -0
- package/clients/transports/ipc.ts +38 -29
- package/clients/transports/webSocket.ts +42 -33
- package/errors/version.ts +1 -1
- package/package.json +2 -2
- package/tempo/Account.ts +95 -84
- package/tempo/Client.ts +3 -3
- package/tempo/Decorator.ts +86 -57
- package/tempo/ExecutionError.ts +1 -1
- package/tempo/Formatters.ts +14 -13
- package/tempo/KeyAuthorizationManager.ts +71 -19
- package/tempo/Relay.ts +70 -14
- package/tempo/Transaction.ts +31 -23
- package/tempo/Transport.ts +49 -21
- package/tempo/{multisig → accounts}/Config.ts +21 -21
- package/tempo/{multisig → accounts}/Operation.ts +26 -26
- package/tempo/{multisig → accounts}/Signature.ts +5 -3
- package/tempo/actions/accessKey.ts +179 -79
- package/tempo/actions/{multisig.ts → accounts.ts} +47 -56
- package/tempo/actions/index.ts +1 -1
- package/tempo/chainConfig.ts +52 -52
- package/tempo/index.ts +5 -4
- package/tempo/internal/relay/{multisig.ts → accounts.ts} +118 -118
- package/tempo/internal/relay/feePayer.ts +1 -1
- package/tempo/internal/relay/keyAuthorization.ts +415 -0
- package/tempo/internal/relay/plugin.ts +20 -7
- package/utils/hash/normalizeSignature.ts +3 -2
- package/utils/rpc/http.ts +76 -30
- package/utils/rpc/socket.ts +3 -1
- package/_cjs/tempo/actions/multisig.js.map +0 -1
- package/_cjs/tempo/internal/relay/multisig.js.map +0 -1
- package/_cjs/tempo/multisig/Signature.js.map +0 -1
- package/_esm/tempo/actions/multisig.js.map +0 -1
- package/_esm/tempo/internal/relay/multisig.js.map +0 -1
- package/_esm/tempo/multisig/Signature.js +0 -9
- package/_esm/tempo/multisig/Signature.js.map +0 -1
- package/_types/tempo/internal/relay/multisig.d.ts +0 -4
- package/_types/tempo/internal/relay/multisig.d.ts.map +0 -1
- package/_types/tempo/multisig/Config.d.ts.map +0 -1
- package/_types/tempo/multisig/Operation.d.ts.map +0 -1
- package/_types/tempo/multisig/Signature.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Address } from 'abitype'
|
|
2
2
|
import type * as RpcSchema from 'ox/RpcSchema'
|
|
3
3
|
import {
|
|
4
|
+
AccountConfig,
|
|
5
|
+
AccountOperation,
|
|
4
6
|
KeyAuthorization,
|
|
5
|
-
MultisigConfig,
|
|
6
|
-
MultisigOperation,
|
|
7
7
|
type RpcSchemaTempo,
|
|
8
8
|
SignatureEnvelope,
|
|
9
9
|
} from 'ox/tempo'
|
|
@@ -21,6 +21,10 @@ import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
|
|
|
21
21
|
import type { Client } from '../../clients/createClient.js'
|
|
22
22
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
23
23
|
import type { BaseErrorType } from '../../errors/base.js'
|
|
24
|
+
import {
|
|
25
|
+
MethodNotFoundRpcError,
|
|
26
|
+
MethodNotSupportedRpcError,
|
|
27
|
+
} from '../../errors/rpc.js'
|
|
24
28
|
import type { Chain } from '../../types/chain.js'
|
|
25
29
|
import type { ExtractAbiItem, GetEventArgs } from '../../types/contract.js'
|
|
26
30
|
import type { Log, Log as viem_Log } from '../../types/log.js'
|
|
@@ -31,16 +35,17 @@ import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
|
|
|
31
35
|
import * as Abis from '../Abis.js'
|
|
32
36
|
import type {
|
|
33
37
|
AccessKeyAccount,
|
|
34
|
-
|
|
38
|
+
ConfigurableAccount,
|
|
35
39
|
RootAccount,
|
|
36
40
|
} from '../Account.js'
|
|
37
41
|
import {
|
|
38
|
-
|
|
42
|
+
fromConfig,
|
|
39
43
|
getKeyAuthorizationSignPayload,
|
|
40
44
|
resolveAccessKey,
|
|
41
45
|
signKeyAuthorization,
|
|
42
46
|
} from '../Account.js'
|
|
43
47
|
import * as Addresses from '../Addresses.js'
|
|
48
|
+
import { parseApproval } from '../accounts/Signature.js'
|
|
44
49
|
import * as Hardfork from '../Hardfork.js'
|
|
45
50
|
import type {
|
|
46
51
|
GetAccountParameter,
|
|
@@ -48,9 +53,8 @@ import type {
|
|
|
48
53
|
WriteParameters,
|
|
49
54
|
} from '../internal/types.js'
|
|
50
55
|
import { defineCall } from '../internal/utils.js'
|
|
51
|
-
import { parseApproval } from '../multisig/Signature.js'
|
|
52
56
|
import type { TransactionReceipt } from '../Transaction.js'
|
|
53
|
-
import { getConfig } from './
|
|
57
|
+
import { getConfig } from './accounts.js'
|
|
54
58
|
|
|
55
59
|
/** @internal */
|
|
56
60
|
const signatureTypes = {
|
|
@@ -174,7 +178,7 @@ export namespace authorize {
|
|
|
174
178
|
const account_ = rest.account ?? client.account
|
|
175
179
|
if (!account_) throw new Error('account is required.')
|
|
176
180
|
if (!chainId) throw new Error('chainId is required.')
|
|
177
|
-
const keyAuthorization = await
|
|
181
|
+
const keyAuthorization = await signLocal(client, {
|
|
178
182
|
account: account_,
|
|
179
183
|
accessKey,
|
|
180
184
|
chainId,
|
|
@@ -1058,13 +1062,13 @@ export async function prepareAuthorization<
|
|
|
1058
1062
|
if (!account_) throw new Error('account is required.')
|
|
1059
1063
|
if (!chainId) throw new Error('chainId is required.')
|
|
1060
1064
|
const parsed = parseAccount(account_)
|
|
1061
|
-
const
|
|
1062
|
-
if ('
|
|
1063
|
-
if (parsed.source !== '
|
|
1064
|
-
const account = parsed as
|
|
1065
|
+
const configurableState = await (async () => {
|
|
1066
|
+
if ('configurable' in parameters) return parameters.configurable
|
|
1067
|
+
if (parsed.source !== 'configurable') return undefined
|
|
1068
|
+
const account = parsed as ConfigurableAccount
|
|
1065
1069
|
if (!account.config)
|
|
1066
1070
|
throw new Error(
|
|
1067
|
-
'
|
|
1071
|
+
'An account config is required to prepare a key authorization.',
|
|
1068
1072
|
)
|
|
1069
1073
|
return { config: account.config }
|
|
1070
1074
|
})()
|
|
@@ -1077,10 +1081,10 @@ export async function prepareAuthorization<
|
|
|
1077
1081
|
},
|
|
1078
1082
|
)
|
|
1079
1083
|
const signPayload =
|
|
1080
|
-
parsed.source === '
|
|
1081
|
-
?
|
|
1084
|
+
parsed.source === 'configurable' && configurableState
|
|
1085
|
+
? AccountConfig.getSignPayload({
|
|
1082
1086
|
account: parsed.address,
|
|
1083
|
-
config:
|
|
1087
|
+
config: configurableState.config,
|
|
1084
1088
|
payload: authorizationSignPayload,
|
|
1085
1089
|
})
|
|
1086
1090
|
: authorizationSignPayload
|
|
@@ -1088,7 +1092,7 @@ export async function prepareAuthorization<
|
|
|
1088
1092
|
...parameters,
|
|
1089
1093
|
account: parsed,
|
|
1090
1094
|
chainId,
|
|
1091
|
-
|
|
1095
|
+
configurable: configurableState,
|
|
1092
1096
|
signPayload,
|
|
1093
1097
|
} as never
|
|
1094
1098
|
}
|
|
@@ -1115,8 +1119,8 @@ export namespace prepareAuthorization {
|
|
|
1115
1119
|
limits?:
|
|
1116
1120
|
| { token: Address; limit: bigint; period?: number | undefined }[]
|
|
1117
1121
|
| undefined
|
|
1118
|
-
/** @internal Prepared
|
|
1119
|
-
|
|
1122
|
+
/** @internal Prepared configurable account state. */
|
|
1123
|
+
configurable?: signKeyAuthorization.Parameters['configurable']
|
|
1120
1124
|
/** Call scopes restricting which contracts/selectors this key can call. */
|
|
1121
1125
|
scopes?: KeyAuthorization.Scope[] | undefined
|
|
1122
1126
|
/**
|
|
@@ -1136,22 +1140,81 @@ export namespace prepareAuthorization {
|
|
|
1136
1140
|
Omit<Parameters<Account | undefined>, 'account' | 'chainId'> & {
|
|
1137
1141
|
account: Account
|
|
1138
1142
|
chainId: number
|
|
1139
|
-
|
|
1140
|
-
/** Payload that the authorizing account or
|
|
1143
|
+
configurable: signKeyAuthorization.Parameters['configurable']
|
|
1144
|
+
/** Payload that the authorizing account or owners sign. */
|
|
1141
1145
|
signPayload: Hex
|
|
1142
1146
|
}
|
|
1143
1147
|
>
|
|
1144
1148
|
}
|
|
1145
1149
|
|
|
1150
|
+
/**
|
|
1151
|
+
* Saves a signed key authorization to a relay with key authorization storage.
|
|
1152
|
+
*
|
|
1153
|
+
* The relay attaches the authorization to the access key's next transaction until
|
|
1154
|
+
* the key is active onchain. Use this for authorizations signed outside
|
|
1155
|
+
* {@link signAuthorization}, such as on another device. Requires a relay running the
|
|
1156
|
+
* `Relay.keyAuthorization` plugin.
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```ts
|
|
1160
|
+
* import { createClient, http } from 'viem'
|
|
1161
|
+
* import { tempo } from 'viem/chains'
|
|
1162
|
+
* import { Actions, withRelay } from 'viem/tempo'
|
|
1163
|
+
*
|
|
1164
|
+
* const client = createClient({
|
|
1165
|
+
* chain: tempo,
|
|
1166
|
+
* transport: withRelay(http(), http('https://relay.example.com'), {
|
|
1167
|
+
* keyAuthorization: true,
|
|
1168
|
+
* }),
|
|
1169
|
+
* })
|
|
1170
|
+
*
|
|
1171
|
+
* await Actions.accessKey.saveAuthorization(client, {
|
|
1172
|
+
* keyAuthorization,
|
|
1173
|
+
* })
|
|
1174
|
+
* ```
|
|
1175
|
+
*
|
|
1176
|
+
* @param client - Client.
|
|
1177
|
+
* @param parameters - Parameters.
|
|
1178
|
+
*/
|
|
1179
|
+
export async function saveAuthorization<
|
|
1180
|
+
chain extends Chain | undefined,
|
|
1181
|
+
account extends Account | undefined,
|
|
1182
|
+
>(
|
|
1183
|
+
client: Client<Transport, chain, account>,
|
|
1184
|
+
parameters: saveAuthorization.Parameters,
|
|
1185
|
+
): Promise<saveAuthorization.ReturnValue> {
|
|
1186
|
+
const { keyAuthorization } = parameters
|
|
1187
|
+
await client.request<relay_saveKeyAuthorization>({
|
|
1188
|
+
method: 'relay_saveKeyAuthorization',
|
|
1189
|
+
params: [KeyAuthorization.toRpc(keyAuthorization)],
|
|
1190
|
+
})
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
export namespace saveAuthorization {
|
|
1194
|
+
export type Parameters = {
|
|
1195
|
+
/** Signed key authorization to save. */
|
|
1196
|
+
keyAuthorization: KeyAuthorization.Signed
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
export type ReturnValue = void
|
|
1200
|
+
|
|
1201
|
+
// TODO: exhaustive error type
|
|
1202
|
+
export type ErrorType = BaseErrorType
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1146
1205
|
/**
|
|
1147
1206
|
* Signs a key authorization for an access key.
|
|
1148
1207
|
*
|
|
1149
1208
|
* Use {@link prepareAuthorization} before this action when signing requires
|
|
1150
1209
|
* transient user activation.
|
|
1151
1210
|
*
|
|
1211
|
+
* When the client transport is a relay with the `Relay.keyAuthorization` plugin,
|
|
1212
|
+
* an authorization signed by the account is saved to the relay, which attaches it
|
|
1213
|
+
* to the access key's next transaction.
|
|
1214
|
+
*
|
|
1152
1215
|
* @param client - Client.
|
|
1153
1216
|
* @param parameters - Authorization fields, or a stored operation hash.
|
|
1154
|
-
* @returns A signed key authorization with
|
|
1217
|
+
* @returns A signed key authorization with account operation metadata when coordinated.
|
|
1155
1218
|
*/
|
|
1156
1219
|
export function signAuthorization<
|
|
1157
1220
|
chain extends Chain | undefined,
|
|
@@ -1185,13 +1248,13 @@ export async function signAuthorization<
|
|
|
1185
1248
|
const owner_ = parameters_.owner
|
|
1186
1249
|
if (!owner_ || typeof owner_ === 'string')
|
|
1187
1250
|
throw new Error(
|
|
1188
|
-
'A local owner account is required to approve a
|
|
1251
|
+
'A local owner account is required to approve a configurable account key authorization.',
|
|
1189
1252
|
)
|
|
1190
1253
|
const owner = parseAccount(owner_)
|
|
1191
1254
|
const sign = owner.sign
|
|
1192
1255
|
if (!sign)
|
|
1193
1256
|
throw new Error(
|
|
1194
|
-
'A local owner account is required to approve a
|
|
1257
|
+
'A local owner account is required to approve a configurable account key authorization.',
|
|
1195
1258
|
)
|
|
1196
1259
|
|
|
1197
1260
|
const request = await (async () => {
|
|
@@ -1214,16 +1277,16 @@ export async function signAuthorization<
|
|
|
1214
1277
|
const config = await getConfig(client, { address })
|
|
1215
1278
|
if (config) return config
|
|
1216
1279
|
throw new Error(
|
|
1217
|
-
`No current
|
|
1280
|
+
`No current account config is cached for account ${address}. Provide the current config.`,
|
|
1218
1281
|
)
|
|
1219
1282
|
})()
|
|
1220
1283
|
const account = (() => {
|
|
1221
|
-
if (config.version !== 0n) return
|
|
1284
|
+
if (config.version !== 0n) return fromConfig({ address, ...config })
|
|
1222
1285
|
const { version: _, ...initialConfig } = config
|
|
1223
|
-
return
|
|
1286
|
+
return fromConfig({ address: 'infer', ...initialConfig })
|
|
1224
1287
|
})()
|
|
1225
1288
|
if (!isAddressEqual(account.address, address))
|
|
1226
|
-
throw new Error('Initial
|
|
1289
|
+
throw new Error('Initial account config does not match the account.')
|
|
1227
1290
|
const prepared = await prepareAuthorization(client, {
|
|
1228
1291
|
...authorization,
|
|
1229
1292
|
account,
|
|
@@ -1250,79 +1313,81 @@ export async function signAuthorization<
|
|
|
1250
1313
|
return { keyAuthorization: KeyAuthorization.toRpc(keyAuthorization) }
|
|
1251
1314
|
})()
|
|
1252
1315
|
|
|
1253
|
-
type
|
|
1254
|
-
RpcSchema.ToViem<RpcSchemaTempo.
|
|
1255
|
-
{ Method: '
|
|
1316
|
+
type account_approveKeyAuthorization = Extract<
|
|
1317
|
+
RpcSchema.ToViem<RpcSchemaTempo.Account>[number],
|
|
1318
|
+
{ Method: 'account_approveKeyAuthorization' }
|
|
1256
1319
|
>
|
|
1257
|
-
const operation = await client.request<
|
|
1258
|
-
method: '
|
|
1320
|
+
const operation = await client.request<account_approveKeyAuthorization>({
|
|
1321
|
+
method: 'account_approveKeyAuthorization',
|
|
1259
1322
|
params: [request],
|
|
1260
1323
|
})
|
|
1261
|
-
const
|
|
1324
|
+
const operation_ = AccountOperation.fromRpc(operation)
|
|
1262
1325
|
const keyAuthorization = KeyAuthorization.deserialize(
|
|
1263
1326
|
await (async () => {
|
|
1264
|
-
if (
|
|
1265
|
-
const approvals = await
|
|
1266
|
-
account:
|
|
1267
|
-
approvals:
|
|
1268
|
-
config:
|
|
1269
|
-
hash:
|
|
1327
|
+
if (operation_.status === 'success') return operation_.keyAuthorization
|
|
1328
|
+
const approvals = await AccountOperation.selectApprovals({
|
|
1329
|
+
account: operation_.account,
|
|
1330
|
+
approvals: operation_.approvals,
|
|
1331
|
+
config: operation_.config,
|
|
1332
|
+
hash: operation_.hash,
|
|
1270
1333
|
})
|
|
1271
|
-
return
|
|
1272
|
-
|
|
1334
|
+
return AccountOperation.serializeKeyAuthorization(
|
|
1335
|
+
operation_.keyAuthorization,
|
|
1273
1336
|
{
|
|
1274
|
-
account:
|
|
1337
|
+
account: operation_.account,
|
|
1275
1338
|
approvals:
|
|
1276
1339
|
approvals.selectedApprovals.length > 0
|
|
1277
1340
|
? approvals.selectedApprovals
|
|
1278
1341
|
: approvals.approvals.slice(0, 1),
|
|
1279
|
-
config:
|
|
1342
|
+
config: operation_.config,
|
|
1280
1343
|
},
|
|
1281
1344
|
)
|
|
1282
1345
|
})(),
|
|
1283
1346
|
)
|
|
1284
1347
|
if (!keyAuthorization.signature)
|
|
1285
|
-
throw new Error(
|
|
1348
|
+
throw new Error(
|
|
1349
|
+
'Expected a signed configurable account key authorization.',
|
|
1350
|
+
)
|
|
1286
1351
|
return {
|
|
1287
1352
|
...keyAuthorization,
|
|
1288
|
-
hash:
|
|
1289
|
-
|
|
1290
|
-
status:
|
|
1353
|
+
hash: operation_.hash,
|
|
1354
|
+
operation: operation_,
|
|
1355
|
+
status: operation_.status,
|
|
1291
1356
|
} as never
|
|
1292
1357
|
}
|
|
1293
1358
|
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1359
|
+
const keyAuthorization = await signLocal(
|
|
1360
|
+
client,
|
|
1361
|
+
parameters as signAuthorization.LocalParameters<account>,
|
|
1362
|
+
)
|
|
1363
|
+
const signer = parameters.account ?? client.account
|
|
1364
|
+
// Relays with key authorization storage attach it to the access key's next
|
|
1365
|
+
// transaction. Admin-signed authorizations can only be submitted by the admin key.
|
|
1366
|
+
if (
|
|
1367
|
+
(client.transport as { keyAuthorization?: boolean }).keyAuthorization &&
|
|
1368
|
+
signer &&
|
|
1369
|
+
parseAccount(signer).source !== 'accessKey'
|
|
1370
|
+
)
|
|
1371
|
+
await saveAuthorization(client, { keyAuthorization }).catch((error) => {
|
|
1372
|
+
// Remote relays without key authorization storage do not expose this method.
|
|
1373
|
+
if (
|
|
1374
|
+
error instanceof MethodNotFoundRpcError ||
|
|
1375
|
+
error instanceof MethodNotSupportedRpcError
|
|
1376
|
+
)
|
|
1377
|
+
return
|
|
1378
|
+
throw error
|
|
1379
|
+
})
|
|
1380
|
+
return keyAuthorization
|
|
1316
1381
|
}
|
|
1317
1382
|
|
|
1318
1383
|
export namespace signAuthorization {
|
|
1319
1384
|
/** Initial coordinated key authorization parameters. */
|
|
1320
1385
|
export type CoordinatedInitialParameters = Omit<
|
|
1321
1386
|
prepareAuthorization.Parameters<Account>,
|
|
1322
|
-
'account' | '
|
|
1387
|
+
'account' | 'configurable'
|
|
1323
1388
|
> & {
|
|
1324
|
-
/**
|
|
1325
|
-
account: Address |
|
|
1389
|
+
/** Configurable account being authorized. */
|
|
1390
|
+
account: Address | ConfigurableAccount
|
|
1326
1391
|
/** Local owner that approves the authorization. */
|
|
1327
1392
|
owner: RootAccount
|
|
1328
1393
|
}
|
|
@@ -1331,7 +1396,7 @@ export namespace signAuthorization {
|
|
|
1331
1396
|
export type CoordinatedParameters = OneOf<
|
|
1332
1397
|
| CoordinatedInitialParameters
|
|
1333
1398
|
| {
|
|
1334
|
-
/** Stored
|
|
1399
|
+
/** Stored account operation hash. */
|
|
1335
1400
|
hash: Hex
|
|
1336
1401
|
/** Local owner that approves the authorization. */
|
|
1337
1402
|
owner: RootAccount
|
|
@@ -1342,7 +1407,7 @@ export namespace signAuthorization {
|
|
|
1342
1407
|
export type LocalParameters<
|
|
1343
1408
|
account extends Account | undefined = Account | undefined,
|
|
1344
1409
|
> = prepareAuthorization.Parameters<account> & {
|
|
1345
|
-
/** Serialized approvals from external
|
|
1410
|
+
/** Serialized approvals from external owners. */
|
|
1346
1411
|
signatures?: readonly SignatureEnvelope.Serialized[] | undefined
|
|
1347
1412
|
}
|
|
1348
1413
|
|
|
@@ -1357,12 +1422,12 @@ export namespace signAuthorization {
|
|
|
1357
1422
|
/** Coordinated return value for {@link signAuthorization}. */
|
|
1358
1423
|
export type CoordinatedReturnValue = Compute<
|
|
1359
1424
|
ReturnValue & {
|
|
1360
|
-
/** Deterministic
|
|
1425
|
+
/** Deterministic account operation hash. */
|
|
1361
1426
|
hash: Hex
|
|
1362
|
-
/** Current
|
|
1363
|
-
|
|
1364
|
-
/** Current
|
|
1365
|
-
status:
|
|
1427
|
+
/** Current account operation. */
|
|
1428
|
+
operation: AccountOperation.KeyAuthorizationOperation
|
|
1429
|
+
/** Current account operation status. */
|
|
1430
|
+
status: AccountOperation.KeyAuthorizationOperation['status']
|
|
1366
1431
|
}
|
|
1367
1432
|
>
|
|
1368
1433
|
|
|
@@ -1370,6 +1435,41 @@ export namespace signAuthorization {
|
|
|
1370
1435
|
export type ErrorType = BaseErrorType
|
|
1371
1436
|
}
|
|
1372
1437
|
|
|
1438
|
+
/** Signs a key authorization locally without saving it to a relay. */
|
|
1439
|
+
async function signLocal<
|
|
1440
|
+
chain extends Chain | undefined,
|
|
1441
|
+
account extends Account | undefined,
|
|
1442
|
+
>(
|
|
1443
|
+
client: Client<Transport, chain, account>,
|
|
1444
|
+
parameters: signAuthorization.LocalParameters<account>,
|
|
1445
|
+
): Promise<signAuthorization.ReturnValue> {
|
|
1446
|
+
const prepared = (
|
|
1447
|
+
'signPayload' in parameters
|
|
1448
|
+
? parameters
|
|
1449
|
+
: await prepareAuthorization(client, parameters)
|
|
1450
|
+
) as prepareAuthorization.ReturnValue
|
|
1451
|
+
const {
|
|
1452
|
+
accessKey,
|
|
1453
|
+
account: account_,
|
|
1454
|
+
chainId,
|
|
1455
|
+
configurable: configurableState,
|
|
1456
|
+
signPayload: _,
|
|
1457
|
+
...rest
|
|
1458
|
+
} = prepared
|
|
1459
|
+
return signKeyAuthorization(account_ as never, {
|
|
1460
|
+
chainId: BigInt(chainId),
|
|
1461
|
+
key: accessKey,
|
|
1462
|
+
configurable: configurableState,
|
|
1463
|
+
...rest,
|
|
1464
|
+
})
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
type relay_saveKeyAuthorization = {
|
|
1468
|
+
Method: 'relay_saveKeyAuthorization'
|
|
1469
|
+
Parameters: [KeyAuthorization.Rpc]
|
|
1470
|
+
ReturnType: null
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1373
1473
|
/**
|
|
1374
1474
|
* Updates the spending limit for a specific token on an authorized access key.
|
|
1375
1475
|
*
|