@onekeyfe/hd-core 1.2.5-alpha.1 → 1.2.5-alpha.3
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,6 +1,10 @@
|
|
|
1
1
|
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { openFirmwareByteSource } from '../../src/api/firmware/FirmwareArtifactSource';
|
|
4
|
+
import {
|
|
5
|
+
updateResourceFromSource,
|
|
6
|
+
uploadFirmwareFromSource,
|
|
7
|
+
} from '../../src/api/firmware/uploadFirmware';
|
|
4
8
|
|
|
5
9
|
import type { Device } from '../../src/device/Device';
|
|
6
10
|
import type { FirmwareByteSource } from '../../src/api/firmware/FirmwareArtifactSource';
|
|
@@ -68,3 +72,71 @@ describe('uploadFirmwareFromSource', () => {
|
|
|
68
72
|
expect(requestedRanges.some(({ length }) => length === size)).toBe(false);
|
|
69
73
|
});
|
|
70
74
|
});
|
|
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,14 +54,6 @@ 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
|
-
|
|
65
57
|
test.each([
|
|
66
58
|
{ requiredSigners: ['11'], error: '32-byte hex public key' },
|
|
67
59
|
{ 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,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAA+B,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAiEnE,eAAO,MAAM,cAAc,eAAsB,MAAM,kBAKtD,CAAC;AASF,eAAO,MAAM,wBAAwB,eACvB,UAAU,GAAG,KAAK,aACnB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,kBAAkB,oBACR,OAAO,uBACJ,OAAO,qBAqJ7B,CAAC;AAEF,eAAO,MAAM,cAAc,eACb,UAAU,GAAG,KAA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AA0B,cAC1B,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,WACL,cAAc;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,CAAC,qBAc1E,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAwBpB,CAAC;AAEF,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,10 +49779,11 @@ const updateResourceFromSource = (typedCall, fileName, source, onConfirmAfter) =
|
|
|
49779
49779
|
!Number.isSafeInteger(dataLength) ||
|
|
49780
49780
|
dataLength === undefined ||
|
|
49781
49781
|
dataLength <= 0 ||
|
|
49782
|
-
offset
|
|
49782
|
+
offset >= source.size) {
|
|
49783
49783
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device requested an invalid firmware resource range');
|
|
49784
49784
|
}
|
|
49785
|
-
const
|
|
49785
|
+
const chunkLength = Math.min(dataLength, source.size - offset);
|
|
49786
|
+
const chunk = new Uint8Array(yield source.readAt(offset, chunkLength));
|
|
49786
49787
|
response = yield typedCall('ResourceAck', ['ResourceRequest', 'Success'], {
|
|
49787
49788
|
data_chunk: bytesToHex$1(chunk),
|
|
49788
49789
|
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
|
+
"version": "1.2.5-alpha.3",
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.5-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.5-alpha.3",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.5-alpha.3",
|
|
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": "f42cd4853a78c57ad8bcaf97872f315b2871aca2"
|
|
50
50
|
}
|
|
@@ -568,14 +568,15 @@ export const updateResourceFromSource = async (
|
|
|
568
568
|
!Number.isSafeInteger(dataLength) ||
|
|
569
569
|
dataLength === undefined ||
|
|
570
570
|
dataLength <= 0 ||
|
|
571
|
-
offset
|
|
571
|
+
offset >= 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
|
|
578
|
+
const chunkLength = Math.min(dataLength, source.size - offset);
|
|
579
|
+
const chunk = new Uint8Array(await source.readAt(offset, chunkLength));
|
|
579
580
|
response = await typedCall('ResourceAck', ['ResourceRequest', 'Success'], {
|
|
580
581
|
data_chunk: bytesToHex(chunk),
|
|
581
582
|
hash: bytesToHex(blake2s(chunk)),
|