tempo.ts 0.6.2 → 0.7.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 (101) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +6 -2
  3. package/dist/ox/Transaction.js +1 -1
  4. package/dist/ox/Transaction.js.map +1 -1
  5. package/dist/server/Handler.d.ts +346 -0
  6. package/dist/server/Handler.d.ts.map +1 -0
  7. package/dist/server/Handler.js +441 -0
  8. package/dist/server/Handler.js.map +1 -0
  9. package/dist/server/Kv.d.ts +16 -0
  10. package/dist/server/Kv.d.ts.map +1 -0
  11. package/dist/server/Kv.js +25 -0
  12. package/dist/server/Kv.js.map +1 -0
  13. package/dist/server/index.d.ts +3 -0
  14. package/dist/server/index.d.ts.map +1 -0
  15. package/dist/server/index.js +3 -0
  16. package/dist/server/index.js.map +1 -0
  17. package/dist/server/internal/requestListener.d.ts +124 -0
  18. package/dist/server/internal/requestListener.d.ts.map +1 -0
  19. package/dist/server/internal/requestListener.js +174 -0
  20. package/dist/server/internal/requestListener.js.map +1 -0
  21. package/dist/viem/Actions/amm.d.ts +51 -1245
  22. package/dist/viem/Actions/amm.d.ts.map +1 -1
  23. package/dist/viem/Actions/amm.js +15 -478
  24. package/dist/viem/Actions/amm.js.map +1 -1
  25. package/dist/viem/Actions/reward.d.ts +0 -1067
  26. package/dist/viem/Actions/reward.d.ts.map +1 -1
  27. package/dist/viem/Actions/reward.js +4 -212
  28. package/dist/viem/Actions/reward.js.map +1 -1
  29. package/dist/viem/Decorator.d.ts +0 -263
  30. package/dist/viem/Decorator.d.ts.map +1 -1
  31. package/dist/viem/Decorator.js +0 -10
  32. package/dist/viem/Decorator.js.map +1 -1
  33. package/dist/viem/Storage.d.ts +23 -0
  34. package/dist/viem/Storage.d.ts.map +1 -0
  35. package/dist/viem/Storage.js +47 -0
  36. package/dist/viem/Storage.js.map +1 -0
  37. package/dist/viem/Transport.d.ts +10 -1
  38. package/dist/viem/Transport.d.ts.map +1 -1
  39. package/dist/viem/Transport.js +22 -3
  40. package/dist/viem/Transport.js.map +1 -1
  41. package/dist/viem/internal/utils.d.ts +6 -0
  42. package/dist/viem/internal/utils.d.ts.map +1 -1
  43. package/dist/viem/internal/utils.js +24 -0
  44. package/dist/viem/internal/utils.js.map +1 -1
  45. package/dist/wagmi/Actions/amm.d.ts +0 -225
  46. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  47. package/dist/wagmi/Actions/amm.js +0 -248
  48. package/dist/wagmi/Actions/amm.js.map +1 -1
  49. package/dist/wagmi/Actions/reward.d.ts +0 -110
  50. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  51. package/dist/wagmi/Actions/reward.js +0 -121
  52. package/dist/wagmi/Actions/reward.js.map +1 -1
  53. package/dist/wagmi/Connector.d.ts +6 -17
  54. package/dist/wagmi/Connector.d.ts.map +1 -1
  55. package/dist/wagmi/Connector.js +17 -43
  56. package/dist/wagmi/Connector.js.map +1 -1
  57. package/dist/wagmi/Hooks/amm.d.ts +0 -236
  58. package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
  59. package/dist/wagmi/Hooks/amm.js +0 -285
  60. package/dist/wagmi/Hooks/amm.js.map +1 -1
  61. package/dist/wagmi/Hooks/reward.d.ts +0 -88
  62. package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
  63. package/dist/wagmi/Hooks/reward.js +0 -103
  64. package/dist/wagmi/Hooks/reward.js.map +1 -1
  65. package/dist/wagmi/KeyManager.d.ts +57 -0
  66. package/dist/wagmi/KeyManager.d.ts.map +1 -0
  67. package/dist/wagmi/KeyManager.js +101 -0
  68. package/dist/wagmi/KeyManager.js.map +1 -0
  69. package/dist/wagmi/index.d.ts +1 -0
  70. package/dist/wagmi/index.d.ts.map +1 -1
  71. package/dist/wagmi/index.js +1 -0
  72. package/dist/wagmi/index.js.map +1 -1
  73. package/package.json +8 -2
  74. package/src/ox/Transaction.ts +1 -1
  75. package/src/ox/e2e.test.ts +7 -0
  76. package/src/server/Handler.test.ts +566 -0
  77. package/src/server/Handler.ts +577 -0
  78. package/src/server/Kv.ts +40 -0
  79. package/src/server/index.ts +2 -0
  80. package/src/server/internal/requestListener.ts +285 -0
  81. package/src/viem/Actions/amm.test.ts +10 -284
  82. package/src/viem/Actions/amm.ts +88 -768
  83. package/src/viem/Actions/reward.test.ts +4 -212
  84. package/src/viem/Actions/reward.ts +4 -291
  85. package/src/viem/Decorator.ts +0 -294
  86. package/src/viem/Storage.ts +88 -0
  87. package/src/viem/Transport.ts +40 -2
  88. package/src/viem/e2e.test.ts +106 -3
  89. package/src/viem/internal/utils.ts +21 -0
  90. package/src/wagmi/Actions/amm.test.ts +7 -85
  91. package/src/wagmi/Actions/amm.ts +0 -346
  92. package/src/wagmi/Actions/reward.test.ts +0 -99
  93. package/src/wagmi/Actions/reward.ts +0 -203
  94. package/src/wagmi/Connector.test.ts +4 -1
  95. package/src/wagmi/Connector.ts +24 -58
  96. package/src/wagmi/Hooks/amm.test.ts +8 -200
  97. package/src/wagmi/Hooks/amm.ts +0 -443
  98. package/src/wagmi/Hooks/reward.test.ts +1 -142
  99. package/src/wagmi/Hooks/reward.ts +0 -196
  100. package/src/wagmi/KeyManager.ts +159 -0
  101. package/src/wagmi/index.ts +1 -0
