accounts 0.6.7 → 0.7.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/core/ExecutionError.d.ts +25 -0
  3. package/dist/core/ExecutionError.d.ts.map +1 -0
  4. package/dist/core/ExecutionError.js +170 -0
  5. package/dist/core/ExecutionError.js.map +1 -0
  6. package/dist/core/Schema.d.ts +33 -7
  7. package/dist/core/Schema.d.ts.map +1 -1
  8. package/dist/core/zod/rpc.d.ts +14 -1
  9. package/dist/core/zod/rpc.d.ts.map +1 -1
  10. package/dist/core/zod/rpc.js +14 -1
  11. package/dist/core/zod/rpc.js.map +1 -1
  12. package/dist/server/CliAuth.d.ts +110 -43
  13. package/dist/server/CliAuth.d.ts.map +1 -1
  14. package/dist/server/CliAuth.js +243 -155
  15. package/dist/server/CliAuth.js.map +1 -1
  16. package/dist/server/Handler.d.ts +0 -1
  17. package/dist/server/Handler.d.ts.map +1 -1
  18. package/dist/server/Handler.js +0 -1
  19. package/dist/server/Handler.js.map +1 -1
  20. package/dist/server/internal/handlers/relay.d.ts +29 -12
  21. package/dist/server/internal/handlers/relay.d.ts.map +1 -1
  22. package/dist/server/internal/handlers/relay.js +180 -125
  23. package/dist/server/internal/handlers/relay.js.map +1 -1
  24. package/dist/server/internal/handlers/sponsorship.d.ts +77 -0
  25. package/dist/server/internal/handlers/sponsorship.d.ts.map +1 -0
  26. package/dist/server/internal/handlers/sponsorship.js +96 -0
  27. package/dist/server/internal/handlers/sponsorship.js.map +1 -0
  28. package/dist/server/internal/handlers/utils.d.ts +3 -1
  29. package/dist/server/internal/handlers/utils.d.ts.map +1 -1
  30. package/dist/server/internal/handlers/utils.js +15 -12
  31. package/dist/server/internal/handlers/utils.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/core/ExecutionError.test.ts +205 -0
  34. package/src/core/ExecutionError.ts +189 -0
  35. package/src/core/Provider.test.ts +4 -2
  36. package/src/core/zod/rpc.ts +18 -1
  37. package/src/server/CliAuth.test-d.ts +6 -0
  38. package/src/server/CliAuth.test.ts +83 -0
  39. package/src/server/CliAuth.ts +331 -208
  40. package/src/server/Handler.ts +0 -1
  41. package/src/server/internal/handlers/relay.test.ts +318 -108
  42. package/src/server/internal/handlers/relay.ts +243 -138
  43. package/src/server/internal/handlers/sponsorship.ts +172 -0
  44. package/src/server/internal/handlers/utils.ts +15 -10
  45. package/dist/server/internal/handlers/feePayer.d.ts +0 -73
  46. package/dist/server/internal/handlers/feePayer.d.ts.map +0 -1
  47. package/dist/server/internal/handlers/feePayer.js +0 -184
  48. package/dist/server/internal/handlers/feePayer.js.map +0 -1
  49. package/src/server/internal/handlers/feePayer.test.ts +0 -336
  50. package/src/server/internal/handlers/feePayer.ts +0 -271
