@onekeyfe/hd-transport 1.2.8-alpha.10 → 1.2.8-alpha.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocols/index.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,qBAAqB,EAA+C,MAAM,cAAc,CAAC;AAElG,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAShE,OAAO,EAGL,kBAAkB,EAClB,UAAU,EACX,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,eAAO,MAAM,iCAAiC,QAAQ,CAAC;AAEvD,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAkGF,eAAO,MAAM,UAAU;;;;;;;;;;CAOtB,CAAC;AAEF,eAAO,MAAM,UAAU;;;0BAIC,iBAAiB,SAAS,UAAU;;;;;;;;;;yBAgB/C,iBAAiB,QACpB,MAAM,QACN,OAAO,MAAM,EAAE,OAAO,CAAC,YACpB,sBAAsB;yBAkBZ,iBAAiB,SAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;CAqC1D,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocols/index.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,qBAAqB,EAA+C,MAAM,cAAc,CAAC;AAElG,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAGL,kBAAkB,EAClB,UAAU,EACX,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,eAAO,MAAM,iCAAiC,QAAQ,CAAC;AAEvD,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAqHF,eAAO,MAAM,UAAU;;;;;;;;;;CAOtB,CAAC;AAEF,eAAO,MAAM,UAAU;;;0BAIC,iBAAiB,SAAS,UAAU;;;;;;;;;;yBAgB/C,iBAAiB,QACpB,MAAM,QACN,OAAO,MAAM,EAAE,OAAO,CAAC,YACpB,sBAAsB;yBAkBZ,iBAAiB,SAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;CAqC1D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/serialization/protobuf/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAI7C,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,iBAmCvD;AAED,eAAO,MAAM,qBAAqB,aAAc,SAAS,IAAI,QAAQ,MAAM;;;CAiB1E,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAc,SAAS,IAAI,UAAU,MAAM;;;CAgB5E,CAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/serialization/protobuf/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,iBAMvD;AAED,eAAO,MAAM,qBAAqB,aAAc,SAAS,IAAI,QAAQ,MAAM;;;CAiB1E,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAc,SAAS,IAAI,UAAU,MAAM;;;CAgB5E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport",
3
- "version": "1.2.8-alpha.10",
3
+ "version": "1.2.8-alpha.12",
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",
@@ -11,9 +11,9 @@
11
11
  "access": "public"
12
12
  },
13
13
  "scripts": {
14
- "dev": "node scripts/protobuf-static.js && rimraf dist && rollup -c ../../build/rollup.config.js -w",
15
- "build": "node scripts/protobuf-static.js && rimraf dist && rollup -c ../../build/rollup.config.js",
16
- "test": "node scripts/protobuf-static.js && jest",
14
+ "dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
15
+ "build": "rimraf dist && rollup -c ../../build/rollup.config.js",
16
+ "test": "jest",
17
17
  "lint": "eslint .",
18
18
  "lint:fix": "eslint . --fix",
19
19
  "update:protobuf": "./scripts/protobuf-build.sh"
@@ -28,5 +28,5 @@
28
28
  "long": "^4.0.0",
29
29
  "protobufjs": "^6.11.2"
30
30
  },
31
- "gitHead": "47d2f63acb8e5fa9ee623c060af7c9f83ad6f939"
31
+ "gitHead": "69c7334a3d32e0b55f1b8e57420754fdb5fcd645"
32
32
  }
@@ -1,17 +1,12 @@
1
1
  import ByteBuffer from 'bytebuffer';
2
- import { Reader } from 'protobufjs/light';
2
+ import { Reader, Type } from 'protobufjs/light';
3
3
 
4
4
  import { encodeEnvelopeMessage, encodeMessageChunks, encodeTransportPackets } from './v1/packets';
5
5
  import { decodeFirstChunk } from './v1/decode';
6
6
  import { decodeMessage as decodeV1Message } from './v1/receive';
7
- import {
8
- createMessageFromName,
9
- createMessageFromType,
10
- parseConfigure,
11
- } from '../serialization/protobuf/messages';
7
+ import { createMessageFromName, createMessageFromType } from '../serialization/protobuf/messages';
12
8
  import { encode as encodeProtobuf } from '../serialization/protobuf/encode';
