thirdweb 5.67.1-nightly-07af64706797927a9793a5452bd253e493de38f1-20241111000412 → 5.67.1-nightly-040e478ad6cf630dedf666eac7abeb668d323666-20241112230501

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 (95) hide show
  1. package/dist/cjs/auth/verify-hash.js +1 -1
  2. package/dist/cjs/auth/verify-hash.js.map +1 -1
  3. package/dist/cjs/react/core/utils/walletIcon.js +10 -1
  4. package/dist/cjs/react/core/utils/walletIcon.js.map +1 -1
  5. package/dist/cjs/utils/encoding/from-bytes.js +5 -27
  6. package/dist/cjs/utils/encoding/from-bytes.js.map +1 -1
  7. package/dist/cjs/utils/encoding/helpers/byte-size.js +2 -2
  8. package/dist/cjs/utils/encoding/helpers/byte-size.js.map +1 -1
  9. package/dist/cjs/utils/encoding/helpers/concat-hex.js +2 -1
  10. package/dist/cjs/utils/encoding/helpers/concat-hex.js.map +1 -1
  11. package/dist/cjs/utils/encoding/helpers/is-hex.js +2 -9
  12. package/dist/cjs/utils/encoding/helpers/is-hex.js.map +1 -1
  13. package/dist/cjs/utils/encoding/hex.js +13 -134
  14. package/dist/cjs/utils/encoding/hex.js.map +1 -1
  15. package/dist/cjs/utils/encoding/to-bytes.js +5 -59
  16. package/dist/cjs/utils/encoding/to-bytes.js.map +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js +11 -7
  19. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  20. package/dist/esm/auth/verify-hash.js +1 -1
  21. package/dist/esm/auth/verify-hash.js.map +1 -1
  22. package/dist/esm/react/core/utils/walletIcon.js +10 -1
  23. package/dist/esm/react/core/utils/walletIcon.js.map +1 -1
  24. package/dist/esm/utils/encoding/from-bytes.js +6 -28
  25. package/dist/esm/utils/encoding/from-bytes.js.map +1 -1
  26. package/dist/esm/utils/encoding/helpers/byte-size.js +1 -1
  27. package/dist/esm/utils/encoding/helpers/byte-size.js.map +1 -1
  28. package/dist/esm/utils/encoding/helpers/concat-hex.js +2 -1
  29. package/dist/esm/utils/encoding/helpers/concat-hex.js.map +1 -1
  30. package/dist/esm/utils/encoding/helpers/is-hex.js +2 -9
  31. package/dist/esm/utils/encoding/helpers/is-hex.js.map +1 -1
  32. package/dist/esm/utils/encoding/hex.js +13 -134
  33. package/dist/esm/utils/encoding/hex.js.map +1 -1
  34. package/dist/esm/utils/encoding/to-bytes.js +5 -58
  35. package/dist/esm/utils/encoding/to-bytes.js.map +1 -1
  36. package/dist/esm/version.js +1 -1
  37. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js +11 -7
  38. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  39. package/dist/types/react/core/utils/walletIcon.d.ts +11 -1
  40. package/dist/types/react/core/utils/walletIcon.d.ts.map +1 -1
  41. package/dist/types/utils/encoding/from-bytes.d.ts +4 -9
  42. package/dist/types/utils/encoding/from-bytes.d.ts.map +1 -1
  43. package/dist/types/utils/encoding/helpers/byte-size.d.ts +1 -1
  44. package/dist/types/utils/encoding/helpers/byte-size.d.ts.map +1 -1
  45. package/dist/types/utils/encoding/helpers/concat-hex.d.ts +1 -1
  46. package/dist/types/utils/encoding/helpers/concat-hex.d.ts.map +1 -1
  47. package/dist/types/utils/encoding/helpers/is-hex.d.ts +3 -5
  48. package/dist/types/utils/encoding/helpers/is-hex.d.ts.map +1 -1
  49. package/dist/types/utils/encoding/hex.d.ts +11 -42
  50. package/dist/types/utils/encoding/hex.d.ts.map +1 -1
  51. package/dist/types/utils/encoding/to-bytes.d.ts +5 -19
  52. package/dist/types/utils/encoding/to-bytes.d.ts.map +1 -1
  53. package/dist/types/version.d.ts +1 -1
  54. package/dist/types/wallets/in-app/core/wallet/enclave-wallet.d.ts.map +1 -1
  55. package/package.json +4 -2
  56. package/src/auth/verify-hash.ts +1 -1
  57. package/src/extensions/prebuilts/deploy-published.test.ts +0 -36
  58. package/src/extensions/unstoppable-domains/read/resolveAddress.test.ts +25 -22
  59. package/src/react/core/utils/walletIcon.ts +11 -2
  60. package/src/react/web/ui/SiteEmbed.test.tsx +3 -18
  61. package/src/utils/encoding/from-bytes.ts +8 -38
  62. package/src/utils/encoding/helpers/byte-size.ts +1 -1
  63. package/src/utils/encoding/helpers/concat-hex.ts +3 -5
  64. package/src/utils/encoding/helpers/is-hex.ts +4 -14
  65. package/src/utils/encoding/hex.ts +23 -214
  66. package/src/utils/encoding/to-bytes.test.ts +3 -51
  67. package/src/utils/encoding/to-bytes.ts +10 -82
  68. package/src/version.ts +1 -1
  69. package/src/wallets/in-app/core/wallet/enclave-wallet.ts +23 -18
  70. package/src/wallets/smart/smart-wallet-integration-v07.test.ts +15 -15
  71. package/src/wallets/smart/smart-wallet-integration.test.ts +3 -8
  72. package/dist/cjs/utils/encoding/helpers/assert-size.js +0 -23
  73. package/dist/cjs/utils/encoding/helpers/assert-size.js.map +0 -1
  74. package/dist/cjs/utils/encoding/helpers/charcode-to-base-16.js +0 -27
  75. package/dist/cjs/utils/encoding/helpers/charcode-to-base-16.js.map +0 -1
  76. package/dist/cjs/utils/encoding/helpers/trim.js +0 -36
  77. package/dist/cjs/utils/encoding/helpers/trim.js.map +0 -1
  78. package/dist/esm/utils/encoding/helpers/assert-size.js +0 -20
  79. package/dist/esm/utils/encoding/helpers/assert-size.js.map +0 -1
  80. package/dist/esm/utils/encoding/helpers/charcode-to-base-16.js +0 -24
  81. package/dist/esm/utils/encoding/helpers/charcode-to-base-16.js.map +0 -1
  82. package/dist/esm/utils/encoding/helpers/trim.js +0 -33
  83. package/dist/esm/utils/encoding/helpers/trim.js.map +0 -1
  84. package/dist/types/utils/encoding/helpers/assert-size.d.ts +0 -17
  85. package/dist/types/utils/encoding/helpers/assert-size.d.ts.map +0 -1
  86. package/dist/types/utils/encoding/helpers/charcode-to-base-16.d.ts +0 -5
  87. package/dist/types/utils/encoding/helpers/charcode-to-base-16.d.ts.map +0 -1
  88. package/dist/types/utils/encoding/helpers/trim.d.ts +0 -16
  89. package/dist/types/utils/encoding/helpers/trim.d.ts.map +0 -1
  90. package/src/utils/encoding/helpers/assert-size.test.ts +0 -47
  91. package/src/utils/encoding/helpers/assert-size.ts +0 -24
  92. package/src/utils/encoding/helpers/charcode-to-base-16.test.ts +0 -39
  93. package/src/utils/encoding/helpers/charcode-to-base-16.ts +0 -24
  94. package/src/utils/encoding/helpers/trim.ts +0 -48
  95. /package/src/utils/encoding/helpers/{is-hext.test.ts → is-hex.test.ts} +0 -0
