Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 2.0.1 #67

Merged
merged 3 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.0.1] - 2020-02-08

### Changed
- use optimized Base58 implementation from Ledger BTC app ([#66])

## [2.0.0] - 2020-02-05

### Added
Expand Down Expand Up @@ -32,3 +37,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[#53]: https://github.com/ArkEcosystem/ledger/pull/53
[#55]: https://github.com/ArkEcosystem/ledger/pull/53
[2.0.0]: https://github.com/ArkEcosystem/ledger/compare/master...2.0.0
[#66]: https://github.com/ArkEcosystem/ledger/pull/66
[2.0.1]: https://github.com/ArkEcosystem/ledger/compare/master...2.0.1
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,22 @@ limitations under the License.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-----

Parts of this software are based on the Ledger Bitcoin Wallet App

Ledger App - Bitcoin Wallet
(c) 2016-2019 Ledger

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ APP_LOAD_PARAMS=--appFlags 0x240 --curve secp256k1 --path "44'/111'" --path "44'

APPVERSION_M=2
APPVERSION_N=0
APPVERSION_P=0
APPVERSION_P=1
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

ifeq ($(TARGET_NAME),TARGET_BLUE)
Expand Down
158 changes: 158 additions & 0 deletions docs/PAYLOADS.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/operations/transactions/ux/ipfs_ux.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ void displayIpfs(const Transaction *transaction) {
TOKEN_NAME, TOKEN_NAME_SIZE, TOKEN_DECIMALS);

// DAG
encodeBase58((uint8_t *)transaction->asset.ipfs.dag,
transaction->asset.ipfs.length,
(uint8_t *)displayCtx.extended_text,
MAX_TEXT_LEN);
size_t dagLen = MAX_TEXT_LEN;
btchip_encode_base58(transaction->asset.ipfs.dag,
transaction->asset.ipfs.length,
displayCtx.extended_text,
&dagLen);
}
115 changes: 56 additions & 59 deletions src/utils/base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
*
* -----
*
* Parts of this software are based on Ledger Nano SDK
*
* (c) 2017 Ledger
* Parts of this software are based on the Ledger Bitcoin Wallet App
*
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

#include "utils/base58.h"
Expand All @@ -54,6 +55,9 @@

#include "utils/utils.h"

////////////////////////////////////////////////////////////////////////////////
#define MAX_ENC_INPUT_SIZE 120

////////////////////////////////////////////////////////////////////////////////
static const uint8_t BASE58ALPHABET[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
Expand All @@ -63,71 +67,64 @@ static const uint8_t BASE58ALPHABET[] = {
};

////////////////////////////////////////////////////////////////////////////////
uint8_t encodeBase58(uint8_t *in,
size_t inSize,
uint8_t *out,
size_t maxOutSize) {
uint8_t tmp[164];
uint8_t buffer[164];
size_t j;
size_t startAt;
// src: https://github.com/LedgerHQ/ledger-app-btc/blob/master/src/btchip_base58.c#L79
int btchip_encode_base58(const unsigned char *in, size_t length,
unsigned char *out, size_t *outlen) {
unsigned char buffer[MAX_ENC_INPUT_SIZE * 138 / 100 + 1] = {0};
size_t i = 0, j;
size_t startAt, stopAt;
size_t zeroCount = 0;
size_t outputSize;

if (inSize > sizeof(tmp)) {
return 0;
if (length > MAX_ENC_INPUT_SIZE) {
return -1;
}

bytecpy(tmp, in, inSize);
while ((zeroCount < inSize) && (tmp[zeroCount] == 0U)) {
while ((zeroCount < length) && (in[zeroCount] == 0)) {
++zeroCount;
}

j = 2 * inSize;
startAt = zeroCount;
while (startAt < inSize) {
size_t remainder = 0;
size_t divLoop;

for (divLoop = startAt; divLoop < inSize; divLoop++) {
size_t digit256 = (size_t)(tmp[divLoop] & 0xff);
size_t tmpDiv = remainder * 256 + digit256;
tmp[divLoop] = (uint8_t)(tmpDiv / 58);
remainder = (tmpDiv % 58);
outputSize = (length - zeroCount) * 138 / 100 + 1;
stopAt = outputSize - 1;
for (startAt = zeroCount; startAt < length; startAt++) {
int carry = in[startAt];
for (j = outputSize - 1; (int)j >= 0; j--) {
carry += 256 * buffer[j];
buffer[j] = carry % 58;
carry /= 58;

if (j <= stopAt - 1 && carry == 0) {
break;
}
}

if (tmp[startAt] == 0) {
++startAt;
}

buffer[--j] = (uint8_t)BASE58ALPHABET[remainder];
stopAt = j;
}

while ((j < (2 * inSize)) && (buffer[j] == BASE58ALPHABET[0])) {
++j;
j = 0;
while (j < outputSize && buffer[j] == 0) {
j += 1;
}

while (zeroCount-- > 0) {
buffer[--j] = BASE58ALPHABET[0];
if (*outlen < zeroCount + outputSize - j) {
*outlen = zeroCount + outputSize - j;
return -1;
}

inSize = 2 * inSize - j;
if (maxOutSize < inSize) {
explicit_bzero(out, sizeof(out));
return 0;
}
os_memset(out, BASE58ALPHABET[0], zeroCount);

bytecpy(out, (buffer + j), inSize);
i = zeroCount;
while (j < outputSize) {
out[i++] = BASE58ALPHABET[buffer[j++]];
}
*outlen = i;

return inSize;
return 0;
}

////////////////////////////////////////////////////////////////////////////////
uint16_t encodeBase58PublicKey(uint8_t *in,
size_t inSize,
uint8_t *out,
size_t outSize,
uint16_t version,
uint8_t alreadyHashed) {
int encodeBase58PublicKey(uint8_t *in, size_t inSize,
uint8_t *out, size_t outSize,
uint16_t version, uint8_t alreadyHashed) {
uint8_t temp[inSize + 4];
uint8_t checksum[HASH_32_LEN];
size_t versionSize = (version > 255U ? 2 : 1);
Expand All @@ -153,5 +150,5 @@ uint16_t encodeBase58PublicKey(uint8_t *in,

bytecpy(&temp[ripeLength], checksum, 4);

return encodeBase58(temp, ripeLength + 4, out, outSize);
return btchip_encode_base58(temp, ripeLength + 4, out, &outSize);
}
40 changes: 18 additions & 22 deletions src/utils/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
*
* -----
*
* Parts of this software are based on Ledger Nano SDK
* Parts of this software are based on the Ledger Bitcoin Wallet App
*
* (c) 2017 Ledger
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

#ifndef ARK_UTILS_BASE58_H
Expand All @@ -49,16 +50,11 @@
#include <stdint.h>

////////////////////////////////////////////////////////////////////////////////
uint8_t encodeBase58(uint8_t *in,
size_t inSize,
uint8_t *out,
size_t maxOutSize);
int btchip_encode_base58(const unsigned char *in, size_t length,
unsigned char *out, size_t *outlen);

uint16_t encodeBase58PublicKey(uint8_t *in,
size_t inSize,
uint8_t *out,
size_t outSize,
uint16_t version,
uint8_t alreadyHashed);
int encodeBase58PublicKey(uint8_t *in, size_t inSize,
uint8_t *out, size_t outSize,
uint16_t version, uint8_t alreadyHashed);

#endif // #ifndef ARK_UTILS_BASE58_H
#endif // ARK_UTILS_BASE58_H