@onekeyfe/hd-transport 1.2.0-alpha.67 → 1.2.0-alpha.69

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.
@@ -470,6 +470,7 @@
470
470
  "MessageType_DeviceSessionAskPin": 61202,
471
471
  "MessageType_DeviceSessionAskPassphrase": 61203,
472
472
  "MessageType_PortfolioUpdate": 61400,
473
+ "MessageType_NftUpdate": 61500,
473
474
  "MessageType_OnboardingStatusGet": 61600,
474
475
  "MessageType_OnboardingStatus": 61601
475
476
  },
@@ -12200,11 +12201,26 @@
12200
12201
  "DeviceSessionError_Busy": 5
12201
12202
  }
12202
12203
  },
12204
+ "DeviceSessionSeedDomain": {
12205
+ "values": {
12206
+ "SeedDomain_Standard": 1,
12207
+ "SeedDomain_Cardano": 2
12208
+ }
12209
+ },
12203
12210
  "DeviceSessionGet": {
12204
12211
  "fields": {
12205
12212
  "session_id": {
12206
12213
  "type": "bytes",
12207
12214
  "id": 1
12215
+ },
12216
+ "btc_test_address": {
12217
+ "type": "string",
12218
+ "id": 2
12219
+ },
12220
+ "seed_domains": {
12221
+ "rule": "repeated",
12222
+ "type": "DeviceSessionSeedDomain",
12223
+ "id": 3
12208
12224
  }
12209
12225
  }
12210
12226
  },
@@ -12538,6 +12554,15 @@
12538
12554
  }
12539
12555
  }
12540
12556
  },
12557
+ "NftUpdate": {
12558
+ "fields": {
12559
+ "file_name_no_ext": {
12560
+ "rule": "required",
12561
+ "type": "string",
12562
+ "id": 1
12563
+ }
12564
+ }
12565
+ },
12541
12566
  "OnboardingStep": {
12542
12567
  "values": {
12543
12568
  "ONBOARDING_STEP_UNKNOWN": 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport",
3
- "version": "1.2.0-alpha.67",
3
+ "version": "1.2.0-alpha.69",
4
4
  "description": "Transport layer abstractions and utilities for OneKey hardware SDK.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -28,5 +28,5 @@
28
28
  "long": "^4.0.0",
29
29
  "protobufjs": "^6.11.2"
30
30
  },
31
- "gitHead": "5fea66e8c65a1fab2ccc099b2811c8749b2487e0"
31
+ "gitHead": "c6baed25917e3c3f027f83dfc23cde85400de558"
32
32
  }
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ export type {
36
36
  OneKeyDeviceInfoWithSession,
37
37
  MessageFromOneKey,
38
38
  TransportCallOptions,
39
+ TransportWriteMetrics,
39
40
  LowlevelTransportSharedPlugin,
40
41
  LowLevelDevice,
41
42
  OneKeyDeviceInfoBase,
@@ -10,7 +10,7 @@ import * as check from '../../utils/highlevel-checks';
10
10
  import { LogBlockCommand } from '../../utils/logBlockCommand';
11
11
 
12
12
  import type { Root } from 'protobufjs/light';
13
- import type { MessageFromOneKey } from '../../types';
13
+ import type { MessageFromOneKey, TransportWriteMetrics } from '../../types';
14
14
 
15
15
  export * from './errors';
16
16
 
@@ -23,6 +23,7 @@ export type ProtocolV2CallContext = {
23
23
  messageName: string;
24
24
  timeoutMs?: number;
25
25
  highVolume: boolean;
26
+ writeWithResponse?: boolean;
26
27
  generation: number;
27
28
  signal: AbortSignal;
28
29
  };
@@ -52,6 +53,8 @@ export type ProtocolV2CallOptions = {
52
53
  expectedTypes?: string[];
53
54
  intermediateTypes?: string[];
54
55
  onIntermediateResponse?: (response: MessageFromOneKey) => void;
56
+ onWriteCompleted?: (metrics: TransportWriteMetrics) => void;
57
+ writeWithResponse?: boolean;
55
58
  };
56
59
 
57
60
  export { concatUint8Arrays, ProtocolV2FrameAssembler };
@@ -220,6 +223,9 @@ export class ProtocolV2Session {
220
223
  messageName: name,
221
224
  timeoutMs,
222
225
  highVolume: shouldReduceDebug,
226
+ ...(callOptions.writeWithResponse === undefined
227
+ ? {}
228
+ : { writeWithResponse: callOptions.writeWithResponse }),
223
229
  generation,
224
230
  signal: abortController.signal,
225
231
  };
@@ -239,7 +245,16 @@ export class ProtocolV2Session {
239
245
  );
240
246
  }
