Skip to content

Commit

Permalink
fix: Change UpdatePassword to take multiple addresses, roll back on e…
Browse files Browse the repository at this point in the history
…rror (#175)

BREAKING CHANGE: Change `UpdatePassword` to take an array of addresses,
roll back on error.

Explanation: Currently, `UpdatePassword` takes a single address of the
account to update the password. If a native application wants to change
multiple accounts to the new password, it does a loop to call
`UpdatePassword` multiple times. But if one of the calls has an error,
the application breaks out of the loop and leaves the Keybase in an
inconsistent state where some passwords are changed but not all. The
application could write some logic to roll back these changes, but it is
better for the Gno Native Kit service to handle this.

This PR has two commits:

1. Change the `UpdatePassword` request to take a required array of
account addresses. (If the application only wants to update the password
of one account, it is easy to make an array of one address.) In api.go,
we also change `UpdatePassword` to roll back to the old password in case
of error.
2. In types.ts and GnoNativeApi.ts, change `updatePassword` to take a
required array of Uint8Array for the addresses.

---------

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 authored Sep 17, 2024
1 parent beadf11 commit 7534c7d
Show file tree
Hide file tree
Showing 14 changed files with 770 additions and 464 deletions.
452 changes: 315 additions & 137 deletions api/gen/csharp/Gnonativetypes.cs

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions api/gen/csharp/RpcGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,9 @@ public abstract partial class GnoNativeServiceBase
}

/// <summary>
/// Update the keybase to use the new password for the account in the keybase with the given address.
/// Before calling this, you must call SetPassword with the current password.
/// Update the keybase to use the new password for the accounts in the keybase with the given addresses.
/// Before calling this, you must call SetPassword with the current password for each account.
/// If there is an error, then roll back all accounts to the current password.
/// If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
/// </summary>
/// <param name="request">The request received from the client.</param>
Expand Down Expand Up @@ -1889,8 +1890,9 @@ protected GnoNativeServiceClient(ClientBaseConfiguration configuration) : base(c
return CallInvoker.AsyncUnaryCall(__Method_SetPassword, null, options, request);
}
/// <summary>
/// Update the keybase to use the new password for the account in the keybase with the given address.
/// Before calling this, you must call SetPassword with the current password.
/// Update the keybase to use the new password for the accounts in the keybase with the given addresses.
/// Before calling this, you must call SetPassword with the current password for each account.
/// If there is an error, then roll back all accounts to the current password.
/// If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
/// </summary>
/// <param name="request">The request to send to the server.</param>
Expand All @@ -1904,8 +1906,9 @@ protected GnoNativeServiceClient(ClientBaseConfiguration configuration) : base(c
return UpdatePassword(request, new grpc::CallOptions(headers, deadline, cancellationToken));
}
/// <summary>
/// Update the keybase to use the new password for the account in the keybase with the given address.
/// Before calling this, you must call SetPassword with the current password.
/// Update the keybase to use the new password for the accounts in the keybase with the given addresses.
/// Before calling this, you must call SetPassword with the current password for each account.
/// If there is an error, then roll back all accounts to the current password.
/// If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
/// </summary>
/// <param name="request">The request to send to the server.</param>
Expand All @@ -1917,8 +1920,9 @@ protected GnoNativeServiceClient(ClientBaseConfiguration configuration) : base(c
return CallInvoker.BlockingUnaryCall(__Method_UpdatePassword, null, options, request);
}
/// <summary>
/// Update the keybase to use the new password for the account in the keybase with the given address.
/// Before calling this, you must call SetPassword with the current password.
/// Update the keybase to use the new password for the accounts in the keybase with the given addresses.
/// Before calling this, you must call SetPassword with the current password for each account.
/// If there is an error, then roll back all accounts to the current password.
/// If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
/// </summary>
/// <param name="request">The request to send to the server.</param>
Expand All @@ -1932,8 +1936,9 @@ protected GnoNativeServiceClient(ClientBaseConfiguration configuration) : base(c
return UpdatePasswordAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken));
}
/// <summary>
/// Update the keybase to use the new password for the account in the keybase with the given address.
/// Before calling this, you must call SetPassword with the current password.
/// Update the keybase to use the new password for the accounts in the keybase with the given addresses.
/// Before calling this, you must call SetPassword with the current password for each account.
/// If there is an error, then roll back all accounts to the current password.
/// If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
/// </summary>
/// <param name="request">The request to send to the server.</param>
Expand Down
30 changes: 27 additions & 3 deletions api/gen/es/gnonativetypes_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ export declare class UpdatePasswordRequest extends Message<UpdatePasswordRequest
newPassword: string;

