ox 0.14.30 → 0.14.32

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 (67) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/_cjs/core/AbiParameters.js +2 -1
  3. package/_cjs/core/AbiParameters.js.map +1 -1
  4. package/_cjs/core/internal/abiParameters.js +10 -2
  5. package/_cjs/core/internal/abiParameters.js.map +1 -1
  6. package/_cjs/tempo/EarnShares.js +66 -0
  7. package/_cjs/tempo/EarnShares.js.map +1 -0
  8. package/_cjs/tempo/KeyAuthorization.js +39 -10
  9. package/_cjs/tempo/KeyAuthorization.js.map +1 -1
  10. package/_cjs/tempo/MultisigConfig.js +12 -2
  11. package/_cjs/tempo/MultisigConfig.js.map +1 -1
  12. package/_cjs/tempo/SignatureEnvelope.js +167 -46
  13. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  14. package/_cjs/tempo/index.js +2 -1
  15. package/_cjs/tempo/index.js.map +1 -1
  16. package/_cjs/version.js +1 -1
  17. package/_esm/core/AbiParameters.js +4 -1
  18. package/_esm/core/AbiParameters.js.map +1 -1
  19. package/_esm/core/internal/abiParameters.js +17 -2
  20. package/_esm/core/internal/abiParameters.js.map +1 -1
  21. package/_esm/tempo/EarnShares.js +167 -0
  22. package/_esm/tempo/EarnShares.js.map +1 -0
  23. package/_esm/tempo/KeyAuthorization.js +41 -9
  24. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  25. package/_esm/tempo/MultisigConfig.js +16 -4
  26. package/_esm/tempo/MultisigConfig.js.map +1 -1
  27. package/_esm/tempo/SignatureEnvelope.js +172 -55
  28. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  29. package/_esm/tempo/index.js +22 -0
  30. package/_esm/tempo/index.js.map +1 -1
  31. package/_esm/version.js +1 -1
  32. package/_types/core/AbiParameters.d.ts.map +1 -1
  33. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  34. package/_types/core/internal/rpcSchemas/eth.d.ts +16 -0
  35. package/_types/core/internal/rpcSchemas/eth.d.ts.map +1 -1
  36. package/_types/tempo/EarnShares.d.ts +176 -0
  37. package/_types/tempo/EarnShares.d.ts.map +1 -0
  38. package/_types/tempo/KeyAuthorization.d.ts +22 -16
  39. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  40. package/_types/tempo/MultisigConfig.d.ts +8 -4
  41. package/_types/tempo/MultisigConfig.d.ts.map +1 -1
  42. package/_types/tempo/SignatureEnvelope.d.ts +33 -13
  43. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  44. package/_types/tempo/index.d.ts +22 -0
  45. package/_types/tempo/index.d.ts.map +1 -1
  46. package/_types/version.d.ts +1 -1
  47. package/core/AbiParameters.ts +3 -1
  48. package/core/internal/abiParameters.ts +17 -2
  49. package/core/internal/rpcSchemas/eth.ts +16 -0
  50. package/package.json +16 -1
  51. package/tempo/EarnShares/package.json +6 -0
  52. package/tempo/EarnShares.test.ts +122 -0
  53. package/tempo/EarnShares.ts +232 -0
  54. package/tempo/KeyAuthorization.test-d/package.json +6 -0
  55. package/tempo/KeyAuthorization.test-d.ts +62 -0
  56. package/tempo/KeyAuthorization.test.ts +132 -0
  57. package/tempo/KeyAuthorization.ts +76 -29
  58. package/tempo/MultisigConfig.test.ts +34 -2
  59. package/tempo/MultisigConfig.ts +18 -4
  60. package/tempo/SignatureEnvelope.test-d/package.json +6 -0
  61. package/tempo/SignatureEnvelope.test-d.ts +97 -0
  62. package/tempo/SignatureEnvelope.test.ts +227 -36
  63. package/tempo/SignatureEnvelope.ts +276 -85
  64. package/tempo/e2e.test.ts +0 -416
  65. package/tempo/index.ts +22 -0
  66. package/tempo/multisig.e2e.test.ts +582 -0
  67. package/version.ts +1 -1
