@altiuslabs/tx-sdk 0.1.4 → 0.1.6

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.
package/README.md CHANGED
@@ -73,10 +73,9 @@ import {
73
73
  USDA_ADDRESS,
74
74
  FEE_TOKEN_FACTORY_ADDRESS,
75
75
  FEE_MANAGER_ADDRESS,
76
- ALT_FEE_TOKEN_ADDRESS,
77
76
  BASE_FEE_ATTO,
78
77
  DEFAULT_GAS_LIMIT,
79
- } from '@altius/tx-sdk/constants';
78
+ } from '@altiuslabs/tx-sdk/constants';
80
79
  ```
81
80
 
82
81
  ## Security
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altiuslabs/tx-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "SDK for signing and sending Altius USD multi-token transactions",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/constants.js CHANGED
@@ -36,11 +36,6 @@ export const FEE_TOKEN_FACTORY_ADDRESS = '0xa17000000000000000000000000000000000
36
36
  */
37
37
  export const FEE_MANAGER_ADDRESS = '0xFE0000000000000000000000000000000000000001';
38
38
 
39
- /**
40
- * Alternative fee token for testing (index 2)
41
- */
42
- export const ALT_FEE_TOKEN_ADDRESS = '0xa170000000000000000000000000000000000002';
43
-
44
39
  /**
45
40
  * Fee token prefix (10 bytes) for validation
46
41
  */
@@ -55,7 +50,6 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
55
50
  export const VALID_ADDRESSES = {
56
51
  USDA: USDA_ADDRESS,
57
52
  FACTORY: FEE_TOKEN_FACTORY_ADDRESS,
58
- ALT_TOKEN: ALT_FEE_TOKEN_ADDRESS,
59
53
  };
60
54
 
61
55
  // Invalid addresses for testing
package/src/index.js CHANGED
@@ -25,5 +25,8 @@ export { NonceManager, create_nonce_manager } from './nonce.js';
25
25
  // High-level client
26
26
  export { TxClient, TxClientBuilder, create_tx_client } from './client.js';
27
27
 
28
+ // Utilities
29
+ export { keccak256, pad_hex, num_to_hex, rlp_encode, transaction_hash, computeFeeTokenAddress, isReservedAddress } from './utils.js';
30
+
28
31
  // Constants
29
32
  export * from './constants.js';
package/src/utils.js CHANGED
@@ -56,3 +56,64 @@ export function rlp_encode(items) {
56
56
  export function transaction_hash(signed_tx) {
57
57
  return keccak256(signed_tx);
58
58
  }
59
+
60
+ // ============================================================================
61
+ // Fee Token Address Computation
62
+ // ============================================================================
63
+
64
+ // Altius fee token prefix (10 bytes): 0xA1700000...
65
+ const FEE_TOKEN_PREFIX_BYTES = [0xA1, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
66
+
67
+ /**
68
+ * Compute deterministic fee token address.
69
+ *
70
+ * Address = prefix(10B) || keccak256(creator, salt)[:10]
71
+ *
72
+ * @param {string} creator - Creator address (0x-prefixed hex)
73
+ * @param {string} salt - Salt as 0x-prefixed hex (32 bytes) or B256
74
+ * @returns {{address: string, index: bigint}} Computed address and lower 8 bytes as index
75
+ */
76
+ export function computeFeeTokenAddress(creator, salt) {
77
+ // Clean addresses
78
+ const creatorClean = creator.startsWith('0x') ? creator.slice(2) : creator;
79
+ const saltClean = salt.startsWith('0x') ? salt.slice(2) : salt;
80
+
81
+ // RLP encode (creator, salt) - same as Rust implementation
82
+ const creatorBuf = Buffer.from(creatorClean, 'hex');
83
+ const saltBuf = Buffer.from(saltClean, 'hex');
84
+ const rlpEncoded = RLP.encode([creatorBuf, saltBuf]);
85
+
86
+ // Keccak256 hash
87
+ const hash = sha3.keccak_256(rlpEncoded);
88
+ const hashBytes = Buffer.from(hash, 'hex');
89
+
90
+ // Build address: prefix(10B) + hash[:10](10B)
91
+ const addressBytes = Buffer.alloc(20);
92
+ for (let i = 0; i < 10; i++) {
93
+ addressBytes[i] = FEE_TOKEN_PREFIX_BYTES[i];
94
+ }
95
+ for (let i = 0; i < 10; i++) {
96
+ addressBytes[10 + i] = hashBytes[i];
97
+ }
98
+
99
+ // Compute index from lower 8 bytes
100
+ const lower8 = hashBytes.slice(0, 8);
101
+ const index = BigInt('0x' + lower8.toString('hex'));
102
+
103
+ return {
104
+ address: '0x' + addressBytes.toString('hex'),
105
+ index,
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Check if address is in reserved range (index < 256)
111
+ * @param {string} address - Address to check
112
+ * @param {string} creator - Creator address used for computation
113
+ * @param {string} salt - Salt used for computation
114
+ * @returns {boolean} True if reserved
115
+ */
116
+ export function isReservedAddress(address, creator, salt) {
117
+ const { index } = computeFeeTokenAddress(creator, salt);
118
+ return index < 256n;
119
+ }