/** * 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); }
public UnsRecord(AbstractKey key, int keyMark) { unsAddresses.add(new KeyAddress(key, keyMark, false)); unsAddresses.add(new KeyAddress(key, keyMark, true)); }
public UnsRecord(AbstractKey key) { unsAddresses.add(new KeyAddress(key, 0, false)); unsAddresses.add(new KeyAddress(key, 0, true)); }
/** * Check that the key matches this address, e.g. has of the same type and the digest of its components is the same. * The key components digest is calculated by the key self in the {@link AbstractKey#updateDigestWithKeyComponents(Digest)} * * @param key * to check * * @return true if the key matches (what means, it is the key corresponding to this address) */ @Override public boolean isMatchingKey(AbstractKey key) { KeyAddress other = new KeyAddress(key, 0, _isLong); if (other.keyMask != keyMask) return false; if (!Arrays.equals(keyDigest, other.keyDigest)) return false; return true; }
public JSApiSimpleRole(String name, String... addresses) throws KeyAddress.IllegalAddressException { List<KeyAddress> keyAddresses = new ArrayList<>(); for (int i = 0; i < addresses.length; ++i) { keyAddresses.add(new KeyAddress(addresses[i])); } simpleRole = new SimpleRole(name, keyAddresses); }
public void setOwner(List<String> addresses) throws KeyAddress.IllegalAddressException { List<KeyAddress> addressesList = new ArrayList<>(); for (String s : addresses) addressesList.add(new KeyAddress(s)); this.currentContract.setOwnerKeys(addressesList); }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { try { return new KeyAddress(binder.getBinaryOrThrow("uaddress")); } catch (IllegalAddressException e) { e.printStackTrace(); throw new IllegalArgumentException("can't reconstruct KeyAddress"); } }
protected UnsRecord initializeWithDsl(Binder binder) { String digest = binder.getString(ORIGIN_FIELD_NAME, null); if (digest != null) { unsOrigin = HashId.withDigest(digest); } else { ArrayList<?> list = binder.getArray(ADDRESSES_FIELD_NAME); for (Object obj: list) if (obj.getClass().getName().endsWith("String")) { try { unsAddresses.add(new KeyAddress((String) obj)); } catch (Exception e) { throw new IllegalArgumentException("Error converting address from base58 string: " + e.getMessage()); } } } return this; }
@Before public void beforeScriptEngineTest() throws Exception { // add U issuer test key configForProvider.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }
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(); }
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(); }
Main createMain(String name, String postfix, boolean nolog) throws InterruptedException { String path = new File("src/test_node_config_v2" + postfix + "/" + name).getAbsolutePath(); System.out.println(path); String[] args = new String[]{"--test", "--config", path, nolog ? "--nolog" : ""}; List<Main> mm = new ArrayList<>(); Thread thread = new Thread(() -> { try { Main m = new Main(args); try { m.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } //m.config.getKeysWhiteList().add(m.config.getUIssuerKey()); m.waitReady(); mm.add(m); } catch (InterruptedException e) { e.printStackTrace(); } }); thread.setName("Node Server: " + name); thread.start(); while (mm.size() == 0) { Thread.sleep(100); } return mm.get(0); }
@Before public void beforeMainTest() throws Exception { // clearLedgers List<String> dbUrls = new ArrayList<>(); dbUrls.add("jdbc:postgresql://localhost:5432/universa_node_t1"); dbUrls.add("jdbc:postgresql://localhost:5432/universa_node_t2"); dbUrls.add("jdbc:postgresql://localhost:5432/universa_node_t3"); dbUrls.add("jdbc:postgresql://localhost:5432/universa_node_t4"); List<Ledger> ledgers = new ArrayList<>(); dbUrls.stream().forEach(url -> { try { clearLedger(url); PostgresLedger ledger = new PostgresLedger(url); ledgers.add(ledger); } catch (Exception e) { e.printStackTrace(); } }); // add U issuer test key configForProvider.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }
@Test public void testAddressRole() throws Exception { Set<KeyAddress> keyAddresses = new HashSet<>(); keyAddresses.add(new KeyAddress(keys.get(0).getPublicKey(), 0, true)); SimpleRole sr = new SimpleRole("tr1", keyAddresses); Binder serialized = DefaultBiMapper.serialize(sr); Role r1 = DefaultBiMapper.deserialize(serialized); Set<PublicKey> pubKeys = new HashSet<>(); pubKeys.add(keys.get(0).getPublicKey()); assertTrue(sr.isAllowedForKeys(pubKeys)); assertTrue(r1.isAllowedForKeys(pubKeys)); assertEquals(sr, r1); }
@BeforeClass public static void beforeClass() throws Exception { nodeConfig = new Config(); nodeConfig.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }
static Main createMain(String name,boolean nolog) throws InterruptedException { String path = new File("src/test_node_config_v2/"+name).getAbsolutePath(); System.out.println(path); String[] args = new String[]{"--test", "--config", path, nolog ? "--nolog" : ""}; Main main = new Main(args); try { main.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } try { //main.config.getKeysWhiteList().add(CLIMain.getPrivateKey().getPublicKey()); main.config.getAddressesWhiteList().add(new KeyAddress(CLIMain.getPrivateKey().getPublicKey(), 0, true)); } catch (IOException e) { e.printStackTrace(); } //main.config.getKeysWhiteList().add(main.config.getUIssuerKey()); main.waitReady(); return main; }
@BeforeClass public static void beforeClass() throws Exception { nodeConfig = new Config(); nodeConfig.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }
@Test public void addWhiteListAddressTest() { Config config = new Config(); PrivateKey randomKey = new PrivateKey(4096); KeyAddress keyAddr = new KeyAddress(randomKey.getPublicKey(), 0, true); config.getAddressesWhiteList().add(keyAddr); assertTrue(config.getAddressesWhiteList().contains(keyAddr)); } }
@Test public void testCloneAsAddressRole() throws Exception { Set<KeyAddress> keyAddresses = new HashSet<>(); keyAddresses.add(new KeyAddress(keys.get(0).getPublicKey(), 0, true)); SimpleRole sr = new SimpleRole("tr1", keyAddresses); SimpleRole r1 = sr.cloneAs("tr2"); SimpleRole r2 = r1.cloneAs("tr1"); assertEquals(sr, r2); } }
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) { } }