ox 0.14.67 → 0.14.68

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 (228) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/_cjs/core/AbiEvent.js +45 -1
  3. package/_cjs/core/AbiEvent.js.map +1 -1
  4. package/_cjs/core/AbiParameters.js +6 -2
  5. package/_cjs/core/AbiParameters.js.map +1 -1
  6. package/_cjs/core/Address.js +24 -21
  7. package/_cjs/core/Address.js.map +1 -1
  8. package/_cjs/core/Base58.js +14 -4
  9. package/_cjs/core/Base58.js.map +1 -1
  10. package/_cjs/core/Blobs.js +26 -34
  11. package/_cjs/core/Blobs.js.map +1 -1
  12. package/_cjs/core/Bytes.js +56 -13
  13. package/_cjs/core/Bytes.js.map +1 -1
  14. package/_cjs/core/Cbor.js +33 -18
  15. package/_cjs/core/Cbor.js.map +1 -1
  16. package/_cjs/core/FrameReceipt.js +6 -2
  17. package/_cjs/core/FrameReceipt.js.map +1 -1
  18. package/_cjs/core/Hex.js +54 -21
  19. package/_cjs/core/Hex.js.map +1 -1
  20. package/_cjs/core/Json.js +15 -2
  21. package/_cjs/core/Json.js.map +1 -1
  22. package/_cjs/core/Rlp.js +138 -94
  23. package/_cjs/core/Rlp.js.map +1 -1
  24. package/_cjs/core/RpcTransport.js +3 -1
  25. package/_cjs/core/RpcTransport.js.map +1 -1
  26. package/_cjs/core/Siwe.js +2 -2
  27. package/_cjs/core/Siwe.js.map +1 -1
  28. package/_cjs/core/Transaction.js +6 -3
  29. package/_cjs/core/Transaction.js.map +1 -1
  30. package/_cjs/core/TransactionReceipt.js +12 -4
  31. package/_cjs/core/TransactionReceipt.js.map +1 -1
  32. package/_cjs/core/TransactionRequest.js +6 -2
  33. package/_cjs/core/TransactionRequest.js.map +1 -1
  34. package/_cjs/core/TxEnvelopeEip4844.js +1 -1
  35. package/_cjs/core/TxEnvelopeEip4844.js.map +1 -1
  36. package/_cjs/core/TypedData.js +19 -8
  37. package/_cjs/core/TypedData.js.map +1 -1
  38. package/_cjs/core/internal/abiParameters.js +59 -18
  39. package/_cjs/core/internal/abiParameters.js.map +1 -1
  40. package/_cjs/core/internal/address.js +32 -0
  41. package/_cjs/core/internal/address.js.map +1 -0
  42. package/_cjs/core/internal/base58.js +11 -9
  43. package/_cjs/core/internal/base58.js.map +1 -1
  44. package/_cjs/core/internal/bytes.js +13 -22
  45. package/_cjs/core/internal/bytes.js.map +1 -1
  46. package/_cjs/core/internal/caches.js +1 -0
  47. package/_cjs/core/internal/caches.js.map +1 -1
  48. package/_cjs/core/internal/cursor.js +32 -10
  49. package/_cjs/core/internal/cursor.js.map +1 -1
  50. package/_cjs/core/internal/hex.js +3 -3
  51. package/_cjs/core/internal/hex.js.map +1 -1
  52. package/_cjs/core/internal/lru.js +6 -5
  53. package/_cjs/core/internal/lru.js.map +1 -1
  54. package/_cjs/core/internal/promise.js +3 -3
  55. package/_cjs/core/internal/promise.js.map +1 -1
  56. package/_cjs/erc6492/SignatureErc6492.js +1 -1
  57. package/_cjs/erc6492/SignatureErc6492.js.map +1 -1
  58. package/_cjs/tempo/Transaction.js +13 -7
  59. package/_cjs/tempo/Transaction.js.map +1 -1
  60. package/_cjs/tempo/TransactionRequest.js +23 -19
  61. package/_cjs/tempo/TransactionRequest.js.map +1 -1
  62. package/_cjs/tempo/TxEnvelopeTempo.js +23 -4
  63. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
  64. package/_cjs/tempo/ZoneId.js +3 -0
  65. package/_cjs/tempo/ZoneId.js.map +1 -1
  66. package/_cjs/tempo/internal/virtualMasterPool.js +12 -3
  67. package/_cjs/tempo/internal/virtualMasterPool.js.map +1 -1
  68. package/_cjs/version.js +1 -1
  69. package/_esm/core/AbiEvent.js +69 -0
  70. package/_esm/core/AbiEvent.js.map +1 -1
  71. package/_esm/core/AbiParameters.js +8 -2
  72. package/_esm/core/AbiParameters.js.map +1 -1
  73. package/_esm/core/Address.js +27 -21
  74. package/_esm/core/Address.js.map +1 -1
  75. package/_esm/core/Base58.js +16 -4
  76. package/_esm/core/Base58.js.map +1 -1
  77. package/_esm/core/Blobs.js +38 -39
  78. package/_esm/core/Blobs.js.map +1 -1
  79. package/_esm/core/Bytes.js +66 -13
  80. package/_esm/core/Bytes.js.map +1 -1
  81. package/_esm/core/Cbor.js +33 -17
  82. package/_esm/core/Cbor.js.map +1 -1
  83. package/_esm/core/FrameReceipt.js +6 -2
  84. package/_esm/core/FrameReceipt.js.map +1 -1
  85. package/_esm/core/Hex.js +70 -21
  86. package/_esm/core/Hex.js.map +1 -1
  87. package/_esm/core/Json.js +21 -2
  88. package/_esm/core/Json.js.map +1 -1
  89. package/_esm/core/Rlp.js +146 -97
  90. package/_esm/core/Rlp.js.map +1 -1
  91. package/_esm/core/RpcTransport.js +4 -1
  92. package/_esm/core/RpcTransport.js.map +1 -1
  93. package/_esm/core/Siwe.js +2 -2
  94. package/_esm/core/Siwe.js.map +1 -1
  95. package/_esm/core/Transaction.js +6 -3
  96. package/_esm/core/Transaction.js.map +1 -1
  97. package/_esm/core/TransactionReceipt.js +12 -4
  98. package/_esm/core/TransactionReceipt.js.map +1 -1
  99. package/_esm/core/TransactionRequest.js +6 -2
  100. package/_esm/core/TransactionRequest.js.map +1 -1
  101. package/_esm/core/TxEnvelopeEip4844.js +1 -1
  102. package/_esm/core/TxEnvelopeEip4844.js.map +1 -1
  103. package/_esm/core/TypedData.js +24 -8
  104. package/_esm/core/TypedData.js.map +1 -1
  105. package/_esm/core/internal/abiParameters.js +78 -18
  106. package/_esm/core/internal/abiParameters.js.map +1 -1
  107. package/_esm/core/internal/address.js +41 -0
  108. package/_esm/core/internal/address.js.map +1 -0
  109. package/_esm/core/internal/base58.js +15 -9
  110. package/_esm/core/internal/base58.js.map +1 -1
  111. package/_esm/core/internal/bytes.js +14 -22
  112. package/_esm/core/internal/bytes.js.map +1 -1
  113. package/_esm/core/internal/caches.js +1 -0
  114. package/_esm/core/internal/caches.js.map +1 -1
  115. package/_esm/core/internal/cursor.js +37 -10
  116. package/_esm/core/internal/cursor.js.map +1 -1
  117. package/_esm/core/internal/hex.js +5 -3
  118. package/_esm/core/internal/hex.js.map +1 -1
  119. package/_esm/core/internal/lru.js +7 -5
  120. package/_esm/core/internal/lru.js.map +1 -1
  121. package/_esm/core/internal/promise.js +4 -3
  122. package/_esm/core/internal/promise.js.map +1 -1
  123. package/_esm/erc6492/SignatureErc6492.js +1 -1
  124. package/_esm/erc6492/SignatureErc6492.js.map +1 -1
  125. package/_esm/tempo/Transaction.js +15 -7
  126. package/_esm/tempo/Transaction.js.map +1 -1
  127. package/_esm/tempo/TransactionRequest.js +25 -19
  128. package/_esm/tempo/TransactionRequest.js.map +1 -1
  129. package/_esm/tempo/TxEnvelopeTempo.js +30 -4
  130. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
  131. package/_esm/tempo/ZoneId.js +7 -1
  132. package/_esm/tempo/ZoneId.js.map +1 -1
  133. package/_esm/tempo/internal/virtualMasterPool.js +16 -3
  134. package/_esm/tempo/internal/virtualMasterPool.js.map +1 -1
  135. package/_esm/version.js +1 -1
  136. package/_types/core/AbiEvent.d.ts +36 -1
  137. package/_types/core/AbiEvent.d.ts.map +1 -1
  138. package/_types/core/AbiParameters.d.ts +1 -1
  139. package/_types/core/AbiParameters.d.ts.map +1 -1
  140. package/_types/core/Address.d.ts.map +1 -1
  141. package/_types/core/Base58.d.ts.map +1 -1
  142. package/_types/core/Blobs.d.ts +2 -3
  143. package/_types/core/Blobs.d.ts.map +1 -1
  144. package/_types/core/Bytes.d.ts +2 -0
  145. package/_types/core/Bytes.d.ts.map +1 -1
  146. package/_types/core/Cbor.d.ts +13 -6
  147. package/_types/core/Cbor.d.ts.map +1 -1
  148. package/_types/core/FrameReceipt.d.ts.map +1 -1
  149. package/_types/core/Hex.d.ts +3 -1
  150. package/_types/core/Hex.d.ts.map +1 -1
  151. package/_types/core/Json.d.ts.map +1 -1
  152. package/_types/core/Rlp.d.ts +38 -9
  153. package/_types/core/Rlp.d.ts.map +1 -1
  154. package/_types/core/RpcTransport.d.ts.map +1 -1
  155. package/_types/core/Siwe.d.ts.map +1 -1
  156. package/_types/core/Transaction.d.ts.map +1 -1
  157. package/_types/core/TransactionReceipt.d.ts.map +1 -1
  158. package/_types/core/TransactionRequest.d.ts.map +1 -1
  159. package/_types/core/TypedData.d.ts.map +1 -1
  160. package/_types/core/internal/abiParameters.d.ts +5 -5
  161. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  162. package/_types/core/internal/address.d.ts +14 -0
  163. package/_types/core/internal/address.d.ts.map +1 -0
  164. package/_types/core/internal/base58.d.ts.map +1 -1
  165. package/_types/core/internal/bytes.d.ts +1 -10
  166. package/_types/core/internal/bytes.d.ts.map +1 -1
  167. package/_types/core/internal/caches.d.ts +1 -0
  168. package/_types/core/internal/caches.d.ts.map +1 -1
  169. package/_types/core/internal/cursor.d.ts +7 -2
  170. package/_types/core/internal/cursor.d.ts.map +1 -1
  171. package/_types/core/internal/hex.d.ts.map +1 -1
  172. package/_types/core/internal/lru.d.ts.map +1 -1
  173. package/_types/core/internal/promise.d.ts.map +1 -1
  174. package/_types/erc6492/SignatureErc6492.d.ts +1 -1
  175. package/_types/erc6492/SignatureErc6492.d.ts.map +1 -1
  176. package/_types/tempo/Transaction.d.ts.map +1 -1
  177. package/_types/tempo/TransactionRequest.d.ts.map +1 -1
  178. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  179. package/_types/tempo/ZoneId.d.ts +3 -1
  180. package/_types/tempo/ZoneId.d.ts.map +1 -1
  181. package/_types/tempo/internal/virtualMasterPool.d.ts.map +1 -1
  182. package/_types/version.d.ts +1 -1
  183. package/core/AbiEvent.ts +72 -0
  184. package/core/AbiParameters.ts +8 -1
  185. package/core/Address.ts +25 -20
  186. package/core/Base58.ts +15 -4
  187. package/core/Blobs.ts +47 -51
  188. package/core/Bytes.ts +68 -17
  189. package/core/Cbor.ts +33 -13
  190. package/core/FrameReceipt.ts +6 -2
  191. package/core/Hex.ts +79 -22
  192. package/core/Json.ts +23 -2
  193. package/core/Rlp.ts +184 -94
  194. package/core/RpcTransport.ts +4 -1
  195. package/core/Siwe.ts +2 -2
  196. package/core/Transaction.ts +6 -3
  197. package/core/TransactionReceipt.ts +13 -4
  198. package/core/TransactionRequest.ts +10 -6
  199. package/core/TxEnvelopeEip4844.ts +1 -1
  200. package/core/TypedData.ts +26 -8
  201. package/core/internal/abiParameters.ts +82 -23
  202. package/core/internal/address.ts +38 -0
  203. package/core/internal/base58.ts +14 -9
  204. package/core/internal/bytes.ts +13 -23
  205. package/core/internal/caches.ts +1 -0
  206. package/core/internal/cursor.ts +44 -16
  207. package/core/internal/hex.ts +5 -3
  208. package/core/internal/lru.ts +6 -7
  209. package/core/internal/promise.ts +5 -3
  210. package/erc6492/SignatureErc6492.ts +1 -1
  211. package/package.json +1 -1
  212. package/tempo/AccountSimulation.test.ts +1 -1
  213. package/tempo/SignaturePreAuthorized.test.ts +1 -1
  214. package/tempo/Transaction.ts +15 -9
  215. package/tempo/TransactionRequest.ts +31 -24
  216. package/tempo/TxEnvelopeTempo.test.ts +52 -0
  217. package/tempo/TxEnvelopeTempo.ts +32 -6
  218. package/tempo/ZoneId.test.ts +11 -0
  219. package/tempo/ZoneId.ts +7 -1
  220. package/tempo/internal/virtualMasterPool.ts +18 -4
  221. package/version.ts +1 -1
  222. package/_cjs/core/internal/uid.js +0 -17
  223. package/_cjs/core/internal/uid.js.map +0 -1
  224. package/_esm/core/internal/uid.js +0 -15
  225. package/_esm/core/internal/uid.js.map +0 -1
  226. package/_types/core/internal/uid.d.ts +0 -3
  227. package/_types/core/internal/uid.d.ts.map +0 -1
  228. package/core/internal/uid.ts +0 -15
