This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added address encoding to algorand app (#667)
* Added address encoding to algorand app * Updated documentation Co-authored-by: @greweb <renaudeau.gaetan@gmail.com>
- Loading branch information
Showing
6 changed files
with
69 additions
and
4 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
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,32 @@ | ||
import nacl from "tweetnacl"; | ||
import base32 from "hi-base32"; | ||
import sha512 from "js-sha512"; | ||
|
||
const PUBLIC_KEY_LENGTH = nacl.sign.publicKeyLength; | ||
const ALGORAND_ADDRESS_LENGTH = 58; | ||
const ALGORAND_CHECKSUM_BYTE_LENGTH = 4; | ||
|
||
export const encodeAddress = (address: Uint8Array): string => { | ||
const checksum = sha512.sha512_256 | ||
.array(address) | ||
.slice( | ||
PUBLIC_KEY_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH, | ||
PUBLIC_KEY_LENGTH | ||
); | ||
const addr = base32.encode(concatArrays(address, checksum)); | ||
|
||
return addr.toString().slice(0, ALGORAND_ADDRESS_LENGTH); | ||
}; | ||
|
||
function concatArrays(...arrs: ArrayLike<number>[]): Uint8Array { | ||
const size = arrs.reduce((sum, arr) => sum + arr.length, 0); | ||
const c = new Uint8Array(size); | ||
|
||
let offset = 0; | ||
for (let i = 0; i < arrs.length; i++) { | ||
c.set(arrs[i], offset); | ||
offset += arrs[i].length; | ||
} | ||
|
||
return c; | ||
} |
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
3f09baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lguien me puede ayudar con una app que tengan desarrollada necesito una para adaptarla +573214828505