Skip to content

Commit

Permalink
feature: adding enkrypt wallet for pegin
Browse files Browse the repository at this point in the history
  • Loading branch information
annipi committed Oct 3, 2024
1 parent 38c88f9 commit b9530c0
Show file tree
Hide file tree
Showing 27 changed files with 403 additions and 207 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scanner": "npx sonar-scanner"
},
"dependencies": {
"@enkryptcom/types": "^0.0.5",
"@leather.io/rpc": "^2.0.2",
"@ledgerhq/devices": "6.27.1",
"@ledgerhq/hw-app-btc": "6.27.1",
Expand Down
Binary file added src/assets/exchange/enkrypt/connect_enkrypt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/wallet-icons/enkrypt-black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/wallet-icons/enkrypt-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/wallet-icons/enkrypt-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/common/components/exchange/ConnectDevice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default defineComponent({
// eslint-disable-next-line global-require, import/no-dynamic-require
return require('@/assets/exchange/leather/connect_leather.png');
}
if (bitcoinWallet.value === constants.WALLET_NAMES.ENKRYPT.long_name) {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require('@/assets/exchange/enkrypt/connect_enkrypt.png');
}
// eslint-disable-next-line global-require, import/no-dynamic-require
return require('@/assets/exchange/wallet.png');
});
Expand Down
3 changes: 3 additions & 0 deletions src/common/components/exchange/SelectBitcoinWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export default {
case constants.WALLET_NAMES.LEATHER.long_name:
wallet = constants.WALLET_NAMES.LEATHER.short_name;
break;
case constants.WALLET_NAMES.ENKRYPT.long_name:
wallet = constants.WALLET_NAMES.ENKRYPT.short_name;
break;
default:
wallet = '';
break;
Expand Down
91 changes: 91 additions & 0 deletions src/common/services/EnkryptService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* eslint-disable class-methods-use-this, @typescript-eslint/no-explicit-any */
import * as bitcoin from 'bitcoinjs-lib';
import {
BtcAccount,
WalletAddress,
SignedTx,
} from '@/common/types';
import { WalletService } from '@/common/services/index';
import { EnkryptTx } from '@/pegin/middleware/TxBuilder/EnkryptTxBuilder';
import * as constants from '@/common/store/constants';
import ProviderError from '@enkryptcom/types';

export default class EnkryptService extends WalletService {
private btcProvider;

constructor() {
super();
if (this.network === 'test') window.enkrypt.providers.bitcoin.switchNetwork('testnet');
this.btcProvider = window.enkrypt.providers.bitcoin;
}

name(): Record<'formal_name' | 'short_name' | 'long_name', string> {
return constants.WALLET_NAMES.ENKRYPT;
}

getAccountAddresses(): Promise<WalletAddress[]> {
return new Promise<WalletAddress[]>((resolve, reject) => {
this.btcProvider.getAccounts()
.then((addresses: string[]) => {
const walletAddresses = addresses
.map((address) => ({ address, derivationPath: '', publicKey: '' } as WalletAddress));
resolve(walletAddresses);
})
.catch((e: typeof ProviderError) => reject(e));
});
}

availableAccounts(): BtcAccount[] {
return [constants.BITCOIN_NATIVE_SEGWIT_ADDRESS];
}

isConnected(): Promise<boolean> {
return new Promise<boolean>((resolve) => {
resolve(this.btcProvider.isConnected());
});
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
getXpub(accountType: BtcAccount, accountNumber: number): Promise<string> {
return Promise.reject(new Error());
}

/** Needed to load account balance */
executed = false;

areEnoughUnusedAddresses(): boolean {
if (!this.executed) {
this.executed = true;
return !this.executed;
}
return this.executed;
}

sign(tx: EnkryptTx): Promise<SignedTx> {
return new Promise((resolve, reject) => {
this.btcProvider?.signPsbt(tx.hex, { autoFinalized: false })
.then((hex: string) => {
const signedPsbt = bitcoin.Psbt.fromHex(hex)
.finalizeAllInputs()
.extractTransaction()
.toHex();
resolve({ signedTx: signedPsbt });
})
.catch((e: typeof ProviderError) => {
reject(e);
});
});
}

async reconnect(): Promise<void> {
return new Promise<void>((resolve, reject) => {
try {
if (this.network === 'test') window.enkrypt.providers.bitcoin.switchNetwork('testnet');
this.btcProvider = window.enkrypt.providers.bitcoin;
resolve();
} catch (e: any) {
reject(e);
}
});
}
}
27 changes: 0 additions & 27 deletions src/common/services/LeatherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as bitcoin from 'bitcoinjs-lib';
import {
BtcAccount,
WalletAddress,
Step,
SignedTx,
} from '@/common/types';
import { WalletService } from '@/common/services/index';
Expand Down Expand Up @@ -40,32 +39,6 @@ export default class LeatherService extends WalletService {
];
}

// eslint-disable-next-line class-methods-use-this
confirmationSteps(): Step[] {
return [
{
title: 'Transaction information',
subtitle: '',
outputsToshow: {
opReturn: {
value: false,
amount: true,
},
change: {
address: false,
amount: true,
},
federation: {
address: true,
amount: true,
},
},
fee: true,
fullAmount: false,
},
];
}

// eslint-disable-next-line class-methods-use-this
isConnected(): Promise<boolean> {
return new Promise<boolean>((resolve) => {
Expand Down
88 changes: 1 addition & 87 deletions src/common/services/LedgerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as bitcoin from 'bitcoinjs-lib';
import * as constants from '@/common/store/constants';
import { BtcAccount, WalletAddress } from '@/common/types/pegInTx';
import {
LedgerjsTransaction, LedgerSignedTx, LedgerTx, Step, Tx,
LedgerjsTransaction, LedgerSignedTx, LedgerTx, Tx,
} from '@/common/types';
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
import { WalletService } from '@/common/services/index';
Expand Down Expand Up @@ -33,92 +33,6 @@ export default class LedgerService extends WalletService {
return constants.WALLET_NAMES.LEDGER;
}

// eslint-disable-next-line class-methods-use-this
confirmationSteps(): Step[] {
return [
{
title: 'Confirm transaction',
subtitle: 'Please check your Ledger device',
outputsToshow: {
opReturn: {
value: true,
amount: true,
},
change: {
address: false,
amount: false,
},
federation: {
address: false,
amount: false,
},
},
fee: false,
fullAmount: false,
},
{
title: 'Confirm funds transfer',
subtitle: 'Confirm sending',
outputsToshow: {
opReturn: {
value: false,
amount: false,
},
change: {
address: false,
amount: false,
},
federation: {
address: true,
amount: true,
},
},
fee: false,
fullAmount: false,
},
{
title: 'Confirm change address',
subtitle: 'Confirm sending',
outputsToshow: {
opReturn: {
value: false,
amount: false,
},
change: {
address: true,
amount: true,
},
federation: {
address: false,
amount: false,
},
},
fee: false,
fullAmount: false,
},
{
title: 'Confirm transaction fee',
subtitle: 'Confirm transaction',
outputsToshow: {
opReturn: {
value: false,
amount: false,
},
change: {
address: false,
amount: false,
},
federation: {
address: false,
amount: false,
},
},
fee: true,
fullAmount: false,
},
];
}

// eslint-disable-next-line class-methods-use-this
public reconnect(): Promise<void> {
return new Promise<void>((resolve, reject) => {
Expand Down
Loading

0 comments on commit b9530c0

Please sign in to comment.