本文整理了Java中net.consensys.cava.bytes.Bytes.wrap()
方法的一些代码示例,展示了Bytes.wrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.wrap()
方法的具体详情如下:
包路径:net.consensys.cava.bytes.Bytes
类名称:Bytes
方法名:wrap
[英]Wrap the provided byte array as a Bytes value.
Note that value is not copied and thus any future update to value will be reflected in the returned value.
[中]将提供的字节数组包装为字节值。
请注意,不会复制值,因此将来对值的任何更新都将反映在返回的值中。
代码示例来源:origin: net.consensys.cava/cava-bytes
/**
* Wrap the provided byte array as a {@link Bytes} value.
*
* <p>
* Note that value is not copied and thus any future update to {@code value} will be reflected in the returned value.
*
* @param value The value to wrap.
* @return A {@link Bytes} value wrapping {@code value}.
*/
static Bytes wrap(byte[] value) {
return wrap(value, 0, value.length);
}
代码示例来源:origin: net.consensys.cava/cava-bytes
/**
* Create a value that contains the specified bytes in their specified order.
*
* @param bytes The bytes that must compose the returned value.
* @return A value containing the specified bytes.
*/
static Bytes of(byte... bytes) {
return wrap(bytes);
}
代码示例来源:origin: net.consensys.cava/cava-bytes
/**
* Generate random bytes.
*
* @param size The number of bytes to generate.
* @param generator The generator for random bytes.
* @return A value containing the desired number of random bytes.
*/
static Bytes random(int size, Random generator) {
byte[] array = new byte[size];
generator.nextBytes(array);
return Bytes.wrap(array);
}
代码示例来源:origin: net.consensys.cava/cava-ssz
Bytes toBytes() {
if (values.isEmpty()) {
return Bytes.EMPTY;
}
return Bytes.wrap(values.toArray(new Bytes[0]));
}
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode a list of {@link UInt256}.
*
* @param elements The integers to write.
* @return SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeUInt256List(UInt256... elements) {
ArrayList<Bytes> encoded = new ArrayList<>(elements.length + 1);
encodeUInt256ListTo(elements, b -> encoded.add(Bytes.wrap(b)));
return Bytes.wrap(encoded.toArray(new Bytes[0]));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode a list of hashes.
*
* @param elements The hashes to write.
* @return SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeHashList(Bytes... elements) {
ArrayList<Bytes> encoded = new ArrayList<>(elements.length + 1);
encodeHashListTo(elements, b -> encoded.add(Bytes.wrap(b)));
return Bytes.wrap(encoded.toArray(new Bytes[0]));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode a list of booleans.
*
* @param elements The booleans to write.
* @return SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeBooleanList(boolean... elements) {
ArrayList<Bytes> encoded = new ArrayList<>(elements.length + 1);
encodeBooleanListTo(elements, b -> encoded.add(Bytes.wrap(b)));
return Bytes.wrap(encoded.toArray(new Bytes[0]));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode a list of strings.
*
* @param elements The strings to write.
* @return SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeStringList(String... elements) {
ArrayList<Bytes> encoded = new ArrayList<>(elements.length * 2 + 1);
encodeStringListTo(elements, b -> encoded.add(Bytes.wrap(b)));
return Bytes.wrap(encoded.toArray(new Bytes[0]));
}
代码示例来源:origin: net.consensys.cava/cava-rlp
/**
* Encode a long to a {@link Bytes} value.
*
* @param value The long to encode.
* @return The RLP encoding in a {@link Bytes} value.
*/
public static Bytes encodeLong(long value) {
return Bytes.wrap(encodeNumber(value));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode a value to a {@link Bytes} value.
*
* @param value The value to encode.
* @return The SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeByteArray(byte[] value) {
return encodeBytes(Bytes.wrap(value));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Append an already SSZ encoded value.
*
* Note that this method <b>may not</b> validate that {@code value} is a valid SSZ sequence. Appending an invalid SSZ
* sequence will cause the entire SSZ encoding produced by this writer to also be invalid.
*
* @param value The SSZ encoded bytes to append.
*/
default void writeSSZ(byte[] value) {
writeSSZ(Bytes.wrap(value));
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode an unsigned long integer to a {@link Bytes} value.
*
* @param value The long to encode.
* @param bitLength The bit length of the integer value (must be a multiple of 8).
* @return The SSZ encoding in a {@link Bytes} value.
* @throws IllegalArgumentException If the value is too large for the specified {@code bitLength}.
*/
public static Bytes encodeULong(long value, int bitLength) {
return Bytes.wrap(encodeULongToByteArray(value, bitLength));
}
代码示例来源:origin: net.consensys.cava/cava-rlp
private static Bytes encodeValue(byte[] value) {
int maxSize = value.length + 5;
ByteBuffer buffer = ByteBuffer.allocate(maxSize);
encodeByteArray(value, buffer::put);
return Bytes.wrap(buffer.array(), 0, buffer.position());
}
代码示例来源:origin: net.consensys.cava/cava-rlp
Bytes toBytes() {
Deque<byte[]> values = delegate.values();
if (values.isEmpty()) {
return Bytes.EMPTY;
}
return Bytes.wrap(values.stream().map(Bytes::wrap).toArray(Bytes[]::new));
}
}
代码示例来源:origin: net.consensys.cava/cava-ssz
static void encodeUInt256ListTo(UInt256[] elements, Consumer<Bytes> appender) {
appender.accept(Bytes.wrap(listLengthPrefix(elements.length, 256 / 8)));
for (UInt256 value : elements) {
appender.accept(encodeUInt256(value));
}
}
代码示例来源:origin: net.consensys.cava/cava-ssz
static void encodeAddressListTo(Bytes[] elements, Consumer<Bytes> appender) {
appender.accept(Bytes.wrap(listLengthPrefix(elements.length, 20)));
for (Bytes bytes : elements) {
appender.accept(encodeAddress(bytes));
}
}
代码示例来源:origin: net.consensys.cava/cava-net
/**
* Calculate the fingerprint for a PEM-encoded certificate.
*
* @param certificate The path to a PEM-encoded certificate.
* @return The fingerprint hex-string for the certificate.
* @throws IOException If an IO error occurs.
*/
public static String certificateHexFingerprint(Path certificate) throws IOException {
return Bytes.wrap(certificateFingerprint(certificate)).toHexString().substring(2).toLowerCase();
}
代码示例来源:origin: net.consensys.cava/cava-ssz
/**
* Encode {@link Bytes}.
*
* @param value The value to encode.
* @return The SSZ encoding in a {@link Bytes} value.
*/
public static Bytes encodeBytes(Bytes value) {
Bytes lengthBytes = encodeLong(value.size(), 32);
return Bytes.wrap(lengthBytes, value);
}
代码示例来源:origin: net.consensys.cava/cava-devp2p
PacketHeader(KeyPair keyPair, byte packetType, Bytes payload) {
checkArgument(keyPair != null, "keyPair cannot be null");
checkArgument(payload != null, "payload cannot be null");
Bytes typeBytes = Bytes.of(packetType);
this.packetType = packetType;
this.signature = SECP256K1.sign(Bytes.wrap(typeBytes, payload), keyPair);
this.hash = Hash.sha3_256(Bytes.wrap(signature.bytes(), typeBytes, payload));
this.publicKey = keyPair.publicKey();
}
代码示例来源:origin: net.consensys.cava/cava-eth
@Nullable
private Address verifySignatureAndGetSender() {
Bytes data = signatureData(nonce, gasPrice, gasLimit, to, value, payload);
SECP256K1.PublicKey publicKey = SECP256K1.PublicKey.recoverFromSignature(data, signature);
if (publicKey == null) {
validSignature = false;
} else {
sender = Address.fromBytes(Bytes.wrap(keccak256(publicKey.bytesArray()), 12, 20));
validSignature = true;
}
return sender;
}
内容来源于网络,如有侵权,请联系作者删除!