This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
96 lines (83 loc) · 2.85 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* A version enum that indicates how a message should be signed
*/
export enum Version {
LEGACY = 1,
DEFAULT,
WITHOUT_SALT
}
/**
* A simple type that defines the SignMessage payload, where Version.LEGACY is deprecated and Version.DEFAULT is NeoFS compatible and uses SALT, and Version.WITHOUT_SALT is NeoFS compatible and does not use SALT
*/
export type SignMessagePayload = {
message: string,
version?: Version
}
/**
* A simple type that defines the Signed Message format
*/
export type SignedMessage = {
/**
* signer's public key
*/
publicKey: string
/**
* encrypted message
*/
data: string
/**
* salt used to encrypt
*/
salt?: string
/**
* message hex
*/
messageHex: string
}
export interface EncryptedPayload {
randomVector: string
cipherText: string
dataTag: string
ephemPublicKey: string
}
/**
* A simple interface that defines the Signing and Verifying methods
*/
export interface Neo3Signer {
/**
* Signs a message
* @param params the params to send the request
* @return the signed message object
*/
signMessage(params: SignMessagePayload): Promise<SignedMessage>
/**
* Checks if the signedMessage is true
* @param params an object that represents a signed message
* @return true if the signedMessage is acknowledged by the account
*/
verifyMessage (params: SignedMessage): Promise<boolean>
/**
* returns the address of the account, not as safe as using signMessage and getting the publicKey
*/
getAccountAddress (): string | null
/**
* Encrypts a message using the Elliptic Curve Integrated Encryption Scheme with the secp256r1 curve
* @param message message to be encrypted
* @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[]
/**
* 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
/**
* 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 }
}