-
Notifications
You must be signed in to change notification settings - Fork 73
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
CAIP 10 support (blockchainAccountId) #205
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import SHA256 from 'crypto-js/sha256' | ||
import RIPEMD160 from 'crypto-js/ripemd160' | ||
import enc from 'crypto-js/enc-hex' | ||
import RIPEMD160 from 'ripemd160' | ||
import { bytesToBase58 } from '../util' | ||
import { sha256 } from '../Digest' | ||
|
||
export const publicKeyToAddress = (publicKeyBuffer: string): string => { | ||
const publicKeyHash = RIPEMD160(SHA256(enc.parse(publicKeyBuffer))) | ||
const step1 = Buffer.from('00' + publicKeyHash.toString(enc), 'hex') | ||
const step2 = SHA256(SHA256(enc.parse(step1.toString('hex')))) | ||
const checksum = step2.toString(enc).substring(0, 8) | ||
const step3 = step1.toString('hex') + checksum | ||
return bytesToBase58(Uint8Array.from(Buffer.from(step3, 'hex'))) | ||
export const publicKeyToAddress = (publicKey: string): string => { | ||
const publicKeyBuffer = Uint8Array.from(Buffer.from(publicKey, 'hex')) | ||
const hash = new RIPEMD160().update(Buffer.from(sha256(publicKeyBuffer))).digest() | ||
const step1 = Buffer.concat([Buffer.from('00', 'hex'), hash]) | ||
const checksum = Buffer.from(sha256(sha256(step1))) | ||
.toString('hex') | ||
.substring(0, 8) | ||
const step2 = step1.toString('hex') + checksum | ||
return bytesToBase58(Uint8Array.from(Buffer.from(step2, 'hex'))) | ||
} |
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,10 +1,10 @@ | ||
import SHA256 from 'crypto-js/sha256' | ||
import RIPEMD160 from 'crypto-js/ripemd160' | ||
import enc from 'crypto-js/enc-hex' | ||
import RIPEMD160 from 'ripemd160' | ||
import { sha256 } from '../Digest' | ||
import { bech32 } from 'bech32' | ||
|
||
export const publicKeyToAddress = (publicKeyBuffer: string, prefix: string): string => { | ||
const hash = RIPEMD160(SHA256(enc.parse(publicKeyBuffer))) | ||
const words = bech32.toWords(Buffer.from(hash.toString(), 'hex')) | ||
export const publicKeyToAddress = (publicKey: string, prefix: string): string => { | ||
const publicKeyBuffer = Uint8Array.from(Buffer.from(publicKey, 'hex')) | ||
const hash = new RIPEMD160().update(Buffer.from(sha256(publicKeyBuffer))).digest() | ||
const words = bech32.toWords(hash) | ||
return bech32.encode(prefix, words).replace(prefix, '') | ||
} |
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 |
---|---|---|
|
@@ -1825,11 +1825,6 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/crypto-js@^4.0.2": | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.0.2.tgz#4524325a175bf819fec6e42560c389ce1fb92c97" | ||
integrity sha512-sCVniU+h3GcGqxOmng11BRvf9TfN9yIs8KKjB8C8d75W69cpTfZG80gau9yTx5SxF3gvHGbJhdESzzvnjtf3Og== | ||
|
||
"@types/[email protected]", "@types/elliptic@^6.4.9": | ||
version "6.4.12" | ||
resolved "https://registry.yarnpkg.com/@types/elliptic/-/elliptic-6.4.12.tgz#e8add831f9cc9a88d9d84b3733ff669b68eaa124" | ||
|
@@ -1949,6 +1944,13 @@ | |
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" | ||
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== | ||
|
||
"@types/ripemd160@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/ripemd160/-/ripemd160-2.0.0.tgz#d33e49cf66edf4668828030d4aa80116bbf8ae81" | ||
integrity sha512-LD6AO/+8cAa1ghXax9NG9iPDLPUEGB2WWPjd//04KYfXxTwHvlDEfL0NRjrM5z9XWBi6WbKw75Are0rDyn3PSA== | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/stack-utils@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff" | ||
|
@@ -3195,11 +3197,6 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: | |
shebang-command "^2.0.0" | ||
which "^2.0.1" | ||
|
||
crypto-js@^4.1.1: | ||
version "4.1.1" | ||
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf" | ||
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw== | ||
|
||
crypto-random-string@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" | ||
|
@@ -4429,6 +4426,15 @@ has@^1.0.0, has@^1.0.3: | |
dependencies: | ||
function-bind "^1.1.1" | ||
|
||
hash-base@^3.0.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.1.0.tgz#55c381d9e06e1d2997a883b4a3fddfe7f0d3af33" | ||
integrity sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA== | ||
dependencies: | ||
inherits "^2.0.4" | ||
readable-stream "^3.6.0" | ||
safe-buffer "^5.2.0" | ||
|
||
hash.js@^1.0.0, hash.js@^1.0.3: | ||
version "1.1.7" | ||
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" | ||
|
@@ -7439,7 +7445,7 @@ read@1, read@^1.0.7, read@~1.0.1, read@~1.0.7: | |
dependencies: | ||
mute-stream "~0.0.4" | ||
|
||
readable-stream@3, readable-stream@^3.0.0: | ||
readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.6.0: | ||
version "3.6.0" | ||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" | ||
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== | ||
|
@@ -7658,6 +7664,14 @@ rimraf@^3.0.0, rimraf@^3.0.2: | |
dependencies: | ||
glob "^7.1.3" | ||
|
||
ripemd160@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" | ||
integrity sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA== | ||
dependencies: | ||
hash-base "^3.0.0" | ||
inherits "^2.0.1" | ||
|
||
rollup-plugin-bundle-size@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/rollup-plugin-bundle-size/-/rollup-plugin-bundle-size-1.0.3.tgz#d245cd988486b4040279f9fd33f357f61673e90f" | ||
|
@@ -7734,7 +7748,7 @@ sade@^1.7.4: | |
dependencies: | ||
mri "^1.1.0" | ||
|
||
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.2.0: | ||
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0: | ||
version "5.2.1" | ||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" | ||
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we please not use
Buffer
it's a nodejs only dependency!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.
Should use
Uint8Array
instead!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.
The
uint8arrays
pkg is your friend.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.
Buffer error from ripemd160, and ripemd160 also use buffer.
So use
crypto-js/ripemd160
package (or ripemd160.js) only, or looking for other way.What do you think?
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.
Hm, thoughts @mirceanis ? Could
crypto-js/ripemd160
cause issues somewhere bc it's js modules?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.
make and add new
ripemd160.ts
.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.
@daoauth I've been trying to test your changes in react-native (that's where most issues arise with new dependencies), and there are still issues with regards to the use of
Buffer
.I suppose that they can be worked around by some rn-nodeify magic, but I would like to keep that option as a last resort, since it complicates all setups.
@oed's suggestion to use
uint8arrays
instead ofBuffer
refers to the complete replacement of the nodejs-specificBuffer
API.That being said, I'm not yet comfortable taking on the maintenance burden of a RIPEMD160 implementation.
Ideally there should be a Uint8Array friendly RIPEMD160 implementation we could use.
I haven't yet had time to try the variant with
crypto-js/ripemd160
; but I see there were some build issues with it.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.
@mirceanis How about
DataView
? Can I use it?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.
wow, that was fast :)
This new commit seems to work ok in my tests.
I'm still reluctant about taking on the RIPEMD160 implementation, but I'm also not aware of trustworthy alternatives.
@oed any insights appreciated ;)
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.
DataView
seems like a standard lib: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView