@onekeyfe/hd-core 1.2.2-alpha.14 → 1.2.2-alpha.15
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/__tests__/device-lifecycle-events.test.ts +6 -8
- package/__tests__/open-wallet-session.test.ts +0 -53
- package/__tests__/protocol-v2.test.ts +2 -0
- package/__tests__/sol-sign-offchain-message.test.ts +73 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/index.d.ts +6 -2
- package/dist/index.js +70 -31
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/solSignOffchainMessage.d.ts +2 -0
- package/dist/types/api/solSignOffchainMessage.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/UploadPortfolio.ts +1 -0
- package/src/api/solana/SolSignOffchainMessage.ts +63 -4
- package/src/core/index.ts +2 -3
- package/src/data/messages/messages-protocol-v2.json +8 -5
- package/src/data/messages/messages.json +8 -5
- package/src/protocols/protocol-v2/walletSession.ts +2 -7
- package/src/types/api/solSignOffchainMessage.ts +3 -0
|
@@ -367,7 +367,6 @@ describe('public device lifecycle events', () => {
|
|
|
367
367
|
[HardwareErrorCode.PollingTimeout, false],
|
|
368
368
|
[HardwareErrorCode.BleDeviceBondError, false],
|
|
369
369
|
[HardwareErrorCode.BlePeerRemovedPairingInformation, false],
|
|
370
|
-
[HardwareErrorCode.BleBondInvalid, false],
|
|
371
370
|
] as const)('retries a BLE connection error with error code %s: %s', (errorCode, expected) => {
|
|
372
371
|
const method = { payload: { connectProtocol: 'V2' } } as never;
|
|
373
372
|
const error = {
|
|
@@ -379,16 +378,15 @@ describe('public device lifecycle events', () => {
|
|
|
379
378
|
});
|
|
380
379
|
|
|
381
380
|
test.each([
|
|
382
|
-
['V2',
|
|
383
|
-
['
|
|
384
|
-
[
|
|
385
|
-
[undefined, HardwareErrorCode.BleBondInvalid, false],
|
|
381
|
+
['V2', true],
|
|
382
|
+
['V1', false],
|
|
383
|
+
[undefined, false],
|
|
386
384
|
] as const)(
|
|
387
|
-
'treats
|
|
388
|
-
(connectProtocol,
|
|
385
|
+
'treats peer-removed pairing as terminal only for Protocol %s: %s',
|
|
386
|
+
(connectProtocol, expected) => {
|
|
389
387
|
const method = { payload: { connectProtocol } } as never;
|
|
390
388
|
const error = {
|
|
391
|
-
errorCode,
|
|
389
|
+
errorCode: HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
392
390
|
};
|
|
393
391
|
|
|
394
392
|
expect(isProtocolV2PeerRemovedPairingError(method, error)).toBe(expected);
|
|
@@ -2080,59 +2080,6 @@ describe('openWalletSession', () => {
|
|
|
2080
2080
|
expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('renewed-session');
|
|
2081
2081
|
});
|
|
2082
2082
|
|
|
2083
|
-
test('recovers the current Attach PIN wallet when the cached session is invalid', async () => {
|
|
2084
|
-
const typedCall = jest
|
|
2085
|
-
.fn()
|
|
2086
|
-
.mockResolvedValueOnce({ message: { version: 2 } })
|
|
2087
|
-
.mockRejectedValueOnce(
|
|
2088
|
-
Object.assign(new Error('Invalid session'), {
|
|
2089
|
-
errorCode: HardwareErrorCode.WalletSessionInvalid,
|
|
2090
|
-
})
|
|
2091
|
-
)
|
|
2092
|
-
.mockResolvedValueOnce({
|
|
2093
|
-
message: {
|
|
2094
|
-
btc_test_address: 'hidden-state',
|
|
2095
|
-
session_id: 'renewed-session',
|
|
2096
|
-
},
|
|
2097
|
-
});
|
|
2098
|
-
const promptPassphrase = jest.fn();
|
|
2099
|
-
const method = new OpenWalletSession({
|
|
2100
|
-
payload: {
|
|
2101
|
-
method: 'openWalletSession',
|
|
2102
|
-
connectId: 'connect-id',
|
|
2103
|
-
mode: 'resume-hidden',
|
|
2104
|
-
deviceId: 'device-1',
|
|
2105
|
-
passphraseState: 'hidden-state',
|
|
2106
|
-
},
|
|
2107
|
-
});
|
|
2108
|
-
method.init();
|
|
2109
|
-
deviceWalletSessionStore.set('device-1', 'hidden-state', 'expired-session');
|
|
2110
|
-
const device = createDevice({ unlockedAttachPin: true, typedCall, promptPassphrase });
|
|
2111
|
-
method.device = device as any;
|
|
2112
|
-
|
|
2113
|
-
await expect(method.run()).resolves.toEqual({
|
|
2114
|
-
protocol: 'V2',
|
|
2115
|
-
walletType: 'hidden',
|
|
2116
|
-
deviceId: 'device-1',
|
|
2117
|
-
passphraseState: 'hidden-state',
|
|
2118
|
-
resumed: false,
|
|
2119
|
-
});
|
|
2120
|
-
expect(typedCall.mock.calls.filter(call => call[0] === 'DeviceSessionGet')).toEqual([
|
|
2121
|
-
[
|
|
2122
|
-
'DeviceSessionGet',
|
|
2123
|
-
'DeviceSession',
|
|
2124
|
-
{
|
|
2125
|
-
session_id: 'expired-session',
|
|
2126
|
-
btc_test_address: 'hidden-state',
|
|
2127
|
-
},
|
|
2128
|
-
],
|
|
2129
|
-
['DeviceSessionGet', 'DeviceSession', {}],
|
|
2130
|
-
]);
|
|
2131
|
-
expect(promptPassphrase).not.toHaveBeenCalled();
|
|
2132
|
-
expect(device.lockDevice).not.toHaveBeenCalled();
|
|
2133
|
-
expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('renewed-session');
|
|
2134
|
-
});
|
|
2135
|
-
|
|
2136
2083
|
test('selects the expected hidden wallet when Protocol V2 has no cached session', async () => {
|
|
2137
2084
|
const typedCall = jest
|
|
2138
2085
|
.fn()
|
|
@@ -555,7 +555,9 @@ describe('UploadPortfolio', () => {
|
|
|
555
555
|
method.init();
|
|
556
556
|
await method.run();
|
|
557
557
|
|
|
558
|
+
expect(method.unlockPolicy).toBe('none');
|
|
558
559
|
expect(method.protocolV2UiMode).toBe('auto');
|
|
560
|
+
expect(method.protocolV2UiInteraction).toBeUndefined();
|
|
559
561
|
expect(method.payload.emitProgress).toBe(true);
|
|
560
562
|
expect(method.postMessage).toHaveBeenCalledWith({
|
|
561
563
|
event: 'UI_EVENT',
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SolanaOffChainMessageFormat, SolanaOffChainMessageVersion } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
import SolSignOffchainMessage from '../src/api/solana/SolSignOffchainMessage';
|
|
4
|
+
|
|
5
|
+
import type { Device } from '../src/device/Device';
|
|
6
|
+
|
|
7
|
+
jest.mock('../src/data/config', () => ({
|
|
8
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
9
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const signerA = '11'.repeat(32);
|
|
13
|
+
const signerB = '22'.repeat(32);
|
|
14
|
+
|
|
15
|
+
const createMethod = (overrides: Record<string, unknown> = {}) =>
|
|
16
|
+
new SolSignOffchainMessage({
|
|
17
|
+
id: 1,
|
|
18
|
+
payload: {
|
|
19
|
+
method: 'solSignOffchainMessage',
|
|
20
|
+
path: "m/44'/501'/0'/0'",
|
|
21
|
+
messageHex: '48656c6c6f',
|
|
22
|
+
messageVersion: SolanaOffChainMessageVersion.MESSAGE_VERSION_1,
|
|
23
|
+
messageFormat: SolanaOffChainMessageFormat.V0_LIMITED_UTF8,
|
|
24
|
+
applicationDomainHex: `0x${'aa'.repeat(32)}`,
|
|
25
|
+
sourceFingerprint: 0x12345678,
|
|
26
|
+
requiredSigners: [`0x${signerA.toUpperCase()}`, signerB],
|
|
27
|
+
...overrides,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('SolSignOffchainMessage', () => {
|
|
32
|
+
test('maps V1 public parameters to Protocol V2 fields', async () => {
|
|
33
|
+
const method = createMethod();
|
|
34
|
+
method.init();
|
|
35
|
+
|
|
36
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
37
|
+
message: { signature: 'signature', public_key: signerA },
|
|
38
|
+
});
|
|
39
|
+
method.device = { commands: { typedCall } } as unknown as Device;
|
|
40
|
+
|
|
41
|
+
await expect(method.run()).resolves.toEqual({ signature: 'signature', pub: signerA });
|
|
42
|
+
expect(typedCall).toHaveBeenCalledWith('SolanaSignOffChainMessage', 'SolanaMessageSignature', {
|
|
43
|
+
address_n: [2147483692, 2147484149, 2147483648, 2147483648],
|
|
44
|
+
message: '48656c6c6f',
|
|
45
|
+
message_version: SolanaOffChainMessageVersion.MESSAGE_VERSION_1,
|
|
46
|
+
message_format: SolanaOffChainMessageFormat.V0_LIMITED_UTF8,
|
|
47
|
+
application_domain: 'aa'.repeat(32),
|
|
48
|
+
source_fingerprint: 0x12345678,
|
|
49
|
+
required_signers: [signerA, signerB],
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test.each([
|
|
54
|
+
{ requiredSigners: ['11'], error: '32-byte hex public key' },
|
|
55
|
+
{ requiredSigners: [signerB, signerA], error: 'strictly sorted and unique' },
|
|
56
|
+
{ requiredSigners: [signerA, signerA], error: 'strictly sorted and unique' },
|
|
57
|
+
{
|
|
58
|
+
requiredSigners: Array.from({ length: 11 }, (_, index) =>
|
|
59
|
+
index.toString(16).padStart(64, '0')
|
|
60
|
+
),
|
|
61
|
+
error: 'at most 10 entries',
|
|
62
|
+
},
|
|
63
|
+
])('rejects invalid required signers: $error', ({ requiredSigners, error }) => {
|
|
64
|
+
expect(() => createMethod({ requiredSigners }).init()).toThrow(error);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test.each([-1, 0x100000000, 1.5])(
|
|
68
|
+
'rejects an invalid source fingerprint: %s',
|
|
69
|
+
sourceFingerprint => {
|
|
70
|
+
expect(() => createMethod({ sourceFingerprint }).init()).toThrow('uint32');
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadPortfolio.d.ts","sourceRoot":"","sources":["../../src/api/UploadPortfolio.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"UploadPortfolio.d.ts","sourceRoot":"","sources":["../../src/api/UploadPortfolio.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CAChC,CAAC;AAQF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,SAAS;IACpD,IAAI;IAuBE,GAAG;;;;;;;;CAsBV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolSignOffchainMessage.d.ts","sourceRoot":"","sources":["../../../src/api/solana/SolSignOffchainMessage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,yBAAyB,IAAI,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"SolSignOffchainMessage.d.ts","sourceRoot":"","sources":["../../../src/api/solana/SolSignOffchainMessage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,yBAAyB,IAAI,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAmC1G,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU,CAAC,8BAA8B,CAAC;IAC5F,qBAAqB;IAIrB,IAAI;IAqDJ,eAAe;;;;;;;;;;;IAcT,GAAG;;;;CAcV"}
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAEL,KAAK,6BAA6B,EAElC,KAAK,YAAY,EAIlB,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AA0E7D,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBAoFvE,CAAC;AAyqBF,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAWpF;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAW/E;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAQlF;AAED,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAEL,KAAK,6BAA6B,EAElC,KAAK,YAAY,EAIlB,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AA0E7D,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBAoFvE,CAAC;AAyqBF,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAWpF;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAW/E;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAQlF;AAED,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAMrF;AA6JD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAMtF;AAwLD,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SA4G9D,CAAC;AA8GF,eAAO,MAAM,qBAAqB,gFAejC,CAAC;AAiLF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,cAAc,CAAoB;IAE1C,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,YAAY,CAAsB;IAE1C,OAAO,CAAC,cAAc,CAAC,CAAgB;IAGvC,OAAO,CAAC,sBAAsB,CAAoC;IAElE,OAAO,CAAC,iBAAiB,CAAoB;;IAS7C,OAAO,CAAC,cAAc;IA6BhB,aAAa,CAAC,OAAO,EAAE,WAAW;IAuExC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAOV,gBAAgB;CAiC/B;AAED,eAAO,MAAM,QAAQ,YAIpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAiBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
|
|
@@ -31,7 +31,7 @@ export declare const cancelDeviceInPrompt: (device: Device, expectResponse?: boo
|
|
|
31
31
|
};
|
|
32
32
|
} | {
|
|
33
33
|
success: boolean;
|
|
34
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
34
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
35
35
|
payload: {
|
|
36
36
|
message: string;
|
|
37
37
|
};
|
|
@@ -50,7 +50,7 @@ export declare const cancelDeviceWithInitialize: (device: Device) => Promise<{
|
|
|
50
50
|
};
|
|
51
51
|
} | {
|
|
52
52
|
success: boolean;
|
|
53
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
53
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
54
54
|
payload: {
|
|
55
55
|
message: string;
|
|
56
56
|
};
|
|
@@ -80,7 +80,7 @@ export declare class DeviceCommands {
|
|
|
80
80
|
};
|
|
81
81
|
} | {
|
|
82
82
|
success: boolean;
|
|
83
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
83
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
84
84
|
payload: {
|
|
85
85
|
message: string;
|
|
86
86
|
};
|
|
@@ -99,7 +99,7 @@ export declare class DeviceCommands {
|
|
|
99
99
|
};
|
|
100
100
|
} | {
|
|
101
101
|
success: boolean;
|
|
102
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
102
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
103
103
|
payload: {
|
|
104
104
|
message: string;
|
|
105
105
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ declare class DeviceCommands {
|
|
|
136
136
|
};
|
|
137
137
|
} | {
|
|
138
138
|
success: boolean;
|
|
139
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
139
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
140
140
|
payload: {
|
|
141
141
|
message: string;
|
|
142
142
|
};
|
|
@@ -155,7 +155,7 @@ declare class DeviceCommands {
|
|
|
155
155
|
};
|
|
156
156
|
} | {
|
|
157
157
|
success: boolean;
|
|
158
|
-
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 |
|
|
158
|
+
error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902;
|
|
159
159
|
payload: {
|
|
160
160
|
message: string;
|
|
161
161
|
};
|
|
@@ -1116,6 +1116,7 @@ declare const switchTransport: ({ env, Transport, plugin, }: {
|
|
|
1116
1116
|
type UploadPortfolioParams = {
|
|
1117
1117
|
packageBase64: string;
|
|
1118
1118
|
timeoutMs?: number | string;
|
|
1119
|
+
/** Controls transfer progress UI events. Defaults to `silent`. */
|
|
1119
1120
|
uiMode?: 'silent' | 'progress';
|
|
1120
1121
|
};
|
|
1121
1122
|
|
|
@@ -2476,6 +2477,9 @@ type SolSignOffchainMessageParams = {
|
|
|
2476
2477
|
messageVersion?: SolanaOffChainMessageVersion;
|
|
2477
2478
|
messageFormat?: SolanaOffChainMessageFormat;
|
|
2478
2479
|
applicationDomainHex?: string;
|
|
2480
|
+
sourceFingerprint?: number;
|
|
2481
|
+
/** 32-byte public keys encoded as hex, strictly sorted and unique. */
|
|
2482
|
+
requiredSigners?: string[];
|
|
2479
2483
|
};
|
|
2480
2484
|
declare function solSignOffchainMessage(connectId: string, deviceId: string, params: CommonParams & SolSignOffchainMessageParams): Response<SolSignOffchainMessageResponse>;
|
|
2481
2485
|
|
package/dist/index.js
CHANGED
|
@@ -13203,7 +13203,8 @@ var nested$2 = {
|
|
|
13203
13203
|
},
|
|
13204
13204
|
SolanaOffChainMessageVersion: {
|
|
13205
13205
|
values: {
|
|
13206
|
-
MESSAGE_VERSION_0: 0
|
|
13206
|
+
MESSAGE_VERSION_0: 0,
|
|
13207
|
+
MESSAGE_VERSION_1: 1
|
|
13207
13208
|
}
|
|
13208
13209
|
},
|
|
13209
13210
|
SolanaOffChainMessageFormat: {
|
|
@@ -13236,14 +13237,16 @@ var nested$2 = {
|
|
|
13236
13237
|
},
|
|
13237
13238
|
message_format: {
|
|
13238
13239
|
type: "SolanaOffChainMessageFormat",
|
|
13239
|
-
id: 4
|
|
13240
|
-
options: {
|
|
13241
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
13242
|
-
}
|
|
13240
|
+
id: 4
|
|
13243
13241
|
},
|
|
13244
13242
|
application_domain: {
|
|
13245
13243
|
type: "bytes",
|
|
13246
13244
|
id: 5
|
|
13245
|
+
},
|
|
13246
|
+
required_signers: {
|
|
13247
|
+
rule: "repeated",
|
|
13248
|
+
type: "bytes",
|
|
13249
|
+
id: 7
|
|
13247
13250
|
}
|
|
13248
13251
|
}
|
|
13249
13252
|
},
|
|
@@ -36027,7 +36030,8 @@ var nested = {
|
|
|
36027
36030
|
},
|
|
36028
36031
|
SolanaOffChainMessageVersion: {
|
|
36029
36032
|
values: {
|
|
36030
|
-
MESSAGE_VERSION_0: 0
|
|
36033
|
+
MESSAGE_VERSION_0: 0,
|
|
36034
|
+
MESSAGE_VERSION_1: 1
|
|
36031
36035
|
}
|
|
36032
36036
|
},
|
|
36033
36037
|
SolanaOffChainMessageFormat: {
|
|
@@ -36115,10 +36119,7 @@ var nested = {
|
|
|
36115
36119
|
},
|
|
36116
36120
|
message_format: {
|
|
36117
36121
|
type: "SolanaOffChainMessageFormat",
|
|
36118
|
-
id: 4
|
|
36119
|
-
options: {
|
|
36120
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
36121
|
-
}
|
|
36122
|
+
id: 4
|
|
36122
36123
|
},
|
|
36123
36124
|
application_domain: {
|
|
36124
36125
|
type: "bytes",
|
|
@@ -36127,6 +36128,11 @@ var nested = {
|
|
|
36127
36128
|
source_fingerprint: {
|
|
36128
36129
|
type: "uint32",
|
|
36129
36130
|
id: 6
|
|
36131
|
+
},
|
|
36132
|
+
required_signers: {
|
|
36133
|
+
rule: "repeated",
|
|
36134
|
+
type: "bytes",
|
|
36135
|
+
id: 7
|
|
36130
36136
|
}
|
|
36131
36137
|
}
|
|
36132
36138
|
},
|
|
@@ -41811,7 +41817,7 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onS
|
|
|
41811
41817
|
return getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
41812
41818
|
});
|
|
41813
41819
|
function getProtocolV2WalletSession(device, options) {
|
|
41814
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l
|
|
41820
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41815
41821
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41816
41822
|
const forceWalletSelection = (options === null || options === void 0 ? void 0 : options.forceWalletSelection) === true || (options === null || options === void 0 ? void 0 : options.initSession) === true;
|
|
41817
41823
|
const readCurrentAttachPinSession = (options === null || options === void 0 ? void 0 : options.readCurrentAttachPinSession) === true;
|
|
@@ -41882,7 +41888,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41882
41888
|
return keepAttachPin ? Object.assign(session, { viaAttachPin: true }) : session;
|
|
41883
41889
|
});
|
|
41884
41890
|
const rejectMismatchedAttachPinWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41885
|
-
var
|
|
41891
|
+
var _m;
|
|
41886
41892
|
const features = yield refreshProtocolV2DeviceStatus(device);
|
|
41887
41893
|
markWalletStatusRefreshed();
|
|
41888
41894
|
if (features.unlockedAttachPin !== true) {
|
|
@@ -41891,10 +41897,10 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41891
41897
|
try {
|
|
41892
41898
|
yield device.lockDevice();
|
|
41893
41899
|
}
|
|
41894
|
-
catch (
|
|
41900
|
+
catch (_o) {
|
|
41895
41901
|
}
|
|
41896
41902
|
if (options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet) {
|
|
41897
|
-
(
|
|
41903
|
+
(_m = device.clearStandardInternalState) === null || _m === void 0 ? void 0 : _m.call(device);
|
|
41898
41904
|
device.clearInternalState();
|
|
41899
41905
|
}
|
|
41900
41906
|
else {
|
|
@@ -41903,11 +41909,11 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41903
41909
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
41904
41910
|
});
|
|
41905
41911
|
const lockAttachPinBeforePassphraseSelection = () => __awaiter(this, void 0, void 0, function* () {
|
|
41906
|
-
var
|
|
41912
|
+
var _p;
|
|
41907
41913
|
if (readCurrentAttachPinSession || (options === null || options === void 0 ? void 0 : options.onlyMainPin)) {
|
|
41908
41914
|
return;
|
|
41909
41915
|
}
|
|
41910
|
-
if (((
|
|
41916
|
+
if (((_p = device.features) === null || _p === void 0 ? void 0 : _p.unlockedAttachPin) !== true) {
|
|
41911
41917
|
return;
|
|
41912
41918
|
}
|
|
41913
41919
|
yield rejectMismatchedAttachPinWallet();
|
|
@@ -41928,8 +41934,8 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41928
41934
|
}
|
|
41929
41935
|
});
|
|
41930
41936
|
const selectStandardWallet = (forceMainPin = false) => __awaiter(this, void 0, void 0, function* () {
|
|
41931
|
-
var
|
|
41932
|
-
if (((
|
|
41937
|
+
var _q;
|
|
41938
|
+
if (((_q = device.features) === null || _q === void 0 ? void 0 : _q.passphraseProtection) === true) {
|
|
41933
41939
|
yield selectMainPin();
|
|
41934
41940
|
yield askDevicePassphrase(device, {
|
|
41935
41941
|
passphrase: '',
|
|
@@ -41994,9 +42000,6 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41994
42000
|
throw error;
|
|
41995
42001
|
}
|
|
41996
42002
|
resumed = false;
|
|
41997
|
-
if (((_g = device.features) === null || _g === void 0 ? void 0 : _g.unlockedAttachPin) === true) {
|
|
41998
|
-
response = yield getDeviceSession(device, sessionGetRequest());
|
|
41999
|
-
}
|
|
42000
42003
|
}
|
|
42001
42004
|
}
|
|
42002
42005
|
else if (expectedPassphraseState) {
|
|
@@ -42025,7 +42028,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42025
42028
|
}
|
|
42026
42029
|
catch (error) {
|
|
42027
42030
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42028
|
-
(
|
|
42031
|
+
(_g = device.clearStandardInternalState) === null || _g === void 0 ? void 0 : _g.call(device);
|
|
42029
42032
|
}
|
|
42030
42033
|
else {
|
|
42031
42034
|
device.clearInternalState();
|
|
@@ -42040,7 +42043,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42040
42043
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
|
|
42041
42044
|
}
|
|
42042
42045
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42043
|
-
(
|
|
42046
|
+
(_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
|
|
42044
42047
|
yield selectStandardWallet(true);
|
|
42045
42048
|
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42046
42049
|
}
|
|
@@ -42055,7 +42058,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42055
42058
|
}
|
|
42056
42059
|
catch (error) {
|
|
42057
42060
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42058
|
-
(
|
|
42061
|
+
(_j = device.clearStandardInternalState) === null || _j === void 0 ? void 0 : _j.call(device);
|
|
42059
42062
|
}
|
|
42060
42063
|
else {
|
|
42061
42064
|
device.clearInternalState();
|
|
@@ -42078,7 +42081,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42078
42081
|
if (sessionIsAttachPinWallet(response)) {
|
|
42079
42082
|
response = yield askEmptyPassphraseAndGet({ deriveCardano: true, keepAttachPin: true });
|
|
42080
42083
|
}
|
|
42081
|
-
else if (((
|
|
42084
|
+
else if (((_k = device.features) === null || _k === void 0 ? void 0 : _k.passphraseProtection) === false) {
|
|
42082
42085
|
response = yield getDeviceSession(device, buildDeviceSessionGetRequest());
|
|
42083
42086
|
}
|
|
42084
42087
|
else if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
@@ -42095,7 +42098,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42095
42098
|
}
|
|
42096
42099
|
catch (error) {
|
|
42097
42100
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42098
|
-
(
|
|
42101
|
+
(_l = device.clearStandardInternalState) === null || _l === void 0 ? void 0 : _l.call(device);
|
|
42099
42102
|
}
|
|
42100
42103
|
else {
|
|
42101
42104
|
device.clearInternalState();
|
|
@@ -59463,6 +59466,29 @@ class SolSignTransaction extends BaseMethod {
|
|
|
59463
59466
|
}
|
|
59464
59467
|
}
|
|
59465
59468
|
|
|
59469
|
+
const SOLANA_PUBLIC_KEY_LENGTH = 32;
|
|
59470
|
+
const SOLANA_APPLICATION_DOMAIN_LENGTH = 32;
|
|
59471
|
+
const MAX_REQUIRED_SIGNERS = 10;
|
|
59472
|
+
const normalizeRequiredSigners = (requiredSigners) => {
|
|
59473
|
+
if (!requiredSigners)
|
|
59474
|
+
return undefined;
|
|
59475
|
+
if (requiredSigners.length > MAX_REQUIRED_SIGNERS) {
|
|
59476
|
+
throw invalidParameter(`Parameter [requiredSigners] supports at most ${MAX_REQUIRED_SIGNERS} entries.`);
|
|
59477
|
+
}
|
|
59478
|
+
const normalized = requiredSigners.map((signer, index) => {
|
|
59479
|
+
if (typeof signer !== 'string' ||
|
|
59480
|
+
!isHexString(addHexPrefix(signer), SOLANA_PUBLIC_KEY_LENGTH)) {
|
|
59481
|
+
throw invalidParameter(`Parameter [requiredSigners][${index}] must be a ${SOLANA_PUBLIC_KEY_LENGTH}-byte hex public key.`);
|
|
59482
|
+
}
|
|
59483
|
+
return stripHexPrefix(signer).toLowerCase();
|
|
59484
|
+
});
|
|
59485
|
+
for (let index = 1; index < normalized.length; index += 1) {
|
|
59486
|
+
if (normalized[index - 1] >= normalized[index]) {
|
|
59487
|
+
throw invalidParameter('Parameter [requiredSigners] must be strictly sorted and unique.');
|
|
59488
|
+
}
|
|
59489
|
+
}
|
|
59490
|
+
return normalized;
|
|
59491
|
+
};
|
|
59466
59492
|
class SolSignOffchainMessage extends BaseMethod {
|
|
59467
59493
|
getSupportedProtocols() {
|
|
59468
59494
|
return ['V1', 'V2'];
|
|
@@ -59477,15 +59503,29 @@ class SolSignOffchainMessage extends BaseMethod {
|
|
|
59477
59503
|
{ name: 'messageVersion', type: 'number', required: false },
|
|
59478
59504
|
{ name: 'messageFormat', type: 'number', required: false },
|
|
59479
59505
|
{ name: 'applicationDomainHex', type: 'hexString', required: false },
|
|
59506
|
+
{ name: 'sourceFingerprint', type: 'number', required: false },
|
|
59507
|
+
{ name: 'requiredSigners', type: 'array', required: false, allowEmpty: true },
|
|
59480
59508
|
]);
|
|
59481
|
-
const { path, messageHex, messageVersion, messageFormat, applicationDomainHex } = this.payload;
|
|
59509
|
+
const { path, messageHex, messageVersion, messageFormat, applicationDomainHex, sourceFingerprint, requiredSigners, } = this.payload;
|
|
59482
59510
|
const addressN = validatePath(path, 3);
|
|
59511
|
+
if (sourceFingerprint !== undefined &&
|
|
59512
|
+
(!Number.isInteger(sourceFingerprint) ||
|
|
59513
|
+
sourceFingerprint < 0 ||
|
|
59514
|
+
sourceFingerprint > 0xffffffff)) {
|
|
59515
|
+
throw invalidParameter('Parameter [sourceFingerprint] must be a uint32 number.');
|
|
59516
|
+
}
|
|
59517
|
+
if (applicationDomainHex !== undefined &&
|
|
59518
|
+
!isHexString(addHexPrefix(applicationDomainHex), SOLANA_APPLICATION_DOMAIN_LENGTH)) {
|
|
59519
|
+
throw invalidParameter('Parameter [applicationDomainHex] must be 32 bytes.');
|
|
59520
|
+
}
|
|
59483
59521
|
this.params = {
|
|
59484
59522
|
address_n: addressN,
|
|
59485
59523
|
message: stripHexPrefix(messageHex),
|
|
59486
59524
|
message_version: messageVersion !== null && messageVersion !== void 0 ? messageVersion : undefined,
|
|
59487
59525
|
message_format: messageFormat !== null && messageFormat !== void 0 ? messageFormat : undefined,
|
|
59488
|
-
application_domain: applicationDomainHex
|
|
59526
|
+
application_domain: applicationDomainHex ? stripHexPrefix(applicationDomainHex) : undefined,
|
|
59527
|
+
source_fingerprint: sourceFingerprint !== null && sourceFingerprint !== void 0 ? sourceFingerprint : undefined,
|
|
59528
|
+
required_signers: normalizeRequiredSigners(requiredSigners),
|
|
59489
59529
|
};
|
|
59490
59530
|
}
|
|
59491
59531
|
getVersionRange() {
|
|
@@ -66347,10 +66387,9 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
66347
66387
|
typedError.message.includes('Device protocol has not been detected'));
|
|
66348
66388
|
}
|
|
66349
66389
|
function isProtocolV2PeerRemovedPairingError(method, error) {
|
|
66350
|
-
const errorCode = error === null || error === void 0 ? void 0 : error.errorCode;
|
|
66351
66390
|
return (method.payload.connectProtocol === 'V2' &&
|
|
66352
|
-
(
|
|
66353
|
-
|
|
66391
|
+
(error === null || error === void 0 ? void 0 : error.errorCode) ===
|
|
66392
|
+
hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
66354
66393
|
}
|
|
66355
66394
|
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
66356
66395
|
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;
|
|
1
|
+
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;GA6XF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;;GAOxB"}
|
|
@@ -10,6 +10,8 @@ export type SolSignOffchainMessageParams = {
|
|
|
10
10
|
messageVersion?: SolanaOffChainMessageVersion;
|
|
11
11
|
messageFormat?: SolanaOffChainMessageFormat;
|
|
12
12
|
applicationDomainHex?: string;
|
|
13
|
+
sourceFingerprint?: number;
|
|
14
|
+
requiredSigners?: string[];
|
|
13
15
|
};
|
|
14
16
|
export declare function solSignOffchainMessage(connectId: string, deviceId: string, params: CommonParams & SolSignOffchainMessageParams): Response<SolSignOffchainMessageResponse>;
|
|
15
17
|
//# sourceMappingURL=solSignOffchainMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solSignOffchainMessage.d.ts","sourceRoot":"","sources":["../../../src/types/api/solSignOffchainMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,4BAA4B,CAAC;IAC9C,aAAa,CAAC,EAAE,2BAA2B,CAAC;IAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"solSignOffchainMessage.d.ts","sourceRoot":"","sources":["../../../src/types/api/solSignOffchainMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,4BAA4B,CAAC;IAC9C,aAAa,CAAC,EAAE,2BAA2B,CAAC;IAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,4BAA4B,GAClD,QAAQ,CAAC,8BAA8B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.15",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.15",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.15",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "ea66eff5817385ee2144d8e037c385342e44e21f"
|
|
50
50
|
}
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
2
|
import { validatePath } from '../helpers/pathUtils';
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
|
-
import { validateParams } from '../helpers/paramsValidator';
|
|
5
|
-
import { stripHexPrefix } from '../helpers/hexUtils';
|
|
4
|
+
import { invalidParameter, validateParams } from '../helpers/paramsValidator';
|
|
5
|
+
import { addHexPrefix, isHexString, stripHexPrefix } from '../helpers/hexUtils';
|
|
6
6
|
|
|
7
7
|
import type { SolanaSignOffChainMessage as HardwareSolSignOffChainMessage } from '@onekeyfe/hd-transport';
|
|
8
8
|
|
|
9
|
+
const SOLANA_PUBLIC_KEY_LENGTH = 32;
|
|
10
|
+
const SOLANA_APPLICATION_DOMAIN_LENGTH = 32;
|
|
11
|
+
const MAX_REQUIRED_SIGNERS = 10;
|
|
12
|
+
|
|
13
|
+
const normalizeRequiredSigners = (requiredSigners?: unknown[]): string[] | undefined => {
|
|
14
|
+
if (!requiredSigners) return undefined;
|
|
15
|
+
if (requiredSigners.length > MAX_REQUIRED_SIGNERS) {
|
|
16
|
+
throw invalidParameter(
|
|
17
|
+
`Parameter [requiredSigners] supports at most ${MAX_REQUIRED_SIGNERS} entries.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const normalized = requiredSigners.map((signer, index) => {
|
|
22
|
+
if (
|
|
23
|
+
typeof signer !== 'string' ||
|
|
24
|
+
!isHexString(addHexPrefix(signer), SOLANA_PUBLIC_KEY_LENGTH)
|
|
25
|
+
) {
|
|
26
|
+
throw invalidParameter(
|
|
27
|
+
`Parameter [requiredSigners][${index}] must be a ${SOLANA_PUBLIC_KEY_LENGTH}-byte hex public key.`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return stripHexPrefix(signer).toLowerCase();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
for (let index = 1; index < normalized.length; index += 1) {
|
|
34
|
+
if (normalized[index - 1] >= normalized[index]) {
|
|
35
|
+
throw invalidParameter('Parameter [requiredSigners] must be strictly sorted and unique.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return normalized;
|
|
40
|
+
};
|
|
41
|
+
|
|
9
42
|
export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignOffChainMessage> {
|
|
10
43
|
getSupportedProtocols() {
|
|
11
44
|
return ['V1', 'V2'] as const;
|
|
@@ -23,10 +56,34 @@ export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignOf
|
|
|
23
56
|
{ name: 'messageVersion', type: 'number', required: false },
|
|
24
57
|
{ name: 'messageFormat', type: 'number', required: false },
|
|
25
58
|
{ name: 'applicationDomainHex', type: 'hexString', required: false },
|
|
59
|
+
{ name: 'sourceFingerprint', type: 'number', required: false },
|
|
60
|
+
{ name: 'requiredSigners', type: 'array', required: false, allowEmpty: true },
|
|
26
61
|
]);
|
|
27
62
|
|
|
28
|
-
const {
|
|
63
|
+
const {
|
|
64
|
+
path,
|
|
65
|
+
messageHex,
|
|
66
|
+
messageVersion,
|
|
67
|
+
messageFormat,
|
|
68
|
+
applicationDomainHex,
|
|
69
|
+
sourceFingerprint,
|
|
70
|
+
requiredSigners,
|
|
71
|
+
} = this.payload;
|
|
29
72
|
const addressN = validatePath(path, 3);
|
|
73
|
+
if (
|
|
74
|
+
sourceFingerprint !== undefined &&
|
|
75
|
+
(!Number.isInteger(sourceFingerprint) ||
|
|
76
|
+
sourceFingerprint < 0 ||
|
|
77
|
+
sourceFingerprint > 0xffffffff)
|
|
78
|
+
) {
|
|
79
|
+
throw invalidParameter('Parameter [sourceFingerprint] must be a uint32 number.');
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
applicationDomainHex !== undefined &&
|
|
83
|
+
!isHexString(addHexPrefix(applicationDomainHex), SOLANA_APPLICATION_DOMAIN_LENGTH)
|
|
84
|
+
) {
|
|
85
|
+
throw invalidParameter('Parameter [applicationDomainHex] must be 32 bytes.');
|
|
86
|
+
}
|
|
30
87
|
|
|
31
88
|
// init params
|
|
32
89
|
this.params = {
|
|
@@ -34,7 +91,9 @@ export default class SolSignOffchainMessage extends BaseMethod<HardwareSolSignOf
|
|
|
34
91
|
message: stripHexPrefix(messageHex),
|
|
35
92
|
message_version: messageVersion ?? undefined,
|
|
36
93
|
message_format: messageFormat ?? undefined,
|
|
37
|
-
application_domain: applicationDomainHex
|
|
94
|
+
application_domain: applicationDomainHex ? stripHexPrefix(applicationDomainHex) : undefined,
|
|
95
|
+
source_fingerprint: sourceFingerprint ?? undefined,
|
|
96
|
+
required_signers: normalizeRequiredSigners(requiredSigners),
|
|
38
97
|
};
|
|
39
98
|
}
|
|
40
99
|
|
package/src/core/index.ts
CHANGED
|
@@ -965,11 +965,10 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
965
965
|
}
|
|
966
966
|
|
|
967
967
|
export function isProtocolV2PeerRemovedPairingError(method: BaseMethod, error: unknown) {
|
|
968
|
-
const errorCode = (error as { errorCode?: unknown })?.errorCode;
|
|
969
968
|
return (
|
|
970
969
|
method.payload.connectProtocol === 'V2' &&
|
|
971
|
-
(errorCode
|
|
972
|
-
|
|
970
|
+
(error as { errorCode?: unknown })?.errorCode ===
|
|
971
|
+
HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
973
972
|
);
|
|
974
973
|
}
|
|
975
974
|
|
|
@@ -8968,7 +8968,8 @@
|
|
|
8968
8968
|
},
|
|
8969
8969
|
"SolanaOffChainMessageVersion": {
|
|
8970
8970
|
"values": {
|
|
8971
|
-
"MESSAGE_VERSION_0": 0
|
|
8971
|
+
"MESSAGE_VERSION_0": 0,
|
|
8972
|
+
"MESSAGE_VERSION_1": 1
|
|
8972
8973
|
}
|
|
8973
8974
|
},
|
|
8974
8975
|
"SolanaOffChainMessageFormat": {
|
|
@@ -9056,10 +9057,7 @@
|
|
|
9056
9057
|
},
|
|
9057
9058
|
"message_format": {
|
|
9058
9059
|
"type": "SolanaOffChainMessageFormat",
|
|
9059
|
-
"id": 4
|
|
9060
|
-
"options": {
|
|
9061
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
9062
|
-
}
|
|
9060
|
+
"id": 4
|
|
9063
9061
|
},
|
|
9064
9062
|
"application_domain": {
|
|
9065
9063
|
"type": "bytes",
|
|
@@ -9068,6 +9066,11 @@
|
|
|
9068
9066
|
"source_fingerprint": {
|
|
9069
9067
|
"type": "uint32",
|
|
9070
9068
|
"id": 6
|
|
9069
|
+
},
|
|
9070
|
+
"required_signers": {
|
|
9071
|
+
"rule": "repeated",
|
|
9072
|
+
"type": "bytes",
|
|
9073
|
+
"id": 7
|
|
9071
9074
|
}
|
|
9072
9075
|
}
|
|
9073
9076
|
},
|
|
@@ -10243,7 +10243,8 @@
|
|
|
10243
10243
|
},
|
|
10244
10244
|
"SolanaOffChainMessageVersion": {
|
|
10245
10245
|
"values": {
|
|
10246
|
-
"MESSAGE_VERSION_0": 0
|
|
10246
|
+
"MESSAGE_VERSION_0": 0,
|
|
10247
|
+
"MESSAGE_VERSION_1": 1
|
|
10247
10248
|
}
|
|
10248
10249
|
},
|
|
10249
10250
|
"SolanaOffChainMessageFormat": {
|
|
@@ -10276,14 +10277,16 @@
|
|
|
10276
10277
|
},
|
|
10277
10278
|
"message_format": {
|
|
10278
10279
|
"type": "SolanaOffChainMessageFormat",
|
|
10279
|
-
"id": 4
|
|
10280
|
-
"options": {
|
|
10281
|
-
"default": "V0_RESTRICTED_ASCII"
|
|
10282
|
-
}
|
|
10280
|
+
"id": 4
|
|
10283
10281
|
},
|
|
10284
10282
|
"application_domain": {
|
|
10285
10283
|
"type": "bytes",
|
|
10286
10284
|
"id": 5
|
|
10285
|
+
},
|
|
10286
|
+
"required_signers": {
|
|
10287
|
+
"rule": "repeated",
|
|
10288
|
+
"type": "bytes",
|
|
10289
|
+
"id": 7
|
|
10287
10290
|
}
|
|
10288
10291
|
}
|
|
10289
10292
|
},
|
|
@@ -234,9 +234,9 @@ export async function getProtocolV2WalletSession(
|
|
|
234
234
|
const forceWalletSelection =
|
|
235
235
|
options?.forceWalletSelection === true || options?.initSession === true;
|
|
236
236
|
const readCurrentAttachPinSession = options?.readCurrentAttachPinSession === true;
|
|
237
|
-
const sessionIsAttachPinWallet = (session?:
|
|
237
|
+
const sessionIsAttachPinWallet = (session?: { viaAttachPin?: boolean }) =>
|
|
238
238
|
readCurrentAttachPinSession ||
|
|
239
|
-
|
|
239
|
+
session?.viaAttachPin === true ||
|
|
240
240
|
device.features?.unlockedAttachPin === true;
|
|
241
241
|
|
|
242
242
|
if (forceWalletSelection) {
|
|
@@ -455,11 +455,6 @@ export async function getProtocolV2WalletSession(
|
|
|
455
455
|
throw error;
|
|
456
456
|
}
|
|
457
457
|
resumed = false;
|
|
458
|
-
if (device.features?.unlockedAttachPin === true) {
|
|
459
|
-
// Locking invalidates the old handle, but Attach PIN already selected the wallet.
|
|
460
|
-
// Read the current session and validate its passphrase state below.
|
|
461
|
-
response = await getDeviceSession(device, sessionGetRequest());
|
|
462
|
-
}
|
|
463
458
|
}
|
|
464
459
|
} else if (expectedPassphraseState) {
|
|
465
460
|
try {
|
|
@@ -15,6 +15,9 @@ export type SolSignOffchainMessageParams = {
|
|
|
15
15
|
messageVersion?: SolanaOffChainMessageVersion;
|
|
16
16
|
messageFormat?: SolanaOffChainMessageFormat;
|
|
17
17
|
applicationDomainHex?: string;
|
|
18
|
+
sourceFingerprint?: number;
|
|
19
|
+
/** 32-byte public keys encoded as hex, strictly sorted and unique. */
|
|
20
|
+
requiredSigners?: string[];
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
export declare function solSignOffchainMessage(
|