@@ -13,6 +13,39 @@ it("should reconstruct a key", () => {
1313 ) ;
1414} ) ;
1515
16+ describe ( "should handle a key part being passed twice" , ( ) => {
17+ it ( "fail when there are not enough key parts" , ( ) => {
18+ assert . notStrictEqual (
19+ Buffer . from ( shamir . reconstruct ( [
20+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
21+ Buffer . from ( [ 0x62 , 0x1e , 0x41 , 0x63 , 0xfa , 0x5e , 0x0b , 0x1c ] ) ,
22+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
23+ ] ) ) . toString ( "hex" ) ,
24+ Buffer . from ( "caritat" ) . toString ( "hex" ) ,
25+ ) ;
26+ } ) ;
27+ it ( "throw if the are incompatible key parts" , ( ) => {
28+ assert . throws (
29+ ( ) => shamir . reconstruct ( [
30+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
31+ Buffer . from ( [ 0x62 , 0x1e , 0x41 , 0x63 , 0xfa , 0x5e , 0x0b , 0x1c ] ) ,
32+ Buffer . from ( [ 0xc4 , 0xc8 , 0x3c , 0x22 , 0x53 , 0x05 , 0x62 , 0x02 ] ) ,
33+ ] ) , / T h e r e a r e c o n f l i c t i n g k e y s h a r e s / ) ;
34+ } ) ;
35+ it ( "succeed when there are enough key parts" , ( ) => {
36+ assert . strictEqual (
37+ Buffer . from ( shamir . reconstruct ( [
38+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
39+ Buffer . from ( [ 0x62 , 0x1e , 0x41 , 0x63 , 0xfa , 0x5e , 0x0b , 0x1c ] ) ,
40+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
41+ Buffer . from ( [ 0xc4 , 0xc8 , 0x3c , 0x22 , 0x53 , 0x05 , 0x62 , 0x0a ] ) ,
42+ Buffer . from ( [ 0xef , 0x05 , 0x70 , 0x4a , 0xf2 , 0xb2 , 0xcd , 0x02 ] ) ,
43+ ] ) ) . toString ( "hex" ) ,
44+ Buffer . from ( "caritat" ) . toString ( "hex" ) ,
45+ ) ;
46+ } ) ;
47+ } ) ;
48+
1649const key = crypto . getRandomValues ( new Uint8Array ( 256 ) ) ;
1750
1851describe ( "should reconstruct single byte with enough shareholders" , ( ) => {
@@ -95,9 +128,9 @@ it("should fail reconstruct key from not enough shareholders", () => {
95128it ( "should fail reconstruct key with duplicate shareholders" , ( ) => {
96129 assert . throws (
97130 ( ) => {
98- shamir . reconstruct ( [ parts [ 1 ] , parts [ 5 ] , parts [ 1 ] ] ) ;
131+ shamir . reconstruct ( [ parts [ 1 ] , parts [ 5 ] , parts [ 1 ] ] , 3 ) ;
99132 } ,
100- { message : "Div/0 " } ,
133+ { message : "Not enough parts to reconstruct key " } ,
101134 ) ;
102135} ) ;
103136
0 commit comments