tempo.ts 0.7.5 → 0.8.0

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 (147) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/chains.d.ts +6 -20
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +14 -15
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/KeyAuthorization.d.ts +356 -0
  7. package/dist/ox/KeyAuthorization.d.ts.map +1 -0
  8. package/dist/ox/KeyAuthorization.js +360 -0
  9. package/dist/ox/KeyAuthorization.js.map +1 -0
  10. package/dist/ox/SignatureEnvelope.d.ts +21 -6
  11. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  12. package/dist/ox/SignatureEnvelope.js +43 -3
  13. package/dist/ox/SignatureEnvelope.js.map +1 -1
  14. package/dist/ox/Transaction.d.ts +5 -1
  15. package/dist/ox/Transaction.d.ts.map +1 -1
  16. package/dist/ox/Transaction.js +5 -0
  17. package/dist/ox/Transaction.js.map +1 -1
  18. package/dist/ox/TransactionEnvelopeAA.d.ts +9 -0
  19. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  20. package/dist/ox/TransactionEnvelopeAA.js +17 -4
  21. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  22. package/dist/ox/TransactionRequest.d.ts +7 -1
  23. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  24. package/dist/ox/TransactionRequest.js +12 -0
  25. package/dist/ox/TransactionRequest.js.map +1 -1
  26. package/dist/ox/index.d.ts +1 -0
  27. package/dist/ox/index.d.ts.map +1 -1
  28. package/dist/ox/index.js +1 -0
  29. package/dist/ox/index.js.map +1 -1
  30. package/dist/prool/Instance.js +1 -1
  31. package/dist/prool/Instance.js.map +1 -1
  32. package/{src/prool/internal → dist/prool}/chain.json +4 -2
  33. package/dist/viem/Abis.d.ts +319 -6
  34. package/dist/viem/Abis.d.ts.map +1 -1
  35. package/dist/viem/Abis.js +199 -7
  36. package/dist/viem/Abis.js.map +1 -1
  37. package/dist/viem/Account.d.ts +103 -14
  38. package/dist/viem/Account.d.ts.map +1 -1
  39. package/dist/viem/Account.js +177 -23
  40. package/dist/viem/Account.js.map +1 -1
  41. package/dist/viem/Actions/account.d.ts.map +1 -1
  42. package/dist/viem/Actions/account.js +4 -5
  43. package/dist/viem/Actions/account.js.map +1 -1
  44. package/dist/viem/Actions/amm.d.ts +84 -32
  45. package/dist/viem/Actions/amm.d.ts.map +1 -1
  46. package/dist/viem/Actions/amm.js +12 -32
  47. package/dist/viem/Actions/amm.js.map +1 -1
  48. package/dist/viem/Actions/dex.d.ts +156 -4
  49. package/dist/viem/Actions/dex.d.ts.map +1 -1
  50. package/dist/viem/Actions/fee.d.ts +4 -0
  51. package/dist/viem/Actions/fee.d.ts.map +1 -1
  52. package/dist/viem/Actions/reward.d.ts +78 -0
  53. package/dist/viem/Actions/reward.d.ts.map +1 -1
  54. package/dist/viem/Actions/token.d.ts +585 -0
  55. package/dist/viem/Actions/token.d.ts.map +1 -1
  56. package/dist/viem/Actions/token.js +2 -2
  57. package/dist/viem/Actions/token.js.map +1 -1
  58. package/dist/viem/Addresses.d.ts +1 -1
  59. package/dist/viem/Addresses.d.ts.map +1 -1
  60. package/dist/viem/Addresses.js +1 -1
  61. package/dist/viem/Addresses.js.map +1 -1
  62. package/dist/viem/Chain.d.ts +35 -0
  63. package/dist/viem/Chain.d.ts.map +1 -1
  64. package/dist/viem/Chain.js +37 -0
  65. package/dist/viem/Chain.js.map +1 -1
  66. package/dist/viem/Decorator.d.ts +193 -16
  67. package/dist/viem/Decorator.d.ts.map +1 -1
  68. package/dist/viem/Decorator.js +7 -0
  69. package/dist/viem/Decorator.js.map +1 -1
  70. package/dist/viem/Formatters.d.ts.map +1 -1
  71. package/dist/viem/Formatters.js +8 -7
  72. package/dist/viem/Formatters.js.map +1 -1
  73. package/dist/viem/Storage.d.ts +1 -0
  74. package/dist/viem/Storage.d.ts.map +1 -1
  75. package/dist/viem/Storage.js +21 -0
  76. package/dist/viem/Storage.js.map +1 -1
  77. package/dist/viem/TokenIds.d.ts +1 -1
  78. package/dist/viem/TokenIds.d.ts.map +1 -1
  79. package/dist/viem/TokenIds.js +1 -1
  80. package/dist/viem/TokenIds.js.map +1 -1
  81. package/dist/viem/Transaction.d.ts +9 -1
  82. package/dist/viem/Transaction.d.ts.map +1 -1
  83. package/dist/viem/Transaction.js +2 -1
  84. package/dist/viem/Transaction.js.map +1 -1
  85. package/dist/viem/WebAuthnP256.d.ts +4 -1
  86. package/dist/viem/WebAuthnP256.d.ts.map +1 -1
  87. package/dist/viem/WebAuthnP256.js +3 -1
  88. package/dist/viem/WebAuthnP256.js.map +1 -1
  89. package/dist/wagmi/Actions/amm.d.ts +6 -16
  90. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  91. package/dist/wagmi/Actions/amm.js +6 -16
  92. package/dist/wagmi/Actions/amm.js.map +1 -1
  93. package/dist/wagmi/Connector.d.ts +25 -8
  94. package/dist/wagmi/Connector.d.ts.map +1 -1
  95. package/dist/wagmi/Connector.js +120 -27
  96. package/dist/wagmi/Connector.js.map +1 -1
  97. package/dist/wagmi/Hooks/amm.d.ts +6 -16
  98. package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
  99. package/dist/wagmi/Hooks/amm.js +6 -16
  100. package/dist/wagmi/Hooks/amm.js.map +1 -1
  101. package/package.json +3 -2
  102. package/src/chains.ts +14 -15
  103. package/src/ox/KeyAuthorization.test.ts +1332 -0
  104. package/src/ox/KeyAuthorization.ts +542 -0
  105. package/src/ox/SignatureEnvelope.test.ts +624 -0
  106. package/src/ox/SignatureEnvelope.ts +89 -9
  107. package/src/ox/Transaction.test.ts +214 -0
  108. package/src/ox/Transaction.ts +13 -1
  109. package/src/ox/TransactionEnvelopeAA.test.ts +164 -4
  110. package/src/ox/TransactionEnvelopeAA.ts +36 -3
  111. package/src/ox/TransactionRequest.ts +22 -1
  112. package/src/ox/e2e.test.ts +612 -5
  113. package/src/ox/index.ts +1 -0
  114. package/src/prool/Instance.ts +1 -1
  115. package/src/prool/chain.json +238 -0
  116. package/src/server/Handler.test.ts +20 -36
  117. package/src/viem/Abis.ts +200 -7
  118. package/src/viem/Account.test.ts +444 -0
  119. package/src/viem/Account.ts +355 -42
  120. package/src/viem/Actions/account.ts +3 -5
  121. package/src/viem/Actions/amm.test.ts +220 -1
  122. package/src/viem/Actions/amm.ts +12 -32
  123. package/src/viem/Actions/token.test.ts +8 -8
  124. package/src/viem/Actions/token.ts +2 -2
  125. package/src/viem/Addresses.ts +1 -1
  126. package/src/viem/Chain.test.ts +168 -0
  127. package/src/viem/Chain.ts +37 -1
  128. package/src/viem/Decorator.ts +214 -16
  129. package/src/viem/Formatters.ts +8 -7
  130. package/src/viem/Storage.ts +22 -0
  131. package/src/viem/TokenIds.ts +1 -1
  132. package/src/viem/Transaction.ts +14 -2
  133. package/src/viem/WebAuthnP256.ts +8 -2
  134. package/src/viem/e2e.test.ts +299 -96
  135. package/src/wagmi/Actions/amm.test.ts +93 -2
  136. package/src/wagmi/Actions/amm.ts +6 -16
  137. package/src/wagmi/Connector.test.ts +1 -1
  138. package/src/wagmi/Connector.ts +184 -54
  139. package/src/wagmi/Hooks/amm.test.ts +335 -0
  140. package/src/wagmi/Hooks/amm.ts +6 -16
  141. package/src/wagmi/Hooks/fee.test.ts +10 -4
  142. package/src/wagmi/Hooks/token.test.ts +0 -488
  143. package/dist/viem/internal/account.d.ts +0 -21
  144. package/dist/viem/internal/account.d.ts.map +0 -1
  145. package/dist/viem/internal/account.js +0 -61
  146. package/dist/viem/internal/account.js.map +0 -1
  147. package/src/viem/internal/account.ts +0 -89
