thirdweb 5.121.1 → 5.121.3

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 (78) hide show
  1. package/dist/cjs/react/core/hooks/x402/useFetchWithPaymentCore.js +1 -0
  2. package/dist/cjs/react/core/hooks/x402/useFetchWithPaymentCore.js.map +1 -1
  3. package/dist/cjs/react/native/hooks/x402/useFetchWithPayment.js +1 -1
  4. package/dist/cjs/react/web/hooks/x402/useFetchWithPayment.js +2 -2
  5. package/dist/cjs/react/web/hooks/x402/useFetchWithPayment.js.map +1 -1
  6. package/dist/cjs/react/web/ui/Bridge/common/token-query.js +4 -1
  7. package/dist/cjs/react/web/ui/Bridge/common/token-query.js.map +1 -1
  8. package/dist/cjs/react/web/ui/x402/PaymentErrorModal.js +4 -4
  9. package/dist/cjs/react/web/ui/x402/PaymentErrorModal.js.map +1 -1
  10. package/dist/cjs/version.js +1 -1
  11. package/dist/cjs/x402/encode.js +41 -2
  12. package/dist/cjs/x402/encode.js.map +1 -1
  13. package/dist/cjs/x402/fetchWithPayment.js +56 -33
  14. package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
  15. package/dist/cjs/x402/schemas.js +134 -2
  16. package/dist/cjs/x402/schemas.js.map +1 -1
  17. package/dist/cjs/x402/sign.js +56 -15
  18. package/dist/cjs/x402/sign.js.map +1 -1
  19. package/dist/esm/react/core/hooks/x402/useFetchWithPaymentCore.js +2 -1
  20. package/dist/esm/react/core/hooks/x402/useFetchWithPaymentCore.js.map +1 -1
  21. package/dist/esm/react/native/hooks/x402/useFetchWithPayment.js +1 -1
  22. package/dist/esm/react/web/hooks/x402/useFetchWithPayment.js +2 -2
  23. package/dist/esm/react/web/hooks/x402/useFetchWithPayment.js.map +1 -1
  24. package/dist/esm/react/web/ui/Bridge/common/token-query.js +4 -1
  25. package/dist/esm/react/web/ui/Bridge/common/token-query.js.map +1 -1
  26. package/dist/esm/react/web/ui/x402/PaymentErrorModal.js +5 -5
  27. package/dist/esm/react/web/ui/x402/PaymentErrorModal.js.map +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/dist/esm/x402/encode.js +40 -2
  30. package/dist/esm/x402/encode.js.map +1 -1
  31. package/dist/esm/x402/fetchWithPayment.js +57 -35
  32. package/dist/esm/x402/fetchWithPayment.js.map +1 -1
  33. package/dist/esm/x402/schemas.js +129 -1
  34. package/dist/esm/x402/schemas.js.map +1 -1
  35. package/dist/esm/x402/sign.js +57 -16
  36. package/dist/esm/x402/sign.js.map +1 -1
  37. package/dist/scripts/bridge-widget.js +3 -3
  38. package/dist/types/react/core/hooks/x402/useFetchWithPaymentCore.d.ts +1 -0
  39. package/dist/types/react/core/hooks/x402/useFetchWithPaymentCore.d.ts.map +1 -1
  40. package/dist/types/react/native/hooks/x402/useFetchWithPayment.d.ts +1 -1
  41. package/dist/types/react/web/hooks/x402/useFetchWithPayment.d.ts +1 -1
  42. package/dist/types/react/web/hooks/x402/useFetchWithPayment.d.ts.map +1 -1
  43. package/dist/types/react/web/ui/Bridge/common/token-query.d.ts.map +1 -1
  44. package/dist/types/react/web/ui/x402/PaymentErrorModal.d.ts +1 -0
  45. package/dist/types/react/web/ui/x402/PaymentErrorModal.d.ts.map +1 -1
  46. package/dist/types/version.d.ts +1 -1
  47. package/dist/types/x402/encode.d.ts +7 -0
  48. package/dist/types/x402/encode.d.ts.map +1 -1
  49. package/dist/types/x402/fetchWithPayment.d.ts +10 -1
  50. package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
  51. package/dist/types/x402/schemas.d.ts +60 -2
  52. package/dist/types/x402/schemas.d.ts.map +1 -1
  53. package/dist/types/x402/sign.d.ts +13 -1
  54. package/dist/types/x402/sign.d.ts.map +1 -1
  55. package/package.json +3 -3
  56. package/src/contract/actions/resolve-abi.test.ts +3 -5
  57. package/src/extensions/airdrop/write/airdropERC721WithSignature.test.ts +4 -5
  58. package/src/extensions/erc1155/drop1155.test.ts +1 -1
  59. package/src/extensions/erc1155/write/sigMint1155.test.ts +189 -187
  60. package/src/extensions/erc20/drop20.test.ts +1 -1
  61. package/src/extensions/erc721/write/sigMint721.test.ts +4 -6
  62. package/src/extensions/modules/ClaimableERC1155/claimableERC1155.test.ts +180 -178
  63. package/src/extensions/modules/ClaimableERC20/claimableERC20.test.ts +1 -1
  64. package/src/extensions/modules/ClaimableERC721/claimableERC721.test.ts +1 -1
  65. package/src/extensions/prebuilts/process-ref-deployments.test.ts +1 -1
  66. package/src/react/core/hooks/x402/useFetchWithPaymentCore.ts +6 -1
  67. package/src/react/native/hooks/x402/useFetchWithPayment.ts +1 -1
  68. package/src/react/web/hooks/x402/useFetchWithPayment.tsx +3 -1
  69. package/src/react/web/ui/Bridge/common/token-query.test.tsx +117 -0
  70. package/src/react/web/ui/Bridge/common/token-query.ts +4 -1
  71. package/src/react/web/ui/x402/PaymentErrorModal.tsx +9 -4
  72. package/src/version.ts +1 -1
  73. package/src/x402/encode.ts +46 -2
  74. package/src/x402/fetchWithPayment.test.ts +1173 -104
  75. package/src/x402/fetchWithPayment.ts +72 -54
  76. package/src/x402/schemas.test.ts +123 -0
  77. package/src/x402/schemas.ts +199 -6
  78. package/src/x402/sign.ts +86 -10
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.121.1";
1
+ export const version = "5.121.3";
@@ -1,4 +1,6 @@
1
1
  import type { ExactEvmPayload } from "x402/types";
