org.web3j.utils.Numeric.toHexStringNoPrefix()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.web3j.utils.Numeric.toHexStringNoPrefix()方法的一些代码示例,展示了Numeric.toHexStringNoPrefix()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Numeric.toHexStringNoPrefix()方法的具体详情如下:
包路径:org.web3j.utils.Numeric
类名称:Numeric
方法名:toHexStringNoPrefix

Numeric.toHexStringNoPrefix介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

static String encodeBool(Bool value) {
  byte[] rawValue = new byte[MAX_BYTE_LENGTH];
  if (value.getValue()) {
    rawValue[rawValue.length - 1] = 1;
  }
  return Numeric.toHexStringNoPrefix(rawValue);
}

代码示例来源:origin: web3j/web3j

public static String toHexStringWithPrefixSafe(BigInteger value) {
  String result = toHexStringNoPrefix(value);
  if (result.length() < 2) {
    result = Strings.zeros(1) + result;
  }
  return HEX_PREFIX + result;
}

代码示例来源:origin: web3j/web3j

static String encodeBytes(BytesType bytesType) {
  byte[] value = bytesType.getValue();
  int length = value.length;
  int mod = length % MAX_BYTE_LENGTH;
  byte[] dest;
  if (mod != 0) {
    int padding = MAX_BYTE_LENGTH - mod;
    dest = new byte[length + padding];
    System.arraycopy(value, 0, dest, 0, length);
  } else {
    dest = value;
  }
  return Numeric.toHexStringNoPrefix(dest);
}

代码示例来源:origin: web3j/web3j

private static String toHexStringZeroPadded(BigInteger value, int size, boolean withPrefix) {
  String result = toHexStringNoPrefix(value);
  int length = result.length();
  if (length > size) {
    throw new UnsupportedOperationException(
        "Value " + result + "is larger then length " + size);
  } else if (value.signum() < 0) {
    throw new UnsupportedOperationException("Value cannot be negative");
  }
  if (length < size) {
    result = Strings.zeros(size - length) + result;
  }
  if (withPrefix) {
    return HEX_PREFIX + result;
  } else {
    return result;
  }
}

代码示例来源:origin: web3j/web3j

static String encodeNumeric(NumericType numericType) {
  byte[] rawValue = toByteArray(numericType);
  byte paddingValue = getPaddingValue(numericType);
  byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH];
  if (paddingValue != 0) {
    for (int i = 0; i < paddedRawValue.length; i++) {
      paddedRawValue[i] = paddingValue;
    }
  }
  System.arraycopy(
      rawValue, 0,
      paddedRawValue, MAX_BYTE_LENGTH - rawValue.length,
      rawValue.length);
  return Numeric.toHexStringNoPrefix(paddedRawValue);
}

代码示例来源:origin: web3j/web3j

@Test
public void testToHexStringNoPrefix() {
  assertThat(Numeric.toHexStringNoPrefix(BigInteger.TEN), is("a"));
}

代码示例来源:origin: web3j/web3j

Numeric.toHexStringNoPrefix(
    Numeric.toBytesPadded(
        new BigInteger(Long.toString(offset)), MAX_BYTE_LENGTH

代码示例来源:origin: web3j/web3j

private static WalletFile createWalletFile(
    ECKeyPair ecKeyPair, byte[] cipherText, byte[] iv, byte[] salt, byte[] mac,
    int n, int p) {
  WalletFile walletFile = new WalletFile();
  walletFile.setAddress(Keys.getAddress(ecKeyPair));
  WalletFile.Crypto crypto = new WalletFile.Crypto();
  crypto.setCipher(CIPHER);
  crypto.setCiphertext(Numeric.toHexStringNoPrefix(cipherText));
  WalletFile.CipherParams cipherParams = new WalletFile.CipherParams();
  cipherParams.setIv(Numeric.toHexStringNoPrefix(iv));
  crypto.setCipherparams(cipherParams);
  crypto.setKdf(SCRYPT);
  WalletFile.ScryptKdfParams kdfParams = new WalletFile.ScryptKdfParams();
  kdfParams.setDklen(DKLEN);
  kdfParams.setN(n);
  kdfParams.setP(p);
  kdfParams.setR(R);
  kdfParams.setSalt(Numeric.toHexStringNoPrefix(salt));
  crypto.setKdfparams(kdfParams);
  crypto.setMac(Numeric.toHexStringNoPrefix(mac));
  walletFile.setCrypto(crypto);
  walletFile.setId(UUID.randomUUID().toString());
  walletFile.setVersion(CURRENT_VERSION);
  return walletFile;
}

代码示例来源:origin: web3j/web3j

@Test
public void testGetAddressZeroPadded() {
  byte[] address = Keys.getAddress(
      Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE));
  String expected = Numeric.toHexStringNoPrefix(address);
  String value = "1234";
  assertThat(Keys.getAddress("0x"
          + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value),
      equalTo(expected));
}

代码示例来源:origin: web3j/web3j

@Test
public void testGetAddressSmallPublicKey() {
  byte[] address = Keys.getAddress(
      Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE));
  String expected = Numeric.toHexStringNoPrefix(address);
  assertThat(Keys.getAddress("0x1234"), equalTo(expected));
}