241
247
 
248
+ const writeStartedAt = Date.now();
242
249
  await writeFrame(frame, baseCallContext);
250
+ try {
251
+ callOptions.onWriteCompleted?.({
252
+ elapsedMs: Math.max(Date.now() - writeStartedAt, 0),
253
+ frameBytes: frame.byteLength,
254
+ });
255
+ } catch (error) {
256
+ logger?.error?.(`${logPrefix} write metrics callback failed: ${String(error)}`);
257
+ }
243
258
 
244
259
  // Some Protocol V2 operations emit progress notifications before the
245
260
  // terminal response. Consume those frames here so callers still see a
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from 'buffer';
2
2
  import ByteBuffer from 'bytebuffer';
3
+ import { Enum } from 'protobufjs/light';
3
4
 
4
5
  import { isPrimitiveField } from '../../utils/protobuf';
5
6
 
@@ -49,7 +50,10 @@ export function patch(Message: Type, payload: any) {
49
50
  // repeated
50
51
  if (field.repeated) {
51
52
  const RefMessage = Message.lookupTypeOrEnum(field.type);
52
- patched[key] = value.map((v: any) => patch(RefMessage, v));
53
+ patched[key] =
54
+ RefMessage instanceof Enum
55
+ ? value.map((v: any) => transform(field.type, v))
56
+ : value.map((v: any) => patch(RefMessage, v));
53
57
  }
54
58
  // message type
55
59
  else if (typeof value === 'object' && value !== null) {
@@ -4980,9 +4980,16 @@ export enum DeviceSessionErrorCode {
4980
4980
  DeviceSessionError_Busy = 5,
4981
4981
  }
4982
4982
 
4983
+ export enum DeviceSessionSeedDomain {
4984
+ SeedDomain_Standard = 1,
4985
+ SeedDomain_Cardano = 2,
4986
+ }
4987
+
4983
4988
  // DeviceSessionGet
4984
4989
  export type DeviceSessionGet = {
4985
4990
  session_id?: string;
4991
+ btc_test_address?: string;
4992
+ seed_domains: DeviceSessionSeedDomain[];
4986
4993
  };
4987
4994
 
4988
4995
  // DeviceSession
@@ -5118,6 +5125,11 @@ export type InternalMyAddressRequest = {
5118
5125
  derive_type: number;
5119
5126
  };
5120
5127
 
5128
+ // NftUpdate
5129
+ export type NftUpdate = {
5130
+ file_name_no_ext: string;
5131
+ };
5132
+
5121
5133
  export enum OnboardingStep {
5122
5134
  ONBOARDING_STEP_UNKNOWN = 0,
5123
5135
  ONBOARDING_STEP_CHECKING = 1,
@@ -5908,6 +5920,7 @@ export type MessageType = {
5908
5920
  FilesystemDirRemove: FilesystemDirRemove;
5909
5921
  FilesystemFormat: FilesystemFormat;
5910
5922
  InternalMyAddressRequest: InternalMyAddressRequest;
5923
+ NftUpdate: NftUpdate;
5911
5924
  OnboardingSetupStatus: OnboardingSetupStatus;
5912
5925
  OnboardingStatusGet: OnboardingStatusGet;
5913
5926
  OnboardingStatus: OnboardingStatus;
@@ -58,11 +58,20 @@ export type AcquireInput = {
58
58
 
59
59
  export type MessageFromOneKey = { type: string; message: Record<string, any> };
60
60
 
61
+ export type TransportWriteMetrics = {
62
+ elapsedMs: number;
63
+ frameBytes: number;
64
+ };
65
+
61
66
  export type TransportCallOptions = {
62
67
  timeoutMs?: number;
63
68
  expectedTypes?: string[];
64
69
  intermediateTypes?: string[];
65
70
  onIntermediateResponse?: (response: MessageFromOneKey) => void;
71
+ /** Called after the complete request frame has been submitted to the transport. */
72
+ onWriteCompleted?: (metrics: TransportWriteMetrics) => void;
73
+ /** Prefer acknowledged BLE characteristic writes for this call when supported. */
74
+ writeWithResponse?: boolean;
66
75
  };
67
76
 
68
77
  type ITransportInitFn = (