-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds checksum validation and required refactorings.
- Loading branch information
1 parent
031555c
commit ddbbb39
Showing
19 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/assertWordCount..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
instance creation | ||
assertions | ||
assertWordCount: count | ||
((12 to: 24 by: 3) includes: count) | ||
ifFalse: [ self | ||
|
9 changes: 9 additions & 0 deletions
9
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/createChecksumFrom.size..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
utilities | ||
createChecksumFrom: hexString size: checksumSize | ||
^ Integer | ||
readFrom: | ||
(((SHA256 hashMessage: (ByteArray fromHexString: hexString asLowercase)) asInteger | ||
printStringBase: 2 | ||
length: 256 | ||
padded: true) copyFrom: 1 to: checksumSize) | ||
base: 2 |
2 changes: 1 addition & 1 deletion
2
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/defaultLanguage.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
instance creation | ||
utilities | ||
defaultLanguage | ||
^ 'english' |
2 changes: 1 addition & 1 deletion
2
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/detectLanguageOf..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
instance creation | ||
utilities | ||
detectLanguageOf: aString | ||
|
||
self ensureAllLanguages. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/generate..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
instance creation | ||
generate: entropyLength | ||
"Answer a new instance of receiver with the default bit length. | ||
WARNING: The entropy generation of this class is weak, so please avoid using it for critical purposes, randomness has not been tested." | ||
|
||
^self fromBits: (1 to: (2 raisedTo: entropyLength)) atRandom |
6 changes: 6 additions & 0 deletions
6
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/class/generate.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
instance creation | ||
generate | ||
"Answer a new instance of receiver with the default bit length. | ||
WARNING: The entropy generation of this class is weak, so please avoid using it for critical purposes, randomness has not been tested." | ||
|
||
^self generate: 128 |
3 changes: 3 additions & 0 deletions
3
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/instance/bitsString.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
printing | ||
bitsString | ||
^ self bits printStringBase: 2 length: self size * 11 padded: true |
5 changes: 5 additions & 0 deletions
5
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/instance/checksum.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
accessing | ||
checksum | ||
| bitsString | | ||
bitsString := self bitsString. | ||
^Integer readFrom: (bitsString copyFrom: bitsString size - self checksumSize + 1 to: bitsString size) base: 2 |
3 changes: 3 additions & 0 deletions
3
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/instance/checksumSize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
checksumSize | ||
^ self bitsString size // 33 |
5 changes: 5 additions & 0 deletions
5
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/instance/entropy.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
accessing | ||
entropy | ||
| bitsString | | ||
bitsString := self bitsString. | ||
^Integer readFrom: (bitsString copyFrom: 1 to: bitsString size - self checksumSize) base: 2 |
7 changes: 7 additions & 0 deletions
7
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/instance/hasValidChecksum.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
testing | ||
hasValidChecksum | ||
^ self checksum | ||
= | ||
(self class | ||
createChecksumFrom: (self entropy printStringBase: 16 length: (self bitsString size - self checksumSize) / 4 padded: true) | ||
size: self checksumSize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/BIP39Mnemonic-Core.package/BIP39Mnemonic.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/BIP39Mnemonic-Core.package/BIP39MnemonicTest.class/instance/testChecksumSize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests | ||
testChecksumSize | ||
|
||
| m | | ||
m := BIP39Mnemonic fromWords: 'legal winner thank year wave sausage worth useful legal winner thank yellow'. | ||
self assert: m checksumSize = 4. | ||
|
||
m := BIP39Mnemonic fromWords: 'void come effort suffer camp survey warrior heavy shoot primary clutch crush open amazing screen patrol group space point ten exist slush involve unfold'. | ||
self assert: m checksumSize = 8 | ||
|
||
|
||
|
||
|
6 changes: 6 additions & 0 deletions
6
src/BIP39Mnemonic-Core.package/BIP39MnemonicTest.class/instance/testInvalidChecksum.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests | ||
testInvalidChecksum | ||
| m | | ||
m := BIP39Mnemonic fromWords: 'bless cloud wheel regular tiny venue bird web grief security dignity zoo'. | ||
self deny: m isValid | ||
|
7 changes: 7 additions & 0 deletions
7
src/BIP39Mnemonic-Core.package/BIP39MnemonicTest.class/instance/testSymmetry.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tests | ||
testSymmetry | ||
|
||
| m1 m2 | | ||
m1 := BIP39Mnemonic fromWords: 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless' language: 'english'. | ||
m2 := BIP39Mnemonic fromBits: m1 bits size: m1 size language: m1 language. | ||
self assert: m1 words equals: m2 words. |
2 changes: 1 addition & 1 deletion
2
...st.class/instance/testWordsFromEntropy.st → ...nemonicTest.class/instance/testVectors.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
tests | ||
testWordsFromEntropy | ||
testVectors | ||
self vectors | ||
do: [ :v | | ||
| mnemonic | | ||
|