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

Allow utilising wallet's keys for assymetric cryptography. #198

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
164 changes: 164 additions & 0 deletions docs/classes/_tonconnect_protocol.SessionCrypto.html.orig

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"main": "./lib/cjs/index.cjs",
"module": "./lib/esm/index.mjs",
"types": "./lib/types/index.d.ts",
"exports": {
"export": {
".": {
"types": "./lib/types/index.d.ts",
"require": "./lib/cjs/index.cjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { SendTransactionRpcRequest } from './send-transaction-rpc-request';
import { SignDataRpcRequest } from './sign-data-rpc-request';
import { RpcMethod } from '../../rpc-method';
import { DisconnectRpcRequest } from './disconnect-rpc-request';
import { EncryptDataRpcRequest } from './encrypt-data-rpc-request';
import { DecryptDataRpcRequest } from './decrypt-data-rpc-request';

export type RpcRequests = {
sendTransaction: SendTransactionRpcRequest;
signData: SignDataRpcRequest;
disconnect: DisconnectRpcRequest;
encryptData: EncryptDataRpcRequest;
decryptData: DecryptDataRpcRequest;
};

export type AppRequest<T extends RpcMethod> = RpcRequests[T];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface DecryptDataRpcRequest {
method: 'decryptData';
// params: [
// senderAddress: string,
// data: string,
// ];
params: string[];//senderAddress, stringToDecrypt
id: string;
//TODO: currently senderAddress is the first parameter in the array, but it shall be passed separately, with array holding the many entries
// senderAddress: string;
}

//TODO: change to just array in interface with string hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface EncryptDataRpcRequest {
method: 'encryptData';
// data:
// string
// ;
params: string[];//publicKey, stringToEncrypt
id: string;
}
2 changes: 2 additions & 0 deletions packages/protocol/src/models/app-message/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { AppRequest, RpcRequests } from './app-request';
export { SendTransactionRpcRequest } from './send-transaction-rpc-request';
export { SignDataRpcRequest } from './sign-data-rpc-request';
export { DisconnectRpcRequest } from './disconnect-rpc-request';
export { EncryptDataRpcRequest } from './encrypt-data-rpc-request';
export { DecryptDataRpcRequest } from './decrypt-data-rpc-request';
5 changes: 4 additions & 1 deletion packages/protocol/src/models/feature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export type Feature = SendTransactionFeatureDeprecated | SendTransactionFeature | SignDataFeature;
export type Feature = SendTransactionFeatureDeprecated | SendTransactionFeature | SignDataFeature | EncryptDataFeature | DecryptDataFeature;

export type SendTransactionFeatureDeprecated = 'SendTransaction';
export type SendTransactionFeature = { name: 'SendTransaction'; maxMessages: number };
export type SignDataFeature = { name: 'SignData' };

export type EncryptDataFeature = {name: 'EncryptData'};
export type DecryptDataFeature = {name: 'DecryptData'}
4 changes: 3 additions & 1 deletion packages/protocol/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export {
Feature,
SendTransactionFeatureDeprecated,
SendTransactionFeature,
SignDataFeature
SignDataFeature,
EncryptDataFeature,
DecryptDataFeature,
} from './feature';
export { CHAIN } from './CHAIN';
2 changes: 1 addition & 1 deletion packages/protocol/src/models/rpc-method.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type RpcMethod = 'disconnect' | 'sendTransaction' | 'signData';
export type RpcMethod = 'disconnect' | 'sendTransaction' | 'signData' | 'encryptData' | 'decryptData';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { WalletResponseTemplateError, WalletResponseTemplateSuccess } from './wallet-response-template';
//TODO: make them arrays

export type DecryptDataRpcResponse = DecryptDataRpcResponseSuccess | DecryptDataRpcResponseError;

// export interface DecryptDataRpcResponseSuccess {
// id: string;
// // result: {
// // // data: string[];
// // data: string;
// // };
// result: string;
// }

export interface DecryptDataRpcResponseSuccess {
result: string[];
id: string;
}

export interface DecryptDataRpcResponseError extends WalletResponseTemplateError {
error: { code: DECRYPT_DATA_ERROR_CODES; message: string; data?: unknown };
id: string;
}

export enum DECRYPT_DATA_ERROR_CODES {
UNKNOWN_ERROR = 0,
BAD_REQUEST_ERROR = 1,
UNKNOWN_APP_ERROR = 100,
USER_REJECTS_ERROR = 300,
METHOD_NOT_SUPPORTED = 400
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { WalletResponseTemplateError, WalletResponseTemplateSuccess } from './wallet-response-template';
//TODO: make them arrays

export type EncryptDataRpcResponse = EncryptDataRpcResponseSuccess | EncryptDataRpcResponseError;

// export interface EncryptDataRpcResponseSuccess {
// id: string;
// // result: {
// // data: string;
// // };
// result: string;
// }

export interface EncryptDataRpcResponseSuccess extends WalletResponseTemplateSuccess {}

export interface EncryptDataRpcResponseError extends WalletResponseTemplateError {
error: { code: ENCRYPT_DATA_ERROR_CODES; message: string; data?: unknown };
id: string;
}

export enum ENCRYPT_DATA_ERROR_CODES {
UNKNOWN_ERROR = 0,
BAD_REQUEST_ERROR = 1,
UNKNOWN_APP_ERROR = 100,
USER_REJECTS_ERROR = 300,
METHOD_NOT_SUPPORTED = 400
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ export {
WalletResponseTemplateError,
WalletResponseTemplateSuccess
} from './wallet-response-template';
export {
EncryptDataRpcResponse,
EncryptDataRpcResponseSuccess,
EncryptDataRpcResponseError,
ENCRYPT_DATA_ERROR_CODES
} from './encrypt-rpc-response';
export {
DecryptDataRpcResponse,
DecryptDataRpcResponseSuccess,
DecryptDataRpcResponseError,
DECRYPT_DATA_ERROR_CODES
} from './decrypt-rpc-response';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
DisconnectRpcResponseError,
DisconnectRpcResponseSuccess
} from './disconnect-rpc-response';
import { DecryptDataRpcResponseError, DecryptDataRpcResponseSuccess } from './decrypt-rpc-response';
import { EncryptDataRpcResponseError, EncryptDataRpcResponseSuccess } from './encrypt-rpc-response';

export type RpcResponses = {
sendTransaction: {
Expand All @@ -24,6 +26,14 @@ export type RpcResponses = {
error: DisconnectRpcResponseError;
success: DisconnectRpcResponseSuccess;
};
decryptData: {
error: DecryptDataRpcResponseError;
success: DecryptDataRpcResponseSuccess;
};
encryptData: {
error: EncryptDataRpcResponseError;
success: EncryptDataRpcResponseSuccess;
};
};

export type WalletResponseSuccess<T extends RpcMethod> = RpcResponses[T]['success'];
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@tonconnect/isomorphic-eventsource": "^0.0.2",
"@tonconnect/isomorphic-fetch": "^0.0.3",
"@tonconnect/protocol": "^2.2.6"
"@tonconnect/protocol": "file:../protocol"
},
"files": [
"lib",
Expand Down
26 changes: 23 additions & 3 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export {
createTransactionSignedEvent,
createRequestVersionEvent,
createResponseVersionEvent,
createVersionInfo
createVersionInfo,
createEncryptDataEvent,
createDecryptDataEvent,
createEncryptDataFailedEvent,
createEncryptDataSentEvent,
createDecryptDataSentEvent,
createDecryptDataFailedEvent,
} from './tracker/types';
export type {
AuthType,
Expand All @@ -48,7 +54,17 @@ export type {
ResponseVersionEvent,
VersionEvent,
Version,
WithoutVersion
WithoutVersion,
EncryptDataSentEvent,
EncryptDataEvent,
EncryptDataFailedEvent,
EncryptedDataEvent,
EncryptDataInfo,
DecryptDataInfo,
DecryptDataSentEvent,
DecryptDataEvent,
DecryptDataFailedEvent,
DecryptedDataEvent,
} from './tracker/types';
export { BrowserEventDispatcher } from './tracker/browser-event-dispatcher';
export type { TonAddressItem, TonProofItem, ConnectItem } from '@tonconnect/protocol';
Expand All @@ -58,14 +74,18 @@ export {
Feature,
SendTransactionFeature,
SignDataFeature,
EncryptDataFeature,
DecryptDataFeature,
SendTransactionFeatureDeprecated,
TonProofItemReply,
TonProofItemReplySuccess,
TonProofItemReplyError,
ConnectItemReplyError,
CONNECT_ITEM_ERROR_CODES,
CONNECT_EVENT_ERROR_CODES,
SEND_TRANSACTION_ERROR_CODES
SEND_TRANSACTION_ERROR_CODES,
ENCRYPT_DATA_ERROR_CODES,
DECRYPT_DATA_ERROR_CODES,
} from '@tonconnect/protocol';
export { toUserFriendlyAddress } from './utils/address';
export { isTelegramUrl, encodeTelegramUrlParameters } from './utils/url';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface DecryptData {
senderAddress: string;
data: string;
}

export interface DecryptDataRequest {
// params: DecryptData[];
data: string[];
id: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface DecryptDataResponse {
result: string[];//[]
// boc: string
// id: string;
}
2 changes: 2 additions & 0 deletions packages/sdk/src/models/methods/decrypt-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { DecryptDataRequest } from './decrypt-data-request';
export { DecryptDataResponse } from './decrypt-data-response';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface EncryptDataRequest {
data: string[];// receiversPublicKey, data
// data: {data: string
// }[];
id: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface EncryptDataResponse {
boc: string;
// data: {data: string
// }[];
// id: string;
}
2 changes: 2 additions & 0 deletions packages/sdk/src/models/methods/encrypt-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { EncryptDataRequest } from './encrypt-data-request';
export { EncryptDataResponse } from './encrypt-data-response';
2 changes: 2 additions & 0 deletions packages/sdk/src/models/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './connect';
export * from './send-transaction';
export * from './decrypt-data';
export * from './encrypt-data';
Loading