@ledgerhq/live-common 27.1.0 → 27.2.0-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +90 -81
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/specs.d.ts.map +1 -1
- package/lib/bot/specs.js +11 -2
- package/lib/bot/specs.js.map +1 -1
- package/lib/families/bitcoin/hw-signMessage.d.ts +5 -3
- package/lib/families/bitcoin/hw-signMessage.d.ts.map +1 -1
- package/lib/families/bitcoin/hw-signMessage.js +2 -2
- package/lib/families/bitcoin/hw-signMessage.js.map +1 -1
- package/lib/families/cosmos/specs.d.ts.map +1 -1
- package/lib/families/cosmos/specs.js +12 -8
- package/lib/families/cosmos/specs.js.map +1 -1
- package/lib/families/ethereum/hw-signMessage.d.ts +7 -3
- package/lib/families/ethereum/hw-signMessage.d.ts.map +1 -1
- package/lib/families/ethereum/hw-signMessage.js +73 -14
- package/lib/families/ethereum/hw-signMessage.js.map +1 -1
- package/lib/families/ethereum/hw-signMessage.test.js +99 -23
- package/lib/families/ethereum/hw-signMessage.test.js.map +1 -1
- package/lib/families/ethereum/types.d.ts +6 -8
- package/lib/families/ethereum/types.d.ts.map +1 -1
- package/lib/families/filecoin/bridge.integration.test.js +1 -1
- package/lib/families/filecoin/bridge.integration.test.js.map +1 -1
- package/lib/families/filecoin/hw-signMessage.d.ts +5 -3
- package/lib/families/filecoin/hw-signMessage.d.ts.map +1 -1
- package/lib/families/filecoin/hw-signMessage.js +2 -2
- package/lib/families/filecoin/hw-signMessage.js.map +1 -1
- package/lib/families/osmosis/specs.d.ts.map +1 -1
- package/lib/families/osmosis/specs.js +32 -22
- package/lib/families/osmosis/specs.js.map +1 -1
- package/lib/families/tron/specs.js +1 -1
- package/lib/families/tron/specs.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +9 -3
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/generated/hw-signMessage.d.ts +10 -3
- package/lib/generated/hw-signMessage.d.ts.map +1 -1
- package/lib/hw/getOnboardingStatePolling.d.ts.map +1 -1
- package/lib/hw/getOnboardingStatePolling.js +1 -0
- package/lib/hw/getOnboardingStatePolling.js.map +1 -1
- package/lib/hw/signMessage/index.d.ts +5 -5
- package/lib/hw/signMessage/index.d.ts.map +1 -1
- package/lib/hw/signMessage/index.js +10 -6
- package/lib/hw/signMessage/index.js.map +1 -1
- package/lib/hw/signMessage/index.test.js +42 -43
- package/lib/hw/signMessage/index.test.js.map +1 -1
- package/lib/hw/signMessage/types.d.ts +1 -1
- package/lib/hw/signMessage/types.d.ts.map +1 -1
- package/lib/walletconnect/index.d.ts +1 -1
- package/lib/walletconnect/index.d.ts.map +1 -1
- package/lib/walletconnect/index.js +1 -9
- package/lib/walletconnect/index.js.map +1 -1
- package/lib/walletconnect/walletconnect.test.js.map +1 -1
- package/package.json +4 -4
- package/src/bot/index.ts +174 -113
- package/src/bot/specs.ts +16 -2
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +1 -35
- package/src/families/bitcoin/hw-signMessage.ts +3 -3
- package/src/families/cosmos/specs.ts +14 -10
- package/src/families/ethereum/hw-signMessage.test.ts +105 -21
- package/src/families/ethereum/hw-signMessage.ts +68 -16
- package/src/families/ethereum/types.ts +6 -8
- package/src/families/filecoin/__snapshots__/bridge.integration.test.ts.snap +27 -0
- package/src/families/filecoin/bridge.integration.test.ts +6 -2
- package/src/families/filecoin/hw-signMessage.ts +3 -3
- package/src/families/osmosis/specs.ts +35 -25
- package/src/families/tron/specs.ts +1 -1
- package/src/featureFlags/defaultFeatures.ts +9 -3
- package/src/hw/getOnboardingStatePolling.ts +2 -0
- package/src/hw/signMessage/index.test.ts +48 -45
- package/src/hw/signMessage/index.ts +23 -9
- package/src/hw/signMessage/types.ts +4 -1
- package/src/walletconnect/index.ts +3 -11
- package/src/walletconnect/walletconnect.test.ts +2 -0
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`filecoin currency bridge scanAccounts filecoin seed 1 1`] = `
|
|
4
4
|
Array [
|
|
5
|
+
Object {
|
|
6
|
+
"balance": "1000000000000000",
|
|
7
|
+
"currencyId": "filecoin",
|
|
8
|
+
"derivationMode": "gliflegacy",
|
|
9
|
+
"freshAddress": "t15lauyzdivqj7m3yob3rxmzdsy7uyhfflwyheuri",
|
|
10
|
+
"freshAddressPath": "44'/1'/0'/0/0",
|
|
11
|
+
"freshAddresses": Array [
|
|
12
|
+
Object {
|
|
13
|
+
"address": "t15lauyzdivqj7m3yob3rxmzdsy7uyhfflwyheuri",
|
|
14
|
+
"derivationPath": "44'/1'/0'/0/0",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
"id": "js:2:filecoin:t15lauyzdivqj7m3yob3rxmzdsy7uyhfflwyheuri:gliflegacy",
|
|
18
|
+
"index": 0,
|
|
19
|
+
"name": "Filecoin 1",
|
|
20
|
+
"nfts": undefined,
|
|
21
|
+
"operationsCount": 0,
|
|
22
|
+
"pendingOperations": Array [],
|
|
23
|
+
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
|
|
24
|
+
"spendableBalance": "1000000000000000",
|
|
25
|
+
"starred": false,
|
|
26
|
+
"swapHistory": Array [],
|
|
27
|
+
"syncHash": undefined,
|
|
28
|
+
"unitMagnitude": 18,
|
|
29
|
+
"used": true,
|
|
30
|
+
},
|
|
5
31
|
Object {
|
|
6
32
|
"balance": "100000000000000000",
|
|
7
33
|
"currencyId": "filecoin",
|
|
@@ -59,6 +85,7 @@ Array [
|
|
|
59
85
|
|
|
60
86
|
exports[`filecoin currency bridge scanAccounts filecoin seed 1 2`] = `
|
|
61
87
|
Array [
|
|
88
|
+
Array [],
|
|
62
89
|
Array [
|
|
63
90
|
Object {
|
|
64
91
|
"accountId": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:",
|
|
@@ -31,9 +31,13 @@ const filecoin: CurrenciesData<Transaction> = {
|
|
|
31
31
|
=> 06010000142c000080cd010080000000800000000000000000
|
|
32
32
|
<= 04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb015017ff83e316c2605c018ab3a6126d5d8ce0a3023e529663170373464346d6c6d657963346167666c686a71736e766f797a796664616937666d6b79736f32619000
|
|
33
33
|
=> 0600000000
|
|
34
|
-
<=
|
|
34
|
+
<= 0000160500311000049000
|
|
35
35
|
=> 06010000142c00008001000080000000800000000000000000
|
|
36
|
-
<=
|
|
36
|
+
<= 04d493dab3ff63d6f0673454f8f6d6adec08db19e8c0298c65cfcace76a10757774afdee518b15a8b82452531bcb7860eefce02a89ef9051037646f5d4d6bd74171501eac14c6468ac13f66f0e0ee3766472c7e98394ab297431356c6175797a646976716a376d33796f623372786d7a6473793775796866666c777968657572699000
|
|
37
|
+
=> 0600000000
|
|
38
|
+
<= 0000160500311000049000
|
|
39
|
+
=> 06010000142c00008001000080000000800000000001000000
|
|
40
|
+
<= 040cbb57791d797268e34340565393f8a014ae754026159973fbe46bdcef3b6d28d155f4923256a2beb9bcff3bd39e5066d1c778306f28a2d4faa3a66dbf70453e150148c9b66fef1fce116652099bec6301ced31e56472974316a6465336d33377064376862637a737362676e36797979627a336a7234767368676370696b32619000
|
|
37
41
|
=> 0600000000
|
|
38
42
|
<= 0000160500311000049000
|
|
39
43
|
=> 06010000142c000080cd010080000000800000000001000000
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Fil from "@zondax/ledger-filecoin";
|
|
2
2
|
import { log } from "@ledgerhq/logs";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { SignMessage, Result } from "../../hw/signMessage/types";
|
|
5
5
|
import { getBufferFromString, getPath, isError } from "./utils";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const signMessage: SignMessage = async (
|
|
8
8
|
transport,
|
|
9
9
|
{ path, message }
|
|
10
10
|
): Promise<Result> => {
|
|
@@ -27,4 +27,4 @@ const resolver: Resolver = async (
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export default
|
|
30
|
+
export default { signMessage };
|
|
@@ -192,13 +192,15 @@ const osmosis: AppSpec<Transaction> = {
|
|
|
192
192
|
(d) => d.validatorAddress === v.address
|
|
193
193
|
);
|
|
194
194
|
invariant(d, "delegated %s must be found in account", v.address);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
botTest("delegator have planned address and amount", () =>
|
|
196
|
+
expect({
|
|
197
|
+
address: v.address,
|
|
198
|
+
amount: approximateValue(v.amount),
|
|
199
|
+
}).toMatchObject({
|
|
200
|
+
address: (d as CosmosDelegation).validatorAddress,
|
|
201
|
+
amount: approximateValue((d as CosmosDelegation).amount),
|
|
202
|
+
})
|
|
203
|
+
);
|
|
202
204
|
});
|
|
203
205
|
},
|
|
204
206
|
},
|
|
@@ -260,13 +262,15 @@ const osmosis: AppSpec<Transaction> = {
|
|
|
260
262
|
(d) => d.validatorAddress === v.address
|
|
261
263
|
);
|
|
262
264
|
invariant(d, "undelegated %s must be found in account", v.address);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
botTest("validator have planned address and amount", () =>
|
|
266
|
+
expect({
|
|
267
|
+
address: v.address,
|
|
268
|
+
amount: approximateValue(v.amount),
|
|
269
|
+
}).toMatchObject({
|
|
270
|
+
address: (d as CosmosUnbonding).validatorAddress,
|
|
271
|
+
amount: approximateValue((d as CosmosUnbonding).amount),
|
|
272
|
+
})
|
|
273
|
+
);
|
|
270
274
|
});
|
|
271
275
|
},
|
|
272
276
|
},
|
|
@@ -338,13 +342,15 @@ const osmosis: AppSpec<Transaction> = {
|
|
|
338
342
|
d.validatorSrcAddress === transaction.sourceValidator
|
|
339
343
|
);
|
|
340
344
|
invariant(d, "redelegated %s must be found in account", v.address);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
botTest("validator have planned address and amount", () =>
|
|
346
|
+
expect({
|
|
347
|
+
address: v.address,
|
|
348
|
+
amount: approximateValue(v.amount),
|
|
349
|
+
}).toMatchObject({
|
|
350
|
+
address: (d as CosmosRedelegation).validatorDstAddress,
|
|
351
|
+
amount: approximateValue((d as CosmosRedelegation).amount),
|
|
352
|
+
})
|
|
353
|
+
);
|
|
348
354
|
}
|
|
349
355
|
});
|
|
350
356
|
},
|
|
@@ -385,10 +391,14 @@ const osmosis: AppSpec<Transaction> = {
|
|
|
385
391
|
const d = (cosmosResources as CosmosResources).delegations.find(
|
|
386
392
|
(d) => d.validatorAddress === v.address
|
|
387
393
|
);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
botTest("delegation exists in account", () =>
|
|
395
|
+
invariant(d, "delegation %s must be found in account", v.address)
|
|
396
|
+
);
|
|
397
|
+
botTest("reward is no longer claimable after claim", () =>
|
|
398
|
+
invariant(
|
|
399
|
+
!canClaimRewards(account as CosmosAccount, d as CosmosDelegation),
|
|
400
|
+
"reward no longer be claimable"
|
|
401
|
+
)
|
|
392
402
|
);
|
|
393
403
|
});
|
|
394
404
|
},
|
|
@@ -90,7 +90,7 @@ const tron: AppSpec<Transaction> = {
|
|
|
90
90
|
},
|
|
91
91
|
test: ({ account }) => {
|
|
92
92
|
botTest("account spendable balance is zero", () =>
|
|
93
|
-
|
|
93
|
+
expectedApproximate(account.spendableBalance, new BigNumber(0))
|
|
94
94
|
);
|
|
95
95
|
},
|
|
96
96
|
},
|
|
@@ -50,9 +50,6 @@ export const defaultFeatures: DefaultFeatures = {
|
|
|
50
50
|
currencyFlareMobile: {
|
|
51
51
|
enabled: false,
|
|
52
52
|
},
|
|
53
|
-
currency: {
|
|
54
|
-
enabled: false,
|
|
55
|
-
},
|
|
56
53
|
ratings: {
|
|
57
54
|
enabled: false,
|
|
58
55
|
params: {
|
|
@@ -103,4 +100,13 @@ export const defaultFeatures: DefaultFeatures = {
|
|
|
103
100
|
counterValue: {
|
|
104
101
|
enabled: false,
|
|
105
102
|
},
|
|
103
|
+
llmUsbFirmwareUpdate: {
|
|
104
|
+
enabled: false,
|
|
105
|
+
},
|
|
106
|
+
ptxSmartRouting: {
|
|
107
|
+
enabled: false,
|
|
108
|
+
},
|
|
109
|
+
ptxSmartRoutingMobile: {
|
|
110
|
+
enabled: false,
|
|
111
|
+
},
|
|
106
112
|
};
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
DeviceExtractOnboardingStateError,
|
|
17
17
|
DisconnectedDevice,
|
|
18
18
|
CantOpenDevice,
|
|
19
|
+
TransportRaceCondition,
|
|
19
20
|
} from "@ledgerhq/errors";
|
|
20
21
|
import { FirmwareInfo } from "@ledgerhq/types-live";
|
|
21
22
|
import {
|
|
@@ -149,6 +150,7 @@ export const isAllowedOnboardingStatePollingError = (error: Error): boolean => {
|
|
|
149
150
|
(error instanceof TimeoutError ||
|
|
150
151
|
error instanceof DisconnectedDevice ||
|
|
151
152
|
error instanceof CantOpenDevice ||
|
|
153
|
+
error instanceof TransportRaceCondition ||
|
|
152
154
|
error instanceof TransportStatusError)
|
|
153
155
|
) {
|
|
154
156
|
return true;
|
|
@@ -1,19 +1,38 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
1
2
|
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
3
|
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
-
import
|
|
4
|
+
import { createFixtureCryptoCurrency } from "../../mock/fixtures/cryptoCurrencies";
|
|
5
|
+
import { TypedMessageData } from "../../families/ethereum/types";
|
|
4
6
|
import { prepareMessageToSign } from "./index";
|
|
5
7
|
import { MessageData } from "./types";
|
|
6
8
|
|
|
9
|
+
const signResult = {
|
|
10
|
+
message: "Sign results",
|
|
11
|
+
rawMessage: "Sign raw results",
|
|
12
|
+
};
|
|
13
|
+
const signFunction = jest.fn(() => signResult);
|
|
14
|
+
jest.mock("../../generated/hw-signMessage", () => {
|
|
15
|
+
return {
|
|
16
|
+
signExistFamily: {
|
|
17
|
+
prepareMessageToSign: function () {
|
|
18
|
+
return signFunction();
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
bitcoin: {
|
|
22
|
+
otherMethod: function () {},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
7
27
|
describe("prepareMessageToSign", () => {
|
|
8
|
-
it("
|
|
28
|
+
it("calls the perFamily function if it's exist and returns this function results", () => {
|
|
9
29
|
// Given
|
|
10
|
-
const crypto =
|
|
30
|
+
const crypto = createFixtureCryptoCurrency("signExistFamily");
|
|
11
31
|
const account = createAccount(crypto);
|
|
12
|
-
const message = "
|
|
13
|
-
const expectedRawMessage = "0x4d6573736167652064652074657374";
|
|
32
|
+
const message = "whatever";
|
|
14
33
|
|
|
15
34
|
// When
|
|
16
|
-
let result: MessageData |
|
|
35
|
+
let result: MessageData | TypedMessageData | undefined;
|
|
17
36
|
let error: unknown = null;
|
|
18
37
|
try {
|
|
19
38
|
result = prepareMessageToSign(account, message);
|
|
@@ -23,10 +42,26 @@ describe("prepareMessageToSign", () => {
|
|
|
23
42
|
|
|
24
43
|
// Then
|
|
25
44
|
expect(error).toBeNull();
|
|
45
|
+
expect(signFunction).toBeCalledTimes(1);
|
|
46
|
+
expect(result).toEqual(signResult);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("returns a default implementation if account is linked to a crypto able to sign but with no prepareMessageToSign function", () => {
|
|
50
|
+
// Given
|
|
51
|
+
const currency = createFixtureCryptoCurrency("bitcoin");
|
|
52
|
+
const account = createAccount(currency);
|
|
53
|
+
const message = "4d6573736167652064652074657374";
|
|
54
|
+
const expectedPath = "44'/60'/0'/0/0";
|
|
55
|
+
const expectedRawMessage = "0x4d6573736167652064652074657374";
|
|
56
|
+
|
|
57
|
+
// // When
|
|
58
|
+
const result = prepareMessageToSign(account, message);
|
|
59
|
+
|
|
60
|
+
// // Then
|
|
26
61
|
expect(result).toEqual({
|
|
27
|
-
currency
|
|
28
|
-
path:
|
|
29
|
-
derivationMode:
|
|
62
|
+
currency,
|
|
63
|
+
path: expectedPath,
|
|
64
|
+
derivationMode: account.derivationMode,
|
|
30
65
|
message: "Message de test",
|
|
31
66
|
rawMessage: expectedRawMessage,
|
|
32
67
|
});
|
|
@@ -34,12 +69,12 @@ describe("prepareMessageToSign", () => {
|
|
|
34
69
|
|
|
35
70
|
it("returns an error if account is not linked to a crypto able to sign a message", () => {
|
|
36
71
|
// Given
|
|
37
|
-
const crypto =
|
|
72
|
+
const crypto = createFixtureCryptoCurrency("mycoin");
|
|
38
73
|
const account = createAccount(crypto);
|
|
39
|
-
const message = "
|
|
74
|
+
const message = "whatever";
|
|
40
75
|
|
|
41
76
|
// When
|
|
42
|
-
let result: MessageData |
|
|
77
|
+
let result: MessageData | TypedMessageData | undefined;
|
|
43
78
|
let error: Error | null = null;
|
|
44
79
|
try {
|
|
45
80
|
result = prepareMessageToSign(account, message);
|
|
@@ -48,43 +83,11 @@ describe("prepareMessageToSign", () => {
|
|
|
48
83
|
}
|
|
49
84
|
|
|
50
85
|
// Then
|
|
51
|
-
expect(result).
|
|
86
|
+
expect(result).toBeUndefined();
|
|
52
87
|
expect(error).toEqual(Error("Crypto does not support signMessage"));
|
|
53
88
|
});
|
|
54
89
|
});
|
|
55
90
|
|
|
56
|
-
const createCryptoCurrency = (family: string): CryptoCurrency => ({
|
|
57
|
-
type: "CryptoCurrency",
|
|
58
|
-
id: "testCoinId",
|
|
59
|
-
coinType: 8008,
|
|
60
|
-
name: "MyCoin",
|
|
61
|
-
managerAppName: "MyCoin",
|
|
62
|
-
ticker: "MYC",
|
|
63
|
-
countervalueTicker: "MYC",
|
|
64
|
-
scheme: "mycoin",
|
|
65
|
-
color: "#ff0000",
|
|
66
|
-
family,
|
|
67
|
-
units: [
|
|
68
|
-
{
|
|
69
|
-
name: "MYC",
|
|
70
|
-
code: "MYC",
|
|
71
|
-
magnitude: 8,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "SmallestUnit",
|
|
75
|
-
code: "SMALLESTUNIT",
|
|
76
|
-
magnitude: 0,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
explorerViews: [
|
|
80
|
-
{
|
|
81
|
-
address: "https://mycoinexplorer.com/account/$address",
|
|
82
|
-
tx: "https://mycoinexplorer.com/transaction/$hash",
|
|
83
|
-
token: "https://mycoinexplorer.com/token/$contractAddress/?a=$address",
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
|
|
88
91
|
const createAccount = (crypto: CryptoCurrency): Account => ({
|
|
89
92
|
type: "Account",
|
|
90
93
|
id: "ethereumjs:2:ethereum:0x01:",
|
|
@@ -13,17 +13,29 @@ import { createAction as createAppAction } from "../actions/app";
|
|
|
13
13
|
import type { Device } from "../actions/types";
|
|
14
14
|
import type { ConnectAppEvent, Input as ConnectAppInput } from "../connectApp";
|
|
15
15
|
import { withDevice } from "../deviceAccess";
|
|
16
|
-
import type { MessageData,
|
|
16
|
+
import type { MessageData, SignMessage, Result } from "./types";
|
|
17
17
|
import { DerivationMode } from "../../derivation";
|
|
18
18
|
|
|
19
19
|
export const prepareMessageToSign = (
|
|
20
|
-
|
|
20
|
+
account: Account,
|
|
21
21
|
message: string
|
|
22
|
-
): MessageData
|
|
22
|
+
): MessageData => {
|
|
23
|
+
const { currency, freshAddressPath, derivationMode } = account;
|
|
24
|
+
|
|
23
25
|
if (!perFamily[currency.family]) {
|
|
24
26
|
throw new Error("Crypto does not support signMessage");
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
if ("prepareMessageToSign" in perFamily[currency.family]) {
|
|
30
|
+
return perFamily[currency.family].prepareMessageToSign(
|
|
31
|
+
currency,
|
|
32
|
+
freshAddressPath,
|
|
33
|
+
derivationMode,
|
|
34
|
+
message
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Default implementation
|
|
27
39
|
return {
|
|
28
40
|
currency: currency,
|
|
29
41
|
path: freshAddressPath,
|
|
@@ -33,9 +45,9 @@ export const prepareMessageToSign = (
|
|
|
33
45
|
};
|
|
34
46
|
};
|
|
35
47
|
|
|
36
|
-
const
|
|
48
|
+
const signMessage: SignMessage = (transport, opts) => {
|
|
37
49
|
const { currency, verify } = opts;
|
|
38
|
-
const signMessage = perFamily[currency.family];
|
|
50
|
+
const signMessage = perFamily[currency.family].signMessage;
|
|
39
51
|
invariant(signMessage, `signMessage is not implemented for ${currency.id}`);
|
|
40
52
|
return signMessage(transport, opts)
|
|
41
53
|
.then((result) => {
|
|
@@ -87,7 +99,7 @@ export const signMessageExec = ({
|
|
|
87
99
|
deviceId,
|
|
88
100
|
}: Input): Observable<Result> => {
|
|
89
101
|
const result: Observable<Result> = withDevice(deviceId)((transport) =>
|
|
90
|
-
from(
|
|
102
|
+
from(signMessage(transport, request.message))
|
|
91
103
|
);
|
|
92
104
|
return result;
|
|
93
105
|
};
|
|
@@ -99,8 +111,10 @@ const initialState: BaseState = {
|
|
|
99
111
|
};
|
|
100
112
|
|
|
101
113
|
export const createAction = (
|
|
102
|
-
connectAppExec: (
|
|
103
|
-
|
|
114
|
+
connectAppExec: (
|
|
115
|
+
connectAppInput: ConnectAppInput
|
|
116
|
+
) => Observable<ConnectAppEvent>,
|
|
117
|
+
signMessage: (input: Input) => Observable<Result> = signMessageExec
|
|
104
118
|
) => {
|
|
105
119
|
const useHook = (
|
|
106
120
|
reduxDevice: Device | null | undefined,
|
|
@@ -175,4 +189,4 @@ export const createAction = (
|
|
|
175
189
|
}),
|
|
176
190
|
};
|
|
177
191
|
};
|
|
178
|
-
export default
|
|
192
|
+
export default signMessage;
|
|
@@ -17,4 +17,7 @@ export type MessageData = {
|
|
|
17
17
|
message: string;
|
|
18
18
|
rawMessage: string;
|
|
19
19
|
};
|
|
20
|
-
export type
|
|
20
|
+
export type SignMessage = (
|
|
21
|
+
transport: Transport,
|
|
22
|
+
message: MessageData
|
|
23
|
+
) => Promise<Result>;
|
|
@@ -39,7 +39,7 @@ export type WCCallRequest =
|
|
|
39
39
|
method: "send" | "sign";
|
|
40
40
|
data: Transaction;
|
|
41
41
|
};
|
|
42
|
-
type Parser = (
|
|
42
|
+
type Parser = (account: Account, payload: WCPayload) => Promise<WCCallRequest>;
|
|
43
43
|
export const parseCallRequest: Parser = async (account, payload) => {
|
|
44
44
|
let wcTransactionData, bridge, transaction, message, rawMessage, hashes;
|
|
45
45
|
|
|
@@ -52,12 +52,11 @@ export const parseCallRequest: Parser = async (account, payload) => {
|
|
|
52
52
|
|
|
53
53
|
// @dev: Today, `eth_signTypedData` is versionned. We can't only check `eth_signTypedData`
|
|
54
54
|
// This regex matches `eth_signTypedData` and `eth_signTypedData_v[0-9]`
|
|
55
|
+
// https://docs.metamask.io/guide/signing-data.html
|
|
55
56
|
case payload.method.match(/eth_signTypedData(_v.)?$/)?.input:
|
|
56
57
|
message = JSON.parse(payload.params[1]);
|
|
57
58
|
hashes = {
|
|
58
|
-
// $FlowFixMe
|
|
59
59
|
domainHash: bufferToHex(domainHash(message)),
|
|
60
|
-
// $FlowFixMe
|
|
61
60
|
messageHash: bufferToHex(messageHash(message)),
|
|
62
61
|
};
|
|
63
62
|
case "eth_sign":
|
|
@@ -67,7 +66,6 @@ export const parseCallRequest: Parser = async (account, payload) => {
|
|
|
67
66
|
stringHash:
|
|
68
67
|
"0x" +
|
|
69
68
|
sha("sha256")
|
|
70
|
-
// $FlowFixMe
|
|
71
69
|
.update(Buffer.from(payload.params[1].slice(2), "hex"))
|
|
72
70
|
.digest("hex"),
|
|
73
71
|
};
|
|
@@ -76,16 +74,10 @@ export const parseCallRequest: Parser = async (account, payload) => {
|
|
|
76
74
|
message || Buffer.from(payload.params[0].slice(2), "hex").toString();
|
|
77
75
|
rawMessage = rawMessage || payload.params[0];
|
|
78
76
|
hashes = hashes || {
|
|
79
|
-
stringHash:
|
|
80
|
-
"0x" +
|
|
81
|
-
sha("sha256")
|
|
82
|
-
// $FlowFixMe
|
|
83
|
-
.update(message)
|
|
84
|
-
.digest("hex"),
|
|
77
|
+
stringHash: "0x" + sha("sha256").update(message).digest("hex"),
|
|
85
78
|
};
|
|
86
79
|
return {
|
|
87
80
|
type: "message",
|
|
88
|
-
// $FlowFixMe (can't figure out MessageData | TypedMessageData)
|
|
89
81
|
data: {
|
|
90
82
|
path: account.freshAddressPath,
|
|
91
83
|
message,
|
|
@@ -51,6 +51,7 @@ describe("walletconnect", () => {
|
|
|
51
51
|
})
|
|
52
52
|
).rejects.toThrow("wrong payload");
|
|
53
53
|
});
|
|
54
|
+
|
|
54
55
|
test("should parse personal_sign payloads", async () => {
|
|
55
56
|
expect(
|
|
56
57
|
await parseCallRequest(account, {
|
|
@@ -132,6 +133,7 @@ describe("walletconnect", () => {
|
|
|
132
133
|
type: "message",
|
|
133
134
|
});
|
|
134
135
|
});
|
|
136
|
+
|
|
135
137
|
test("should parse eth_sendTransaction payloads", async () => {
|
|
136
138
|
const raw: WCPayloadTransaction = {
|
|
137
139
|
data: "0x",
|