@onekeyfe/hwk-trezor-core 1.2.8 → 1.2.10-alpha.2
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 +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +61 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
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
|
-
"
|
|
7916
|
+
"ChVtZXNzYWdlcy1zb2xhbmEucHJvdG8SGWh3LnRyZXpvci5tZXNzYWdlcy5zb2xhbmEiPQoSU29sYW5hR2V0UHVibGljS2V5EhEKCWFkZHJlc3NfbhgBIAMoDRIUCgxzaG93X2Rpc3BsYXkYAiABKAgiJQoPU29sYW5hUHVibGljS2V5EhIKCnB1YmxpY19rZXkYASACKAwiTQoQU29sYW5hR2V0QWRkcmVzcxIRCglhZGRyZXNzX24YASADKA0SFAoMc2hvd19kaXNwbGF5GAIgASgIEhAKCGNodW5raWZ5GAMgASgIIi0KDVNvbGFuYUFkZHJlc3MSDwoHYWRkcmVzcxgBIAIoCRILCgNtYWMYAiABKAwicgoYU29sYW5hVHhUb2tlbkFjY291bnRJbmZvEhQKDGJhc2VfYWRkcmVzcxgBIAIoCRIVCg10b2tlbl9wcm9ncmFtGAIgAigJEhIKCnRva2VuX21pbnQYAyACKAkSFQoNdG9rZW5fYWNjb3VudBgEIAIoCSKCAQoWU29sYW5hVHhBZGRpdGlvbmFsSW5mbxJRChR0b2tlbl9hY2NvdW50c19pbmZvcxgBIAMoCzIzLmh3LnRyZXpvci5tZXNzYWdlcy5zb2xhbmEuU29sYW5hVHhUb2tlbkFjY291bnRJbmZvEhUKDWVuY29kZWRfdG9rZW4YAiABKAwi1gEKDFNvbGFuYVNpZ25UeBIRCglhZGRyZXNzX24YASADKA0SFQoNc2VyaWFsaXplZF90eBgCIAIoDBJKCg9hZGRpdGlvbmFsX2luZm8YAyABKAsyMS5ody50cmV6b3IubWVzc2FnZXMuc29sYW5hLlNvbGFuYVR4QWRkaXRpb25hbEluZm8SPgoLcGF5bWVudF9yZXEYBCABKAsyKS5ody50cmV6b3IubWVzc2FnZXMuY29tbW9uLlBheW1lbnRSZXF1ZXN0EhAKCGNodW5raWZ5GAUgASgIIiYKEVNvbGFuYVR4U2lnbmF0dXJlEhEKCXNpZ25hdHVyZRgBIAIoDCI7ChdTb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMRIPCgdtZXNzYWdlGAEgAigJEg8KB3NpZ25lcnMYAiADKAwigwEKEVNvbGFuYVNpZ25NZXNzYWdlEhEKCWFkZHJlc3NfbhgBIAMoDRIQCghjaHVua2lmeRgDIAEoCBJDCgdtZXNzYWdlGAQgAigLMjIuaHcudHJlem9yLm1lc3NhZ2VzLnNvbGFuYS5Tb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMUoECAIQAyJAChZTb2xhbmFNZXNzYWdlU2lnbmF0dXJlEhEKCXNpZ25hdHVyZRgBIAIoDBITCgtzaWduZWRfZGF0YRgCIAEoDCKGAQoTU29sYW5hVmVyaWZ5TWVzc2FnZRIQCghjaHVua2lmeRgCIAEoCBJDCgdtZXNzYWdlGAMgAigLMjIuaHcudHJlem9yLm1lc3NhZ2VzLnNvbGFuYS5Tb2xhbmFPZmZjaGFpbk1lc3NhZ2VWMRISCgpzaWduYXR1cmVzGAQgAygMSgQIARACQjoKI2NvbS5zYXRvc2hpbGFicy50cmV6b3IubGliLnByb3RvYnVmQhNUcmV6b3JNZXNzYWdlU29sYW5h",
|
|
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
|
|
7927
|
-
var
|
|
7928
|
-
var
|
|
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 = {};
|
|
@@ -11274,7 +11276,8 @@ async function receive(receiver, protocol) {
|
|
|
11274
11276
|
} catch (e) {
|
|
11275
11277
|
console.warn("Protocol decode failed", {
|
|
11276
11278
|
error: e.message,
|
|
11277
|
-
|
|
11279
|
+
payloadLength: readResult.payload.length,
|
|
11280
|
+
payloadHead: readResult.payload.subarray(0, 2).toString("hex")
|
|
11278
11281
|
});
|
|
11279
11282
|
return error({ code: PROTOCOL_MALFORMED, message: e.message });
|
|
11280
11283
|
}
|
|
@@ -11999,6 +12002,9 @@ var normalizeCreateAppSessionOptions = (options = {}) => {
|
|
|
11999
12002
|
passphraseMode
|
|
12000
12003
|
};
|
|
12001
12004
|
};
|
|
12005
|
+
function thpPairingRefused(message) {
|
|
12006
|
+
return Object.assign(new Error(message), { code: "ThpPairingFailed" });
|
|
12007
|
+
}
|
|
12002
12008
|
var TrezorDeviceSession = class {
|
|
12003
12009
|
transport;
|
|
12004
12010
|
connectionType;
|
|
@@ -12082,6 +12088,11 @@ var TrezorDeviceSession = class {
|
|
|
12082
12088
|
this.log("error", "session.initialize.error", { error: errorToLog(error2) });
|
|
12083
12089
|
throw error2;
|
|
12084
12090
|
}
|
|
12091
|
+
if (this.connectionType === "ble" && this.currentFeatures?.bootloader_mode !== true) {
|
|
12092
|
+
this.core = void 0;
|
|
12093
|
+
this.currentFeatures = void 0;
|
|
12094
|
+
throw thpPairingRefused("Trezor Bluetooth requires the encrypted THP protocol");
|
|
12095
|
+
}
|
|
12085
12096
|
this.log("info", "session.initialize.done", {
|
|
12086
12097
|
protocol: this.protocol,
|
|
12087
12098
|
features: summarizeFeatures(this.currentFeatures)
|
|
@@ -12129,6 +12140,11 @@ var TrezorDeviceSession = class {
|
|
|
12129
12140
|
requestData = {};
|
|
12130
12141
|
continue;
|
|
12131
12142
|
}
|
|
12143
|
+
if ((response.type === "PinMatrixRequest" || response.type === "PassphraseRequest") && this.connectionType === "ble" && this.protocol === "v1") {
|
|
12144
|
+
this.core = void 0;
|
|
12145
|
+
this.currentFeatures = void 0;
|
|
12146
|
+
throw thpPairingRefused("Trezor Bluetooth requires the encrypted THP protocol");
|
|
12147
|
+
}
|
|
12132
12148
|
if (response.type === "PinMatrixRequest") {
|
|
12133
12149
|
const pin = await this.handlePinMatrixRequest(
|
|
12134
12150
|
response.message
|
|
@@ -12249,6 +12265,36 @@ var TrezorDeviceSession = class {
|
|
|
12249
12265
|
const response = await this.core.call("Initialize", {});
|
|
12250
12266
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
12251
12267
|
this.thpAppSessionActive = false;
|
|
12268
|
+
if (passphraseMode === "empty") {
|
|
12269
|
+
expectMessage(
|
|
12270
|
+
await this.call("GetAddress", {
|
|
12271
|
+
address_n: [2147483692, 2147483649, 2147483648, 0, 0],
|
|
12272
|
+
coin_name: "Testnet",
|
|
12273
|
+
script_type: "SPENDADDRESS",
|
|
12274
|
+
show_display: false
|
|
12275
|
+
}),
|
|
12276
|
+
"Address"
|
|
12277
|
+
);
|
|
12278
|
+
expectMessage(await this.call("GetFeatures", {}), "Features");
|
|
12279
|
+
if (this.currentFeatures?.passphrase_protection == null) {
|
|
12280
|
+
throw new TrezorFailureError({
|
|
12281
|
+
type: "Failure",
|
|
12282
|
+
message: {
|
|
12283
|
+
code: "Failure_DataError",
|
|
12284
|
+
message: "Empty passphrase cannot be enforced: device did not report its passphrase setting"
|
|
12285
|
+
}
|
|
12286
|
+
});
|
|
12287
|
+
}
|
|
12288
|
+
}
|
|
12289
|
+
if (passphraseMode === "empty" && this.currentFeatures?.passphrase_protection === true && this.currentFeatures?.passphrase_always_on_device === true) {
|
|
12290
|
+
throw new TrezorFailureError({
|
|
12291
|
+
type: "Failure",
|
|
12292
|
+
message: {
|
|
12293
|
+
code: "Failure_DataError",
|
|
12294
|
+
message: "Empty passphrase cannot be enforced with PASSPHRASE_ALWAYS_ON_DEVICE enabled"
|
|
12295
|
+
}
|
|
12296
|
+
});
|
|
12297
|
+
}
|
|
12252
12298
|
this.log("info", "v1.appSession.create.done", {
|
|
12253
12299
|
features: summarizeFeatures(this.currentFeatures)
|
|
12254
12300
|
});
|
|
@@ -12376,7 +12422,8 @@ var TrezorThpSession = class {
|
|
|
12376
12422
|
}
|
|
12377
12423
|
const pairingMethods = getPairingMethods(
|
|
12378
12424
|
properties.pairing_methods,
|
|
12379
|
-
|
|
12425
|
+
// SkipPairing is for emulators and debug firmware only; production devices offer CodeEntry.
|
|
12426
|
+
this.options.pairingMethods ?? ["CodeEntry", "QrCode", "NFC"]
|
|
12380
12427
|
);
|
|
12381
12428
|
if (pairingMethods.length === 0) {
|
|
12382
12429
|
throw new Error("No compatible THP pairing method");
|
|
@@ -12443,12 +12490,16 @@ var TrezorThpSession = class {
|
|
|
12443
12490
|
"ThpHandshakeCompletionResponse"
|
|
12444
12491
|
);
|
|
12445
12492
|
const completionState = completion.message.state;
|
|
12493
|
+
if (completionState !== 0 && !handshakeCredentials.credentials) {
|
|
12494
|
+
throw thpPairingRefused("Trezor reported a pairing that no stored credential confirms");
|
|
12495
|
+
}
|
|
12446
12496
|
this.thpState.setIsPaired(completionState !== 0);
|
|
12447
12497
|
this.thpState.setPhase("pairing");
|
|
12448
12498
|
if (!completionState && handshakeCredentials.credentials) {
|
|
12449
12499
|
this.thpState.removePairingCredential(handshakeCredentials.credentials);
|
|
12450
12500
|
await this.options.onPairingCredentialsChanged?.({
|
|
12451
|
-
credentials: this.thpState.pairingCredentials
|
|
12501
|
+
credentials: this.thpState.pairingCredentials,
|
|
12502
|
+
removed: [handshakeCredentials.credentials]
|
|
12452
12503
|
});
|
|
12453
12504
|
}
|
|
12454
12505
|
this.log("info", "thp.handshake.done", {
|
|
@@ -12482,6 +12533,9 @@ var TrezorThpSession = class {
|
|
|
12482
12533
|
selected_pairing_method: selectedMethod
|
|
12483
12534
|
});
|
|
12484
12535
|
if (selectMethod.type === "ThpEndResponse") {
|
|
12536
|
+
if (selectedMethod !== protocol_thp_exports.ThpPairingMethod.SkipPairing) {
|
|
12537
|
+
throw thpPairingRefused("Trezor ended pairing without completing the selected method");
|
|
12538
|
+
}
|
|
12485
12539
|
this.thpState.setIsPaired(true);
|
|
12486
12540
|
this.thpState.setPhase("paired");
|
|
12487
12541
|
this.log("info", "thp.pair.done", { responseType: selectMethod.type });
|