-
Notifications
You must be signed in to change notification settings - Fork 7
/
HDKeyPair.swift
42 lines (35 loc) · 932 Bytes
/
HDKeyPair.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// ECKeyPair.swift
// GoldenKeystore
//
// Created by Tran Viet on 7/19/18.
// Copyright © 2018 Skylab. All rights reserved.
//
import Foundation
import TrezorCrypto
public final class HDKeyPair {
var node: HDNode
init(node: HDNode) {
self.node = node
}
public var privateKeyHex:String {
return self.privateKey.hex
}
public var publicKeyHex:String {
return self.publicKey.hex
}
public var privateKey: Data {
return Data(bytes: withUnsafeBytes(of: &node.private_key) { ptr in
return ptr.map({ $0 })
})
}
public var publicKey: Data {
var key = Data(repeating: 0, count: 65)
privateKey.withUnsafeBytes { ptr in
key.withUnsafeMutableBytes { keyPtr in
ecdsa_get_public_key65(node.curve.pointee.params, ptr, keyPtr)
}
}
return key
}
}