-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce Nim impl of generateAlias
Closes #32
- Loading branch information
1 parent
6f39981
commit e4ef049
Showing
23 changed files
with
3,378 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.vscode | ||
bin/ | ||
/bottles/ | ||
/DLLs/ | ||
build/ | ||
vendor/.nimble | ||
tmp | ||
|
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
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
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
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
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
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,8 +1,11 @@ | ||
import ../lib | ||
import lib/shim as nim_shim_c | ||
import sys | ||
|
||
proc hashMessage*(message: cstring): cstring = | ||
let hash = lib.hashMessage($message) | ||
result = cast[cstring](c_malloc(csize_t hash.len + 1)) | ||
copyMem(result, hash.cstring, hash.len) | ||
result[hash.len] = '\0' | ||
|
||
let generateAlias* = nim_shim_c.generateAlias |
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
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
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
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,25 @@ | ||
from bitops import bitand, bitor, bitxor | ||
import secp256k1 | ||
import stew/endians2 | ||
|
||
# For details: https://en.wikipedia.org/wiki/Linear-feedback_shift_register | ||
type Lsfr* = ref object | ||
poly*: uint64 | ||
data*: uint64 | ||
|
||
proc next*(self: Lsfr): uint64 = | ||
const one: uint64 = 1 | ||
const limit: uint64 = 64 | ||
var bit: uint64 = 0 | ||
var i: uint64 = 0 | ||
while i < limit: | ||
if bitand(self.poly, one shl i) != 0: | ||
bit = bitxor(bit, self.data shr i) | ||
i += one | ||
bit = bitand(bit, one) | ||
self.data = bitor(self.data shl one, bit) | ||
result = self.data | ||
|
||
proc truncPubKey*(pubKey: string): uint64 = | ||
let rawKey = SkPublicKey.fromHex(pubKey).get.toRaw | ||
fromBytesBE(uint64, rawKey[25..32]) |
Oops, something went wrong.