This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LL-7930 Ensure bech32 version 1.1.x and 2.0.0 are not used together (#…
…1528) * LL-7930 Fallback using bech32 ^1.1.3 instead of 2.0.0 * Revert wrong modif * Update yarn.lock * Fix from review * Add jira ticket info
- Loading branch information
Hakim
authored
Nov 19, 2021
1 parent
44c2680
commit 57f82d0
Showing
12 changed files
with
220 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
// Ported from https://github.com/bitcoinjs/bech32/tree/605655d6b37a782345549cd1388db688a96ad56f | ||
// until we can use bech32 2.0.0 | ||
// We can't directly use bech32 2.0.0 because many of our dependencies are still using bech32 ^1.1.3 | ||
// which conflict on mobile (root cause of https://ledgerhq.atlassian.net/browse/LL-7930) | ||
// FIXME Remove that file and use bech32 2.0.0 when all dependencies also uses it. | ||
|
||
const ENCODING_CONST = 0x2bc830a3; | ||
const ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; | ||
const ALPHABET_MAP: { [key: string]: number } = {}; | ||
for (let z = 0; z < ALPHABET.length; z++) { | ||
const x = ALPHABET.charAt(z); | ||
ALPHABET_MAP[x] = z; | ||
} | ||
|
||
function prefixChk(prefix) { | ||
let chk = 1; | ||
for (let i = 0; i < prefix.length; ++i) { | ||
const c = prefix.charCodeAt(i); | ||
if (c < 33 || c > 126) return "Invalid prefix (" + prefix + ")"; | ||
chk = polymodStep(chk) ^ (c >> 5); | ||
} | ||
chk = polymodStep(chk); | ||
for (let i = 0; i < prefix.length; ++i) { | ||
const v = prefix.charCodeAt(i); | ||
chk = polymodStep(chk) ^ (v & 0x1f); | ||
} | ||
return chk; | ||
} | ||
|
||
function polymodStep(pre: number): number { | ||
const b = pre >> 25; | ||
return ( | ||
((pre & 0x1ffffff) << 5) ^ | ||
(-((b >> 0) & 1) & 0x3b6a57b2) ^ | ||
(-((b >> 1) & 1) & 0x26508e6d) ^ | ||
(-((b >> 2) & 1) & 0x1ea119fa) ^ | ||
(-((b >> 3) & 1) & 0x3d4233dd) ^ | ||
(-((b >> 4) & 1) & 0x2a1462b3) | ||
); | ||
} | ||
|
||
function encode( | ||
prefix: string, | ||
words: ArrayLike<number>, | ||
LIMIT?: number | ||
): string { | ||
LIMIT = LIMIT || 90; | ||
if (prefix.length + 7 + words.length > LIMIT) | ||
throw new TypeError("Exceeds length limit"); | ||
|
||
prefix = prefix.toLowerCase(); | ||
|
||
// determine chk mod | ||
let chk = prefixChk(prefix); | ||
if (typeof chk === "string") throw new Error(chk); | ||
|
||
let result = prefix + "1"; | ||
for (let i = 0; i < words.length; ++i) { | ||
const x = words[i]; | ||
if (x >> 5 !== 0) throw new Error("Non 5-bit word"); | ||
|
||
chk = polymodStep(chk) ^ x; | ||
result += ALPHABET.charAt(x); | ||
} | ||
|
||
for (let i = 0; i < 6; ++i) { | ||
chk = polymodStep(chk); | ||
} | ||
chk ^= ENCODING_CONST; | ||
|
||
for (let i = 0; i < 6; ++i) { | ||
const v = (chk >> ((5 - i) * 5)) & 0x1f; | ||
result += ALPHABET.charAt(v); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function __decode(str: string, LIMIT?: number) { | ||
LIMIT = LIMIT || 90; | ||
if (str.length < 8) return str + " too short"; | ||
if (str.length > LIMIT) return "Exceeds length limit"; | ||
|
||
// don't allow mixed case | ||
const lowered = str.toLowerCase(); | ||
const uppered = str.toUpperCase(); | ||
if (str !== lowered && str !== uppered) return "Mixed-case string " + str; | ||
str = lowered; | ||
|
||
const split = str.lastIndexOf("1"); | ||
if (split === -1) return "No separator character for " + str; | ||
if (split === 0) return "Missing prefix for " + str; | ||
|
||
const prefix = str.slice(0, split); | ||
const wordChars = str.slice(split + 1); | ||
if (wordChars.length < 6) return "Data too short"; | ||
|
||
let chk = prefixChk(prefix); | ||
if (typeof chk === "string") return chk; | ||
|
||
const words: number[] = []; | ||
for (let i = 0; i < wordChars.length; ++i) { | ||
const c = wordChars.charAt(i); | ||
const v = ALPHABET_MAP[c]; | ||
if (v === undefined) return "Unknown character " + c; | ||
chk = polymodStep(chk) ^ v; | ||
|
||
// not in the checksum? | ||
if (i + 6 >= wordChars.length) continue; | ||
words.push(v); | ||
} | ||
|
||
if (chk !== ENCODING_CONST) return "Invalid checksum for " + str; | ||
return { prefix, words }; | ||
} | ||
|
||
function decodeUnsafe(str: string, LIMIT?: number) { | ||
const res = __decode(str, LIMIT); | ||
if (typeof res === "object") return res; | ||
} | ||
|
||
function decode(str: string, LIMIT?: number) { | ||
const res = __decode(str, LIMIT); | ||
if (typeof res === "object") return res; | ||
|
||
throw new Error(res); | ||
} | ||
|
||
function convert( | ||
data: ArrayLike<number>, | ||
inBits: number, | ||
outBits: number, | ||
pad: true | ||
): number[]; | ||
function convert( | ||
data: ArrayLike<number>, | ||
inBits: number, | ||
outBits: number, | ||
pad: false | ||
): number[] | string; | ||
function convert( | ||
data: ArrayLike<number>, | ||
inBits: number, | ||
outBits: number, | ||
pad: boolean | ||
): number[] | string { | ||
let value = 0; | ||
let bits = 0; | ||
const maxV = (1 << outBits) - 1; | ||
|
||
const result: number[] = []; | ||
for (let i = 0; i < data.length; ++i) { | ||
value = (value << inBits) | data[i]; | ||
bits += inBits; | ||
|
||
while (bits >= outBits) { | ||
bits -= outBits; | ||
result.push((value >> bits) & maxV); | ||
} | ||
} | ||
|
||
if (pad) { | ||
if (bits > 0) { | ||
result.push((value << (outBits - bits)) & maxV); | ||
} | ||
} else { | ||
if (bits >= inBits) return "Excess padding"; | ||
if ((value << (outBits - bits)) & maxV) return "Non-zero padding"; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function toWords(bytes: ArrayLike<number>): number[] { | ||
return convert(bytes, 8, 5, true); | ||
} | ||
|
||
function fromWordsUnsafe(words: ArrayLike<number>): number[] | undefined { | ||
const res = convert(words, 5, 8, false); | ||
if (Array.isArray(res)) return res; | ||
} | ||
|
||
function fromWords(words: ArrayLike<number>): number[] { | ||
const res = convert(words, 5, 8, false); | ||
if (Array.isArray(res)) return res; | ||
|
||
throw new Error(res); | ||
} | ||
|
||
export const bech32m = { | ||
decodeUnsafe, | ||
decode, | ||
encode, | ||
toWords, | ||
fromWordsUnsafe, | ||
fromWords, | ||
}; |
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
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 |
---|---|---|
|
@@ -2609,7 +2609,7 @@ bchaddrjs@^0.5.2: | |
cashaddrjs "0.4.4" | ||
stream-browserify "^3.0.0" | ||
|
||
[email protected], bech32@^1.1.2, bech32@^1.1.4: | ||
[email protected], bech32@^1.1.2, bech32@^1.1.3, bech32@^1.1.4: | ||
version "1.1.4" | ||
resolved "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz" | ||
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== | ||
|
@@ -2619,11 +2619,6 @@ bech32@=1.1.3: | |
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.3.tgz#bd47a8986bbb3eec34a56a097a84b8d3e9a2dfcd" | ||
integrity sha512-yuVFUvrNcoJi0sv5phmqc6P+Fl1HjRDRNOOkHY2X/3LBy2bIGNSFx4fZ95HMaXHupuS7cZR15AsvtmCIF4UEyg== | ||
|
||
bech32@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" | ||
integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== | ||
|
||
benchmark@^2.1.4: | ||
version "2.1.4" | ||
resolved "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz" | ||
|
57f82d0
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.
Successfully deployed to the following URLs:
57f82d0
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.
✅ 40 txs ❌ 15 txs⚠️ 2 specs ($332.67) for Bot 'Silicium'
2 critical spec errors
Spec BSC failed!
Spec Filecoin failed!
15 mutation errors
Details of the 55 mutations
Spec Algorand (6)
Spec Bitcoin (5)
Spec Bitcoin Testnet (24)
Spec Bitcoin Cash (failed)
Spec Bitcoin Gold (6)
Spec Dash (7)
Spec Digibyte (8)
Spec DogeCoin (7)
Spec Komodo (5)
Spec Litecoin (7)
Spec Peercoin (5)
Spec PivX (5)
Spec Qtum (6)
Spec Stakenet (6)
Spec Vertcoin (5)
Spec Viacoin (5)
Spec ZCash (5)
Spec Horizen (5)
Spec Cosmos (6)
Spec Crypto.org Testnet (5)
Spec Elrond (3)
Spec BSC (failed)
Spec Ethereum (failed)
Spec Ethereum Classic (6)
Spec Ethereum Ropsten (10)
Spec Filecoin (failed)
Spec Polkadot (3)
Spec XRP (failed)
Spec Stellar (6)
Spec Tezos (8)
Spec Tron (10)
Details of the 68 uncovered mutations
Spec Algorand (5)
Spec Bitcoin (4)
Spec Bitcoin Cash (4)
Spec Dash (4)
Spec Qtum (3)
Spec Stakenet (2)
Spec Vertcoin (3)
Spec Viacoin (2)
Spec ZCash (4)
Spec Horizen (2)
Spec Cosmos (6)
Spec BSC (2)
Spec Ethereum (6)
Spec Filecoin (1)
Spec Polkadot (5)
Spec XRP (1)
Spec Tezos (7)
Spec Tron (7)
Portfolio ($332.67)
Details of the 31 currencies