@onekeyfe/hwk-trezor-core 1.2.8-alpha.4 → 1.2.8-alpha.50
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 +56 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -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)
|
|
@@ -12249,6 +12260,36 @@ var TrezorDeviceSession = class {
|
|
|
12249
12260
|
const response = await this.core.call("Initialize", {});
|
|
12250
12261
|
this.currentFeatures = expectMessage(response, "Features").message;
|
|
12251
12262
|
this.thpAppSessionActive = false;
|
|
12263
|
+
if (passphraseMode === "empty" && this.currentFeatures?.passphrase_protection == null) {
|
|
12264
|
+
expectMessage(
|
|
12265
|
+
await this.call("GetAddress", {
|
|
12266
|
+
address_n: [2147483692, 2147483649, 2147483648, 0, 0],
|
|
12267
|
+
coin_name: "Testnet",
|
|
12268
|
+
script_type: "SPENDADDRESS",
|
|
12269
|
+
show_display: false
|
|
12270
|
+
}),
|
|
12271
|
+
"Address"
|
|
12272
|
+
);
|
|
12273
|
+
expectMessage(await this.call("GetFeatures", {}), "Features");
|
|
12274
|
+
if (this.currentFeatures?.passphrase_protection == null) {
|
|
12275
|
+
throw new TrezorFailureError({
|
|
12276
|
+
type: "Failure",
|
|
12277
|
+
message: {
|
|
12278
|
+
code: "Failure_DataError",
|
|
12279
|
+
message: "Empty passphrase cannot be enforced: device did not report its passphrase setting"
|
|
12280
|
+
}
|
|
12281
|
+
});
|
|
12282
|
+
}
|
|
12283
|
+
}
|
|
12284
|
+
if (passphraseMode === "empty" && this.currentFeatures?.passphrase_protection === true && this.currentFeatures?.passphrase_always_on_device === true) {
|
|
12285
|
+
throw new TrezorFailureError({
|
|
12286
|
+
type: "Failure",
|
|
12287
|
+
message: {
|
|
12288
|
+
code: "Failure_DataError",
|
|
12289
|
+
message: "Empty passphrase cannot be enforced with PASSPHRASE_ALWAYS_ON_DEVICE enabled"
|
|
12290
|
+
}
|
|
12291
|
+
});
|
|
12292
|
+
}
|
|
12252
12293
|
this.log("info", "v1.appSession.create.done", {
|
|
12253
12294
|
features: summarizeFeatures(this.currentFeatures)
|
|
12254
12295
|
});
|
|
@@ -12376,7 +12417,8 @@ var TrezorThpSession = class {
|
|
|
12376
12417
|
}
|
|
12377
12418
|
const pairingMethods = getPairingMethods(
|
|
12378
12419
|
properties.pairing_methods,
|
|
12379
|
-
|
|
12420
|
+
// SkipPairing is for emulators and debug firmware only; production devices offer CodeEntry.
|
|
12421
|
+
this.options.pairingMethods ?? ["CodeEntry", "QrCode", "NFC"]
|
|
12380
12422
|
);
|
|
12381
12423
|
if (pairingMethods.length === 0) {
|
|
12382
12424
|
throw new Error("No compatible THP pairing method");
|
|
@@ -12443,12 +12485,16 @@ var TrezorThpSession = class {
|
|
|
12443
12485
|
"ThpHandshakeCompletionResponse"
|
|
12444
12486
|
);
|
|
12445
12487
|
const completionState = completion.message.state;
|
|
12488
|
+
if (completionState !== 0 && !handshakeCredentials.credentials) {
|
|
12489
|
+
throw thpPairingRefused("Trezor reported a pairing that no stored credential confirms");
|
|
12490
|
+
}
|
|
12446
12491
|
this.thpState.setIsPaired(completionState !== 0);
|
|
12447
12492
|
this.thpState.setPhase("pairing");
|
|
12448
12493
|
if (!completionState && handshakeCredentials.credentials) {
|
|
12449
12494
|
this.thpState.removePairingCredential(handshakeCredentials.credentials);
|
|
12450
12495
|
await this.options.onPairingCredentialsChanged?.({
|
|
12451
|
-
credentials: this.thpState.pairingCredentials
|
|
12496
|
+
credentials: this.thpState.pairingCredentials,
|
|
12497
|
+
removed: [handshakeCredentials.credentials]
|
|
12452
12498
|
});
|
|
12453
12499
|
}
|
|
12454
12500
|
this.log("info", "thp.handshake.done", {
|
|
@@ -12482,6 +12528,9 @@ var TrezorThpSession = class {
|
|
|
12482
12528
|
selected_pairing_method: selectedMethod
|
|
12483
12529
|
});
|
|
12484
12530
|
if (selectMethod.type === "ThpEndResponse") {
|
|
12531
|
+
if (selectedMethod !== protocol_thp_exports.ThpPairingMethod.SkipPairing) {
|
|
12532
|
+
throw thpPairingRefused("Trezor ended pairing without completing the selected method");
|
|
12533
|
+
}
|
|
12485
12534
|
this.thpState.setIsPaired(true);
|
|
12486
12535
|
this.thpState.setPhase("paired");
|
|
12487
12536
|
this.log("info", "thp.pair.done", { responseType: selectMethod.type });
|