Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/telegram-dev' into telegram-wallet
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/extension-koni-ui/src/utils/date/index.ts
  • Loading branch information
saltict committed Jul 27, 2024
2 parents 2d283c0 + daf7b4f commit 7407b9d
Show file tree
Hide file tree
Showing 50 changed files with 1,459 additions and 756 deletions.
2 changes: 1 addition & 1 deletion packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@subwallet/extension-inject": "^1.2.10-0",
"@subwallet/keyring": "^0.1.5",
"@subwallet/ui-keyring": "^0.1.5",
"@twa-dev/sdk": "^7.0.0",
"@walletconnect/keyvaluestorage": "^1.1.1",
"@walletconnect/sign-client": "^2.13.1",
"@walletconnect/types": "^2.13.1",
Expand Down Expand Up @@ -98,6 +97,7 @@
},
"devDependencies": {
"@subwallet/extension-mocks": "^1.2.10-0",
"@types/telegram-web-app": "^7.3.1",
"@types/uuid": "^9.0.1"
}
}
21 changes: 19 additions & 2 deletions packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,23 @@ export interface ResponseSubscribeHistory {

/* Campaign */

/* Internal Signing */
export interface ConfirmationMetadata {
title?: string,
message?: string,
}

export interface InternalSignRequestMetadata extends ConfirmationMetadata{
url: string,
}

export interface InternalSignRequest<T> {
metadata: InternalSignRequestMetadata
payload: T
}

/* Internal Signing */

/* Core types */
export type _Address = string;
export type _BalanceMetadata = unknown;
Expand Down Expand Up @@ -2400,8 +2417,8 @@ export interface KoniRequestSignatures {
/* Database Service */

/* Internal Signing */
'pri(bytes.sign)': [SignerPayloadRaw, ResponseSigning];
'pri(extrinsic.sign)': [SignerPayloadJSON, ResponseSigning];
'pri(bytes.sign)': [InternalSignRequest<SignerPayloadRaw>, ResponseSigning];
'pri(extrinsic.sign)': [InternalSignRequest<SignerPayloadJSON>, ResponseSigning];
/* Internal Signing */

/* Swap */
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-base/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types'
import type { HexString } from '@polkadot/util/types';
import type { KeypairType } from '@polkadot/util-crypto/types';

import { CurrentNetworkInfo, KoniRequestSignatures, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';
import { ConfirmationMetadata, CurrentNetworkInfo, KoniRequestSignatures, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';

import { TypeRegistry } from '@polkadot/types';

Expand Down Expand Up @@ -102,6 +102,7 @@ export interface ConfirmationRequestBase {
id: string;
url: string;
isInternal?: boolean;
metadata?: ConfirmationMetadata
}

export interface AuthorizeRequest extends ConfirmationRequestBase {
Expand Down
22 changes: 11 additions & 11 deletions packages/extension-base/src/koni/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { _AssetRef, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AccountExternalError, AccountExternalErrorCode, AccountsWithCurrentAddress, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BasicTxErrorType, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CreateDeriveAccountInfo, CronReloadRequest, CurrentAccountInfo, DeriveAccountInfo, ExternalRequestPromiseStatus, ExtrinsicType, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, OptionInputAddress, PriceJson, RemarkWithEvent, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateSuriV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAccountMeta, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBatchRestoreV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestConnectWalletConnect, RequestCrossChainTransfer, RequestDeleteContactAccount, RequestDeriveCreateMultiple, RequestDeriveCreateV2, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetDeriveAccounts, RequestGetTransaction, RequestJsonRestoreV2, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveRecentAccount, RequestSeedCreateV2, RequestSeedValidateV2, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTransfer, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountCreateSuriV2, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseAccountMeta, ResponseChangeMasterPassword, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseFindRawMetadata, ResponseGetDeriveAccounts, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponsePrivateKeyValidateV2, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSeedCreateV2, ResponseSeedValidateV2, ResponseSubscribeHistory, ResponseUnlockKeyring, StakingTxErrorType, StakingType, ThemeNames, TransactionHistoryItem, TransactionResponse, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import { AccountExternalError, AccountExternalErrorCode, AccountsWithCurrentAddress, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BasicTxErrorType, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CreateDeriveAccountInfo, CronReloadRequest, CurrentAccountInfo, DeriveAccountInfo, ExternalRequestPromiseStatus, ExtrinsicType, InternalSignRequest, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, OptionInputAddress, PriceJson, RemarkWithEvent, RequestAccountBatchExportV2, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateSuriV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAccountMeta, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBatchRestoreV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangePriceCurrency, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestConnectWalletConnect, RequestCrossChainTransfer, RequestDeleteContactAccount, RequestDeriveCreateMultiple, RequestDeriveCreateV2, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetDeriveAccounts, RequestGetTransaction, RequestJsonRestoreV2, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveRecentAccount, RequestSeedCreateV2, RequestSeedValidateV2, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTransfer, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountBatchExportV2, ResponseAccountCreateSuriV2, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseAccountMeta, ResponseChangeMasterPassword, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseFindRawMetadata, ResponseGetDeriveAccounts, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponsePrivateKeyValidateV2, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSeedCreateV2, ResponseSeedValidateV2, ResponseSubscribeHistory, ResponseUnlockKeyring, ShowCampaignPopupRequest, StakingJson, StakingRewardJson, StakingTxErrorType, StakingType, ThemeNames, TransactionHistoryItem, TransactionResponse, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign';
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
import { AccountAuthType, AccountJson, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestAuthorizeCancel, RequestAuthorizeReject, RequestBatchRestore, RequestCurrentAccountAddress, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApproveSignature, RequestSigningCancel, RequestTypes, ResponseAccountExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigning, ResponseType, SigningRequest, WindowOpenParams } from '@subwallet/extension-base/background/types';
Expand Down Expand Up @@ -4050,19 +4050,19 @@ export default class KoniExtension {

/* Buy service */

private async bytesSign (request: SignerPayloadRaw): Promise<ResponseSigning> {
const address = request.address;
const pair = this.#koniState.keyringService.getPair(address);
private async bytesSign (request: InternalSignRequest<SignerPayloadRaw>): Promise<ResponseSigning> {
const { metadata, payload } = request;
const pair = this.#koniState.keyringService.getPair(payload.address);

return this.#koniState.sign('https://booka.games', new RequestBytesSign(request), { address, ...pair.meta });
return this.#koniState.sign(metadata?.url, new RequestBytesSign(payload), { address: payload.address, ...pair.meta }, metadata);
}

private async extrinsicSign (request: SignerPayloadJSON): Promise<ResponseSigning> {
const address = request.address;
private async extrinsicSign (request: InternalSignRequest<SignerPayloadJSON>): Promise<ResponseSigning> {
const { metadata, payload } = request;

const pair = this.#koniState.keyringService.getPair(address);
const pair = this.#koniState.keyringService.getPair(payload.address);

return this.#koniState.sign('https://booka.games', new RequestExtrinsicSign(request), { address, ...pair.meta });
return this.#koniState.sign(metadata.url, new RequestExtrinsicSign(payload), { address: payload.address, ...pair.meta }, metadata);
}

private async remarkWithEvent (request: RemarkWithEvent): Promise<SWTransactionResponse> {
Expand Down Expand Up @@ -4680,9 +4680,9 @@ export default class KoniExtension {
/* Database */
/* Internal Signing */
case 'pri(bytes.sign)':
return this.bytesSign(request as SignerPayloadRaw);
return this.bytesSign(request as InternalSignRequest<SignerPayloadRaw>);
case 'pri(extrinsic.sign)':
return this.extrinsicSign(request as SignerPayloadJSON);
return this.extrinsicSign(request as InternalSignRequest<SignerPayloadJSON>);
/* Internal Signing */
// Default
default:
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-base/src/koni/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AccountRefMap, AddTokenRequestExternal, AmountData, APIItemState, ApiMap, AuthRequestV2, BasicTxErrorType, ChainStakingMetadata, ChainType, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrencyType, CurrentAccountInfo, EvmProviderErrorType, EvmSendTransactionParams, EvmSendTransactionRequest, EvmSignatureRequest, ExternalRequestPromise, ExternalRequestPromiseStatus, ExtrinsicType, MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AccountRefMap, AddTokenRequestExternal, AmountData, APIItemState, ApiMap, AuthRequestV2, BasicTxErrorType, ChainStakingMetadata, ChainType, ConfirmationMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrencyType, CurrentAccountInfo, EvmProviderErrorType, EvmSendTransactionParams, EvmSendTransactionRequest, EvmSignatureRequest, ExternalRequestPromise, ExternalRequestPromiseStatus, ExtrinsicType, MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
Expand Down Expand Up @@ -270,8 +270,8 @@ export default class KoniState {
this.requestService.saveMetadata(meta);
}

public sign (url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning> {
return this.requestService.sign(url, request, account);
public sign (url: string, request: RequestSign, account: AccountJson, metadata?: ConfirmationMetadata): Promise<ResponseSigning> {
return this.requestService.sign(url, request, account, undefined, metadata);
}

public get authSubjectV2 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ConfirmationMetadata } from '@subwallet/extension-base/background/KoniTypes';
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
import { AccountJson, RequestSign, Resolver, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
import RequestService from '@subwallet/extension-base/services/request-service';
Expand Down Expand Up @@ -32,7 +33,7 @@ export default class SubstrateRequestHandler {
public get allSubstrateRequests (): SigningRequest[] {
return Object
.values(this.#substrateRequests)
.map(({ account, id, request, url }) => ({ account, id, request, url, isInternal: isInternalRequest(url) }));
.map(({ account, id, metadata, request, url }) => ({ account, id, request, url, isInternal: isInternalRequest(url), metadata }));
}

private updateIconSign (shouldClose?: boolean): void {
Expand Down Expand Up @@ -63,7 +64,7 @@ export default class SubstrateRequestHandler {
return Object.keys(this.#substrateRequests).length;
}

public async sign (url: string, request: RequestSign, account: AccountJson, _id?: string): Promise<ResponseSigning> {
public async sign (url: string, request: RequestSign, account: AccountJson, _id?: string, metadata?: ConfirmationMetadata): Promise<ResponseSigning> {
const id = _id || getId();
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;

Expand All @@ -77,7 +78,8 @@ export default class SubstrateRequestHandler {
account,
id,
request,
url
url,
metadata
};

this.updateIconSign();
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-base/src/services/request-service/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationMetadata, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
import { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
import { ChainService } from '@subwallet/extension-base/services/chain-service';
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
Expand Down Expand Up @@ -158,8 +158,8 @@ export default class RequestService {
return this.#substrateRequestHandler.allSubstrateRequests;
}

public sign (url: string, request: RequestSign, account: AccountJson, id?: string): Promise<ResponseSigning> {
return this.#substrateRequestHandler.sign(url, request, account, id);
public sign (url: string, request: RequestSign, account: AccountJson, id?: string, metadata?: ConfirmationMetadata): Promise<ResponseSigning> {
return this.#substrateRequestHandler.sign(url, request, account, id, metadata);
}

public get numSubstrateRequests (): number {
Expand Down
2 changes: 2 additions & 0 deletions packages/extension-base/src/services/request-service/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ConfirmationMetadata } from '@subwallet/extension-base/background/KoniTypes';
import { AccountAuthType, AccountJson, RequestSign, Resolver, ResponseSigning } from '@subwallet/extension-base/background/types';
import { MetadataDef } from '@subwallet/extension-inject/types';

Expand All @@ -9,6 +10,7 @@ export interface SignRequest extends Resolver<ResponseSigning> {
id: string;
request: RequestSign;
url: string;
metadata?: ConfirmationMetadata
}

export interface MetaRequest extends Resolver<boolean> {
Expand Down
5 changes: 2 additions & 3 deletions packages/extension-base/src/utils/telegram.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019-2022 @subwallet/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import WebApp from '@twa-dev/sdk';

export const TelegramWebApp = WebApp;
export const telegramObj = window.Telegram;
export const TelegramWebApp = telegramObj.WebApp;
Loading

0 comments on commit 7407b9d

Please sign in to comment.