Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Query ETH RPC to remove JWT requirement #558

Merged
merged 1 commit into from
Feb 1, 2022
Merged
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
79 changes: 37 additions & 42 deletions src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,7 @@ export enum TransferRestrictionStatusString {
providedIn: "root",
})
export class BackendApiService {
constructor(
private httpClient: HttpClient,
private identityService: IdentityService
) {}
constructor(private httpClient: HttpClient, private identityService: IdentityService) {}

static GET_PROFILES_ORDER_BY_INFLUENCER_COIN_PRICE = "influencer_coin_price";
static BUY_CREATOR_COIN_OPERATION_TYPE = "buy";
Expand All @@ -506,7 +503,7 @@ export class BackendApiService {
LastIdentityServiceKey = "lastIdentityServiceURLV2";

// Messaging V3 default key name.
DefaultKey = "default-key"
DefaultKey = "default-key";

// TODO: Wipe all this data when transition is complete
LegacyUserListKey = "userList";
Expand Down Expand Up @@ -777,7 +774,6 @@ export class BackendApiService {
MessageText: string,
MinFeeRateNanosPerKB: number
): Observable<any> {

// First check if either sender or recipient has registered the "default-key" messaging group key.
// In V3 messages, we expect users to migrate to the V3 messages, which means they'll have the default
// key registered on-chain. We want to automatically send messages to this default key is it's registered.
Expand All @@ -786,43 +782,43 @@ export class BackendApiService {
SenderPublicKeyBase58Check,
SenderMessagingKeyName: this.DefaultKey,
RecipientPublicKeyBase58Check,
RecipientMessagingKeyName: this.DefaultKey
})
.pipe(
switchMap( (partyMessagingKeys) => {
// Once we determine the messaging keys of the parties, we will then encrypt a message based on the keys.
return this.identityService.encrypt({
RecipientMessagingKeyName: this.DefaultKey,
}).pipe(
switchMap((partyMessagingKeys) => {
// Once we determine the messaging keys of the parties, we will then encrypt a message based on the keys.
return this.identityService
.encrypt({
...this.identityService.identityServiceParamsForKey(SenderPublicKeyBase58Check),
recipientPublicKey: partyMessagingKeys.RecipientMessagingPublicKeyBase58Check,
senderGroupKeyName: partyMessagingKeys.SenderMessagingKeyName,
message: MessageText,
})
.pipe(
switchMap((encrypted) => {
// Now we will use the ciphertext encrypted to user's messaging keys as part of the metadata of the
// sendMessage transaction.
const EncryptedMessageText = encrypted.encryptedMessage;
// Determine whether to use V3 messaging group key names for sender or recipient.
const senderV3 = partyMessagingKeys.IsSenderMessagingKey;
const SenderMessagingGroupKeyName = senderV3 ? partyMessagingKeys.SenderMessagingKeyName : "";
const recipientV3 = partyMessagingKeys.IsRecipientMessagingKey;
const RecipientMessagingGroupKeyName = recipientV3 ? partyMessagingKeys.RecipientMessagingKeyName : "";
return this.post(endpoint, BackendRoutes.RoutePathSendMessageStateless, {
SenderPublicKeyBase58Check,
RecipientPublicKeyBase58Check,
EncryptedMessageText,
SenderMessagingGroupKeyName,
RecipientMessagingGroupKeyName,
MinFeeRateNanosPerKB,
}).pipe(
map((request) => {
return {...request};
})
);
})
)
})
)
.pipe(
switchMap((encrypted) => {
// Now we will use the ciphertext encrypted to user's messaging keys as part of the metadata of the
// sendMessage transaction.
const EncryptedMessageText = encrypted.encryptedMessage;
// Determine whether to use V3 messaging group key names for sender or recipient.
const senderV3 = partyMessagingKeys.IsSenderMessagingKey;
const SenderMessagingGroupKeyName = senderV3 ? partyMessagingKeys.SenderMessagingKeyName : "";
const recipientV3 = partyMessagingKeys.IsRecipientMessagingKey;
const RecipientMessagingGroupKeyName = recipientV3 ? partyMessagingKeys.RecipientMessagingKeyName : "";
return this.post(endpoint, BackendRoutes.RoutePathSendMessageStateless, {
SenderPublicKeyBase58Check,
RecipientPublicKeyBase58Check,
EncryptedMessageText,
SenderMessagingGroupKeyName,
RecipientMessagingGroupKeyName,
MinFeeRateNanosPerKB,
}).pipe(
map((request) => {
return { ...request };
})
);
})
);
})
);
return this.signAndSubmitTransaction(endpoint, req, SenderPublicKeyBase58Check);
}

Expand Down Expand Up @@ -1548,7 +1544,7 @@ export class BackendApiService {
SenderMessagingPublicKey: message.SenderMessagingPublicKey,
SenderMessagingGroupKeyName: message.SenderMessagingGroupKeyName,
RecipientMessagingPublicKey: message.RecipientMessagingPublicKey,
RecipientMessagingGroupKeyName: message.RecipientMessagingGroupKeyName
RecipientMessagingGroupKeyName: message.RecipientMessagingGroupKeyName,
}))
);
return { ...res, encryptedMessages };
Expand Down Expand Up @@ -1943,11 +1939,10 @@ export class BackendApiService {
});
}

QueryETHRPC(endpoint: string, Method: string, Params: string[], PublicKeyBase58Check: string): Observable<any> {
return this.jwtPost(endpoint, BackendRoutes.RoutePathQueryETHRPC, PublicKeyBase58Check, {
QueryETHRPC(endpoint: string, Method: string, Params: string[]): Observable<any> {
return this.post(endpoint, BackendRoutes.RoutePathQueryETHRPC, {
Method,
Params,
PublicKeyBase58Check,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export class BuyDeSoEthComponent implements OnInit {

queryETHRPC<Type>(method: string, params: any[]): Promise<Type> {
return this.backendApi
.QueryETHRPC(this.globalVars.localNode, method, params, this.globalVars.loggedInUser?.PublicKeyBase58Check)
.QueryETHRPC(this.globalVars.localNode, method, params)
.toPromise()
.then(
(res) => {
Expand Down