@fairblock/stabletrust 1.0.14 → 1.0.16

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
@@ -38,12 +38,12 @@ The following contract addresses are available for confidential transfers on tes
38
38
 
39
39
  | Network(Testnet) | Chain ID | Contract Address |
40
40
  | :--------------- | :------- | :------------------------------------------- |
41
- | Stable | 2201 | `0xb0b461aFA69b715d842c7fAb602f50D4cef83fe5` |
42
- | Arc | 1244 | `0xEa837218c7Ccd9eA1BCfB640e5c6aFE59952b4FA` |
43
- | Base | 84532 | `0x1a06530765e942a1D26B74d9558e9a1EdA615867` |
44
- | Ethereum | 11155111 | `0xABEa3399873b80f528Ee76286087b45ed38Fbf97` |
45
- | Arbitrum | 421614 | `0x2131De660C6be8b535E6f17E171bFf7143E9E9F4` |
46
- | Tempo | 42431 | `0xF3525FF8F592883f8fA2d89EfBe85637955Df487` |
41
+ | Stable | 2201 | `0xB96aa42b246a956B170fE426A72fB610E4976f9E` |
42
+ | Arc | 1244 | `0xb20aB54e1c6AE55B0DD11FEB7FFf3fF1E9631f19` |
43
+ | Base | 84532 | `0x962a8A7CD28BfFBb17C4F6Ec388782cca3ffd618` |
44
+ | Ethereum | 11155111 | `0x2E48F3D9b8F4aCA9E6AF0630eaB2ceB7A3f5eEd1` |
45
+ | Arbitrum | 421614 | `0x14Afd604971bee5b5fac52df2d56CaE421519Cc5` |
46
+ | Tempo | 42431 | `0x08B6563C95dfe3a4F5533CAA6F7D55a74FCb4F6c` |
47
47
 
48
48
  ## Usage
49
49
 
