ox 1.7.1 → 1.7.4

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 (123) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/core/Hash.js +1 -1
  3. package/dist/core/Hash.js.map +1 -1
  4. package/dist/tempo/KeyAuthorization.d.ts +2 -2
  5. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  6. package/dist/tempo/MultisigConfig.d.ts +151 -83
  7. package/dist/tempo/MultisigConfig.d.ts.map +1 -1
  8. package/dist/tempo/MultisigConfig.js +164 -86
  9. package/dist/tempo/MultisigConfig.js.map +1 -1
  10. package/dist/tempo/MultisigOperation.d.ts +340 -0
  11. package/dist/tempo/MultisigOperation.d.ts.map +1 -0
  12. package/dist/tempo/MultisigOperation.js +839 -0
  13. package/dist/tempo/MultisigOperation.js.map +1 -0
  14. package/dist/tempo/MultisigSimulation.d.ts +132 -0
  15. package/dist/tempo/MultisigSimulation.d.ts.map +1 -0
  16. package/dist/tempo/MultisigSimulation.js +140 -0
  17. package/dist/tempo/MultisigSimulation.js.map +1 -0
  18. package/dist/tempo/RpcSchemaTempo.d.ts +45 -0
  19. package/dist/tempo/RpcSchemaTempo.d.ts.map +1 -1
  20. package/dist/tempo/SignatureEnvelope.d.ts +55 -86
  21. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  22. package/dist/tempo/SignatureEnvelope.js +93 -158
  23. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  24. package/dist/tempo/TransactionRequest.d.ts +9 -17
  25. package/dist/tempo/TransactionRequest.d.ts.map +1 -1
  26. package/dist/tempo/TransactionRequest.js +7 -7
  27. package/dist/tempo/TransactionRequest.js.map +1 -1
  28. package/dist/tempo/TxEnvelopeTempo.d.ts +3 -2
  29. package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  30. package/dist/tempo/TxEnvelopeTempo.js +3 -2
  31. package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
  32. package/dist/tempo/index.d.ts +22 -2
  33. package/dist/tempo/index.d.ts.map +1 -1
  34. package/dist/tempo/index.js +22 -2
  35. package/dist/tempo/index.js.map +1 -1
  36. package/dist/zod/tempo/AuthorizationTempo.d.ts +60 -180
  37. package/dist/zod/tempo/AuthorizationTempo.d.ts.map +1 -1
  38. package/dist/zod/tempo/KeyAuthorization.d.ts +65 -118
  39. package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
  40. package/dist/zod/tempo/MultisigConfig.d.ts +31 -2
  41. package/dist/zod/tempo/MultisigConfig.d.ts.map +1 -1
  42. package/dist/zod/tempo/MultisigConfig.js +26 -3
  43. package/dist/zod/tempo/MultisigConfig.js.map +1 -1
  44. package/dist/zod/tempo/MultisigOperation.d.ts +158 -0
  45. package/dist/zod/tempo/MultisigOperation.d.ts.map +1 -0
  46. package/dist/zod/tempo/MultisigOperation.js +62 -0
  47. package/dist/zod/tempo/MultisigOperation.js.map +1 -0
  48. package/dist/zod/tempo/MultisigSimulation.d.ts +120 -0
  49. package/dist/zod/tempo/MultisigSimulation.d.ts.map +1 -0
  50. package/dist/zod/tempo/MultisigSimulation.js +78 -0
  51. package/dist/zod/tempo/MultisigSimulation.js.map +1 -0
  52. package/dist/zod/tempo/RpcSchemaTempo.d.ts +528 -144
  53. package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
  54. package/dist/zod/tempo/RpcSchemaTempo.js +47 -0
  55. package/dist/zod/tempo/RpcSchemaTempo.js.map +1 -1
  56. package/dist/zod/tempo/SignatureEnvelope.d.ts +18 -54
  57. package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
  58. package/dist/zod/tempo/SignatureEnvelope.js +5 -22
  59. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  60. package/dist/zod/tempo/Transaction.d.ts +138 -348
  61. package/dist/zod/tempo/Transaction.d.ts.map +1 -1
  62. package/dist/zod/tempo/TransactionRequest.d.ts +286 -239
  63. package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
  64. package/dist/zod/tempo/TransactionRequest.js +11 -22
  65. package/dist/zod/tempo/TransactionRequest.js.map +1 -1
  66. package/dist/zod/tempo/TxEnvelopeTempo.d.ts +60 -48
  67. package/dist/zod/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  68. package/dist/zod/tempo/ZoneRpcAuthentication.d.ts +15 -12
  69. package/dist/zod/tempo/ZoneRpcAuthentication.d.ts.map +1 -1
  70. package/dist/zod/tempo/z.d.ts +2 -0
  71. package/dist/zod/tempo/z.d.ts.map +1 -1
  72. package/dist/zod/tempo/z.js +2 -0
  73. package/dist/zod/tempo/z.js.map +1 -1
  74. package/package.json +21 -1
  75. package/src/core/Hash.ts +1 -1
  76. package/src/core/_test/Hash.test.ts +15 -0
  77. package/src/tempo/AuthorizationTempo.test.ts +4 -0
  78. package/src/tempo/KeyAuthorization.test-d.ts +13 -12
  79. package/src/tempo/KeyAuthorization.test.ts +109 -3
  80. package/src/tempo/KeyAuthorization.ts +4 -4
  81. package/src/tempo/MultisigConfig.test-d.ts +52 -0
  82. package/src/tempo/MultisigConfig.test.ts +288 -227
  83. package/src/tempo/MultisigConfig.ts +275 -104
  84. package/src/tempo/MultisigOperation.test-d.ts +79 -0
  85. package/src/tempo/MultisigOperation.test.ts +1950 -0
  86. package/src/tempo/MultisigOperation.ts +1293 -0
  87. package/src/tempo/MultisigSimulation.test-d.ts +33 -0
  88. package/src/tempo/MultisigSimulation.test.ts +283 -0
  89. package/src/tempo/MultisigSimulation.ts +266 -0
  90. package/src/tempo/RpcSchemaTempo.test-d.ts +91 -0
  91. package/src/tempo/RpcSchemaTempo.ts +46 -0
  92. package/src/tempo/SignatureEnvelope.test-d.ts +33 -72
  93. package/src/tempo/SignatureEnvelope.test.ts +533 -500
  94. package/src/tempo/SignatureEnvelope.ts +171 -258
  95. package/src/tempo/Transaction.test.ts +61 -0
  96. package/src/tempo/TransactionRequest.test-d.ts +11 -0
  97. package/src/tempo/TransactionRequest.test.ts +214 -41
  98. package/src/tempo/TransactionRequest.ts +19 -20
  99. package/src/tempo/TxEnvelopeTempo.test-d.ts +7 -0
  100. package/src/tempo/TxEnvelopeTempo.test.ts +25 -0
  101. package/src/tempo/TxEnvelopeTempo.ts +5 -3
  102. package/src/tempo/index.ts +22 -2
  103. package/src/tempo/multisig.e2e.test.ts +164 -87
  104. package/src/version.ts +1 -1
  105. package/src/zod/tempo/MultisigConfig.ts +29 -3
  106. package/src/zod/tempo/MultisigOperation.ts +66 -0
  107. package/src/zod/tempo/MultisigSimulation.ts +98 -0
  108. package/src/zod/tempo/RpcSchemaTempo.ts +53 -0
  109. package/src/zod/tempo/SignatureEnvelope.ts +12 -54
  110. package/src/zod/tempo/TransactionRequest.ts +17 -26
  111. package/src/zod/tempo/_test/KeyAuthorization.test.ts +2 -4
  112. package/src/zod/tempo/_test/MultisigConfig.test-d.ts +13 -0
  113. package/src/zod/tempo/_test/MultisigConfig.test.ts +13 -2
  114. package/src/zod/tempo/_test/MultisigOperation.test-d.ts +27 -0
  115. package/src/zod/tempo/_test/MultisigOperation.test.ts +66 -0
  116. package/src/zod/tempo/_test/MultisigSimulation.test-d.ts +13 -0
  117. package/src/zod/tempo/_test/MultisigSimulation.test.ts +78 -0
  118. package/src/zod/tempo/_test/RpcSchemaTempo.test-d.ts +48 -0
  119. package/src/zod/tempo/_test/RpcSchemaTempo.test.ts +83 -0
  120. package/src/zod/tempo/_test/SignatureEnvelope.test-d.ts +1 -1
  121. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +57 -120
  122. package/src/zod/tempo/_test/TransactionRequest.test.ts +43 -16
  123. package/src/zod/tempo/z.ts +2 -0