2
+ import { cachedTextDecoder } from "../utils/text-decoder.js";
3
+ import { cachedTextEncoder } from "../utils/text-encoder.js";
2
4
  import type {
3
5
  RequestedPaymentPayload,
4
6
  RequestedPaymentRequirements,
@@ -27,7 +29,7 @@ export function encodePayment(payment: RequestedPaymentPayload): string {
27
29
  ) as ExactEvmPayload["authorization"],
28
30
  },
29
31
  };
30
- return safeBase64Encode(JSON.stringify(safe));
32
+ return base64EncodeUtf8(JSON.stringify(safe));
31
33
  }
32
34
 
33
35
  /**
@@ -37,7 +39,7 @@ export function encodePayment(payment: RequestedPaymentPayload): string {
37
39
  * @returns The decoded and validated PaymentPayload object
38
40
  */
39
41
  export function decodePayment(payment: string): RequestedPaymentPayload {
40
- const decoded = safeBase64Decode(payment);
42
+ const decoded = base64DecodeUtf8(payment);
41
43
  const parsed = JSON.parse(decoded);
42
44
 
43
45
  const obj: RequestedPaymentPayload = {
@@ -93,3 +95,45 @@ export function safeBase64Decode(data: string): string {
93
95
  }
94
96
  return Buffer.from(data, "base64").toString("utf-8");
95
97
  }
98
+
99
+ /**
100
+ * Encodes a string as UTF-8 and then to base64
101
+ *
102
+ * @param data - The string to encode
103
+ * @returns The base64 encoded UTF-8 bytes
104
+ */
105
+ function base64EncodeUtf8(data: string): string {
106
+ if (
107
+ typeof globalThis !== "undefined" &&
108
+ typeof globalThis.btoa === "function"
109
+ ) {
110
+ const bytes = cachedTextEncoder().encode(data);
111
+ let binary = "";
112
+ for (const byte of bytes) {
113
+ binary += String.fromCharCode(byte);
114
+ }
115
+ return globalThis.btoa(binary);
116
+ }
117
+ return Buffer.from(data, "utf-8").toString("base64");
118
+ }
119
+
120
+ /**
121
+ * Decodes a base64 string and interprets the bytes as UTF-8
122
+ *
123
+ * @param data - The base64 encoded string
124
+ * @returns The decoded string
125
+ */
126
+ export function base64DecodeUtf8(data: string): string {
127
+ if (
128
+ typeof globalThis !== "undefined" &&
129
+ typeof globalThis.atob === "function"
130
+ ) {
131
+ const binary = globalThis.atob(data);
132
+ const bytes = new Uint8Array(binary.length);
133
+ for (let i = 0; i < binary.length; i++) {
134
+ bytes[i] = binary.charCodeAt(i);
135
+ }
136
+ return cachedTextDecoder().decode(bytes);
137
+ }
138
+ return Buffer.from(data, "base64").toString("utf-8");
139
+ }