@Test public void tvTest4() throws BipSss.NotEnoughSharesException, BipSss.InvalidContentTypeException, BipSss.IncompatibleSharesException { Collection<Share> shares = addShareWithId("SSS-2cTMvHxbT71LzEzbfi", "5851", new ArrayList<Share>()); addShareWithId("SSS-2cTMvNxxgQ3Hcg1Bab", "5851", shares); addShareWithId("SSS-2cTMvRAx1uoJ6T9Fz5", "5851", shares); addShareWithId("SSS-2cTMvSXoCxpjcMFhvb", "5851", shares); addShareWithId("SSS-2cTMvVpRNubeWKfbKS", "5851", shares); addShareWithId("SSS-2cTMvaEr6YefknXEV4", "5851", shares); addShareWithId("SSS-2cTMvdkULmYJVobgaW", "5851", shares); addShareWithId("SSS-2cTMvh5uxQ4SavKAkh", "5851", shares); String result1 = BipSss.combine(shares); assertResult(result1, HexUtils.toBytes("0102030405")); shares = addShareWithId("SSS-2cTMvHxbT71LzEzbfi", "5851", new ArrayList<Share>()); addShareWithId("SSS-2cTMvVpRNubeWKfbKS", "5851", shares); addShareWithId("SSS-2cTMvaEr6YefknXEV4", "5851", shares); addShareWithId("SSS-2cTMvdkULmYJVobgaW", "5851", shares); addShareWithId("SSS-2cTMvh5uxQ4SavKAkh", "5851", shares); String result2 = BipSss.combine(shares); assertEquals(result1, result2); }
public static String combine(Collection<Share> shares) throws IncompatibleSharesException, NotEnoughSharesException, InvalidContentTypeException { if (shares.size() == 0) { throw new NotEnoughSharesException(1); } Iterator<Share> it = shares.iterator(); Share firstShare = it.next(); while (it.hasNext()) { Share share = it.next(); if (!share.isCompatible(firstShare)) { throw new IncompatibleSharesException(); } } if (firstShare.contentType != TYPE_BASE_58_STRING) { throw new InvalidContentTypeException(); } Collection<Share> unique = Share.removeDuplicateIndexes(shares); int threshold = unique.iterator().next().threshold; if (threshold > unique.size()) { throw new NotEnoughSharesException(threshold - unique.size()); } List<Share> selection = new ArrayList<Share>(); it = unique.iterator(); while (it.hasNext()) { selection.add(it.next()); if (selection.size() == threshold) { break; } } Gf256 gf = new Gf256(); List<Gf256.Share> gfShares = new ArrayList<Gf256.Share>(); for (Share s : selection) { gfShares.add(new Gf256.Share((byte) s.shareNumber, s.shareData)); } byte[] content = gf.combineShares(gfShares); return Base58.encodeWithChecksum(content); }
BipSss { public static String combine(Collection<Share> shares) throws IncompatibleSharesException, NotEnoughSharesException, InvalidContentTypeException { if (shares.size() == 0) { throw new NotEnoughSharesException(1); } Iterator<Share> it = shares.iterator(); Share firstShare = it.next(); while (it.hasNext()) { Share share = it.next(); if (!share.isCompatible(firstShare)) { throw new IncompatibleSharesException(); } } if (firstShare.contentType != TYPE_BASE_58_STRING) { throw new InvalidContentTypeException(); } Collection<Share> unique = Share.removeDuplicateIndexes(shares); int threshold = unique.iterator().next().threshold; if (threshold > unique.size()) { throw new NotEnoughSharesException(threshold - unique.size()); } List<Share> selection = new ArrayList<Share>(); it = unique.iterator(); while (it.hasNext()) { selection.add(it.next()); if (selection.size() == threshold) { break; } } Gf256 gf = new Gf256(); List<Gf256.Share> gfShares = new ArrayList<Gf256.Share>(); for (Share s : selection) { gfShares.add(new Gf256.Share((byte) s.shareNumber, s.shareData)); } byte[] content = gf.combineShares(gfShares); return Base58.encodeWithChecksum(content); } }
BipSss { public static String combine(Collection<Share> shares) throws IncompatibleSharesException, NotEnoughSharesException, InvalidContentTypeException { if (shares.size() == 0) { throw new NotEnoughSharesException(1); } Iterator<Share> it = shares.iterator(); Share firstShare = it.next(); while (it.hasNext()) { Share share = it.next(); if (!share.isCompatible(firstShare)) { throw new IncompatibleSharesException(); } } if (firstShare.contentType != TYPE_BASE_58_STRING) { throw new InvalidContentTypeException(); } Collection<Share> unique = Share.removeDuplicateIndexes(shares); int threshold = unique.iterator().next().threshold; if (threshold > unique.size()) { throw new NotEnoughSharesException(threshold - unique.size()); } List<Share> selection = new ArrayList<Share>(); it = unique.iterator(); while (it.hasNext()) { selection.add(it.next()); if (selection.size() == threshold) { break; } } Gf256 gf = new Gf256(); List<Gf256.Share> gfShares = new ArrayList<Gf256.Share>(); for (Share s : selection) { gfShares.add(new Gf256.Share((byte) s.shareNumber, s.shareData)); } byte[] content = gf.combineShares(gfShares); return Base58.encodeWithChecksum(content); }  }
BipSss { public static String combine(Collection<Share> shares) throws IncompatibleSharesException, NotEnoughSharesException, InvalidContentTypeException { if (shares.size() == 0) { throw new NotEnoughSharesException(1); } Iterator<Share> it = shares.iterator(); Share firstShare = it.next(); while (it.hasNext()) { Share share = it.next(); if (!share.isCompatible(firstShare)) { throw new IncompatibleSharesException(); } } if (firstShare.contentType != TYPE_BASE_58_STRING) { throw new InvalidContentTypeException(); } Collection<Share> unique = Share.removeDuplicateIndexes(shares); int threshold = unique.iterator().next().threshold; if (threshold > unique.size()) { throw new NotEnoughSharesException(threshold - unique.size()); } List<Share> selection = new ArrayList<Share>(); it = unique.iterator(); while (it.hasNext()) { selection.add(it.next()); if (selection.size() == threshold) { break; } } Gf256 gf = new Gf256(); List<Gf256.Share> gfShares = new ArrayList<Gf256.Share>(); for (Share s : selection) { gfShares.add(new Gf256.Share((byte) s.shareNumber, s.shareData)); } byte[] content = gf.combineShares(gfShares); return Base58.encodeWithChecksum(content); }  static String combine(Collection<Share> shares); }
BipSss { public static String combine(Collection<Share> shares) throws IncompatibleSharesException, NotEnoughSharesException, InvalidContentTypeException { if (shares.size() == 0) { throw new NotEnoughSharesException(1); } Iterator<Share> it = shares.iterator(); Share firstShare = it.next(); while (it.hasNext()) { Share share = it.next(); if (!share.isCompatible(firstShare)) { throw new IncompatibleSharesException(); } } if (firstShare.contentType != TYPE_BASE_58_STRING) { throw new InvalidContentTypeException(); } Collection<Share> unique = Share.removeDuplicateIndexes(shares); int threshold = unique.iterator().next().threshold; if (threshold > unique.size()) { throw new NotEnoughSharesException(threshold - unique.size()); } List<Share> selection = new ArrayList<Share>(); it = unique.iterator(); while (it.hasNext()) { selection.add(it.next()); if (selection.size() == threshold) { break; } } Gf256 gf = new Gf256(); List<Gf256.Share> gfShares = new ArrayList<Gf256.Share>(); for (Share s : selection) { gfShares.add(new Gf256.Share((byte) s.shareNumber, s.shareData)); } byte[] content = gf.combineShares(gfShares); return Base58.encodeWithChecksum(content); }  static String combine(Collection<Share> shares);  }