Skip to content

Commit fd4a48d

Browse files
committed
RequestSignTransactionNimiq,RequestSignMessageNimiq: require 2.0 app if needed
For message signing and Albatross transactions require app version 2.0, as support for these was added in that app version.
1 parent 2162ba8 commit fd4a48d

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

src/high-level-api/requests/bitcoin/request-sign-transaction-bitcoin.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ export default class RequestSignTransactionBitcoin extends RequestBitcoin<string
7373
public readonly network: Exclude<Network, Network.DEVNET>;
7474
private _inputType: AddressTypeBitcoin;
7575

76+
public get requiredApp(): string {
77+
// The new Bitcoin app does not allow custom input scripts (for example custom witness scripts) unless an
78+
// associated wallet policy had been registered. For this reason, we currently still require using the old api
79+
// if custom input scripts are set.
80+
if (!this.transaction.inputs.some(({ customScript }) => !!customScript)) return super.requiredApp;
81+
if (this._coinAppConnection && this._coinAppConnection.app === super.requiredApp
82+
&& !RequestBitcoin._isNewApiSupported(this._coinAppConnection.app, this._coinAppConnection.appVersion)) {
83+
// We're already connected to an appropriate Bitcoin app on which we don't use the new api, e.g. a Bitcoin
84+
// app before 2.0. Thus, no need to specifically require the Legacy app variant.
85+
return super.requiredApp;
86+
}
87+
return getLegacyApp(super.requiredApp); // require Legacy app variant
88+
}
89+
7690
constructor(transaction: TransactionInfoBitcoin, expectedWalletId?: string) {
7791
super(expectedWalletId);
7892

@@ -145,20 +159,6 @@ export default class RequestSignTransactionBitcoin extends RequestBitcoin<string
145159
this._loadBitcoinLibIfNeeded().catch(() => {});
146160
}
147161

148-
public get requiredApp(): string {
149-
// The new Bitcoin app does not allow custom input scripts (for example custom witness scripts) unless an
150-
// associated wallet policy had been registered. For this reason, we currently still require using the old api
151-
// if custom input scripts are set.
152-
if (!this.transaction.inputs.some(({ customScript }) => !!customScript)) return super.requiredApp;
153-
if (this._coinAppConnection && this._coinAppConnection.app === super.requiredApp
154-
&& !RequestBitcoin._isNewApiSupported(this._coinAppConnection.app, this._coinAppConnection.appVersion)) {
155-
// We're already connected to an appropriate Bitcoin app on which we don't use the new api, e.g. a Bitcoin
156-
// app before 2.0. Thus, no need to specifically require the Legacy app variant.
157-
return super.requiredApp;
158-
}
159-
return getLegacyApp(super.requiredApp); // require Legacy app variant
160-
}
161-
162162
public async call(transport: Transport): Promise<string> {
163163
// Resources:
164164
// - to learn more about scripts and how input and output script relate to each other:

src/high-level-api/requests/nimiq/request-nimiq.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ export default abstract class RequestNimiq<Version extends NimiqVersion, T>
1818

1919
public readonly coin: Coin.NIMIQ = Coin.NIMIQ;
2020
public readonly requiredApp: string = 'Nimiq';
21-
public readonly minRequiredAppVersion: string = '1.4.2'; // first version supporting web usb
2221
public readonly nimiqVersion: Version;
2322

23+
public get minRequiredAppVersion(): string {
24+
return '1.4.2'; // first version supporting web usb
25+
}
26+
2427
protected constructor(nimiqVersion: Version, expectedWalletId?: string) {
2528
super(expectedWalletId);
2629
this.nimiqVersion = nimiqVersion;

src/high-level-api/requests/nimiq/request-sign-message-nimiq.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export default class RequestSignMessageNimiq<Version extends NimiqVersion>
1919
preferDisplayTypeHash: boolean, // second choice, if multiple flags are set
2020
};
2121

22+
public get minRequiredAppVersion(): string {
23+
return '2.0'; // first version supporting message signing
24+
}
25+
2226
constructor(
2327
nimiqVersion: Version,
2428
keyPath: string,

src/high-level-api/requests/nimiq/request-sign-transaction-nimiq.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export default class RequestSignTransactionNimiq<Version extends NimiqVersion>
3636
public readonly type: RequestTypeNimiq.SIGN_TRANSACTION;
3737
public readonly transaction: TransactionInfoNimiq<Version>;
3838

39+
public get minRequiredAppVersion(): string {
40+
return this.nimiqVersion === NimiqVersion.ALBATROSS
41+
? '2.0' // first version supporting Albatross transactions
42+
: super.minRequiredAppVersion;
43+
}
44+
3945
constructor(
4046
nimiqVersion: Version,
4147
keyPath: string,

0 commit comments

Comments
 (0)