Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"@buildonspark/spark-sdk": "^0.3.5",
"@cardano-foundation/cardano-verify-datasignature": "^1.0.11",
"@deuro/eurocoin": "^1.0.16",
"@dfinity/identity": "^3.4.3",
"@dfinity/ledger-icp": "^9.1.0",
"@dfinity/ledger-icrc": "^7.1.0",
"@dhedge/v2-sdk": "^1.11.1",
"@emurgo/cardano-serialization-lib-nodejs": "^15.0.3",
"@eth-optimism/sdk": "^3.3.3",
Expand Down Expand Up @@ -169,7 +172,8 @@
],
"rootDir": "src",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
"^src/(.*)$": "<rootDir>/$1",
"^@dfinity/(ledger-icp|ledger-icrc|utils)$": "<rootDir>/integration/blockchain/icp/__mocks__/dfinity-$1.mock.ts"
},
"testRegex": ".*\\.spec\\.ts$",
"transform": {
Expand Down
36 changes: 27 additions & 9 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ export class Configuration {
solanaAddressFormat = '[1-9A-HJ-NP-Za-km-z]{43,44}';
tronAddressFormat = 'T[1-9A-HJ-NP-Za-km-z]{32,34}';
zanoAddressFormat = 'Z[a-zA-Z0-9]{96}|iZ[a-zA-Z0-9]{106}';
internetComputerPrincipalFormat = '[a-z0-9]{5}(-[a-z0-9]{5})*(-[a-z0-9]{1,5})?';

allAddressFormat = `${this.bitcoinAddressFormat}|${this.lightningAddressFormat}|${this.sparkAddressFormat}|${this.firoAddressFormat}|${this.moneroAddressFormat}|${this.ethereumAddressFormat}|${this.liquidAddressFormat}|${this.arweaveAddressFormat}|${this.cardanoAddressFormat}|${this.defichainAddressFormat}|${this.railgunAddressFormat}|${this.solanaAddressFormat}|${this.tronAddressFormat}|${this.zanoAddressFormat}`;
allAddressFormat = `${this.bitcoinAddressFormat}|${this.lightningAddressFormat}|${this.sparkAddressFormat}|${this.firoAddressFormat}|${this.moneroAddressFormat}|${this.ethereumAddressFormat}|${this.liquidAddressFormat}|${this.arweaveAddressFormat}|${this.cardanoAddressFormat}|${this.defichainAddressFormat}|${this.railgunAddressFormat}|${this.solanaAddressFormat}|${this.tronAddressFormat}|${this.zanoAddressFormat}|${this.internetComputerPrincipalFormat}`;

masterKeySignatureFormat = '[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}';
hashSignatureFormat = '[A-Fa-f0-9]{64}';
Expand All @@ -178,13 +179,15 @@ export class Configuration {
solanaSignatureFormat = '[1-9A-HJ-NP-Za-km-z]{87,88}';
tronSignatureFormat = '(0x)?[a-f0-9]{130}';
zanoSignatureFormat = '[a-f0-9]{128}';
internetComputerSignatureFormat = '[a-f0-9]{128,144}';

allSignatureFormat = `${this.masterKeySignatureFormat}|${this.hashSignatureFormat}|${this.bitcoinSignatureFormat}|${this.lightningSignatureFormat}|${this.lightningCustodialSignatureFormat}|${this.firoSignatureFormat}|${this.moneroSignatureFormat}|${this.ethereumSignatureFormat}|${this.arweaveSignatureFormat}|${this.cardanoSignatureFormat}|${this.railgunSignatureFormat}|${this.solanaSignatureFormat}|${this.tronSignatureFormat}|${this.zanoSignatureFormat}`;
allSignatureFormat = `${this.masterKeySignatureFormat}|${this.hashSignatureFormat}|${this.bitcoinSignatureFormat}|${this.lightningSignatureFormat}|${this.lightningCustodialSignatureFormat}|${this.firoSignatureFormat}|${this.moneroSignatureFormat}|${this.ethereumSignatureFormat}|${this.arweaveSignatureFormat}|${this.cardanoSignatureFormat}|${this.railgunSignatureFormat}|${this.solanaSignatureFormat}|${this.tronSignatureFormat}|${this.zanoSignatureFormat}|${this.internetComputerSignatureFormat}`;

arweaveKeyFormat = '[\\w\\-]{683}';
cardanoKeyFormat = '.*';
internetComputerKeyFormat = '[a-f0-9]{64,130}';

allKeyFormat = `${this.arweaveKeyFormat}|${this.cardanoKeyFormat}`;
allKeyFormat = `${this.arweaveKeyFormat}|${this.cardanoKeyFormat}|${this.internetComputerKeyFormat}`;

formats = {
address: new RegExp(`^(${this.allAddressFormat})$`),
Expand Down Expand Up @@ -629,16 +632,20 @@ export class Configuration {
solanaSeed: process.env.PAYMENT_SOLANA_SEED,
tronSeed: process.env.PAYMENT_TRON_SEED,
cardanoSeed: process.env.PAYMENT_CARDANO_SEED,
internetComputerSeed: process.env.PAYMENT_INTERNET_COMPUTER_SEED,
bitcoinAddress: process.env.PAYMENT_BITCOIN_ADDRESS,
firoAddress: process.env.PAYMENT_FIRO_ADDRESS,
moneroAddress: process.env.PAYMENT_MONERO_ADDRESS,
zanoAddress: process.env.PAYMENT_ZANO_ADDRESS,
minConfirmations: (blockchain: Blockchain) =>
[Blockchain.ETHEREUM, Blockchain.BITCOIN, Blockchain.FIRO, Blockchain.MONERO, Blockchain.ZANO].includes(
blockchain,
)
? 6
: 100,
minConfirmations: (blockchain: Blockchain): number =>
({
[Blockchain.ETHEREUM]: 6,
[Blockchain.BITCOIN]: 6,
[Blockchain.FIRO]: 6,
[Blockchain.MONERO]: 6,
[Blockchain.ZANO]: 6,
[Blockchain.INTERNET_COMPUTER]: 1,
})[blockchain] ?? 100,
minVolume: 0.01, // CHF
maxDepositBalance: 10000, // CHF
cryptoPayoutMinAmount: +(process.env.PAYMENT_CRYPTO_PAYOUT_MIN ?? 1000), // CHF
Expand Down Expand Up @@ -971,6 +978,17 @@ export class Configuration {
index: accountIndex,
}),
},
internetComputer: {
internetComputerHost: 'https://ic0.app',
internetComputerWalletSeed: process.env.ICP_WALLET_SEED,
internetComputerLedgerCanisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai',
transferFee: 0.0001,

walletAccount: (accountIndex: number): WalletAccount => ({
seed: this.blockchain.internetComputer.internetComputerWalletSeed,
index: accountIndex,
}),
},
frankencoin: {
zchfGraphUrl: process.env.ZCHF_GRAPH_URL,
contractAddress: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Test } from '@nestjs/testing';
import { ArweaveService } from 'src/integration/blockchain/arweave/services/arweave.service';
import { CardanoService } from 'src/integration/blockchain/cardano/services/cardano.service';
import { FiroService } from 'src/integration/blockchain/firo/services/firo.service';
import { InternetComputerService } from 'src/integration/blockchain/icp/services/icp.service';
import { MoneroService } from 'src/integration/blockchain/monero/services/monero.service';
import { Blockchain } from 'src/integration/blockchain/shared/enums/blockchain.enum';
import { BlockchainRegistryService } from 'src/integration/blockchain/shared/services/blockchain-registry.service';
Expand Down Expand Up @@ -33,6 +34,7 @@ describe('CryptoService', () => {
{ provide: CardanoService, useValue: createMock<CardanoService>() },
{ provide: ArweaveService, useValue: createMock<ArweaveService>() },
{ provide: RailgunService, useValue: createMock<RailgunService>() },
{ provide: InternetComputerService, useValue: createMock<InternetComputerService>() },
{ provide: BlockchainRegistryService, useValue: createMock<BlockchainRegistryService>() },
TestUtil.provideConfig(),
],
Expand Down Expand Up @@ -293,6 +295,18 @@ describe('CryptoService', () => {
);
});

it('should return Blockchain.INTERNET_COMPUTER for address rjyxf-rur4n-jwk64-rsslr-kppnq-irqqy-s2wil-peeif-k3syc-intp2-uae', () => {
expect(
CryptoService.getBlockchainsBasedOn('rjyxf-rur4n-jwk64-rsslr-kppnq-irqqy-s2wil-peeif-k3syc-intp2-uae'),
).toEqual([Blockchain.INTERNET_COMPUTER]);
});

it('should return UserAddressType.INTERNET_COMPUTER for address rjyxf-rur4n-jwk64-rsslr-kppnq-irqqy-s2wil-peeif-k3syc-intp2-uae', () => {
expect(CryptoService.getAddressType('rjyxf-rur4n-jwk64-rsslr-kppnq-irqqy-s2wil-peeif-k3syc-intp2-uae')).toEqual(
UserAddressType.INTERNET_COMPUTER,
);
});

it('should return Blockchain.RAILGUN for address 0zk1qyq24xdx7xuuf2ldgm2a96zd32t9ktru7dm88apaykhqu9cmnx9a3rv7j6fe3z53l7p2rhypluwfqqwa6t7nejqq0nj2quwy0599l8aw8u7fqh98qkhyupxjfqh', () => {
expect(
CryptoService.getBlockchainsBasedOn(
Expand Down
3 changes: 3 additions & 0 deletions src/integration/blockchain/blockchain.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { TxValidationService } from './shared/services/tx-validation.service';
import { SolanaModule } from './solana/solana.module';
import { SparkModule } from './spark/spark.module';
import { TronModule } from './tron/tron.module';
import { InternetComputerModule } from './icp/icp.module';
import { ZanoModule } from './zano/zano.module';

@Module({
Expand Down Expand Up @@ -64,6 +65,7 @@ import { ZanoModule } from './zano/zano.module';
SolanaModule,
TronModule,
CardanoModule,
InternetComputerModule,
CitreaModule,
CitreaTestnetModule,
ClementineModule,
Expand Down Expand Up @@ -96,6 +98,7 @@ import { ZanoModule } from './zano/zano.module';
SolanaModule,
TronModule,
CardanoModule,
InternetComputerModule,
CitreaModule,
CitreaTestnetModule,
ClementineModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const IcpLedgerCanister = {
create: () => ({
transfer: jest.fn(),
icrc1Transfer: jest.fn(),
accountBalance: jest.fn(),
}),
};

export const AccountIdentifier = {
fromHex: jest.fn(),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const IcrcLedgerCanister = {
create: () => ({
balance: jest.fn(),
transactionFee: jest.fn(),
transfer: jest.fn(),
icrc1Transfer: jest.fn(),
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty mock - @dfinity/utils is only loaded transitively
Loading
Loading