tempo.ts 0.11.1 → 0.12.1

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 +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +3 -13
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/chains.d.ts +0 -73
  75. package/dist/chains.d.ts.map +0 -1
  76. package/dist/chains.js +0 -51
  77. package/dist/chains.js.map +0 -1
  78. package/dist/viem/Abis.d.ts +0 -2649
  79. package/dist/viem/Abis.d.ts.map +0 -1
  80. package/dist/viem/Abis.js +0 -1677
  81. package/dist/viem/Abis.js.map +0 -1
  82. package/dist/viem/Account.d.ts +0 -244
  83. package/dist/viem/Account.d.ts.map +0 -1
  84. package/dist/viem/Account.js +0 -382
  85. package/dist/viem/Account.js.map +0 -1
  86. package/dist/viem/Actions/account.d.ts +0 -40
  87. package/dist/viem/Actions/account.d.ts.map +0 -1
  88. package/dist/viem/Actions/account.js +0 -86
  89. package/dist/viem/Actions/account.js.map +0 -1
  90. package/dist/viem/Actions/amm.d.ts +0 -1991
  91. package/dist/viem/Actions/amm.d.ts.map +0 -1
  92. package/dist/viem/Actions/amm.js +0 -814
  93. package/dist/viem/Actions/amm.js.map +0 -1
  94. package/dist/viem/Actions/dex.d.ts +0 -3900
  95. package/dist/viem/Actions/dex.d.ts.map +0 -1
  96. package/dist/viem/Actions/dex.js +0 -1414
  97. package/dist/viem/Actions/dex.js.map +0 -1
  98. package/dist/viem/Actions/faucet.d.ts +0 -69
  99. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  100. package/dist/viem/Actions/faucet.js +0 -73
  101. package/dist/viem/Actions/faucet.js.map +0 -1
  102. package/dist/viem/Actions/fee.d.ts +0 -360
  103. package/dist/viem/Actions/fee.d.ts.map +0 -1
  104. package/dist/viem/Actions/fee.js +0 -237
  105. package/dist/viem/Actions/fee.js.map +0 -1
  106. package/dist/viem/Actions/index.d.ts +0 -10
  107. package/dist/viem/Actions/index.d.ts.map +0 -1
  108. package/dist/viem/Actions/index.js +0 -10
  109. package/dist/viem/Actions/index.js.map +0 -1
  110. package/dist/viem/Actions/nonce.d.ts +0 -257
  111. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  112. package/dist/viem/Actions/nonce.js +0 -228
  113. package/dist/viem/Actions/nonce.js.map +0 -1
  114. package/dist/viem/Actions/policy.d.ts +0 -1680
  115. package/dist/viem/Actions/policy.d.ts.map +0 -1
  116. package/dist/viem/Actions/policy.js +0 -875
  117. package/dist/viem/Actions/policy.js.map +0 -1
  118. package/dist/viem/Actions/reward.d.ts +0 -2422
  119. package/dist/viem/Actions/reward.d.ts.map +0 -1
  120. package/dist/viem/Actions/reward.js +0 -651
  121. package/dist/viem/Actions/reward.js.map +0 -1
  122. package/dist/viem/Actions/token.d.ts +0 -16007
  123. package/dist/viem/Actions/token.d.ts.map +0 -1
  124. package/dist/viem/Actions/token.js +0 -2936
  125. package/dist/viem/Actions/token.js.map +0 -1
  126. package/dist/viem/Addresses.d.ts +0 -9
  127. package/dist/viem/Addresses.d.ts.map +0 -1
  128. package/dist/viem/Addresses.js +0 -9
  129. package/dist/viem/Addresses.js.map +0 -1
  130. package/dist/viem/Chain.d.ts +0 -451
  131. package/dist/viem/Chain.d.ts.map +0 -1
  132. package/dist/viem/Chain.js +0 -96
  133. package/dist/viem/Chain.js.map +0 -1
  134. package/dist/viem/Decorator.d.ts +0 -2783
  135. package/dist/viem/Decorator.d.ts.map +0 -1
  136. package/dist/viem/Decorator.js +0 -137
  137. package/dist/viem/Decorator.js.map +0 -1
  138. package/dist/viem/Formatters.d.ts +0 -10
  139. package/dist/viem/Formatters.d.ts.map +0 -1
  140. package/dist/viem/Formatters.js +0 -104
  141. package/dist/viem/Formatters.js.map +0 -1
  142. package/dist/viem/P256.d.ts +0 -2
  143. package/dist/viem/P256.d.ts.map +0 -1
  144. package/dist/viem/P256.js +0 -2
  145. package/dist/viem/P256.js.map +0 -1
  146. package/dist/viem/Secp256k1.d.ts +0 -2
  147. package/dist/viem/Secp256k1.d.ts.map +0 -1
  148. package/dist/viem/Secp256k1.js +0 -2
  149. package/dist/viem/Secp256k1.js.map +0 -1
  150. package/dist/viem/Storage.d.ts +0 -24
  151. package/dist/viem/Storage.d.ts.map +0 -1
  152. package/dist/viem/Storage.js +0 -68
  153. package/dist/viem/Storage.js.map +0 -1
  154. package/dist/viem/TokenIds.d.ts +0 -2
  155. package/dist/viem/TokenIds.d.ts.map +0 -1
  156. package/dist/viem/TokenIds.js +0 -2
  157. package/dist/viem/TokenIds.js.map +0 -1
  158. package/dist/viem/Transaction.d.ts +0 -76
  159. package/dist/viem/Transaction.d.ts.map +0 -1
  160. package/dist/viem/Transaction.js +0 -176
  161. package/dist/viem/Transaction.js.map +0 -1
  162. package/dist/viem/Transport.d.ts +0 -33
  163. package/dist/viem/Transport.d.ts.map +0 -1
  164. package/dist/viem/Transport.js +0 -138
  165. package/dist/viem/Transport.js.map +0 -1
  166. package/dist/viem/WebAuthnP256.d.ts +0 -82
  167. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  168. package/dist/viem/WebAuthnP256.js +0 -97
  169. package/dist/viem/WebAuthnP256.js.map +0 -1
  170. package/dist/viem/WebCryptoP256.d.ts +0 -2
  171. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  172. package/dist/viem/WebCryptoP256.js +0 -2
  173. package/dist/viem/WebCryptoP256.js.map +0 -1
  174. package/dist/viem/index.d.ts +0 -26
  175. package/dist/viem/index.d.ts.map +0 -1
  176. package/dist/viem/index.js +0 -17
  177. package/dist/viem/index.js.map +0 -1
  178. package/dist/viem/internal/types.d.ts +0 -20
  179. package/dist/viem/internal/types.d.ts.map +0 -1
  180. package/dist/viem/internal/types.js +0 -2
  181. package/dist/viem/internal/types.js.map +0 -1
  182. package/dist/viem/internal/utils.d.ts +0 -14
  183. package/dist/viem/internal/utils.d.ts.map +0 -1
  184. package/dist/viem/internal/utils.js +0 -33
  185. package/dist/viem/internal/utils.js.map +0 -1
  186. package/src/chains.ts +0 -54
  187. package/src/viem/Abis.ts +0 -1688
  188. package/src/viem/Account.test.ts +0 -444
  189. package/src/viem/Account.ts +0 -601
  190. package/src/viem/Actions/account.test.ts +0 -414
  191. package/src/viem/Actions/account.ts +0 -106
  192. package/src/viem/Actions/amm.test.ts +0 -381
  193. package/src/viem/Actions/amm.ts +0 -1227
  194. package/src/viem/Actions/dex.test.ts +0 -1549
  195. package/src/viem/Actions/dex.ts +0 -2150
  196. package/src/viem/Actions/faucet.ts +0 -121
  197. package/src/viem/Actions/fee.test.ts +0 -259
  198. package/src/viem/Actions/fee.ts +0 -372
  199. package/src/viem/Actions/index.ts +0 -9
  200. package/src/viem/Actions/nonce.test.ts +0 -206
  201. package/src/viem/Actions/nonce.ts +0 -347
  202. package/src/viem/Actions/policy.test.ts +0 -534
  203. package/src/viem/Actions/policy.ts +0 -1335
  204. package/src/viem/Actions/reward.test.ts +0 -434
  205. package/src/viem/Actions/reward.ts +0 -944
  206. package/src/viem/Actions/token.test.ts +0 -3029
  207. package/src/viem/Actions/token.ts +0 -4458
  208. package/src/viem/Addresses.ts +0 -9
  209. package/src/viem/Chain.bench-d.ts +0 -12
  210. package/src/viem/Chain.test.ts +0 -168
  211. package/src/viem/Chain.ts +0 -157
  212. package/src/viem/Decorator.bench-d.ts +0 -11
  213. package/src/viem/Decorator.test.ts +0 -39
  214. package/src/viem/Decorator.ts +0 -3179
  215. package/src/viem/Formatters.ts +0 -164
  216. package/src/viem/P256.ts +0 -1
  217. package/src/viem/Secp256k1.ts +0 -1
  218. package/src/viem/Storage.ts +0 -110
  219. package/src/viem/TokenIds.ts +0 -1
  220. package/src/viem/Transaction.ts +0 -382
  221. package/src/viem/Transport.ts +0 -191
  222. package/src/viem/WebAuthnP256.ts +0 -146
  223. package/src/viem/WebCryptoP256.ts +0 -1
  224. package/src/viem/e2e.test.ts +0 -1602
  225. package/src/viem/index.ts +0 -30
  226. package/src/viem/internal/types.ts +0 -69
  227. package/src/viem/internal/utils.ts +0 -58
  228. package/src/wagmi/internal/types.ts +0 -16