@@ -0,0 +1,444 @@
1
+ import { Value, WebCryptoP256 } from 'ox'
2
+ import { describe, expect, test } from 'vitest'
3
+ import * as SignatureEnvelope from '../ox/SignatureEnvelope.js'
4
+ import * as Account from './Account.js'
5
+
6
+ const privateKey_secp256k1 =
7
+ '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
8
+ const privateKey_p256 =
9
+ '0x5c878151adef73f88b1c360d33e9bf9dd1b6e2e0e07bc555fc33cb8cf6bc9b28'
10
+
11
+ describe('fromSecp256k1', () => {
12
+ test('default', async () => {
13
+ const account = Account.fromSecp256k1(privateKey_secp256k1)
14
+ expect(account).toMatchInlineSnapshot(`
15
+ {
16
+ "address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
17
+ "assignKeyAuthorization": [Function],
18
+ "keyType": "secp256k1",
19
+ "publicKey": "0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5",
20
+ "sign": [Function],
21
+ "signAuthorization": [Function],
22
+ "signKeyAuthorization": [Function],
23
+ "signMessage": [Function],
24
+ "signTransaction": [Function],
25
+ "signTypedData": [Function],
26
+ "source": "root",
27
+ "storage": {
28
+ "getItem": [Function],
29
+ "removeItem": [Function],
30
+ "setItem": [Function],
31
+ },
32
+ "type": "local",
33
+ }
34
+ `)
35
+
36
+ const signature = await account.sign({
37
+ hash: '0xdeadbeef',
38
+ })
39
+ expect(signature).toMatchInlineSnapshot(
40
+ `"0xfa78c5905fb0b9d6066ef531f962a62bc6ef0d5eb59ecb134056d206f75aaed7780926ff2601a935c2c79707d9e1799948c9f19dcdde1e090e903b19a07923d01c"`,
41
+ )
42
+ expect(SignatureEnvelope.deserialize(signature)).toMatchInlineSnapshot(`
43
+ {
44
+ "signature": {
45
+ "r": 113291597329930009559670063131885256927775966057121513567941051428123344285399n,
46
+ "s": 54293712598725100598138577281441749550405991478212695085505730636505228583888n,
47
+ "yParity": 1,
48
+ },
49
+ "type": "secp256k1",
50
+ }
51
+ `)
52
+ })
53
+
54
+ test('behavior: access key', async () => {
55
+ const account = Account.fromSecp256k1(privateKey_secp256k1)
56
+ const access = Account.fromSecp256k1(
57
+ '0x06a952d58c24d287245276dd8b4272d82a921d27d90874a6c27a3bc19ff4bfde',
58
+ {
59
+ access: account,
60
+ },
61
+ )
62
+
63
+ const signature = await access.sign({
64
+ hash: '0xdeadbeef',
65
+ })
66
+ expect(signature).toMatchInlineSnapshot(
67
+ `"0x03f39Fd6e51aad88F6F4ce6aB8827279cffFb9226627c4025daa5c473942fd6282cfb7c07edb48a1764fb3c228fc094a715300e0e56fcf8a7849bb8bcc2938d8a041fdbce56d2b6c70aadbae6a0b70b4a1e98256161b"`,
68
+ )
69
+ expect(SignatureEnvelope.deserialize(signature)).toMatchInlineSnapshot(`
70
+ {
71
+ "inner": {
72
+ "signature": {
73
+ "r": 17986519448152736741806679848301503760738507672285374215138617395147700232421n,
74
+ "s": 50573419219106101097329274608677894804280434221354410855341207650465321473558n,
75
+ "yParity": 0,
76
+ },
77
+ "type": "secp256k1",
78
+ },
79
+ "type": "keychain",
80
+ "userAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
81
+ }
82
+ `)
83
+ })
84
+ })
85
+
86
+ describe('fromP256', () => {
87
+ test('default', async () => {
88
+ const account = Account.fromP256(privateKey_p256)
89
+ expect(account).toMatchInlineSnapshot(`
90
+ {
91
+ "address": "0xc3Cf8B814B729A1ad648b49fbBdED3767BCd35fd",
92
+ "assignKeyAuthorization": [Function],
93
+ "keyType": "p256",
94
+ "publicKey": "0x20fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c812240",
95
+ "sign": [Function],
96
+ "signAuthorization": [Function],
97
+ "signKeyAuthorization": [Function],
98
+ "signMessage": [Function],
99
+ "signTransaction": [Function],
100
+ "signTypedData": [Function],
101
+ "source": "root",
102
+ "storage": {
103
+ "getItem": [Function],
104
+ "removeItem": [Function],
105
+ "setItem": [Function],
106
+ },
107
+ "type": "local",
108
+ }
109
+ `)
110
+
111
+ const signature = await account.sign({
112
+ hash: '0xdeadbeef',
113
+ })
114
+ expect(signature).toMatchInlineSnapshot(
115
+ `"0x01daab749a3dea3f76c52ff0cfc86f0d433ecaf4d20f2ea327042bf5c15bccf847098dc3591fc68bf94d8db6d16cf326808dbf0f44d8e8373e8a7fcaf39b38281020fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c81224000"`,
116
+ )
117
+ })
118
+
119
+ test('behavior: access key', async () => {
120
+ const account = Account.fromP256(privateKey_p256)
121
+ const access = Account.fromP256(
122
+ '0x5c878151adef73f88b1c360d33e9bf9dd1b6e2e0e07bc555fc33cb8cf6bc9b28',
123
+ {
124
+ access: account,
125
+ },
126
+ )
127
+
128
+ const signature = await access.sign({
129
+ hash: '0xdeadbeef',
130
+ })
131
+ expect(signature).toMatchInlineSnapshot(
132
+ `"0x03c3Cf8B814B729A1ad648b49fbBdED3767BCd35fd01daab749a3dea3f76c52ff0cfc86f0d433ecaf4d20f2ea327042bf5c15bccf847098dc3591fc68bf94d8db6d16cf326808dbf0f44d8e8373e8a7fcaf39b38281020fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c81224000"`,
133
+ )
134
+ expect(SignatureEnvelope.deserialize(signature)).toMatchInlineSnapshot(`
135
+ {
136
+ "inner": {
137
+ "prehash": false,
138
+ "publicKey": {
139
+ "prefix": 4,
140
+ "x": 14922859167660714031319135249406228569331107293314503672038378501577989797848n,
141
+ "y": 57892587925019714505251703757706314187537979987563648366993255393643804566080n,
142
+ },
143
+ "signature": {
144
+ "r": 98907136600157604623356371387339224256063842362088951992859252568183251204167n,
145
+ "s": 4321289316702385668777418513388640777474210589895706234285069930616319387664n,
146
+ },
147
+ "type": "p256",
148
+ },
149
+ "type": "keychain",
150
+ "userAddress": "0xc3Cf8B814B729A1ad648b49fbBdED3767BCd35fd",
151
+ }
152
+ `)
153
+ })
154
+ })
155
+
156
+ describe('fromHeadlessWebAuthn', () => {
157
+ test('default', async () => {
158
+ const account = Account.fromHeadlessWebAuthn(privateKey_p256, {
159
+ rpId: 'localhost',
160
+ origin: 'http://localhost',
161
+ })
162
+ expect(account).toMatchInlineSnapshot(`
163
+ {
164
+ "address": "0xc3Cf8B814B729A1ad648b49fbBdED3767BCd35fd",
165
+ "assignKeyAuthorization": [Function],
166
+ "keyType": "webAuthn",
167
+ "publicKey": "0x20fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c812240",
168
+ "sign": [Function],
169
+ "signAuthorization": [Function],
170
+ "signKeyAuthorization": [Function],
171
+ "signMessage": [Function],
172
+ "signTransaction": [Function],
173
+ "signTypedData": [Function],
174
+ "source": "root",
175
+ "storage": {
176
+ "getItem": [Function],
177
+ "removeItem": [Function],
178
+ "setItem": [Function],
179
+ },
180
+ "type": "local",
181
+ }
182
+ `)
183
+
184
+ const signature = await account.sign({
185
+ hash: '0xdeadbeef',
186
+ })
187
+ expect(signature).toMatchInlineSnapshot(
188
+ `"0x0249960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d976305000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a223371322d3777222c226f726967696e223a22687474703a2f2f6c6f63616c686f7374222c2263726f73734f726967696e223a66616c73657d1b3346991a9ad1498e401dc0448e93d1bde113778d442f5bcafc44925cf3121961e9b1c21b054e54fe6c2eec0cd310c8535b7e7dd1f7dd7bf749e6d78154b48120fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c812240"`,
189
+ )
190
+ })
191
+
192
+ test('behavior: access key', async () => {
193
+ const account = Account.fromHeadlessWebAuthn(privateKey_p256, {
194
+ rpId: 'localhost',
195
+ origin: 'http://localhost',
196
+ })
197
+ const access = Account.fromHeadlessWebAuthn(privateKey_p256, {
198
+ access: account,
199
+ rpId: 'localhost',
200
+ origin: 'http://localhost',
201
+ })
202
+
203
+ const signature = await access.sign({
204
+ hash: '0xdeadbeef',
205
+ })
206
+ expect(signature).toMatchInlineSnapshot(
207
+ `"0x03c3Cf8B814B729A1ad648b49fbBdED3767BCd35fd0249960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d976305000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a223371322d3777222c226f726967696e223a22687474703a2f2f6c6f63616c686f7374222c2263726f73734f726967696e223a66616c73657d1b3346991a9ad1498e401dc0448e93d1bde113778d442f5bcafc44925cf3121961e9b1c21b054e54fe6c2eec0cd310c8535b7e7dd1f7dd7bf749e6d78154b48120fe09fa1af47a6b3b4e973040f0588a1c2c96df1ce78b10e50903566ad9b7d87ffe0b281b616196c2ccdb64cd51230d8dc1f1d258ca7e8cb33a63cf8c812240"`,
208
+ )
209
+ expect(SignatureEnvelope.deserialize(signature)).toMatchInlineSnapshot(`
210
+ {
211
+ "inner": {
212
+ "metadata": {
213
+ "authenticatorData": "0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000",
214
+ "clientDataJSON": "{"type":"webauthn.get","challenge":"3q2-7w","origin":"http://localhost","crossOrigin":false}",
215
+ },
216
+ "publicKey": {
217
+ "prefix": 4,
218
+ "x": 14922859167660714031319135249406228569331107293314503672038378501577989797848n,
219
+ "y": 57892587925019714505251703757706314187537979987563648366993255393643804566080n,
220
+ },
221
+ "signature": {
222
+ "r": 12303043361969813321008510595799352303777626167191077212436720864556362175001n,
223
+ "s": 44287248520848853208449965274039658906134850867725872574460252467151437608065n,
224
+ },
225
+ "type": "webAuthn",
226
+ },
227
+ "type": "keychain",
228
+ "userAddress": "0xc3Cf8B814B729A1ad648b49fbBdED3767BCd35fd",
229
+ }
230
+ `)
231
+ })
232
+ })
233
+
234
+ describe('fromWebCryptoP256', () => {
235
+ test('default', async () => {
236
+ const keyPair = await WebCryptoP256.createKeyPair()
237
+ const account = Account.fromWebCryptoP256(keyPair)
238
+ expect(account.keyType).toBe('p256')
239
+ })
240
+ })
241
+
242
+ describe('signKeyAuthorization', () => {
243
+ test('default', async () => {
244
+ const account = Account.fromSecp256k1(privateKey_secp256k1)
245
+ const key = Account.fromSecp256k1(privateKey_secp256k1, {
246
+ access: account,
247
+ })
248
+
249
+ const authorization = await account.signKeyAuthorization(key)
250
+
251
+ expect(authorization).toMatchInlineSnapshot(`
252
+ {
253
+ "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
254
+ "expiry": undefined,
255
+ "limits": undefined,
256
+ "signature": {
257
+ "signature": {
258
+ "r": 79205852917725370379355270588870592116219723320468023492479334723587833964208n,
259
+ "s": 4843127791679253574310716587415423223041264865988930666086461408483250881493n,
260
+ "yParity": 1,
261
+ },
262
+ "type": "secp256k1",
263
+ },
264
+ "type": "secp256k1",
265
+ }
266
+ `)
267
+ })
268
+
269
+ test('secp256k1', async () => {
270
+ const account = Account.fromSecp256k1(privateKey_secp256k1)
271
+ const key = Account.fromSecp256k1(privateKey_secp256k1, {
272
+ access: account,
273
+ })
274
+
275
+ const authorization = await account.signKeyAuthorization(key, {
276
+ expiry: 1234567890,
277
+ limits: [
278
+ {
279
+ token: '0x20c0000000000000000000000000000000000001',
280
+ limit: Value.from('10', 6),
281
+ },
282
+ ],
283
+ })
284
+ expect(authorization).toMatchInlineSnapshot(`
285
+ {
286
+ "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
287
+ "expiry": 1234567890,
288
+ "limits": [
289
+ {
290
+ "limit": 10000000n,
291
+ "token": "0x20c0000000000000000000000000000000000001",
292
+ },
293
+ ],
294
+ "signature": {
295
+ "signature": {
296
+ "r": 48603032183460068649726257603541287031240449157747147951793434940348798421977n,
297
+ "s": 52252948283033674801195452183159160801795536276956563866652050470169279213377n,
298
+ "yParity": 1,
299
+ },
300
+ "type": "secp256k1",
301
+ },
302
+ "type": "secp256k1",
303
+ }
304
+ `)
305
+ })
306
+
307
+ test('p256', async () => {
308
+ const account = Account.fromP256(privateKey_p256)
309
+ const key = Account.fromSecp256k1(privateKey_p256, {
310
+ access: account,
311
+ })
312
+
313
+ const authorization = await account.signKeyAuthorization(key, {
314
+ expiry: 1234567890,
315
+ limits: [
316
+ {
317
+ token: '0x20c0000000000000000000000000000000000001',
318
+ limit: Value.from('10', 6),
319
+ },
320
+ ],
321
+ })
322
+ expect(authorization).toMatchInlineSnapshot(`
323
+ {
324
+ "address": "0x7b9f73245dee5855ef858f5c00eea6205f9bb4d2",
325
+ "expiry": 1234567890,
326
+ "limits": [
327
+ {
328
+ "limit": 10000000n,
329
+ "token": "0x20c0000000000000000000000000000000000001",
330
+ },
331
+ ],
332
+ "signature": {
333
+ "prehash": false,
334
+ "publicKey": {
335
+ "prefix": 4,
336
+ "x": 14922859167660714031319135249406228569331107293314503672038378501577989797848n,
337
+ "y": 57892587925019714505251703757706314187537979987563648366993255393643804566080n,
338
+ },
339
+ "signature": {
340
+ "r": 61783347383434217927888325272237644430195567463134160594444735116547420206984n,
341
+ "s": 11737632122119624918549121055165681708107124199303685870565323985056705147576n,
342
+ },
343
+ "type": "p256",
344
+ },
345
+ "type": "secp256k1",
346
+ }
347
+ `)
348
+ })
349
+
350
+ test('webAuthn', async () => {
351
+ const account = Account.fromHeadlessWebAuthn(privateKey_p256, {
352
+ rpId: 'localhost',
353
+ origin: 'http://localhost',
354
+ })
355
+ const key = Account.fromSecp256k1(privateKey_secp256k1, {
356
+ access: account,
357
+ })
358
+
359
+ const authorization = await account.signKeyAuthorization(key, {
360
+ expiry: 1234567890,
361
+ limits: [
362
+ {
363
+ token: '0x20c0000000000000000000000000000000000001',
364
+ limit: Value.from('10', 6),
365
+ },
366
+ ],
367
+ })
368
+ expect(authorization).toMatchInlineSnapshot(`
369
+ {
370
+ "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
371
+ "expiry": 1234567890,
372
+ "limits": [
373
+ {
374
+ "limit": 10000000n,
375
+ "token": "0x20c0000000000000000000000000000000000001",
376
+ },
377
+ ],
378
+ "signature": {
379
+ "metadata": {
380
+ "authenticatorData": "0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000",
381
+ "clientDataJSON": "{"type":"webauthn.get","challenge":"lGAMxkLdccXnNTMWbfQ1rYi8HBqAdMPo1CDv0cJ2IsE","origin":"http://localhost","crossOrigin":false}",
382
+ },
383
+ "publicKey": {
384
+ "prefix": 4,
385
+ "x": 14922859167660714031319135249406228569331107293314503672038378501577989797848n,
386
+ "y": 57892587925019714505251703757706314187537979987563648366993255393643804566080n,
387
+ },
388
+ "signature": {
389
+ "r": 78216200649325922174765550266136727201161525335688064274452437990389629688142n,
390
+ "s": 45615041673857220498429503388722739621903077428603741554126666038202271956449n,
391
+ },
392
+ "type": "webAuthn",
393
+ },
394
+ "type": "secp256k1",
395
+ }
396
+ `)
397
+ })
398
+
399
+ test('multiple limits', async () => {
400
+ const account = Account.fromSecp256k1(privateKey_secp256k1)
401
+ const key = Account.fromSecp256k1(privateKey_secp256k1, {
402
+ access: account,
403
+ })
404
+
405
+ const authorization = await account.signKeyAuthorization(key, {
406
+ expiry: 1234567890,
407
+ limits: [
408
+ {
409
+ token: '0x20c0000000000000000000000000000000000001',
410
+ limit: Value.from('10', 6),
411
+ },
412
+ {
413
+ token: '0x20c0000000000000000000000000000000000002',
414
+ limit: Value.from('20', 6),
415
+ },
416
+ ],
417
+ })
418
+ expect(authorization).toMatchInlineSnapshot(`
419
+ {
420
+ "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
421
+ "expiry": 1234567890,
422
+ "limits": [
423
+ {
424
+ "limit": 10000000n,
425
+ "token": "0x20c0000000000000000000000000000000000001",
426
+ },
427
+ {
428
+ "limit": 20000000n,
429
+ "token": "0x20c0000000000000000000000000000000000002",
430
+ },
431
+ ],
432
+ "signature": {
433
+ "signature": {
434
+ "r": 103446563773805832555738463837136311499830712555215862064308154410957015968940n,
435
+ "s": 19247215858016211284757060583528935834485291841858715669623661689922072500812n,
436
+ "yParity": 0,
437
+ },
438
+ "type": "secp256k1",
439
+ },
440
+ "type": "secp256k1",
441
+ }
442
+ `)
443
+ })
444
+ })