ox 1.7.2 → 1.7.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/core/AbiEvent.d.ts.map +1 -1
  3. package/dist/core/AbiEvent.js +10 -9
  4. package/dist/core/AbiEvent.js.map +1 -1
  5. package/dist/core/Blobs.d.ts.map +1 -1
  6. package/dist/core/Blobs.js +6 -2
  7. package/dist/core/Blobs.js.map +1 -1
  8. package/dist/core/Signature.d.ts +6 -5
  9. package/dist/core/Signature.d.ts.map +1 -1
  10. package/dist/core/Signature.js +17 -7
  11. package/dist/core/Signature.js.map +1 -1
  12. package/dist/core/Siwe.d.ts.map +1 -1
  13. package/dist/core/Siwe.js +21 -1
  14. package/dist/core/Siwe.js.map +1 -1
  15. package/dist/tempo/KeyAuthorization.d.ts +43 -39
  16. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  17. package/dist/tempo/KeyAuthorization.js +24 -4
  18. package/dist/tempo/KeyAuthorization.js.map +1 -1
  19. package/dist/tempo/MultisigConfig.d.ts +18 -15
  20. package/dist/tempo/MultisigConfig.d.ts.map +1 -1
  21. package/dist/tempo/MultisigConfig.js +49 -20
  22. package/dist/tempo/MultisigConfig.js.map +1 -1
  23. package/dist/tempo/MultisigOperation.d.ts +45 -28
  24. package/dist/tempo/MultisigOperation.d.ts.map +1 -1
  25. package/dist/tempo/MultisigOperation.js +81 -131
  26. package/dist/tempo/MultisigOperation.js.map +1 -1
  27. package/dist/tempo/MultisigSimulation.d.ts +85 -0
  28. package/dist/tempo/MultisigSimulation.d.ts.map +1 -0
  29. package/dist/tempo/MultisigSimulation.js +112 -0
  30. package/dist/tempo/MultisigSimulation.js.map +1 -0
  31. package/dist/tempo/RpcSchemaTempo.d.ts +20 -10
  32. package/dist/tempo/RpcSchemaTempo.d.ts.map +1 -1
  33. package/dist/tempo/SignatureEnvelope.d.ts +74 -153
  34. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  35. package/dist/tempo/SignatureEnvelope.js +130 -187
  36. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  37. package/dist/tempo/TransactionRequest.d.ts +9 -7
  38. package/dist/tempo/TransactionRequest.d.ts.map +1 -1
  39. package/dist/tempo/TransactionRequest.js +12 -7
  40. package/dist/tempo/TransactionRequest.js.map +1 -1
  41. package/dist/tempo/index.d.ts +7 -5
  42. package/dist/tempo/index.d.ts.map +1 -1
  43. package/dist/tempo/index.js +7 -5
  44. package/dist/tempo/index.js.map +1 -1
  45. package/dist/zod/tempo/AuthorizationTempo.d.ts +360 -140
  46. package/dist/zod/tempo/AuthorizationTempo.d.ts.map +1 -1
  47. package/dist/zod/tempo/KeyAuthorization.d.ts +247 -487
  48. package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
  49. package/dist/zod/tempo/KeyAuthorization.js +29 -31
  50. package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
  51. package/dist/zod/tempo/MultisigOperation.d.ts +0 -10
  52. package/dist/zod/tempo/MultisigOperation.d.ts.map +1 -1
  53. package/dist/zod/tempo/MultisigOperation.js +0 -3
  54. package/dist/zod/tempo/MultisigOperation.js.map +1 -1
  55. package/dist/zod/tempo/MultisigSimulation.d.ts +52 -0
  56. package/dist/zod/tempo/MultisigSimulation.d.ts.map +1 -0
  57. package/dist/zod/tempo/MultisigSimulation.js +44 -0
  58. package/dist/zod/tempo/MultisigSimulation.js.map +1 -0
  59. package/dist/zod/tempo/RpcSchemaTempo.d.ts +357 -422
  60. package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
  61. package/dist/zod/tempo/RpcSchemaTempo.js +19 -10
  62. package/dist/zod/tempo/RpcSchemaTempo.js.map +1 -1
  63. package/dist/zod/tempo/SignatureEnvelope.d.ts +108 -42
  64. package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
  65. package/dist/zod/tempo/SignatureEnvelope.js +21 -19
  66. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  67. package/dist/zod/tempo/Transaction.d.ts +678 -666
  68. package/dist/zod/tempo/Transaction.d.ts.map +1 -1
  69. package/dist/zod/tempo/TransactionRequest.d.ts +580 -619
  70. package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
  71. package/dist/zod/tempo/TransactionRequest.js +18 -10
  72. package/dist/zod/tempo/TransactionRequest.js.map +1 -1
  73. package/dist/zod/tempo/TxEnvelopeTempo.d.ts +327 -213
  74. package/dist/zod/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  75. package/dist/zod/tempo/ZoneRpcAuthentication.d.ts +105 -3
  76. package/dist/zod/tempo/ZoneRpcAuthentication.d.ts.map +1 -1
  77. package/dist/zod/tempo/z.d.ts +1 -1
  78. package/dist/zod/tempo/z.d.ts.map +1 -1
  79. package/dist/zod/tempo/z.js +1 -1
  80. package/dist/zod/tempo/z.js.map +1 -1
  81. package/package.json +9 -9
  82. package/src/core/AbiEvent.ts +11 -9
  83. package/src/core/Blobs.ts +6 -2
  84. package/src/core/Signature.ts +41 -11
  85. package/src/core/Siwe.ts +20 -1
  86. package/src/core/_test/AbiEvent.test.ts +45 -0
  87. package/src/core/_test/Blobs.test.ts +22 -0
  88. package/src/core/_test/Signature.test.ts +166 -0
  89. package/src/core/_test/Siwe.test.ts +100 -1
  90. package/src/tempo/AuthorizationTempo.test.ts +8 -0
  91. package/src/tempo/KeyAuthorization.test-d.ts +16 -74
  92. package/src/tempo/KeyAuthorization.test.ts +113 -14
  93. package/src/tempo/KeyAuthorization.ts +110 -66
  94. package/src/tempo/MultisigConfig.test.ts +44 -20
  95. package/src/tempo/MultisigConfig.ts +65 -23
  96. package/src/tempo/MultisigOperation.test-d.ts +8 -6
  97. package/src/tempo/MultisigOperation.test.ts +187 -591
  98. package/src/tempo/MultisigOperation.ts +129 -205
  99. package/src/tempo/MultisigSimulation.test-d.ts +33 -0
  100. package/src/tempo/MultisigSimulation.test.ts +194 -0
  101. package/src/tempo/MultisigSimulation.ts +192 -0
  102. package/src/tempo/RpcSchemaTempo.test-d.ts +45 -10
  103. package/src/tempo/RpcSchemaTempo.ts +15 -6
  104. package/src/tempo/SignatureEnvelope.test-d.ts +27 -101
  105. package/src/tempo/SignatureEnvelope.test.ts +330 -533
  106. package/src/tempo/SignatureEnvelope.ts +198 -310
  107. package/src/tempo/Transaction.test.ts +61 -0
  108. package/src/tempo/TransactionRequest.test-d.ts +7 -7
  109. package/src/tempo/TransactionRequest.test.ts +81 -223
  110. package/src/tempo/TransactionRequest.ts +34 -13
  111. package/src/tempo/index.ts +7 -5
  112. package/src/tempo/multisig.e2e.test.ts +329 -818
  113. package/src/version.ts +1 -1
  114. package/src/zod/tempo/KeyAuthorization.ts +50 -39
  115. package/src/zod/tempo/MultisigOperation.ts +0 -3
  116. package/src/zod/tempo/MultisigSimulation.ts +53 -0
  117. package/src/zod/tempo/RpcSchemaTempo.ts +20 -10
  118. package/src/zod/tempo/SignatureEnvelope.ts +46 -59
  119. package/src/zod/tempo/TransactionRequest.ts +28 -14
  120. package/src/zod/tempo/_test/KeyAuthorization.test.ts +66 -30
  121. package/src/zod/tempo/_test/MultisigOperation.test.ts +0 -2
  122. package/src/zod/tempo/_test/MultisigSimulation.test-d.ts +13 -0
  123. package/src/zod/tempo/_test/MultisigSimulation.test.ts +53 -0
  124. package/src/zod/tempo/_test/RpcSchemaTempo.test-d.ts +19 -2
  125. package/src/zod/tempo/_test/RpcSchemaTempo.test.ts +46 -4
  126. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +108 -129
  127. package/src/zod/tempo/_test/TransactionRequest.test.ts +17 -168
  128. package/src/zod/tempo/z.ts +1 -1
  129. package/dist/tempo/MultisigWitness.d.ts +0 -106
  130. package/dist/tempo/MultisigWitness.d.ts.map +0 -1
  131. package/dist/tempo/MultisigWitness.js +0 -118
  132. package/dist/tempo/MultisigWitness.js.map +0 -1
  133. package/dist/zod/tempo/MultisigWitness.d.ts +0 -152
  134. package/dist/zod/tempo/MultisigWitness.d.ts.map +0 -1
  135. package/dist/zod/tempo/MultisigWitness.js +0 -76
  136. package/dist/zod/tempo/MultisigWitness.js.map +0 -1
  137. package/src/tempo/MultisigWitness.test-d.ts +0 -42
  138. package/src/tempo/MultisigWitness.test.ts +0 -288
  139. package/src/tempo/MultisigWitness.ts +0 -210
  140. package/src/zod/tempo/MultisigWitness.ts +0 -101
  141. package/src/zod/tempo/_test/MultisigWitness.test-d.ts +0 -13
  142. package/src/zod/tempo/_test/MultisigWitness.test.ts +0 -149