@@ -141,34 +141,39 @@ export class EnclaveWallet implements IWebWallet {
141
141
  const transaction: Record<string, Hex | number | undefined> = {
142
142
  to: tx.to ? getAddress(tx.to) : undefined,
143
143
  data: tx.data,
144
- value: tx.value ? toHex(tx.value) : undefined,
145
- gas: tx.gas ? toHex(tx.gas + tx.gas / BigInt(10)) : undefined, // Add a 10% buffer to gas
146
- nonce: tx.nonce
147
- ? toHex(tx.nonce)
148
- : toHex(
149
- await import(
150
- "../../../../rpc/actions/eth_getTransactionCount.js"
151
- ).then(({ eth_getTransactionCount }) =>
152
- eth_getTransactionCount(rpcRequest, {
153
- address: this.address,
154
- blockTag: "pending",
155
- }),
144
+ value: typeof tx.value === "bigint" ? toHex(tx.value) : undefined,
145
+ gas:
146
+ typeof tx.gas === "bigint"
147
+ ? toHex(tx.gas + tx.gas / BigInt(10))
148
+ : undefined, // Add a 10% buffer to gas
149
+ nonce:
150
+ typeof tx.nonce === "number"
151
+ ? toHex(tx.nonce)
152
+ : toHex(
153
+ await import(
154
+ "../../../../rpc/actions/eth_getTransactionCount.js"
155
+ ).then(({ eth_getTransactionCount }) =>
156
+ eth_getTransactionCount(rpcRequest, {
157
+ address: this.address,
158
+ blockTag: "pending",
159
+ }),
160
+ ),
156
161
  ),
157
- ),
158
162
  chainId: toHex(tx.chainId),
159
163
  };
160
164
 
161
165
  if (tx.maxFeePerGas) {
162
166
  transaction.maxFeePerGas = toHex(tx.maxFeePerGas);
163
- transaction.maxPriorityFeePerGas = tx.maxPriorityFeePerGas
164
- ? toHex(tx.maxPriorityFeePerGas)
165
- : undefined;
167
+ transaction.maxPriorityFeePerGas =
168
+ typeof tx.maxPriorityFeePerGas === "bigint"
169
+ ? toHex(tx.maxPriorityFeePerGas)
170
+ : undefined;
166
171
  transaction.type = 2;
167
172
  } else {
168
- transaction.gasPrice = tx.gasPrice ? toHex(tx.gasPrice) : undefined;
173
+ transaction.gasPrice =
174
+ typeof tx.gasPrice === "bigint" ? toHex(tx.gasPrice) : undefined;
169
175
  transaction.type = 0;
170
176
  }
171
-
172
177
  return signEnclaveTransaction({
173
178
  client,
174
179
  storage,
@@ -41,7 +41,7 @@ const contract = getContract({
41
41
  address: "0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8",
42
42
  });
43
43
 
44
- describe.runIf(process.env.TW_SECRET_KEY).sequential(
44
+ describe.runIf(process.env.TW_SECRET_KEY).skip(
45
45
  "SmartWallet 0.7 core tests",
46
46
  {
47
47
  retry: 0,
@@ -150,17 +150,12 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
150
150
  ],
151
151
  });
152
152
  expect(tx.transactionHash).toHaveLength(66);
153
- await waitForReceipt({
153
+ const result = await waitForReceipt({
154
154
  client,
155
155
  transactionHash: tx.transactionHash,
156
156
  chain,
157
157
  });
158
- const balance = await balanceOf({
159
- contract,
160
- owner: getAddress(smartWalletAddress),
161
- tokenId: 0n,
162
- });
163
- expect(balance).toEqual(3n);
158
+ expect(result.status).toEqual("success");
164
159
  });
165
160
 
166
161
  it("can sign and verify 1271 with replay protection", async () => {
@@ -222,7 +217,6 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
222
217
  client: TEST_CLIENT,
223
218
  personalAccount,
224
219
  });
225
- console.log("newSmartAccount", newSmartAccount.address);
226
220
  const newSmartAccountContract = getContract({
227
221
  address: newSmartAccount.address,
228
222
  chain,
@@ -256,15 +250,21 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
256
250
  ]);
257
251
  expect(txs.length).toEqual(2);
258
252
  expect(txs.every((t) => t.transactionHash.length === 66)).toBe(true);
253
+ const result1 = await waitForReceipt({
254
+ client,
255
+ transactionHash: txs[0].transactionHash,
256
+ chain,
257
+ });
258
+ expect(result1.status).toEqual("success");
259
+ const result2 = await waitForReceipt({
260
+ client,
261
+ transactionHash: txs[1].transactionHash,
262
+ chain,
263
+ });
264
+ expect(result2.status).toEqual("success");
259
265
 
260
266
  isDeployed = await isContractDeployed(newSmartAccountContract);
261
267
  expect(isDeployed).toEqual(true);
262
- const balance = await balanceOf({
263
- contract,
264
- owner: newSmartAccountContract.address,
265
- tokenId: 0n,
266
- });
267
- expect(balance).toEqual(2n);
268
268
  });
269
269
  },
270
270
  );