@@ -140,7 +140,8 @@ export function decodeArray(
140
140
 
141
141
  // If the length of the array is not known in advance (dynamic array),
142
142
  // this means we will need to wonder off to the pointer and decode.
143
- if (!length) {
143
+ // Note: zero-length fixed arrays (`T[0]`) are not dynamic.
144
+ if (length === null) {
144
145
  // Dealing with a dynamic type, so get the offset of the array data.
145
146
  const offset = Bytes.toNumber(cursor.readBytes(sizeOfOffset))
146
147
 
@@ -167,6 +168,12 @@ export function decodeArray(
167
168
  })
168
169
  consumed += consumed_
169
170
  value.push(data)
171
+ // Charge zero-width elements against the read limit to bound work
172
+ // on huge lengths of zero-width types (e.g. `uint256[0][]`).
173
+ if (consumed_ === 0) {
174
+ cursor.assertReadLimit()
175
+ cursor._touch()
176
+ }
170
177
  }
171
178
 
172
179
  // As we have gone wondering, restore to the original position + next slot.
@@ -211,6 +218,12 @@ export function decodeArray(
211
218
  })
212
219
  consumed += consumed_
213
220
  value.push(data)
221
+ // Charge zero-width elements against the read limit to bound work
222
+ // on huge lengths of zero-width types (e.g. `uint256[0][4294967295]`).
223
+ if (consumed_ === 0) {
224
+ cursor.assertReadLimit()
225
+ cursor._touch()
226
+ }
214
227
  }
215
228
  return [value, consumed]
216
229
  }
@@ -583,7 +596,9 @@ export function encodeArray<const parameter extends AbiParameters.Parameter>(
583
596
  type: `${parameter.type}[${length}]`,
584
597
  })
585
598
 
586
- let dynamicChild = false
599
+ // Zero-length fixed arrays of dynamic types (e.g. `string[0]`) are dynamic
600
+ // per the ABI spec, even though they have no elements to inspect.
601
+ let dynamicChild = value.length === 0 && hasDynamicChild(parameter)
587
602
  const preparedParameters: PreparedParameter[] = []
