Skip to content

Commit

Permalink
Update albatross client, add support for reactivation in update-staker
Browse files Browse the repository at this point in the history
This reverts commit a46dc56.
  • Loading branch information
sisou committed Nov 21, 2023
1 parent ac5a571 commit 557c889
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion client/HubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class HubApi<
public signStaking<B extends BehaviorType = DB>(
request: Promise<SignStakingRequest> | SignStakingRequest,
requestBehavior: RequestBehavior<B> = this._defaultBehavior as any,
): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction[]> {
): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction> {
return this._request(requestBehavior, RequestType.SIGN_STAKING, [request]);
}

Expand Down
10 changes: 8 additions & 2 deletions client/PublicRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ export interface SignTransactionRequest extends BasicRequest {

export interface SignStakingRequest extends SignTransactionRequest {
type: number;

// For createStaker and updateStaker transactions
delegation?: string;

// For updateStaker transactions
reactivateAllStake?: boolean;

// For inactivateStake transactions
newInactiveBalance?: number;
}

Expand Down Expand Up @@ -641,7 +648,6 @@ export type RpcRequest = SignTransactionRequest
| RefundSwapRequest;

export type RpcResult = SignedTransaction
| SignedTransaction[]
| Account
| Account[]
| SimpleResult
Expand All @@ -663,7 +669,7 @@ export type ResultByRequestType<T> =
T extends RequestType.LIST_CASHLINKS ? Cashlink[] :
T extends RequestType.CHOOSE_ADDRESS | RequestType.ADD_ADDRESS ? Address :
T extends RequestType.SIGN_TRANSACTION ? SignedTransaction :
T extends RequestType.SIGN_STAKING ? SignedTransaction[] :
T extends RequestType.SIGN_STAKING ? SignedTransaction :
T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult :
T extends RequestType.SIGN_MESSAGE ? SignedMessage :
T extends RequestType.LOGOUT | RequestType.CHANGE_PASSWORD ? SimpleResult :
Expand Down
2 changes: 1 addition & 1 deletion client/dist/src/HubApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class HubApi<DB extends BehaviorType = BehaviorType.POPUP, IB ext
} ? SimpleResult | SignedTransaction : SignedTransaction>;
chooseAddress<B extends BehaviorType = DB>(request: Promise<ChooseAddressRequest> | ChooseAddressRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : ChooseAddressResult>;
signTransaction<B extends BehaviorType = DB>(request: Promise<SignTransactionRequest> | SignTransactionRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction>;
signStaking<B extends BehaviorType = DB>(request: Promise<SignStakingRequest> | SignStakingRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction[]>;
signStaking<B extends BehaviorType = DB>(request: Promise<SignStakingRequest> | SignStakingRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction>;
signMessage<B extends BehaviorType = DB>(request: Promise<SignMessageRequest> | SignMessageRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedMessage>;
signBtcTransaction<B extends BehaviorType = DB>(request: Promise<SignBtcTransactionRequest> | SignBtcTransactionRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedBtcTransaction>;
signPolygonTransaction<B extends BehaviorType = DB>(request: Promise<SignPolygonTransactionRequest> | SignPolygonTransactionRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedPolygonTransaction>;
Expand Down
5 changes: 3 additions & 2 deletions client/dist/src/PublicRequestTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface SignTransactionRequest extends BasicRequest {
export interface SignStakingRequest extends SignTransactionRequest {
type: number;
delegation?: string;
reactivateAllStake?: boolean;
newInactiveBalance?: number;
}
export interface NimiqCheckoutRequest extends BasicRequest {
Expand Down Expand Up @@ -510,5 +511,5 @@ export interface SignedPolygonTransaction {
signature: string;
}
export declare type RpcRequest = SignTransactionRequest | SignStakingRequest | CreateCashlinkRequest | ManageCashlinkRequest | CheckoutRequest | BasicRequest | SimpleRequest | ChooseAddressRequest | OnboardRequest | RenameRequest | SignMessageRequest | ExportRequest | SignBtcTransactionRequest | AddBtcAddressesRequest | SignPolygonTransactionRequest | SetupSwapRequest | RefundSwapRequest;
export declare type RpcResult = SignedTransaction | SignedTransaction[] | Account | Account[] | SimpleResult | ChooseAddressResult | Address | Cashlink | Cashlink[] | SignedMessage | ExportResult | SignedBtcTransaction | AddBtcAddressesResult | SignedPolygonTransaction | SetupSwapResult;
export declare type ResultByRequestType<T> = T extends RequestType.RENAME ? Account : T extends RequestType.ONBOARD | RequestType.SIGNUP | RequestType.LOGIN | RequestType.MIGRATE | RequestType.LIST ? Account[] : T extends RequestType.LIST_CASHLINKS ? Cashlink[] : T extends RequestType.CHOOSE_ADDRESS | RequestType.ADD_ADDRESS ? Address : T extends RequestType.SIGN_TRANSACTION ? SignedTransaction : T extends RequestType.SIGN_STAKING ? SignedTransaction[] : T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult : T extends RequestType.SIGN_MESSAGE ? SignedMessage : T extends RequestType.LOGOUT | RequestType.CHANGE_PASSWORD ? SimpleResult : T extends RequestType.EXPORT ? ExportResult : T extends RequestType.CREATE_CASHLINK | RequestType.MANAGE_CASHLINK ? Cashlink : T extends RequestType.SIGN_BTC_TRANSACTION ? SignedBtcTransaction : T extends RequestType.SIGN_POLYGON_TRANSACTION ? SignedPolygonTransaction : T extends RequestType.ACTIVATE_BITCOIN ? Account : T extends RequestType.ACTIVATE_POLYGON ? Account : T extends RequestType.ADD_BTC_ADDRESSES ? AddBtcAddressesResult : T extends RequestType.SETUP_SWAP ? SetupSwapResult : never;
export declare type RpcResult = SignedTransaction | Account | Account[] | SimpleResult | ChooseAddressResult | Address | Cashlink | Cashlink[] | SignedMessage | ExportResult | SignedBtcTransaction | AddBtcAddressesResult | SignedPolygonTransaction | SetupSwapResult;
export declare type ResultByRequestType<T> = T extends RequestType.RENAME ? Account : T extends RequestType.ONBOARD | RequestType.SIGNUP | RequestType.LOGIN | RequestType.MIGRATE | RequestType.LIST ? Account[] : T extends RequestType.LIST_CASHLINKS ? Cashlink[] : T extends RequestType.CHOOSE_ADDRESS | RequestType.ADD_ADDRESS ? Address : T extends RequestType.SIGN_TRANSACTION ? SignedTransaction : T extends RequestType.SIGN_STAKING ? SignedTransaction : T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult : T extends RequestType.SIGN_MESSAGE ? SignedMessage : T extends RequestType.LOGOUT | RequestType.CHANGE_PASSWORD ? SimpleResult : T extends RequestType.EXPORT ? ExportResult : T extends RequestType.CREATE_CASHLINK | RequestType.MANAGE_CASHLINK ? Cashlink : T extends RequestType.SIGN_BTC_TRANSACTION ? SignedBtcTransaction : T extends RequestType.SIGN_POLYGON_TRANSACTION ? SignedPolygonTransaction : T extends RequestType.ACTIVATE_BITCOIN ? Account : T extends RequestType.ACTIVATE_POLYGON ? Account : T extends RequestType.ADD_BTC_ADDRESSES ? AddBtcAddressesResult : T extends RequestType.SETUP_SWAP ? SetupSwapResult : never;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@nimiq/electrum-client": "https://github.com/nimiq/electrum-client#build",
"@nimiq/fastspot-api": "^1.7.0",
"@nimiq/iqons": "^1.5.2",
"@nimiq/keyguard-client": "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19",
"@nimiq/keyguard-client": "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fb889616bb9221792a6cb2b0194a33cb0835da96",
"@nimiq/ledger-api": "^2.3.0",
"@nimiq/network-client": "^0.6.2",
"@nimiq/oasis-api": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ msgstr ""
msgid "Unsupported Request"
msgstr ""

#: src/components/CheckoutCardNimiq.vue:324
#: src/components/CheckoutCardNimiq.vue:328
msgid "Updating balances"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions src/lib/RequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class RequestParser {
...(requestType === RequestType.SIGN_STAKING ? {
type: (signTransactionRequest as any as SignStakingRequest).type,
delegation: (signTransactionRequest as any as SignStakingRequest).delegation,
reactivateAllStake: (signTransactionRequest as any as SignStakingRequest).reactivateAllStake,
newInactiveBalance: (signTransactionRequest as any as SignStakingRequest).newInactiveBalance,
} : {}),
} as ParsedSignTransactionRequest;
Expand Down Expand Up @@ -726,6 +727,8 @@ export class RequestParser {
...(request.kind === RequestType.SIGN_STAKING ? {
type: (signTransactionRequest as any as ParsedSignStakingRequest).type,
delegation: (signTransactionRequest as any as ParsedSignStakingRequest).delegation,
reactivateAllStake: (signTransactionRequest as any as ParsedSignStakingRequest)
.reactivateAllStake,
newInactiveBalance: (signTransactionRequest as any as ParsedSignStakingRequest)
.newInactiveBalance,
} : {}),
Expand Down
1 change: 1 addition & 0 deletions src/lib/RequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface ParsedSignTransactionRequest extends ParsedBasicRequest {
export interface ParsedSignStakingRequest extends ParsedSignTransactionRequest {
type: number;
delegation?: string;
reactivateAllStake?: boolean;
newInactiveBalance?: number;
}

Expand Down
1 change: 1 addition & 0 deletions src/views/SignStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default class SignStaking extends Vue {
type: this.request.type,
delegation: this.request.delegation,
reactivateAllStake: this.request.reactivateAllStake,
newInactiveBalance: this.request.newInactiveBalance,
};
Expand Down
28 changes: 13 additions & 15 deletions src/views/SignStakingSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ export default class SignStakingSuccess extends Vue {
@State private keyguardResult!: KeyguardClient.SignStakingResult;
private async mounted() {
const result: SignedTransaction[] = await Promise.all(this.keyguardResult.map(async (keyguardResult) => {
const tx = await (this.$refs.network as Network).createTx(Object.assign(
{ signerPubKey: keyguardResult.publicKey },
this.keyguardRequest,
keyguardResult,
StakingSignallingTypes.includes(this.keyguardRequest.type) ? { value: 0, flags: 0b10 } : {},
this.keyguardRequest.type === StakingTransactionType.UNSTAKE
? { proofPrefix: new Uint8Array([StakingTransactionType.UNSTAKE])}
: {},
));
const res: SignedTransaction = await (this.$refs.network as Network).makeSignTransactionResult(tx);
// Overwrite serializedTx with Albatross serialization format
res.serializedTx = Nimiq.BufferUtils.toHex(keyguardResult.serializedTx);
return res;
}));
const tx = await (this.$refs.network as Network).createTx(Object.assign(
{ signerPubKey: this.keyguardResult.publicKey },
this.keyguardRequest,
this.keyguardResult,
StakingSignallingTypes.includes(this.keyguardRequest.type) ? { value: 0, flags: 0b10 } : {},
this.keyguardRequest.type === StakingTransactionType.UNSTAKE
? { proofPrefix: new Uint8Array([StakingTransactionType.UNSTAKE])}
: {},
));
const result: SignedTransaction = await (this.$refs.network as Network).makeSignTransactionResult(tx);
// Overwrite serializedTx with Albatross serialization format
result.serializedTx = Nimiq.BufferUtils.toHex(this.keyguardResult.serializedTx);
this.$rpc.resolve(result);
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1434,9 +1434,9 @@
glob-to-regexp "^0.3.0"

"@nimiq/albatross-wasm@npm:@nimiq/core-web@next":
version "2.0.0-alpha.15"
resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-2.0.0-alpha.15.tgz#ac0c8ab92c76ec4f60edcc62074bcd56352d5c25"
integrity sha512-jWCvaBEW1K1q2MxqnkkHcbui0XwEvoylU/wdR32QR7cXAVgbKVKgdCBvn64ypbK2U1StX+TgFsG8cb7xDWaGFA==
version "2.0.0-alpha.17"
resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-2.0.0-alpha.17.tgz#4cdfeb896ed98879566b4a87846d6c6c17796121"
integrity sha512-mPKhhrLXE/sRdBMxiEWtokTy889tkPILHg14wBzVuCwarjuH6CGxLWY64G2Mr6+kRXJpL95s7/zvaaMeCE1b3A==
dependencies:
comlink "^4.4.1"
websocket "^1.0.34"
Expand Down Expand Up @@ -1513,9 +1513,9 @@
btoa "^1.1.2"
node-lmdb "^0.9.6"

"@nimiq/keyguard-client@https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19":
"@nimiq/keyguard-client@https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fb889616bb9221792a6cb2b0194a33cb0835da96":
version "1.0.0"
resolved "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19#42ebeee7f590b230a3220fac31ac0f5ccaa67667"
resolved "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&fb889616bb9221792a6cb2b0194a33cb0835da96#a016613e0ec5248a1a10acfbaa0147e6a42486d8"

"@nimiq/ledger-api@^2.3.0":
version "2.3.0"
Expand Down

0 comments on commit 557c889

Please sign in to comment.