@@ -0,0 +1,101 @@
1
+ import * as Json from 'ox/Json';
2
+ import * as Storage from '../viem/Storage.js';
3
+ /** Instantiates a key manager. */
4
+ export function from(manager) {
5
+ return manager;
6
+ }
7
+ /** Instantiates a key manager from a Storage instance. */
8
+ export function fromStorage(s) {
9
+ const storage = Storage.from(s, { key: 'webAuthn:publicKey' });
10
+ return from({
11
+ async getPublicKey(parameters) {
12
+ const publicKey = await storage.getItem(parameters.credential.id);
13
+ if (!publicKey)
14
+ throw new Error('publicKey not found.');
15
+ return publicKey;
16
+ },
17
+ async setPublicKey(parameters) {
18
+ await storage.setItem(parameters.credential.id, parameters.publicKey);
19
+ },
20
+ });
21
+ }
22
+ /**
23
+ * Instantiates a key manager from a localStorage instance.
24
+ *
25
+ * WARNING: Do not use this in production.
26
+ * This is because we are unable to extract a user's public key after the registration
27
+ * process. If a user clears their storage, or visits the website on a different device,
28
+ * they will not be able to access their account.
29
+ *
30
+ * Instead, we recommend to set up a remote store such as [`KeyManager.http`](#http) to register
31
+ * public keys against their WebAuthn credential.
32
+ *
33
+ * @see {@link http}
34
+ *
35
+ * @deprecated
36
+ */
37
+ export function localStorage(options = {}) {
38
+ return fromStorage(Storage.localStorage(options));
39
+ }
40
+ /**
41
+ * Instantiates a key manager that uses HTTP endpoints for credential management.
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * import { KeyManager } from 'tempo.ts/wagmi'
46
+ *
47
+ * const keyManager = KeyManager.http('https://api.example.com')
48
+ * ```
49
+ *
50
+ * @param url - The URL to use for the HTTP endpoints.
51
+ * @param options - Configuration options for HTTP endpoints.
52
+ * @returns A KeyManager instance that uses HTTP for credential operations.
53
+ */
54
+ export function http(url, options = {}) {
55
+ const { fetch: fetchFn = globalThis.fetch } = options;
56
+ const { getChallenge, getPublicKey, setPublicKey } = (() => {
57
+ const base = typeof url === 'string' ? url : '';
58
+ const urls = typeof url === 'object' ? url : {};
59
+ return {
60
+ getChallenge: urls.getChallenge ?? `${base}/challenge`,
61
+ getPublicKey: urls.getPublicKey ?? `${base}/:credentialId`,
62
+ setPublicKey: urls.setPublicKey ?? `${base}/:credentialId`,
63
+ };
64
+ })();
65
+ return from({
66
+ async getChallenge() {
67
+ const request = getChallenge instanceof Request
68
+ ? getChallenge
69
+ : new Request(getChallenge);
70
+ const response = await fetchFn(request);
71
+ if (!response.ok)
72
+ throw new Error(`Failed to get create options: ${response.statusText}`);
73
+ return await response.json();
74
+ },
75
+ async getPublicKey(parameters) {
76
+ const request = getPublicKey instanceof Request
77
+ ? getPublicKey
78
+ : new Request(getPublicKey);
79
+ const response = await fetchFn(new Request(request.url.replace(':credentialId', parameters.credential.id), request));
80
+ if (!response.ok)
81
+ throw new Error(`Failed to get public key: ${response.statusText}`);
82
+ const data = await response.json();
83
+ return data.publicKey;
84
+ },
85
+ async setPublicKey(parameters) {
86
+ const request = setPublicKey instanceof Request
87
+ ? setPublicKey
88
+ : new Request(setPublicKey);
89
+ const response = await fetchFn(new Request(request.url.replace(':credentialId', parameters.credential.id), request), {
90
+ method: 'POST',
91
+ headers: {
92
+ 'Content-Type': 'application/json',
93
+ },
94
+ body: Json.stringify(parameters),
95
+ });
96
+ if (!response.ok)
97
+ throw new Error(`Failed to set public key: ${response.statusText}`);
98
+ },
99
+ });
100
+ }
101
+ //# sourceMappingURL=KeyManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyManager.js","sourceRoot":"","sources":["../../src/wagmi/KeyManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAE/B,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAiB7C,kCAAkC;AAClC,MAAM,UAAU,IAAI,CAA6B,OAAgB;IAC/D,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,WAAW,CAAC,CAAkB;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,CAAA;IAC9D,OAAO,IAAI,CAAC;QACV,KAAK,CAAC,YAAY,CAAC,UAAU;YAC3B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;YACjE,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;YACvD,OAAO,SAAoB,CAAA;QAC7B,CAAC;QACD,KAAK,CAAC,YAAY,CAAC,UAAU;YAC3B,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QACvE,CAAC;KAC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@@ -1,4 +1,5 @@
1
1
  export * as Actions from './Actions/index.js';