@@ -1,16 +1,11 @@
1
1
  import * as Address from '../core/Address.js'
2
2
  import type * as Bytes from '../core/Bytes.js'
3
+ import * as ContractAddress from '../core/ContractAddress.js'
3
4
  import * as Errors from '../core/Errors.js'
4
5
  import * as Hash from '../core/Hash.js'
5
6
  import * as Hex from '../core/Hex.js'
6
7
  import type { Compute } from '../core/internal/types.js'
7
8
 
8
- /**
9
- * Maximum number of native multisig signatures in one nested authorization
10
- * path, including the top-level transaction signature.
11
- */
12
- export const maxNestingDepth = 2
13
-
14
9
  /** Maximum encoded byte length for one primitive owner approval. */
15
10
  export const maxOwnerSignatureBytes = 2049
16
11
 
@@ -21,7 +16,7 @@ export const maxOwners = 48
21
16
  export const maxSignatures = 8
22
17
 
23
18
  /** Maximum threshold accepted by a native multisig config. */
24
- export const maxThreshold = 0xff
19
+ export const maxThreshold = 8
25
20
 
26
21
  /** Maximum version accepted by a native multisig config. */
27
22
  export const maxVersion = 2n ** 64n - 1n
@@ -38,6 +33,10 @@ const accountDomain = 'tempo:multisig:account'
38
33
  /** Domain prefix for native multisig configuration commitments. */