@@ -0,0 +1,172 @@
1
+ import { RpcResponse, Signature } from 'ox'
2
+ import { TxEnvelopeTempo } from 'ox/tempo'
3
+ import type { Address, Client } from 'viem'
4
+ import type { LocalAccount } from 'viem/accounts'
5
+ import { signTransaction } from 'viem/actions'
6
+ import { Transaction } from 'viem/tempo'
7
+
8
+ import * as Utils from './utils.js'
9
+
10
+ /** Returns sponsor metadata for `eth_fillTransaction` responses. */
11
+ export function getSponsor(options: getSponsor.Options): getSponsor.ReturnType {
12
+ const { account, name, url } = options
13
+ return {
14
+ address: account.address,
15
+ ...(name ? { name } : {}),
16
+ ...(url ? { url } : {}),
17
+ }
18
+ }
19
+
20
+ export declare namespace getSponsor {
21
+ type Options = {
22
+ /** Account used for sponsorship. */
23
+ account: LocalAccount
24
+ /** Optional display name. */
25
+ name?: string | undefined
26
+ /** Optional display URL. */
27
+ url?: string | undefined
28
+ }
29
+
30
+ type ReturnType = {
31
+ /** Sponsor address. */
32
+ address: Address
33
+ /** Sponsor display name. */
34
+ name?: string | undefined
35
+ /** Sponsor display URL. */
36
+ url?: string | undefined
37
+ }
38
+ }
39
+
40
+ /** Returns whether the fee payer approves a filled transaction. */
41
+ export async function shouldSponsor(options: shouldSponsor.Options) {
42
+ const { sender, transaction, validate } = options
43
+ if (!validate) return true
44
+ return await validate({
45
+ ...transaction,
46
+ from: sender,
47
+ } as Transaction.TransactionRequest)
48
+ }
49
+
50
+ export declare namespace shouldSponsor {
51
+ type Options = {
52
+ /** Sender address from the original request. */
53
+ sender?: Address | undefined
54
+ /** Filled transaction to validate. */
55
+ transaction: Record<string, unknown>
56
+ /** Optional sponsorship approval callback. */
57
+ validate?: ((request: Transaction.TransactionRequest) => boolean | Promise<boolean>) | undefined
58
+ }
59
+ }
60
+
61
+ /** Returns whether a raw Tempo transaction is explicitly requesting sponsorship. */
62
+ export function requestsRawSponsorship(serialized: `0x${string}`) {
63
+ if (!serialized.startsWith('0x76') && !serialized.startsWith('0x78')) return false
64
+ const transaction = Transaction.deserialize(serialized as `0x76${string}`)
65
+ return 'feePayerSignature' in transaction && transaction.feePayerSignature === null
66
+ }
67
+
68
+ /** Returns `true` when a fill request already has the fields needed for sponsorship signing. */
69
+ export function isPreparedTransaction(value: Record<string, unknown>) {
70
+ return (
71
+ typeof value.from === 'string' &&
72
+ typeof Utils.resolveChainId(value.chainId) === 'number' &&
73
+ typeof value.gas !== 'undefined' &&
74
+ typeof value.nonce !== 'undefined' &&
75
+ (typeof value.maxFeePerGas !== 'undefined' || typeof value.gasPrice !== 'undefined')
76
+ )
77
+ }
78
+
79
+ /** Signs a filled transaction as the fee payer. */
80
+ export async function sign(options: sign.Options) {
81
+ const { account, transaction, sender } = options
82
+ const from = (transaction.from as Address | undefined) ?? sender
83
+ const { signature: _, ...withoutSenderSig } = transaction
84
+ const prepared = { ...withoutSenderSig, from }
85
+
86
+ if (!prepared.from)
87
+ throw new RpcResponse.InvalidParamsError({
88
+ message: 'Transaction sender must be provided before fee payer signing.',
89
+ })
90
+ if (!account.sign) throw new Error('Fee payer account cannot sign transactions.')
91
+
92
+ const feePayerSignature = Signature.from(
93
+ await account.sign({
94
+ hash: TxEnvelopeTempo.getFeePayerSignPayload(TxEnvelopeTempo.from(prepared as never), {
95
+ sender: prepared.from,
96
+ }),
97
+ }),
98
+ )
99
+
100
+ return { ...prepared, feePayerSignature }
101
+ }
102
+
103
+ export declare namespace sign {
104
+ type Options = {
105
+ /** Account used as the fee payer. */
106
+ account: LocalAccount
107
+ /** Filled transaction to sign. */
108
+ transaction: Record<string, unknown>
109
+ /** Sender address from the original request. */
110
+ sender?: Address | undefined
111
+ }
112
+ }
113
+
114
+ /** Handles `eth_signRawTransaction` and broadcast methods for sponsored Tempo transactions. */
115
+ export async function handleRawTransaction(options: handleRawTransaction.Options) {
116
+ const { account, getClient, method, request, validate } = options
117
+ const serialized = request.params?.[0] as `0x76${string}` | undefined
118
+
119
+ if (!serialized?.startsWith('0x76') && !serialized?.startsWith('0x78'))
120
+ throw new RpcResponse.InvalidParamsError({
121
+ message: 'Only Tempo (0x76/0x78) transactions are supported.',
122
+ })
123
+
124
+ const transaction = Transaction.deserialize(serialized)
125
+
126
+ if (!transaction.signature || !transaction.from)
127
+ throw new RpcResponse.InvalidParamsError({
128
+ message: 'Transaction must be signed by the sender before fee payer signing.',
129
+ })
130
+
131
+ if (validate && !(await validate(transaction as Transaction.TransactionRequest)))
132
+ throw new RpcResponse.InvalidParamsError({
133
+ message: 'Sponsorship rejected.',
134
+ })
135
+
136
+ const client = getClient(transaction.chainId)
137
+ const serializedTransaction = toSerializedTransaction(
138
+ await signTransaction(client, {
139
+ ...transaction,
140
+ account,
141
+ feePayer: account,
142
+ } as never),
143
+ )
144
+
145
+ if (method === 'eth_signRawTransaction') return serializedTransaction
146
+ return await client.request({
147
+ method: method as never,
148
+ params: [serializedTransaction],
149
+ })
150
+ }
151
+
152
+ export declare namespace handleRawTransaction {
153
+ type Options = {
154
+ /** Account used as the fee payer. */
155
+ account: LocalAccount
156
+ /** Client resolver keyed by transaction `chainId`. */
157
+ getClient: (chainId?: number | undefined) => Client
158
+ /** Raw transaction method to handle. */
159
+ method: 'eth_signRawTransaction' | 'eth_sendRawTransaction' | 'eth_sendRawTransactionSync'
160
+ /** Incoming JSON-RPC request. */
161
+ request: { params?: readonly unknown[] | undefined }
162
+ /** Optional sponsorship approval callback. */
163
+ validate?: ((request: Transaction.TransactionRequest) => boolean | Promise<boolean>) | undefined
164
+ }
165
+ }
166
+
167
+ function toSerializedTransaction(value: unknown) {
168
+ if (typeof value === 'string') return value
169
+ if (value && typeof value === 'object' && 'raw' in value && typeof value.raw === 'string')
170
+ return value.raw
171
+ throw new Error('Expected a serialized transaction result.')
172
+ }
@@ -16,17 +16,22 @@ export function formatFillTransactionRequest(client: Client, value: Record<strin
16
16
  return format({ ...value } as never, 'fillTransaction') as Record<string, unknown>
17
17
  }
