Skip to content

Commit

Permalink
Update to Keyguard's multiple staking tx return type
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Aug 10, 2023
1 parent 71306cb commit a46dc56
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 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
3 changes: 2 additions & 1 deletion client/PublicRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ export type RpcRequest = SignTransactionRequest
| RefundSwapRequest;

export type RpcResult = SignedTransaction
| SignedTransaction[]
| Account
| Account[]
| SimpleResult
Expand All @@ -662,7 +663,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
4 changes: 2 additions & 2 deletions client/dist/src/PublicRequestTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,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 | 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 | 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&2b94687a6f09cddc901850dbdcb8759f60c33501",
"@nimiq/keyguard-client": "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19",
"@nimiq/ledger-api": "^2.3.0",
"@nimiq/network-client": "^0.6.2",
"@nimiq/oasis-api": "^1.1.1",
Expand Down
28 changes: 15 additions & 13 deletions src/views/SignStakingSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ export default class SignStakingSuccess extends Vue {
@State private keyguardResult!: KeyguardClient.SignStakingResult;
private async mounted() {
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);
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;
}));
this.$rpc.resolve(result);
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,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&2b94687a6f09cddc901850dbdcb8759f60c33501":
"@nimiq/keyguard-client@https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19":
version "1.0.0"
resolved "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&2b94687a6f09cddc901850dbdcb8759f60c33501#b791150b76ed7cad893fa9b364673308bf0c30ed"
resolved "https://gitpkg.vercel.app/nimiq/keyguard?scripts.postinstall=cd%20client%20%26%26%20.%2Fbuild-gitpkg.sh&479c45c7edbf9b7167d2f2c5c4055b09127b1c19#42ebeee7f590b230a3220fac31ac0f5ccaa67667"

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

0 comments on commit a46dc56

Please sign in to comment.