From f5f3b1d99281ff229955652224ac6667cf9d1c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Thu, 16 Nov 2023 08:41:46 -0600 Subject: [PATCH] Update albatross client, add support for reactivation in update-staker --- client/src/PublicRequest.ts | 11 ++++++++++- src/request/sign-staking/SignStaking.js | 6 +++++- src/request/sign-staking/SignStakingApi.js | 5 +++++ src/request/sign-transaction/SignTransaction.js | 2 +- tools/build.sh | 3 +-- yarn.lock | 9 +++++---- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/client/src/PublicRequest.ts b/client/src/PublicRequest.ts index 07eb8b831..0f3c508db 100644 --- a/client/src/PublicRequest.ts +++ b/client/src/PublicRequest.ts @@ -190,9 +190,18 @@ export type SignTransactionRequest export type SignStakingRequest = SignTransactionRequestCommon & { type: number, // See SignStakingApi for types - recipientLabel?: string, + + // For createStaker and updateStaker transactions delegation?: string, + + // For updateStaker transactions + reactivateAllStake?: boolean, + + // For inactivateStake transactions newInactiveBalance?: number, + + // For unstake transactions + recipientLabel?: string, }; export type SignBtcTransactionRequestStandard = SimpleRequest & BitcoinTransactionInfo & { diff --git a/src/request/sign-staking/SignStaking.js b/src/request/sign-staking/SignStaking.js index be4ea5e93..bcba30233 100644 --- a/src/request/sign-staking/SignStaking.js +++ b/src/request/sign-staking/SignStaking.js @@ -183,6 +183,7 @@ class SignStaking { tx = Albatross.TransactionBuilder.newUpdateStaker( keyPair.toAddress(), Albatross.Address.fromString(/** @type {Nimiq.Address} */ (request.delegation).toHex()), + Boolean(request.reactivateAllStake), BigInt(request.transaction.fee), request.transaction.validityStartHeight, request.transaction.networkId, @@ -210,7 +211,7 @@ class SignStaking { throw new Errors.KeyguardError('Unreachable'); } - tx = tx.sign(keyPair); + tx.sign(keyPair); /** @type {KeyguardRequest.SignStakingResult} */ const result = { @@ -255,6 +256,9 @@ class SignStaking { } else { text += ' to no validator'; } + if (buf.readUint8() === 1) { + text += ' and reactivate all stake'; + } return text; } case SignStakingApi.IncomingStakingType.ADD_STAKE: { diff --git a/src/request/sign-staking/SignStakingApi.js b/src/request/sign-staking/SignStakingApi.js index 9aa363a6d..dbd2bd729 100644 --- a/src/request/sign-staking/SignStakingApi.js +++ b/src/request/sign-staking/SignStakingApi.js @@ -30,15 +30,20 @@ class SignStakingApi extends TopLevelApi { case SignStakingApi.IncomingStakingType.CREATE_STAKER: case SignStakingApi.IncomingStakingType.UPDATE_STAKER: { parsedRequest.delegation = this.parseAddress(request.delegation, 'delegation'); + parsedRequest.reactivateAllStake = this.parseBoolean(request.reactivateAllStake); const data = new Nimiq.SerialBuffer( 1 // Data type + 1 // Option<> indicator + Nimiq.Address.SERIALIZED_SIZE // Validator address (delegation) + + (type === SignStakingApi.IncomingStakingType.UPDATE_STAKER ? 1 : 0) // Stake reactivation boolean + Nimiq.SignatureProof.SINGLE_SIG_SIZE, // Staker signature ); data.writeUint8(type); data.writeUint8(1); // Delegation is optional, this signals that we are including it. data.write(parsedRequest.delegation.serialize()); + if (type === SignStakingApi.IncomingStakingType.UPDATE_STAKER) { + data.writeUint8(parsedRequest.reactivateAllStake ? 1 : 0); + } request.data = data; isSignalling = type === SignStakingApi.IncomingStakingType.UPDATE_STAKER; break; diff --git a/src/request/sign-transaction/SignTransaction.js b/src/request/sign-transaction/SignTransaction.js index dadfae191..0beddc8b1 100644 --- a/src/request/sign-transaction/SignTransaction.js +++ b/src/request/sign-transaction/SignTransaction.js @@ -223,7 +223,7 @@ class SignTransaction { ); } - tx = tx.sign(keyPair); + tx.sign(keyPair); /** @type {KeyguardRequest.SignTransactionResult} */ const result = { diff --git a/tools/build.sh b/tools/build.sh index be561ae9b..ea729c74b 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -384,8 +384,7 @@ cp -v node_modules/@nimiq/core-web/web.js \ # copy Albatross files output "‼️ Copying Albatross files" -cp -vr node_modules/@nimiq/albatross-wasm/client-proxy.js \ - node_modules/@nimiq/albatross-wasm/transfer-handlers.js \ +cp -vr node_modules/@nimiq/albatross-wasm/lib \ node_modules/@nimiq/albatross-wasm/web \ dist/assets/albatross diff --git a/yarn.lock b/yarn.lock index 7a84a88f8..732a0f7b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -393,11 +393,12 @@ "@ethersproject/strings" "^5.7.0" "@nimiq/albatross-wasm@npm:@nimiq/core-web@next": - version "2.0.0-alpha.13" - resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-2.0.0-alpha.13.tgz#6fe7ae67aeaadbfff880061c75728928de75d863" - integrity sha512-lSOhtgDy7jl74naVuwik54eCFD/oDiAhe1JV0uQVbm3O5tJKCTLqik+wSO9FvdjpZwLj/XwzA06NcJWM/PyFcA== + 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" "@nimiq/core-web@1.5.8": version "1.5.8" @@ -5809,7 +5810,7 @@ webidl-conversions@^3.0.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== -websocket@^1.0.32: +websocket@^1.0.32, websocket@^1.0.34: version "1.0.34" resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111" integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==