@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,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decompressPublicKey = decompressPublicKey;
|
|
4
|
+
exports.isCompressedPublicKey = isCompressedPublicKey;
|
|
5
|
+
exports.getUncompressedPublicKey = getUncompressedPublicKey;
|
|
6
|
+
/**
|
|
7
|
+
* Decompress a compressed ECDSA public key
|
|
8
|
+
* @param compressedHex - Hex string of compressed public key (33 bytes)
|
|
9
|
+
* @returns Uncompressed public key hex string (64 bytes, without 04 prefix)
|
|
10
|
+
*/
|
|
11
|
+
function decompressPublicKey(compressedHex) {
|
|
12
|
+
// Remove 0x prefix if present
|
|
13
|
+
const cleanHex = compressedHex.replace(/^0x/, '');
|
|
14
|
+
if (cleanHex.length !== 66) {
|
|
15
|
+
throw new Error('Invalid compressed public key length');
|
|
16
|
+
}
|
|
17
|
+
const prefix = cleanHex.slice(0, 2);
|
|
18
|
+
if (prefix !== '02' && prefix !== '03') {
|
|
19
|
+
throw new Error('Invalid compressed public key prefix');
|
|
20
|
+
}
|
|
21
|
+
// Get x coordinate
|
|
22
|
+
const x = BigInt('0x' + cleanHex.slice(2));
|
|
23
|
+
// secp256k1 curve parameters
|
|
24
|
+
const p = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F');
|
|
25
|
+
const a = BigInt(0);
|
|
26
|
+
const b = BigInt(7);
|
|
27
|
+
// Calculate y^2 = x^3 + ax + b (mod p)
|
|
28
|
+
const x3 = modPow(x, 3n, p);
|
|
29
|
+
const ax = (a * x) % p;
|
|
30
|
+
const y2 = (x3 + ax + b) % p;
|
|
31
|
+
// Calculate y = sqrt(y^2) mod p
|
|
32
|
+
let y = modSqrt(y2, p);
|
|
33
|
+
if (y === null) {
|
|
34
|
+
throw new Error('Invalid public key - no valid y coordinate');
|
|
35
|
+
}
|
|
36
|
+
// Choose the correct y based on prefix
|
|
37
|
+
const isEven = y % 2n === 0n;
|
|
38
|
+
const shouldBeEven = prefix === '02';
|
|
39
|
+
if (isEven !== shouldBeEven) {
|
|
40
|
+
y = p - y;
|
|
41
|
+
}
|
|
42
|
+
// Convert to hex strings (32 bytes each)
|
|
43
|
+
const xHex = x.toString(16).padStart(64, '0');
|
|
44
|
+
const yHex = y.toString(16).padStart(64, '0');
|
|
45
|
+
return xHex + yHex;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Modular exponentiation: (base^exp) % mod
|
|
49
|
+
*/
|
|
50
|
+
function modPow(base, exp, mod) {
|
|
51
|
+
let result = 1n;
|
|
52
|
+
base = base % mod;
|
|
53
|
+
while (exp > 0n) {
|
|
54
|
+
if (exp % 2n === 1n) {
|
|
55
|
+
result = (result * base) % mod;
|
|
56
|
+
}
|
|
57
|
+
exp = exp >> 1n;
|
|
58
|
+
base = (base * base) % mod;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Modular square root using Tonelli-Shanks algorithm
|
|
64
|
+
* For secp256k1, p ≡ 3 (mod 4), so we can use the simpler formula
|
|
65
|
+
*/
|
|
66
|
+
function modSqrt(a, p) {
|
|
67
|
+
// Check if a is a quadratic residue
|
|
68
|
+
const legendreSymbol = modPow(a, (p - 1n) / 2n, p);
|
|
69
|
+
if (legendreSymbol !== 1n) {
|
|
70
|
+
return null; // No square root exists
|
|
71
|
+
}
|
|
72
|
+
// For p ≡ 3 (mod 4), sqrt(a) = a^((p+1)/4) mod p
|
|
73
|
+
if (p % 4n === 3n) {
|
|
74
|
+
return modPow(a, (p + 1n) / 4n, p);
|
|
75
|
+
}
|
|
76
|
+
// For other cases, would need full Tonelli-Shanks
|
|
77
|
+
throw new Error('Unsupported prime for square root');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if a public key is compressed
|
|
81
|
+
* @param publicKeyHex - Hex string of public key
|
|
82
|
+
* @returns True if compressed (33 bytes), false if uncompressed (64 or 65 bytes)
|
|
83
|
+
*/
|
|
84
|
+
function isCompressedPublicKey(publicKeyHex) {
|
|
85
|
+
const cleanHex = publicKeyHex.replace(/^0x/, '');
|
|
86
|
+
// Compressed keys are 33 bytes (66 hex chars)
|
|
87
|
+
if (cleanHex.length === 66) {
|
|
88
|
+
const prefix = cleanHex.slice(0, 2);
|
|
89
|
+
return prefix === '02' || prefix === '03';
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get uncompressed public key, handling both compressed and uncompressed inputs
|
|
95
|
+
* @param publicKeyHex - Hex string of public key (compressed or uncompressed)
|
|
96
|
+
* @returns Uncompressed public key hex string (64 bytes, without 04 prefix)
|
|
97
|
+
*/
|
|
98
|
+
function getUncompressedPublicKey(publicKeyHex) {
|
|
99
|
+
const cleanHex = publicKeyHex.replace(/^0x/, '');
|
|
100
|
+
// Check if compressed
|
|
101
|
+
if (isCompressedPublicKey(cleanHex)) {
|
|
102
|
+
return decompressPublicKey(cleanHex);
|
|
103
|
+
}
|
|
104
|
+
// If uncompressed with 04 prefix, remove it
|
|
105
|
+
if (cleanHex.startsWith('04')) {
|
|
106
|
+
return cleanHex.slice(2);
|
|
107
|
+
}
|
|
108
|
+
// If already uncompressed without prefix (128 chars = 64 bytes)
|
|
109
|
+
if (cleanHex.length === 128) {
|
|
110
|
+
return cleanHex;
|
|
111
|
+
}
|
|
112
|
+
throw new Error(`Invalid public key format: ${cleanHex.length} hex chars`);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=elliptic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elliptic.js","sourceRoot":"","sources":["../../src/crypto/elliptic.ts"],"names":[],"mappings":";;AAKA,kDA8CC;AA6CD,sDAUC;AAOD,4DAmBC;AApID;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,aAAqB;IACrD,8BAA8B;IAC9B,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAElD,IAAI,QAAQ,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CA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AM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,YAAoB;IACzD,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEjD,sBAAsB;IACtB,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,4CAA4C;IAC5C,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,gEAAgE;IAChE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,QAAQ,CAAC,MAAM,YAAY,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encoding utilities for cryptocurrency operations
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert hex string to Uint8Array
|
|
6
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
7
|
+
* @returns Uint8Array
|
|
8
|
+
*/
|
|
9
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Convert Uint8Array to hex string
|
|
12
|
+
* @param bytes - Uint8Array
|
|
13
|
+
* @param prefix - Whether to add 0x prefix (default: false)
|
|
14
|
+
* @returns Hex string
|
|
15
|
+
*/
|
|
16
|
+
export declare function bytesToHex(bytes: Uint8Array, prefix?: boolean): string;
|
|
17
|
+
/**
|
|
18
|
+
* Convert Buffer to hex string
|
|
19
|
+
* @param buffer - Buffer
|
|
20
|
+
* @param prefix - Whether to add 0x prefix (default: false)
|
|
21
|
+
* @returns Hex string
|
|
22
|
+
*/
|
|
23
|
+
export declare function bufferToHex(buffer: Buffer, prefix?: boolean): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert hex string to Buffer
|
|
26
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
27
|
+
* @returns Buffer
|
|
28
|
+
*/
|
|
29
|
+
export declare function hexToBuffer(hex: string): Buffer;
|
|
30
|
+
/**
|
|
31
|
+
* Convert base64 string to Uint8Array
|
|
32
|
+
* @param base64 - Base64 encoded string
|
|
33
|
+
* @returns Uint8Array
|
|
34
|
+
*/
|
|
35
|
+
export declare function base64ToBytes(base64: string): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Convert Uint8Array to base64 string
|
|
38
|
+
* @param bytes - Uint8Array
|
|
39
|
+
* @returns Base64 encoded string
|
|
40
|
+
*/
|
|
41
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
42
|
+
/**
|
|
43
|
+
* Convert UTF-8 string to Uint8Array
|
|
44
|
+
* @param str - UTF-8 string
|
|
45
|
+
* @returns Uint8Array
|
|
46
|
+
*/
|
|
47
|
+
export declare function utf8ToBytes(str: string): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Convert Uint8Array to UTF-8 string
|
|
50
|
+
* @param bytes - Uint8Array
|
|
51
|
+
* @returns UTF-8 string
|
|
52
|
+
*/
|
|
53
|
+
export declare function bytesToUtf8(bytes: Uint8Array): string;
|
|
54
|
+
/**
|
|
55
|
+
* Concatenate multiple Uint8Arrays
|
|
56
|
+
* @param arrays - Arrays to concatenate
|
|
57
|
+
* @returns Combined Uint8Array
|
|
58
|
+
*/
|
|
59
|
+
export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Compare two Uint8Arrays for equality
|
|
62
|
+
* @param a - First array
|
|
63
|
+
* @param b - Second array
|
|
64
|
+
* @returns True if arrays are equal
|
|
65
|
+
*/
|
|
66
|
+
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Convert number to big-endian Uint8Array
|
|
69
|
+
* @param num - Number to convert
|
|
70
|
+
* @param bytes - Number of bytes (default: 4)
|
|
71
|
+
* @returns Uint8Array in big-endian format
|
|
72
|
+
*/
|
|
73
|
+
export declare function numberToBytes(num: number, bytes?: number): Uint8Array;
|
|
74
|
+
/**
|
|
75
|
+
* Convert big-endian Uint8Array to number
|
|
76
|
+
* @param bytes - Uint8Array in big-endian format
|
|
77
|
+
* @returns Number
|
|
78
|
+
*/
|
|
79
|
+
export declare function bytesToNumber(bytes: Uint8Array): number;
|
|
80
|
+
/**
|
|
81
|
+
* Convert BigInt to Uint8Array
|
|
82
|
+
* @param bigint - BigInt value
|
|
83
|
+
* @param length - Optional fixed length (pads with zeros)
|
|
84
|
+
* @returns Uint8Array
|
|
85
|
+
*/
|
|
86
|
+
export declare function bigintToBytes(bigint: bigint, length?: number): Uint8Array;
|
|
87
|
+
/**
|
|
88
|
+
* Convert Uint8Array to BigInt
|
|
89
|
+
* @param bytes - Uint8Array
|
|
90
|
+
* @returns BigInt
|
|
91
|
+
*/
|
|
92
|
+
export declare function bytesToBigint(bytes: Uint8Array): bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Generate random bytes
|
|
95
|
+
* @param length - Number of bytes to generate
|
|
96
|
+
* @returns Random Uint8Array
|
|
97
|
+
*/
|
|
98
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
99
|
+
/**
|
|
100
|
+
* Hash data using SHA256
|
|
101
|
+
* @param data - Data to hash
|
|
102
|
+
* @returns SHA256 hash as Uint8Array
|
|
103
|
+
*/
|
|
104
|
+
export declare function sha256(data: Uint8Array): Uint8Array;
|
|
105
|
+
/**
|
|
106
|
+
* Double SHA256 hash (used in Bitcoin)
|
|
107
|
+
* @param data - Data to hash
|
|
108
|
+
* @returns Double SHA256 hash as Uint8Array
|
|
109
|
+
*/
|
|
110
|
+
export declare function doubleSha256(data: Uint8Array): Uint8Array;
|
|
111
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/crypto/encoding.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAYlD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,GAAE,OAAe,GAAG,MAAM,CAM7E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe,GAAG,MAAM,CAG3E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAExD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAErD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAW/D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAQhE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,UAAU,CAOxE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAezE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAGvD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAWtD;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAKnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEzD"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Encoding utilities for cryptocurrency operations
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hexToBytes = hexToBytes;
|
|
7
|
+
exports.bytesToHex = bytesToHex;
|
|
8
|
+
exports.bufferToHex = bufferToHex;
|
|
9
|
+
exports.hexToBuffer = hexToBuffer;
|
|
10
|
+
exports.base64ToBytes = base64ToBytes;
|
|
11
|
+
exports.bytesToBase64 = bytesToBase64;
|
|
12
|
+
exports.utf8ToBytes = utf8ToBytes;
|
|
13
|
+
exports.bytesToUtf8 = bytesToUtf8;
|
|
14
|
+
exports.concatBytes = concatBytes;
|
|
15
|
+
exports.bytesEqual = bytesEqual;
|
|
16
|
+
exports.numberToBytes = numberToBytes;
|
|
17
|
+
exports.bytesToNumber = bytesToNumber;
|
|
18
|
+
exports.bigintToBytes = bigintToBytes;
|
|
19
|
+
exports.bytesToBigint = bytesToBigint;
|
|
20
|
+
exports.randomBytes = randomBytes;
|
|
21
|
+
exports.sha256 = sha256;
|
|
22
|
+
exports.doubleSha256 = doubleSha256;
|
|
23
|
+
/**
|
|
24
|
+
* Convert hex string to Uint8Array
|
|
25
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
26
|
+
* @returns Uint8Array
|
|
27
|
+
*/
|
|
28
|
+
function hexToBytes(hex) {
|
|
29
|
+
const cleanHex = hex.replace(/^0x/, '');
|
|
30
|
+
if (cleanHex.length % 2 !== 0) {
|
|
31
|
+
throw new Error('Hex string must have even length');
|
|
32
|
+
}
|
|
33
|
+
const bytes = new Uint8Array(cleanHex.length / 2);
|
|
34
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
35
|
+
bytes[i] = parseInt(cleanHex.substr(i * 2, 2), 16);
|
|
36
|
+
}
|
|
37
|
+
return bytes;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert Uint8Array to hex string
|
|
41
|
+
* @param bytes - Uint8Array
|
|
42
|
+
* @param prefix - Whether to add 0x prefix (default: false)
|
|
43
|
+
* @returns Hex string
|
|
44
|
+
*/
|
|
45
|
+
function bytesToHex(bytes, prefix = false) {
|
|
46
|
+
const hex = Array.from(bytes)
|
|
47
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
48
|
+
.join('');
|
|
49
|
+
return prefix ? '0x' + hex : hex;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Convert Buffer to hex string
|
|
53
|
+
* @param buffer - Buffer
|
|
54
|
+
* @param prefix - Whether to add 0x prefix (default: false)
|
|
55
|
+
* @returns Hex string
|
|
56
|
+
*/
|
|
57
|
+
function bufferToHex(buffer, prefix = false) {
|
|
58
|
+
const hex = buffer.toString('hex');
|
|
59
|
+
return prefix ? '0x' + hex : hex;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert hex string to Buffer
|
|
63
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
64
|
+
* @returns Buffer
|
|
65
|
+
*/
|
|
66
|
+
function hexToBuffer(hex) {
|
|
67
|
+
const cleanHex = hex.replace(/^0x/, '');
|
|
68
|
+
return Buffer.from(cleanHex, 'hex');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Convert base64 string to Uint8Array
|
|
72
|
+
* @param base64 - Base64 encoded string
|
|
73
|
+
* @returns Uint8Array
|
|
74
|
+
*/
|
|
75
|
+
function base64ToBytes(base64) {
|
|
76
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Convert Uint8Array to base64 string
|
|
80
|
+
* @param bytes - Uint8Array
|
|
81
|
+
* @returns Base64 encoded string
|
|
82
|
+
*/
|
|
83
|
+
function bytesToBase64(bytes) {
|
|
84
|
+
return Buffer.from(bytes).toString('base64');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Convert UTF-8 string to Uint8Array
|
|
88
|
+
* @param str - UTF-8 string
|
|
89
|
+
* @returns Uint8Array
|
|
90
|
+
*/
|
|
91
|
+
function utf8ToBytes(str) {
|
|
92
|
+
return new TextEncoder().encode(str);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert Uint8Array to UTF-8 string
|
|
96
|
+
* @param bytes - Uint8Array
|
|
97
|
+
* @returns UTF-8 string
|
|
98
|
+
*/
|
|
99
|
+
function bytesToUtf8(bytes) {
|
|
100
|
+
return new TextDecoder().decode(bytes);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Concatenate multiple Uint8Arrays
|
|
104
|
+
* @param arrays - Arrays to concatenate
|
|
105
|
+
* @returns Combined Uint8Array
|
|
106
|
+
*/
|
|
107
|
+
function concatBytes(...arrays) {
|
|
108
|
+
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
109
|
+
const result = new Uint8Array(totalLength);
|
|
110
|
+
let offset = 0;
|
|
111
|
+
for (const arr of arrays) {
|
|
112
|
+
result.set(arr, offset);
|
|
113
|
+
offset += arr.length;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Compare two Uint8Arrays for equality
|
|
119
|
+
* @param a - First array
|
|
120
|
+
* @param b - Second array
|
|
121
|
+
* @returns True if arrays are equal
|
|
122
|
+
*/
|
|
123
|
+
function bytesEqual(a, b) {
|
|
124
|
+
if (a.length !== b.length)
|
|
125
|
+
return false;
|
|
126
|
+
for (let i = 0; i < a.length; i++) {
|
|
127
|
+
if (a[i] !== b[i])
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Convert number to big-endian Uint8Array
|
|
134
|
+
* @param num - Number to convert
|
|
135
|
+
* @param bytes - Number of bytes (default: 4)
|
|
136
|
+
* @returns Uint8Array in big-endian format
|
|
137
|
+
*/
|
|
138
|
+
function numberToBytes(num, bytes = 4) {
|
|
139
|
+
const arr = new Uint8Array(bytes);
|
|
140
|
+
for (let i = bytes - 1; i >= 0; i--) {
|
|
141
|
+
arr[i] = num & 0xff;
|
|
142
|
+
num = num >> 8;
|
|
143
|
+
}
|
|
144
|
+
return arr;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Convert big-endian Uint8Array to number
|
|
148
|
+
* @param bytes - Uint8Array in big-endian format
|
|
149
|
+
* @returns Number
|
|
150
|
+
*/
|
|
151
|
+
function bytesToNumber(bytes) {
|
|
152
|
+
let num = 0;
|
|
153
|
+
for (const byte of bytes) {
|
|
154
|
+
num = (num << 8) | byte;
|
|
155
|
+
}
|
|
156
|
+
return num;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Convert BigInt to Uint8Array
|
|
160
|
+
* @param bigint - BigInt value
|
|
161
|
+
* @param length - Optional fixed length (pads with zeros)
|
|
162
|
+
* @returns Uint8Array
|
|
163
|
+
*/
|
|
164
|
+
function bigintToBytes(bigint, length) {
|
|
165
|
+
let hex = bigint.toString(16);
|
|
166
|
+
if (hex.length % 2 !== 0) {
|
|
167
|
+
hex = '0' + hex;
|
|
168
|
+
}
|
|
169
|
+
const bytes = hexToBytes(hex);
|
|
170
|
+
if (length && bytes.length < length) {
|
|
171
|
+
const padded = new Uint8Array(length);
|
|
172
|
+
padded.set(bytes, length - bytes.length);
|
|
173
|
+
return padded;
|
|
174
|
+
}
|
|
175
|
+
return bytes;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Convert Uint8Array to BigInt
|
|
179
|
+
* @param bytes - Uint8Array
|
|
180
|
+
* @returns BigInt
|
|
181
|
+
*/
|
|
182
|
+
function bytesToBigint(bytes) {
|
|
183
|
+
if (bytes.length === 0)
|
|
184
|
+
return 0n;
|
|
185
|
+
return BigInt('0x' + bytesToHex(bytes));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Generate random bytes
|
|
189
|
+
* @param length - Number of bytes to generate
|
|
190
|
+
* @returns Random Uint8Array
|
|
191
|
+
*/
|
|
192
|
+
function randomBytes(length) {
|
|
193
|
+
const bytes = new Uint8Array(length);
|
|
194
|
+
if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues) {
|
|
195
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Fallback for Node.js
|
|
199
|
+
const crypto = require('crypto');
|
|
200
|
+
const buffer = crypto.randomBytes(length);
|
|
201
|
+
bytes.set(buffer);
|
|
202
|
+
}
|
|
203
|
+
return bytes;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Hash data using SHA256
|
|
207
|
+
* @param data - Data to hash
|
|
208
|
+
* @returns SHA256 hash as Uint8Array
|
|
209
|
+
*/
|
|
210
|
+
function sha256(data) {
|
|
211
|
+
const crypto = require('crypto');
|
|
212
|
+
const hash = crypto.createHash('sha256');
|
|
213
|
+
hash.update(data);
|
|
214
|
+
return new Uint8Array(hash.digest());
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Double SHA256 hash (used in Bitcoin)
|
|
218
|
+
* @param data - Data to hash
|
|
219
|
+
* @returns Double SHA256 hash as Uint8Array
|
|
220
|
+
*/
|
|
221
|
+
function doubleSha256(data) {
|
|
222
|
+
return sha256(sha256(data));
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/crypto/encoding.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAOH,gCAYC;AAQD,gCAMC;AAQD,kCAGC;AAOD,kCAGC;AAOD,sCAEC;AAOD,sCAEC;AAOD,kCAEC;AAOD,kCAEC;AAOD,kCAWC;AAQD,gCAQC;AAQD,sCAOC;AAOD,sCAMC;AAQD,sCAeC;AAOD,sCAGC;AAOD,kCAWC;AAOD,wBAKC;AAOD,oCAEC;AA9ND;;;;GAIG;AACH,SAAgB,UAAU,CAAC,GAAW;IAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAiB,EAAE,SAAkB,KA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AAC,MAAM,KAAK,WAAW,IAAI,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAChF,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACJ,uBAAuB;QACvB,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC1C,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,IAAgB;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAgB;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { DKLSService } from './core/DKLSService';
|
|
2
|
+
export { DKLSParty } from './core/DKLSParty';
|
|
3
|
+
export { ThresholdConfig } from './core/ThresholdConfig';
|
|
4
|
+
export * from './core/types';
|
|
5
|
+
export * from './crypto/addresses';
|
|
6
|
+
export * from './crypto/encoding';
|
|
7
|
+
export * from './protocols/keygen';
|
|
8
|
+
export * from './protocols/signing';
|
|
9
|
+
export * from './protocols/presignature';
|
|
10
|
+
export * from './protocols/refresh';
|
|
11
|
+
export * from './chains/config';
|
|
12
|
+
export * from './chains/evm/EVMChain';
|
|
13
|
+
export * from './chains/bitcoin/BitcoinChain';
|
|
14
|
+
export * from './rpc/RPCProvider';
|
|
15
|
+
export * from './rpc/methods';
|
|
16
|
+
export * from './wire/format';
|
|
17
|
+
export * from './wire/validation';
|
|
18
|
+
export * from './websocket/coordinator';
|
|
19
|
+
export * from './websocket/session';
|
|
20
|
+
export * from './websocket/messages';
|
|
21
|
+
export { BitShardSDK } from './BitShardSDK';
|
|
22
|
+
export { Message, Keyshare, KeygenSession, SignSession } from '@silencelaboratories/dkls-wasm-ll-node';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,cAAc,cAAc,CAAC;AAG7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAG9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAG9B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SignSession = exports.KeygenSession = exports.Keyshare = exports.Message = exports.BitShardSDK = exports.ThresholdConfig = exports.DKLSParty = exports.DKLSService = void 0;
|
|
18
|
+
// Core exports
|
|
19
|
+
var DKLSService_1 = require("./core/DKLSService");
|
|
20
|
+
Object.defineProperty(exports, "DKLSService", { enumerable: true, get: function () { return DKLSService_1.DKLSService; } });
|
|
21
|
+
var DKLSParty_1 = require("./core/DKLSParty");
|
|
22
|
+
Object.defineProperty(exports, "DKLSParty", { enumerable: true, get: function () { return DKLSParty_1.DKLSParty; } });
|
|
23
|
+
var ThresholdConfig_1 = require("./core/ThresholdConfig");
|
|
24
|
+
Object.defineProperty(exports, "ThresholdConfig", { enumerable: true, get: function () { return ThresholdConfig_1.ThresholdConfig; } });
|
|
25
|
+
__exportStar(require("./core/types"), exports);
|
|
26
|
+
// Crypto exports
|
|
27
|
+
__exportStar(require("./crypto/addresses"), exports);
|
|
28
|
+
__exportStar(require("./crypto/encoding"), exports);
|
|
29
|
+
// Protocol exports
|
|
30
|
+
__exportStar(require("./protocols/keygen"), exports);
|
|
31
|
+
__exportStar(require("./protocols/signing"), exports);
|
|
32
|
+
__exportStar(require("./protocols/presignature"), exports);
|
|
33
|
+
__exportStar(require("./protocols/refresh"), exports);
|
|
34
|
+
// Chain exports
|
|
35
|
+
__exportStar(require("./chains/config"), exports);
|
|
36
|
+
__exportStar(require("./chains/evm/EVMChain"), exports);
|
|
37
|
+
__exportStar(require("./chains/bitcoin/BitcoinChain"), exports);
|
|
38
|
+
// RPC exports
|
|
39
|
+
__exportStar(require("./rpc/RPCProvider"), exports);
|
|
40
|
+
__exportStar(require("./rpc/methods"), exports);
|
|
41
|
+
// Wire format exports
|
|
42
|
+
__exportStar(require("./wire/format"), exports);
|
|
43
|
+
__exportStar(require("./wire/validation"), exports);
|
|
44
|
+
// WebSocket exports
|
|
45
|
+
__exportStar(require("./websocket/coordinator"), exports);
|
|
46
|
+
__exportStar(require("./websocket/session"), exports);
|
|
47
|
+
__exportStar(require("./websocket/messages"), exports);
|
|
48
|
+
// Main SDK class
|
|
49
|
+
var BitShardSDK_1 = require("./BitShardSDK");
|
|
50
|
+
Object.defineProperty(exports, "BitShardSDK", { enumerable: true, get: function () { return BitShardSDK_1.BitShardSDK; } });
|
|
51
|
+
// Re-export classes and types from WASM library
|
|
52
|
+
// This ensures all consumers use the same WASM instance
|
|
53
|
+
var dkls_wasm_ll_node_1 = require("@silencelaboratories/dkls-wasm-ll-node");
|
|
54
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return dkls_wasm_ll_node_1.Message; } });
|
|
55
|
+
Object.defineProperty(exports, "Keyshare", { enumerable: true, get: function () { return dkls_wasm_ll_node_1.Keyshare; } });
|
|
56
|
+
Object.defineProperty(exports, "KeygenSession", { enumerable: true, get: function () { return dkls_wasm_ll_node_1.KeygenSession; } });
|
|
57
|
+
Object.defineProperty(exports, "SignSession", { enumerable: true, get: function () { return dkls_wasm_ll_node_1.SignSession; } });
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,8CAA6C;AAApC,sGAAA,SAAS,OAAA;AAClB,0DAAyD;AAAhD,kHAAA,eAAe,OAAA;AACxB,+CAA6B;AAE7B,iBAAiB;AACjB,qDAAmC;AACnC,oDAAkC;AAElC,mBAAmB;AACnB,qDAAmC;AACnC,sDAAoC;AACpC,2DAAyC;AACzC,sDAAoC;AAEpC,gBAAgB;AAChB,kDAAgC;AAChC,wDAAsC;AACtC,gEAA8C;AAE9C,cAAc;AACd,oDAAkC;AAClC,gDAA8B;AAE9B,sBAAsB;AACtB,gDAA8B;AAC9B,oDAAkC;AAElC,oBAAoB;AACpB,0DAAwC;AACxC,sDAAoC;AACpC,uDAAqC;AAErC,iBAAiB;AACjB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAEpB,gDAAgD;AAChD,wDAAwD;AACxD,4EAAuG;AAA9F,4GAAA,OAAO,OAAA;AAAE,6GAAA,QAAQ,OAAA;AAAE,kHAAA,aAAa,OAAA;AAAE,gHAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keygen.d.ts","sourceRoot":"","sources":["../../src/protocols/keygen.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Key generation protocol implementation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DKLSParty = exports.DKLSService = void 0;
|
|
7
|
+
var DKLSService_1 = require("../core/DKLSService");
|
|
8
|
+
Object.defineProperty(exports, "DKLSService", { enumerable: true, get: function () { return DKLSService_1.DKLSService; } });
|
|
9
|
+
var DKLSParty_1 = require("../core/DKLSParty");
|
|
10
|
+
Object.defineProperty(exports, "DKLSParty", { enumerable: true, get: function () { return DKLSParty_1.DKLSParty; } });
|
|
11
|
+
// TODO: Implement protocol-specific helpers and utilities
|
|
12
|
+
//# sourceMappingURL=keygen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keygen.js","sourceRoot":"","sources":["../../src/protocols/keygen.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AACpB,+CAA8C;AAArC,sGAAA,SAAS,OAAA;AAElB,0DAA0D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-signature generation and management
|
|
3
|
+
*
|
|
4
|
+
* CRITICAL SECURITY WARNING:
|
|
5
|
+
* Pre-signatures MUST NOT be reused. Reusing a pre-signature will expose the private key.
|
|
6
|
+
*/
|
|
7
|
+
import { Keyshare } from '@silencelaboratories/dkls-wasm-ll-node';
|
|
8
|
+
import type { PreSignature } from '../core/types';
|
|
9
|
+
/**
|
|
10
|
+
* Pre-signature manager for secure pre-signature generation and tracking
|
|
11
|
+
*/
|
|
12
|
+
export declare class PreSignatureManager {
|
|
13
|
+
private consumedPreSignatures;
|
|
14
|
+
private preSignaturePool;
|
|
15
|
+
/**
|
|
16
|
+
* Generate pre-signatures that can be computed ahead of time
|
|
17
|
+
* @param keyshares Array of keyshares
|
|
18
|
+
* @param threshold Threshold value
|
|
19
|
+
* @param count Number of pre-signatures to generate
|
|
20
|
+
* @returns Array of pre-signatures
|
|
21
|
+
*/
|
|
22
|
+
generatePreSignatures(keyshares: Keyshare[], threshold: number, count?: number): Promise<PreSignature[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Execute pre-signature generation rounds
|
|
25
|
+
*/
|
|
26
|
+
private executePreSignatureRounds;
|
|
27
|
+
/**
|
|
28
|
+
* Use a pre-signature to sign a message
|
|
29
|
+
* @param messageHash Message hash to sign
|
|
30
|
+
* @param preSignature Pre-signature to consume
|
|
31
|
+
* @returns Signature components
|
|
32
|
+
*/
|
|
33
|
+
signWithPreSignature(messageHash: Uint8Array, preSignature: PreSignature): Promise<[Uint8Array, Uint8Array]>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a pre-signature has been consumed
|
|
36
|
+
* @param id Pre-signature ID
|
|
37
|
+
* @returns True if consumed
|
|
38
|
+
*/
|
|
39
|
+
isConsumed(id: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Get available pre-signature count
|
|
42
|
+
* @returns Number of unused pre-signatures
|
|
43
|
+
*/
|
|
44
|
+
getAvailableCount(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Get next available pre-signature
|
|
47
|
+
* @returns Pre-signature or undefined
|
|
48
|
+
*/
|
|
49
|
+
getNextAvailable(): PreSignature | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Clear consumed pre-signatures from pool
|
|
52
|
+
*/
|
|
53
|
+
cleanupConsumed(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Generate unique ID
|
|
56
|
+
*/
|
|
57
|
+
private generateId;
|
|
58
|
+
/**
|
|
59
|
+
* Filter messages for broadcast
|
|
60
|
+
*/
|
|
61
|
+
private filterMessages;
|
|
62
|
+
/**
|
|
63
|
+
* Select P2P messages
|
|
64
|
+
*/
|
|
65
|
+
private selectMessages;
|
|
66
|
+
}
|
|
67
|
+
export declare const preSignatureManager: PreSignatureManager;
|
|
68
|
+
//# sourceMappingURL=presignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presignature.d.ts","sourceRoot":"","sources":["../../src/protocols/presignature.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAe,QAAQ,EAAW,MAAM,wCAAwC,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,qBAAqB,CAA0B;IACvD,OAAO,CAAC,gBAAgB,CAAwC;IAEhE;;;;;;OAMG;IACG,qBAAqB,CACvB,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,MAAU,GAClB,OAAO,CAAC,YAAY,EAAE,CAAC;IA+B1B;;OAEG;YACW,yBAAyB;IA+BvC;;;;;OAKG;IACG,oBAAoB,CACtB,WAAW,EAAE,UAAU,EACvB,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAgCpC;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI/B;;;OAGG;IACH,iBAAiB,IAAI,MAAM;IAK3B;;;OAGG;IACH,gBAAgB,IAAI,YAAY,GAAG,SAAS;IAK5C;;OAEG;IACH,eAAe,IAAI,IAAI;IAQvB;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,cAAc;CAGzB;AAGD,eAAO,MAAM,mBAAmB,qBAA4B,CAAC"}
|