Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
refactor(eos): migrate from eosjs-ecc to elliptic (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Jul 17, 2020
1 parent 65332ff commit 6d96fe9
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 194 deletions.
121 changes: 35 additions & 86 deletions .pnp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/create-hash-npm-1.1.3-8725c5adf1-2.zip
Binary file not shown.
Binary file removed .yarn/cache/create-hmac-npm-1.1.6-eb5c8566c2-2.zip
Binary file not shown.
Binary file removed .yarn/cache/ecurve-npm-1.0.5-2f786984dd-2.zip
Binary file not shown.
Binary file added .yarn/cache/elliptic-npm-6.5.3-783c509c01-2.zip
Binary file not shown.
Binary file removed .yarn/cache/eosjs-ecc-npm-4.0.7-a418aa59a6-2.zip
Binary file not shown.
Binary file removed .yarn/cache/eosjs-npm-20.0.3-417dbb6532-2.zip
Binary file not shown.
Binary file added .yarn/cache/eosjs-npm-21.0.2-047daf3463-2.zip
Binary file not shown.
Binary file added .yarn/cache/pako-npm-1.0.11-b8f1b69d3e-2.zip
Binary file not shown.
Binary file removed .yarn/cache/randombytes-npm-2.0.5-7cebe2baa8-2.zip
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ plugins:
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
spec: "@yarnpkg/plugin-interactive-tools"

packageExtensions:
"eosjs@*":
dependencies:
"bn.js": "4.11.6"
7 changes: 5 additions & 2 deletions packages/platform-sdk-eos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
"@arkecosystem/platform-sdk": "workspace:packages/platform-sdk",
"@arkecosystem/platform-sdk-crypto": "workspace:packages/platform-sdk-crypto",
"@arkecosystem/platform-sdk-support": "workspace:packages/platform-sdk-support",
"eosjs": "^20.0.3",
"eosjs-ecc": "^4.0.7",
"bn.js": "4.11.6",
"elliptic": "^6.5.3",
"eosjs": "^21.0.2",
"node-fetch": "^2.6.0",
"yup": "^0.29.1"
},
"devDependencies": {
"@ledgerhq/hw-transport-mocker": "^5.19.0",
"@sindresorhus/tsconfig": "^0.7.0",
"@types/bn.js": "4.11.6",
"@types/elliptic": "6.4.12",
"@types/eslint": "^7.2.0",
"@types/eslint-plugin-prettier": "^3.1.0",
"@types/hapi__joi": "17.1.4",
Expand Down
10 changes: 10 additions & 0 deletions packages/platform-sdk-eos/src/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PrivateKey, PublicKey, Signature } from "eosjs/dist/eosjs-jssig";

export const privateToPublic = (mnemonic: string): string =>
PrivateKey.fromString(mnemonic).getPublicKey().toLegacyString();

export const sign = (data: string, privateKey: string): string =>
PrivateKey.fromString(privateKey).sign(data, true, "utf8").toString();

export const verify = (signature: string, data: string, publicKey: string): boolean =>
Signature.fromString(signature).verify(data, PublicKey.fromString(publicKey), true, "utf8");
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Contracts, Exceptions } from "@arkecosystem/platform-sdk";
import { privateToPublic } from "eosjs-ecc";

import { privateToPublic } from "../../crypto";

export class PublicKey implements Contracts.PublicKey {
public async fromMnemonic(mnemonic: string): Promise<string> {
Expand Down
5 changes: 2 additions & 3 deletions packages/platform-sdk-eos/src/services/identity/wif.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Contracts } from "@arkecosystem/platform-sdk";
import { seedPrivate } from "eosjs-ecc";
import { Contracts, Exceptions } from "@arkecosystem/platform-sdk";

export class WIF implements Contracts.WIF {
public async fromMnemonic(mnemonic: string): Promise<string> {
return seedPrivate(mnemonic);
throw new Exceptions.NotSupported(this.constructor.name, "fromMnemonic");
}
}
9 changes: 5 additions & 4 deletions packages/platform-sdk-eos/src/services/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Coins, Contracts } from "@arkecosystem/platform-sdk";
import { BIP39 } from "@arkecosystem/platform-sdk-crypto";
import ecc from "eosjs-ecc";

import { privateToPublic, sign, verify } from "../crypto";

export class MessageService implements Contracts.MessageService {
public static async construct(config: Coins.Config): Promise<MessageService> {
Expand All @@ -16,12 +17,12 @@ export class MessageService implements Contracts.MessageService {

return {
message: input.message,
signatory: ecc.privateToPublic(mnemonic),
signature: ecc.sign(input.message, mnemonic),
signatory: privateToPublic(mnemonic),
signature: sign(input.message, mnemonic),
};
}

public async verify(input: Contracts.SignedMessage): Promise<boolean> {
return ecc.verify(input.signature, input.message, input.signatory);
return verify(input.signature, input.message, input.signatory);
}
}
Loading

0 comments on commit 6d96fe9

Please sign in to comment.