@@ -193,18 +193,22 @@ export function fromRpc<
193
193
  ): transaction extends Rpc<pending> ? Transaction<pending> : null {
194
194
  if (!transaction) return null as never
195
195
 
196
+ // Leave out `aaAuthorizationList` rather than deleting it afterwards, and
197
+ // only copy the transaction when it is present.
198
+ const { aaAuthorizationList } = transaction
196
199
  const transaction_ = ox_Transaction.fromRpc(
197
- transaction as ox_Transaction.Rpc<pending>,
200
+ (aaAuthorizationList
201
+ ? (({ aaAuthorizationList: _, ...rest }) => rest)(transaction)
202
+ : transaction) as ox_Transaction.Rpc<pending>,
198
203
  ) as Transaction<pending>
199
204
 
200
- transaction_.type = fromRpcType[transaction.type as keyof typeof fromRpcType]
205
+ transaction_.type = Object.hasOwn(fromRpcType, transaction.type)
206
+ ? fromRpcType[transaction.type as keyof typeof fromRpcType]
207
+ : (undefined as never)
201
208
 
202
- if (transaction.aaAuthorizationList) {
203
- transaction_.authorizationList = AuthorizationTempo.fromRpcList(
204
- transaction.aaAuthorizationList,
205
- )
206
- delete (transaction_ as any).aaAuthorizationList
207
- }
209
+ if (aaAuthorizationList)
210
+ transaction_.authorizationList =
211
+ AuthorizationTempo.fromRpcList(aaAuthorizationList)
208
212
  if (transaction.calls)
209
213
  transaction_.calls = transaction.calls.map((call) => ({
210
214
  to: call.to,
@@ -297,7 +301,9 @@ export function toRpc<pending extends boolean = false>(
297
301
  transaction as ox_Transaction.Transaction<pending>,
298
302
  ) as Rpc<pending>
299
303
 
300
- rpc.type = toRpcType[transaction.type as keyof typeof toRpcType]
304
+ rpc.type = Object.hasOwn(toRpcType, transaction.type)
305
+ ? toRpcType[transaction.type as keyof typeof toRpcType]
306
+ : (undefined as never)
301
307
 
302
308
  if (transaction.authorizationList)
303
309
  rpc.aaAuthorizationList = AuthorizationTempo.toRpcList(
@@ -102,9 +102,11 @@ export function fromRpc(request: Rpc): TransactionRequest {
102
102
 
103
103
  if (typeof request.type !== 'undefined')
104
104
  request_.type =
105
- Transaction.fromRpcType[
106
- request.type as keyof typeof Transaction.fromRpcType
107
- ] || request_.type
105
+ (Object.hasOwn(Transaction.fromRpcType, request.type) &&
106
+ Transaction.fromRpcType[
107
+ request.type as keyof typeof Transaction.fromRpcType
108
+ ]) ||
109
+ request_.type
108
110
 
109
111
  if (request.authorizationList)
110
112
  request_.authorizationList = AuthorizationTempo.fromRpcList(
@@ -208,10 +210,31 @@ export declare namespace fromRpc {
208
210
  * @returns An RPC request.
209
211
  */
210
212
  export function toRpc(request: TransactionRequest): Rpc {
211
- const request_rpc = ox_TransactionRequest.toRpc({
212
- ...request,
213
- authorizationList: undefined,
214
- }) as Rpc
213
+ const tempo =
214
+ typeof request.accountSimulation !== 'undefined' ||
215
+ typeof request.calls !== 'undefined' ||
216
+ typeof request.feePayer !== 'undefined' ||
217
+ typeof request.feeToken !== 'undefined' ||
218
+ typeof request.keyAuthorization !== 'undefined' ||
219
+ typeof request.nonceKey !== 'undefined' ||
220
+ typeof request.validBefore !== 'undefined' ||
221
+ typeof request.validAfter !== 'undefined' ||
222
+ request.type === 'tempo'
223
+
224
+ // A Tempo request carries `data`, `to` and `value` in `calls`, so leave
225
+ // them out rather than deleting them afterwards.
226
+ const request_rpc = ox_TransactionRequest.toRpc(
227
+ tempo
228
+ ? {
229
+ ...request,
230
+ authorizationList: undefined,
231
+ data: undefined,
232
+ input: undefined,
233
+ to: undefined,
234
+ value: undefined,
235
+ }
236
+ : { ...request, authorizationList: undefined },
237
+ ) as Rpc
215
238
 
216
239
  if (request.authorizationList)
217
240
  request_rpc.authorizationList = AuthorizationTempo.toRpcList(
@@ -258,23 +281,7 @@ export function toRpc(request: TransactionRequest): Rpc {
258
281
  })()
259
282
  if (nonceKey) request_rpc.nonceKey = nonceKey
260
283
 
261
- if (
262
- typeof request.accountSimulation !== 'undefined' ||
263
- typeof request.calls !== 'undefined' ||
264
- typeof request.feePayer !== 'undefined' ||
265
- typeof request.feeToken !== 'undefined' ||
266
- typeof request.keyAuthorization !== 'undefined' ||
267
- typeof request.nonceKey !== 'undefined' ||
268
- typeof request.validBefore !== 'undefined' ||
269
- typeof request.validAfter !== 'undefined' ||
270
- request.type === 'tempo'
271
- ) {
272
- request_rpc.type = Transaction.toRpcType.tempo
273
- delete request_rpc.data
274
- delete request_rpc.input
275
- delete request_rpc.to
276
- delete request_rpc.value
277
- }
284
+ if (tempo) request_rpc.type = Transaction.toRpcType.tempo
278
285
 
279
286
  return request_rpc
280
287
  }
@@ -618,6 +618,58 @@ describe('deserialize', () => {
618
618
  expect(deserialized.feePayerSignature).toEqual(feePayerSig)
619
619
  })
620
620
 
621
+ describe('sender marker', () => {
622
+ const signed = TxEnvelopeTempo.serialize(
623
+ { ...transaction, feePayerSignature: null },
624
+ {
625
+ signature: Secp256k1.sign({
626
+ payload: TxEnvelopeTempo.getSignPayload({
627
+ ...transaction,
628
+ feePayerSignature: null,
629
+ }),
630
+ privateKey,
631
+ }),
632
+ },
633
+ )
634
+
635
+ test('ignores sender and marker after the list', () => {
636
+ const serialized = Hex.concat(
637
+ signed,
638
+ address,
639
+ '0xfeefeefeefee',
640
+ ) as TxEnvelopeTempo.Serialized
641
+ expect(TxEnvelopeTempo.deserialize(serialized)).toEqual(
642
+ TxEnvelopeTempo.deserialize(signed),
643
+ )
644
+ })
645
+
646
+ test('behavior: marker after other trailing bytes', () => {
647
+ const serialized = Hex.concat(
648
+ signed,
649
+ '0x00',
650
+ address,
651
+ '0xfeefeefeefee',
652
+ ) as TxEnvelopeTempo.Serialized
653
+ expect(() =>
654
+ TxEnvelopeTempo.deserialize(serialized),
655
+ ).toThrowErrorMatchingInlineSnapshot(
656
+ `[Rlp.TrailingBytesError: RLP payload encodes a single item, but \`27\` trailing bytes remain.]`,
657
+ )
658
+ })
659
+
660
+ test('behavior: marker without a sender', () => {
661
+ const serialized = Hex.concat(
662
+ signed,
663
+ '0xfeefeefeefee',
664
+ ) as TxEnvelopeTempo.Serialized
665
+ expect(() =>
666
+ TxEnvelopeTempo.deserialize(serialized),
667
+ ).toThrowErrorMatchingInlineSnapshot(
668
+ `[Rlp.TrailingBytesError: RLP payload encodes a single item, but \`6\` trailing bytes remain.]`,
669
+ )
670
+ })
671
+ })
672
+
621
673
  test('feePayerSignature null', () => {
622
674
  const transaction_feePayer = TxEnvelopeTempo.from({
623
675
  ...transaction,
@@ -1,5 +1,6 @@
1
1
  import * as AccessList from '../core/AccessList.js'
2
2
  import * as Address from '../core/Address.js'
3
+ import * as Bytes from '../core/Bytes.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'
@@ -276,7 +277,9 @@ export declare namespace assert {
276
277
  * @returns Deserialized Transaction Envelope.
277
278
  */
278
279
  export function deserialize(serialized: Serialized): Compute<TxEnvelopeTempo> {
279
- const transactionArray = Rlp.toHex(Hex.slice(serialized, 1))
280
+ const transactionArray = Rlp.toHex(
281
+ withoutSenderMarker(Hex.slice(serialized, 1)),
282
+ )
280
283
 
281
284
  const [
282
285
  chainId,
@@ -388,13 +391,13 @@ export function deserialize(serialized: Serialized): Compute<TxEnvelopeTempo> {
388
391
  feePayerSignatureOrSender !== '0x' &&
389
392
  feePayerSignatureOrSender !== undefined
390
393
  ) {
391
- if (
392
- feePayerSignatureOrSender === '0x00' ||
394
+ // A fee payer signature is a tuple, while a sender is an address string.
395
+ const sender =
396
+ typeof feePayerSignatureOrSender === 'string' &&
393
397
  Address.validate(feePayerSignatureOrSender)
394
- ) {
398
+ if (feePayerSignatureOrSender === '0x00' || sender) {
395
399
  transaction.feePayerSignature = null
396
- if (Address.validate(feePayerSignatureOrSender))
397
- transaction.from = feePayerSignatureOrSender
400
+ if (sender) transaction.from = feePayerSignatureOrSender
398
401
  } else
399
402
  transaction.feePayerSignature = Signature.fromTuple(
400
403
  feePayerSignatureOrSender as never,
@@ -435,6 +438,29 @@ export declare namespace deserialize {
435
438
  type ErrorType = Errors.GlobalErrorType
436
439
  }
437
440
 
441
+ /** Bytes after the RLP list in `rlp ‖ sender ‖ 0xfeefeefeefee`. */
442
+ const senderMarkerSize = 20 + 6
443
+
444
+ // Removes the `sender ‖ 0xfeefeefeefee` that follows the RLP list when a signed
445
+ // transaction is passed to a fee payer (e.g. by viem). The suffix is removed
446
+ // only when the list ends exactly before it, so any other trailing bytes are
447
+ // still rejected by `Rlp.toHex`.
448
+ function withoutSenderMarker(payload: Hex.Hex): Hex.Hex {
449
+ const size = Hex.size(payload)
450
+ if (size <= senderMarkerSize) return payload
451
+ if (payload.slice(-12).toLowerCase() !== 'feefeefeefee') return payload
452
+
453
+ // Read the list header (a prefix and up to 4 length bytes).
454
+ const header = Bytes.fromHex(Hex.slice(payload, 0, 5))
455
+ const prefix = header[0]!
456
+ if (prefix < 0xc0) return payload
457
+ const cursor = { bytes: header, position: 1 }
458
+ const length = Rlp.readLength(cursor, prefix, 0xc0)
459
+ if (cursor.position + length + senderMarkerSize !== size) return payload
460
+
461
+ return Hex.slice(payload, 0, -senderMarkerSize)
462
+ }
463
+
438
464
  /**
439
465
  * Converts an arbitrary transaction object into a Tempo Transaction Envelope.
440
466
  *
@@ -13,6 +13,17 @@ describe('fromChainId', () => {
13
13
  )
14
14
  })
15
15
 
16
+ test('other source chains', () => {
17
+ // Source chain 31318, zone 1: 31318 * 2^32 + 1.
18
+ expect(ZoneId.fromChainId(134_509_785_776_129)).toMatchInlineSnapshot(`1`)
19
+ expect(
20
+ ZoneId.fromChainId(134_509_785_776_129, 42_431),
21
+ ).toMatchInlineSnapshot(`1`)
22
+ expect(ZoneId.fromChainId(2 ** 32 + 4_294_967_295)).toMatchInlineSnapshot(
23
+ `4294967295`,
24
+ )
25
+ })
26
+
16
27
  test('unsupported source id', () => {
17
28
  expect(() =>
18
29
  // @ts-expect-error Unsupported source ID.
package/tempo/ZoneId.ts CHANGED
@@ -13,6 +13,9 @@ const chainIdConfig = {
13
13
 
14
14
  const defaultSourceId = 4_217
15
15
 
16
+ /** Chain IDs at or above this value carry their source chain ID in the high 32 bits. */
17
+ const genericChainIdBase = 2 ** 32
18
+
16
19
  /**
17
20
  * Base offset for deriving Presto zone chain IDs.
18
21
  */
@@ -24,7 +27,9 @@ export type SourceId = keyof typeof chainIdConfig
24
27
  /**
25
28
  * Derives a zone ID from a zone chain ID.
26
29
  *
27
- * Zone chain IDs use the base assigned to their Tempo source chain.
30
+ * Zone chain IDs use the base assigned to their Tempo source chain. Zones of other Tempo chains
31
+ * (such as devnets) encode the source chain ID in the high 32 bits and the zone ID in the low 32
32
+ * bits, so the zone ID is read from the chain ID alone.
28
33
  *
29
34
  * @example
30
35
  * ```ts twoslash
@@ -42,6 +47,7 @@ export function fromChainId(
42
47
  chainId: number,
43
48
  sourceId: SourceId = defaultSourceId,
44
49
  ): number {
50
+ if (chainId >= genericChainIdBase) return chainId % genericChainIdBase
45
51
  return chainId - getChainIdConfig(sourceId).base
46
52
  }
47
53
 
@@ -26,7 +26,7 @@ export type Pool = {
26
26
  ): { postMessage(data: unknown): void; terminate(): void }
27
27
  }
28
28
 
29
- let cachedPool: Pool | undefined
29
+ let cachedPool: Promise<Pool | undefined> | undefined
30
30
 
31
31
  /**
32
32
  * Whether the current runtime is Node.js.
@@ -42,10 +42,24 @@ const isNode =
42
42
  *
43
43
  * @internal
44
44
  */
45
- export async function resolve(): Promise<Pool | undefined> {
45
+ export function resolve(): Promise<Pool | undefined> {
46
+ // The promise is cached rather than its result, so calls made while the
47
+ // pool resolves share it instead of each building a pool (and, in browsers,
48
+ // a Blob URL that is never revoked). A failed attempt, or one that found no
49
+ // pool, is discarded so a later call can retry.
46
50
  if (cachedPool) return cachedPool
47
- cachedPool = isNode ? await resolveNode() : await resolveBrowser()
48
- return cachedPool
51
+ const promise = (isNode ? resolveNode() : resolveBrowser()).then(
52
+ (pool) => {
53
+ if (!pool && cachedPool === promise) cachedPool = undefined
54
+ return pool
55
+ },
56
+ (error) => {
57
+ if (cachedPool === promise) cachedPool = undefined
58
+ throw error
59
+ },
60
+ )
61
+ cachedPool = promise
62
+ return promise
49
63
  }
50
64
 
51
65
  /**
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.67'
2
+ export const version = '0.14.68'
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uid = uid;
4
- const size = 256;
5
- let index = size;
6
- let buffer;
7
- function uid(length = 11) {
8
- if (!buffer || index + length > size * 2) {
9
- buffer = '';
10
- index = 0;
11
- for (let i = 0; i < size; i++) {
12
- buffer += ((256 + Math.random() * 256) | 0).toString(16).substring(1);
13
- }
14
- }
15
- return buffer.substring(index, index++ + length);
16
- }
17
- //# sourceMappingURL=uid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uid.js","sourceRoot":"","sources":["../../../core/internal/uid.ts"],"names":[],"mappings":";;AAKA,kBASC;AAdD,MAAM,IAAI,GAAG,GAAG,CAAA;AAChB,IAAI,KAAK,GAAG,IAAI,CAAA;AAChB,IAAI,MAAc,CAAA;AAGlB,SAAgB,GAAG,CAAC,MAAM,GAAG,EAAE;IAC7B,IAAI,CAAC,MAAM,IAAI,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,GAAG,EAAE,CAAA;QACX,KAAK,GAAG,CAAC,CAAA;QACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QACvE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;AAClD,CAAC"}
@@ -1,15 +0,0 @@
1
- const size = 256;
2
- let index = size;
3
- let buffer;
4
- /** @internal */
5
- export function uid(length = 11) {
6
- if (!buffer || index + length > size * 2) {
7
- buffer = '';
8
- index = 0;
9
- for (let i = 0; i < size; i++) {
10
- buffer += ((256 + Math.random() * 256) | 0).toString(16).substring(1);
11
- }
12
- }
13
- return buffer.substring(index, index++ + length);
14
- }
15
- //# sourceMappingURL=uid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uid.js","sourceRoot":"","sources":["../../../core/internal/uid.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,GAAG,GAAG,CAAA;AAChB,IAAI,KAAK,GAAG,IAAI,CAAA;AAChB,IAAI,MAAc,CAAA;AAElB,gBAAgB;AAChB,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,EAAE;IAC7B,IAAI,CAAC,MAAM,IAAI,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,GAAG,EAAE,CAAA;QACX,KAAK,GAAG,CAAC,CAAA;QACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QACvE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;AAClD,CAAC"}
@@ -1,3 +0,0 @@
1
- /** @internal */
2
- export declare function uid(length?: number): string;
3
- //# sourceMappingURL=uid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../../core/internal/uid.ts"],"names":[],"mappings":"AAIA,gBAAgB;AAChB,wBAAgB,GAAG,CAAC,MAAM,SAAK,UAS9B"}
@@ -1,15 +0,0 @@
1
- const size = 256
2
- let index = size
3
- let buffer: string
4
-
5
- /** @internal */
6
- export function uid(length = 11) {
7
- if (!buffer || index + length > size * 2) {
8
- buffer = ''
9
- index = 0
10
- for (let i = 0; i < size; i++) {
11
- buffer += ((256 + Math.random() * 256) | 0).toString(16).substring(1)
12
- }
13
- }
14
- return buffer.substring(index, index++ + length)
15
- }