@@ -1,414 +0,0 @@
1
- import { Hex, P256, Secp256k1, WebCryptoP256 } from 'ox'
2
- import { verifyMessage, verifyTypedData } from 'viem/actions'
3
- import { describe, expect, test } from 'vitest'
4
- import { client as baseClient } from '../../../test/viem/config.js'
5
- import * as Account from '../Account.js'
6
- import { decorator as tempoActions } from '../Decorator.js'
7
- import * as actions from './account.js'
8
-
9
- const client = baseClient.extend(tempoActions())
10
-
11
- describe('verifyHash', () => {
12
- test('secp256k1: default signature', async () => {
13
- const privateKey = Secp256k1.randomPrivateKey()
14
- const account = Account.fromSecp256k1(privateKey)
15
-
16
- const hash = Hex.random(32)
17
- const signature = await account.sign({ hash })
18
-
19
- const valid = await actions.verifyHash(client, {
20
- address: account.address,
21
- hash,
22
- signature,
23
- })
24
-
25
- expect(valid).toBe(true)
26
- })
27
-
28
- test('secp256k1: without address (recovers from signature)', async () => {
29
- const privateKey = Secp256k1.randomPrivateKey()
30
- const account = Account.fromSecp256k1(privateKey)
31
-
32
- const hash = Hex.random(32)
33
- const signature = await account.sign({ hash })
34
-
35
- const valid = await actions.verifyHash(client, {
36
- hash,
37
- signature,
38
- })
39
-
40
- expect(valid).toBe(true)
41
- })
42
-
43
- test('secp256k1: invalid signature returns false', async () => {
44
- const privateKey = Secp256k1.randomPrivateKey()
45
- const account = Account.fromSecp256k1(privateKey)
46
-
47
- const hash = Hex.random(32)
48
- const wrongHash = Hex.random(32)
49
- const signature = await account.sign({ hash })
50
-
51
- const valid = await actions.verifyHash(client, {
52
- address: account.address,
53
- hash: wrongHash,
54
- signature,
55
- })
56
-
57
- expect(valid).toBe(false)
58
- })
59
-
60
- test('p256: default signature', async () => {
61
- const privateKey = P256.randomPrivateKey()
62
- const account = Account.fromP256(privateKey)
63
-
64
- const hash = Hex.random(32)
65
- const signature = await account.sign({ hash })
66
-
67
- const valid = await actions.verifyHash(client, {
68
- address: account.address,
69
- hash,
70
- signature,
71
- })
72
-
73
- expect(valid).toBe(true)
74
- })
75
-
76
- test('p256: invalid signature returns false', async () => {
77
- const privateKey = P256.randomPrivateKey()
78
- const account = Account.fromP256(privateKey)
79
-
80
- const hash = Hex.random(32)
81
- const wrongHash = Hex.random(32)
82
- const signature = await account.sign({ hash })
83
-
84
- const valid = await actions.verifyHash(client, {
85
- address: account.address,
86
- hash: wrongHash,
87
- signature,
88
- })
89
-
90
- expect(valid).toBe(false)
91
- })
92
-
93
- test('webCrypto p256: default signature', async () => {
94
- const keyPair = await WebCryptoP256.createKeyPair()
95
- const account = Account.fromWebCryptoP256(keyPair)
96
-
97
- const hash = Hex.random(32)
98
- const signature = await account.sign({ hash })
99
-
100
- const valid = await actions.verifyHash(client, {
101
- address: account.address,
102
- hash,
103
- signature,
104
- })
105
-
106
- expect(valid).toBe(true)
107
- })
108
-
109
- test('webCrypto p256: invalid signature returns false', async () => {
110
- const keyPair = await WebCryptoP256.createKeyPair()
111
- const account = Account.fromWebCryptoP256(keyPair)
112
-
113
- const hash = Hex.random(32)
114
- const wrongHash = Hex.random(32)
115
- const signature = await account.sign({ hash })
116
-
117
- const valid = await actions.verifyHash(client, {
118
- address: account.address,
119
- hash: wrongHash,
120
- signature,
121
- })
122
-
123
- expect(valid).toBe(false)
124
- })
125
-
126
- test('headless webAuthn: default signature', async () => {
127
- const privateKey = P256.randomPrivateKey()
128
- const account = Account.fromHeadlessWebAuthn(privateKey, {
129
- rpId: 'example.com',
130
- origin: 'https://example.com',
131
- })
132
-
133
- const hash = Hex.random(32)
134
- const signature = await account.sign({ hash })
135
-
136
- const valid = await actions.verifyHash(client, {
137
- address: account.address,
138
- hash,
139
- signature,
140
- })
141
-
142
- expect(valid).toBe(true)
143
- })
144
-
145
- test('headless webAuthn: invalid signature returns false', async () => {
146
- const privateKey = P256.randomPrivateKey()
147
- const account = Account.fromHeadlessWebAuthn(privateKey, {
148
- rpId: 'example.com',
149
- origin: 'https://example.com',
150
- })
151
-
152
- const hash = Hex.random(32)
153
- const wrongHash = Hex.random(32)
154
- const signature = await account.sign({ hash })
155
-
156
- const valid = await actions.verifyHash(client, {
157
- address: account.address,
158
- hash: wrongHash,
159
- signature,
160
- })
161
-
162
- expect(valid).toBe(false)
163
- })
164
-
165
- test('behavior: signature from wrong account returns false', async () => {
166
- const privateKey1 = Secp256k1.randomPrivateKey()
167
- const account1 = Account.fromSecp256k1(privateKey1)
168
-
169
- const privateKey2 = Secp256k1.randomPrivateKey()
170
- const account2 = Account.fromSecp256k1(privateKey2)
171
-
172
- const hash = Hex.random(32)
173
- const signature = await account1.sign({ hash })
174
-
175
- // Try to verify with wrong address
176
- const valid = await actions.verifyHash(client, {
177
- address: account2.address,
178
- hash,
179
- signature,
180
- })
181
-
182
- expect(valid).toBe(false)
183
- })
184
-
185
- test('as inherited: verifyMessage with secp256k1', async () => {
186
- const privateKey = Secp256k1.randomPrivateKey()
187
- const account = Account.fromSecp256k1(privateKey)
188
-
189
- const message = 'Hello, World!'
190
- const signature = await account.signMessage({ message })
191
-
192
- const valid = await verifyMessage(client, {
193
- address: account.address,
194
- message,
195
- signature,
196
- })
197
-
198
- expect(valid).toBe(true)
199
- })
200
-
201
- test('as inherited: verifyMessage with p256', async () => {
202
- const privateKey = P256.randomPrivateKey()
203
- const account = Account.fromP256(privateKey)
204
-
205
- const message = 'Hello, P256!'
206
- const signature = await account.signMessage({ message })
207
-
208
- const valid = await verifyMessage(client, {
209
- address: account.address,
210
- message,
211
- signature,
212
- })
213
-
214
- expect(valid).toBe(true)
215
- })
216
-
217
- test('as inherited: verifyMessage with webCrypto p256', async () => {
218
- const keyPair = await WebCryptoP256.createKeyPair()
219
- const account = Account.fromWebCryptoP256(keyPair)
220
-
221
- const message = 'Hello, WebCrypto!'
222
- const signature = await account.signMessage({ message })
223
-
224
- const valid = await verifyMessage(client, {
225
- address: account.address,
226
- message,
227
- signature,
228
- })
229
-
230
- expect(valid).toBe(true)
231
- })
232
-
233
- test('as inherited: verifyMessage with headless webAuthn', async () => {
234
- const privateKey = P256.randomPrivateKey()
235
- const account = Account.fromHeadlessWebAuthn(privateKey, {
236
- rpId: 'example.com',
237
- origin: 'https://example.com',
238
- })
239
-
240
- const message = 'Hello, WebAuthn!'
241
- const signature = await account.signMessage({ message })
242
-
243
- const valid = await verifyMessage(client, {
244
- address: account.address,
245
- message,
246
- signature,
247
- })
248
-
249
- expect(valid).toBe(true)
250
- })
251
-
252
- test('as inherited: verifyTypedData with secp256k1', async () => {
253
- const privateKey = Secp256k1.randomPrivateKey()
254
- const account = Account.fromSecp256k1(privateKey)
255
-
256
- const domain = {
257
- name: 'Test App',
258
- version: '1',
259
- chainId: 1,
260
- }
261
-
262
- const types = {
263
- Person: [
264
- { name: 'name', type: 'string' },
265
- { name: 'wallet', type: 'address' },
266
- ],
267
- }
268
-
269
- const message = {
270
- name: 'Alice',
271
- wallet: '0x0000000000000000000000000000000000000000',
272
- }
273
-
274
- const signature = await account.signTypedData({
275
- domain,
276
- types,
277
- primaryType: 'Person',
278
- message,
279
- })
280
-
281
- const valid = await verifyTypedData(client, {
282
- address: account.address,
283
- domain,
284
- types,
285
- primaryType: 'Person',
286
- message,
287
- signature,
288
- })
289
-
290
- expect(valid).toBe(true)
291
- })
292
-
293
- test('as inherited: verifyTypedData with p256', async () => {
294
- const privateKey = P256.randomPrivateKey()
295
- const account = Account.fromP256(privateKey)
296
-
297
- const domain = {
298
- name: 'P256 App',
299
- version: '1',
300
- chainId: 1,
301
- }
302
-
303
- const types = {
304
- Message: [{ name: 'content', type: 'string' }],
305
- }
306
-
307
- const message = {
308
- content: 'Hello from P256!',
309
- }
310
-
311
- const signature = await account.signTypedData({
312
- domain,
313
- types,
314
- primaryType: 'Message',
315
- message,
316
- })
317
-
318
- const valid = await verifyTypedData(client, {
319
- address: account.address,
320
- domain,
321
- types,
322
- primaryType: 'Message',
323
- message,
324
- signature,
325
- })
326
-
327
- expect(valid).toBe(true)
328
- })
329
-
330
- test('as inherited: verifyTypedData with webCrypto p256', async () => {
331
- const keyPair = await WebCryptoP256.createKeyPair()
332
- const account = Account.fromWebCryptoP256(keyPair)
333
-
334
- const domain = {
335
- name: 'WebCrypto App',
336
- version: '1',
337
- chainId: 1,
338
- }
339
-
340
- const types = {
341
- Data: [
342
- { name: 'value', type: 'uint256' },
343
- { name: 'label', type: 'string' },
344
- ],
345
- }
346
-
347
- const message = {
348
- value: 42n,
349
- label: 'test',
350
- }
351
-
352
- const signature = await account.signTypedData({
353
- domain,
354
- types,
355
- primaryType: 'Data',
356
- message,
357
- })
358
-
359
- const valid = await verifyTypedData(client, {
360
- address: account.address,
361
- domain,
362
- types,
363
- primaryType: 'Data',
364
- message,
365
- signature,
366
- })
367
-
368
- expect(valid).toBe(true)
369
- })
370
-
371
- test('as inherited: verifyTypedData with headless webAuthn', async () => {
372
- const privateKey = P256.randomPrivateKey()
373
- const account = Account.fromHeadlessWebAuthn(privateKey, {
374
- rpId: 'example.com',
375
- origin: 'https://example.com',
376
- })
377
-
378
- const domain = {
379
- name: 'WebAuthn App',
380
- version: '1',
381
- chainId: 1,
382
- }
383
-
384
- const types = {
385
- Auth: [
386
- { name: 'user', type: 'address' },
387
- { name: 'action', type: 'string' },
388
- ],
389
- }
390
-
391
- const message = {
392
- user: account.address,
393
- action: 'login',
394
- }
395
-
396
- const signature = await account.signTypedData({
397
- domain,
398
- types,
399
- primaryType: 'Auth',
400
- message,
401
- })
402
-
403
- const valid = await verifyTypedData(client, {
404
- address: account.address,
405
- domain,
406
- types,
407
- primaryType: 'Auth',
408
- message,
409
- signature,
410
- })
411
-
412
- expect(valid).toBe(true)
413
- })
414
- })
@@ -1,106 +0,0 @@
1
- import { Secp256k1 } from 'ox'
2
- import * as Hex from 'ox/Hex'
3
- import * as P256 from 'ox/P256'
4
- import { SignatureEnvelope } from 'ox/tempo'
5
- import * as WebAuthnP256 from 'ox/WebAuthnP256'
6
- import type { Chain, Client, Transport } from 'viem'
7
- import type { VerifyHashParameters, VerifyHashReturnType } from 'viem/actions'
8
- import { verifyHash as viem_verifyHash } from 'viem/actions'
9
- import { getAction } from 'viem/utils'
10
- import type { PartialBy } from '../../internal/types.js'
11
-
12
- /**
13
- * Verifies that a signature is valid for a given hash and address.
14
- * Supports multiple signature types: Secp256k1, P256, WebCrypto P256, and WebAuthn P256.
15
- *
16
- * @example
17
- * ```ts
18
- * import { createClient, http } from 'viem'
19
- * import { tempo } from 'tempo.ts/chains'
20
- * import { Actions, Account, P256 } from 'tempo.ts/viem'
21
- *
22
- * const client = createClient({
23
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
24
- * transport: http(),
25
- * })
26
- *
27
- * const privateKey = P256.randomPrivateKey()
28
- * const account = Account.fromP256(privateKey)
29
- *
30
- * const hash = '0x...'
31
- * const signature = await account.sign({ hash })
32
- *
33
- * const valid = await Actions.verifyHash(client, {
34
- * hash,
35
- * signature,
36
- * })
37
- * ```
38
- *
39
- * @param client - Client.
40
- * @param parameters - Parameters.
41
- * @returns Whether the signature is valid.
42
- */
43
- export async function verifyHash<chain extends Chain | undefined>(
44
- client: Client<Transport, chain>,
45
- parameters: verifyHash.Parameters,
46
- ): Promise<verifyHash.ReturnValue> {
47
- const { hash } = parameters
48
-
49
- const signature = (() => {
50
- const signature = parameters.signature
51
- if (Hex.validate(signature)) return signature
52
- if (typeof signature === 'object' && 'r' in signature && 's' in signature)
53
- return SignatureEnvelope.serialize({
54
- type: 'secp256k1',
55
- signature: {
56
- r: BigInt(signature.r),
57
- s: BigInt(signature.s),
58
- yParity: signature.yParity!,
59
- },
60
- })
61
- return Hex.fromBytes(signature)
62
- })()
63
-
64
- const [envelope, userAddress] = (() => {
65
- const envelope = SignatureEnvelope.from(signature)
66
- if (envelope.type === 'keychain')
67
- return [envelope.inner, envelope.userAddress]
68
- return [envelope, undefined]
69
- })()
70
-
71
- if (envelope.type === 'p256')
72
- return P256.verify({
73
- payload: hash,
74
- publicKey: envelope.publicKey,
75
- signature: envelope.signature,
76
- hash: envelope.prehash,
77
- })
78
- if (envelope.type === 'webAuthn')
79
- return WebAuthnP256.verify({
80
- challenge: hash,
81
- metadata: envelope.metadata,
82
- publicKey: envelope.publicKey,
83
- signature: envelope.signature,
84
- })
85
- if (envelope.type === 'keychain') throw new Error('not supported')
86
-
87
- const address =
88
- parameters.address ??
89
- userAddress ??
90
- Secp256k1.recoverAddress({
91
- payload: hash,
92
- signature: envelope.signature,
93
- })
94
-
95
- return await getAction(
96
- client,
97
- viem_verifyHash,
98
- 'verifyHash',
99
- )({ ...parameters, address } as never)
100
- }
101
-
102
- export declare namespace verifyHash {
103
- export type Parameters = PartialBy<VerifyHashParameters, 'address'>
104
-
105
- export type ReturnValue = VerifyHashReturnType
106
- }