Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SPVClient: @unchecked Sendable {
return false
}()

init(network: Network = DashSDKNetwork(rawValue: 1), dataDir: String?, startHeight: UInt32, eventHandlers: SPVEventHandlers? = nil) throws {
init(network: DashSDKNetwork = DashSDKNetwork(rawValue: 1), dataDir: String?, startHeight: UInt32, eventHandlers: SPVEventHandlers? = nil) throws {
if swiftLoggingEnabled {
let level = (ProcessInfo.processInfo.environment["SPV_LOG"] ?? "off")
print("[SPV][Log] Initialized SPV logging level=\(level)")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public struct ModelContainerHelper {
PersistentDataContract.self,
PersistentToken.self,
PersistentDocumentType.self,
PersistentTokenHistoryEvent.self,
PersistentKeyword.self
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,33 +283,6 @@ public class CoreWalletManager: ObservableObject {
return wallet
}

public func decryptSeed(_ encryptedSeed: Data?) -> Data? {
// This method is used internally by other services
// In a real implementation, this would decrypt using the current PIN
// For now, return nil to indicate manual unlock is needed
return nil
}

public func changeWalletPIN(currentPIN: String, newPIN: String) async throws {
// Retrieve seed with current PIN
let seed = try storage.retrieveSeed(pin: currentPIN)

// Re-encrypt with new PIN
_ = try storage.storeSeed(seed, pin: newPIN)
}

public func enableBiometricProtection(pin: String) async throws {
// First verify PIN and get seed
let seed = try storage.retrieveSeed(pin: pin)

// Enable biometric protection
try storage.enableBiometricProtection(for: seed)
}

public func unlockWithBiometric() async throws -> Data {
return try storage.retrieveSeedWithBiometric()
}

// MARK: - Account Management

/// Build a signed transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,6 @@ public class WalletStorage {
return try decryptData(encryptedSeed, with: key)
}

public func deleteSeed() throws {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: keychainService,
kSecAttrAccount as String: seedKeychainAccount
]

let status = SecItemDelete(query as CFDictionary)
guard status == errSecSuccess || status == errSecItemNotFound else {
throw WalletStorageError.keychainError(status)
}
}

// MARK: - PIN Management

private func storePINHash(_ pin: String) throws {
Expand Down Expand Up @@ -141,58 +128,6 @@ public class WalletStorage {
return Data(hash) == storedHash
}

// MARK: - Biometric Protection

public func enableBiometricProtection(for seed: Data) throws {
// Create access control with biometric authentication
var error: Unmanaged<CFError>?
guard let access = SecAccessControlCreateWithFlags(
nil,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
.biometryCurrentSet,
&error
) else {
throw WalletStorageError.biometricSetupFailed
}

let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: keychainService,
kSecAttrAccount as String: biometricKeychainAccount,
kSecValueData as String: seed,
kSecAttrAccessControl as String: access
]

SecItemDelete(query as CFDictionary)

let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else {
throw WalletStorageError.keychainError(status)
}
}

public func retrieveSeedWithBiometric() throws -> Data {
let context = LAContext()
context.localizedReason = "Authenticate to access your wallet"
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: keychainService,
kSecAttrAccount as String: biometricKeychainAccount,
kSecReturnData as String: true,
kSecUseAuthenticationContext as String: context
]

var result: AnyObject?
let status = SecItemCopyMatching(query as CFDictionary, &result)

guard status == errSecSuccess,
let seed = result as? Data else {
throw WalletStorageError.biometricAuthenticationFailed
}

return seed
}

// MARK: - Encryption Helpers

private func generateSalt() -> Data {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public struct DPPDataContract: Identifiable, Codable, Equatable, Sendable {

public struct DocumentType: Codable, Equatable, Sendable {
public let name: String
public let schema: JsonSchema
public let indices: [Index]
public let properties: [String: DocumentProperty]
public let security: DocumentTypeSecurity
Expand All @@ -112,7 +111,6 @@ public struct DocumentType: Codable, Equatable, Sendable {

public init(
name: String,
schema: JsonSchema,
indices: [Index],
properties: [String: DocumentProperty],
security: DocumentTypeSecurity,
Expand All @@ -125,7 +123,6 @@ public struct DocumentType: Codable, Equatable, Sendable {
tradeMode: TradeMode
) {
self.name = name
self.schema = schema
self.indices = indices
self.properties = properties
self.security = security
Expand Down Expand Up @@ -451,95 +448,3 @@ public struct TokenEveryoneRules: Codable, Equatable, Sendable {
}
}

// MARK: - Json Schema

public struct JsonSchema: Codable, Equatable, Sendable {
public let type: String
public let properties: [String: JsonSchemaProperty]
public let required: [String]
public let additionalProperties: Bool

public init(type: String, properties: [String: JsonSchemaProperty], required: [String], additionalProperties: Bool = false) {
self.type = type
self.properties = properties
self.required = required
self.additionalProperties = additionalProperties
}
}

public indirect enum JsonSchemaPropertyValue: Codable, Equatable, Sendable {
case property(JsonSchemaProperty)
}

public struct JsonSchemaProperty: Codable, Equatable, Sendable {
public let type: String
public let schemaDescription: String?
public let format: String?
public let pattern: String?
public let minLength: Int?
public let maxLength: Int?
public let minimum: Double?
public let maximum: Double?
public let items: JsonSchemaPropertyValue?

public init(
type: String,
schemaDescription: String? = nil,
format: String? = nil,
pattern: String? = nil,
minLength: Int? = nil,
maxLength: Int? = nil,
minimum: Double? = nil,
maximum: Double? = nil,
items: JsonSchemaPropertyValue? = nil
) {
self.type = type
self.schemaDescription = schemaDescription
self.format = format
self.pattern = pattern
self.minLength = minLength
self.maxLength = maxLength
self.minimum = minimum
self.maximum = maximum
self.items = items
}
}

// MARK: - Factory Methods

extension DPPDataContract {
/// Create a simple data contract
public static func create(
id: Identifier? = nil,
ownerId: Identifier,
documentTypes: [DocumentName: DocumentType] = [:],
contractDescription: String? = nil
) -> DPPDataContract {
let contractId = id ?? Data(UUID().uuidString.utf8).prefix(32).paddedToLength(32)

return DPPDataContract(
id: contractId,
version: 0,
ownerId: ownerId,
documentTypes: documentTypes,
config: DataContractConfig(
canBeDeleted: false,
readOnly: false,
keepsHistory: true,
documentsKeepRevisionLogForPassedTimeMs: nil,
documentsMutableContractDefaultStored: true
),
schemaDefs: nil,
createdAt: TimestampMillis(Date().timeIntervalSince1970 * 1000),
updatedAt: nil,
createdAtBlockHeight: nil,
updatedAtBlockHeight: nil,
createdAtEpoch: nil,
updatedAtEpoch: nil,
groups: [:],
tokens: [:],
keywords: [],
contractDescription: contractDescription
)
}
}
135 changes: 0 additions & 135 deletions packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,63 +77,6 @@ public struct DPPDocument: Identifiable, Codable, Equatable, Sendable {
}
}

// MARK: - Extended Document

/// Extended document that includes data contract and metadata
public struct ExtendedDocument: Identifiable, Codable, Equatable, Sendable {
public let documentTypeName: String
public let dataContractId: Identifier
public let document: DPPDocument
public let dataContract: DPPDataContract
public let metadata: DocumentMetadata?
public let entropy: Bytes32
public let tokenPaymentInfo: TokenPaymentInfo?

/// Convenience accessor for document ID
public var id: Identifier {
document.id
}

/// Get the data contract ID as a base58 string
public var dataContractIdString: String {
dataContractId.toBase58String()
}

public init(
documentTypeName: String,
dataContractId: Identifier,
document: DPPDocument,
dataContract: DPPDataContract,
metadata: DocumentMetadata?,
entropy: Bytes32,
tokenPaymentInfo: TokenPaymentInfo?
) {
self.documentTypeName = documentTypeName
self.dataContractId = dataContractId
self.document = document
self.dataContract = dataContract
self.metadata = metadata
self.entropy = entropy
self.tokenPaymentInfo = tokenPaymentInfo
}
}

// MARK: - Document Metadata

public struct DocumentMetadata: Codable, Equatable, Sendable {
public let blockHeight: BlockHeight
public let coreBlockHeight: CoreBlockHeight
public let timeMs: TimestampMillis
public let protocolVersion: UInt32

public init(blockHeight: BlockHeight, coreBlockHeight: CoreBlockHeight, timeMs: TimestampMillis, protocolVersion: UInt32) {
self.blockHeight = blockHeight
self.coreBlockHeight = coreBlockHeight
self.timeMs = timeMs
self.protocolVersion = protocolVersion
}
}

// MARK: - Token Payment Info

public struct TokenPaymentInfo: Codable, Equatable, Sendable {
Expand All @@ -149,81 +92,3 @@ public struct TokenPaymentInfo: Codable, Equatable, Sendable {
self.amount = amount
}
}

// MARK: - Document Patch

/// Represents a partial document update
public struct DocumentPatch: Codable, Equatable, Sendable {
public let id: Identifier
public let properties: [String: PlatformValue]
public let revision: Revision?
public let updatedAt: TimestampMillis?

/// Get the document ID as a base58 string
public var idString: String {
id.toBase58String()
}

public init(id: Identifier, properties: [String: PlatformValue], revision: Revision?, updatedAt: TimestampMillis?) {
self.id = id
self.properties = properties
self.revision = revision
self.updatedAt = updatedAt
}
}

// MARK: - Document Property Names

public struct DocumentPropertyNames {
public static let featureVersion = "$version"
public static let id = "$id"
public static let dataContractId = "$dataContractId"
public static let revision = "$revision"
public static let ownerId = "$ownerId"
public static let price = "$price"
public static let createdAt = "$createdAt"
public static let updatedAt = "$updatedAt"
public static let transferredAt = "$transferredAt"
public static let createdAtBlockHeight = "$createdAtBlockHeight"
public static let updatedAtBlockHeight = "$updatedAtBlockHeight"
public static let transferredAtBlockHeight = "$transferredAtBlockHeight"
public static let createdAtCoreBlockHeight = "$createdAtCoreBlockHeight"
public static let updatedAtCoreBlockHeight = "$updatedAtCoreBlockHeight"
public static let transferredAtCoreBlockHeight = "$transferredAtCoreBlockHeight"

public static let identifierFields = [id, ownerId, dataContractId]
public static let timestampFields = [createdAt, updatedAt, transferredAt]
public static let blockHeightFields = [
createdAtBlockHeight, updatedAtBlockHeight, transferredAtBlockHeight,
createdAtCoreBlockHeight, updatedAtCoreBlockHeight, transferredAtCoreBlockHeight
]
}

// MARK: - Document Factory

extension DPPDocument {
/// Create a new document with auto-generated ID
public static func create(
id: Identifier? = nil,
ownerId: Identifier,
properties: [String: PlatformValue] = [:]
) -> DPPDocument {
let documentId = id ?? Data(UUID().uuidString.utf8).prefix(32).paddedToLength(32)

return DPPDocument(
id: documentId,
ownerId: ownerId,
properties: properties,
revision: 0,
createdAt: TimestampMillis(Date().timeIntervalSince1970 * 1000),
updatedAt: nil,
transferredAt: nil,
createdAtBlockHeight: nil,
updatedAtBlockHeight: nil,
transferredAtBlockHeight: nil,
createdAtCoreBlockHeight: nil,
updatedAtCoreBlockHeight: nil,
transferredAtCoreBlockHeight: nil
)
}
}
Loading
Loading