@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
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DKLSService = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const dkls_wasm_ll_node_1 = require("@silencelaboratories/dkls-wasm-ll-node");
|
|
9
|
+
const addresses_1 = require("../crypto/addresses");
|
|
10
|
+
/**
|
|
11
|
+
* Core DKLS protocol service for distributed key generation and threshold signatures
|
|
12
|
+
*/
|
|
13
|
+
class DKLSService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.sessions = new Map();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wire format for DKLS Message over WS
|
|
19
|
+
*/
|
|
20
|
+
static toWireMessage(msg) {
|
|
21
|
+
return {
|
|
22
|
+
from_id: msg.from_id,
|
|
23
|
+
to_id: msg.to_id,
|
|
24
|
+
payload: Buffer.from(msg.payload).toString('base64')
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reconstruct DKLS Message from wire payload
|
|
29
|
+
*/
|
|
30
|
+
static fromWireMessage(w) {
|
|
31
|
+
const bytes = new Uint8Array(Buffer.from(w.payload, 'base64'));
|
|
32
|
+
// Note: Message constructor requires payload, from, and optional to
|
|
33
|
+
return new dkls_wasm_ll_node_1.Message(bytes, w.from_id, w.to_id);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generate DKG using DKLS protocol with flexible threshold
|
|
37
|
+
* @param totalParties Total number of parties (n)
|
|
38
|
+
* @param threshold Threshold required for signing (t)
|
|
39
|
+
* @param partyIds Optional array of party IDs (defaults to 0..n-1)
|
|
40
|
+
*/
|
|
41
|
+
async generateDKG(totalParties = 3, threshold = 2, partyIds) {
|
|
42
|
+
try {
|
|
43
|
+
console.log(`🔐 Starting DKLS DKG for ${threshold}-of-${totalParties} threshold scheme...`);
|
|
44
|
+
// Validate parameters
|
|
45
|
+
if (threshold > totalParties) {
|
|
46
|
+
throw new Error('Threshold cannot be greater than total parties');
|
|
47
|
+
}
|
|
48
|
+
if (threshold < 2) {
|
|
49
|
+
throw new Error('Threshold must be at least 2');
|
|
50
|
+
}
|
|
51
|
+
// Use provided party IDs or default to 0..n-1
|
|
52
|
+
const ids = partyIds ?? Array.from({ length: totalParties }, (_, i) => i);
|
|
53
|
+
if (ids.length !== totalParties) {
|
|
54
|
+
throw new Error('Party IDs array length must match totalParties');
|
|
55
|
+
}
|
|
56
|
+
// Create KeygenSession for each party
|
|
57
|
+
const parties = [];
|
|
58
|
+
for (let i = 0; i < totalParties; i++) {
|
|
59
|
+
parties.push(new dkls_wasm_ll_node_1.KeygenSession(totalParties, threshold, ids[i]));
|
|
60
|
+
}
|
|
61
|
+
// Execute DKG protocol
|
|
62
|
+
const keyshares = this.executeDKG(parties);
|
|
63
|
+
// Get public key from first keyshare
|
|
64
|
+
const publicKeyBytes = keyshares[0].publicKey;
|
|
65
|
+
const publicKeyHex = Buffer.from(publicKeyBytes).toString('hex');
|
|
66
|
+
// Generate addresses for different blockchains
|
|
67
|
+
const addresses = this.deriveAllAddresses(publicKeyBytes);
|
|
68
|
+
// Create party keyshares with commitments
|
|
69
|
+
const partyKeyshares = keyshares.map((ks, idx) => {
|
|
70
|
+
const shareBytes = ks.toBytes();
|
|
71
|
+
const shareData = Buffer.from(shareBytes).toString('base64');
|
|
72
|
+
const commitment = crypto_1.default.createHash('sha256')
|
|
73
|
+
.update(shareData)
|
|
74
|
+
.digest('hex');
|
|
75
|
+
return {
|
|
76
|
+
partyId: ids[idx],
|
|
77
|
+
share: shareData,
|
|
78
|
+
commitment
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
// Generate DKG commitment
|
|
82
|
+
const dkgCommitment = crypto_1.default.createHash('sha256')
|
|
83
|
+
.update(publicKeyHex)
|
|
84
|
+
.digest('hex');
|
|
85
|
+
console.log(`✅ DKLS DKG completed successfully`);
|
|
86
|
+
console.log(`📍 Ethereum address: ${addresses.ethereum}`);
|
|
87
|
+
console.log(`📍 Bitcoin address: ${addresses.bitcoin}`);
|
|
88
|
+
return {
|
|
89
|
+
totalParties,
|
|
90
|
+
threshold,
|
|
91
|
+
publicKey: '0x' + publicKeyHex,
|
|
92
|
+
dkgCommitment,
|
|
93
|
+
keyshares: partyKeyshares,
|
|
94
|
+
addresses
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('❌ DKLS DKG generation error:', error);
|
|
99
|
+
throw new Error(`Failed to generate DKG: ${error.message}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Legacy method for backward compatibility - generates standard 2-of-3 setup
|
|
104
|
+
*/
|
|
105
|
+
async generateDKGCommitments() {
|
|
106
|
+
const result = await this.generateDKG(3, 2);
|
|
107
|
+
// Map to legacy format
|
|
108
|
+
return {
|
|
109
|
+
dkgCommitment: result.dkgCommitment,
|
|
110
|
+
serverShareCommitment: result.keyshares[0].commitment,
|
|
111
|
+
masterPublicKey: result.publicKey,
|
|
112
|
+
serverShare: result.keyshares[0].share,
|
|
113
|
+
backupShare: result.keyshares[1].share,
|
|
114
|
+
mobileShare: result.keyshares[2].share,
|
|
115
|
+
publicKey: result.publicKey,
|
|
116
|
+
ethAddress: result.addresses.ethereum,
|
|
117
|
+
btcAddress: result.addresses.bitcoin,
|
|
118
|
+
cosmosAddress: result.addresses.cosmos,
|
|
119
|
+
bnbAddress: result.addresses.bnb,
|
|
120
|
+
polygonAddress: result.addresses.polygon,
|
|
121
|
+
avaxAddress: result.addresses.avalanche,
|
|
122
|
+
arbAddress: result.addresses.arbitrum
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Execute the DKG protocol rounds
|
|
127
|
+
*/
|
|
128
|
+
executeDKG(parties) {
|
|
129
|
+
// Round 1: Create first messages and capture each session's self id
|
|
130
|
+
const msg1 = parties.map(p => p.createFirstMessage());
|
|
131
|
+
const selfIds = msg1.map(m => m.from_id);
|
|
132
|
+
// Broadcast round 1 messages (exclude own by selfId)
|
|
133
|
+
const msg2 = parties.flatMap((p, idx) => p.handleMessages(this.filterMessages(msg1, selfIds[idx])));
|
|
134
|
+
// Calculate chain code commitments and index them by actual party id
|
|
135
|
+
const commitmentsRaw = parties.map(p => p.calculateChainCodeCommitment());
|
|
136
|
+
const commitments = new Array(parties.length);
|
|
137
|
+
selfIds.forEach((id, idx) => {
|
|
138
|
+
commitments[id] = commitmentsRaw[idx];
|
|
139
|
+
});
|
|
140
|
+
// Handle P2P messages (round 2) using selfId mapping
|
|
141
|
+
const msg3 = parties.flatMap((p, idx) => p.handleMessages(this.selectMessages(msg2, selfIds[idx])));
|
|
142
|
+
// Handle P2P messages with commitments (round 3)
|
|
143
|
+
const msg4 = parties.flatMap((p, idx) => p.handleMessages(this.selectMessages(msg3, selfIds[idx]), commitments));
|
|
144
|
+
// Handle final broadcast messages
|
|
145
|
+
parties.forEach((p, idx) => p.handleMessages(this.filterMessages(msg4, selfIds[idx])));
|
|
146
|
+
// Extract keyshares
|
|
147
|
+
return parties.map(p => p.keyshare());
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Sign a message using threshold signatures
|
|
151
|
+
* @param messageHash The message hash to sign
|
|
152
|
+
* @param keyshares Array of keyshares (at least threshold number required)
|
|
153
|
+
* @param threshold Threshold value (must match keyshare generation)
|
|
154
|
+
* @param publicKey Optional public key for v calculation
|
|
155
|
+
*/
|
|
156
|
+
async signMessage(messageHash, keyshares, threshold, publicKey) {
|
|
157
|
+
try {
|
|
158
|
+
console.log(`🖊️ Starting DKLS signature generation (${threshold}-of-${keyshares.length})...`);
|
|
159
|
+
if (keyshares.length < threshold) {
|
|
160
|
+
throw new Error(`Insufficient keyshares: need ${threshold}, got ${keyshares.length}`);
|
|
161
|
+
}
|
|
162
|
+
// Clone keyshares since SignSession consumes them
|
|
163
|
+
const signingShares = keyshares.slice(0, threshold).map(ks => {
|
|
164
|
+
const bytes = ks.toBytes();
|
|
165
|
+
return dkls_wasm_ll_node_1.Keyshare.fromBytes(bytes);
|
|
166
|
+
});
|
|
167
|
+
// Create sign sessions
|
|
168
|
+
// NOTE: DKLS library currently only supports "m" path
|
|
169
|
+
const parties = signingShares.map(ks => new dkls_wasm_ll_node_1.SignSession(ks, "m"));
|
|
170
|
+
// Round 1: Create first messages and capture self ids
|
|
171
|
+
const msg1 = parties.map(p => p.createFirstMessage());
|
|
172
|
+
const selfIds = msg1.map(m => m.from_id);
|
|
173
|
+
// Broadcast the first message to all parties
|
|
174
|
+
const msg2 = parties.flatMap((p, idx) => p.handleMessages(this.filterMessages(msg1, selfIds[idx])));
|
|
175
|
+
// Handle P2P messages (round 2)
|
|
176
|
+
const msg3 = parties.flatMap((p, idx) => p.handleMessages(this.selectMessages(msg2, selfIds[idx])));
|
|
177
|
+
// Complete pre-signature (round 3)
|
|
178
|
+
parties.forEach((p, idx) => p.handleMessages(this.selectMessages(msg3, selfIds[idx])));
|
|
179
|
+
// WARNING: PRE-SIGNATURES MUST NOT BE REUSED
|
|
180
|
+
// Generate final signature with message hash
|
|
181
|
+
const msg4 = parties.map(p => p.lastMessage(messageHash));
|
|
182
|
+
// Combine to produce signature
|
|
183
|
+
const signatures = parties.map((p, idx) => p.combine(this.filterMessages(msg4, selfIds[idx])));
|
|
184
|
+
// All parties should produce the same signature
|
|
185
|
+
const signatureComponents = signatures[0];
|
|
186
|
+
const [r_bytes, s_bytes] = signatureComponents;
|
|
187
|
+
const r = Buffer.from(r_bytes).toString('hex');
|
|
188
|
+
const s = Buffer.from(s_bytes).toString('hex');
|
|
189
|
+
const signatureHex = r + s;
|
|
190
|
+
// Calculate v value for Ethereum signature recovery
|
|
191
|
+
let v = 27; // Default value
|
|
192
|
+
if (publicKey) {
|
|
193
|
+
// Try to recover with both v values and see which matches our public key
|
|
194
|
+
const ethers = require('ethers');
|
|
195
|
+
const { deriveEthereumAddress } = require('../crypto/addresses');
|
|
196
|
+
const expectedAddress = deriveEthereumAddress(publicKey);
|
|
197
|
+
const msgHashHex = '0x' + Buffer.from(messageHash).toString('hex');
|
|
198
|
+
for (const testV of [27, 28]) {
|
|
199
|
+
try {
|
|
200
|
+
const sig = { r: '0x' + r, s: '0x' + s, v: testV };
|
|
201
|
+
const recoveredAddress = ethers.utils.recoverAddress(msgHashHex, sig);
|
|
202
|
+
if (recoveredAddress.toLowerCase() === expectedAddress.toLowerCase()) {
|
|
203
|
+
v = testV;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
// Try next v value
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
console.log('✅ DKLS signature generated successfully');
|
|
213
|
+
return {
|
|
214
|
+
signature: '0x' + signatureHex,
|
|
215
|
+
r: '0x' + r,
|
|
216
|
+
s: '0x' + s,
|
|
217
|
+
v
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.error('❌ DKLS signing error:', error);
|
|
222
|
+
throw new Error(`Failed to sign message: ${error.message}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Legacy signing method for backward compatibility
|
|
227
|
+
*/
|
|
228
|
+
async signMessageLegacy(messageHash, serverShareData, backupShareData, _chain = 'ethereum') {
|
|
229
|
+
// Deserialize keyshares
|
|
230
|
+
const serverKeyshare = dkls_wasm_ll_node_1.Keyshare.fromBytes(new Uint8Array(Buffer.from(serverShareData, 'base64')));
|
|
231
|
+
const backupKeyshare = dkls_wasm_ll_node_1.Keyshare.fromBytes(new Uint8Array(Buffer.from(backupShareData, 'base64')));
|
|
232
|
+
return this.signMessage(messageHash, [serverKeyshare, backupKeyshare], 2);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Refresh shares (key rotation) while preserving the public key
|
|
236
|
+
*/
|
|
237
|
+
async refreshShares(existingShares) {
|
|
238
|
+
try {
|
|
239
|
+
console.log('🔄 Starting DKLS key rotation...');
|
|
240
|
+
console.log(` ${existingShares.length} parties participating in rotation`);
|
|
241
|
+
// Create rotation sessions
|
|
242
|
+
const rotationParties = existingShares.map(share => dkls_wasm_ll_node_1.KeygenSession.initKeyRotation(share));
|
|
243
|
+
console.log('Executing key generation protocol for rotation...');
|
|
244
|
+
// Execute DKG protocol for rotation
|
|
245
|
+
const newKeyshares = this.executeDKG(rotationParties);
|
|
246
|
+
// Verify all parties got keyshares
|
|
247
|
+
if (!newKeyshares.every(ks => ks !== null)) {
|
|
248
|
+
throw new Error('Key rotation failed: Not all parties generated new shares');
|
|
249
|
+
}
|
|
250
|
+
// Get public key (should be same as before)
|
|
251
|
+
const publicKeyHex = Buffer.from(newKeyshares[0].publicKey).toString('hex');
|
|
252
|
+
const originalPubKey = Buffer.from(existingShares[0].publicKey).toString('hex');
|
|
253
|
+
console.log('Original public key:', originalPubKey.substring(0, 20) + '...');
|
|
254
|
+
console.log('Rotated public key:', publicKeyHex.substring(0, 20) + '...');
|
|
255
|
+
// Finalize rotation
|
|
256
|
+
console.log('Finalizing key rotation...');
|
|
257
|
+
for (let i = 0; i < newKeyshares.length; i++) {
|
|
258
|
+
newKeyshares[i].finishKeyRotation(existingShares[i]);
|
|
259
|
+
console.log(` Party ${i} rotation finalized`);
|
|
260
|
+
}
|
|
261
|
+
console.log('✅ DKLS key rotation completed successfully');
|
|
262
|
+
if (publicKeyHex === originalPubKey) {
|
|
263
|
+
console.log(' ✅ Public key preserved: addresses remain unchanged');
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
console.log(' ⚠️ Public key changed (unexpected for rotation)');
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
newShares: newKeyshares,
|
|
270
|
+
publicKey: '0x' + publicKeyHex
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
console.error('❌ DKLS key rotation error:', error);
|
|
275
|
+
throw new Error(`Failed to refresh shares: ${error.message}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Filter messages for broadcast (exclude own messages)
|
|
280
|
+
*/
|
|
281
|
+
filterMessages(msgs, party) {
|
|
282
|
+
return msgs.filter((m) => m.from_id !== party).map(m => m.clone());
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Select P2P messages for a specific party
|
|
286
|
+
*/
|
|
287
|
+
selectMessages(msgs, party) {
|
|
288
|
+
return msgs.filter((m) => m.to_id === party).map(m => m.clone());
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Derive all blockchain addresses from public key
|
|
292
|
+
*/
|
|
293
|
+
deriveAllAddresses(publicKey) {
|
|
294
|
+
return (0, addresses_1.deriveAddressesFromBytes)(publicKey);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get active session by ID
|
|
298
|
+
*/
|
|
299
|
+
getSession(sessionId) {
|
|
300
|
+
return this.sessions.get(sessionId);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Create a new MPC session
|
|
304
|
+
*/
|
|
305
|
+
createSession(session) {
|
|
306
|
+
const fullSession = {
|
|
307
|
+
...session,
|
|
308
|
+
createdAt: new Date(),
|
|
309
|
+
updatedAt: new Date()
|
|
310
|
+
};
|
|
311
|
+
this.sessions.set(session.id, fullSession);
|
|
312
|
+
return fullSession;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Update session status
|
|
316
|
+
*/
|
|
317
|
+
updateSession(sessionId, updates) {
|
|
318
|
+
const session = this.sessions.get(sessionId);
|
|
319
|
+
if (session) {
|
|
320
|
+
Object.assign(session, updates, { updatedAt: new Date() });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.DKLSService = DKLSService;
|
|
325
|
+
//# sourceMappingURL=DKLSService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DKLSService.js","sourceRoot":"","sources":["../../src/core/DKLSService.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,8EAKgD;AAShD,mDAA+D;AAE/D;;GAEG;AACH,MAAa,WAAW;IAAxB;QACY,aAAQ,GAA4B,IAAI,GAAG,EAAE,CAAC;IAoZ1D,CAAC;IAlZG;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,GAAY;QAC7B,OAAO;YACH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IAED;;OAEG;IACH,UAAU,CAAC,SAAiB;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,OAAoD;QAC9D,MAAM,WAAW,GAAe;YAC5B,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACxB,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC3C,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,SAAiB,EAAE,OAA4B;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/D,CAAC;IACL,CAAC;CACJ;AArZD,kCAqZC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for threshold signature schemes
|
|
3
|
+
*/
|
|
4
|
+
export declare class ThresholdConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Total number of parties
|
|
7
|
+
*/
|
|
8
|
+
readonly totalParties: number;
|
|
9
|
+
/**
|
|
10
|
+
* Threshold required for signing (t-of-n)
|
|
11
|
+
*/
|
|
12
|
+
readonly threshold: number;
|
|
13
|
+
/**
|
|
14
|
+
* Party identifiers (optional, defaults to 0..n-1)
|
|
15
|
+
*/
|
|
16
|
+
readonly partyIds: number[];
|
|
17
|
+
/**
|
|
18
|
+
* Create a new threshold configuration
|
|
19
|
+
* @param totalParties Total number of parties (n)
|
|
20
|
+
* @param threshold Threshold required for signing (t)
|
|
21
|
+
* @param partyIds Optional array of party IDs
|
|
22
|
+
*/
|
|
23
|
+
constructor(totalParties: number, threshold: number, partyIds?: number[]);
|
|
24
|
+
/**
|
|
25
|
+
* Create a standard 2-of-3 configuration
|
|
26
|
+
*/
|
|
27
|
+
static createStandard(): ThresholdConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Create a 3-of-4 configuration with additional signer
|
|
30
|
+
*/
|
|
31
|
+
static createEnhanced(): ThresholdConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Create an enterprise configuration
|
|
34
|
+
* @param totalParties Total number of parties (5-7 recommended)
|
|
35
|
+
* @param threshold Threshold (3-4 recommended)
|
|
36
|
+
*/
|
|
37
|
+
static createEnterprise(totalParties?: number, threshold?: number): ThresholdConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a set of party IDs can sign
|
|
40
|
+
* @param signingParties Array of party IDs that want to sign
|
|
41
|
+
* @returns True if the parties can meet the threshold
|
|
42
|
+
*/
|
|
43
|
+
canSign(signingParties: number[]): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get the minimum number of additional parties needed to sign
|
|
46
|
+
* @param currentParties Array of party IDs currently available
|
|
47
|
+
* @returns Number of additional parties needed, or 0 if threshold is met
|
|
48
|
+
*/
|
|
49
|
+
additionalPartiesNeeded(currentParties: number[]): number;
|
|
50
|
+
/**
|
|
51
|
+
* Get a subset of parties for signing
|
|
52
|
+
* @param availableParties Array of available party IDs
|
|
53
|
+
* @returns Array of party IDs to use for signing (threshold size)
|
|
54
|
+
*/
|
|
55
|
+
selectSigningParties(availableParties: number[]): number[];
|
|
56
|
+
/**
|
|
57
|
+
* Validate party ID
|
|
58
|
+
* @param partyId Party ID to validate
|
|
59
|
+
* @returns True if party ID is valid
|
|
60
|
+
*/
|
|
61
|
+
isValidParty(partyId: number): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get configuration summary
|
|
64
|
+
*/
|
|
65
|
+
toString(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Get detailed configuration info
|
|
68
|
+
*/
|
|
69
|
+
toJSON(): {
|
|
70
|
+
totalParties: number;
|
|
71
|
+
threshold: number;
|
|
72
|
+
partyIds: number[];
|
|
73
|
+
scheme: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=ThresholdConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThresholdConfig.d.ts","sourceRoot":"","sources":["../../src/core/ThresholdConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,eAAe;IACxB;;OAEG;IACH,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC;;OAEG;IACH,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,SAAgB,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnC;;;;;OAKG;gBACS,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE;IAiCxE;;OAEG;IACH,MAAM,CAAC,cAAc,IAAI,eAAe;IAIxC;;OAEG;IACH,MAAM,CAAC,cAAc,IAAI,eAAe;IAIxC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,YAAY,GAAE,MAAU,EAAE,SAAS,GAAE,MAAU,GAAG,eAAe;IAOzF;;;;OAIG;IACH,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO;IAQ1C;;;;OAIG;IACH,uBAAuB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM;IAMzD;;;;OAIG;IACH,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAa1D;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAItC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,MAAM,IAAI;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;KAClB;CAQJ"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThresholdConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for threshold signature schemes
|
|
6
|
+
*/
|
|
7
|
+
class ThresholdConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new threshold configuration
|
|
10
|
+
* @param totalParties Total number of parties (n)
|
|
11
|
+
* @param threshold Threshold required for signing (t)
|
|
12
|
+
* @param partyIds Optional array of party IDs
|
|
13
|
+
*/
|
|
14
|
+
constructor(totalParties, threshold, partyIds) {
|
|
15
|
+
// Validate parameters
|
|
16
|
+
if (totalParties < 2) {
|
|
17
|
+
throw new Error('Total parties must be at least 2');
|
|
18
|
+
}
|
|
19
|
+
if (threshold < 2) {
|
|
20
|
+
throw new Error('Threshold must be at least 2');
|
|
21
|
+
}
|
|
22
|
+
if (threshold > totalParties) {
|
|
23
|
+
throw new Error('Threshold cannot be greater than total parties');
|
|
24
|
+
}
|
|
25
|
+
this.totalParties = totalParties;
|
|
26
|
+
this.threshold = threshold;
|
|
27
|
+
// Use provided party IDs or default to sequential
|
|
28
|
+
if (partyIds) {
|
|
29
|
+
if (partyIds.length !== totalParties) {
|
|
30
|
+
throw new Error('Party IDs array length must match totalParties');
|
|
31
|
+
}
|
|
32
|
+
// Check for duplicates
|
|
33
|
+
const uniqueIds = new Set(partyIds);
|
|
34
|
+
if (uniqueIds.size !== partyIds.length) {
|
|
35
|
+
throw new Error('Party IDs must be unique');
|
|
36
|
+
}
|
|
37
|
+
this.partyIds = [...partyIds];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.partyIds = Array.from({ length: totalParties }, (_, i) => i);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a standard 2-of-3 configuration
|
|
45
|
+
*/
|
|
46
|
+
static createStandard() {
|
|
47
|
+
return new ThresholdConfig(3, 2);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a 3-of-4 configuration with additional signer
|
|
51
|
+
*/
|
|
52
|
+
static createEnhanced() {
|
|
53
|
+
return new ThresholdConfig(4, 3);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create an enterprise configuration
|
|
57
|
+
* @param totalParties Total number of parties (5-7 recommended)
|
|
58
|
+
* @param threshold Threshold (3-4 recommended)
|
|
59
|
+
*/
|
|
60
|
+
static createEnterprise(totalParties = 5, threshold = 3) {
|
|
61
|
+
if (totalParties < 5 || totalParties > 20) {
|
|
62
|
+
throw new Error('Enterprise configuration should have 5-20 parties');
|
|
63
|
+
}
|
|
64
|
+
return new ThresholdConfig(totalParties, threshold);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if a set of party IDs can sign
|
|
68
|
+
* @param signingParties Array of party IDs that want to sign
|
|
69
|
+
* @returns True if the parties can meet the threshold
|
|
70
|
+
*/
|
|
71
|
+
canSign(signingParties) {
|
|
72
|
+
// Check if all signing parties are valid
|
|
73
|
+
const validParties = signingParties.filter(id => this.partyIds.includes(id));
|
|
74
|
+
// Check if we have enough valid parties
|
|
75
|
+
return validParties.length >= this.threshold;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the minimum number of additional parties needed to sign
|
|
79
|
+
* @param currentParties Array of party IDs currently available
|
|
80
|
+
* @returns Number of additional parties needed, or 0 if threshold is met
|
|
81
|
+
*/
|
|
82
|
+
additionalPartiesNeeded(currentParties) {
|
|
83
|
+
const validParties = currentParties.filter(id => this.partyIds.includes(id));
|
|
84
|
+
const needed = this.threshold - validParties.length;
|
|
85
|
+
return Math.max(0, needed);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get a subset of parties for signing
|
|
89
|
+
* @param availableParties Array of available party IDs
|
|
90
|
+
* @returns Array of party IDs to use for signing (threshold size)
|
|
91
|
+
*/
|
|
92
|
+
selectSigningParties(availableParties) {
|
|
93
|
+
const validParties = availableParties.filter(id => this.partyIds.includes(id));
|
|
94
|
+
if (validParties.length < this.threshold) {
|
|
95
|
+
throw new Error(`Insufficient parties: need ${this.threshold}, have ${validParties.length}`);
|
|
96
|
+
}
|
|
97
|
+
// Return first threshold number of valid parties
|
|
98
|
+
return validParties.slice(0, this.threshold);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Validate party ID
|
|
102
|
+
* @param partyId Party ID to validate
|
|
103
|
+
* @returns True if party ID is valid
|
|
104
|
+
*/
|
|
105
|
+
isValidParty(partyId) {
|
|
106
|
+
return this.partyIds.includes(partyId);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get configuration summary
|
|
110
|
+
*/
|
|
111
|
+
toString() {
|
|
112
|
+
return `${this.threshold}-of-${this.totalParties} threshold scheme`;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get detailed configuration info
|
|
116
|
+
*/
|
|
117
|
+
toJSON() {
|
|
118
|
+
return {
|
|
119
|
+
totalParties: this.totalParties,
|
|
120
|
+
threshold: this.threshold,
|
|
121
|
+
partyIds: this.partyIds,
|
|
122
|
+
scheme: this.toString()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.ThresholdConfig = ThresholdConfig;
|
|
127
|
+
//# sourceMappingURL=ThresholdConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThresholdConfig.js","sourceRoot":"","sources":["../../src/core/ThresholdConfig.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,eAAe;IAgBxB;;;;;OAKG;IACH,YAAY,YAAoB,EAAE,SAAiB,EAAE,QAAmB;QACpE,sBAAsB;QACtB,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,C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