Skip to content

Commit

Permalink
Add Base58 implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpota authored Feb 28, 2023
1 parent 7512738 commit 89a77a4
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build & Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Build
run: mvn package
- name: Test
run: mvn test
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish to Maven Central

on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: build artifact
run: mvn clean package
- name: Publish to the Maven Central Repository
run: mvn --no-transfer-progress --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SECRET_KEY_PASSWORD }}
18 changes: 8 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
out/*

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
build
*.iml
.gradle
/local.properties
/.idea
123 changes: 123 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sol4k</groupId>
<artifactId>utilities</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>utilities</name>
<description>sol4k utilities library</description>
<url>https://github.com/sol4k/utilities</url>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>

<developers>
<developer>
<name>Sasha Shpota</name>
<email>[email protected]</email>
<organization>sol4k</organization>
<organizationUrl>https://github.com/sol4k</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/sol4k/utilities.git</connection>
<developerConnection>scm:git:ssh://github.com:sol4k/utilities.git</developerConnection>
<url>https://github.com/sol4k/utilities/tree/main</url>
</scm>


<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-source</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<distributionManagement>
<repository>
<id>ossrh</id>
<name>Central Repository OSSRH</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>
118 changes: 118 additions & 0 deletions src/main/java/org/sol4k/utilities/AddressFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2011 Google Inc.
* Copyright 2015 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.sol4k.utilities;


@SuppressWarnings("serial")
public class AddressFormatException extends IllegalArgumentException {
public AddressFormatException() {
super();
}

public AddressFormatException(String message) {
super(message);
}

/**
* This exception is thrown by {@link Base58} when you try to decode data and a character isn't valid.
* You shouldn't allow the user to proceed in this case.
*/
public static class InvalidCharacter extends AddressFormatException {
public final char character;
public final int position;

public InvalidCharacter(char character, int position) {
super("Invalid character '" + Character.toString(character) + "' at position " + position);
this.character = character;
this.position = position;
}
}

/**
* This exception is thrown by {@link Base58} when you try to decode data and the data isn't of the right size.
* You shouldn't allow the user to proceed in this case.
*/
public static class InvalidDataLength extends AddressFormatException {
public InvalidDataLength() {
super();
}

public InvalidDataLength(String message) {
super(message);
}
}

/**
* This exception is thrown by {@link Base58} when you try to decode data and the checksum isn't valid.
* You shouldn't allow the user to proceed in this case.
*/
public static class InvalidChecksum extends AddressFormatException {
public InvalidChecksum() {
super("Checksum does not validate");
}

public InvalidChecksum(String message) {
super(message);
}
}

/**
* This exception is thrown by {@code SegwitAddress} when you try to decode data and the witness version doesn't
* match the Bech32 encoding as per BIP350. You shouldn't allow the user to proceed in this case.
*/
public static class UnexpectedWitnessVersion extends AddressFormatException {
public UnexpectedWitnessVersion() {
super("Unexpected witness version");
}

public UnexpectedWitnessVersion(String message) {
super(message);
}
}

/**
* This exception is thrown by the {@code EncodedPrivateKey} hierarchy of classes when you try and decode an
* address or private key with an invalid prefix (version header or human-readable part). You shouldn't allow the
* user to proceed in this case.
*/
public static class InvalidPrefix extends AddressFormatException {
public InvalidPrefix() {
super();
}

public InvalidPrefix(String message) {
super(message);
}
}

/**
* This exception is thrown by the {@code EncodedPrivateKey} hierarchy of classes when you try and decode an
* address with a prefix (version header or human-readable part) that used by another network (usually: mainnet vs
* testnet). You shouldn't allow the user to proceed in this case as they are trying to send money across different
* chains, an operation that is guaranteed to destroy the money.
*/
public static class WrongNetwork extends InvalidPrefix {
public WrongNetwork(int versionHeader) {
super("Version code of address did not match acceptable versions for network: " + versionHeader);
}

public WrongNetwork(String hrp) {
super("Human readable part of address did not match acceptable HRPs for network: " + hrp);
}
}
}
Loading

0 comments on commit 89a77a4

Please sign in to comment.