Skip to content

Commit

Permalink
feat(grpc): add Ed25519 to AddressType proto (#1492)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipaz authored Sep 2, 2024
1 parent 550d5b5 commit 5752032
Show file tree
Hide file tree
Showing 24 changed files with 1,099 additions and 738 deletions.
12 changes: 10 additions & 2 deletions wallet/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (wm *Manager) SignRawTransaction(
}

func (wm *Manager) GetNewAddress(
walletName, label string,
walletName, label, password string,
addressType crypto.AddressType,
) (*vault.AddressInfo, error) {
wlt, ok := wm.wallets[walletName]
Expand All @@ -168,8 +168,16 @@ func (wm *Manager) GetNewAddress(
addressInfo = info

case crypto.AddressTypeEd25519Account:
return nil, status.Errorf(codes.InvalidArgument, "not supported yet")
if password == "" {
return nil, status.Errorf(codes.InvalidArgument, "password cannot be empty when address type is Ed25519")
}

info, err := wlt.NewEd25519AccountAddress(label, password)
if err != nil {
return nil, err
}

addressInfo = info
case crypto.AddressTypeTreasury:
return nil, status.Errorf(codes.InvalidArgument, "invalid address type")

Expand Down
34 changes: 17 additions & 17 deletions www/grpc/gen/dart/blockchain.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1026,23 +1026,23 @@ class GetConsensusInfoRequest extends $pb.GeneratedMessage {

class GetConsensusInfoResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GetConsensusInfoResponse', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..pc<ConsensusInfo>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'instances', $pb.PbFieldType.PM, subBuilder: ConsensusInfo.create)
..aOM<Proposal>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'proposal', subBuilder: Proposal.create)
..aOM<Proposal>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'proposal', subBuilder: Proposal.create)
..pc<ConsensusInfo>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'instances', $pb.PbFieldType.PM, subBuilder: ConsensusInfo.create)
..hasRequiredFields = false
;

GetConsensusInfoResponse._() : super();
factory GetConsensusInfoResponse({
$core.Iterable<ConsensusInfo>? instances,
Proposal? proposal,
$core.Iterable<ConsensusInfo>? instances,
}) {
final _result = create();
if (instances != null) {
_result.instances.addAll(instances);
}
if (proposal != null) {
_result.proposal = proposal;
}
if (instances != null) {
_result.instances.addAll(instances);
}
return _result;
}
factory GetConsensusInfoResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand All @@ -1067,18 +1067,18 @@ class GetConsensusInfoResponse extends $pb.GeneratedMessage {
static GetConsensusInfoResponse? _defaultInstance;

@$pb.TagNumber(1)
$core.List<ConsensusInfo> get instances => $_getList(0);
Proposal get proposal => $_getN(0);
@$pb.TagNumber(1)
set proposal(Proposal v) { setField(1, v); }
@$pb.TagNumber(1)
$core.bool hasProposal() => $_has(0);
@$pb.TagNumber(1)
void clearProposal() => clearField(1);
@$pb.TagNumber(1)
Proposal ensureProposal() => $_ensure(0);

@$pb.TagNumber(6)
Proposal get proposal => $_getN(1);
@$pb.TagNumber(6)
set proposal(Proposal v) { setField(6, v); }
@$pb.TagNumber(6)
$core.bool hasProposal() => $_has(1);
@$pb.TagNumber(6)
void clearProposal() => clearField(6);
@$pb.TagNumber(6)
Proposal ensureProposal() => $_ensure(1);
@$pb.TagNumber(2)
$core.List<ConsensusInfo> get instances => $_getList(1);
}

class GetTxPoolContentRequest extends $pb.GeneratedMessage {
Expand Down
8 changes: 4 additions & 4 deletions www/grpc/gen/dart/blockchain.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ final $typed_data.Uint8List getConsensusInfoRequestDescriptor = $convert.base64D
const GetConsensusInfoResponse$json = const {
'1': 'GetConsensusInfoResponse',
'2': const [
const {'1': 'instances', '3': 1, '4': 3, '5': 11, '6': '.pactus.ConsensusInfo', '10': 'instances'},
const {'1': 'proposal', '3': 6, '4': 1, '5': 11, '6': '.pactus.Proposal', '10': 'proposal'},
const {'1': 'proposal', '3': 1, '4': 1, '5': 11, '6': '.pactus.Proposal', '10': 'proposal'},
const {'1': 'instances', '3': 2, '4': 3, '5': 11, '6': '.pactus.ConsensusInfo', '10': 'instances'},
],
};

/// Descriptor for `GetConsensusInfoResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getConsensusInfoResponseDescriptor = $convert.base64Decode('ChhHZXRDb25zZW5zdXNJbmZvUmVzcG9uc2USMwoJaW5zdGFuY2VzGAEgAygLMhUucGFjdHVzLkNvbnNlbnN1c0luZm9SCWluc3RhbmNlcxIsCghwcm9wb3NhbBgGIAEoCzIQLnBhY3R1cy5Qcm9wb3NhbFIIcHJvcG9zYWw=');
final $typed_data.Uint8List getConsensusInfoResponseDescriptor = $convert.base64Decode('ChhHZXRDb25zZW5zdXNJbmZvUmVzcG9uc2USLAoIcHJvcG9zYWwYASABKAsyEC5wYWN0dXMuUHJvcG9zYWxSCHByb3Bvc2FsEjMKCWluc3RhbmNlcxgCIAMoCzIVLnBhY3R1cy5Db25zZW5zdXNJbmZvUglpbnN0YW5jZXM=');
@$core.Deprecated('Use getTxPoolContentRequestDescriptor instead')
const GetTxPoolContentRequest$json = const {
'1': 'GetTxPoolContentRequest',
Expand Down Expand Up @@ -394,9 +394,9 @@ const $core.Map<$core.String, $core.Map<$core.String, $core.dynamic>> Blockchain
'.pactus.ValidatorInfo': ValidatorInfo$json,
'.pactus.GetConsensusInfoRequest': GetConsensusInfoRequest$json,
'.pactus.GetConsensusInfoResponse': GetConsensusInfoResponse$json,
'.pactus.Proposal': Proposal$json,
'.pactus.ConsensusInfo': ConsensusInfo$json,
'.pactus.VoteInfo': VoteInfo$json,
'.pactus.Proposal': Proposal$json,
'.pactus.GetAccountRequest': GetAccountRequest$json,
'.pactus.GetAccountResponse': GetAccountResponse$json,
'.pactus.AccountInfo': AccountInfo$json,
Expand Down
14 changes: 14 additions & 0 deletions www/grpc/gen/dart/wallet.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class GetNewAddressRequest extends $pb.GeneratedMessage {
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'walletName')
..e<AddressType>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'addressType', $pb.PbFieldType.OE, defaultOrMaker: AddressType.ADDRESS_TYPE_TREASURY, valueOf: AddressType.valueOf, enumValues: AddressType.values)
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'label')
..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password')
..hasRequiredFields = false
;

Expand All @@ -322,6 +323,7 @@ class GetNewAddressRequest extends $pb.GeneratedMessage {
$core.String? walletName,
AddressType? addressType,
$core.String? label,
$core.String? password,
}) {
final _result = create();
if (walletName != null) {
Expand All @@ -333,6 +335,9 @@ class GetNewAddressRequest extends $pb.GeneratedMessage {
if (label != null) {
_result.label = label;
}
if (password != null) {
_result.password = password;
}
return _result;
}
factory GetNewAddressRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand Down Expand Up @@ -382,6 +387,15 @@ class GetNewAddressRequest extends $pb.GeneratedMessage {
$core.bool hasLabel() => $_has(2);
@$pb.TagNumber(3)
void clearLabel() => clearField(3);

@$pb.TagNumber(4)
$core.String get password => $_getSZ(3);
@$pb.TagNumber(4)
set password($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4)
$core.bool hasPassword() => $_has(3);
@$pb.TagNumber(4)
void clearPassword() => clearField(4);
}

class GetNewAddressResponse extends $pb.GeneratedMessage {
Expand Down
2 changes: 2 additions & 0 deletions www/grpc/gen/dart/wallet.pbenum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class AddressType extends $pb.ProtobufEnum {
static const AddressType ADDRESS_TYPE_TREASURY = AddressType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ADDRESS_TYPE_TREASURY');
static const AddressType ADDRESS_TYPE_VALIDATOR = AddressType._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ADDRESS_TYPE_VALIDATOR');
static const AddressType ADDRESS_TYPE_BLS_ACCOUNT = AddressType._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ADDRESS_TYPE_BLS_ACCOUNT');
static const AddressType ADDRESS_TYPE_ED25519_ACCOUNT = AddressType._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ADDRESS_TYPE_ED25519_ACCOUNT');

static const $core.List<AddressType> values = <AddressType> [
ADDRESS_TYPE_TREASURY,
ADDRESS_TYPE_VALIDATOR,
ADDRESS_TYPE_BLS_ACCOUNT,
ADDRESS_TYPE_ED25519_ACCOUNT,
];

static final $core.Map<$core.int, AddressType> _byValue = $pb.ProtobufEnum.initByValue(values);
Expand Down
6 changes: 4 additions & 2 deletions www/grpc/gen/dart/wallet.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const AddressType$json = const {
const {'1': 'ADDRESS_TYPE_TREASURY', '2': 0},
const {'1': 'ADDRESS_TYPE_VALIDATOR', '2': 1},
const {'1': 'ADDRESS_TYPE_BLS_ACCOUNT', '2': 2},
const {'1': 'ADDRESS_TYPE_ED25519_ACCOUNT', '2': 3},
],
};

/// Descriptor for `AddressType`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List addressTypeDescriptor = $convert.base64Decode('CgtBZGRyZXNzVHlwZRIZChVBRERSRVNTX1RZUEVfVFJFQVNVUlkQABIaChZBRERSRVNTX1RZUEVfVkFMSURBVE9SEAESHAoYQUREUkVTU19UWVBFX0JMU19BQ0NPVU5UEAI=');
final $typed_data.Uint8List addressTypeDescriptor = $convert.base64Decode('CgtBZGRyZXNzVHlwZRIZChVBRERSRVNTX1RZUEVfVFJFQVNVUlkQABIaChZBRERSRVNTX1RZUEVfVkFMSURBVE9SEAESHAoYQUREUkVTU19UWVBFX0JMU19BQ0NPVU5UEAISIAocQUREUkVTU19UWVBFX0VEMjU1MTlfQUNDT1VOVBAD');
@$core.Deprecated('Use addressInfoDescriptor instead')
const AddressInfo$json = const {
'1': 'AddressInfo',
Expand Down Expand Up @@ -75,11 +76,12 @@ const GetNewAddressRequest$json = const {
const {'1': 'wallet_name', '3': 1, '4': 1, '5': 9, '10': 'walletName'},
const {'1': 'address_type', '3': 2, '4': 1, '5': 14, '6': '.pactus.AddressType', '10': 'addressType'},
const {'1': 'label', '3': 3, '4': 1, '5': 9, '10': 'label'},
const {'1': 'password', '3': 4, '4': 1, '5': 9, '10': 'password'},
],
};

/// Descriptor for `GetNewAddressRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNewAddressRequestDescriptor = $convert.base64Decode('ChRHZXROZXdBZGRyZXNzUmVxdWVzdBIfCgt3YWxsZXRfbmFtZRgBIAEoCVIKd2FsbGV0TmFtZRI2CgxhZGRyZXNzX3R5cGUYAiABKA4yEy5wYWN0dXMuQWRkcmVzc1R5cGVSC2FkZHJlc3NUeXBlEhQKBWxhYmVsGAMgASgJUgVsYWJlbA==');
final $typed_data.Uint8List getNewAddressRequestDescriptor = $convert.base64Decode('ChRHZXROZXdBZGRyZXNzUmVxdWVzdBIfCgt3YWxsZXRfbmFtZRgBIAEoCVIKd2FsbGV0TmFtZRI2CgxhZGRyZXNzX3R5cGUYAiABKA4yEy5wYWN0dXMuQWRkcmVzc1R5cGVSC2FkZHJlc3NUeXBlEhQKBWxhYmVsGAMgASgJUgVsYWJlbBIaCghwYXNzd29yZBgEIAEoCVIIcGFzc3dvcmQ=');
@$core.Deprecated('Use getNewAddressResponseDescriptor instead')
const GetNewAddressResponse$json = const {
'1': 'GetNewAddressResponse',
Expand Down
81 changes: 45 additions & 36 deletions www/grpc/gen/docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,41 @@ Message has no fields.
</thead>
<tbody class="table-group-divider">
<tr>
<td class="fw-bold">proposal</td>
<td> Proposal</td>
<td>
The proposal of the consensus info.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.height</td>
<td> uint32</td>
<td>
The height of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.round</td>
<td> int32</td>
<td>
The round of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.block_data</td>
<td> string</td>
<td>
The block data of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.signature_data</td>
<td> string</td>
<td>
The signature data of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">instances</td>
<td>repeated ConsensusInfo</td>
<td>
Expand Down Expand Up @@ -1513,42 +1548,7 @@ committee.
The change-proposer value of the vote.
</td>
</tr>
<tr>
<td class="fw-bold">proposal</td>
<td> Proposal</td>
<td>
The proposal of the consensus info.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.height</td>
<td> uint32</td>
<td>
The height of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.round</td>
<td> int32</td>
<td>
The round of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.block_data</td>
<td> string</td>
<td>
The block data of the proposal.
</td>
</tr>
<tr>
<td class="fw-bold">proposal.signature_data</td>
<td> string</td>
<td>
The signature data of the proposal.
</td>
</tr>
</tbody>
</tbody>
</table>

### GetAccount <span id="pactus.Blockchain.GetAccount" class="rpc-badge"></span>
Expand Down Expand Up @@ -2924,6 +2924,8 @@ public key.</p>
Should not be used to generate new addresses.)</li>
<li>ADDRESS_TYPE_VALIDATOR = 1 (Validator address type.)</li>
<li>ADDRESS_TYPE_BLS_ACCOUNT = 2 (Account address type with BLS signature scheme.)</li>
<li>ADDRESS_TYPE_ED25519_ACCOUNT = 3 (Account address type with Ed25519 signature scheme.
Note: Generating a new Ed25519 address requires the wallet password.)</li>
</ul>
</td>
</tr>
Expand All @@ -2934,6 +2936,13 @@ Should not be used to generate new addresses.)</li>
A label for the new address.
</td>
</tr>
<tr>
<td class="fw-bold">password</td>
<td> string</td>
<td>
Password for the new address. It's required when address_type is ADDRESS_TYPE_ED25519_ACCOUNT.
</td>
</tr>
</tbody>
</table>
<h4>GetNewAddressResponse <span class="badge text-bg-warning fs-6 align-top">Response</span></h4>
Expand Down
Loading

0 comments on commit 5752032

Please sign in to comment.