# xrpl4j-keypairs [![javadoc](https://javadoc.io/badge2/org.xrpl/xrpl4j-keypairs/javadoc.svg?color=blue)](https://javadoc.io/doc/org.xrpl/xrpl4j-keypairs)
Library for generating secure random seeds, deriving public/private keypairs, and signing messages and verifying signatures. This library supports both [ECDSA
using the secp256k1 elliptic curve and EdDSA using the Ed25519 elliptic curve](https://xrpl.org/cryptographic-keys.html#signing-algorithms).
## Installation
Use this module in your project by adding the following to your `pom.xml`:
```
<dependency>
<groupId>org.xrpl</groupId>
<artifactId>xrpl4j-keypairs</artifactId>
<version>1.0.0</version>
</dependency>
```
## Usage
The [`DefaultWalletFactory`](./src/main/java/org/xrpl/xrpl4j/wallet/DefaultWalletFactory.java) class can be used to generate a random wallet,
or to restore a wallet from a seed or a key pair. `DefaultWalletFactory` uses a
[`DefaultKeyPairService`](./src/main/java/org/xrpl/xrpl4j/keypairs/DefaultKeyPairService.java), which can also be used on its own, to
generate seeds and derive keypairs and addresses.
### DefaultWalletFactory
The `DefaultWalletFactory` can generate new wallets and restore existing wallets.
The following code generates a new testnet wallet with an ED25519 public/private keypair:
```java
WalletFactory walletFactory = DefaultWalletFactory.getInstance();
SeedWalletGenerationResult seedWalletGenerationResult = walletFactory.randomWallet(true);
System.out.println("Generation result: " + seedWalletGenerationResult);
```
Which produces the following output:
```
Generation result: SeedWalletGenerationResult{
seed=sEdSbPbSNZHqH1r1d27Sp3mh8Rq3oyu,
wallet=Wallet{
privateKey=ED9000C29279778F95F807B3F3320E4F8DC9B08067E4F3A4CBE587F88CDB20AEBE,
publicKey=ED26F7054744A45706A6D138A32429111DCB090C0CBECE3853A59693657F7AB63A,
classicAddress=rKdYoCQbvNz12ELDVmiJcWUADZ1Lg2o9w1,
xAddress=TVR8ETfqXp1isjemD7wQCHguktJWAn8HhqpwCVThmUSVPPk,
isTest=true
}
}
```
Alternatively, you can restore a wallet from a seed:
```java
WalletFactory walletFactory = DefaultWalletFactory.getInstance();
Wallet wallet = walletFactory.fromSeed("sEdSbPbSNZHqH1r1d27Sp3mh8Rq3oyu", true);
System.out.println("Wallet: " + wallet);
```
or from a `KeyPair`:
```java
WalletFactory walletFactory = DefaultWalletFactory.getInstance();
Wallet wallet = walletFactory.fromKeyPair(KeyPair.builder()
.privateKey("ED9000C29279778F95F807B3F3320E4F8DC9B08067E4F3A4CBE587F88CDB20AEBE")
.publicKey("ED26F7054744A45706A6D138A32429111DCB090C0CBECE3853A59693657F7AB63A")
.build(),
true);
System.out.println("Wallet: " + wallet);
```
which both produce the following output:
```
Wallet: Wallet{
privateKey=ED9000C29279778F95F807B3F3320E4F8DC9B08067E4F3A4CBE587F88CDB20AEBE,
publicKey=ED26F7054744A45706A6D138A32429111DCB090C0CBECE3853A59693657F7AB63A,
classicAddress=rKdYoCQbvNz12ELDVmiJcWUADZ1Lg2o9w1,
xAddress=TVR8ETfqXp1isjemD7wQCHguktJWAn8HhqpwCVThmUSVPPk,
isTest=true
}
```
For full API documentation, check out the [`DefaultWalletFactory` Javadoc](https://www.javadoc.io/doc/org.xrpl/xrpl4j-keypairs/latest/org/xrpl/xrpl4j/wallet/DefaultWalletFactory.html).
### DefaultKeyPairService
`DefaultWalletFactory` uses an instance of `DefaultKeyPairService`, which is responsible for generating seeds, deriving `KeyPair`s from seeds, signing messages, and verifying message signatures.
The following code generates a seed, derives a `KeyPair` from the seed, signs a message with that `KeyPair`, and finally verifies the signature:
```java
KeyPairService keyPairService = DefaultKeyPairService.getInstance();
String seed = keyPairService.generateSeed();
System.out.println("Generated seed: " + seed);
KeyPair keyPair = keyPairService.deriveKeyPair(seed);
System.out.println("Derived KeyPair: " + keyPair);
String message = BaseEncoding.base16().encode("test message".getBytes());
String signature = keyPairService.sign(message, keyPair.privateKey());
System.out.println("Message signature: " + signature);
boolean verifies = keyPairService.verify(message, signature, keyPair.publicKey());
System.out.println("Signature verified? : " + verifies);
```
which produces the following output:
```
Generated seed: sEd7Ld6RUVbX9cZEG3jx221tCkq3ZaP
Derived KeyPair: KeyPair{
privateKey=ED2AAB0754AEB0638D8B87777031F8A524C41A1492AF910BEEF2FBFDF08E2C9168,
publicKey=ED0924FE18B96F63BD9C1EF74BC2DA8093840A4F1A272BD13FDBF6E3399AF24448
}
Message signature: 6687EF589B2571938F42043A3617B09AEA92E5C2420C307E670145E9620149D8798224DF1AEB3E2B90CD30D2AD097530F8E32AF7324F2A0B573090C913189C00
Signature verified? : true
```
没有合适的资源?快使用搜索试试~ 我知道了~
xrpl4j:纯Java XRP工具包
共322个文件
java:295个
xml:9个
md:8个
需积分: 10 1 下载量 97 浏览量
2021-02-11
06:15:32
上传
评论
收藏 471KB ZIP 举报
温馨提示
xrpl4j 与XRP分类帐交互所必需的核心功能的纯Java实现。 尽管该库不提供网络客户端,但它确实支持XRPL序列化和事务签名的艰巨任务,并为XRP Ledger对象和波纹的请求/响应对象提供了有用的Java绑定。 项目结构 Xrpl4j被构造为一个Maven多模块项目,具有以下模块: xrpl4j-binary-codec : 将XRPL事务的JSON表示序列化为XRP分类帐的规范二进制格式 xrpl4j-address-codec : 将种子,地址和公共密钥从其字节表示形式转换为XRPL Base58Check编码格式,反之亦然 处理X地址编码和解码 xrpl4j-keypairs : 生成种子并派生XRPL密钥对,可用于签署交易和验证交易签名 同时支持secp256k1和ed25519密钥类型和签名算法 xrpl4j-model : 提供为XRP Ledger对
资源详情
资源评论
资源推荐
收起资源包目录
xrpl4j:纯Java XRP工具包 (322个子文件)
rippled.cfg 42KB
CODEOWNERS 33B
.gitignore 4KB
Flags.java 37KB
XrplClient.java 22KB
BinarySerializationTests.java 22KB
EscrowIT.java 21KB
PaymentChannelIT.java 17KB
IssuedCurrencyIT.java 16KB
AddressCodec.java 13KB
OfferIT.java 13KB
SignerListSetIT.java 12KB
CheckIT.java 12KB
XAddressTest.java 11KB
EscrowFinishTest.java 10KB
ServerInfo.java 10KB
AccountSet.java 9KB
AbstractIT.java 9KB
Transaction.java 8KB
PayChannelObject.java 8KB
DepositPreAuthIT.java 8KB
AccountTransactionsResultJsonTests.java 8KB
XrplBinaryCodecTest.java 8KB
ServerInfoResultJsonTests.java 7KB
AccountObjectsResultJsonTests.java 7KB
SubmitMultisignedResultJsonTests.java 7KB
AccountSetIT.java 7KB
DefinitionsService.java 7KB
AmountType.java 7KB
EscrowObject.java 7KB
LedgerHeaderJsonTests.java 7KB
BinaryParser.java 7KB
XrplBinaryCodec.java 7KB
AddressBase58.java 6KB
AccountChannelsResultJsonTests.java 6KB
UnsignedByteArray.java 6KB
AccountRootObject.java 6KB
RippleStateObject.java 6KB
SerializedType.java 6KB
SetRegularKeyIT.java 6KB
Secp256k1KeyPairService.java 6KB
JsonRpcClient.java 6KB
EscrowJsonTests.java 5KB
Base58.java 5KB
FluentCompareTo.java 5KB
CheckObject.java 5KB
CheckJsonTests.java 5KB
SubmitResultJsonTests.java 5KB
AddressCodecTest.java 5KB
Wrappers.java 5KB
PaymentFlagsJsonTests.java 5KB
PaymentChannelJsonTests.java 5KB
FieldHeaderCodec.java 5KB
PaymentChannelResultObject.java 5KB
SubmitResult.java 5KB
LedgerHeader.java 5KB
EcDsaSignature.java 5KB
RippledContainer.java 5KB
AccountSetTests.java 5KB
ByteUtils.java 5KB
STObjectType.java 5KB
AccountInfoResultJsonTests.java 5KB
EscrowFinish.java 5KB
RipplePathFindResultJsonTests.java 5KB
SubmitMultisignedRequestParamsJsonTests.java 5KB
TrustLine.java 4KB
AccountObjectsRequestParams.java 4KB
SubmitPaymentIT.java 4KB
PaymentChannelClaim.java 4KB
LedgerRequestParams.java 4KB
OfferObject.java 4KB
PaymentChannelTests.java 4KB
UnsignedByte.java 4KB
Payment.java 4KB
DefaultKeyPairServiceTest.java 4KB
TransactionResultJsonTests.java 4KB
EscrowCreate.java 4KB
CurrencyType.java 4KB
Ed25519KeyPairService.java 4KB
AmountTypeTest.java 4KB
PaymentChannelCreate.java 4KB
AccountRootFlagsTests.java 4KB
SignerListSetJsonTests.java 4KB
AccountTransactionsIT.java 4KB
DepositPreAuthObject.java 4KB
AccountTransactionsRequestParams.java 3KB
CheckCash.java 3KB
KeyPairService.java 3KB
SignerListObject.java 3KB
RipplePathFindRequestParams.java 3KB
BinarySerializer.java 3KB
AccountInfoRequestParams.java 3KB
LedgerResultJsonTests.java 3KB
FeeResult.java 3KB
AccountLinesResultJsonTests.java 3KB
AccountObjectsResult.java 3KB
SignerListObjectJsonTests.java 3KB
TrustSetFlagsTests.java 3KB
RippleStateFlagsTests.java 3KB
CheckCreate.java 3KB
共 322 条
- 1
- 2
- 3
- 4
吴玄熙
- 粉丝: 21
- 资源: 4583
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0