588
603
  for (let i = 0; i < value.length; i++) {
589
604
  const preparedParam = prepareParameter({
@@ -436,6 +436,22 @@ export type Eth = RpcSchema.From<
436
436
  }
437
437
  ReturnType: AccountProof.Rpc
438
438
  }
439
+ /**
440
+ * Returns the raw, serialized transaction specified by hash
441
+ *
442
+ * @example
443
+ * ```
444
+ * request({ method: 'eth_getRawTransactionByHash', params: ['0x...'] })
445
+ * // '0x...'
446
+ * ```
447
+ */
448
+ | {
449
+ Request: {
450
+ method: 'eth_getRawTransactionByHash'
451
+ params: [hash: Hex.Hex]
452
+ }
453
+ ReturnType: Hex.Hex | null
454
+ }
439
455
  /**
440
456
  * Returns the value from a storage position at an address
441
457
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.14.30",
4
+ "version": "0.14.32",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -508,6 +508,16 @@
508
508
  "import": "./_esm/tempo/Channel.js",
509
509
  "default": "./_cjs/tempo/Channel.js"
510
510
  },
511
+ "./tempo/EarnShares": {
512
+ "types": "./_types/tempo/EarnShares.d.ts",
513
+ "import": "./_esm/tempo/EarnShares.js",
514
+ "default": "./_cjs/tempo/EarnShares.js"
515
+ },
516
+ "./tempo/KeyAuthorization.test-d": {
517
+ "types": "./_types/tempo/KeyAuthorization.test-d.d.ts",
518
+ "import": "./_esm/tempo/KeyAuthorization.test-d.js",
519
+ "default": "./_cjs/tempo/KeyAuthorization.test-d.js"
520
+ },
511
521
  "./tempo/KeyAuthorization": {
512
522
  "types": "./_types/tempo/KeyAuthorization.d.ts",
513
523
  "import": "./_esm/tempo/KeyAuthorization.js",
@@ -538,6 +548,11 @@
538
548
  "import": "./_esm/tempo/RpcSchemaTempo.js",
539
549
  "default": "./_cjs/tempo/RpcSchemaTempo.js"
540
550
  },
551
+ "./tempo/SignatureEnvelope.test-d": {
552
+ "types": "./_types/tempo/SignatureEnvelope.test-d.d.ts",
553
+ "import": "./_esm/tempo/SignatureEnvelope.test-d.js",
554
+ "default": "./_cjs/tempo/SignatureEnvelope.test-d.js"
555
+ },
541
556
  "./tempo/SignatureEnvelope": {
542
557
  "types": "./_types/tempo/SignatureEnvelope.d.ts",
543
558
  "import": "./_esm/tempo/SignatureEnvelope.js",
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/EarnShares.d.ts",
4
+ "main": "../../_cjs/tempo/EarnShares.js",
5
+ "module": "../../_esm/tempo/EarnShares.js"
6
+ }
@@ -0,0 +1,122 @@
1
+ import { EarnShares } from 'ox/tempo'
2
+ import { describe, expect, test } from 'vitest'
3
+
4
+ const anchor = { engineShares: 3n, shareSupply: 2n } as const
5
+
6
+ describe('toAmount', () => {
7
+ test('default', () => {
8
+ expect(EarnShares.toAmount(anchor, 7n)).toBe(4n)
9
+ })
10
+
11
+ test('behavior: rounds down', () => {
12
+ expect(EarnShares.toAmount({ engineShares: 3n, shareSupply: 1n }, 2n)).toBe(
13
+ 0n,
14
+ )
15
+ })
16
+ })
17
+
18
+ describe('toAmountUp', () => {
19
+ test('default', () => {
20
+ expect(EarnShares.toAmountUp(anchor, 7n)).toBe(5n)
21
+ })
22
+
23
+ test('behavior: exact conversions do not round up', () => {
24
+ expect(EarnShares.toAmountUp(anchor, 3n)).toBe(2n)
25
+ })
26
+ })
27
+
28
+ describe('toVenueAmount', () => {
29
+ test('default', () => {
30
+ expect(EarnShares.toVenueAmount(anchor, 7n)).toBe(10n)
31
+ })
32
+
33
+ test('behavior: identity at the initial 1:1 anchor', () => {
34
+ expect(
35
+ EarnShares.toVenueAmount({ engineShares: 1n, shareSupply: 1n }, 12_345n),
36
+ ).toBe(12_345n)
37
+ })
38
+ })
39
+
40
+ describe('feeShares', () => {
41
+ test('default', () => {
42
+ expect(
43
+ EarnShares.feeShares({
44
+ activeAssets: 1_100n,
45
+ shareSupply: 1_000n,
46
+ totalFeeAssets: 100n,
47
+ }),
48
+ ).toBe(100n)
49
+ })
50
+
51
+ test('behavior: zero fee mints nothing', () => {
52
+ expect(
53
+ EarnShares.feeShares({
54
+ activeAssets: 1_100n,
55
+ shareSupply: 1_000n,
56
+ totalFeeAssets: 0n,
57
+ }),
58
+ ).toBe(0n)
59
+ })
60
+
61
+ test('behavior: fee at or above active assets mints nothing', () => {
62
+ expect(
63
+ EarnShares.feeShares({
64
+ activeAssets: 100n,
65
+ shareSupply: 1_000n,
66
+ totalFeeAssets: 100n,
67
+ }),
68
+ ).toBe(0n)
69
+ })
70
+
71
+ test('behavior: rounds down', () => {
72
+ expect(
73
+ EarnShares.feeShares({
74
+ activeAssets: 1_000n,
75
+ shareSupply: 999n,
76
+ totalFeeAssets: 100n,
77
+ }),
78
+ ).toBe(111n)
79
+ })
80
+ })
81
+
82
+ describe('minimumOutput', () => {
83
+ test('default', () => {
84
+ expect(EarnShares.minimumOutput(1_000_000n, 50)).toBe(995_000n)
85
+ })
86
+
87
+ test('behavior: zero slippage returns the expected output', () => {
88
+ expect(EarnShares.minimumOutput(1_000_000n, 0)).toBe(1_000_000n)
89
+ })
90
+
91
+ test('behavior: floors to 1n', () => {
92
+ expect(EarnShares.minimumOutput(1n, 9_999)).toBe(1n)
93
+ })
94
+
95
+ test('error: non-positive expected output', () => {
96
+ expect(() =>
97
+ EarnShares.minimumOutput(0n, 50),
98
+ ).toThrowErrorMatchingInlineSnapshot(
99
+ `[EarnShares.InvalidExpectedOutputError: Expected output \`0\` must be greater than zero.]`,
100
+ )
101
+ })
102
+
103
+ test('error: out-of-range slippage', () => {
104
+ expect(() =>
105
+ EarnShares.minimumOutput(1_000_000n, 10_000),
106
+ ).toThrowErrorMatchingInlineSnapshot(`
107
+ [EarnShares.InvalidSlippageError: Slippage tolerance \`10000\` is invalid.
108
+
109
+ Slippage must be a whole number from 0 through 9999 basis points.]
110
+ `)
111
+ })
112
+
113
+ test('error: non-integer slippage', () => {
114
+ expect(() =>
115
+ EarnShares.minimumOutput(1_000_000n, 0.5),
116
+ ).toThrowErrorMatchingInlineSnapshot(`
117
+ [EarnShares.InvalidSlippageError: Slippage tolerance \`0.5\` is invalid.
118
+
119
+ Slippage must be a whole number from 0 through 9999 basis points.]
120
+ `)
121
+ })
122
+ })
@@ -0,0 +1,232 @@
1
+ import * as Errors from '../core/Errors.js'
2
+
3
+ /** Basis-point denominator used by slippage bounds. */
4
+ export const basisPointScale = 10_000
5
+
6
+ /**
7
+ * Tempo Earn `VaultAdapter` conversion anchor.
8
+ *
9
+ * The adapter prices vault shares against venue shares through this pair:
10
+ * `engineShares` venue shares are worth `shareSupply` vault shares. It is initialised
11
+ * 1:1 and restated on `contribute` and `migrateEngine`.
12
+ *
13
+ * These conversions are raw and fee-blind; they ignore pending fee dilution
14
+ * and are unsuitable for user-facing value (use the adapter's `previewRedeem`).
15
+ */
16
+ export type Anchor = {
17
+ /** Venue shares held by the engine at the anchor point. */
18
+ engineShares: bigint
19
+ /** Vault share supply at the anchor point. */
20
+ shareSupply: bigint
21
+ }
22
+
23
+ /**
24
+ * Converts venue shares to a vault share amount at the anchor rate, rounding down.
25
+ *
26
+ * Mirrors `VaultAdapter.sharesToTokens`.
27
+ *
28
+ * @example
29
+ * ```ts twoslash
30
+ * import { EarnShares } from 'ox/tempo'
31
+ *
32
+ * const shareAmount = EarnShares.toAmount(
33
+ * { engineShares: 3n, shareSupply: 2n },
34
+ * 7n,
35
+ * )
36
+ * // @log: 4n
37
+ * ```
38
+ *
39
+ * @param anchor - The conversion anchor.
40
+ * @param venueShareAmount - Venue share amount, base units.
41
+ * @returns Vault share amount, rounded down.
42
+ */
43
+ export function toAmount(anchor: Anchor, venueShareAmount: bigint): bigint {
44
+ return (venueShareAmount * anchor.shareSupply) / anchor.engineShares
45
+ }
46
+
47
+ export declare namespace toAmount {
48
+ type ErrorType = Errors.GlobalErrorType
49
+ }
50
+
51
+ /**
52
+ * Converts venue shares to a vault share amount at the anchor rate, rounding up.
53
+ *
54
+ * Mirrors the adapter's ceiling conversion used by exact-asset exits.
55
+ *
56
+ * @example
57
+ * ```ts twoslash
58
+ * import { EarnShares } from 'ox/tempo'
59
+ *
60
+ * const shareAmount = EarnShares.toAmountUp(
61
+ * { engineShares: 3n, shareSupply: 2n },
62
+ * 7n,
63
+ * )
64
+ * // @log: 5n
65
+ * ```
66
+ *
67
+ * @param anchor - The conversion anchor.
68
+ * @param venueShareAmount - Venue share amount, base units.
69
+ * @returns Vault share amount, rounded up.
70
+ */
71
+ export function toAmountUp(anchor: Anchor, venueShareAmount: bigint): bigint {
72
+ const { engineShares, shareSupply } = anchor
73
+ return (venueShareAmount * shareSupply + engineShares - 1n) / engineShares
74
+ }
75
+
76
+ export declare namespace toAmountUp {
77
+ type ErrorType = Errors.GlobalErrorType
78
+ }
79
+
80
+ /**
81
+ * Converts a vault share amount to venue shares at the anchor rate, rounding down.
82
+ *
83
+ * Mirrors `VaultAdapter.tokensToShares`.
84
+ *
85
+ * @example
86
+ * ```ts twoslash
87
+ * import { EarnShares } from 'ox/tempo'
88
+ *
89
+ * const venueShareAmount = EarnShares.toVenueAmount(
90
+ * { engineShares: 3n, shareSupply: 2n },
91
+ * 7n,
92
+ * )
93
+ * // @log: 10n
94
+ * ```
95
+ *
96
+ * @param anchor - The conversion anchor.
97
+ * @param shareAmount - Vault share amount, base units.
98
+ * @returns Venue share amount, rounded down.
99
+ */
100
+ export function toVenueAmount(anchor: Anchor, shareAmount: bigint): bigint {
101
+ return (shareAmount * anchor.engineShares) / anchor.shareSupply
102
+ }
103
+
104
+ export declare namespace toVenueAmount {
105
+ type ErrorType = Errors.GlobalErrorType
106
+ }
107
+
108
+ /**
109
+ * Computes the dilution-correct vault shares minted for an asset-denominated fee.
110
+ *
111
+ * Mirrors `FeeMath`:
112
+ * `feeShares = floor(fee * shareSupply / (activeAssets - fee))`, zero when the
113
+ * fee is zero or not smaller than the active assets. Minting this amount to the
114
+ * fee ledger prices the fee at post-mint value per share.
115
+ *
116
+ * @example
117
+ * ```ts twoslash
118
+ * import { EarnShares } from 'ox/tempo'
119
+ *
120
+ * const shares = EarnShares.feeShares({
121
+ * activeAssets: 1_100n,
122
+ * shareSupply: 1_000n,
123
+ * totalFeeAssets: 100n,
124
+ * })
125
+ * // @log: 100n
126
+ * ```
127
+ *
128
+ * @param options - Fee accrual inputs.
129
+ * @returns Vault shares to mint for the fee, rounded down.
130
+ */
131
+ export function feeShares(options: feeShares.Options): bigint {
132
+ const { activeAssets, shareSupply, totalFeeAssets } = options
133
+ if (totalFeeAssets === 0n || totalFeeAssets >= activeAssets) return 0n
134
+ return (totalFeeAssets * shareSupply) / (activeAssets - totalFeeAssets)
135
+ }
136
+
137
+ export declare namespace feeShares {
138
+ export type Options = {
139
+ /** Assets backing the active (non-queued) supply, base units. */
140
+ activeAssets: bigint
141
+ /** Active vault share supply, base units. */
142
+ shareSupply: bigint
143
+ /** Total fee liability in asset units. */
144
+ totalFeeAssets: bigint
145
+ }
146
+ export type ErrorType = Errors.GlobalErrorType
147
+ }
148
+
149
+ /**
150
+ * Lowers an expected output by a basis-point slippage tolerance, flooring to `1n`.
151
+ *
152
+ * Suitable for lower bounds such as a deposit's minimum shares or a redeem's
153
+ * minimum assets; not for upper bounds such as an exact withdrawal's maximum
154
+ * shares.
155
+ *
156
+ * @example
157
+ * ```ts twoslash
158
+ * import { EarnShares } from 'ox/tempo'
159
+ *
160
+ * const minimumShares = EarnShares.minimumOutput(1_000_000n, 50)
161
+ * // @log: 995_000n
162
+ * ```
163
+ *
164
+ * @param expectedAmount - Expected output in base units.
165
+ * @param slippageBps - Allowed slippage in basis points from `0` through `9_999`.
166
+ * @returns The minimum accepted output, floored to `1n`.
167
+ * @throws `InvalidExpectedOutputError` when `expectedAmount` is not positive.
168
+ * @throws `InvalidSlippageError` when `slippageBps` is outside its valid range.
169
+ */
170
+ export function minimumOutput(
171
+ expectedAmount: bigint,
172
+ slippageBps: number,
173
+ ): bigint {
174
+ if (expectedAmount <= 0n)
175
+ throw new InvalidExpectedOutputError({ expectedAmount })
176
+ if (
177
+ !Number.isInteger(slippageBps) ||
178
+ slippageBps < 0 ||
179
+ slippageBps >= basisPointScale
180
+ )
181
+ throw new InvalidSlippageError({ slippageBps })
182
+ const scale = BigInt(basisPointScale)
183
+ const bounded = (expectedAmount * (scale - BigInt(slippageBps))) / scale
184
+ return bounded === 0n ? 1n : bounded
185
+ }
186
+
187
+ export declare namespace minimumOutput {
188
+ type ErrorType =
189
+ | InvalidExpectedOutputError
190
+ | InvalidSlippageError
191
+ | Errors.GlobalErrorType
192
+ }
193
+
194
+ /**
195
+ * Error thrown when an expected output is not positive.
196
+ */
197
+ export class InvalidExpectedOutputError extends Errors.BaseError {
198
+ override readonly name = 'EarnShares.InvalidExpectedOutputError'
199
+
200
+ constructor(options: InvalidExpectedOutputError.Options) {
201
+ super(
202
+ `Expected output \`${options.expectedAmount}\` must be greater than zero.`,
203
+ )
204
+ }
205
+ }
206
+
207
+ export declare namespace InvalidExpectedOutputError {
208
+ export type Options = {
209
+ expectedAmount: bigint
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Error thrown when a slippage tolerance is not an integer from `0` through `9_999`.
215
+ */
216
+ export class InvalidSlippageError extends Errors.BaseError {
217
+ override readonly name = 'EarnShares.InvalidSlippageError'
218
+
219
+ constructor(options: InvalidSlippageError.Options) {
220
+ super(`Slippage tolerance \`${options.slippageBps}\` is invalid.`, {
221
+ metaMessages: [
222
+ `Slippage must be a whole number from 0 through ${basisPointScale - 1} basis points.`,
223
+ ],
224
+ })
225
+ }
226
+ }
227
+
228
+ export declare namespace InvalidSlippageError {
229
+ export type Options = {
230
+ slippageBps: number
231
+ }
232
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/KeyAuthorization.test-d.d.ts",
4
+ "main": "../../_cjs/tempo/KeyAuthorization.test-d.js",
5
+ "module": "../../_esm/tempo/KeyAuthorization.test-d.js"
6
+ }
@@ -0,0 +1,62 @@
1
+ import { expectTypeOf, test } from 'vitest'
2
+ import * as KeyAuthorization from './KeyAuthorization.js'
3
+ import type * as SignatureEnvelope from './SignatureEnvelope.js'
4
+
5
+ const authorization = {
6
+ address: '0x1111111111111111111111111111111111111111',
7
+ chainId: 1n,
8
+ type: 'secp256k1',
9
+ } as const satisfies KeyAuthorization.Input
10
+
11
+ const signature = {
12
+ signature: {
13
+ r: 1n,
14
+ s: 2n,
15
+ yParity: 0,
16
+ },
17
+ type: 'secp256k1',
18
+ } as const satisfies SignatureEnvelope.Secp256k1
19
+
20
+ const multisig = {
21
+ account: '0x2222222222222222222222222222222222222222',
22
+ signatures: [signature],
23
+ type: 'multisig',
24
+ } as const satisfies SignatureEnvelope.Multisig
25
+
26
+ test('accepts primitive signatures', () => {
27
+ const signed = KeyAuthorization.from(authorization, { signature })
28
+
29
+ expectTypeOf(signed.signature).toMatchTypeOf<
30
+ KeyAuthorization.Signed['signature']
31
+ >()
32
+ })
33
+
34
+ test('rejects multisig signatures', () => {
35
+ KeyAuthorization.from(authorization, {
36
+ // @ts-expect-error Key authorizations accept only primitive signatures.
37
+ signature: multisig,
38
+ })
39
+
40
+ const multisigRpc = {
41
+ account: multisig.account,
42
+ signatures: [
43
+ {
44
+ r: '0x01',
45
+ s: '0x02',
46
+ type: 'secp256k1',
47
+ yParity: '0x0',
48
+ },
49
+ ],
50
+ } as const satisfies SignatureEnvelope.MultisigRpc
51
+
52
+ const rpc: KeyAuthorization.Rpc = {
53
+ chainId: '0x1',
54
+ expiry: null,
55
+ keyId: authorization.address,
56
+ keyType: authorization.type,
57
+ // @ts-expect-error Key authorizations accept only primitive RPC signatures.
58
+ signature: multisigRpc,
59
+ }
60
+
61
+ expectTypeOf(rpc).toEqualTypeOf<KeyAuthorization.Rpc>()
62
+ })