ox 1.0.0-beta.0 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/core/Provider.d.ts +7 -7
  2. package/dist/core/Provider.d.ts.map +1 -1
  3. package/dist/core/RpcSchema.d.ts +50 -0
  4. package/dist/core/RpcSchema.d.ts.map +1 -1
  5. package/dist/core/RpcSchema.js.map +1 -1
  6. package/dist/core/RpcTransport.d.ts +2 -2
  7. package/dist/core/RpcTransport.d.ts.map +1 -1
  8. package/dist/core/RpcTransport.js.map +1 -1
  9. package/dist/core/internal/rpcTransport.d.ts +1 -1
  10. package/dist/core/internal/rpcTransport.d.ts.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/tempo/MultisigConfig.d.ts +79 -16
  16. package/dist/tempo/MultisigConfig.d.ts.map +1 -1
  17. package/dist/tempo/MultisigConfig.js +69 -11
  18. package/dist/tempo/MultisigConfig.js.map +1 -1
  19. package/dist/tempo/SignatureEnvelope.d.ts +83 -19
  20. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  21. package/dist/tempo/SignatureEnvelope.js +99 -30
  22. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  23. package/dist/tempo/index.d.ts +2 -2
  24. package/dist/tempo/index.js +2 -2
  25. package/dist/zod/RpcSchema.d.ts +144 -25
  26. package/dist/zod/RpcSchema.d.ts.map +1 -1
  27. package/dist/zod/RpcSchema.js +85 -13
  28. package/dist/zod/RpcSchema.js.map +1 -1
  29. package/dist/zod/internal/rpcSchemas/Eth.d.ts +12 -12
  30. package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
  31. package/dist/zod/internal/rpcSchemas/Eth.js +14 -12
  32. package/dist/zod/internal/rpcSchemas/Eth.js.map +1 -1
  33. package/dist/zod/tempo/AuthorizationTempo.d.ts +6 -6
  34. package/dist/zod/tempo/KeyAuthorization.d.ts +3 -3
  35. package/dist/zod/tempo/RpcSchemaTempo.d.ts +6 -6
  36. package/dist/zod/tempo/SignatureEnvelope.d.ts +3 -3
  37. package/dist/zod/tempo/SignatureEnvelope.js +1 -1
  38. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  39. package/dist/zod/tempo/Transaction.d.ts +6 -6
  40. package/dist/zod/tempo/TransactionRequest.d.ts +6 -6
  41. package/dist/zod/tempo/TxEnvelopeTempo.d.ts +9 -9
  42. package/dist/zod/tempo/ZoneRpcAuthentication.d.ts +3 -3
  43. package/package.json +1 -1
  44. package/src/CHANGELOG.md +6 -0
  45. package/src/core/Provider.ts +7 -7
  46. package/src/core/RpcSchema.ts +60 -0
  47. package/src/core/RpcTransport.ts +7 -4
  48. package/src/core/_test/Provider.test-d.ts +21 -0
  49. package/src/core/_test/RpcSchema.test-d.ts +87 -1
  50. package/src/core/_test/RpcTransport.test-d.ts +43 -0
  51. package/src/core/internal/rpcTransport.ts +1 -1
  52. package/src/index.ts +2 -0
  53. package/src/tempo/MultisigConfig.test.ts +21 -12
  54. package/src/tempo/MultisigConfig.ts +103 -18
  55. package/src/tempo/SignatureEnvelope.test.ts +124 -26
  56. package/src/tempo/SignatureEnvelope.ts +150 -48
  57. package/src/tempo/e2e.test.ts +42 -47
  58. package/src/tempo/index.ts +2 -2
  59. package/src/version.ts +1 -1
  60. package/src/zod/RpcSchema.ts +190 -13
  61. package/src/zod/_test/RpcSchema.test-d.ts +53 -6
  62. package/src/zod/_test/RpcSchema.test.ts +138 -18
  63. package/src/zod/internal/rpcSchemas/Eth.ts +14 -12
  64. package/src/zod/tempo/SignatureEnvelope.ts +1 -1
  65. package/src/zod/tempo/_test/RpcSchemaTempo.test.ts +1 -1
  66. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +23 -0
