@onekeyfe/hd-core 1.2.0-alpha.107 → 1.2.0-alpha.108

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.
Files changed (57) hide show
  1. package/__tests__/DeviceCommands.test.ts +140 -26
  2. package/__tests__/base64Data.test.ts +70 -0
  3. package/__tests__/device-lifecycle-events.test.ts +113 -2
  4. package/__tests__/device-pool-state.test.ts +25 -0
  5. package/__tests__/deviceSettings.test.ts +0 -1
  6. package/__tests__/deviceUploadNft.test.ts +33 -4
  7. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +178 -0
  8. package/__tests__/get-device-state.test.ts +52 -13
  9. package/__tests__/logBlockEvent.test.ts +13 -1
  10. package/__tests__/protocol-v2.test.ts +762 -124
  11. package/__tests__/refresh-device-state.test.ts +3 -1
  12. package/__tests__/resourceBase64Boundary.test.ts +48 -0
  13. package/__tests__/ton-sign-message.test.ts +84 -0
  14. package/dist/api/FirmwareUpdateV4.d.ts +10 -3
  15. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  16. package/dist/api/UploadPortfolio.d.ts +1 -1
  17. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  18. package/dist/api/helpers/base64Data.d.ts +16 -0
  19. package/dist/api/helpers/base64Data.d.ts.map +1 -0
  20. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +2 -3
  21. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  22. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +2 -3
  23. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  24. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  25. package/dist/core/index.d.ts.map +1 -1
  26. package/dist/device/Device.d.ts +7 -2
  27. package/dist/device/Device.d.ts.map +1 -1
  28. package/dist/device/DeviceCommands.d.ts.map +1 -1
  29. package/dist/device/DevicePool.d.ts.map +1 -1
  30. package/dist/events/logBlockEvent.d.ts.map +1 -1
  31. package/dist/index.d.ts +11 -14
  32. package/dist/index.js +455 -200
  33. package/dist/protocols/protocol-v2/features.d.ts +9 -1
  34. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  35. package/dist/protocols/protocol-v2/index.d.ts +2 -2
  36. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  37. package/dist/types/api/protocolV2.d.ts +1 -1
  38. package/dist/types/api/protocolV2.d.ts.map +1 -1
  39. package/dist/utils/pro2Nft.d.ts +7 -0
  40. package/dist/utils/pro2Nft.d.ts.map +1 -1
  41. package/package.json +6 -4
  42. package/src/api/FirmwareUpdateV4.ts +326 -174
  43. package/src/api/UploadPortfolio.ts +9 -2
  44. package/src/api/helpers/base64Data.ts +85 -0
  45. package/src/api/protocol-v2/DeviceUploadNft.ts +56 -8
  46. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +37 -18
  47. package/src/api/ton/TonSignMessage.ts +5 -3
  48. package/src/core/index.ts +6 -2
  49. package/src/device/Device.ts +53 -31
  50. package/src/device/DeviceCommands.ts +4 -14
  51. package/src/device/DevicePool.ts +6 -2
  52. package/src/events/logBlockEvent.ts +14 -1
  53. package/src/protocols/protocol-v2/features.ts +19 -2
  54. package/src/protocols/protocol-v2/index.ts +2 -0
  55. package/src/types/api/protocolV2.ts +1 -1
  56. package/src/utils/deviceSettings.ts +1 -1
  57. package/src/utils/pro2Nft.ts +31 -8
@@ -68,7 +68,7 @@ export declare function deviceUploadNft(
68
68
  export declare function uploadPortfolio(
69
69
  connectId: string,
70
70
  params: {
71
- packageBytes: ArrayBuffer | Uint8Array | Blob;
71
+ packageBase64: string;
72
72
  timeoutMs?: number | string;
73
73
  }
74
74
  ): Response<FileInfo & { portfolioUpdated: true }>;
@@ -200,7 +200,7 @@ export const getAutoShutDownOptions = (
200
200
  return withNever([60_000, 120_000, 300_000, 600_000], protocol);
201
201
  case EDeviceType.Pro2:
202
202
  case EDeviceType.Neo:
203
- return withNever([60_000, 120_000, 300_000, 600_000, 1_800_000], protocol);
203
+ return withNever([60_000, 120_000, 300_000, 600_000], protocol);
204
204
  default:
205
205
  return [];
206
206
  }
@@ -109,6 +109,34 @@ export function buildPro2NftBundle(options: {
109
109
  const { image, thumbnail, title, subtitle, timestampMs } = options;
110
110
  assertImage('image', image, PRO2_NFT_IMAGE_WIDTH, PRO2_NFT_IMAGE_HEIGHT);
111
111
  assertImage('thumbnail', thumbnail, PRO2_NFT_THUMBNAIL_WIDTH, PRO2_NFT_THUMBNAIL_HEIGHT);
112
+ const encodedImage = encodePro2Image({ ...image, alphaMode: 'black-background' }).data;
113
+ const encodedThumbnail = encodePro2Image({
114
+ ...thumbnail,
115
+ alphaMode: 'black-background',
116
+ }).data;
117
+ return buildPro2NftBundleFromEncodedImages({
118
+ image: encodedImage,
119
+ thumbnail: encodedThumbnail,
120
+ title,
121
+ subtitle,
122
+ timestampMs,
123
+ });
124
+ }
125
+
126
+ export function buildPro2NftBundleFromEncodedImages(options: {
127
+ image: Uint8Array;
128
+ thumbnail: Uint8Array;
129
+ title: string;
130
+ subtitle: string;
131
+ timestampMs: number;
132
+ }): Pro2NftBundle {
133
+ const { image, thumbnail, title, subtitle, timestampMs } = options;
134
+ if (!(image instanceof Uint8Array) || image.byteLength === 0) {
135
+ throw invalidParameter('Parameter [image] must contain encoded NFT image data.');
136
+ }
137
+ if (!(thumbnail instanceof Uint8Array) || thumbnail.byteLength === 0) {
138
+ throw invalidParameter('Parameter [thumbnail] must contain encoded NFT thumbnail data.');
139
+ }
112
140
  const titleLength = typeof title === 'string' ? utf8Length(title) : 0;
113
141
  const subtitleLength =
114
142
  typeof subtitle === 'string' ? utf8Length(subtitle) : Number.POSITIVE_INFINITY;
@@ -122,21 +150,16 @@ export function buildPro2NftBundle(options: {
122
150
  throw invalidParameter('Parameter [timestampMs] must be a positive safe integer.');
123
151
  }
124
152
 
125
- const encodedImage = encodePro2Image({ ...image, alphaMode: 'black-background' }).data;
126
- const encodedThumbnail = encodePro2Image({
127
- ...thumbnail,
128
- alphaMode: 'black-background',
129
- }).data;
130
153
  const metadata = new TextEncoder().encode(JSON.stringify({ title, subtitle }));
131
154
  if (metadata.byteLength === 0 || metadata.byteLength > 512) {
132
155
  throw invalidParameter('Pro2 NFT metadata must contain 1 to 512 UTF-8 bytes.');
133
156
  }
134
157
 
135
- const hash8 = bytesToHex(blake2s(encodedImage)).slice(0, 8);
158
+ const hash8 = bytesToHex(blake2s(image)).slice(0, 8);
136
159
  return {
137
160
  basename: `nft-${hash8}-${timestampMs}`,
138
- image: encodedImage,
139
- thumbnail: encodedThumbnail,
161
+ image,
162
+ thumbnail,
140
163
  metadata,
141
164
  };
142
165
  }