Skip to content

Commit

Permalink
feat(rsk): add rsk protocol with erc20-token
Browse files Browse the repository at this point in the history
  • Loading branch information
7alip committed Nov 3, 2021
1 parent 37956d1 commit 6e887c4
Show file tree
Hide file tree
Showing 44 changed files with 2,026 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Currently supported are:
- Bitcoin
- Ethereum
- Generic ERC20 Tokens
- RSK
- Generic ERC20 Tokens
- Aeternity
- Tezos
- Groestlcoin
Expand Down
4 changes: 4 additions & 0 deletions examples/generic/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BitcoinProtocol,
CosmosProtocol,
EthereumProtocol,
RskProtocol,
GroestlcoinProtocol,
KusamaProtocol,
PolkadotProtocol,
Expand All @@ -19,6 +20,7 @@ const aeternityProtocol = new AeternityProtocol()
const bitcoinProtocol = new BitcoinProtocol()
const cosmosProtocol = new CosmosProtocol()
const ethereumProtocol = new EthereumProtocol()
const rskProtocol = new RskProtocol()
const groestlcoinProtocol = new GroestlcoinProtocol()
const polkadotProtocol = new PolkadotProtocol()
const kusamaProtocol = new KusamaProtocol()
Expand All @@ -33,6 +35,8 @@ setTimeout(() => {
generateIACCode(cosmosProtocol, mnemonic, 50),
generateIACCode(ethereumProtocol, mnemonic),
generateIACCode(ethereumProtocol, mnemonic, 50),
generateIACCode(rskProtocol, mnemonic),
generateIACCode(rskProtocol, mnemonic, 50),
generateIACCode(groestlcoinProtocol, mnemonic),
generateIACCode(groestlcoinProtocol, mnemonic, 50),
generateIACCode(polkadotProtocol, mnemonic),
Expand Down
2 changes: 2 additions & 0 deletions packages/core/scripts/generate-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CURR_DIR=${BASH_SOURCE[0]%/generate-schemas.sh}
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/message-sign-response.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/message-sign-response.json"

./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-ethereum.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-ethereum.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-rsk.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-rsk.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-bitcoin.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-bitcoin.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-cosmos.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-cosmos.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-aeternity.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-aeternity.json"
Expand All @@ -58,6 +59,7 @@ CURR_DIR=${BASH_SOURCE[0]%/generate-schemas.sh}
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/signed-transaction-tezos-sapling.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-response-tezos-sapling.json"

./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/unsigned-transaction-ethereum.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-request-ethereum.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/unsigned-transaction-rsk.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-request-rsk.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/unsigned-transaction-bitcoin.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-request-bitcoin.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/unsigned-transaction-cosmos.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-request-cosmos.json"
./node_modules/.bin/ts-json-schema-generator --path "$CURR_DIR/../src/serializer-v3/schemas/definitions/unsigned-transaction-aeternity.ts" --tsconfig "tsconfig.json" > "$CURR_DIR/../src/serializer-v3/schemas/generated/transaction-sign-request-aeternity.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var replaceInFile = function (file, src, dest) {
fs_1.writeFileSync(file, newContent)
}
replaceInFile('./dist/protocols/ethereum/BaseEthereumProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/protocols/rsk/BaseRskProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/protocols/tezos/TezosProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/wallet/AirGapWallet.d.ts', 'get receivingPublicAddress(): string;', 'readonly receivingPublicAddress: string;')
replaceInFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const replaceInFile: (file: string, src: string, dest: string) => void = (file:
}

replaceInFile('./dist/protocols/ethereum/BaseEthereumProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/protocols/rsk/BaseRskProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/protocols/tezos/TezosProtocol.d.ts', 'get subProtocols(): any[];', 'readonly subProtocols: any[];')
replaceInFile('./dist/wallet/AirGapWallet.d.ts', 'get receivingPublicAddress(): string;', 'readonly receivingPublicAddress: string;')
replaceInFile(
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/errors/coinlib-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Domain {
BITCOIN = 'BITCOIN',
ETHEREUM = 'ETHEREUM',
ERC20 = 'ERC20',
RSK = 'RSK',
COSMOS = 'COSMOS',
SUBSTRATE = 'SUBSTRATE',
AETERNITY = 'AETERNITY',
Expand Down
36 changes: 36 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// tslint:disable:ordered-imports
// This needs to be imported first, otherwise the tests won't run anymore
import { EthereumProtocol } from './protocols/ethereum/EthereumProtocol'
import { RskProtocol } from './protocols/rsk/RskProtocol'

import { ProtocolNotSupported, ProtocolVersionMismatch, SerializerVersionMismatch, TypeNotSupported, NetworkError } from './errors'
import { Domain } from './errors/coinlib-error'
Expand All @@ -13,6 +14,8 @@ import { CosmosDelegationActionType, CosmosProtocol } from './protocols/cosmos/C
import { GenericERC20 } from './protocols/ethereum/erc20/GenericERC20'
import { EthereumClassicProtocol } from './protocols/ethereum/EthereumClassicProtocol'
import { EthereumRopstenProtocol } from './protocols/ethereum/EthereumRopstenProtocol'
import { GenericRskERC20 } from './protocols/rsk/erc20/GenericRskERC20'
import { RskTestnetProtocol } from './protocols/rsk/RskTestnetProtocol'
import { GroestlcoinProtocol } from './protocols/groestlcoin/GroestlcoinProtocol'
import { GroestlcoinTestnetProtocol } from './protocols/groestlcoin/GroestlcoinTestnetProtocol'
import {
Expand Down Expand Up @@ -57,18 +60,21 @@ import { SignedAeternityTransaction } from './serializer/schemas/definitions/sig
import { SignedBitcoinTransaction } from './serializer/schemas/definitions/signed-transaction-bitcoin'
import { SignedCosmosTransaction } from './serializer/schemas/definitions/signed-transaction-cosmos'
import { SignedEthereumTransaction } from './serializer/schemas/definitions/signed-transaction-ethereum'
import { SignedRskTransaction } from './serializer/schemas/definitions/signed-transaction-rsk'
import { SignedTezosTransaction } from './serializer/schemas/definitions/signed-transaction-tezos'
import { UnsignedTransaction } from './serializer/schemas/definitions/unsigned-transaction'
import { UnsignedAeternityTransaction } from './serializer/schemas/definitions/unsigned-transaction-aeternity'
import { UnsignedBitcoinTransaction } from './serializer/schemas/definitions/unsigned-transaction-bitcoin'
import { UnsignedEthereumTransaction } from './serializer/schemas/definitions/unsigned-transaction-ethereum'
import { UnsignedRskTransaction } from './serializer/schemas/definitions/unsigned-transaction-rsk'
import { UnsignedTezosTransaction } from './serializer/schemas/definitions/unsigned-transaction-tezos'
import { Serializer } from './serializer/serializer'
import { SerializerV3 } from './serializer-v3/serializer'
import {
RawAeternityTransaction,
RawBitcoinTransaction,
RawEthereumTransaction,
RawRskTransaction,
RawSubstrateTransaction,
RawTezosTransaction,
UnsignedCosmosTransaction
Expand Down Expand Up @@ -99,6 +105,7 @@ import {
CosmosProtocolOptions
} from './protocols/cosmos/CosmosProtocolOptions'
import { EthereumCryptoClient } from './protocols/ethereum/EthereumCryptoClient'
import { RskCryptoClient } from './protocols/rsk/RskCryptoClient'
import { SubstrateCryptoClient } from './protocols/substrate/SubstrateCryptoClient'
import { TezosCryptoClient } from './protocols/tezos/TezosCryptoClient'
import {
Expand All @@ -110,6 +117,15 @@ import {
EthereumERC20ProtocolConfig,
EthereumERC20ProtocolOptions
} from './protocols/ethereum/EthereumProtocolOptions'
import {
RskProtocolNetworkExtras,
RskExplorerBlockExplorer,
RskProtocolNetwork,
RskProtocolConfig,
RskProtocolOptions,
RskERC20ProtocolConfig,
RskERC20ProtocolOptions
} from './protocols/rsk/RskProtocolOptions'
import { ProtocolBlockExplorer } from './utils/ProtocolBlockExplorer'
import { NetworkType, ProtocolNetwork } from './utils/ProtocolNetwork'
import {
Expand Down Expand Up @@ -213,6 +229,7 @@ import { TezosDomains } from './protocols/tezos/domains/TezosDomains'
import { AeternityAddress } from './protocols/aeternity/AeternityAddress'
import { BitcoinAddress } from './protocols/bitcoin/BitcoinAddress'
import { EthereumAddress } from './protocols/ethereum/EthereumAddress'
import { RskAddress } from './protocols/rsk/RskAddress'
import { TezosAddress } from './protocols/tezos/TezosAddress'
import { IACMessageDefinitionObjectV3 } from './serializer-v3/message'
import { IACMessages as IACMessagesV2 } from './serializer/message'
Expand Down Expand Up @@ -324,6 +341,23 @@ export {
RawEthereumTransaction
}

// Rsk
export {
RskProtocol,
RskTestnetProtocol,
GenericRskERC20,
RskCryptoClient,
RskProtocolNetworkExtras,
RskExplorerBlockExplorer,
RskProtocolNetwork,
RskProtocolConfig,
RskProtocolOptions,
RskERC20ProtocolConfig,
RskERC20ProtocolOptions,
RskAddress,
RawRskTransaction
}

// Groestlcoin
export {
GroestlcoinProtocol,
Expand Down Expand Up @@ -454,12 +488,14 @@ export {
UnsignedBitcoinSegwitTransaction,
UnsignedCosmosTransaction,
UnsignedEthereumTransaction,
UnsignedRskTransaction,
UnsignedTezosTransaction,
SignedAeternityTransaction,
SignedBitcoinTransaction,
SignedBitcoinSegwitTransaction,
SignedCosmosTransaction,
SignedEthereumTransaction,
SignedRskTransaction,
SignedTezosTransaction,
Serializer,
SerializerV3,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/interfaces/IAirGapTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AeternityTransactionCursor } from '../protocols/aeternity/AeternityTypes'
import { EthereumTransactionCursor } from '../protocols/ethereum/EthereumTypes'
import { RskTransactionCursor } from '../protocols/rsk/RskTypes'
import { ProtocolNetwork } from '../utils/ProtocolNetwork'
import { ProtocolSymbols } from '../utils/ProtocolSymbols'

Expand Down Expand Up @@ -60,6 +61,7 @@ export interface IAirGapTransaction {

export type IProtocolTransactionCursor =
| EthereumTransactionCursor
| RskTransactionCursor
| BitcoinTransactionCursor
| TezosTransactionCursor
| AeternityTransactionCursor
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,19 @@ networks.etc = {
ethereum: true
}

// TODO: Validate config
networks.rks = {
messagePrefix: '\x19RSK Signed Message:\n',
bip32: {
public: 0xffffffff,
private: 0xffffffff
},
scriptHash: 13,
pubKeyHash: 0xff,
wif: 0xff,
ethereum: true
}

networks.clo = {
bip32: {
public: 0xffffffff,
Expand Down
Loading

0 comments on commit 6e887c4

Please sign in to comment.