@onekeyfe/hd-core 1.2.5-alpha.3 → 1.2.5-alpha.4

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,10 +1,6 @@
1
1
  import { EDeviceType } from '@onekeyfe/hd-shared';
2
2
 
3
- import { openFirmwareByteSource } from '../../src/api/firmware/FirmwareArtifactSource';
4
- import {
5
- updateResourceFromSource,
6
- uploadFirmwareFromSource,
7
- } from '../../src/api/firmware/uploadFirmware';
3
+ import { uploadFirmwareFromSource } from '../../src/api/firmware/uploadFirmware';
8
4
 
9
5
  import type { Device } from '../../src/device/Device';
10
6
  import type { FirmwareByteSource } from '../../src/api/firmware/FirmwareArtifactSource';
@@ -72,71 +68,3 @@ describe('uploadFirmwareFromSource', () => {
72
68
  expect(requestedRanges.some(({ length }) => length === size)).toBe(false);
73
69
  });
74
70
  });
75
-
76
- describe('updateResourceFromSource', () => {
77
- it('serves the remaining bytes when Touch requests a full final resource chunk', async () => {
78
- const chunkSize = 16 * 1024;
79
- const bytes = new Uint8Array(chunkSize * 2 + 3);
80
- bytes.fill(0x5a, chunkSize, chunkSize * 2);
81
- bytes.set([1, 2, 3], chunkSize * 2);
82
- const source = await openFirmwareByteSource({ binary: bytes.buffer });
83
- if (!source) {
84
- throw new Error('Expected a firmware byte source');
85
- }
86
- const readAt = jest.spyOn(source, 'readAt');
87
- const typedCall = jest
88
- .fn()
89
- .mockResolvedValueOnce({
90
- type: 'ResourceRequest',
91
- message: { offset: chunkSize, data_length: chunkSize },
92
- })
93
- .mockResolvedValueOnce({
94
- type: 'ResourceRequest',
95
- message: { offset: chunkSize * 2, data_length: chunkSize },
96
- })
97
- .mockResolvedValueOnce({ type: 'Success', message: { message: 'updated' } });
98
-
99
- try {
100
- await expect(
101
- updateResourceFromSource(typedCall as never, 'icon.png', source)
102
- ).resolves.toEqual({ message: 'updated' });
103
- expect(typedCall).toHaveBeenCalledTimes(3);
104
- expect(readAt).toHaveBeenNthCalledWith(2, chunkSize, chunkSize);
105
- expect(readAt).toHaveBeenNthCalledWith(3, chunkSize * 2, 3);
106
- expect(typedCall).toHaveBeenNthCalledWith(
107
- 2,
108
- 'ResourceAck',
109
- ['ResourceRequest', 'Success'],
110
- expect.objectContaining({ data_chunk: '5a'.repeat(chunkSize) })
111
- );
112
- expect(typedCall).toHaveBeenNthCalledWith(
113
- 3,
114
- 'ResourceAck',
115
- ['ResourceRequest', 'Success'],
116
- expect.objectContaining({ data_chunk: '010203' })
117
- );
118
- } finally {
119
- await source.close();
120
- }
121
- });
122
-
123
- it('rejects a resource request starting beyond the last byte', async () => {
124
- const source = await openFirmwareByteSource({ binary: new Uint8Array(3).buffer });
125
- if (!source) {
126
- throw new Error('Expected a firmware byte source');
127
- }
128
- const typedCall = jest.fn().mockResolvedValueOnce({
129
- type: 'ResourceRequest',
130
- message: { offset: source.size, data_length: 16 * 1024 },
131
- });
132
-
133
- try {
134
- await expect(
135
- updateResourceFromSource(typedCall as never, 'icon.png', source)
136
- ).rejects.toThrow('Device requested an invalid firmware resource range');
137
- expect(typedCall).toHaveBeenCalledTimes(1);
138
- } finally {
139
- await source.close();
140
- }
141
- });
142
- });
@@ -54,6 +54,14 @@ describe('SolSignOffchainMessage', () => {
54
54
  });
55
55
  });
56
56
 
57
+ test('maps omitted required signers to an empty repeated field', () => {
58
+ const method = createMethod({ requiredSigners: undefined });
59
+
60
+ method.init();
61
+
62
+ expect(method.params.required_signers).toEqual([]);
63
+ });
64
+
57
65
  test.each([
58
66
  { requiredSigners: ['11'], error: '32-byte hex public key' },
59
67
  { requiredSigners: [signerB, signerA], error: 'strictly sorted and unique' },
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;AACnF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB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,eAAO,MAAM,gBAAgB,cAChB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,QACR,WAAW,qBAWlB,CAAC;AAEF,eAAO,MAAM,0BAA0B,cAC1B,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,kBAAkB,qBAU3B,CAAC"}
package/dist/index.js CHANGED
@@ -49779,11 +49779,10 @@ const updateResourceFromSource = (typedCall, fileName, source, onConfirmAfter) =
49779
49779
  !Number.isSafeInteger(dataLength) ||
49780
49780
  dataLength === undefined ||
49781
49781
  dataLength <= 0 ||
49782
- offset >= source.size) {
49782
+ offset + dataLength > source.size) {
49783
49783
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device requested an invalid firmware resource range');
49784
49784
  }
49785
- const chunkLength = Math.min(dataLength, source.size - offset);
49786
- const chunk = new Uint8Array(yield source.readAt(offset, chunkLength));
49785
+ const chunk = new Uint8Array(yield source.readAt(offset, dataLength));
49787
49786
  response = yield typedCall('ResourceAck', ['ResourceRequest', 'Success'], {
49788
49787
  data_chunk: bytesToHex$1(chunk),
49789
49788
  hash: bytesToHex$1(blake2s.blake2s(chunk)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.5-alpha.3",
3
+ "version": "1.2.5-alpha.4",
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.5-alpha.3",
29
- "@onekeyfe/hd-transport": "1.2.5-alpha.3",
28
+ "@onekeyfe/hd-shared": "1.2.5-alpha.4",
29
+ "@onekeyfe/hd-transport": "1.2.5-alpha.4",
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": "f42cd4853a78c57ad8bcaf97872f315b2871aca2"
49
+ "gitHead": "ae361a665a1301285834b3682046ee08aca05b2c"
50
50
  }
@@ -568,15 +568,14 @@ export const updateResourceFromSource = async (
568
568
  !Number.isSafeInteger(dataLength) ||
569
569
  dataLength === undefined ||
570
570
  dataLength <= 0 ||
571
- offset >= source.size
571
+ offset + dataLength > source.size
572
572
  ) {
573
573
  throw ERRORS.TypedError(
574
574
  HardwareErrorCode.RuntimeError,
575
575
  'Device requested an invalid firmware resource range'
576
576
  );
577
577
  }
578
- const chunkLength = Math.min(dataLength, source.size - offset);
579
- const chunk = new Uint8Array(await source.readAt(offset, chunkLength));
578
+ const chunk = new Uint8Array(await source.readAt(offset, dataLength));
580
579
  response = await typedCall('ResourceAck', ['ResourceRequest', 'Success'], {
581
580
  data_chunk: bytesToHex(chunk),
582
581
  hash: bytesToHex(blake2s(chunk)),