代码示例来源:origin: web3j/web3j

@Test
public void testDecryptScrypt() throws Exception {
  WalletFile walletFile = load(SCRYPT);
  ECKeyPair ecKeyPair = Wallet.decrypt(PASSWORD, walletFile);
  assertThat(Numeric.toHexStringNoPrefix(ecKeyPair.getPrivateKey()), is(SECRET));
}

代码示例来源:origin: web3j/web3j

@Test
public void testDecryptAes128Ctr() throws Exception {
  WalletFile walletFile = load(AES_128_CTR);
  ECKeyPair ecKeyPair = Wallet.decrypt(PASSWORD, walletFile);
  assertThat(Numeric.toHexStringNoPrefix(ecKeyPair.getPrivateKey()), is(SECRET));
}

代码示例来源:origin: org.web3j/abi

static String encodeBool(Bool value) {
  byte[] rawValue = new byte[MAX_BYTE_LENGTH];
  if (value.getValue()) {
    rawValue[rawValue.length - 1] = 1;
  }
  return Numeric.toHexStringNoPrefix(rawValue);
}

代码示例来源:origin: org.web3j/abi

static String encodeBytes(BytesType bytesType) {
  byte[] value = bytesType.getValue();
  int length = value.length;
  int mod = length % MAX_BYTE_LENGTH;
  byte[] dest;
  if (mod != 0) {
    int padding = MAX_BYTE_LENGTH - mod;
    dest = new byte[length + padding];
    System.arraycopy(value, 0, dest, 0, length);
  } else {
    dest = value;
  }
  return Numeric.toHexStringNoPrefix(dest);
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

private static Boolean validateChecksumEthereumAddress(String address) {
    address = address.replace("0x", "");
    String hash = Numeric.toHexStringNoPrefix(Hash.sha3(address.toLowerCase().getBytes()));
    for (int i = 0; i < 40; i++) {
      if (Character.isLetter(address.charAt(i))) {
        // each uppercase letter should correlate with a first bit of 1 in the hash
        // char with the same index, and each lowercase letter with a 0 bit
        int charInt = Integer.parseInt(Character.toString(hash.charAt(i)), 16);
        if ((Character.isUpperCase(address.charAt(i)) && charInt <= 7)
          || (Character.isLowerCase(address.charAt(i)) && charInt > 7)) {
          return false;
        }
      }
    }
    return true;
  }
}

代码示例来源:origin: io.daonomic.scalether/util

private static String toHexStringZeroPadded(BigInteger value, int size, boolean withPrefix) {
  String result = toHexStringNoPrefix(value);
  int length = result.length();
  if (length > size) {
    throw new UnsupportedOperationException(
        "Value " + result + "is larger then length " + size);
  } else if (value.signum() < 0) {
    throw new UnsupportedOperationException("Value cannot be negative");
  }
  if (length < size) {
    result = Strings.zeros(size - length) + result;
  }
  if (withPrefix) {
    return HEX_PREFIX + result;
  } else {
    return result;
  }
}

代码示例来源:origin: org.web3j/abi

static String encodeNumeric(NumericType numericType) {
  byte[] rawValue = toByteArray(numericType);
  byte paddingValue = getPaddingValue(numericType);
  byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH];
  if (paddingValue != 0) {
    for (int i = 0; i < paddedRawValue.length; i++) {
      paddedRawValue[i] = paddingValue;
    }
  }
  System.arraycopy(
      rawValue, 0,
      paddedRawValue, MAX_BYTE_LENGTH - rawValue.length,
      rawValue.length);
  return Numeric.toHexStringNoPrefix(paddedRawValue);
}

代码示例来源:origin: org.web3j/abi

Numeric.toHexStringNoPrefix(
    Numeric.toBytesPadded(
        new BigInteger(Long.toString(offset)), MAX_BYTE_LENGTH

相关文章