@onekeyfe/hd-transport 1.2.8 → 1.2.10-alpha.2
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__/babylon-context-hash.test.js +44 -0
- package/__tests__/protocol-v2-file-write-pipeline.test.js +478 -0
- package/__tests__/protocol-v2.test.js +3 -3
- package/__tests__/static-protobuf.test.js +436 -0
- package/__tests__/transport-log.test.js +176 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +158 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109280 -98
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/session.d.ts +7 -1
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/serialization/protobuf/messages.d.ts +1 -1
- package/dist/serialization/protobuf/messages.d.ts.map +1 -1
- package/dist/types/messages.d.ts +72 -0
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +6 -0
- package/dist/types/transport.d.ts.map +1 -1
- package/dist/utils/transportLog.d.ts.map +1 -1
- package/jest.config.js +3 -0
- package/messages-protocol-v2.json +152 -0
- package/package.json +6 -4
- package/scripts/protobuf-build.sh +37 -0
- package/scripts/protobuf-static-csp.js +103 -0
- package/scripts/protobuf-static.js +85 -0
- package/scripts/protobuf-types.js +1 -0
- package/src/constants.ts +10 -1
- package/src/index.ts +1 -0
- package/src/protocols/index.ts +10 -23
- package/src/protocols/v2/session.ts +326 -96
- package/src/serialization/protobuf/generated/codecs.d.ts +3 -0
- package/src/serialization/protobuf/generated/codecs.js +108990 -0
- package/src/serialization/protobuf/legacy-protocol-info.json +16 -0
- package/src/serialization/protobuf/messages.ts +12 -6
- package/src/types/messages.ts +97 -0
- package/src/types/transport.ts +25 -0
- package/src/utils/transportLog.ts +17 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nested": {
|
|
3
|
+
"LegacyProtocolInfo": {
|
|
4
|
+
"fields": {
|
|
5
|
+
"version": { "rule": "required", "type": "uint32", "id": 1 },
|
|
6
|
+
"supported_messages": {
|
|
7
|
+
"rule": "repeated",
|
|
8
|
+
"type": "uint32",
|
|
9
|
+
"id": 2,
|
|
10
|
+
"options": { "packed": false }
|
|
11
|
+
},
|
|
12
|
+
"protobuf_definition": { "type": "string", "id": 3 }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import * as protobuf from 'protobufjs/light';
|
|
2
|
+
import Long from 'long';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { installStaticCodecs } from './generated/codecs';
|
|
5
|
+
|
|
6
|
+
// protobufjs optional dependency discovery uses Function, which CSP can disable.
|
|
7
|
+
protobuf.util.Long = Long;
|
|
8
|
+
protobuf.configure();
|
|
9
|
+
|
|
10
|
+
export function parseConfigure(data: protobuf.INamespace | string) {
|
|
11
|
+
const root = protobuf.Root.fromJSON(typeof data === 'string' ? JSON.parse(data) : data);
|
|
12
|
+
// Unrecognized custom schemas retain the existing reflection-based API.
|
|
13
|
+
installStaticCodecs(root);
|
|
14
|
+
return root;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
export const createMessageFromName = (messages: protobuf.Root, name: string) => {
|
package/src/types/messages.ts
CHANGED
|
@@ -4554,6 +4554,28 @@ export enum CommandFlags {
|
|
|
4554
4554
|
Factory_Only = 1,
|
|
4555
4555
|
}
|
|
4556
4556
|
|
|
4557
|
+
export enum Enum_CanonicalBitcoinNetwork {
|
|
4558
|
+
BITCOIN_MAINNET = 0,
|
|
4559
|
+
BITCOIN_TESTNET = 1,
|
|
4560
|
+
BITCOIN_SIGNET = 2,
|
|
4561
|
+
BITCOIN_REGTEST = 3,
|
|
4562
|
+
}
|
|
4563
|
+
export type CanonicalBitcoinNetwork = keyof typeof Enum_CanonicalBitcoinNetwork;
|
|
4564
|
+
|
|
4565
|
+
// BabylonDeriveContextHash
|
|
4566
|
+
export type BabylonDeriveContextHash = {
|
|
4567
|
+
address_n: number[];
|
|
4568
|
+
script_type: InputScriptType;
|
|
4569
|
+
app_name: string;
|
|
4570
|
+
context: string;
|
|
4571
|
+
network: CanonicalBitcoinNetwork;
|
|
4572
|
+
};
|
|
4573
|
+
|
|
4574
|
+
// BabylonDerivedContextHash
|
|
4575
|
+
export type BabylonDerivedContextHash = {
|
|
4576
|
+
secret: string;
|
|
4577
|
+
};
|
|
4578
|
+
|
|
4557
4579
|
export type TextMemo = {
|
|
4558
4580
|
text: string;
|
|
4559
4581
|
};
|
|
@@ -4658,6 +4680,70 @@ export type UiAnimationRequest = {
|
|
|
4658
4680
|
type?: UiAnimationType;
|
|
4659
4681
|
};
|
|
4660
4682
|
|
|
4683
|
+
export enum ZcashAddressType {
|
|
4684
|
+
UNIFIED_ORCHARD_P2PKH = 0,
|
|
4685
|
+
TRANSPARENT_P2PKH = 1,
|
|
4686
|
+
UNIFIED_ORCHARD = 2,
|
|
4687
|
+
}
|
|
4688
|
+
|
|
4689
|
+
export enum ZcashAddressScope {
|
|
4690
|
+
EXTERNAL = 0,
|
|
4691
|
+
INTERNAL = 1,
|
|
4692
|
+
}
|
|
4693
|
+
|
|
4694
|
+
// ZcashGetAddress
|
|
4695
|
+
export type ZcashGetAddress = {
|
|
4696
|
+
address_n: number[];
|
|
4697
|
+
show_display?: boolean;
|
|
4698
|
+
include_seed_fingerprint?: boolean;
|
|
4699
|
+
diversifier_index?: number;
|
|
4700
|
+
address_type?: ZcashAddressType;
|
|
4701
|
+
scope?: ZcashAddressScope;
|
|
4702
|
+
};
|
|
4703
|
+
|
|
4704
|
+
// ZcashAddress
|
|
4705
|
+
export type ZcashAddress = {
|
|
4706
|
+
address: string;
|
|
4707
|
+
seed_fingerprint?: string;
|
|
4708
|
+
};
|
|
4709
|
+
|
|
4710
|
+
// ZcashGetFullViewingKey
|
|
4711
|
+
export type ZcashGetFullViewingKey = {
|
|
4712
|
+
address_n: number[];
|
|
4713
|
+
};
|
|
4714
|
+
|
|
4715
|
+
// ZcashFullViewingKey
|
|
4716
|
+
export type ZcashFullViewingKey = {
|
|
4717
|
+
ufvk: string;
|
|
4718
|
+
};
|
|
4719
|
+
|
|
4720
|
+
// ZcashSignPczt
|
|
4721
|
+
export type ZcashSignPczt = {
|
|
4722
|
+
pczt_length: number;
|
|
4723
|
+
pczt_initial_chunk: string;
|
|
4724
|
+
};
|
|
4725
|
+
|
|
4726
|
+
// ZcashPcztChunkRequest
|
|
4727
|
+
export type ZcashPcztChunkRequest = {
|
|
4728
|
+
chunk_length: number;
|
|
4729
|
+
};
|
|
4730
|
+
|
|
4731
|
+
// ZcashPcztChunkAck
|
|
4732
|
+
export type ZcashPcztChunkAck = {
|
|
4733
|
+
data_chunk: string;
|
|
4734
|
+
};
|
|
4735
|
+
|
|
4736
|
+
// ZcashSignedPczt
|
|
4737
|
+
export type ZcashSignedPczt = {
|
|
4738
|
+
pczt_length: number;
|
|
4739
|
+
pczt_initial_chunk: string;
|
|
4740
|
+
};
|
|
4741
|
+
|
|
4742
|
+
// ZcashSignedPcztChunkRequest
|
|
4743
|
+
export type ZcashSignedPcztChunkRequest = {
|
|
4744
|
+
chunk_length: number;
|
|
4745
|
+
};
|
|
4746
|
+
|
|
4661
4747
|
// experimental_message
|
|
4662
4748
|
export type experimental_message = {};
|
|
4663
4749
|
|
|
@@ -5949,6 +6035,8 @@ export type MessageType = {
|
|
|
5949
6035
|
TronSignMessage: TronSignMessage;
|
|
5950
6036
|
TronMessageSignature: TronMessageSignature;
|
|
5951
6037
|
facotry: facotry;
|
|
6038
|
+
BabylonDeriveContextHash: BabylonDeriveContextHash;
|
|
6039
|
+
BabylonDerivedContextHash: BabylonDerivedContextHash;
|
|
5952
6040
|
TextMemo: TextMemo;
|
|
5953
6041
|
RefundMemo: RefundMemo;
|
|
5954
6042
|
CoinPurchaseMemo: CoinPurchaseMemo;
|
|
@@ -5964,6 +6052,15 @@ export type MessageType = {
|
|
|
5964
6052
|
UnlockPath: UnlockPath;
|
|
5965
6053
|
UnlockedPathRequest: UnlockedPathRequest;
|
|
5966
6054
|
UiAnimationRequest: UiAnimationRequest;
|
|
6055
|
+
ZcashGetAddress: ZcashGetAddress;
|
|
6056
|
+
ZcashAddress: ZcashAddress;
|
|
6057
|
+
ZcashGetFullViewingKey: ZcashGetFullViewingKey;
|
|
6058
|
+
ZcashFullViewingKey: ZcashFullViewingKey;
|
|
6059
|
+
ZcashSignPczt: ZcashSignPczt;
|
|
6060
|
+
ZcashPcztChunkRequest: ZcashPcztChunkRequest;
|
|
6061
|
+
ZcashPcztChunkAck: ZcashPcztChunkAck;
|
|
6062
|
+
ZcashSignedPczt: ZcashSignedPczt;
|
|
6063
|
+
ZcashSignedPcztChunkRequest: ZcashSignedPcztChunkRequest;
|
|
5967
6064
|
experimental_message: experimental_message;
|
|
5968
6065
|
experimental_field: experimental_field;
|
|
5969
6066
|
ProtocolInfoRequest: ProtocolInfoRequest;
|
package/src/types/transport.ts
CHANGED
|
@@ -34,6 +34,12 @@ export type OneKeyDeviceInfoWithSession = OneKeyUsbDeviceInfo & {
|
|
|
34
34
|
export type OneKeyMobileDeviceInfo = {
|
|
35
35
|
id: string;
|
|
36
36
|
name: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Color letter of the serial number ('A'-'Z') from the Pro2 / Neo BLE advertisement,
|
|
39
|
+
* possibly seen in an earlier scan. Set by the React Native and Electron BLE
|
|
40
|
+
* transports; absent when unknown.
|
|
41
|
+
*/
|
|
42
|
+
bleColorCode?: string;
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
export type OneKeyDeviceInfoBase = {
|
|
@@ -70,6 +76,19 @@ export type TransportWriteMetrics = {
|
|
|
70
76
|
frameBytes: number;
|
|
71
77
|
};
|
|
72
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Supplies the remaining chunks of one file for an ordered FilesystemFileWrite pipeline.
|
|
81
|
+
* The call's request data is the first chunk; `next` returns the following chunk in offset
|
|
82
|
+
* order, or undefined to stop. The call then resolves with the last confirmation (or the
|
|
83
|
+
* device Failure), so the caller must check `processed_byte` for completeness. Callbacks
|
|
84
|
+
* should not throw: an error escapes with chunks still in flight and invalidates the link.
|
|
85
|
+
*/
|
|
86
|
+
export type ProtocolV2FileWritePipeline = {
|
|
87
|
+
next: () => Promise<Record<string, unknown> | undefined>;
|
|
88
|
+
/** Called for each chunk after the device confirms it, in offset order. */
|
|
89
|
+
onResponse: (response: MessageFromOneKey) => void;
|
|
90
|
+
};
|
|
91
|
+
|
|
73
92
|
export type TransportCallOptions = {
|
|
74
93
|
timeoutMs?: number;
|
|
75
94
|
expectedTypes?: string[];
|
|
@@ -83,6 +102,12 @@ export type TransportCallOptions = {
|
|
|
83
102
|
onResponseAfterWrite?: (response: MessageFromOneKey) => void;
|
|
84
103
|
/** Prefer acknowledged BLE characteristic writes for this call when supported. */
|
|
85
104
|
writeWithResponse?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Protocol V2 only: keep up to PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW ordered
|
|
107
|
+
* FilesystemFileWrite frames of one file in flight within this call. `timeoutMs`
|
|
108
|
+
* bounds each frame write and each response instead of the whole file.
|
|
109
|
+
*/
|
|
110
|
+
fileWritePipeline?: ProtocolV2FileWritePipeline;
|
|
86
111
|
};
|
|
87
112
|
|
|
88
113
|
type ITransportInitFn = (
|
|
@@ -4,28 +4,39 @@ const REDACTED = '[REDACTED]';
|
|
|
4
4
|
|
|
5
5
|
const SENSITIVE_LOG_KEYS = new Set([
|
|
6
6
|
'accesstoken',
|
|
7
|
+
'additionaltxpubkeys',
|
|
7
8
|
'address',
|
|
8
9
|
'apikey',
|
|
9
10
|
'connectid',
|
|
11
|
+
'datachunk',
|
|
10
12
|
'devicestate',
|
|
11
13
|
'deviceid',
|
|
14
|
+
'enckey',
|
|
12
15
|
'entropy',
|
|
13
16
|
'expectedpassphrasestate',
|
|
14
17
|
'mnemonic',
|
|
18
|
+
'outkey',
|
|
15
19
|
'passphrase',
|
|
16
20
|
'passphrasestate',
|
|
17
21
|
'password',
|
|
22
|
+
'pczt',
|
|
18
23
|
'pin',
|
|
19
24
|
'privatekey',
|
|
20
25
|
'publickey',
|
|
21
26
|
'seed',
|
|
27
|
+
'secret',
|
|
28
|
+
'seedfingerprint',
|
|
22
29
|
'serialnumber',
|
|
23
30
|
'session',
|
|
24
31
|
'sessionid',
|
|
25
32
|
'signature',
|
|
33
|
+
'signedpczt',
|
|
26
34
|
'token',
|
|
35
|
+
'txpubkey',
|
|
36
|
+
'ufvk',
|
|
27
37
|
'uuid',
|
|
28
38
|
'walletsessionid',
|
|
39
|
+
'watchkey',
|
|
29
40
|
'xprv',
|
|
30
41
|
'xpub',
|
|
31
42
|
]);
|
|
@@ -44,7 +55,11 @@ const isSensitiveLogKey = (key: string) => {
|
|
|
44
55
|
};
|
|
45
56
|
|
|
46
57
|
const isSigningMessage = (messageName?: string) =>
|
|
47
|
-
Boolean(messageName && /(?:sign|txack|transaction)/i.test(messageName));
|
|
58
|
+
Boolean(messageName && /(?:sign|txack|transaction|pczt)/i.test(messageName));
|
|
59
|
+
|
|
60
|
+
// Key image and tx key exchanges carry per-output secrets under generic field names (iv, blob, salt).
|
|
61
|
+
const isMoneroSecretMessage = (messageName?: string) =>
|
|
62
|
+
Boolean(messageName && /^Monero(?:KeyImage|GetTxKey|LiveRefresh)/.test(messageName));
|
|
48
63
|
|
|
49
64
|
const redactLogValue = (value: unknown, seen: WeakSet<object>): unknown => {
|
|
50
65
|
if (ArrayBuffer.isView(value)) {
|
|
@@ -77,7 +92,7 @@ const redactLogValue = (value: unknown, seen: WeakSet<object>): unknown => {
|
|
|
77
92
|
};
|
|
78
93
|
|
|
79
94
|
export function getSafeTransportLogPayload(value: unknown, messageName?: string): unknown {
|
|
80
|
-
if (isSigningMessage(messageName)) {
|
|
95
|
+
if (isSigningMessage(messageName) || isMoneroSecretMessage(messageName)) {
|
|
81
96
|
return REDACTED;
|
|
82
97
|
}
|
|
83
98
|
return redactLogValue(value, new WeakSet());
|