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

feat: add plugins DashPay and DashPaySyncWorker #281

Open
wants to merge 59 commits into
base: v0.22-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d12bb12
chore: bump version to 3.21.0-dev.1 (#243)
antouhou Aug 3, 2021
df3bca0
Merge branch 'master' into v0.21-dev
shumkov Aug 9, 2021
344a345
chore: update grpc (#247)
strophy Aug 11, 2021
c6f5f83
chore: bump version to 3.21.0-dev.2 (#248)
strophy Aug 11, 2021
9672bb9
feat: update wallet-lib to 7.21.0-dev.3 (#251)
Aug 16, 2021
724d6c7
chore: bump version to 3.21.0-dev.3 (#255)
Aug 16, 2021
c8b8f80
chore: update grpc-common deps (#256)
strophy Aug 16, 2021
ce85c74
chore: bump version to 3.21.0-dev.4 (#257)
strophy Aug 16, 2021
9f1ce1d
feat: add `driveProtocolVersion` option (#249)
jawid-h Aug 24, 2021
59a0045
chore: bump version to 3.21.0-dev.5 (#258)
Aug 24, 2021
d004eaf
feat: provide DashPayWorker plugin
Alex-Werner Jul 12, 2021
4e30cb9
feat: added method for DashPayPlugin
Alex-Werner Aug 6, 2021
a9ac18e
feat: removed default for function
Alex-Werner Aug 31, 2021
763148e
test: fix mock for getBlockHeaderByHash (#260)
Alex-Werner Sep 8, 2021
36096a7
feat: moved encryptPublicKey and encryptShared to Plugin
Alex-Werner Sep 9, 2021
88bd675
test: provide tests
Alex-Werner Sep 10, 2021
d96c9c6
test: provide encryptPublicKey and encryptSharedKey unit test
Alex-Werner Sep 10, 2021
7d1eb84
feat(DashPaySyncWorker): add fetchContactRequests
Alex-Werner Sep 10, 2021
9f680fa
feat(DashPayPlugin): add acceptContactRequest
Alex-Werner Sep 10, 2021
a60de06
feat: add plugin injection ordering
Alex-Werner Sep 10, 2021
67c4457
fix: createAccountReference 28 MSB
Alex-Werner Sep 13, 2021
8ddb5c4
feat: add Contact and establish contact + fetch
Alex-Werner Sep 14, 2021
baced33
feat: comprehensive error codes (#262)
shumkov Sep 15, 2021
b8d9b90
chore: bump version to 3.21.0-dev.6 (#265)
Sep 15, 2021
0378035
feat: provide Contact and Profile
Alex-Werner Sep 17, 2021
c8d3e2b
feat!: convenient broadcast errors (#266)
shumkov Sep 20, 2021
547437f
chore: bump version to 3.21.0-dev.7 (#269)
Alex-Werner Sep 20, 2021
115d3c4
chore: update package to node 16 (#267)
Alex-Werner Sep 24, 2021
f30c3ca
chore: bump version to 3.21.0-dev.8 (#270)
strophy Sep 25, 2021
8f2ee45
fix: update error usage
Alex-Werner Sep 26, 2021
18d7c8c
fix: breaking change from dpp
Alex-Werner Sep 26, 2021
320904a
Merge remote-tracking branch 'origin/v0.21-dev' into feat/dip15
Alex-Werner Sep 26, 2021
931bf9d
feat: fetchContactRequest and fetchEstablishedContacts
Alex-Werner Sep 26, 2021
a05d778
feat: support higher protocol version (#271)
Sep 27, 2021
ed2a9c9
chore: bump version to 3.21.0-dev.9 (#272)
Sep 28, 2021
17c8fa4
fix: createConsensusError can be called with empty arguments (#273)
Sep 29, 2021
9839c7d
chore: bump version to 3.21.0-dev.11 (#274)
Sep 29, 2021
a653814
fix: UTXO selection doesn't work properly (#277)
shumkov Oct 5, 2021
ec12cf6
chore(release): bump version to 3.21.0-dev.11
shumkov Oct 5, 2021
9924e8e
chore: version 3.21.0-dev.12 (#279)
Alex-Werner Oct 12, 2021
7802f90
chore: bump version to v3.21.0-dev.13 (#280)
Oct 14, 2021
31393b9
feat: add decryptPublicKey
Alex-Werner Oct 15, 2021
dda3b28
feat: only fetch when identity is created
Alex-Werner Oct 15, 2021
a1852bb
fix: correctly decrypt shared key
Alex-Werner Oct 15, 2021
ae0975e
test: encryptShareKey
Alex-Werner Oct 15, 2021
aa45f2c
chore: update package
Alex-Werner Oct 15, 2021
24a27b8
Merge remote-tracking branch 'origin/v0.21-dev' into feat/dip15
Alex-Werner Oct 15, 2021
d2d996f
fix: revert changed contract ids
Alex-Werner Oct 15, 2021
5f8a844
fix: removed unused file
Alex-Werner Oct 15, 2021
7d83852
build: update target from es5 to es2017
Alex-Werner Oct 16, 2021
5f29c0e
chore: using specific dependency removal branch
Alex-Werner Oct 16, 2021
d626211
test: upgrade dpp output
Alex-Werner Oct 17, 2021
691fa8d
style: fix excessive logs
Alex-Werner Oct 17, 2021
f200bd3
feat: subscribe to receiving address
Alex-Werner Oct 17, 2021
0a1a872
Merge branch 'v0.22-dev' into feat/dip15
antouhou Oct 26, 2021
ca63d2e
chore: resolve conflicts in package-lock.json
antouhou Oct 26, 2021
5b0c1e8
Merge branch 'v0.22-dev' into feat/dip15
antouhou Oct 26, 2021
392fc48
chore: update package-lock.json
antouhou Oct 26, 2021
16599c4
feat: integrate with keychain and bloomfilter tx stream
Alex-Werner Dec 9, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#DRIVE_BRANCH=v0.21-dev
#DAPI_BRANCH=v0.21-dev
#DASHMATE_BRANCH=update-dependencies
#TEST_SUITE_BRANCH=update-dependencies
#DASHMATE_BRANCH=fix-mnsync
TEST_SUITE_BRANCH=browser-tests
#LOG_LEVEL=silly
50 changes: 49 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"@dashevo/grpc-common": "~0.5.4",
"@dashevo/wallet-lib": "~7.22.0-dev.1",
"bs58": "^4.0.1",
"node-inspect-extracted": "1.0.7"
"crypto-js": "^4.0.0",
"node-inspect-extracted": "1.0.7",
"secp256k1-native": "^1.1.2"
},
"devDependencies": {
"@types/chai": "^4.2.12",
Expand Down
41 changes: 36 additions & 5 deletions src/SDK/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Platform } from './Platform';
import { Network } from "@dashevo/dashcore-lib";
import DAPIClient from "@dashevo/dapi-client";
import { ClientApps, ClientAppsOptions } from "./ClientApps";
import { DashPaySyncWorker } from "./plugins/DashPaySyncWorker/DashPaySyncWorker";
import { DashPay } from "./plugins/DashPay/DashPay";

export interface WalletOptions extends Wallet.IWalletOptions {
defaultAccountIndex?: number;
Expand Down Expand Up @@ -82,6 +84,8 @@ export class Client extends EventEmitter {

this.dapiClient = new DAPIClient(dapiClientOptions);

let dashpayPlugin;
let dashpaySyncWorker;
// Initialize a wallet if `wallet` option is preset
if (this.options.wallet !== undefined) {
if (this.options.wallet.network !== undefined && this.options.wallet.network !== this.network) {
Expand All @@ -90,11 +94,24 @@ export class Client extends EventEmitter {

const transport = new DAPIClientTransport(this.dapiClient);

this.wallet = new Wallet({
const walletOptions = {
transport,
network: this.network,
...this.options.wallet,
});
...this.options.wallet,
}

// If it's a bip44 wallet, we pass the DashPay Worker and DashPay plugin
if(
!this.options.wallet.privateKey &&
this.options.wallet.offlineMode !== true
){
dashpayPlugin = new DashPay();
dashpaySyncWorker = new DashPaySyncWorker();
//@ts-ignore
walletOptions.plugins = [dashpayPlugin, dashpaySyncWorker];
}
//@ts-ignore
this.wallet = new Wallet(walletOptions);

// @ts-ignore
this.wallet.on('error', (error, context) => (
Expand All @@ -119,6 +136,12 @@ export class Client extends EventEmitter {
network: this.network,
driveProtocolVersion: this.options.driveProtocolVersion,
});

if(dashpaySyncWorker && dashpayPlugin){
dashpayPlugin.inject('platform', this.platform, true)
dashpaySyncWorker.inject('platform', this.platform, true)
}

}

/**
Expand All @@ -128,16 +151,24 @@ export class Client extends EventEmitter {
* @returns {Promise<Account>}
*/
async getWalletAccount(options: Account.Options = {}) : Promise<Account> {
if (!this.wallet) {
const { wallet } = this;
if (!wallet) {
throw new Error('Wallet is not initialized, pass `wallet` option to Client');
}

options = {
index: this.defaultAccountIndex,
...options,
}
const account = await wallet.getAccount(options);

try {
const dashpayworker = account.getWorker('DashPaySyncWorker');
//@ts-ignore
await dashpayworker.execute();
} catch {}

return this.wallet.getAccount(options);
return account;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/SDK/Client/Platform/methods/identities/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ export default async function register(
await broadcastStateTransition(this, identityCreateTransition);

// If state transition was broadcast without any errors, import identity to the account
account.storage.insertIdentityIdAtIndex(
account.walletId,
identity.getId().toString(),
identityIndex,
account.storage
.getWalletStore(account.walletId)
.insertIdentityIdAtIndex(
identity.getId().toString(),
identityIndex,
);

return identity;
Expand Down
65 changes: 65 additions & 0 deletions src/SDK/Client/plugins/DashPay/DashPay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { plugins } from "@dashevo/wallet-lib"

import { acceptContactRequest } from "./methods/acceptContactRequest";
import { createAccountReference } from "./methods/createAccountReference";
import { decryptAccountLabel }from "./methods/decryptAccountLabel";
import { decryptPublicKey } from "./methods/decryptPublicKey";
import { encryptAccountLabel } from "./methods/encryptAccountLabel";
import { encryptPublicKey } from "./methods/encryptPublicKey";
import { encryptSharedKey } from "./methods/encryptSharedKey";
import { fetchEstablishedContacts } from "./methods/fetchEstablishedContacts";
import { fetchProfile } from "./methods/fetchProfile";
import { fetchReceivedContactRequests } from "./methods/fetchReceivedContactRequests";
import { fetchSentContactRequests } from "./methods/fetchSentContactRequests";
import { sendContactRequest } from "./methods/sendContactRequest";

export class DashPay extends plugins.StandardPlugin {
acceptContactRequest: any;
createAccountReference: any;
decryptAccountLabel: any;
decryptPublicKey: any;
encryptAccountLabel: any;
encryptPublicKey: any;
encryptSharedKey: any;
fetchEstablishedContacts: any;
fetchProfile: any;
fetchReceivedContactRequests: any;
fetchSentContactRequests: any;
sendContactRequest: any;
private contacts: any[];
constructor() {
super({
name: 'DashPay',
executeOnStart: true,
firstExecutionRequired: true,
awaitOnInjection: true,
workerIntervalTime: 60 * 1000,
dependencies: [
'storage',
'decrypt',
'encrypt',
'keyChainStore',
'walletId',
'network',
'identities',
'getUnusedIdentityIndex'
],
injectionOrder:{
after: ['IdentitySyncWorker']
}
});
this.contacts = []
}
}
DashPay.prototype.acceptContactRequest = acceptContactRequest;
DashPay.prototype.createAccountReference = createAccountReference;
DashPay.prototype.decryptAccountLabel = decryptAccountLabel;
DashPay.prototype.decryptPublicKey = decryptPublicKey;
DashPay.prototype.encryptAccountLabel = encryptAccountLabel;
DashPay.prototype.encryptPublicKey = encryptPublicKey;
DashPay.prototype.encryptSharedKey = encryptSharedKey;
DashPay.prototype.fetchEstablishedContacts = fetchEstablishedContacts;
DashPay.prototype.fetchProfile = fetchProfile;
DashPay.prototype.fetchReceivedContactRequests = fetchReceivedContactRequests;
DashPay.prototype.fetchSentContactRequests = fetchSentContactRequests;
DashPay.prototype.sendContactRequest = sendContactRequest;
Loading