Skip to content

Commit 775e5c4

Browse files
Marcus ArnettMarcus Arnett
authored andcommitted
Implement lint for Cyrptography objects
1 parent 4c0643a commit 775e5c4

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

Sources/SuiKit/Types/Enums/Sui/Cryptography/SignatureScheme.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import Foundation
2929
///
3030
/// - `ED25519`: Represents the Ed25519 cryptographic algorithm.
3131
/// - `SECP256K1`: Represents the SECP256K1 cryptographic algorithm.
32+
/// - `SECP256R1`: Represents the SECP256R1 (P256) cryptographic algorithm.
3233
public enum SignatureScheme: String {
3334
/// Represents the Ed25519 cryptographic algorithm.
3435
case ED25519
3536

3637
/// Represents the SECP256K1 cryptographic algorithm.
3738
case SECP256K1
38-
39+
40+
/// Represents the SECP256R1 cryptographic algorithm.
3941
case SECP256R1
4042
}

Sources/SuiKit/Types/Structs/Cryptography/Signature.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ public struct Signature: Equatable, KeyProtocol {
100100
let pubKeyBytes = Array(bytes[(1 + signature.count)...])
101101
let pubKey = try SECP256K1PublicKey(data: Data(pubKeyBytes))
102102
return Signature(signature: Data(signature), publickey: pubKey.key, signatureScheme: .SECP256K1)
103+
} else if signatureScheme == "SECP256R1" {
104+
if #available(macOS 13.0, *) {
105+
let signature = Array(bytes[1...(bytes.count - SECP256R1PublicKey.LENGTH)])
106+
let pubKeyBytes = Array(bytes[(1 + signature.count)...])
107+
let pubKey = try SECP256R1PublicKey(data: Data(pubKeyBytes))
108+
return Signature(
109+
signature: Data(signature),
110+
publickey: pubKey.key.compressedRepresentation,
111+
signatureScheme: .SECP256R1
112+
)
113+
} else {
114+
throw AccountError.cannotBeDeserialized
115+
}
103116
} else {
104117
throw AccountError.cannotBeDeserialized
105118
}

Sources/SuiKit/Types/Structs/Cryptography/SignatureSchemeFlags.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public struct SignatureSchemeFlags {
3131
public static var SIGNATURE_SCHEME_TO_FLAG: [String: UInt8] = [
3232
"ED25519": 0x00, // Represents the Ed25519 signature scheme.
3333
"SECP256K1": 0x01, // Represents the SECP256K1 signature scheme.
34-
"SECP256R1": 0x02,
35-
"ZkLogin": 0x05
34+
"SECP256R1": 0x02, // Represents the SECP256R1 (P256) signature scheme.
35+
"ZkLogin": 0x05 // Represents the zkLogin signature scheme.
3636
]
3737

3838
/// A dictionary mapping the flags of signature schemes to their associated names.
3939
public static var SIGNATURE_FLAG_TO_SCHEME: [UInt8: String] = [
4040
0x00: "ED25519", // Represents the flag for the Ed25519 signature scheme.
4141
0x01: "SECP256K1", // Represents the flag for the SECP256K1 signature scheme.
42-
0x02: "SECP256R1",
43-
0x05: "ZkLogin"
42+
0x02: "SECP256R1", // Represents the flag for the SECP256R1 (P256) signature scheme.
43+
0x05: "ZkLogin" // Represents the flag for the zkLogin signature scheme.
4444
]
4545
}

0 commit comments

Comments
 (0)