@Test public void tvTest5() throws BipSss.NotEnoughSharesException, BipSss.InvalidContentTypeException, BipSss.IncompatibleSharesException { Collection<Share> shares = addShareWithId("SSS-5CJkUwdiUPZi2R8RJJzkUFvs1TWC22JAQD2T3QMyhuAvDgzrXKuhT5at", "20ba", new ArrayList<Share>()); addShareWithId("SSS-5CJkUyu8LAq7Newbgpc58SKsuNXvQyxAtnYzVjU1bRhF5hFYyvYaKToq", "20ba", shares); addShareWithId("SSS-5CJkVAkE319sk7FZVnoUgaqge6vmK1bLXwN2mm9d3VgM5hzm6qdh5TrX", "20ba", shares); String result1 = BipSss.combine(shares); assertResult(result1, HexUtils.toBytes("80be1583452771c1def6789be9ab5086bf3c18dd47aa99d785056ba330bcda7aaf")); assertEquals(result1, "5KG12Hn1g33JEFwdFsbjW4Hzi2fqdsEKZTtcJ3q9L6QFLvL1UJS"); String result2 = BipSss.combine(addShareWithId("SSS-5CJkVAkE319sk7FZVnoUgaqge6vmK1bLXwN2mm9d3VgM5hzm6qdh5TrX", "20ba", addShareWithId("SSS-5CJkUyu8LAq7Newbgpc58SKsuNXvQyxAtnYzVjU1bRhF5hFYyvYaKToq", "20ba", new ArrayList<Share>()))); 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);  }