Skip to content

Commit

Permalink
feat: update to latest request package
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Jan 16, 2025
1 parent 357073a commit 31f1abf
Show file tree
Hide file tree
Showing 7 changed files with 8,133 additions and 9,770 deletions.
Binary file not shown.
105 changes: 41 additions & 64 deletions packages/desktop/electron/services/request-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequestNetwork } from '@requestnetwork/request-client.js';
import EthereumPrivateKeyCipherProvider from './ehtereum-private-key-cipher-provider';
import { EthereumPrivateKeyCipherProvider } from '@requestnetwork/epk-cipher';
import { EthereumPrivateKeySignatureProvider } from '@requestnetwork/epk-signature';
import { Types } from '@requestnetwork/request-client.js';
import { getWebApiBaseUrl } from '../../frontend/lib/env';
Expand All @@ -16,7 +16,10 @@ export class RequestService {
private signatureProvider: EthereumPrivateKeySignatureProvider;
private cipherProvider: EthereumPrivateKeyCipherProvider;
private payeeWallet: ethers.Wallet;
private static WALLET_PATH = path.join(app.getPath('userData'), 'wallet.json');
private static WALLET_PATH = path.join(
app.getPath('userData'),
'wallet.json'
);

constructor() {
this.initializeWallet();
Expand All @@ -36,9 +39,10 @@ export class RequestService {

// Initialize the request client with explicit encryption parameters
this.requestClient = new RequestNetwork({

nodeConnectionConfig: {
baseURL: process.env.REQUEST_NODE_URL || 'https://xdai.gateway.request.network/',
baseURL:
process.env.REQUEST_NODE_URL ||
'https://xdai.gateway.request.network/',
},
cipherProvider: this.cipherProvider,
signatureProvider: this.signatureProvider,
Expand All @@ -49,9 +53,15 @@ export class RequestService {
private initializeWallet() {
try {
if (fs.existsSync(RequestService.WALLET_PATH)) {
const walletData = JSON.parse(fs.readFileSync(RequestService.WALLET_PATH, 'utf8'));
const walletData = JSON.parse(
fs.readFileSync(RequestService.WALLET_PATH, 'utf8')
);
this.payeeWallet = new ethers.Wallet(walletData.privateKey);
console.log('0xHypr', 'Loaded existing wallet:', this.payeeWallet.address);
console.log(
'0xHypr',
'Loaded existing wallet:',
this.payeeWallet.address
);
} else {
this.payeeWallet = ethers.Wallet.createRandom();
fs.writeFileSync(
Expand Down Expand Up @@ -106,9 +116,12 @@ export class RequestService {
}

async generateEphemeralKey() {
const response = await fetch(`${getWebApiBaseUrl()}/ephemeral-keys/generate`, {
method: 'POST',
});
const response = await fetch(
`${getWebApiBaseUrl()}/ephemeral-keys/generate`,
{
method: 'POST',
}
);

if (!response.ok) {
throw new Error('Failed to generate ephemeral key');
Expand All @@ -122,9 +135,8 @@ export class RequestService {

console.log('0xHypr', 'Parsed data:', parsedData);
try {
const { token, publicKey: payerPublicKey } = await this.generateEphemeralKey();


const { token, publicKey: payerPublicKey } =
await this.generateEphemeralKey();

// Merge business profile with request data
const requestWithProfile = {
Expand All @@ -143,10 +155,20 @@ export class RequestService {
method: Types.Encryption.METHOD.ECIES,
key: this.payeeWallet.publicKey,
},
{
method: Types.Encryption.METHOD.ECIES,
key: payerPublicKey,
},
];

console.log('0xHypr', 'encryptionParams', encryptionParams, 'payee wallet', this.payeeWallet.privateKey);

console.log(
'0xHypr',
'encryptionParams',
encryptionParams,
'payee wallet',
this.payeeWallet.privateKey
);

// Prepare request data
const requestData: Types.ICreateRequestParameters = {
...requestWithProfile,
Expand All @@ -166,7 +188,10 @@ export class RequestService {
// print private key
console.log('0xHypr', 'private key', this.payeeWallet.privateKey);

const request = await this.requestClient._createEncryptedRequest(requestData, encryptionParams);
const request = await this.requestClient._createEncryptedRequest(
requestData,
encryptionParams
);
console.log('step before addStakeholders');

console.log('step after addStakeholders');
Expand All @@ -176,59 +201,11 @@ export class RequestService {
});
console.log('0xHypr', 'isPayeeRegistered', isPayeeRegistered);


console.log('step before waitForConfirmation');
await request.waitForConfirmation();
request.addStakeholders(
[
{
method: Types.Encryption.METHOD.ECIES,
key: payerPublicKey,
},
],
{
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: data.payeeIdentity || this.payeeWallet.address,
}
);
console.log('step after waitForConfirmation');
console.log('0xHypr', 'Request created:', request);
// temp force decryption for test
// is
// Checking Capabilities
// // Check if encryption is available
// const canEncrypt = cipherProvider.isEncryptionAvailable();
// // Check if decryption is available
// const canDecrypt = cipherProvider.isDecryptionAvailable();
// // Check if an identity is registered
// const isRegistered = await cipherProvider.isIdentityRegistered({
// type: 'ethereum_address',
// value: '0x123...'
// });// Some code
const canEncrypt = this.cipherProvider.isEncryptionAvailable();
const canDecrypt = this.cipherProvider.isDecryptionAvailable();


console.log('0xHypr', 'canEncrypt', canEncrypt);
console.log('0xHypr', 'canDecrypt', canDecrypt);
// is payee registered after adding to stakeholders
const isPayeeRegisteredAfterAddingStakeholders = await this.cipherProvider.isIdentityRegistered({
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: this.payeeWallet.address,
});
console.log('0xHypr', 'isPayeeRegisteredAfterAddingStakeholders', isPayeeRegisteredAfterAddingStakeholders);

const isPayerRegistered = await this.cipherProvider.isIdentityRegistered({
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: payerPublicKey,
});
console.log('0xHypr', 'isRegistered', isPayerRegistered);

// decrypt from the requiest id
const decryptedRequest = await this.requestClient.fromRequestId(request.requestId);
console.log('0xHypr', 'decryptedRequest', decryptedRequest);

return {
return {
requestId: request.requestId,
token,
success: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@requestnetwork/epk-cipher": "^0.5.0",
"@requestnetwork/epk-signature": "^0.9.5",
"@requestnetwork/payment-processor": "^0.52.0",
"@requestnetwork/request-client.js": "^0.54.0",
"@requestnetwork/request-client.js": "^0.55.0",
"@requestnetwork/types": "^0.49.0",
"@requestnetwork/utils": "^0.49.0",
"@requestnetwork/web3-signature": "^0.8.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/request-invoice-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@hypr/shared": "workspace:*",
"@requestnetwork/epk-cipher": "^0.5.0",
"@requestnetwork/payment-processor": "^0.52.0",
"@requestnetwork/request-client.js": "^0.54.0",
"@requestnetwork/request-client.js": "^0.55.0",
"@requestnetwork/web3-signature": "^0.8.5",
"@vercel/postgres": "^0.10.0",
"dotenv": "^16.4.7",
Expand All @@ -40,14 +40,14 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"dotenv-cli": "^7.3.0",
"drizzle-kit": "^0.30.1",
"eslint": "^9",
"eslint-config-next": "13.4.0",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"tsx": "^4.19.2",
"typescript": "^5",
"vitest": "^1.6.0",
"dotenv-cli": "^7.3.0"
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@requestnetwork/epk-cipher": "^0.5.0",
"@requestnetwork/epk-signature": "^0.9.5",
"@requestnetwork/payment-processor": "^0.52.0",
"@requestnetwork/request-client.js": "^0.54.0",
"@requestnetwork/request-client.js": "^0.55.0",
"@requestnetwork/types": "^0.49.0",
"@requestnetwork/utils": "^0.49.0",
"@requestnetwork/web3-signature": "^0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/lib/request-network.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestNetwork } from '@requestnetwork/request-client.js';
import { Types } from '@requestnetwork/request-client.js';
import EthereumPrivateKeyCipherProvider from './ehtereum-private-key-cipher-provider';
import { EthereumPrivateKeyCipherProvider } from '@requestnetwork/epk-cipher';
import { EthereumPrivateKeySignatureProvider } from '@requestnetwork/epk-signature';
import { Wallet } from 'ethers';

Expand Down
Loading

0 comments on commit 31f1abf

Please sign in to comment.