@onekeyfe/hwk-trezor-core 1.2.8-alpha.11 → 1.2.8-alpha.13

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.
package/dist/index.d.mts CHANGED
@@ -206,7 +206,10 @@ type TrezorThpSessionOptions = {
206
206
  * it back via `knownCredentials` on the next connect to skip pairing UX.
207
207
  */
208
208
  onPairingCredentialsChanged?: (payload: {
209
+ /** This device's credentials only, never other devices'. */
209
210
  credentials: TrezorThpCredentials[];
211
+ /** Credentials the device rejected; a host keeping one list for all devices drops these. */
212
+ removed?: TrezorThpCredentials[];
210
213
  }) => Promise<void> | void;
211
214
  logger?: TrezorDebugLogger;
212
215
  };
package/dist/index.d.ts CHANGED
@@ -206,7 +206,10 @@ type TrezorThpSessionOptions = {
206
206
  * it back via `knownCredentials` on the next connect to skip pairing UX.
207
207
  */
208
208
  onPairingCredentialsChanged?: (payload: {
209
+ /** This device's credentials only, never other devices'. */
209
210
  credentials: TrezorThpCredentials[];
211
+ /** Credentials the device rejected; a host keeping one list for all devices drops these. */
212
+ removed?: TrezorThpCredentials[];
210
213
  }) => Promise<void> | void;
211
214
  logger?: TrezorDebugLogger;
212
215
  };
