-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS-8008 Sign hashes with different sizes #382
Conversation
@@ -125,10 +125,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable { | |||
|
|||
/// This error is returned when a `SignCommand` receives only empty hashes for signature. | |||
case emptyHashes | |||
|
|||
/// This error is returned when a `SignCommand` receives hashes of different lengths for signature. | |||
case hashSizeMustBeEqual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
больше не актуально, карта конечно все равно вернет свою ошибку, но посредством сдк эту ошибку получить более невозможно
@@ -0,0 +1,56 @@ | |||
// | |||
// ChunkHashesUtil.swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Перенес старую логику чанкования из команды в отдельную утилиту ради тестируемости и добавил сюда новый чанкинг
// ChunkedHashesContainer.swift | ||
// TangemSdk | ||
// | ||
// Created by Alexander Osokin on 31.10.2024. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сюда перенес стейт менеджмент чанков из команды опять же ради тестируемости. Логика чуть поменялась. Раньше я оперировал ренджами, вычисляя чанки на лету, а теперь сразу чанками
do { | ||
let signatures = try self.processSignatures(with: session.environment) | ||
|
||
if let remainingSignatures = session.environment.card?.wallets[self.walletPublicKey]?.remainingSignatures { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
просто перенос пониже, чтобы был доступ к количеству подписей
@@ -20,45 +20,25 @@ public struct SignResponse: JSONStringConvertible { | |||
|
|||
/// Signs transaction hashes using a wallet private key, stored on the card. | |||
class SignCommand: Command { | |||
typealias Response = SignResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пришлось поделить, чтобы не делать лишнего в функции десериализации
У текущей реализации команды подписи было ограничение, она ожидала хеши одного размера, иначе кидала ошибку. Это связано с техничеакой реализацией подписи - мы передаем на карту конкатенированную подпись и размер хеша, а карта уже сама нарезает, подпись возвращается в таком же виде.
Из дополнительных ограничений - макс 10 хешей за операцию и макс 2 хеша для старых девайсов
Я перерработал чанкование, чтобы хеши объединялись в группы по размерам, с учетом ограничений выше и с сохранением порядка. Порядок респонса с подписями соответствуют порядку переданных хешей. У тому же может быть несколько одинаковых хешей с разными подписями