ox 0.14.32 → 0.14.34

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 (48) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/_cjs/tempo/KeyAuthorization.js +6 -6
  3. package/_cjs/tempo/KeyAuthorization.js.map +1 -1
  4. package/_cjs/tempo/MultisigConfig.js +4 -4
  5. package/_cjs/tempo/MultisigConfig.js.map +1 -1
  6. package/_cjs/tempo/SignatureEnvelope.js +23 -15
  7. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  8. package/_cjs/tempo/ZoneId.js +38 -6
  9. package/_cjs/tempo/ZoneId.js.map +1 -1
  10. package/_cjs/tempo/index.js.map +1 -1
  11. package/_cjs/version.js +1 -1
  12. package/_esm/tempo/KeyAuthorization.js +7 -13
  13. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  14. package/_esm/tempo/MultisigConfig.js +17 -16
  15. package/_esm/tempo/MultisigConfig.js.map +1 -1
  16. package/_esm/tempo/SignatureEnvelope.js +42 -28
  17. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  18. package/_esm/tempo/ZoneId.js +46 -16
  19. package/_esm/tempo/ZoneId.js.map +1 -1
  20. package/_esm/tempo/index.js +7 -8
  21. package/_esm/tempo/index.js.map +1 -1
  22. package/_esm/version.js +1 -1
  23. package/_types/tempo/KeyAuthorization.d.ts +16 -12
  24. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  25. package/_types/tempo/MultisigConfig.d.ts +20 -17
  26. package/_types/tempo/MultisigConfig.d.ts.map +1 -1
  27. package/_types/tempo/SignatureEnvelope.d.ts +26 -18
  28. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  29. package/_types/tempo/ZoneId.d.ts +35 -17
  30. package/_types/tempo/ZoneId.d.ts.map +1 -1
  31. package/_types/tempo/index.d.ts +7 -8
  32. package/_types/tempo/index.d.ts.map +1 -1
  33. package/_types/version.d.ts +1 -1
  34. package/package.json +6 -1
  35. package/tempo/KeyAuthorization.test-d.ts +41 -6
  36. package/tempo/KeyAuthorization.test.ts +106 -60
  37. package/tempo/KeyAuthorization.ts +36 -38
  38. package/tempo/MultisigConfig.test.ts +28 -8
  39. package/tempo/MultisigConfig.ts +28 -19
  40. package/tempo/SignatureEnvelope.test.ts +64 -19
  41. package/tempo/SignatureEnvelope.ts +52 -36
  42. package/tempo/ZoneId.test-d/package.json +6 -0
  43. package/tempo/ZoneId.test-d.ts +16 -0
  44. package/tempo/ZoneId.test.ts +48 -13
  45. package/tempo/ZoneId.ts +55 -19
  46. package/tempo/index.ts +7 -8
  47. package/tempo/multisig.e2e.test.ts +402 -145
  48. package/version.ts +1 -1
package/tempo/ZoneId.ts CHANGED
@@ -1,58 +1,94 @@
1
- import type * as Errors from '../core/Errors.js'
1
+ import * as Errors from '../core/Errors.js'
2
+
3
+ const chainIdConfig = {
4
+ 4217: {
5
+ base: 421_700_000,
6
+ range: 1_002_610_000,
7
+ },
8
+ 42431: {
9
+ base: 1_424_310_000,
10
+ range: 723_173_648,
11
+ },
12
+ } as const
13
+
14
+ const defaultSourceId = 4_217
2
15
 
3
16
  /**
4
- * Base offset for deriving zone chain IDs.
5
- *
6
- * Zone chain IDs are computed as `chainIdBase + zoneId`.
17
+ * Base offset for deriving Presto zone chain IDs.
7
18
  */
8
- export const chainIdBase = 4_217_000_000 as const
19
+ export const chainIdBase = chainIdConfig[defaultSourceId].base
20
+
21
+ /** Tempo source chain ID. */
22
+ export type SourceId = keyof typeof chainIdConfig
9
23
 
10
24
  /**
11
25
  * Derives a zone ID from a zone chain ID.
12
26
  *
13
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so a chain ID
14
- * of `4217000006` corresponds to zone ID `6`.
27
+ * Zone chain IDs use the base assigned to their Tempo source chain.
15
28
  *
16
29
  * @example
17
30
  * ```ts twoslash
18
31
  * import { ZoneId } from 'ox/tempo'
19
32
  *
20
- * const zoneId = ZoneId.fromChainId(4_217_000_006)
21
- * // @log: 6
33
+ * const zoneId = ZoneId.fromChainId(421_700_001)
34
+ * // @log: 1
22
35
  * ```
23
36
  *
24
37
  * @param chainId - The zone chain ID.
38
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
25
39
  * @returns The zone ID.
26
40
  */