package/dist/index.js CHANGED
@@ -7901,6 +7901,7 @@ __export(messages_solana_pb_exports, {
7901
7901
  SolanaGetAddressSchema: () => SolanaGetAddressSchema,
7902
7902
  SolanaGetPublicKeySchema: () => SolanaGetPublicKeySchema,
7903
7903
  SolanaMessageSignatureSchema: () => SolanaMessageSignatureSchema,
7904
+ SolanaOffchainMessageV1Schema: () => SolanaOffchainMessageV1Schema,
7904
7905
  SolanaPublicKeySchema: () => SolanaPublicKeySchema,
7905
7906
  SolanaSignMessageSchema: () => SolanaSignMessageSchema,
7906
7907
  SolanaSignTxSchema: () => SolanaSignTxSchema,
@@ -7912,7 +7913,7 @@ __export(messages_solana_pb_exports, {
7912
7913
  });
7913
7914
  init_buffer();
7914
7915
  var file_messages_solana = fileDesc(
7915
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AyABKAsyMS5ody50cmV6b3IubWVzc2FnZXMuc29sYW5hLlNvbGFuYVR4QWRkaXRpb25hbEluZm8SPgoLcGF5bWVudF9yZXEYBCABKAsyKS5ody50cmV6b3IubWVzc2FnZXMuY29tbW9uLlBheW1lbnRSZXF1ZXN0EhAKCGNodW5raWZ5GAUgASgIIiYKEVNvbGFuYVR4U2lnbmF0dXJlEhEKCXNpZ25hdHVyZRgBIAIoDCI7ChdTb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMRIPCgdtZXNzYWdlGAEgAigJEg8KB3NpZ25lcnMYAiADKAwigwEKEVNvbGFuYVNpZ25NZXNzYWdlEhEKCWFkZHJlc3NfbhgBIAMoDRIQCghjaHVua2lmeRgDIAEoCBJDCgdtZXNzYWdlGAQgAigLMjIuaHcudHJlem9yLm1lc3NhZ2VzLnNvbGFuYS5Tb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMUoECAIQAyJAChZTb2xhbmFNZXNzYWdlU2lnbmF0dXJlEhEKCXNpZ25hdHVyZRgBIAIoDBITCgtzaWduZWRfZGF0YRgCIAEoDCKGAQoTU29sYW5hVmVyaWZ5TWVzc2FnZRIQCghjaHVua2lmeRgCIAEoCBJDCgdtZXNzYWdlGAMgAigLMjIuaHcudHJlem9yLm1lc3NhZ2VzLnNvbGFuYS5Tb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMRISCgpzaWduYXR1cmVzGAQgAygMSgQIARACQjoKI2NvbS5zYXRvc2hpbGFicy50cmV6b3IubGliLnByb3RvYnVmQhNUcmV6b3JNZXNzYWdlU29sYW5h",
7916
7917
  [file_messages_common]
7917
7918
  );
7918
7919
  var SolanaGetPublicKeySchema = messageDesc(file_messages_solana, 0);
@@ -7923,9 +7924,10 @@ var SolanaTxTokenAccountInfoSchema = messageDesc(file_messages_solana, 4);
7923
7924
  var SolanaTxAdditionalInfoSchema = messageDesc(file_messages_solana, 5);
7924
7925
  var SolanaSignTxSchema = messageDesc(file_messages_solana, 6);
7925
7926
  var SolanaTxSignatureSchema = messageDesc(file_messages_solana, 7);
7926
- var SolanaSignMessageSchema = messageDesc(file_messages_solana, 8);
7927
- var SolanaMessageSignatureSchema = messageDesc(file_messages_solana, 9);
7928
- var SolanaVerifyMessageSchema = messageDesc(file_messages_solana, 10);
7927
+ var SolanaOffchainMessageV1Schema = messageDesc(file_messages_solana, 8);
7928
+ var SolanaSignMessageSchema = messageDesc(file_messages_solana, 9);
7929
+ var SolanaMessageSignatureSchema = messageDesc(file_messages_solana, 10);
7930
+ var SolanaVerifyMessageSchema = messageDesc(file_messages_solana, 11);
7929
7931
 
7930
7932
  // ../hwk-trezor-protobuf/src/definitions/messages-stellar_pb.js
7931
7933
  var messages_stellar_pb_exports = {};
@@ -11999,6 +12001,9 @@ var normalizeCreateAppSessionOptions = (options = {}) => {
11999
12001
  passphraseMode
12000
12002
  };
12001
12003
  };
12004
+ function thpPairingRefused(message) {
12005
+ return Object.assign(new Error(message), { code: "ThpPairingFailed" });
12006
+ }
12002
12007
  var TrezorDeviceSession = class {
12003
12008
  transport;
12004
12009
  connectionType;
@@ -12082,6 +12087,11 @@ var TrezorDeviceSession = class {
12082
12087
  this.log("error", "session.initialize.error", { error: errorToLog(error2) });
12083
12088
  throw error2;
12084
12089
  }
12090
+ if (this.connectionType === "ble" && this.currentFeatures?.bootloader_mode !== true) {
12091
+ this.core = void 0;
12092
+ this.currentFeatures = void 0;
12093
+ throw thpPairingRefused("Trezor Bluetooth requires the encrypted THP protocol");
12094
+ }
12085
12095
  this.log("info", "session.initialize.done", {
12086
12096
  protocol: this.protocol,
12087
12097
  features: summarizeFeatures(this.currentFeatures)
@@ -12249,6 +12259,36 @@ var TrezorDeviceSession = class {
12249
12259
  const response = await this.core.call("Initialize", {});
12250
12260
  this.currentFeatures = expectMessage(response, "Features").message;
12251
12261
  this.thpAppSessionActive = false;
12262
+ if (passphraseMode === "empty" && this.currentFeatures?.passphrase_protection == null) {
12263
+ expectMessage(
12264
+ await this.call("GetAddress", {
12265
+ address_n: [2147483692, 2147483649, 2147483648, 0, 0],
12266
+ coin_name: "Testnet",
12267
+ script_type: "SPENDADDRESS",
12268
+ show_display: false
12269
+ }),
12270
+ "Address"
12271
+ );
12272
+ expectMessage(await this.call("GetFeatures", {}), "Features");
12273
+ if (this.currentFeatures?.passphrase_protection == null) {
12274
+ throw new TrezorFailureError({
12275
+ type: "Failure",
12276
+ message: {
12277
+ code: "Failure_DataError",
12278
+ message: "Empty passphrase cannot be enforced: device did not report its passphrase setting"
12279
+ }
12280
+ });
12281
+ }
12282
+ }
12283
+ if (passphraseMode === "empty" && this.currentFeatures?.passphrase_protection === true && this.currentFeatures?.passphrase_always_on_device === true) {
12284
+ throw new TrezorFailureError({
12285
+ type: "Failure",
12286
+ message: {
12287
+ code: "Failure_DataError",
12288
+ message: "Empty passphrase cannot be enforced with PASSPHRASE_ALWAYS_ON_DEVICE enabled"
12289
+ }
12290
+ });
12291
+ }
12252
12292
  this.log("info", "v1.appSession.create.done", {
12253
12293
  features: summarizeFeatures(this.currentFeatures)
12254
12294
  });
@@ -12376,7 +12416,8 @@ var TrezorThpSession = class {
12376
12416
  }
12377
12417
  const pairingMethods = getPairingMethods(
12378
12418
  properties.pairing_methods,
12379
- this.options.pairingMethods ?? ["CodeEntry", "QrCode", "NFC", "SkipPairing"]
12419
+ // SkipPairing is for emulators and debug firmware only; production devices offer CodeEntry.
12420
+ this.options.pairingMethods ?? ["CodeEntry", "QrCode", "NFC"]
12380
12421
  );
12381
12422
  if (pairingMethods.length === 0) {
12382
12423
  throw new Error("No compatible THP pairing method");
@@ -12443,12 +12484,16 @@ var TrezorThpSession = class {
12443
12484
  "ThpHandshakeCompletionResponse"
12444
12485
  );
12445
12486
  const completionState = completion.message.state;
12487
+ if (completionState !== 0 && !handshakeCredentials.credentials) {
12488
+ throw thpPairingRefused("Trezor reported a pairing that no stored credential confirms");
12489
+ }
12446
12490
  this.thpState.setIsPaired(completionState !== 0);
12447
12491
  this.thpState.setPhase("pairing");
12448
12492
  if (!completionState && handshakeCredentials.credentials) {
12449
12493
  this.thpState.removePairingCredential(handshakeCredentials.credentials);
12450
12494
  await this.options.onPairingCredentialsChanged?.({
12451
- credentials: this.thpState.pairingCredentials
12495
+ credentials: this.thpState.pairingCredentials,
12496
+ removed: [handshakeCredentials.credentials]
12452
12497
  });
12453
12498
  }
12454
12499
  this.log("info", "thp.handshake.done", {
@@ -12482,6 +12527,9 @@ var TrezorThpSession = class {
12482
12527
  selected_pairing_method: selectedMethod
12483
12528
  });
12484
12529
  if (selectMethod.type === "ThpEndResponse") {
12530
+ if (selectedMethod !== protocol_thp_exports.ThpPairingMethod.SkipPairing) {
12531
+ throw thpPairingRefused("Trezor ended pairing without completing the selected method");
12532
+ }
12485
12533
  this.thpState.setIsPaired(true);
12486
12534
  this.thpState.setPhase("paired");
12487
12535
  this.log("info", "thp.pair.done", { responseType: selectMethod.type });