@@ -0,0 +1,33 @@
1
+ import { expectTypeOf, test } from 'vp/test'
2
+ import * as MultisigSimulation from './MultisigSimulation.js'
3
+
4
+ const rpc = {
5
+ account: '0x2222222222222222222222222222222222222222',
6
+ approvals: [
7
+ {
8
+ owner: '0x1111111111111111111111111111111111111111',
9
+ type: 'primitive',
10
+ },
11
+ ],
12
+ config:
13
+ '0xf83ba000000000000000000000000000000000000000000000000000000000000000008001d7d694111111111111111111111111111111111111111101',
14
+ } as const satisfies MultisigSimulation.Rpc
15
+
16
+ test('fromRpc returns a domain spec', () => {
17
+ const spec = MultisigSimulation.fromRpc(rpc)
18
+
19
+ expectTypeOf(spec).toEqualTypeOf<MultisigSimulation.Spec>()
20
+ expectTypeOf(spec.config.version).toEqualTypeOf<bigint>()
21
+ })
22
+
23
+ test('RPC specs use encoded configurations', () => {
24
+ expectTypeOf<
25
+ MultisigSimulation.Rpc['config']
26
+ >().toEqualTypeOf<`0x${string}`>()
27
+ })
28
+
29
+ test('toRpc returns an RPC spec', () => {
30
+ expectTypeOf(
31
+ MultisigSimulation.toRpc(MultisigSimulation.fromRpc(rpc)),
32
+ ).toEqualTypeOf<MultisigSimulation.Rpc>()
33
+ })
@@ -0,0 +1,283 @@
1
+ import { MultisigConfig, MultisigSimulation } from 'ox/tempo'
2
+ import { describe, expect, test } from 'vp/test'
3
+
4
+ const config =
5
+ '0xf852a011111111111111111111111111111111111111111111111111111111111111118002eed694111111111111111111111111111111111111111101d694bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb01' as const
6
+ const nestedConfig =
7
+ '0xf83ba022222222222222222222222222222222222222222222222222222222222222220101d7d694222222222222222222222222222222222222222201' as const
8
+ const rpc = {
9
+ account: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
10
+ approvals: [
11
+ {
12
+ keyData: '0x0102030405',
13
+ keyType: 'webAuthn',
14
+ owner: '0x1111111111111111111111111111111111111111',
15
+ type: 'primitive',
16
+ },
17
+ {
18
+ spec: {
19
+ account: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
20
+ approvals: [
21
+ {
22
+ keyData: '0x010203040506',
23
+ keyType: 'secp256k1',
24
+ owner: '0x2222222222222222222222222222222222222222',
25
+ },
26
+ ],
27
+ config: nestedConfig,
28
+ },
29
+ type: 'multisig',
30
+ },
31
+ ],
32
+ config,
33
+ } as const satisfies MultisigSimulation.Rpc
34
+
35
+ describe('fromRpc', () => {
36
+ test('behavior: decodes root and nested configurations', () => {
37
+ expect(MultisigSimulation.fromRpc(rpc)).toMatchInlineSnapshot(`
38
+ {
39
+ "account": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
40
+ "approvals": [
41
+ {
42
+ "keyData": "0x0102030405",
43
+ "keyType": "webAuthn",
44
+ "owner": "0x1111111111111111111111111111111111111111",
45
+ "type": "primitive",
46
+ },
47
+ {
48
+ "spec": {
49
+ "account": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
50
+ "approvals": [
51
+ {
52
+ "keyData": "0x010203040506",
53
+ "keyType": "secp256k1",
54
+ "owner": "0x2222222222222222222222222222222222222222",
55
+ },
56
+ ],
57
+ "config": {
58
+ "owners": [
59
+ {
60
+ "owner": "0x2222222222222222222222222222222222222222",
61
+ "weight": 1,
62
+ },
63
+ ],
64
+ "salt": "0x2222222222222222222222222222222222222222222222222222222222222222",
65
+ "threshold": 1,
66
+ "version": 1n,
67
+ },
68
+ },
69
+ "type": "multisig",
70
+ },
71
+ ],
72
+ "config": {
73
+ "owners": [
74
+ {
75
+ "owner": "0x1111111111111111111111111111111111111111",
76
+ "weight": 1,
77
+ },
78
+ {
79
+ "owner": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
80
+ "weight": 1,
81
+ },
82
+ ],
83
+ "salt": "0x1111111111111111111111111111111111111111111111111111111111111111",
84
+ "threshold": 2,
85
+ "version": 0n,
86
+ },
87
+ }
88
+ `)
89
+ })
90
+
91
+ test('behavior: preserves the maximum uint64 configuration version', () => {
92
+ const config =
93
+ '0xf843a0000000000000000000000000000000000000000000000000000000000000000088ffffffffffffffff01d7d694111111111111111111111111111111111111111101' as const
94
+
95
+ expect(
96
+ MultisigSimulation.fromRpc({ ...rpc, approvals: [], config }).config
97
+ .version,
98
+ ).toMatchInlineSnapshot(`18446744073709551615n`)
99
+ })
100
+
101
+ test('error: rejects excess root approvals', () => {
102
+ expect(() =>
103
+ MultisigSimulation.fromRpc({
104
+ ...rpc,
105
+ approvals: Array.from({ length: 9 }, () => rpc.approvals[0]),
106
+ }),
107
+ ).toThrowErrorMatchingInlineSnapshot(
108
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: approval count exceeds 8.]`,
109
+ )
110
+ })
111
+
112
+ test('error: rejects excess nested approvals', () => {
113
+ expect(() =>
114
+ MultisigSimulation.fromRpc({
115
+ ...rpc,
116
+ approvals: [
117
+ {
118
+ ...rpc.approvals[1],
119
+ spec: {
120
+ ...rpc.approvals[1].spec,
121
+ approvals: Array.from(
122
+ { length: 9 },
123
+ () => rpc.approvals[1].spec.approvals[0],
124
+ ),
125
+ },
126
+ },
127
+ ],
128
+ }),
129
+ ).toThrowErrorMatchingInlineSnapshot(
130
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: approval count exceeds 8.]`,
131
+ )
132
+ })
133
+
134
+ test('error: rejects trailing configuration bytes', () => {
135
+ expect(() =>
136
+ MultisigSimulation.fromRpc({ ...rpc, config: `${config}00` }),
137
+ ).toThrowErrorMatchingInlineSnapshot(
138
+ `[Rlp.TrailingBytesError: RLP payload encodes a single item, but \`1\` trailing byte remains.]`,
139
+ )
140
+ })
141
+
142
+ test('error: rejects malformed configuration RLP', () => {
143
+ expect(() =>
144
+ MultisigSimulation.fromRpc({ ...rpc, config: '0xf8' }),
145
+ ).toThrowErrorMatchingInlineSnapshot(
146
+ `[Cursor.PositionOutOfBoundsError: Position \`1\` is out of bounds (\`0 < position < 1\`).]`,
147
+ )
148
+ })
149
+
150
+ test('error: rejects a non-list configuration', () => {
151
+ expect(() =>
152
+ MultisigSimulation.fromRpc({ ...rpc, config: '0x01' }),
153
+ ).toThrowErrorMatchingInlineSnapshot(
154
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: invalid config encoding.]`,
155
+ )
156
+ })
157
+
158
+ test('error: rejects noncanonical configuration integers', () => {
159
+ const noncanonical = config
160
+ .replace('0xf852', '0xf853')
161
+ .replace('118002', '11810002') as `0x${string}`
162
+
163
+ expect(() =>
164
+ MultisigSimulation.fromRpc({ ...rpc, config: noncanonical }),
165
+ ).toThrowErrorMatchingInlineSnapshot(
166
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: invalid config encoding.]`,
167
+ )
168
+ })
169
+ })
170
+
171
+ describe('toRpc', () => {
172
+ test('behavior: encodes configurations and shims long key data', () => {
173
+ expect(MultisigSimulation.toRpc(MultisigSimulation.fromRpc(rpc)))
174
+ .toMatchInlineSnapshot(`
175
+ {
176
+ "account": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
177
+ "approvals": [
178
+ {
179
+ "keyData": "0x0005",
180
+ "keyType": "webAuthn",
181
+ "owner": "0x1111111111111111111111111111111111111111",
182
+ "type": "primitive",
183
+ },
184
+ {
185
+ "spec": {
186
+ "account": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
187
+ "approvals": [
188
+ {
189
+ "keyData": "0x0006",
190
+ "keyType": "secp256k1",
191
+ "owner": "0x2222222222222222222222222222222222222222",
192
+ },
193
+ ],
194
+ "config": "${nestedConfig}",
195
+ },
196
+ "type": "multisig",
197
+ },
198
+ ],
199
+ "config": "${config}",
200
+ }
201
+ `)
202
+ })
203
+
204
+ test('behavior: preserves short key data', () => {
205
+ const spec = MultisigSimulation.fromRpc({
206
+ ...rpc,
207
+ approvals: [{ ...rpc.approvals[0], keyData: '0x0102' }],
208
+ })
209
+
210
+ expect(MultisigSimulation.toRpc(spec).approvals).toMatchInlineSnapshot(`
211
+ [
212
+ {
213
+ "keyData": "0x0102",
214
+ "keyType": "webAuthn",
215
+ "owner": "0x1111111111111111111111111111111111111111",
216
+ "type": "primitive",
217
+ },
218
+ ]
219
+ `)
220
+ })
221
+
222
+ test('behavior: encodes the maximum uint64 configuration version', () => {
223
+ const spec = MultisigSimulation.fromRpc(rpc)
224
+
225
+ expect(
226
+ MultisigSimulation.toRpc({
227
+ ...spec,
228
+ approvals: [],
229
+ config: MultisigConfig.from({
230
+ owners: [
231
+ {
232
+ owner: '0x1111111111111111111111111111111111111111',
233
+ weight: 1,
234
+ },
235
+ ],
236
+ threshold: 1,
237
+ version: MultisigConfig.maxVersion,
238
+ }),
239
+ }).config,
240
+ ).toMatchInlineSnapshot(
241
+ `"0xf843a0000000000000000000000000000000000000000000000000000000000000000088ffffffffffffffff01d7d694111111111111111111111111111111111111111101"`,
242
+ )
243
+ })
244
+
245
+ test('error: rejects excess root approvals', () => {
246
+ const spec = MultisigSimulation.fromRpc(rpc)
247
+
248
+ expect(() =>
249
+ MultisigSimulation.toRpc({
250
+ ...spec,
251
+ approvals: Array.from({ length: 9 }, () => spec.approvals[0]!),
252
+ }),
253
+ ).toThrowErrorMatchingInlineSnapshot(
254
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: approval count exceeds 8.]`,
255
+ )
256
+ })
257
+
258
+ test('error: rejects excess nested approvals', () => {
259
+ const spec = MultisigSimulation.fromRpc(rpc)
260
+ const nested = spec.approvals[1]!
261
+ if (nested.type !== 'multisig') throw new Error('unreachable')
262
+
263
+ expect(() =>
264
+ MultisigSimulation.toRpc({
265
+ ...spec,
266
+ approvals: [
267
+ {
268
+ ...nested,
269
+ spec: {
270
+ ...nested.spec,
271
+ approvals: Array.from(
272
+ { length: 9 },
273
+ () => nested.spec.approvals[0]!,
274
+ ),
275
+ },
276
+ },
277
+ ],
278
+ }),
279
+ ).toThrowErrorMatchingInlineSnapshot(
280
+ `[MultisigSimulation.InvalidSimulationError: Invalid multisig simulation: approval count exceeds 8.]`,
281
+ )
282
+ })
283
+ })
@@ -0,0 +1,266 @@
1
+ import * as Address from '../core/Address.js'
2
+ import * as Errors from '../core/Errors.js'
3
+ import * as Hex from '../core/Hex.js'
4
+ import type { Compute } from '../core/internal/types.js'
5
+ import * as Rlp from '../core/Rlp.js'
6
+ import * as MultisigConfig from './MultisigConfig.js'
7
+ import type * as SignatureEnvelope from './SignatureEnvelope.js'
8
+
9
+ /** Native multisig owner approval used for RPC simulation. */
10
+ export type Approval = NestedApproval | PrimitiveApproval
11
+
12
+ /** JSON-RPC native multisig owner approval used for RPC simulation. */
13
+ export type ApprovalRpc = NestedApprovalRpc | PrimitiveApproval
14
+
15
+ /** Nested native multisig owner approval used for RPC simulation. */
16
+ export type NestedApproval = {
17
+ /** Depth-2 multisig simulation spec. */
18
+ spec: NestedSpec
19
+ /** Approval type. */
20
+ type: 'multisig'
21
+ }
22
+
23
+ /** JSON-RPC nested native multisig owner approval used for RPC simulation. */
24
+ export type NestedApprovalRpc = {
25
+ /** Depth-2 multisig simulation spec. */
26
+ spec: NestedSpecRpc
27
+ /** Approval type. */
28
+ type: 'multisig'
29
+ }
30
+
31
+ /** Primitive approval in a depth-2 multisig simulation spec. */
32
+ export type NestedPrimitiveApproval = {
33
+ /** Optional signature-specific gas-estimation data. */
34
+ keyData?: Hex.Hex | undefined
35
+ /** Signature type to model. Omission uses a maximum-size WebAuthn signature. */
36
+ keyType?: SignatureEnvelope.Type | undefined
37
+ /** Configured owner address. */
38
+ owner: Address.Address
39
+ }
40
+
41
+ /** Depth-2 native multisig spec used for RPC simulation. */
42
+ export type NestedSpec = {
43
+ /** Nested multisig account. */
44
+ account: Address.Address
45
+ /** Primitive owner approvals to model. */
46
+ approvals: readonly NestedPrimitiveApproval[]
47
+ /** Complete applicable configuration. */
48
+ config: MultisigConfig.Config
49
+ }
50
+
51
+ /** JSON-RPC depth-2 native multisig spec used for RPC simulation. */
52
+ export type NestedSpecRpc = {
53
+ /** Nested multisig account. */
54
+ account: Address.Address
55
+ /** Primitive owner approvals to model. */
56
+ approvals: readonly NestedPrimitiveApproval[]
57
+ /** Canonical RLP-encoded applicable configuration. */
58
+ config: Hex.Hex
59
+ }
60
+
61
+ /** Primitive owner approval used for RPC simulation. */
62
+ export type PrimitiveApproval = {
63
+ /** Optional signature-specific gas-estimation data. */
64
+ keyData?: Hex.Hex | undefined
65
+ /** Signature type to model. Omission uses a maximum-size WebAuthn signature. */
66
+ keyType?: SignatureEnvelope.Type | undefined
67
+ /** Configured owner address. */
68
+ owner: Address.Address
69
+ /** Approval type. */
70
+ type: 'primitive'
71
+ }
72
+
73
+ /** JSON-RPC representation of a native multisig simulation spec. */
74
+ export type Rpc = Compute<{
75
+ /** Account authorized by this spec. */
76
+ account: Address.Address
77
+ /** Owner approvals to model. */
78
+ approvals: readonly ApprovalRpc[]
79
+ /** Canonical RLP-encoded applicable configuration. */
80
+ config: Hex.Hex
81
+ }>
82
+
83
+ /** Native multisig spec used to construct an RPC simulation signature. */
84
+ export type Spec = Compute<{
85
+ /** Account authorized by this spec. */
86
+ account: Address.Address
87
+ /** Owner approvals to model. */
88
+ approvals: readonly Approval[]
89
+ /** Complete applicable configuration. */
90
+ config: MultisigConfig.Config
91
+ }>
92
+
93
+ /**
94
+ * Converts a JSON-RPC multisig simulation spec to its domain representation.
95
+ *
96
+ * @example
97
+ * ```ts twoslash
98
+ * // @noErrors
99
+ * import { MultisigSimulation } from 'ox/tempo'
100
+ *
101
+ * const spec = MultisigSimulation.fromRpc(specRpc)
102
+ * ```
103
+ *
104
+ * @param spec - JSON-RPC multisig simulation spec.
105
+ * @returns The multisig simulation spec with decoded configurations.
106
+ */
107
+ export function fromRpc(spec: Rpc): Spec {
108
+ const { account, approvals, config } = spec
109
+ assertApprovalCount(approvals)
110
+ return {
111
+ account,
112
+ approvals: approvals.map((approval) => {
113
+ if (approval.type === 'primitive') return approval
114
+ assertApprovalCount(approval.spec.approvals)
115
+ return {
116
+ spec: {
117
+ account: approval.spec.account,
118
+ approvals: approval.spec.approvals,
119
+ config: deserializeConfig(approval.spec.config),
120
+ },
121
+ type: 'multisig',
122
+ }
123
+ }),
124
+ config: deserializeConfig(config),
125
+ }
126
+ }
127
+
128
+ export declare namespace fromRpc {
129
+ /** Error type for `fromRpc`. */
130
+ export type ErrorType =
131
+ | Hex.isEqual.ErrorType
132
+ | InvalidSimulationError
133
+ | MultisigConfig.assert.ErrorType
134
+ | Rlp.fromHex.ErrorType
135
+ | Rlp.toHex.ErrorType
136
+ | Errors.GlobalErrorType
137
+ }
138
+
139
+ /**
140
+ * Converts a multisig simulation spec to its JSON-RPC representation.
141
+ *
142
+ * @example
143
+ * ```ts twoslash
144
+ * // @noErrors
145
+ * import { MultisigSimulation } from 'ox/tempo'
146
+ *
147
+ * const specRpc = MultisigSimulation.toRpc(spec)
148
+ * ```
149
+ *
150
+ * @param spec - Multisig simulation spec.
151
+ * @returns The JSON-RPC multisig simulation spec with encoded configurations.
152
+ */
153
+ export function toRpc(spec: Spec): Rpc {
154
+ const { account, approvals, config } = spec
155
+ assertApprovalCount(approvals)
156
+ return {
157
+ account,
158
+ approvals: approvals.map((approval) => {
159
+ if (approval.type === 'primitive')
160
+ return {
161
+ ...approval,
162
+ ...(typeof approval.keyData !== 'undefined'
163
+ ? { keyData: shimKeyData(approval.keyData) }
164
+ : {}),
165
+ }
166
+ assertApprovalCount(approval.spec.approvals)
167
+ return {
168
+ spec: {
169
+ account: approval.spec.account,
170
+ approvals: approval.spec.approvals.map((approval) => ({
171
+ ...approval,
172
+ ...(typeof approval.keyData !== 'undefined'
173
+ ? { keyData: shimKeyData(approval.keyData) }
174
+ : {}),
175
+ })),
176
+ config: serializeConfig(approval.spec.config),
177
+ },
178
+ type: 'multisig',
179
+ }
180
+ }),
181
+ config: serializeConfig(config),
182
+ }
183
+ }
184
+
185
+ export declare namespace toRpc {
186
+ /** Error type for `toRpc`. */
187
+ export type ErrorType =
188
+ | Hex.fromNumber.ErrorType
189
+ | InvalidSimulationError
190
+ | MultisigConfig.assert.ErrorType
191
+ | Rlp.fromHex.ErrorType
192
+ | Errors.GlobalErrorType
193
+ }
194
+
195
+ /** @internal */
196
+ function assertApprovalCount(approvals: readonly unknown[]) {
197
+ if (approvals.length > MultisigConfig.maxSignatures)
198
+ throw new InvalidSimulationError({
199
+ reason: `approval count exceeds ${MultisigConfig.maxSignatures}`,
200
+ })
201
+ }
202
+
203
+ /** @internal */
204
+ function deserializeConfig(config: Hex.Hex): MultisigConfig.Config {
205
+ const tuple = Rlp.toHex(config)
206
+ if (!Array.isArray(tuple) || tuple.length !== 4)
207
+ throw new InvalidSimulationError({ reason: 'invalid config encoding' })
208
+ const [salt, version, threshold, owners] = tuple
209
+ if (
210
+ Array.isArray(salt) ||
211
+ Hex.size(salt) !== 32 ||
212
+ Array.isArray(version) ||
213
+ Hex.size(version) > 8 ||
214
+ (version !== '0x' && Hex.slice(version, 0, 1) === '0x00') ||
215
+ Array.isArray(threshold) ||
216
+ Hex.size(threshold) > 1 ||
217
+ !Array.isArray(owners) ||
218
+ owners.some(
219
+ (owner) =>
220
+ !Array.isArray(owner) ||
221
+ owner.length !== 2 ||
222
+ owner.some(Array.isArray) ||
223
+ !Address.validate(owner[0]) ||
224
+ Hex.size(owner[1] as Hex.Hex) > 1,
225
+ )
226
+ )
227
+ throw new InvalidSimulationError({ reason: 'invalid config encoding' })
228
+ const value = MultisigConfig.fromTuple(
229
+ tuple as unknown as MultisigConfig.Tuple,
230
+ )
231
+ MultisigConfig.assert(value)
232
+ if (!Hex.isEqual(config, serializeConfig(value)))
233
+ throw new InvalidSimulationError({ reason: 'noncanonical config encoding' })
234
+ return value
235
+ }
236
+
237
+ /** @internal */
238
+ function serializeConfig(config: MultisigConfig.Input): Hex.Hex {
239
+ return Rlp.fromHex(MultisigConfig.toTuple(config))
240
+ }
241
+
242
+ /**
243
+ * Shims long key data into the length hint accepted by Tempo's gas estimator.
244
+ * @internal
245
+ */
246
+ function shimKeyData(data: Hex.Hex): Hex.Hex {
247
+ const size = Hex.size(data)
248
+ if (size <= 4) return data
249
+ return Hex.fromNumber(size, { size: 2 })
250
+ }
251
+
252
+ /** Thrown when a native multisig simulation spec is invalid. */
253
+ export class InvalidSimulationError extends Errors.BaseError {
254
+ override readonly name = 'MultisigSimulation.InvalidSimulationError'
255
+ constructor(options: InvalidSimulationError.Options) {
256
+ super(`Invalid multisig simulation: ${options.reason}.`)
257
+ }
258
+ }
259
+
260
+ export declare namespace InvalidSimulationError {
261
+ /** Error construction options. */
262
+ export type Options = {
263
+ /** Validation failure. */
264
+ reason: string
265
+ }
266
+ }
@@ -0,0 +1,91 @@
1
+ import type { Provider } from 'ox'
2
+ import type {
3
+ KeyAuthorization,
4
+ MultisigConfig,
5
+ MultisigOperation,
6
+ MultisigSimulation,
7
+ RpcSchemaTempo,
8
+ } from 'ox/tempo'
9
+ import { expectTypeOf, test } from 'vp/test'
10
+ import type * as Address from '../core/Address.js'
11
+ import type * as Hex from '../core/Hex.js'
12
+
13
+ declare const provider: Provider.Provider<{ schema: RpcSchemaTempo.Multisig }>
14
+ declare const tempoProvider: Provider.Provider<{
15
+ schema: RpcSchemaTempo.Tempo
16
+ }>
17
+ declare const address: Address.Address
18
+ declare const hash: Hex.Hex
19
+ declare const keyAuthorization: KeyAuthorization.Rpc
20
+ declare const multisigSimulation: MultisigSimulation.Rpc
21
+ declare const serializedTransaction: Hex.Hex
22
+ declare const signature: Hex.Hex
23
+
24
+ test('multisig provider methods', () => {
25
+ expectTypeOf(
26
+ provider.request({
27
+ method: 'multisig_approveKeyAuthorization',
28
+ params: [{ keyAuthorization }],
29
+ }),
30
+ ).resolves.toEqualTypeOf<MultisigOperation.KeyAuthorizationRpc>()
31
+
32
+ expectTypeOf(
33
+ provider.request({
34
+ method: 'multisig_approveKeyAuthorization',
35
+ params: [{ hash, signature }],
36
+ }),
37
+ ).resolves.toEqualTypeOf<MultisigOperation.KeyAuthorizationRpc>()
38
+
39
+ expectTypeOf(
40
+ provider.request({
41
+ method: 'multisig_approveRawTransaction',
42
+ params: [serializedTransaction],
43
+ }),
44
+ ).resolves.toEqualTypeOf<Hex.Hex>()
45
+
46
+ expectTypeOf(
47
+ provider.request({
48
+ method: 'multisig_approveRawTransactionSync',
49
+ params: [serializedTransaction],
50
+ }),
51
+ ).resolves.toEqualTypeOf<MultisigOperation.TransactionRpc>()
52
+
53
+ void provider.request({
54
+ method: 'multisig_approveRawTransactionSync',
55
+ params: [serializedTransaction, 30_000],
56
+ })
57
+
58
+ expectTypeOf(
59
+ provider.request({
60
+ method: 'multisig_getConfig',
61
+ params: [{ address }],
62
+ }),
63
+ ).resolves.toEqualTypeOf<MultisigConfig.Rpc | null>()
64
+
65
+ expectTypeOf(
66
+ provider.request({
67
+ method: 'multisig_getOperation',
68
+ params: [hash],
69
+ }),
70
+ ).resolves.toEqualTypeOf<MultisigOperation.Rpc | null>()
71
+ })
72
+
73
+ test('tempo simulation accepts multisig specs', () => {
74
+ void tempoProvider.request({
75
+ method: 'tempo_simulateV1',
76
+ params: [
77
+ {
78
+ blockStateCalls: [
79
+ {
80
+ calls: [
81
+ {
82
+ multisigSimulation,
83
+ },
84
+ ],
85
+ },
86
+ ],
87
+ },
88
+ 'latest',
89
+ ],
90
+ })
91
+ })