Skip to content

Commit

Permalink
base58
Browse files Browse the repository at this point in the history
  • Loading branch information
xueyuejie committed Jul 22, 2022
1 parent adf9ae2 commit 3f0776f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
13 changes: 2 additions & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
"repositoryURL": "https://github.com/mathwallet/Base58Swift.git",
"state": {
"branch": null,
"revision": "916940466f7e149b4029832ba5521252d7d68d92",
"version": "3.0.0"
}
},
{
"package": "BigInt",
"repositoryURL": "https://github.com/attaswift/BigInt.git",
"state": {
"branch": null,
"revision": "0ed110f7555c34ff468e72e1686e59721f2b0da6",
"version": "5.3.0"
"revision": "04ccae070ac6f3117db11af864a04229f7c1e025",
"version": "0.0.1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "Base58Swift", url: "https://github.com/mathwallet/Base58Swift.git", from: "3.0.0"),
.package(name: "Base58Swift", url: "https://github.com/mathwallet/Base58Swift", from: "0.0.1"),
.package(name:"Blake2",url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.2"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.4.1"),
.package(name:"BIP39swift", url: "https://github.com/mathwallet/BIP39swift", from: "1.0.1"),
Expand Down
9 changes: 5 additions & 4 deletions Sources/TezosSwift/TezosKeypair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public struct TezosAddress {

public var address: String {
let addressBytes = TezosPrefix.tz1 + data.bytes
return Base58.base58CheckEncode(addressBytes)
return addressBytes.base58CheckEncodedString
}

public init?(_ address: String) {
guard let addressBytes = Base58.base58CheckDecode(address), addressBytes.count == TezosAddress.SIZE + TezosPrefix.tz1.count else {
guard let addressBytes = address.base58CheckDecodedData, addressBytes.count == TezosAddress.SIZE + TezosPrefix.tz1.count else {
return nil
}
self.data = Data(addressBytes[3..<addressBytes.endIndex])
Expand All @@ -46,7 +46,8 @@ public struct TezosKeypair {
}

public var privateKey: String {
return Base58.base58CheckEncode(TezosPrefix.edsk + secretKey.bytes)
let privateKeyBytes = TezosPrefix.edsk + secretKey.bytes
return privateKeyBytes.base58CheckEncodedString
}

public init(secretKey: Data) throws {
Expand All @@ -55,7 +56,7 @@ public struct TezosKeypair {
}

public init(privateKey: String) throws {
guard let privateBytes = Base58.base58CheckDecode(privateKey) else {
guard let privateBytes = privateKey.base58CheckDecodedData else {
throw Error.invalidPrivateKey
}
try self.init(secretKey:Data(privateBytes[4..<privateBytes.endIndex]))
Expand Down
3 changes: 2 additions & 1 deletion Sources/TezosSwift/Transaction/TezosTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class TezosTransaction {

public func sign(keypair: TezosKeypair) {
if let _forgeString = self.forgeString, let signatureData = self.signHexString(keypair: keypair, hexString:_forgeString) {
self.signatureString = Base58.base58CheckEncode(TezosPrefix.edsig + signatureData.bytes)
let signatureBytes = TezosPrefix.edsig + signatureData.bytes
self.signatureString = signatureBytes.base58CheckEncodedString
self.sendString = _forgeString + signatureData.toHexString()
}
}
Expand Down

0 comments on commit 3f0776f

Please sign in to comment.