2
2
  export { dangerous_secp256k1, webAuthn } from './Connector.js';
3
3
  export * as Hooks from './Hooks/index.js';
4
+ export * as KeyManager from './KeyManager.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wagmi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wagmi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * as Actions from './Actions/index.js';
2
2
  export { dangerous_secp256k1, webAuthn } from './Connector.js';
3
3
  export * as Hooks from './Hooks/index.js';
4
+ export * as KeyManager from './KeyManager.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wagmi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wagmi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "tempo.ts",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "dependencies": {
6
- "ox": "~0.9.16"
6
+ "@remix-run/fetch-router": "~0.12.0",
7
+ "ox": "~0.9.17"
7
8
  },
8
9
  "peerDependencies": {
9
10
  "@tanstack/query-core": ">=5.0.0",
@@ -65,6 +66,11 @@
65
66
  "types": "./dist/prool/index.d.ts",
66
67
  "default": "./dist/prool/index.js"
67
68
  },
69
+ "./server": {
70
+ "src": "./src/server/index.ts",
71
+ "types": "./dist/server/index.d.ts",
72
+ "default": "./dist/server/index.js"
73
+ },
68
74
  "./viem": {
69
75
  "src": "./src/viem/index.ts",
70
76
  "types": "./dist/viem/index.d.ts",
@@ -188,7 +188,7 @@ export function fromRpc<
188
188
  if (transaction.calls)
189
189
  transaction_.calls = transaction.calls.map((call) => ({
190
190
  to: call.to,
191
- value: call.value ? BigInt(call.value) : undefined,
191
+ value: call.value && call.value !== '0x' ? BigInt(call.value) : undefined,
192
192
  // @ts-expect-error
193
193
  data: call.input || call.data || '0x',
194
194
  }))
@@ -75,6 +75,8 @@ test('behavior: default (secp256k1)', async () => {
75
75
  hash,
76
76
  feeToken: _,
77
77
  from,
78
+ // @ts-expect-error
79
+ keyAuthorization: __,
78
80
  nonce,
79
81
  maxFeePerGas,
80
82
  maxPriorityFeePerGas,
@@ -213,6 +215,8 @@ test('behavior: default (p256)', async () => {
213
215
  chainId,
214
216
  feeToken: _,
215
217
  from,
218
+ // @ts-expect-error
219
+ keyAuthorization: __,
216
220
  hash,
217
221
  nonce,
218
222
  maxFeePerGas,
@@ -351,6 +355,7 @@ test('behavior: default (p256 - webcrypto)', async () => {
351
355
  chainId,
352
356
  feeToken: _,
353
357
  from,
358
+ keyAuthorization: __,
354
359
  hash,
355
360
  nonce,
356
361
  maxFeePerGas,
@@ -496,6 +501,8 @@ test('behavior: default (webauthn)', async () => {
496
501
  chainId,
497
502
  feeToken: _,
498
503
  from,
504
+ // @ts-expect-error
505
+ keyAuthorization: __,
499
506
  hash,
500
507
  nonce,
501
508
  maxFeePerGas,