/**
* The address of the account to update the password
* The addresses of the account to update the password
*
* @generated from field: bytes address = 2;
* @generated from field: repeated bytes addresses = 2;
*/
address: Uint8Array;
addresses: Uint8Array[];

constructor(data?: PartialMessage<UpdatePasswordRequest>);

Expand Down Expand Up @@ -2055,3 +2055,27 @@ export declare class HelloStreamResponse extends Message<HelloStreamResponse> {
static equals(a: HelloStreamResponse | PlainMessage<HelloStreamResponse> | undefined, b: HelloStreamResponse | PlainMessage<HelloStreamResponse> | undefined): boolean;
}

/**
* @generated from message land.gno.gnonative.v1.GNONATIVETYPES_BytesList
*/
export declare class GNONATIVETYPES_BytesList extends Message<GNONATIVETYPES_BytesList> {
/**
* @generated from field: repeated bytes Value = 1;
*/
Value: Uint8Array[];

constructor(data?: PartialMessage<GNONATIVETYPES_BytesList>);

static readonly runtime: typeof proto3;
static readonly typeName = "land.gno.gnonative.v1.GNONATIVETYPES_BytesList";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GNONATIVETYPES_BytesList;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): GNONATIVETYPES_BytesList;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): GNONATIVETYPES_BytesList;

static equals(a: GNONATIVETYPES_BytesList | PlainMessage<GNONATIVETYPES_BytesList> | undefined, b: GNONATIVETYPES_BytesList | PlainMessage<GNONATIVETYPES_BytesList> | undefined): boolean;
}

12 changes: 11 additions & 1 deletion api/gen/es/gnonativetypes_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const UpdatePasswordRequest = proto3.makeMessageType(
"land.gno.gnonative.v1.UpdatePasswordRequest",
() => [
{ no: 1, name: "new_password", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "address", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
{ no: 2, name: "addresses", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true },
],
);

Expand Down Expand Up @@ -782,3 +782,13 @@ export const HelloStreamResponse = proto3.makeMessageType(
],
);

/**
* @generated from message land.gno.gnonative.v1.GNONATIVETYPES_BytesList
*/
export const GNONATIVETYPES_BytesList = proto3.makeMessageType(
"land.gno.gnonative.v1.GNONATIVETYPES_BytesList",
() => [
{ no: 1, name: "Value", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true },
],
);

5 changes: 3 additions & 2 deletions api/gen/es/rpc_connect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ export declare const GnoNativeService: {
readonly kind: MethodKind.Unary,
},
/**
* Update the keybase to use the new password for the account in the keybase with the given address.
* Before calling this, you must call SetPassword with the current password.
* Update the keybase to use the new password for the accounts in the keybase with the given addresses.
* Before calling this, you must call SetPassword with the current password for each account.
* If there is an error, then roll back all accounts to the current password.
* If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
*
* @generated from rpc land.gno.gnonative.v1.GnoNativeService.UpdatePassword
Expand Down
5 changes: 3 additions & 2 deletions api/gen/es/rpc_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ export const GnoNativeService = {
kind: MethodKind.Unary,
},
/**
* Update the keybase to use the new password for the account in the keybase with the given address.
* Before calling this, you must call SetPassword with the current password.
* Update the keybase to use the new password for the accounts in the keybase with the given addresses.
* Before calling this, you must call SetPassword with the current password for each account.
* If there is an error, then roll back all accounts to the current password.
* If there is no activated account with the given address, return [ErrCode](#land.gno.gnonative.v1.ErrCode).ErrNoActiveAccount.
*
* @generated from rpc land.gno.gnonative.v1.GnoNativeService.UpdatePassword
Expand Down
10 changes: 6 additions & 4 deletions api/gen/go/_goconnect/rpc.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7534c7d

Please sign in to comment.