From 557c88937a241bb09511653d80abf7dcf9f8363f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Thu, 16 Nov 2023 08:51:03 -0600 Subject: [PATCH] Update albatross client, add support for reactivation in update-staker This reverts commit a46dc56da53ad43d2871b7ff831e5278172c23e6. --- client/HubApi.ts | 2 +- client/PublicRequestTypes.ts | 10 +++++++-- client/dist/src/HubApi.d.ts | 2 +- client/dist/src/PublicRequestTypes.d.ts | 5 +++-- package.json | 2 +- src/i18n/en.po | 2 +- src/lib/RequestParser.ts | 3 +++ src/lib/RequestTypes.ts | 1 + src/views/SignStaking.vue | 1 + src/views/SignStakingSuccess.vue | 28 ++++++++++++------------- yarn.lock | 10 ++++----- 11 files changed, 38 insertions(+), 28 deletions(-) diff --git a/client/HubApi.ts b/client/HubApi.ts index 32e78539..78f5cb01 100644 --- a/client/HubApi.ts +++ b/client/HubApi.ts @@ -174,7 +174,7 @@ export default class HubApi< public signStaking( request: Promise | SignStakingRequest, requestBehavior: RequestBehavior = this._defaultBehavior as any, - ): Promise { + ): Promise { return this._request(requestBehavior, RequestType.SIGN_STAKING, [request]); } diff --git a/client/PublicRequestTypes.ts b/client/PublicRequestTypes.ts index 77d987cb..6027026b 100644 --- a/client/PublicRequestTypes.ts +++ b/client/PublicRequestTypes.ts @@ -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; } @@ -641,7 +648,6 @@ export type RpcRequest = SignTransactionRequest | RefundSwapRequest; export type RpcResult = SignedTransaction - | SignedTransaction[] | Account | Account[] | SimpleResult @@ -663,7 +669,7 @@ export type ResultByRequestType = 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 : diff --git a/client/dist/src/HubApi.d.ts b/client/dist/src/HubApi.d.ts index 4cb84bb8..7d95a169 100644 --- a/client/dist/src/HubApi.d.ts +++ b/client/dist/src/HubApi.d.ts @@ -33,7 +33,7 @@ export default class HubApi; chooseAddress(request: Promise | ChooseAddressRequest, requestBehavior?: RequestBehavior): Promise; signTransaction(request: Promise | SignTransactionRequest, requestBehavior?: RequestBehavior): Promise; - signStaking(request: Promise | SignStakingRequest, requestBehavior?: RequestBehavior): Promise; + signStaking(request: Promise | SignStakingRequest, requestBehavior?: RequestBehavior): Promise; signMessage(request: Promise | SignMessageRequest, requestBehavior?: RequestBehavior): Promise; signBtcTransaction(request: Promise | SignBtcTransactionRequest, requestBehavior?: RequestBehavior): Promise; signPolygonTransaction(request: Promise | SignPolygonTransactionRequest, requestBehavior?: RequestBehavior): Promise; diff --git a/client/dist/src/PublicRequestTypes.d.ts b/client/dist/src/PublicRequestTypes.d.ts index 8dc69760..c03cc924 100644 --- a/client/dist/src/PublicRequestTypes.d.ts +++ b/client/dist/src/PublicRequestTypes.d.ts @@ -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 { @@ -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 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 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; diff --git a/package.json b/package.json index 8460ca4b..039045e1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/i18n/en.po b/src/i18n/en.po index 25164400..3e42f54d 100644 --- a/src/i18n/en.po +++ b/src/i18n/en.po @@ -1153,7 +1153,7 @@ msgstr "" msgid "Unsupported Request" msgstr "" -#: src/components/CheckoutCardNimiq.vue:324 +#: src/components/CheckoutCardNimiq.vue:328 msgid "Updating balances" msgstr "" diff --git a/src/lib/RequestParser.ts b/src/lib/RequestParser.ts index d40f8bea..0963c273 100644 --- a/src/lib/RequestParser.ts +++ b/src/lib/RequestParser.ts @@ -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; @@ -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, } : {}), diff --git a/src/lib/RequestTypes.ts b/src/lib/RequestTypes.ts index 87216cd7..2e34f7ad 100644 --- a/src/lib/RequestTypes.ts +++ b/src/lib/RequestTypes.ts @@ -54,6 +54,7 @@ export interface ParsedSignTransactionRequest extends ParsedBasicRequest { export interface ParsedSignStakingRequest extends ParsedSignTransactionRequest { type: number; delegation?: string; + reactivateAllStake?: boolean; newInactiveBalance?: number; } diff --git a/src/views/SignStaking.vue b/src/views/SignStaking.vue index 8b251260..5511390a 100644 --- a/src/views/SignStaking.vue +++ b/src/views/SignStaking.vue @@ -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, }; diff --git a/src/views/SignStakingSuccess.vue b/src/views/SignStakingSuccess.vue index 67ba1167..d350a579 100644 --- a/src/views/SignStakingSuccess.vue +++ b/src/views/SignStakingSuccess.vue @@ -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); } diff --git a/yarn.lock b/yarn.lock index f4132383..90ad413a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"