18
18
 
19
- export function normalizeFillTransactionRequest(value: Record<string, unknown>) {
20
- if (typeof value.to !== 'undefined' || typeof value.data !== 'undefined') return value
21
- if (!Array.isArray(value.calls) || value.calls.length !== 1) return value
22
- const [call] = value.calls as Array<Record<string, unknown>>
23
- const { calls: _, ...rest } = value
24
- return {
25
- ...rest,
26
- ...(typeof call?.data !== 'undefined' ? { data: call.data } : {}),
27
- ...(typeof call?.to !== 'undefined' ? { to: call.to } : {}),
28
- ...(typeof call?.value !== 'undefined' ? { value: normalizeFillValue(call.value) } : {}),
19
+ export function normalizeFillTransactionRequest(tx: Record<string, unknown>) {
20
+ const { to, data, value, ...rest } = tx
21
+ if (Array.isArray(tx.calls) && tx.calls.length > 0)
22
+ return {
23
+ ...tx,
24
+ calls: tx.calls.map((call) => ({
25
+ ...call,
26
+ value: normalizeFillValue(call.value),
27
+ })),
28
+ }
29
+ const call = {
30
+ ...(typeof to !== 'undefined' ? { to } : {}),
31
+ ...(typeof data !== 'undefined' ? { data } : {}),
32
+ ...(typeof value !== 'undefined' ? { value: normalizeFillValue(value) } : {}),
29
33
  }
34
+ return { ...rest, calls: [call] }
30
35
  }
31
36
 
32
37
  function normalizeFillValue(value: unknown) {
@@ -1,73 +0,0 @@
1
- import { RpcRequest } from 'ox';
2
- import type { Chain, Transport } from 'viem';
3
- import type { LocalAccount } from 'viem/accounts';
4
- import { Transaction } from 'viem/tempo';
5
- import { type Handler, from } from '../../Handler.js';
6
- /**
7
- * Instantiates a fee payer service request handler that can be used to
8
- * sponsor the fee for user transactions.
9
- *
10
- * @example
11
- * ```ts
12
- * import { privateKeyToAccount } from 'viem/accounts'
13
- * import { Handler } from 'accounts/server'
14
- *
15
- * const handler = Handler.feePayer({
16
- * account: privateKeyToAccount('0x...'),
17
- * })
18
- *
19
- * // Plug handler into your server framework of choice:
20
- * createServer(handler.listener) // Node.js
21
- * Bun.serve(handler) // Bun
22
- * Deno.serve(handler) // Deno
23
- * app.use(handler.listener) // Express
24
- * app.all('*', c => handler.fetch(c.req.raw)) // Hono
25
- * export const GET = handler.fetch // Next.js
26
- * export const POST = handler.fetch // Next.js
27
- * ```
28
- *
29
- * @param options - Options.
30
- * @returns Request handler.
31
- */
32
- export declare function feePayer(options: feePayer.Options): Handler;
33
- export declare namespace feePayer {
34
- type Options = from.Options & {
35
- /** Account to use as the fee payer. */
36
- account: LocalAccount;
37
- /**
38
- * Supported chains. The handler resolves the client based on the
39
- * `chainId` in the incoming transaction.
40
- * @default [tempo, tempoModerato]
41
- */
42
- chains?: readonly [Chain, ...Chain[]] | undefined;
43
- /** Function to call before handling the request. */
44
- onRequest?: (request: RpcRequest.RpcRequest) => Promise<void>;
45
- /** Path to use for the handler. */
46
- path?: string | undefined;
47
- /**
48
- * Validates whether to sponsor the transaction. When omitted, all
49
- * transactions are sponsored. Return `false` to reject sponsorship.
50
- */
51
- validate?: ((request: Transaction.TransactionRequest) => boolean | Promise<boolean>) | undefined;
52
- /** Sponsor display name returned from `eth_fillTransaction`. */
53
- name?: string | undefined;
54
- /** Transports keyed by chain ID. Defaults to `http()` for each chain. */
55
- transports?: Record<number, Transport> | undefined;
56
- /** Sponsor URL returned from `eth_fillTransaction`. */
57
- url?: string | undefined;
58
- };
59
- }
60
- /** Signs a filled transaction as the fee payer. */
61
- export declare function sign(options: {
62
- account: LocalAccount;
63
- transaction: Record<string, unknown>;
64
- sender?: `0x${string}` | undefined;
65
- }): Promise<{
66
- feePayerSignature: {
67
- r: bigint;
68
- s: bigint;
69
- yParity: number;
70
- };
71
- from: `0x${string}` | undefined;
72
- }>;
73
- //# sourceMappingURL=feePayer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feePayer.d.ts","sourceRoot":"","sources":["../../../../src/server/internal/handlers/feePayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,IAAI,CAAA;AAEvD,OAAO,KAAK,EAAW,KAAK,EAAU,SAAS,EAAE,MAAM,MAAM,CAAA;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,CA+J3D;AAED,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG;QAC5B,uCAAuC;QACvC,OAAO,EAAE,YAAY,CAAA;QACrB;;;;WAIG;QACH,MAAM,CAAC,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,GAAG,SAAS,CAAA;QACjD,oDAAoD;QACpD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QAC7D,mCAAmC;QACnC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACzB;;;WAGG;QACH,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,kBAAkB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAA;QAChG,gEAAgE;QAChE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACzB,yEAAyE;QACzE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,CAAA;QAClD,uDAAuD;QACvD,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACzB,CAAA;CACF;AAED,mDAAmD;AACnD,wBAAsB,IAAI,CAAC,OAAO,EAAE;IAClC,OAAO,EAAE,YAAY,CAAA;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAA;CACnC;;;;;;;GAqBA"}
@@ -1,184 +0,0 @@
1
- import { RpcRequest, RpcResponse, Signature } from 'ox';
2
- import { Transaction as core_Transaction, TxEnvelopeTempo } from 'ox/tempo';
3
- import { createClient, http } from 'viem';
4
- import { signTransaction } from 'viem/actions';
5
- import { tempo, tempoModerato } from 'viem/chains';
6
- import { Transaction } from 'viem/tempo';
7
- import { from } from '../../Handler.js';
8
- import * as Utils from './utils.js';
9
- /**
10
- * Instantiates a fee payer service request handler that can be used to
11
- * sponsor the fee for user transactions.
12
- *
13
- * @example
14
- * ```ts
15
- * import { privateKeyToAccount } from 'viem/accounts'
16
- * import { Handler } from 'accounts/server'
17
- *
18
- * const handler = Handler.feePayer({
19
- * account: privateKeyToAccount('0x...'),
20
- * })
21
- *
22
- * // Plug handler into your server framework of choice:
23
- * createServer(handler.listener) // Node.js
24
- * Bun.serve(handler) // Bun
25
- * Deno.serve(handler) // Deno
26
- * app.use(handler.listener) // Express
27
- * app.all('*', c => handler.fetch(c.req.raw)) // Hono
28
- * export const GET = handler.fetch // Next.js
29
- * export const POST = handler.fetch // Next.js
30
- * ```
31
- *
32
- * @param options - Options.
33
- * @returns Request handler.
34
- */
35
- export function feePayer(options) {
36
- const { account, chains = [tempo, tempoModerato], name, onRequest, path = '/', validate, transports = {}, url, ...rest } = options;
37
- const clients = new Map();
38
- for (const chain of chains) {
39
- const transport = transports[chain.id] ?? http();
40
- clients.set(chain.id, createClient({ chain, transport }));
41
- }
42
- function getClient(chainId) {
43
- if (chainId) {
44
- const client = clients.get(chainId);
45
- if (!client)
46
- throw new Error(`Chain ${chainId} not configured`);
47
- return client;
48
- }
49
- return clients.get(chains[0].id);
50
- }
51
- const sponsor = {
52
- address: account.address,
53
- ...(name ? { name } : {}),
54
- ...(url ? { url } : {}),
55
- };
56
- const router = from(rest);
57
- router.post(path, async (c) => {
58
- const request = RpcRequest.from((await c.req.raw.json()));
59
- try {
60
- await onRequest?.(request);
61
- const method = request.method;
62
- if (method !== 'eth_fillTransaction' &&
63
- method !== 'eth_signRawTransaction' &&
64
- method !== 'eth_sendRawTransaction' &&
65
- method !== 'eth_sendRawTransactionSync')
66
- return Response.json(RpcResponse.from({
67
- error: new RpcResponse.MethodNotSupportedError({
68
- message: `Method not supported: ${request.method}`,
69
- }),
70
- }, { request }));
71
- if (method === 'eth_fillTransaction') {
72
- const [parameters] = Utils.parseParams.parse(request.params);
73
- const chainId = Utils.resolveChainId(parameters.chainId);
74
- const client = getClient(chainId);
75
- const normalized = Utils.normalizeFillTransactionRequest(parameters);
76
- const sender = typeof parameters.from === 'string' ? parameters.from : undefined;
77
- let transaction = await (async () => {
78
- if (isPreparedFeePayerTransaction(parameters))
79
- return Utils.normalizeTempoTransaction(parameters);
80
- const fillRequest = Utils.formatFillTransactionRequest(client, {
81
- ...normalized,
82
- ...(typeof chainId !== 'undefined' ? { chainId } : {}),
83
- feePayer: true,
84
- });
85
- const result = (await client.request({
86
- method: 'eth_fillTransaction',
87
- params: [fillRequest],
88
- }));
89
- return Utils.normalizeTempoTransaction(result.tx);
90
- })();
91
- if (validate &&
92
- // @ts-expect-error - TODO: Convert to `TransactionRequest` properly.
93
- !(await validate({
94
- ...transaction,
95
- from: sender,
96
- }))) {
97
- // Re-fill without feePayer so gas/nonce are correct for self-payment.
98
- const fillRequest = Utils.formatFillTransactionRequest(client, {
99
- ...normalized,
100
- ...(typeof chainId !== 'undefined' ? { chainId } : {}),
101
- });
102
- const result = (await client.request({
103
- method: 'eth_fillTransaction',
104
- params: [fillRequest],
105
- }));
106
- transaction = Utils.normalizeTempoTransaction(result.tx);
107
- return Utils.rpcResult(request, {
108
- tx: core_Transaction.toRpc(transaction),
109
- });
110
- }
111
- const signed = await sign({ account, transaction, sender });
112
- return Utils.rpcResult(request, {
113
- sponsor,
114
- tx: core_Transaction.toRpc(signed),
115
- });
116
- }
117
- const serialized = request.params?.[0];
118
- if (!serialized?.startsWith('0x76') && !serialized?.startsWith('0x78'))
119
- throw new RpcResponse.InvalidParamsError({
120
- message: 'Only Tempo (0x76/0x78) transactions are supported.',
121
- });
122
- const transaction = Transaction.deserialize(serialized);
123
- if (!transaction.signature || !transaction.from)
124
- throw new RpcResponse.InvalidParamsError({
125
- message: 'Transaction must be signed by the sender before fee payer signing.',
126
- });
127
- if (validate && !(await validate(transaction)))
128
- throw new RpcResponse.InvalidParamsError({
129
- message: 'Sponsorship rejected.',
130
- });
131
- const client = getClient(transaction.chainId);
132
- const serializedTransaction = toSerializedTransaction(await signTransaction(client, {
133
- ...transaction,
134
- account,
135
- feePayer: account,
136
- }));
137
- if (method === 'eth_signRawTransaction')
138
- return Response.json(RpcResponse.from({ result: serializedTransaction }, { request }));
139
- const result = await client.request({
140
- method: method,
141
- params: [serializedTransaction],
142
- });
143
- return Response.json(RpcResponse.from({ result }, { request }));
144
- }
145
- catch (error) {
146
- return Utils.rpcError(request, error);
147
- }
148
- });
149
- return router;
150
- }
151
- /** Signs a filled transaction as the fee payer. */
152
- export async function sign(options) {
153
- const { account, transaction, sender } = options;
154
- const from = transaction.from ?? sender;
155
- const { signature: _, ...withoutSenderSig } = transaction;
156
- const prepared = { ...withoutSenderSig, from };
157
- if (!prepared.from)
158
- throw new RpcResponse.InvalidParamsError({
159
- message: 'Transaction sender must be provided before fee payer signing.',
160
- });
161
- if (!account.sign)
162
- throw new Error('Fee payer account cannot sign transactions.');
163
- const feePayerSignature = Signature.from(await account.sign({
164
- hash: TxEnvelopeTempo.getFeePayerSignPayload(TxEnvelopeTempo.from(prepared), {
165
- sender: prepared.from,
166
- }),
167
- }));
168
- return { ...prepared, feePayerSignature };
169
- }
170
- function isPreparedFeePayerTransaction(value) {
171
- return (typeof value.from === 'string' &&
172
- typeof Utils.resolveChainId(value.chainId) === 'number' &&
173
- typeof value.gas !== 'undefined' &&
174
- typeof value.nonce !== 'undefined' &&
175
- (typeof value.maxFeePerGas !== 'undefined' || typeof value.gasPrice !== 'undefined'));
176
- }
177
- function toSerializedTransaction(value) {
178
- if (typeof value === 'string')
179
- return value;
180
- if (value && typeof value === 'object' && 'raw' in value && typeof value.raw === 'string')
181
- return value.raw;
182
- throw new Error('Expected a serialized transaction result.');
183
- }
184
- //# sourceMappingURL=feePayer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feePayer.js","sourceRoot":"","sources":["../../../../src/server/internal/handlers/feePayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AACvD,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE3E,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAgB,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,QAAQ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