@fairblock/stabletrust 1.0.20 → 1.0.22
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 +11 -8
- package/examples/complete-flow.js +2 -2
- package/examples/simple-snippets.js +1 -1
- package/package.json +1 -1
- package/src/client.js +5 -5
- package/src/constants.js +2 -2
- package/src/index.d.ts +6 -6
- package/src/index.js +1 -1
- package/src/utils.js +1 -1
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
The
|
|
5
|
+
The Stabletrust SDK by Fairblock provides a robust interface for executing confidential transfers using homomorphic encryption and zero-knowledge proofs. This package enables developers to integrate confidentiality features directly into their applications, allowing for secure token deposits, private transfers, and withdrawals while maintaining the integrity and auditability of the underlying blockchain transactions.
|
|
6
6
|
|
|
7
7
|
For a comprehensive technical understanding of the architecture and cryptographic primitives, please refer to the following documentation:
|
|
8
8
|
|
|
9
9
|
- **Technical Overview**: [Fairblock Confidential Transfers](https://docs.fairblock.network/docs/confidential_transfers/technical_overview)
|
|
10
|
-
- **
|
|
10
|
+
- **Stabletrust Protocol**: [Stabletrust Documentation](https://docs.fairblock.network/docs/confidential_transfers/stabletrust)
|
|
11
11
|
- **Confidential Transactions**: [Transaction Mechanics](https://docs.fairblock.network/docs/confidential_transfers/confidential_transactions)
|
|
12
12
|
|
|
13
13
|
## Requirements
|
|
@@ -39,7 +39,7 @@ The following contract addresses are available for confidential transfers on tes
|
|
|
39
39
|
| Network(Testnet) | Chain ID | Contract Address |
|
|
40
40
|
| :--------------- | :------- | :------------------------------------------- |
|
|
41
41
|
| Stable | 2201 | `0xB96aa42b246a956B170fE426A72fB610E4976f9E` |
|
|
42
|
-
| Arc |
|
|
42
|
+
| Arc | 5042002 | `0xb20aB54e1c6AE55B0DD11FEB7FFf3fF1E9631f19` |
|
|
43
43
|
| Base | 84532 | `0x962a8A7CD28BfFBb17C4F6Ec388782cca3ffd618` |
|
|
44
44
|
| Ethereum | 11155111 | `0x2E48F3D9b8F4aCA9E6AF0630eaB2ceB7A3f5eEd1` |
|
|
45
45
|
| Arbitrum | 421614 | `0x14Afd604971bee5b5fac52df2d56CaE421519Cc5` |
|
|
@@ -57,7 +57,7 @@ Import and initialize the client with your network configuration.
|
|
|
57
57
|
import { ConfidentialTransferClient } from "@fairblock/stabletrust";
|
|
58
58
|
import { ethers } from "ethers";
|
|
59
59
|
|
|
60
|
-
// Configuration for Base Sepolia (uses SDK default
|
|
60
|
+
// Configuration for Base Sepolia (uses SDK default Stabletrust contract for chainId 84532)
|
|
61
61
|
const client = new ConfidentialTransferClient(
|
|
62
62
|
"https://sepolia.base.org",
|
|
63
63
|
84532,
|
|
@@ -69,7 +69,7 @@ If you are using a custom deployment, you can still pass an explicit contract ad
|
|
|
69
69
|
```javascript
|
|
70
70
|
const customClient = new ConfidentialTransferClient(
|
|
71
71
|
"https://sepolia.base.org",
|
|
72
|
-
"
|
|
72
|
+
"0xYourCustomStabletrustContract",
|
|
73
73
|
84532,
|
|
74
74
|
);
|
|
75
75
|
```
|
|
@@ -86,7 +86,10 @@ const stableClient = new ConfidentialTransferClient(
|
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
// Arc testnet
|
|
89
|
-
const arcClient = new ConfidentialTransferClient(
|
|
89
|
+
const arcClient = new ConfidentialTransferClient(
|
|
90
|
+
"https://rpc.arc.xyz",
|
|
91
|
+
5042002,
|
|
92
|
+
);
|
|
90
93
|
|
|
91
94
|
// Tempo (Stablecoin chain with special fee handling)
|
|
92
95
|
const tempoClient = new ConfidentialTransferClient(
|
|
@@ -146,7 +149,7 @@ Fetches account core information from the contract.
|
|
|
146
149
|
|
|
147
150
|
#### `ensureAccount(signer, options)`
|
|
148
151
|
|
|
149
|
-
Initializes or retrieves the cryptographic keys associated with an account. This step is required before performing any confidential operations. Automatically creates the account
|
|
152
|
+
Initializes or retrieves the cryptographic keys associated with an account. This step is required before performing any confidential operations. Automatically creates the account onchain if it doesn't exist.
|
|
150
153
|
|
|
151
154
|
- **Parameters**:
|
|
152
155
|
- `signer` (ethers.Signer): The ethers.js signer instance for the user.
|
|
@@ -266,7 +269,7 @@ The following are estimated execution times for standard operations within the c
|
|
|
266
269
|
|
|
267
270
|
## Security Considerations
|
|
268
271
|
|
|
269
|
-
When using the
|
|
272
|
+
When using the Stabletrust SDK, follow these best practices to ensure the security of your confidential transactions:
|
|
270
273
|
|
|
271
274
|
1. **Private Key Management**
|
|
272
275
|
- Never expose or log private keys or seed phrases
|
|
@@ -21,7 +21,7 @@ const CHAINS = [
|
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
network: "Arc",
|
|
24
|
-
chainId:
|
|
24
|
+
chainId: 5042002,
|
|
25
25
|
tokenAddress: "0x3600000000000000000000000000000000000000",
|
|
26
26
|
rpcUrl: "https://rpc.testnet.arc.network",
|
|
27
27
|
explorerUrl: "https://testnet.arcscan.app/tx/",
|
|
@@ -245,7 +245,7 @@ async function runChainFlow(chain, senderPrivateKey, recipientPrivateKey) {
|
|
|
245
245
|
|
|
246
246
|
const txHash = txRes.result.hash || txRes.result.transactionHash;
|
|
247
247
|
console.log(
|
|
248
|
-
"Status: Confidential Transfer is completed. Transfer amount is hidden
|
|
248
|
+
"Status: Confidential Transfer is completed. Transfer amount is hidden onchain.",
|
|
249
249
|
);
|
|
250
250
|
console.log(`Transaction Hash: ${txHash}`);
|
|
251
251
|
console.log(`View Transaction: ${explorerBaseUrl}${txHash}`);
|
|
@@ -28,7 +28,7 @@ async function minimalFlow() {
|
|
|
28
28
|
// 3. DEPOSIT: Move public ERC20 into the confidential contract
|
|
29
29
|
res = await client.confidentialDeposit(sender, TOKEN, amount);
|
|
30
30
|
console.log("Deposit TX Hash:", EXPLORER_URL + res.hash);
|
|
31
|
-
// 4. TRANSFER: Privacy-preserving transfer (
|
|
31
|
+
// 4. TRANSFER: Privacy-preserving transfer (onchain amount is hidden)
|
|
32
32
|
// This moves funds from Sender's 'Available' to Recipient's 'Pending' balance
|
|
33
33
|
res = await client.confidentialTransfer(
|
|
34
34
|
sender,
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ethers } from "ethers";
|
|
|
2
2
|
import {
|
|
3
3
|
CONTRACT_ABI,
|
|
4
4
|
ERC20_ABI,
|
|
5
|
-
|
|
5
|
+
getStabletrustContractAddress,
|
|
6
6
|
} from "./constants.js";
|
|
7
7
|
import { deriveKeys, decryptCiphertext, combineCiphertext } from "./crypto.js";
|
|
8
8
|
import {
|
|
@@ -45,23 +45,23 @@ export class ConfidentialTransferClient {
|
|
|
45
45
|
|
|
46
46
|
if (typeof contractAddressOrChainId === "number" && chainId === undefined) {
|
|
47
47
|
resolvedChainId = contractAddressOrChainId;
|
|
48
|
-
resolvedContractAddress =
|
|
48
|
+
resolvedContractAddress = getStabletrustContractAddress(resolvedChainId);
|
|
49
49
|
} else {
|
|
50
50
|
resolvedChainId = chainId;
|
|
51
51
|
resolvedContractAddress =
|
|
52
52
|
contractAddressOrChainId ||
|
|
53
|
-
|
|
53
|
+
getStabletrustContractAddress(resolvedChainId);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (!resolvedChainId) {
|
|
57
57
|
throw new Error("chainId is required");
|
|
58
58
|
}
|
|
59
59
|
if (!resolvedContractAddress) {
|
|
60
|
-
const supportedChainIds = [2201,
|
|
60
|
+
const supportedChainIds = [2201, 5042002, 84532, 11155111, 421614, 42431]
|
|
61
61
|
.map(String)
|
|
62
62
|
.join(", ");
|
|
63
63
|
throw new Error(
|
|
64
|
-
`contractAddress is required for chainId ${resolvedChainId}. No default
|
|
64
|
+
`contractAddress is required for chainId ${resolvedChainId}. No default Stabletrust contract is configured for this chain. Supported chainIds: ${supportedChainIds}`,
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
if (!ethers.isAddress(resolvedContractAddress)) {
|
package/src/constants.js
CHANGED
|
@@ -26,13 +26,13 @@ export const TEMPO_FEE_TOKEN_ADDRESS =
|
|
|
26
26
|
|
|
27
27
|
export const STABLETRUST_CONTRACTS_BY_CHAIN_ID = Object.freeze({
|
|
28
28
|
2201: "0xdf43bC80B5b22A858860947d383b6F4d6C81d8EC", //Stable
|
|
29
|
-
|
|
29
|
+
5042002: "0x5d43CE5269Cd46badC67B3664369862F20eC5649", //Arc
|
|
30
30
|
84532: "0xFBEa2AbCf1208E09dd90266fE94Fb76d8BfC34d9", //Base
|
|
31
31
|
11155111: "0x72B87207791996F416D2F3B0dcAcbb07F445C496", //Ethereum
|
|
32
32
|
421614: "0x6C9eDBDd028Fe610b054187A34712714E341D112", //Arbitrum
|
|
33
33
|
42431: "0xE559fB936C69c46E216bf61B07C16bF1a6d444aa", //Tempo
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
export function
|
|
36
|
+
export function getStabletrustContractAddress(chainId) {
|
|
37
37
|
return STABLETRUST_CONTRACTS_BY_CHAIN_ID[Number(chainId)] || null;
|
|
38
38
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ declare module "@fairblock/stabletrust" {
|
|
|
10
10
|
chainId: number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export type
|
|
14
|
-
|
|
|
13
|
+
export type StabletrustChainId =
|
|
14
|
+
| 5042002
|
|
15
15
|
| 2201
|
|
16
16
|
| 42431
|
|
17
17
|
| 84532
|
|
@@ -82,7 +82,7 @@ declare module "@fairblock/stabletrust" {
|
|
|
82
82
|
/**
|
|
83
83
|
* Create a new ConfidentialTransferClient
|
|
84
84
|
* @param rpcUrl RPC endpoint URL
|
|
85
|
-
* @param chainId Chain ID (uses default
|
|
85
|
+
* @param chainId Chain ID (uses default Stabletrust contract for known networks)
|
|
86
86
|
*/
|
|
87
87
|
constructor(rpcUrl: string, chainId: number);
|
|
88
88
|
|
|
@@ -233,12 +233,12 @@ declare module "@fairblock/stabletrust" {
|
|
|
233
233
|
export const ERC20_ABI: any[];
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
236
|
+
* Stabletrust contract addresses by chain id
|
|
237
237
|
*/
|
|
238
238
|
export const STABLETRUST_CONTRACTS_BY_CHAIN_ID: Record<number, string>;
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
|
-
* Resolve
|
|
241
|
+
* Resolve Stabletrust contract address by chain id
|
|
242
242
|
*/
|
|
243
|
-
export function
|
|
243
|
+
export function getStabletrustContractAddress(chainId: number): string | null;
|
|
244
244
|
}
|
package/src/index.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -56,7 +56,7 @@ export function logTransaction(hash, explorerUrl, isConfidential = false) {
|
|
|
56
56
|
console.log(`Transaction submitted: ${explorerUrl}${hash}`);
|
|
57
57
|
if (isConfidential) {
|
|
58
58
|
console.log(
|
|
59
|
-
`Note: This is a confidential transaction - the amount is not visible
|
|
59
|
+
`Note: This is a confidential transaction - the amount is not visible onchain.`,
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
}
|