Skip to content

Commit

Permalink
CU-86a0gevc3 - Change WalletConnectSDK to use neon-dappkit - added Pr…
Browse files Browse the repository at this point in the history
…omise to type return on methods encrypt, descrypt and decryptFromArray
  • Loading branch information
endkeyCoder committed Aug 28, 2023
1 parent 728fa54 commit 88786d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions packages/neon-dappkit-types/dist/Neo3Signer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<EncryptedPayload[]>;
/**
* 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<string>;
/**
* 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<DecryptFromArrayResult>;
}
2 changes: 1 addition & 1 deletion packages/neon-dappkit/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 6 additions & 5 deletions packages/neon-dappkit/src/NeonSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<EncryptedPayload[]>{
const curve = new elliptic.ec('p256')

const messageBuffer = new TextEncoder().encode(message)
Expand Down Expand Up @@ -122,7 +123,7 @@ export class NeonSigner implements Neo3Signer {
})
}

decrypt(payload: EncryptedPayload) : string {
async decrypt(payload: EncryptedPayload) : Promise<string> {
if (!this.account) {
throw new Error('No account provided')
}
Expand Down Expand Up @@ -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<DecryptFromArrayResult> {
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
Expand Down

0 comments on commit 88786d1

Please sign in to comment.