@buildersgarden/siwa 0.0.3 → 0.0.4

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 (3) hide show
  1. package/dist/keystore.js +53 -5
  2. package/package.json +11 -6
  3. package/LICENSE +0 -21
package/dist/keystore.js CHANGED
@@ -323,6 +323,46 @@ export async function signMessage(message, config = {}) {
323
323
  const signature = await account.signMessage({ message });
324
324
  return { signature, address: account.address };
325
325
  }
326
+ /**
327
+ * Parse a numeric value from JSON (string/number) to bigint.
328
+ * Returns undefined for null, undefined, or zero values.
329
+ * Zero is returned as undefined so viem encodes it as empty (0x80 in RLP).
330
+ */
331
+ function parseBigIntFromJson(value) {
332
+ if (value === null || value === undefined)
333
+ return undefined;
334
+ let result;
335
+ if (typeof value === 'bigint') {
336
+ result = value;
337
+ }
338
+ else if (typeof value === 'number') {
339
+ result = BigInt(value);
340
+ }
341
+ else if (typeof value === 'string') {
342
+ // Handle hex strings (0x...) and decimal strings
343
+ result = BigInt(value);
344
+ }
345
+ else {
346
+ return undefined;
347
+ }
348
+ // Return undefined for zero so viem encodes it as empty (0x80)
349
+ // instead of 0x00 which is non-canonical RLP
350
+ return result === 0n ? undefined : result;
351
+ }
352
+ /**
353
+ * Parse a numeric value, keeping zero as 0n (for fields like nonce where 0 is valid).
354
+ */
355
+ function parseBigIntKeepZero(value) {
356
+ if (value === null || value === undefined)
357
+ return undefined;
358
+ if (typeof value === 'bigint')
359
+ return value;
360
+ if (typeof value === 'number')
361
+ return BigInt(value);
362
+ if (typeof value === 'string')
363
+ return BigInt(value);
364
+ return undefined;
365
+ }
326
366
  /**
327
367
  * Sign a transaction.
328
368
  * The private key is loaded, used, and immediately discarded.
@@ -338,24 +378,32 @@ export async function signTransaction(tx, config = {}) {
338
378
  if (!privateKey)
339
379
  throw new Error('No wallet found. Run createWallet() first.');
340
380
  const account = privateKeyToAccount(privateKey);
381
+ // Parse numeric fields from JSON representation (strings) to bigints.
382
+ // For 'value', zero is converted to undefined so viem encodes it as 0x80 (empty)
383
+ // instead of 0x00, which is non-canonical RLP and rejected by nodes.
384
+ const value = parseBigIntFromJson(tx.value);
385
+ const gas = parseBigIntKeepZero(tx.gasLimit ?? tx.gas);
386
+ const maxFeePerGas = parseBigIntKeepZero(tx.maxFeePerGas);
387
+ const maxPriorityFeePerGas = parseBigIntKeepZero(tx.maxPriorityFeePerGas);
388
+ const gasPrice = parseBigIntKeepZero(tx.gasPrice);
341
389
  // Build transaction request for viem
342
390
  const viemTx = {
343
391
  to: tx.to,
344
392
  data: tx.data,
345
- value: tx.value,
393
+ value,
346
394
  nonce: tx.nonce,
347
395
  chainId: tx.chainId,
348
- gas: tx.gasLimit ?? tx.gas,
396
+ gas,
349
397
  };
350
398
  // Handle EIP-1559 vs legacy transactions
351
399
  if (tx.type === 2 || tx.maxFeePerGas !== undefined) {
352
400
  viemTx.type = 'eip1559';
353
- viemTx.maxFeePerGas = tx.maxFeePerGas;
354
- viemTx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas;
401
+ viemTx.maxFeePerGas = maxFeePerGas;
402
+ viemTx.maxPriorityFeePerGas = maxPriorityFeePerGas;
355
403
  }
356
404
  else if (tx.gasPrice !== undefined) {
357
405
  viemTx.type = 'legacy';
358
- viemTx.gasPrice = tx.gasPrice;
406
+ viemTx.gasPrice = gasPrice;
359
407
  }
360
408
  if (tx.accessList) {
361
409
  viemTx.accessList = tx.accessList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildersgarden/siwa",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -37,9 +37,18 @@
37
37
  "files": [
38
38
  "dist"
39
39
  ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/builders-garden/siwa",
43
+ "directory": "packages/siwa"
44
+ },
40
45
  "publishConfig": {
41
46
  "access": "public"
42
47
  },
48
+ "scripts": {
49
+ "build": "tsc",
50
+ "clean": "rm -rf dist"
51
+ },
43
52
  "dependencies": {
44
53
  "@noble/ciphers": "^0.5.0",
45
54
  "@noble/hashes": "^1.4.0",
@@ -48,9 +57,5 @@
48
57
  "devDependencies": {
49
58
  "@types/node": "^25.2.1",
50
59
  "typescript": "^5.5.0"
51
- },
52
- "scripts": {
53
- "build": "tsc",
54
- "clean": "rm -rf dist"
55
60
  }
56
- }
61
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Builders Garden SRL
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.