From 88786d1ba4797a78dd281c6e69c7d1127335f5e8 Mon Sep 17 00:00:00 2001 From: Kenedy Ribeiro Date: Mon, 28 Aug 2023 16:14:18 -0300 Subject: [PATCH] CU-86a0gevc3 - Change WalletConnectSDK to use neon-dappkit - added Promise to type return on methods encrypt, descrypt and decryptFromArray --- packages/neon-dappkit-types/dist/Neo3Signer.d.ts | 13 +++++++------ packages/neon-dappkit/package.json | 2 +- packages/neon-dappkit/src/NeonSigner.ts | 11 ++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/neon-dappkit-types/dist/Neo3Signer.d.ts b/packages/neon-dappkit-types/dist/Neo3Signer.d.ts index 0abb790..c88011c 100644 --- a/packages/neon-dappkit-types/dist/Neo3Signer.d.ts +++ b/packages/neon-dappkit-types/dist/Neo3Signer.d.ts @@ -40,6 +40,10 @@ export interface EncryptedPayload { dataTag: string; ephemPublicKey: string; } +export interface DecryptFromArrayResult { + message: string; + keyIndex: number; +} /** * A simple interface that defines the Signing and Verifying methods */ @@ -66,21 +70,18 @@ export interface Neo3Signer { * @param publicKeys a list of public keys to encrypt the message with * @returns an array with the same lenght as the array of public keys, each element is an EncryptedPayload */ - encrypt(message: string, publicKeys: string[]): EncryptedPayload[]; + encrypt(message: string, publicKeys: string[]): Promise; /** * Decrypts a message encrypted using the Elliptic Curve Integrated Encryption Scheme with the secp256r1 curve * @param payload an object that was encrypted with the public key corresponding to the account * @returns the decrypted message */ - decrypt(payload: EncryptedPayload): string; + decrypt(payload: EncryptedPayload): Promise; /** * Tries to find the first payload that can be decrypted from an array of objects that were encrypted using the Elliptic Curve Integrated Encryption Scheme with the secp256r1 curve * @param payloads an array of objects that were encrypted with the public keys * @returns an object with the decrypted message of the first payload that could be decrypted and the index indicating which encrypted message from the array was decrypt * @throws an error if none of the public keys used to encrypt correspond to the account */ - decryptFromArray(payloads: EncryptedPayload[]): { - message: string; - keyIndex: number; - }; + decryptFromArray(payloads: EncryptedPayload[]): Promise; } diff --git a/packages/neon-dappkit/package.json b/packages/neon-dappkit/package.json index 8dbe169..e7f5e35 100644 --- a/packages/neon-dappkit/package.json +++ b/packages/neon-dappkit/package.json @@ -1,6 +1,6 @@ { "name": "@cityofzion/neon-dappkit", - "version": "0.0.2", + "version": "0.0.3", "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/neon-dappkit/src/NeonSigner.ts b/packages/neon-dappkit/src/NeonSigner.ts index 6977c2f..577ed16 100644 --- a/packages/neon-dappkit/src/NeonSigner.ts +++ b/packages/neon-dappkit/src/NeonSigner.ts @@ -3,7 +3,8 @@ import { SignMessagePayload, SignedMessage, SignMessageVersion, - EncryptedPayload + EncryptedPayload, + DecryptFromArrayResult } from '@cityofzion/neon-dappkit-types' import { wallet, u } from '@cityofzion/neon-core' import randomBytes from 'randombytes' @@ -81,7 +82,7 @@ export class NeonSigner implements Neo3Signer { return this.account?.address ?? null } - encrypt(message: string, publicKeys: string[]) : EncryptedPayload[]{ + async encrypt(message: string, publicKeys: string[]) : Promise{ const curve = new elliptic.ec('p256') const messageBuffer = new TextEncoder().encode(message) @@ -122,7 +123,7 @@ export class NeonSigner implements Neo3Signer { }) } - decrypt(payload: EncryptedPayload) : string { + async decrypt(payload: EncryptedPayload) : Promise { if (!this.account) { throw new Error('No account provided') } @@ -151,10 +152,10 @@ export class NeonSigner implements Neo3Signer { return new TextDecoder().decode(Buffer.concat([firstChunk, secondChunk])) } - decryptFromArray(payloads: EncryptedPayload[]) : { message: string, keyIndex: number } { + async decryptFromArray(payloads: EncryptedPayload[]) : Promise { for (let [index, payload] of payloads.entries()) { try { - const message = this.decrypt(payload) + const message = await this.decrypt(payload) return { message, keyIndex: index } } catch (e) { // do nothing