@@ -51,7 +51,7 @@ export declare const TxEnvelopeTempo: z.ZodMiniObject<{
51
51
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
52
52
  }, z.core.$strip>, z.ZodMiniObject<{
53
53
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
54
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
54
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
55
55
  init: z.ZodMiniOptional<z.ZodMiniObject<{
56
56
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
57
57
  threshold: z.ZodMiniNumber<number>;
@@ -113,7 +113,7 @@ export declare const TxEnvelopeTempo: z.ZodMiniObject<{
113
113
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
114
114
  }, z.core.$strip>, z.ZodMiniObject<{
115
115
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
116
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
116
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
117
117
  init: z.ZodMiniOptional<z.ZodMiniObject<{
118
118
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
119
119
  threshold: z.ZodMiniNumber<number>;
@@ -197,7 +197,7 @@ export declare const TxEnvelopeTempo: z.ZodMiniObject<{
197
197
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
198
198
  }, z.core.$strip>, z.ZodMiniObject<{
199
199
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
200
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
200
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
201
201
  init: z.ZodMiniOptional<z.ZodMiniObject<{
202
202
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
203
203
  threshold: z.ZodMiniNumber<number>;
@@ -263,7 +263,7 @@ export declare const Signed: z.ZodMiniObject<{
263
263
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
264
264
  }, z.core.$strip>, z.ZodMiniObject<{
265
265
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
266
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
266
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
267
267
  init: z.ZodMiniOptional<z.ZodMiniObject<{
268
268
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
269
269
  threshold: z.ZodMiniNumber<number>;
@@ -325,7 +325,7 @@ export declare const Signed: z.ZodMiniObject<{
325
325
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
326
326
  }, z.core.$strip>, z.ZodMiniObject<{
327
327
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
328
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
328
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
329
329
  init: z.ZodMiniOptional<z.ZodMiniObject<{
330
330
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
331
331
  threshold: z.ZodMiniNumber<number>;
@@ -409,7 +409,7 @@ export declare const Signed: z.ZodMiniObject<{
409
409
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
410
410
  }, z.core.$strip>, z.ZodMiniObject<{
411
411
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
412
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
412
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
413
413
  init: z.ZodMiniOptional<z.ZodMiniObject<{
414
414
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
415
415
  threshold: z.ZodMiniNumber<number>;
@@ -475,7 +475,7 @@ export declare const serialized: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${st
475
475
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
476
476
  }, z.core.$strip>, z.ZodMiniObject<{
477
477
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
478
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
478
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
479
479
  init: z.ZodMiniOptional<z.ZodMiniObject<{
480
480
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
481
481
  threshold: z.ZodMiniNumber<number>;
@@ -537,7 +537,7 @@ export declare const serialized: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${st
537
537
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
538
538
  }, z.core.$strip>, z.ZodMiniObject<{
539
539
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
540
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
540
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
541
541
  init: z.ZodMiniOptional<z.ZodMiniObject<{
542
542
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
543
543
  threshold: z.ZodMiniNumber<number>;
@@ -621,7 +621,7 @@ export declare const serialized: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${st
621
621
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
622
622
  }, z.core.$strip>, z.ZodMiniObject<{
623
623
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
624
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
624
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
625
625
  init: z.ZodMiniOptional<z.ZodMiniObject<{
626
626
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
627
627
  threshold: z.ZodMiniNumber<number>;
@@ -61,7 +61,7 @@ export declare const Signed: z.ZodMiniObject<{
61
61
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
62
62
  }, z.core.$strip>, z.ZodMiniObject<{
63
63
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
64
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
64
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
65
65
  init: z.ZodMiniOptional<z.ZodMiniObject<{
66
66
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
67
67
  threshold: z.ZodMiniNumber<number>;
@@ -123,7 +123,7 @@ export declare const ZoneRpcAuthentication: z.ZodMiniUnion<readonly [z.ZodMiniOb
123
123
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
124
124
  }, z.core.$strip>, z.ZodMiniObject<{
125
125
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
126
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
126
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
127
127
  init: z.ZodMiniOptional<z.ZodMiniObject<{
128
128
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
129
129
  threshold: z.ZodMiniNumber<number>;
@@ -192,7 +192,7 @@ export declare const serialized: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${st
192
192
  version: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"v1">, z.ZodMiniLiteral<"v2">]>>;
193
193
  }, z.core.$strip>, z.ZodMiniObject<{
194
194
  account: z.ZodMiniTemplateLiteral<`0x${string}`>;
195
- configId: z.ZodMiniTemplateLiteral<`0x${string}`>;
195
+ genesisConfigId: z.ZodMiniTemplateLiteral<`0x${string}`>;
196
196
  init: z.ZodMiniOptional<z.ZodMiniObject<{
197
197
  salt: z.ZodMiniOptional<z.ZodMiniTemplateLiteral<`0x${string}`>>;
198
198
  threshold: z.ZodMiniNumber<number>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
4
  "type": "module",
5
- "version": "1.0.0-beta.0",
5
+ "version": "1.0.0-beta.2",
6
6
  "main": "./dist/index.js",
7
7
  "sideEffects": false,
8
8
  "license": "MIT",
package/src/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ox
2
2
 
3
+ ## 0.14.29
4
+
5
+ ### Patch Changes
6
+
7
+ - [#268](https://github.com/wevm/ox/pull/268) [`ed93945`](https://github.com/wevm/ox/commit/ed93945197dd505d4848535de72a93c225fa8466) Thanks [@jxom](https://github.com/jxom)! - `viem/tempo`: Added `genesisConfig` shorthand to TIP-1061 multisig helpers and renamed `configId` → `genesisConfigId` on the typed `SignatureEnvelope.Multisig`.
8
+
3
9
  ## 0.14.28
4
10
 
5
11
  ### Patch Changes
@@ -14,7 +14,7 @@ export type Options = {
14
14
  *
15
15
  * @default `RpcSchema.Generic`
16
16
  */
17
- schema?: RpcSchema.Generic | undefined
17
+ schema?: RpcSchema.Schema | undefined
18
18
  }
19
19
 
20
20
  /** Root type for an EIP-1193 Provider. */
@@ -23,9 +23,9 @@ export type Provider<
23
23
  eventMap extends boolean | Record<string, unknown> = false,
24
24
  ///
25
25
  _schema extends RpcSchema.Generic = options extends {
26
- schema: infer schema extends RpcSchema.Generic
26
+ schema: infer schema extends RpcSchema.Schema
27
27
  }
28
- ? schema
28
+ ? RpcSchema.ToGeneric<schema>
29
29
  : RpcSchema.Default,
30
30
  > = Compute<
31
31
  {
@@ -499,9 +499,9 @@ export declare namespace from {
499
499
  > & {
500
500
  request: (
501
501
  parameters: options extends {
502
- schema: infer schema extends RpcSchema.Generic
502
+ schema: infer schema extends RpcSchema.Schema
503
503
  }
504
- ? schema['Request']
504
+ ? RpcSchema.ToGeneric<schema>['Request']
505
505
  : RpcSchema.Generic['Request'],
506
506
  ) => unknown
507
507
  }
@@ -513,8 +513,8 @@ export declare namespace from {
513
513
  | undefined,
514
514
  > = Omit<provider, 'request'> & {
515
515
  request: RequestFn<
516
- options extends { schema: infer schema extends RpcSchema.Generic }
517
- ? schema
516
+ options extends { schema: infer schema extends RpcSchema.Schema }
517
+ ? RpcSchema.ToGeneric<schema>
518
518
  : RpcSchema.Default
519
519
  >
520
520
  }
@@ -1,3 +1,4 @@
1
+ import type * as z from 'zod/mini'
1
2
  import type { ResolvedRegister } from './internal/register.js'
2
3
  import type { Compute, IsNarrowable } from './internal/types.js'
3
4
 
@@ -281,6 +282,65 @@ export type FromViem<schema extends readonly ViemSchemaItem[]> = {
281
282
  : never
282
283
  }[number]
283
284
 
285
+ /**
286
+ * Converts a record of Zod `params`/`returns` schemas (keyed by method name) to
287
+ * an Ox {@link ox#RpcSchema.Generic} (union of `{ Request, ReturnType }`).
288
+ *
289
+ * Each method's name comes from its key. Both `params` and `ReturnType` are
290
+ * derived from the Zod schema's input (wire) type, since raw JSON-RPC clients
291
+ * send and receive wire values. Decode wire results to their native
292
+ * representation explicitly via {@link ox#zod/RpcSchema.decodeReturns}.
293
+ *
294
+ * @example
295
+ * ```ts twoslash
296
+ * import { RpcSchema } from 'ox'
297
+ * import { z } from 'ox/zod'
298
+ *
299
+ * type Schema = RpcSchema.FromZod<typeof z.RpcSchema.Eth>
300
+ * // ^?
301
+ * ```
302
+ */
303
+ export type FromZod<namespace extends FromZod.Namespace> = {
304
+ [method in keyof namespace & string]: Compute<{
305
+ Request: {
306
+ method: method
307
+ params: z.input<namespace[method]['params']>
308
+ }
309
+ ReturnType: z.input<namespace[method]['returns']>
310
+ }>
311
+ }[keyof namespace & string]
312
+
313
+ export declare namespace FromZod {
314
+ /** A single method schema: Zod `params`/`returns`, keyed by method name. */
315
+ type Item = {
316
+ params: z.ZodMiniType
317
+ returns: z.ZodMiniType
318
+ }
319
+
320
+ /** A record of Zod method schemas keyed by method name. */
321
+ type Namespace = Record<string, Item>
322
+ }
323
+
324
+ /**
325
+ * Schema input accepted by APIs that statically type JSON-RPC requests
326
+ * (e.g. {@link ox#Provider.(from:function)}, {@link ox#RpcTransport.(fromHttp:function)}):
327
+ * either an Ox {@link ox#RpcSchema.Generic} or a record of Zod `params`/`returns`
328
+ * schemas (keyed by method name) from `ox/zod`.
329
+ */
330
+ export type Schema = Generic | FromZod.Namespace
331
+
332
+ /**
333
+ * Resolves a {@link ox#RpcSchema.Schema} input to an Ox {@link ox#RpcSchema.Generic}.
334
+ * A Zod namespace is converted via {@link ox#RpcSchema.FromZod}; a `Generic` is
335
+ * passed through; otherwise falls back to {@link ox#RpcSchema.Default}.
336
+ */
337
+ export type ToGeneric<schema extends Schema | undefined> =
338
+ schema extends FromZod.Namespace
339
+ ? FromZod<schema>
340
+ : schema extends Generic
341
+ ? schema
342
+ : Default
343
+
284
344
  /** @internal */
285
345
  type ViemSchemaItem = {
286
346
  Method: string
@@ -81,9 +81,12 @@ export type RequestFn<
81
81
  */
82
82
  export function fromHttp<
83
83
  raw extends boolean = false,
84
- schema extends RpcSchema.Generic = RpcSchema.Default,
85
- >(url: string, options: fromHttp.Options<raw, schema> = {}): Http<raw, schema> {
86
- return internal.create<HttpOptions, schema, raw>(
84
+ schema extends RpcSchema.Schema = RpcSchema.Default,
85
+ >(
86
+ url: string,
87
+ options: fromHttp.Options<raw, schema> = {},
88
+ ): Http<raw, RpcSchema.ToGeneric<schema>> {
89
+ return internal.create<HttpOptions, RpcSchema.ToGeneric<schema>, raw>(
87
90
  {
88
91
  async request(body_, options_) {
89
92
  const {
@@ -175,7 +178,7 @@ export function fromHttp<
175
178
  export declare namespace fromHttp {
176
179
  type Options<
177
180
  raw extends boolean = false,
178
- schema extends RpcSchema.Generic = RpcSchema.Default,
181
+ schema extends RpcSchema.Schema = RpcSchema.Default,
179
182
  > = internal.Options<raw, HttpOptions, schema>
180
183
 
181
184
  type ErrorType =
@@ -1,4 +1,5 @@
1
1
  import { Provider, RpcSchema } from 'ox'
2
+ import { z } from 'ox/zod'
2
3
  import { describe, expectTypeOf, test } from 'vp/test'
3
4
 
4
5
  describe('Provider.createEmitter', () => {
@@ -132,6 +133,26 @@ describe('Provider.from', () => {
132
133
  ).resolves.toEqualTypeOf<`0x${string}`>()
133
134
  })
134
135
 
136
+ test('with zod schema', () => {
137
+ const schema = z.RpcSchema.from({
138
+ abe_foo: {
139
+ params: z.tuple([z.number()]),
140
+ returns: z.string(),
141
+ },
142
+ })
143
+
144
+ const provider = Provider.from(
145
+ {
146
+ request: async (args) => args,
147
+ },
148
+ { schema },
149
+ )
150
+
151
+ expectTypeOf(
152
+ provider.request({ method: 'abe_foo', params: [123] }),
153
+ ).resolves.toEqualTypeOf<string>()
154
+ })
155
+
135
156
  test('with emitter', () => {
136
157
  const emitter = Provider.createEmitter()
137
158
  const provider = Provider.from({
@@ -1,4 +1,5 @@
1
- import type { RpcSchema } from 'ox'
1
+ import { RpcSchema } from 'ox'
2
+ import { z } from 'ox/zod'
2
3
  import { expectTypeOf, test } from 'vp/test'
3
4
 
4
5
  test('ToViem: converts ox schema to viem schema', () => {
@@ -116,3 +117,88 @@ test('roundtrip: FromViem -> ToViem preserves schema', () => {
116
117
  expectTypeOf<Roundtrip[0]['Method']>().toEqualTypeOf<'eth_blockNumber'>()
117
118
  expectTypeOf<Roundtrip[0]['ReturnType']>().toEqualTypeOf<`0x${string}`>()
118
119
  })
120
+
121
+ test('FromZod: derives Generic from a record of zod schemas', () => {
122
+ const namespace = {
123
+ eth_blockNumber: {
124
+ params: z.optional(z.tuple([])),
125
+ returns: z.Hex.Hex,
126
+ },
127
+ abe_foo: {
128
+ params: z.tuple([z.number()]),
129
+ returns: z.string(),
130
+ },
131
+ }
132
+
133
+ type Schema = RpcSchema.FromZod<typeof namespace>
134
+
135
+ type MethodName = RpcSchema.ExtractMethodName<Schema>
136
+ expectTypeOf<MethodName>().toEqualTypeOf<'eth_blockNumber' | 'abe_foo'>()
137
+
138
+ expectTypeOf<
139
+ RpcSchema.ExtractReturnType<Schema, 'eth_blockNumber'>
140
+ >().toEqualTypeOf<`0x${string}`>()
141
+ expectTypeOf<
142
+ RpcSchema.ExtractReturnType<Schema, 'abe_foo'>
143
+ >().toEqualTypeOf<string>()
144
+ expectTypeOf<RpcSchema.ExtractParams<Schema, 'abe_foo'>>().toEqualTypeOf<
145
+ [number]
146
+ >()
147
+ })
148
+
149
+ test('FromZod: accepts an ox/zod namespace', () => {
150
+ type Schema = RpcSchema.FromZod<typeof z.RpcSchema.Eth>
151
+
152
+ expectTypeOf<
153
+ RpcSchema.ExtractReturnType<Schema, 'eth_blockNumber'>
154
+ >().toEqualTypeOf<`0x${string}`>()
155
+ })
156
+
157
+ test('ToGeneric: resolves a zod namespace to a Generic', () => {
158
+ const namespace = {
159
+ abe_foo: {
160
+ params: z.tuple([z.number()]),
161
+ returns: z.string(),
162
+ },
163
+ }
164
+
165
+ type Schema = RpcSchema.ToGeneric<typeof namespace>
166
+
167
+ expectTypeOf<
168
+ RpcSchema.ExtractReturnType<Schema, 'abe_foo'>
169
+ >().toEqualTypeOf<string>()
170
+ expectTypeOf<RpcSchema.ExtractParams<Schema, 'abe_foo'>>().toEqualTypeOf<
171
+ [number]
172
+ >()
173
+ })
174
+
175
+ test('ToGeneric: passes a Generic through', () => {
176
+ type Schema = RpcSchema.ToGeneric<{
177
+ Request: { method: 'abe_bar'; params: [id: string] }
178
+ ReturnType: string
179
+ }>
180
+
181
+ expectTypeOf<
182
+ RpcSchema.ExtractReturnType<Schema, 'abe_bar'>
183
+ >().toEqualTypeOf<string>()
184
+ })
185
+
186
+ test('ToGeneric: falls back to Default for undefined', () => {
187
+ expectTypeOf<
188
+ RpcSchema.ToGeneric<undefined>
189
+ >().toEqualTypeOf<RpcSchema.Default>()
190
+ })
191
+
192
+ test('from: no-arg type tag still works', () => {
193
+ const schema = RpcSchema.from<
194
+ | RpcSchema.Default
195
+ | {
196
+ Request: { method: 'abe_bar'; params: [id: string] }
197
+ ReturnType: string
198
+ }
199
+ >()
200
+
201
+ expectTypeOf<
202
+ RpcSchema.ExtractReturnType<typeof schema, 'abe_bar'>
203
+ >().toEqualTypeOf<string>()
204
+ })
@@ -0,0 +1,43 @@
1
+ import { RpcSchema, RpcTransport } from 'ox'
2
+ import { z } from 'ox/zod'
3
+ import { describe, expectTypeOf, test } from 'vp/test'
4
+
5
+ describe('fromHttp', () => {
6
+ test('default schema', () => {
7
+ const transport = RpcTransport.fromHttp('https://example.com')
8
+ expectTypeOf(
9
+ transport.request({ method: 'eth_blockNumber' }),
10
+ ).resolves.toEqualTypeOf<`0x${string}`>()
11
+ })
12
+
13
+ test('with custom generic schema', () => {
14
+ const schema = RpcSchema.from<
15
+ | RpcSchema.Default
16
+ | {
17
+ Request: { method: 'abe_foo'; params: [id: number] }
18
+ ReturnType: string
19
+ }
20
+ >()
21
+
22
+ const transport = RpcTransport.fromHttp('https://example.com', { schema })
23
+
24
+ expectTypeOf(
25
+ transport.request({ method: 'abe_foo', params: [123] }),
26
+ ).resolves.toEqualTypeOf<string>()
27
+ })
28
+
29
+ test('with zod schema', () => {
30
+ const schema = z.RpcSchema.from({
31
+ abe_foo: {
32
+ params: z.tuple([z.number()]),
33
+ returns: z.string(),
34
+ },
35
+ })
36
+
37
+ const transport = RpcTransport.fromHttp('https://example.com', { schema })
38
+
39
+ expectTypeOf(
40
+ transport.request({ method: 'abe_foo', params: [123] }),
41
+ ).resolves.toEqualTypeOf<string>()
42
+ })
43
+ })
@@ -9,7 +9,7 @@ import type { Compute } from './types.js'
9
9
  export type Options<
10
10
  raw extends boolean | undefined = undefined,
11
11
  options extends Record<string, unknown> = {},
12
- schema extends RpcSchema.Generic = RpcSchema.Default,
12
+ schema extends RpcSchema.Schema = RpcSchema.Default,
13
13
  > = {
14
14
  /**
15
15
  * Enables raw mode – responses will return an object with `result` and `error` properties instead of returning the `result` directly and throwing errors.
package/src/index.ts CHANGED
@@ -1515,6 +1515,8 @@ export * as Ens from './core/Ens.js'
1515
1515
 
1516
1516
  export * as Errors from './core/Errors.js'
1517
1517
  /**
1518
+ * Utility types for working with Ethereum transaction fees and fee history.
1519
+ *
1518
1520
  * @category Execution Spec
1519
1521
  */
1520
1522
  export * as Fee from './core/Fee.js'
@@ -30,7 +30,7 @@ describe('from', () => {
30
30
  })
31
31
  })
32
32
 
33
- describe('configId', () => {
33
+ describe('genesisConfigId', () => {
34
34
  test('matches independent ground truth', () => {
35
35
  expect(MultisigConfig.toId(singleOwnerConfig)).toMatchInlineSnapshot(
36
36
  `"0xd1f20e1a5bfdd89488f57f68db5bd1aae9a51b510f4a042b2604b57a0b7b471d"`,
@@ -64,15 +64,15 @@ describe('configId', () => {
64
64
 
65
65
  describe('getAddress', () => {
66
66
  test('matches independent ground truth', () => {
67
- expect(
68
- MultisigConfig.getAddress({ config: singleOwnerConfig }),
69
- ).toMatchInlineSnapshot(`"0x6ca655065b1de473d903eebd50e5cb4996e10468"`)
67
+ expect(MultisigConfig.getAddress(singleOwnerConfig)).toMatchInlineSnapshot(
68
+ `"0x6ca655065b1de473d903eebd50e5cb4996e10468"`,
69
+ )
70
70
  })
71
71
 
72
- test('derives from config or configId identically', () => {
73
- const configId = MultisigConfig.toId(singleOwnerConfig)
74
- expect(MultisigConfig.getAddress({ configId })).toBe(
75
- MultisigConfig.getAddress({ config: singleOwnerConfig }),
72
+ test('derives from positional config or `{ genesisConfigId }` identically', () => {
73
+ const genesisConfigId = MultisigConfig.toId(singleOwnerConfig)
74
+ expect(MultisigConfig.getAddress({ genesisConfigId })).toBe(
75
+ MultisigConfig.getAddress(singleOwnerConfig),
76
76
  )
77
77
  })
78
78
 
@@ -86,18 +86,27 @@ describe('getAddress', () => {
86
86
 
87
87
  describe('getSignPayload', () => {
88
88
  test('matches independent ground truth', () => {
89
- const configId = MultisigConfig.toId(singleOwnerConfig)
90
- const account = MultisigConfig.getAddress({ configId })
91
89
  expect(
92
90
  MultisigConfig.getSignPayload({
93
91
  payload: `0x${'42'.repeat(32)}`,
94
- account,
95
- configId,
92
+ genesisConfig: singleOwnerConfig,
96
93
  }),
97
94
  ).toMatchInlineSnapshot(
98
95
  `"0xe3d66f6118b89a67c71c8137c46abf0c829056a46ee6a038a1b42c84529fc17e"`,
99
96
  )
100
97
  })
98
+
99
+ test('behavior: `genesisConfig` and `{account, genesisConfigId}` produce identical digests', () => {
100
+ const genesisConfigId = MultisigConfig.toId(singleOwnerConfig)
101
+ const account = MultisigConfig.getAddress({ genesisConfigId })
102
+ const payload = `0x${'42'.repeat(32)}` as const
103
+ expect(
104
+ MultisigConfig.getSignPayload({
105
+ payload,
106
+ genesisConfig: singleOwnerConfig,
107
+ }),
108
+ ).toBe(MultisigConfig.getSignPayload({ payload, account, genesisConfigId }))
109
+ })
101
110
  })
102
111
 
103
112
  describe('toTuple / fromTuple', () => {