@bitshard.io/bitshard-sdk 0.0.1
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/dist/BitShardSDK.d.ts +156 -0
- package/dist/BitShardSDK.d.ts.map +1 -0
- package/dist/BitShardSDK.js +350 -0
- package/dist/BitShardSDK.js.map +1 -0
- package/dist/chains/bitcoin/BitcoinChain.d.ts +6 -0
- package/dist/chains/bitcoin/BitcoinChain.d.ts.map +1 -0
- package/dist/chains/bitcoin/BitcoinChain.js +10 -0
- package/dist/chains/bitcoin/BitcoinChain.js.map +1 -0
- package/dist/chains/config.d.ts +5 -0
- package/dist/chains/config.d.ts.map +1 -0
- package/dist/chains/config.js +7 -0
- package/dist/chains/config.js.map +1 -0
- package/dist/chains/evm/EVMChain.d.ts +6 -0
- package/dist/chains/evm/EVMChain.d.ts.map +1 -0
- package/dist/chains/evm/EVMChain.js +10 -0
- package/dist/chains/evm/EVMChain.js.map +1 -0
- package/dist/core/DKLSParty.d.ts +132 -0
- package/dist/core/DKLSParty.d.ts.map +1 -0
- package/dist/core/DKLSParty.js +267 -0
- package/dist/core/DKLSParty.js.map +1 -0
- package/dist/core/DKLSService.d.ts +83 -0
- package/dist/core/DKLSService.d.ts.map +1 -0
- package/dist/core/DKLSService.js +325 -0
- package/dist/core/DKLSService.js.map +1 -0
- package/dist/core/ThresholdConfig.d.ts +76 -0
- package/dist/core/ThresholdConfig.d.ts.map +1 -0
- package/dist/core/ThresholdConfig.js +127 -0
- package/dist/core/ThresholdConfig.js.map +1 -0
- package/dist/core/types.d.ts +238 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -0
- package/dist/crypto/addresses.d.ts +82 -0
- package/dist/crypto/addresses.d.ts.map +1 -0
- package/dist/crypto/addresses.js +242 -0
- package/dist/crypto/addresses.js.map +1 -0
- package/dist/crypto/elliptic.d.ts +19 -0
- package/dist/crypto/elliptic.d.ts.map +1 -0
- package/dist/crypto/elliptic.js +114 -0
- package/dist/crypto/elliptic.js.map +1 -0
- package/dist/crypto/encoding.d.ts +111 -0
- package/dist/crypto/encoding.d.ts.map +1 -0
- package/dist/crypto/encoding.js +224 -0
- package/dist/crypto/encoding.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/protocols/keygen.d.ts +6 -0
- package/dist/protocols/keygen.d.ts.map +1 -0
- package/dist/protocols/keygen.js +12 -0
- package/dist/protocols/keygen.js.map +1 -0
- package/dist/protocols/presignature.d.ts +68 -0
- package/dist/protocols/presignature.d.ts.map +1 -0
- package/dist/protocols/presignature.js +147 -0
- package/dist/protocols/presignature.js.map +1 -0
- package/dist/protocols/refresh.d.ts +5 -0
- package/dist/protocols/refresh.d.ts.map +1 -0
- package/dist/protocols/refresh.js +10 -0
- package/dist/protocols/refresh.js.map +1 -0
- package/dist/protocols/signing.d.ts +7 -0
- package/dist/protocols/signing.d.ts.map +1 -0
- package/dist/protocols/signing.js +12 -0
- package/dist/protocols/signing.js.map +1 -0
- package/dist/rpc/RPCProvider.d.ts +6 -0
- package/dist/rpc/RPCProvider.d.ts.map +1 -0
- package/dist/rpc/RPCProvider.js +6 -0
- package/dist/rpc/RPCProvider.js.map +1 -0
- package/dist/rpc/methods.d.ts +5 -0
- package/dist/rpc/methods.d.ts.map +1 -0
- package/dist/rpc/methods.js +10 -0
- package/dist/rpc/methods.js.map +1 -0
- package/dist/websocket/coordinator.d.ts +6 -0
- package/dist/websocket/coordinator.d.ts.map +1 -0
- package/dist/websocket/coordinator.js +10 -0
- package/dist/websocket/coordinator.js.map +1 -0
- package/dist/websocket/messages.d.ts +9 -0
- package/dist/websocket/messages.d.ts.map +1 -0
- package/dist/websocket/messages.js +7 -0
- package/dist/websocket/messages.js.map +1 -0
- package/dist/websocket/session.d.ts +5 -0
- package/dist/websocket/session.d.ts.map +1 -0
- package/dist/websocket/session.js +7 -0
- package/dist/websocket/session.js.map +1 -0
- package/dist/wire/format.d.ts +8 -0
- package/dist/wire/format.d.ts.map +1 -0
- package/dist/wire/format.js +11 -0
- package/dist/wire/format.js.map +1 -0
- package/dist/wire/validation.d.ts +6 -0
- package/dist/wire/validation.d.ts.map +1 -0
- package/dist/wire/validation.js +13 -0
- package/dist/wire/validation.js.map +1 -0
- package/package.json +67 -0
- package/src/BitShardSDK.ts +428 -0
- package/src/chains/bitcoin/BitcoinChain.ts +7 -0
- package/src/chains/config.ts +7 -0
- package/src/chains/evm/EVMChain.ts +7 -0
- package/src/core/DKLSParty.ts +317 -0
- package/src/core/DKLSService.ts +426 -0
- package/src/core/ThresholdConfig.ts +159 -0
- package/src/core/types.ts +253 -0
- package/src/crypto/addresses.ts +282 -0
- package/src/crypto/elliptic.ts +133 -0
- package/src/crypto/encoding.ts +227 -0
- package/src/index.ts +40 -0
- package/src/protocols/keygen.ts +8 -0
- package/src/protocols/presignature.ts +196 -0
- package/src/protocols/refresh.ts +7 -0
- package/src/protocols/signing.ts +9 -0
- package/src/rpc/RPCProvider.ts +7 -0
- package/src/rpc/methods.ts +7 -0
- package/src/websocket/coordinator.ts +7 -0
- package/src/websocket/messages.ts +11 -0
- package/src/websocket/session.ts +7 -0
- package/src/wire/format.ts +10 -0
- package/src/wire/validation.ts +14 -0
- package/test-sdk.js +234 -0
package/test-sdk.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const { BitShardSDK } = require('./dist/index.js');
|
|
2
|
+
|
|
3
|
+
async function testSDK() {
|
|
4
|
+
console.log('Testing BitShard SDK...');
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
// Create SDK instance
|
|
8
|
+
const sdk = new BitShardSDK();
|
|
9
|
+
console.log('ā
SDK created successfully');
|
|
10
|
+
|
|
11
|
+
// Create a local wallet
|
|
12
|
+
const wallet = await sdk.createLocalWallet({
|
|
13
|
+
totalParties: 3,
|
|
14
|
+
threshold: 2
|
|
15
|
+
});
|
|
16
|
+
console.log('ā
Local wallet created');
|
|
17
|
+
console.log(' Public key:', wallet.publicKey);
|
|
18
|
+
console.log(' Keyshares:', wallet.keyshares.length);
|
|
19
|
+
|
|
20
|
+
// Derive addresses
|
|
21
|
+
const addresses = sdk.deriveAddresses(wallet.publicKey);
|
|
22
|
+
console.log('ā
Addresses derived:');
|
|
23
|
+
console.log(' Ethereum:', addresses.ethereum);
|
|
24
|
+
console.log(' Bitcoin:', addresses.bitcoin);
|
|
25
|
+
console.log(' Arbitrum:', addresses.arbitrum);
|
|
26
|
+
|
|
27
|
+
// Test signing with threshold (2 of 3)
|
|
28
|
+
const message = 'Hello BitShard!';
|
|
29
|
+
const signature = await sdk.personalSignWithWallet(message, wallet, { threshold: 2 });
|
|
30
|
+
console.log('ā
Message signed:');
|
|
31
|
+
console.log(' Signature:', signature.signature);
|
|
32
|
+
|
|
33
|
+
// Verify the signature
|
|
34
|
+
const { ethers } = require('ethers');
|
|
35
|
+
try {
|
|
36
|
+
const fullSig = signature.signature + signature.v.toString(16).padStart(2, '0');
|
|
37
|
+
const recoveredAddress = ethers.utils.verifyMessage(message, fullSig);
|
|
38
|
+
if (recoveredAddress.toLowerCase() === addresses.ethereum.toLowerCase()) {
|
|
39
|
+
console.log('ā
Signature verified! Recovered address matches.');
|
|
40
|
+
console.log(' Recovered address:', recoveredAddress);
|
|
41
|
+
} else {
|
|
42
|
+
console.log('ā ļø Recovered address:', recoveredAddress);
|
|
43
|
+
console.log(' Expected address:', addresses.ethereum);
|
|
44
|
+
return; // Exit if signature doesn't match
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.log('ā ļø Verification error:', error.message);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Arbitrum Sepolia transaction functionality
|
|
52
|
+
console.log('\n' + '='.repeat(60));
|
|
53
|
+
console.log('š° ARBITRUM SEPOLIA TRANSACTION TEST');
|
|
54
|
+
console.log('='.repeat(60));
|
|
55
|
+
|
|
56
|
+
// Set up Arbitrum Sepolia provider
|
|
57
|
+
const ARBITRUM_SEPOLIA_RPC = 'https://sepolia-rollup.arbitrum.io/rpc';
|
|
58
|
+
const provider = new ethers.providers.JsonRpcProvider(ARBITRUM_SEPOLIA_RPC);
|
|
59
|
+
|
|
60
|
+
console.log('\nš” Connected to Arbitrum Sepolia');
|
|
61
|
+
console.log(' RPC:', ARBITRUM_SEPOLIA_RPC);
|
|
62
|
+
|
|
63
|
+
// Display the address to fund
|
|
64
|
+
console.log('\nš³ Please send some ETH to this address on Arbitrum Sepolia:');
|
|
65
|
+
console.log(' Address:', addresses.ethereum);
|
|
66
|
+
console.log(' (Minimum: 0.001 ETH for test transaction + gas)');
|
|
67
|
+
|
|
68
|
+
// You can get testnet ETH from:
|
|
69
|
+
console.log('\nš° Get testnet ETH from:');
|
|
70
|
+
console.log(' 1. Arbitrum Sepolia Faucet: https://faucet.quicknode.com/arbitrum/sepolia');
|
|
71
|
+
console.log(' 2. Bridge from Sepolia: https://bridge.arbitrum.io/');
|
|
72
|
+
|
|
73
|
+
console.log('\nā³ Monitoring balance (checking every 5 seconds)...');
|
|
74
|
+
|
|
75
|
+
// Monitor balance
|
|
76
|
+
let previousBalance = ethers.BigNumber.from(0);
|
|
77
|
+
const checkBalance = async () => {
|
|
78
|
+
try {
|
|
79
|
+
const balance = await provider.getBalance(addresses.ethereum);
|
|
80
|
+
const balanceEth = ethers.utils.formatEther(balance);
|
|
81
|
+
|
|
82
|
+
if (balance.gt(previousBalance) && previousBalance.gt(0)) {
|
|
83
|
+
console.log(`\nš° Funds received! New balance: ${balanceEth} ETH`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (balance.gt(0) && previousBalance.eq(0)) {
|
|
87
|
+
console.log(`\nā
Funds detected! Balance: ${balanceEth} ETH`);
|
|
88
|
+
previousBalance = balance;
|
|
89
|
+
|
|
90
|
+
// Create and send transaction
|
|
91
|
+
await sendTransaction();
|
|
92
|
+
return true; // Stop monitoring
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
previousBalance = balance;
|
|
96
|
+
|
|
97
|
+
if (balance.eq(0)) {
|
|
98
|
+
process.stdout.write('.');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return false; // Continue monitoring
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error('\nā Error checking balance:', error.message);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Send transaction function
|
|
109
|
+
const sendTransaction = async () => {
|
|
110
|
+
try {
|
|
111
|
+
console.log('\nš Preparing transaction...');
|
|
112
|
+
|
|
113
|
+
// Get current gas price and nonce
|
|
114
|
+
const [gasPrice, nonce] = await Promise.all([
|
|
115
|
+
provider.getGasPrice(),
|
|
116
|
+
provider.getTransactionCount(addresses.ethereum)
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
// Convert message to hex data
|
|
120
|
+
// You can customize this message or even pass JSON data
|
|
121
|
+
const message = process.env.TX_MESSAGE || 'bitshard.io - MPC wallet transaction';
|
|
122
|
+
const messageHex = '0x' + Buffer.from(message, 'utf8').toString('hex');
|
|
123
|
+
|
|
124
|
+
// Calculate additional gas needed for data (roughly 68 gas per byte)
|
|
125
|
+
const dataGas = Buffer.from(message).length * 68;
|
|
126
|
+
|
|
127
|
+
// Create transaction with data field
|
|
128
|
+
const tx = {
|
|
129
|
+
to: '0xd8424ee7cc2520f7dae828f84f99f53ac0dd6734', // G recipient
|
|
130
|
+
value: ethers.utils.parseEther('0.0001'), // Send 0.0001 ETH
|
|
131
|
+
data: messageHex, // Add custom message as data
|
|
132
|
+
gasLimit: 21000 + dataGas, // Base gas + data gas
|
|
133
|
+
gasPrice: gasPrice.mul(110).div(100), // Add 10% buffer
|
|
134
|
+
nonce: nonce,
|
|
135
|
+
chainId: 421614, // Arbitrum Sepolia chain ID
|
|
136
|
+
type: 0 // Legacy transaction for simplicity
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
console.log('\nš Transaction details:');
|
|
140
|
+
console.log(' To:', tx.to);
|
|
141
|
+
console.log(' Value:', ethers.utils.formatEther(tx.value), 'ETH');
|
|
142
|
+
console.log(' Data:', message, `(${messageHex})`);
|
|
143
|
+
console.log(' Gas Price:', ethers.utils.formatUnits(tx.gasPrice, 'gwei'), 'gwei');
|
|
144
|
+
console.log(' Gas Limit:', tx.gasLimit);
|
|
145
|
+
console.log(' Nonce:', tx.nonce);
|
|
146
|
+
console.log(' Chain ID:', tx.chainId);
|
|
147
|
+
|
|
148
|
+
// Serialize the transaction for signing
|
|
149
|
+
const serializedTx = ethers.utils.serializeTransaction(tx);
|
|
150
|
+
const txHash = ethers.utils.keccak256(serializedTx);
|
|
151
|
+
|
|
152
|
+
console.log('\nšļø Signing transaction with MPC wallet...');
|
|
153
|
+
console.log(' Transaction hash:', txHash);
|
|
154
|
+
|
|
155
|
+
// Sign the transaction hash (use signTransactionWithWallet for raw hash)
|
|
156
|
+
const txSignature = await sdk.signTransactionWithWallet(
|
|
157
|
+
txHash,
|
|
158
|
+
wallet,
|
|
159
|
+
{ threshold: 2 }
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
console.log(' Signature R:', txSignature.r);
|
|
163
|
+
console.log(' Signature S:', txSignature.s);
|
|
164
|
+
console.log(' Signature V (recovery):', txSignature.v);
|
|
165
|
+
|
|
166
|
+
// For Arbitrum Sepolia, we need to adjust v value for EIP-155
|
|
167
|
+
// v = chainId * 2 + 35 + recovery_id (0 or 1)
|
|
168
|
+
// DKLS returns 27 or 28 based on signature (27 = recovery_id 0, 28 = recovery_id 1)
|
|
169
|
+
// The SDK automatically determines the correct v value by testing recovery
|
|
170
|
+
const recoveryId = txSignature.v - 27; // Will be 0 or 1 depending on the signature
|
|
171
|
+
const eip155V = tx.chainId * 2 + 35 + recoveryId;
|
|
172
|
+
|
|
173
|
+
console.log(' Recovery ID:', recoveryId, `(from v=${txSignature.v})`);
|
|
174
|
+
console.log(' EIP-155 V value:', eip155V);
|
|
175
|
+
|
|
176
|
+
// Add signature to transaction
|
|
177
|
+
const signedTx = ethers.utils.serializeTransaction(tx, {
|
|
178
|
+
r: txSignature.r,
|
|
179
|
+
s: txSignature.s,
|
|
180
|
+
v: eip155V
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
console.log('ā
Transaction signed');
|
|
184
|
+
console.log(' Signed transaction:', signedTx);
|
|
185
|
+
console.log('\nš” Broadcasting transaction...');
|
|
186
|
+
|
|
187
|
+
// Send the transaction
|
|
188
|
+
const txResponse = await provider.sendTransaction(signedTx);
|
|
189
|
+
console.log('ā
Transaction sent!');
|
|
190
|
+
console.log(' Transaction hash:', txResponse.hash);
|
|
191
|
+
console.log(' View on explorer: https://sepolia.arbiscan.io/tx/' + txResponse.hash);
|
|
192
|
+
|
|
193
|
+
console.log('\nā³ Waiting for confirmation...');
|
|
194
|
+
const receipt = await txResponse.wait();
|
|
195
|
+
|
|
196
|
+
console.log('ā
Transaction confirmed!');
|
|
197
|
+
console.log(' Block number:', receipt.blockNumber);
|
|
198
|
+
console.log(' Gas used:', receipt.gasUsed.toString());
|
|
199
|
+
|
|
200
|
+
// Show how to view the input data
|
|
201
|
+
console.log('\nš Transaction Data:');
|
|
202
|
+
console.log(' Input data on chain:', tx.data);
|
|
203
|
+
console.log(' Decoded message:', Buffer.from(tx.data.slice(2), 'hex').toString('utf8'));
|
|
204
|
+
console.log(' View on explorer (check "Input Data" section):');
|
|
205
|
+
console.log(' https://sepolia.arbiscan.io/tx/' + txResponse.hash);
|
|
206
|
+
|
|
207
|
+
// Check final balance
|
|
208
|
+
const finalBalance = await provider.getBalance(addresses.ethereum);
|
|
209
|
+
console.log('\nš° Final balance:', ethers.utils.formatEther(finalBalance), 'ETH');
|
|
210
|
+
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error('\nā Transaction error:', error.message);
|
|
213
|
+
if (error.reason) console.error(' Reason:', error.reason);
|
|
214
|
+
if (error.code) console.error(' Code:', error.code);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Start monitoring loop
|
|
219
|
+
const monitorInterval = setInterval(async () => {
|
|
220
|
+
const shouldStop = await checkBalance();
|
|
221
|
+
if (shouldStop) {
|
|
222
|
+
clearInterval(monitorInterval);
|
|
223
|
+
}
|
|
224
|
+
}, 5000);
|
|
225
|
+
|
|
226
|
+
// Initial balance check
|
|
227
|
+
await checkBalance();
|
|
228
|
+
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error('ā Error:', error.message);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
testSDK();
|