-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6bd930
commit 7a93f7c
Showing
10 changed files
with
111 additions
and
37 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,25 @@ | ||
import base64url from 'base64url' | ||
import { keccak_256 } from 'js-sha3' | ||
import * as jose from 'jose' | ||
|
||
function keccak(data: any): Buffer { | ||
return Buffer.from(keccak_256.arrayBuffer(data)) | ||
} | ||
export function toEthereumAddress(hexPublicKey: string): string { | ||
return `0x${keccak(Buffer.from(hexPublicKey.slice(2), 'hex')) | ||
.slice(-20) | ||
.toString('hex')}` | ||
} | ||
|
||
export function convertECKeyToEthHexKeys(key: jose.JWK.ECKey) { | ||
const bx = base64url.toBuffer(key.x) | ||
const by = base64url.toBuffer(key.y) | ||
const hexPrivateKey = key.d ? base64url.toBuffer(key.d).toString('hex') : '' | ||
const hexPublicKey = '04' + Buffer.concat([bx, by], 64).toString('hex') | ||
const address = toEthereumAddress(hexPublicKey) | ||
return { | ||
hexPrivateKey, | ||
hexPublicKey, | ||
address, | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3754,6 +3754,16 @@ asn1.js@^4.0.0: | |
inherits "^2.0.1" | ||
minimalistic-assert "^1.0.0" | ||
|
||
asn1.js@^5.3.0: | ||
version "5.3.0" | ||
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.3.0.tgz#439099fe9174e09cff5a54a9dda70260517e8689" | ||
integrity sha512-WHnQJFcOrIWT1RLOkFFBQkFVvyt9BPOOrH+Dp152Zk4R993rSzXUGPmkybIcUFhHE2d/iHH+nCaOWVCDbO8fgA== | ||
dependencies: | ||
bn.js "^4.0.0" | ||
inherits "^2.0.1" | ||
minimalistic-assert "^1.0.0" | ||
safer-buffer "^2.1.0" | ||
|
||
asn1@~0.2.3: | ||
version "0.2.4" | ||
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136" | ||
|
@@ -9567,6 +9577,13 @@ [email protected], jest@^24.9.0: | |
import-local "^2.0.0" | ||
jest-cli "^24.9.0" | ||
|
||
jose@^1.22.1: | ||
version "1.22.1" | ||
resolved "https://registry.yarnpkg.com/jose/-/jose-1.22.1.tgz#c8681ce92cf6dbe768b3e24f86049b652e3ca680" | ||
integrity sha512-0TV4InJSlSFNXM3a9q3mwvk+hsp03G2/rHbxhR82wV1HbtJXt+5s0dazoYyfsNhLGDfxhN1htw8I0rBLLmtfLA== | ||
dependencies: | ||
asn1.js "^5.3.0" | ||
|
||
js-levenshtein@^1.1.3: | ||
version "1.1.6" | ||
resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d" | ||
|