[#1] add client environment
add client cut code cleanup Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
dc0eef770c
commit
b0db7df192
95 changed files with 1202 additions and 560 deletions
|
@ -19,11 +19,6 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
|
@ -34,11 +29,6 @@
|
|||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -18,19 +18,23 @@ public class Helper {
|
|||
return hash;
|
||||
}
|
||||
|
||||
public static byte[] getSha256(byte[] value) {
|
||||
public static MessageDigest getSha256Instance() {
|
||||
try {
|
||||
return MessageDigest.getInstance("SHA-256").digest(value);
|
||||
return MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getSha256(byte[] value) {
|
||||
return getSha256Instance().digest(value);
|
||||
}
|
||||
|
||||
public static ByteString getSha256(AbstractMessage value) {
|
||||
return ByteString.copyFrom(getSha256(value.toByteArray()));
|
||||
}
|
||||
|
||||
public static String пуеHexString(byte[] array) {
|
||||
public static String getHexString(byte[] array) {
|
||||
return String.format("%0" + (array.length << 1) + "x", new BigInteger(1, array));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@ public class KeyExtension {
|
|||
|
||||
public static byte[] loadPublicKey(byte[] privateKey) {
|
||||
X9ECParameters params = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
params.getCurve(), params.getG(), params.getN(), params.getH()
|
||||
);
|
||||
ECPoint q = domain.getG().multiply(new BigInteger(1, privateKey));
|
||||
ECPublicKeyParameters publicParams = new ECPublicKeyParameters(q, domain);
|
||||
return publicParams.getQ().getEncoded(true);
|
||||
|
@ -65,7 +67,9 @@ public class KeyExtension {
|
|||
|
||||
public static PrivateKey loadPrivateKey(byte[] privateKey) {
|
||||
X9ECParameters params = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
params.getCurve(), params.getG(), params.getN(), params.getH()
|
||||
);
|
||||
ECPrivateKeyParameters ecParams = new ECPrivateKeyParameters(fromUnsignedByteArray(privateKey), domain);
|
||||
|
||||
ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(
|
||||
|
@ -80,7 +84,7 @@ public class KeyExtension {
|
|||
}
|
||||
}
|
||||
|
||||
public static PublicKey getPublicKeyByPublic(byte[] publicKey) {
|
||||
public static PublicKey getPublicKeyFromBytes(byte[] publicKey) {
|
||||
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Decompress argument isn't compressed public key. Expected length=%s, actual=%s",
|
||||
|
@ -89,14 +93,17 @@ public class KeyExtension {
|
|||
}
|
||||
|
||||
X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH()
|
||||
);
|
||||
var ecPoint = secp256R1.getCurve().decodePoint(publicKey);
|
||||
var publicParams = new ECPublicKeyParameters(ecPoint, domain);
|
||||
java.security.spec.ECPoint point = new java.security.spec.ECPoint(
|
||||
publicParams.getQ().getRawXCoord().toBigInteger(), publicParams.getQ().getRawYCoord().toBigInteger()
|
||||
);
|
||||
ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(
|
||||
"secp256r1", secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH(), secp256R1.getSeed()
|
||||
"secp256r1", secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(),
|
||||
secp256R1.getH(), secp256R1.getSeed()
|
||||
);
|
||||
ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(point, ecParameterSpec);
|
||||
|
||||
|
@ -108,7 +115,6 @@ public class KeyExtension {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static byte[] getScriptHash(byte[] publicKey) {
|
||||
var script = createSignatureRedeemScript(publicKey);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue