Skip to content

Commit

Permalink
Merge pull request #5 from Sajjon/expose_mnemonic_word_list
Browse files Browse the repository at this point in the history
Extracting mnemonic word lists for each language to seprate files, ch…
  • Loading branch information
Sajjon authored Aug 29, 2019
2 parents c068926 + 3bbd37b commit 0129f1c
Show file tree
Hide file tree
Showing 15 changed files with 16,784 additions and 16,498 deletions.
42 changes: 41 additions & 1 deletion BitcoinKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@
CFA290702101CDCA001A1BAB /* ScriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA2906F2101CDCA001A1BAB /* ScriptTests.swift */; };
CFA290722102B635001A1BAB /* ScriptMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA290712102B635001A1BAB /* ScriptMachine.swift */; };
CFA290742102B650001A1BAB /* ScriptMachineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA290732102B650001A1BAB /* ScriptMachineTests.swift */; };
E67112EA23181BAA00F1496B /* WordList+English.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112E923181BAA00F1496B /* WordList+English.swift */; };
E67112EC23181BF800F1496B /* WordList+Japanese.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112EB23181BF800F1496B /* WordList+Japanese.swift */; };
E67112EE23181C3E00F1496B /* WordList+Korean.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112ED23181C3E00F1496B /* WordList+Korean.swift */; };
E67112F023181C5A00F1496B /* WordList+Spanish.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112EF23181C5A00F1496B /* WordList+Spanish.swift */; };
E67112F223181C7700F1496B /* WordList+SimplifiedChinese.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112F123181C7700F1496B /* WordList+SimplifiedChinese.swift */; };
E67112F423181C9900F1496B /* WordList+TraditionalChinese.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112F323181C9900F1496B /* WordList+TraditionalChinese.swift */; };
E67112F623181CB600F1496B /* WordList+French.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112F523181CB600F1496B /* WordList+French.swift */; };
E67112F823181CCE00F1496B /* WordList+Italian.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67112F723181CCE00F1496B /* WordList+Italian.swift */; };
E6A64306224418EB00CD4BFC /* PointOnCurve.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A64305224418EB00CD4BFC /* PointOnCurve.swift */; };
E6A643082244190400CD4BFC /* Scalar32Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A643072244190400CD4BFC /* Scalar32Bytes.swift */; };
E6A643102244EA3B00CD4BFC /* DecodePointFromCompressedKeyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A6430F2244EA3B00CD4BFC /* DecodePointFromCompressedKeyTests.swift */; };
Expand Down Expand Up @@ -447,6 +455,14 @@
CFA2906F2101CDCA001A1BAB /* ScriptTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptTests.swift; sourceTree = "<group>"; };
CFA290712102B635001A1BAB /* ScriptMachine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptMachine.swift; sourceTree = "<group>"; };
CFA290732102B650001A1BAB /* ScriptMachineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptMachineTests.swift; sourceTree = "<group>"; };
E67112E923181BAA00F1496B /* WordList+English.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+English.swift"; sourceTree = "<group>"; };
E67112EB23181BF800F1496B /* WordList+Japanese.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+Japanese.swift"; sourceTree = "<group>"; };
E67112ED23181C3E00F1496B /* WordList+Korean.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+Korean.swift"; sourceTree = "<group>"; };
E67112EF23181C5A00F1496B /* WordList+Spanish.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+Spanish.swift"; sourceTree = "<group>"; };
E67112F123181C7700F1496B /* WordList+SimplifiedChinese.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+SimplifiedChinese.swift"; sourceTree = "<group>"; };
E67112F323181C9900F1496B /* WordList+TraditionalChinese.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+TraditionalChinese.swift"; sourceTree = "<group>"; };
E67112F523181CB600F1496B /* WordList+French.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+French.swift"; sourceTree = "<group>"; };
E67112F723181CCE00F1496B /* WordList+Italian.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WordList+Italian.swift"; sourceTree = "<group>"; };
E6A64305224418EB00CD4BFC /* PointOnCurve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOnCurve.swift; sourceTree = "<group>"; };
E6A643072244190400CD4BFC /* Scalar32Bytes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scalar32Bytes.swift; sourceTree = "<group>"; };
E6A6430F2244EA3B00CD4BFC /* DecodePointFromCompressedKeyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodePointFromCompressedKeyTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -631,7 +647,7 @@
E6A64305224418EB00CD4BFC /* PointOnCurve.swift */,
E6A643072244190400CD4BFC /* Scalar32Bytes.swift */,
1482B5E12026B0680098B612 /* Mnemonic.swift */,
1482B5E32026F2580098B612 /* WordList.swift */,
E67112E823181B6A00F1496B /* WordList */,
14839A7B202F79F900A6CB34 /* PaymentURI.swift */,
147494E3201F9B85006D1CF8 /* Crypto.swift */,
147494EF201FAE30006D1CF8 /* Serialization.swift */,
Expand Down Expand Up @@ -890,6 +906,22 @@
path = Keys;
sourceTree = "<group>";
};
E67112E823181B6A00F1496B /* WordList */ = {
isa = PBXGroup;
children = (
1482B5E32026F2580098B612 /* WordList.swift */,
E67112F723181CCE00F1496B /* WordList+Italian.swift */,
E67112ED23181C3E00F1496B /* WordList+Korean.swift */,
E67112F123181C7700F1496B /* WordList+SimplifiedChinese.swift */,
E67112F323181C9900F1496B /* WordList+TraditionalChinese.swift */,
E67112F523181CB600F1496B /* WordList+French.swift */,
E67112EF23181C5A00F1496B /* WordList+Spanish.swift */,
E67112E923181BAA00F1496B /* WordList+English.swift */,
E67112EB23181BF800F1496B /* WordList+Japanese.swift */,
);
path = WordList;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -1047,13 +1079,16 @@
E6A643082244190400CD4BFC /* Scalar32Bytes.swift in Sources */,
2933014D214FCE150028946B /* TransactionHistoryProvider.swift in Sources */,
0C1DE155211D787100FE8E43 /* OP_TOTALSTACK.swift in Sources */,
E67112EC23181BF800F1496B /* WordList+Japanese.swift in Sources */,
147494E6201F9BF0006D1CF8 /* Encoding.swift in Sources */,
2949920220F228B400D078B6 /* UnspentTransaction.swift in Sources */,
0C0900442116BA8F0077E9BC /* OP_RSHIFT.swift in Sources */,
14839A7F202FE58800A6CB34 /* VersionMessage.swift in Sources */,
E67112EE23181C3E00F1496B /* WordList+Korean.swift in Sources */,
0C1DE16B211E7C0900FE8E43 /* OP_2DROP.swift in Sources */,
298E17BC215097C000FF6C77 /* BitcoinComUtxoProvider.swift in Sources */,
0C4132EF210EFD1700906E4A /* OP_SWAP.swift in Sources */,
E67112F423181C9900F1496B /* WordList+TraditionalChinese.swift in Sources */,
14839AAB202FE7F000A6CB34 /* NetworkAddress.swift in Sources */,
297DB97320EB12E60077EEEE /* AddressType.swift in Sources */,
294DDE43211B31EA00B7F645 /* OP_VERIF.swift in Sources */,
Expand Down Expand Up @@ -1086,9 +1121,11 @@
CFA2906C2101CD96001A1BAB /* ScriptChunk.swift in Sources */,
29330147214F97450028946B /* BitcoinKitDataStoreProtocol.swift in Sources */,
14F37A3C20209F9200D34748 /* Script.swift in Sources */,
E67112F823181CCE00F1496B /* WordList+Italian.swift in Sources */,
0C1DE17C211E8A0100FE8E43 /* OP_SPLIT.swift in Sources */,
294DDE3B211B31B100B7F645 /* OP_NOP.swift in Sources */,
0C66CD07212542730049DB89 /* OP_OR.swift in Sources */,
E67112F023181C5A00F1496B /* WordList+Spanish.swift in Sources */,
298E17C42150AD6900FF6C77 /* TransactionBuilder.swift in Sources */,
0C1DE15F211E6FA700FE8E43 /* OP_NIP.swift in Sources */,
29330152214FDC880028946B /* UserDefaults+BitcoinKitDataStoreProtocol.swift in Sources */,
Expand Down Expand Up @@ -1131,6 +1168,7 @@
0C1DE163211E724E00FE8E43 /* OP_PICK.swift in Sources */,
2914BE47211BAB0500B349CB /* OP_HASH256.swift in Sources */,
298E17BE2150983C00FF6C77 /* BitcoinComTransactionHistoryProvider.swift in Sources */,
E67112EA23181BAA00F1496B /* WordList+English.swift in Sources */,
2949920020F227EB00D078B6 /* VersionByte.swift in Sources */,
29248EEF2104B64E00CC9051 /* ScriptChunkHelper.swift in Sources */,
14839A85202FE60E00A6CB34 /* InventoryMessage.swift in Sources */,
Expand All @@ -1153,8 +1191,10 @@
0C0900422116B9DE0077E9BC /* OP_LSHIFT.swift in Sources */,
14839A9F202FE73B00A6CB34 /* TransactionOutput.swift in Sources */,
1463E6B62025E99C0033DAAE /* BlockChain.swift in Sources */,
E67112F623181CB600F1496B /* WordList+French.swift in Sources */,
2914BE4E211BCF7600B349CB /* OP_RESERVED.swift in Sources */,
14839A81202FE5CA00A6CB34 /* VerackMessage.swift in Sources */,
E67112F223181C7700F1496B /* WordList+SimplifiedChinese.swift in Sources */,
29E1ED71210EC751007F4627 /* OP_1NEGATE.swift in Sources */,
0C66CD032125425D0049DB89 /* OP_INVERT.swift in Sources */,
0C0900242116935E0077E9BC /* OP_MAX.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/BitcoinKit/Core/Mnemonic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public struct Mnemonic {
return seed
}

private static func wordList(for language: Language) -> [String.SubSequence] {
public static func wordList(for language: Language) -> [String] {
switch language {
case .english:
return WordList.english
Expand Down
34 changes: 18 additions & 16 deletions Sources/BitcoinKit/Core/PointOnCurve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct PointOnCurve {
#if BitcoinKitXcode
public extension PointOnCurve {

public enum Error: Swift.Error {
enum Error: Swift.Error {
case multiplicationResultedInTooFewBytes(expected: Int, butGot: Int)
case expectedUncompressedPoint
case publicKeyContainsTooFewBytes(expected: Int, butGot: Int)
Expand All @@ -45,21 +45,6 @@ public extension PointOnCurve {
return try PointOnCurve.decodePointFrom(xAndYPrefixedWithCompressionType: data)
}

private static func decodePointFrom(xAndYPrefixedWithCompressionType data: Data) throws -> PointOnCurve {
var xAndY = data
guard xAndY[0] == PointOnCurve.byteForUncompressed else {
throw Error.expectedUncompressedPoint
}
xAndY = Data(xAndY.dropFirst())
let expectedByteCount = Scalar32Bytes.expectedByteCount * 2
guard xAndY.count == expectedByteCount else {
throw Error.multiplicationResultedInTooFewBytes(expected: expectedByteCount, butGot: xAndY.count)
}
let resultX = xAndY.prefix(Scalar32Bytes.expectedByteCount)
let resultY = xAndY.suffix(Scalar32Bytes.expectedByteCount)
return try PointOnCurve(x: resultX, y: resultY)
}

func multiplyBy(scalar: Scalar32Bytes) throws -> PointOnCurve {
let xAndY = _EllipticCurve.multiplyECPointX(x.data, andECPointY: y.data, withScalar: scalar.data)
return try PointOnCurve.decodePointFrom(xAndYPrefixedWithCompressionType: xAndY)
Expand All @@ -74,4 +59,21 @@ public extension PointOnCurve {
return try multiplyBy(scalar: scalar)
}
}

private extension PointOnCurve {
static func decodePointFrom(xAndYPrefixedWithCompressionType data: Data) throws -> PointOnCurve {
var xAndY = data
guard xAndY[0] == PointOnCurve.byteForUncompressed else {
throw Error.expectedUncompressedPoint
}
xAndY = Data(xAndY.dropFirst())
let expectedByteCount = Scalar32Bytes.expectedByteCount * 2
guard xAndY.count == expectedByteCount else {
throw Error.multiplicationResultedInTooFewBytes(expected: expectedByteCount, butGot: xAndY.count)
}
let resultX = xAndY.prefix(Scalar32Bytes.expectedByteCount)
let resultY = xAndY.suffix(Scalar32Bytes.expectedByteCount)
return try PointOnCurve(x: resultX, y: resultY)
}
}
#endif
Loading

0 comments on commit 0129f1c

Please sign in to comment.