13
9
  import { decode as decodeProtobuf } from '../serialization/protobuf/decode';
14
- import { legacyProtocolInfoSchema } from '../../lib/protobuf-static';
15
10
  import {
16
11
  decodeFrame as decodeV2Frame,
17
12
  encodeProtobufFrame,
@@ -35,8 +30,27 @@ type ProtocolV2FrameOptions = {
35
30
  seq?: number;
36
31
  };
37
32
 
38
- const LEGACY_PROTOCOL_V2_PROTOCOL_INFO =
39
- parseConfigure(legacyProtocolInfoSchema).lookupType('LegacyProtocolInfo');
33
+ const LEGACY_PROTOCOL_V2_PROTOCOL_INFO = Type.fromJSON('LegacyProtocolInfo', {
34
+ fields: {
35
+ version: {
36
+ rule: 'required',
37
+ type: 'uint32',
38
+ id: 1,
39
+ },
40
+ supported_messages: {
41
+ rule: 'repeated',
42
+ type: 'uint32',
43
+ id: 2,
44
+ options: {
45
+ packed: false,
46
+ },
47
+ },
48
+ protobuf_definition: {
49
+ type: 'string',
50
+ id: 3,
51
+ },
52
+ },
53
+ });
40
54
 
41
55
  const decodeLegacyProtocolV2ProtocolInfo = (pbPayload: Uint8Array) => {
42
56
  const byteBuffer = ByteBuffer.wrap(Buffer.from(pbPayload) as unknown as ArrayBuffer);
@@ -1,42 +1,11 @@
1
1
  import * as protobuf from 'protobufjs/light';
2
2
 
3
- import { schemaKey, schemas } from '../../../lib/protobuf-static';
4
-
5
3
  export function parseConfigure(data: protobuf.INamespace) {
6
4
  // @ts-ignore [compatiblity]: connect is sending stringified json
7
- const schema = typeof data === 'string' ? JSON.parse(data) : data;
8
- const key = schemaKey(schema);
9
- const createConstructors = schemas[key];
10
- // Field resolution mutates options; keep built-in descriptors reusable across connections.
11
- const messages = protobuf.Root.fromJSON(
12
- createConstructors ? JSON.parse(JSON.stringify(schema)) : schema
13
- );
14
- if (createConstructors) {
15
- const constructors = createConstructors();
16
- const types: protobuf.Type[] = [];
17
- const collect = (namespace: protobuf.Namespace) => {
18
- if (namespace instanceof protobuf.Type) types.push(namespace);
19
- namespace.nestedArray.forEach(child => {
20
- if (child instanceof protobuf.Namespace) collect(child);
21
- });
22
- };
23
- collect(messages);
24
- // Register every constructor before resolving fields, which access parent.ctor.
25
- types.forEach(type => {
26
- type.ctor = constructors[type.fullName];
27
- });
28
- types.forEach(type => {
29
- const constructor = constructors[type.fullName];
30
- type.encode = constructor.encode;
31
- type.decode = constructor.decode;
32
- type.verify = constructor.verify;
33
- type.fromObject = constructor.fromObject;
34
- type.toObject = constructor.toObject;
35
- type.setup = () => type;
36
- });
37
- messages.resolveAll();
5
+ if (typeof data === 'string') {
6
+ return protobuf.Root.fromJSON(JSON.parse(data));
38
7
  }
39
- return messages;
8
+ return protobuf.Root.fromJSON(data);
40
9
  }
41
10
 
42
11
  export const createMessageFromName = (messages: protobuf.Root, name: string) => {
@@ -1,5 +0,0 @@
1
- import type { Constructor, INamespace, Type } from 'protobufjs/light';
2
- type StaticMessageConstructor = Constructor<{}> & Pick<Type, 'encode' | 'decode' | 'verify' | 'fromObject' | 'toObject'>;
3
- export function schemaKey(schema: INamespace): string;
4
- export const schemas: Partial<Record<string, () => Record<string, StaticMessageConstructor>>>;
5
- export const legacyProtocolInfoSchema: INamespace;