@@ -97,21 +97,23 @@ const tempoClient = new ConfidentialTransferClient(
97
97
 
98
98
  **Note on Tempo Chain**: The Tempo network (chainId 42431) uses token-based fees instead of native currency. The SDK automatically handles fee payment using PathUSD when detected.
99
99
 
100
- ### Token Denomination (x100)
100
+ ### Token Denomination
101
101
 
102
- All confidential token amounts in this SDK use a fixed scale of 100. That means the SDK expects amounts in "token \* 100" units for deposit, transfer, and withdraw. When displaying balances, divide by 100.
102
+ When interacting with the SDK for deposit, transfer, and withdraw operations, you should parse the token amount using the underlying token's decimals. When displaying the fetched balance, format it using the token's decimals.
103
103
 
104
- - To deposit 0.1 tokens, send 10 units (0.1 \* 100).
105
- - To display a balance, use $display = raw / 100$.
104
+ - To deposit, transfer, or withdraw tokens, parse the amount using `ethers.parseUnits(amount, tokenDecimals)`.
105
+ - To display a balance, format the raw amount using `ethers.formatUnits(balance.amount, tokenDecimals)`.
106
106
 
107
107
  **Recommended helpers (consistent with examples):**
108
108
 
109
109
  ```javascript
110
- // Use 2 decimals to match x100 scaling
111
- const amountToDeposit = ethers.parseUnits("0.1", 2); // 10
110
+ // Fetch or define your token's decimals (e.g., 6 for USDC)
111
+ const tokenDecimals = 6;
112
+
113
+ const amountToDeposit = ethers.parseUnits("0.1", tokenDecimals);
112
114
  await client.confidentialDeposit(signer, tokenAddress, amountToDeposit);
113
115
 
114
- const amountToTransfer = ethers.parseUnits("0.05", 2); // 5
116
+ const amountToTransfer = ethers.parseUnits("0.05", tokenDecimals);
115
117
  await client.confidentialTransfer(
116
118
  signer,
117
119
  recipientAddress,
@@ -119,7 +121,7 @@ await client.confidentialTransfer(
119
121
  amountToTransfer,
120
122
  );
121
123
 
122
- const amountToWithdraw = ethers.parseUnits("0.02", 2); // 2
124
+ const amountToWithdraw = ethers.parseUnits("0.02", tokenDecimals);
123
125
  await client.withdraw(signer, tokenAddress, amountToWithdraw);
124
126
 
125
127
  const balance = await client.getConfidentialBalance(
@@ -127,7 +129,7 @@ const balance = await client.getConfidentialBalance(
127
129
  privateKey,
128
130
  tokenAddress,
129
131
  );
130
- console.log("Balance:", ethers.formatUnits(balance.amount, 2));
132
+ console.log("Balance:", ethers.formatUnits(balance.amount, tokenDecimals));
131
133
  ```
132
134
 
133
135
  ### Key Functions
@@ -162,9 +164,9 @@ Retrieves the decrypted available and pending balances for a specific token, plu
162
164
  - `privateKey` (string): The private key for decryption.
163
165
  - `tokenAddress` (string): The token contract address.
164
166
  - **Returns**: An object containing:
165
- - `amount` (number): The total (available + pending) in x100 units
166
- - `available` (object): `{ amount, ciphertext }` in x100 units
167
- - `pending` (object): `{ amount, ciphertext }` in x100 units
167
+ - `amount` (bigint): The total (available + pending)
168
+ - `available` (object): `{ amount, ciphertext }`
169
+ - `pending` (object): `{ amount, ciphertext }`
168
170
 
169
171
  #### `confidentialDeposit(signer, tokenAddress, amount, options)`
170
172
 
@@ -173,7 +175,7 @@ Deposits a specified amount of ERC20 tokens into the confidential contract, conv
173
175
  - **Parameters**:
174
176
  - `signer` (ethers.Signer): The transaction signer.
175
177
  - `tokenAddress` (string): The contract address of the ERC20 token.
176
- - `amount` (bigint | string | number): The amount to deposit in x100 units.
178
+ - `amount` (bigint | string | number): The amount to deposit, parsed with token decimals.
177
179
  - `options` (object, optional):
178
180
  - `waitForFinalization` (boolean): Wait for deposit finalization. Default: `true`
179
181
  - **Returns**: A transaction receipt.
@@ -186,7 +188,7 @@ Executes a confidential transfer of tokens from the sender to a recipient. The a
186
188
  - `signer` (ethers.Signer): The sender's signer.
187
189
  - `recipientAddress` (string): The public address of the recipient.
188
190
  - `tokenAddress` (string): The token contract address.
189
- - `amount` (number): The amount to transfer in x100 units.
191
+ - `amount` (bigint | string | number): The amount to transfer, parsed with token decimals.
190
192
  - `options` (object, optional):
191
193
  - `useOffchainVerify` (boolean): Use offchain verification. Default: `false`
192
194
  - `waitForFinalization` (boolean): Wait for transfer finalization. Default: `true`
@@ -199,7 +201,7 @@ Withdraws funds from the confidential "available" balance back to the public lay
199
201
  - **Parameters**:
200
202
  - `signer` (ethers.Signer): The user's signer.
201
203
  - `tokenAddress` (string): The token contract address.
202
- - `amount` (number): The amount to withdraw in x100 units.
204
+ - `amount` (bigint | string | number): The amount to withdraw, parsed with token decimals.
203
205
  - `options` (object, optional):
204
206
  - `useOffchainVerify` (boolean): Use offchain verification. Default: `false`
205
207
  - `waitForFinalization` (boolean): Wait for withdrawal finalization. Default: `true`
@@ -288,7 +290,7 @@ When using the StableTrust SDK, follow these best practices to ensure the securi
288
290
 
289
291
  5. **Balance Verification**
290
292
 
291
- - Check available balance before initiating transfers (values are in x100 units)
293
+ - Check available balance before initiating transfers
292
294
  - Be aware of transaction fees that may vary by network
293
295
  - On Tempo chain, ensure sufficient PathUSD balance for fee payment
294
296
 
@@ -1,7 +1,7 @@
1
1
  import { ethers } from "ethers";
2
2
  import dotenv from "dotenv";
3
3
  import { ConfidentialTransferClient } from "@fairblock/stabletrust";
4
-
4
+ import { ERC20_ABI } from "./constants.js";
5
5
  dotenv.config();
6
6
 
7
7
  /**
@@ -11,9 +11,6 @@ dotenv.config();
11
11
  * https://docs.fairblock.network/docs/confidential_transfers/technical_overview
12
12
  */
13
13
 
14
- // Optional override for custom confidential contract deployments.
15
- const CONTRACT_ADDRESS =
16
- process.env.CONTRACT_ADDRESS || "0xb0b461aFA69b715d842c7fAb602f50D4cef83fe5";
17
14
  // Standard ERC20 token contract. Any ERC20 on this chain ID can be used.
18
15
  const TOKEN_ADDRESS =
19
16
  process.env.TOKEN_ADDRESS || "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9";
@@ -42,11 +39,7 @@ async function trackPerformance(actionName, action) {
42
39
  async function main() {
43
40
  console.log("=== Starting Confidential Flow Performance Test ===\n");
44
41
 
45
- const client = new ConfidentialTransferClient(
46
- RPC_URL,
47
- CONTRACT_ADDRESS,
48
- Number(CHAIN_ID),
49
- );
42
+ const client = new ConfidentialTransferClient(RPC_URL, Number(CHAIN_ID));
50
43
 
51
44
  const provider = new ethers.JsonRpcProvider(RPC_URL);
52
45
  const sender = new ethers.Wallet(process.env.SENDER_PRIVATE_KEY, provider);
@@ -55,6 +48,9 @@ async function main() {
55
48
  provider,
56
49
  );
57
50
 
51
+ const tokenContract = new ethers.Contract(TOKEN_ADDRESS, ERC20_ABI, provider);
52
+ const tokenDecimals = await tokenContract.decimals();
53
+
58
54
  console.log("Sender Address:", sender.address);
59
55
  console.log("Recipient Address:", recipient.address);
60
56
 
@@ -62,7 +58,7 @@ async function main() {
62
58
  const recipientKeys = await client.ensureAccount(recipient);
63
59
 
64
60
  // 1. DEPOSIT PHASE
65
- const depositAmount = ethers.parseUnits("0.1", 2);
61
+ const depositAmount = ethers.parseUnits("0.1", tokenDecimals);
66
62
  const senderConfidentialBalanceBefore = await client.getConfidentialBalance(
67
63
  sender.address,
68
64
  senderKeys.privateKey,
@@ -71,7 +67,7 @@ async function main() {
71
67
 
72
68
  console.log(
73
69
  "Sender Confidential Balance (Pre-Deposit):",
74
- ethers.formatUnits(senderConfidentialBalanceBefore.amount, 2),
70
+ ethers.formatUnits(senderConfidentialBalanceBefore.amount, tokenDecimals),
75
71
  );
76
72
 
77
73
  console.log("Depositing 0.1 tokens into confidential contract...");
@@ -91,11 +87,11 @@ async function main() {
91
87
  );
92
88
  console.log(
93
89
  "Sender Confidential Balance (Post-Deposit):",
94
- ethers.formatUnits(senderConfidentialBalanceAfterDep.amount, 2),
90
+ ethers.formatUnits(senderConfidentialBalanceAfterDep.amount, tokenDecimals),
95
91
  );
96
92
 
97
93
  // 2. TRANSFER PHASE
98
- const transferAmount = ethers.parseUnits("0.05", 2);
94
+ const transferAmount = ethers.parseUnits("0.05", tokenDecimals);
99
95
  const senderConfidentialBalanceBeforeTx = await client.getConfidentialBalance(
100
96
  sender.address,
101
97
  senderKeys.privateKey,
@@ -111,11 +107,14 @@ async function main() {
111
107
 
112
108
  console.log(
113
109
  "Sender Confidential Balance (Pre-Transfer):",
114
- ethers.formatUnits(senderConfidentialBalanceBeforeTx.amount, 2),
110
+ ethers.formatUnits(senderConfidentialBalanceBeforeTx.amount, tokenDecimals),
115
111
  );
116
112
  console.log(
117
113
  "Recipient Confidential Balance (Pre-Transfer):",
118
- ethers.formatUnits(recipientConfidentialBalanceBeforeTx.amount, 2),
114
+ ethers.formatUnits(
115
+ recipientConfidentialBalanceBeforeTx.amount,
116
+ tokenDecimals,
117
+ ),
119
118
  );
120
119
 
121
120
  console.log("Transferring 0.05 tokens confidentially to recipient...");
@@ -152,22 +151,22 @@ async function main() {
152
151
 
153
152
  console.log(
154
153
  "Sender Confidential Balance (Post-Transfer):",
155
- ethers.formatUnits(senderConfidentialBalanceAfterTx.amount, 2),
154
+ ethers.formatUnits(senderConfidentialBalanceAfterTx.amount, tokenDecimals),
156
155
  );
157
156
  console.log(
158
157
  "Recipient Confidential Balance (Post-Transfer):",
159
- ethers.formatUnits(recipientConfidentialBalanceAfterTx.amount, 2),
158
+ ethers.formatUnits(
159
+ recipientConfidentialBalanceAfterTx.amount,
160
+ tokenDecimals,
161
+ ),
160
162
  "\n",
161
163
  );
162
164
 
163
165
  // 3. WITHDRAW PHASE
164
- const withdrawAmount = ethers.parseUnits("0.05", 2);
166
+ const withdrawAmount = ethers.parseUnits("0.05", tokenDecimals);
165
167
  console.log(
166
168
  "Withdrawing 0.05 tokens from confidential contract to recipient's public balance...",
167
169
  );
168
- const withdrawRes = await trackPerformance("WITHDRAW_TOKENS", () =>
169
- client.withdraw(recipient, TOKEN_ADDRESS, withdrawAmount),
170
- );
171
170
  let recipientConfidentialBalanceBeforeWithdraw =
172
171
  await client.getConfidentialBalance(
173
172
  recipient.address,
@@ -177,8 +176,15 @@ async function main() {
177
176
 
178
177
  console.log(
179
178
  "Recipient Confidential Balance (Pre-Withdraw):",
180
- ethers.formatUnits(recipientConfidentialBalanceBeforeWithdraw.amount, 2),
179
+ ethers.formatUnits(
180
+ recipientConfidentialBalanceBeforeWithdraw.amount,
181
+ tokenDecimals,
182
+ ),
181
183
  );
184
+ const withdrawRes = await trackPerformance("WITHDRAW_TOKENS", () =>
185
+ client.withdraw(recipient, TOKEN_ADDRESS, withdrawAmount),
186
+ );
187
+
182
188
  const withdrawHash = withdrawRes.result.hash;
183
189
  console.log(`Transaction Hash: ${withdrawHash}`);
184
190
  console.log(`View Transaction: ${EXPLORER_URL}${withdrawHash}`);
@@ -192,7 +198,10 @@ async function main() {
192
198
 
193
199
  console.log(
194
200
  "Recipient Confidential Balance (Final):",
195
- ethers.formatUnits(recipientConfidentialBalanceAfterWithdraw.amount, 2),
201
+ ethers.formatUnits(
202
+ recipientConfidentialBalanceAfterWithdraw.amount,
203
+ tokenDecimals,
204
+ ),
196
205
  );
197
206
 
198
207
  console.log("\n=== Complete Flow Execution Finished ===");
@@ -0,0 +1,6 @@
1
+ export const ERC20_ABI = [
2
+ "function approve(address spender, uint256 amount) external returns (bool)",
3
+ "function allowance(address owner, address spender) external view returns (uint256)",
4
+ "function balanceOf(address account) external view returns (uint256)",
5
+ "function decimals() external view returns (uint8)",
6
+ ];
@@ -19,9 +19,10 @@ async function minimalFlow() {
19
19
  // 2. Initialize Confidential Accounts (View Keys)
20
20
  await client.ensureAccount(sender);
21
21
  await client.ensureAccount(recipient);
22
-
22
+ const tokenContract = new ethers.Contract(TOKEN_ADDRESS, ERC20_ABI, provider);
23
+ const tokenDecimals = await tokenContract.decimals();
23
24
  const TOKEN = "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9";
24
- const amount = ethers.parseUnits("0.1", 2);
25
+ const amount = ethers.parseUnits("0.1", tokenDecimals);
25
26
  let res;
26
27
  // 3. DEPOSIT: Move public ERC20 into the confidential contract
27
28
  res = await client.confidentialDeposit(sender, TOKEN, amount);
@@ -32,11 +33,15 @@ async function minimalFlow() {
32
33
  sender,
33
34
  recipient.address,
34
35
  TOKEN,
35
- ethers.parseUnits("0.05", 2),
36
+ ethers.parseUnits("0.05", tokenDecimals),
36
37
  );
37
38
  console.log("Transfer TX Hash:", EXPLORER_URL + res.hash);
38
39
  // 5. WITHDRAW: Convert confidential balance back to public ERC20
39
- res = await client.withdraw(recipient, TOKEN, ethers.parseUnits("0.05", 2));
40
+ res = await client.withdraw(
41
+ recipient,
42
+ TOKEN,
43
+ ethers.parseUnits("0.05", tokenDecimals),
44
+ );
40
45
  console.log("Withdraw TX Hash:", EXPLORER_URL + res.hash);
41
46
  console.log("Confidential flow complete.");
42
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fairblock/stabletrust",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "SDK for confidential transfers using homomorphic encryption and zero-knowledge proofs",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/client.js CHANGED
@@ -288,18 +288,24 @@ export class ConfidentialTransferClient {
288
288
  }
289
289
 
290
290
  if ((!c1 || c1 === "0x") && (!c2 || c2 === "0x")) {
291
- return { amount: 0, ciphertext: null };
291
+ return { amount: 0n, ciphertext: null };
292
292
  }
293
293
 
294
294
  const wasm = await this._getWasm();
295
295
  const ciphertext = combineCiphertext(c1, c2);
296
- const amount = decryptCiphertext(
296
+ const contractAmount = decryptCiphertext(
297
297
  ciphertext,
298
298
  privateKey,
299
299
  wasm.decrypt_ciphertext,
300
300
  );
301
+ const tokenAmount = ethers.formatUnits(contractAmount, 2);
302
+ const tokenContract = this._getTokenContract(tokenAddress);
303
+ const tokenUnits = await tokenContract.decimals();
301
304
 
302
- return { amount, ciphertext };
305
+ return {
306
+ amount: ethers.parseUnits(tokenAmount, Number(tokenUnits)),
307
+ ciphertext,
308
+ };
303
309
  } catch (error) {
304
310
  throw new Error(`Failed to get balance: ${error.message}`);
305
311
  }
@@ -360,8 +366,11 @@ export class ConfidentialTransferClient {
360
366
  tokenAddress,
361
367
  "deposit",
362
368
  );
363
- const depositAmount = BigInt(amount);
369
+
364
370
  const tokenContract = this._getTokenContract(tokenAddress);
371
+ const tokenDecimals = await tokenContract.decimals();
372
+ const depositAmount =
373
+ (BigInt(amount) * 100n) / 10n ** BigInt(tokenDecimals);
365
374
 
366
375
  // Check token balance and allowance in parallel
367
376
  const [tokenBalance, allowance] = await Promise.all([
@@ -370,11 +379,11 @@ export class ConfidentialTransferClient {
370
379
  ]);
371
380
  if (tokenBalance < depositAmount) {
372
381
  throw new Error(
373
- `Insufficient token balance. Required: ${depositAmount}, Available: ${tokenBalance}`,
382
+ `Insufficient token balance. Required: ${amount}, Available: ${tokenBalance}`,
374
383
  );
375
384
  }
376
385
 
377
- if (allowance < depositAmount) {
386
+ if (allowance < amount) {
378
387
  const approveTx = await tokenContract
379
388
  .connect(wallet)
380
389
  .approve(this.config.contractAddress, ethers.MaxUint256);
@@ -442,6 +451,10 @@ export class ConfidentialTransferClient {
442
451
  if (!amount || amount <= 0) {
443
452
  throw new Error("Transfer amount must be greater than 0");
444
453
  }
454
+ const tokenContract = this._getTokenContract(tokenAddress);
455
+ const tokenDecimals = await tokenContract.decimals();
456
+ const transferAmount =
457
+ (BigInt(amount) * 100n) / 10n ** BigInt(tokenDecimals);
445
458
 
446
459
  const senderAddress = await senderWallet.getAddress();
447
460
 
@@ -498,28 +511,28 @@ export class ConfidentialTransferClient {
498
511
  "Current balance ciphertext is required. Did you call getConfidentialBalance()?",
499
512
  );
500
513
  }
501
- if (balanceSummary.amount < amount) {
514
+ if (balanceSummary.amount < BigInt(amount)) {
502
515
  throw new Error(
503
516
  `Insufficient balance. Required: ${amount}, Total: ${balanceSummary.amount}`,
504
517
  );
505
518
  }
506
519
  if (
507
520
  derivedCurrentBalance === undefined ||
508
- derivedCurrentBalance < amount
521
+ derivedCurrentBalance < BigInt(amount)
509
522
  ) {
510
523
  throw new Error(
511
524
  `Insufficient balance. Required: ${amount}, Available: ${derivedCurrentBalance}`,
512
525
  );
513
526
  }
514
527
 
528
+ const currentBalanceContractScale =
529
+ (BigInt(derivedCurrentBalance) * 100n) / 10n ** BigInt(tokenDecimals);
530
+
515
531
  // Generate proof
516
532
  const proofInput = {
517
533
  current_balance_ciphertext: derivedCurrentBalanceCiphertext,
518
- current_balance:
519
- typeof derivedCurrentBalance === "bigint"
520
- ? derivedCurrentBalance.toString()
521
- : derivedCurrentBalance,
522
- transfer_amount: typeof amount === "bigint" ? Number(amount) : amount,
534
+ current_balance: Number(currentBalanceContractScale),
535
+ transfer_amount: Number(transferAmount),
523
536
  source_keypair: derivedSenderKeys.privateKey,
524
537
  destination_pubkey: derivedRecipientPublicKey,
525
538
  };
@@ -753,6 +766,11 @@ export class ConfidentialTransferClient {
753
766
  throw new Error("Withdrawal amount must be greater than 0");
754
767
  }
755
768
 
769
+ const tokenContract = this._getTokenContract(tokenAddress);
770
+ const tokenDecimals = await tokenContract.decimals();
771
+ const withdrawAmount =
772
+ (BigInt(amount) * 100n) / 10n ** BigInt(tokenDecimals);
773
+
756
774
  // Auto-derive keys
757
775
  const derivedKeys = await this._deriveKeys(wallet);
758
776
  if (!derivedKeys?.privateKey) {
@@ -780,25 +798,25 @@ export class ConfidentialTransferClient {
780
798
  "Current balance ciphertext is required. Did you call getConfidentialBalance()?",
781
799
  );
782
800
  }
783
- if (balanceSummary.amount < amount) {
801
+ if (balanceSummary.amount < BigInt(amount)) {
784
802
  throw new Error(
785
803
  `Insufficient balance. Required: ${amount}, Total: ${balanceSummary.amount}`,
786
804
  );
787
805
  }
788
- if (currentBalance === undefined || currentBalance < amount) {
806
+ if (currentBalance === undefined || currentBalance < BigInt(amount)) {
789
807
  throw new Error(
790
808
  `Insufficient balance. Required: ${amount}, Available: ${currentBalance}`,
791
809
  );
792
810
  }
793
811
 
812
+ const currentBalanceContractScale =
813
+ (BigInt(currentBalance) * 100n) / 10n ** BigInt(tokenDecimals);
814
+
794
815
  // Generate withdrawal proof
795
816
  const withdrawInput = {
796
817
  current_balance_ciphertext: currentBalanceCiphertext,
797
- current_balance:
798
- typeof currentBalance === "bigint"
799
- ? Number(currentBalance)
800
- : currentBalance,
801
- withdraw_amount: typeof amount === "bigint" ? Number(amount) : amount,
818
+ current_balance: Number(currentBalanceContractScale),
819
+ withdraw_amount: Number(withdrawAmount),
802
820
  keypair: derivedKeys.privateKey,
803
821
  };
804
822
 
@@ -819,7 +837,7 @@ export class ConfidentialTransferClient {
819
837
  .connect(wallet)
820
838
  .withdraw(
821
839
  tokenAddress,
822
- BigInt(amount),
840
+ BigInt(withdrawAmount),
823
841
  ethers.getBytes(encodeWithdrawProof(proof.data)),
824
842
  useOffchainVerify,
825
843
  );
package/src/constants.js CHANGED
@@ -18,18 +18,19 @@ export const ERC20_ABI = [
18
18
  "function approve(address spender, uint256 amount) external returns (bool)",
19
19
  "function allowance(address owner, address spender) external view returns (uint256)",
20
20
  "function balanceOf(address account) external view returns (uint256)",
21
+ "function decimals() external view returns (uint8)",
21
22
  ];
22
23
 
23
24
  export const TEMPO_FEE_TOKEN_ADDRESS =
24
25
  "0x20c0000000000000000000000000000000000000";
25
26
 
26
27
  export const STABLETRUST_CONTRACTS_BY_CHAIN_ID = Object.freeze({
27
- 2201: "0xb0b461aFA69b715d842c7fAb602f50D4cef83fe5", //Stable
28
- 1244: "0xEa837218c7Ccd9eA1BCfB640e5c6aFE59952b4FA", //Arc
29
- 84532: "0x1a06530765e942a1D26B74d9558e9a1EdA615867", //Base
30
- 11155111: "0xABEa3399873b80f528Ee76286087b45ed38Fbf97", //Ethereum
31
- 421614: "0x2131De660C6be8b535E6f17E171bFf7143E9E9F4", //Arbitrum
32
- 42431: "0xF3525FF8F592883f8fA2d89EfBe85637955Df487", //Tempo
28
+ 2201: "0xB96aa42b246a956B170fE426A72fB610E4976f9E", //Stable
29
+ 1244: "0xb20aB54e1c6AE55B0DD11FEB7FFf3fF1E9631f19", //Arc
30
+ 84532: "0x962a8A7CD28BfFBb17C4F6Ec388782cca3ffd618", //Base
31
+ 11155111: "0x2E48F3D9b8F4aCA9E6AF0630eaB2ceB7A3f5eEd1", //Ethereum
32
+ 421614: "0x14Afd604971bee5b5fac52df2d56CaE421519Cc5", //Arbitrum
33
+ 42431: "0x08B6563C95dfe3a4F5533CAA6F7D55a74FCb4F6c", //Tempo
33
34
  });
34
35
 
35
36
  export function getStableTrustContractAddress(chainId) {
package/src/crypto.js CHANGED
@@ -11,7 +11,7 @@ import { ethers } from "ethers";
11
11
  */
12
12
  export async function deriveKeys(wallet, config, generateKeypair) {
13
13
  const domain = {
14
- name: "Fairblock",
14
+ name: "ConfidentialTokens",
15
15
  version: "1",
16
16
  chainId: config.chainId,
17
17
  verifyingContract: config.contractAddress,
@@ -26,15 +26,15 @@ export async function deriveKeys(wallet, config, generateKeypair) {
26
26
  };
27
27
 
28
28
  const contextHash = ethers.keccak256(
29
- ethers.solidityPacked(
29
+ ethers.AbiCoder.defaultAbiCoder().encode(
30
30
  ["uint256", "address", "address", "string"],
31
31
  [config.chainId, config.contractAddress, ethers.ZeroAddress, "main"],
32
32
  ),
33
33
  );
34
-
34
+ const userAddress = wallet.address.toLowerCase();
35
35
  const message = {
36
36
  purpose: "homomorphic-key-derive-v1",
37
- user: wallet.address,
37
+ user: userAddress,
38
38
  context: contextHash,
39
39
  };
40
40
 
@@ -42,7 +42,7 @@ export async function deriveKeys(wallet, config, generateKeypair) {
42
42
  const domainContext = JSON.stringify({
43
43
  chainId: config.chainId.toString(),
44
44
  verifyingContract: config.contractAddress,
45
- user: wallet.address,
45
+ user: userAddress,
46
46
  purpose: "homomorphic-key-derive-v1",
47
47
  version: "1",
48
48
  });