39
34
  const configDomain = 'tempo:multisig:config'
40
35
 
36
+ /** Keccak-256 of the canonical recovery wallet creation code. */
37
+ const recoveryWalletInitCodeHash =
38
+ '0x583cc63a2e37f645b43eac911b1a6d6de08b83abdc308c61364edda8cfc3bd37'
39
+
41
40
  /** Domain prefix for native multisig owner approvals. */
42
41
  const signatureDomain = 'tempo:multisig:signature'
43
42
 
@@ -304,7 +303,33 @@ export declare namespace fromRpc {
304
303
  */
305
304
  export function fromTuple(tuple: Tuple): Config {
306
305
  const [salt, version, threshold, owners] = tuple
307
- return {
306
+ if (
307
+ tuple.length !== 4 ||
308
+ typeof salt !== 'string' ||
309
+ Hex.size(salt) !== 32 ||
310
+ typeof version !== 'string' ||
311
+ Hex.size(version) > 8 ||
312
+ version.startsWith('0x00') ||
313
+ typeof threshold !== 'string' ||
314
+ Hex.size(threshold) > 1 ||
315
+ threshold.startsWith('0x00') ||
316
+ !Array.isArray(owners) ||
317
+ owners.some(
318
+ (owner) =>
319
+ !Array.isArray(owner) ||
320
+ owner.length !== 2 ||
321
+ typeof owner[0] !== 'string' ||
322
+ !Address.validate(owner[0]) ||
323
+ typeof owner[1] !== 'string' ||
324
+ Hex.size(owner[1] as Hex.Hex) > 1 ||
325
+ owner[1].startsWith('0x00'),
326
+ )
327
+ )
328
+ throw new InvalidConfigError({ reason: 'invalid config RLP tuple' })
329
+ const config = {
330
+ salt: salt && salt !== '0x' ? Hex.padLeft(salt, 32) : zeroSalt,
331
+ version: version === '0x' ? 0n : Hex.toBigInt(version),
332
+ threshold: threshold === '0x' ? 0 : Hex.toNumber(threshold),
308
333
  owners: owners.map((owner) => {
309
334
  const [ownerAddress, weight] = owner as readonly Hex.Hex[]
310
335
  return {
@@ -312,17 +337,17 @@ export function fromTuple(tuple: Tuple): Config {
312
337
  weight: !weight || weight === '0x' ? 0 : Hex.toNumber(weight),
313
338
  }
314
339
  }),
315
- salt: salt && salt !== '0x' ? Hex.padLeft(salt, 32) : zeroSalt,
316
- threshold: threshold === '0x' ? 0 : Hex.toNumber(threshold),
317
- version: version === '0x' ? 0n : Hex.toBigInt(version),
318
340
  }
341
+ assert(config)
342
+ return config
319
343
  }
320
344
 
321
345
  /**
322
346
  * Derives the stable native multisig account address.
323
347
  *
324
- * Preimage (fixed-width big-endian, **not** RLP):
325
- * `keccak256("tempo:multisig:account" || salt || u8(threshold) || u8(owners.length) || (owner || u8(weight)) for each owner)[12:32]`.
348
+ * The initial config is hashed into a CREATE2 salt using fixed-width
349
+ * big-endian fields, not RLP. The account uses the chain-configured recovery
350
+ * factory and wallet init-code hash.
326
351
  *
327
352
  * The address is derived once from the initial version-0 config. Config
328
353
  * updates do not change it.
@@ -341,19 +366,26 @@ export function fromTuple(tuple: Tuple): Config {
341
366
  * threshold: 1
342
367
  * })
343
368
  *
344
- * const address = MultisigConfig.getAddress(initialConfig)
369
+ * const address = MultisigConfig.getAddress(initialConfig, {
370
+ * factory: '0x7171717171717171717171717171717171717171'
371
+ * })
345
372
  * ```
346
373
  *
347
374
  * @param config - The initial multisig config.
375
+ * @param options - The recovery factory configured by the chain.
348
376
  * @returns The multisig account address.
349
377
  */
350
- export function getAddress(config: Input): Address.Address {
378
+ export function getAddress(
379
+ config: Input,
380
+ options: getAddress.Options,
381
+ ): Address.Address {
382
+ Address.assert(options.factory)
351
383
  assert(config)
352
384
  if (BigInt(config.version ?? 0) !== 0n)
353
385
  throw new InvalidConfigError({
354
386
  reason: 'account address requires version zero',
355
387
  })
356
- const hash = Hash.keccak256(
388
+ const accountSalt = Hash.keccak256(
357
389
  Hex.concat(
358
390
  Hex.fromString(accountDomain),
359
391
  Hex.padLeft(config.salt ?? zeroSalt, 32),
@@ -365,7 +397,11 @@ export function getAddress(config: Input): Address.Address {
365
397
  ]),
366
398
  ),
367
399
  )
368
- const account = Address.from(Hex.slice(hash, 12, 32))
400
+ const account = ContractAddress.fromCreate2({
401
+ bytecodeHash: recoveryWalletInitCodeHash,
402
+ from: options.factory,
403
+ salt: accountSalt,
404
+ })
369
405
  if (Hex.toBigInt(account) === 0n)
370
406
  throw new InvalidConfigError({ reason: 'derived account cannot be zero' })
371
407
  if (config.owners.some((owner) => Address.isEqual(owner.owner, account)))
@@ -376,14 +412,18 @@ export function getAddress(config: Input): Address.Address {
376
412
  }
377
413
 
378
414
  export declare namespace getAddress {
415
+ type Options = {
416
+ /** Recovery factory configured by the chain. */
417
+ factory: Address.Address
418
+ }
419
+
379
420
  type ErrorType =
380
421
  | assert.ErrorType
381
- | Address.from.ErrorType
422
+ | ContractAddress.fromCreate2.ErrorType
382
423
  | Hash.keccak256.ErrorType
383
424
  | Hex.concat.ErrorType
384
425
  | Hex.fromNumber.ErrorType
385
426
  | Hex.fromString.ErrorType
386
- | Hex.slice.ErrorType
387
427
  | Errors.GlobalErrorType
388
428
  }
389
429
 
@@ -450,9 +490,6 @@ export declare namespace getCommitment {
450
490
  * version. Initial approvals use version `0n`; each config update increments
451
491
  * it.
452
492
  *
453
- * For a nested multisig owner approval, the parent digest becomes the nested
454
- * approval's `payload`, with the nested multisig `account`.
455
- *
456
493
  * @example
457
494
  * ```ts twoslash
458
495
  * import { MultisigConfig, TxEnvelopeTempo } from 'ox/tempo'
@@ -473,7 +510,9 @@ export declare namespace getCommitment {
473
510
  * })
474
511
  *
475
512
  * const digest = MultisigConfig.getSignPayload({
476
- * account: MultisigConfig.getAddress(config),
513
+ * account: MultisigConfig.getAddress(config, {
514
+ * factory: '0x7171717171717171717171717171717171717171'
515
+ * }),
477
516
  * config,
478
517
  * payload: TxEnvelopeTempo.getSignPayload(envelope)
479
518
  * })
@@ -485,6 +524,9 @@ export declare namespace getCommitment {
485
524
  export function getSignPayload(value: getSignPayload.Value): Hex.Hex {
486
525
  const { account, config, payload } = value
487
526
  assertVersion(config.version)
527
+ Address.assert(account)
528
+ if (Hex.size(Hex.from(payload)) !== 32)
529
+ throw new InvalidConfigError({ reason: 'payload must be 32 bytes' })
488
530
  return Hash.keccak256(
489
531
  Hex.concat(
490
532
  Hex.fromString(signatureDomain),
@@ -11,6 +11,8 @@ declare const operation: MultisigOperation.Operation
11
11
  declare const operationRpc: MultisigOperation.Rpc
12
12
  declare const getHashOptions: MultisigOperation.getHash.Options
13
13
  declare const selectApprovalsOptions: MultisigOperation.selectApprovals.Options
14
+ declare const serializedKeyAuthorization: Hex.Hex
15
+ declare const serializeKeyAuthorizationOptions: MultisigOperation.serializeKeyAuthorization.Options
14
16
  declare const serializeTransactionOptions: MultisigOperation.serializeTransaction.Options
15
17
 
16
18
  test('preserves operation kinds during validation', () => {
@@ -50,15 +52,9 @@ test('uses JSON-RPC quantities only in RPC operations', () => {
50
52
  expectTypeOf<
51
53
  MultisigOperation.Operation['config']['version']
52
54
  >().toEqualTypeOf<bigint>()
53
- expectTypeOf<
54
- MultisigOperation.Operation['configVersion']
55
- >().toEqualTypeOf<bigint>()
56
55
  expectTypeOf<
57
56
  MultisigOperation.Rpc['config']['version']
58
57
  >().toEqualTypeOf<Hex.Hex>()
59
- expectTypeOf<
60
- MultisigOperation.Rpc['configVersion']
61
- >().toEqualTypeOf<Hex.Hex>()
62
58
  })
63
59
 
64
60
  test('operation helpers return narrow types', async () => {
@@ -68,6 +64,12 @@ test('operation helpers return narrow types', async () => {
68
64
  expectTypeOf(
69
65
  await MultisigOperation.selectApprovals(selectApprovalsOptions),
70
66
  ).toEqualTypeOf<MultisigOperation.selectApprovals.ReturnValue>()
67
+ expectTypeOf(
68
+ MultisigOperation.serializeKeyAuthorization(
69
+ serializedKeyAuthorization,
70
+ serializeKeyAuthorizationOptions,
71
+ ),
72
+ ).toEqualTypeOf<Hex.Hex>()
71
73
  expectTypeOf(
72
74
  MultisigOperation.serializeTransaction(
73
75
  transaction,