@ledgerhq/live-common 34.32.0 → 34.33.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/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +7 -0
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/families/cosmos/datasets/babylon.d.ts.map +1 -1
- package/lib/families/cosmos/datasets/babylon.js +24 -20
- package/lib/families/cosmos/datasets/babylon.js.map +1 -1
- package/lib/families/solana/bridge/mock.d.ts.map +1 -1
- package/lib/families/solana/bridge/mock.js +7 -0
- package/lib/families/solana/bridge/mock.js.map +1 -1
- package/lib/families/solana/config.d.ts.map +1 -1
- package/lib/families/solana/config.js +1 -0
- package/lib/families/solana/config.js.map +1 -1
- package/lib/families/solana/setup.js +3 -3
- package/lib/families/solana/setup.js.map +1 -1
- package/lib/families/solana/setup.test.js +19 -5
- package/lib/families/solana/setup.test.js.map +1 -1
- package/lib/hw/actions/transaction.d.ts +1 -0
- package/lib/hw/actions/transaction.d.ts.map +1 -1
- package/lib/hw/actions/transaction.js +5 -0
- package/lib/hw/actions/transaction.js.map +1 -1
- package/lib/wallet-api/react.d.ts +1 -0
- package/lib/wallet-api/react.d.ts.map +1 -1
- package/lib/wallet-api/react.js +2 -1
- package/lib/wallet-api/react.js.map +1 -1
- package/lib/wallet-api/useDappLogic.d.ts.map +1 -1
- package/lib/wallet-api/useDappLogic.js +4 -0
- package/lib/wallet-api/useDappLogic.js.map +1 -1
- package/lib-es/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.js +7 -0
- package/lib-es/exchange/swap/completeExchange.js.map +1 -1
- package/lib-es/families/cosmos/datasets/babylon.d.ts.map +1 -1
- package/lib-es/families/cosmos/datasets/babylon.js +24 -20
- package/lib-es/families/cosmos/datasets/babylon.js.map +1 -1
- package/lib-es/families/solana/bridge/mock.d.ts.map +1 -1
- package/lib-es/families/solana/bridge/mock.js +7 -0
- package/lib-es/families/solana/bridge/mock.js.map +1 -1
- package/lib-es/families/solana/config.d.ts.map +1 -1
- package/lib-es/families/solana/config.js +1 -0
- package/lib-es/families/solana/config.js.map +1 -1
- package/lib-es/families/solana/setup.js +3 -3
- package/lib-es/families/solana/setup.js.map +1 -1
- package/lib-es/families/solana/setup.test.js +19 -5
- package/lib-es/families/solana/setup.test.js.map +1 -1
- package/lib-es/hw/actions/transaction.d.ts +1 -0
- package/lib-es/hw/actions/transaction.d.ts.map +1 -1
- package/lib-es/hw/actions/transaction.js +5 -0
- package/lib-es/hw/actions/transaction.js.map +1 -1
- package/lib-es/wallet-api/react.d.ts +1 -0
- package/lib-es/wallet-api/react.d.ts.map +1 -1
- package/lib-es/wallet-api/react.js +2 -1
- package/lib-es/wallet-api/react.js.map +1 -1
- package/lib-es/wallet-api/useDappLogic.d.ts.map +1 -1
- package/lib-es/wallet-api/useDappLogic.js +4 -0
- package/lib-es/wallet-api/useDappLogic.js.map +1 -1
- package/package.json +57 -57
- package/src/exchange/swap/completeExchange.ts +9 -0
- package/src/families/cosmos/datasets/__snapshots__/babylon.integration.test.ts.snap +17 -98
- package/src/families/cosmos/datasets/babylon.ts +24 -20
- package/src/families/solana/bridge/mock.ts +8 -1
- package/src/families/solana/config.ts +2 -1
- package/src/families/solana/setup.test.ts +22 -6
- package/src/families/solana/setup.ts +4 -4
- package/src/hw/actions/transaction.ts +8 -0
- package/src/wallet-api/react.ts +3 -1
- package/src/wallet-api/useDappLogic.ts +4 -0
- package/lib/families/solana/offchainMessage/format.d.ts +0 -9
- package/lib/families/solana/offchainMessage/format.d.ts.map +0 -1
- package/lib/families/solana/offchainMessage/format.js +0 -72
- package/lib/families/solana/offchainMessage/format.js.map +0 -1
- package/lib/families/solana/offchainMessage/format.test.d.ts +0 -2
- package/lib/families/solana/offchainMessage/format.test.d.ts.map +0 -1
- package/lib/families/solana/offchainMessage/format.test.js +0 -54
- package/lib/families/solana/offchainMessage/format.test.js.map +0 -1
- package/lib-es/families/solana/offchainMessage/format.d.ts +0 -9
- package/lib-es/families/solana/offchainMessage/format.d.ts.map +0 -1
- package/lib-es/families/solana/offchainMessage/format.js +0 -68
- package/lib-es/families/solana/offchainMessage/format.js.map +0 -1
- package/lib-es/families/solana/offchainMessage/format.test.d.ts +0 -2
- package/lib-es/families/solana/offchainMessage/format.test.d.ts.map +0 -1
- package/lib-es/families/solana/offchainMessage/format.test.js +0 -52
- package/lib-es/families/solana/offchainMessage/format.test.js.map +0 -1
- package/src/families/solana/offchainMessage/format.test.ts +0 -71
- package/src/families/solana/offchainMessage/format.ts +0 -76
@@ -11,13 +11,11 @@ const dataset: CurrenciesData<Transaction> = {
|
|
11
11
|
name: "babylon seed 1",
|
12
12
|
apdus: `
|
13
13
|
=> 55040000180362626e2c00008076000080000000800000000000000000
|
14
|
-
<=
|
14
|
+
<= 03cd9e27aa78eddce3fda5f8050db35196b188d80d10bd04aab15e5669defee8b062626e3175777077733037376130613970636c61707633663266796a3575306d6c683665776d6473386e9000
|
15
15
|
=> 55040000180362626e2c00008076000080000000800000000000000000
|
16
|
-
<=
|
16
|
+
<= 03cd9e27aa78eddce3fda5f8050db35196b188d80d10bd04aab15e5669defee8b062626e3175777077733037376130613970636c61707633663266796a3575306d6c683665776d6473386e9000
|
17
17
|
=> 55040000180362626e2c00008076000080010000800000000000000000
|
18
|
-
<=
|
19
|
-
=> 55040000180362626e2c00008076000080020000800000000000000000
|
20
|
-
<= 038ff98278402aa3e46ccfd020561dc9724ab63d7179ca507c8154b5257c7d520062626e3163676336393661793270673664346763656a656b3279386c6136366a37653579787830386d689000
|
18
|
+
<= 02b3c7368432b998240a2806eb08a00becd359867ca9cdc94f3eb4ba29a6eb0d7a62626e316a7932387a6e6c6b7034783767663863786c6a366e326e676b726b78683279793774326d39799000
|
21
19
|
`,
|
22
20
|
},
|
23
21
|
],
|
@@ -25,36 +23,42 @@ const dataset: CurrenciesData<Transaction> = {
|
|
25
23
|
{
|
26
24
|
FIXME_tests: ["balance is sum of ops", "pendingOperations are cleaned up"],
|
27
25
|
raw: {
|
28
|
-
id: "js:2:babylon:
|
29
|
-
seedIdentifier: "
|
30
|
-
|
26
|
+
id: "js:2:babylon:bbn1uwpws077a0a9pclapv3f2fyj5u0mlh6ewmds8n:",
|
27
|
+
seedIdentifier: "03cd9e27aa78eddce3fda5f8050db35196b188d80d10bd04aab15e5669defee8b0",
|
28
|
+
used: true,
|
31
29
|
derivationMode: "",
|
32
30
|
index: 0,
|
33
|
-
freshAddress: "
|
31
|
+
freshAddress: "bbn1uwpws077a0a9pclapv3f2fyj5u0mlh6ewmds8n",
|
34
32
|
freshAddressPath: "44'/118'/0'/0/0",
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
spendableBalance: "40699912",
|
33
|
+
blockHeight: 207592,
|
34
|
+
creationDate: "2025-05-02T10:23:08.000Z",
|
35
|
+
operationsCount: 1,
|
39
36
|
operations: [],
|
40
|
-
operationsCount: 2,
|
41
37
|
pendingOperations: [],
|
42
38
|
currencyId: "babylon",
|
43
|
-
lastSyncDate: "",
|
44
|
-
|
39
|
+
lastSyncDate: "2025-05-02T10:24:44.245Z",
|
40
|
+
balance: "1000000",
|
41
|
+
spendableBalance: "1000000",
|
42
|
+
balanceHistoryCache: {
|
43
|
+
HOUR: { balances: [0], latestDate: 1746180000000 },
|
44
|
+
DAY: { balances: [0], latestDate: 1746136800000 },
|
45
|
+
WEEK: { balances: [0], latestDate: 1745704800000 },
|
46
|
+
},
|
47
|
+
xpub: "bbn1uwpws077a0a9pclapv3f2fyj5u0mlh6ewmds8n",
|
48
|
+
swapHistory: [],
|
45
49
|
},
|
46
50
|
transactions: [
|
47
51
|
{
|
48
52
|
name: "Normal transaction",
|
49
53
|
transaction: fromTransactionRaw({
|
50
|
-
amount: "
|
54
|
+
amount: "1000",
|
51
55
|
recipient: "bbn1vh34djka7ug2gww9njrsmmr7emj3dx3paz5sj4",
|
52
56
|
useAllAmount: false,
|
53
57
|
family: "cosmos",
|
54
58
|
mode: "send",
|
55
59
|
networkInfo: null,
|
56
|
-
fees: "
|
57
|
-
gas: "
|
60
|
+
fees: "238",
|
61
|
+
gas: "118993",
|
58
62
|
validators: [],
|
59
63
|
memo: "",
|
60
64
|
sourceValidator: "",
|
@@ -62,7 +66,7 @@ const dataset: CurrenciesData<Transaction> = {
|
|
62
66
|
expectedStatus: () => ({
|
63
67
|
errors: {},
|
64
68
|
warnings: {},
|
65
|
-
amount: BigNumber("
|
69
|
+
amount: BigNumber("1000"),
|
66
70
|
}),
|
67
71
|
},
|
68
72
|
],
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
} from "@ledgerhq/coin-solana/network/index";
|
9
9
|
import { Functions } from "@ledgerhq/coin-solana/utils";
|
10
10
|
import { makeBridges } from "@ledgerhq/coin-solana/bridge/bridge";
|
11
|
-
import { SolanaSigner } from "@ledgerhq/coin-solana/signer";
|
11
|
+
import { PubKeyDisplayMode, SolanaSigner } from "@ledgerhq/coin-solana/signer";
|
12
12
|
import { makeLRUCache, minutes } from "@ledgerhq/live-network/cache";
|
13
13
|
import { Message } from "@solana/web3.js";
|
14
14
|
import { flow, isArray, isEqual, isObject, isUndefined, mapValues, omitBy } from "lodash/fp";
|
@@ -84,8 +84,15 @@ function createMockDataForAPI() {
|
|
84
84
|
};
|
85
85
|
}
|
86
86
|
|
87
|
+
const APP_VERSION = "1.7.1";
|
87
88
|
function getMockedAPIs() {
|
88
89
|
const signer = {
|
90
|
+
getAppConfiguration: () =>
|
91
|
+
Promise.resolve({
|
92
|
+
version: APP_VERSION,
|
93
|
+
blindSigningEnabled: false,
|
94
|
+
pubKeyDisplayMode: PubKeyDisplayMode.LONG,
|
95
|
+
}),
|
89
96
|
getAddress: (_path: string, _display?: boolean) =>
|
90
97
|
Promise.resolve({ address: Buffer.from("") }),
|
91
98
|
signTransaction: (_path: string, _txBuffer: Buffer) =>
|
@@ -1,11 +1,23 @@
|
|
1
1
|
import Solana from "@ledgerhq/hw-app-solana";
|
2
2
|
import Transport from "@ledgerhq/hw-transport";
|
3
3
|
import { Account, AnyMessage } from "@ledgerhq/types-live";
|
4
|
+
import { PubKeyDisplayMode } from "@ledgerhq/coin-solana/signer";
|
5
|
+
import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
|
4
6
|
import { messageSigner } from "./setup";
|
7
|
+
import { solanaConfig } from "./config";
|
5
8
|
|
6
9
|
const SIGNATURE =
|
7
10
|
"97fb71bae8971e272b17a464dc2f76995de2da9fc5d40e369edc43b0c3f7c601c4e5a60bb7c6ac69671120c381ce5cab7a06f53eb802e3ac555066455f2cbd05";
|
8
11
|
|
12
|
+
const APP_VERSION = "1.8.2";
|
13
|
+
const getAppConfigurationMock = jest.fn(() => {
|
14
|
+
return Promise.resolve({
|
15
|
+
version: APP_VERSION,
|
16
|
+
blindSigningEnabled: false,
|
17
|
+
pubKeyDisplayMode: PubKeyDisplayMode.LONG,
|
18
|
+
});
|
19
|
+
});
|
20
|
+
|
9
21
|
const signOffchainMessageMock = jest.fn(() =>
|
10
22
|
Promise.resolve({
|
11
23
|
signature: SIGNATURE,
|
@@ -14,18 +26,24 @@ const signOffchainMessageMock = jest.fn(() =>
|
|
14
26
|
|
15
27
|
jest.mock("@ledgerhq/hw-app-solana", () => {
|
16
28
|
return jest.fn().mockImplementation(() => {
|
17
|
-
return {
|
29
|
+
return {
|
30
|
+
signOffchainMessage: signOffchainMessageMock,
|
31
|
+
getAppConfiguration: getAppConfigurationMock,
|
32
|
+
};
|
18
33
|
});
|
19
34
|
});
|
20
35
|
|
36
|
+
LiveConfig.setConfig(solanaConfig);
|
37
|
+
|
21
38
|
describe("Testing setup on Solana", () => {
|
22
39
|
describe("Testing message signer", () => {
|
23
40
|
it("should call hardware for off-chain message signature", async () => {
|
24
41
|
const freshAddressPath = "44'/60'/0'/0/0";
|
42
|
+
const freshAddress = "8DpKDisipx6f76cEmuGvCX9TrA3SjeR76HaTRePxHBDe";
|
25
43
|
const message = "4c6f6e67204f66662d436861696e2054657374204d6573736167652e";
|
26
44
|
const result = await messageSigner.signMessage(
|
27
45
|
{} as Transport,
|
28
|
-
{ freshAddressPath: freshAddressPath } as Account,
|
46
|
+
{ freshAddressPath: freshAddressPath, freshAddress } as Account,
|
29
47
|
{ message: message } as AnyMessage,
|
30
48
|
);
|
31
49
|
|
@@ -35,10 +53,8 @@ describe("Testing setup on Solana", () => {
|
|
35
53
|
const args = signOffchainMessageMock.mock.calls[0] as unknown[];
|
36
54
|
expect(args[0]).toEqual(freshAddressPath);
|
37
55
|
|
38
|
-
|
39
|
-
|
40
|
-
expect((args[1] as Buffer).toString("hex")).toMatch(
|
41
|
-
/^ff736f6c616e61206f6666636861696e000138003463366636653637323034663636363632643433363836313639366532303534363537333734323034643635373337333631363736353265$/,
|
56
|
+
expect((args[1] as Buffer).toString("hex")).toEqual(
|
57
|
+
"ff736f6c616e61206f6666636861696e00000000000000000000000000000000000000000000000000000000000000000000016b4a46c53959cac0eff146ab323053cfc503321adfd453a7c67c91a24be0323538003463366636653637323034663636363632643433363836313639366532303534363537333734323034643635373337333631363736353265",
|
42
58
|
);
|
43
59
|
|
44
60
|
expect(result.signature).toEqual("0x" + SIGNATURE);
|
@@ -23,10 +23,9 @@ import {
|
|
23
23
|
import { LatestFirmwareVersionRequired } from "../../errors";
|
24
24
|
import type { Resolver } from "../../hw/getAddress/types";
|
25
25
|
import { getCurrencyConfiguration } from "../../config";
|
26
|
-
import { SolanaCoinConfig } from "@ledgerhq/coin-solana/
|
26
|
+
import { SolanaCoinConfig } from "@ledgerhq/coin-solana/config";
|
27
27
|
import { getCryptoCurrencyById } from "../../currencies";
|
28
28
|
import { signMessage } from "@ledgerhq/coin-solana/hw-signMessage";
|
29
|
-
import { toOffChainMessage } from "./offchainMessage/format";
|
30
29
|
|
31
30
|
const TRUSTED_NAME_MIN_VERSION = "1.7.1";
|
32
31
|
const MANAGER_APP_NAME = "Solana";
|
@@ -47,6 +46,7 @@ function isPKIUnsupportedError(err: unknown): err is TransportStatusError {
|
|
47
46
|
const createSigner: CreateSigner<SolanaSigner> = (transport: Transport) => {
|
48
47
|
const app = new Solana(transport);
|
49
48
|
return {
|
49
|
+
getAppConfiguration: app.getAppConfiguration,
|
50
50
|
getAddress: app.getAddress,
|
51
51
|
signTransaction: async (path, tx, resolution) => {
|
52
52
|
if (resolution) {
|
@@ -99,8 +99,8 @@ const createSigner: CreateSigner<SolanaSigner> = (transport: Transport) => {
|
|
99
99
|
|
100
100
|
return app.signTransaction(path, tx);
|
101
101
|
},
|
102
|
-
signMessage: (path: string,
|
103
|
-
return app.signOffchainMessage(path,
|
102
|
+
signMessage: (path: string, messageHex: string) => {
|
103
|
+
return app.signOffchainMessage(path, Buffer.from(messageHex, "hex"));
|
104
104
|
},
|
105
105
|
};
|
106
106
|
};
|
@@ -27,6 +27,7 @@ type State = {
|
|
27
27
|
deviceStreamingProgress: number | null | undefined;
|
28
28
|
transactionSignError: Error | null | undefined;
|
29
29
|
transactionChecksOptInTriggered: boolean;
|
30
|
+
transactionChecksOptIn: boolean | null;
|
30
31
|
manifestId?: string;
|
31
32
|
manifestName?: string;
|
32
33
|
};
|
@@ -83,6 +84,7 @@ const initialState = {
|
|
83
84
|
deviceStreamingProgress: null,
|
84
85
|
transactionSignError: null,
|
85
86
|
transactionChecksOptInTriggered: false,
|
87
|
+
transactionChecksOptIn: null,
|
86
88
|
};
|
87
89
|
|
88
90
|
const reducer = (state: State, e: Event): State => {
|
@@ -111,6 +113,12 @@ const reducer = (state: State, e: Event): State => {
|
|
111
113
|
case "transaction-checks-opt-in-triggered":
|
112
114
|
return { ...state, transactionChecksOptInTriggered: true };
|
113
115
|
|
116
|
+
case "transaction-checks-opt-in":
|
117
|
+
return { ...state, transactionChecksOptIn: true };
|
118
|
+
|
119
|
+
case "transaction-checks-opt-out":
|
120
|
+
return { ...state, transactionChecksOptIn: false };
|
121
|
+
|
114
122
|
default:
|
115
123
|
return state;
|
116
124
|
}
|
package/src/wallet-api/react.ts
CHANGED
@@ -143,6 +143,7 @@ export interface UiHook {
|
|
143
143
|
"message.sign": (params: {
|
144
144
|
account: AccountLike;
|
145
145
|
message: AnyMessage;
|
146
|
+
options: Parameters<WalletHandlers["message.sign"]>[0]["options"];
|
146
147
|
onSuccess: (signature: string) => void;
|
147
148
|
onError: (error: Error) => void;
|
148
149
|
onCancel: () => void;
|
@@ -431,7 +432,7 @@ export function useWalletAPIServer({
|
|
431
432
|
useEffect(() => {
|
432
433
|
if (!uiMessageSign) return;
|
433
434
|
|
434
|
-
server.setHandler("message.sign", ({ account, message }) =>
|
435
|
+
server.setHandler("message.sign", ({ account, message, options }) =>
|
435
436
|
signMessageLogic(
|
436
437
|
{ manifest, accounts, tracking },
|
437
438
|
account.id,
|
@@ -442,6 +443,7 @@ export function useWalletAPIServer({
|
|
442
443
|
return uiMessageSign({
|
443
444
|
account,
|
444
445
|
message,
|
446
|
+
options,
|
445
447
|
onSuccess: signature => {
|
446
448
|
if (done) return;
|
447
449
|
done = true;
|
@@ -604,10 +604,12 @@ export function useDappLogic({
|
|
604
604
|
message,
|
605
605
|
);
|
606
606
|
|
607
|
+
const options = nanoApp ? { hwAppId: nanoApp, dependencies: dependencies } : undefined;
|
607
608
|
const signedMessage = await new Promise<string>((resolve, reject) =>
|
608
609
|
uiHook["message.sign"]({
|
609
610
|
account: currentAccount,
|
610
611
|
message: formattedMessage,
|
612
|
+
options,
|
611
613
|
onSuccess: resolve,
|
612
614
|
onError: reject,
|
613
615
|
onCancel: () => {
|
@@ -649,10 +651,12 @@ export function useDappLogic({
|
|
649
651
|
Buffer.from(message).toString("hex"),
|
650
652
|
);
|
651
653
|
|
654
|
+
const options = nanoApp ? { hwAppId: nanoApp, dependencies: dependencies } : undefined;
|
652
655
|
const signedMessage = await new Promise<string>((resolve, reject) =>
|
653
656
|
uiHook["message.sign"]({
|
654
657
|
account: currentAccount,
|
655
658
|
message: formattedMessage,
|
659
|
+
options,
|
656
660
|
onSuccess: resolve,
|
657
661
|
onError: reject,
|
658
662
|
onCancel: () => {
|
@@ -1,9 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Major functions of this file have been taken from https://github.com/LedgerHQ/app-solana/blob/develop/examples/example-sign.js
|
3
|
-
* Thus, have not been fully tested (unit tests + manual tests)
|
4
|
-
* We should add more tests in the future
|
5
|
-
*/
|
6
|
-
/// <reference types="node" />
|
7
|
-
/// <reference types="node" />
|
8
|
-
export declare function toOffChainMessage(message: string): Buffer;
|
9
|
-
//# sourceMappingURL=format.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;AAqEH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/**
|
3
|
-
* Major functions of this file have been taken from https://github.com/LedgerHQ/app-solana/blob/develop/examples/example-sign.js
|
4
|
-
* Thus, have not been fully tested (unit tests + manual tests)
|
5
|
-
* We should add more tests in the future
|
6
|
-
*/
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
8
|
-
exports.toOffChainMessage = void 0;
|
9
|
-
// Max off-chain message length supported by Ledger
|
10
|
-
const OFFCM_MAX_LEDGER_LEN = 1212;
|
11
|
-
// Max length of version 0 off-chain message
|
12
|
-
const OFFCM_MAX_V0_LEN = 65515;
|
13
|
-
const SOLANA_HEADER_BUFFER = Buffer.concat([Buffer.from([255]), Buffer.from("solana offchain")]);
|
14
|
-
function isPrintableASCII(buffer) {
|
15
|
-
return (buffer &&
|
16
|
-
buffer.every(element => {
|
17
|
-
return element >= 0x20 && element <= 0x7e;
|
18
|
-
}));
|
19
|
-
}
|
20
|
-
function isUTF8(buffer) {
|
21
|
-
try {
|
22
|
-
new TextDecoder("utf8", { fatal: true }).decode(Buffer.from(buffer));
|
23
|
-
return true;
|
24
|
-
}
|
25
|
-
catch {
|
26
|
-
return false;
|
27
|
-
}
|
28
|
-
}
|
29
|
-
function findMessageFormat(message) {
|
30
|
-
if (Object.prototype.toString.call(message) !== "[object Uint8Array]") {
|
31
|
-
if (isUTF8(message)) {
|
32
|
-
return 1;
|
33
|
-
}
|
34
|
-
return undefined;
|
35
|
-
}
|
36
|
-
if (message.length <= OFFCM_MAX_LEDGER_LEN) {
|
37
|
-
if (isPrintableASCII(message)) {
|
38
|
-
return 0;
|
39
|
-
}
|
40
|
-
else if (isUTF8(message)) {
|
41
|
-
return 1;
|
42
|
-
}
|
43
|
-
}
|
44
|
-
else if (message.length <= OFFCM_MAX_V0_LEN) {
|
45
|
-
if (isUTF8(message)) {
|
46
|
-
return 2;
|
47
|
-
}
|
48
|
-
}
|
49
|
-
return undefined;
|
50
|
-
}
|
51
|
-
function writeMessageLength(buffer, length, offset) {
|
52
|
-
buffer.writeUInt16LE(length, offset);
|
53
|
-
}
|
54
|
-
function writeMessageFormat(message, buffer, offset) {
|
55
|
-
const messageFormat = findMessageFormat(message) ?? 0;
|
56
|
-
return buffer.writeUInt8(messageFormat, offset);
|
57
|
-
}
|
58
|
-
function writeVersion(buffer) {
|
59
|
-
return buffer.writeUInt8(0);
|
60
|
-
}
|
61
|
-
function toMessageInformation(message) {
|
62
|
-
const buffer = Buffer.alloc(4);
|
63
|
-
let offset = writeVersion(buffer);
|
64
|
-
offset = writeMessageFormat(message, buffer, offset);
|
65
|
-
writeMessageLength(buffer, Buffer.from(message).length, offset);
|
66
|
-
return buffer;
|
67
|
-
}
|
68
|
-
function toOffChainMessage(message) {
|
69
|
-
return Buffer.concat([SOLANA_HEADER_BUFFER, toMessageInformation(message), Buffer.from(message)]);
|
70
|
-
}
|
71
|
-
exports.toOffChainMessage = toOffChainMessage;
|
72
|
-
//# sourceMappingURL=format.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.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"],"names":[],"mappings":""}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const format_1 = require("./format");
|
4
|
-
// hexadecimal of \xffsolana offchain
|
5
|
-
const SOLANA_HEADER = "ff736f6c616e61206f6666636861696e";
|
6
|
-
describe("test", () => {
|
7
|
-
const cases = [
|
8
|
-
{
|
9
|
-
value: "hello",
|
10
|
-
hexadecimal: "68656c6c6f",
|
11
|
-
messageFormat: "01",
|
12
|
-
messageLength: "05",
|
13
|
-
},
|
14
|
-
{
|
15
|
-
value: "bonjour",
|
16
|
-
hexadecimal: "626f6e6a6f7572",
|
17
|
-
messageFormat: "01",
|
18
|
-
messageLength: "07",
|
19
|
-
},
|
20
|
-
{
|
21
|
-
value: "salam",
|
22
|
-
hexadecimal: "73616c616d",
|
23
|
-
messageFormat: "01",
|
24
|
-
messageLength: "05",
|
25
|
-
},
|
26
|
-
{
|
27
|
-
value: "Long Off-Chain Test Message.",
|
28
|
-
hexadecimal: "4c6f6e67204f66662d436861696e2054657374204d6573736167652e",
|
29
|
-
messageFormat: "01",
|
30
|
-
messageLength: "1c",
|
31
|
-
},
|
32
|
-
{
|
33
|
-
value: "Тестовое сообщение в формате UTF-8",
|
34
|
-
hexadecimal: "d0a2d0b5d181d182d0bed0b2d0bed0b520d181d0bed0bed0b1d189d0b5d0bdd0b8d0b520d0b220d184d0bed180d0bcd0b0d182d0b5205554462d38",
|
35
|
-
messageFormat: "01",
|
36
|
-
messageLength: "3b",
|
37
|
-
},
|
38
|
-
];
|
39
|
-
it.each(cases)('should format message "$value" correctly for off-chain signing on Solana', ({ value, hexadecimal, messageFormat, messageLength }) => {
|
40
|
-
const result = (0, format_1.toOffChainMessage)(value).toString("hex");
|
41
|
-
expect(result.startsWith(SOLANA_HEADER)).toBe(true);
|
42
|
-
const version = result.substring(SOLANA_HEADER.length, SOLANA_HEADER.length + 2);
|
43
|
-
expect(version).toEqual("00");
|
44
|
-
const format = result.substring(SOLANA_HEADER.length + 2, SOLANA_HEADER.length + 4);
|
45
|
-
expect(format).toEqual(messageFormat);
|
46
|
-
const length = result.substring(SOLANA_HEADER.length + 4, SOLANA_HEADER.length + 6);
|
47
|
-
expect(length).toEqual(messageLength);
|
48
|
-
const remaining = result.substring(SOLANA_HEADER.length + 6, SOLANA_HEADER.length + 8);
|
49
|
-
expect(remaining).toEqual("00");
|
50
|
-
// message should end with message parameter
|
51
|
-
expect(result.substring(SOLANA_HEADER.length + 8)).toEqual(hexadecimal);
|
52
|
-
});
|
53
|
-
});
|
54
|
-
//# sourceMappingURL=format.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.test.js","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.test.ts"],"names":[],"mappings":";;AAAA,qCAA6C;AAS7C,qCAAqC;AACrC,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,MAAM,KAAK,GAAkB;QAC3B;YACE,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,YAAY;YACzB,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,gBAAgB;YAC7B,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,YAAY;YACzB,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,8BAA8B;YACrC,WAAW,EAAE,0DAA0D;YACvE,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,oCAAoC;YAC3C,WAAW,EACT,wHAAwH;YAC1H,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;KACF,CAAC;IAEF,EAAE,CAAC,IAAI,CAAC,KA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AC,CAAC"}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Major functions of this file have been taken from https://github.com/LedgerHQ/app-solana/blob/develop/examples/example-sign.js
|
3
|
-
* Thus, have not been fully tested (unit tests + manual tests)
|
4
|
-
* We should add more tests in the future
|
5
|
-
*/
|
6
|
-
/// <reference types="node" />
|
7
|
-
/// <reference types="node" />
|
8
|
-
export declare function toOffChainMessage(message: string): Buffer;
|
9
|
-
//# sourceMappingURL=format.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;AAqEH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Major functions of this file have been taken from https://github.com/LedgerHQ/app-solana/blob/develop/examples/example-sign.js
|
3
|
-
* Thus, have not been fully tested (unit tests + manual tests)
|
4
|
-
* We should add more tests in the future
|
5
|
-
*/
|
6
|
-
// Max off-chain message length supported by Ledger
|
7
|
-
const OFFCM_MAX_LEDGER_LEN = 1212;
|
8
|
-
// Max length of version 0 off-chain message
|
9
|
-
const OFFCM_MAX_V0_LEN = 65515;
|
10
|
-
const SOLANA_HEADER_BUFFER = Buffer.concat([Buffer.from([255]), Buffer.from("solana offchain")]);
|
11
|
-
function isPrintableASCII(buffer) {
|
12
|
-
return (buffer &&
|
13
|
-
buffer.every(element => {
|
14
|
-
return element >= 0x20 && element <= 0x7e;
|
15
|
-
}));
|
16
|
-
}
|
17
|
-
function isUTF8(buffer) {
|
18
|
-
try {
|
19
|
-
new TextDecoder("utf8", { fatal: true }).decode(Buffer.from(buffer));
|
20
|
-
return true;
|
21
|
-
}
|
22
|
-
catch {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
function findMessageFormat(message) {
|
27
|
-
if (Object.prototype.toString.call(message) !== "[object Uint8Array]") {
|
28
|
-
if (isUTF8(message)) {
|
29
|
-
return 1;
|
30
|
-
}
|
31
|
-
return undefined;
|
32
|
-
}
|
33
|
-
if (message.length <= OFFCM_MAX_LEDGER_LEN) {
|
34
|
-
if (isPrintableASCII(message)) {
|
35
|
-
return 0;
|
36
|
-
}
|
37
|
-
else if (isUTF8(message)) {
|
38
|
-
return 1;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
else if (message.length <= OFFCM_MAX_V0_LEN) {
|
42
|
-
if (isUTF8(message)) {
|
43
|
-
return 2;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
return undefined;
|
47
|
-
}
|
48
|
-
function writeMessageLength(buffer, length, offset) {
|
49
|
-
buffer.writeUInt16LE(length, offset);
|
50
|
-
}
|
51
|
-
function writeMessageFormat(message, buffer, offset) {
|
52
|
-
const messageFormat = findMessageFormat(message) ?? 0;
|
53
|
-
return buffer.writeUInt8(messageFormat, offset);
|
54
|
-
}
|
55
|
-
function writeVersion(buffer) {
|
56
|
-
return buffer.writeUInt8(0);
|
57
|
-
}
|
58
|
-
function toMessageInformation(message) {
|
59
|
-
const buffer = Buffer.alloc(4);
|
60
|
-
let offset = writeVersion(buffer);
|
61
|
-
offset = writeMessageFormat(message, buffer, offset);
|
62
|
-
writeMessageLength(buffer, Buffer.from(message).length, offset);
|
63
|
-
return buffer;
|
64
|
-
}
|
65
|
-
export function toOffChainMessage(message) {
|
66
|
-
return Buffer.concat([SOLANA_HEADER_BUFFER, toMessageInformation(message), Buffer.from(message)]);
|
67
|
-
}
|
68
|
-
//# sourceMappingURL=format.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mDAAmD;AACnD,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,4CAA4C;AAC5C,MAAM,gBAAgB,GAAG,KAAK,C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,SAAS,kBAAkB,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc;IACxE,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAe,EAAE,MAAc,EAAE,MAAc;IACzE,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAe;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,GAAG,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.test.ts"],"names":[],"mappings":""}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { toOffChainMessage } from "./format";
|
2
|
-
// hexadecimal of \xffsolana offchain
|
3
|
-
const SOLANA_HEADER = "ff736f6c616e61206f6666636861696e";
|
4
|
-
describe("test", () => {
|
5
|
-
const cases = [
|
6
|
-
{
|
7
|
-
value: "hello",
|
8
|
-
hexadecimal: "68656c6c6f",
|
9
|
-
messageFormat: "01",
|
10
|
-
messageLength: "05",
|
11
|
-
},
|
12
|
-
{
|
13
|
-
value: "bonjour",
|
14
|
-
hexadecimal: "626f6e6a6f7572",
|
15
|
-
messageFormat: "01",
|
16
|
-
messageLength: "07",
|
17
|
-
},
|
18
|
-
{
|
19
|
-
value: "salam",
|
20
|
-
hexadecimal: "73616c616d",
|
21
|
-
messageFormat: "01",
|
22
|
-
messageLength: "05",
|
23
|
-
},
|
24
|
-
{
|
25
|
-
value: "Long Off-Chain Test Message.",
|
26
|
-
hexadecimal: "4c6f6e67204f66662d436861696e2054657374204d6573736167652e",
|
27
|
-
messageFormat: "01",
|
28
|
-
messageLength: "1c",
|
29
|
-
},
|
30
|
-
{
|
31
|
-
value: "Тестовое сообщение в формате UTF-8",
|
32
|
-
hexadecimal: "d0a2d0b5d181d182d0bed0b2d0bed0b520d181d0bed0bed0b1d189d0b5d0bdd0b8d0b520d0b220d184d0bed180d0bcd0b0d182d0b5205554462d38",
|
33
|
-
messageFormat: "01",
|
34
|
-
messageLength: "3b",
|
35
|
-
},
|
36
|
-
];
|
37
|
-
it.each(cases)('should format message "$value" correctly for off-chain signing on Solana', ({ value, hexadecimal, messageFormat, messageLength }) => {
|
38
|
-
const result = toOffChainMessage(value).toString("hex");
|
39
|
-
expect(result.startsWith(SOLANA_HEADER)).toBe(true);
|
40
|
-
const version = result.substring(SOLANA_HEADER.length, SOLANA_HEADER.length + 2);
|
41
|
-
expect(version).toEqual("00");
|
42
|
-
const format = result.substring(SOLANA_HEADER.length + 2, SOLANA_HEADER.length + 4);
|
43
|
-
expect(format).toEqual(messageFormat);
|
44
|
-
const length = result.substring(SOLANA_HEADER.length + 4, SOLANA_HEADER.length + 6);
|
45
|
-
expect(length).toEqual(messageLength);
|
46
|
-
const remaining = result.substring(SOLANA_HEADER.length + 6, SOLANA_HEADER.length + 8);
|
47
|
-
expect(remaining).toEqual("00");
|
48
|
-
// message should end with message parameter
|
49
|
-
expect(result.substring(SOLANA_HEADER.length + 8)).toEqual(hexadecimal);
|
50
|
-
});
|
51
|
-
});
|
52
|
-
//# sourceMappingURL=format.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"format.test.js","sourceRoot":"","sources":["../../../../src/families/solana/offchainMessage/format.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAS7C,qCAAqC;AACrC,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,MAAM,KAAK,GAAkB;QAC3B;YACE,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,YAAY;YACzB,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,gBAAgB;YAC7B,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,YAAY;YACzB,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,8BAA8B;YACrC,WAAW,EAAE,0DAA0D;YACvE,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;QACD;YACE,KAAK,EAAE,oCAAoC;YAC3C,WAAW,EACT,wHAAwH;YAC1H,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;SACpB;KACF,CAAC;IAEF,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CACZ,0EAA0E,EAC1E,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,EAAE,EAAE;QACvD,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,QAAQ,CA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