/** * Generate address for the key, see {@link KeyAddress} for more. * * @param useSha3_384 use SHA3-384 for hash, otherwise SHA3-256 * @param keyMark some data code in 0..15 range inclusive * @return generated address */ public KeyAddress address(boolean useSha3_384, int keyMark) { return new KeyAddress(this, keyMark, useSha3_384); }
@Override public int hashCode() { return toString().hashCode(); }
private static void doAddressMatch(String address, String keyFilePath) throws IOException { boolean bResult = false; try { PublicKey key = readKeyAndGetPublic(keyFilePath); KeyAddress keyAddress = new KeyAddress(address); bResult = keyAddress.isMatchingKey(key); } catch (Exception e) {}; report("Matching address: " + address + " with key: "+ keyFilePath); report("Matching result: " + bResult); finish(); }
@Override public final boolean isMatchingKeyAddress(KeyAddress other) { return other.isLong() ? getLongAddress().isMatchingKeyAddress(other) : getShortAddress().isMatchingKeyAddress(other); }
/** * Check that the address matches role. * * @param keyAddress address for matching with role * @return true if match or false * @deprecated the only usable check allowance method is isAllowedForKeys */ @Deprecated public boolean isMatchingKeyAddress(KeyAddress keyAddress) { for (KeyAddress ka : this.getKeyAddresses()) { if (keyAddress.isMatchingKeyAddress(ka)) return true; } for (PublicKey pk : this.getKeys()) { if (keyAddress.isMatchingKey(pk)) return true; } return false; } /**
private void testMatch(boolean use384) throws KeyAddress.IllegalAddressException { KeyAddress a = key1.address(use384, 7); KeyAddress b = new KeyAddress(a.toString()); assertEquals(7, b.getTypeMark()); assertEquals(7, a.getTypeMark()); assertTrue(b.isMatchingKey(key1)); assertTrue(a.isMatchingKeyAddress(b)); assertTrue(b.isMatchingKeyAddress(a)); assertTrue(key1.isMatchingKey(key1)); assertTrue(key1.isMatchingKeyAddress(a)); assertTrue(key1.isMatchingKeyAddress(b)); byte[] pack = a.getPacked(); pack[7] ^= 71; try { new KeyAddress(pack); fail("must throw error on spoiled address"); } catch(KeyAddress.IllegalAddressException e) { } }
private static void doCreateAddress(String keyFilePath, boolean bShort) throws IOException { report("Generate " + (bShort ? "short" : "long") + " address from key: " + keyFilePath); PublicKey key = readKeyAndGetPublic(keyFilePath); KeyAddress address = new KeyAddress(key, 0, !bShort); report("Address: " + address.toString()); finish(); }
public NNameRecord(@NonNull UnsName unsName, @NonNull ZonedDateTime expiresAt) { name = unsName.getUnsName(); nameReduced = unsName.getUnsReducedName(); description = unsName.getUnsDescription(); url = unsName.getUnsURL(); this.expiresAt = expiresAt; unsName.getUnsRecords().forEach(unsRecord -> { String longAddress = null; String shortAddress = null; for (KeyAddress keyAddress : unsRecord.getAddresses()) { if (keyAddress.isLong()) longAddress = keyAddress.toString(); else shortAddress = keyAddress.toString(); } entries.add(new NNameRecordEntry(unsRecord.getOrigin(), shortAddress, longAddress)); }); }
public boolean isMatchingKey(AbstractKey key) { for (KeyAddress addr: unsAddresses) if (addr.isMatchingKey(key)) return true; return false; }
@Test public void serialize() throws IOException { KeyAddress a = key1.address(true, 8); KeyAddress b = key1.address(false, 9); Boss.Reader r = new Boss.Reader(Boss.dump(a,b).toArray()); KeyAddress x = r.read(); KeyAddress y = r.read(); assertEquals(8, x.getTypeMark()); assertEquals(9, y.getTypeMark()); assertTrue(x.isMatchingKey(key1)); assertTrue(y.isMatchingKeyAddress(b)); } }
addError(Errors.FAILED_CHECK, NAMES_FIELD_NAME, "name " + n.getUnsName() + ": Addresses list should not be contains more 2 addresses"); if ((unsRecord.getAddresses().size() == 2) && unsRecord.getAddresses().get(0).isLong() == unsRecord.getAddresses().get(1).isLong()) addError(Errors.FAILED_CHECK, NAMES_FIELD_NAME, "name " + n.getUnsName() + ": Addresses list may only contain one short and one long addresses"); if(!unsRecord.getAddresses().stream().allMatch(keyAddress -> getEffectiveKeys().stream().anyMatch(key -> keyAddress.isMatchingKey(key)))) { addError(Errors.FAILED_CHECK, NAMES_FIELD_NAME, "name " + n.getUnsName() + " using address that missing corresponding key UNS contract signed with."); return false;
public boolean isMatchingAddress(KeyAddress address) { for (KeyAddress addr: unsAddresses) if (addr.isMatchingKeyAddress(address)) return true; return false; }
public UnsRecord(List<KeyAddress> addresses) { if (addresses.size() > 2) throw new IllegalArgumentException("Addresses list should not be contains more 2 addresses"); if ((addresses.size() == 2) && addresses.get(0).isLong() == addresses.get(1).isLong()) throw new IllegalArgumentException("Addresses list may be contains only one short and one long addresses"); unsAddresses.addAll(addresses); }
private boolean hasAllKeys(SimpleRole role1, SimpleRole role2) { if(!role1.keyRecords.keySet().stream().allMatch(k-> role2.keyRecords.containsKey(k) || role2.keyAddresses.contains(k.getShortAddress()) || role2.keyAddresses.contains(k.getLongAddress()) || role2.anonymousIds.contains(new AnonymousId(k.createAnonymousId())))) return false; if(!role1.keyAddresses.stream().allMatch(ka-> role2.keyAddresses.contains(ka) || role2.keyRecords.keySet().stream().anyMatch(key->ka.equals(key.getShortAddress()) || ka.equals(key.getLongAddress())))) return false; if(!role1.anonymousIds.stream().allMatch(anonymousId -> role2.anonymousIds.contains(anonymousId) || role2.keyRecords.keySet().stream().anyMatch(key->new AnonymousId(key.createAnonymousId()).equals(anonymousId)))) return false; return true; }
KeyAddress keyAddr = new KeyAddress(randomPrivKey.getPublicKey(), 0, true); nameInfo = testSpace.client.queryNameRecord(keyAddr.toString()); name = nameInfo.getString("name", null); System.out.println("name info is null: " + (name == null)); assertEquals(ItemState.APPROVED, itemResult.state); nameInfo = testSpace.client.queryNameRecord(keyAddr.toString()); assertNotNull(nameInfo); System.out.println("name info size: " + nameInfo.size());
private Binder startApproval(final Binder params, Session session) throws IOException, Quantiser.QuantiserException { if (config == null || config.limitFreeRegistrations()) if(config == null || ( !config.getKeysWhiteList().contains(session.getPublicKey()) && !config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())))) { System.out.println("startApproval ERROR: session key shoild be in the white list"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"startApproval", "command needs client key from whitelist")); } int n = asyncStarts.incrementAndGet(); AtomicInteger k = new AtomicInteger(); params.getListOrThrow("packedItems").forEach((item) -> es.execute(() -> { try { checkNode(session); System.out.println("Request to start registration #"+n+":"+k.incrementAndGet()); node.registerItem(Contract.fromPackedTransaction(((Bytes)item).toArray())); } catch (Exception e) { e.printStackTrace(); } }) ); //TODO: return ItemResult return new Binder(); }
@Override public Binder serialize(Object object, BiSerializer serializer) { return Binder.of("uaddress", serializer.serialize(((KeyAddress) object).getPacked())); //TODO: serialization is necessary }
@Override public boolean isMatchingKey(AbstractKey key) { return getShortAddress().isMatchingKeyAddress(key.getShortAddress()); }