@@ -150,17 +150,12 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
150
150
  ],
151
151
  });
152
152
  expect(tx.transactionHash).toHaveLength(66);
153
- await waitForReceipt({
153
+ const result = await waitForReceipt({
154
154
  client,
155
155
  transactionHash: tx.transactionHash,
156
156
  chain,
157
157
  });
158
- const balance = await balanceOf({
159
- contract,
160
- owner: smartWalletAddress,
161
- tokenId: 0n,
162
- });
163
- expect(balance).toEqual(3n);
158
+ expect(result.status).toEqual("success");
164
159
  });
165
160
 
166
161
  it("can sign and verify 1271 with replay protection", async () => {
@@ -289,7 +284,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
289
284
  expect(wallet.getChain()?.id).toEqual(baseSepolia.id);
290
285
  });
291
286
 
292
- it("can execute a 2 tx in parallel", async () => {
287
+ it("can execute 2 tx in parallel", async () => {
293
288
  const newSmartWallet = smartWallet({
294
289
  chain,
295
290
  gasless: true,
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertSize = assertSize;
4
- const byte_size_js_1 = require("./byte-size.js");
5
- /**
6
- * Asserts that the size of the given hex or bytes is not greater than the specified size.
7
- * @param hexOrBytes - The hex or bytes to check the size of.
8
- * @param size - The maximum allowed size.
9
- * @throws Error if the size of the hex or bytes is greater than the specified size.
10
- * @example
11
- * ```ts
12
- * import { assertSize } from "thirdweb/utils";
13
- * assertSize("0x1a4", { size: 2 });
14
- * ```
15
- * @internal
16
- */
17
- function assertSize(hexOrBytes, { size }) {
18
- const givenSize = (0, byte_size_js_1.byteSize)(hexOrBytes);
19
- if (givenSize > size) {
20
- throw new Error(`Size overflow: ${givenSize} > ${size}`);
21
- }
22
- }
23
- //# sourceMappingURL=assert-size.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-size.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/assert-size.ts"],"names":[],"mappings":";;AAeA,gCAQC;AAvBD,iDAA0C;AAG1C;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CACxB,UAA4B,EAC5B,EAAE,IAAI,EAAoB;IAE1B,MAAM,SAAS,GAAG,IAAA,uBAAQ,EAAC,UAAU,CAAC,CAAC;IACvC,IAAI,SAAS,GAAG,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kBAAkB,SAAS,MAAM,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.charCodeToBase16 = charCodeToBase16;
4
- const charCodeMap = {
5
- zero: 48,
6
- nine: 57,
7
- A: 65,
8
- F: 70,
9
- a: 97,
10
- f: 102,
11
- };
12
- /**
13
- * @internal
14
- */
15
- function charCodeToBase16(char) {
16
- if (char >= charCodeMap.zero && char <= charCodeMap.nine) {
17
- return char - charCodeMap.zero;
18
- }
19
- if (char >= charCodeMap.A && char <= charCodeMap.F) {
20
- return char - (charCodeMap.A - 10);
21
- }
22
- if (char >= charCodeMap.a && char <= charCodeMap.f) {
23
- return char - (charCodeMap.a - 10);
24
- }
25
- return undefined;
26
- }
27
- //# sourceMappingURL=charcode-to-base-16.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"charcode-to-base-16.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/charcode-to-base-16.ts"],"names":[],"mappings":";;AAYA,4CAWC;AAvBD,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,GAAG;CACE,CAAC;AAEX;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;QACzD,OAAO,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trim = trim;
4
- /**
5
- * Trims leading or trailing zeros from a hexadecimal string or byte array.
6
- *
7
- * @param hexOrBytes - The hexadecimal string or byte array to trim.
8
- * @param options - The options for trimming. Default is to trim leading zeros.
9
- * @returns The trimmed hexadecimal string or byte array.
10
- * @internal
11
- */
12
- function trim(hexOrBytes, { dir = "left" } = {}) {
13
- // biome-ignore lint/suspicious/noExplicitAny: TODO: fix any
14
- let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
15
- let sliceLength = 0;
16
- for (let i = 0; i < data.length - 1; i++) {
17
- if (data[dir === "left" ? i : data.length - i - 1].toString() === "0") {
18
- sliceLength++;
19
- }
20
- else {
21
- break;
22
- }
23
- }
24
- data =
25
- dir === "left"
26
- ? data.slice(sliceLength)
27
- : data.slice(0, data.length - sliceLength);
28
- if (typeof hexOrBytes === "string") {
29
- if (data.length === 1 && dir === "right") {
30
- data = `${data}0`;
31
- }
32
- return `0x${data.length % 2 === 1 ? `0${data}` : data}`;
33
- }
34
- return data;
35
- }
36
- //# sourceMappingURL=trim.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/trim.ts"],"names":[],"mappings":";;AAiBA,oBA8BC;AAtCD;;;;;;;GAOG;AACH,SAAgB,IAAI,CAClB,UAAkB,EAClB,EAAE,GAAG,GAAG,MAAM,KAAkB,EAAE;IAElC,4DAA4D;IAC5D,IAAI,IAAI,GACN,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAE7E,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,GAAG,EAAE,CAAC;YACtE,WAAW,EAAE,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,MAAM;QACR,CAAC;IACH,CAAC;IACD,IAAI;QACF,GAAG,KAAK,MAAM;YACZ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;YACzB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC;IAE/C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;YACzC,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC;QACpB,CAAC;QACD,OAAO,KACL,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IACvC,EAA4B,CAAC;IAC/B,CAAC;IACD,OAAO,IAA8B,CAAC;AACxC,CAAC"}
@@ -1,20 +0,0 @@
1
- import { byteSize } from "./byte-size.js";
2
- /**
3
- * Asserts that the size of the given hex or bytes is not greater than the specified size.
4
- * @param hexOrBytes - The hex or bytes to check the size of.
5
- * @param size - The maximum allowed size.
6
- * @throws Error if the size of the hex or bytes is greater than the specified size.
7
- * @example
8
- * ```ts
9
- * import { assertSize } from "thirdweb/utils";
10
- * assertSize("0x1a4", { size: 2 });
11
- * ```
12
- * @internal
13
- */
14
- export function assertSize(hexOrBytes, { size }) {
15
- const givenSize = byteSize(hexOrBytes);
16
- if (givenSize > size) {
17
- throw new Error(`Size overflow: ${givenSize} > ${size}`);
18
- }
19
- }
20
- //# sourceMappingURL=assert-size.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-size.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/assert-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACxB,UAA4B,EAC5B,EAAE,IAAI,EAAoB;IAE1B,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACvC,IAAI,SAAS,GAAG,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kBAAkB,SAAS,MAAM,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
@@ -1,24 +0,0 @@
1
- const charCodeMap = {
2
- zero: 48,
3
- nine: 57,
4
- A: 65,
5
- F: 70,
6
- a: 97,
7
- f: 102,
8
- };
9
- /**
10
- * @internal
11
- */
12
- export function charCodeToBase16(char) {
13
- if (char >= charCodeMap.zero && char <= charCodeMap.nine) {
14
- return char - charCodeMap.zero;
15
- }
16
- if (char >= charCodeMap.A && char <= charCodeMap.F) {
17
- return char - (charCodeMap.A - 10);
18
- }
19
- if (char >= charCodeMap.a && char <= charCodeMap.f) {
20
- return char - (charCodeMap.a - 10);
21
- }
22
- return undefined;
23
- }
24
- //# sourceMappingURL=charcode-to-base-16.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"charcode-to-base-16.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/charcode-to-base-16.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,GAAG;CACE,CAAC;AAEX;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;QACzD,OAAO,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,IAAI,IAAI,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,33 +0,0 @@
1
- /**
2
- * Trims leading or trailing zeros from a hexadecimal string or byte array.
3
- *
4
- * @param hexOrBytes - The hexadecimal string or byte array to trim.
5
- * @param options - The options for trimming. Default is to trim leading zeros.
6
- * @returns The trimmed hexadecimal string or byte array.
7
- * @internal
8
- */
9
- export function trim(hexOrBytes, { dir = "left" } = {}) {
10
- // biome-ignore lint/suspicious/noExplicitAny: TODO: fix any
11
- let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
12
- let sliceLength = 0;
13
- for (let i = 0; i < data.length - 1; i++) {
14
- if (data[dir === "left" ? i : data.length - i - 1].toString() === "0") {
15
- sliceLength++;
16
- }
17
- else {
18
- break;
19
- }
20
- }
21
- data =
22
- dir === "left"
23
- ? data.slice(sliceLength)
24
- : data.slice(0, data.length - sliceLength);
25
- if (typeof hexOrBytes === "string") {
26
- if (data.length === 1 && dir === "right") {
27
- data = `${data}0`;
28
- }
29
- return `0x${data.length % 2 === 1 ? `0${data}` : data}`;
30
- }
31
- return data;
32
- }
33
- //# sourceMappingURL=trim.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/trim.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAClB,UAAkB,EAClB,EAAE,GAAG,GAAG,MAAM,KAAkB,EAAE;IAElC,4DAA4D;IAC5D,IAAI,IAAI,GACN,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAE7E,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,GAAG,EAAE,CAAC;YACtE,WAAW,EAAE,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,MAAM;QACR,CAAC;IACH,CAAC;IACD,IAAI;QACF,GAAG,KAAK,MAAM;YACZ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;YACzB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC;IAE/C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;YACzC,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC;QACpB,CAAC;QACD,OAAO,KACL,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IACvC,EAA4B,CAAC;IAC/B,CAAC;IACD,OAAO,IAA8B,CAAC;AACxC,CAAC"}
@@ -1,17 +0,0 @@
1
- import type { Hex } from "./is-hex.js";
2
- /**
3
- * Asserts that the size of the given hex or bytes is not greater than the specified size.
4
- * @param hexOrBytes - The hex or bytes to check the size of.
5
- * @param size - The maximum allowed size.
6
- * @throws Error if the size of the hex or bytes is greater than the specified size.
7
- * @example
8
- * ```ts
9
- * import { assertSize } from "thirdweb/utils";
10
- * assertSize("0x1a4", { size: 2 });
11
- * ```
12
- * @internal
13
- */
14
- export declare function assertSize(hexOrBytes: Hex | Uint8Array, { size }: {
15
- size: number;
16
- }): void;
17
- //# sourceMappingURL=assert-size.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-size.d.ts","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/assert-size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,GAAG,GAAG,UAAU,EAC5B,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB,IAAI,CAKN"}
@@ -1,5 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export declare function charCodeToBase16(char: number): number | undefined;
5
- //# sourceMappingURL=charcode-to-base-16.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"charcode-to-base-16.d.ts","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/charcode-to-base-16.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,sBAW5C"}
@@ -1,16 +0,0 @@
1
- import type { Hex } from "./is-hex.js";
2
- type TrimOptions = {
3
- dir?: "left" | "right";
4
- };
5
- type TrimReturnType<TValue extends Uint8Array | Hex> = TValue extends Hex ? Hex : Uint8Array;
6
- /**
7
- * Trims leading or trailing zeros from a hexadecimal string or byte array.
8
- *
9
- * @param hexOrBytes - The hexadecimal string or byte array to trim.
10
- * @param options - The options for trimming. Default is to trim leading zeros.
11
- * @returns The trimmed hexadecimal string or byte array.
12
- * @internal
13
- */
14
- export declare function trim<TValue extends Uint8Array | Hex>(hexOrBytes: TValue, { dir }?: TrimOptions): TrimReturnType<TValue>;
15
- export {};
16
- //# sourceMappingURL=trim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../../../../src/utils/encoding/helpers/trim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvC,KAAK,WAAW,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AACF,KAAK,cAAc,CAAC,MAAM,SAAS,UAAU,GAAG,GAAG,IAAI,MAAM,SAAS,GAAG,GACrE,GAAG,GACH,UAAU,CAAC;AAEf;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,MAAM,SAAS,UAAU,GAAG,GAAG,EAClD,UAAU,EAAE,MAAM,EAClB,EAAE,GAAY,EAAE,GAAE,WAAgB,GACjC,cAAc,CAAC,MAAM,CAAC,CA2BxB"}
@@ -1,47 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { assertSize } from "./assert-size.js";
3
-
4
- describe("assertSize", () => {
5
- it("should not throw an error for hex strings within the specified size", () => {
6
- expect(() => assertSize("0x1a4", { size: 2 })).not.toThrow();
7
- expect(() => assertSize("0x1234", { size: 2 })).not.toThrow();
8
- });
9
-
10
- it("should throw an error for hex strings exceeding the specified size", () => {
11
- expect(() => assertSize("0x123456", { size: 2 })).toThrow(
12
- "Size overflow: 3 > 2",
13
- );
14
- expect(() => assertSize("0xabcdef", { size: 2 })).toThrow(
15
- "Size overflow: 3 > 2",
16
- );
17
- });
18
-
19
- it("should not throw an error for Uint8Array within the specified size", () => {
20
- expect(() =>
21
- assertSize(new Uint8Array([1, 2, 3]), { size: 3 }),
22
- ).not.toThrow();
23
- expect(() => assertSize(new Uint8Array([]), { size: 0 })).not.toThrow();
24
- });
25
-
26
- it("should throw an error for Uint8Array exceeding the specified size", () => {
27
- expect(() => assertSize(new Uint8Array([1, 2, 3, 4]), { size: 3 })).toThrow(
28
- "Size overflow: 4 > 3",
29
- );
30
- });
31
-
32
- it("should not throw an error for empty hex strings", () => {
33
- expect(() => assertSize("0x", { size: 0 })).not.toThrow();
34
- });
35
-
36
- it("should handle boundary conditions correctly", () => {
37
- expect(() => assertSize("0x12", { size: 1 })).not.toThrow();
38
- expect(() => assertSize("0x12", { size: 0 })).toThrow(
39
- "Size overflow: 1 > 0",
40
- );
41
- });
42
-
43
- it("should not throw an error for hex strings exactly at the specified size", () => {
44
- expect(() => assertSize("0x12", { size: 1 })).not.toThrow();
45
- expect(() => assertSize("0x1234", { size: 2 })).not.toThrow();
46
- });
47
- });
@@ -1,24 +0,0 @@
1
- import { byteSize } from "./byte-size.js";
2
- import type { Hex } from "./is-hex.js";
3
-
4
- /**
5
- * Asserts that the size of the given hex or bytes is not greater than the specified size.
6
- * @param hexOrBytes - The hex or bytes to check the size of.
7
- * @param size - The maximum allowed size.
8
- * @throws Error if the size of the hex or bytes is greater than the specified size.
9
- * @example
10
- * ```ts
11
- * import { assertSize } from "thirdweb/utils";
12
- * assertSize("0x1a4", { size: 2 });
13
- * ```
14
- * @internal
15
- */
16
- export function assertSize(
17
- hexOrBytes: Hex | Uint8Array,
18
- { size }: { size: number },
19
- ): void {
20
- const givenSize = byteSize(hexOrBytes);
21
- if (givenSize > size) {
22
- throw new Error(`Size overflow: ${givenSize} > ${size}`);
23
- }
24
- }
@@ -1,39 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { charCodeToBase16 } from "./charcode-to-base-16.js";
3
-
4
- describe("charCodeToBase16", () => {
5
- it("should return correct values for digits (0-9)", () => {
6
- expect(charCodeToBase16("0".charCodeAt(0))).toBe(0);
7
- expect(charCodeToBase16("5".charCodeAt(0))).toBe(5);
8
- expect(charCodeToBase16("9".charCodeAt(0))).toBe(9);
9
- });
10
-
11
- it("should return correct values for uppercase letters (A-F)", () => {
12
- expect(charCodeToBase16("A".charCodeAt(0))).toBe(10);
13
- expect(charCodeToBase16("C".charCodeAt(0))).toBe(12);
14
- expect(charCodeToBase16("F".charCodeAt(0))).toBe(15);
15
- });
16
-
17
- it("should return correct values for lowercase letters (a-f)", () => {
18
- expect(charCodeToBase16("a".charCodeAt(0))).toBe(10);
19
- expect(charCodeToBase16("c".charCodeAt(0))).toBe(12);
20
- expect(charCodeToBase16("f".charCodeAt(0))).toBe(15);
21
- });
22
-
23
- // Test cases for invalid inputs
24
- it("should return undefined for invalid inputs", () => {
25
- expect(charCodeToBase16("G".charCodeAt(0))).toBeUndefined();
26
- expect(charCodeToBase16("z".charCodeAt(0))).toBeUndefined();
27
- expect(charCodeToBase16(" ".charCodeAt(0))).toBeUndefined();
28
- expect(charCodeToBase16("!".charCodeAt(0))).toBeUndefined();
29
- });
30
-
31
- it("should handle edge cases correctly", () => {
32
- expect(charCodeToBase16("0".charCodeAt(0) - 1)).toBeUndefined(); // Just below '0'
33
- expect(charCodeToBase16("9".charCodeAt(0) + 1)).toBeUndefined(); // Just above '9'
34
- expect(charCodeToBase16("A".charCodeAt(0) - 1)).toBeUndefined(); // Just below 'A'
35
- expect(charCodeToBase16("F".charCodeAt(0) + 1)).toBeUndefined(); // Just above 'F'
36
- expect(charCodeToBase16("a".charCodeAt(0) - 1)).toBeUndefined(); // Just below 'a'
37
- expect(charCodeToBase16("f".charCodeAt(0) + 1)).toBeUndefined(); // Just above 'f'
38
- });
39
- });
@@ -1,24 +0,0 @@
1
- const charCodeMap = {
2
- zero: 48,
3
- nine: 57,
4
- A: 65,
5
- F: 70,
6
- a: 97,
7
- f: 102,
8
- } as const;
9
-
10
- /**
11
- * @internal
12
- */
13
- export function charCodeToBase16(char: number) {
14
- if (char >= charCodeMap.zero && char <= charCodeMap.nine) {
15
- return char - charCodeMap.zero;
16
- }
17
- if (char >= charCodeMap.A && char <= charCodeMap.F) {
18
- return char - (charCodeMap.A - 10);
19
- }
20
- if (char >= charCodeMap.a && char <= charCodeMap.f) {
21
- return char - (charCodeMap.a - 10);
22
- }
23
- return undefined;
24
- }
@@ -1,48 +0,0 @@
1
- import type { Hex } from "./is-hex.js";
2
-
3
- type TrimOptions = {
4
- dir?: "left" | "right";
5
- };
6
- type TrimReturnType<TValue extends Uint8Array | Hex> = TValue extends Hex
7
- ? Hex
8
- : Uint8Array;
9
-
10
- /**
11
- * Trims leading or trailing zeros from a hexadecimal string or byte array.
12
- *
13
- * @param hexOrBytes - The hexadecimal string or byte array to trim.
14
- * @param options - The options for trimming. Default is to trim leading zeros.
15
- * @returns The trimmed hexadecimal string or byte array.
16
- * @internal
17
- */
18
- export function trim<TValue extends Uint8Array | Hex>(
19
- hexOrBytes: TValue,
20
- { dir = "left" }: TrimOptions = {},
21
- ): TrimReturnType<TValue> {
22
- // biome-ignore lint/suspicious/noExplicitAny: TODO: fix any
23
- let data: any =
24
- typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
25
-
26
- let sliceLength = 0;
27
- for (let i = 0; i < data.length - 1; i++) {
28
- if (data[dir === "left" ? i : data.length - i - 1].toString() === "0") {
29
- sliceLength++;
30
- } else {
31
- break;
32
- }
33
- }
34
- data =
35
- dir === "left"
36
- ? data.slice(sliceLength)
37
- : data.slice(0, data.length - sliceLength);
38
-
39
- if (typeof hexOrBytes === "string") {
40
- if (data.length === 1 && dir === "right") {
41
- data = `${data}0`;
42
- }
43
- return `0x${
44
- data.length % 2 === 1 ? `0${data}` : data
45
- }` as TrimReturnType<TValue>;
46
- }
47
- return data as TrimReturnType<TValue>;
48
- }