27
- export function fromChainId(chainId: number): number {
28
- return chainId - chainIdBase
41
+ export function fromChainId(
42
+ chainId: number,
43
+ sourceId: SourceId = defaultSourceId,
44
+ ): number {
45
+ return chainId - getChainIdConfig(sourceId).base
29
46
  }
30
47
 
31
48
  export declare namespace fromChainId {
32
- type ErrorType = Errors.GlobalErrorType
49
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType
33
50
  }
34
51
 
35
52
  /**
36
53
  * Derives a zone chain ID from a zone ID.
37
54
  *
38
- * Zone chain IDs follow the formula `4_217_000_000 + zoneId`, so zone ID
39
- * `6` corresponds to chain ID `4217000006`.
55
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
40
56
  *
41
57
  * @example
42
58
  * ```ts twoslash
43
59
  * import { ZoneId } from 'ox/tempo'
44
60
  *
45
- * const chainId = ZoneId.toChainId(6)
46
- * // @log: 4217000006
61
+ * const chainId = ZoneId.toChainId(1)
62
+ * // @log: 421700001
47
63
  * ```
48
64
  *
49
65
  * @param zoneId - The zone ID.
66
+ * @param sourceId - The Tempo source chain ID. Defaults to `4217` (Presto).
50
67
  * @returns The zone chain ID.
51
68
  */
52
- export function toChainId(zoneId: number): number {
53
- return chainIdBase + zoneId
69
+ export function toChainId(
70
+ zoneId: number,
71
+ sourceId: SourceId = defaultSourceId,
72
+ ): number {
73
+ const { base, range } = getChainIdConfig(sourceId)
74
+ return base + (zoneId % range)
54
75
  }
55
76
 
56
77
  export declare namespace toChainId {
57
- type ErrorType = Errors.GlobalErrorType
78
+ type ErrorType = typeof UnsupportedSourceIdError | Errors.GlobalErrorType
79
+ }
80
+
81
+ /** Thrown when a Tempo source chain ID is unsupported. */
82
+ export class UnsupportedSourceIdError extends Errors.BaseError {
83
+ override readonly name = 'ZoneId.UnsupportedSourceIdError'
84
+ constructor({ sourceId }: { sourceId: number }) {
85
+ super(`Source chain ID "${sourceId}" is not supported.`, {
86
+ metaMessages: ['Supported source chain IDs: 4217, 42431.'],
87
+ })
88
+ }
89
+ }
90
+
91
+ function getChainIdConfig(sourceId: number) {
92
+ if (sourceId === 4_217 || sourceId === 42_431) return chainIdConfig[sourceId]
93
+ throw new UnsupportedSourceIdError({ sourceId })
58
94
  }
package/tempo/index.ts CHANGED
@@ -136,7 +136,7 @@ export * as KeyAuthorization from './KeyAuthorization.js'
136
136
  * ```ts twoslash
137
137
  * import { MultisigConfig } from 'ox/tempo'
138
138
  *
139
- * const genesisConfig = MultisigConfig.from({
139
+ * const initialConfig = MultisigConfig.from({
140
140
  * threshold: 2,
141
141
  * owners: [
142
142
  * { owner: '0x1111111111111111111111111111111111111111', weight: 1 },
@@ -144,7 +144,7 @@ export * as KeyAuthorization from './KeyAuthorization.js'
144
144
  * ],
145
145
  * })
146
146
  *
147
- * const account = MultisigConfig.getAddress(genesisConfig)
147
+ * const account = MultisigConfig.getAddress(initialConfig)
148
148
  * ```
149
149
  *
150
150
  * @category Reference
@@ -524,18 +524,17 @@ export * as VirtualMaster from './VirtualMaster.js'
524
524
  /**
525
525
  * Zone ID utilities for converting between zone IDs and zone chain IDs.
526
526
  *
527
- * Zone chain IDs are deterministically derived from zone IDs using the formula
528
- * `421_700_000 + zoneId`. This module provides helpers to convert between them.
527
+ * Zone chain IDs use the base and range assigned to their Tempo source chain.
529
528
  *
530
529
  * @example
531
530
  * ```ts twoslash
532
531
  * import { ZoneId } from 'ox/tempo'
533
532
  *
534
- * const zoneId = ZoneId.fromChainId(421_700_026)
535
- * // @log: 26
533
+ * const zoneId = ZoneId.fromChainId(421_700_001)
534
+ * // @log: 1
536
535
  *
537
- * const chainId = ZoneId.toChainId(26)
538
- * // @log: 421700026
536
+ * const chainId = ZoneId.toChainId(1)
537
+ * // @log: 421700001
539
538
  * ```
540
539
  *
541
540
  * @category Reference