Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

feat: AOPP support for signMessage method #942

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@
"comment": ["new eth transaction pricing mechanism (EIP1559) since 1.10.4/2.4.2"]
},
{
"capabilities": ["taproot"],
"capabilities": ["taproot", "aopp"],
"min": ["1.10.4", "2.4.3"],
"comment": ["new btc accounts taproot since 1.10.4/2.4.3 (BTC + TEST only)"]
"comment": [
"new btc accounts taproot since 1.10.4/2.4.3 (BTC + TEST only)",
"SignMessage with AOPP support"
]
}
]
}
7 changes: 7 additions & 0 deletions src/data/messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@
"type": "InputScriptType",
"name": "script_type",
"id": 4
},
{
"rule": "optional",
"options": {},
"type": "bool",
"name": "no_script_type",
"id": 5
}
],
"enums": [],
Expand Down
13 changes: 9 additions & 4 deletions src/js/core/methods/SignMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class SignMessage extends AbstractMethod {
{ name: 'coin', type: 'string' },
{ name: 'message', type: 'string', obligatory: true },
{ name: 'hex', type: 'boolean' },
{ name: 'no_script_type', type: 'boolean' },
]);

const path = validatePath(payload.path);
Expand All @@ -37,10 +38,13 @@ export default class SignMessage extends AbstractMethod {

this.info = getLabel('Sign #NETWORK message', coinInfo);

if (coinInfo) {
// check required firmware with coinInfo support
this.firmwareRange = getFirmwareRange(this.name, coinInfo, this.firmwareRange);
}
// firmware range depends on used no_script_type parameter
// AOPP is possible since 1.10/42.4.3
this.firmwareRange = getFirmwareRange(
payload.no_script_type ? 'aopp' : this.name,
coinInfo,
this.firmwareRange,
);

const messageHex = payload.hex
? messageToHex(payload.message)
Expand All @@ -51,6 +55,7 @@ export default class SignMessage extends AbstractMethod {
message: messageHex,
coin_name: coinInfo ? coinInfo.name : undefined,
script_type: scriptType && scriptType !== 'SPENDMULTISIG' ? scriptType : 'SPENDADDRESS', // script_type 'SPENDMULTISIG' throws Failure_FirmwareError
no_script_type: payload.no_script_type,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/js/types/trezor/protobuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export type SignMessage = {
message: string,
coin_name?: string,
script_type?: InputScriptType,
no_script_type?: boolean,
};

// MessageSignature
Expand Down
2 changes: 2 additions & 0 deletions src/js/utils/__tests__/deviceFeaturesUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('utils/deviceFeaturesUtils', () => {
decreaseOutput: 'update-required',
eip1559: 'update-required',
taproot: 'update-required',
aopp: 'update-required',
});

const feat2 = {
Expand All @@ -135,6 +136,7 @@ describe('utils/deviceFeaturesUtils', () => {
decreaseOutput: 'update-required',
eip1559: 'update-required',
taproot: 'update-required',
aopp: 'update-required',
});

// added new capability
Expand Down
1 change: 1 addition & 0 deletions src/ts/types/trezor/protobuf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export type SignMessage = {
message: string;
coin_name?: string;
script_type?: InputScriptType;
no_script_type?: boolean;
};

// MessageSignature
Expand Down
48 changes: 48 additions & 0 deletions tests/__fixtures__/signMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,53 @@ export default {
).toString('base64'),
},
},
{
description: 'BTC AOPP p2pkh',
params: {
coin: 'Bitcoin',
path: ADDRESS_N("m/44'/0'/0'/0/0"),
message: 'This is an example of a signed message.',
no_script_type: true,
},
result: {
address: '1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL',
signature: Buffer.from(
'20fd8f2f7db5238fcdd077d5204c3e6949c261d700269cefc1d9d2dcef6b95023630ee617f6c8acf9eb40c8edd704c9ca74ea4afc393f43f35b4e8958324cbdd1c',
'hex',
).toString('base64'),
},
},
{
description: 'BTC AOPP p2sh',
params: {
coin: 'Bitcoin',
path: ADDRESS_N("m/49'/0'/0'/0/0"),
message: 'This is an example of a signed message.',
no_script_type: true,
},
result: {
address: '3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2',
signature: Buffer.from(
'1f744de4516fac5c140808015664516a32fead94de89775cec7e24dbc24fe133075ac09301c4cc8e197bea4b6481661d5b8e9bf19d8b7b8a382ecdb53c2ee0750d',
'hex',
).toString('base64'),
},
},
{
description: 'BTC AOPP p2wpkh',
params: {
coin: 'Bitcoin',
path: ADDRESS_N("m/84'/0'/0'/0/0"),
message: 'This is an example of a signed message.',
no_script_type: true,
},
result: {
address: 'bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk',
signature: Buffer.from(
'20b55d7600d9e9a7e2a49155ddf3cfdb8e796c207faab833010fa41fb7828889bc47cf62348a7aaa0923c0832a589fab541e8f12eb54fb711c90e2307f0f66b194',
'hex',
).toString('base64'),
},
},
],
};